Home | History | Annotate | Line # | Download | only in mtree
compare.c revision 1.37
      1  1.37        tv /*	$NetBSD: compare.c,v 1.37 2002/01/29 00:07:27 tv 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.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.13     lukem #include <sys/cdefs.h>
     37   1.1       cgd #ifndef 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.37        tv __RCSID("$NetBSD: compare.c,v 1.37 2002/01/29 00:07:27 tv 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.32     lukem #include <string.h>
     51   1.1       cgd #include <time.h>
     52   1.4       cgd #include <unistd.h>
     53  1.24    simonb 
     54  1.36     lukem #ifndef NO_MD5
     55  1.36     lukem #include <md5.h>
     56  1.36     lukem #endif
     57  1.36     lukem #ifndef NO_RMD160
     58  1.36     lukem #include <rmd160.h>
     59  1.36     lukem #endif
     60  1.36     lukem #ifndef NO_SHA1
     61  1.36     lukem #include <sha1.h>
     62  1.36     lukem #endif
     63  1.36     lukem 
     64   1.4       cgd #include "extern.h"
     65   1.4       cgd 
     66   1.4       cgd #define	INDENTNAMELEN	8
     67  1.34     lukem #define MARK								\
     68  1.34     lukem do {									\
     69  1.34     lukem 	len = printf("%s: ", RP(p));					\
     70  1.34     lukem 	if (len > INDENTNAMELEN) {					\
     71  1.34     lukem 		tab = "\t";						\
     72  1.34     lukem 		printf("\n");						\
     73  1.34     lukem 	} else {							\
     74  1.34     lukem 		tab = "";						\
     75  1.34     lukem 		printf("%*s", INDENTNAMELEN - (int)len, "");		\
     76  1.34     lukem 	}								\
     77  1.20       mrg } while (0)
     78  1.20       mrg #define	LABEL if (!label++) MARK
     79  1.20       mrg 
     80  1.34     lukem #define CHANGEFLAGS(path, oflags)					\
     81  1.34     lukem 	if (flags != (oflags)) {					\
     82  1.34     lukem 		if (!label) {						\
     83  1.34     lukem 			MARK;						\
     84  1.34     lukem 			printf("%sflags (\"%s\"", tab,			\
     85  1.20       mrg 			    flags_to_string(p->fts_statp->st_flags, "none")); \
     86  1.34     lukem 		}							\
     87  1.34     lukem 		if (chflags(path, flags)) {				\
     88  1.34     lukem 			label++;					\
     89  1.34     lukem 			printf(", not modified: %s)\n",			\
     90  1.34     lukem 			    strerror(errno));				\
     91  1.34     lukem 		} else							\
     92  1.34     lukem 			printf(", modified to \"%s\")\n",		\
     93  1.34     lukem 			     flags_to_string(flags, "none"));		\
     94   1.4       cgd 	}
     95   1.1       cgd 
     96  1.20       mrg /* SETFLAGS:
     97  1.20       mrg  * given pflags, additionally set those flags specified in sflags and
     98  1.20       mrg  * selected by mask (the other flags are left unchanged). oflags is
     99  1.20       mrg  * passed as reference to check if chflags is necessary.
    100  1.20       mrg  */
    101  1.34     lukem #define SETFLAGS(path, sflags, pflags, oflags, mask)			\
    102  1.34     lukem do {									\
    103  1.34     lukem 	flags = ((sflags) & (mask)) | (pflags);				\
    104  1.34     lukem 	CHANGEFLAGS(path, oflags);					\
    105  1.20       mrg } while (0)
    106  1.20       mrg 
    107  1.20       mrg /* CLEARFLAGS:
    108  1.20       mrg  * given pflags, reset the flags specified in sflags and selected by mask
    109  1.20       mrg  * (the other flags are left unchanged). oflags is
    110  1.20       mrg  * passed as reference to check if chflags is necessary.
    111  1.20       mrg  */
    112  1.34     lukem #define CLEARFLAGS(path, sflags, pflags, oflags, mask)			\
    113  1.34     lukem do {									\
    114  1.34     lukem 	flags = (~((sflags) & (mask)) & CH_MASK) & (pflags);		\
    115  1.34     lukem 	CHANGEFLAGS(path, oflags);					\
    116  1.20       mrg } while (0)
    117  1.20       mrg 
    118   1.4       cgd int
    119  1.34     lukem compare(NODE *s, FTSENT *p)
    120   1.1       cgd {
    121  1.20       mrg 	u_int32_t len, val, flags;
    122   1.4       cgd 	int fd, label;
    123  1.30     lukem 	const char *cp, *tab;
    124  1.36     lukem #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1)
    125  1.34     lukem 	char digestbuf[41];	/* large enough for {MD5,RMD160,SHA1}File() */
    126  1.36     lukem #endif
    127   1.1       cgd 
    128  1.13     lukem 	tab = NULL;
    129   1.1       cgd 	label = 0;
    130   1.1       cgd 	switch(s->type) {
    131   1.1       cgd 	case F_BLOCK:
    132   1.3   deraadt 		if (!S_ISBLK(p->fts_statp->st_mode))
    133   1.1       cgd 			goto typeerr;
    134   1.1       cgd 		break;
    135   1.1       cgd 	case F_CHAR:
    136   1.3   deraadt 		if (!S_ISCHR(p->fts_statp->st_mode))
    137   1.1       cgd 			goto typeerr;
    138   1.1       cgd 		break;
    139   1.1       cgd 	case F_DIR:
    140   1.3   deraadt 		if (!S_ISDIR(p->fts_statp->st_mode))
    141   1.1       cgd 			goto typeerr;
    142   1.1       cgd 		break;
    143   1.1       cgd 	case F_FIFO:
    144   1.3   deraadt 		if (!S_ISFIFO(p->fts_statp->st_mode))
    145   1.1       cgd 			goto typeerr;
    146   1.1       cgd 		break;
    147   1.1       cgd 	case F_FILE:
    148   1.3   deraadt 		if (!S_ISREG(p->fts_statp->st_mode))
    149   1.1       cgd 			goto typeerr;
    150   1.1       cgd 		break;
    151   1.1       cgd 	case F_LINK:
    152   1.3   deraadt 		if (!S_ISLNK(p->fts_statp->st_mode))
    153   1.1       cgd 			goto typeerr;
    154   1.1       cgd 		break;
    155   1.1       cgd 	case F_SOCK:
    156   1.4       cgd 		if (!S_ISSOCK(p->fts_statp->st_mode)) {
    157  1.34     lukem  typeerr:		LABEL;
    158  1.34     lukem 			printf("\ttype (%s, %s)\n",
    159  1.27     lukem 			    nodetype(s->type), inotype(p->fts_statp->st_mode));
    160  1.34     lukem 			return (label);
    161   1.1       cgd 		}
    162   1.1       cgd 		break;
    163   1.1       cgd 	}
    164  1.33     lukem 	if (Wflag)
    165  1.33     lukem 		goto afterpermwhack;
    166  1.37        tv #if HAVE_STRUCT_STAT_ST_FLAGS
    167  1.20       mrg 	if (iflag && !uflag) {
    168  1.20       mrg 		if (s->flags & F_FLAGS)
    169  1.20       mrg 		    SETFLAGS(p->fts_accpath, s->st_flags,
    170  1.20       mrg 			p->fts_statp->st_flags, p->fts_statp->st_flags,
    171  1.20       mrg 			SP_FLGS);
    172  1.20       mrg 		return (label);
    173  1.20       mrg         }
    174  1.20       mrg 	if (mflag && !uflag) {
    175  1.20       mrg 		if (s->flags & F_FLAGS)
    176  1.34     lukem 		    CLEARFLAGS(p->fts_accpath, s->st_flags,
    177  1.20       mrg 			p->fts_statp->st_flags, p->fts_statp->st_flags,
    178  1.20       mrg 			SP_FLGS);
    179  1.20       mrg 		return (label);
    180  1.20       mrg         }
    181  1.37        tv #endif
    182  1.34     lukem 	if (s->flags & F_DEV &&
    183  1.34     lukem 	    (s->type == F_BLOCK || s->type == F_CHAR) &&
    184  1.34     lukem 	    s->st_rdev != p->fts_statp->st_rdev) {
    185  1.34     lukem 		LABEL;
    186  1.34     lukem 		printf("%sdevice (%#x, %#x",
    187  1.34     lukem 		    tab, s->st_rdev, p->fts_statp->st_rdev);
    188  1.34     lukem 		if (uflag) {
    189  1.34     lukem 			if ((unlink(p->fts_accpath) == -1) ||
    190  1.34     lukem 			    (mknod(p->fts_accpath,
    191  1.34     lukem 			      s->st_mode | nodetoino(s->type),
    192  1.34     lukem 			      s->st_rdev) == -1) ||
    193  1.34     lukem 			    (chown(p->fts_accpath, p->fts_statp->st_uid,
    194  1.34     lukem 			      p->fts_statp->st_gid) == -1) )
    195  1.34     lukem 				printf(", not modified: %s)\n",
    196  1.34     lukem 				    strerror(errno));
    197  1.34     lukem 			 else
    198  1.34     lukem 				printf(", modified)\n");
    199  1.34     lukem 		} else
    200  1.34     lukem 			printf(")\n");
    201  1.34     lukem 		tab = "\t";
    202  1.34     lukem 	}
    203   1.4       cgd 	/* Set the uid/gid first, then set the mode. */
    204   1.4       cgd 	if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
    205   1.1       cgd 		LABEL;
    206  1.34     lukem 		printf("%suser (%lu, %lu",
    207  1.19  christos 		    tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
    208  1.19  christos 		if (uflag) {
    209   1.4       cgd 			if (chown(p->fts_accpath, s->st_uid, -1))
    210  1.34     lukem 				printf(", not modified: %s)\n",
    211   1.1       cgd 				    strerror(errno));
    212   1.1       cgd 			else
    213  1.34     lukem 				printf(", modified)\n");
    214  1.19  christos 		} else
    215  1.34     lukem 			printf(")\n");
    216   1.4       cgd 		tab = "\t";
    217   1.1       cgd 	}
    218   1.4       cgd 	if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
    219   1.1       cgd 		LABEL;
    220  1.34     lukem 		printf("%sgid (%lu, %lu",
    221  1.19  christos 		    tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
    222  1.19  christos 		if (uflag) {
    223   1.4       cgd 			if (chown(p->fts_accpath, -1, s->st_gid))
    224  1.34     lukem 				printf(", not modified: %s)\n",
    225   1.1       cgd 				    strerror(errno));
    226   1.1       cgd 			else
    227  1.34     lukem 				printf(", modified)\n");
    228  1.19  christos 		}
    229   1.4       cgd 		else
    230  1.34     lukem 			printf(")\n");
    231   1.4       cgd 		tab = "\t";
    232   1.1       cgd 	}
    233   1.4       cgd 	if (s->flags & F_MODE &&
    234   1.4       cgd 	    s->st_mode != (p->fts_statp->st_mode & MBITS)) {
    235  1.26     perry 		if (lflag) {
    236  1.26     perry 			mode_t tmode, mode;
    237  1.26     perry 
    238  1.26     perry 			tmode = s->st_mode;
    239  1.26     perry 			mode = p->fts_statp->st_mode & MBITS;
    240  1.26     perry 			/*
    241  1.26     perry 			 * if none of the suid/sgid/etc bits are set,
    242  1.26     perry 			 * then if the mode is a subset of the target,
    243  1.26     perry 			 * skip.
    244  1.26     perry 			 */
    245  1.26     perry 			if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) ||
    246  1.26     perry 			    (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO))))
    247  1.26     perry 				if ((mode | tmode) == tmode)
    248  1.26     perry 					goto skip;
    249  1.26     perry 		}
    250  1.34     lukem 
    251   1.1       cgd 		LABEL;
    252  1.34     lukem 		printf("%spermissions (%#lo, %#lo",
    253  1.19  christos 		    tab, (u_long)s->st_mode,
    254  1.19  christos 		    (u_long)p->fts_statp->st_mode & MBITS);
    255  1.19  christos 		if (uflag) {
    256   1.4       cgd 			if (chmod(p->fts_accpath, s->st_mode))
    257  1.34     lukem 				printf(", not modified: %s)\n",
    258   1.1       cgd 				    strerror(errno));
    259   1.1       cgd 			else
    260  1.34     lukem 				printf(", modified)\n");
    261  1.19  christos 		}
    262   1.4       cgd 		else
    263  1.34     lukem 			printf(")\n");
    264   1.4       cgd 		tab = "\t";
    265  1.31     lukem 	skip:	;
    266  1.29     lukem 	}
    267   1.1       cgd 	if (s->flags & F_NLINK && s->type != F_DIR &&
    268   1.3   deraadt 	    s->st_nlink != p->fts_statp->st_nlink) {
    269   1.1       cgd 		LABEL;
    270  1.34     lukem 		printf("%slink count (%lu, %lu)\n",
    271  1.19  christos 		    tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink);
    272   1.4       cgd 		tab = "\t";
    273   1.1       cgd 	}
    274   1.3   deraadt 	if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
    275   1.1       cgd 		LABEL;
    276  1.34     lukem 		printf("%ssize (%lld, %lld)\n",
    277  1.14     enami 		    tab, (long long)s->st_size,
    278  1.14     enami 		    (long long)p->fts_statp->st_size);
    279   1.4       cgd 		tab = "\t";
    280   1.4       cgd 	}
    281   1.7       cgd 	/*
    282   1.7       cgd 	 * XXX
    283  1.11   mycroft 	 * Since utimes(2) only takes a timeval, there's no point in
    284  1.11   mycroft 	 * comparing the low bits of the timespec nanosecond field.  This
    285  1.11   mycroft 	 * will only result in mismatches that we can never fix.
    286  1.11   mycroft 	 *
    287  1.11   mycroft 	 * Doesn't display microsecond differences.
    288   1.7       cgd 	 */
    289  1.11   mycroft 	if (s->flags & F_TIME) {
    290  1.11   mycroft 		struct timeval tv[2];
    291  1.21  christos 		struct stat *ps = p->fts_statp;
    292  1.22  christos 		time_t smtime = s->st_mtimespec.tv_sec;
    293  1.22  christos 
    294  1.21  christos #ifdef BSD4_4
    295  1.21  christos 		time_t pmtime = ps->st_mtimespec.tv_sec;
    296  1.11   mycroft 
    297  1.37        tv 		TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec);
    298  1.21  christos 		TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec);
    299  1.21  christos #else
    300  1.22  christos 		time_t pmtime = (time_t)ps->st_mtime;
    301  1.21  christos 
    302  1.37        tv 		tv[0].tv_sec = smtime;
    303  1.37        tv 		tv[0].tv_usec = 0;
    304  1.37        tv 		tv[1].tv_sec = pmtime;
    305  1.21  christos 		tv[1].tv_usec = 0;
    306  1.21  christos #endif
    307  1.21  christos 
    308  1.11   mycroft 		if (tv[0].tv_sec != tv[1].tv_sec ||
    309  1.11   mycroft 		    tv[0].tv_usec != tv[1].tv_usec) {
    310  1.11   mycroft 			LABEL;
    311  1.34     lukem 			printf("%smodification time (%.24s, ",
    312  1.21  christos 			    tab, ctime(&smtime));
    313  1.34     lukem 			printf("%.24s", ctime(&pmtime));
    314  1.11   mycroft 			if (tflag) {
    315  1.11   mycroft 				tv[1] = tv[0];
    316  1.11   mycroft 				if (utimes(p->fts_accpath, tv))
    317  1.34     lukem 					printf(", not modified: %s)\n",
    318  1.11   mycroft 					    strerror(errno));
    319  1.11   mycroft 				else
    320  1.34     lukem 					printf(", modified)\n");
    321  1.11   mycroft 			} else
    322  1.34     lukem 				printf(")\n");
    323  1.11   mycroft 			tab = "\t";
    324  1.11   mycroft 		}
    325  1.17       mrg 	}
    326  1.37        tv #if HAVE_STRUCT_STAT_ST_FLAGS
    327  1.17       mrg 	/*
    328  1.17       mrg 	 * XXX
    329  1.17       mrg 	 * since chflags(2) will reset file times, the utimes() above
    330  1.17       mrg 	 * may have been useless!  oh well, we'd rather have correct
    331  1.17       mrg 	 * flags, rather than times?
    332  1.17       mrg 	 */
    333  1.20       mrg         if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags)
    334  1.20       mrg 	    || mflag || iflag)) {
    335  1.20       mrg 		if (s->st_flags != p->fts_statp->st_flags) {
    336  1.20       mrg 			LABEL;
    337  1.34     lukem 			printf("%sflags (\"%s\" is not ", tab,
    338  1.20       mrg 			    flags_to_string(s->st_flags, "none"));
    339  1.34     lukem 			printf("\"%s\"",
    340  1.20       mrg 			    flags_to_string(p->fts_statp->st_flags, "none"));
    341  1.20       mrg 		}
    342  1.19  christos 		if (uflag) {
    343  1.20       mrg 			if (iflag)
    344  1.20       mrg 				SETFLAGS(p->fts_accpath, s->st_flags,
    345  1.20       mrg 				    0, p->fts_statp->st_flags, CH_MASK);
    346  1.20       mrg 			else if (mflag)
    347  1.20       mrg 				CLEARFLAGS(p->fts_accpath, s->st_flags,
    348  1.20       mrg 				    0, p->fts_statp->st_flags, SP_FLGS);
    349  1.17       mrg 			else
    350  1.20       mrg 				SETFLAGS(p->fts_accpath, s->st_flags,
    351  1.20       mrg 			     	    0, p->fts_statp->st_flags,
    352  1.20       mrg 				    (~SP_FLGS & CH_MASK));
    353  1.19  christos 		} else
    354  1.34     lukem 			printf(")\n");
    355  1.17       mrg 		tab = "\t";
    356   1.1       cgd 	}
    357  1.37        tv #endif
    358  1.33     lukem 
    359  1.33     lukem 	/*
    360  1.33     lukem 	 * from this point, no more permission checking or whacking
    361  1.33     lukem 	 * occurs, only checking of stuff like checksums and symlinks.
    362  1.33     lukem 	 */
    363  1.33     lukem  afterpermwhack:
    364  1.15      ross 	if (s->flags & F_CKSUM) {
    365   1.4       cgd 		if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
    366   1.4       cgd 			LABEL;
    367  1.34     lukem 			printf("%scksum: %s: %s\n",
    368   1.4       cgd 			    tab, p->fts_accpath, strerror(errno));
    369   1.4       cgd 			tab = "\t";
    370   1.4       cgd 		} else if (crc(fd, &val, &len)) {
    371  1.34     lukem 			close(fd);
    372   1.1       cgd 			LABEL;
    373  1.34     lukem 			printf("%scksum: %s: %s\n",
    374   1.4       cgd 			    tab, p->fts_accpath, strerror(errno));
    375   1.4       cgd 			tab = "\t";
    376   1.4       cgd 		} else {
    377  1.34     lukem 			close(fd);
    378   1.4       cgd 			if (s->cksum != val) {
    379   1.4       cgd 				LABEL;
    380  1.34     lukem 				printf("%scksum (%lu, %lu)\n",
    381  1.16  wsanchez 				    tab, s->cksum, (unsigned long)val);
    382   1.4       cgd 			}
    383   1.4       cgd 			tab = "\t";
    384   1.1       cgd 		}
    385  1.15      ross 	}
    386  1.36     lukem #ifndef NO_MD5
    387  1.18     jwise 	if (s->flags & F_MD5) {
    388  1.34     lukem 		if (MD5File(p->fts_accpath, digestbuf) == NULL) {
    389  1.18     jwise 			LABEL;
    390  1.34     lukem 			printf("%smd5: %s: %s\n",
    391  1.18     jwise 			    tab, p->fts_accpath, strerror(errno));
    392  1.18     jwise 			tab = "\t";
    393  1.18     jwise 		} else {
    394  1.34     lukem 			if (strcmp(s->md5digest, digestbuf)) {
    395  1.18     jwise 				LABEL;
    396  1.34     lukem 				printf("%smd5 (0x%s, 0x%s)\n",
    397  1.34     lukem 				    tab, s->md5digest, digestbuf);
    398  1.18     jwise 			}
    399  1.18     jwise 			tab = "\t";
    400  1.18     jwise 		}
    401  1.18     jwise 	}
    402  1.36     lukem #endif	/* ! NO_MD5 */
    403  1.36     lukem #ifndef NO_RMD160
    404  1.34     lukem 	if (s->flags & F_RMD160) {
    405  1.34     lukem 		if (RMD160File(p->fts_accpath, digestbuf) == NULL) {
    406  1.34     lukem 			LABEL;
    407  1.34     lukem 			printf("%srmd160: %s: %s\n",
    408  1.34     lukem 			    tab, p->fts_accpath, strerror(errno));
    409  1.34     lukem 			tab = "\t";
    410  1.34     lukem 		} else {
    411  1.34     lukem 			if (strcmp(s->rmd160digest, digestbuf)) {
    412  1.34     lukem 				LABEL;
    413  1.34     lukem 				printf("%srmd160 (0x%s, 0x%s)\n",
    414  1.34     lukem 				    tab, s->rmd160digest, digestbuf);
    415  1.34     lukem 			}
    416  1.34     lukem 			tab = "\t";
    417  1.34     lukem 		}
    418  1.34     lukem 	}
    419  1.36     lukem #endif	/* ! NO_RMD160 */
    420  1.36     lukem #ifndef NO_SHA1
    421  1.34     lukem 	if (s->flags & F_SHA1) {
    422  1.34     lukem 		if (SHA1File(p->fts_accpath, digestbuf) == NULL) {
    423  1.34     lukem 			LABEL;
    424  1.34     lukem 			printf("%ssha1: %s: %s\n",
    425  1.34     lukem 			    tab, p->fts_accpath, strerror(errno));
    426  1.34     lukem 			tab = "\t";
    427  1.34     lukem 		} else {
    428  1.34     lukem 			if (strcmp(s->sha1digest, digestbuf)) {
    429  1.34     lukem 				LABEL;
    430  1.34     lukem 				printf("%ssha1 (0x%s, 0x%s)\n",
    431  1.34     lukem 				    tab, s->sha1digest, digestbuf);
    432  1.34     lukem 			}
    433  1.34     lukem 			tab = "\t";
    434  1.34     lukem 		}
    435  1.34     lukem 	}
    436  1.36     lukem #endif	/* ! NO_SHA1 */
    437  1.34     lukem 	if (s->flags & F_SLINK &&
    438  1.34     lukem 	    strcmp(cp = rlink(p->fts_accpath), s->slink)) {
    439   1.1       cgd 		LABEL;
    440  1.34     lukem 		printf("%slink ref (%s, %s", tab, cp, s->slink);
    441  1.34     lukem 		if (uflag) {
    442  1.34     lukem 			if ((unlink(p->fts_accpath) == -1) ||
    443  1.34     lukem 			    (symlink(s->slink, p->fts_accpath) == -1) )
    444  1.34     lukem 				printf(", not modified: %s)\n",
    445  1.34     lukem 				    strerror(errno));
    446  1.34     lukem 			else
    447  1.34     lukem 				printf(", modified)\n");
    448  1.34     lukem 		} else
    449  1.34     lukem 			printf(")\n");
    450   1.1       cgd 	}
    451   1.4       cgd 	return (label);
    452   1.1       cgd }
    453   1.1       cgd 
    454  1.25     lukem const char *
    455  1.25     lukem rlink(const char *name)
    456   1.1       cgd {
    457  1.35     lukem 	static char lbuf[MAXPATHLEN];
    458  1.13     lukem 	int len;
    459   1.1       cgd 
    460  1.34     lukem 	if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1)
    461  1.16  wsanchez 		mtree_err("%s: %s", name, strerror(errno));
    462   1.1       cgd 	lbuf[len] = '\0';
    463   1.4       cgd 	return (lbuf);
    464   1.1       cgd }
    465