summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2001-11-20 22:44:46 +0000
committerWilliam A. Rowe Jr <wrowe@apache.org>2001-11-20 22:44:46 +0000
commit596872eae32bdcda6b921aee6ed3b140002a3630 (patch)
treea100cf5aa8a4755f0fbfdea2e8ea002e5452953c
parentd83f6d4a31aa7dcabb9a7569ed4e618f391eae59 (diff)
downloadapr-596872eae32bdcda6b921aee6ed3b140002a3630.tar.gz
Implement apr_get_groupid [to mirror apr_get_userid]
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62528 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/apr_user.h17
-rw-r--r--user/unix/groupinfo.c19
2 files changed, 32 insertions, 4 deletions
diff --git a/include/apr_user.h b/include/apr_user.h
index 4fcf4ad39..7c41b0fc1 100644
--- a/include/apr_user.h
+++ b/include/apr_user.h
@@ -144,19 +144,28 @@ APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, const char *use
#if defined(WIN32)
APR_DECLARE(apr_status_t) apr_compare_users(apr_uid_t left, apr_uid_t right);
#else
-#define apr_compare_users(left,right) ((left == right) ? APR_SUCCESS : APR_EMISMATCH)
+#define apr_compare_users(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH)
#endif
/**
* Get the group name for a specified groupid
- * @param dirname Pointer to new string containing group name (on output)
- * @param userid The groupid
+ * @param groupname Pointer to new string containing group name (on output)
+ * @param groupid The groupid
* @param p The pool from which to allocate the string
* @remark This function is available only if APR_HAS_USER is defined.
*/
APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t groupid, apr_pool_t *p);
/**
+ * Get the groupid for a specified group name
+ * @param groupid Pointer to the group id (on output)
+ * @param groupname The group name to look up
+ * @param p The pool from which to allocate the string
+ * @remark This function is available only if APR_HAS_USER is defined.
+ */
+APR_DECLARE(apr_status_t) apr_get_groupid(apr_gid_t *groupid, const char *groupname, apr_pool_t *p);
+
+/**
* Compare two group identifiers for equality.
* @param left One gid to test
* @param right Another gid to test
@@ -167,7 +176,7 @@ APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t groupid,
#if defined(WIN32)
APR_DECLARE(apr_status_t) apr_compare_groups(apr_gid_t left, apr_gid_t right);
#else
-#define apr_compare_groups(left,right) ((left == right) ? APR_SUCCESS : APR_EMISMATCH)
+#define apr_compare_groups(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH)
#endif
#endif /* ! APR_HAS_USER */
diff --git a/user/unix/groupinfo.c b/user/unix/groupinfo.c
index 34f2e4345..bca6ac32b 100644
--- a/user/unix/groupinfo.c
+++ b/user/unix/groupinfo.c
@@ -86,3 +86,22 @@ APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t groupid,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_get_groupid(apr_gid_t *groupid, const char *groupname, apr_pool_t *p)
+{
+ struct group *gr;
+#ifndef BEOS
+
+#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
+ struct group grp;
+ char grbuf[512];
+
+ if (getgrnam_r(&grpname, &gr, grbuf, sizeof(grbuf))) {
+#else
+ if ((gr = getgrnam(groupname)) == NULL) {
+#endif
+ return errno;
+ }
+ *groupid = gr->gr_gid;
+#endif
+ return APR_SUCCESS;
+}