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;
91 if(sampass == NULL || buf == NULL) {
92 DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n"));
96 /* unpack the buffer into variables */
97 len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING,
102 &pass_can_change_time,
103 &pass_must_change_time,
104 &username_len, &username,
105 &domain_len, &domain,
106 &nt_username_len, &nt_username,
107 &fullname_len, &fullname,
108 &homedir_len, &homedir,
109 &dir_drive_len, &dir_drive,
110 &logon_script_len, &logon_script,
111 &profile_path_len, &profile_path,
112 &acct_desc_len, &acct_desc,
113 &workstations_len, &workstations,
114 &unknown_str_len, &unknown_str,
115 &munged_dial_len, &munged_dial,
118 &lmpwlen, &lm_pw_ptr,
119 &ntpwlen, &nt_pw_ptr,
133 if ((tdb_state->permit_non_unix_accounts)
134 && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid)
135 && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) {
139 /* validate the account and fill in UNIX uid and gid. Standard
140 * getpwnam() is used instead of Get_Pwnam() as we do not need
141 * to try case permutations
143 if (!username || !(pw=getpwnam(username))) {
144 DEBUG(0,("tdb_sam: getpwnam(%s) return NULL. User does not exist!\n",
145 username?username:"NULL"));
149 pdb_set_uid(sampass, pw->pw_uid);
151 pdb_set_gid(sampass, gid);
154 pdb_set_logon_time(sampass, logon_time);
155 pdb_set_logoff_time(sampass, logoff_time);
156 pdb_set_kickoff_time(sampass, kickoff_time);
157 pdb_set_pass_can_change_time(sampass, pass_can_change_time);
158 pdb_set_pass_must_change_time(sampass, pass_must_change_time);
159 pdb_set_pass_last_set_time(sampass, pass_last_set_time);
161 pdb_set_username (sampass, username);
162 pdb_set_domain (sampass, domain);
163 pdb_set_nt_username (sampass, nt_username);
164 pdb_set_fullname (sampass, fullname);
166 if (homedir) setflag = True;
169 homedir = strdup(lp_logon_home());
170 if(!homedir) { ret = False; goto done; }
171 standard_sub_advanced(-1, username, "", gid, username, homedir);
172 DEBUG(5,("Home directory set back to %s\n", homedir));
174 pdb_set_homedir(sampass, homedir, setflag);
176 if (dir_drive) setflag = True;
179 dir_drive = strdup(lp_logon_drive());
180 if(!dir_drive) { ret = False; goto done; }
181 standard_sub_advanced(-1, username, "", gid, username, dir_drive);
182 DEBUG(5,("Home directory set back to %s\n", dir_drive));
184 pdb_set_dir_drive(sampass, dir_drive, setflag);
186 if (logon_script) setflag = True;
189 logon_script = strdup(lp_logon_script());
190 if(!logon_script) { ret = False; goto done; }
191 standard_sub_advanced(-1, username, "", gid, username, logon_script);
192 DEBUG(5,("Home directory set back to %s\n", logon_script));
194 pdb_set_logon_script(sampass, logon_script, setflag);
196 if (profile_path) setflag = True;
199 profile_path = strdup(lp_logon_path());
200 if(!profile_path) { ret = False; goto done; }
201 standard_sub_advanced(-1, username, "", gid, username, profile_path);
202 DEBUG(5,("Home directory set back to %s\n", profile_path));
204 pdb_set_profile_path(sampass, profile_path, setflag);
206 pdb_set_acct_desc (sampass, acct_desc);
207 pdb_set_workstations (sampass, workstations);
208 pdb_set_munged_dial (sampass, munged_dial);
209 if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr)) {
213 if (!pdb_set_nt_passwd(sampass, nt_pw_ptr)) {
218 /*pdb_set_uid(sampass, uid);
219 pdb_set_gid(sampass, gid);*/
220 pdb_set_user_rid(sampass, user_rid);
221 pdb_set_group_rid(sampass, group_rid);
222 pdb_set_unknown_3(sampass, unknown_3);
223 pdb_set_hours_len(sampass, hours_len);
224 pdb_set_unknown_5(sampass, unknown_5);
225 pdb_set_unknown_6(sampass, unknown_6);
226 pdb_set_acct_ctrl(sampass, acct_ctrl);
227 pdb_set_logon_divs(sampass, logon_divs);
228 pdb_set_hours(sampass, hours);
234 SAFE_FREE(nt_username);
237 SAFE_FREE(dir_drive);
238 SAFE_FREE(logon_script);
239 SAFE_FREE(profile_path);
240 SAFE_FREE(acct_desc);
241 SAFE_FREE(workstations);
242 SAFE_FREE(munged_dial);
247 /**********************************************************************
248 Intialize a BYTE buffer from a SAM_ACCOUNT struct
249 *********************************************************************/
250 static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **buf,
251 const SAM_ACCOUNT *sampass, uint32 user_rid, uint32 group_rid)
255 /* times are stored as 32bit integer
256 take care on system with 64bit wide time_t
262 pass_can_change_time,
263 pass_must_change_time;
264 const char *username;
266 const char *nt_username;
267 const char *dir_drive;
268 const char *unknown_str;
269 const char *munged_dial;
270 const char *fullname;
272 const char *logon_script;
273 const char *profile_path;
274 const char *acct_desc;
275 const char *workstations;
276 uint32 username_len, domain_len, nt_username_len,
277 dir_drive_len, unknown_str_len, munged_dial_len,
278 fullname_len, homedir_len, logon_script_len,
279 profile_path_len, acct_desc_len, workstations_len;
283 uint32 lm_pw_len = 16;
284 uint32 nt_pw_len = 16;
286 /* do we have a valid SAM_ACCOUNT pointer? */
287 if (sampass == NULL) {
288 DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n"));
295 logon_time = (uint32)pdb_get_logon_time(sampass);
296 logoff_time = (uint32)pdb_get_logoff_time(sampass);
297 kickoff_time = (uint32)pdb_get_kickoff_time(sampass);
298 pass_can_change_time = (uint32)pdb_get_pass_can_change_time(sampass);
299 pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass);
300 pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass);
303 username = pdb_get_username(sampass);
304 if (username) username_len = strlen(username) +1;
305 else username_len = 0;
307 domain = pdb_get_domain(sampass);
308 if (domain) domain_len = strlen(domain) +1;
311 nt_username = pdb_get_nt_username(sampass);
312 if (nt_username) nt_username_len = strlen(nt_username) +1;
313 else nt_username_len = 0;
315 fullname = pdb_get_fullname(sampass);
316 if (fullname) fullname_len = strlen(fullname) +1;
317 else fullname_len = 0;
320 * Only updates fields which have been set (not defaults from smb.conf)
323 if (IS_SAM_SET(sampass, FLAG_SAM_DRIVE)) dir_drive = pdb_get_dirdrive(sampass);
324 else dir_drive = NULL;
325 if (dir_drive) dir_drive_len = strlen(dir_drive) +1;
326 else dir_drive_len = 0;
328 if (IS_SAM_SET(sampass, FLAG_SAM_SMBHOME)) homedir = pdb_get_homedir(sampass);
330 if (homedir) homedir_len = strlen(homedir) +1;
331 else homedir_len = 0;
333 if (IS_SAM_SET(sampass, FLAG_SAM_LOGONSCRIPT)) logon_script = pdb_get_logon_script(sampass);
334 else logon_script = NULL;
335 if (logon_script) logon_script_len = strlen(logon_script) +1;
336 else logon_script_len = 0;
338 if (IS_SAM_SET(sampass, FLAG_SAM_PROFILE)) profile_path = pdb_get_profile_path(sampass);
339 else profile_path = NULL;
340 if (profile_path) profile_path_len = strlen(profile_path) +1;
341 else profile_path_len = 0;
343 lm_pw = pdb_get_lanman_passwd(sampass);
344 if (!lm_pw) lm_pw_len = 0;
346 nt_pw = pdb_get_nt_passwd(sampass);
347 if (!nt_pw) nt_pw_len = 0;
349 acct_desc = pdb_get_acct_desc(sampass);
350 if (acct_desc) acct_desc_len = strlen(acct_desc) +1;
351 else acct_desc_len = 0;
353 workstations = pdb_get_workstations(sampass);
354 if (workstations) workstations_len = strlen(workstations) +1;
355 else workstations_len = 0;
360 munged_dial = pdb_get_munged_dial(sampass);
361 if (munged_dial) munged_dial_len = strlen(munged_dial) +1;
362 else munged_dial_len = 0;
364 /* one time to get the size needed */
365 len = tdb_pack(NULL, 0, TDB_FORMAT_STRING,
370 pass_can_change_time,
371 pass_must_change_time,
372 username_len, username,
374 nt_username_len, nt_username,
375 fullname_len, fullname,
376 homedir_len, homedir,
377 dir_drive_len, dir_drive,
378 logon_script_len, logon_script,
379 profile_path_len, profile_path,
380 acct_desc_len, acct_desc,
381 workstations_len, workstations,
382 unknown_str_len, unknown_str,
383 munged_dial_len, munged_dial,
388 pdb_get_acct_ctrl(sampass),
389 pdb_get_unknown3(sampass),
390 pdb_get_logon_divs(sampass),
391 pdb_get_hours_len(sampass),
392 MAX_HOURS_LEN, pdb_get_hours(sampass),
393 pdb_get_unknown5(sampass),
394 pdb_get_unknown6(sampass));
397 /* malloc the space needed */
398 if ( (*buf=(uint8*)malloc(len)) == NULL) {
399 DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n"));
403 /* now for the real call to tdb_pack() */
404 buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING,
409 pass_can_change_time,
410 pass_must_change_time,
411 username_len, username,
413 nt_username_len, nt_username,
414 fullname_len, fullname,
415 homedir_len, homedir,
416 dir_drive_len, dir_drive,
417 logon_script_len, logon_script,
418 profile_path_len, profile_path,
419 acct_desc_len, acct_desc,
420 workstations_len, workstations,
421 unknown_str_len, unknown_str,
422 munged_dial_len, munged_dial,
427 pdb_get_acct_ctrl(sampass),
428 pdb_get_unknown3(sampass),
429 pdb_get_logon_divs(sampass),
430 pdb_get_hours_len(sampass),
431 MAX_HOURS_LEN, pdb_get_hours(sampass),
432 pdb_get_unknown5(sampass),
433 pdb_get_unknown6(sampass));
436 /* check to make sure we got it correct */
438 DEBUG(0, ("init_buffer_from_sam: somthing odd is going on here: bufflen (%d) != len (%d) in tdb_pack operations!\n",
448 /***************************************************************
449 Open the TDB passwd database for SAM account enumeration.
450 ****************************************************************/
452 static BOOL tdbsam_setsampwent(struct pdb_context *context, BOOL update)
454 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
456 /* Open tdb passwd */
457 if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600)))
459 DEBUG(0, ("Unable to open/create TDB passwd\n"));
463 tdb_state->key = tdb_firstkey(tdb_state->passwd_tdb);
468 static void close_tdb(struct tdbsam_privates *tdb_state)
470 if (tdb_state->passwd_tdb) {
471 tdb_close(tdb_state->passwd_tdb);
472 tdb_state->passwd_tdb = NULL;
476 /***************************************************************
477 End enumeration of the TDB passwd list.
478 ****************************************************************/
480 static void tdbsam_endsampwent(struct pdb_context *context)
482 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
483 close_tdb(tdb_state);
485 DEBUG(7, ("endtdbpwent: closed sam database.\n"));
488 /*****************************************************************
489 Get one SAM_ACCOUNT from the TDB (next in line)
490 *****************************************************************/
492 static BOOL tdbsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user)
494 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
496 char *prefix = USERPREFIX;
497 int prefixlen = strlen (prefix);
501 DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n"));
505 /* skip all non-USER entries (eg. RIDs) */
506 while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen)))
507 /* increment to next in line */
508 tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key);
510 /* do we have an valid interation pointer? */
511 if(tdb_state->passwd_tdb == NULL) {
512 DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n"));
516 data = tdb_fetch(tdb_state->passwd_tdb, tdb_state->key);
518 DEBUG(5,("pdb_getsampwent: database entry not found.\n"));
522 /* unpack the buffer */
523 if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) {
524 DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
525 SAFE_FREE(data.dptr);
528 SAFE_FREE(data.dptr);
530 /* increment to next in line */
531 tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key);
536 /******************************************************************
537 Lookup a name in the SAM TDB
538 ******************************************************************/
540 static BOOL tdbsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname)
542 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
543 TDB_CONTEXT *pwd_tdb;
549 DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n"));
553 /* Data is stored in all lower-case */
554 unix_strlower(sname, -1, name, sizeof(name));
557 slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
559 key.dsize = strlen(keystr) + 1;
561 /* open the accounts TDB */
562 if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
563 DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location));
568 data = tdb_fetch(pwd_tdb, key);
570 DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n"));
571 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
572 DEBUGADD(5, (" Key: %s\n", keystr));
577 /* unpack the buffer */
578 if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) {
579 DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
580 SAFE_FREE(data.dptr);
584 SAFE_FREE(data.dptr);
586 /* no further use for database, close it now */
592 /***************************************************************************
594 **************************************************************************/
596 static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid)
598 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
599 TDB_CONTEXT *pwd_tdb;
605 DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n"));
610 slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
612 key.dsize = strlen (keystr) + 1;
614 /* open the accounts TDB */
615 if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
616 DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n"));
621 data = tdb_fetch (pwd_tdb, key);
623 DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n"));
624 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
629 fstrcpy (name, data.dptr);
630 SAFE_FREE(data.dptr);
634 return tdbsam_getsampwnam (context, user, name);
637 /***************************************************************************
639 ****************************************************************************/
641 static BOOL tdbsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass)
643 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
644 TDB_CONTEXT *pwd_tdb;
650 unix_strlower(pdb_get_username(sam_pass), -1, name, sizeof(name));
653 if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) {
654 DEBUG(0, ("Unable to open TDB passwd!"));
658 /* set the search key */
659 slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
661 key.dsize = strlen (keystr) + 1;
663 rid = pdb_get_user_rid(sam_pass);
665 /* it's outaa here! 8^) */
666 if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
667 DEBUG(5, ("Error deleting entry from tdb passwd database!\n"));
668 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
673 /* delete also the RID key */
675 /* set the search key */
676 slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
678 key.dsize = strlen (keystr) + 1;
680 /* it's outaa here! 8^) */
681 if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
682 DEBUG(5, ("Error deleting entry from tdb rid database!\n"));
683 DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
693 /***************************************************************************
695 ****************************************************************************/
697 static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpwd, int flag)
699 struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data;
700 TDB_CONTEXT *pwd_tdb = NULL;
710 /* invalidate the existing TDB iterator if it is open */
711 if (tdb_state->passwd_tdb) {
712 tdb_close(tdb_state->passwd_tdb);
713 tdb_state->passwd_tdb = NULL;
716 /* open the account TDB passwd*/
717 pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600);
720 DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location));
724 /* if we don't have a RID, then make them up. */
725 if (!(user_rid = pdb_get_user_rid(newpwd))) {
726 if (!tdb_state->permit_non_unix_accounts) {
727 DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd)));
731 user_rid = tdb_state->low_nua_rid;
732 tdb_ret = tdb_change_int32_atomic(pwd_tdb, "NUA_NEXT_RID", &user_rid, RID_MULTIPLIER);
740 if (!(group_rid = pdb_get_group_rid(newpwd))) {
741 if (!tdb_state->permit_non_unix_accounts) {
742 DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd)));
746 /* This seems like a good default choice for non-unix users */
747 group_rid = DOMAIN_GROUP_RID_USERS;
751 /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */
752 if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd, user_rid, group_rid)) == -1) {
753 DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n"));
759 unix_strlower(pdb_get_username(newpwd), -1, name, sizeof(name));
761 DEBUG(5, ("Storing %saccount %s with RID %d\n", flag == TDB_INSERT ? "(new) " : "", name, user_rid));
763 /* setup the USER index key */
764 slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
766 key.dsize = strlen (keystr) + 1;
768 /* add the account */
769 if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) {
770 DEBUG(0, ("Unable to modify passwd TDB!"));
771 DEBUGADD(0, (" Error: %s", tdb_errorstr(pwd_tdb)));
772 DEBUGADD(0, (" occured while storing the main record (%s)\n", keystr));
778 data.dsize = sizeof(fstring);
781 /* setup the RID index key */
782 slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, user_rid);
784 key.dsize = strlen (keystr) + 1;
786 /* add the reference */
787 if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) {
788 DEBUG(0, ("Unable to modify TDB passwd !"));
789 DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
790 DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr));
803 /***************************************************************************
804 Modifies an existing SAM_ACCOUNT
805 ****************************************************************************/
807 static BOOL tdbsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
809 return (tdb_update_sam(context, newpwd, TDB_MODIFY));
812 /***************************************************************************
813 Adds an existing SAM_ACCOUNT
814 ****************************************************************************/
816 static BOOL tdbsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
818 return (tdb_update_sam(context, newpwd, TDB_INSERT));
821 static void free_private_data(void **vp)
823 struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp;
824 close_tdb(*tdb_state);
827 /* No need to free any further, as it is talloc()ed */
831 NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
834 struct tdbsam_privates *tdb_state;
836 if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) {
840 (*pdb_method)->setsampwent = tdbsam_setsampwent;
841 (*pdb_method)->endsampwent = tdbsam_endsampwent;
842 (*pdb_method)->getsampwent = tdbsam_getsampwent;
843 (*pdb_method)->getsampwnam = tdbsam_getsampwnam;
844 (*pdb_method)->getsampwrid = tdbsam_getsampwrid;
845 (*pdb_method)->add_sam_account = tdbsam_add_sam_account;
846 (*pdb_method)->update_sam_account = tdbsam_update_sam_account;
847 (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account;
849 /* TODO: Setup private data and free */
851 tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates));
854 DEBUG(0, ("talloc() failed for tdbsam private_data!\n"));
855 return NT_STATUS_NO_MEMORY;
859 tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, location);
862 get_private_directory(tdbfile);
863 pstrcat (tdbfile, PASSDB_FILE_NAME);
864 tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile);
867 (*pdb_method)->private_data = tdb_state;
869 (*pdb_method)->free_private_data = free_private_data;
874 NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
877 struct tdbsam_privates *tdb_state;
878 uint32 low_nua_uid, high_nua_uid;
880 if (!NT_STATUS_IS_OK(nt_status = pdb_init_tdbsam(pdb_context, pdb_method, location))) {
884 tdb_state = (*pdb_method)->private_data;
886 tdb_state->permit_non_unix_accounts = True;
888 if (!lp_non_unix_account_range(&low_nua_uid, &high_nua_uid)) {
889 DEBUG(0, ("cannot use tdbsam_nua without 'non unix account range' in smb.conf!\n"));
890 return NT_STATUS_UNSUCCESSFUL;
893 tdb_state->low_nua_rid=pdb_uid_to_user_rid(low_nua_uid);
895 tdb_state->high_nua_rid=pdb_uid_to_user_rid(high_nua_uid);
903 NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
905 DEBUG(0, ("tdbsam not compiled in!\n"));
906 return NT_STATUS_UNSUCCESSFUL;
909 NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
911 DEBUG(0, ("tdbsam_nua not compiled in!\n"));
912 return NT_STATUS_UNSUCCESSFUL;