Here are a few more patches. Still keeping it easy for now. Again the basis for these patches is dovecot-1.1.7.

Patch #6. Solve a cross-compilation endianness issue. Currently, Dovecot assumes that the endianness of the build system is the same as the endianness of the runtime system. This is not necessarily true. We ran into this while compiling for i386 on a ppc machine. The patch switches to using gcc's __BIG_ENDIAN__ macro; see the comment in the patch to configure.in. It also removes the related and unused MAIL_INDEX_COMPAT_FLAGS parameter. This patch may be applicable to other build environments with a little tweaking.
diff -ur dovecot-1.1.7/config.h.in dovecot-patch/config.h.in
--- dovecot-1.1.7/config.h.in   2008-11-23 16:16:57.000000000 -0600
+++ dovecot-patch/config.h.in   2008-12-16 20:34:01.000000000 -0600
@@ -458,9 +458,6 @@
 /* Define if you have ldap_start_tls_s */
 #undef LDAP_HAVE_START_TLS_S
 
-/* Index file compatibility flags */
-#undef MAIL_INDEX_COMPAT_FLAGS
-
 /* List of compiled in mail storages */
 #undef MAIL_STORAGES
 
diff -ur dovecot-1.1.7/configure.in dovecot-patch/configure.in
--- dovecot-1.1.7/configure.in  2008-11-23 16:16:26.000000000 -0600
+++ dovecot-patch/configure.in  2008-12-16 20:35:08.000000000 -0600
@@ -2164,15 +2164,18 @@
 
 dnl * currently just checking for endianess
 
-AC_C_BIGENDIAN
-
-if test $ac_cv_c_bigendian = yes; then
-       flags=0
-else
-       flags=1
-fi
-
-AC_DEFINE_UNQUOTED(MAIL_INDEX_COMPAT_FLAGS, $flags, Index file compatibility 
flags)
+dnl APPLE
+case "$host_os" in
+darwin*)
+       dnl The build system's endianness is not necessarily the same as
+       dnl the runtime system's endianness, thanks to the -arch gcc flag
+       dnl and fat binaries.  So leave the endianness determination up
+       dnl to gcc by using __BIG_ENDIAN__ which is set by -arch.
+       AC_DEFINE(WORDS_BIGENDIAN, __BIG_ENDIAN__, APPLE)
+       ;;
+*)     AC_C_BIGENDIAN
+       ;;
+esac
 
 dnl **
 dnl ** IPv6 support
diff -ur dovecot-1.1.7/src/lib/sha1.c dovecot-patch/src/lib/sha1.c
--- dovecot-1.1.7/src/lib/sha1.c        2008-10-26 10:03:45.000000000 -0500
+++ dovecot-patch/src/lib/sha1.c        2008-12-16 20:35:37.000000000 -0600
@@ -80,7 +80,7 @@
        size_t t, s;
        uint32_t        tmp;
 
-#ifndef WORDS_BIGENDIAN
+#if !WORDS_BIGENDIAN
        struct sha1_ctxt tctxt;
        memmove(&tctxt.m.b8[0], &ctxt->m.b8[0], 64);
        ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
@@ -189,7 +189,7 @@
        memset(&ctxt->m.b8[padstart], 0, padlen - 8);
        COUNT += (padlen - 8);
        COUNT %= 64;
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
        PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
        PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
        PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
@@ -235,7 +235,7 @@
 
        digest = (uint8_t *)digest0;
        sha1_pad(ctxt);
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
        memmove(digest, &ctxt->h.b8[0], 20);
 #else
        digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];
diff -ur dovecot-1.1.7/src/lib-index/mail-index-map.c 
dovecot-patch/src/lib-index/mail-index-map.c
--- dovecot-1.1.7/src/lib-index/mail-index-map.c        2008-10-26 
10:03:45.000000000 -0500
+++ dovecot-patch/src/lib-index/mail-index-map.c        2008-12-16 
20:35:15.000000000 -0600
@@ -367,7 +367,7 @@
 {
         enum mail_index_header_compat_flags compat_flags = 0;
 
-#ifndef WORDS_BIGENDIAN
+#if !WORDS_BIGENDIAN
        compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 #endif
 
@@ -784,7 +784,7 @@
        hdr->header_size = sizeof(*hdr);
        hdr->record_size = sizeof(struct mail_index_record);
 
-#ifndef WORDS_BIGENDIAN
+#if !WORDS_BIGENDIAN
        hdr->compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 #endif
 
diff -ur dovecot-1.1.7/src/lib-index/mail-index.c 
dovecot-patch/src/lib-index/mail-index.c
--- dovecot-1.1.7/src/lib-index/mail-index.c    2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/lib-index/mail-index.c    2008-12-16 20:35:31.000000000 
-0600
@@ -633,7 +633,7 @@
         index->index_lock_timeout = FALSE;
 }
 
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
 /* FIXME: Unfortunately these functions were originally written to use
    endian-specific code and we can't avoid that without breaking backwards
    compatibility. When we do break it, just select one of these. */



Patch #7. Replace all occurrences of "hash_create" and "hash_destroy" with "hash_table_create" and "hash_table_destroy" respectively. The symbols hash_create and hash_destroy conflict with symbols defined in <strhash.h> and libc. This showed up when loading dovecot's quota plugin (one of our future patches will add a hash table to it; stay tuned). The wrong hash_create was called which caused a crash at the first hash_insert. Apparently this is only a problem in loaded dynamic libraries and not linked-in ones.
diff -ur dovecot-1.1.7/src/auth/auth-cache.c dovecot-patch/src/auth/auth-cache.c
--- dovecot-1.1.7/src/auth/auth-cache.c 2008-10-26 10:00:45.000000000 -0500
+++ dovecot-patch/src/auth/auth-cache.c 2008-12-16 21:11:17.000000000 -0600
@@ -119,8 +119,8 @@
        struct auth_cache *cache;
 
        cache = i_new(struct auth_cache, 1);
