Blame SOURCES/cryptsetup-2.0.4-add-blkid-utilities-for-fast-detection-of-device-sig.patch

7cdc99
From 12d00da84239c3dcc4560dc60a0c36d534908cc0 Mon Sep 17 00:00:00 2001
7cdc99
From: Ondrej Kozina <okozina@redhat.com>
7cdc99
Date: Wed, 4 Jul 2018 15:39:11 +0200
7cdc99
Subject: [PATCH 1/6] Add blkid utilities for fast detection of device
7cdc99
 signatures.
7cdc99
7cdc99
---
7cdc99
 configure.ac      |  21 ++++++++
7cdc99
 lib/Makemodule.am |   5 +-
7cdc99
 lib/utils_blkid.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
7cdc99
 lib/utils_blkid.h |  48 +++++++++++++++++
7cdc99
 4 files changed, 231 insertions(+), 1 deletion(-)
7cdc99
 create mode 100644 lib/utils_blkid.c
7cdc99
 create mode 100644 lib/utils_blkid.h
7cdc99
7cdc99
diff --git a/configure.ac b/configure.ac
7cdc99
index 05da6d6..31508d0 100644
7cdc99
--- a/configure.ac
7cdc99
+++ b/configure.ac
7cdc99
@@ -415,6 +415,26 @@ if test x$enable_internal_argon2 = xyes ; then
7cdc99
 fi
7cdc99
 AM_CONDITIONAL(CRYPTO_INTERNAL_ARGON2, test x$enable_internal_argon2 = xyes)
7cdc99
 
