1 /* $NetBSD: verify.c,v 1.40 2012/03/25 16:07:04 christos Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #if HAVE_NBTOOL_CONFIG_H
33 #include "nbtool_config.h"
36 #include <sys/cdefs.h>
37 #if defined(__RCSID) && !defined(lint)
39 static char sccsid
[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
41 __RCSID("$NetBSD: verify.c,v 1.40 2012/03/25 16:07:04 christos Exp $");
45 #include <sys/param.h>
48 #if ! HAVE_NBTOOL_CONFIG_H
61 static char path
[MAXPATHLEN
];
63 static void miss(NODE
*, char *);
64 static int vwalk(void);
89 if ((t
= fts_open(argv
, ftsoptions
, NULL
)) == NULL
)
90 mtree_err("fts_open: %s", strerror(errno
));
93 while ((p
= fts_read(t
)) != NULL
) {
94 if (check_excludes(p
->fts_name
, p
->fts_path
)) {
95 fts_set(t
, p
, FTS_SKIP
);
103 if (specdepth
> p
->fts_level
) {
104 for (level
= level
->parent
; level
->prev
;
113 warnx("%s: %s", RP(p
), strerror(p
->fts_errno
));
120 if (specdepth
!= p
->fts_level
)
122 for (ep
= level
; ep
; ep
= ep
->next
)
123 if ((ep
->flags
& F_MAGIC
&&
124 !fnmatch(ep
->name
, p
->fts_name
, FNM_PATHNAME
)) ||
125 !strcmp(ep
->name
, p
->fts_name
)) {
126 ep
->flags
|= F_VISIT
;
129 if (!(ep
->flags
& F_IGN
) &&
131 p
->fts_info
== FTS_D
) {
137 fts_set(t
, p
, FTS_SKIP
);
144 if (!eflag
&& !(dflag
&& p
->fts_info
== FTS_SL
)) {
145 printf("extra: %s", RP(p
));
147 if ((S_ISDIR(p
->fts_statp
->st_mode
)
148 ? rmdir
: unlink
)(p
->fts_accpath
)) {
149 printf(", not removed: %s",
156 fts_set(t
, p
, FTS_SKIP
);
160 warnx("%s checksum: %u", fullpath
, crc_total
);
165 miss(NODE
*p
, char *tail
)
172 for (; p
; p
= p
->next
) {
173 if (p
->flags
& F_OPT
&& !(p
->flags
& F_VISIT
))
175 if (p
->type
!= F_DIR
&& (dflag
|| p
->flags
& F_VISIT
))
177 strcpy(tail
, p
->name
);
178 if (!(p
->flags
& F_VISIT
))
179 printf("missing: %s", path
);
197 if (!(p
->flags
& F_VISIT
) && uflag
) {
198 if (mtree_Wflag
|| p
->type
== F_LINK
)
200 if (!(p
->flags
& (F_UID
| F_UNAME
)))
202 " (%s not created: user not specified)", type
);
203 else if (!(p
->flags
& (F_GID
| F_GNAME
)))
205 " (%s not created: group not specified)", type
);
206 else if (!(p
->flags
& F_MODE
))
208 " (%s not created: mode not specified)", type
);
216 if (!(p
->flags
& F_DEV
))
218 " (%s not created: device not specified)",
221 p
->st_mode
| nodetoino(p
->type
),
223 printf(" (%s not created: %s)\n",
224 type
, strerror(errno
));
229 if (!(p
->flags
& F_SLINK
))
231 " (%s not created: link not specified)\n",
233 else if (symlink(p
->slink
, path
))
235 " (%s not created: %s)\n",
236 type
, strerror(errno
));
241 if (mkdir(path
, S_IRWXU
|S_IRWXG
|S_IRWXO
))
242 printf(" (not created: %s)",
248 mtree_err("can't create create %s",
253 printf(" (created)");
254 if (p
->type
== F_DIR
) {
255 if (!(p
->flags
& F_VISIT
))
257 for (tp
= tail
; *tp
; ++tp
)
260 miss(p
->child
, tp
+ 1);
265 if (!create
|| mtree_Wflag
)
268 if ((p
->flags
& (F_UID
| F_UNAME
)) &&
269 (p
->flags
& (F_GID
| F_GNAME
)) &&
270 (lchown(path
, p
->st_uid
, p
->st_gid
))) {
271 printf("%s: user/group/mode not modified: %s\n",
272 path
, strerror(errno
));
273 printf("%s: warning: file mode %snot set\n", path
,
274 (p
->flags
& F_FLAGS
) ? "and file flags " : "");
278 if ((p
->flags
& (F_UID
| F_UNAME
)) &&
279 (p
->flags
& (F_GID
| F_GNAME
))) {
280 printf("Warning: unable to change user/group/mode due "
281 "to lack of lchown(3) support");
284 if (p
->flags
& F_MODE
) {
286 if (lchmod(path
, p
->st_mode
))
287 printf("%s: permissions not set: %s\n",
288 path
, strerror(errno
));
290 printf("Warning: unable to set permissions due "
291 "to lack of lchmod(3) support");
294 #if HAVE_STRUCT_STAT_ST_FLAGS && !defined(__minix)
295 if ((p
->flags
& F_FLAGS
) && p
->st_flags
) {
299 flags
= p
->st_flags
& ~SP_FLGS
;
300 if (lchflags(path
, flags
))
301 printf("%s: file flags not set: %s\n",
302 path
, strerror(errno
));
304 #endif /* HAVE_STRUCT_STAT_ST_FLAGS */