-       cache->hash = hash_create(default_pool, default_pool, 0, str_hash,
-                                 (hash_cmp_callback_t *)strcmp);
+       cache->hash = hash_table_create(default_pool, default_pool, 0, str_hash,
+                                       (hash_cmp_callback_t *)strcmp);
        cache->size_left = max_size;
        cache->ttl_secs = ttl_secs;
        cache->neg_ttl_secs = neg_ttl_secs;
@@ -139,7 +139,7 @@
        lib_signals_unset_handler(SIGUSR2, sig_auth_cache_stats, cache);
 
        auth_cache_clear(cache);
-       hash_destroy(&cache->hash);
+       hash_table_destroy(&cache->hash);
        i_free(cache);
 }
 
diff -ur dovecot-1.1.7/src/auth/auth-request-handler.c 
dovecot-patch/src/auth/auth-request-handler.c
--- dovecot-1.1.7/src/auth/auth-request-handler.c       2008-10-26 
10:00:45.000000000 -0500
+++ dovecot-patch/src/auth/auth-request-handler.c       2008-12-16 
21:11:17.000000000 -0600
@@ -52,7 +52,7 @@
        handler = p_new(pool, struct auth_request_handler, 1);
        handler->refcount = 1;
        handler->pool = pool;
-       handler->requests = hash_create(default_pool, pool, 0, NULL, NULL);
+       handler->requests = hash_table_create(default_pool, pool, 0, NULL, 
NULL);
        handler->auth = auth;
        handler->callback = callback;
        handler->context = context;
@@ -82,7 +82,7 @@
        /* notify parent that we're done with all requests */
        handler->callback(NULL, handler->context);
 
-       hash_destroy(&handler->requests);
+       hash_table_destroy(&handler->requests);
        pool_unref(&handler->pool);
 }
 
diff -ur dovecot-1.1.7/src/auth/db-ldap.c dovecot-patch/src/auth/db-ldap.c
--- dovecot-1.1.7/src/auth/db-ldap.c    2008-10-26 10:00:45.000000000 -0500
+++ dovecot-patch/src/auth/db-ldap.c    2008-12-16 21:11:17.000000000 -0600
@@ -1260,9 +1260,9 @@
        aqueue_deinit(&conn->request_queue);
 
        if (conn->pass_attr_map != NULL)
-               hash_destroy(&conn->pass_attr_map);
+               hash_table_destroy(&conn->pass_attr_map);
        if (conn->user_attr_map != NULL)
-               hash_destroy(&conn->user_attr_map);
+               hash_table_destroy(&conn->user_attr_map);
        pool_unref(&conn->pool);
 }
 
diff -ur dovecot-1.1.7/src/auth/db-passwd-file.c 
dovecot-patch/src/auth/db-passwd-file.c
--- dovecot-1.1.7/src/auth/db-passwd-file.c     2008-11-19 08:29:51.000000000 
-0600
+++ dovecot-patch/src/auth/db-passwd-file.c     2008-12-16 21:11:17.000000000 
-0600
@@ -179,8 +179,8 @@
        pw->size = st.st_size;
 
        pw->pool = pool_alloconly_create(MEMPOOL_GROWING"passwd_file", 10240);
-       pw->users = hash_create(default_pool, pw->pool, 100,
-                               str_hash, (hash_cmp_callback_t *)strcmp);
+       pw->users = hash_table_create(default_pool, pw->pool, 100,
+                                     str_hash, (hash_cmp_callback_t *)strcmp);
 
        input = i_stream_create_fd(pw->fd, 4096, FALSE);
        i_stream_set_return_partial_line(input, TRUE);
@@ -217,7 +217,7 @@
        }
 
        if (pw->users != NULL)
-               hash_destroy(&pw->users);
+               hash_table_destroy(&pw->users);
        if (pw->pool != NULL)
                pool_unref(&pw->pool);
 }
@@ -309,9 +309,9 @@
 
        db->path = i_strdup(path);
        if (db->vars) {
-               db->files = hash_create(default_pool, default_pool, 100,
-                                       str_hash,
-                                       (hash_cmp_callback_t *)strcmp);
+               db->files = hash_table_create(default_pool, default_pool, 100,
+                                             str_hash,
+                                             (hash_cmp_callback_t *)strcmp);
        } else {
                db->default_file = passwd_file_new(db, path);
        }
@@ -359,7 +359,7 @@
                        passwd_file_free(file);
                }
                hash_iterate_deinit(&iter);
-               hash_destroy(&db->files);
+               hash_table_destroy(&db->files);
        }
        i_free(db->path);
        i_free(db);
diff -ur dovecot-1.1.7/src/auth/otp-skey-common.c 
dovecot-patch/src/auth/otp-skey-common.c
--- dovecot-1.1.7/src/auth/otp-skey-common.c    2008-10-26 10:00:45.000000000 
-0500
+++ dovecot-patch/src/auth/otp-skey-common.c    2008-12-16 21:09:53.000000000 
-0600
@@ -20,9 +20,9 @@
        if (otp_lock_table != NULL)
                return;
 
-       otp_lock_table = hash_create(system_pool, system_pool,
-                                    128, strcase_hash,
-                                    (hash_cmp_callback_t *)strcasecmp);
+       otp_lock_table = hash_table_create(system_pool, system_pool,
+                                          128, strcase_hash,
+                                          (hash_cmp_callback_t *)strcasecmp);
 }
 
 int otp_try_lock(struct auth_request *auth_request)
