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
!= pdb_get_user_rid(to
)) {
173 DEBUG(10,("INFO_21 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to
),from
->user_rid
));
174 /* we really allow this ??? metze */
175 /* pdb_set_user_sid_from_rid(to, from->user_rid, PDB_CHANGED);*/
178 if (from
->group_rid
!= pdb_get_group_rid(to
)) {
179 DEBUG(10,("INFO_21 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to
),from
->group_rid
));
180 pdb_set_group_sid_from_rid(to
, from
->group_rid
, PDB_CHANGED
);
183 DEBUG(10,("INFO_21 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to
),from
->acb_info
));
184 if (from
->acb_info
!= pdb_get_acct_ctrl(to
)) {
185 pdb_set_acct_ctrl(to
, from
->acb_info
, PDB_CHANGED
);
188 DEBUG(10,("INFO_21 UNKOWN_3: %08X -> %08X\n",pdb_get_unknown_3(to
),from
->unknown_3
));
189 if (from
->unknown_3
!= pdb_get_unknown_3(to
)) {
190 pdb_set_unknown_3(to
, from
->unknown_3
, PDB_CHANGED
);
193 DEBUG(15,("INFO_21 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to
),from
->logon_divs
));
194 if (from
->logon_divs
!= pdb_get_logon_divs(to
)) {
195 pdb_set_logon_divs(to
, from
->logon_divs
, PDB_CHANGED
);
198 DEBUG(15,("INFO_21 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to
),from
->logon_hrs
.len
));
199 if (from
->logon_hrs
.len
!= pdb_get_hours_len(to
)) {
200 pdb_set_hours_len(to
, from
->logon_hrs
.len
, PDB_CHANGED
);
203 DEBUG(15,("INFO_21 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to
),from
->logon_hrs
.hours
));
204 /* Fix me: only update if it changes --metze */
205 pdb_set_hours(to
, from
->logon_hrs
.hours
, PDB_CHANGED
);
207 DEBUG(10,("INFO_21 UNKOWN_5: %08X -> %08X\n",pdb_get_unknown_5(to
),from
->unknown_5
));
208 if (from
->unknown_5
!= pdb_get_unknown_5(to
)) {
209 pdb_set_unknown_5(to
, from
->unknown_5
, PDB_CHANGED
);
212 DEBUG(10,("INFO_21 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to
),from
->unknown_6
));
213 if (from
->unknown_6
!= pdb_get_unknown_6(to
)) {
214 pdb_set_unknown_6(to
, from
->unknown_6
, PDB_CHANGED
);
217 DEBUG(10,("INFO_21 PADDING1 %02X %02X %02X %02X %02X %02X\n",
225 DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from
->passmustchange
));
226 if (from
->passmustchange
==PASS_MUST_CHANGE_AT_NEXT_LOGON
) {
227 pdb_set_pass_must_change_time(to
,0, PDB_CHANGED
);
230 DEBUG(10,("INFO_21 PADDING_2: %02X\n",from
->padding2
));
232 DEBUG(10,("INFO_21 PADDING_4: %08X\n",from
->padding4
));
236 /*************************************************************
237 Copies a SAM_USER_INFO_23 to a SAM_ACCOUNT
238 **************************************************************/
240 void copy_id23_to_sam_passwd(SAM_ACCOUNT
*to
, SAM_USER_INFO_23
*from
)
242 time_t unix_time
, stored_time
;
243 const char *old_string
, *new_string
;
245 if (from
== NULL
|| to
== NULL
)
247 if (!nt_time_is_zero(&from
->logon_time
)) {
248 unix_time
=nt_time_to_unix(&from
->logon_time
);
249 stored_time
= pdb_get_logon_time(to
);
250 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
251 if (stored_time
!= unix_time
)
252 pdb_set_logon_time(to
, unix_time
, PDB_CHANGED
);
254 if (!nt_time_is_zero(&from
->logoff_time
)) {
255 unix_time
=nt_time_to_unix(&from
->logoff_time
);
256 stored_time
= pdb_get_logoff_time(to
);
257 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
258 if (stored_time
!= unix_time
)
259 pdb_set_logoff_time(to
, unix_time
, PDB_CHANGED
);
262 if (!nt_time_is_zero(&from
->kickoff_time
)) {
263 unix_time
=nt_time_to_unix(&from
->kickoff_time
);
264 stored_time
= pdb_get_kickoff_time(to
);
265 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
266 if (stored_time
!= unix_time
)
267 pdb_set_kickoff_time(to
, unix_time
, PDB_CHANGED
);
270 if (!nt_time_is_zero(&from
->pass_can_change_time
)) {
271 unix_time
=nt_time_to_unix(&from
->pass_can_change_time
);
272 stored_time
= pdb_get_pass_can_change_time(to
);
273 DEBUG(10,("INFO_23 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
274 if (stored_time
!= unix_time
)
275 pdb_set_pass_can_change_time(to
, unix_time
, PDB_CHANGED
);
277 if (!nt_time_is_zero(&from
->pass_last_set_time
)) {
278 unix_time
=nt_time_to_unix(&from
->pass_last_set_time
);
279 stored_time
= pdb_get_pass_last_set_time(to
);
280 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
281 if (stored_time
!= unix_time
)
282 pdb_set_pass_last_set_time(to
, unix_time
, PDB_CHANGED
);
285 if (!nt_time_is_zero(&from
->pass_must_change_time
)) {
286 unix_time
=nt_time_to_unix(&from
->pass_must_change_time
);
287 stored_time
=pdb_get_pass_must_change_time(to
);
288 DEBUG(10,("INFO_23 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time
, (long unsigned int)unix_time
));
289 if (stored_time
!= unix_time
)
290 pdb_set_pass_must_change_time(to
, unix_time
, PDB_CHANGED
);
293 /* Backend should check this for sainity */
294 if (from
->hdr_user_name
.buffer
) {
295 old_string
= pdb_get_username(to
);
296 new_string
= unistr2_static(&from
->uni_user_name
);
297 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string
, new_string
));
299 pdb_set_username(to
, new_string
, PDB_CHANGED
);
302 if (from
->hdr_full_name
.buffer
) {
303 old_string
= pdb_get_fullname(to
);
304 new_string
= unistr2_static(&from
->uni_full_name
);
305 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string
, new_string
));
307 pdb_set_fullname(to
, new_string
, PDB_CHANGED
);
310 if (from
->hdr_home_dir
.buffer
) {
311 old_string
= pdb_get_homedir(to
);
312 new_string
= unistr2_static(&from
->uni_home_dir
);
313 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string
,new_string
));
315 pdb_set_homedir(to
, new_string
, PDB_CHANGED
);
318 if (from
->hdr_dir_drive
.buffer
) {
319 old_string
= pdb_get_dir_drive(to
);
320 new_string
= unistr2_static(&from
->uni_dir_drive
);
321 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string
,new_string
));
323 pdb_set_dir_drive(to
, new_string
, PDB_CHANGED
);
326 if (from
->hdr_logon_script
.buffer
) {
327 old_string
= pdb_get_logon_script(to
);
328 new_string
= unistr2_static(&from
->uni_logon_script
);
329 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string
,new_string
));
331 pdb_set_logon_script(to
, new_string
, PDB_CHANGED
);
334 if (from
->hdr_profile_path
.buffer
) {
335 old_string
= pdb_get_profile_path(to
);
336 new_string
= unistr2_static(&from
->uni_profile_path
);
337 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string
, new_string
));
339 pdb_set_profile_path(to
, new_string
, PDB_CHANGED
);
342 if (from
->hdr_acct_desc
.buffer
) {
343 old_string
= pdb_get_acct_desc(to
);
344 new_string
= unistr2_static(&from
->uni_acct_desc
);
345 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string
,new_string
));
347 pdb_set_acct_desc(to
, new_string
, PDB_CHANGED
);
350 if (from
->hdr_workstations
.buffer
) {
351 old_string
= pdb_get_workstations(to
);
352 new_string
= unistr2_static(&from
->uni_workstations
);
353 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string
, new_string
));
355 pdb_set_workstations(to
, new_string
, PDB_CHANGED
);
358 if (from
->hdr_unknown_str
.buffer
) {
359 old_string
= pdb_get_unknown_str(to
);
360 new_string
= unistr2_static(&from
->uni_unknown_str
);
361 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string
, new_string
));
363 pdb_set_unknown_str(to
, new_string
, PDB_CHANGED
);
366 if (from
->hdr_munged_dial
.buffer
) {
367 old_string
= pdb_get_munged_dial(to
);
368 new_string
= unistr2_static(&from
->uni_munged_dial
);
369 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string
, new_string
));
371 pdb_set_munged_dial(to
, new_string
, PDB_CHANGED
);
374 if (from
->user_rid
!= pdb_get_user_rid(to
)) {
375 DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to
),from
->user_rid
));
376 /* we really allow this ??? metze */
377 /* pdb_set_user_sid_from_rid(to, from->user_rid, PDB_CHANGED);*/
380 if (from
->group_rid
!= pdb_get_group_rid(to
)) {
381 DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to
),from
->group_rid
));
382 pdb_set_group_sid_from_rid(to
, from
->group_rid
, PDB_CHANGED
);
385 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to
),from
->acb_info
));
386 if (from
->acb_info
!= pdb_get_acct_ctrl(to
)) {
387 pdb_set_acct_ctrl(to
, from
->acb_info
, PDB_CHANGED
);
390 DEBUG(10,("INFO_23 UNKOWN_3: %08X -> %08X\n",pdb_get_unknown_3(to
),from
->unknown_3
));
391 if (from
->unknown_3
!= pdb_get_unknown_3(to
)) {
392 pdb_set_unknown_3(to
, from
->unknown_3
, PDB_CHANGED
);
395 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to
),from
->logon_divs
));
396 if (from
->logon_divs
!= pdb_get_logon_divs(to
)) {
397 pdb_set_logon_divs(to
, from
->logon_divs
, PDB_CHANGED
);
400 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to
),from
->logon_hrs
.len
));
401 if (from
->logon_hrs
.len
!= pdb_get_hours_len(to
)) {
402 pdb_set_hours_len(to
, from
->logon_hrs
.len
, PDB_CHANGED
);
405 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to
),from
->logon_hrs
.hours
));
406 /* Fix me: only update if it changes --metze */
407 pdb_set_hours(to
, from
->logon_hrs
.hours
, PDB_CHANGED
);
409 DEBUG(10,("INFO_23 UNKOWN_5: %08X -> %08X\n",pdb_get_unknown_5(to
),from
->unknown_5
));
410 if (from
->unknown_5
!= pdb_get_unknown_5(to
)) {
411 pdb_set_unknown_5(to
, from
->unknown_5
, PDB_CHANGED
);
414 DEBUG(10,("INFO_23 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to
),from
->unknown_6
));
415 if (from
->unknown_6
!= pdb_get_unknown_6(to
)) {
416 pdb_set_unknown_6(to
, from
->unknown_6
, PDB_CHANGED
);
419 DEBUG(10,("INFO_23 PADDING1 %02X %02X %02X %02X %02X %02X\n",
427 DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from
->passmustchange
));
428 if (from
->passmustchange
==PASS_MUST_CHANGE_AT_NEXT_LOGON
) {
429 pdb_set_pass_must_change_time(to
,0, PDB_CHANGED
);
432 DEBUG(10,("INFO_23 PADDING_2: %02X\n",from
->padding2
));
434 DEBUG(10,("INFO_23 PADDING_4: %08X\n",from
->padding4
));