--- /dev/null
+/* $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"
+
-/* $NetBSD: user.c,v 1.126 2011/01/04 10:30:21 wiz Exp $ */
+/* $NetBSD: user.c,v 1.129 2011/12/01 00:34:05 dholland Exp $ */
/*
* Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1999\
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.126 2011/01/04 10:30:21 wiz Exp $");
+__RCSID("$NetBSD: user.c,v 1.129 2011/12/01 00:34:05 dholland Exp $");
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <ctype.h>
#include <dirent.h>
#ifdef EXTENSIONS
#include <login_cap.h>
#endif
-#include <paths.h>
#include <pwd.h>
#include <regex.h>
#include <stdarg.h>
#include <util.h>
#include <errno.h>
+#include "pathnames.h"
#include "defs.h"
#include "usermgmt.h"
#define LOCK 1
#define LOCKED "*LOCKED*"
-#define PATH_LOGINCONF "/etc/login.conf"
#ifndef DEF_GROUP
#define DEF_GROUP "users"
DES_Len = 13,
};
-/* Full paths of programs used here */
-#define CHMOD "/bin/chmod"
-#define CHOWN "/usr/bin/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)"
-static int asystem(const char *fmt, ...)
- __attribute__((__format__(__printf__, 1, 2)));
+static int asystem(const char *fmt, ...) __printflike(1, 2);
static int is_number(const char *);
static struct group *find_group_info(const char *);
static int verbose;
if (verbose) {
(void)printf("Command: %s\n", buf);
}
- if ((ret = system(buf)) != 0) {
+ ret = system(buf);
+ if (ret == -1) {
warn("Error running `%s'", buf);
+ } else if (WIFSIGNALED(ret)) {
+ warnx("Error running `%s': Signal %d", buf, WTERMSIG(ret));
+ } else if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0) {
+ warnx("Error running `%s': Exit %d", buf, WEXITSTATUS(ret));
}
return ret;
}
(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);
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;
}
warnx("Can't create group `%s': already exists", group);
return 0;
}
- if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
+ if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
warn("Can't create group `%s': can't open `%s'", name,
_PATH_GROUP);
return 0;
int fd;
int cc;
- if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
+ if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
warn("Can't modify group `%s': can't open `%s'",
group, _PATH_GROUP);
return 0;
}
}
}
- if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
+ if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
warn("Can't append group(s) for `%s': can't open `%s'",
user, _PATH_GROUP);
return 0;
* 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;
}
}
/* 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)
login_name, up->u_class);
}
#endif
- if ((masterfd = open(_PATH_MASTERPASSWD, O_RDWR)) < 0) {
+ if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
err(EXIT_FAILURE, "Can't add user `%s': can't open `%s'",
login_name, _PATH_MASTERPASSWD);
}
"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': "
buf);
return 0;
}
- if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
+ if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
warn("Can't remove user `%s' from `%s': can't open `%s'",
login_name, _PATH_GROUP, _PATH_GROUP);
return 0;
/* keep dir name in case we need it for '-m' */
homedir = pwp->pw_dir;
- if ((masterfd = open(_PATH_MASTERPASSWD, O_RDWR)) < 0) {
+ if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
err(EXIT_FAILURE, "Can't modify user `%s': can't open `%s'",
login_name, _PATH_MASTERPASSWD);
}
}
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': "
}
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));