diff -ur dovecot-1.1.7/src/auth/passdb-checkpassword.c 
dovecot-patch/src/auth/passdb-checkpassword.c
--- dovecot-1.1.7/src/auth/passdb-checkpassword.c       2008-10-26 
10:00:45.000000000 -0500
+++ dovecot-patch/src/auth/passdb-checkpassword.c       2008-12-16 
21:11:17.000000000 -0600
@@ -438,7 +438,7 @@
                PKG_LIBEXECDIR"/checkpassword-reply";
 
        module->clients =
-               hash_create(default_pool, default_pool, 0, NULL, NULL);
+               hash_table_create(default_pool, default_pool, 0, NULL, NULL);
 
        return &module->module;
 }
@@ -464,7 +464,7 @@
                                             PASSDB_RESULT_INTERNAL_FAILURE);
        }
        hash_iterate_deinit(&iter);
-       hash_destroy(&module->clients);
+       hash_table_destroy(&module->clients);
 }
 
 struct passdb_module_interface passdb_checkpassword = {
diff -ur dovecot-1.1.7/src/auth/passdb-ldap.c 
dovecot-patch/src/auth/passdb-ldap.c
--- dovecot-1.1.7/src/auth/passdb-ldap.c        2008-10-26 10:00:45.000000000 
-0500
+++ dovecot-patch/src/auth/passdb-ldap.c        2008-12-16 21:09:53.000000000 
-0600
@@ -393,8 +393,8 @@
        module = p_new(auth_passdb->auth->pool, struct ldap_passdb_module, 1);
        module->conn = conn = db_ldap_init(args);
        conn->pass_attr_map =
-               hash_create(default_pool, conn->pool, 0, str_hash,
-                           (hash_cmp_callback_t *)strcmp);
+               hash_table_create(default_pool, conn->pool, 0, str_hash,
+                                 (hash_cmp_callback_t *)strcmp);
 
        db_ldap_set_attrs(conn, conn->set.pass_attrs, &conn->pass_attr_names,
                          conn->pass_attr_map,
diff -ur dovecot-1.1.7/src/auth/userdb-ldap.c 
dovecot-patch/src/auth/userdb-ldap.c
--- dovecot-1.1.7/src/auth/userdb-ldap.c        2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/auth/userdb-ldap.c        2008-12-16 21:09:53.000000000 
-0600
@@ -123,8 +123,8 @@
        module = p_new(auth_userdb->auth->pool, struct ldap_userdb_module, 1);
        module->conn = conn = db_ldap_init(args);
        conn->user_attr_map =
-               hash_create(default_pool, conn->pool, 0, str_hash,
-                           (hash_cmp_callback_t *)strcmp);
+               hash_table_create(default_pool, conn->pool, 0, str_hash,
+                                 (hash_cmp_callback_t *)strcmp);
 
        db_ldap_set_attrs(conn, conn->set.user_attrs, &conn->user_attr_names,
                          conn->user_attr_map, NULL);
diff -ur dovecot-1.1.7/src/deliver/duplicate.c 
dovecot-patch/src/deliver/duplicate.c
--- dovecot-1.1.7/src/deliver/duplicate.c       2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/deliver/duplicate.c       2008-12-16 21:11:17.000000000 
-0600
@@ -212,8 +212,8 @@
                                         &file->dotlock);
        if (file->new_fd == -1)
                i_error("file_dotlock_create(%s) failed: %m", path);
-       file->hash = hash_create(default_pool, pool, 0,
-                                duplicate_hash, duplicate_cmp);
+       file->hash = hash_table_create(default_pool, pool, 0,
+                                      duplicate_hash, duplicate_cmp);
        (void)duplicate_read(file);
        return file;
 }
@@ -226,7 +226,7 @@
        if (file->dotlock != NULL)
                file_dotlock_delete(&file->dotlock);
 
-       hash_destroy(&file->hash);
+       hash_table_destroy(&file->hash);
        pool_unref(&file->pool);
 }
 
diff -ur dovecot-1.1.7/src/imap/imap-thread.c 
dovecot-patch/src/imap/imap-thread.c
--- dovecot-1.1.7/src/imap/imap-thread.c        2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/imap/imap-thread.c        2008-12-16 21:11:17.000000000 
-0600
@@ -93,9 +93,9 @@
 static void mail_thread_deinit(struct thread_context *ctx)
 {
        if (ctx->msgid_hash != NULL)
-               hash_destroy(&ctx->msgid_hash);
+               hash_table_destroy(&ctx->msgid_hash);
        if (ctx->subject_hash != NULL)
-               hash_destroy(&ctx->subject_hash);
+               hash_table_destroy(&ctx->subject_hash);
 
        pool_unref(&ctx->temp_pool);
        pool_unref(&ctx->pool);
@@ -131,9 +131,9 @@
        ctx->temp_pool = pool_alloconly_create("thread_context temp",
                                               APPROX_MSG_COUNT *
                                               APPROX_MSGID_SIZE);
-       ctx->msgid_hash = hash_create(default_pool, ctx->temp_pool,
-                                     APPROX_MSG_COUNT*2, str_hash,
-                                     (hash_cmp_callback_t *)strcmp);
+       ctx->msgid_hash = hash_table_create(default_pool, ctx->temp_pool,
+                                           APPROX_MSG_COUNT*2, str_hash,
+                                           (hash_cmp_callback_t *)strcmp);
        ctx->id_is_uid = cmd->uid;
 
        headers_ctx = mailbox_header_lookup_init(client->mailbox,
@@ -676,8 +676,8 @@
        uint32_t seq;
 
        ctx->subject_hash =
-               hash_create(default_pool, ctx->temp_pool, ctx->root_count * 2,
-                           str_hash, (hash_cmp_callback_t *)strcmp);
+               hash_table_create(default_pool, ctx->temp_pool, ctx->root_count 
* 2,
+                                 str_hash, (hash_cmp_callback_t *)strcmp);
 
        headers_ctx = mailbox_header_lookup_init(ctx->box, wanted_headers);
        ctx->mail = mail_alloc(ctx->t, 0, headers_ctx);
@@ -947,7 +947,7 @@
 
        /* drop the memory allocated for message-IDs and msgid_hash,
           reuse their memory for base subjects */
-       hash_destroy(&ctx->msgid_hash);
+       hash_table_destroy(&ctx->msgid_hash);
        p_clear(ctx->temp_pool);
 
        if (ctx->root_node.first_child == NULL) {
diff -ur dovecot-1.1.7/src/lib/hash.c dovecot-patch/src/lib/hash.c
--- dovecot-1.1.7/src/lib/hash.c        2008-10-26 10:03:45.000000000 -0500
+++ dovecot-patch/src/lib/hash.c        2008-12-16 21:11:17.000000000 -0600
@@ -50,8 +50,8 @@
 }
 
 struct hash_table *
-hash_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
-           hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb)
+hash_table_create(pool_t table_pool, pool_t node_pool, unsigned int 
initial_size,
+                 hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb)
 {
        struct hash_table *table;
 
@@ -101,7 +101,7 @@
        }
 }
 
