1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-03 04:22:09 +03:00

Modified interfaces to getting smb password entries from

get_smbpwd_entry (now an internal function to smbpass.c)
to a more UNIX-like :

getsmbpwnam() - get entry by name.
getsmbpwuid() - get entry by uid.

Changed the type returned by the smbpasswd enumeration
functions to be a void * so that people don't come to
depend on it being a FILE *.

These abstractions should make it much easier to
replace the smbpasswd file with a better backend
in future.

Other files changed are to match the above changes.

Jeremy.
(This used to be commit 1161cfb7f2)
This commit is contained in:
Jeremy Allison
1998-04-14 00:41:59 +00:00
parent 49ce0cab3c
commit 2a53d6f707
10 changed files with 83 additions and 38 deletions

View File

@ -1690,10 +1690,13 @@ char *smb_errstr(char *inbuf);
int pw_file_lock(int fd, int type, int secs);
int pw_file_unlock(int fd);
FILE *startsmbpwent(BOOL update);
void endsmbpwent(FILE *fp);
struct smb_passwd *getsmbpwent(FILE *fp);
struct smb_passwd *get_smbpwd_entry(char *name, int smb_userid);
void *startsmbpwent(BOOL update);
void endsmbpwent(void *vp);
struct smb_passwd *getsmbpwent(void *vp);
unsigned long getsmbpwpos(void *vp);
BOOL setsmbpwpos(void *vp, unsigned long tok);
struct smb_passwd *getsmbpwnam(char *name);
struct smb_passwd *getsmbpwuid(unsigned int uid);
BOOL add_smbpwd_entry(struct smb_passwd *newpwd);
BOOL mod_smbpwd_entry(struct smb_passwd* pwd);

View File

@ -201,7 +201,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */
strcpy(reply_name+2,my_name);
smb_pass = get_smbpwd_entry(ascuser, 0);
smb_pass = getsmbpwnam(ascuser);
if(!smb_pass )
{

View File

@ -89,10 +89,11 @@ int pw_file_unlock(int fd)
}
/***************************************************************
Open the smbpasswd file - get ready to enumerate it.
Start to enumerate the smbpasswd list. Returns a void pointer
to ensure no modification outside this module.
****************************************************************/
FILE *startsmbpwent(BOOL update)
void *startsmbpwent(BOOL update)
{
FILE *fp = NULL;
char *pfile = lp_smb_passwd_file();
@ -123,15 +124,17 @@ FILE *startsmbpwent(BOOL update)
chmod(pfile, 0600);
/* We have a lock on the file. */
return fp;
return (void *)fp;
}
/***************************************************************
Close the smbpasswd file - end enumeration.
End enumeration of the smbpasswd list.
****************************************************************/
void endsmbpwent(FILE *fp)
void endsmbpwent(void *vp)
{
FILE *fp = (FILE *)vp;
pw_file_unlock(fileno(fp));
fclose(fp);
DEBUG(7, ("endsmbpwent: closed password file.\n"));
@ -166,16 +169,17 @@ static int gethexpwd(char *p, char *pwd)
}
/*************************************************************************
Routine to return the next entry in the smbpasswd file.
Routine to return the next entry in the smbpasswd list.
*************************************************************************/
struct smb_passwd *getsmbpwent(FILE *fp)
struct smb_passwd *getsmbpwent(void *vp)
{
/* Static buffers we will return. */
static struct smb_passwd pw_buf;
static pstring user_name;
static unsigned char smbpwd[16];
static unsigned char smbntpwd[16];
FILE *fp = (FILE *)vp;
char linebuf[256];
unsigned char c;
unsigned char *p;
@ -428,12 +432,32 @@ struct smb_passwd *getsmbpwent(FILE *fp)
return NULL;
}
/*************************************************************************
Return the current position in the smbpasswd list as an unsigned long.
This must be treated as an opaque token.
*************************************************************************/
unsigned long getsmbpwpos(void *vp)
{
return (unsigned long)ftell((FILE *)vp);
}
/*************************************************************************
Set the current position in the smbpasswd list from unsigned long.
This must be treated as an opaque token.
*************************************************************************/
BOOL setsmbpwpos(void *vp, unsigned long tok)
{
return !fseek((FILE *)vp, tok, SEEK_SET);
}
/*************************************************************************
Routine to search the smbpasswd file for an entry matching the username
or user id. if the name is NULL, then the smb_uid is used instead.
*************************************************************************/
struct smb_passwd *get_smbpwd_entry(char *name, int smb_userid)
static struct smb_passwd *get_smbpwd_entry(char *name, int smb_userid)
{
struct smb_passwd *pwd = NULL;
FILE *fp = NULL;
@ -477,6 +501,24 @@ struct smb_passwd *get_smbpwd_entry(char *name, int smb_userid)
return pwd;
}
/************************************************************************
Routine to search smbpasswd by name.
*************************************************************************/
struct smb_passwd *getsmbpwnam(char *name)
{
return get_smbpwd_entry(name, 0);
}
/************************************************************************
Routine to search smbpasswd by uid.
*************************************************************************/
struct smb_passwd *getsmbpwuid(unsigned int uid)
{
return get_smbpwd_entry(NULL, uid);
}
/************************************************************************
Routine to add an entry to the smbpasswd file.
*************************************************************************/

