You are here

function simple_ldap_user_variable_get in Simple LDAP 7

Same name and namespace in other branches
  1. 7.2 simple_ldap_user/simple_ldap_user.module \simple_ldap_user_variable_get()

Returns the value for the specified variable.

This function takes into account the configured LDAP server type, and attempts to determine a reasonable default value to try to use in the event that the module has not yet been configured.

36 calls to simple_ldap_user_variable_get()
SimpleLdapRole::addUser in simple_ldap_role/SimpleLdapRole.class.php
Add an LDAP user to the LDAP group.
SimpleLdapRole::deleteUser in simple_ldap_role/SimpleLdapRole.class.php
Remove an LDAP user from the LDAP group.
SimpleLdapRoleChangeDrupalUserRoleTestCase::testChangeDrupalUserRole in simple_ldap_role/simple_ldap_role.test
Changes a user's drupal roles.
SimpleLdapRoleChangeLdapGroupMembership::testChangeLdapGroupMembership in simple_ldap_role/simple_ldap_role.test
Test changing group membership directly in LDAP.
SimpleLdapUser::filter in simple_ldap_user/SimpleLdapUser.class.php
Return the LDAP search filter, as set by the module configuration.

... See full list

File

simple_ldap_user/simple_ldap_user.module, line 564
Main simple_ldap_user module file.

Code

function simple_ldap_user_variable_get($name, $default = NULL, $force_default = FALSE) {

  // Allow variable name shorthand by prepending 'simple_ldap_user_' to $name if
  // it is not already there.
  if (strpos($name, 'simple_ldap_user_') !== 0) {
    $name = 'simple_ldap_user_' . $name;
  }

  // Get an LDAP server object.
  $server = SimpleLdapServer::singleton();

  // Handle special variables.
  switch ($name) {
    case 'simple_ldap_user_source':

      // If the LDAP server is set to read-only, force LDAP->Drupal sync.
      if ($server->readonly) {
        return 'ldap';
      }
      break;
    case 'simple_ldap_user_attribute_map':

      // Load the attribute map from settings.php.
      $attribute_map = variable_get($name, array());
      return $attribute_map;
  }

  // Define defaults that differ based on LDAP server type.
  switch ($server->type) {
    case 'Active Directory':
      $defaults = array(
        'simple_ldap_user_objectclass' => array(
          'user',
        ),
        'simple_ldap_user_attribute_name' => 'samaccountname',
        'simple_ldap_user_attribute_mail' => 'mail',
        'simple_ldap_user_attribute_pass' => 'unicodepwd',
        'simple_ldap_user_password_hash' => 'unicode',
        'simple_ldap_user_attribute_rdn' => 'cn',
      );
      break;
    default:
      $defaults = array(
        'simple_ldap_user_objectclass' => array(
          'inetorgperson',
        ),
        'simple_ldap_user_attribute_name' => 'cn',
        'simple_ldap_user_attribute_mail' => 'mail',
        'simple_ldap_user_attribute_pass' => 'userpassword',
        'simple_ldap_user_password_hash' => 'salted sha',
      );
  }

  // Define defaults that do not depend on LDAP server type.
  $defaults['simple_ldap_user_basedn'] = $server->basedn;
  $defaults['simple_ldap_user_scope'] = 'sub';
  $defaults['simple_ldap_user_source'] = 'ldap';
  $defaults['simple_ldap_user_sync'] = 'hook_user_load';
  $defaults['simple_ldap_user_delete_from_ldap'] = '1';

  // Determine the default value for the given variable.
  $default = isset($defaults[$name]) ? $defaults[$name] : $default;
  if ($force_default) {
    return $default;
  }
  return variable_get($name, $default);
}