Esempio n. 1
0
File: Dn.php Progetto: raZ3l/zf2
 /**
  * Checks if given $childDn is beneath $parentDn subtree.
  *
  * @param  string|Dn $childDn
  * @param  string|Dn $parentDn
  * @return boolean
  */
 public static function isChildOf($childDn, $parentDn)
 {
     try {
         $keys = array();
         $vals = array();
         if ($childDn instanceof Dn) {
             $cdn = $childDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $cdn = self::explodeDn($childDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
         if ($parentDn instanceof Dn) {
             $pdn = $parentDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $pdn = self::explodeDn($parentDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
     } catch (Exception\LdapException $e) {
         return false;
     }
     $startIndex = count($cdn) - count($pdn);
     if ($startIndex < 0) {
         return false;
     }
     for ($i = 0; $i < count($pdn); $i++) {
         if ($cdn[$i + $startIndex] != $pdn[$i]) {
             return false;
         }
     }
     return true;
 }
Esempio n. 2
0
File: Node.php Progetto: narixx/zf2
 /**
  * Sets the new DN for this node
  *
  * This is an offline method.
  *
  * @param  \Zend\Ldap\Dn|string|array $newDn
  * @throws \Zend\Ldap\Exception
  * @return \Zend\Ldap\Node Provides a fluid interface
  */
 public function setDn($newDn)
 {
     if ($newDn instanceof Dn) {
         $this->_newDn = clone $newDn;
     } else {
         $this->_newDn = Dn::factory($newDn);
     }
     $this->_ensureRdnAttributeValues();
     return $this;
 }
Esempio n. 3
0
File: Ldap.php Progetto: rexmac/zf2
 /**
  * Update LDAP registry
  *
  * @param  string|\Zend\Ldap\Dn $dn
  * @param  array               $entry
  * @return \Zend\Ldap\Ldap                  Provides a fluid interface
  * @throws \Zend\Ldap\Exception
  */
 public function update($dn, array $entry)
 {
     if (!$dn instanceof DN) {
         $dn = DN::factory($dn, null);
     }
     self::prepareLdapEntryArray($entry);
     $rdnParts = $dn->getRdn(DN::ATTR_CASEFOLD_LOWER);
     foreach ($rdnParts as $key => $value) {
         $value = Dn::unescapeValue($value);
         if (array_key_exists($key, $entry) && !in_array($value, $entry[$key])) {
             $entry[$key] = array_merge(array($value), $entry[$key]);
         }
     }
     $adAttributes = array('distinguishedname', 'instancetype', 'name', 'objectcategory', 'objectguid', 'usnchanged', 'usncreated', 'whenchanged', 'whencreated');
     foreach ($adAttributes as $attr) {
         if (array_key_exists($attr, $entry)) {
             unset($entry[$attr]);
         }
     }
     if (count($entry) > 0) {
         $isModified = @ldap_modify($this->getResource(), $dn->toString(), $entry);
         if ($isModified === false) {
             throw new Exception($this, 'updating: ' . $dn->toString());
         }
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * Copies a LDAP entry from one DN to another DN.
  *
  * @param  string|\Zend\Ldap\Dn $from
  * @param  string|\Zend\Ldap\Dn $to
  * @param  boolean             $recursively
  * @return \Zend\Ldap\Ldap Provides a fluid interface
  * @throws \Zend\Ldap\Exception
  */
 public function copy($from, $to, $recursively = false)
 {
     $entry = $this->getEntry($from, array(), true);
     if ($to instanceof Dn) {
         $toDnParts = $to->toArray();
     } else {
         $toDnParts = Dn::explodeDn($to);
     }
     $this->add($to, $entry);
     if ($recursively === true && $this->countChildren($from) > 0) {
         $children = $this->_getChildrenDns($from);
         foreach ($children as $c) {
             $cDnParts = Dn::explodeDn($c);
             $newChildParts = array_merge(array(array_shift($cDnParts)), $toDnParts);
             $newChild = Dn::implodeDn($newChildParts);
             $this->copy($c, $newChild, true);
         }
     }
     return $this;
 }