diff options
author | bapt <bapt@FreeBSD.org> | 2012-12-26 18:14:45 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2012-12-26 18:14:45 +0000 |
commit | d1e0080a5ef8d493131ae801cbc3ab257dd761b9 (patch) | |
tree | 2ecd10cfe3e087dcc4e4ffe101ed98024fe70479 /usr.sbin/pw | |
parent | 27fa8d59ff9ba9772b2c8708ac558a08e5514100 (diff) | |
download | FreeBSD-src-d1e0080a5ef8d493131ae801cbc3ab257dd761b9.zip FreeBSD-src-d1e0080a5ef8d493131ae801cbc3ab257dd761b9.tar.gz |
Fix creating a user and adding it to a group
Reported by: "Sam Fourman Jr." <sfourman@gmail.com>, dim
Diffstat (limited to 'usr.sbin/pw')
-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); } } |