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
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.
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.
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.
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().
33 #define PDB_NOT_QUITE_NULL ""
35 /*********************************************************************
36 Collection of get...() functions for SAM_ACCOUNT_INFO.
37 ********************************************************************/
39 uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
42 return (sampass->private.acct_ctrl);
44 return (ACB_DISABLED);
47 time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
50 return (sampass->private.logon_time);
55 time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
58 return (sampass->private.logoff_time);
63 time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
66 return (sampass->private.kickoff_time);
71 time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
74 return (sampass->private.pass_last_set_time);
79 time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
82 return (sampass->private.pass_can_change_time);
87 time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
90 return (sampass->private.pass_must_change_time);
95 uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
98 return (sampass->private.logon_divs);
103 uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
106 return (sampass->private.hours_len);
111 const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
114 return (sampass->private.hours);
119 const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *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);
130 const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *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);
141 uint32 pdb_get_user_rid (const SAM_ACCOUNT *sampass)
144 return (sampass->private.user_rid);
149 uint32 pdb_get_group_rid (const SAM_ACCOUNT *sampass)
152 return (sampass->private.group_rid);
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.
163 uint32 pdb_get_init_flag (const SAM_ACCOUNT *sampass)
166 return sampass->private.init_flag;
168 return FLAG_SAM_UNINIT;
171 uid_t pdb_get_uid (const SAM_ACCOUNT *sampass)
174 return (sampass->private.uid);
179 gid_t pdb_get_gid (const SAM_ACCOUNT *sampass)
182 return (sampass->private.gid);
187 const char* pdb_get_username (const SAM_ACCOUNT *sampass)
190 return (sampass->private.username);
195 const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
198 return (sampass->private.domain);
203 const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
206 return (sampass->private.nt_username);
211 const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
214 return (sampass->private.full_name);
219 const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
222 return (sampass->private.home_dir);
227 const char* pdb_get_dirdrive (const SAM_ACCOUNT *sampass)
230 return (sampass->private.dir_drive);
235 const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
238 return (sampass->private.logon_script);
243 const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
246 return (sampass->private.profile_path);
251 const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
254 return (sampass->private.acct_desc);
259 const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
262 return (sampass->private.workstations);
267 const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
270 return (sampass->private.unknown_str);
275 const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
278 return (sampass->private.munged_dial);
283 uint32 pdb_get_unknown3 (const SAM_ACCOUNT *sampass)
286 return (sampass->private.unknown_3);
291 uint32 pdb_get_unknown5 (const SAM_ACCOUNT *sampass)
294 return (sampass->private.unknown_5);
299 uint32 pdb_get_unknown6 (const SAM_ACCOUNT *sampass)
302 return (sampass->private.unknown_6);
307 /*********************************************************************
308 Collection of set...() functions for SAM_ACCOUNT_INFO.
309 ********************************************************************/
311 BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
317 sampass->private.acct_ctrl = flags;
324 BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime)
329 sampass->private.logon_time = mytime;
333 BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime)
338 sampass->private.logoff_time = mytime;
342 BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime)
347 sampass->private.kickoff_time = mytime;
351 BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime)
356 sampass->private.pass_can_change_time = mytime;
360 BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime)
365 sampass->private.pass_must_change_time = mytime;
369 BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime)
374 sampass->private.pass_last_set_time = mytime;
378 BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len)
383 sampass->private.hours_len = len;
387 BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours)
392 sampass->private.logon_divs = hours;
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.
403 BOOL pdb_set_init_flag (SAM_ACCOUNT *sampass, uint32 flag)
408 sampass->private.init_flag |= flag;
413 BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t uid)
418 DEBUG(10, ("pdb_set_uid: setting uid %d, was %d\n",
419 (int)uid, (int)sampass->private.uid));
421 sampass->private.uid = uid;
422 pdb_set_init_flag(sampass, FLAG_SAM_UID);
428 BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid)
433 DEBUG(10, ("pdb_set_gid: setting gid %d, was %d\n",
434 (int)gid, (int)sampass->private.gid));
436 sampass->private.gid = gid;
437 pdb_set_init_flag(sampass, FLAG_SAM_GID);
443 BOOL pdb_set_user_rid (SAM_ACCOUNT *sampass, uint32 rid)
448 DEBUG(10, ("pdb_set_rid: setting user rid %d, was %d\n",
449 rid, sampass->private.user_rid));
451 sampass->private.user_rid = rid;
455 BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid)
460 DEBUG(10, ("pdb_set_group_rid: setting group rid %d, was %d\n",
461 grid, sampass->private.group_rid));
463 sampass->private.group_rid = grid;
467 /*********************************************************************
468 Set the user's UNIX name.
469 ********************************************************************/
471 BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username)
476 DEBUG(10, ("pdb_set_username: setting username %s, was %s\n",
477 username, sampass->private.username));
480 sampass->private.username = talloc_strdup(sampass->mem_ctx, username);
482 if (!sampass->private.username) {
483 DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
488 sampass->private.username = PDB_NOT_QUITE_NULL;
494 /*********************************************************************
496 ********************************************************************/
498 BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain)
503 DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n",
504 domain, sampass->private.domain));
507 sampass->private.domain = talloc_strdup(sampass->mem_ctx, domain);
509 if (!sampass->private.domain) {
510 DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
515 sampass->private.domain = PDB_NOT_QUITE_NULL;
521 /*********************************************************************
522 Set the user's NT name.
523 ********************************************************************/
525 BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username)
530 DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n",
531 nt_username, sampass->private.nt_username));
534 sampass->private.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
536 if (!sampass->private.nt_username) {
537 DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
542 sampass->private.nt_username = PDB_NOT_QUITE_NULL;
548 /*********************************************************************
549 Set the user's full name.
550 ********************************************************************/
552 BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name)
557 DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n",
558 full_name, sampass->private.full_name));
561 sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);
563 if (!sampass->private.full_name) {
564 DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
569 sampass->private.full_name = PDB_NOT_QUITE_NULL;
575 /*********************************************************************
576 Set the user's logon script.
577 ********************************************************************/
579 BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, BOOL store)
584 DEBUG(10, ("pdb_set_logon_script: setting logon script (store:%d) %s, was %s\n",
585 store, logon_script, sampass->private.logon_script));
588 sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
590 if (!sampass->private.logon_script) {
591 DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
596 sampass->private.logon_script = PDB_NOT_QUITE_NULL;
600 pdb_set_init_flag(sampass, FLAG_SAM_LOGONSCRIPT);
605 /*********************************************************************
606 Set the user's profile path.
607 ********************************************************************/
609 BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, BOOL store)
614 DEBUG(10, ("pdb_set_profile_path: setting profile path (store:%d) %s, was %s\n",
615 store, profile_path, sampass->private.profile_path));
618 sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
620 if (!sampass->private.profile_path) {
621 DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
626 sampass->private.profile_path = PDB_NOT_QUITE_NULL;
630 pdb_set_init_flag(sampass, FLAG_SAM_PROFILE);
635 /*********************************************************************
636 Set the user's directory drive.
637 ********************************************************************/
639 BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, BOOL store)
645 sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
647 if (!sampass->private.dir_drive) {
648 DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
653 sampass->private.dir_drive = PDB_NOT_QUITE_NULL;
657 pdb_set_init_flag(sampass, FLAG_SAM_DRIVE);
662 /*********************************************************************
663 Set the user's home directory.
664 ********************************************************************/
666 BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, BOOL store)
672 sampass->private.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
674 if (!sampass->private.home_dir) {
675 DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
680 sampass->private.home_dir = PDB_NOT_QUITE_NULL;
684 pdb_set_init_flag(sampass, FLAG_SAM_SMBHOME);
689 /*********************************************************************
690 Set the user's account description.
691 ********************************************************************/
693 BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc)
699 sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
701 if (!sampass->private.acct_desc) {
702 DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
707 sampass->private.acct_desc = PDB_NOT_QUITE_NULL;
713 /*********************************************************************
714 Set the user's workstation allowed list.
715 ********************************************************************/
717 BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations)
723 sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);
725 if (!sampass->private.workstations) {
726 DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
731 sampass->private.workstations = PDB_NOT_QUITE_NULL;
737 /*********************************************************************
738 Set the user's 'unknown_str', whatever the heck this actually is...
739 ********************************************************************/
741 BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str)
747 sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
749 if (!sampass->private.unknown_str) {
750 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
755 sampass->private.unknown_str = PDB_NOT_QUITE_NULL;
761 /*********************************************************************
762 Set the user's dial string.
763 ********************************************************************/
765 BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial)
770 sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
772 if (!sampass->private.munged_dial) {
773 DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
778 sampass->private.munged_dial = PDB_NOT_QUITE_NULL;
784 /*********************************************************************
785 Set the user's NT hash.
786 ********************************************************************/
788 BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
793 data_blob_clear_free(&sampass->private.nt_pw);
795 sampass->private.nt_pw = data_blob(pwd, NT_HASH_LEN);
800 /*********************************************************************
801 Set the user's LM hash.
802 ********************************************************************/
804 BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
809 data_blob_clear_free(&sampass->private.lm_pw);
811 sampass->private.lm_pw = data_blob(pwd, LM_HASH_LEN);
816 BOOL pdb_set_unknown_3 (SAM_ACCOUNT *sampass, uint32 unkn)
821 sampass->private.unknown_3 = unkn;
825 BOOL pdb_set_unknown_5 (SAM_ACCOUNT *sampass, uint32 unkn)
830 sampass->private.unknown_5 = unkn;
834 BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn)
839 sampass->private.unknown_6 = unkn;
843 BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours)
849 memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
853 memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);
859 /* Helpful interfaces to the above */
861 /*********************************************************************
862 Sets the last changed times and must change times for a normal
864 ********************************************************************/
866 BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
873 if (!pdb_set_pass_last_set_time (sampass, time(NULL)))
876 account_policy_get(AP_MAX_PASSWORD_AGE, &expire);
878 if (expire==(uint32)-1) {
879 if (!pdb_set_pass_must_change_time (sampass, 0))
882 if (!pdb_set_pass_must_change_time (sampass,
883 pdb_get_pass_last_set_time(sampass)
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 ********************************************************************/
896 BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
898 uchar new_lanman_p16[16];
899 uchar new_nt_p16[16];
901 if (!sampass || !plaintext)
904 nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);
906 if (!pdb_set_nt_passwd (sampass, new_nt_p16))
909 if (!pdb_set_lanman_passwd (sampass, new_lanman_p16))
912 if (!pdb_set_pass_changed_now (sampass))