本文整理汇总了PHP中ldap_add函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_add函数的具体用法?PHP ldap_add怎么用?PHP ldap_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addUser
/**
* Add a set of authentication credentials.
*
* @param string $accountName The user sAMAccountName to find.
* @param array $credentials The credentials to be set.
*
* @throws Horde_Auth_Exception
*/
public function addUser($accountName, $credentials)
{
/* Connect to the MSAD server. */
$this->_connect();
if (isset($credentials['ldap'])) {
$dn = $credentials['ldap']['dn'];
} else {
$basedn = isset($credentials['basedn']) ? $credentials['basedn'] : $this->_params['basedn'];
/* Set a default CN */
$dn = 'cn=' . $accountName . ',' . $basedn;
$entry['cn'] = $accountName;
$entry['samaccountname'] = $accountName;
$entry['objectclass'][0] = "top";
$entry['objectclass'][1] = "person";
$entry['objectclass'][2] = "organizationalPerson";
$entry['objectclass'][3] = "user";
$entry['description'] = isset($credentials['description']) ? $credentials['description'] : 'New horde user';
if ($this->_params['ssl']) {
$entry["AccountDisabled"] = false;
}
$entry['userPassword'] = Horde_Auth::getCryptedPassword($credentials['password'], '', $this->_params['encryption'], false);
if (isset($this->_params['binddn'])) {
$entry['manager'] = $this->_params['binddn'];
}
}
$success = @ldap_add($this->_ds, $dn, $entry);
if (!$success) {
throw new Horde_Auth_Exception(sprintf(__CLASS__ . ': Unable to add user "%s". This is what the server said: ', $accountName) . ldap_error($this->_ds));
}
@ldap_close($this->_ds);
}
示例2: process
function process()
{
print_r($this->input);
if (ldap_add($this->ds, $this->rdn, $this->input)) {
return true;
}
}
示例3: add
/**
* lastname (sn) is required for the "inetOrgPerson" schema
*/
public function add(Users_Model_User $user)
{
$dn = 'cn=' . $user->username . ',' . $this->_ldapConfig->baseDn;
$info = array('cn' => $user->username, 'givenName' => $user->firstname, 'sn' => $user->lastname, 'mail' => $user->email, 'userPassword' => $this->_hashPassword($user->password), 'objectclass' => 'inetOrgPerson');
if (!@ldap_add($this->_dp, $dn, $info) && ldap_error($this->_dp) != 'Success') {
throw new Exception('Could not add record to LDAP server: ' . ldap_error($this->_dp));
}
}
示例4: prepareLDAPServer
protected function prepareLDAPServer()
{
$this->nodes = array($this->createDn('ou=Node,') => array("objectClass" => "organizationalUnit", "ou" => "Node", "postalCode" => "1234"), $this->createDn('ou=Test1,ou=Node,') => array("objectClass" => "organizationalUnit", "ou" => "Test1"), $this->createDn('ou=Test2,ou=Node,') => array("objectClass" => "organizationalUnit", "ou" => "Test2"), $this->createDn('ou=Test1,') => array("objectClass" => "organizationalUnit", "ou" => "Test1", "l" => "e"), $this->createDn('ou=Test2,') => array("objectClass" => "organizationalUnit", "ou" => "Test2", "l" => "d"), $this->createDn('ou=Test3,') => array("objectClass" => "organizationalUnit", "ou" => "Test3", "l" => "c"), $this->createDn('ou=Test4,') => array("objectClass" => "organizationalUnit", "ou" => "Test4", "l" => "b"), $this->createDn('ou=Test5,') => array("objectClass" => "organizationalUnit", "ou" => "Test5", "l" => "a"));
$ldap = $this->ldap->getResource();
foreach ($this->nodes as $dn => $entry) {
ldap_add($ldap, $dn, $entry);
}
}
示例5: add
/**
* {@inheritdoc}
*/
public function add(Entry $entry)
{
$con = $this->connection->getResource();
if (!@ldap_add($con, $entry->getDn(), $entry->getAttributes())) {
throw new LdapException(sprintf('Could not add entry "%s": %s', $entry->getDn(), ldap_error($con)));
}
return $this;
}
示例6: addGroup
function addGroup($ds, $info)
{
// On ajoute le nouveau groupe
$r = ldap_add($ds, "cn=" . $info['cn'] . ",ou=groups,dc=rBOX,dc=lan", $info);
// On affiche un message d'erreur si l'utilisateur n'a pas pu être ajouté
if (!$r) {
echo '<p class="center red">Le groupe n\'a pas pu être ajouté. Nous vous prions de nous excuser pour le désagrément.</p>';
exit;
}
}
示例7: create
public function create($attrs)
{
if (!isset($attrs['uid'])) {
return false;
}
$entry = array_merge(['objectclass' => $this->objectclass], $attrs);
try {
return ldap_add($this->ds, "dc=" . $attrs['uid'] . "," . $this->dn, $entry);
} catch (\Exception $e) {
return false;
}
}
示例8: AssistedLDAPAdd
function AssistedLDAPAdd($ldapc, $newdn, $in)
{
// Use these variables that are outside the function
global $app_theme;
// Add the new entry
$r_add = ldap_add($ldapc, $newdn, $in);
// Let's see if you could make it
if (!$r_add) {
echo '<div class="error">' . _("An error has ocurred trying to insert entries on the LDAP database: ") . ldap_error($ldapc) . '.<br /><br /><a href="javascript:history.back(1);">' . _("Back") . '</a></div>';
include "../themes/{$app_theme}/footer.php";
die;
}
return $r_add;
}
示例9: ldapCreateUser
/**
* Create LDAP User
* @param $userDn
* @param $newUserInfo
* @return mixed
*/
public function ldapCreateUser($userDn, $newUserInfo)
{
// Initialiazing ldap connection
$ldapInitialisation = $this->ldapInit();
$issue = null;
if ($ldapInitialisation) {
// Creating user
ErrorHandler::start(E_WARNING);
$issue = ldap_add($this->ldapLinkIdentifier, $userDn, $newUserInfo);
ErrorHandler::stop();
// Closing ldap connection
ldap_close($this->ldapLinkIdentifier);
}
return $issue;
}
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->_prepareLdapServer();
$this->_orgDn = $this->_createDn('ou=OrgTest,');
$this->_newDn = $this->_createDn('ou=NewTest,');
$this->_orgSubTreeDn = $this->_createDn('ou=OrgSubtree,');
$this->_newSubTreeDn = $this->_createDn('ou=NewSubtree,');
$this->_targetSubTreeDn = $this->_createDn('ou=Target,');
$this->_nodes = array($this->_orgDn => array("objectClass" => "organizationalUnit", "ou" => "OrgTest"), $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "OrgSubtree"), 'ou=Subtree1,' . $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Subtree1"), 'ou=Subtree11,ou=Subtree1,' . $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Subtree11"), 'ou=Subtree12,ou=Subtree1,' . $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Subtree12"), 'ou=Subtree13,ou=Subtree1,' . $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Subtree13"), 'ou=Subtree2,' . $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Subtree2"), 'ou=Subtree3,' . $this->_orgSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Subtree3"), $this->_targetSubTreeDn => array("objectClass" => "organizationalUnit", "ou" => "Target"));
$ldap = $this->_getLdap()->getResource();
foreach ($this->_nodes as $dn => $entry) {
ldap_add($ldap, $dn, $entry);
}
}
示例11: addUser
function addUser($ds, $info, $infoGroupes)
{
// On ajoute le nouvel utilisateur
$r = ldap_add($ds, "cn=" . $info["cn"] . ",ou=users,dc=rBOX,dc=lan", $info);
// On affiche un message d'erreur si l'utilisateur n'a pas pu être ajouté
if (!$r) {
echo '<p class="center red">L\'utilisateur n\'a pas pu être ajouté. Nous vous prions de nous excuser pour le désagrément.</p>';
exit;
}
$entry['memberUid'] = $info["cn"];
$res = add2Group($ds, $entry, $infoGroupes);
$res2 = add2OtherGroup($ds, $entry, $infoGroupes);
if (!$res or !$res2) {
return false;
}
return true;
}
示例12: saveNewUser
public function saveNewUser($user)
{
if (!is_object($user) || !$user instanceof jAuthUserLDAP) {
throw new jException('jelix~auth.ldap.object.user.unknown');
}
if (!($user->login != '')) {
throw new jException('jelix~auth.ldap.user.login.unset');
}
$entries = $this->getAttributesLDAP($user);
$connect = $this->_bindLdapUser();
if ($connect === false) {
return false;
}
$result = ldap_add($connect, $this->_buildUserDn($user->login), $entries);
ldap_close($connect);
return $result;
}
示例13: saveNewUser
public function saveNewUser($user)
{
if (!is_object($user) || !$user instanceof jAuthUserLDAP) {
throw new jException('jelix~auth.ldap.object.user.unknown');
}
if (!($user->login != '')) {
throw new jException('jelix~auth.ldap.user.login.unset');
}
$entries = $this->getAttributesLDAP($user);
$connect = $this->_getLinkId();
$result = false;
if ($connect) {
if (ldap_bind($connect, $this->_params['ldapUser'], $this->_params['ldapPassword'])) {
$result = ldap_add($connect, $this->_buildUserDn($user->login), $entries);
}
ldap_close($connect);
}
return $result;
}
示例14: saveNewUser
public function saveNewUser($user)
{
if (!is_object($user) || !$user instanceof jAuthUserLDAP) {
throw new jException('jelix~auth.ldap.object.user.unknown');
}
if (!($user->login != '')) {
throw new jException('jelix~auth.ldap.user.login.unset');
}
$entries = $this->getAttributesLDAP($user);
$connect = ldap_connect($this->_params['hostname'], $this->_params['port']);
$result = false;
if ($connect) {
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
if (ldap_bind($connect, $this->_params['ldapUser'], $this->_params['ldapPassword'])) {
$result = ldap_add($connect, 'cn=' . $user->login . ',' . $this->_params['searchBaseDN'], $entries);
}
ldap_close($connect);
}
return $result;
}
示例15: registerNewUser
function registerNewUser($username, $password, $firstname, $lastname, $email, $phone, $groups)
{
$info = array();
$info["uid"] = $username;
$info["userPassword"] = $password;
$info["givenName"] = $firstname;
$info["sn"] = $lastname;
$info["cn"] = $firstname . $lastname;
$info["mail"] = $email;
$info["telephoneNumber"] = $phone;
$info["objectClass"][0] = "top";
$info["objectClass"][1] = "person";
$info["objectClass"][2] = "organizationalPerson";
$info["objectClass"][3] = "inetorgperson";
$info["objectClass"][4] = "posixAccount";
$info["objectClass"][5] = "inetuser";
if (ldap_add($connection, $DN, $info) == false) {
return false;
}
foreach ($groups as $group) {
addUserToGroup($username, $group);
}
return true;
}