From 98010a076797f4d05d8c9bff45e65c076f30da3a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 30 Dec 2001 00:03:47 +0000 Subject: pdb_getsampwnuid() merge from 2.2 (This used to be commit 54cbfc7ebcdf1bd2094407b689b0050f0abfa46f) --- source3/passdb/passdb.c | 29 +++++++++++++++++++++++++ source3/passdb/pdb_ldap.c | 49 ------------------------------------------ source3/passdb/pdb_nisplus.c | 40 ---------------------------------- source3/passdb/pdb_smbpasswd.c | 42 ------------------------------------ source3/passdb/pdb_tdb.c | 25 --------------------- 5 files changed, 29 insertions(+), 156 deletions(-) (limited to 'source3/passdb') diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index ca7c508dc5..eeecc0abe5 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -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); + +} diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c index a6593491d0..215292be48 100644 --- a/source3/passdb/pdb_ldap.c +++ b/source3/passdb/pdb_ldap.c @@ -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 *********************************************************************/ diff --git a/source3/passdb/pdb_nisplus.c b/source3/passdb/pdb_nisplus.c index 27dd420f3f..c2505b99f5 100644 --- a/source3/passdb/pdb_nisplus.c +++ b/source3/passdb/pdb_nisplus.c @@ -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 *************************************************************************/ diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index 8e942a60fb..e82e94dae5 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -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; diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 08439a9d20..fbfdd1aace 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -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 **************************************************************************/ -- cgit