Skip to content

Commit

Permalink
New function to match a DN againts filter, base and scope
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Oct 29, 2024
1 parent a53bbf2 commit cebbde4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Ltb/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public function getLdapDate($date) : string;
* Get password policy configuration
*/
public function getPwdPolicyConfiguration($ldap, $entry_dn, $default_ppolicy_dn) : Array;

/*
* Return special attribute name containing entry DN
*/
public function getDnAttribute() : string;
}
4 changes: 4 additions & 0 deletions src/Ltb/Directory/ActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,8 @@ public function getPwdPolicyConfiguration($ldap, $entry_dn, $default_ppolicy_dn)

return $ppolicyConfig;
}

public function getDnAttribute() : string {
return "distinguishedName";
}
}
3 changes: 3 additions & 0 deletions src/Ltb/Directory/OpenLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,7 @@ public function getPwdPolicyConfiguration($ldap, $entry_dn, $default_ppolicy_dn)
return $ppolicyConfig;
}

public function getDnAttribute() : string {
return "entryDn";
}
}
22 changes: 22 additions & 0 deletions src/Ltb/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,27 @@ function get_first_value($ldap_base, $ldap_scope, $ldap_filter, $attribute): str

}

/**
* test if a DN matches filter, base and scope
* @param string $dn: entry DN
* @param string $dnAttribute: attribute name containing the DN
* @param string $filter
* @param string $base
* @param string $scope
* @return bool: true if DN matches filter, base and scope
*/
public function matchDn($dn, $dnAttribute, $filter, $base, $scope): bool {

# Build filter
$search_filter = '(&' . $filter . '(' . $dnAttribute . '=' . $dn .'))';

# Search with scope
$search = $this->search_with_scope($scope, $base, $search_filter, ['1.1']);

$count = \Ltb\PhpLDAP::ldap_count_entries($this->ldap, $search);

if ( $count == 1) { return true; }
return false;
}
}
?>

0 comments on commit cebbde4

Please sign in to comment.