From 03f69f8fff3711c925b98f6e17aec4c8321f02b7 Mon Sep 17 00:00:00 2001
From: Jay Soffian <jaysoffian@gmail.com>
Date: Fri, 13 Mar 2009 02:12:43 -0400
Subject: [PATCH] Add auth.backend.ldap.port option
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/http_auth.c |    2 +-
 src/http_auth.h |    1 +
 src/mod_auth.c  |    8 +++++++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/http_auth.c b/src/http_auth.c
index ccd087e..ae1a8da 100644
--- a/src/http_auth.c
+++ b/src/http_auth.c
@@ -786,7 +786,7 @@ static int http_auth_basic_password_compare(server *srv, mod_auth_plugin_data *p
 
 
 		/* 3. */
-		if (NULL == (ldap = ldap_init(p->conf.auth_ldap_hostname->ptr, LDAP_PORT))) {
+		if (NULL == (ldap = ldap_init(p->conf.auth_ldap_hostname->ptr, p->conf.auth_ldap_port))) {
 			log_error_write(srv, __FILE__, __LINE__, "ss", "ldap ...", strerror(errno));
 			return -1;
 		}
diff --git a/src/http_auth.h b/src/http_auth.h
index 5828a7e..16719fc 100644
--- a/src/http_auth.h
+++ b/src/http_auth.h
@@ -35,6 +35,7 @@ typedef struct {
 	buffer *auth_ldap_bindpw;
 	buffer *auth_ldap_filter;
 	buffer *auth_ldap_cafile;
+	unsigned short auth_ldap_port;
 	unsigned short auth_ldap_starttls;
 	unsigned short auth_ldap_allow_empty_pw;
 
diff --git a/src/mod_auth.c b/src/mod_auth.c
index 77d30f2..6886779 100644
--- a/src/mod_auth.c
+++ b/src/mod_auth.c
@@ -107,6 +107,7 @@ static int mod_auth_patch_connection(server *srv, connection *con, mod_auth_plug
 	PATCH(auth_require);
 	PATCH(auth_debug);
 	PATCH(auth_ldap_hostname);
+	PATCH(auth_ldap_port);
 	PATCH(auth_ldap_basedn);
 	PATCH(auth_ldap_binddn);
 	PATCH(auth_ldap_bindpw);
@@ -151,6 +152,8 @@ static int mod_auth_patch_connection(server *srv, connection *con, mod_auth_plug
 #ifdef USE_LDAP
 				p->anon_conf = s;
 #endif
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.port"))) {
+				PATCH(auth_ldap_port);
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.base-dn"))) {
 				PATCH(auth_ldap_basedn);
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.filter"))) {
@@ -346,6 +346,7 @@
 		{ "auth.backend.htpasswd.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
 		{ "auth.backend.program.exec",      NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 14 */
 		{ "auth.debug",                     NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },  /* 15 */
+		{ "auth.backend.ldap.port",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
 		{ NULL,                             NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
 	};
 
@@ -346,6 +350,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
 		s->auth_backend_conf = buffer_init();
 
 		s->auth_ldap_hostname = buffer_init();
+		s->auth_ldap_port = LDAP_PORT;
 		s->auth_ldap_basedn = buffer_init();
 		s->auth_ldap_binddn = buffer_init();
 		s->auth_ldap_bindpw = buffer_init();
@@ -398,6 +399,7 @@
 		cv[13].destination = s->auth_htpasswd_userfile;
 		cv[14].destination = s->auth_program_exec;
 		cv[15].destination = &(s->auth_debug);
+		cv[16].destination = &(s->auth_ldap_port);
 
 		p->config_storage[i] = s;
 		ca = ((data_config *)srv->config_context->data[i])->value;
@@ -557,7 +563,7 @@ handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s) {
 		/* free old context */
 		if (NULL != s->ldap) ldap_unbind_s(s->ldap);
 
-		if (NULL == (s->ldap = ldap_init(s->auth_ldap_hostname->ptr, LDAP_PORT))) {
+		if (NULL == (s->ldap = ldap_init(s->auth_ldap_hostname->ptr, s->auth_ldap_port))) {
 			log_error_write(srv, __FILE__, __LINE__, "ss", "ldap ...", strerror(errno));
 
 			return HANDLER_ERROR;