-void hash_destroy(struct hash_table **_table)
+void hash_table_destroy(struct hash_table **_table)
 {
        struct hash_table *table = *_table;
 
diff -ur dovecot-1.1.7/src/lib/hash.h dovecot-patch/src/lib/hash.h
--- dovecot-1.1.7/src/lib/hash.h        2008-10-26 10:03:45.000000000 -0500
+++ dovecot-patch/src/lib/hash.h        2008-12-16 21:11:17.000000000 -0600
@@ -11,11 +11,12 @@
 
    table_pool is used to allocate/free large hash tables, node_pool is used
    for smaller allocations and can also be alloconly pool. The pools must not
-   be free'd before hash_destroy() is called. */
+   be free'd before hash_table_destroy() is called. */
+/* APPLE - renamed from hash_create/hash_destroy to avoid libc conflict */
 struct hash_table *
-hash_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
-           hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb);
-void hash_destroy(struct hash_table **table);
+hash_table_create(pool_t table_pool, pool_t node_pool, unsigned int 
initial_size,
+                 hash_callback_t *hash_cb, hash_cmp_callback_t 
*key_compare_cb);
+void hash_table_destroy(struct hash_table **table);
 /* Remove all nodes from hash table. If free_collisions is TRUE, the
    memory allocated from node_pool is freed, or discarded with
    alloconly pools. */
diff -ur dovecot-1.1.7/src/lib-auth/auth-server-connection.c 
dovecot-patch/src/lib-auth/auth-server-connection.c
--- dovecot-1.1.7/src/lib-auth/auth-server-connection.c 2008-10-26 
10:03:45.000000000 -0500
+++ dovecot-patch/src/lib-auth/auth-server-connection.c 2008-12-16 
21:11:17.000000000 -0600
@@ -248,7 +248,7 @@
        conn->input = i_stream_create_fd(fd, AUTH_CLIENT_MAX_LINE_LENGTH,
                                         FALSE);
        conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
-       conn->requests = hash_create(default_pool, pool, 100, NULL, NULL);
+       conn->requests = hash_table_create(default_pool, pool, 100, NULL, NULL);
        conn->auth_mechs_buf = buffer_create_dynamic(default_pool, 256);
 
        conn->to = timeout_add(AUTH_HANDSHAKE_TIMEOUT,
@@ -324,7 +324,7 @@
                return;
        i_assert(conn->refcount == 0);
 
-       hash_destroy(&conn->requests);
+       hash_table_destroy(&conn->requests);
        buffer_free(&conn->auth_mechs_buf);
 
        i_stream_unref(&conn->input);
diff -ur dovecot-1.1.7/src/lib-index/mail-cache.c 
dovecot-patch/src/lib-index/mail-cache.c
--- dovecot-1.1.7/src/lib-index/mail-cache.c    2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/lib-index/mail-cache.c    2008-12-16 21:11:17.000000000 
-0600
@@ -409,8 +409,8 @@
                i_strconcat(index->filepath, MAIL_CACHE_FILE_SUFFIX, NULL);
        cache->field_pool = pool_alloconly_create("Cache fields", 1024);
        cache->field_name_hash =
-               hash_create(default_pool, cache->field_pool, 0,
-                           strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+               hash_table_create(default_pool, cache->field_pool, 0,
+                                 strcase_hash, (hash_cmp_callback_t 
*)strcasecmp);
 
        cache->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
        cache->dotlock_settings.nfs_flush = index->nfs_flush;
@@ -478,7 +478,7 @@
 
        mail_cache_file_close(cache);
 
-       hash_destroy(&cache->field_name_hash);
+       hash_table_destroy(&cache->field_name_hash);
        pool_unref(&cache->field_pool);
        i_free(cache->field_file_map);
        i_free(cache->file_field_map);
diff -ur dovecot-1.1.7/src/lib-index/mail-index.c 
dovecot-patch/src/lib-index/mail-index.c
--- dovecot-1.1.7/src/lib-index/mail-index.c    2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/lib-index/mail-index.c    2008-12-16 21:11:17.000000000 
-0600
@@ -47,8 +47,8 @@
        index->keywords_pool = pool_alloconly_create("keywords", 512);
        i_array_init(&index->keywords, 16);
        index->keywords_hash =
-               hash_create(default_pool, index->keywords_pool, 0,
-                           strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+               hash_table_create(default_pool, index->keywords_pool, 0,
+                                 strcase_hash, (hash_cmp_callback_t 
*)strcasecmp);
        index->log = mail_transaction_log_alloc(index);
        return index;
 }
@@ -61,7 +61,7 @@
        mail_index_close(index);
 
        mail_transaction_log_free(&index->log);
-       hash_destroy(&index->keywords_hash);
+       hash_table_destroy(&index->keywords_hash);
        pool_unref(&index->extension_pool);
        pool_unref(&index->keywords_pool);
 
diff -ur dovecot-1.1.7/src/lib-sql/sql-pool.c 
dovecot-patch/src/lib-sql/sql-pool.c
--- dovecot-1.1.7/src/lib-sql/sql-pool.c        2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/lib-sql/sql-pool.c        2008-12-16 21:11:17.000000000 
-0600
@@ -122,8 +122,8 @@
        struct sql_pool *pool;
 
        pool = i_new(struct sql_pool, 1);
-       pool->dbs = hash_create(default_pool, default_pool, 0, str_hash,
-                               (hash_cmp_callback_t *)strcmp);
+       pool->dbs = hash_table_create(default_pool, default_pool, 0, str_hash,
+                                     (hash_cmp_callback_t *)strcmp);
        pool->max_unused_connections = max_unused_connections;
        return pool;
 }
@@ -133,6 +133,6 @@
        struct sql_pool *pool = *_pool;
 
        *_pool = NULL;
-       hash_destroy(&pool->dbs);
+       hash_table_destroy(&pool->dbs);
        i_free(pool);
 }
