Core\Ldap\Ad\AccountFlags::isPartialSecretsAccount
$accountFlags->isPartialSecretsAccount(): boolChecks if an account is a read-only domain controller. The result is true or false.
A read-only domain controller is a server with a copy of the directory that it cannot change. It keeps the passwords of only some users. Companies use it in places that are less safe, such as a small branch office.
isPartialSecretsAccount reads the bit 0x4000000 of userAccountControl. The account of a read-only domain controller usually has the value 83890176.
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\AccountFlags method that checks a flag now starts with is, has, allows or uses, for example isDisabled() and hasNonExpiringPassword(). The field trustedToAuthForDelegation of with() is now trustedToAuthenticateForDelegation. |
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 person is not a read only controller
<?nvs// Shows that `isPartialSecretsAccount` returns `false` for the account of a person.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Anna Berg,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { // This prints `read-only controller: false`. echo 'read-only controller: ', $flags->isPartialSecretsAccount() ? 'true' : 'false', "\n";}read-only controller: falseSkip read only controllers
<?nvs// Shows how to skip read-only domain controllers when you list the accounts of a directory.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $found = $corp->search( Core\Ldap\Filter::equals('objectClass', 'user'), { base: 'OU=Company,DC=example,DC=test', select: ['userAccountControl'] },);
array<tainted string> $names = [];foreach ($found as Core\Ldap\Entry $account) { var $flags = $account->accountFlags(); if ($flags != null && !$flags->isPartialSecretsAccount()) { $names[] = $account->dn()->rdnValue(); }}
// The server sends entries in no fixed order, so the names are sorted.// No account here is a read-only domain controller. This prints `Anna Berg`, `Ben Kohl`, `Carla Diaz`, `Dora Lind` and `Reader`.foreach (Core\Arr::sort($names) as tainted string $name) { echo $name, "\n";}Anna BergBen KohlCarla DiazDora LindReaderBuild a read only controller
<?nvs// Shows how to build the flags of a read-only domain controller on a copy made with `with`.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Anna Berg,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { // A read-only domain controller is a computer account with two more flags. var $controller = $flags->with({ normalAccount: false, workstationTrustAccount: true, trustedToAuthenticateForDelegation: true, partialSecretsAccount: true, });
// This prints `512 false` and then `83890176 true`. echo $flags->bits(), $flags->isPartialSecretsAccount() ? ' true' : ' false', "\n"; echo $controller->bits(), $controller->isPartialSecretsAccount() ? ' true' : ' false', "\n";}512 false83890176 true