Home | History | Annotate | Line # | Download | only in mtree
compare.c revision 1.53
      1  1.53  christos /*	$NetBSD: compare.c,v 1.53 2012/10/05 00:41:24 christos 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.53  christos __RCSID("$NetBSD: compare.c,v 1.53 2012/10/05 00:41:24 christos 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.24    simonb 
     47  1.24    simonb #include <errno.h>
     48   1.4       cgd #include <fcntl.h>
     49   1.1       cgd #include <stdio.h>
     50  1.50        he #include <stdlib.h>
     51  1.32     lukem #include <string.h>
     52   1.1       cgd #include <time.h>
     53   1.4       cgd #include <unistd.h>
     54  1.24    simonb 
     55  1.36     lukem #ifndef NO_MD5
     56  1.36     lukem #include <md5.h>
     57  1.36     lukem #endif
     58  1.36     lukem #ifndef NO_RMD160
     59  1.49  christos #include <rmd160.h>
     60  1.36     lukem #endif
     61  1.36     lukem #ifndef NO_SHA1
     62  1.36     lukem #include <sha1.h>
     63  1.36     lukem #endif
     64  1.46      elad #ifndef NO_SHA2
     65  1.49  christos #include <sha2.h>
     66  1.46      elad #endif
     67  1.36     lukem 
     68   1.4       cgd #include "extern.h"
     69   1.4       cgd 
     70   1.4       cgd #define	INDENTNAMELEN	8
     71  1.34     lukem #define MARK								\
     72  1.34     lukem do {									\
     73  1.34     lukem 	len = printf("%s: ", RP(p));					\
     74  1.34     lukem 	if (len > INDENTNAMELEN) {					\
     75  1.34     lukem 		tab = "\t";						\
     76  1.34     lukem 		printf("\n");						\
     77  1.34     lukem 	} else {							\
     78  1.34     lukem 		tab = "";						\
     79  1.34     lukem 		printf("%*s", INDENTNAMELEN - (int)len, "");		\
     80  1.34     lukem 	}								\
     81  1.20       mrg } while (0)
     82  1.20       mrg #define	LABEL if (!label++) MARK
     83  1.20       mrg 
     84  1.41     lukem #if HAVE_STRUCT_STAT_ST_FLAGS
     85  1.41     lukem 
     86  1.41     lukem 
     87  1.41     lukem #define CHANGEFLAGS							\
     88  1.41     lukem 	if (flags != p->fts_statp->st_flags) {				\
     89  1.50        he 		char *sf;						\
     90  1.34     lukem 		if (!label) {						\
     91  1.34     lukem 			MARK;						\
     92  1.50        he 			sf = flags_to_string(p->fts_statp->st_flags, "none"); \
     93  1.50        he 			printf("%sflags (\"%s\"", tab, sf);		\
     94  1.50        he 			free(sf);					\
     95  1.34     lukem 		}							\
     96  1.42     lukem 		if (lchflags(p->fts_accpath, flags)) {			\
     97  1.34     lukem 			label++;					\
     98  1.34     lukem 			printf(", not modified: %s)\n",			\
     99  1.34     lukem 			    strerror(errno));				\
    100  1.50        he 		} else {						\
    101  1.50        he 			sf = flags_to_string(flags, "none");		\
    102  1.50        he 			printf(", modified to \"%s\")\n", sf);		\
    103  1.50        he 			free(sf);					\
    104  1.50        he 		}							\
    105   1.4       cgd 	}
    106   1.1       cgd 
    107  1.20       mrg /* SETFLAGS:
    108  1.41     lukem  * given pflags, additionally set those flags specified in s->st_flags and
    109  1.41     lukem  * selected by mask (the other flags are left unchanged).
    110  1.20       mrg  */
    111  1.41     lukem #define SETFLAGS(pflags, mask)						\
    112  1.34     lukem do {									\
    113  1.41     lukem 	flags = (s->st_flags & (mask)) | (pflags);			\
    114  1.41     lukem 	CHANGEFLAGS;							\
    115  1.20       mrg } while (0)
    116  1.20       mrg 
    117  1.20       mrg /* CLEARFLAGS:
    118  1.41     lukem  * given pflags, reset the flags specified in s->st_flags and selected by mask
    119  1.41     lukem  * (the other flags are left unchanged).
    120  1.20       mrg  */
    121  1.41     lukem #define CLEARFLAGS(pflags, mask)					\
    122  1.34     lukem do {									\
    123  1.41     lukem 	flags = (~(s->st_flags & (mask)) & CH_MASK) & (pflags);		\
    124  1.41     lukem 	CHANGEFLAGS;							\
    125  1.20       mrg } while (0)
    126  1.41     lukem #endif	/* HAVE_STRUCT_STAT_ST_FLAGS */
    127  1.20       mrg 
    128   1.4       cgd int
    129  1.34     lukem compare(NODE *s, FTSENT *p)
    130   1.1       cgd {
    131  1.20       mrg 	u_int32_t len, val, flags;
    132   1.4       cgd 	int fd, label;
    133  1.30     lukem 	const char *cp, *tab;
    134  1.46      elad #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)
    135  1.51      elad 	char *digestbuf;
    136  1.36     lukem #endif
    137   1.1       cgd 
    138  1.13     lukem 	tab = NULL;
    139   1.1       cgd 	label = 0;
    140   1.1       cgd 	switch(s->type) {
    141   1.1       cgd 	case F_BLOCK:
    142   1.3   deraadt 		if (!S_ISBLK(p->fts_statp->st_mode))
    143   1.1       cgd 			goto typeerr;
    144   1.1       cgd 		break;
    145   1.1       cgd 	case F_CHAR:
    146   1.3   deraadt 		if (!S_ISCHR(p->fts_statp->st_mode))
    147   1.1       cgd 			goto typeerr;
    148   1.1       cgd 		break;
    149   1.1       cgd 	case F_DIR:
    150   1.3   deraadt 		if (!S_ISDIR(p->fts_statp->st_mode))
    151   1.1       cgd 			goto typeerr;
    152   1.1       cgd 		break;
    153   1.1       cgd 	case F_FIFO:
    154   1.3   deraadt 		if (!S_ISFIFO(p->fts_statp->st_mode))
    155   1.1       cgd 			goto typeerr;
    156   1.1       cgd 		break;
    157   1.1       cgd 	case F_FILE:
    158   1.3   deraadt 		if (!S_ISREG(p->fts_statp->st_mode))
    159   1.1       cgd 			goto typeerr;
    160   1.1       cgd 		break;
    161   1.1       cgd 	case F_LINK:
    162   1.3   deraadt 		if (!S_ISLNK(p->fts_statp->st_mode))
    163   1.1       cgd 			goto typeerr;
    164   1.1       cgd 		break;
    165  1.44       jmc #ifdef S_ISSOCK
    166   1.1       cgd 	case F_SOCK:
    167  1.44       jmc 		if (!S_ISSOCK(p->fts_statp->st_mode))
    168  1.44       jmc 			goto typeerr;
    169   1.1       cgd 		break;
    170  1.44       jmc #endif
    171  1.44       jmc typeerr:		LABEL;
    172  1.44       jmc 		printf("\ttype (%s, %s)\n",
    173  1.44       jmc 		    nodetype(s->type), inotype(p->fts_statp->st_mode));
    174  1.44       jmc 		return (label);
    175   1.1       cgd 	}
    176  1.45     lukem 	if (mtree_Wflag)
    177  1.33     lukem 		goto afterpermwhack;
    178  1.37        tv #if HAVE_STRUCT_STAT_ST_FLAGS
    179  1.20       mrg 	if (iflag && !uflag) {
    180  1.20       mrg 		if (s->flags & F_FLAGS)
    181  1.41     lukem 		    SETFLAGS(p->fts_statp->st_flags, SP_FLGS);
    182  1.20       mrg 		return (label);
    183  1.20       mrg         }
    184  1.20       mrg 	if (mflag && !uflag) {
    185  1.20       mrg 		if (s->flags & F_FLAGS)
    186  1.41     lukem 		    CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS);
    187  1.20       mrg 		return (label);
    188  1.20       mrg         }
    189  1.37        tv #endif
    190  1.34     lukem 	if (s->flags & F_DEV &&
    191  1.34     lukem 	    (s->type == F_BLOCK || s->type == F_CHAR) &&
    192  1.34     lukem 	    s->st_rdev != p->fts_statp->st_rdev) {
    193  1.34     lukem 		LABEL;
    194  1.52  christos 		printf("%sdevice (%#llx, %#llx",
    195  1.52  christos 		    tab, (long long)s->st_rdev,
    196  1.52  christos 		    (long long)p->fts_statp->st_rdev);
    197  1.34     lukem 		if (uflag) {
    198  1.34     lukem 			if ((unlink(p->fts_accpath) == -1) ||
    199  1.34     lukem 			    (mknod(p->fts_accpath,
    200  1.34     lukem 			      s->st_mode | nodetoino(s->type),
    201  1.34     lukem 			      s->st_rdev) == -1) ||
    202  1.39     lukem 			    (lchown(p->fts_accpath, p->fts_statp->st_uid,
    203  1.34     lukem 			      p->fts_statp->st_gid) == -1) )
    204  1.34     lukem 				printf(", not modified: %s)\n",
    205  1.34     lukem 				    strerror(errno));
    206  1.34     lukem 			 else
    207  1.34     lukem 				printf(", modified)\n");
    208  1.34     lukem 		} else
    209  1.34     lukem 			printf(")\n");
    210  1.34     lukem 		tab = "\t";
    211  1.34     lukem 	}
    212   1.4       cgd 	/* Set the uid/gid first, then set the mode. */
    213   1.4       cgd 	if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
    214   1.1       cgd 		LABEL;
    215  1.34     lukem 		printf("%suser (%lu, %lu",
    216  1.19  christos 		    tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
    217  1.19  christos 		if (uflag) {
    218  1.39     lukem 			if (lchown(p->fts_accpath, s->st_uid, -1))
    219  1.34     lukem 				printf(", not modified: %s)\n",
    220   1.1       cgd 				    strerror(errno));
    221   1.1       cgd 			else
    222  1.34     lukem 				printf(", modified)\n");
    223  1.19  christos 		} else
    224  1.34     lukem 			printf(")\n");
    225   1.4       cgd 		tab = "\t";
    226   1.1       cgd 	}
    227   1.4       cgd 	if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
    228   1.1       cgd 		LABEL;
    229  1.34     lukem 		printf("%sgid (%lu, %lu",
    230  1.19  christos 		    tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
    231  1.19  christos 		if (uflag) {
    232  1.39     lukem 			if (lchown(p->fts_accpath, -1, s->st_gid))
    233  1.34     lukem 				printf(", not modified: %s)\n",
    234   1.1       cgd 				    strerror(errno));
    235   1.1       cgd 			else
    236  1.34     lukem 				printf(", modified)\n");
    237  1.19  christos 		}
    238   1.4       cgd 		else
    239  1.34     lukem 			printf(")\n");
    240   1.4       cgd 		tab = "\t";
    241   1.1       cgd 	}
    242   1.4       cgd 	if (s->flags & F_MODE &&
    243   1.4       cgd 	    s->st_mode != (p->fts_statp->st_mode & MBITS)) {
    244  1.26     perry 		if (lflag) {
    245  1.26     perry 			mode_t tmode, mode;
    246  1.26     perry 
    247  1.26     perry 			tmode = s->st_mode;
    248  1.26     perry 			mode = p->fts_statp->st_mode & MBITS;
    249  1.26     perry 			/*
    250  1.26     perry 			 * if none of the suid/sgid/etc bits are set,
    251  1.26     perry 			 * then if the mode is a subset of the target,
    252  1.26     perry 			 * skip.
    253  1.26     perry 			 */
    254  1.26     perry 			if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) ||
    255  1.26     perry 			    (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO))))
    256  1.26     perry 				if ((mode | tmode) == tmode)
    257  1.26     perry 					goto skip;
    258  1.26     perry 		}
    259  1.34     lukem 
    260   1.1       cgd 		LABEL;
    261  1.34     lukem 		printf("%spermissions (%#lo, %#lo",
    262  1.19  christos 		    tab, (u_long)s->st_mode,
    263  1.19  christos 		    (u_long)p->fts_statp->st_mode & MBITS);
    264  1.19  christos 		if (uflag) {
    265  1.39     lukem 			if (lchmod(p->fts_accpath, s->st_mode))
    266  1.34     lukem 				printf(", not modified: %s)\n",
    267   1.1       cgd 				    strerror(errno));
    268   1.1       cgd 			else
    269  1.34     lukem 				printf(", modified)\n");
    270  1.19  christos 		}
    271   1.4       cgd 		else
    272  1.34     lukem 			printf(")\n");
    273   1.4       cgd 		tab = "\t";
    274  1.31     lukem 	skip:	;
    275  1.29     lukem 	}
    276   1.1       cgd 	if (s->flags & F_NLINK && s->type != F_DIR &&
    277   1.3   deraadt 	    s->st_nlink != p->fts_statp->st_nlink) {
    278   1.1       cgd 		LABEL;
    279  1.34     lukem 		printf("%slink count (%lu, %lu)\n",
    280  1.19  christos 		    tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink);
    281   1.4       cgd 		tab = "\t";
    282   1.1       cgd 	}
    283   1.3   deraadt 	if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
    284   1.1       cgd 		LABEL;
    285  1.34     lukem 		printf("%ssize (%lld, %lld)\n",
    286  1.14     enami 		    tab, (long long)s->st_size,
    287  1.14     enami 		    (long long)p->fts_statp->st_size);
    288   1.4       cgd 		tab = "\t";
    289   1.4       cgd 	}
    290   1.7       cgd 	/*
    291   1.7       cgd 	 * XXX
    292  1.11   mycroft 	 * Since utimes(2) only takes a timeval, there's no point in
    293  1.11   mycroft 	 * comparing the low bits of the timespec nanosecond field.  This
    294  1.11   mycroft 	 * will only result in mismatches that we can never fix.
    295  1.11   mycroft 	 *
    296  1.11   mycroft 	 * Doesn't display microsecond differences.
    297   1.7       cgd 	 */
    298  1.11   mycroft 	if (s->flags & F_TIME) {
    299  1.11   mycroft 		struct timeval tv[2];
    300  1.21  christos 		struct stat *ps = p->fts_statp;
    301  1.22  christos 		time_t smtime = s->st_mtimespec.tv_sec;
    302  1.22  christos 
    303  1.44       jmc #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H)
    304  1.21  christos 		time_t pmtime = ps->st_mtimespec.tv_sec;
    305  1.11   mycroft 
    306  1.37        tv 		TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec);
    307  1.21  christos 		TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec);
    308  1.21  christos #else
    309  1.22  christos 		time_t pmtime = (time_t)ps->st_mtime;
    310  1.21  christos 
    311  1.37        tv 		tv[0].tv_sec = smtime;
    312  1.37        tv 		tv[0].tv_usec = 0;
    313  1.37        tv 		tv[1].tv_sec = pmtime;
    314  1.21  christos 		tv[1].tv_usec = 0;
    315  1.21  christos #endif
    316  1.21  christos 
    317  1.11   mycroft 		if (tv[0].tv_sec != tv[1].tv_sec ||
    318  1.11   mycroft 		    tv[0].tv_usec != tv[1].tv_usec) {
    319  1.11   mycroft 			LABEL;
    320  1.34     lukem 			printf("%smodification time (%.24s, ",
    321  1.21  christos 			    tab, ctime(&smtime));
    322  1.34     lukem 			printf("%.24s", ctime(&pmtime));
    323  1.11   mycroft 			if (tflag) {
    324  1.11   mycroft 				tv[1] = tv[0];
    325  1.11   mycroft 				if (utimes(p->fts_accpath, tv))
    326  1.34     lukem 					printf(", not modified: %s)\n",
    327  1.11   mycroft 					    strerror(errno));
    328  1.11   mycroft 				else
    329  1.34     lukem 					printf(", modified)\n");
    330  1.11   mycroft 			} else
    331  1.34     lukem 				printf(")\n");
    332  1.11   mycroft 			tab = "\t";
    333  1.11   mycroft 		}
    334  1.17       mrg 	}
    335  1.37        tv #if HAVE_STRUCT_STAT_ST_FLAGS
    336  1.17       mrg 	/*
    337  1.17       mrg 	 * XXX
    338  1.39     lukem 	 * since lchflags(2) will reset file times, the utimes() above
    339  1.17       mrg 	 * may have been useless!  oh well, we'd rather have correct
    340  1.17       mrg 	 * flags, rather than times?
    341  1.17       mrg 	 */
    342  1.20       mrg         if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags)
    343  1.20       mrg 	    || mflag || iflag)) {
    344  1.20       mrg 		if (s->st_flags != p->fts_statp->st_flags) {
    345  1.50        he 			char *f_s;
    346  1.20       mrg 			LABEL;
    347  1.50        he 			f_s = flags_to_string(s->st_flags, "none");
    348  1.50        he 			printf("%sflags (\"%s\" is not ", tab, f_s);
    349  1.50        he 			free(f_s);
    350  1.50        he 			f_s = flags_to_string(p->fts_statp->st_flags, "none");
    351  1.50        he 			printf("\"%s\"", f_s);
    352  1.50        he 			free(f_s);
    353  1.20       mrg 		}
    354  1.19  christos 		if (uflag) {
    355  1.20       mrg 			if (iflag)
    356  1.41     lukem 				SETFLAGS(0, CH_MASK);
    357  1.20       mrg 			else if (mflag)
    358  1.41     lukem 				CLEARFLAGS(0, SP_FLGS);
    359  1.17       mrg 			else
    360  1.41     lukem 				SETFLAGS(0, (~SP_FLGS & CH_MASK));
    361  1.19  christos 		} else
    362  1.34     lukem 			printf(")\n");
    363  1.17       mrg 		tab = "\t";
    364   1.1       cgd 	}
    365  1.41     lukem #endif	/* HAVE_STRUCT_STAT_ST_FLAGS */
    366  1.33     lukem 
    367  1.33     lukem 	/*
    368  1.33     lukem 	 * from this point, no more permission checking or whacking
    369  1.33     lukem 	 * occurs, only checking of stuff like checksums and symlinks.
    370  1.33     lukem 	 */
    371  1.33     lukem  afterpermwhack:
    372  1.15      ross 	if (s->flags & F_CKSUM) {
    373   1.4       cgd 		if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
    374   1.4       cgd 			LABEL;
    375  1.34     lukem 			printf("%scksum: %s: %s\n",
    376   1.4       cgd 			    tab, p->fts_accpath, strerror(errno));
    377   1.4       cgd 			tab = "\t";
    378   1.4       cgd 		} else if (crc(fd, &val, &len)) {
    379  1.34     lukem 			close(fd);
    380   1.1       cgd 			LABEL;
    381  1.34     lukem 			printf("%scksum: %s: %s\n",
    382   1.4       cgd 			    tab, p->fts_accpath, strerror(errno));
    383   1.4       cgd 			tab = "\t";
    384   1.4       cgd 		} else {
    385  1.34     lukem 			close(fd);
    386   1.4       cgd 			if (s->cksum != val) {
    387   1.4       cgd 				LABEL;
    388  1.34     lukem 				printf("%scksum (%lu, %lu)\n",
    389  1.16  wsanchez 				    tab, s->cksum, (unsigned long)val);
    390   1.4       cgd 			}
    391   1.4       cgd 			tab = "\t";
    392   1.1       cgd 		}
    393  1.15      ross 	}
    394  1.36     lukem #ifndef NO_MD5
    395  1.18     jwise 	if (s->flags & F_MD5) {
    396  1.51      elad 		if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL) {
    397  1.18     jwise 			LABEL;
    398  1.34     lukem 			printf("%smd5: %s: %s\n",
    399  1.18     jwise 			    tab, p->fts_accpath, strerror(errno));
    400  1.18     jwise 			tab = "\t";
    401  1.18     jwise 		} else {
    402  1.34     lukem 			if (strcmp(s->md5digest, digestbuf)) {
    403  1.18     jwise 				LABEL;
    404  1.34     lukem 				printf("%smd5 (0x%s, 0x%s)\n",
    405  1.34     lukem 				    tab, s->md5digest, digestbuf);
    406  1.18     jwise 			}
    407  1.18     jwise 			tab = "\t";
    408  1.51      elad 			free(digestbuf);
    409  1.18     jwise 		}
    410  1.18     jwise 	}
    411  1.36     lukem #endif	/* ! NO_MD5 */
    412  1.36     lukem #ifndef NO_RMD160
    413  1.34     lukem 	if (s->flags & F_RMD160) {
    414  1.51      elad 		if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL) {
    415  1.34     lukem 			LABEL;
    416  1.34     lukem 			printf("%srmd160: %s: %s\n",
    417  1.34     lukem 			    tab, p->fts_accpath, strerror(errno));
    418  1.34     lukem 			tab = "\t";
    419  1.34     lukem 		} else {
    420  1.34     lukem 			if (strcmp(s->rmd160digest, digestbuf)) {
    421  1.34     lukem 				LABEL;
    422  1.34     lukem 				printf("%srmd160 (0x%s, 0x%s)\n",
    423  1.34     lukem 				    tab, s->rmd160digest, digestbuf);
    424  1.34     lukem 			}
    425  1.34     lukem 			tab = "\t";
    426  1.51      elad 			free(digestbuf);
    427  1.34     lukem 		}
    428  1.34     lukem 	}
    429  1.36     lukem #endif	/* ! NO_RMD160 */
    430  1.36     lukem #ifndef NO_SHA1
    431  1.34     lukem 	if (s->flags & F_SHA1) {
    432  1.51      elad 		if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL) {
    433  1.34     lukem 			LABEL;
    434  1.34     lukem 			printf("%ssha1: %s: %s\n",
    435  1.34     lukem 			    tab, p->fts_accpath, strerror(errno));
    436  1.34     lukem 			tab = "\t";
    437  1.34     lukem 		} else {
    438  1.34     lukem 			if (strcmp(s->sha1digest, digestbuf)) {
    439  1.34     lukem 				LABEL;
    440  1.34     lukem 				printf("%ssha1 (0x%s, 0x%s)\n",
    441  1.34     lukem 				    tab, s->sha1digest, digestbuf);
    442  1.34     lukem 			}
    443  1.34     lukem 			tab = "\t";
    444  1.51      elad 			free(digestbuf);
    445  1.34     lukem 		}
    446  1.34     lukem 	}
    447  1.36     lukem #endif	/* ! NO_SHA1 */
    448  1.46      elad #ifndef NO_SHA2
    449  1.46      elad 	if (s->flags & F_SHA256) {
    450  1.51      elad 		if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL) {
    451  1.46      elad 			LABEL;
    452  1.46      elad 			printf("%ssha256: %s: %s\n",
    453  1.46      elad 			    tab, p->fts_accpath, strerror(errno));
    454  1.46      elad 			tab = "\t";
    455  1.46      elad 		} else {
    456  1.46      elad 			if (strcmp(s->sha256digest, digestbuf)) {
    457  1.46      elad 				LABEL;
    458  1.46      elad 				printf("%ssha256 (0x%s, 0x%s)\n",
    459  1.46      elad 				    tab, s->sha256digest, digestbuf);
    460  1.46      elad 			}
    461  1.46      elad 			tab = "\t";
    462  1.51      elad 			free(digestbuf);
    463  1.46      elad 		}
    464  1.46      elad 	}
    465  1.53  christos #ifdef SHA384_BLOCK_LENGTH
    466  1.46      elad 	if (s->flags & F_SHA384) {
    467  1.51      elad 		if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL) {
    468  1.46      elad 			LABEL;
    469  1.46      elad 			printf("%ssha384: %s: %s\n",
    470  1.46      elad 			    tab, p->fts_accpath, strerror(errno));
    471  1.46      elad 			tab = "\t";
    472  1.46      elad 		} else {
    473  1.46      elad 			if (strcmp(s->sha384digest, digestbuf)) {
    474  1.46      elad 				LABEL;
    475  1.46      elad 				printf("%ssha384 (0x%s, 0x%s)\n",
    476  1.46      elad 				    tab, s->sha384digest, digestbuf);
    477  1.46      elad 			}
    478  1.46      elad 			tab = "\t";
    479  1.51      elad 			free(digestbuf);
    480  1.46      elad 		}
    481  1.46      elad 	}
    482  1.53  christos #endif
    483  1.46      elad 	if (s->flags & F_SHA512) {
    484  1.51      elad 		if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL) {
    485  1.46      elad 			LABEL;
    486  1.46      elad 			printf("%ssha512: %s: %s\n",
    487  1.46      elad 			    tab, p->fts_accpath, strerror(errno));
    488  1.46      elad 			tab = "\t";
    489  1.46      elad 		} else {
    490  1.46      elad 			if (strcmp(s->sha512digest, digestbuf)) {
    491  1.46      elad 				LABEL;
    492  1.46      elad 				printf("%ssha512 (0x%s, 0x%s)\n",
    493  1.46      elad 				    tab, s->sha512digest, digestbuf);
    494  1.46      elad 			}
    495  1.46      elad 			tab = "\t";
    496  1.51      elad 			free(digestbuf);
    497  1.46      elad 		}
    498  1.46      elad 	}
    499  1.46      elad #endif	/* ! NO_SHA2 */
    500  1.34     lukem 	if (s->flags & F_SLINK &&
    501  1.34     lukem 	    strcmp(cp = rlink(p->fts_accpath), s->slink)) {
    502   1.1       cgd 		LABEL;
    503  1.34     lukem 		printf("%slink ref (%s, %s", tab, cp, s->slink);
    504  1.34     lukem 		if (uflag) {
    505  1.34     lukem 			if ((unlink(p->fts_accpath) == -1) ||
    506  1.34     lukem 			    (symlink(s->slink, p->fts_accpath) == -1) )
    507  1.34     lukem 				printf(", not modified: %s)\n",
    508  1.34     lukem 				    strerror(errno));
    509  1.34     lukem 			else
    510  1.34     lukem 				printf(", modified)\n");
    511  1.34     lukem 		} else
    512  1.34     lukem 			printf(")\n");
    513   1.1       cgd 	}
    514   1.4       cgd 	return (label);
    515   1.1       cgd }
    516   1.1       cgd 
    517  1.25     lukem const char *
    518  1.25     lukem rlink(const char *name)
    519   1.1       cgd {
    520  1.35     lukem 	static char lbuf[MAXPATHLEN];
    521  1.13     lukem 	int len;
    522   1.1       cgd 
    523  1.34     lukem 	if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1)
    524  1.16  wsanchez 		mtree_err("%s: %s", name, strerror(errno));
    525   1.1       cgd 	lbuf[len] = '\0';
    526   1.4       cgd 	return (lbuf);
    527   1.1       cgd }
    528