/**
  * fetch domain config with domain sid and name
  *
  * @throws Tinebase_Exception_Backend_Ldap
  * @throws Zend_Ldap_Exception
  * @return array
  *
  * TODO cache this longer?
  */
 public function getDomainConfiguration()
 {
     if ($this->_domainConfig === null) {
         $this->_domainConfig = $this->getLdap()->search('objectClass=domain', $this->getLdap()->getFirstNamingContext(), Zend_Ldap::SEARCH_SCOPE_BASE)->getFirst();
         $this->_domainConfig['domainSidBinary'] = $this->_domainConfig['objectsid'][0];
         $this->_domainConfig['domainSidPlain'] = Tinebase_Ldap::decodeSid($this->_domainConfig['objectsid'][0]);
         $domainNameParts = array();
         $keys = null;
         // not really needed
         Zend_Ldap_Dn::explodeDn($this->_domainConfig['distinguishedname'][0], $keys, $domanNameParts);
         $this->_domainConfig['domainName'] = implode('.', $domainNameParts);
     }
     return $this->_domainConfig;
 }
 /**
  * returns ldap metadata of given group
  *
  * @param  string $_groupId
  * @return array
  * @throws Tinebase_Exception_NotFound
  * 
  * @todo remove obsolete code
  */
 protected function _getMetaData($_groupId)
 {
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $filter = Zend_Ldap_Filter::equals($this->_groupUUIDAttribute, $this->_encodeGroupId($groupId));
     $result = $this->getLdap()->search($filter, $this->_options['groupsDn'], $this->_groupSearchScope, array('objectclass', 'objectsid'));
     if (count($result) !== 1) {
         throw new Tinebase_Exception_NotFound("Group with id {$_groupId} not found.");
     }
     $group = $result->getFirst();
     return array('dn' => $group['dn'], 'objectclass' => $group['objectclass'], 'objectsid' => Tinebase_Ldap::decodeSid($group['objectsid'][0]));
 }
 /**
  * @see 0011844: decodeSid fails for some encoded SIDs
  *
  * TODO write a test for a decoded sid, like this: ^A^E^@^@^@^@^@^E^U^@^@^@^A.z<F4>^W<B0>Ot^^<DC>^O^V<DE>-^@^@
  *
  * we could dump the encoded sid like this:
  *  $str = pack('c*', $data);
  *  for ($i=0; $i < strlen($str); ++$i) {
  *    echo '\x' . ord($str[$i]);
  *  }
  */
 public function testDecodeAlreadyDecodedSid()
 {
     $sid = "S-1-5-21-2127521184-1604012920-1887927527";
     $decodedSid = Tinebase_Ldap::decodeSid($sid);
     $this->assertEquals($decodedSid, $sid);
 }
 /**
  * convert binary id to plain text id
  * 
  * @param  string  $accountId
  * @return string
  */
 protected function _decodeAccountId($accountId)
 {
     switch ($this->_userUUIDAttribute) {
         case 'objectguid':
             return Tinebase_Ldap::decodeGuid($accountId);
             break;
         case 'objectsid':
             return Tinebase_Ldap::decodeSid($accountId);
             break;
         default:
             return $accountId;
             break;
     }
 }