Initial import of mtree-20030331 into The NetBSD Packages Collection.

The mtree utility 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
characteristics do not match the specification, or which are missing
from either the file hierarchy or the specification.
This commit is contained in:
grant 2003-03-31 08:51:06 +00:00
parent 94d3410739
commit 04f45d9901
20 changed files with 14694 additions and 0 deletions

5
pkgtools/mtree/DESCR Normal file
View file

@ -0,0 +1,5 @@
The mtree utility 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
characteristics do not match the specification, or which are missing
from either the file hierarchy or the specification.

28
pkgtools/mtree/Makefile Normal file
View file

@ -0,0 +1,28 @@
# $NetBSD: Makefile,v 1.1.1.1 2003/03/31 08:51:06 grant Exp $
#
DISTNAME= mtree-20030331
CATEGORIES= pkgtools
MASTER_SITES= # empty
DISTFILES= # empty
MAINTAINER= grant@NetBSD.org
HOMEPAGE= http://www.NetBSD.org/
COMMENT= mtree - a utility for mapping directory hierarchies
USE_BUILDLINK2= # defined
GNU_CONFIGURE= # defined
NO_PKGTOOLS_REQD_CHECK= # defined
NO_CHECKSUM= # defined
NO_PATCH= # defined
NO_MTREE= # defined
NO_PKG_REGISTER= # defined
NO_PACKAGE= Deinstallation is not permitted
PKG_PRESERVE= # defined
do-extract:
@${CP} -Rp ${FILESDIR} ${WRKSRC}
.include "../../pkgtools/libnbcompat/buildlink2.mk"
.include "../../mk/bsd.pkg.mk"

2
pkgtools/mtree/PLIST Normal file
View file

@ -0,0 +1,2 @@
@comment $NetBSD: PLIST,v 1.1.1.1 2003/03/31 08:51:06 grant Exp $
@comment this PLIST intentionally left blank.

View file

@ -0,0 +1,45 @@
# $NetBSD: Makefile.in,v 1.1.1.1 2003/03/31 08:51:32 grant Exp $
srcdir = @srcdir@
prefix = @prefix@
VPATH = @srcdir@
SHELL = /bin/sh
CC = @CC@
CCLD = $(CC)
CFLAGS = -I${srcdir} -I. -I${prefix}/include/libnbcompat @INCLUDES@ @CFLAGS@
CPPFLAGS= @CPPFLAGS@
DEFS = @DEFS@
INSTALL = @INSTALL@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@ -lnbcompat
mandir= ${prefix}/man
mandircat8= ${mandir}/cat8
all: mtree
PROG= mtree
MAN=
OBJS= compare.o crc.o create.o excludes.o mtree.o verify.o
LINK= $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@
COMPILE= $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)
all: ${PROG}
${PROG}: ${OBJS}
${LINK} ${OBJS} ${LIBS}
.c.o:
$(COMPILE) -c $< -o $@
clean:
rm -f ${OBJS} ${PROG}
distclean: clean
rm -f Makefile config.h config.status configure.lineno config.log
install:
${INSTALL} ${PROG} ${PREFIX}/sbin
${INSTALL} -m 444 ${PROG}.cat8 ${mandircat8}/${PROG}.0

View file

@ -0,0 +1,8 @@
/* $Id: acconfig.h,v 1.1.1.1 2003/03/31 08:51:33 grant Exp $ */
/* Define if *printf() uses %qd to print `long long' (otherwise uses %lld) */
#undef HAVE_PRINTF_QD
/* Define if `long long' is supported and sizeof(off_t) >= 8 */
#undef HAVE_QUAD_SUPPORT

141
pkgtools/mtree/files/aclocal.m4 vendored Normal file
View file

@ -0,0 +1,141 @@
dnl $Id: aclocal.m4,v 1.1.1.1 2003/03/31 08:51:33 grant Exp $
dnl
dnl
dnl AC_MSG_TRY_COMPILE
dnl
dnl Written by Luke Mewburn <lukem@netbsd.org>
dnl
dnl Usage:
dnl AC_MSG_TRY_COMPILE(Message, CacheVar, Includes, Code,
dnl ActionPass [,ActionFail] )
dnl
dnl effectively does:
dnl AC_CACHE_CHECK(Message, CacheVar,
dnl AC_TRY_COMPILE(Includes, Code, CacheVar = yes, CacheVar = no)
dnl if CacheVar == yes
dnl AC_MESSAGE_RESULT(yes)
dnl ActionPass
dnl else
dnl AC_MESSAGE_RESULT(no)
dnl ActionFail
dnl )
dnl
AC_DEFUN(AC_MSG_TRY_COMPILE, [
AC_CACHE_CHECK($1, $2, [
AC_TRY_COMPILE([ $3 ], [ $4; ], [ $2=yes ], [ $2=no ])
])
if test "x[$]$2" = "xyes"; then
$5
else
$6
:
fi
])
dnl
dnl AC_MSG_TRY_LINK
dnl
dnl Usage:
dnl AC_MSG_TRY_LINK(Message, CacheVar, Includes, Code,
dnl ActionPass [,ActionFail] )
dnl
dnl as AC_MSG_TRY_COMPILE, but uses AC_TRY_LINK instead of AC_TRY_COMPILE
dnl
AC_DEFUN(AC_MSG_TRY_LINK, [
AC_CACHE_CHECK($1, $2, [
AC_TRY_LINK([ $3 ], [ $4; ], [ $2=yes ], [ $2=no ])
])
if test "x[$]$2" = "xyes"; then
$5
else
$6
:
fi
])
dnl
dnl AC_LIBRARY_NET: #Id: net.m4,v 1.5 1997/11/09 21:36:54 jhawk Exp #
dnl
dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
dnl Domain.
dnl
dnl This test is for network applications that need socket() and
dnl gethostbyname() -ish functions. Under Solaris, those applications need to
dnl link with "-lsocket -lnsl". Under IRIX, they should *not* link with
dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
dnl IRIX).
dnl
dnl Unfortunately, many application developers are not aware of this, and
dnl mistakenly write tests that cause -lsocket to be used under IRIX. It is
dnl also easy to write tests that cause -lnsl to be used under operating
dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
dnl uses -lnsl for TLI.
dnl
dnl This test exists so that every application developer does not test this in
dnl a different, and subtly broken fashion.
dnl
dnl It has been argued that this test should be broken up into two seperate
dnl tests, one for the resolver libraries, and one for the libraries necessary
dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
dnl allowing the autoconf user to use them independantly potentially results in
dnl unfortunate ordering dependancies -- as such, such component macros would
dnl have to carefully use indirection and be aware if the other components were
dnl executed. Since other autoconf macros do not go to this trouble, and almost
dnl no applications use sockets without the resolver, this complexity has not
dnl been implemented.
dnl
dnl The check for libresolv is in case you are attempting to link statically
dnl and happen to have a libresolv.a lying around (and no libnsl.a).
dnl
AC_DEFUN(AC_LIBRARY_NET, [
# Most operating systems have gethostbyname() in the default searched
# libraries (i.e. libc):
AC_CHECK_FUNC(gethostbyname, ,
# Some OSes (eg. Solaris) place it in libnsl:
AC_CHECK_LIB(nsl, gethostbyname, ,
# Some strange OSes (SINIX) have it in libsocket:
AC_CHECK_LIB(socket, gethostbyname, ,
# Unfortunately libsocket sometimes depends on libnsl.
# AC_CHECK_LIB's API is essentially broken so the following
# ugliness is necessary:
AC_CHECK_LIB(socket, gethostbyname,
LIBS="-lsocket -lnsl $LIBS",
AC_CHECK_LIB(resolv, gethostbyname),
-lnsl)
)
)
)
AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
])
dnl
dnl Test for __attribute__
dnl
AC_DEFUN(AC_C___ATTRIBUTE__, [
AC_MSG_CHECKING(for __attribute__)
AC_CACHE_VAL(ac_cv___attribute__, [
AC_TRY_COMPILE([
#include <stdlib.h>
],
[
static void foo(void) __attribute__ ((noreturn));
static void
foo(void)
{
exit(1);
}
],
ac_cv___attribute__=yes,
ac_cv___attribute__=no)])
if test "$ac_cv___attribute__" = "yes"; then
AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
fi
AC_MSG_RESULT($ac_cv___attribute__)
])

View file

