Merge branch 'MDL-32777' of git://github.com/danpoltawski/moodle
[moodle.git] / auth / ldap / ntlmsso_magic.php
blob9c74f87c93a46474f08752aee3bbff16cafe1671
1 <?php
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);
9 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
11 //HTTPS is required in this page when $CFG->loginhttps enabled
12 $PAGE->https_required();
14 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
16 $authsequence = get_enabled_auth_plugins(true); // auths, in sequence
17 if (!in_array('ldap', $authsequence, true)) {
18 print_error('ldap_isdisabled', 'auth');
21 $authplugin = get_auth_plugin('ldap');
22 if (empty($authplugin->config->ntlmsso_enabled)) {
23 print_error('ntlmsso_isdisabled', 'auth_ldap');
26 $sesskey = required_param('sesskey', PARAM_RAW);
27 $file = $CFG->dirroot.'/pix/spacer.gif';
29 if ($authplugin->ntlmsso_magic($sesskey) && file_exists($file)) {
30 if (!empty($authplugin->config->ntlmsso_ie_fastpath)) {
31 if (check_browser_version('MSIE')) {
32 redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_finish.php');
36 // Serve GIF
37 // Type
38 header('Content-Type: image/gif');
39 header('Content-Length: '.filesize($file));
41 // Output file
42 $handle = fopen($file, 'r');
43 fpassthru($handle);
44 fclose($handle);
45 exit;
46 } else {
47 print_error('ntlmsso_iwamagicnotenabled', 'auth_ldap');