diff -ur dovecot-1.1.7/src/lib-storage/index/dbox/dbox-sync.c 
dovecot-patch/src/lib-storage/index/dbox/dbox-sync.c
--- dovecot-1.1.7/src/lib-storage/index/dbox/dbox-sync.c        2008-10-26 
10:03:45.000000000 -0500
+++ dovecot-patch/src/lib-storage/index/dbox/dbox-sync.c        2008-12-16 
21:11:17.000000000 -0600
@@ -205,7 +205,7 @@
 
        /* read all changes and sort them to file_id order */
        ctx->pool = pool_alloconly_create("dbox sync pool", 1024*32);
-       ctx->syncs = hash_create(default_pool, ctx->pool, 0, NULL, NULL);
+       ctx->syncs = hash_table_create(default_pool, ctx->pool, 0, NULL, NULL);
        i_array_init(&ctx->expunge_files, 32);
        i_array_init(&ctx->locked_files, 32);
 
@@ -243,7 +243,7 @@
 
        dbox_sync_unlock_files(ctx);
        array_free(&ctx->locked_files);
-       hash_destroy(&ctx->syncs);
+       hash_table_destroy(&ctx->syncs);
        pool_unref(&ctx->pool);
        return ret;
 }
diff -ur dovecot-1.1.7/src/lib-storage/index/maildir/maildir-keywords.c 
dovecot-patch/src/lib-storage/index/maildir/maildir-keywords.c
--- dovecot-1.1.7/src/lib-storage/index/maildir/maildir-keywords.c      
2008-10-26 10:03:45.000000000 -0500
+++ dovecot-patch/src/lib-storage/index/maildir/maildir-keywords.c      
2008-12-16 21:11:17.000000000 -0600
@@ -71,8 +71,8 @@
        mk->path = i_strconcat(dir, "/" MAILDIR_KEYWORDS_NAME, NULL);
        mk->pool = pool_alloconly_create("maildir keywords", 512);
        i_array_init(&mk->list, MAILDIR_MAX_KEYWORDS);
