From: Mike Frysinger <vapier@gentoo.org>
To: nfs@lists.sourceforge.net
Subject: [patch] provide non-standard getgrouplist() in libnfsidmap when need be
Date: Sun, 25 Mar 2007 03:29:02 -0400 [thread overview]
Message-ID: <200703250329.03353.vapier@gentoo.org> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 207 bytes --]
libnfsidmap uses the non-standard function getgrouplist() ... the attached
patch takes code from FreeBSD to implement the function based on POSIX
functions when the system libc is not sufficient
-mike
[-- Attachment #1.2: Type: application/pgp-signature, Size: 827 bytes --]
[-- Attachment #2: libnfsidmap-0.19-getgrouplist.patch --]
[-- Type: text/x-diff, Size: 3408 bytes --]
http://bugs.gentoo.org/169909
--- libnfsidmap-0.19/configure.in
+++ libnfsidmap-0.19/configure.in
@@ -38,7 +38,7 @@
# Checks for library functions.
AC_FUNC_MALLOC
-AC_CHECK_FUNCS([strchr strdup])
+AC_CHECK_FUNCS([strchr strdup getgrouplist])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT(libnfsidmap.pc)
--- libnfsidmap-0.19/nss.c
+++ libnfsidmap-0.19/nss.c
@@ -49,6 +49,8 @@
#include "cfg.h"
#include <syslog.h>
+#include "getgrouplist.c"
+
/*
* NSS Translation Methods
*
--- libnfsidmap-0.19/getgrouplist.c
+++ libnfsidmap-0.19/getgrouplist.c
@@ -0,0 +1,85 @@
+/*
+ * getgrouplist.c
+ *
+ * if system does not provide the non-standard getgrouplist, we will emulate
+ * it via POSIX standard functions
+ *
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <grp.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifndef HAVE_GETGROUPLIST
+static
+int
+getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
+{
+ const struct group *grp;
+ int i, maxgroups, ngroups, ret;
+
+ ret = 0;
+ ngroups = 0;
+ maxgroups = *grpcnt;
+ /*
+ * When installing primary group, duplicate it;
+ * the first element of groups is the effective gid
+ * and will be overwritten when a setgid file is executed.
+ */
+ groups[ngroups++] = agroup;
+ if (maxgroups > 1)
+ groups[ngroups++] = agroup;
+ /*
+ * Scan the group file to find additional groups.
+ */
+ setgrent();
+ while ((grp = getgrent()) != NULL) {
+ for (i = 0; i < ngroups; i++) {
+ if (grp->gr_gid == groups[i])
+ goto skip;
+ }
+ for (i = 0; grp->gr_mem[i]; i++) {
+ if (!strcmp(grp->gr_mem[i], uname)) {
+ if (ngroups >= maxgroups) {
+ ret = -1;
+ break;
+ }
+ groups[ngroups++] = grp->gr_gid;
+ break;
+ }
+ }
+skip:
+ ;
+ }
+ endgrent();
+ *grpcnt = ngroups;
+ return (ret);
+}
+#endif
[-- Attachment #3: Type: text/plain, Size: 345 bytes --]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
[-- Attachment #4: Type: text/plain, Size: 140 bytes --]
_______________________________________________
NFS maillist - NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs
next reply other threads:[~2007-03-25 7:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-25 7:29 Mike Frysinger [this message]
2007-03-26 13:22 ` [patch] provide non-standard getgrouplist() in libnfsidmap when need be Trond Myklebust
2007-03-26 14:32 ` Peter Åstrand
2007-03-26 15:46 ` Trond Myklebust
2007-03-26 16:09 ` J. Bruce Fields
2007-03-26 17:40 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200703250329.03353.vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=nfs@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.