2004-12-02 02:27:36 +03:00
|
|
|
/* $NetBSD: spec.c,v 1.59 2004/12/01 23:27:36 lukem Exp $ */
|
1995-03-08 00:12:04 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1995-03-07 18:28:32 +03:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-10-05 19:32:57 +04:00
|
|
|
/*-
|
2004-07-22 20:51:45 +04:00
|
|
|
* Copyright (c) 2001-2004 The NetBSD Foundation, Inc.
|
2001-10-05 19:32:57 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Luke Mewburn of Wasabi Systems.
|
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
2002-02-01 01:43:33 +03:00
|
|
|
#if defined(__RCSID) && !defined(lint)
|
1995-03-08 00:12:04 +03:00
|
|
|
#if 0
|
1997-10-17 09:24:29 +04:00
|
|
|
static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95";
|
1995-03-08 00:12:04 +03:00
|
|
|
#else
|
2004-12-02 02:27:36 +03:00
|
|
|
__RCSID("$NetBSD: spec.c,v 1.59 2004/12/01 23:27:36 lukem Exp $");
|
1995-03-08 00:12:04 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2001-10-01 06:30:40 +04:00
|
|
|
#include <sys/param.h>
|
1993-11-02 10:51:06 +03:00
|
|
|
#include <sys/stat.h>
|
2001-03-09 06:09:45 +03:00
|
|
|
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <grp.h>
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <pwd.h>
|
1993-11-02 10:51:06 +03:00
|
|
|
#include <stdio.h>
|
2001-10-22 11:07:46 +04:00
|
|
|
#include <stdlib.h>
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2002-12-23 07:40:19 +03:00
|
|
|
#include <vis.h>
|
2003-11-17 03:02:33 +03:00
|
|
|
#include <util.h>
|
1997-10-17 15:46:30 +04:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
#include "extern.h"
|
2001-10-09 08:50:00 +04:00
|
|
|
#include "pack_dev.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-11-03 15:51:40 +03:00
|
|
|
size_t mtree_lineno; /* Current spec line number */
|
2004-07-22 20:51:45 +04:00
|
|
|
int mtree_Mflag; /* Merge duplicate entries */
|
|
|
|
int mtree_Wflag; /* Don't "whack" permissions */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-02-11 15:43:55 +03:00
|
|
|
static dev_t parsedev(char *);
|
|
|
|
static void replacenode(NODE *, NODE *);
|
|
|
|
static void set(char *, NODE *);
|
|
|
|
static void unset(char *, NODE *);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2004-07-22 20:51:45 +04:00
|
|
|
#define REPLACEPTR(x,v) do { if ((x)) free((x)); (x) = (v); } while (0)
|
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
NODE *
|
2001-10-22 11:07:46 +04:00
|
|
|
spec(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-10-05 19:32:57 +04:00
|
|
|
NODE *centry, *last, *pathparent, *cur;
|
2001-10-17 05:19:17 +04:00
|
|
|
char *p, *e, *next;
|
1993-11-02 10:51:06 +03:00
|
|
|
NODE ginfo, *root;
|
2003-09-19 10:11:35 +04:00
|
|
|
char *buf, *tname, *ntname;
|
2001-10-05 19:32:57 +04:00
|
|
|
size_t tnamelen, plen;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
root = NULL;
|
1997-10-17 15:46:30 +04:00
|
|
|
centry = last = NULL;
|
2001-10-05 19:32:57 +04:00
|
|
|
tname = NULL;
|
|
|
|
tnamelen = 0;
|
1997-10-17 15:46:30 +04:00
|
|
|
memset(&ginfo, 0, sizeof(ginfo));
|
2001-11-03 15:51:40 +03:00
|
|
|
for (mtree_lineno = 0;
|
|
|
|
(buf = fparseln(fp, NULL, &mtree_lineno, NULL,
|
2001-09-10 07:22:24 +04:00
|
|
|
FPARSELN_UNESCCOMM | FPARSELN_UNESCCONT | FPARSELN_UNESCESC));
|
|
|
|
free(buf)) {
|
1993-11-02 10:51:06 +03:00
|
|
|
/* Skip leading whitespace. */
|
2001-09-10 07:22:24 +04:00
|
|
|
for (p = buf; *p && isspace((unsigned char)*p); ++p)
|
|
|
|
continue;
|
1993-11-02 10:51:06 +03:00
|
|
|
|
2001-09-10 07:22:24 +04:00
|
|
|
/* If nothing but whitespace, continue. */
|
|
|
|
if (!*p)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
#ifdef DEBUG
|
User interface changes from (or inspired by) FreeBSD:
- Add -L to walk the tree `logically', by following symbolic links in
the heirarchy.
- Add -P to walk the tree `physically'. This is the current behaviour,
and the default.
- Add "-X excludes-file" to give mtree the ability to exclude files and
directories from its traversal. excludes-file contains fnmatch(3)
patterns to exclude from the walk.
- Add "md5digest" synonym for "md5".
- Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym.
- Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym.
- Don't try to compare() other attributes if the type doesn't match;
it's nothing but trouble, and no use anyway.
- In -c, only emit "/set" records if something has changed since the
previous one.
User interface changes by me:
- Check a device's parameters before checking uid/gid/mode.
- If updating (-u), modify the following to match the specification:
- Device type (retaining existing ownership).
- Symlink target.
Fixes from (or inspired by) FreeBSD:
- Use p->ftslevel instead of own code to keep track of the level ourself.
The previous code got majorly confused if fts(3) couldn't descend
into a subdir, resulting in leaf nodes getting attached to the wrong
directory.
XXX: This new method is much much more robust, even though it's not 100%
perfect; it might result in a couple of following entries in the spec
to be incorrectly tagged as missing.
- Pass a useful pathname to rlink(), so that logical (-L) traversal
doesn't confuse symlink checking.
- Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that
there's room for the NUL.
- Use mtree_err() and strerror(p->fts_errno) to report errors during
the fts(3) walk.
Fixes by me:
- Remove now-unused `const char *name' argument from compare().
- Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c.
- Remove trailing whitespace.
- Remove unnecessary (void) casts on functions.
- Reorder entries in the getopt() switch.
- Replace strtoq() with strtoll(), and use strtoul() appropriately.
- Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
|
|
|
fprintf(stderr, "line %lu: {%s}\n",
|
2001-11-03 15:51:40 +03:00
|
|
|
(u_long)mtree_lineno, p);
|
1993-11-02 10:51:06 +03:00
|
|
|
#endif
|
|
|
|
/* Grab file name, "$", "set", or "unset". */
|
2001-10-17 05:19:17 +04:00
|
|
|
next = buf;
|
|
|
|
while ((p = strsep(&next, " \t")) != NULL && *p == '\0')
|
|
|
|
continue;
|
|
|
|
if (p == NULL)
|
1998-10-08 06:04:55 +04:00
|
|
|
mtree_err("missing field");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-07-18 08:51:54 +04:00
|
|
|
if (p[0] == '/') {
|
|
|
|
if (strcmp(p + 1, "set") == 0)
|
2001-10-17 05:19:17 +04:00
|
|
|
set(next, &ginfo);
|
2001-07-18 08:51:54 +04:00
|
|
|
else if (strcmp(p + 1, "unset") == 0)
|
2001-10-17 05:19:17 +04:00
|
|
|
unset(next, &ginfo);
|
2001-07-18 08:51:54 +04:00
|
|
|
else
|
|
|
|
mtree_err("invalid specification `%s'", p);
|
|
|
|
continue;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-10-05 19:32:57 +04:00
|
|
|
if (strcmp(p, "..") == 0) {
|
1993-11-02 10:51:06 +03:00
|
|
|
/* Don't go up, if haven't gone down. */
|
2001-10-05 19:32:57 +04:00
|
|
|
if (root == NULL)
|
1993-11-02 10:51:06 +03:00
|
|
|
goto noparent;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (last->type != F_DIR || last->flags & F_DONE) {
|
|
|
|
if (last == root)
|
1993-11-02 10:51:06 +03:00
|
|
|
goto noparent;
|
1993-03-21 12:45:37 +03:00
|
|
|
last = last->parent;
|
|
|
|
}
|
|
|
|
last->flags |= F_DONE;
|
|
|
|
continue;
|
1993-11-02 10:51:06 +03:00
|
|
|
|
1998-10-08 06:04:55 +04:00
|
|
|
noparent: mtree_err("no parent node");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2001-10-05 19:32:57 +04:00
|
|
|
plen = strlen(p) + 1;
|
|
|
|
if (plen > tnamelen) {
|
2003-09-19 10:11:35 +04:00
|
|
|
if ((ntname = realloc(tname, plen)) == NULL)
|
2001-10-05 19:32:57 +04:00
|
|
|
mtree_err("realloc: %s", strerror(errno));
|
2003-09-19 10:11:35 +04:00
|
|
|
tname = ntname;
|
|
|
|
tnamelen = plen;
|
2001-10-05 19:32:57 +04:00
|
|
|
}
|
|
|
|
if (strunvis(tname, p) == -1)
|
|
|
|
mtree_err("strunvis failed on `%s'", p);
|
|
|
|
p = tname;
|
|
|
|
|
|
|
|
pathparent = NULL;
|
|
|
|
if (strchr(p, '/') != NULL) {
|
|
|
|
cur = root;
|
|
|
|
for (; (e = strchr(p, '/')) != NULL; p = e+1) {
|
|
|
|
if (p == e)
|
|
|
|
continue; /* handle // */
|
|
|
|
*e = '\0';
|
|
|
|
if (strcmp(p, ".") != 0) {
|
2002-02-11 15:43:55 +03:00
|
|
|
while (cur &&
|
|
|
|
strcmp(cur->name, p) != 0) {
|
2001-10-05 19:32:57 +04:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur == NULL || cur->type != F_DIR) {
|
|
|
|
mtree_err("%s: %s", tname,
|
|
|
|
strerror(ENOENT));
|
|
|
|
}
|
|
|
|
*e = '/';
|
|
|
|
pathparent = cur;
|
|
|
|
cur = cur->child;
|
|
|
|
}
|
|
|
|
if (*p == '\0')
|
|
|
|
mtree_err("%s: empty leaf element", tname);
|
|
|
|
}
|
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL)
|
1998-10-08 06:04:55 +04:00
|
|
|
mtree_err("%s", strerror(errno));
|
1993-03-21 12:45:37 +03:00
|
|
|
*centry = ginfo;
|
2001-11-03 15:51:40 +03:00
|
|
|
centry->lineno = mtree_lineno;
|
2001-10-05 19:32:57 +04:00
|
|
|
strcpy(centry->name, p);
|
1993-03-21 12:45:37 +03:00
|
|
|
#define MAGIC "?*["
|
|
|
|
if (strpbrk(p, MAGIC))
|
|
|
|
centry->flags |= F_MAGIC;
|
2001-10-17 05:19:17 +04:00
|
|
|
set(next, centry);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-10-05 19:32:57 +04:00
|
|
|
if (root == NULL) {
|
2002-02-11 15:43:55 +03:00
|
|
|
/*
|
|
|
|
* empty tree
|
|
|
|
*/
|
|
|
|
if (strcmp(centry->name, ".") != 0 ||
|
|
|
|
centry->type != F_DIR)
|
2001-10-22 11:07:46 +04:00
|
|
|
mtree_err(
|
|
|
|
"root node must be the directory `.'");
|
1993-03-21 12:45:37 +03:00
|
|
|
last = root = centry;
|
|
|
|
root->parent = root;
|
2001-10-05 19:32:57 +04:00
|
|
|
} else if (pathparent != NULL) {
|
2002-02-11 15:43:55 +03:00
|
|
|
/*
|
|
|
|
* full path entry
|
|
|
|
*/
|
2001-10-05 19:32:57 +04:00
|
|
|
centry->parent = pathparent;
|
|
|
|
cur = pathparent->child;
|
2002-02-11 15:43:55 +03:00
|
|
|
if (cur == NULL) {
|
2001-10-05 19:32:57 +04:00
|
|
|
pathparent->child = centry;
|
2002-02-11 15:43:55 +03:00
|
|
|
last = centry;
|
|
|
|
} else {
|
|
|
|
for (; cur != NULL; cur = cur->next) {
|
|
|
|
if (strcmp(cur->name, centry->name)
|
|
|
|
== 0) {
|
|
|
|
/* existing entry; replace */
|
|
|
|
replacenode(cur, centry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cur->next == NULL) {
|
|
|
|
/* last entry; add new */
|
|
|
|
cur->next = centry;
|
|
|
|
centry->prev = cur;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last = cur;
|
|
|
|
while (last->next != NULL)
|
|
|
|
last = last->next;
|
2001-10-05 19:32:57 +04:00
|
|
|
}
|
2002-02-11 15:43:55 +03:00
|
|
|
} else if (strcmp(centry->name, ".") == 0) {
|
|
|
|
/*
|
|
|
|
* duplicate "." entry; always replace
|
|
|
|
*/
|
|
|
|
replacenode(root, centry);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (last->type == F_DIR && !(last->flags & F_DONE)) {
|
2002-02-11 15:43:55 +03:00
|
|
|
/*
|
|
|
|
* new relative child
|
|
|
|
* (no duplicate check)
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
centry->parent = last;
|
|
|
|
last = last->child = centry;
|
|
|
|
} else {
|
2002-02-11 15:43:55 +03:00
|
|
|
/*
|
|
|
|
* relative entry, up one directory
|
|
|
|
* (no duplicate check)
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
centry->parent = last->parent;
|
|
|
|
centry->prev = last;
|
|
|
|
last = last->next = centry;
|
|
|
|
}
|
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
return (root);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2004-07-22 20:51:45 +04:00
|
|
|
void
|
|
|
|
free_nodes(NODE *root)
|
|
|
|
{
|
|
|
|
NODE *cur, *next;
|
|
|
|
|
|
|
|
if (root == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
next = NULL;
|
|
|
|
for (cur = root; cur != NULL; cur = next) {
|
|
|
|
next = cur->next;
|
|
|
|
free_nodes(cur->child);
|
|
|
|
REPLACEPTR(cur->slink, NULL);
|
|
|
|
REPLACEPTR(cur->md5digest, NULL);
|
|
|
|
REPLACEPTR(cur->rmd160digest, NULL);
|
|
|
|
REPLACEPTR(cur->sha1digest, NULL);
|
|
|
|
REPLACEPTR(cur->tags, NULL);
|
|
|
|
REPLACEPTR(cur, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-01 06:30:40 +04:00
|
|
|
/*
|
|
|
|
* dump_nodes --
|
2002-12-23 07:40:19 +03:00
|
|
|
* dump the NODEs from `cur', based in the directory `dir'.
|
|
|
|
* if pathlast is none zero, print the path last, otherwise print
|
|
|
|
* it first.
|
2001-10-01 06:30:40 +04:00
|
|
|
*/
|
|
|
|
void
|
2002-12-23 07:40:19 +03:00
|
|
|
dump_nodes(const char *dir, NODE *root, int pathlast)
|
2001-10-01 06:30:40 +04:00
|
|
|
{
|
|
|
|
NODE *cur;
|
2001-11-09 09:55:56 +03:00
|
|
|
char path[MAXPATHLEN];
|
2001-10-05 17:14:56 +04:00
|
|
|
const char *name;
|
2001-10-01 06:30:40 +04:00
|
|
|
|
|
|
|
for (cur = root; cur != NULL; cur = cur->next) {
|
2001-10-05 05:03:24 +04:00
|
|
|
if (cur->type != F_DIR && !matchtags(cur))
|
|
|
|
continue;
|
2001-10-04 08:51:27 +04:00
|
|
|
|
2001-10-01 06:30:40 +04:00
|
|
|
if (snprintf(path, sizeof(path), "%s%s%s",
|
|
|
|
dir, *dir ? "/" : "", cur->name)
|
|
|
|
>= sizeof(path))
|
|
|
|
mtree_err("Pathname too long.");
|
2001-10-05 17:14:56 +04:00
|
|
|
|
2002-12-23 07:40:19 +03:00
|
|
|
if (!pathlast)
|
|
|
|
printf("%s ", vispath(path));
|
|
|
|
|
2001-10-05 17:14:56 +04:00
|
|
|
#define MATCHFLAG(f) ((keys & (f)) && (cur->flags & (f)))
|
|
|
|
if (MATCHFLAG(F_TYPE))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("type=%s ", nodetype(cur->type));
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_UID | F_UNAME)) {
|
|
|
|
if (keys & F_UNAME &&
|
|
|
|
(name = user_from_uid(cur->st_uid, 1)) != NULL)
|
|
|
|
printf("uname=%s ", name);
|
|
|
|
else
|
|
|
|
printf("uid=%u ", cur->st_uid);
|
|
|
|
}
|
|
|
|
if (MATCHFLAG(F_GID | F_GNAME)) {
|
|
|
|
if (keys & F_GNAME &&
|
|
|
|
(name = group_from_gid(cur->st_gid, 1)) != NULL)
|
|
|
|
printf("gname=%s ", name);
|
|
|
|
else
|
|
|
|
printf("gid=%u ", cur->st_gid);
|
|
|
|
}
|
|
|
|
if (MATCHFLAG(F_MODE))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("mode=%#o ", cur->st_mode);
|
2001-10-09 08:50:00 +04:00
|
|
|
if (MATCHFLAG(F_DEV) &&
|
|
|
|
(cur->type == F_BLOCK || cur->type == F_CHAR))
|
|
|
|
printf("device=%#x ", cur->st_rdev);
|
2001-10-05 19:32:57 +04:00
|
|
|
if (MATCHFLAG(F_NLINK))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("nlink=%d ", cur->st_nlink);
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_SLINK))
|
2004-12-01 13:07:56 +03:00
|
|
|
printf("link=%s ", vispath(cur->slink));
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_SIZE))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("size=%lld ", (long long)cur->st_size);
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_TIME))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("time=%ld.%ld ", (long)cur->st_mtimespec.tv_sec,
|
|
|
|
cur->st_mtimespec.tv_nsec);
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_CKSUM))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("cksum=%lu ", cur->cksum);
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_MD5))
|
User interface changes from (or inspired by) FreeBSD:
- Add -L to walk the tree `logically', by following symbolic links in
the heirarchy.
- Add -P to walk the tree `physically'. This is the current behaviour,
and the default.
- Add "-X excludes-file" to give mtree the ability to exclude files and
directories from its traversal. excludes-file contains fnmatch(3)
patterns to exclude from the walk.
- Add "md5digest" synonym for "md5".
- Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym.
- Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym.
- Don't try to compare() other attributes if the type doesn't match;
it's nothing but trouble, and no use anyway.
- In -c, only emit "/set" records if something has changed since the
previous one.
User interface changes by me:
- Check a device's parameters before checking uid/gid/mode.
- If updating (-u), modify the following to match the specification:
- Device type (retaining existing ownership).
- Symlink target.
Fixes from (or inspired by) FreeBSD:
- Use p->ftslevel instead of own code to keep track of the level ourself.
The previous code got majorly confused if fts(3) couldn't descend
into a subdir, resulting in leaf nodes getting attached to the wrong
directory.
XXX: This new method is much much more robust, even though it's not 100%
perfect; it might result in a couple of following entries in the spec
to be incorrectly tagged as missing.
- Pass a useful pathname to rlink(), so that logical (-L) traversal
doesn't confuse symlink checking.
- Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that
there's room for the NUL.
- Use mtree_err() and strerror(p->fts_errno) to report errors during
the fts(3) walk.
Fixes by me:
- Remove now-unused `const char *name' argument from compare().
- Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c.
- Remove trailing whitespace.
- Remove unnecessary (void) casts on functions.
- Reorder entries in the getopt() switch.
- Replace strtoq() with strtoll(), and use strtoul() appropriately.
- Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
|
|
|
printf("md5=%s ", cur->md5digest);
|
|
|
|
if (MATCHFLAG(F_RMD160))
|
|
|
|
printf("rmd160=%s ", cur->rmd160digest);
|
|
|
|
if (MATCHFLAG(F_SHA1))
|
|
|
|
printf("sha1=%s ", cur->sha1digest);
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_FLAGS))
|
2001-10-01 06:30:40 +04:00
|
|
|
printf("flags=%s ",
|
|
|
|
flags_to_string(cur->st_flags, "none"));
|
2001-10-05 17:14:56 +04:00
|
|
|
if (MATCHFLAG(F_IGN))
|
|
|
|
printf("ignore ");
|
|
|
|
if (MATCHFLAG(F_OPT))
|
|
|
|
printf("optional ");
|
|
|
|
if (MATCHFLAG(F_TAGS))
|
2001-10-04 08:51:27 +04:00
|
|
|
printf("tags=%s ", cur->tags);
|
2002-12-23 07:40:19 +03:00
|
|
|
puts(pathlast ? vispath(path) : "");
|
2001-10-01 06:30:40 +04:00
|
|
|
|
|
|
|
if (cur->child)
|
2002-12-23 07:40:19 +03:00
|
|
|
dump_nodes(path, cur->child, pathlast);
|
2001-10-01 06:30:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-23 07:40:19 +03:00
|
|
|
/*
|
|
|
|
* vispath --
|
|
|
|
* strsvis(3) encodes path, which must not be longer than MAXPATHLEN
|
|
|
|
* characters long, and returns a pointer to a static buffer containing
|
|
|
|
* the result.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
vispath(const char *path)
|
|
|
|
{
|
|
|
|
const char extra[] = { ' ', '\t', '\n', '\\', '#', '\0' };
|
|
|
|
static char pathbuf[4*MAXPATHLEN + 1];
|
|
|
|
|
|
|
|
strsvis(pathbuf, path, VIS_CSTYLE, extra);
|
|
|
|
return(pathbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-09 08:50:00 +04:00
|
|
|
static dev_t
|
|
|
|
parsedev(char *arg)
|
|
|
|
{
|
|
|
|
#define MAX_PACK_ARGS 3
|
|
|
|
u_long numbers[MAX_PACK_ARGS];
|
|
|
|
char *p, *ep, *dev;
|
|
|
|
int argc;
|
|
|
|
pack_t *pack;
|
|
|
|
dev_t result;
|
2004-05-11 21:11:03 +04:00
|
|
|
const char *error = NULL;
|
2001-10-09 08:50:00 +04:00
|
|
|
|
|
|
|
if ((dev = strchr(arg, ',')) != NULL) {
|
|
|
|
*dev++='\0';
|
|
|
|
if ((pack = pack_find(arg)) == NULL)
|
|
|
|
mtree_err("unknown format `%s'", arg);
|
|
|
|
argc = 0;
|
|
|
|
while ((p = strsep(&dev, ",")) != NULL) {
|
|
|
|
if (*p == '\0')
|
|
|
|
mtree_err("missing number");
|
|
|
|
numbers[argc++] = strtoul(p, &ep, 0);
|
|
|
|
if (*ep != '\0')
|
|
|
|
mtree_err("invalid number `%s'",
|
|
|
|
p);
|
|
|
|
if (argc > MAX_PACK_ARGS)
|
|
|
|
mtree_err("too many arguments");
|
|
|
|
}
|
|
|
|
if (argc < 2)
|
|
|
|
mtree_err("not enough arguments");
|
2004-01-30 22:09:03 +03:00
|
|
|
result = (*pack)(argc, numbers, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
mtree_err(error);
|
2001-10-09 08:50:00 +04:00
|
|
|
} else {
|
|
|
|
result = (dev_t)strtoul(arg, &ep, 0);
|
|
|
|
if (*ep != '\0')
|
|
|
|
mtree_err("invalid device `%s'", arg);
|
|
|
|
}
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2002-02-11 15:43:55 +03:00
|
|
|
static void
|
|
|
|
replacenode(NODE *cur, NODE *new)
|
|
|
|
{
|
|
|
|
|
|
|
|
#define REPLACE(x) cur->x = new->x
|
2004-07-22 20:51:45 +04:00
|
|
|
#define REPLACESTR(x) REPLACEPTR(cur->x,new->x)
|
|
|
|
|
|
|
|
if (cur->type != new->type) {
|
|
|
|
if (mtree_Mflag) {
|
|
|
|
/*
|
|
|
|
* merge entries with different types; we
|
|
|
|
* don't want children retained in this case.
|
|
|
|
*/
|
|
|
|
REPLACE(type);
|
|
|
|
free_nodes(cur->child);
|
|
|
|
cur->child = NULL;
|
|
|
|
} else {
|
|
|
|
mtree_err(
|
|
|
|
"existing entry for `%s', type `%s'"
|
|
|
|
" does not match type `%s'",
|
|
|
|
cur->name, nodetype(cur->type),
|
|
|
|
nodetype(new->type));
|
|
|
|
}
|
|
|
|
}
|
2002-02-11 15:43:55 +03:00
|
|
|
|
|
|
|
REPLACE(st_size);
|
|
|
|
REPLACE(st_mtimespec);
|
|
|
|
REPLACESTR(slink);
|
2004-12-02 02:27:36 +03:00
|
|
|
if (cur->slink != NULL) {
|
|
|
|
if ((cur->slink = strdup(new->slink)) == NULL)
|
|
|
|
mtree_err("memory allocation error");
|
|
|
|
if (strunvis(cur->slink, new->slink) == -1)
|
|
|
|
mtree_err("strunvis failed on `%s'", new->slink);
|
|
|
|
free(new->slink);
|
|
|
|
}
|
2002-02-11 15:43:55 +03:00
|
|
|
REPLACE(st_uid);
|
|
|
|
REPLACE(st_gid);
|
|
|
|
REPLACE(st_mode);
|
|
|
|
REPLACE(st_rdev);
|
|
|
|
REPLACE(st_flags);
|
|
|
|
REPLACE(st_nlink);
|
|
|
|
REPLACE(cksum);
|
|
|
|
REPLACESTR(md5digest);
|
|
|
|
REPLACESTR(rmd160digest);
|
|
|
|
REPLACESTR(sha1digest);
|
|
|
|
REPLACESTR(tags);
|
|
|
|
REPLACE(lineno);
|
|
|
|
REPLACE(flags);
|
|
|
|
free(new);
|
|
|
|
}
|
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
static void
|
2001-03-09 06:09:45 +03:00
|
|
|
set(char *t, NODE *ip)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-10-09 08:50:00 +04:00
|
|
|
int type, value, len;
|
|
|
|
gid_t gid;
|
|
|
|
uid_t uid;
|
|
|
|
char *kw, *val, *md, *ep;
|
|
|
|
void *m;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-17 15:46:30 +04:00
|
|
|
val = NULL;
|
2001-10-17 05:19:17 +04:00
|
|
|
while ((kw = strsep(&t, "= \t")) != NULL) {
|
|
|
|
if (*kw == '\0')
|
|
|
|
continue;
|
2001-10-05 17:14:56 +04:00
|
|
|
if (strcmp(kw, "all") == 0)
|
|
|
|
mtree_err("invalid keyword `all'");
|
1993-11-02 10:51:06 +03:00
|
|
|
ip->flags |= type = parsekey(kw, &value);
|
2001-10-17 05:19:17 +04:00
|
|
|
if (value) {
|
|
|
|
while ((val = strsep(&t, " \t")) != NULL &&
|
|
|
|
*val == '\0')
|
|
|
|
continue;
|
|
|
|
if (val == NULL)
|
|
|
|
mtree_err("missing value");
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
switch(type) {
|
|
|
|
case F_CKSUM:
|
1993-11-02 10:51:06 +03:00
|
|
|
ip->cksum = strtoul(val, &ep, 10);
|
|
|
|
if (*ep)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid checksum `%s'", val);
|
1993-11-02 10:51:06 +03:00
|
|
|
break;
|
2001-10-09 08:50:00 +04:00
|
|
|
case F_DEV:
|
|
|
|
ip->st_rdev = parsedev(val);
|
|
|
|
break;
|
1998-10-10 11:50:27 +04:00
|
|
|
case F_FLAGS:
|
|
|
|
if (strcmp("none", val) == 0)
|
|
|
|
ip->st_flags = 0;
|
2001-10-09 08:50:00 +04:00
|
|
|
else if (string_to_flags(&val, &ip->st_flags, NULL)
|
|
|
|
!= 0)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid flag `%s'", val);
|
1998-10-10 11:50:27 +04:00
|
|
|
break;
|
1993-11-02 10:51:06 +03:00
|
|
|
case F_GID:
|
1997-04-25 09:45:24 +04:00
|
|
|
ip->st_gid = (gid_t)strtoul(val, &ep, 10);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (*ep)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid gid `%s'", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1993-11-02 10:51:06 +03:00
|
|
|
case F_GNAME:
|
2004-07-22 20:51:45 +04:00
|
|
|
if (mtree_Wflag) /* don't parse if whacking */
|
2001-11-03 15:51:40 +03:00
|
|
|
break;
|
2001-11-01 05:15:41 +03:00
|
|
|
if (gid_from_group(val, &gid) == -1)
|
2001-11-03 15:51:40 +03:00
|
|
|
mtree_err("unknown group `%s'", val);
|
2001-11-01 05:15:41 +03:00
|
|
|
ip->st_gid = gid;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case F_IGN:
|
|
|
|
/* just set flag bit */
|
|
|
|
break;
|
1998-12-06 22:07:53 +03:00
|
|
|
case F_MD5:
|
|
|
|
if (val[0]=='0' && val[1]=='x')
|
|
|
|
md=&val[2];
|
|
|
|
else
|
|
|
|
md=val;
|
User interface changes from (or inspired by) FreeBSD:
- Add -L to walk the tree `logically', by following symbolic links in
the heirarchy.
- Add -P to walk the tree `physically'. This is the current behaviour,
and the default.
- Add "-X excludes-file" to give mtree the ability to exclude files and
directories from its traversal. excludes-file contains fnmatch(3)
patterns to exclude from the walk.
- Add "md5digest" synonym for "md5".
- Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym.
- Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym.
- Don't try to compare() other attributes if the type doesn't match;
it's nothing but trouble, and no use anyway.
- In -c, only emit "/set" records if something has changed since the
previous one.
User interface changes by me:
- Check a device's parameters before checking uid/gid/mode.
- If updating (-u), modify the following to match the specification:
- Device type (retaining existing ownership).
- Symlink target.
Fixes from (or inspired by) FreeBSD:
- Use p->ftslevel instead of own code to keep track of the level ourself.
The previous code got majorly confused if fts(3) couldn't descend
into a subdir, resulting in leaf nodes getting attached to the wrong
directory.
XXX: This new method is much much more robust, even though it's not 100%
perfect; it might result in a couple of following entries in the spec
to be incorrectly tagged as missing.
- Pass a useful pathname to rlink(), so that logical (-L) traversal
doesn't confuse symlink checking.
- Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that
there's room for the NUL.
- Use mtree_err() and strerror(p->fts_errno) to report errors during
the fts(3) walk.
Fixes by me:
- Remove now-unused `const char *name' argument from compare().
- Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c.
- Remove trailing whitespace.
- Remove unnecessary (void) casts on functions.
- Reorder entries in the getopt() switch.
- Replace strtoq() with strtoll(), and use strtoul() appropriately.
- Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
|
|
|
if ((ip->md5digest = strdup(md)) == NULL)
|
1998-12-06 22:07:53 +03:00
|
|
|
mtree_err("memory allocation error");
|
|
|
|
break;
|
1993-11-02 10:51:06 +03:00
|
|
|
case F_MODE:
|
|
|
|
if ((m = setmode(val)) == NULL)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid file mode `%s'", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
ip->st_mode = getmode(m, 0);
|
1998-09-23 23:46:00 +04:00
|
|
|
free(m);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case F_NLINK:
|
1997-04-25 09:45:24 +04:00
|
|
|
ip->st_nlink = (nlink_t)strtoul(val, &ep, 10);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (*ep)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid link count `%s'", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2001-10-09 08:50:00 +04:00
|
|
|
case F_OPT:
|
|
|
|
/* just set flag bit */
|
|
|
|
break;
|
User interface changes from (or inspired by) FreeBSD:
- Add -L to walk the tree `logically', by following symbolic links in
the heirarchy.
- Add -P to walk the tree `physically'. This is the current behaviour,
and the default.
- Add "-X excludes-file" to give mtree the ability to exclude files and
directories from its traversal. excludes-file contains fnmatch(3)
patterns to exclude from the walk.
- Add "md5digest" synonym for "md5".
- Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym.
- Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym.
- Don't try to compare() other attributes if the type doesn't match;
it's nothing but trouble, and no use anyway.
- In -c, only emit "/set" records if something has changed since the
previous one.
User interface changes by me:
- Check a device's parameters before checking uid/gid/mode.
- If updating (-u), modify the following to match the specification:
- Device type (retaining existing ownership).
- Symlink target.
Fixes from (or inspired by) FreeBSD:
- Use p->ftslevel instead of own code to keep track of the level ourself.
The previous code got majorly confused if fts(3) couldn't descend
into a subdir, resulting in leaf nodes getting attached to the wrong
directory.
XXX: This new method is much much more robust, even though it's not 100%
perfect; it might result in a couple of following entries in the spec
to be incorrectly tagged as missing.
- Pass a useful pathname to rlink(), so that logical (-L) traversal
doesn't confuse symlink checking.
- Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that
there's room for the NUL.
- Use mtree_err() and strerror(p->fts_errno) to report errors during
the fts(3) walk.
Fixes by me:
- Remove now-unused `const char *name' argument from compare().
- Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c.
- Remove trailing whitespace.
- Remove unnecessary (void) casts on functions.
- Reorder entries in the getopt() switch.
- Replace strtoq() with strtoll(), and use strtoul() appropriately.
- Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
|
|
|
case F_RMD160:
|
|
|
|
if (val[0]=='0' && val[1]=='x')
|
|
|
|
md=&val[2];
|
|
|
|
else
|
|
|
|
md=val;
|
|
|
|
if ((ip->rmd160digest = strdup(md)) == NULL)
|
|
|
|
mtree_err("memory allocation error");
|
|
|
|
break;
|
|
|
|
case F_SHA1:
|
|
|
|
if (val[0]=='0' && val[1]=='x')
|
|
|
|
md=&val[2];
|
|
|
|
else
|
|
|
|
md=val;
|
|
|
|
if ((ip->sha1digest = strdup(md)) == NULL)
|
|
|
|
mtree_err("memory allocation error");
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case F_SIZE:
|
User interface changes from (or inspired by) FreeBSD:
- Add -L to walk the tree `logically', by following symbolic links in
the heirarchy.
- Add -P to walk the tree `physically'. This is the current behaviour,
and the default.
- Add "-X excludes-file" to give mtree the ability to exclude files and
directories from its traversal. excludes-file contains fnmatch(3)
patterns to exclude from the walk.
- Add "md5digest" synonym for "md5".
- Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym.
- Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym.
- Don't try to compare() other attributes if the type doesn't match;
it's nothing but trouble, and no use anyway.
- In -c, only emit "/set" records if something has changed since the
previous one.
User interface changes by me:
- Check a device's parameters before checking uid/gid/mode.
- If updating (-u), modify the following to match the specification:
- Device type (retaining existing ownership).
- Symlink target.
Fixes from (or inspired by) FreeBSD:
- Use p->ftslevel instead of own code to keep track of the level ourself.
The previous code got majorly confused if fts(3) couldn't descend
into a subdir, resulting in leaf nodes getting attached to the wrong
directory.
XXX: This new method is much much more robust, even though it's not 100%
perfect; it might result in a couple of following entries in the spec
to be incorrectly tagged as missing.
- Pass a useful pathname to rlink(), so that logical (-L) traversal
doesn't confuse symlink checking.
- Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that
there's room for the NUL.
- Use mtree_err() and strerror(p->fts_errno) to report errors during
the fts(3) walk.
Fixes by me:
- Remove now-unused `const char *name' argument from compare().
- Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c.
- Remove trailing whitespace.
- Remove unnecessary (void) casts on functions.
- Reorder entries in the getopt() switch.
- Replace strtoq() with strtoll(), and use strtoul() appropriately.
- Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
|
|
|
ip->st_size = (off_t)strtoll(val, &ep, 10);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (*ep)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid size `%s'", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case F_SLINK:
|
1993-11-02 10:51:06 +03:00
|
|
|
if ((ip->slink = strdup(val)) == NULL)
|
1998-12-06 22:07:53 +03:00
|
|
|
mtree_err("memory allocation error");
|
2004-12-01 13:07:56 +03:00
|
|
|
if (strunvis(ip->slink, val) == -1)
|
|
|
|
mtree_err("strunvis failed on `%s'", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2001-10-04 09:03:42 +04:00
|
|
|
case F_TAGS:
|
|
|
|
len = strlen(val) + 3; /* "," + str + ",\0" */
|
|
|
|
if ((ip->tags = malloc(len)) == NULL)
|
|
|
|
mtree_err("memory allocation error");
|
|
|
|
snprintf(ip->tags, len, ",%s,", val);
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case F_TIME:
|
1997-04-25 09:45:24 +04:00
|
|
|
ip->st_mtimespec.tv_sec =
|
|
|
|
(time_t)strtoul(val, &ep, 10);
|
1995-03-07 18:28:32 +03:00
|
|
|
if (*ep != '.')
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid time `%s'", val);
|
1995-03-07 18:28:32 +03:00
|
|
|
val = ep + 1;
|
User interface changes from (or inspired by) FreeBSD:
- Add -L to walk the tree `logically', by following symbolic links in
the heirarchy.
- Add -P to walk the tree `physically'. This is the current behaviour,
and the default.
- Add "-X excludes-file" to give mtree the ability to exclude files and
directories from its traversal. excludes-file contains fnmatch(3)
patterns to exclude from the walk.
- Add "md5digest" synonym for "md5".
- Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym.
- Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym.
- Don't try to compare() other attributes if the type doesn't match;
it's nothing but trouble, and no use anyway.
- In -c, only emit "/set" records if something has changed since the
previous one.
User interface changes by me:
- Check a device's parameters before checking uid/gid/mode.
- If updating (-u), modify the following to match the specification:
- Device type (retaining existing ownership).
- Symlink target.
Fixes from (or inspired by) FreeBSD:
- Use p->ftslevel instead of own code to keep track of the level ourself.
The previous code got majorly confused if fts(3) couldn't descend
into a subdir, resulting in leaf nodes getting attached to the wrong
directory.
XXX: This new method is much much more robust, even though it's not 100%
perfect; it might result in a couple of following entries in the spec
to be incorrectly tagged as missing.
- Pass a useful pathname to rlink(), so that logical (-L) traversal
doesn't confuse symlink checking.
- Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that
there's room for the NUL.
- Use mtree_err() and strerror(p->fts_errno) to report errors during
the fts(3) walk.
Fixes by me:
- Remove now-unused `const char *name' argument from compare().
- Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c.
- Remove trailing whitespace.
- Remove unnecessary (void) casts on functions.
- Reorder entries in the getopt() switch.
- Replace strtoq() with strtoll(), and use strtoul() appropriately.
- Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
|
|
|
ip->st_mtimespec.tv_nsec = strtoul(val, &ep, 10);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (*ep)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid time `%s'", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case F_TYPE:
|
2001-07-18 08:51:54 +04:00
|
|
|
ip->type = parsetype(val);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1993-11-02 10:51:06 +03:00
|
|
|
case F_UID:
|
1997-04-25 09:45:24 +04:00
|
|
|
ip->st_uid = (uid_t)strtoul(val, &ep, 10);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (*ep)
|
2001-03-26 00:02:01 +04:00
|
|
|
mtree_err("invalid uid `%s'", val);
|
1993-11-02 10:51:06 +03:00
|
|
|
break;
|
|
|
|
case F_UNAME:
|
2004-07-22 20:51:45 +04:00
|
|
|
if (mtree_Wflag) /* don't parse if whacking */
|
2001-11-03 15:51:40 +03:00
|
|
|
break;
|
2001-11-01 05:15:41 +03:00
|
|
|
if (uid_from_user(val, &uid) == -1)
|
2001-11-03 15:51:40 +03:00
|
|
|
mtree_err("unknown user `%s'", val);
|
2001-11-01 05:15:41 +03:00
|
|
|
ip->st_uid = uid;
|
1993-11-02 10:51:06 +03:00
|
|
|
break;
|
2001-10-04 08:51:27 +04:00
|
|
|
default:
|
|
|
|
mtree_err(
|
|
|
|
"set(): unsupported key type 0x%x (INTERNAL ERROR)",
|
|
|
|
type);
|
|
|
|
/* NOTREACHED */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
static void
|
2001-03-09 06:09:45 +03:00
|
|
|
unset(char *t, NODE *ip)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-17 15:46:30 +04:00
|
|
|
char *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-10-17 05:19:17 +04:00
|
|
|
while ((p = strsep(&t, " \t")) != NULL) {
|
|
|
|
if (*p == '\0')
|
|
|
|
continue;
|
1993-11-02 10:51:06 +03:00
|
|
|
ip->flags &= ~parsekey(p, NULL);
|
2001-10-05 17:14:56 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|