compare.c revision 1.60 1 1.60 simonb /* $NetBSD: compare.c,v 1.60 2021/04/03 13:37:18 simonb Exp $ */
2 1.8 cgd
3 1.1 cgd /*-
4 1.7 cgd * Copyright (c) 1989, 1993
5 1.7 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.43 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.44 jmc #if HAVE_NBTOOL_CONFIG_H
33 1.44 jmc #include "nbtool_config.h"
34 1.44 jmc #endif
35 1.44 jmc
36 1.13 lukem #include <sys/cdefs.h>
37 1.38 tv #if defined(__RCSID) && !defined(lint)
38 1.8 cgd #if 0
39 1.7 cgd static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
40 1.8 cgd #else
41 1.60 simonb __RCSID("$NetBSD: compare.c,v 1.60 2021/04/03 13:37:18 simonb Exp $");
42 1.8 cgd #endif
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.1 cgd #include <sys/param.h>
46 1.54 christos #include <sys/stat.h>
47 1.24 simonb
48 1.24 simonb #include <errno.h>
49 1.4 cgd #include <fcntl.h>
50 1.1 cgd #include <stdio.h>
51 1.57 christos #include <stdint.h>
52 1.50 he #include <stdlib.h>
53 1.32 lukem #include <string.h>
54 1.1 cgd #include <time.h>
55 1.4 cgd #include <unistd.h>
56 1.24 simonb
57 1.36 lukem #ifndef NO_MD5
58 1.36 lukem #include <md5.h>
59 1.36 lukem #endif
60 1.36 lukem #ifndef NO_RMD160
61 1.49 christos #include <rmd160.h>
62 1.36 lukem #endif
63 1.36 lukem #ifndef NO_SHA1
64 1.36 lukem #include <sha1.h>
65 1.36 lukem #endif
66 1.46 elad #ifndef NO_SHA2
67 1.49 christos #include <sha2.h>
68 1.46 elad #endif
69 1.36 lukem
70 1.4 cgd #include "extern.h"
71 1.4 cgd
72 1.4 cgd #define INDENTNAMELEN 8
73 1.34 lukem #define MARK \
74 1.34 lukem do { \
75 1.58 christos if (flavor == F_FREEBSD9) { \
76 1.58 christos len = printf("%s changed\n", RP(p)); \
77 1.34 lukem tab = "\t"; \
78 1.34 lukem } else { \
79 1.58 christos len = printf("%s: ", RP(p)); \
80 1.58 christos if (len > INDENTNAMELEN) { \
81 1.58 christos tab = "\t"; \
82 1.58 christos printf("\n"); \
83 1.58 christos } else { \
84 1.58 christos tab = ""; \
85 1.58 christos printf("%*s", INDENTNAMELEN - (int)len, ""); \
86 1.58 christos } \
87 1.34 lukem } \
88 1.20 mrg } while (0)
89 1.20 mrg #define LABEL if (!label++) MARK
90 1.20 mrg
91 1.41 lukem #if HAVE_STRUCT_STAT_ST_FLAGS
92 1.41 lukem
93 1.41 lukem
94 1.41 lukem #define CHANGEFLAGS \
95 1.41 lukem if (flags != p->fts_statp->st_flags) { \
96 1.50 he char *sf; \
97 1.34 lukem if (!label) { \
98 1.34 lukem MARK; \
99 1.50 he sf = flags_to_string(p->fts_statp->st_flags, "none"); \
100 1.50 he printf("%sflags (\"%s\"", tab, sf); \
101 1.50 he free(sf); \
102 1.34 lukem } \
103 1.42 lukem if (lchflags(p->fts_accpath, flags)) { \
104 1.34 lukem label++; \
105 1.34 lukem printf(", not modified: %s)\n", \
106 1.34 lukem strerror(errno)); \
107 1.50 he } else { \
108 1.50 he sf = flags_to_string(flags, "none"); \
109 1.50 he printf(", modified to \"%s\")\n", sf); \
110 1.50 he free(sf); \
111 1.50 he } \
112 1.4 cgd }
113 1.1 cgd
114 1.20 mrg /* SETFLAGS:
115 1.41 lukem * given pflags, additionally set those flags specified in s->st_flags and
116 1.41 lukem * selected by mask (the other flags are left unchanged).
117 1.20 mrg */
118 1.41 lukem #define SETFLAGS(pflags, mask) \
119 1.34 lukem do { \
120 1.41 lukem flags = (s->st_flags & (mask)) | (pflags); \
121 1.41 lukem CHANGEFLAGS; \
122 1.20 mrg } while (0)
123 1.20 mrg
124 1.20 mrg /* CLEARFLAGS:
125 1.41 lukem * given pflags, reset the flags specified in s->st_flags and selected by mask
126 1.41 lukem * (the other flags are left unchanged).
127 1.20 mrg */
128 1.41 lukem #define CLEARFLAGS(pflags, mask) \
129 1.34 lukem do { \
130 1.41 lukem flags = (~(s->st_flags & (mask)) & CH_MASK) & (pflags); \
131 1.41 lukem CHANGEFLAGS; \
132 1.20 mrg } while (0)
133 1.41 lukem #endif /* HAVE_STRUCT_STAT_ST_FLAGS */
134 1.20 mrg
135 1.4 cgd int
136 1.34 lukem compare(NODE *s, FTSENT *p)
137 1.1 cgd {
138 1.59 cheusov uint32_t len, val, flags;
139 1.4 cgd int fd, label;
140 1.60 simonb bool was_unlinked;
141 1.30 lukem const char *cp, *tab;
142 1.46 elad #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)
143 1.51 elad char *digestbuf;
144 1.36 lukem #endif
145 1.1 cgd
146 1.13 lukem tab = NULL;
147 1.1 cgd label = 0;
148 1.60 simonb was_unlinked = false;
149 1.1 cgd switch(s->type) {
150 1.1 cgd case F_BLOCK:
151 1.3 deraadt if (!S_ISBLK(p->fts_statp->st_mode))
152 1.1 cgd goto typeerr;
153 1.1 cgd break;
154 1.1 cgd case F_CHAR:
155 1.3 deraadt if (!S_ISCHR(p->fts_statp->st_mode))
156 1.1 cgd goto typeerr;
157 1.1 cgd break;
158 1.1 cgd case F_DIR:
159 1.3 deraadt if (!S_ISDIR(p->fts_statp->st_mode))
160 1.1 cgd goto typeerr;
161 1.1 cgd break;
162 1.1 cgd case F_FIFO:
163 1.3 deraadt if (!S_ISFIFO(p->fts_statp->st_mode))
164 1.1 cgd goto typeerr;
165 1.1 cgd break;
166 1.1 cgd case F_FILE:
167 1.3 deraadt if (!S_ISREG(p->fts_statp->st_mode))
168 1.1 cgd goto typeerr;
169 1.1 cgd break;
170 1.1 cgd case F_LINK:
171 1.3 deraadt if (!S_ISLNK(p->fts_statp->st_mode))
172 1.1 cgd goto typeerr;
173 1.1 cgd break;
174 1.44 jmc #ifdef S_ISSOCK
175 1.1 cgd case F_SOCK:
176 1.44 jmc if (!S_ISSOCK(p->fts_statp->st_mode))
177 1.44 jmc goto typeerr;
178 1.1 cgd break;
179 1.44 jmc #endif
180 1.44 jmc typeerr: LABEL;
181 1.58 christos printf(flavor == F_FREEBSD9 ?
182 1.58 christos "\ttype expected %s found %s\n" : "\ttype (%s, %s)\n",
183 1.44 jmc nodetype(s->type), inotype(p->fts_statp->st_mode));
184 1.44 jmc return (label);
185 1.1 cgd }
186 1.45 lukem if (mtree_Wflag)
187 1.33 lukem goto afterpermwhack;
188 1.37 tv #if HAVE_STRUCT_STAT_ST_FLAGS
189 1.20 mrg if (iflag && !uflag) {
190 1.20 mrg if (s->flags & F_FLAGS)
191 1.41 lukem SETFLAGS(p->fts_statp->st_flags, SP_FLGS);
192 1.20 mrg return (label);
193 1.20 mrg }
194 1.20 mrg if (mflag && !uflag) {
195 1.20 mrg if (s->flags & F_FLAGS)
196 1.41 lukem CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS);
197 1.20 mrg return (label);
198 1.20 mrg }
199 1.37 tv #endif
200 1.34 lukem if (s->flags & F_DEV &&
201 1.34 lukem (s->type == F_BLOCK || s->type == F_CHAR) &&
202 1.34 lukem s->st_rdev != p->fts_statp->st_rdev) {
203 1.34 lukem LABEL;
204 1.58 christos printf(flavor == F_FREEBSD9 ?
205 1.58 christos "%sdevice expected %#jx found %#jx" :
206 1.58 christos "%sdevice (%#jx, %#jx",
207 1.56 christos tab, (uintmax_t)s->st_rdev,
208 1.56 christos (uintmax_t)p->fts_statp->st_rdev);
209 1.34 lukem if (uflag) {
210 1.34 lukem if ((unlink(p->fts_accpath) == -1) ||
211 1.34 lukem (mknod(p->fts_accpath,
212 1.34 lukem s->st_mode | nodetoino(s->type),
213 1.34 lukem s->st_rdev) == -1) ||
214 1.39 lukem (lchown(p->fts_accpath, p->fts_statp->st_uid,
215 1.60 simonb p->fts_statp->st_gid) == -1) ) {
216 1.58 christos printf(", not modified: %s%s\n",
217 1.58 christos strerror(errno),
218 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
219 1.60 simonb } else {
220 1.58 christos printf(", modified%s\n",
221 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
222 1.60 simonb was_unlinked = true;
223 1.60 simonb }
224 1.34 lukem } else
225 1.34 lukem printf(")\n");
226 1.34 lukem tab = "\t";
227 1.34 lukem }
228 1.4 cgd /* Set the uid/gid first, then set the mode. */
229 1.60 simonb if (s->flags & (F_UID | F_UNAME) &&
230 1.60 simonb (was_unlinked || s->st_uid != p->fts_statp->st_uid)) {
231 1.1 cgd LABEL;
232 1.58 christos printf(flavor == F_FREEBSD9 ?
233 1.58 christos "%suser expected %lu found %lu" : "%suser (%lu, %lu",
234 1.19 christos tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
235 1.19 christos if (uflag) {
236 1.39 lukem if (lchown(p->fts_accpath, s->st_uid, -1))
237 1.58 christos printf(", not modified: %s%s\n",
238 1.58 christos strerror(errno),
239 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
240 1.1 cgd else
241 1.60 simonb printf(", modified%s%s\n",
242 1.60 simonb was_unlinked ? " by unlink" : "",
243 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
244 1.19 christos } else
245 1.34 lukem printf(")\n");
246 1.4 cgd tab = "\t";
247 1.1 cgd }
248 1.60 simonb if (s->flags & (F_GID | F_GNAME) &&
249 1.60 simonb (was_unlinked || s->st_gid != p->fts_statp->st_gid)) {
250 1.1 cgd LABEL;
251 1.58 christos printf(flavor == F_FREEBSD9 ?
252 1.58 christos "%sgid expected %lu found %lu" : "%sgid (%lu, %lu",
253 1.19 christos tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
254 1.19 christos if (uflag) {
255 1.39 lukem if (lchown(p->fts_accpath, -1, s->st_gid))
256 1.58 christos printf(", not modified: %s%s\n",
257 1.58 christos strerror(errno),
258 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
259 1.1 cgd else
260 1.60 simonb printf(", modified%s%s\n",
261 1.60 simonb was_unlinked ? " by unlink" : "",
262 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
263 1.19 christos }
264 1.4 cgd else
265 1.34 lukem printf(")\n");
266 1.4 cgd tab = "\t";
267 1.1 cgd }
268 1.4 cgd if (s->flags & F_MODE &&
269 1.60 simonb (was_unlinked || s->st_mode != (p->fts_statp->st_mode & MBITS))) {
270 1.60 simonb if (lflag && !was_unlinked) {
271 1.26 perry mode_t tmode, mode;
272 1.26 perry
273 1.26 perry tmode = s->st_mode;
274 1.26 perry mode = p->fts_statp->st_mode & MBITS;
275 1.26 perry /*
276 1.26 perry * if none of the suid/sgid/etc bits are set,
277 1.26 perry * then if the mode is a subset of the target,
278 1.26 perry * skip.
279 1.26 perry */
280 1.26 perry if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) ||
281 1.26 perry (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO))))
282 1.26 perry if ((mode | tmode) == tmode)
283 1.26 perry goto skip;
284 1.26 perry }
285 1.34 lukem
286 1.1 cgd LABEL;
287 1.58 christos printf(flavor == F_FREEBSD9 ?
288 1.58 christos "%spermissions expcted %#lo found %#lo" :
289 1.58 christos "%spermissions (%#lo, %#lo",
290 1.19 christos tab, (u_long)s->st_mode,
291 1.19 christos (u_long)p->fts_statp->st_mode & MBITS);
292 1.19 christos if (uflag) {
293 1.39 lukem if (lchmod(p->fts_accpath, s->st_mode))
294 1.58 christos printf(", not modified: %s%s\n",
295 1.58 christos strerror(errno),
296 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
297 1.1 cgd else
298 1.60 simonb printf(", modified%s%s\n",
299 1.60 simonb was_unlinked ? " by unlink" : "",
300 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
301 1.19 christos }
302 1.4 cgd else
303 1.34 lukem printf(")\n");
304 1.4 cgd tab = "\t";
305 1.31 lukem skip: ;
306 1.29 lukem }
307 1.1 cgd if (s->flags & F_NLINK && s->type != F_DIR &&
308 1.3 deraadt s->st_nlink != p->fts_statp->st_nlink) {
309 1.1 cgd LABEL;
310 1.58 christos printf(flavor == F_FREEBSD9 ?
311 1.58 christos "%slink count expected %lu found %lu\n" :
312 1.58 christos "%slink count (%lu, %lu)\n",
313 1.19 christos tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink);
314 1.4 cgd tab = "\t";
315 1.1 cgd }
316 1.3 deraadt if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
317 1.1 cgd LABEL;
318 1.58 christos printf(flavor == F_FREEBSD9 ?
319 1.58 christos "%ssize expected %ju found %ju\n" : "%ssize (%ju, %ju)\n",
320 1.56 christos tab, (uintmax_t)s->st_size,
321 1.56 christos (uintmax_t)p->fts_statp->st_size);
322 1.4 cgd tab = "\t";
323 1.4 cgd }
324 1.7 cgd /*
325 1.7 cgd * XXX
326 1.11 mycroft * Since utimes(2) only takes a timeval, there's no point in
327 1.11 mycroft * comparing the low bits of the timespec nanosecond field. This
328 1.11 mycroft * will only result in mismatches that we can never fix.
329 1.11 mycroft *
330 1.11 mycroft * Doesn't display microsecond differences.
331 1.7 cgd */
332 1.11 mycroft if (s->flags & F_TIME) {
333 1.11 mycroft struct timeval tv[2];
334 1.21 christos struct stat *ps = p->fts_statp;
335 1.22 christos time_t smtime = s->st_mtimespec.tv_sec;
336 1.22 christos
337 1.44 jmc #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H)
338 1.21 christos time_t pmtime = ps->st_mtimespec.tv_sec;
339 1.11 mycroft
340 1.37 tv TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec);
341 1.21 christos TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec);
342 1.21 christos #else
343 1.22 christos time_t pmtime = (time_t)ps->st_mtime;
344 1.21 christos
345 1.37 tv tv[0].tv_sec = smtime;
346 1.37 tv tv[0].tv_usec = 0;
347 1.37 tv tv[1].tv_sec = pmtime;
348 1.21 christos tv[1].tv_usec = 0;
349 1.21 christos #endif
350 1.21 christos
351 1.11 mycroft if (tv[0].tv_sec != tv[1].tv_sec ||
352 1.11 mycroft tv[0].tv_usec != tv[1].tv_usec) {
353 1.11 mycroft LABEL;
354 1.58 christos printf(flavor == F_FREEBSD9 ?
355 1.58 christos "%smodification time expected %.24s found " :
356 1.58 christos "%smodification time (%.24s, ",
357 1.21 christos tab, ctime(&smtime));
358 1.34 lukem printf("%.24s", ctime(&pmtime));
359 1.11 mycroft if (tflag) {
360 1.11 mycroft tv[1] = tv[0];
361 1.11 mycroft if (utimes(p->fts_accpath, tv))
362 1.58 christos printf(", not modified: %s%s\n",
363 1.58 christos strerror(errno),
364 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
365 1.11 mycroft else
366 1.58 christos printf(", modified%s\n",
367 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
368 1.11 mycroft } else
369 1.58 christos printf("%s\n", flavor == F_FREEBSD9 ? "" : ")");
370 1.11 mycroft tab = "\t";
371 1.11 mycroft }
372 1.17 mrg }
373 1.37 tv #if HAVE_STRUCT_STAT_ST_FLAGS
374 1.17 mrg /*
375 1.17 mrg * XXX
376 1.39 lukem * since lchflags(2) will reset file times, the utimes() above
377 1.17 mrg * may have been useless! oh well, we'd rather have correct
378 1.17 mrg * flags, rather than times?
379 1.17 mrg */
380 1.20 mrg if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags)
381 1.20 mrg || mflag || iflag)) {
382 1.20 mrg if (s->st_flags != p->fts_statp->st_flags) {
383 1.50 he char *f_s;
384 1.20 mrg LABEL;
385 1.50 he f_s = flags_to_string(s->st_flags, "none");
386 1.58 christos printf(flavor == F_FREEBSD9 ?
387 1.58 christos "%sflags expected \"%s\" found " :
388 1.58 christos "%sflags (\"%s\" is not ", tab, f_s);
389 1.50 he free(f_s);
390 1.50 he f_s = flags_to_string(p->fts_statp->st_flags, "none");
391 1.50 he printf("\"%s\"", f_s);
392 1.50 he free(f_s);
393 1.20 mrg }
394 1.19 christos if (uflag) {
395 1.20 mrg if (iflag)
396 1.41 lukem SETFLAGS(0, CH_MASK);
397 1.20 mrg else if (mflag)
398 1.41 lukem CLEARFLAGS(0, SP_FLGS);
399 1.17 mrg else
400 1.41 lukem SETFLAGS(0, (~SP_FLGS & CH_MASK));
401 1.19 christos } else
402 1.58 christos printf("%s\n", flavor == F_FREEBSD9 ? "" : ")");
403 1.17 mrg tab = "\t";
404 1.1 cgd }
405 1.41 lukem #endif /* HAVE_STRUCT_STAT_ST_FLAGS */
406 1.33 lukem
407 1.33 lukem /*
408 1.33 lukem * from this point, no more permission checking or whacking
409 1.33 lukem * occurs, only checking of stuff like checksums and symlinks.
410 1.33 lukem */
411 1.33 lukem afterpermwhack:
412 1.15 ross if (s->flags & F_CKSUM) {
413 1.4 cgd if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
414 1.4 cgd LABEL;
415 1.34 lukem printf("%scksum: %s: %s\n",
416 1.4 cgd tab, p->fts_accpath, strerror(errno));
417 1.4 cgd tab = "\t";
418 1.4 cgd } else if (crc(fd, &val, &len)) {
419 1.34 lukem close(fd);
420 1.1 cgd LABEL;
421 1.34 lukem printf("%scksum: %s: %s\n",
422 1.4 cgd tab, p->fts_accpath, strerror(errno));
423 1.4 cgd tab = "\t";
424 1.4 cgd } else {
425 1.34 lukem close(fd);
426 1.4 cgd if (s->cksum != val) {
427 1.4 cgd LABEL;
428 1.58 christos printf(flavor == F_FREEBSD9 ?
429 1.58 christos "%scksum expected %lu found %lu\n" :
430 1.58 christos "%scksum (%lu, %lu)\n",
431 1.16 wsanchez tab, s->cksum, (unsigned long)val);
432 1.4 cgd }
433 1.4 cgd tab = "\t";
434 1.1 cgd }
435 1.15 ross }
436 1.36 lukem #ifndef NO_MD5
437 1.18 jwise if (s->flags & F_MD5) {
438 1.51 elad if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL) {
439 1.18 jwise LABEL;
440 1.55 christos printf("%s%s: %s: %s\n",
441 1.55 christos tab, MD5KEY, p->fts_accpath, strerror(errno));
442 1.18 jwise tab = "\t";
443 1.18 jwise } else {
444 1.34 lukem if (strcmp(s->md5digest, digestbuf)) {
445 1.18 jwise LABEL;
446 1.58 christos printf(flavor == F_FREEBSD9 ?
447 1.58 christos "%s%s expected %s found %s\n" :
448 1.58 christos "%s%s (0x%s, 0x%s)\n",
449 1.55 christos tab, MD5KEY, s->md5digest, digestbuf);
450 1.18 jwise }
451 1.18 jwise tab = "\t";
452 1.51 elad free(digestbuf);
453 1.18 jwise }
454 1.18 jwise }
455 1.36 lukem #endif /* ! NO_MD5 */
456 1.36 lukem #ifndef NO_RMD160
457 1.34 lukem if (s->flags & F_RMD160) {
458 1.51 elad if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL) {
459 1.34 lukem LABEL;
460 1.55 christos printf("%s%s: %s: %s\n",
461 1.55 christos tab, RMD160KEY, p->fts_accpath, strerror(errno));
462 1.34 lukem tab = "\t";
463 1.34 lukem } else {
464 1.34 lukem if (strcmp(s->rmd160digest, digestbuf)) {
465 1.34 lukem LABEL;
466 1.58 christos printf(flavor == F_FREEBSD9 ?
467 1.58 christos "%s%s expected %s found %s\n" :
468 1.58 christos "%s%s (0x%s, 0x%s)\n",
469 1.55 christos tab, RMD160KEY, s->rmd160digest, digestbuf);
470 1.34 lukem }
471 1.34 lukem tab = "\t";
472 1.51 elad free(digestbuf);
473 1.34 lukem }
474 1.34 lukem }
475 1.36 lukem #endif /* ! NO_RMD160 */
476 1.36 lukem #ifndef NO_SHA1
477 1.34 lukem if (s->flags & F_SHA1) {
478 1.51 elad if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL) {
479 1.34 lukem LABEL;
480 1.55 christos printf("%s%s: %s: %s\n",
481 1.55 christos tab, SHA1KEY, p->fts_accpath, strerror(errno));
482 1.34 lukem tab = "\t";
483 1.34 lukem } else {
484 1.34 lukem if (strcmp(s->sha1digest, digestbuf)) {
485 1.34 lukem LABEL;
486 1.58 christos printf(flavor == F_FREEBSD9 ?
487 1.58 christos "%s%s expected %s found %s\n" :
488 1.58 christos "%s%s (0x%s, 0x%s)\n",
489 1.55 christos tab, SHA1KEY, s->sha1digest, digestbuf);
490 1.34 lukem }
491 1.34 lukem tab = "\t";
492 1.51 elad free(digestbuf);
493 1.34 lukem }
494 1.34 lukem }
495 1.36 lukem #endif /* ! NO_SHA1 */
496 1.46 elad #ifndef NO_SHA2
497 1.46 elad if (s->flags & F_SHA256) {
498 1.51 elad if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL) {
499 1.46 elad LABEL;
500 1.55 christos printf("%s%s: %s: %s\n",
501 1.55 christos tab, SHA256KEY, p->fts_accpath, strerror(errno));
502 1.46 elad tab = "\t";
503 1.46 elad } else {
504 1.46 elad if (strcmp(s->sha256digest, digestbuf)) {
505 1.46 elad LABEL;
506 1.58 christos printf(flavor == F_FREEBSD9 ?
507 1.58 christos "%s%s expected %s found %s\n" :
508 1.58 christos "%s%s (0x%s, 0x%s)\n",
509 1.55 christos tab, SHA256KEY, s->sha256digest, digestbuf);
510 1.46 elad }
511 1.46 elad tab = "\t";
512 1.51 elad free(digestbuf);
513 1.46 elad }
514 1.46 elad }
515 1.53 christos #ifdef SHA384_BLOCK_LENGTH
516 1.46 elad if (s->flags & F_SHA384) {
517 1.51 elad if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL) {
518 1.46 elad LABEL;
519 1.55 christos printf("%s%s: %s: %s\n",
520 1.55 christos tab, SHA384KEY, p->fts_accpath, strerror(errno));
521 1.46 elad tab = "\t";
522 1.46 elad } else {
523 1.46 elad if (strcmp(s->sha384digest, digestbuf)) {
524 1.46 elad LABEL;
525 1.58 christos printf(flavor == F_FREEBSD9 ?
526 1.58 christos "%s%s expected %s found %s\n" :
527 1.58 christos "%s%s (0x%s, 0x%s)\n",
528 1.55 christos tab, SHA384KEY, s->sha384digest, digestbuf);
529 1.46 elad }
530 1.46 elad tab = "\t";
531 1.51 elad free(digestbuf);
532 1.46 elad }
533 1.46 elad }
534 1.53 christos #endif
535 1.46 elad if (s->flags & F_SHA512) {
536 1.51 elad if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL) {
537 1.46 elad LABEL;
538 1.55 christos printf("%s%s: %s: %s\n",
539 1.55 christos tab, SHA512KEY, p->fts_accpath, strerror(errno));
540 1.46 elad tab = "\t";
541 1.46 elad } else {
542 1.46 elad if (strcmp(s->sha512digest, digestbuf)) {
543 1.46 elad LABEL;
544 1.58 christos printf(flavor == F_FREEBSD9 ?
545 1.58 christos "%s%s expected %s found %s\n" :
546 1.58 christos "%s%s (0x%s, 0x%s)\n",
547 1.55 christos tab, SHA512KEY, s->sha512digest, digestbuf);
548 1.46 elad }
549 1.46 elad tab = "\t";
550 1.51 elad free(digestbuf);
551 1.46 elad }
552 1.46 elad }
553 1.46 elad #endif /* ! NO_SHA2 */
554 1.34 lukem if (s->flags & F_SLINK &&
555 1.34 lukem strcmp(cp = rlink(p->fts_accpath), s->slink)) {
556 1.1 cgd LABEL;
557 1.58 christos printf(flavor == F_FREEBSD9 ?
558 1.58 christos "%slink ref expected %s found %s" :
559 1.58 christos "%slink ref (%s, %s", tab, cp, s->slink);
560 1.34 lukem if (uflag) {
561 1.34 lukem if ((unlink(p->fts_accpath) == -1) ||
562 1.34 lukem (symlink(s->slink, p->fts_accpath) == -1) )
563 1.58 christos printf(", not modified: %s%s\n",
564 1.58 christos strerror(errno),
565 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
566 1.34 lukem else
567 1.58 christos printf(", modified%s\n",
568 1.58 christos flavor == F_FREEBSD9 ? "" : ")");
569 1.34 lukem } else
570 1.58 christos printf("%s\n", flavor == F_FREEBSD9 ? "" : ")");
571 1.1 cgd }
572 1.4 cgd return (label);
573 1.1 cgd }
574 1.1 cgd
575 1.25 lukem const char *
576 1.25 lukem rlink(const char *name)
577 1.1 cgd {
578 1.35 lukem static char lbuf[MAXPATHLEN];
579 1.13 lukem int len;
580 1.1 cgd
581 1.34 lukem if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1)
582 1.16 wsanchez mtree_err("%s: %s", name, strerror(errno));
583 1.1 cgd lbuf[len] = '\0';
584 1.4 cgd return (lbuf);
585 1.1 cgd }
586