Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/user Pullup through 1.29 [simonb]:



details:   https://anonhg.NetBSD.org/src/rev/82df4765c518
branches:  netbsd-1-5
changeset: 489965:82df4765c518
user:      tv <tv%NetBSD.org@localhost>
date:      Fri Oct 20 20:00:18 2000 +0000

description:
Pullup through 1.29 [simonb]:
Numerous cosmetic fixes and bug fixes, already discussed to be part of 1.5.

diffstat:

 usr.sbin/user/user.c |  545 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 390 insertions(+), 155 deletions(-)

diffs (truncated from 995 to 300 lines):

diff -r dcdbf0d62fdf -r 82df4765c518 usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Fri Oct 20 18:21:35 2000 +0000
+++ b/usr.sbin/user/user.c      Fri Oct 20 20:00:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.20.4.1 2000/10/17 19:50:31 tv Exp $ */
+/* $NetBSD: user.c,v 1.20.4.2 2000/10/20 20:00:18 tv 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.20.4.1 2000/10/17 19:50:31 tv Exp $");
+__RCSID("$NetBSD: user.c,v 1.20.4.2 2000/10/20 20:00:18 tv 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,7 +140,7 @@
 #endif
 
 #ifndef DEF_EXPIRE
-#define DEF_EXPIRE     (char *) NULL
+#define DEF_EXPIRE     NULL
 #endif
 
 #ifndef WAITSECS
@@ -169,7 +184,7 @@
 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));
@@ -197,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)
@@ -213,7 +271,75 @@
        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
+
+#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
@@ -247,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;
@@ -281,11 +407,11 @@
        int             fd;
        int             cc;
 
-       if (getgrnam(group) != (struct group *) NULL) {
+       if (getgrnam(group) != NULL) {
                warnx("group `%s' already exists", group);
                return 0;
        }
-       if ((from = fopen(_PATH_GROUP, "r")) == (FILE *) NULL) {
+       if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
                warn("can't create gid for %s: can't open %s", name, _PATH_GROUP);
                return 0;
        }
@@ -299,7 +425,7 @@
                warn("can't create gid: mkstemp failed");
                return 0;
        }
-       if ((to = fdopen(fd, "w")) == (FILE *) NULL) {
+       if ((to = fdopen(fd, "w")) == NULL) {
                (void) fclose(from);
                (void) close(fd);
                (void) unlink(f);
@@ -341,7 +467,7 @@
        int             fd;
        int             cc;
 
-       if ((from = fopen(_PATH_GROUP, "r")) == (FILE *) NULL) {
+       if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
                warn("can't create gid for %s: can't open %s", group, _PATH_GROUP);
                return 0;
        }
@@ -355,7 +481,7 @@
                warn("can't create gid: mkstemp failed");
                return 0;
        }
-       if ((to = fdopen(fd, "w")) == (FILE *) NULL) {
+       if ((to = fdopen(fd, "w")) == NULL) {
                (void) fclose(from);
                (void) close(fd);
                (void) unlink(f);
@@ -396,6 +522,98 @@
        return 1;
 }
 
+/* modify the group entries for all `groups', by adding `user' */
+static int
+append_group(char *user, int ngroups, char **groups)
+{
+       struct group    *grp;



Home | Main Index | Thread Index | Old Index