import HEAD into svn+ssh://svn.samba.org/home/svn/samba/trunk
[metze/old/v3-2-winbind-ndr.git] / source / rpc_server / srv_samr_util.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SAMR Pipe utility functions.
4    
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
9       
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.
14    
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.
19    
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.
23 */
24
25 #include "includes.h"
26
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_SRV
29
30 #define STRING_CHANGED (old_string && !new_string) ||\
31                     (!old_string && new_string) ||\
32                 (old_string && new_string && (strcmp(old_string, new_string) != 0))
33
34 #define STRING_CHANGED_NC(s1,s2) ((s1) && !(s2)) ||\
35                     (!(s1) && (s2)) ||\
36                 ((s1) && (s2) && (strcmp((s1), (s2)) != 0))
37
38 /*************************************************************
39  Copies a SAM_USER_INFO_20 to a SAM_ACCOUNT
40 **************************************************************/
41
42 void copy_id20_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_20 *from)
43 {
44         const char *old_string;
45         char *new_string;
46         DATA_BLOB mung;
47
48         if (from == NULL || to == NULL) 
49                 return;
50         
51         if (from->hdr_munged_dial.buffer) {
52                 old_string = pdb_get_munged_dial(to);
53                 mung.length = from->hdr_munged_dial.uni_str_len;
54                 mung.data = (uint8 *) from->uni_munged_dial.buffer;
55                 new_string = base64_encode_data_blob(mung);
56                 DEBUG(10,("INFO_20 UNI_MUNGED_DIAL: %s -> %s\n",old_string, new_string));
57                 if (STRING_CHANGED_NC(old_string,new_string))
58                         pdb_set_munged_dial(to   , new_string, PDB_CHANGED);
59
60                 SAFE_FREE(new_string);
61         }
62 }
63
64 /*************************************************************
65  Copies a SAM_USER_INFO_21 to a SAM_ACCOUNT
66 **************************************************************/
67
68 void copy_id21_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_21 *from)
69 {
70         time_t unix_time, stored_time;
71         const char *old_string, *new_string;
72         DATA_BLOB mung;
73
74         if (from == NULL || to == NULL) 
75                 return;
76
77         if (from->fields_present & ACCT_LAST_LOGON) {
78                 unix_time=nt_time_to_unix(&from->logon_time);
79                 stored_time = pdb_get_logon_time(to);
80                 DEBUG(10,("INFO_21 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
81                 if (stored_time != unix_time) 
82                         pdb_set_logon_time(to, unix_time, PDB_CHANGED);
83         }
84
85         if (from->fields_present & ACCT_LAST_LOGOFF) {
86                 unix_time=nt_time_to_unix(&from->logoff_time);
87                 stored_time = pdb_get_logoff_time(to);
88                 DEBUG(10,("INFO_21 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
89                 if (stored_time != unix_time) 
90                         pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
91         }
92
93         if (from->fields_present & ACCT_EXPIRY) {
94                 unix_time=nt_time_to_unix(&from->kickoff_time);
95                 stored_time = pdb_get_kickoff_time(to);
96                 DEBUG(10,("INFO_21 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
97                 if (stored_time != unix_time) 
98                         pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
99         }       
100
101         if (from->fields_present & ACCT_ALLOW_PWD_CHANGE) {
102                 unix_time=nt_time_to_unix(&from->pass_can_change_time);
103                 stored_time = pdb_get_pass_can_change_time(to);
104                 DEBUG(10,("INFO_21 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
105                 if (stored_time != unix_time) 
106                         pdb_set_pass_can_change_time(to, unix_time, PDB_CHANGED);
107         }
108
109         if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
110                 unix_time=nt_time_to_unix(&from->pass_last_set_time);
111                 stored_time = pdb_get_pass_last_set_time(to);
112                 DEBUG(10,("INFO_21 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
113                 if (stored_time != unix_time) 
114                         pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
115         }
116
117         if (from->fields_present & ACCT_FORCE_PWD_CHANGE) {
118                 unix_time=nt_time_to_unix(&from->pass_must_change_time);
119                 stored_time=pdb_get_pass_must_change_time(to);
120                 DEBUG(10,("INFO_21 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
121                 if (stored_time != unix_time) 
122                         pdb_set_pass_must_change_time(to, unix_time, PDB_CHANGED);
123         }
124
125         if ((from->fields_present & ACCT_USERNAME) &&
126             (from->hdr_user_name.buffer)) {
127                 old_string = pdb_get_username(to);
128                 new_string = unistr2_static(&from->uni_user_name);
129                 DEBUG(10,("INFO_21 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
130                 if (STRING_CHANGED)
131                     pdb_set_username(to      , new_string, PDB_CHANGED);
132         }
133
134         if ((from->fields_present & ACCT_FULL_NAME) &&
135             (from->hdr_full_name.buffer)) {
136                 old_string = pdb_get_fullname(to);
137                 new_string = unistr2_static(&from->uni_full_name);
138                 DEBUG(10,("INFO_21 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
139                 if (STRING_CHANGED)
140                         pdb_set_fullname(to      , new_string, PDB_CHANGED);
141         }
142         
143         if ((from->fields_present & ACCT_HOME_DIR) &&
144             (from->hdr_home_dir.buffer)) {
145                 old_string = pdb_get_homedir(to);
146                 new_string = unistr2_static(&from->uni_home_dir);
147                 DEBUG(10,("INFO_21 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
148                 if (STRING_CHANGED)
149                         pdb_set_homedir(to       , new_string, PDB_CHANGED);
150         }
151
152         if ((from->fields_present & ACCT_HOME_DRIVE) &&
153             (from->hdr_dir_drive.buffer)) {
154                 old_string = pdb_get_dir_drive(to);
155                 new_string = unistr2_static(&from->uni_dir_drive);
156                 DEBUG(10,("INFO_21 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
157                 if (STRING_CHANGED)
158                         pdb_set_dir_drive(to     , new_string, PDB_CHANGED);
159         }
160
161         if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
162             (from->hdr_logon_script.buffer)) {
163                 old_string = pdb_get_logon_script(to);
164                 new_string = unistr2_static(&from->uni_logon_script);
165                 DEBUG(10,("INFO_21 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
166                 if (STRING_CHANGED)
167                         pdb_set_logon_script(to  , new_string, PDB_CHANGED);
168         }
169
170         if ((from->fields_present & ACCT_PROFILE) &&
171             (from->hdr_profile_path.buffer)) {
172                 old_string = pdb_get_profile_path(to);
173                 new_string = unistr2_static(&from->uni_profile_path);
174                 DEBUG(10,("INFO_21 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
175                 if (STRING_CHANGED)
176                         pdb_set_profile_path(to  , new_string, PDB_CHANGED);
177         }
178         
179         if ((from->fields_present & ACCT_DESCRIPTION) &&
180             (from->hdr_acct_desc.buffer)) {
181                 old_string = pdb_get_acct_desc(to);
182                 new_string = unistr2_static(&from->uni_acct_desc);
183                 DEBUG(10,("INFO_21 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
184                 if (STRING_CHANGED)
185                         pdb_set_acct_desc(to     , new_string, PDB_CHANGED);
186         }
187         
188         if ((from->fields_present & ACCT_WORKSTATIONS) &&
189             (from->hdr_workstations.buffer)) {
190                 old_string = pdb_get_workstations(to);
191                 new_string = unistr2_static(&from->uni_workstations);
192                 DEBUG(10,("INFO_21 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
193                 if (STRING_CHANGED)
194                         pdb_set_workstations(to  , new_string, PDB_CHANGED);
195         }
196
197         /* is this right? */
198         if ((from->fields_present & ACCT_ADMIN_DESC) &&
199             (from->hdr_unknown_str.buffer)) {
200                 old_string = pdb_get_unknown_str(to);
201                 new_string = unistr2_static(&from->uni_unknown_str);
202                 DEBUG(10,("INFO_21 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
203                 if (STRING_CHANGED)
204                         pdb_set_unknown_str(to   , new_string, PDB_CHANGED);
205         }
206         
207         if ((from->fields_present & ACCT_CALLBACK) &&
208             (from->hdr_munged_dial.buffer)) {
209                 char *newstr;
210                 old_string = pdb_get_munged_dial(to);
211                 mung.length = from->hdr_munged_dial.uni_str_len;
212                 mung.data = (uint8 *) from->uni_munged_dial.buffer;
213                 newstr = base64_encode_data_blob(mung);
214                 DEBUG(10,("INFO_21 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
215                 if (STRING_CHANGED_NC(old_string,newstr))
216                         pdb_set_munged_dial(to   , newstr, PDB_CHANGED);
217
218                 SAFE_FREE(newstr);
219         }
220         
221         if (from->fields_present & ACCT_RID) {
222                 if (from->user_rid == 0) {
223                         DEBUG(10, ("INFO_21: Asked to set User RID to 0 !? Skipping change!\n"));
224                 } else if (from->user_rid != pdb_get_user_rid(to)) {
225                         DEBUG(10,("INFO_21 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
226                 }
227         }
228         
229         if (from->fields_present & ACCT_PRIMARY_GID) {
230                 if (from->group_rid == 0) {
231                         DEBUG(10, ("INFO_21: Asked to set Group RID to 0 !? Skipping change!\n"));
232                 } else if (from->group_rid != pdb_get_group_rid(to)) {
233                         DEBUG(10,("INFO_21 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
234                         pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
235                 }
236         }
237         
238         if (from->fields_present & ACCT_FLAGS) {
239                 DEBUG(10,("INFO_21 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
240                 if (from->acb_info != pdb_get_acct_ctrl(to)) {
241                         pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
242                 }
243         }
244
245         if (from->fields_present & ACCT_LOGON_HOURS) {
246                 DEBUG(15,("INFO_21 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
247                 if (from->logon_divs != pdb_get_logon_divs(to)) {
248                         pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
249                 }
250
251                 DEBUG(15,("INFO_21 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
252                 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
253                         pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
254                 }
255
256                 DEBUG(15,("INFO_21 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
257                 /* Fix me: only update if it changes --metze */
258                 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
259
260                 /* This is max logon hours */
261                 DEBUG(10,("INFO_21 UNKNOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to),from->unknown_6));
262                 if (from->unknown_6 != pdb_get_unknown_6(to)) {
263                         pdb_set_unknown_6(to, from->unknown_6, PDB_CHANGED);
264                 }
265         }
266
267         if (from->fields_present & ACCT_BAD_PWD_COUNT) {
268                 DEBUG(10,("INFO_21 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
269                 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
270                         pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
271                 }
272         }
273
274         if (from->fields_present & ACCT_NUM_LOGONS) {
275                 DEBUG(10,("INFO_21 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
276                 if (from->logon_count != pdb_get_logon_count(to)) {
277                         pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
278                 }
279         }
280
281         DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
282         if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
283                 pdb_set_pass_must_change_time(to,0, PDB_CHANGED);
284         } else {
285                 uint32 expire;
286                 time_t new_time;
287                 if (pdb_get_pass_must_change_time(to) == 0) {
288                         if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
289                             || expire == (uint32)-1) {
290                                 new_time = get_time_t_max();
291                         } else {
292                                 time_t old_time = pdb_get_pass_last_set_time(to);
293                                 new_time = old_time + expire;
294                                 if ((new_time) < time(0)) {
295                                         new_time = time(0) + expire;
296                                 }
297                         }
298                         if (!pdb_set_pass_must_change_time (to, new_time, PDB_CHANGED)) {
299                                 DEBUG (0, ("pdb_set_pass_must_change_time failed!\n"));
300                         }
301                 }
302         }
303
304         DEBUG(10,("INFO_21 PADDING_2: %02X\n",from->padding2));
305
306         DEBUG(10,("INFO_21 PADDING_4: %08X\n",from->padding4));
307 }
308
309
310 /*************************************************************
311  Copies a SAM_USER_INFO_23 to a SAM_ACCOUNT
312 **************************************************************/
313
314 void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from)
315 {
316         time_t unix_time, stored_time;
317         const char *old_string, *new_string;
318         DATA_BLOB mung;
319
320         if (from == NULL || to == NULL) 
321                 return;
322
323         if (from->fields_present & ACCT_LAST_LOGON) {
324                 unix_time=nt_time_to_unix(&from->logon_time);
325                 stored_time = pdb_get_logon_time(to);
326                 DEBUG(10,("INFO_23 LOGON_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
327                 if (stored_time != unix_time) 
328                         pdb_set_logon_time(to, unix_time, PDB_CHANGED);
329         }
330
331         if (from->fields_present & ACCT_LAST_LOGOFF) {
332                 unix_time=nt_time_to_unix(&from->logoff_time);
333                 stored_time = pdb_get_logoff_time(to);
334                 DEBUG(10,("INFO_23 LOGOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
335                 if (stored_time != unix_time) 
336                         pdb_set_logoff_time(to, unix_time, PDB_CHANGED);
337         }
338         
339         if (from->fields_present & ACCT_EXPIRY) {
340                 unix_time=nt_time_to_unix(&from->kickoff_time);
341                 stored_time = pdb_get_kickoff_time(to);
342                 DEBUG(10,("INFO_23 KICKOFF_TIME: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
343                 if (stored_time != unix_time) 
344                         pdb_set_kickoff_time(to, unix_time , PDB_CHANGED);
345         }       
346
347         if (from->fields_present & ACCT_ALLOW_PWD_CHANGE) {
348                 unix_time=nt_time_to_unix(&from->pass_can_change_time);
349                 stored_time = pdb_get_pass_can_change_time(to);
350                 DEBUG(10,("INFO_23 PASS_CAN_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
351                 if (stored_time != unix_time) 
352                         pdb_set_pass_can_change_time(to, unix_time, PDB_CHANGED);
353         }
354
355         if (from->fields_present & ACCT_LAST_PWD_CHANGE) {
356                 unix_time=nt_time_to_unix(&from->pass_last_set_time);
357                 stored_time = pdb_get_pass_last_set_time(to);
358                 DEBUG(10,("INFO_23 PASS_LAST_SET: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
359                 if (stored_time != unix_time) 
360                         pdb_set_pass_last_set_time(to, unix_time, PDB_CHANGED);
361         }
362
363         if (from->fields_present & ACCT_FORCE_PWD_CHANGE) {
364                 unix_time=nt_time_to_unix(&from->pass_must_change_time);
365                 stored_time=pdb_get_pass_must_change_time(to);
366                 DEBUG(10,("INFO_23 PASS_MUST_CH: %lu -> %lu\n",(long unsigned int)stored_time, (long unsigned int)unix_time));
367                 if (stored_time != unix_time) 
368                         pdb_set_pass_must_change_time(to, unix_time, PDB_CHANGED);
369         }
370
371         /* Backend should check this for sanity */
372         if ((from->fields_present & ACCT_USERNAME) &&
373             (from->hdr_user_name.buffer)) {
374                 old_string = pdb_get_username(to);
375                 new_string = unistr2_static(&from->uni_user_name);
376                 DEBUG(10,("INFO_23 UNI_USER_NAME: %s -> %s\n", old_string, new_string));
377                 if (STRING_CHANGED)
378                     pdb_set_username(to      , new_string, PDB_CHANGED);
379         }
380
381         if ((from->fields_present & ACCT_FULL_NAME) &&
382             (from->hdr_full_name.buffer)) {
383                 old_string = pdb_get_fullname(to);
384                 new_string = unistr2_static(&from->uni_full_name);
385                 DEBUG(10,("INFO_23 UNI_FULL_NAME: %s -> %s\n",old_string, new_string));
386                 if (STRING_CHANGED)
387                         pdb_set_fullname(to      , new_string, PDB_CHANGED);
388         }
389         
390         if ((from->fields_present & ACCT_HOME_DIR) &&
391             (from->hdr_home_dir.buffer)) {
392                 old_string = pdb_get_homedir(to);
393                 new_string = unistr2_static(&from->uni_home_dir);
394                 DEBUG(10,("INFO_23 UNI_HOME_DIR: %s -> %s\n",old_string,new_string));
395                 if (STRING_CHANGED)
396                         pdb_set_homedir(to       , new_string, PDB_CHANGED);
397         }
398
399         if ((from->fields_present & ACCT_HOME_DRIVE) &&
400             (from->hdr_dir_drive.buffer)) {
401                 old_string = pdb_get_dir_drive(to);
402                 new_string = unistr2_static(&from->uni_dir_drive);
403                 DEBUG(10,("INFO_23 UNI_DIR_DRIVE: %s -> %s\n",old_string,new_string));
404                 if (STRING_CHANGED)
405                         pdb_set_dir_drive(to     , new_string, PDB_CHANGED);
406         }
407
408         if ((from->fields_present & ACCT_LOGON_SCRIPT) &&
409             (from->hdr_logon_script.buffer)) {
410                 old_string = pdb_get_logon_script(to);
411                 new_string = unistr2_static(&from->uni_logon_script);
412                 DEBUG(10,("INFO_23 UNI_LOGON_SCRIPT: %s -> %s\n",old_string,new_string));
413                 if (STRING_CHANGED)
414                         pdb_set_logon_script(to  , new_string, PDB_CHANGED);
415         }
416
417         if ((from->fields_present & ACCT_PROFILE) &&
418             (from->hdr_profile_path.buffer)) {
419                 old_string = pdb_get_profile_path(to);
420                 new_string = unistr2_static(&from->uni_profile_path);
421                 DEBUG(10,("INFO_23 UNI_PROFILE_PATH: %s -> %s\n",old_string, new_string));
422                 if (STRING_CHANGED)
423                         pdb_set_profile_path(to  , new_string, PDB_CHANGED);
424         }
425         
426         if ((from->fields_present & ACCT_DESCRIPTION) &&
427             (from->hdr_acct_desc.buffer)) {
428                 old_string = pdb_get_acct_desc(to);
429                 new_string = unistr2_static(&from->uni_acct_desc);
430                 DEBUG(10,("INFO_23 UNI_ACCT_DESC: %s -> %s\n",old_string,new_string));
431                 if (STRING_CHANGED)
432                         pdb_set_acct_desc(to     , new_string, PDB_CHANGED);
433         }
434         
435         if ((from->fields_present & ACCT_WORKSTATIONS) &&
436             (from->hdr_workstations.buffer)) {
437                 old_string = pdb_get_workstations(to);
438                 new_string = unistr2_static(&from->uni_workstations);
439                 DEBUG(10,("INFO_23 UNI_WORKSTATIONS: %s -> %s\n",old_string, new_string));
440                 if (STRING_CHANGED)
441                         pdb_set_workstations(to  , new_string, PDB_CHANGED);
442         }
443
444         /* is this right? */
445         if ((from->fields_present & ACCT_ADMIN_DESC) &&
446             (from->hdr_unknown_str.buffer)) {
447                 old_string = pdb_get_unknown_str(to);
448                 new_string = unistr2_static(&from->uni_unknown_str);
449                 DEBUG(10,("INFO_23 UNI_UNKNOWN_STR: %s -> %s\n",old_string, new_string));
450                 if (STRING_CHANGED)
451                         pdb_set_unknown_str(to   , new_string, PDB_CHANGED);
452         }
453         
454         if ((from->fields_present & ACCT_CALLBACK) &&
455             (from->hdr_munged_dial.buffer)) {
456                 char *newstr;
457                 old_string = pdb_get_munged_dial(to);
458                 mung.length = from->hdr_munged_dial.uni_str_len;
459                 mung.data = (uint8 *) from->uni_munged_dial.buffer;
460                 newstr = base64_encode_data_blob(mung);
461                 DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
462                 if (STRING_CHANGED_NC(old_string, newstr))
463                         pdb_set_munged_dial(to   , newstr, PDB_CHANGED);
464
465                 SAFE_FREE(newstr);
466         }
467         
468         if (from->fields_present & ACCT_RID) {
469                 if (from->user_rid == 0) {
470                         DEBUG(10, ("INFO_23: Asked to set User RID to 0 !? Skipping change!\n"));
471                 } else if (from->user_rid != pdb_get_user_rid(to)) {
472                         DEBUG(10,("INFO_23 USER_RID: %u -> %u NOT UPDATED!\n",pdb_get_user_rid(to),from->user_rid));
473                 }
474         }
475
476         if (from->fields_present & ACCT_PRIMARY_GID) {
477                 if  (from->group_rid == 0) {
478                         DEBUG(10, ("INFO_23: Asked to set Group RID to 0 !? Skipping change!\n"));
479                 } else if (from->group_rid != pdb_get_group_rid(to)) {
480                         DEBUG(10,("INFO_23 GROUP_RID: %u -> %u\n",pdb_get_group_rid(to),from->group_rid));
481                         pdb_set_group_sid_from_rid(to, from->group_rid, PDB_CHANGED);
482                 }
483         }
484         
485         if (from->fields_present & ACCT_FLAGS) {
486                 DEBUG(10,("INFO_23 ACCT_CTRL: %08X -> %08X\n",pdb_get_acct_ctrl(to),from->acb_info));
487                 if (from->acb_info != pdb_get_acct_ctrl(to)) {
488                         pdb_set_acct_ctrl(to, from->acb_info, PDB_CHANGED);
489                 }
490         }
491
492         if (from->fields_present & ACCT_LOGON_HOURS) {
493                 DEBUG(15,("INFO_23 LOGON_DIVS: %08X -> %08X\n",pdb_get_logon_divs(to),from->logon_divs));
494                 if (from->logon_divs != pdb_get_logon_divs(to)) {
495                         pdb_set_logon_divs(to, from->logon_divs, PDB_CHANGED);
496                 }
497
498                 DEBUG(15,("INFO_23 LOGON_HRS.LEN: %08X -> %08X\n",pdb_get_hours_len(to),from->logon_hrs.len));
499                 if (from->logon_hrs.len != pdb_get_hours_len(to)) {
500                         pdb_set_hours_len(to, from->logon_hrs.len, PDB_CHANGED);
501                 }
502
503                 DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
504                 /* Fix me: only update if it changes --metze */
505                 pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
506
507                 /* This is max logon hours */
508                 DEBUG(10,("INFO_23 UNKOWN_6: %08X -> %08X\n",pdb_get_unknown_6(to),from->unknown_6));
509                 if (from->unknown_6 != pdb_get_unknown_6(to)) {
510                         pdb_set_unknown_6(to, from->unknown_6, PDB_CHANGED);
511                 }
512         }
513
514         if (from->fields_present & ACCT_BAD_PWD_COUNT) {
515                 DEBUG(10,("INFO_23 BAD_PASSWORD_COUNT: %08X -> %08X\n",pdb_get_bad_password_count(to),from->bad_password_count));
516                 if (from->bad_password_count != pdb_get_bad_password_count(to)) {
517                         pdb_set_bad_password_count(to, from->bad_password_count, PDB_CHANGED);
518                 }
519         }
520
521         if (from->fields_present & ACCT_NUM_LOGONS) {
522                 DEBUG(10,("INFO_23 LOGON_COUNT: %08X -> %08X\n",pdb_get_logon_count(to),from->logon_count));
523                 if (from->logon_count != pdb_get_logon_count(to)) {
524                         pdb_set_logon_count(to, from->logon_count, PDB_CHANGED);
525                 }
526         }
527
528         DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
529         if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
530                 pdb_set_pass_must_change_time(to,0, PDB_CHANGED);               
531         } else {
532                 uint32 expire;
533                 time_t new_time;
534                 if (pdb_get_pass_must_change_time(to) == 0) {
535                         if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
536                             || expire == (uint32)-1) {
537                                 new_time = get_time_t_max();
538                         } else {
539                                 time_t old_time = pdb_get_pass_last_set_time(to);
540                                 new_time = old_time + expire;
541                                 if ((new_time) < time(0)) {
542                                         new_time = time(0) + expire;
543                                 }
544                         }
545                         if (!pdb_set_pass_must_change_time (to, new_time, PDB_CHANGED)) {
546                                 DEBUG (0, ("pdb_set_pass_must_change_time failed!\n"));
547                         }
548                 }
549         }
550
551         DEBUG(10,("INFO_23 PADDING_2: %02X\n",from->padding2));
552
553         DEBUG(10,("INFO_23 PADDING_4: %08X\n",from->padding4));
554 }