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 /*************************************************************
35 Copies a SAM_USER_INFO_21 to a SAM_ACCOUNT
36 **************************************************************/
38 void copy_id21_to_sam_passwd(SAM_ACCOUNT
*to
, SAM_USER_INFO_21
*from
)
40 time_t unix_time
, stored_time
;
41 const char *old_string
, *new_string
;
43 if (from
== NULL
|| to
== NULL
)
45 if (!nt_time_is_zero(&from
->logon_time
)) {
46 unix_time
=nt_time_to_unix(&from
->logon_time
);
47 stored_time
= pdb_get_logon_time(to
);
48 DEBUG(10,("INFO_21 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
49 if (stored_time
!= unix_time
)
50 pdb_set_logon_time(to
, unix_time
, PDB_CHANGED
);
52 if (!nt_time_is_zero(&from
->logoff_time
)) {
53 unix_time
=nt_time_to_unix(&from
->logoff_time
);
54 stored_time
= pdb_get_logoff_time(to
);
55 DEBUG(10,("INFO_21 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
56 if (stored_time
!= unix_time
)
57 pdb_set_logoff_time(to
, unix_time
, PDB_CHANGED
);
60 if (!nt_time_is_zero(&from
->kickoff_time
)) {
61 unix_time
=nt_time_to_unix(&from
->kickoff_time
);
62 stored_time
= pdb_get_kickoff_time(to
);
63 DEBUG(10,("INFO_21 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
64 if (stored_time
!= unix_time
)
65 pdb_set_kickoff_time(to
, unix_time
, PDB_CHANGED
);
68 if (!nt_time_is_zero(&from
->pass_can_change_time
)) {
69 unix_time
=nt_time_to_unix(&from
->pass_can_change_time
);
70 stored_time
= pdb_get_pass_can_change_time(to
);
71 DEBUG(10,("INFO_21 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
72 if (stored_time
!= unix_time
)
73 pdb_set_pass_can_change_time(to
, unix_time
, PDB_CHANGED
);
75 if (!nt_time_is_zero(&from
->pass_last_set_time
)) {
76 unix_time
=nt_time_to_unix(&from
->pass_last_set_time
);
77 stored_time
= pdb_get_pass_last_set_time(to
);
78 DEBUG(10,("INFO_21 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
79 if (stored_time
!= unix_time
)
80 pdb_set_pass_last_set_time(to
, unix_time
, PDB_CHANGED
);
83 if (!nt_time_is_zero(&from
->pass_must_change_time
)) {
84 unix_time
=nt_time_to_unix(&from
->pass_must_change_time
);
85 stored_time
=pdb_get_pass_must_change_time(to
);
86 DEBUG(10,("INFO_21 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
87 if (stored_time
!= unix_time
)
88 pdb_set_pass_must_change_time(to
, unix_time
, PDB_CHANGED
);
91 /* Backend should check this for sainity */
92 if (from
->hdr_user_name
.buffer
) {
93 old_string
= pdb_get_username(to
);
94 new_string
= unistr2_static(&from
->uni_user_name
);
95 DEBUG(10,("INFO_21 UNI_USER_NAME: %s -> %s\n", old_string
, new_string
));
97 pdb_set_username(to
, new_string
, PDB_CHANGED
);
100 if (from
->hdr_full_name
.buffer
) {
101 old_string
= pdb_get_fullname(to
);
102 new_string
= unistr2_static(&from
->uni_full_name
);
103 DEBUG(10,("INFO_21 UNI_FULL_NAME: %s -> %s\n",old_string
, new_string
));
105 pdb_set_fullname(to
, new_string
, PDB_CHANGED
);
108 if (from
->hdr_home_dir
.buffer
) {
109 old_string
= pdb_get_homedir(to
);
110 new_string
= unistr2_static(&from
->uni_home_dir
);
111 DEBUG(10,("INFO_21 UNI_HOME_DIR: %s -> %s\n",old_string
,new_string
));
113 pdb_set_homedir(to
, new_string
, PDB_CHANGED
);
116 if (from
->hdr_dir_drive
.buffer
) {
117 old_string
= pdb_get_dir_drive(to
);
118 new_string
= unistr2_static(&from
->uni_dir_drive
);
119 DEBUG(10,("INFO_21 UNI_DIR_DRIVE: %s -> %s\n",old_string
,new_string
));
121 pdb_set_dir_drive(to
, new_string
, PDB_CHANGED
);
124 if (from
->hdr_logon_script
.buffer
) {
125 old_string
= pdb_get_logon_script(to
);
126 new_string
= unistr2_static(&from
->uni_logon_script
);
127 DEBUG(10,("INFO_21 UNI_LOGON_SCRIPT: %s -> %s\n",old_string
,new_string
));
129 pdb_set_logon_script(to
, new_string
, PDB_CHANGED
);
132 if (from
->hdr_profile_path
.buffer
) {
133 old_string
= pdb_get_profile_path(to
);
134 new_string
= unistr2_static(&from
->uni_profile_path
);
135 DEBUG(10,("INFO_21 UNI_PROFILE_PATH: %s -> %s\n",old_string
, new_string
));
137 pdb_set_profile_path(to
, new_string
, PDB_CHANGED
);
140 if (from
->hdr_acct_desc
.buffer
) {
141 old_string
= pdb_get_acct_desc(to
);
142 new_string
= unistr2_static(&from
->uni_acct_desc
);
143 DEBUG(10,("INFO_21 UNI_ACCT_DESC: %s -> %s\n",old_string
,new_string
));
145 pdb_set_acct_desc(to
, new_string
, PDB_CHANGED
);
148 if (from
->hdr_workstations
.buffer
) {
149 old_string
= pdb_get_workstations(to
);
150 new_string
= unistr2_static(&from
->uni_workstations
);
151 DEBUG(10,("INFO_21 UNI_WORKSTATIONS: %s -> %s\n",old_string
, new_string
));
153 pdb_set_workstations(to
, new_string
, PDB_CHANGED
);
156 if (from
->hdr_unknown_str
.buffer
) {
157 old_string
= pdb_get_unknown_str(to
);
158 new_string
= unistr2_static(&from
->uni_unknown_str
);
159 DEBUG(10,("INFO_21 UNI_UNKNOWN_STR: %s -> %s\n",old_string
, new_string
));
161 pdb_set_unknown_str(to
, new_string
, PDB_CHANGED
);
164 if (from
->hdr_munged_dial
.buffer
) {
165 old_string
= pdb_get_munged_dial(to
);
166 new_string
= unistr2_static(&from
->uni_munged_dial
);
167 DEBUG(10,("INFO_21 UNI_MUNGED_DIAL: %s -> %s\n",old_string
, new_string
));
169 pdb_set_munged_dial(to
, new_string
, PDB_CHANGED
);
172 if (from
->user_rid
== 0) {
173 DEBUG(10, ("INFO_21: Asked to set User RID to 0 !? Skipping change!\n"));
174 } else if (from
->user_rid
!= pdb_get_user_rid(to
)) {
175 DEBUG(10,("INFO_21 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to
),from
->user_rid
));
176 /* we really allow this ??? metze */
177 /* pdb_set_user_sid_from_rid(to, from->user_rid, PDB_CHANGED);*/
180 if (from
->group_rid
== 0) {
181 DEBUG(10, ("INFO_21: Asked to set Group RID to 0 !? Skipping change!\n"));
182 } else if (from
->group_rid
!= pdb_get_group_rid(to
)) {
183 DEBUG(10,("INFO_21 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to
),from
->group_rid
));
184 pdb_set_group_sid_from_rid(to
, from
->group_rid
, PDB_CHANGED
);
187 DEBUG(10,("INFO_21 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to
),from
->acb_info
));
188 if (from
->acb_info
!= pdb_get_acct_ctrl(to
)) {
189 pdb_set_acct_ctrl(to
, from
->acb_info
, PDB_CHANGED
);
192 DEBUG(10,("INFO_21 UNKNOWN_3: %08X -> %08X\n",pdb_get_unknown_3(to
),from
->unknown_3
));
193 if (from
->unknown_3
!= pdb_get_unknown_3(to
)) {
194 pdb_set_unknown_3(to
, from
->unknown_3
, PDB_CHANGED
);
197 DEBUG(15,("INFO_21 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to
),from
->logon_divs
));
198 if (from
->logon_divs
!= pdb_get_logon_divs(to
)) {
199 pdb_set_logon_divs(to
, from
->logon_divs
, PDB_CHANGED
);
202 DEBUG(15,("INFO_21 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to
),from
->logon_hrs
.len
));
203 if (from
->logon_hrs
.len
!= pdb_get_hours_len(to
)) {
204 pdb_set_hours_len(to
, from
->logon_hrs
.len
, PDB_CHANGED
);
207 DEBUG(15,("INFO_21 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to
),from
->logon_hrs
.hours
));
208 /* Fix me: only update if it changes --metze */
209 pdb_set_hours(to
, from
->logon_hrs
.hours
, PDB_CHANGED
);
211 DEBUG(10,("INFO_21 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to
),from
->bad_password_count
));
212 if (from
->bad_password_count
!= pdb_get_bad_password_count(to
)) {
213 pdb_set_bad_password_count(to
, from
->bad_password_count
, PDB_CHANGED
);
216 DEBUG(10,("INFO_21 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to
),from
->logon_count
));
217 if (from
->logon_count
!= pdb_get_logon_count(to
)) {
218 pdb_set_logon_count(to
, from
->logon_count
, PDB_CHANGED
);
221 DEBUG(10,("INFO_21 UNKNOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to
),from
->unknown_6
));
222 if (from
->unknown_6
!= pdb_get_unknown_6(to
)) {
223 pdb_set_unknown_6(to
, from
->unknown_6
, PDB_CHANGED
);
226 DEBUG(10,("INFO_21 PADDING1 %02X %02X %02X %02X %02X %02X\n",
234 DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from
->passmustchange
));
235 if (from
->passmustchange
==PASS_MUST_CHANGE_AT_NEXT_LOGON
) {
236 pdb_set_pass_must_change_time(to
,0, PDB_CHANGED
);
239 DEBUG(10,("INFO_21 PADDING_2: %02X\n",from
->padding2
));
241 DEBUG(10,("INFO_21 PADDING_4: %08X\n",from
->padding4
));
245 /*************************************************************
246 Copies a SAM_USER_INFO_23 to a SAM_ACCOUNT
247 **************************************************************/
249 void copy_id23_to_sam_passwd(SAM_ACCOUNT
*to
, SAM_USER_INFO_23
*from
)
251 time_t unix_time
, stored_time
;
252 const char *old_string
, *new_string
;
254 if (from
== NULL
|| to
== NULL
)
256 if (!nt_time_is_zero(&from
->logon_time
)) {
257 unix_time
=nt_time_to_unix(&from
->logon_time
);
258 stored_time
= pdb_get_logon_time(to
);
259 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
260 if (stored_time
!= unix_time
)
261 pdb_set_logon_time(to
, unix_time
, PDB_CHANGED
);
263 if (!nt_time_is_zero(&from
->logoff_time
)) {
264 unix_time
=nt_time_to_unix(&from
->logoff_time
);
265 stored_time
= pdb_get_logoff_time(to
);
266 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
267 if (stored_time
!= unix_time
)
268 pdb_set_logoff_time(to
, unix_time
, PDB_CHANGED
);
271 if (!nt_time_is_zero(&from
->kickoff_time
)) {
272 unix_time
=nt_time_to_unix(&from
->kickoff_time
);
273 stored_time
= pdb_get_kickoff_time(to
);
274 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
275 if (stored_time
!= unix_time
)
276 pdb_set_kickoff_time(to
, unix_time
, PDB_CHANGED
);
279 if (!nt_time_is_zero(&from
->pass_can_change_time
)) {
280 unix_time
=nt_time_to_unix(&from
->pass_can_change_time
);
281 stored_time
= pdb_get_pass_can_change_time(to
);
282 DEBUG(10,("INFO_23 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
283 if (stored_time
!= unix_time
)
284 pdb_set_pass_can_change_time(to
, unix_time
, PDB_CHANGED
);
286 if (!nt_time_is_zero(&from
->pass_last_set_time
)) {
287 unix_time
=nt_time_to_unix(&from
->pass_last_set_time
);
288 stored_time
= pdb_get_pass_last_set_time(to
);
289 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
290 if (stored_time
!= unix_time
)
291 pdb_set_pass_last_set_time(to
, unix_time
, PDB_CHANGED
);
294 if (!nt_time_is_zero(&from
->pass_must_change_time
)) {
295 unix_time
=nt_time_to_unix(&from
->pass_must_change_time
);
296 stored_time
=pdb_get_pass_must_change_time(to
);
297 DEBUG(10,("INFO_23 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
298 if (stored_time
!= unix_time
)
299 pdb_set_pass_must_change_time(to
, unix_time
, PDB_CHANGED
);
302 /* Backend should check this for sainity */
303 if (from
->hdr_user_name
.buffer
) {
304 old_string
= pdb_get_username(to
);
305 new_string
= unistr2_static(&from
->uni_user_name
);
306 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string
, new_string
));
308 pdb_set_username(to
, new_string
, PDB_CHANGED
);
311 if (from
->hdr_full_name
.buffer
) {
312 old_string
= pdb_get_fullname(to
);
313 new_string
= unistr2_static(&from
->uni_full_name
);
314 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string
, new_string
));
316 pdb_set_fullname(to
, new_string
, PDB_CHANGED
);
319 if (from
->hdr_home_dir
.buffer
) {
320 old_string
= pdb_get_homedir(to
);
321 new_string
= unistr2_static(&from
->uni_home_dir
);
322 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string
,new_string
));
324 pdb_set_homedir(to
, new_string
, PDB_CHANGED
);
327 if (from
->hdr_dir_drive
.buffer
) {
328 old_string
= pdb_get_dir_drive(to
);
329 new_string
= unistr2_static(&from
->uni_dir_drive
);
330 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string
,new_string
));
332 pdb_set_dir_drive(to
, new_string
, PDB_CHANGED
);
335 if (from
->hdr_logon_script
.buffer
) {
336 old_string
= pdb_get_logon_script(to
);
337 new_string
= unistr2_static(&from
->uni_logon_script
);
338 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string
,new_string
));
340 pdb_set_logon_script(to
, new_string
, PDB_CHANGED
);
343 if (from
->hdr_profile_path
.buffer
) {
344 old_string
= pdb_get_profile_path(to
);
345 new_string
= unistr2_static(&from
->uni_profile_path
);
346 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string
, new_string
));
348 pdb_set_profile_path(to
, new_string
, PDB_CHANGED
);
351 if (from
->hdr_acct_desc
.buffer
) {
352 old_string
= pdb_get_acct_desc(to
);
353 new_string
= unistr2_static(&from
->uni_acct_desc
);
354 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string
,new_string
));
356 pdb_set_acct_desc(to
, new_string
, PDB_CHANGED
);
359 if (from
->hdr_workstations
.buffer
) {
360 old_string
= pdb_get_workstations(to
);
361 new_string
= unistr2_static(&from
->uni_workstations
);
362 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string
, new_string
));
364 pdb_set_workstations(to
, new_string
, PDB_CHANGED
);
367 if (from
->hdr_unknown_str
.buffer
) {
368 old_string
= pdb_get_unknown_str(to
);
369 new_string
= unistr2_static(&from
->uni_unknown_str
);
370 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string
, new_string
));
372 pdb_set_unknown_str(to
, new_string
, PDB_CHANGED
);
375 if (from
->hdr_munged_dial
.buffer
) {
376 old_string
= pdb_get_munged_dial(to
);
377 new_string
= unistr2_static(&from
->uni_munged_dial
);
378 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string
, new_string
));
380 pdb_set_munged_dial(to
, new_string
, PDB_CHANGED
);
383 if (from
->user_rid
== 0) {
384 DEBUG(10, ("INFO_23: Asked to set User RID to 0 !? Skipping change!\n"));
385 } else if (from
->user_rid
!= pdb_get_user_rid(to
)) {
386 DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to
),from
->user_rid
));
387 /* we really allow this ??? metze */
388 /* pdb_set_user_sid_from_rid(to, from->user_rid, PDB_CHANGED);*/
390 if (from
->group_rid
== 0) {
391 DEBUG(10, ("INFO_23: Asked to set Group RID to 0 !? Skipping change!\n"));
392 } else if (from
->group_rid
!= pdb_get_group_rid(to
)) {
393 DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to
),from
->group_rid
));
394 pdb_set_group_sid_from_rid(to
, from
->group_rid
, PDB_CHANGED
);
397 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to
),from
->acb_info
));
398 if (from
->acb_info
!= pdb_get_acct_ctrl(to
)) {
399 pdb_set_acct_ctrl(to
, from
->acb_info
, PDB_CHANGED
);
402 DEBUG(10,("INFO_23 UNKOWN_3: %08X -> %08X\n",pdb_get_unknown_3(to
),from
->unknown_3
));
403 if (from
->unknown_3
!= pdb_get_unknown_3(to
)) {
404 pdb_set_unknown_3(to
, from
->unknown_3
, PDB_CHANGED
);
407 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to
),from
->logon_divs
));
408 if (from
->logon_divs
!= pdb_get_logon_divs(to
)) {
409 pdb_set_logon_divs(to
, from
->logon_divs
, PDB_CHANGED
);
412 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to
),from
->logon_hrs
.len
));
413 if (from
->logon_hrs
.len
!= pdb_get_hours_len(to
)) {
414 pdb_set_hours_len(to
, from
->logon_hrs
.len
, PDB_CHANGED
);
417 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to
),from
->logon_hrs
.hours
));
418 /* Fix me: only update if it changes --metze */
419 pdb_set_hours(to
, from
->logon_hrs
.hours
, PDB_CHANGED
);
421 DEBUG(10,("INFO_23 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to
),from
->bad_password_count
));
422 if (from
->bad_password_count
!= pdb_get_bad_password_count(to
)) {
423 pdb_set_bad_password_count(to
, from
->bad_password_count
, PDB_CHANGED
);
426 DEBUG(10,("INFO_23 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to
),from
->logon_count
));
427 if (from
->logon_count
!= pdb_get_logon_count(to
)) {
428 pdb_set_logon_count(to
, from
->logon_count
, PDB_CHANGED
);
431 DEBUG(10,("INFO_23 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to
),from
->unknown_6
));
432 if (from
->unknown_6
!= pdb_get_unknown_6(to
)) {
433 pdb_set_unknown_6(to
, from
->unknown_6
, PDB_CHANGED
);
436 DEBUG(10,("INFO_23 PADDING1 %02X %02X %02X %02X %02X %02X\n",
444 DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from
->passmustchange
));
445 if (from
->passmustchange
==PASS_MUST_CHANGE_AT_NEXT_LOGON
) {
446 pdb_set_pass_must_change_time(to
,0, PDB_CHANGED
);
449 DEBUG(10,("INFO_23 PADDING_2: %02X\n",from
->padding2
));
451 DEBUG(10,("INFO_23 PADDING_4: %08X\n",from
->padding4
));