pdb_getsampwnuid() merge from 2.2
authorGerald Carter <jerry@samba.org>
Sun, 30 Dec 2001 00:03:47 +0000 (00:03 +0000)
committerGerald Carter <jerry@samba.org>
Sun, 30 Dec 2001 00:03:47 +0000 (00:03 +0000)
source/passdb/passdb.c
source/passdb/pdb_ldap.c
source/passdb/pdb_nisplus.c
source/passdb/pdb_smbpasswd.c
source/passdb/pdb_tdb.c

index ca7c508dc5c532c702fe3d08a9415121ca0be2a2..eeecc0abe5940091af5dfd19d6023822952aa562 100644 (file)
@@ -1793,4 +1793,33 @@ BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
        return True;
 }
 
+/***************************************************************************
+ Search by uid.  Wrapper around pdb_getsampwnam()
+ **************************************************************************/
+
+BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid)
+{
+       struct passwd   *pw;
+       fstring         name;
+
+       if (user==NULL) {
+               DEBUG(0,("pdb_getsampwuid: SAM_ACCOUNT is NULL.\n"));
+               return False;
+       }
+
+       /*
+        * Never trust the uid in the passdb.  Lookup the username first
+        * and then lokup the user by name in the sam.
+        */
+        
+       if ((pw=sys_getpwuid(uid)) == NULL)  {
+               DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist in Unix accounts!\n", uid));
+               return False;
+       }
+       
+       fstrcpy (name, pw->pw_name);
+
+       return pdb_getsampwnam (user, name);
+
+}
 
index a6593491d01d632dcd76cbc8dff433568b164f3d..215292be48d168816ba85756d5e0b34bb887d98a 100644 (file)
@@ -781,55 +781,6 @@ BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
        }
 }
 
-/**********************************************************************
- Get SAM_ACCOUNT entry from LDAP by uid 
-*********************************************************************/
-BOOL pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
-{
-       LDAP *ldap_struct;
-       LDAPMessage *result;
-       LDAPMessage *entry;
-
-       if (!ldap_open_connection(&ldap_struct))
-               return False;
-
-       if (!ldap_connect_system(ldap_struct))
-       {
-               ldap_unbind(ldap_struct);
-               return False;
-       }
-       if (ldap_search_one_user_by_uid(ldap_struct, uid, &result) !=
-           LDAP_SUCCESS)
-       {
-               ldap_unbind(ldap_struct);
-               return False;
-       }
-
-       if (ldap_count_entries(ldap_struct, result) < 1)
-       {
-               DEBUG(0,
-                     ("We don't find this uid [%i] count=%d\n", uid,
-                      ldap_count_entries(ldap_struct, result)));
-               ldap_unbind(ldap_struct);
-               return False;
-       }
-       entry = ldap_first_entry(ldap_struct, result);
-       if (entry)
-       {
-               init_sam_from_ldap(user, ldap_struct, entry);
-               ldap_msgfree(result);
-               ldap_unbind(ldap_struct);
-               return True;
-       }
-       else
-       {
-               ldap_msgfree(result);
-               ldap_unbind(ldap_struct);
-               return False;
-       }
-}
-
-
 /**********************************************************************
 Delete entry from LDAP for username 
 *********************************************************************/
index 27dd420f3f413980e26e6039698eaf8fff8ae12e..c2505b99f561b8cb6916eac69fb8d2495e0afbd4 100644 (file)
@@ -1018,46 +1018,6 @@ BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
        return ret;
 }
 
-/*************************************************************************
- Routine to search the nisplus passwd file for an entry matching the username
- *************************************************************************/
-BOOL pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
-{
-       nis_result *result;
-       char *nisname;
-       BOOL ret;
-       char *sp, *p = lp_smb_passwd_file();
-       pstring pfiletmp;
-
-       if (!*p)
-       {
-               DEBUG(0, ("no SMB password file set\n"));
-               return False;
-       }
-
-       if( (sp = strrchr( p, '/' )) )
-          safe_strcpy(pfiletmp, sp+1, sizeof(pfiletmp)-1);
-        else
-          safe_strcpy(pfiletmp, p, sizeof(pfiletmp)-1);
-        safe_strcat(pfiletmp, ".org_dir", sizeof(pfiletmp)-strlen(pfiletmp)-1);
-
-       nisname = make_nisname_from_uid(uid, pfiletmp);
-
-       DEBUG(10, ("search by uid: %s\n", nisname));
-
-       /* Search the table. */
-
-       if(!(result = nisp_get_nis_list(nisname, 0)))
-       {
-               return False;
-       }
-
-       ret = make_sam_from_nisresult(user, result);
-       nis_freeresult(result);
-
-       return ret;
-}
-
 /*************************************************************************
  Routine to remove entry from the nisplus smbpasswd table
  *************************************************************************/
index 8e942a60fb4375fba73006b71dc21373773642ee..e82e94dae5ca4b2f9edf4b8329dc04a770b86f99 100644 (file)
@@ -1418,48 +1418,6 @@ BOOL pdb_getsampwnam(SAM_ACCOUNT *sam_acct, const char *username)
 }
 
 
-BOOL pdb_getsampwuid (SAM_ACCOUNT *sam_acct, uid_t uid)
-{
-       struct smb_passwd *smb_pw;
-       void *fp = NULL;
-
-       DEBUG(10, ("pdb_getsampwuid: search by uid: %d\n", (int)uid));
-
-       /* Open the sam password file - not for update. */
-       fp = startsmbfilepwent(lp_smb_passwd_file(), PWF_READ, &pw_file_lock_depth);
-
-       if (fp == NULL) {
-               DEBUG(0, ("unable to open passdb database.\n"));
-               return False;
-       }
-
-       while ( ((smb_pw=getsmbfilepwent(fp)) != NULL) && (smb_pw->smb_userid != uid) )
-               /* do nothing */ ;
-
-       endsmbfilepwent(fp, &pw_file_lock_depth);
-
-       /* did we locate the username in smbpasswd  */
-       if (smb_pw == NULL)
-               return False;
-       
-       DEBUG(10, ("pdb_getsampwuid: found by name: %s\n", smb_pw->smb_name));
-               
-       if (!sam_acct) {
-               DEBUG(10,("pdb_getsampwuid:SAM_ACCOUNT is NULL\n"));
-#if 0
-               smb_panic("NULL pointer passed to pdb_getsampwuid\n");
-#endif
-               return False;
-       }
-
-       /* now build the SAM_ACCOUNT */
-       if (!build_sam_account(sam_acct, smb_pw))
-               return False;
-
-       /* success */
-       return True;
-}
-
 BOOL pdb_getsampwrid(SAM_ACCOUNT *sam_acct,uint32 rid)
 {
        struct smb_passwd *smb_pw;
index 08439a9d206964d3c1fd0c625a5f97a63545571d..fbfdd1aace229327cb581a5d082ffb57d2bff3d0 100644 (file)
@@ -541,31 +541,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname)
        return True;
 }
 
-/***************************************************************************
- Search by uid
- **************************************************************************/
-
-BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid)
-{
-       struct passwd   *pw;
-       fstring         name;
-
-       if (user==NULL) {
-               DEBUG(0,("pdb_getsampwuid: SAM_ACCOUNT is NULL.\n"));
-               return False;
-       }
-
-       pw = sys_getpwuid(uid);
-       if (pw == NULL) {
-               DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist!\n", uid));
-               return False;
-       }
-       fstrcpy (name, pw->pw_name);
-
-       return pdb_getsampwnam (user, name);
-
-}
-
 /***************************************************************************
  Search by rid
  **************************************************************************/