summaryrefslogtreecommitdiff
path: root/source3/passdb/sampass.c
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-02-08 00:24:57 +0000
committerLuke Leighton <lkcl@samba.org>1999-02-08 00:24:57 +0000
commit6d698d51b324f84b2d2b4c56ea1e728c0c30b220 (patch)
treee34e22ff61ff463f7d3fd2d5ef94dc2757d5daf0 /source3/passdb/sampass.c
parentceef08b60e1fc3839df89b27028aa9ac0f920f25 (diff)
downloadsamba-6d698d51b324f84b2d2b4c56ea1e728c0c30b220.tar.gz
samba-6d698d51b324f84b2d2b4c56ea1e728c0c30b220.tar.bz2
samba-6d698d51b324f84b2d2b4c56ea1e728c0c30b220.zip
iteration of sam passwd entries was an order n-cubed algorithm due
to resolution of unix name to nt name being unnecessarily _inside_ another loop. (This used to be commit d455c9d2c9f60289d78d0331228f5922152070bf)
Diffstat (limited to 'source3/passdb/sampass.c')
-rw-r--r--source3/passdb/sampass.c107
1 files changed, 87 insertions, 20 deletions
diff --git a/source3/passdb/sampass.c b/source3/passdb/sampass.c
index c15b20c11e..28d28150ec 100644
--- a/source3/passdb/sampass.c
+++ b/source3/passdb/sampass.c
@@ -32,7 +32,7 @@ extern DOM_SID global_sam_sid;
to ensure no modification outside this module.
****************************************************************/
-void *startsamfilepwent(BOOL update)
+static void *startsamfilepwent(BOOL update)
{
return startsmbpwent(update);
}
@@ -41,7 +41,7 @@ void *startsamfilepwent(BOOL update)
End enumeration of the smbpasswd list.
****************************************************************/
-void endsamfilepwent(void *vp)
+static void endsamfilepwent(void *vp)
{
endsmbpwent(vp);
}
@@ -51,7 +51,7 @@ void endsamfilepwent(void *vp)
This must be treated as an opaque token.
*************************************************************************/
-SMB_BIG_UINT getsamfilepwpos(void *vp)
+static SMB_BIG_UINT getsamfilepwpos(void *vp)
{
return getsmbpwpos(vp);
}
@@ -61,7 +61,7 @@ SMB_BIG_UINT getsamfilepwpos(void *vp)
This must be treated as an opaque token.
*************************************************************************/
-BOOL setsamfilepwpos(void *vp, SMB_BIG_UINT tok)
+static BOOL setsamfilepwpos(void *vp, SMB_BIG_UINT tok)
{
return setsmbpwpos(vp, tok);
}
@@ -88,7 +88,7 @@ static struct sam_passwd *getsamfile21pwent(void *vp)
DEBUG(5,("getsamfile21pwent\n"));
- user = pwdb_smb_to_sam(getsmbpwent(vp));
+ user = pwdb_smb_to_sam(getsmbfilepwent(vp));
if (user == NULL)
{
return NULL;
@@ -143,6 +143,72 @@ static struct sam_passwd *getsamfile21pwent(void *vp)
return user;
}
+/************************************************************************
+search sam db by uid.
+*************************************************************************/
+static struct sam_passwd *getsamfilepwuid(uid_t uid)
+{
+ struct sam_passwd *pwd = NULL;
+ void *fp = NULL;
+
+ DEBUG(10, ("search by uid: %x\n", (int)uid));
+
+ /* Open the smb password file - not for update. */
+ fp = startsam21pwent(False);
+
+ if (fp == NULL)
+ {
+ DEBUG(0, ("unable to open sam password database.\n"));
+ return NULL;
+ }
+
+ while ((pwd = getsamfile21pwent(fp)) != NULL && pwd->unix_uid != uid)
+ {
+ }
+
+ if (pwd != NULL)
+ {
+ DEBUG(10, ("found by unix_uid: %x\n", (int)uid));
+ }
+
+ endsam21pwent(fp);
+
+ return pwd;
+}
+
+/************************************************************************
+search sam db by rid.
+*************************************************************************/
+static struct sam_passwd *getsamfilepwrid(uint32 user_rid)
+{
+ DOM_NAME_MAP gmep;
+ DOM_SID sid;
+ sid_copy(&sid, &global_sam_sid);
+ sid_append_rid(&sid, user_rid);
+
+ if (!lookupsmbpwsid(&sid, &gmep))
+ {
+ return NULL;
+ }
+
+ return getsamfilepwuid((uid_t)gmep.unix_id);
+}
+
+/************************************************************************
+search sam db by nt name.
+*************************************************************************/
+static struct sam_passwd *getsamfilepwntnam(const char *nt_name)
+{
+ DOM_NAME_MAP gmep;
+
+ if (!lookupsmbpwntnam(nt_name, &gmep))
+ {
+ return NULL;
+ }
+
+ return getsamfilepwuid((uid_t)gmep.unix_id);
+}
+
/*
* Stub functions - implemented in terms of others.
*/
@@ -172,25 +238,26 @@ static struct sam_disp_info *getsamfiledispent(void *vp)
return pwdb_sam_to_dispinfo(getsam21pwent(vp));
}
-static struct sam_passdb_ops file_ops = {
- startsamfilepwent,
- endsamfilepwent,
- getsamfilepwpos,
- setsamfilepwpos,
- iterate_getsam21pwntnam,
- iterate_getsam21pwuid,
- iterate_getsam21pwrid,
- getsamfile21pwent,
- add_samfile21pwd_entry,
- mod_samfile21pwd_entry,
- getsamfiledispntnam,
- getsamfiledisprid,
- getsamfiledispent
+static struct sam_passdb_ops sam_file_ops =
+{
+ startsamfilepwent,
+ endsamfilepwent,
+ getsamfilepwpos,
+ setsamfilepwpos,
+ getsamfilepwntnam,
+ getsamfilepwuid,
+ getsamfilepwrid,
+ getsamfile21pwent,
+ add_samfile21pwd_entry,
+ mod_samfile21pwd_entry,
+ getsamfiledispntnam,
+ getsamfiledisprid,
+ getsamfiledispent
};
struct sam_passdb_ops *file_initialise_sam_password_db(void)
{
- return &file_ops;
+ return &sam_file_ops;
}
#else