Skip to content

Core\Ldap\Ad\GroupType::isUniversal

$groupType->isUniversal(): bool

Checks if a group is a universal group. The result is true or false.

A universal group can have members from any domain, and it can be given permissions in any domain. Enterprise Admins and Schema Admins are universal groups.

A group has exactly one scope: global, domain local or universal. isUniversal reads the bit 0x8 of groupType.

Return value

Returns bool. true when the bit is set, and false when it is not.

Changelog

VersionChange
0.0.6Every Core\Ldap\Ad\GroupType method that checks a flag now starts with is, for example isGlobal() and isSecurityGroup(). The old names were system, global, domainLocal, universal, appBasic, appQuery and security.

Examples

The examples below run with this configuration file.

nvs.toml
# These examples use the LDAP directory server on this computer at port 16636.
# `tls_ca_file` is the certificate that the server's certificate is checked against.
[ldap.corp]
url = "ldaps://127.0.0.1:16636"
base = "DC=example,DC=test"
user = "CN=Reader,OU=Company,DC=example,DC=test"
password = "Novis-reader-1"
tls_ca_file = "../../../../../tests/db/ca.crt"
timeout = "5s"
# The program may open the `corp` directory.
[capabilities.ldap]
connect = ["corp"]

A universal group

<?nvs
// Shows that `isUniversal` returns `true` for a group with the universal scope.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $type = $corp->read('CN=Enterprise Admins,CN=Users,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) {
// This prints `universal: true`.
echo 'universal: ', $type->isUniversal() ? 'true' : 'false', "\n";
}
Output
universal: true

Name the scope

<?nvs
// Shows how to print the scope of a group as a word.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
array<string> $dns = [
'CN=Managers,OU=Company,DC=example,DC=test',
'CN=Cert Publishers,CN=Users,DC=example,DC=test',
'CN=Schema Admins,CN=Users,DC=example,DC=test',
];
// A group has exactly one scope, so one of the three checks is `true`.
// This prints `global`, `domain local` and `universal`, one for each group.
foreach ($dns as string $dn) {
var $type = $corp->read($dn, { select: ['groupType'] })?->groupType();
if ($type != null) {
if ($type->isUniversal()) {
echo "universal\n";
} elseif ($type->isDomainLocal()) {
echo "domain local\n";
} elseif ($type->isGlobal()) {
echo "global\n";
}
}
}
Output
global
domain local
universal

Check before adding a member

<?nvs
// Shows how to check that a group can take members from another domain.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $type = $corp->read('CN=Managers,OU=Company,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) {
// `Managers` is a global group, so it only takes members from its own domain.
// This prints `Managers takes members from other domains: false`.
echo 'Managers takes members from other domains: ', $type->isUniversal() ? 'true' : 'false', "\n";
}
Output
Managers takes members from other domains: false