Skip to content

Commit

Permalink
Implement apr_get_groupid [to mirror apr_get_userid]
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62528 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
wrowe committed Nov 20, 2001
1 parent 0ec5b4c commit 777305a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
17 changes: 13 additions & 4 deletions include/apr_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,27 @@ 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
Expand All @@ -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 */
Expand Down
19 changes: 19 additions & 0 deletions user/unix/groupinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 777305a

Please sign in to comment.