Skip to content

Core\Ldap\Ad\AccountFlags::isTemporaryDuplicateAccount

$accountFlags->isTemporaryDuplicateAccount(): bool

Checks if an account is a local account for a user from another domain. The result is true or false.

Such an account is called a temporary duplicate account. The user's main account is in another domain, and this account gives the user access to this domain only. Few directories have such accounts. For an ordinary user account, isNormalAccount returns true instead.

isTemporaryDuplicateAccount reads the bit 0x100 of userAccountControl. An account with only this flag is 256.

Return value

Returns bool. true when the bit is set, and false when it is not.

Changelog

VersionChange
0.0.6Every 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.

nvs.toml
# 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 ordinary account

<?nvs
// Shows that `isTemporaryDuplicateAccount` returns `false` for an ordinary user account.
// 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 `temporary duplicate: false`.
echo 'temporary duplicate: ', $flags->isTemporaryDuplicateAccount() ? 'true' : 'false', "\n";
}
Output
temporary duplicate: false

Count accounts from other domains

<?nvs
// Shows how to count the accounts that belong to users from another domain.
// 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->isTemporaryDuplicateAccount()) {
$count = $count + 1;
}
}
}
// Every account in this directory is an ordinary account. This prints `0 of 5`.
echo $count, ' of ', $all, "\n";
Output
0 of 5

Change the account type on a copy

<?nvs
// Shows how to change the account type 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) {
// An account has one type, so the copy clears the `normalAccount` flag and sets the new type.
var $changed = $flags->with({ normalAccount: false, temporaryDuplicateAccount: true });
// This prints `512 false` and then `256 true`.
echo $flags->bits(), $flags->isTemporaryDuplicateAccount() ? ' true' : ' false', "\n";
echo $changed->bits(), $changed->isTemporaryDuplicateAccount() ? ' true' : ' false', "\n";
}
Output
512 false
256 true