-       mk->hash = hash_create(default_pool, mk->pool, 0,
-                              strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+       mk->hash = hash_table_create(default_pool, mk->pool, 0,
+                                    strcase_hash, (hash_cmp_callback_t 
*)strcasecmp);
 
        mk->dotlock_settings.use_excl_lock =
                (box->storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
@@ -91,7 +91,7 @@
        struct maildir_keywords *mk = *_mk;
 
        *_mk = NULL;
-       hash_destroy(&mk->hash);
+       hash_table_destroy(&mk->hash);
        array_free(&mk->list);
        pool_unref(&mk->pool);
        i_free(mk->path);
diff -ur dovecot-1.1.7/src/lib-storage/index/maildir/maildir-uidlist.c 
dovecot-patch/src/lib-storage/index/maildir/maildir-uidlist.c
--- dovecot-1.1.7/src/lib-storage/index/maildir/maildir-uidlist.c       
2008-10-26 10:03:45.000000000 -0500
+++ dovecot-patch/src/lib-storage/index/maildir/maildir-uidlist.c       
2008-12-16 21:11:17.000000000 -0600
@@ -228,9 +228,9 @@
        uidlist->ibox = ibox;
        uidlist->path = i_strconcat(control_dir, "/"MAILDIR_UIDLIST_NAME, NULL);
        i_array_init(&uidlist->records, 128);
-       uidlist->files = hash_create(default_pool, default_pool, 4096,
-                                    maildir_filename_base_hash,
-                                    maildir_filename_base_cmp);
+       uidlist->files = hash_table_create(default_pool, default_pool, 4096,
+                                          maildir_filename_base_hash,
+                                          maildir_filename_base_cmp);
        uidlist->next_uid = 1;
        uidlist->hdr_extensions = str_new(default_pool, 128);
 
@@ -280,7 +280,7 @@
        maildir_uidlist_update(uidlist);
        maildir_uidlist_close(uidlist);
 
-       hash_destroy(&uidlist->files);
+       hash_table_destroy(&uidlist->files);
        if (uidlist->record_pool != NULL)
                pool_unref(&uidlist->record_pool);
 
@@ -1327,9 +1327,9 @@
 
        ctx->record_pool = pool_alloconly_create(MEMPOOL_GROWING
                                                 "maildir_uidlist_sync", 16384);
-       ctx->files = hash_create(default_pool, ctx->record_pool, 4096,
-                                maildir_filename_base_hash,
-                                maildir_filename_base_cmp);
+       ctx->files = hash_table_create(default_pool, ctx->record_pool, 4096,
+                                      maildir_filename_base_hash,
+                                      maildir_filename_base_cmp);
 
        i_array_init(&ctx->records, array_count(&uidlist->records));
        return 1;
@@ -1572,7 +1572,7 @@
        uidlist->records = ctx->records;
        ctx->records.arr.buffer = NULL;
 
-       hash_destroy(&uidlist->files);
+       hash_table_destroy(&uidlist->files);
        uidlist->files = ctx->files;
        ctx->files = NULL;
 
@@ -1626,7 +1626,7 @@
                maildir_uidlist_unlock(ctx->uidlist);
 
        if (ctx->files != NULL)
-               hash_destroy(&ctx->files);
+               hash_table_destroy(&ctx->files);
        if (ctx->record_pool != NULL)
                pool_unref(&ctx->record_pool);
        if (array_is_created(&ctx->records))
diff -ur dovecot-1.1.7/src/login-common/master.c 
dovecot-patch/src/login-common/master.c
--- dovecot-1.1.7/src/login-common/master.c     2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/login-common/master.c     2008-12-16 21:11:17.000000000 
-0600
@@ -262,8 +262,8 @@
        main_ref();
 
        master_fd = fd;
-       master_requests = hash_create(system_pool, system_pool,
-                                     0, NULL, NULL);
+       master_requests = hash_table_create(system_pool, system_pool,
+                                           0, NULL, NULL);
 
         master_pos = 0;
        io_master = io_add(master_fd, IO_READ, master_input, NULL);
@@ -271,7 +271,7 @@
 
 void master_deinit(void)
 {
-       hash_destroy(&master_requests);
+       hash_table_destroy(&master_requests);
 
        if (io_master != NULL)
                io_remove(&io_master);
diff -ur dovecot-1.1.7/src/login-common/ssl-proxy-gnutls.c 
dovecot-patch/src/login-common/ssl-proxy-gnutls.c
--- dovecot-1.1.7/src/login-common/ssl-proxy-gnutls.c   2008-10-26 
10:03:45.000000000 -0500
+++ dovecot-patch/src/login-common/ssl-proxy-gnutls.c   2008-12-16 
21:11:17.000000000 -0600
@@ -519,7 +519,7 @@
         gnutls_certificate_set_dh_params(x509_cred, dh_params);
         gnutls_certificate_set_rsa_export_params(x509_cred, rsa_params);
 
-        ssl_proxies = hash_create(system_pool, system_pool, 0, NULL, NULL);
+        ssl_proxies = hash_table_create(system_pool, system_pool, 0, NULL, 
NULL);
        ssl_initialized = TRUE;
 }
 
@@ -535,7 +535,7 @@
        while (hash_iterate(iter, &key, &value))
                ssl_proxy_destroy(value);
        hash_iterate_deinit(iter);
-       hash_destroy(ssl_proxies);
+       hash_table_destroy(ssl_proxies);
 
        gnutls_certificate_free_credentials(x509_cred);
        gnutls_global_deinit();
diff -ur dovecot-1.1.7/src/master/auth-process.c 
dovecot-patch/src/master/auth-process.c
--- dovecot-1.1.7/src/master/auth-process.c     2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/master/auth-process.c     2008-12-16 21:11:17.000000000 
-0600
@@ -314,7 +314,7 @@
        p->io = io_add(fd, IO_READ, auth_process_input, p);
        p->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
        p->output = o_stream_create_fd(fd, MAX_OUTBUF_SIZE, FALSE);
-       p->requests = hash_create(default_pool, default_pool, 0, NULL, NULL);
+       p->requests = hash_table_create(default_pool, default_pool, 0, NULL, 
NULL);
 
        group->process_count++;
 
@@ -381,7 +381,7 @@
        while (hash_iterate(iter, &key, &value))
                auth_master_callback(NULL, NULL, value);
        hash_iterate_deinit(&iter);
-       hash_destroy(&p->requests);
+       hash_table_destroy(&p->requests);
 
        i_stream_destroy(&p->input);
        o_stream_destroy(&p->output);
diff -ur dovecot-1.1.7/src/master/child-process.c 
dovecot-patch/src/master/child-process.c
--- dovecot-1.1.7/src/master/child-process.c    2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/master/child-process.c    2008-12-16 21:11:17.000000000 
-0600
@@ -198,7 +198,7 @@
 
 void child_processes_init(void)
 {
-       processes = hash_create(default_pool, default_pool, 128, NULL, NULL);
+       processes = hash_table_create(default_pool, default_pool, 128, NULL, 
NULL);
        lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL);
 }
 
@@ -207,5 +207,5 @@
        /* make sure we log if child processes died unexpectedly */
        sigchld_handler(SIGCHLD, NULL);
        lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL);
-       hash_destroy(&processes);
+       hash_table_destroy(&processes);
 }
