r65178 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65177‎ | r65178 | r65179 >
Date:20:12, 17 April 2010
Author:reedy
Status:ok
Tags:
Comment:
Stylize LdapAuthentication
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)
  • /trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php
@@ -16,8 +16,8 @@
1717 $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE );
1818
1919 if ( version_compare( $wgVersion, '1.14.0', '<' ) ) {
20 - //The following section is a hack to determine whether or not
21 - //the user is logged in. We need a core fix to make this simpler.
 20+ // The following section is a hack to determine whether or not
 21+ // the user is logged in. We need a core fix to make this simpler.
2222 if ( isset( $_SESSION['wsUserID'] ) ) {
2323 $user->setID( $_SESSION['wsUserID'] );
2424 if ( $user->loadFromId() ) {
@@ -39,22 +39,22 @@
4040
4141 $wgAuth->printDebug( "User isn't logged in, calling setup.", NONSENSITIVE );
4242
43 - //Let regular authentication plugins configure themselves for auto
44 - //authentication chaining
 43+ // Let regular authentication plugins configure themselves for auto
 44+ // authentication chaining
4545 $wgAuth->autoAuthSetup();
4646
4747 $wgAuth->printDebug( "Calling authenticate with username ($wgLDAPAutoAuthUsername).", NONSENSITIVE );
48 - //The user hasn't already been authenticated, let's check them
 48+ // The user hasn't already been authenticated, let's check them
4949 $authenticated = $wgAuth->authenticate( $wgLDAPAutoAuthUsername );
5050 if ( !$authenticated ) {
51 - //If the user doesn't exist in LDAP, there isn't much reason to
52 - //go any further.
53 - $wgAuth->printDebug("User wasn't found in LDAP, exiting.", NONSENSITIVE );
 51+ // If the user doesn't exist in LDAP, there isn't much reason to
 52+ // go any further.
 53+ $wgAuth->printDebug( "User wasn't found in LDAP, exiting.", NONSENSITIVE );
5454 return false;
5555 }
5656
57 - //We need the username that MediaWiki will always use, *not* the one we
58 - //get from LDAP.
 57+ // We need the username that MediaWiki will always use, *not* the one we
 58+ // get from LDAP.
5959 $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPAutoAuthUsername );
6060
6161 $wgAuth->printDebug( "User exists in LDAP; finding the user by name ($mungedUsername) in MediaWiki.", NONSENSITIVE );
@@ -62,8 +62,8 @@
6363 $localId = User::idFromName( $mungedUsername );
6464 $wgAuth->printDebug( "Got id ($localId).", NONSENSITIVE );
6565
66 - //Is the user already in the database?
67 - if( !$localId ) {
 66+ // Is the user already in the database?
 67+ if ( !$localId ) {
6868 $userAdded = self::attemptAddUser( $user, $mungedUsername );
6969 if ( !$userAdded ) {
7070 $result = false;
Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -53,44 +53,44 @@
5454 'url' => 'http://www.mediawiki.org/wiki/Extension:LDAP_Authentication',
5555 );
5656
57 -$dir = dirname(__FILE__) . '/';
 57+$dir = dirname( __FILE__ ) . '/';
5858 $wgExtensionMessagesFiles['LdapAuthentication'] = $dir . 'LdapAuthentication.i18n.php';
5959
60 -//constants for search base
61 -define("GROUPDN", 0);
62 -define("USERDN", 1);
63 -define("DEFAULTDN", 2);
 60+// constants for search base
 61+define( "GROUPDN", 0 );
 62+define( "USERDN", 1 );
 63+define( "DEFAULTDN", 2 );
6464
65 -//constants for error reporting
66 -define("NONSENSITIVE", 1);
67 -define("SENSITIVE", 2);
68 -define("HIGHLYSENSITIVE", 3);
 65+// constants for error reporting
 66+define( "NONSENSITIVE", 1 );
 67+define( "SENSITIVE", 2 );
 68+define( "HIGHLYSENSITIVE", 3 );
6969
7070 class LdapAuthenticationPlugin extends AuthPlugin {
7171
72 - //ldap connection resource
 72+ // ldap connection resource
7373 var $ldapconn;
7474
75 - //preferences
 75+ // preferences
7676 var $email, $lang, $realname, $nickname, $externalid;
7777
78 - //username pulled from ldap
 78+ // username pulled from ldap
7979 var $LDAPUsername;
8080
81 - //userdn pulled from ldap
 81+ // userdn pulled from ldap
8282 var $userdn;
8383
84 - //groups pulled from ldap
 84+ // groups pulled from ldap
8585 var $userLDAPGroups;
8686 var $allLDAPGroups;
8787
88 - //boolean to test for failed auth
 88+ // boolean to test for failed auth
8989 var $authFailed;
9090
91 - //boolean to test for fetched user info
 91+ // boolean to test for fetched user info
9292 var $fetchedUserInfo;
9393
94 - //the user's entry and all attributes
 94+ // the user's entry and all attributes
9595 var $userInfo;
9696
9797 function LdapAuthenticationPlugin() {
@@ -111,11 +111,11 @@
112112
113113 $this->printDebug( "Entering userExists", NONSENSITIVE );
114114
115 - //If we can't add LDAP users, we don't really need to check
116 - //if the user exists, the authenticate method will do this for
117 - //us. This will decrease hits to the LDAP server.
118 - //We do however, need to use this if we are using auto authentication.
119 - if ( ( !isset( $wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) || !$wgLDAPAddLDAPUsers[$_SESSION['wsDomain']]) && !$this->useAutoAuth() ) {
 115+ // If we can't add LDAP users, we don't really need to check
 116+ // if the user exists, the authenticate method will do this for
 117+ // us. This will decrease hits to the LDAP server.
 118+ // We do however, need to use this if we are using auto authentication.
 119+ if ( ( !isset( $wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) || !$wgLDAPAddLDAPUsers[$_SESSION['wsDomain']] ) && !$this->useAutoAuth() ) {
120120 return true;
121121 }
122122
@@ -125,20 +125,20 @@
126126
127127 $searchstring = $this->getSearchString( $this->ldapconn, $username );
128128
129 - //If we are using auto authentication, and we got
130 - //anything back, then the user exists.
 129+ // If we are using auto authentication, and we got
 130+ // anything back, then the user exists.
131131 if ( $this->useAutoAuth() && $searchstring != '' ) {
132 - //getSearchString is going to bind, but will not unbind
133 - //Let's clean up
 132+ // getSearchString is going to bind, but will not unbind
 133+ // Let's clean up
134134 @ldap_unbind();
135135 return true;
136136 }
137137
138 - //Search for the entry.
 138+ // Search for the entry.
139139 $entry = @ldap_read( $this->ldapconn, $searchstring, "objectclass=*" );
140140
141 - //getSearchString is going to bind, but will not unbind
142 - //Let's clean up
 141+ // getSearchString is going to bind, but will not unbind
 142+ // Let's clean up
143143 @ldap_unbind();
144144 if ( !$entry ) {
145145 $this->printDebug( "Did not find a matching user in LDAP", NONSENSITIVE );
@@ -171,14 +171,14 @@
172172 return false;
173173 }
174174
175 - //If the admin didn't set an encryption type, we default to tls
 175+ // If the admin didn't set an encryption type, we default to tls
176176 if ( isset( $wgLDAPEncryptionType[$_SESSION['wsDomain']] ) ) {
177177 $encryptionType = $wgLDAPEncryptionType[$_SESSION['wsDomain']];
178178 } else {
179179 $encryptionType = "tls";
180180 }
181181
182 - //Set the server string depending on whether we use ssl or not
 182+ // Set the server string depending on whether we use ssl or not
183183 switch( $encryptionType ) {
184184 case "ldapi":
185185 # this is a really dirty place to put this,
@@ -195,8 +195,8 @@
196196 $serverpre = "ldap://";
197197 }
198198
199 - //Make a space separated list of server strings with the ldap:// or ldaps://
200 - //string added.
 199+ // Make a space separated list of server strings with the ldap:// or ldaps://
 200+ // string added.
201201 $servers = "";
202202 $tmpservers = $wgLDAPServerNames[$_SESSION['wsDomain']];
203203 $tok = strtok( $tmpservers, " " );
@@ -204,14 +204,14 @@
205205 $servers = $servers . " " . $serverpre . $tok;
206206 $tok = strtok( " " );
207207 }
208 - $servers = rtrim($servers);
 208+ $servers = rtrim( $servers );
209209
210210 $this->printDebug( "Using servers: $servers", SENSITIVE );
211211
212 - //Connect and set options
 212+ // Connect and set options
213213 $this->ldapconn = @ldap_connect( $servers );
214 - ldap_set_option( $this->ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
215 - ldap_set_option( $this->ldapconn, LDAP_OPT_REFERRALS, 0);
 214+ ldap_set_option( $this->ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3 );
 215+ ldap_set_option( $this->ldapconn, LDAP_OPT_REFERRALS, 0 );
216216
217217 if ( isset( $wgLDAPOptions[$_SESSION['wsDomain']] ) ) {
218218 $options = $wgLDAPOptions[$_SESSION['wsDomain']];
@@ -222,7 +222,7 @@
223223 }
224224 }
225225
226 - //TLS needs to be started after the connection is made
 226+ // TLS needs to be started after the connection is made
227227 if ( $encryptionType == "tls" ) {
228228 $this->printDebug( "Using TLS", SENSITIVE );
229229 if ( !ldap_start_tls( $this->ldapconn ) ) {
@@ -244,7 +244,7 @@
245245 * @return bool
246246 * @access public
247247 */
248 - function authenticate( $username, $password='' ) {
 248+ function authenticate( $username, $password = '' ) {
249249 global $wgLDAPAuthAttribute;
250250 global $wgLDAPAutoAuthUsername;
251251 global $wgLDAPLowerCaseUsername;
@@ -252,25 +252,25 @@
253253
254254 $this->printDebug( "Entering authenticate", NONSENSITIVE );
255255
256 - //We don't handle local authentication
 256+ // We don't handle local authentication
257257 if ( 'local' == $_SESSION['wsDomain'] ) {
258258 $this->printDebug( "User is using a local domain", SENSITIVE );
259259 return false;
260260 }
261261
262 - //If the user is using auto authentication, we need to ensure
263 - //that he/she isn't trying to fool us by sending a username other
264 - //than the one the web server got from the auto-authentication method.
 262+ // If the user is using auto authentication, we need to ensure
 263+ // that he/she isn't trying to fool us by sending a username other
 264+ // than the one the web server got from the auto-authentication method.
265265 if ( $this->useAutoAuth() && $wgLDAPAutoAuthUsername != $username ) {
266266 $this->printDebug( "The username provided ($username) doesn't match the username provided by the webserver ($wgLDAPAutoAuthUsername). The user is probably trying to log in to the auto-authentication domain with password authentication via the wiki. Denying access.", SENSITIVE );
267267 return false;
268268 }
269269
270 - //We need to ensure that if we require a password, that it is
271 - //not blank. We don't allow blank passwords, so we are being
272 - //tricked if someone is supplying one when using password auth.
273 - //Smartcard authentication uses a pin, and does not require
274 - //a password to be given; a blank password here is wanted.
 270+ // We need to ensure that if we require a password, that it is
 271+ // not blank. We don't allow blank passwords, so we are being
 272+ // tricked if someone is supplying one when using password auth.
 273+ // Smartcard authentication uses a pin, and does not require
 274+ // a password to be given; a blank password here is wanted.
275275 if ( '' == $password && !$this->useAutoAuth() ) {
276276 $this->printDebug( "User used a blank password", NONSENSITIVE );
277277 return false;
@@ -280,10 +280,10 @@
281281 if ( $this->ldapconn ) {
282282 $this->printDebug( "Connected successfully", NONSENSITIVE );
283283
284 - //Mediawiki munges the username before authenticate is called,
285 - //this can mess with authentication, group pulling/restriction,
286 - //preference pulling, etc. Let's allow the admin to use
287 - //a lowercased username if needed.
 284+ // Mediawiki munges the username before authenticate is called,
 285+ // this can mess with authentication, group pulling/restriction,
 286+ // preference pulling, etc. Let's allow the admin to use
 287+ // a lowercased username if needed.
288288 if ( isset( $wgLDAPLowerCaseUsername[$_SESSION['wsDomain']] ) && $wgLDAPLowerCaseUsername[$_SESSION['wsDomain']] ) {
289289 $this->printDebug( "Lowercasing the username: $username", NONSENSITIVE );
290290 $username = strtolower( $username );
@@ -291,9 +291,9 @@
292292
293293 $this->userdn = $this->getSearchString( $username );
294294
295 - //It is possible that getSearchString will return an
296 - //empty string; if this happens, the bind will ALWAYS
297 - //return true, and will let anyone in!
 295+ // It is possible that getSearchString will return an
 296+ // empty string; if this happens, the bind will ALWAYS
 297+ // return true, and will let anyone in!
298298 if ( '' == $this->userdn ) {
299299 $this->printDebug( "User DN is blank", NONSENSITIVE );
300300 @ldap_unbind();
@@ -301,12 +301,12 @@
302302 return false;
303303 }
304304
305 - //If we are using password authentication, we need to bind as the
306 - //user to make sure the password is correct.
 305+ // If we are using password authentication, we need to bind as the
 306+ // user to make sure the password is correct.
307307 if ( !$this->useAutoAuth() ) {
308308 $this->printDebug( "Binding as the user", NONSENSITIVE );
309309
310 - //Let's see if the user can authenticate.
 310+ // Let's see if the user can authenticate.
311311 $bind = $this->bindAs( $this->userdn, $password );
312312 if ( !$bind ) {
313313 $this->markAuthFailed();
@@ -315,12 +315,12 @@
316316
317317 $this->printDebug( "Bound successfully", NONSENSITIVE );
318318
319 - if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
 319+ if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
320320 $ss = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
321321 if ( strstr( $ss, "@" ) || strstr( $ss, '\\' ) ) {
322 - //We are most likely configured using USER-NAME@DOMAIN, or
323 - //DOMAIN\\USER-NAME.
324 - //Get the user's full DN so we can search for groups and such.
 322+ // We are most likely configured using USER-NAME@DOMAIN, or
 323+ // DOMAIN\\USER-NAME.
 324+ // Get the user's full DN so we can search for groups and such.
325325 $this->userdn = $this->getUserDN( $username );
326326 $this->printDebug( "Pulled the user's DN: $this->userdn", NONSENSITIVE );
327327 }
@@ -369,7 +369,7 @@
370370 }
371371 $this->printDebug( "Authentication passed", NONSENSITIVE );
372372
373 - //We made it this far; the user authenticated and didn't fail any checks, so he/she gets in.
 373+ // We made it this far; the user authenticated and didn't fail any checks, so he/she gets in.
374374 return true;
375375 }
376376
@@ -406,8 +406,8 @@
407407 if ( isset( $wgLDAPAutoAuthDomain ) ) {
408408 $this->printDebug( "Allowing auto-authentication login, removing the domain from the list.", NONSENSITIVE );
409409
410 - //There is no reason for people to log in directly to the wiki if the are using an
411 - //auto-authentication domain. If they try to, they are probably up to something fishy.
 410+ // There is no reason for people to log in directly to the wiki if the are using an
 411+ // auto-authentication domain. If they try to, they are probably up to something fishy.
412412 unset( $tempDomArr[array_search( $wgLDAPAutoAuthDomain, $tempDomArr )] );
413413 }
414414
@@ -451,21 +451,21 @@
452452 if ( $_SESSION['wsDomain'] == 'local' ) {
453453 $this->printDebug( "User is using a local domain", NONSENSITIVE );
454454
455 - //We don't set local passwords, but we don't want the wiki
456 - //to send the user a failure.
 455+ // We don't set local passwords, but we don't want the wiki
 456+ // to send the user a failure.
457457 return true;
458458 } else if ( !isset( $wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) || !$wgLDAPUpdateLDAP[$_SESSION['wsDomain']] ) {
459459 $this->printDebug( "Wiki is set to not allow updates", NONSENSITIVE );
460460
461 - //We aren't allowing the user to change his/her own password
 461+ // We aren't allowing the user to change his/her own password
462462 return false;
463463 }
464464
465465 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
466466 $this->printDebug( "Wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE );
467467
468 - //We can't change a user's password without an account that is
469 - //allowed to do it.
 468+ // We can't change a user's password without an account that is
 469+ // allowed to do it.
470470 return false;
471471 }
472472
@@ -484,13 +484,13 @@
485485
486486 $values["userpassword"] = $pass;
487487
488 - //Blank out the password in the database. We don't want to save
489 - //domain credentials for security reasons.
 488+ // Blank out the password in the database. We don't want to save
 489+ // domain credentials for security reasons.
490490 $password = '';
491491
492492 $success = @ldap_modify( $this->ldapconn, $this->userdn, $values );
493493
494 - //Let's clean up
 494+ // Let's clean up
495495 @ldap_unbind();
496496 if ( $success ) {
497497 $this->printDebug( "Successfully modified the user's password", NONSENSITIVE );
@@ -512,7 +512,7 @@
513513 * @param User $user
514514 * @return bool
515515 * @access public
516 - */
 516+ */
517517 function updateExternalDB( $user ) {
518518 global $wgLDAPUpdateLDAP;
519519 global $wgLDAPWriterDN, $wgLDAPWriterPassword;
@@ -523,16 +523,16 @@
524524 $_SESSION['wsDomain'] == 'local' ) {
525525 $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing updates", NONSENSITIVE );
526526
527 - //We don't handle local preferences, but we don't want the
528 - //wiki to return an error.
 527+ // We don't handle local preferences, but we don't want the
 528+ // wiki to return an error.
529529 return true;
530530 }
531531
532532 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
533533 $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE );
534534
535 - //We can't modify LDAP preferences if we don't have a user
536 - //capable of editing LDAP attributes.
 535+ // We can't modify LDAP preferences if we don't have a user
 536+ // capable of editing LDAP attributes.
537537 return false;
538538 }
539539
@@ -578,7 +578,7 @@
579579 *
580580 * @return bool
581581 * @access public
582 - */
 582+ */
583583 function canCreateAccounts() {
584584 global $wgLDAPAddLDAPUsers;
585585
@@ -596,7 +596,7 @@
597597 *
598598 * @return bool
599599 * @access public
600 - */
 600+ */
601601 function allowPasswordChange() {
602602 global $wgLDAPUpdateLDAP, $wgLDAPMailPassword;
603603 global $wgLDAPUseLocal;
@@ -606,7 +606,7 @@
607607 $retval = false;
608608
609609 // Local domains need to be able to change passwords
610 - if ( (isset($wgLDAPUseLocal) && $wgLDAPUseLocal) && 'local' == $_SESSION['wsDomain'] ) {
 610+ if ( ( isset( $wgLDAPUseLocal ) && $wgLDAPUseLocal ) && 'local' == $_SESSION['wsDomain'] ) {
611611 $retval = true;
612612 }
613613
@@ -643,22 +643,22 @@
644644 'local' == $_SESSION['wsDomain'] ) {
645645 $this->printDebug( "Either the user is using a local domain, or the wiki isn't allowing users to be added to LDAP", NONSENSITIVE );
646646
647 - //Tell the wiki not to return an error.
 647+ // Tell the wiki not to return an error.
648648 return true;
649649 }
650650
651651 if ( $wgLDAPRequiredGroups || $wgLDAPGroupDN ) {
652652 $this->printDebug( "The wiki is requiring users to be in specific groups, and cannot add users as this would be a security hole.", NONSENSITIVE );
653 - //It is possible that later we can add users into
654 - //groups, but since we don't support it, we don't want
655 - //to open holes!
 653+ // It is possible that later we can add users into
 654+ // groups, but since we don't support it, we don't want
 655+ // to open holes!
656656 return false;
657657 }
658658
659659 if ( !isset( $wgLDAPWriterDN[$_SESSION['wsDomain']] ) ) {
660660 $this->printDebug( "The wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE );
661661
662 - //We can't add users without an LDAP account capable of doing so.
 662+ // We can't add users without an LDAP account capable of doing so.
663663 return false;
664664 }
665665
@@ -681,7 +681,7 @@
682682 $username . "," . $wgLDAPWriteLocation[$_SESSION['wsDomain']];
683683 } else {
684684 $this->printDebug( "wgLDAPWriteLocation is not set, failing", NONSENSITIVE );
685 - //getSearchString will bind, but will not unbind
 685+ // getSearchString will bind, but will not unbind
686686 @ldap_unbind();
687687 return false;
688688 }
@@ -695,12 +695,12 @@
696696 return false;
697697 }
698698
699 - //Set up LDAP attributes
 699+ // Set up LDAP attributes
700700 $values["uid"] = $username;
701 - //sn is required for objectclass inetorgperson
 701+ // sn is required for objectclass inetorgperson
702702 $values["sn"] = $username;
703703 if ( '' != $this->email ) { $values["mail"] = $this->email; }
704 - if ( '' != $this->realname ) {$values["cn"] = $this->realname; }
 704+ if ( '' != $this->realname ) { $values["cn"] = $this->realname; }
705705 else { $values["cn"] = $username; }
706706 $values["userpassword"] = $pass;
707707 $values["objectclass"] = "inetorgperson";
@@ -772,15 +772,15 @@
773773
774774 $this->printDebug( "Entering updateUser", NONSENSITIVE );
775775
776 - if ($this->authFailed) {
 776+ if ( $this->authFailed ) {
777777 $this->printDebug( "User didn't successfully authenticate, exiting.", NONSENSITIVE );
778778 return;
779779 }
780780
781781 $saveSettings = false;
782782
783 - //If we aren't pulling preferences, we don't want to accidentally
784 - //overwrite anything.
 783+ // If we aren't pulling preferences, we don't want to accidentally
 784+ // overwrite anything.
785785 if ( ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] )
786786 || isset( $wgLDAPPreferences[$_SESSION['wsDomain']] ) ) {
787787 $this->printDebug( "Setting user preferences.", NONSENSITIVE );
@@ -838,7 +838,7 @@
839839
840840 $this->printDebug( "Entering initUser", NONSENSITIVE );
841841
842 - if ($this->authFailed) {
 842+ if ( $this->authFailed ) {
843843 $this->printDebug( "User didn't successfully authenticate, exiting.", NONSENSITIVE );
844844 return;
845845 }
@@ -848,15 +848,15 @@
849849 return;
850850 }
851851
852 - //We are creating an LDAP user, it is very important that we do
853 - //NOT set a local password because it could compromise the
854 - //security of our domain.
 852+ // We are creating an LDAP user, it is very important that we do
 853+ // NOT set a local password because it could compromise the
 854+ // security of our domain.
855855 $user->mPassword = '';
856856
857 - //The update user function does everything else we need done.
858 - $this->updateUser($user);
 857+ // The update user function does everything else we need done.
 858+ $this->updateUser( $user );
859859
860 - //updateUser() won't definately save the user's settings
 860+ // updateUser() won't definately save the user's settings
861861 $user->saveSettings();
862862 }
863863
@@ -898,22 +898,22 @@
899899 if ( $username != '' ) {
900900 $this->printDebug( "Username isn't empty.", NONSENSITIVE );
901901
902 - //We want to use the username returned by LDAP
903 - //if it exists
 902+ // We want to use the username returned by LDAP
 903+ // if it exists
904904 if ( $this->LDAPUsername != '' ) {
905905 $this->printDebug( "Using LDAPUsername.", NONSENSITIVE );
906906 $username = $this->LDAPUsername;
907907 }
908908
909 - if ( isset($_SESSION['wsDomain']) && 'local' != $_SESSION['wsDomain']) {
910 - //Change username to lowercase so that multiple user accounts
911 - //won't be created for the same user.
912 - //But don't do it for the local domain!
 909+ if ( isset( $_SESSION['wsDomain'] ) && 'local' != $_SESSION['wsDomain'] ) {
 910+ // Change username to lowercase so that multiple user accounts
 911+ // won't be created for the same user.
 912+ // But don't do it for the local domain!
913913 $username = strtolower( $username );
914914 }
915915
916 - //The wiki considers an all lowercase name to be invalid; need to
917 - //uppercase the first letter
 916+ // The wiki considers an all lowercase name to be invalid; need to
 917+ // uppercase the first letter
918918 $username[0] = strtoupper( $username[0] );
919919 }
920920
@@ -949,19 +949,19 @@
950950 $this->printDebug( "Entering getSearchString", NONSENSITIVE );
951951
952952 if ( isset( $wgLDAPSearchStrings[$_SESSION['wsDomain']] ) ) {
953 - //This is a straight bind
 953+ // This is a straight bind
954954 $this->printDebug( "Doing a straight bind", NONSENSITIVE );
955955
956956 $tmpuserdn = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
957957 $userdn = str_replace( "USER-NAME", $username, $tmpuserdn );
958958 } else {
959 - //This is a proxy bind, or an anonymous bind with a search
 959+ // This is a proxy bind, or an anonymous bind with a search
960960 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
961 - //This is a proxy bind
 961+ // This is a proxy bind
962962 $this->printDebug( "Doing a proxy bind", NONSENSITIVE );
963963 $bind = $this->bindAs( $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
964964 } else {
965 - //This is an anonymous bind
 965+ // This is an anonymous bind
966966 $this->printDebug( "Doing an anonymous bind", NONSENSITIVE );
967967 $bind = $this->bindAs();
968968 }
@@ -990,11 +990,11 @@
991991 global $wgLDAPSearchAttributes;
992992 global $wgLDAPAuthAttribute;
993993
994 - $this->printDebug("Entering getUserDN", NONSENSITIVE);
 994+ $this->printDebug( "Entering getUserDN", NONSENSITIVE );
995995
996 - //we need to do a subbase search for the entry
 996+ // we need to do a subbase search for the entry
997997
998 - //Auto auth needs to check LDAP for required attributes.
 998+ // Auto auth needs to check LDAP for required attributes.
999999 if ( ( isset( $wgLDAPAuthAttribute[$_SESSION['wsDomain']] ) )
10001000 && $this->useAutoAuth() ) {
10011001 $auth_filter = "(" . $wgLDAPAuthAttribute[$_SESSION['wsDomain']] . ")";
@@ -1021,8 +1021,8 @@
10221022 $this->userInfo = @ldap_get_entries( $this->ldapconn, $entry );
10231023 $this->fetchedUserInfo = true;
10241024
1025 - //This is a pretty useful thing to have for auto authentication,
1026 - //group checking, and pulling preferences.
 1025+ // This is a pretty useful thing to have for auto authentication,
 1026+ // group checking, and pulling preferences.
10271027 wfRunHooks( 'SetUsernameAttributeFromLDAP', array( &$this->LDAPUsername, $this->userInfo ) );
10281028 if ( !is_string( $this->LDAPUsername ) ) {
10291029 $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 );
@@ -1034,7 +1034,7 @@
10351035 }
10361036
10371037 function getUserInfo() {
1038 - //Don't fetch the same data more than once
 1038+ // Don't fetch the same data more than once
10391039 if ( $this->fetchedUserInfo ) {
10401040 return $this->userInfo;
10411041 }
@@ -1060,14 +1060,14 @@
10611061 global $wgLDAPPreferences;
10621062 global $wgLDAPRetrievePrefs;
10631063
1064 - $this->printDebug("Entering getPreferences", NONSENSITIVE);
 1064+ $this->printDebug( "Entering getPreferences", NONSENSITIVE );
10651065
10661066 $this->userInfo = $this->getUserInfo();
10671067 if ( is_null( $this->userInfo ) ) {
1068 - $this->printDebug("Failed to get preferences", NONSENSITIVE);
 1068+ $this->printDebug( "Failed to get preferences", NONSENSITIVE );
10691069 }
10701070
1071 - //Retrieve preferences
 1071+ // Retrieve preferences
10721072 if ( isset( $wgLDAPPreferences[$_SESSION['wsDomain']] ) ) {
10731073 $this->printDebug( "Retrieving preferences", NONSENSITIVE );
10741074 $prefs = $wgLDAPPreferences[$_SESSION['wsDomain']];
@@ -1100,20 +1100,20 @@
11011101 }
11021102 }
11031103 } else if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
1104 - //DEPRECATED. Kept for backwards compatibility.
 1104+ // DEPRECATED. Kept for backwards compatibility.
11051105 $this->printDebug( "Retrieving preferences", NONSENSITIVE );
11061106 $this->printDebug( '$wgLDAPRetrievePrefs is a DEPRECATED option, please use $wgLDAPPreferences.', NONSENSITIVE );
11071107
1108 - if (isset($this->userInfo[0]["mail"])) {
 1108+ if ( isset( $this->userInfo[0]["mail"] ) ) {
11091109 $this->email = $this->userInfo[0]["mail"][0];
11101110 }
1111 - if (isset($this->userInfo[0]["preferredlanguage"])) {
 1111+ if ( isset( $this->userInfo[0]["preferredlanguage"] ) ) {
11121112 $this->lang = $this->userInfo[0]["preferredlanguage"][0];
11131113 }
1114 - if (isset($this->userInfo[0]["displayname"])) {
 1114+ if ( isset( $this->userInfo[0]["displayname"] ) ) {
11151115 $this->nickname = $this->userInfo[0]["displayname"][0];
11161116 }
1117 - if (isset($this->userInfo[0]["cn"])) {
 1117+ if ( isset( $this->userInfo[0]["cn"] ) ) {
11181118 $this->realname = $this->userInfo[0]["cn"][0];
11191119 }
11201120
@@ -1125,11 +1125,11 @@
11261126 global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
11271127 global $wgLDAPUniqueAttribute;
11281128
1129 - $this->printDebug("Entering synchUsername", NONSENSITIVE);
 1129+ $this->printDebug( "Entering synchUsername", NONSENSITIVE );
11301130
11311131 $this->userInfo = $this->getUserInfo();
11321132 if ( is_null( $this->userInfo ) ) {
1133 - $this->printDebug("Failed to get preferences", NONSENSITIVE);
 1133+ $this->printDebug( "Failed to get preferences", NONSENSITIVE );
11341134 }
11351135
11361136 // Are we blocking login/renaming users on unique external ID mismatches?
@@ -1144,7 +1144,7 @@
11451145
11461146 $this->printDebug( "Checking for username change in LDAP.", SENSITIVE );
11471147
1148 - //Get the user's unique attribute from LDAP
 1148+ // Get the user's unique attribute from LDAP
11491149 if ( isset( $wgLDAPUniqueAttribute[$_SESSION['wsDomain']] ) ) {
11501150 $ldapuniqueattr = $wgLDAPUniqueAttribute[$_SESSION['wsDomain']];
11511151 $this->externalid = $this->info[0][$ldapuniqueattr][0];
@@ -1214,13 +1214,13 @@
12151215 global $wgLDAPGroupDN;
12161216 global $wgLDAPRequiredGroups, $wgLDAPExcludedGroups;
12171217
1218 - $this->printDebug("Entering checkGroups", NONSENSITIVE);
 1218+ $this->printDebug( "Entering checkGroups", NONSENSITIVE );
12191219
1220 - //Old style groups, non-nestable and fairly limited on group type (full DN
1221 - //versus username). DEPRECATED
 1220+ // Old style groups, non-nestable and fairly limited on group type (full DN
 1221+ // versus username). DEPRECATED
12221222 if ( $wgLDAPGroupDN ) {
12231223 $this->printDebug( "Checking for (old style) group membership", NONSENSITIVE );
1224 - //we need to do a subbase search for the entry
 1224+ // we need to do a subbase search for the entry
12251225 $filter = "(member=" . $this->getLdapEscapedString( $this->userdn ) . ")";
12261226 $info = @ldap_get_entries( $this->ldapconn, @ldap_search( $this->ldapconn, $wgLDAPGroupDN, $filter ) );
12271227
@@ -1245,7 +1245,7 @@
12461246 }
12471247 }
12481248
1249 - //New style group checking
 1249+ // New style group checking
12501250 if ( isset( $wgLDAPRequiredGroups[$_SESSION['wsDomain']] ) ) {
12511251 $this->printDebug( "Checking for (new style) group membership", NONSENSITIVE );
12521252 $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']];
@@ -1263,7 +1263,7 @@
12641264 }
12651265 }
12661266
1267 - $this->printDebug("Couldn't find the user in any groups.", NONSENSITIVE );
 1267+ $this->printDebug( "Couldn't find the user in any groups.", NONSENSITIVE );
12681268 return false;
12691269 }
12701270
@@ -1283,13 +1283,13 @@
12841284 global $wgLDAPGroupsPrevail;
12851285 global $wgLDAPGroupsUseMemberOf;
12861286
1287 - $this->printDebug("Entering getGroups", NONSENSITIVE);
 1287+ $this->printDebug( "Entering getGroups", NONSENSITIVE );
12881288
1289 - //Find groups
 1289+ // Find groups
12901290 if ( isset( $wgLDAPRequiredGroups[$_SESSION['wsDomain']] ) || ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) ) {
12911291 $this->printDebug( "Retrieving LDAP group membership", NONSENSITIVE );
12921292
1293 - //Let's figure out what we should be searching for
 1293+ // Let's figure out what we should be searching for
12941294 if ( isset( $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) && $wgLDAPGroupUseFullDN[$_SESSION['wsDomain']] ) {
12951295 $usertopass = $this->userdn;
12961296 } else {
@@ -1306,14 +1306,14 @@
13071307 $this->printDebug( "Using memberOf", NONSENSITIVE );
13081308 $this->userInfo = $this->getUserInfo();
13091309 if ( is_null( $this->userInfo ) ) {
1310 - $this->printDebug("Failed to get memberOf attribute", NONSENSITIVE);
 1310+ $this->printDebug( "Failed to get memberOf attribute", NONSENSITIVE );
13111311 }
13121312 if ( isset( $this->userInfo[0]["memberof"] ) ) {
13131313 # The first entry is always a count
13141314 $memberOfMembers = $this->userInfo[0]["memberof"];
13151315 array_shift( $memberOfMembers );
1316 - $groups = array( "dn"=> array(), "short"=>array() );
1317 - foreach( $memberOfMembers as $mem ) {
 1316+ $groups = array( "dn" => array(), "short" => array() );
 1317+ foreach ( $memberOfMembers as $mem ) {
13181318 array_push( $groups["dn"], strtolower( $mem ) );
13191319 }
13201320 $this->userLDAPGroups = $groups;
@@ -1328,8 +1328,8 @@
13291329 }
13301330 }
13311331
1332 - //Only find all groups if the user has any groups; otherwise, we are
1333 - //just wasting a search.
 1332+ // Only find all groups if the user has any groups; otherwise, we are
 1333+ // just wasting a search.
13341334 if ( ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && count( $this->userLDAPGroups ) != 0 ) {
13351335 $this->allLDAPGroups = $this->searchGroups( '*' );
13361336 }
@@ -1349,7 +1349,7 @@
13501350 function searchNestedGroups( $groups, $searchedgroups = array( "dn" => Array(), "short" => Array() ) ) {
13511351 $this->printDebug( "Entering searchNestedGroups", NONSENSITIVE );
13521352
1353 - //base case, no more groups left to check
 1353+ // base case, no more groups left to check
13541354 if ( count( $groups["dn"] ) == 0 ) {
13551355 $this->printDebug( "No more groups to search.", NONSENSITIVE );
13561356 return $searchedgroups;
@@ -1357,27 +1357,27 @@
13581358
13591359 $this->printDebug( "Searching groups:", SENSITIVE, $groups["dn"] );
13601360
1361 - $groupstosearch = array( "short"=>array(), "dn"=>array() );
 1361+ $groupstosearch = array( "short" => array(), "dn" => array() );
13621362 foreach ( $groups["dn"] as $group ) {
13631363 $returnedgroups = $this->searchGroups( $group );
13641364 $this->printDebug( "Group $group is in the following groups:", SENSITIVE, $returnedgroups["dn"] );
13651365 foreach ( $returnedgroups["dn"] as $searchme ) {
13661366 if ( in_array( $searchme, $searchedgroups["dn"] ) ) {
1367 - //We already searched this, move on
 1367+ // We already searched this, move on
13681368 continue;
13691369 } else {
1370 - //We'll need to search this group's members now
 1370+ // We'll need to search this group's members now
13711371 $this->printDebug( "Adding $searchme to the list of groups (1)", SENSITIVE );
13721372 $groupstosearch["dn"][] = $searchme;
13731373 }
13741374 }
13751375 foreach ( $returnedgroups["short"] as $searchme ) {
13761376 if ( in_array( $searchme, $searchedgroups["short"] ) ) {
1377 - //We already searched this, move on
 1377+ // We already searched this, move on
13781378 continue;
13791379 } else {
13801380 $this->printDebug( "Adding $searchme to the list of groups (2)", SENSITIVE );
1381 - //We'll need to search this group's members now
 1381+ // We'll need to search this group's members now
13821382 $groupstosearch["short"][] = $searchme;
13831383 }
13841384 }
@@ -1385,8 +1385,8 @@
13861386
13871387 $searchedgroups = array_merge_recursive( $groups, $searchedgroups );
13881388
1389 - //Mmmmmm. Tail recursion. Tasty.
1390 - return $this->searchNestedGroups( $groupstosearch, $searchedgroups );
 1389+ // Mmmmmm. Tail recursion. Tasty.
 1390+ return $this->searchNestedGroups( $groupstosearch, $searchedgroups );
13911391 }
13921392
13931393 /**
@@ -1419,30 +1419,30 @@
14201420 $this->printDebug( "Search string: $filter", SENSITIVE );
14211421
14221422 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
1423 - //We'll try to bind as the proxyagent as the proxyagent should normally have more
1424 - //rights than the user. If the proxyagent fails to bind, we will still be able
1425 - //to search as the normal user (which is why we don't return on fail).
 1423+ // We'll try to bind as the proxyagent as the proxyagent should normally have more
 1424+ // rights than the user. If the proxyagent fails to bind, we will still be able
 1425+ // to search as the normal user (which is why we don't return on fail).
14261426 $this->printDebug( "Binding as the proxyagent", NONSENSITIVE );
14271427 $bind = $this->bindAs( $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
14281428 }
14291429
14301430 $info = @ldap_search( $this->ldapconn, $base, $filter );
1431 - #if ( $info["count"] < 1 ) {
 1431+ # if ( $info["count"] < 1 ) {
14321432 if ( !$info ) {
14331433 $this->printDebug( "No entries returned from search.", SENSITIVE );
14341434
1435 - //Return an array so that other functions
1436 - //don't error out.
1437 - return array( "short"=>array(), "dn"=>array() );
 1435+ // Return an array so that other functions
 1436+ // don't error out.
 1437+ return array( "short" => array(), "dn" => array() );
14381438 }
14391439
14401440 $entries = @ldap_get_entries( $this->ldapconn, $info );
14411441
1442 - //We need to shift because the first entry will be a count
 1442+ // We need to shift because the first entry will be a count
14431443 array_shift( $entries );
14441444
1445 - //Let's get a list of both full dn groups and shortname groups
1446 - $groups = array( "short"=>array(), "dn"=>array() );
 1445+ // Let's get a list of both full dn groups and shortname groups
 1446+ $groups = array( "short" => array(), "dn" => array() );
14471447 foreach ( $entries as $entry ) {
14481448 $shortMember = strtolower( $entry[$nameattribute][0] );
14491449 $dnMember = strtolower( $entry['dn'] );
@@ -1493,7 +1493,7 @@
14941494 global $wgLDAPGroupsPrevail, $wgGroupPermissions;
14951495 global $wgLDAPLocallyManagedGroups;
14961496
1497 - //TODO: this is *really* ugly code. clean it up!
 1497+ // TODO: this is *really* ugly code. clean it up!
14981498
14991499 $this->printDebug( "Entering setGroups.", NONSENSITIVE );
15001500
@@ -1505,7 +1505,7 @@
15061506
15071507 if ( isset( $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']] ) ) {
15081508 $locallyManagedGrps = $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']];
1509 - $locallyManagedGrps = array_unique( array_merge( $defaultLocallyManagedGrps, $locallyManagedGrps ) );
 1509+ $locallyManagedGrps = array_unique( array_merge( $defaultLocallyManagedGrps, $locallyManagedGrps ) );
15101510 $this->printDebug( "Locally managed groups: ", SENSITIVE, $locallyManagedGrps );
15111511 } else {
15121512 $locallyManagedGrps = $defaultLocallyManagedGrps;
@@ -1528,7 +1528,7 @@
15291529 # as $localAvailGrps contains $cGroup only once.
15301530 foreach ( $localAvailGrps as $cGroup ) {
15311531 # did we once add the user to the group?
1532 - if ( in_array( $cGroup,$localUserGrps ) ) {
 1532+ if ( in_array( $cGroup, $localUserGrps ) ) {
15331533 $this->printDebug( "Checking to see if we need to remove user from: $cGroup", NONSENSITIVE );
15341534 if ( ( !$this->hasLDAPGroup( $cGroup ) ) && ( !in_array( $cGroup, $locallyManagedGrps ) ) ) {
15351535 $this->printDebug( "Removing user from: $cGroup", NONSENSITIVE );
@@ -1564,7 +1564,7 @@
15651565 $hashtouse = '';
15661566 }
15671567
1568 - //Set the password hashing based upon admin preference
 1568+ // Set the password hashing based upon admin preference
15691569 switch ( $hashtouse ) {
15701570 case 'crypt':
15711571 $pass = '{CRYPT}' . crypt( $password );
@@ -1573,8 +1573,8 @@
15741574 $pass = $password;
15751575 break;
15761576 default:
1577 - $pwd_sha = base64_encode( pack( 'H*',sha1( $password ) ) );
1578 - $pass = "{SHA}".$pwd_sha;
 1577+ $pwd_sha = base64_encode( pack( 'H*', sha1( $password ) ) );
 1578+ $pass = "{SHA}" . $pwd_sha;
15791579 break;
15801580 }
15811581
@@ -1614,8 +1614,8 @@
16151615 * @return bool
16161616 * @access private
16171617 */
1618 - function bindAs( $userdn=null, $password=null ) {
1619 - //Let's see if the user can authenticate.
 1618+ function bindAs( $userdn = null, $password = null ) {
 1619+ // Let's see if the user can authenticate.
16201620 if ( $userdn == null || $password == null ) {
16211621 $bind = @ldap_bind( $this->ldapconn );
16221622 } else {
@@ -1655,9 +1655,9 @@
16561656 function getLdapEscapedString ( $string ) {
16571657 // Make the string LDAP compliant by escaping *, (, ) , \ & NUL
16581658 return str_replace(
1659 - array( "*", "(", ")", "\\", "\x00" ), //replace this
1660 - array( "\\2a", "\\28", "\\29", "\\5c", "\\00" ), //with this
1661 - $string //in this
 1659+ array( "*", "(", ")", "\\", "\x00" ), // replace this
 1660+ array( "\\2a", "\\28", "\\29", "\\5c", "\\00" ), // with this
 1661+ $string // in this
16621662 );
16631663 }
16641664
@@ -1731,7 +1731,7 @@
17321732
17331733 $wgAuth->printDebug( "Entering AutoAuthSetup.", NONSENSITIVE );
17341734
1735 - //Set configuration options for backwards compatibility
 1735+ // Set configuration options for backwards compatibility
17361736 if ( isset( $wgLDAPSSLUsername ) ) {
17371737 $wgAuth->printDebug( 'Setting $wgLDAPAutoAuthUsername to $wgLDAPSSLUsername; please change your configuration to fix this deprecated configuration variable.', NONSENSITIVE );
17381738 $wgLDAPAutoAuthUsername = $wgLDAPSSLUsername;
@@ -1741,7 +1741,7 @@
17421742 $wgLDAPAutoAuthDomain = $wgLDAPSmartcardDomain;
17431743 }
17441744
1745 - if( $wgLDAPAutoAuthUsername != null ) {
 1745+ if ( $wgLDAPAutoAuthUsername != null ) {
17461746 $wgAuth->printDebug( "wgLDAPAutoAuthUsername is not null, adding hooks.", NONSENSITIVE );
17471747 if ( version_compare( $wgVersion, '1.14.0', '<' ) ) {
17481748 if ( version_compare( $wgVersion, '1.13.0', '<' ) ) {

Status & tagging log