View File

@ -238,7 +238,7 @@ static BOOL get_md4pw(char *md4pw, char *mach_name, char *mach_acct)
}
become_root(True);
smb_pass = get_smbpwd_entry(mach_acct, 0);
smb_pass = getsmbpwnam(mach_acct);
unbecome_root(True);
if (smb_pass != NULL)
@ -637,7 +637,7 @@ static void api_net_sam_logon( int uid,
DEBUG(3,("User:[%s]\n", samlogon_user));
become_root(True);
smb_pass = get_smbpwd_entry(samlogon_user, 0);
smb_pass = getsmbpwnam(samlogon_user);
unbecome_root(True);
if (smb_pass == NULL)

View File

@ -43,7 +43,7 @@ static BOOL get_smbpwd_entries(SAM_USER_INFO_21 *pw_buf,
int max_num_entries,
uint16 acb_mask)
{
FILE *fp = NULL;
void *vp = NULL;
struct smb_passwd *pwd = NULL;
(*num_entries) = 0;
@ -51,14 +51,14 @@ static BOOL get_smbpwd_entries(SAM_USER_INFO_21 *pw_buf,
if (pw_buf == NULL) return False;
fp = startsmbpwent(False);
if (!fp)
vp = startsmbpwent(False);
if (!vp)
{
DEBUG(0, ("get_smbpwd_entries: Unable to open SMB password file.\n"));
return False;
}
while (((pwd = getsmbpwent(fp)) != NULL) && (*num_entries) < max_num_entries)
while (((pwd = getsmbpwent(vp)) != NULL) && (*num_entries) < max_num_entries)
{
int user_name_len = strlen(pwd->smb_name);
make_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pwd->smb_name, user_name_len);
@ -91,7 +91,7 @@ static BOOL get_smbpwd_entries(SAM_USER_INFO_21 *pw_buf,
(*total_entries)++;
}
endsmbpwent(fp);
endsmbpwent(vp);
return (*num_entries) > 0;
}
@ -806,7 +806,7 @@ static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
}
become_root(True);
smb_pass = get_smbpwd_entry(NULL, q_u->user_rid);
smb_pass = getsmbpwuid(q_u->user_rid);
unbecome_root(True);
/* check that the RID exists in our domain. */
@ -877,7 +877,7 @@ static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 rid)
struct smb_passwd *smb_pass;
become_root(True);
smb_pass = get_smbpwd_entry(NULL, rid);
smb_pass = getsmbpwuid(rid);
unbecome_root(True);
if (smb_pass == NULL)
@ -1095,7 +1095,7 @@ static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
if (status == 0x0)
{
become_root(True);
smb_pass = get_smbpwd_entry(NULL, rid);
smb_pass = getsmbpwuid(rid);
unbecome_root(True);
if (smb_pass == NULL)
@ -1191,7 +1191,7 @@ static void api_samr_unknown_32( int uid, prs_struct *data, prs_struct *rdata)
q_u.uni_mach_acct.uni_str_len));
become_root(True);
smb_pass = get_smbpwd_entry(mach_acct, 0);
smb_pass = getsmbpwnam(mach_acct);
unbecome_root(True);
if (smb_pass != NULL)

