本文整理汇总了PHP中ldap_explode_dn函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_explode_dn函数的具体用法?PHP ldap_explode_dn怎么用?PHP ldap_explode_dn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_explode_dn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateUsingLdapExt
protected function validateUsingLdapExt($value)
{
if (!ldap_explode_dn($value, 0)) {
return false;
}
return true;
}
示例2: getParentDN
/**
* @return string
*/
public function getParentDN()
{
$parts = ldap_explode_dn($this->distinguisedName, 0);
unset($parts['count']);
unset($parts[0]);
return implode(',', $parts);
}
示例3: createOrganizationalUnit
/**
* @param string $dn
* @param bool $createParent
*
* @return bool
*/
public function createOrganizationalUnit($dn, $createParent = false)
{
$parts = ldap_explode_dn($dn, 0);
unset($parts['count']);
// Doesn't support anything else than 'ou'
if (stripos($parts[0], 'ou=') !== 0) {
return false;
}
// Previously create parents
if ($createParent) {
$parentParts = $parts;
unset($parentParts[0]);
$parent = implode(',', $parentParts);
$found = $this->searchDN($parent);
if (!$found) {
$this->createOrganizationalUnit($parent, true);
}
}
// Already exists ?
$found = $this->searchDN($dn);
if (!$found) {
list(, $name) = explode('=', $parts[0]);
$object = new Object($dn);
$object->get('objectClass')->add('top');
$object->get('objectClass')->add('organizationalUnit');
$object->get('ou')->add($name);
return $this->add($object, false);
}
return true;
}
示例4: explodeDN
/**
* Extends PHPs ldap_explode_dn() function
*
* UTF-8 chars like German umlauts would otherwise be escaped and shown
* as backslash-prefixed hexcode-sequenzes.
*
* @param string DN
* @param boolean Returns 'type=value' when true and 'value' when false
* @return string
*/
public static function explodeDN($dn, $with_type = true)
{
$res = ldap_explode_dn($dn, $with_type ? 0 : 1);
foreach ($res as $k => $v) {
$res[$k] = preg_replace('/\\\\([0-9a-f]{2})/ei', "chr(hexdec('\\1'))", $v);
}
unset($res['count']);
return $res;
}
示例5: explodeDn
/**
* Converts a string distinguished name into its separate pieces.
*
* @param string $dn
* @param int $withAttributes Set to 0 to get the attribute names along with the value.
* @return array
*/
public static function explodeDn($dn, $withAttributes = 1)
{
$pieces = ldap_explode_dn($dn, $withAttributes);
if ($pieces === false || !isset($pieces['count']) || $pieces['count'] == 0) {
throw new \yii\base\InvalidParamException(sprintf('Unable to parse DN "%s".', $dn));
}
unset($pieces['count']);
return $pieces;
}
示例6: explodeDn
/**
* Converts a DN string into an array of RDNs.
*
* This will also decode hex characters into their true
* UTF-8 representation embedded inside the DN as well.
*
* @param string $dn
* @param bool $removeAttributePrefixes
*
* @return array|false
*/
public static function explodeDn($dn, $removeAttributePrefixes = true)
{
$dn = ldap_explode_dn($dn, $removeAttributePrefixes ? 1 : 0);
if (is_array($dn) && array_key_exists('count', $dn)) {
foreach ($dn as $rdn => $value) {
$dn[$rdn] = self::unescape($value);
}
}
return $dn;
}
示例7: explode_dn
function explode_dn($dn, $with_attributes = 0)
{
$result = ldap_explode_dn($dn, $with_attributes);
if (is_array($result)) {
foreach ($result as $key => $value) {
$result[$key] = $value;
}
}
return $result;
}
示例8: __construct
/**
* Entry constructor.
*
* @param resource $ds
* LDAP connection resource.
* @param string $rdn
* Relative distinguished name (to baseDN).
* @param string $dn
* Distinguished name.
* @param array $data
* Associative array of attribute keys and values.
*/
public function __construct($ds, $rdn, $dn, $data)
{
$this->ds = $ds;
$this->rdn = $rdn;
$this->dn = $dn;
$this->data = $data;
$this->oldData = $data;
$exploded_dn = ldap_explode_dn($dn, 0);
$top_dn = explode('=', $exploded_dn[0]);
$this->dnAttribute = strtolower($top_dn[0]);
}
示例9: explodeDN
/**
* Extends PHPs ldap_explode_dn() function
*
* UTF-8 chars like German umlauts would otherwise be escaped and shown
* as backslash-prefixed hexcode-sequenzes.
*
* @param string DN
* @param boolean Returns 'type=value' when true and 'value' when false
* @return string
*/
public static function explodeDN($dn, $with_type = true)
{
$res = ldap_explode_dn($dn, $with_type ? 0 : 1);
foreach ($res as $k => $v) {
$res[$k] = preg_replace_callback('/\\\\([0-9a-f]{2})/i', function ($m) {
return chr(hexdec($m[1]));
}, $v);
}
unset($res['count']);
return $res;
}
示例10: escapeDN
function escapeDN($dn)
{
$aDN = ldap_explode_dn($dn, false);
unset($aDN['count']);
foreach ($aDN as $key => $part) {
$value = substr($part, strpos($part, '=') + 1);
$escapedValue = strtr($value, array(',' => '\\2c', '=' => '\\3d', '+' => '\\2b', '<' => '\\3c', '>' => '\\3e', ';' => '\\3b', '\\' => '\\5c', '"' => '\\22', '#' => '\\23'));
$part = str_replace($part, $value, $escapedValue);
}
$dn = implode(',', $aDN);
return $dn;
}
示例11: testEntryConstruct
public function testEntryConstruct()
{
$returnedLdapEntries = ['count' => 3, 0 => [0 => 'distinguishedname', 'count' => 1, 'dn' => 'CN=Karen Berge,CN=admin,DC=corp,DC=Fabrikam,DC=COM', 'distinguishedname' => ['count' => 1, 'CN=Karen Berge,CN=admin,DC=corp,DC=Fabrikam,DC=COM']], 1 => [0 => 'distinguishedname', 'count' => 1, 'dn' => 'CN=Doe\\, John,CN=admin,DC=corp,DC=Fabrikam,DC=COM', 'distinguishedname' => ['count' => 1, 'CN=Doe\\, John,CN=admin,DC=corp,DC=Fabrikam,DC=COM']], 2 => [0 => 'cn', 'cn' => ['count' => 1, 0 => 'Test'], 'distinguishedname' => ['count' => 1, 0 => 'CN=Bauman\\, Steve,OU=Users,OU=Developers,OU=User Accounts,OU=Canada,DC=corp,DC=Fabrikam,DC=COM'], 1 => 'distinguishedname', 'displayname' => ['count' => 1, 0 => 'Bauman, Steve'], 2 => 'displayname', 'samaccountname' => ['count' => 1, 0 => 'stevebauman'], 3 => 'samaccountname', 'count' => 4, 'dn' => 'CN=Bauman\\, Steve,OU=Users,OU=Developers,OU=User Accounts,OU=Canada,DC=corp,DC=Fabrikam,DC=COM']];
$explodedDnsToReturn = [ldap_explode_dn($returnedLdapEntries[0]['dn'], 1), ldap_explode_dn($returnedLdapEntries[1]['dn'], 1), ldap_explode_dn($returnedLdapEntries[2]['dn'], 1)];
$connection = $this->newConnectionMock();
$connection->shouldReceive('explodeDn')->times(3)->andReturnValues($explodedDnsToReturn)->shouldReceive('close')->andReturn(true);
$expectedResults = [['distinguishedname' => 'CN=Karen Berge,CN=admin,DC=corp,DC=Fabrikam,DC=COM', 'dn' => 'CN=Karen Berge,CN=admin,DC=corp,DC=Fabrikam,DC=COM', 'dn_array' => ['count' => 5, 0 => 'Karen Berge', 1 => 'admin', 2 => 'corp', 3 => 'Fabrikam', 4 => 'COM']], ['distinguishedname' => 'CN=Doe\\, John,CN=admin,DC=corp,DC=Fabrikam,DC=COM', 'dn' => 'CN=Doe\\, John,CN=admin,DC=corp,DC=Fabrikam,DC=COM', 'dn_array' => ['count' => 5, 0 => 'Doe\\2C John', 1 => 'admin', 2 => 'corp', 3 => 'Fabrikam', 4 => 'COM']], ['cn' => 'Test', 'displayname' => 'Bauman, Steve', 'samaccountname' => 'stevebauman', 'distinguishedname' => 'CN=Bauman\\, Steve,OU=Users,OU=Developers,OU=User Accounts,OU=Canada,DC=corp,DC=Fabrikam,DC=COM', 'dn' => 'CN=Bauman\\, Steve,OU=Users,OU=Developers,OU=User Accounts,OU=Canada,DC=corp,DC=Fabrikam,DC=COM', 'dn_array' => ['count' => 8, 0 => 'Bauman\\2C Steve', 1 => 'Users', 2 => 'Developers', 3 => 'User Accounts', 4 => 'Canada', 5 => 'corp', 6 => 'Fabrikam', 7 => 'COM']]];
$entries = [];
for ($i = 0; $i < $returnedLdapEntries["count"]; $i++) {
$entry = new Entry($returnedLdapEntries[$i], $connection);
$entries[] = $entry->getAttributes();
}
$this->assertEquals($expectedResults, $entries);
}
示例12: dnToName
/**
* Answer a string name for a DN
*
* @param string $dn
* @return string
* @access public
* @since 8/31/09
*/
function dnToName($dn)
{
$levels = ldap_explode_dn($dn, 1);
unset($levels['count']);
// if (preg_match('/Miles/i', $dn)) {
// var_dump($dn);
// var_dump($levels);
// exit;
// }
if (count($levels) <= 2) {
return implode('.', $levels);
} else {
return str_replace('\\2C', ',', $levels[0]);
}
}
示例13: parseLdapDn
public function parseLdapDn($dn)
{
$parsr = ldap_explode_dn($dn, 0);
$out = array();
foreach ($parsr as $key => $value) {
if (FALSE !== strstr($value, '=')) {
list($prefix, $data) = explode("=", $value);
$data = preg_replace("/\\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $data);
if (isset($current_prefix) && $prefix == $current_prefix) {
$out[$prefix][] = $data;
} else {
$current_prefix = $prefix;
$out[$prefix][] = $data;
}
}
}
return $out;
}
示例14: assign
private function assign($computer)
{
if (array_key_exists(0, $computer) && $computer['count'] > 0) {
if (array_key_exists('dn', $computer[0])) {
$this->dn = ldap_explode_dn($computer[0]['dn'], 1);
$this->name = $this->dn[0];
if (array_key_exists(1, $this->dn)) {
$this->group = $this->dn[1];
}
if (array_key_exists(2, $this->dn)) {
$this->type = $this->dn[2];
}
if (array_key_exists('dnshostname', $computer[0])) {
$this->host_name = $computer[0]['dnshostname'][0];
}
$this->os = new ComputerOs($computer[0]);
}
}
}
示例15: ldap_process
function ldap_process($user, $pass)
{
require_once QA_INCLUDE_DIR . "../qa-plugin/qa-ldap-login/ldap-config.php";
// Establish link with LDAP server
$con = ldap_connect($hostname, $port) or die("Could not connect to ldap host.");
if (!is_resource($con)) {
trigger_error("Unable to connect to {$hostname}", E_USER_WARNING);
}
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
// Removing @email.com
if (strstr($user, '@')) {
$parts = preg_split("/@/", $user);
$user = $parts[0];
}
// Check if user/pass combo authenticates
$bind = ldap_bind($con, $user . $account_suffix, $pass);
if ($bind) {
} else {
return false;
}
// Connect to LDAP with read-only admin account
$bind = ldap_bind($con, $username . $account_suffix, $password);
if ($bind) {
// Run query to determine user's name
// Replace DOMAIN & com with ldap domain info
$dn = "CN=Users,DC=DOMAIN,DC=com";
$filter = "(&(objectClass=user)(sAMAccountName=" . $uname . "))";
$attributes = array("displayname");
$search = ldap_search($con, $dn, $filter, $attributes);
$data = ldap_get_entries($con, $search);
$explode = ldap_explode_dn($data[0]["dn"], 0);
$name = explode(" ", str_replace("CN=", "", $explode[0]));
// Close LDAP link
ldap_close($con);
// Return user's name in array
$name[2] = $user;
return $name;
}
}