r26013 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26012‎ | r26013 | r26014 >
Date:21:00, 21 September 2007
Author:laner
Status:old
Tags:
Comment:
* Fixed compatability with php4 (MediaWiki 1.6) - Patch from Bill Allison
* Only call getAllGroups() if $wgLDAPGroupsPrevail is enabled
* Added option $wgLDAPLocallyManagedGroups, to specify which groups won't have members automatically removed
** The sysop, bureaucrat, and bot groups are always considered locally managed
* Fixed security issue where users weren't removed from groups when the LDAP group was deleted
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -43,17 +43,17 @@
4444
4545 require_once( 'AuthPlugin.php' );
4646
47 -class LdapAuthenticationPlugin extends AuthPlugin {
 47+//constants for search base
 48+define("GROUPDN", 0);
 49+define("USERDN", 1);
 50+define("DEFAULTDN", 2);
4851
49 - //constants for search base
50 - const GROUPDN = 0;
51 - const USERDN = 1;
52 - const DEFAULTDN = 2;
 52+//constants for error reporting
 53+define("NONSENSITIVE", 1);
 54+define("SENSITIVE", 2);
 55+define("HIGHLYSENSITIVE", 3);
5356
54 - //constants for error reporting
55 - const NONSENSITIVE = 1;
56 - const SENSITIVE = 2;
57 - const HIGHLYSENSITIVE = 3;
 57+class LdapAuthenticationPlugin extends AuthPlugin {
5858
5959 //preferences
6060 var $email, $lang, $realname, $nickname, $externalid;
@@ -65,6 +65,9 @@
6666 var $userLDAPGroups, $foundUserLDAPGroups;
6767 var $allLDAPGroups;
6868
 69+ //boolean to test for failed auth
 70+ var $authFailed;
 71+
6972 function LdapAuthenticationPlugin() {
7073 }
7174
@@ -81,7 +84,7 @@
8285 function userExists( $username ) {
8386 global $wgLDAPAddLDAPUsers;
8487
85 - $this->printDebug( "Entering userExists", self::NONSENSITIVE );
 88+ $this->printDebug( "Entering userExists", NONSENSITIVE );
8689
8790 //If we can't add LDAP users, we don't really need to check
8891 //if the user exists, the authenticate method will do this for
@@ -93,7 +96,7 @@
9497
9598 $ldapconn = $this->connect();
9699 if ( $ldapconn ) {
97 - $this->printDebug( "Successfully connected", self::NONSENSITIVE );
 100+ $this->printDebug( "Successfully connected", NONSENSITIVE );
98101
99102 $searchstring = $this->getSearchString( $ldapconn, $username );
100103
@@ -113,14 +116,14 @@
114117 //Let's clean up
115118 @ldap_unbind();
116119 if ( !$entry ) {
117 - $this->printDebug( "Did not find a matching user in LDAP", self::NONSENSITIVE );
 120+ $this->printDebug( "Did not find a matching user in LDAP", NONSENSITIVE );
118121 return false;
119122 } else {
120 - $this->printDebug( "Found a matching user in LDAP", self::NONSENSITIVE );
 123+ $this->printDebug( "Found a matching user in LDAP", NONSENSITIVE );
121124 return true;
122125 }
123126 } else {
124 - $this->printDebug( "Failed to connect", self::NONSENSITIVE );
 127+ $this->printDebug( "Failed to connect", NONSENSITIVE );
125128 return false;
126129 }
127130
@@ -137,11 +140,10 @@
138141 global $wgLDAPEncryptionType;
139142 global $wgLDAPOptions;
140143
141 - $this->printDebug( "Entering Connect", self::NONSENSITIVE );
 144+ $this->printDebug( "Entering Connect", NONSENSITIVE );
142145
143146 if ( !extension_loaded( 'ldap' ) ) {
144 - $this->printDebug( "Missing LDAP support; please ensure you have either compiled LDAP support in, or have enabled the module.", self::SENSITIVE );
145 - return;
 147+ $this->printDebug( "It looks like you are issing LDAP support; please ensure you have either compiled LDAP support in, or have enabled the module. If the authentication is working for you, the plugin isn't properly detecting the LDAP module, and you can safely ignore this message.", NONSENSITIVE );
146148 }
147149
148150 //If the admin didn't set an encryption type, we default to tls
@@ -154,11 +156,11 @@
155157 //Set the server string depending on whether we use ssl or not
156158 switch( $encryptionType ) {
157159 case "ssl":
158 - $this->printDebug( "Using SSL", self::SENSITIVE );
 160+ $this->printDebug( "Using SSL", SENSITIVE );
159161 $serverpre = "ldaps://";
160162 break;
161163 default:
162 - $this->printDebug( "Using TLS or not using encryption.", self::SENSITIVE );
 164+ $this->printDebug( "Using TLS or not using encryption.", SENSITIVE );
163165 $serverpre = "ldap://";
164166 }
165167
@@ -173,7 +175,7 @@
174176 }
175177 $servers = rtrim($servers);
176178
177 - $this->printDebug( "Using servers: $servers", self::SENSITIVE );
 179+ $this->printDebug( "Using servers: $servers", SENSITIVE );
178180
179181 //Connect and set options
180182 $ldapconn = @ldap_connect( $servers );
@@ -191,9 +193,9 @@
192194
193195 //TLS needs to be started after the connection is made
194196 if ( $encryptionType == "tls" ) {
195 - $this->printDebug( "Using TLS", self::SENSITIVE );
 197+ $this->printDebug( "Using TLS", SENSITIVE );
196198 if ( !ldap_start_tls( $ldapconn ) ) {
197 - $this->printDebug( "Failed to start TLS.", self::SENSITIVE );
 199+ $this->printDebug( "Failed to start TLS.", SENSITIVE );
198200 return;
199201 }
200202 }
@@ -223,12 +225,14 @@
224226 global $wgLDAPLowerCaseUsername;
225227 global $wgLDAPSearchStrings;
226228 global $wgLDAPUniqueAttribute, $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
 229+ global $wgLDAPGroupsPrevail;
227230
228 - $this->printDebug( "Entering authenticate", self::NONSENSITIVE );
 231+ $this->printDebug( "Entering authenticate", NONSENSITIVE );
229232
230233 //We don't handle local authentication
231234 if ( 'local' == $_SESSION['wsDomain'] ) {
232 - $this->printDebug( "User is using a local domain", self::SENSITIVE );
 235+ $this->printDebug( "User is using a local domain", SENSITIVE );
 236+ $this->cleanupFailedAuth();
233237 return false;
234238 }
235239
@@ -236,7 +240,8 @@
237241 //that he/she isn't trying to fool us by sending a username other
238242 //than the one the web server got from the smartcard.
239243 if ( $this->useSmartcardAuth() && $wgLDAPSSLUsername != $username ) {
240 - $this->printDebug( "The username provided doesn't match the username on the smartcard. The user is probably trying to log in to the smartcard domain with password authentication. Denying access.", self::SENSITIVE );
 244+ $this->printDebug( "The username provided doesn't match the username on the smartcard. The user is probably trying to log in to the smartcard domain with password authentication. Denying access.", SENSITIVE );
 245+ $this->cleanupFailedAuth();
241246 return false;
242247 }
243248
@@ -246,20 +251,21 @@
247252 //Smartcard authentication uses a pin, and does not require
248253 //a password to be given; a blank password here is wanted.
249254 if ( '' == $password && !$this->useSmartcardAuth() ) {
250 - $this->printDebug( "User used a blank password", self::NONSENSITIVE );
 255+ $this->printDebug( "User used a blank password", NONSENSITIVE );
 256+ $this->cleanupFailedAuth();
251257 return false;
252258 }
253259
254260 $ldapconn = $this->connect();
255261 if ( $ldapconn ) {
256 - $this->printDebug( "Connected successfully", self::NONSENSITIVE );
 262+ $this->printDebug( "Connected successfully", NONSENSITIVE );
257263
258264 //Mediawiki munges the username before authenticate is called,
259265 //this can mess with authentication, group pulling/restriction,
260266 //preference pulling, etc. Let's allow the admin to use
261267 //a lowercased username if needed.
262268 if ( isset( $wgLDAPLowerCaseUsername[$_SESSION['wsDomain']] ) && $wgLDAPLowerCaseUsername[$_SESSION['wsDomain']] ) {
263 - $this->printDebug( "Lowercasing the username: $username", self::NONSENSITIVE );
 269+ $this->printDebug( "Lowercasing the username: $username", NONSENSITIVE );
264270 $username = strtolower( $username );
265271 }
266272
@@ -269,25 +275,27 @@
270276 //empty string; if this happens, the bind will ALWAYS
271277 //return true, and will let anyone in!
272278 if ( '' == $userdn ) {
273 - $this->printDebug( "User DN is blank", self::NONSENSITIVE );
 279+ $this->printDebug( "User DN is blank", NONSENSITIVE );
274280 // Lets clean up.
275281 @ldap_unbind();
 282+ $this->cleanupFailedAuth();
276283 return false;
277284 }
278285
279286 //If we are using password authentication, we need to bind as the
280287 //user to make sure the password is correct.
281288 if ( !$this->useSmartcardAuth() ) {
282 - $this->printDebug( "Binding as the user", self::NONSENSITIVE );
 289+ $this->printDebug( "Binding as the user", NONSENSITIVE );
283290
284291 //Let's see if the user can authenticate.
285292 $bind = $this->bindAs( $ldapconn, $userdn, $password );
286293 if ( !$bind ) {
287294 // Lets clean up.
288295 @ldap_unbind();
 296+ $this->cleanupFailedAuth();
289297 return false;
290298 }
291 - $this->printDebug( "Bound successfully", self::NONSENSITIVE );
 299+ $this->printDebug( "Bound successfully", NONSENSITIVE );
292300
293301 if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
294302 $ss = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
@@ -296,14 +304,14 @@
297305 //DOMAIN\\USER-NAME.
298306 //Get the user's full DN so we can search for groups and such.
299307 $userdn = $this->getUserDN( $ldapconn, $username );
300 - $this->printDebug( "Pulled the user's DN: $userdn", self::NONSENSITIVE );
 308+ $this->printDebug( "Pulled the user's DN: $userdn", NONSENSITIVE );
301309 }
302310 }
303311
304312 if ( ( isset( $wgLDAPRequireAuthAttribute[$_SESSION['wsDomain']] )
305313 && $wgLDAPRequireAuthAttribute[$_SESSION['wsDomain']] ) ) {
306314
307 - $this->printDebug( "Checking for auth attributes", self::NONSENSITIVE );
 315+ $this->printDebug( "Checking for auth attributes", NONSENSITIVE );
308316
309317 $filter = "(" . $wgLDAPAuthAttribute[$_SESSION['wsDomain']] . ")";
310318 $attributes = array( "dn" );
@@ -312,9 +320,10 @@
313321 $info = ldap_get_entries( $ldapconn, $entry );
314322
315323 if ( $info["count"] < 1 ) {
316 - $this->printDebug( "Failed auth attribute check", self::NONSENSITIVE );
 324+ $this->printDebug( "Failed auth attribute check", NONSENSITIVE );
317325 // Lets clean up.
318326 @ldap_unbind();
 327+ $this->cleanupFailedAuth();
319328 return false;
320329 }
321330 }
@@ -323,20 +332,21 @@
324333 //Old style groups, non-nestable and fairly limited on group type (full DN
325334 //versus username). DEPRECATED
326335 if ( $wgLDAPGroupDN ) {
327 - $this->printDebug( "Checking for (old style) group membership", self::NONSENSITIVE );
 336+ $this->printDebug( "Checking for (old style) group membership", NONSENSITIVE );
328337 if ( !$this->isMemberOfLdapGroup( $ldapconn, $userdn, $wgLDAPGroupDN ) ) {
329 - $this->printDebug( "Failed (old style) group membership check", self::NONSENSITIVE );
 338+ $this->printDebug( "Failed (old style) group membership check", NONSENSITIVE );
330339
331340 //No point in going on if the user isn't in the required group
332341 // Lets clean up.
333342 @ldap_unbind();
 343+ $this->cleanupFailedAuth();
334344 return false;
335345 }
336346 }
337347
338348 //New style group checking
339349 if ( isset( $wgLDAPRequiredGroups[$_SESSION['wsDomain']] ) ) {
340 - $this->printDebug( "Checking for (new style) group membership", self::NONSENSITIVE );
 350+ $this->printDebug( "Checking for (new style) group membership", NONSENSITIVE );
341351
342352 if ( isset( $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) && $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) {
343353 $inGroup = $this->isMemberOfRequiredLdapGroup( $ldapconn, $userdn );
@@ -345,7 +355,7 @@
346356 && $wgLDAPGroupUseRetrievedUsername[$_SESSION['wsDomain']] )
347357 && $this->LDAPUsername != '' ) {
348358
349 - $this->printDebug( "Using the username retrieved from the user's entry.", self::NONSENSITIVE );
 359+ $this->printDebug( "Using the username retrieved from the user's entry.", NONSENSITIVE );
350360 $inGroup = $this->isMemberOfRequiredLdapGroup( $ldapconn, $this->LDAPUsername );
351361 } else {
352362 $inGroup = $this->isMemberOfRequiredLdapGroup( $ldapconn, $username );
@@ -355,6 +365,7 @@
356366 if ( !$inGroup ) {
357367 // Lets clean up.
358368 @ldap_unbind();
 369+ $this->cleanupFailedAuth();
359370 return false;
360371 }
361372
@@ -362,7 +373,7 @@
363374
364375 //Synch LDAP groups with MediaWiki groups
365376 if ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) {
366 - $this->printDebug( "Retrieving LDAP group membership", self::NONSENSITIVE );
 377+ $this->printDebug( "Retrieving LDAP group membership", NONSENSITIVE );
367378
368379 //Let's get the user's LDAP groups
369380 if ( isset( $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) && $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) {
@@ -379,14 +390,14 @@
380391
381392 //Only find all groups if the user has any groups; otherwise, we are
382393 //just wasting a search.
383 - if ( $this->foundUserLDAPGroups ) {
 394+ if ( $this->foundUserLDAPGroups && ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) ) {
384395 $this->allLDAPGroups = $this->getAllGroups( $ldapconn, true );
385396 }
386397 }
387398
388399 //Retrieve preferences
389400 if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
390 - $this->printDebug( "Retrieving preferences", self::NONSENSITIVE );
 401+ $this->printDebug( "Retrieving preferences", NONSENSITIVE );
391402
392403 $entry = @ldap_read( $ldapconn, $userdn, "objectclass=*" );
393404 $info = @ldap_get_entries( $ldapconn, $entry );
@@ -403,7 +414,7 @@
404415 $this->realname = $info[0]["cn"][0];
405416 }
406417
407 - $this->printDebug( "Retrieved: $this->email, $this->lang, $this->nickname, $this->realname", self::SENSITIVE );
 418+ $this->printDebug( "Retrieved: $this->email, $this->lang, $this->nickname, $this->realname", SENSITIVE );
408419 }
409420
410421 // Are we blocking login/renaming users on unique external ID mismatches?
@@ -416,7 +427,7 @@
417428 if ( ( isset( $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] ) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] )
418429 || ( isset( $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) ) {
419430
420 - $this->printDebug( "Checking for username change in LDAP.", self::SENSITIVE );
 431+ $this->printDebug( "Checking for username change in LDAP.", SENSITIVE );
421432
422433 //Get the user's unique attribute from LDAP
423434 if ( isset( $wgLDAPUniqueAttribute[$_SESSION['wsDomain']] ) ) {
@@ -424,26 +435,27 @@
425436 $this->externalid = $info[0][$ldapuniqueattr][0];
426437 }
427438
428 - $this->printDebug( "Retrieved external id: $this->externalid", self::SENSITIVE );
 439+ $this->printDebug( "Retrieved external id: $this->externalid", SENSITIVE );
429440
430441 $retrievedusername = User::whoIsExternalID( "$this->externalid" );
431442
432 - $this->printDebug( "Username (in MediaWiki database) of fetched external id: $retrievedusername", self::SENSITIVE );
 443+ $this->printDebug( "Username (in MediaWiki database) of fetched external id: $retrievedusername", SENSITIVE );
433444
434445 // See if the username returned from the database matches the username given
435446 if ( $retrievedusername != '' && ( $username != $retrievedusername ) ) {
436447 if ( isset( $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] )
437448 && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] ) {
438449
439 - $this->printDebug( "Usernames do not match, blocking login.", self::SENSITIVE );
 450+ $this->printDebug( "Usernames do not match, blocking login.", SENSITIVE );
440451 return false;
441452 } else if ( isset( $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] )
442453 && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) {
443454
444 - $this->printDebug( "Usernames do not match, renaming user in database.", self::SENSITIVE );
 455+ $this->printDebug( "Usernames do not match, renaming user in database.", SENSITIVE );
445456
446457 if ( version_compare( $wgVersion, '1.7.0', '<' ) ) {
447 - $this->printDebug( "Renaming users is only supported in MediaWiki 1.7+, please upgrade.", self::SENSITIVE );
 458+ $this->printDebug( "Renaming users is only supported in MediaWiki 1.7+, please upgrade.", SENSITIVE );
 459+ $this->cleanupFailedAuth();
448460 return false;
449461 }
450462
@@ -463,25 +475,31 @@
464476 // as MediaWiki will try to create the user account after we
465477 // do a rename. If we don't return false, the user will get
466478 // a database error
 479+ $this->cleanupFailedAuth();
467480 return false;
468481 }
469482 }
470483
471 - $this->printDebug( "Usernames matched or the user doesn't exist in the database yet.", self::SENSITIVE );
 484+ $this->printDebug( "Usernames matched or the user doesn't exist in the database yet.", SENSITIVE );
