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.
28 #define DBGC_CLASS DBGC_PASSDB
31 * @todo Redefine this to NULL, but this changes the API because
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.
41 ********************************************************************/
43 uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
46 return (sampass->private.acct_ctrl);
48 return (ACB_DISABLED);
51 time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
54 return (sampass->private.logon_time);
59 time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
62 return (sampass->private.logoff_time);
67 time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
70 return (sampass->private.kickoff_time);
75 time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
78 return (sampass->private.pass_last_set_time);
83 time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
86 return (sampass->private.pass_can_change_time);
91 time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
94 return (sampass->private.pass_must_change_time);
99 uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
102 return (sampass->private.logon_divs);
107 uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
110 return (sampass->private.hours_len);
115 const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
118 return (sampass->private.hours);
123 const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *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);
134 const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *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);
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)
154 return (sampass->private.plaintext_pw);
159 const DOM_SID *pdb_get_user_sid(const SAM_ACCOUNT *sampass)
162 return &sampass->private.user_sid;
167 const DOM_SID *pdb_get_group_sid(const SAM_ACCOUNT *sampass)
170 return &sampass->private.group_sid;
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 enum pdb_value_state pdb_get_init_flags (const SAM_ACCOUNT *sampass, enum pdb_elements element)
183 enum pdb_value_state ret = PDB_DEFAULT;
185 if (!sampass || !sampass->private.change_flags || !sampass->private.set_flags)
188 if (bitmap_query(sampass->private.set_flags, element)) {
189 DEBUG(11, ("element %d: SET\n", element));
193 if (bitmap_query(sampass->private.change_flags, element)) {
194 DEBUG(11, ("element %d: CHANGED\n", element));
198 if (ret == PDB_DEFAULT) {
199 DEBUG(11, ("element %d: DEFAULT\n", element));
205 const char* pdb_get_username (const SAM_ACCOUNT *sampass)
208 return (sampass->private.username);
213 const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
216 return (sampass->private.domain);
221 const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
224 return (sampass->private.nt_username);
229 const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
232 return (sampass->private.full_name);
237 const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
240 return (sampass->private.home_dir);
245 const char* pdb_get_unix_homedir (const SAM_ACCOUNT *sampass)
248 return (sampass->private.unix_home_dir);
253 const char* pdb_get_dir_drive (const SAM_ACCOUNT *sampass)
256 return (sampass->private.dir_drive);
261 const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
264 return (sampass->private.logon_script);
269 const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
272 return (sampass->private.profile_path);
277 const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
280 return (sampass->private.acct_desc);
285 const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
288 return (sampass->private.workstations);
293 const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
296 return (sampass->private.unknown_str);
301 const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
304 return (sampass->private.munged_dial);
309 uint16 pdb_get_bad_password_count(const SAM_ACCOUNT *sampass)
312 return (sampass->private.bad_password_count);
317 uint16 pdb_get_logon_count(const SAM_ACCOUNT *sampass)
320 return (sampass->private.logon_count);
325 uint32 pdb_get_unknown_6 (const SAM_ACCOUNT *sampass)
328 return (sampass->private.unknown_6);
333 void *pdb_get_backend_private_data (const SAM_ACCOUNT *sampass, const struct pdb_methods *my_methods)
335 if (sampass && my_methods == sampass->private.backend_private_methods)
336 return sampass->private.backend_private_data;
341 /*********************************************************************
342 Collection of set...() functions for SAM_ACCOUNT.
343 ********************************************************************/
345 BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 acct_ctrl, enum pdb_value_state flag)
350 sampass->private.acct_ctrl = acct_ctrl;
352 return pdb_set_init_flags(sampass, PDB_ACCTCTRL, flag);
355 BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
360 sampass->private.logon_time = mytime;
362 return pdb_set_init_flags(sampass, PDB_LOGONTIME, flag);
365 BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
370 sampass->private.logoff_time = mytime;
372 return pdb_set_init_flags(sampass, PDB_LOGOFFTIME, flag);
375 BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
380 sampass->private.kickoff_time = mytime;
382 return pdb_set_init_flags(sampass, PDB_KICKOFFTIME, flag);
385 BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
390 sampass->private.pass_can_change_time = mytime;
392 return pdb_set_init_flags(sampass, PDB_CANCHANGETIME, flag);
395 BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
400 sampass->private.pass_must_change_time = mytime;
402 return pdb_set_init_flags(sampass, PDB_MUSTCHANGETIME, flag);
405 BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime, enum pdb_value_state flag)
410 sampass->private.pass_last_set_time = mytime;
412 return pdb_set_init_flags(sampass, PDB_PASSLASTSET, flag);
415 BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len, enum pdb_value_state flag)
420 sampass->private.hours_len = len;
422 return pdb_set_init_flags(sampass, PDB_HOURSLEN, flag);
425 BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours, enum pdb_value_state flag)
430 sampass->private.logon_divs = hours;
432 return pdb_set_init_flags(sampass, PDB_LOGONDIVS, flag);
436 * Set flags showing what is initalised in the SAM_ACCOUNT
437 * @param sampass the SAM_ACCOUNT in question
438 * @param flag The *new* flag to be set. Old flags preserved
439 * this flag is only added.
442 BOOL pdb_set_init_flags (SAM_ACCOUNT *sampass, enum pdb_elements element, enum pdb_value_state value_flag)
444 if (!sampass || !sampass->mem_ctx)
447 if (!sampass->private.set_flags) {
448 if ((sampass->private.set_flags =
449 bitmap_talloc(sampass->mem_ctx,
451 DEBUG(0,("bitmap_talloc failed\n"));
455 if (!sampass->private.change_flags) {
456 if ((sampass->private.change_flags =
457 bitmap_talloc(sampass->mem_ctx,
459 DEBUG(0,("bitmap_talloc failed\n"));
466 if (!bitmap_set(sampass->private.change_flags, element)) {
467 DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
470 if (!bitmap_set(sampass->private.set_flags, element)) {
471 DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
474 DEBUG(11, ("element %d -> now CHANGED\n", element));
477 if (!bitmap_clear(sampass->private.change_flags, element)) {
478 DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
481 if (!bitmap_set(sampass->private.set_flags, element)) {
482 DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
485 DEBUG(10, ("element %d -> now SET\n", element));
489 if (!bitmap_clear(sampass->private.change_flags, element)) {
490 DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
493 if (!bitmap_clear(sampass->private.set_flags, element)) {
494 DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
497 DEBUG(11, ("element %d -> now DEFAULT\n", element));
504 BOOL pdb_set_user_sid (SAM_ACCOUNT *sampass, const DOM_SID *u_sid, enum pdb_value_state flag)
506 if (!sampass || !u_sid)
509 sid_copy(&sampass->private.user_sid, u_sid);
511 DEBUG(10, ("pdb_set_user_sid: setting user sid %s\n",
512 sid_string_static(&sampass->private.user_sid)));
514 return pdb_set_init_flags(sampass, PDB_USERSID, flag);
517 BOOL pdb_set_user_sid_from_string (SAM_ACCOUNT *sampass, fstring u_sid, enum pdb_value_state flag)
521 if (!sampass || !u_sid)
524 DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
527 if (!string_to_sid(&new_sid, u_sid)) {
528 DEBUG(1, ("pdb_set_user_sid_from_string: %s isn't a valid SID!\n", u_sid));
532 if (!pdb_set_user_sid(sampass, &new_sid, flag)) {
533 DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", u_sid));
540 BOOL pdb_set_group_sid (SAM_ACCOUNT *sampass, const DOM_SID *g_sid, enum pdb_value_state flag)
542 if (!sampass || !g_sid)
545 sid_copy(&sampass->private.group_sid, g_sid);
547 DEBUG(10, ("pdb_set_group_sid: setting group sid %s\n",
548 sid_string_static(&sampass->private.group_sid)));
550 return pdb_set_init_flags(sampass, PDB_GROUPSID, flag);
553 BOOL pdb_set_group_sid_from_string (SAM_ACCOUNT *sampass, fstring g_sid, enum pdb_value_state flag)
556 if (!sampass || !g_sid)
559 DEBUG(10, ("pdb_set_group_sid_from_string: setting group sid %s\n",
562 if (!string_to_sid(&new_sid, g_sid)) {
563 DEBUG(1, ("pdb_set_group_sid_from_string: %s isn't a valid SID!\n", g_sid));
567 if (!pdb_set_group_sid(sampass, &new_sid, flag)) {
568 DEBUG(1, ("pdb_set_group_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", g_sid));
574 /*********************************************************************
575 Set the user's UNIX name.
576 ********************************************************************/
578 BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username, enum pdb_value_state flag)
584 DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", username,
585 (sampass->private.username)?(sampass->private.username):"NULL"));
587 sampass->private.username = talloc_strdup(sampass->mem_ctx, username);
589 if (!sampass->private.username) {
590 DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
595 sampass->private.username = PDB_NOT_QUITE_NULL;
598 return pdb_set_init_flags(sampass, PDB_USERNAME, flag);
601 /*********************************************************************
603 ********************************************************************/
605 BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain, enum pdb_value_state flag)
611 DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", domain,
612 (sampass->private.domain)?(sampass->private.domain):"NULL"));
614 sampass->private.domain = talloc_strdup(sampass->mem_ctx, domain);
616 if (!sampass->private.domain) {
617 DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
622 sampass->private.domain = PDB_NOT_QUITE_NULL;
625 return pdb_set_init_flags(sampass, PDB_DOMAIN, flag);
628 /*********************************************************************
629 Set the user's NT name.
630 ********************************************************************/
632 BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username, enum pdb_value_state flag)
638 DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", nt_username,
639 (sampass->private.nt_username)?(sampass->private.nt_username):"NULL"));
641 sampass->private.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
643 if (!sampass->private.nt_username) {
644 DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
649 sampass->private.nt_username = PDB_NOT_QUITE_NULL;
652 return pdb_set_init_flags(sampass, PDB_NTUSERNAME, flag);
655 /*********************************************************************
656 Set the user's full name.
657 ********************************************************************/
659 BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name, enum pdb_value_state flag)
665 DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", full_name,
666 (sampass->private.full_name)?(sampass->private.full_name):"NULL"));
668 sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);
670 if (!sampass->private.full_name) {
671 DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
676 sampass->private.full_name = PDB_NOT_QUITE_NULL;
679 return pdb_set_init_flags(sampass, PDB_FULLNAME, flag);
682 /*********************************************************************
683 Set the user's logon script.
684 ********************************************************************/
686 BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, enum pdb_value_state flag)
692 DEBUG(10, ("pdb_set_logon_script: setting logon script %s, was %s\n", logon_script,
693 (sampass->private.logon_script)?(sampass->private.logon_script):"NULL"));
695 sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
697 if (!sampass->private.logon_script) {
698 DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
703 sampass->private.logon_script = PDB_NOT_QUITE_NULL;
706 return pdb_set_init_flags(sampass, PDB_LOGONSCRIPT, flag);
709 /*********************************************************************
710 Set the user's profile path.
711 ********************************************************************/
713 BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, enum pdb_value_state flag)
719 DEBUG(10, ("pdb_set_profile_path: setting profile path %s, was %s\n", profile_path,
720 (sampass->private.profile_path)?(sampass->private.profile_path):"NULL"));
722 sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
724 if (!sampass->private.profile_path) {
725 DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
730 sampass->private.profile_path = PDB_NOT_QUITE_NULL;
733 return pdb_set_init_flags(sampass, PDB_PROFILE, flag);
736 /*********************************************************************
737 Set the user's directory drive.
738 ********************************************************************/
740 BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, enum pdb_value_state flag)
746 DEBUG(10, ("pdb_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
747 (sampass->private.dir_drive)?(sampass->private.dir_drive):"NULL"));
749 sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
751 if (!sampass->private.dir_drive) {
752 DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
757 sampass->private.dir_drive = PDB_NOT_QUITE_NULL;
760 return pdb_set_init_flags(sampass, PDB_DRIVE, flag);
763 /*********************************************************************
764 Set the user's home directory.
765 ********************************************************************/
767 BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, enum pdb_value_state flag)
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"));
784 sampass->private.home_dir = PDB_NOT_QUITE_NULL;
787 return pdb_set_init_flags(sampass, PDB_SMBHOME, flag);
790 /*********************************************************************
791 Set the user's unix home directory.
792 ********************************************************************/
794 BOOL pdb_set_unix_homedir (SAM_ACCOUNT *sampass, const char *unix_home_dir, enum pdb_value_state flag)
800 DEBUG(10, ("pdb_set_unix_homedir: setting home dir %s, was %s\n", unix_home_dir,
801 (sampass->private.unix_home_dir)?(sampass->private.unix_home_dir):"NULL"));
803 sampass->private.unix_home_dir = talloc_strdup(sampass->mem_ctx,
806 if (!sampass->private.unix_home_dir) {
807 DEBUG(0, ("pdb_set_unix_home_dir: talloc_strdup() failed!\n"));
812 sampass->private.unix_home_dir = PDB_NOT_QUITE_NULL;
815 return pdb_set_init_flags(sampass, PDB_UNIXHOMEDIR, flag);
818 /*********************************************************************
819 Set the user's account description.
820 ********************************************************************/
822 BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc, enum pdb_value_state flag)
828 sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
830 if (!sampass->private.acct_desc) {
831 DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
836 sampass->private.acct_desc = PDB_NOT_QUITE_NULL;
839 return pdb_set_init_flags(sampass, PDB_ACCTDESC, flag);
842 /*********************************************************************
843 Set the user's workstation allowed list.
844 ********************************************************************/
846 BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations, enum pdb_value_state flag)
852 DEBUG(10, ("pdb_set_workstations: setting workstations %s, was %s\n", workstations,
853 (sampass->private.workstations)?(sampass->private.workstations):"NULL"));
855 sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);
857 if (!sampass->private.workstations) {
858 DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
863 sampass->private.workstations = PDB_NOT_QUITE_NULL;
866 return pdb_set_init_flags(sampass, PDB_WORKSTATIONS, flag);
869 /*********************************************************************
870 Set the user's 'unknown_str', whatever the heck this actually is...
871 ********************************************************************/
873 BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str, enum pdb_value_state flag)
879 sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
881 if (!sampass->private.unknown_str) {
882 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
887 sampass->private.unknown_str = PDB_NOT_QUITE_NULL;
890 return pdb_set_init_flags(sampass, PDB_UNKNOWNSTR, flag);
893 /*********************************************************************
894 Set the user's dial string.
895 ********************************************************************/
897 BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial, enum pdb_value_state flag)
903 sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
905 if (!sampass->private.munged_dial) {
906 DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
911 sampass->private.munged_dial = PDB_NOT_QUITE_NULL;
914 return pdb_set_init_flags(sampass, PDB_MUNGEDDIAL, flag);
917 /*********************************************************************
918 Set the user's NT hash.
919 ********************************************************************/
921 BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[NT_HASH_LEN], enum pdb_value_state flag)
926 data_blob_clear_free(&sampass->private.nt_pw);
929 sampass->private.nt_pw = data_blob(pwd, NT_HASH_LEN);
931 sampass->private.nt_pw = data_blob(NULL, 0);
934 return pdb_set_init_flags(sampass, PDB_NTPASSWD, flag);
937 /*********************************************************************
938 Set the user's LM hash.
939 ********************************************************************/
941 BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[LM_HASH_LEN], enum pdb_value_state flag)
946 data_blob_clear_free(&sampass->private.lm_pw);
949 sampass->private.lm_pw = data_blob(pwd, LM_HASH_LEN);
951 sampass->private.lm_pw = data_blob(NULL, 0);
954 return pdb_set_init_flags(sampass, PDB_LMPASSWD, flag);
957 /*********************************************************************
958 Set the user's plaintext password only (base procedure, see helper
960 ********************************************************************/
962 BOOL pdb_set_plaintext_pw_only (SAM_ACCOUNT *sampass, const char *password, enum pdb_value_state flag)
968 if (sampass->private.plaintext_pw!=NULL)
969 memset(sampass->private.plaintext_pw,'\0',strlen(sampass->private.plaintext_pw)+1);
971 sampass->private.plaintext_pw = talloc_strdup(sampass->mem_ctx, password);
973 if (!sampass->private.plaintext_pw) {
974 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
979 sampass->private.plaintext_pw = NULL;
982 return pdb_set_init_flags(sampass, PDB_PLAINTEXT_PW, flag);
985 BOOL pdb_set_bad_password_count(SAM_ACCOUNT *sampass, uint16 bad_password_count, enum pdb_value_state flag)
990 sampass->private.bad_password_count = bad_password_count;
992 return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_COUNT, flag);
995 BOOL pdb_set_logon_count(SAM_ACCOUNT *sampass, uint16 logon_count, enum pdb_value_state flag)
1000 sampass->private.logon_count = logon_count;
1002 return pdb_set_init_flags(sampass, PDB_LOGON_COUNT, flag);
1005 BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn, enum pdb_value_state flag)
1010 sampass->private.unknown_6 = unkn;
1012 return pdb_set_init_flags(sampass, PDB_UNKNOWN6, flag);
1015 BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours, enum pdb_value_state flag)
1021 memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
1025 memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);
1027 return pdb_set_init_flags(sampass, PDB_HOURS, flag);
1030 BOOL pdb_set_backend_private_data (SAM_ACCOUNT *sampass, void *private_data,
1031 void (*free_fn)(void **),
1032 const struct pdb_methods *my_methods,
1033 enum pdb_value_state flag)
1038 if (sampass->private.backend_private_data && sampass->private.backend_private_data_free_fn) {
1039 sampass->private.backend_private_data_free_fn(&sampass->private.backend_private_data);
1042 sampass->private.backend_private_data = private_data;
1043 sampass->private.backend_private_data_free_fn = free_fn;
1044 sampass->private.backend_private_methods = my_methods;
1046 return pdb_set_init_flags(sampass, PDB_BACKEND_PRIVATE_DATA, flag);
1050 /* Helpful interfaces to the above */
1052 /*********************************************************************
1053 Sets the last changed times and must change times for a normal
1055 ********************************************************************/
1057 BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
1065 if (!pdb_set_pass_last_set_time (sampass, time(NULL), PDB_CHANGED))
1068 if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
1069 || (expire==(uint32)-1)) {
1070 if (!pdb_set_pass_must_change_time (sampass, get_time_t_max(), PDB_CHANGED))
1073 if (!pdb_set_pass_must_change_time (sampass,
1074 pdb_get_pass_last_set_time(sampass)
1075 + expire, PDB_CHANGED))
1079 if (!account_policy_get(AP_MIN_PASSWORD_AGE, &min_age)
1080 || (min_age==(uint32)-1)) {
1081 if (!pdb_set_pass_can_change_time (sampass, 0, PDB_CHANGED))
1084 if (!pdb_set_pass_can_change_time (sampass,
1085 pdb_get_pass_last_set_time(sampass)
1086 + min_age, PDB_CHANGED))
1092 /*********************************************************************
1093 Set the user's PLAINTEXT password. Used as an interface to the above.
1094 Also sets the last change time to NOW.
1095 ********************************************************************/
1097 BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
1099 uchar new_lanman_p16[16];
1100 uchar new_nt_p16[16];
1102 if (!sampass || !plaintext)
1105 nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);
1107 if (!pdb_set_nt_passwd (sampass, new_nt_p16, PDB_CHANGED))
1110 if (!pdb_set_lanman_passwd (sampass, new_lanman_p16, PDB_CHANGED))
1113 if (!pdb_set_plaintext_pw_only (sampass, plaintext, PDB_CHANGED))
1116 if (!pdb_set_pass_changed_now (sampass))
1122 /* check for any PDB_SET/CHANGED field and fill the appropriate mask bit */
1123 uint32 pdb_build_fields_present (SAM_ACCOUNT *sampass)
1125 /* value set to all for testing */