From: Alejandro Colomar Date: Tue, 19 Nov 2024 00:20:56 +0000 (+0100) Subject: lib/, src/: Use agetgroups() instead of its pattern X-Git-Tag: 4.17.3~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d7dfa0a7bbf36f6f9767b8ee57b4caf3f43c7a5;p=thirdparty%2Fshadow.git lib/, src/: Use agetgroups() instead of its pattern Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/addgrps.c b/lib/addgrps.c index bfdaf2edc..83a5b20a8 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -19,9 +19,9 @@ #include #include -#include "alloc/malloc.h" #include "alloc/reallocf.h" #include "search/l/lsearch.h" +#include "shadow/grp/agetgroups.h" #include "shadowlog.h" #include "string/strchr/strchrscnt.h" @@ -38,21 +38,12 @@ add_groups(const char *list) FILE *shadow_logfd = log_get_logfd(); gid_t *gids; size_t n; - ssize_t n0; - n0 = getgroups(0, NULL); - if (n0 == -1) - return -1; - - gids = MALLOC(n0, gid_t); + gids = agetgroups(&n); if (gids == NULL) return -1; - n0 = getgroups(n0, gids); - if (n0 == -1) - goto free_gids; - - gids = REALLOCF(gids, n0 + strchrscnt(list, ",:") + 1, gid_t); + gids = REALLOCF(gids, n + strchrscnt(list, ",:") + 1, gid_t); if (gids == NULL) return -1; @@ -60,7 +51,6 @@ add_groups(const char *list) if (dup == NULL) goto free_gids; - n = n0; while (NULL != (g = strsep(&p, ",:"))) { struct group *grp; diff --git a/src/newgrp.c b/src/newgrp.c index ee31b56b2..6e05277f6 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -26,6 +26,7 @@ #include "prototypes.h" #include "search/l/lfind.h" #include "search/l/lsearch.h" +#include "shadow/grp/agetgroups.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" @@ -557,17 +558,9 @@ int main (int argc, char **argv) * nasty message but at least your real and effective group ids are * set. */ - - ngroups = getgroups(0, NULL); - if (ngroups == -1) - goto fail_gg; - - gids = XMALLOC(ngroups, gid_t); - - ngroups = getgroups(ngroups, gids); - if (ngroups == -1) { -fail_gg: - perror("getgroups"); + gids = agetgroups(&ngroups); + if (gids == NULL) { + perror("agetgroups"); #ifdef WITH_AUDIT if (group) { SNPRINTF(audit_buf, "changing new-group=%s", group);