From d6f6b30b3ec0c2323474a7d5c80795ba1e6cec25 Mon Sep 17 00:00:00 2001 From: jwoolley Date: Wed, 21 Feb 2001 18:41:29 +0000 Subject: Added apr_get_userid() as a companion to apr_get_username(). PR: Needed to fix Apache PR7271. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61275 13f79535-47bb-0310-9956-ffa450edef68 --- user/unix/userinfo.c | 36 ++++++++++++++++++++++++++++++++---- user/win32/userinfo.c | 9 ++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) (limited to 'user') 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 #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; diff --git a/user/win32/userinfo.c b/user/win32/userinfo.c index 1771f9036..de1794d19 100644 --- a/user/win32/userinfo.c +++ b/user/win32/userinfo.c @@ -60,11 +60,18 @@ #include #endif -APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, const char *userid, apr_pool_t *p) +APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, const char *username, apr_pool_t *p) { return APR_ENOTIMPL; } +APR_DECLARE(apr_status_t) apr_get_userid(apr_uid_t *uid, apr_gid_t *gid, + const char *username) +{ + /* XXX: could someone please implement this for me? */ + return APR_ENOTIMPL; +} + APR_DECLARE(apr_status_t) apr_get_username(char **username, apr_uid_t userid, apr_pool_t *p) { SID_NAME_USE type; -- cgit v1.2.1