r23336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23335‎ | r23336 | r23337 >
Date:20:55, 24 June 2007
Author:laner
Status:old
Tags:
Comment:
* Some internal cleanup; slight code refactoring
* Added the ability to define different basedns for groups and users
* Fixed a bug with auto-rename of users breaking things even when it wasn't being used
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -44,6 +44,17 @@
4545 require_once( 'AuthPlugin.php' );
4646
4747 class LdapAuthenticationPlugin extends AuthPlugin {
 48+
 49+ //constants for search base
 50+ const GROUPDN = 0;
 51+ const USERDN = 1;
 52+ const DEFAULTDN = 2;
 53+
 54+ //constants for error reporting
 55+ const NONSENSITIVE = 1;
 56+ const SENSITIVE = 2;
 57+ const HIGHLYSENSITIVE = 3;
 58+
4859 //preferences
4960 var $email, $lang, $realname, $nickname, $externalid;
5061
@@ -70,7 +81,7 @@
7182 function userExists( $username ) {
7283 global $wgLDAPAddLDAPUsers;
7384
74 - $this->printDebug( "Entering userExists", 1 );
 85+ $this->printDebug( "Entering userExists", self::NONSENSITIVE );
7586
7687 //If we can't add LDAP users, we don't really need to check
7788 //if the user exists, the authenticate method will do this for
@@ -82,7 +93,8 @@
8394
8495 $ldapconn = $this->connect();
8596 if ( $ldapconn ) {
86 - $this->printDebug( "Successfully connected", 1 );
 97+ $this->printDebug( "Successfully connected", self::NONSENSITIVE );
 98+
8799 $searchstring = $this->getSearchString( $ldapconn, $username );
88100
89101 //If we are using smartcard authentication, and we got
@@ -101,15 +113,14 @@
102114 //Let's clean up
103115 @ldap_unbind();
104116 if ( !$entry ) {
105 - $this->printDebug( "Did not find a matching user in LDAP", 1 );
106 - //user wasn't found
 117+ $this->printDebug( "Did not find a matching user in LDAP", self::NONSENSITIVE );
107118 return false;
108119 } else {
109 - $this->printDebug( "Found a matching user in LDAP", 1 );
 120+ $this->printDebug( "Found a matching user in LDAP", self::NONSENSITIVE );
110121 return true;
111122 }
112123 } else {
113 - $this->printDebug( "Failed to connect", 1 );
 124+ $this->printDebug( "Failed to connect", self::NONSENSITIVE );
114125 return false;
115126 }
116127
@@ -125,9 +136,9 @@
126137 global $wgLDAPServerNames;
127138 global $wgLDAPEncryptionType;
128139
129 - $this->printDebug( "Entering Connect", 1 );
 140+ $this->printDebug( "Entering Connect", self::NONSENSITIVE );
130141
131 - //If the user didn't set an encryption type, we default to tls
 142+ //If the admin didn't set an encryption type, we default to tls
132143 if ( isset( $wgLDAPEncryptionType[$_SESSION['wsDomain']] ) ) {
133144 $encryptionType = $wgLDAPEncryptionType[$_SESSION['wsDomain']];
134145 } else {
@@ -137,11 +148,11 @@
138149 //Set the server string depending on whether we use ssl or not
139150 switch( $encryptionType ) {
140151 case "ssl":
141 - $this->printDebug( "Using SSL", 2 );
 152+ $this->printDebug( "Using SSL", self::SENSITIVE );
142153 $serverpre = "ldaps://";
143154 break;
144155 default:
145 - $this->printDebug( "Using TLS or not using encryption.", 2 );
 156+ $this->printDebug( "Using TLS or not using encryption.", self::SENSITIVE );
146157 $serverpre = "ldap://";
147158 }
148159
@@ -156,7 +167,7 @@
157168 }
158169 $servers = rtrim($servers);
159170
160 - $this->printDebug( "Using servers: $servers", 2 );
 171+ $this->printDebug( "Using servers: $servers", self::SENSITIVE );
161172
162173 //Connect and set options
163174 $ldapconn = @ldap_connect( $servers );
@@ -165,9 +176,9 @@
166177
167178 //TLS needs to be started after the connection is made
168179 if ( $encryptionType == "tls" ) {
169 - $this->printDebug( "Using TLS", 2 );
 180+ $this->printDebug( "Using TLS", self::SENSITIVE );
170181 if ( !ldap_start_tls( $ldapconn ) ) {
171 - $this->printDebug( "Failed to start TLS.", 2 );
 182+ $this->printDebug( "Failed to start TLS.", self::SENSITIVE );
172183 return;
173184 }
174185 }
@@ -198,11 +209,11 @@
199210 global $wgLDAPSearchStrings;
200211 global $wgLDAPUniqueAttribute, $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
201212
202 - $this->printDebug( "Entering authenticate", 1 );
 213+ $this->printDebug( "Entering authenticate", self::NONSENSITIVE );
203214
204215 //We don't handle local authentication
205216 if ( 'local' == $_SESSION['wsDomain'] ) {
206 - $this->printDebug( "User is using a local domain", 2 );
 217+ $this->printDebug( "User is using a local domain", self::SENSITIVE );
207218 return false;
208219 }
209220
@@ -210,7 +221,7 @@
211222 //that he/she isn't trying to fool us by sending a username other
212223 //than the one the web server got from the smartcard.
213224 if ( $this->useSmartcardAuth() && $wgLDAPSSLUsername != $username ) {
214 - $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.", 2 );
 225+ $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 );
215226 return false;
216227 }
217228
@@ -220,21 +231,21 @@
221232 //Smartcard authentication uses a pin, and does not require
222233 //a password to be given; a blank password here is wanted.
223234 if ( '' == $password && !$this->useSmartcardAuth() ) {
224 - $this->printDebug( "User used a blank password", 1 );
 235+ $this->printDebug( "User used a blank password", self::NONSENSITIVE );
225236 return false;
226237 }
227238
228239 $ldapconn = $this->connect();
229240 if ( $ldapconn ) {
230 - $this->printDebug( "Connected successfully", 1 );
 241+ $this->printDebug( "Connected successfully", self::NONSENSITIVE );
231242
232243 //Mediawiki munges the username before authenticate is called,
233244 //this can mess with authentication, group pulling/restriction,
234 - //preference pulling, etc. Let's allow the user to use
235 - //a lowercased username.
 245+ //preference pulling, etc. Let's allow the admin to use
 246+ //a lowercased username if needed.
236247 if ( isset( $wgLDAPLowerCaseUsername[$_SESSION['wsDomain']] ) && $wgLDAPLowerCaseUsername[$_SESSION['wsDomain']] ) {
 248+ $this->printDebug( "Lowercasing the username: $username", self::NONSENSITIVE );
237249 $username = strtolower( $username );
238 - $this->printDebug( "Lowercasing the username: $username", 1 );
239250 }
240251
241252 $userdn = $this->getSearchString( $ldapconn, $username );
@@ -243,7 +254,7 @@
244255 //empty string; if this happens, the bind will ALWAYS
245256 //return true, and will let anyone in!
246257 if ( '' == $userdn ) {
247 - $this->printDebug( "User DN is blank", 1 );
 258+ $this->printDebug( "User DN is blank", self::NONSENSITIVE );
248259 // Lets clean up.
249260 @ldap_unbind();
250261 return false;
@@ -252,7 +263,7 @@
253264 //If we are using password authentication, we need to bind as the
254265 //user to make sure the password is correct.
255266 if ( !$this->useSmartcardAuth() ) {
256 - $this->printDebug( "Binding as the user", 1 );
 267+ $this->printDebug( "Binding as the user", self::NONSENSITIVE );
257268
258269 //Let's see if the user can authenticate.
259270 $bind = $this->bindAs( $ldapconn, $userdn, $password );
@@ -261,7 +272,7 @@
262273 @ldap_unbind();
263274 return false;
264275 }
265 - $this->printDebug( "Binded successfully", 1 );
 276+ $this->printDebug( "Binded successfully", self::NONSENSITIVE );
266277
267278 if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
268279 $ss = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
@@ -270,20 +281,23 @@
271282 //DOMAIN\\USER-NAME.
272283 //Get the user's full DN so we can search for groups and such.
273284 $userdn = $this->getUserDN( $ldapconn, $username );
274 - $this->printDebug( "Pulled the user's DN: $userdn", 1 );
 285+ $this->printDebug( "Pulled the user's DN: $userdn", self::NONSENSITIVE );
275286 }
276287 }
277288
278289 if ( ( isset( $wgLDAPRequireAuthAttribute[$_SESSION['wsDomain']] )
279290 && $wgLDAPRequireAuthAttribute[$_SESSION['wsDomain']] ) ) {
280291
281 - $this->printDebug( "Checking for auth attributes", 1 );
 292+ $this->printDebug( "Checking for auth attributes", self::NONSENSITIVE );
 293+
282294 $filter = "(" . $wgLDAPAuthAttribute[$_SESSION['wsDomain']] . ")";
283295 $attributes = array( "dn" );
 296+
284297 $entry = ldap_read( $ldapconn, $userdn, $filter, $attributes );
285298 $info = ldap_get_entries( $ldapconn, $entry );
 299+
286300 if ( $info["count"] < 1 ) {
287 - $this->printDebug( "Failed auth attribute check", 1 );
 301+ $this->printDebug( "Failed auth attribute check", self::NONSENSITIVE );
288302 // Lets clean up.
289303 @ldap_unbind();
290304 return false;
@@ -294,9 +308,9 @@
295309 //Old style groups, non-nestable and fairly limited on group type (full DN
296310 //versus username). DEPRECATED
297311 if ( $wgLDAPGroupDN ) {
298 - $this->printDebug( "Checking for (old style) group membership", 1 );
 312+ $this->printDebug( "Checking for (old style) group membership", self::NONSENSITIVE );
299313 if ( !$this->isMemberOfLdapGroup( $ldapconn, $userdn, $wgLDAPGroupDN ) ) {
300 - $this->printDebug( "Failed (old style) group membership check", 1 );
 314+ $this->printDebug( "Failed (old style) group membership check", self::NONSENSITIVE );
301315
302316 //No point in going on if the user isn't in the required group
303317 // Lets clean up.
@@ -307,7 +321,7 @@
308322
309323 //New style group checking
310324 if ( isset( $wgLDAPRequiredGroups[$_SESSION['wsDomain']] ) ) {
311 - $this->printDebug( "Checking for (new style) group membership", 1 );
 325+ $this->printDebug( "Checking for (new style) group membership", self::NONSENSITIVE );
312326
313327 if ( isset( $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) && $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) {
314328 $inGroup = $this->isMemberOfRequiredLdapGroup( $ldapconn, $userdn );
@@ -316,7 +330,7 @@
317331 && $wgLDAPGroupUseRetrievedUsername[$_SESSION['wsDomain']] )
318332 && $this->LDAPUsername != '' ) {
319333
320 - $this->printDebug( "Using the username retrieved from the user's entry.", 1 );
 334+ $this->printDebug( "Using the username retrieved from the user's entry.", self::NONSENSITIVE );
321335 $inGroup = $this->isMemberOfRequiredLdapGroup( $ldapconn, $this->LDAPUsername );
322336 } else {
323337 $inGroup = $this->isMemberOfRequiredLdapGroup( $ldapconn, $username );
@@ -333,7 +347,7 @@
334348
335349 //Synch LDAP groups with MediaWiki groups
336350 if ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) {
337 - $this->printDebug( "Retrieving LDAP group membership", 1 );
 351+ $this->printDebug( "Retrieving LDAP group membership", self::NONSENSITIVE );
338352
339353 //Let's get the user's LDAP groups
340354 if ( isset( $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) && $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) {
@@ -341,13 +355,15 @@
342356 } else {
343357 if ( ( isset( $wgLDAPGroupUseRetrievedUsername[$_SESSION['wsDomain']] ) && $wgLDAPGroupUseRetrievedUsername[$_SESSION['wsDomain']] )
344358 && $this->LDAPUsername != '' ) {
 359+
345360 $this->userLDAPGroups = $this->getUserGroups( $ldapconn, $this->LDAPUsername, true );
346361 } else {
347362 $this->userLDAPGroups = $this->getUserGroups( $ldapconn, $username, true );
348363 }
349364 }
350365
351 - //If the user doesn't have any groups there is no need to waste another search.
 366+ //Only find all groups if the user has any groups; otherwise, we are
 367+ //just wasting a search.
352368 if ( $this->foundUserLDAPGroups ) {
353369 $this->allLDAPGroups = $this->getAllGroups( $ldapconn, true );
354370 }
@@ -355,7 +371,7 @@
356372
357373 //Retrieve preferences
358374 if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
359 - $this->printDebug( "Retrieving preferences", 1 );
 375+ $this->printDebug( "Retrieving preferences", self::NONSENSITIVE );
360376
361377 $entry = @ldap_read( $ldapconn, $userdn, "objectclass=*" );
362378 $info = @ldap_get_entries( $ldapconn, $entry );
@@ -364,19 +380,20 @@
365381 $this->nickname = $info[0]["displayname"][0];
366382 $this->realname = $info[0]["cn"][0];
367383
368 - $this->printDebug( "Retrieved: $this->email, $this->lang, $this->nickname, $this->realname", 2 );
 384+ $this->printDebug( "Retrieved: $this->email, $this->lang, $this->nickname, $this->realname", self::SENSITIVE );
369385 }
370386
371387 // Are we blocking login/renaming users on unique external ID mismatches?
372388 // *** WARNING ***
373389 // This needs to be fixed before use! This probably does not work correctly
374390 // with all options. It is probably a good idea to refactor the username stuff
375 - // in general (as it is currently somewhat of a kludge)! ***
 391+ // in general (as it is currently somewhat of a kludge). Also, MediaWiki does
 392+ // not currently have support for this.
376393 // *** WARNING ***
377394 if ( ( isset( $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] ) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] )
378395 || ( isset( $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) ) {
379396
380 - $this->printDebug( "Checking for username change in LDAP.", 2 );
 397+ $this->printDebug( "Checking for username change in LDAP.", self::SENSITIVE );
381398
382399 //Get the user's unique attribute from LDAP
383400 if ( isset( $wgLDAPUniqueAttribute[$_SESSION['wsDomain']] ) ) {
@@ -384,27 +401,26 @@
385402 $this->externalid = $info[0][$ldapuniqueattr][0];
386403 }
387404
388 - $this->printDebug( "Retrieved external id: $this->externalid", 2 );
 405+ $this->printDebug( "Retrieved external id: $this->externalid", self::SENSITIVE );
389406
390407 $retrievedusername = User::whoIsExternalID( "$this->externalid" );
391408
392 - $this->printDebug( "Username in database of fetched external id: $retrievedusername", 2 );
 409+ $this->printDebug( "Username (in MediaWiki database) of fetched external id: $retrievedusername", self::SENSITIVE );
393410
394411 // See if the username returned from the database matches the username given
395412 if ( $retrievedusername != '' && ( $username != $retrievedusername ) ) {
396 - //
397413 if ( isset( $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] )
398414 && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] ) {
399415
400 - $this->printDebug( "Usernames do not match, blocking login.", 2 );
 416+ $this->printDebug( "Usernames do not match, blocking login.", self::SENSITIVE );
401417 return false;
402418 } else if ( isset( $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] )
403419 && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) {
404420
405 - $this->printDebug( "Usernames do not match, renaming user in database.", 2 );
 421+ $this->printDebug( "Usernames do not match, renaming user in database.", self::SENSITIVE );
406422
407423 if ( version_compare( $wgVersion, '1.7.0', '<' ) ) {
408 - $this->printDebug( "Renaming users is only supported in MediaWiki 1.7+, please upgrade.", 2 );
 424+ $this->printDebug( "Renaming users is only supported in MediaWiki 1.7+, please upgrade.", self::SENSITIVE );
409425 return false;
410426 }
411427
@@ -428,16 +444,16 @@
429445 }
430446 }
431447
432 - $this->printDebug( "Usernames matched or the user doesn't exist in the database yet.", 2 );
 448+ $this->printDebug( "Usernames matched or the user doesn't exist in the database yet.", self::SENSITIVE );
433449 }
434450
435451 // Lets clean up.
436452 @ldap_unbind();
437453 } else {
438 - $this->printDebug( "Failed to connect", 1 );
 454+ $this->printDebug( "Failed to connect", self::NONSENSITIVE );
439455 return false;
440456 }
441 - $this->printDebug( "Authentication passed", 1 );
 457+ $this->printDebug( "Authentication passed", self::NONSENSITIVE );
