svn commit: r338267 - head/sbin/md5

Alex Richardson arichardson at FreeBSD.org
Thu Aug 23 18:19:03 UTC 2018


Author: arichardson
Date: Thu Aug 23 18:19:01 2018
New Revision: 338267
URL: https://svnweb.freebsd.org/changeset/base/338267

Log:
  Allow bootstrapping md5 on Linux, MacOS and FreeBSD < 12
  
  In order to build on a Linux host we need to bootstrap md5 since the Linux
  md5sum command produces output in a different format.
  
  Reviewed By:	emaste
  Approved By:	brooks (mentor)
  Differential Revision: https://reviews.freebsd.org/D16846

Modified:
  head/sbin/md5/Makefile
  head/sbin/md5/md5.c

Modified: head/sbin/md5/Makefile
==============================================================================
--- head/sbin/md5/Makefile	Thu Aug 23 18:18:52 2018	(r338266)
+++ head/sbin/md5/Makefile	Thu Aug 23 18:19:01 2018	(r338267)
@@ -28,4 +28,12 @@ MLINKS=	md5.1 rmd160.1 \
 
 LIBADD=	md
 
+.ifndef(BOOTSTRAPPING)
+# Avoid depending on capsicum during bootstrap. caph_limit_stdout() is not
+# available when building for Linux/MacOS or older FreeBSD hosts.
+# We need to bootstrap md5 when building on Linux since the md5sum command there
+# produces different output.
+CFLAGS+=-DHAVE_CAPSICUM
+.endif
+
 .include <bsd.prog.mk>

Modified: head/sbin/md5/md5.c
==============================================================================
--- head/sbin/md5/md5.c	Thu Aug 23 18:18:52 2018	(r338266)
+++ head/sbin/md5/md5.c	Thu Aug 23 18:19:01 2018	(r338267)
@@ -21,11 +21,10 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
-#include <sys/capsicum.h>
 #include <sys/time.h>
 #include <sys/resource.h>
-#include <capsicum_helpers.h>
 #include <err.h>
+#include <fcntl.h>
 #include <md5.h>
 #include <ripemd.h>
 #include <sha.h>
@@ -41,6 +40,11 @@ __FBSDID("$FreeBSD$");
 #include <time.h>
 #include <unistd.h>
 
+#ifdef HAVE_CAPSICUM
+#include <sys/capsicum.h>
+#include <capsicum_helpers.h>
+#endif
+
 /*
  * Length of test block, number of test blocks.
  */
@@ -162,7 +166,9 @@ Arguments (may be any combination):
 int
 main(int argc, char *argv[])
 {
+#ifdef HAVE_CAPSICUM
 	cap_rights_t	rights;
+#endif
 	int	ch, fd;
 	char   *p;
 	char	buf[HEX_DIGEST_LENGTH];
@@ -215,8 +221,10 @@ main(int argc, char *argv[])
 	argc -= optind;
 	argv += optind;
 
+#ifdef HAVE_CAPSICUM
 	if (caph_limit_stdout() < 0 || caph_limit_stderr() < 0)
 		err(1, "unable to limit rights for stdio");
+#endif
 
 	if (*argv) {
 		do {
@@ -232,10 +240,12 @@ main(int argc, char *argv[])
 			 * earlier.
 			 */
 			if (*(argv + 1) == NULL) {
+#ifdef HAVE_CAPSICUM
 				cap_rights_init(&rights, CAP_READ);
 				if ((cap_rights_limit(fd, &rights) < 0 &&
 				    errno != ENOSYS) || caph_enter() < 0)
 					err(1, "capsicum");
+#endif
 			}
 			if ((p = Algorithm[digest].Fd(fd, buf)) == NULL) {
 				warn("%s", *argv);
@@ -258,8 +268,10 @@ main(int argc, char *argv[])
 			}
 		} while (*++argv);
 	} else if (!sflag && (optind == 1 || qflag || rflag)) {
+#ifdef HAVE_CAPSICUM
 		if (caph_limit_stdin() < 0 || caph_enter() < 0)
 			err(1, "capsicum");
+#endif
 		MDFilter(&Algorithm[digest], 0);
 	}
 


More information about the svn-src-head mailing list