diff -ur dovecot-1.1.7/src/master/mail-process.c 
dovecot-patch/src/master/mail-process.c
--- dovecot-1.1.7/src/master/mail-process.c     2008-11-15 11:36:54.000000000 
-0600
+++ dovecot-patch/src/master/mail-process.c     2008-12-16 21:11:17.000000000 
-0600
@@ -912,9 +912,9 @@
 
 void mail_processes_init(void)
 {
-       mail_process_groups = hash_create(default_pool, default_pool, 0,
-                                         mail_process_group_hash,
-                                         mail_process_group_cmp);
+       mail_process_groups = hash_table_create(default_pool, default_pool, 0,
+                                               mail_process_group_hash,
+                                               mail_process_group_cmp);
 
        child_process_set_destroy_callback(PROCESS_TYPE_IMAP,
                                           mail_process_destroyed);
@@ -934,5 +934,5 @@
        }
        hash_iterate_deinit(&iter);
 
-       hash_destroy(&mail_process_groups);
+       hash_table_destroy(&mail_process_groups);
 }
diff -ur dovecot-1.1.7/src/plugins/acl/acl-cache.c 
dovecot-patch/src/plugins/acl/acl-cache.c
--- dovecot-1.1.7/src/plugins/acl/acl-cache.c   2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/plugins/acl/acl-cache.c   2008-12-16 21:11:17.000000000 
-0600
@@ -48,11 +48,11 @@
        cache->validity_rec_size = validity_rec_size;
        cache->right_names_pool =
                pool_alloconly_create("ACL right names", 1024);
-       cache->objects = hash_create(default_pool, default_pool, 0,
-                                    str_hash, (hash_cmp_callback_t *)strcmp);
+       cache->objects = hash_table_create(default_pool, default_pool, 0,
+                                          str_hash, (hash_cmp_callback_t 
*)strcmp);
        cache->right_name_idx_map =
-               hash_create(default_pool, cache->right_names_pool, 0,
-                           str_hash, (hash_cmp_callback_t *)strcmp);
+               hash_table_create(default_pool, cache->right_names_pool, 0,
+                                 str_hash, (hash_cmp_callback_t *)strcmp);
        i_array_init(&cache->right_idx_name_map, DEFAULT_ACL_RIGHTS_COUNT);
        return cache;
 }
@@ -65,8 +65,8 @@
 
        acl_cache_flush_all(cache);
        array_free(&cache->right_idx_name_map);
-       hash_destroy(&cache->right_name_idx_map);
-       hash_destroy(&cache->objects);
+       hash_table_destroy(&cache->right_name_idx_map);
+       hash_table_destroy(&cache->objects);
        pool_unref(&cache->right_names_pool);
        i_free(cache);
 }



Patch #8. Back off after auth failures to deter abusers. Stalls 5 seconds per failed attempt.
diff -ur dovecot-1.1.7/src/imap-login/client-authenticate.c 
dovecot-patch/src/imap-login/client-authenticate.c
--- dovecot-1.1.7/src/imap-login/client-authenticate.c  2008-10-29 
11:18:51.000000000 -0500
+++ dovecot-patch/src/imap-login/client-authenticate.c  2008-12-17 
09:00:25.000000000 -0600
@@ -75,16 +75,6 @@
        }
 }
 
-static void client_auth_failed(struct imap_client *client)
-{
-       /* get back to normal client input. */
-       if (client->io != NULL)
-               io_remove(&client->io);
-       client->io = io_add(client->common.fd, IO_READ,
-                           client_input, client);
-       client_input(client);
-}
-
 static bool client_handle_args(struct imap_client *client,
                               const char *const *args, bool success)
 {
diff -ur dovecot-1.1.7/src/imap-login/client.c 
dovecot-patch/src/imap-login/client.c
--- dovecot-1.1.7/src/imap-login/client.c       2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/imap-login/client.c       2008-12-17 08:58:53.000000000 
-0600
@@ -432,6 +432,45 @@
                            client_auth_waiting_timeout, client);
 }
 
+/* APPLE */    
+static void client_authfail_delay_timeout(struct imap_client *client)
+{
+       i_assert(client->to_authfail_delay != NULL);
+       timeout_remove(&client->to_authfail_delay);
+
+       i_assert(client->to_idle_disconnect == NULL);
+       client->to_idle_disconnect =
+               timeout_add(CLIENT_LOGIN_IDLE_TIMEOUT_MSECS,
+                           client_idle_disconnect_timeout, client);
+
+       /* get back to normal client input. */
+       i_assert(client->io == NULL);
+       client->io = io_add(client->common.fd, IO_READ, client_input, client);
+       client_input(client);
+}
+
+/* APPLE - delay after unsuccessful auth to foil attackers */
+void client_auth_failed(struct imap_client *client)
+{
+       unsigned int delay;
+
+       delay = client->common.auth_attempts;
+       if (delay < 1)
+               delay = 1;
+       delay *= 5 * 1000;
+
+       if (client->io != NULL)
+               io_remove(&client->io);
+
+       i_assert(client->to_idle_disconnect != NULL);
+       timeout_remove(&client->to_idle_disconnect);
+
+       i_assert(client->to_authfail_delay == NULL);
+       client->to_authfail_delay = timeout_add(delay,
+                                               client_authfail_delay_timeout,
+                                               client);
+}
+
 struct client *client_create(int fd, bool ssl, const struct ip_addr *local_ip,
                             const struct ip_addr *ip)
 {
@@ -511,6 +550,10 @@
        if (client->to_auth_waiting != NULL)
                timeout_remove(&client->to_auth_waiting);
 
+       /* APPLE */
+       if (client->to_authfail_delay != NULL)
+               timeout_remove(&client->to_authfail_delay);
+
        if (client->common.fd != -1) {
                net_disconnect(client->common.fd);
                client->common.fd = -1;
diff -ur dovecot-1.1.7/src/imap-login/client.h 
dovecot-patch/src/imap-login/client.h
--- dovecot-1.1.7/src/imap-login/client.h       2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/imap-login/client.h       2008-12-17 08:58:58.000000000 
-0600
@@ -16,6 +16,7 @@
        struct ostream *output;
        struct imap_parser *parser;
        struct timeout *to_idle_disconnect, *to_auth_waiting;
+       struct timeout *to_authfail_delay;              /* APPLE */
 
        struct login_proxy *proxy;
        char *proxy_user, *proxy_password;
@@ -43,6 +44,7 @@
 bool client_read(struct imap_client *client);
 bool client_skip_line(struct imap_client *client);
 void client_input(struct imap_client *client);
+void client_auth_failed(struct imap_client *client);           /* APPLE */
 
 void client_ref(struct imap_client *client);
 bool client_unref(struct imap_client *client);
diff -ur dovecot-1.1.7/src/pop3-login/client-authenticate.c 
dovecot-patch/src/pop3-login/client-authenticate.c
--- dovecot-1.1.7/src/pop3-login/client-authenticate.c  2008-10-29 
11:17:08.000000000 -0500
+++ dovecot-patch/src/pop3-login/client-authenticate.c  2008-12-17 
09:00:32.000000000 -0600
@@ -146,14 +146,8 @@
 
        client_send_line(client, str_c(reply));
 
-       if (!client->destroyed) {
-               /* get back to normal client input. */
-               if (client->io != NULL)
-                       io_remove(&client->io);
-               client->io = io_add(client->common.fd, IO_READ,
-                                   client_input, client);
-               client_input(client);
-       }
+       if (!client->destroyed)
+               client_auth_failed(client);             /* APPLE */
        return TRUE;
 }
 
@@ -190,14 +184,8 @@
                                  data : AUTH_FAILED_MSG, NULL);
                client_send_line(client, msg);
 
