From: Timo Sirainen Date: Wed, 8 Jul 2009 21:58:02 +0000 (-0400) Subject: dbox: Allow any kind of non-128bit GUIDs. For those store their hash to index instead. X-Git-Tag: 2.0.alpha1~457 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=261b430b30fc5e215f19569ac360a8a51cd8da4f;p=thirdparty%2Fdovecot%2Fcore.git dbox: Allow any kind of non-128bit GUIDs. For those store their hash to index instead. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox/dbox-file.c b/src/lib-storage/index/dbox/dbox-file.c index 863198e349..abbdb993a9 100644 --- a/src/lib-storage/index/dbox/dbox-file.c +++ b/src/lib-storage/index/dbox/dbox-file.c @@ -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); + } +} diff --git a/src/lib-storage/index/dbox/dbox-file.h b/src/lib-storage/index/dbox/dbox-file.h index 6bba0b498e..d7bf8d3d5e 100644 --- a/src/lib-storage/index/dbox/dbox-file.h +++ b/src/lib-storage/index/dbox/dbox-file.h @@ -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 diff --git a/src/lib-storage/index/dbox/dbox-save.c b/src/lib-storage/index/dbox/dbox-save.c index cf77f17fae..fc71c6ea2b 100644 --- a/src/lib-storage/index/dbox/dbox-save.c +++ b/src/lib-storage/index/dbox/dbox-save.c @@ -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)); } diff --git a/src/lib-storage/index/dbox/dbox-storage-rebuild.c b/src/lib-storage/index/dbox/dbox-storage-rebuild.c index 7a0ba0c153..1a149e2d2d 100644 --- a/src/lib-storage/index/dbox/dbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox/dbox-storage-rebuild.c @@ -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;