WARNSify, getopt returns -1 not EOF

This commit is contained in:
lukem 1997-10-17 11:46:30 +00:00
parent 76da6c89a7
commit 4eb7653054
11 changed files with 126 additions and 104 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compare.c,v 1.12 1997/07/11 07:05:29 mikel Exp $ */
/* $NetBSD: compare.c,v 1.13 1997/10/17 11:46:30 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -33,11 +33,12 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: compare.c,v 1.12 1997/07/11 07:05:29 mikel Exp $";
__RCSID("$NetBSD: compare.c,v 1.13 1997/10/17 11:46:30 lukem Exp $");
#endif
#endif /* not lint */
@ -72,13 +73,14 @@ static char *ftype __P((u_int));
int
compare(name, s, p)
char *name;
register NODE *s;
register FTSENT *p;
NODE *s;
FTSENT *p;
{
u_long len, val;
int fd, label;
char *cp, *tab;
tab = NULL;
label = 0;
switch(s->type) {
case F_BLOCK:
@ -285,7 +287,7 @@ rlink(name)
char *name;
{
static char lbuf[MAXPATHLEN];
register int len;
int len;
if ((len = readlink(name, lbuf, sizeof(lbuf))) == -1)
err("%s: %s", name, strerror(errno));

View File

@ -1,4 +1,4 @@
/* $NetBSD: create.c,v 1.12 1997/07/11 07:05:30 mikel Exp $ */
/* $NetBSD: create.c,v 1.13 1997/10/17 11:46:35 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -33,25 +33,27 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: create.c,v 1.12 1997/07/11 07:05:30 mikel Exp $";
__RCSID("$NetBSD: create.c,v 1.13 1997/10/17 11:46:35 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <time.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
#include <dirent.h>
#include <grp.h>
#include <pwd.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "mtree.h"
#include "extern.h"
@ -75,8 +77,8 @@ static void statf __P((FTSENT *));
void
cwalk()
{
register FTS *t;
register FTSENT *p;
FTS *t;
FTSENT *p;
time_t clock;
char *argv[2], host[MAXHOSTNAMELEN];
@ -185,10 +187,10 @@ statd(t, parent, puid, pgid, pmode)
gid_t *pgid;
mode_t *pmode;
{
register FTSENT *p;
register gid_t sgid;
register uid_t suid;
register mode_t smode;
FTSENT *p;
gid_t sgid;
uid_t suid;
mode_t smode;
struct group *gr;
struct passwd *pw;
gid_t savegid;
@ -196,15 +198,18 @@ statd(t, parent, puid, pgid, pmode)
mode_t savemode;
u_short maxgid, maxuid, maxmode, g[MAXGID], u[MAXUID], m[MAXMODE];
savegid = 0;
saveuid = 0;
savemode = 0;
if ((p = fts_children(t, 0)) == NULL) {
if (errno)
err("%s: %s", RP(parent), strerror(errno));
return (1);
}
bzero(g, sizeof(g));
bzero(u, sizeof(u));
bzero(m, sizeof(m));
memset(g, 0, sizeof(g));
memset(u, 0, sizeof(u));
memset(m, 0, sizeof(m));
maxuid = maxgid = maxmode = 0;
for (; p; p = p->fts_link) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: misc.c,v 1.4 1995/03/07 21:26:23 cgd Exp $ */
/* $NetBSD: misc.c,v 1.5 1997/10/17 11:46:40 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -35,6 +35,11 @@
* @(#)misc.c 8.1 (Berkeley) 6/6/93
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: misc.c,v 1.5 1997/10/17 11:46:40 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <fts.h>
@ -54,28 +59,29 @@ typedef struct _key {
/* NB: the following table must be sorted lexically. */
static KEY keylist[] = {
"cksum", F_CKSUM, NEEDVALUE,
"gid", F_GID, NEEDVALUE,
"gname", F_GNAME, NEEDVALUE,
"ignore", F_IGN, 0,
"link", F_SLINK, NEEDVALUE,
"mode", F_MODE, NEEDVALUE,
"nlink", F_NLINK, NEEDVALUE,
"optional", F_OPT, 0,
"size", F_SIZE, NEEDVALUE,
"time", F_TIME, NEEDVALUE,
"type", F_TYPE, NEEDVALUE,
"uid", F_UID, NEEDVALUE,
"uname", F_UNAME, NEEDVALUE,
{"cksum", F_CKSUM, NEEDVALUE},
{"gid", F_GID, NEEDVALUE},
{"gname", F_GNAME, NEEDVALUE},
{"ignore", F_IGN, 0},
{"link", F_SLINK, NEEDVALUE},
{"mode", F_MODE, NEEDVALUE},
{"nlink", F_NLINK, NEEDVALUE},
{"optional", F_OPT, 0},
{"size", F_SIZE, NEEDVALUE},
{"time", F_TIME, NEEDVALUE},
{"type", F_TYPE, NEEDVALUE},
{"uid", F_UID, NEEDVALUE},
{"uname", F_UNAME, NEEDVALUE}
};
int keycompare __P((const void *, const void *));
u_int
parsekey(name, needvaluep)
char *name;
int *needvaluep;
{
KEY *k, tmp;
int keycompare __P((const void *, const void *));
tmp.name = name;
k = (KEY *)bsearch(&tmp, keylist, sizeof(keylist) / sizeof(KEY),

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mtree.8,v 1.6 1997/08/20 15:14:51 agc Exp $
.\" $NetBSD: mtree.8,v 1.7 1997/10/17 11:46:46 lukem Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -40,7 +40,7 @@
.Nm mtree
.Nd map a directory hierarchy
.Sh SYNOPSIS
.Nm mtree
.Nm
.Op Fl cderux
.Op Fl f Ar spec
.Op Fl K Ar keywords
@ -49,7 +49,7 @@
.Op Fl s Ar seed
.Sh DESCRIPTION
The utility
.Nm mtree
.Nm
compares the file hierarchy rooted in the current directory against a
specification read from the standard input.
Messages are written to the standard output for any files whose
@ -213,13 +213,13 @@ Empty lines and lines whose first non-whitespace character is a hash
mark (``#'') are ignored.
.Pp
The
.Nm mtree
.Nm
utility exits with a status of 0 on success, 1 if any error occurred,
and 2 if the file hierarchy did not match the specification.
.Sh EXAMPLES
To detect system binaries that have been ``trojan horsed'', it is recommended
that
.Nm mtree
.Nm
be run on the file systems, and a copy of the results stored on a different
machine, or, at least, in encrypted form.
The seed for the
@ -227,7 +227,7 @@ The seed for the
option should not be an obvious value and the final checksum should not be
stored on-line under any circumstances!
Then, periodically,
.Nm mtree
.Nm
should be run against the on-line specifications and the final checksum
compared with the previous value.
While it is possible for the bad guys to change the on-line specifications
@ -256,6 +256,6 @@ system specification directory
.Xr chown 8
.Sh HISTORY
The
.Nm mtree
.Nm
utility appeared in
.Bx 4.3 Reno .

View File

@ -1,4 +1,4 @@
/* $NetBSD: mtree.c,v 1.8 1997/08/20 15:14:52 agc Exp $ */
/* $NetBSD: mtree.c,v 1.9 1997/10/17 11:46:51 lukem Exp $ */
/*-
* Copyright (c) 1989, 1990, 1993
@ -33,17 +33,17 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1989, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
__COPYRIGHT("@(#) Copyright (c) 1989, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: mtree.c,v 1.8 1997/08/20 15:14:52 agc Exp $";
__RCSID("$NetBSD: mtree.c,v 1.9 1997/10/17 11:46:51 lukem Exp $");
#endif
#endif /* not lint */
@ -63,22 +63,21 @@ int cflag, dflag, eflag, rflag, sflag, tflag, uflag, Uflag;
u_short keys;
char fullpath[MAXPATHLEN];
static void usage __P((void));
int main __P((int, char **));
static void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
{
extern int optind;
extern char *optarg;
int ch;
char *dir, *p;
int status;
dir = NULL;
keys = KEYDEFAULT;
while ((ch = getopt(argc, argv, "cdef:K:k:p:rs:tUux")) != EOF)
while ((ch = getopt(argc, argv, "cdef:K:k:p:rs:tUux")) != -1)
switch((char)ch) {
case 'c':
cflag = 1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: spec.c,v 1.10 1997/10/17 05:24:32 mrg Exp $ */
/* $NetBSD: spec.c,v 1.11 1997/10/17 11:46:55 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -33,23 +33,26 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95";
#else
static char rcsid[] = "$NetBSD: spec.c,v 1.10 1997/10/17 05:24:32 mrg Exp $";
__RCSID("$NetBSD: spec.c,v 1.11 1997/10/17 11:46:55 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <fts.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <fts.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mtree.h"
#include "extern.h"
@ -61,14 +64,15 @@ static void unset __P((char *, NODE *));
NODE *
spec()
{
register NODE *centry, *last;
register char *p;
NODE *centry, *last;
char *p;
NODE ginfo, *root;
int c_cur, c_next;
char buf[2048];
root = NULL;
bzero(&ginfo, sizeof(ginfo));
centry = last = NULL;
memset(&ginfo, 0, sizeof(ginfo));
c_cur = c_next = 0;
for (lineno = 1; fgets(buf, sizeof(buf), stdin);
++lineno, c_cur = c_next, c_next = 0) {
@ -77,7 +81,7 @@ spec()
continue;
/* Find end of line. */
if ((p = index(buf, '\n')) == NULL)
if ((p = strchr(buf, '\n')) == NULL)
err("line %d too long", lineno);
/* See if next line is continuation line. */
@ -122,7 +126,7 @@ spec()
continue;
}
if (index(p, '/'))
if (strchr(p, '/'))
err("slash character in file name");
if (!strcmp(p, "..")) {
@ -167,16 +171,17 @@ noparent: err("no parent node");
static void
set(t, ip)
char *t;
register NODE *ip;
NODE *ip;
{
register int type;
register char *kw, *val;
int type;
char *kw, *val;
struct group *gr;
struct passwd *pw;
mode_t *m;
int value;
char *ep;
val = NULL;
for (; (kw = strtok(t, "= \t\n")) != NULL; t = NULL) {
ip->flags |= type = parsekey(kw, &value);
if (value && (val = strtok(NULL, " \t\n")) == NULL)
@ -278,9 +283,9 @@ set(t, ip)
static void
unset(t, ip)
char *t;
register NODE *ip;
NODE *ip;
{
register char *p;
char *p;
while ((p = strtok(t, "\n\t ")) != NULL)
ip->flags &= ~parsekey(p, NULL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: verify.c,v 1.12 1997/07/11 07:05:31 mikel Exp $ */
/* $NetBSD: verify.c,v 1.13 1997/10/17 11:46:58 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -33,11 +33,12 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: verify.c,v 1.12 1997/07/11 07:05:31 mikel Exp $";
__RCSID("$NetBSD: verify.c,v 1.13 1997/10/17 11:46:58 lukem Exp $");
#endif
#endif /* not lint */
@ -76,9 +77,9 @@ verify()
static int
vwalk()
{
register FTS *t;
register FTSENT *p;
register NODE *ep, *level;
FTS *t;
FTSENT *p;
NODE *ep, *level;
int ftsdepth, specdepth, rval;
char *argv[2];
@ -153,11 +154,11 @@ vwalk()
static void
miss(p, tail)
register NODE *p;
register char *tail;
NODE *p;
char *tail;
{
register int create;
register char *tp;
int create;
char *tp;
for (; p; p = p->next) {
if (p->flags & F_OPT && !(p->flags & F_VISIT))

View File

@ -1,4 +1,4 @@
.\" $NetBSD: netgroup_mkdb.8,v 1.3 1996/10/04 05:15:28 christos Exp $
.\" $NetBSD: netgroup_mkdb.8,v 1.4 1997/10/17 11:49:00 lukem Exp $
.\"
.\" Copyright (c) 1994 Christos Zoulas
.\" All rights reserved.
@ -35,11 +35,11 @@
.Nm netgroup_mkdb
.Nd generate the netgroup databases
.Sh SYNOPSIS
.Nm netgroup_mkdb
.Nm
.Op Fl o Ar database
.Op file
.Sh DESCRIPTION
.Nm Netgroup_mkdb
.Nm
creates
.Xr db 3
style databases for the specified file. If no file is specified, then
@ -59,7 +59,7 @@ Put the output databases in the named file.
The databases are used by the C library netgroup routines (see
.Xr getnetgrent 3 ).
.Pp
.Nm Netgroup_mkdb
.Nm
exits zero on success, non-zero on failure.
.Sh FILES
.Bl -tag -width 24n -compact
@ -72,14 +72,14 @@ The current netgroup file
.El
.Sh BUGS
Because
.Nm netgroup_mkdb
.Nm
guarantees not to install a partial destination file it must
build a temporary file in the same file system and if successful use
.Xr rename 2
to install over the destination file.
.Pp
If
.Nm netgroup_mkdb
.Nm
fails it will leave the previous version of the destination file intact.
.Sh SEE ALSO
.Xr db 3 ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: netgroup_mkdb.c,v 1.7 1997/06/16 23:18:50 christos Exp $ */
/* $NetBSD: netgroup_mkdb.c,v 1.8 1997/10/17 11:49:05 lukem Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@ -30,8 +30,9 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char *rcsid = "$NetBSD: netgroup_mkdb.c,v 1.7 1997/06/16 23:18:50 christos Exp $";
__RCSID("$NetBSD: netgroup_mkdb.c,v 1.8 1997/10/17 11:49:05 lukem Exp $");
#endif
#include <sys/types.h>
@ -71,23 +72,24 @@ struct nentry {
};
static DB *ng_insert __P((DB *, const char *));
static void ng_reventry __P((DB *, DB *, struct nentry *, char *,
static void cleanup __P((void));
int main __P((int, char **));
static DB *ng_insert __P((DB *, const char *));
static void ng_reventry __P((DB *, DB *, struct nentry *, char *,
size_t, StringList *));
static void ng_print __P((struct nentry *, struct string *));
static void ng_rprint __P((DB *, struct string *));
static DB *ng_reverse __P((DB *, size_t));
static DB *ng_load __P((const char *));
static void ng_write __P((DB *, DB *, int));
static void ng_rwrite __P((DB *, DB *, int));
static void usage __P((void));
static void cleanup __P((void));
static void ng_print __P((struct nentry *, struct string *));
static void ng_rprint __P((DB *, struct string *));
static DB *ng_reverse __P((DB *, size_t));
static DB *ng_load __P((const char *));
static void ng_write __P((DB *, DB *, int));
static void ng_rwrite __P((DB *, DB *, int));
static void usage __P((void));
#ifdef DEBUG_NG
static int debug = 0;
static void ng_dump __P((DB *));
static void ng_rdump __P((DB *));
static int debug = 0;
static void ng_dump __P((DB *));
static void ng_rdump __P((DB *));
#endif /* DEBUG_NG */
@ -107,7 +109,7 @@ main(argc, argv)
char *fname = _PATH_NETGROUP;
while ((ch = getopt(argc, argv, "do:")) != EOF)
while ((ch = getopt(argc, argv, "do:")) != -1)
switch (ch) {
#ifdef DEBUG_NG
case 'd':

View File

@ -1,4 +1,4 @@
/* $NetBSD: str.c,v 1.3 1996/10/04 05:15:30 christos Exp $ */
/* $NetBSD: str.c,v 1.4 1997/10/17 11:49:10 lukem Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@ -31,8 +31,9 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char *rcsid = "$NetBSD: str.c,v 1.3 1996/10/04 05:15:30 christos Exp $";
__RCSID("$NetBSD: str.c,v 1.4 1997/10/17 11:49:10 lukem Exp $");
#endif
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.3 1996/10/04 05:15:31 christos Exp $ */
/* $NetBSD: util.c,v 1.4 1997/10/17 11:49:17 lukem Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@ -31,8 +31,9 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char *rcsid = "$NetBSD: util.c,v 1.3 1996/10/04 05:15:31 christos Exp $";
__RCSID("$NetBSD: util.c,v 1.4 1997/10/17 11:49:17 lukem Exp $");
#endif
#include <err.h>