coreutils/coreutils-8.14-getgrouplist.patch

80 lines
2.3 KiB
Diff

--- coreutils-8.14/lib/getugroups.c.getgrouplist~ 2011-10-20 20:03:09.911334912 +0200
+++ coreutils-8.14/lib/getugroups.c 2011-10-20 20:03:18.968325315 +0200
@@ -19,6 +19,9 @@
#include <config.h>
+/* We do not need this code if getgrouplist(3) is available. */
+#ifndef HAVE_GETGROUPLIST
+
#include "getugroups.h"
#include <errno.h>
@@ -128,3 +131,4 @@ getugroups (int maxcount, gid_t *groupli
}
#endif /* HAVE_GRP_H */
+#endif /* have getgrouplist */
--- coreutils-8.14/lib/mgetgroups.c.getgrouplist~ 2011-04-29 21:39:05.000000000 +0200
+++ coreutils-8.14/lib/mgetgroups.c 2011-10-20 20:03:18.969325314 +0200
@@ -115,9 +115,17 @@ mgetgroups (char const *username, gid_t
/* 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);
+ else
+ {
+#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.
@@ -139,10 +147,25 @@ mgetgroups (char const *username, gid_t
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)
+ ng = getgroups (max_n_groups - (gid != (gid_t)-1), g + (gid != (gid_t)-1));
+ 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)
{
--- coreutils-8.14/m4/jm-macros.m4.getgrouplist~ 2011-10-10 09:30:55.000000000 +0200
+++ coreutils-8.14/m4/jm-macros.m4 2011-10-20 20:04:27.697252776 +0200
@@ -77,6 +77,7 @@ AC_DEFUN([coreutils_MACROS],
fchown
fchmod
ftruncate
+ getgrouplist
iswspace
mkfifo
mbrlen