-# $OpenBSD: Makefile,v 1.2 1996/12/08 01:13:38 niklas Exp $
+# $OpenBSD: Makefile,v 1.3 1996/12/10 08:25:57 deraadt Exp $
# $NetBSD: Makefile,v 1.8 1995/03/07 21:12:04 cgd Exp $
PROG= mtree
#CFLAGS+=-DDEBUG
+CFLAGS+=-Wall
MAN= mtree.8
SRCS= compare.c crc.c create.c misc.c mtree.c spec.c verify.c
.PATH: ${.CURDIR}/../../usr.bin/cksum
/* $NetBSD: compare.c,v 1.9 1995/10/22 20:12:07 pk Exp $ */
-/* $OpenBSD: compare.c,v 1.4 1996/12/08 01:13:38 niklas Exp $ */
+/* $OpenBSD: compare.c,v 1.5 1996/12/10 08:25:57 deraadt Exp $ */
/*-
* Copyright (c) 1989, 1993
#include <stdio.h>
#include <time.h>
#include <unistd.h>
+#include <md5.h>
#include "mtree.h"
#include "extern.h"
(void)printf("\n"); \
} else { \
tab = ""; \
- (void)printf("%*s", INDENTNAMELEN - len, ""); \
+ (void)printf("%*s", INDENTNAMELEN - (int)len, ""); \
} \
}
extern int uflag;
u_int32_t len, val;
int fd, label;
- char *cp, *tab;
+ char *cp, *tab = "";
label = 0;
switch(s->type) {
* XXX
* Catches nano-second differences, but doesn't display them.
*/
- if (s->flags & F_TIME &&
- (s->st_mtimespec.tv_sec != p->fts_statp->st_mtimespec.tv_sec ||
- s->st_mtimespec.tv_nsec != p->fts_statp->st_mtimespec.tv_nsec)) {
+ if ((s->flags & F_TIME) &&
+ ((s->st_mtimespec.tv_sec != p->fts_statp->st_mtimespec.tv_sec) ||
+ (s->st_mtimespec.tv_nsec != p->fts_statp->st_mtimespec.tv_nsec))) {
LABEL;
(void)printf("%smodification time (%.24s, ",
tab, ctime(&s->st_mtimespec.tv_sec));
(void)close(fd);
if (s->cksum != val) {
LABEL;
- (void)printf("%scksum (%u, %u)\n",
+ (void)printf("%scksum (%u, %u)\n",
tab, s->cksum, val);
}
tab = "\t";
}
+ if (s->flags & F_MD5) {
+ char *new_digest, buf[33];
+
+ new_digest = MD5File(p->fts_accpath,buf);
+ if (!new_digest) {
+ LABEL;
+ printf("%sMD5File: %s: %s\n", tab, p->fts_accpath,
+ strerror(errno));
+ tab = "\t";
+ } else if (strcmp(new_digest, s->md5digest)) {
+ LABEL;
+ printf("%sMD5 (%s, %s)\n", tab, s->md5digest,
+ new_digest);
+ tab = "\t";
+ }
+ }
+
if (s->flags & F_SLINK && strcmp(cp = rlink(name), s->slink)) {
LABEL;
(void)printf("%slink ref (%s, %s)\n", tab, cp, s->slink);
/* $NetBSD: create.c,v 1.9 1995/03/07 21:12:06 cgd Exp $ */
-/* $OpenBSD: create.c,v 1.3 1996/12/08 01:13:39 niklas Exp $ */
+/* $OpenBSD: create.c,v 1.4 1996/12/10 08:25:58 deraadt Exp $ */
/*-
* Copyright (c) 1989, 1993
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
+#include <md5.h>
#include "mtree.h"
#include "extern.h"
extern u_int32_t crc_total;
extern int ftsoptions;
-extern int dflag, sflag;
+extern int dflag, iflag, nflag, sflag;
extern u_short keys;
extern char fullpath[MAXPATHLEN];
static mode_t mode;
static int dsort __P((const FTSENT **, const FTSENT **));
-static void output __P((int *, const char *, ...));
+static void output __P((int, int *, const char *, ...));
static int statd __P((FTS *, FTSENT *, uid_t *, gid_t *, mode_t *));
-static void statf __P((FTSENT *));
+static void statf __P((int, FTSENT *));
void
cwalk()
register FTSENT *p;
time_t clock;
char *argv[2], host[MAXHOSTNAMELEN];
+ int indent = 0;
(void)time(&clock);
(void)gethostname(host, sizeof(host));
argv[1] = NULL;
if ((t = fts_open(argv, ftsoptions, dsort)) == NULL)
err("fts_open: %s", strerror(errno));
- while (p = fts_read(t))
+ while ((p = fts_read(t))) {
+ if (iflag)
+ indent = p->fts_level * 4;
switch(p->fts_info) {
case FTS_D:
- (void)printf("\n# %s\n", p->fts_path);
+ if (!dflag)
+ (void)printf("\n");
+ if (!nflag)
+ (void)printf("# %s\n", p->fts_path);
statd(t, p, &uid, &gid, &mode);
- statf(p);
+ statf(indent, p);
break;
case FTS_DP:
- if (p->fts_level > 0)
- (void)printf("# %s\n..\n\n", p->fts_path);
+ if (!nflag && (p->fts_level > 0))
+ (void)printf("%*s# %s\n", indent, "", p->fts_path);
+ (void)printf("%*s..\n", indent, "");
+ if (!dflag)
+ (void)printf("\n");
break;
case FTS_DNR:
case FTS_ERR:
case FTS_NS:
- (void)fprintf(stderr,
- "mtree: %s: %s\n", p->fts_path, strerror(errno));
+ (void)fprintf(stderr, "mtree: %s: %s\n",
+ p->fts_path, strerror(p->fts_errno));
break;
default:
if (!dflag)
- statf(p);
+ statf(indent, p);
break;
}
+ }
(void)fts_close(t);
if (sflag && keys & F_CKSUM)
(void)fprintf(stderr,
}
static void
-statf(p)
+statf(indent, p)
+ int indent;
FTSENT *p;
{
struct group *gr;
struct passwd *pw;
u_int32_t len, val;
- int fd, indent;
+ int fd, offset;
- if (S_ISDIR(p->fts_statp->st_mode))
- indent = printf("%s", p->fts_name);
+ if (iflag || S_ISDIR(p->fts_statp->st_mode))
+ offset = printf("%*s%s", indent, "", p->fts_name);
else
- indent = printf(" %s", p->fts_name);
+ offset = printf("%*s %s", indent, "", p->fts_name);
- if (indent > INDENTNAMELEN)
- indent = MAXLINELEN;
+ if (offset > (INDENTNAMELEN + indent))
+ offset = MAXLINELEN;
else
- indent += printf("%*s", INDENTNAMELEN - indent, "");
+ offset += printf("%*s", (INDENTNAMELEN + indent) - offset, "");
- if (!S_ISREG(p->fts_statp->st_mode))
- output(&indent, "type=%s", inotype(p->fts_statp->st_mode));
- if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid)
- if (keys & F_UNAME && (pw = getpwuid(p->fts_statp->st_uid)))
- output(&indent, "uname=%s", pw->pw_name);
- else /* if (keys & F_UID) */
- output(&indent, "uid=%u", p->fts_statp->st_uid);
- if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid)
- if (keys & F_GNAME && (gr = getgrgid(p->fts_statp->st_gid)))
- output(&indent, "gname=%s", gr->gr_name);
- else /* if (keys & F_GID) */
- output(&indent, "gid=%u", p->fts_statp->st_gid);
+ if (!S_ISREG(p->fts_statp->st_mode) && !dflag)
+ output(indent, &offset, "type=%s", inotype(p->fts_statp->st_mode));
+ if (p->fts_statp->st_uid != uid) {
+ if (keys & F_UNAME) {
+ if ((pw = getpwuid(p->fts_statp->st_uid)) != NULL) {
+ output(indent, &offset, "uname=%s", pw->pw_name);
+ } else {
+ err("could not get uname for uid=%u",
+ p->fts_statp->st_uid);
+ }
+ }
+ if (keys & F_UID)
+ output(indent, &offset, "uid=%u", p->fts_statp->st_uid);
+ }
+ if (p->fts_statp->st_gid != gid) {
+ if (keys & F_GNAME) {
+ if ((gr = getgrgid(p->fts_statp->st_gid)) != NULL) {
+ output(indent, &offset, "gname=%s", gr->gr_name);
+ } else {
+ err("could not get gname for gid=%u",
+ p->fts_statp->st_gid);
+ }
+ }
+ if (keys & F_GID)
+ output(indent, &offset, "gid=%u", p->fts_statp->st_gid);
+ }
if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode)
- output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS);
+ output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS);
if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
- output(&indent, "nlink=%u", p->fts_statp->st_nlink);
+ output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink);
if (keys & F_SIZE)
- output(&indent, "size=%qd", p->fts_statp->st_size);
+ output(indent, &offset, "size=%qd", p->fts_statp->st_size);
if (keys & F_TIME)
- output(&indent, "time=%ld.%ld",
+ output(indent, &offset, "time=%ld.%ld",
p->fts_statp->st_mtimespec.tv_sec,
p->fts_statp->st_mtimespec.tv_nsec);
if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
crc(fd, &val, &len))
err("%s: %s", p->fts_accpath, strerror(errno));
(void)close(fd);
- output(&indent, "cksum=%u", val);
+ output(indent, &offset, "cksum=%lu", val);
+ }
+ if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) {
+ char *md5digest, buf[33];
+
+ md5digest = MD5File(p->fts_accpath,buf);
+ if (!md5digest) {
+ err("%s: %s", p->fts_accpath, strerror(errno));
+ } else {
+ output(indent, &offset, "md5digest=%s", md5digest);
+ }
}
if (keys & F_SLINK &&
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
- output(&indent, "link=%s", rlink(p->fts_accpath));
+ output(indent, &offset, "link=%s", rlink(p->fts_accpath));
(void)putchar('\n');
}
register mode_t smode;
struct group *gr;
struct passwd *pw;
- gid_t savegid;
- uid_t saveuid;
- mode_t savemode;
+ gid_t savegid = *pgid;
+ uid_t saveuid = *puid;
+ mode_t savemode = *pmode;
u_short maxgid, maxuid, maxmode, g[MAXGID], u[MAXUID], m[MAXMODE];
+ static int first = 1;
if ((p = fts_children(t, 0)) == NULL) {
if (errno)
maxuid = maxgid = maxmode = 0;
for (; p; p = p->fts_link) {
- smode = p->fts_statp->st_mode & MBITS;
- if (smode < MAXMODE && ++m[smode] > maxmode) {
- savemode = smode;
- maxmode = m[smode];
- }
- sgid = p->fts_statp->st_gid;
- if (sgid < MAXGID && ++g[sgid] > maxgid) {
- savegid = sgid;
- maxgid = g[sgid];
- }
- suid = p->fts_statp->st_uid;
- if (suid < MAXUID && ++u[suid] > maxuid) {
- saveuid = suid;
- maxuid = u[suid];
+ if (!dflag || (dflag && S_ISDIR(p->fts_statp->st_mode))) {
+ smode = p->fts_statp->st_mode & MBITS;
+ if (smode < MAXMODE && ++m[smode] > maxmode) {
+ savemode = smode;
+ maxmode = m[smode];
+ }
+ sgid = p->fts_statp->st_gid;
+ if (sgid < MAXGID && ++g[sgid] > maxgid) {
+ savegid = sgid;
+ maxgid = g[sgid];
+ }
+ suid = p->fts_statp->st_uid;
+ if (suid < MAXUID && ++u[suid] > maxuid) {
+ saveuid = suid;
+ maxuid = u[suid];
+ }
}
}
- (void)printf("/set type=file");
- if (keys & F_GID)
- (void)printf(" gid=%u", savegid);
- if (keys & F_GNAME)
- if ((gr = getgrgid(savegid)) != NULL)
- (void)printf(" gname=%s", gr->gr_name);
- else
- (void)printf(" gid=%u", savegid);
- if (keys & F_UNAME)
- if ((pw = getpwuid(saveuid)) != NULL)
- (void)printf(" uname=%s", pw->pw_name);
+ /*
+ * If the /set record is the same as the last one we do not need to output
+ * a new one. So first we check to see if anything changed. Note that we
+ * always output a /set record for the first directory.
+ */
+ if ((((keys & F_UNAME) | (keys & F_UID)) && (*puid != saveuid)) ||
+ (((keys & F_GNAME) | (keys & F_GID)) && (*pgid != savegid)) ||
+ ((keys & F_MODE) && (*pmode != savemode)) || (first)) {
+ first = 0;
+ if (dflag)
+ (void)printf("/set type=dir");
else
+ (void)printf("/set type=file");
+ if (keys & F_UNAME)
+ if ((pw = getpwuid(saveuid)) != NULL)
+ (void)printf(" uname=%s", pw->pw_name);
+ else
+ err("could not get uname for uid=%u", saveuid);
+ if (keys & F_UID)
(void)printf(" uid=%u", saveuid);
- if (keys & F_UID)
- (void)printf(" uid=%u", saveuid);
- if (keys & F_MODE)
- (void)printf(" mode=%#o", savemode);
- if (keys & F_NLINK)
- (void)printf(" nlink=1");
- (void)printf("\n");
- *puid = saveuid;
- *pgid = savegid;
- *pmode = savemode;
+ if (keys & F_GNAME)
+ if ((gr = getgrgid(savegid)) != NULL)
+ (void)printf(" gname=%s", gr->gr_name);
+ else
+ err("could not get gname for gid=%u", savegid);
+ if (keys & F_GID)
+ (void)printf(" gid=%u", savegid);
+ if (keys & F_MODE)
+ (void)printf(" mode=%#o", savemode);
+ if (keys & F_NLINK)
+ (void)printf(" nlink=1");
+ (void)printf("\n");
+ *puid = saveuid;
+ *pgid = savegid;
+ *pmode = savemode;
+ }
return (0);
}
void
#if __STDC__
-output(int *offset, const char *fmt, ...)
+output(int indent, int *offset, const char *fmt, ...)
#else
-output(offset, fmt, va_alist)
+output(indent, offset, fmt, va_alist)
+ int indent;
int *offset;
char *fmt;
va_dcl
va_end(ap);
if (*offset + strlen(buf) > MAXLINELEN - 3) {
- (void)printf(" \\\n%*s", INDENTNAMELEN, "");
- *offset = INDENTNAMELEN;
+ (void)printf(" \\\n%*s", INDENTNAMELEN + indent, "");
+ *offset = INDENTNAMELEN + indent;
}
*offset += printf(" %s", buf) + 1;
}
-/* $OpenBSD: misc.c,v 1.2 1996/12/08 01:13:40 niklas Exp $ */
+/* $OpenBSD: misc.c,v 1.3 1996/12/10 08:26:08 deraadt Exp $ */
/* $NetBSD: misc.c,v 1.4 1995/03/07 21:26:23 cgd Exp $ */
/*-
/* 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},
+ {"md5digest", F_MD5, NEEDVALUE},
+ {"mode", F_MODE, NEEDVALUE},
+ {"nlink", F_NLINK, NEEDVALUE},
+ {"size", F_SIZE, NEEDVALUE},
+ {"time", F_TIME, NEEDVALUE},
+ {"type", F_TYPE, NEEDVALUE},
+ {"uid", F_UID, NEEDVALUE},
+ {"uname", F_UNAME, NEEDVALUE},
};
u_int
#else
va_start(ap);
#endif
- (void)fprintf(stderr, "mtree: ");
+ (void)fflush(NULL);
+ (void)fprintf(stderr, "\nmtree: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
-.\" $OpenBSD: mtree.8,v 1.2 1996/12/08 01:13:41 niklas Exp $
+.\" $OpenBSD: mtree.8,v 1.3 1996/12/10 08:26:08 deraadt Exp $
.\" $NetBSD: mtree.8,v 1.4 1995/03/07 21:26:25 cgd Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.Nd map a directory hierarchy
.Sh SYNOPSIS
.Nm mtree
-.Op Fl cderux
+.Op Fl cdeinrUux
.Op Fl f Ar spec
.Op Fl K Ar keywords
.Op Fl k Ar keywords
Read the specification from
.Ar file ,
instead of from the standard input.
+.It Fl i
+Indents the output 4 spaces each time a directory level is descended when
+create a specification with the
+.Fl c
+option.
+This does not effect either the /set statements or the comment before each
+directory.
+It does however effect the comment before the close of each directory.
.It Fl K
Add the specified (whitespace or comma separated) keywords to the current
set of keywords.
.It Fl k
Use the ``type'' keyword plus the specified (whitespace or comma separated)
keywords instead of the current set of keywords.
+.It Fl n
+Do not emit pathname comments when creating a specification. Normally
+a comment is emitted before each directory and before the close of that
+directory when using the
+.Fl c
+option.
.It Fl p
Use the file hierarchy rooted in
.Ar path ,
.Cm cksum
was specified.
The checksum is seeded with the specified value.
-.It Fl u
+.It Fl U
Modify the owner, group, and permissions of existing files to match
the specification and create any missing directories.
User, group, and permissions must all be specified for missing directories
to be created.
+Exit with a status of 0 on success, 1 if any error occurred,
+a mismatch is not considered an error if it was corrected.
+.It Fl u
+Same as
+.Fl U
+except a status of 2 is returned if the file hierarchy did not match
+the specification.
.It Fl x
Don't descend below mount points in the file hierarchy.
.El
The file group as a numeric value.
.It Cm gname
The file group as a symbolic name.
-.It Cm link
-The file the symbolic link is expected to reference.
+.It Cm md5digest
+The MD5 message digest of the file.
.It Cm mode
The current file's permissions as a numeric (octal) or symbolic
value.
.It Cm nlink
The number of hard links the file is expected to have.
-.It Cm optional
-The file is optional; don't complain about the file if it's
-not in the file hierarchy.
.It Cm uid
The file owner as a numeric value.
.It Cm uname
The file owner as a symbolic name.
.It Cm size
The size, in bytes, of the file.
+.It Cm link
+The file the symbolic link is expected to reference.
.It Cm time
The last modification time of the file.
.It Cm type
.Pp
The default set of keywords are
.Cm gid ,
-.Cm link ,
.Cm mode ,
.Cm nlink ,
.Cm size ,
+.Cm link ,
.Cm time ,
and
.Cm uid .
.Nm mtree
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.
+A status of 2 is converted to a status of 0 if the
+.Fl U
+option is used.
.Sh EXAMPLES
To detect system binaries that have been ``trojan horsed'', it is recommended
that
.Nm mtree
+.Fl K
+.Cm md5digest
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
-.Fl s
-option should not be an obvious value and the final checksum should not be
-stored on-line under any circumstances!
+The output file itself should be digested using the
+.Xr md5 1
+utility.
Then, periodically,
.Nm mtree
-should be run against the on-line specifications and the final checksum
-compared with the previous value.
+and
+.Xr md5 1
+should be run against the on-line specifications.
While it is possible for the bad guys to change the on-line specifications
-to conform to their modified binaries, it shouldn't be possible for them
-to make it produce the same final checksum value.
-If the final checksum value changes, the off-line copies of the specification
-can be used to detect which of the binaries have actually been modified.
+to conform to their modified binaries, it is believed to be
+impractical for them to create a modified specification which has
+the same MD5 digest as the original.
.Pp
The
.Fl d
and
.Fl u
options can be used in combination to create directory hierarchies
-for distributions and other such things.
+for distributions and other such things; the files in
+.Pa /etc/mtree
+were used to create almost all directories in a normal binary
+distribution.
.Sh FILES
.Bl -tag -width /etc/mtree -compact
.It Pa /etc/mtree
.El
.Sh SEE ALSO
.Xr chmod 1 ,
-.Xr chown 1 ,
.Xr chgrp 1 ,
.Xr cksum 1 ,
+.Xr md5 1 ,
.Xr stat 2 ,
.Xr fts 3 ,
+.Xr md5 3 ,
+.Xr chown 8
.Sh HISTORY
The
.Nm mtree
utility appeared in
.Bx 4.3 Reno .
+The MD5 digest capability was added in FreeBSD.
-/* $OpenBSD: mtree.c,v 1.2 1996/12/08 01:13:41 niklas Exp $ */
+/* $OpenBSD: mtree.c,v 1.3 1996/12/10 08:26:09 deraadt Exp $ */
/* $NetBSD: mtree.c,v 1.5 1995/03/07 21:12:10 cgd Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: mtree.c,v 1.2 1996/12/08 01:13:41 niklas Exp $";
+static char rcsid[] = "$OpenBSD: mtree.c,v 1.3 1996/12/10 08:26:09 deraadt Exp $";
#endif
#endif /* not lint */
extern u_int32_t crc_total;
int ftsoptions = FTS_PHYSICAL;
-int cflag, dflag, eflag, rflag, sflag, uflag;
+int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag;
u_short keys;
char fullpath[MAXPATHLEN];
extern char *optarg;
int ch;
char *dir, *p;
+ int status;
dir = NULL;
keys = KEYDEFAULT;
- while ((ch = getopt(argc, argv, "cdef:K:k:p:rs:ux")) != EOF)
+ while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != EOF)
switch((char)ch) {
case 'c':
cflag = 1;
if (!(freopen(optarg, "r", stdin)))
err("%s: %s", optarg, strerror(errno));
break;
+ case 'i':
+ iflag = 1;
+ break;
case 'K':
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
if (*p != '\0')
keys |= parsekey(p, NULL);
break;
+ case 'n':
+ nflag = 1;
+ break;
case 'p':
dir = optarg;
break;
crc_total = ~strtol(optarg, &p, 0);
if (*p)
err("illegal seed value -- %s", optarg);
+ case 'U':
+ Uflag = 1;
+ uflag = 1;
+ break;
case 'u':
uflag = 1;
break;
cwalk();
exit(0);
}
- exit(verify());
+ status = verify();
+ if (Uflag & (status == MISMATCHEXIT))
+ status = 0;
+ exit(status);
}
static void
usage()
{
(void)fprintf(stderr,
-"usage: mtree [-cderux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n");
+"usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n");
exit(1);
}
-/* $OpenBSD: mtree.h,v 1.2 1996/12/08 01:13:42 niklas Exp $ */
+/* $OpenBSD: mtree.h,v 1.3 1996/12/10 08:26:09 deraadt Exp $ */
/* $NetBSD: mtree.h,v 1.7 1995/03/07 21:26:27 cgd Exp $ */
/*-
struct _node *prev, *next; /* left, right */
off_t st_size; /* size */
struct timespec st_mtimespec; /* last modification time */
- u_int32_t cksum; /* check sum */
+ u_int32_t cksum; /* check sum */
+ char *md5digest; /* MD5 digest */
char *slink; /* symbolic link reference */
uid_t st_uid; /* uid */
gid_t st_gid; /* gid */
#define F_MAGIC 0x0020 /* name has magic chars */
#define F_MODE 0x0040 /* mode */
#define F_NLINK 0x0080 /* number of links */
-#define F_OPT 0x0100 /* existence optional */
-#define F_SIZE 0x0200 /* size */
-#define F_SLINK 0x0400 /* link count */
-#define F_TIME 0x0800 /* modification time */
-#define F_TYPE 0x1000 /* file type */
-#define F_UID 0x2000 /* uid */
-#define F_UNAME 0x4000 /* user name */
-#define F_VISIT 0x8000 /* file visited */
+#define F_SIZE 0x0100 /* size */
+#define F_SLINK 0x0200 /* link count */
+#define F_TIME 0x0400 /* modification time */
+#define F_TYPE 0x0800 /* file type */
+#define F_UID 0x1000 /* uid */
+#define F_UNAME 0x2000 /* user name */
+#define F_VISIT 0x4000 /* file visited */
+#define F_MD5 0x8000 /* MD5 digest */
u_short flags; /* items set */
#define F_BLOCK 0x001 /* block special */
/* $NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $ */
-/* $OpenBSD: spec.c,v 1.2 1996/03/02 00:46:04 tholo Exp $ */
+/* $OpenBSD: spec.c,v 1.3 1996/12/10 08:26:10 deraadt Exp $ */
/*-
* Copyright (c) 1989, 1993
int c_cur, c_next;
char buf[2048];
- root = NULL;
+ centry = last = root = NULL;
bzero(&ginfo, sizeof(ginfo));
c_cur = c_next = 0;
for (lineno = 1; fgets(buf, sizeof(buf), stdin);
register NODE *ip;
{
register int type;
- register char *kw, *val;
+ register char *kw, *val = NULL;
struct group *gr;
struct passwd *pw;
mode_t *m;
int value;
char *ep;
- for (; kw = strtok(t, "= \t\n"); t = NULL) {
+ for (; (kw = strtok(t, "= \t\n")); t = NULL) {
ip->flags |= type = parsekey(kw, &value);
if (value && (val = strtok(NULL, " \t\n")) == NULL)
err("missing value");
if (*ep)
err("invalid checksum %s", val);
break;
+ case F_MD5:
+ ip->md5digest = strdup(val);
+ if (!ip->md5digest) {
+ err("%s", strerror(errno));
+ }
+ break;
case F_GID:
ip->st_gid = strtoul(val, &ep, 10);
if (*ep)
err("invalid link count %s", val);
break;
case F_SIZE:
- ip->st_size = strtouq(val, &ep, 10);
+ ip->st_size = strtoq(val, &ep, 10);
if (*ep)
err("invalid size %s", val);
break;
{
register char *p;
- while (p = strtok(t, "\n\t "))
+ while ((p = strtok(t, "\n\t ")))
ip->flags &= ~parsekey(p, NULL);
}
-/* $OpenBSD: verify.c,v 1.2 1996/12/08 01:13:42 niklas Exp $ */
+/* $OpenBSD: verify.c,v 1.3 1996/12/10 08:26:10 deraadt Exp $ */
/* $NetBSD: verify.c,v 1.10 1995/03/07 21:26:28 cgd Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: verify.c,v 1.2 1996/12/08 01:13:42 niklas Exp $";
+static char rcsid[] = "$OpenBSD: verify.c,v 1.3 1996/12/10 08:26:10 deraadt Exp $";
#endif
#endif /* not lint */
register FTS *t;
register FTSENT *p;
register NODE *ep, *level;
- int ftsdepth, specdepth, rval;
+ int specdepth, rval;
char *argv[2];
argv[0] = ".";
if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
err("fts_open: %s", strerror(errno));
level = root;
- ftsdepth = specdepth = rval = 0;
- while (p = fts_read(t)) {
+ specdepth = rval = 0;
+ while ((p = fts_read(t))) {
switch(p->fts_info) {
case FTS_D:
- ++ftsdepth;
break;
case FTS_DP:
- --ftsdepth;
- if (specdepth > ftsdepth) {
+ if (specdepth > p->fts_level) {
for (level = level->parent; level->prev;
level = level->prev);
--specdepth;
case FTS_ERR:
case FTS_NS:
(void)fprintf(stderr, "mtree: %s: %s\n",
- RP(p), strerror(errno));
+ RP(p), strerror(p->fts_errno));
continue;
default:
if (dflag)
continue;
}
+ if (specdepth != p->fts_level)
+ goto extra;
for (ep = level; ep; ep = ep->next)
- if (ep->flags & F_MAGIC &&
- !fnmatch(ep->name, p->fts_name, FNM_PATHNAME) ||
+ if ((ep->flags & F_MAGIC &&
+ !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
!strcmp(ep->name, p->fts_name)) {
ep->flags |= F_VISIT;
if (compare(ep->name, ep, p))
if (ep)
continue;
+extra:
if (!eflag) {
(void)printf("extra: %s", RP(p));
if (rflag) {
- if (unlink(p->fts_accpath)) {
+ if ((S_ISDIR(p->fts_statp->st_mode)
+ ? rmdir : unlink)(p->fts_accpath)) {
(void)printf(", not removed: %s",
strerror(errno));
} else
register char *tp;
for (; p; p = p->next) {
- if (p->flags & F_OPT && !(p->flags & F_VISIT))
- continue;
if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
continue;
(void)strcpy(tail, p->name);