dev-libs/volume_key: Added a patch for cryptsetup-2
authorLars Wendler <polynomial-c@gentoo.org>
Wed, 18 Oct 2017 06:48:16 +0000 (08:48 +0200)
committerLars Wendler <polynomial-c@gentoo.org>
Wed, 18 Oct 2017 06:48:24 +0000 (08:48 +0200)
Package-Manager: Portage-2.3.11, Repoman-2.3.3

dev-libs/volume_key/files/volume_key-0.3.9-cryptsetup2.patch [new file with mode: 0644]
dev-libs/volume_key/volume_key-0.3.9.ebuild

diff --git a/dev-libs/volume_key/files/volume_key-0.3.9-cryptsetup2.patch b/dev-libs/volume_key/files/volume_key-0.3.9-cryptsetup2.patch
new file mode 100644 (file)
index 0000000..c0386fa
--- /dev/null
@@ -0,0 +1,68 @@
+From a41c53d35b594a7fd8d5b92501b4fe52d7252909 Mon Sep 17 00:00:00 2001
+From: Milan Broz <gmazyland@gmail.com>
+Date: Tue, 17 Oct 2017 13:44:24 +0200
+Subject: [PATCH] volume_key: Switch to libcryptsetup error callback.
+
+This change should be compatible with new libcryptsetup as well.
+
+Note that now is error set even for retry, so the code must
+clear it after successfull (but retried) password query.
+
+Signed-off-by: Milan Broz <gmazyland@gmail.com>
+---
+ lib/volume_luks.c | 21 ++++++++++++++-------
+ 1 file changed, 14 insertions(+), 7 deletions(-)
+
+diff --git a/lib/volume_luks.c b/lib/volume_luks.c
+index 14794d7..4034cc3 100644
+--- a/lib/volume_luks.c
++++ b/lib/volume_luks.c
+@@ -65,13 +65,8 @@ my_strerror (int err_no)
+ static void
+ error_from_cryptsetup (GError **error, LIBVKError code, int res)
+ {
+-  /* It's not possible to get the error message length from libcryptsetup, just
+-     guess. */
+-  char crypt_msg[4096];
+-
+-  crypt_get_error (crypt_msg, sizeof (crypt_msg));
+-  if (crypt_msg[0] != '\0')
+-    g_set_error (error, LIBVK_ERROR, code, "%s", crypt_msg);
++  if (error && *error && (*error)->message)
++    (*error)->code = code;
+   else
+     {
+       char *s;
+@@ -82,6 +77,16 @@ error_from_cryptsetup (GError **error, LIBVKError code, int res)
+     }
+ }
++void cryptsetup_log (int level, const char *msg, void *usrptr)
++{
++  GError **error = usrptr;
++
++  if (level != CRYPT_LOG_ERROR)
++    return;
++  g_clear_error(error);
++  g_set_error (error, LIBVK_ERROR, -1, "%s", msg);
++}
++
+ /* Open volume PATH and load its header.
+    Return the volume, or NULL on error. */
+ static struct crypt_device *
+@@ -93,6 +98,7 @@ open_crypt_device (const char *path, GError **error)
+   r = crypt_init (&cd, path);
+   if (r < 0)
+     goto err;
++  crypt_set_log_callback(cd, cryptsetup_log, error);
+   r = crypt_load (cd, CRYPT_LUKS1, NULL);
+   if (r < 0)
+     goto err_cd;
+@@ -307,6 +313,7 @@ luks_get_secret (struct libvk_volume *vol, enum libvk_secret secret_type,
+         g_prefix_error (error, _("Error getting LUKS data encryption key: "));
+         goto err_prompt;
+       }
++      g_clear_error(error);
+     }
+   g_set_error (error, LIBVK_ERROR, LIBVK_ERROR_FAILED,
+              _("Too many attempts to get a valid passphrase"));
index 6edf1dda06a012567b2d34ef4ba40fd9da9463ef..05ac55ccf1e36497403620446c07110e1e0aa829 100644 (file)
@@ -37,6 +37,9 @@ RESTRICT="test" # possible gpgme issue
 PATCHES=(
        "${FILESDIR}"/${P}-config.h.diff
        "${FILESDIR}"/${PN}-0.3.9-find_python.patch
+
+       # Patches from upstream (can usually be removed with next version bump)
+       "${FILESDIR}/${P}-cryptsetup2.patch"
 )
 
 pkg_setup() {