Page MenuHomePhabricator

LdapAuthentication-1.1b.php.diff

Authored By
• bzimport
Nov 21 2014, 7:04 PM
Size
3 KB
Referenced Files
None
Subscribers
None

LdapAuthentication-1.1b.php.diff

--- LdapAuthentication-1.1b.php 2006-12-13 16:04:38.000000000 +0000
+++ LdapNtlmAuthentication.php 2006-12-13 18:50:56.000000000 +0000
@@ -1,4 +1,12 @@
<?php
+# Modified to support transparent NTLM authentication
+# Alastair Hole <afhole@wortech.ac.uk>
+# Worcester College of Technology www.wortech.ac.uk
+#
+# NTLM components taken from: Id: Auth_remoteuser.php,v 1.1 2006/01/14 02:01:41 otheus
+# See http://meta.wikimedia.org/wiki/User:Otheus/Auto_Login_via_REMOTE_USER/code
+#
+#
# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
# http://www.mediawiki.org/
#
@@ -45,11 +53,94 @@
require_once( 'AuthPlugin.php' );
+function Auth_remote_user_hook() {
+ global $wgUser;
+ global $wgRequest;
+ global $wgLDAPDomainNames;
+ global $_REQUEST;
+
+ // For a few special pages, don't do anything.
+ $title = $wgRequest->getVal('title') ;
+ if ($title == 'Special:Userlogout' || $title == 'Special:Userlogin') {
+ return;
+ }
+
+ // Do nothing if session is valid
+ $wgUser = User::loadFromSession();
+ if ($wgUser->isLoggedIn()) {
+ return;
+ }
+
+ //get username from ntlm/apache REMOTE_USER
+ $username = strtolower($_SERVER['REMOTE_USER']);
+
+ //remove the domain name from the domain\username pair
+ //NOTE: Strip slashes appears to be switched on
+ //so we haven't explode()ed by '\'
+ //let's hope no one has a domain name in their username!
+ foreach($wgLDAPDomainNames as $wgLDAPDomainName){
+ $username = str_replace(strtolower($wgLDAPDomainName), "", $username);
+ }
+
+ $u = User::newFromName( $username );
+ if (is_null($u)) {
+ # Invalid username or some other error -- force login, just return
+ return;
+ }
+
+ $wgUser = $u;
+ if ($u->getId() != 0) {
+ $_REQUEST['wpName'] = $username;
+ # also return, but user is know. set Cookies, et al
+ $wgUser->setCookies();
+ $wgUser->saveSettings();
+
+ return;
+ }
+
+
+ // Ok, now we need to create a user.
+
+ include 'includes/SpecialUserlogin.php';
+ $form = new LoginForm( $wgRequest );
+ $form->initUser( $wgUser );
+ $wgUser->saveSettings();
+
+ // if it worked: refer to login page, otherwise, exit
+
+ header( "Location: http" .
+ (isset($_SERVER['HTTPS'])
+ && $_SERVER['HTTPS'] == "on" ? "s" : "") .
+ "://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] .
+ "/" .
+ ( isset($_SERVER['URL']) ? $_SERVER['PATH_INFO'] .
+ ( $_SERVER['QUERY_STRING'] ? "?" . $_SERVER['QUERY_STRING'] : "" )
+ : "" )
+ );
+
+ // Now redirect to referred page
+ // print("Done");
+ return;
+}
+
class LdapAuthenticationPlugin extends AuthPlugin {
var $email, $lang, $realname, $nickname, $SearchType;
var $LDAPUsername;
function LdapAuthenticationPlugin() {
+ global $wgLDAPUseNTLM;
+ if ($wgLDAPUseNTLM){
+ if ( strlen($_SERVER['REMOTE_USER']) ) {
+ global $wgExtensionFunctions;
+ if (!isset($wgExtensionFunctions)) {
+ $wgExtensionFunctions = array();
+ } else if (!is_array($wgExtensionFunctions)) {
+ $wgExtensionFunctions = array( $wgExtensionFunctions );
+ }
+ array_push($wgExtensionFunctions, 'Auth_remote_user_hook');
+ }
+ return;
+ }
}
/**

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1277
Default Alt Text
LdapAuthentication-1.1b.php.diff (3 KB)

Event Timeline