r68286 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68285‎ | r68286 | r68287 >
Date:20:33, 19 June 2010
Author:laner
Status:deferred
Tags:
Comment:
* Add primary group support for memberOf when used with AD domains
* Fix group synchronization for memberOf
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -1304,10 +1304,21 @@
13051305 # The first entry is always a count
13061306 $memberOfMembers = $this->userInfo[0]["memberof"];
13071307 array_shift( $memberOfMembers );
1308 - $groups = array( "dn" => array(), "short" => array() );
1309 - foreach ( $memberOfMembers as $mem ) {
 1308+ $groups = array( "dn"=> array(), "short"=>array() );
 1309+
 1310+ foreach( $memberOfMembers as $mem ) {
13101311 array_push( $groups["dn"], strtolower( $mem ) );
 1312+
 1313+ // Get short name of group
 1314+ $memAttrs = explode( ',', strtolower( $mem ) );
 1315+ if ( isset( $memAttrs[0] ) ) {
 1316+ $memAttrs = explode( '=', $memAttrs[0] );
 1317+ if ( isset( $memAttrs[0] ) ) {
 1318+ array_push( $groups["short"], strtolower( $memAttrs[1] ) );
 1319+ }
 1320+ }
13111321 }
 1322+
13121323 $this->userLDAPGroups = $groups;
13131324 }
13141325 } else {
@@ -1393,7 +1404,8 @@
13941405 global $wgLDAPGroupObjectclass, $wgLDAPGroupAttribute, $wgLDAPGroupNameAttribute;
13951406 global $wgLDAPProxyAgent, $wgLDAPProxyAgentPassword;
13961407 global $wgUser;
1397 -
 1408+ global $wgLDAPGroupsUseMemberOf;
 1409+
13981410 $this->printDebug( "Entering searchGroups", NONSENSITIVE );
13991411
14001412 $base = $this->getBaseDN( GROUPDN );
@@ -1402,15 +1414,11 @@
14031415 $attribute = $wgLDAPGroupAttribute[$_SESSION['wsDomain']];
14041416 $nameattribute = $wgLDAPGroupNameAttribute[$_SESSION['wsDomain']];
14051417
1406 - // We actually want to search for * not \2a
1407 - $value = $dn;
1408 - if ( $value != "*" )
1409 - $value = $this->getLdapEscapedString( $value );
 1418+ // We actually want to search for * not \2a, ensure we don't escape *
 1419+ $value = $dn;
 1420+ if ( $value != "*" )
 1421+ $value = $this->getLdapEscapedString( $value );
14101422
1411 - $filter = "(&($attribute=$value)(objectclass=$objectclass))";
1412 -
1413 - $this->printDebug( "Search string: $filter", SENSITIVE );
1414 -
14151423 if ( isset( $wgLDAPProxyAgent[$_SESSION['wsDomain']] ) ) {
14161424 // We'll try to bind as the proxyagent as the proxyagent should normally have more
14171425 // rights than the user. If the proxyagent fails to bind, we will still be able
@@ -1419,6 +1427,61 @@
14201428 $bind = $this->bindAs( $wgLDAPProxyAgent[$_SESSION['wsDomain']], $wgLDAPProxyAgentPassword[$_SESSION['wsDomain']] );
14211429 }
14221430
 1431+ $groups = array( "short" => array(), "dn" => array() );
 1432+
 1433+ // AD does not include the primary group in the list of groups, we have to find it ourselves.
 1434+ // TODO: find a way to only do this search for AD domains.
 1435+ if ( $dn != "*" ) {
 1436+ $PGfilter = "(&(distinguishedName=$value)(objectclass=user))";
 1437+ $this->printDebug( "User Filter: $PGfilter", SENSITIVE );
 1438+ $PGinfo = @ldap_search( $ldapconn, $base, $PGfilter );
 1439+ $PGentries = @ldap_get_entries( $ldapconn, $PGinfo );
 1440+ if ( $PGentries ) {
 1441+ $Usid = $PGentries[0]['objectsid'][0];
 1442+ $PGrid = $PGentries[0]['primarygroupid'][0];
 1443+ $PGsid = bin2hex( $Usid );
 1444+ for ( $i=0; $i < 56; $i += 2 ) {
 1445+ $PGSID[] = substr( $PGsid, $i, 2 );
 1446+ }
 1447+ $dPGrid = dechex( $PGrid );
 1448+ $dPGrid = str_pad( $dPGrid, 8, '0', STR_PAD_LEFT );
 1449+ $PGRID = array();
 1450+ for ( $i = 0; $i < 8; $i += 2 ) {
 1451+ array_push( $PGRID, substr( $dPGrid, $i, 2 ) );
 1452+ }
 1453+ for ( $i = 24; $i < 28; $i++ ) {
 1454+ $PGSID[$i] = array_pop( $PGRID );
 1455+ }
 1456+ foreach ( $PGSID as $PGsid_bit ) {
 1457+ $PGsid_string .= "\\" . $PGsid_bit;
 1458+ }
 1459+ $PGfilter = "(&(objectSid=$PGsid_string)(objectclass=$objectclass))";
 1460+ $this->printDebug( "Primary Group Filter: $PGfilter", SENSITIVE );
 1461+ $info = @ldap_search( $ldapconn, $base, $PGfilter );
 1462+ $PGentries = @ldap_get_entries( $ldapconn, $info );
 1463+ array_shift( $PGentries );
 1464+ $dnMember = strtolower( $PGentry[0]['dn'] );
 1465+ $groups["dn"][] = $dnMember;
 1466+ // Get short name of group
 1467+ $memAttrs = explode( ',', strtolower( $dnMember ) );
 1468+ if ( isset( $memAttrs[0] ) ) {
 1469+ $memAttrs = explode( '=', $memAttrs[0] );
 1470+ if ( isset( $memAttrs[0] ) ) {
 1471+ $groups["short"][] = strtolower( $memAttrs[1] );
 1472+ }
 1473+ }
 1474+
 1475+ }
 1476+ }
 1477+
 1478+ $filter = "(&($attribute=$value)(objectclass=$objectclass))";
 1479+
 1480+ $this->printDebug( "Search string: $filter", SENSITIVE );
 1481+
 1482+ $filter = "(&($attribute=$value)(objectclass=$objectclass))";
 1483+
 1484+ $this->printDebug( "Search string: $filter", SENSITIVE );
 1485+
14231486 $info = @ldap_search( $this->ldapconn, $base, $filter );
14241487 # if ( $info["count"] < 1 ) {
14251488 if ( !$info ) {
@@ -1435,7 +1498,6 @@
14361499 array_shift( $entries );
14371500
14381501 // Let's get a list of both full dn groups and shortname groups
1439 - $groups = array( "short" => array(), "dn" => array() );
14401502 foreach ( $entries as $entry ) {
14411503 $shortMember = strtolower( $entry[$nameattribute][0] );
14421504 $dnMember = strtolower( $entry['dn'] );
@@ -1489,6 +1551,16 @@
14901552
14911553 $this->printDebug( "Entering setGroups.", NONSENSITIVE );
14921554
 1555+ # Add ldap groups as local groups
 1556+ if ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) {
 1557+ $this->printDebug( "Adding all groups to wgGroupPermissions: ", SENSITIVE, $this->allLDAPGroups );
 1558+
 1559+ foreach ( $this->allLDAPGroups["short"] as $ldapgroup ) {
 1560+ if ( !array_key_exists( $ldapgroup, $wgGroupPermissions ) )
 1561+ $wgGroupPermissions[$ldapgroup] = array();
 1562+ }
 1563+ }
 1564+
14931565 # add groups permissions
14941566 $localAvailGrps = $user->getAllGroups();
14951567 $localUserGrps = $user->getEffectiveGroups();
@@ -1504,17 +1576,6 @@
15051577 $this->printDebug( "Locally managed groups is unset, using defaults: ", SENSITIVE, $locallyManagedGrps );
15061578 }
15071579
1508 -
1509 - # Add ldap groups as local groups
1510 - if ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) {
1511 - $this->printDebug( "Adding all groups to wgGroupPermissions: ", SENSITIVE, $this->allLDAPGroups );
1512 -
1513 - foreach ( $this->allLDAPGroups["short"] as $ldapgroup ) {
1514 - if ( !array_key_exists( $ldapgroup, $wgGroupPermissions ) )
1515 - $wgGroupPermissions[$ldapgroup] = array();
1516 - }
1517 - }
1518 -
15191580 $this->printDebug( "Available groups are: ", NONSENSITIVE, $localAvailGrps );
15201581 $this->printDebug( "Effective groups are: ", NONSENSITIVE, $localUserGrps );
15211582

Status & tagging log