2 Unix SMB/Netbios implementation.
4 SAM_ACCOUNT access routines
5 Copyright (C) Jeremy Allison 1996-2001
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
7 Copyright (C) Gerald (Jerry) Carter 2000-2001
8 Copyright (C) Andrew Bartlett 2001-2002
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * @todo Redefine this to NULL, but this changes the API becouse
29 * much of samba assumes that the pdb_get...() funtions
30 * return pstrings. (ie not null-pointers).
31 * See also pdb_fill_default_sam().
34 #define PDB_NOT_QUITE_NULL ""
36 /*********************************************************************
37 Collection of get...() functions for SAM_ACCOUNT_INFO.
38 ********************************************************************/
40 uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
43 return (sampass->private.acct_ctrl);
45 return (ACB_DISABLED);
48 time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
51 return (sampass->private.logon_time);
56 time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
59 return (sampass->private.logoff_time);
64 time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
67 return (sampass->private.kickoff_time);
72 time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
75 return (sampass->private.pass_last_set_time);
80 time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
83 return (sampass->private.pass_can_change_time);
88 time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
91 return (sampass->private.pass_must_change_time);
96 uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
99 return (sampass->private.logon_divs);
104 uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
107 return (sampass->private.hours_len);
112 const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
115 return (sampass->private.hours);
120 const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *sampass)
123 SMB_ASSERT((!sampass->private.nt_pw.data)
124 || sampass->private.nt_pw.length == NT_HASH_LEN);
125 return ((uint8*)sampass->private.nt_pw.data);
131 const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *sampass)
134 SMB_ASSERT((!sampass->private.lm_pw.data)
135 || sampass->private.lm_pw.length == LM_HASH_LEN);
136 return ((uint8*)sampass->private.lm_pw.data);
142 uint32 pdb_get_user_rid (const SAM_ACCOUNT *sampass)
145 return (sampass->private.user_rid);
150 uint32 pdb_get_group_rid (const SAM_ACCOUNT *sampass)
153 return (sampass->private.group_rid);
159 * Get flags showing what is initalised in the SAM_ACCOUNT
160 * @param sampass the SAM_ACCOUNT in question
161 * @return the flags indicating the members initialised in the struct.
164 uint32 pdb_get_init_flag (const SAM_ACCOUNT *sampass)
167 return sampass->private.init_flag;
169 return FLAG_SAM_UNINIT;
172 uid_t pdb_get_uid (const SAM_ACCOUNT *sampass)
175 return (sampass->private.uid);
180 gid_t pdb_get_gid (const SAM_ACCOUNT *sampass)
183 return (sampass->private.gid);
188 const char* pdb_get_username (const SAM_ACCOUNT *sampass)
191 return (sampass->private.username);
196 const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
199 return (sampass->private.domain);
204 const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
207 return (sampass->private.nt_username);
212 const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
215 return (sampass->private.full_name);
220 const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
223 return (sampass->private.home_dir);
228 const char* pdb_get_dirdrive (const SAM_ACCOUNT *sampass)
231 return (sampass->private.dir_drive);
236 const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
239 return (sampass->private.logon_script);
244 const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
247 return (sampass->private.profile_path);
252 const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
255 return (sampass->private.acct_desc);
260 const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
263 return (sampass->private.workstations);
268 const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
271 return (sampass->private.unknown_str);
276 const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
279 return (sampass->private.munged_dial);
284 uint32 pdb_get_unknown3 (const SAM_ACCOUNT *sampass)
287 return (sampass->private.unknown_3);
292 uint32 pdb_get_unknown5 (const SAM_ACCOUNT *sampass)
295 return (sampass->private.unknown_5);
300 uint32 pdb_get_unknown6 (const SAM_ACCOUNT *sampass)
303 return (sampass->private.unknown_6);
308 /*********************************************************************
309 Collection of set...() functions for SAM_ACCOUNT_INFO.
310 ********************************************************************/
312 BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
318 sampass->private.acct_ctrl = flags;
325 BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime)
330 sampass->private.logon_time = mytime;
334 BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime)
339 sampass->private.logoff_time = mytime;
343 BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime)
348 sampass->private.kickoff_time = mytime;
352 BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime)
357 sampass->private.pass_can_change_time = mytime;
361 BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime)
366 sampass->private.pass_must_change_time = mytime;
370 BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime)
375 sampass->private.pass_last_set_time = mytime;
379 BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len)
384 sampass->private.hours_len = len;
388 BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours)
393 sampass->private.logon_divs = hours;
398 * Set flags showing what is initalised in the SAM_ACCOUNT
399 * @param sampass the SAM_ACCOUNT in question
400 * @param flag The *new* flag to be set. Old flags preserved
401 * this flag is only added.
404 BOOL pdb_set_init_flag (SAM_ACCOUNT *sampass, uint32 flag)
409 sampass->private.init_flag |= flag;
414 BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t uid)
419 DEBUG(10, ("pdb_set_uid: setting uid %d, was %d\n",
420 (int)uid, (int)sampass->private.uid));
422 sampass->private.uid = uid;
423 pdb_set_init_flag(sampass, FLAG_SAM_UID);
429 BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid)
434 DEBUG(10, ("pdb_set_gid: setting gid %d, was %d\n",
435 (int)gid, (int)sampass->private.gid));
437 sampass->private.gid = gid;
438 pdb_set_init_flag(sampass, FLAG_SAM_GID);
444 BOOL pdb_set_user_rid (SAM_ACCOUNT *sampass, uint32 rid)
449 DEBUG(10, ("pdb_set_rid: setting user rid %d, was %d\n",
450 rid, sampass->private.user_rid));
452 sampass->private.user_rid = rid;
456 BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid)
461 DEBUG(10, ("pdb_set_group_rid: setting group rid %d, was %d\n",
462 grid, sampass->private.group_rid));
464 sampass->private.group_rid = grid;
468 /*********************************************************************
469 Set the user's UNIX name.
470 ********************************************************************/
472 BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username)
477 DEBUG(10, ("pdb_set_username: setting username %s, was %s\n",
478 username, sampass->private.username));
481 sampass->private.username = talloc_strdup(sampass->mem_ctx, username);
483 if (!sampass->private.username) {
484 DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
489 sampass->private.username = PDB_NOT_QUITE_NULL;
495 /*********************************************************************
497 ********************************************************************/
499 BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain)
504 DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n",
505 domain, sampass->private.domain));
508 sampass->private.domain = talloc_strdup(sampass->mem_ctx, domain);
510 if (!sampass->private.domain) {
511 DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
516 sampass->private.domain = PDB_NOT_QUITE_NULL;
522 /*********************************************************************
523 Set the user's NT name.
524 ********************************************************************/
526 BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username)
531 DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n",
532 nt_username, sampass->private.nt_username));
535 sampass->private.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
537 if (!sampass->private.nt_username) {
538 DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
543 sampass->private.nt_username = PDB_NOT_QUITE_NULL;
549 /*********************************************************************
550 Set the user's full name.
551 ********************************************************************/
553 BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name)
558 DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n",
559 full_name, sampass->private.full_name));
562 sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);
564 if (!sampass->private.full_name) {
565 DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
570 sampass->private.full_name = PDB_NOT_QUITE_NULL;
576 /*********************************************************************
577 Set the user's logon script.
578 ********************************************************************/
580 BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, BOOL store)
585 DEBUG(10, ("pdb_set_logon_script: setting logon script (store:%d) %s, was %s\n",
586 store, logon_script, sampass->private.logon_script));
589 sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
591 if (!sampass->private.logon_script) {
592 DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
597 sampass->private.logon_script = PDB_NOT_QUITE_NULL;
601 pdb_set_init_flag(sampass, FLAG_SAM_LOGONSCRIPT);
606 /*********************************************************************
607 Set the user's profile path.
608 ********************************************************************/
610 BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, BOOL store)
615 DEBUG(10, ("pdb_set_profile_path: setting profile path (store:%d) %s, was %s\n",
616 store, profile_path, sampass->private.profile_path));
619 sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
621 if (!sampass->private.profile_path) {
622 DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
627 sampass->private.profile_path = PDB_NOT_QUITE_NULL;
631 pdb_set_init_flag(sampass, FLAG_SAM_PROFILE);
636 /*********************************************************************
637 Set the user's directory drive.
638 ********************************************************************/
640 BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, BOOL store)
646 sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
648 if (!sampass->private.dir_drive) {
649 DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
654 sampass->private.dir_drive = PDB_NOT_QUITE_NULL;
658 pdb_set_init_flag(sampass, FLAG_SAM_DRIVE);
663 /*********************************************************************
664 Set the user's home directory.
665 ********************************************************************/
667 BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, BOOL store)
673 sampass->private.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
675 if (!sampass->private.home_dir) {
676 DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
681 sampass->private.home_dir = PDB_NOT_QUITE_NULL;
685 pdb_set_init_flag(sampass, FLAG_SAM_SMBHOME);
690 /*********************************************************************
691 Set the user's account description.
692 ********************************************************************/
694 BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc)
700 sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
702 if (!sampass->private.acct_desc) {
703 DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
708 sampass->private.acct_desc = PDB_NOT_QUITE_NULL;
714 /*********************************************************************
715 Set the user's workstation allowed list.
716 ********************************************************************/
718 BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations)
724 sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);
726 if (!sampass->private.workstations) {
727 DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
732 sampass->private.workstations = PDB_NOT_QUITE_NULL;
738 /*********************************************************************
739 Set the user's 'unknown_str', whatever the heck this actually is...
740 ********************************************************************/
742 BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str)
748 sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
750 if (!sampass->private.unknown_str) {
751 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
756 sampass->private.unknown_str = PDB_NOT_QUITE_NULL;
762 /*********************************************************************
763 Set the user's dial string.
764 ********************************************************************/
766 BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial)
771 sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
773 if (!sampass->private.munged_dial) {
774 DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
779 sampass->private.munged_dial = PDB_NOT_QUITE_NULL;
785 /*********************************************************************
786 Set the user's NT hash.
787 ********************************************************************/
789 BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
794 data_blob_clear_free(&sampass->private.nt_pw);
796 sampass->private.nt_pw = data_blob(pwd, NT_HASH_LEN);
801 /*********************************************************************
802 Set the user's LM hash.
803 ********************************************************************/
805 BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
810 data_blob_clear_free(&sampass->private.lm_pw);
812 sampass->private.lm_pw = data_blob(pwd, LM_HASH_LEN);
817 BOOL pdb_set_unknown_3 (SAM_ACCOUNT *sampass, uint32 unkn)
822 sampass->private.unknown_3 = unkn;
826 BOOL pdb_set_unknown_5 (SAM_ACCOUNT *sampass, uint32 unkn)
831 sampass->private.unknown_5 = unkn;
835 BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn)
840 sampass->private.unknown_6 = unkn;
844 BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours)
850 memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
854 memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);
860 /* Helpful interfaces to the above */
862 /*********************************************************************
863 Sets the last changed times and must change times for a normal
865 ********************************************************************/
867 BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
874 if (!pdb_set_pass_last_set_time (sampass, time(NULL)))
877 account_policy_get(AP_MAX_PASSWORD_AGE, &expire);
879 if (expire==(uint32)-1) {
880 if (!pdb_set_pass_must_change_time (sampass, 0))
883 if (!pdb_set_pass_must_change_time (sampass,
884 pdb_get_pass_last_set_time(sampass)
892 /*********************************************************************
893 Set the user's PLAINTEXT password. Used as an interface to the above.
894 Also sets the last change time to NOW.
895 ********************************************************************/
897 BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
899 uchar new_lanman_p16[16];
900 uchar new_nt_p16[16];
902 if (!sampass || !plaintext)
905 nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);
907 if (!pdb_set_nt_passwd (sampass, new_nt_p16))
910 if (!pdb_set_lanman_passwd (sampass, new_lanman_p16))
913 if (!pdb_set_pass_changed_now (sampass))