#include <string.h>
#include <sys/types.h>
-#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"
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;
if (dup == NULL)
goto free_gids;
- n = n0;
while (NULL != (g = strsep(&p, ",:"))) {
struct group *grp;
#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"
* 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);