web/lib/Zend/Ldap.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * obtain it through the world-wide-web, please send an email
    13  * obtain it through the world-wide-web, please send an email
    14  * to license@zend.com so we can send you a copy immediately.
    14  * to license@zend.com so we can send you a copy immediately.
    15  *
    15  *
    16  * @category   Zend
    16  * @category   Zend
    17  * @package    Zend_Ldap
    17  * @package    Zend_Ldap
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Ldap.php 24593 2012-01-05 20:35:02Z matthew $
    20  * @version    $Id$
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * @category   Zend
    24  * @category   Zend
    25  * @package    Zend_Ldap
    25  * @package    Zend_Ldap
    26  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    26  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    27  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    27  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    28  */
    28  */
    29 class Zend_Ldap
    29 class Zend_Ldap
    30 {
    30 {
    31     const SEARCH_SCOPE_SUB  = 1;
    31     const SEARCH_SCOPE_SUB  = 1;
   811      * @throws Zend_Ldap_Exception
   811      * @throws Zend_Ldap_Exception
   812      */
   812      */
   813     public function bind($username = null, $password = null)
   813     public function bind($username = null, $password = null)
   814     {
   814     {
   815         $moreCreds = true;
   815         $moreCreds = true;
       
   816 
       
   817         // Security check: remove null bytes in password
       
   818         // @see https://net.educause.edu/ir/library/pdf/csd4875.pdf
       
   819         $password = str_replace("\0", '', $password);
   816 
   820 
   817         if ($username === null) {
   821         if ($username === null) {
   818             $username = $this->_getUsername();
   822             $username = $this->_getUsername();
   819             $password = $this->_getPassword();
   823             $password = $this->_getPassword();
   820             $moreCreds = false;
   824             $moreCreds = false;
  1200     /**
  1204     /**
  1201      * Add new information to the LDAP repository
  1205      * Add new information to the LDAP repository
  1202      *
  1206      *
  1203      * @param  string|Zend_Ldap_Dn $dn
  1207      * @param  string|Zend_Ldap_Dn $dn
  1204      * @param  array               $entry
  1208      * @param  array               $entry
  1205      * @return Zend_Ldap                  Provides a fluid interface
  1209      * @return Zend_Ldap                  Provides a fluent interface
  1206      * @throws Zend_Ldap_Exception
  1210      * @throws Zend_Ldap_Exception
  1207      */
  1211      */
  1208     public function add($dn, array $entry)
  1212     public function add($dn, array $entry)
  1209     {
  1213     {
  1210         if (!($dn instanceof Zend_Ldap_Dn)) {
  1214         if (!($dn instanceof Zend_Ldap_Dn)) {
  1248     /**
  1252     /**
  1249      * Update LDAP registry
  1253      * Update LDAP registry
  1250      *
  1254      *
  1251      * @param  string|Zend_Ldap_Dn $dn
  1255      * @param  string|Zend_Ldap_Dn $dn
  1252      * @param  array               $entry
  1256      * @param  array               $entry
  1253      * @return Zend_Ldap                  Provides a fluid interface
  1257      * @return Zend_Ldap                  Provides a fluent interface
  1254      * @throws Zend_Ldap_Exception
  1258      * @throws Zend_Ldap_Exception
  1255      */
  1259      */
  1256     public function update($dn, array $entry)
  1260     public function update($dn, array $entry)
  1257     {
  1261     {
  1258         if (!($dn instanceof Zend_Ldap_Dn)) {
  1262         if (!($dn instanceof Zend_Ldap_Dn)) {
  1295      * Internally decides if entry will be updated to added by calling
  1299      * Internally decides if entry will be updated to added by calling
  1296      * {@link exists()}.
  1300      * {@link exists()}.
  1297      *
  1301      *
  1298      * @param  string|Zend_Ldap_Dn $dn
  1302      * @param  string|Zend_Ldap_Dn $dn
  1299      * @param  array               $entry
  1303      * @param  array               $entry
  1300      * @return Zend_Ldap Provides a fluid interface
  1304      * @return Zend_Ldap Provides a fluent interface
  1301      * @throws Zend_Ldap_Exception
  1305      * @throws Zend_Ldap_Exception
  1302      */
  1306      */
  1303     public function save($dn, array $entry)
  1307     public function save($dn, array $entry)
  1304     {
  1308     {
  1305         if ($dn instanceof Zend_Ldap_Dn) {
  1309         if ($dn instanceof Zend_Ldap_Dn) {
  1313     /**
  1317     /**
  1314      * Delete an LDAP entry
  1318      * Delete an LDAP entry
  1315      *
  1319      *
  1316      * @param  string|Zend_Ldap_Dn $dn
  1320      * @param  string|Zend_Ldap_Dn $dn
  1317      * @param  boolean             $recursively
  1321      * @param  boolean             $recursively
  1318      * @return Zend_Ldap Provides a fluid interface
  1322      * @return Zend_Ldap Provides a fluent interface
  1319      * @throws Zend_Ldap_Exception
  1323      * @throws Zend_Ldap_Exception
  1320      */
  1324      */
  1321     public function delete($dn, $recursively = false)
  1325     public function delete($dn, $recursively = false)
  1322     {
  1326     {
  1323         if ($dn instanceof Zend_Ldap_Dn) {
  1327         if ($dn instanceof Zend_Ldap_Dn) {
  1380      *
  1384      *
  1381      * @param  string|Zend_Ldap_Dn $from
  1385      * @param  string|Zend_Ldap_Dn $from
  1382      * @param  string|Zend_Ldap_Dn $to
  1386      * @param  string|Zend_Ldap_Dn $to
  1383      * @param  boolean             $recursively
  1387      * @param  boolean             $recursively
  1384      * @param  boolean             $alwaysEmulate
  1388      * @param  boolean             $alwaysEmulate
  1385      * @return Zend_Ldap Provides a fluid interface
  1389      * @return Zend_Ldap Provides a fluent interface
  1386      * @throws Zend_Ldap_Exception
  1390      * @throws Zend_Ldap_Exception
  1387      */
  1391      */
  1388     public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate = false)
  1392     public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate = false)
  1389     {
  1393     {
  1390         if ($from instanceof Zend_Ldap_Dn) {
  1394         if ($from instanceof Zend_Ldap_Dn) {
  1411      *
  1415      *
  1412      * @param  string|Zend_Ldap_Dn $from
  1416      * @param  string|Zend_Ldap_Dn $from
  1413      * @param  string|Zend_Ldap_Dn $to
  1417      * @param  string|Zend_Ldap_Dn $to
  1414      * @param  boolean             $recursively
  1418      * @param  boolean             $recursively
  1415      * @param  boolean             $alwaysEmulate
  1419      * @param  boolean             $alwaysEmulate
  1416      * @return Zend_Ldap Provides a fluid interface
  1420      * @return Zend_Ldap Provides a fluent interface
  1417      * @throws Zend_Ldap_Exception
  1421      * @throws Zend_Ldap_Exception
  1418      */
  1422      */
  1419     public function move($from, $to, $recursively = false, $alwaysEmulate = false)
  1423     public function move($from, $to, $recursively = false, $alwaysEmulate = false)
  1420     {
  1424     {
  1421         return $this->rename($from, $to, $recursively, $alwaysEmulate);
  1425         return $this->rename($from, $to, $recursively, $alwaysEmulate);
  1428      *
  1432      *
  1429      * @param  string|Zend_Ldap_Dn $from
  1433      * @param  string|Zend_Ldap_Dn $from
  1430      * @param  string|Zend_Ldap_Dn $to
  1434      * @param  string|Zend_Ldap_Dn $to
  1431      * @param  boolean             $recursively
  1435      * @param  boolean             $recursively
  1432      * @param  boolean             $alwaysEmulate
  1436      * @param  boolean             $alwaysEmulate
  1433      * @return Zend_Ldap Provides a fluid interface
  1437      * @return Zend_Ldap Provides a fluent interface
  1434      * @throws Zend_Ldap_Exception
  1438      * @throws Zend_Ldap_Exception
  1435      */
  1439      */
  1436     public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
  1440     public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
  1437     {
  1441     {
  1438         $emulate = (bool)$alwaysEmulate;
  1442         $emulate = (bool)$alwaysEmulate;
  1473      * Copies a LDAP entry from one DN to another subtree.
  1477      * Copies a LDAP entry from one DN to another subtree.
  1474      *
  1478      *
  1475      * @param  string|Zend_Ldap_Dn $from
  1479      * @param  string|Zend_Ldap_Dn $from
  1476      * @param  string|Zend_Ldap_Dn $to
  1480      * @param  string|Zend_Ldap_Dn $to
  1477      * @param  boolean             $recursively
  1481      * @param  boolean             $recursively
  1478      * @return Zend_Ldap Provides a fluid interface
  1482      * @return Zend_Ldap Provides a fluent interface
  1479      * @throws Zend_Ldap_Exception
  1483      * @throws Zend_Ldap_Exception
  1480      */
  1484      */
  1481     public function copyToSubtree($from, $to, $recursively = false)
  1485     public function copyToSubtree($from, $to, $recursively = false)
  1482     {
  1486     {
  1483         if ($from instanceof Zend_Ldap_Dn) {
  1487         if ($from instanceof Zend_Ldap_Dn) {
  1501      * Copies a LDAP entry from one DN to another DN.
  1505      * Copies a LDAP entry from one DN to another DN.
  1502      *
  1506      *
  1503      * @param  string|Zend_Ldap_Dn $from
  1507      * @param  string|Zend_Ldap_Dn $from
  1504      * @param  string|Zend_Ldap_Dn $to
  1508      * @param  string|Zend_Ldap_Dn $to
  1505      * @param  boolean             $recursively
  1509      * @param  boolean             $recursively
  1506      * @return Zend_Ldap Provides a fluid interface
  1510      * @return Zend_Ldap Provides a fluent interface
  1507      * @throws Zend_Ldap_Exception
  1511      * @throws Zend_Ldap_Exception
  1508      */
  1512      */
  1509     public function copy($from, $to, $recursively = false)
  1513     public function copy($from, $to, $recursively = false)
  1510     {
  1514     {
  1511         $entry = $this->getEntry($from, array(), true);
  1515         $entry = $this->getEntry($from, array(), true);