472485 }
473486
474487 // Lets clean up.
475488 @ldap_unbind();
476489 } else {
477 - $this->printDebug( "Failed to connect", self::NONSENSITIVE );
 490+ $this->printDebug( "Failed to connect", NONSENSITIVE );
 491+ $this->cleanupFailedAuth();
478492 return false;
479493 }
480 - $this->printDebug( "Authentication passed", self::NONSENSITIVE );
 494+ $this->printDebug( "Authentication passed", NONSENSITIVE );
481495
482496 //We made it this far; the user authenticated and didn't fail any checks, so he/she gets in.
483497 return true;
484498 }
485499
 500+ function cleanupFailedAuth() {
 501+ $this->authFailed = true;
 502+ }
 503+
486504 /**
487505 * Modify options in the login template.
488506 *
@@ -493,7 +511,7 @@
494512 global $wgLDAPAddLDAPUsers;
495513 global $wgLDAPUseSmartcardAuth, $wgLDAPSmartcardDomain;
496514
497 - $this->printDebug( "Entering modifyUITemplate", self::NONSENSITIVE );
 515+ $this->printDebug( "Entering modifyUITemplate", NONSENSITIVE );
498516
499517 if ( !isset( $wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) || !$wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) {
500518 $template->set( 'create', false );
@@ -504,12 +522,12 @@
505523
506524 $tempDomArr = $wgLDAPDomainNames;
507525 if ( $wgLDAPUseLocal ) {
508 - $this->printDebug( "Allowing the local domain, adding it to the list.", self::NONSENSITIVE );
 526+ $this->printDebug( "Allowing the local domain, adding it to the list.", NONSENSITIVE );
509527 array_push( $tempDomArr, 'local' );
510528 }
511529
512530 if ( $wgLDAPUseSmartcardAuth ) {
513 - $this->printDebug( "Allowing smartcard login, removing the domain from the list.", self::NONSENSITIVE );
 531+ $this->printDebug( "Allowing smartcard login, removing the domain from the list.", NONSENSITIVE );
514532
515533 //There is no reason for people to log in directly to the wiki if the are using a
516534 //smartcard. If they try to, they are probably up to something fishy.
@@ -551,23 +569,23 @@
552570 function setPassword( $user, &$password ) {
553571 global $wgLDAPUpdateLDAP, $wgLDAPWriterDN, $wgLDAPWriterPassword;
554572
555 - $this->printDebug( "Entering setPassword", self::NONSENSITIVE );
 573+ $this->printDebug( "Entering setPassword", NONSENSITIVE );
556574
557575 if ( $_SESSION['wsDomain'] == 'local' ) {
558 - $this->printDebug( "User is using a local domain", self::NONSENSITIVE );
 576+ $this->printDebug( "User is using a local domain", NONSENSITIVE );
559577
560578 //We don't set local passwords, but we don't want the wiki
561579 //to send the user a failure.
562580 return true;
563581 } else if ( !isset( $wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) || !$wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) {
564 - $this->printDebug( "Wiki is set to not allow updates", self::NONSENSITIVE );
 582+ $this->printDebug( "Wiki is set to not allow updates", NONSENSITIVE );
565583
566584 //We aren't allowing the user to change his/her own password
567585 return false;
568586 }
569587
570588 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
571 - $this->printDebug( "Wiki doesn't have wgLDAPWriterDN set", self::NONSENSITIVE );
 589+ $this->printDebug( "Wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE );
572590
573591 //We can't change a user's password without an account that is
574592 //allowed to do it.
@@ -578,10 +596,10 @@
579597
580598 $ldapconn = $this->connect();
581599 if ( $ldapconn ) {
582 - $this->printDebug( "Connected successfully", self::NONSENSITIVE );
 600+ $this->printDebug( "Connected successfully", NONSENSITIVE );
583601 $userdn = $this->getSearchString( $ldapconn, $user->getName() );
584602
585 - $this->printDebug( "Binding as the writerDN", self::NONSENSITIVE );
 603+ $this->printDebug( "Binding as the writerDN", NONSENSITIVE );
586604 $bind = $this->bindAs( $ldapconn, $wgLDAPWriterDN[$_SESSION['wsDomain']], $wgLDAPWriterPassword[$_SESSION['wsDomain']] );
587605 if ( !$bind ) {
588606 return false;
@@ -598,14 +616,14 @@
599617 //Let's clean up
600618 @ldap_unbind();
601619 if ( $success ) {
602 - $this->printDebug( "Successfully modified the user's password", self::NONSENSITIVE );
 620+ $this->printDebug( "Successfully modified the user's password", NONSENSITIVE );
603621 return true;
604622 } else {
605 - $this->printDebug( "Failed to modify the user's password", self::NONSENSITIVE );
 623+ $this->printDebug( "Failed to modify the user's password", NONSENSITIVE );
606624 return false;
607625 }
608626 } else {
609 - $this->printDebug( "Failed to connect", self::NONSENSITIVE );
 627+ $this->printDebug( "Failed to connect", NONSENSITIVE );
610628 return false;
611629 }
612630 }
@@ -622,11 +640,11 @@
623641 global $wgLDAPUpdateLDAP;
624642 global $wgLDAPWriterDN, $wgLDAPWriterPassword;
625643
626 - $this->printDebug( "Entering updateExternalDB", self::NONSENSITIVE );
 644+ $this->printDebug( "Entering updateExternalDB", NONSENSITIVE );
627645
628646 if ( ( !isset( $wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) || !$wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) ||
629647 $_SESSION['wsDomain'] == 'local' ) {
630 - $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing updates", self::NONSENSITIVE );
 648+ $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing updates", NONSENSITIVE );
631649
632650 //We don't handle local preferences, but we don't want the
633651 //wiki to return an error.
@@ -634,7 +652,7 @@
635653 }
636654
637655 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
638 - $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", self::NONSENSITIVE );
 656+ $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE );
639657
640658 //We can't modify LDAP preferences if we don't have a user
641659 //capable of editing LDAP attributes.
@@ -648,10 +666,10 @@
649667
650668 $ldapconn = $this->connect();
651669 if ( $ldapconn ) {
652 - $this->printDebug( "Connected successfully", self::NONSENSITIVE );
 670+ $this->printDebug( "Connected successfully", NONSENSITIVE );
653671 $userdn = $this->getSearchString( $ldapconn, $user->getName() );
654672
655 - $this->printDebug( "Binding as the writerDN", self::NONSENSITIVE );
 673+ $this->printDebug( "Binding as the writerDN", NONSENSITIVE );
656674 $bind = $this->bindAs( $ldapconn, $wgLDAPWriterDN[$_SESSION['wsDomain']], $wgLDAPWriterPassword[$_SESSION['wsDomain']] );
657675 if ( !$bind ) {
658676 return false;
@@ -663,16 +681,16 @@
664682 if ( '' != $this->language ) { $values["preferredlanguage"] = $this->language; }
665683
666684 if ( 0 != sizeof( $values ) && ldap_modify( $ldapconn, $userdn, $values ) ) {
667 - $this->printDebug( "Successfully modified the user's attributes", self::NONSENSITIVE );
 685+ $this->printDebug( "Successfully modified the user's attributes", NONSENSITIVE );
668686 @ldap_unbind();
669687 return true;
670688 } else {
671 - $this->printDebug( "Failed to modify the user's attributes", self::NONSENSITIVE );
 689+ $this->printDebug( "Failed to modify the user's attributes", NONSENSITIVE );
672690 @ldap_unbind();
673691 return false;
674692 }
675693 } else {
676 - $this->printDebug( "Failed to Connect", self::NONSENSITIVE );
 694+ $this->printDebug( "Failed to Connect", NONSENSITIVE );
677695 return false;
678696 }
679697 }
@@ -740,18 +758,18 @@
741759 global $wgLDAPRequiredGroups, $wgLDAPGroupDN;
742760 global $wgLDAPRequireAuthAttribute, $wgLDAPAuthAttribute;
743761
744 - $this->printDebug( "Entering addUser", self::NONSENSITIVE );
 762+ $this->printDebug( "Entering addUser", NONSENSITIVE );
745763
746764 if ( ( !isset( $wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) || !$wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) ||
747765 'local' == $_SESSION['wsDomain'] ) {
748 - $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing users to be added to LDAP", self::NONSENSITIVE );
 766+ $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing users to be added to LDAP", NONSENSITIVE );
749767
750768 //Tell the wiki not to return an error.
751769 return true;
752770 }
753771
754772 if ( $wgLDAPRequiredGroups || $wgLDAPGroupDN ) {
755 - $this->printDebug( "The wiki is requiring users to be in specific groups, and cannot add users as this would be a security hole.", self::NONSENSITIVE );
 773+ $this->printDebug( "The wiki is requiring users to be in specific groups, and cannot add users as this would be a security hole.", NONSENSITIVE );
756774 //It is possible that later we can add users into
757775 //groups, but since we don't support it, we don't want
758776 //to open holes!
@@ -759,7 +777,7 @@
760778 }
761779
762780 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
763 - $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", self::NONSENSITIVE );
 781+ $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE );
764782
765783 //We can't add users without an LDAP account capable of doing so.
766784 return false;
@@ -773,28 +791,28 @@
774792
775793 $ldapconn = $this->connect();
776794 if ( $ldapconn ) {
777 - $this->printDebug( "Successfully connected", self::NONSENSITIVE );
 795+ $this->printDebug( "Successfully connected", NONSENSITIVE );
778796
779797 $userdn = $this->getSearchString( $ldapconn, $username );
780798 if ( '' == $userdn ) {
781 - $this->printDebug( "userdn is blank, attempting to use wgLDAPWriteLocation", self::NONSENSITIVE );
 799+ $this->printDebug( "userdn is blank, attempting to use wgLDAPWriteLocation", NONSENSITIVE );
782800 if ( isset( $wgLDAPWriteLocation[$_SESSION['wsDomain']] ) ) {
783 - $this->printDebug( "wgLDAPWriteLocation is set, using that", self::NONSENSITIVE );
 801+ $this->printDebug( "wgLDAPWriteLocation is set, using that", NONSENSITIVE );
784802 $userdn = $wgLDAPSearchAttributes[$_SESSION['wsDomain']] . "=" .
785803 $username . $wgLDAPWriteLocation[$_SESSION['wsDomain']];
786804 } else {
787 - $this->printDebug( "wgLDAPWriteLocation is not set, failing", self::NONSENSITIVE );
 805+ $this->printDebug( "wgLDAPWriteLocation is not set, failing", NONSENSITIVE );
788806 //getSearchString will bind, but will not unbind
789807 @ldap_unbind();
790808 return false;
791809 }
792810 }
793811
794 - $this->printDebug( "Binding as the writerDN", self::NONSENSITIVE );
 812+ $this->printDebug( "Binding as the writerDN", NONSENSITIVE );
795813
796814 $bind = $this->bindAs( $ldapconn, $wgLDAPWriterDN[$_SESSION['wsDomain']], $wgLDAPWriterPassword[$_SESSION['wsDomain']] );
797815 if ( !$bind ) {
798 - $this->printDebug( "Failed to bind as the writerDN; add failed", self::NONSENSITIVE );
 816+ $this->printDebug( "Failed to bind as the writerDN; add failed", NONSENSITIVE );
799817 return false;
800818 }
801819
@@ -812,18 +830,18 @@
813831 $values[$wgLDAPAuthAttribute[$_SESSION['wsDomain']]] = "true";
814832 }
815833
816 - $this->printDebug( "Adding user", self::NONSENSITIVE );
 834+ $this->printDebug( "Adding user", NONSENSITIVE );
817835 if ( @ldap_add( $ldapconn, $userdn, $values ) ) {
818 - $this->printDebug( "Successfully added user", self::NONSENSITIVE );
 836+ $this->printDebug( "Successfully added user", NONSENSITIVE );
819837 @ldap_unbind();
820838 return true;
821839 } else {
822 - $this->printDebug( "Failed to add user", self::NONSENSITIVE );
 840+ $this->printDebug( "Failed to add user", NONSENSITIVE );
823841 @ldap_unbind();
824842 return false;
825843 }
826844 } else {
827 - $this->printDebug( "Failed to connect; add failed", self::NONSENSITIVE );
 845+ $this->printDebug( "Failed to connect; add failed", NONSENSITIVE );
828846 return false;
829847 }
830848 }
@@ -835,7 +853,7 @@
836854 * @access public
837855 */
838856 function setDomain( $domain ) {
839 - $this->printDebug( "Setting domain as: $domain", self::NONSENSITIVE );
 857+ $this->printDebug( "Setting domain as: $domain", NONSENSITIVE );
840858 $_SESSION['wsDomain'] = $domain;
841859 }
842860
@@ -850,13 +868,13 @@
851869 function validDomain( $domain ) {
852870 global $wgLDAPDomainNames, $wgLDAPUseLocal;
853871
854 - $this->printDebug( "Entering validDomain", self::NONSENSITIVE );
 872+ $this->printDebug( "Entering validDomain", NONSENSITIVE );
855873
856874 if ( in_array( $domain, $wgLDAPDomainNames ) || ( $wgLDAPUseLocal && 'local' == $domain ) ) {
857 - $this->printDebug( "User is using a valid domain.", self::NONSENSITIVE );
 875+ $this->printDebug( "User is using a valid domain.", NONSENSITIVE );
858876 return true;
859877 } else {
860 - $this->printDebug( "User is not using a valid domain.", self::NONSENSITIVE );
 878+ $this->printDebug( "User is not using a valid domain.", NONSENSITIVE );
861879 return false;
862880 }
863881 }
@@ -873,14 +891,19 @@
874892 global $wgLDAPUseLDAPGroups;
875893 global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
876894
877 - $this->printDebug( "Entering updateUser", self::NONSENSITIVE );
 895+ $this->printDebug( "Entering updateUser", NONSENSITIVE );
