1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-23 09:57:40 +03:00

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 commit is contained in:
Gerald Carter -
parent 63cafb34b3
commit 4792029a29
12 changed files with 923 additions and 890 deletions

View File

@ -50,7 +50,7 @@ PASSWD_PROGRAM = /bin/passwd
PRIVATEDIR = @privatedir@
SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
TDB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd.tdb
PRIVATE_DIR = $(PRIVATEDIR)
# This is where SWAT images and help files go
SWATDIR = @swatdir@
@ -72,7 +72,7 @@ CODEPAGELIST= 437 737 775 850 852 861 932 866 949 950 936 1251 ISO8859-1 ISO8859
SMBRUN = $(BINDIR)/smbrun
PASSWD_FLAGS = -DPASSWD_PROGRAM=\"$(PASSWD_PROGRAM)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -DTDB_PASSWD_FILE=\"$(TDB_PASSWD_FILE)\"
PASSWD_FLAGS = -DPASSWD_PROGRAM=\"$(PASSWD_PROGRAM)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -DPRIVATE_DIR=\"$(PRIVATE_DIR)\"
FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper $(CPPFLAGS) -DLOGFILEBASE=\"$(LOGFILEBASE)\"
FLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"
FLAGS3 = -DSWATDIR=\"$(SWATDIR)\" -DSBINDIR=\"$(SBINDIR)\" -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\" -DCODEPAGEDIR=\"$(CODEPAGEDIR)\"
@ -156,7 +156,8 @@ LOCKING_OBJ = locking/locking.o locking/brlock.o locking/posix.o
PASSDB_OBJ = passdb/passdb.o passdb/secrets.o \
passdb/pass_check.o passdb/smbpassfile.o \
passdb/machine_sid.o passdb/pdb_smbpasswd.o
passdb/machine_sid.o passdb/pdb_smbpasswd.o \
passdb/pdb_tdb.o
# passdb/smbpass.o passdb/ldap.o passdb/nispass.o

10
source/configure vendored
View File

@ -47,8 +47,8 @@ ac_help="$ac_help
--with-pam Include PAM password database support
--without-pam Don't include PAM password database support (default)"
ac_help="$ac_help
--with-tdbpwd Include experimental TDB password database
--without-tdbpwd Don't include experimental TDB password database (default)"
--with-tdbsam Include experimental TDB password database
--without-tdbsam Don't include experimental TDB password database (default)"
ac_help="$ac_help
--with-ldap Include LDAP support
--without-ldap Don't include LDAP support (default)"
@ -10641,9 +10641,9 @@ fi
# check for a TDB password database
echo $ac_n "checking whether to use TDB password database""... $ac_c" 1>&6
echo "configure:10644: checking whether to use TDB password database" >&5
# Check whether --with-tdbpwd or --without-tdbpwd was given.
if test "${with_tdbpwd+set}" = set; then
withval="$with_tdbpwd"
# Check whether --with-tdbsam or --without-tdbsam was given.
if test "${with_tdbsam+set}" = set; then
withval="$with_tdbsam"
case "$withval" in
yes)
echo "$ac_t""yes" 1>&6

View File

