diff src/auth/db-ldap.c @ 1143:50f10a7a3bad HEAD

Use the same LDAP connection for both userdb and passdb if config_path is the same.
author Timo Sirainen <tss@iki.fi>
date Tue, 11 Feb 2003 16:06:46 +0200
parents 873634a5b472
children ac7dbb236b59
line wrap: on
line diff
--- a/src/auth/db-ldap.c	Tue Feb 11 15:13:24 2003 +0200
+++ b/src/auth/db-ldap.c	Tue Feb 11 16:06:46 2003 +0200
@@ -52,6 +52,8 @@
 	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 @@
 				       &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 @@
 	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 @@
         conn->set.ldap_scope = scope2str(conn->set.scope);
 
 	(void)ldap_conn_open(conn);
+
+	conn->next = ldap_connections;
+        ldap_connections = conn;
 	return conn;
 }