]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Use the same LDAP connection for both userdb and passdb if config_path is
authorTimo Sirainen <tss@iki.fi>
Tue, 11 Feb 2003 14:06:46 +0000 (16:06 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 11 Feb 2003 14:06:46 +0000 (16:06 +0200)
the same.

--HG--
branch : HEAD

src/auth/db-ldap.c
src/auth/db-ldap.h

index f40f219ad63d7e099a1246469370fc1e6aa0696d..07bbf09ee508cea3db3136ec4a1e461e3fb2a2fb 100644 (file)
@@ -52,6 +52,8 @@ struct ldap_settings default_ldap_settings = {
        MEMBER(user_global_gid) 0
 };
 
+static struct ldap_connection *ldap_connections = NULL;
+
 static int ldap_conn_open(struct ldap_connection *conn);
 
 static int deref2str(const char *str)
@@ -258,11 +260,30 @@ static const char *parse_setting(const char *key, const char *value,
                                       &conn->set, key, value);
 }
 
+static struct ldap_connection *ldap_conn_find(const char *config_path)
+{
+       struct ldap_connection *conn;
+
+       for (conn = ldap_connections; conn != NULL; conn = conn->next) {
+               if (strcmp(conn->config_path, config_path) == 0)
+                       return conn;
+       }
+
+       return NULL;
+}
+
 struct ldap_connection *db_ldap_init(const char *config_path)
 {
        struct ldap_connection *conn;
        pool_t pool;
 
+       /* see if it already exists */
+       conn = ldap_conn_find(config_path);
+       if (conn != NULL) {
+               conn->refcount++;
+               return conn;
+       }
+
        pool = pool_alloconly_create("ldap_connection", 1024);
        conn = p_new(pool, struct ldap_connection, 1);
        conn->pool = pool;
@@ -270,6 +291,7 @@ struct ldap_connection *db_ldap_init(const char *config_path)
        conn->refcount = 1;
        conn->requests = hash_create(default_pool, pool, 0, NULL, NULL);
 
+       conn->config_path = p_strdup(pool, config_path);
        conn->set = default_ldap_settings;
        settings_read(config_path, parse_setting, conn);
 
@@ -280,6 +302,9 @@ struct ldap_connection *db_ldap_init(const char *config_path)
         conn->set.ldap_scope = scope2str(conn->set.scope);
 
        (void)ldap_conn_open(conn);
+
+       conn->next = ldap_connections;
+        ldap_connections = conn;
        return conn;
 }
 
index 75685d87e36376b5498916e1e462e01f1426205b..92c18e0630e1247653bdecada79d41d8f49819ad 100644 (file)
@@ -29,6 +29,8 @@ struct ldap_settings {
 };
 
 struct ldap_connection {
+       struct ldap_connection *next;
+
        pool_t pool;
        int refcount;