summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/substitute.c26
-rw-r--r--source3/lib/username.c49
2 files changed, 26 insertions, 49 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
index e06917c8fb..80feee9579 100644
--- a/source3/lib/substitute.c
+++ b/source3/lib/substitute.c
@@ -408,7 +408,7 @@ static const char *automount_path(const char *user_name)
/* use the passwd entry as the default */
/* this will be the default if WITH_AUTOMOUNT is not used or fails */
- server_path = talloc_strdup(ctx, get_user_home_dir(user_name));
+ server_path = talloc_strdup(ctx, get_user_home_dir(ctx, user_name));
if (!server_path) {
return "";
}
@@ -541,7 +541,6 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
{
char *b, *p, *s, *r, *a_string;
fstring pidstr, vnnstr;
- struct passwd *pass;
char addr[INET6_ADDRSTRLEN];
const char *local_machine_name = get_local_machine_name();
@@ -571,15 +570,21 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
}
a_string = realloc_string_sub(a_string, "%U", r);
break;
- case 'G' :
+ case 'G' : {
+ struct passwd *pass;
r = SMB_STRDUP(smb_name);
if (r == NULL) {
goto error;
}
- if ((pass = Get_Pwnam(r))!=NULL) {
- a_string = realloc_string_sub(a_string, "%G", gidtoname(pass->pw_gid));
- }
+ pass = Get_Pwnam_alloc(talloc_tos(), r);
+ if (pass != NULL) {
+ a_string = realloc_string_sub(
+ a_string, "%G",
+ gidtoname(pass->pw_gid));
+ }
+ TALLOC_FREE(pass);
break;
+ }
case 'D' :
r = strdup_upper(domain_name);
if (r == NULL) {
@@ -766,7 +771,7 @@ static char *alloc_sub_advanced(const char *servicename, const char *user,
const char *str)
{
char *a_string, *ret_string;
- char *b, *p, *s, *h;
+ char *b, *p, *s;
a_string = SMB_STRDUP(str);
if (a_string == NULL) {
@@ -782,10 +787,13 @@ static char *alloc_sub_advanced(const char *servicename, const char *user,
case 'N' :
a_string = realloc_string_sub(a_string, "%N", automount_server(user));
break;
- case 'H':
- if ((h = get_user_home_dir(user)))
+ case 'H': {
+ char *h;
+ if ((h = get_user_home_dir(talloc_tos(), user)))
a_string = realloc_string_sub(a_string, "%H", h);
+ TALLOC_FREE(h);
break;
+ }
case 'P':
a_string = realloc_string_sub(a_string, "%P", connectpath);
break;
diff --git a/source3/lib/username.c b/source3/lib/username.c
index 21eed9f5fc..3087bac0f4 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -32,19 +32,24 @@ static struct passwd *uname_string_combinations2(char *s, TALLOC_CTX *mem_ctx, i
Get a users home directory.
****************************************************************************/
-char *get_user_home_dir(const char *user)
+char *get_user_home_dir(TALLOC_CTX *mem_ctx, const char *user)
{
- static struct passwd *pass;
+ struct passwd *pass;
+ char *result;
/* Ensure the user exists. */
- pass = Get_Pwnam(user);
+ pass = Get_Pwnam_alloc(mem_ctx, user);
if (!pass)
return(NULL);
+
/* Return home directory from struct passwd. */
- return(pass->pw_dir);
+ result = talloc_move(mem_ctx, &pass->pw_dir);
+
+ TALLOC_FREE(pass);
+ return result;
}
/****************************************************************************
@@ -55,8 +60,6 @@ char *get_user_home_dir(const char *user)
* - using lp_usernamelevel() for permutations.
****************************************************************************/
-static struct passwd *Get_Pwnam_ret = NULL;
-
static struct passwd *Get_Pwnam_internals(TALLOC_CTX *mem_ctx,
const char *user, char *user2)
{
@@ -134,40 +137,6 @@ struct passwd *Get_Pwnam_alloc(TALLOC_CTX *mem_ctx, const char *user)
return ret;
}
-/****************************************************************************
- Get_Pwnam wrapper without modification.
- NOTE: This with NOT modify 'user'!
-****************************************************************************/
-
-struct passwd *Get_Pwnam(const char *user)
-{
- struct passwd *ret;
-
- ret = Get_Pwnam_alloc(NULL, user);
-
- /* This call used to just return the 'passwd' static buffer.
- This could then have accidental reuse implications, so
- we now malloc a copy, and free it in the next use.
-
- This should cause the (ab)user to segfault if it
- uses an old struct.
-
- This is better than useing the wrong data in security
- critical operations.
-
- The real fix is to make the callers free the returned
- malloc'ed data.
- */
-
- if (Get_Pwnam_ret) {
- TALLOC_FREE(Get_Pwnam_ret);
- }
-
- Get_Pwnam_ret = ret;
-
- return ret;
-}
-
/* The functions below have been taken from password.c and slightly modified */
/****************************************************************************
Apply a function to upper/lower case combinations