summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/chpass/chpass.c8
-rw-r--r--usr.bin/chpass/chpass.h4
-rw-r--r--usr.bin/chpass/field.c10
-rw-r--r--usr.bin/chpass/util.c38
4 files changed, 39 insertions, 21 deletions
diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c
index 8b716ba..ad6b985 100644
--- a/usr.bin/chpass/chpass.c
+++ b/usr.bin/chpass/chpass.c
@@ -53,15 +53,9 @@ static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
__FBSDID("$FreeBSD$");
#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/signal.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <ctype.h>
#include <err.h>
#include <errno.h>
-#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -292,7 +286,7 @@ usage(void)
{
(void)fprintf(stderr,
- "Usage: chpass%s %s [user]\n",
+ "usage: chpass%s %s [user]\n",
#ifdef YP
" [-d domain] [-h host]",
#else
diff --git a/usr.bin/chpass/chpass.h b/usr.bin/chpass/chpass.h
index b78b85e..ed1a586 100644
--- a/usr.bin/chpass/chpass.h
+++ b/usr.bin/chpass/chpass.h
@@ -64,7 +64,8 @@ extern int master_mode;
int atot(char *, time_t *);
struct passwd *edit(const char *, struct passwd *);
-char *ok_shell(char *);
+int ok_shell(char *);
+char *dup_shell(char *);
int p_change(char *, struct passwd *, ENTRY *);
int p_class(char *, struct passwd *, ENTRY *);
int p_expire(char *, struct passwd *, ENTRY *);
@@ -72,7 +73,6 @@ int p_gecos(char *, struct passwd *, ENTRY *);
int p_gid(char *, struct passwd *, ENTRY *);
int p_hdir(char *, struct passwd *, ENTRY *);
int p_login(char *, struct passwd *, ENTRY *);
-int p_login(char *, struct passwd *, ENTRY *);
int p_passwd(char *, struct passwd *, ENTRY *);
int p_shell(char *, struct passwd *, ENTRY *);
int p_uid(char *, struct passwd *, ENTRY *);
diff --git a/usr.bin/chpass/field.c b/usr.bin/chpass/field.c
index fe5b30f..eac5561 100644
--- a/usr.bin/chpass/field.c
+++ b/usr.bin/chpass/field.c
@@ -56,10 +56,8 @@ __FBSDID("$FreeBSD$");
#include <grp.h>
#include <paths.h>
#include <pwd.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include "chpass.h"
@@ -218,7 +216,6 @@ p_hdir(char *p, struct passwd *pw, ENTRY *ep __unused)
int
p_shell(char *p, struct passwd *pw, ENTRY *ep __unused)
{
- char *t;
struct stat sbuf;
if (!*p) {
@@ -230,15 +227,16 @@ p_shell(char *p, struct passwd *pw, ENTRY *ep __unused)
warnx("%s: current shell non-standard", pw->pw_shell);
return (-1);
}
- if (!(t = ok_shell(p))) {
+ if (!ok_shell(p)) {
if (!master_mode) {
warnx("%s: non-standard shell", p);
return (-1);
}
+ pw->pw_shell = strdup(p);
}
else
- p = t;
- if (!(pw->pw_shell = strdup(p))) {
+ pw->pw_shell = dup_shell(p);
+ if (!pw->pw_shell) {
warnx("can't save entry");
return (-1);
}
diff --git a/usr.bin/chpass/util.c b/usr.bin/chpass/util.c
index ac105aa..07d96e2 100644
--- a/usr.bin/chpass/util.c
+++ b/usr.bin/chpass/util.c
@@ -49,7 +49,6 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <ctype.h>
-#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -139,18 +138,45 @@ bad: return (1);
return (0);
}
-char *
+int
ok_shell(char *name)
{
char *p, *sh;
setusershell();
while ((sh = getusershell())) {
- if (!strcmp(name, sh))
- return (name);
+ if (!strcmp(name, sh)) {
+ endusershell();
+ return (1);
+ }
+ /* allow just shell name, but use "real" path */
+ if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) {
+ endusershell();
+ return (1);
+ }
+ }
+ endusershell();
+ return (0);
+}
+
+char *
+dup_shell(char *name)
+{
+ char *p, *sh, *ret;
+
+ setusershell();
+ while ((sh = getusershell())) {
+ if (!strcmp(name, sh)) {
+ endusershell();
+ return (strdup(name));
+ }
/* allow just shell name, but use "real" path */
- if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0)
- return (sh);
+ if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) {
+ ret = strdup(sh);
+ endusershell();
+ return (ret);
+ }
}
+ endusershell();
return (NULL);
}
OpenPOWER on IntegriCloud