1 /* @(#)verify.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: verify.c,v 1.46 2015/01/23 20:28:24 christos Exp $ */
5 * Copyright (c) 1990, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
46 static char path[MAXPATHLEN];
48 static void miss(NODE *, char *);
49 static int vwalk(void);
74 if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
75 mtree_err("fts_open: %s", strerror(errno));
78 while ((p = fts_read(t)) != NULL) {
79 if (check_excludes(p->fts_name, p->fts_path)) {
80 fts_set(t, p, FTS_SKIP);
83 if (!find_only(p->fts_path)) {
84 fts_set(t, p, FTS_SKIP);
92 if (specdepth > p->fts_level) {
93 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 &&
119 if (!(ep->flags & F_IGN) &&
121 p->fts_info == FTS_D) {
127 fts_set(t, p, FTS_SKIP);
134 if (!eflag && !(dflag && p->fts_info == FTS_SL)) {
135 printf("extra: %s", RP(p));
137 #if HAVE_STRUCT_STAT_ST_FLAGS
139 lchflags(p->fts_accpath, 0) == -1)
140 printf(" (chflags %s)",
143 if ((S_ISDIR(p->fts_statp->st_mode)
144 ? rmdir : unlink)(p->fts_accpath)) {
145 printf(", not removed: %s",
152 fts_set(t, p, FTS_SKIP);
156 warnx("%s checksum: %u", fullpath, crc_total);
161 miss(NODE *p, char *tail)
168 for (; p; p = p->next) {
169 if (p->flags & F_OPT && !(p->flags & F_VISIT))
171 if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
173 strcpy(tail, p->name);
174 if (!(p->flags & F_VISIT)) {
175 /* Don't print missing message if file exists as a
176 symbolic link and the -q flag is set. */
179 if (qflag && stat(path, &statbuf) == 0 &&
180 S_ISDIR(statbuf.st_mode))
183 (void)printf("%s missing", path);
202 if (!(p->flags & F_VISIT) && uflag) {
203 if (mtree_Wflag || p->type == F_LINK)
205 if (!(p->flags & (F_UID | F_UNAME)))
207 " (%s not created: user not specified)", type);
208 else if (!(p->flags & (F_GID | F_GNAME)))
210 " (%s not created: group not specified)", type);
211 else if (!(p->flags & F_MODE))
213 " (%s not created: mode not specified)", type);
221 if (!(p->flags & F_DEV))
223 " (%s not created: device not specified)",
226 p->st_mode | nodetoino(p->type),
228 printf(" (%s not created: %s)\n",
229 type, strerror(errno));
234 if (!(p->flags & F_SLINK))
236 " (%s not created: link not specified)\n",
238 else if (symlink(p->slink, path))
240 " (%s not created: %s)\n",
241 type, strerror(errno));
246 if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO))
247 printf(" (not created: %s)",
253 mtree_err("can't create create %s",
258 printf(" (created)");
259 if (p->type == F_DIR) {
260 if (!(p->flags & F_VISIT))
262 for (tp = tail; *tp; ++tp)
265 miss(p->child, tp + 1);
270 if (!create || mtree_Wflag)
272 if ((p->flags & (F_UID | F_UNAME)) &&
273 (p->flags & (F_GID | F_GNAME)) &&
274 (lchown(path, p->st_uid, p->st_gid))) {
275 printf("%s: user/group/mode not modified: %s\n",
276 path, strerror(errno));
277 printf("%s: warning: file mode %snot set\n", path,
278 (p->flags & F_FLAGS) ? "and file flags " : "");
281 if (p->flags & F_MODE) {
282 if (lchmod(path, p->st_mode))
283 printf("%s: permissions not set: %s\n",
284 path, strerror(errno));
286 #if HAVE_STRUCT_STAT_ST_FLAGS
287 if ((p->flags & F_FLAGS) && p->st_flags) {
291 flags = p->st_flags & ~SP_FLGS;
292 if (lchflags(path, flags))
293 printf("%s: file flags not set: %s\n",
294 path, strerror(errno));
296 #endif /* HAVE_STRUCT_STAT_ST_FLAGS */