442458
443459 //We made it this far; the user authenticated and didn't fail any checks, so he/she gets in.
444460 return true;
@@ -454,7 +470,7 @@
455471 global $wgLDAPAddLDAPUsers;
456472 global $wgLDAPUseSmartcardAuth, $wgLDAPSmartcardDomain;
457473
458 - $this->printDebug( "Entering modifyUITemplate", 1 );
 474+ $this->printDebug( "Entering modifyUITemplate", self::NONSENSITIVE );
459475
460476 if ( !isset( $wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) || !$wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) {
461477 $template->set( 'create', false );
@@ -465,12 +481,13 @@
466482
467483 $tempDomArr = $wgLDAPDomainNames;
468484 if ( $wgLDAPUseLocal ) {
469 - $this->printDebug( "Allowing the local domain, adding it to the list.", 1 );
 485+ $this->printDebug( "Allowing the local domain, adding it to the list.", self::NONSENSITIVE );
470486 array_push( $tempDomArr, 'local' );
471487 }
472488
473489 if ( $wgLDAPUseSmartcardAuth ) {
474 - $this->printDebug( "Allowing smartcard login, removing the domain from the list.", 1 );
 490+ $this->printDebug( "Allowing smartcard login, removing the domain from the list.", self::NONSENSITIVE );
 491+
475492 //There is no reason for people to log in directly to the wiki if the are using a
476493 //smartcard. If they try to, they are probably up to something fishy.
477494 unset( $tempDomArr[array_search( $wgLDAPSmartcardDomain, $tempDomArr )] );
@@ -511,23 +528,23 @@
512529 function setPassword( $user, &$password ) {
513530 global $wgLDAPUpdateLDAP, $wgLDAPWriterDN, $wgLDAPWriterPassword;
514531
515 - $this->printDebug( "Entering setPassword", 1 );
 532+ $this->printDebug( "Entering setPassword", self::NONSENSITIVE );
516533
517534 if ( $_SESSION['wsDomain'] == 'local' ) {
518 - $this->printDebug( "User is using a local domain", 1 );
 535+ $this->printDebug( "User is using a local domain", self::NONSENSITIVE );
519536
520537 //We don't set local passwords, but we don't want the wiki
521538 //to send the user a failure.
522539 return true;
523540 } else if ( !isset( $wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) || !$wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) {
524 - $this->printDebug( "Wiki is set to not allow updates", 1 );
 541+ $this->printDebug( "Wiki is set to not allow updates", self::NONSENSITIVE );
525542
526543 //We aren't allowing the user to change his/her own password
527544 return false;
528545 }
529546
530547 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
531 - $this->printDebug( "Wiki doesn't have wgLDAPWriterDN set", 1 );
 548+ $this->printDebug( "Wiki doesn't have wgLDAPWriterDN set", self::NONSENSITIVE );
532549
533550 //We can't change a user's password without an account that is
534551 //allowed to do it.
@@ -538,10 +555,10 @@
539556
540557 $ldapconn = $this->connect();
541558 if ( $ldapconn ) {
542 - $this->printDebug( "Connected successfully", 1 );
 559+ $this->printDebug( "Connected successfully", self::NONSENSITIVE );
543560 $userdn = $this->getSearchString( $ldapconn, $user->getName() );
544561
545 - $this->printDebug( "Binding as the writerDN", 1 );
 562+ $this->printDebug( "Binding as the writerDN", self::NONSENSITIVE );
546563 $bind = $this->bindAs( $ldapconn, $wgLDAPWriterDN[$_SESSION['wsDomain']], $wgLDAPWriterPassword[$_SESSION['wsDomain']] );
547564 if ( !$bind ) {
548565 return false;
@@ -558,13 +575,14 @@
559576 //Let's clean up
560577 @ldap_unbind();
561578 if ( $success ) {
562 - $this->printDebug( "Successfully modified the user's password", 1 );
 579+ $this->printDebug( "Successfully modified the user's password", self::NONSENSITIVE );
563580 return true;
564581 } else {
565 - $this->printDebug( "Failed to modify the user's password", 1 );
 582+ $this->printDebug( "Failed to modify the user's password", self::NONSENSITIVE );
566583 return false;
567584 }
568585 } else {
 586+ $this->printDebug( "Failed to connect", self::NONSENSITIVE );
569587 return false;
570588 }
571589 }
@@ -581,11 +599,11 @@
582600 global $wgLDAPUpdateLDAP;
583601 global $wgLDAPWriterDN, $wgLDAPWriterPassword;
584602
585 - $this->printDebug( "Entering updateExternalDB", 1 );
 603+ $this->printDebug( "Entering updateExternalDB", self::NONSENSITIVE );
586604
587605 if ( ( !isset( $wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) || !$wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) ||
588606 $_SESSION['wsDomain'] == 'local' ) {
589 - $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing updates", 1 );
 607+ $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing updates", self::NONSENSITIVE );
590608
591609 //We don't handle local preferences, but we don't want the
592610 //wiki to return an error.
@@ -593,7 +611,7 @@
594612 }
595613
596614 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
597 - $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", 1 );
 615+ $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", self::NONSENSITIVE );
598616
599617 //We can't modify LDAP preferences if we don't have a user
600618 //capable of editing LDAP attributes.
@@ -607,10 +625,10 @@
608626
609627 $ldapconn = $this->connect();
610628 if ( $ldapconn ) {
611 - $this->printDebug( "Connected successfully", 1 );
 629+ $this->printDebug( "Connected successfully", self::NONSENSITIVE );
612630 $userdn = $this->getSearchString( $ldapconn, $user->getName() );
613631
614 - $this->printDebug( "Binding as the writerDN", 1 );
 632+ $this->printDebug( "Binding as the writerDN", self::NONSENSITIVE );
615633 $bind = $this->bindAs( $ldapconn, $wgLDAPWriterDN[$_SESSION['wsDomain']], $wgLDAPWriterPassword[$_SESSION['wsDomain']] );
616634 if ( !$bind ) {
617635 return false;
@@ -622,16 +640,16 @@
623641 if ( '' != $this->language ) { $values["preferredlanguage"] = $this->language; }
624642
625643 if ( 0 != sizeof( $values ) && ldap_modify( $ldapconn, $userdn, $values ) ) {
626 - $this->printDebug( "Successfully modified the user's attributes", 1 );
 644+ $this->printDebug( "Successfully modified the user's attributes", self::NONSENSITIVE );
627645 @ldap_unbind();
628646 return true;
629647 } else {
630 - $this->printDebug( "Failed to modify the user's attributes", 1 );
 648+ $this->printDebug( "Failed to modify the user's attributes", self::NONSENSITIVE );
631649 @ldap_unbind();
632650 return false;
633651 }
634652 } else {
635 - $this->printDebug( "Failed to Connect", 1 );
 653+ $this->printDebug( "Failed to Connect", self::NONSENSITIVE );
636654 return false;
637655 }
638656 }
@@ -697,18 +715,18 @@
698716 global $wgLDAPRequiredGroups, $wgLDAPGroupDN;
699717 global $wgLDAPRequireAuthAttribute, $wgLDAPAuthAttribute;
700718
701 - $this->printDebug( "Entering addUser", 1 );
 719+ $this->printDebug( "Entering addUser", self::NONSENSITIVE );
702720
703721 if ( ( !isset( $wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) || !$wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) ||
704722 'local' == $_SESSION['wsDomain'] ) {
705 - $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing users to be added to LDAP", 1 );
 723+ $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing users to be added to LDAP", self::NONSENSITIVE );
706724
707725 //Tell the wiki not to return an error.
708726 return true;
709727 }
710728
711729 if ( $wgLDAPRequiredGroups || $wgLDAPGroupDN ) {
712 - $this->printDebug( "The wiki is requiring users to be in specific groups, and cannot add users as this would be a security hole.", 1 );
 730+ $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 );
713731 //It is possible that later we can add users into
714732 //groups, but since we don't support it, we don't want
715733 //to open holes!
@@ -716,7 +734,7 @@
717735 }
718736
719737 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
720 - $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", 1 );
 738+ $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", self::NONSENSITIVE );
721739
722740 //We can't add users without an LDAP account capable of doing so.
723741 return false;
@@ -730,30 +748,34 @@
731749
732750 $ldapconn = $this->connect();
733751 if ( $ldapconn ) {
734 - $this->printDebug( "Successfully connected", 1 );
 752+ $this->printDebug( "Successfully connected", self::NONSENSITIVE );
 753+
735754 $userdn = $this->getSearchString( $ldapconn, $username );
736755 if ( '' == $userdn ) {
737 - $this->printDebug( "userdn is blank, attempting to use wgLDAPWriteLocation", 1 );
 756+ $this->printDebug( "userdn is blank, attempting to use wgLDAPWriteLocation", self::NONSENSITIVE );
738757 if ( isset( $wgLDAPWriteLocation[$_SESSION['wsDomain']] ) ) {
739 - $this->printDebug( "wgLDAPWriteLocation is set, using that", 1 );
 758+ $this->printDebug( "wgLDAPWriteLocation is set, using that", self::NONSENSITIVE );
740759 $userdn = $wgLDAPSearchAttributes[$_SESSION['wsDomain']] . "=" .
741760 $username . $wgLDAPWriteLocation[$_SESSION['wsDomain']];
742761 } else {
743 - $this->printDebug( "wgLDAPWriteLocation is not set, failing", 1 );
 762+ $this->printDebug( "wgLDAPWriteLocation is not set, failing", self::NONSENSITIVE );
744763 //getSearchString will bind, but will not unbind
745764 @ldap_unbind();
746765 return false;
747766 }
748767 }
749768
750 - $this->printDebug( "Binding as the writerDN", 1 );
 769+ $this->printDebug( "Binding as the writerDN", self::NONSENSITIVE );
 770+
751771 $bind = $this->bindAs( $ldapconn, $wgLDAPWriterDN[$_SESSION['wsDomain']], $wgLDAPWriterPassword[$_SESSION['wsDomain']] );
752772 if ( !$bind ) {
 773+ $this->printDebug( "Failed to bind as the writerDN; add failed", self::NONSENSITIVE );
753774 return false;
754775 }
755776
756777 //Set up LDAP attributes
757778 $values["uid"] = $username;
 779+ //sn is required for objectclass inetorgperson
758780 $values["sn"] = $username;
759781 if ( '' != $this->email ) { $values["mail"] = $this->email; }
760782 if ( '' != $this->realname ) {$values["cn"] = $this->realname; }
@@ -765,16 +787,18 @@
766788 $values[$wgLDAPAuthAttribute[$_SESSION['wsDomain']]] = "true";
767789 }
768790
 791+ $this->printDebug( "Adding user", self::NONSENSITIVE );
769792 if ( @ldap_add( $ldapconn, $userdn, $values ) ) {
770 - $this->printDebug( "Successfully added user", 1 );
 793+ $this->printDebug( "Successfully added user", self::NONSENSITIVE );
771794 @ldap_unbind();
772795 return true;
773796 } else {
774 - $this->printDebug( "Failed to add user", 1 );
 797+ $this->printDebug( "Failed to add user", self::NONSENSITIVE );
775798 @ldap_unbind();
776799 return false;
777800 }
778801 } else {
 802+ $this->printDebug( "Failed to connect; add failed", self::NONSENSITIVE );
779803 return false;
780804 }
781805 }
@@ -786,7 +810,7 @@
787811 * @access public
788812 */
789813 function setDomain( $domain ) {
790 - $this->printDebug( "Setting domain as: $domain", 1 );
 814+ $this->printDebug( "Setting domain as: $domain", self::NONSENSITIVE );
791815 $_SESSION['wsDomain'] = $domain;
792816 }
793817
@@ -801,13 +825,13 @@
802826 function validDomain( $domain ) {
803827 global $wgLDAPDomainNames, $wgLDAPUseLocal;
804828
805 - $this->printDebug( "Entering validDomain", 1 );
 829+ $this->printDebug( "Entering validDomain", self::NONSENSITIVE );
806830
807831 if ( in_array( $domain, $wgLDAPDomainNames ) || ( $wgLDAPUseLocal && 'local' == $domain ) ) {
808 - $this->printDebug( "User is using a valid domain.", 1 );
 832+ $this->printDebug( "User is using a valid domain.", self::NONSENSITIVE );
809833 return true;
810834 } else {
811 - $this->printDebug( "User is not using a valid domain.", 1 );
 835+ $this->printDebug( "User is not using a valid domain.", self::NONSENSITIVE );
812836 return false;
813837 }
814838 }
@@ -817,19 +841,21 @@
818842 *
819843 * @param User $user
820844 * @access public
 845+ * TODO: fix the setExternalID stuff
