diff options
author | Eric Blake <ebb9@byu.net> | 2009-11-12 10:19:39 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-11-13 07:39:56 -0700 |
commit | 6e4b15b5ee28b52b4a03c74fe8a9ac9bc8a976ea (patch) | |
tree | 60e9911fe45923bfaa4a562268ab26a0979f3ee9 /lib/getgroups.c | |
parent | 61b3a42219dc8f575923346b59162f81186b7425 (diff) | |
download | gnulib-6e4b15b5ee28b52b4a03c74fe8a9ac9bc8a976ea.tar.gz |
getgroups: don't expose GETGROUPS_T to user
These days, most systems already declare getgroups with gid_t*.
But in the rare case that GETGROUPS_T is still int but gid_t
is short, the user should not have to uglify their code; let
the replacement hide all the magic.
Tested by configuring with ac_cv_type_getgroups=uint64_t on a
platform with 32-bit gid_t, and ignoring compiler warnings.
However, since we don't replace setgroups, the GETGROUPS_T
workaround is still needed there for now.
* lib/getgroups.c (rpl_getgroups): Change signature. Copy array
an element at a time if GETGROUPS_T is wrong size.
* lib/getugroups.h (getugroups): Change signature.
* lib/unistd.in.h (getgroups): Likewise.
* m4/getgroups.m4 (gl_FUNC_GETGROUPS): Use replacement if
signature needs fixing.
* m4/getugroups.m4 (gl_GETUGROUPS): No longer need
AC_TYPE_GETGROUPS.
* modules/group-member (Depends-on): Add getgroups.
* lib/group-member.c (group_info, get_group_info): Use gid_t.
(group_member): Rely on getgroups replacement.
* lib/getugroups.c (getugroups): Use gid_t.
* tests/test-getgroups.c (main): Likewise.
* NEWS: Mention the signature change.
* doc/posix-functions/getgroups.texi (getgroups): Mention the
problem with signature.
* doc/glibc-functions/setgroups.texi (setgroups): Mention that
GETGROUPS_T is still useful for setgroups.
Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'lib/getgroups.c')
-rw-r--r-- | lib/getgroups.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/getgroups.c b/lib/getgroups.c index bad676ea5e..e4540fe9b7 100644 --- a/lib/getgroups.c +++ b/lib/getgroups.c @@ -48,14 +48,44 @@ getgroups (int n _UNUSED_PARAMETER_, GETGROUPS_T *groups _UNUSED_PARAMETER_) whether the effective group id is included in the list. */ int -rpl_getgroups (int n, GETGROUPS_T *group) +rpl_getgroups (int n, gid_t *group) { int n_groups; GETGROUPS_T *gbuf; int saved_errno; if (n != 0) - return getgroups (n, group); + { + int result; + int saved_errno; + if (sizeof *group == sizeof *gbuf) + return getgroups (n, (GETGROUPS_T *) group); + + if (n < 0) + { + errno = EINVAL; + return -1; + } + if (SIZE_MAX / sizeof *gbuf <= n) + { + errno = ENOMEM; + return -1; + } + gbuf = malloc (n * sizeof *gbuf); + if (!gbuf) + return -1; + result = getgroups (n, gbuf); + if (0 <= result) + { + n = result; + while (n--) + group[n] = gbuf[n]; + } + saved_errno = errno; + free (gbuf); + errno == saved_errno; + return result; + } n = 20; while (1) |