878896
 897+ if ($this->authFailed) {
 898+ $this->printDebug( "User didn't successfully authenticate, exiting.", NONSENSITIVE );
 899+ return;
 900+ }
 901+
879902 $saveSettings = false;
880903
881904 //If we aren't pulling preferences, we don't want to accidentally
882905 //overwrite anything.
883906 if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
884 - $this->printDebug( "Setting user preferences.", self::NONSENSITIVE );
 907+ $this->printDebug( "Setting user preferences.", NONSENSITIVE );
885908
886909 if ( '' != $this->lang ) {
887910 $user->setOption( 'language', $this->lang );
@@ -906,14 +929,14 @@
907930 }
908931
909932 if ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) {
910 - $this->printDebug( "Setting user groups.", self::NONSENSITIVE );
 933+ $this->printDebug( "Setting user groups.", NONSENSITIVE );
911934 $this->setGroups( $user );
912935
913936 $saveSettings = true;
914937 }
915938
916939 if ( $saveSettings ) {
917 - $this->printDebug( "Saving user settings.", self::NONSENSITIVE );
 940+ $this->printDebug( "Saving user settings.", NONSENSITIVE );
918941 $user->saveSettings();
919942 }
920943 }
@@ -928,10 +951,15 @@
929952 function initUser( &$user ) {
930953 global $wgLDAPUseLDAPGroups;
931954
932 - $this->printDebug( "Entering initUser", self::NONSENSITIVE );
 955+ $this->printDebug( "Entering initUser", NONSENSITIVE );
933956
 957+ if ($this->authFailed) {
 958+ $this->printDebug( "User didn't successfully authenticate, exiting.", NONSENSITIVE );
 959+ return;
 960+ }
 961+
934962 if ( 'local' == $_SESSION['wsDomain'] ) {
935 - $this->printDebug( "User is using a local domain", self::NONSENSITIVE );
 963+ $this->printDebug( "User is using a local domain", NONSENSITIVE );
936964 return;
937965 }
938966
@@ -959,13 +987,13 @@
960988 function strict() {
961989 global $wgLDAPUseLocal, $wgLDAPMailPassword;
962990
963 - $this->printDebug( "Entering strict.", self::NONSENSITIVE );
 991+ $this->printDebug( "Entering strict.", NONSENSITIVE );
964992
965993 if ( $wgLDAPUseLocal || $wgLDAPMailPassword ) {
966 - $this->printDebug( "Returning false in strict().", self::NONSENSITIVE );
 994+ $this->printDebug( "Returning false in strict().", NONSENSITIVE );
967995 return false;
968996 } else {
969 - $this->printDebug( "Returning true in strict().", self::NONSENSITIVE );
 997+ $this->printDebug( "Returning true in strict().", NONSENSITIVE );
970998 return true;
971999 }
9721000 }
@@ -980,15 +1008,15 @@
9811009 */
9821010 function getCanonicalName( $username ) {
9831011 global $wgLDAPUseLocal;
984 - $this->printDebug( "Entering getCanonicalName", self::NONSENSITIVE );
 1012+ $this->printDebug( "Entering getCanonicalName", NONSENSITIVE );
9851013
9861014 if ( $username != '' ) {
987 - $this->printDebug( "Username isn't empty.", self::NONSENSITIVE );
 1015+ $this->printDebug( "Username isn't empty.", NONSENSITIVE );
9881016
9891017 //We want to use the username returned by LDAP
9901018 //if it exists
9911019 if ( $this->LDAPUsername != '' ) {
992 - $this->printDebug( "Using LDAPUsername.", self::NONSENSITIVE );
 1020+ $this->printDebug( "Using LDAPUsername.", NONSENSITIVE );
9931021 $username = $this->LDAPUsername;
9941022 }
9951023
@@ -1004,7 +1032,7 @@
10051033 $username[0] = strtoupper( $username[0] );
10061034 }
10071035
1008 - $this->printDebug( "Munged username: $username", self::NONSENSITIVE );
 1036+ $this->printDebug( "Munged username: $username", NONSENSITIVE );
10091037
10101038 return $username;
10111039 }
@@ -1036,11 +1064,11 @@
10371065 global $wgLDAPSearchStrings;
10381066 global $wgLDAPProxyAgent, $wgLDAPProxyAgentPassword;
10391067
1040 - $this->printDebug( "Entering getSearchString", self::NONSENSITIVE );
 1068+ $this->printDebug( "Entering getSearchString", NONSENSITIVE );
10411069
10421070 if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
10431071 //This is a straight bind
1044 - $this->printDebug( "Doing a straight bind", self::NONSENSITIVE );
 1072+ $this->printDebug( "Doing a straight bind", NONSENSITIVE );
10451073
10461074 $tmpuserdn = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
10471075 $userdn = str_replace( "USER-NAME", $username, $tmpuserdn );
@@ -1048,22 +1076,22 @@
10491077 //This is a proxy bind, or an anonymous bind with a search
10501078 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
10511079 //This is a proxy bind
1052 - $this->printDebug( "Doing a proxy bind", self::NONSENSITIVE );
 1080+ $this->printDebug( "Doing a proxy bind", NONSENSITIVE );
10531081 $bind = $this->bindAs( $ldapconn, $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
10541082 } else {
10551083 //This is an anonymous bind
1056 - $this->printDebug( "Doing an anonymous bind", self::NONSENSITIVE );
 1084+ $this->printDebug( "Doing an anonymous bind", NONSENSITIVE );
10571085 $bind = $this->bindAs( $ldapconn );
10581086 }
10591087
10601088 if ( !$bind ) {
1061 - $this->printDebug( "Failed to bind", self::NONSENSITIVE );
 1089+ $this->printDebug( "Failed to bind", NONSENSITIVE );
10621090 return '';
10631091 }
10641092
10651093 $userdn = $this->getUserDN( $ldapconn, $username );
10661094 }
1067 - $this->printDebug( "userdn is: $userdn", self::SENSITIVE );
 1095+ $this->printDebug( "userdn is: $userdn", SENSITIVE );
