Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/user Move path names to pathnames.h per conventions



details:   https://anonhg.NetBSD.org/src/rev/6f684b8359a3
branches:  trunk
changeset: 771720:6f684b8359a3
user:      dholland <dholland%NetBSD.org@localhost>
date:      Thu Dec 01 00:34:05 2011 +0000

description:
Move path names to pathnames.h per conventions

diffstat:

 usr.sbin/user/pathnames.h |  44 ++++++++++++++++++++++++++++++++++++++++++++
 usr.sbin/user/user.c      |  41 ++++++++++++++++-------------------------
 2 files changed, 60 insertions(+), 25 deletions(-)

diffs (183 lines):

diff -r fe126a93ccdb -r 6f684b8359a3 usr.sbin/user/pathnames.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/user/pathnames.h Thu Dec 01 00:34:05 2011 +0000
@@ -0,0 +1,44 @@
+/* $NetBSD: pathnames.h,v 1.1 2011/12/01 00:34:05 dholland Exp $ */
+
+/*
+ * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
+ * Copyright (c) 2005 Liam J. Foy.  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 BY THE AUTHOR ``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.
+ */
+
+#include <paths.h>
+
+/* Full paths of programs used here */
+#define _PATH_CHMOD            "/bin/chmod"
+#define _PATH_CHOWN            "/usr/sbin/chown"
+#define        _PATH_LOGINCONF         "/etc/login.conf"
+#define _PATH_MKDIR            "/bin/mkdir"
+#define _PATH_MV               "/bin/mv"
+/* note that there's a _PATH_NOLOGIN in <paths.h> that's for /etc/nologin */
+#define _PATH_SBIN_NOLOGIN     "/sbin/nologin"
+#define _PATH_PAX              "/bin/pax"
+#define _PATH_RM               "/bin/rm"
+
diff -r fe126a93ccdb -r 6f684b8359a3 usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Thu Dec 01 00:26:45 2011 +0000
+++ b/usr.sbin/user/user.c      Thu Dec 01 00:34:05 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.128 2011/12/01 00:26:45 dholland Exp $ */
+/* $NetBSD: user.c,v 1.129 2011/12/01 00:34:05 dholland Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.128 2011/12/01 00:26:45 dholland Exp $");
+__RCSID("$NetBSD: user.c,v 1.129 2011/12/01 00:34:05 dholland Exp $");
 #endif
 
 #include <sys/types.h>
@@ -49,7 +49,6 @@
 #ifdef EXTENSIONS
 #include <login_cap.h>
 #endif
-#include <paths.h>
 #include <pwd.h>
 #include <regex.h>
 #include <stdarg.h>
@@ -62,6 +61,7 @@
 #include <util.h>
 #include <errno.h>
 
+#include "pathnames.h"
 #include "defs.h"
 #include "usermgmt.h"
 
@@ -142,8 +142,6 @@
 #define LOCK           1
 #define LOCKED         "*LOCKED*"
 
-#define        PATH_LOGINCONF  "/etc/login.conf"
-
 #ifndef DEF_GROUP
 #define DEF_GROUP      "users"
 #endif
@@ -208,15 +206,6 @@
        DES_Len = 13,
 };
 
-/* Full paths of programs used here */
-#define CHMOD          "/bin/chmod"
-#define CHOWN          "/usr/sbin/chown"
-#define MKDIR          "/bin/mkdir"
-#define MV             "/bin/mv"
-#define NOLOGIN                "/sbin/nologin"
-#define PAX            "/bin/pax"
-#define RM             "/bin/rm"
-
 #define UNSET_INACTIVE "Null (unset)"
 #define UNSET_EXPIRY   "Null (unset)"
 
@@ -308,7 +297,8 @@
 
        (void)seteuid(pwp->pw_uid);
        /* we add the "|| true" to keep asystem() quiet if there is a non-zero exit status. */
-       (void)asystem("%s -rf %s > /dev/null 2>&1 || true", RM, pwp->pw_dir);
+       (void)asystem("%s -rf %s > /dev/null 2>&1 || true", _PATH_RM,
+                     pwp->pw_dir);
        (void)seteuid(0);
        if (rmdir(pwp->pw_dir) < 0) {
                warn("Unable to remove all files in `%s'", pwp->pw_dir);
@@ -365,12 +355,12 @@
                warnx("No \"dot\" initialisation files found");
        } else {
                (void)asystem("cd %s && %s -rw -pe %s . %s",
-                               skeldir, PAX, (verbose) ? "-v" : "", dir);
+                       skeldir, _PATH_PAX, (verbose) ? "-v" : "", dir);
        }
-       (void)asystem("%s -R -h %d:%d %s", CHOWN, uid, gid, dir);
-       (void)asystem("%s -R u+w %s", CHMOD, dir);
+       (void)asystem("%s -R -h %d:%d %s", _PATH_CHOWN, uid, gid, dir);
+       (void)asystem("%s -R u+w %s", _PATH_CHMOD, dir);
 #ifdef EXTENSIONS
-       (void)asystem("%s 0%o %s", CHMOD, homeperm, dir);
+       (void)asystem("%s 0%o %s", _PATH_CHMOD, homeperm, dir);
 #endif
        return n;
 }
@@ -994,9 +984,9 @@
         * user the actual login class does not exist.
         */
 
-       if (access(PATH_LOGINCONF, R_OK) == -1) {
+       if (access(_PATH_LOGINCONF, R_OK) == -1) {
                warn("Access failed for `%s'; will not validate class `%s'",
-                   PATH_LOGINCONF, class);
+                   _PATH_LOGINCONF, class);
                return 1;
        }
 
@@ -1021,7 +1011,7 @@
        } 
 
        /* if nologin is used as a shell, consider it a valid shell */
-       if (strcmp(shellname, NOLOGIN) == 0)
+       if (strcmp(shellname, _PATH_SBIN_NOLOGIN) == 0)
                return 1;
 
        while ((shellp = getusershell()) != NULL)
@@ -1262,7 +1252,7 @@
                            "Can't add user `%s': home directory `%s' "
                            "already exists", login_name, home);
                } else {
-                       if (asystem("%s -p %s", MKDIR, home) != 0) {
+                       if (asystem("%s -p %s", _PATH_MKDIR, home) != 0) {
                                (void)close(ptmpfd);
                                (void)pw_abort();
                                errx(EXIT_FAILURE, "Can't add user `%s': "
@@ -1704,7 +1694,7 @@
        }
        if (up != NULL) {
                if ((up->u_flags & F_MKDIR) &&
-                   asystem("%s %s %s", MV, homedir, pwp->pw_dir) != 0) {
+                   asystem("%s %s %s", _PATH_MV, homedir, pwp->pw_dir) != 0) {
                        (void)close(ptmpfd);
                        (void)pw_abort();
                        errx(EXIT_FAILURE, "Can't modify user `%s': "
@@ -2210,7 +2200,8 @@
        }
        if (up->u_preserve) {
                up->u_flags |= F_SHELL;
-               memsave(&up->u_shell, NOLOGIN, strlen(NOLOGIN));
+               memsave(&up->u_shell, _PATH_SBIN_NOLOGIN,
+                       strlen(_PATH_SBIN_NOLOGIN));
                (void)memset(password, '*', DES_Len);
                password[DES_Len] = 0;
                memsave(&up->u_password, password, strlen(password));



Home | Main Index | Thread Index | Old Index