diff options
author | Cliff Woolley <jwoolley@apache.org> | 2001-02-21 18:41:29 +0000 |
---|---|---|
committer | Cliff Woolley <jwoolley@apache.org> | 2001-02-21 18:41:29 +0000 |
commit | 60ea2d762ddbee601ea05cf6e444b8f518e91a55 (patch) | |
tree | f84a6fe1474ef9377f60875441697fd937427e3f /user/unix | |
parent | 0e21821dc0cae1147173fc4d8fa8de7ba4cafb4e (diff) | |
download | apr-60ea2d762ddbee601ea05cf6e444b8f518e91a55.tar.gz |
Added apr_get_userid() as a companion to apr_get_username().
PR: Needed to fix Apache PR7271.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@61275 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'user/unix')
-rw-r--r-- | user/unix/userinfo.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/user/unix/userinfo.c b/user/unix/userinfo.c index 307296925..cc2e98cfd 100644 --- a/user/unix/userinfo.c +++ b/user/unix/userinfo.c @@ -63,19 +63,32 @@ #include <sys/types.h> #endif -APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, const char *userid, apr_pool_t *p) +static apr_status_t getpwnam_safe(const char *username, + struct passwd **pw) { - struct passwd *pw; #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) struct passwd pwd; char pwbuf[512]; - if (getpwnam_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw)) { + if (getpwnam_r(username, &pwd, pwbuf, sizeof(pwbuf), pw)) { #else - if ((pw = getpwnam(userid)) == NULL) { + if ((*pw = getpwnam(username)) == NULL) { #endif return errno; } + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, + const char *username, + apr_pool_t *p) +{ + struct passwd *pw; + apr_status_t rv; + + if ((rv = getpwnam_safe(username, &pw)) != APR_SUCCESS) + return rv; + #ifdef OS2 /* Need to manually add user name for OS/2 */ *dirname = apr_pstrcat(p, pw->pw_dir, pw->pw_name, NULL); @@ -85,6 +98,21 @@ APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, const char *use return APR_SUCCESS; } +APR_DECLARE(apr_status_t) apr_get_userid(apr_uid_t *uid, apr_gid_t *gid, + const char *username) +{ + struct passwd *pw; + apr_status_t rv; + + if ((rv = getpwnam_safe(username, &pw)) != APR_SUCCESS) + return rv; + + *uid = pw->pw_uid; + *gid = pw->pw_gid; + + return APR_SUCCESS; +} + APR_DECLARE(apr_status_t) apr_get_username(char **username, apr_uid_t userid, apr_pool_t *p) { struct passwd *pw; |