10681096 return $userdn;
10691097 }
10701098
@@ -1081,7 +1109,7 @@
10821110 global $wgLDAPSearchAttributes;
10831111 global $wgLDAPRequireAuthAttribute, $wgLDAPAuthAttribute;
10841112
1085 - $this->printDebug("Entering getUserDN", self::NONSENSITIVE);
 1113+ $this->printDebug("Entering getUserDN", NONSENSITIVE);
10861114
10871115 //we need to do a subbase search for the entry
10881116
@@ -1091,20 +1119,20 @@
10921120 $auth_filter = "(" . $wgLDAPAuthAttribute[$_SESSION['wsDomain']] . ")";
10931121 $srch_filter = "(" . $wgLDAPSearchAttributes[$_SESSION['wsDomain']] . "=" . $this->getLdapEscapedString( $username ) . ")";
10941122 $filter = "(&" . $srch_filter . $auth_filter . ")";
1095 - $this->printDebug( "Created an auth attribute filter: $filter", self::SENSITIVE );
 1123+ $this->printDebug( "Created an auth attribute filter: $filter", SENSITIVE );
10961124 } else {
10971125 $filter = "(" . $wgLDAPSearchAttributes[$_SESSION['wsDomain']] . "=" . $this->getLdapEscapedString( $username ) . ")";
1098 - $this->printDebug( "Created a regular filter: $filter", self::SENSITIVE );
 1126+ $this->printDebug( "Created a regular filter: $filter", SENSITIVE );
10991127 }
11001128
11011129 $attributes = array( "*" );
1102 - $base = $this->getBaseDN( self::USERDN );
 1130+ $base = $this->getBaseDN( USERDN );