-               if (!client->destroyed) {
-                       /* get back to normal client input. */
-                       if (client->io != NULL)
-                               io_remove(&client->io);
-                       client->io = io_add(client->common.fd, IO_READ,
-                                           client_input, client);
-                       client_input(client);
-               }
+               if (!client->destroyed)
+                       client_auth_failed(client);             /* APPLE */
                break;
        case SASL_SERVER_REPLY_MASTER_FAILED:
                if (data == NULL)
diff -ur dovecot-1.1.7/src/pop3-login/client.c 
dovecot-patch/src/pop3-login/client.c
--- dovecot-1.1.7/src/pop3-login/client.c       2008-10-29 11:10:09.000000000 
-0500
+++ dovecot-patch/src/pop3-login/client.c       2008-12-17 08:59:04.000000000 
-0600
@@ -300,6 +300,45 @@
        client_destroy(client, "Disconnected: Inactivity");
 }
 
+/* APPLE */    
+static void client_authfail_delay_timeout(struct pop3_client *client)
+{
+       i_assert(client->to_authfail_delay != NULL);
+       timeout_remove(&client->to_authfail_delay);
+
+       i_assert(client->to_idle_disconnect == NULL);
+       client->to_idle_disconnect =
+               timeout_add(CLIENT_LOGIN_IDLE_TIMEOUT_MSECS,
+                           client_idle_disconnect_timeout, client);
+
+       /* get back to normal client input. */
+       i_assert(client->io == NULL);
+       client->io = io_add(client->common.fd, IO_READ, client_input, client);
+       client_input(client);
+}
+
+/* APPLE - delay after unsuccessful auth to foil attackers */
+void client_auth_failed(struct pop3_client *client)
+{
+       unsigned int delay;
+
+       delay = client->common.auth_attempts;
+       if (delay < 1)
+               delay = 1;
+       delay *= 5 * 1000;
+
+       if (client->io != NULL)
+               io_remove(&client->io);
+
+       i_assert(client->to_idle_disconnect != NULL);
+       timeout_remove(&client->to_idle_disconnect);
+
+       i_assert(client->to_authfail_delay == NULL);
+       client->to_authfail_delay = timeout_add(delay,
+                                               client_authfail_delay_timeout,
+                                               client);
+}
+
 struct client *client_create(int fd, bool ssl, const struct ip_addr *local_ip,
                             const struct ip_addr *ip)
 {
@@ -379,6 +418,10 @@
        if (client->to_idle_disconnect != NULL)
                timeout_remove(&client->to_idle_disconnect);
 
+       /* APPLE */
+       if (client->to_authfail_delay != NULL)
+               timeout_remove(&client->to_authfail_delay);
+
        if (client->common.fd != -1) {
                net_disconnect(client->common.fd);
                client->common.fd = -1;
diff -ur dovecot-1.1.7/src/pop3-login/client.h 
dovecot-patch/src/pop3-login/client.h
--- dovecot-1.1.7/src/pop3-login/client.h       2008-10-26 10:03:45.000000000 
-0500
+++ dovecot-patch/src/pop3-login/client.h       2008-12-17 08:59:09.000000000 
-0600
@@ -16,6 +16,7 @@
        struct istream *input;
        struct ostream *output;
        struct timeout *to_idle_disconnect;
+       struct timeout *to_authfail_delay;              /* APPLE */
 
        struct login_proxy *proxy;
        char *proxy_user, *proxy_password;
@@ -42,6 +43,7 @@
 
 bool client_read(struct pop3_client *client);
 void client_input(struct pop3_client *client);
+void client_auth_failed(struct pop3_client *client);           /* APPLE */
 
 void client_ref(struct pop3_client *client);
 bool client_unref(struct pop3_client *client);



PS -- Please forgive me if I make a mistake at some point while splitting these patches out from our source tree. They're all mingled together on my end and it's sometimes tricky to extract just the right changes for each patch. If anything seems fishy just let me know and I'll take another look. Thanks.

Reply via email to