821846 */
822847 function updateUser( &$user ) {
823848 global $wgLDAPRetrievePrefs;
824849 global $wgLDAPUseLDAPGroups;
 850+ global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
825851
826 - $this->printDebug( "Entering updateUser", 1 );
 852+ $this->printDebug( "Entering updateUser", self::NONSENSITIVE );
827853
828854 $saveSettings = false;
829855
830856 //If we aren't pulling preferences, we don't want to accidentally
831857 //overwrite anything.
832858 if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
833 - $this->printDebug( "Setting user preferences.", 1 );
 859+ $this->printDebug( "Setting user preferences.", self::NONSENSITIVE );
834860
835861 if ( '' != $this->lang ) {
836862 $user->setOption( 'language', $this->lang );
@@ -843,60 +869,44 @@
844870 if ( '' != $this->email ) {
845871 $user->setEmail( $this->email );
846872 }
847 - if ( '' != $this->externalid ) {
848 - $user->setExternalID( $this->externalid );
 873+ if ( ( isset( $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] ) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] )
 874+ || ( isset( $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']] ) ) {
 875+
 876+ if ( '' != $this->externalid ) {
 877+ $user->setExternalID( $this->externalid );
 878+ }
849879 }
850880
851881 $saveSettings = true;
852882 }
853883
854884 if ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) {
 885+ $this->printDebug( "Setting user groups.", self::NONSENSITIVE );
855886 $this->setGroups( $user );
 887+
856888 $saveSettings = true;
857889 }
858890
859891 if ( $saveSettings ) {
860 - $this->printDebug( "Saving user settings.", 1 );
 892+ $this->printDebug( "Saving user settings.", self::NONSENSITIVE );
861893 $user->saveSettings();
862894 }
863895 }
864896
865897 /**
866 - * Return true to prevent logins that don't authenticate here from being
867 - * checked against the local database's password fields.
868 - *
869 - * This is just a question, and shouldn't perform any actions.
870 - *
871 - * @return bool
872 - * @access public
873 - */
874 - function strict() {
875 - global $wgLDAPUseLocal, $wgLDAPMailPassword;
876 -
877 - $this->printDebug( "Entering strict.", 1 );
878 -
879 - if ( $wgLDAPUseLocal || $wgLDAPMailPassword ) {
880 - $this->printDebug( "Returning false in strict().", 1 );
881 - return false;
882 - } else {
883 - $this->printDebug( "Returning true in strict().", 1 );
884 - return true;
885 - }
886 - }
887 -
888 - /**
889898 * When creating a user account, initialize user with information from LDAP.
890899 *
891900 * @param User $user
892901 * @access public
 902+ * TODO: fix setExternalID stuff
893903 */
894904 function initUser( &$user ) {
895905 global $wgLDAPUseLDAPGroups;
896906
897 - $this->printDebug( "Entering initUser", 1 );
 907+ $this->printDebug( "Entering initUser", self::NONSENSITIVE );
898908
899909 if ( 'local' == $_SESSION['wsDomain'] ) {
900 - $this->printDebug( "User is using a local domain", 1 );
 910+ $this->printDebug( "User is using a local domain", self::NONSENSITIVE );
901911 return;
902912 }
903913
@@ -905,32 +915,37 @@
906916 //security of our domain.
907917 $user->mPassword = '';
908918
909 - if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
910 - if ( '' != $this->lang ) {
911 - $user->setOption( 'language', $this->lang );
912 - }
913 - if ( '' != $this->nickname ) {
914 - $user->setOption( 'nickname', $this->nickname );
915 - }
916 - if ( '' != $this->realname ) {
917 - $user->setRealName( $this->realname );
918 - }
919 - if ( '' != $this->email ) {
920 - $user->setEmail( $this->email );
921 - }
922 - if ( '' != $this->externalid ) {
923 - $user->setExternalID( 'uniqueLDAPattr', $this->externalid );
924 - }
925 - }
 919+ //The update user function does everything else we need done.
 920+ $this->updateUser($user);
