summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-27 19:02:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-27 19:02:41 +0000
commit9ca3dc4b9ef711cefb42fc40dfcf22d1e18dfd61 (patch)
tree117beef48f90c33e99f0e5d9d726caaa8ca620ac /usr.bin
parentf576c1fdbc81379456dfb7a6c5e5e9b6b5e928a4 (diff)
cleanup; mpech & millert ok
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/chpass/chpass.c25
-rw-r--r--usr.bin/chpass/edit.c21
-rw-r--r--usr.bin/chpass/field.c63
-rw-r--r--usr.bin/chpass/pw_yp.c50
-rw-r--r--usr.bin/chpass/util.c23
5 files changed, 66 insertions, 116 deletions
diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c
index 494a2647002..c8cd928c6e1 100644
--- a/usr.bin/chpass/chpass.c
+++ b/usr.bin/chpass/chpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chpass.c,v 1.22 2002/03/14 06:51:41 mpech Exp $ */
+/* $OpenBSD: chpass.c,v 1.23 2002/06/27 19:02:40 deraadt Exp $ */
/* $NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $ */
/*-
@@ -43,8 +43,8 @@ static char copyright[] =
#ifndef lint
#if 0
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
-#else
-static char rcsid[] = "$OpenBSD: chpass.c,v 1.22 2002/03/14 06:51:41 mpech Exp $";
+#else
+static char rcsid[] = "$OpenBSD: chpass.c,v 1.23 2002/06/27 19:02:40 deraadt Exp $";
#endif
#endif /* not lint */
@@ -88,13 +88,11 @@ void kbintr(int);
void usage(void);
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char *argv[])
{
- struct passwd *pw, lpw;
+ struct passwd *pw = NULL, lpw;
int i, ch, pfd, tfd, dfd;
- char *arg;
+ char *arg = NULL;
sigset_t fullset;
#ifdef YP
@@ -133,7 +131,7 @@ main(argc, argv)
#ifdef YP
if (op == LOADENTRY && use_yp)
- errx(1, "cannot load entry using NIS.\n\tUse the -l flag to load local.");
+ errx(1, "cannot load using YP, use -l to load local.");
#endif
uid = getuid();
@@ -240,22 +238,21 @@ main(argc, argv)
}
void
-baduser()
+baduser(void)
{
errx(1, "%s", strerror(EACCES));
}
void
-tempcleanup()
+tempcleanup(void)
{
unlink(tempname);
}
void
-kbintr(signo)
- int signo;
+kbintr(int signo)
{
struct iovec iv[5];
@@ -278,7 +275,7 @@ kbintr(signo)
}
void
-usage()
+usage(void)
{
#ifdef YP
diff --git a/usr.bin/chpass/edit.c b/usr.bin/chpass/edit.c
index 87b07686803..d62dcd1fb12 100644
--- a/usr.bin/chpass/edit.c
+++ b/usr.bin/chpass/edit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: edit.c,v 1.21 2001/07/12 05:16:57 deraadt Exp $ */
+/* $OpenBSD: edit.c,v 1.22 2002/06/27 19:02:40 deraadt Exp $ */
/* $NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: edit.c,v 1.21 2001/07/12 05:16:57 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: edit.c,v 1.22 2002/06/27 19:02:40 deraadt Exp $";
#endif
#endif /* not lint */
@@ -145,12 +145,12 @@ verify(tempname, pw)
char *tempname;
struct passwd *pw;
{
- ENTRY *ep;
- char *p, *q;
- struct stat sb;
- FILE *fp;
unsigned int len, alen, line;
static char buf[LINE_MAX];
+ struct stat sb;
+ char *p, *q;
+ ENTRY *ep;
+ FILE *fp;
if (!(fp = fopen(tempname, "r")))
pw_error(tempname, 1, 1);
@@ -166,13 +166,13 @@ verify(tempname, pw)
if (!buf[0] || buf[0] == '#')
continue;
if (!(p = strchr(buf, '\n'))) {
- warnx("line %d too long", line);
+ warnx("line %u too long", line);
goto bad;
}
*p = '\0';
for (ep = list;; ++ep) {
if (!ep->prompt) {
- warnx("unrecognized field on line %d", line);
+ warnx("unrecognized field on line %u", line);
goto bad;
}
if (!strncasecmp(buf, ep->prompt, ep->len)) {
@@ -183,7 +183,7 @@ verify(tempname, pw)
goto bad;
}
if (!(p = strchr(buf, ':'))) {
- warnx("line %d corrupted", line);
+ warnx("line %u corrupted", line);
goto bad;
}
while (isspace(*++p));
@@ -224,8 +224,9 @@ bad: (void)fclose(fp);
alen = alen + strlen(pw->pw_name) - 1;
if (!(p = malloc(len)))
err(1, NULL);
- (void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s", list[E_NAME].save,
+ (void)snprintf(p, len, "%s,%s,%s,%s", list[E_NAME].save,
list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save);
+ pw->pw_gecos = p;
if (snprintf(buf, sizeof(buf),
"%s:%s:%u:%u:%s:%ld:%ld:%s:%s:%s",
diff --git a/usr.bin/chpass/field.c b/usr.bin/chpass/field.c
index 1b82a395e48..a6b29c35afa 100644
--- a/usr.bin/chpass/field.c
+++ b/usr.bin/chpass/field.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: field.c,v 1.3 1998/05/29 22:26:46 downsj Exp $ */
+/* $OpenBSD: field.c,v 1.4 2002/06/27 19:02:40 deraadt Exp $ */
/* $NetBSD: field.c,v 1.3 1995/03/26 04:55:28 glass Exp $ */
/*
@@ -37,8 +37,8 @@
#ifndef lint
#if 0
static char sccsid[] = "@(#)field.c 8.4 (Berkeley) 4/2/94";
-#else
-static char rcsid[] = "$OpenBSD: field.c,v 1.3 1998/05/29 22:26:46 downsj Exp $";
+#else
+static char rcsid[] = "$OpenBSD: field.c,v 1.4 2002/06/27 19:02:40 deraadt Exp $";
#endif
#endif /* not lint */
@@ -59,10 +59,7 @@ static char rcsid[] = "$OpenBSD: field.c,v 1.3 1998/05/29 22:26:46 downsj Exp $"
/* ARGSUSED */
int
-p_login(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_login(char *p, struct passwd *pw, ENTRY *ep)
{
if (!*p) {
warnx("empty login field");
@@ -88,10 +85,7 @@ p_login(p, pw, ep)
/* ARGSUSED */
int
-p_passwd(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_passwd(char *p, struct passwd *pw, ENTRY *ep)
{
if (!*p)
pw->pw_passwd = ""; /* "NOLOGIN"; */
@@ -99,16 +93,13 @@ p_passwd(p, pw, ep)
warnx("can't save password entry");
return (1);
}
-
+
return (0);
}
/* ARGSUSED */
int
-p_uid(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_uid(char *p, struct passwd *pw, ENTRY *ep)
{
uid_t id;
char *np;
@@ -133,10 +124,7 @@ p_uid(p, pw, ep)
/* ARGSUSED */
int
-p_gid(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_gid(char *p, struct passwd *pw, ENTRY *ep)
{
struct group *gr;
gid_t id;
@@ -166,10 +154,7 @@ p_gid(p, pw, ep)
/* ARGSUSED */
int
-p_class(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_class(char *p, struct passwd *pw, ENTRY *ep)
{
if (!*p)
pw->pw_class = "";
@@ -177,16 +162,13 @@ p_class(p, pw, ep)
warnx("can't save entry");
return (1);
}
-
+
return (0);
}
/* ARGSUSED */
int
-p_change(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_change(char *p, struct passwd *pw, ENTRY *ep)
{
if (!atot(p, &pw->pw_change))
return (0);
@@ -196,10 +178,7 @@ p_change(p, pw, ep)
/* ARGSUSED */
int
-p_expire(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_expire(char *p, struct passwd *pw, ENTRY *ep)
{
if (!atot(p, &pw->pw_expire))
return (0);
@@ -209,10 +188,7 @@ p_expire(p, pw, ep)
/* ARGSUSED */
int
-p_gecos(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_gecos(char *p, struct passwd *pw, ENTRY *ep)
{
if (!*p)
ep->save = "";
@@ -225,10 +201,7 @@ p_gecos(p, pw, ep)
/* ARGSUSED */
int
-p_hdir(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_hdir(char *p, struct passwd *pw, ENTRY *ep)
{
if (!*p) {
warnx("empty home directory field");
@@ -243,10 +216,7 @@ p_hdir(p, pw, ep)
/* ARGSUSED */
int
-p_shell(p, pw, ep)
- char *p;
- struct passwd *pw;
- ENTRY *ep;
+p_shell(char *p, struct passwd *pw, ENTRY *ep)
{
char *t;
@@ -264,8 +234,7 @@ p_shell(p, pw, ep)
warnx("%s: non-standard shell", p);
return (1);
}
- }
- else
+ } else
p = t;
if (!(pw->pw_shell = strdup(p))) {
warnx("can't save entry");
diff --git a/usr.bin/chpass/pw_yp.c b/usr.bin/chpass/pw_yp.c
index 4c084f1c416..27c4f6a02cf 100644
--- a/usr.bin/chpass/pw_yp.c
+++ b/usr.bin/chpass/pw_yp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pw_yp.c,v 1.15 2002/06/04 00:09:08 deraadt Exp $ */
+/* $OpenBSD: pw_yp.c,v 1.16 2002/06/27 19:02:40 deraadt Exp $ */
/* $NetBSD: pw_yp.c,v 1.5 1995/03/26 04:55:33 glass Exp $ */
/*
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)pw_yp.c 1.0 2/2/93";
#else
-static char rcsid[] = "$OpenBSD: pw_yp.c,v 1.15 2002/06/04 00:09:08 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pw_yp.c,v 1.16 2002/06/27 19:02:40 deraadt Exp $";
#endif
#endif /* not lint */
@@ -50,6 +50,7 @@ static char rcsid[] = "$OpenBSD: pw_yp.c,v 1.15 2002/06/04 00:09:08 deraadt Exp
#include <pwd.h>
#include <err.h>
#include <errno.h>
+#include <unistd.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
@@ -63,19 +64,14 @@ extern char *__progname;
static char *domain;
int
-pw_yp(pw, uid)
- struct passwd *pw;
- uid_t uid;
+pw_yp(struct passwd *pw, uid_t uid)
{
- char *master;
- char *p;
- char buf[10];
+ char buf[10], *master, *p;
int r, rpcport, status, alen;
struct yppasswd yppasswd;
struct timeval tv;
CLIENT *client;
- extern char *getpass();
-
+
/*
* Get local domain
*/
@@ -126,7 +122,7 @@ pw_yp(pw, uid)
(void)fprintf(stderr, "Cancelled.\n");
return(0);
}
-
+
for (alen = 0, p = pw->pw_gecos; *p; p++)
if (*p == '&')
alen = alen + strlen(pw->pw_name) - 1;
@@ -142,7 +138,7 @@ pw_yp(pw, uid)
/* tell rpc.yppasswdd */
yppasswd.newpw.pw_name = pw->pw_name;
yppasswd.newpw.pw_passwd= pw->pw_passwd;
- yppasswd.newpw.pw_uid = pw->pw_uid;
+ yppasswd.newpw.pw_uid = pw->pw_uid;
yppasswd.newpw.pw_gid = pw->pw_gid;
yppasswd.newpw.pw_gecos = pw->pw_gecos;
yppasswd.newpw.pw_dir = pw->pw_dir;
@@ -176,8 +172,7 @@ pw_yp(pw, uid)
}
static char *
-pwskip(p)
- char *p;
+pwskip(char *p)
{
while (*p && *p != ':' && *p != '\n')
++p;
@@ -187,9 +182,7 @@ pwskip(p)
}
static struct passwd *
-interpret(pwent, line)
- struct passwd *pwent;
- char *line;
+interpret(struct passwd *pwent, char *line)
{
char *p = line;
@@ -202,7 +195,7 @@ interpret(pwent, line)
pwent->pw_change = 0;
pwent->pw_expire = 0;
pwent->pw_class = "";
-
+
/* line without colon separators is no good, so ignore it */
if(!strchr(p,':'))
return(NULL);
@@ -229,13 +222,12 @@ interpret(pwent, line)
static char *__yplin;
struct passwd *
-ypgetpwnam(nam)
- char *nam;
+ypgetpwnam(char *nam)
{
static struct passwd pwent;
- char *val;
int reason, vallen;
-
+ char *val;
+
/*
* Get local domain
*/
@@ -259,28 +251,26 @@ ypgetpwnam(nam)
free(__yplin);
if (!(__yplin = (char *)malloc(vallen + 1)))
err(1, NULL);
- strcpy(__yplin, val); /* ok */
+ strlcpy(__yplin, val, vallen + 1);
free(val);
return(interpret(&pwent, __yplin));
}
struct passwd *
-ypgetpwuid(uid)
- uid_t uid;
+ypgetpwuid(uid_t uid)
{
static struct passwd pwent;
- char *val;
int reason, vallen;
- char namebuf[16];
-
+ char namebuf[16], *val;
+
if (!domain && (reason = yp_get_default_domain(&domain))) {
fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",
__progname, yperr_string(reason));
exit(1);
}
- snprintf(namebuf, sizeof namebuf, "%u", uid);
+ snprintf(namebuf, sizeof namebuf, "%u", (u_int)uid);
reason = yp_match(domain, "passwd.byuid", namebuf, strlen(namebuf),
&val, &vallen);
switch(reason) {
@@ -295,7 +285,7 @@ ypgetpwuid(uid)
free(__yplin);
if (!(__yplin = (char *)malloc(vallen + 1)))
err(1, NULL);
- strcpy(__yplin, val); /* ok */
+ strlcpy(__yplin, val, vallen + 1);
free(val);
return(interpret(&pwent, __yplin));
diff --git a/usr.bin/chpass/util.c b/usr.bin/chpass/util.c
index 3470c2c7be1..e501fada390 100644
--- a/usr.bin/chpass/util.c
+++ b/usr.bin/chpass/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.4 1998/03/30 06:59:34 deraadt Exp $ */
+/* $OpenBSD: util.c,v 1.5 2002/06/27 19:02:40 deraadt Exp $ */
/* $NetBSD: util.c,v 1.4 1995/03/26 04:55:35 glass Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)util.c 8.4 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: util.c,v 1.4 1998/03/30 06:59:34 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.5 2002/06/27 19:02:40 deraadt Exp $";
#endif
#endif /* not lint */
@@ -57,31 +57,25 @@ static char rcsid[] = "$OpenBSD: util.c,v 1.4 1998/03/30 06:59:34 deraadt Exp $"
#include "pathnames.h"
char *
-ttoa(buf, len, tval)
- char *buf;
- size_t len;
- time_t tval;
+ttoa(char *buf, size_t len, time_t tval)
{
if (tval) {
struct tm *tp = localtime(&tval);
(void) strftime(buf, len, "%B %d, %Y", tp);
buf[len - 1] = '\0';
- }
- else if (len > 0)
+ } else if (len > 0)
*buf = '\0';
return (buf);
-}
+}
int
-atot(p, store)
- char *p;
- time_t *store;
+atot(char *p, time_t *store)
{
static struct tm *lt;
struct tm tm;
- char *t;
time_t tval;
+ char *t;
if (!*p) {
*store = 0;
@@ -105,8 +99,7 @@ atot(p, store)
}
char *
-ok_shell(name)
- char *name;
+ok_shell(char *name)
{
char *p, *sh;