You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Ryan Morgan <rm...@covalent.net> on 2001/02/02 11:47:39 UTC
[PATCH] apr_get_groupname
I've been working a bit with apr, and noticed that the implementation of
apr_get_groupname is missing from the unix code.
This patch has only been tested on Linux, so commit at your own risk.
Re: [PATCH] apr_get_groupname
Posted by Ryan Morgan <rm...@covalent.net>.
Ok, I'm an idiot. I completely missed the implementation in groupinfo.c.
I was having some problems with undefined symbols in httpd because the linker
wasn't pulling that symbol in from aprlib.a, but I guess that was fixed a
couple of days ago.
-Ryan
On Fri, Feb 02, 2001 at 02:47:39AM -0800, Ryan Morgan wrote:
>
> I've been working a bit with apr, and noticed that the implementation of
> apr_get_groupname is missing from the unix code.
>
> This patch has only been tested on Linux, so commit at your own risk.
>
>
> Index: userinfo.c
> ===================================================================
> RCS file: /home/cvspublic/apr/user/unix/userinfo.c,v
> retrieving revision 1.6
> diff -u -r1.6 userinfo.c
> --- userinfo.c 2001/01/28 23:45:57 1.6
> +++ userinfo.c 2001/02/02 08:40:02
> @@ -59,6 +59,9 @@
> #ifdef HAVE_PWD_H
> #include <pwd.h>
> #endif
> +#ifdef HAVE_GRP_H
> +#include <grp.h>
> +#endif
> #if APR_HAVE_SYS_TYPES_H
> #include <sys/types.h>
> #endif
> @@ -100,5 +103,21 @@
> }
> *username = apr_pstrdup(p, pw->pw_name);
> return APR_SUCCESS;
> +}
> +
> +APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t groupid, apr_pool_t *p)
> +{
> + struct group *gp;
> +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
> + struct group grp;
> + char grpbuf[512];
> +
> + if(getgrgid_r(groupid, &grp, grpbuf, sizeof(grpbuf), &gp)) {
> +#else
> + if((gp = getgrgid(groupid)) == NULL) {
> +#endif
> + return errno;
> + }
> + *groupname = apr_pstrdup(p, gp->gr_name);
> + return APR_SUCCESS;
> }
> -