diff options
author | Simo Sorce <idra@samba.org> | 2008-02-01 14:24:31 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2008-02-01 14:24:31 -0500 |
commit | 2fffc9a1b1fe2a1490e867bb38462e50c282d2b3 (patch) | |
tree | 428e09c9b35138db8b7ca7161c659a71aa129d29 /source3/lib/username.c | |
parent | 93a3c5b3f9927973b4ad1496f593ea147052d1e1 (diff) | |
parent | b708005a7106db26d7df689b887b419c9f2ea41c (diff) | |
download | samba-2fffc9a1b1fe2a1490e867bb38462e50c282d2b3.tar.gz samba-2fffc9a1b1fe2a1490e867bb38462e50c282d2b3.tar.xz samba-2fffc9a1b1fe2a1490e867bb38462e50c282d2b3.zip |
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
(This used to be commit 7dbfc7bdc65314466a83e8121b35c9bcb24b2631)
Diffstat (limited to 'source3/lib/username.c')
-rw-r--r-- | source3/lib/username.c | 49 |
1 files changed, 9 insertions, 40 deletions
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 |