2 Unix SMB/CIFS implementation.
3 SAMR Pipe utility functions.
5 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
6 Copyright (C) Gerald (Jerry) Carter 2000-2001
7 Copyright (C) Andrew Bartlett 2001-2002
8 Copyright (C) Stefan (metze) Metzmacher 2002
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #define DBGC_CLASS DBGC_RPC_SRV
30 #define STRING_CHANGED (old_string && !new_string) ||\
31 (!old_string && new_string) ||\
32 (old_string && new_string && (strcmp(old_string, new_string) != 0))
34 #define STRING_CHANGED_NC(s1,s2) ((s1) && !(s2)) ||\
36 ((s1) && (s2) && (strcmp((s1), (s2)) != 0))
38 /*************************************************************
39 Copies a SAM_USER_INFO_20 to a struct samu
40 **************************************************************/
42 void copy_id20_to_sam_passwd(struct samu *to, SAM_USER_INFO_20 *from)
44 const char *old_string;
48 if (from == NULL || to == NULL)
51 if (from->hdr_munged_dial.buffer) {
52 old_string = pdb_get_munged_dial(to);
53 mung.length = from->hdr_munged_dial.uni_str_len;
54 mung.data = (uint8 *) from->uni_munged_dial.buffer;
55 new_string = (mung.length == 0) ?
56 NULL : base64_encode_data_blob(mung);
57 DEBUG(10,("INFO_20 UNI_MUNGED_DIAL: %s -> %s\n",old_string, new_string));
58 if (STRING_CHANGED_NC(old_string,new_string))
59 pdb_set_munged_dial(to , new_string, PDB_CHANGED);
61 SAFE_FREE(new_string);
65 /*************************************************************
66 Copies a SAM_USER_INFO_21 to a struct samu
67 **************************************************************/
69 void copy_id21_to_sam_passwd(struct samu *to, SAM_USER_INFO_21 *from)
71 time_t unix_time, stored_time;
72 const char *old_string, *new_string;
75 if (from == NULL || to == NULL)
78 if (from->fields_present & ACCT_LAST_LOGON) {
79 unix_time=nt_time_to_unix(from->logon_time);
80 stored_time = pdb_get_logon_time(to);
81 DEBUG(10,("INFO_21 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
82 if (stored_time != unix_time)
83 pdb_set_logon_time(to, unix_time, PDB_CHANGED);
86 if (from->fields_present & ACCT_LAST_LOGOFF) {
87 unix_time=nt_time_to_unix(from->logoff_time);
88 stored_time = pdb_get_logoff_time(to);
89 DEBUG(10,("INFO_21 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
90 if (stored_time != unix_time)
91 pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
94 if (from->fields_present & ACCT_EXPIRY) {
95 unix_time=nt_time_to_unix(from->kickoff_time);
96 stored_time = pdb_get_kickoff_time(to);
97 DEBUG(10,("INFO_21 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
98 if (stored_time != unix_time)
99 pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
102 if (from->fields_present & ACCT_ALLOW_PWD_CHANGE) {
103 unix_time=nt_time_to_unix(from->pass_can_change_time);
104 stored_time = pdb_get_pass_can_change_time(to);
105 DEBUG(10,("INFO_21 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
106 if (stored_time != unix_time)
107 pdb_set_pass_can_change_time(to, unix_time, PDB_CHANGED);
110 if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
111 unix_time=nt_time_to_unix(from->pass_last_set_time);
112 stored_time = pdb_get_pass_last_set_time(to);
113 DEBUG(10,("INFO_21 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
114 if (stored_time != unix_time)
115 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
118 if (from->fields_present & ACCT_FORCE_PWD_CHANGE) {
119 unix_time=nt_time_to_unix(from->pass_must_change_time);
120 stored_time=pdb_get_pass_must_change_time(to);
121 DEBUG(10,("INFO_21 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
122 if (stored_time != unix_time)
123 pdb_set_pass_must_change_time(to, unix_time, PDB_CHANGED);
126 if ((from->fields_present & ACCT_USERNAME) &&
127 (from->hdr_user_name.buffer)) {
128 old_string = pdb_get_username(to);
129 new_string = unistr2_static(&from->uni_user_name);
130 DEBUG(10,("INFO_21 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
132 pdb_set_username(to , new_string, PDB_CHANGED);
135 if ((from->fields_present & ACCT_FULL_NAME) &&
136 (from->hdr_full_name.buffer)) {
137 old_string = pdb_get_fullname(to);
138 new_string = unistr2_static(&from->uni_full_name);
139 DEBUG(10,("INFO_21 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
141 pdb_set_fullname(to , new_string, PDB_CHANGED);
144 if ((from->fields_present & ACCT_HOME_DIR) &&
145 (from->hdr_home_dir.buffer)) {
146 old_string = pdb_get_homedir(to);
147 new_string = unistr2_static(&from->uni_home_dir);
148 DEBUG(10,("INFO_21 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
150 pdb_set_homedir(to , new_string, PDB_CHANGED);
153 if ((from->fields_present & ACCT_HOME_DRIVE) &&
154 (from->hdr_dir_drive.buffer)) {
155 old_string = pdb_get_dir_drive(to);
156 new_string = unistr2_static(&from->uni_dir_drive);
157 DEBUG(10,("INFO_21 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
159 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
162 if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
163 (from->hdr_logon_script.buffer)) {
164 old_string = pdb_get_logon_script(to);
165 new_string = unistr2_static(&from->uni_logon_script);
166 DEBUG(10,("INFO_21 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
168 pdb_set_logon_script(to , new_string, PDB_CHANGED);
171 if ((from->fields_present & ACCT_PROFILE) &&
172 (from->hdr_profile_path.buffer)) {
173 old_string = pdb_get_profile_path(to);
174 new_string = unistr2_static(&from->uni_profile_path);
175 DEBUG(10,("INFO_21 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
177 pdb_set_profile_path(to , new_string, PDB_CHANGED);
180 if ((from->fields_present & ACCT_DESCRIPTION) &&
181 (from->hdr_acct_desc.buffer)) {
182 old_string = pdb_get_acct_desc(to);
183 new_string = unistr2_static(&from->uni_acct_desc);
184 DEBUG(10,("INFO_21 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
186 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
189 if ((from->fields_present & ACCT_WORKSTATIONS) &&
190 (from->hdr_workstations.buffer)) {
191 old_string = pdb_get_workstations(to);
192 new_string = unistr2_static(&from->uni_workstations);
193 DEBUG(10,("INFO_21 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
195 pdb_set_workstations(to , new_string, PDB_CHANGED);
198 if ((from->fields_present & ACCT_COMMENT) &&
199 (from->hdr_comment.buffer)) {
200 old_string = pdb_get_comment(to);
201 new_string = unistr2_static(&from->uni_comment);
202 DEBUG(10,("INFO_21 UNI_COMMENT: %s -> %s\n",old_string, new_string));
204 pdb_set_comment(to, new_string, PDB_CHANGED);
207 if ((from->fields_present & ACCT_CALLBACK) &&
208 (from->hdr_munged_dial.buffer)) {
210 old_string = pdb_get_munged_dial(to);
211 mung.length = from->hdr_munged_dial.uni_str_len;
212 mung.data = (uint8 *) from->uni_munged_dial.buffer;
213 newstr = (mung.length == 0) ?
214 NULL : base64_encode_data_blob(mung);
215 DEBUG(10,("INFO_21 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
216 if (STRING_CHANGED_NC(old_string,newstr))
217 pdb_set_munged_dial(to , newstr, PDB_CHANGED);
222 if (from->fields_present & ACCT_RID) {
223 if (from->user_rid == 0) {
224 DEBUG(10, ("INFO_21: Asked to set User RID to 0 !? Skipping change!\n"));
225 } else if (from->user_rid != pdb_get_user_rid(to)) {
226 DEBUG(10,("INFO_21 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
230 if (from->fields_present & ACCT_PRIMARY_GID) {
231 if (from->group_rid == 0) {
232 DEBUG(10, ("INFO_21: Asked to set Group RID to 0 !? Skipping change!\n"));
233 } else if (from->group_rid != pdb_get_group_rid(to)) {
234 DEBUG(10,("INFO_21 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
235 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
239 if (from->fields_present & ACCT_FLAGS) {
240 DEBUG(10,("INFO_21 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
241 if (from->acb_info != pdb_get_acct_ctrl(to)) {
242 if (!(from->acb_info & ACB_AUTOLOCK) && (pdb_get_acct_ctrl(to) & ACB_AUTOLOCK)) {
243 /* We're unlocking a previously locked user. Reset bad password counts.
244 Patch from Jianliang Lu. <Jianliang.Lu@getronics.com> */
245 pdb_set_bad_password_count(to, 0, PDB_CHANGED);
246 pdb_set_bad_password_time(to, 0, PDB_CHANGED);
248 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
252 if (from->fields_present & ACCT_LOGON_HOURS) {
253 pstring oldstr, newstr;
254 DEBUG(15,("INFO_21 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
255 if (from->logon_divs != pdb_get_logon_divs(to)) {
256 pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
259 DEBUG(15,("INFO_21 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
260 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
261 pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
264 DEBUG(15,("INFO_21 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
265 pdb_sethexhours(oldstr, pdb_get_hours(to));
266 pdb_sethexhours(newstr, from->logon_hrs.hours);
267 if (!strequal(oldstr, newstr)) {
268 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
272 if (from->fields_present & ACCT_BAD_PWD_COUNT) {
273 DEBUG(10,("INFO_21 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
274 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
275 pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
279 if (from->fields_present & ACCT_NUM_LOGONS) {
280 DEBUG(10,("INFO_21 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
281 if (from->logon_count != pdb_get_logon_count(to)) {
282 pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
286 DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
287 if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
288 pdb_set_pass_must_change_time(to,0, PDB_CHANGED);
292 if (pdb_get_pass_must_change_time(to) == 0) {
293 if (!pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &expire)
294 || expire == (uint32)-1) {
295 new_time = get_time_t_max();
297 time_t old_time = pdb_get_pass_last_set_time(to);
298 new_time = old_time + expire;
299 if ((new_time) < time(0)) {
300 new_time = time(0) + expire;
303 if (!pdb_set_pass_must_change_time (to, new_time, PDB_CHANGED)) {
304 DEBUG (0, ("pdb_set_pass_must_change_time failed!\n"));
309 DEBUG(10,("INFO_21 PADDING_2: %02X\n",from->padding2));
313 /*************************************************************
314 Copies a SAM_USER_INFO_23 to a struct samu
315 **************************************************************/
317 void copy_id23_to_sam_passwd(struct samu *to, SAM_USER_INFO_23 *from)
319 time_t unix_time, stored_time;
320 const char *old_string, *new_string;
323 if (from == NULL || to == NULL)
326 if (from->fields_present & ACCT_LAST_LOGON) {
327 unix_time=nt_time_to_unix(from->logon_time);
328 stored_time = pdb_get_logon_time(to);
329 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
330 if (stored_time != unix_time)
331 pdb_set_logon_time(to, unix_time, PDB_CHANGED);
334 if (from->fields_present & ACCT_LAST_LOGOFF) {
335 unix_time=nt_time_to_unix(from->logoff_time);
336 stored_time = pdb_get_logoff_time(to);
337 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
338 if (stored_time != unix_time)
339 pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
342 if (from->fields_present & ACCT_EXPIRY) {
343 unix_time=nt_time_to_unix(from->kickoff_time);
344 stored_time = pdb_get_kickoff_time(to);
345 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
346 if (stored_time != unix_time)
347 pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
350 if (from->fields_present & ACCT_ALLOW_PWD_CHANGE) {
351 unix_time=nt_time_to_unix(from->pass_can_change_time);
352 stored_time = pdb_get_pass_can_change_time(to);
353 DEBUG(10,("INFO_23 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
354 if (stored_time != unix_time)
355 pdb_set_pass_can_change_time(to, unix_time, PDB_CHANGED);
358 if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
359 unix_time=nt_time_to_unix(from->pass_last_set_time);
360 stored_time = pdb_get_pass_last_set_time(to);
361 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
362 if (stored_time != unix_time)
363 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
366 if (from->fields_present & ACCT_FORCE_PWD_CHANGE) {
367 unix_time=nt_time_to_unix(from->pass_must_change_time);
368 stored_time=pdb_get_pass_must_change_time(to);
369 DEBUG(10,("INFO_23 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
370 if (stored_time != unix_time)
371 pdb_set_pass_must_change_time(to, unix_time, PDB_CHANGED);
374 /* Backend should check this for sanity */
375 if ((from->fields_present & ACCT_USERNAME) &&
376 (from->hdr_user_name.buffer)) {
377 old_string = pdb_get_username(to);
378 new_string = unistr2_static(&from->uni_user_name);
379 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
381 pdb_set_username(to , new_string, PDB_CHANGED);
384 if ((from->fields_present & ACCT_FULL_NAME) &&
385 (from->hdr_full_name.buffer)) {
386 old_string = pdb_get_fullname(to);
387 new_string = unistr2_static(&from->uni_full_name);
388 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
390 pdb_set_fullname(to , new_string, PDB_CHANGED);
393 if ((from->fields_present & ACCT_HOME_DIR) &&
394 (from->hdr_home_dir.buffer)) {
395 old_string = pdb_get_homedir(to);
396 new_string = unistr2_static(&from->uni_home_dir);
397 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
399 pdb_set_homedir(to , new_string, PDB_CHANGED);
402 if ((from->fields_present & ACCT_HOME_DRIVE) &&
403 (from->hdr_dir_drive.buffer)) {
404 old_string = pdb_get_dir_drive(to);
405 new_string = unistr2_static(&from->uni_dir_drive);
406 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
408 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
411 if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
412 (from->hdr_logon_script.buffer)) {
413 old_string = pdb_get_logon_script(to);
414 new_string = unistr2_static(&from->uni_logon_script);
415 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
417 pdb_set_logon_script(to , new_string, PDB_CHANGED);
420 if ((from->fields_present & ACCT_PROFILE) &&
421 (from->hdr_profile_path.buffer)) {
422 old_string = pdb_get_profile_path(to);
423 new_string = unistr2_static(&from->uni_profile_path);
424 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
426 pdb_set_profile_path(to , new_string, PDB_CHANGED);
429 if ((from->fields_present & ACCT_DESCRIPTION) &&
430 (from->hdr_acct_desc.buffer)) {
431 old_string = pdb_get_acct_desc(to);
432 new_string = unistr2_static(&from->uni_acct_desc);
433 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
435 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
438 if ((from->fields_present & ACCT_WORKSTATIONS) &&
439 (from->hdr_workstations.buffer)) {
440 old_string = pdb_get_workstations(to);
441 new_string = unistr2_static(&from->uni_workstations);
442 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
444 pdb_set_workstations(to , new_string, PDB_CHANGED);
447 if ((from->fields_present & ACCT_COMMENT) &&
448 (from->hdr_comment.buffer)) {
449 old_string = pdb_get_comment(to);
450 new_string = unistr2_static(&from->uni_comment);
451 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
453 pdb_set_comment(to , new_string, PDB_CHANGED);
456 if ((from->fields_present & ACCT_CALLBACK) &&
457 (from->hdr_munged_dial.buffer)) {
459 old_string = pdb_get_munged_dial(to);
460 mung.length = from->hdr_munged_dial.uni_str_len;
461 mung.data = (uint8 *) from->uni_munged_dial.buffer;
462 newstr = (mung.length == 0) ?
463 NULL : base64_encode_data_blob(mung);
464 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
465 if (STRING_CHANGED_NC(old_string, newstr))
466 pdb_set_munged_dial(to , newstr, PDB_CHANGED);
471 if (from->fields_present & ACCT_RID) {
472 if (from->user_rid == 0) {
473 DEBUG(10, ("INFO_23: Asked to set User RID to 0 !? Skipping change!\n"));
474 } else if (from->user_rid != pdb_get_user_rid(to)) {
475 DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
479 if (from->fields_present & ACCT_PRIMARY_GID) {
480 if (from->group_rid == 0) {
481 DEBUG(10, ("INFO_23: Asked to set Group RID to 0 !? Skipping change!\n"));
482 } else if (from->group_rid != pdb_get_group_rid(to)) {
483 DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
484 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
488 if (from->fields_present & ACCT_FLAGS) {
489 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
490 if (from->acb_info != pdb_get_acct_ctrl(to)) {
491 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
495 if (from->fields_present & ACCT_LOGON_HOURS) {
496 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
497 if (from->logon_divs != pdb_get_logon_divs(to)) {
498 pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
501 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
502 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
503 pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
506 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
507 /* Fix me: only update if it changes --metze */
508 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
511 if (from->fields_present & ACCT_BAD_PWD_COUNT) {
512 DEBUG(10,("INFO_23 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
513 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
514 pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
518 if (from->fields_present & ACCT_NUM_LOGONS) {
519 DEBUG(10,("INFO_23 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
520 if (from->logon_count != pdb_get_logon_count(to)) {
521 pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
525 DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
526 if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
527 pdb_set_pass_must_change_time(to,0, PDB_CHANGED);
531 if (pdb_get_pass_must_change_time(to) == 0) {
532 if (!pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &expire)
533 || expire == (uint32)-1) {
534 new_time = get_time_t_max();
536 time_t old_time = pdb_get_pass_last_set_time(to);
537 new_time = old_time + expire;
538 if ((new_time) < time(0)) {
539 new_time = time(0) + expire;
542 if (!pdb_set_pass_must_change_time (to, new_time, PDB_CHANGED)) {
543 DEBUG (0, ("pdb_set_pass_must_change_time failed!\n"));
548 DEBUG(10,("INFO_23 PADDING_2: %02X\n",from->padding2));
551 /*************************************************************
552 Copies a SAM_USER_INFO_25 to a struct samu
553 **************************************************************/
555 void copy_id25_to_sam_passwd(struct samu *to, SAM_USER_INFO_25 *from)
557 time_t unix_time, stored_time;
558 const char *old_string, *new_string;
561 if (from == NULL || to == NULL)
564 if (from->fields_present & ACCT_LAST_LOGON) {
565 unix_time=nt_time_to_unix(from->logon_time);
566 stored_time = pdb_get_logon_time(to);
567 DEBUG(10,("INFO_25 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
568 if (stored_time != unix_time)
569 pdb_set_logon_time(to, unix_time, PDB_CHANGED);
572 if (from->fields_present & ACCT_LAST_LOGOFF) {
573 unix_time=nt_time_to_unix(from->logoff_time);
574 stored_time = pdb_get_logoff_time(to);
575 DEBUG(10,("INFO_25 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
576 if (stored_time != unix_time)
577 pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
580 if (from->fields_present & ACCT_EXPIRY) {
581 unix_time=nt_time_to_unix(from->kickoff_time);
582 stored_time = pdb_get_kickoff_time(to);
583 DEBUG(10,("INFO_25 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
584 if (stored_time != unix_time)
585 pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
588 if (from->fields_present & ACCT_ALLOW_PWD_CHANGE) {
589 unix_time=nt_time_to_unix(from->pass_can_change_time);
590 stored_time = pdb_get_pass_can_change_time(to);
591 DEBUG(10,("INFO_25 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
592 if (stored_time != unix_time)
593 pdb_set_pass_can_change_time(to, unix_time, PDB_CHANGED);
596 if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
597 unix_time=nt_time_to_unix(from->pass_last_set_time);
598 stored_time = pdb_get_pass_last_set_time(to);
599 DEBUG(10,("INFO_25 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
600 if (stored_time != unix_time)
601 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
604 if (from->fields_present & ACCT_FORCE_PWD_CHANGE) {
605 unix_time=nt_time_to_unix(from->pass_must_change_time);
606 stored_time=pdb_get_pass_must_change_time(to);
607 DEBUG(10,("INFO_25 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
608 if (stored_time != unix_time)
609 pdb_set_pass_must_change_time(to, unix_time, PDB_CHANGED);
612 if ((from->fields_present & ACCT_USERNAME) &&
613 (from->hdr_user_name.buffer)) {
614 old_string = pdb_get_username(to);
615 new_string = unistr2_static(&from->uni_user_name);
616 DEBUG(10,("INFO_25 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
618 pdb_set_username(to , new_string, PDB_CHANGED);
621 if ((from->fields_present & ACCT_FULL_NAME) &&
622 (from->hdr_full_name.buffer)) {
623 old_string = pdb_get_fullname(to);
624 new_string = unistr2_static(&from->uni_full_name);
625 DEBUG(10,("INFO_25 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
627 pdb_set_fullname(to , new_string, PDB_CHANGED);
630 if ((from->fields_present & ACCT_HOME_DIR) &&
631 (from->hdr_home_dir.buffer)) {
632 old_string = pdb_get_homedir(to);
633 new_string = unistr2_static(&from->uni_home_dir);
634 DEBUG(10,("INFO_25 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
636 pdb_set_homedir(to , new_string, PDB_CHANGED);
639 if ((from->fields_present & ACCT_HOME_DRIVE) &&
640 (from->hdr_dir_drive.buffer)) {
641 old_string = pdb_get_dir_drive(to);
642 new_string = unistr2_static(&from->uni_dir_drive);
643 DEBUG(10,("INFO_25 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
645 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
648 if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
649 (from->hdr_logon_script.buffer)) {
650 old_string = pdb_get_logon_script(to);
651 new_string = unistr2_static(&from->uni_logon_script);
652 DEBUG(10,("INFO_25 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
654 pdb_set_logon_script(to , new_string, PDB_CHANGED);
657 if ((from->fields_present & ACCT_PROFILE) &&
658 (from->hdr_profile_path.buffer)) {
659 old_string = pdb_get_profile_path(to);
660 new_string = unistr2_static(&from->uni_profile_path);
661 DEBUG(10,("INFO_25 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
663 pdb_set_profile_path(to , new_string, PDB_CHANGED);
666 if ((from->fields_present & ACCT_DESCRIPTION) &&
667 (from->hdr_acct_desc.buffer)) {
668 old_string = pdb_get_acct_desc(to);
669 new_string = unistr2_static(&from->uni_acct_desc);
670 DEBUG(10,("INFO_25 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
672 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
675 if ((from->fields_present & ACCT_WORKSTATIONS) &&
676 (from->hdr_workstations.buffer)) {
677 old_string = pdb_get_workstations(to);
678 new_string = unistr2_static(&from->uni_workstations);
679 DEBUG(10,("INFO_25 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
681 pdb_set_workstations(to , new_string, PDB_CHANGED);
684 if ((from->fields_present & ACCT_COMMENT) &&
685 (from->hdr_comment.buffer)) {
686 old_string = pdb_get_comment(to);
687 new_string = unistr2_static(&from->uni_comment);
688 DEBUG(10,("INFO_25 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
690 pdb_set_comment(to , new_string, PDB_CHANGED);
693 if ((from->fields_present & ACCT_CALLBACK) &&
694 (from->hdr_munged_dial.buffer)) {
696 old_string = pdb_get_munged_dial(to);
697 mung.length = from->hdr_munged_dial.uni_str_len;
698 mung.data = (uint8 *) from->uni_munged_dial.buffer;
699 newstr = (mung.length == 0) ?
700 NULL : base64_encode_data_blob(mung);
701 DEBUG(10,("INFO_25 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
702 if (STRING_CHANGED_NC(old_string,newstr))
703 pdb_set_munged_dial(to , newstr, PDB_CHANGED);
708 if (from->fields_present & ACCT_RID) {
709 if (from->user_rid == 0) {
710 DEBUG(10, ("INFO_25: Asked to set User RID to 0 !? Skipping change!\n"));
711 } else if (from->user_rid != pdb_get_user_rid(to)) {
712 DEBUG(10,("INFO_25 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
716 if (from->fields_present & ACCT_PRIMARY_GID) {
717 if (from->group_rid == 0) {
718 DEBUG(10, ("INFO_25: Asked to set Group RID to 0 !? Skipping change!\n"));
719 } else if (from->group_rid != pdb_get_group_rid(to)) {
720 DEBUG(10,("INFO_25 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
721 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
725 if (from->fields_present & ACCT_FLAGS) {
726 DEBUG(10,("INFO_25 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
727 if (from->acb_info != pdb_get_acct_ctrl(to)) {
728 if (!(from->acb_info & ACB_AUTOLOCK) && (pdb_get_acct_ctrl(to) & ACB_AUTOLOCK)) {
729 /* We're unlocking a previously locked user. Reset bad password counts.
730 Patch from Jianliang Lu. <Jianliang.Lu@getronics.com> */
731 pdb_set_bad_password_count(to, 0, PDB_CHANGED);
732 pdb_set_bad_password_time(to, 0, PDB_CHANGED);
734 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);