@ -1392,9 +1392,9 @@ AC_ARG_WITH(pam,
#################################################
# check for a TDB password database
AC_MSG_CHECKING(whether to use TDB password database)
AC_ARG_WITH(tdbpwd,
[ --with-tdbpwd Include experimental TDB password database
--without-tdbpwd Don't include experimental TDB password database (default)],
AC_ARG_WITH(tdbsam,
[ --with-tdbsam Include experimental TDB password database
--without-tdbsam Don't include experimental TDB password database (default)],
[ case "$withval" in
yes)
AC_MSG_RESULT(yes)

View File

@ -654,6 +654,9 @@ typedef struct
typedef struct sam_passwd
{
BOOL own_memory; /* do we own the memory allocated for the
pointers in this struct? */
time_t logon_time; /* logon time */
time_t logoff_time; /* logoff time */
time_t kickoff_time; /* kickoff time */
@ -694,71 +697,6 @@ typedef struct sam_passwd
} SAM_ACCOUNT;
#if 0 /* GWC */
/*
* Each implementation of the password database code needs
* to support the following operations.
*/
struct passdb_ops {
/*
* Password database ops.
*/
void *(*startsmbpwent)(BOOL);
void (*endsmbpwent)(void *);
SMB_BIG_UINT (*getsmbpwpos)(void *);
BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
/*
* smb password database query functions.
*/
struct smb_passwd *(*getsmbpwnam)(char *);
struct smb_passwd *(*getsmbpwuid)(uid_t);
struct smb_passwd *(*getsmbpwrid)(uint32);
struct smb_passwd *(*getsmbpwent)(void *);
/*
* smb password database modification functions.
*/
BOOL (*add_smbpwd_entry)(struct smb_passwd *);
BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
BOOL (*del_smbpwd_entry)(const char *);
/*
* Functions that manupulate a struct sam_passwd.
*/
struct sam_passwd *(*getsam21pwent)(void *);
/*
* sam password database query functions.
*/
struct sam_passwd *(*getsam21pwnam)(char *);
struct sam_passwd *(*getsam21pwuid)(uid_t);
struct sam_passwd *(*getsam21pwrid)(uint32);
/*
* sam password database modification functions.
*/
BOOL (*add_sam21pwd_entry)(struct sam_passwd *);
BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL);
/*
* sam query display info functions.
*/
struct sam_disp_info *(*getsamdispnam)(char *);
struct sam_disp_info *(*getsamdisprid)(uint32);
struct sam_disp_info *(*getsamdispent)(void *);
/*
* password checking functions
*/
struct smb_passwd *(*smb_password_chal )(char *username, char lm_pass[24], char nt_pass[24], char chal[8]);
struct smb_passwd *(*smb_password_check )(char *username, char lm_hash[16], char nt_hash[16]);
struct passwd *(*unix_password_check)(char *username, char *pass, int pass_len);
};
#endif /* 0 */
/*
* Flags for local user manipulation.
*/

View File

@ -304,6 +304,12 @@ void unix_to_nt_time(NTTIME *nt, time_t t)
nt->high = 0;
return;
}
if (t == -1)
{
nt->low = 0xffffffff;
nt->high = 0xffffffff;
return;
}
/* this converts GMT to kludge-GMT */
t -= LocTimeDiff(t) - serverzone;

View File

@ -119,11 +119,8 @@ typedef struct
char *szPasswdChat;
char *szLogFile;
char *szConfigFile;
#ifdef WITH_TDBPWD
char *szTDBPasswdFile;
#else
char *szSMBPasswdFile;
#endif
char *szPrivateDir;
char *szPassdbModulePath;
char *szPasswordServer;
char *szSocketOptions;
@ -669,11 +666,8 @@ static struct parm_struct parm_table[] = {
{"map to guest", P_ENUM, P_GLOBAL, &Globals.map_to_guest, NULL, enum_map_to_guest, 0},
{"null passwords", P_BOOL, P_GLOBAL, &Globals.bNullPasswords, NULL, NULL, 0},
{"password server", P_STRING, P_GLOBAL, &Globals.szPasswordServer, NULL, NULL, 0},
/* #ifdef WITH_TDBPWD
{"tdb passwd file", P_STRING, P_GLOBAL, &Globals.szTDBPasswdFile, NULL, NULL, 0},
#else */
{"smb passwd file", P_STRING, P_GLOBAL, &Globals.szSMBPasswdFile, NULL, NULL, 0},
/* #endif */
{"private dir", P_STRING, P_GLOBAL, &Globals.szPrivateDir, NULL, NULL, 0},
{"passdb module path", P_STRING, P_GLOBAL, &Globals.szPassdbModulePath, NULL, NULL, 0},
{"root directory", P_STRING, P_GLOBAL, &Globals.szRootdir, NULL, NULL, 0},
{"root dir", P_STRING, P_GLOBAL, &Globals.szRootdir, NULL, NULL, 0},
@ -1149,11 +1143,8 @@ static void init_globals(void)
DEBUG(3, ("Initialising global parameters\n"));
#ifdef WITH_TDBPWD
string_set(&Globals.szTDBPasswdFile, TDB_PASSWD_FILE);
#else
string_set(&Globals.szSMBPasswdFile, SMB_PASSWD_FILE);
#endif
string_set(&Globals.szPrivateDir, PRIVATE_DIR);
string_set(&Globals.szPassdbModulePath, "");
/*
@ -1384,11 +1375,8 @@ static char *lp_string(const char *s)
FN_GLOBAL_STRING(lp_logfile, &Globals.szLogFile)
FN_GLOBAL_STRING(lp_smbrun, &Globals.szSmbrun)
FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
#ifdef WITH_TDBPWD
FN_GLOBAL_STRING(lp_tdb_passwd_file, &Globals.szTDBPasswdFile)
#else
FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile)
#endif
FN_GLOBAL_STRING(lp_private_dir, &Globals.szPrivateDir)
FN_GLOBAL_STRING(lp_passdb_module_path, &Globals.szPassdbModulePath)
FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString)
FN_GLOBAL_STRING(lp_printcapname, &Globals.szPrintcapname)

View File

@ -36,30 +36,6 @@ extern DOM_SID global_sam_sid;
extern pstring global_myname;
extern fstring global_myworkgroup;
/*
* NOTE. All these functions are abstracted into a structure
* that points to the correct function for the selected database. JRA.
*
* NOTE. for the get/mod/add functions, there are two sets of functions.
* one supports struct sam_passwd, the other supports struct smb_passwd.
* for speed optimisation it is best to support both these sets.
*
* it is, however, optional to support one set but not the other: there
* is conversion-capability built in to passdb.c, and run-time error
* detection for when neither are supported.
*
* password database writers are recommended to implement the sam_passwd
* functions in a first pass, as struct sam_passwd contains more
* information, needed by the NT Domain support.
*
* a full example set of derivative functions are listed below. an API
* writer is expected to cut/paste these into their module, replace
* either one set (struct smb_passwd) or the other (struct sam_passwd)
* OR both, and optionally also to write display info routines
* (struct sam_disp_info). lkcl
*
*/
struct passdb_ops *pdb_ops;
static void* pdb_handle = NULL;
@ -152,36 +128,30 @@ void pdb_init_sam(SAM_ACCOUNT *user)
***********************************************************/
void pdb_clear_sam(SAM_ACCOUNT *user)
{
if (user == NULL)
/* do we have a SAM_CCOUTN struct to work with? */
if (user == NULL)
return;
/* clear all pointer members */
if (user->username)
free(user->username);
if (user->full_name)
free(user->full_name);
if (user->home_dir)
free(user->home_dir);
if (user->dir_drive)
free(user->dir_drive);
if (user->logon_script)
free(user->logon_script);
if (user->profile_path)
free(user->profile_path);
if (user->acct_desc)
free(user->acct_desc);
if (user->workstations)
free(user->workstations);
if (user->unknown_str)
free(user->unknown_str);
if (user->munged_dial)
free(user->munged_dial);
if (user->lm_pw)
free(user->lm_pw);
if (user->nt_pw)
free(user->nt_pw);
/* do we own the memory? */
if (user->own_memory)
{
/* clear all pointer members */
if (user->username) free(user->username);
if (user->full_name) free(user->full_name);
if (user->domain) free(user->domain);
if (user->nt_username) free(user->nt_username);
if (user->home_dir) free(user->home_dir);
if (user->dir_drive) free(user->dir_drive);
if (user->logon_script) free(user->logon_script);
if (user->profile_path) free(user->profile_path);
if (user->acct_desc) free(user->acct_desc);
if (user->workstations) free(user->workstations);
if (user->unknown_str) free(user->unknown_str);
if (user->munged_dial) free(user->munged_dial);
if (user->lm_pw) free(user->lm_pw);
if (user->nt_pw) free(user->nt_pw);
}
/* now initialize */
pdb_init_sam(user);
@ -664,9 +634,9 @@ static void select_name(fstring *string, char **name, const UNISTR2 *from)
}
/*************************************************************
copies a sam passwd.
copies a SAM_USER_INFO_23 to a SAM_ACCOUNT
**************************************************************/
void copy_id23_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_23 *from)
void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from)
{
static fstring smb_name;
static fstring full_name;
@ -679,7 +649,8 @@ void copy_id23_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_23 *from)
static fstring unknown_str;
static fstring munged_dial;
if (from == NULL || to == NULL) return;
if (from == NULL || to == NULL)
return;
to->logon_time = nt_time_to_unix(&from->logon_time);
to->logoff_time = nt_time_to_unix(&from->logoff_time);
@ -699,14 +670,9 @@ void copy_id23_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_23 *from)
select_name(&unknown_str , &to->unknown_str , &from->uni_unknown_str );
select_name(&munged_dial , &to->munged_dial , &from->uni_munged_dial );
to->uid = (uid_t)-1;
to->gid = (gid_t)-1;
to->user_rid = from->user_rid;
to->group_rid = from->group_rid;
to->lm_pw = NULL;
to->nt_pw = NULL;
to->acct_ctrl = from->acb_info;
to->unknown_3 = from->unknown_3;
@ -721,7 +687,7 @@ void copy_id23_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_23 *from)
/*************************************************************
copies a sam passwd.
**************************************************************/
void copy_id21_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_21 *from)
void copy_id21_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_21 *from)
{
static fstring smb_name;
static fstring full_name;
@ -734,7 +700,8 @@ void copy_id21_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_21 *from)
static fstring unknown_str;
static fstring munged_dial;
if (from == NULL || to == NULL) return;
if (from == NULL || to == NULL)
return;
to->logon_time = nt_time_to_unix(&from->logon_time);
to->logoff_time = nt_time_to_unix(&from->logoff_time);
@ -754,13 +721,11 @@ void copy_id21_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_21 *from)
select_name(&unknown_str , &to->unknown_str , &from->uni_unknown_str );
select_name(&munged_dial , &to->munged_dial , &from->uni_munged_dial );
to->uid = (uid_t)-1;
to->gid = (gid_t)-1;
to->user_rid = from->user_rid;
to->group_rid = from->group_rid;
to->lm_pw = NULL;
to->nt_pw = NULL;
/* FIXME!! Do we need to copy the passwords here as well?
I don't know. Need to figure this out --jerry */
to->acct_ctrl = from->acb_info;
to->unknown_3 = from->unknown_3;
@ -776,13 +741,8 @@ void copy_id21_to_sam_passwd(struct sam_passwd *to, SAM_USER_INFO_21 *from)
/*************************************************************
copies a sam passwd.
FIXME! Do we need to use dynamically allocated strings
here instead of static strings?
Why are password hashes not also copied? --jerry
**************************************************************/
void copy_sam_passwd(struct sam_passwd *to, const struct sam_passwd *from)
void copy_sam_passwd(SAM_ACCOUNT *to, const SAM_ACCOUNT *from)
{
static fstring smb_name="";
static fstring full_name="";
@ -794,60 +754,90 @@ void copy_sam_passwd(struct sam_passwd *to, const struct sam_passwd *from)
static fstring workstations="";
static fstring unknown_str="";
static fstring munged_dial="";
static BYTE lm_pw[16], nt_pw[16];
if (from == NULL || to == NULL) return;
if (from == NULL || to == NULL)
return;
/* we won't own this memory so set the flag.
This will also clear the strings from 'to' */
pdb_set_mem_ownership (to, False);
memcpy(to, from, sizeof(*from));
if (from->username != NULL) {
fstrcpy(smb_name , from->username);
if (from->username != NULL)
{
fstrcpy(smb_name , from->username);
to->username = smb_name;
}
if (from->full_name != NULL) {
if (from->full_name != NULL)
{
fstrcpy(full_name, from->full_name);
to->full_name = full_name;
}
if (from->home_dir != NULL) {
fstrcpy(home_dir , from->home_dir);
if (from->home_dir != NULL)
{
fstrcpy(home_dir, from->home_dir);
to->home_dir = home_dir;
}
if (from->dir_drive != NULL) {
if (from->dir_drive != NULL)
{
fstrcpy(dir_drive , from->dir_drive);
to->dir_drive = dir_drive;
}
if (from->logon_script != NULL) {
if (from->logon_script != NULL)
{
fstrcpy(logon_script , from->logon_script);
to->logon_script = logon_script;
}
if (from->profile_path != NULL) {
if (from->profile_path != NULL)
{
fstrcpy(profile_path , from->profile_path);
to->profile_path = profile_path;
}
if (from->acct_desc != NULL) {
if (from->acct_desc != NULL)
{
fstrcpy(acct_desc , from->acct_desc);
to->acct_desc = acct_desc;
}
if (from->workstations != NULL) {
if (from->workstations != NULL)
{
fstrcpy(workstations , from->workstations);
to->workstations = workstations;
}
if (from->unknown_str != NULL) {
if (from->unknown_str != NULL)
{
fstrcpy(unknown_str , from->unknown_str);
to->unknown_str = unknown_str;
}
if (from->munged_dial != NULL) {
if (from->munged_dial != NULL)
{
fstrcpy(munged_dial , from->munged_dial);
to->munged_dial = munged_dial;
}
if (from->nt_pw != NULL)
{
memcpy (nt_pw, from->nt_pw, 16);
to->nt_pw = nt_pw;
}
if (from->lm_pw != NULL)
{
memcpy (lm_pw, from->lm_pw, 16);
to->lm_pw = lm_pw;
}
return;
}
/*************************************************************
@ -901,8 +891,11 @@ account without a valid local system user.\n", user_name);
return False;
}
/* create the SAM_ACCOUNT struct and call pdb_add_sam_account */
/* create the SAM_ACCOUNT struct and call pdb_add_sam_account.
Because the new_sam_pwd only exists in the scope of this function
we will not allocate memory for members */
pdb_init_sam (&new_sam_acct);
pdb_set_mem_ownership (&new_sam_acct, False);
pdb_set_username (&new_sam_acct, user_name);
pdb_set_uid (&new_sam_acct, pwd->pw_uid);
pdb_set_pass_last_set_time(&new_sam_acct, time(NULL));
@ -1262,8 +1255,35 @@ uint32 pdb_get_unknown6 (SAM_ACCOUNT *sampass)
/*********************************************************************
collection of set...() functions for SAM_ACCOUNT_INFO
********************************************************************/
/********************************************************************
The purpose of this flag is to determine whether or not we
should free the memory when we are done. This allows us to
use local static variables for string (reduce the number of
malloc() calls) while still allowing for flexibility of
dynamic objects.
We always clear the structure even if setting the flag to the
same value.
*******************************************************************/
void pdb_set_mem_ownership (SAM_ACCOUNT *sampass, BOOL flag)
{
/* if we have no SAM_ACCOUNT struct or no change, then done */
if (sampass == NULL)
return;
/* clear the struct and set the ownership flag */
pdb_clear_sam (sampass);
sampass->own_memory = flag;
return;
}
BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
{
if (!sampass)
return False;
if (sampass)
{
sampass->acct_ctrl = flags;
@ -1275,264 +1295,360 @@ BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime)
{
if (sampass)
{
sampass->logon_time = mytime;
return True;
}
return False;
if (!sampass)
return False;
sampass->logon_time = mytime;
return True;
}
BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime)
{
if (sampass)
{
sampass->logoff_time = mytime;
return True;
}
return False;
if (!sampass)
return False;
sampass->logoff_time = mytime;
return True;
}
BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime)
{
if (sampass)
{
sampass->kickoff_time = mytime;
return True;
}
return False;
if (!sampass)
return False;
sampass->kickoff_time = mytime;
return True;
}
BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime)
{
if (sampass)
{
sampass->pass_can_change_time = mytime;
return True;
}
return False;
if (!sampass)
return False;
sampass->pass_can_change_time = mytime;
return True;
}
BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime)
{
if (sampass)
{
sampass->pass_must_change_time = mytime;
return True;
}
return False;
if (!sampass)
return False;
sampass->pass_must_change_time = mytime;
return True;
}
BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime)
{
if (sampass)
{
sampass->pass_last_set_time = mytime;
return True;
}
return False;
if (!sampass)
return False;
sampass->pass_last_set_time = mytime;
return True;
}
BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len)
{
if (sampass)
{
sampass->hours_len = len;
return True;
}
return False;
if (!sampass)
return False;
sampass->hours_len = len;
return True;
}
BOOL pdb_set_logons_divs (SAM_ACCOUNT *sampass, uint16 hours)
{
if (sampass)
{
sampass->logon_divs = hours;
return True;
}
return False;
if (!sampass)
return False;
sampass->logon_divs = hours;
return True;
}
BOOL pdb_set_uid (SAM_ACCOUNT *sampass, uid_t uid)
{
if (sampass)
{
sampass->uid = uid;
return True;
}
return False;
if (!sampass)
return False;
sampass->uid = uid;
return True;
}
BOOL pdb_set_gid (SAM_ACCOUNT *sampass, gid_t gid)
{
if (sampass)
{
sampass->gid = gid;
return True;
}
return False;
if (!sampass)
return False;
sampass->gid = gid;
return True;
}
BOOL pdb_set_user_rid (SAM_ACCOUNT *sampass, uint32 rid)
{
if (sampass)
{
sampass->user_rid = rid;
return True;
}
return False;
if (!sampass)
return False;
sampass->user_rid = rid;
return True;
}
BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid)
{
if (sampass)
{
sampass->group_rid = grid;
return True;
}
return False;
if (!sampass)
return False;
sampass->group_rid = grid;
return True;
}
BOOL pdb_set_username (SAM_ACCOUNT *sampass, char *username)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->username = username;
else
{
sampass->username = strdup(username);
return True;
if ( (sampass->username=strdup(username)) == NULL )
{
DEBUG (0,("pdb_set_username: ERROR - Unable to malloc memory for [%s]\n", username));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_domain (SAM_ACCOUNT *sampass, char *domain)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->domain = domain;
else
{
sampass->domain = strdup(domain);
return True;
if ( (sampass->domain=strdup(domain)) == NULL )
{
DEBUG (0,("pdb_set_domain: ERROR - Unable to malloc memory for [%s]\n", domain));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_nt_username (SAM_ACCOUNT *sampass, char *nt_username)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->nt_username = nt_username;
else
{
sampass->nt_username = strdup(nt_username);
return True;
if ( (sampass->nt_username=strdup(nt_username)) == NULL )
{
DEBUG (0,("pdb_set_nt_username: ERROR - Unable to malloc memory for [%s]\n", nt_username));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_fullname (SAM_ACCOUNT *sampass, char *fullname)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->full_name = fullname;
else
{
sampass->full_name = strdup(fullname);
return True;
if ( (sampass->full_name=strdup(fullname)) == NULL )
{
DEBUG (0,("pdb_set_fullname: ERROR - Unable to malloc memory for [%s]\n", fullname));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_logon_script (SAM_ACCOUNT *sampass, char *logon_script)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->logon_script = logon_script;
else
{
sampass->logon_script = strdup(logon_script);
return True;
if ( (sampass->logon_script=strdup(logon_script)) == NULL )
{
DEBUG (0,("pdb_set_logon_script: ERROR - Unable to malloc memory for [%s]\n", logon_script));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, char *profile_path)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->profile_path = profile_path;
else
{
sampass->profile_path = strdup(profile_path);
return True;
if ( (sampass->profile_path=strdup(profile_path)) == NULL )
{
DEBUG (0,("pdb_set_profile_path: ERROR - Unable to malloc memory for [%s]\n", profile_path));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, char *dir_drive)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->dir_drive = dir_drive;
else
{
sampass->dir_drive = strdup(dir_drive);
return True;
if ( (sampass->dir_drive=strdup(dir_drive)) == NULL )
{
DEBUG (0,("pdb_set_dir_drive: ERROR - Unable to malloc memory for [%s]\n", dir_drive));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, char *homedir)
{
if (sampass)
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->home_dir = homedir;
else
{
sampass->home_dir = strdup(homedir);
return True;
if ( (sampass->home_dir=strdup(homedir)) == NULL )
{
DEBUG (0,("pdb_set_home_dir: ERROR - Unable to malloc memory for [%s]\n", homedir));
return False;
}
}
return False;
return True;
}
BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, char *acct_desc)
{
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->acct_desc = acct_desc;
else
{
if ( (sampass->acct_desc=strdup(acct_desc)) == NULL )
{
DEBUG (0,("pdb_set_acct_desc: ERROR - Unable to malloc memory for [%s]\n", acct_desc));
return False;
}
}
return True;
}
BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, char *workstations)
{
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->workstations = workstations;
else
{
if ( (sampass->workstations=strdup(workstations)) == NULL )
{
DEBUG (0,("pdb_set_workstations: ERROR - Unable to malloc memory for [%s]\n", workstations));
return False;
}
}
return True;
}
BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, char *munged_dial)
{
if (!sampass)
return False;
if (!sampass->own_memory)
sampass->munged_dial = munged_dial;
else
{
if ( (sampass->munged_dial=strdup(munged_dial)) == NULL )
{
DEBUG (0,("pdb_set_munged_dial: ERROR - Unable to malloc memory for [%s]\n", munged_dial));
return False;
}
}
return True;
}
BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, BYTE *pwd)
{
if (pwd == NULL)
if ( (!sampass) ||(pwd == NULL) )
return False;
/* allocate space for the password and make a copy of it */
if (sampass)
if (!sampass->own_memory)
sampass->nt_pw = pwd;
else
{
if ((sampass->nt_pw=(BYTE*)malloc(sizeof(BYTE)*16)) == NULL)
{
DEBUG(0,("pdb_set_nt_passwd: ERROR - out of memory for nt_pw!\n"));
return False;
}
if (memcpy(sampass->nt_pw, pwd, 16))
return True;
if (!memcpy(sampass->nt_pw, pwd, 16))
return False;
}
return False;
return True;
}
BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, BYTE *pwd)
{
if (pwd == NULL)
if ( (!sampass) ||(pwd == NULL) )
return False;
/* allocate space for the password and make a copy of it */
if (sampass)
if (!sampass->own_memory)
sampass->lm_pw = pwd;
else
{
if ((sampass->lm_pw=(BYTE*)malloc(sizeof(BYTE)*16)) == NULL)
{
DEBUG(0,("pdb_set_lanman_passwd: ERROR - out of memory for lm_pw!\n"));
return False;
}
if (memcpy(sampass->lm_pw, pwd, 16))
return True;
if (!memcpy(sampass->lm_pw, pwd, 16))
return False;
}
return False;
return True;
}

View File

@ -1222,6 +1222,13 @@ static BOOL build_sam_account (SAM_ACCOUNT *sam_pass,
struct passwd *pwfile;
if (!sam_pass)
return (False);
/* make sure that we own the memory here--also clears
any existing members as a side effect */
pdb_set_mem_ownership(sam_pass, True);
/* is the user valid? Verify in system password file...
FIXME!!! This is where we should look up an internal
@ -1347,10 +1354,8 @@ SAM_ACCOUNT* pdb_getsampwent (void)
if (pw_buf == NULL)
return NULL;
/* clear out any preexisting information from the last call */
pdb_clear_sam (&global_sam_pass);
/* build the SAM_ACCOUNT entry from the smb_passwd struct */
/* build the SAM_ACCOUNT entry from the smb_passwd struct.
This will also clear out the previous SAM_ACCOUNT fields */
if (!build_sam_account (&global_sam_pass, pw_buf))
return NULL;
@ -1420,7 +1425,6 @@ SAM_ACCOUNT* pdb_getsampwnam (char *username)
DEBUG(10, ("found by name: %s\n", smb_pw->smb_name));
/* now build the SAM_ACCOUNT */
pdb_clear_sam (&global_sam_pass);
if (!build_sam_account (&global_sam_pass, smb_pw))
return NULL;
@ -1460,7 +1464,6 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid)
DEBUG(10, ("found by name: %s\n", smb_pw->smb_name));
/* now build the SAM_ACCOUNT */
pdb_clear_sam (&global_sam_pass);
if (!build_sam_account (&global_sam_pass, smb_pw))
return NULL;
@ -1499,7 +1502,6 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid)
DEBUG(10, ("found by name: %s\n", smb_pw->smb_name));
/* now build the SAM_ACCOUNT */
pdb_clear_sam (&global_sam_pass);
if (!build_sam_account (&global_sam_pass, smb_pw))
return NULL;

File diff suppressed because it is too large Load Diff

View File

@ -34,11 +34,7 @@ BOOL secrets_init(void)
if (tdb) return True;
pstrcpy(fname, lp_smb_passwd_file());
p = strrchr(fname, '/');
if(!p) return False;
*p = 0;
pstrcpy(fname, lp_private_dir());
pstrcat(fname,"/secrets.tdb");
tdb = tdb_open(fname, 0, 0, O_RDWR|O_CREAT, 0600);

View File

@ -85,12 +85,10 @@ static BOOL pw_file_unlock(int fd, int *plock_depth)
static void get_trust_account_file_name( char *domain, char *name, char *mac_file)
{
unsigned int mac_file_len;
char *p;
pstrcpy(mac_file, lp_smb_passwd_file());
p = strrchr(mac_file, '/');
if(p != NULL)
*++p = '\0';
pstrcpy(mac_file, lp_private_dir());
if (mac_file[strlen(mac_file)-1] != '/')
pstrcat (mac_file, "/");
mac_file_len = strlen(mac_file);

View File

@ -2226,7 +2226,7 @@ static BOOL set_user_info_12(SAM_USER_INFO_12 *id12, uint32 rid)
/*******************************************************************
set_user_info_21
********************************************************************/
static BOOL set_user_info_21(SAM_USER_INFO_21 * id21, uint32 rid)
static BOOL set_user_info_21 (SAM_USER_INFO_21 *id21, uint32 rid)
{
SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
SAM_ACCOUNT new_pwd;
@ -2239,33 +2239,20 @@ static BOOL set_user_info_21(SAM_USER_INFO_21 * id21, uint32 rid)
if (pwd == NULL)
return False;
/* Zero out struct and set a few initial items */
pdb_init_sam(&new_pwd);
/* FIXME!! these two calls may need to be fixed. copy_sam_passwd()
uses static strings and copy_id21..() reassigns some
strings. Right now there is no memory leaks, but if
the internals of copy_sam_passwd() changes to use dynamically
allocated strings, this will need to be fixed --jerry */
/* we make a copy so that we can modify stuff */
copy_sam_passwd(&new_pwd, pwd);
copy_id21_to_sam_passwd(&new_pwd, id21);
/*
* The funny part about the previous two calls is
* that pwd still has the password hashes from the
* passdb entry. These have not been updated from
* id21. I don't know if they need to be set. --jerry
*/
/* passwords are not copied as part of copy_sam_passwd() */
if (pdb_get_nt_passwd(pwd) != NULL)
pdb_set_nt_passwd (&new_pwd, pdb_get_nt_passwd(pwd));
if (pdb_get_lanman_passwd(pwd) != NULL)
pdb_set_lanman_passwd (&new_pwd, pdb_get_lanman_passwd(pwd));
/* write the change out */
if(!pdb_update_sam_account(&new_pwd, True))
return False;
/* FIXME!!! Memory leak here. Cannot call pdb_clear_sam()
because copy_sam_passwd uses static arrays. Therefore,
we will manually free the password pointers here. This
needs to be fixed. ---jerry */
if (new_pwd.nt_pw) free (new_pwd.nt_pw);
if (new_pwd.lm_pw) free (new_pwd.lm_pw);
return True;
}
@ -2290,7 +2277,6 @@ static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, uint32 rid)
if (pwd == NULL)
return False;
pdb_init_sam(&new_pwd);
copy_sam_passwd(&new_pwd, pwd);
copy_id23_to_sam_passwd(&new_pwd, id23);
@ -2311,13 +2297,6 @@ static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, uint32 rid)
if(!pdb_update_sam_account(&new_pwd, True))
return False;
/* FIXME!!! Memory leak here. Cannot call pdb_clear_sam()
because copy_sam_passwd uses static arrays. Therefore,
we will manually free the password pointers here. This
needs to be fixed. ---jerry */
if (new_pwd.nt_pw) free (new_pwd.nt_pw);
if (new_pwd.lm_pw) free (new_pwd.lm_pw);
return True;
}