2 Unix SMB/CIFS implementation.
4 Copyright (C) Guenther Deschner <gd@samba.org> 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "libnet/libnet_dssync.h"
22 #include "libnet/libnet_samsync.h"
23 #include "../libcli/security/security.h"
24 #include "../libds/common/flags.h"
25 #include "../librpc/gen_ndr/ndr_drsuapi.h"
28 /****************************************************************
29 ****************************************************************/
31 struct dssync_passdb {
32 struct pdb_methods *methods;
33 struct db_context *all;
34 struct db_context *aliases;
35 struct db_context *groups;
38 struct dssync_passdb_obj {
39 struct dssync_passdb_obj *self;
41 struct drsuapi_DsReplicaObjectListItemEx *cur;
44 struct db_context *members;
47 struct dssync_passdb_mem {
48 struct dssync_passdb_mem *self;
50 struct drsuapi_DsReplicaObjectIdentifier3 *cur;
51 struct dssync_passdb_obj *obj;
56 static NTSTATUS dssync_insert_obj(struct dssync_passdb *pctx,
57 struct db_context *db,
58 struct dssync_passdb_obj *obj)
61 struct db_record *rec;
63 rec = db->fetch_locked(db, talloc_tos(), obj->key);
65 return NT_STATUS_NO_MEMORY;
67 if (rec->value.dsize != 0) {
71 status = rec->store(rec, obj->data, TDB_INSERT);
72 if (!NT_STATUS_IS_OK(status)) {
80 static struct dssync_passdb_obj *dssync_parse_obj(const TDB_DATA data)
82 struct dssync_passdb_obj *obj;
84 if (data.dsize != sizeof(obj)) {
89 * we need to copy the pointer to avoid alignment problems
92 memcpy(&obj, data.dptr, sizeof(obj));
94 return talloc_get_type_abort(obj, struct dssync_passdb_obj);
97 static struct dssync_passdb_obj *dssync_search_obj_by_guid(struct dssync_passdb *pctx,
98 struct db_context *db,
99 const struct GUID *guid)
101 struct dssync_passdb_obj *obj;
106 key = make_tdb_data((const uint8_t *)(void *)guid,
109 ret = db->fetch(db, talloc_tos(), key, &data);
114 obj = dssync_parse_obj(data);
118 static NTSTATUS dssync_create_obj(struct dssync_passdb *pctx,
119 struct db_context *db,
121 struct drsuapi_DsReplicaObjectListItemEx *cur,
122 struct dssync_passdb_obj **_obj)
125 struct dssync_passdb_obj *obj;
127 obj = talloc_zero(pctx, struct dssync_passdb_obj);
129 return NT_STATUS_NO_MEMORY;
134 obj->key = make_tdb_data((const uint8_t *)(void *)&cur->object.identifier->guid,
135 sizeof(cur->object.identifier->guid));
136 obj->data = make_tdb_data((const uint8_t *)(void *)&obj->self,
139 obj->members = db_open_rbt(obj);
140 if (obj->members == NULL) {
141 return NT_STATUS_NO_MEMORY;
144 status = dssync_insert_obj(pctx, db, obj);
145 if (!NT_STATUS_IS_OK(status)) {
153 static NTSTATUS dssync_insert_mem(struct dssync_passdb *pctx,
154 struct dssync_passdb_obj *obj,
155 struct dssync_passdb_mem *mem)
158 struct db_record *rec;
160 rec = obj->members->fetch_locked(obj->members, talloc_tos(), mem->key);
162 return NT_STATUS_NO_MEMORY;
164 if (rec->value.dsize != 0) {
168 status = rec->store(rec, mem->data, TDB_INSERT);
169 if (!NT_STATUS_IS_OK(status)) {
177 static NTSTATUS dssync_create_mem(struct dssync_passdb *pctx,
178 struct dssync_passdb_obj *obj,
180 struct drsuapi_DsReplicaObjectIdentifier3 *cur,
181 struct dssync_passdb_mem **_mem)
184 struct dssync_passdb_mem *mem;
186 mem = talloc_zero(pctx, struct dssync_passdb_mem);
188 return NT_STATUS_NO_MEMORY;
192 mem->active = active;
194 mem->key = make_tdb_data((const uint8_t *)(void *)&cur->guid,
196 mem->data = make_tdb_data((const uint8_t *)(void *)&mem->self,
199 status = dssync_insert_mem(pctx, obj, mem);
200 if (!NT_STATUS_IS_OK(status)) {
208 static struct dssync_passdb_mem *dssync_parse_mem(const TDB_DATA data)
210 struct dssync_passdb_mem *mem;
212 if (data.dsize != sizeof(mem)) {
217 * we need to copy the pointer to avoid alignment problems
220 memcpy(&mem, data.dptr, sizeof(mem));
222 return talloc_get_type_abort(mem, struct dssync_passdb_mem);
225 static NTSTATUS passdb_startup(struct dssync_context *ctx, TALLOC_CTX *mem_ctx,
226 struct replUpToDateVectorBlob **pold_utdv)
229 struct dssync_passdb *pctx;
231 pctx = talloc_zero(mem_ctx, struct dssync_passdb);
233 return NT_STATUS_NO_MEMORY;
236 if (ctx->output_filename) {
237 status = make_pdb_method_name(&pctx->methods, ctx->output_filename);
239 status = make_pdb_method_name(&pctx->methods, lp_passdb_backend());
242 if (!NT_STATUS_IS_OK(status)) {
246 pctx->all = db_open_rbt(pctx);
247 if (pctx->all == NULL) {
248 return NT_STATUS_NO_MEMORY;
250 pctx->aliases = db_open_rbt(pctx);
251 if (pctx->aliases == NULL) {
252 return NT_STATUS_NO_MEMORY;
254 pctx->groups = db_open_rbt(pctx);
255 if (pctx->groups == NULL) {
256 return NT_STATUS_NO_MEMORY;
259 ctx->private_data = pctx;
264 /****************************************************************
265 ****************************************************************/
267 struct dssync_passdb_traverse_amembers {
268 struct dssync_context *ctx;
269 struct dssync_passdb_obj *obj;
274 struct dssync_passdb_traverse_aliases {
275 struct dssync_context *ctx;
280 static int dssync_passdb_traverse_amembers(struct db_record *rec,
283 struct dssync_passdb_traverse_amembers *state =
284 (struct dssync_passdb_traverse_amembers *)private_data;
285 struct dssync_passdb *pctx =
286 talloc_get_type_abort(state->ctx->private_data,
287 struct dssync_passdb);
288 struct dssync_passdb_mem *mem;
290 struct dom_sid alias_sid;
291 struct dom_sid member_sid;
292 const char *member_dn;
295 struct dom_sid *members;
296 bool is_member = false;
301 alias_sid = state->obj->cur->object.identifier->sid;
303 mem = dssync_parse_mem(rec->value);
308 member_sid = mem->cur->sid;
309 member_dn = mem->cur->dn;
311 mem->obj = dssync_search_obj_by_guid(pctx, pctx->all, &mem->cur->guid);
312 if (mem->obj == NULL) {
313 DEBUG(0,("alias[%s] member[%s] can't resolve member - ignoring\n",
314 sid_string_dbg(&alias_sid),
315 is_null_sid(&member_sid)?
316 sid_string_dbg(&member_sid):
321 switch (mem->obj->type) {
322 case ATYPE_DISTRIBUTION_LOCAL_GROUP:
323 case ATYPE_DISTRIBUTION_GLOBAL_GROUP:
324 DEBUG(0, ("alias[%s] ignore distribution group [%s]\n",
325 sid_string_dbg(&alias_sid),
332 DEBUG(0,("alias[%s] member[%s]\n",
333 sid_string_dbg(&alias_sid),
334 sid_string_dbg(&member_sid)));
336 status = pdb_enum_aliasmem(&alias_sid, talloc_tos(),
337 &members, &num_members);
338 if (!NT_STATUS_IS_OK(status)) {
339 DEBUG(0, ("Could not find current alias members %s - %s\n",
340 sid_string_dbg(&alias_sid),
345 for (i=0; i < num_members; i++) {
348 match = dom_sid_equal(&members[i], &member_sid);
355 status = NT_STATUS_OK;
357 if (!is_member && mem->active) {
359 pdb_add_aliasmem(&alias_sid, &member_sid);
360 } else if (is_member && !mem->active) {
362 pdb_del_aliasmem(&alias_sid, &member_sid);
364 if (!NT_STATUS_IS_OK(status)) {
365 DEBUG(0, ("Could not %s %s as alias members of %s - %s\n",
367 sid_string_dbg(&member_sid),
368 sid_string_dbg(&alias_sid),
376 static int dssync_passdb_traverse_aliases(struct db_record *rec,
379 struct dssync_passdb_traverse_aliases *state =
380 (struct dssync_passdb_traverse_aliases *)private_data;
381 struct dssync_passdb *pctx =
382 talloc_get_type_abort(state->ctx->private_data,
383 struct dssync_passdb);
384 struct dssync_passdb_traverse_amembers mstate;
385 struct dssync_passdb_obj *obj;
389 if (pctx->methods == NULL) {
393 obj = dssync_parse_obj(rec->value);
399 mstate.ctx = state->ctx;
400 mstate.name = "members";
402 ret = obj->members->traverse_read(obj->members,
403 dssync_passdb_traverse_amembers,
412 struct dssync_passdb_traverse_gmembers {
413 struct dssync_context *ctx;
414 struct dssync_passdb_obj *obj;
419 struct dssync_passdb_traverse_groups {
420 struct dssync_context *ctx;
425 static int dssync_passdb_traverse_gmembers(struct db_record *rec,
428 struct dssync_passdb_traverse_gmembers *state =
429 (struct dssync_passdb_traverse_gmembers *)private_data;
430 struct dssync_passdb *pctx =
431 talloc_get_type_abort(state->ctx->private_data,
432 struct dssync_passdb);
433 struct dssync_passdb_mem *mem;
435 char *nt_member = NULL;
437 struct dom_sid group_sid;
438 struct dom_sid member_sid;
439 struct samu *member = NULL;
440 const char *member_dn = NULL;
444 bool is_unix_member = false;
448 DEBUG(0,("%s[%u]...\n", state->name, state->idx));
450 group_sid = state->obj->cur->object.identifier->sid;
452 status = dom_sid_split_rid(talloc_tos(), &group_sid, NULL, &rid);
453 if (!NT_STATUS_IS_OK(status)) {
457 mem = dssync_parse_mem(rec->value);
462 member_sid = mem->cur->sid;
463 member_dn = mem->cur->dn;
465 mem->obj = dssync_search_obj_by_guid(pctx, pctx->all, &mem->cur->guid);
466 if (mem->obj == NULL) {
467 DEBUG(0,("group[%s] member[%s] can't resolve member - ignoring\n",
468 sid_string_dbg(&group_sid),
469 is_null_sid(&member_sid)?
470 sid_string_dbg(&member_sid):
475 member_sid = mem->obj->cur->object.identifier->sid;
476 member_dn = mem->obj->cur->object.identifier->dn;
478 switch (mem->obj->type) {
479 case ATYPE_SECURITY_LOCAL_GROUP:
480 case ATYPE_SECURITY_GLOBAL_GROUP:
481 DEBUG(0, ("Group[%s] ignore member group [%s]\n",
482 sid_string_dbg(&group_sid),
483 sid_string_dbg(&member_sid)));
486 case ATYPE_DISTRIBUTION_LOCAL_GROUP:
487 case ATYPE_DISTRIBUTION_GLOBAL_GROUP:
488 DEBUG(0, ("Group[%s] ignore distribution group [%s]\n",
489 sid_string_dbg(&group_sid),
496 if (!get_domain_group_from_sid(group_sid, &map)) {
497 DEBUG(0, ("Could not find global group %s\n",
498 sid_string_dbg(&group_sid)));
499 //return NT_STATUS_NO_SUCH_GROUP;
503 if (!(grp = getgrgid(map.gid))) {
504 DEBUG(0, ("Could not find unix group %lu\n", (unsigned long)map.gid));
505 //return NT_STATUS_NO_SUCH_GROUP;
509 DEBUG(0,("Group members of %s: ", grp->gr_name));
511 if ( !(member = samu_new(talloc_tos())) ) {
512 //return NT_STATUS_NO_MEMORY;
516 if (!pdb_getsampwsid(member, &member_sid)) {
517 DEBUG(1, ("Found bogus group member: (member_sid=%s group=%s)\n",
518 sid_string_tos(&member_sid), grp->gr_name));
523 if (pdb_get_group_rid(member) == rid) {
524 DEBUGADD(0,("%s(primary),", pdb_get_username(member)));
529 DEBUGADD(0,("%s,", pdb_get_username(member)));
530 nt_member = talloc_strdup(talloc_tos(), pdb_get_username(member));
535 unix_members = grp->gr_mem;
537 while (*unix_members) {
538 if (strcmp(*unix_members, nt_member) == 0) {
539 is_unix_member = true;
545 if (!is_unix_member && mem->active) {
546 smb_add_user_group(grp->gr_name, nt_member);
547 } else if (is_unix_member && !mem->active) {
548 smb_delete_user_group(grp->gr_name, nt_member);
554 static int dssync_passdb_traverse_groups(struct db_record *rec,
557 struct dssync_passdb_traverse_groups *state =
558 (struct dssync_passdb_traverse_groups *)private_data;
559 struct dssync_passdb *pctx =
560 talloc_get_type_abort(state->ctx->private_data,
561 struct dssync_passdb);
562 struct dssync_passdb_traverse_gmembers mstate;
563 struct dssync_passdb_obj *obj;
567 if (pctx->methods == NULL) {
571 DEBUG(0,("%s[%u]...\n", state->name, state->idx));
573 obj = dssync_parse_obj(rec->value);
579 mstate.ctx = state->ctx;
580 mstate.name = "members";
582 ret = obj->members->traverse_read(obj->members,
583 dssync_passdb_traverse_gmembers,
592 static NTSTATUS passdb_finish(struct dssync_context *ctx, TALLOC_CTX *mem_ctx,
593 struct replUpToDateVectorBlob *new_utdv)
595 struct dssync_passdb *pctx =
596 talloc_get_type_abort(ctx->private_data,
597 struct dssync_passdb);
598 struct dssync_passdb_traverse_aliases astate;
599 struct dssync_passdb_traverse_groups gstate;
604 astate.name = "aliases";
605 ret = pctx->aliases->traverse_read(pctx->aliases,
606 dssync_passdb_traverse_aliases,
609 return NT_STATUS_INTERNAL_ERROR;
614 gstate.name = "groups";
615 ret = pctx->groups->traverse_read(pctx->groups,
616 dssync_passdb_traverse_groups,
619 return NT_STATUS_INTERNAL_ERROR;
622 TALLOC_FREE(pctx->methods);
628 /****************************************************************
629 ****************************************************************/
631 static NTSTATUS smb_create_user(TALLOC_CTX *mem_ctx,
634 struct passwd **passwd_p)
636 struct passwd *passwd;
637 char *add_script = NULL;
639 passwd = Get_Pwnam_alloc(mem_ctx, account);
645 /* Create appropriate user */
646 if (acct_flags & ACB_NORMAL) {
647 add_script = talloc_strdup(mem_ctx, lp_adduser_script());
648 } else if ( (acct_flags & ACB_WSTRUST) ||
649 (acct_flags & ACB_SVRTRUST) ||
650 (acct_flags & ACB_DOMTRUST) ) {
651 add_script = talloc_strdup(mem_ctx, lp_addmachine_script());
653 DEBUG(1, ("Unknown user type: %s\n",
654 pdb_encode_acct_ctrl(acct_flags, NEW_PW_FORMAT_SPACE_PADDED_LEN)));
655 return NT_STATUS_UNSUCCESSFUL;
659 return NT_STATUS_NO_MEMORY;
664 add_script = talloc_all_string_sub(mem_ctx, add_script,
667 return NT_STATUS_NO_MEMORY;
669 add_ret = smbrun(add_script, NULL);
670 DEBUG(add_ret ? 0 : 1,("fetch_account: Running the command `%s' "
671 "gave %d\n", add_script, add_ret));
673 smb_nscd_flush_user_cache();
677 /* try and find the possible unix account again */
678 passwd = Get_Pwnam_alloc(mem_ctx, account);
680 return NT_STATUS_NO_SUCH_USER;
688 static struct drsuapi_DsReplicaAttribute *find_drsuapi_attr(
689 const struct drsuapi_DsReplicaObjectListItemEx *cur,
694 for (i = 0; i < cur->object.attribute_ctr.num_attributes; i++) {
695 struct drsuapi_DsReplicaAttribute *attr;
697 attr = &cur->object.attribute_ctr.attributes[i];
699 if (attr->attid == attid) {
707 static NTSTATUS find_drsuapi_attr_string(TALLOC_CTX *mem_ctx,
708 const struct drsuapi_DsReplicaObjectListItemEx *cur,
713 struct drsuapi_DsReplicaAttribute *attr;
717 attr = find_drsuapi_attr(cur, attid);
719 return NT_STATUS_PROPSET_NOT_FOUND;
722 array = talloc_array(mem_ctx, char *, attr->value_ctr.num_values);
724 return NT_STATUS_NO_MEMORY;
727 for (a = 0; a < attr->value_ctr.num_values; a++) {
728 const DATA_BLOB *blob;
731 blob = attr->value_ctr.values[a].blob;
734 return NT_STATUS_INTERNAL_DB_CORRUPTION;
737 ret = pull_string_talloc(array, NULL, 0, &array[a],
738 blob->data, blob->length,
742 return NT_STATUS_INTERNAL_ERROR;
746 *_count = attr->value_ctr.num_values;
751 static NTSTATUS find_drsuapi_attr_int32(TALLOC_CTX *mem_ctx,
752 const struct drsuapi_DsReplicaObjectListItemEx *cur,
757 struct drsuapi_DsReplicaAttribute *attr;
761 attr = find_drsuapi_attr(cur, attid);
763 return NT_STATUS_PROPSET_NOT_FOUND;
766 array = talloc_array(mem_ctx, int32_t, attr->value_ctr.num_values);
768 return NT_STATUS_NO_MEMORY;
771 for (a = 0; a < attr->value_ctr.num_values; a++) {
772 const DATA_BLOB *blob;
774 blob = attr->value_ctr.values[a].blob;
777 return NT_STATUS_INTERNAL_DB_CORRUPTION;
780 if (blob->length != 4) {
781 return NT_STATUS_INTERNAL_DB_CORRUPTION;
784 array[a] = IVAL(blob->data, 0);
787 *_count = attr->value_ctr.num_values;
792 static NTSTATUS find_drsuapi_attr_blob(TALLOC_CTX *mem_ctx,
793 const struct drsuapi_DsReplicaObjectListItemEx *cur,
798 struct drsuapi_DsReplicaAttribute *attr;
802 attr = find_drsuapi_attr(cur, attid);
804 return NT_STATUS_PROPSET_NOT_FOUND;
807 array = talloc_array(mem_ctx, DATA_BLOB, attr->value_ctr.num_values);
809 return NT_STATUS_NO_MEMORY;
812 for (a = 0; a < attr->value_ctr.num_values; a++) {
813 const DATA_BLOB *blob;
815 blob = attr->value_ctr.values[a].blob;
818 return NT_STATUS_INTERNAL_DB_CORRUPTION;
821 array[a] = data_blob_talloc(array, blob->data, blob->length);
822 if (array[a].length != blob->length) {
823 return NT_STATUS_NO_MEMORY;
826 *_count = attr->value_ctr.num_values;
831 static NTSTATUS find_drsuapi_attr_int64(TALLOC_CTX *mem_ctx,
832 const struct drsuapi_DsReplicaObjectListItemEx *cur,
837 struct drsuapi_DsReplicaAttribute *attr;
841 attr = find_drsuapi_attr(cur, attid);
843 return NT_STATUS_PROPSET_NOT_FOUND;
846 array = talloc_array(mem_ctx, int64_t, attr->value_ctr.num_values);
848 return NT_STATUS_NO_MEMORY;
851 for (a = 0; a < attr->value_ctr.num_values; a++) {
852 const DATA_BLOB *blob;
854 blob = attr->value_ctr.values[a].blob;
857 return NT_STATUS_INTERNAL_DB_CORRUPTION;
860 if (blob->length != 8) {
861 return NT_STATUS_INTERNAL_DB_CORRUPTION;
864 array[a] = BVAL(blob->data, 0);
866 *_count = attr->value_ctr.num_values;
871 static NTSTATUS find_drsuapi_attr_dn(TALLOC_CTX *mem_ctx,
872 const struct drsuapi_DsReplicaObjectListItemEx *cur,
875 struct drsuapi_DsReplicaObjectIdentifier3 **_array)
877 struct drsuapi_DsReplicaAttribute *attr;
878 struct drsuapi_DsReplicaObjectIdentifier3 *array;
881 attr = find_drsuapi_attr(cur, attid);
883 return NT_STATUS_PROPSET_NOT_FOUND;
886 array = talloc_array(mem_ctx,
887 struct drsuapi_DsReplicaObjectIdentifier3,
888 attr->value_ctr.num_values);
890 return NT_STATUS_NO_MEMORY;
893 for (a = 0; a < attr->value_ctr.num_values; a++) {
894 const DATA_BLOB *blob;
895 enum ndr_err_code ndr_err;
898 blob = attr->value_ctr.values[a].blob;
901 return NT_STATUS_INTERNAL_DB_CORRUPTION;
904 /* windows sometimes sends an extra two pad bytes here */
905 ndr_err = ndr_pull_struct_blob(blob, array, &array[a],
906 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);
907 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
908 status = ndr_map_error2ntstatus(ndr_err);
912 *_count = attr->value_ctr.num_values;
917 #define GET_BLOB_EX(attr, needed) do { \
920 DATA_BLOB *_vals = NULL; \
921 attr = data_blob_null; \
922 _status = find_drsuapi_attr_blob(mem_ctx, cur, \
923 DRSUAPI_ATTID_ ## attr, \
925 if (NT_STATUS_EQUAL(_status, NT_STATUS_PROPSET_NOT_FOUND)) { \
927 _status = NT_STATUS_OK; \
931 if (!NT_STATUS_IS_OK(_status)) { \
932 DEBUG(0,(__location__ "attr[%s] %s\n", \
933 #attr, nt_errstr(_status))); \
938 talloc_free(_vals); \
939 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
940 return NT_STATUS_OBJECT_NAME_NOT_FOUND; \
942 } else if (_cnt > 1) { \
943 talloc_free(_vals); \
944 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
945 return NT_STATUS_INTERNAL_DB_CORRUPTION; \
948 (void)talloc_steal(mem_ctx, _vals[0].data); \
950 talloc_free(_vals); \
953 #define GET_STRING_EX(attr, needed) do { \
956 char **_vals = NULL; \
958 _status = find_drsuapi_attr_string(mem_ctx, cur, \
959 DRSUAPI_ATTID_ ## attr, \
961 if (NT_STATUS_EQUAL(_status, NT_STATUS_PROPSET_NOT_FOUND)) { \
963 _status = NT_STATUS_OK; \
967 if (!NT_STATUS_IS_OK(_status)) { \
968 DEBUG(0,(__location__ "attr[%s] %s\n", \
969 #attr, nt_errstr(_status))); \
974 talloc_free(_vals); \
975 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
976 return NT_STATUS_OBJECT_NAME_NOT_FOUND; \
978 } else if (_cnt > 1) { \
979 talloc_free(_vals); \
980 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
981 return NT_STATUS_INTERNAL_DB_CORRUPTION; \
983 attr = talloc_move(mem_ctx, &_vals[0]); \
985 talloc_free(_vals); \
988 #define GET_UINT32_EX(attr, needed) do { \
991 int32_t*_vals = NULL; \
993 _status = find_drsuapi_attr_int32(mem_ctx, cur, \
994 DRSUAPI_ATTID_ ## attr, \
996 if (NT_STATUS_EQUAL(_status, NT_STATUS_PROPSET_NOT_FOUND)) { \
998 _status = NT_STATUS_OK; \
1002 if (!NT_STATUS_IS_OK(_status)) { \
1003 DEBUG(0,(__location__ "attr[%s] %s\n", \
1004 #attr, nt_errstr(_status))); \
1009 talloc_free(_vals); \
1010 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
1011 return NT_STATUS_OBJECT_NAME_NOT_FOUND; \
1013 } else if (_cnt > 1) { \
1014 talloc_free(_vals); \
1015 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
1016 return NT_STATUS_INTERNAL_DB_CORRUPTION; \
1018 attr = (uint32_t)_vals[0]; \
1020 talloc_free(_vals); \
1023 #define GET_UINT64_EX(attr, needed) do { \
1026 int64_t *_vals = NULL; \
1028 _status = find_drsuapi_attr_int64(mem_ctx, cur, \
1029 DRSUAPI_ATTID_ ## attr, \
1031 if (NT_STATUS_EQUAL(_status, NT_STATUS_PROPSET_NOT_FOUND)) { \
1033 _status = NT_STATUS_OK; \
1037 if (!NT_STATUS_IS_OK(_status)) { \
1038 DEBUG(0,(__location__ "attr[%s] %s\n", \
1039 #attr, nt_errstr(_status))); \
1044 talloc_free(_vals); \
1045 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
1046 return NT_STATUS_OBJECT_NAME_NOT_FOUND; \
1048 } else if (_cnt > 1) { \
1049 talloc_free(_vals); \
1050 DEBUG(0,(__location__ "attr[%s] count[%u]\n", #attr, _cnt)); \
1051 return NT_STATUS_INTERNAL_DB_CORRUPTION; \
1053 attr = (uint64_t)_vals[0]; \
1055 talloc_free(_vals); \
1058 #define GET_BLOB(attr) GET_BLOB_EX(attr, false)
1059 #define GET_STRING(attr) GET_STRING_EX(attr, false)
1060 #define GET_UINT32(attr) GET_UINT32_EX(attr, false)
1061 #define GET_UINT64(attr) GET_UINT64_EX(attr, false)
1063 /* Convert a struct samu_DELTA to a struct samu. */
1064 #define STRING_CHANGED (old_string && !new_string) ||\
1065 (!old_string && new_string) ||\
1066 (old_string && new_string && (strcmp(old_string, new_string) != 0))
1068 #define STRING_CHANGED_NC(s1,s2) ((s1) && !(s2)) ||\
1070 ((s1) && (s2) && (strcmp((s1), (s2)) != 0))
1072 /****************************************************************
1073 ****************************************************************/
1075 static NTSTATUS sam_account_from_object(struct samu *account,
1076 struct drsuapi_DsReplicaObjectListItemEx *cur)
1078 TALLOC_CTX *mem_ctx = account;
1079 const char *old_string, *new_string;
1080 time_t unix_time, stored_time;
1087 NTTIME accountExpires;
1088 const char *sAMAccountName;
1089 const char *displayName;
1090 const char *homeDirectory;
1091 const char *homeDrive;
1092 const char *scriptPath;
1093 const char *profilePath;
1094 const char *description;
1095 const char *userWorkstations;
1096 const char *comment;
1097 DATA_BLOB userParameters;
1098 struct dom_sid objectSid;
1099 uint32_t primaryGroupID;
1100 uint32_t userAccountControl;
1101 DATA_BLOB logonHours;
1102 uint32_t badPwdCount;
1103 uint32_t logonCount;
1104 DATA_BLOB unicodePwd;
1108 uint32_t acct_flags;
1109 uint32_t units_per_week;
1111 memset(zero_buf, '\0', sizeof(zero_buf));
1113 objectSid = cur->object.identifier->sid;
1114 GET_STRING_EX(sAMAccountName, true);
1115 DEBUG(0,("sam_account_from_object(%s, %s) start\n",
1116 sAMAccountName, sid_string_dbg(&objectSid)));
1117 GET_UINT64(lastLogon);
1118 GET_UINT64(lastLogoff);
1119 GET_UINT64(pwdLastSet);
1120 GET_UINT64(accountExpires);
1121 GET_STRING(displayName);
1122 GET_STRING(homeDirectory);
1123 GET_STRING(homeDrive);
1124 GET_STRING(scriptPath);
1125 GET_STRING(profilePath);
1126 GET_STRING(description);
1127 GET_STRING(userWorkstations);
1128 GET_STRING(comment);
1129 GET_BLOB(userParameters);
1130 GET_UINT32(primaryGroupID);
1131 GET_UINT32(userAccountControl);
1132 GET_BLOB(logonHours);
1133 GET_UINT32(badPwdCount);
1134 GET_UINT32(logonCount);
1135 GET_BLOB(unicodePwd);
1138 status = dom_sid_split_rid(mem_ctx, &objectSid, NULL, &rid);
1139 if (!NT_STATUS_IS_OK(status)) {
1142 acct_flags = ds_uf2acb(userAccountControl);
1144 /* Username, fullname, home dir, dir drive, logon script, acct
1145 desc, workstations, profile. */
1147 if (sAMAccountName) {
1148 old_string = pdb_get_nt_username(account);
1149 new_string = sAMAccountName;
1151 if (STRING_CHANGED) {
1152 pdb_set_nt_username(account, new_string, PDB_CHANGED);
1155 /* Unix username is the same - for sanity */
1156 old_string = pdb_get_username( account );
1157 if (STRING_CHANGED) {
1158 pdb_set_username(account, new_string, PDB_CHANGED);
1163 old_string = pdb_get_fullname(account);
1164 new_string = displayName;
1167 pdb_set_fullname(account, new_string, PDB_CHANGED);
1170 if (homeDirectory) {
1171 old_string = pdb_get_homedir(account);
1172 new_string = homeDirectory;
1175 pdb_set_homedir(account, new_string, PDB_CHANGED);
1179 old_string = pdb_get_dir_drive(account);
1180 new_string = homeDrive;
1183 pdb_set_dir_drive(account, new_string, PDB_CHANGED);
1187 old_string = pdb_get_logon_script(account);
1188 new_string = scriptPath;
1191 pdb_set_logon_script(account, new_string, PDB_CHANGED);
1195 old_string = pdb_get_acct_desc(account);
1196 new_string = description;
1199 pdb_set_acct_desc(account, new_string, PDB_CHANGED);
1202 if (userWorkstations) {
1203 old_string = pdb_get_workstations(account);
1204 new_string = userWorkstations;
1207 pdb_set_workstations(account, new_string, PDB_CHANGED);
1211 old_string = pdb_get_profile_path(account);
1212 new_string = profilePath;
1215 pdb_set_profile_path(account, new_string, PDB_CHANGED);
1218 if (userParameters.data) {
1220 old_string = pdb_get_munged_dial(account);
1221 newstr = (userParameters.length == 0) ? NULL :
1222 base64_encode_data_blob(talloc_tos(), userParameters);
1224 if (STRING_CHANGED_NC(old_string, newstr))
1225 pdb_set_munged_dial(account, newstr, PDB_CHANGED);
1226 TALLOC_FREE(newstr);
1229 /* User and group sid */
1230 if (rid != 0 && pdb_get_user_rid(account) != rid) {
1231 pdb_set_user_sid_from_rid(account, rid, PDB_CHANGED);
1233 if (primaryGroupID != 0 && pdb_get_group_rid(account) != primaryGroupID) {
1234 pdb_set_group_sid_from_rid(account, primaryGroupID, PDB_CHANGED);
1237 /* Logon and password information */
1238 if (!nt_time_is_zero(&lastLogon)) {
1239 unix_time = nt_time_to_unix(lastLogon);
1240 stored_time = pdb_get_logon_time(account);
1241 if (stored_time != unix_time)
1242 pdb_set_logon_time(account, unix_time, PDB_CHANGED);
1245 if (!nt_time_is_zero(&lastLogoff)) {
1246 unix_time = nt_time_to_unix(lastLogoff);
1247 stored_time = pdb_get_logoff_time(account);
1248 if (stored_time != unix_time)
1249 pdb_set_logoff_time(account, unix_time,PDB_CHANGED);
1253 units_per_week = logonHours.length * 8;
1255 if (pdb_get_logon_divs(account) != units_per_week) {
1256 pdb_set_logon_divs(account, units_per_week, PDB_CHANGED);
1259 /* Logon Hours Len */
1260 if (units_per_week/8 != pdb_get_hours_len(account)) {
1261 pdb_set_hours_len(account, units_per_week/8, PDB_CHANGED);
1265 if (logonHours.data) {
1266 char oldstr[44], newstr[44];
1267 pdb_sethexhours(oldstr, pdb_get_hours(account));
1268 pdb_sethexhours(newstr, logonHours.data);
1269 if (!strequal(oldstr, newstr)) {
1270 pdb_set_hours(account, logonHours.data, PDB_CHANGED);
1274 if (pdb_get_bad_password_count(account) != badPwdCount)
1275 pdb_set_bad_password_count(account, badPwdCount, PDB_CHANGED);
1277 if (pdb_get_logon_count(account) != logonCount)
1278 pdb_set_logon_count(account, logonCount, PDB_CHANGED);
1280 if (!nt_time_is_zero(&pwdLastSet)) {
1281 unix_time = nt_time_to_unix(pwdLastSet);
1282 stored_time = pdb_get_pass_last_set_time(account);
1283 if (stored_time != unix_time)
1284 pdb_set_pass_last_set_time(account, unix_time, PDB_CHANGED);
1286 /* no last set time, make it now */
1287 pdb_set_pass_last_set_time(account, time(NULL), PDB_CHANGED);
1290 if (!nt_time_is_zero(&accountExpires)) {
1291 unix_time = nt_time_to_unix(accountExpires);
1292 stored_time = pdb_get_kickoff_time(account);
1293 if (stored_time != unix_time)
1294 pdb_set_kickoff_time(account, unix_time, PDB_CHANGED);
1297 /* Decode hashes from password hash
1298 Note that win2000 may send us all zeros for the hashes if it doesn't
1299 think this channel is secure enough - don't set the passwords at all
1302 if (dBCSPwd.length == 16 && memcmp(dBCSPwd.data, zero_buf, 16) != 0) {
1303 pdb_set_lanman_passwd(account, dBCSPwd.data, PDB_CHANGED);
1306 if (unicodePwd.length == 16 && memcmp(unicodePwd.data, zero_buf, 16) != 0) {
1307 pdb_set_nt_passwd(account, unicodePwd.data, PDB_CHANGED);
1312 /* TODO: account expiry time */
1314 pdb_set_acct_ctrl(account, acct_flags, PDB_CHANGED);
1316 pdb_set_domain(account, lp_workgroup(), PDB_CHANGED);
1318 DEBUG(0,("sam_account_from_object(%s, %s) done\n",
1319 sAMAccountName, sid_string_dbg(&objectSid)));
1320 return NT_STATUS_OK;
1323 /****************************************************************
1324 ****************************************************************/
1326 static NTSTATUS handle_account_object(struct dssync_passdb *pctx,
1327 TALLOC_CTX *mem_ctx,
1328 struct dssync_passdb_obj *obj)
1330 struct drsuapi_DsReplicaObjectListItemEx *cur = obj->cur;
1333 struct samu *sam_account=NULL;
1336 struct dom_sid user_sid;
1337 struct dom_sid group_sid;
1338 struct passwd *passwd = NULL;
1339 uint32_t acct_flags;
1342 const char *sAMAccountName;
1343 uint32_t sAMAccountType;
1344 uint32_t userAccountControl;
1346 user_sid = cur->object.identifier->sid;
1347 GET_STRING_EX(sAMAccountName, true);
1348 GET_UINT32_EX(sAMAccountType, true);
1349 GET_UINT32_EX(userAccountControl, true);
1351 status = dom_sid_split_rid(mem_ctx, &user_sid, NULL, &rid);
1352 if (!NT_STATUS_IS_OK(status)) {
1356 fstrcpy(account, sAMAccountName);
1357 if (rid == DOMAIN_RID_GUEST) {
1359 * pdb_getsampwsid() has special handling for DOMAIN_RID_GUEST
1360 * that's why we need to ignore it here.
1362 * pdb_smbpasswd.c also has some DOMAIN_RID_GUEST related
1365 DEBUG(0,("Ignore %s - %s\n", account, sid_string_dbg(&user_sid)));
1366 return NT_STATUS_OK;
1368 DEBUG(0,("Creating account: %s\n", account));
1370 if ( !(sam_account = samu_new(mem_ctx)) ) {
1371 return NT_STATUS_NO_MEMORY;
1374 acct_flags = ds_uf2acb(userAccountControl);
1375 status = smb_create_user(sam_account, acct_flags, account, &passwd);
1376 if (!NT_STATUS_IS_OK(status)) {
1377 DEBUG(0,("Could not create posix account info for '%s'- %s\n",
1378 account, nt_errstr(status)));
1379 TALLOC_FREE(sam_account);
1383 DEBUG(3, ("Attempting to find SID %s for user %s in the passdb\n",
1384 sid_string_dbg(&user_sid), account));
1385 if (!pdb_getsampwsid(sam_account, &user_sid)) {
1386 sam_account_from_object(sam_account, cur);
1387 DEBUG(3, ("Attempting to add user SID %s for user %s in the passdb\n",
1388 sid_string_dbg(&user_sid),
1389 pdb_get_username(sam_account)));
1390 if (!NT_STATUS_IS_OK(pdb_add_sam_account(sam_account))) {
1391 DEBUG(1, ("SAM Account for %s failed to be added to the passdb!\n",
1393 TALLOC_FREE(sam_account);
1394 return NT_STATUS_ACCESS_DENIED;
1397 sam_account_from_object(sam_account, cur);
1398 DEBUG(3, ("Attempting to update user SID %s for user %s in the passdb\n",
1399 sid_string_dbg(&user_sid),
1400 pdb_get_username(sam_account)));
1401 if (!NT_STATUS_IS_OK(pdb_update_sam_account(sam_account))) {
1402 DEBUG(1, ("SAM Account for %s failed to be updated in the passdb!\n",
1404 TALLOC_FREE(sam_account);
1405 return NT_STATUS_ACCESS_DENIED;
1409 if (pdb_get_group_sid(sam_account) == NULL) {
1410 TALLOC_FREE(sam_account);
1411 return NT_STATUS_UNSUCCESSFUL;
1414 group_sid = *pdb_get_group_sid(sam_account);
1416 if (!pdb_getgrsid(&map, group_sid)) {
1417 DEBUG(0, ("Primary group of %s has no mapping!\n",
1418 pdb_get_username(sam_account)));
1420 if (map.gid != passwd->pw_gid) {
1421 if (!(grp = getgrgid(map.gid))) {
1422 DEBUG(0, ("Could not find unix group %lu for user %s (group SID=%s)\n",
1423 (unsigned long)map.gid, pdb_get_username(sam_account),
1424 sid_string_dbg(&group_sid)));
1426 smb_set_primary_group(grp->gr_name, pdb_get_username(sam_account));
1432 DEBUG(1, ("No unix user for this account (%s), cannot adjust mappings\n",
1433 pdb_get_username(sam_account)));
1436 TALLOC_FREE(sam_account);
1437 return NT_STATUS_OK;
1440 /****************************************************************
1441 ****************************************************************/
1443 static NTSTATUS handle_alias_object(struct dssync_passdb *pctx,
1444 TALLOC_CTX *mem_ctx,
1445 struct dssync_passdb_obj *obj)
1447 struct drsuapi_DsReplicaObjectListItemEx *cur = obj->cur;
1451 struct group *grp = NULL;
1452 struct dom_sid group_sid;
1454 struct dom_sid *dom_sid = NULL;
1459 const char *sAMAccountName;
1460 uint32_t sAMAccountType;
1462 const char *description;
1464 uint32_t num_members = 0;
1465 struct drsuapi_DsReplicaObjectIdentifier3 *members = NULL;
1467 group_sid = cur->object.identifier->sid;
1468 GET_STRING_EX(sAMAccountName, true);
1469 GET_UINT32_EX(sAMAccountType, true);
1470 GET_UINT32_EX(groupType, true);
1471 GET_STRING(description);
1473 status = find_drsuapi_attr_dn(obj, cur, DRSUAPI_ATTID_member,
1474 &num_members, &members);
1475 if (NT_STATUS_EQUAL(status, NT_STATUS_PROPSET_NOT_FOUND)) {
1476 status = NT_STATUS_OK;
1478 if (!NT_STATUS_IS_OK(status)) {
1482 fstrcpy(name, sAMAccountName);
1483 fstrcpy(comment, description);
1485 dom_sid_split_rid(mem_ctx, &group_sid, &dom_sid, &rid);
1487 sid_to_fstring(sid_string, &group_sid);
1488 DEBUG(0,("Creating alias[%s] - %s members[%u]\n",
1489 name, sid_string, num_members));
1491 status = dssync_insert_obj(pctx, pctx->aliases, obj);
1492 if (!NT_STATUS_IS_OK(status)) {
1496 if (pdb_getgrsid(&map, group_sid)) {
1497 if ( map.gid != -1 )
1498 grp = getgrgid(map.gid);
1505 /* No group found from mapping, find it from its name. */
1506 if ((grp = getgrnam(name)) == NULL) {
1508 /* No appropriate group found, create one */
1510 DEBUG(0,("Creating unix group: '%s'\n", name));
1512 if (smb_create_group(name, &gid) != 0)
1513 return NT_STATUS_ACCESS_DENIED;
1515 if ((grp = getgrgid(gid)) == NULL)
1516 return NT_STATUS_ACCESS_DENIED;
1520 map.gid = grp->gr_gid;
1521 map.sid = group_sid;
1523 if (dom_sid_equal(dom_sid, &global_sid_Builtin)) {
1525 * pdb_ldap does not like SID_NAME_WKN_GRP...
1527 * map.sid_name_use = SID_NAME_WKN_GRP;
1529 map.sid_name_use = SID_NAME_ALIAS;
1531 map.sid_name_use = SID_NAME_ALIAS;
1534 fstrcpy(map.nt_name, name);
1536 fstrcpy(map.comment, comment);
1538 fstrcpy(map.comment, "");
1542 pdb_add_group_mapping_entry(&map);
1544 pdb_update_group_mapping_entry(&map);
1546 for (i=0; i < num_members; i++) {
1547 struct dssync_passdb_mem *mem;
1549 status = dssync_create_mem(pctx, obj,
1552 if (!NT_STATUS_IS_OK(status)) {
1557 return NT_STATUS_OK;
1560 /****************************************************************
1561 ****************************************************************/
1563 static NTSTATUS handle_group_object(struct dssync_passdb *pctx,
1564 TALLOC_CTX *mem_ctx,
1565 struct dssync_passdb_obj *obj)
1567 struct drsuapi_DsReplicaObjectListItemEx *cur = obj->cur;
1571 struct group *grp = NULL;
1572 struct dom_sid group_sid;
1577 const char *sAMAccountName;
1578 uint32_t sAMAccountType;
1580 const char *description;
1582 uint32_t num_members = 0;
1583 struct drsuapi_DsReplicaObjectIdentifier3 *members = NULL;
1585 group_sid = cur->object.identifier->sid;
1586 GET_STRING_EX(sAMAccountName, true);
1587 GET_UINT32_EX(sAMAccountType, true);
1588 GET_UINT32_EX(groupType, true);
1589 GET_STRING(description);
1591 status = find_drsuapi_attr_dn(obj, cur, DRSUAPI_ATTID_member,
1592 &num_members, &members);
1593 if (NT_STATUS_EQUAL(status, NT_STATUS_PROPSET_NOT_FOUND)) {
1594 status = NT_STATUS_OK;
1596 if (!NT_STATUS_IS_OK(status)) {
1600 fstrcpy(name, sAMAccountName);
1601 fstrcpy(comment, description);
1603 sid_to_fstring(sid_string, &group_sid);
1604 DEBUG(0,("Creating group[%s] - %s members [%u]\n",
1605 name, sid_string, num_members));
1607 status = dssync_insert_obj(pctx, pctx->groups, obj);
1608 if (!NT_STATUS_IS_OK(status)) {
1612 if (pdb_getgrsid(&map, group_sid)) {
1613 if ( map.gid != -1 )
1614 grp = getgrgid(map.gid);
1621 /* No group found from mapping, find it from its name. */
1622 if ((grp = getgrnam(name)) == NULL) {
1624 /* No appropriate group found, create one */
1626 DEBUG(0,("Creating unix group: '%s'\n", name));
1628 if (smb_create_group(name, &gid) != 0)
1629 return NT_STATUS_ACCESS_DENIED;
1631 if ((grp = getgrnam(name)) == NULL)
1632 return NT_STATUS_ACCESS_DENIED;
1636 map.gid = grp->gr_gid;
1637 map.sid = group_sid;
1638 map.sid_name_use = SID_NAME_DOM_GRP;
1639 fstrcpy(map.nt_name, name);
1641 fstrcpy(map.comment, comment);
1643 fstrcpy(map.comment, "");
1647 pdb_add_group_mapping_entry(&map);
1649 pdb_update_group_mapping_entry(&map);
1651 for (i=0; i < num_members; i++) {
1652 struct dssync_passdb_mem *mem;
1654 status = dssync_create_mem(pctx, obj,
1657 if (!NT_STATUS_IS_OK(status)) {
1662 return NT_STATUS_OK;
1665 /****************************************************************
1666 ****************************************************************/
1668 static NTSTATUS handle_interdomain_trust_object(struct dssync_passdb *pctx,
1669 TALLOC_CTX *mem_ctx,
1670 struct dssync_passdb_obj *obj)
1672 struct drsuapi_DsReplicaObjectListItemEx *cur = obj->cur;
1673 DEBUG(0,("trust: %s\n", cur->object.identifier->dn));
1674 return NT_STATUS_NOT_IMPLEMENTED;
1677 /****************************************************************
1678 ****************************************************************/
1680 struct dssync_object_table_t {
1682 NTSTATUS (*fn) (struct dssync_passdb *pctx,
1683 TALLOC_CTX *mem_ctx,
1684 struct dssync_passdb_obj *obj);
1687 static const struct dssync_object_table_t dssync_object_table[] = {
1688 { ATYPE_NORMAL_ACCOUNT, handle_account_object },
1689 { ATYPE_WORKSTATION_TRUST, handle_account_object },
1690 { ATYPE_SECURITY_LOCAL_GROUP, handle_alias_object },
1691 { ATYPE_SECURITY_GLOBAL_GROUP, handle_group_object },
1692 { ATYPE_INTERDOMAIN_TRUST, handle_interdomain_trust_object },
1695 /****************************************************************
1696 ****************************************************************/
1698 static NTSTATUS parse_object(struct dssync_passdb *pctx,
1699 TALLOC_CTX *mem_ctx,
1700 struct drsuapi_DsReplicaObjectListItemEx *cur)
1702 NTSTATUS status = NT_STATUS_OK;
1706 struct drsuapi_DsReplicaAttribute *attr;
1710 uint32_t sam_type = 0;
1712 DEBUG(3, ("parsing object '%s'\n", cur->object.identifier->dn));
1714 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
1716 attr = &cur->object.attribute_ctr.attributes[i];
1718 if (attr->value_ctr.num_values != 1) {
1722 if (!attr->value_ctr.values[0].blob) {
1726 blob = attr->value_ctr.values[0].blob;
1728 switch (attr->attid) {
1729 case DRSUAPI_ATTID_sAMAccountName:
1730 pull_string_talloc(mem_ctx, NULL, 0, &name,
1731 blob->data, blob->length,
1734 case DRSUAPI_ATTID_sAMAccountType:
1735 sam_type = IVAL(blob->data, 0);
1737 case DRSUAPI_ATTID_userAccountControl:
1738 uacc = IVAL(blob->data, 0);
1745 for (a=0; a < ARRAY_SIZE(dssync_object_table); a++) {
1746 if (sam_type == dssync_object_table[a].type) {
1747 if (dssync_object_table[a].fn) {
1748 struct dssync_passdb_obj *obj;
1749 status = dssync_create_obj(pctx, pctx->all,
1750 sam_type, cur, &obj);
1751 if (!NT_STATUS_IS_OK(status)) {
1754 status = dssync_object_table[a].fn(pctx,
1765 static NTSTATUS parse_link(struct dssync_passdb *pctx,
1766 TALLOC_CTX *mem_ctx,
1767 struct drsuapi_DsReplicaLinkedAttribute *cur)
1769 struct drsuapi_DsReplicaObjectIdentifier3 *id3;
1770 const DATA_BLOB *blob;
1771 enum ndr_err_code ndr_err;
1773 bool active = false;
1774 struct dssync_passdb_mem *mem;
1775 struct dssync_passdb_obj *obj;
1777 if (cur->attid != DRSUAPI_ATTID_member) {
1778 return NT_STATUS_OK;
1781 if (cur->flags & DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE) {
1785 DEBUG(3, ("parsing link '%s' - %s\n",
1786 cur->identifier->dn, active?"adding":"deleting"));
1788 blob = cur->value.blob;
1791 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1794 obj = dssync_search_obj_by_guid(pctx, pctx->all, &cur->identifier->guid);
1796 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1799 id3 = talloc_zero(obj, struct drsuapi_DsReplicaObjectIdentifier3);
1801 return NT_STATUS_NO_MEMORY;
1804 /* windows sometimes sends an extra two pad bytes here */
1805 ndr_err = ndr_pull_struct_blob(blob, id3, id3,
1806 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);
1807 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1808 status = ndr_map_error2ntstatus(ndr_err);
1812 status = dssync_create_mem(pctx, obj,
1815 if (!NT_STATUS_IS_OK(status)) {
1819 return NT_STATUS_OK;
1822 /****************************************************************
1823 ****************************************************************/
1825 static NTSTATUS passdb_process_objects(struct dssync_context *ctx,
1826 TALLOC_CTX *mem_ctx,
1827 struct drsuapi_DsReplicaObjectListItemEx *cur,
1828 struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr)
1830 NTSTATUS status = NT_STATUS_OK;
1831 struct dssync_passdb *pctx =
1832 talloc_get_type_abort(ctx->private_data,
1833 struct dssync_passdb);
1835 for (; cur; cur = cur->next_object) {
1836 status = parse_object(pctx, mem_ctx, cur);
1837 if (!NT_STATUS_IS_OK(status)) {
1846 /****************************************************************
1847 ****************************************************************/
1849 static NTSTATUS passdb_process_links(struct dssync_context *ctx,
1850 TALLOC_CTX *mem_ctx,
1852 struct drsuapi_DsReplicaLinkedAttribute *links,
1853 struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr)
1855 NTSTATUS status = NT_STATUS_OK;
1856 struct dssync_passdb *pctx =
1857 talloc_get_type_abort(ctx->private_data,
1858 struct dssync_passdb);
1861 for (i = 0; i < count; i++) {
1862 status = parse_link(pctx, mem_ctx, &links[i]);
1863 if (!NT_STATUS_IS_OK(status)) {
1872 /****************************************************************
1873 ****************************************************************/
1875 const struct dssync_ops libnet_dssync_passdb_ops = {
1876 .startup = passdb_startup,
1877 .process_objects = passdb_process_objects,
1878 .process_links = passdb_process_links,
1879 .finish = passdb_finish,