本文整理汇总了PHP中ldap_escape函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_escape函数的具体用法?PHP ldap_escape怎么用?PHP ldap_escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_escape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: escape
/**
* Escape strings for safe use in an LDAP filter or DN
*
* @see RFC2254 define how string search filters must be represented
* @see For PHP >= 5.6.0, ldap_escape() is a core function
*
* @author Chris Wright
* @see https://github.com/DaveRandom/LDAPi/blob/master/src/global_functions.php
*
* @return String
*/
private function escape($value, $ignore = '', $flags = 0)
{
if (function_exists('ldap_escape')) {
return ldap_escape($value, $ignore, $flags);
}
$value = (string) $value;
$ignore = (string) $ignore;
$flags = (int) $flags;
if ($value === '') {
return '';
}
$char_list = array();
if ($flags & self::LDAP_ESCAPE_FILTER) {
$char_list = array("\\", "*", "(", ")", "");
}
if ($flags & self::LDAP_ESCAPE_DN) {
$char_list = array_merge($char_list, array("\\", ",", "=", "+", "<", ">", ";", "\"", "#"));
}
if (!$char_list) {
for ($i = 0; $i < 256; $i++) {
$char_list[] = chr($i);
}
}
$char_list = array_flip($char_list);
for ($i = 0; isset($ignore[$i]); $i++) {
unset($char_list[$ignore[$i]]);
}
foreach ($char_list as $k => &$v) {
$v = sprintf('\\%02x', ord($k));
}
return strtr($value, $char_list);
}
开发者ID:pombredanne,项目名称:tuleap,代码行数:43,代码来源:QueryEscaper.class.php
示例2: createUser
public function createUser($fn, $ln, $mn, $uname, $pwd, $groups, $phType, $ph, $domain)
{
$ldapObj = new Lucid_LDAP($this->configFile);
// Use sAMAccountName in commonName
$newEntry = array('givenName' => $fn, 'sn' => $ln, 'cn' => $uname, 'name' => "{$fn} {$ln}", 'displayName' => "{$fn} {$ln}", 'objectClass' => array("top", "person", "organizationalPerson", "user"), 'objectCategory' => "CN=Person,CN=Schema,CN=Configuration," . $ldapObj->basedn, 'sAMAccountName' => $uname, 'mail' => "{$uname}@{$domain}", 'userAccountControl' => 512, 'unicodePwd' => adifyPw($pwd));
if (!empty($mn)) {
$newEntry['middleName'] = $mn;
}
if ($phType == "home") {
$newEntry['homePhone'] = $ph;
} else {
if ($phType == "mobile") {
$newEntry['mobile'] = $ph;
}
}
// The DN for the new user
$dn = ldap_escape("cn={$uname},") . $ldapObj->createUserDn;
$ldapObj->bind($this->username, $this->password);
$status = $ldapObj->addEntry($dn, $newEntry);
if (!empty($groups)) {
$this->addUserToGroups($ldapObj, $dn, $groups);
}
$this->loggerObj->log("ADMIN::info::{$this->username} has successfully created User {$uname} successfully");
$ldapObj->destroy();
return $status;
}
开发者ID:sriraamas,项目名称:simple-ldap-manager,代码行数:26,代码来源:admin.php
示例3: escape
/**
* Returns an escaped string for use in an LDAP filter.
*
* @param string $value
* @param string $ignore
* @param $flags
*
* @return string
*/
public static function escape($value, $ignore = '', $flags = 0)
{
if (!static::isEscapingSupported()) {
return static::escapeManual($value, $ignore, $flags);
}
return ldap_escape($value, $ignore, $flags);
}
开发者ID:adldap2,项目名称:adldap2,代码行数:16,代码来源:Utilities.php
示例4: escape
/**
* {@inheritdoc}
*/
public function escape($subject, $ignore = '', $flags = 0)
{
$value = ldap_escape($subject, $ignore, $flags);
// Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
if ((int) $flags & LDAP_ESCAPE_DN) {
if (!empty($value) && $value[0] === ' ') {
$value = '\\20' . substr($value, 1);
}
if (!empty($value) && $value[strlen($value) - 1] === ' ') {
$value = substr($value, 0, -1) . '\\20';
}
$value = str_replace("\r", '\\0d', $value);
}
return $value;
}
开发者ID:robinkanters,项目名称:symfony,代码行数:18,代码来源:Adapter.php
示例5: searchUser
public function searchUser($username, $attr)
{
if (!$this->conn) {
throw new ADNotBoundException();
}
$eUserName = ldap_escape($username);
$entries = ldap_search($this->conn, $this->searchUserDn, "(sAMAccountName={$eUserName})", $attr);
$count = ldap_count_entries($this->conn, $entries);
$this->logger->log("Lucid_LDAP::info::LDAP Search Complete for '{$eUserName}', found {$count} entries");
if ($count > 0) {
$entry = ldap_first_entry($this->conn, $entries);
$dn = ldap_get_dn($this->conn, $entry);
return array($entry, $dn);
} else {
throw new EntryNotFoundException($username);
}
}
开发者ID:sriraamas,项目名称:simple-ldap-manager,代码行数:17,代码来源:lucid_ldap.php
示例6: escapeValue
/**
* Escape any special characters for LDAP to their hexadecimal representation.
*
* @param mixed $value The value to escape.
* @param null|string $ignore The characters to ignore.
* @param null|int $flags The context for the escaped string. LDAP_ESCAPE_FILTER or LDAP_ESCAPE_DN.
* @return string The escaped value.
*/
public static function escapeValue($value, $ignore = null, $flags = null)
{
// If this is a hexadecimal escaped string, then do not escape it.
$value = preg_match('/^(\\\\[0-9a-fA-F]{2})+$/', (string) $value) ? $value : ldap_escape($value, $ignore, $flags);
// Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
if ((int) $flags & LDAP_ESCAPE_DN) {
if (!empty($value) && $value[0] === ' ') {
$value = '\\20' . substr($value, 1);
}
if (!empty($value) && $value[strlen($value) - 1] === ' ') {
$value = substr($value, 0, -1) . '\\20';
}
// Only carriage returns seem to be valid, not line feeds (per testing of AD anyway).
$value = str_replace("\r", '\\0d', $value);
}
return $value;
}
开发者ID:ldaptools,项目名称:ldaptools,代码行数:25,代码来源:LdapUtilities.php
示例7: myldap_search
function myldap_search($ds, $dn, $filter)
{
$dn = ldap_escape($dn);
//$filter = ldap_escape($filter);
$sr = ldap_search($ds, $dn, $filter);
$info = ldap_get_entries($ds, $sr);
$data = array();
$data["count"] = $info["count"];
for ($i = 0; $i < $info["count"]; $i++) {
$entry = $info[$i];
$data[$i] = array();
$data[$i]["cn"] = $entry["cn"][0];
$data[$i]["sn"] = $entry["sn"][0];
$data[$i]["telephonenumber"] = $entry["telephonenumber"][0];
$data[$i]["postalcode"] = $entry["postalcode"][0];
$data[$i]["userpassword"] = $entry["userpassword"][0];
}
return $data;
}
开发者ID:seyyah,项目名称:ldapTool,代码行数:19,代码来源:fun.php
示例8: validateCredentials
/**
* Validate a user against the given credentials.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param array $credentials
* @return bool
*/
public function validateCredentials(UserContract $user, array $credentials)
{
$email = $credentials['email'];
$password = $credentials['password'];
$ldap_conn = ldap_connect($this->ldapConfig['host'], $this->ldapConfig['port']);
$ldap_bind = ldap_bind($ldap_conn, $this->ldapConfig['user'], $this->ldapConfig['password']);
try {
// Find By Email
$escEmail = ldap_escape($email, '', LDAP_ESCAPE_FILTER);
$filter = "(&(uid=*)(|(mail=" . $escEmail . ")" . "(gosaMailAlternateAddress=" . $escEmail . ")))";
$sr = ldap_search($ldap_conn, $this->ldapConfig['base'], $filter, []);
if (!$sr) {
return false;
}
$conn = ldap_connect($this->ldapConfig['host'], $this->ldapConfig['port']);
$entry = ldap_first_entry($ldap_conn, $sr);
while ($entry) {
$dn = ldap_get_dn($ldap_conn, $entry);
// Check Credentials
// remove warnings for incorrect passwords
$level = error_reporting();
error_reporting($level & ~E_WARNING);
try {
$bind = ldap_bind($conn, $dn, $password);
if ($bind) {
// successful
ldap_unbind($conn);
return true;
}
} finally {
// restore warnings
error_reporting($level);
}
$entry = ldap_next_entry($ldap_conn, $entry);
}
} finally {
ldap_unbind($ldap_conn);
}
return false;
}
开发者ID:AlexRadch,项目名称:Laravel-LdapCredentials,代码行数:47,代码来源:ValidateLdapCredentials.php
示例9: getUserByUsernameField
/**
* Returns user by uid
*
* @param string $username
* @param int $configId
* @return array|boolean
*/
public function getUserByUsernameField($username, $configId = 0)
{
$ldapConnections = $this->getLDAPConnectionsByConfigId($configId);
$user = false;
foreach ($ldapConnections as $ldapConnection) {
try {
$filter = $this->getFeUsersFilter($ldapConnection, ldap_escape($username));
$entry = $ldapConnection->search($ldapConnection->getDN(), $filter)->getFirstEntry();
} catch (LDAPException $e) {
continue;
}
if (!empty($entry)) {
foreach ($entry->getAttributes() as $attribute) {
$attribute = strtolower($attribute);
$user[$attribute] = $entry->getValues($attribute);
}
$user['dn'] = $entry->getDN();
$user['configId'] = $ldapConnection->getConfigUid();
}
}
return $user;
}
开发者ID:LiaraAlis,项目名称:typo3-ap_ldap_auth,代码行数:29,代码来源:LDAPFeUserRepository.php
示例10: studentska_osobe
//.........这里部分代码省略.........
?>
<p><a href="?sta=studentska/osobe&osoba=<?php
echo $osoba;
?>
&akcija=izbori&broj_izbora=-1">Kliknite ovdje za unos novog izbora</a></p>
<?php
}
} else {
if ($akcija == "edit") {
$pretraga = my_escape($_REQUEST['search']);
$ofset = my_escape($_REQUEST['offset']);
?>
<a href="?sta=studentska/osobe&search=<?php
echo $pretraga;
?>
&offset=<?php
echo $ofset;
?>
">Nazad na rezultate pretrage</a><br/><br/><?php
// Prvo odredjujemo aktuelnu akademsku godinu - ovaj upit se dosta koristi kasnije
$q210 = myquery("select id,naziv from akademska_godina where aktuelna=1 order by id desc");
if (mysql_num_rows($q210) < 1) {
// Nijedna godina nije aktuelna - ali mora postojati barem jedna u bazi
$q210 = myquery("select id,naziv from akademska_godina order by id desc");
}
$id_ak_god = mysql_result($q210, 0, 0);
$naziv_ak_god = mysql_result($q210, 0, 1);
// Posto se id_ak_god moze promijeniti.... CLEANUP!!!
$orig_iag = $id_ak_god;
// ======= SUBMIT AKCIJE =========
// Promjena korisničkog pristupa i pristupnih podataka
if ($_POST['subakcija'] == "auth" && check_csrf_token()) {
$login = my_escape(trim($_REQUEST['login']));
$login_ldap = ldap_escape(trim($_REQUEST['login']));
$stari_login = my_escape($_REQUEST['stari_login']);
$password = my_escape($_REQUEST['password']);
$aktivan = intval($_REQUEST['aktivan']);
if ($login == "") {
niceerror("Ne možete postaviti prazan login");
} else {
if ($stari_login == "") {
// Provjeravamo LDAP?
if ($conf_system_auth == "ldap") {
do {
// Simuliramo GOTO...
// Tražimo ovaj login na LDAPu...
$ds = ldap_connect($conf_ldap_server);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if (!ldap_bind($ds)) {
zamgerlog("Ne mogu se spojiti na LDAP server", 3);
// 3 - greska
zamgerlog2("ne mogu se spojiti na LDAP server");
niceerror("Ne mogu se spojiti na LDAP server - nastavljam dalje bez provjere");
break;
}
$sr = ldap_search($ds, "", "uid={$login_ldap}", array());
if (!$sr) {
zamgerlog("ldap_search() nije uspio.", 3);
zamgerlog2("ldap_search() nije uspio.");
niceerror("ldap_search() nije uspio - nastavljam dalje bez provjere");
break;
}
$results = ldap_get_entries($ds, $sr);
if ($results['count'] > 0) {
nicemessage("Login '{$login}' pronađen na LDAP serveru");
break;
开发者ID:msehalic,项目名称:zamger,代码行数:67,代码来源:osobe.php
示例11: mailUsed
public function mailUsed($mail)
{
$resource = ldap_search($this->ldapconn, $this->ldapbasedn, "otherMailbox=" . ldap_escape($mail, true));
if ($resource) {
$entry = ldap_first_entry($this->ldapconn, $resource);
if (@ldap_get_dn($this->ldapconn, $entry)) {
return true;
}
}
return false;
}
开发者ID:jungepiraten,项目名称:ucp,代码行数:11,代码来源:UserDatabase.class.php
示例12: login
function login($pass)
{
// RETURN VALUE:
// 0 - OK
// 1 - unknown user
// 2 - password doesn't match
// VARIABLES:
// $admin - user has admin privileges (from auth table)
// $userid - whatever is used internally (aside from login)
global $userid, $admin, $login, $conf_system_auth, $conf_ldap_server, $conf_ldap_domain, $posljednji_pristup;
$q1 = myquery("select id, password, admin, UNIX_TIMESTAMP(posljednji_pristup) from auth where login='{$login}' and aktivan=1");
if (mysql_num_rows($q1) <= 0) {
return 1;
}
function is_alias($results)
{
foreach ($results as $k1 => $v1) {
if ($k1 === "objectclass") {
foreach ($v1 as $k2 => $v2) {
if ($v2 === "zimbraAlias") {
return true;
}
}
}
}
return false;
}
if ($conf_system_auth == "ldap") {
$ds = ldap_connect($conf_ldap_server);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ds) {
if (ldap_bind($ds)) {
$i = 0;
// Probavamo UID
$login = ldap_escape($login);
$sr = ldap_search($ds, "", "uid={$login}", array());
if (!$sr) {
niceerror("ldap_search() failed.");
exit;
}
$results = ldap_get_entries($ds, $sr);
// Ako ldap_get_entries vrati false, pretpostavićemo da nema rezultata
// To se dešava rijetko ali se dešava i nije mi jasno zašto
// Ovaj upit ce vratiti i aliase, koje moramo profiltrirati
while ($results && is_alias($results[$i]) && $i < $results['count']) {
$i++;
}
// Probavamo email adresu
if (!$results || $i == $results['count']) {
$sr = ldap_search($ds, "", "mail={$login}", array());
if (!$sr) {
niceerror("ldap_search() 1 failed.");
exit;
}
$results = ldap_get_entries($ds, $sr);
$i = 0;
while ($results && is_alias($results[$i]) && $i < $results['count']) {
$i++;
}
}
// Probavamo email adresu + domena
if (!$results || $i == $results['count']) {
$sr = ldap_search($ds, "", "mail={$login}{$conf_ldap_domain}", array());
if (!$sr) {
niceerror("ldap_search() 2 failed.");
exit;
}
$results = ldap_get_entries($ds, $sr);
$i = 0;
while ($results && is_alias($results[$i]) && $i < $results['count']) {
$i++;
}
}
if (!$results || $i == $results['count']) {
return 1;
}
$dn = $results[$i]['dn'];
if (!@ldap_bind($ds, $dn, $pass)) {
// ldap_bind generiše warning svaki put kad je pogrešna šifra :(
return 2;
}
// ldap_bind succeeded, user is authenticated
} else {
niceerror("LDAP anonymous bind failed.");
exit;
}
} else {
niceerror("Can't contact LDAP server.");
exit;
}
} else {
if ($conf_system_auth == "table") {
if ($pass != mysql_result($q1, 0, 1)) {
return 2;
}
}
}
$userid = mysql_result($q1, 0, 0);
$admin = mysql_result($q1, 0, 2);
$posljednji_pristup = mysql_result($q1, 0, 3);
//.........这里部分代码省略.........
开发者ID:msehalic,项目名称:zamger,代码行数:101,代码来源:libvedran.php
示例13: add_netid_check_to_representation
/**
* Takes a generic representation of the group and adds the username provided to
* limit returned items to those matching the username
*
* This is useful for the is_username_member_of_group() method, which gets the representation, then adds the user limit with this method.
*
* @param string $user_netID The username we're going to test
* @param array $rep group representation
* @return string
* @access private
*/
function add_netid_check_to_representation($user_netID, $rep)
{
$user_netID = ldap_escape($user_netID);
foreach ($rep as $filter_key => $filter_info) {
if (!empty($filter_info['filter'])) {
$rep[$filter_key]['filter'] = '(&(ds_username=' . $user_netID . ')' . $filter_info['filter'] . ')';
}
if (!empty($filter_info['group_filter'])) {
if ($this->group->get_value('ldap_group_member_fields')) {
$fields = explode(',', $this->group->get_value('ldap_group_member_fields'));
$member_chunk = '(|';
foreach ($fields as $field) {
$field = trim($field);
if (!empty($field)) {
$member_chunk .= '(' . $field . '=' . $user_netID . ')';
}
}
$member_chunk .= ')';
} else {
$member_chunk = '(ds_member=' . $user_netID . ')';
}
$rep[$filter_key]['group_filter'] = '(&' . $member_chunk . $filter_info['group_filter'] . ')';
}
}
return $rep;
}
开发者ID:hunter2814,项目名称:reason_package,代码行数:37,代码来源:group_helper.php
示例14: escape
/**
* @link http://php.net/manual/en/function.ldap-escape.php
* @param $subject
* @param null $ignore
* @param null $escape
* @return string
*/
public function escape($subject, $ignore = null, $escape = null)
{
return ldap_escape($subject, $ignore, $escape);
}
开发者ID:CarnegieLearningWeb,项目名称:ldap-orm-bundle,代码行数:11,代码来源:Core.php
示例15: escape_filter
static function escape_filter($string)
{
if (function_exists('ldap_escape')) {
return ldap_escape($string, '', LDAP_ESCAPE_FILTER);
} else {
$map = array('\\' => '\\5c', '*' => '\\2a', '(' => '\\28', ')' => '\\29', "" => '\\00');
return str_replace(array_keys($map), $map, $string);
}
}
开发者ID:btalayminaei,项目名称:DGSecurity,代码行数:9,代码来源:ldap.php
示例16: updateAllGroups
/**
* Update All Groups
* Runs through the directory to update all settings (users and naming)
*/
private function updateAllGroups()
{
if (!empty($this->gcache)) {
return true;
}
if (php_sapi_name() !== 'cli') {
throw new \Exception("Can only update groups over CLI");
}
$this->connect();
$this->out("Retrieving all groups...", false);
$sr = ldap_search($this->ldap, $this->dn, "(objectCategory=Group)", array("distinguishedname", "primarygrouptoken", "objectsid", "description", "cn"));
if ($sr === false) {
return false;
}
$groups = ldap_get_entries($this->ldap, $sr);
$this->out("Got " . $groups['count'] . " groups");
unset($groups['count']);
$sql = "DROP TABLE IF EXISTS msad_procs_temp";
$sth = $this->FreePBX->Database->prepare($sql);
$sth->execute();
$tempsql = "CREATE TABLE msad_procs_temp (\n\t\t\t`pid` int NOT NULL,\n\t\t\t`udata` varchar(255),\n\t\t\t`gdata` varchar(255),\n\t\t\tPRIMARY KEY(pid)\n\t\t) ENGINE = MEMORY";
$sth = $this->FreePBX->Database->prepare($tempsql);
$sth->execute();
$this->out("Forking child processes");
$tpath = __DIR__ . "/tmp";
if (!file_exists($tpath)) {
mkdir($tpath, 0777, true);
}
foreach ($groups as $i => $group) {
$pid = pcntl_fork();
if (!$pid) {
$iid = getmypid();
\FreePBX::Database()->__construct();
$db = new \DB();
$this->connect(true);
//http://www.rlmueller.net/CharactersEscaped.htm
$group['distinguishedname'][0] = ldap_escape($group['distinguishedname'][0]);
$this->out("\tGetting users from " . $group['cn'][0] . "...");
$gs = ldap_search($this->ldap, $this->dn, "(&(objectCategory=Person)(sAMAccountName=*)(memberof=" . $group['distinguishedname'][0] . "))");
if ($gs !== false) {
$users = ldap_get_entries($this->ldap, $gs);
$susers = serialize($users);
file_put_contents($tpath . "/" . $iid . "-users", $susers);
$sgroup = serialize($group);
file_put_contents($tpath . "/" . $iid . "-group", $sgroup);
$sql = "INSERT INTO msad_procs_temp (`pid`,`udata`,`gdata`) VALUES (?,?,?)";
$sth = $this->FreePBX->Database->prepare($sql);
$sth->execute(array($i, $iid . "-users", $iid . "-group"));
}
$this->out("\tFinished Getting users from " . $group['cn'][0]);
exit($i);
}
}
\FreePBX::Database()->__construct();
$db = new \DB();
while (pcntl_waitpid(0, $status) != -1) {
$status = pcntl_wexitstatus($status);
}
$this->out("Child processes have finished");
$sql = "SELECT * FROM msad_procs_temp";
$sth = $this->FreePBX->Database->prepare($sql);
$sth->execute();
$children = $sth->fetchAll(\PDO::FETCH_ASSOC);
$this->out("Adding Users from non-primary groups...");
foreach ($children as $child) {
if (!file_exists($tpath . "/" . $child['udata']) || !file_exists($tpath . "/" . $child['gdata'])) {
continue;
}
$udata = file_get_contents($tpath . "/" . $child['udata']);
unlink($tpath . "/" . $child['udata']);
$users = unserialize($udata);
$gdata = file_get_contents($tpath . "/" . $child['gdata']);
unlink($tpath . "/" . $child['gdata']);
$group = unserialize($gdata);
$this->out("\tFound " . $users['count'] . " users in " . $group['cn'][0]);
unset($users['count']);
$members = array();
foreach ($users as $user) {
$usid = $this->binToStrSid($user['objectsid'][0]);
$u = $this->getUserByAuthID($usid);
$members[] = $u['id'];
}
$sid = $this->binToStrSid($group['objectsid'][0]);
$this->gcache[$sid] = $group;
$um = $this->linkGroup($group['cn'][0], 'msad', $sid);
if ($um['status']) {
$this->updateGroupData($um['id'], array("description" => !empty($group['description'][0]) ? $group['description'][0] : '', "users" => $members));
if ($um['new']) {
$this->groupHooks['add'][$um['id']] = array($um['id'], $group['cn'][0], !empty($group['description'][0]) ? $group['description'][0] : '', $members);
} else {
$this->groupHooks['update'][$um['id']] = array($um['id'], $um['prevGroupname'], $group['cn'][0], !empty($group['description'][0]) ? $group['description'][0] : '', $members);
}
}
}
//remove users
$fgroups = $this->getAllGroups();
//.........这里部分代码省略.........
开发者ID:ringfreejohn,项目名称:pbxframework,代码行数:101,代码来源:Msad.php
示例17: getUserGroups
/**
* Gets the list of the groups in which specified user has memberships.
*
* @return array Returns array of the sAMAccount name of the Groups
* @throws Exception\LdapException
*/
public function getUserGroups()
{
$this->log('%s is called.', __FUNCTION__);
$name = strtok($this->username, '@');
$groups = array();
$this->getConnection();
//Ldap bind
if (!$this->isbound && (!empty($this->config->user) && !empty($this->password))) {
if ($this->bindRdn() === false) {
throw new Exception\LdapException(sprintf("Could not bind LDAP. %s", $this->getLdapError()));
}
}
if (empty($this->dn)) {
$filter = sprintf('(&%s(' . $this->getConfig()->usernameAttribute . '=%s))', $this->config->userFilter, self::realEscape($name));
$query = @ldap_search($this->conn, $this->config->baseDn, $filter, array('dn'), 0, 1);
$this->log("Query user baseDn:%s filter:%s - %s", $this->config->baseDn, $filter, $query !== false ? 'OK' : 'Failed');
if ($query === false) {
throw new Exception\LdapException(sprintf("Could not perform ldap_search. %s", $this->getLdapError()));
}
$results = ldap_get_entries($this->conn, $query);
$this->dn = $results[0]['dn'];
}
$baseDn = !empty($this->config->baseDnGroups) ? $this->config->baseDnGroups : $this->config->baseDn;
if ($this->memberofDn !== null && empty($this->memberofDn)) {
//User has no membership in any group.
return array();
}
if ($this->getConfig()->bindType == 'openldap') {
$uid = $this->uid ? $this->uid : $this->username;
if ($this->getConfig()->groupMemberAttributeType == 'unix_netgroup') {
$filter = "(&" . $this->config->groupFilter . "(" . $this->getConfig()->groupMemberAttribute . "" . ($this->config->groupNesting ? ":1.2.840.113556.1.4.1941:" : "") . '=\\(,' . self::escape($uid) . ',\\)))';
} elseif ($this->getConfig()->groupMemberAttributeType == 'regular') {
$filter = "(&" . $this->config->groupFilter . "(" . $this->getConfig()->groupMemberAttribute . "" . ($this->config->groupNesting ? ":1.2.840.113556.1.4.1941:" : "") . '=' . self::escape($uid) . '))';
} elseif ($this->getConfig()->groupMemberAttributeType == 'user_dn') {
$filter = "(&" . $this->config->groupFilter . "(" . $this->getConfig()->groupMemberAttribute . "" . ($this->config->groupNesting ? ":1.2.840.113556.1.4.1941:" : "") . '=' . self::escape($this->username) . '))';
}
} else {
$filter = "(&" . $this->config->groupFilter . "(" . $this->getConfig()->groupMemberAttribute . "" . ($this->config->groupNesting ? ":1.2.840.113556.1.4.1941:" : "") . "=" . ldap_escape($this->dn, null, LDAP_ESCAPE_FILTER) . "))";
}
$search = @ldap_search($this->conn, $baseDn, $filter, array($this->getConfig()->groupnameAttribute));
$this->log("Query user's groups baseDn:%s filter:%s - %s", $baseDn, $filter, $search !== false ? 'OK' : 'Failed');
if ($search === false) {
throw new Exception\LdapException(sprintf("Could not perform ldap_search. %s", $this->getLdapError()));
}
$results = ldap_get_entries($this->conn, $search);
for ($item = 0; $item < $results['count']; $item++) {
$groups[] = $results[$item][strtolower($this->getConfig()->groupnameAttribute)][0];
}
$this->log("Found groups: %s", implode(", ", $groups));
return $groups;
}
开发者ID:scalr,项目名称:scalr,代码行数:57,代码来源:LdapClient.php
示例18: trim
die;
}
require_once '../core/admin.php';
$aname = trim($_POST['aname']);
$apwd = trim($_POST['apwd']);
$adminObj = new Admin($aname, $apwd);
$userQ = $_POST['userQuery'];
try {
$valuePattern = "[ ]*([a-zA-Z0-9]+[ a-zA-Z0-9-_.]*)[ ]*";
if (preg_match("/^[ ]*(sn|givenName|sAMAccountName)[ ]*:{$valuePattern}\$/", $userQ, $matches)) {
$field = $matches[1];
$value = ldap_escape(trim($matches[2]));
$filter = "({$field}={$value}*)";
} else {
if (preg_match("/^{$valuePattern}\$/", $userQ, $matches)) {
$value = ldap_escape(trim($matches[1]));
$filter = "(|(sAMAccountName={$value}*)(givenName={$value}*)(sn={$value}*))";
} else {
throw new Exception("Invalid Search Query '{$userQ}'.Search query must start with alphanumeric character and can contain letters, digits, dashes, periods and underscores only!");
}
}
$results = $adminObj->searchUsers($filter);
$response = array('success' => true, 'data' => $results, 'errors' => array());
} catch (EntryNotFoundException $en) {
$response = array('success' => false, 'errors' => array("Search for '{$value}' returned No Results"));
} catch (Exception $e) {
$response = array('success' => false, 'errors' => array($e->getMessage()));
}
header('Content-Type: application/json', TRUE);
$jsonstring = json_encode($response);
echo $jsonstring;
开发者ID:sriraamas,项目名称:simple-ldap-manager,代码行数:31,代码来源:userSearch.php
示例19: escape
/**
* Escape a string for use in an LDAP filter or DN
*
* `$flags` may be one of: `Ldap::ESCAPE_FILTER`, `Ldap::ESCAPE_DN`
*
* @since PHP 5.6
* @param string $value The value to escape
* @param string $ignore Characters to ignore when escaping
* @param integer $flags The context the escaped string will be used in
* @return string Returns the escaped string
*/
public static function escape($value, $ignore = null, $flags = null)
{
if (!function_exists('ldap_escape')) {
// Bail out, can't work our magic!
trigger_error('ldap_escape() is only available in PHP 5.6 or newer', E_USER_ERROR);
}
return ldap_escape($value, $ignore, $flags);
}
开发者ID:dreamscapes,项目名称:ldap-core,代码行数:19,代码来源:Ldap.php
示例20: escape
/**
* {@inheritdoc}
*/
public function escape($subject, $ignore = '', $flags = 0)
{
return ldap_escape($subject, $ignore, $flags);
}
开发者ID:ABaldwinHunter,项目名称:symfony-clone,代码行数:7,代码来源:LdapClient.php
注:本文中的ldap_escape函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论