From 5114e81f1007f98abeca8e6aa8a88b3c966ba7e5 Mon Sep 17 00:00:00 2001 From: simonb Date: Tue, 17 Oct 2000 05:31:50 +0000 Subject: [PATCH] Handle -G for the useradd case (usermod was already correct). Also show warning if a non-existant group is specified. Patch from PR bin/11123 by David Edmondson. --- usr.sbin/user/user.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c index 72ffe8cceb1f..27700c4a21ce 100644 --- a/usr.sbin/user/user.c +++ b/usr.sbin/user/user.c @@ -1,4 +1,4 @@ -/* $NetBSD: user.c,v 1.26 2000/10/17 04:53:27 simonb Exp $ */ +/* $NetBSD: user.c,v 1.27 2000/10/17 05:31:50 simonb Exp $ */ /* * Copyright (c) 1999 Alistair G. Crooks. All rights reserved. @@ -35,7 +35,7 @@ #ifndef lint __COPYRIGHT("@(#) Copyright (c) 1999 \ The NetBSD Foundation, Inc. All rights reserved."); -__RCSID("$NetBSD: user.c,v 1.26 2000/10/17 04:53:27 simonb Exp $"); +__RCSID("$NetBSD: user.c,v 1.27 2000/10/17 05:31:50 simonb Exp $"); #endif #include @@ -542,7 +542,9 @@ append_group(char *user, int ngroups, char **groups) int j; for (i = 0 ; i < ngroups ; i++) { - if ((grp = getgrnam(groups[i])) != NULL) { + if ((grp = getgrnam(groups[i])) == NULL) { + warnx("can't append group `%s' for user `%s'", groups[i], user); + } else { for (j = 0 ; grp->gr_mem[j] ; j++) { if (strcmp(user, grp->gr_mem[j]) == 0) { /* already in it */ @@ -980,6 +982,11 @@ adduser(char *login, user_t *up) (void) pw_abort(); err(EXIT_FAILURE, "can't create gid %d for login name %s", gid, login); } + if (up->u_groupc > 0 && !append_group(login, up->u_groupc, up->u_groupv)) { + (void) close(ptmpfd); + (void) pw_abort(); + errx(EXIT_FAILURE, "can't append `%s' to new groups", login); + } (void) close(ptmpfd); if (pw_mkdb() < 0) { err(EXIT_FAILURE, "pw_mkdb failed");