summaryrefslogtreecommitdiff
path: root/source3/passdb
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
commit2a53d6f7077de596265a3e73e79827392054142c (patch)
tree9e3553f5c3210b814b14501fb2f6e6cd4a2c129b /source3/passdb
parent49ce0cab3c3ec31e08be9afb7872b8bb03371810 (diff)
downloadsamba-2a53d6f7077de596265a3e73e79827392054142c.tar.gz
samba-2a53d6f7077de596265a3e73e79827392054142c.tar.bz2
samba-2a53d6f7077de596265a3e73e79827392054142c.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. (This used to be commit 1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/smbpass.c58
1 files changed, 50 insertions, 8 deletions
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.
*************************************************************************/