]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Fix error reporting for doveadm-dump-dcrypt
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 14 Nov 2016 08:52:22 +0000 (10:52 +0200)
committerGitLab <gitlab@git.dovecot.net>
Tue, 15 Nov 2016 09:08:35 +0000 (11:08 +0200)
src/doveadm/doveadm-dump-dcrypt-file.c
src/doveadm/doveadm-dump-dcrypt-key.c

index bdc469930ad4667b5d11cb1677f11caae3718fba..5cceb5de960f05d681ebbeac8e101b5d50a5c9bb 100644 (file)
@@ -58,8 +58,10 @@ static bool dcrypt_file_dump_metadata(const char *filename, bool print)
                        dcrypt_istream_dump_metadata(ds);
                        printf("decrypt key digest: %s\n", key_digest);
                }
-       } else if (print) {
-               i_error("%s", i_stream_get_error(ds));
+       } else if (print && ds->stream_errno != 0) {
+               i_error("read(%s) failed: %s",
+                       i_stream_get_name(ds),
+                       i_stream_get_error(ds));
        }
 
        i_stream_unref(&ds);
@@ -80,7 +82,7 @@ static void cmd_dump_dcrypt_file(int argc ATTR_UNUSED, char *argv[])
 {
        const char *error = NULL;
        if (!dcrypt_initialize("openssl", NULL, &error))
-               i_fatal("dcrypt_initialize: %s", error);
+               i_fatal("dcrypt_initialize failed: %s", error);
        (void)dcrypt_file_dump_metadata(argv[1], TRUE);
        dcrypt_deinitialize();
 }
index 0fd7abc41a34754d6228b581cf6db4a0d4670ac1..3968b1fe50850664bdf9fb9f3f9262a25e5f2067 100644 (file)
@@ -24,7 +24,7 @@ static void dcrypt_dump_public_key_metadata(const char *buf)
 
        bool ret = dcrypt_key_load_public(&pub_key, buf, &error);
        if (ret == FALSE) {
-               i_error("dcrypt_key_load_public: %s", error);
+               i_error("dcrypt_key_load_public failed: %s", error);
                return;
        }
        enum dcrypt_key_type key_type = dcrypt_key_type_public(pub_key);
@@ -35,23 +35,23 @@ static void dcrypt_dump_public_key_metadata(const char *buf)
 
        string_t *hash = t_str_new(128);
        if (!dcrypt_key_id_public(pub_key, "sha256", hash, &error)) {
-               i_error("dcrypt_key_id_public: %s", error);
-               goto out;
-       }
-       const char *v2_hash = binary_to_hex(hash->data, hash->used);
-       printf("v2 hash: %s\n", v2_hash);
-
-       if (key_type == DCRYPT_KEY_EC) {
-               buffer_set_used_size(hash, 0);
-               if (!dcrypt_key_id_public_old(pub_key, hash, &error))
-               {
-                       i_error("dcrypt_key_id_public_old: %s", error);
-                       goto out;
+               i_error("dcrypt_key_id_public failed: %s", error);
+       } else {
+               const char *v2_hash = binary_to_hex(hash->data, hash->used);
+               printf("v2 hash: %s\n", v2_hash);
+
+               if (key_type == DCRYPT_KEY_EC) {
+                       buffer_set_used_size(hash, 0);
+                       if (!dcrypt_key_id_public_old(pub_key, hash, &error)) {
+                               i_error("dcrypt_key_id_public_old failed: %s",
+                                       error);
+                       } else {
+                               const char *v1_hash = binary_to_hex(hash->data,
+                                                                   hash->used);
+                               printf("v1 hash: %s\n", v1_hash);
+                       }
                }
-               const char *v1_hash = binary_to_hex(hash->data, hash->used);
-               printf("v1 hash: %s\n", v1_hash);
        }
-out:
        dcrypt_key_unref_public(&pub_key);
 }
 
@@ -63,7 +63,7 @@ static void dcrypt_dump_private_key_metadata(const char *buf)
        bool ret = dcrypt_key_load_private(&priv_key, buf, NULL, NULL,
                        &error);
        if (ret == FALSE) {
-               i_error("dcrypt_key_load_private: %s", error);
+               i_error("dcrypt_key_load_private failed: %s", error);
                return;
        }
        enum dcrypt_key_type key_type = dcrypt_key_type_private(priv_key);
@@ -74,23 +74,22 @@ static void dcrypt_dump_private_key_metadata(const char *buf)
 
        string_t *hash = t_str_new(128);
        if (!dcrypt_key_id_private(priv_key, "sha256", hash, &error)) {
-               i_error("dcrypt_key_id_private: %s", error);
-               goto out;
-       }
-       const char *v2_hash = binary_to_hex(hash->data, hash->used);
-       printf("v2 hash: %s\n", v2_hash);
-
-       if (key_type == DCRYPT_KEY_EC) {
-               buffer_set_used_size(hash, 0);
-               if (!dcrypt_key_id_private_old(priv_key, hash, &error))
-               {
-                       i_error("dcrypt_key_id_private_old: %s", error);
-                       goto out;
+               i_error("dcrypt_key_id_private failed: %s", error);
+       } else {
+               const char *v2_hash = binary_to_hex(hash->data, hash->used);
+               printf("v2 hash: %s\n", v2_hash);
+
+               if (key_type == DCRYPT_KEY_EC) {
+                       buffer_set_used_size(hash, 0);
+                       if (!dcrypt_key_id_private_old(priv_key, hash, &error)) {
+                               i_error("dcrypt_key_id_private_old failed: %s", error);
+                       } else {
+                               const char *v1_hash = binary_to_hex(hash->data,
+                                                                   hash->used);
+                               printf("v1 hash: %s\n", v1_hash);
+                       }
                }
-               const char *v1_hash = binary_to_hex(hash->data, hash->used);
-               printf("v1 hash: %s\n", v1_hash);
        }
-out:
        dcrypt_key_unref_private(&priv_key);
 }
 
@@ -106,7 +105,7 @@ static bool dcrypt_key_dump_metadata(const char *filename, bool print)
        char buf[KEY_BUF_SIZE+1];
        ssize_t res = read(fd, buf, KEY_BUF_SIZE);
        if (res < 0) {
-               if (print) i_error("read(%d) failed: %m", fd);
+               if (print) i_error("read(%s) failed: %m", filename);
                i_close_fd(&fd);
                return FALSE;
        }
@@ -125,7 +124,7 @@ static bool dcrypt_key_dump_metadata(const char *filename, bool print)
                        &kind, &encryption_type, &encryption_key_hash,
                        &key_hash, &error);
        if (ret == FALSE) {
-               if (print) i_error("dcrypt_key_string_get_info: %s", error);
+               if (print) i_error("dcrypt_key_string_get_info failed: %s", error);
                return FALSE;
        }
        if (!print) return TRUE;