@ -0,0 +1,463 @@
/* $NetBSD: compare.c,v 1.1.1.1 2003/03/31 08:51:09 grant Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "nbcompat.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: compare.c,v 1.1.1.1 2003/03/31 08:51:09 grant Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#ifndef NO_MD5
#include <md5.h>
#endif
#ifndef NO_RMD160
#include <rmd160.h>
#endif
#ifndef NO_SHA1
#include <sha1.h>
#endif
#include "extern.h"
#define INDENTNAMELEN 8
#define MARK \
do { \
len = printf("%s: ", RP(p)); \
if (len > INDENTNAMELEN) { \
tab = "\t"; \
printf("\n"); \
} else { \
tab = ""; \
printf("%*s", INDENTNAMELEN - (int)len, ""); \
} \
} while (0)
#define LABEL if (!label++) MARK
#if HAVE_STRUCT_STAT_ST_FLAGS
#define CHANGEFLAGS \
if (flags != p->fts_statp->st_flags) { \
if (!label) { \
MARK; \
printf("%sflags (\"%s\"", tab, \
flags_to_string(p->fts_statp->st_flags, "none")); \
} \
if (lchflags(p->fts_accpath, flags)) { \
label++; \
printf(", not modified: %s)\n", \
strerror(errno)); \
} else \
printf(", modified to \"%s\")\n", \
flags_to_string(flags, "none")); \
}
/* SETFLAGS:
* given pflags, additionally set those flags specified in s->st_flags and
* selected by mask (the other flags are left unchanged).
*/
#define SETFLAGS(pflags, mask) \
do { \
flags = (s->st_flags & (mask)) | (pflags); \
CHANGEFLAGS; \
} while (0)
/* CLEARFLAGS:
* given pflags, reset the flags specified in s->st_flags and selected by mask
* (the other flags are left unchanged).
*/
#define CLEARFLAGS(pflags, mask) \
do { \
flags = (~(s->st_flags & (mask)) & CH_MASK) & (pflags); \
CHANGEFLAGS; \
} while (0)
#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
int
compare(NODE *s, FTSENT *p)
{
u_int32_t len, val, flags;
int fd, label;
const char *cp, *tab;
#if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1)
char digestbuf[41]; /* large enough for {MD5,RMD160,SHA1}File() */
#endif
tab = NULL;
label = 0;
switch(s->type) {
case F_BLOCK:
if (!S_ISBLK(p->fts_statp->st_mode))
goto typeerr;
break;
case F_CHAR:
if (!S_ISCHR(p->fts_statp->st_mode))
goto typeerr;
break;
case F_DIR:
if (!S_ISDIR(p->fts_statp->st_mode))
goto typeerr;
break;
case F_FIFO:
if (!S_ISFIFO(p->fts_statp->st_mode))
goto typeerr;
break;
case F_FILE:
if (!S_ISREG(p->fts_statp->st_mode))
goto typeerr;
break;
case F_LINK:
if (!S_ISLNK(p->fts_statp->st_mode))
goto typeerr;
break;
case F_SOCK:
if (!S_ISSOCK(p->fts_statp->st_mode)) {
typeerr: LABEL;
printf("\ttype (%s, %s)\n",
nodetype(s->type), inotype(p->fts_statp->st_mode));
return (label);
}
break;
}
if (Wflag)
goto afterpermwhack;
#if HAVE_STRUCT_STAT_ST_FLAGS
if (iflag && !uflag) {
if (s->flags & F_FLAGS)
SETFLAGS(p->fts_statp->st_flags, SP_FLGS);
return (label);
}
if (mflag && !uflag) {
if (s->flags & F_FLAGS)
CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS);
return (label);
}
#endif
if (s->flags & F_DEV &&
(s->type == F_BLOCK || s->type == F_CHAR) &&
s->st_rdev != p->fts_statp->st_rdev) {
LABEL;
printf("%sdevice (%#x, %#x",
tab, s->st_rdev, p->fts_statp->st_rdev);
if (uflag) {
if ((unlink(p->fts_accpath) == -1) ||
(mknod(p->fts_accpath,
s->st_mode | nodetoino(s->type),
s->st_rdev) == -1) ||
(lchown(p->fts_accpath, p->fts_statp->st_uid,
p->fts_statp->st_gid) == -1) )
printf(", not modified: %s)\n",
strerror(errno));
else
printf(", modified)\n");
} else
printf(")\n");
tab = "\t";
}
/* Set the uid/gid first, then set the mode. */
if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
LABEL;
printf("%suser (%lu, %lu",
tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
if (uflag) {
if (lchown(p->fts_accpath, s->st_uid, -1))
printf(", not modified: %s)\n",
strerror(errno));
else
printf(", modified)\n");
} else
printf(")\n");
tab = "\t";
}
if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
LABEL;
printf("%sgid (%lu, %lu",
tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
if (uflag) {
if (lchown(p->fts_accpath, -1, s->st_gid))
printf(", not modified: %s)\n",
strerror(errno));
else
printf(", modified)\n");
}
else
printf(")\n");
tab = "\t";
}
if (s->flags & F_MODE &&
s->st_mode != (p->fts_statp->st_mode & MBITS)) {
if (lflag) {
mode_t tmode, mode;
tmode = s->st_mode;
mode = p->fts_statp->st_mode & MBITS;
/*
* if none of the suid/sgid/etc bits are set,
* then if the mode is a subset of the target,
* skip.
*/
if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) ||
(mode & ~(S_IRWXU|S_IRWXG|S_IRWXO))))
if ((mode | tmode) == tmode)
goto skip;
}
LABEL;
printf("%spermissions (%#lo, %#lo",
tab, (u_long)s->st_mode,
(u_long)p->fts_statp->st_mode & MBITS);
if (uflag) {
if (lchmod(p->fts_accpath, s->st_mode))
printf(", not modified: %s)\n",
strerror(errno));
else
printf(", modified)\n");
}
else
printf(")\n");
tab = "\t";
skip: ;
}
if (s->flags & F_NLINK && s->type != F_DIR &&
s->st_nlink != p->fts_statp->st_nlink) {
LABEL;
printf("%slink count (%lu, %lu)\n",
tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink);
tab = "\t";
}
if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
LABEL;
printf("%ssize (%lld, %lld)\n",
tab, (long long)s->st_size,
(long long)p->fts_statp->st_size);
tab = "\t";
}
/*
* XXX
* Since utimes(2) only takes a timeval, there's no point in
* comparing the low bits of the timespec nanosecond field. This
* will only result in mismatches that we can never fix.
*
* Doesn't display microsecond differences.
*/
if (s->flags & F_TIME) {
struct timeval tv[2];
struct stat *ps = p->fts_statp;
time_t smtime = s->st_mtimespec.tv_sec;
#ifdef BSD4_4
time_t pmtime = ps->st_mtimespec.tv_sec;
TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec);
TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec);
#else
time_t pmtime = (time_t)ps->st_mtime;
tv[0].tv_sec = smtime;
tv[0].tv_usec = 0;
tv[1].tv_sec = pmtime;
tv[1].tv_usec = 0;
#endif
if (tv[0].tv_sec != tv[1].tv_sec ||
tv[0].tv_usec != tv[1].tv_usec) {
LABEL;
printf("%smodification time (%.24s, ",
tab, ctime(&smtime));
printf("%.24s", ctime(&pmtime));
if (tflag) {
tv[1] = tv[0];
if (utimes(p->fts_accpath, tv))
printf(", not modified: %s)\n",
strerror(errno));
else
printf(", modified)\n");
} else
printf(")\n");
tab = "\t";
}
}
#if HAVE_STRUCT_STAT_ST_FLAGS
/*
* XXX
* since lchflags(2) will reset file times, the utimes() above
* may have been useless! oh well, we'd rather have correct
* flags, rather than times?
*/
if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags)
|| mflag || iflag)) {
if (s->st_flags != p->fts_statp->st_flags) {
LABEL;
printf("%sflags (\"%s\" is not ", tab,
flags_to_string(s->st_flags, "none"));
printf("\"%s\"",
flags_to_string(p->fts_statp->st_flags, "none"));
}
if (uflag) {
if (iflag)
SETFLAGS(0, CH_MASK);
else if (mflag)
CLEARFLAGS(0, SP_FLGS);
else
SETFLAGS(0, (~SP_FLGS & CH_MASK));
} else
printf(")\n");
tab = "\t";
}
#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
/*
* from this point, no more permission checking or whacking
* occurs, only checking of stuff like checksums and symlinks.
*/
afterpermwhack:
if (s->flags & F_CKSUM) {
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
LABEL;
printf("%scksum: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
tab = "\t";
} else if (crc(fd, &val, &len)) {
close(fd);
LABEL;
printf("%scksum: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
tab = "\t";
} else {
close(fd);
if (s->cksum != val) {
LABEL;
printf("%scksum (%lu, %lu)\n",
tab, s->cksum, (unsigned long)val);
}
tab = "\t";
}
}
#ifndef NO_MD5
if (s->flags & F_MD5) {
if (MD5File(p->fts_accpath, digestbuf) == NULL) {
LABEL;
printf("%smd5: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
tab = "\t";
} else {
if (strcmp(s->md5digest, digestbuf)) {
LABEL;
printf("%smd5 (0x%s, 0x%s)\n",
tab, s->md5digest, digestbuf);
}
tab = "\t";
}
}
#endif /* ! NO_MD5 */
#ifndef NO_RMD160
if (s->flags & F_RMD160) {
if (RMD160File(p->fts_accpath, digestbuf) == NULL) {
LABEL;
printf("%srmd160: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
tab = "\t";
} else {
if (strcmp(s->rmd160digest, digestbuf)) {
LABEL;
printf("%srmd160 (0x%s, 0x%s)\n",
tab, s->rmd160digest, digestbuf);
}
tab = "\t";
}
}
#endif /* ! NO_RMD160 */
#ifndef NO_SHA1
if (s->flags & F_SHA1) {
if (SHA1File(p->fts_accpath, digestbuf) == NULL) {
LABEL;
printf("%ssha1: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
tab = "\t";
} else {
if (strcmp(s->sha1digest, digestbuf)) {
LABEL;
printf("%ssha1 (0x%s, 0x%s)\n",
tab, s->sha1digest, digestbuf);
}
tab = "\t";
}
}
#endif /* ! NO_SHA1 */
if (s->flags & F_SLINK &&
strcmp(cp = rlink(p->fts_accpath), s->slink)) {
LABEL;
printf("%slink ref (%s, %s", tab, cp, s->slink);
if (uflag) {
if ((unlink(p->fts_accpath) == -1) ||
(symlink(s->slink, p->fts_accpath) == -1) )
printf(", not modified: %s)\n",
strerror(errno));
else
printf(", modified)\n");
} else
printf(")\n");
}
return (label);
}
const char *
rlink(const char *name)
{
static char lbuf[MAXPATHLEN];
int len;
if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1)
mtree_err("%s: %s", name, strerror(errno));
lbuf[len] = '\0';
return (lbuf);
}

1354
pkgtools/mtree/files/config.guess vendored Executable file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,509 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* $Id: config.h.in,v 1.1.1.1 2003/03/31 08:51:31 grant Exp $ */
/* Define if *printf() uses %qd to print `long long' (otherwise uses %lld) */
#undef HAVE_PRINTF_QD
/* Define if `long long' is supported and sizeof(off_t) >= 8 */
#undef HAVE_QUAD_SUPPORT
/* Define to 1 if the `getpgrp' function requires zero arguments. */
#undef GETPGRP_VOID
/* Define to 1 if you have the <arpa/nameser.h> header file. */
#undef HAVE_ARPA_NAMESER_H
/* Define to 1 if you have the <assert.h> header file. */
#undef HAVE_ASSERT_H
/* Define to 1 if you have the `bcopy' function. */
#undef HAVE_BCOPY
/* Define to 1 if you have the <bind/bitypes.h> header file. */
#undef HAVE_BIND_BITYPES_H
/* Define to 1 if you have the `bzero' function. */
#undef HAVE_BZERO
/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
don't. */
#undef HAVE_DECL_STRERROR_R
/* Define to 1 if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
/* Define to 1 if you have the `err' function. */
#undef HAVE_ERR
/* Define to 1 if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
/* Define to 1 if you have the <err.h> header file. */
#undef HAVE_ERR_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `fgetln' function. */
#undef HAVE_FGETLN
/* Define to 1 if you have the `fparseln' function. */
#undef HAVE_FPARSELN
/* Define to 1 if you have the `fseeko' function. */
#undef HAVE_FSEEKO
/* Define to 1 if you have the <fts.h> header file. */
#undef HAVE_FTS_H
/* Define to 1 if you have the `getenv' function. */
#undef HAVE_GETENV
/* Define to 1 if you have the `getpassphrase' function. */
#undef HAVE_GETPASSPHRASE
/* Define to 1 if you have the `getpgrp' function. */
#undef HAVE_GETPGRP
/* Define to 1 if you have the `gid_from_group' function. */
#undef HAVE_GID_FROM_GROUP
/* Define to 1 if you have the `glob' function. */
#undef HAVE_GLOB
/* Define to 1 if you have the `group_from_gid' function. */
#undef HAVE_GROUP_FROM_GID
/* Define to 1 if you have the `inet_ntop' function. */
#undef HAVE_INET_NTOP
/* Define to 1 if you have the `inet_pton' function. */
#undef HAVE_INET_PTON
/* Define to 1 if the system has the type `int16_t'. */
#undef HAVE_INT16_T
/* Define to 1 if the system has the type `int32_t'. */
#undef HAVE_INT32_T
/* Define to 1 if the system has the type `int64_t'. */
#undef HAVE_INT64_T
/* Define to 1 if the system has the type `int8_t'. */
#undef HAVE_INT8_T
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `lchflags' function. */
#undef HAVE_LCHFLAGS
/* Define to 1 if you have the `lchmod' function. */
#undef HAVE_LCHMOD
/* Define to 1 if you have the `lchown' function. */
#undef HAVE_LCHOWN
/* Define to 1 if you have the `util' library (-lutil). */
#undef HAVE_LIBUTIL
/* Define to 1 if you have the <libutil.h> header file. */
#undef HAVE_LIBUTIL_H
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
/* Define to 1 if the system has the type `long long'. */
#undef HAVE_LONG_LONG
/* Define to 1 if you have the `lutimes' function. */
#undef HAVE_LUTIMES
/* Define to 1 if you have the <machine/endian.h> header file. */
#undef HAVE_MACHINE_ENDIAN_H
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
/* Define to 1 if you have the `MD5File' function. */
#undef HAVE_MD5FILE
/* Define to 1 if you have the `memcpy' function. */
#undef HAVE_MEMCPY
/* Define to 1 if you have the `memmove' function. */
#undef HAVE_MEMMOVE
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the `mkstemp' function. */
#undef HAVE_MKSTEMP
/* Define to 1 if you have the <param.h> header file. */
#undef HAVE_PARAM_H
/* Define to 1 if you have the <paths.h> header file. */
#undef HAVE_PATHS_H
/* Define to 1 if you have the `poll' function. */
#undef HAVE_POLL
/* Define to 1 if you have the <poll.h> header file. */
#undef HAVE_POLL_H
/* Define to 1 if you have the `pwcache_groupdb' function. */
#undef HAVE_PWCACHE_GROUPDB
/* Define to 1 if you have the `pwcache_userdb' function. */
#undef HAVE_PWCACHE_USERDB
/* Define to 1 if you have the <regex.h> header file. */
#undef HAVE_REGEX_H
/* Define to 1 if you have the `RMD160File' function. */
#undef HAVE_RMD160FILE
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `setenv' function. */
#undef HAVE_SETENV
/* Define to 1 if you have the `setgrent' function. */
#undef HAVE_SETGRENT
/* Define to 1 if you have the `setgroupent' function. */
#undef HAVE_SETGROUPENT
/* Define to 1 if you have the `setlocale' function. */
#undef HAVE_SETLOCALE
/* Define to 1 if you have the `setpassent' function. */
#undef HAVE_SETPASSENT
/* Define to 1 if you have the `setprogname' function. */
#undef HAVE_SETPROGNAME
/* Define to 1 if you have the `setpwent' function. */
#undef HAVE_SETPWENT
/* Define to 1 if you have the `SHA1File' function. */
#undef HAVE_SHA1FILE
/* Define to 1 if you have the `sl_init' function. */
#undef HAVE_SL_INIT
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the `statfs' function. */
#undef HAVE_STATFS
/* Define to 1 if you have the `statvfs' function. */
#undef HAVE_STATVFS
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strdup' function. */
#undef HAVE_STRDUP
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
/* Define to 1 if you have the `strerror_r' function. */
#undef HAVE_STRERROR_R
/* Define to 1 if you have the <stringlist.h> header file. */
#undef HAVE_STRINGLIST_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strlcat' function. */
#undef HAVE_STRLCAT
/* Define to 1 if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define to 1 if you have the `strptime' function. */
#undef HAVE_STRPTIME
/* Define to 1 if you have the `strsep' function. */
#undef HAVE_STRSEP
/* Define to 1 if you have the `strsvis' function. */
#undef HAVE_STRSVIS
/* Define to 1 if you have the `strtoll' function. */
#undef HAVE_STRTOLL
/* Define to 1 if you have the `strunvis' function. */
#undef HAVE_STRUNVIS
/* Define to 1 if you have the `strvis' function. */
#undef HAVE_STRVIS
/* Define to 1 if you have the <sys/bitypes.h> header file. */
#undef HAVE_SYS_BITYPES_H
/* Define to 1 if you have the <sys/byteorder.h> header file. */
#undef HAVE_SYS_BYTEORDER_H
/* Define to 1 if you have the <sys/cdefs.h> header file. */
#undef HAVE_SYS_CDEFS_H
/* Define to 1 if you have the <sys/endian.h> header file. */
#undef HAVE_SYS_ENDIAN_H
/* Define to 1 if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H
/* Define to 1 if you have the <sys/mkdev.h> header file. */
#undef HAVE_SYS_MKDEV_H
/* Define to 1 if you have the <sys/mount.h> header file. */
#undef HAVE_SYS_MOUNT_H
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define to 1 if you have the <sys/poll.h> header file. */
#undef HAVE_SYS_POLL_H
/* Define to 1 if you have the <sys/queue.h> header file. */
#undef HAVE_SYS_QUEUE_H
/* Define to 1 if you have the <sys/statvfs.h> header file. */
#undef HAVE_SYS_STATVFS_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/vfs.h> header file. */
#undef HAVE_SYS_VFS_H
/* Define to 1 if you have the <termcap.h> header file. */
#undef HAVE_TERMCAP_H
/* Define to 1 if you have the `timegm' function. */
#undef HAVE_TIMEGM
/* Define to 1 if you have the `uid_from_user' function. */
#undef HAVE_UID_FROM_USER
/* Define to 1 if the system has the type `uint16_t'. */
#undef HAVE_UINT16_T
/* Define to 1 if the system has the type `uint32_t'. */
#undef HAVE_UINT32_T
/* Define to 1 if the system has the type `uint64_t'. */
#undef HAVE_UINT64_T
/* Define to 1 if the system has the type `uint8_t'. */
#undef HAVE_UINT8_T
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `user_from_uid' function. */
#undef HAVE_USER_FROM_UID
/* Define to 1 if you have the `usleep' function. */
#undef HAVE_USLEEP
/* Define to 1 if you have the <util.h> header file. */
#undef HAVE_UTIL_H
/* Define to 1 if the system has the type `u_int16_t'. */
#undef HAVE_U_INT16_T
/* Define to 1 if the system has the type `u_int32_t'. */
#undef HAVE_U_INT32_T
/* Define to 1 if the system has the type `u_int64_t'. */
#undef HAVE_U_INT64_T
/* Define to 1 if the system has the type `u_int8_t'. */
#undef HAVE_U_INT8_T
/* Define to 1 if you have the <vis.h> header file. */
#undef HAVE_VIS_H
/* Define to 1 if you have the `vprintf' function. */
#undef HAVE_VPRINTF
/* define if your compiler has __attribute__ */
#undef HAVE___ATTRIBUTE__
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of a `off_t', as computed by sizeof. */
#undef SIZEOF_OFF_T
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if strerror_r returns char *. */
#undef STRERROR_R_CHAR_P
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to `unsigned' if <sys/types.h> does not define. */
#undef size_t
#ifndef HAVE___ATTRIBUTE__
# define __attribute__(x)
#endif
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#ifndef __IDSTRING
# define __IDSTRING(name,string) \
static const char name[] __attribute__((__unused__)) = string
#endif
#ifndef __RCSID
# define __RCSID(_s) __IDSTRING(rcsid,_s)
#endif
#ifndef __COPYRIGHT
# define __COPYRIGHT(_s) __IDSTRING(copyright,_s)
#endif
#ifndef __P
# if defined(__STDC__) || defined(__cplusplus)
# define __P(protos) protos /* full-blown ANSI C */
# else
# define __P(protos) () /* traditional C preprocessor */
# endif
#endif
#ifndef __CONCAT
# if defined(__STDC__) || defined(__cplusplus)
# define __CONCAT(x,y) x ## y
# else
# define __CONCAT(x,y) x/**/y
# endif
#endif
#ifndef __BEGIN_DECLS
# if defined(__cplusplus)
# define __BEGIN_DECLS extern "C" {
# else
# define __BEGIN_DECLS
# endif
#endif
#ifndef __END_DECLS
# if defined(__cplusplus)
# define __END_DECLS };
# else
# define __END_DECLS
# endif
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
#ifdef HAVE_MACHINE_ENDIAN_H
#include <machine/endian.h>
#endif
#ifdef HAVE_SYS_BYTEORDER_H
#include <sys/byteorder.h>
#endif
#ifndef LITTLE_ENDIAN
# define LITTLE_ENDIAN 1234
#endif
#ifndef BIG_ENDIAN
# define BIG_ENDIAN 4321
#endif
#ifndef UINT_MAX
# define UINT_MAX 4294967295U
#endif
#ifndef BYTE_ORDER
# if defined(_BIG_ENDIAN)
# define BYTE_ORDER BIG_ENDIAN
# elif defined(_LITTE_ENDIAN)
# define BYTE_ORDER LITTLE_ENDIAN
# elif defined(WORDS_BIGENDIAN)
# define BYTE_ORDER BIG_ENDIAN
# else
# define BYTE_ORDER LITTLE_ENDIAN
# endif
#endif
#if defined(HAVE_MEMSET)
#define MEMSET_BZERO(p,l) memset((p), 0, (l))
#else
# if defined(HAVE_BZERO)
#define MEMSET_BZERO(p,l) bzero((p), (l))
# else
#error You need either memset or bzero
# endif
#endif
#if defined(HAVE_MEMCPY)
#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l))
#else
# if defined(HAVE_BCOPY)
#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l))
# else
#error You need either memcpy or bcopy
# endif
#endif

1463
pkgtools/mtree/files/config.sub vendored Executable file

File diff suppressed because it is too large Load diff

8010
pkgtools/mtree/files/configure vendored Executable file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,271 @@
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.52)
AC_INIT([mtree], [20030331], [grant@NetBSD.org])
AC_CONFIG_SRCDIR([mtree.c])
AC_CONFIG_HEADER(config.h)
AC_ARG_PROGRAM
AC_CANONICAL_HOST
CANONICAL_HOST=$host
AC_SUBST(CANONICAL_HOST)
AC_SUBST(INCLUDES)
# Checks for programs.
AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB
AC_CHECK_PROG(AR, ar, ar)
AUTOCONF=${AUTOCONF-"$srcdir/missing --run autoconf"}
AC_SUBST(AUTOCONF)
AUTOHEADER=${AUTOHEADER-"$srcdir/missing --run autoheader"}
AC_SUBST(AUTOHEADER)
dnl Checks for libraries.
dnl
AC_CHECK_LIB(util, fparseln)
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([sys/endian.h sys/file.h sys/mkdev.h sys/param.h])
AC_CHECK_HEADERS([assert.h arpa/nameser.h dirent.h err.h errno.h fcntl.h \
fts.h libutil.h locale.h machine/endian.h param.h paths.h \
poll.h regex.h stringlist.h sys/byteorder.h sys/poll.h \
termcap.h unistd.h util.h vis.h limits.h])
AC_CHECK_HEADERS([bind/bitypes.h inttypes.h sys/bitypes.h sys/cdefs.h \
sys/endian.h sys/mkdev.h sys/mount.h sys/queue.h \
sys/stat.h sys/statvfs.h sys/vfs.h sys/types.h \
sys/byteorder.h])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C___ATTRIBUTE__
AC_TYPE_SIZE_T
AC_CHECK_TYPES([long long, int8_t, int16_t, int32_t, int64_t, u_int8_t, u_int16_t, u_int32_t, u_int64_t, uint8_t, uint16_t, uint32_t, uint64_t],[],[],
[#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_BITYPES_H
#include <sys/bitypes.h>
#endif])
AC_C_BIGENDIAN
AC_CHECK_SIZEOF(off_t, 0)
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_STRERROR_R
AC_FUNC_VPRINTF
AC_REPLACE_FUNCS([err fgetln fseeko getenv glob inet_ntop \
inet_pton lchflags lchmod lchown lutimes mkstemp setenv \
setprogname sl_init snprintf strdup strerror strlcat \
strlcpy strptime strsep strtoll timegm usleep])
AC_CHECK_FUNCS([MD5File RMD160File SHA1File])
AC_CHECK_FUNCS([setgroupent setgrent setpassent setpwent])
AC_CHECK_FUNCS([bcopy bzero memset memcpy setlocale])
AC_CHECK_FUNCS([statfs statvfs])
AC_CHECK_FUNCS([gid_from_group group_from_gid pwcache_groupdb pwcache_userdb \
uid_from_user user_from_uid])
AC_CHECK_FUNCS([strunvis strvis strsvis])
AC_CHECK_FUNCS([getpassphrase getpgrp memmove poll select])
if test $ac_cv_func_getpgrp = yes; then
AC_FUNC_GETPGRP
fi
if test $ac_cv_lib_util_fparseln != yes; then
AC_REPLACE_FUNCS([fparseln])
fi
if test $ac_cv_type_long_long = yes -a $ac_cv_sizeof_off_t -ge 8; then
dnl We assume that if sprintf() supports %lld or %qd,
dnl then all of *printf() does. If not, disable long long
dnl support because we don't know how to display it.
AC_MSG_CHECKING(*printf() support for %lld)
can_printf_longlong=no
AC_TRY_RUN([
#include <stdio.h>
int main() {
char buf[100];
sprintf(buf, "%lld", 4294967300LL);
return (strcmp(buf, "4294967300"));
}
], [
AC_MSG_RESULT(yes)
can_printf_longlong=yes
], [
AC_MSG_RESULT(no)
], [ : ])
if test $can_printf_longlong != yes; then
AC_MSG_CHECKING(*printf() support for %qd)
AC_TRY_RUN([
#include <stdio.h>
int main() {
char buf[100];
sprintf(buf, "%qd", 4294967300LL);
return (strcmp(buf, "4294967300"));
}
], [
AC_MSG_RESULT(yes)
can_printf_longlong=yes
AC_DEFINE(HAVE_PRINTF_QD, 1)
], [
AC_MSG_RESULT(no)
], [ : ])
fi
if test $can_printf_longlong = yes; then
AC_DEFINE(HAVE_QUAD_SUPPORT, 1)
AC_REPLACE_FUNCS(strtoll)
fi
fi
if test $ac_cv_func_sl_init = yes; then
AC_MSG_TRY_COMPILE(if sl_add() returns int, pkg_cv_INT_SL_ADD, [
#include <stringlist.h> ], [ int f = sl_add((StringList *)0, "foo") ],
[:] , [AC_LIBOBJ="$AC_LIBOBJ sl_init.o"])
fi
if test $ac_cv_header_vis_h = yes; then
AC_MSG_TRY_COMPILE(for VIS_WHITE in vis.h,
pkg_cv_have_vis_white, [
#include <sys/types.h>
#include <vis.h> ], [ int X = VIS_WHITE ], [:],
ac_cv_header_vis_h=no )
fi
AH_BOTTOM([
#ifndef HAVE___ATTRIBUTE__
# define __attribute__(x)
#endif
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#ifndef __IDSTRING
# define __IDSTRING(name,string) \
static const char name[] __attribute__((__unused__)) = string
#endif
#ifndef __RCSID
# define __RCSID(_s) __IDSTRING(rcsid,_s)
#endif
#ifndef __COPYRIGHT
# define __COPYRIGHT(_s) __IDSTRING(copyright,_s)
#endif
#ifndef __P
# if defined(__STDC__) || defined(__cplusplus)
# define __P(protos) protos /* full-blown ANSI C */
# else
# define __P(protos) () /* traditional C preprocessor */
# endif
#endif
#ifndef __CONCAT
# if defined(__STDC__) || defined(__cplusplus)
# define __CONCAT(x,y) x ## y
# else
# define __CONCAT(x,y) x/**/y
# endif
#endif
#ifndef __BEGIN_DECLS
# if defined(__cplusplus)
# define __BEGIN_DECLS extern "C" {
# else
# define __BEGIN_DECLS
# endif
#endif
#ifndef __END_DECLS
# if defined(__cplusplus)
# define __END_DECLS };
# else
# define __END_DECLS
# endif
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
#ifdef HAVE_MACHINE_ENDIAN_H
#include <machine/endian.h>
#endif
#ifdef HAVE_SYS_BYTEORDER_H
#include <sys/byteorder.h>
#endif
#ifndef LITTLE_ENDIAN
# define LITTLE_ENDIAN 1234
#endif
#ifndef BIG_ENDIAN
# define BIG_ENDIAN 4321
#endif
#ifndef UINT_MAX
# define UINT_MAX 4294967295U
#endif
#ifndef BYTE_ORDER
# if defined(_BIG_ENDIAN)
# define BYTE_ORDER BIG_ENDIAN
# elif defined(_LITTE_ENDIAN)
# define BYTE_ORDER LITTLE_ENDIAN
# elif defined(WORDS_BIGENDIAN)
# define BYTE_ORDER BIG_ENDIAN
# else
# define BYTE_ORDER LITTLE_ENDIAN
# endif
#endif
#if defined(HAVE_MEMSET)
#define MEMSET_BZERO(p,l) memset((p), 0, (l))
#else
# if defined(HAVE_BZERO)
#define MEMSET_BZERO(p,l) bzero((p), (l))
# else
#error You need either memset or bzero
# endif
#endif
#if defined(HAVE_MEMCPY)
#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l))
#else
# if defined(HAVE_BCOPY)
#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l))
# else
#error You need either memcpy or bcopy
# endif
#endif
])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

171
pkgtools/mtree/files/crc.c Normal file
View file

@ -0,0 +1,171 @@
/* $NetBSD: crc.c,v 1.1.1.1 2003/03/31 08:51:10 grant Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* James W. Williams of NASA Goddard Space Flight Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "nbcompat.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
#else
__RCSID("$NetBSD: crc.c,v 1.1.1.1 2003/03/31 08:51:10 grant Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "extern.h"
static const u_int32_t crctab[] = {
0x0,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
/*
* Compute a POSIX 1003.2 checksum. This routine has been broken out so that
* other programs can use it. It takes a file descriptor to read from and
* locations to store the crc and the number of bytes read. It returns 0 on
* success and 1 on failure. Errno is set on failure.
*/
extern int sflag;
u_int32_t crc_total = ~0; /* The crc over a number of files. */
int
crc(fd, cval, clen)
register int fd;
u_int32_t *cval, *clen;
{
register u_char *p;
register int nr;
register u_int32_t thecrc, len;
register u_int32_t crctot;
u_char buf[16 * 1024];
#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
thecrc = len = 0;
if (sflag)
crctot = ~crc_total;
while ((nr = read(fd, buf, sizeof(buf))) > 0)
if (sflag) {
for (len += nr, p = buf; nr--; ++p) {
COMPUTE(thecrc, *p);
COMPUTE(crctot, *p);
}
} else {
for (len += nr, p = buf; nr--; ++p)
COMPUTE(thecrc, *p);
}
if (nr < 0)
return (1);
*clen = len;
/* Include the length of the file. */
if (sflag) {
for (; len != 0; len >>= 8) {
COMPUTE(thecrc, len & 0xff);
COMPUTE(crctot, len & 0xff);
}
} else {
for (; len != 0; len >>= 8)
COMPUTE(thecrc, len & 0xff);
}
*cval = ~thecrc;
if (sflag)
crc_total = ~crctot;
return (0);
}

View file

@ -0,0 +1,385 @@
/* $NetBSD: create.c,v 1.1.1.1 2003/03/31 08:51:10 grant Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "nbcompat.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: create.c,v 1.1.1.1 2003/03/31 08:51:10 grant Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#if !HAVE_CONFIG_H
#include <dirent.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#ifndef NO_MD5
#include <md5.h>
#endif
#ifndef NO_RMD160
#include <rmd160.h>
#endif
#ifndef NO_SHA1
#include <sha1.h>
#endif
#include "extern.h"
#define INDENTNAMELEN 15
#define MAXLINELEN 80
static gid_t gid;
static uid_t uid;
static mode_t mode;
static u_long flags;
static int dsort(const FTSENT **, const FTSENT **);
static void output(int *, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
static int statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *);
static void statf(FTSENT *);
void
cwalk(void)
{
FTS *t;
FTSENT *p;
time_t clocktime;
char host[MAXHOSTNAMELEN + 1];
char *argv[2];
char dot[] = ".";
argv[0] = dot;
argv[1] = NULL;
time(&clocktime);
gethostname(host, sizeof(host));
host[sizeof(host) - 1] = '\0';
printf(
"#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n#\t date: %s",
getlogin(), host, fullpath, ctime(&clocktime));
if ((t = fts_open(argv, ftsoptions, dsort)) == NULL)
mtree_err("fts_open: %s", strerror(errno));
while ((p = fts_read(t)) != NULL) {
if (check_excludes(p->fts_name, p->fts_path)) {
fts_set(t, p, FTS_SKIP);
continue;
}
switch(p->fts_info) {
case FTS_D:
printf("\n# %s\n", p->fts_path);
statd(t, p, &uid, &gid, &mode, &flags);
statf(p);
break;
case FTS_DP:
if (p->fts_level > 0)
printf("# %s\n..\n\n", p->fts_path);
break;
case FTS_DNR:
case FTS_ERR:
case FTS_NS:
mtree_err("%s: %s",
p->fts_path, strerror(p->fts_errno));
break;
default:
if (!dflag)
statf(p);
break;
}
}
fts_close(t);
if (sflag && keys & F_CKSUM)
mtree_err("%s checksum: %u", fullpath, crc_total);
}
static void
statf(FTSENT *p)
{
u_int32_t len, val;
int fd, indent;
const char *name, *path;
#if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1)
char digestbuf[41]; /* large enough for {MD5,RMD160,SHA1}File() */
#endif
path = vispath(p->fts_name);
indent = printf("%s%s",
S_ISDIR(p->fts_statp->st_mode) ? "" : " ", path);
if (indent > INDENTNAMELEN)
indent = MAXLINELEN;
else
indent += printf("%*s", INDENTNAMELEN - indent, "");
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 &&
(name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL)
output(&indent, "uname=%s", 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 &&
(name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL)
output(&indent, "gname=%s", name);
else /* if (keys & F_GID) */
output(&indent, "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);
if (keys & F_DEV &&
(S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode)))
output(&indent, "device=%#x", p->fts_statp->st_rdev);
if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
output(&indent, "nlink=%u", p->fts_statp->st_nlink);
if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode))
output(&indent, "size=%lld", (long long)p->fts_statp->st_size);
#ifdef BSD4_4
if (keys & F_TIME)
output(&indent, "time=%ld.%ld",
(long)p->fts_statp->st_mtimespec.tv_sec,
p->fts_statp->st_mtimespec.tv_nsec);
#else
output(&indent, "time=%ld.%ld",
p->fts_statp->st_mtime, 0);
#endif
if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 ||
crc(fd, &val, &len))
mtree_err("%s: %s", p->fts_accpath, strerror(errno));
close(fd);
output(&indent, "cksum=%lu", (long)val);
}
#ifndef NO_MD5
if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) {
if (MD5File(p->fts_accpath, digestbuf) == NULL)
mtree_err("%s: %s", p->fts_accpath, "MD5File");
output(&indent, "md5=%s", digestbuf);
}
#endif /* ! NO_MD5 */
#ifndef NO_RMD160
if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) {
if (RMD160File(p->fts_accpath, digestbuf) == NULL)
mtree_err("%s: %s", p->fts_accpath, "RMD160File");
output(&indent, "rmd160=%s", digestbuf);
}
#endif /* ! NO_RMD160 */
#ifndef NO_SHA1
if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) {
if (SHA1File(p->fts_accpath, digestbuf) == NULL)
mtree_err("%s: %s", p->fts_accpath, "SHA1File");
output(&indent, "sha1=%s", digestbuf);
}
#endif /* ! NO_SHA1 */
if (keys & F_SLINK &&
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
output(&indent, "link=%s", rlink(p->fts_accpath));
#if HAVE_STRUCT_STAT_ST_FLAGS
if (keys & F_FLAGS && p->fts_statp->st_flags != flags)
output(&indent, "flags=%s",
flags_to_string(p->fts_statp->st_flags, "none"));
#endif
putchar('\n');
}
/* XXX
* FLAGS2INDEX will fail once the user and system settable bits need more
* than one byte, respectively.
*/
#define FLAGS2INDEX(x) (((x >> 8) & 0x0000ff00) | (x & 0x000000ff))
#define MTREE_MAXGID 5000
#define MTREE_MAXUID 5000
#define MTREE_MAXMODE (MBITS + 1)
#if HAVE_STRUCT_STAT_ST_FLAGS
#define MTREE_MAXFLAGS (FLAGS2INDEX(CH_MASK) + 1) /* 1808 */
#else
#define MTREE_MAXFLAGS 1
#endif
#define MTREE_MAXS 16
static int
statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode,
u_long *pflags)
{
FTSENT *p;
gid_t sgid;
uid_t suid;
mode_t smode;
u_long sflags = 0;
const char *name;
gid_t savegid;
uid_t saveuid;
mode_t savemode;
u_long saveflags;
u_short maxgid, maxuid, maxmode, maxflags;
u_short g[MTREE_MAXGID], u[MTREE_MAXUID],
m[MTREE_MAXMODE], f[MTREE_MAXFLAGS];
static int first = 1;
savegid = *pgid;
saveuid = *puid;
savemode = *pmode;
saveflags = *pflags;
if ((p = fts_children(t, 0)) == NULL) {
if (errno)
mtree_err("%s: %s", RP(parent), strerror(errno));
return (1);
}
memset(g, 0, sizeof(g));
memset(u, 0, sizeof(u));
memset(m, 0, sizeof(m));
memset(f, 0, sizeof(f));
maxuid = maxgid = maxmode = maxflags = 0;
for (; p; p = p->fts_link) {
smode = p->fts_statp->st_mode & MBITS;
if (smode < MTREE_MAXMODE && ++m[smode] > maxmode) {
savemode = smode;
maxmode = m[smode];
}
sgid = p->fts_statp->st_gid;
if (sgid < MTREE_MAXGID && ++g[sgid] > maxgid) {
savegid = sgid;
maxgid = g[sgid];
}
suid = p->fts_statp->st_uid;
if (suid < MTREE_MAXUID && ++u[suid] > maxuid) {
saveuid = suid;
maxuid = u[suid];
}
#if HAVE_STRUCT_STAT_ST_FLAGS
sflags = FLAGS2INDEX(p->fts_statp->st_flags);
if (sflags < MTREE_MAXFLAGS && ++f[sflags] > maxflags) {
saveflags = p->fts_statp->st_flags;
maxflags = f[sflags];
}
#endif
}
/*
* 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 | F_UID)) && (*puid != saveuid)) ||
((keys & (F_GNAME | F_GID)) && (*pgid != savegid)) ||
((keys & F_MODE) && (*pmode != savemode)) ||
((keys & F_FLAGS) && (*pflags != saveflags)) ||
first) {
first = 0;
printf("/set type=file");
if (keys & (F_UID | F_UNAME)) {
if (keys & F_UNAME &&
(name = user_from_uid(saveuid, 1)) != NULL)
printf(" uname=%s", name);
else /* if (keys & F_UID) */
printf(" uid=%lu", (u_long)saveuid);
}
if (keys & (F_GID | F_GNAME)) {
if (keys & F_GNAME &&
(name = group_from_gid(savegid, 1)) != NULL)
printf(" gname=%s", name);
else /* if (keys & F_UID) */
printf(" gid=%lu", (u_long)savegid);
}
if (keys & F_MODE)
printf(" mode=%#lo", (u_long)savemode);
if (keys & F_NLINK)
printf(" nlink=1");
if (keys & F_FLAGS)
printf(" flags=%s",
flags_to_string(saveflags, "none"));
printf("\n");
*puid = saveuid;
*pgid = savegid;
*pmode = savemode;
*pflags = saveflags;
}
return (0);
}
static int
dsort(const FTSENT **a, const FTSENT **b)
{
if (S_ISDIR((*a)->fts_statp->st_mode)) {
if (!S_ISDIR((*b)->fts_statp->st_mode))
return (1);
} else if (S_ISDIR((*b)->fts_statp->st_mode))
return (-1);
return (strcmp((*a)->fts_name, (*b)->fts_name));
}
void
output(int *offset, const char *fmt, ...)
{
va_list ap;
char buf[1024];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (*offset + strlen(buf) > MAXLINELEN - 3) {
printf(" \\\n%*s", INDENTNAMELEN, "");
*offset = INDENTNAMELEN;
}
*offset += printf(" %s", buf) + 1;
}

