]> granicus.if.org Git - sudo/commitdiff
Use _getgroupsbymember() on Solaris to get the groups list. Fixes
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 18 Jan 2013 19:58:12 +0000 (14:58 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 18 Jan 2013 19:58:12 +0000 (14:58 -0500)
performance problems with the getgroupslist() compat on Solaris
systems with network-based group databases.

compat/getgrouplist.c
config.h.in
configure
configure.in

index 2d22714f4c1278cafc3b837532eaf332c065dfdf..cea72f5110fa5f5e757969da410f311fe315416f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2010, 2011, 2013 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -36,7 +36,7 @@
 
 #include "missing.h"
 
-#ifdef HAVE_GETGRSET
+#if defined(HAVE_GETGRSET)
 /*
  * BSD-compatible getgrouplist(3) using getgrset(3)
  */
@@ -79,7 +79,32 @@ done:
     return rval;
 }
 
-#else /* HAVE_GETGRSET */
+#elif defined(HAVE__GETGROUPSBYMEMBER)
+
+/*
+ * BSD-compatible getgrouplist(3) using _getgroupsbymember(3)
+ */
+int
+getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroupsp)
+{
+    int ngroups, grpsize = *ngroupsp;
+    int rval = -1;
+
+    if (grpsize > 0) {
+       /* We support BSD semantics where the first element is the base gid */
+       groups[0] = basegid;
+
+       /* The last arg is 1 because we already filled in the base gid. */
+       ngroups = _getgroupsbymember(name, groups, grpsize, 1);
+       if (ngroups != -1) {
+           rval = 0;
+           *ngroupsp = ngroups;
+       }
+    }
+    return rval;
+}
+
+#else /* !HAVE_GETGRSET && !HAVE__GETGROUPSBYMEMBER */
 
 /*
  * BSD-compatible getgrouplist(3) using getgrent(3)
@@ -128,4 +153,4 @@ done:
 
     return rval;
 }
-#endif /* HAVE_GETGRSET */
+#endif /* !HAVE_GETGRSET && !HAVE__GETGROUPSBYMEMBER */
index bead6ae8cbc91668ea0961704165993a34820c68..3483ac225cce2e3c6a4c885b35134d3860a171fc 100644 (file)
 /* Define to 1 if the system has the type `_Bool'. */
 #undef HAVE__BOOL
 
+/* Define to 1 if you have the `_getgroupsbymember' function. */
+#undef HAVE__GETGROUPSBYMEMBER
+
 /* Define to 1 if you have the `_getpty' function. */
 #undef HAVE__GETPTY
 
index 5dbd996f8692249ad76c0472cf83fdb7e8811ef5..5018c023ee7d3fa029ab9bda5bc18551c587e049 100755 (executable)
--- a/configure
+++ b/configure
@@ -13927,6 +13927,19 @@ case "$host" in
                OS_INIT=os_init_solaris
                SUDO_OBJS="${SUDO_OBJS} solaris.o"
 
+               # For implementing getgrouplist()
+               for ac_func in _getgroupsbymember
+do :
+  ac_fn_c_check_func "$LINENO" "_getgroupsbymember" "ac_cv_func__getgroupsbymember"
+if test "x$ac_cv_func__getgroupsbymember" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE__GETGROUPSBYMEMBER 1
+_ACEOF
+
+fi
+done
+
+
                # To get the crypt(3) prototype (so we pass -Wall)
                OSDEFS="${OSDEFS} -D__EXTENSIONS__"
                # AFS support needs -lucb
index 02c4760e501f11780441af679a0a96560196b61b..c9b589d70c73008a796c1ea2368d139e928b0a8d 100644 (file)
@@ -1573,6 +1573,9 @@ case "$host" in
                OS_INIT=os_init_solaris
                SUDO_OBJS="${SUDO_OBJS} solaris.o"
 
+               # For implementing getgrouplist()
+               AC_CHECK_FUNCS(_getgroupsbymember)
+
                # To get the crypt(3) prototype (so we pass -Wall)
                OSDEFS="${OSDEFS} -D__EXTENSIONS__"
                # AFS support needs -lucb