2 Unix SMB/CIFS implementation.
3 Password and authentication handling
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) Simo Sorce 2003
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
30 /******************************************************************
31 get the default domain/netbios name to be used when
32 testing authentication. For example, if you connect
33 to a Windows member server using a bogus domain name, the
34 Windows box will map the BOGUS\user to DOMAIN\user. A
35 standalone box will map to WKS\user.
36 ******************************************************************/
38 const char *get_default_sam_name(void)
40 /* standalone servers can only use the local netbios name */
41 if ( lp_server_role() == ROLE_STANDALONE )
42 return global_myname();
44 /* Windows domain members default to the DOMAIN
45 name when not specified */
46 return lp_workgroup();
49 /******************************************************************
50 get the default domain/netbios name to be used when dealing
51 with our passdb list of accounts
52 ******************************************************************/
54 const char *get_global_sam_name(void)
56 if ((lp_server_role() == ROLE_DOMAIN_PDC) || (lp_server_role() == ROLE_DOMAIN_BDC)) {
57 return lp_workgroup();
59 return global_myname();
62 /************************************************************
63 Fill the SAM_ACCOUNT with default values.
64 ***********************************************************/
66 void pdb_fill_default_sam(SAM_ACCOUNT *user)
68 ZERO_STRUCT(user->private); /* Don't touch the talloc context */
70 /* no initial methods */
73 /* Don't change these timestamp settings without a good reason.
74 They are important for NT member server compatibility. */
76 user->private.logon_time = (time_t)0;
77 user->private.pass_last_set_time = (time_t)0;
78 user->private.pass_can_change_time = (time_t)0;
79 user->private.logoff_time =
80 user->private.kickoff_time =
81 user->private.pass_must_change_time = get_time_t_max();
82 user->private.unknown_3 = 0x00ffffff; /* don't know */
83 user->private.logon_divs = 168; /* hours per week */
84 user->private.hours_len = 21; /* 21 times 8 bits = 168 */
85 memset(user->private.hours, 0xff, user->private.hours_len); /* available at all hours */
86 user->private.unknown_5 = 0x00000000; /* don't know */
87 user->private.unknown_6 = 0x000004ec; /* don't know */
89 /* Some parts of samba strlen their pdb_get...() returns,
90 so this keeps the interface unchanged for now. */
92 user->private.username = "";
93 user->private.domain = "";
94 user->private.nt_username = "";
95 user->private.full_name = "";
96 user->private.home_dir = "";
97 user->private.logon_script = "";
98 user->private.profile_path = "";
99 user->private.acct_desc = "";
100 user->private.workstations = "";
101 user->private.unknown_str = "";
102 user->private.munged_dial = "";
104 user->private.plaintext_pw = NULL;
108 static void destroy_pdb_talloc(SAM_ACCOUNT **user)
111 data_blob_clear_free(&((*user)->private.lm_pw));
112 data_blob_clear_free(&((*user)->private.nt_pw));
114 if((*user)->private.plaintext_pw!=NULL)
115 memset((*user)->private.plaintext_pw,'\0',strlen((*user)->private.plaintext_pw));
116 talloc_destroy((*user)->mem_ctx);
122 /**********************************************************************
123 Alloc memory and initialises a struct sam_passwd on supplied mem_ctx.
124 ***********************************************************************/
126 NTSTATUS pdb_init_sam_talloc(TALLOC_CTX *mem_ctx, SAM_ACCOUNT **user)
129 DEBUG(0,("pdb_init_sam_talloc: SAM_ACCOUNT was non NULL\n"));
131 smb_panic("non-NULL pointer passed to pdb_init_sam\n");
133 return NT_STATUS_UNSUCCESSFUL;
137 DEBUG(0,("pdb_init_sam_talloc: mem_ctx was NULL!\n"));
138 return NT_STATUS_UNSUCCESSFUL;
141 *user=(SAM_ACCOUNT *)talloc(mem_ctx, sizeof(SAM_ACCOUNT));
144 DEBUG(0,("pdb_init_sam_talloc: error while allocating memory\n"));
145 return NT_STATUS_NO_MEMORY;
148 (*user)->mem_ctx = mem_ctx;
150 (*user)->free_fn = NULL;
152 pdb_fill_default_sam(*user);
158 /*************************************************************
159 Alloc memory and initialises a struct sam_passwd.
160 ************************************************************/
162 NTSTATUS pdb_init_sam(SAM_ACCOUNT **user)
167 mem_ctx = talloc_init("passdb internal SAM_ACCOUNT allocation");
170 DEBUG(0,("pdb_init_sam: error while doing talloc_init()\n"));
171 return NT_STATUS_NO_MEMORY;
174 if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam_talloc(mem_ctx, user))) {
175 talloc_destroy(mem_ctx);
179 (*user)->free_fn = destroy_pdb_talloc;
185 /*************************************************************
186 Initialises a struct sam_passwd with sane values.
187 ************************************************************/
189 NTSTATUS pdb_fill_sam_pw(SAM_ACCOUNT *sam_account, const struct passwd *pwd)
194 return NT_STATUS_UNSUCCESSFUL;
197 pdb_fill_default_sam(sam_account);
199 pdb_set_username(sam_account, pwd->pw_name, PDB_SET);
200 pdb_set_fullname(sam_account, pwd->pw_gecos, PDB_SET);
202 pdb_set_unix_homedir(sam_account, pwd->pw_dir, PDB_SET);
204 pdb_set_domain (sam_account, get_global_sam_name(), PDB_DEFAULT);
206 /* When we get a proper uid -> SID and SID -> uid allocation
207 mechinism, we should call it here.
209 We can't just set this to 0 or allow it only to be filled
210 in when added to the backend, because the user's SID
211 may already be in security descriptors etc.
213 -- abartlet 11-May-02
216 ret = pdb_set_sam_sids(sam_account, pwd);
217 if (!NT_STATUS_IS_OK(ret)) return ret;
219 /* check if this is a user account or a machine account */
220 if (pwd->pw_name[strlen(pwd->pw_name)-1] != '$')
222 pdb_set_profile_path(sam_account,
223 talloc_sub_specified((sam_account)->mem_ctx,
225 pwd->pw_name, global_myname(),
226 pwd->pw_uid, pwd->pw_gid),
229 pdb_set_homedir(sam_account,
230 talloc_sub_specified((sam_account)->mem_ctx,
232 pwd->pw_name, global_myname(),
233 pwd->pw_uid, pwd->pw_gid),
236 pdb_set_dir_drive(sam_account,
237 talloc_sub_specified((sam_account)->mem_ctx,
239 pwd->pw_name, global_myname(),
240 pwd->pw_uid, pwd->pw_gid),
243 pdb_set_logon_script(sam_account,
244 talloc_sub_specified((sam_account)->mem_ctx,
246 pwd->pw_name, global_myname(),
247 pwd->pw_uid, pwd->pw_gid),
249 if (!pdb_set_acct_ctrl(sam_account, ACB_NORMAL, PDB_DEFAULT)) {
250 DEBUG(1, ("Failed to set 'normal account' flags for user %s.\n", pwd->pw_name));
251 return NT_STATUS_UNSUCCESSFUL;
254 if (!pdb_set_acct_ctrl(sam_account, ACB_WSTRUST, PDB_DEFAULT)) {
255 DEBUG(1, ("Failed to set 'trusted workstation account' flags for user %s.\n", pwd->pw_name));
256 return NT_STATUS_UNSUCCESSFUL;
263 /*************************************************************
264 Initialises a struct sam_passwd with sane values.
265 ************************************************************/
267 NTSTATUS pdb_init_sam_pw(SAM_ACCOUNT **new_sam_acct, const struct passwd *pwd)
273 return NT_STATUS_INVALID_PARAMETER;
276 if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(new_sam_acct))) {
281 if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*new_sam_acct, pwd))) {
282 pdb_free_sam(new_sam_acct);
291 /*************************************************************
292 Initialises a SAM_ACCOUNT ready to add a new account, based
293 on the UNIX user. Pass in a RID if you have one
294 ************************************************************/
296 NTSTATUS pdb_init_sam_new(SAM_ACCOUNT **new_sam_acct, const char *username,
299 NTSTATUS nt_status = NT_STATUS_NO_MEMORY;
303 pwd = Get_Pwnam(username);
306 return NT_STATUS_NO_SUCH_USER;
308 if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam_pw(new_sam_acct, pwd))) {
309 *new_sam_acct = NULL;
313 /* see if we need to generate a new rid using the 2.2 algorithm */
314 if ( rid == 0 && lp_enable_rid_algorithm() ) {
315 DEBUG(10,("pdb_init_sam_new: no RID specified. Generating one via old algorithm\n"));
316 rid = fallback_pdb_uid_to_user_rid(pwd->pw_uid);
319 /* set the new SID */
321 ret = pdb_set_user_sid_from_rid( *new_sam_acct, rid, PDB_SET );
323 return (ret ? NT_STATUS_OK : NT_STATUS_NO_SUCH_USER);
328 * Free the contets of the SAM_ACCOUNT, but not the structure.
330 * Also wipes the LM and NT hashes and plaintext password from
333 * @param user SAM_ACCOUNT to free members of.
336 static void pdb_free_sam_contents(SAM_ACCOUNT *user)
339 /* Kill off sensitive data. Free()ed by the
342 data_blob_clear_free(&(user->private.lm_pw));
343 data_blob_clear_free(&(user->private.nt_pw));
344 if (user->private.plaintext_pw!=NULL)
345 memset(user->private.plaintext_pw,'\0',strlen(user->private.plaintext_pw));
347 if (user->private.backend_private_data && user->private.backend_private_data_free_fn) {
348 user->private.backend_private_data_free_fn(&user->private.backend_private_data);
353 /************************************************************
354 Reset the SAM_ACCOUNT and free the NT/LM hashes.
355 ***********************************************************/
357 NTSTATUS pdb_reset_sam(SAM_ACCOUNT *user)
360 DEBUG(0,("pdb_reset_sam: SAM_ACCOUNT was NULL\n"));
362 smb_panic("NULL pointer passed to pdb_free_sam\n");
364 return NT_STATUS_UNSUCCESSFUL;
367 pdb_free_sam_contents(user);
369 pdb_fill_default_sam(user);
375 /************************************************************
376 Free the SAM_ACCOUNT and the member pointers.
377 ***********************************************************/
379 NTSTATUS pdb_free_sam(SAM_ACCOUNT **user)
382 DEBUG(0,("pdb_free_sam: SAM_ACCOUNT was NULL\n"));
384 smb_panic("NULL pointer passed to pdb_free_sam\n");
386 return NT_STATUS_UNSUCCESSFUL;
389 pdb_free_sam_contents(*user);
391 if ((*user)->free_fn) {
392 (*user)->free_fn(user);
398 /**************************************************************************
399 * This function will take care of all the steps needed to correctly
400 * allocate and set the user SID, please do use this function to create new
401 * users, messing with SIDs is not good.
403 * account_data must be provided initialized, pwd may be null.
405 ***************************************************************************/
407 NTSTATUS pdb_set_sam_sids(SAM_ACCOUNT *account_data, const struct passwd *pwd)
409 const char *guest_account = lp_guestaccount();
412 if (!account_data || !pwd) {
413 return NT_STATUS_INVALID_PARAMETER;
416 /* this is a hack this thing should not be set
418 if (!(guest_account && *guest_account)) {
419 DEBUG(1, ("NULL guest account!?!?\n"));
420 return NT_STATUS_UNSUCCESSFUL;
422 /* Ensure this *must* be set right */
423 if (strcmp(pwd->pw_name, guest_account) == 0) {
424 if (!pdb_set_user_sid_from_rid(account_data, DOMAIN_USER_RID_GUEST, PDB_DEFAULT)) {
425 return NT_STATUS_UNSUCCESSFUL;
427 if (!pdb_set_group_sid_from_rid(account_data, DOMAIN_GROUP_RID_GUESTS, PDB_DEFAULT)) {
428 return NT_STATUS_UNSUCCESSFUL;
434 if (!pdb_set_user_sid_from_rid(account_data, fallback_pdb_uid_to_user_rid(pwd->pw_uid), PDB_SET)) {
435 DEBUG(0,("Can't set User SID from RID!\n"));
436 return NT_STATUS_INVALID_PARAMETER;
439 /* call the mapping code here */
440 if(pdb_getgrgid(&map, pwd->pw_gid)) {
441 if (!pdb_set_group_sid(account_data, &map.sid, PDB_SET)){
442 DEBUG(0,("Can't set Group SID!\n"));
443 return NT_STATUS_INVALID_PARAMETER;
447 if (!pdb_set_group_sid_from_rid(account_data, pdb_gid_to_group_rid(pwd->pw_gid), PDB_SET)) {
448 DEBUG(0,("Can't set Group SID\n"));
449 return NT_STATUS_INVALID_PARAMETER;
456 /**********************************************************
457 Encode the account control bits into a string.
458 length = length of string to encode into (including terminating
459 null). length *MUST BE MORE THAN 2* !
460 **********************************************************/
462 char *pdb_encode_acct_ctrl(uint16 acct_ctrl, size_t length)
464 static fstring acct_str;
469 if (acct_ctrl & ACB_PWNOTREQ ) acct_str[i++] = 'N';
470 if (acct_ctrl & ACB_DISABLED ) acct_str[i++] = 'D';
471 if (acct_ctrl & ACB_HOMDIRREQ) acct_str[i++] = 'H';
472 if (acct_ctrl & ACB_TEMPDUP ) acct_str[i++] = 'T';
473 if (acct_ctrl & ACB_NORMAL ) acct_str[i++] = 'U';
474 if (acct_ctrl & ACB_MNS ) acct_str[i++] = 'M';
475 if (acct_ctrl & ACB_WSTRUST ) acct_str[i++] = 'W';
476 if (acct_ctrl & ACB_SVRTRUST ) acct_str[i++] = 'S';
477 if (acct_ctrl & ACB_AUTOLOCK ) acct_str[i++] = 'L';
478 if (acct_ctrl & ACB_PWNOEXP ) acct_str[i++] = 'X';
479 if (acct_ctrl & ACB_DOMTRUST ) acct_str[i++] = 'I';
481 for ( ; i < length - 2 ; i++ )
486 acct_str[i++] = '\0';
491 /**********************************************************
492 Decode the account control bits from a string.
493 **********************************************************/
495 uint16 pdb_decode_acct_ctrl(const char *p)
497 uint16 acct_ctrl = 0;
498 BOOL finished = False;
501 * Check if the account type bits have been encoded after the
502 * NT password (in the form [NDHTUWSLXI]).
508 for (p++; *p && !finished; p++) {
510 case 'N': { acct_ctrl |= ACB_PWNOTREQ ; break; /* 'N'o password. */ }
511 case 'D': { acct_ctrl |= ACB_DISABLED ; break; /* 'D'isabled. */ }
512 case 'H': { acct_ctrl |= ACB_HOMDIRREQ; break; /* 'H'omedir required. */ }
513 case 'T': { acct_ctrl |= ACB_TEMPDUP ; break; /* 'T'emp account. */ }
514 case 'U': { acct_ctrl |= ACB_NORMAL ; break; /* 'U'ser account (normal). */ }
515 case 'M': { acct_ctrl |= ACB_MNS ; break; /* 'M'NS logon user account. What is this ? */ }
516 case 'W': { acct_ctrl |= ACB_WSTRUST ; break; /* 'W'orkstation account. */ }
517 case 'S': { acct_ctrl |= ACB_SVRTRUST ; break; /* 'S'erver account. */ }
518 case 'L': { acct_ctrl |= ACB_AUTOLOCK ; break; /* 'L'ocked account. */ }
519 case 'X': { acct_ctrl |= ACB_PWNOEXP ; break; /* No 'X'piry on password */ }
520 case 'I': { acct_ctrl |= ACB_DOMTRUST ; break; /* 'I'nterdomain trust account. */ }
526 default: { finished = True; }
533 /*************************************************************
534 Routine to set 32 hex password characters from a 16 byte array.
535 **************************************************************/
537 void pdb_sethexpwd(char *p, const unsigned char *pwd, uint16 acct_ctrl)
541 for (i = 0; i < 16; i++)
542 slprintf(&p[i*2], 3, "%02X", pwd[i]);
544 if (acct_ctrl & ACB_PWNOTREQ)
545 safe_strcpy(p, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", 33);
547 safe_strcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 33);
551 /*************************************************************
552 Routine to get the 32 hex characters and turn them
553 into a 16 byte array.
554 **************************************************************/
556 BOOL pdb_gethexpwd(const char *p, unsigned char *pwd)
559 unsigned char lonybble, hinybble;
560 const char *hexchars = "0123456789ABCDEF";
566 for (i = 0; i < 32; i += 2) {
567 hinybble = toupper(p[i]);
568 lonybble = toupper(p[i + 1]);
570 p1 = strchr(hexchars, hinybble);
571 p2 = strchr(hexchars, lonybble);
576 hinybble = PTR_DIFF(p1, hexchars);
577 lonybble = PTR_DIFF(p2, hexchars);
579 pwd[i / 2] = (hinybble << 4) | lonybble;
584 int algorithmic_rid_base(void)
586 static int rid_offset = 0;
591 rid_offset = lp_algorithmic_rid_base();
593 if (rid_offset < BASE_RID) {
594 /* Try to prevent admin foot-shooting, we can't put algorithmic
595 rids below 1000, that's the 'well known RIDs' on NT */
596 DEBUG(0, ("'algorithmic rid base' must be equal to or above %ld\n", BASE_RID));
597 rid_offset = BASE_RID;
599 if (rid_offset & 1) {
600 DEBUG(0, ("algorithmic rid base must be even\n"));
606 /*******************************************************************
607 Converts NT user RID to a UNIX uid.
608 ********************************************************************/
610 uid_t fallback_pdb_user_rid_to_uid(uint32 user_rid)
612 int rid_offset = algorithmic_rid_base();
613 return (uid_t)(((user_rid & (~USER_RID_TYPE)) - rid_offset)/RID_MULTIPLIER);
616 /*******************************************************************
617 converts UNIX uid to an NT User RID.
618 ********************************************************************/
620 uint32 fallback_pdb_uid_to_user_rid(uid_t uid)
622 int rid_offset = algorithmic_rid_base();
623 return (((((uint32)uid)*RID_MULTIPLIER) + rid_offset) | USER_RID_TYPE);
626 /*******************************************************************
627 Converts NT group RID to a UNIX gid.
628 ********************************************************************/
630 gid_t pdb_group_rid_to_gid(uint32 group_rid)
632 int rid_offset = algorithmic_rid_base();
633 return (gid_t)(((group_rid & (~GROUP_RID_TYPE))- rid_offset)/RID_MULTIPLIER);
636 /*******************************************************************
637 converts NT Group RID to a UNIX uid.
639 warning: you must not call that function only
640 you must do a call to the group mapping first.
641 there is not anymore a direct link between the gid and the rid.
642 ********************************************************************/
644 uint32 pdb_gid_to_group_rid(gid_t gid)
646 int rid_offset = algorithmic_rid_base();
647 return (((((uint32)gid)*RID_MULTIPLIER) + rid_offset) | GROUP_RID_TYPE);
650 /*******************************************************************
651 Decides if a RID is a well known RID.
652 ********************************************************************/
654 static BOOL pdb_rid_is_well_known(uint32 rid)
656 /* Not using rid_offset here, because this is the actual
657 NT fixed value (1000) */
659 return (rid < BASE_RID);
662 /*******************************************************************
663 Decides if a RID is a user or group RID.
664 ********************************************************************/
666 BOOL fallback_pdb_rid_is_user(uint32 rid)
668 /* lkcl i understand that NT attaches an enumeration to a RID
669 * such that it can be identified as either a user, group etc
670 * type. there are 5 such categories, and they are documented.
672 /* However, they are not in the RID, just somthing you can query
673 seperatly. Sorry luke :-) */
675 if(pdb_rid_is_well_known(rid)) {
677 * The only well known user RIDs are DOMAIN_USER_RID_ADMIN
678 * and DOMAIN_USER_RID_GUEST.
680 if(rid == DOMAIN_USER_RID_ADMIN || rid == DOMAIN_USER_RID_GUEST)
682 } else if((rid & RID_TYPE_MASK) == USER_RID_TYPE) {
688 /*******************************************************************
689 Convert a rid into a name. Used in the lookup SID rpc.
690 ********************************************************************/
692 BOOL local_lookup_sid(DOM_SID *sid, char *name, enum SID_NAME_USE *psid_name_use)
695 SAM_ACCOUNT *sam_account = NULL;
698 if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)){
699 DEBUG(0,("local_lookup_sid: sid_peek_check_rid return False! SID: %s\n",
700 sid_string_static(&map.sid)));
703 *psid_name_use = SID_NAME_UNKNOWN;
705 DEBUG(5,("local_lookup_sid: looking up RID %u.\n", (unsigned int)rid));
707 if (rid == DOMAIN_USER_RID_ADMIN) {
708 const char **admin_list = lp_admin_users(-1);
709 *psid_name_use = SID_NAME_USER;
711 const char *p = *admin_list;
712 if(!next_token(&p, name, NULL, sizeof(fstring)))
713 fstrcpy(name, "Administrator");
715 fstrcpy(name, "Administrator");
721 * Don't try to convert the rid to a name if
722 * running in appliance mode
725 if (lp_hide_local_users())
728 if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) {
732 /* see if the passdb can help us with the name of the user */
735 if (pdb_getsampwsid(sam_account, sid)) {
737 fstrcpy(name, pdb_get_username(sam_account));
738 *psid_name_use = SID_NAME_USER;
740 pdb_free_sam(&sam_account);
745 pdb_free_sam(&sam_account);
747 if (pdb_getgrsid(&map, *sid)) {
748 if (map.gid!=(gid_t)-1) {
749 DEBUG(5,("local_lookup_sid: mapped group %s to gid %u\n", map.nt_name, (unsigned int)map.gid));
751 DEBUG(5,("local_lookup_sid: mapped group %s to no unix gid. Returning name.\n", map.nt_name));
754 fstrcpy(name, map.nt_name);
755 *psid_name_use = map.sid_name_use;
759 if (fallback_pdb_rid_is_user(rid)) {
761 struct passwd *pw = NULL;
763 DEBUG(5, ("assuming RID %u is a user\n", (unsigned)rid));
765 uid = fallback_pdb_user_rid_to_uid(rid);
766 pw = sys_getpwuid( uid );
768 DEBUG(5,("local_lookup_sid: looking up uid %u %s\n", (unsigned int)uid,
769 pw ? "succeeded" : "failed" ));
772 fstr_sprintf(name, "unix_user.%u", (unsigned int)uid);
774 fstrcpy( name, pw->pw_name );
776 DEBUG(5,("local_lookup_sid: found user %s for rid %u\n", name,
777 (unsigned int)rid ));
779 return ( pw != NULL );
784 DEBUG(5, ("assuming RID %u is a group\n", (unsigned)rid));
786 gid = pdb_group_rid_to_gid(rid);
789 *psid_name_use = SID_NAME_ALIAS;
791 DEBUG(5,("local_lookup_sid: looking up gid %u %s\n", (unsigned int)gid,
792 gr ? "succeeded" : "failed" ));
795 fstr_sprintf(name, "unix_group.%u", (unsigned int)gid);
797 fstrcpy( name, gr->gr_name);
799 DEBUG(5,("local_lookup_sid: found group %s for rid %u\n", name,
800 (unsigned int)rid ));
802 return ( gr != NULL );
806 /*******************************************************************
807 Convert a name into a SID. Used in the lookup name rpc.
808 ********************************************************************/
810 BOOL local_lookup_name(const char *c_user, DOM_SID *psid, enum SID_NAME_USE *psid_name_use)
812 extern DOM_SID global_sid_World_Domain;
815 SAM_ACCOUNT *sam_account = NULL;
819 *psid_name_use = SID_NAME_UNKNOWN;
822 * user may be quoted a const string, and map_username and
823 * friends can modify it. Make a modifiable copy. JRA.
826 fstrcpy(user, c_user);
828 sid_copy(&local_sid, get_global_sam_sid());
831 * Special case for MACHINE\Everyone. Map to the world_sid.
834 if(strequal(user, "Everyone")) {
835 sid_copy( psid, &global_sid_World_Domain);
836 sid_append_rid(psid, 0);
837 *psid_name_use = SID_NAME_ALIAS;
842 * Don't lookup local unix users if running in appliance mode
844 if (lp_hide_local_users())
847 (void)map_username(user);
849 if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) {
854 if (pdb_getsampwnam(sam_account, user)) {
856 sid_copy(psid, pdb_get_user_sid(sam_account));
857 *psid_name_use = SID_NAME_USER;
859 pdb_free_sam(&sam_account);
864 pdb_free_sam(&sam_account);
867 * Maybe it was a group ?
870 /* check if it's a mapped group */
871 if (pdb_getgrnam(&map, user)) {
872 /* yes it's a mapped group */
873 sid_copy(&local_sid, &map.sid);
874 *psid_name_use = map.sid_name_use;
876 /* it's not a mapped group */
877 grp = getgrnam(user);
882 *check if it's mapped, if it is reply it doesn't exist
884 * that's to prevent this case:
886 * unix group ug is mapped to nt group ng
887 * someone does a lookup on ug
888 * we must not reply as it doesn't "exist" anymore
889 * for NT. For NT only ng exists.
893 if (pdb_getgrgid(&map, grp->gr_gid)){
897 sid_append_rid( &local_sid, pdb_gid_to_group_rid(grp->gr_gid));
898 *psid_name_use = SID_NAME_ALIAS;
901 sid_copy( psid, &local_sid);
906 /*************************************************************
907 Change a password entry in the local smbpasswd file.
908 *************************************************************/
910 BOOL local_password_change(const char *user_name, int local_flags,
911 const char *new_passwd,
912 char *err_str, size_t err_str_len,
913 char *msg_str, size_t msg_str_len)
915 SAM_ACCOUNT *sam_pass=NULL;
921 /* Get the smb passwd entry for this user */
922 pdb_init_sam(&sam_pass);
925 if(!pdb_getsampwnam(sam_pass, user_name)) {
927 pdb_free_sam(&sam_pass);
929 if ((local_flags & LOCAL_ADD_USER) || (local_flags & LOCAL_DELETE_USER)) {
930 /* Might not exist in /etc/passwd. Use rid algorithm here */
931 if (!NT_STATUS_IS_OK(pdb_init_sam_new(&sam_pass, user_name, 0))) {
932 slprintf(err_str, err_str_len-1, "Failed initialise SAM_ACCOUNT for user %s.\n", user_name);
936 slprintf(err_str, err_str_len-1,"Failed to find entry for user %s.\n", user_name);
941 /* the entry already existed */
942 local_flags &= ~LOCAL_ADD_USER;
945 /* the 'other' acb bits not being changed here */
946 other_acb = (pdb_get_acct_ctrl(sam_pass) & (!(ACB_WSTRUST|ACB_DOMTRUST|ACB_SVRTRUST|ACB_NORMAL)));
947 if (local_flags & LOCAL_TRUST_ACCOUNT) {
948 if (!pdb_set_acct_ctrl(sam_pass, ACB_WSTRUST | other_acb, PDB_CHANGED) ) {
949 slprintf(err_str, err_str_len - 1, "Failed to set 'trusted workstation account' flags for user %s.\n", user_name);
950 pdb_free_sam(&sam_pass);
953 } else if (local_flags & LOCAL_INTERDOM_ACCOUNT) {
954 if (!pdb_set_acct_ctrl(sam_pass, ACB_DOMTRUST | other_acb, PDB_CHANGED)) {
955 slprintf(err_str, err_str_len - 1, "Failed to set 'domain trust account' flags for user %s.\n", user_name);
956 pdb_free_sam(&sam_pass);
960 if (!pdb_set_acct_ctrl(sam_pass, ACB_NORMAL | other_acb, PDB_CHANGED)) {
961 slprintf(err_str, err_str_len - 1, "Failed to set 'normal account' flags for user %s.\n", user_name);
962 pdb_free_sam(&sam_pass);
968 * We are root - just write the new password
969 * and the valid last change time.
972 if (local_flags & LOCAL_DISABLE_USER) {
973 if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_DISABLED, PDB_CHANGED)) {
974 slprintf(err_str, err_str_len-1, "Failed to set 'disabled' flag for user %s.\n", user_name);
975 pdb_free_sam(&sam_pass);
978 } else if (local_flags & LOCAL_ENABLE_USER) {
979 if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_DISABLED), PDB_CHANGED)) {
980 slprintf(err_str, err_str_len-1, "Failed to unset 'disabled' flag for user %s.\n", user_name);
981 pdb_free_sam(&sam_pass);
986 if (local_flags & LOCAL_SET_NO_PASSWORD) {
987 if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_PWNOTREQ, PDB_CHANGED)) {
988 slprintf(err_str, err_str_len-1, "Failed to set 'no password required' flag for user %s.\n", user_name);
989 pdb_free_sam(&sam_pass);
992 } else if (local_flags & LOCAL_SET_PASSWORD) {
994 * If we're dealing with setting a completely empty user account
995 * ie. One with a password of 'XXXX', but not set disabled (like
996 * an account created from scratch) then if the old password was
997 * 'XX's then getsmbpwent will have set the ACB_DISABLED flag.
998 * We remove that as we're giving this user their first password
999 * and the decision hasn't really been made to disable them (ie.
1000 * don't create them disabled). JRA.
1002 if ((pdb_get_lanman_passwd(sam_pass)==NULL) && (pdb_get_acct_ctrl(sam_pass)&ACB_DISABLED)) {
1003 if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_DISABLED), PDB_CHANGED)) {
1004 slprintf(err_str, err_str_len-1, "Failed to unset 'disabled' flag for user %s.\n", user_name);
1005 pdb_free_sam(&sam_pass);
1009 if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_PWNOTREQ), PDB_CHANGED)) {
1010 slprintf(err_str, err_str_len-1, "Failed to unset 'no password required' flag for user %s.\n", user_name);
1011 pdb_free_sam(&sam_pass);
1015 if (!pdb_set_plaintext_passwd (sam_pass, new_passwd)) {
1016 slprintf(err_str, err_str_len-1, "Failed to set password for user %s.\n", user_name);
1017 pdb_free_sam(&sam_pass);
1022 if (local_flags & LOCAL_ADD_USER) {
1023 if (pdb_add_sam_account(sam_pass)) {
1024 slprintf(msg_str, msg_str_len-1, "Added user %s.\n", user_name);
1025 pdb_free_sam(&sam_pass);
1028 slprintf(err_str, err_str_len-1, "Failed to add entry for user %s.\n", user_name);
1029 pdb_free_sam(&sam_pass);
1032 } else if (local_flags & LOCAL_DELETE_USER) {
1033 if (!pdb_delete_sam_account(sam_pass)) {
1034 slprintf(err_str,err_str_len-1, "Failed to delete entry for user %s.\n", user_name);
1035 pdb_free_sam(&sam_pass);
1038 slprintf(msg_str, msg_str_len-1, "Deleted user %s.\n", user_name);
1040 if(!pdb_update_sam_account(sam_pass)) {
1041 slprintf(err_str, err_str_len-1, "Failed to modify entry for user %s.\n", user_name);
1042 pdb_free_sam(&sam_pass);
1045 if(local_flags & LOCAL_DISABLE_USER)
1046 slprintf(msg_str, msg_str_len-1, "Disabled user %s.\n", user_name);
1047 else if (local_flags & LOCAL_ENABLE_USER)
1048 slprintf(msg_str, msg_str_len-1, "Enabled user %s.\n", user_name);
1049 else if (local_flags & LOCAL_SET_NO_PASSWORD)
1050 slprintf(msg_str, msg_str_len-1, "User %s password set to none.\n", user_name);
1053 pdb_free_sam(&sam_pass);
1057 /****************************************************************************
1058 Convert a uid to SID - locally.
1059 ****************************************************************************/
1061 DOM_SID *local_uid_to_sid(DOM_SID *psid, uid_t uid)
1063 SAM_ACCOUNT *sampw = NULL;
1064 struct passwd *unix_pw;
1067 unix_pw = sys_getpwuid( uid );
1070 DEBUG(4,("local_uid_to_sid: host has know idea of uid %lu\n", (unsigned long)uid));
1074 if ( !NT_STATUS_IS_OK(pdb_init_sam(&sampw)) ) {
1075 DEBUG(0,("local_uid_to_sid: failed to allocate SAM_ACCOUNT object\n"));
1080 ret = pdb_getsampwnam( sampw, unix_pw->pw_name );
1084 sid_copy( psid, pdb_get_user_sid(sampw) );
1086 DEBUG(4,("local_uid_to_sid: User %s [uid == %lu] has no samba account\n",
1087 unix_pw->pw_name, (unsigned long)uid));
1089 if ( !lp_enable_rid_algorithm() )
1092 DEBUG(8,("local_uid_to_sid: falling back to RID algorithm\n"));
1094 sid_copy( psid, get_global_sam_sid() );
1095 sid_append_rid( psid, fallback_pdb_uid_to_user_rid(uid) );
1099 DEBUG(10,("local_uid_to_sid: uid (%d) -> SID %s (%s).\n",
1100 (unsigned int)uid, sid_string_static(psid), unix_pw->pw_name));
1105 /****************************************************************************
1106 Convert a SID to uid - locally.
1107 ****************************************************************************/
1109 BOOL local_sid_to_uid(uid_t *puid, const DOM_SID *psid, enum SID_NAME_USE *name_type)
1111 SAM_ACCOUNT *sampw = NULL;
1112 struct passwd *unix_pw;
1113 const char *user_name;
1115 *name_type = SID_NAME_UNKNOWN;
1118 * We can only convert to a uid if this is our local
1119 * Domain SID (ie. we are the controling authority).
1121 if (!sid_check_is_in_our_domain(psid) ) {
1122 DEBUG(5,("local_sid_to_uid: this SID (%s) is not from our domain\n", sid_string_static(psid)));
1126 /* lookup the user account */
1128 if ( !NT_STATUS_IS_OK(pdb_init_sam(&sampw)) ) {
1129 DEBUG(0,("local_sid_to_uid: Failed to allocate memory for SAM_ACCOUNT object\n"));
1134 if ( !pdb_getsampwsid(sampw, psid) ) {
1136 DEBUG(8,("local_sid_to_uid: Could not find SID %s in passdb\n",
1137 sid_string_static(psid)));
1142 user_name = pdb_get_username(sampw);
1144 unix_pw = sys_getpwnam( user_name );
1147 DEBUG(0,("local_sid_to_uid: %s found in passdb but getpwnam() return NULL!\n",
1149 pdb_free_sam( &sampw );
1153 *puid = unix_pw->pw_uid;
1155 DEBUG(10,("local_sid_to_uid: SID %s -> uid (%u) (%s).\n", sid_string_static(psid),
1156 (unsigned int)*puid, user_name ));
1158 *name_type = SID_NAME_USER;
1163 /****************************************************************************
1164 Convert a gid to SID - locally.
1165 ****************************************************************************/
1167 DOM_SID *local_gid_to_sid(DOM_SID *psid, gid_t gid)
1171 /* we don't need to disable winbindd since the gid is stored in
1172 the GROUP_MAP object */
1174 if ( !pdb_getgrgid( &group, gid ) ) {
1176 /* fallback to rid mapping if enabled */
1178 if ( lp_enable_rid_algorithm() ) {
1179 sid_copy(psid, get_global_sam_sid());
1180 sid_append_rid(psid, pdb_gid_to_group_rid(gid));
1182 DEBUG(10,("local_gid_to_sid: Fall back to algorithmic mapping: %u -> %s\n",
1183 (unsigned int)gid, sid_string_static(psid)));
1191 sid_copy( psid, &group.sid );
1193 DEBUG(10,("local_gid_to_sid: gid (%d) -> SID %s.\n",
1194 (unsigned int)gid, sid_string_static(psid)));
1199 /****************************************************************************
1200 Convert a SID to gid - locally.
1201 ****************************************************************************/
1203 BOOL local_sid_to_gid(gid_t *pgid, const DOM_SID *psid, enum SID_NAME_USE *name_type)
1208 *name_type = SID_NAME_UNKNOWN;
1210 /* This call can enumerate group mappings for foreign sids as well.
1211 So don't check for a match against our domain SID */
1213 /* we don't need to disable winbindd since the gid is stored in
1214 the GROUP_MAP object */
1216 if ( !pdb_getgrsid(&group, *psid) ) {
1218 /* fallback to rid mapping if enabled */
1220 if ( lp_enable_rid_algorithm() ) {
1222 if (!sid_check_is_in_our_domain(psid) ) {
1223 DEBUG(5,("local_sid_to_gid: RID algorithm only supported for our domain (%s is not)\n", sid_string_static(psid)));
1227 if (!sid_peek_rid(psid, &rid)) {
1228 DEBUG(10,("local_sid_to_uid: invalid SID!\n"));
1232 DEBUG(10,("local_sid_to_gid: Fall back to algorithmic mapping\n"));
1234 if (fallback_pdb_rid_is_user(rid)) {
1235 DEBUG(3, ("local_sid_to_gid: SID %s is *NOT* a group\n", sid_string_static(psid)));
1238 *pgid = pdb_group_rid_to_gid(rid);
1239 DEBUG(10,("local_sid_to_gid: mapping: %s -> %u\n", sid_string_static(psid), (unsigned int)(*pgid)));
1249 DEBUG(10,("local_sid_to_gid: SID %s -> gid (%u)\n", sid_string_static(psid),
1250 (unsigned int)*pgid));
1255 /**********************************************************************
1256 Marshall/unmarshall SAM_ACCOUNT structs.
1257 *********************************************************************/
1259 #define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd"
1261 /**********************************************************************
1262 Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len
1263 *********************************************************************/
1265 BOOL init_sam_from_buffer(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
1268 /* times are stored as 32bit integer
1269 take care on system with 64bit wide time_t
1275 pass_can_change_time,
1276 pass_must_change_time;
1289 uint32 username_len, domain_len, nt_username_len,
1290 dir_drive_len, unknown_str_len, munged_dial_len,
1291 fullname_len, homedir_len, logon_script_len,
1292 profile_path_len, acct_desc_len, workstations_len;
1294 uint32 user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6;
1295 uint16 acct_ctrl, logon_divs;
1297 static uint8 *lm_pw_ptr, *nt_pw_ptr;
1299 uint32 lm_pw_len, nt_pw_len, hourslen;
1304 if(sampass == NULL || buf == NULL) {
1305 DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n"));
1309 /* unpack the buffer into variables */
1310 len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING,
1314 &pass_last_set_time,
1315 &pass_can_change_time,
1316 &pass_must_change_time,
1317 &username_len, &username,
1318 &domain_len, &domain,
1319 &nt_username_len, &nt_username,
1320 &fullname_len, &fullname,
1321 &homedir_len, &homedir,
1322 &dir_drive_len, &dir_drive,
1323 &logon_script_len, &logon_script,
1324 &profile_path_len, &profile_path,
1325 &acct_desc_len, &acct_desc,
1326 &workstations_len, &workstations,
1327 &unknown_str_len, &unknown_str,
1328 &munged_dial_len, &munged_dial,
1331 &lm_pw_len, &lm_pw_ptr,
1332 &nt_pw_len, &nt_pw_ptr,
1346 pdb_set_logon_time(sampass, logon_time, PDB_SET);
1347 pdb_set_logoff_time(sampass, logoff_time, PDB_SET);
1348 pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET);
1349 pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET);
1350 pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET);
1351 pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET);
1353 pdb_set_username(sampass, username, PDB_SET);
1354 pdb_set_domain(sampass, domain, PDB_SET);
1355 pdb_set_nt_username(sampass, nt_username, PDB_SET);
1356 pdb_set_fullname(sampass, fullname, PDB_SET);
1359 pdb_set_homedir(sampass, homedir, PDB_SET);
1362 pdb_set_homedir(sampass,
1363 talloc_sub_specified(sampass->mem_ctx,
1371 pdb_set_dir_drive(sampass, dir_drive, PDB_SET);
1373 pdb_set_dir_drive(sampass,
1374 talloc_sub_specified(sampass->mem_ctx,
1382 pdb_set_logon_script(sampass, logon_script, PDB_SET);
1384 pdb_set_logon_script(sampass,
1385 talloc_sub_specified(sampass->mem_ctx,
1393 pdb_set_profile_path(sampass, profile_path, PDB_SET);
1395 pdb_set_profile_path(sampass,
1396 talloc_sub_specified(sampass->mem_ctx,
1403 pdb_set_acct_desc(sampass, acct_desc, PDB_SET);
1404 pdb_set_workstations(sampass, workstations, PDB_SET);
1405 pdb_set_munged_dial(sampass, munged_dial, PDB_SET);
1407 if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) {
1408 if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) {
1414 if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) {
1415 if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) {
1421 pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET);
1422 pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET);
1423 pdb_set_unknown_3(sampass, unknown_3, PDB_SET);
1424 pdb_set_hours_len(sampass, hours_len, PDB_SET);
1425 pdb_set_unknown_5(sampass, unknown_5, PDB_SET);
1426 pdb_set_unknown_6(sampass, unknown_6, PDB_SET);
1427 pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET);
1428 pdb_set_logon_divs(sampass, logon_divs, PDB_SET);
1429 pdb_set_hours(sampass, hours, PDB_SET);
1433 SAFE_FREE(username);
1435 SAFE_FREE(nt_username);
1436 SAFE_FREE(fullname);
1438 SAFE_FREE(dir_drive);
1439 SAFE_FREE(logon_script);
1440 SAFE_FREE(profile_path);
1441 SAFE_FREE(acct_desc);
1442 SAFE_FREE(workstations);
1443 SAFE_FREE(munged_dial);
1444 SAFE_FREE(unknown_str);
1450 /**********************************************************************
1451 Intialize a BYTE buffer from a SAM_ACCOUNT struct
1452 *********************************************************************/
1454 uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass, BOOL size_only)
1458 /* times are stored as 32bit integer
1459 take care on system with 64bit wide time_t
1465 pass_can_change_time,
1466 pass_must_change_time;
1468 uint32 user_rid, group_rid;
1470 const char *username;
1472 const char *nt_username;
1473 const char *dir_drive;
1474 const char *unknown_str;
1475 const char *munged_dial;
1476 const char *fullname;
1477 const char *homedir;
1478 const char *logon_script;
1479 const char *profile_path;
1480 const char *acct_desc;
1481 const char *workstations;
1482 uint32 username_len, domain_len, nt_username_len,
1483 dir_drive_len, unknown_str_len, munged_dial_len,
1484 fullname_len, homedir_len, logon_script_len,
1485 profile_path_len, acct_desc_len, workstations_len;
1489 uint32 lm_pw_len = 16;
1490 uint32 nt_pw_len = 16;
1492 /* do we have a valid SAM_ACCOUNT pointer? */
1493 if (sampass == NULL) {
1494 DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n"));
1501 logon_time = (uint32)pdb_get_logon_time(sampass);
1502 logoff_time = (uint32)pdb_get_logoff_time(sampass);
1503 kickoff_time = (uint32)pdb_get_kickoff_time(sampass);
1504 pass_can_change_time = (uint32)pdb_get_pass_can_change_time(sampass);
1505 pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass);
1506 pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass);
1508 user_rid = pdb_get_user_rid(sampass);
1509 group_rid = pdb_get_group_rid(sampass);
1511 username = pdb_get_username(sampass);
1513 username_len = strlen(username) +1;
1517 domain = pdb_get_domain(sampass);
1519 domain_len = strlen(domain) +1;
1523 nt_username = pdb_get_nt_username(sampass);
1525 nt_username_len = strlen(nt_username) +1;
1527 nt_username_len = 0;
1529 fullname = pdb_get_fullname(sampass);
1531 fullname_len = strlen(fullname) +1;
1536 * Only updates fields which have been set (not defaults from smb.conf)
1539 if (!IS_SAM_DEFAULT(sampass, PDB_DRIVE))
1540 dir_drive = pdb_get_dir_drive(sampass);
1544 dir_drive_len = strlen(dir_drive) +1;
1548 if (!IS_SAM_DEFAULT(sampass, PDB_SMBHOME))
1549 homedir = pdb_get_homedir(sampass);
1553 homedir_len = strlen(homedir) +1;
1557 if (!IS_SAM_DEFAULT(sampass, PDB_LOGONSCRIPT))
1558 logon_script = pdb_get_logon_script(sampass);
1560 logon_script = NULL;
1562 logon_script_len = strlen(logon_script) +1;
1564 logon_script_len = 0;
1566 if (!IS_SAM_DEFAULT(sampass, PDB_PROFILE))
1567 profile_path = pdb_get_profile_path(sampass);
1569 profile_path = NULL;
1571 profile_path_len = strlen(profile_path) +1;
1573 profile_path_len = 0;
1575 lm_pw = pdb_get_lanman_passwd(sampass);
1579 nt_pw = pdb_get_nt_passwd(sampass);
1583 acct_desc = pdb_get_acct_desc(sampass);
1585 acct_desc_len = strlen(acct_desc) +1;
1589 workstations = pdb_get_workstations(sampass);
1591 workstations_len = strlen(workstations) +1;
1593 workstations_len = 0;
1596 unknown_str_len = 0;
1598 munged_dial = pdb_get_munged_dial(sampass);
1600 munged_dial_len = strlen(munged_dial) +1;
1602 munged_dial_len = 0;
1604 /* one time to get the size needed */
1605 len = tdb_pack(NULL, 0, TDB_FORMAT_STRING,
1610 pass_can_change_time,
1611 pass_must_change_time,
1612 username_len, username,
1614 nt_username_len, nt_username,
1615 fullname_len, fullname,
1616 homedir_len, homedir,
1617 dir_drive_len, dir_drive,
1618 logon_script_len, logon_script,
1619 profile_path_len, profile_path,
1620 acct_desc_len, acct_desc,
1621 workstations_len, workstations,
1622 unknown_str_len, unknown_str,
1623 munged_dial_len, munged_dial,
1628 pdb_get_acct_ctrl(sampass),
1629 pdb_get_unknown_3(sampass),
1630 pdb_get_logon_divs(sampass),
1631 pdb_get_hours_len(sampass),
1632 MAX_HOURS_LEN, pdb_get_hours(sampass),
1633 pdb_get_unknown_5(sampass),
1634 pdb_get_unknown_6(sampass));
1640 /* malloc the space needed */
1641 if ( (*buf=(uint8*)malloc(len)) == NULL) {
1642 DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n"));
1646 /* now for the real call to tdb_pack() */
1647 buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING,
1652 pass_can_change_time,
1653 pass_must_change_time,
1654 username_len, username,
1656 nt_username_len, nt_username,
1657 fullname_len, fullname,
1658 homedir_len, homedir,
1659 dir_drive_len, dir_drive,
1660 logon_script_len, logon_script,
1661 profile_path_len, profile_path,
1662 acct_desc_len, acct_desc,
1663 workstations_len, workstations,
1664 unknown_str_len, unknown_str,
1665 munged_dial_len, munged_dial,
1670 pdb_get_acct_ctrl(sampass),
1671 pdb_get_unknown_3(sampass),
1672 pdb_get_logon_divs(sampass),
1673 pdb_get_hours_len(sampass),
1674 MAX_HOURS_LEN, pdb_get_hours(sampass),
1675 pdb_get_unknown_5(sampass),
1676 pdb_get_unknown_6(sampass));
1679 /* check to make sure we got it correct */
1680 if (buflen != len) {
1681 DEBUG(0, ("init_buffer_from_sam: somthing odd is going on here: bufflen (%lu) != len (%lu) in tdb_pack operations!\n",
1682 (unsigned long)buflen, (unsigned long)len));