Core\Ldap\Ad\AccountFlags::isSmartcardRequired
$accountFlags->isSmartcardRequired(): boolChecks if the user must log in with a smart card. The result is true or false.
A smart card is a small card with a chip. The user puts it into a card reader to log in. When this flag is set, the user cannot log in with a password. An administrator sets this flag on accounts that need more protection.
isSmartcardRequired reads the bit 0x40000 of userAccountControl. A normal account with this flag is 262656.
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"]An account without a smart card
<?nvs// Shows that `isSmartcardRequired` returns `false` for an account that logs in with a password.// 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 `smart card: false`. echo 'smart card: ', $flags->isSmartcardRequired() ? 'true' : 'false', "\n";}smart card: falseList password logins
<?nvs// Shows how to list the accounts that may log in with a password.// 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->isSmartcardRequired()) { $names[] = $account->dn()->rdnValue(); }}
// The server sends entries in no fixed order, so the names are sorted.// No account here needs a smart card. 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 LindReaderRequire a smart card on a copy
<?nvs// Shows how `isSmartcardRequired` and the number change 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) { var $changed = $flags->with({ smartcardRequired: true });
// This prints `512 false` and then `262656 true`. echo $flags->bits(), $flags->isSmartcardRequired() ? ' true' : ' false', "\n"; echo $changed->bits(), $changed->isSmartcardRequired() ? ' true' : ' false', "\n";}512 false262656 true