]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-ldap: Removed caching of ldap-clients
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 2 May 2016 11:35:40 +0000 (14:35 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 2 May 2016 11:35:40 +0000 (14:35 +0300)
With the previous per-username caching there could be a huge number of
dict-ldaps.

src/lib-dict-extra/dict-ldap.c

index bed99ea64d9ce1932cb1129d87c62460b394ec11..9673d92db948429578159af1c84bf36457058f93 100644 (file)
@@ -46,9 +46,6 @@ struct ldap_dict {
        struct ldap_dict *prev,*next;
 };
 
-static
-struct ldap_dict *ldap_dict_list;
-
 static
 void ldap_dict_lookup_async(struct dict *dict, const char *key,
                             dict_lookup_callback_t *callback, void *context);
@@ -199,9 +196,9 @@ ldap_dict_build_query(struct ldap_dict *dict, const struct dict_ldap_map *map,
 }
 
 static
-int ldap_dict_create(struct dict *dict_driver, const char *uri,
-                    const struct dict_settings *set,
-                    struct dict **dict_r, const char **error_r)
+int ldap_dict_init(struct dict *dict_driver, const char *uri,
+                  const struct dict_settings *set,
+                  struct dict **dict_r, const char **error_r)
 {
        pool_t pool = pool_alloconly_create("ldap dict", 2048);
        struct ldap_dict *dict = p_new(pool, struct ldap_dict, 1);
@@ -223,32 +220,16 @@ int ldap_dict_create(struct dict *dict_driver, const char *uri,
 
        *dict_r = (struct dict*)dict;
        *error_r = NULL;
-
-       DLLIST_PREPEND(&ldap_dict_list, dict);
-
        return 0;
 }
 
 static
-int ldap_dict_init(struct dict *dict_driver, const char *uri,
-                  const struct dict_settings *set,
-                  struct dict **dict_r, const char **error_r)
+void ldap_dict_deinit(struct dict *dict)
 {
-       /* reuse possible existing entry */
-       for(struct ldap_dict *ptr = ldap_dict_list;
-           ptr != NULL;
-           ptr = ptr->next) {
-               if (strcmp(ptr->uri, uri) == 0 &&
-                   null_strcmp(ptr->username, set->username) == 0) {
-                       *dict_r = (struct dict*)ptr;
-                       return 0;
-               }
-       }
-       return ldap_dict_create(dict_driver, uri, set, dict_r, error_r);
-}
+       struct ldap_dict *ctx = (struct ldap_dict *)dict;
 
-static
-void ldap_dict_deinit(struct dict *dict ATTR_UNUSED) {
+       ldap_client_deinit(&ctx->client);
+       pool_unref(&ctx->pool);
 }
 
 static
@@ -452,22 +433,11 @@ void dict_ldap_deinit(void);
 void dict_ldap_init(struct module *module ATTR_UNUSED)
 {
        dict_driver_register(&dict_driver_ldap);
-       ldap_dict_list = NULL;
 }
 
 void dict_ldap_deinit(void)
 {
        dict_driver_unregister(&dict_driver_ldap);
-       /* destroy all server connections */
-       struct ldap_dict *ptr = ldap_dict_list;
-       ldap_dict_list = NULL;
-
-       while(ptr != NULL) {
-               ldap_client_deinit(&(ptr->client));
-               pool_t pool = ptr->pool;
-               ptr = ptr->next;
-               pool_unref(&pool);
-       }
 }
 
 const char *dict_ldap_plugin_dependencies[] = { NULL };