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, True);
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, True);
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 , True);
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, True);
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);
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, True);
91 /* Backend should check this for sainity */
92 if (from->hdr_user_name.buffer) {
93 old_string = pdb_get_username(to);
94 new_string = pdb_unistr2_convert(&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);
100 if (from->hdr_full_name.buffer) {
101 old_string = pdb_get_fullname(to);
102 new_string = pdb_unistr2_convert(&from->uni_user_name);
103 DEBUG(10,("INFO_21 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
105 pdb_set_fullname(to , new_string);
108 if (from->hdr_home_dir.buffer) {
109 old_string = pdb_get_homedir(to);
110 new_string = pdb_unistr2_convert(&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, True);
116 if (from->hdr_dir_drive.buffer) {
117 old_string = pdb_get_dir_drive(to);
118 new_string = pdb_unistr2_convert(&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, True);
124 if (from->hdr_logon_script.buffer) {
125 old_string = pdb_get_logon_script(to);
126 new_string = pdb_unistr2_convert(&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, True);
132 if (from->hdr_profile_path.buffer) {
133 old_string = pdb_get_profile_path(to);
134 new_string = pdb_unistr2_convert(&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, True);
140 if (from->hdr_acct_desc.buffer) {
141 old_string = pdb_get_acct_desc(to);
142 new_string = pdb_unistr2_convert(&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);
148 if (from->hdr_workstations.buffer) {
149 old_string = pdb_get_workstations(to);
150 new_string = pdb_unistr2_convert(&from->uni_workstations);
151 DEBUG(10,("INFO_21 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
153 pdb_set_workstations(to , new_string);
156 if (from->hdr_unknown_str.buffer) {
157 old_string = pdb_get_unknown_str(to);
158 new_string = pdb_unistr2_convert(&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);
164 if (from->hdr_munged_dial.buffer) {
165 old_string = pdb_get_munged_dial(to);
166 new_string = pdb_unistr2_convert(&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);
172 if (from->user_rid) {
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);*/
178 if (from->group_rid) {
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);
183 DEBUG(10,("INFO_21 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
184 pdb_set_acct_ctrl(to, from->acb_info);
186 DEBUG(10,("INFO_21 UNKOWN_3: %08X -> %08X\n",pdb_get_unknown3(to),from->unknown_3));
187 pdb_set_unknown_3(to, from->unknown_3);
190 DEBUG(15,("INFO_21 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
191 pdb_set_logon_divs(to, from->logon_divs);
193 DEBUG(15,("INFO_21 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
194 pdb_set_hours_len(to, from->logon_hrs.len);
195 DEBUG(15,("INFO_21 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
196 pdb_set_hours(to, from->logon_hrs.hours);
198 DEBUG(10,("INFO_21 UNKOWN_5: %08X -> %08X\n",pdb_get_unknown5(to),from->unknown_5));
199 pdb_set_unknown_5(to, from->unknown_5);
201 DEBUG(10,("INFO_21 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown6(to),from->unknown_6));
202 pdb_set_unknown_6(to, from->unknown_6);
204 DEBUG(10,("INFO_21 PADDING1 %02X %02X %02X %02X %02X %02X\n",
212 DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
213 if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
214 pdb_set_pass_must_change_time(to,0, True);
217 DEBUG(10,("INFO_21 PADDING_2: %02X\n",from->padding2));
219 DEBUG(10,("INFO_21 PADDING_4: %08X\n",from->padding4));
223 /*************************************************************
224 Copies a SAM_USER_INFO_23 to a SAM_ACCOUNT
225 **************************************************************/
227 void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from)
229 time_t unix_time, stored_time;
230 const char *old_string, *new_string;
232 if (from == NULL || to == NULL)
234 if (!nt_time_is_zero(&from->logon_time)) {
235 unix_time=nt_time_to_unix(&from->logon_time);
236 stored_time = pdb_get_logon_time(to);
237 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
238 if (stored_time != unix_time)
239 pdb_set_logon_time(to, unix_time, True);
241 if (!nt_time_is_zero(&from->logoff_time)) {
242 unix_time=nt_time_to_unix(&from->logoff_time);
243 stored_time = pdb_get_logoff_time(to);
244 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
245 if (stored_time != unix_time)
246 pdb_set_logoff_time(to, unix_time, True);
249 if (!nt_time_is_zero(&from->kickoff_time)) {
250 unix_time=nt_time_to_unix(&from->kickoff_time);
251 stored_time = pdb_get_kickoff_time(to);
252 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
253 if (stored_time != unix_time)
254 pdb_set_kickoff_time(to, unix_time , True);
257 if (!nt_time_is_zero(&from->pass_can_change_time)) {
258 unix_time=nt_time_to_unix(&from->pass_can_change_time);
259 stored_time = pdb_get_pass_can_change_time(to);
260 DEBUG(10,("INFO_23 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
261 if (stored_time != unix_time)
262 pdb_set_pass_can_change_time(to, unix_time, True);
264 if (!nt_time_is_zero(&from->pass_last_set_time)) {
265 unix_time=nt_time_to_unix(&from->pass_last_set_time);
266 stored_time = pdb_get_pass_last_set_time(to);
267 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
268 if (stored_time != unix_time)
269 pdb_set_pass_last_set_time(to, unix_time);
272 if (!nt_time_is_zero(&from->pass_must_change_time)) {
273 unix_time=nt_time_to_unix(&from->pass_must_change_time);
274 stored_time=pdb_get_pass_must_change_time(to);
275 DEBUG(10,("INFO_23 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
276 if (stored_time != unix_time)
277 pdb_set_pass_must_change_time(to, unix_time, True);
280 /* Backend should check this for sainity */
281 if (from->hdr_user_name.buffer) {
282 old_string = pdb_get_username(to);
283 new_string = pdb_unistr2_convert(&from->uni_user_name);
284 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
286 pdb_set_username(to , new_string);
289 if (from->hdr_full_name.buffer) {
290 old_string = pdb_get_fullname(to);
291 new_string = pdb_unistr2_convert(&from->uni_user_name);
292 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
294 pdb_set_fullname(to , new_string);
297 if (from->hdr_home_dir.buffer) {
298 old_string = pdb_get_homedir(to);
299 new_string = pdb_unistr2_convert(&from->uni_home_dir);
300 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
302 pdb_set_homedir(to , new_string, True);
305 if (from->hdr_dir_drive.buffer) {
306 old_string = pdb_get_dir_drive(to);
307 new_string = pdb_unistr2_convert(&from->uni_dir_drive);
308 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
310 pdb_set_dir_drive(to , new_string, True);
313 if (from->hdr_logon_script.buffer) {
314 old_string = pdb_get_logon_script(to);
315 new_string = pdb_unistr2_convert(&from->uni_logon_script);
316 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
318 pdb_set_logon_script(to , new_string, True);
321 if (from->hdr_profile_path.buffer) {
322 old_string = pdb_get_profile_path(to);
323 new_string = pdb_unistr2_convert(&from->uni_profile_path);
324 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
326 pdb_set_profile_path(to , new_string, True);
329 if (from->hdr_acct_desc.buffer) {
330 old_string = pdb_get_acct_desc(to);
331 new_string = pdb_unistr2_convert(&from->uni_acct_desc);
332 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
334 pdb_set_acct_desc(to , new_string);
337 if (from->hdr_workstations.buffer) {
338 old_string = pdb_get_workstations(to);
339 new_string = pdb_unistr2_convert(&from->uni_workstations);
340 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
342 pdb_set_workstations(to , new_string);
345 if (from->hdr_unknown_str.buffer) {
346 old_string = pdb_get_unknown_str(to);
347 new_string = pdb_unistr2_convert(&from->uni_unknown_str);
348 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
350 pdb_set_unknown_str(to , new_string);
353 if (from->hdr_munged_dial.buffer) {
354 old_string = pdb_get_munged_dial(to);
355 new_string = pdb_unistr2_convert(&from->uni_munged_dial);
356 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string, new_string));
358 pdb_set_munged_dial(to , new_string);
361 if (from->user_rid) {
362 DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
363 /* we really allow this ??? metze */
364 /* pdb_set_user_sid_from_rid(to, from->user_rid);*/
367 if (from->group_rid) {
368 DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
369 pdb_set_group_sid_from_rid(to, from->group_rid);
372 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
373 pdb_set_acct_ctrl(to, from->acb_info);
375 DEBUG(10,("INFO_23 UNKOWN_3: %08X -> %08X\n",pdb_get_unknown3(to),from->unknown_3));
376 pdb_set_unknown_3(to, from->unknown_3);
379 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
380 pdb_set_logon_divs(to, from->logon_divs);
382 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
383 pdb_set_hours_len(to, from->logon_hrs.len);
384 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
385 pdb_set_hours(to, from->logon_hrs.hours);
387 DEBUG(10,("INFO_23 UNKOWN_5: %08X -> %08X\n",pdb_get_unknown5(to),from->unknown_5));
388 pdb_set_unknown_5(to, from->unknown_5);
390 DEBUG(10,("INFO_23 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown6(to),from->unknown_6));
391 pdb_set_unknown_6(to, from->unknown_6);
393 DEBUG(10,("INFO_23 PADDING1 %02X %02X %02X %02X %02X %02X\n",
401 DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
402 if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
403 pdb_set_pass_must_change_time(to,0, True);
406 DEBUG(10,("INFO_23 PADDING_2: %02X\n",from->padding2));
408 DEBUG(10,("INFO_23 PADDING_4: %08X\n",from->padding4));