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 $
33 #include <sys/param.h>
46 static char path[MAXPATHLEN];
48 static void miss(NODE *, char *);
49 static int vwalk(void);
69 char *argv[2], dot[] = ".";
73 if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
74 err(1, "line %d: fts_open", lineno);
77 while ((p = fts_read(t))) {
78 if (check_excludes(p->fts_name, p->fts_path)) {
79 fts_set(t, p, FTS_SKIP);
87 if (specdepth > p->fts_level) {
88 for (level = level->parent; level->prev;
96 warnx("%s: %s", RP(p), strerror(p->fts_errno));
103 if (specdepth != p->fts_level)
105 for (ep = level; ep; ep = ep->next)
106 if ((ep->flags & F_MAGIC &&
107 !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
108 !strcmp(ep->name, p->fts_name)) {
109 ep->flags |= F_VISIT;
110 if ((ep->flags & F_NOCHANGE) == 0 &&
113 if (ep->flags & F_IGN)
114 fts_set(t, p, FTS_SKIP);
115 else if (ep->child && ep->type == F_DIR &&
116 p->fts_info == FTS_D) {
127 printf("%s extra", RP(p));
129 if ((S_ISDIR(p->fts_statp->st_mode)
130 ? rmdir : unlink)(p->fts_accpath)) {
131 printf(", not removed: %s",
138 fts_set(t, p, FTS_SKIP);
142 warnx("%s checksum: %u", fullpath, crc_total);
147 miss(NODE *p, char *tail)
153 for (; p; p = p->next) {
154 if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
156 strcpy(tail, p->name);
157 if (!(p->flags & F_VISIT)) {
158 /* Don't print missing message if file exists as a
159 symbolic link and the -q flag is set. */
162 if (qflag && stat(path, &statbuf) == 0)
165 printf("%s missing", path);
167 if (p->type != F_DIR && p->type != F_LINK) {
173 if (p->type == F_LINK)
177 if (!(p->flags & F_VISIT) && uflag) {
178 if (!(p->flags & (F_UID | F_UNAME)))
179 printf(" (%s not created: user not specified)", type);
180 else if (!(p->flags & (F_GID | F_GNAME)))
181 printf(" (%s not created: group not specified)", type);
182 else if (p->type == F_LINK) {
183 if (symlink(p->slink, path))
184 printf(" (symlink not created: %s)\n",
187 printf(" (created)\n");
188 if (lchown(path, p->st_uid, p->st_gid))
189 printf("%s: user/group not modified: %s\n",
190 path, strerror(errno));
192 } else if (!(p->flags & F_MODE))
193 printf(" (directory not created: mode not specified)");
194 else if (mkdir(path, S_IRWXU))
195 printf(" (directory not created: %s)",
199 printf(" (created)");
202 if (!(p->flags & F_VISIT))
205 for (tp = tail; *tp; ++tp);
207 miss(p->child, tp + 1);
212 if (chown(path, p->st_uid, p->st_gid)) {
213 printf("%s: user/group/mode not modified: %s\n",
214 path, strerror(errno));
215 printf("%s: warning: file mode %snot set\n", path,
216 (p->flags & F_FLAGS) ? "and file flags " : "");
219 if (chmod(path, p->st_mode))
220 printf("%s: permissions not set: %s\n",
221 path, strerror(errno));
222 if ((p->flags & F_FLAGS) && p->st_flags &&
223 chflags(path, p->st_flags))
224 printf("%s: file flags not set: %s\n",
225 path, strerror(errno));