2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998
4 * Copyright (C) Simo Sorce 2000
5 * Copyright (C) Gerald Carter 2000
6 * Copyright (C) Jeremy Allison 2001
7 * Copyright (C) Andrew Bartlett 2002
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program; if not, write to the Free Software Foundation, Inc., 675
21 * Mass Ave, Cambridge, MA 02139, USA.
28 #define PDB_VERSION "20010830"
29 #define PASSDB_FILE_NAME "/passdb.tdb"
30 #define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd"
31 #define USERPREFIX "USER_"
32 #define RIDPREFIX "RID_"
34 struct tdbsam_privates {
35 TDB_CONTEXT *passwd_tdb;
38 /* retrive-once info */
39 const char *tdbsam_location;
41 BOOL permit_non_unix_accounts;
47 /**********************************************************************
48 Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len
49 *********************************************************************/
51 static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state,
52 SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
55 /* times are stored as 32bit integer
56 take care on system with 64bit wide time_t
63 pass_must_change_time;
76 uint32 username_len, domain_len, nt_username_len,
77 dir_drive_len, unknown_str_len, munged_dial_len,
78 fullname_len, homedir_len, logon_script_len,
79 profile_path_len, acct_desc_len, workstations_len;
81 uint32 /* uid, gid,*/ user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6;
82 uint16 acct_ctrl, logon_divs;
84 static uint8 *lm_pw_ptr, *nt_pw_ptr;
86 uint32 lmpwlen, ntpwlen, hourslen;
89 if(sampass == NULL || buf == NULL) {
90 DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n"));
94 /* unpack the buffer into variables */
95 len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING,
100 &pass_can_change_time,
101 &pass_must_change_time,
102 &username_len, &username,
103 &domain_len, &domain,
104 &nt_username_len, &nt_username,
105 &fullname_len, &fullname,
106 &homedir_len, &homedir,
107 &dir_drive_len, &dir_drive,
108 &logon_script_len, &logon_script,
109 &profile_path_len, &profile_path,
110 &acct_desc_len, &acct_desc,
111 &workstations_len, &workstations,
112 &unknown_str_len, &unknown_str,
113 &munged_dial_len, &munged_dial,
116 &lmpwlen, &lm_pw_ptr,
117 &ntpwlen, &nt_pw_ptr,
131 pdb_set_logon_time(sampass, logon_time);
132 pdb_set_logoff_time(sampass, logoff_time);
133 pdb_set_kickoff_time(sampass, kickoff_time);
134 pdb_set_pass_can_change_time(sampass, pass_can_change_time);
135 pdb_set_pass_must_change_time(sampass, pass_must_change_time);
136 pdb_set_pass_last_set_time(sampass, pass_last_set_time);
138 pdb_set_username (sampass, username_len?username:NULL);
139 pdb_set_domain (sampass, domain_len?domain:NULL);
140 pdb_set_nt_username (sampass, nt_username_len?nt_username:NULL);
141 pdb_set_fullname (sampass, fullname_len?fullname:NULL);
142 pdb_set_homedir (sampass, homedir_len?homedir:NULL, True);
143 pdb_set_dir_drive (sampass, dir_drive_len?dir_drive:NULL, True);
144 pdb_set_logon_script (sampass, logon_script_len?logon_script:NULL, True);
145 pdb_set_profile_path (sampass, profile_path_len?profile_path:NULL, True);
146 pdb_set_acct_desc (sampass, acct_desc_len?acct_desc:NULL);
147 pdb_set_workstations (sampass, workstations_len?workstations:NULL);
148 pdb_set_munged_dial (sampass, munged_dial_len?munged_dial:NULL);
149 if (!pdb_set_lanman_passwd(sampass, lmpwlen?lm_pw_ptr:NULL)) {
153 if (!pdb_set_nt_passwd(sampass, ntpwlen?nt_pw_ptr:NULL)) {
158 pdb_set_user_rid(sampass, user_rid);
159 pdb_set_group_rid(sampass, group_rid);
160 pdb_set_unknown_3(sampass, unknown_3);
161 pdb_set_hours_len(sampass, hours_len);
162 pdb_set_unknown_5(sampass, unknown_5);
163 pdb_set_unknown_6(sampass, unknown_6);
164 pdb_set_acct_ctrl(sampass, acct_ctrl);
165 pdb_set_logon_divs(sampass, logon_divs);
166 pdb_set_hours(sampass, hours);
168 if ((tdb_state->permit_non_unix_accounts)
169 && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid)
170 && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) {
174 /* validate the account and fill in UNIX uid and gid. sys_getpwnam()
175 is used instaed of Get_Pwnam() as we do not need to try case
178 if ((pw=getpwnam_alloc(pdb_get_username(sampass))) == NULL) {
179 DEBUG(0,("init_sam_from_buffer: (tdbsam) getpwnam(%s) return NULL. User does not exist!\n",
180 pdb_get_username(sampass)));
184 pdb_set_uid(sampass, pw->pw_uid);
185 pdb_set_gid(sampass, pw->pw_gid);
194 SAFE_FREE(nt_username);
197 SAFE_FREE(dir_drive);
198 SAFE_FREE(logon_script);
199 SAFE_FREE(profile_path);
200 SAFE_FREE(acct_desc);
201 SAFE_FREE(workstations);
202 SAFE_FREE(munged_dial);
207 /**********************************************************************
208 Intialize a BYTE buffer from a SAM_ACCOUNT struct
209 *********************************************************************/
210 static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **buf,
211 const SAM_ACCOUNT *sampass, uint32 user_rid, uint32 group_rid)
215 /* times are stored as 32bit integer
216 take care on system with 64bit wide time_t
222 pass_can_change_time,
223 pass_must_change_time;
224 const char *username;
226 const char *nt_username;
227 const char *dir_drive;
228 const char *unknown_str;
229 const char *munged_dial;
230 const char *fullname;
232 const char *logon_script;
233 const char *profile_path;
234 const char *acct_desc;
235 const char *workstations;
236 uint32 username_len, domain_len, nt_username_len,
237 dir_drive_len, unknown_str_len, munged_dial_len,
238 fullname_len, homedir_len, logon_script_len,
239 profile_path_len, acct_desc_len, workstations_len;
243 uint32 lm_pw_len = 16;
244 uint32 nt_pw_len = 16;
246 /* do we have a valid SAM_ACCOUNT pointer? */
247 if (sampass == NULL) {
248 DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n"));
255 logon_time = (uint32)pdb_get_logon_time(sampass);
256 logoff_time = (uint32)pdb_get_logoff_time(sampass);
257 kickoff_time = (uint32)pdb_get_kickoff_time(sampass);
258 pass_can_change_time = (uint32)pdb_get_pass_can_change_time(sampass);
259 pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass);
260 pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass);
263 username = pdb_get_username(sampass);
265 username_len = strlen(username) +1;
268 domain = pdb_get_domain(sampass);
270 domain_len = strlen(domain) +1;
273 nt_username = pdb_get_nt_username(sampass);
275 nt_username_len = strlen(nt_username) +1;
278 dir_drive = pdb_get_dirdrive(sampass);
280 dir_drive_len = strlen(dir_drive) +1;
285 munged_dial = pdb_get_munged_dial(sampass);
287 munged_dial_len = strlen(munged_dial) +1;
291 fullname = pdb_get_fullname(sampass);
293 fullname_len = strlen(fullname) +1;
296 homedir = pdb_get_homedir(sampass);
298 homedir_len = strlen(homedir) +1;
301 logon_script = pdb_get_logon_script(sampass);
303 logon_script_len = strlen(logon_script) +1;
305 logon_script_len = 0;
306 profile_path = pdb_get_profile_path(sampass);
308 profile_path_len = strlen(profile_path) +1;
310 profile_path_len = 0;
311 acct_desc = pdb_get_acct_desc(sampass);
313 acct_desc_len = strlen(acct_desc) +1;
316 workstations = pdb_get_workstations(sampass);
318 workstations_len = strlen(workstations) +1;
320 workstations_len = 0;
322 lm_pw = pdb_get_lanman_passwd(sampass);
326 nt_pw = pdb_get_nt_passwd(sampass);
330 /* one time to get the size needed */
331 len = tdb_pack(NULL, 0, TDB_FORMAT_STRING,
336 pass_can_change_time,
337 pass_must_change_time,
338 username_len, username,
340 nt_username_len, nt_username,
341 fullname_len, fullname,
342 homedir_len, homedir,
343 dir_drive_len, dir_drive,
344 logon_script_len, logon_script,
345 profile_path_len, profile_path,
346 acct_desc_len, acct_desc,
347 workstations_len, workstations,
348 unknown_str_len, unknown_str,
349 munged_dial_len, munged_dial,
354 pdb_get_acct_ctrl(sampass),
355 pdb_get_unknown3(sampass),
356 pdb_get_logon_divs(sampass),
357 pdb_get_hours_len(sampass),
358 MAX_HOURS_LEN, pdb_get_hours(sampass),
359 pdb_get_unknown5(sampass),
360 pdb_get_unknown6(sampass));
363 /* malloc the space needed */
364 if ( (*buf=(uint8*)malloc(len)) == NULL) {
365 DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n"));
369 /* now for the real call to tdb_pack() */
370 buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING,
375 pass_can_change_time,
376 pass_must_change_time,
377 username_len, username,
379 nt_username_len, nt_username,
380 fullname_len, fullname,
381 homedir_len, homedir,
382 dir_drive_len, dir_drive,
383 logon_script_len, logon_script,
384 profile_path_len, profile_path,
385 acct_desc_len, acct_desc,
386 workstations_len, workstations,
387 unknown_str_len, unknown_str,
388 munged_dial_len, munged_dial,
393 pdb_get_acct_ctrl(sampass),
394 pdb_get_unknown3(sampass),
395 pdb_get_logon_divs(sampass),
396 pdb_get_hours_len(sampass),
397 MAX_HOURS_LEN, pdb_get_hours(sampass),
398 pdb_get_unknown5(sampass),
399 pdb_get_unknown6(sampass));
402 /* check to make sure we got it correct */
404 DEBUG(0, ("init_buffer_from_sam: somthing odd is going on here: bufflen (%d) != len (%d) in tdb_pack operations!\n",
414 /***************************************************************
415 Open the TDB passwd database for SAM account enumeration.
416 ****************************************************************/
418 static BOOL tdbsam_setsampwent(struct pdb_context *context, BOOL update)
420 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
422 /* Open tdb passwd */
423 if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600)))
425 DEBUG(0, ("Unable to open/create TDB passwd\n"));
429 tdb_state->key = tdb_firstkey(tdb_state->passwd_tdb);
434 static void close_tdb(struct tdbsam_privates *tdb_state)
436 if (tdb_state->passwd_tdb) {
437 tdb_close(tdb_state->passwd_tdb);
438 tdb_state->passwd_tdb = NULL;
442 /***************************************************************
443 End enumeration of the TDB passwd list.
444 ****************************************************************/
446 static void tdbsam_endsampwent(struct pdb_context *context)
448 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
449 close_tdb(tdb_state);
451 DEBUG(7, ("endtdbpwent: closed sam database.\n"));
454 /*****************************************************************
455 Get one SAM_ACCOUNT from the TDB (next in line)
456 *****************************************************************/
458 static BOOL tdbsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user)
460 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
462 char *prefix = USERPREFIX;
463 int prefixlen = strlen (prefix);
467 DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n"));
471 /* skip all non-USER entries (eg. RIDs) */
472 while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen)))
473 /* increment to next in line */
474 tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key);
476 /* do we have an valid interation pointer? */
477 if(tdb_state->passwd_tdb == NULL) {
478 DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n"));
482 data = tdb_fetch(tdb_state->passwd_tdb, tdb_state->key);
484 DEBUG(5,("pdb_getsampwent: database entry not found.\n"));
488 /* unpack the buffer */
489 if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) {
490 DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
491 SAFE_FREE(data.dptr);
494 SAFE_FREE(data.dptr);
496 /* increment to next in line */
497 tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key);
502 /******************************************************************
503 Lookup a name in the SAM TDB
504 ******************************************************************/
506 static BOOL tdbsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname)
508 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
509 TDB_CONTEXT *pwd_tdb;
515 DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n"));
519 /* Data is stored in all lower-case */
520 unix_strlower(sname, -1, name, sizeof(name));
523 slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
525 key.dsize = strlen(keystr) + 1;
527 /* open the accounts TDB */
528 if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
529 DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location));
534 data = tdb_fetch(pwd_tdb, key);
536 DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n"));
537 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
538 DEBUGADD(5, (" Key: %s\n", keystr));
543 /* unpack the buffer */
544 if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) {
545 DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
546 SAFE_FREE(data.dptr);
550 SAFE_FREE(data.dptr);
552 /* no further use for database, close it now */
558 /***************************************************************************
560 **************************************************************************/
562 static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid)
564 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
565 TDB_CONTEXT *pwd_tdb;
571 DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n"));
576 slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
578 key.dsize = strlen (keystr) + 1;
580 /* open the accounts TDB */
581 if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
582 DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n"));
587 data = tdb_fetch (pwd_tdb, key);
589 DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n"));
590 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
595 fstrcpy (name, data.dptr);
596 SAFE_FREE(data.dptr);
600 return tdbsam_getsampwnam (context, user, name);
603 /***************************************************************************
605 ****************************************************************************/
607 static BOOL tdbsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass)
609 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
610 TDB_CONTEXT *pwd_tdb;
616 unix_strlower(pdb_get_username(sam_pass), -1, name, sizeof(name));
619 if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) {
620 DEBUG(0, ("Unable to open TDB passwd!"));
624 /* set the search key */
625 slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
627 key.dsize = strlen (keystr) + 1;
629 rid = pdb_get_user_rid(sam_pass);
631 /* it's outaa here! 8^) */
632 if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
633 DEBUG(5, ("Error deleting entry from tdb passwd database!\n"));
634 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
639 /* delete also the RID key */
641 /* set the search key */
642 slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
644 key.dsize = strlen (keystr) + 1;
646 /* it's outaa here! 8^) */
647 if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
648 DEBUG(5, ("Error deleting entry from tdb rid database!\n"));
649 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
659 /***************************************************************************
661 ****************************************************************************/
663 static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpwd, int flag)
665 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
666 TDB_CONTEXT *pwd_tdb = NULL;
676 /* invalidate the existing TDB iterator if it is open */
677 if (tdb_state->passwd_tdb) {
678 tdb_close(tdb_state->passwd_tdb);
679 tdb_state->passwd_tdb = NULL;
682 /* open the account TDB passwd*/
683 pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600);
686 DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location));
690 /* if we don't have a RID, then make them up. */
691 if (!(user_rid = pdb_get_user_rid(newpwd))) {
692 if (!tdb_state->permit_non_unix_accounts) {
693 DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd)));
697 user_rid = tdb_state->low_nua_rid;
698 tdb_ret = tdb_change_int32_atomic(pwd_tdb, "NUA_NEXT_RID", &user_rid, RID_MULTIPLIER);
706 if (!(group_rid = pdb_get_group_rid(newpwd))) {
707 if (!tdb_state->permit_non_unix_accounts) {
708 DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd)));
712 /* This seems like a good default choice for non-unix users */
713 group_rid = DOMAIN_GROUP_RID_USERS;
717 /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */
718 if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd, user_rid, group_rid)) == -1) {
719 DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n"));
725 unix_strlower(pdb_get_username(newpwd), -1, name, sizeof(name));
727 DEBUG(5, ("Storing %saccount %s with RID %d\n", flag == TDB_INSERT ? "(new) " : "", name, user_rid));
729 /* setup the USER index key */
730 slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
732 key.dsize = strlen (keystr) + 1;
734 /* add the account */
735 if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) {
736 DEBUG(0, ("Unable to modify passwd TDB!"));
737 DEBUGADD(0, (" Error: %s", tdb_errorstr(pwd_tdb)));
738 DEBUGADD(0, (" occured while storing the main record (%s)\n", keystr));
744 data.dsize = sizeof(fstring);
747 /* setup the RID index key */
748 slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, user_rid);
750 key.dsize = strlen (keystr) + 1;
752 /* add the reference */
753 if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) {
754 DEBUG(0, ("Unable to modify TDB passwd !"));
755 DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
756 DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr));
769 /***************************************************************************
770 Modifies an existing SAM_ACCOUNT
771 ****************************************************************************/
773 static BOOL tdbsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
775 return (tdb_update_sam(context, newpwd, TDB_MODIFY));
778 /***************************************************************************
779 Adds an existing SAM_ACCOUNT
780 ****************************************************************************/
782 static BOOL tdbsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
784 return (tdb_update_sam(context, newpwd, TDB_INSERT));
787 static void free_private_data(void **vp)
789 struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp;
790 close_tdb(*tdb_state);
793 /* No need to free any further, as it is talloc()ed */
797 NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
800 struct tdbsam_privates *tdb_state;
802 if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) {
806 (*pdb_method)->setsampwent = tdbsam_setsampwent;
807 (*pdb_method)->endsampwent = tdbsam_endsampwent;
808 (*pdb_method)->getsampwent = tdbsam_getsampwent;
809 (*pdb_method)->getsampwnam = tdbsam_getsampwnam;
810 (*pdb_method)->getsampwrid = tdbsam_getsampwrid;
811 (*pdb_method)->add_sam_account = tdbsam_add_sam_account;
812 (*pdb_method)->update_sam_account = tdbsam_update_sam_account;
813 (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account;
815 /* TODO: Setup private data and free */
817 tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates));
820 DEBUG(0, ("talloc() failed for tdbsam private_data!\n"));
821 return NT_STATUS_NO_MEMORY;
825 tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, location);
828 get_private_directory(tdbfile);
829 pstrcat (tdbfile, PASSDB_FILE_NAME);
830 tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile);
833 (*pdb_method)->private_data = tdb_state;
835 (*pdb_method)->free_private_data = free_private_data;
840 NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
843 struct tdbsam_privates *tdb_state;
844 uint32 low_nua_uid, high_nua_uid;
846 if (!NT_STATUS_IS_OK(nt_status = pdb_init_tdbsam(pdb_context, pdb_method, location))) {
850 tdb_state = (*pdb_method)->private_data;
852 tdb_state->permit_non_unix_accounts = True;
854 if (!lp_non_unix_account_range(&low_nua_uid, &high_nua_uid)) {
855 DEBUG(0, ("cannot use tdbsam_nua without 'non unix account range' in smb.conf!\n"));
856 return NT_STATUS_UNSUCCESSFUL;
859 tdb_state->low_nua_rid=pdb_uid_to_user_rid(low_nua_uid);
861 tdb_state->high_nua_rid=pdb_uid_to_user_rid(high_nua_uid);
869 NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
871 DEBUG(0, ("tdbsam not compiled in!\n"));
872 return NT_STATUS_UNSUCCESSFUL;
875 NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
877 DEBUG(0, ("tdbsam_nua not compiled in!\n"));
878 return NT_STATUS_UNSUCCESSFUL;