summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakan Olsson <ho@cvs.openbsd.org>2000-07-15 08:31:55 +0000
committerHakan Olsson <ho@cvs.openbsd.org>2000-07-15 08:31:55 +0000
commit0353fe4699dd92a0a5e736c168b324edfd5e5a60 (patch)
treed537ffe792b6fafc5576e6a03416032f58540840
parent0332b36de5c0aaf5662e612e855a1515e90abd71 (diff)
When modifying users and not specifying a new GID, don't arbitrarily
reset it to the default GID, keep the old one. Further, when given a new home dir, actually use it. Fixes PR #1318.
-rw-r--r--usr.sbin/user/user.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c
index 836b10b5937..09af2aad3fc 100644
--- a/usr.sbin/user/user.c
+++ b/usr.sbin/user/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.16 2000/07/06 09:23:30 ho Exp $ */
+/* $OpenBSD: user.c,v 1.17 2000/07/15 08:31:54 ho Exp $ */
/* $NetBSD: user.c,v 1.17 2000/04/14 06:26:55 simonb Exp $ */
/*
@@ -911,8 +911,10 @@ moduser(char *login, char *newlogin, user_t *up)
if (up->u_uid == -1) {
up->u_uid = pwp->pw_uid;
}
- /* if -g=uid was specified, check gid is unused */
- if (strcmp(up->u_primgrp, "=uid") == 0) {
+ if (up->u_primgrp == NULL) {
+ gid = pwp->pw_gid;
+ } else if (strcmp(up->u_primgrp, "=uid") == 0) {
+ /* if -g=uid was specified, check gid is unused */
if (getgrgid((gid_t)(up->u_uid)) != (struct group *) NULL) {
(void) close(ptmpfd);
(void) pw_abort();
@@ -938,6 +940,8 @@ moduser(char *login, char *newlogin, user_t *up)
/* if home directory hasn't been given, use the old one */
if (!up->u_homeset) {
(void) strlcpy(home, pwp->pw_dir, sizeof(home));
+ } else {
+ (void) strlcpy(home, up->u_home, sizeof(home));
}
expire = 0;
if (up->u_expire != NULL) {
@@ -1251,6 +1255,8 @@ usermod(int argc, char **argv)
(void) memset(newuser, 0, sizeof(newuser));
read_defaults(&u);
u.u_uid = -1;
+ free(u.u_primgrp);
+ u.u_primgrp = NULL;
have_new_user = 0;
while ((c = getopt(argc, argv, "G:c:d:e:f:g:l:mos:u:" MOD_OPT_EXTENSIONS)) != -1) {
switch(c) {