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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)verify.c 8.1 (Berkeley) 6/6/93
34 * $FreeBSD: src/usr.sbin/mtree/verify.c,v 1.10.2.2 2001/01/12 19:17:18 phk Exp $
35 * $DragonFly: src/usr.sbin/mtree/verify.c,v 1.5 2004/03/15 16:24:22 dillon Exp $
38 #include <sys/param.h>
50 extern long int crc_total;
51 extern int ftsoptions;
52 extern int dflag, eflag, qflag, rflag, sflag, uflag;
53 extern char fullpath[MAXPATHLEN];
57 static char path[MAXPATHLEN];
59 static void miss(NODE *, char *);
60 static int vwalk(void);
84 if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
85 err(1, "line %d: fts_open", lineno);
88 while ((p = fts_read(t))) {
89 if (check_excludes(p->fts_name, p->fts_path)) {
90 fts_set(t, p, FTS_SKIP);
98 if (specdepth > p->fts_level) {
99 for (level = level->parent; level->prev;
100 level = level->prev);
107 warnx("%s: %s", RP(p), strerror(p->fts_errno));
114 if (specdepth != p->fts_level)
116 for (ep = level; ep; ep = ep->next)
117 if ((ep->flags & F_MAGIC &&
118 !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
119 !strcmp(ep->name, p->fts_name)) {
120 ep->flags |= F_VISIT;
121 if ((ep->flags & F_NOCHANGE) == 0 &&
122 compare(ep->name, ep, p))
124 if (ep->flags & F_IGN)
125 fts_set(t, p, FTS_SKIP);
126 else if (ep->child && ep->type == F_DIR &&
127 p->fts_info == FTS_D) {
138 printf("%s extra", RP(p));
140 if ((S_ISDIR(p->fts_statp->st_mode)
141 ? rmdir : unlink)(p->fts_accpath)) {
142 printf(", not removed: %s",
149 fts_set(t, p, FTS_SKIP);
153 warnx("%s checksum: %lu", fullpath, crc_total);
158 miss(NODE *p, char *tail)
164 for (; p; p = p->next) {
165 if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
167 strcpy(tail, p->name);
168 if (!(p->flags & F_VISIT)) {
169 /* Don't print missing message if file exists as a
170 symbolic link and the -q flag is set. */
173 if (qflag && stat(path, &statbuf) == 0)
176 printf("%s missing", path);
178 if (p->type != F_DIR && p->type != F_LINK) {
184 if (p->type == F_LINK)
188 if (!(p->flags & F_VISIT) && uflag) {
189 if (!(p->flags & (F_UID | F_UNAME)))
190 printf(" (%s not created: user not specified)", type);
191 else if (!(p->flags & (F_GID | F_GNAME)))
192 printf(" (%s not created: group not specified)", type);
193 else if (p->type == F_LINK) {
194 if (symlink(p->slink, path))
195 printf(" (symlink not created: %s)\n",
198 printf(" (created)\n");
199 if (lchown(path, p->st_uid, p->st_gid))
200 printf("%s: user/group not modified: %s\n",
201 path, strerror(errno));
203 } else if (!(p->flags & F_MODE))
204 printf(" (directory not created: mode not specified)");
205 else if (mkdir(path, S_IRWXU))
206 printf(" (directory not created: %s)",
210 printf(" (created)");
213 if (!(p->flags & F_VISIT))
216 for (tp = tail; *tp; ++tp);
218 miss(p->child, tp + 1);
223 if (chown(path, p->st_uid, p->st_gid)) {
224 printf("%s: user/group/mode not modified: %s\n",
225 path, strerror(errno));
226 printf("%s: warning: file mode %snot set\n", path,
227 (p->flags & F_FLAGS) ? "and file flags " : "");
230 if (chmod(path, p->st_mode))
231 printf("%s: permissions not set: %s\n",
232 path, strerror(errno));
233 if ((p->flags & F_FLAGS) && p->st_flags &&
234 chflags(path, p->st_flags))
235 printf("%s: file flags not set: %s\n",
236 path, strerror(errno));