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
32 static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
51 static char path[MAXPATHLEN];
53 static void miss(NODE *, char *);
54 static int vwalk(void);
57 mtree_verifyspec(FILE *fi)
61 root = mtree_readspec(fi);
79 if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
80 err(1, "line %d: fts_open", lineno);
83 while ((p = fts_read(t))) {
84 if (check_excludes(p->fts_name, p->fts_path)) {
85 fts_set(t, p, FTS_SKIP);
93 if (specdepth > p->fts_level) {
94 for (level = level->parent; level->prev;
102 warnx("%s: %s", RP(p), strerror(p->fts_errno));
109 if (specdepth != p->fts_level)
111 for (ep = level; ep; ep = ep->next)
112 if ((ep->flags & F_MAGIC &&
113 !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
114 !strcmp(ep->name, p->fts_name)) {
115 ep->flags |= F_VISIT;
116 if ((ep->flags & F_NOCHANGE) == 0 &&
117 compare(ep->name, ep, p))
119 if (ep->flags & F_IGN)
120 (void)fts_set(t, p, FTS_SKIP);
121 else if (ep->child && ep->type == F_DIR &&
122 p->fts_info == FTS_D) {
133 (void)printf("%s extra", RP(p));
135 if ((S_ISDIR(p->fts_statp->st_mode)
136 ? rmdir : unlink)(p->fts_accpath)) {
137 (void)printf(", not removed: %s",
140 (void)printf(", removed");
144 (void)fts_set(t, p, FTS_SKIP);
148 warnx("%s checksum: %lu", fullpath, (unsigned long)crc_total);
153 miss(NODE *p, char *tail)
157 const char *type, *what;
160 for (; p; p = p->next) {
161 if (p->flags & F_OPT && !(p->flags & F_VISIT))
163 if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
165 (void)strcpy(tail, p->name);
166 if (!(p->flags & F_VISIT)) {
167 /* Don't print missing message if file exists as a
168 symbolic link and the -q flag is set. */
171 if (qflag && stat(path, &statbuf) == 0)
174 (void)printf("%s missing", path);
176 if (p->type != F_DIR && p->type != F_LINK) {
182 if (p->type == F_LINK)
186 if (!(p->flags & F_VISIT) && uflag) {
187 if (!(p->flags & (F_UID | F_UNAME)))
188 (void)printf(" (%s not created: user not specified)", type);
189 else if (!(p->flags & (F_GID | F_GNAME)))
190 (void)printf(" (%s not created: group not specified)", type);
191 else if (p->type == F_LINK) {
192 if (symlink(p->slink, path))
193 (void)printf(" (symlink not created: %s)\n",
196 (void)printf(" (created)\n");
197 if (lchown(path, p->st_uid, p->st_gid) == -1) {
199 if (p->st_uid == (uid_t)-1)
201 else if (lchown(path, (uid_t)-1,
203 what = "user & group";
208 (void)printf("%s: %s not modified: %s"
209 "\n", path, what, strerror(errno));
212 } else if (!(p->flags & F_MODE))
213 (void)printf(" (directory not created: mode not specified)");
214 else if (mkdir(path, S_IRWXU))
215 (void)printf(" (directory not created: %s)",
219 (void)printf(" (created)");
222 if (!(p->flags & F_VISIT))
225 for (tp = tail; *tp; ++tp);
227 miss(p->child, tp + 1);
232 if (chown(path, p->st_uid, p->st_gid) == -1) {
234 if (p->st_uid == (uid_t)-1)
236 else if (chown(path, (uid_t)-1, p->st_gid) == -1)
237 what = "user & group";
242 (void)printf("%s: %s not modified: %s\n",
243 path, what, strerror(errno));
245 if (chmod(path, p->st_mode))
246 (void)printf("%s: permissions not set: %s\n",
247 path, strerror(errno));
248 if ((p->flags & F_FLAGS) && p->st_flags &&
249 chflags(path, p->st_flags))
250 (void)printf("%s: file flags not set: %s\n",
251 path, strerror(errno));