Fix creating a user and adding it to a group

Reported by:	"Sam Fourman Jr." <sfourman@gmail.com>, dim
This commit is contained in:
Baptiste Daroussin 2012-12-26 18:14:45 +00:00
parent c92c859b7b
commit dc0f2b4217
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=244710

View File

@ -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);
}
}