mirror of
https://github.com/samba-team/samba.git
synced 2025-02-04 17:47:26 +03:00
pdb_getsampwnuid() merge from 2.2
This commit is contained in:
parent
a076e2e4c5
commit
54cbfc7ebc
@ -1793,4 +1793,33 @@ BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
|
|||||||
return True;
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -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
|
Delete entry from LDAP for username
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
@ -1018,46 +1018,6 @@ BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
|
|||||||
return ret;
|
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
|
Routine to remove entry from the nisplus smbpasswd table
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
@ -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)
|
BOOL pdb_getsampwrid(SAM_ACCOUNT *sam_acct,uint32 rid)
|
||||||
{
|
{
|
||||||
struct smb_passwd *smb_pw;
|
struct smb_passwd *smb_pw;
|
||||||
|
@ -541,31 +541,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname)
|
|||||||
return True;
|
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
|
Search by rid
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user