You are here

function LdapServer::userUsernameToLdapNameTransform in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/LdapServer.class.php \LdapServer::userUsernameToLdapNameTransform()
1 call to LdapServer::userUsernameToLdapNameTransform()
LdapServer::userUserNameToExistingLdapEntry in ldap_servers/LdapServer.class.php
Queries LDAP server for the user.

File

ldap_servers/LdapServer.class.php, line 931
Defines server classes and related functions.

Class

LdapServer
LDAP Server Class

Code

function userUsernameToLdapNameTransform($drupal_username, &$watchdog_tokens) {
  if ($this->ldapToDrupalUserPhp && module_exists('php')) {
    global $name;
    $old_name_value = $name;
    $name = $drupal_username;
    $code = "<?php global \$name; \n" . $this->ldapToDrupalUserPhp . "; \n ?>";
    $watchdog_tokens['%code'] = $this->ldapToDrupalUserPhp;
    $code_result = php_eval($code);
    $watchdog_tokens['%code_result'] = $code_result;
    $ldap_username = $code_result;
    $watchdog_tokens['%ldap_username'] = $ldap_username;
    $name = $old_name_value;

    // important because of global scope of $name
    if ($this->detailedWatchdogLog) {
      watchdog('ldap_server', '%drupal_user_name tansformed to %ldap_username by applying code <code>%code</code>', $watchdog_tokens, WATCHDOG_DEBUG);
    }
  }
  else {
    $ldap_username = $drupal_username;
  }
  return $ldap_username;
}