From 3cacf845e5a62f4f9aff6f0cb53e5ef676f4dc35 Mon Sep 17 00:00:00 2001
From: Matt Schwager <matts@duosecurity.com>
Date: Thu, 14 May 2015 10:39:59 -0400
Subject: [PATCH] Allow specifying the LDAP port used from the configuration
 file.

---
 config-templates/authsources.php  |  4 ++++
 modules/ldap/lib/ConfigHelper.php | 14 +++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/config-templates/authsources.php b/config-templates/authsources.php
index e077d2f36..2865d3453 100644
--- a/config-templates/authsources.php
+++ b/config-templates/authsources.php
@@ -276,6 +276,10 @@ $config = array(
         // The default is 0, which means no timeout.
         'timeout' => 0,
 
+        // The port used when accessing the LDAP server.
+        // The default is 389.
+        'port' => 389,
+
         // Set whether to follow referrals. AD Controllers may require FALSE to function.
         'referrals' => TRUE,
 
diff --git a/modules/ldap/lib/ConfigHelper.php b/modules/ldap/lib/ConfigHelper.php
index 8f8f4d539..d5d271b07 100644
--- a/modules/ldap/lib/ConfigHelper.php
+++ b/modules/ldap/lib/ConfigHelper.php
@@ -45,6 +45,13 @@ class sspmod_ldap_ConfigHelper {
 	 */
 	private $timeout;
 
+	/**
+	 * The port used when accessing the LDAP server.
+	 *
+	 * @var int
+	 */
+	private $port;
+
 	/**
 	 * Whether to follow referrals
 	 */
@@ -130,6 +137,7 @@ class sspmod_ldap_ConfigHelper {
 		$this->enableTLS = $config->getBoolean('enable_tls', FALSE);
 		$this->debug = $config->getBoolean('debug', FALSE);
 		$this->timeout = $config->getInteger('timeout', 0);
+		$this->port = $config->getInteger('port', 389);
 		$this->referrals = $config->getBoolean('referrals', TRUE);
 		$this->searchEnable = $config->getBoolean('search.enable', FALSE);
 		$this->privRead = $config->getBoolean('priv.read', FALSE);
@@ -177,7 +185,7 @@ class sspmod_ldap_ConfigHelper {
 			throw new SimpleSAML_Error_Error('WRONGUSERPASS');
 		}
 
-		$ldap = new SimpleSAML_Auth_LDAP($this->hostname, $this->enableTLS, $this->debug, $this->timeout, 389, $this->referrals);
+		$ldap = new SimpleSAML_Auth_LDAP($this->hostname, $this->enableTLS, $this->debug, $this->timeout, $this->port, $this->referrals);
 
 		if (!$this->searchEnable) {
 			$ldapusername = addcslashes($username, ',+"\\<>;*');
@@ -245,7 +253,7 @@ class sspmod_ldap_ConfigHelper {
 			$this->enableTLS,
 			$this->debug,
 			$this->timeout,
-			389,
+			$this->port,
 			$this->referrals);
 
 		if ($attribute == NULL)
@@ -269,7 +277,7 @@ class sspmod_ldap_ConfigHelper {
 			$this->enableTLS,
 			$this->debug,
 			$this->timeout,
-			389,
+			$this->port,
 			$this->referrals);
 
 		/* Are privs needed to get the attributes? */
-- 
GitLab