Removed version number from file header.
[samba.git] / source3 / passdb / pdb_get_set.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SAM_ACCOUNT access routines
4    Copyright (C) Jeremy Allison                 1996-2001
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       
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 /**
27  * @todo Redefine this to NULL, but this changes the API becouse
28  *       much of samba assumes that the pdb_get...() funtions 
29  *       return pstrings.  (ie not null-pointers).
30  *       See also pdb_fill_default_sam().
31  */
32
33 #define PDB_NOT_QUITE_NULL ""
34
35 /*********************************************************************
36  Collection of get...() functions for SAM_ACCOUNT_INFO.
37  ********************************************************************/
38
39 uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
40 {
41         if (sampass)
42                 return (sampass->private.acct_ctrl);
43         else
44                 return (ACB_DISABLED);
45 }
46
47 time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
48 {
49         if (sampass)
50                 return (sampass->private.logon_time);
51         else
52                 return (0);
53 }
54
55 time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
56 {
57         if (sampass)
58                 return (sampass->private.logoff_time);
59         else
60                 return (-1);
61 }
62
63 time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
64 {
65         if (sampass)
66                 return (sampass->private.kickoff_time);
67         else
68                 return (-1);
69 }
70
71 time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
72 {
73         if (sampass)
74                 return (sampass->private.pass_last_set_time);
75         else
76                 return (-1);
77 }
78
79 time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
80 {
81         if (sampass)
82                 return (sampass->private.pass_can_change_time);
83         else
84                 return (-1);
85 }
86
87 time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
88 {
89         if (sampass)
90                 return (sampass->private.pass_must_change_time);
91         else
92                 return (-1);
93 }
94
95 uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
96 {
97         if (sampass)
98                 return (sampass->private.logon_divs);
99         else
100                 return (-1);
101 }
102
103 uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
104 {
105         if (sampass)
106                 return (sampass->private.hours_len);
107         else
108                 return (-1);
109 }
110
111 const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
112 {
113         if (sampass)
114                 return (sampass->private.hours);
115         else
116                 return (NULL);
117 }
118
119 const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *sampass)
120 {
121         if (sampass) {
122                 SMB_ASSERT((!sampass->private.nt_pw.data) 
123                            || sampass->private.nt_pw.length == NT_HASH_LEN);
124                 return ((uint8*)sampass->private.nt_pw.data);
125         }
126         else
127                 return (NULL);
128 }
129
130 const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *sampass)
131 {
132         if (sampass) {
133                 SMB_ASSERT((!sampass->private.lm_pw.data) 
134                            || sampass->private.lm_pw.length == LM_HASH_LEN);
135                 return ((uint8*)sampass->private.lm_pw.data);
136         }
137         else
138                 return (NULL);
139 }
140
141 uint32 pdb_get_user_rid (const SAM_ACCOUNT *sampass)
142 {
143         if (sampass)
144                 return (sampass->private.user_rid);
145         else
146                 return (-1);
147 }
148
149 uint32 pdb_get_group_rid (const SAM_ACCOUNT *sampass)
150 {
151         if (sampass)
152                 return (sampass->private.group_rid);
153         else
154                 return (-1);
155 }
156
157 /**
158  * Get flags showing what is initalised in the SAM_ACCOUNT
159  * @param sampass the SAM_ACCOUNT in question
160  * @return the flags indicating the members initialised in the struct.
161  **/
162  
163 uint32 pdb_get_init_flag (const SAM_ACCOUNT *sampass)
164 {
165         if (sampass)
166                 return sampass->private.init_flag;
167         else 
168                 return FLAG_SAM_UNINIT;
169 }
170
171 uid_t pdb_get_uid (const SAM_ACCOUNT *sampass)
172 {
173         if (sampass)
174                 return (sampass->private.uid);
175         else
176                 return (-1);
177 }
178
179 gid_t pdb_get_gid (const SAM_ACCOUNT *sampass)
180 {
181         if (sampass)
182                 return (sampass->private.gid);
183         else
184                 return (-1);
185 }
186
187 const char* pdb_get_username (const SAM_ACCOUNT *sampass)
188 {
189         if (sampass)
190                 return (sampass->private.username);
191         else
192                 return (NULL);
193 }
194
195 const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
196 {
197         if (sampass)
198                 return (sampass->private.domain);
199         else
200                 return (NULL);
201 }
202
203 const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
204 {
205         if (sampass)
206                 return (sampass->private.nt_username);
207         else
208                 return (NULL);
209 }
210
211 const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
212 {
213         if (sampass)
214                 return (sampass->private.full_name);
215         else
216                 return (NULL);
217 }
218
219 const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
220 {
221         if (sampass)
222                 return (sampass->private.home_dir);
223         else
224                 return (NULL);
225 }
226
227 const char* pdb_get_dirdrive (const SAM_ACCOUNT *sampass)
228 {
229         if (sampass)
230                 return (sampass->private.dir_drive);
231         else
232                 return (NULL);
233 }
234
235 const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
236 {
237         if (sampass)
238                 return (sampass->private.logon_script);
239         else
240                 return (NULL);
241 }
242
243 const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
244 {
245         if (sampass)
246                 return (sampass->private.profile_path);
247         else
248                 return (NULL);
249 }
250
251 const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
252 {
253         if (sampass)
254                 return (sampass->private.acct_desc);
255         else
256                 return (NULL);
257 }
258
259 const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
260 {
261         if (sampass)
262                 return (sampass->private.workstations);
263         else
264                 return (NULL);
265 }
266
267 const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
268 {
269         if (sampass)
270                 return (sampass->private.unknown_str);
271         else
272                 return (NULL);
273 }
274
275 const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
276 {
277         if (sampass)
278                 return (sampass->private.munged_dial);
279         else
280                 return (NULL);
281 }
282
283 uint32 pdb_get_unknown3 (const SAM_ACCOUNT *sampass)
284 {
285         if (sampass)
286                 return (sampass->private.unknown_3);
287         else
288                 return (-1);
289 }
290
291 uint32 pdb_get_unknown5 (const SAM_ACCOUNT *sampass)
292 {
293         if (sampass)
294                 return (sampass->private.unknown_5);
295         else
296                 return (-1);
297 }
298
299 uint32 pdb_get_unknown6 (const SAM_ACCOUNT *sampass)
300 {
301         if (sampass)
302                 return (sampass->private.unknown_6);
303         else
304                 return (-1);
305 }
306
307 /*********************************************************************
308  Collection of set...() functions for SAM_ACCOUNT_INFO.
309  ********************************************************************/
310
311 BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
312 {
313         if (!sampass)
314                 return False;
315                 
316         if (sampass) {
317                 sampass->private.acct_ctrl = flags;
318                 return True;
319         }
320         
321         return False;
322 }
323
324 BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime)
325 {
326         if (!sampass)
327                 return False;
328
329         sampass->private.logon_time = mytime;
330         return True;
331 }
332
333 BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime)
334 {
335         if (!sampass)
336                 return False;
337
338         sampass->private.logoff_time = mytime;
339         return True;
340 }
341
342 BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime)
343 {
344         if (!sampass)
345                 return False;
346
347         sampass->private.kickoff_time = mytime;
348         return True;
349 }
350
351 BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime)
352 {
353         if (!sampass)
354                 return False;
355
356         sampass->private.pass_can_change_time = mytime;
357         return True;
358 }
359
360 BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime)
361 {
362         if (!sampass)
363                 return False;
364
365         sampass->private.pass_must_change_time = mytime;
366         return True;
367 }
368
369 BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime)
370 {
371         if (!sampass)
372                 return False;
373
374         sampass->private.pass_last_set_time = mytime;
375         return True;
376 }
377
378 BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len)
379 {
380         if (!sampass)
381                 return False;
382
383         sampass->private.hours_len = len;
384         return True;
385 }
386
387 BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours)
388 {
389         if (!sampass)
390                 return False;
391
392         sampass->private.logon_divs = hours;
393         return True;
394 }
395
396 /**
397  * Set flags showing what is initalised in the SAM_ACCOUNT
398  * @param sampass the SAM_ACCOUNT in question
399  * @param flag The *new* flag to be set.  Old flags preserved
400  *             this flag is only added.  
401  **/
402  
403 BOOL pdb_set_init_flag (SAM_ACCOUNT *sampass, uint32 flag)
404 {
405         if (!sampass)
406                 return False;
407
408         sampass->private.init_flag |= flag;
409
410         return True;
411 }
412
413 BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t uid)
414 {
415         if (!sampass)
416                 return False;
417         
418         DEBUG(10, ("pdb_set_uid: setting uid %d, was %d\n", 
419                    (int)uid, (int)sampass->private.uid));
420  
421         sampass->private.uid = uid;
422         pdb_set_init_flag(sampass, FLAG_SAM_UID); 
423
424         return True;
425
426 }
427
428 BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid)
429 {
430         if (!sampass)
431                 return False;
432                 
433         DEBUG(10, ("pdb_set_gid: setting gid %d, was %d\n", 
434                    (int)gid, (int)sampass->private.gid));
435  
436         sampass->private.gid = gid; 
437         pdb_set_init_flag(sampass, FLAG_SAM_GID); 
438
439         return True;
440
441 }
442
443 BOOL pdb_set_user_rid (SAM_ACCOUNT *sampass, uint32 rid)
444 {
445         if (!sampass)
446                 return False;
447
448         DEBUG(10, ("pdb_set_rid: setting user rid %d, was %d\n", 
449                    rid, sampass->private.user_rid));
450  
451         sampass->private.user_rid = rid;
452         return True;
453 }
454
455 BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid)
456 {
457         if (!sampass)
458                 return False;
459
460         DEBUG(10, ("pdb_set_group_rid: setting group rid %d, was %d\n", 
461                    grid, sampass->private.group_rid));
462  
463         sampass->private.group_rid = grid;
464         return True;
465 }
466
467 /*********************************************************************
468  Set the user's UNIX name.
469  ********************************************************************/
470
471 BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username)
472 {       
473         if (!sampass)
474                 return False;
475
476         DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", 
477                    username, sampass->private.username));
478  
479         if (username) { 
480                 sampass->private.username = talloc_strdup(sampass->mem_ctx, username);
481
482                 if (!sampass->private.username) {
483                         DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
484                         return False;
485                 }
486
487         } else {
488                 sampass->private.username = PDB_NOT_QUITE_NULL;
489         }
490
491         return True;
492 }
493
494 /*********************************************************************
495  Set the domain name.
496  ********************************************************************/
497
498 BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain)
499 {       
500         if (!sampass)
501                 return False;
502
503         DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", 
504                    domain, sampass->private.domain));
505  
506         if (domain) { 
507                 sampass->private.domain = talloc_strdup(sampass->mem_ctx, domain);
508
509                 if (!sampass->private.domain) {
510                         DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
511                         return False;
512                 }
513
514         } else {
515                 sampass->private.domain = PDB_NOT_QUITE_NULL;
516         }
517
518         return True;
519 }
520
521 /*********************************************************************
522  Set the user's NT name.
523  ********************************************************************/
524
525 BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username)
526 {
527         if (!sampass)
528                 return False;
529
530         DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", 
531                    nt_username, sampass->private.nt_username));
532  
533         if (nt_username) { 
534                 sampass->private.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
535                 
536                 if (!sampass->private.nt_username) {
537                         DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
538                         return False;
539                 }
540
541         } else {
542                 sampass->private.nt_username = PDB_NOT_QUITE_NULL;
543         }
544
545         return True;
546 }
547
548 /*********************************************************************
549  Set the user's full name.
550  ********************************************************************/
551
552 BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name)
553 {
554         if (!sampass)
555                 return False;
556
557         DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", 
558                    full_name, sampass->private.full_name));
559         
560         if (full_name) { 
561                 sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);
562
563                 if (!sampass->private.full_name) {
564                         DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
565                         return False;
566                 }
567
568         } else {
569                 sampass->private.full_name = PDB_NOT_QUITE_NULL;
570         }
571
572         return True;
573 }
574
575 /*********************************************************************
576  Set the user's logon script.
577  ********************************************************************/
578
579 BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, BOOL store)
580 {
581         if (!sampass)
582                 return False;
583
584         DEBUG(10, ("pdb_set_logon_script: setting logon script (store:%d) %s, was %s\n", 
585                    store, logon_script, sampass->private.logon_script));
586  
587         if (logon_script) { 
588                 sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
589
590                 if (!sampass->private.logon_script) {
591                         DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
592                         return False;
593                 }
594
595         } else {
596                 sampass->private.logon_script = PDB_NOT_QUITE_NULL;
597         }
598         
599         if (store)
600                 pdb_set_init_flag(sampass, FLAG_SAM_LOGONSCRIPT); 
601
602         return True;
603 }
604
605 /*********************************************************************
606  Set the user's profile path.
607  ********************************************************************/
608
609 BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, BOOL store)
610 {
611         if (!sampass)
612                 return False;
613
614         DEBUG(10, ("pdb_set_profile_path: setting profile path (store:%d) %s, was %s\n", 
615                    store, profile_path, sampass->private.profile_path));
616  
617         if (profile_path) { 
618                 sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
619                 
620                 if (!sampass->private.profile_path) {
621                         DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
622                         return False;
623                 }
624
625         } else {
626                 sampass->private.profile_path = PDB_NOT_QUITE_NULL;
627         }
628
629         if (store)
630                 pdb_set_init_flag(sampass, FLAG_SAM_PROFILE);
631
632         return True;
633 }
634
635 /*********************************************************************
636  Set the user's directory drive.
637  ********************************************************************/
638
639 BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, BOOL store)
640 {
641         if (!sampass)
642                 return False;
643
644         if (dir_drive) { 
645                 sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
646                 
647                 if (!sampass->private.dir_drive) {
648                         DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
649                         return False;
650                 }
651
652         } else {
653                 sampass->private.dir_drive = PDB_NOT_QUITE_NULL;
654         }
655         
656         if (store)
657                 pdb_set_init_flag(sampass, FLAG_SAM_DRIVE);
658
659         return True;
660 }
661
662 /*********************************************************************
663  Set the user's home directory.
664  ********************************************************************/
665
666 BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, BOOL store)
667 {
668         if (!sampass)
669                 return False;
670
671         if (home_dir) { 
672                 sampass->private.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
673                 
674                 if (!sampass->private.home_dir) {
675                         DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
676                         return False;
677                 }
678
679         } else {
680                 sampass->private.home_dir = PDB_NOT_QUITE_NULL;
681         }
682
683         if (store)
684                 pdb_set_init_flag(sampass, FLAG_SAM_SMBHOME);
685
686         return True;
687 }
688
689 /*********************************************************************
690  Set the user's account description.
691  ********************************************************************/
692
693 BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc)
694 {
695         if (!sampass)
696                 return False;
697
698         if (acct_desc) { 
699                 sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
700
701                 if (!sampass->private.acct_desc) {
702                         DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
703                         return False;
704                 }
705
706         } else {
707                 sampass->private.acct_desc = PDB_NOT_QUITE_NULL;
708         }
709
710         return True;
711 }
712
713 /*********************************************************************
714  Set the user's workstation allowed list.
715  ********************************************************************/
716
717 BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations)
718 {
719         if (!sampass)
720                 return False;
721
722         if (workstations) { 
723                 sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);
724
725                 if (!sampass->private.workstations) {
726                         DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
727                         return False;
728                 }
729
730         } else {
731                 sampass->private.workstations = PDB_NOT_QUITE_NULL;
732         }
733
734         return True;
735 }
736
737 /*********************************************************************
738  Set the user's 'unknown_str', whatever the heck this actually is...
739  ********************************************************************/
740
741 BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str)
742 {
743         if (!sampass)
744                 return False;
745
746         if (unknown_str) { 
747                 sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
748                 
749                 if (!sampass->private.unknown_str) {
750                         DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
751                         return False;
752                 }
753
754         } else {
755                 sampass->private.unknown_str = PDB_NOT_QUITE_NULL;
756         }
757
758         return True;
759 }
760
761 /*********************************************************************
762  Set the user's dial string.
763  ********************************************************************/
764
765 BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial)
766 {
767         if (!sampass)
768                 return False;
769         if (munged_dial) { 
770                 sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
771                 
772                 if (!sampass->private.munged_dial) {
773                         DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
774                         return False;
775                 }
776
777         } else {
778                 sampass->private.munged_dial = PDB_NOT_QUITE_NULL;
779         }
780
781         return True;
782 }
783
784 /*********************************************************************
785  Set the user's NT hash.
786  ********************************************************************/
787
788 BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
789 {
790         if (!sampass)
791                 return False;
792
793         data_blob_clear_free(&sampass->private.nt_pw);
794         
795         sampass->private.nt_pw = data_blob(pwd, NT_HASH_LEN);
796
797         return True;
798 }
799
800 /*********************************************************************
801  Set the user's LM hash.
802  ********************************************************************/
803
804 BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
805 {
806         if (!sampass)
807                 return False;
808
809         data_blob_clear_free(&sampass->private.lm_pw);
810         
811         sampass->private.lm_pw = data_blob(pwd, LM_HASH_LEN);
812
813         return True;
814 }
815
816 BOOL pdb_set_unknown_3 (SAM_ACCOUNT *sampass, uint32 unkn)
817 {
818         if (!sampass)
819                 return False;
820
821         sampass->private.unknown_3 = unkn;
822         return True;
823 }
824
825 BOOL pdb_set_unknown_5 (SAM_ACCOUNT *sampass, uint32 unkn)
826 {
827         if (!sampass)
828                 return False;
829
830         sampass->private.unknown_5 = unkn;
831         return True;
832 }
833
834 BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn)
835 {
836         if (!sampass)
837                 return False;
838
839         sampass->private.unknown_6 = unkn;
840         return True;
841 }
842
843 BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours)
844 {
845         if (!sampass)
846                 return False;
847
848         if (!hours) {
849                 memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
850                 return True;
851         }
852         
853         memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);
854
855         return True;
856 }
857
858
859 /* Helpful interfaces to the above */
860
861 /*********************************************************************
862  Sets the last changed times and must change times for a normal
863  password change.
864  ********************************************************************/
865
866 BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
867 {
868         uint32 expire;
869
870         if (!sampass)
871                 return False;
872         
873         if (!pdb_set_pass_last_set_time (sampass, time(NULL)))
874                 return False;
875
876         account_policy_get(AP_MAX_PASSWORD_AGE, &expire);
877
878         if (expire==(uint32)-1) {
879                 if (!pdb_set_pass_must_change_time (sampass, 0))
880                         return False;
881         } else {
882                 if (!pdb_set_pass_must_change_time (sampass, 
883                                             pdb_get_pass_last_set_time(sampass)
884                                             + expire))
885                         return False;
886         }
887         
888         return True;
889 }
890
891 /*********************************************************************
892  Set the user's PLAINTEXT password.  Used as an interface to the above.
893  Also sets the last change time to NOW.
894  ********************************************************************/
895
896 BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
897 {
898         uchar new_lanman_p16[16];
899         uchar new_nt_p16[16];
900
901         if (!sampass || !plaintext)
902                 return False;
903         
904         nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);
905
906         if (!pdb_set_nt_passwd (sampass, new_nt_p16)) 
907                 return False;
908
909         if (!pdb_set_lanman_passwd (sampass, new_lanman_p16)) 
910                 return False;
911         
912         if (!pdb_set_pass_changed_now (sampass))
913                 return False;
914
915         return True;
916 }
917