926921
927 - if ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) {
928 - $this->setGroups( $user );
929 - }
930 -
 922+ //updateUser() won't definately save the user's settings
931923 $user->saveSettings();
932924 }
933925
934926 /**
 927+ * Return true to prevent logins that don't authenticate here from being
 928+ * checked against the local database's password fields.
 929+ *
 930+ * This is just a question, and shouldn't perform any actions.
 931+ *
 932+ * @return bool
 933+ * @access public
 934+ */
 935+ function strict() {
 936+ global $wgLDAPUseLocal, $wgLDAPMailPassword;
 937+
 938+ $this->printDebug( "Entering strict.", self::NONSENSITIVE );
 939+
 940+ if ( $wgLDAPUseLocal || $wgLDAPMailPassword ) {
 941+ $this->printDebug( "Returning false in strict().", self::NONSENSITIVE );
 942+ return false;
 943+ } else {
 944+ $this->printDebug( "Returning true in strict().", self::NONSENSITIVE );
 945+ return true;
 946+ }
 947+ }
 948+
 949+ /**
935950 * Munge the username to always have a form of uppercase for the first letter,
936951 * and lowercase for the rest of the letters.
937952 *
@@ -939,15 +954,15 @@
940955 * @access public
941956 */
942957 function getCanonicalName( $username ) {
943 - $this->printDebug( "Entering getCanonicalName", 1 );
 958+ $this->printDebug( "Entering getCanonicalName", self::NONSENSITIVE );
944959
945960 if ( $username != '' ) {
946 - $this->printDebug( "Username isn't empty.", 1 );
 961+ $this->printDebug( "Username isn't empty.", self::NONSENSITIVE );
947962
948963 //We want to use the username returned by LDAP
949964 //if it exists
950965 if ( $this->LDAPUsername != '' ) {
951 - $this->printDebug( "Using LDAPUsername.", 1 );
 966+ $this->printDebug( "Using LDAPUsername.", self::NONSENSITIVE );
952967 $username = $this->LDAPUsername;
953968 }
954969
@@ -959,21 +974,13 @@
960975 //uppercase the first letter
961976 $username[0] = strtoupper( $username[0] );
962977 }
963 - $this->printDebug( "Munged username: $username", 1 );
 978+
 979+ $this->printDebug( "Munged username: $username", self::NONSENSITIVE );
 980+
964981 return $username;
965982 }
966983
967984 /**
968 - * Returns the username pulled from LDAP when getSearchString() was called.
969 - *
970 - * @return string
971 - * @access public
972 - */
973 - function getLDAPUsername() {
974 - return $this->LDAPUsername;
975 - }
976 -
977 - /**
978985 * Configures the authentication plugin for use with auto-authentication
979986 * plugins.
980987 *
@@ -1000,11 +1007,11 @@
10011008 global $wgLDAPSearchStrings;
10021009 global $wgLDAPProxyAgent, $wgLDAPProxyAgentPassword;
10031010
1004 - $this->printDebug( "Entering getSearchString", 1 );
 1011+ $this->printDebug( "Entering getSearchString", self::NONSENSITIVE );
10051012
10061013 if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
10071014 //This is a straight bind
1008 - $this->printDebug( "Doing a straight bind", 1 );
 1015+ $this->printDebug( "Doing a straight bind", self::NONSENSITIVE );
10091016
10101017 $tmpuserdn = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
10111018 $userdn = str_replace( "USER-NAME", $username, $tmpuserdn );
@@ -1012,22 +1019,22 @@
10131020 //This is a proxy bind, or an anonymous bind with a search
10141021 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
10151022 //This is a proxy bind
1016 - $this->printDebug( "Doing a proxy bind", 1 );
 1023+ $this->printDebug( "Doing a proxy bind", self::NONSENSITIVE );
10171024 $bind = $this->bindAs( $ldapconn, $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
10181025 } else {
10191026 //This is an anonymous bind
1020 - $this->printDebug( "Doing an anonymous bind", 1 );
 1027+ $this->printDebug( "Doing an anonymous bind", self::NONSENSITIVE );
10211028 $bind = $this->bindAs( $ldapconn );
10221029 }
10231030
10241031 if ( !$bind ) {
1025 - $this->printDebug( "Failed to bind", 1 );
 1032+ $this->printDebug( "Failed to bind", self::NONSENSITIVE );
10261033 return '';
10271034 }
10281035
10291036 $userdn = $this->getUserDN( $ldapconn, $username );
10301037 }
1031 - $this->printDebug( "userdn is: $userdn", 2 );
 1038+ $this->printDebug( "userdn is: $userdn", self::SENSITIVE );
10321039 return $userdn;
10331040 }
10341041
@@ -1044,9 +1051,8 @@
10451052 function getUserDN( $ldapconn, $username ) {
10461053 global $wgLDAPSearchAttributes;
10471054 global $wgLDAPRequireAuthAttribute, $wgLDAPAuthAttribute;
1048 - global $wgLDAPBaseDNs;
10491055
1050 - $this->printDebug("Entering getUserDN",1);
 1056+ $this->printDebug("Entering getUserDN", self::NONSENSITIVE);
10511057
10521058 //we need to do a subbase search for the entry
10531059
@@ -1056,30 +1062,30 @@
10571063 $auth_filter = "(" . $wgLDAPAuthAttribute[$_SESSION['wsDomain']] . ")";
10581064 $srch_filter = "(" . $wgLDAPSearchAttributes[$_SESSION['wsDomain']] . "=" . $this->getLdapEscapedString( $username ) . ")";
10591065 $filter = "(&" . $srch_filter . $auth_filter . ")";
1060 - $this->printDebug( "Created an auth attribute filter: $filter", 2 );
 1066+ $this->printDebug( "Created an auth attribute filter: $filter", self::SENSITIVE );
10611067 } else {
10621068 $filter = "(" . $wgLDAPSearchAttributes[$_SESSION['wsDomain']] . "=" . $this->getLdapEscapedString( $username ) . ")";
1063 - $this->printDebug( "Created a regular filter: $filter", 2 );
 1069+ $this->printDebug( "Created a regular filter: $filter", self::SENSITIVE );
10641070 }
10651071
10661072 $attributes = array( "*" );
1067 - $base = $wgLDAPBaseDNs[$_SESSION['wsDomain']];
 1073+ $base = $this->getBaseDN( self::USERDN );
10681074
1069 - $this->printDebug( "Using base: $base", 2 );
 1075+ $this->printDebug( "Using base: $base", self::SENSITIVE );
10701076
10711077 $entry = @ldap_search( $ldapconn, $base, $filter, $attributes );
10721078 if ( !$entry ) {
1073 - $this->printDebug( "Couldn't find an entry", 1 );
 1079+ $this->printDebug( "Couldn't find an entry", self::NONSENSITIVE );
10741080 return '';
10751081 }
10761082
10771083 $info = @ldap_get_entries( $ldapconn, $entry );
10781084
1079 - //This is a pretty useful thing to have for both smartcard authentication,
 1085+ //This is a pretty useful thing to have for smartcard authentication,
10801086 //group checking, and pulling preferences.
10811087 wfRunHooks( 'SetUsernameAttributeFromLDAP', array( &$this->LDAPUsername, $info ) );
10821088 if ( !is_string( $this->LDAPUsername ) ) {
1083 - $this->printDebug( "Fetched username is not a string (check your hook code...).", 1 );
 1089+ $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 );
10841090 $this->LDAPUsername = '';
10851091 }
10861092
@@ -1089,11 +1095,12 @@
10901096
10911097 //DEPRECATED
10921098 function isMemberOfLdapGroup( $ldapconn, $userDN, $groupDN ) {
1093 - $this->printDebug( "Entering isMemberOfLdapGroup (DEPRECATED)", 1 );
 1099+ $this->printDebug( "Entering isMemberOfLdapGroup (DEPRECATED)", self::NONSENSITIVE );
10941100
10951101 //we need to do a subbase search for the entry
10961102 $filter = "(member=" . $this->getLdapEscapedString( $userDN ) . ")";
10971103 $info = ldap_get_entries( $ldapconn, @ldap_search( $ldapconn, $groupDN, $filter ) );
 1104+
10981105 return ( $info["count"] >= 1 );
10991106 }
11001107
@@ -1109,7 +1116,7 @@
11101117 global $wgLDAPRequiredGroups;
11111118 global $wgLDAPGroupSearchNestedGroups;
11121119
1113 - $this->printDebug( "Entering isMemberOfRequiredLdapGroup", 1 );
 1120+ $this->printDebug( "Entering isMemberOfRequiredLdapGroup", self::NONSENSITIVE );
11141121
11151122 $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']];
11161123 for ( $i = 0; $i < count( $reqgroups ); $i++ ) {
@@ -1118,35 +1125,35 @@
11191126
11201127 $searchnested = $wgLDAPGroupSearchNestedGroups[$_SESSION['wsDomain']];
11211128
1122 - $this->printDebug( "Required groups:" . implode( ",",$reqgroups ) . "", 1 );
 1129+ $this->printDebug( "Required groups:" . implode( ",",$reqgroups ) . "", self::NONSENSITIVE );
11231130
11241131 $groups = $this->getUserGroups( $ldapconn, $userDN );
11251132
 1133+ //TODO: using variables for this kind of thing is dirty, let's think of a new way
 1134+ // to handle this need.
11261135 if ( !$this->foundUserLDAPGroups ) {
 1136+ $this->printDebug( "Couldn't find the user in any groups (1).", self::NONSENSITIVE );
 1137+
11271138 //User isn't in any groups, so he/she obviously can't be in
11281139 //a required one
1129 - $this->printDebug( "Couldn't find the user in any groups (1).", 1 );
1130 -
11311140 return false;
11321141 } else {
11331142 //User is in groups, let's see if a required group is one of them
11341143 foreach ( $groups as $group ) {
11351144 if ( in_array( $group, $reqgroups ) ) {
1136 - $this->printDebug( "Found user in a group.", 1 );
 1145+ $this->printDebug( "Found user in a group.", self::NONSENSITIVE );
11371146 return true;
11381147 }
11391148 }
11401149
11411150 //We didn't find the user in the group, lets check nested groups
11421151 if ( $searchnested ) {
1143 - //No reason to go on if we aren't allowing nested group
1144 - //searches
11451152 if ( $this->searchNestedGroups( $ldapconn, $groups ) ) {
11461153 return true;
11471154 }
11481155 }
11491156
1150 - $this->printDebug( "Couldn't find the user in any groups (2).", 1 );
 1157+ $this->printDebug( "Couldn't find the user in any groups (2).", self::NONSENSITIVE );
11511158
11521159 return false;
11531160 }
@@ -1166,15 +1173,15 @@
11671174 function searchNestedGroups( $ldapconn, $groups, $checkedgroups = array() ) {
11681175 global $wgLDAPRequiredGroups;
11691176
1170 - $this->printDebug( "Entering searchNestedGroups", 1 );
 1177+ $this->printDebug( "Entering searchNestedGroups", self::NONSENSITIVE );
11711178
11721179 //base case, no more groups left to check
11731180 if ( !$groups ) {
1174 - $this->printDebug( "Couldn't find user in any nested groups.", 1 );
 1181+ $this->printDebug( "Couldn't find user in any nested groups.", self::NONSENSITIVE );
11751182 return false;
11761183 }
11771184
1178 - $this->printDebug( "Checking groups:" . implode( ",", $groups ) . "", 2 );
 1185+ $this->printDebug( "Checking groups:" . implode( ",", $groups ) . "", self::SENSITIVE );
11791186
11801187 $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']];
11811188 for ( $i = 0; $i < count( $reqgroups ); $i++ ) {
@@ -1185,12 +1192,12 @@
11861193 foreach ( $groups as $group ) {
11871194 $returnedgroups = $this->getUserGroups( $ldapconn, $group );
11881195 foreach ( $returnedgroups as $checkme ) {
1189 - $this->printDebug( "Checking membership for: $checkme", 2 );
 1196+ $this->printDebug( "Checking membership for: $checkme", self::SENSITIVE );
11901197 if ( in_array( $checkme, $checkedgroups ) ) {
11911198 //We already checked this, move on
11921199 continue;
11931200 } else if ( in_array( $checkme, $reqgroups ) ) {
1194 - $this->printDebug( "Found user in a nested group.", 1 );
 1201+ $this->printDebug( "Found user in a nested group.", self::NONSENSITIVE );
11951202 //Woohoo
11961203 return true;
11971204 } else {
@@ -1203,15 +1210,12 @@
12041211 $checkedgroups = array_unique( array_merge( $groups, $checkedgroups ) );
12051212
12061213 //Mmmmmm. Tail recursion. Tasty.
1207 - if ( $this->searchNestedGroups( $ldapconn, $groupstocheck, $checkedgroups ) ) {
1208 - return true;
1209 - } else {
1210 - return false;
1211 - }
 1214+ return $this->searchNestedGroups( $ldapconn, $groupstocheck, $checkedgroups );
12121215 }
12131216
12141217 /**
1215 - * Helper function for isMemberOfRequiredLdapGroup and searchNestedGroups
 1218+ * Helper function for isMemberOfRequiredLdapGroup and searchNestedGroups. Returns
 1219+ * a list of groups the user is in, all munged to lowercase.
12161220 * Sets $this->foundUserLDAPGroups
12171221 *
12181222 * @param resource $ldapconn
@@ -1220,7 +1224,7 @@
12211225 * @access private
12221226 */
12231227 function getUserGroups( $ldapconn, $dn, $getShortnames = false ) {
1224 - $this->printDebug( "Entering getUserGroups", 1 );
 1228+ $this->printDebug( "Entering getUserGroups", self::NONSENSITIVE );
12251229
12261230 //Let's return the saved groups if they are available
12271231 if ( $getShortnames ) {
@@ -1256,7 +1260,9 @@
12571261 }
12581262
12591263 /**
1260 - * Helper function for retrieving all LDAP groups
 1264+ * Helper function for retrieving all LDAP groups. Returns
 1265+ * a list of all groups in the LDAP server, under the appropriate
 1266+ * basedn, all munged to lowercase.
12611267 * Sets $this->foundAllLDAPGroups
12621268 *
12631269 * @param resource $ldapconn
@@ -1265,7 +1271,7 @@
12661272 * @access private
12671273 */
12681274 function getAllGroups( $ldapconn, $getShortnames = false ) {
1269 - $this->printDebug( "Entering getAllGroups", 1 );
 1275+ $this->printDebug( "Entering getAllGroups", self::NONSENSITIVE );
12701276
12711277 //Let's return the saved groups if they are available
12721278 if ( $getShortnames ) {
@@ -1310,13 +1316,12 @@
13111317 * @access private
13121318 */
13131319 function getGroups( $ldapconn, $dn ) {
1314 - global $wgLDAPBaseDNs;
13151320 global $wgLDAPGroupObjectclass, $wgLDAPGroupAttribute, $wgLDAPGroupNameAttribute;
13161321 global $wgLDAPProxyAgent, $wgLDAPProxyAgentPassword;
13171322
1318 - $this->printDebug( "Entering getGroups", 1 );
 1323+ $this->printDebug( "Entering getGroups", self::NONSENSITIVE );
13191324
1320 - $base = $wgLDAPBaseDNs[$_SESSION['wsDomain']];
 1325+ $base = $this->getBaseDN( self::GROUPDN );
13211326 $objectclass = $wgLDAPGroupObjectclass[$_SESSION['wsDomain']];
13221327 $attribute = $wgLDAPGroupAttribute[$_SESSION['wsDomain']];
13231328 $nameattribute = $wgLDAPGroupNameAttribute[$_SESSION['wsDomain']];
@@ -1324,19 +1329,19 @@
13251330 //Search for the groups this user is in
13261331 $filter = "(&($attribute=" . $this->getLdapEscapedString( $dn ) . ")(objectclass=$objectclass))";
13271332
1328 - $this->printDebug( "Search string: $filter", 2 );
 1333+ $this->printDebug( "Search string: $filter", self::SENSITIVE );
13291334
13301335 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
13311336 //We'll try to bind as the proxyagent as the proxyagent should normally have more
13321337 //rights than the user. If the proxyagent fails to bind, we will still be able
13331338 //to search as the normal user (which is why we don't return on fail).
1334 - $this->printDebug( "Binding as the proxyagentDN", 1 );
 1339+ $this->printDebug( "Binding as the proxyagentDN", self::NONSENSITIVE );
13351340 $bind = $this->bindAs( $ldapconn, $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
13361341 }
13371342
13381343 $info = @ldap_search( $ldapconn, $base, $filter );
13391344 if ( !$info ) {
1340 - $this->printDebug( "No entries returned from search.", 2 );
 1345+ $this->printDebug( "No entries returned from search.", self::SENSITIVE );
13411346
13421347 //Return an array with two empty arrays so that other functions
13431348 //don't error out.
@@ -1363,8 +1368,8 @@
13641369 array_push( $both_groups, $groups );
13651370 array_push( $both_groups, $shortnamegroups );
13661371
1367 - $this->printDebug( "Returned groups:" . implode( ",", $groups ) . "", 2 );
1368 - $this->printDebug( "Returned groups:" . implode( ",", $shortnamegroups ) . "", 2 );
 1372+ $this->printDebug( "Returned groups:" . implode( ",", $groups ) . "", self::SENSITIVE );
 1373+ $this->printDebug( "Returned groups:" . implode( ",", $shortnamegroups ) . "", self::SENSITIVE );
13691374
13701375 return $both_groups;
13711376 }
@@ -1378,7 +1383,7 @@
13791384 * @access private
13801385 */
13811386 function hasLDAPGroup( $group ) {
1382 - $this->printDebug( "Entering hasLDAPGroup", 1 );
 1387+ $this->printDebug( "Entering hasLDAPGroup", self::NONSENSITIVE );
13831388
13841389 return in_array( strtolower( $group ), $this->userLDAPGroups );
13851390 }
@@ -1391,7 +1396,7 @@
13921397 * @access private
13931398 */
13941399 function isLDAPGroup( $group ) {
1395 - $this->printDebug( "Entering isLDAPGroup", 1 );
 1400+ $this->printDebug( "Entering isLDAPGroup", self::NONSENSITIVE );
13961401
13971402 return in_array( strtolower( $group ), $this->allLDAPGroups );
13981403 }
@@ -1404,34 +1409,34 @@
14051410 * @access private
14061411 */
14071412 function setGroups( &$user ) {
1408 - $this->printDebug( "Pulling groups from LDAP.", 1 );
 1413+ $this->printDebug( "Pulling groups from LDAP.", self::NONSENSITIVE );
14091414
14101415 # add groups permissions
14111416 $localAvailGrps = $user->getAllGroups();
14121417 $localUserGrps = $user->getEffectiveGroups();
14131418
1414 - $this->printDebug( "Available groups are: " . implode( ",", $localAvailGrps ) . "", 1 );
1415 - $this->printDebug( "Effective groups are: " . implode( ",", $localUserGrps ) . "", 1 );
 1419+ $this->printDebug( "Available groups are: " . implode( ",", $localAvailGrps ) . "", self::NONSENSITIVE );
 1420+ $this->printDebug( "Effective groups are: " . implode( ",", $localUserGrps ) . "", self::NONSENSITIVE );
14161421
14171422 # note: $localUserGrps does not need to be updated with $cGroup added,
14181423 # as $localAvailGrps contains $cGroup only once.
14191424 foreach ( $localAvailGrps as $cGroup ) {
14201425 # did we once add the user to the group?
14211426 if ( in_array( $cGroup,$localUserGrps ) ) {
1422 - $this->printDebug( "Checking to see if we need to remove user from: $cGroup", 1 );
 1427+ $this->printDebug( "Checking to see if we need to remove user from: $cGroup", self::NONSENSITIVE );
14231428 if ( ( !$this->hasLDAPGroup( $cGroup ) ) && ( $this->isLDAPGroup( $cGroup ) ) ) {
1424 - $this->printDebug( "Removing user from: $cGroup", 1 );
 1429+ $this->printDebug( "Removing user from: $cGroup", self::NONSENSITIVE );
14251430 # the ldap group overrides the local group
14261431 # so as the user is currently not a member of the ldap group, he shall be removed from the local group
14271432 $user->removeGroup( $cGroup );
14281433 }
14291434 } else { # no, but maybe the user has recently been added to the ldap group?
1430 - $this->printDebug( "Checking to see if user is in: $cGroup", 1 );
 1435+ $this->printDebug( "Checking to see if user is in: $cGroup", self::NONSENSITIVE );
14311436 if ( $this->hasLDAPGroup( $cGroup ) ) {
1432 - $this->printDebug( "Adding user to: $cGroup", 1 );
 1437+ $this->printDebug( "Adding user to: $cGroup", self::NONSENSITIVE );
14331438 # so use the addGroup function
14341439 $user->addGroup( $cGroup );
1435 - # completedfor $cGroup.
 1440+ # completed for $cGroup.
14361441 }
14371442 }
14381443 }
@@ -1447,13 +1452,14 @@
14481453 function getPasswordHash( $password ) {
14491454 global $wgLDAPPasswordHash;
14501455
1451 - $this->printDebug( "Entering getPasswordHash", 1 );
 1456+ $this->printDebug( "Entering getPasswordHash", self::NONSENSITIVE );
14521457
14531458 if ( isset( $wgLDAPPasswordHash[$_SESSION['wsDomain']] ) ) {
14541459 $hashtouse = $wgLDAPPasswordHash[$_SESSION['wsDomain']];
14551460 } else {
14561461 $hashtouse = '';
14571462 }
 1463+
14581464 //Set the password hashing based upon admin preference
14591465 switch ( $hashtouse ) {
14601466 case 'crypt':
@@ -1463,11 +1469,12 @@
14641470 $pass = $password;
14651471 break;
14661472 default:
1467 - $pwd_md5 = base64_encode( pack( 'H*',sha1( $password ) ) );
1468 - $pass = "{SHA}".$pwd_md5;
 1473+ $pwd_sha = base64_encode( pack( 'H*',sha1( $password ) ) );
 1474+ $pass = "{SHA}".$pwd_sha;
14691475 break;
14701476 }
1471 - $this->printDebug( "Password is $pass", 3 );
 1477+
 1478+ $this->printDebug( "Password is $pass", self::HIGHLYSENSITIVE );
14721479 return $pass;
14731480 }
14741481
@@ -1505,8 +1512,8 @@
15061513 $bind = @ldap_bind( $ldapconn, $userdn, $password );
15071514 }
15081515 if ( !$bind ) {
1509 - $this->printDebug( "Failed to bind as $userdn", 1 );
1510 - $this->printDebug( "with password: $password", 3 );
 1516+ $this->printDebug( "Failed to bind as $userdn", self::NONSENSITIVE );
 1517+ $this->printDebug( "with password: $password", self::HIGHLYSENSITIVE );
15111518 return false;
15121519 }
15131520 return true;
@@ -1543,6 +1550,53 @@
15441551 );
15451552 }
15461553
 1554+ /**
 1555+ * Returns a basedn by the type of entry we are searching for.
 1556+ *
 1557+ * @param int $type
 1558+ * @return string
 1559+ * @access private
 1560+ */
 1561+ function getBaseDN ( $type ) {
 1562+ global $wgLDAPBaseDNs, $wgLDAPGroupBaseDNs, $wgLDAPUserBaseDNs;
 1563+
 1564+ $this->printDebug( "Entering getBaseDN", self::NONSENSITIVE );
 1565+
 1566+ $ret = '';
 1567+ switch( $type ) {
 1568+ case self::USERDN:
 1569+ if ( isset( $wgLDAPUserBaseDNs[$_SESSION['wsDomain']] ) ) {
 1570+ $ret = $wgLDAPUserBaseDNs[$_SESSION['wsDomain']];
 1571+ }
 1572+ break;
 1573+ case self::GROUPDN:
 1574+ if ( isset( $wgLDAPGroupBaseDNs[$_SESSION['wsDomain']] ) ) {
 1575+ $ret = $wgLDAPGroupBaseDNs[$_SESSION['wsDomain']];
 1576+ }
 1577+ break;
 1578+ case self::DEFAULTDN:
 1579+ if ( isset( $wgLDAPBaseDNs[$_SESSION['wsDomain']] ) ) {
 1580+ $ret = $wgLDAPBaseDNs[$_SESSION['wsDomain']];
 1581+ $this->printDebug( "basedn is $ret", self::NONSENSITIVE );
 1582+ return $ret;
 1583+ } else {
 1584+ $this->printDebug( "basedn is not set.", self::NONSENSITIVE );
 1585+ return '';
 1586+ }
 1587+ break;
 1588+ }
 1589+
 1590+ if ( $ret == '' ) {
 1591+ $this->printDebug( "basedn is not set for this type of entry, trying to get the default basedn.", self::NONSENSITIVE );
 1592+ // We will never reach here if $type is self::DEFAULTDN, so to avoid code
 1593+ // code duplication, we'll get the default by re-calling the function.
 1594+ return $this->getBaseDN( self::DEFAULTDN );
 1595+ } else {
 1596+ $this->printDebug( "basedn is $ret", self::NONSENSITIVE );
 1597+ return $ret;
 1598+ }
 1599+ }
 1600+
15471601 }
15481602
15491603 /**
@@ -1572,23 +1626,23 @@
15731627
15741628 $wgAuth = new LdapAuthenticationPlugin();
15751629
1576 - $wgAuth->printDebug( "Entering AutoAuthSetup.", 1 );
 1630+ $wgAuth->printDebug( "Entering AutoAuthSetup.", self::NONSENSITIVE );
15771631
15781632 //We may add quite a few different auto authenticate methods in the
15791633 //future, let's make it easy to support.
15801634 switch( $wgLDAPAutoAuthMethod ) {
15811635 case "smartcard":
1582 - $wgAuth->printDebug( "Allowing smartcard authentication.", 1 );
1583 - $wgAuth->printDebug( "wgLDAPSSLUsername = $wgLDAPSSLUsername", 2 );
 1636+ $wgAuth->printDebug( "Allowing smartcard authentication.", self::NONSENSITIVE );
 1637+ $wgAuth->printDebug( "wgLDAPSSLUsername = $wgLDAPSSLUsername", self::SENSITIVE );
15841638
15851639 if( $wgLDAPSSLUsername != null ) {
1586 - $wgAuth->printDebug( "wgLDAPSSLUsername is not null, adding hooks.", 1 );
 1640+ $wgAuth->printDebug( "wgLDAPSSLUsername is not null, adding hooks.", self::NONSENSITIVE );
15871641 $wgHooks['AutoAuthenticate'][] = 'SSLAuth'; /* Hook for magical authN */
15881642 $wgHooks['PersonalUrls'][] = 'NoLogout'; /* Disallow logout link */
15891643 }
15901644 break;
15911645 default:
1592 - $wgAuth->printDebug( "Not using any AutoAuthentication methods.", 1 );
 1646+ $wgAuth->printDebug( "Not using any AutoAuthentication methods.", self::NONSENSITIVE );
