Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/usr.sbin/user Pull up revisions 1.12, 1.14-1.24, 1.26-1.2...



details:   https://anonhg.NetBSD.org/src/rev/1048e736b57d
branches:  netbsd-1-4
changeset: 471180:1048e736b57d
user:      he <he%NetBSD.org@localhost>
date:      Wed Oct 25 17:08:01 2000 +0000

description:
Pull up revisions 1.12,1.14-1.24,1.26-1.29 (via patch, requested by simonb):
  Synchronize to current versions of the user management tool.
  Fixes PR#11100, PR#11103, PR#11123 and PR#10985.

diffstat:

 usr.sbin/user/user.c |  696 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 475 insertions(+), 221 deletions(-)

diffs (truncated from 1319 to 300 lines):

diff -r 52efd8cf97ef -r 1048e736b57d usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Wed Oct 25 17:07:36 2000 +0000
+++ b/usr.sbin/user/user.c      Wed Oct 25 17:08:01 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.10.2.6 2000/10/19 17:05:56 he Exp $ */
+/* $NetBSD: user.c,v 1.10.2.7 2000/10/25 17:08:01 he Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -33,10 +33,9 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__COPYRIGHT(
-       "@(#) Copyright (c) 1999 \
+__COPYRIGHT("@(#) Copyright (c) 1999 \
                The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.10.2.6 2000/10/19 17:05:56 he Exp $");
+__RCSID("$NetBSD: user.c,v 1.10.2.7 2000/10/25 17:08:01 he Exp $");
 #endif
 
 #include <sys/types.h>
@@ -48,6 +47,7 @@
 #include <err.h>
 #include <fcntl.h>
 #include <grp.h>
+#include <paths.h>
 #include <pwd.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -60,6 +60,7 @@
 #include "defs.h"
 #include "usermgmt.h"
 
+
 /* this struct describes a uid range */
 typedef struct range_t {
        int     r_from;         /* low uid */
@@ -68,10 +69,10 @@
 
 /* this struct encapsulates the user information */
 typedef struct user_t {
+       int             u_flags;                /* see below */
        int             u_uid;                  /* uid of user */
        char            *u_password;            /* encrypted password */
        char            *u_comment;             /* comment field */
-       int             u_homeset;              /* home dir has been set */
        char            *u_home;                /* home directory */
        char            *u_primgrp;             /* primary group */
        int             u_groupc;               /* # of secondary groups */
@@ -80,8 +81,6 @@
        char            *u_basedir;             /* base directory for home */
        char            *u_expire;              /* when password will expire */
        int             u_inactive;             /* inactive */
-       int             u_mkdir;                /* make the home directory */
-       int             u_dupuid;               /* duplicate uids are allowed */
        char            *u_skeldir;             /* directory for startup files */
        unsigned        u_rsize;                /* size of range array */
        unsigned        u_rc;                   /* # of ranges */
@@ -90,6 +89,22 @@
        int             u_preserve;             /* preserve uids on deletion */
 } user_t;
 
+/* flags for which fields of the user_t replace the passwd entry */
+enum {
+       F_COMMENT       = 0x0001,
+       F_DUPUID        = 0x0002,
+       F_EXPIRE        = 0x0004,
+       F_GROUP         = 0x0008,
+       F_HOMEDIR       = 0x0010,
+       F_MKDIR         = 0x0020,
+       F_INACTIVE      = 0x0040,
+       F_PASSWORD      = 0x0080,
+       F_SECGROUP      = 0x0100,
+       F_SHELL         = 0x0200,
+       F_UID           = 0x0400,
+       F_USERNAME      = 0x0800
+};
+
 #define CONFFILE       "/etc/usermgmt.conf"
 
 #ifndef DEF_GROUP
@@ -105,7 +120,7 @@
 #endif
 
 #ifndef DEF_SHELL
-#define DEF_SHELL      "/bin/csh"
+#define DEF_SHELL      _PATH_CSHELL
 #endif
 
 #ifndef DEF_COMMENT
@@ -125,15 +140,7 @@
 #endif
 
 #ifndef DEF_EXPIRE
-#define DEF_EXPIRE     (char *) NULL
-#endif
-
-#ifndef MASTER
-#define MASTER         "/etc/master.passwd"
-#endif
-
-#ifndef ETCGROUP
-#define ETCGROUP       "/etc/group"
+#define DEF_EXPIRE     NULL
 #endif
 
 #ifndef WAITSECS
@@ -177,12 +184,12 @@
 static void
 memsave(char **cpp, char *s, size_t n)
 {
-       if (*cpp != (char *) NULL) {
+       if (*cpp != NULL) {
                FREE(*cpp);
        }
        NEWARRAY(char, *cpp, n + 1, exit(1));
        (void) memcpy(*cpp, s, n);
-       (*cpp)[n] = 0;
+       (*cpp)[n] = '\0';
 }
 
 /* a replacement for system(3) */
@@ -205,6 +212,49 @@
        return ret;
 }
 
+/* remove a users home directory, returning 1 for success (ie, no problems encountered) */
+static int
+removehomedir(const char *user, int uid, const char *dir)
+{
+       struct stat st;
+
+       /* userid not root? */
+       if (uid == 0) {
+               warnx("Not deleting home directory `%s'; userid is 0", dir);
+               return 0;
+       }
+
+       /* directory exists (and is a directory!) */
+       if (stat(dir, &st) < 0) {
+               warnx("Home directory `%s' doesn't exist", dir);
+               return 0;
+       }
+       if (!S_ISDIR(st.st_mode)) {
+               warnx("Home directory `%s' is not a directory", dir);
+               return 0;
+       }
+
+       /* userid matches directory owner? */
+       if (st.st_uid != uid) {
+               warnx("User `%s' doesn't own directory `%s', not removed\n", user, dir);
+               return 0;
+       }
+
+       (void) seteuid(uid);
+       /* we add the "|| true" to keep asystem() quiet if there is a non-zero exit status. */
+#if 1
+printf("XXX: %s -rf %s > /dev/null 2>&1 || true", RM, dir);
+#else
+       (void) asystem("%s -rf %s > /dev/null 2>&1 || true", RM, dir);
+       (void) seteuid(0);
+       if (rmdir(dir) < 0) {
+               warnx("Unable to remove all files in `%s'\n", dir);
+               return 0;
+       }
+#endif
+       return 1;
+}
+
 #define NetBSD_1_4_K   104110000
 
 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ < NetBSD_1_4_K)
