Mercurial > dovecot > core-2.2
changeset 9595:d4c1a2941c43 HEAD
dbox: Allow any kind of non-128bit GUIDs. For those store their hash to index instead.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 08 Jul 2009 17:58:02 -0400 |
parents | 49bf801bf840 |
children | d5637a78d263 |
files | 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 |
diffstat | 4 files changed, 27 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-file.c Wed Jul 08 17:57:10 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-file.c Wed Jul 08 17:58:02 2009 -0400 @@ -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 @@ 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); + } +}
--- a/src/lib-storage/index/dbox/dbox-file.h Wed Jul 08 17:57:10 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-file.h Wed Jul 08 17:58:02 2009 -0400 @@ -206,5 +206,6 @@ 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
--- a/src/lib-storage/index/dbox/dbox-save.c Wed Jul 08 17:57:10 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-save.c Wed Jul 08 17:58:02 2009 -0400 @@ -202,15 +202,9 @@ 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)); }
--- a/src/lib-storage/index/dbox/dbox-storage-rebuild.c Wed Jul 08 17:57:10 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-storage-rebuild.c Wed Jul 08 17:58:02 2009 -0400 @@ -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 @@ 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;