dsdb-repl: split out dsdb_repl_resolve_working_schema
[Samba/id10ts.git] / source3 / libnet / libnet_samsync_passdb.c
blobc09474e9b7f14b6d83ff5b5adf3466aa64f4ccc2
1 /*
2 Unix SMB/CIFS implementation.
3 dump the remote SAM using rpc samsync operations
5 Copyright (C) Andrew Tridgell 2002
6 Copyright (C) Tim Potter 2001,2002
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005
8 Modified by Volker Lendecke 2002
9 Copyright (C) Jeremy Allison 2005.
10 Copyright (C) Guenther Deschner 2008.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "includes.h"
27 #include "system/passwd.h"
28 #include "libnet/libnet_samsync.h"
29 #include "../libcli/security/security.h"
30 #include "passdb.h"
32 /* Convert a struct samu_DELTA to a struct samu. */
33 #define STRING_CHANGED (old_string && !new_string) ||\
34 (!old_string && new_string) ||\
35 (old_string && new_string && (strcmp(old_string, new_string) != 0))
37 #define STRING_CHANGED_NC(s1,s2) ((s1) && !(s2)) ||\
38 (!(s1) && (s2)) ||\
39 ((s1) && (s2) && (strcmp((s1), (s2)) != 0))
41 /****************************************************************
42 ****************************************************************/
44 static NTSTATUS sam_account_from_delta(struct samu *account,
45 struct netr_DELTA_USER *r)
47 const char *old_string, *new_string;
48 time_t unix_time, stored_time;
49 uchar zero_buf[16];
51 memset(zero_buf, '\0', sizeof(zero_buf));
53 /* Username, fullname, home dir, dir drive, logon script, acct
54 desc, workstations, profile. */
56 if (r->account_name.string) {
57 old_string = pdb_get_nt_username(account);
58 new_string = r->account_name.string;
60 if (STRING_CHANGED) {
61 pdb_set_nt_username(account, new_string, PDB_CHANGED);
64 /* Unix username is the same - for sanity */
65 old_string = pdb_get_username( account );
66 if (STRING_CHANGED) {
67 pdb_set_username(account, new_string, PDB_CHANGED);
71 if (r->full_name.string) {
72 old_string = pdb_get_fullname(account);
73 new_string = r->full_name.string;
75 if (STRING_CHANGED)
76 pdb_set_fullname(account, new_string, PDB_CHANGED);
79 if (r->home_directory.string) {
80 old_string = pdb_get_homedir(account);
81 new_string = r->home_directory.string;
83 if (STRING_CHANGED)
84 pdb_set_homedir(account, new_string, PDB_CHANGED);
87 if (r->home_drive.string) {
88 old_string = pdb_get_dir_drive(account);
89 new_string = r->home_drive.string;
91 if (STRING_CHANGED)
92 pdb_set_dir_drive(account, new_string, PDB_CHANGED);
95 if (r->logon_script.string) {
96 old_string = pdb_get_logon_script(account);
97 new_string = r->logon_script.string;
99 if (STRING_CHANGED)
100 pdb_set_logon_script(account, new_string, PDB_CHANGED);
103 if (r->description.string) {
104 old_string = pdb_get_acct_desc(account);
105 new_string = r->description.string;
107 if (STRING_CHANGED)
108 pdb_set_acct_desc(account, new_string, PDB_CHANGED);
111 if (r->workstations.string) {
112 old_string = pdb_get_workstations(account);
113 new_string = r->workstations.string;
115 if (STRING_CHANGED)
116 pdb_set_workstations(account, new_string, PDB_CHANGED);
119 if (r->profile_path.string) {
120 old_string = pdb_get_profile_path(account);
121 new_string = r->profile_path.string;
123 if (STRING_CHANGED)
124 pdb_set_profile_path(account, new_string, PDB_CHANGED);
127 if (r->parameters.array) {
128 DATA_BLOB mung;
129 char *newstr;
130 old_string = pdb_get_munged_dial(account);
131 mung.length = r->parameters.length * 2;
132 mung.data = (uint8_t *) r->parameters.array;
133 newstr = (mung.length == 0) ? NULL :
134 base64_encode_data_blob(talloc_tos(), mung);
136 if (STRING_CHANGED_NC(old_string, newstr))
137 pdb_set_munged_dial(account, newstr, PDB_CHANGED);
138 TALLOC_FREE(newstr);
141 /* User and group sid */
142 if (pdb_get_user_rid(account) != r->rid)
143 pdb_set_user_sid_from_rid(account, r->rid, PDB_CHANGED);
144 if (pdb_get_group_rid(account) != r->primary_gid)
145 pdb_set_group_sid_from_rid(account, r->primary_gid, PDB_CHANGED);
147 /* Logon and password information */
148 if (!nt_time_is_zero(&r->last_logon)) {
149 unix_time = nt_time_to_unix(r->last_logon);
150 stored_time = pdb_get_logon_time(account);
151 if (stored_time != unix_time)
152 pdb_set_logon_time(account, unix_time, PDB_CHANGED);
155 if (!nt_time_is_zero(&r->last_logoff)) {
156 unix_time = nt_time_to_unix(r->last_logoff);
157 stored_time = pdb_get_logoff_time(account);
158 if (stored_time != unix_time)
159 pdb_set_logoff_time(account, unix_time,PDB_CHANGED);
162 /* Logon Divs */
163 if (pdb_get_logon_divs(account) != r->logon_hours.units_per_week)
164 pdb_set_logon_divs(account, r->logon_hours.units_per_week, PDB_CHANGED);
166 #if 0
167 /* no idea what to do with this one - gd */
168 /* Max Logon Hours */
169 if (delta->unknown1 != pdb_get_unknown_6(account)) {
170 pdb_set_unknown_6(account, delta->unknown1, PDB_CHANGED);
172 #endif
173 /* Logon Hours Len */
174 if (r->logon_hours.units_per_week/8 != pdb_get_hours_len(account)) {
175 pdb_set_hours_len(account, r->logon_hours.units_per_week/8, PDB_CHANGED);
178 /* Logon Hours */
179 if (r->logon_hours.bits) {
180 char oldstr[44], newstr[44];
181 pdb_sethexhours(oldstr, pdb_get_hours(account));
182 pdb_sethexhours(newstr, r->logon_hours.bits);
183 if (!strequal(oldstr, newstr))
184 pdb_set_hours(account, r->logon_hours.bits,
185 pdb_get_hours_len(account), PDB_CHANGED);
188 if (pdb_get_bad_password_count(account) != r->bad_password_count)
189 pdb_set_bad_password_count(account, r->bad_password_count, PDB_CHANGED);
191 if (pdb_get_logon_count(account) != r->logon_count)
192 pdb_set_logon_count(account, r->logon_count, PDB_CHANGED);
194 if (!nt_time_is_zero(&r->last_password_change)) {
195 unix_time = nt_time_to_unix(r->last_password_change);
196 stored_time = pdb_get_pass_last_set_time(account);
197 if (stored_time != unix_time)
198 pdb_set_pass_last_set_time(account, unix_time, PDB_CHANGED);
199 } else {
200 /* no last set time, make it now */
201 pdb_set_pass_last_set_time(account, time(NULL), PDB_CHANGED);
204 if (!nt_time_is_zero(&r->acct_expiry)) {
205 unix_time = nt_time_to_unix(r->acct_expiry);
206 stored_time = pdb_get_kickoff_time(account);
207 if (stored_time != unix_time)
208 pdb_set_kickoff_time(account, unix_time, PDB_CHANGED);
211 /* Decode hashes from password hash
212 Note that win2000 may send us all zeros for the hashes if it doesn't
213 think this channel is secure enough - don't set the passwords at all
214 in that case
216 if (memcmp(r->lmpassword.hash, zero_buf, 16) != 0) {
217 pdb_set_lanman_passwd(account, r->lmpassword.hash, PDB_CHANGED);
220 if (memcmp(r->ntpassword.hash, zero_buf, 16) != 0) {
221 pdb_set_nt_passwd(account, r->ntpassword.hash, PDB_CHANGED);
224 /* TODO: account expiry time */
226 pdb_set_acct_ctrl(account, r->acct_flags, PDB_CHANGED);
228 pdb_set_domain(account, lp_workgroup(), PDB_CHANGED);
230 return NT_STATUS_OK;
234 /****************************************************************
235 ****************************************************************/
237 static NTSTATUS smb_create_user(TALLOC_CTX *mem_ctx,
238 uint32_t acct_flags,
239 const char *account,
240 struct passwd **passwd_p)
242 struct passwd *passwd;
243 char *add_script = NULL;
245 passwd = Get_Pwnam_alloc(mem_ctx, account);
246 if (passwd) {
247 *passwd_p = passwd;
248 return NT_STATUS_OK;
251 /* Create appropriate user */
252 if (acct_flags & ACB_NORMAL) {
253 add_script = lp_adduser_script(mem_ctx);
254 } else if ( (acct_flags & ACB_WSTRUST) ||
255 (acct_flags & ACB_SVRTRUST) ||
256 (acct_flags & ACB_DOMTRUST) ) {
257 add_script = lp_addmachine_script(mem_ctx);
258 } else {
259 DEBUG(1, ("Unknown user type: %s\n",
260 pdb_encode_acct_ctrl(acct_flags, NEW_PW_FORMAT_SPACE_PADDED_LEN)));
261 return NT_STATUS_UNSUCCESSFUL;
264 if (!add_script) {
265 return NT_STATUS_NO_MEMORY;
268 if (*add_script) {
269 int add_ret;
270 add_script = talloc_all_string_sub(mem_ctx, add_script,
271 "%u", account);
272 if (!add_script) {
273 return NT_STATUS_NO_MEMORY;
275 add_ret = smbrun(add_script, NULL);
276 DEBUG(add_ret ? 0 : 1,("fetch_account: Running the command `%s' "
277 "gave %d\n", add_script, add_ret));
278 if (add_ret == 0) {
279 smb_nscd_flush_user_cache();
283 /* try and find the possible unix account again */
284 passwd = Get_Pwnam_alloc(mem_ctx, account);
285 if (!passwd) {
286 return NT_STATUS_NO_SUCH_USER;
289 *passwd_p = passwd;
291 return NT_STATUS_OK;
293 /****************************************************************
294 ****************************************************************/
296 static NTSTATUS fetch_account_info(TALLOC_CTX *mem_ctx,
297 uint32_t rid,
298 struct netr_DELTA_USER *r)
301 NTSTATUS nt_ret = NT_STATUS_UNSUCCESSFUL;
302 fstring account;
303 struct samu *sam_account=NULL;
304 GROUP_MAP *map = NULL;
305 struct group *grp;
306 struct dom_sid user_sid;
307 struct dom_sid group_sid;
308 struct passwd *passwd = NULL;
309 fstring sid_string;
311 fstrcpy(account, r->account_name.string);
312 d_printf("Creating account: %s\n", account);
314 if ( !(sam_account = samu_new(mem_ctx)) ) {
315 return NT_STATUS_NO_MEMORY;
318 nt_ret = smb_create_user(sam_account, r->acct_flags, account, &passwd);
319 if (!NT_STATUS_IS_OK(nt_ret)) {
320 d_fprintf(stderr, "Could not create posix account info for '%s'\n",
321 account);
322 goto done;
325 sid_compose(&user_sid, get_global_sam_sid(), r->rid);
327 DEBUG(3, ("Attempting to find SID %s for user %s in the passdb\n",
328 sid_to_fstring(sid_string, &user_sid), account));
329 if (!pdb_getsampwsid(sam_account, &user_sid)) {
330 sam_account_from_delta(sam_account, r);
331 DEBUG(3, ("Attempting to add user SID %s for user %s in the passdb\n",
332 sid_to_fstring(sid_string, &user_sid),
333 pdb_get_username(sam_account)));
334 if (!NT_STATUS_IS_OK(pdb_add_sam_account(sam_account))) {
335 DEBUG(1, ("SAM Account for %s failed to be added to the passdb!\n",
336 account));
337 return NT_STATUS_ACCESS_DENIED;
339 } else {
340 sam_account_from_delta(sam_account, r);
341 DEBUG(3, ("Attempting to update user SID %s for user %s in the passdb\n",
342 sid_to_fstring(sid_string, &user_sid),
343 pdb_get_username(sam_account)));
344 if (!NT_STATUS_IS_OK(pdb_update_sam_account(sam_account))) {
345 DEBUG(1, ("SAM Account for %s failed to be updated in the passdb!\n",
346 account));
347 TALLOC_FREE(sam_account);
348 return NT_STATUS_ACCESS_DENIED;
352 if (pdb_get_group_sid(sam_account) == NULL) {
353 return NT_STATUS_UNSUCCESSFUL;
356 group_sid = *pdb_get_group_sid(sam_account);
358 map = talloc_zero(mem_ctx, GROUP_MAP);
359 if (!map) {
360 return NT_STATUS_NO_MEMORY;
363 if (!pdb_getgrsid(map, group_sid)) {
364 DEBUG(0, ("Primary group of %s has no mapping!\n",
365 pdb_get_username(sam_account)));
366 } else {
367 if (map->gid != passwd->pw_gid) {
368 if (!(grp = getgrgid(map->gid))) {
369 DEBUG(0, ("Could not find unix group %lu for user %s (group SID=%s)\n",
370 (unsigned long)map->gid, pdb_get_username(sam_account), sid_string_tos(&group_sid)));
371 } else {
372 smb_set_primary_group(grp->gr_name, pdb_get_username(sam_account));
377 if ( !passwd ) {
378 DEBUG(1, ("No unix user for this account (%s), cannot adjust mappings\n",
379 pdb_get_username(sam_account)));
382 done:
383 TALLOC_FREE(sam_account);
384 TALLOC_FREE(map);
385 return nt_ret;
388 /****************************************************************
389 ****************************************************************/
391 static NTSTATUS fetch_group_info(TALLOC_CTX *mem_ctx,
392 uint32_t rid,
393 struct netr_DELTA_GROUP *r)
395 struct group *grp = NULL;
396 struct dom_sid group_sid;
397 fstring sid_string;
398 GROUP_MAP *map;
399 bool insert = true;
401 map = talloc_zero(mem_ctx, GROUP_MAP);
402 if (!map) {
403 return NT_STATUS_NO_MEMORY;
405 /* add the group to the mapping table */
406 sid_compose(&group_sid, get_global_sam_sid(), rid);
407 sid_to_fstring(sid_string, &group_sid);
409 if (pdb_getgrsid(map, group_sid)) {
410 if (map->gid != -1) {
411 grp = getgrgid(map->gid);
413 insert = false;
416 map->nt_name = talloc_strdup(map, r->group_name.string);
417 if (!map->nt_name) {
418 return NT_STATUS_NO_MEMORY;
420 map->comment = talloc_strdup(map, r->description.string);
421 if (!map->comment) {
422 return NT_STATUS_NO_MEMORY;
425 if (grp == NULL) {
426 gid_t gid;
428 /* No group found from mapping, find it from its name. */
429 if ((grp = getgrnam(map->nt_name)) == NULL) {
431 /* No appropriate group found, create one */
433 d_printf("Creating unix group: '%s'\n", map->nt_name);
435 if (smb_create_group(map->nt_name, &gid) != 0)
436 return NT_STATUS_ACCESS_DENIED;
438 if ((grp = getgrnam(map->nt_name)) == NULL)
439 return NT_STATUS_ACCESS_DENIED;
443 map->gid = grp->gr_gid;
444 map->sid = group_sid;
445 map->sid_name_use = SID_NAME_DOM_GRP;
447 if (insert) {
448 pdb_add_group_mapping_entry(map);
449 } else {
450 pdb_update_group_mapping_entry(map);
453 TALLOC_FREE(map);
454 return NT_STATUS_OK;
457 /****************************************************************
458 ****************************************************************/
460 static NTSTATUS fetch_group_mem_info(TALLOC_CTX *mem_ctx,
461 uint32_t rid,
462 struct netr_DELTA_GROUP_MEMBER *r)
464 int i;
465 char **nt_members = NULL;
466 char **unix_members;
467 struct dom_sid group_sid;
468 GROUP_MAP *map;
469 struct group *grp;
471 if (r->num_rids == 0) {
472 return NT_STATUS_OK;
475 sid_compose(&group_sid, get_global_sam_sid(), rid);
477 map = talloc_zero(mem_ctx, GROUP_MAP);
478 if (!map) {
479 return NT_STATUS_NO_MEMORY;
482 if (!get_domain_group_from_sid(group_sid, map)) {
483 DEBUG(0, ("Could not find global group %d\n", rid));
484 TALLOC_FREE(map);
485 return NT_STATUS_NO_SUCH_GROUP;
488 if (!(grp = getgrgid(map->gid))) {
489 DEBUG(0, ("Could not find unix group %lu\n",
490 (unsigned long)map->gid));
491 TALLOC_FREE(map);
492 return NT_STATUS_NO_SUCH_GROUP;
495 TALLOC_FREE(map);
497 d_printf("Group members of %s: ", grp->gr_name);
499 if (r->num_rids) {
500 if ((nt_members = talloc_zero_array(mem_ctx, char *, r->num_rids)) == NULL) {
501 DEBUG(0, ("talloc failed\n"));
502 return NT_STATUS_NO_MEMORY;
504 } else {
505 nt_members = NULL;
508 for (i=0; i < r->num_rids; i++) {
509 struct samu *member = NULL;
510 struct dom_sid member_sid;
512 if ( !(member = samu_new(mem_ctx)) ) {
513 return NT_STATUS_NO_MEMORY;
516 sid_compose(&member_sid, get_global_sam_sid(), r->rids[i]);
518 if (!pdb_getsampwsid(member, &member_sid)) {
519 DEBUG(1, ("Found bogus group member: %d (member_sid=%s group=%s)\n",
520 r->rids[i], sid_string_tos(&member_sid), grp->gr_name));
521 TALLOC_FREE(member);
522 continue;
525 if (pdb_get_group_rid(member) == rid) {
526 d_printf("%s(primary),", pdb_get_username(member));
527 TALLOC_FREE(member);
528 continue;
531 d_printf("%s,", pdb_get_username(member));
532 nt_members[i] = talloc_strdup(mem_ctx, pdb_get_username(member));
533 TALLOC_FREE(member);
536 d_printf("\n");
538 unix_members = grp->gr_mem;
540 while (*unix_members) {
541 bool is_nt_member = false;
542 for (i=0; i < r->num_rids; i++) {
543 if (nt_members[i] == NULL) {
544 /* This was a primary group */
545 continue;
548 if (strcmp(*unix_members, nt_members[i]) == 0) {
549 is_nt_member = true;
550 break;
553 if (!is_nt_member) {
554 /* We look at a unix group member that is not
555 an nt group member. So, remove it. NT is
556 boss here. */
557 smb_delete_user_group(grp->gr_name, *unix_members);
559 unix_members += 1;
562 for (i=0; i < r->num_rids; i++) {
563 bool is_unix_member = false;
565 if (nt_members[i] == NULL) {
566 /* This was the primary group */
567 continue;
570 unix_members = grp->gr_mem;
572 while (*unix_members) {
573 if (strcmp(*unix_members, nt_members[i]) == 0) {
574 is_unix_member = true;
575 break;
577 unix_members += 1;
580 if (!is_unix_member) {
581 /* We look at a nt group member that is not a
582 unix group member currently. So, add the nt
583 group member. */
584 smb_add_user_group(grp->gr_name, nt_members[i]);
588 return NT_STATUS_OK;
591 /****************************************************************
592 ****************************************************************/
594 static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx,
595 uint32_t rid,
596 struct netr_DELTA_ALIAS *r,
597 const struct dom_sid *dom_sid)
599 struct group *grp = NULL;
600 struct dom_sid alias_sid;
601 fstring sid_string;
602 GROUP_MAP *map;
603 bool insert = true;
605 map = talloc_zero(mem_ctx, GROUP_MAP);
606 if (!map) {
607 return NT_STATUS_NO_MEMORY;
610 /* Find out whether the group is already mapped */
611 sid_compose(&alias_sid, dom_sid, rid);
612 sid_to_fstring(sid_string, &alias_sid);
614 if (pdb_getgrsid(map, alias_sid)) {
615 grp = getgrgid(map->gid);
616 insert = false;
619 map->nt_name = talloc_strdup(map, r->alias_name.string);
620 if (!map->nt_name) {
621 return NT_STATUS_NO_MEMORY;
623 map->comment = talloc_strdup(map, r->description.string);
624 if (!map->comment) {
625 return NT_STATUS_NO_MEMORY;
628 if (grp == NULL) {
629 gid_t gid;
631 /* No group found from mapping, find it from its name. */
632 if ((grp = getgrnam(map->nt_name)) == NULL) {
633 /* No appropriate group found, create one */
634 d_printf("Creating unix group: '%s'\n", map->nt_name);
635 if (smb_create_group(map->nt_name, &gid) != 0)
636 return NT_STATUS_ACCESS_DENIED;
637 if ((grp = getgrgid(gid)) == NULL)
638 return NT_STATUS_ACCESS_DENIED;
642 map->gid = grp->gr_gid;
643 map->sid = alias_sid;
645 if (dom_sid_equal(dom_sid, &global_sid_Builtin)) {
646 map->sid_name_use = SID_NAME_WKN_GRP;
647 } else {
648 map->sid_name_use = SID_NAME_ALIAS;
651 if (insert) {
652 pdb_add_group_mapping_entry(map);
653 } else {
654 pdb_update_group_mapping_entry(map);
657 TALLOC_FREE(map);
658 return NT_STATUS_OK;
661 /****************************************************************
662 ****************************************************************/
664 static NTSTATUS fetch_alias_mem(TALLOC_CTX *mem_ctx,
665 uint32_t rid,
666 struct netr_DELTA_ALIAS_MEMBER *r,
667 const struct dom_sid *dom_sid)
669 return NT_STATUS_OK;
672 /****************************************************************
673 ****************************************************************/
675 static NTSTATUS fetch_domain_info(TALLOC_CTX *mem_ctx,
676 uint32_t rid,
677 struct netr_DELTA_DOMAIN *r)
679 time_t u_max_age, u_min_age, u_logout;
680 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
681 const char *domname;
682 struct netr_AcctLockStr *lockstr = NULL;
683 NTSTATUS status;
685 status = pull_netr_AcctLockStr(mem_ctx, &r->account_lockout,
686 &lockstr);
687 if (!NT_STATUS_IS_OK(status)) {
688 d_printf("failed to pull account lockout string: %s\n",
689 nt_errstr(status));
692 u_max_age = uint64s_nt_time_to_unix_abs((uint64 *)&r->max_password_age);
693 u_min_age = uint64s_nt_time_to_unix_abs((uint64 *)&r->min_password_age);
694 u_logout = uint64s_nt_time_to_unix_abs((uint64 *)&r->force_logoff_time);
696 domname = r->domain_name.string;
697 if (!domname) {
698 return NT_STATUS_NO_MEMORY;
701 /* we don't handle BUILTIN account policies */
702 if (!strequal(domname, get_global_sam_name())) {
703 printf("skipping SAM_DOMAIN_INFO delta for '%s' (is not my domain)\n", domname);
704 return NT_STATUS_OK;
708 if (!pdb_set_account_policy(PDB_POLICY_PASSWORD_HISTORY,
709 r->password_history_length))
710 return nt_status;
712 if (!pdb_set_account_policy(PDB_POLICY_MIN_PASSWORD_LEN,
713 r->min_password_length))
714 return nt_status;
716 if (!pdb_set_account_policy(PDB_POLICY_MAX_PASSWORD_AGE,
717 (uint32)u_max_age))
718 return nt_status;
720 if (!pdb_set_account_policy(PDB_POLICY_MIN_PASSWORD_AGE,
721 (uint32)u_min_age))
722 return nt_status;
724 if (!pdb_set_account_policy(PDB_POLICY_TIME_TO_LOGOUT,
725 (uint32)u_logout))
726 return nt_status;
728 if (lockstr) {
729 time_t u_lockoutreset, u_lockouttime;
731 u_lockoutreset = uint64s_nt_time_to_unix_abs(&lockstr->reset_count);
732 u_lockouttime = uint64s_nt_time_to_unix_abs((uint64_t *)&lockstr->lockout_duration);
734 if (!pdb_set_account_policy(PDB_POLICY_BAD_ATTEMPT_LOCKOUT,
735 lockstr->bad_attempt_lockout))
736 return nt_status;
738 if (!pdb_set_account_policy(PDB_POLICY_RESET_COUNT_TIME,
739 (uint32_t)u_lockoutreset/60))
740 return nt_status;
742 if (u_lockouttime != -1)
743 u_lockouttime /= 60;
745 if (!pdb_set_account_policy(PDB_POLICY_LOCK_ACCOUNT_DURATION,
746 (uint32_t)u_lockouttime))
747 return nt_status;
750 if (!pdb_set_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS,
751 r->logon_to_chgpass))
752 return nt_status;
754 return NT_STATUS_OK;
757 /****************************************************************
758 ****************************************************************/
760 static NTSTATUS fetch_sam_entry(TALLOC_CTX *mem_ctx,
761 enum netr_SamDatabaseID database_id,
762 struct netr_DELTA_ENUM *r,
763 struct samsync_context *ctx)
765 NTSTATUS status = NT_STATUS_NOT_IMPLEMENTED;
767 switch (r->delta_type) {
768 case NETR_DELTA_USER:
769 status = fetch_account_info(mem_ctx,
770 r->delta_id_union.rid,
771 r->delta_union.user);
772 break;
773 case NETR_DELTA_GROUP:
774 status = fetch_group_info(mem_ctx,
775 r->delta_id_union.rid,
776 r->delta_union.group);
777 break;
778 case NETR_DELTA_GROUP_MEMBER:
779 status = fetch_group_mem_info(mem_ctx,
780 r->delta_id_union.rid,
781 r->delta_union.group_member);
782 break;
783 case NETR_DELTA_ALIAS:
784 status = fetch_alias_info(mem_ctx,
785 r->delta_id_union.rid,
786 r->delta_union.alias,
787 ctx->domain_sid);
788 break;
789 case NETR_DELTA_ALIAS_MEMBER:
790 status = fetch_alias_mem(mem_ctx,
791 r->delta_id_union.rid,
792 r->delta_union.alias_member,
793 ctx->domain_sid);
794 break;
795 case NETR_DELTA_DOMAIN:
796 status = fetch_domain_info(mem_ctx,
797 r->delta_id_union.rid,
798 r->delta_union.domain);
799 break;
800 /* The following types are recognised but not handled */
801 case NETR_DELTA_RENAME_GROUP:
802 d_printf("NETR_DELTA_RENAME_GROUP not handled\n");
803 break;
804 case NETR_DELTA_RENAME_USER:
805 d_printf("NETR_DELTA_RENAME_USER not handled\n");
806 break;
807 case NETR_DELTA_RENAME_ALIAS:
808 d_printf("NETR_DELTA_RENAME_ALIAS not handled\n");
809 break;
810 case NETR_DELTA_POLICY:
811 d_printf("NETR_DELTA_POLICY not handled\n");
812 break;
813 case NETR_DELTA_TRUSTED_DOMAIN:
814 d_printf("NETR_DELTA_TRUSTED_DOMAIN not handled\n");
815 break;
816 case NETR_DELTA_ACCOUNT:
817 d_printf("NETR_DELTA_ACCOUNT not handled\n");
818 break;
819 case NETR_DELTA_SECRET:
820 d_printf("NETR_DELTA_SECRET not handled\n");
821 break;
822 case NETR_DELTA_DELETE_GROUP:
823 d_printf("NETR_DELTA_DELETE_GROUP not handled\n");
824 break;
825 case NETR_DELTA_DELETE_USER:
826 d_printf("NETR_DELTA_DELETE_USER not handled\n");
827 break;
828 case NETR_DELTA_MODIFY_COUNT:
829 d_printf("NETR_DELTA_MODIFY_COUNT not handled\n");
830 break;
831 case NETR_DELTA_DELETE_ALIAS:
832 d_printf("NETR_DELTA_DELETE_ALIAS not handled\n");
833 break;
834 case NETR_DELTA_DELETE_TRUST:
835 d_printf("NETR_DELTA_DELETE_TRUST not handled\n");
836 break;
837 case NETR_DELTA_DELETE_ACCOUNT:
838 d_printf("NETR_DELTA_DELETE_ACCOUNT not handled\n");
839 break;
840 case NETR_DELTA_DELETE_SECRET:
841 d_printf("NETR_DELTA_DELETE_SECRET not handled\n");
842 break;
843 case NETR_DELTA_DELETE_GROUP2:
844 d_printf("NETR_DELTA_DELETE_GROUP2 not handled\n");
845 break;
846 case NETR_DELTA_DELETE_USER2:
847 d_printf("NETR_DELTA_DELETE_USER2 not handled\n");
848 break;
849 default:
850 d_printf("Unknown delta record type %d\n", r->delta_type);
851 status = NT_STATUS_INVALID_PARAMETER;
852 break;
855 return status;
858 /****************************************************************
859 ****************************************************************/
861 static NTSTATUS fetch_sam_entries(TALLOC_CTX *mem_ctx,
862 enum netr_SamDatabaseID database_id,
863 struct netr_DELTA_ENUM_ARRAY *r,
864 uint64_t *sequence_num,
865 struct samsync_context *ctx)
867 int i;
869 for (i = 0; i < r->num_deltas; i++) {
870 fetch_sam_entry(mem_ctx, database_id, &r->delta_enum[i], ctx);
873 return NT_STATUS_OK;
876 /****************************************************************
877 ****************************************************************/
879 const struct samsync_ops libnet_samsync_passdb_ops = {
880 .process_objects = fetch_sam_entries,