]>
git.saurik.com Git - apple/file_cmds.git/blob - mtree/compare.c
a9fc284a582848eefcfbe0b685054704889de818
2 * Copyright (c) 1989, 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
[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD: src/usr.sbin/mtree/compare.c,v 1.34 2005/03/29 11:44:17 tobez Exp $");
38 #include <sys/param.h>
59 #endif /* !__APPLE__ */
70 #include "commoncrypto.h"
71 #endif /* __APPLE__ */
73 #define INDENTNAMELEN 8
76 len = printf("%s changed\n", RP(p)); \
81 compare(char *name __unused
, NODE
*s
, FTSENT
*p
)
94 if (!S_ISBLK(p
->fts_statp
->st_mode
))
98 if (!S_ISCHR(p
->fts_statp
->st_mode
))
102 if (!S_ISDIR(p
->fts_statp
->st_mode
))
106 if (!S_ISFIFO(p
->fts_statp
->st_mode
))
110 if (!S_ISREG(p
->fts_statp
->st_mode
))
114 if (!S_ISLNK(p
->fts_statp
->st_mode
))
118 if (!S_ISSOCK(p
->fts_statp
->st_mode
)) {
120 (void)printf("\ttype expected %s found %s\n",
121 ftype(s
->type
), inotype(p
->fts_statp
->st_mode
));
126 /* Set the uid/gid first, then set the mode. */
127 if (s
->flags
& (F_UID
| F_UNAME
) && s
->st_uid
!= p
->fts_statp
->st_uid
) {
129 (void)printf("%suser expected %lu found %lu",
130 tab
, (u_long
)s
->st_uid
, (u_long
)p
->fts_statp
->st_uid
);
132 if (chown(p
->fts_accpath
, s
->st_uid
, -1))
133 (void)printf(" not modified: %s\n",
136 (void)printf(" modified\n");
141 if (s
->flags
& (F_GID
| F_GNAME
) && s
->st_gid
!= p
->fts_statp
->st_gid
) {
143 (void)printf("%sgid expected %lu found %lu",
144 tab
, (u_long
)s
->st_gid
, (u_long
)p
->fts_statp
->st_gid
);
146 if (chown(p
->fts_accpath
, -1, s
->st_gid
))
147 (void)printf(" not modified: %s\n",
150 (void)printf(" modified\n");
155 if (s
->flags
& F_MODE
&&
156 !S_ISLNK(p
->fts_statp
->st_mode
) &&
157 s
->st_mode
!= (p
->fts_statp
->st_mode
& MBITS
)) {
159 (void)printf("%spermissions expected %#o found %#o",
160 tab
, s
->st_mode
, p
->fts_statp
->st_mode
& MBITS
);
162 if (chmod(p
->fts_accpath
, s
->st_mode
))
163 (void)printf(" not modified: %s\n",
166 (void)printf(" modified\n");
171 if (s
->flags
& F_NLINK
&& s
->type
!= F_DIR
&&
172 s
->st_nlink
!= p
->fts_statp
->st_nlink
) {
174 (void)printf("%slink_count expected %u found %u\n",
175 tab
, s
->st_nlink
, p
->fts_statp
->st_nlink
);
178 if (s
->flags
& F_SIZE
&& s
->st_size
!= p
->fts_statp
->st_size
&&
179 !S_ISDIR(p
->fts_statp
->st_mode
)) {
181 (void)printf("%ssize expected %jd found %jd\n", tab
,
182 (intmax_t)s
->st_size
, (intmax_t)p
->fts_statp
->st_size
);
187 * Catches nano-second differences, but doesn't display them.
189 if ((s
->flags
& F_TIME
) &&
190 ((s
->st_mtimespec
.tv_sec
!= p
->fts_statp
->st_mtimespec
.tv_sec
) ||
191 (s
->st_mtimespec
.tv_nsec
!= p
->fts_statp
->st_mtimespec
.tv_nsec
))) {
193 (void)printf("%smodification time expected %.24s ",
194 tab
, ctime(&s
->st_mtimespec
.tv_sec
));
195 (void)printf("found %.24s",
196 ctime(&p
->fts_statp
->st_mtimespec
.tv_sec
));
198 tv
[0].tv_sec
= s
->st_mtimespec
.tv_sec
;
199 tv
[0].tv_usec
= s
->st_mtimespec
.tv_nsec
/ 1000;
201 if (utimes(p
->fts_accpath
, tv
))
202 (void)printf(" not modified: %s\n",
205 (void)printf(" modified\n");
210 if (s
->flags
& F_CKSUM
) {
211 if ((fd
= open(p
->fts_accpath
, O_RDONLY
, 0)) < 0) {
213 (void)printf("%scksum: %s: %s\n",
214 tab
, p
->fts_accpath
, strerror(errno
));
216 } else if (crc(fd
, &val
, &len
)) {
219 (void)printf("%scksum: %s: %s\n",
220 tab
, p
->fts_accpath
, strerror(errno
));
224 if (s
->cksum
!= val
) {
226 (void)printf("%scksum expected %lu found %lu\n",
227 tab
, s
->cksum
, (unsigned long)val
);
232 if ((s
->flags
& F_FLAGS
) && s
->st_flags
!= p
->fts_statp
->st_flags
) {
234 fflags
= flags_to_string(s
->st_flags
);
235 (void)printf("%sflags expected \"%s\"", tab
, fflags
);
238 fflags
= flags_to_string(p
->fts_statp
->st_flags
);
239 (void)printf(" found \"%s\"", fflags
);
243 if (chflags(p
->fts_accpath
, (u_int
)s
->st_flags
))
244 (void)printf(" not modified: %s\n",
247 (void)printf(" modified\n");
253 if (s
->flags
& F_MD5
) {
254 char *new_digest
, buf
[33];
256 new_digest
= MD5File(p
->fts_accpath
, buf
);
259 printf("%sMD5: %s: %s\n", tab
, p
->fts_accpath
,
262 } else if (strcmp(new_digest
, s
->md5digest
)) {
264 printf("%sMD5 expected %s found %s\n", tab
, s
->md5digest
,
269 #endif /* ENABLE_MD5 */
271 if (s
->flags
& F_SHA1
) {
272 char *new_digest
, buf
[41];
274 new_digest
= SHA1_File(p
->fts_accpath
, buf
);
277 printf("%sSHA-1: %s: %s\n", tab
, p
->fts_accpath
,
280 } else if (strcmp(new_digest
, s
->sha1digest
)) {
282 printf("%sSHA-1 expected %s found %s\n",
283 tab
, s
->sha1digest
, new_digest
);
287 #endif /* ENABLE_SHA1 */
289 if (s
->flags
& F_RMD160
) {
290 char *new_digest
, buf
[41];
292 new_digest
= RIPEMD160_File(p
->fts_accpath
, buf
);
295 printf("%sRIPEMD160: %s: %s\n", tab
,
296 p
->fts_accpath
, strerror(errno
));
298 } else if (strcmp(new_digest
, s
->rmd160digest
)) {
300 printf("%sRIPEMD160 expected %s found %s\n",
301 tab
, s
->rmd160digest
, new_digest
);
305 #endif /* ENABLE_RMD160 */
307 if (s
->flags
& F_SHA256
) {
308 char *new_digest
, buf
[65];
310 new_digest
= SHA256_File(p
->fts_accpath
, buf
);
313 printf("%sSHA-256: %s: %s\n", tab
, p
->fts_accpath
,
316 } else if (strcmp(new_digest
, s
->sha256digest
)) {
318 printf("%sSHA-256 expected %s found %s\n",
319 tab
, s
->sha256digest
, new_digest
);
323 #endif /* ENABLE_SHA256 */
325 if (s
->flags
& F_SLINK
&&
326 strcmp(cp
= rlink(p
->fts_accpath
), s
->slink
)) {
328 (void)printf("%slink_ref expected %s found %s\n",
337 switch(type
& S_IFMT
) {
385 static char lbuf
[MAXPATHLEN
* 4];
387 char tbuf
[MAXPATHLEN
];
389 if ((len
= readlink(name
, tbuf
, sizeof(tbuf
) - 1)) == -1)
390 err(1, "line %d: %s", lineno
, name
);
392 strvis(lbuf
, tbuf
, VIS_WHITE
| VIS_OCTAL
);