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 3 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, see <http://www.gnu.org/licenses/>.
27 #define DBGC_CLASS DBGC_RPC_SRV
29 #define STRING_CHANGED (old_string && !new_string) ||\
30 (!old_string && new_string) ||\
31 (old_string && new_string && (strcmp(old_string, new_string) != 0))
33 #define STRING_CHANGED_NC(s1,s2) ((s1) && !(s2)) ||\
35 ((s1) && (s2) && (strcmp((s1), (s2)) != 0))
37 /*************************************************************
38 Copies a SAM_USER_INFO_20 to a struct samu
39 **************************************************************/
41 void copy_id20_to_sam_passwd(struct samu *to, SAM_USER_INFO_20 *from)
43 const char *old_string;
47 if (from == NULL || to == NULL)
50 if (from->hdr_munged_dial.buffer) {
51 old_string = pdb_get_munged_dial(to);
52 mung.length = from->hdr_munged_dial.uni_str_len;
53 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 TALLOC_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_LAST_PWD_CHANGE) {
103 unix_time=nt_time_to_unix(from->pass_last_set_time);
104 stored_time = pdb_get_pass_last_set_time(to);
105 DEBUG(10,("INFO_21 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
106 if (stored_time != unix_time)
107 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
110 if ((from->fields_present & ACCT_USERNAME) &&
111 (from->hdr_user_name.buffer)) {
112 old_string = pdb_get_username(to);
113 new_string = unistr2_static(&from->uni_user_name);
114 DEBUG(10,("INFO_21 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
116 pdb_set_username(to , new_string, PDB_CHANGED);
119 if ((from->fields_present & ACCT_FULL_NAME) &&
120 (from->hdr_full_name.buffer)) {
121 old_string = pdb_get_fullname(to);
122 new_string = unistr2_static(&from->uni_full_name);
123 DEBUG(10,("INFO_21 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
125 pdb_set_fullname(to , new_string, PDB_CHANGED);
128 if ((from->fields_present & ACCT_HOME_DIR) &&
129 (from->hdr_home_dir.buffer)) {
130 old_string = pdb_get_homedir(to);
131 new_string = unistr2_static(&from->uni_home_dir);
132 DEBUG(10,("INFO_21 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
134 pdb_set_homedir(to , new_string, PDB_CHANGED);
137 if ((from->fields_present & ACCT_HOME_DRIVE) &&
138 (from->hdr_dir_drive.buffer)) {
139 old_string = pdb_get_dir_drive(to);
140 new_string = unistr2_static(&from->uni_dir_drive);
141 DEBUG(10,("INFO_21 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
143 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
146 if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
147 (from->hdr_logon_script.buffer)) {
148 old_string = pdb_get_logon_script(to);
149 new_string = unistr2_static(&from->uni_logon_script);
150 DEBUG(10,("INFO_21 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
152 pdb_set_logon_script(to , new_string, PDB_CHANGED);
155 if ((from->fields_present & ACCT_PROFILE) &&
156 (from->hdr_profile_path.buffer)) {
157 old_string = pdb_get_profile_path(to);
158 new_string = unistr2_static(&from->uni_profile_path);
159 DEBUG(10,("INFO_21 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
161 pdb_set_profile_path(to , new_string, PDB_CHANGED);
164 if ((from->fields_present & ACCT_DESCRIPTION) &&
165 (from->hdr_acct_desc.buffer)) {
166 old_string = pdb_get_acct_desc(to);
167 new_string = unistr2_static(&from->uni_acct_desc);
168 DEBUG(10,("INFO_21 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
170 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
173 if ((from->fields_present & ACCT_WORKSTATIONS) &&
174 (from->hdr_workstations.buffer)) {
175 old_string = pdb_get_workstations(to);
176 new_string = unistr2_static(&from->uni_workstations);
177 DEBUG(10,("INFO_21 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
179 pdb_set_workstations(to , new_string, PDB_CHANGED);
182 if ((from->fields_present & ACCT_COMMENT) &&
183 (from->hdr_comment.buffer)) {
184 old_string = pdb_get_comment(to);
185 new_string = unistr2_static(&from->uni_comment);
186 DEBUG(10,("INFO_21 UNI_COMMENT: %s -> %s\n",old_string, new_string));
188 pdb_set_comment(to, new_string, PDB_CHANGED);
191 if ((from->fields_present & ACCT_CALLBACK) &&
192 (from->hdr_munged_dial.buffer)) {
194 old_string = pdb_get_munged_dial(to);
195 mung.length = from->hdr_munged_dial.uni_str_len;
196 mung.data = (uint8 *) from->uni_munged_dial.buffer;
198 newstr = (mung.length == 0) ?
199 NULL : base64_encode_data_blob(mung);
200 DEBUG(10,("INFO_21 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
201 if (STRING_CHANGED_NC(old_string,newstr))
202 pdb_set_munged_dial(to , newstr, PDB_CHANGED);
207 if (from->fields_present & ACCT_RID) {
208 if (from->user_rid == 0) {
209 DEBUG(10, ("INFO_21: Asked to set User RID to 0 !? Skipping change!\n"));
210 } else if (from->user_rid != pdb_get_user_rid(to)) {
211 DEBUG(10,("INFO_21 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
215 if (from->fields_present & ACCT_PRIMARY_GID) {
216 if (from->group_rid == 0) {
217 DEBUG(10, ("INFO_21: Asked to set Group RID to 0 !? Skipping change!\n"));
218 } else if (from->group_rid != pdb_get_group_rid(to)) {
219 DEBUG(10,("INFO_21 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
220 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
224 if (from->fields_present & ACCT_FLAGS) {
225 DEBUG(10,("INFO_21 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
226 if (from->acb_info != pdb_get_acct_ctrl(to)) {
227 if (!(from->acb_info & ACB_AUTOLOCK) && (pdb_get_acct_ctrl(to) & ACB_AUTOLOCK)) {
228 /* We're unlocking a previously locked user. Reset bad password counts.
229 Patch from Jianliang Lu. <Jianliang.Lu@getronics.com> */
230 pdb_set_bad_password_count(to, 0, PDB_CHANGED);
231 pdb_set_bad_password_time(to, 0, PDB_CHANGED);
233 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
237 if (from->fields_present & ACCT_LOGON_HOURS) {
238 char oldstr[44]; /* hours strings are 42 bytes. */
240 DEBUG(15,("INFO_21 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
241 if (from->logon_divs != pdb_get_logon_divs(to)) {
242 pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
245 DEBUG(15,("INFO_21 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
246 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
247 pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
250 DEBUG(15,("INFO_21 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
251 pdb_sethexhours(oldstr, pdb_get_hours(to));
252 pdb_sethexhours(newstr, from->logon_hrs.hours);
253 if (!strequal(oldstr, newstr)) {
254 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
258 if (from->fields_present & ACCT_BAD_PWD_COUNT) {
259 DEBUG(10,("INFO_21 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
260 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
261 pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
265 if (from->fields_present & ACCT_NUM_LOGONS) {
266 DEBUG(10,("INFO_21 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
267 if (from->logon_count != pdb_get_logon_count(to)) {
268 pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
272 /* If the must change flag is set, the last set time goes to zero.
273 the must change and can change fields also do, but they are
274 calculated from policy, not set from the wire */
276 if (from->fields_present & ACCT_EXPIRED_FLAG) {
277 DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
278 if (from->passmustchange == PASS_MUST_CHANGE_AT_NEXT_LOGON) {
279 pdb_set_pass_last_set_time(to, 0, PDB_CHANGED);
281 pdb_set_pass_last_set_time(to, time(NULL),PDB_CHANGED);
285 DEBUG(10,("INFO_21 PADDING_2: %02X\n",from->padding2));
289 /*************************************************************
290 Copies a SAM_USER_INFO_23 to a struct samu
291 **************************************************************/
293 void copy_id23_to_sam_passwd(struct samu *to, SAM_USER_INFO_23 *from)
295 time_t unix_time, stored_time;
296 const char *old_string, *new_string;
299 if (from == NULL || to == NULL)
302 if (from->fields_present & ACCT_LAST_LOGON) {
303 unix_time=nt_time_to_unix(from->logon_time);
304 stored_time = pdb_get_logon_time(to);
305 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
306 if (stored_time != unix_time)
307 pdb_set_logon_time(to, unix_time, PDB_CHANGED);
310 if (from->fields_present & ACCT_LAST_LOGOFF) {
311 unix_time=nt_time_to_unix(from->logoff_time);
312 stored_time = pdb_get_logoff_time(to);
313 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
314 if (stored_time != unix_time)
315 pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
318 if (from->fields_present & ACCT_EXPIRY) {
319 unix_time=nt_time_to_unix(from->kickoff_time);
320 stored_time = pdb_get_kickoff_time(to);
321 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
322 if (stored_time != unix_time)
323 pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
326 if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
327 unix_time=nt_time_to_unix(from->pass_last_set_time);
328 stored_time = pdb_get_pass_last_set_time(to);
329 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
330 if (stored_time != unix_time)
331 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
334 /* Backend should check this for sanity */
335 if ((from->fields_present & ACCT_USERNAME) &&
336 (from->hdr_user_name.buffer)) {
337 old_string = pdb_get_username(to);
338 new_string = unistr2_static(&from->uni_user_name);
339 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
341 pdb_set_username(to , new_string, PDB_CHANGED);
344 if ((from->fields_present & ACCT_FULL_NAME) &&
345 (from->hdr_full_name.buffer)) {
346 old_string = pdb_get_fullname(to);
347 new_string = unistr2_static(&from->uni_full_name);
348 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
350 pdb_set_fullname(to , new_string, PDB_CHANGED);
353 if ((from->fields_present & ACCT_HOME_DIR) &&
354 (from->hdr_home_dir.buffer)) {
355 old_string = pdb_get_homedir(to);
356 new_string = unistr2_static(&from->uni_home_dir);
357 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
359 pdb_set_homedir(to , new_string, PDB_CHANGED);
362 if ((from->fields_present & ACCT_HOME_DRIVE) &&
363 (from->hdr_dir_drive.buffer)) {
364 old_string = pdb_get_dir_drive(to);
365 new_string = unistr2_static(&from->uni_dir_drive);
366 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
368 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
371 if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
372 (from->hdr_logon_script.buffer)) {
373 old_string = pdb_get_logon_script(to);
374 new_string = unistr2_static(&from->uni_logon_script);
375 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
377 pdb_set_logon_script(to , new_string, PDB_CHANGED);
380 if ((from->fields_present & ACCT_PROFILE) &&
381 (from->hdr_profile_path.buffer)) {
382 old_string = pdb_get_profile_path(to);
383 new_string = unistr2_static(&from->uni_profile_path);
384 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
386 pdb_set_profile_path(to , new_string, PDB_CHANGED);
389 if ((from->fields_present & ACCT_DESCRIPTION) &&
390 (from->hdr_acct_desc.buffer)) {
391 old_string = pdb_get_acct_desc(to);
392 new_string = unistr2_static(&from->uni_acct_desc);
393 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
395 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
398 if ((from->fields_present & ACCT_WORKSTATIONS) &&
399 (from->hdr_workstations.buffer)) {
400 old_string = pdb_get_workstations(to);
401 new_string = unistr2_static(&from->uni_workstations);
402 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
404 pdb_set_workstations(to , new_string, PDB_CHANGED);
407 if ((from->fields_present & ACCT_COMMENT) &&
408 (from->hdr_comment.buffer)) {
409 old_string = pdb_get_comment(to);
410 new_string = unistr2_static(&from->uni_comment);
411 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
413 pdb_set_comment(to , new_string, PDB_CHANGED);
416 if ((from->fields_present & ACCT_CALLBACK) &&
417 (from->hdr_munged_dial.buffer)) {
419 old_string = pdb_get_munged_dial(to);
420 mung.length = from->hdr_munged_dial.uni_str_len;
421 mung.data = (uint8 *) from->uni_munged_dial.buffer;
423 newstr = (mung.length == 0) ?
424 NULL : base64_encode_data_blob(mung);
425 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
426 if (STRING_CHANGED_NC(old_string, newstr))
427 pdb_set_munged_dial(to , newstr, PDB_CHANGED);
432 if (from->fields_present & ACCT_RID) {
433 if (from->user_rid == 0) {
434 DEBUG(10, ("INFO_23: Asked to set User RID to 0 !? Skipping change!\n"));
435 } else if (from->user_rid != pdb_get_user_rid(to)) {
436 DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
440 if (from->fields_present & ACCT_PRIMARY_GID) {
441 if (from->group_rid == 0) {
442 DEBUG(10, ("INFO_23: Asked to set Group RID to 0 !? Skipping change!\n"));
443 } else if (from->group_rid != pdb_get_group_rid(to)) {
444 DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
445 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
449 if (from->fields_present & ACCT_FLAGS) {
450 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
451 if (from->acb_info != pdb_get_acct_ctrl(to)) {
452 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
456 if (from->fields_present & ACCT_LOGON_HOURS) {
457 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
458 if (from->logon_divs != pdb_get_logon_divs(to)) {
459 pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
462 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
463 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
464 pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
467 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
468 /* Fix me: only update if it changes --metze */
469 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
472 if (from->fields_present & ACCT_BAD_PWD_COUNT) {
473 DEBUG(10,("INFO_23 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
474 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
475 pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
479 if (from->fields_present & ACCT_NUM_LOGONS) {
480 DEBUG(10,("INFO_23 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
481 if (from->logon_count != pdb_get_logon_count(to)) {
482 pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
486 /* If the must change flag is set, the last set time goes to zero.
487 the must change and can change fields also do, but they are
488 calculated from policy, not set from the wire */
490 if (from->fields_present & ACCT_EXPIRED_FLAG) {
491 DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
492 if (from->passmustchange == PASS_MUST_CHANGE_AT_NEXT_LOGON) {
493 pdb_set_pass_last_set_time(to, 0, PDB_CHANGED);
495 pdb_set_pass_last_set_time(to, time(NULL),PDB_CHANGED);
499 DEBUG(10,("INFO_23 PADDING_2: %02X\n",from->padding2));
502 /*************************************************************
503 Copies a SAM_USER_INFO_25 to a struct samu
504 **************************************************************/
506 void copy_id25_to_sam_passwd(struct samu *to, SAM_USER_INFO_25 *from)
508 time_t unix_time, stored_time;
509 const char *old_string, *new_string;
512 if (from == NULL || to == NULL)
515 if (from->fields_present & ACCT_LAST_LOGON) {
516 unix_time=nt_time_to_unix(from->logon_time);
517 stored_time = pdb_get_logon_time(to);
518 DEBUG(10,("INFO_25 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
519 if (stored_time != unix_time)
520 pdb_set_logon_time(to, unix_time, PDB_CHANGED);
523 if (from->fields_present & ACCT_LAST_LOGOFF) {
524 unix_time=nt_time_to_unix(from->logoff_time);
525 stored_time = pdb_get_logoff_time(to);
526 DEBUG(10,("INFO_25 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
527 if (stored_time != unix_time)
528 pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
531 if (from->fields_present & ACCT_EXPIRY) {
532 unix_time=nt_time_to_unix(from->kickoff_time);
533 stored_time = pdb_get_kickoff_time(to);
534 DEBUG(10,("INFO_25 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
535 if (stored_time != unix_time)
536 pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
539 if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
540 unix_time=nt_time_to_unix(from->pass_last_set_time);
541 stored_time = pdb_get_pass_last_set_time(to);
542 DEBUG(10,("INFO_25 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
543 if (stored_time != unix_time)
544 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
547 if ((from->fields_present & ACCT_USERNAME) &&
548 (from->hdr_user_name.buffer)) {
549 old_string = pdb_get_username(to);
550 new_string = unistr2_static(&from->uni_user_name);
551 DEBUG(10,("INFO_25 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
553 pdb_set_username(to , new_string, PDB_CHANGED);
556 if ((from->fields_present & ACCT_FULL_NAME) &&
557 (from->hdr_full_name.buffer)) {
558 old_string = pdb_get_fullname(to);
559 new_string = unistr2_static(&from->uni_full_name);
560 DEBUG(10,("INFO_25 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
562 pdb_set_fullname(to , new_string, PDB_CHANGED);
565 if ((from->fields_present & ACCT_HOME_DIR) &&
566 (from->hdr_home_dir.buffer)) {
567 old_string = pdb_get_homedir(to);
568 new_string = unistr2_static(&from->uni_home_dir);
569 DEBUG(10,("INFO_25 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
571 pdb_set_homedir(to , new_string, PDB_CHANGED);
574 if ((from->fields_present & ACCT_HOME_DRIVE) &&
575 (from->hdr_dir_drive.buffer)) {
576 old_string = pdb_get_dir_drive(to);
577 new_string = unistr2_static(&from->uni_dir_drive);
578 DEBUG(10,("INFO_25 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
580 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
583 if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
584 (from->hdr_logon_script.buffer)) {
585 old_string = pdb_get_logon_script(to);
586 new_string = unistr2_static(&from->uni_logon_script);
587 DEBUG(10,("INFO_25 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
589 pdb_set_logon_script(to , new_string, PDB_CHANGED);
592 if ((from->fields_present & ACCT_PROFILE) &&
593 (from->hdr_profile_path.buffer)) {
594 old_string = pdb_get_profile_path(to);
595 new_string = unistr2_static(&from->uni_profile_path);
596 DEBUG(10,("INFO_25 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
598 pdb_set_profile_path(to , new_string, PDB_CHANGED);
601 if ((from->fields_present & ACCT_DESCRIPTION) &&
602 (from->hdr_acct_desc.buffer)) {
603 old_string = pdb_get_acct_desc(to);
604 new_string = unistr2_static(&from->uni_acct_desc);
605 DEBUG(10,("INFO_25 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
607 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
610 if ((from->fields_present & ACCT_WORKSTATIONS) &&
611 (from->hdr_workstations.buffer)) {
612 old_string = pdb_get_workstations(to);
613 new_string = unistr2_static(&from->uni_workstations);
614 DEBUG(10,("INFO_25 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
616 pdb_set_workstations(to , new_string, PDB_CHANGED);
619 if ((from->fields_present & ACCT_COMMENT) &&
620 (from->hdr_comment.buffer)) {
621 old_string = pdb_get_comment(to);
622 new_string = unistr2_static(&from->uni_comment);
623 DEBUG(10,("INFO_25 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
625 pdb_set_comment(to , new_string, PDB_CHANGED);
628 if ((from->fields_present & ACCT_CALLBACK) &&
629 (from->hdr_munged_dial.buffer)) {
631 old_string = pdb_get_munged_dial(to);
632 mung.length = from->hdr_munged_dial.uni_str_len;
633 mung.data = (uint8 *) from->uni_munged_dial.buffer;
635 newstr = (mung.length == 0) ?
636 NULL : base64_encode_data_blob(mung);
637 DEBUG(10,("INFO_25 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
638 if (STRING_CHANGED_NC(old_string,newstr))
639 pdb_set_munged_dial(to , newstr, PDB_CHANGED);
644 if (from->fields_present & ACCT_RID) {
645 if (from->user_rid == 0) {
646 DEBUG(10, ("INFO_25: Asked to set User RID to 0 !? Skipping change!\n"));
647 } else if (from->user_rid != pdb_get_user_rid(to)) {
648 DEBUG(10,("INFO_25 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
652 if (from->fields_present & ACCT_PRIMARY_GID) {
653 if (from->group_rid == 0) {
654 DEBUG(10, ("INFO_25: Asked to set Group RID to 0 !? Skipping change!\n"));
655 } else if (from->group_rid != pdb_get_group_rid(to)) {
656 DEBUG(10,("INFO_25 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
657 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
661 if (from->fields_present & ACCT_FLAGS) {
662 DEBUG(10,("INFO_25 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
663 if (from->acb_info != pdb_get_acct_ctrl(to)) {
664 if (!(from->acb_info & ACB_AUTOLOCK) && (pdb_get_acct_ctrl(to) & ACB_AUTOLOCK)) {
665 /* We're unlocking a previously locked user. Reset bad password counts.
666 Patch from Jianliang Lu. <Jianliang.Lu@getronics.com> */
667 pdb_set_bad_password_count(to, 0, PDB_CHANGED);
668 pdb_set_bad_password_time(to, 0, PDB_CHANGED);
670 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
674 if (from->fields_present & ACCT_LOGON_HOURS) {
675 DEBUG(15,("INFO_25 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
676 if (from->logon_divs != pdb_get_logon_divs(to)) {
677 pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
680 DEBUG(15,("INFO_25 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
681 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
682 pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
685 DEBUG(15,("INFO_25 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
686 /* Fix me: only update if it changes --metze */
687 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
690 if (from->fields_present & ACCT_BAD_PWD_COUNT) {
691 DEBUG(10,("INFO_25 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
692 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
693 pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
697 if (from->fields_present & ACCT_NUM_LOGONS) {
698 DEBUG(10,("INFO_25 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
699 if (from->logon_count != pdb_get_logon_count(to)) {
700 pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
704 /* If the must change flag is set, the last set time goes to zero.
705 the must change and can change fields also do, but they are
706 calculated from policy, not set from the wire */
708 if (from->fields_present & ACCT_EXPIRED_FLAG) {
709 DEBUG(10,("INFO_25 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
710 if (from->passmustchange == PASS_MUST_CHANGE_AT_NEXT_LOGON) {
711 pdb_set_pass_last_set_time(to, 0, PDB_CHANGED);
713 pdb_set_pass_last_set_time(to, time(NULL),PDB_CHANGED);