From 8a94df645b2c01727af1bd2e723742c8bc129a9f Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Wed, 25 Sep 2013 17:49:51 +0100 Subject: [PATCH 1/7] Renamed ResultEntry Renamed ResultEntry to Entry --- src/LDAPi/{ResultEntry.php => Entry.php} | 6 +++--- src/LDAPi/ResultSet.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/LDAPi/{ResultEntry.php => Entry.php} (94%) diff --git a/src/LDAPi/ResultEntry.php b/src/LDAPi/Entry.php similarity index 94% rename from src/LDAPi/ResultEntry.php rename to src/LDAPi/Entry.php index b366b16..23d62e2 100644 --- a/src/LDAPi/ResultEntry.php +++ b/src/LDAPi/Entry.php @@ -2,7 +2,7 @@ namespace LDAPi; -class ResultEntry +class Entry { /** * @var resource ext/ldap link resource @@ -25,7 +25,7 @@ public function __construct($link, $entry) } /** - * @return ResultEntry|null + * @return Entry|null * @throws EntryRetrievalFailureException */ public function nextEntry() @@ -38,7 +38,7 @@ public function nextEntry() return null; } - return new ResultEntry($this->link, $entry); + return new Entry($this->link, $entry); } /** diff --git a/src/LDAPi/ResultSet.php b/src/LDAPi/ResultSet.php index e0b8065..c958357 100644 --- a/src/LDAPi/ResultSet.php +++ b/src/LDAPi/ResultSet.php @@ -57,7 +57,7 @@ public function entryCount() } /** - * @return ResultEntry|null + * @return Entry|null * @throws EntryRetrievalFailureException */ public function firstEntry() @@ -70,7 +70,7 @@ public function firstEntry() return null; } - return new ResultEntry($this->link, $entry); + return new Entry($this->link, $entry); } /** From 0025f0daf64eff96178856576a366d9e75a51e35 Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Wed, 25 Sep 2013 17:53:19 +0100 Subject: [PATCH 2/7] Cast attribute lists to arrays Cast attribute lists to arrays in read operations --- src/LDAPi/Directory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LDAPi/Directory.php b/src/LDAPi/Directory.php index 41d6703..587a498 100644 --- a/src/LDAPi/Directory.php +++ b/src/LDAPi/Directory.php @@ -171,7 +171,7 @@ public function listChildren($dn, $filter, array $attributes = null, $attrsOnly { $this->checkBound(); - if (!$result = @ldap_list($this->link, $dn, $filter, $attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + if (!$result = @ldap_list($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -254,7 +254,7 @@ public function read($dn, $filter, array $attributes = null, $attrsOnly = false, { $this->checkBound(); - if (!$result = @ldap_read($this->link, $dn, $filter, $attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + if (!$result = @ldap_read($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -316,7 +316,7 @@ public function search($dn, $filter, array $attributes = null, $attrsOnly = fals { $this->checkBound(); - if (!$result = @ldap_search($this->link, $dn, $filter, $attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + if (!$result = @ldap_search($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } From 344237a57df491fa713b987bd6429275941e105d Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Wed, 25 Sep 2013 18:03:30 +0100 Subject: [PATCH 3/7] Moved global functions to separate file Moved global function definitions to separate file and added composer entry --- composer.json | 5 +- src/LDAPi/Directory.php | 703 ++++++++++++++++++--------------------- src/global_functions.php | 49 +++ 3 files changed, 382 insertions(+), 375 deletions(-) create mode 100644 src/global_functions.php diff --git a/composer.json b/composer.json index e8770fb..c515028 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "autoload": { "psr-0": { "LDAPi\\": "src/" - } + }, + "files": [ + "src/global_functions.php" + ] } } diff --git a/src/LDAPi/Directory.php b/src/LDAPi/Directory.php index 587a498..db12651 100644 --- a/src/LDAPi/Directory.php +++ b/src/LDAPi/Directory.php @@ -1,429 +1,384 @@ link) { - throw new UnavailableException('An active connection to the directory is not available'); - } + if (!$this->link) { + throw new UnavailableException('An active connection to the directory is not available'); } + } - private function checkBound() - { - if (!$this->bound) { - throw new UnavailableException('An active bound connection to the directory is not available'); - } + private function checkBound() + { + if (!$this->bound) { + throw new UnavailableException('An active bound connection to the directory is not available'); } + } - private function createResultSet($result) - { - return new ResultSet($this->link, $result); - } + private function createResultSet($result) + { + return new ResultSet($this->link, $result); + } - public function __destruct() - { - if ($this->bound) { - $this->unbind(); - } + public function __destruct() + { + if ($this->bound) { + $this->unbind(); } + } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function add($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_add($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - } + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function add($dn, array $entry) + { + $this->checkBound(); - /** - * @param string $dn - * @param string $password - * @throws UnavailableException - * @throws BindFailureException - */ - public function bind($dn = null, $password = null) - { - $this->checkConnected(); - - if (!@ldap_bind($this->link, $dn, $password)) { - throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - $this->bound = true; + if (!@ldap_add($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param string $attribute - * @param mixed $value - * @return bool - * @throws UnavailableException - * @throws ReadFailureException - */ - public function compare($dn, $attribute, $value) - { - $this->checkBound(); - - if (-1 === $result = @ldap_compare($this->link, $dn, $entry)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $result; - } + /** + * @param string $dn + * @param string $password + * @throws UnavailableException + * @throws BindFailureException + */ + public function bind($dn = null, $password = null) + { + $this->checkConnected(); - /** - * @param string $host - * @param int $port - * @throws AlreadyAvailableException - * @throws ConnectFailureException - */ - public function connect($host, $port = 389) - { - if ($this->link) { - throw new AlreadyAvailableException('An active connection to the directory is already available'); - } - - if (!$this->link = @ldap_connect($host, $port)) { - throw new ConnectFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + if (!@ldap_bind($this->link, $dn, $password)) { + throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param int $pageSize - * @param bool $isCritical - * @param string $cookie - * @throws UnavailableException - * @throws PaginationFailureException - */ - public function controlPagedResult($pageSize, $isCritical = false, $cookie = '') - { - $this->checkBound(); - - if (!@ldap_control_paged_result($this->link, $pageSize, $isCritical, $cookie)) { - throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + $this->bound = true; + } + + /** + * @param string $dn + * @param string $attribute + * @param mixed $value + * @return bool + * @throws UnavailableException + * @throws ReadFailureException + */ + public function compare($dn, $attribute, $value) + { + $this->checkBound(); + + if (-1 === $result = @ldap_compare($this->link, $dn, $entry)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param string $dn - * @throws UnavailableException - * @throws WriteFailureException - */ - public function delete($dn) - { - $this->checkBound(); - - if (!@ldap_delete($this->link, $dn)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $result; + } + + /** + * @param string $host + * @param int $port + * @throws AlreadyAvailableException + * @throws ConnectFailureException + */ + public function connect($host, $port = 389) + { + if ($this->link) { + throw new AlreadyAvailableException('An active connection to the directory is already available'); } - /** - * @param int $opt - * @return mixed - * @throws UnavailableException - * @throws OptionFailureException - */ - public function getOption($opt) - { - $this->checkConnected(); - - if (!@ldap_get_option($this->link, $opt, $value)) { - throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $value; + if (!$this->link = @ldap_connect($host, $port)) { + throw new ConnectFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } + + /** + * @param int $pageSize + * @param bool $isCritical + * @param string $cookie + * @throws UnavailableException + * @throws PaginationFailureException + */ + public function controlPagedResult($pageSize, $isCritical = false, $cookie = '') + { + $this->checkBound(); - /** - * @param string $dn - * @param string $filter - * @param array $attributes - * @param bool $attrsOnly - * @param int $sizeLimit - * @param int $timeLimit - * @param int $deRef - * @return ResultSet - * @throws UnavailableException - * @throws ReadFailureException - */ - public function listChildren($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) - { - $this->checkBound(); - - if (!$result = @ldap_list($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $this->createResultSet($result); + if (!@ldap_control_paged_result($this->link, $pageSize, $isCritical, $cookie)) { + throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modAdd($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_mod_add($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + /** + * @param string $dn + * @throws UnavailableException + * @throws WriteFailureException + */ + public function delete($dn) + { + $this->checkBound(); + + if (!@ldap_delete($this->link, $dn)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modDel($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_mod_del($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + /** + * @param int $opt + * @return mixed + * @throws UnavailableException + * @throws OptionFailureException + */ + public function getOption($opt) + { + $this->checkConnected(); + + if (!@ldap_get_option($this->link, $opt, $value)) { + throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modReplace($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_mod_replace($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $value; + } + + /** + * @param string $dn + * @param string $filter + * @param array $attributes + * @param bool $attrsOnly + * @param int $sizeLimit + * @param int $timeLimit + * @param int $deRef + * @return ResultSet + * @throws UnavailableException + * @throws ReadFailureException + */ + public function listChildren($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) + { + $this->checkBound(); + + if (!$result = @ldap_list($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modify($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_modify($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $this->createResultSet($result); + } + + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modAdd($dn, array $entry) + { + $this->checkBound(); + + if (!@ldap_mod_add($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } + + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modDel($dn, array $entry) + { + $this->checkBound(); - /** - * @param string $dn - * @param string $filter - * @param array $attributes - * @param bool $attrsOnly - * @param int $sizeLimit - * @param int $timeLimit - * @param int $deRef - * @return ResultSet - * @throws UnavailableException - * @throws ReadFailureException - */ - public function read($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) - { - $this->checkBound(); - - if (!$result = @ldap_read($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $this->createResultSet($result); + if (!@ldap_mod_del($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } + + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modReplace($dn, array $entry) + { + $this->checkBound(); - /** - * @param string $dn - * @param string $newRDN - * @param string $newParent - * @param bool $deleteOldRDN - * @throws UnavailableException - * @throws WriteFailureException - */ - public function rename($dn, $newRDN, $newParent, $deleteOldRDN = true) - { - $this->checkBound(); - - if (!@ldap_rename($this->link, $dn, $newRDN, $newParent, $deleteOldRDN)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + if (!@ldap_mod_replace($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param string $password - * @param string $saslMech - * @param string $saslRealm - * @param string $saslAuthcId - * @param string $saslAuthzId - * @param string $props - * @throws UnavailableException - * @throws BindFailureException - */ - public function saslBind($dn = null, $password = null, $saslMech = null, $saslRealm = null, $saslAuthcId = null, $saslAuthzId = null, $props = null) - { - $this->checkConnected(); - - if (!@ldap_sasl_bind($this->link, $dn, $password, $saslMech, $saslRealm, $saslAuthcId, $saslAuthzId, $props)) { - throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - $this->bound = true; + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modify($dn, array $entry) + { + $this->checkBound(); + + if (!@ldap_modify($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param string $filter - * @param array $attributes - * @param bool $attrsOnly - * @param int $sizeLimit - * @param int $timeLimit - * @param int $deRef - * @return ResultSet - * @throws UnavailableException - * @throws ReadFailureException - */ - public function search($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) - { - $this->checkBound(); - - if (!$result = @ldap_search($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $this->createResultSet($result); + /** + * @param string $dn + * @param string $filter + * @param array $attributes + * @param bool $attrsOnly + * @param int $sizeLimit + * @param int $timeLimit + * @param int $deRef + * @return ResultSet + * @throws UnavailableException + * @throws ReadFailureException + */ + public function read($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) + { + $this->checkBound(); + + if (!$result = @ldap_read($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param int $opt - * @param mixed $value - * @throws UnavailableException - * @throws OptionFailureException - */ - public function setOption($opt, $value) - { - $this->checkConnected(); - - if (!@ldap_set_option($this->link, $opt, $value)) { - throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $this->createResultSet($result); + } + + /** + * @param string $dn + * @param string $newRDN + * @param string $newParent + * @param bool $deleteOldRDN + * @throws UnavailableException + * @throws WriteFailureException + */ + public function rename($dn, $newRDN, $newParent, $deleteOldRDN = true) + { + $this->checkBound(); + + if (!@ldap_rename($this->link, $dn, $newRDN, $newParent, $deleteOldRDN)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param callable $callback - * @throws UnavailableException - * @throws OptionFailureException - */ - public function setRebindProc(callable $callback) - { - $this->checkConnected(); - - if (!@ldap_set_rebind_proc($this->link, $callback)) { - throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + /** + * @param string $dn + * @param string $password + * @param string $saslMech + * @param string $saslRealm + * @param string $saslAuthcId + * @param string $saslAuthzId + * @param string $props + * @throws UnavailableException + * @throws BindFailureException + */ + public function saslBind($dn = null, $password = null, $saslMech = null, $saslRealm = null, $saslAuthcId = null, $saslAuthzId = null, $props = null) + { + $this->checkConnected(); + + if (!@ldap_sasl_bind($this->link, $dn, $password, $saslMech, $saslRealm, $saslAuthcId, $saslAuthzId, $props)) { + throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @throws UnavailableException - * @throws AlreadyAvailableException - * @throws EncryptionFailureException - */ - public function startTLS() - { - $this->checkConnected(); - if ($this->bound) { - throw new AlreadyAvailableException('An active bound connection to the directory is already available'); - } - - if (!@ldap_start_tls($this->link)) { - throw new EncryptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + $this->bound = true; + } + + /** + * @param string $dn + * @param string $filter + * @param array $attributes + * @param bool $attrsOnly + * @param int $sizeLimit + * @param int $timeLimit + * @param int $deRef + * @return ResultSet + * @throws UnavailableException + * @throws ReadFailureException + */ + public function search($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) + { + $this->checkBound(); + + if (!$result = @ldap_search($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @throws UnavailableException - */ - public function unbind() - { - $this->checkBound(); + return $this->createResultSet($result); + } - @ldap_unbind($this->link); + /** + * @param int $opt + * @param mixed $value + * @throws UnavailableException + * @throws OptionFailureException + */ + public function setOption($opt, $value) + { + $this->checkConnected(); - $this->link = null; - $this->bound = false; + if (!@ldap_set_option($this->link, $opt, $value)) { + throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } -} -namespace -{ - if (!function_exists('ldap_escape')) { - define('LDAP_ESCAPE_FILTER', 0x01); - define('LDAP_ESCAPE_DN', 0x02); - - /** - * @param string $subject - * @param string $ignore - * @param int $flags - * @return string - */ - function ldap_escape($subject, $ignore = '', $flags = 0) - { - $subject = (string) $subject; - if ($subject === '') { - return ''; - } - - $charList = array_fill(0, 256, false); - $haveCharList = false; - - if ($flags & LDAP_ESCAPE_FILTER) { - $charList = array_fill(0, 256, false); - $haveCharList = true; - - foreach (["\\", "*", "(", ")", "\x00"] as $char) { - $charList[ord($char)] = true; - } - } - - if ($flags & LDAP_ESCAPE_DN) { - if (!$haveCharList) { - $charList = array_fill(0, 256, false); - } - - foreach (["\\", ",", "=", "+", "<", ">", ";", "\"", "#"] as $char) { - $charList[ord($char)] = true; - } - } + /** + * @param callable $callback + * @throws UnavailableException + * @throws OptionFailureException + */ + public function setRebindProc(callable $callback) + { + $this->checkConnected(); + + if (!@ldap_set_rebind_proc($this->link, $callback)) { + throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); + } + } + + /** + * @throws UnavailableException + * @throws AlreadyAvailableException + * @throws EncryptionFailureException + */ + public function startTLS() + { + $this->checkConnected(); + if ($this->bound) { + throw new AlreadyAvailableException('An active bound connection to the directory is already available'); + } + + if (!@ldap_start_tls($this->link)) { + throw new EncryptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } + + /** + * @throws UnavailableException + */ + public function unbind() + { + $this->checkBound(); + + @ldap_unbind($this->link); + + $this->link = null; + $this->bound = false; + } } diff --git a/src/global_functions.php b/src/global_functions.php new file mode 100644 index 0000000..6cfdcd0 --- /dev/null +++ b/src/global_functions.php @@ -0,0 +1,49 @@ +", ";", "\"", "#"]); + } + if (!$charList) { + for ($i = 0; $i < 256; $i++) { + $charList[] = chr($i); + } + } + $charList = array_flip($charList); + + for ($i = 0; isset($ignore[$i]); $i++) { + unset($charList[$ignore[$i]]); + } + + foreach ($charList as $key => &$value) { + $value = sprintf('\%02x', ord($key)); + } + + return strtr($subject, $charList); + } +} From 7652b01666c084bf55ec0585801ffda334fc0ef4 Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Wed, 25 Sep 2013 18:29:50 +0100 Subject: [PATCH 4/7] Add license --- license | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 license diff --git a/license b/license new file mode 100644 index 0000000..360bbe1 --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 Chris Wright + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From 21e9d40cce46148596233e9c1168c2f74e56830a Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Wed, 25 Sep 2013 18:34:29 +0100 Subject: [PATCH 5/7] Added PHP version constraint Added composer requirement for PHP>=5.4.0 and ext/ldap --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index c515028..ea9f2b6 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,10 @@ "role": "Developer" } ], + "require": { + "php": ">=5.4.0", + "ext-ldap": "*" + }, "autoload": { "psr-0": { "LDAPi\\": "src/" From d9a953e007e2076d4acfdee97d6bf63fa0bb008e Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Thu, 26 Sep 2013 11:30:29 +0100 Subject: [PATCH 6/7] Renamed ResultReference Renamed ResultReference to Reference --- src/LDAPi/{ResultReference.php => Reference.php} | 8 ++++---- src/LDAPi/ResultSet.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/LDAPi/{ResultReference.php => Reference.php} (89%) diff --git a/src/LDAPi/ResultReference.php b/src/LDAPi/Reference.php similarity index 89% rename from src/LDAPi/ResultReference.php rename to src/LDAPi/Reference.php index 67edf20..8daeed7 100644 --- a/src/LDAPi/ResultReference.php +++ b/src/LDAPi/Reference.php @@ -2,7 +2,7 @@ namespace LDAPi; -class ResultReference +class Reference { /** * @var resource ext/ldap link resource @@ -26,7 +26,7 @@ public function __construct($link, $reference) } /** - * @return ResultReference|null + * @return Reference|null * @throws ReferenceRetrievalFailureException */ public function nextReference() @@ -39,11 +39,11 @@ public function nextReference() return null; } - return new ResultReference($this->link, $reference); + return new Reference($this->link, $reference); } /** - * @return array + * @return string[] * @throws ValueRetrievalFailureException */ public function parse() diff --git a/src/LDAPi/ResultSet.php b/src/LDAPi/ResultSet.php index c958357..b663d41 100644 --- a/src/LDAPi/ResultSet.php +++ b/src/LDAPi/ResultSet.php @@ -74,7 +74,7 @@ public function firstEntry() } /** - * @return ResultReference|null + * @return Reference|null * @throws ReferenceRetrievalFailureException */ public function firstReference() @@ -87,7 +87,7 @@ public function firstReference() return null; } - return new ResultReference($this->link, $reference); + return new Reference($this->link, $reference); } /** From 0be571bbe3c132c65c7e79d406a5f4f0a433a0e4 Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Thu, 26 Sep 2013 17:11:19 +0100 Subject: [PATCH 7/7] Remove error suppression Don't suppress errors emitted by ext/ldap functions --- src/LDAPi/Directory.php | 40 ++++++++++++++++++++-------------------- src/LDAPi/Entry.php | 8 ++++---- src/LDAPi/Reference.php | 4 ++-- src/LDAPi/ResultSet.php | 14 +++++++------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/LDAPi/Directory.php b/src/LDAPi/Directory.php index db12651..5cc8f07 100644 --- a/src/LDAPi/Directory.php +++ b/src/LDAPi/Directory.php @@ -50,7 +50,7 @@ public function add($dn, array $entry) { $this->checkBound(); - if (!@ldap_add($this->link, $dn, $entry)) { + if (!ldap_add($this->link, $dn, $entry)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -65,7 +65,7 @@ public function bind($dn = null, $password = null) { $this->checkConnected(); - if (!@ldap_bind($this->link, $dn, $password)) { + if (!ldap_bind($this->link, $dn, $password)) { throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -84,7 +84,7 @@ public function compare($dn, $attribute, $value) { $this->checkBound(); - if (-1 === $result = @ldap_compare($this->link, $dn, $entry)) { + if (-1 === $result = ldap_compare($this->link, $dn, $entry)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -103,7 +103,7 @@ public function connect($host, $port = 389) throw new AlreadyAvailableException('An active connection to the directory is already available'); } - if (!$this->link = @ldap_connect($host, $port)) { + if (!$this->link = ldap_connect($host, $port)) { throw new ConnectFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -119,7 +119,7 @@ public function controlPagedResult($pageSize, $isCritical = false, $cookie = '') { $this->checkBound(); - if (!@ldap_control_paged_result($this->link, $pageSize, $isCritical, $cookie)) { + if (!ldap_control_paged_result($this->link, $pageSize, $isCritical, $cookie)) { throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -133,7 +133,7 @@ public function delete($dn) { $this->checkBound(); - if (!@ldap_delete($this->link, $dn)) { + if (!ldap_delete($this->link, $dn)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -148,7 +148,7 @@ public function getOption($opt) { $this->checkConnected(); - if (!@ldap_get_option($this->link, $opt, $value)) { + if (!ldap_get_option($this->link, $opt, $value)) { throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -171,7 +171,7 @@ public function listChildren($dn, $filter, array $attributes = null, $attrsOnly { $this->checkBound(); - if (!$result = @ldap_list($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + if (!$result = ldap_list($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -188,7 +188,7 @@ public function modAdd($dn, array $entry) { $this->checkBound(); - if (!@ldap_mod_add($this->link, $dn, $entry)) { + if (!ldap_mod_add($this->link, $dn, $entry)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -203,7 +203,7 @@ public function modDel($dn, array $entry) { $this->checkBound(); - if (!@ldap_mod_del($this->link, $dn, $entry)) { + if (!ldap_mod_del($this->link, $dn, $entry)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -218,7 +218,7 @@ public function modReplace($dn, array $entry) { $this->checkBound(); - if (!@ldap_mod_replace($this->link, $dn, $entry)) { + if (!ldap_mod_replace($this->link, $dn, $entry)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -233,7 +233,7 @@ public function modify($dn, array $entry) { $this->checkBound(); - if (!@ldap_modify($this->link, $dn, $entry)) { + if (!ldap_modify($this->link, $dn, $entry)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -254,7 +254,7 @@ public function read($dn, $filter, array $attributes = null, $attrsOnly = false, { $this->checkBound(); - if (!$result = @ldap_read($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + if (!$result = ldap_read($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -273,7 +273,7 @@ public function rename($dn, $newRDN, $newParent, $deleteOldRDN = true) { $this->checkBound(); - if (!@ldap_rename($this->link, $dn, $newRDN, $newParent, $deleteOldRDN)) { + if (!ldap_rename($this->link, $dn, $newRDN, $newParent, $deleteOldRDN)) { throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -293,7 +293,7 @@ public function saslBind($dn = null, $password = null, $saslMech = null, $saslRe { $this->checkConnected(); - if (!@ldap_sasl_bind($this->link, $dn, $password, $saslMech, $saslRealm, $saslAuthcId, $saslAuthzId, $props)) { + if (!ldap_sasl_bind($this->link, $dn, $password, $saslMech, $saslRealm, $saslAuthcId, $saslAuthzId, $props)) { throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -316,7 +316,7 @@ public function search($dn, $filter, array $attributes = null, $attrsOnly = fals { $this->checkBound(); - if (!$result = @ldap_search($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + if (!$result = ldap_search($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -333,7 +333,7 @@ public function setOption($opt, $value) { $this->checkConnected(); - if (!@ldap_set_option($this->link, $opt, $value)) { + if (!ldap_set_option($this->link, $opt, $value)) { throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -347,7 +347,7 @@ public function setRebindProc(callable $callback) { $this->checkConnected(); - if (!@ldap_set_rebind_proc($this->link, $callback)) { + if (!ldap_set_rebind_proc($this->link, $callback)) { throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -364,7 +364,7 @@ public function startTLS() throw new AlreadyAvailableException('An active bound connection to the directory is already available'); } - if (!@ldap_start_tls($this->link)) { + if (!ldap_start_tls($this->link)) { throw new EncryptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } @@ -376,7 +376,7 @@ public function unbind() { $this->checkBound(); - @ldap_unbind($this->link); + ldap_unbind($this->link); $this->link = null; $this->bound = false; diff --git a/src/LDAPi/Entry.php b/src/LDAPi/Entry.php index 23d62e2..89336bd 100644 --- a/src/LDAPi/Entry.php +++ b/src/LDAPi/Entry.php @@ -30,7 +30,7 @@ public function __construct($link, $entry) */ public function nextEntry() { - if (!$entry = @ldap_next_entry($this->link, $this->entry)) { + if (!$entry = ldap_next_entry($this->link, $this->entry)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new EntryRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -47,7 +47,7 @@ public function nextEntry() */ public function getValues($attribute) { - if (!$values = @ldap_get_values($this->link, $this->entry, $attribute)) { + if (!$values = ldap_get_values($this->link, $this->entry, $attribute)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -60,7 +60,7 @@ public function getValues($attribute) */ public function getAttributes() { - if (!$attributes = @ldap_get_attributes($this->link, $this->entry)) { + if (!$attributes = ldap_get_attributes($this->link, $this->entry)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -73,7 +73,7 @@ public function getAttributes() */ public function getDN() { - if (!$dn = @ldap_get_dn($this->link, $this->entry)) { + if (!$dn = ldap_get_dn($this->link, $this->entry)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } diff --git a/src/LDAPi/Reference.php b/src/LDAPi/Reference.php index 8daeed7..ee675d1 100644 --- a/src/LDAPi/Reference.php +++ b/src/LDAPi/Reference.php @@ -31,7 +31,7 @@ public function __construct($link, $reference) */ public function nextReference() { - if (!$reference = @ldap_next_reference($this->link, $this->reference)) { + if (!$reference = ldap_next_reference($this->link, $this->reference)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new ReferenceRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -48,7 +48,7 @@ public function nextReference() */ public function parse() { - if (!@ldap_parse_reference($this->link, $this->reference, $referrals)) { + if (!ldap_parse_reference($this->link, $this->reference, $referrals)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } diff --git a/src/LDAPi/ResultSet.php b/src/LDAPi/ResultSet.php index b663d41..0be1f23 100644 --- a/src/LDAPi/ResultSet.php +++ b/src/LDAPi/ResultSet.php @@ -26,7 +26,7 @@ public function __construct($link, $result) public function __destruct() { - @ldap_free_result($this->result); + ldap_free_result($this->result); } /** @@ -36,7 +36,7 @@ public function __destruct() */ public function controlPagedResult(&$estimated = null) { - if (!@ldap_control_paged_result_response($this->link, $this->result, $cookie, $estimated)) { + if (!ldap_control_paged_result_response($this->link, $this->result, $cookie, $estimated)) { throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -49,7 +49,7 @@ public function controlPagedResult(&$estimated = null) */ public function entryCount() { - if (!$result = @ldap_count_entries($this->link, $this->result)) { + if (!$result = ldap_count_entries($this->link, $this->result)) { throw new EntryCountRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -62,7 +62,7 @@ public function entryCount() */ public function firstEntry() { - if (!$entry = @ldap_first_entry($this->link, $this->result)) { + if (!$entry = ldap_first_entry($this->link, $this->result)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new EntryRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -79,7 +79,7 @@ public function firstEntry() */ public function firstReference() { - if (!$reference = @ldap_first_reference($this->link, $this->result)) { + if (!$reference = ldap_first_reference($this->link, $this->result)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new ReferenceRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -96,7 +96,7 @@ public function firstReference() */ public function parse() { - if (!@ldap_parse_result($this->link, $this->result, $errCode, $matchedDN, $errMsg, $referrals)) { + if (!ldap_parse_result($this->link, $this->result, $errCode, $matchedDN, $errMsg, $referrals)) { throw new InformationRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -114,7 +114,7 @@ public function parse() */ public function getEntries() { - if (!$entries = @ldap_get_entries($this->link, $this->result)) { + if (!$entries = ldap_get_entries($this->link, $this->result)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); }