summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/auth/auth_util.c4
-rw-r--r--source3/auth/server_info_sam.c2
-rw-r--r--source3/auth/token_util.c6
-rw-r--r--source3/include/proto.h10
-rw-r--r--source3/lib/username.c74
-rw-r--r--source3/lib/util.c2
-rw-r--r--source3/lib/util_pw.c88
-rw-r--r--source3/passdb/pdb_interface.c4
-rw-r--r--source3/passdb/pdb_smbpasswd.c4
-rw-r--r--source3/passdb/util_unixsids.c2
-rw-r--r--source3/smbd/password.c2
-rw-r--r--source3/smbd/uid.c2
-rw-r--r--source3/torture/pdbtest.c2
-rw-r--r--source3/utils/net_sam.c4
-rw-r--r--source3/web/cgi.c4
-rw-r--r--source3/wscript_build2
17 files changed, 97 insertions, 117 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 86cd88af64..5d390def48 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -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 \
diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c
index 73713093c2..2fcee89bbb 100644
--- a/source3/auth/auth_util.c
+++ b/source3/auth/auth_util.c
@@ -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;
}
diff --git a/source3/auth/server_info_sam.c b/source3/auth/server_info_sam.c
index 4731ad44f1..c09ae764b9 100644
--- a/source3/auth/server_info_sam.c
+++ b/source3/auth/server_info_sam.c
@@ -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);
diff --git a/source3/auth/token_util.c b/source3/auth/token_util.c
index 1a7c4816e8..4a702ef230 100644
--- a/source3/auth/token_util.c
+++ b/source3/auth/token_util.c
@@ -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;
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 9a8cf67756..3e4655eeb5 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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);
diff --git a/source3/lib/username.c b/source3/lib/username.c
index 3087bac0f4..afe83acfd9 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -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.
****************************************************************************/
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 36d966126e..36b2e422e2 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -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);
diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c
deleted file mode 100644
index 5ba5fde0eb..0000000000
--- a/source3/lib/util_pw.c
+++ /dev/null
@@ -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);
-}
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index a0913a3ea9..a6fe2e0408 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -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;
}
diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index f188399f78..8d6ac318cb 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -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;
diff --git a/source3/passdb/util_unixsids.c b/source3/passdb/util_unixsids.c
index ce64dc2d88..1f830b35c5 100644
--- a/source3/passdb/util_unixsids.c
+++ b/source3/passdb/util_unixsids.c
@@ -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;
}
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index afe4f1b91f..cbe4d62595 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -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",
diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c
index 2b16d05b7c..dd6af6d9c0 100644
--- a/source3/smbd/uid.c
+++ b/source3/smbd/uid.c
@@ -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;
}
diff --git a/source3/torture/pdbtest.c b/source3/torture/pdbtest.c
index cb61489f00..6745ab0f7d 100644
--- a/source3/torture/pdbtest.c
+++ b/source3/torture/pdbtest.c
@@ -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);
}
diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c
index 51d49849ae..8a9ca8ad18 100644
--- a/source3/utils/net_sam.c
+++ b/source3/utils/net_sam.c
@@ -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"
diff --git a/source3/web/cgi.c b/source3/web/cgi.c
index 1a472a77c7..e3356a2f7e 100644
--- a/source3/web/cgi.c
+++ b/source3/web/cgi.c
@@ -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"))
diff --git a/source3/wscript_build b/source3/wscript_build
index 9f781741b3..75025970ac 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -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