All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] provide non-standard getgrouplist() in libnfsidmap when need be
@ 2007-03-25  7:29 Mike Frysinger
  2007-03-26 13:22 ` Trond Myklebust
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2007-03-25  7:29 UTC (permalink / raw)
  To: nfs


[-- 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-03-26 17:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-25  7:29 [patch] provide non-standard getgrouplist() in libnfsidmap when need be Mike Frysinger
2007-03-26 13:22 ` 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

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.