summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68>2001-02-21 18:41:29 +0000
committerjwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68>2001-02-21 18:41:29 +0000
commitd6f6b30b3ec0c2323474a7d5c80795ba1e6cec25 (patch)
treef84a6fe1474ef9377f60875441697fd937427e3f
parentca03e80ee659262b1b830911e9bbbc64ef936acf (diff)
downloadlibapr-d6f6b30b3ec0c2323474a7d5c80795ba1e6cec25.tar.gz
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
-rw-r--r--include/apr_user.h32
-rw-r--r--user/unix/userinfo.c36
-rw-r--r--user/win32/userinfo.c9
3 files changed, 62 insertions, 15 deletions
diff --git a/include/apr_user.h b/include/apr_user.h
index a4e62e640..314803de3 100644
--- a/include/apr_user.h
+++ b/include/apr_user.h
@@ -91,31 +91,42 @@ typedef gid_t apr_gid_t;
/***
* Get the user name for a specified userid
- * @param dirname Pointer to new string containing user name (on output)
+ * @param username Pointer to new string containing user name (on output)
* @param userid The userid
* @param p The pool from which to allocate the string
- * @deffunc apr_status_t apr_get_username(char **username, apr_uid_t userid, apr_pool_t *p)
* @tip This function is available only if APR_HAS_USER is defined.
+ * @deffunc apr_status_t apr_get_username(char **username, apr_uid_t userid, apr_pool_t *p)
*/
APR_DECLARE(apr_status_t) apr_get_username(char **username, apr_uid_t userid, apr_pool_t *p);
/***
+ * Get the userid (and groupid) for the specified username
+ * @param userid Returns the user id
+ * @param groupid Returns the user's group id
+ * @param username The username to lookup
+ * @tip This function is available only if APR_HAS_USER is defined.
+ * @deffunc apr_status_t apr_get_userid(apr_uid_t *userid, apr_gid_t *groupid, const char *username)
+ */
+APR_DECLARE(apr_status_t) apr_get_userid(apr_uid_t *userid, apr_gid_t *groupid, const char *username);
+
+/***
* Get the home directory for the named user
* @param dirname Pointer to new string containing directory name (on output)
- * @param userid The named user
+ * @param username The named user
* @param p The pool from which to allocate the string
- * @deffunc apr_status_t apr_get_home_directory(char **dirname, const char *userid, apr_pool_t *p)
* @tip This function is available only if APR_HAS_USER is defined.
+ * @deffunc apr_status_t apr_get_home_directory(char **dirname, const char *username, apr_pool_t *p)
*/
-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);
/***
* Compare two user identifiers for equality.
* @param left One uid to test
* @param right Another uid to test
- * @deffunc apr_status_t apr_compare_users(apr_uid_t left, apr_uid_t right)
- * @tip Returns APR_SUCCESS if the apr_uid_t strutures identify the same user,
+ * @return APR_SUCCESS if the apr_uid_t strutures identify the same user,
* APR_EMISMATCH if not, APR_BADARG if an apr_uid_t is invalid.
+ * @tip This function is available only if APR_HAS_USER is defined.
+ * @deffunc apr_status_t apr_compare_users(apr_uid_t left, apr_uid_t right)
*/
#if defined(WIN32)
APR_DECLARE(apr_status_t) apr_compare_users(apr_uid_t left, apr_uid_t right);
@@ -128,8 +139,8 @@ APR_DECLARE(apr_status_t) apr_compare_users(apr_uid_t left, apr_uid_t right);
* @param dirname Pointer to new string containing group name (on output)
* @param userid The groupid
* @param p The pool from which to allocate the string
- * @deffunc apr_status_t apr_get_groupname(char **groupname, apr_gid_t userid, apr_pool_t *p);
* @tip This function is available only if APR_HAS_USER is defined.
+ * @deffunc apr_status_t apr_get_groupname(char **groupname, apr_gid_t userid, apr_pool_t *p);
*/
APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t groupid, apr_pool_t *p);
@@ -137,9 +148,10 @@ APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t groupid,
* Compare two group identifiers for equality.
* @param left One gid to test
* @param right Another gid to test
- * @deffunc apr_status_t apr_compare_groups(apr_gid_t left, apr_gid_t right)
- * @tip Returns APR_SUCCESS if the apr_gid_t strutures identify the same group,
+ * @return APR_SUCCESS if the apr_gid_t strutures identify the same group,
* APR_EMISMATCH if not, APR_BADARG if an apr_gid_t is invalid.
+ * @tip This function is available only if APR_HAS_USER is defined.
+ * @deffunc apr_status_t apr_compare_groups(apr_gid_t left, apr_gid_t right)
*/
#if defined(WIN32)
APR_DECLARE(apr_status_t) apr_compare_groups(apr_gid_t left, apr_gid_t right);
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;
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 <sys/types.h>
#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;