15931647 }
15941648 }
15951649
@@ -1607,15 +1661,15 @@
16081662 global $wgUser;
16091663 global $wgAuth;
16101664
1611 - $wgAuth->printDebug( "Entering SSLAuth.", 1 );
 1665+ $wgAuth->printDebug( "Entering SSLAuth.", self::NONSENSITIVE );
16121666
16131667 //Give us a user, see if we're around
1614 - $tmpuser = User::newFromSession();
 1668+ $tmpuser = User::LoadFromSession();
16151669
16161670 //They already with us? If so, quit this function.
16171671 if( $tmpuser->isLoggedIn() ) {
1618 - $wgAuth->printDebug( "User is already logged in.", 1 );
1619 - return false;
 1672+ $wgAuth->printDebug( "User is already logged in.", self::NONSENSITIVE );
 1673+ return;
16201674 }
16211675
16221676 //Let regular authentication plugins configure themselves for auto
@@ -1623,39 +1677,39 @@
16241678 $wgAuth->autoAuthSetup();
16251679
16261680 //The user hasn't already been authenticated, let's check them
1627 - $wgAuth->printDebug( "User is not logged in, we need to authenticate", 1 );
 1681+ $wgAuth->printDebug( "User is not logged in, we need to authenticate", self::NONSENSITIVE );