11031131
1104 - $this->printDebug( "Using base: $base", self::SENSITIVE );
 1132+ $this->printDebug( "Using base: $base", SENSITIVE );
11051133
11061134 $entry = @ldap_search( $ldapconn, $base, $filter, $attributes );
11071135 if ( !$entry ) {
1108 - $this->printDebug( "Couldn't find an entry", self::NONSENSITIVE );
 1136+ $this->printDebug( "Couldn't find an entry", NONSENSITIVE );
11091137 return '';
11101138 }
11111139
@@ -1114,7 +1142,7 @@
11151143 //group checking, and pulling preferences.
11161144 wfRunHooks( 'SetUsernameAttributeFromLDAP', array( &$this->LDAPUsername, $info ) );
11171145 if ( !is_string( $this->LDAPUsername ) ) {
1118 - $this->printDebug( "Fetched username is not a string (check your hook code...). This message can be safely ignored if you do not have the SetUsernameAttributeFromLDAP hook defined.", self::NONSENSITIVE );
 1146+ $this->printDebug( "Fetched username is not a string (check your hook code...). This message can be safely ignored if you do not have the SetUsernameAttributeFromLDAP hook defined.", NONSENSITIVE );
11191147 $this->LDAPUsername = '';
11201148 }
11211149
@@ -1124,7 +1152,7 @@
11251153
11261154 //DEPRECATED
11271155 function isMemberOfLdapGroup( $ldapconn, $userDN, $groupDN ) {
1128 - $this->printDebug( "Entering isMemberOfLdapGroup (DEPRECATED)", self::NONSENSITIVE );
 1156+ $this->printDebug( "Entering isMemberOfLdapGroup (DEPRECATED)", NONSENSITIVE );
11291157
11301158 //we need to do a subbase search for the entry
11311159 $filter = "(member=" . $this->getLdapEscapedString( $userDN ) . ")";
@@ -1145,7 +1173,7 @@
11461174 global $wgLDAPRequiredGroups;
11471175 global $wgLDAPGroupSearchNestedGroups;
11481176
1149 - $this->printDebug( "Entering isMemberOfRequiredLdapGroup", self::NONSENSITIVE );
 1177+ $this->printDebug( "Entering isMemberOfRequiredLdapGroup", NONSENSITIVE );
11501178
11511179 $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']];
11521180 for ( $i = 0; $i < count( $reqgroups ); $i++ ) {
@@ -1154,14 +1182,14 @@
11551183
11561184 $searchnested = $wgLDAPGroupSearchNestedGroups[$_SESSION['wsDomain']];
11571185
1158 - $this->printDebug( "Required groups:" . implode( ",",$reqgroups ) . "", self::NONSENSITIVE );
 1186+ $this->printDebug( "Required groups:" . implode( ",",$reqgroups ) . "", NONSENSITIVE );
11591187
11601188 $groups = $this->getUserGroups( $ldapconn, $userDN );
11611189
11621190 //TODO: using variables for this kind of thing is dirty, let's think of a new way
11631191 // to handle this need.
11641192 if ( !$this->foundUserLDAPGroups ) {
1165 - $this->printDebug( "Couldn't find the user in any groups (1).", self::NONSENSITIVE );
 1193+ $this->printDebug( "Couldn't find the user in any groups (1).", NONSENSITIVE );
11661194
11671195 //User isn't in any groups, so he/she obviously can't be in
11681196 //a required one
@@ -1170,7 +1198,7 @@
11711199 //User is in groups, let's see if a required group is one of them
11721200 foreach ( $groups as $group ) {
11731201 if ( in_array( $group, $reqgroups ) ) {
1174 - $this->printDebug( "Found user in a group.", self::NONSENSITIVE );
 1202+ $this->printDebug( "Found user in a group.", NONSENSITIVE );
11751203 return true;
11761204 }
11771205 }
@@ -1182,7 +1210,7 @@
11831211 }
11841212 }
11851213
1186 - $this->printDebug( "Couldn't find the user in any groups (2).", self::NONSENSITIVE );
 1214+ $this->printDebug("Couldn't find the user in any groups (2).", NONSENSITIVE );
11871215
11881216 return false;
11891217 }
@@ -1202,15 +1230,15 @@
12031231 function searchNestedGroups( $ldapconn, $groups, $checkedgroups = array() ) {
12041232 global $wgLDAPRequiredGroups;
12051233
1206 - $this->printDebug( "Entering searchNestedGroups", self::NONSENSITIVE );
 1234+ $this->printDebug( "Entering searchNestedGroups", NONSENSITIVE );
12071235
12081236 //base case, no more groups left to check
12091237 if ( !$groups ) {
1210 - $this->printDebug( "Couldn't find user in any nested groups.", self::NONSENSITIVE );
 1238+ $this->printDebug( "Couldn't find user in any nested groups.", NONSENSITIVE );
12111239 return false;
12121240 }
12131241
1214 - $this->printDebug( "Checking groups:" . implode( ",", $groups ) . "", self::SENSITIVE );
 1242+ $this->printDebug( "Checking groups:" . implode( ",", $groups ) . "", SENSITIVE );
12151243
12161244 $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']];
12171245 for ( $i = 0; $i < count( $reqgroups ); $i++ ) {
@@ -1220,15 +1248,15 @@
12211249 $groupstocheck = array();
12221250 foreach ( $groups as $group ) {
12231251 $returnedgroups = $this->getUserGroups( $ldapconn, $group, false, false );
1224 - $this->printDebug( "Group $group is in the following groups:" . implode( ",", $returnedgroups ) . "", self::SENSITIVE );
 1252+ $this->printDebug( "Group $group is in the following groups:" . implode( ",", $returnedgroups ) . "", SENSITIVE );
12251253 foreach ( $returnedgroups as $checkme ) {
12261254 if ( in_array( $checkme, $checkedgroups ) ) {
12271255 //We already checked this, move on
12281256 continue;
12291257 }
1230 - $this->printDebug( "Checking membership for: $checkme", self::SENSITIVE );
 1258+ $this->printDebug( "Checking membership for: $checkme", SENSITIVE );
12311259 if ( in_array( $checkme, $reqgroups ) ) {
1232 - $this->printDebug( "Found user in a nested group.", self::NONSENSITIVE );
 1260+ $this->printDebug( "Found user in a nested group.", NONSENSITIVE );
12331261 //Woohoo
12341262 return true;
12351263 } else {
@@ -1255,17 +1283,17 @@
12561284 * @access private
12571285 */
12581286 function getUserGroups( $ldapconn, $dn, $getShortnames = false, $returncache = true ) {
1259 - $this->printDebug( "Entering getUserGroups", self::NONSENSITIVE );
 1287+ $this->printDebug( "Entering getUserGroups", NONSENSITIVE );
12601288
12611289 //Let's return the saved groups if they are available
12621290 if ( $getShortnames ) {
12631291 if ( $returncache && isset( $this->userLDAPShortnameGroupCache ) ) {
1264 - $this->printDebug( "Returning short name group cache.", self::NONSENSITIVE );
 1292+ $this->printDebug( "Returning short name group cache.", NONSENSITIVE );
12651293 return $this->userLDAPShortnameGroupCache;
12661294 }
12671295 } else {
12681296 if ( $returncache && isset( $this->userLDAPGroupCache ) ) {
1269 - $this->printDebug( "Returning long name group cache.", self::NONSENSITIVE );
 1297+ $this->printDebug( "Returning long name group cache.", NONSENSITIVE );
12701298 return $this->userLDAPGroupCache;
12711299 }
12721300 }
@@ -1304,7 +1332,8 @@
13051333
13061334 /**
13071335 * Helper function for retrieving all LDAP groups. Returns
1308 - * a list of all groups in the LDAP server, under the appropriate
 1336+ * a list of all groups in the LDAP server, that match available groups
 1337+ * the user is already joined to in MediaWiki, under the appropriate
13091338 * basedn, all munged to lowercase.
13101339 * Sets $this->foundAllLDAPGroups
13111340 *
@@ -1314,7 +1343,7 @@
13151344 * @access private
13161345 */
13171346 function getAllGroups( $ldapconn, $getShortnames = false ) {
1318 - $this->printDebug( "Entering getAllGroups", self::NONSENSITIVE );
 1347+ $this->printDebug( "Entering getAllGroups", NONSENSITIVE );
13191348
13201349 //Let's return the saved groups if they are available
13211350 if ( $getShortnames ) {
@@ -1361,10 +1390,11 @@
13621391 function getGroups( $ldapconn, $dn ) {
13631392 global $wgLDAPGroupObjectclass, $wgLDAPGroupAttribute, $wgLDAPGroupNameAttribute;
13641393 global $wgLDAPProxyAgent, $wgLDAPProxyAgentPassword;
 1394+ global $wgUser;
13651395
1366 - $this->printDebug( "Entering getGroups", self::NONSENSITIVE );
 1396+ $this->printDebug( "Entering getGroups", NONSENSITIVE );
13671397
1368 - $base = $this->getBaseDN( self::GROUPDN );
 1398+ $base = $this->getBaseDN( GROUPDN );
13691399
13701400 $objectclass = $wgLDAPGroupObjectclass[$_SESSION['wsDomain']];
13711401 $attribute = $wgLDAPGroupAttribute[$_SESSION['wsDomain']];
@@ -1374,21 +1404,22 @@
13751405 $value = $dn;
13761406 if ( $value != "*" )
13771407 $value = $this->getLdapEscapedString( $value );
 1408+
13781409 $filter = "(&($attribute=$value)(objectclass=$objectclass))";
13791410
1380 - $this->printDebug( "Search string: $filter", self::SENSITIVE );
 1411+ $this->printDebug( "Search string: $filter", SENSITIVE );
13811412
13821413 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
13831414 //We'll try to bind as the proxyagent as the proxyagent should normally have more
13841415 //rights than the user. If the proxyagent fails to bind, we will still be able
13851416 //to search as the normal user (which is why we don't return on fail).
1386 - $this->printDebug( "Binding as the proxyagentDN", self::NONSENSITIVE );
 1417+ $this->printDebug( "Binding as the proxyagentDN", NONSENSITIVE );
13871418 $bind = $this->bindAs( $ldapconn, $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
13881419 }
13891420
13901421 $info = @ldap_search( $ldapconn, $base, $filter );
13911422 if ( !$info ) {
1392 - $this->printDebug( "No entries returned from search.", self::SENSITIVE );
 1423+ $this->printDebug( "No entries returned from search.", SENSITIVE );
13931424
13941425 //Return an array with two empty arrays so that other functions
13951426 //don't error out.
@@ -1415,8 +1446,8 @@
14161447 array_push( $both_groups, $groups );
14171448 array_push( $both_groups, $shortnamegroups );
14181449
1419 - $this->printDebug( "Returned groups:" . implode( ",", $groups ) . "", self::SENSITIVE );
1420 - $this->printDebug( "Returned groups:" . implode( ",", $shortnamegroups ) . "", self::SENSITIVE );
 1450+ $this->printDebug( "Returned groups:" . implode( ",", $groups ) . "", SENSITIVE );
 1451+ $this->printDebug( "Returned groups:" . implode( ",", $shortnamegroups ) . "", SENSITIVE );
14211452
14221453 return $both_groups;
14231454 }
@@ -1430,7 +1461,7 @@
14311462 * @access private
14321463 */
14331464 function hasLDAPGroup( $group ) {
1434 - $this->printDebug( "Entering hasLDAPGroup", self::NONSENSITIVE );
 1465+ $this->printDebug( "Entering hasLDAPGroup", NONSENSITIVE );
14351466
14361467 return in_array( strtolower( $group ), $this->userLDAPGroups );
14371468 }
@@ -1443,7 +1474,7 @@
14441475 * @access private
14451476 */
14461477 function isLDAPGroup( $group ) {
1447 - $this->printDebug( "Entering isLDAPGroup", self::NONSENSITIVE );
 1478+ $this->printDebug( "Entering isLDAPGroup", NONSENSITIVE );
14481479
14491480 return in_array( strtolower( $group ), $this->allLDAPGroups );
14501481 }
@@ -1457,40 +1488,53 @@
14581489 */
14591490 function setGroups( &$user ) {
14601491 global $wgLDAPGroupsPrevail, $wgGroupPermissions;
 1492+ global $wgLDAPLocallyManagedGroups;
14611493
1462 - $this->printDebug( "Entering setGroups.", self::NONSENSITIVE );
 1494+ $this->printDebug( "Entering setGroups.", NONSENSITIVE );
14631495
14641496 # add groups permissions
14651497 $localAvailGrps = $user->getAllGroups();
14661498 $localUserGrps = $user->getEffectiveGroups();
 1499+
 1500+ $defaultLocallyManagedGrps = array( 'bot', 'sysop', 'bureaucrat' );
14671501
 1502+ if ( isset( $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']] ) ) {
 1503+ $locallyManagedGrps = $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']];
 1504+ $locallyManagedGrps = array_unique( array_merge( $defaultLocallyManagedGrps, $locallyManagedGrps ) );
 1505+ $this->printDebug( "Locally managed groups: " . implode( ",", $locallyManagedGrps ) . "", SENSITIVE );
 1506+ } else {
 1507+ $locallyManagedGrps = $defaultLocallyManagedGrps;
 1508+ $this->printDebug( "Locally managed groups is unset, using defaults: " . implode( ",", $locallyManagedGrps ) . "", SENSITIVE );
 1509+ }
 1510+
 1511+
14681512 # Add ldap groups as local groups
14691513 if ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) {
1470 - $this->printDebug( "Adding all groups to wgGroupPermissions: " . implode( ",", $this->allLDAPGroups ) . "", self::SENSITIVE );
 1514+ $this->printDebug( "Adding all groups to wgGroupPermissions: " . implode( ",", $this->allLDAPGroups ) . "", SENSITIVE );
14711515 foreach ( $this->allLDAPGroups as $ldapgroup )
14721516 if ( !array_key_exists( $ldapgroup, $wgGroupPermissions ) )
14731517 $wgGroupPermissions[$ldapgroup] = array();
14741518 }
14751519
1476 - $this->printDebug( "Available groups are: " . implode( ",", $localAvailGrps ) . "", self::NONSENSITIVE );
1477 - $this->printDebug( "Effective groups are: " . implode( ",", $localUserGrps ) . "", self::NONSENSITIVE );
 1520+ $this->printDebug( "Available groups are: " . implode( ",", $localAvailGrps ) . "", NONSENSITIVE );
 1521+ $this->printDebug( "Effective groups are: " . implode( ",", $localUserGrps ) . "", NONSENSITIVE );
14781522
14791523 # note: $localUserGrps does not need to be updated with $cGroup added,
14801524 # as $localAvailGrps contains $cGroup only once.
14811525 foreach ( $localAvailGrps as $cGroup ) {
14821526 # did we once add the user to the group?
14831527 if ( in_array( $cGroup,$localUserGrps ) ) {
1484 - $this->printDebug( "Checking to see if we need to remove user from: $cGroup", self::NONSENSITIVE );
1485 - if ( ( !$this->hasLDAPGroup( $cGroup ) ) && ( $this->isLDAPGroup( $cGroup ) ) ) {
1486 - $this->printDebug( "Removing user from: $cGroup", self::NONSENSITIVE );
 1528+ $this->printDebug( "Checking to see if we need to remove user from: $cGroup", NONSENSITIVE );
 1529+ if ( ( !$this->hasLDAPGroup( $cGroup ) ) && ( !in_array( $cGroup, $locallyManagedGrps ) ) ) {
 1530+ $this->printDebug( "Removing user from: $cGroup", NONSENSITIVE );
14871531 # the ldap group overrides the local group
14881532 # so as the user is currently not a member of the ldap group, he shall be removed from the local group
14891533 $user->removeGroup( $cGroup );
14901534 }
14911535 } else { # no, but maybe the user has recently been added to the ldap group?
1492 - $this->printDebug( "Checking to see if user is in: $cGroup", self::NONSENSITIVE );
 1536+ $this->printDebug( "Checking to see if user is in: $cGroup", NONSENSITIVE );
14931537 if ( $this->hasLDAPGroup( $cGroup ) ) {
1494 - $this->printDebug( "Adding user to: $cGroup", self::NONSENSITIVE );
 1538+ $this->printDebug( "Adding user to: $cGroup", NONSENSITIVE );
14951539 # so use the addGroup function
14961540 $user->addGroup( $cGroup );
14971541 # completed for $cGroup.
@@ -1509,7 +1553,7 @@
15101554 function getPasswordHash( $password ) {
15111555 global $wgLDAPPasswordHash;
15121556
1513 - $this->printDebug( "Entering getPasswordHash", self::NONSENSITIVE );
 1557+ $this->printDebug( "Entering getPasswordHash", NONSENSITIVE );
15141558
15151559 if ( isset( $wgLDAPPasswordHash[$_SESSION['wsDomain']] ) ) {
15161560 $hashtouse = $wgLDAPPasswordHash[$_SESSION['wsDomain']];
@@ -1531,7 +1575,7 @@
15321576 break;
15331577 }
15341578
1535 - $this->printDebug( "Password is $pass", self::HIGHLYSENSITIVE );
 1579+ $this->printDebug( "Password is $pass", HIGHLYSENSITIVE );
15361580 return $pass;
15371581 }
15381582
@@ -1569,8 +1613,8 @@
15701614 $bind = @ldap_bind( $ldapconn, $userdn, $password );
15711615 }
15721616 if ( !$bind ) {
1573 - $this->printDebug( "Failed to bind as $userdn", self::NONSENSITIVE );
1574 - $this->printDebug( "with password: $password", self::HIGHLYSENSITIVE );
 1617+ $this->printDebug( "Failed to bind as $userdn", NONSENSITIVE );
 1618+ $this->printDebug( "with password: $password", HIGHLYSENSITIVE );
15751619 return false;
15761620 }
15771621 return true;
@@ -1617,39 +1661,39 @@
16181662 function getBaseDN ( $type ) {
16191663 global $wgLDAPBaseDNs, $wgLDAPGroupBaseDNs, $wgLDAPUserBaseDNs;
16201664
1621 - $this->printDebug( "Entering getBaseDN", self::NONSENSITIVE );
 1665+ $this->printDebug( "Entering getBaseDN", NONSENSITIVE );
16221666
16231667 $ret = '';
16241668 switch( $type ) {
1625 - case self::USERDN:
 1669+ case USERDN:
16261670 if ( isset( $wgLDAPUserBaseDNs[$_SESSION['wsDomain']] ) ) {
16271671 $ret = $wgLDAPUserBaseDNs[$_SESSION['wsDomain']];
16281672 }
16291673 break;
1630 - case self::GROUPDN:
 1674+ case GROUPDN:
16311675 if ( isset( $wgLDAPGroupBaseDNs[$_SESSION['wsDomain']] ) ) {
16321676 $ret = $wgLDAPGroupBaseDNs[$_SESSION['wsDomain']];
16331677 }
16341678 break;
1635 - case self::DEFAULTDN:
 1679+ case DEFAULTDN:
16361680 if ( isset( $wgLDAPBaseDNs[$_SESSION['wsDomain']] ) ) {
16371681 $ret = $wgLDAPBaseDNs[$_SESSION['wsDomain']];
1638 - $this->printDebug( "basedn is $ret", self::NONSENSITIVE );
 1682+ $this->printDebug( "basedn is $ret", NONSENSITIVE );
16391683 return $ret;
16401684 } else {
1641 - $this->printDebug( "basedn is not set.", self::NONSENSITIVE );
 1685+ $this->printDebug( "basedn is not set.", NONSENSITIVE );
16421686 return '';
16431687 }
16441688 break;
16451689 }
16461690
16471691 if ( $ret == '' ) {
1648 - $this->printDebug( "basedn is not set for this type of entry, trying to get the default basedn.", self::NONSENSITIVE );
 1692+ $this->printDebug( "basedn is not set for this type of entry, trying to get the default basedn.", NONSENSITIVE );
16491693 // We will never reach here if $type is self::DEFAULTDN, so to avoid code
16501694 // code duplication, we'll get the default by re-calling the function.
1651 - return $this->getBaseDN( self::DEFAULTDN );
 1695+ return $this->getBaseDN( DEFAULTDN );
16521696 } else {
1653 - $this->printDebug( "basedn is $ret", self::NONSENSITIVE );
 1697+ $this->printDebug( "basedn is $ret", NONSENSITIVE );
16541698 return $ret;
16551699 }
16561700 }
@@ -1683,23 +1727,23 @@
16841728
16851729 $wgAuth = new LdapAuthenticationPlugin();
16861730
1687 - $wgAuth->printDebug( "Entering AutoAuthSetup.", self::NONSENSITIVE );
 1731+ $wgAuth->printDebug( "Entering AutoAuthSetup.", NONSENSITIVE );
16881732
16891733 //We may add quite a few different auto authenticate methods in the
16901734 //future, let's make it easy to support.
16911735 switch( $wgLDAPAutoAuthMethod ) {
16921736 case "smartcard":
1693 - $wgAuth->printDebug( "Allowing smartcard authentication.", self::NONSENSITIVE );
1694 - $wgAuth->printDebug( "wgLDAPSSLUsername = $wgLDAPSSLUsername", self::SENSITIVE );
 1737+ $wgAuth->printDebug( "Allowing smartcard authentication.", NONSENSITIVE );
 1738+ $wgAuth->printDebug( "wgLDAPSSLUsername = $wgLDAPSSLUsername", SENSITIVE );
16951739
16961740 if( $wgLDAPSSLUsername != null ) {
1697 - $wgAuth->printDebug( "wgLDAPSSLUsername is not null, adding hooks.", self::NONSENSITIVE );
 1741+ $wgAuth->printDebug( "wgLDAPSSLUsername is not null, adding hooks.", NONSENSITIVE );
16981742 $wgHooks['AutoAuthenticate'][] = 'SSLAuth'; /* Hook for magical authN */
16991743 $wgHooks['PersonalUrls'][] = 'NoLogout'; /* Disallow logout link */
17001744 }
17011745 break;
17021746 default:
1703 - $wgAuth->printDebug( "Not using any AutoAuthentication methods.", self::NONSENSITIVE );
 1747+ $wgAuth->printDebug( "Not using any AutoAuthentication methods.", NONSENSITIVE );
17041748 }
17051749 }
17061750
@@ -1718,14 +1762,14 @@
17191763 global $wgUser;
17201764 global $wgAuth;
17211765
1722 - $wgAuth->printDebug( "Entering SSLAuth.", self::NONSENSITIVE );
 1766+ $wgAuth->printDebug( "Entering SSLAuth.", NONSENSITIVE );
17231767
17241768 //Give us a user, see if we're around
17251769 $tmpuser = User::LoadFromSession();
17261770
17271771 //They already with us? If so, quit this function.
17281772 if( $tmpuser->isLoggedIn() ) {
1729 - $wgAuth->printDebug( "User is already logged in.", self::NONSENSITIVE );
 1773+ $wgAuth->printDebug( "User is already logged in.", NONSENSITIVE );
17301774 return true;
17311775 }
17321776
@@ -1734,12 +1778,12 @@
17351779 $wgAuth->autoAuthSetup();
17361780
17371781 //The user hasn't already been authenticated, let's check them
1738 - $wgAuth->printDebug( "User is not logged in, we need to authenticate", self::NONSENSITIVE );
 1782+ $wgAuth->printDebug( "User is not logged in, we need to authenticate", NONSENSITIVE );
17391783 $authenticated = $wgAuth->authenticate( $wgLDAPSSLUsername );
17401784 if ( !$authenticated ) {
17411785 //If the user doesn't exist in LDAP, there isn't much reason to
17421786 //go any further.
1743 - $wgAuth->printDebug("User wasn't found in LDAP, exiting.", self::NONSENSITIVE );
 1787+ $wgAuth->printDebug("User wasn't found in LDAP, exiting.", NONSENSITIVE );
17441788 return false;
17451789 }
17461790
@@ -1747,26 +1791,26 @@
17481792 //get from LDAP.
17491793 $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPSSLUsername );
17501794
1751 - $wgAuth->printDebug( "User exists in LDAP; finding the user by name in MediaWiki.", self::NONSENSITIVE );
 1795+ $wgAuth->printDebug( "User exists in LDAP; finding the user by name in MediaWiki.", NONSENSITIVE );
17521796
17531797 //Is the user already in the database?
17541798 $tmpuser = User::newFromName( $mungedUsername );
17551799
17561800 if ( $tmpuser == null ) {
1757 - $wgAuth->printDebug( "Username is not a valid MediaWiki username.", self::NONSENSITIVE );
 1801+ $wgAuth->printDebug( "Username is not a valid MediaWiki username.", NONSENSITIVE );
17581802 return false;
17591803 }
17601804
17611805 //If exists, log them in
17621806 if( $tmpuser->getID() != 0 ) {
1763 - $wgAuth->printDebug( "User exists in local database, logging in.", self::NONSENSITIVE );
 1807+ $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE );
17641808 $wgUser = &$tmpuser;
17651809 $wgAuth->updateUser( $wgUser );
17661810 $wgUser->setCookies();
17671811 $wgUser->setupSession();
17681812 return true;
17691813 }
1770 - $wgAuth->printDebug( "User does not exist in local database; creating.", self::NONSENSITIVE );
 1814+ $wgAuth->printDebug( "User does not exist in local database; creating.", NONSENSITIVE );
17711815
17721816 //Require SpecialUserlogin so that we can get a loginForm
17731817 require_once( 'SpecialUserlogin.php' );
@@ -1781,7 +1825,7 @@
17821826 $wgLangUnset = true;
17831827 }
17841828
1785 - $wgAuth->printDebug( "Creating LoginForm.", self::NONSENSITIVE );
 1829+ $wgAuth->printDebug( "Creating LoginForm.", NONSENSITIVE );
17861830
17871831 //This creates our form that'll let us create a new user in the database
17881832 $lf = new LoginForm( $wgRequest );
@@ -1790,7 +1834,7 @@
17911835 $wgUser = &$tmpuser;
17921836 $wgUser->setName( $wgContLang->ucfirst( $mungedUsername ) );
17931837
1794 - $wgAuth->printDebug( "Creating User.", self::NONSENSITIVE );
 1838+ $wgAuth->printDebug( "Creating User.", NONSENSITIVE );
17951839
17961840 //Create the user
17971841 $lf->initUser( $wgUser );

Status & tagging log