@@ -218,12 +268,79 @@
        fromsize = strlen(from);
        n = MIN(tosize - 1, fromsize);
        (void) memcpy(to, from, n);
-       to[n] = 0;
+       to[n] = '\0';
        return fromsize;
 }
-#endif
+#endif /* NetBSD < 1.4K */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * research has shown that NetBSD 1.3H was the first version of -current
+ * with asprintf in libc. agc
+ */
+#define NetBSD_1_3_H   103080000
 
-#ifdef EXTENSIONS
+#if defined(__NetBSD_Version__) && (__NetBSD_Version__ < NetBSD_1_3_H)
+
+int
+asprintf(char **str, char const *fmt, ...)
+{
+       int ret;
+       va_list ap;
+       FILE f;
+       unsigned char *_base;
+
+       va_start(ap, fmt);
+       f._flags = __SWR | __SSTR | __SALC;
+       f._bf._base = f._p = (unsigned char *)malloc(128);
+       if (f._bf._base == NULL)
+               goto err;
+       f._bf._size = f._w = 127;               /* Leave room for the NUL */
+       ret = vfprintf(&f, fmt, ap);
+       if (ret == -1)
+               goto err;
+       *f._p = '\0';
+       va_end(ap);
+       _base = realloc(f._bf._base, (size_t)(ret + 1));
+       if (_base == NULL)
+               goto err;
+       *str = (char *)_base;
+       return (ret);
+
+err:
+       if (f._bf._base)
+               free(f._bf._base);
+       *str = NULL;
+       return (-1);
+}
+#endif /* NetBSD < 1.3H */
+
 /* return 1 if all of `s' is numeric */
 static int
 is_number(char *s)
@@ -235,7 +352,6 @@
        }
        return 1;
 }
-#endif
 
 /*
  * check that the effective uid is 0 - called from funcs which will
@@ -257,11 +373,11 @@
        DIR             *dirp;
        int             n;
 
-       if ((dirp = opendir(skeldir)) == (DIR *) NULL) {
+       if ((dirp = opendir(skeldir)) == NULL) {
                warn("can't open source . files dir `%s'", skeldir);
                return 0;
        }
-       for (n = 0; (dp = readdir(dirp)) != (struct dirent *) NULL && n == 0 ; ) {
+       for (n = 0; (dp = readdir(dirp)) != NULL && n == 0 ; ) {
                if (strcmp(dp->d_name, ".") == 0 ||
                    strcmp(dp->d_name, "..") == 0) {
                        continue;
@@ -291,21 +407,25 @@
        int             fd;
        int             cc;
 
-       if ((from = fopen(ETCGROUP, "r")) == (FILE *) NULL) {
-               warn("can't create gid for %s: can't open %s", name, ETCGROUP);
+       if (getgrnam(group) != NULL) {
+               warnx("group `%s' already exists", group);
+               return 0;
+       }
+       if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
+               warn("can't create gid for %s: can't open %s", name, _PATH_GROUP);
                return 0;
        }
        if (flock(fileno(from), LOCK_EX | LOCK_NB) < 0) {
-               warn("can't lock `%s'", ETCGROUP);
+               warn("can't lock `%s'", _PATH_GROUP);
        }
        (void) fstat(fileno(from), &st);
-       (void) snprintf(f, sizeof(f), "%s.XXXXXX", ETCGROUP);
+       (void) snprintf(f, sizeof(f), "%s.XXXXXX", _PATH_GROUP);
        if ((fd = mkstemp(f)) < 0) {



Home | Main Index | Thread Index | Old Index