forgot to add the file where things moved
[Samba.git] / source3 / rpc_server / srv_samr_util.c
blobb81c441811411fcfccc31c22ac2d421e1f8cb691
1 /*
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.
25 #include "includes.h"
27 #undef DBGC_CLASS
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)
44 return;
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));
96 if (STRING_CHANGED)
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));
104 if (STRING_CHANGED)
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));
112 if (STRING_CHANGED)
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));
120 if (STRING_CHANGED)
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));
128 if (STRING_CHANGED)
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));
136 if (STRING_CHANGED)
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));
144 if (STRING_CHANGED)
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));
152 if (STRING_CHANGED)
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));
160 if (STRING_CHANGED)
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));
168 if (STRING_CHANGED)
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 UNKOWN_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 UNKOWN_5: %08X -> %08X\n",pdb_get_unknown_5(to),from->unknown_5));
212 if (from->unknown_5 != pdb_get_unknown_5(to)) {
213 pdb_set_unknown_5(to, from->unknown_5, PDB_CHANGED);
216 DEBUG(10,("INFO_21 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to),from->unknown_6));
217 if (from->unknown_6 != pdb_get_unknown_6(to)) {
218 pdb_set_unknown_6(to, from->unknown_6, PDB_CHANGED);
221 DEBUG(10,("INFO_21 PADDING1 %02X %02X %02X %02X %02X %02X\n",
222 from->padding1[0],
223 from->padding1[1],
224 from->padding1[2],
225 from->padding1[3],
226 from->padding1[4],
227 from->padding1[5]));
229 DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
230 if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
231 pdb_set_pass_must_change_time(to,0, PDB_CHANGED);
234 DEBUG(10,("INFO_21 PADDING_2: %02X\n",from->padding2));
236 DEBUG(10,("INFO_21 PADDING_4: %08X\n",from->padding4));
240 /*************************************************************
241 Copies a SAM_USER_INFO_23 to a SAM_ACCOUNT
242 **************************************************************/
244 void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from)
246 time_t unix_time, stored_time;
247 const char *old_string, *new_string;
249 if (from == NULL || to == NULL)
250 return;
251 if (!nt_time_is_zero(&from->logon_time)) {
252 unix_time=nt_time_to_unix(&from->logon_time);
253 stored_time = pdb_get_logon_time(to);
254 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
255 if (stored_time != unix_time)
256 pdb_set_logon_time(to, unix_time, PDB_CHANGED);
258 if (!nt_time_is_zero(&from->logoff_time)) {
259 unix_time=nt_time_to_unix(&from->logoff_time);
260 stored_time = pdb_get_logoff_time(to);
261 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
262 if (stored_time != unix_time)
263 pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
266 if (!nt_time_is_zero(&from->kickoff_time)) {
267 unix_time=nt_time_to_unix(&from->kickoff_time);
268 stored_time = pdb_get_kickoff_time(to);
269 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
270 if (stored_time != unix_time)
271 pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
274 if (!nt_time_is_zero(&from->pass_can_change_time)) {
275 unix_time=nt_time_to_unix(&from->pass_can_change_time);
276 stored_time = pdb_get_pass_can_change_time(to);
277 DEBUG(10,("INFO_23 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
278 if (stored_time != unix_time)
279 pdb_set_pass_can_change_time(to, unix_time, PDB_CHANGED);
281 if (!nt_time_is_zero(&from->pass_last_set_time)) {
282 unix_time=nt_time_to_unix(&from->pass_last_set_time);
283 stored_time = pdb_get_pass_last_set_time(to);
284 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
285 if (stored_time != unix_time)
286 pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
289 if (!nt_time_is_zero(&from->pass_must_change_time)) {
290 unix_time=nt_time_to_unix(&from->pass_must_change_time);
291 stored_time=pdb_get_pass_must_change_time(to);
292 DEBUG(10,("INFO_23 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
293 if (stored_time != unix_time)
294 pdb_set_pass_must_change_time(to, unix_time, PDB_CHANGED);
297 /* Backend should check this for sainity */
298 if (from->hdr_user_name.buffer) {
299 old_string = pdb_get_username(to);
300 new_string = unistr2_static(&from->uni_user_name);
301 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
302 if (STRING_CHANGED)
303 pdb_set_username(to , new_string, PDB_CHANGED);
306 if (from->hdr_full_name.buffer) {
307 old_string = pdb_get_fullname(to);
308 new_string = unistr2_static(&from->uni_full_name);
309 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
310 if (STRING_CHANGED)
311 pdb_set_fullname(to , new_string, PDB_CHANGED);
314 if (from->hdr_home_dir.buffer) {
315 old_string = pdb_get_homedir(to);
316 new_string = unistr2_static(&from->uni_home_dir);
317 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
318 if (STRING_CHANGED)
319 pdb_set_homedir(to , new_string, PDB_CHANGED);
322 if (from->hdr_dir_drive.buffer) {
323 old_string = pdb_get_dir_drive(to);
324 new_string = unistr2_static(&from->uni_dir_drive);
325 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
326 if (STRING_CHANGED)
327 pdb_set_dir_drive(to , new_string, PDB_CHANGED);
330 if (from->hdr_logon_script.buffer) {
331 old_string = pdb_get_logon_script(to);
332 new_string = unistr2_static(&from->uni_logon_script);
333 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
334 if (STRING_CHANGED)
335 pdb_set_logon_script(to , new_string, PDB_CHANGED);
338 if (from->hdr_profile_path.buffer) {
339 old_string = pdb_get_profile_path(to);
340 new_string = unistr2_static(&from->uni_profile_path);
341 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
342 if (STRING_CHANGED)
343 pdb_set_profile_path(to , new_string, PDB_CHANGED);
346 if (from->hdr_acct_desc.buffer) {
347 old_string = pdb_get_acct_desc(to);
348 new_string = unistr2_static(&from->uni_acct_desc);
349 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
350 if (STRING_CHANGED)
351 pdb_set_acct_desc(to , new_string, PDB_CHANGED);
354 if (from->hdr_workstations.buffer) {
355 old_string = pdb_get_workstations(to);
356 new_string = unistr2_static(&from->uni_workstations);
357 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
358 if (STRING_CHANGED)
359 pdb_set_workstations(to , new_string, PDB_CHANGED);
362 if (from->hdr_unknown_str.buffer) {
363 old_string = pdb_get_unknown_str(to);
364 new_string = unistr2_static(&from->uni_unknown_str);
365 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
366 if (STRING_CHANGED)
367 pdb_set_unknown_str(to , new_string, PDB_CHANGED);
370 if (from->hdr_munged_dial.buffer) {
371 old_string = pdb_get_munged_dial(to);
372 new_string = unistr2_static(&from->uni_munged_dial);
373 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string, new_string));
374 if (STRING_CHANGED)
375 pdb_set_munged_dial(to , new_string, PDB_CHANGED);
378 if (from->user_rid == 0) {
379 DEBUG(10, ("INFO_23: Asked to set User RID to 0 !? Skipping change!\n"));
380 } else if (from->user_rid != pdb_get_user_rid(to)) {
381 DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
382 /* we really allow this ??? metze */
383 /* pdb_set_user_sid_from_rid(to, from->user_rid, PDB_CHANGED);*/
385 if (from->group_rid == 0) {
386 DEBUG(10, ("INFO_23: Asked to set Group RID to 0 !? Skipping change!\n"));
387 } else if (from->group_rid != pdb_get_group_rid(to)) {
388 DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
389 pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
392 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
393 if (from->acb_info != pdb_get_acct_ctrl(to)) {
394 pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
397 DEBUG(10,("INFO_23 UNKOWN_3: %08X -> %08X\n",pdb_get_unknown_3(to),from->unknown_3));
398 if (from->unknown_3 != pdb_get_unknown_3(to)) {
399 pdb_set_unknown_3(to, from->unknown_3, PDB_CHANGED);
402 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
403 if (from->logon_divs != pdb_get_logon_divs(to)) {
404 pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
407 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
408 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
409 pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
412 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
413 /* Fix me: only update if it changes --metze */
414 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
416 DEBUG(10,("INFO_23 UNKOWN_5: %08X -> %08X\n",pdb_get_unknown_5(to),from->unknown_5));
417 if (from->unknown_5 != pdb_get_unknown_5(to)) {
418 pdb_set_unknown_5(to, from->unknown_5, PDB_CHANGED);
421 DEBUG(10,("INFO_23 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to),from->unknown_6));
422 if (from->unknown_6 != pdb_get_unknown_6(to)) {
423 pdb_set_unknown_6(to, from->unknown_6, PDB_CHANGED);
426 DEBUG(10,("INFO_23 PADDING1 %02X %02X %02X %02X %02X %02X\n",
427 from->padding1[0],
428 from->padding1[1],
429 from->padding1[2],
430 from->padding1[3],
431 from->padding1[4],
432 from->padding1[5]));
434 DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
435 if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
436 pdb_set_pass_must_change_time(to,0, PDB_CHANGED);
439 DEBUG(10,("INFO_23 PADDING_2: %02X\n",from->padding2));
441 DEBUG(10,("INFO_23 PADDING_4: %08X\n",from->padding4));