diff options
-rw-r--r-- | usr.sbin/pw/pw_user.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 23a7856..7df6b85 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -747,6 +747,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) if (mode == M_ADD || getarg(args, 'G') != NULL) { int i, j; for (i = 0; cnf->groups[i] != NULL; i++) { + char **members; grp = GETGRNAM(cnf->groups[i]); for (j = 0; grp->gr_mem[j] != NULL; j++) { if (!strcmp(grp->gr_mem[j], pwd->pw_name)) @@ -755,15 +756,15 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) if (grp->gr_mem[j] != NULL) /* user already member of group */ continue; - if (j == 0) - grp->gr_mem = NULL; + members = malloc(sizeof(char *) * (j + 1)); + for (j = 0; grp->gr_mem[j] != NULL; j++) + members[j] = grp->gr_mem[j]; - grp->gr_mem = reallocf(grp->gr_mem, sizeof(*grp->gr_mem) * - (j + 2)); - - grp->gr_mem[j] = pwd->pw_name; - grp->gr_mem[j+1] = NULL; + members[j] = pwd->pw_name; + members[j+1] = NULL; + grp->gr_mem = members; chggrent(cnf->groups[i], grp); + free(members); } } |