]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add getgrouplist() for Solaris
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 15 Sep 2015 09:26:44 +0000 (02:26 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 9 Apr 2016 00:33:15 +0000 (20:33 -0400)
Of course Solaris doesn't have getgrouplist()...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
configure.ac
lib/privs.c

index 8f8859a3f148e5c70ff483316648d77683b3a7a8..718bd2d03c356b9f9eac24f03c4154f25f3aecee 100755 (executable)
@@ -830,7 +830,7 @@ AC_CHECK_FUNCS([dup2 ftruncate getcwd gethostbyname getpagesize gettimeofday \
        strtol strtoul strlcat strlcpy \
        daemon snprintf vsnprintf \
        if_nametoindex if_indextoname getifaddrs \
-       uname fcntl])
+       uname fcntl getgrouplist])
 
 dnl ------------------------------------
 dnl Determine routing get and set method
index ff0be2fe128bc044fa1f91d721410c63ed5e13ab..0ca8783dcc87826719b24201890ff1bea86b3248 100644 (file)
@@ -622,6 +622,41 @@ zprivs_state_null (void)
   return zprivs_null_state;
 }
 
+#ifndef HAVE_GETGROUPLIST
+/* Solaris 11 has no getgrouplist() */
+static int
+getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups)
+{
+  struct group *grp;
+  size_t usridx;
+  int pos = 0, ret;
+
+  if (pos < *ngroups)
+    groups[pos] = group;
+  pos++;
+
+  setgrent();
+  while ((grp = getgrent()))
+    {
+      if (grp->gr_gid == group)
+        continue;
+      for (usridx = 0; grp->gr_mem[usridx] != NULL; usridx++)
+        if (!strcmp (grp->gr_mem[usridx], user))
+          {
+            if (pos < *ngroups)
+              groups[pos] = grp->gr_gid;
+            pos++;
+            break;
+          }
+    }
+  endgrent();
+
+  ret = (pos <= *ngroups) ? pos : -1;
+  *ngroups = pos;
+  return ret;
+}
+#endif /* HAVE_GETGROUPLIST */
+
 void
 zprivs_init(struct zebra_privs_t *zprivs)
 {