]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Allow any kind of non-128bit GUIDs. For those store their hash to index instead.
authorTimo Sirainen <tss@iki.fi>
Wed, 8 Jul 2009 21:58:02 +0000 (17:58 -0400)
committerTimo Sirainen <tss@iki.fi>
Wed, 8 Jul 2009 21:58:02 +0000 (17:58 -0400)
--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-file.c
src/lib-storage/index/dbox/dbox-file.h
src/lib-storage/index/dbox/dbox-save.c
src/lib-storage/index/dbox/dbox-storage-rebuild.c

index 863198e34961361218f40ea8ab6309c74bab5835..abbdb993a9f06f4f9c7e322e5e25a33b6a9665ab 100644 (file)
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "array.h"
 #include "hex-dec.h"
+#include "hex-binary.h"
 #include "hostpid.h"
 #include "istream.h"
 #include "ostream.h"
@@ -11,6 +12,7 @@
 #include "mkdir-parents.h"
 #include "fdatasync-path.h"
 #include "eacces-error.h"
+#include "sha1.h"
 #include "str.h"
 #include "dbox-storage.h"
 #include "dbox-file.h"
@@ -1027,3 +1029,23 @@ void dbox_msg_header_fill(struct dbox_message_header *dbox_msg_hdr,
                sizeof(dbox_msg_hdr->message_size_hex));
        dbox_msg_hdr->save_lf = '\n';
 }
+
+void dbox_get_guid_128(const char *input, buffer_t *output)
+{
+       unsigned char sha1_sum[SHA1_RESULTLEN];
+
+       buffer_set_used_size(output, 0);
+       if (strlen(input) != DBOX_GUID_BIN_LEN*2 ||
+           hex_to_binary(input, output) < 0 ||
+           output->used != DBOX_GUID_BIN_LEN) {
+               /* not 128bit hex. use a hash of it instead. */
+               buffer_set_used_size(output, 0);
+               sha1_get_digest(input, strlen(input), sha1_sum);
+#if SHA1_RESULTLEN < DBOX_GUID_BIN_LEN
+#  error not possible
+#endif
+               buffer_append(output,
+                             sha1_sum + SHA1_RESULTLEN - DBOX_GUID_BIN_LEN,
+                             DBOX_GUID_BIN_LEN);
+       }
+}
index 6bba0b498ed2e5b377a87d98829cde777879f34e..d7bf8d3d5e2b26a74091d690b976e3bf5350eb37 100644 (file)
@@ -206,5 +206,6 @@ int dbox_create_fd(struct dbox_storage *storage, const char *path);
 int dbox_file_header_write(struct dbox_file *file, struct ostream *output);
 int dbox_file_read_mail_header(struct dbox_file *file, uoff_t *physical_size_r);
 int dbox_file_metadata_skip_header(struct dbox_file *file);
+void dbox_get_guid_128(const char *input, buffer_t *output);
 
 #endif
index cf77f17fae9ba94a45f98fbda3cbefc4b943891b..fc71c6ea2b432d66eccfc67943fc5742b3e6c906 100644 (file)
@@ -202,15 +202,9 @@ static void dbox_save_write_metadata(struct dbox_save_context *ctx)
        if (ctx->ctx.guid != NULL && ctx->cur_file->single_mbox == NULL) {
                guid_buf = buffer_create_dynamic(pool_datastack_create(),
                                                 sizeof(guid_128));
-               if (strlen(guid) != sizeof(guid_128)*2 ||
-                   hex_to_binary(guid, guid_buf) < 0 ||
-                   guid_buf->used != sizeof(guid_128))
-                       guid = NULL;
-               else
-                       memcpy(guid_128, guid_buf->data, sizeof(guid_128));
-       }
-
-       if (guid == NULL) {
+               dbox_get_guid_128(guid, guid_buf);
+               memcpy(guid_128, guid_buf->data, sizeof(guid_128));
+       } else {
                mail_generate_guid_128(guid_128);
                guid = binary_to_hex(guid_128, sizeof(guid_128));
        }
index 7a0ba0c153347370841e1a2710e3d41bec6d6ca0..1a149e2d2d93641acc6e20e429470331d84bbdf9 100644 (file)
@@ -5,7 +5,6 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "hash.h"
-#include "hex-binary.h"
 #include "str.h"
 #include "dbox-storage.h"
 #include "dbox-file.h"
@@ -200,14 +199,7 @@ static int rebuild_add_file(struct dbox_storage_rebuild_context *ctx,
                        ret = 0;
                        break;
                }
-               buffer_set_used_size(guid_buf, 0);
-               if (hex_to_binary(guid, guid_buf) < 0 ||
-                   guid_buf->used != sizeof(rec->guid_128)) {
-                       dbox_file_set_corrupted(file,
-                               "Message GUID is not 128 bit hex: %s", guid);
-                       ret = 0;
-                       break;
-               }
+               dbox_get_guid_128(guid, guid_buf);
 
                rec = p_new(ctx->pool, struct dbox_rebuild_msg, 1);
                rec->file_id = file_id;