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)
166 #if HAVE_STRUCT_STAT_ST_FLAGS
170 for (; p; p = p->next) {
171 if (p->flags & F_OPT && !(p->flags & F_VISIT))
173 if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
175 strcpy(tail, p->name);
176 if (!(p->flags & F_VISIT)) {
177 /* Don't print missing message if file exists as a
178 symbolic link and the -q flag is set. */
181 if (qflag && stat(path, &statbuf) == 0 &&
182 S_ISDIR(statbuf.st_mode))
185 (void)printf("%s missing", path);
204 if (!(p->flags & F_VISIT) && uflag) {
205 if (mtree_Wflag || p->type == F_LINK)
207 if (!(p->flags & (F_UID | F_UNAME)))
209 " (%s not created: user not specified)", type);
210 else if (!(p->flags & (F_GID | F_GNAME)))
212 " (%s not created: group not specified)", type);
213 else if (!(p->flags & F_MODE))
215 " (%s not created: mode not specified)", type);
223 if (!(p->flags & F_DEV))
225 " (%s not created: device not specified)",
228 p->st_mode | nodetoino(p->type),
230 printf(" (%s not created: %s)\n",
231 type, strerror(errno));
236 if (!(p->flags & F_SLINK))
238 " (%s not created: link not specified)\n",
240 else if (symlink(p->slink, path))
242 " (%s not created: %s)\n",
243 type, strerror(errno));
248 if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO))
249 printf(" (not created: %s)",
255 mtree_err("can't create create %s",
260 printf(" (created)");
261 if (p->type == F_DIR) {
262 if (!(p->flags & F_VISIT))
264 for (tp = tail; *tp; ++tp)
267 miss(p->child, tp + 1);
272 if (!create || mtree_Wflag)
274 if ((p->flags & (F_UID | F_UNAME)) &&
275 (p->flags & (F_GID | F_GNAME)) &&
276 (lchown(path, p->st_uid, p->st_gid))) {
277 printf("%s: user/group/mode not modified: %s\n",
278 path, strerror(errno));
279 printf("%s: warning: file mode %snot set\n", path,
280 (p->flags & F_FLAGS) ? "and file flags " : "");
283 if (p->flags & F_MODE) {
284 if (lchmod(path, p->st_mode))
285 printf("%s: permissions not set: %s\n",
286 path, strerror(errno));
288 #if HAVE_STRUCT_STAT_ST_FLAGS
289 if ((p->flags & F_FLAGS) && p->st_flags) {
293 flags = p->st_flags & ~SP_FLGS;
294 if (lchflags(path, flags))
295 printf("%s: file flags not set: %s\n",
296 path, strerror(errno));
298 #endif /* HAVE_STRUCT_STAT_ST_FLAGS */