iteration of sam passwd entries was an order n-cubed algorithm due
authorLuke Leighton <lkcl@samba.org>
Mon, 8 Feb 1999 00:24:57 +0000 (00:24 +0000)
committerLuke Leighton <lkcl@samba.org>
Mon, 8 Feb 1999 00:24:57 +0000 (00:24 +0000)
to resolution of unix name to nt name being unnecessarily _inside_
another loop.
(This used to be commit d455c9d2c9f60289d78d0331228f5922152070bf)

source3/include/proto.h
source3/passdb/sampass.c
source3/passdb/smbpass.c

index bf5f8076fe4c63ce23c114075202732a17c474b9..301fcbe755e43c354c1f7fe5fdfb18a49401f21e 100644 (file)
@@ -1449,10 +1449,6 @@ struct passgrp_ops *ldap_initialise_password_grp(void);
 
 /*The following definitions come from  passdb/sampass.c  */
 
-void *startsamfilepwent(BOOL update);
-void endsamfilepwent(void *vp);
-SMB_BIG_UINT getsamfilepwpos(void *vp);
-BOOL setsamfilepwpos(void *vp, SMB_BIG_UINT tok);
 struct sam_passdb_ops *file_initialise_sam_password_db(void);
 
 /*The following definitions come from  passdb/sampassdb.c  */
@@ -1481,6 +1477,7 @@ struct sam_passdb_ops *ldap_initialise_sam_password_db(void);
 
 /*The following definitions come from  passdb/smbpass.c  */
 
+struct smb_passwd *getsmbfilepwent(void *vp);
 struct smb_passdb_ops *file_initialise_password_db(void);
 
 /*The following definitions come from  passdb/smbpasschange.c  */
index c15b20c11eed87f5a18f786d1e1d2bf9a9578ee1..28d28150ecb9a7b126375ffda13ffb2eb6a0e43e 100644 (file)
@@ -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
index b1ca9ad0717c72f46088a0267e9aa108cfef9a18..694cceb39f6e94ca2e0c9d4ddbe9e35e45cb0797 100644 (file)
@@ -68,8 +68,11 @@ static BOOL setsmbfilepwpos(void *vp, SMB_BIG_UINT tok)
 
 /*************************************************************************
  Routine to return the next entry in the smbpasswd list.
+
+ this function is non-static as it is called (exclusively and only)
+ from getsamfile21pwent().
  *************************************************************************/
-static struct smb_passwd *getsmbfilepwent(void *vp)
+struct smb_passwd *getsmbfilepwent(void *vp)
 {
        /* Static buffers we will return. */
        static struct smb_passwd pw_buf;