View file

@ -0,0 +1,119 @@
/* $NetBSD: excludes.c,v 1.1.1.1 2003/03/31 08:51:11 grant Exp $ */
/*
* Copyright 2000 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that both the above copyright notice and this
* permission notice appear in all copies, that both the above
* copyright notice and this permission notice appear in all
* supporting documentation, and that the name of M.I.T. not be used
* in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. M.I.T. makes
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
* SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "nbcompat.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: excludes.c,v 1.1.1.1 2003/03/31 08:51:11 grant Exp $");
#endif
#include <sys/types.h>
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "extern.h"
/*
* We're assuming that there won't be a whole lot of excludes,
* so it's OK to use a stupid algorithm.
*/
struct exclude {
LIST_ENTRY(exclude) link;
const char *glob;
int pathname;
};
static LIST_HEAD(, exclude) excludes;
void
init_excludes(void)
{
LIST_INIT(&excludes);
}
void
read_excludes_file(const char *name)
{
FILE *fp;
char *line;
struct exclude *e;
fp = fopen(name, "r");
if (fp == 0)
err(1, "%s", name);
while ((line = fparseln(fp, NULL, NULL, NULL,
FPARSELN_UNESCCOMM | FPARSELN_UNESCCONT | FPARSELN_UNESCESC))
!= NULL) {
if (line[0] == '\0')
continue;
if ((e = malloc(sizeof *e)) == NULL)
mtree_err("memory allocation error");
e->glob = line;
if (strchr(e->glob, '/') != NULL)
e->pathname = 1;
else
e->pathname = 0;
LIST_INSERT_HEAD(&excludes, e, link);
}
fclose(fp);
}
int
check_excludes(const char *fname, const char *path)
{
struct exclude *e;
/* fnmatch(3) has a funny return value convention... */
#define MATCH(g, n) (fnmatch((g), (n), FNM_PATHNAME) == 0)
e = LIST_FIRST(&excludes);
while (e) {
if ((e->pathname && MATCH(e->glob, path))
|| MATCH(e->glob, fname)) {
return (1);
}
e = LIST_NEXT(e, link);
}
return (0);
}

