Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   1  <?php
   2  
   3  // Don't let lib/setup.php set any cookies
   4  // as we will be executing under the OS security
   5  // context of the user we are trying to login, rather than
   6  // of the webserver.
   7  define('NO_MOODLE_COOKIES', true);
   8  
   9  require(__DIR__.'/../../config.php');
  10  
  11  $PAGE->set_context(context_system::instance());
  12  
  13  $authsequence = get_enabled_auth_plugins(); // Auths, in sequence.
  14  if (!in_array('ldap', $authsequence, true)) {
  15      throw new \moodle_exception('ldap_isdisabled', 'auth');
  16  }
  17  
  18  $authplugin = get_auth_plugin('ldap');
  19  if (empty($authplugin->config->ntlmsso_enabled)) {
  20      throw new \moodle_exception('ntlmsso_isdisabled', 'auth_ldap');
  21  }
  22  
  23  $sesskey = required_param('sesskey', PARAM_RAW);
  24  $file = $CFG->dirroot.'/pix/spacer.gif';
  25  
  26  if ($authplugin->ntlmsso_magic($sesskey) && file_exists($file)) {
  27      if (!empty($authplugin->config->ntlmsso_ie_fastpath)) {
  28          if (core_useragent::is_ie()) {
  29              redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_finish.php');
  30          }
  31      }
  32  
  33      // Serve GIF
  34      // Type
  35      header('Content-Type: image/gif');
  36      header('Content-Length: '.filesize($file));
  37  
  38      // Output file
  39      $handle = fopen($file, 'r');
  40      fpassthru($handle);
  41      fclose($handle);
  42      exit;
  43  } else {
  44      throw new \moodle_exception('ntlmsso_iwamagicnotenabled', 'auth_ldap');
  45  }
  46  
  47