Core\Ldap\Ad\GroupType::isSystemGroup
$groupType->isSystemGroup(): boolChecks if Active Directory created the group itself. The result is true or false.
The groups under CN=Builtin, such as Administrators, are created together with the domain, so isSystemGroup returns true for them. A group that a person or a program created returns false.
isSystemGroup reads the bit 0x1 of groupType.
Return value
Returns bool. true when the bit is set, and false when it is not.
Changelog
| Version | Change |
|---|---|
0.0.6 | Every 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.
# 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 built in group
<?nvs// Shows that `isSystemGroup` returns `true` for a group that came with the domain.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $type = $corp->read('CN=Administrators,CN=Builtin,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) { // This prints `system: true`. echo 'system: ', $type->isSystemGroup() ? 'true' : 'false', "\n";}system: trueGroups you created
<?nvs// Shows that `isSystemGroup` returns `false` for every group that somebody created.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $found = $corp->search( Core\Ldap\Filter::equals('objectClass', 'group'), { base: 'OU=Company,DC=example,DC=test', select: ['groupType'] },);
array<tainted string> $lines = [];foreach ($found as Core\Ldap\Entry $group) { var $type = $group->groupType(); if ($type != null) { $lines[] = $group->dn()->rdnValue() . ': ' . ($type->isSystemGroup() ? 'true' : 'false'); }}
// The server sends entries in no fixed order, so the lines are sorted.// This prints `false` for `Employees`, `Managers` and `Newsletter`.foreach (Core\Arr::sort($lines) as tainted string $line) { echo $line, "\n";}Employees: falseManagers: falseNewsletter: falseSkip built in groups
<?nvs// Shows how to leave out built-in groups, for example from a list a person can edit.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');array<string> $dns = [ 'CN=Administrators,CN=Builtin,DC=example,DC=test', 'CN=Employees,OU=Company,DC=example,DC=test', 'CN=Users,CN=Builtin,DC=example,DC=test', 'CN=Managers,OU=Company,DC=example,DC=test',];
// The two groups under `CN=Builtin` are left out.// This prints `Employees` and `Managers`.foreach ($dns as string $dn) { var $group = $corp->read($dn, { select: ['groupType'] }); var $type = $group?->groupType(); if ($group != null && $type != null && !$type->isSystemGroup()) { echo $group->dn()->rdnValue(), "\n"; }}EmployeesManagers