Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php |
— | — | @@ -41,6 +41,17 @@ |
42 | 42 | # Support is available at http://www.mediawiki.org/wiki/Extension_talk:LDAP_Authentication |
43 | 43 | # |
44 | 44 | |
| 45 | +/** |
| 46 | + * Add extension information to Special:Version |
| 47 | + */ |
| 48 | +$wgExtensionCredits['other'][] = array( |
| 49 | + 'name' => 'LDAP Authentication Plugin', |
| 50 | + 'version' => '1.2a (beta)', |
| 51 | + 'author' => 'Ryan Lane', |
| 52 | + 'description' => 'LDAP Authentication plugin with support for multiple LDAP authentication methods', |
| 53 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:LDAP_Authentication', |
| 54 | + ); |
| 55 | + |
45 | 56 | //constants for search base |
46 | 57 | define("GROUPDN", 0); |
47 | 58 | define("USERDN", 1); |
— | — | @@ -262,6 +273,7 @@ |
263 | 274 | } |
264 | 275 | |
265 | 276 | $ldapconn = $this->connect(); |
| 277 | + //This seems really expensive. |
266 | 278 | if ( $ldapconn ) { |
267 | 279 | $this->printDebug( "Connected successfully", NONSENSITIVE ); |
268 | 280 | |
— | — | @@ -1229,7 +1241,7 @@ |
1230 | 1242 | |
1231 | 1243 | $searchnested = $wgLDAPGroupSearchNestedGroups[$_SESSION['wsDomain']]; |
1232 | 1244 | |
1233 | | - $this->printDebug( "Required groups:" . implode( ",",$reqgroups ) . "", NONSENSITIVE ); |
| 1245 | + $this->printDebug( "Required groups:", NONSENSITIVE, $reqgroups ); |
1234 | 1246 | |
1235 | 1247 | $groups = $this->getUserGroups( $ldapconn, $userDN ); |
1236 | 1248 | |
— | — | @@ -1285,7 +1297,7 @@ |
1286 | 1298 | return false; |
1287 | 1299 | } |
1288 | 1300 | |
1289 | | - $this->printDebug( "Checking groups:" . implode( ",", $groups ) . "", SENSITIVE ); |
| 1301 | + $this->printDebug( "Checking groups:", SENSITIVE, $groups ); |
1290 | 1302 | |
1291 | 1303 | $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']]; |
1292 | 1304 | for ( $i = 0; $i < count( $reqgroups ); $i++ ) { |
— | — | @@ -1295,7 +1307,7 @@ |
1296 | 1308 | $groupstocheck = array(); |
1297 | 1309 | foreach ( $groups as $group ) { |
1298 | 1310 | $returnedgroups = $this->getUserGroups( $ldapconn, $group, false, false ); |
1299 | | - $this->printDebug( "Group $group is in the following groups:" . implode( ",", $returnedgroups ) . "", SENSITIVE ); |
| 1311 | + $this->printDebug( "Group $group is in the following groups:", SENSITIVE, $returnedgroups ); |
1300 | 1312 | foreach ( $returnedgroups as $checkme ) { |
1301 | 1313 | if ( in_array( $checkme, $checkedgroups ) ) { |
1302 | 1314 | //We already checked this, move on |
— | — | @@ -1465,6 +1477,7 @@ |
1466 | 1478 | } |
1467 | 1479 | |
1468 | 1480 | $info = @ldap_search( $ldapconn, $base, $filter ); |
| 1481 | + //TODO: Active Directory always returns something, we need to take this into account |
1469 | 1482 | if ( !$info ) { |
1470 | 1483 | $this->printDebug( "No entries returned from search.", SENSITIVE ); |
1471 | 1484 | |
— | — | @@ -1473,7 +1486,7 @@ |
1474 | 1487 | return array( array(), array() ); |
1475 | 1488 | } |
1476 | 1489 | |
1477 | | - $entries = @ldap_get_entries( $ldapconn,$info ); |
| 1490 | + $entries = @ldap_get_entries( $ldapconn, $info ); |
1478 | 1491 | |
1479 | 1492 | //We need to shift because the first entry will be a count |
1480 | 1493 | array_shift( $entries ); |
— | — | @@ -1493,8 +1506,8 @@ |
1494 | 1507 | array_push( $both_groups, $groups ); |
1495 | 1508 | array_push( $both_groups, $shortnamegroups ); |
1496 | 1509 | |
1497 | | - $this->printDebug( "Returned groups:" . implode( ",", $groups ) . "", SENSITIVE ); |
1498 | | - $this->printDebug( "Returned groups:" . implode( ",", $shortnamegroups ) . "", SENSITIVE ); |
| 1510 | + $this->printDebug( "Returned groups:", SENSITIVE, $groups ); |
| 1511 | + $this->printDebug( "Returned groups:", SENSITIVE, $shortnamegroups ); |
1499 | 1512 | |
1500 | 1513 | return $both_groups; |
1501 | 1514 | } |
— | — | @@ -1537,6 +1550,8 @@ |
1538 | 1551 | global $wgLDAPGroupsPrevail, $wgGroupPermissions; |
1539 | 1552 | global $wgLDAPLocallyManagedGroups; |
1540 | 1553 | |
| 1554 | + //TODO: this is *really* ugly code. clean it up! |
| 1555 | + |
1541 | 1556 | $this->printDebug( "Entering setGroups.", NONSENSITIVE ); |
1542 | 1557 | |
1543 | 1558 | # add groups permissions |
— | — | @@ -1548,23 +1563,23 @@ |
1549 | 1564 | if ( isset( $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']] ) ) { |
1550 | 1565 | $locallyManagedGrps = $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']]; |
1551 | 1566 | $locallyManagedGrps = array_unique( array_merge( $defaultLocallyManagedGrps, $locallyManagedGrps ) ); |
1552 | | - $this->printDebug( "Locally managed groups: " . implode( ",", $locallyManagedGrps ) . "", SENSITIVE ); |
| 1567 | + $this->printDebug( "Locally managed groups: ", SENSITIVE, $locallyManagedGrps ); |
1553 | 1568 | } else { |
1554 | 1569 | $locallyManagedGrps = $defaultLocallyManagedGrps; |
1555 | | - $this->printDebug( "Locally managed groups is unset, using defaults: " . implode( ",", $locallyManagedGrps ) . "", SENSITIVE ); |
| 1570 | + $this->printDebug( "Locally managed groups is unset, using defaults: ", SENSITIVE, $locallyManagedGrps ); |
1556 | 1571 | } |
1557 | 1572 | |
1558 | 1573 | |
1559 | 1574 | # Add ldap groups as local groups |
1560 | 1575 | if ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) { |
1561 | | - $this->printDebug( "Adding all groups to wgGroupPermissions: " . implode( ",", $this->allLDAPGroups ) . "", SENSITIVE ); |
| 1576 | + $this->printDebug( "Adding all groups to wgGroupPermissions: ", SENSITIVE, $this->allLDAPGroups ); |
1562 | 1577 | foreach ( $this->allLDAPGroups as $ldapgroup ) |
1563 | 1578 | if ( !array_key_exists( $ldapgroup, $wgGroupPermissions ) ) |
1564 | 1579 | $wgGroupPermissions[$ldapgroup] = array(); |
1565 | 1580 | } |
1566 | 1581 | |
1567 | | - $this->printDebug( "Available groups are: " . implode( ",", $localAvailGrps ) . "", NONSENSITIVE ); |
1568 | | - $this->printDebug( "Effective groups are: " . implode( ",", $localUserGrps ) . "", NONSENSITIVE ); |
| 1582 | + $this->printDebug( "Available groups are: ", NONSENSITIVE, $localAvailGrps ); |
| 1583 | + $this->printDebug( "Effective groups are: ", NONSENSITIVE, $localUserGrps ); |
1569 | 1584 | |
1570 | 1585 | # note: $localUserGrps does not need to be updated with $cGroup added, |
1571 | 1586 | # as $localAvailGrps contains $cGroup only once. |
— | — | @@ -1582,9 +1597,7 @@ |
1583 | 1598 | $this->printDebug( "Checking to see if user is in: $cGroup", NONSENSITIVE ); |
1584 | 1599 | if ( $this->hasLDAPGroup( $cGroup ) ) { |
1585 | 1600 | $this->printDebug( "Adding user to: $cGroup", NONSENSITIVE ); |
1586 | | - # so use the addGroup function |
1587 | 1601 | $user->addGroup( $cGroup ); |
1588 | | - # completed for $cGroup. |
1589 | 1602 | } |
1590 | 1603 | } |
1591 | 1604 | } |
— | — | @@ -1634,11 +1647,17 @@ |
1635 | 1648 | * @param string $debugVal |
1636 | 1649 | * @access private |
1637 | 1650 | */ |
1638 | | - function printDebug( $debugText, $debugVal ) { |
| 1651 | + function printDebug( $debugText, $debugVal, $debugArr = Null ) { |
1639 | 1652 | global $wgLDAPDebug; |
1640 | 1653 | |
1641 | | - if ( $wgLDAPDebug > $debugVal ) { |
1642 | | - echo $debugText . "<br />"; |
| 1654 | + if ( isset( $debugArr ) ) { |
| 1655 | + if ( $wgLDAPDebug > $debugVal ) { |
| 1656 | + echo $debugText . implode( ",", $debugArr ) . "<br />"; |
| 1657 | + } |
| 1658 | + } else { |
| 1659 | + if ( $wgLDAPDebug > $debugVal ) { |
| 1660 | + echo $debugText . "<br />"; |
| 1661 | + } |
1643 | 1662 | } |
1644 | 1663 | } |
1645 | 1664 | |
— | — | @@ -1748,17 +1767,6 @@ |
1749 | 1768 | |
1750 | 1769 | } |
1751 | 1770 | |
1752 | | -/** |
1753 | | - * Add extension information to Special:Version |
1754 | | - */ |
1755 | | -$wgExtensionCredits['other'][] = array( |
1756 | | - 'name' => 'LDAP Authentication Plugin', |
1757 | | - 'version' => '1.2a (beta)', |
1758 | | - 'author' => 'Ryan Lane', |
1759 | | - 'description' => 'LDAP Authentication plugin with support for multiple LDAP authentication methods', |
1760 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:LDAP_Authentication', |
1761 | | - ); |
1762 | | - |
1763 | 1771 | // The following was derived from the SSL Authentication plugin |
1764 | 1772 | // http://www.mediawiki.org/wiki/SSL_authentication |
1765 | 1773 | |