2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)verify.c 8.1 (Berkeley) 6/6/93
30 * $FreeBSD: src/usr.sbin/mtree/verify.c,v 1.10.2.2 2001/01/12 19:17:18 phk Exp $
31 * $DragonFly: src/usr.sbin/mtree/verify.c,v 1.5 2004/03/15 16:24:22 dillon Exp $
34 #include <sys/param.h>
47 static char path[MAXPATHLEN];
49 static void miss(NODE *, char *);
50 static int vwalk(void);
70 char *argv[2], dot[] = ".";
74 if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
75 err(1, "line %d: fts_open", lineno);
78 while ((p = fts_read(t))) {
79 if (check_excludes(p->fts_name, p->fts_path)) {
80 fts_set(t, p, FTS_SKIP);
88 if (specdepth > p->fts_level) {
89 for (level = level->parent; level->prev;
97 warnx("%s: %s", RP(p), strerror(p->fts_errno));
104 if (specdepth != p->fts_level)
106 for (ep = level; ep; ep = ep->next)
107 if ((ep->flags & F_MAGIC &&
108 !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
109 !strcmp(ep->name, p->fts_name)) {
110 ep->flags |= F_VISIT;
111 if ((ep->flags & F_NOCHANGE) == 0 &&
114 if (ep->flags & F_IGN)
115 fts_set(t, p, FTS_SKIP);
116 else if (ep->child && ep->type == F_DIR &&
117 p->fts_info == FTS_D) {
128 printf("%s extra", RP(p));
130 if ((S_ISDIR(p->fts_statp->st_mode)
131 ? rmdir : unlink)(p->fts_accpath)) {
132 printf(", not removed: %s",
139 fts_set(t, p, FTS_SKIP);
143 warnx("%s checksum: %lu", fullpath, crc_total);
148 miss(NODE *p, char *tail)
154 for (; p; p = p->next) {
155 if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
157 strcpy(tail, p->name);
158 if (!(p->flags & F_VISIT)) {
159 /* Don't print missing message if file exists as a
160 symbolic link and the -q flag is set. */
163 if (qflag && stat(path, &statbuf) == 0)
166 printf("%s missing", path);
168 if (p->type != F_DIR && p->type != F_LINK) {
174 if (p->type == F_LINK)
178 if (!(p->flags & F_VISIT) && uflag) {
179 if (!(p->flags & (F_UID | F_UNAME)))
180 printf(" (%s not created: user not specified)", type);
181 else if (!(p->flags & (F_GID | F_GNAME)))
182 printf(" (%s not created: group not specified)", type);
183 else if (p->type == F_LINK) {
184 if (symlink(p->slink, path))
185 printf(" (symlink not created: %s)\n",
188 printf(" (created)\n");
189 if (lchown(path, p->st_uid, p->st_gid))
190 printf("%s: user/group not modified: %s\n",
191 path, strerror(errno));
193 } else if (!(p->flags & F_MODE))
194 printf(" (directory not created: mode not specified)");
195 else if (mkdir(path, S_IRWXU))
196 printf(" (directory not created: %s)",
200 printf(" (created)");
203 if (!(p->flags & F_VISIT))
206 for (tp = tail; *tp; ++tp);
208 miss(p->child, tp + 1);
213 if (chown(path, p->st_uid, p->st_gid)) {
214 printf("%s: user/group/mode not modified: %s\n",
215 path, strerror(errno));
216 printf("%s: warning: file mode %snot set\n", path,
217 (p->flags & F_FLAGS) ? "and file flags " : "");
220 if (chmod(path, p->st_mode))
221 printf("%s: permissions not set: %s\n",
222 path, strerror(errno));
223 if ((p->flags & F_FLAGS) && p->st_flags &&
224 chflags(path, p->st_flags))
225 printf("%s: file flags not set: %s\n",
226 path, strerror(errno));