16281682 $authenticated = $wgAuth->authenticate( $wgLDAPSSLUsername );
16291683 if ( !$authenticated ) {
16301684 //If the user doesn't exist in LDAP, there isn't much reason to
16311685 //go any further.
1632 - $wgAuth->printDebug("User wasn't found in LDAP, exiting.", 1 );
1633 - return false;
 1686+ $wgAuth->printDebug("User wasn't found in LDAP, exiting.", self::NONSENSITIVE );
 1687+ return;
16341688 }
16351689
16361690 //We need the username that MediaWiki will always use, *not* the one we
16371691 //get from LDAP.
16381692 $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPSSLUsername );
16391693
1640 - $wgAuth->printDebug( "User exists in LDAP; finding the user by name in MediaWiki.", 1 );
 1694+ $wgAuth->printDebug( "User exists in LDAP; finding the user by name in MediaWiki.", self::NONSENSITIVE );
16411695
16421696 //Is the user already in the database?
16431697 $tmpuser = User::newFromName( $mungedUsername );
16441698
16451699 if ( $tmpuser == null ) {
1646 - $wgAuth->printDebug( "Username is not a valid MediaWiki username.", 1 );
1647 - return false;
 1700+ $wgAuth->printDebug( "Username is not a valid MediaWiki username.", self::NONSENSITIVE );
 1701+ return;
16481702 }
16491703
16501704 //If exists, log them in
16511705 if( $tmpuser->getID() != 0 ) {
1652 - $wgAuth->printDebug( "User exists in local database, logging in.", 1 );
 1706+ $wgAuth->printDebug( "User exists in local database, logging in.", self::NONSENSITIVE );
16531707 $wgUser = &$tmpuser;
16541708 $wgAuth->updateUser( $wgUser );
16551709 $wgUser->setCookies();
16561710 $wgUser->setupSession();
1657 - return true;
 1711+ return;
16581712 }
1659 - $wgAuth->printDebug( "User does not exist in local database; creating.", 1 );
 1713+ $wgAuth->printDebug( "User does not exist in local database; creating.", self::NONSENSITIVE );
16601714
16611715 //Require SpecialUserlogin so that we can get a loginForm
16621716 require_once( 'SpecialUserlogin.php' );
@@ -1670,7 +1724,7 @@
16711725 $wgLangUnset = true;
16721726 }
16731727
1674 - $wgAuth->printDebug( "Creating LoginForm.", 1 );
 1728+ $wgAuth->printDebug( "Creating LoginForm.", self::NONSENSITIVE );
16751729
16761730 //This creates our form that'll let us create a new user in the database
16771731 $lf = new LoginForm( $wgRequest );
@@ -1679,7 +1733,7 @@
16801734 $wgUser = &$tmpuser;
16811735 $wgUser->setName( $wgContLang->ucfirst( $mungedUsername ) );
16821736
1683 - $wgAuth->printDebug( "Creating User.", 1 );
 1737+ $wgAuth->printDebug( "Creating User.", self::NONSENSITIVE );
16841738
16851739 //Create the user
16861740 $lf->initUser( $wgUser );
@@ -1687,7 +1741,5 @@
16881742 //Initialize the user
16891743 $wgUser->setupSession();
16901744 $wgUser->setCookies();
1691 -
1692 - return true;
16931745 }
16941746 ?>

Status & tagging log