From 9fede0dc0dbad51528cd1384023d24549c3f0ba4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 13 Nov 2000 23:03:34 +0000 Subject: Large commit which restructures the local password storage API. Currently the only backend which works is smbpasswd (tdb, LDAP, and NIS+) are broken, but they were somewhat broken before. :) The following functions implement the storage manipulation interface /*The following definitions come from passdb/pdb_smbpasswd.c */ BOOL pdb_setsampwent (BOOL update); void pdb_endsampwent (void); SAM_ACCOUNT* pdb_getsampwent (void); SAM_ACCOUNT* pdb_getsampwnam (char *username); SAM_ACCOUNT* pdb_getsampwuid (uid_t uid); SAM_ACCOUNT* pdb_getsampwrid (uint32 rid); BOOL pdb_add_sam_account (SAM_ACCOUNT *sampass); BOOL pdb_update_sam_account (SAM_ACCOUNT *sampass, BOOL override); BOOL pdb_delete_sam_account (char* username); There is also a host of pdb_set..() and pdb_get..() functions for manipulating SAM_ACCOUNT struct members. Note that the struct passdb_ops {} has gone away. Also notice that struct smb_passwd (formally in smb.h) has been moved to passdb/pdb_smbpasswd.c and is not accessed outisde of static internal functions in this file. All local password searches should make use of the the SAM_ACCOUNT struct and the previously mentioned functions. I'll write some documentation for this later. The next step is to fix the TDB passdb backend, then work on spliting the backends out into share libraries, and finally get the LDAP backend going. What works and may not: o domain logons from Win9x works o domain logons from WinNT 4 works o user and group enumeration as implemented by Tim works o file and print access works o changing password from Win9x & NT ummm...i'll fix this tonight :) If I broke anything else, just yell and I'll fix it. I think it should be fairly quite. -- jerry (This used to be commit 0b92d0838ebdbe24f34f17e313ecbf61a0301389) --- source3/passdb/pdb_tdb.c | 600 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 600 insertions(+) create mode 100644 source3/passdb/pdb_tdb.c (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c new file mode 100644 index 0000000000..29f1b119ae --- /dev/null +++ b/source3/passdb/pdb_tdb.c @@ -0,0 +1,600 @@ +/* + * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup + * Copyright (C) Andrew Tridgell 1992-1998 + * Copyright (C) Simo Sorce 2000 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 675 + * Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +#ifdef WITH_TDBPWD + +#define lp_tdb_passwd_file lp_smb_passwd_file +#define tdb_writelock(ptr) +#define tdb_writeunlock(ptr) + +extern int DEBUGLEVEL; +extern pstring samlogon_user; +extern BOOL sam_logon_in_ssb; + +#if 0 /* GWC */ +struct tdb_sam_entry +{ + time_t logon_time; /* logon time */ + time_t logoff_time; /* logoff time */ + time_t kickoff_time; /* kickoff time */ + time_t pass_last_set_time; /* password last set time */ + time_t pass_can_change_time; /* password can change time */ + time_t pass_must_change_time; /* password must change time */ + + uid_t smb_userid; /* this is actually the unix uid_t */ + gid_t smb_grpid; /* this is actually the unix gid_t */ + uint32 user_rid; /* Primary User ID */ + uint32 group_rid; /* Primary Group ID */ + + char smb_passwd[33]; /* Null if no password */ + char smb_nt_passwd[33]; /* Null if no password */ + + uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */ + uint32 unknown_3; /* 0x00ff ffff */ + + uint16 logon_divs; /* 168 - number of hours in a week */ + uint32 hours_len; /* normally 21 bytes */ + uint8 hours[MAX_HOURS_LEN]; + + uint32 unknown_5; /* 0x0002 0000 */ + uint32 unknown_6; /* 0x0000 04ec */ + + /* relative pointers to dynamically allocated strings[] */ + int smb_name_offset; /* username string */ + int full_name_offset; /* user's full name string */ + int home_dir_offset; /* home directory string */ + int dir_drive_offset; /* home directory drive string */ + int logon_script_offset; /* logon script string */ + int profile_path_offset; /* profile path string */ + int acct_desc_offset; /* user description string */ + int workstations_offset; /* login from workstations string */ + int unknown_str_offset; /* don't know what this is, yet. */ + int munged_dial_offset; /* munged path name and dial-back tel number */ + + /* how to correctly declare this ?*/ + char strings[1]; +}; + +#endif + +struct tdb_enum_info +{ + TDB_CONTEXT *passwd_tdb; + TDB_DATA key; +}; + +static struct tdb_enum_info tdb_ent; + +/*************************************************************** + Start to enumerate the TDB passwd list. Returns a void pointer + to ensure no modification outside this module. +****************************************************************/ + +static void *startsamtdbpwent(BOOL update) +{ + /* Open tdb passwd */ + if (!(tdb_ent.passwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, update ? O_RDWR : O_RDONLY, 0600))) + { + DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); + if (!(tdb_ent.passwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + { + DEBUG(0, ("Unable to creat TDB passwd (smbpasswd.tdb) !!!")); + return NULL; + } + return &tdb_ent; + } + + tdb_ent.key = tdb_firstkey(tdb_ent.passwd_tdb); + return &tdb_ent; +} + +/*************************************************************** + End enumeration of the TDB passwd list. +****************************************************************/ + +static void endsamtdbpwent(void *vp) +{ + struct tdb_enum_info *p_ent = (struct tdb_enum_info *)vp; + + tdb_close(p_ent->passwd_tdb); + DEBUG(7, ("endtdbpwent: closed password file.\n")); +} + +static struct sam_passwd *getsamtdb21pwent(void *vp) +{ + static struct sam_passwd sam_entry; + static struct tdb_sam_entry *tdb_entry; + struct tdb_enum_info *p_ent = (struct tdb_enum_info *)vp; + TDB_DATA data; + + if(p_ent == NULL) { + DEBUG(0,("gettdbpwent: Bad TDB Context pointer.\n")); + return NULL; + } + + data = tdb_fetch (p_ent->passwd_tdb, p_ent->key); + if (!data.dptr) + { + DEBUG(5,("gettdbpwent: database entry not found.\n")); + return NULL; + } + + tdb_entry = (struct tdb_sam_entry *)(data.dptr); + + sam_entry.logon_time = tdb_entry->logon_time; + sam_entry.logoff_time = tdb_entry->logoff_time; + sam_entry.kickoff_time = tdb_entry->kickoff_time; + sam_entry.pass_last_set_time = tdb_entry->pass_last_set_time; + sam_entry.pass_can_change_time = tdb_entry->pass_can_change_time; + sam_entry.pass_must_change_time = tdb_entry->pass_must_change_time; + sam_entry.smb_name = tdb_entry->strings + tdb_entry->smb_name_offset; + sam_entry.full_name = tdb_entry->strings + tdb_entry->full_name_offset; + sam_entry.home_dir = tdb_entry->strings + tdb_entry->home_dir_offset; + sam_entry.dir_drive = tdb_entry->strings + tdb_entry->dir_drive_offset; + sam_entry.logon_script = tdb_entry->strings + tdb_entry->logon_script_offset; + sam_entry.profile_path = tdb_entry->strings + tdb_entry->profile_path_offset; + sam_entry.acct_desc = tdb_entry->strings + tdb_entry->acct_desc_offset; + sam_entry.workstations = tdb_entry->strings + tdb_entry->workstations_offset; + sam_entry.unknown_str = tdb_entry->strings + tdb_entry->unknown_str_offset; + sam_entry.munged_dial = tdb_entry->strings + tdb_entry->munged_dial_offset; + sam_entry.smb_userid = tdb_entry->smb_userid; + sam_entry.smb_grpid = tdb_entry->smb_grpid; + sam_entry.user_rid = tdb_entry->user_rid; + sam_entry.group_rid = tdb_entry->group_rid; + sam_entry.smb_passwd = tdb_entry->smb_passwd; + sam_entry.smb_nt_passwd = tdb_entry->smb_nt_passwd; + sam_entry.acct_ctrl = tdb_entry->acct_ctrl; + sam_entry.unknown_3 = tdb_entry->unknown_3; + sam_entry.logon_divs = tdb_entry->logon_divs; + sam_entry.hours_len = tdb_entry->hours_len; + memcpy (sam_entry.hours, tdb_entry->hours, MAX_HOURS_LEN); + sam_entry.unknown_5 = tdb_entry->unknown_5; + sam_entry.unknown_6 = tdb_entry->unknown_6; + + p_ent->key = tdb_nextkey (p_ent->passwd_tdb, p_ent->key); + + return &sam_entry; +} + +static BOOL del_samtdbpwd_entry(const char *name) +{ + TDB_CONTEXT *pwd_tdb; + TDB_DATA key; + fstring keystr; + + if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("Unable to open TDB passwd!")); + return False; + } + + slprintf(keystr, sizeof(keystr), "USER_%s", name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) + { + DEBUG(5, ("Error deleting entry from tdb database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); + tdb_close(pwd_tdb); + return False; + } + tdb_close(pwd_tdb); + return True; +} + +static BOOL mod_samtdb21pwd_entry(struct sam_passwd* newpwd, BOOL override) +{ + TDB_CONTEXT *pwd_tdb; + TDB_DATA key; + TDB_DATA data; + struct tdb_sam_entry *tdb_entry; + fstring keystr; + + int smb_name_len = (newpwd->smb_name) ? (strlen (newpwd->smb_name) + 1) : 0; + int full_name_len = (newpwd->full_name) ? (strlen (newpwd->full_name) + 1) : 0; + int home_dir_len = (newpwd->home_dir) ? (strlen (newpwd->home_dir) + 1) : 0; + int dir_drive_len = (newpwd->dir_drive) ? (strlen (newpwd->dir_drive) + 1) : 0; + int logon_script_len = (newpwd->logon_script) ? (strlen (newpwd->logon_script) + 1) : 0; + int profile_path_len = (newpwd->profile_path) ? (strlen (newpwd->profile_path) + 1) : 0; + int acct_desc_len = (newpwd->acct_desc) ? (strlen (newpwd->acct_desc) + 1) : 0; + int workstations_len = (newpwd->workstations) ? (strlen (newpwd->workstations) + 1) : 0; + int unknown_str_len = (newpwd->unknown_str) ? (strlen (newpwd->unknown_str) + 1) : 0; + int munged_dial_len = (newpwd->munged_dial) ? (strlen (newpwd->munged_dial) + 1) : 0; + + if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("Unable to open TDB passwd!")); + return False; + } + + data.dsize = sizeof (struct tdb_sam_entry) + + smb_name_len + + full_name_len + + home_dir_len + + dir_drive_len + + logon_script_len + + profile_path_len + + acct_desc_len + + workstations_len + + unknown_str_len + + munged_dial_len; + + tdb_entry = malloc (data.dsize); + data.dptr = tdb_entry; + memset (data.dptr, 0, data.dsize); + + tdb_entry->logon_time = newpwd->logon_time; + tdb_entry->logoff_time = newpwd->logoff_time; + tdb_entry->kickoff_time = newpwd->kickoff_time; + tdb_entry->pass_last_set_time = newpwd->pass_last_set_time; + tdb_entry->pass_can_change_time = newpwd->pass_can_change_time; + tdb_entry->pass_must_change_time = newpwd->pass_must_change_time; + tdb_entry->smb_userid = newpwd->smb_userid; + tdb_entry->smb_grpid = newpwd->smb_grpid; + tdb_entry->user_rid = newpwd->user_rid; + tdb_entry->group_rid = newpwd->group_rid; + memcpy (tdb_entry->smb_passwd, newpwd->smb_passwd, strlen (newpwd->smb_passwd) + 1); + memcpy (tdb_entry->smb_nt_passwd, newpwd->smb_nt_passwd, strlen (newpwd->smb_nt_passwd) + 1); + tdb_entry->acct_ctrl = newpwd->acct_ctrl; + tdb_entry->unknown_3 = newpwd->unknown_3; + tdb_entry->logon_divs = newpwd->logon_divs; + tdb_entry->hours_len = newpwd->hours_len; + memcpy (tdb_entry->hours, newpwd->hours, MAX_HOURS_LEN); + tdb_entry->unknown_5 = newpwd->unknown_5; + tdb_entry->unknown_6 = newpwd->unknown_6; + tdb_entry->smb_name_offset = 0; + tdb_entry->full_name_offset = smb_name_len; + tdb_entry->home_dir_offset = tdb_entry->full_name_offset + full_name_len; + tdb_entry->dir_drive_offset = tdb_entry->home_dir_offset + home_dir_len; + tdb_entry->logon_script_offset = tdb_entry->dir_drive_offset + dir_drive_len; + tdb_entry->profile_path_offset = tdb_entry->logon_script_offset + logon_script_len; + tdb_entry->acct_desc_offset = tdb_entry->profile_path_offset + profile_path_len; + tdb_entry->workstations_offset = tdb_entry->acct_desc_offset + acct_desc_len; + tdb_entry->unknown_str_offset = tdb_entry->workstations_offset + workstations_len; + tdb_entry->munged_dial_offset = tdb_entry->unknown_str_offset + unknown_str_len; + if (newpwd->smb_name) + memcpy (tdb_entry->strings + tdb_entry->smb_name_offset, newpwd->smb_name, smb_name_len); + if (newpwd->full_name) + memcpy (tdb_entry->strings + tdb_entry->full_name_offset, newpwd->full_name, full_name_len); + if (newpwd->home_dir) + memcpy (tdb_entry->strings + tdb_entry->home_dir_offset, newpwd->home_dir, home_dir_len); + if (newpwd->dir_drive) + memcpy (tdb_entry->strings + tdb_entry->dir_drive_offset, newpwd->dir_drive, dir_drive_len); + if (newpwd->logon_script) + memcpy (tdb_entry->strings + tdb_entry->logon_script_offset, newpwd->logon_script, logon_script_len); + if (newpwd->profile_path) + memcpy (tdb_entry->strings + tdb_entry->profile_path_offset, newpwd->profile_path, profile_path_len); + if (newpwd->acct_desc) + memcpy (tdb_entry->strings + tdb_entry->acct_desc_offset, newpwd->acct_desc, acct_desc_len); + if (newpwd->workstations) + memcpy (tdb_entry->strings + tdb_entry->workstations_offset, newpwd->workstations, workstations_len); + if (newpwd->unknown_str) + memcpy (tdb_entry->strings + tdb_entry->unknown_str_offset, newpwd->unknown_str, unknown_str_len); + if (newpwd->munged_dial) + memcpy (tdb_entry->strings + tdb_entry->munged_dial_offset, newpwd->munged_dial, munged_dial_len); + + slprintf(keystr, sizeof(keystr), "USER_%s", newpwd->smb_name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + tdb_writelock (pwd_tdb); + if (tdb_store (pwd_tdb, key, data, TDB_MODIFY) != TDB_SUCCESS) + { + DEBUG(0, ("Unable to modify TDB passwd!")); + DEBUGADD(0, (" Error: %s\n", tdb_error (pwd_tdb))); + tdb_writeunlock (pwd_tdb); + tdb_close (pwd_tdb); + return False; + } + + tdb_writeunlock (pwd_tdb); + tdb_close (pwd_tdb); + return True; +} + +static BOOL add_samtdb21pwd_entry(struct sam_passwd *newpwd) +{ + TDB_CONTEXT *pwd_tdb; + TDB_DATA key; + TDB_DATA data; + struct tdb_sam_entry *tdb_entry; + fstring keystr; + + int smb_name_len = (newpwd->smb_name) ? (strlen (newpwd->smb_name) + 1) : 1; + int full_name_len = (newpwd->full_name) ? (strlen (newpwd->full_name) + 1) : 1; + int home_dir_len = (newpwd->home_dir) ? (strlen (newpwd->home_dir) + 1) : 1; + int dir_drive_len = (newpwd->dir_drive) ? (strlen (newpwd->dir_drive) + 1) : 1; + int logon_script_len = (newpwd->logon_script) ? (strlen (newpwd->logon_script) + 1) : 1; + int profile_path_len = (newpwd->profile_path) ? (strlen (newpwd->profile_path) + 1) : 1; + int acct_desc_len = (newpwd->acct_desc) ? (strlen (newpwd->acct_desc) + 1) : 1; + int workstations_len = (newpwd->workstations) ? (strlen (newpwd->workstations) + 1) : 1; + int unknown_str_len = (newpwd->unknown_str) ? (strlen (newpwd->unknown_str) + 1) : 1; + int munged_dial_len = (newpwd->munged_dial) ? (strlen (newpwd->munged_dial) + 1) : 1; + + if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("Unable to open TDB passwd!")); + return False; + } + + data.dsize = sizeof (struct tdb_sam_entry) + + smb_name_len + + full_name_len + + home_dir_len + + dir_drive_len + + logon_script_len + + profile_path_len + + acct_desc_len + + workstations_len + + unknown_str_len + + munged_dial_len; + + tdb_entry = malloc (data.dsize); + data.dptr = tdb_entry; + memset (data.dptr, 0, data.dsize); + + tdb_entry->logon_time = newpwd->logon_time; + tdb_entry->logoff_time = newpwd->logoff_time; + tdb_entry->kickoff_time = newpwd->kickoff_time; + tdb_entry->pass_last_set_time = newpwd->pass_last_set_time; + tdb_entry->pass_can_change_time = newpwd->pass_can_change_time; + tdb_entry->pass_must_change_time = newpwd->pass_must_change_time; + tdb_entry->smb_userid = newpwd->smb_userid; + tdb_entry->smb_grpid = newpwd->smb_grpid; + tdb_entry->user_rid = newpwd->user_rid; + tdb_entry->group_rid = newpwd->group_rid; + memcpy (tdb_entry->smb_passwd, newpwd->smb_passwd, strlen (newpwd->smb_passwd) + 1); + memcpy (tdb_entry->smb_nt_passwd, newpwd->smb_nt_passwd, strlen (newpwd->smb_nt_passwd) + 1); + tdb_entry->acct_ctrl = newpwd->acct_ctrl; + tdb_entry->unknown_3 = newpwd->unknown_3; + tdb_entry->logon_divs = newpwd->logon_divs; + tdb_entry->hours_len = newpwd->hours_len; + memcpy (tdb_entry->hours, newpwd->hours, MAX_HOURS_LEN); + tdb_entry->unknown_5 = newpwd->unknown_5; + tdb_entry->unknown_6 = newpwd->unknown_6; + tdb_entry->smb_name_offset = 0; + tdb_entry->full_name_offset = smb_name_len; + tdb_entry->home_dir_offset = tdb_entry->full_name_offset + full_name_len; + tdb_entry->dir_drive_offset = tdb_entry->home_dir_offset + home_dir_len; + tdb_entry->logon_script_offset = tdb_entry->dir_drive_offset + dir_drive_len; + tdb_entry->profile_path_offset = tdb_entry->logon_script_offset + logon_script_len; + tdb_entry->acct_desc_offset = tdb_entry->profile_path_offset + profile_path_len; + tdb_entry->workstations_offset = tdb_entry->acct_desc_offset + acct_desc_len; + tdb_entry->unknown_str_offset = tdb_entry->workstations_offset + workstations_len; + tdb_entry->munged_dial_offset = tdb_entry->unknown_str_offset + unknown_str_len; + if (newpwd->smb_name) + memcpy (tdb_entry->strings + tdb_entry->smb_name_offset, newpwd->smb_name, smb_name_len); + if (newpwd->full_name) + memcpy (tdb_entry->strings + tdb_entry->full_name_offset, newpwd->full_name, full_name_len); + if (newpwd->home_dir) + memcpy (tdb_entry->strings + tdb_entry->home_dir_offset, newpwd->home_dir, home_dir_len); + if (newpwd->dir_drive) + memcpy (tdb_entry->strings + tdb_entry->dir_drive_offset, newpwd->dir_drive, dir_drive_len); + if (newpwd->logon_script) + memcpy (tdb_entry->strings + tdb_entry->logon_script_offset, newpwd->logon_script, logon_script_len); + if (newpwd->profile_path) + memcpy (tdb_entry->strings + tdb_entry->profile_path_offset, newpwd->profile_path, profile_path_len); + if (newpwd->acct_desc) + memcpy (tdb_entry->strings + tdb_entry->acct_desc_offset, newpwd->acct_desc, acct_desc_len); + if (newpwd->workstations) + memcpy (tdb_entry->strings + tdb_entry->workstations_offset, newpwd->workstations, workstations_len); + if (newpwd->unknown_str) + memcpy (tdb_entry->strings + tdb_entry->unknown_str_offset, newpwd->unknown_str, unknown_str_len); + if (newpwd->munged_dial) + memcpy (tdb_entry->strings + tdb_entry->munged_dial_offset, newpwd->munged_dial, munged_dial_len); + + slprintf(keystr, sizeof(keystr), "USER_%s", newpwd->smb_name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + tdb_writelock (pwd_tdb); + if (tdb_store (pwd_tdb, key, data, TDB_INSERT) != TDB_SUCCESS) + { + DEBUG(0, ("Unable to modify TDB passwd!")); + DEBUGADD(0, (" Error: %s\n", tdb_error (pwd_tdb))); + tdb_writeunlock (pwd_tdb); + tdb_close (pwd_tdb); + return False; + } + + tdb_writeunlock (pwd_tdb); + tdb_close (pwd_tdb); + return True; +} + +static struct sam_passwd *iterate_getsamtdb21pwrid(uint32 user_rid) +{ + struct sam_passwd *pwd = NULL; + void *fp = NULL; + + DEBUG(10, ("search by smb_userid: %x\n", (int)user_rid)); + + /* Open the smb password database - not for update. */ + fp = startsamtdbpwent(False); + + if (fp == NULL) + { + DEBUG(0, ("unable to open smb password database.\n")); + return NULL; + } + + while ((pwd = getsamtdb21pwent(fp)) != NULL && pwd->user_rid != user_rid); + + if (pwd != NULL) + { + DEBUG(10, ("found by user_rid: %x\n", (int)user_rid)); + } + + endsamtdbpwent(fp); + return pwd; +} + +static struct sam_passwd *getsamtdb21pwnam(char *name) +{ + static struct sam_passwd sam_entry; + static struct tdb_sam_entry *tdb_entry; + TDB_CONTEXT *pwd_tdb; + TDB_DATA data; + TDB_DATA key; + fstring keystr; + + if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDONLY, 0600))) + { + DEBUG(0, ("Unable to open TDB passwd!")); + return False; + } + + slprintf(keystr, sizeof(keystr), "USER_%s", name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + data = tdb_fetch (pwd_tdb, key); + if (!data.dptr) + { + DEBUG(5,("getsamtdbpwent: error fetching database.\n")); + DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); + tdb_close (pwd_tdb); + return NULL; + } + + tdb_entry = (struct tdb_sam_entry *)(data.dptr); + + sam_entry.logon_time = tdb_entry->logon_time; + sam_entry.logoff_time = tdb_entry->logoff_time; + sam_entry.kickoff_time = tdb_entry->kickoff_time; + sam_entry.pass_last_set_time = tdb_entry->pass_last_set_time; + sam_entry.pass_can_change_time = tdb_entry->pass_can_change_time; + sam_entry.pass_must_change_time = tdb_entry->pass_must_change_time; + sam_entry.smb_name = tdb_entry->strings + tdb_entry->smb_name_offset; + sam_entry.full_name = tdb_entry->strings + tdb_entry->full_name_offset; + sam_entry.home_dir = tdb_entry->strings + tdb_entry->home_dir_offset; + sam_entry.dir_drive = tdb_entry->strings + tdb_entry->dir_drive_offset; + sam_entry.logon_script = tdb_entry->strings + tdb_entry->logon_script_offset; + sam_entry.profile_path = tdb_entry->strings + tdb_entry->profile_path_offset; + sam_entry.acct_desc = tdb_entry->strings + tdb_entry->acct_desc_offset; + sam_entry.workstations = tdb_entry->strings + tdb_entry->workstations_offset; + sam_entry.unknown_str = tdb_entry->strings + tdb_entry->unknown_str_offset; + sam_entry.munged_dial = tdb_entry->strings + tdb_entry->munged_dial_offset; + sam_entry.smb_userid = tdb_entry->smb_userid; + sam_entry.smb_grpid = tdb_entry->smb_grpid; + sam_entry.user_rid = tdb_entry->user_rid; + sam_entry.group_rid = tdb_entry->group_rid; + sam_entry.smb_passwd = tdb_entry->smb_passwd; + sam_entry.smb_nt_passwd = tdb_entry->smb_nt_passwd; + sam_entry.acct_ctrl = tdb_entry->acct_ctrl; + sam_entry.unknown_3 = tdb_entry->unknown_3; + sam_entry.logon_divs = tdb_entry->logon_divs; + sam_entry.hours_len = tdb_entry->hours_len; + memcpy (sam_entry.hours, tdb_entry->hours, MAX_HOURS_LEN); + sam_entry.unknown_5 = tdb_entry->unknown_5; + sam_entry.unknown_6 = tdb_entry->unknown_6; + + tdb_close (pwd_tdb); + return &sam_entry; +} + +static SMB_BIG_UINT getsamtdbpwpos(void *vp) +{ + return (SMB_BIG_UINT)0; +} + +static BOOL setsamtdbpwpos(void *vp, SMB_BIG_UINT tok) +{ + return False; +} + +static struct smb_passwd *getsamtdbpwent(void *vp) +{ + return pdb_sam_to_smb(getsamtdb21pwent(vp)); +} + +static BOOL add_samtdbpwd_entry(struct smb_passwd *newpwd) +{ + return add_samtdb21pwd_entry(pdb_smb_to_sam(newpwd)); +} + +static BOOL mod_samtdbpwd_entry(struct smb_passwd* pwd, BOOL override) +{ + return mod_samtdb21pwd_entry(pdb_smb_to_sam(pwd), override); +} + +static struct sam_disp_info *getsamtdbdispnam(char *name) +{ + return pdb_sam_to_dispinfo(getsam21pwnam(name)); +} + +static struct sam_disp_info *getsamtdbdisprid(uint32 rid) +{ + return pdb_sam_to_dispinfo(getsam21pwrid(rid)); +} + +static struct sam_disp_info *getsamtdbdispent(void *vp) +{ + return pdb_sam_to_dispinfo(getsam21pwent(vp)); +} + +static struct smb_passwd *iterate_getsamtdbpwrid(uint32 user_rid) +{ + return pdb_sam_to_smb(iterate_getsamtdb21pwrid(user_rid)); +} + +static struct smb_passwd *getsamtdbpwnam(char *name) +{ + return pdb_sam_to_smb(getsamtdb21pwnam(name)); +} + +static struct passdb_ops tdb_ops = { + startsamtdbpwent, + endsamtdbpwent, + getsamtdbpwpos, + setsamtdbpwpos, + getsamtdbpwnam, + iterate_getsmbpwuid, /* In passdb.c */ + iterate_getsamtdbpwrid, + getsamtdbpwent, + add_samtdbpwd_entry, + mod_samtdbpwd_entry, + del_samtdbpwd_entry, + getsamtdb21pwent, + getsamtdb21pwnam, + + /* TODO change get username from uid and then use + getsamtdb21pwnam */ + iterate_getsam21pwuid, + + iterate_getsamtdb21pwrid, + add_samtdb21pwd_entry, + mod_samtdb21pwd_entry, + getsamtdbdispnam, + getsamtdbdisprid, + getsamtdbdispent +}; + +struct passdb_ops *tdb_initialize_password_db(void) +{ + return &tdb_ops; +} + +#else + /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */ + void samtdb_dummy_function(void) { } /* stop some compilers complaining */ +#endif /* WITH_TDBPWD */ -- cgit From 0dcbafe2b97035df779f2e0742a130c4c79e3241 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 21 Nov 2000 05:55:16 +0000 Subject: Another large patch for the passdb rewrite. o added BOOL own_memory flag in SAM_ACCOUNT so we could use static memory for string pointer assignment or allocate a new string o added a reference TDB passdb backend. This is only a reference and should not be used in production because - RID's are generated using the same algorithm as with smbpasswd - a TDB can only have one key (w/o getting into problems) and we need three. Therefore the pdb_sam-getpwuid() and pdb_getsampwrid() functions are interative searches :-( we need transaction support, multiple indexes, and a nice open source DBM. The Berkeley DB (from sleepycat.com seems to fit this criteria now) o added a new parameter "private dir" as many places in the code were using lp_smb_passwd_file() and chopping off the filename part. This makes more sense to me and I will docuement it in the man pages o Ran through Insure-lite and corrected memory leaks. Need for a public flogging this time Jeremy (-: -- jerry (This used to be commit 4792029a2991bd84251d152a62b1033dec62cee2) --- source3/passdb/pdb_tdb.c | 1015 +++++++++++++++++++++++----------------------- 1 file changed, 512 insertions(+), 503 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 29f1b119ae..e997d6c318 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -22,577 +22,586 @@ #ifdef WITH_TDBPWD -#define lp_tdb_passwd_file lp_smb_passwd_file -#define tdb_writelock(ptr) -#define tdb_writeunlock(ptr) +#define TDB_FORMAT_STRING "ddddddfffPPfPPPPffddBBwdwdBdd" +#define USERPREFIX "USER_" -extern int DEBUGLEVEL; -extern pstring samlogon_user; -extern BOOL sam_logon_in_ssb; +extern int DEBUGLEVEL; +extern pstring samlogon_user; +extern BOOL sam_logon_in_ssb; -#if 0 /* GWC */ -struct tdb_sam_entry + +struct tdb_enum_info { - time_t logon_time; /* logon time */ - time_t logoff_time; /* logoff time */ - time_t kickoff_time; /* kickoff time */ - time_t pass_last_set_time; /* password last set time */ - time_t pass_can_change_time; /* password can change time */ - time_t pass_must_change_time; /* password must change time */ - - uid_t smb_userid; /* this is actually the unix uid_t */ - gid_t smb_grpid; /* this is actually the unix gid_t */ - uint32 user_rid; /* Primary User ID */ - uint32 group_rid; /* Primary Group ID */ - - char smb_passwd[33]; /* Null if no password */ - char smb_nt_passwd[33]; /* Null if no password */ - - uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */ - uint32 unknown_3; /* 0x00ff ffff */ - - uint16 logon_divs; /* 168 - number of hours in a week */ - uint32 hours_len; /* normally 21 bytes */ - uint8 hours[MAX_HOURS_LEN]; - - uint32 unknown_5; /* 0x0002 0000 */ - uint32 unknown_6; /* 0x0000 04ec */ - - /* relative pointers to dynamically allocated strings[] */ - int smb_name_offset; /* username string */ - int full_name_offset; /* user's full name string */ - int home_dir_offset; /* home directory string */ - int dir_drive_offset; /* home directory drive string */ - int logon_script_offset; /* logon script string */ - int profile_path_offset; /* profile path string */ - int acct_desc_offset; /* user description string */ - int workstations_offset; /* login from workstations string */ - int unknown_str_offset; /* don't know what this is, yet. */ - int munged_dial_offset; /* munged path name and dial-back tel number */ - - /* how to correctly declare this ?*/ - char strings[1]; + TDB_CONTEXT *passwd_tdb; + TDB_DATA key; }; -#endif +static struct tdb_enum_info global_tdb_ent; +static SAM_ACCOUNT global_sam_pass; -struct tdb_enum_info +/********************************************************************** + Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len + *********************************************************************/ +static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, BYTE *buf, + uint32 buflen) { - TDB_CONTEXT *passwd_tdb; - TDB_DATA key; -}; + static fstring username, + domain, + nt_username, + dir_drive, + unknown_str, + munged_dial; + static pstring full_name, + home_dir, + logon_script, + profile_path, + acct_desc, + workstations; + static BYTE *lm_pw_ptr, + *nt_pw_ptr, + lm_pw[16], + nt_pw[16]; + uint32 len = 0; + uint32 lmpwlen, ntpwlen, hourslen; + + /* unpack the buffer into variables */ + len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, + &sampass->logon_time, + &sampass->logoff_time, + &sampass->kickoff_time, + &sampass->pass_last_set_time, + &sampass->pass_can_change_time, + &sampass->pass_must_change_time, + username, + domain, + nt_username, + full_name, + home_dir, + dir_drive, + logon_script, + profile_path, + acct_desc, + workstations, + unknown_str, + munged_dial, + &sampass->user_rid, + &sampass->group_rid, + &lmpwlen, &lm_pw_ptr, + &ntpwlen, &nt_pw_ptr, + &sampass->acct_ctrl, + &sampass->unknown_3, + &sampass->logon_divs, + &sampass->hours_len, + &hourslen, &sampass->hours, + &sampass->unknown_5, + &sampass->unknown_6); + + if (len == -1) + return False; + + /* + * We have to copy the password hashes into static memory + * and free the memory allocated by tdb_unpack. This is because + * the sampass->own_memory flag is for all pointer members. + * The remaining members are using static memory and so + * the password hashes must as well. --jerry + */ + if (lm_pw_ptr) + { + memcpy(lm_pw, lm_pw_ptr, 16); + free (lm_pw_ptr); + } + if (nt_pw_ptr) + { + memcpy(nt_pw, nt_pw_ptr, 16); + free (nt_pw_ptr); + } + + /* using static memory for strings */ + pdb_set_mem_ownership(sampass, False); + + pdb_set_username (sampass, username); + pdb_set_domain (sampass, domain); + pdb_set_nt_username (sampass, nt_username); + pdb_set_fullname (sampass, full_name); + pdb_set_homedir (sampass, home_dir); + pdb_set_dir_drive (sampass, dir_drive); + pdb_set_logon_script (sampass, logon_script); + pdb_set_profile_path (sampass, profile_path); + pdb_set_acct_desc (sampass, acct_desc); + pdb_set_workstations (sampass, workstations); + pdb_set_munged_dial (sampass, munged_dial); + pdb_set_lanman_passwd(sampass, lm_pw); + pdb_set_nt_passwd (sampass, nt_pw); + + return True; +} + +/********************************************************************** + Intialize a BYTE buffer from a SAM_ACCOUNT struct + *********************************************************************/ +static uint32 init_buffer_from_sam (BYTE **buf, SAM_ACCOUNT *sampass) +{ + size_t len, buflen; + + fstring username, + domain, + nt_username, + dir_drive, + unknown_str, + munged_dial; + pstring full_name, + home_dir, + logon_script, + profile_path, + acct_desc, + workstations; + BYTE lm_pw[16], + nt_pw[16]; + char null_pw[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + + /* do we have a valid SAM_ACCOUNT pointer? */ + if (sampass == NULL) + return -1; + + *buf = NULL; + buflen = 0; + + fstrcpy(username, sampass->username); + fstrcpy(domain, sampass->domain); + fstrcpy(nt_username, sampass->nt_username); + fstrcpy(dir_drive, sampass->dir_drive); + fstrcpy(unknown_str, sampass->unknown_str); + fstrcpy(munged_dial, sampass->munged_dial); + + pstrcpy(full_name, sampass->full_name); + pstrcpy(home_dir, sampass->home_dir); + pstrcpy(logon_script, sampass->logon_script); + pstrcpy(profile_path, sampass->profile_path); + pstrcpy(acct_desc, sampass->acct_desc); + pstrcpy(workstations, sampass->workstations); + + if (sampass->lm_pw) + memcpy(lm_pw, sampass->lm_pw, 16); + else + pdb_gethexpwd (null_pw, lm_pw); + + if (sampass->nt_pw) + memcpy(nt_pw, sampass->nt_pw, 16); + else + pdb_gethexpwd (null_pw, nt_pw); + + + /* one time to get the size needed */ + len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, + sampass->logon_time, + sampass->logoff_time, + sampass->kickoff_time, + sampass->pass_last_set_time, + sampass->pass_can_change_time, + sampass->pass_must_change_time, + username, + domain, + nt_username, + full_name, + home_dir, + dir_drive, + logon_script, + profile_path, + acct_desc, + workstations, + unknown_str, + munged_dial, + sampass->user_rid, + sampass->group_rid, + 16, lm_pw, + 16, nt_pw, + sampass->acct_ctrl, + sampass->unknown_3, + sampass->logon_divs, + sampass->hours_len, + MAX_HOURS_LEN, sampass->hours, + sampass->unknown_5, + sampass->unknown_6); + + + /* malloc the space needed */ + if ( (*buf=(BYTE*)malloc(len)) == NULL) + { + DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n")); + return (-1); + } + + /* now for the real call to tdb_pack() */ + /* one time to get the size needed */ + buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING, + sampass->logon_time, + sampass->logoff_time, + sampass->kickoff_time, + sampass->pass_last_set_time, + sampass->pass_can_change_time, + sampass->pass_must_change_time, + username, + domain, + nt_username, + full_name, + home_dir, + dir_drive, + logon_script, + profile_path, + acct_desc, + workstations, + unknown_str, + munged_dial, + sampass->user_rid, + sampass->group_rid, + 16, lm_pw, + 16, nt_pw, + sampass->acct_ctrl, + sampass->unknown_3, + sampass->logon_divs, + sampass->hours_len, + MAX_HOURS_LEN, sampass->hours, + sampass->unknown_5, + sampass->unknown_6); + + + /* check to make sure we got it correct */ + if (buflen != len) + { + /* error */ + free (*buf); + return (-1); + } -static struct tdb_enum_info tdb_ent; + return (buflen); +} /*************************************************************** - Start to enumerate the TDB passwd list. Returns a void pointer - to ensure no modification outside this module. + Open the TDB account SAM fo renumeration. ****************************************************************/ - -static void *startsamtdbpwent(BOOL update) +BOOL pdb_setsampwent(BOOL update) { + pstring tdbfile; + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/passdb.tdb"); + /* Open tdb passwd */ - if (!(tdb_ent.passwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, update ? O_RDWR : O_RDONLY, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open(tdbfile, 0, 0, update ? O_RDWR : O_RDONLY, 0600))) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(tdb_ent.passwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) { - DEBUG(0, ("Unable to creat TDB passwd (smbpasswd.tdb) !!!")); - return NULL; + DEBUG(0, ("Unable to create TDB passwd (smbpasswd.tdb) !!!")); + return False; } - return &tdb_ent; } - tdb_ent.key = tdb_firstkey(tdb_ent.passwd_tdb); - return &tdb_ent; + global_tdb_ent.key = tdb_firstkey(global_tdb_ent.passwd_tdb); + + return True; } /*************************************************************** End enumeration of the TDB passwd list. ****************************************************************/ - -static void endsamtdbpwent(void *vp) +void pdb_endsampwent(void) { - struct tdb_enum_info *p_ent = (struct tdb_enum_info *)vp; - - tdb_close(p_ent->passwd_tdb); - DEBUG(7, ("endtdbpwent: closed password file.\n")); + if (global_tdb_ent.passwd_tdb) + { + tdb_close(global_tdb_ent.passwd_tdb); + global_tdb_ent.passwd_tdb = NULL; + } + + DEBUG(7, ("endtdbpwent: closed password file.\n")); } -static struct sam_passwd *getsamtdb21pwent(void *vp) -{ - static struct sam_passwd sam_entry; - static struct tdb_sam_entry *tdb_entry; - struct tdb_enum_info *p_ent = (struct tdb_enum_info *)vp; - TDB_DATA data; - - if(p_ent == NULL) { - DEBUG(0,("gettdbpwent: Bad TDB Context pointer.\n")); - return NULL; - } - - data = tdb_fetch (p_ent->passwd_tdb, p_ent->key); - if (!data.dptr) - { - DEBUG(5,("gettdbpwent: database entry not found.\n")); - return NULL; - } - - tdb_entry = (struct tdb_sam_entry *)(data.dptr); - - sam_entry.logon_time = tdb_entry->logon_time; - sam_entry.logoff_time = tdb_entry->logoff_time; - sam_entry.kickoff_time = tdb_entry->kickoff_time; - sam_entry.pass_last_set_time = tdb_entry->pass_last_set_time; - sam_entry.pass_can_change_time = tdb_entry->pass_can_change_time; - sam_entry.pass_must_change_time = tdb_entry->pass_must_change_time; - sam_entry.smb_name = tdb_entry->strings + tdb_entry->smb_name_offset; - sam_entry.full_name = tdb_entry->strings + tdb_entry->full_name_offset; - sam_entry.home_dir = tdb_entry->strings + tdb_entry->home_dir_offset; - sam_entry.dir_drive = tdb_entry->strings + tdb_entry->dir_drive_offset; - sam_entry.logon_script = tdb_entry->strings + tdb_entry->logon_script_offset; - sam_entry.profile_path = tdb_entry->strings + tdb_entry->profile_path_offset; - sam_entry.acct_desc = tdb_entry->strings + tdb_entry->acct_desc_offset; - sam_entry.workstations = tdb_entry->strings + tdb_entry->workstations_offset; - sam_entry.unknown_str = tdb_entry->strings + tdb_entry->unknown_str_offset; - sam_entry.munged_dial = tdb_entry->strings + tdb_entry->munged_dial_offset; - sam_entry.smb_userid = tdb_entry->smb_userid; - sam_entry.smb_grpid = tdb_entry->smb_grpid; - sam_entry.user_rid = tdb_entry->user_rid; - sam_entry.group_rid = tdb_entry->group_rid; - sam_entry.smb_passwd = tdb_entry->smb_passwd; - sam_entry.smb_nt_passwd = tdb_entry->smb_nt_passwd; - sam_entry.acct_ctrl = tdb_entry->acct_ctrl; - sam_entry.unknown_3 = tdb_entry->unknown_3; - sam_entry.logon_divs = tdb_entry->logon_divs; - sam_entry.hours_len = tdb_entry->hours_len; - memcpy (sam_entry.hours, tdb_entry->hours, MAX_HOURS_LEN); - sam_entry.unknown_5 = tdb_entry->unknown_5; - sam_entry.unknown_6 = tdb_entry->unknown_6; - - p_ent->key = tdb_nextkey (p_ent->passwd_tdb, p_ent->key); - - return &sam_entry; -} -static BOOL del_samtdbpwd_entry(const char *name) +/***************************************************************** + Get one SAM_ACCOUNT from the TDB (next in line) +*****************************************************************/ +SAM_ACCOUNT* pdb_getsampwent(void) { - TDB_CONTEXT *pwd_tdb; - TDB_DATA key; - fstring keystr; - - if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("Unable to open TDB passwd!")); - return False; - } - - slprintf(keystr, sizeof(keystr), "USER_%s", name); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) - { - DEBUG(5, ("Error deleting entry from tdb database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); - tdb_close(pwd_tdb); - return False; - } - tdb_close(pwd_tdb); - return True; -} + TDB_DATA data; + struct passwd *pw; -static BOOL mod_samtdb21pwd_entry(struct sam_passwd* newpwd, BOOL override) -{ - TDB_CONTEXT *pwd_tdb; - TDB_DATA key; - TDB_DATA data; - struct tdb_sam_entry *tdb_entry; - fstring keystr; - - int smb_name_len = (newpwd->smb_name) ? (strlen (newpwd->smb_name) + 1) : 0; - int full_name_len = (newpwd->full_name) ? (strlen (newpwd->full_name) + 1) : 0; - int home_dir_len = (newpwd->home_dir) ? (strlen (newpwd->home_dir) + 1) : 0; - int dir_drive_len = (newpwd->dir_drive) ? (strlen (newpwd->dir_drive) + 1) : 0; - int logon_script_len = (newpwd->logon_script) ? (strlen (newpwd->logon_script) + 1) : 0; - int profile_path_len = (newpwd->profile_path) ? (strlen (newpwd->profile_path) + 1) : 0; - int acct_desc_len = (newpwd->acct_desc) ? (strlen (newpwd->acct_desc) + 1) : 0; - int workstations_len = (newpwd->workstations) ? (strlen (newpwd->workstations) + 1) : 0; - int unknown_str_len = (newpwd->unknown_str) ? (strlen (newpwd->unknown_str) + 1) : 0; - int munged_dial_len = (newpwd->munged_dial) ? (strlen (newpwd->munged_dial) + 1) : 0; - - if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("Unable to open TDB passwd!")); - return False; - } - - data.dsize = sizeof (struct tdb_sam_entry) + - smb_name_len + - full_name_len + - home_dir_len + - dir_drive_len + - logon_script_len + - profile_path_len + - acct_desc_len + - workstations_len + - unknown_str_len + - munged_dial_len; - - tdb_entry = malloc (data.dsize); - data.dptr = tdb_entry; - memset (data.dptr, 0, data.dsize); - - tdb_entry->logon_time = newpwd->logon_time; - tdb_entry->logoff_time = newpwd->logoff_time; - tdb_entry->kickoff_time = newpwd->kickoff_time; - tdb_entry->pass_last_set_time = newpwd->pass_last_set_time; - tdb_entry->pass_can_change_time = newpwd->pass_can_change_time; - tdb_entry->pass_must_change_time = newpwd->pass_must_change_time; - tdb_entry->smb_userid = newpwd->smb_userid; - tdb_entry->smb_grpid = newpwd->smb_grpid; - tdb_entry->user_rid = newpwd->user_rid; - tdb_entry->group_rid = newpwd->group_rid; - memcpy (tdb_entry->smb_passwd, newpwd->smb_passwd, strlen (newpwd->smb_passwd) + 1); - memcpy (tdb_entry->smb_nt_passwd, newpwd->smb_nt_passwd, strlen (newpwd->smb_nt_passwd) + 1); - tdb_entry->acct_ctrl = newpwd->acct_ctrl; - tdb_entry->unknown_3 = newpwd->unknown_3; - tdb_entry->logon_divs = newpwd->logon_divs; - tdb_entry->hours_len = newpwd->hours_len; - memcpy (tdb_entry->hours, newpwd->hours, MAX_HOURS_LEN); - tdb_entry->unknown_5 = newpwd->unknown_5; - tdb_entry->unknown_6 = newpwd->unknown_6; - tdb_entry->smb_name_offset = 0; - tdb_entry->full_name_offset = smb_name_len; - tdb_entry->home_dir_offset = tdb_entry->full_name_offset + full_name_len; - tdb_entry->dir_drive_offset = tdb_entry->home_dir_offset + home_dir_len; - tdb_entry->logon_script_offset = tdb_entry->dir_drive_offset + dir_drive_len; - tdb_entry->profile_path_offset = tdb_entry->logon_script_offset + logon_script_len; - tdb_entry->acct_desc_offset = tdb_entry->profile_path_offset + profile_path_len; - tdb_entry->workstations_offset = tdb_entry->acct_desc_offset + acct_desc_len; - tdb_entry->unknown_str_offset = tdb_entry->workstations_offset + workstations_len; - tdb_entry->munged_dial_offset = tdb_entry->unknown_str_offset + unknown_str_len; - if (newpwd->smb_name) - memcpy (tdb_entry->strings + tdb_entry->smb_name_offset, newpwd->smb_name, smb_name_len); - if (newpwd->full_name) - memcpy (tdb_entry->strings + tdb_entry->full_name_offset, newpwd->full_name, full_name_len); - if (newpwd->home_dir) - memcpy (tdb_entry->strings + tdb_entry->home_dir_offset, newpwd->home_dir, home_dir_len); - if (newpwd->dir_drive) - memcpy (tdb_entry->strings + tdb_entry->dir_drive_offset, newpwd->dir_drive, dir_drive_len); - if (newpwd->logon_script) - memcpy (tdb_entry->strings + tdb_entry->logon_script_offset, newpwd->logon_script, logon_script_len); - if (newpwd->profile_path) - memcpy (tdb_entry->strings + tdb_entry->profile_path_offset, newpwd->profile_path, profile_path_len); - if (newpwd->acct_desc) - memcpy (tdb_entry->strings + tdb_entry->acct_desc_offset, newpwd->acct_desc, acct_desc_len); - if (newpwd->workstations) - memcpy (tdb_entry->strings + tdb_entry->workstations_offset, newpwd->workstations, workstations_len); - if (newpwd->unknown_str) - memcpy (tdb_entry->strings + tdb_entry->unknown_str_offset, newpwd->unknown_str, unknown_str_len); - if (newpwd->munged_dial) - memcpy (tdb_entry->strings + tdb_entry->munged_dial_offset, newpwd->munged_dial, munged_dial_len); - - slprintf(keystr, sizeof(keystr), "USER_%s", newpwd->smb_name); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; - - tdb_writelock (pwd_tdb); - if (tdb_store (pwd_tdb, key, data, TDB_MODIFY) != TDB_SUCCESS) - { - DEBUG(0, ("Unable to modify TDB passwd!")); - DEBUGADD(0, (" Error: %s\n", tdb_error (pwd_tdb))); - tdb_writeunlock (pwd_tdb); - tdb_close (pwd_tdb); - return False; - } - - tdb_writeunlock (pwd_tdb); - tdb_close (pwd_tdb); - return True; -} + /* do we have an valid interation pointer? */ + if(global_tdb_ent.passwd_tdb == NULL) + { + DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); + return NULL; + } -static BOOL add_samtdb21pwd_entry(struct sam_passwd *newpwd) -{ - TDB_CONTEXT *pwd_tdb; - TDB_DATA key; - TDB_DATA data; - struct tdb_sam_entry *tdb_entry; - fstring keystr; - - int smb_name_len = (newpwd->smb_name) ? (strlen (newpwd->smb_name) + 1) : 1; - int full_name_len = (newpwd->full_name) ? (strlen (newpwd->full_name) + 1) : 1; - int home_dir_len = (newpwd->home_dir) ? (strlen (newpwd->home_dir) + 1) : 1; - int dir_drive_len = (newpwd->dir_drive) ? (strlen (newpwd->dir_drive) + 1) : 1; - int logon_script_len = (newpwd->logon_script) ? (strlen (newpwd->logon_script) + 1) : 1; - int profile_path_len = (newpwd->profile_path) ? (strlen (newpwd->profile_path) + 1) : 1; - int acct_desc_len = (newpwd->acct_desc) ? (strlen (newpwd->acct_desc) + 1) : 1; - int workstations_len = (newpwd->workstations) ? (strlen (newpwd->workstations) + 1) : 1; - int unknown_str_len = (newpwd->unknown_str) ? (strlen (newpwd->unknown_str) + 1) : 1; - int munged_dial_len = (newpwd->munged_dial) ? (strlen (newpwd->munged_dial) + 1) : 1; - - if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("Unable to open TDB passwd!")); - return False; - } - - data.dsize = sizeof (struct tdb_sam_entry) + - smb_name_len + - full_name_len + - home_dir_len + - dir_drive_len + - logon_script_len + - profile_path_len + - acct_desc_len + - workstations_len + - unknown_str_len + - munged_dial_len; - - tdb_entry = malloc (data.dsize); - data.dptr = tdb_entry; - memset (data.dptr, 0, data.dsize); - - tdb_entry->logon_time = newpwd->logon_time; - tdb_entry->logoff_time = newpwd->logoff_time; - tdb_entry->kickoff_time = newpwd->kickoff_time; - tdb_entry->pass_last_set_time = newpwd->pass_last_set_time; - tdb_entry->pass_can_change_time = newpwd->pass_can_change_time; - tdb_entry->pass_must_change_time = newpwd->pass_must_change_time; - tdb_entry->smb_userid = newpwd->smb_userid; - tdb_entry->smb_grpid = newpwd->smb_grpid; - tdb_entry->user_rid = newpwd->user_rid; - tdb_entry->group_rid = newpwd->group_rid; - memcpy (tdb_entry->smb_passwd, newpwd->smb_passwd, strlen (newpwd->smb_passwd) + 1); - memcpy (tdb_entry->smb_nt_passwd, newpwd->smb_nt_passwd, strlen (newpwd->smb_nt_passwd) + 1); - tdb_entry->acct_ctrl = newpwd->acct_ctrl; - tdb_entry->unknown_3 = newpwd->unknown_3; - tdb_entry->logon_divs = newpwd->logon_divs; - tdb_entry->hours_len = newpwd->hours_len; - memcpy (tdb_entry->hours, newpwd->hours, MAX_HOURS_LEN); - tdb_entry->unknown_5 = newpwd->unknown_5; - tdb_entry->unknown_6 = newpwd->unknown_6; - tdb_entry->smb_name_offset = 0; - tdb_entry->full_name_offset = smb_name_len; - tdb_entry->home_dir_offset = tdb_entry->full_name_offset + full_name_len; - tdb_entry->dir_drive_offset = tdb_entry->home_dir_offset + home_dir_len; - tdb_entry->logon_script_offset = tdb_entry->dir_drive_offset + dir_drive_len; - tdb_entry->profile_path_offset = tdb_entry->logon_script_offset + logon_script_len; - tdb_entry->acct_desc_offset = tdb_entry->profile_path_offset + profile_path_len; - tdb_entry->workstations_offset = tdb_entry->acct_desc_offset + acct_desc_len; - tdb_entry->unknown_str_offset = tdb_entry->workstations_offset + workstations_len; - tdb_entry->munged_dial_offset = tdb_entry->unknown_str_offset + unknown_str_len; - if (newpwd->smb_name) - memcpy (tdb_entry->strings + tdb_entry->smb_name_offset, newpwd->smb_name, smb_name_len); - if (newpwd->full_name) - memcpy (tdb_entry->strings + tdb_entry->full_name_offset, newpwd->full_name, full_name_len); - if (newpwd->home_dir) - memcpy (tdb_entry->strings + tdb_entry->home_dir_offset, newpwd->home_dir, home_dir_len); - if (newpwd->dir_drive) - memcpy (tdb_entry->strings + tdb_entry->dir_drive_offset, newpwd->dir_drive, dir_drive_len); - if (newpwd->logon_script) - memcpy (tdb_entry->strings + tdb_entry->logon_script_offset, newpwd->logon_script, logon_script_len); - if (newpwd->profile_path) - memcpy (tdb_entry->strings + tdb_entry->profile_path_offset, newpwd->profile_path, profile_path_len); - if (newpwd->acct_desc) - memcpy (tdb_entry->strings + tdb_entry->acct_desc_offset, newpwd->acct_desc, acct_desc_len); - if (newpwd->workstations) - memcpy (tdb_entry->strings + tdb_entry->workstations_offset, newpwd->workstations, workstations_len); - if (newpwd->unknown_str) - memcpy (tdb_entry->strings + tdb_entry->unknown_str_offset, newpwd->unknown_str, unknown_str_len); - if (newpwd->munged_dial) - memcpy (tdb_entry->strings + tdb_entry->munged_dial_offset, newpwd->munged_dial, munged_dial_len); - - slprintf(keystr, sizeof(keystr), "USER_%s", newpwd->smb_name); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; + data = tdb_fetch (global_tdb_ent.passwd_tdb, global_tdb_ent.key); + if (!data.dptr) + { + DEBUG(5,("pdb_getsampwent: database entry not found.\n")); + return NULL; + } - tdb_writelock (pwd_tdb); - if (tdb_store (pwd_tdb, key, data, TDB_INSERT) != TDB_SUCCESS) - { - DEBUG(0, ("Unable to modify TDB passwd!")); - DEBUGADD(0, (" Error: %s\n", tdb_error (pwd_tdb))); - tdb_writeunlock (pwd_tdb); - tdb_close (pwd_tdb); - return False; - } - - tdb_writeunlock (pwd_tdb); - tdb_close (pwd_tdb); - return True; + /* unpack the buffer */ + pdb_clear_sam (&global_sam_pass); + if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + { + DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + return NULL; + } + + /* validate the account and fill in UNIX uid and gid. sys_getpwnam() + is used instaed of Get_Pwnam() as we do not need to try case + permutations */ + if ((pw=sys_getpwnam(pdb_get_username(&global_sam_pass))) == NULL) + { + DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", + pdb_get_username(&global_sam_pass))); + return NULL; + } + + pdb_set_uid (&global_sam_pass, pw->pw_uid); + pdb_set_gid (&global_sam_pass, pw->pw_gid); + + /* increment to next in line */ + global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); + + return (&global_sam_pass); } -static struct sam_passwd *iterate_getsamtdb21pwrid(uint32 user_rid) +/****************************************************************** + Lookup a name in the SAM TDB +******************************************************************/ +SAM_ACCOUNT* pdb_getsampwnam (char *name) { - struct sam_passwd *pwd = NULL; - void *fp = NULL; - - DEBUG(10, ("search by smb_userid: %x\n", (int)user_rid)); + TDB_CONTEXT *pwd_tdb; + TDB_DATA data, key; + fstring keystr; + struct passwd *pw; + pstring tdbfile; + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/passdb.tdb"); + + /* set search key */ + slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; - /* Open the smb password database - not for update. */ - fp = startsamtdbpwent(False); + /* open the accounts TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDONLY, 0600))) + { + DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd!\n")); + return False; + } - if (fp == NULL) + /* get the record */ + data = tdb_fetch (pwd_tdb, key); + if (!data.dptr) { - DEBUG(0, ("unable to open smb password database.\n")); + DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); + DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); + tdb_close (pwd_tdb); return NULL; } - - while ((pwd = getsamtdb21pwent(fp)) != NULL && pwd->user_rid != user_rid); - - if (pwd != NULL) + + /* unpack the buffer */ + pdb_clear_sam (&global_sam_pass); + if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + { + DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + return NULL; + } + + /* validate the account and fill in UNIX uid and gid. sys_getpwnam() + is used instaed of Get_Pwnam() as we do not need to try case + permutations */ + if ((pw=sys_getpwnam(pdb_get_username(&global_sam_pass))) == NULL) { - DEBUG(10, ("found by user_rid: %x\n", (int)user_rid)); + DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", + pdb_get_username(&global_sam_pass))); + return NULL; } + + pdb_set_uid (&global_sam_pass, pw->pw_uid); + pdb_set_gid (&global_sam_pass, pw->pw_gid); + + /* cleanup */ + tdb_close (pwd_tdb); - endsamtdbpwent(fp); - return pwd; + return (&global_sam_pass); } -static struct sam_passwd *getsamtdb21pwnam(char *name) +/*************************************************************************** + Search by uid + + I now know what the 'T' stands for in TDB :-( This is an unacceptable + solution. We need multiple indexes and transactional support. I'm + including this implementation only as an example. + **************************************************************************/ +SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) { - static struct sam_passwd sam_entry; - static struct tdb_sam_entry *tdb_entry; - TDB_CONTEXT *pwd_tdb; - TDB_DATA data; - TDB_DATA key; - fstring keystr; - - if (!(pwd_tdb = tdb_open(lp_tdb_passwd_file(), 0, 0, O_RDONLY, 0600))) - { - DEBUG(0, ("Unable to open TDB passwd!")); - return False; - } - - slprintf(keystr, sizeof(keystr), "USER_%s", name); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; - - data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) - { - DEBUG(5,("getsamtdbpwent: error fetching database.\n")); - DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); - tdb_close (pwd_tdb); - return NULL; - } - - tdb_entry = (struct tdb_sam_entry *)(data.dptr); - - sam_entry.logon_time = tdb_entry->logon_time; - sam_entry.logoff_time = tdb_entry->logoff_time; - sam_entry.kickoff_time = tdb_entry->kickoff_time; - sam_entry.pass_last_set_time = tdb_entry->pass_last_set_time; - sam_entry.pass_can_change_time = tdb_entry->pass_can_change_time; - sam_entry.pass_must_change_time = tdb_entry->pass_must_change_time; - sam_entry.smb_name = tdb_entry->strings + tdb_entry->smb_name_offset; - sam_entry.full_name = tdb_entry->strings + tdb_entry->full_name_offset; - sam_entry.home_dir = tdb_entry->strings + tdb_entry->home_dir_offset; - sam_entry.dir_drive = tdb_entry->strings + tdb_entry->dir_drive_offset; - sam_entry.logon_script = tdb_entry->strings + tdb_entry->logon_script_offset; - sam_entry.profile_path = tdb_entry->strings + tdb_entry->profile_path_offset; - sam_entry.acct_desc = tdb_entry->strings + tdb_entry->acct_desc_offset; - sam_entry.workstations = tdb_entry->strings + tdb_entry->workstations_offset; - sam_entry.unknown_str = tdb_entry->strings + tdb_entry->unknown_str_offset; - sam_entry.munged_dial = tdb_entry->strings + tdb_entry->munged_dial_offset; - sam_entry.smb_userid = tdb_entry->smb_userid; - sam_entry.smb_grpid = tdb_entry->smb_grpid; - sam_entry.user_rid = tdb_entry->user_rid; - sam_entry.group_rid = tdb_entry->group_rid; - sam_entry.smb_passwd = tdb_entry->smb_passwd; - sam_entry.smb_nt_passwd = tdb_entry->smb_nt_passwd; - sam_entry.acct_ctrl = tdb_entry->acct_ctrl; - sam_entry.unknown_3 = tdb_entry->unknown_3; - sam_entry.logon_divs = tdb_entry->logon_divs; - sam_entry.hours_len = tdb_entry->hours_len; - memcpy (sam_entry.hours, tdb_entry->hours, MAX_HOURS_LEN); - sam_entry.unknown_5 = tdb_entry->unknown_5; - sam_entry.unknown_6 = tdb_entry->unknown_6; - - tdb_close (pwd_tdb); - return &sam_entry; -} + SAM_ACCOUNT *pw = NULL; -static SMB_BIG_UINT getsamtdbpwpos(void *vp) -{ - return (SMB_BIG_UINT)0; + if (!pdb_setsampwent(False)) + return NULL; + + while ( ((pw=pdb_getsampwent()) != NULL) && (pdb_get_uid(pw) != uid) ) + /* do nothing */ ; + + pdb_endsampwent(); + + return pw; } -static BOOL setsamtdbpwpos(void *vp, SMB_BIG_UINT tok) +/*************************************************************************** + Search by rid + **************************************************************************/ +SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) { - return False; -} + SAM_ACCOUNT *pw = NULL; -static struct smb_passwd *getsamtdbpwent(void *vp) -{ - return pdb_sam_to_smb(getsamtdb21pwent(vp)); + if (!pdb_setsampwent(False)) + return NULL; + + while ( ((pw=pdb_getsampwent()) != NULL) && (pdb_get_user_rid(pw) != rid) ) + /* do nothing */ ; + + pdb_endsampwent(); + + return pw; } -static BOOL add_samtdbpwd_entry(struct smb_passwd *newpwd) -{ - return add_samtdb21pwd_entry(pdb_smb_to_sam(newpwd)); -} -static BOOL mod_samtdbpwd_entry(struct smb_passwd* pwd, BOOL override) +/*************************************************************************** + Delete a SAM_ACCOUNT +****************************************************************************/ +BOOL pdb_delete_sam_account(char *name) { - return mod_samtdb21pwd_entry(pdb_smb_to_sam(pwd), override); -} + TDB_CONTEXT *pwd_tdb; + TDB_DATA key; + fstring keystr; + pstring tdbfile; + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/passdb.tdb"); + -static struct sam_disp_info *getsamtdbdispnam(char *name) -{ - return pdb_sam_to_dispinfo(getsam21pwnam(name)); + /* open the TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("Unable to open TDB passwd!")); + return False; + } + + /* set the search key */ + slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* it's outaa here! 8^) */ + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) + { + DEBUG(5, ("Error deleting entry from tdb database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); + tdb_close(pwd_tdb); + return False; + } + + tdb_close(pwd_tdb); + return True; } -static struct sam_disp_info *getsamtdbdisprid(uint32 rid) +/*************************************************************************** + Update the TDB SAM +****************************************************************************/ +static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) { - return pdb_sam_to_dispinfo(getsam21pwrid(rid)); -} + TDB_CONTEXT *pwd_tdb; + TDB_DATA key, data; + BYTE *buf = NULL; + fstring keystr; + pstring tdbfile; + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/passdb.tdb"); + + if ( (!newpwd->uid) || (!newpwd->gid) ) + { + DEBUG (0,("tdb_update_sam: Attempting to store a SAM_ACCOUNT for [%s] with no uid/gid!\n", newpwd->username)); + return False; + } + + /* if we don't have a RID, then generate one */ + if (!newpwd->user_rid) + pdb_set_user_rid (pdb_uid_to_user_rid (newpwd->uid)); + if (!newpwd->group_rid) + pdb_set_user_rid (pdb_uid_to_group_rid (newpwd->gid)); + + /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ + if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) + { + DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); + return False; + } + data.dptr = buf; -static struct sam_disp_info *getsamtdbdispent(void *vp) -{ - return pdb_sam_to_dispinfo(getsam21pwent(vp)); + /* setup the index key */ + slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, pdb_get_username(newpwd)); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* invalidate the existing TDB iterator if it is open */ + if (global_tdb_ent.passwd_tdb) + { + tdb_close(global_tdb_ent.passwd_tdb); + global_tdb_ent.passwd_tdb = NULL; + } + + /* open the account TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); + if (flag == TDB_INSERT) + { + DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + { + DEBUG(0, ("Unable to create TDB passwd (smbpasswd.tdb) !!!\n")); + return False; + } + } + } + + /* add the account */ + if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) + { + DEBUG(0, ("Unable to modify TDB passwd!")); + DEBUGADD(0, (" Error: %s\n", tdb_error (pwd_tdb))); + tdb_close (pwd_tdb); + return False; + } + + /* cleanup */ + tdb_close (pwd_tdb); + + return (True); } -static struct smb_passwd *iterate_getsamtdbpwrid(uint32 user_rid) +/*************************************************************************** + Modifies an existing SAM_ACCOUNT +****************************************************************************/ +BOOL pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override) { - return pdb_sam_to_smb(iterate_getsamtdb21pwrid(user_rid)); + return (tdb_update_sam(newpwd, override, TDB_MODIFY)); } -static struct smb_passwd *getsamtdbpwnam(char *name) +/*************************************************************************** + Adds an existing SAM_ACCOUNT +****************************************************************************/ +BOOL pdb_add_sam_account (SAM_ACCOUNT *newpwd) { - return pdb_sam_to_smb(getsamtdb21pwnam(name)); + return (tdb_update_sam(newpwd, True, TDB_INSERT)); } -static struct passdb_ops tdb_ops = { - startsamtdbpwent, - endsamtdbpwent, - getsamtdbpwpos, - setsamtdbpwpos, - getsamtdbpwnam, - iterate_getsmbpwuid, /* In passdb.c */ - iterate_getsamtdbpwrid, - getsamtdbpwent, - add_samtdbpwd_entry, - mod_samtdbpwd_entry, - del_samtdbpwd_entry, - getsamtdb21pwent, - getsamtdb21pwnam, - - /* TODO change get username from uid and then use - getsamtdb21pwnam */ - iterate_getsam21pwuid, - - iterate_getsamtdb21pwrid, - add_samtdb21pwd_entry, - mod_samtdb21pwd_entry, - getsamtdbdispnam, - getsamtdbdisprid, - getsamtdbdispent -}; - -struct passdb_ops *tdb_initialize_password_db(void) -{ - return &tdb_ops; -} #else /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */ -- cgit From c09b1d19f881d60b7594fe8f5479580ffb573041 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 6 Dec 2000 18:22:29 +0000 Subject: updates to the tdbsam implementation. --jerry (This used to be commit 29b3ac8634769d01c20bf394eecc536a02e0f36c) --- source3/passdb/pdb_tdb.c | 299 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 263 insertions(+), 36 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e997d6c318..921ce853c6 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -2,6 +2,7 @@ * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup * Copyright (C) Andrew Tridgell 1992-1998 * Copyright (C) Simo Sorce 2000 + * Copyright (C) Gerald Carter 2000 * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -24,6 +25,8 @@ #define TDB_FORMAT_STRING "ddddddfffPPfPPPPffddBBwdwdBdd" #define USERPREFIX "USER_" +#define UIDPREFIX "UID_" +#define RIDPREFIX "RID_" extern int DEBUGLEVEL; extern pstring samlogon_user; @@ -63,7 +66,12 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, BYTE *buf, nt_pw[16]; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; - + + /* using static memory for strings */ + /* you set it now or you will delete any fields retrieved by tdb_unpack */ + pdb_set_mem_ownership(sampass, False); + + /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, &sampass->logon_time, @@ -116,9 +124,6 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, BYTE *buf, memcpy(nt_pw, nt_pw_ptr, 16); free (nt_pw_ptr); } - - /* using static memory for strings */ - pdb_set_mem_ownership(sampass, False); pdb_set_username (sampass, username); pdb_set_domain (sampass, domain); @@ -370,14 +375,17 @@ SAM_ACCOUNT* pdb_getsampwent(void) /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ -SAM_ACCOUNT* pdb_getsampwnam (char *name) +SAM_ACCOUNT* pdb_getsampwnam (char *sname) { TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; fstring keystr; struct passwd *pw; pstring tdbfile; + fstring name; + fstrcpy (name, sname); + strlower (name); pstrcpy (tdbfile, lp_private_dir()); pstrcat (tdbfile, "/passdb.tdb"); @@ -398,7 +406,7 @@ SAM_ACCOUNT* pdb_getsampwnam (char *name) if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); - DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return NULL; } @@ -439,16 +447,44 @@ SAM_ACCOUNT* pdb_getsampwnam (char *name) **************************************************************************/ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) { - SAM_ACCOUNT *pw = NULL; + SAM_ACCOUNT *pw = NULL; + TDB_CONTEXT *pwd_tdb; + TDB_DATA data, key; + fstring keystr; + pstring tdbfile; + fstring name; + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/uiddb.tdb"); + + /* set search key */ + slprintf(keystr, sizeof(keystr), "%s%.5u", UIDPREFIX, uid); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* open the accounts TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDONLY, 0600))) + { + DEBUG(0, ("pdb_getsampwuid: Unable to open TDB uid database!\n")); + return False; + } - if (!pdb_setsampwent(False)) + /* get the record */ + data = tdb_fetch (pwd_tdb, key); + if (!data.dptr) + { + DEBUG(5,("pdb_getsampwuid (TDB): error fetching database.\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + tdb_close (pwd_tdb); return NULL; - - while ( ((pw=pdb_getsampwent()) != NULL) && (pdb_get_uid(pw) != uid) ) - /* do nothing */ ; + } + + fstrcpy (name, data.dptr); + + tdb_close (pwd_tdb); - pdb_endsampwent(); - + pw = pdb_getsampwnam (name); + return pw; } @@ -457,33 +493,68 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) **************************************************************************/ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) { - SAM_ACCOUNT *pw = NULL; + SAM_ACCOUNT *pw = NULL; + TDB_CONTEXT *pwd_tdb; + TDB_DATA data, key; + fstring keystr; + pstring tdbfile; + fstring name; + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/riddb.tdb"); + + /* set search key */ + slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, rid); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; - if (!pdb_setsampwent(False)) + /* open the accounts TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDONLY, 0600))) + { + DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); + return False; + } + + /* get the record */ + data = tdb_fetch (pwd_tdb, key); + if (!data.dptr) + { + DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + tdb_close (pwd_tdb); return NULL; - - while ( ((pw=pdb_getsampwent()) != NULL) && (pdb_get_user_rid(pw) != rid) ) - /* do nothing */ ; + } + + fstrcpy (name, data.dptr); - pdb_endsampwent(); - + tdb_close (pwd_tdb); + + pw = pdb_getsampwnam (name); + return pw; + } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_delete_sam_account(char *name) +BOOL pdb_delete_sam_account(char *sname) { + struct passwd *pwd = NULL; TDB_CONTEXT *pwd_tdb; - TDB_DATA key; + TDB_DATA key, data; fstring keystr; pstring tdbfile; + uid_t uid; + uint32 rid; + fstring name; + + fstrcpy (name, sname); + strlower (name); pstrcpy (tdbfile, lp_private_dir()); pstrcat (tdbfile, "/passdb.tdb"); - /* open the TDB */ if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) @@ -497,16 +568,90 @@ BOOL pdb_delete_sam_account(char *name) key.dptr = keystr; key.dsize = strlen (keystr) + 1; + /* get the record */ + data = tdb_fetch (pwd_tdb, key); + if (!data.dptr) + { + DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + tdb_close (pwd_tdb); + return False; + } + + /* unpack the buffer */ + pdb_clear_sam (&global_sam_pass); + if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + { + DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + return False; + } + + pwd = sys_getpwnam(global_sam_pass.username); + uid = pwd->pw_uid; + rid = pdb_uid_to_user_rid (uid); + + /* it's outaa here! 8^) */ + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) + { + DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + tdb_close(pwd_tdb); + return False; + } + tdb_close(pwd_tdb); + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/uiddb.tdb"); + + /* open the UID TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("Unable to open TDB uid file!")); + return False; + } + + /* set the search key */ + slprintf(keystr, sizeof(keystr), "%s%.5u", UIDPREFIX, uid); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* it's outaa here! 8^) */ + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) + { + DEBUG(5, ("Error deleting entry from tdb uid database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + tdb_close(pwd_tdb); + return False; + } + + tdb_close(pwd_tdb); + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/riddb.tdb"); + + /* open the RID TDB */ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("Unable to open TDB rid file!")); + return False; + } + + /* set the search key */ + slprintf(keystr, sizeof(keystr), "%s%.8x", UIDPREFIX, rid); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + /* it's outaa here! 8^) */ if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { - DEBUG(5, ("Error deleting entry from tdb database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_error(pwd_tdb))); + DEBUG(5, ("Error deleting entry from tdb rid database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close(pwd_tdb); return False; } tdb_close(pwd_tdb); + return True; } @@ -520,21 +665,21 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) BYTE *buf = NULL; fstring keystr; pstring tdbfile; + fstring name; + int newtdb = FALSE; pstrcpy (tdbfile, lp_private_dir()); pstrcat (tdbfile, "/passdb.tdb"); if ( (!newpwd->uid) || (!newpwd->gid) ) - { - DEBUG (0,("tdb_update_sam: Attempting to store a SAM_ACCOUNT for [%s] with no uid/gid!\n", newpwd->username)); - return False; - } + DEBUG (0,("tdb_update_sam: Storing a SAM_ACCOUNT for [%s] with uid %d and gid %d!\n", + newpwd->username, newpwd->uid, newpwd->gid)); /* if we don't have a RID, then generate one */ if (!newpwd->user_rid) - pdb_set_user_rid (pdb_uid_to_user_rid (newpwd->uid)); + pdb_set_user_rid (newpwd, pdb_uid_to_user_rid (newpwd->uid)); if (!newpwd->group_rid) - pdb_set_user_rid (pdb_uid_to_group_rid (newpwd->gid)); + pdb_set_user_rid (newpwd, pdb_gid_to_group_rid (newpwd->gid)); /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) @@ -544,8 +689,11 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } data.dptr = buf; - /* setup the index key */ - slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, pdb_get_username(newpwd)); + fstrcpy (name, pdb_get_username(newpwd)); + strlower (name); + + /* setup the USER index key */ + slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -556,7 +704,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) global_tdb_ent.passwd_tdb = NULL; } - /* open the account TDB */ + /* open the account TDB passwd*/ if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); @@ -565,9 +713,10 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) { - DEBUG(0, ("Unable to create TDB passwd (smbpasswd.tdb) !!!\n")); + DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); return False; } + newtdb = TRUE; } } @@ -575,14 +724,92 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify TDB passwd!")); - DEBUGADD(0, (" Error: %s\n", tdb_error (pwd_tdb))); + DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return False; } /* cleanup */ tdb_close (pwd_tdb); + + /* setup UID/RID data */ + data.dsize = sizeof(fstring); + data.dptr = name; + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/uiddb.tdb"); + + /* setup the UID index key */ + slprintf(keystr, sizeof(keystr), "%s%.5u", UIDPREFIX, pdb_get_uid(newpwd)); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* open the account TDB uid file*/ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("tdb_update_sam: Unable to open TDB uid database!\n")); + if (newtdb == FALSE) + DEBUG(0, ("WARNING: uid database missing and passdb exist, check references integrity!\n")); + if (flag == TDB_INSERT) + { + DEBUG(0, ("Unable to open TDB uid file, trying create new!\n")); + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + { + DEBUG(0, ("Unable to create TDB uid (uiddb.tdb) !!!\n")); + /* return False; */ + } + } + } + + /* add the reference */ + if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) + { + DEBUG(0, ("Unable to modify TDB uid database!")); + DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + /* tdb_close (pwd_tdb); + return False; */ + } + + /* cleanup */ + tdb_close (pwd_tdb); + + pstrcpy (tdbfile, lp_private_dir()); + pstrcat (tdbfile, "/riddb.tdb"); + + /* setup the RID index key */ + slprintf(keystr, sizeof(keystr), "%s%.8x", UIDPREFIX, pdb_get_user_rid(newpwd)); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* open the account TDB rid file*/ + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + { + DEBUG(0, ("tdb_update_sam: Unable to open TDB rid database!\n")); + if (newtdb == FALSE) + DEBUG(0, ("WARNING: rid database missing and passdb exist, check references integrity!\n")); + if (flag == TDB_INSERT) + { + DEBUG(0, ("Unable to open TDB rid file, trying create new!\n")); + if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + { + DEBUG(0, ("Unable to create TDB rid (riddb.tdb) !!!\n")); + /* return False; */ + } + } + } + + /* add the reference */ + if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) + { + DEBUG(0, ("Unable to modify TDB rid database!")); + DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + /* tdb_close (pwd_tdb); + return False; */ + } + + /* cleanup */ + tdb_close (pwd_tdb); + return (True); } -- cgit From f449a5913603f94774472d248dc6979d65a271a6 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 9 Dec 2000 20:45:04 +0000 Subject: group rid assignment cut and paste error --jerry (This used to be commit bb48b02d5f2118470a415d5f1f92305688e6b432) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 921ce853c6..0591be68d8 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -298,7 +298,7 @@ BOOL pdb_setsampwent(BOOL update) DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); if (!(global_tdb_ent.passwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) { - DEBUG(0, ("Unable to create TDB passwd (smbpasswd.tdb) !!!")); + DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!")); return False; } } @@ -679,7 +679,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if (!newpwd->user_rid) pdb_set_user_rid (newpwd, pdb_uid_to_user_rid (newpwd->uid)); if (!newpwd->group_rid) - pdb_set_user_rid (newpwd, pdb_gid_to_group_rid (newpwd->gid)); + pdb_set_group_rid (newpwd, pdb_gid_to_group_rid (newpwd->gid)); /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) -- cgit From d21325dbd90659bf06b0570ab8a9330de808ee0a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 12 Dec 2000 16:50:23 +0000 Subject: more fixes from Simo. Also fixed the password expiration field in the tdbsam to never expire (we don't support this yet). jerry (This used to be commit 3b7d0fe7eb3a9275d2713d7b3325de0ab510ea62) --- source3/passdb/pdb_tdb.c | 193 +++++++++++++++-------------------------------- 1 file changed, 59 insertions(+), 134 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0591be68d8..1b0cce08fb 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -23,9 +23,10 @@ #ifdef WITH_TDBPWD +#define PASSDB_FILE_NAME "/passdb.tdb" +#define RIDDB_FILE_NAME "/riddb.tdb" #define TDB_FORMAT_STRING "ddddddfffPPfPPPPffddBBwdwdBdd" #define USERPREFIX "USER_" -#define UIDPREFIX "UID_" #define RIDPREFIX "RID_" extern int DEBUGLEVEL; @@ -283,14 +284,14 @@ static uint32 init_buffer_from_sam (BYTE **buf, SAM_ACCOUNT *sampass) } /*************************************************************** - Open the TDB account SAM fo renumeration. + Open the TDB passwd database for SAM account enumeration. ****************************************************************/ BOOL pdb_setsampwent(BOOL update) { pstring tdbfile; pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/passdb.tdb"); + pstrcat (tdbfile, PASSDB_FILE_NAME); /* Open tdb passwd */ if (!(global_tdb_ent.passwd_tdb = tdb_open(tdbfile, 0, 0, update ? O_RDWR : O_RDONLY, 0600))) @@ -328,8 +329,10 @@ void pdb_endsampwent(void) *****************************************************************/ SAM_ACCOUNT* pdb_getsampwent(void) { - TDB_DATA data; - struct passwd *pw; + TDB_DATA data; + struct passwd *pw; + uid_t uid; + gid_t gid; /* do we have an valid interation pointer? */ if(global_tdb_ent.passwd_tdb == NULL) @@ -362,9 +365,18 @@ SAM_ACCOUNT* pdb_getsampwent(void) pdb_get_username(&global_sam_pass))); return NULL; } - - pdb_set_uid (&global_sam_pass, pw->pw_uid); - pdb_set_gid (&global_sam_pass, pw->pw_gid); + + uid = pw->pw_uid; + gid = pw->pw_gid; + pdb_set_uid (&global_sam_pass, uid); + pdb_set_gid (&global_sam_pass, gid); + + /* 21 days from present */ + pdb_set_pass_must_change_time(&global_sam_pass, time(NULL)+1814400); + + standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_logon_script(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_profile_path(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_homedir(&global_sam_pass)); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -377,17 +389,19 @@ SAM_ACCOUNT* pdb_getsampwent(void) ******************************************************************/ SAM_ACCOUNT* pdb_getsampwnam (char *sname) { - TDB_CONTEXT *pwd_tdb; - TDB_DATA data, key; - fstring keystr; - struct passwd *pw; - pstring tdbfile; - fstring name; + TDB_CONTEXT *pwd_tdb; + TDB_DATA data, key; + fstring keystr; + struct passwd *pw; + pstring tdbfile; + fstring name; + uid_t uid; + gid_t gid; fstrcpy (name, sname); strlower (name); pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/passdb.tdb"); + pstrcat (tdbfile, PASSDB_FILE_NAME); /* set search key */ slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); @@ -429,9 +443,18 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) return NULL; } - pdb_set_uid (&global_sam_pass, pw->pw_uid); - pdb_set_gid (&global_sam_pass, pw->pw_gid); + uid = pw->pw_uid; + gid = pw->pw_gid; + pdb_set_uid (&global_sam_pass, uid); + pdb_set_gid (&global_sam_pass, gid); + + /* 21 days from present */ + pdb_set_pass_must_change_time(&global_sam_pass, time(NULL)+1814400); + standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_logon_script(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_profile_path(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_homedir(&global_sam_pass)); + /* cleanup */ tdb_close (pwd_tdb); @@ -440,52 +463,22 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) /*************************************************************************** Search by uid - - I now know what the 'T' stands for in TDB :-( This is an unacceptable - solution. We need multiple indexes and transactional support. I'm - including this implementation only as an example. **************************************************************************/ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) { - SAM_ACCOUNT *pw = NULL; - TDB_CONTEXT *pwd_tdb; - TDB_DATA data, key; - fstring keystr; - pstring tdbfile; - fstring name; - - pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/uiddb.tdb"); - - /* set search key */ - slprintf(keystr, sizeof(keystr), "%s%.5u", UIDPREFIX, uid); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; - - /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDONLY, 0600))) - { - DEBUG(0, ("pdb_getsampwuid: Unable to open TDB uid database!\n")); - return False; - } + struct passwd *pw; + fstring name; - /* get the record */ - data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) + pw = sys_getpwuid(uid); + if (pw == NULL) { - DEBUG(5,("pdb_getsampwuid (TDB): error fetching database.\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close (pwd_tdb); + DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist!\n", uid)); return NULL; } + fstrcpy (name, pw->pw_name); - fstrcpy (name, data.dptr); + return pdb_getsampwnam (name); - tdb_close (pwd_tdb); - - pw = pdb_getsampwnam (name); - - return pw; } /*************************************************************************** @@ -493,7 +486,6 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) **************************************************************************/ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) { - SAM_ACCOUNT *pw = NULL; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; fstring keystr; @@ -501,7 +493,7 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) fstring name; pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/riddb.tdb"); + pstrcat (tdbfile, RIDDB_FILE_NAME); /* set search key */ slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, rid); @@ -529,10 +521,7 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) tdb_close (pwd_tdb); - pw = pdb_getsampwnam (name); - - return pw; - + return pdb_getsampwnam (name); } @@ -554,7 +543,7 @@ BOOL pdb_delete_sam_account(char *sname) strlower (name); pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/passdb.tdb"); + pstrcat (tdbfile, PASSDB_FILE_NAME); /* open the TDB */ if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) @@ -572,7 +561,7 @@ BOOL pdb_delete_sam_account(char *sname) data = tdb_fetch (pwd_tdb, key); if (!data.dptr) { - DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); + DEBUG(5,("pdb_delete_sam_account (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return False; @@ -587,7 +576,6 @@ BOOL pdb_delete_sam_account(char *sname) } pwd = sys_getpwnam(global_sam_pass.username); - uid = pwd->pw_uid; rid = pdb_uid_to_user_rid (uid); /* it's outaa here! 8^) */ @@ -601,33 +589,7 @@ BOOL pdb_delete_sam_account(char *sname) tdb_close(pwd_tdb); pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/uiddb.tdb"); - - /* open the UID TDB */ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("Unable to open TDB uid file!")); - return False; - } - - /* set the search key */ - slprintf(keystr, sizeof(keystr), "%s%.5u", UIDPREFIX, uid); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; - - /* it's outaa here! 8^) */ - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) - { - DEBUG(5, ("Error deleting entry from tdb uid database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close(pwd_tdb); - return False; - } - - tdb_close(pwd_tdb); - - pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/riddb.tdb"); + pstrcat (tdbfile, RIDDB_FILE_NAME); /* open the RID TDB */ if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) @@ -637,7 +599,7 @@ BOOL pdb_delete_sam_account(char *sname) } /* set the search key */ - slprintf(keystr, sizeof(keystr), "%s%.8x", UIDPREFIX, rid); + slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -669,7 +631,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) int newtdb = FALSE; pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/passdb.tdb"); + pstrcat (tdbfile, PASSDB_FILE_NAME); if ( (!newpwd->uid) || (!newpwd->gid) ) DEBUG (0,("tdb_update_sam: Storing a SAM_ACCOUNT for [%s] with uid %d and gid %d!\n", @@ -732,52 +694,15 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) /* cleanup */ tdb_close (pwd_tdb); - /* setup UID/RID data */ + /* setup RID data */ data.dsize = sizeof(fstring); data.dptr = name; pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/uiddb.tdb"); - - /* setup the UID index key */ - slprintf(keystr, sizeof(keystr), "%s%.5u", UIDPREFIX, pdb_get_uid(newpwd)); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; - - /* open the account TDB uid file*/ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("tdb_update_sam: Unable to open TDB uid database!\n")); - if (newtdb == FALSE) - DEBUG(0, ("WARNING: uid database missing and passdb exist, check references integrity!\n")); - if (flag == TDB_INSERT) - { - DEBUG(0, ("Unable to open TDB uid file, trying create new!\n")); - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) - { - DEBUG(0, ("Unable to create TDB uid (uiddb.tdb) !!!\n")); - /* return False; */ - } - } - } - - /* add the reference */ - if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) - { - DEBUG(0, ("Unable to modify TDB uid database!")); - DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - /* tdb_close (pwd_tdb); - return False; */ - } - - /* cleanup */ - tdb_close (pwd_tdb); - - pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, "/riddb.tdb"); + pstrcat (tdbfile, RIDDB_FILE_NAME); /* setup the RID index key */ - slprintf(keystr, sizeof(keystr), "%s%.8x", UIDPREFIX, pdb_get_user_rid(newpwd)); + slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -803,8 +728,8 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) { DEBUG(0, ("Unable to modify TDB rid database!")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - /* tdb_close (pwd_tdb); - return False; */ + tdb_close (pwd_tdb); + return False; } /* cleanup */ -- cgit From a2e5dbb1120e726ba80b00a159dad1a1ca2e3a18 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:51:54 +0000 Subject: Remove "BYTE" - we already have uint8 - don't need more conflicts with system header files... Jeremy. (This used to be commit 31e0ce310ec38b3a3a05b344d6450d442c6be471) --- source3/passdb/pdb_tdb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1b0cce08fb..740d8b1c5f 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -46,7 +46,7 @@ static SAM_ACCOUNT global_sam_pass; /********************************************************************** Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len *********************************************************************/ -static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, BYTE *buf, +static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) { static fstring username, @@ -61,7 +61,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, BYTE *buf, profile_path, acct_desc, workstations; - static BYTE *lm_pw_ptr, + static uint8 *lm_pw_ptr, *nt_pw_ptr, lm_pw[16], nt_pw[16]; @@ -146,7 +146,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, BYTE *buf, /********************************************************************** Intialize a BYTE buffer from a SAM_ACCOUNT struct *********************************************************************/ -static uint32 init_buffer_from_sam (BYTE **buf, SAM_ACCOUNT *sampass) +static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) { size_t len, buflen; @@ -162,7 +162,7 @@ static uint32 init_buffer_from_sam (BYTE **buf, SAM_ACCOUNT *sampass) profile_path, acct_desc, workstations; - BYTE lm_pw[16], + uint8 lm_pw[16], nt_pw[16]; char null_pw[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; @@ -232,7 +232,7 @@ static uint32 init_buffer_from_sam (BYTE **buf, SAM_ACCOUNT *sampass) /* malloc the space needed */ - if ( (*buf=(BYTE*)malloc(len)) == NULL) + if ( (*buf=(uint8*)malloc(len)) == NULL) { DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n")); return (-1); @@ -624,7 +624,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) { TDB_CONTEXT *pwd_tdb; TDB_DATA key, data; - BYTE *buf = NULL; + uint8 *buf = NULL; fstring keystr; pstring tdbfile; fstring name; -- cgit From 98560fa3944b1eb8cc01df05b93408753296b4a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 8 Apr 2001 20:31:39 +0000 Subject: HEAD specific slprintf paranoia fixes. Jeremy. (This used to be commit 61723c18f96a7b38cab0fcf545da7fb3640c5f7b) --- source3/passdb/pdb_tdb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 740d8b1c5f..0003b024c9 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -404,7 +404,7 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) pstrcat (tdbfile, PASSDB_FILE_NAME); /* set search key */ - slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -496,7 +496,7 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) pstrcat (tdbfile, RIDDB_FILE_NAME); /* set search key */ - slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, rid); + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -553,7 +553,7 @@ BOOL pdb_delete_sam_account(char *sname) } /* set the search key */ - slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -599,7 +599,7 @@ BOOL pdb_delete_sam_account(char *sname) } /* set the search key */ - slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, rid); + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -655,7 +655,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) strlower (name); /* setup the USER index key */ - slprintf(keystr, sizeof(keystr), "%s%s", USERPREFIX, name); + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -702,7 +702,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) pstrcat (tdbfile, RIDDB_FILE_NAME); /* setup the RID index key */ - slprintf(keystr, sizeof(keystr), "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); key.dptr = keystr; key.dsize = strlen (keystr) + 1; -- cgit From ba411ebf0cd21aebe34250e8fbd8bde4c6dcb6e7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 4 May 2001 14:01:33 +0000 Subject: fixes from Simo (This used to be commit 7703fbb30d9695b5a71ee0bcca9520bed4880bbd) --- source3/passdb/pdb_tdb.c | 451 +++++++++++++++++++++++++---------------------- 1 file changed, 238 insertions(+), 213 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0003b024c9..8db8b2e60d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -24,8 +24,7 @@ #ifdef WITH_TDBPWD #define PASSDB_FILE_NAME "/passdb.tdb" -#define RIDDB_FILE_NAME "/riddb.tdb" -#define TDB_FORMAT_STRING "ddddddfffPPfPPPPffddBBwdwdBdd" +#define TDB_FORMAT_STRING "BBBBBBBBBBBBBBBBBBddBBwdwdBdd" #define USERPREFIX "USER_" #define RIDPREFIX "RID_" @@ -49,97 +48,108 @@ static SAM_ACCOUNT global_sam_pass; static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) { - static fstring username, - domain, - nt_username, - dir_drive, - unknown_str, - munged_dial; - static pstring full_name, - home_dir, - logon_script, - profile_path, - acct_desc, - workstations; + time_t logon_time, + logoff_time, + kickoff_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time; + uint32 time_t_len; + char *username; + char *domain; + char *nt_username; + char *dir_drive; + char *unknown_str; + char *munged_dial; + char *fullname; + char *homedir; + char *logon_script; + char *profile_path; + char *acct_desc; + char *workstations; + uint32 username_len, domain_len, nt_username_len, + dir_drive_len, unknown_str_len, munged_dial_len, + fullname_len, homedir_len, logon_script_len, + profile_path_len, acct_desc_len, workstations_len; + + uint32 /* uid, gid,*/ user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6; + uint16 acct_ctrl, logon_divs; + uint8 *hours; static uint8 *lm_pw_ptr, - *nt_pw_ptr, - lm_pw[16], - nt_pw[16]; + *nt_pw_ptr; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; - - /* using static memory for strings */ - /* you set it now or you will delete any fields retrieved by tdb_unpack */ - pdb_set_mem_ownership(sampass, False); - + /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, - &sampass->logon_time, - &sampass->logoff_time, - &sampass->kickoff_time, - &sampass->pass_last_set_time, - &sampass->pass_can_change_time, - &sampass->pass_must_change_time, - username, - domain, - nt_username, - full_name, - home_dir, - dir_drive, - logon_script, - profile_path, - acct_desc, - workstations, - unknown_str, - munged_dial, - &sampass->user_rid, - &sampass->group_rid, + &time_t_len, &logon_time, + &time_t_len, &logoff_time, + &time_t_len, &kickoff_time, + &time_t_len, &pass_last_set_time, + &time_t_len, &pass_can_change_time, + &time_t_len, &pass_must_change_time, + &username_len, &username, + &domain_len, &domain, + &nt_username_len, &nt_username, + &fullname_len, &fullname, + &homedir_len, &homedir, + &dir_drive_len, &dir_drive, + &logon_script_len, &logon_script, + &profile_path_len, &profile_path, + &acct_desc_len, &acct_desc, + &workstations_len, &workstations, + &unknown_str_len, &unknown_str, + &munged_dial_len, &munged_dial, + &user_rid, + &group_rid, &lmpwlen, &lm_pw_ptr, &ntpwlen, &nt_pw_ptr, - &sampass->acct_ctrl, - &sampass->unknown_3, - &sampass->logon_divs, - &sampass->hours_len, - &hourslen, &sampass->hours, - &sampass->unknown_5, - &sampass->unknown_6); + &acct_ctrl, + &unknown_3, + &logon_divs, + &hours_len, + &hourslen, &hours, + &unknown_5, + &unknown_6); if (len == -1) return False; - /* - * We have to copy the password hashes into static memory - * and free the memory allocated by tdb_unpack. This is because - * the sampass->own_memory flag is for all pointer members. - * The remaining members are using static memory and so - * the password hashes must as well. --jerry - */ - if (lm_pw_ptr) - { - memcpy(lm_pw, lm_pw_ptr, 16); - free (lm_pw_ptr); - } - if (nt_pw_ptr) - { - memcpy(nt_pw, nt_pw_ptr, 16); - free (nt_pw_ptr); - } - - pdb_set_username (sampass, username); - pdb_set_domain (sampass, domain); - pdb_set_nt_username (sampass, nt_username); - pdb_set_fullname (sampass, full_name); - pdb_set_homedir (sampass, home_dir); - pdb_set_dir_drive (sampass, dir_drive); - pdb_set_logon_script (sampass, logon_script); - pdb_set_profile_path (sampass, profile_path); - pdb_set_acct_desc (sampass, acct_desc); - pdb_set_workstations (sampass, workstations); - pdb_set_munged_dial (sampass, munged_dial); - pdb_set_lanman_passwd(sampass, lm_pw); - pdb_set_nt_passwd (sampass, nt_pw); - + pdb_set_logon_time(sampass, logon_time); + pdb_set_logoff_time(sampass, logoff_time); + pdb_set_kickoff_time(sampass, kickoff_time); + pdb_set_pass_can_change_time(sampass, pass_can_change_time); + pdb_set_pass_must_change_time(sampass, pass_must_change_time); + pdb_set_pass_last_set_time(sampass, pass_last_set_time); + + pdb_set_username (sampass, username_len?username:NULL); + pdb_set_domain (sampass, domain_len?domain:NULL); + pdb_set_nt_username (sampass, nt_username_len?nt_username:NULL); + pdb_set_fullname (sampass, fullname_len?fullname:NULL); + pdb_set_homedir (sampass, homedir_len?homedir:NULL); + pdb_set_dir_drive (sampass, dir_drive_len?dir_drive:NULL); + pdb_set_logon_script (sampass, logon_script_len?logon_script:NULL); + pdb_set_profile_path (sampass, profile_path_len?profile_path:NULL); + pdb_set_acct_desc (sampass, acct_desc_len?acct_desc:NULL); + pdb_set_workstations (sampass, workstations_len?workstations:NULL); + pdb_set_munged_dial (sampass, munged_dial_len?munged_dial:NULL); + pdb_set_lanman_passwd(sampass, lmpwlen?lm_pw_ptr:NULL); + pdb_set_nt_passwd (sampass, ntpwlen?nt_pw_ptr:NULL); + + /*pdb_set_uid(sampass, uid); + pdb_set_gid(sampass, gid);*/ + pdb_set_user_rid(sampass, user_rid); + pdb_set_group_rid(sampass, group_rid); + pdb_set_unknown_3(sampass, unknown_3); + pdb_set_hours_len(sampass, hours_len); + pdb_set_unknown_5(sampass, unknown_5); + pdb_set_unknown_6(sampass, unknown_6); + pdb_set_acct_ctrl(sampass, acct_ctrl); + pdb_set_logons_divs(sampass, logon_divs); + pdb_set_hours(sampass, hours); + + return True; } @@ -150,20 +160,32 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) { size_t len, buflen; - fstring username, - domain, - nt_username, - dir_drive, - unknown_str, - munged_dial; - pstring full_name, - home_dir, - logon_script, - profile_path, - acct_desc, - workstations; - uint8 lm_pw[16], - nt_pw[16]; + time_t logon_time, + logoff_time, + kickoff_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time; + char *username; + char *domain; + char *nt_username; + char *dir_drive; + char *unknown_str; + char *munged_dial; + char *fullname; + char *homedir; + char *logon_script; + char *profile_path; + char *acct_desc; + char *workstations; + uint32 username_len, domain_len, nt_username_len, + dir_drive_len, unknown_str_len, munged_dial_len, + fullname_len, homedir_len, logon_script_len, + profile_path_len, acct_desc_len, workstations_len; + + uint8 *lm_pw; + uint8 *nt_pw; + uint32 time_t_len = sizeof (time_t); char null_pw[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; /* do we have a valid SAM_ACCOUNT pointer? */ @@ -173,62 +195,89 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) *buf = NULL; buflen = 0; - fstrcpy(username, sampass->username); - fstrcpy(domain, sampass->domain); - fstrcpy(nt_username, sampass->nt_username); - fstrcpy(dir_drive, sampass->dir_drive); - fstrcpy(unknown_str, sampass->unknown_str); - fstrcpy(munged_dial, sampass->munged_dial); - - pstrcpy(full_name, sampass->full_name); - pstrcpy(home_dir, sampass->home_dir); - pstrcpy(logon_script, sampass->logon_script); - pstrcpy(profile_path, sampass->profile_path); - pstrcpy(acct_desc, sampass->acct_desc); - pstrcpy(workstations, sampass->workstations); - - if (sampass->lm_pw) - memcpy(lm_pw, sampass->lm_pw, 16); - else - pdb_gethexpwd (null_pw, lm_pw); + logon_time = pdb_get_logon_time(sampass); + logoff_time = pdb_get_logoff_time(sampass); + kickoff_time = pdb_get_kickoff_time(sampass); + pass_can_change_time = pdb_get_pass_can_change_time(sampass); + pass_must_change_time = pdb_get_pass_must_change_time(sampass); + pass_last_set_time = pdb_get_pass_last_set_time(sampass); + + + username = pdb_get_username(sampass); + if (username) username_len = strlen(username) +1; + else username_len = 0; + domain = pdb_get_domain(sampass); + if (domain) domain_len = strlen(domain) +1; + else domain_len = 0; + nt_username = pdb_get_nt_username(sampass); + if (nt_username) nt_username_len = strlen(nt_username) +1; + else nt_username_len = 0; + dir_drive = pdb_get_dirdrive(sampass); + if (dir_drive) dir_drive_len = strlen(dir_drive) +1; + else dir_drive_len = 0; + unknown_str = NULL; + unknown_str_len = 0; + munged_dial = pdb_get_munged_dial(sampass); + if (munged_dial) munged_dial_len = strlen(munged_dial) +1; + else munged_dial_len = 0; - if (sampass->nt_pw) - memcpy(nt_pw, sampass->nt_pw, 16); - else - pdb_gethexpwd (null_pw, nt_pw); + fullname = pdb_get_fullname(sampass); + if (fullname) fullname_len = strlen(fullname) +1; + else fullname_len = 0; + homedir = pdb_get_homedir(sampass); + if (homedir) homedir_len = strlen(homedir) +1; + else homedir_len = 0; + logon_script = pdb_get_logon_script(sampass); + if (logon_script) logon_script_len = strlen(logon_script) +1; + else logon_script_len = 0; + profile_path = pdb_get_profile_path(sampass); + if (profile_path) profile_path_len = strlen(profile_path) +1; + else profile_path_len = 0; + acct_desc = pdb_get_acct_desc(sampass); + if (acct_desc) acct_desc_len = strlen(acct_desc) +1; + else acct_desc_len = 0; + workstations = pdb_get_workstations(sampass); + if (workstations) workstations_len = strlen(workstations) +1; + else workstations_len = 0; + + lm_pw = pdb_get_lanman_passwd(sampass); + if (!lm_pw) pdb_gethexpwd (null_pw, lm_pw); + + nt_pw = pdb_get_nt_passwd(sampass); + if (!nt_pw) pdb_gethexpwd (null_pw, nt_pw); /* one time to get the size needed */ len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, - sampass->logon_time, - sampass->logoff_time, - sampass->kickoff_time, - sampass->pass_last_set_time, - sampass->pass_can_change_time, - sampass->pass_must_change_time, - username, - domain, - nt_username, - full_name, - home_dir, - dir_drive, - logon_script, - profile_path, - acct_desc, - workstations, - unknown_str, - munged_dial, - sampass->user_rid, - sampass->group_rid, + time_t_len, &logon_time, + time_t_len, &logoff_time, + time_t_len, &kickoff_time, + time_t_len, &pass_last_set_time, + time_t_len, &pass_can_change_time, + time_t_len, &pass_must_change_time, + username_len, username, + domain_len, domain, + nt_username_len, nt_username, + fullname_len, fullname, + homedir_len, homedir, + dir_drive_len, dir_drive, + logon_script_len, logon_script, + profile_path_len, profile_path, + acct_desc_len, acct_desc, + workstations_len, workstations, + unknown_str_len, unknown_str, + munged_dial_len, munged_dial, + pdb_get_user_rid(sampass), + pdb_get_group_rid(sampass), 16, lm_pw, 16, nt_pw, - sampass->acct_ctrl, - sampass->unknown_3, - sampass->logon_divs, - sampass->hours_len, - MAX_HOURS_LEN, sampass->hours, - sampass->unknown_5, - sampass->unknown_6); + pdb_get_acct_ctrl(sampass), + pdb_get_unknown3(sampass), + pdb_get_logon_divs(sampass), + pdb_get_hours_len(sampass), + MAX_HOURS_LEN, pdb_get_hours(sampass), + pdb_get_unknown5(sampass), + pdb_get_unknown6(sampass)); /* malloc the space needed */ @@ -241,35 +290,35 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) /* now for the real call to tdb_pack() */ /* one time to get the size needed */ buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING, - sampass->logon_time, - sampass->logoff_time, - sampass->kickoff_time, - sampass->pass_last_set_time, - sampass->pass_can_change_time, - sampass->pass_must_change_time, - username, - domain, - nt_username, - full_name, - home_dir, - dir_drive, - logon_script, - profile_path, - acct_desc, - workstations, - unknown_str, - munged_dial, - sampass->user_rid, - sampass->group_rid, + time_t_len, &logon_time, + time_t_len, &logoff_time, + time_t_len, &kickoff_time, + time_t_len, &pass_last_set_time, + time_t_len, &pass_can_change_time, + time_t_len, &pass_must_change_time, + username_len, username, + domain_len, domain, + nt_username_len, nt_username, + fullname_len, fullname, + homedir_len, homedir, + dir_drive_len, dir_drive, + logon_script_len, logon_script, + profile_path_len, profile_path, + acct_desc_len, acct_desc, + workstations_len, workstations, + unknown_str_len, unknown_str, + munged_dial_len, munged_dial, + pdb_get_user_rid(sampass), + pdb_get_group_rid(sampass), 16, lm_pw, 16, nt_pw, - sampass->acct_ctrl, - sampass->unknown_3, - sampass->logon_divs, - sampass->hours_len, - MAX_HOURS_LEN, sampass->hours, - sampass->unknown_5, - sampass->unknown_6); + pdb_get_acct_ctrl(sampass), + pdb_get_unknown3(sampass), + pdb_get_logon_divs(sampass), + pdb_get_hours_len(sampass), + MAX_HOURS_LEN, pdb_get_hours(sampass), + pdb_get_unknown5(sampass), + pdb_get_unknown6(sampass)); /* check to make sure we got it correct */ @@ -333,6 +382,13 @@ SAM_ACCOUNT* pdb_getsampwent(void) struct passwd *pw; uid_t uid; gid_t gid; + char *prefix = USERPREFIX; + int prefixlen = strlen (prefix); + + /* skip all RID entries */ + while ((global_tdb_ent.key.dsize != 0) && (strncmp (global_tdb_ent.key.dptr, prefix, prefixlen))) + /* increment to next in line */ + global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); /* do we have an valid interation pointer? */ if(global_tdb_ent.passwd_tdb == NULL) @@ -493,7 +549,7 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) fstring name; pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, RIDDB_FILE_NAME); + pstrcat (tdbfile, PASSDB_FILE_NAME); /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); @@ -535,7 +591,6 @@ BOOL pdb_delete_sam_account(char *sname) TDB_DATA key, data; fstring keystr; pstring tdbfile; - uid_t uid; uint32 rid; fstring name; @@ -576,7 +631,8 @@ BOOL pdb_delete_sam_account(char *sname) } pwd = sys_getpwnam(global_sam_pass.username); - rid = pdb_uid_to_user_rid (uid); + + rid = pdb_uid_to_user_rid (pwd->pw_uid); /* it's outaa here! 8^) */ if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) @@ -586,17 +642,8 @@ BOOL pdb_delete_sam_account(char *sname) tdb_close(pwd_tdb); return False; } - tdb_close(pwd_tdb); - - pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, RIDDB_FILE_NAME); - - /* open the RID TDB */ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("Unable to open TDB rid file!")); - return False; - } + + /* delete also the RID key */ /* set the search key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); @@ -636,13 +683,14 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if ( (!newpwd->uid) || (!newpwd->gid) ) DEBUG (0,("tdb_update_sam: Storing a SAM_ACCOUNT for [%s] with uid %d and gid %d!\n", newpwd->username, newpwd->uid, newpwd->gid)); - + /* if we don't have a RID, then generate one */ if (!newpwd->user_rid) pdb_set_user_rid (newpwd, pdb_uid_to_user_rid (newpwd->uid)); if (!newpwd->group_rid) pdb_set_group_rid (newpwd, pdb_gid_to_group_rid (newpwd->gid)); - + + /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) { @@ -665,7 +713,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) tdb_close(global_tdb_ent.passwd_tdb); global_tdb_ent.passwd_tdb = NULL; } - + /* open the account TDB passwd*/ if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) { @@ -685,48 +733,25 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) /* add the account */ if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { - DEBUG(0, ("Unable to modify TDB passwd!")); + DEBUG(0, ("Unable to modify passwd TDB!")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return False; } - - /* cleanup */ - tdb_close (pwd_tdb); /* setup RID data */ data.dsize = sizeof(fstring); data.dptr = name; - pstrcpy (tdbfile, lp_private_dir()); - pstrcat (tdbfile, RIDDB_FILE_NAME); - /* setup the RID index key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); key.dptr = keystr; key.dsize = strlen (keystr) + 1; - /* open the account TDB rid file*/ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) - { - DEBUG(0, ("tdb_update_sam: Unable to open TDB rid database!\n")); - if (newtdb == FALSE) - DEBUG(0, ("WARNING: rid database missing and passdb exist, check references integrity!\n")); - if (flag == TDB_INSERT) - { - DEBUG(0, ("Unable to open TDB rid file, trying create new!\n")); - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) - { - DEBUG(0, ("Unable to create TDB rid (riddb.tdb) !!!\n")); - /* return False; */ - } - } - } - /* add the reference */ if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { - DEBUG(0, ("Unable to modify TDB rid database!")); + DEBUG(0, ("Unable to modify TDB passwd !")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return False; -- cgit From f35157f39293f9fa240a28642c41708b55d301c8 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 4 May 2001 15:44:27 +0000 Subject: Big cleanup of passdb and backends. I did some basic tests but I have probably broken something. Notably the password changing. So don't cry ;-) J.F. (This used to be commit a4a4c02b12f030a3b9e6225b999c90689dfc4719) --- source3/passdb/pdb_tdb.c | 97 +++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 39 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 8db8b2e60d..0bf8ca2da5 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -40,7 +40,7 @@ struct tdb_enum_info }; static struct tdb_enum_info global_tdb_ent; -static SAM_ACCOUNT global_sam_pass; +/*static SAM_ACCOUNT global_sam_pass;*/ /********************************************************************** Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len @@ -79,7 +79,6 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, *nt_pw_ptr; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; - /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, @@ -376,7 +375,7 @@ void pdb_endsampwent(void) /***************************************************************** Get one SAM_ACCOUNT from the TDB (next in line) *****************************************************************/ -SAM_ACCOUNT* pdb_getsampwent(void) +BOOL pdb_getsampwent(SAM_ACCOUNT *user) { TDB_DATA data; struct passwd *pw; @@ -385,6 +384,11 @@ SAM_ACCOUNT* pdb_getsampwent(void) char *prefix = USERPREFIX; int prefixlen = strlen (prefix); + if (user==NULL) { + DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n")); + return False; + } + /* skip all RID entries */ while ((global_tdb_ent.key.dsize != 0) && (strncmp (global_tdb_ent.key.dptr, prefix, prefixlen))) /* increment to next in line */ @@ -394,56 +398,55 @@ SAM_ACCOUNT* pdb_getsampwent(void) if(global_tdb_ent.passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); - return NULL; + return False; } data = tdb_fetch (global_tdb_ent.passwd_tdb, global_tdb_ent.key); if (!data.dptr) { DEBUG(5,("pdb_getsampwent: database entry not found.\n")); - return NULL; + return False; } /* unpack the buffer */ - pdb_clear_sam (&global_sam_pass); - if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); - return NULL; + return False; } /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(&global_sam_pass))) == NULL) + if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(&global_sam_pass))); - return NULL; + pdb_get_username(user))); + return False; } uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (&global_sam_pass, uid); - pdb_set_gid (&global_sam_pass, gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); /* 21 days from present */ - pdb_set_pass_must_change_time(&global_sam_pass, time(NULL)+1814400); + pdb_set_pass_must_change_time(user, time(NULL)+1814400); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_logon_script(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_profile_path(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_homedir(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); - return (&global_sam_pass); + return True; } /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ -SAM_ACCOUNT* pdb_getsampwnam (char *sname) +BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) { TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -453,7 +456,13 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) fstring name; uid_t uid; gid_t gid; - + + + if (user==NULL) { + DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); + return False; + } + fstrcpy (name, sname); strlower (name); pstrcpy (tdbfile, lp_private_dir()); @@ -478,53 +487,58 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); - return NULL; + return False; } /* unpack the buffer */ - pdb_clear_sam (&global_sam_pass); - if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + /*pdb_clear_sam (&global_sam_pass);*/ + if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); - return NULL; + return False; } /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(&global_sam_pass))) == NULL) + if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(&global_sam_pass))); - return NULL; + pdb_get_username(user))); + return False; } uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (&global_sam_pass, uid); - pdb_set_gid (&global_sam_pass, gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); /* 21 days from present */ - pdb_set_pass_must_change_time(&global_sam_pass, time(NULL)+1814400); + pdb_set_pass_must_change_time(user, time(NULL)+1814400); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_logon_script(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_profile_path(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_homedir(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); /* cleanup */ tdb_close (pwd_tdb); - return (&global_sam_pass); + return True; } /*************************************************************************** Search by uid **************************************************************************/ -SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) +BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) { struct passwd *pw; fstring name; + if (user==NULL) { + DEBUG(0,("pdb_getsampwuid: SAM_ACCOUNT is NULL.\n")); + return False; + } + pw = sys_getpwuid(uid); if (pw == NULL) { @@ -533,14 +547,14 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) } fstrcpy (name, pw->pw_name); - return pdb_getsampwnam (name); + return pdb_getsampwnam (user, name); } /*************************************************************************** Search by rid **************************************************************************/ -SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) +BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) { TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -548,6 +562,11 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) pstring tdbfile; fstring name; + if (user==NULL) { + DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n")); + return False; + } + pstrcpy (tdbfile, lp_private_dir()); pstrcat (tdbfile, PASSDB_FILE_NAME); @@ -570,14 +589,14 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); - return NULL; + return False; } fstrcpy (name, data.dptr); tdb_close (pwd_tdb); - return pdb_getsampwnam (name); + return pdb_getsampwnam (user, name); } -- cgit From 30c4c04c2f584857633ce7605555dcfb37a3e1af Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 7 May 2001 14:04:46 +0000 Subject: Patch from Simo: o sed 's/pdb_clear_sam/pdb_free_sam/g' o add pdb_reset_sam() o password changing should be ok now as well. (This used to be commit 96d0e7c3301ad990f6c83b9c216720cb32661fb5) --- source3/passdb/pdb_tdb.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0bf8ca2da5..f2b98adebd 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -79,6 +79,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, *nt_pw_ptr; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; + /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, @@ -148,6 +149,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, pdb_set_logons_divs(sampass, logon_divs); pdb_set_hours(sampass, hours); + /* TODO: free TDB alloced memory !!!!! */ return True; } @@ -491,7 +493,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) } /* unpack the buffer */ - /*pdb_clear_sam (&global_sam_pass);*/ if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); @@ -543,7 +544,7 @@ BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) if (pw == NULL) { DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist!\n", uid)); - return NULL; + return False; } fstrcpy (name, pw->pw_name); @@ -606,6 +607,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) BOOL pdb_delete_sam_account(char *sname) { struct passwd *pwd = NULL; + SAM_ACCOUNT *sam_pass = NULL; TDB_CONTEXT *pwd_tdb; TDB_DATA key, data; fstring keystr; @@ -642,14 +644,22 @@ BOOL pdb_delete_sam_account(char *sname) } /* unpack the buffer */ - pdb_clear_sam (&global_sam_pass); - if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + if (!pdb_init_sam (&sam_pass)) + { + tdb_close (pwd_tdb); + return False; + } + + if (!init_sam_from_buffer (sam_pass, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + tdb_close (pwd_tdb); return False; } - pwd = sys_getpwnam(global_sam_pass.username); + pwd = sys_getpwnam(sam_pass->username); + + pdb_free_sam (sam_pass); rid = pdb_uid_to_user_rid (pwd->pw_uid); -- cgit From fcc23d40dcb017fe5cff761c4633f95d025eb3f1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 May 2001 20:52:20 +0000 Subject: update from Simo (This used to be commit 9e4a6c227f719226cac6e00f1a6719651570e2c7) --- source3/passdb/pdb_tdb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index f2b98adebd..dc80c6250b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -187,7 +187,8 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) uint8 *lm_pw; uint8 *nt_pw; uint32 time_t_len = sizeof (time_t); - char null_pw[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + uint32 lm_pw_len = 16; + uint32 nt_pw_len = 16; /* do we have a valid SAM_ACCOUNT pointer? */ if (sampass == NULL) @@ -242,12 +243,11 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) else workstations_len = 0; lm_pw = pdb_get_lanman_passwd(sampass); - if (!lm_pw) pdb_gethexpwd (null_pw, lm_pw); + if (!lm_pw) lm_pw_len = 0; nt_pw = pdb_get_nt_passwd(sampass); - if (!nt_pw) pdb_gethexpwd (null_pw, nt_pw); + if (!nt_pw) nt_pw_len = 0; - /* one time to get the size needed */ len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, time_t_len, &logon_time, @@ -270,8 +270,8 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) munged_dial_len, munged_dial, pdb_get_user_rid(sampass), pdb_get_group_rid(sampass), - 16, lm_pw, - 16, nt_pw, + lm_pw_len, lm_pw, + nt_pw_len, nt_pw, pdb_get_acct_ctrl(sampass), pdb_get_unknown3(sampass), pdb_get_logon_divs(sampass), @@ -311,8 +311,8 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) munged_dial_len, munged_dial, pdb_get_user_rid(sampass), pdb_get_group_rid(sampass), - 16, lm_pw, - 16, nt_pw, + lm_pw_len, lm_pw, + nt_pw_len, nt_pw, pdb_get_acct_ctrl(sampass), pdb_get_unknown3(sampass), pdb_get_logon_divs(sampass), -- cgit From 05fc3e578c895f632b351969d09cd00feb7599c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jun 2001 05:13:59 +0000 Subject: use LDSHFLAGS not -shared in several places (This used to be commit 8ec9c87b5d1a7dae17d5b1a30f58effaf5e69e4b) --- source3/passdb/pdb_tdb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index dc80c6250b..0816ac9a99 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -344,10 +344,10 @@ BOOL pdb_setsampwent(BOOL update) pstrcat (tdbfile, PASSDB_FILE_NAME); /* Open tdb passwd */ - if (!(global_tdb_ent.passwd_tdb = tdb_open(tdbfile, 0, 0, update ? O_RDWR : O_RDONLY, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, 0, update ? O_RDWR : O_RDONLY, 0600))) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(global_tdb_ent.passwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!")); return False; @@ -476,7 +476,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDONLY, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd!\n")); return False; @@ -577,7 +577,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDONLY, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return False; @@ -622,7 +622,7 @@ BOOL pdb_delete_sam_account(char *sname) pstrcat (tdbfile, PASSDB_FILE_NAME); /* open the TDB */ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR, 0600))) { DEBUG(0, ("Unable to open TDB passwd!")); return False; @@ -744,13 +744,13 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } /* open the account TDB passwd*/ - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR, 0600))) { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); if (flag == TDB_INSERT) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(pwd_tdb = tdb_open(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); return False; -- cgit From afa73000063d7c3eb94ccc7b423c8a7bea28f9a5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 12 Jul 2001 22:27:00 +0000 Subject: Changed instances of TRUE, FALSE to True, False as some compilers don't have the first set of symbols. (This used to be commit ad0cbfbd790bc5d6003ffcff2835d82fb0140625) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0816ac9a99..5ee7a37915 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -755,7 +755,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); return False; } - newtdb = TRUE; + newtdb = True; } } -- cgit From 996719cce26700c68ff0e456e6a25d20085d091f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Jul 2001 22:21:31 +0000 Subject: Added "use mmap" for HPUX. Jeremy. (This used to be commit 840802f10677cb0009cb4df4c37c7d01aa5edacd) --- source3/passdb/pdb_tdb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 5ee7a37915..fc19f27918 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -344,10 +344,10 @@ BOOL pdb_setsampwent(BOOL update) pstrcat (tdbfile, PASSDB_FILE_NAME); /* Open tdb passwd */ - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, 0, update ? O_RDWR : O_RDONLY, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, update ? O_RDWR : O_RDONLY, 0600))) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!")); return False; @@ -476,7 +476,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDONLY, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd!\n")); return False; @@ -577,7 +577,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDONLY, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return False; @@ -622,7 +622,7 @@ BOOL pdb_delete_sam_account(char *sname) pstrcat (tdbfile, PASSDB_FILE_NAME); /* open the TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR, 0600))) { DEBUG(0, ("Unable to open TDB passwd!")); return False; @@ -744,13 +744,13 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } /* open the account TDB passwd*/ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR, 0600))) { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); if (flag == TDB_INSERT) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, 0, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); return False; -- cgit From 137fb61490080c3419e109dbfd40aca14caa4c95 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 31 Aug 2001 01:29:53 +0000 Subject: changed the data format in the tdb, as the time fields were not managed correctly. this mean you need to rebuild your passdb.tdb file. (This used to be commit 57b8d3bb84e261e55febdde88e45684455f0a294) --- source3/passdb/pdb_tdb.c | 53 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index fc19f27918..909a5d809f 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -23,8 +23,9 @@ #ifdef WITH_TDBPWD +#define PDB_VERSION "20010830" #define PASSDB_FILE_NAME "/passdb.tdb" -#define TDB_FORMAT_STRING "BBBBBBBBBBBBBBBBBBddBBwdwdBdd" +#define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd" #define USERPREFIX "USER_" #define RIDPREFIX "RID_" @@ -48,13 +49,16 @@ static struct tdb_enum_info global_tdb_ent; static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) { - time_t logon_time, + + /* times are stored as 32bit integer + take care on system with 64bit wide time_t + --SSS */ + uint32 logon_time, logoff_time, kickoff_time, pass_last_set_time, pass_can_change_time, pass_must_change_time; - uint32 time_t_len; char *username; char *domain; char *nt_username; @@ -83,12 +87,12 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, - &time_t_len, &logon_time, - &time_t_len, &logoff_time, - &time_t_len, &kickoff_time, - &time_t_len, &pass_last_set_time, - &time_t_len, &pass_can_change_time, - &time_t_len, &pass_must_change_time, + &logon_time, + &logoff_time, + &kickoff_time, + &pass_last_set_time, + &pass_can_change_time, + &pass_must_change_time, &username_len, &username, &domain_len, &domain, &nt_username_len, &nt_username, @@ -161,7 +165,10 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) { size_t len, buflen; - time_t logon_time, + /* times are stored as 32bit integer + take care on system with 64bit wide time_t + --SSS */ + uint32 logon_time, logoff_time, kickoff_time, pass_last_set_time, @@ -186,7 +193,6 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) uint8 *lm_pw; uint8 *nt_pw; - uint32 time_t_len = sizeof (time_t); uint32 lm_pw_len = 16; uint32 nt_pw_len = 16; @@ -250,12 +256,12 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) /* one time to get the size needed */ len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, - time_t_len, &logon_time, - time_t_len, &logoff_time, - time_t_len, &kickoff_time, - time_t_len, &pass_last_set_time, - time_t_len, &pass_can_change_time, - time_t_len, &pass_must_change_time, + logon_time, + logoff_time, + kickoff_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time, username_len, username, domain_len, domain, nt_username_len, nt_username, @@ -289,14 +295,13 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) } /* now for the real call to tdb_pack() */ - /* one time to get the size needed */ buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING, - time_t_len, &logon_time, - time_t_len, &logoff_time, - time_t_len, &kickoff_time, - time_t_len, &pass_last_set_time, - time_t_len, &pass_can_change_time, - time_t_len, &pass_must_change_time, + logon_time, + logoff_time, + kickoff_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time, username_len, username, domain_len, domain, nt_username_len, nt_username, -- cgit From 9a9ac2739bbdc993ecdfa78298bdd9c059328378 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Sep 2001 22:08:19 +0000 Subject: got rid of USE_TDB_MMAP_FLAG as its not needed any more (This used to be commit c26e0d3f27a05ecc8bd2390f9aab7f9451524e47) --- source3/passdb/pdb_tdb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 909a5d809f..6da6215c79 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -349,10 +349,10 @@ BOOL pdb_setsampwent(BOOL update) pstrcat (tdbfile, PASSDB_FILE_NAME); /* Open tdb passwd */ - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, update ? O_RDWR : O_RDONLY, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, update ? O_RDWR : O_RDONLY, 0600))) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!")); return False; @@ -481,7 +481,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd!\n")); return False; @@ -582,7 +582,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return False; @@ -627,7 +627,7 @@ BOOL pdb_delete_sam_account(char *sname) pstrcat (tdbfile, PASSDB_FILE_NAME); /* open the TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) { DEBUG(0, ("Unable to open TDB passwd!")); return False; @@ -749,13 +749,13 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } /* open the account TDB passwd*/ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); if (flag == TDB_INSERT) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, USE_TDB_MMAP_FLAG, O_RDWR | O_CREAT | O_EXCL, 0600))) + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); return False; -- cgit From a3203a7b16bad20d705eb385f68b85b14c1fcae0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 14 Sep 2001 15:33:09 +0000 Subject: merges from 2.2 (This used to be commit b619458dde158c37a4420a28a7e1e1f70e7a18d1) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6da6215c79..28fbb52209 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -21,7 +21,7 @@ #include "includes.h" -#ifdef WITH_TDBPWD +#ifdef WITH_TDBSAM #define PDB_VERSION "20010830" #define PASSDB_FILE_NAME "/passdb.tdb" @@ -817,4 +817,4 @@ BOOL pdb_add_sam_account (SAM_ACCOUNT *newpwd) #else /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */ void samtdb_dummy_function(void) { } /* stop some compilers complaining */ -#endif /* WITH_TDBPWD */ +#endif /* WITH_TDBSAM */ -- cgit From 4561e8a8ea35f3703ff607f604b5e25cd6144da1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 05:04:17 +0000 Subject: move to SAFE_FREE() (This used to be commit 64d35e94fe6f7e56353b286162f670c8595a90e6) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 28fbb52209..6aa26bea53 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -331,7 +331,7 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) if (buflen != len) { /* error */ - free (*buf); + SAFE_FREE (*buf); return (-1); } -- cgit From 76c8d7a579bbed73c1cd2dd30a1336cc87851c36 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 25 Sep 2001 09:58:36 +0000 Subject: memory leak fixes .. (This used to be commit 7f07004571ad1b8d1ce787f6788b4c4d8685db37) --- source3/passdb/pdb_tdb.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6aa26bea53..66ebb73b1a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -419,8 +419,10 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + SAFE_FREE(data.dptr); return False; } + SAFE_FREE(data.dptr); /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case @@ -501,8 +503,10 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + SAFE_FREE(data.dptr); return False; } + SAFE_FREE(data.dptr); /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case @@ -599,6 +603,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) } fstrcpy (name, data.dptr); + SAFE_FREE(data.dptr); tdb_close (pwd_tdb); @@ -659,8 +664,10 @@ BOOL pdb_delete_sam_account(char *sname) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); tdb_close (pwd_tdb); + SAFE_FREE(data.dptr); return False; } + SAFE_FREE(data.dptr); pwd = sys_getpwnam(sam_pass->username); @@ -709,6 +716,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) fstring keystr; pstring tdbfile; fstring name; + BOOL ret = True; int newtdb = FALSE; pstrcpy (tdbfile, lp_private_dir()); @@ -729,7 +737,8 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); - return False; + ret = False; + goto done; } data.dptr = buf; @@ -758,7 +767,8 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); - return False; + ret = False; + goto done; } newtdb = True; } @@ -770,7 +780,8 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) DEBUG(0, ("Unable to modify passwd TDB!")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); - return False; + ret = False; + goto done; } /* setup RID data */ @@ -787,14 +798,17 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) { DEBUG(0, ("Unable to modify TDB passwd !")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close (pwd_tdb); - return False; + ret = False; + goto done; } - + +done: /* cleanup */ tdb_close (pwd_tdb); + SAFE_FREE(buf); + + return (ret); - return (True); } /*************************************************************************** -- cgit From 00842ae2530a67129c9885e4e9bec914c9743a93 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Sep 2001 14:40:25 +0000 Subject: Don't segfault when deleting accounts not in /etc/passwd. The RID we want is the one in the sampass anyway. Andrew Bartlett (This used to be commit 29b7434293d7778376486b241f9458a71fa843a6) --- source3/passdb/pdb_tdb.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 66ebb73b1a..cf2a7f2ec1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -616,7 +616,6 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) ****************************************************************************/ BOOL pdb_delete_sam_account(char *sname) { - struct passwd *pwd = NULL; SAM_ACCOUNT *sam_pass = NULL; TDB_CONTEXT *pwd_tdb; TDB_DATA key, data; @@ -669,12 +668,10 @@ BOOL pdb_delete_sam_account(char *sname) } SAFE_FREE(data.dptr); - pwd = sys_getpwnam(sam_pass->username); - + rid = pdb_get_user_rid(sam_pass); + pdb_free_sam (sam_pass); - rid = pdb_uid_to_user_rid (pwd->pw_uid); - /* it's outaa here! 8^) */ if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { -- cgit From 6ddcd8a3bcef32694d9d753ff91cced71f5ca3a8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Sep 2001 20:21:21 +0000 Subject: Fixup passdb stuff to add new nisplus and ldap backends. Jeremy. (This used to be commit 611bf806d569b70edabbc04a2f5408142370a550) --- source3/passdb/pdb_tdb.c | 243 +++++++++++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 116 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index cf2a7f2ec1..700a241be8 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -3,6 +3,7 @@ * Copyright (C) Andrew Tridgell 1992-1998 * Copyright (C) Simo Sorce 2000 * Copyright (C) Gerald Carter 2000 + * Copyright (C) Jeremy Allison 2001 * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -21,7 +22,7 @@ #include "includes.h" -#ifdef WITH_TDBSAM +#ifdef WITH_TDB_SAM #define PDB_VERSION "20010830" #define PASSDB_FILE_NAME "/passdb.tdb" @@ -33,9 +34,7 @@ extern int DEBUGLEVEL; extern pstring samlogon_user; extern BOOL sam_logon_in_ssb; - -struct tdb_enum_info -{ +struct tdb_enum_info { TDB_CONTEXT *passwd_tdb; TDB_DATA key; }; @@ -46,8 +45,8 @@ static struct tdb_enum_info global_tdb_ent; /********************************************************************** Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len *********************************************************************/ -static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, - uint32 buflen) + +static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) { /* times are stored as 32bit integer @@ -79,11 +78,10 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 /* uid, gid,*/ user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6; uint16 acct_ctrl, logon_divs; uint8 *hours; - static uint8 *lm_pw_ptr, - *nt_pw_ptr; + static uint8 *lm_pw_ptr, *nt_pw_ptr; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; - + BOOL ret = True; /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, @@ -117,8 +115,10 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, &unknown_5, &unknown_6); - if (len == -1) - return False; + if (len == -1) { + ret = False; + goto done; + } pdb_set_logon_time(sampass, logon_time); pdb_set_logoff_time(sampass, logoff_time); @@ -153,9 +153,21 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, pdb_set_logons_divs(sampass, logon_divs); pdb_set_hours(sampass, hours); - /* TODO: free TDB alloced memory !!!!! */ - - return True; +done: + + SAFE_FREE(username); + SAFE_FREE(domain); + SAFE_FREE(nt_username); + SAFE_FREE(fullname); + SAFE_FREE(homedir); + SAFE_FREE(dir_drive); + SAFE_FREE(logon_script); + SAFE_FREE(profile_path); + SAFE_FREE(acct_desc); + SAFE_FREE(workstations); + SAFE_FREE(munged_dial); + + return ret; } /********************************************************************** @@ -203,56 +215,80 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) *buf = NULL; buflen = 0; - logon_time = pdb_get_logon_time(sampass); - logoff_time = pdb_get_logoff_time(sampass); - kickoff_time = pdb_get_kickoff_time(sampass); - pass_can_change_time = pdb_get_pass_can_change_time(sampass); - pass_must_change_time = pdb_get_pass_must_change_time(sampass); - pass_last_set_time = pdb_get_pass_last_set_time(sampass); + logon_time = (uint32)pdb_get_logon_time(sampass); + logoff_time = (uint32)pdb_get_logoff_time(sampass); + kickoff_time = (uint32)pdb_get_kickoff_time(sampass); + pass_can_change_time = (uint32)pdb_get_pass_can_change_time(sampass); + pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass); + pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass); username = pdb_get_username(sampass); - if (username) username_len = strlen(username) +1; - else username_len = 0; + if (username) + username_len = strlen(username) +1; + else + username_len = 0; domain = pdb_get_domain(sampass); - if (domain) domain_len = strlen(domain) +1; - else domain_len = 0; + if (domain) + domain_len = strlen(domain) +1; + else + domain_len = 0; nt_username = pdb_get_nt_username(sampass); - if (nt_username) nt_username_len = strlen(nt_username) +1; - else nt_username_len = 0; + if (nt_username) + nt_username_len = strlen(nt_username) +1; + else + nt_username_len = 0; dir_drive = pdb_get_dirdrive(sampass); - if (dir_drive) dir_drive_len = strlen(dir_drive) +1; - else dir_drive_len = 0; + if (dir_drive) + dir_drive_len = strlen(dir_drive) +1; + else + dir_drive_len = 0; unknown_str = NULL; unknown_str_len = 0; munged_dial = pdb_get_munged_dial(sampass); - if (munged_dial) munged_dial_len = strlen(munged_dial) +1; - else munged_dial_len = 0; + if (munged_dial) + munged_dial_len = strlen(munged_dial) +1; + else + munged_dial_len = 0; fullname = pdb_get_fullname(sampass); - if (fullname) fullname_len = strlen(fullname) +1; - else fullname_len = 0; + if (fullname) + fullname_len = strlen(fullname) +1; + else + fullname_len = 0; homedir = pdb_get_homedir(sampass); - if (homedir) homedir_len = strlen(homedir) +1; - else homedir_len = 0; + if (homedir) + homedir_len = strlen(homedir) +1; + else + homedir_len = 0; logon_script = pdb_get_logon_script(sampass); - if (logon_script) logon_script_len = strlen(logon_script) +1; - else logon_script_len = 0; + if (logon_script) + logon_script_len = strlen(logon_script) +1; + else + logon_script_len = 0; profile_path = pdb_get_profile_path(sampass); - if (profile_path) profile_path_len = strlen(profile_path) +1; - else profile_path_len = 0; + if (profile_path) + profile_path_len = strlen(profile_path) +1; + else + profile_path_len = 0; acct_desc = pdb_get_acct_desc(sampass); - if (acct_desc) acct_desc_len = strlen(acct_desc) +1; - else acct_desc_len = 0; + if (acct_desc) + acct_desc_len = strlen(acct_desc) +1; + else + acct_desc_len = 0; workstations = pdb_get_workstations(sampass); - if (workstations) workstations_len = strlen(workstations) +1; - else workstations_len = 0; + if (workstations) + workstations_len = strlen(workstations) +1; + else + workstations_len = 0; lm_pw = pdb_get_lanman_passwd(sampass); - if (!lm_pw) lm_pw_len = 0; + if (!lm_pw) + lm_pw_len = 0; nt_pw = pdb_get_nt_passwd(sampass); - if (!nt_pw) nt_pw_len = 0; + if (!nt_pw) + nt_pw_len = 0; /* one time to get the size needed */ len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, @@ -288,8 +324,7 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) /* malloc the space needed */ - if ( (*buf=(uint8*)malloc(len)) == NULL) - { + if ( (*buf=(uint8*)malloc(len)) == NULL) { DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n")); return (-1); } @@ -328,8 +363,7 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) /* check to make sure we got it correct */ - if (buflen != len) - { + if (buflen != len) { /* error */ SAFE_FREE (*buf); return (-1); @@ -341,19 +375,18 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) /*************************************************************** Open the TDB passwd database for SAM account enumeration. ****************************************************************/ + BOOL pdb_setsampwent(BOOL update) { pstring tdbfile; - pstrcpy (tdbfile, lp_private_dir()); + get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); /* Open tdb passwd */ - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, update ? O_RDWR : O_RDONLY, 0600))) - { + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, update ? O_RDWR : O_RDONLY, 0600))) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) - { + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!")); return False; } @@ -367,10 +400,10 @@ BOOL pdb_setsampwent(BOOL update) /*************************************************************** End enumeration of the TDB passwd list. ****************************************************************/ + void pdb_endsampwent(void) { - if (global_tdb_ent.passwd_tdb) - { + if (global_tdb_ent.passwd_tdb) { tdb_close(global_tdb_ent.passwd_tdb); global_tdb_ent.passwd_tdb = NULL; } @@ -378,10 +411,10 @@ void pdb_endsampwent(void) DEBUG(7, ("endtdbpwent: closed password file.\n")); } - /***************************************************************** Get one SAM_ACCOUNT from the TDB (next in line) *****************************************************************/ + BOOL pdb_getsampwent(SAM_ACCOUNT *user) { TDB_DATA data; @@ -402,22 +435,19 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); /* do we have an valid interation pointer? */ - if(global_tdb_ent.passwd_tdb == NULL) - { + if(global_tdb_ent.passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); return False; } data = tdb_fetch (global_tdb_ent.passwd_tdb, global_tdb_ent.key); - if (!data.dptr) - { + if (!data.dptr) { DEBUG(5,("pdb_getsampwent: database entry not found.\n")); return False; } /* unpack the buffer */ - if (!init_sam_from_buffer (user, data.dptr, data.dsize)) - { + if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); return False; @@ -427,8 +457,7 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) - { + if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", pdb_get_username(user))); return False; @@ -455,6 +484,7 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ + BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) { TDB_CONTEXT *pwd_tdb; @@ -473,8 +503,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) } fstrcpy (name, sname); - strlower (name); - pstrcpy (tdbfile, lp_private_dir()); + get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); /* set search key */ @@ -483,16 +512,14 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) - { + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd!\n")); return False; } /* get the record */ data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) - { + if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); @@ -500,8 +527,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) } /* unpack the buffer */ - if (!init_sam_from_buffer (user, data.dptr, data.dsize)) - { + if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); return False; @@ -511,8 +537,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) - { + if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", pdb_get_username(user))); return False; @@ -539,6 +564,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) /*************************************************************************** Search by uid **************************************************************************/ + BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) { struct passwd *pw; @@ -550,8 +576,7 @@ BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) } pw = sys_getpwuid(uid); - if (pw == NULL) - { + if (pw == NULL) { DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist!\n", uid)); return False; } @@ -564,6 +589,7 @@ BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) /*************************************************************************** Search by rid **************************************************************************/ + BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) { TDB_CONTEXT *pwd_tdb; @@ -577,7 +603,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) return False; } - pstrcpy (tdbfile, lp_private_dir()); + get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); /* set search key */ @@ -586,16 +612,14 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) - { + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return False; } /* get the record */ data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) - { + if (!data.dptr) { DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); @@ -610,10 +634,10 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) return pdb_getsampwnam (user, name); } - /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ + BOOL pdb_delete_sam_account(char *sname) { SAM_ACCOUNT *sam_pass = NULL; @@ -627,12 +651,11 @@ BOOL pdb_delete_sam_account(char *sname) fstrcpy (name, sname); strlower (name); - pstrcpy (tdbfile, lp_private_dir()); + get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); /* open the TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) - { + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) { DEBUG(0, ("Unable to open TDB passwd!")); return False; } @@ -644,8 +667,7 @@ BOOL pdb_delete_sam_account(char *sname) /* get the record */ data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) - { + if (!data.dptr) { DEBUG(5,("pdb_delete_sam_account (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); @@ -653,14 +675,12 @@ BOOL pdb_delete_sam_account(char *sname) } /* unpack the buffer */ - if (!pdb_init_sam (&sam_pass)) - { + if (!pdb_init_sam (&sam_pass)) { tdb_close (pwd_tdb); return False; } - if (!init_sam_from_buffer (sam_pass, data.dptr, data.dsize)) - { + if (!init_sam_from_buffer (sam_pass, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); tdb_close (pwd_tdb); SAFE_FREE(data.dptr); @@ -673,8 +693,7 @@ BOOL pdb_delete_sam_account(char *sname) pdb_free_sam (sam_pass); /* it's outaa here! 8^) */ - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) - { + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close(pwd_tdb); @@ -689,8 +708,7 @@ BOOL pdb_delete_sam_account(char *sname) key.dsize = strlen (keystr) + 1; /* it's outaa here! 8^) */ - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) - { + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { DEBUG(5, ("Error deleting entry from tdb rid database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close(pwd_tdb); @@ -705,6 +723,7 @@ BOOL pdb_delete_sam_account(char *sname) /*************************************************************************** Update the TDB SAM ****************************************************************************/ + static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) { TDB_CONTEXT *pwd_tdb; @@ -716,7 +735,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) BOOL ret = True; int newtdb = FALSE; - pstrcpy (tdbfile, lp_private_dir()); + get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); if ( (!newpwd->uid) || (!newpwd->gid) ) @@ -729,10 +748,8 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if (!newpwd->group_rid) pdb_set_group_rid (newpwd, pdb_gid_to_group_rid (newpwd->gid)); - /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ - if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) - { + if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); ret = False; goto done; @@ -748,21 +765,17 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) key.dsize = strlen (keystr) + 1; /* invalidate the existing TDB iterator if it is open */ - if (global_tdb_ent.passwd_tdb) - { + if (global_tdb_ent.passwd_tdb) { tdb_close(global_tdb_ent.passwd_tdb); global_tdb_ent.passwd_tdb = NULL; } /* open the account TDB passwd*/ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) - { - DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); - if (flag == TDB_INSERT) - { + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) { + DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); + if (flag == TDB_INSERT) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) - { + if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); ret = False; goto done; @@ -772,8 +785,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } /* add the account */ - if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) - { + if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify passwd TDB!")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); @@ -791,8 +803,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) key.dsize = strlen (keystr) + 1; /* add the reference */ - if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) - { + if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify TDB passwd !")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); ret = False; @@ -800,17 +811,17 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } done: + /* cleanup */ tdb_close (pwd_tdb); SAFE_FREE(buf); - return (ret); - } /*************************************************************************** Modifies an existing SAM_ACCOUNT ****************************************************************************/ + BOOL pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override) { return (tdb_update_sam(newpwd, override, TDB_MODIFY)); @@ -819,13 +830,13 @@ BOOL pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override) /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ + BOOL pdb_add_sam_account (SAM_ACCOUNT *newpwd) { return (tdb_update_sam(newpwd, True, TDB_INSERT)); } - #else /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */ void samtdb_dummy_function(void) { } /* stop some compilers complaining */ -#endif /* WITH_TDBSAM */ +#endif /* WITH_TDB_SAM */ -- cgit From f12ebc00a847e5d38e0a591e8958c4e71f2c2842 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Sep 2001 11:36:37 +0000 Subject: Fix up TDB_SAM with repect to case sensitvity. (need to use unix_strlower) Also attempt to make some of the syntax clearer, its confusing enought for the compiler... (it thinks that there is use of an unitilaised variable) In fact there is, see next patch... (This used to be commit 540abc8125f1b821bd362dc0d8c19a107382479f) --- source3/passdb/pdb_tdb.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 700a241be8..8ec0e82c3e 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -502,7 +502,9 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) return False; } - fstrcpy (name, sname); + /* Data is stored in all lower-case */ + unix_strlower(sname, -1, name, sizeof(name)); + get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); @@ -648,8 +650,7 @@ BOOL pdb_delete_sam_account(char *sname) uint32 rid; fstring name; - fstrcpy (name, sname); - strlower (name); + unix_strlower(sname, -1, name, sizeof(name)); get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); @@ -756,8 +757,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } data.dptr = buf; - fstrcpy (name, pdb_get_username(newpwd)); - strlower (name); + unix_strlower(pdb_get_username(newpwd), -1, name, sizeof(name)); /* setup the USER index key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); @@ -771,11 +771,13 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } /* open the account TDB passwd*/ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) { + pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600); + if (!pwd_tdb) { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); if (flag == TDB_INSERT) { DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { + pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600); + if (!pwd_tdb) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); ret = False; goto done; -- cgit From 1ef468f805d415e587e2f9a242fa934670ea9330 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Sep 2001 11:44:25 +0000 Subject: Fix the uninitialised variable, but more importantly fix the SEGFAULT. Merge for 2.2.2 Should TDB cope with TDB pointers itself? Andrew Bartlett (This used to be commit 27f0510a0b458792293d5ce2957f61383569f62f) --- source3/passdb/pdb_tdb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 8ec0e82c3e..6702926355 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -727,7 +727,7 @@ BOOL pdb_delete_sam_account(char *sname) static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) { - TDB_CONTEXT *pwd_tdb; + TDB_CONTEXT *pwd_tdb = NULL; TDB_DATA key, data; uint8 *buf = NULL; fstring keystr; @@ -780,7 +780,7 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) if (!pwd_tdb) { DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); ret = False; - goto done; + goto reallydone; } newtdb = True; } @@ -816,6 +816,8 @@ done: /* cleanup */ tdb_close (pwd_tdb); + +reallydone: SAFE_FREE(buf); return (ret); } -- cgit From 59a02ecae1b0251da5cdd5e34653f7eb14704e72 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 27 Sep 2001 02:05:30 +0000 Subject: minor fixes (This used to be commit 57e639bbdd115b51362caf7e3db4ba34ccdeddc2) --- source3/passdb/pdb_tdb.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6702926355..990d0077b2 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -384,12 +384,10 @@ BOOL pdb_setsampwent(BOOL update) pstrcat (tdbfile, PASSDB_FILE_NAME); /* Open tdb passwd */ - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, update ? O_RDWR : O_RDONLY, 0600))) { - DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600))) { - DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!")); - return False; - } + if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600))) + { + DEBUG(0, ("Unable to open/create TDB passwd\n")); + return False; } global_tdb_ent.key = tdb_firstkey(global_tdb_ent.passwd_tdb); @@ -771,19 +769,11 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } /* open the account TDB passwd*/ - pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600); - if (!pwd_tdb) { + pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); + if (!pwd_tdb) + { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); - if (flag == TDB_INSERT) { - DEBUG(0, ("Unable to open TDB passwd, trying create new!\n")); - pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL, 0600); - if (!pwd_tdb) { - DEBUG(0, ("Unable to create TDB passwd (passdb.tdb) !!!\n")); - ret = False; - goto reallydone; - } - newtdb = True; - } + return False; } /* add the account */ @@ -813,13 +803,11 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) } done: - /* cleanup */ tdb_close (pwd_tdb); - -reallydone: SAFE_FREE(buf); - return (ret); + + return (ret); } /*************************************************************************** -- cgit From a28dd18fe7d88f7d229f2746ac05f9f9e7978cfe Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 Sep 2001 13:14:19 +0000 Subject: This is the passdb section of the previously mentioned commit. Of particular note is the change to pdb_free_sam() to take its sam argument by reference, allowing it to be NULLified by the SAFE_FREE() macro, and the changed to local_password_change() both to make it work and to remove the duplicate code that caused so much breakage over the last few days. - Small change in behaviour: when LOCAL_ADD_USER is set, the user doesn't actually exist locally but does exist in the passdb we don't attempt to do a GetPwnam(). (How the entry got there is another matter, and most passdbs won't allow this anyway). Andrew Bartlett (This used to be commit 6b45e342fd1ed82d7f5bd613048fe862a6a6f2a1) --- source3/passdb/pdb_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 990d0077b2..9b932b7821 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -689,7 +689,7 @@ BOOL pdb_delete_sam_account(char *sname) rid = pdb_get_user_rid(sam_pass); - pdb_free_sam (sam_pass); + pdb_free_sam (&sam_pass); /* it's outaa here! 8^) */ if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { @@ -732,7 +732,6 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) pstring tdbfile; fstring name; BOOL ret = True; - int newtdb = FALSE; get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); -- cgit From c6d1e756649408412d72e5ad2789804b2908b6f2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Oct 2001 10:54:11 +0000 Subject: - fix handling of 0 last_change_time and must_change_time - move the arbitrary 21 day timeout to local.h (This used to be commit 11075f543470c3283accce0246d0b2983420695a) --- source3/passdb/pdb_tdb.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 9b932b7821..43eefa5c7a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -466,9 +466,6 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) pdb_set_uid (user, uid); pdb_set_gid (user, gid); - /* 21 days from present */ - pdb_set_pass_must_change_time(user, time(NULL)+1814400); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); -- cgit From 0db1899256517507fb5a441bd75725e3fcecc2e8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 29 Oct 2001 07:24:49 +0000 Subject: This commit is number 2 of 4. In particular this commit focuses on: The guts of the moving about inside passdb. While these changes have been mildly tested, and are pretty small, any assistance in this is appreciated. ---- These changes allow for the introduction of a large dose of 'const' to the Samba tree. There are a number of good reasons to do this: - I want to allow the SAM_ACCOUNT structure to move from wasteful pstrings and fstrings to allocated strings. We can't do that if people are modifying these outputs, as they may well make assumptions about getting pstrings and fstrings - I want --with-pam_smbpass to compile with a slightly sane volume of warnings, currently its pretty bad, even in 2.2 where is compiles at all. - Tridge assures me that he no longer opposes 'const religion' based on the ability to #define const the problem away. - Changed Get_Pwnam(x,y) into two variants (so that the const parameter can work correctly): - Get_Pwnam(const x) and Get_Pwnam_Modify(x). - Reworked smbd/chgpasswd.c to work with these mods, passing around a 'struct passwd' rather than the modified username passdb/ - Kill off disp_info stuff, it isn't used any more - Kill off support for writing to the old smbpasswd format, it isn't relevent to Samba 3.0 - Move around and modify the pdb_...() helper functions, adding one that sets the last changed time to 'now' and that sets the must change time appropriately. - Remove the ugly forced update of the LCT- value in pdb_smbpasswd. - Remove the implicit modification of the ACB flags when both NT and LM passwords are set. - Removed substation in pdb_getsampwnam output, as a single password change will render them inoperable in any case (they will be substituted and stored) - Added a default RID to the init_sam_from_pw() function, based on our rid algorithm. - Added checks that an smbpasswd stored user has a uid-based RID. - Fail to store tdb based users without a RID lib/ - Change the substituion code to use global_myname if there is no connection (and therefore no called name) at the present time. (This used to be commit 8f607810eb24ed1157bbd2e896c2c167bc34d986) --- source3/passdb/pdb_tdb.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 43eefa5c7a..95f66fc671 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -466,10 +466,6 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) pdb_set_uid (user, uid); pdb_set_gid (user, gid); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); - /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -545,13 +541,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) pdb_set_uid (user, uid); pdb_set_gid (user, gid); - /* 21 days from present */ - pdb_set_pass_must_change_time(user, time(NULL)+1814400); - - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); - /* cleanup */ tdb_close (pwd_tdb); @@ -720,7 +709,7 @@ BOOL pdb_delete_sam_account(char *sname) Update the TDB SAM ****************************************************************************/ -static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) +static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) { TDB_CONTEXT *pwd_tdb = NULL; TDB_DATA key, data; @@ -733,15 +722,15 @@ static BOOL tdb_update_sam(SAM_ACCOUNT* newpwd, BOOL override, int flag) get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); - if ( (!newpwd->uid) || (!newpwd->gid) ) + if ( (!pdb_get_uid(newpwd)) || (!pdb_get_gid(newpwd)) ) DEBUG (0,("tdb_update_sam: Storing a SAM_ACCOUNT for [%s] with uid %d and gid %d!\n", - newpwd->username, newpwd->uid, newpwd->gid)); + pdb_get_username(newpwd), pdb_get_uid(newpwd), pdb_get_gid(newpwd))); - /* if we don't have a RID, then generate one */ - if (!newpwd->user_rid) - pdb_set_user_rid (newpwd, pdb_uid_to_user_rid (newpwd->uid)); - if (!newpwd->group_rid) - pdb_set_group_rid (newpwd, pdb_gid_to_group_rid (newpwd->gid)); + /* if we don't have a RID, then FAIL */ + if (!pdb_get_user_rid(newpwd)) + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); + if (!pdb_get_group_rid(newpwd)) + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) { -- cgit From d9d7f023d8d11943ca0375e1573e6ec9921889bc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 29 Oct 2001 07:35:11 +0000 Subject: This commit is number 4 of 4. In particular this commit focuses on: Actually adding the 'const' to the passdb interface, and the flow-on changes. Also kill off the 'disp_info' stuff, as its no longer used. While these changes have been mildly tested, and are pretty small, any assistance in this is appreciated. ---- These changes introduces a large dose of 'const' to the Samba tree. There are a number of good reasons to do this: - I want to allow the SAM_ACCOUNT structure to move from wasteful pstrings and fstrings to allocated strings. We can't do that if people are modifying these outputs, as they may well make assumptions about getting pstrings and fstrings - I want --with-pam_smbpass to compile with a slightly sane volume of warnings, currently its pretty bad, even in 2.2 where is compiles at all. - Tridge assures me that he no longer opposes 'const religion' based on the ability to #define const the problem away. - Changed Get_Pwnam(x,y) into two variants (so that the const parameter can work correctly): - Get_Pwnam(const x) and Get_Pwnam_Modify(x). - Reworked smbd/chgpasswd.c to work with these mods, passing around a 'struct passwd' rather than the modified username --- This finishes this line of commits off, your tree should now compile again :-) Andrew Bartlett (This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317) --- source3/passdb/pdb_tdb.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 95f66fc671..a170ac1345 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -173,7 +173,7 @@ done: /********************************************************************** Intialize a BYTE buffer from a SAM_ACCOUNT struct *********************************************************************/ -static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) +static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) { size_t len, buflen; @@ -186,25 +186,25 @@ static uint32 init_buffer_from_sam (uint8 **buf, SAM_ACCOUNT *sampass) pass_last_set_time, pass_can_change_time, pass_must_change_time; - char *username; - char *domain; - char *nt_username; - char *dir_drive; - char *unknown_str; - char *munged_dial; - char *fullname; - char *homedir; - char *logon_script; - char *profile_path; - char *acct_desc; - char *workstations; + const char *username; + const char *domain; + const char *nt_username; + const char *dir_drive; + const char *unknown_str; + const char *munged_dial; + const char *fullname; + const char *homedir; + const char *logon_script; + const char *profile_path; + const char *acct_desc; + const char *workstations; uint32 username_len, domain_len, nt_username_len, dir_drive_len, unknown_str_len, munged_dial_len, fullname_len, homedir_len, logon_script_len, profile_path_len, acct_desc_len, workstations_len; - uint8 *lm_pw; - uint8 *nt_pw; + const uint8 *lm_pw; + const uint8 *nt_pw; uint32 lm_pw_len = 16; uint32 nt_pw_len = 16; @@ -476,7 +476,7 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) Lookup a name in the SAM TDB ******************************************************************/ -BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) +BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) { TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -624,7 +624,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) Delete a SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_delete_sam_account(char *sname) +BOOL pdb_delete_sam_account(const char *sname) { SAM_ACCOUNT *sam_pass = NULL; TDB_CONTEXT *pwd_tdb; @@ -799,7 +799,7 @@ done: Modifies an existing SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override) +BOOL pdb_update_sam_account (const SAM_ACCOUNT *newpwd, BOOL override) { return (tdb_update_sam(newpwd, override, TDB_MODIFY)); } @@ -808,7 +808,7 @@ BOOL pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override) Adds an existing SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_add_sam_account (SAM_ACCOUNT *newpwd) +BOOL pdb_add_sam_account (const SAM_ACCOUNT *newpwd) { return (tdb_update_sam(newpwd, True, TDB_INSERT)); } -- cgit From acb81fe408f0e674088f0952aaba442ddb494b0c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 1 Nov 2001 05:02:41 +0000 Subject: Various post AuthRewrite cleanups, fixups and tidyups. Zero out some of the plaintext passwords for paranoia Fix up some of the other passdb backends with the change to *uid_t rather than uid_t. Make some of the code in srv_netlog_nt.c clearer, is passing an array around, so pass its lenght in is definition, not as a seperate paramater. Use sizeof() rather than magic numbers, it makes things easier to read. Cope with a PAM authenticated user who is not in /etc/passwd - currently by saying NO_SUCH_USER, but this can change in future. Andrew Bartlett (This used to be commit 514c91b16baca639bb04638042bf9894d881172a) --- source3/passdb/pdb_tdb.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a170ac1345..a6c40eb970 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -463,8 +463,8 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, uid); - pdb_set_gid (user, gid); + pdb_set_uid (user, &uid); + pdb_set_gid (user, &gid); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -538,8 +538,8 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, uid); - pdb_set_gid (user, gid); + pdb_set_uid (user, &uid); + pdb_set_gid (user, &gid); /* cleanup */ tdb_close (pwd_tdb); @@ -722,10 +722,6 @@ static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) get_private_directory(tdbfile); pstrcat (tdbfile, PASSDB_FILE_NAME); - if ( (!pdb_get_uid(newpwd)) || (!pdb_get_gid(newpwd)) ) - DEBUG (0,("tdb_update_sam: Storing a SAM_ACCOUNT for [%s] with uid %d and gid %d!\n", - pdb_get_username(newpwd), pdb_get_uid(newpwd), pdb_get_gid(newpwd))); - /* if we don't have a RID, then FAIL */ if (!pdb_get_user_rid(newpwd)) DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); -- cgit From 971181179b8f5c1ffebcb3bb43a137677aa4124a Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 4 Nov 2001 01:10:21 +0000 Subject: Fixup for accounts without a local /etc/passwd entry. - Now perfectly valid. (This used to be commit be04aad90da341fb1b4ef472f2279aefab972258) --- source3/passdb/pdb_tdb.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a6c40eb970..3153b47337 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -530,17 +530,13 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { - DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(user))); - return False; + if ((pw=sys_getpwnam(pdb_get_username(user)))) { + uid = pw->pw_uid; + gid = pw->pw_gid; + pdb_set_uid (user, &uid); + pdb_set_gid (user, &gid); } - uid = pw->pw_uid; - gid = pw->pw_gid; - pdb_set_uid (user, &uid); - pdb_set_gid (user, &gid); - /* cleanup */ tdb_close (pwd_tdb); -- cgit From 64bfd85d95f5a4e23dc0ca7f36966d485aa45253 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Nov 2001 18:49:20 +0000 Subject: Don't close tdb twice. (This used to be commit 6dda341bc80dc7c4d044df134fc153f646a6a4e9) --- source3/passdb/pdb_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 3153b47337..332118425b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -757,7 +757,6 @@ static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify passwd TDB!")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close (pwd_tdb); ret = False; goto done; } -- cgit From e0066d2dd4d9a657d1fbcb474e66a304a64e2a31 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Thu, 6 Dec 2001 13:09:15 +0000 Subject: again an intrusive patch: - removed the ugly as hell sam_logon_in_ssb variable, I changed a bit the definition of standard_sub_basic() to cope with that. - removed the smb.conf: 'domain admin group' and 'domain guest group' parameters ! We're not playing anymore with the user's group RIDs ! - in get_domain_user_groups(), if the user's gid is a group, put it first in the group RID list. I just have to write an HOWTO now ;-) J.F. (This used to be commit fef52c4b96c987115fb1818c00c2352c67790e50) --- source3/passdb/pdb_tdb.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 332118425b..1f1d1ab455 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -31,8 +31,6 @@ #define RIDPREFIX "RID_" extern int DEBUGLEVEL; -extern pstring samlogon_user; -extern BOOL sam_logon_in_ssb; struct tdb_enum_info { TDB_CONTEXT *passwd_tdb; -- cgit From 04aff47c716a51a1039b44a81d6ff19eeaa09017 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Dec 2001 06:38:04 +0000 Subject: moving SAM_ACCOUNT to include a bit field for initialized members (such as uid and gid). This way we will be able to keep ourselves from writing out default smb.conf settings when the admin doesn't want to, That part is not done yet. Tested compiles with ldap/tdb/smbpasswd. Tested connection with smbpasswd backend. oh...and smbpasswd doesn'y automatically expire accounts after 21 days from the last password change either now. Just ifdef'd out that code in build_sam_account(). Will merge updates into 2.2 as they are necessary. jerry (This used to be commit f0d43791157d8f04a13a07d029f203ad4384d317) --- source3/passdb/pdb_tdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1f1d1ab455..08439a9d20 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -461,8 +461,8 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, &uid); - pdb_set_gid (user, &gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -531,8 +531,8 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) if ((pw=sys_getpwnam(pdb_get_username(user)))) { uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, &uid); - pdb_set_gid (user, &gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); } /* cleanup */ -- cgit From 98010a076797f4d05d8c9bff45e65c076f30da3a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 30 Dec 2001 00:03:47 +0000 Subject: pdb_getsampwnuid() merge from 2.2 (This used to be commit 54cbfc7ebcdf1bd2094407b689b0050f0abfa46f) --- source3/passdb/pdb_tdb.c | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 08439a9d20..fbfdd1aace 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -541,31 +541,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) return True; } -/*************************************************************************** - Search by uid - **************************************************************************/ - -BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) -{ - struct passwd *pw; - fstring name; - - if (user==NULL) { - DEBUG(0,("pdb_getsampwuid: SAM_ACCOUNT is NULL.\n")); - return False; - } - - pw = sys_getpwuid(uid); - if (pw == NULL) { - DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist!\n", uid)); - return False; - } - fstrcpy (name, pw->pw_name); - - return pdb_getsampwnam (user, name); - -} - /*************************************************************************** Search by rid **************************************************************************/ -- cgit From 0608a60390db336bf179564aefdf16c43f1793ad Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 30 Dec 2001 19:21:25 +0000 Subject: util_sid.c - respect a const variabile (addedd strdup) cli_reg.c - indentation pdb_ldap.c - some checks on init fns parameters pdb_tdb.c - some checks on init fns parameters + make sure we close the db on failure (This used to be commit 49f5cb7a3df6d673f86e6769319aa657e30d8380) --- source3/passdb/pdb_tdb.c | 57 +++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index fbfdd1aace..8c17bb76ec 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -80,6 +80,11 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 bufle uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; BOOL ret = True; + + if(sampass == NULL || buf == NULL) { + DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); + return False; + } /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, @@ -207,9 +212,11 @@ static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) uint32 nt_pw_len = 16; /* do we have a valid SAM_ACCOUNT pointer? */ - if (sampass == NULL) + if (sampass == NULL) { + DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n")); return -1; - + } + *buf = NULL; buflen = 0; @@ -404,7 +411,7 @@ void pdb_endsampwent(void) global_tdb_ent.passwd_tdb = NULL; } - DEBUG(7, ("endtdbpwent: closed password file.\n")); + DEBUG(7, ("endtdbpwent: closed sam database.\n")); } /***************************************************************** @@ -425,10 +432,10 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) return False; } - /* skip all RID entries */ - while ((global_tdb_ent.key.dsize != 0) && (strncmp (global_tdb_ent.key.dptr, prefix, prefixlen))) + /* skip all non-USER entries (eg. RIDs) */ + while ((global_tdb_ent.key.dsize != 0) && (strncmp(global_tdb_ent.key.dptr, prefix, prefixlen))) /* increment to next in line */ - global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); + global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); /* do we have an valid interation pointer? */ if(global_tdb_ent.passwd_tdb == NULL) { @@ -436,14 +443,14 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) return False; } - data = tdb_fetch (global_tdb_ent.passwd_tdb, global_tdb_ent.key); + data = tdb_fetch(global_tdb_ent.passwd_tdb, global_tdb_ent.key); if (!data.dptr) { DEBUG(5,("pdb_getsampwent: database entry not found.\n")); return False; } /* unpack the buffer */ - if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); return False; @@ -461,11 +468,11 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, uid); - pdb_set_gid (user, gid); + pdb_set_uid(user, uid); + pdb_set_gid(user, gid); /* increment to next in line */ - global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); + global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); return True; } @@ -495,12 +502,12 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) unix_strlower(sname, -1, name, sizeof(name)); get_private_directory(tdbfile); - pstrcat (tdbfile, PASSDB_FILE_NAME); + pstrcat(tdbfile, PASSDB_FILE_NAME); /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; - key.dsize = strlen (keystr) + 1; + key.dsize = strlen(keystr) + 1; /* open the accounts TDB */ if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { @@ -509,34 +516,40 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) } /* get the record */ - data = tdb_fetch (pwd_tdb, key); + data = tdb_fetch(pwd_tdb, key); if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close (pwd_tdb); + tdb_close(pwd_tdb); return False; } /* unpack the buffer */ - if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); + tdb_close(pwd_tdb); return False; } SAFE_FREE(data.dptr); + + /* cleanup */ + tdb_close(pwd_tdb); /* validate the account and fill in UNIX uid and gid. sys_getpwnam() - is used instaed of Get_Pwnam() as we do not need to try case + is used instead of Get_Pwnam() as we do not need to try case permutations */ if ((pw=sys_getpwnam(pdb_get_username(user)))) { uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, uid); - pdb_set_gid (user, gid); + pdb_set_uid(user, uid); + pdb_set_gid(user, gid); + } + else { + DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", + pdb_get_username(user))); + return False; } - - /* cleanup */ - tdb_close (pwd_tdb); return True; } -- cgit From 8e4e261471c4e10d50519155f49913eff79ff842 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 31 Dec 2001 11:25:48 +0000 Subject: Make --with-tdbsam compile again, given the new 'am I setting a default' flags. Andrew Bartlett (This used to be commit 20d7c5d9b9bc0a426897f21b3350933602abdbf1) --- source3/passdb/pdb_tdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 8c17bb76ec..bc3062aedb 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -134,10 +134,10 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 bufle pdb_set_domain (sampass, domain_len?domain:NULL); pdb_set_nt_username (sampass, nt_username_len?nt_username:NULL); pdb_set_fullname (sampass, fullname_len?fullname:NULL); - pdb_set_homedir (sampass, homedir_len?homedir:NULL); - pdb_set_dir_drive (sampass, dir_drive_len?dir_drive:NULL); - pdb_set_logon_script (sampass, logon_script_len?logon_script:NULL); - pdb_set_profile_path (sampass, profile_path_len?profile_path:NULL); + pdb_set_homedir (sampass, homedir_len?homedir:NULL, True); + pdb_set_dir_drive (sampass, dir_drive_len?dir_drive:NULL, True); + pdb_set_logon_script (sampass, logon_script_len?logon_script:NULL, True); + pdb_set_profile_path (sampass, profile_path_len?profile_path:NULL, True); pdb_set_acct_desc (sampass, acct_desc_len?acct_desc:NULL); pdb_set_workstations (sampass, workstations_len?workstations:NULL); pdb_set_munged_dial (sampass, munged_dial_len?munged_dial:NULL); -- cgit From 39b61ab3a42311ee263a8d8ba879eb4076b9419c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 31 Dec 2001 15:48:03 +0000 Subject: port mods from 2.2 (This used to be commit f796f18a83cd2fc0988612aa38c794f005efbfaf) --- source3/passdb/pdb_tdb.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index bc3062aedb..69b2aab229 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -141,8 +141,14 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 bufle pdb_set_acct_desc (sampass, acct_desc_len?acct_desc:NULL); pdb_set_workstations (sampass, workstations_len?workstations:NULL); pdb_set_munged_dial (sampass, munged_dial_len?munged_dial:NULL); - pdb_set_lanman_passwd(sampass, lmpwlen?lm_pw_ptr:NULL); - pdb_set_nt_passwd (sampass, ntpwlen?nt_pw_ptr:NULL); + if (!pdb_set_lanman_passwd(sampass, lmpwlen?lm_pw_ptr:NULL)) { + ret = False; + goto done; + } + if (!pdb_set_nt_passwd(sampass, ntpwlen?nt_pw_ptr:NULL)) { + ret = False; + goto done; + } /*pdb_set_uid(sampass, uid); pdb_set_gid(sampass, gid);*/ @@ -427,6 +433,9 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) char *prefix = USERPREFIX; int prefixlen = strlen (prefix); + const char *sam_user; + pstring sam_subst; + if (user==NULL) { DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n")); return False; @@ -471,6 +480,17 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) pdb_set_uid(user, uid); pdb_set_gid(user, gid); + /* 21 days from present */ + pdb_set_pass_must_change_time(user, time(NULL)+1814400); + + sam_user = pdb_get_username(user); + pstrcpy(sam_subst, pdb_get_logon_script(user)); + standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); + pstrcpy(sam_subst, pdb_get_profile_path(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + pstrcpy(sam_subst, pdb_get_homedir(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + /* increment to next in line */ global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -492,6 +512,8 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) uid_t uid; gid_t gid; + char *sam_user; + pstring sam_subst; if (user==NULL) { DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); @@ -533,7 +555,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) } SAFE_FREE(data.dptr); - /* cleanup */ + /* no further use for database, close it now */ tdb_close(pwd_tdb); /* validate the account and fill in UNIX uid and gid. sys_getpwnam() @@ -544,6 +566,17 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) gid = pw->pw_gid; pdb_set_uid(user, uid); pdb_set_gid(user, gid); + + /* 21 days from present */ + pdb_set_pass_must_change_time(user, time(NULL)+1814400); + + sam_user = pdb_get_username(user); + pstrcpy(sam_subst, pdb_get_logon_script(user)); + standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); + pstrcpy(sam_subst, pdb_get_profile_path(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + pstrcpy(sam_subst, pdb_get_homedir(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); } else { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", -- cgit From 7a3cac39a5cbbadcd31d30058d3b513725aa2fa0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 31 Dec 2001 16:01:04 +0000 Subject: ops, froget to set the values. jerry, can you look at theis where we use standard_sub_advanced() fns? I think this structure should be backported to 2.2 because we do not know if the SAM_ACCOUNT strings have enough space to contain the "substituted" string. (Yes, just now we know they are pstrings, but we may change them into alloced one, I'm a strong suported of alloced strings as 1024 bytes are not always enough and are often too much) (This used to be commit 29b3b5e9292805aa65e887755567abd50f74e5cb) --- source3/passdb/pdb_tdb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 69b2aab229..ca6a2361d7 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -486,10 +486,13 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) sam_user = pdb_get_username(user); pstrcpy(sam_subst, pdb_get_logon_script(user)); standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); + pdb_set_logon_script(user, sam_subst, True); pstrcpy(sam_subst, pdb_get_profile_path(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + pdb_set_profile_path(user, sam_subst, True); pstrcpy(sam_subst, pdb_get_homedir(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + pdb_set_homedir(user, sam_subst, True); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -512,7 +515,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) uid_t uid; gid_t gid; - char *sam_user; + const char *sam_user; pstring sam_subst; if (user==NULL) { @@ -573,10 +576,13 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) sam_user = pdb_get_username(user); pstrcpy(sam_subst, pdb_get_logon_script(user)); standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); + pdb_set_logon_script(user, sam_subst, True); pstrcpy(sam_subst, pdb_get_profile_path(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + pdb_set_profile_path(user, sam_subst, True); pstrcpy(sam_subst, pdb_get_homedir(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); + pdb_set_homedir(user, sam_subst, True); } else { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", -- cgit From a3f891dbd2e9ee1681e3c8295cd62a877c727d4f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 2 Jan 2002 07:41:54 +0000 Subject: Actually enforce the passdb API. Thou shalt not reference SAM_ACCOUNT members directly - always use pdb_get/pdb_set. This is achived by making the whole of SAM_ACCOUNT have a .private member, where the real members live. This caught a pile of examples, and these have beeen fixed. The pdb_get..() functions are 'const' (have been for some time) and this required a few small changes to constify other functions. I've also added some debugs to the pdb get and set, they can be removed if requested. I've rewritten the copy_id2x_to_sam_pass() functions to use the new passdb interface, but I need the flags info to do it properly. The pdb_free_sam() funciton now blanks out the LM and NT hashes, and as such I have removed many extra 'samr_clear_sam_passwd(smbpass)' calls as a result. Finally, any and all testing is always appriciated - but the basics seem to work. Andrew Bartlett (This used to be commit d3dd28f6c443187b8d820d5a39c7c5b3be2fa95c) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index ca6a2361d7..c1b06067b4 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -159,7 +159,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 bufle pdb_set_unknown_5(sampass, unknown_5); pdb_set_unknown_6(sampass, unknown_6); pdb_set_acct_ctrl(sampass, acct_ctrl); - pdb_set_logons_divs(sampass, logon_divs); + pdb_set_logon_divs(sampass, logon_divs); pdb_set_hours(sampass, hours); done: -- cgit From dbee612f7150ee2921c37fa331b38b86d2d63937 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 15 Jan 2002 01:02:13 +0000 Subject: Change the passdb interface to use allocated strings. These strings are allocated using talloc(), either using its own memory context stored on the SAM_ACCOUNT or one supplied by the caller. The pdb_init_sam() and pdb_free_sam() function have been modifed so that a call to pdb_free_sam() will either clean up (remove hashes from memory) and destroy the TALLOC_CTX or just clean up depending on who supplied it. The pdb_init_sam and pdb_free_sam functions now also return an NTSTATUS, and I have modified the 3 places that actually checked these returns. The only nasty thing about this patch is the small measure needed to maintin interface compatability - strings set to NULL are actually set to "". This is becouse there are too many places in Samba that do strlen() on these strings without checking if they are NULL pointers. A supp patch will follow to set all strings to "" in pdb_default_sam(). Andrew Bartlett (This used to be commit 144345b41d39a6f68d01f62b7aee64ca0d328085) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index c1b06067b4..90976b3fef 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -681,7 +681,7 @@ BOOL pdb_delete_sam_account(const char *sname) } /* unpack the buffer */ - if (!pdb_init_sam (&sam_pass)) { + if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pass))) { tdb_close (pwd_tdb); return False; } -- cgit From c311d24ce32d2a8aa244f126bcec67ec03549727 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Jan 2002 08:45:58 +0000 Subject: A nice *big* change to the fundemental way we do things. Samba (ab)uses the returns from getpwnam() a lot - in particular it keeps them around for a long time - often past the next call... This adds a getpwnam_alloc and a getpwuid_alloc to the collection. These function as expected, returning a malloced structure that can be free()ed with passwd_free(&passwd). This patch also cuts down on the number of calls to getpwnam - mostly by taking advantage of the fact that the passdb interface is already case-insensiteve. With this patch most of the recursive cases have been removed (that I know of) and the problems are reduced further by not using the sys_ interface in the new code. This means that pointers to the cache won't be affected. (This is a tempoary HACK, I intend to kill the password cache entirly). The only change I'm a little worried about is the change to rpc_server/srv_samr_nt.c for private groups. In this case we are getting groups from the new group mapping DB. Do we still need to check for private groups? I've toned down the check to a case sensitve match with the new code, but we might be able to kill it entirly. I've also added a make_modifyable_passwd() function, that copies a passwd struct into the form that the old sys_getpw* code provided. As far as I can tell this is only actually used in the pass_check.c crazies, where I moved the final 'special case' for shadow passwords (out of _Get_Pwnam()). The matching case for getpwent() is dealt with already, in lib/util_getent.c Also included in here is a small change to register the [homes] share at vuid creation rather than just in one varient of the session setup. (This picks up the SPNEGO cases). The home directory is now stored on the vuid, and I am hoping this might provide a saner way to do %H substitions. TODO: Kill off remaining Get_Pwnam_Modify calls (they are not needed), change the remaining sys_getpwnam() callers to use getpwnam_alloc() and move Get_Pwnam to return an allocated struct. Andrew Bartlett (This used to be commit 1d86c7f94230bc53daebd4d2cd829da6292e05da) --- source3/passdb/pdb_tdb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 90976b3fef..1f234edc93 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -469,7 +469,7 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { + if ((pw=getpwnam_alloc(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", pdb_get_username(user))); return False; @@ -480,6 +480,8 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) pdb_set_uid(user, uid); pdb_set_gid(user, gid); + passwd_free(&pw); + /* 21 days from present */ pdb_set_pass_must_change_time(user, time(NULL)+1814400); @@ -564,7 +566,7 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instead of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(user)))) { + if ((pw=getpwnam_alloc(pdb_get_username(user)))) { uid = pw->pw_uid; gid = pw->pw_gid; pdb_set_uid(user, uid); @@ -590,6 +592,8 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) return False; } + passwd_free(&pw); + return True; } -- cgit From 7019bfe546912397e7f4d37a44a510ce17a7febb Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 19 Jan 2002 17:29:32 +0000 Subject: fixes (asprintf) from 2.2 (This used to be commit 6b123adda901ff05b0271eeda060297448f64eec) --- source3/passdb/pdb_tdb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1f234edc93..b33e684c7a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -488,13 +488,13 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) sam_user = pdb_get_username(user); pstrcpy(sam_subst, pdb_get_logon_script(user)); standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); - pdb_set_logon_script(user, sam_subst, True); + if (!pdb_set_logon_script(user, sam_subst, True)) return False; pstrcpy(sam_subst, pdb_get_profile_path(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - pdb_set_profile_path(user, sam_subst, True); + if (!pdb_set_profile_path(user, sam_subst, True)) return False; pstrcpy(sam_subst, pdb_get_homedir(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - pdb_set_homedir(user, sam_subst, True); + if (!pdb_set_homedir(user, sam_subst, True)) return False; /* increment to next in line */ global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -578,13 +578,13 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) sam_user = pdb_get_username(user); pstrcpy(sam_subst, pdb_get_logon_script(user)); standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); - pdb_set_logon_script(user, sam_subst, True); + if (!pdb_set_logon_script(user, sam_subst, True)) return False; pstrcpy(sam_subst, pdb_get_profile_path(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - pdb_set_profile_path(user, sam_subst, True); + if (!pdb_set_profile_path(user, sam_subst, True)) return False; pstrcpy(sam_subst, pdb_get_homedir(user)); standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - pdb_set_homedir(user, sam_subst, True); + if (!pdb_set_homedir(user, sam_subst, True)) return False; } else { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", -- cgit From 1a74d8d1f0758d15c5c35d20e33d9868565812cf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 20 Jan 2002 14:30:58 +0000 Subject: This is another *BIG* change... Samba now features a pluggable passdb interface, along the same lines as the one in use in the auth subsystem. In this case, only one backend may be active at a time by the 'normal' interface, and only one backend per passdb_context is permitted outside that. This pluggable interface is designed to allow any number of passdb backends to be compiled in, with the selection at runtime. The 'passdb backend' paramater has been created (and documented!) to support this. As such, configure has been modfied to allow (for example) --with-ldap and the old smbpasswd to be selected at the same time. This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua. These two backends accept 'non unix accounts', where the user does *not* exist in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to avoid conflicts in the algroitmic mapping of RIDs, they use the values specified in the 'non unix account range' paramter - in the same way as the winbind ranges are specifed. While I was at it, I cleaned up some of the code in pdb_tdb (code copied directly from smbpasswd and not really considered properly). Most of this was to do with % macro expansion on stored data. It isn't easy to get the macros into the tdb, and the first password change will 'expand' them. tdbsam needs to use a similar system to pdb_ldap in this regard. This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I don't have the test facilities for these. I plan to incoroprate at least pdb_ldap into this scheme after consultation with Jerry. Each (converted) passdb module now no longer has any 'static' variables, and only exports 1 init function outside its .c file. The non-unix-account support in this patch has been proven! It is now possible to join a win2k machine to a Samba PDC without an account in /etc/passwd! Other changes: Minor interface adjustments: pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*. pdb_update_sam_account() no longer takes the 'override' argument that was being ignored so often (every other passdb backend). Extra checks have been added in some places. Minor code changes: smbpasswd no longer attempts to initialise the passdb at startup, this is now done on first use. pdbedit has lost some of its 'machine account' logic, as this behaviour is now controlled by the passdb subsystem directly. The samr subsystem no longer calls 'local password change', but does the pdb interactions directly. This allow the ACB_ flags specifed to be transferred direct to the backend, without interference. Doco: I've updated the doco to reflect some of the changes, and removed some paramters no longer applicable to HEAD. (This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b) --- source3/passdb/pdb_tdb.c | 421 ++++++++++++++++++++++++++--------------------- 1 file changed, 232 insertions(+), 189 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b33e684c7a..0e0bf541e3 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -4,6 +4,7 @@ * Copyright (C) Simo Sorce 2000 * Copyright (C) Gerald Carter 2000 * Copyright (C) Jeremy Allison 2001 + * Copyright (C) Andrew Bartlett 2002 * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -30,21 +31,25 @@ #define USERPREFIX "USER_" #define RIDPREFIX "RID_" -extern int DEBUGLEVEL; - -struct tdb_enum_info { +struct tdbsam_privates { TDB_CONTEXT *passwd_tdb; TDB_DATA key; -}; -static struct tdb_enum_info global_tdb_ent; -/*static SAM_ACCOUNT global_sam_pass;*/ + /* retrive-once info */ + const char *tdbsam_location; + + BOOL permit_non_unix_accounts; + + uint32 low_nua_rid; + uint32 high_nua_rid; +}; /********************************************************************** Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len *********************************************************************/ -static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) +static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, + SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) { /* times are stored as 32bit integer @@ -150,8 +155,6 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 bufle goto done; } - /*pdb_set_uid(sampass, uid); - pdb_set_gid(sampass, gid);*/ pdb_set_user_rid(sampass, user_rid); pdb_set_group_rid(sampass, group_rid); pdb_set_unknown_3(sampass, unknown_3); @@ -162,6 +165,28 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, uint32 bufle pdb_set_logon_divs(sampass, logon_divs); pdb_set_hours(sampass, hours); + if ((tdb_state->permit_non_unix_accounts) + && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid) + && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) { + + } else { + struct passwd *pw; + /* validate the account and fill in UNIX uid and gid. sys_getpwnam() + is used instaed of Get_Pwnam() as we do not need to try case + permutations */ + + if ((pw=getpwnam_alloc(pdb_get_username(sampass))) == NULL) { + DEBUG(0,("init_sam_from_buffer: (tdbsam) getpwnam(%s) return NULL. User does not exist!\n", + pdb_get_username(sampass))); + return False; + } + + pdb_set_uid(sampass, pw->pw_uid); + pdb_set_gid(sampass, pw->pw_gid); + + passwd_free(&pw); + } + done: SAFE_FREE(username); @@ -182,7 +207,8 @@ done: /********************************************************************** Intialize a BYTE buffer from a SAM_ACCOUNT struct *********************************************************************/ -static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) +static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **buf, + const SAM_ACCOUNT *sampass, uint32 user_rid, uint32 group_rid) { size_t len, buflen; @@ -321,8 +347,8 @@ static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) workstations_len, workstations, unknown_str_len, unknown_str, munged_dial_len, munged_dial, - pdb_get_user_rid(sampass), - pdb_get_group_rid(sampass), + user_rid, + group_rid, lm_pw_len, lm_pw, nt_pw_len, nt_pw, pdb_get_acct_ctrl(sampass), @@ -360,8 +386,8 @@ static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) workstations_len, workstations, unknown_str_len, unknown_str, munged_dial_len, munged_dial, - pdb_get_user_rid(sampass), - pdb_get_group_rid(sampass), + user_rid, + group_rid, lm_pw_len, lm_pw, nt_pw_len, nt_pw, pdb_get_acct_ctrl(sampass), @@ -375,6 +401,8 @@ static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) /* check to make sure we got it correct */ if (buflen != len) { + DEBUG(0, ("init_buffer_from_sam: somthing odd is going on here: bufflen (%d) != len (%d) in tdb_pack operations!\n", + buflen, len)); /* error */ SAFE_FREE (*buf); return (-1); @@ -387,35 +415,38 @@ static uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass) Open the TDB passwd database for SAM account enumeration. ****************************************************************/ -BOOL pdb_setsampwent(BOOL update) +static BOOL tdbsam_setsampwent(struct pdb_context *context, BOOL update) { - pstring tdbfile; - - get_private_directory(tdbfile); - pstrcat (tdbfile, PASSDB_FILE_NAME); + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; /* Open tdb passwd */ - if (!(global_tdb_ent.passwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600))) + if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600))) { DEBUG(0, ("Unable to open/create TDB passwd\n")); return False; } - global_tdb_ent.key = tdb_firstkey(global_tdb_ent.passwd_tdb); + tdb_state->key = tdb_firstkey(tdb_state->passwd_tdb); return True; } +static void close_tdb(struct tdbsam_privates *tdb_state) +{ + if (tdb_state->passwd_tdb) { + tdb_close(tdb_state->passwd_tdb); + tdb_state->passwd_tdb = NULL; + } +} + /*************************************************************** End enumeration of the TDB passwd list. ****************************************************************/ -void pdb_endsampwent(void) +static void tdbsam_endsampwent(struct pdb_context *context) { - if (global_tdb_ent.passwd_tdb) { - tdb_close(global_tdb_ent.passwd_tdb); - global_tdb_ent.passwd_tdb = NULL; - } + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + close_tdb(tdb_state); DEBUG(7, ("endtdbpwent: closed sam database.\n")); } @@ -424,17 +455,13 @@ void pdb_endsampwent(void) Get one SAM_ACCOUNT from the TDB (next in line) *****************************************************************/ -BOOL pdb_getsampwent(SAM_ACCOUNT *user) +static BOOL tdbsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) { + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; TDB_DATA data; - struct passwd *pw; - uid_t uid; - gid_t gid; char *prefix = USERPREFIX; int prefixlen = strlen (prefix); - const char *sam_user; - pstring sam_subst; if (user==NULL) { DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n")); @@ -442,62 +469,32 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) } /* skip all non-USER entries (eg. RIDs) */ - while ((global_tdb_ent.key.dsize != 0) && (strncmp(global_tdb_ent.key.dptr, prefix, prefixlen))) + while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen))) /* increment to next in line */ - global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); + tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); /* do we have an valid interation pointer? */ - if(global_tdb_ent.passwd_tdb == NULL) { + if(tdb_state->passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); return False; } - data = tdb_fetch(global_tdb_ent.passwd_tdb, global_tdb_ent.key); + data = tdb_fetch(tdb_state->passwd_tdb, tdb_state->key); if (!data.dptr) { DEBUG(5,("pdb_getsampwent: database entry not found.\n")); return False; } /* unpack the buffer */ - if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); return False; } SAFE_FREE(data.dptr); - /* validate the account and fill in UNIX uid and gid. sys_getpwnam() - is used instaed of Get_Pwnam() as we do not need to try case - permutations */ - if ((pw=getpwnam_alloc(pdb_get_username(user))) == NULL) { - DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(user))); - return False; - } - - uid = pw->pw_uid; - gid = pw->pw_gid; - pdb_set_uid(user, uid); - pdb_set_gid(user, gid); - - passwd_free(&pw); - - /* 21 days from present */ - pdb_set_pass_must_change_time(user, time(NULL)+1814400); - - sam_user = pdb_get_username(user); - pstrcpy(sam_subst, pdb_get_logon_script(user)); - standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); - if (!pdb_set_logon_script(user, sam_subst, True)) return False; - pstrcpy(sam_subst, pdb_get_profile_path(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - if (!pdb_set_profile_path(user, sam_subst, True)) return False; - pstrcpy(sam_subst, pdb_get_homedir(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - if (!pdb_set_homedir(user, sam_subst, True)) return False; - /* increment to next in line */ - global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key); + tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); return True; } @@ -506,19 +503,13 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) Lookup a name in the SAM TDB ******************************************************************/ -BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) +static BOOL tdbsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname) { + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; fstring keystr; - struct passwd *pw; - pstring tdbfile; fstring name; - uid_t uid; - gid_t gid; - - const char *sam_user; - pstring sam_subst; if (user==NULL) { DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); @@ -528,17 +519,14 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) /* Data is stored in all lower-case */ unix_strlower(sname, -1, name, sizeof(name)); - get_private_directory(tdbfile); - pstrcat(tdbfile, PASSDB_FILE_NAME); - /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen(keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { - DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd!\n")); + if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { + DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); return False; } @@ -547,12 +535,13 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + DEBUGADD(5, (" Key: %s\n", keystr)); tdb_close(pwd_tdb); return False; } /* unpack the buffer */ - if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); tdb_close(pwd_tdb); @@ -563,37 +552,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) /* no further use for database, close it now */ tdb_close(pwd_tdb); - /* validate the account and fill in UNIX uid and gid. sys_getpwnam() - is used instead of Get_Pwnam() as we do not need to try case - permutations */ - if ((pw=getpwnam_alloc(pdb_get_username(user)))) { - uid = pw->pw_uid; - gid = pw->pw_gid; - pdb_set_uid(user, uid); - pdb_set_gid(user, gid); - - /* 21 days from present */ - pdb_set_pass_must_change_time(user, time(NULL)+1814400); - - sam_user = pdb_get_username(user); - pstrcpy(sam_subst, pdb_get_logon_script(user)); - standard_sub_advanced(-1, sam_user, "", gid, sam_user, sam_subst); - if (!pdb_set_logon_script(user, sam_subst, True)) return False; - pstrcpy(sam_subst, pdb_get_profile_path(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - if (!pdb_set_profile_path(user, sam_subst, True)) return False; - pstrcpy(sam_subst, pdb_get_homedir(user)); - standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_username(user), sam_subst); - if (!pdb_set_homedir(user, sam_subst, True)) return False; - } - else { - DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(user))); - return False; - } - - passwd_free(&pw); - return True; } @@ -601,12 +559,12 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) Search by rid **************************************************************************/ -BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) +static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid) { + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; fstring keystr; - pstring tdbfile; fstring name; if (user==NULL) { @@ -614,16 +572,13 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) return False; } - get_private_directory(tdbfile); - pstrcat (tdbfile, PASSDB_FILE_NAME); - /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) { + if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return False; } @@ -642,30 +597,26 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) tdb_close (pwd_tdb); - return pdb_getsampwnam (user, name); + return tdbsam_getsampwnam (context, user, name); } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_delete_sam_account(const char *sname) +static BOOL tdbsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass) { - SAM_ACCOUNT *sam_pass = NULL; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; TDB_CONTEXT *pwd_tdb; - TDB_DATA key, data; + TDB_DATA key; fstring keystr; - pstring tdbfile; uint32 rid; fstring name; - unix_strlower(sname, -1, name, sizeof(name)); + unix_strlower(pdb_get_username(sam_pass), -1, name, sizeof(name)); - get_private_directory(tdbfile); - pstrcat (tdbfile, PASSDB_FILE_NAME); - /* open the TDB */ - if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0600))) { + if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) { DEBUG(0, ("Unable to open TDB passwd!")); return False; } @@ -675,33 +626,8 @@ BOOL pdb_delete_sam_account(const char *sname) key.dptr = keystr; key.dsize = strlen (keystr) + 1; - /* get the record */ - data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) { - DEBUG(5,("pdb_delete_sam_account (TDB): error fetching database.\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close (pwd_tdb); - return False; - } - - /* unpack the buffer */ - if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pass))) { - tdb_close (pwd_tdb); - return False; - } - - if (!init_sam_from_buffer (sam_pass, data.dptr, data.dsize)) { - DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); - tdb_close (pwd_tdb); - SAFE_FREE(data.dptr); - return False; - } - SAFE_FREE(data.dptr); - rid = pdb_get_user_rid(sam_pass); - pdb_free_sam (&sam_pass); - /* it's outaa here! 8^) */ if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); @@ -734,27 +660,62 @@ BOOL pdb_delete_sam_account(const char *sname) Update the TDB SAM ****************************************************************************/ -static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) +static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpwd, int flag) { + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; TDB_CONTEXT *pwd_tdb = NULL; TDB_DATA key, data; uint8 *buf = NULL; fstring keystr; - pstring tdbfile; fstring name; BOOL ret = True; - - get_private_directory(tdbfile); - pstrcat (tdbfile, PASSDB_FILE_NAME); - - /* if we don't have a RID, then FAIL */ - if (!pdb_get_user_rid(newpwd)) - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); - if (!pdb_get_group_rid(newpwd)) - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + uint32 user_rid; + uint32 group_rid; + int32 tdb_ret; + + /* invalidate the existing TDB iterator if it is open */ + if (tdb_state->passwd_tdb) { + tdb_close(tdb_state->passwd_tdb); + tdb_state->passwd_tdb = NULL; + } + + /* open the account TDB passwd*/ + pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); + if (!pwd_tdb) + { + DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); + return False; + } + + /* if we don't have a RID, then make them up. */ + if (!(user_rid = pdb_get_user_rid(newpwd))) { + if (!tdb_state->permit_non_unix_accounts) { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); + ret = False; + goto done; + } else { + user_rid = tdb_state->low_nua_rid; + tdb_ret = tdb_change_int32_atomic(pwd_tdb, "NUA_NEXT_RID", &user_rid, RID_MULTIPLIER); + if (tdb_ret == -1) { + ret = False; + goto done; + } + } + } + + if (!(group_rid = pdb_get_group_rid(newpwd))) { + if (!tdb_state->permit_non_unix_accounts) { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + ret = False; + goto done; + } else { + /* This seems like a good default choice for non-unix users */ + group_rid = DOMAIN_GROUP_RID_USERS; + } + } /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ - if ((data.dsize=init_buffer_from_sam (&buf, newpwd)) == -1) { + if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd, user_rid, group_rid)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); ret = False; goto done; @@ -763,29 +724,18 @@ static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) unix_strlower(pdb_get_username(newpwd), -1, name, sizeof(name)); + DEBUG(5, ("Storing %saccount %s with RID %d\n", flag == TDB_INSERT ? "(new) " : "", name, user_rid)); + /* setup the USER index key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; - /* invalidate the existing TDB iterator if it is open */ - if (global_tdb_ent.passwd_tdb) { - tdb_close(global_tdb_ent.passwd_tdb); - global_tdb_ent.passwd_tdb = NULL; - } - - /* open the account TDB passwd*/ - pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); - if (!pwd_tdb) - { - DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd!\n")); - return False; - } - /* add the account */ if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify passwd TDB!")); - DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + DEBUGADD(0, (" Error: %s", tdb_errorstr(pwd_tdb))); + DEBUGADD(0, (" occured while storing the main record (%s)\n", keystr)); ret = False; goto done; } @@ -795,7 +745,7 @@ static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) data.dptr = name; /* setup the RID index key */ - slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, user_rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -803,6 +753,7 @@ static BOOL tdb_update_sam(const SAM_ACCOUNT* newpwd, BOOL override, int flag) if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify TDB passwd !")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr)); ret = False; goto done; } @@ -819,21 +770,113 @@ done: Modifies an existing SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_update_sam_account (const SAM_ACCOUNT *newpwd, BOOL override) +static BOOL tdbsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) { - return (tdb_update_sam(newpwd, override, TDB_MODIFY)); + return (tdb_update_sam(context, newpwd, TDB_MODIFY)); } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -BOOL pdb_add_sam_account (const SAM_ACCOUNT *newpwd) +static BOOL tdbsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +{ + return (tdb_update_sam(context, newpwd, TDB_INSERT)); +} + +static void free_private_data(void **vp) { - return (tdb_update_sam(newpwd, True, TDB_INSERT)); + struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; + close_tdb(*tdb_state); + *tdb_state = NULL; + + /* No need to free any further, as it is talloc()ed */ } + +NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + NTSTATUS nt_status; + struct tdbsam_privates *tdb_state; + + if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + return nt_status; + } + + (*pdb_method)->setsampwent = tdbsam_setsampwent; + (*pdb_method)->endsampwent = tdbsam_endsampwent; + (*pdb_method)->getsampwent = tdbsam_getsampwent; + (*pdb_method)->getsampwnam = tdbsam_getsampwnam; + (*pdb_method)->getsampwrid = tdbsam_getsampwrid; + (*pdb_method)->add_sam_account = tdbsam_add_sam_account; + (*pdb_method)->update_sam_account = tdbsam_update_sam_account; + (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; + + /* TODO: Setup private data and free */ + + tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); + + if (!tdb_state) { + DEBUG(0, ("talloc() failed for tdbsam private_data!\n")); + return NT_STATUS_NO_MEMORY; + } + + if (location) { + tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, location); + } else { + pstring tdbfile; + get_private_directory(tdbfile); + pstrcat (tdbfile, PASSDB_FILE_NAME); + tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile); + } + + (*pdb_method)->private_data = tdb_state; + + (*pdb_method)->free_private_data = free_private_data; + + return NT_STATUS_OK; +} + +NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + NTSTATUS nt_status; + struct tdbsam_privates *tdb_state; + uint32 low_nua_uid, high_nua_uid; + + if (!NT_STATUS_IS_OK(nt_status = pdb_init_tdbsam(pdb_context, pdb_method, location))) { + return nt_status; + } + + tdb_state = (*pdb_method)->private_data; + + tdb_state->permit_non_unix_accounts = True; + + if (!lp_non_unix_account_range(&low_nua_uid, &high_nua_uid)) { + DEBUG(0, ("cannot use tdbsam_nua without 'non unix account range' in smb.conf!\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + tdb_state->low_nua_rid=pdb_uid_to_user_rid(low_nua_uid); + + tdb_state->high_nua_rid=pdb_uid_to_user_rid(high_nua_uid); + + return NT_STATUS_OK; +} + + #else - /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */ - void samtdb_dummy_function(void) { } /* stop some compilers complaining */ -#endif /* WITH_TDB_SAM */ + +NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + DEBUG(0, ("tdbsam not compiled in!\n")); + return NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + DEBUG(0, ("tdbsam_nua not compiled in!\n")); + return NT_STATUS_UNSUCCESSFUL; +} + + +#endif -- cgit From 56d884eefeec40920fd51ce1e38798ac3ef799f0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 20 Jan 2002 17:03:23 +0000 Subject: fixes from 2.2 (This used to be commit e8a891354d307b2352eac375b9be02d7616cdb61) --- source3/passdb/pdb_tdb.c | 220 +++++++++++++++++++++++++++-------------------- 1 file changed, 127 insertions(+), 93 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0e0bf541e3..90b7cb5a0a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -85,6 +85,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; BOOL ret = True; + BOOL setflag; + gid_t gid; if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); @@ -128,6 +130,27 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, goto done; } + if ((tdb_state->permit_non_unix_accounts) + && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid) + && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) { + + } else { + struct passwd *pw; + /* validate the account and fill in UNIX uid and gid. Standard + * getpwnam() is used instead of Get_Pwnam() as we do not need + * to try case permutations + */ + if (!username || !(pw=getpwnam(username))) { + DEBUG(0,("tdb_sam: getpwnam(%s) return NULL. User does not exist!\n", + username?username:"NULL")); + ret = False; + goto done; + } + pdb_set_uid(sampass, pw->pw_uid); + gid = pw->pw_gid; + pdb_set_gid(sampass, gid); + } + pdb_set_logon_time(sampass, logon_time); pdb_set_logoff_time(sampass, logoff_time); pdb_set_kickoff_time(sampass, kickoff_time); @@ -135,26 +158,65 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, pdb_set_pass_must_change_time(sampass, pass_must_change_time); pdb_set_pass_last_set_time(sampass, pass_last_set_time); - pdb_set_username (sampass, username_len?username:NULL); - pdb_set_domain (sampass, domain_len?domain:NULL); - pdb_set_nt_username (sampass, nt_username_len?nt_username:NULL); - pdb_set_fullname (sampass, fullname_len?fullname:NULL); - pdb_set_homedir (sampass, homedir_len?homedir:NULL, True); - pdb_set_dir_drive (sampass, dir_drive_len?dir_drive:NULL, True); - pdb_set_logon_script (sampass, logon_script_len?logon_script:NULL, True); - pdb_set_profile_path (sampass, profile_path_len?profile_path:NULL, True); - pdb_set_acct_desc (sampass, acct_desc_len?acct_desc:NULL); - pdb_set_workstations (sampass, workstations_len?workstations:NULL); - pdb_set_munged_dial (sampass, munged_dial_len?munged_dial:NULL); - if (!pdb_set_lanman_passwd(sampass, lmpwlen?lm_pw_ptr:NULL)) { + pdb_set_username (sampass, username); + pdb_set_domain (sampass, domain); + pdb_set_nt_username (sampass, nt_username); + pdb_set_fullname (sampass, fullname); + + if (homedir) setflag = True; + else { + setflag = False; + homedir = strdup(lp_logon_home()); + if(!homedir) { ret = False; goto done; } + standard_sub_advanced(-1, username, "", gid, username, homedir); + DEBUG(5,("Home directory set back to %s\n", homedir)); + } + pdb_set_homedir(sampass, homedir, setflag); + + if (dir_drive) setflag = True; + else { + setflag = False; + dir_drive = strdup(lp_logon_drive()); + if(!dir_drive) { ret = False; goto done; } + standard_sub_advanced(-1, username, "", gid, username, dir_drive); + DEBUG(5,("Home directory set back to %s\n", dir_drive)); + } + pdb_set_dir_drive(sampass, dir_drive, setflag); + + if (logon_script) setflag = True; + else { + setflag = False; + logon_script = strdup(lp_logon_script()); + if(!logon_script) { ret = False; goto done; } + standard_sub_advanced(-1, username, "", gid, username, logon_script); + DEBUG(5,("Home directory set back to %s\n", logon_script)); + } + pdb_set_logon_script(sampass, logon_script, setflag); + + if (profile_path) setflag = True; + else { + setflag = False; + profile_path = strdup(lp_logon_path()); + if(!profile_path) { ret = False; goto done; } + standard_sub_advanced(-1, username, "", gid, username, profile_path); + DEBUG(5,("Home directory set back to %s\n", profile_path)); + } + pdb_set_profile_path(sampass, profile_path, setflag); + + pdb_set_acct_desc (sampass, acct_desc); + pdb_set_workstations (sampass, workstations); + pdb_set_munged_dial (sampass, munged_dial); + if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr)) { ret = False; goto done; } - if (!pdb_set_nt_passwd(sampass, ntpwlen?nt_pw_ptr:NULL)) { + if (!pdb_set_nt_passwd(sampass, nt_pw_ptr)) { ret = False; goto done; } + /*pdb_set_uid(sampass, uid); + pdb_set_gid(sampass, gid);*/ pdb_set_user_rid(sampass, user_rid); pdb_set_group_rid(sampass, group_rid); pdb_set_unknown_3(sampass, unknown_3); @@ -165,28 +227,6 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, pdb_set_logon_divs(sampass, logon_divs); pdb_set_hours(sampass, hours); - if ((tdb_state->permit_non_unix_accounts) - && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid) - && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) { - - } else { - struct passwd *pw; - /* validate the account and fill in UNIX uid and gid. sys_getpwnam() - is used instaed of Get_Pwnam() as we do not need to try case - permutations */ - - if ((pw=getpwnam_alloc(pdb_get_username(sampass))) == NULL) { - DEBUG(0,("init_sam_from_buffer: (tdbsam) getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(sampass))); - return False; - } - - pdb_set_uid(sampass, pw->pw_uid); - pdb_set_gid(sampass, pw->pw_gid); - - passwd_free(&pw); - } - done: SAFE_FREE(username); @@ -261,71 +301,65 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **b username = pdb_get_username(sampass); - if (username) - username_len = strlen(username) +1; - else - username_len = 0; + if (username) username_len = strlen(username) +1; + else username_len = 0; + domain = pdb_get_domain(sampass); - if (domain) - domain_len = strlen(domain) +1; - else - domain_len = 0; + if (domain) domain_len = strlen(domain) +1; + else domain_len = 0; + nt_username = pdb_get_nt_username(sampass); - if (nt_username) - nt_username_len = strlen(nt_username) +1; - else - nt_username_len = 0; - dir_drive = pdb_get_dirdrive(sampass); - if (dir_drive) - dir_drive_len = strlen(dir_drive) +1; - else - dir_drive_len = 0; - unknown_str = NULL; - unknown_str_len = 0; - munged_dial = pdb_get_munged_dial(sampass); - if (munged_dial) - munged_dial_len = strlen(munged_dial) +1; - else - munged_dial_len = 0; - + if (nt_username) nt_username_len = strlen(nt_username) +1; + else nt_username_len = 0; + fullname = pdb_get_fullname(sampass); - if (fullname) - fullname_len = strlen(fullname) +1; - else - fullname_len = 0; - homedir = pdb_get_homedir(sampass); - if (homedir) - homedir_len = strlen(homedir) +1; - else - homedir_len = 0; - logon_script = pdb_get_logon_script(sampass); - if (logon_script) - logon_script_len = strlen(logon_script) +1; - else - logon_script_len = 0; - profile_path = pdb_get_profile_path(sampass); - if (profile_path) - profile_path_len = strlen(profile_path) +1; - else - profile_path_len = 0; - acct_desc = pdb_get_acct_desc(sampass); - if (acct_desc) - acct_desc_len = strlen(acct_desc) +1; - else - acct_desc_len = 0; - workstations = pdb_get_workstations(sampass); - if (workstations) - workstations_len = strlen(workstations) +1; - else - workstations_len = 0; + if (fullname) fullname_len = strlen(fullname) +1; + else fullname_len = 0; + + /* + * Only updates fields which have been set (not defaults from smb.conf) + */ + + if (IS_SAM_SET(sampass, FLAG_SAM_DRIVE)) dir_drive = pdb_get_dirdrive(sampass); + else dir_drive = NULL; + if (dir_drive) dir_drive_len = strlen(dir_drive) +1; + else dir_drive_len = 0; + + if (IS_SAM_SET(sampass, FLAG_SAM_SMBHOME)) homedir = pdb_get_homedir(sampass); + else homedir = NULL; + if (homedir) homedir_len = strlen(homedir) +1; + else homedir_len = 0; + + if (IS_SAM_SET(sampass, FLAG_SAM_LOGONSCRIPT)) logon_script = pdb_get_logon_script(sampass); + else logon_script = NULL; + if (logon_script) logon_script_len = strlen(logon_script) +1; + else logon_script_len = 0; + + if (IS_SAM_SET(sampass, FLAG_SAM_PROFILE)) profile_path = pdb_get_profile_path(sampass); + else profile_path = NULL; + if (profile_path) profile_path_len = strlen(profile_path) +1; + else profile_path_len = 0; lm_pw = pdb_get_lanman_passwd(sampass); - if (!lm_pw) - lm_pw_len = 0; + if (!lm_pw) lm_pw_len = 0; nt_pw = pdb_get_nt_passwd(sampass); - if (!nt_pw) - nt_pw_len = 0; + if (!nt_pw) nt_pw_len = 0; + + acct_desc = pdb_get_acct_desc(sampass); + if (acct_desc) acct_desc_len = strlen(acct_desc) +1; + else acct_desc_len = 0; + + workstations = pdb_get_workstations(sampass); + if (workstations) workstations_len = strlen(workstations) +1; + else workstations_len = 0; + + unknown_str = NULL; + unknown_str_len = 0; + + munged_dial = pdb_get_munged_dial(sampass); + if (munged_dial) munged_dial_len = strlen(munged_dial) +1; + else munged_dial_len = 0; /* one time to get the size needed */ len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, -- cgit From 93e9fd542dfbde89ab84717db3b0981773b63923 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 20 Jan 2002 23:17:36 +0000 Subject: Inititialise the gid to what standard_sub_advanced wants for 'no value'. Andrew Bartlett (This used to be commit a96503475d9c1d91c2dfcdebb4f60183432d9aff) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 90b7cb5a0a..e05a9066cd 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -86,7 +86,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uint32 lmpwlen, ntpwlen, hourslen; BOOL ret = True; BOOL setflag; - gid_t gid; + gid_t gid = -1; /* This is what standard sub advanced expects if no gid is known */ if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); -- cgit From 3723171ea652650f7b89aa76efdf12b15bba9774 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 21 Jan 2002 02:51:23 +0000 Subject: getpwnam -> getpwnam_alloc (This used to be commit 59905d44e51d83f2d4a7b6844e0ae764e0b35c0c) --- source3/passdb/pdb_tdb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e05a9066cd..3d3b620f50 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -140,8 +140,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, * getpwnam() is used instead of Get_Pwnam() as we do not need * to try case permutations */ - if (!username || !(pw=getpwnam(username))) { - DEBUG(0,("tdb_sam: getpwnam(%s) return NULL. User does not exist!\n", + if (!username || !(pw=getpwnam_alloc(username))) { + DEBUG(0,("tdb_sam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username?username:"NULL")); ret = False; goto done; @@ -149,6 +149,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, pdb_set_uid(sampass, pw->pw_uid); gid = pw->pw_gid; pdb_set_gid(sampass, gid); + passwd_free(&pw); } pdb_set_logon_time(sampass, logon_time); -- cgit From 38c7fc5fe12cd6400016126dba85cfbbbb59f90a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Jan 2002 07:51:26 +0000 Subject: replace getpwnam_alloc with plain getpwnam. We are not going to reuse any getpw* call, so the extra alloc,copy and free only uses extra memory and extra cpu time for nothing. (This used to be commit 5c0bb0487bec00df494b72b64ddf274f42bfefea) --- source3/passdb/pdb_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 3d3b620f50..d7bfbb8026 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -140,7 +140,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, * getpwnam() is used instead of Get_Pwnam() as we do not need * to try case permutations */ - if (!username || !(pw=getpwnam_alloc(username))) { + if (!username || !(pw=getpwnam(username))) { DEBUG(0,("tdb_sam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username?username:"NULL")); ret = False; @@ -149,7 +149,6 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, pdb_set_uid(sampass, pw->pw_uid); gid = pw->pw_gid; pdb_set_gid(sampass, gid); - passwd_free(&pw); } pdb_set_logon_time(sampass, logon_time); -- cgit From 6e22428f278bd5241999b1fe885ccf6af84b8c93 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Jan 2002 07:54:09 +0000 Subject: fix also the comment. (This used to be commit 7f7a15e09a53a03dd423d40201f037f8da049cd7) --- source3/passdb/pdb_tdb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index d7bfbb8026..a089b947f4 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -136,18 +136,21 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, } else { struct passwd *pw; + uid_t uid; /* validate the account and fill in UNIX uid and gid. Standard * getpwnam() is used instead of Get_Pwnam() as we do not need * to try case permutations */ if (!username || !(pw=getpwnam(username))) { - DEBUG(0,("tdb_sam: getpwnam_alloc(%s) return NULL. User does not exist!\n", + DEBUG(0,("tdb_sam: getpwnam(%s) return NULL. User does not exist!\n", username?username:"NULL")); ret = False; goto done; } - pdb_set_uid(sampass, pw->pw_uid); + uid_t = pw->pw_uid; gid = pw->pw_gid; + + pdb_set_uid(sampass, uid); pdb_set_gid(sampass, gid); } -- cgit From d6b4327f11875c5634fa9452242ed2c5730d5934 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Jan 2002 07:55:35 +0000 Subject: hmm, get it right this time. (This used to be commit 57a145bff6b382e6dc9a9af96451175d81462c8d) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a089b947f4..30fe3dc354 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -147,7 +147,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, ret = False; goto done; } - uid_t = pw->pw_uid; + uid = pw->pw_uid; gid = pw->pw_gid; pdb_set_uid(sampass, uid); -- cgit From 158efc3aa2060e21f40e231a1e8aa945b6a3ab71 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 23 Jan 2002 12:59:24 +0000 Subject: getpwnam -> getpwnam_alloc. idra has promised not to revert these this time :-) (This used to be commit f556ad67e82518f5a024ffe9184ff9430ab5c541) --- source3/passdb/pdb_tdb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 30fe3dc354..b1ba01fe98 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -141,14 +141,16 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, * getpwnam() is used instead of Get_Pwnam() as we do not need * to try case permutations */ - if (!username || !(pw=getpwnam(username))) { - DEBUG(0,("tdb_sam: getpwnam(%s) return NULL. User does not exist!\n", + if (!username || !(pw=getpwnam_alloc(username))) { + DEBUG(0,("tdb_sam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username?username:"NULL")); ret = False; goto done; } uid = pw->pw_uid; gid = pw->pw_gid; + + passwd_free(&pw); pdb_set_uid(sampass, uid); pdb_set_gid(sampass, gid); -- cgit From 320f7cb4ac66bbb9fbfdd1f8b330264127c3f730 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 25 Jan 2002 11:44:15 +0000 Subject: Passdb changes: Modules now name themselves, which should allow for sane behaviour when we get an 'extern' passdb module (which in turn loads a .so). Fix up tdbsam for non-unix-accounts. Not sure if this fixes idra's bug, but its a start... Andrew Bartlett (This used to be commit 7d576d89d7b4a7b95e87a844568d7d7cd89f0542) --- source3/passdb/pdb_tdb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b1ba01fe98..5fdf348e15 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -131,8 +131,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, } if ((tdb_state->permit_non_unix_accounts) - && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid) - && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) { + && (user_rid >= tdb_state->low_nua_rid) + && (user_rid <= tdb_state->high_nua_rid)) { } else { struct passwd *pw; @@ -142,7 +142,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, * to try case permutations */ if (!username || !(pw=getpwnam_alloc(username))) { - DEBUG(0,("tdb_sam: getpwnam_alloc(%s) return NULL. User does not exist!\n", + DEBUG(0,("tdbsam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username?username:"NULL")); ret = False; goto done; @@ -842,6 +842,8 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con return nt_status; } + (*pdb_method)->name = "tdbsam"; + (*pdb_method)->setsampwent = tdbsam_setsampwent; (*pdb_method)->endsampwent = tdbsam_endsampwent; (*pdb_method)->getsampwent = tdbsam_getsampwent; @@ -851,8 +853,6 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; - /* TODO: Setup private data and free */ - tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); if (!tdb_state) { @@ -886,6 +886,8 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, return nt_status; } + (*pdb_method)->name = "tdbsam_nua"; + tdb_state = (*pdb_method)->private_data; tdb_state->permit_non_unix_accounts = True; -- cgit From 8a05b8c53f217b0536956687863c8afe5ff103b2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 26 Jan 2002 01:52:52 +0000 Subject: Add some information tidbits to an error DEBUG(). (This used to be commit 3db417c2ebfda0d5872dee39e36edc4fb6299b9a) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 5fdf348e15..1237408840 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -625,7 +625,7 @@ static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, /* get the record */ data = tdb_fetch (pwd_tdb, key); if (!data.dptr) { - DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n")); + DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return False; -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/passdb/pdb_tdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1237408840..9b7f99bbc8 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1,5 +1,6 @@ /* - * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup + * Unix SMB/CIFS implementation. + * SMB parameters and setup * Copyright (C) Andrew Tridgell 1992-1998 * Copyright (C) Simo Sorce 2000 * Copyright (C) Gerald Carter 2000 -- cgit From 0da3a4e6597b1a2ba06a411917c836286dac41b9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 1 Feb 2002 23:20:08 +0000 Subject: update from 2.2 (This used to be commit 8bb2a7446ed69020086aaedf2889795dd38ef9d4) --- source3/passdb/pdb_tdb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 9b7f99bbc8..3c76f8336b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -27,7 +27,7 @@ #ifdef WITH_TDB_SAM #define PDB_VERSION "20010830" -#define PASSDB_FILE_NAME "/passdb.tdb" +#define PASSDB_FILE_NAME "passdb.tdb" #define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd" #define USERPREFIX "USER_" #define RIDPREFIX "RID_" @@ -866,7 +866,8 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con } else { pstring tdbfile; get_private_directory(tdbfile); - pstrcat (tdbfile, PASSDB_FILE_NAME); + pstrcat(tdbfile, "/"); + pstrcat(tdbfile, PASSDB_FILE_NAME); tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile); } -- cgit From 2ef9be9a99cbd4b3c5076433153d675aa0cd4ca2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 2 Mar 2002 10:16:28 +0000 Subject: This patch merges my private LDAP tree into HEAD. The main change here is to move ldap into the new pluggable passdb subsystem and to take the LDAP location as a 'location' paramter on the 'passdb backend' line in the smb.conf. This is an LDAP URL, parsed by OpenLDAP where supported, and by hand where it isn't. It also adds the ldap user suffix and ldap machine suffix smb.conf options, so that machines added to the LDAP dir don't get mixed in with people. Non-unix account support is also added. This means that machines don't need to be in /etc/passwd or in nss_ldap's scope. This code has stood up well under my production environment, so it relitivly well tested. I'm commiting this now becouse others have shown interest in using it, and there is no point 'hording' the code :-). Andrew Bartlett (This used to be commit cd5234d7dd7309d88944b83d807c1f1c2ca0460a) --- source3/passdb/pdb_tdb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 3c76f8336b..40ba8dd475 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -157,11 +157,11 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, pdb_set_gid(sampass, gid); } - pdb_set_logon_time(sampass, logon_time); - pdb_set_logoff_time(sampass, logoff_time); - pdb_set_kickoff_time(sampass, kickoff_time); - pdb_set_pass_can_change_time(sampass, pass_can_change_time); - pdb_set_pass_must_change_time(sampass, pass_must_change_time); + pdb_set_logon_time(sampass, logon_time, True); + pdb_set_logoff_time(sampass, logoff_time, True); + pdb_set_kickoff_time(sampass, kickoff_time, True); + pdb_set_pass_can_change_time(sampass, pass_can_change_time, True); + pdb_set_pass_must_change_time(sampass, pass_must_change_time, True); pdb_set_pass_last_set_time(sampass, pass_last_set_time); pdb_set_username (sampass, username); -- cgit From 9fffb0859d07a885278c395a366656f05731235c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 18 Mar 2002 11:35:53 +0000 Subject: Start to switch away from the alghorithmic uid->rid mapping model (This used to be commit 724390a8daabbecd236960562e0a50f62c6904f1) --- source3/passdb/pdb_tdb.c | 109 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 22 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 40ba8dd475..86089cfd69 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -32,6 +32,8 @@ #define USERPREFIX "USER_" #define RIDPREFIX "RID_" +#define BASE_RID 0x200 + struct tdbsam_privates { TDB_CONTEXT *passwd_tdb; TDB_DATA key; @@ -253,8 +255,8 @@ done: /********************************************************************** Intialize a BYTE buffer from a SAM_ACCOUNT struct *********************************************************************/ -static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **buf, - const SAM_ACCOUNT *sampass, uint32 user_rid, uint32 group_rid) +static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, + uint8 **buf, const SAM_ACCOUNT *sampass) { size_t len, buflen; @@ -267,6 +269,9 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **b pass_last_set_time, pass_can_change_time, pass_must_change_time; + + uint32 user_rid, group_rid; + const char *username; const char *domain; const char *nt_username; @@ -305,6 +310,8 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **b pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass); pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass); + user_rid = pdb_get_user_rid(sampass); + group_rid = pdb_get_group_rid(sampass); username = pdb_get_username(sampass); if (username) username_len = strlen(username) +1; @@ -640,6 +647,56 @@ static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, return tdbsam_getsampwnam (context, user, name); } +/*************************************************************************** + Search by rid and give back the uid! + **************************************************************************/ + +uid_t tdbsam_rid_to_uid (struct pdb_context *context, uint32 rid) +{ + uid_t ret; + SAM_ACCOUNT *sa; + + if (!NT_STATUS_IS_OK(pdb_init_sam(&sa))) return -1; + if (!tdbsam_getsampwrid (context, sa, rid)) { + ret = -1; + goto done; + } + else { + ret = pdb_get_uid(sa); + } +done: + pdb_free_sam(&sa); + return ret; +} + +/*************************************************************************** + Search by uid and give back the rid! + **************************************************************************/ + +uint32 tdbsam_uid_to_rid (struct pdb_context *context, uid_t uid) +{ + uint32 ret; + char *name; + struct passwd *pw; + SAM_ACCOUNT *sa; + + if (!NT_STATUS_IS_OK(pdb_init_sam(&sa))) return 0; + pw = getpwuid(uid); + if (!pw) return 0; + name = strdup(pw->pw_name); + if (!tdbsam_getsampwnam (context, sa, name)) { + ret = 0; + goto done; + } + else { + ret = pdb_get_user_rid(sa); + } +done: + SAFE_FREE(name); + pdb_free_sam(&sa); + return ret; +} + /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ @@ -709,9 +766,8 @@ static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpw fstring keystr; fstring name; BOOL ret = True; - uint32 user_rid; - uint32 group_rid; - int32 tdb_ret; + uint32 user_rid; + int32 tdb_ret; /* invalidate the existing TDB iterator if it is open */ if (tdb_state->passwd_tdb) { @@ -727,35 +783,42 @@ static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpw return False; } - /* if we don't have a RID, then make them up. */ - if (!(user_rid = pdb_get_user_rid(newpwd))) { - if (!tdb_state->permit_non_unix_accounts) { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); - ret = False; - goto done; - } else { - user_rid = tdb_state->low_nua_rid; - tdb_ret = tdb_change_int32_atomic(pwd_tdb, "NUA_NEXT_RID", &user_rid, RID_MULTIPLIER); + /* if flag == TDB_INSERT then make up a new RID else throw an error. */ + if (!pdb_get_user_rid(newpwd)) { + if (flag & TDB_INSERT) { + user_rid = BASE_RID; + tdb_ret = tdb_change_int32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); if (tdb_ret == -1) { ret = False; goto done; } + pdb_set_user_rid(newpwd, user_rid); + } else { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); + ret = False; + goto done; } } - if (!(group_rid = pdb_get_group_rid(newpwd))) { - if (!tdb_state->permit_non_unix_accounts) { + if (!pdb_get_group_rid(newpwd)) { + if (flag & TDB_INSERT) { + if (!tdb_state->permit_non_unix_accounts) { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + ret = False; + goto done; + } else { + /* This seems like a good default choice for non-unix users */ + pdb_set_group_rid(newpwd, DOMAIN_GROUP_RID_USERS); + } + } else { DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); ret = False; goto done; - } else { - /* This seems like a good default choice for non-unix users */ - group_rid = DOMAIN_GROUP_RID_USERS; } } /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ - if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd, user_rid, group_rid)) == -1) { + if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); ret = False; goto done; @@ -853,6 +916,8 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; + (*pdb_method)->uid_to_user_rid = tdbsam_uid_to_rid; + (*pdb_method)->user_rid_to_uid = tdbsam_rid_to_uid; tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); @@ -899,9 +964,9 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, return NT_STATUS_UNSUCCESSFUL; } - tdb_state->low_nua_rid=pdb_uid_to_user_rid(low_nua_uid); + tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); - tdb_state->high_nua_rid=pdb_uid_to_user_rid(high_nua_uid); + tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid); return NT_STATUS_OK; } -- cgit From 32334bc6553c25b706e60a321f9c16f8931f94c1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 18 Mar 2002 23:57:14 +0000 Subject: more verbose checking in talloc and util_pw fixed tdbsam memory corruption (and segfault) reducing calls to pdb_uid_to_user_rid and countrary to 0 to move to a non alghoritmic rid allocation with some passdb modules. (This used to be commit 9836af7cd623357feaec07bc49cfb78f0aa01fc3) --- source3/passdb/pdb_tdb.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 86089cfd69..b55a74d290 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -90,6 +90,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, BOOL ret = True; BOOL setflag; gid_t gid = -1; /* This is what standard sub advanced expects if no gid is known */ + pstring sub_buffer; if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); @@ -144,9 +145,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, * getpwnam() is used instead of Get_Pwnam() as we do not need * to try case permutations */ - if (!username || !(pw=getpwnam_alloc(username))) { - DEBUG(0,("tdbsam: getpwnam_alloc(%s) return NULL. User does not exist!\n", - username?username:"NULL")); + if (!username || !(pw = getpwnam_alloc(username))) { + DEBUG(0,("tdbsam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username?username:"NULL")); ret = False; goto done; } @@ -174,9 +174,11 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, if (homedir) setflag = True; else { setflag = False; - homedir = strdup(lp_logon_home()); + pstrcpy(sub_buffer, lp_logon_home()); + /* standard_sub_advanced() assumes pstring is passed!! */ + standard_sub_advanced(-1, username, "", gid, username, sub_buffer); + homedir = strdup(sub_buffer); if(!homedir) { ret = False; goto done; } - standard_sub_advanced(-1, username, "", gid, username, homedir); DEBUG(5,("Home directory set back to %s\n", homedir)); } pdb_set_homedir(sampass, homedir, setflag); @@ -184,30 +186,33 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, if (dir_drive) setflag = True; else { setflag = False; - dir_drive = strdup(lp_logon_drive()); + pstrcpy(sub_buffer, lp_logon_drive()); + standard_sub_advanced(-1, username, "", gid, username, sub_buffer); + dir_drive = strdup(sub_buffer); if(!dir_drive) { ret = False; goto done; } - standard_sub_advanced(-1, username, "", gid, username, dir_drive); - DEBUG(5,("Home directory set back to %s\n", dir_drive)); + DEBUG(5,("Drive set back to %s\n", dir_drive)); } pdb_set_dir_drive(sampass, dir_drive, setflag); if (logon_script) setflag = True; else { setflag = False; - logon_script = strdup(lp_logon_script()); + pstrcpy(sub_buffer, lp_logon_script()); + standard_sub_advanced(-1, username, "", gid, username, sub_buffer); + logon_script = strdup(sub_buffer); if(!logon_script) { ret = False; goto done; } - standard_sub_advanced(-1, username, "", gid, username, logon_script); - DEBUG(5,("Home directory set back to %s\n", logon_script)); + DEBUG(5,("Logon script set back to %s\n", logon_script)); } pdb_set_logon_script(sampass, logon_script, setflag); if (profile_path) setflag = True; else { setflag = False; - profile_path = strdup(lp_logon_path()); + pstrcpy(sub_buffer, lp_logon_path()); + standard_sub_advanced(-1, username, "", gid, username, sub_buffer); + profile_path = strdup(sub_buffer); if(!profile_path) { ret = False; goto done; } - standard_sub_advanced(-1, username, "", gid, username, profile_path); - DEBUG(5,("Home directory set back to %s\n", profile_path)); + DEBUG(5,("Profile path set back to %s\n", profile_path)); } pdb_set_profile_path(sampass, profile_path, setflag); @@ -223,8 +228,6 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, goto done; } - /*pdb_set_uid(sampass, uid); - pdb_set_gid(sampass, gid);*/ pdb_set_user_rid(sampass, user_rid); pdb_set_group_rid(sampass, group_rid); pdb_set_unknown_3(sampass, unknown_3); -- cgit From 050b80356edea52f1bbb0a27599186ad84c18b73 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 19 Mar 2002 13:57:53 +0000 Subject: second step to gain free uid<->rid mapping we still need to free gid<->rid mapping and few other stuff (This used to be commit aa4b6f8181f34196a28951264dd8b631a5deef7f) --- source3/passdb/pdb_tdb.c | 93 ++++++++++-------------------------------------- 1 file changed, 19 insertions(+), 74 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b55a74d290..a8edac917e 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -32,8 +32,6 @@ #define USERPREFIX "USER_" #define RIDPREFIX "RID_" -#define BASE_RID 0x200 - struct tdbsam_privates { TDB_CONTEXT *passwd_tdb; TDB_DATA key; @@ -43,8 +41,8 @@ struct tdbsam_privates { BOOL permit_non_unix_accounts; - uint32 low_nua_rid; - uint32 high_nua_rid; +/* uint32 low_nua_rid; + uint32 high_nua_rid; */ }; /********************************************************************** @@ -81,7 +79,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, fullname_len, homedir_len, logon_script_len, profile_path_len, acct_desc_len, workstations_len; - uint32 /* uid, gid,*/ user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6; + uint32 user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6; uint16 acct_ctrl, logon_divs; uint8 *hours; static uint8 *lm_pw_ptr, *nt_pw_ptr; @@ -89,8 +87,10 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uint32 lmpwlen, ntpwlen, hourslen; BOOL ret = True; BOOL setflag; - gid_t gid = -1; /* This is what standard sub advanced expects if no gid is known */ pstring sub_buffer; + struct passwd *pw; + uid_t uid; + gid_t gid = -1; /* This is what standard sub advanced expects if no gid is known */ if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); @@ -134,22 +134,19 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, goto done; } - if ((tdb_state->permit_non_unix_accounts) - && (user_rid >= tdb_state->low_nua_rid) - && (user_rid <= tdb_state->high_nua_rid)) { - - } else { - struct passwd *pw; - uid_t uid; - /* validate the account and fill in UNIX uid and gid. Standard - * getpwnam() is used instead of Get_Pwnam() as we do not need - * to try case permutations - */ - if (!username || !(pw = getpwnam_alloc(username))) { - DEBUG(0,("tdbsam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username?username:"NULL")); + /* validate the account and fill in UNIX uid and gid. Standard + * getpwnam() is used instead of Get_Pwnam() as we do not need + * to try case permutations + */ + if (!username || !(pw = getpwnam_alloc(username))) { + if (!(tdb_state->permit_non_unix_accounts)) { + DEBUG(0,("tdbsam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username)); ret = False; goto done; } + } + + if (pw) { uid = pw->pw_uid; gid = pw->pw_gid; @@ -650,56 +647,6 @@ static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, return tdbsam_getsampwnam (context, user, name); } -/*************************************************************************** - Search by rid and give back the uid! - **************************************************************************/ - -uid_t tdbsam_rid_to_uid (struct pdb_context *context, uint32 rid) -{ - uid_t ret; - SAM_ACCOUNT *sa; - - if (!NT_STATUS_IS_OK(pdb_init_sam(&sa))) return -1; - if (!tdbsam_getsampwrid (context, sa, rid)) { - ret = -1; - goto done; - } - else { - ret = pdb_get_uid(sa); - } -done: - pdb_free_sam(&sa); - return ret; -} - -/*************************************************************************** - Search by uid and give back the rid! - **************************************************************************/ - -uint32 tdbsam_uid_to_rid (struct pdb_context *context, uid_t uid) -{ - uint32 ret; - char *name; - struct passwd *pw; - SAM_ACCOUNT *sa; - - if (!NT_STATUS_IS_OK(pdb_init_sam(&sa))) return 0; - pw = getpwuid(uid); - if (!pw) return 0; - name = strdup(pw->pw_name); - if (!tdbsam_getsampwnam (context, sa, name)) { - ret = 0; - goto done; - } - else { - ret = pdb_get_user_rid(sa); - } -done: - SAFE_FREE(name); - pdb_free_sam(&sa); - return ret; -} - /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ @@ -787,7 +734,7 @@ static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpw } /* if flag == TDB_INSERT then make up a new RID else throw an error. */ - if (!pdb_get_user_rid(newpwd)) { + if (!(user_rid = pdb_get_user_rid(newpwd))) { if (flag & TDB_INSERT) { user_rid = BASE_RID; tdb_ret = tdb_change_int32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); @@ -919,8 +866,6 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; - (*pdb_method)->uid_to_user_rid = tdbsam_uid_to_rid; - (*pdb_method)->user_rid_to_uid = tdbsam_rid_to_uid; tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); @@ -967,10 +912,10 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, return NT_STATUS_UNSUCCESSFUL; } - tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); +/* tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid); - +*/ return NT_STATUS_OK; } -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/passdb/pdb_tdb.c | 226 +++++++++++++++++++++++++++++------------------ 1 file changed, 142 insertions(+), 84 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a8edac917e..6279318969 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -2,7 +2,7 @@ * Unix SMB/CIFS implementation. * SMB parameters and setup * Copyright (C) Andrew Tridgell 1992-1998 - * Copyright (C) Simo Sorce 2000 + * Copyright (C) Simo Sorce 2000-2002 * Copyright (C) Gerald Carter 2000 * Copyright (C) Jeremy Allison 2001 * Copyright (C) Andrew Bartlett 2002 @@ -24,6 +24,19 @@ #include "includes.h" +#if 0 /* when made a module use this */ + +static int tdbsam_debug_level = DBGC_ALL; +#undef DBGC_CLASS +#define DBGC_CLASS tdbsam_debug_level + +#else + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_PASSDB + +#endif + #ifdef WITH_TDB_SAM #define PDB_VERSION "20010830" @@ -41,8 +54,10 @@ struct tdbsam_privates { BOOL permit_non_unix_accounts; -/* uint32 low_nua_rid; - uint32 high_nua_rid; */ + BOOL algorithmic_rids; + + uint32 low_nua_rid; + uint32 high_nua_rid; }; /********************************************************************** @@ -84,12 +99,10 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uint8 *hours; static uint8 *lm_pw_ptr, *nt_pw_ptr; uint32 len = 0; - uint32 lmpwlen, ntpwlen, hourslen; + uint32 lm_pw_len, nt_pw_len, hourslen; BOOL ret = True; - BOOL setflag; - pstring sub_buffer; struct passwd *pw; - uid_t uid; + uid_t uid = -1; gid_t gid = -1; /* This is what standard sub advanced expects if no gid is known */ if(sampass == NULL || buf == NULL) { @@ -119,8 +132,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, &munged_dial_len, &munged_dial, &user_rid, &group_rid, - &lmpwlen, &lm_pw_ptr, - &ntpwlen, &nt_pw_ptr, + &lm_pw_len, &lm_pw_ptr, + &nt_pw_len, &nt_pw_ptr, &acct_ctrl, &unknown_3, &logon_divs, @@ -150,6 +163,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uid = pw->pw_uid; gid = pw->pw_gid; + pdb_set_unix_homedir(sampass, pw->pw_dir); + passwd_free(&pw); pdb_set_uid(sampass, uid); @@ -163,70 +178,76 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, pdb_set_pass_must_change_time(sampass, pass_must_change_time, True); pdb_set_pass_last_set_time(sampass, pass_last_set_time); - pdb_set_username (sampass, username); + pdb_set_username (sampass, username); pdb_set_domain (sampass, domain); pdb_set_nt_username (sampass, nt_username); pdb_set_fullname (sampass, fullname); - if (homedir) setflag = True; - else { - setflag = False; - pstrcpy(sub_buffer, lp_logon_home()); - /* standard_sub_advanced() assumes pstring is passed!! */ - standard_sub_advanced(-1, username, "", gid, username, sub_buffer); - homedir = strdup(sub_buffer); - if(!homedir) { ret = False; goto done; } - DEBUG(5,("Home directory set back to %s\n", homedir)); + if (homedir) { + pdb_set_homedir(sampass, homedir, True); } - pdb_set_homedir(sampass, homedir, setflag); - - if (dir_drive) setflag = True; else { - setflag = False; - pstrcpy(sub_buffer, lp_logon_drive()); - standard_sub_advanced(-1, username, "", gid, username, sub_buffer); - dir_drive = strdup(sub_buffer); - if(!dir_drive) { ret = False; goto done; } - DEBUG(5,("Drive set back to %s\n", dir_drive)); + pdb_set_homedir(sampass, + talloc_sub_specified(sampass->mem_ctx, + lp_logon_home(), + username, domain, + uid, gid), + False); } - pdb_set_dir_drive(sampass, dir_drive, setflag); - if (logon_script) setflag = True; + if (dir_drive) + pdb_set_dir_drive(sampass, dir_drive, True); else { - setflag = False; - pstrcpy(sub_buffer, lp_logon_script()); - standard_sub_advanced(-1, username, "", gid, username, sub_buffer); - logon_script = strdup(sub_buffer); - if(!logon_script) { ret = False; goto done; } - DEBUG(5,("Logon script set back to %s\n", logon_script)); + pdb_set_dir_drive(sampass, + talloc_sub_specified(sampass->mem_ctx, + lp_logon_drive(), + username, domain, + uid, gid), + False); } - pdb_set_logon_script(sampass, logon_script, setflag); - if (profile_path) setflag = True; + if (logon_script) + pdb_set_logon_script(sampass, logon_script, True); else { - setflag = False; - pstrcpy(sub_buffer, lp_logon_path()); - standard_sub_advanced(-1, username, "", gid, username, sub_buffer); - profile_path = strdup(sub_buffer); - if(!profile_path) { ret = False; goto done; } - DEBUG(5,("Profile path set back to %s\n", profile_path)); + pdb_set_logon_script(sampass, + talloc_sub_specified(sampass->mem_ctx, + lp_logon_script(), + username, domain, + uid, gid), + False); + } + + if (profile_path) { + pdb_set_profile_path(sampass, profile_path, True); + } else { + pdb_set_profile_path(sampass, + talloc_sub_specified(sampass->mem_ctx, + lp_logon_path(), + username, domain, + uid, gid), + False); } - pdb_set_profile_path(sampass, profile_path, setflag); pdb_set_acct_desc (sampass, acct_desc); pdb_set_workstations (sampass, workstations); pdb_set_munged_dial (sampass, munged_dial); - if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr)) { - ret = False; - goto done; + + if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { + if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr)) { + ret = False; + goto done; + } } - if (!pdb_set_nt_passwd(sampass, nt_pw_ptr)) { - ret = False; - goto done; + + if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { + if (!pdb_set_nt_passwd(sampass, nt_pw_ptr)) { + ret = False; + goto done; + } } - pdb_set_user_rid(sampass, user_rid); - pdb_set_group_rid(sampass, group_rid); + pdb_set_user_sid_from_rid(sampass, user_rid); + pdb_set_group_sid_from_rid(sampass, group_rid); pdb_set_unknown_3(sampass, unknown_3); pdb_set_hours_len(sampass, hours_len); pdb_set_unknown_5(sampass, unknown_5); @@ -462,9 +483,9 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, Open the TDB passwd database for SAM account enumeration. ****************************************************************/ -static BOOL tdbsam_setsampwent(struct pdb_context *context, BOOL update) +static BOOL tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; /* Open tdb passwd */ if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600))) @@ -490,9 +511,9 @@ static void close_tdb(struct tdbsam_privates *tdb_state) End enumeration of the TDB passwd list. ****************************************************************/ -static void tdbsam_endsampwent(struct pdb_context *context) +static void tdbsam_endsampwent(struct pdb_methods *my_methods) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; close_tdb(tdb_state); DEBUG(7, ("endtdbpwent: closed sam database.\n")); @@ -502,9 +523,9 @@ static void tdbsam_endsampwent(struct pdb_context *context) Get one SAM_ACCOUNT from the TDB (next in line) *****************************************************************/ -static BOOL tdbsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) +static BOOL tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_DATA data; char *prefix = USERPREFIX; int prefixlen = strlen (prefix); @@ -550,9 +571,9 @@ static BOOL tdbsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) Lookup a name in the SAM TDB ******************************************************************/ -static BOOL tdbsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname) +static BOOL tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *user, const char *sname) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; fstring keystr; @@ -606,9 +627,9 @@ static BOOL tdbsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, Search by rid **************************************************************************/ -static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid) +static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *user, uint32 rid) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; fstring keystr; @@ -644,16 +665,24 @@ static BOOL tdbsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, tdb_close (pwd_tdb); - return tdbsam_getsampwnam (context, user, name); + return tdbsam_getsampwnam (my_methods, user, name); +} + +static BOOL tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, DOM_SID *sid) +{ + uint32 rid; + if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) + return False; + return tdbsam_getsampwrid(my_methods, user, rid); } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL tdbsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass) +static BOOL tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA key; fstring keystr; @@ -707,9 +736,9 @@ static BOOL tdbsam_delete_sam_account(struct pdb_context *context, const SAM_ACC Update the TDB SAM ****************************************************************************/ -static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpwd, int flag) +static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, int flag) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)context->pdb_selected->private_data; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb = NULL; TDB_DATA key, data; uint8 *buf = NULL; @@ -717,7 +746,7 @@ static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpw fstring name; BOOL ret = True; uint32 user_rid; - int32 tdb_ret; + BOOL tdb_ret; /* invalidate the existing TDB iterator if it is open */ if (tdb_state->passwd_tdb) { @@ -736,13 +765,32 @@ static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpw /* if flag == TDB_INSERT then make up a new RID else throw an error. */ if (!(user_rid = pdb_get_user_rid(newpwd))) { if (flag & TDB_INSERT) { - user_rid = BASE_RID; - tdb_ret = tdb_change_int32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); - if (tdb_ret == -1) { - ret = False; - goto done; + if (IS_SAM_UNIX_USER(newpwd)) { + if (tdb_state->algorithmic_rids) { + user_rid = fallback_pdb_uid_to_user_rid(pdb_get_uid(newpwd)); + } else { + user_rid = BASE_RID; + tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); + if (!tdb_ret) { + ret = False; + goto done; + } + } + pdb_set_user_sid_from_rid(newpwd, user_rid); + } else { + user_rid = tdb_state->low_nua_rid; + tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "NUA_RID_COUNTER", &user_rid, RID_MULTIPLIER); + if (!tdb_ret) { + ret = False; + goto done; + } + if (user_rid > tdb_state->high_nua_rid) { + DEBUG(0, ("tdbsam: no NUA rids available, cannot add user %s!\n", pdb_get_username(newpwd))); + ret = False; + goto done; + } + pdb_set_user_sid_from_rid(newpwd, user_rid); } - pdb_set_user_rid(newpwd, user_rid); } else { DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); ret = False; @@ -758,7 +806,7 @@ static BOOL tdb_update_sam(struct pdb_context *context, const SAM_ACCOUNT* newpw goto done; } else { /* This seems like a good default choice for non-unix users */ - pdb_set_group_rid(newpwd, DOMAIN_GROUP_RID_USERS); + pdb_set_group_sid_from_rid(newpwd, DOMAIN_GROUP_RID_USERS); } } else { DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); @@ -823,18 +871,18 @@ done: Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL tdbsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +static BOOL tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) { - return (tdb_update_sam(context, newpwd, TDB_MODIFY)); + return (tdb_update_sam(my_methods, newpwd, TDB_MODIFY)); } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL tdbsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +static BOOL tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) { - return (tdb_update_sam(context, newpwd, TDB_INSERT)); + return (tdb_update_sam(my_methods, newpwd, TDB_INSERT)); } static void free_private_data(void **vp) @@ -852,6 +900,14 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con NTSTATUS nt_status; struct tdbsam_privates *tdb_state; +#if 0 /* when made a module use this */ + tdbsam_debug_level = debug_add_class("tdbsam"); + if(tdbsam_debug_level == -1) { + tdbsam_debug_level = DBGC_ALL; + DEBUG(0, ("tdbsam: Couldn't register custom debugging class!\n")); + } +#endif + if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { return nt_status; } @@ -862,7 +918,7 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->endsampwent = tdbsam_endsampwent; (*pdb_method)->getsampwent = tdbsam_getsampwent; (*pdb_method)->getsampwnam = tdbsam_getsampwnam; - (*pdb_method)->getsampwrid = tdbsam_getsampwrid; + (*pdb_method)->getsampwsid = tdbsam_getsampwsid; (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; @@ -884,6 +940,8 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile); } + tdb_state->algorithmic_rids = True; + (*pdb_method)->private_data = tdb_state; (*pdb_method)->free_private_data = free_private_data; @@ -904,7 +962,7 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, (*pdb_method)->name = "tdbsam_nua"; tdb_state = (*pdb_method)->private_data; - + tdb_state->permit_non_unix_accounts = True; if (!lp_non_unix_account_range(&low_nua_uid, &high_nua_uid)) { @@ -912,10 +970,10 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, return NT_STATUS_UNSUCCESSFUL; } -/* tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); + tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid); -*/ + return NT_STATUS_OK; } -- cgit From b2edf254eda92f775e7d3d9b6793b4d77f9000b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 17:00:51 +0000 Subject: sync 3.0 branch with head (This used to be commit 3928578b52cfc949be5e0ef444fce1558d75f290) --- source3/passdb/pdb_tdb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6279318969..27453fc1af 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -354,7 +354,8 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, * Only updates fields which have been set (not defaults from smb.conf) */ - if (IS_SAM_SET(sampass, FLAG_SAM_DRIVE)) dir_drive = pdb_get_dirdrive(sampass); + if (IS_SAM_SET(sampass, FLAG_SAM_DRIVE)) + dir_drive = pdb_get_dir_drive(sampass); else dir_drive = NULL; if (dir_drive) dir_drive_len = strlen(dir_drive) +1; else dir_drive_len = 0; @@ -541,7 +542,7 @@ static BOOL tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user /* increment to next in line */ tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); - /* do we have an valid interation pointer? */ + /* do we have an valid iteration pointer? */ if(tdb_state->passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); return False; @@ -668,7 +669,7 @@ static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *use return tdbsam_getsampwnam (my_methods, user, name); } -static BOOL tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, DOM_SID *sid) +static BOOL tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) { uint32 rid; if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) -- cgit From d9729d81a993234db850fa733fd4591e1a5ae56e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 26 Sep 2002 18:37:55 +0000 Subject: syncing up with HEAD again.... (This used to be commit e026b84815ad1a5fa981c24fff197fefa73b4928) --- source3/passdb/pdb_tdb.c | 70 +++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 30 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 27453fc1af..241b3298b0 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -484,7 +484,7 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, Open the TDB passwd database for SAM account enumeration. ****************************************************************/ -static BOOL tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) +static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) { struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; @@ -492,12 +492,12 @@ static BOOL tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600))) { DEBUG(0, ("Unable to open/create TDB passwd\n")); - return False; + return NT_STATUS_UNSUCCESSFUL; } tdb_state->key = tdb_firstkey(tdb_state->passwd_tdb); - return True; + return NT_STATUS_OK; } static void close_tdb(struct tdbsam_privates *tdb_state) @@ -524,8 +524,9 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) Get one SAM_ACCOUNT from the TDB (next in line) *****************************************************************/ -static BOOL tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user) +static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user) { + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_DATA data; char *prefix = USERPREFIX; @@ -534,7 +535,7 @@ static BOOL tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user if (user==NULL) { DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n")); - return False; + return nt_status; } /* skip all non-USER entries (eg. RIDs) */ @@ -545,35 +546,36 @@ static BOOL tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user /* do we have an valid iteration pointer? */ if(tdb_state->passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); - return False; + return nt_status; } data = tdb_fetch(tdb_state->passwd_tdb, tdb_state->key); if (!data.dptr) { DEBUG(5,("pdb_getsampwent: database entry not found.\n")); - return False; + return nt_status; } /* unpack the buffer */ if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); - return False; + return nt_status; } SAFE_FREE(data.dptr); /* increment to next in line */ tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); - return True; + return NT_STATUS_OK; } /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ -static BOOL tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *user, const char *sname) +static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *user, const char *sname) { + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -582,7 +584,7 @@ static BOOL tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *use if (user==NULL) { DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); - return False; + return nt_status; } /* Data is stored in all lower-case */ @@ -596,7 +598,7 @@ static BOOL tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *use /* open the accounts TDB */ if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); - return False; + return nt_status; } /* get the record */ @@ -606,7 +608,7 @@ static BOOL tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *use DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); DEBUGADD(5, (" Key: %s\n", keystr)); tdb_close(pwd_tdb); - return False; + return nt_status; } /* unpack the buffer */ @@ -614,22 +616,23 @@ static BOOL tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *use DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); tdb_close(pwd_tdb); - return False; + return nt_status; } SAFE_FREE(data.dptr); /* no further use for database, close it now */ tdb_close(pwd_tdb); - return True; + return NT_STATUS_OK; } /*************************************************************************** Search by rid **************************************************************************/ -static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *user, uint32 rid) +static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *user, uint32 rid) { + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -638,7 +641,7 @@ static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *use if (user==NULL) { DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n")); - return False; + return nt_status; } /* set search key */ @@ -649,7 +652,7 @@ static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *use /* open the accounts TDB */ if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); - return False; + return nt_status; } /* get the record */ @@ -658,7 +661,7 @@ static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *use DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); - return False; + return nt_status; } fstrcpy (name, data.dptr); @@ -669,11 +672,11 @@ static BOOL tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *use return tdbsam_getsampwnam (my_methods, user, name); } -static BOOL tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) +static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) { uint32 rid; if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) - return False; + return NT_STATUS_UNSUCCESSFUL; return tdbsam_getsampwrid(my_methods, user, rid); } @@ -681,8 +684,9 @@ static BOOL tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * use Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass) +static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass) { + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_CONTEXT *pwd_tdb; TDB_DATA key; @@ -695,7 +699,7 @@ static BOOL tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUN /* open the TDB */ if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) { DEBUG(0, ("Unable to open TDB passwd!")); - return False; + return nt_status; } /* set the search key */ @@ -710,7 +714,7 @@ static BOOL tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUN DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close(pwd_tdb); - return False; + return nt_status; } /* delete also the RID key */ @@ -725,12 +729,12 @@ static BOOL tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUN DEBUG(5, ("Error deleting entry from tdb rid database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close(pwd_tdb); - return False; + return nt_status; } tdb_close(pwd_tdb); - return True; + return NT_STATUS_OK; } /*************************************************************************** @@ -872,18 +876,24 @@ done: Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) +static NTSTATUS tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) { - return (tdb_update_sam(my_methods, newpwd, TDB_MODIFY)); + if (tdb_update_sam(my_methods, newpwd, TDB_MODIFY)) + return NT_STATUS_OK; + else + return NT_STATUS_UNSUCCESSFUL; } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) +static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) { - return (tdb_update_sam(my_methods, newpwd, TDB_INSERT)); + if (tdb_update_sam(my_methods, newpwd, TDB_INSERT)) + return NT_STATUS_OK; + else + return NT_STATUS_UNSUCCESSFUL; } static void free_private_data(void **vp) -- cgit From 6d7195d1d79c43f5ccc8dc4a9215c02177d5fa89 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 2 Nov 2002 03:47:48 +0000 Subject: Merge passdb from HEAD -> 3.0 The work here includes: - metze' set/changed patch, which avoids making changes to ldap on unmodified attributes. - volker's group mapping in passdb patch - volker's samsync stuff - volkers SAMR changes. - mezte's connection caching patch - my recent changes (fix magic root check, ldap ssl) Andrew Bartlett (This used to be commit 2044d60bbe0043cdbb9aba931115672bde975d2f) --- source3/passdb/pdb_tdb.c | 155 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 107 insertions(+), 48 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 241b3298b0..2aa2e504d7 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -163,28 +163,28 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_unix_homedir(sampass, pw->pw_dir); + pdb_set_unix_homedir(sampass, pw->pw_dir, PDB_SET); passwd_free(&pw); - pdb_set_uid(sampass, uid); - pdb_set_gid(sampass, gid); + pdb_set_uid(sampass, uid, PDB_SET); + pdb_set_gid(sampass, gid, PDB_SET); } - pdb_set_logon_time(sampass, logon_time, True); - pdb_set_logoff_time(sampass, logoff_time, True); - pdb_set_kickoff_time(sampass, kickoff_time, True); - pdb_set_pass_can_change_time(sampass, pass_can_change_time, True); - pdb_set_pass_must_change_time(sampass, pass_must_change_time, True); - pdb_set_pass_last_set_time(sampass, pass_last_set_time); + pdb_set_logon_time(sampass, logon_time, PDB_SET); + pdb_set_logoff_time(sampass, logoff_time, PDB_SET); + pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET); + pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET); + pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET); + pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET); - pdb_set_username (sampass, username); - pdb_set_domain (sampass, domain); - pdb_set_nt_username (sampass, nt_username); - pdb_set_fullname (sampass, fullname); + pdb_set_username (sampass, username, PDB_SET); + pdb_set_domain (sampass, domain, PDB_SET); + pdb_set_nt_username (sampass, nt_username, PDB_SET); + pdb_set_fullname (sampass, fullname, PDB_SET); if (homedir) { - pdb_set_homedir(sampass, homedir, True); + pdb_set_homedir(sampass, homedir, PDB_SET); } else { pdb_set_homedir(sampass, @@ -192,69 +192,69 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, lp_logon_home(), username, domain, uid, gid), - False); + PDB_DEFAULT); } if (dir_drive) - pdb_set_dir_drive(sampass, dir_drive, True); + pdb_set_dir_drive(sampass, dir_drive, PDB_SET); else { pdb_set_dir_drive(sampass, talloc_sub_specified(sampass->mem_ctx, lp_logon_drive(), username, domain, uid, gid), - False); + PDB_DEFAULT); } if (logon_script) - pdb_set_logon_script(sampass, logon_script, True); + pdb_set_logon_script(sampass, logon_script, PDB_SET); else { pdb_set_logon_script(sampass, talloc_sub_specified(sampass->mem_ctx, lp_logon_script(), username, domain, uid, gid), - False); + PDB_DEFAULT); } if (profile_path) { - pdb_set_profile_path(sampass, profile_path, True); + pdb_set_profile_path(sampass, profile_path, PDB_SET); } else { pdb_set_profile_path(sampass, talloc_sub_specified(sampass->mem_ctx, lp_logon_path(), username, domain, uid, gid), - False); + PDB_DEFAULT); } - pdb_set_acct_desc (sampass, acct_desc); - pdb_set_workstations (sampass, workstations); - pdb_set_munged_dial (sampass, munged_dial); + pdb_set_acct_desc (sampass, acct_desc, PDB_SET); + pdb_set_workstations (sampass, workstations, PDB_SET); + pdb_set_munged_dial (sampass, munged_dial, PDB_SET); if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { - if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr)) { + if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) { ret = False; goto done; } } if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { - if (!pdb_set_nt_passwd(sampass, nt_pw_ptr)) { + if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) { ret = False; goto done; } } - pdb_set_user_sid_from_rid(sampass, user_rid); - pdb_set_group_sid_from_rid(sampass, group_rid); - pdb_set_unknown_3(sampass, unknown_3); - pdb_set_hours_len(sampass, hours_len); - pdb_set_unknown_5(sampass, unknown_5); - pdb_set_unknown_6(sampass, unknown_6); - pdb_set_acct_ctrl(sampass, acct_ctrl); - pdb_set_logon_divs(sampass, logon_divs); - pdb_set_hours(sampass, hours); + pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); + pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); + pdb_set_unknown_3(sampass, unknown_3, PDB_SET); + pdb_set_hours_len(sampass, hours_len, PDB_SET); + pdb_set_unknown_5(sampass, unknown_5, PDB_SET); + pdb_set_unknown_6(sampass, unknown_6, PDB_SET); + pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET); + pdb_set_logon_divs(sampass, logon_divs, PDB_SET); + pdb_set_hours(sampass, hours, PDB_SET); done: @@ -354,23 +354,23 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, * Only updates fields which have been set (not defaults from smb.conf) */ - if (IS_SAM_SET(sampass, FLAG_SAM_DRIVE)) + if (!IS_SAM_DEFAULT(sampass, PDB_DRIVE)) dir_drive = pdb_get_dir_drive(sampass); else dir_drive = NULL; if (dir_drive) dir_drive_len = strlen(dir_drive) +1; else dir_drive_len = 0; - if (IS_SAM_SET(sampass, FLAG_SAM_SMBHOME)) homedir = pdb_get_homedir(sampass); + if (!IS_SAM_DEFAULT(sampass, PDB_SMBHOME)) homedir = pdb_get_homedir(sampass); else homedir = NULL; if (homedir) homedir_len = strlen(homedir) +1; else homedir_len = 0; - if (IS_SAM_SET(sampass, FLAG_SAM_LOGONSCRIPT)) logon_script = pdb_get_logon_script(sampass); + if (!IS_SAM_DEFAULT(sampass, PDB_LOGONSCRIPT)) logon_script = pdb_get_logon_script(sampass); else logon_script = NULL; if (logon_script) logon_script_len = strlen(logon_script) +1; else logon_script_len = 0; - if (IS_SAM_SET(sampass, FLAG_SAM_PROFILE)) profile_path = pdb_get_profile_path(sampass); + if (!IS_SAM_DEFAULT(sampass, PDB_PROFILE)) profile_path = pdb_get_profile_path(sampass); else profile_path = NULL; if (profile_path) profile_path_len = strlen(profile_path) +1; else profile_path_len = 0; @@ -421,12 +421,12 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, lm_pw_len, lm_pw, nt_pw_len, nt_pw, pdb_get_acct_ctrl(sampass), - pdb_get_unknown3(sampass), + pdb_get_unknown_3(sampass), pdb_get_logon_divs(sampass), pdb_get_hours_len(sampass), MAX_HOURS_LEN, pdb_get_hours(sampass), - pdb_get_unknown5(sampass), - pdb_get_unknown6(sampass)); + pdb_get_unknown_5(sampass), + pdb_get_unknown_6(sampass)); /* malloc the space needed */ @@ -460,12 +460,12 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, lm_pw_len, lm_pw, nt_pw_len, nt_pw, pdb_get_acct_ctrl(sampass), - pdb_get_unknown3(sampass), + pdb_get_unknown_3(sampass), pdb_get_logon_divs(sampass), pdb_get_hours_len(sampass), MAX_HOURS_LEN, pdb_get_hours(sampass), - pdb_get_unknown5(sampass), - pdb_get_unknown6(sampass)); + pdb_get_unknown_5(sampass), + pdb_get_unknown_6(sampass)); /* check to make sure we got it correct */ @@ -781,7 +781,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, goto done; } } - pdb_set_user_sid_from_rid(newpwd, user_rid); + pdb_set_user_sid_from_rid(newpwd, user_rid, PDB_CHANGED); } else { user_rid = tdb_state->low_nua_rid; tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "NUA_RID_COUNTER", &user_rid, RID_MULTIPLIER); @@ -794,7 +794,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, ret = False; goto done; } - pdb_set_user_sid_from_rid(newpwd, user_rid); + pdb_set_user_sid_from_rid(newpwd, user_rid, PDB_CHANGED); } } else { DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); @@ -811,7 +811,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, goto done; } else { /* This seems like a good default choice for non-unix users */ - pdb_set_group_sid_from_rid(newpwd, DOMAIN_GROUP_RID_USERS); + pdb_set_group_sid_from_rid(newpwd, DOMAIN_GROUP_RID_USERS, PDB_DEFAULT); } } else { DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); @@ -896,6 +896,58 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO return NT_STATUS_UNSUCCESSFUL; } +static NTSTATUS tdbsam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, + DOM_SID sid, BOOL with_priv) +{ + return get_group_map_from_sid(sid, map, with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +static NTSTATUS tdbsam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, + gid_t gid, BOOL with_priv) +{ + return get_group_map_from_gid(gid, map, with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +static NTSTATUS tdbsam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, + char *name, BOOL with_priv) +{ + return get_group_map_from_ntname(name, map, with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +static NTSTATUS tdbsam_add_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map) +{ + return add_mapping_entry(map, TDB_INSERT) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +static NTSTATUS tdbsam_update_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map) +{ + return add_mapping_entry(map, TDB_REPLACE) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +static NTSTATUS tdbsam_delete_group_mapping_entry(struct pdb_methods *methods, + DOM_SID sid) +{ + return group_map_remove(sid) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +static NTSTATUS tdbsam_enum_group_mapping(struct pdb_methods *methods, + enum SID_NAME_USE sid_name_use, + GROUP_MAP **rmap, int *num_entries, + BOOL unix_only, BOOL with_priv) +{ + return enum_group_mapping(sid_name_use, rmap, num_entries, unix_only, + with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + static void free_private_data(void **vp) { struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; @@ -933,6 +985,13 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; + (*pdb_method)->getgrsid = tdbsam_getgrsid; + (*pdb_method)->getgrgid = tdbsam_getgrgid; + (*pdb_method)->getgrnam = tdbsam_getgrnam; + (*pdb_method)->add_group_mapping_entry = tdbsam_add_group_mapping_entry; + (*pdb_method)->update_group_mapping_entry = tdbsam_update_group_mapping_entry; + (*pdb_method)->delete_group_mapping_entry = tdbsam_delete_group_mapping_entry; + (*pdb_method)->enum_group_mapping = tdbsam_enum_group_mapping; tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 2aa2e504d7..a1f786c8cd 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -529,7 +529,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_DATA data; - char *prefix = USERPREFIX; + const char *prefix = USERPREFIX; int prefixlen = strlen (prefix); -- cgit From 3d8c50c87482d75d18b21bee954911951f471e2a Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Mar 2003 09:03:46 +0000 Subject: Thanks to volker, merge passdb changes from HEAD: - pdb_guest (including change defaults) - 'default' passdb actions (instead of 'not implemented' stubs in each module) - net_rpc_samsync no longer assumes pdb_unix Andrew Bartlett (This used to be commit 4bec53c8c81019f0f06a93c4df0800bbf7281dd6) --- source3/passdb/pdb_tdb.c | 59 ------------------------------------------------ 1 file changed, 59 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a1f786c8cd..c48c9567b1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -896,58 +896,6 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO return NT_STATUS_UNSUCCESSFUL; } -static NTSTATUS tdbsam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, - DOM_SID sid, BOOL with_priv) -{ - return get_group_map_from_sid(sid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, - gid_t gid, BOOL with_priv) -{ - return get_group_map_from_gid(gid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, - char *name, BOOL with_priv) -{ - return get_group_map_from_ntname(name, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_add_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_INSERT) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_update_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_REPLACE) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_delete_group_mapping_entry(struct pdb_methods *methods, - DOM_SID sid) -{ - return group_map_remove(sid) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_enum_group_mapping(struct pdb_methods *methods, - enum SID_NAME_USE sid_name_use, - GROUP_MAP **rmap, int *num_entries, - BOOL unix_only, BOOL with_priv) -{ - return enum_group_mapping(sid_name_use, rmap, num_entries, unix_only, - with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - static void free_private_data(void **vp) { struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; @@ -985,13 +933,6 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; - (*pdb_method)->getgrsid = tdbsam_getgrsid; - (*pdb_method)->getgrgid = tdbsam_getgrgid; - (*pdb_method)->getgrnam = tdbsam_getgrnam; - (*pdb_method)->add_group_mapping_entry = tdbsam_add_group_mapping_entry; - (*pdb_method)->update_group_mapping_entry = tdbsam_update_group_mapping_entry; - (*pdb_method)->delete_group_mapping_entry = tdbsam_delete_group_mapping_entry; - (*pdb_method)->enum_group_mapping = tdbsam_enum_group_mapping; tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); -- cgit From 9c3cecbdac2ea888f95db2194bf9f5d2457aef09 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2003 16:01:14 +0000 Subject: Use the new modules system for passdb (merge from HEAD) (This used to be commit 1755d5f66221a910863cfc8a197f8d792e6b6e3d) --- source3/passdb/pdb_tdb.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index c48c9567b1..7e2f4b832f 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -37,8 +37,6 @@ static int tdbsam_debug_level = DBGC_ALL; #endif -#ifdef WITH_TDB_SAM - #define PDB_VERSION "20010830" #define PASSDB_FILE_NAME "passdb.tdb" #define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd" @@ -988,20 +986,10 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, return NT_STATUS_OK; } - -#else - -NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +int pdb_tdbsam_init(void) { - DEBUG(0, ("tdbsam not compiled in!\n")); - return NT_STATUS_UNSUCCESSFUL; + smb_register_passdb("tdbsam", pdb_init_tdbsam, PASSDB_INTERFACE_VERSION); + smb_register_passdb("tdbsam_nua", pdb_init_tdbsam_nua, PASSDB_INTERFACE_VERSION); + return True; } -NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) -{ - DEBUG(0, ("tdbsam_nua not compiled in!\n")); - return NT_STATUS_UNSUCCESSFUL; -} - - -#endif -- cgit From 63118136fa9539fde8aad3e4ba5c286484686075 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 23 Apr 2003 00:56:06 +0000 Subject: Merge idra's fix for pdb_tdb segfaults from HEAD to 3.0 - sombody changed unix_strlower semantics. Andrew Bartlett (This used to be commit 93bdd1a2925edb9dea3e85d8b025a65460896c05) --- source3/passdb/pdb_tdb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 7e2f4b832f..3a1702a4e0 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -585,8 +585,10 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT return nt_status; } + /* Data is stored in all lower-case */ - unix_strlower(sname, -1, name, sizeof(name)); + fstrcpy(name, sname); + strlower(name); /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); @@ -692,7 +694,8 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_AC uint32 rid; fstring name; - unix_strlower(pdb_get_username(sam_pass), -1, name, sizeof(name)); + fstrcpy(name, pdb_get_username(sam_pass)); + strlower(name); /* open the TDB */ if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) { @@ -826,7 +829,8 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, } data.dptr = buf; - unix_strlower(pdb_get_username(newpwd), -1, name, sizeof(name)); + fstrcpy(name, pdb_get_username(newpwd)); + strlower(name); DEBUG(5, ("Storing %saccount %s with RID %d\n", flag == TDB_INSERT ? "(new) " : "", name, user_rid)); -- cgit From 49530d0db5a509951c66b73aaf2aa101caf6117b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 28 Apr 2003 10:20:55 +0000 Subject: A new pdb_ldap! This patch removes 'non unix account range' (same as idra's change in HEAD), and uses the winbind uid range instead. More importanly, this patch changes the LDAP schema to use 'ntSid' instead of 'rid' as the primary attribute. This makes it in common with the group mapping code, and should allow it to be used closely with a future idmap_ldap. Existing installations can use the existing functionality by using the ldapsam_compat backend, and users who compile with --with-ldapsam will get this by default. More importantly, this patch adds a 'sambaDomain' object to our schema - which contains 2 'next rid' attributes, the domain name and the domain sid. Yes, there are *2* next rid attributes. The problem is that we don't 'own' the entire RID space - we can only allocate RIDs that could be 'algorithmic' RIDs. Therefore, we use the fact that UIDs in 'winbind uid' range will be mapped by IDMAP, not the algorithm. Andrew Bartlett (This used to be commit 3e07406ade81e136f67439d4f8fd7fe1dbb6db14) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 3a1702a4e0..300b4e8f7d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -978,8 +978,8 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, tdb_state->permit_non_unix_accounts = True; - if (!lp_non_unix_account_range(&low_nua_uid, &high_nua_uid)) { - DEBUG(0, ("cannot use tdbsam_nua without 'non unix account range' in smb.conf!\n")); + if (!lp_winbind_uid(&low_nua_uid, &high_nua_uid)) { + DEBUG(0, ("cannot use tdbsam_nua without 'winbind uid' range in smb.conf!\n")); return NT_STATUS_UNSUCCESSFUL; } -- cgit From 17a3acafa89bfc6090b0767d05a00a7505003fcc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Apr 2003 17:48:48 +0000 Subject: Use NTSTATUS as return value for smb_register_*() functions and init_module() function. Patch by metze with some minor modifications. (This used to be commit bc4b51bcb2daa7271c884cb83bf8bdba6d3a9b6d) --- source3/passdb/pdb_tdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 300b4e8f7d..c3538042ee 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -990,10 +990,10 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, return NT_STATUS_OK; } -int pdb_tdbsam_init(void) +NTSTATUS pdb_tdbsam_init(void) { - smb_register_passdb("tdbsam", pdb_init_tdbsam, PASSDB_INTERFACE_VERSION); - smb_register_passdb("tdbsam_nua", pdb_init_tdbsam_nua, PASSDB_INTERFACE_VERSION); - return True; + smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam", pdb_init_tdbsam); + smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam_nua", pdb_init_tdbsam_nua); + return NT_STATUS_OK; } -- cgit From c823b191ab476fc2583d6d6aaa1e2edb09cbb88e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 May 2003 18:12:31 +0000 Subject: And finally IDMAP in 3_0 We really need idmap_ldap to have a good solution with ldapsam, porting it from the prvious code is beeing made, the code is really simple to do so I am confident it is not a problem to commit this code in. Not committing it would have been worst. I really would have been able to finish also the group code, maybe we can put it into a followin release after 3.0.0 even if it may be an upgrade problem. The code has been tested and seem to work right, more testing is needed for corner cases. Currently winbind pdc (working only for users and not for groups) is disabled as I was not able to make a complete group code replacement that works somewhat in a week (I have a complete patch, but there are bugs) Simo. (This used to be commit 0e58085978f984436815114a2ec347cf7899a89d) --- source3/passdb/pdb_tdb.c | 188 +++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 104 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index c3538042ee..74437cba6f 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -101,7 +101,7 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, BOOL ret = True; struct passwd *pw; uid_t uid = -1; - gid_t gid = -1; /* This is what standard sub advanced expects if no gid is known */ + gid_t gid = -1; if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); @@ -145,30 +145,6 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, goto done; } - /* validate the account and fill in UNIX uid and gid. Standard - * getpwnam() is used instead of Get_Pwnam() as we do not need - * to try case permutations - */ - if (!username || !(pw = getpwnam_alloc(username))) { - if (!(tdb_state->permit_non_unix_accounts)) { - DEBUG(0,("tdbsam: getpwnam_alloc(%s) return NULL. User does not exist!\n", username)); - ret = False; - goto done; - } - } - - if (pw) { - uid = pw->pw_uid; - gid = pw->pw_gid; - - pdb_set_unix_homedir(sampass, pw->pw_dir, PDB_SET); - - passwd_free(&pw); - - pdb_set_uid(sampass, uid, PDB_SET); - pdb_set_gid(sampass, gid, PDB_SET); - } - pdb_set_logon_time(sampass, logon_time, PDB_SET); pdb_set_logoff_time(sampass, logoff_time, PDB_SET); pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET); @@ -664,7 +640,7 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT return nt_status; } - fstrcpy (name, data.dptr); + fstrcpy(name, data.dptr); SAFE_FREE(data.dptr); tdb_close (pwd_tdb); @@ -768,54 +744,40 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, return False; } + if (!pdb_get_group_rid(newpwd)) { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + ret = False; + goto done; + } + /* if flag == TDB_INSERT then make up a new RID else throw an error. */ if (!(user_rid = pdb_get_user_rid(newpwd))) { - if (flag & TDB_INSERT) { - if (IS_SAM_UNIX_USER(newpwd)) { - if (tdb_state->algorithmic_rids) { - user_rid = fallback_pdb_uid_to_user_rid(pdb_get_uid(newpwd)); - } else { - user_rid = BASE_RID; - tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); - if (!tdb_ret) { - ret = False; - goto done; - } - } - pdb_set_user_sid_from_rid(newpwd, user_rid, PDB_CHANGED); - } else { - user_rid = tdb_state->low_nua_rid; - tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "NUA_RID_COUNTER", &user_rid, RID_MULTIPLIER); - if (!tdb_ret) { - ret = False; - goto done; - } - if (user_rid > tdb_state->high_nua_rid) { - DEBUG(0, ("tdbsam: no NUA rids available, cannot add user %s!\n", pdb_get_username(newpwd))); - ret = False; - goto done; - } - pdb_set_user_sid_from_rid(newpwd, user_rid, PDB_CHANGED); + if ((flag & TDB_INSERT) && tdb_state->permit_non_unix_accounts) { + uint32 lowrid, highrid; + if (!idmap_get_free_rid_range(&lowrid, &highrid)) { + /* should never happen */ + DEBUG(0, ("tdbsam: something messed up, no high/low rids but nua enabled ?!\n")); + ret = False; + goto done; } - } else { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); - ret = False; - goto done; - } - } - - if (!pdb_get_group_rid(newpwd)) { - if (flag & TDB_INSERT) { - if (!tdb_state->permit_non_unix_accounts) { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + user_rid = lowrid; + tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); + if (!tdb_ret) { + ret = False; + goto done; + } + if (user_rid > highrid) { + DEBUG(0, ("tdbsam: no NUA rids available, cannot add user %s!\n", pdb_get_username(newpwd))); + ret = False; + goto done; + } + if (!pdb_set_user_sid_from_rid(newpwd, user_rid, PDB_CHANGED)) { + DEBUG(0, ("tdbsam: not able to set new allocated user RID into sam account!\n")); ret = False; goto done; - } else { - /* This seems like a good default choice for non-unix users */ - pdb_set_group_sid_from_rid(newpwd, DOMAIN_GROUP_RID_USERS, PDB_DEFAULT); } } else { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); ret = False; goto done; } @@ -837,7 +799,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, /* setup the USER index key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; - key.dsize = strlen (keystr) + 1; + key.dsize = strlen(keystr) + 1; /* add the account */ if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { @@ -849,7 +811,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, } /* setup RID data */ - data.dsize = sizeof(fstring); + data.dsize = strlen(name) + 1; data.dptr = name; /* setup the RID index key */ @@ -874,6 +836,49 @@ done: return (ret); } +#if 0 +/*************************************************************************** + Allocates a new RID and returns it to the caller as a domain sid + + NOTE: Use carefullt, do not waste RIDs they are a limited resource! + - SSS + ***************************************************************************/ + +static NTSTATUS tdbsam_get_next_sid (struct pdb_methods *my_methods, DOM_SID *sid) +{ + NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; + TDB_CONTEXT *pwd_tdb; + uint32 rid; + + if (sid == NULL) { + return NT_STATUS_INVALID_PARAMETER; + } + + pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); + if (!pwd_tdb) + { + DEBUG(0, ("tdbsam_get_next_sid: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); + return NT_STATUS_UNSUCCESSFUL; + } + + rid = BASE_RID; + if (tdb_change_uint32_atomic(pwd_tdb, "RID_COUNTER", &rid, 1)) { + + sid_copy(sid, get_global_sam_sid()); + if (!sid_append_rid(sid, rid)) { + goto done; + } + + ret = NT_STATUS_OK; + } + +done: + tdb_close (pwd_tdb); + return ret; +} +#endif + /*************************************************************************** Modifies an existing SAM_ACCOUNT ****************************************************************************/ @@ -912,14 +917,7 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con { NTSTATUS nt_status; struct tdbsam_privates *tdb_state; - -#if 0 /* when made a module use this */ - tdbsam_debug_level = debug_add_class("tdbsam"); - if(tdbsam_debug_level == -1) { - tdbsam_debug_level = DBGC_ALL; - DEBUG(0, ("tdbsam: Couldn't register custom debugging class!\n")); - } -#endif + uint32 low_nua_uid, high_nua_uid; if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { return nt_status; @@ -953,47 +951,29 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile); } - tdb_state->algorithmic_rids = True; - (*pdb_method)->private_data = tdb_state; (*pdb_method)->free_private_data = free_private_data; - return NT_STATUS_OK; -} + if (lp_idmap_uid(&low_nua_uid, &high_nua_uid)) { + DEBUG(0, ("idmap uid range defined, non unix accounts enabled\n")); -NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) -{ - NTSTATUS nt_status; - struct tdbsam_privates *tdb_state; - uint32 low_nua_uid, high_nua_uid; - - if (!NT_STATUS_IS_OK(nt_status = pdb_init_tdbsam(pdb_context, pdb_method, location))) { - return nt_status; - } - - (*pdb_method)->name = "tdbsam_nua"; + tdb_state->permit_non_unix_accounts = True; - tdb_state = (*pdb_method)->private_data; + tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); - tdb_state->permit_non_unix_accounts = True; + tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid); - if (!lp_winbind_uid(&low_nua_uid, &high_nua_uid)) { - DEBUG(0, ("cannot use tdbsam_nua without 'winbind uid' range in smb.conf!\n")); - return NT_STATUS_UNSUCCESSFUL; + } else { + tdb_state->algorithmic_rids = True; } - tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); - - tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid); - return NT_STATUS_OK; } -NTSTATUS pdb_tdbsam_init(void) +int pdb_tdbsam_init(void) { smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam", pdb_init_tdbsam); - smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam_nua", pdb_init_tdbsam_nua); - return NT_STATUS_OK; + return True; } -- cgit From 6abef0810007c317c3ee866eb3933ce2c696085f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 May 2003 21:27:54 +0000 Subject: Fix obvious compiler warnings. Jeremy. (This used to be commit 2a6d0c2481c3c34351e57c30a85004babdbf99b0) --- source3/passdb/pdb_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 74437cba6f..93fa4e1886 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -99,7 +99,6 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, uint32 len = 0; uint32 lm_pw_len, nt_pw_len, hourslen; BOOL ret = True; - struct passwd *pw; uid_t uid = -1; gid_t gid = -1; -- cgit From 3ddaeed2828d96dbddfd2232e63e6cbceb74dc36 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 27 May 2003 07:21:57 +0000 Subject: I'm pretty sure these uint32's should be uid_t's. Can the passdb guys please check this? (This used to be commit af4b1f869a7dca0d24391fb2cefef7e05cca2c04) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 93fa4e1886..7f8c2a26f7 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -916,7 +916,7 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con { NTSTATUS nt_status; struct tdbsam_privates *tdb_state; - uint32 low_nua_uid, high_nua_uid; + uid_t low_nua_uid, high_nua_uid; if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { return nt_status; -- cgit From 3d65c033da4704a93bfd99410aa04bb504427c9c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 16 Jun 2003 05:22:53 +0000 Subject: Quieten another debug message. (This used to be commit 2c47893c7542889d9e2ee097897a1df248b1a5e2) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 7f8c2a26f7..a700c2341b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -955,7 +955,7 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->free_private_data = free_private_data; if (lp_idmap_uid(&low_nua_uid, &high_nua_uid)) { - DEBUG(0, ("idmap uid range defined, non unix accounts enabled\n")); + DEBUG(3, ("idmap uid range defined, non unix accounts enabled\n")); tdb_state->permit_non_unix_accounts = True; -- cgit From cafb5c512dda4b8ed2a1ea3d378306ceb3673c88 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 17 Jun 2003 10:38:22 +0000 Subject: The return value of init_module functions is NTSTATUS, not int (This used to be commit f09df852ac0b25470fb9435c79a4a417e06e9b75) --- source3/passdb/pdb_tdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a700c2341b..ddb036596d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -970,9 +970,8 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con return NT_STATUS_OK; } -int pdb_tdbsam_init(void) +NTSTATUS pdb_tdbsam_init(void) { - smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam", pdb_init_tdbsam); - return True; + return smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam", pdb_init_tdbsam); } -- cgit From c0e24984f0596a5aa9181913c3bd67419f7b70f7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 17 Jun 2003 10:48:06 +0000 Subject: Make static (patch from metze) (This used to be commit 908b16cc2a8b6c5c67aae0e1af9d51f57fe31212) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index ddb036596d..912634a1b1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -912,7 +912,7 @@ static void free_private_data(void **vp) } -NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) { NTSTATUS nt_status; struct tdbsam_privates *tdb_state; -- cgit From 9606397ab1216f995c017957da619a00394b5c7f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Jun 2003 12:03:48 +0000 Subject: Fix a memory leak in pdb_tdb.c. Simo, I remember you complaining about a memleak there, could it be this one, or did you resolve it at that time? Volker (This used to be commit c660595deda2ce836c0a191da0236f850004ba0d) --- source3/passdb/pdb_tdb.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 912634a1b1..d323c20d32 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -242,6 +242,8 @@ done: SAFE_FREE(acct_desc); SAFE_FREE(workstations); SAFE_FREE(munged_dial); + SAFE_FREE(unknown_str); + SAFE_FREE(hours); return ret; } -- cgit From e6fd597fce61787789b76c323c56edc979e4e1fc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 18 Jun 2003 12:00:52 +0000 Subject: And some more memory leaks in mapping.c and pdb_tdb.c. tdb_nextkey mallocs its key, so we should free it after use. Volker (This used to be commit 9750799ba2e1aaa59fa255f23880c9c618195c3d) --- source3/passdb/pdb_tdb.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index d323c20d32..2cf7a0119f 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -490,6 +490,7 @@ static void close_tdb(struct tdbsam_privates *tdb_state) static void tdbsam_endsampwent(struct pdb_methods *my_methods) { struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; + SAFE_FREE(tdb_state->key.dptr); close_tdb(tdb_state); DEBUG(7, ("endtdbpwent: closed sam database.\n")); @@ -503,7 +504,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_DATA data; + TDB_DATA data, old_key; const char *prefix = USERPREFIX; int prefixlen = strlen (prefix); @@ -514,10 +515,16 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * } /* skip all non-USER entries (eg. RIDs) */ - while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen))) + while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen))) { + + old_key = tdb_state->key; + /* increment to next in line */ tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); + SAFE_FREE(old_key.dptr); + } + /* do we have an valid iteration pointer? */ if(tdb_state->passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); @@ -538,9 +545,13 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * } SAFE_FREE(data.dptr); + old_key = tdb_state->key; + /* increment to next in line */ tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); + SAFE_FREE(old_key.dptr); + return NT_STATUS_OK; } -- cgit From ce72beb2b558d86fb49063c6b1fa00e07952ce56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Jul 2003 19:11:31 +0000 Subject: Removed strupper/strlower macros that automatically map to strupper_m/strlower_m. I really want people to think about when they're using multibyte strings. Jeremy. (This used to be commit ff222716a08af65d26ad842ce4c2841cc6540959) --- source3/passdb/pdb_tdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 2cf7a0119f..77473fe0dc 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -576,7 +576,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT /* Data is stored in all lower-case */ fstrcpy(name, sname); - strlower(name); + strlower_m(name); /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); @@ -683,7 +683,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_AC fstring name; fstrcpy(name, pdb_get_username(sam_pass)); - strlower(name); + strlower_m(name); /* open the TDB */ if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) { @@ -804,7 +804,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, data.dptr = buf; fstrcpy(name, pdb_get_username(newpwd)); - strlower(name); + strlower_m(name); DEBUG(5, ("Storing %saccount %s with RID %d\n", flag == TDB_INSERT ? "(new) " : "", name, user_rid)); -- cgit From 5895dfb89b27de6fcdcdd0233ae1ea34be03235e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 7 Jul 2003 20:00:29 +0000 Subject: Cleaning up linking issues. sam/idmap*.c only links in winbindd now. Also removing an unused file. (This used to be commit 688369c23c604e9b6654fcf07190d2e27c1138cf) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 77473fe0dc..6a8589b5df 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -766,7 +766,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, if (!(user_rid = pdb_get_user_rid(newpwd))) { if ((flag & TDB_INSERT) && tdb_state->permit_non_unix_accounts) { uint32 lowrid, highrid; - if (!idmap_get_free_rid_range(&lowrid, &highrid)) { + if (!pdb_get_free_rid_range(&lowrid, &highrid)) { /* should never happen */ DEBUG(0, ("tdbsam: something messed up, no high/low rids but nua enabled ?!\n")); ret = False; -- cgit From e4bfa0a4608d794fd0c6228b58469ddf5473b7b4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Jul 2003 21:58:29 +0000 Subject: Moved SAM_ACCOUNT marshall/unmarshall functions to make them externally available. Removed extra auth_init (thanks metze). Jeremy. (This used to be commit 88135fbc4998c266052647f8b8e437ac01cf50ae) --- source3/passdb/pdb_tdb.c | 404 +---------------------------------------------- 1 file changed, 3 insertions(+), 401 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6a8589b5df..a166697b4b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -39,7 +39,6 @@ static int tdbsam_debug_level = DBGC_ALL; #define PDB_VERSION "20010830" #define PASSDB_FILE_NAME "passdb.tdb" -#define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd" #define USERPREFIX "USER_" #define RIDPREFIX "RID_" @@ -58,403 +57,6 @@ struct tdbsam_privates { uint32 high_nua_rid; }; -/********************************************************************** - Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len - *********************************************************************/ - -static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state, - SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) -{ - - /* times are stored as 32bit integer - take care on system with 64bit wide time_t - --SSS */ - uint32 logon_time, - logoff_time, - kickoff_time, - pass_last_set_time, - pass_can_change_time, - pass_must_change_time; - char *username; - char *domain; - char *nt_username; - char *dir_drive; - char *unknown_str; - char *munged_dial; - char *fullname; - char *homedir; - char *logon_script; - char *profile_path; - char *acct_desc; - char *workstations; - uint32 username_len, domain_len, nt_username_len, - dir_drive_len, unknown_str_len, munged_dial_len, - fullname_len, homedir_len, logon_script_len, - profile_path_len, acct_desc_len, workstations_len; - - uint32 user_rid, group_rid, unknown_3, hours_len, unknown_5, unknown_6; - uint16 acct_ctrl, logon_divs; - uint8 *hours; - static uint8 *lm_pw_ptr, *nt_pw_ptr; - uint32 len = 0; - uint32 lm_pw_len, nt_pw_len, hourslen; - BOOL ret = True; - uid_t uid = -1; - gid_t gid = -1; - - if(sampass == NULL || buf == NULL) { - DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n")); - return False; - } - - /* unpack the buffer into variables */ - len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, - &logon_time, - &logoff_time, - &kickoff_time, - &pass_last_set_time, - &pass_can_change_time, - &pass_must_change_time, - &username_len, &username, - &domain_len, &domain, - &nt_username_len, &nt_username, - &fullname_len, &fullname, - &homedir_len, &homedir, - &dir_drive_len, &dir_drive, - &logon_script_len, &logon_script, - &profile_path_len, &profile_path, - &acct_desc_len, &acct_desc, - &workstations_len, &workstations, - &unknown_str_len, &unknown_str, - &munged_dial_len, &munged_dial, - &user_rid, - &group_rid, - &lm_pw_len, &lm_pw_ptr, - &nt_pw_len, &nt_pw_ptr, - &acct_ctrl, - &unknown_3, - &logon_divs, - &hours_len, - &hourslen, &hours, - &unknown_5, - &unknown_6); - - if (len == -1) { - ret = False; - goto done; - } - - pdb_set_logon_time(sampass, logon_time, PDB_SET); - pdb_set_logoff_time(sampass, logoff_time, PDB_SET); - pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET); - pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET); - pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET); - pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET); - - pdb_set_username (sampass, username, PDB_SET); - pdb_set_domain (sampass, domain, PDB_SET); - pdb_set_nt_username (sampass, nt_username, PDB_SET); - pdb_set_fullname (sampass, fullname, PDB_SET); - - if (homedir) { - pdb_set_homedir(sampass, homedir, PDB_SET); - } - else { - pdb_set_homedir(sampass, - talloc_sub_specified(sampass->mem_ctx, - lp_logon_home(), - username, domain, - uid, gid), - PDB_DEFAULT); - } - - if (dir_drive) - pdb_set_dir_drive(sampass, dir_drive, PDB_SET); - else { - pdb_set_dir_drive(sampass, - talloc_sub_specified(sampass->mem_ctx, - lp_logon_drive(), - username, domain, - uid, gid), - PDB_DEFAULT); - } - - if (logon_script) - pdb_set_logon_script(sampass, logon_script, PDB_SET); - else { - pdb_set_logon_script(sampass, - talloc_sub_specified(sampass->mem_ctx, - lp_logon_script(), - username, domain, - uid, gid), - PDB_DEFAULT); - } - - if (profile_path) { - pdb_set_profile_path(sampass, profile_path, PDB_SET); - } else { - pdb_set_profile_path(sampass, - talloc_sub_specified(sampass->mem_ctx, - lp_logon_path(), - username, domain, - uid, gid), - PDB_DEFAULT); - } - - pdb_set_acct_desc (sampass, acct_desc, PDB_SET); - pdb_set_workstations (sampass, workstations, PDB_SET); - pdb_set_munged_dial (sampass, munged_dial, PDB_SET); - - if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { - if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) { - ret = False; - goto done; - } - } - - if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { - if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) { - ret = False; - goto done; - } - } - - pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); - pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); - pdb_set_unknown_3(sampass, unknown_3, PDB_SET); - pdb_set_hours_len(sampass, hours_len, PDB_SET); - pdb_set_unknown_5(sampass, unknown_5, PDB_SET); - pdb_set_unknown_6(sampass, unknown_6, PDB_SET); - pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET); - pdb_set_logon_divs(sampass, logon_divs, PDB_SET); - pdb_set_hours(sampass, hours, PDB_SET); - -done: - - SAFE_FREE(username); - SAFE_FREE(domain); - SAFE_FREE(nt_username); - SAFE_FREE(fullname); - SAFE_FREE(homedir); - SAFE_FREE(dir_drive); - SAFE_FREE(logon_script); - SAFE_FREE(profile_path); - SAFE_FREE(acct_desc); - SAFE_FREE(workstations); - SAFE_FREE(munged_dial); - SAFE_FREE(unknown_str); - SAFE_FREE(hours); - - return ret; -} - -/********************************************************************** - Intialize a BYTE buffer from a SAM_ACCOUNT struct - *********************************************************************/ -static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, - uint8 **buf, const SAM_ACCOUNT *sampass) -{ - size_t len, buflen; - - /* times are stored as 32bit integer - take care on system with 64bit wide time_t - --SSS */ - uint32 logon_time, - logoff_time, - kickoff_time, - pass_last_set_time, - pass_can_change_time, - pass_must_change_time; - - uint32 user_rid, group_rid; - - const char *username; - const char *domain; - const char *nt_username; - const char *dir_drive; - const char *unknown_str; - const char *munged_dial; - const char *fullname; - const char *homedir; - const char *logon_script; - const char *profile_path; - const char *acct_desc; - const char *workstations; - uint32 username_len, domain_len, nt_username_len, - dir_drive_len, unknown_str_len, munged_dial_len, - fullname_len, homedir_len, logon_script_len, - profile_path_len, acct_desc_len, workstations_len; - - const uint8 *lm_pw; - const uint8 *nt_pw; - uint32 lm_pw_len = 16; - uint32 nt_pw_len = 16; - - /* do we have a valid SAM_ACCOUNT pointer? */ - if (sampass == NULL) { - DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n")); - return -1; - } - - *buf = NULL; - buflen = 0; - - logon_time = (uint32)pdb_get_logon_time(sampass); - logoff_time = (uint32)pdb_get_logoff_time(sampass); - kickoff_time = (uint32)pdb_get_kickoff_time(sampass); - pass_can_change_time = (uint32)pdb_get_pass_can_change_time(sampass); - pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass); - pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass); - - user_rid = pdb_get_user_rid(sampass); - group_rid = pdb_get_group_rid(sampass); - - username = pdb_get_username(sampass); - if (username) username_len = strlen(username) +1; - else username_len = 0; - - domain = pdb_get_domain(sampass); - if (domain) domain_len = strlen(domain) +1; - else domain_len = 0; - - nt_username = pdb_get_nt_username(sampass); - if (nt_username) nt_username_len = strlen(nt_username) +1; - else nt_username_len = 0; - - fullname = pdb_get_fullname(sampass); - if (fullname) fullname_len = strlen(fullname) +1; - else fullname_len = 0; - - /* - * Only updates fields which have been set (not defaults from smb.conf) - */ - - if (!IS_SAM_DEFAULT(sampass, PDB_DRIVE)) - dir_drive = pdb_get_dir_drive(sampass); - else dir_drive = NULL; - if (dir_drive) dir_drive_len = strlen(dir_drive) +1; - else dir_drive_len = 0; - - if (!IS_SAM_DEFAULT(sampass, PDB_SMBHOME)) homedir = pdb_get_homedir(sampass); - else homedir = NULL; - if (homedir) homedir_len = strlen(homedir) +1; - else homedir_len = 0; - - if (!IS_SAM_DEFAULT(sampass, PDB_LOGONSCRIPT)) logon_script = pdb_get_logon_script(sampass); - else logon_script = NULL; - if (logon_script) logon_script_len = strlen(logon_script) +1; - else logon_script_len = 0; - - if (!IS_SAM_DEFAULT(sampass, PDB_PROFILE)) profile_path = pdb_get_profile_path(sampass); - else profile_path = NULL; - if (profile_path) profile_path_len = strlen(profile_path) +1; - else profile_path_len = 0; - - lm_pw = pdb_get_lanman_passwd(sampass); - if (!lm_pw) lm_pw_len = 0; - - nt_pw = pdb_get_nt_passwd(sampass); - if (!nt_pw) nt_pw_len = 0; - - acct_desc = pdb_get_acct_desc(sampass); - if (acct_desc) acct_desc_len = strlen(acct_desc) +1; - else acct_desc_len = 0; - - workstations = pdb_get_workstations(sampass); - if (workstations) workstations_len = strlen(workstations) +1; - else workstations_len = 0; - - unknown_str = NULL; - unknown_str_len = 0; - - munged_dial = pdb_get_munged_dial(sampass); - if (munged_dial) munged_dial_len = strlen(munged_dial) +1; - else munged_dial_len = 0; - - /* one time to get the size needed */ - len = tdb_pack(NULL, 0, TDB_FORMAT_STRING, - logon_time, - logoff_time, - kickoff_time, - pass_last_set_time, - pass_can_change_time, - pass_must_change_time, - username_len, username, - domain_len, domain, - nt_username_len, nt_username, - fullname_len, fullname, - homedir_len, homedir, - dir_drive_len, dir_drive, - logon_script_len, logon_script, - profile_path_len, profile_path, - acct_desc_len, acct_desc, - workstations_len, workstations, - unknown_str_len, unknown_str, - munged_dial_len, munged_dial, - user_rid, - group_rid, - lm_pw_len, lm_pw, - nt_pw_len, nt_pw, - pdb_get_acct_ctrl(sampass), - pdb_get_unknown_3(sampass), - pdb_get_logon_divs(sampass), - pdb_get_hours_len(sampass), - MAX_HOURS_LEN, pdb_get_hours(sampass), - pdb_get_unknown_5(sampass), - pdb_get_unknown_6(sampass)); - - - /* malloc the space needed */ - if ( (*buf=(uint8*)malloc(len)) == NULL) { - DEBUG(0,("init_buffer_from_sam: Unable to malloc() memory for buffer!\n")); - return (-1); - } - - /* now for the real call to tdb_pack() */ - buflen = tdb_pack(*buf, len, TDB_FORMAT_STRING, - logon_time, - logoff_time, - kickoff_time, - pass_last_set_time, - pass_can_change_time, - pass_must_change_time, - username_len, username, - domain_len, domain, - nt_username_len, nt_username, - fullname_len, fullname, - homedir_len, homedir, - dir_drive_len, dir_drive, - logon_script_len, logon_script, - profile_path_len, profile_path, - acct_desc_len, acct_desc, - workstations_len, workstations, - unknown_str_len, unknown_str, - munged_dial_len, munged_dial, - user_rid, - group_rid, - lm_pw_len, lm_pw, - nt_pw_len, nt_pw, - pdb_get_acct_ctrl(sampass), - pdb_get_unknown_3(sampass), - pdb_get_logon_divs(sampass), - pdb_get_hours_len(sampass), - MAX_HOURS_LEN, pdb_get_hours(sampass), - pdb_get_unknown_5(sampass), - pdb_get_unknown_6(sampass)); - - - /* check to make sure we got it correct */ - if (buflen != len) { - DEBUG(0, ("init_buffer_from_sam: somthing odd is going on here: bufflen (%d) != len (%d) in tdb_pack operations!\n", - buflen, len)); - /* error */ - SAFE_FREE (*buf); - return (-1); - } - - return (buflen); -} - /*************************************************************** Open the TDB passwd database for SAM account enumeration. ****************************************************************/ @@ -538,7 +140,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * } /* unpack the buffer */ - if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); return nt_status; @@ -600,7 +202,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT } /* unpack the buffer */ - if (!init_sam_from_buffer(tdb_state, user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); tdb_close(pwd_tdb); @@ -796,7 +398,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, } /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ - if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd)) == -1) { + if ((data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); ret = False; goto done; -- cgit From 03d5867d529f126da368ebda70bf2d997aa602e0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Jul 2003 05:33:40 +0000 Subject: moving more code around. * move rid allocation into IDMAP. See comments in _api_samr_create_user() * add winbind delete user/group functions I'm checking this in to sync up with everyone. But I'm going to split the add a separate winbindd_allocate_rid() function for systems that have an 'add user script' but need idmap to give them a RID. Life would be so much simplier without 'enable rid algorithm'. The current RID allocation is horrible due to this one fact. Tested idmap_tdb but not idmap_ldap yet. Will do that tomorrow. Nothing has changed in the way a samba domain is represented, stored, or search in the directory so things should be ok with previous installations. going to bed now. (This used to be commit 0463045cc7ff177fab44b25faffad5bf7140244d) --- source3/passdb/pdb_tdb.c | 77 ++++++++---------------------------------------- 1 file changed, 13 insertions(+), 64 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a166697b4b..6f5d348ce1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1,11 +1,11 @@ /* * Unix SMB/CIFS implementation. * SMB parameters and setup - * Copyright (C) Andrew Tridgell 1992-1998 - * Copyright (C) Simo Sorce 2000-2002 - * Copyright (C) Gerald Carter 2000 - * Copyright (C) Jeremy Allison 2001 - * Copyright (C) Andrew Bartlett 2002 + * Copyright (C) Andrew Tridgell 1992-1998 + * Copyright (C) Simo Sorce 2000-2002 + * Copyright (C) Gerald Carter 2000 + * Copyright (C) Jeremy Allison 2001 + * Copyright (C) Andrew Bartlett 2002 * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -48,13 +48,6 @@ struct tdbsam_privates { /* retrive-once info */ const char *tdbsam_location; - - BOOL permit_non_unix_accounts; - - BOOL algorithmic_rids; - - uint32 low_nua_rid; - uint32 high_nua_rid; }; /*************************************************************** @@ -342,61 +335,31 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, fstring name; BOOL ret = True; uint32 user_rid; - BOOL tdb_ret; /* invalidate the existing TDB iterator if it is open */ + if (tdb_state->passwd_tdb) { tdb_close(tdb_state->passwd_tdb); tdb_state->passwd_tdb = NULL; } /* open the account TDB passwd*/ + pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); - if (!pwd_tdb) - { - DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); + + if (!pwd_tdb) { + DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", + tdb_state->tdbsam_location)); return False; } if (!pdb_get_group_rid(newpwd)) { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd))); + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n", + pdb_get_username(newpwd))); ret = False; goto done; } - /* if flag == TDB_INSERT then make up a new RID else throw an error. */ - if (!(user_rid = pdb_get_user_rid(newpwd))) { - if ((flag & TDB_INSERT) && tdb_state->permit_non_unix_accounts) { - uint32 lowrid, highrid; - if (!pdb_get_free_rid_range(&lowrid, &highrid)) { - /* should never happen */ - DEBUG(0, ("tdbsam: something messed up, no high/low rids but nua enabled ?!\n")); - ret = False; - goto done; - } - user_rid = lowrid; - tdb_ret = tdb_change_uint32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER); - if (!tdb_ret) { - ret = False; - goto done; - } - if (user_rid > highrid) { - DEBUG(0, ("tdbsam: no NUA rids available, cannot add user %s!\n", pdb_get_username(newpwd))); - ret = False; - goto done; - } - if (!pdb_set_user_sid_from_rid(newpwd, user_rid, PDB_CHANGED)) { - DEBUG(0, ("tdbsam: not able to set new allocated user RID into sam account!\n")); - ret = False; - goto done; - } - } else { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd))); - ret = False; - goto done; - } - } - /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); @@ -531,7 +494,6 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth { NTSTATUS nt_status; struct tdbsam_privates *tdb_state; - uid_t low_nua_uid, high_nua_uid; if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { return nt_status; @@ -569,19 +531,6 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth (*pdb_method)->free_private_data = free_private_data; - if (lp_idmap_uid(&low_nua_uid, &high_nua_uid)) { - DEBUG(3, ("idmap uid range defined, non unix accounts enabled\n")); - - tdb_state->permit_non_unix_accounts = True; - - tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid); - - tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid); - - } else { - tdb_state->algorithmic_rids = True; - } - return NT_STATUS_OK; } -- cgit From 24ce328662bcfb412071ff6b016aa7a61c184543 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Jul 2003 15:17:06 +0000 Subject: fix unitialised variable (This used to be commit 5efa0d7cc28d903c1986b8e40072ae49e9532a88) --- source3/passdb/pdb_tdb.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6f5d348ce1..1078a5bd26 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -360,6 +360,12 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, goto done; } + if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { + DEBUG(0,("tdb_update_sam: SAM_ACCOUNT (%s) with no RID!\n", pdb_get_username(newpwd))); + ret = False; + goto done; + } + /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); -- cgit From b3064ac5d64f54562e4f2d7d1b021374def1352d Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Sun, 20 Jul 2003 21:43:41 +0000 Subject: This creates passdb backend files automatically when adding first account. An extra message notifying that needed file didn't exist is displayed. There's still a little catch with tdb backend, but it's better than it was, from end-user's point of view. This fixes #198 rafal (This used to be commit b0be700605c289ce8e9dd3abe49d78ac77256911) --- source3/passdb/pdb_tdb.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1078a5bd26..051a699357 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -180,6 +180,24 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT /* open the accounts TDB */ if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { + + if (errno == ENOENT) { + /* + * TDB file doesn't exist, so try to create new one. This is useful to avoid + * confusing error msg when adding user account first time + */ + if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_CREAT, 0600))) { + DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n", + tdb_state->tdbsam_location)); + } else { + DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) does not exist. Couldn't create new one. Error was: %s\n", + tdb_state->tdbsam_location, strerror(errno))); + } + + /* requested user isn't there anyway */ + nt_status = NT_STATUS_NO_SUCH_USER; + return nt_status; + } DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); return nt_status; } @@ -423,7 +441,7 @@ done: /*************************************************************************** Allocates a new RID and returns it to the caller as a domain sid - NOTE: Use carefullt, do not waste RIDs they are a limited resource! + NOTE: Use carefully, do not waste RIDs they are a limited resource! - SSS ***************************************************************************/ -- cgit From c51ffbbdaaf43e24114becbbff976e2254c199ea Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Jul 2003 15:08:34 +0000 Subject: removing unused function (This used to be commit b8394a107d3448434f1a34076eaab8e6dd9a8a9d) --- source3/passdb/pdb_tdb.c | 43 ------------------------------------------- 1 file changed, 43 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 051a699357..7c2156455a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -437,49 +437,6 @@ done: return (ret); } -#if 0 -/*************************************************************************** - Allocates a new RID and returns it to the caller as a domain sid - - NOTE: Use carefully, do not waste RIDs they are a limited resource! - - SSS - ***************************************************************************/ - -static NTSTATUS tdbsam_get_next_sid (struct pdb_methods *my_methods, DOM_SID *sid) -{ - NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_CONTEXT *pwd_tdb; - uint32 rid; - - if (sid == NULL) { - return NT_STATUS_INVALID_PARAMETER; - } - - pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); - if (!pwd_tdb) - { - DEBUG(0, ("tdbsam_get_next_sid: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); - return NT_STATUS_UNSUCCESSFUL; - } - - rid = BASE_RID; - if (tdb_change_uint32_atomic(pwd_tdb, "RID_COUNTER", &rid, 1)) { - - sid_copy(sid, get_global_sam_sid()); - if (!sid_append_rid(sid, rid)) { - goto done; - } - - ret = NT_STATUS_OK; - } - -done: - tdb_close (pwd_tdb); - return ret; -} -#endif - /*************************************************************************** Modifies an existing SAM_ACCOUNT ****************************************************************************/ -- cgit From 062f89bc2833bf49f873a7fd5c2624babd702db0 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 15 Aug 2003 01:42:30 +0000 Subject: get rid of some sompiler warnings on IRIX (This used to be commit a6a39c61e8228c8b3b7552ab3c61ec3a6a639143) --- source3/passdb/pdb_tdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 7c2156455a..c9a84f3242 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -133,7 +133,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * } /* unpack the buffer */ - if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); return nt_status; @@ -213,7 +213,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT } /* unpack the buffer */ - if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); tdb_close(pwd_tdb); @@ -390,7 +390,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, ret = False; goto done; } - data.dptr = buf; + data.dptr = (char *)buf; fstrcpy(name, pdb_get_username(newpwd)); strlower_m(name); -- cgit From da520049883b7f95e468a73ebb2c2511e794f977 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 11 Feb 2004 21:10:04 +0000 Subject: fix set/getsampwent iterator in tdbsam to use an allocated list (This used to be commit 8734d91cd7681219f1389e3c41979028eadbb7fe) --- source3/passdb/pdb_tdb.c | 145 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 44 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index c9a84f3242..e4ef51a46d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -44,30 +44,69 @@ static int tdbsam_debug_level = DBGC_ALL; struct tdbsam_privates { TDB_CONTEXT *passwd_tdb; - TDB_DATA key; /* retrive-once info */ const char *tdbsam_location; }; -/*************************************************************** - Open the TDB passwd database for SAM account enumeration. -****************************************************************/ +struct pwent_list { + struct pwent_list *prev, *next; + TDB_DATA key; +}; +static struct pwent_list *tdbsam_pwent_list; -static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) + +/**************************************************************************** + creates a list of user keys +****************************************************************************/ + +static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *state) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; + const char *prefix = USERPREFIX; + int prefixlen = strlen (prefix); + struct pwent_list *ptr; - /* Open tdb passwd */ - if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600))) + if ( strncmp(key.dptr, prefix, prefixlen) == 0 ) { + if ( !(ptr=(struct pwent_list*)malloc(sizeof(struct pwent_list))) ) { + DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n")); + + /* just return 0 and let the traversal continue */ + return 0; + } + ZERO_STRUCTP(ptr); + + /* save a copy of the key */ + + ptr->key.dptr = memdup( key.dptr, key.dsize ); + ptr->key.dsize = key.dsize; + + DLIST_ADD( tdbsam_pwent_list, ptr ); + + } + + + return 0; +} + +/***************************************************************************** + Utility functions to open and close the tdb sam database + ****************************************************************************/ + +static BOOL open_tdbsam( struct tdbsam_privates *tdb_state, BOOL update ) +{ + /* check if we already have the tdbsam open */ + + if ( tdb_state->passwd_tdb ) + return True; + + if ( !(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, + 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600)) ) { DEBUG(0, ("Unable to open/create TDB passwd\n")); - return NT_STATUS_UNSUCCESSFUL; + return False; } - - tdb_state->key = tdb_firstkey(tdb_state->passwd_tdb); - return NT_STATUS_OK; + return True; } static void close_tdb(struct tdbsam_privates *tdb_state) @@ -78,6 +117,25 @@ static void close_tdb(struct tdbsam_privates *tdb_state) } } +/*************************************************************** + Open the TDB passwd database for SAM account enumeration. + Save a list of user keys for iteration. +****************************************************************/ + +static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) +{ + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; + + /* Open tdb passwd */ + if ( !open_tdbsam(tdb_state, update) ) + return NT_STATUS_UNSUCCESSFUL; + + tdb_traverse( tdb_state->passwd_tdb, tdbsam_traverse_setpwent, NULL ); + + return NT_STATUS_OK; +} + + /*************************************************************** End enumeration of the TDB passwd list. ****************************************************************/ @@ -85,9 +143,18 @@ static void close_tdb(struct tdbsam_privates *tdb_state) static void tdbsam_endsampwent(struct pdb_methods *my_methods) { struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - SAFE_FREE(tdb_state->key.dptr); + struct pwent_list *ptr; + close_tdb(tdb_state); + /* clear out any remaining entries in the list */ + + for ( ptr=tdbsam_pwent_list; ptr; ptr=ptr->next ) { + DLIST_REMOVE( tdbsam_pwent_list, ptr ); + SAFE_FREE( ptr->key.dptr); + SAFE_FREE( ptr ); + } + DEBUG(7, ("endtdbpwent: closed sam database.\n")); } @@ -97,55 +164,45 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user) { - NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_DATA data, old_key; - const char *prefix = USERPREFIX; - int prefixlen = strlen (prefix); - + TDB_DATA data; + struct pwent_list *pkey; - if (user==NULL) { - DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n")); + if ( !user ) { + DEBUG(0,("tdbsam_getsampwent: SAM_ACCOUNT is NULL.\n")); return nt_status; } - /* skip all non-USER entries (eg. RIDs) */ - while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen))) { - - old_key = tdb_state->key; - - /* increment to next in line */ - tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); - - SAFE_FREE(old_key.dptr); - } + if( !open_tdbsam(tdb_state, True) ) + return nt_status; - /* do we have an valid iteration pointer? */ - if(tdb_state->passwd_tdb == NULL) { - DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); + if ( !tdbsam_pwent_list ) { + DEBUG(4,("tdbsam_getsampwent: end of list\n")); return nt_status; } - data = tdb_fetch(tdb_state->passwd_tdb, tdb_state->key); + /* pull the next entry */ + + pkey = tdbsam_pwent_list; + DLIST_REMOVE( tdbsam_pwent_list, pkey ); + + data = tdb_fetch(tdb_state->passwd_tdb, pkey->key); + + SAFE_FREE( pkey->key.dptr); + SAFE_FREE( pkey); + if (!data.dptr) { - DEBUG(5,("pdb_getsampwent: database entry not found.\n")); + DEBUG(5,("pdb_getsampwent: database entry not found. Was the user deleted?\n")); return nt_status; } - /* unpack the buffer */ if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); - SAFE_FREE(data.dptr); - return nt_status; } - SAFE_FREE(data.dptr); - old_key = tdb_state->key; + SAFE_FREE( data.dptr ); - /* increment to next in line */ - tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key); - - SAFE_FREE(old_key.dptr); return NT_STATUS_OK; } -- cgit From 16733020e3b61e7beb7c7a4f7bafa796ee3e92e2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Feb 2004 22:47:12 +0000 Subject: Don't set an iterator to a piece of free'd memory, store it first. Jeremy. (This used to be commit e914230a2d1a7b515bd7859d655d6555b7d3e67e) --- source3/passdb/pdb_tdb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e4ef51a46d..22818b058b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -143,13 +143,14 @@ static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) static void tdbsam_endsampwent(struct pdb_methods *my_methods) { struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - struct pwent_list *ptr; + struct pwent_list *ptr, *ptr_next; close_tdb(tdb_state); /* clear out any remaining entries in the list */ - for ( ptr=tdbsam_pwent_list; ptr; ptr=ptr->next ) { + for ( ptr=tdbsam_pwent_list; ptr; ptr = ptr_next ) { + ptr_next = ptr->next; DLIST_REMOVE( tdbsam_pwent_list, ptr ); SAFE_FREE( ptr->key.dptr); SAFE_FREE( ptr ); -- cgit From a6a2a696807992e60c905ff28828317fbcbe3913 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 12 Feb 2004 05:07:44 +0000 Subject: updates for tdbsam code to help make merge into head easier; needs a bit more testing tomorrow but initial results seem ok (This used to be commit daee8d7feee4a08d6c204e2de3f346b6d10640e6) --- source3/passdb/pdb_tdb.c | 99 ++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 46 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 22818b058b..554d330ce0 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -43,7 +43,7 @@ static int tdbsam_debug_level = DBGC_ALL; #define RIDPREFIX "RID_" struct tdbsam_privates { - TDB_CONTEXT *passwd_tdb; + TDB_CONTEXT *passwd_tdb; /* retrive-once info */ const char *tdbsam_location; @@ -55,6 +55,39 @@ struct pwent_list { }; static struct pwent_list *tdbsam_pwent_list; +/***************************************************************************** + Utility functions to open the tdb sam database + ****************************************************************************/ + +static TDB_CONTEXT * tdbsam_tdbopen (const char *name, int open_flags) +{ + TDB_CONTEXT *tdb; + + if ( !(tdb = tdb_open_log(name, 0, TDB_DEFAULT, open_flags, 0600)) ) { + DEBUG(0, ("Unable to open/create TDB passwd\n")); + return NULL; + } + + return tdb; +} + +/***************************************************************************** + Utility functions to open the tdb sam database + ****************************************************************************/ + +static void tdbsam_tdbclose ( struct tdbsam_privates *state ) +{ + if ( !state ) + return; + + if ( state->passwd_tdb ) { + tdb_close( state->passwd_tdb ); + state->passwd_tdb = NULL; + } + + return; + +} /**************************************************************************** creates a list of user keys @@ -88,35 +121,6 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, return 0; } -/***************************************************************************** - Utility functions to open and close the tdb sam database - ****************************************************************************/ - -static BOOL open_tdbsam( struct tdbsam_privates *tdb_state, BOOL update ) -{ - /* check if we already have the tdbsam open */ - - if ( tdb_state->passwd_tdb ) - return True; - - if ( !(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, - 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600)) ) - { - DEBUG(0, ("Unable to open/create TDB passwd\n")); - return False; - } - - return True; -} - -static void close_tdb(struct tdbsam_privates *tdb_state) -{ - if (tdb_state->passwd_tdb) { - tdb_close(tdb_state->passwd_tdb); - tdb_state->passwd_tdb = NULL; - } -} - /*************************************************************** Open the TDB passwd database for SAM account enumeration. Save a list of user keys for iteration. @@ -124,14 +128,15 @@ static void close_tdb(struct tdbsam_privates *tdb_state) static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) { + uint32 flags = update ? (O_RDWR|O_CREAT) : O_RDONLY; + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - /* Open tdb passwd */ - if ( !open_tdbsam(tdb_state, update) ) + if ( !(tdb_state->passwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, flags )) ) return NT_STATUS_UNSUCCESSFUL; tdb_traverse( tdb_state->passwd_tdb, tdbsam_traverse_setpwent, NULL ); - + return NT_STATUS_OK; } @@ -145,7 +150,7 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; struct pwent_list *ptr, *ptr_next; - close_tdb(tdb_state); + tdbsam_tdbclose( tdb_state ); /* clear out any remaining entries in the list */ @@ -175,13 +180,16 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * return nt_status; } - if( !open_tdbsam(tdb_state, True) ) - return nt_status; - if ( !tdbsam_pwent_list ) { DEBUG(4,("tdbsam_getsampwent: end of list\n")); + tdbsam_tdbclose( tdb_state ); return nt_status; } + + if ( !tdb_state->passwd_tdb ) { + if ( !(tdb_state->passwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY)) ) + return nt_status; + } /* pull the next entry */ @@ -221,11 +229,10 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT fstring keystr; fstring name; - if (user==NULL) { + if ( !user ) { DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); return nt_status; } - /* Data is stored in all lower-case */ fstrcpy(name, sname); @@ -237,14 +244,14 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT key.dsize = strlen(keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { + if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY))) { if (errno == ENOENT) { /* * TDB file doesn't exist, so try to create new one. This is useful to avoid * confusing error msg when adding user account first time */ - if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_CREAT, 0600))) { + if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT ))) { DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n", tdb_state->tdbsam_location)); } else { @@ -309,14 +316,14 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) { + if ( !(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY)) ) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return nt_status; } /* get the record */ data = tdb_fetch (pwd_tdb, key); - if (!data.dptr) { + if ( !data.dptr ) { DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); @@ -357,7 +364,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_AC strlower_m(name); /* open the TDB */ - if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) { + if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR))) { DEBUG(0, ("Unable to open TDB passwd!")); return nt_status; } @@ -421,7 +428,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, /* open the account TDB passwd*/ - pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600); + pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR | O_CREAT); if (!pwd_tdb) { DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", @@ -522,7 +529,7 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO static void free_private_data(void **vp) { struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; - close_tdb(*tdb_state); + tdbsam_tdbclose(*tdb_state); *tdb_state = NULL; /* No need to free any further, as it is talloc()ed */ -- cgit From d21f23e01fb4bcdf3d5138b1c7c21ca3c3e032b9 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 13 Feb 2004 14:48:20 +0000 Subject: Move tdbsam versioning/upgrade code into 3.0 (This used to be commit 730c07cac2166812f4a2da5cfba7152d168b2bdd) --- source3/passdb/pdb_tdb.c | 188 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 175 insertions(+), 13 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 554d330ce0..9bfb10c400 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -37,13 +37,15 @@ static int tdbsam_debug_level = DBGC_ALL; #endif -#define PDB_VERSION "20010830" +#define TDBSAM_VERSION 1 /* Most recent TDBSAM version */ +#define TDBSAM_VERSION_STRING "INFO/version" #define PASSDB_FILE_NAME "passdb.tdb" #define USERPREFIX "USER_" #define RIDPREFIX "RID_" +#define tdbsamver_t int32 struct tdbsam_privates { - TDB_CONTEXT *passwd_tdb; + TDB_CONTEXT *passwd_tdb; /* retrive-once info */ const char *tdbsam_location; @@ -55,24 +57,183 @@ struct pwent_list { }; static struct pwent_list *tdbsam_pwent_list; -/***************************************************************************** - Utility functions to open the tdb sam database - ****************************************************************************/ -static TDB_CONTEXT * tdbsam_tdbopen (const char *name, int open_flags) +/** + * Convert old TDBSAM to the latest version. + * @param pdb_tdb A pointer to the opened TDBSAM file which must be converted. + * This file must be opened with read/write access. + * @param from Current version of the TDBSAM file. + * @return True if the conversion has been successful, false otherwise. + **/ + +static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) { - TDB_CONTEXT *tdb; + const char * vstring = TDBSAM_VERSION_STRING; + SAM_ACCOUNT *user = NULL; + const char *prefix = USERPREFIX; + TDB_DATA data, key, old_key; + uint8 *buf = NULL; + BOOL ret; + + if (pdb_tdb == NULL) { + DEBUG(0,("tdbsam_convert: Bad TDB Context pointer.\n")); + return False; + } + + /* handle a Samba upgrade */ + tdb_lock_bystring(pdb_tdb, vstring, 0); + + if (!NT_STATUS_IS_OK(pdb_init_sam(&user))) { + DEBUG(0,("tdbsam_convert: cannot initialized a SAM_ACCOUNT.\n")); + return False; + } + + /* Enumerate all records and convert them */ + key = tdb_firstkey(pdb_tdb); + + while (key.dptr) { + + /* skip all non-USER entries (eg. RIDs) */ + while ((key.dsize != 0) && (strncmp(key.dptr, prefix, strlen (prefix)))) { + old_key = key; + /* increment to next in line */ + key = tdb_nextkey(pdb_tdb, key); + SAFE_FREE(old_key.dptr); + } + + if (key.dptr) { + + /* read from tdbsam */ + data = tdb_fetch(pdb_tdb, key); + if (!data.dptr) { + DEBUG(0,("tdbsam_convert: database entry not found: %s.\n",key.dptr)); + return False; + } + + if (!NT_STATUS_IS_OK(pdb_reset_sam(user))) { + DEBUG(0,("tdbsam_convert: cannot reset SAM_ACCOUNT.\n")); + SAFE_FREE(data.dptr); + return False; + } + + /* unpack the buffer from the former format */ + DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) (version:%d)\n", key.dptr, from)); + switch (from) { + case 0: + ret = init_sam_from_buffer_v0(user, (uint8 *)data.dptr, data.dsize); + break; + case 1: + ret = init_sam_from_buffer_v1(user, (uint8 *)data.dptr, data.dsize); + break; + default: + /* unknown tdbsam version */ + ret = False; + } + if (!ret) { + DEBUG(0,("tdbsam_convert: Bad SAM_ACCOUNT entry returned from TDB (key:%s) (version:%d)\n", key.dptr, from)); + SAFE_FREE(data.dptr); + return False; + } + + /* pack from the buffer into the new format */ + DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", key.dptr, from)); + if ((data.dsize=init_buffer_from_sam (&buf, user, False)) == -1) { + DEBUG(0,("tdbsam_convert: cannot pack the SAM_ACCOUNT into the new format\n")); + SAFE_FREE(data.dptr); + return False; + } + data.dptr = (char *)buf; + + /* Store the buffer inside the TDBSAM */ + if (tdb_store(pdb_tdb, key, data, TDB_MODIFY) != TDB_SUCCESS) { + DEBUG(0,("tdbsam_convert: cannot store the SAM_ACCOUNT (key:%s) in new format\n",key.dptr)); + SAFE_FREE(data.dptr); + return False; + } + + SAFE_FREE(data.dptr); + + /* increment to next in line */ + old_key = key; + key = tdb_nextkey(pdb_tdb, key); + SAFE_FREE(old_key.dptr); + } - if ( !(tdb = tdb_open_log(name, 0, TDB_DEFAULT, open_flags, 0600)) ) { + } + + pdb_free_sam(&user); + + /* upgrade finished */ + tdb_store_int32(pdb_tdb, vstring, TDBSAM_VERSION); + tdb_unlock_bystring(pdb_tdb, vstring); + + return(True); +} + +/** + * Open the TDB passwd database, check version and convert it if needed. + * @param name filename of the tdbsam file. + * @param open_flags file access mode. + * @return a TDB_CONTEXT handle on the tdbsam file. + **/ + +static TDB_CONTEXT * tdbsam_tdbopen (const char *name, int open_flags) +{ + TDB_CONTEXT *pdb_tdb; + tdbsamver_t version; + + /* Try to open tdb passwd */ + if (!(pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, + open_flags, 0600))) { DEBUG(0, ("Unable to open/create TDB passwd\n")); return NULL; } - return tdb; + /* Check the version */ + version = (tdbsamver_t) tdb_fetch_int32(pdb_tdb, + TDBSAM_VERSION_STRING); + if (version == -1) + version = 0; /* Version not found, assume version 0 */ + + /* Compare the version */ + if (version > TDBSAM_VERSION) { + /* Version more recent than the latest known */ + DEBUG(0, ("TDBSAM version unknown: %d\n", version)); + tdb_close(pdb_tdb); + pdb_tdb = NULL; + } + else if (version < TDBSAM_VERSION) { + /* Older version, must be converted */ + DEBUG(1, ("TDBSAM version too old (%d), trying to convert it.\n", version)); + + /* Reopen the pdb file with read-write access if needed */ + if (!(open_flags & O_RDWR)) { + DEBUG(10, ("tdbsam_tdbopen: TDB file opened with read only access, reopen it with read-write access.\n")); + tdb_close(pdb_tdb); + pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, (open_flags & 07777770) | O_RDWR, 0600); + } + + /* Convert */ + if (!tdbsam_convert(pdb_tdb, version)){ + DEBUG(0, ("tdbsam_tdbopen: Error when trying to convert tdbsam: %s\n",name)); + tdb_close(pdb_tdb); + pdb_tdb = NULL; + } else { + DEBUG(1, ("TDBSAM converted successfully.\n")); + } + + /* Reopen the pdb file as it must be */ + if (!(open_flags & O_RDWR)) { + tdb_close(pdb_tdb); + pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, open_flags, 0600); + } + } + + return pdb_tdb; } /***************************************************************************** - Utility functions to open the tdb sam database + Utility functions to close the tdb sam database ****************************************************************************/ static void tdbsam_tdbclose ( struct tdbsam_privates *state ) @@ -233,7 +394,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); return nt_status; } - + /* Data is stored in all lower-case */ fstrcpy(name, sname); strlower_m(name); @@ -316,20 +477,21 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT key.dsize = strlen (keystr) + 1; /* open the accounts TDB */ - if ( !(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY)) ) { + if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY))) { DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); return nt_status; } /* get the record */ data = tdb_fetch (pwd_tdb, key); - if ( !data.dptr ) { + if (!data.dptr) { DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); return nt_status; } + fstrcpy(name, data.dptr); SAFE_FREE(data.dptr); -- cgit From 1c5867502a47371e24519ffeb4165c69cab63482 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 Jul 2004 22:46:51 +0000 Subject: r1388: Adding password history code for ldap backend, based on a patch from "Jianliang Lu" . Multi-string attribute changed to linearised pstring due to ordering issues. A few other changes to fix race conditions. I will add the tdb backend code next. This code compiles but has not yet been tested with password history policy set to greater than zero. Targeted for 3.0.6. Jeremy. (This used to be commit dd54b2a3c45e202e504ad69d170eb798da4e6fc9) --- source3/passdb/pdb_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 9bfb10c400..2cf7c55049 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -746,4 +746,3 @@ NTSTATUS pdb_tdbsam_init(void) { return smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam", pdb_init_tdbsam); } - -- cgit From 10f0c34a2aa1171fe8d769100d6027580dada5ad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Jul 2004 06:39:22 +0000 Subject: r1392: Added password history code to tdbsam backend. Not yet tested (ie. may core dump) but compiles and links correctly. I will run the full set of tests on the ldap sam and the tdb sam for password history tomorrow. Jeremy. (This used to be commit ac846420d0ef2c60d2dc71319b24401c73699249) --- source3/passdb/pdb_tdb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 2cf7c55049..97ef467064 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -37,7 +37,7 @@ static int tdbsam_debug_level = DBGC_ALL; #endif -#define TDBSAM_VERSION 1 /* Most recent TDBSAM version */ +#define TDBSAM_VERSION 2 /* Most recent TDBSAM version */ #define TDBSAM_VERSION_STRING "INFO/version" #define PASSDB_FILE_NAME "passdb.tdb" #define USERPREFIX "USER_" @@ -125,6 +125,9 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) case 1: ret = init_sam_from_buffer_v1(user, (uint8 *)data.dptr, data.dsize); break; + case 2: + ret = init_sam_from_buffer_v2(user, (uint8 *)data.dptr, data.dsize); + break; default: /* unknown tdbsam version */ ret = False; -- cgit From d4ac326d46faab010eeeb24c893ab13bbbf0337e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Jul 2004 21:01:30 +0000 Subject: r1412: Fix password history list in tdbsam. Fix some memory leaks. Add my (C) to a header file that was at least 50% mine :-). Jeremy. (This used to be commit 8ee6060977ec8e65082f3ad09e1e1ccf5b4672ed) --- source3/passdb/pdb_tdb.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 97ef467064..5fb5ce3891 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -138,6 +138,9 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) return False; } + /* We're finished with the old data. */ + SAFE_FREE(data.dptr); + /* pack from the buffer into the new format */ DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", key.dptr, from)); if ((data.dsize=init_buffer_from_sam (&buf, user, False)) == -1) { -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 5fb5ce3891..c792d229b9 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -267,7 +267,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, struct pwent_list *ptr; if ( strncmp(key.dptr, prefix, prefixlen) == 0 ) { - if ( !(ptr=(struct pwent_list*)malloc(sizeof(struct pwent_list))) ) { + if ( !(ptr=SMB_MALLOC_P(struct pwent_list)) ) { DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n")); /* just return 0 and let the traversal continue */ @@ -724,7 +724,7 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; - tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); + tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates); if (!tdb_state) { DEBUG(0, ("talloc() failed for tdbsam private_data!\n")); -- cgit From d94d87472ca2f3875caa146424caa178ce20274f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 13 Jan 2005 18:20:37 +0000 Subject: r4724: Add support for Windows privileges in Samba 3.0 (based on Simo's code in trunk). Rewritten with the following changes: * privilege set is based on a 32-bit mask instead of strings (plans are to extend this to a 64 or 128-bit mask before the next 3.0.11preX release). * Remove the privilege code from the passdb API (replication to come later) * Only support the minimum amount of privileges that make sense. * Rewrite the domain join checks to use the SeMachineAccountPrivilege instead of the 'is a member of "Domain Admins"?' check that started all this. Still todo: * Utilize the SePrintOperatorPrivilege in addition to the 'printer admin' parameter * Utilize the SeAddUserPrivilege for adding users and groups * Fix some of the hard coded _lsa_*() calls * Start work on enough of SAM replication to get privileges from one Samba DC to another. * Come up with some management tool for manipultaing privileges instead of user manager since it is buggy when run on a 2k client (haven't tried xp). Works ok on NT4. (This used to be commit 77c10ff9aa6414a31eece6dfec00793f190a9d6c) --- source3/passdb/pdb_tdb.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index c792d229b9..53baaf580d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -2,7 +2,7 @@ * Unix SMB/CIFS implementation. * SMB parameters and setup * Copyright (C) Andrew Tridgell 1992-1998 - * Copyright (C) Simo Sorce 2000-2002 + * Copyright (C) Simo Sorce 2000-2003 * Copyright (C) Gerald Carter 2000 * Copyright (C) Jeremy Allison 2001 * Copyright (C) Andrew Bartlett 2002 @@ -42,6 +42,7 @@ static int tdbsam_debug_level = DBGC_ALL; #define PASSDB_FILE_NAME "passdb.tdb" #define USERPREFIX "USER_" #define RIDPREFIX "RID_" +#define PRIVPREFIX "PRIV_" #define tdbsamver_t int32 struct tdbsam_privates { @@ -704,6 +705,18 @@ static void free_private_data(void **vp) } + + +/** + * Init tdbsam backend + * + * @param pdb_context initialised passdb context + * @param pdb_method backend methods structure to be filled with function pointers + * @param location the backend tdb file location + * + * @return nt_status code + **/ + static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) { NTSTATUS nt_status; -- cgit From 1ed62fde09f382342a396a047975fdeeea7113bb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Jan 2005 16:13:26 +0000 Subject: r4847: Hand over a acb_mask to pdb_setsampwent in load_sampwd_entries(). This allows the ldap-backend to search much more effeciently. Machines will be searched in the ldap_machine_suffix and users in the ldap_users_suffix. (Note that we already use the ldap_group_suffix in ldapsam_setsamgrent for quite some time). Using the specific ldap-bases becomes notably important in large domains: On my testmachine "net rpc trustdom list" has to search through 40k accounts just to list 3 interdomain-trust-accounts, similiar effects show up the non-user query_dispinfo-calls, etc. Also renamed all_machines to only_machines in load_sampwd_entries() since that reflects better what is really meant. Guenther (This used to be commit 6394257cc721ca739bda0e320375f04506913533) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 53baaf580d..755e33940b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -294,7 +294,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, Save a list of user keys for iteration. ****************************************************************/ -static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update) +static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, uint16 acb_mask) { uint32 flags = update ? (O_RDWR|O_CREAT) : O_RDONLY; -- cgit From 254938c636b6062630d54a598b2975d7a984f70d Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 11 Oct 2005 20:14:04 +0000 Subject: r10911: part of #2861: add rename support for usrmgr.exe when using tdbsam This gets it working before replacing tdb with the samba4 version. (This used to be commit 8210b0503a050e12ee1b4335fa6e50d10ad06577) --- source3/passdb/pdb_tdb.c | 248 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 208 insertions(+), 40 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 755e33940b..f04c82a5b1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -6,6 +6,7 @@ * Copyright (C) Gerald Carter 2000 * Copyright (C) Jeremy Allison 2001 * Copyright (C) Andrew Bartlett 2002 + * Copyright (C) Jim McDonough 2005 * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -515,6 +516,32 @@ static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * return tdbsam_getsampwrid(my_methods, user, rid); } +static BOOL tdb_delete_samacct_only(TDB_CONTEXT *pwd_tdb, + struct pdb_methods *my_methods, + SAM_ACCOUNT *sam_pass) +{ + TDB_DATA key; + fstring keystr; + fstring name; + + fstrcpy(name, pdb_get_username(sam_pass)); + strlower_m(name); + + /* set the search key */ + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); + key.dptr = keystr; + key.dsize = strlen (keystr) + 1; + + /* it's outaa here! 8^) */ + if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { + DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + tdb_close(pwd_tdb); + return False; + } + return True; +} + /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ @@ -573,50 +600,19 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_AC return NT_STATUS_OK; } + /*************************************************************************** - Update the TDB SAM + Update the TDB SAM account record only ****************************************************************************/ - -static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, int flag) +static BOOL tdb_update_samacct_only(TDB_CONTEXT *pwd_tdb, + struct pdb_methods *my_methods, + SAM_ACCOUNT* newpwd, int flag) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_CONTEXT *pwd_tdb = NULL; TDB_DATA key, data; uint8 *buf = NULL; fstring keystr; fstring name; BOOL ret = True; - uint32 user_rid; - - /* invalidate the existing TDB iterator if it is open */ - - if (tdb_state->passwd_tdb) { - tdb_close(tdb_state->passwd_tdb); - tdb_state->passwd_tdb = NULL; - } - - /* open the account TDB passwd*/ - - pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR | O_CREAT); - - if (!pwd_tdb) { - DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", - tdb_state->tdbsam_location)); - return False; - } - - if (!pdb_get_group_rid(newpwd)) { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n", - pdb_get_username(newpwd))); - ret = False; - goto done; - } - - if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { - DEBUG(0,("tdb_update_sam: SAM_ACCOUNT (%s) with no RID!\n", pdb_get_username(newpwd))); - ret = False; - goto done; - } /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ if ((data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1) { @@ -629,7 +625,9 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, fstrcpy(name, pdb_get_username(newpwd)); strlower_m(name); - DEBUG(5, ("Storing %saccount %s with RID %d\n", flag == TDB_INSERT ? "(new) " : "", name, user_rid)); + DEBUG(5, ("Storing %saccount %s with RID %d\n", + flag == TDB_INSERT ? "(new) " : "", name, + pdb_get_user_rid(newpwd))); /* setup the USER index key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); @@ -640,17 +638,40 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify passwd TDB!")); DEBUGADD(0, (" Error: %s", tdb_errorstr(pwd_tdb))); - DEBUGADD(0, (" occured while storing the main record (%s)\n", keystr)); + DEBUGADD(0, (" occured while storing the main record (%s)\n", + keystr)); ret = False; goto done; } + +done: + /* cleanup */ + SAFE_FREE(buf); + return (ret); +} + +/*************************************************************************** + Update the TDB SAM RID record only +****************************************************************************/ +static BOOL tdb_update_ridrec_only(TDB_CONTEXT *pwd_tdb, + struct pdb_methods *my_methods, + SAM_ACCOUNT* newpwd, int flag) +{ + TDB_DATA key, data; + fstring keystr; + fstring name; + + fstrcpy(name, pdb_get_username(newpwd)); + strlower_m(name); + /* setup RID data */ data.dsize = strlen(name) + 1; data.dptr = name; /* setup the RID index key */ - slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, user_rid); + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, + pdb_get_user_rid(newpwd)); key.dptr = keystr; key.dsize = strlen (keystr) + 1; @@ -659,6 +680,56 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, DEBUG(0, ("Unable to modify TDB passwd !")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr)); + return False; + } + + return True; + +} + +/*************************************************************************** + Update the TDB SAM +****************************************************************************/ + +static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, int flag) +{ + struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; + TDB_CONTEXT *pwd_tdb = NULL; + BOOL ret = True; + uint32 user_rid; + + /* invalidate the existing TDB iterator if it is open */ + + if (tdb_state->passwd_tdb) { + tdb_close(tdb_state->passwd_tdb); + tdb_state->passwd_tdb = NULL; + } + + /* open the account TDB passwd*/ + + pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR | O_CREAT); + + if (!pwd_tdb) { + DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", + tdb_state->tdbsam_location)); + return False; + } + + if (!pdb_get_group_rid(newpwd)) { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n", + pdb_get_username(newpwd))); + ret = False; + goto done; + } + + if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { + DEBUG(0,("tdb_update_sam: SAM_ACCOUNT (%s) with no RID!\n", pdb_get_username(newpwd))); + ret = False; + goto done; + } + + if (!tdb_update_samacct_only(pwd_tdb, my_methods, newpwd, flag) || + !tdb_update_ridrec_only(pwd_tdb, my_methods, newpwd, flag)) { ret = False; goto done; } @@ -666,7 +737,6 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, done: /* cleanup */ tdb_close (pwd_tdb); - SAFE_FREE(buf); return (ret); } @@ -695,6 +765,103 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO return NT_STATUS_UNSUCCESSFUL; } +/*************************************************************************** + Renames a SAM_ACCOUNT + - check for the posix user/rename user script + - Add and lock the new user record + - rename the posix user + - rewrite the rid->username record + - delete the old user + - unlock the new user record +***************************************************************************/ +static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, + SAM_ACCOUNT *oldname, const char *newname) +{ + struct tdbsam_privates *tdb_state = + (struct tdbsam_privates *)my_methods->private_data; + SAM_ACCOUNT *new_acct = NULL; + pstring rename_script; + TDB_CONTEXT *pwd_tdb = NULL; + NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; + BOOL interim_account = False; + + if (!*(lp_renameuser_script())) + goto done; + + if (!pdb_copy_sam_account(oldname, &new_acct) || + !pdb_set_username(new_acct, newname, PDB_CHANGED)) + goto done; + + /* invalidate the existing TDB iterator if it is open */ + + if (tdb_state->passwd_tdb) { + tdb_close(tdb_state->passwd_tdb); + tdb_state->passwd_tdb = NULL; + } + + /* open the account TDB passwd */ + + pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR | O_CREAT); + + if (!pwd_tdb) { + DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", + tdb_state->tdbsam_location)); + goto done; + } + + /* add the new account and lock it */ + if (!tdb_update_samacct_only(pwd_tdb, my_methods, new_acct, + TDB_INSERT)) + goto done; + interim_account = True; + + if (tdb_lock_bystring(pwd_tdb, newname, 30) == -1) { + goto done; + } + + /* rename the posix user */ + pstrcpy(rename_script, lp_renameuser_script()); + + if (*rename_script) { + int rename_ret; + + pstring_sub(rename_script, "%unew", newname); + pstring_sub(rename_script, "%uold", pdb_get_username(oldname)); + rename_ret = smbrun(rename_script, NULL); + + DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); + + if (rename_ret) + goto done; + } else { + goto done; + } + + /* rewrite the rid->username record */ + if (!tdb_update_ridrec_only(pwd_tdb, my_methods, new_acct, TDB_MODIFY)) + goto done; + interim_account = False; + tdb_unlock_bystring(pwd_tdb, newname); + + tdb_delete_samacct_only(pwd_tdb, my_methods, oldname); + + ret = NT_STATUS_OK; + + +done: + /* cleanup */ + if (interim_account) { + tdb_unlock_bystring(pwd_tdb, newname); + tdb_delete_samacct_only(pwd_tdb, my_methods, new_acct); + } + if (pwd_tdb) + tdb_close (pwd_tdb); + if (new_acct) + pdb_free_sam(&new_acct); + + return (ret); +} + static void free_private_data(void **vp) { struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; @@ -736,6 +903,7 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; + (*pdb_method)->rename_sam_account = tdbsam_rename_sam_account; tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates); -- cgit From 1113cad9c0c81e9ecec3a0f4317c950943cfc62a Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 20 Oct 2005 20:40:47 +0000 Subject: r11236: Implement user rename for smbpasswd and ldap backends. Some cleanup on tdb as well to make naming consistent. (This used to be commit ee91eb9a39cc5e3edd9e97eb040e7557930e4e62) --- source3/passdb/pdb_tdb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index f04c82a5b1..8bf9b1b282 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -775,7 +775,8 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO - unlock the new user record ***************************************************************************/ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, - SAM_ACCOUNT *oldname, const char *newname) + SAM_ACCOUNT *old_acct, + const char *newname) { struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; @@ -788,7 +789,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, if (!*(lp_renameuser_script())) goto done; - if (!pdb_copy_sam_account(oldname, &new_acct) || + if (!pdb_copy_sam_account(old_acct, &new_acct) || !pdb_set_username(new_acct, newname, PDB_CHANGED)) goto done; @@ -826,7 +827,8 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, int rename_ret; pstring_sub(rename_script, "%unew", newname); - pstring_sub(rename_script, "%uold", pdb_get_username(oldname)); + pstring_sub(rename_script, "%uold", + pdb_get_username(old_acct)); rename_ret = smbrun(rename_script, NULL); DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); @@ -843,7 +845,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, interim_account = False; tdb_unlock_bystring(pwd_tdb, newname); - tdb_delete_samacct_only(pwd_tdb, my_methods, oldname); + tdb_delete_samacct_only(pwd_tdb, my_methods, old_acct); ret = NT_STATUS_OK; -- cgit From 3ea781f62a93a251891a0e57babe36118e92ddea Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Jan 2006 23:55:26 +0000 Subject: r13172: Fix incorrect error message when new tdb not created correctly. Jeremy. (This used to be commit e5f19ad5ac1b728de4ca5a6c37c0d79b0752f536) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 8bf9b1b282..d58187ffe5 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -420,7 +420,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT * TDB file doesn't exist, so try to create new one. This is useful to avoid * confusing error msg when adding user account first time */ - if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT ))) { + if ((pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT )) != NULL) { DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n", tdb_state->tdbsam_location)); } else { -- cgit From 114a24c19bfcdfdfd15df191d43c9cb36b705491 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Jan 2006 00:09:03 +0000 Subject: r13175: Actually make adding a new user into an empty pdbtdb file create the file. Jeremy. (This used to be commit 31b3201f537220ec82d6fecbb4c457bfe3dbb9c9) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index d58187ffe5..164ec72299 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -420,7 +420,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT * TDB file doesn't exist, so try to create new one. This is useful to avoid * confusing error msg when adding user account first time */ - if ((pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT )) != NULL) { + if ((pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT|O_RDWR )) != NULL) { DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n", tdb_state->tdbsam_location)); } else { -- cgit From b2e8358b3d76d88d5dc090095a4e62647c823aa5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 28 Jan 2006 17:08:24 +0000 Subject: r13209: Make smbpasswd -a work again if passdb did not exist. Volker (This used to be commit e747ea7250b3ff19aee49072a2cf95840ff50b85) --- source3/passdb/pdb_tdb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 164ec72299..370c8adc7d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -423,6 +423,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT if ((pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT|O_RDWR )) != NULL) { DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n", tdb_state->tdbsam_location)); + tdb_close(pwd_tdb); } else { DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) does not exist. Couldn't create new one. Error was: %s\n", tdb_state->tdbsam_location, strerror(errno))); -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/passdb/pdb_tdb.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 370c8adc7d..74f47e70dc 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -864,7 +864,98 @@ done: return (ret); } - + +static BOOL tdbsam_rid_algorithm(struct pdb_methods *methods) +{ + return False; +} + +/* + * Historically, winbind was responsible for allocating RIDs, so the next RID + * value was stored in winbindd_idmap.tdb. It has been moved to passdb now, + * but for compatibility reasons we still keep the the next RID counter in + * winbindd_idmap.tdb. + */ + +/***************************************************************************** + Initialise idmap database. For now (Dec 2005) this is a copy of the code in + sam/idmap_tdb.c. Maybe at a later stage we can remove that capability from + winbind completely and store the RID counter in passdb.tdb. + + Dont' fully initialize with the HWM values, if it's new, we're only + interested in the RID counter. +*****************************************************************************/ + +static BOOL init_idmap_tdb(TDB_CONTEXT *tdb) +{ + int32 version; + + if (tdb_lock_bystring(tdb, "IDMAP_VERSION", 0) != 0) { + DEBUG(0, ("Could not lock IDMAP_VERSION\n")); + return False; + } + + version = tdb_fetch_int32(tdb, "IDMAP_VERSION"); + + if (version == -1) { + /* No key found, must be a new db */ + if (tdb_store_int32(tdb, "IDMAP_VERSION", + IDMAP_VERSION) != 0) { + DEBUG(0, ("Could not store IDMAP_VERSION\n")); + tdb_unlock_bystring(tdb, "IDMAP_VERSION"); + return False; + } + version = IDMAP_VERSION; + } + + if (version != IDMAP_VERSION) { + DEBUG(0, ("Expected IDMAP_VERSION=%d, found %d. Please " + "start winbind once\n", IDMAP_VERSION, version)); + tdb_unlock_bystring(tdb, "IDMAP_VERSION"); + return False; + } + + tdb_unlock_bystring(tdb, "IDMAP_VERSION"); + return True; +} + +static BOOL tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) +{ + TDB_CONTEXT *tdb; + uint32 rid; + BOOL ret = False; + + tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, + TDB_DEFAULT, O_RDWR | O_CREAT, 0644); + + if (tdb == NULL) { + DEBUG(1, ("Could not open idmap: %s\n", strerror(errno))); + goto done; + } + + if (!init_idmap_tdb(tdb)) { + DEBUG(1, ("Could not init idmap\n")); + goto done; + } + + rid = BASE_RID; /* Default if not set */ + + if (!tdb_change_uint32_atomic(tdb, "RID_COUNTER", &rid, 1)) { + DEBUG(3, ("tdbsam_new_rid: Failed to increase RID_COUNTER\n")); + goto done; + } + + *prid = rid; + ret = True; + + done: + if ((tdb != NULL) && (tdb_close(tdb) != 0)) { + smb_panic("tdb_close(idmap_tdb) failed\n"); + } + + return ret; +} + static void free_private_data(void **vp) { struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; @@ -908,6 +999,9 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; (*pdb_method)->rename_sam_account = tdbsam_rename_sam_account; + (*pdb_method)->rid_algorithm = tdbsam_rid_algorithm; + (*pdb_method)->new_rid = tdbsam_new_rid; + tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates); if (!tdb_state) { -- cgit From 75ef18fa7510d894ccc4540d82616110c3166db3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 11 Feb 2006 21:27:08 +0000 Subject: r13460: by popular demand.... * remove pdb_context data structure * set default group for DOMAIN_RID_GUEST user as RID 513 (just like Windows) * Allow RID 513 to resolve to always resolve to a name * Remove auto mapping of guest account primary group given the previous 2 changes (This used to be commit 7a2da5f0cc05c1920c664c9a690a23bdf854e285) --- source3/passdb/pdb_tdb.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 74f47e70dc..d77f2b3377 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -965,25 +965,21 @@ static void free_private_data(void **vp) /* No need to free any further, as it is talloc()ed */ } - - - /** * Init tdbsam backend * - * @param pdb_context initialised passdb context * @param pdb_method backend methods structure to be filled with function pointers * @param location the backend tdb file location * * @return nt_status code **/ -static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *location) { NTSTATUS nt_status; struct tdbsam_privates *tdb_state; - if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + if (!NT_STATUS_IS_OK(nt_status = make_pdb_method( pdb_method ))) { return nt_status; } @@ -1002,21 +998,19 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth (*pdb_method)->rid_algorithm = tdbsam_rid_algorithm; (*pdb_method)->new_rid = tdbsam_new_rid; - tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates); - - if (!tdb_state) { + if ( !(tdb_state = TALLOC_ZERO_P( *pdb_method, struct tdbsam_privates)) ) { DEBUG(0, ("talloc() failed for tdbsam private_data!\n")); return NT_STATUS_NO_MEMORY; } if (location) { - tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, location); + tdb_state->tdbsam_location = talloc_strdup(*pdb_method, location); } else { pstring tdbfile; get_private_directory(tdbfile); pstrcat(tdbfile, "/"); pstrcat(tdbfile, PASSDB_FILE_NAME); - tdb_state->tdbsam_location = talloc_strdup(pdb_context->mem_ctx, tdbfile); + tdb_state->tdbsam_location = talloc_strdup(*pdb_method, tdbfile); } (*pdb_method)->private_data = tdb_state; -- cgit From ab4fa1958fe17f4105bb20f8acd84241fdb65581 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Feb 2006 18:26:06 +0000 Subject: r13512: Rewrite tdbsam code to use a reference count based open/close on the tdb file. This allow recusive calls to succeed without complaining about failed opens since a tdb can only be opened once per process. We probably still need to backport the transaction support from Samba 4 here though. (This used to be commit 94c37e06522bfc1753cc8f3c6c7bd4329587007e) --- source3/passdb/pdb_tdb.c | 607 ++++++++++++++++++++++------------------------- 1 file changed, 281 insertions(+), 326 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index d77f2b3377..e7f5e0cac9 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -3,7 +3,7 @@ * SMB parameters and setup * Copyright (C) Andrew Tridgell 1992-1998 * Copyright (C) Simo Sorce 2000-2003 - * Copyright (C) Gerald Carter 2000 + * Copyright (C) Gerald Carter 2000-2006 * Copyright (C) Jeremy Allison 2001 * Copyright (C) Andrew Bartlett 2002 * Copyright (C) Jim McDonough 2005 @@ -44,14 +44,6 @@ static int tdbsam_debug_level = DBGC_ALL; #define USERPREFIX "USER_" #define RIDPREFIX "RID_" #define PRIVPREFIX "PRIV_" -#define tdbsamver_t int32 - -struct tdbsam_privates { - TDB_CONTEXT *passwd_tdb; - - /* retrive-once info */ - const char *tdbsam_location; -}; struct pwent_list { struct pwent_list *prev, *next; @@ -59,6 +51,11 @@ struct pwent_list { }; static struct pwent_list *tdbsam_pwent_list; +/* GLOBAL TDB SAM CONTEXT */ + +static TDB_CONTEXT *tdbsam; +static int ref_count = 0; +static pstring tdbsam_filename; /** * Convert old TDBSAM to the latest version. @@ -68,30 +65,25 @@ static struct pwent_list *tdbsam_pwent_list; * @return True if the conversion has been successful, false otherwise. **/ -static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) +static BOOL tdbsam_convert(int32 from) { - const char * vstring = TDBSAM_VERSION_STRING; - SAM_ACCOUNT *user = NULL; - const char *prefix = USERPREFIX; + const char *vstring = TDBSAM_VERSION_STRING; + SAM_ACCOUNT *user = NULL; + const char *prefix = USERPREFIX; TDB_DATA data, key, old_key; uint8 *buf = NULL; BOOL ret; - if (pdb_tdb == NULL) { - DEBUG(0,("tdbsam_convert: Bad TDB Context pointer.\n")); - return False; - } - /* handle a Samba upgrade */ - tdb_lock_bystring(pdb_tdb, vstring, 0); + tdb_lock_bystring(tdbsam, vstring, 0); - if (!NT_STATUS_IS_OK(pdb_init_sam(&user))) { + if ( !NT_STATUS_IS_OK(pdb_init_sam(&user)) ) { DEBUG(0,("tdbsam_convert: cannot initialized a SAM_ACCOUNT.\n")); return False; } /* Enumerate all records and convert them */ - key = tdb_firstkey(pdb_tdb); + key = tdb_firstkey(tdbsam); while (key.dptr) { @@ -99,14 +91,14 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) while ((key.dsize != 0) && (strncmp(key.dptr, prefix, strlen (prefix)))) { old_key = key; /* increment to next in line */ - key = tdb_nextkey(pdb_tdb, key); + key = tdb_nextkey(tdbsam, key); SAFE_FREE(old_key.dptr); } if (key.dptr) { /* read from tdbsam */ - data = tdb_fetch(pdb_tdb, key); + data = tdb_fetch(tdbsam, key); if (!data.dptr) { DEBUG(0,("tdbsam_convert: database entry not found: %s.\n",key.dptr)); return False; @@ -153,7 +145,7 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) data.dptr = (char *)buf; /* Store the buffer inside the TDBSAM */ - if (tdb_store(pdb_tdb, key, data, TDB_MODIFY) != TDB_SUCCESS) { + if (tdb_store(tdbsam, key, data, TDB_MODIFY) != TDB_SUCCESS) { DEBUG(0,("tdbsam_convert: cannot store the SAM_ACCOUNT (key:%s) in new format\n",key.dptr)); SAFE_FREE(data.dptr); return False; @@ -163,7 +155,7 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) /* increment to next in line */ old_key = key; - key = tdb_nextkey(pdb_tdb, key); + key = tdb_nextkey(tdbsam, key); SAFE_FREE(old_key.dptr); } @@ -172,90 +164,94 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from) pdb_free_sam(&user); /* upgrade finished */ - tdb_store_int32(pdb_tdb, vstring, TDBSAM_VERSION); - tdb_unlock_bystring(pdb_tdb, vstring); + tdb_store_int32(tdbsam, vstring, TDBSAM_VERSION); + tdb_unlock_bystring(tdbsam, vstring); return(True); } -/** - * Open the TDB passwd database, check version and convert it if needed. - * @param name filename of the tdbsam file. - * @param open_flags file access mode. - * @return a TDB_CONTEXT handle on the tdbsam file. - **/ +/********************************************************************* + Open the tdbsam file based on the absolute path specified. + Uses a reference count to allow multiple open calls. +*********************************************************************/ -static TDB_CONTEXT * tdbsam_tdbopen (const char *name, int open_flags) +static BOOL tdbsam_open( const char *name ) { - TDB_CONTEXT *pdb_tdb; - tdbsamver_t version; - - /* Try to open tdb passwd */ - if (!(pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, - open_flags, 0600))) { - DEBUG(0, ("Unable to open/create TDB passwd\n")); - return NULL; + int32 version; + + /* check if we are already open */ + + if ( tdbsam ) { + ref_count++; + DEBUG(8,("tdbsam_open: Incrementing open reference count. Ref count is now %d\n", + ref_count)); + return True; + } + + SMB_ASSERT( ref_count == 0 ); + + /* Try to open tdb passwd. Create a new one if necessary */ + + if (!(tdbsam = tdb_open_log(name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600))) { + DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd [%s]\n", name)); + return False; } /* Check the version */ - version = (tdbsamver_t) tdb_fetch_int32(pdb_tdb, - TDBSAM_VERSION_STRING); + version = tdb_fetch_int32( tdbsam, TDBSAM_VERSION_STRING ); + if (version == -1) version = 0; /* Version not found, assume version 0 */ /* Compare the version */ if (version > TDBSAM_VERSION) { /* Version more recent than the latest known */ - DEBUG(0, ("TDBSAM version unknown: %d\n", version)); - tdb_close(pdb_tdb); - pdb_tdb = NULL; + DEBUG(0, ("tdbsam_open: unknown version => %d\n", version)); + tdb_close( tdbsam ); + return False; } - else if (version < TDBSAM_VERSION) { - /* Older version, must be converted */ - DEBUG(1, ("TDBSAM version too old (%d), trying to convert it.\n", version)); - - /* Reopen the pdb file with read-write access if needed */ - if (!(open_flags & O_RDWR)) { - DEBUG(10, ("tdbsam_tdbopen: TDB file opened with read only access, reopen it with read-write access.\n")); - tdb_close(pdb_tdb); - pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, (open_flags & 07777770) | O_RDWR, 0600); - } + + + if ( version < TDBSAM_VERSION ) { + DEBUG(1, ("tdbsam_open: Converting version %d database to version %d.\n", + version, TDBSAM_VERSION)); - /* Convert */ - if (!tdbsam_convert(pdb_tdb, version)){ - DEBUG(0, ("tdbsam_tdbopen: Error when trying to convert tdbsam: %s\n",name)); - tdb_close(pdb_tdb); - pdb_tdb = NULL; - } else { - DEBUG(1, ("TDBSAM converted successfully.\n")); - } - - /* Reopen the pdb file as it must be */ - if (!(open_flags & O_RDWR)) { - tdb_close(pdb_tdb); - pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, open_flags, 0600); + if ( !tdbsam_convert(version) ) { + DEBUG(0, ("tdbsam_open: Error when trying to convert tdbsam [%s]\n",name)); + tdb_close(tdbsam); + return False; } + + DEBUG(3, ("TDBSAM converted successfully.\n")); } - return pdb_tdb; + /* set the initial reference count */ + + ref_count = 1; + + DEBUG(4,("tdbsam_open: successfully opened %s\n", name )); + + return True; } -/***************************************************************************** - Utility functions to close the tdb sam database - ****************************************************************************/ +/**************************************************************************** + wrapper atound tdb_close() to handle the reference count +****************************************************************************/ -static void tdbsam_tdbclose ( struct tdbsam_privates *state ) +void tdbsam_close( void ) { - if ( !state ) - return; - - if ( state->passwd_tdb ) { - tdb_close( state->passwd_tdb ); - state->passwd_tdb = NULL; + ref_count--; + + DEBUG(8,("tdbsam_close: Reference count is now %d.\n", ref_count)); + + SMB_ASSERT(ref_count >= 0 ); + + if ( ref_count == 0 ) { + tdb_close( tdbsam ); + tdbsam = NULL; } return; - } /**************************************************************************** @@ -297,14 +293,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, uint16 acb_mask) { - uint32 flags = update ? (O_RDWR|O_CREAT) : O_RDONLY; - - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - - if ( !(tdb_state->passwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, flags )) ) - return NT_STATUS_UNSUCCESSFUL; - - tdb_traverse( tdb_state->passwd_tdb, tdbsam_traverse_setpwent, NULL ); + tdb_traverse( tdbsam, tdbsam_traverse_setpwent, NULL ); return NT_STATUS_OK; } @@ -316,11 +305,8 @@ static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, static void tdbsam_endsampwent(struct pdb_methods *my_methods) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; struct pwent_list *ptr, *ptr_next; - tdbsam_tdbclose( tdb_state ); - /* clear out any remaining entries in the list */ for ( ptr=tdbsam_pwent_list; ptr; ptr = ptr_next ) { @@ -340,7 +326,6 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; TDB_DATA data; struct pwent_list *pkey; @@ -351,36 +336,29 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * if ( !tdbsam_pwent_list ) { DEBUG(4,("tdbsam_getsampwent: end of list\n")); - tdbsam_tdbclose( tdb_state ); return nt_status; } - if ( !tdb_state->passwd_tdb ) { - if ( !(tdb_state->passwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY)) ) - return nt_status; - } - /* pull the next entry */ pkey = tdbsam_pwent_list; DLIST_REMOVE( tdbsam_pwent_list, pkey ); - data = tdb_fetch(tdb_state->passwd_tdb, pkey->key); + data = tdb_fetch(tdbsam, pkey->key); SAFE_FREE( pkey->key.dptr); SAFE_FREE( pkey); - if (!data.dptr) { + if ( !data.dptr ) { DEBUG(5,("pdb_getsampwent: database entry not found. Was the user deleted?\n")); return nt_status; } - if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { + if ( !init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize) ) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); } SAFE_FREE( data.dptr ); - return NT_STATUS_OK; } @@ -391,16 +369,14 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *user, const char *sname) { - NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_CONTEXT *pwd_tdb; + NTSTATUS result; TDB_DATA data, key; fstring keystr; fstring name; if ( !user ) { DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); - return nt_status; + return NT_STATUS_NO_MEMORY; } /* Data is stored in all lower-case */ @@ -412,54 +388,40 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT key.dptr = keystr; key.dsize = strlen(keystr) + 1; - /* open the accounts TDB */ - if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY))) { - - if (errno == ENOENT) { - /* - * TDB file doesn't exist, so try to create new one. This is useful to avoid - * confusing error msg when adding user account first time - */ - if ((pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_CREAT|O_RDWR )) != NULL) { - DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n", - tdb_state->tdbsam_location)); - tdb_close(pwd_tdb); - } else { - DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) does not exist. Couldn't create new one. Error was: %s\n", - tdb_state->tdbsam_location, strerror(errno))); - } - - /* requested user isn't there anyway */ - nt_status = NT_STATUS_NO_SUCH_USER; - return nt_status; - } - DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location)); - return nt_status; + /* open the database */ + + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + return NT_STATUS_ACCESS_DENIED; } - + /* get the record */ - data = tdb_fetch(pwd_tdb, key); + + data = tdb_fetch(tdbsam, key); if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); DEBUGADD(5, (" Key: %s\n", keystr)); - tdb_close(pwd_tdb); - return nt_status; + result = NT_STATUS_NO_SUCH_USER; + goto done; } /* unpack the buffer */ + if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); SAFE_FREE(data.dptr); - tdb_close(pwd_tdb); - return nt_status; + result = NT_STATUS_NO_MEMORY; + goto done; } + + result = NT_STATUS_OK; + + done: SAFE_FREE(data.dptr); - - /* no further use for database, close it now */ - tdb_close(pwd_tdb); + tdbsam_close(); - return NT_STATUS_OK; + return result; } /*************************************************************************** @@ -468,58 +430,63 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *user, uint32 rid) { - NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_CONTEXT *pwd_tdb; + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; TDB_DATA data, key; fstring keystr; fstring name; - - if (user==NULL) { + + if ( !user ) { DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n")); return nt_status; } - + /* set search key */ + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; - /* open the accounts TDB */ - if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY))) { - DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n")); - return nt_status; + /* open the database */ + + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + return NT_STATUS_ACCESS_DENIED; } /* get the record */ - data = tdb_fetch (pwd_tdb, key); + + data = tdb_fetch (tdbsam, key); if (!data.dptr) { DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close (pwd_tdb); - return nt_status; + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; } - fstrcpy(name, data.dptr); SAFE_FREE(data.dptr); - tdb_close (pwd_tdb); + nt_status = tdbsam_getsampwnam (my_methods, user, name); + + done: + /* cleanup */ - return tdbsam_getsampwnam (my_methods, user, name); + tdbsam_close(); + + return nt_status; } static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) { uint32 rid; - if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) + + if ( !sid_peek_check_rid(get_global_sam_sid(), sid, &rid) ) return NT_STATUS_UNSUCCESSFUL; + return tdbsam_getsampwrid(my_methods, user, rid); } -static BOOL tdb_delete_samacct_only(TDB_CONTEXT *pwd_tdb, - struct pdb_methods *my_methods, - SAM_ACCOUNT *sam_pass) +static BOOL tdb_delete_samacct_only( SAM_ACCOUNT *sam_pass ) { TDB_DATA key; fstring keystr; @@ -529,85 +496,98 @@ static BOOL tdb_delete_samacct_only(TDB_CONTEXT *pwd_tdb, strlower_m(name); /* set the search key */ + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; /* it's outaa here! 8^) */ - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { + + if (tdb_delete(tdbsam, key) != TDB_SUCCESS) { DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close(pwd_tdb); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); return False; } + return True; } /*************************************************************************** - Delete a SAM_ACCOUNT + Delete a SAM_ACCOUNT records for the username and RID key ****************************************************************************/ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass) { - NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_CONTEXT *pwd_tdb; + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; TDB_DATA key; fstring keystr; uint32 rid; fstring name; + /* make sure we have an open handle to the tdb. Should have happened + at module initialization time */ + + if ( !tdbsam ) { + DEBUG(0,("tdbsam_getsampwrid: tdbsam not open!\n")); + return NT_STATUS_NO_SUCH_USER; + } + fstrcpy(name, pdb_get_username(sam_pass)); strlower_m(name); - /* open the TDB */ - if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR))) { - DEBUG(0, ("Unable to open TDB passwd!")); - return nt_status; - } - /* set the search key */ + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); key.dptr = keystr; key.dsize = strlen (keystr) + 1; rid = pdb_get_user_rid(sam_pass); + /* open the database */ + + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + return NT_STATUS_ACCESS_DENIED; + } + /* it's outaa here! 8^) */ - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { - DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close(pwd_tdb); - return nt_status; - } - /* delete also the RID key */ + if ( tdb_delete(tdbsam, key) != TDB_SUCCESS ) { + DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } /* set the search key */ + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); key.dptr = keystr; key.dsize = strlen (keystr) + 1; /* it's outaa here! 8^) */ - if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) { + + if ( tdb_delete(tdbsam, key) != TDB_SUCCESS ) { DEBUG(5, ("Error deleting entry from tdb rid database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); - tdb_close(pwd_tdb); - return nt_status; + DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; } + + nt_status = NT_STATUS_OK; - tdb_close(pwd_tdb); + done: + tdbsam_close(); - return NT_STATUS_OK; + return nt_status; } /*************************************************************************** Update the TDB SAM account record only + Assumes that the tdbsam is already open ****************************************************************************/ -static BOOL tdb_update_samacct_only(TDB_CONTEXT *pwd_tdb, - struct pdb_methods *my_methods, - SAM_ACCOUNT* newpwd, int flag) +static BOOL tdb_update_samacct_only( SAM_ACCOUNT* newpwd, int flag ) { TDB_DATA key, data; uint8 *buf = NULL; @@ -616,7 +596,8 @@ static BOOL tdb_update_samacct_only(TDB_CONTEXT *pwd_tdb, BOOL ret = True; /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ - if ((data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1) { + + if ( (data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1 ) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); ret = False; goto done; @@ -636,9 +617,10 @@ static BOOL tdb_update_samacct_only(TDB_CONTEXT *pwd_tdb, key.dsize = strlen(keystr) + 1; /* add the account */ - if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { + + if ( tdb_store(tdbsam, key, data, flag) != TDB_SUCCESS ) { DEBUG(0, ("Unable to modify passwd TDB!")); - DEBUGADD(0, (" Error: %s", tdb_errorstr(pwd_tdb))); + DEBUGADD(0, (" Error: %s", tdb_errorstr(tdbsam))); DEBUGADD(0, (" occured while storing the main record (%s)\n", keystr)); ret = False; @@ -649,15 +631,14 @@ done: /* cleanup */ SAFE_FREE(buf); - return (ret); + return ret; } /*************************************************************************** Update the TDB SAM RID record only + Assumes that the tdbsam is already open ****************************************************************************/ -static BOOL tdb_update_ridrec_only(TDB_CONTEXT *pwd_tdb, - struct pdb_methods *my_methods, - SAM_ACCOUNT* newpwd, int flag) +static BOOL tdb_update_ridrec_only( SAM_ACCOUNT* newpwd, int flag ) { TDB_DATA key, data; fstring keystr; @@ -671,15 +652,14 @@ static BOOL tdb_update_ridrec_only(TDB_CONTEXT *pwd_tdb, data.dptr = name; /* setup the RID index key */ - slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, - pdb_get_user_rid(newpwd)); + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); key.dptr = keystr; key.dsize = strlen (keystr) + 1; /* add the reference */ - if (tdb_store(pwd_tdb, key, data, flag) != TDB_SUCCESS) { + if (tdb_store(tdbsam, key, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify TDB passwd !")); - DEBUGADD(0, (" Error: %s\n", tdb_errorstr(pwd_tdb))); + DEBUGADD(0, (" Error: %s\n", tdb_errorstr(tdbsam))); DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr)); return False; } @@ -694,52 +674,40 @@ static BOOL tdb_update_ridrec_only(TDB_CONTEXT *pwd_tdb, static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, int flag) { - struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data; - TDB_CONTEXT *pwd_tdb = NULL; - BOOL ret = True; uint32 user_rid; + BOOL result = True; /* invalidate the existing TDB iterator if it is open */ - if (tdb_state->passwd_tdb) { - tdb_close(tdb_state->passwd_tdb); - tdb_state->passwd_tdb = NULL; - } - - /* open the account TDB passwd*/ - - pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR | O_CREAT); + tdbsam_endsampwent( my_methods ); - if (!pwd_tdb) { - DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", - tdb_state->tdbsam_location)); + if ( !pdb_get_group_rid(newpwd) ) { + DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] " + "without a primary group RID\n", pdb_get_username(newpwd))); return False; } - if (!pdb_get_group_rid(newpwd)) { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n", - pdb_get_username(newpwd))); - ret = False; - goto done; - } - if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { DEBUG(0,("tdb_update_sam: SAM_ACCOUNT (%s) with no RID!\n", pdb_get_username(newpwd))); - ret = False; - goto done; + return False; } - if (!tdb_update_samacct_only(pwd_tdb, my_methods, newpwd, flag) || - !tdb_update_ridrec_only(pwd_tdb, my_methods, newpwd, flag)) { - ret = False; - goto done; + /* open the database */ + + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + return False; + } + + if ( !tdb_update_samacct_only(newpwd, flag) || !tdb_update_ridrec_only(newpwd, flag)) { + result = False; } -done: /* cleanup */ - tdb_close (pwd_tdb); + + tdbsam_close(); - return (ret); + return result; } /*************************************************************************** @@ -748,10 +716,10 @@ done: static NTSTATUS tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) { - if (tdb_update_sam(my_methods, newpwd, TDB_MODIFY)) - return NT_STATUS_OK; - else + if ( !tdb_update_sam(my_methods, newpwd, TDB_MODIFY) ) return NT_STATUS_UNSUCCESSFUL; + + return NT_STATUS_OK; } /*************************************************************************** @@ -760,10 +728,10 @@ static NTSTATUS tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_A static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) { - if (tdb_update_sam(my_methods, newpwd, TDB_INSERT)) - return NT_STATUS_OK; - else + if ( !tdb_update_sam(my_methods, newpwd, TDB_INSERT) ) return NT_STATUS_UNSUCCESSFUL; + + return NT_STATUS_OK; } /*************************************************************************** @@ -779,90 +747,95 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *old_acct, const char *newname) { - struct tdbsam_privates *tdb_state = - (struct tdbsam_privates *)my_methods->private_data; - SAM_ACCOUNT *new_acct = NULL; - pstring rename_script; - TDB_CONTEXT *pwd_tdb = NULL; - NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; - BOOL interim_account = False; - - if (!*(lp_renameuser_script())) - goto done; + SAM_ACCOUNT *new_acct = NULL; + pstring rename_script; + BOOL interim_account = False; + int rename_ret; - if (!pdb_copy_sam_account(old_acct, &new_acct) || - !pdb_set_username(new_acct, newname, PDB_CHANGED)) - goto done; + /* make sure we have an open handle to the tdb. Should have happened + at module initialization time */ + + if ( !tdbsam ) { + DEBUG(0,("tdbsam_getsampwrid: tdbsam not open!\n")); + return NT_STATUS_NO_SUCH_USER; + } + + /* can't do anything without an external script */ + + pstrcpy(rename_script, lp_renameuser_script() ); + if ( ! *rename_script ) + return NT_STATUS_ACCESS_DENIED; /* invalidate the existing TDB iterator if it is open */ - if (tdb_state->passwd_tdb) { - tdb_close(tdb_state->passwd_tdb); - tdb_state->passwd_tdb = NULL; + tdbsam_endsampwent( my_methods ); + + if ( !pdb_copy_sam_account(old_acct, &new_acct) + || !pdb_set_username(new_acct, newname, PDB_CHANGED)) + { + pdb_free_sam( &new_acct ); + return NT_STATUS_NO_MEMORY; } - /* open the account TDB passwd */ - - pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDWR | O_CREAT); - - if (!pwd_tdb) { - DEBUG(0, ("tdb_update_sam: Unable to open TDB passwd (%s)!\n", - tdb_state->tdbsam_location)); - goto done; + /* open the database */ + + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + pdb_free_sam( &new_acct ); + return NT_STATUS_ACCESS_DENIED; } /* add the new account and lock it */ - if (!tdb_update_samacct_only(pwd_tdb, my_methods, new_acct, - TDB_INSERT)) + + if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) + { goto done; + } + interim_account = True; - if (tdb_lock_bystring(pwd_tdb, newname, 30) == -1) { + if ( tdb_lock_bystring(tdbsam, newname, 30) == -1 ) { goto done; } /* rename the posix user */ - pstrcpy(rename_script, lp_renameuser_script()); - - if (*rename_script) { - int rename_ret; + + pstring_sub(rename_script, "%unew", newname); + pstring_sub(rename_script, "%uold", pdb_get_username(old_acct)); + rename_ret = smbrun(rename_script, NULL); - pstring_sub(rename_script, "%unew", newname); - pstring_sub(rename_script, "%uold", - pdb_get_username(old_acct)); - rename_ret = smbrun(rename_script, NULL); + DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); - DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); - - if (rename_ret) - goto done; - } else { - goto done; - } + if (rename_ret) + goto done; /* rewrite the rid->username record */ - if (!tdb_update_ridrec_only(pwd_tdb, my_methods, new_acct, TDB_MODIFY)) + + if ( !tdb_update_ridrec_only( new_acct, TDB_MODIFY) ) goto done; interim_account = False; - tdb_unlock_bystring(pwd_tdb, newname); - - tdb_delete_samacct_only(pwd_tdb, my_methods, old_acct); - - ret = NT_STATUS_OK; + tdb_unlock_bystring( tdbsam, newname ); + tdb_delete_samacct_only( old_acct ); + + tdbsam_close(); + + pdb_free_sam( &new_acct ); + return NT_STATUS_OK; done: /* cleanup */ if (interim_account) { - tdb_unlock_bystring(pwd_tdb, newname); - tdb_delete_samacct_only(pwd_tdb, my_methods, new_acct); + tdb_unlock_bystring(tdbsam, newname); + tdb_delete_samacct_only(new_acct); } - if (pwd_tdb) - tdb_close (pwd_tdb); + + tdbsam_close(); + if (new_acct) pdb_free_sam(&new_acct); - return (ret); + return NT_STATUS_ACCESS_DENIED; } static BOOL tdbsam_rid_algorithm(struct pdb_methods *methods) @@ -956,28 +929,16 @@ static BOOL tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) return ret; } -static void free_private_data(void **vp) -{ - struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; - tdbsam_tdbclose(*tdb_state); - *tdb_state = NULL; - - /* No need to free any further, as it is talloc()ed */ -} - -/** - * Init tdbsam backend - * - * @param pdb_method backend methods structure to be filled with function pointers - * @param location the backend tdb file location - * - * @return nt_status code - **/ +/********************************************************************* + Initialize the tdb sam backend. Setup the dispath table of methods, + open the tdb, etc... +*********************************************************************/ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *location) { NTSTATUS nt_status; - struct tdbsam_privates *tdb_state; + pstring tdbfile; + const char *pfile = location; if (!NT_STATUS_IS_OK(nt_status = make_pdb_method( pdb_method ))) { return nt_status; @@ -998,24 +959,18 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc (*pdb_method)->rid_algorithm = tdbsam_rid_algorithm; (*pdb_method)->new_rid = tdbsam_new_rid; - if ( !(tdb_state = TALLOC_ZERO_P( *pdb_method, struct tdbsam_privates)) ) { - DEBUG(0, ("talloc() failed for tdbsam private_data!\n")); - return NT_STATUS_NO_MEMORY; - } - - if (location) { - tdb_state->tdbsam_location = talloc_strdup(*pdb_method, location); - } else { - pstring tdbfile; - get_private_directory(tdbfile); - pstrcat(tdbfile, "/"); - pstrcat(tdbfile, PASSDB_FILE_NAME); - tdb_state->tdbsam_location = talloc_strdup(*pdb_method, tdbfile); + /* save the path for later */ + + if ( !location ) { + pstr_sprintf( tdbfile, "%s/%s", lp_private_dir(), PASSDB_FILE_NAME ); + pfile = tdbfile; } + pstrcpy( tdbsam_filename, pfile ); - (*pdb_method)->private_data = tdb_state; - - (*pdb_method)->free_private_data = free_private_data; + /* no private data */ + + (*pdb_method)->private_data = NULL; + (*pdb_method)->free_private_data = NULL; return NT_STATUS_OK; } -- cgit From 2203bed32c84c63737f402accf73452efb76b483 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 20 Feb 2006 20:09:36 +0000 Subject: r13576: This is the beginnings of moving the SAM_ACCOUNT data structure to make full use of the new talloc() interface. Discussed with Volker and Jeremy. * remove the internal mem_ctx and simply use the talloc() structure as the context. * replace the internal free_fn() with a talloc_destructor() function * remove the unnecessary private nested structure * rename SAM_ACCOUNT to 'struct samu' to indicate the current an upcoming changes. Groups will most likely be replaced with a 'struct samg' in the future. Note that there are now passbd API changes. And for the most part, the wrapper functions remain the same. While this code has been tested on tdb and ldap based Samba PDC's as well as Samba member servers, there are probably still some bugs. The code also needs more testing under valgrind to ensure it's not leaking memory. But it's a start...... (This used to be commit 19b7593972480540283c5bf02c02e5ecd8d2c3f0) --- source3/passdb/pdb_tdb.c | 102 +++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e7f5e0cac9..a5e2f7ae02 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -68,7 +68,6 @@ static pstring tdbsam_filename; static BOOL tdbsam_convert(int32 from) { const char *vstring = TDBSAM_VERSION_STRING; - SAM_ACCOUNT *user = NULL; const char *prefix = USERPREFIX; TDB_DATA data, key, old_key; uint8 *buf = NULL; @@ -77,11 +76,6 @@ static BOOL tdbsam_convert(int32 from) /* handle a Samba upgrade */ tdb_lock_bystring(tdbsam, vstring, 0); - if ( !NT_STATUS_IS_OK(pdb_init_sam(&user)) ) { - DEBUG(0,("tdbsam_convert: cannot initialized a SAM_ACCOUNT.\n")); - return False; - } - /* Enumerate all records and convert them */ key = tdb_firstkey(tdbsam); @@ -96,7 +90,8 @@ static BOOL tdbsam_convert(int32 from) } if (key.dptr) { - + struct samu *user = NULL; + /* read from tdbsam */ data = tdb_fetch(tdbsam, key); if (!data.dptr) { @@ -104,13 +99,8 @@ static BOOL tdbsam_convert(int32 from) return False; } - if (!NT_STATUS_IS_OK(pdb_reset_sam(user))) { - DEBUG(0,("tdbsam_convert: cannot reset SAM_ACCOUNT.\n")); - SAFE_FREE(data.dptr); - return False; - } - /* unpack the buffer from the former format */ + pdb_init_sam( &user ); DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) (version:%d)\n", key.dptr, from)); switch (from) { case 0: @@ -127,8 +117,9 @@ static BOOL tdbsam_convert(int32 from) ret = False; } if (!ret) { - DEBUG(0,("tdbsam_convert: Bad SAM_ACCOUNT entry returned from TDB (key:%s) (version:%d)\n", key.dptr, from)); + DEBUG(0,("tdbsam_convert: Bad struct samu entry returned from TDB (key:%s) (version:%d)\n", key.dptr, from)); SAFE_FREE(data.dptr); + TALLOC_FREE(user ); return False; } @@ -136,17 +127,20 @@ static BOOL tdbsam_convert(int32 from) SAFE_FREE(data.dptr); /* pack from the buffer into the new format */ + DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", key.dptr, from)); - if ((data.dsize=init_buffer_from_sam (&buf, user, False)) == -1) { - DEBUG(0,("tdbsam_convert: cannot pack the SAM_ACCOUNT into the new format\n")); - SAFE_FREE(data.dptr); + data.dsize = init_buffer_from_sam (&buf, user, False); + TALLOC_FREE(user ); + + if ( data.dsize == -1 ) { + DEBUG(0,("tdbsam_convert: cannot pack the struct samu into the new format\n")); return False; } data.dptr = (char *)buf; /* Store the buffer inside the TDBSAM */ if (tdb_store(tdbsam, key, data, TDB_MODIFY) != TDB_SUCCESS) { - DEBUG(0,("tdbsam_convert: cannot store the SAM_ACCOUNT (key:%s) in new format\n",key.dptr)); + DEBUG(0,("tdbsam_convert: cannot store the struct samu (key:%s) in new format\n",key.dptr)); SAFE_FREE(data.dptr); return False; } @@ -161,7 +155,6 @@ static BOOL tdbsam_convert(int32 from) } - pdb_free_sam(&user); /* upgrade finished */ tdb_store_int32(tdbsam, vstring, TDBSAM_VERSION); @@ -293,8 +286,13 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, uint16 acb_mask) { + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + return NT_STATUS_ACCESS_DENIED; + } + tdb_traverse( tdbsam, tdbsam_traverse_setpwent, NULL ); - + return NT_STATUS_OK; } @@ -317,20 +315,22 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) } DEBUG(7, ("endtdbpwent: closed sam database.\n")); + + tdbsam_close(); } /***************************************************************** - Get one SAM_ACCOUNT from the TDB (next in line) + Get one struct samu from the TDB (next in line) *****************************************************************/ -static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *user) +static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, struct samu *user) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; TDB_DATA data; struct pwent_list *pkey; if ( !user ) { - DEBUG(0,("tdbsam_getsampwent: SAM_ACCOUNT is NULL.\n")); + DEBUG(0,("tdbsam_getsampwent: struct samu is NULL.\n")); return nt_status; } @@ -355,7 +355,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * } if ( !init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize) ) { - DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n")); } SAFE_FREE( data.dptr ); @@ -367,7 +367,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT * Lookup a name in the SAM TDB ******************************************************************/ -static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT *user, const char *sname) +static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu *user, const char *sname) { NTSTATUS result; TDB_DATA data, key; @@ -375,7 +375,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT fstring name; if ( !user ) { - DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); + DEBUG(0,("pdb_getsampwnam: struct samu is NULL.\n")); return NT_STATUS_NO_MEMORY; } @@ -409,7 +409,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT /* unpack the buffer */ if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { - DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n")); SAFE_FREE(data.dptr); result = NT_STATUS_NO_MEMORY; goto done; @@ -428,7 +428,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT Search by rid **************************************************************************/ -static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *user, uint32 rid) +static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu *user, uint32 rid) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; TDB_DATA data, key; @@ -436,7 +436,7 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT fstring name; if ( !user ) { - DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n")); + DEBUG(0,("pdb_getsampwrid: struct samu is NULL.\n")); return nt_status; } @@ -476,7 +476,7 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT return nt_status; } -static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) +static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, struct samu * user, const DOM_SID *sid) { uint32 rid; @@ -486,7 +486,7 @@ static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * return tdbsam_getsampwrid(my_methods, user, rid); } -static BOOL tdb_delete_samacct_only( SAM_ACCOUNT *sam_pass ) +static BOOL tdb_delete_samacct_only( struct samu *sam_pass ) { TDB_DATA key; fstring keystr; @@ -513,10 +513,10 @@ static BOOL tdb_delete_samacct_only( SAM_ACCOUNT *sam_pass ) } /*************************************************************************** - Delete a SAM_ACCOUNT records for the username and RID key + Delete a struct samu records for the username and RID key ****************************************************************************/ -static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass) +static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct samu *sam_pass) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; TDB_DATA key; @@ -587,7 +587,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_AC Update the TDB SAM account record only Assumes that the tdbsam is already open ****************************************************************************/ -static BOOL tdb_update_samacct_only( SAM_ACCOUNT* newpwd, int flag ) +static BOOL tdb_update_samacct_only( struct samu* newpwd, int flag ) { TDB_DATA key, data; uint8 *buf = NULL; @@ -595,10 +595,10 @@ static BOOL tdb_update_samacct_only( SAM_ACCOUNT* newpwd, int flag ) fstring name; BOOL ret = True; - /* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */ + /* copy the struct samu struct into a BYTE buffer for storage */ if ( (data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1 ) { - DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n")); + DEBUG(0,("tdb_update_sam: ERROR - Unable to copy struct samu info BYTE buffer!\n")); ret = False; goto done; } @@ -638,7 +638,7 @@ done: Update the TDB SAM RID record only Assumes that the tdbsam is already open ****************************************************************************/ -static BOOL tdb_update_ridrec_only( SAM_ACCOUNT* newpwd, int flag ) +static BOOL tdb_update_ridrec_only( struct samu* newpwd, int flag ) { TDB_DATA key, data; fstring keystr; @@ -672,7 +672,7 @@ static BOOL tdb_update_ridrec_only( SAM_ACCOUNT* newpwd, int flag ) Update the TDB SAM ****************************************************************************/ -static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, int flag) +static BOOL tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, int flag) { uint32 user_rid; BOOL result = True; @@ -682,13 +682,13 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, tdbsam_endsampwent( my_methods ); if ( !pdb_get_group_rid(newpwd) ) { - DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] " + DEBUG (0,("tdb_update_sam: Failing to store a struct samu for [%s] " "without a primary group RID\n", pdb_get_username(newpwd))); return False; } if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { - DEBUG(0,("tdb_update_sam: SAM_ACCOUNT (%s) with no RID!\n", pdb_get_username(newpwd))); + DEBUG(0,("tdb_update_sam: struct samu (%s) with no RID!\n", pdb_get_username(newpwd))); return False; } @@ -711,10 +711,10 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd, } /*************************************************************************** - Modifies an existing SAM_ACCOUNT + Modifies an existing struct samu ****************************************************************************/ -static NTSTATUS tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) +static NTSTATUS tdbsam_update_sam_account (struct pdb_methods *my_methods, struct samu *newpwd) { if ( !tdb_update_sam(my_methods, newpwd, TDB_MODIFY) ) return NT_STATUS_UNSUCCESSFUL; @@ -723,10 +723,10 @@ static NTSTATUS tdbsam_update_sam_account (struct pdb_methods *my_methods, SAM_A } /*************************************************************************** - Adds an existing SAM_ACCOUNT + Adds an existing struct samu ****************************************************************************/ -static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCOUNT *newpwd) +static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, struct samu *newpwd) { if ( !tdb_update_sam(my_methods, newpwd, TDB_INSERT) ) return NT_STATUS_UNSUCCESSFUL; @@ -735,7 +735,7 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO } /*************************************************************************** - Renames a SAM_ACCOUNT + Renames a struct samu - check for the posix user/rename user script - Add and lock the new user record - rename the posix user @@ -744,10 +744,10 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO - unlock the new user record ***************************************************************************/ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, - SAM_ACCOUNT *old_acct, + struct samu *old_acct, const char *newname) { - SAM_ACCOUNT *new_acct = NULL; + struct samu *new_acct = NULL; pstring rename_script; BOOL interim_account = False; int rename_ret; @@ -773,7 +773,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, if ( !pdb_copy_sam_account(old_acct, &new_acct) || !pdb_set_username(new_acct, newname, PDB_CHANGED)) { - pdb_free_sam( &new_acct ); + TALLOC_FREE(new_acct ); return NT_STATUS_NO_MEMORY; } @@ -781,7 +781,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); - pdb_free_sam( &new_acct ); + TALLOC_FREE(new_acct ); return NT_STATUS_ACCESS_DENIED; } @@ -820,7 +820,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, tdbsam_close(); - pdb_free_sam( &new_acct ); + TALLOC_FREE(new_acct ); return NT_STATUS_OK; done: @@ -833,7 +833,7 @@ done: tdbsam_close(); if (new_acct) - pdb_free_sam(&new_acct); + TALLOC_FREE(new_acct); return NT_STATUS_ACCESS_DENIED; } -- cgit From 87ef96e6be75fb4988fac48b2e21892720c20426 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 21 Feb 2006 14:03:15 +0000 Subject: r13589: Make sure we only try to close the tdbsam file in endsampwent() when we have a valid pwent list from a setsampwent(). Fixes a bug with the reference count on the open tdb. (This used to be commit 77332f0738423d16a2b5e21af6aaf92b029da0ef) --- source3/passdb/pdb_tdb.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a5e2f7ae02..0a05e1f2a5 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -50,6 +50,7 @@ struct pwent_list { TDB_DATA key; }; static struct pwent_list *tdbsam_pwent_list; +static BOOL pwent_initialized; /* GLOBAL TDB SAM CONTEXT */ @@ -292,6 +293,7 @@ static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, } tdb_traverse( tdbsam, tdbsam_traverse_setpwent, NULL ); + pwent_initialized = True; return NT_STATUS_OK; } @@ -305,6 +307,13 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) { struct pwent_list *ptr, *ptr_next; + /* close the tdb only if we have a valid pwent state */ + + if ( pwent_initialized ) { + DEBUG(7, ("endtdbpwent: closed sam database.\n")); + tdbsam_close(); + } + /* clear out any remaining entries in the list */ for ( ptr=tdbsam_pwent_list; ptr; ptr = ptr_next ) { @@ -312,11 +321,9 @@ static void tdbsam_endsampwent(struct pdb_methods *my_methods) DLIST_REMOVE( tdbsam_pwent_list, ptr ); SAFE_FREE( ptr->key.dptr); SAFE_FREE( ptr ); - } + } - DEBUG(7, ("endtdbpwent: closed sam database.\n")); - - tdbsam_close(); + pwent_initialized = False; } /***************************************************************** -- cgit From cd559192633d78a9f06e239c6a448955f6ea0842 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 21 Feb 2006 14:34:11 +0000 Subject: r13590: * replace all pdb_init_sam[_talloc]() calls with samu_new() * replace all pdb_{init,fill}_sam_pw() calls with samu_set_unix() (This used to be commit 6f1afa4acc93a07d0ee9940822d7715acaae634f) --- source3/passdb/pdb_tdb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0a05e1f2a5..e994760fab 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -101,7 +101,11 @@ static BOOL tdbsam_convert(int32 from) } /* unpack the buffer from the former format */ - pdb_init_sam( &user ); + if ( !(user = samu_new( NULL )) ) { + DEBUG(0,("tdbsam_convert: samu_new() failed!\n")); + SAFE_FREE( data.dptr ); + return False; + } DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) (version:%d)\n", key.dptr, from)); switch (from) { case 0: -- cgit From 7b9736eb749d3cd55f0cf19c746cc65bdfd45bf7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 21 Feb 2006 19:02:22 +0000 Subject: r13600: Move functions local to tdbsam to pdb_tdb.c (This used to be commit e3489f7eddb21981bb74cd8792aca869ae6790e1) --- source3/passdb/pdb_tdb.c | 404 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 397 insertions(+), 7 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e994760fab..6c079a96f0 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -58,13 +58,403 @@ static TDB_CONTEXT *tdbsam; static int ref_count = 0; static pstring tdbsam_filename; -/** - * Convert old TDBSAM to the latest version. - * @param pdb_tdb A pointer to the opened TDBSAM file which must be converted. - * This file must be opened with read/write access. - * @param from Current version of the TDBSAM file. - * @return True if the conversion has been successful, false otherwise. - **/ +/********************************************************************** + Marshall/unmarshall struct samu structs. + *********************************************************************/ + +#define TDB_FORMAT_STRING_V0 "ddddddBBBBBBBBBBBBddBBwdwdBwwd" +#define TDB_FORMAT_STRING_V1 "dddddddBBBBBBBBBBBBddBBwdwdBwwd" + +/********************************************************************* +*********************************************************************/ + +static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buflen) +{ + + /* times are stored as 32bit integer + take care on system with 64bit wide time_t + --SSS */ + uint32 logon_time, + logoff_time, + kickoff_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time; + char *username = NULL; + char *domain = NULL; + char *nt_username = NULL; + char *dir_drive = NULL; + char *unknown_str = NULL; + char *munged_dial = NULL; + char *fullname = NULL; + char *homedir = NULL; + char *logon_script = NULL; + char *profile_path = NULL; + char *acct_desc = NULL; + char *workstations = NULL; + uint32 username_len, domain_len, nt_username_len, + dir_drive_len, unknown_str_len, munged_dial_len, + fullname_len, homedir_len, logon_script_len, + profile_path_len, acct_desc_len, workstations_len; + + uint32 user_rid, group_rid, remove_me, hours_len, unknown_6; + uint16 acct_ctrl, logon_divs; + uint16 bad_password_count, logon_count; + uint8 *hours = NULL; + uint8 *lm_pw_ptr = NULL, *nt_pw_ptr = NULL; + uint32 len = 0; + uint32 lm_pw_len, nt_pw_len, hourslen; + BOOL ret = True; + + if(sampass == NULL || buf == NULL) { + DEBUG(0, ("init_sam_from_buffer_v0: NULL parameters found!\n")); + return False; + } + +/* TDB_FORMAT_STRING_V0 "ddddddBBBBBBBBBBBBddBBwdwdBwwd" */ + + /* unpack the buffer into variables */ + len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING_V0, + &logon_time, /* d */ + &logoff_time, /* d */ + &kickoff_time, /* d */ + &pass_last_set_time, /* d */ + &pass_can_change_time, /* d */ + &pass_must_change_time, /* d */ + &username_len, &username, /* B */ + &domain_len, &domain, /* B */ + &nt_username_len, &nt_username, /* B */ + &fullname_len, &fullname, /* B */ + &homedir_len, &homedir, /* B */ + &dir_drive_len, &dir_drive, /* B */ + &logon_script_len, &logon_script, /* B */ + &profile_path_len, &profile_path, /* B */ + &acct_desc_len, &acct_desc, /* B */ + &workstations_len, &workstations, /* B */ + &unknown_str_len, &unknown_str, /* B */ + &munged_dial_len, &munged_dial, /* B */ + &user_rid, /* d */ + &group_rid, /* d */ + &lm_pw_len, &lm_pw_ptr, /* B */ + &nt_pw_len, &nt_pw_ptr, /* B */ + &acct_ctrl, /* w */ + &remove_me, /* remove on the next TDB_FORMAT upgarde */ /* d */ + &logon_divs, /* w */ + &hours_len, /* d */ + &hourslen, &hours, /* B */ + &bad_password_count, /* w */ + &logon_count, /* w */ + &unknown_6); /* d */ + + if (len == (uint32) -1) { + ret = False; + goto done; + } + + pdb_set_logon_time(sampass, logon_time, PDB_SET); + pdb_set_logoff_time(sampass, logoff_time, PDB_SET); + pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET); + pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET); + pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET); + pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET); + + pdb_set_username(sampass, username, PDB_SET); + pdb_set_domain(sampass, domain, PDB_SET); + pdb_set_nt_username(sampass, nt_username, PDB_SET); + pdb_set_fullname(sampass, fullname, PDB_SET); + + if (homedir) { + pdb_set_homedir(sampass, homedir, PDB_SET); + } + else { + pdb_set_homedir(sampass, + talloc_sub_basic(sampass, username, lp_logon_home()), + PDB_DEFAULT); + } + + if (dir_drive) + pdb_set_dir_drive(sampass, dir_drive, PDB_SET); + else { + pdb_set_dir_drive(sampass, + talloc_sub_basic(sampass, username, lp_logon_drive()), + PDB_DEFAULT); + } + + if (logon_script) + pdb_set_logon_script(sampass, logon_script, PDB_SET); + else { + pdb_set_logon_script(sampass, + talloc_sub_basic(sampass, username, lp_logon_script()), + PDB_DEFAULT); + } + + if (profile_path) { + pdb_set_profile_path(sampass, profile_path, PDB_SET); + } else { + pdb_set_profile_path(sampass, + talloc_sub_basic(sampass, username, lp_logon_path()), + PDB_DEFAULT); + } + + pdb_set_acct_desc(sampass, acct_desc, PDB_SET); + pdb_set_workstations(sampass, workstations, PDB_SET); + pdb_set_munged_dial(sampass, munged_dial, PDB_SET); + + if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { + if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) { + ret = False; + goto done; + } + } + + if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { + if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) { + ret = False; + goto done; + } + } + + pdb_set_pw_history(sampass, NULL, 0, PDB_SET); + pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); + pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); + pdb_set_hours_len(sampass, hours_len, PDB_SET); + pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); + pdb_set_logon_count(sampass, logon_count, PDB_SET); + pdb_set_unknown_6(sampass, unknown_6, PDB_SET); + pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET); + pdb_set_logon_divs(sampass, logon_divs, PDB_SET); + pdb_set_hours(sampass, hours, PDB_SET); + +done: + + SAFE_FREE(username); + SAFE_FREE(domain); + SAFE_FREE(nt_username); + SAFE_FREE(fullname); + SAFE_FREE(homedir); + SAFE_FREE(dir_drive); + SAFE_FREE(logon_script); + SAFE_FREE(profile_path); + SAFE_FREE(acct_desc); + SAFE_FREE(workstations); + SAFE_FREE(munged_dial); + SAFE_FREE(unknown_str); + SAFE_FREE(lm_pw_ptr); + SAFE_FREE(nt_pw_ptr); + SAFE_FREE(hours); + + return ret; +} + +/********************************************************************* +*********************************************************************/ + +static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buflen) +{ + + /* times are stored as 32bit integer + take care on system with 64bit wide time_t + --SSS */ + uint32 logon_time, + logoff_time, + kickoff_time, + bad_password_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time; + char *username = NULL; + char *domain = NULL; + char *nt_username = NULL; + char *dir_drive = NULL; + char *unknown_str = NULL; + char *munged_dial = NULL; + char *fullname = NULL; + char *homedir = NULL; + char *logon_script = NULL; + char *profile_path = NULL; + char *acct_desc = NULL; + char *workstations = NULL; + uint32 username_len, domain_len, nt_username_len, + dir_drive_len, unknown_str_len, munged_dial_len, + fullname_len, homedir_len, logon_script_len, + profile_path_len, acct_desc_len, workstations_len; + + uint32 user_rid, group_rid, remove_me, hours_len, unknown_6; + uint16 acct_ctrl, logon_divs; + uint16 bad_password_count, logon_count; + uint8 *hours = NULL; + uint8 *lm_pw_ptr = NULL, *nt_pw_ptr = NULL; + uint32 len = 0; + uint32 lm_pw_len, nt_pw_len, hourslen; + BOOL ret = True; + + if(sampass == NULL || buf == NULL) { + DEBUG(0, ("init_sam_from_buffer_v1: NULL parameters found!\n")); + return False; + } + +/* TDB_FORMAT_STRING_V1 "dddddddBBBBBBBBBBBBddBBwdwdBwwd" */ + + /* unpack the buffer into variables */ + len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING_V1, + &logon_time, /* d */ + &logoff_time, /* d */ + &kickoff_time, /* d */ + /* Change from V0 is addition of bad_password_time field. */ + &bad_password_time, /* d */ + &pass_last_set_time, /* d */ + &pass_can_change_time, /* d */ + &pass_must_change_time, /* d */ + &username_len, &username, /* B */ + &domain_len, &domain, /* B */ + &nt_username_len, &nt_username, /* B */ + &fullname_len, &fullname, /* B */ + &homedir_len, &homedir, /* B */ + &dir_drive_len, &dir_drive, /* B */ + &logon_script_len, &logon_script, /* B */ + &profile_path_len, &profile_path, /* B */ + &acct_desc_len, &acct_desc, /* B */ + &workstations_len, &workstations, /* B */ + &unknown_str_len, &unknown_str, /* B */ + &munged_dial_len, &munged_dial, /* B */ + &user_rid, /* d */ + &group_rid, /* d */ + &lm_pw_len, &lm_pw_ptr, /* B */ + &nt_pw_len, &nt_pw_ptr, /* B */ + &acct_ctrl, /* w */ + &remove_me, /* d */ + &logon_divs, /* w */ + &hours_len, /* d */ + &hourslen, &hours, /* B */ + &bad_password_count, /* w */ + &logon_count, /* w */ + &unknown_6); /* d */ + + if (len == (uint32) -1) { + ret = False; + goto done; + } + + pdb_set_logon_time(sampass, logon_time, PDB_SET); + pdb_set_logoff_time(sampass, logoff_time, PDB_SET); + pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET); + + /* Change from V0 is addition of bad_password_time field. */ + pdb_set_bad_password_time(sampass, bad_password_time, PDB_SET); + pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET); + pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET); + pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET); + + pdb_set_username(sampass, username, PDB_SET); + pdb_set_domain(sampass, domain, PDB_SET); + pdb_set_nt_username(sampass, nt_username, PDB_SET); + pdb_set_fullname(sampass, fullname, PDB_SET); + + if (homedir) { + pdb_set_homedir(sampass, homedir, PDB_SET); + } + else { + pdb_set_homedir(sampass, + talloc_sub_basic(sampass, username, lp_logon_home()), + PDB_DEFAULT); + } + + if (dir_drive) + pdb_set_dir_drive(sampass, dir_drive, PDB_SET); + else { + pdb_set_dir_drive(sampass, + talloc_sub_basic(sampass, username, lp_logon_drive()), + PDB_DEFAULT); + } + + if (logon_script) + pdb_set_logon_script(sampass, logon_script, PDB_SET); + else { + pdb_set_logon_script(sampass, + talloc_sub_basic(sampass, username, lp_logon_script()), + PDB_DEFAULT); + } + + if (profile_path) { + pdb_set_profile_path(sampass, profile_path, PDB_SET); + } else { + pdb_set_profile_path(sampass, + talloc_sub_basic(sampass, username, lp_logon_path()), + PDB_DEFAULT); + } + + pdb_set_acct_desc(sampass, acct_desc, PDB_SET); + pdb_set_workstations(sampass, workstations, PDB_SET); + pdb_set_munged_dial(sampass, munged_dial, PDB_SET); + + if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { + if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) { + ret = False; + goto done; + } + } + + if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { + if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) { + ret = False; + goto done; + } + } + + pdb_set_pw_history(sampass, NULL, 0, PDB_SET); + + pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); + pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); + pdb_set_hours_len(sampass, hours_len, PDB_SET); + pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); + pdb_set_logon_count(sampass, logon_count, PDB_SET); + pdb_set_unknown_6(sampass, unknown_6, PDB_SET); + pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET); + pdb_set_logon_divs(sampass, logon_divs, PDB_SET); + pdb_set_hours(sampass, hours, PDB_SET); + +done: + + SAFE_FREE(username); + SAFE_FREE(domain); + SAFE_FREE(nt_username); + SAFE_FREE(fullname); + SAFE_FREE(homedir); + SAFE_FREE(dir_drive); + SAFE_FREE(logon_script); + SAFE_FREE(profile_path); + SAFE_FREE(acct_desc); + SAFE_FREE(workstations); + SAFE_FREE(munged_dial); + SAFE_FREE(unknown_str); + SAFE_FREE(lm_pw_ptr); + SAFE_FREE(nt_pw_ptr); + SAFE_FREE(hours); + + return ret; +} + +/********************************************************************** + Intialize a struct samu struct from a BYTE buffer of size len + *********************************************************************/ + +static BOOL init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen) +{ + return init_sam_from_buffer_v2(sampass, buf, buflen); +} + +/********************************************************************** + Intialize a BYTE buffer from a struct samu struct + *********************************************************************/ + +static uint32 init_buffer_from_sam (uint8 **buf, const struct samu *sampass, BOOL size_only) +{ + return init_buffer_from_sam_v2(buf, sampass, size_only); +} + +/********************************************************************** + Intialize a BYTE buffer from a struct samu struct + *********************************************************************/ static BOOL tdbsam_convert(int32 from) { -- cgit From cab298856ab1179cdaec2ef89121f7c66c6b6d76 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 22 Feb 2006 10:28:02 +0000 Subject: r13622: Allow to rename machine accounts in a Samba Domain. This still uses the "rename user script" to do the rename of the posix machine account (this might be changed later). Fixes #2331. Guenther (This used to be commit b2eac2e6eb6ddd1bcb4ed5172e7cd64144c18d16) --- source3/passdb/pdb_tdb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 6c079a96f0..26b60dcc3c 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1200,9 +1200,10 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, } /* rename the posix user */ - - pstring_sub(rename_script, "%unew", newname); - pstring_sub(rename_script, "%uold", pdb_get_username(old_acct)); + string_sub2(rename_script, "%unew", newname, sizeof(pstring), + True, False, True); + string_sub2(rename_script, "%uold", pdb_get_username(old_acct), + sizeof(pstring), True, False, True); rename_ret = smbrun(rename_script, NULL); DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); -- cgit From d95e13e68f3c7ac517a45877b351849ef4a99b93 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 24 Feb 2006 21:36:40 +0000 Subject: r13679: Commiting the rm_primary_group.patch posted on samba-technical * ignore the primary group SID attribute from struct samu* * generate the primary group SID strictlky from the Unix primary group when dealing with passdb users * Fix memory leak in original patch caused by failing to free a talloc * * add wrapper around samu_set_unix() to prevent exposing the create BOOL to callers. Wrappers are samu_set_unix() and samu-allic_rid_unix() (This used to be commit bcf269e2ec6630b78d909010fabd3b69dd6dda84) --- source3/passdb/pdb_tdb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 26b60dcc3c..e905b026ec 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -216,7 +216,6 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_pw_history(sampass, NULL, 0, PDB_SET); pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); - pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); pdb_set_hours_len(sampass, hours_len, PDB_SET); pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); pdb_set_logon_count(sampass, logon_count, PDB_SET); @@ -404,7 +403,6 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_pw_history(sampass, NULL, 0, PDB_SET); pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); - pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); pdb_set_hours_len(sampass, hours_len, PDB_SET); pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); pdb_set_logon_count(sampass, logon_count, PDB_SET); @@ -447,7 +445,7 @@ static BOOL init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen Intialize a BYTE buffer from a struct samu struct *********************************************************************/ -static uint32 init_buffer_from_sam (uint8 **buf, const struct samu *sampass, BOOL size_only) +static uint32 init_buffer_from_sam (uint8 **buf, struct samu *sampass, BOOL size_only) { return init_buffer_from_sam_v2(buf, sampass, size_only); } @@ -1171,7 +1169,11 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, tdbsam_endsampwent( my_methods ); - if ( !pdb_copy_sam_account(old_acct, &new_acct) + if ( !(new_acct = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } + + if ( !pdb_copy_sam_account(new_acct, old_acct) || !pdb_set_username(new_acct, newname, PDB_CHANGED)) { TALLOC_FREE(new_acct ); -- cgit From e54786b53543b4667288c64abb55478fddd95061 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 27 Feb 2006 10:32:45 +0000 Subject: r13711: * Correctly handle acb_info/acct_flags as uint32 not as uint16. * Fix a couple of related parsing issues. * in the info3 reply in a samlogon, return the ACB-flags (instead of returning zero) Guenther (This used to be commit 5b89e8bc24f0fdc8b52d5c9e849aba723df34ea7) --- source3/passdb/pdb_tdb.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 238 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e905b026ec..e33cd46d54 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -38,7 +38,7 @@ static int tdbsam_debug_level = DBGC_ALL; #endif -#define TDBSAM_VERSION 2 /* Most recent TDBSAM version */ +#define TDBSAM_VERSION 3 /* Most recent TDBSAM version */ #define TDBSAM_VERSION_STRING "INFO/version" #define PASSDB_FILE_NAME "passdb.tdb" #define USERPREFIX "USER_" @@ -64,6 +64,7 @@ static pstring tdbsam_filename; #define TDB_FORMAT_STRING_V0 "ddddddBBBBBBBBBBBBddBBwdwdBwwd" #define TDB_FORMAT_STRING_V1 "dddddddBBBBBBBBBBBBddBBwdwdBwwd" +#define TDB_FORMAT_STRING_V2 "dddddddBBBBBBBBBBBBddBBBwwdBwwd" /********************************************************************* *********************************************************************/ @@ -432,13 +433,243 @@ done: return ret; } +BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) +{ + + /* times are stored as 32bit integer + take care on system with 64bit wide time_t + --SSS */ + uint32 logon_time, + logoff_time, + kickoff_time, + bad_password_time, + pass_last_set_time, + pass_can_change_time, + pass_must_change_time; + char *username = NULL; + char *domain = NULL; + char *nt_username = NULL; + char *dir_drive = NULL; + char *unknown_str = NULL; + char *munged_dial = NULL; + char *fullname = NULL; + char *homedir = NULL; + char *logon_script = NULL; + char *profile_path = NULL; + char *acct_desc = NULL; + char *workstations = NULL; + uint32 username_len, domain_len, nt_username_len, + dir_drive_len, unknown_str_len, munged_dial_len, + fullname_len, homedir_len, logon_script_len, + profile_path_len, acct_desc_len, workstations_len; + + uint32 user_rid, group_rid, hours_len, unknown_6; + uint16 acct_ctrl, logon_divs; + uint16 bad_password_count, logon_count; + uint8 *hours = NULL; + uint8 *lm_pw_ptr = NULL, *nt_pw_ptr = NULL, *nt_pw_hist_ptr = NULL; + uint32 len = 0; + uint32 lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen; + uint32 pwHistLen = 0; + BOOL ret = True; + fstring tmpstring; + BOOL expand_explicit = lp_passdb_expand_explicit(); + + if(sampass == NULL || buf == NULL) { + DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n")); + return False; + } + +/* TDB_FORMAT_STRING_V2 "dddddddBBBBBBBBBBBBddBBBwwdBwwd" */ + + /* unpack the buffer into variables */ + len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING_V2, + &logon_time, /* d */ + &logoff_time, /* d */ + &kickoff_time, /* d */ + &bad_password_time, /* d */ + &pass_last_set_time, /* d */ + &pass_can_change_time, /* d */ + &pass_must_change_time, /* d */ + &username_len, &username, /* B */ + &domain_len, &domain, /* B */ + &nt_username_len, &nt_username, /* B */ + &fullname_len, &fullname, /* B */ + &homedir_len, &homedir, /* B */ + &dir_drive_len, &dir_drive, /* B */ + &logon_script_len, &logon_script, /* B */ + &profile_path_len, &profile_path, /* B */ + &acct_desc_len, &acct_desc, /* B */ + &workstations_len, &workstations, /* B */ + &unknown_str_len, &unknown_str, /* B */ + &munged_dial_len, &munged_dial, /* B */ + &user_rid, /* d */ + &group_rid, /* d */ + &lm_pw_len, &lm_pw_ptr, /* B */ + &nt_pw_len, &nt_pw_ptr, /* B */ + /* Change from V1 is addition of password history field. */ + &nt_pw_hist_len, &nt_pw_hist_ptr, /* B */ + &acct_ctrl, /* w */ + /* Also "remove_me" field was removed. */ + &logon_divs, /* w */ + &hours_len, /* d */ + &hourslen, &hours, /* B */ + &bad_password_count, /* w */ + &logon_count, /* w */ + &unknown_6); /* d */ + + if (len == (uint32) -1) { + ret = False; + goto done; + } + + pdb_set_logon_time(sampass, logon_time, PDB_SET); + pdb_set_logoff_time(sampass, logoff_time, PDB_SET); + pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET); + pdb_set_bad_password_time(sampass, bad_password_time, PDB_SET); + pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET); + pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET); + pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET); + + pdb_set_username(sampass, username, PDB_SET); + pdb_set_domain(sampass, domain, PDB_SET); + pdb_set_nt_username(sampass, nt_username, PDB_SET); + pdb_set_fullname(sampass, fullname, PDB_SET); + + if (homedir) { + fstrcpy( tmpstring, homedir ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } + pdb_set_homedir(sampass, tmpstring, PDB_SET); + } + else { + pdb_set_homedir(sampass, + talloc_sub_basic(sampass, username, lp_logon_home()), + PDB_DEFAULT); + } + + if (dir_drive) + pdb_set_dir_drive(sampass, dir_drive, PDB_SET); + else + pdb_set_dir_drive(sampass, lp_logon_drive(), PDB_DEFAULT ); + + if (logon_script) { + fstrcpy( tmpstring, logon_script ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } + pdb_set_logon_script(sampass, tmpstring, PDB_SET); + } + else { + pdb_set_logon_script(sampass, + talloc_sub_basic(sampass, username, lp_logon_script()), + PDB_DEFAULT); + } + + if (profile_path) { + fstrcpy( tmpstring, profile_path ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } + pdb_set_profile_path(sampass, tmpstring, PDB_SET); + } + else { + pdb_set_profile_path(sampass, + talloc_sub_basic(sampass, username, lp_logon_path()), + PDB_DEFAULT); + } + + pdb_set_acct_desc(sampass, acct_desc, PDB_SET); + pdb_set_workstations(sampass, workstations, PDB_SET); + pdb_set_munged_dial(sampass, munged_dial, PDB_SET); + + if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { + if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) { + ret = False; + goto done; + } + } + + if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { + if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) { + ret = False; + goto done; + } + } + + /* Change from V1 is addition of password history field. */ + pdb_get_account_policy(AP_PASSWORD_HISTORY, &pwHistLen); + if (pwHistLen) { + uint8 *pw_hist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN); + if (!pw_hist) { + ret = False; + goto done; + } + memset(pw_hist, '\0', pwHistLen * PW_HISTORY_ENTRY_LEN); + if (nt_pw_hist_ptr && nt_pw_hist_len) { + int i; + SMB_ASSERT((nt_pw_hist_len % PW_HISTORY_ENTRY_LEN) == 0); + nt_pw_hist_len /= PW_HISTORY_ENTRY_LEN; + for (i = 0; (i < pwHistLen) && (i < nt_pw_hist_len); i++) { + memcpy(&pw_hist[i*PW_HISTORY_ENTRY_LEN], + &nt_pw_hist_ptr[i*PW_HISTORY_ENTRY_LEN], + PW_HISTORY_ENTRY_LEN); + } + } + if (!pdb_set_pw_history(sampass, pw_hist, pwHistLen, PDB_SET)) { + SAFE_FREE(pw_hist); + ret = False; + goto done; + } + SAFE_FREE(pw_hist); + } else { + pdb_set_pw_history(sampass, NULL, 0, PDB_SET); + } + + pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); + pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); + pdb_set_hours_len(sampass, hours_len, PDB_SET); + pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); + pdb_set_logon_count(sampass, logon_count, PDB_SET); + pdb_set_unknown_6(sampass, unknown_6, PDB_SET); + pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET); + pdb_set_logon_divs(sampass, logon_divs, PDB_SET); + pdb_set_hours(sampass, hours, PDB_SET); + +done: + + SAFE_FREE(username); + SAFE_FREE(domain); + SAFE_FREE(nt_username); + SAFE_FREE(fullname); + SAFE_FREE(homedir); + SAFE_FREE(dir_drive); + SAFE_FREE(logon_script); + SAFE_FREE(profile_path); + SAFE_FREE(acct_desc); + SAFE_FREE(workstations); + SAFE_FREE(munged_dial); + SAFE_FREE(unknown_str); + SAFE_FREE(lm_pw_ptr); + SAFE_FREE(nt_pw_ptr); + SAFE_FREE(nt_pw_hist_ptr); + SAFE_FREE(hours); + + return ret; +} + + /********************************************************************** Intialize a struct samu struct from a BYTE buffer of size len *********************************************************************/ static BOOL init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen) { - return init_sam_from_buffer_v2(sampass, buf, buflen); + return init_sam_from_buffer_v3(sampass, buf, buflen); } /********************************************************************** @@ -447,7 +678,7 @@ static BOOL init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen static uint32 init_buffer_from_sam (uint8 **buf, struct samu *sampass, BOOL size_only) { - return init_buffer_from_sam_v2(buf, sampass, size_only); + return init_buffer_from_sam_v3(buf, sampass, size_only); } /********************************************************************** @@ -505,6 +736,9 @@ static BOOL tdbsam_convert(int32 from) case 2: ret = init_sam_from_buffer_v2(user, (uint8 *)data.dptr, data.dsize); break; + case 3: + ret = init_sam_from_buffer_v3(user, (uint8 *)data.dptr, data.dsize); + break; default: /* unknown tdbsam version */ ret = False; @@ -677,7 +911,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, Save a list of user keys for iteration. ****************************************************************/ -static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, uint16 acb_mask) +static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, uint32 acb_mask) { if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); -- cgit From 06e720a66c9f05cd99ef5a7cb8b2018b5cde5ff0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 27 Feb 2006 21:24:12 +0000 Subject: r13728: No, we have not talked about this on irc less than 24h ago... ;-) (This used to be commit 59f95ea752d932b00d4a4ff37311b830d65c8a03) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e33cd46d54..b0f8a11788 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1161,7 +1161,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct at module initialization time */ if ( !tdbsam ) { - DEBUG(0,("tdbsam_getsampwrid: tdbsam not open!\n")); + DEBUG(0,("tdbsam_delete_sam_account: tdbsam not open!\n")); return NT_STATUS_NO_SUCH_USER; } @@ -1179,7 +1179,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct /* open the database */ if ( !tdbsam_open( tdbsam_filename ) ) { - DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); + DEBUG(0,("tdbsam_delete_sam_account: failed to open %s!\n", tdbsam_filename)); return NT_STATUS_ACCESS_DENIED; } -- cgit From 2479b8305b71bc153f808827cd63618af8fe93d8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 27 Feb 2006 21:28:19 +0000 Subject: r13729: Fix smbpasswd -x (This used to be commit 2afcbbfb6f2efcc2e10106b10a87365556013787) --- source3/passdb/pdb_tdb.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b0f8a11788..fdf22d9c42 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1157,12 +1157,12 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct uint32 rid; fstring name; - /* make sure we have an open handle to the tdb. Should have happened - at module initialization time */ - - if ( !tdbsam ) { - DEBUG(0,("tdbsam_delete_sam_account: tdbsam not open!\n")); - return NT_STATUS_NO_SUCH_USER; + /* open the database */ + + if ( !tdbsam_open( tdbsam_filename ) ) { + DEBUG(0,("tdbsam_delete_sam_account: failed to open %s!\n", + tdbsam_filename)); + return NT_STATUS_ACCESS_DENIED; } fstrcpy(name, pdb_get_username(sam_pass)); @@ -1176,13 +1176,6 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct rid = pdb_get_user_rid(sam_pass); - /* open the database */ - - if ( !tdbsam_open( tdbsam_filename ) ) { - DEBUG(0,("tdbsam_delete_sam_account: failed to open %s!\n", tdbsam_filename)); - return NT_STATUS_ACCESS_DENIED; - } - /* it's outaa here! 8^) */ if ( tdb_delete(tdbsam, key) != TDB_SUCCESS ) { -- cgit From ddf14cc286944e11cebfcf550cf57a7a9436a5a0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Feb 2006 06:33:31 +0000 Subject: r13747: Fix the reference count for tdbsam_open() - on an upgrade it calls tdbsam_convert() which calls tdbsam_open() deep inside the init_sam_from_buffer_vX call. If the ref count hasn't been set yet then we will close the tdbsam reference in tdbsam_getsampwsid(). smbpasswd -a was core-dumping again :-). Jeremy (This used to be commit 993069eb87c190ba8ee92224340c8f9ffb3ade74) --- source3/passdb/pdb_tdb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index fdf22d9c42..b38ebe436a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -817,17 +817,24 @@ static BOOL tdbsam_open( const char *name ) return False; } + /* set the initial reference count - must be done before tdbsam_convert + as that calls tdbsam_open()/tdbsam_close(). */ + + ref_count = 1; + /* Check the version */ version = tdb_fetch_int32( tdbsam, TDBSAM_VERSION_STRING ); - if (version == -1) + if (version == -1) { version = 0; /* Version not found, assume version 0 */ + } /* Compare the version */ if (version > TDBSAM_VERSION) { /* Version more recent than the latest known */ DEBUG(0, ("tdbsam_open: unknown version => %d\n", version)); tdb_close( tdbsam ); + ref_count = 0; return False; } @@ -839,16 +846,13 @@ static BOOL tdbsam_open( const char *name ) if ( !tdbsam_convert(version) ) { DEBUG(0, ("tdbsam_open: Error when trying to convert tdbsam [%s]\n",name)); tdb_close(tdbsam); + ref_count = 0; return False; } DEBUG(3, ("TDBSAM converted successfully.\n")); } - /* set the initial reference count */ - - ref_count = 1; - DEBUG(4,("tdbsam_open: successfully opened %s\n", name )); return True; -- cgit From 5837baa12672dd0c0ee3f1011fba6c11bb9d3da9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 1 Mar 2006 02:47:50 +0000 Subject: r13765: Fix bug reported by jra. Don't check for a group SID when storing a user since we no longer pay any attention to the value. (This used to be commit 085c6859ee5b97efe9ec06e95877d500822d3c82) --- source3/passdb/pdb_tdb.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b38ebe436a..0bab02343e 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1311,11 +1311,13 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, tdbsam_endsampwent( my_methods ); +#if 0 if ( !pdb_get_group_rid(newpwd) ) { DEBUG (0,("tdb_update_sam: Failing to store a struct samu for [%s] " "without a primary group RID\n", pdb_get_username(newpwd))); return False; } +#endif if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { DEBUG(0,("tdb_update_sam: struct samu (%s) with no RID!\n", pdb_get_username(newpwd))); -- cgit From 5aa66fd0393318586edb5ee17e5cad2236aa5c8b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 20 Mar 2006 10:18:23 +0000 Subject: r14577: BUG Fixes: * Add back in the import/export support to pdbedit * Fix segv in pam_smbpass * Cleanup some error paths in pdb_tdb and pdb_interface (This used to be commit df53d64910fbb96eb810102e986b3c337d54c463) --- source3/passdb/pdb_tdb.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0bab02343e..b7161ff589 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1006,7 +1006,6 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, struct samu * static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu *user, const char *sname) { - NTSTATUS result; TDB_DATA data, key; fstring keystr; fstring name; @@ -1039,8 +1038,8 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); DEBUGADD(5, (" Key: %s\n", keystr)); - result = NT_STATUS_NO_SUCH_USER; - goto done; + tdbsam_close(); + return NT_STATUS_NO_SUCH_USER; } /* unpack the buffer */ @@ -1048,17 +1047,16 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n")); SAFE_FREE(data.dptr); - result = NT_STATUS_NO_MEMORY; - goto done; + tdbsam_close(); + return NT_STATUS_NO_MEMORY; } - result = NT_STATUS_OK; + /* success */ - done: SAFE_FREE(data.dptr); tdbsam_close(); - return result; + return NT_STATUS_OK; } /*************************************************************************** -- cgit From 1839b4be14e905428257eb999def184d73dcf08f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 22 Mar 2006 08:04:13 +0000 Subject: r14634: Many bug fixes thanks to train rides and overnight stays in airports * Finally fix parsing idmap uid/gid ranges not to break with spaces surrounding the '-' * Allow local groups to renamed by adding info level 2 to _samr_set_aliasinfo() * Fix parsing bug in _samr_del_dom_alias() reply * Prevent root from being deleted via Samba * Prevent builting groups from being renamed or deleted * Fix bug in pdb_tdb that broke renaming user accounts * Make sure winbindd is running when trying to create the Administrators and Users BUILTIN groups automatically from smbd (and not just check the winbind nexted groups parameter value). * Have the top level rid allocator verify that the RID it is about to grant is not already assigned in our own SAM (retries up to 250 times). This fixes passdb with existing SIDs assigned to users from the RID algorithm but not monotonically allocating the RIDs from passdb. (This used to be commit db1162241f79c2af8afb7d8c26e8ed1c4a4b476f) --- source3/passdb/pdb_tdb.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b7161ff589..94ae328812 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1382,19 +1382,12 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, BOOL interim_account = False; int rename_ret; - /* make sure we have an open handle to the tdb. Should have happened - at module initialization time */ - - if ( !tdbsam ) { - DEBUG(0,("tdbsam_getsampwrid: tdbsam not open!\n")); - return NT_STATUS_NO_SUCH_USER; - } - /* can't do anything without an external script */ pstrcpy(rename_script, lp_renameuser_script() ); - if ( ! *rename_script ) + if ( ! *rename_script ) { return NT_STATUS_ACCESS_DENIED; + } /* invalidate the existing TDB iterator if it is open */ @@ -1421,8 +1414,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, /* add the new account and lock it */ - if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) - { + if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) { goto done; } @@ -1441,13 +1433,15 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); - if (rename_ret) + if (rename_ret) { goto done; + } /* rewrite the rid->username record */ - if ( !tdb_update_ridrec_only( new_acct, TDB_MODIFY) ) + if ( !tdb_update_ridrec_only( new_acct, TDB_MODIFY) ) { goto done; + } interim_account = False; tdb_unlock_bystring( tdbsam, newname ); -- cgit From e17302200c138eec7df504a7f4b2bde46073a810 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 17 Apr 2006 11:49:06 +0000 Subject: r15101: Little step towards getting Samba4 tdb into 3: tdb_lock_bystring does not have the timeout argument in Samba4. Add a new routine tdb_lock_bystring_with_timeout. Volker (This used to be commit b9c6e3f55602fa505859a4b2cd137b74105d685f) --- source3/passdb/pdb_tdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 94ae328812..ba8124d392 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -694,7 +694,7 @@ static BOOL tdbsam_convert(int32 from) BOOL ret; /* handle a Samba upgrade */ - tdb_lock_bystring(tdbsam, vstring, 0); + tdb_lock_bystring(tdbsam, vstring); /* Enumerate all records and convert them */ key = tdb_firstkey(tdbsam); @@ -1420,7 +1420,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, interim_account = True; - if ( tdb_lock_bystring(tdbsam, newname, 30) == -1 ) { + if ( tdb_lock_bystring_with_timeout(tdbsam, newname, 30) == -1 ) { goto done; } @@ -1492,7 +1492,7 @@ static BOOL init_idmap_tdb(TDB_CONTEXT *tdb) { int32 version; - if (tdb_lock_bystring(tdb, "IDMAP_VERSION", 0) != 0) { + if (tdb_lock_bystring(tdb, "IDMAP_VERSION") != 0) { DEBUG(0, ("Could not lock IDMAP_VERSION\n")); return False; } -- cgit From d7dbf378250d1053758228ed8113716819c92493 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 2 Jun 2006 21:53:09 +0000 Subject: r16014: Correctly set the group RID in init_sam_from_buffer. BIG THANKS to Tom Bork for reporting that Bug! Volker (This used to be commit 40339fdcced67d62e449ba6f19329d89c808e139) --- source3/passdb/pdb_tdb.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index ba8124d392..0dc46bec2d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -217,6 +217,7 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_pw_history(sampass, NULL, 0, PDB_SET); pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); + pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); pdb_set_hours_len(sampass, hours_len, PDB_SET); pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); pdb_set_logon_count(sampass, logon_count, PDB_SET); @@ -404,6 +405,7 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_pw_history(sampass, NULL, 0, PDB_SET); pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); + pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); pdb_set_hours_len(sampass, hours_len, PDB_SET); pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); pdb_set_logon_count(sampass, logon_count, PDB_SET); -- cgit From d1014c1cdfce116741ddd6eccd65b69530ce0b84 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 00:50:14 +0000 Subject: r16582: Fix Klocwork #1997 and all generic class of problems where we don't correctly check the return from memdup. Jeremy. (This used to be commit ce14daf51c7ee2f9c68c77f7f4674e6f0e35c9ca) --- source3/passdb/pdb_tdb.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0dc46bec2d..94be32162c 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -902,6 +902,12 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, /* save a copy of the key */ ptr->key.dptr = memdup( key.dptr, key.dsize ); + if (!ptr->key.dptr) { + DEBUG(0,("tdbsam_traverse_setpwent: memdup failed\n")); + /* just return 0 and let the traversal continue */ + return 0; + } + ptr->key.dsize = key.dsize; DLIST_ADD( tdbsam_pwent_list, ptr ); -- cgit From 5887885da3c98d7b72a6c6f876a0d352fe3efcde Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 17:11:06 +0000 Subject: r16624: Fix bug #3877, reported by jason@ncac.gwu.edu Jeremy. (This used to be commit 1f52b8b40619679242da663f5e5e7836d547f0a2) --- source3/passdb/pdb_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 94be32162c..11bbbc186c 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1310,7 +1310,6 @@ static BOOL tdb_update_ridrec_only( struct samu* newpwd, int flag ) static BOOL tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, int flag) { - uint32 user_rid; BOOL result = True; /* invalidate the existing TDB iterator if it is open */ @@ -1325,7 +1324,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, } #endif - if ( !(user_rid = pdb_get_user_rid(newpwd)) ) { + if (!pdb_get_user_rid(newpwd)) { DEBUG(0,("tdb_update_sam: struct samu (%s) with no RID!\n", pdb_get_username(newpwd))); return False; } -- cgit From 124cd3c6043900be696148bb3c416f8c7c098cc9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Jun 2006 00:04:47 +0000 Subject: r16663: Fix coverity #301, memleak in error path. Jeremy. (This used to be commit dfdb4ce89155dc1528b455252751616cc2c6708c) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 11bbbc186c..f3ae4b7b02 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -905,6 +905,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, if (!ptr->key.dptr) { DEBUG(0,("tdbsam_traverse_setpwent: memdup failed\n")); /* just return 0 and let the traversal continue */ + SAFE_FREE(ptr); return 0; } @@ -914,7 +915,6 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, } - return 0; } -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/passdb/pdb_tdb.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index f3ae4b7b02..ac8cbbe91a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -169,7 +169,8 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf } else { pdb_set_homedir(sampass, - talloc_sub_basic(sampass, username, lp_logon_home()), + talloc_sub_basic(sampass, username, domain, + lp_logon_home()), PDB_DEFAULT); } @@ -177,7 +178,8 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_dir_drive(sampass, dir_drive, PDB_SET); else { pdb_set_dir_drive(sampass, - talloc_sub_basic(sampass, username, lp_logon_drive()), + talloc_sub_basic(sampass, username, domain, + lp_logon_drive()), PDB_DEFAULT); } @@ -185,7 +187,8 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_logon_script(sampass, logon_script, PDB_SET); else { pdb_set_logon_script(sampass, - talloc_sub_basic(sampass, username, lp_logon_script()), + talloc_sub_basic(sampass, username, domain, + lp_logon_script()), PDB_DEFAULT); } @@ -193,7 +196,8 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_profile_path(sampass, profile_path, PDB_SET); } else { pdb_set_profile_path(sampass, - talloc_sub_basic(sampass, username, lp_logon_path()), + talloc_sub_basic(sampass, username, domain, + lp_logon_path()), PDB_DEFAULT); } @@ -356,7 +360,8 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf } else { pdb_set_homedir(sampass, - talloc_sub_basic(sampass, username, lp_logon_home()), + talloc_sub_basic(sampass, username, domain, + lp_logon_home()), PDB_DEFAULT); } @@ -364,7 +369,8 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_dir_drive(sampass, dir_drive, PDB_SET); else { pdb_set_dir_drive(sampass, - talloc_sub_basic(sampass, username, lp_logon_drive()), + talloc_sub_basic(sampass, username, domain, + lp_logon_drive()), PDB_DEFAULT); } @@ -372,7 +378,8 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_logon_script(sampass, logon_script, PDB_SET); else { pdb_set_logon_script(sampass, - talloc_sub_basic(sampass, username, lp_logon_script()), + talloc_sub_basic(sampass, username, domain, + lp_logon_script()), PDB_DEFAULT); } @@ -380,7 +387,8 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf pdb_set_profile_path(sampass, profile_path, PDB_SET); } else { pdb_set_profile_path(sampass, - talloc_sub_basic(sampass, username, lp_logon_path()), + talloc_sub_basic(sampass, username, domain, + lp_logon_path()), PDB_DEFAULT); } @@ -541,14 +549,15 @@ BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) if (homedir) { fstrcpy( tmpstring, homedir ); if (expand_explicit) { - standard_sub_basic( username, tmpstring, + standard_sub_basic( username, domain, tmpstring, sizeof(tmpstring) ); } pdb_set_homedir(sampass, tmpstring, PDB_SET); } else { pdb_set_homedir(sampass, - talloc_sub_basic(sampass, username, lp_logon_home()), + talloc_sub_basic(sampass, username, domain, + lp_logon_home()), PDB_DEFAULT); } @@ -560,28 +569,30 @@ BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) if (logon_script) { fstrcpy( tmpstring, logon_script ); if (expand_explicit) { - standard_sub_basic( username, tmpstring, + standard_sub_basic( username, domain, tmpstring, sizeof(tmpstring) ); } pdb_set_logon_script(sampass, tmpstring, PDB_SET); } else { pdb_set_logon_script(sampass, - talloc_sub_basic(sampass, username, lp_logon_script()), + talloc_sub_basic(sampass, username, domain, + lp_logon_script()), PDB_DEFAULT); } if (profile_path) { fstrcpy( tmpstring, profile_path ); if (expand_explicit) { - standard_sub_basic( username, tmpstring, + standard_sub_basic( username, domain, tmpstring, sizeof(tmpstring) ); } pdb_set_profile_path(sampass, tmpstring, PDB_SET); } else { pdb_set_profile_path(sampass, - talloc_sub_basic(sampass, username, lp_logon_path()), + talloc_sub_basic(sampass, username, domain, + lp_logon_path()), PDB_DEFAULT); } @@ -606,7 +617,7 @@ BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) /* Change from V1 is addition of password history field. */ pdb_get_account_policy(AP_PASSWORD_HISTORY, &pwHistLen); if (pwHistLen) { - uint8 *pw_hist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN); + uint8 *pw_hist = SMB_MALLOC_ARRAY(uint8, pwHistLen * PW_HISTORY_ENTRY_LEN); if (!pw_hist) { ret = False; goto done; @@ -901,7 +912,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, /* save a copy of the key */ - ptr->key.dptr = memdup( key.dptr, key.dsize ); + ptr->key.dptr = (char *)memdup( key.dptr, key.dsize ); if (!ptr->key.dptr) { DEBUG(0,("tdbsam_traverse_setpwent: memdup failed\n")); /* just return 0 and let the traversal continue */ -- cgit From 9f6fb43eeefb18578040a0f3b5af941460ec5ca9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 19 Jul 2006 20:59:04 +0000 Subject: r17150: MMC User & group plugins fixes: * Make sure to lower case all usernames before calling the create, delete, or rename hooks. * Preserve case for usernames in passdb * Flush the getpwnam cache after renaming a user * Add become/unbecome root block in _samr_delete_dom_user() when trying to verify the account's existence. (This used to be commit bbe11b7a950e7d85001f042bbd1ea3bf33ecda7b) --- source3/passdb/pdb_tdb.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index ac8cbbe91a..b16368baf1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1399,6 +1399,8 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, pstring rename_script; BOOL interim_account = False; int rename_ret; + fstring oldname_lower; + fstring newname_lower; /* can't do anything without an external script */ @@ -1442,11 +1444,19 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, goto done; } - /* rename the posix user */ - string_sub2(rename_script, "%unew", newname, sizeof(pstring), - True, False, True); - string_sub2(rename_script, "%uold", pdb_get_username(old_acct), - sizeof(pstring), True, False, True); + /* Rename the posix user. Follow the semantics of _samr_create_user() + so that we lower case the posix name but preserve the case in passdb */ + + fstrcpy( oldname_lower, pdb_get_username(old_acct) ); + strlower_m( oldname_lower ); + + fstrcpy( newname_lower, newname ); + strlower_m( newname_lower ); + + string_sub2(rename_script, "%unew", newname_lower, sizeof(pstring), + True, False, True); + string_sub2(rename_script, "%uold", oldname_lower, sizeof(pstring), + True, False, True); rename_ret = smbrun(rename_script, NULL); DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); -- cgit From a3e1f7e44d2d6a5ef801badc189b3dcf19dc72d9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 20 Sep 2006 00:15:50 +0000 Subject: r18703: Fix the annoying effect that happens when nscd is running: We usually do not get the results from user/group script modifications immediately. A lot of users do add nscd restart/refresh commands into their scripts to workaround that while we could flush the nscd caches directly using libnscd. Guenther (This used to be commit 7db6ce295afbedfada7b207ad56566d2195a0d21) --- source3/passdb/pdb_tdb.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b16368baf1..e9beaa0536 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1461,6 +1461,10 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); + if (rename_ret == 0) { + smb_nscd_flush_user_cache(); + } + if (rename_ret) { goto done; } -- cgit From a3a4d6721b451807d55e9c5199275aad57db26fb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 27 Mar 2007 10:43:32 +0000 Subject: r21982: make use of tdb_*_bystring() and string_term_tdb_data() to avoid creating the TDB_DATA struct from strings "by hand" metze (This used to be commit 9ebaa4c573ea5784a8c9cd9d29561b760d62bb18) --- source3/passdb/pdb_tdb.c | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index e9beaa0536..37ee19028a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1025,7 +1025,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, struct samu * static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu *user, const char *sname) { - TDB_DATA data, key; + TDB_DATA data; fstring keystr; fstring name; @@ -1040,8 +1040,6 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; /* open the database */ @@ -1052,7 +1050,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu /* get the record */ - data = tdb_fetch(tdbsam, key); + data = tdb_fetch_bystring(tdbsam, keystr); if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); @@ -1085,7 +1083,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu *user, uint32 rid) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - TDB_DATA data, key; + TDB_DATA data; fstring keystr; fstring name; @@ -1097,8 +1095,6 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu /* set search key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; /* open the database */ @@ -1109,7 +1105,7 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu /* get the record */ - data = tdb_fetch (tdbsam, key); + data = tdb_fetch_bystring (tdbsam, keystr); if (!data.dptr) { DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); @@ -1142,7 +1138,6 @@ static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, struct samu * static BOOL tdb_delete_samacct_only( struct samu *sam_pass ) { - TDB_DATA key; fstring keystr; fstring name; @@ -1152,12 +1147,10 @@ static BOOL tdb_delete_samacct_only( struct samu *sam_pass ) /* set the search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; /* it's outaa here! 8^) */ - if (tdb_delete(tdbsam, key) != TDB_SUCCESS) { + if (tdb_delete_bystring(tdbsam, keystr) != TDB_SUCCESS) { DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); return False; @@ -1173,7 +1166,6 @@ static BOOL tdb_delete_samacct_only( struct samu *sam_pass ) static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct samu *sam_pass) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - TDB_DATA key; fstring keystr; uint32 rid; fstring name; @@ -1192,14 +1184,12 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct /* set the search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; rid = pdb_get_user_rid(sam_pass); /* it's outaa here! 8^) */ - if ( tdb_delete(tdbsam, key) != TDB_SUCCESS ) { + if ( tdb_delete_bystring(tdbsam, keystr) != TDB_SUCCESS ) { DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); nt_status = NT_STATUS_UNSUCCESSFUL; @@ -1209,12 +1199,10 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct /* set the search key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; /* it's outaa here! 8^) */ - if ( tdb_delete(tdbsam, key) != TDB_SUCCESS ) { + if ( tdb_delete_bystring(tdbsam, keystr) != TDB_SUCCESS ) { DEBUG(5, ("Error deleting entry from tdb rid database!\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); nt_status = NT_STATUS_UNSUCCESSFUL; @@ -1236,7 +1224,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct ****************************************************************************/ static BOOL tdb_update_samacct_only( struct samu* newpwd, int flag ) { - TDB_DATA key, data; + TDB_DATA data; uint8 *buf = NULL; fstring keystr; fstring name; @@ -1260,12 +1248,10 @@ static BOOL tdb_update_samacct_only( struct samu* newpwd, int flag ) /* setup the USER index key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; /* add the account */ - if ( tdb_store(tdbsam, key, data, flag) != TDB_SUCCESS ) { + if ( tdb_store_bystring(tdbsam, keystr, data, flag) != TDB_SUCCESS ) { DEBUG(0, ("Unable to modify passwd TDB!")); DEBUGADD(0, (" Error: %s", tdb_errorstr(tdbsam))); DEBUGADD(0, (" occured while storing the main record (%s)\n", @@ -1287,7 +1273,7 @@ done: ****************************************************************************/ static BOOL tdb_update_ridrec_only( struct samu* newpwd, int flag ) { - TDB_DATA key, data; + TDB_DATA data; fstring keystr; fstring name; @@ -1295,16 +1281,13 @@ static BOOL tdb_update_ridrec_only( struct samu* newpwd, int flag ) strlower_m(name); /* setup RID data */ - data.dsize = strlen(name) + 1; - data.dptr = name; + data = string_term_tdb_data(name); /* setup the RID index key */ slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); - key.dptr = keystr; - key.dsize = strlen (keystr) + 1; /* add the reference */ - if (tdb_store(tdbsam, key, data, flag) != TDB_SUCCESS) { + if (tdb_store_bystring(tdbsam, keystr, data, flag) != TDB_SUCCESS) { DEBUG(0, ("Unable to modify TDB passwd !")); DEBUGADD(0, (" Error: %s\n", tdb_errorstr(tdbsam))); DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr)); -- cgit From bc2b6436d0f5f3e9ffdfaeb7f1b32996a83d5478 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Mar 2007 09:35:51 +0000 Subject: r22009: change TDB_DATA from char * to unsigned char * and fix all compiler warnings in the users metze (This used to be commit 3a28443079c141a6ce8182c65b56ca210e34f37f) --- source3/passdb/pdb_tdb.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 37ee19028a..2cb92e542f 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -115,7 +115,7 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf /* TDB_FORMAT_STRING_V0 "ddddddBBBBBBBBBBBBddBBwdwdBwwd" */ /* unpack the buffer into variables */ - len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING_V0, + len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING_V0, &logon_time, /* d */ &logoff_time, /* d */ &kickoff_time, /* d */ @@ -301,7 +301,7 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf /* TDB_FORMAT_STRING_V1 "dddddddBBBBBBBBBBBBddBBwdwdBwwd" */ /* unpack the buffer into variables */ - len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING_V1, + len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING_V1, &logon_time, /* d */ &logoff_time, /* d */ &kickoff_time, /* d */ @@ -493,7 +493,7 @@ BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) /* TDB_FORMAT_STRING_V2 "dddddddBBBBBBBBBBBBddBBBwwdBwwd" */ /* unpack the buffer into variables */ - len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING_V2, + len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING_V2, &logon_time, /* d */ &logoff_time, /* d */ &kickoff_time, /* d */ @@ -715,7 +715,7 @@ static BOOL tdbsam_convert(int32 from) while (key.dptr) { /* skip all non-USER entries (eg. RIDs) */ - while ((key.dsize != 0) && (strncmp(key.dptr, prefix, strlen (prefix)))) { + while ((key.dsize != 0) && (strncmp((const char *)key.dptr, prefix, strlen (prefix)))) { old_key = key; /* increment to next in line */ key = tdb_nextkey(tdbsam, key); @@ -768,7 +768,8 @@ static BOOL tdbsam_convert(int32 from) /* pack from the buffer into the new format */ - DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", key.dptr, from)); + DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", + (const char *)key.dptr, from)); data.dsize = init_buffer_from_sam (&buf, user, False); TALLOC_FREE(user ); @@ -776,7 +777,7 @@ static BOOL tdbsam_convert(int32 from) DEBUG(0,("tdbsam_convert: cannot pack the struct samu into the new format\n")); return False; } - data.dptr = (char *)buf; + data.dptr = buf; /* Store the buffer inside the TDBSAM */ if (tdb_store(tdbsam, key, data, TDB_MODIFY) != TDB_SUCCESS) { @@ -901,7 +902,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, int prefixlen = strlen (prefix); struct pwent_list *ptr; - if ( strncmp(key.dptr, prefix, prefixlen) == 0 ) { + if ( strncmp((const char *)key.dptr, prefix, prefixlen) == 0 ) { if ( !(ptr=SMB_MALLOC_P(struct pwent_list)) ) { DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n")); @@ -912,7 +913,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, /* save a copy of the key */ - ptr->key.dptr = (char *)memdup( key.dptr, key.dsize ); + ptr->key.dptr = (uint8 *)memdup( key.dptr, key.dsize ); if (!ptr->key.dptr) { DEBUG(0,("tdbsam_traverse_setpwent: memdup failed\n")); /* just return 0 and let the traversal continue */ @@ -1061,7 +1062,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu /* unpack the buffer */ - if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) { + if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n")); SAFE_FREE(data.dptr); tdbsam_close(); @@ -1113,7 +1114,7 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu goto done; } - fstrcpy(name, data.dptr); + fstrcpy(name, (const char *)data.dptr); SAFE_FREE(data.dptr); nt_status = tdbsam_getsampwnam (my_methods, user, name); @@ -1237,7 +1238,7 @@ static BOOL tdb_update_samacct_only( struct samu* newpwd, int flag ) ret = False; goto done; } - data.dptr = (char *)buf; + data.dptr = buf; fstrcpy(name, pdb_get_username(newpwd)); strlower_m(name); -- cgit From b1ce226af8b61ad7e3c37860a59c6715012e738b Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 15 Jun 2007 21:58:49 +0000 Subject: r23510: Tidy calls to smb_panic by removing trailing newlines. Print the failed expression in SMB_ASSERT. (This used to be commit 171dc060e2a576d724eed1ca65636bdafffd7713) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 2cb92e542f..094479774b 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1568,7 +1568,7 @@ static BOOL tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) done: if ((tdb != NULL) && (tdb_close(tdb) != 0)) { - smb_panic("tdb_close(idmap_tdb) failed\n"); + smb_panic("tdb_close(idmap_tdb) failed"); } return ret; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 094479774b..53f6fd7d98 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -10,7 +10,7 @@ * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * Software Foundation; either version 3 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/passdb/pdb_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 53f6fd7d98..ec5ed4d89a 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -19,8 +19,7 @@ * more details. * * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 675 - * Mass Ave, Cambridge, MA 02139, USA. + * this program; if not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/passdb/pdb_tdb.c | 50 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index ec5ed4d89a..530660f48c 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -49,7 +49,7 @@ struct pwent_list { TDB_DATA key; }; static struct pwent_list *tdbsam_pwent_list; -static BOOL pwent_initialized; +static bool pwent_initialized; /* GLOBAL TDB SAM CONTEXT */ @@ -68,7 +68,7 @@ static pstring tdbsam_filename; /********************************************************************* *********************************************************************/ -static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buflen) +static bool init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buflen) { /* times are stored as 32bit integer @@ -104,7 +104,7 @@ static BOOL init_sam_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buf uint8 *lm_pw_ptr = NULL, *nt_pw_ptr = NULL; uint32 len = 0; uint32 lm_pw_len, nt_pw_len, hourslen; - BOOL ret = True; + bool ret = True; if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer_v0: NULL parameters found!\n")); @@ -253,7 +253,7 @@ done: /********************************************************************* *********************************************************************/ -static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buflen) +static bool init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buflen) { /* times are stored as 32bit integer @@ -290,7 +290,7 @@ static BOOL init_sam_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buf uint8 *lm_pw_ptr = NULL, *nt_pw_ptr = NULL; uint32 len = 0; uint32 lm_pw_len, nt_pw_len, hourslen; - BOOL ret = True; + bool ret = True; if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer_v1: NULL parameters found!\n")); @@ -442,7 +442,7 @@ done: return ret; } -BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) +bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) { /* times are stored as 32bit integer @@ -480,9 +480,9 @@ BOOL init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) uint32 len = 0; uint32 lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen; uint32 pwHistLen = 0; - BOOL ret = True; + bool ret = True; fstring tmpstring; - BOOL expand_explicit = lp_passdb_expand_explicit(); + bool expand_explicit = lp_passdb_expand_explicit(); if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n")); @@ -679,7 +679,7 @@ done: Intialize a struct samu struct from a BYTE buffer of size len *********************************************************************/ -static BOOL init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen) +static bool init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen) { return init_sam_from_buffer_v3(sampass, buf, buflen); } @@ -688,7 +688,7 @@ static BOOL init_sam_from_buffer(struct samu *sampass, uint8 *buf, uint32 buflen Intialize a BYTE buffer from a struct samu struct *********************************************************************/ -static uint32 init_buffer_from_sam (uint8 **buf, struct samu *sampass, BOOL size_only) +static uint32 init_buffer_from_sam (uint8 **buf, struct samu *sampass, bool size_only) { return init_buffer_from_sam_v3(buf, sampass, size_only); } @@ -697,13 +697,13 @@ static uint32 init_buffer_from_sam (uint8 **buf, struct samu *sampass, BOOL size Intialize a BYTE buffer from a struct samu struct *********************************************************************/ -static BOOL tdbsam_convert(int32 from) +static bool tdbsam_convert(int32 from) { const char *vstring = TDBSAM_VERSION_STRING; const char *prefix = USERPREFIX; TDB_DATA data, key, old_key; uint8 *buf = NULL; - BOOL ret; + bool ret; /* handle a Samba upgrade */ tdb_lock_bystring(tdbsam, vstring); @@ -808,7 +808,7 @@ static BOOL tdbsam_convert(int32 from) Uses a reference count to allow multiple open calls. *********************************************************************/ -static BOOL tdbsam_open( const char *name ) +static bool tdbsam_open( const char *name ) { int32 version; @@ -934,7 +934,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, Save a list of user keys for iteration. ****************************************************************/ -static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update, uint32 acb_mask) +static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, bool update, uint32 acb_mask) { if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); @@ -1136,7 +1136,7 @@ static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, struct samu * return tdbsam_getsampwrid(my_methods, user, rid); } -static BOOL tdb_delete_samacct_only( struct samu *sam_pass ) +static bool tdb_delete_samacct_only( struct samu *sam_pass ) { fstring keystr; fstring name; @@ -1222,13 +1222,13 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct Update the TDB SAM account record only Assumes that the tdbsam is already open ****************************************************************************/ -static BOOL tdb_update_samacct_only( struct samu* newpwd, int flag ) +static bool tdb_update_samacct_only( struct samu* newpwd, int flag ) { TDB_DATA data; uint8 *buf = NULL; fstring keystr; fstring name; - BOOL ret = True; + bool ret = True; /* copy the struct samu struct into a BYTE buffer for storage */ @@ -1271,7 +1271,7 @@ done: Update the TDB SAM RID record only Assumes that the tdbsam is already open ****************************************************************************/ -static BOOL tdb_update_ridrec_only( struct samu* newpwd, int flag ) +static bool tdb_update_ridrec_only( struct samu* newpwd, int flag ) { TDB_DATA data; fstring keystr; @@ -1302,9 +1302,9 @@ static BOOL tdb_update_ridrec_only( struct samu* newpwd, int flag ) Update the TDB SAM ****************************************************************************/ -static BOOL tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, int flag) +static bool tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, int flag) { - BOOL result = True; + bool result = True; /* invalidate the existing TDB iterator if it is open */ @@ -1380,7 +1380,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, { struct samu *new_acct = NULL; pstring rename_script; - BOOL interim_account = False; + bool interim_account = False; int rename_ret; fstring oldname_lower; fstring newname_lower; @@ -1482,7 +1482,7 @@ done: return NT_STATUS_ACCESS_DENIED; } -static BOOL tdbsam_rid_algorithm(struct pdb_methods *methods) +static bool tdbsam_rid_algorithm(struct pdb_methods *methods) { return False; } @@ -1503,7 +1503,7 @@ static BOOL tdbsam_rid_algorithm(struct pdb_methods *methods) interested in the RID counter. *****************************************************************************/ -static BOOL init_idmap_tdb(TDB_CONTEXT *tdb) +static bool init_idmap_tdb(TDB_CONTEXT *tdb) { int32 version; @@ -1536,11 +1536,11 @@ static BOOL init_idmap_tdb(TDB_CONTEXT *tdb) return True; } -static BOOL tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) +static bool tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) { TDB_CONTEXT *tdb; uint32 rid; - BOOL ret = False; + bool ret = False; tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644); -- cgit From 88ee61625a5de5e443d14c54eab91a90d87cda85 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Thu, 1 Nov 2007 15:53:44 -0400 Subject: Patch 2 of 3 from Debian Samba packagers: The point is doing the following associations: - non discardable state data (all TDB files that may need to be backed up) go to statedir - shared data (codepage stuff) go to codepagedir The patch *does not change* the default location for these directories. So, there is no behaviour change when applying it. The main change is for samba developers who have to think when dealing with files that previously pertained to libdir whether they: - go in statedir - go in codepagedir - stay in libdir (This used to be commit d6cdbfd875bb2653e831d314726c3240beb0a96b) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 530660f48c..79427a587c 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1542,7 +1542,7 @@ static bool tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) uint32 rid; bool ret = False; - tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, + tdb = tdb_open_log(state_path("winbindd_idmap.tdb"), 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644); if (tdb == NULL) { @@ -1606,7 +1606,7 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc /* save the path for later */ if ( !location ) { - pstr_sprintf( tdbfile, "%s/%s", lp_private_dir(), PASSDB_FILE_NAME ); + pstr_sprintf( tdbfile, "%s/%s", dyn_STATEDIR(), PASSDB_FILE_NAME ); pfile = tdbfile; } pstrcpy( tdbsam_filename, pfile ); -- cgit From 33d83175715d2179588c774259fd707c6daea2f9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 4 Nov 2007 18:15:37 +0100 Subject: static pstring removal (This used to be commit 5490e2d77233f594a42cb32eda8215014db544e3) --- source3/passdb/pdb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 79427a587c..099b443072 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -55,7 +55,7 @@ static bool pwent_initialized; static TDB_CONTEXT *tdbsam; static int ref_count = 0; -static pstring tdbsam_filename; +static char *tdbsam_filename; /********************************************************************** Marshall/unmarshall struct samu structs. @@ -1609,7 +1609,7 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc pstr_sprintf( tdbfile, "%s/%s", dyn_STATEDIR(), PASSDB_FILE_NAME ); pfile = tdbfile; } - pstrcpy( tdbsam_filename, pfile ); + tdbsam_filename = SMB_STRDUP(pfile); /* no private data */ -- cgit From 66298d808034bb606478ff66aa156bda4e7e3f2a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Nov 2007 17:18:16 -0800 Subject: More pstring elimination. Jeremy. (This used to be commit 15074de938539e7a9c527d9a6d81792adc2ac3d0) --- source3/passdb/pdb_tdb.c | 109 +++++++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 42 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 099b443072..fe8497c939 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -481,7 +481,7 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) uint32 lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen; uint32 pwHistLen = 0; bool ret = True; - fstring tmpstring; + fstring tmp_string; bool expand_explicit = lp_passdb_expand_explicit(); if(sampass == NULL || buf == NULL) { @@ -546,12 +546,12 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) pdb_set_fullname(sampass, fullname, PDB_SET); if (homedir) { - fstrcpy( tmpstring, homedir ); + fstrcpy( tmp_string, homedir ); if (expand_explicit) { - standard_sub_basic( username, domain, tmpstring, - sizeof(tmpstring) ); + standard_sub_basic( username, domain, tmp_string, + sizeof(tmp_string) ); } - pdb_set_homedir(sampass, tmpstring, PDB_SET); + pdb_set_homedir(sampass, tmp_string, PDB_SET); } else { pdb_set_homedir(sampass, @@ -566,12 +566,12 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) pdb_set_dir_drive(sampass, lp_logon_drive(), PDB_DEFAULT ); if (logon_script) { - fstrcpy( tmpstring, logon_script ); + fstrcpy( tmp_string, logon_script ); if (expand_explicit) { - standard_sub_basic( username, domain, tmpstring, - sizeof(tmpstring) ); + standard_sub_basic( username, domain, tmp_string, + sizeof(tmp_string) ); } - pdb_set_logon_script(sampass, tmpstring, PDB_SET); + pdb_set_logon_script(sampass, tmp_string, PDB_SET); } else { pdb_set_logon_script(sampass, @@ -581,12 +581,12 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen) } if (profile_path) { - fstrcpy( tmpstring, profile_path ); + fstrcpy( tmp_string, profile_path ); if (expand_explicit) { - standard_sub_basic( username, domain, tmpstring, - sizeof(tmpstring) ); + standard_sub_basic( username, domain, tmp_string, + sizeof(tmp_string) ); } - pdb_set_profile_path(sampass, tmpstring, PDB_SET); + pdb_set_profile_path(sampass, tmp_string, PDB_SET); } else { pdb_set_profile_path(sampass, @@ -1375,40 +1375,43 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, struct s - unlock the new user record ***************************************************************************/ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, - struct samu *old_acct, + struct samu *old_acct, const char *newname) { + TALLOC_CTX *ctx = talloc_tos(); struct samu *new_acct = NULL; - pstring rename_script; + char *rename_script = NULL; bool interim_account = False; int rename_ret; fstring oldname_lower; fstring newname_lower; /* can't do anything without an external script */ - - pstrcpy(rename_script, lp_renameuser_script() ); - if ( ! *rename_script ) { + + rename_script = talloc_strdup(ctx, lp_renameuser_script()); + if (!rename_script) { + return NT_STATUS_NO_MEMORY; + } + if (!*rename_script) { return NT_STATUS_ACCESS_DENIED; } /* invalidate the existing TDB iterator if it is open */ - + tdbsam_endsampwent( my_methods ); if ( !(new_acct = samu_new( NULL )) ) { return NT_STATUS_NO_MEMORY; } - - if ( !pdb_copy_sam_account(new_acct, old_acct) - || !pdb_set_username(new_acct, newname, PDB_CHANGED)) + + if ( !pdb_copy_sam_account(new_acct, old_acct) + || !pdb_set_username(new_acct, newname, PDB_CHANGED)) { TALLOC_FREE(new_acct ); return NT_STATUS_NO_MEMORY; } /* open the database */ - if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); TALLOC_FREE(new_acct ); @@ -1416,11 +1419,10 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, } /* add the new account and lock it */ - if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) { goto done; } - + interim_account = True; if ( tdb_lock_bystring_with_timeout(tdbsam, newname, 30) == -1 ) { @@ -1436,24 +1438,41 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, fstrcpy( newname_lower, newname ); strlower_m( newname_lower ); - string_sub2(rename_script, "%unew", newname_lower, sizeof(pstring), - True, False, True); - string_sub2(rename_script, "%uold", oldname_lower, sizeof(pstring), - True, False, True); + rename_script = talloc_string_sub2(ctx, + rename_script, + "%unew", + newname_lower, + true, + false, + true); + if (!rename_script) { + goto done; + } + rename_script = talloc_string_sub2(ctx, + rename_script, + "%uold", + oldname_lower, + true, + false, + true); + if (!rename_script) { + goto done; + } rename_ret = smbrun(rename_script, NULL); - DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); + DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", + rename_script, rename_ret)); if (rename_ret == 0) { smb_nscd_flush_user_cache(); } if (rename_ret) { - goto done; + goto done; } /* rewrite the rid->username record */ - + if ( !tdb_update_ridrec_only( new_acct, TDB_MODIFY) ) { goto done; } @@ -1461,21 +1480,21 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, tdb_unlock_bystring( tdbsam, newname ); tdb_delete_samacct_only( old_acct ); - + tdbsam_close(); - + TALLOC_FREE(new_acct ); return NT_STATUS_OK; -done: +done: /* cleanup */ if (interim_account) { tdb_unlock_bystring(tdbsam, newname); tdb_delete_samacct_only(new_acct); } - + tdbsam_close(); - + if (new_acct) TALLOC_FREE(new_acct); @@ -1581,7 +1600,7 @@ static bool tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *location) { NTSTATUS nt_status; - pstring tdbfile; + char *tdbfile = NULL; const char *pfile = location; if (!NT_STATUS_IS_OK(nt_status = make_pdb_method( pdb_method ))) { @@ -1604,15 +1623,21 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc (*pdb_method)->new_rid = tdbsam_new_rid; /* save the path for later */ - - if ( !location ) { - pstr_sprintf( tdbfile, "%s/%s", dyn_STATEDIR(), PASSDB_FILE_NAME ); + + if (!location) { + if (asprintf(&tdbfile, "%s/%s", dyn_STATEDIR(), PASSDB_FILE_NAME) < 0) { + return NT_STATUS_NO_MEMORY; + } pfile = tdbfile; } tdbsam_filename = SMB_STRDUP(pfile); + if (!tdbsam_filename) { + return NT_STATUS_NO_MEMORY; + } + SAFE_FREE(tdbfile); /* no private data */ - + (*pdb_method)->private_data = NULL; (*pdb_method)->free_private_data = NULL; -- cgit From 7faee02d0d351c5c039e8f1be7e82ce3a93cbe96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 11:30:37 -0800 Subject: Remove the char[1024] strings from dynconfig. Replace them with malloc'ing accessor functions. Should save a lot of static space :-). Jeremy. (This used to be commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index fe8497c939..b4282b1278 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1625,7 +1625,7 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc /* save the path for later */ if (!location) { - if (asprintf(&tdbfile, "%s/%s", dyn_STATEDIR(), PASSDB_FILE_NAME) < 0) { + if (asprintf(&tdbfile, "%s/%s", get_dyn_STATEDIR(), PASSDB_FILE_NAME) < 0) { return NT_STATUS_NO_MEMORY; } pfile = tdbfile; -- cgit From 533c7c81fe9c5ca9f8936e1e6f2eb7502cbd653f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 24 Dec 2007 12:58:40 +0100 Subject: Add tdbsam_search_users (This used to be commit 02f0b0bd393bd942fc934f251bd6afed8e5424b0) --- source3/passdb/pdb_tdb.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b4282b1278..1c2278ba7d 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1592,6 +1592,139 @@ static bool tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid) return ret; } +struct tdbsam_search_state { + struct pdb_methods *methods; + uint32_t acct_flags; + + uint32_t *rids; + uint32_t num_rids; + ssize_t array_size; + uint32_t current; +}; + +static int tdbsam_collect_rids(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, + void *private_data) +{ + struct tdbsam_search_state *state = talloc_get_type_abort( + private_data, struct tdbsam_search_state); + size_t prefixlen = strlen(RIDPREFIX); + uint32 rid; + + if ((key.dsize < prefixlen) + || (strncmp((char *)key.dptr, RIDPREFIX, prefixlen))) { + return 0; + } + + rid = strtoul((char *)key.dptr+prefixlen, NULL, 16); + + ADD_TO_LARGE_ARRAY(state, uint32, rid, &state->rids, &state->num_rids, + &state->array_size); + + return 0; +} + +static void tdbsam_search_end(struct pdb_search *search) +{ + struct tdbsam_search_state *state = talloc_get_type_abort( + search->private_data, struct tdbsam_search_state); + TALLOC_FREE(state); +} + +static bool tdbsam_search_next_entry(struct pdb_search *search, + struct samr_displayentry *entry) +{ + struct tdbsam_search_state *state = talloc_get_type_abort( + search->private_data, struct tdbsam_search_state); + struct samu *user = NULL; + NTSTATUS status; + uint32_t rid; + + again: + TALLOC_FREE(user); + user = samu_new(talloc_tos()); + if (user == NULL) { + DEBUG(0, ("samu_new failed\n")); + return false; + } + + if (state->current == state->num_rids) { + return false; + } + + rid = state->rids[state->current++]; + + status = tdbsam_getsampwrid(state->methods, user, rid); + + if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) { + /* + * Someone has deleted that user since we listed the RIDs + */ + goto again; + } + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("tdbsam_getsampwrid failed: %s\n", + nt_errstr(status))); + TALLOC_FREE(user); + return false; + } + + if ((state->acct_flags != 0) && + ((state->acct_flags & pdb_get_acct_ctrl(user)) == 0)) { + goto again; + } + + entry->acct_flags = pdb_get_acct_ctrl(user); + entry->rid = rid; + entry->account_name = talloc_strdup( + search->mem_ctx, pdb_get_username(user)); + entry->fullname = talloc_strdup( + search->mem_ctx, pdb_get_fullname(user)); + entry->description = talloc_strdup( + search->mem_ctx, pdb_get_acct_desc(user)); + + TALLOC_FREE(user); + + if ((entry->account_name == NULL) || (entry->fullname == NULL) + || (entry->description == NULL)) { + DEBUG(0, ("talloc_strdup failed\n")); + return false; + } + + return true; +} + +static bool tdbsam_search_users(struct pdb_methods *methods, + struct pdb_search *search, + uint32 acct_flags) +{ + struct tdbsam_search_state *state; + + if (!tdbsam_open(tdbsam_filename)) { + DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", + tdbsam_filename)); + return false; + } + + state = TALLOC_ZERO_P(search->mem_ctx, struct tdbsam_search_state); + if (state == NULL) { + DEBUG(0, ("talloc failed\n")); + return false; + } + state->acct_flags = acct_flags; + state->methods = methods; + + tdb_traverse(tdbsam, tdbsam_collect_rids, state); + + tdbsam_close(); + + search->private_data = state; + search->next_entry = tdbsam_search_next_entry; + search->search_end = tdbsam_search_end; + + return true; +} + /********************************************************************* Initialize the tdb sam backend. Setup the dispath table of methods, open the tdb, etc... @@ -1618,6 +1751,7 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; (*pdb_method)->rename_sam_account = tdbsam_rename_sam_account; + (*pdb_method)->search_users = tdbsam_search_users; (*pdb_method)->rid_algorithm = tdbsam_rid_algorithm; (*pdb_method)->new_rid = tdbsam_new_rid; -- cgit From e70c97ef85b309d6e005c07e16a003725d21ffc8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 26 Dec 2007 17:58:55 +0100 Subject: Remove the sampwent interface (This used to be commit 9e80b969fb40766de2c9b1a05d16bf4d4c6e46f7) --- source3/passdb/pdb_tdb.c | 146 ----------------------------------------------- 1 file changed, 146 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1c2278ba7d..1277b9c395 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -44,13 +44,6 @@ static int tdbsam_debug_level = DBGC_ALL; #define RIDPREFIX "RID_" #define PRIVPREFIX "PRIV_" -struct pwent_list { - struct pwent_list *prev, *next; - TDB_DATA key; -}; -static struct pwent_list *tdbsam_pwent_list; -static bool pwent_initialized; - /* GLOBAL TDB SAM CONTEXT */ static TDB_CONTEXT *tdbsam; @@ -891,134 +884,6 @@ void tdbsam_close( void ) return; } -/**************************************************************************** - creates a list of user keys -****************************************************************************/ - -static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *state) -{ - const char *prefix = USERPREFIX; - int prefixlen = strlen (prefix); - struct pwent_list *ptr; - - if ( strncmp((const char *)key.dptr, prefix, prefixlen) == 0 ) { - if ( !(ptr=SMB_MALLOC_P(struct pwent_list)) ) { - DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n")); - - /* just return 0 and let the traversal continue */ - return 0; - } - ZERO_STRUCTP(ptr); - - /* save a copy of the key */ - - ptr->key.dptr = (uint8 *)memdup( key.dptr, key.dsize ); - if (!ptr->key.dptr) { - DEBUG(0,("tdbsam_traverse_setpwent: memdup failed\n")); - /* just return 0 and let the traversal continue */ - SAFE_FREE(ptr); - return 0; - } - - ptr->key.dsize = key.dsize; - - DLIST_ADD( tdbsam_pwent_list, ptr ); - - } - - return 0; -} - -/*************************************************************** - Open the TDB passwd database for SAM account enumeration. - Save a list of user keys for iteration. -****************************************************************/ - -static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, bool update, uint32 acb_mask) -{ - if ( !tdbsam_open( tdbsam_filename ) ) { - DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); - return NT_STATUS_ACCESS_DENIED; - } - - tdb_traverse( tdbsam, tdbsam_traverse_setpwent, NULL ); - pwent_initialized = True; - - return NT_STATUS_OK; -} - - -/*************************************************************** - End enumeration of the TDB passwd list. -****************************************************************/ - -static void tdbsam_endsampwent(struct pdb_methods *my_methods) -{ - struct pwent_list *ptr, *ptr_next; - - /* close the tdb only if we have a valid pwent state */ - - if ( pwent_initialized ) { - DEBUG(7, ("endtdbpwent: closed sam database.\n")); - tdbsam_close(); - } - - /* clear out any remaining entries in the list */ - - for ( ptr=tdbsam_pwent_list; ptr; ptr = ptr_next ) { - ptr_next = ptr->next; - DLIST_REMOVE( tdbsam_pwent_list, ptr ); - SAFE_FREE( ptr->key.dptr); - SAFE_FREE( ptr ); - } - - pwent_initialized = False; -} - -/***************************************************************** - Get one struct samu from the TDB (next in line) -*****************************************************************/ - -static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, struct samu *user) -{ - NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - TDB_DATA data; - struct pwent_list *pkey; - - if ( !user ) { - DEBUG(0,("tdbsam_getsampwent: struct samu is NULL.\n")); - return nt_status; - } - - if ( !tdbsam_pwent_list ) { - DEBUG(4,("tdbsam_getsampwent: end of list\n")); - return nt_status; - } - - /* pull the next entry */ - - pkey = tdbsam_pwent_list; - DLIST_REMOVE( tdbsam_pwent_list, pkey ); - - data = tdb_fetch(tdbsam, pkey->key); - - SAFE_FREE( pkey->key.dptr); - SAFE_FREE( pkey); - - if ( !data.dptr ) { - DEBUG(5,("pdb_getsampwent: database entry not found. Was the user deleted?\n")); - return nt_status; - } - - if ( !init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize) ) { - DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n")); - } - - SAFE_FREE( data.dptr ); - - return NT_STATUS_OK; -} - /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ @@ -1306,10 +1171,6 @@ static bool tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, { bool result = True; - /* invalidate the existing TDB iterator if it is open */ - - tdbsam_endsampwent( my_methods ); - #if 0 if ( !pdb_get_group_rid(newpwd) ) { DEBUG (0,("tdb_update_sam: Failing to store a struct samu for [%s] " @@ -1396,10 +1257,6 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, return NT_STATUS_ACCESS_DENIED; } - /* invalidate the existing TDB iterator if it is open */ - - tdbsam_endsampwent( my_methods ); - if ( !(new_acct = samu_new( NULL )) ) { return NT_STATUS_NO_MEMORY; } @@ -1742,9 +1599,6 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc (*pdb_method)->name = "tdbsam"; - (*pdb_method)->setsampwent = tdbsam_setsampwent; - (*pdb_method)->endsampwent = tdbsam_endsampwent; - (*pdb_method)->getsampwent = tdbsam_getsampwent; (*pdb_method)->getsampwnam = tdbsam_getsampwnam; (*pdb_method)->getsampwsid = tdbsam_getsampwsid; (*pdb_method)->add_sam_account = tdbsam_add_sam_account; -- cgit From 40bf6730aaca0409d17619c49e9eea59d68a6f10 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 24 Dec 2007 14:12:54 +0100 Subject: passdb.tdb is located in the private directory Jerry, as part of d6cdbfd87 the default location of passdb.tdb has changed from the private directory to the state directory. I think because passdb.tdb holds the password hashes, it is reasonable to keep this next to the smbpasswd file. Please review and potentially push. Thanks, Volker (This used to be commit c9c7607c402c0a9df9796c767b689d207d67d8e4) --- source3/passdb/pdb_tdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1277b9c395..5e21c46abf 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1613,7 +1613,8 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc /* save the path for later */ if (!location) { - if (asprintf(&tdbfile, "%s/%s", get_dyn_STATEDIR(), PASSDB_FILE_NAME) < 0) { + if (asprintf(&tdbfile, "%s/%s", get_dyn_PRIVATE_DIR(), + PASSDB_FILE_NAME) < 0) { return NT_STATUS_NO_MEMORY; } pfile = tdbfile; -- cgit From df450fc090071b3645ecede5d15685e68e209d99 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 30 Dec 2007 03:12:11 +0100 Subject: Make pdb_tdb honour a private dir overridden in smb.conf. One lp_private_dir() has to be used instead of get_dyn_PRIVATE_DIR() to determine the location of the passdb.tdb. I noticed this when running make test as a "normal user" from a build, where I had done "make install" as root before, and so the passdb.tdb could not be accessed during the startup phase "CREATE TEST ENVIRONMENT IN ./st ..." in selftest.sh. Michael (This used to be commit 1f96389afa7250af7393489fb538b8aed93d815c) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 5e21c46abf..5ee1cdc0c0 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1613,7 +1613,7 @@ static NTSTATUS pdb_init_tdbsam(struct pdb_methods **pdb_method, const char *loc /* save the path for later */ if (!location) { - if (asprintf(&tdbfile, "%s/%s", get_dyn_PRIVATE_DIR(), + if (asprintf(&tdbfile, "%s/%s", lp_private_dir(), PASSDB_FILE_NAME) < 0) { return NT_STATUS_NO_MEMORY; } -- cgit From aa8818bcc38dc3993bc41776ba29adb906c3dd66 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 12 Jan 2008 00:09:35 -0800 Subject: Fix CID 469. new_acct can't be NULL here. Jeremy. (This used to be commit c79e9414c4baed6e61fc6a3f766395b873bcc4ea) --- source3/passdb/pdb_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 5ee1cdc0c0..b05a42b32c 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1352,8 +1352,7 @@ done: tdbsam_close(); - if (new_acct) - TALLOC_FREE(new_acct); + TALLOC_FREE(new_acct); return NT_STATUS_ACCESS_DENIED; } -- cgit From 88ee949777fefbceb7a1fd6fb599f45b90a4018b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 14 Mar 2008 20:35:38 +0100 Subject: Convert pdb_tdb to use dbwrap (This used to be commit 948ab77863b12b1b0bd1c970004b84b9bb1bb2fa) --- source3/passdb/pdb_tdb.c | 634 +++++++++++++++++++++++------------------------ 1 file changed, 316 insertions(+), 318 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b05a42b32c..25aa6b4fb0 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -41,13 +41,13 @@ static int tdbsam_debug_level = DBGC_ALL; #define TDBSAM_VERSION_STRING "INFO/version" #define PASSDB_FILE_NAME "passdb.tdb" #define USERPREFIX "USER_" +#define USERPREFIX_LEN 5 #define RIDPREFIX "RID_" #define PRIVPREFIX "PRIV_" /* GLOBAL TDB SAM CONTEXT */ -static TDB_CONTEXT *tdbsam; -static int ref_count = 0; +static struct db_context *db_sam; static char *tdbsam_filename; /********************************************************************** @@ -690,110 +690,129 @@ static uint32 init_buffer_from_sam (uint8 **buf, struct samu *sampass, bool size Intialize a BYTE buffer from a struct samu struct *********************************************************************/ -static bool tdbsam_convert(int32 from) +struct tdbsam_convert_state { + int32_t from; + bool success; +}; + +static int tdbsam_convert_one(struct db_record *rec, void *priv) { - const char *vstring = TDBSAM_VERSION_STRING; - const char *prefix = USERPREFIX; - TDB_DATA data, key, old_key; - uint8 *buf = NULL; - bool ret; + struct tdbsam_convert_state *state = + (struct tdbsam_convert_state *)priv; + struct samu *user; + TDB_DATA data; + NTSTATUS status; + bool ret; - /* handle a Samba upgrade */ - tdb_lock_bystring(tdbsam, vstring); - - /* Enumerate all records and convert them */ - key = tdb_firstkey(tdbsam); + if (rec->key.dsize < USERPREFIX_LEN) { + return 0; + } + if (strncmp((char *)rec->key.dptr, USERPREFIX, USERPREFIX_LEN) != 0) { + return 0; + } - while (key.dptr) { - - /* skip all non-USER entries (eg. RIDs) */ - while ((key.dsize != 0) && (strncmp((const char *)key.dptr, prefix, strlen (prefix)))) { - old_key = key; - /* increment to next in line */ - key = tdb_nextkey(tdbsam, key); - SAFE_FREE(old_key.dptr); - } - - if (key.dptr) { - struct samu *user = NULL; - - /* read from tdbsam */ - data = tdb_fetch(tdbsam, key); - if (!data.dptr) { - DEBUG(0,("tdbsam_convert: database entry not found: %s.\n",key.dptr)); - return False; - } - - /* unpack the buffer from the former format */ - if ( !(user = samu_new( NULL )) ) { - DEBUG(0,("tdbsam_convert: samu_new() failed!\n")); - SAFE_FREE( data.dptr ); - return False; - } - DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) (version:%d)\n", key.dptr, from)); - switch (from) { - case 0: - ret = init_sam_from_buffer_v0(user, (uint8 *)data.dptr, data.dsize); - break; - case 1: - ret = init_sam_from_buffer_v1(user, (uint8 *)data.dptr, data.dsize); - break; - case 2: - ret = init_sam_from_buffer_v2(user, (uint8 *)data.dptr, data.dsize); - break; - case 3: - ret = init_sam_from_buffer_v3(user, (uint8 *)data.dptr, data.dsize); - break; - default: - /* unknown tdbsam version */ - ret = False; - } - if (!ret) { - DEBUG(0,("tdbsam_convert: Bad struct samu entry returned from TDB (key:%s) (version:%d)\n", key.dptr, from)); - SAFE_FREE(data.dptr); - TALLOC_FREE(user ); - return False; - } - - /* We're finished with the old data. */ - SAFE_FREE(data.dptr); - - /* pack from the buffer into the new format */ - - DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", - (const char *)key.dptr, from)); - data.dsize = init_buffer_from_sam (&buf, user, False); - TALLOC_FREE(user ); - - if ( data.dsize == -1 ) { - DEBUG(0,("tdbsam_convert: cannot pack the struct samu into the new format\n")); - return False; - } - data.dptr = buf; - - /* Store the buffer inside the TDBSAM */ - if (tdb_store(tdbsam, key, data, TDB_MODIFY) != TDB_SUCCESS) { - DEBUG(0,("tdbsam_convert: cannot store the struct samu (key:%s) in new format\n",key.dptr)); - SAFE_FREE(data.dptr); - return False; - } - - SAFE_FREE(data.dptr); - - /* increment to next in line */ - old_key = key; - key = tdb_nextkey(tdbsam, key); - SAFE_FREE(old_key.dptr); - } - + user = samu_new(talloc_tos()); + if (user == NULL) { + DEBUG(0,("tdbsam_convert: samu_new() failed!\n")); + state->success = false; + return -1; + } + + DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) " + "(version:%d)\n", rec->key.dptr, state->from)); + + switch (state->from) { + case 0: + ret = init_sam_from_buffer_v0(user, (uint8 *)rec->value.dptr, + rec->value.dsize); + break; + case 1: + ret = init_sam_from_buffer_v1(user, (uint8 *)rec->value.dptr, + rec->value.dsize); + break; + case 2: + ret = init_sam_from_buffer_v2(user, (uint8 *)rec->value.dptr, + rec->value.dsize); + break; + case 3: + ret = init_sam_from_buffer_v3(user, (uint8 *)rec->value.dptr, + rec->value.dsize); + break; + default: + /* unknown tdbsam version */ + ret = False; + } + if (!ret) { + DEBUG(0,("tdbsam_convert: Bad struct samu entry returned " + "from TDB (key:%s) (version:%d)\n", rec->key.dptr, + state->from)); + TALLOC_FREE(user); + state->success = false; + return -1; } - - /* upgrade finished */ - tdb_store_int32(tdbsam, vstring, TDBSAM_VERSION); - tdb_unlock_bystring(tdbsam, vstring); + data.dsize = init_buffer_from_sam(&data.dptr, user, false); + TALLOC_FREE(user); + + if (data.dsize == -1) { + DEBUG(0,("tdbsam_convert: cannot pack the struct samu into " + "the new format\n")); + state->success = false; + return -1; + } + + status = rec->store(rec, data, TDB_MODIFY); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("Could not store the new record: %s\n", + nt_errstr(status))); + state->success = false; + return -1; + } + + return 0; +} + +static bool tdbsam_convert(struct db_context *db, int32 from) +{ + struct tdbsam_convert_state state; + + state.from = from; + state.success = true; + + if (db->transaction_start(db) != 0) { + DEBUG(0, ("Could not start transaction\n")); + return false; + } + + if (db->traverse(db, tdbsam_convert_one, &state) != 0) { + DEBUG(0, ("traverse failed\n")); + goto cancel; + } - return(True); + if (!state.success) { + DEBUG(0, ("Converting records failed\n")); + goto cancel; + } + + if (dbwrap_store_int32(db, TDBSAM_VERSION_STRING, + TDBSAM_VERSION) != 0) { + DEBUG(0, ("Could not store tdbsam version\n")); + goto cancel; + } + + if (db->transaction_commit(db) != 0) { + DEBUG(0, ("Could not commit transaction\n")); + goto cancel; + } + + return true; + + cancel: + if (db->transaction_cancel(db) != 0) { + smb_panic("transaction_cancel failed"); + } + + return false; } /********************************************************************* @@ -804,91 +823,61 @@ static bool tdbsam_convert(int32 from) static bool tdbsam_open( const char *name ) { int32 version; - + /* check if we are already open */ - - if ( tdbsam ) { - ref_count++; - DEBUG(8,("tdbsam_open: Incrementing open reference count. Ref count is now %d\n", - ref_count)); - return True; - } - - SMB_ASSERT( ref_count == 0 ); - - /* Try to open tdb passwd. Create a new one if necessary */ - - if (!(tdbsam = tdb_open_log(name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600))) { - DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd [%s]\n", name)); - return False; + + if ( db_sam ) { + return true; } - /* set the initial reference count - must be done before tdbsam_convert - as that calls tdbsam_open()/tdbsam_close(). */ + /* Try to open tdb passwd. Create a new one if necessary */ - ref_count = 1; + db_sam = db_open(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600); + if (db_sam == NULL) { + DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd " + "[%s]\n", name)); + return false; + } /* Check the version */ - version = tdb_fetch_int32( tdbsam, TDBSAM_VERSION_STRING ); - + version = dbwrap_fetch_int32(db_sam, TDBSAM_VERSION_STRING); if (version == -1) { version = 0; /* Version not found, assume version 0 */ } - + /* Compare the version */ if (version > TDBSAM_VERSION) { - /* Version more recent than the latest known */ + /* Version more recent than the latest known */ DEBUG(0, ("tdbsam_open: unknown version => %d\n", version)); - tdb_close( tdbsam ); - ref_count = 0; - return False; - } - - - if ( version < TDBSAM_VERSION ) { - DEBUG(1, ("tdbsam_open: Converting version %d database to version %d.\n", - version, TDBSAM_VERSION)); - - if ( !tdbsam_convert(version) ) { - DEBUG(0, ("tdbsam_open: Error when trying to convert tdbsam [%s]\n",name)); - tdb_close(tdbsam); - ref_count = 0; - return False; - } - - DEBUG(3, ("TDBSAM converted successfully.\n")); + TALLOC_FREE(db_sam); + return false; } - - DEBUG(4,("tdbsam_open: successfully opened %s\n", name )); - - return True; -} -/**************************************************************************** - wrapper atound tdb_close() to handle the reference count -****************************************************************************/ + if ( version < TDBSAM_VERSION ) { + DEBUG(1, ("tdbsam_open: Converting version %d database to " + "version %d.\n", version, TDBSAM_VERSION)); -void tdbsam_close( void ) -{ - ref_count--; - - DEBUG(8,("tdbsam_close: Reference count is now %d.\n", ref_count)); + if ( !tdbsam_convert(db_sam, version) ) { + DEBUG(0, ("tdbsam_open: Error when trying to convert " + "tdbsam [%s]\n",name)); + TALLOC_FREE(db_sam); + return false; + } - SMB_ASSERT(ref_count >= 0 ); - - if ( ref_count == 0 ) { - tdb_close( tdbsam ); - tdbsam = NULL; + DEBUG(3, ("TDBSAM converted successfully.\n")); } - - return; + + DEBUG(4,("tdbsam_open: successfully opened %s\n", name )); + + return true; } /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ -static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu *user, const char *sname) +static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, + struct samu *user, const char *sname) { TDB_DATA data; fstring keystr; @@ -907,37 +896,33 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); /* open the database */ - + if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); return NT_STATUS_ACCESS_DENIED; } - + /* get the record */ - - data = tdb_fetch_bystring(tdbsam, keystr); + + data = dbwrap_fetch_bystring(db_sam, talloc_tos(), keystr); if (!data.dptr) { DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); DEBUGADD(5, (" Key: %s\n", keystr)); - tdbsam_close(); return NT_STATUS_NO_SUCH_USER; } - + /* unpack the buffer */ - + if (!init_sam_from_buffer(user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n")); SAFE_FREE(data.dptr); - tdbsam_close(); return NT_STATUS_NO_MEMORY; } - + /* success */ - - SAFE_FREE(data.dptr); - tdbsam_close(); - + + TALLOC_FREE(data.dptr); + return NT_STATUS_OK; } @@ -945,7 +930,8 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, struct samu Search by rid **************************************************************************/ -static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu *user, uint32 rid) +static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, + struct samu *user, uint32 rid) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; TDB_DATA data; @@ -956,45 +942,37 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, struct samu DEBUG(0,("pdb_getsampwrid: struct samu is NULL.\n")); return nt_status; } - + /* set search key */ - + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); /* open the database */ - + if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); return NT_STATUS_ACCESS_DENIED; } /* get the record */ - - data = tdb_fetch_bystring (tdbsam, keystr); + + data = dbwrap_fetch_bystring(db_sam, talloc_tos(), keystr); if (!data.dptr) { DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr)); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); - nt_status = NT_STATUS_UNSUCCESSFUL; - goto done; + return NT_STATUS_UNSUCCESSFUL; } fstrcpy(name, (const char *)data.dptr); - SAFE_FREE(data.dptr); - - nt_status = tdbsam_getsampwnam (my_methods, user, name); + TALLOC_FREE(data.dptr); - done: - /* cleanup */ - - tdbsam_close(); - - return nt_status; + return tdbsam_getsampwnam (my_methods, user, name); } -static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, struct samu * user, const DOM_SID *sid) +static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods, + struct samu * user, const DOM_SID *sid) { uint32 rid; - + if ( !sid_peek_check_rid(get_global_sam_sid(), sid, &rid) ) return NT_STATUS_UNSUCCESSFUL; @@ -1005,38 +983,41 @@ static bool tdb_delete_samacct_only( struct samu *sam_pass ) { fstring keystr; fstring name; + NTSTATUS status; fstrcpy(name, pdb_get_username(sam_pass)); strlower_m(name); - + /* set the search key */ - + slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); - + /* it's outaa here! 8^) */ - - if (tdb_delete_bystring(tdbsam, keystr) != TDB_SUCCESS) { - DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); - return False; + + status = dbwrap_delete_bystring(db_sam, keystr); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(5, ("Error deleting entry from tdb passwd " + "database: %s!\n", nt_errstr(status))); + return false; } - - return True; + + return true; } /*************************************************************************** Delete a struct samu records for the username and RID key ****************************************************************************/ -static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct samu *sam_pass) +static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, + struct samu *sam_pass) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; fstring keystr; uint32 rid; fstring name; - + /* open the database */ - + if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_delete_sam_account: failed to open %s!\n", tdbsam_filename)); @@ -1045,40 +1026,52 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, struct fstrcpy(name, pdb_get_username(sam_pass)); strlower_m(name); - + /* set the search key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); - + rid = pdb_get_user_rid(sam_pass); /* it's outaa here! 8^) */ - if ( tdb_delete_bystring(tdbsam, keystr) != TDB_SUCCESS ) { - DEBUG(5, ("Error deleting entry from tdb passwd database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); - nt_status = NT_STATUS_UNSUCCESSFUL; - goto done; + if (db_sam->transaction_start(db_sam) != 0) { + DEBUG(0, ("Could not start transaction\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + nt_status = dbwrap_delete_bystring(db_sam, keystr); + if (!NT_STATUS_IS_OK(nt_status)) { + DEBUG(5, ("Error deleting entry from tdb passwd " + "database: %s!\n", nt_errstr(nt_status))); + goto cancel; } /* set the search key */ - + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid); /* it's outaa here! 8^) */ - - if ( tdb_delete_bystring(tdbsam, keystr) != TDB_SUCCESS ) { - DEBUG(5, ("Error deleting entry from tdb rid database!\n")); - DEBUGADD(5, (" Error: %s\n", tdb_errorstr(tdbsam))); - nt_status = NT_STATUS_UNSUCCESSFUL; - goto done; + + nt_status = dbwrap_delete_bystring(db_sam, keystr); + if (!NT_STATUS_IS_OK(nt_status)) { + DEBUG(5, ("Error deleting entry from tdb rid " + "database: %s!\n", nt_errstr(nt_status))); + goto cancel; + } + + if (db_sam->transaction_commit(db_sam) != 0) { + DEBUG(0, ("Could not commit transaction\n")); + goto cancel; + } + + return NT_STATUS_OK; + + cancel: + if (db_sam->transaction_cancel(db_sam) != 0) { + smb_panic("transaction_cancel failed"); } - nt_status = NT_STATUS_OK; - - done: - tdbsam_close(); - return nt_status; } @@ -1093,54 +1086,54 @@ static bool tdb_update_samacct_only( struct samu* newpwd, int flag ) uint8 *buf = NULL; fstring keystr; fstring name; - bool ret = True; + bool ret = false; + NTSTATUS status; /* copy the struct samu struct into a BYTE buffer for storage */ - + if ( (data.dsize=init_buffer_from_sam (&buf, newpwd, False)) == -1 ) { DEBUG(0,("tdb_update_sam: ERROR - Unable to copy struct samu info BYTE buffer!\n")); - ret = False; goto done; } data.dptr = buf; fstrcpy(name, pdb_get_username(newpwd)); strlower_m(name); - - DEBUG(5, ("Storing %saccount %s with RID %d\n", - flag == TDB_INSERT ? "(new) " : "", name, + + DEBUG(5, ("Storing %saccount %s with RID %d\n", + flag == TDB_INSERT ? "(new) " : "", name, pdb_get_user_rid(newpwd))); /* setup the USER index key */ slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name); /* add the account */ - - if ( tdb_store_bystring(tdbsam, keystr, data, flag) != TDB_SUCCESS ) { - DEBUG(0, ("Unable to modify passwd TDB!")); - DEBUGADD(0, (" Error: %s", tdb_errorstr(tdbsam))); - DEBUGADD(0, (" occured while storing the main record (%s)\n", - keystr)); - ret = False; + + status = dbwrap_store_bystring(db_sam, keystr, data, flag); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("Unable to modify passwd TDB: %s!", + nt_errstr(status))); goto done; } -done: + ret = true; + +done: /* cleanup */ SAFE_FREE(buf); - return ret; } /*************************************************************************** Update the TDB SAM RID record only - Assumes that the tdbsam is already open + Assumes that the tdbsam is already open ****************************************************************************/ static bool tdb_update_ridrec_only( struct samu* newpwd, int flag ) { TDB_DATA data; fstring keystr; fstring name; + NTSTATUS status; fstrcpy(name, pdb_get_username(newpwd)); strlower_m(name); @@ -1149,17 +1142,18 @@ static bool tdb_update_ridrec_only( struct samu* newpwd, int flag ) data = string_term_tdb_data(name); /* setup the RID index key */ - slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd)); - + slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, + pdb_get_user_rid(newpwd)); + /* add the reference */ - if (tdb_store_bystring(tdbsam, keystr, data, flag) != TDB_SUCCESS) { - DEBUG(0, ("Unable to modify TDB passwd !")); - DEBUGADD(0, (" Error: %s\n", tdb_errorstr(tdbsam))); - DEBUGADD(0, (" occured while storing the RID index (%s)\n", keystr)); - return False; + status = dbwrap_store_bystring(db_sam, keystr, data, flag); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("Unable to modify TDB passwd: %s!\n", + nt_errstr(status))); + return false; } - return True; + return true; } @@ -1167,39 +1161,44 @@ static bool tdb_update_ridrec_only( struct samu* newpwd, int flag ) Update the TDB SAM ****************************************************************************/ -static bool tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, int flag) +static bool tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, + int flag) { - bool result = True; - -#if 0 - if ( !pdb_get_group_rid(newpwd) ) { - DEBUG (0,("tdb_update_sam: Failing to store a struct samu for [%s] " - "without a primary group RID\n", pdb_get_username(newpwd))); - return False; - } -#endif - if (!pdb_get_user_rid(newpwd)) { - DEBUG(0,("tdb_update_sam: struct samu (%s) with no RID!\n", pdb_get_username(newpwd))); + DEBUG(0,("tdb_update_sam: struct samu (%s) with no RID!\n", + pdb_get_username(newpwd))); return False; } /* open the database */ - + if ( !tdbsam_open( tdbsam_filename ) ) { DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); return False; } - - if ( !tdb_update_samacct_only(newpwd, flag) || !tdb_update_ridrec_only(newpwd, flag)) { - result = False; + + if (db_sam->transaction_start(db_sam) != 0) { + DEBUG(0, ("Could not start transaction\n")); + return false; } - /* cleanup */ + if (!tdb_update_samacct_only(newpwd, flag) + || !tdb_update_ridrec_only(newpwd, flag)) { + goto cancel; + } - tdbsam_close(); - - return result; + if (db_sam->transaction_commit(db_sam) != 0) { + DEBUG(0, ("Could not commit transaction\n")); + goto cancel; + } + + return true; + + cancel: + if (db_sam->transaction_cancel(db_sam) != 0) { + smb_panic("transaction_cancel failed"); + } + return false; } /*************************************************************************** @@ -1239,51 +1238,53 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, struct samu *old_acct, const char *newname) { - TALLOC_CTX *ctx = talloc_tos(); struct samu *new_acct = NULL; char *rename_script = NULL; - bool interim_account = False; int rename_ret; fstring oldname_lower; fstring newname_lower; /* can't do anything without an external script */ - rename_script = talloc_strdup(ctx, lp_renameuser_script()); + if ( !(new_acct = samu_new( talloc_tos() )) ) { + return NT_STATUS_NO_MEMORY; + } + + rename_script = talloc_strdup(new_acct, lp_renameuser_script()); if (!rename_script) { + TALLOC_FREE(new_acct); return NT_STATUS_NO_MEMORY; } if (!*rename_script) { + TALLOC_FREE(new_acct); return NT_STATUS_ACCESS_DENIED; } - if ( !(new_acct = samu_new( NULL )) ) { - return NT_STATUS_NO_MEMORY; - } - if ( !pdb_copy_sam_account(new_acct, old_acct) || !pdb_set_username(new_acct, newname, PDB_CHANGED)) { - TALLOC_FREE(new_acct ); + TALLOC_FREE(new_acct); return NT_STATUS_NO_MEMORY; } /* open the database */ if ( !tdbsam_open( tdbsam_filename ) ) { - DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename)); - TALLOC_FREE(new_acct ); + DEBUG(0, ("tdbsam_getsampwnam: failed to open %s!\n", + tdbsam_filename)); + TALLOC_FREE(new_acct); return NT_STATUS_ACCESS_DENIED; } - /* add the new account and lock it */ - if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) { - goto done; - } + if (db_sam->transaction_start(db_sam) == -1) { + DEBUG(0, ("Could not start transaction\n")); + TALLOC_FREE(new_acct); + return NT_STATUS_ACCESS_DENIED; - interim_account = True; + } - if ( tdb_lock_bystring_with_timeout(tdbsam, newname, 30) == -1 ) { - goto done; + /* add the new account and lock it */ + if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) { + goto cancel; } /* Rename the posix user. Follow the semantics of _samr_create_user() @@ -1295,7 +1296,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, fstrcpy( newname_lower, newname ); strlower_m( newname_lower ); - rename_script = talloc_string_sub2(ctx, + rename_script = talloc_string_sub2(new_acct, rename_script, "%unew", newname_lower, @@ -1303,9 +1304,9 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, false, true); if (!rename_script) { - goto done; + goto cancel; } - rename_script = talloc_string_sub2(ctx, + rename_script = talloc_string_sub2(new_acct, rename_script, "%uold", oldname_lower, @@ -1313,47 +1314,47 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, false, true); if (!rename_script) { - goto done; + goto cancel; } rename_ret = smbrun(rename_script, NULL); DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret)); - if (rename_ret == 0) { - smb_nscd_flush_user_cache(); + if (rename_ret != 0) { + goto cancel; } - if (rename_ret) { - goto done; - } + smb_nscd_flush_user_cache(); /* rewrite the rid->username record */ if ( !tdb_update_ridrec_only( new_acct, TDB_MODIFY) ) { - goto done; + goto cancel; } - interim_account = False; - tdb_unlock_bystring( tdbsam, newname ); tdb_delete_samacct_only( old_acct ); - tdbsam_close(); + if (db_sam->transaction_commit(db_sam) == -1) { + /* + * Ok, we're screwed. We've changed the posix account, but + * could not adapt passdb.tdb. Shall we change the posix + * account back? + */ + DEBUG(0, ("transaction_commit failed\n")); + goto cancel; + } TALLOC_FREE(new_acct ); return NT_STATUS_OK; -done: - /* cleanup */ - if (interim_account) { - tdb_unlock_bystring(tdbsam, newname); - tdb_delete_samacct_only(new_acct); + cancel: + if (db_sam->transaction_cancel(db_sam) != 0) { + smb_panic("transaction_cancel failed"); } - tdbsam_close(); - TALLOC_FREE(new_acct); - + return NT_STATUS_ACCESS_DENIED; } @@ -1458,20 +1459,19 @@ struct tdbsam_search_state { uint32_t current; }; -static int tdbsam_collect_rids(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, - void *private_data) +static int tdbsam_collect_rids(struct db_record *rec, void *private_data) { struct tdbsam_search_state *state = talloc_get_type_abort( private_data, struct tdbsam_search_state); size_t prefixlen = strlen(RIDPREFIX); uint32 rid; - if ((key.dsize < prefixlen) - || (strncmp((char *)key.dptr, RIDPREFIX, prefixlen))) { + if ((rec->key.dsize < prefixlen) + || (strncmp((char *)rec->key.dptr, RIDPREFIX, prefixlen))) { return 0; } - rid = strtoul((char *)key.dptr+prefixlen, NULL, 16); + rid = strtoul((char *)rec->key.dptr+prefixlen, NULL, 16); ADD_TO_LARGE_ARRAY(state, uint32, rid, &state->rids, &state->num_rids, &state->array_size); @@ -1570,9 +1570,7 @@ static bool tdbsam_search_users(struct pdb_methods *methods, state->acct_flags = acct_flags; state->methods = methods; - tdb_traverse(tdbsam, tdbsam_collect_rids, state); - - tdbsam_close(); + db_sam->traverse_read(db_sam, tdbsam_collect_rids, state); search->private_data = state; search->next_entry = tdbsam_search_next_entry; -- cgit From 7d413b8beec4f47b1acd79bbcd1c9d1178a16d7a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 27 Mar 2008 16:55:35 +0100 Subject: pdb_tdb: use db_sam->transaction_start(db_sam) != 0 consistent metze Signed-off-by: Stefan Metzmacher (This used to be commit 3bf9ab640e9a79157fcfee0b5d0cde5badc92755) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 25aa6b4fb0..c3ee188010 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1275,7 +1275,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, return NT_STATUS_ACCESS_DENIED; } - if (db_sam->transaction_start(db_sam) == -1) { + if (db_sam->transaction_start(db_sam) != 0) { DEBUG(0, ("Could not start transaction\n")); TALLOC_FREE(new_acct); return NT_STATUS_ACCESS_DENIED; -- cgit From dbd2e3860dc5855833da0673427ac655e99d33d3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 27 Mar 2008 16:57:10 +0100 Subject: pdb_tdb: use db_open_trans() metze Signed-off-by: Stefan Metzmacher (This used to be commit 9925cc01a2a4739d6cde5991eb0d0b79ae13353b) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index c3ee188010..b41a7cc0a4 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -832,7 +832,7 @@ static bool tdbsam_open( const char *name ) /* Try to open tdb passwd. Create a new one if necessary */ - db_sam = db_open(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600); + db_sam = db_open_trans(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600); if (db_sam == NULL) { DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd " "[%s]\n", name)); -- cgit From 8957f6b0cf76e595d08eeb4accbf67575ea35b5b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 27 Mar 2008 16:55:35 +0100 Subject: pdb_tdb: use != 0 instead off == -1 for dbwrap functions metze (This used to be commit d4826a01369c00b5e83cd62c2412a4eb826e216d) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index b41a7cc0a4..068ddb3692 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -1335,7 +1335,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, tdb_delete_samacct_only( old_acct ); - if (db_sam->transaction_commit(db_sam) == -1) { + if (db_sam->transaction_commit(db_sam) != 0) { /* * Ok, we're screwed. We've changed the posix account, but * could not adapt passdb.tdb. Shall we change the posix -- cgit From 625f2d6c2324ec78edc58d1d5ff697582b52b824 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 15 Apr 2008 00:12:45 +0200 Subject: pdb_tdb: fix the upgrade code, db_traverse returns the number of records! metze (This used to be commit baaf571d540ace5119c528fd35bceab335bd6741) --- source3/passdb/pdb_tdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 068ddb3692..9c8c7b8517 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -775,6 +775,7 @@ static int tdbsam_convert_one(struct db_record *rec, void *priv) static bool tdbsam_convert(struct db_context *db, int32 from) { struct tdbsam_convert_state state; + int ret; state.from = from; state.success = true; @@ -784,7 +785,8 @@ static bool tdbsam_convert(struct db_context *db, int32 from) return false; } - if (db->traverse(db, tdbsam_convert_one, &state) != 0) { + ret = db->traverse(db, tdbsam_convert_one, &state); + if (ret < 0) { DEBUG(0, ("traverse failed\n")); goto cancel; } -- cgit From 0f41961e4ffaa602a5b19a1e0899bffa491c886f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Aug 2008 16:20:05 +1000 Subject: first cut at adding full transactions for ctdb to samba3 (This used to be commit f91a3e0f7b7737c1d0667cd961ea950e2b93e592) --- source3/passdb/pdb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 9c8c7b8517..824e61b063 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -834,7 +834,7 @@ static bool tdbsam_open( const char *name ) /* Try to open tdb passwd. Create a new one if necessary */ - db_sam = db_open_trans(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600); + db_sam = db_open(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600); if (db_sam == NULL) { DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd " "[%s]\n", name)); -- cgit From fe3dd9b3e6daf626ea094d1ce5fc96f89c61b7ad Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 8 Aug 2008 11:42:06 +1000 Subject: fixed lots of places that paniced on a failed transaction_commit, thinking it was a failure of a transaction cancel (This used to be commit 22dbe158ed62ae47bbcb41bba3db345294f75437) --- source3/passdb/pdb_tdb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/passdb/pdb_tdb.c') diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 824e61b063..e40f4bbab8 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -804,7 +804,7 @@ static bool tdbsam_convert(struct db_context *db, int32 from) if (db->transaction_commit(db) != 0) { DEBUG(0, ("Could not commit transaction\n")); - goto cancel; + return false; } return true; @@ -1064,7 +1064,7 @@ static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, if (db_sam->transaction_commit(db_sam) != 0) { DEBUG(0, ("Could not commit transaction\n")); - goto cancel; + return NT_STATUS_INTERNAL_DB_CORRUPTION; } return NT_STATUS_OK; @@ -1191,7 +1191,7 @@ static bool tdb_update_sam(struct pdb_methods *my_methods, struct samu* newpwd, if (db_sam->transaction_commit(db_sam) != 0) { DEBUG(0, ("Could not commit transaction\n")); - goto cancel; + return false; } return true; @@ -1344,7 +1344,8 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods, * account back? */ DEBUG(0, ("transaction_commit failed\n")); - goto cancel; + TALLOC_FREE(new_acct); + return NT_STATUS_INTERNAL_DB_CORRUPTION; } TALLOC_FREE(new_acct ); -- cgit