commit: 6e0f64cb72a3e2948fdb8b6a59aac9bb57223dc2
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 14 13:07:42 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jul 14 13:07:42 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=6e0f64cb
qtegrity: use libq/hash iso shelling out to shaXsum
Use libq/hash functionality (as used by qmanifest) in qtegrity to obtain
hashes for files. This adds a dep on openssl currently, so allow
disabling this applet.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
Makefile.am | 13 ++++++++++-
configure.ac | 33 ++++++++++++++++++++++++++--
qtegrity.c | 65 ++++++++++++-------------------------------------------
tests/Makefile.am | 4 +++-
4 files changed, 60 insertions(+), 55 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index fc0619c..e8b11f8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,7 +64,6 @@ q_SOURCES = \
qsearch.c \
qsize.c \
qtbz2.c \
- qtegrity.c \
quse.c \
qxpak.c \
$(NULL)
@@ -95,6 +94,18 @@ q_LDADD += \
dist_man_MANS += man/qmanifest.1
APPLETS += qmanifest
endif
+if QTEGRITY_ENABLED
+q_SOURCES += qtegrity.c
+if !QMANIFEST_ENABLED
+q_CPPFLAGS += \
+ $(OPENMP_CFLAGS)
+q_LDADD += \
+ $(OPENMP_CFLAGS)
+endif
+dist_man_MANS += man/qtegrity.1
+APPLETS += qtegrity
+endif
+
install-exec-hook:
cd $(DESTDIR)$(bindir); \
diff --git a/configure.ac b/configure.ac
index bda5a84..0577d07 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,11 +35,15 @@ AC_SUBST([CONFIG_EPREFIX], ["$with_eprefix"])
AC_ARG_ENABLE([qmanifest], [AS_HELP_STRING([--enable-qmanifest],
[support qmanifest applet])],
[], [enable_qmanifest=auto])
+AC_ARG_ENABLE([qtegrity], [AS_HELP_STRING([--enable-qtegrity],
+ [support qtegrity applet])],
+ [], [enable_qtegrity=auto])
LIBSSL=
LIBBL2=
LIBZ=
HASGPGME=
-AS_IF([test "x$enable_qmanifest" != xno],
+
+AS_IF([test "x${enable_qmanifest}x${enable_qtegrity}" != xnoxno],
[AC_CHECK_HEADERS([openssl/err.h \
openssl/ssl.h], [], [LIBSSL=_missing_header])
AC_CHECK_LIB([ssl${LIBSSL}], [SSL_connect],
@@ -55,9 +59,33 @@ AS_IF([test "x$enable_qmanifest" != xno],
AC_MSG_FAILURE(
[--enable-qmanifest was given, but
test for ssl failed])
fi
+ if test "x$enable_qtegrity" != xauto;
then
+ AC_MSG_FAILURE(
+ [--enable-qtegrity was given, but
test for ssl failed])
+ fi
LIBSSL=
])
- AC_CHECK_HEADERS([blake2.h], [], [LIBBL2=_missing_header])
+ AC_MSG_CHECKING([whether to enable qtegrity])
+ case "x${LIBSSL}" in
+ "x-lssl"*)
+ AC_MSG_RESULT([yes])
+ ;;
+ *)
+ enable_qtegrity=no
+ AC_MSG_RESULT([no: missing dependencies])
+ ;;
+ esac
+ if test "x$enable_qtegrity" != xno ; then
+ AC_DEFINE([ENABLE_QTEGRITY], [1],
+ [Define if qtegrity should be
compiled])
+ fi
+ ],
+ [
+ AC_MSG_CHECKING([whether to enable qtegrity])
+ AC_MSG_RESULT([no: disabled by configure argument])
+ ])
+AS_IF([test "x$enable_qmanifest" != xno],
+ [AC_CHECK_HEADERS([blake2.h], [], [LIBBL2=_missing_header])
AC_CHECK_LIB([b2${LIBBL2}], [blake2b_update],
[LIBBL2="-lb2"
AC_DEFINE([HAVE_BLAKE2B], [1],
@@ -104,6 +132,7 @@ AS_IF([test "x$enable_qmanifest" != xno],
AC_MSG_RESULT([no: disabled by configure argument])
])
AM_CONDITIONAL([QMANIFEST_ENABLED], [test "x$enable_qmanifest" != xno])
+AM_CONDITIONAL([QTEGRITY_ENABLED], [test "x$enable_qtegrity" != xno])
AX_CFLAGS_WARN_ALL
AC_DEFUN([PT_CHECK_CFLAG],[AX_CHECK_COMPILER_FLAGS([$1],[CFLAGS="$CFLAGS
$1"])])
diff --git a/qtegrity.c b/qtegrity.c
index 70a99d5..0d23a7f 100644
--- a/qtegrity.c
+++ b/qtegrity.c
@@ -5,10 +5,12 @@
* Copyright 2005-2010 Ned Ludd - <[email protected]>
* Copyright 2005-2014 Mike Frysinger - <[email protected]>
* Copyright 2017-2018 Sam Besselink
+ * Copyright 2019- Fabian Groffen - <[email protected]>
*/
#include "main.h"
#include "applets.h"
+#include "libq/hash.h"
#include <stdio.h>
#include <unistd.h>
@@ -60,63 +62,24 @@ struct qtegrity_opt_state {
#define SHA256_LENGTH (SHA256_PREFIX_LENGTH + SHA256_DIGEST_LENGTH)
#define SHA512_DIGEST_LENGTH 128
-static void external_check_sha(char * ret_digest, char * filepath, char *
algo) {
- size_t size_digest = 1;
- char cmd[11];
- int pipefd[2];
- pid_t pid;
+static void
+check_sha(char *ret_digest, char *path, char *algo)
+{
+ int hashes = 0;
+ size_t flen = 0;
if (strcmp(algo, "sha256") == 0) {
- size_digest = 64;
+ hashes |= HASH_SHA256;
} else if (strcmp(algo, "sha512") == 0) {
- size_digest = 128;
- }
-
- if ((strcmp(algo, "sha256") != 0) && (strcmp(algo, "sha512") != 0)) {
+ hashes |= HASH_SHA512;
+ } else {
+ /* no matching hash? (we could support whirlpool and blake2b) */
return;
}
- snprintf(cmd, 10, "%ssum", algo);
-
- if (pipe(pipefd) == -1) {
- perror("Couldn't create pipe to shasum\n");
- exit(1);
- }
- if ((pid = fork()) == -1) {
- perror("Couldn't fork to shasum\n");
- exit(1);
- }
- if (pid == 0)
- {
- /* Child. Redirect stdout and stderr to pipe, replace execution
- * environment */
- close(pipefd[0]);
- dup2(pipefd[1], STDOUT_FILENO);
- dup2(pipefd[1], STDERR_FILENO);
- execlp(cmd, cmd, filepath, (char *)NULL);
- perror("Executing shasum failed\n");
- exit(1);
- }
-
- /* Only parent gets here. Listen to pipe */
- close(pipefd[1]);
- FILE* output = fdopen(pipefd[0], "r");
- if (output == NULL) {
- printf("Failed to run command '%s'\n", cmd);
- exit(1);
- }
-
- /* Read pipe line for line */
- while (fgets(ret_digest, size_digest+1, output))
- {
- if (strlen(ret_digest) == 64) /* Found what we need, can stop */
- {
- kill(pid, SIGKILL);
- break;
- }
- }
+ hash_compute_file(path, ret_digest, ret_digest, NULL, NULL, &flen,
hashes);
+ (void)flen; /* we don't use the file size */
- pclose(output);
return;
}
@@ -458,7 +421,7 @@ int qtegrity_main(int argc, char **argv)
char *file_digest;
file_digest = xmalloc(SHA256_DIGEST_LENGTH+1);
file_digest[0] = '\0';
- external_check_sha(file_digest, state.add_file, hash_algo);
+ check_sha(file_digest, state.add_file, hash_algo);
/* Iterate over lines; if fname matches, exit-loop */
char *line, *fname;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3a7a00b..447ed0f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,12 +1,14 @@
SUBDIRS = \
atom_compare atom_explode copy_file mkdir rmspace \
qatom qcheck qdepends qfile qlist qlop qmerge qtbz2 quse qxpak \
- install profile source
+ install profile
if QMANIFEST_ENABLED
SUBDIRS += qmanifest
endif
+SUBDIRS += source
+
%_subdir:
$(Q)cd $(@:_subdir=) || exit 1; \
out=`$(MAKE) check 2>&1`; \