summaryrefslogtreecommitdiff
path: root/usr.sbin/user
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/user')
-rw-r--r--usr.sbin/user/user.c94
1 files changed, 70 insertions, 24 deletions
diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c
index 0731ca5a691..b800059c99a 100644
--- a/usr.sbin/user/user.c
+++ b/usr.sbin/user/user.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: user.c,v 1.44 2003/06/08 20:50:51 millert Exp $ */
-/* $NetBSD: user.c,v 1.45 2001/08/17 08:29:00 joda Exp $ */
+/* $OpenBSD: user.c,v 1.45 2003/06/08 23:04:36 millert Exp $ */
+/* $NetBSD: user.c,v 1.52 2002/06/01 06:28:06 grant Exp $ */
/*
* Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
@@ -73,7 +73,7 @@ typedef struct user_t {
char *u_shell; /* user's shell */
char *u_basedir; /* base directory for home */
char *u_expire; /* when password will expire */
- int u_inactive; /* inactive */
+ char *u_inactive; /* when account will expire */
char *u_skeldir; /* directory for startup files */
char *u_class; /* login class */
unsigned int u_rsize; /* size of range array */
@@ -171,6 +171,7 @@ enum {
#define PAX "/bin/pax"
#define RM "/bin/rm"
+#define UNSET_INACTIVE "Null (unset)"
#define UNSET_EXPIRY "Null (unset)"
static int asystem(const char *fmt, ...)
@@ -322,7 +323,7 @@ creategid(char *group, gid_t gid, char *name)
return 0;
}
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
- warn("can't create gid for %s: can't open %s", group,
+ warn("can't create gid for `%s': can't open `%s'", group,
_PATH_GROUP);
return 0;
}
@@ -381,7 +382,7 @@ modify_gid(char *group, char *newent)
int cc;
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
- warn("can't create gid for %s: can't open %s", group,
+ warn("can't create gid for `%s': can't open `%s'", group,
_PATH_GROUP);
return 0;
}
@@ -474,7 +475,7 @@ append_group(char *user, int ngroups, char **groups)
}
}
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
- warn("can't append group for %s: can't open %s", user,
+ warn("can't append group for `%s': can't open `%s'", user,
_PATH_GROUP);
return 0;
}
@@ -659,7 +660,7 @@ setdefaults(user_t *up)
#ifdef EXTENSIONS
fprintf(fp, "class\t\t%s\n", up->u_class) <= 0 ||
#endif
- fprintf(fp, "inactive\t%d\n", up->u_inactive) <= 0 ||
+ fprintf(fp, "inactive\t%s\n", (up->u_inactive == NULL) ? UNSET_INACTIVE : up->u_inactive) <= 0 ||
fprintf(fp, "expire\t\t%s\n", (up->u_expire == NULL) ? UNSET_EXPIRY : up->u_expire) <= 0 ||
fprintf(fp, "preserve\t%s\n", (up->u_preserve == 0) ? "false" : "true") <= 0) {
warn("can't write to `%s'", CONFFILE);
@@ -741,7 +742,14 @@ read_defaults(user_t *up)
} else if (strncmp(s, "inactive", 8) == 0) {
for (cp = s + 8 ; *cp && isspace(*cp) ; cp++) {
}
- up->u_inactive = atoi(cp);
+ if (strcmp(cp, UNSET_INACTIVE) == 0) {
+ if (up->u_inactive) {
+ FREE(up->u_inactive);
+ }
+ up->u_inactive = NULL;
+ } else {
+ memsave(&up->u_inactive, cp, strlen(cp));
+ }
#ifdef EXTENSIONS
} else if (strncmp(s, "range", 5) == 0) {
for (cp = s + 5 ; *cp && isspace(*cp) ; cp++) {
@@ -806,6 +814,7 @@ adduser(char *login, user_t *up)
struct stat st;
struct tm tm;
time_t expire;
+ time_t inactive;
char password[PasswordLength + 1];
char home[MaxFileNameLen];
char buf[LINE_MAX];
@@ -904,13 +913,32 @@ adduser(char *login, user_t *up)
/* if home directory hasn't been given, make it up */
(void) snprintf(home, sizeof(home), "%s/%s", up->u_basedir, login);
}
+ 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",
+ up->u_inactive);
+ }
+ }
expire = 0;
if (up->u_expire != NULL) {
(void) memset(&tm, 0, sizeof(tm));
- if (strptime(up->u_expire, "%c", &tm) == NULL) {
- warnx("invalid time format `%s'", optarg);
- } else {
+ 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",
+ up->u_expire);
}
}
if (lstat(home, &st) < 0 && !(up->u_flags & F_MKDIR)) {
@@ -928,7 +956,7 @@ adduser(char *login, user_t *up)
}
}
- if ((cc = snprintf(buf, sizeof(buf), "%s:%s:%u:%u:%s:%d:%ld:%s:%s:%s\n",
+ cc = snprintf(buf, sizeof(buf), "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
login,
password,
up->u_uid,
@@ -938,13 +966,14 @@ adduser(char *login, user_t *up)
#else
"",
#endif
- up->u_inactive,
+ (long) inactive,
(long) expire,
up->u_comment,
home,
- up->u_shell)) >= sizeof(buf) || cc < 0 ||
- (strchr(up->u_comment, '&') != NULL &&
- cc + strlen(login) >= sizeof(buf))) {
+ up->u_shell);
+ if (strchr(up->u_comment, '&') != NULL)
+ cc += strlen(login);
+ if (cc >= sizeof(buf)) {
(void) close(ptmpfd);
pw_abort();
errx(EXIT_FAILURE, "can't add `%s', line too long", buf);
@@ -1086,14 +1115,31 @@ moduser(char *login, char *newlogin, user_t *up)
errx(EXIT_FAILURE, "group %s not found", up->u_primgrp);
}
}
- if (up->u_flags |= F_INACTIVE)
- pwp->pw_change = up->u_inactive;
+ if (up->u_flags & F_INACTIVE) {
+ (void) memset(&tm, 0, sizeof(tm));
+ if (strptime(up->u_inactive, "%c", &tm) != NULL) {
+ pwp->pw_change = mktime(&tm);
+ } else if (strptime(up->u_inactive, "%B %d %Y", &tm) != NULL) {
+ pwp->pw_change = mktime(&tm);
+ } else if (isdigit(up->u_inactive[0]) != NULL) {
+ pwp->pw_change = atoi(up->u_inactive);
+ } else {
+ warnx("Warning: inactive time `%s' invalid, password expiry off",
+ up->u_inactive);
+ }
+ }
if (up->u_flags & F_EXPIRE) {
(void) memset(&tm, 0, sizeof(tm));
- if (strptime(up->u_expire, "%c", &tm) == NULL)
- warnx("invalid time format `%s'", optarg);
- else
+ if (strptime(up->u_expire, "%c", &tm) != NULL) {
+ pwp->pw_expire = mktime(&tm);
+ } else if (strptime(up->u_expire, "%B %d %Y", &tm) != NULL) {
pwp->pw_expire = mktime(&tm);
+ } else if (isdigit(up->u_expire[0]) != NULL) {
+ pwp->pw_expire = atoi(up->u_expire);
+ } else {
+ warnx("Warning: expire time `%s' invalid, password expiry off",
+ up->u_expire);
+ }
}
if (up->u_flags & F_COMMENT)
pwp->pw_gecos = up->u_comment;
@@ -1324,7 +1370,7 @@ useradd(int argc, char **argv)
break;
case 'f':
defaultfield = 1;
- u.u_inactive = atoi(optarg);
+ memsave(&u.u_inactive, optarg, strlen(optarg));
break;
case 'g':
defaultfield = 1;
@@ -1386,7 +1432,7 @@ useradd(int argc, char **argv)
#ifdef EXTENSIONS
(void) printf("class\t\t%s\n", u.u_class);
#endif
- (void) printf("inactive\t%d\n", u.u_inactive);
+ (void) printf("inactive\t%s\n", (u.u_inactive == NULL) ? UNSET_INACTIVE : u.u_inactive);
(void) printf("expire\t\t%s\n", (u.u_expire == NULL) ? UNSET_EXPIRY : u.u_expire);
#ifdef EXTENSIONS
for (i = 0 ; i < u.u_rc ; i++) {
@@ -1450,7 +1496,7 @@ usermod(int argc, char **argv)
u.u_flags |= F_EXPIRE;
break;
case 'f':
- u.u_inactive = atoi(optarg);
+ memsave(&u.u_inactive, optarg, strlen(optarg));
u.u_flags |= F_INACTIVE;
break;
case 'g':