mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
Make getpwnam_alloc() static to lib/username.c, and ensure all username lookups go
through Get_Pwnam_alloc(), which is the correct wrapper function. We were using it *some* of the time anyway, so this just makes us properly consistent. Jeremy. Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Wed Oct 20 16:02:12 UTC 2010 on sn-devel-104
This commit is contained in:
parent
ab01d6139f
commit
e1cfca1e2e
@ -453,7 +453,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
|
||||
lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \
|
||||
lib/username.o \
|
||||
../libds/common/flag_mapping.o \
|
||||
lib/util_pw.o lib/access.o lib/smbrun.o \
|
||||
lib/access.o lib/smbrun.o \
|
||||
lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \
|
||||
lib/wins_srv.o \
|
||||
lib/util_str.o lib/clobber.o lib/util_sid.o \
|
||||
|
@ -641,7 +641,7 @@ static NTSTATUS get_guest_info3(TALLOC_CTX *mem_ctx,
|
||||
struct passwd *pwd;
|
||||
const char *tmp;
|
||||
|
||||
pwd = getpwnam_alloc(mem_ctx, guest_account);
|
||||
pwd = Get_Pwnam_alloc(mem_ctx, guest_account);
|
||||
if (pwd == NULL) {
|
||||
DEBUG(0,("SamInfo3_for_guest: Unable to locate guest "
|
||||
"account [%s]!\n", guest_account));
|
||||
@ -793,7 +793,7 @@ NTSTATUS make_serverinfo_from_username(TALLOC_CTX *mem_ctx,
|
||||
struct passwd *pwd;
|
||||
NTSTATUS status;
|
||||
|
||||
pwd = getpwnam_alloc(talloc_tos(), username);
|
||||
pwd = Get_Pwnam_alloc(talloc_tos(), username);
|
||||
if (pwd == NULL) {
|
||||
return NT_STATUS_NO_SUCH_USER;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ NTSTATUS make_server_info_sam(struct auth_serversupplied_info **server_info,
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
if ( !(pwd = getpwnam_alloc(result, username)) ) {
|
||||
if ( !(pwd = Get_Pwnam_alloc(result, username)) ) {
|
||||
DEBUG(1, ("User %s in passdb, but getpwnam() fails!\n",
|
||||
pdb_get_username(sampass)));
|
||||
TALLOC_FREE(result);
|
||||
|
@ -757,14 +757,14 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
|
||||
* about the mapping of guest sid to lp_guestaccount()
|
||||
* username and will return the unix_pw info for a guest
|
||||
* user. Use it if it's there, else lookup the *uid details
|
||||
* using getpwnam_alloc(). See bug #6291 for details. JRA.
|
||||
* using Get_Pwnam_alloc(). See bug #6291 for details. JRA.
|
||||
*/
|
||||
|
||||
/* We must always assign the *uid. */
|
||||
if (sam_acct->unix_pw == NULL) {
|
||||
struct passwd *pwd = getpwnam_alloc(sam_acct, *found_username );
|
||||
struct passwd *pwd = Get_Pwnam_alloc(sam_acct, *found_username );
|
||||
if (!pwd) {
|
||||
DEBUG(10, ("getpwnam_alloc failed for %s\n",
|
||||
DEBUG(10, ("Get_Pwnam_alloc failed for %s\n",
|
||||
*found_username));
|
||||
result = NT_STATUS_NO_SUCH_USER;
|
||||
goto done;
|
||||
|
@ -1033,6 +1033,9 @@ bool nt_time_is_set(const NTTIME *nt);
|
||||
|
||||
/* The following definitions come from lib/username.c */
|
||||
|
||||
struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from) ;
|
||||
void flush_pwnam_cache(void);
|
||||
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) ;
|
||||
char *get_user_home_dir(TALLOC_CTX *mem_ctx, const char *user);
|
||||
struct passwd *Get_Pwnam_alloc(TALLOC_CTX *mem_ctx, const char *user);
|
||||
|
||||
@ -1221,13 +1224,6 @@ NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx,
|
||||
struct security_token **token_out);
|
||||
bool token_sid_in_ace(const struct security_token *token, const struct security_ace *ace);
|
||||
|
||||
/* The following definitions come from lib/util_pw.c */
|
||||
|
||||
struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from) ;
|
||||
void flush_pwnam_cache(void);
|
||||
struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name);
|
||||
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) ;
|
||||
|
||||
/* The following definitions come from ..libcli/registry/util_reg.c */
|
||||
|
||||
const char *str_regtype(int type);
|
||||
|
@ -3,7 +3,8 @@
|
||||
Username handling
|
||||
Copyright (C) Andrew Tridgell 1992-1998
|
||||
Copyright (C) Jeremy Allison 1997-2001.
|
||||
|
||||
Copyright (C) Andrew Bartlett 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
@ -19,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "memcache.h"
|
||||
|
||||
/* internal functions */
|
||||
static struct passwd *uname_string_combinations(char *s, TALLOC_CTX *mem_ctx,
|
||||
@ -28,6 +30,76 @@ static struct passwd *uname_string_combinations2(char *s, TALLOC_CTX *mem_ctx, i
|
||||
struct passwd * (*fn) (TALLOC_CTX *mem_ctx, const char *),
|
||||
int N);
|
||||
|
||||
static struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
|
||||
{
|
||||
struct passwd *pw, *for_cache;
|
||||
|
||||
pw = (struct passwd *)memcache_lookup_talloc(
|
||||
NULL, GETPWNAM_CACHE, data_blob_string_const_null(name));
|
||||
if (pw != NULL) {
|
||||
return tcopy_passwd(mem_ctx, pw);
|
||||
}
|
||||
|
||||
pw = sys_getpwnam(name);
|
||||
if (pw == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for_cache = tcopy_passwd(talloc_tos(), pw);
|
||||
if (for_cache == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcache_add_talloc(NULL, GETPWNAM_CACHE,
|
||||
data_blob_string_const_null(name), &for_cache);
|
||||
|
||||
return tcopy_passwd(mem_ctx, pw);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
talloc copy a struct passwd.
|
||||
****************************************************************************/
|
||||
|
||||
struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from)
|
||||
{
|
||||
struct passwd *ret = TALLOC_P(mem_ctx, struct passwd);
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
ret->pw_name = talloc_strdup(ret, from->pw_name);
|
||||
ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
|
||||
ret->pw_uid = from->pw_uid;
|
||||
ret->pw_gid = from->pw_gid;
|
||||
ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
|
||||
ret->pw_dir = talloc_strdup(ret, from->pw_dir);
|
||||
ret->pw_shell = talloc_strdup(ret, from->pw_shell);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Flush all cached passwd structs.
|
||||
****************************************************************************/
|
||||
|
||||
void flush_pwnam_cache(void)
|
||||
{
|
||||
memcache_flush(NULL, GETPWNAM_CACHE);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
talloc'ed version of getpwuid.
|
||||
****************************************************************************/
|
||||
|
||||
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
|
||||
{
|
||||
struct passwd *temp = sys_getpwuid(uid);
|
||||
|
||||
if (!temp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tcopy_passwd(mem_ctx, temp);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Get a users home directory.
|
||||
****************************************************************************/
|
||||
|
@ -1306,7 +1306,7 @@ uid_t nametouid(const char *name)
|
||||
char *p;
|
||||
uid_t u;
|
||||
|
||||
pass = getpwnam_alloc(talloc_tos(), name);
|
||||
pass = Get_Pwnam_alloc(talloc_tos(), name);
|
||||
if (pass) {
|
||||
u = pass->pw_uid;
|
||||
TALLOC_FREE(pass);
|
||||
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Safe versions of getpw* calls
|
||||
|
||||
Copyright (C) Andrew Bartlett 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "memcache.h"
|
||||
|
||||
struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from)
|
||||
{
|
||||
struct passwd *ret = TALLOC_P(mem_ctx, struct passwd);
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
ret->pw_name = talloc_strdup(ret, from->pw_name);
|
||||
ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
|
||||
ret->pw_uid = from->pw_uid;
|
||||
ret->pw_gid = from->pw_gid;
|
||||
ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
|
||||
ret->pw_dir = talloc_strdup(ret, from->pw_dir);
|
||||
ret->pw_shell = talloc_strdup(ret, from->pw_shell);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void flush_pwnam_cache(void)
|
||||
{
|
||||
memcache_flush(NULL, GETPWNAM_CACHE);
|
||||
}
|
||||
|
||||
struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
|
||||
{
|
||||
struct passwd *pw, *for_cache;
|
||||
|
||||
pw = (struct passwd *)memcache_lookup_talloc(
|
||||
NULL, GETPWNAM_CACHE, data_blob_string_const_null(name));
|
||||
if (pw != NULL) {
|
||||
return tcopy_passwd(mem_ctx, pw);
|
||||
}
|
||||
|
||||
pw = sys_getpwnam(name);
|
||||
if (pw == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for_cache = tcopy_passwd(talloc_tos(), pw);
|
||||
if (for_cache == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcache_add_talloc(NULL, GETPWNAM_CACHE,
|
||||
data_blob_string_const_null(name), &for_cache);
|
||||
|
||||
return tcopy_passwd(mem_ctx, pw);
|
||||
}
|
||||
|
||||
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
|
||||
{
|
||||
struct passwd *temp;
|
||||
|
||||
temp = sys_getpwuid(uid);
|
||||
|
||||
if (!temp) {
|
||||
#if 0
|
||||
if (errno == ENOMEM) {
|
||||
/* what now? */
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tcopy_passwd(mem_ctx, temp);
|
||||
}
|
@ -352,7 +352,7 @@ static bool guest_user_info( struct samu *user )
|
||||
NTSTATUS result;
|
||||
const char *guestname = lp_guestaccount();
|
||||
|
||||
pwd = getpwnam_alloc(talloc_tos(), guestname);
|
||||
pwd = Get_Pwnam_alloc(talloc_tos(), guestname);
|
||||
if (pwd == NULL) {
|
||||
DEBUG(0,("guest_user_info: Unable to locate guest account [%s]!\n",
|
||||
guestname));
|
||||
@ -1546,7 +1546,7 @@ static NTSTATUS pdb_default_enum_group_memberships(struct pdb_methods *methods,
|
||||
/* Ignore the primary group SID. Honor the real Unix primary group.
|
||||
The primary group SID is only of real use to Windows clients */
|
||||
|
||||
if ( !(pw = getpwnam_alloc(mem_ctx, username)) ) {
|
||||
if ( !(pw = Get_Pwnam_alloc(mem_ctx, username)) ) {
|
||||
return NT_STATUS_NO_SUCH_USER;
|
||||
}
|
||||
|
||||
|
@ -1198,9 +1198,9 @@ static bool build_smb_pass (struct smb_passwd *smb_pw, const struct samu *sampas
|
||||
|
||||
/* If the user specified a RID, make sure its able to be both stored and retreived */
|
||||
if (rid == DOMAIN_RID_GUEST) {
|
||||
struct passwd *passwd = getpwnam_alloc(NULL, lp_guestaccount());
|
||||
struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guestaccount());
|
||||
if (!passwd) {
|
||||
DEBUG(0, ("Could not find guest account via getpwnam()! (%s)\n", lp_guestaccount()));
|
||||
DEBUG(0, ("Could not find guest account via Get_Pwnam_alloc()! (%s)\n", lp_guestaccount()));
|
||||
return False;
|
||||
}
|
||||
smb_pw->smb_userid=passwd->pw_uid;
|
||||
|
@ -64,7 +64,7 @@ bool lookup_unix_user_name(const char *name, struct dom_sid *sid)
|
||||
struct passwd *pwd;
|
||||
bool ret;
|
||||
|
||||
pwd = getpwnam_alloc(talloc_tos(), name);
|
||||
pwd = Get_Pwnam_alloc(talloc_tos(), name);
|
||||
if (pwd == NULL) {
|
||||
return False;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ int register_homes_share(const char *username)
|
||||
return result;
|
||||
}
|
||||
|
||||
pwd = getpwnam_alloc(talloc_tos(), username);
|
||||
pwd = Get_Pwnam_alloc(talloc_tos(), username);
|
||||
|
||||
if ((pwd == NULL) || (pwd->pw_dir[0] == '\0')) {
|
||||
DEBUG(3, ("No home directory defined for user '%s'\n",
|
||||
|
@ -33,7 +33,7 @@ bool change_to_guest(void)
|
||||
{
|
||||
struct passwd *pass;
|
||||
|
||||
pass = getpwnam_alloc(talloc_tos(), lp_guestaccount());
|
||||
pass = Get_Pwnam_alloc(talloc_tos(), lp_guestaccount());
|
||||
if (!pass) {
|
||||
return false;
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((pwd = getpwnam_alloc(ctx, unix_user)) == NULL) {
|
||||
if ((pwd = Get_Pwnam_alloc(ctx, unix_user)) == NULL) {
|
||||
fprintf(stderr, "Error getting user information for %s\n", unix_user);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1856,7 +1856,7 @@ doma_done:
|
||||
|
||||
sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
|
||||
|
||||
pwd = getpwnam_alloc(tc, lp_guestaccount());
|
||||
pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
|
||||
|
||||
if (!pwd) {
|
||||
if (domusers_gid == -1) {
|
||||
@ -1927,7 +1927,7 @@ doma_done:
|
||||
|
||||
d_printf(_("Checking Guest's group.\n"));
|
||||
|
||||
pwd = getpwnam_alloc(tc, lp_guestaccount());
|
||||
pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
|
||||
if (!pwd) {
|
||||
d_fprintf(stderr,
|
||||
_("Failed to find just created Guest account!\n"
|
||||
|
@ -314,7 +314,7 @@ static void cgi_web_auth(void)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pwd = getpwnam_alloc(talloc_tos(), user);
|
||||
pwd = Get_Pwnam_alloc(talloc_tos(), user);
|
||||
if (!pwd) {
|
||||
printf("%sCannot find user %s<br>%s\n", head, user, tail);
|
||||
exit(0);
|
||||
@ -369,7 +369,7 @@ static bool cgi_handle_authorization(char *line)
|
||||
* Try and get the user from the UNIX password file.
|
||||
*/
|
||||
|
||||
pass = getpwnam_alloc(talloc_tos(), user);
|
||||
pass = Get_Pwnam_alloc(talloc_tos(), user);
|
||||
|
||||
rhost = client_name(1);
|
||||
if (strequal(rhost,"UNKNOWN"))
|
||||
|
@ -178,7 +178,7 @@ LIB_SRC = '''${LIBSAMBAUTIL_SRC} ${UTIL_SRC}
|
||||
lib/system.c lib/sendfile.c lib/recvfile.c lib/time.c
|
||||
lib/username.c
|
||||
../libds/common/flag_mapping.c
|
||||
lib/util_pw.c lib/access.c lib/smbrun.c
|
||||
lib/access.c lib/smbrun.c
|
||||
lib/bitmap.c lib/dprintf.c ${UTIL_REG_SRC}
|
||||
lib/wins_srv.c
|
||||
lib/util_str.c lib/clobber.c lib/util_sid.c
|
||||
|
Loading…
Reference in New Issue
Block a user