summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h11
-rw-r--r--source3/nmbd/nmbd_processlogon.c2
-rw-r--r--source3/passdb/smbpass.c58
-rw-r--r--source3/rpc_server/srv_netlog.c4
-rw-r--r--source3/rpc_server/srv_samr.c18
-rw-r--r--source3/rpc_server/srv_util.c4
-rw-r--r--source3/smbd/chgpasswd.c10
-rw-r--r--source3/smbd/password.c4
-rw-r--r--source3/smbd/reply.c2
-rw-r--r--source3/utils/smbpasswd.c8
10 files changed, 83 insertions, 38 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 3e1f9f5fa3..07df90e1bd 100644
--- a/source3/include/proto.h
+++ b/source3/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/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c
index f881b867c0..bc9fcb5921 100644
--- a/source3/nmbd/nmbd_processlogon.c
+++ b/source3/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/source3/passdb/smbpass.c b/source3/passdb/smbpass.c
index 512d26c552..58029a1b61 100644
--- a/source3/passdb/smbpass.c
+++ b/source3/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/source3/rpc_server/srv_netlog.c b/source3/rpc_server/srv_netlog.c
index a08ea2395b..3912ad7938 100644
--- a/source3/rpc_server/srv_netlog.c
+++ b/source3/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/source3/rpc_server/srv_samr.c b/source3/rpc_server/srv_samr.c
index 02c8cb0ffe..162d9c45d0 100644
--- a/source3/rpc_server/srv_samr.c
+++ b/source3/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/source3/rpc_server/srv_util.c b/source3/rpc_server/srv_util.c
index 3f4d66eab2..868cf3a4ac 100644
--- a/source3/rpc_server/srv_util.c
+++ b/source3/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/source3/smbd/chgpasswd.c b/source3/smbd/chgpasswd.c
index ae1fd1a675..7494d0162d 100644
--- a/source3/smbd/chgpasswd.c
+++ b/source3/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/source3/smbd/password.c b/source3/smbd/password.c
index 74ebeb1617..bbd9f8b849 100644
--- a/source3/smbd/password.c
+++ b/source3/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/source3/smbd/reply.c b/source3/smbd/reply.c
index 7807bf8369..eaf3fe9920 100644
--- a/source3/smbd/reply.c
+++ b/source3/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/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index 2433fa1bb4..b569ba96b3 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/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;
}