251
pkgtools/mtree/files/install-sh Executable file
View file

@ -0,0 +1,251 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

View file

@ -0,0 +1,625 @@
.\" $NetBSD: mtree.8,v 1.1.1.1 2003/03/31 08:51:12 grant Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)mtree.8 8.2 (Berkeley) 12/11/93
.\"
.Dd December 22, 2002
.Dt MTREE 8
.Os
.Sh NAME
.Nm mtree
.Nd map a directory hierarchy
.Sh SYNOPSIS
.Nm
.Op Fl cCdDelLPruUWx
.Bk -words
.Op Fl i | Fl m
.Ek
.Bk -words
.Op Fl f Ar spec
.Ek
.Bk -words
.Op Fl p Ar path
.Ek
.Bk -words
.Op Fl k Ar keywords
.Ek
.Bk -words
.Op Fl K Ar keywords
.Ek
.Bk -words
.Op Fl R Ar keywords
.Ek
.Bk -words
.Op Fl E Ar tags
.Ek
.Bk -words
.Op Fl I Ar tags
.Ek
.Bk -words
.Op Fl N Ar dbdir
.Ek
.Bk -words
.Op Fl s Ar seed
.Ek
.Bk -words
.Op Fl X Ar exclude-file
.Ek
.Sh DESCRIPTION
The
.Nm
utility 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
characteristics do not match the specification, or which are
missing from either the file hierarchy or the specification.
.Pp
The options are as follows:
.Bl -tag -width flag
.It Fl c
Print a specification for the file hierarchy to the standard output.
.It Fl d
Ignore everything except directory type files.
.It Fl C
Print
.Pq Sq dump
the specification as provided by
.Fl f Ar spec
in a format that's easier to parse with various tools.
The full path name is always printed as the first field, and
.Fl k ,
.Fl K ,
and
.Fl R
can be used to control which other keywords are printed,
and
.Fl E
and
.Fl I
can be used to control which files are printed.
.It Fl D
As per
.Fl C ,
except that the path name is always printed as the last field instead of
the first.
.It Fl E Ar tags
Add the comma separated tags to the
.Dq exclusion
list.
Non-directories with tags which are in the exclusion list are not printed with
.Fl D .
.It Fl e
Don't complain about files that are in the file hierarchy, but not in the
specification.
.It Fl f Ar spec
Read the specification from
.Ar file ,
instead of from the standard input.
.It Fl I Ar tags
Add the comma separated tags to the
.Dq inclusion
list.
Non-directories with tags which are in the inclusion list are printed with
.Fl D .
If no inclusion list is provided, the default is to display all files.
.It Fl i
If specified, set the schg and/or sappnd flags.
.It Fl K Ar keywords
Add the specified (whitespace or comma separated) keywords to the current
set of keywords.
If
.Ql all
is specified, add all of the other keywords.
.It Fl k Ar keywords
Use the
.Sy type
keyword plus the specified (whitespace or comma separated)
keywords instead of the current set of keywords.
If
.Ql all
is specified, use all of the other keywords.
.It Fl l
Do
.Dq loose
permissions checks, in which more stringent permissions
will match less stringent ones. For example, a file marked mode 0444
will pass a check for mode 0644.
.Dq Loose
checks apply only to read, write and execute permissions -- in
particular, if other bits like the sticky bit or suid/sgid bits are
set either in the specification or the file, exact checking will be
performed. This flag may not be set at the same time as the
.Fl u
or
.Fl U
flags.
.It Fl L
Follow all symbolic links in the file hierarchy.
.It Fl m
If the schg and/or sappnd flags are specified, reset these flags. Note that
this is only possible with securelevel less than 1 (i. e. in single user mode
or while the system is running in insecure mode). See
.Xr init 8
for information on security levels.
.It Fl N Ar dbdir
Use the user database text file
.Pa master.passwd
and group database text file
.Pa group
from
.Ar dbdir ,
rather than using the results from the system's
.Xr getpwnam 3
and
.Xr getgrnam 3
(and related) library calls.
.It Fl p Ar path
Use the file hierarchy rooted in
.Ar path ,
instead of the current directory.
.It Fl P
Don't follow symbolic links in the file hierarchy, instead consider
the symbolic link itself in any comparisons.
This is the default.
.It Fl r
Remove any files in the file hierarchy that are not described in the
specification.
.It Fl R Ar keywords
Remove the specified (whitespace or comma separated) keywords from the current
set of keywords.
If
.Ql all
is specified, remove all of the other keywords.
.It Fl s Ar seed
Display a single checksum to the standard error output that represents all
of the files for which the keyword
.Sy cksum
was specified.
The checksum is seeded with the specified value.
.It Fl u
Modify the owner, group, permissions, and flags of existing files,
the device type of devices, and symbolic link targets,
to match the specification.
Create any missing directories, devices or symbolic links.
User, group, and permissions must all be specified for missing directories
to be created.
Note that unless the
.Fl i
option is given, the schg and sappnd flags will not be set, even if
specified. If
.Fl m
is given, these flags will be reset.
Exit with a status of 0 on success,
2 if the file hierarchy did not match the specification, and
1 if any other error occurred.
.It Fl U
Same as
.Fl u
except that a mismatch is not considered to be an error if it was corrected.
.It Fl W
Don't attempt to set various file attributes such as the
ownership, mode, flags, or time
when creating new directories or changing existing entries.
This option will be most useful when used in conjunction with
.Fl u
or
.Fl U .
.It Fl x
Don't descend below mount points in the file hierarchy.
.It Fl X Ar exclude-file
The specified file contains
.Xr fnmatch 3
patterns matching files to be excluded from
the specification, one to a line.
If the pattern contains a
.Ql \&/
character, it will be matched against entire pathnames (relative to
the starting directory); otherwise,
it will be matched against basenames only.
Comments are permitted in
the
.Ar exclude-list
file.
.El
.Pp
Specifications are mostly composed of
.Dq keywords ,
i.e. strings that
that specify values relating to files.
No keywords have default values, and if a keyword has no value set, no
checks based on it are performed.
.Pp
Currently supported keywords are as follows:
.Bl -tag -width Sy
.It Sy cksum
The checksum of the file using the default algorithm specified by
the
.Xr cksum 1
utility.
.It Sy device
The device number to use for
.Sy block
or
.Sy char
file types.
The argument must be one of the following forms:
.Pp
.Bl -tag -width 4n
.It Xo
.Sm off
.Ar format ,
.Ar major ,
.Ar minor
.Sm on
.Xc
A device with
.Ar major
and
.Ar minor
fields, for an operating system specified with
.Ar format .
See below for valid formats.
.It Xo
.Sm off
.Ar format ,
.Ar major ,
.Ar unit ,
.Ar subunit
.Sm on
.Xc
A device with
.Ar major ,
.Ar unit ,
and
.Ar subunit
fields, for an operating system specified with
.Ar format .
(Currently this is only supported by the
.Sy bsdos
format.)
.It Ar number
Opaque number (as stored on the file system).
.El
.Pp
The following values for
.Ar format
are recognized:
.Sy native ,
.Sy 386bsd ,
.Sy 4bsd ,
.Sy bsdos ,
.Sy freebsd ,
.Sy hpux ,
.Sy isc ,
.Sy linux ,
.Sy netbsd ,
.Sy osf1 ,
.Sy sco ,
.Sy solaris ,
.Sy sunos ,
.Sy svr3 ,
.Sy svr4 ,
and
.Sy ultrix .
.Pp
See
.Xr mknod 8
for more details.
.It Sy flags
The file flags as a symbolic name. See
.Xr chflags 1
for information on these names. If no flags are to be set the string
.Ql none
may be used to override the current default.
Note that the schg and sappnd flags are treated specially (see the
.Fl i
and
.Fl m
options).
.It Sy ignore
Ignore any file hierarchy below this file.
.It Sy gid
The file group as a numeric value.
.It Sy gname
The file group as a symbolic name.
.It Sy link
The file the symbolic link is expected to reference.
.It Sy md5
The
.Tn MD5
cryptographic message digest of the file.
.It Sy md5digest
Synonym for
.Sy md5 .
.It Sy mode
The current file's permissions as a numeric (octal) or symbolic
value.
.It Sy nlink
The number of hard links the file is expected to have.
.It Sy optional
The file is optional; don't complain about the file if it's
not in the file hierarchy.
.It Sy rmd160
The
.Tn RMD-160
cryptographic message digest of the file.
.It Sy rmd160digest
Synonym for
.Sy rmd160 .
.It Sy sha1
The
.Tn SHA-1
cryptographic message digest of the file.
.It Sy sha1digest
Synonym for
.Sy sha1 .
.It Sy size
The size, in bytes, of the file.
.It Sy tags
Comma delimited tags to be matched with
.Fl E
and
.Fl I .
These may be specified without leading or trailing commas, but will be
stored internally with them.
.It Sy time
The last modification time of the file.
.It Sy type
The type of the file; may be set to any one of the following:
.Pp
.Bl -tag -width Sy -compact
.It Sy block
block special device
.It Sy char
character special device
.It Sy dir
directory
.It Sy fifo
fifo
.It Sy file
regular file
.It Sy link
symbolic link
.It Sy socket
socket
.El
.It Sy uid
The file owner as a numeric value.
.It Sy uname
The file owner as a symbolic name.
.El
.Pp
The default set of keywords are
.Sy flags ,
.Sy gid ,
.Sy link ,
.Sy mode ,
.Sy nlink ,
.Sy size ,
.Sy time ,
.Sy type ,
and
.Sy uid .
.Pp
There are four types of lines in a specification:
.Pp
.Bl -enum
.It
Set global values for a keyword.
This consists of the string
.Ql /set
followed by whitespace, followed by sets of keyword/value
pairs, separated by whitespace.
Keyword/value pairs consist of a keyword, followed by an equals sign
.Pq Ql = ,
followed by a value, without whitespace characters.
Once a keyword has been set, its value remains unchanged until either
reset or unset.
.It
Unset global values for a keyword.
This consists of the string
.Ql /unset ,
followed by whitespace, followed by one or more keywords,
separated by whitespace.
If
.Ql all
is specified, unset all of the keywords.
.It
A file specification, consisting of a path name, followed by whitespace,
followed by zero or more whitespace separated keyword/value pairs.
.Pp
The path name may be preceded by whitespace characters.
The path name may contain any of the standard path name matching
characters
.Po
.Ql [ ,
.Ql \] ,
.Ql ?
or
.Ql *
.Pc ,
in which case files
in the hierarchy will be associated with the first pattern that
they match.
.Nm
uses
.Xr strsvis 3
(in VIS_CSTYLE format) to encode path names containing
non-printable characters. Whitespace characters are encoded as
.Ql \es
(space),
.Ql \et
(tab), and
.Ql \en
(new line).
.Ql #
characters in path names are escaped by a preceding backslash
.Ql \e
to distinguish them from comments.
.Pp
Each of the keyword/value pairs consist of a keyword, followed by an
equals sign
.Pq Ql = ,
followed by the keyword's value, without
whitespace characters.
These values override, without changing, the global value of the
corresponding keyword.
.Pp
The first path name entry listed must be a directory named
.Ql \&. ,
as this ensures that intermixing full and relative path names will
work consistently and correctly.
Multiple entries for a directory named
.Ql \&.
are permitted; the settings for the last such entry override those
of the existing entry.
.Pp
A path name that contains a slash
.Pq Ql /
that is not the first character will be treated as a full path
(relative to the root of the tree).
All parent directories referenced in the path name must exist.
The current directory path used by relative path names will be updated
appropriately.
Multiple entries for the same full path are permitted if the types
are the same;
in this case the settings for the last entry take precedence.
.Pp
A path name that does not contain a slash will be treated as a relative path.
Specifying a directory will cause subsequent files to be searched
for in that directory hierarchy.
.It
A line containing only the string
.Ql \&..
which causes the current directory path (used by relative paths)
to ascend one level.
.El
.Pp
Empty lines and lines whose first non-whitespace character is a hash
mark
.Pq Ql #
are ignored.
.Pp
The
.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 FILES
.Bl -tag -width /etc/mtree -compact
.It Pa /etc/mtree
system specification directory
.El
.Sh EXAMPLES
To detect system binaries that have been
.Dq trojan horsed ,
it is recommended that
.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
.Fl s
option should not be an obvious value and the final checksum should not be
stored on-line under any circumstances!
Then, periodically,
.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
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.
.Pp
The
.Fl d
and
.Fl u
options can be used in combination to create directory hierarchies
for distributions and other such things.
.Sh SEE ALSO
.Xr chflags 1 ,
.Xr chgrp 1 ,
.Xr chmod 1 ,
.Xr cksum 1 ,
.Xr md5 1 ,
.Xr stat 2 ,
.Xr fnmatch 3 ,
.Xr fts 3 ,
.Xr strsvis 3 ,
.Xr chown 8 ,
.Xr mknod 8
.Sh HISTORY
The
.Nm
utility appeared in
.Bx 4.3 Reno .
The
.Sy optional
keyword appeared in
.Nx 1.2 .
The
.Fl U
flag appeared in
.Nx 1.3 .
The
.Sy flags
and
.Sy md5
keywords, and
.Fl i
and
.Fl m
flags
appeared in
.Nx 1.4 .
The
.Sy device ,
.Sy rmd160 ,
.Sy sha1 ,
.Sy tags ,
and
.Sy all
keywords,
.Fl D ,
.Fl E ,
.Fl I ,
.Fl l ,
.Fl L ,
.Fl N ,
.Fl P ,
.Fl R ,
.Fl W ,
and
.Fl X
flags, and support for full paths appeared in
.Nx 1.6 .

