summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-04-14 00:41:59 +0000
committerJeremy Allison <jra@samba.org>1998-04-14 00:41:59 +0000
commit1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb (patch)
treebb1e3cd83914797f7f42a8d24546484ff36c65d5
parentc963ec8cc4bd311023ca4ad00ded4502989b7faa (diff)
downloadsamba-1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb.tar.gz
samba-1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb.tar.xz
samba-1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb.zip
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.
-rw-r--r--source/include/proto.h11
-rw-r--r--source/nmbd/nmbd_processlogon.c2
-rw-r--r--source/passdb/smbpass.c58
-rw-r--r--source/rpc_server/srv_netlog.c4
-rw-r--r--source/rpc_server/srv_samr.c18
-rw-r--r--source/rpc_server/srv_util.c4
-rw-r--r--source/smbd/chgpasswd.c10
-rw-r--r--source/smbd/password.c4
-rw-r--r--source/smbd/reply.c2
-rw-r--r--source/utils/smbpasswd.c8
10 files changed, 83 insertions, 38 deletions
diff --git a/source/include/proto.h b/source/include/proto.h
index 3e1f9f5fa3f..07df90e1bdd 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -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);
diff --git a/source/nmbd/nmbd_processlogon.c b/source/nmbd/nmbd_processlogon.c
index f881b867c0f..bc9fcb59218 100644
--- a/source/nmbd/nmbd_processlogon.c
+++ b/source/nmbd/nmbd_processlogon.c
@@ -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 )
{
diff --git a/source/passdb/smbpass.c b/source/passdb/smbpass.c
index 512d26c5520..58029a1b613 100644
--- a/source/passdb/smbpass.c
+++ b/source/passdb/smbpass.c
@@ -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;
@@ -429,11 +433,31 @@ struct smb_passwd *getsmbpwent(FILE *fp)
}
/*************************************************************************
+ 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;
@@ -478,6 +502,24 @@ struct smb_passwd *get_smbpwd_entry(char *name, int smb_userid)
}
/************************************************************************
+ 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.
*************************************************************************/
diff --git a/source/rpc_server/srv_netlog.c b/source/rpc_server/srv_netlog.c
index a08ea2395b2..3912ad7938a 100644
--- a/source/rpc_server/srv_netlog.c
+++ b/source/rpc_server/srv_netlog.c
@@ -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)
diff --git a/source/rpc_server/srv_samr.c b/source/rpc_server/srv_samr.c
index 02c8cb0ffec..162d9c45d01 100644
--- a/source/rpc_server/srv_samr.c
+++ b/source/rpc_server/srv_samr.c
@@ -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)
diff --git a/source/rpc_server/srv_util.c b/source/rpc_server/srv_util.c
index 3f4d66eab26..868cf3a4aca 100644
--- a/source/rpc_server/srv_util.c
+++ b/source/rpc_server/srv_util.c
@@ -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)
diff --git a/source/smbd/chgpasswd.c b/source/smbd/chgpasswd.c
index ae1fd1a6752..7494d0162da 100644
--- a/source/smbd/chgpasswd.c
+++ b/source/smbd/chgpasswd.c
@@ -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;
}
diff --git a/source/smbd/password.c b/source/smbd/password.c
index 74ebeb16170..bbd9f8b849e 100644
--- a/source/smbd/password.c
+++ b/source/smbd/password.c
@@ -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));
diff --git a/source/smbd/reply.c b/source/smbd/reply.c
index 7807bf83698..eaf3fe99206 100644
--- a/source/smbd/reply.c
+++ b/source/smbd/reply.c
@@ -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
{
diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c
index 2433fa1bb42..b569ba96b35 100644
--- a/source/utils/smbpasswd.c
+++ b/source/utils/smbpasswd.c
@@ -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;
}