sync with HEAD
[Samba.git] / source / passdb / pdb_get_set.c
blob07474693ddf2bbefbbb95d736452ea5b2d0df2b1
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 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_PASSDB
30 /**
31 * @todo Redefine this to NULL, but this changes the API becouse
32 * much of samba assumes that the pdb_get...() funtions
33 * return pstrings. (ie not null-pointers).
34 * See also pdb_fill_default_sam().
37 #define PDB_NOT_QUITE_NULL ""
39 /*********************************************************************
40 Collection of get...() functions for SAM_ACCOUNT_INFO.
41 ********************************************************************/
43 uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
45 if (sampass)
46 return (sampass->private.acct_ctrl);
47 else
48 return (ACB_DISABLED);
51 time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
53 if (sampass)
54 return (sampass->private.logon_time);
55 else
56 return (0);
59 time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
61 if (sampass)
62 return (sampass->private.logoff_time);
63 else
64 return (-1);
67 time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
69 if (sampass)
70 return (sampass->private.kickoff_time);
71 else
72 return (-1);
75 time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
77 if (sampass)
78 return (sampass->private.pass_last_set_time);
79 else
80 return (-1);
83 time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
85 if (sampass)
86 return (sampass->private.pass_can_change_time);
87 else
88 return (-1);
91 time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
93 if (sampass)
94 return (sampass->private.pass_must_change_time);
95 else
96 return (-1);
99 uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
101 if (sampass)
102 return (sampass->private.logon_divs);
103 else
104 return (-1);
107 uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
109 if (sampass)
110 return (sampass->private.hours_len);
111 else
112 return (-1);
115 const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
117 if (sampass)
118 return (sampass->private.hours);
119 else
120 return (NULL);
123 const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *sampass)
125 if (sampass) {
126 SMB_ASSERT((!sampass->private.nt_pw.data)
127 || sampass->private.nt_pw.length == NT_HASH_LEN);
128 return ((uint8*)sampass->private.nt_pw.data);
130 else
131 return (NULL);
134 const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *sampass)
136 if (sampass) {
137 SMB_ASSERT((!sampass->private.lm_pw.data)
138 || sampass->private.lm_pw.length == LM_HASH_LEN);
139 return ((uint8*)sampass->private.lm_pw.data);
141 else
142 return (NULL);
145 /* Return the plaintext password if known. Most of the time
146 it isn't, so don't assume anything magic about this function.
148 Used to pass the plaintext to passdb backends that might
149 want to store more than just the NTLM hashes.
151 const char* pdb_get_plaintext_passwd (const SAM_ACCOUNT *sampass)
153 if (sampass) {
154 return (sampass->private.plaintext_pw);
156 else
157 return (NULL);
159 const DOM_SID *pdb_get_user_sid(const SAM_ACCOUNT *sampass)
161 if (sampass)
162 return &sampass->private.user_sid;
163 else
164 return (NULL);
167 const DOM_SID *pdb_get_group_sid(const SAM_ACCOUNT *sampass)
169 if (sampass)
170 return &sampass->private.group_sid;
171 else
172 return (NULL);
176 * Get flags showing what is initalised in the SAM_ACCOUNT
177 * @param sampass the SAM_ACCOUNT in question
178 * @return the flags indicating the members initialised in the struct.
181 uint32 pdb_get_init_flag (const SAM_ACCOUNT *sampass)
183 if (sampass)
184 return sampass->private.init_flag;
185 else
186 return FLAG_SAM_UNINIT;
189 uid_t pdb_get_uid (const SAM_ACCOUNT *sampass)
191 if (sampass)
192 return (sampass->private.uid);
193 else
194 return (-1);
197 gid_t pdb_get_gid (const SAM_ACCOUNT *sampass)
199 if (sampass)
200 return (sampass->private.gid);
201 else
202 return (-1);
205 const char* pdb_get_username (const SAM_ACCOUNT *sampass)
207 if (sampass)
208 return (sampass->private.username);
209 else
210 return (NULL);
213 const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
215 if (sampass)
216 return (sampass->private.domain);
217 else
218 return (NULL);
221 const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
223 if (sampass)
224 return (sampass->private.nt_username);
225 else
226 return (NULL);
229 const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
231 if (sampass)
232 return (sampass->private.full_name);
233 else
234 return (NULL);
237 const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
239 if (sampass)
240 return (sampass->private.home_dir);
241 else
242 return (NULL);
245 const char* pdb_get_unix_homedir (const SAM_ACCOUNT *sampass)
247 if (sampass)
248 return (sampass->private.unix_home_dir);
249 else
250 return (NULL);
253 const char* pdb_get_dir_drive (const SAM_ACCOUNT *sampass)
255 if (sampass)
256 return (sampass->private.dir_drive);
257 else
258 return (NULL);
261 const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
263 if (sampass)
264 return (sampass->private.logon_script);
265 else
266 return (NULL);
269 const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
271 if (sampass)
272 return (sampass->private.profile_path);
273 else
274 return (NULL);
277 const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
279 if (sampass)
280 return (sampass->private.acct_desc);
281 else
282 return (NULL);
285 const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
287 if (sampass)
288 return (sampass->private.workstations);
289 else
290 return (NULL);
293 const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
295 if (sampass)
296 return (sampass->private.unknown_str);
297 else
298 return (NULL);
301 const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
303 if (sampass)
304 return (sampass->private.munged_dial);
305 else
306 return (NULL);
309 uint32 pdb_get_unknown3 (const SAM_ACCOUNT *sampass)
311 if (sampass)
312 return (sampass->private.unknown_3);
313 else
314 return (-1);
317 uint32 pdb_get_unknown5 (const SAM_ACCOUNT *sampass)
319 if (sampass)
320 return (sampass->private.unknown_5);
321 else
322 return (-1);
325 uint32 pdb_get_unknown6 (const SAM_ACCOUNT *sampass)
327 if (sampass)
328 return (sampass->private.unknown_6);
329 else
330 return (-1);
333 /*********************************************************************
334 Collection of set...() functions for SAM_ACCOUNT_INFO.
335 ********************************************************************/
337 BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
339 if (!sampass)
340 return False;
342 if (sampass) {
343 sampass->private.acct_ctrl = flags;
344 return True;
347 return False;
350 BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
352 if (!sampass)
353 return False;
355 sampass->private.logon_time = mytime;
357 if (store)
358 pdb_set_init_flag(sampass, FLAG_SAM_LOGONTIME);
360 return True;
363 BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
365 if (!sampass)
366 return False;
368 sampass->private.logoff_time = mytime;
370 if (store)
371 pdb_set_init_flag(sampass, FLAG_SAM_LOGOFFTIME);
373 return True;
376 BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
378 if (!sampass)
379 return False;
381 sampass->private.kickoff_time = mytime;
383 if (store)
384 pdb_set_init_flag(sampass, FLAG_SAM_KICKOFFTIME);
386 return True;
389 BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
391 if (!sampass)
392 return False;
394 sampass->private.pass_can_change_time = mytime;
396 if (store)
397 pdb_set_init_flag(sampass, FLAG_SAM_CANCHANGETIME);
399 return True;
402 BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
404 if (!sampass)
405 return False;
407 sampass->private.pass_must_change_time = mytime;
409 if (store)
410 pdb_set_init_flag(sampass, FLAG_SAM_MUSTCHANGETIME);
412 return True;
415 BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime)
417 if (!sampass)
418 return False;
420 sampass->private.pass_last_set_time = mytime;
422 return True;
425 BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len)
427 if (!sampass)
428 return False;
430 sampass->private.hours_len = len;
431 return True;
434 BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours)
436 if (!sampass)
437 return False;
439 sampass->private.logon_divs = hours;
440 return True;
444 * Set flags showing what is initalised in the SAM_ACCOUNT
445 * @param sampass the SAM_ACCOUNT in question
446 * @param flag The *new* flag to be set. Old flags preserved
447 * this flag is only added.
450 BOOL pdb_set_init_flag (SAM_ACCOUNT *sampass, uint32 flag)
452 if (!sampass)
453 return False;
455 sampass->private.init_flag |= flag;
457 return True;
460 BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t uid)
462 if (!sampass)
463 return False;
465 DEBUG(10, ("pdb_set_uid: setting uid %d, was %d\n",
466 (int)uid, (int)sampass->private.uid));
468 sampass->private.uid = uid;
469 pdb_set_init_flag(sampass, FLAG_SAM_UID);
471 return True;
475 BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid)
477 if (!sampass)
478 return False;
480 DEBUG(10, ("pdb_set_gid: setting gid %d, was %d\n",
481 (int)gid, (int)sampass->private.gid));
483 sampass->private.gid = gid;
484 pdb_set_init_flag(sampass, FLAG_SAM_GID);
486 return True;
490 BOOL pdb_set_user_sid (SAM_ACCOUNT *sampass, DOM_SID *u_sid)
492 if (!sampass || !u_sid)
493 return False;
495 sid_copy(&sampass->private.user_sid, u_sid);
497 DEBUG(10, ("pdb_set_user_sid: setting user sid %s\n",
498 sid_string_static(&sampass->private.user_sid)));
500 return True;
503 BOOL pdb_set_user_sid_from_string (SAM_ACCOUNT *sampass, fstring u_sid)
505 DOM_SID new_sid;
506 if (!sampass || !u_sid)
507 return False;
509 DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
510 u_sid));
512 if (!string_to_sid(&new_sid, u_sid)) {
513 DEBUG(1, ("pdb_set_user_sid_from_string: %s isn't a valid SID!\n", u_sid));
514 return False;
517 if (!pdb_set_user_sid(sampass, &new_sid)) {
518 DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", u_sid));
519 return False;
522 return True;
525 BOOL pdb_set_group_sid (SAM_ACCOUNT *sampass, DOM_SID *g_sid)
527 if (!sampass || !g_sid)
528 return False;
530 sid_copy(&sampass->private.group_sid, g_sid);
532 DEBUG(10, ("pdb_set_group_sid: setting group sid %s\n",
533 sid_string_static(&sampass->private.group_sid)));
535 return True;
538 BOOL pdb_set_group_sid_from_string (SAM_ACCOUNT *sampass, fstring g_sid)
540 DOM_SID new_sid;
541 if (!sampass || !g_sid)
542 return False;
544 DEBUG(10, ("pdb_set_group_sid_from_string: setting group sid %s\n",
545 g_sid));
547 if (!string_to_sid(&new_sid, g_sid)) {
548 DEBUG(1, ("pdb_set_group_sid_from_string: %s isn't a valid SID!\n", g_sid));
549 return False;
552 if (!pdb_set_group_sid(sampass, &new_sid)) {
553 DEBUG(1, ("pdb_set_group_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", g_sid));
554 return False;
556 return True;
559 /*********************************************************************
560 Set the user's UNIX name.
561 ********************************************************************/
563 BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username)
565 if (!sampass)
566 return False;
568 if (username) {
569 DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", username,
570 (sampass->private.username)?(sampass->private.username):"NULL"));
572 sampass->private.username = talloc_strdup(sampass->mem_ctx, username);
574 if (!sampass->private.username) {
575 DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
576 return False;
579 } else {
580 sampass->private.username = PDB_NOT_QUITE_NULL;
583 return True;
586 /*********************************************************************
587 Set the domain name.
588 ********************************************************************/
590 BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain)
592 if (!sampass)
593 return False;
595 if (domain) {
596 DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", domain,
597 (sampass->private.domain)?(sampass->private.domain):"NULL"));
599 sampass->private.domain = talloc_strdup(sampass->mem_ctx, domain);
601 if (!sampass->private.domain) {
602 DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
603 return False;
606 } else {
607 sampass->private.domain = PDB_NOT_QUITE_NULL;
610 return True;
613 /*********************************************************************
614 Set the user's NT name.
615 ********************************************************************/
617 BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username)
619 if (!sampass)
620 return False;
622 if (nt_username) {
623 DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", nt_username,
624 (sampass->private.nt_username)?(sampass->private.nt_username):"NULL"));
626 sampass->private.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
628 if (!sampass->private.nt_username) {
629 DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
630 return False;
633 } else {
634 sampass->private.nt_username = PDB_NOT_QUITE_NULL;
637 return True;
640 /*********************************************************************
641 Set the user's full name.
642 ********************************************************************/
644 BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name)
646 if (!sampass)
647 return False;
649 if (full_name) {
650 DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", full_name,
651 (sampass->private.full_name)?(sampass->private.full_name):"NULL"));
653 sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);
655 if (!sampass->private.full_name) {
656 DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
657 return False;
660 } else {
661 sampass->private.full_name = PDB_NOT_QUITE_NULL;
664 return True;
667 /*********************************************************************
668 Set the user's logon script.
669 ********************************************************************/
671 BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, BOOL store)
673 if (!sampass)
674 return False;
676 if (logon_script) {
677 DEBUG(10, ("pdb_set_logon_script: setting logon script %s, was %s\n", logon_script,
678 (sampass->private.logon_script)?(sampass->private.logon_script):"NULL"));
680 sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
682 if (!sampass->private.logon_script) {
683 DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
684 return False;
687 } else {
688 sampass->private.logon_script = PDB_NOT_QUITE_NULL;
691 if (store) {
692 DEBUG(10, ("pdb_set_logon_script: setting logon script sam flag!\n"));
693 pdb_set_init_flag(sampass, FLAG_SAM_LOGONSCRIPT);
696 return True;
699 /*********************************************************************
700 Set the user's profile path.
701 ********************************************************************/
703 BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, BOOL store)
705 if (!sampass)
706 return False;
708 if (profile_path) {
709 DEBUG(10, ("pdb_set_profile_path: setting profile path %s, was %s\n", profile_path,
710 (sampass->private.profile_path)?(sampass->private.profile_path):"NULL"));
712 sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
714 if (!sampass->private.profile_path) {
715 DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
716 return False;
719 } else {
720 sampass->private.profile_path = PDB_NOT_QUITE_NULL;
723 if (store) {
724 DEBUG(10, ("pdb_set_profile_path: setting profile path sam flag!\n"));
725 pdb_set_init_flag(sampass, FLAG_SAM_PROFILE);
728 return True;
731 /*********************************************************************
732 Set the user's directory drive.
733 ********************************************************************/
735 BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, BOOL store)
737 if (!sampass)
738 return False;
740 if (dir_drive) {
741 DEBUG(10, ("pdb_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
742 (sampass->private.dir_drive)?(sampass->private.dir_drive):"NULL"));
744 sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
746 if (!sampass->private.dir_drive) {
747 DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
748 return False;
751 } else {
752 sampass->private.dir_drive = PDB_NOT_QUITE_NULL;
755 if (store) {
756 DEBUG(10, ("pdb_set_dir_drive: setting dir drive sam flag!\n"));
757 pdb_set_init_flag(sampass, FLAG_SAM_DRIVE);
760 return True;
763 /*********************************************************************
764 Set the user's home directory.
765 ********************************************************************/
767 BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, BOOL store)
769 if (!sampass)
770 return False;
772 if (home_dir) {
773 DEBUG(10, ("pdb_set_homedir: setting home dir %s, was %s\n", home_dir,
774 (sampass->private.home_dir)?(sampass->private.home_dir):"NULL"));
776 sampass->private.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
778 if (!sampass->private.home_dir) {
779 DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
780 return False;
783 } else {
784 sampass->private.home_dir = PDB_NOT_QUITE_NULL;
787 if (store) {
788 DEBUG(10, ("pdb_set_homedir: setting home dir sam flag!\n"));
789 pdb_set_init_flag(sampass, FLAG_SAM_SMBHOME);
792 return True;
795 /*********************************************************************
796 Set the user's unix home directory.
797 ********************************************************************/
799 BOOL pdb_set_unix_homedir (SAM_ACCOUNT *sampass, const char *unix_home_dir)
801 if (!sampass)
802 return False;
804 if (unix_home_dir) {
805 DEBUG(10, ("pdb_set_unix_homedir: setting home dir %s, was %s\n", unix_home_dir,
806 (sampass->private.unix_home_dir)?(sampass->private.unix_home_dir):"NULL"));
808 sampass->private.unix_home_dir = talloc_strdup(sampass->mem_ctx,
809 unix_home_dir);
811 if (!sampass->private.unix_home_dir) {
812 DEBUG(0, ("pdb_set_unix_home_dir: talloc_strdup() failed!\n"));
813 return False;
816 } else {
817 sampass->private.unix_home_dir = PDB_NOT_QUITE_NULL;
820 return True;
823 /*********************************************************************
824 Set the user's account description.
825 ********************************************************************/
827 BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc)
829 if (!sampass)
830 return False;
832 if (acct_desc) {
833 sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
835 if (!sampass->private.acct_desc) {
836 DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
837 return False;
840 } else {
841 sampass->private.acct_desc = PDB_NOT_QUITE_NULL;
844 return True;
847 /*********************************************************************
848 Set the user's workstation allowed list.
849 ********************************************************************/
851 BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations)
853 if (!sampass)
854 return False;
856 if (workstations) {
857 DEBUG(10, ("pdb_set_workstations: setting workstations %s, was %s\n", workstations,
858 (sampass->private.workstations)?(sampass->private.workstations):"NULL"));
860 sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);
862 if (!sampass->private.workstations) {
863 DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
864 return False;
867 } else {
868 sampass->private.workstations = PDB_NOT_QUITE_NULL;
871 return True;
874 /*********************************************************************
875 Set the user's 'unknown_str', whatever the heck this actually is...
876 ********************************************************************/
878 BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str)
880 if (!sampass)
881 return False;
883 if (unknown_str) {
884 sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
886 if (!sampass->private.unknown_str) {
887 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
888 return False;
891 } else {
892 sampass->private.unknown_str = PDB_NOT_QUITE_NULL;
895 return True;
898 /*********************************************************************
899 Set the user's dial string.
900 ********************************************************************/
902 BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial)
904 if (!sampass)
905 return False;
907 if (munged_dial) {
908 sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
910 if (!sampass->private.munged_dial) {
911 DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
912 return False;
915 } else {
916 sampass->private.munged_dial = PDB_NOT_QUITE_NULL;
919 return True;
922 /*********************************************************************
923 Set the user's NT hash.
924 ********************************************************************/
926 BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
928 if (!sampass)
929 return False;
931 data_blob_clear_free(&sampass->private.nt_pw);
933 sampass->private.nt_pw = data_blob(pwd, NT_HASH_LEN);
935 return True;
938 /*********************************************************************
939 Set the user's LM hash.
940 ********************************************************************/
942 BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[16])
944 if (!sampass)
945 return False;
947 data_blob_clear_free(&sampass->private.lm_pw);
949 sampass->private.lm_pw = data_blob(pwd, LM_HASH_LEN);
951 return True;
954 /*********************************************************************
955 Set the user's plaintext password only (base procedure, see helper
956 below)
957 ********************************************************************/
959 BOOL pdb_set_plaintext_pw_only (SAM_ACCOUNT *sampass, const char *password)
961 if (!sampass)
962 return False;
964 if (password) {
965 if (sampass->private.plaintext_pw!=NULL)
966 memset(sampass->private.plaintext_pw,'\0',strlen(sampass->private.plaintext_pw)+1);
968 sampass->private.plaintext_pw = talloc_strdup(sampass->mem_ctx, password);
970 if (!sampass->private.plaintext_pw) {
971 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
972 return False;
975 } else {
976 sampass->private.plaintext_pw = NULL;
979 return True;
982 BOOL pdb_set_unknown_3 (SAM_ACCOUNT *sampass, uint32 unkn)
984 if (!sampass)
985 return False;
987 sampass->private.unknown_3 = unkn;
988 return True;
991 BOOL pdb_set_unknown_5 (SAM_ACCOUNT *sampass, uint32 unkn)
993 if (!sampass)
994 return False;
996 sampass->private.unknown_5 = unkn;
997 return True;
1000 BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn)
1002 if (!sampass)
1003 return False;
1005 sampass->private.unknown_6 = unkn;
1006 return True;
1009 BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours)
1011 if (!sampass)
1012 return False;
1014 if (!hours) {
1015 memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
1016 return True;
1019 memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);
1021 return True;
1025 /* Helpful interfaces to the above */
1027 /*********************************************************************
1028 Sets the last changed times and must change times for a normal
1029 password change.
1030 ********************************************************************/
1032 BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
1034 uint32 expire;
1036 if (!sampass)
1037 return False;
1039 if (!pdb_set_pass_last_set_time (sampass, time(NULL)))
1040 return False;
1042 if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
1043 || (expire==(uint32)-1)) {
1044 if (!pdb_set_pass_must_change_time (sampass, get_time_t_max(), False))
1045 return False;
1046 } else {
1047 if (!pdb_set_pass_must_change_time (sampass,
1048 pdb_get_pass_last_set_time(sampass)
1049 + expire, True))
1050 return False;
1053 return True;
1056 /*********************************************************************
1057 Set the user's PLAINTEXT password. Used as an interface to the above.
1058 Also sets the last change time to NOW.
1059 ********************************************************************/
1061 BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
1063 uchar new_lanman_p16[16];
1064 uchar new_nt_p16[16];
1066 if (!sampass || !plaintext)
1067 return False;
1069 nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);
1071 if (!pdb_set_nt_passwd (sampass, new_nt_p16))
1072 return False;
1074 if (!pdb_set_lanman_passwd (sampass, new_lanman_p16))
1075 return False;
1077 if (!pdb_set_plaintext_pw_only (sampass, plaintext))
1078 return False;
1080 if (!pdb_set_pass_changed_now (sampass))
1081 return False;
1083 return True;