From a63755c03a86a58d57217ac417429f5c9f00374c Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Thu, 19 Mar 2015 12:47:21 +0800 Subject: [PATCH] Check port when it is being set, and use getPort() throughout. --- lib/adLDAP/adLDAP.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/adLDAP/adLDAP.php b/lib/adLDAP/adLDAP.php index f36c3aa..4f760d1 100644 --- a/lib/adLDAP/adLDAP.php +++ b/lib/adLDAP/adLDAP.php @@ -401,7 +401,10 @@ public function getDomainControllers() { * * @param int $adPort */ - public function setPort($adPort) { + public function setPort($adPort) { + if (!is_numeric($adPort)) { + throw new adLDAPException("[ad_port] must be a number; '$adPort' given"); + } $this->adPort = $adPort; } @@ -621,9 +624,9 @@ public function connect() { // Connect to the AD/LDAP server as the username/password $domainController = $this->randomController(); if ($this->useSSL) { - $this->ldapConnection = ldap_connect("ldaps://" . $domainController, $this->adPort); + $this->ldapConnection = ldap_connect("ldaps://" . $domainController, $this->getPort()); } else { - $this->ldapConnection = ldap_connect("ldap://" . $domainController, $this->adPort); + $this->ldapConnection = ldap_connect("ldap://" . $domainController, $this->getPort()); } // Set some ldap options for talking to AD @@ -971,7 +974,7 @@ protected function randomController() { * @return bool */ protected function pingController($host) { - $port = $this->adPort; + $port = $this->getPort(); fsockopen($host, $port, $errno, $errstr, 10); if ($errno > 0) { return false;