Core\Ldap\Ad\AccountFlags::isNormalAccount
$accountFlags->isNormalAccount(): boolChecks if an account is an ordinary user account. The result is true or false.
Every account has one type. The account of a person is an ordinary user account. A computer, a domain controller and a trust with another domain have their own types, and for them isNormalAccount is false. Use it to keep only the accounts of people.
isNormalAccount reads the bit 0x200 of userAccountControl. An ordinary account is 512.
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 has a normal account
<?nvs// Shows that `isNormalAccount` returns `true` 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 `normal account: true`. echo 'normal account: ', $flags->isNormalAccount() ? 'true' : 'false', "\n";}normal account: trueCount the user accounts
<?nvs// Shows how to count the ordinary user accounts.// 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'] },);
uint $count = 0;uint $all = 0;foreach ($found as Core\Ldap\Entry $account) { var $flags = $account->accountFlags(); if ($flags != null) { $all = $all + 1; if ($flags->isNormalAccount()) { $count = $count + 1; } }}
// A disabled account is still an ordinary account. This prints `5 of 5`.echo $count, ' of ', $all, "\n";5 of 5Make a copy a computer account
<?nvs// Shows how `isNormalAccount` changes when a copy gets another account type.// 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) { // An account has one type, so the copy clears the `normalAccount` flag and sets the new type. var $computer = $flags->with({ normalAccount: false, workstationTrustAccount: true });
// This prints `512 true` and then `4096 false`. echo $flags->bits(), $flags->isNormalAccount() ? ' true' : ' false', "\n"; echo $computer->bits(), $computer->isNormalAccount() ? ' true' : ' false', "\n";}512 true4096 false