]> granicus.if.org Git - neomutt/commitdiff
Use system's md5 instead of compiling our own mutt_md5 (#711)
authorPietro Cerutti <gahr@gahr.ch>
Tue, 8 Aug 2017 12:56:23 +0000 (13:56 +0100)
committerGitHub <noreply@github.com>
Tue, 8 Aug 2017 12:56:23 +0000 (13:56 +0100)
* Use the system's md5(sum)? utility to compute the hcache md5

Issue #710

* Simplify md5 generation and truncation

Issue #710

* Handle different md5 programs more gracefully

Issue #710

* Solaris' uname is still SunOS

Issue #710

* Consistently use OpenSSL for md5, if it's available

Issue #710

configure.ac
hcache/Makefile.am
hcache/hcachever.sh
hcache/mutt_md5.c [deleted file]
po/POTFILES.in

index 283b0076196d4719e09bca6754eb4a5fc9c36a8e..b3b79d32f2527a1253e302e35a303600ae77c35a 100644 (file)
@@ -826,9 +826,6 @@ AM_CONDITIONAL(BUILD_HC_QDBM, test "x$build_hc_qdbm" = "xyes")
 AM_CONDITIONAL(BUILD_HC_TC,   test "x$build_hc_tc"   = "xyes")
 dnl -- end cache --
 
-MUTT_MD5="mutt_md5$EXEEXT"
-
-AC_SUBST(MUTT_MD5)
 AC_SUBST(MUTT_LIB_OBJECTS)
 AC_SUBST(HCACHE_LIBS)
 AC_SUBST(HCACHE_DEPS)
index 0bf7700d65690f5de6c843798350acc9483c8722..4700d0e88b368a0cbe46549d9cecbfd8fced166d 100644 (file)
@@ -2,7 +2,6 @@
 include $(top_srcdir)/flymake.am
 
 AUTOMAKE_OPTIONS = 1.6 foreign
-EXTRA_PROGRAMS = mutt_md5
 
 EXTRA_DIST = bdb.c gdbm.c hcache.c kc.c lmdb.c qdbm.c tc.c hcachever.sh
 
@@ -10,7 +9,6 @@ AM_CPPFLAGS = -I$(top_srcdir)
 
 noinst_LIBRARIES = libhcache.a
 noinst_HEADERS = backend.h hcache.h
-noinst_PROGRAMS = $(MUTT_MD5)
 
 libhcache_a_SOURCES =
 
@@ -41,10 +39,6 @@ endif
 LIBMUTT = -L../lib -lmutt
 LIBMUTTDEPS = $(top_srcdir)/lib/lib.h ../lib/libmutt.a
 
-mutt_md5_SOURCES = mutt_md5.c
-mutt_md5_LDADD = $(LIBMUTT)
-mutt_md5_DEPENDENCIES = $(LIBMUTTDEPS)
-
 BUILT_SOURCES = $(HCVERSION)
 
 $(top_srcdir)/keymap_defs.h:
@@ -53,7 +47,7 @@ $(top_srcdir)/keymap_defs.h:
 hcversion.h: $(top_srcdir)/mutt.h $(top_srcdir)/address.h $(top_srcdir)/list.h \
                $(top_srcdir)/lib/buffer.h $(top_srcdir)/parameter.h \
                $(top_srcdir)/body.h $(top_srcdir)/envelope.h \
-               $(top_srcdir)/header.h $(srcdir)/hcachever.sh $(MUTT_MD5)
+               $(top_srcdir)/header.h $(srcdir)/hcachever.sh
        ( echo '#include "config.h"'; echo '#include "mutt.h"'; \
        echo '#include "address.h"'; echo '#include "list.h"'; \
        echo '#include "lib/buffer.h"'; echo '#include "parameter.h"'; \
index fa7a8ed8a92f587fb18c3002f71940d115e14f54..3070dee178621f412f991c4f5e8acd11b0f2dabf 100755 (executable)
@@ -54,6 +54,35 @@ getstruct () {
   return
 }
 
+md5prog () {
+  prog=""
+
+  # Use OpenSSL if it's installed
+  openssl=`which openssl`
+  if [ $? = 0 ];then
+    echo "$openssl md5 -r"
+    return
+  fi
+
+  # Fallback to looking for a system-specific utility
+  case "`uname`" in
+    SunOS)
+      # This matches most of the Solaris family
+      prog="digest -a md5"
+      ;;
+    *BSD)
+      # FreeBSD, NetBSD, and OpenBSD all have md5
+      prog="md5"
+      ;;
+    *)
+      # Assume anything else has binutils' md5sum
+      prog="md5sum"
+      ;;
+  esac
+
+  echo $prog
+}
+
 DEST="$1"
 TMPD="$DEST.tmp"
 
@@ -77,8 +106,9 @@ do
 done
 echo " */" >> $TMPD
 
-MD5TEXT=`echo "$TEXT" | ./mutt_md5`
-echo "#define HCACHEVER 0x"`echo $MD5TEXT | cut -c-8` >> $TMPD
+MD5PROG=$(md5prog)
+MD5TEXT=`echo "$TEXT" | $MD5PROG | cut -c-8`
+echo "#define HCACHEVER 0x$MD5TEXT" >> $TMPD
 
 # TODO: validate we have all structs
 
diff --git a/hcache/mutt_md5.c b/hcache/mutt_md5.c
deleted file mode 100644 (file)
index 03d0a4f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * @file
- * Calculate the MD5 checksum of a buffer
- *
- * @authors
- * Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006,2008 Free Software Foundation, Inc.
- *
- * @copyright
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- * md5.c - Functions to compute MD5 message digest of files or memory blocks
- * according to the definition of MD5 in RFC1321 from April 1992.
- *
- * NOTE: The canonical source of this file is maintained with the GNU C
- * Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
- */
-
-/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.  */
-
-#include "config.h"
-#include <stddef.h>
-#include <stdbool.h>
-#include <string.h>
-#include "lib/md5.h"
-
-/* local md5 equivalent for header cache versioning */
-int main(void)
-{
-  unsigned char r[16];
-  int rc;
-
-  if ((rc = md5_stream(stdin, r)))
-    return rc;
-
-  printf("%02x%02x%02x%02x%02x%02x%02x%02x"
-         "%02x%02x%02x%02x%02x%02x%02x%02x\n",
-         r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
-         r[11], r[12], r[13], r[14], r[15]);
-
-  return 0;
-}
-
index 3b455c11a05baad295f1b2cef7d55e4b4b665c48..efea07097b1e9b3c054fc379c9a4ef94b9485375 100644 (file)
@@ -70,7 +70,6 @@ lib/string.c
 main.c
 mbox.c
 mbyte.c
-hcache/mutt_md5.c
 menu.c
 mh.c
 muttlib.c