]>
git.saurik.com Git - apple/file_cmds.git/blob - mtree/verify.c
4ad32029f4baabcc4dd470e6f796502a4a60f438
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: src/usr.sbin/mtree/verify.c,v 1.24 2005/08/11 15:43:55 brian Exp $");
38 #include <sys/param.h>
52 static char path
[MAXPATHLEN
];
54 static void miss(NODE
*, char *);
55 static int vwalk(void);
58 mtree_verifyspec(FILE *fi
)
62 root
= mtree_readspec(fi
);
80 if ((t
= fts_open(argv
, ftsoptions
, NULL
)) == NULL
)
81 err(1, "line %d: fts_open", lineno
);
84 while ((p
= fts_read(t
))) {
85 if (check_excludes(p
->fts_name
, p
->fts_path
)) {
86 fts_set(t
, p
, FTS_SKIP
);
94 if (specdepth
> p
->fts_level
) {
95 for (level
= level
->parent
; level
->prev
;
103 warnx("%s: %s", RP(p
), strerror(p
->fts_errno
));
110 if (specdepth
!= p
->fts_level
)
112 for (ep
= level
; ep
; ep
= ep
->next
)
113 if ((ep
->flags
& F_MAGIC
&&
114 !fnmatch(ep
->name
, p
->fts_name
, FNM_PATHNAME
)) ||
115 !strcmp(ep
->name
, p
->fts_name
)) {
116 ep
->flags
|= F_VISIT
;
117 if ((ep
->flags
& F_NOCHANGE
) == 0 &&
118 compare(ep
->name
, ep
, p
))
120 if (ep
->flags
& F_IGN
)
121 (void)fts_set(t
, p
, FTS_SKIP
);
122 else if (ep
->child
&& ep
->type
== F_DIR
&&
123 p
->fts_info
== FTS_D
) {
134 (void)printf("%s extra", RP(p
));
136 if ((S_ISDIR(p
->fts_statp
->st_mode
)
137 ? rmdir
: unlink
)(p
->fts_accpath
)) {
138 (void)printf(", not removed: %s",
141 (void)printf(", removed");
145 (void)fts_set(t
, p
, FTS_SKIP
);
149 warnx("%s checksum: %lu", fullpath
, (unsigned long)crc_total
);
154 miss(NODE
*p
, char *tail
)
158 const char *type
, *what
;
161 for (; p
; p
= p
->next
) {
162 if (p
->type
!= F_DIR
&& (dflag
|| p
->flags
& F_VISIT
))
164 (void)strcpy(tail
, p
->name
);
165 if (!(p
->flags
& F_VISIT
)) {
166 /* Don't print missing message if file exists as a
167 symbolic link and the -q flag is set. */
170 if (qflag
&& stat(path
, &statbuf
) == 0)
173 (void)printf("%s missing", path
);
175 if (p
->type
!= F_DIR
&& p
->type
!= F_LINK
) {
181 if (p
->type
== F_LINK
)
185 if (!(p
->flags
& F_VISIT
) && uflag
) {
186 if (!(p
->flags
& (F_UID
| F_UNAME
)))
187 (void)printf(" (%s not created: user not specified)", type
);
188 else if (!(p
->flags
& (F_GID
| F_GNAME
)))
189 (void)printf(" (%s not created: group not specified)", type
);
190 else if (p
->type
== F_LINK
) {
191 if (symlink(p
->slink
, path
))
192 (void)printf(" (symlink not created: %s)\n",
195 (void)printf(" (created)\n");
196 if (lchown(path
, p
->st_uid
, p
->st_gid
) == -1) {
198 if (p
->st_uid
== (uid_t
)-1)
200 else if (lchown(path
, (uid_t
)-1,
202 what
= "user & group";
207 (void)printf("%s: %s not modified: %s"
208 "\n", path
, what
, strerror(errno
));
211 } else if (!(p
->flags
& F_MODE
))
212 (void)printf(" (directory not created: mode not specified)");
213 else if (mkdir(path
, S_IRWXU
))
214 (void)printf(" (directory not created: %s)",
218 (void)printf(" (created)");
221 if (!(p
->flags
& F_VISIT
))
224 for (tp
= tail
; *tp
; ++tp
);
226 miss(p
->child
, tp
+ 1);
231 if (chown(path
, p
->st_uid
, p
->st_gid
) == -1) {
233 if (p
->st_uid
== (uid_t
)-1)
235 else if (chown(path
, (uid_t
)-1, p
->st_gid
) == -1)
236 what
= "user & group";
241 (void)printf("%s: %s not modified: %s\n",
242 path
, what
, strerror(errno
));
244 if (chmod(path
, p
->st_mode
))
245 (void)printf("%s: permissions not set: %s\n",
246 path
, strerror(errno
));
247 if ((p
->flags
& F_FLAGS
) && p
->st_flags
&&
248 chflags(path
, (u_int
)p
->st_flags
))
249 (void)printf("%s: file flags not set: %s\n",
250 path
, strerror(errno
));