+STATIC int
+in_group(gid)
+ int gid;
+ {
+#ifdef _POSIX_VERSION
+#ifdef __STDC__
+ /*
+ * This bogus declararation is to force an error when
+ * someone fixes getgroups().
+ */
+ extern int getgroups(int ngroups, int *group_list);
+#endif
+#if NGROUPS_MAX != 0
+ int group_list[NGROUPS_MAX];
+#else
+#undef NGROUPS_MAX
+ size_t NGROUPS_MAX = sysconf(_SC_NGROUPS_MAX);
+ int *group_list = ckmalloc(NGROUPS_MAX);
+#endif
+ int i;
+ int ngroups;
+
+ ngroups = getgroups(NGROUPS_MAX, group_list);
+ for (i = 0; i < ngroups; i++)
+ if (gid == group_list[i]) {
+#ifndef NGROUPS_MAX
+ ckfree(group_list);
+#endif
+ return 1;
+ }
+#ifndef NGROUPS_MAX
+ ckfree(group_list);
+#endif
+ return 0;
+#else /* ndef _POSIX_VERSION */
+ return gid == getegid();
+#endif /* _POSIX_VERSION */
+}
+
+
+