Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php |
— | — | @@ -504,8 +504,6 @@ |
505 | 505 | * @return bool |
506 | 506 | */ |
507 | 507 | public function userExists( $username ) { |
508 | | - global $wgLDAPAddLDAPUsers; |
509 | | - |
510 | 508 | $this->printDebug( "Entering userExists", NONSENSITIVE ); |
511 | 509 | |
512 | 510 | // If we can't add LDAP users, we don't really need to check |
— | — | @@ -550,10 +548,8 @@ |
551 | 549 | |
552 | 550 | /** |
553 | 551 | * Connect to LDAP |
554 | | - * |
555 | | - * @access private |
556 | 552 | */ |
557 | | - function connect( $domain='' ) { |
| 553 | + private function connect( $domain='' ) { |
558 | 554 | if ( $domain == '' ) { |
559 | 555 | $domain = $this->getSessionDomain(); |
560 | 556 | } |
— | — | @@ -747,6 +743,7 @@ |
748 | 744 | * Modify options in the login template. |
749 | 745 | * |
750 | 746 | * @param UserLoginTemplate $template |
| 747 | + * @param $type |
751 | 748 | */ |
752 | 749 | public function modifyUITemplate( &$template, &$type ) { |
753 | 750 | $this->printDebug( "Entering modifyUITemplate", NONSENSITIVE ); |
— | — | @@ -764,6 +761,9 @@ |
765 | 762 | wfRunHooks( 'LDAPModifyUITemplate', array( &$template ) ); |
766 | 763 | } |
767 | 764 | |
| 765 | + /** |
| 766 | + * @return array |
| 767 | + */ |
768 | 768 | function domainList() { |
769 | 769 | global $wgLDAPDomainNames; |
770 | 770 | |
— | — | @@ -858,13 +858,10 @@ |
859 | 859 | if ( $success ) { |
860 | 860 | $this->printDebug( "Successfully modified the user's password", NONSENSITIVE ); |
861 | 861 | return true; |
862 | | - } else { |
863 | | - $this->printDebug( "Failed to modify the user's password", NONSENSITIVE ); |
864 | | - return false; |
865 | 862 | } |
866 | | - } else { |
867 | | - return false; |
| 863 | + $this->printDebug( "Failed to modify the user's password", NONSENSITIVE ); |
868 | 864 | } |
| 865 | + return false; |
869 | 866 | } |
870 | 867 | |
871 | 868 | /** |
— | — | @@ -918,14 +915,11 @@ |
919 | 916 | $this->printDebug( "Successfully modified the user's attributes", NONSENSITIVE ); |
920 | 917 | LdapAuthenticationPlugin::ldap_unbind( $this->ldapconn ); |
921 | 918 | return true; |
922 | | - } else { |
923 | | - $this->printDebug( "Failed to modify the user's attributes", NONSENSITIVE ); |
924 | | - LdapAuthenticationPlugin::ldap_unbind( $this->ldapconn ); |
925 | | - return false; |
926 | 919 | } |
927 | | - } else { |
928 | | - return false; |
| 920 | + $this->printDebug( "Failed to modify the user's attributes", NONSENSITIVE ); |
| 921 | + LdapAuthenticationPlugin::ldap_unbind( $this->ldapconn ); |
929 | 922 | } |
| 923 | + return false; |
930 | 924 | } |
931 | 925 | |
932 | 926 | /** |
— | — | @@ -966,6 +960,8 @@ |
967 | 961 | * |
968 | 962 | * @param User $user |
969 | 963 | * @param string $password |
| 964 | + * @param string $email |
| 965 | + * @param string $realname |
970 | 966 | * @return bool |
971 | 967 | */ |
972 | 968 | public function addUser( $user, $password, $email = '', $realname = '' ) { |
— | — | @@ -1054,14 +1050,11 @@ |
1055 | 1051 | $this->printDebug( "Successfully added user", NONSENSITIVE ); |
1056 | 1052 | LdapAuthenticationPlugin::ldap_unbind( $this->ldapconn ); |
1057 | 1053 | return true; |
1058 | | - } else { |
1059 | | - $this->printDebug( "Failed to add user", NONSENSITIVE ); |
1060 | | - LdapAuthenticationPlugin::ldap_unbind( $this->ldapconn ); |
1061 | | - return false; |
1062 | 1054 | } |
1063 | | - } else { |
1064 | | - return false; |
| 1055 | + $this->printDebug( "Failed to add user", NONSENSITIVE ); |
| 1056 | + LdapAuthenticationPlugin::ldap_unbind( $this->ldapconn ); |
1065 | 1057 | } |
| 1058 | + return false; |
1066 | 1059 | } |
1067 | 1060 | |
1068 | 1061 | /** |
— | — | @@ -1198,10 +1191,9 @@ |
1199 | 1192 | if ( $this->getConf( 'UseLocal' ) || $this->getConf( 'MailPassword' ) ) { |
1200 | 1193 | $this->printDebug( "Returning false in strict().", NONSENSITIVE ); |
1201 | 1194 | return false; |
1202 | | - } else { |
1203 | | - $this->printDebug( "Returning true in strict().", NONSENSITIVE ); |
1204 | | - return true; |
1205 | 1195 | } |
| 1196 | + $this->printDebug( "Returning true in strict().", NONSENSITIVE ); |
| 1197 | + return true; |
1206 | 1198 | } |
1207 | 1199 | |
1208 | 1200 | /** |
— | — | @@ -1366,6 +1358,9 @@ |
1367 | 1359 | return $userdn; |
1368 | 1360 | } |
1369 | 1361 | |
| 1362 | + /** |
| 1363 | + * @return array|null |
| 1364 | + */ |
1370 | 1365 | function getUserInfo() { |
1371 | 1366 | // Don't fetch the same data more than once |
1372 | 1367 | if ( $this->fetchedUserInfo ) { |
— | — | @@ -1375,13 +1370,17 @@ |
1376 | 1371 | $userInfo = $this->getUserInfoStateless( $this->usernn ); |
1377 | 1372 | if ( is_null( $userInfo ) ) { |
1378 | 1373 | $this->fetchedUserInfo = false; |
1379 | | - return; |
| 1374 | + return null; |
1380 | 1375 | } else { |
1381 | 1376 | $this->fetchedUserInfo = true; |
1382 | 1377 | return $userInfo; |
1383 | 1378 | } |
1384 | 1379 | } |
1385 | 1380 | |
| 1381 | + /** |
| 1382 | + * @param $userdn string |
| 1383 | + * @return array|null |
| 1384 | + */ |
1386 | 1385 | function getUserInfoStateless( $userdn ) { |
1387 | 1386 | // Don't fetch the same data more than once |
1388 | 1387 | // TODO: use memcached here |
— | — | @@ -1389,7 +1388,7 @@ |
1390 | 1389 | $entry = LdapAuthenticationPlugin::ldap_read( $this->ldapconn, $userdn, "objectclass=*", array( '*', 'memberof' ) ); |
1391 | 1390 | $userInfo = LdapAuthenticationPlugin::ldap_get_entries( $this->ldapconn, $entry ); |
1392 | 1391 | if ( $userInfo["count"] < 1 ) { |
1393 | | - return; |
| 1392 | + return null; |
1394 | 1393 | } else { |
1395 | 1394 | return $userInfo; |
1396 | 1395 | } |
— | — | @@ -1397,11 +1396,8 @@ |
1398 | 1397 | |
1399 | 1398 | /** |
1400 | 1399 | * Retrieve user preferences from LDAP |
1401 | | - * |
1402 | | - * @param string $userDN |
1403 | | - * @access private |
1404 | 1400 | */ |
1405 | | - function getPreferences() { |
| 1401 | + private function getPreferences() { |
1406 | 1402 | $this->printDebug( "Entering getPreferences", NONSENSITIVE ); |
1407 | 1403 | |
1408 | 1404 | $this->userInfo = $this->getUserInfo(); |
— | — | @@ -1411,34 +1407,34 @@ |
1412 | 1408 | |
1413 | 1409 | // Retrieve preferences |
1414 | 1410 | $prefs = $this->getConf( 'Preferences' ); |
1415 | | - if ( $prefs ) { |
1416 | | - $this->printDebug( "Retrieving preferences", NONSENSITIVE ); |
1417 | | - foreach ( array_keys( $prefs ) as $key ) { |
1418 | | - $attr = strtolower( $prefs[$key] ); |
1419 | | - if ( isset( $this->userInfo[0][$attr] ) ) { |
1420 | | - $value = $this->userInfo[0][$attr][0]; |
1421 | | - } else { |
1422 | | - continue; |
1423 | | - } |
1424 | | - switch ( $key ) { |
1425 | | - case "email": |
1426 | | - $this->email = $value; |
1427 | | - $this->printDebug( "Retrieved email ($this->email) using attribute ($prefs[$key])", NONSENSITIVE ); |
1428 | | - break; |
1429 | | - case "language": |
1430 | | - $this->lang = $value; |
1431 | | - $this->printDebug( "Retrieved language ($this->lang) using attribute ($prefs[$key])", NONSENSITIVE ); |
1432 | | - break; |
1433 | | - case "nickname": |
1434 | | - $this->nickname = $value; |
1435 | | - $this->printDebug( "Retrieved nickname ($this->nickname) using attribute ($prefs[$key])", NONSENSITIVE ); |
1436 | | - break; |
1437 | | - case "realname": |
1438 | | - $this->realname = $value; |
1439 | | - $this->printDebug( "Retrieved realname ($this->realname) using attribute ($prefs[$key])", NONSENSITIVE ); |
1440 | | - break; |
1441 | | - } |
| 1411 | + if ( !$prefs ) { |
| 1412 | + return; |
| 1413 | + } |
| 1414 | + $this->printDebug( "Retrieving preferences", NONSENSITIVE ); |
| 1415 | + foreach ( array_keys( $prefs ) as $key ) { |
| 1416 | + $attr = strtolower( $prefs[$key] ); |
| 1417 | + if ( !isset( $this->userInfo[0][$attr] ) ) { |
| 1418 | + continue; |
1442 | 1419 | } |
| 1420 | + $value = $this->userInfo[0][$attr][0]; |
| 1421 | + switch ( $key ) { |
| 1422 | + case "email": |
| 1423 | + $this->email = $value; |
| 1424 | + $this->printDebug( "Retrieved email ($this->email) using attribute ($prefs[$key])", NONSENSITIVE ); |
| 1425 | + break; |
| 1426 | + case "language": |
| 1427 | + $this->lang = $value; |
| 1428 | + $this->printDebug( "Retrieved language ($this->lang) using attribute ($prefs[$key])", NONSENSITIVE ); |
| 1429 | + break; |
| 1430 | + case "nickname": |
| 1431 | + $this->nickname = $value; |
| 1432 | + $this->printDebug( "Retrieved nickname ($this->nickname) using attribute ($prefs[$key])", NONSENSITIVE ); |
| 1433 | + break; |
| 1434 | + case "realname": |
| 1435 | + $this->realname = $value; |
| 1436 | + $this->printDebug( "Retrieved realname ($this->realname) using attribute ($prefs[$key])", NONSENSITIVE ); |
| 1437 | + break; |
| 1438 | + } |
1443 | 1439 | } |
1444 | 1440 | } |
1445 | 1441 | |
— | — | @@ -1497,10 +1493,8 @@ |
1498 | 1494 | |
1499 | 1495 | /** |
1500 | 1496 | * Function to get the user's groups. |
1501 | | - * |
1502 | | - * @access private |
1503 | 1497 | */ |
1504 | | - function getGroups( $username ) { |
| 1498 | + private function getGroups( $username ) { |
1505 | 1499 | $this->printDebug( "Entering getGroups", NONSENSITIVE ); |
1506 | 1500 | |
1507 | 1501 | // Find groups |
— | — | @@ -1624,9 +1618,8 @@ |
1625 | 1619 | * |
1626 | 1620 | * @param string $dn |
1627 | 1621 | * @return array |
1628 | | - * @access private |
1629 | 1622 | */ |
1630 | | - function searchGroups( $dn ) { |
| 1623 | + private function searchGroups( $dn ) { |
1631 | 1624 | $this->printDebug( "Entering searchGroups", NONSENSITIVE ); |
1632 | 1625 | |
1633 | 1626 | $base = $this->getBaseDN( GROUPDN ); |
— | — | @@ -1637,8 +1630,9 @@ |
1638 | 1631 | |
1639 | 1632 | // We actually want to search for * not \2a, ensure we don't escape * |
1640 | 1633 | $value = $dn; |
1641 | | - if ( $value != "*" ) |
| 1634 | + if ( $value != "*" ) { |
1642 | 1635 | $value = $this->getLdapEscapedString( $value ); |
| 1636 | + } |
1643 | 1637 | |
1644 | 1638 | $proxyagent = $this->getConf( 'ProxyAgent' ); |
1645 | 1639 | if ( $proxyagent ) { |
— | — | @@ -1662,6 +1656,7 @@ |
1663 | 1657 | $Usid = $PGentries[0]['objectsid'][0]; |
1664 | 1658 | $PGrid = $PGentries[0]['primarygroupid'][0]; |
1665 | 1659 | $PGsid = bin2hex( $Usid ); |
| 1660 | + $PGSID = array(); |
1666 | 1661 | for ( $i=0; $i < 56; $i += 2 ) { |
1667 | 1662 | $PGSID[] = substr( $PGsid, $i, 2 ); |
1668 | 1663 | } |