7cdc99
+dnl Link with blkid to check for other device types
7cdc99
+AC_ARG_ENABLE(blkid, AS_HELP_STRING([--disable-blkid],
7cdc99
+	[disable use of blkid for device signature detection and wiping.]), [], [enable_blkid=yes])
7cdc99
+
7cdc99
+if test x$enable_blkid = xyes ; then
7cdc99
+	PKG_CHECK_MODULES([BLKID], [blkid],[AC_DEFINE([HAVE_BLKID], 1, [Define to 1 to use blkid for detection of disk signatures.])],[LIBBLKID_LIBS="-lblkid"])
7cdc99
+
7cdc99
+	AC_CHECK_HEADERS(blkid/blkid.h,,[AC_MSG_ERROR([You need blkid development library installed.])])
7cdc99
+	AC_CHECK_DECLS([ blkid_reset_probe,
7cdc99
+			 blkid_probe_set_device,
7cdc99
+			 blkid_probe_filter_superblocks_type,
7cdc99
+			 blkid_do_safeprobe,
7cdc99
+			 blkid_do_probe,
7cdc99
+			 blkid_probe_lookup_value
7cdc99
+		       ],,
7cdc99
+		       [AC_MSG_ERROR([Can not compile with blkid support, disable it by --disable-blkid.])],
7cdc99
+		       [#include <blkid/blkid.h>])
7cdc99
+fi
7cdc99
+AM_CONDITIONAL(HAVE_BLKID, test x$enable_blkid = xyes)
7cdc99
+
7cdc99
 dnl Magic for cryptsetup.static build.
7cdc99
 if test x$enable_static_cryptsetup = xyes; then
7cdc99
 	saved_PKG_CONFIG=$PKG_CONFIG
7cdc99
@@ -465,6 +485,7 @@ AC_SUBST([CRYPTO_STATIC_LIBS])
7cdc99
 
7cdc99
 AC_SUBST([JSON_C_LIBS])
7cdc99
 AC_SUBST([LIBARGON2_LIBS])
7cdc99
+AC_SUBST([BLKID_LIBS])
7cdc99
 
7cdc99
 AC_SUBST([LIBCRYPTSETUP_VERSION])
7cdc99
 AC_SUBST([LIBCRYPTSETUP_VERSION_INFO])
7cdc99
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
7cdc99
index 5e20039..26178b8 100644
7cdc99
--- a/lib/Makemodule.am
7cdc99
+++ b/lib/Makemodule.am
7cdc99
@@ -30,6 +30,7 @@ libcryptsetup_la_LIBADD = \
7cdc99
 	@CRYPTO_LIBS@		\
7cdc99
 	@LIBARGON2_LIBS@	\
7cdc99
 	@JSON_C_LIBS@		\
7cdc99
+	@BLKID_LIBS@		\
7cdc99
 	libcrypto_backend.la
7cdc99
 
7cdc99
 libcryptsetup_la_SOURCES = \
7cdc99
@@ -92,4 +93,6 @@ libcryptsetup_la_SOURCES = \
7cdc99
 	lib/luks2/luks2_token_keyring.c	\
7cdc99
 	lib/luks2/luks2_token.c		\
7cdc99
 	lib/luks2/luks2_internal.h	\
7cdc99
-	lib/luks2/luks2.h
7cdc99
+	lib/luks2/luks2.h		\
7cdc99
+	lib/utils_blkid.c		\
7cdc99
+	lib/utils_blkid.h
7cdc99
diff --git a/lib/utils_blkid.c b/lib/utils_blkid.c
7cdc99
new file mode 100644
7cdc99
index 0000000..7425bc5
7cdc99
--- /dev/null
7cdc99
+++ b/lib/utils_blkid.c
7cdc99
@@ -0,0 +1,158 @@
7cdc99
+/*
7cdc99
+ * blkid probe utilities
7cdc99
+ *
7cdc99
+ * Copyright (C) 2018, Red Hat, Inc. All rights reserved.
7cdc99
+ *
7cdc99
+ * This program is free software; you can redistribute it and/or
7cdc99
+ * modify it under the terms of the GNU General Public License
7cdc99
+ * as published by the Free Software Foundation; either version 2
7cdc99
+ * of the License, or (at your option) any later version.
7cdc99
+ *
7cdc99
+ * This program is distributed in the hope that it will be useful,
7cdc99
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
7cdc99
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7cdc99
+ * GNU General Public License for more details.
7cdc99
+ *
7cdc99
+ * You should have received a copy of the GNU General Public License
7cdc99
+ * along with this program; if not, write to the Free Software
7cdc99
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7cdc99
+ */
7cdc99
+
7cdc99
+#include <errno.h>
7cdc99
+#include <stdio.h>
7cdc99
+#include <stdlib.h>
7cdc99
+#include <string.h>
7cdc99
+#include <unistd.h>
7cdc99
+
7cdc99
+#include "utils_blkid.h"
7cdc99
+
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+#include <blkid/blkid.h>
7cdc99
+struct blkid_handle {
7cdc99
+	int fd;
7cdc99
+	blkid_probe pr;
7cdc99
+};
7cdc99
+#endif
7cdc99
+
7cdc99
+void blk_set_chains_for_fast_detection(struct blkid_handle *h)
7cdc99
+{
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	blkid_probe_enable_partitions(h->pr, 1);
7cdc99
+	blkid_probe_set_partitions_flags(h->pr, 0);
7cdc99
+
7cdc99
+	blkid_probe_enable_superblocks(h->pr, 1);
7cdc99
+	blkid_probe_set_superblocks_flags(h->pr, BLKID_SUBLKS_TYPE);
7cdc99
+#endif
7cdc99
+}
7cdc99
+
7cdc99
+int blk_init_by_path(struct blkid_handle **h, const char *path)
7cdc99
+{
7cdc99
+	int r = -ENOTSUP;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	struct blkid_handle *tmp = malloc(sizeof(*tmp));
7cdc99
+	if (!tmp)
7cdc99
+		return -ENOMEM;
7cdc99
+
7cdc99
+	tmp->fd = -1;
7cdc99
+
7cdc99
+	tmp->pr = blkid_new_probe_from_filename(path);
7cdc99
+	if (!tmp->pr) {
7cdc99
+		free(tmp);
7cdc99
+		return -EINVAL;
7cdc99
+	}
7cdc99
+
7cdc99
+	*h = tmp;
7cdc99
+
7cdc99
+	r = 0;
7cdc99
+#endif
7cdc99
+	return r;
7cdc99
+}
7cdc99
+
7cdc99
+int blk_superblocks_filter_luks(struct blkid_handle *h)
7cdc99
+{
7cdc99
+	int r = -ENOTSUP;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	char *luks_filter[] = {
7cdc99
+		"crypto_LUKS",
7cdc99
+		NULL
7cdc99
+	};
7cdc99
+	r = blkid_probe_filter_superblocks_type(h->pr, BLKID_FLTR_NOTIN, luks_filter);
7cdc99
+#endif
7cdc99
+	return r;
7cdc99
+}
7cdc99
+
7cdc99
+blk_probe_status blk_safeprobe(struct blkid_handle *h)
7cdc99
+{
7cdc99
+	int r = -1;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	r = blkid_do_safeprobe(h->pr);
7cdc99
+#endif
7cdc99
+	switch (r) {
7cdc99
+	case -2:
7cdc99
+		return PRB_AMBIGUOUS;
7cdc99
+	case 1:
7cdc99
+		return PRB_EMPTY;
7cdc99
+	case 0:
7cdc99
+		return PRB_OK;
7cdc99
+	default:
7cdc99
+		return PRB_FAIL;
7cdc99
+	}
7cdc99
+}
7cdc99
+
7cdc99
+int blk_is_partition(struct blkid_handle *h)
7cdc99
+{
7cdc99
+	int r = 0;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	r = blkid_probe_has_value(h->pr, "PTTYPE");
7cdc99
+#endif
7cdc99
+	return r;
7cdc99
+}
7cdc99
+
7cdc99
+int blk_is_superblock(struct blkid_handle *h)
7cdc99
+{
7cdc99
+	int r = 0;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	r = blkid_probe_has_value(h->pr, "TYPE");
7cdc99
+#endif
7cdc99
+	return r;
7cdc99
+}
7cdc99
+
7cdc99
+const char *blk_get_partition_type(struct blkid_handle *h)
7cdc99
+{
7cdc99
+	const char *value = NULL;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	(void) blkid_probe_lookup_value(h->pr, "PTTYPE", &value, NULL);
7cdc99
+#endif
7cdc99
+	return value;
7cdc99
+}
7cdc99
+
7cdc99
+const char *blk_get_superblock_type(struct blkid_handle *h)
7cdc99
+{
7cdc99
+	const char *value = NULL;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	(void) blkid_probe_lookup_value(h->pr, "TYPE", &value, NULL);
7cdc99
+#endif
7cdc99
+	return value;
7cdc99
+}
7cdc99
+
7cdc99
+void blk_free(struct blkid_handle *h)
7cdc99
+{
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	if (!h)
7cdc99
+		return;
7cdc99
+
7cdc99
+	if (h->pr)
7cdc99
+		blkid_free_probe(h->pr);
7cdc99
+
7cdc99
+	free(h);
7cdc99
+#endif
7cdc99
+}
7cdc99
+
7cdc99
+int blk_supported(void)
7cdc99
+{
7cdc99
+	int r = 0;
7cdc99
+#ifdef HAVE_BLKID
7cdc99
+	r = 1;
7cdc99
+#endif
7cdc99
+	return r;
7cdc99
+}
7cdc99
diff --git a/lib/utils_blkid.h b/lib/utils_blkid.h
7cdc99
new file mode 100644
7cdc99
index 0000000..d18b0a0
7cdc99
--- /dev/null
7cdc99
+++ b/lib/utils_blkid.h
7cdc99
@@ -0,0 +1,48 @@
7cdc99
+/*
7cdc99
+ * blkid probe utilities
7cdc99
+ *
7cdc99
+ * Copyright (C) 2018, Red Hat, Inc. All rights reserved.
7cdc99
+ *
7cdc99
+ * This program is free software; you can redistribute it and/or
7cdc99
+ * modify it under the terms of the GNU General Public License
7cdc99
+ * as published by the Free Software Foundation; either version 2
7cdc99
+ * of the License, or (at your option) any later version.
7cdc99
+ *
7cdc99
+ * This program is distributed in the hope that it will be useful,
7cdc99
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
7cdc99
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7cdc99
+ * GNU General Public License for more details.
7cdc99
+ *
7cdc99
+ * You should have received a copy of the GNU General Public License
7cdc99
+ * along with this program; if not, write to the Free Software
7cdc99
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7cdc99
+ */
7cdc99
+
7cdc99
+#ifndef _UTILS_BLKID_H
7cdc99
+#define _UTILS_BLKID_H
7cdc99
+
7cdc99
+struct blkid_handle;
7cdc99
+
7cdc99
+typedef enum { PRB_OK = 0, PRB_EMPTY, PRB_AMBIGUOUS, PRB_FAIL } blk_probe_status;
7cdc99
+
7cdc99
+int blk_init_by_path(struct blkid_handle **h, const char *path);
7cdc99
+
7cdc99
+void blk_free(struct blkid_handle *h);
7cdc99
+
7cdc99
+void blk_set_chains_for_fast_detection(struct blkid_handle *h);
7cdc99
+
7cdc99
+int blk_superblocks_filter_luks(struct blkid_handle *h);
7cdc99
+
7cdc99
+blk_probe_status blk_safeprobe(struct blkid_handle *h);
7cdc99
+
7cdc99
+int blk_is_partition(struct blkid_handle *h);
7cdc99
+
7cdc99
+int blk_is_superblock(struct blkid_handle *h);
7cdc99
+
7cdc99
+const char *blk_get_partition_type(struct blkid_handle *h);
7cdc99
+
7cdc99
+const char *blk_get_superblock_type(struct blkid_handle *h);
7cdc99
+
7cdc99
+int blk_supported(void);
7cdc99
+
7cdc99
+#endif
7cdc99
-- 
7cdc99
1.8.3.1
7cdc99
7cdc99
--- cryptsetup-2.0.3.old/aclocal.m4	2018-05-03 21:36:53.000000000 +0200
7cdc99
+++ cryptsetup-2.0.3/aclocal.m4	2018-07-16 15:37:34.935817650 +0200
7cdc99
@@ -31,7 +31,7 @@ To do so, use the procedure documented b
7cdc99
 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
7cdc99
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7cdc99
 #
7cdc99
-# Last-changed: 2014-10-02
7cdc99
+# Last-changed: 2018-07-16
7cdc99
 
7cdc99
 
7cdc99
 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,