2010-05-14 12:36:48 +00:00
|
|
|
diff --git a/lib/getugroups.c b/lib/getugroups.c
|
|
|
|
index 299bae6..8ece29b 100644
|
|
|
|
--- a/lib/getugroups.c
|
|
|
|
+++ b/lib/getugroups.c
|
2008-01-25 17:48:11 +00:00
|
|
|
@@ -19,6 +19,9 @@
|
2007-01-09 19:29:30 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2004-10-05 15:45:31 +00:00
|
|
|
|
|
|
|
+/* We do not need this code if getgrouplist(3) is available. */
|
|
|
|
+#ifndef HAVE_GETGROUPLIST
|
|
|
|
+
|
2008-01-25 17:48:11 +00:00
|
|
|
#include "getugroups.h"
|
|
|
|
|
2009-11-27 13:24:09 +00:00
|
|
|
#include <errno.h>
|
2016-07-14 14:29:59 +00:00
|
|
|
@@ -126,3 +129,4 @@ getugroups (int maxcount, gid_t *grouplist, char const *username,
|
2004-10-05 15:45:31 +00:00
|
|
|
}
|
2009-11-27 13:24:09 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_GRP_H */
|
2004-10-05 15:45:31 +00:00
|
|
|
+#endif /* have getgrouplist */
|
2010-05-14 12:36:48 +00:00
|
|
|
diff --git a/lib/mgetgroups.c b/lib/mgetgroups.c
|
|
|
|
index 76474c2..0a9d221 100644
|
|
|
|
--- a/lib/mgetgroups.c
|
|
|
|
+++ b/lib/mgetgroups.c
|
2018-11-07 14:53:11 +00:00
|
|
|
@@ -31,6 +31,7 @@
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "getugroups.h"
|
|
|
|
+#include "xalloc.h"
|
|
|
|
#include "xalloc-oversized.h"
|
|
|
|
|
|
|
|
/* Work around an incompatibility of OS X 10.11: getgrouplist
|
|
|
|
@@ -121,9 +122,17 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
|
2010-05-14 12:36:48 +00:00
|
|
|
/* else no username, so fall through and use getgroups. */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
- max_n_groups = (username
|
|
|
|
- ? getugroups (0, NULL, username, gid)
|
|
|
|
- : getgroups (0, NULL));
|
|
|
|
+ if (!username)
|
|
|
|
+ max_n_groups = getgroups(0, NULL);
|
2017-03-09 08:57:09 +00:00
|
|
|
+ else
|
2010-05-14 12:36:48 +00:00
|
|
|
+ {
|
|
|
|
+#ifdef HAVE_GETGROUPLIST
|
|
|
|
+ max_n_groups = 0;
|
|
|
|
+ getgrouplist (username, gid, NULL, &max_n_groups);
|
|
|
|
+#else
|
|
|
|
+ max_n_groups = getugroups (0, NULL, username, gid);
|
|
|
|
+#endif
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/* If we failed to count groups because there is no supplemental
|
|
|
|
group support, then return an array containing just GID.
|
2018-11-07 14:53:11 +00:00
|
|
|
@@ -145,10 +154,25 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
|
2010-05-14 12:36:48 +00:00
|
|
|
if (g == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
- ng = (username
|
|
|
|
- ? getugroups (max_n_groups, g, username, gid)
|
|
|
|
- : getgroups (max_n_groups - (gid != (gid_t) -1),
|
|
|
|
- g + (gid != (gid_t) -1)));
|
|
|
|
+ if (!username)
|
2010-07-02 11:42:29 +00:00
|
|
|
+ ng = getgroups (max_n_groups - (gid != (gid_t)-1), g + (gid != (gid_t)-1));
|
2010-05-14 12:36:48 +00:00
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+#ifdef HAVE_GETGROUPLIST
|
|
|
|
+ int e;
|
|
|
|
+ ng = max_n_groups;
|
|
|
|
+ while ((e = getgrouplist (username, gid, g, &ng)) == -1
|
|
|
|
+ && ng > max_n_groups)
|
|
|
|
+ {
|
|
|
|
+ max_n_groups = ng;
|
|
|
|
+ g = xrealloc (g, max_n_groups * sizeof (GETGROUPS_T));
|
|
|
|
+ }
|
|
|
|
+ if (e == -1)
|
|
|
|
+ ng = -1;
|
|
|
|
+#else
|
|
|
|
+ ng = getugroups (max_n_groups, g, username, gid);
|
|
|
|
+#endif
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (ng < 0)
|
|
|
|
{
|
|
|
|
diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4
|
|
|
|
index 62777c7..5180243 100644
|
|
|
|
--- a/m4/jm-macros.m4
|
|
|
|
+++ b/m4/jm-macros.m4
|
2016-07-14 14:29:59 +00:00
|
|
|
@@ -82,6 +82,7 @@ AC_DEFUN([coreutils_MACROS],
|
2011-10-12 14:13:12 +00:00
|
|
|
fchown
|
|
|
|
fchmod
|
|
|
|
ftruncate
|
|
|
|
+ getgrouplist
|
|
|
|
iswspace
|
|
|
|
mkfifo
|
|
|
|
mbrlen
|