View file

@ -0,0 +1,232 @@
/* $NetBSD: mtree.c,v 1.1.1.1 2003/03/31 08:51:12 grant Exp $ */
/*-
* Copyright (c) 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "nbcompat.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if defined(__COPYRIGHT) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1989, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: mtree.c,v 1.1.1.1 2003/03/31 08:51:12 grant Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
int ftsoptions = FTS_PHYSICAL;
int cflag, Cflag, dflag, Dflag, eflag, iflag, lflag, mflag,
rflag, sflag, tflag, uflag, Uflag;
char fullpath[MAXPATHLEN];
int main(int, char **);
static void usage(void);
int
main(int argc, char **argv)
{
int ch, status;
char *dir, *p;
setprogname(argv[0]);
dir = NULL;
init_excludes();
while ((ch = getopt(argc, argv, "cCdDeE:f:I:ik:K:lLmN:p:PrR:s:tuUWxX:"))
!= -1) {
switch((char)ch) {
case 'c':
cflag = 1;
break;
case 'C':
Cflag = 1;
break;
case 'd':
dflag = 1;
break;
case 'D':
Dflag = 1;
break;
case 'E':
parsetags(&excludetags, optarg);
break;
case 'e':
eflag = 1;
break;
case 'f':
if (!(freopen(optarg, "r", stdin)))
mtree_err("%s: %s", optarg, strerror(errno));
break;
case 'i':
iflag = 1;
break;
case 'I':
parsetags(&includetags, optarg);
break;
case 'k':
keys = F_TYPE;
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys |= parsekey(p, NULL);
break;
case 'K':
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys |= parsekey(p, NULL);
break;
case 'l':
lflag = 1;
break;
case 'L':
ftsoptions &= ~FTS_PHYSICAL;
ftsoptions |= FTS_LOGICAL;
break;
case 'm':
mflag = 1;
break;
case 'N':
if (! setup_getid(optarg))
mtree_err(
"Unable to use user and group databases in `%s'",
optarg);
break;
case 'p':
dir = optarg;
break;
case 'P':
ftsoptions &= ~FTS_LOGICAL;
ftsoptions |= FTS_PHYSICAL;
break;
case 'r':
rflag = 1;
break;
case 'R':
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys &= ~parsekey(p, NULL);
break;
case 's':
sflag = 1;
crc_total = ~strtol(optarg, &p, 0);
if (*p)
mtree_err("illegal seed value -- %s", optarg);
break;
case 't':
tflag = 1;
break;
case 'u':
uflag = 1;
break;
case 'U':
Uflag = uflag = 1;
break;
case 'W':
Wflag = 1;
break;
case 'x':
ftsoptions |= FTS_XDEV;
break;
case 'X':
read_excludes_file(optarg);
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc)
usage();
if (dir && chdir(dir))
mtree_err("%s: %s", dir, strerror(errno));
if ((cflag || sflag) && !getcwd(fullpath, sizeof(fullpath)))
mtree_err("%s", strerror(errno));
if ((cflag && Cflag) || (cflag && Dflag) || (Cflag && Dflag))
mtree_err("-c, -C and -D flags are mutually exclusive");
if (iflag && mflag)
mtree_err("-i and -m flags are mutually exclusive");
if (lflag && uflag)
mtree_err("-l and -u flags are mutually exclusive");
if (cflag) {
cwalk();
exit(0);
}
if (Cflag || Dflag) {
dump_nodes("", spec(stdin), Dflag);
exit(0);
}
status = verify();
if (Uflag & (status == MISMATCHEXIT))
status = 0;
exit(status);
}
static void
usage(void)
{
fprintf(stderr,
"usage: %s [-cCdDelLPruUWx] [-i|-m] [-f spec] [-k key]\n"
"\t\t[-K addkey] [-R removekey] [-I inctags] [-E exctags]\n"
"\t\t[-N userdbdir] [-X exclude-file] [-p path] [-s seed]\n",
getprogname());
exit(1);
}

View file

@ -0,0 +1,316 @@
MTREE(8) NetBSD System Manager's Manual MTREE(8)
NNAAMMEE
mmttrreeee - map a directory hierarchy
SSYYNNOOPPSSIISS
mmttrreeee [--ccCCddDDeellLLPPrruuUUWWxx] [--ii | --mm] [--ff _s_p_e_c] [--pp _p_a_t_h] [--kk _k_e_y_w_o_r_d_s]
[--KK _k_e_y_w_o_r_d_s] [--RR _k_e_y_w_o_r_d_s] [--EE _t_a_g_s] [--II _t_a_g_s] [--NN _d_b_d_i_r] [--ss _s_e_e_d]
[--XX _e_x_c_l_u_d_e_-_f_i_l_e]
DDEESSCCRRIIPPTTIIOONN
The mmttrreeee utility compares the file hierarchy rooted in the current di-
rectory against a specification read from the standard input. Messages
are written to the standard output for any files whose characteristics do
not match the specification, or which are missing from either the file
hierarchy or the specification.
The options are as follows:
--cc Print a specification for the file hierarchy to the standard out-
put.
--dd Ignore everything except directory type files.
--CC Print (`dump') the specification as provided by --ff _s_p_e_c in a format
that's easier to parse with various tools. The full path name is
always printed as the first field, and --kk, --KK, and --RR can be used
to control which other keywords are printed, and --EE and --II can be
used to control which files are printed.
--DD As per --CC, except that the path name is always printed as the last
field instead of the first.
--EE _t_a_g_s
Add the comma separated tags to the ``exclusion'' list. Non-direc-
tories with tags which are in the exclusion list are not printed
with --DD.
--ee Don't complain about files that are in the file hierarchy, but not
in the specification.
--ff _s_p_e_c
Read the specification from _f_i_l_e, instead of from the standard in-
put.
--II _t_a_g_s
Add the comma separated tags to the ``inclusion'' list. Non-direc-
tories with tags which are in the inclusion list are printed with
--DD. If no inclusion list is provided, the default is to display all
files.
--ii If specified, set the schg and/or sappnd flags.
--KK _k_e_y_w_o_r_d_s
Add the specified (whitespace or comma separated) keywords to the
current set of keywords. If `all' is specified, add all of the
other keywords.
--kk _k_e_y_w_o_r_d_s
Use the ttyyppee keyword plus the specified (whitespace or comma sepa-
rated) keywords instead of the current set of keywords. If `all'
is specified, use all of the other keywords.
--ll Do ``loose'' permissions checks, in which more stringent permis-
sions will match less stringent ones. For example, a file marked
mode 0444 will pass a check for mode 0644. ``Loose'' checks apply
only to read, write and execute permissions -- in particular, if
other bits like the sticky bit or suid/sgid bits are set either in
the specification or the file, exact checking will be performed.
This flag may not be set at the same time as the --uu or --UU flags.
--LL Follow all symbolic links in the file hierarchy.
--mm If the schg and/or sappnd flags are specified, reset these flags.
Note that this is only possible with securelevel less than 1 (i. e.
in single user mode or while the system is running in insecure
mode). See init(8) for information on security levels.
--NN _d_b_d_i_r
Use the user database text file _m_a_s_t_e_r_._p_a_s_s_w_d and group database
text file _g_r_o_u_p from _d_b_d_i_r, rather than using the results from the
system's getpwnam(3) and getgrnam(3) (and related) library calls.
--pp _p_a_t_h
Use the file hierarchy rooted in _p_a_t_h, instead of the current di-
rectory.
--PP Don't follow symbolic links in the file hierarchy, instead consider
the symbolic link itself in any comparisons. This is the default.
--rr Remove any files in the file hierarchy that are not described in
the specification.
--RR _k_e_y_w_o_r_d_s
Remove the specified (whitespace or comma separated) keywords from
the current set of keywords. If `all' is specified, remove all of
the other keywords.
--ss _s_e_e_d
Display a single checksum to the standard error output that repre-
sents all of the files for which the keyword cckkssuumm was specified.
The checksum is seeded with the specified value.
--uu Modify the owner, group, permissions, and flags of existing files,
the device type of devices, and symbolic link targets, to match the
specification. Create any missing directories, devices or symbolic
links. User, group, and permissions must all be specified for
missing directories to be created. Note that unless the --ii option
is given, the schg and sappnd flags will not be set, even if speci-
fied. If --mm is given, these flags will be reset. Exit with a sta-
tus of 0 on success, 2 if the file hierarchy did not match the
specification, and 1 if any other error occurred.
--UU Same as --uu except that a mismatch is not considered to be an error
if it was corrected.
--WW Don't attempt to set various file attributes such as the ownership,
mode, flags, or time when creating new directories or changing ex-
isting entries. This option will be most useful when used in con-
junction with --uu or --UU.
--xx Don't descend below mount points in the file hierarchy.
--XX _e_x_c_l_u_d_e_-_f_i_l_e
The specified file contains fnmatch(3) patterns matching files to
be excluded from the specification, one to a line. If the pattern
contains a `/' character, it will be matched against entire path-
names (relative to the starting directory); otherwise, it will be
matched against basenames only. Comments are permitted in the
_e_x_c_l_u_d_e_-_l_i_s_t file.
Specifications are mostly composed of ``keywords'', i.e. strings that
that specify values relating to files. No keywords have default values,
and if a keyword has no value set, no checks based on it are performed.
Currently supported keywords are as follows:
cckkssuumm The checksum of the file using the default algorithm specified by
the cksum(1) utility.
ddeevviiccee The device number to use for bblloocckk or cchhaarr file types. The argu-
ment must be one of the following forms:
_f_o_r_m_a_t,_m_a_j_o_r,_m_i_n_o_r
A device with _m_a_j_o_r and _m_i_n_o_r fields, for an operating sys-
tem specified with _f_o_r_m_a_t. See below for valid formats.
_f_o_r_m_a_t,_m_a_j_o_r,_u_n_i_t,_s_u_b_u_n_i_t
A device with _m_a_j_o_r, _u_n_i_t, and _s_u_b_u_n_i_t fields, for an oper-
ating system specified with _f_o_r_m_a_t. (Currently this is on-
ly supported by the bbssddooss format.)
_n_u_m_b_e_r
Opaque number (as stored on the file system).
The following values for _f_o_r_m_a_t are recognized: nnaattiivvee, 338866bbssdd,
44bbssdd, bbssddooss, ffrreeeebbssdd, hhppuuxx, iisscc, lliinnuuxx, nneettbbssdd, oossff11, ssccoo,
ssoollaarriiss, ssuunnooss, ssvvrr33, ssvvrr44, and uullttrriixx.
See mknod(8) for more details.
ffllaaggss The file flags as a symbolic name. See chflags(1) for informa-
tion on these names. If no flags are to be set the string `none'
may be used to override the current default. Note that the schg
and sappnd flags are treated specially (see the --ii and --mm op-
tions).
iiggnnoorree Ignore any file hierarchy below this file.
ggiidd The file group as a numeric value.
ggnnaammee The file group as a symbolic name.
lliinnkk The file the symbolic link is expected to reference.
mmdd55 The MD5 cryptographic message digest of the file.
mmdd55ddiiggeesstt
Synonym for mmdd55.
mmooddee The current file's permissions as a numeric (octal) or symbolic
value.
nnlliinnkk The number of hard links the file is expected to have.
ooppttiioonnaall
The file is optional; don't complain about the file if it's not
in the file hierarchy.
rrmmdd116600 The RMD-160 cryptographic message digest of the file.
rrmmdd116600ddiiggeesstt
Synonym for rrmmdd116600.
sshhaa11 The SHA-1 cryptographic message digest of the file.
sshhaa11ddiiggeesstt
Synonym for sshhaa11.
ssiizzee The size, in bytes, of the file.
ttaaggss Comma delimited tags to be matched with --EE and --II. These may be
specified without leading or trailing commas, but will be stored
internally with them.
ttiimmee The last modification time of the file.
ttyyppee The type of the file; may be set to any one of the following:
bblloocckk block special device
cchhaarr character special device
ddiirr directory
ffiiffoo fifo
ffiillee regular file
lliinnkk symbolic link
ssoocckkeett socket
uuiidd The file owner as a numeric value.
uunnaammee The file owner as a symbolic name.
The default set of keywords are ffllaaggss, ggiidd, lliinnkk, mmooddee, nnlliinnkk, ssiizzee,
ttiimmee, ttyyppee, and uuiidd.
There are four types of lines in a specification:
1. Set global values for a keyword. This consists of the string `/set'
followed by whitespace, followed by sets of keyword/value pairs,
separated by whitespace. Keyword/value pairs consist of a keyword,
followed by an equals sign (`='), followed by a value, without
whitespace characters. Once a keyword has been set, its value re-
mains unchanged until either reset or unset.
2. Unset global values for a keyword. This consists of the string
`/unset', followed by whitespace, followed by one or more keywords,
separated by whitespace. If `all' is specified, unset all of the
keywords.
3. A file specification, consisting of a path name, followed by whites-
pace, followed by zero or more whitespace separated keyword/value
pairs.
The path name may be preceded by whitespace characters. The path
name may contain any of the standard path name matching characters
(`[', `]', `?' or `*'), in which case files in the hierarchy will be
associated with the first pattern that they match. mmttrreeee uses
strsvis(3) (in VIS_CSTYLE format) to encode path names containing
non-printable characters. Whitespace characters are encoded as `\s'
(space), `\t' (tab), and `\n' (new line). `#' characters in path
names are escaped by a preceding backslash `\' to distinguish them
from comments.
Each of the keyword/value pairs consist of a keyword, followed by an
equals sign (`='), followed by the keyword's value, without whites-
pace characters. These values override, without changing, the glob-
al value of the corresponding keyword.
The first path name entry listed must be a directory named `.', as
this ensures that intermixing full and relative path names will work
consistently and correctly. Multiple entries for a directory named
`.' are permitted; the settings for the last such entry override
those of the existing entry.
A path name that contains a slash (`/') that is not the first char-
acter will be treated as a full path (relative to the root of the
tree). All parent directories referenced in the path name must ex-
ist. The current directory path used by relative path names will be
updated appropriately. Multiple entries for the same full path are
permitted if the types are the same; in this case the settings for
the last entry take precedence.
A path name that does not contain a slash will be treated as a rela-
tive path. Specifying a directory will cause subsequent files to be
searched for in that directory hierarchy.
4. A line containing only the string `..' which causes the current di-
rectory path (used by relative paths) to ascend one level.
Empty lines and lines whose first non-whitespace character is a hash mark
(`#') are ignored.
The mmttrreeee utility exits with a status of 0 on success, 1 if any error oc-
curred, and 2 if the file hierarchy did not match the specification.
FFIILLEESS
/etc/mtree system specification directory
EEXXAAMMPPLLEESS
To detect system binaries that have been ``trojan horsed'', it is recom-
mended that mmttrreeee 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 --ss option should not be an obvious value and the final checksum
should not be stored on-line under any circumstances! Then, periodical-
ly, mmttrreeee 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 to conform to their modi-
fied 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 bina-
ries have actually been modified.
The --dd and --uu options can be used in combination to create directory hi-
erarchies for distributions and other such things.
SSEEEE AALLSSOO
chflags(1), chgrp(1), chmod(1), cksum(1), md5(1), stat(2), fnmatch(3),
fts(3), strsvis(3), chown(8), mknod(8)
HHIISSTTOORRYY
The mmttrreeee utility appeared in 4.3BSD-Reno. The ooppttiioonnaall keyword appeared
in NetBSD 1.2. The --UU flag appeared in NetBSD 1.3. The ffllaaggss and mmdd55
keywords, and --ii and --mm flags appeared in NetBSD 1.4. The ddeevviiccee,
rrmmdd116600, sshhaa11, ttaaggss, and aallll keywords, --DD, --EE, --II, --ll, --LL, --NN, --PP, --RR, --WW,
and --XX flags, and support for full paths appeared in NetBSD 1.6.
NetBSD 1.6 December 22, 2002 5

View file

@ -0,0 +1,296 @@
/* $NetBSD: verify.c,v 1.1.1.1 2003/03/31 08:51:13 grant Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "nbcompat.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: verify.c,v 1.1.1.1 2003/03/31 08:51:13 grant Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#if !HAVE_CONFIG_H
#include <dirent.h>
#endif
#include <errno.h>
#include <fnmatch.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
static NODE *root;
static char path[MAXPATHLEN];
static void miss(NODE *, char *);
static int vwalk(void);
int
verify(void)
{
int rval;
root = spec(stdin);
rval = vwalk();
miss(root, path);
return (rval);
}
static int
vwalk(void)
{
FTS *t;
FTSENT *p;
NODE *ep, *level;
int specdepth, rval;
char *argv[2];
char dot[] = ".";
argv[0] = dot;
argv[1] = NULL;
if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
mtree_err("fts_open: %s", strerror(errno));
level = root;
specdepth = rval = 0;
while ((p = fts_read(t)) != NULL) {
if (check_excludes(p->fts_name, p->fts_path)) {
fts_set(t, p, FTS_SKIP);
continue;
}
switch(p->fts_info) {
case FTS_D:
case FTS_SL:
break;
case FTS_DP:
if (specdepth > p->fts_level) {
for (level = level->parent; level->prev;
level = level->prev)
continue;
--specdepth;
}
continue;
case FTS_DNR:
case FTS_ERR:
case FTS_NS:
warnx("%s: %s", 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)) ||
!strcmp(ep->name, p->fts_name)) {
ep->flags |= F_VISIT;
if (compare(ep, p))
rval = MISMATCHEXIT;
if (!(ep->flags & F_IGN) &&
ep->child && ep->type == F_DIR &&
p->fts_info == FTS_D) {
level = ep->child;
++specdepth;
} else
fts_set(t, p, FTS_SKIP);
break;
}
if (ep)
continue;
extra:
if (!eflag) {
printf("extra: %s", RP(p));
if (rflag) {
if ((S_ISDIR(p->fts_statp->st_mode)
? rmdir : unlink)(p->fts_accpath)) {
printf(", not removed: %s",
strerror(errno));
} else
printf(", removed");
}
putchar('\n');
}
fts_set(t, p, FTS_SKIP);
}
fts_close(t);
if (sflag)
warnx("%s checksum: %u", fullpath, crc_total);
return (rval);
}
static void
miss(NODE *p, char *tail)
{
int create;
char *tp;
const char *type;
u_int32_t flags;
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;
strcpy(tail, p->name);
if (!(p->flags & F_VISIT))
printf("missing: %s", path);
switch (p->type) {
case F_BLOCK:
case F_CHAR:
type = "device";
break;
case F_DIR:
type = "directory";
break;
case F_LINK:
type = "symlink";
break;
default:
putchar('\n');
continue;
}
create = 0;
if (!(p->flags & F_VISIT) && uflag) {
if (Wflag || p->type == F_LINK)
goto createit;
if (!(p->flags & (F_UID | F_UNAME)))
printf(
" (%s not created: user not specified)", type);
else if (!(p->flags & (F_GID | F_GNAME)))
printf(
" (%s not created: group not specified)", type);
else if (!(p->flags & F_MODE))
printf(
" (%s not created: mode not specified)", type);
else
createit:
switch (p->type) {
case F_BLOCK:
case F_CHAR:
if (Wflag)
continue;
if (!(p->flags & F_DEV))
printf(
" (%s not created: device not specified)",
type);
else if (mknod(path,
p->st_mode | nodetoino(p->type),
p->st_rdev) == -1)
printf(" (%s not created: %s)\n",
type, strerror(errno));
else
create = 1;
break;
case F_LINK:
if (!(p->flags & F_SLINK))
printf(
" (%s not created: link not specified)\n",
type);
else if (symlink(p->slink, path))
printf(
" (%s not created: %s)\n",
type, strerror(errno));
else
create = 1;
break;
case F_DIR:
if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO))
printf(" (not created: %s)",
strerror(errno));
else
create = 1;
break;
default:
mtree_err("can't create create %s",
nodetype(p->type));
}
}
if (create)
printf(" (created)");
if (p->type == F_DIR) {
if (!(p->flags & F_VISIT))
putchar('\n');
for (tp = tail; *tp; ++tp)
continue;
*tp = '/';
miss(p->child, tp + 1);
*tp = '\0';
} else
putchar('\n');
if (!create || Wflag)
continue;
if ((p->flags & (F_UID | F_UNAME)) &&
(p->flags & (F_GID | F_GNAME)) &&
(lchown(path, p->st_uid, p->st_gid))) {
printf("%s: user/group/mode not modified: %s\n",
path, strerror(errno));
printf("%s: warning: file mode %snot set\n", path,
(p->flags & F_FLAGS) ? "and file flags " : "");
continue;
}
if (p->flags & F_MODE) {
if (lchmod(path, p->st_mode))
printf("%s: permissions not set: %s\n",
path, strerror(errno));
}
#if HAVE_STRUCT_STAT_ST_FLAGS
if ((p->flags & F_FLAGS) && p->st_flags) {
if (iflag)
flags = p->st_flags;
else
flags = p->st_flags & ~SP_FLGS;
if (lchflags(path, flags))
printf("%s: file flags not set: %s\n",
path, strerror(errno));
}
#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
}
}