Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-6]: src/usr.sbin/user Pullup diffs between revision: 1.51.2.4 a...
details: https://anonhg.NetBSD.org/src/rev/a23f44e79ddb
branches: netbsd-1-6
changeset: 530906:a23f44e79ddb
user: jmc <jmc%NetBSD.org@localhost>
date: Mon Oct 20 07:30:49 2003 +0000
description:
Pullup diffs between revision: 1.51.2.4 and 1.70.
Numerous bug fixes, blowfish password support.
(requested by agc in ticket #1147)
diffstat:
usr.sbin/user/user.c | 289 ++++++++++++++++++++++++++++++++------------------
1 files changed, 185 insertions(+), 104 deletions(-)
diffs (truncated from 734 to 300 lines):
diff -r 6cd4d187fde3 -r a23f44e79ddb usr.sbin/user/user.c
--- a/usr.sbin/user/user.c Mon Oct 20 06:27:37 2003 +0000
+++ b/usr.sbin/user/user.c Mon Oct 20 07:30:49 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.51.2.4 2002/12/26 07:37:50 tron Exp $ */
+/* $NetBSD: user.c,v 1.51.2.5 2003/10/20 07:30:49 jmc Exp $ */
/*
* Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
@@ -35,7 +35,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1999 \
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.51.2.4 2002/12/26 07:37:50 tron Exp $");
+__RCSID("$NetBSD: user.c,v 1.51.2.5 2003/10/20 07:30:49 jmc Exp $");
#endif
#include <sys/types.h>
@@ -54,6 +54,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include <util.h>
@@ -72,21 +73,21 @@
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 */
- char *u_home; /* home directory */
- char *u_primgrp; /* primary group */
+ char *u_password; /* encrypted password */
+ char *u_comment; /* comment field */
+ char *u_home; /* home directory */
+ char *u_primgrp; /* primary group */
int u_groupc; /* # of secondary groups */
const char *u_groupv[NGROUPS_MAX]; /* secondary groups */
- char *u_shell; /* user's shell */
- char *u_basedir; /* base directory for home */
- char *u_expire; /* when password will expire */
- char *u_inactive; /* when account will expire */
- char *u_skeldir; /* directory for startup files */
- char *u_class; /* login class */
+ char *u_shell; /* user's shell */
+ char *u_basedir; /* base directory for home */
+ char *u_expire; /* when password will expire */
+ char *u_inactive; /* when account will expire */
+ char *u_skeldir; /* directory for startup files */
+ char *u_class; /* login class */
unsigned u_rsize; /* size of range array */
unsigned u_rc; /* # of ranges */
- range_t *u_rv; /* the ranges */
+ range_t *u_rv; /* the ranges */
unsigned u_defrc; /* # of ranges in defaults */
int u_preserve; /* preserve uids on deletion */
} user_t;
@@ -168,6 +169,8 @@
MaxEntryLen = 2048,
PasswordLength = 2048,
+ DES_Len = 13,
+
LowGid = DEF_LOWUID,
HighGid = DEF_HIGHUID
};
@@ -245,7 +248,7 @@
/* userid matches directory owner? */
if (st.st_uid != uid) {
- warnx("User `%s' doesn't own directory `%s', not removed\n", user, dir);
+ warnx("User `%s' doesn't own directory `%s', not removed", user, dir);
return 0;
}
@@ -254,7 +257,7 @@
(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);
+ warnx("Unable to remove all files in `%s'", dir);
return 0;
}
return 1;
@@ -351,7 +354,7 @@
is_number(char *s)
{
for ( ; *s ; s++) {
- if (!isdigit(*s)) {
+ if (!isdigit((unsigned char) *s)) {
return 0;
}
}
@@ -456,6 +459,7 @@
return 0;
}
(void) chmod(_PATH_GROUP, st.st_mode & 07777);
+ syslog(LOG_INFO, "new group added: name=%s, gid=%d", group, gid);
return 1;
}
@@ -527,6 +531,11 @@
return 0;
}
(void) chmod(_PATH_GROUP, st.st_mode & 07777);
+ if (newent == NULL) {
+ syslog(LOG_INFO, "group deleted: name=%s", group);
+ } else {
+ syslog(LOG_INFO, "group information modified: name=%s", group);
+ }
return 1;
}
@@ -627,8 +636,11 @@
static int
valid_login(char *login_name)
{
- char *cp;
+ unsigned char *cp;
+ if (strlen(login_name) >= LOGIN_NAME_MAX) {
+ return 0;
+ }
for (cp = login_name ; *cp ; cp++) {
if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-') {
return 0;
@@ -641,7 +653,7 @@
static int
valid_group(char *group)
{
- char *cp;
+ unsigned char *cp;
for (cp = group ; *cp ; cp++) {
if (!isalnum(*cp)) {
@@ -756,8 +768,8 @@
size_t lineno;
size_t len;
FILE *fp;
- char *cp;
- char *s;
+ unsigned char *cp;
+ unsigned char *s;
memsave(&up->u_primgrp, DEF_GROUP, strlen(DEF_GROUP));
memsave(&up->u_basedir, DEF_BASEDIR, strlen(DEF_BASEDIR));
@@ -881,7 +893,7 @@
static passwd_type_t passwd_types[] = {
{ "$2a", 3, 54, "\\$[^$]+\\$[^$]+\\$(.*)", 1 }, /* Blowfish */
{ "$1", 2, 34, NULL, 0 }, /* MD5 */
- { "", 0, 13, NULL, 0 }, /* standard DES */
+ { "", 0, DES_Len,NULL, 0 }, /* standard DES */
{ NULL, -1, -1, NULL, 0 } /* none - terminate search */
};
@@ -909,13 +921,34 @@
return 0;
}
+/* look for a valid time, return 0 if it was specified but bad */
+static int
+scantime(time_t *tp, char *s)
+{
+ struct tm tm;
+
+ *tp = 0;
+ if (s != NULL) {
+ (void) memset(&tm, 0, sizeof(tm));
+ if (strptime(s, "%c", &tm) != NULL) {
+ *tp = mktime(&tm);
+ } else if (strptime(s, "%B %d %Y", &tm) != NULL) {
+ *tp = mktime(&tm);
+ } else if (isdigit((unsigned char) s[0]) != NULL) {
+ *tp = atoi(s);
+ } else {
+ return 0;
+ }
+ }
+ return 1;
+}
+
/* add a user */
static int
adduser(char *login_name, user_t *up)
{
struct group *grp;
struct stat st;
- struct tm tm;
time_t expire;
time_t inactive;
char password[PasswordLength + 1];
@@ -946,7 +979,7 @@
if (write(ptmpfd, buf, (size_t)(cc)) != cc) {
(void) close(masterfd);
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
err(EXIT_FAILURE, "short write to /etc/ptmp (not %d chars)", cc);
}
}
@@ -974,21 +1007,21 @@
}
if (!got_id) {
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
errx(EXIT_FAILURE, "can't get next uid for %d", up->u_uid);
}
}
/* check uid isn't already allocated */
if (!(up->u_flags & F_DUPUID) && getpwuid((uid_t)(up->u_uid)) != NULL) {
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
errx(EXIT_FAILURE, "uid %d is already in use", up->u_uid);
}
/* if -g=uid was specified, check gid is unused */
if (sync_uid_gid) {
if (getgrgid((gid_t)(up->u_uid)) != NULL) {
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
errx(EXIT_FAILURE, "gid %d is already in use", up->u_uid);
}
gid = up->u_uid;
@@ -999,13 +1032,13 @@
gid = grp->gr_gid;
} else {
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
errx(EXIT_FAILURE, "group %s not found", up->u_primgrp);
}
/* check name isn't already in use */
if (!(up->u_flags & F_DUPUID) && getpwnam(login_name) != NULL) {
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
errx(EXIT_FAILURE, "already a `%s' user", login_name);
}
if (up->u_flags & F_HOMEDIR) {
@@ -1014,33 +1047,13 @@
/* if home directory hasn't been given, make it up */
(void) snprintf(home, sizeof(home), "%s/%s", up->u_basedir, login_name);
}
- inactive = 0;
- if (up->u_inactive != NULL) {
- (void) memset(&tm, 0, sizeof(tm));
- if (strptime(up->u_inactive, "%c", &tm) != NULL) {
- inactive = mktime(&tm);
- } else if (strptime(up->u_inactive, "%B %d %Y", &tm) != NULL) {
- inactive = mktime(&tm);
- } else if (isdigit(up->u_inactive[0]) != NULL) {
- inactive = atoi(up->u_inactive);
- } else {
- warnx("Warning: inactive time `%s' invalid, account expiry off",
+ if (!scantime(&inactive, up->u_inactive)) {
+ warnx("Warning: inactive time `%s' invalid, account expiry off",
up->u_inactive);
- }
}
- expire = 0;
- if (up->u_expire != NULL) {
- (void) memset(&tm, 0, sizeof(tm));
- if (strptime(up->u_expire, "%c", &tm) != NULL) {
- expire = mktime(&tm);
- } else if (strptime(up->u_expire, "%B %d %Y", &tm) != NULL) {
- expire = mktime(&tm);
- } else if (isdigit(up->u_expire[0]) != NULL) {
- expire = atoi(up->u_expire);
- } else {
- warnx("Warning: expire time `%s' invalid, password expiry off",
+ if (!scantime(&expire, up->u_expire)) {
+ warnx("Warning: expire time `%s' invalid, password expiry off",
up->u_expire);
- }
}
if (lstat(home, &st) < 0 && !(up->u_flags & F_MKDIR)) {
warnx("Warning: home directory `%s' doesn't exist, and -m was not specified",
@@ -1050,8 +1063,8 @@
if (up->u_password != NULL && valid_password_length(up->u_password)) {
(void) strlcpy(password, up->u_password, sizeof(password));
} else {
- (void) memset(password, '\0', sizeof(password));
- password[0] = '*';
+ (void) memset(password, '*', DES_Len);
+ password[DES_Len] = 0;
if (up->u_password != NULL) {
warnx("Password `%s' is invalid: setting it to `%s'",
up->u_password, password);
@@ -1074,18 +1087,18 @@
up->u_shell);
if (write(ptmpfd, buf, (size_t) cc) != cc) {
(void) close(ptmpfd);
- (void) pw_abort();
+ pw_abort();
err(EXIT_FAILURE, "can't add `%s'", buf);
}
Home |
Main Index |
Thread Index |
Old Index