View File

@ -367,7 +367,7 @@ uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type)
/* find the user account */
become_root(True);
smb_pass = get_smbpwd_entry(NULL, rid); /* lkclXXXX SHOULD use rid mapping here! */
smb_pass = getsmbpwuid(rid); /* lkclXXXX SHOULD use rid mapping here! */
unbecome_root(True);
if (smb_pass != NULL)
@ -427,7 +427,7 @@ uint32 lookup_user_rid(char *user_name, uint32 *rid)
/* find the user account */
become_root(True);
smb_pass = get_smbpwd_entry(user_name, 0);
smb_pass = getsmbpwnam(user_name);
unbecome_root(True);
if (smb_pass != NULL)

View File

@ -452,12 +452,12 @@ BOOL check_lanman_password(char *user, unsigned char *pass1,
*psmbpw = NULL;
become_root(0);
smbpw = get_smbpwd_entry(user, 0);
smbpw = getsmbpwnam(user);
unbecome_root(0);
if(smbpw == NULL)
{
DEBUG(0,("check_lanman_password: get_smbpwd_entry returned NULL\n"));
DEBUG(0,("check_lanman_password: getsmbpwnam returned NULL\n"));
return False;
}
@ -509,7 +509,7 @@ BOOL change_lanman_password(struct smb_passwd *smbpw, unsigned char *pass1, unsi
if(smbpw == NULL)
{
DEBUG(0,("change_lanman_password: get_smbpwd_entry returned NULL\n"));
DEBUG(0,("change_lanman_password: no smb password entry.\n"));
return False;
}
@ -560,12 +560,12 @@ BOOL check_oem_password(char *user, unsigned char *data,
unsigned char null_pw[16];
become_root(0);
*psmbpw = smbpw = get_smbpwd_entry(user, 0);
*psmbpw = smbpw = getsmbpwnam(user);
unbecome_root(0);
if(smbpw == NULL)
{
DEBUG(0,("check_oem_password: get_smbpwd_entry returned NULL\n"));
DEBUG(0,("check_oem_password: getsmbpwnam returned NULL\n"));
return False;
}

View File

@ -1084,8 +1084,8 @@ BOOL password_ok(char *user,char *password, int pwlen, struct passwd *pwd)
return(False);
}
/* non-null username indicates search by username not smb userid */
smb_pass = get_smbpwd_entry(user, 0);
smb_pass = getsmbpwnam(user);
if (!smb_pass)
{
DEBUG(3,("Couldn't find user %s in smb_passwd file.\n", user));

View File

@ -380,7 +380,7 @@ static int session_trust_account(char *inbuf, char *outbuf, char *user,
struct smb_passwd *smb_trust_acct = NULL; /* check if trust account exists */
if (lp_security() == SEC_USER)
{
smb_trust_acct = get_smbpwd_entry(user, 0);
smb_trust_acct = getsmbpwnam(user);
}
else
{

View File

@ -398,7 +398,7 @@ char *encode_acct_ctrl(uint16 acct_ctrl)
int get_new_machine_uid(void)
{
int next_uid_start;
FILE *fp;
void *vp;
struct smb_passwd *smbpw;
if(sizeof(uid_t) == 2)
@ -407,12 +407,12 @@ int get_new_machine_uid(void)
if(sizeof(uid_t) == 4)
next_uid_start = 0x7fffffff;
fp = startsmbpwent(False);
while((smbpw = getsmbpwent(fp)) != NULL) {
vp = startsmbpwent(False);
while((smbpw = getsmbpwent(vp)) != NULL) {
if((smbpw->acct_ctrl & (ACB_SVRTRUST|ACB_WSTRUST)))
next_uid_start = MIN(next_uid_start, (smbpw->smb_userid-1));
}
endsmbpwent(fp);
endsmbpwent(vp);
return next_uid_start;
}