original_string: function ntlmsso_magic($sesskey) {
          if (isset($_SERVER['REMOTE_USER']) && !empty($_SERVER['REMOTE_USER'])) {
  
              // HTTP __headers__ seem to be sent in ISO-8859-1 encoding
              // (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and
              // my local tests), so we need to convert the REMOTE_USER value
              // (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8
              $username = core_text::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8');
  
              switch ($this->config->ntlmsso_type) {
                  case 'ntlm':
                      // The format is now configurable, so try to extract the username
                      $username = $this->get_ntlm_remote_user($username);
                      if (empty($username)) {
                          return false;
                      }
                      break;
                  case 'kerberos':
                      // Format is username@DOMAIN
                      $username = substr($username, 0, strpos($username, '@'));
                      break;
                  default:
                      error_log($this->errorlogtag.get_string ('ntlmsso_unknowntype', 'auth_ldap'));
                      return false; // Should never happen!
              }
  
              $username = core_text::strtolower($username); // Compatibility hack
              set_cache_flag($this->pluginconfig.'/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
              return true;
          }
          return false;
      }
code: function ntlmsso_magic($sesskey) {
          if (isset($_SERVER['REMOTE_USER']) && !empty($_SERVER['REMOTE_USER'])) {
  
              // HTTP __headers__ seem to be sent in ISO-8859-1 encoding
              // (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and
              // my local tests), so we need to convert the REMOTE_USER value
              // (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8
              $username = core_text::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8');
  
              switch ($this->config->ntlmsso_type) {
                  case 'ntlm':
                      // The format is now configurable, so try to extract the username
                      $username = $this->get_ntlm_remote_user($username);
                      if (empty($username)) {
                          return false;
                      }
                      break;
                  case 'kerberos':
                      // Format is username@DOMAIN
                      $username = substr($username, 0, strpos($username, '@'));
                      break;
                  default:
                      error_log($this->errorlogtag.get_string ('ntlmsso_unknowntype', 'auth_ldap'));
                      return false; // Should never happen!
              }
  
              $username = core_text::strtolower($username); // Compatibility hack
              set_cache_flag($this->pluginconfig.'/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
              return true;
          }
          return false;
      }
code_tokens: function ntlmsso_magic ( $ sesskey ) { if ( isset ( $ _SERVER [ 'REMOTE_USER' ] ) && ! empty ( $ _SERVER [ 'REMOTE_USER' ] ) ) { // HTTP __headers__ seem to be sent in ISO-8859-1 encoding // (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and // my local tests), so we need to convert the REMOTE_USER value // (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8 $ username = core_text :: convert ( $ _SERVER [ 'REMOTE_USER' ] , 'iso-8859-1' , 'utf-8' ) ; switch ( $ this -> config -> ntlmsso_type ) { case 'ntlm' : // The format is now configurable, so try to extract the username $ username = $ this -> get_ntlm_remote_user ( $ username ) ; if ( empty ( $ username ) ) { return false ; } break ; case 'kerberos' : // Format is username@DOMAIN $ username = substr ( $ username , 0 , strpos ( $ username , '@' ) ) ; break ; default : error_log ( $ this -> errorlogtag . get_string ( 'ntlmsso_unknowntype' , 'auth_ldap' ) ) ; return false ; // Should never happen! } $ username = core_text :: strtolower ( $ username ) ; // Compatibility hack set_cache_flag ( $ this -> pluginconfig . '/ntlmsess' , $ sesskey , $ username , AUTH_NTLMTIMEOUT ) ; return true ; } return false ; }
docstring: To be called from a page running under NTLM's
  "Integrated Windows Authentication".
  
  If successful, it will set a special "cookie" (not an HTTP cookie!)
  in cache_flags under the $this->pluginconfig/ntlmsess "plugin" and return true.
  The "cookie" will be picked up by ntlmsso_finish() to complete the
  process.
  
  On failure it will return false for the caller to display an appropriate
  error message (probably saying that Integrated Windows Auth isn't enabled!)
  
  NOTE that this code will execute under the OS user credentials,
  so we MUST avoid dealing with files -- such as session files.
  (The caller should define('NO_MOODLE_COOKIES', true) before including config.php)
docstring_tokens: To be called from a page running under NTLM s Integrated Windows Authentication .