Core\Ldap\Ad\GroupType::bits
$groupType->bits(): intReturns the whole number of groupType, exactly as Active Directory stores it. Each flag of the group type is one bit of this number.
The security flag is the highest bit, 0x80000000. Active Directory reads the number as signed, so bits returns a negative number for a security group. A global security group is -2147483646, and a global distribution group is 2.
Use bits when you need the number itself, for example to write a changed group type back to the directory. To check one flag, call the function for that flag, such as isSecurityGroup().
Return value
Returns int. The number, with every bit.
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"]The stored number
<?nvs// Shows the number Active Directory stores in `groupType` for two groups.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');array<string> $dns = [ 'CN=Employees,OU=Company,DC=example,DC=test', 'CN=Newsletter,OU=Company,DC=example,DC=test',];
foreach ($dns as string $dn) { var $group = $corp->read($dn, { select: ['groupType'] }); var $type = $group?->groupType(); if ($group == null || $type == null) { continue; } // A security group has a negative number, because its flag is the highest bit. // This prints `Employees: -2147483646` and `Newsletter: 2`. echo $group->dn()->rdnValue(), ': ', $type->bits(), "\n";}Employees: -2147483646Newsletter: 2The same number as int
<?nvs// Shows that `bits` returns the same number that `int` reads from `groupType`.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $group = $corp->read('CN=Managers,OU=Company,DC=example,DC=test', { select: ['groupType'] });var $type = $group?->groupType();
if ($group != null && $type != null) { // This prints `-2147483646` twice. echo $type->bits(), "\n"; echo $group->int('groupType') ?? 0, "\n";}-2147483646-2147483646The number to write back
<?nvs// Shows how to get the number for a changed group type, for example to write it back to the directory.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $type = $corp->read('CN=Newsletter,OU=Company,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) { // `with` turns the mailing list into a security group. `bits` returns the new number. // This prints `2` and then `-2147483646`. echo $type->bits(), "\n"; echo $type->with({ security: true })->bits(), "\n";}2-2147483646