You are here

function ldapgroups_access_rules in LDAP integration 6

Retrieve the ldapgroups access rules for the specified server.

Parameters

int $sid The server id to get the access rules for.:

Return value

An array of access rules with each element an array of type and group

1 call to ldapgroups_access_rules()
ldapgroups_ldap_user_deny_alter in ./ldapgroups.module
Implementation of hook_ldap_user_deny_alter.

File

./ldapgroups.inc, line 370
ldapgroups include file.

Code

function ldapgroups_access_rules($sid, $reset = FALSE) {
  static $acl = array();
  if ($reset) {
    $acl = array();
  }
  if ($sid === FALSE) {

    // Allow resets without lookup.
    return;
  }
  if (!isset($acl[$sid])) {
    $config_info = _ldapgroups_ldap_info($sid, 'ldapgroups_groups');
    if (empty($config_info)) {
      $acl[$sid][] = array(
        LDAPGROUPS_RULE_TYPE_ALLOW,
        LDAPGROUPS_GROUP_ALL,
      );
    }
    else {

      // All rule sets start with deny all
      $acl[$sid][] = array(
        LDAPGROUPS_RULE_TYPE_DENY,
        LDAPGROUPS_GROUP_ALL,
      );

      // Is just a list of groups?
      if (!preg_match("/^(" . LDAPGROUPS_RULE_TYPE_ALLOW . ")|(" . LDAPGROUPS_RULE_TYPE_DENY . ")??[:]\\s.*/i", $config_info[0])) {
        foreach ($config_info as $group) {
          if (!empty($group)) {
            $acl[$sid][] = array(
              LDAPGROUPS_RULE_TYPE_ALLOW,
              $group,
            );
          }
        }
      }
      else {
        foreach ($config_info as $rule) {
          if (!empty($rule)) {
            $parts = explode(":", $rule, 2);
            $acl[$sid][] = array(
              drupal_strtoupper($parts[0]),
              trim($parts[1]),
            );
          }
        }
      }
    }
  }
  return $acl[$sid];
}