Skip to content

Core\Ldap\Ad\AccountFlags::isInterdomainTrustAccount

$accountFlags->isInterdomainTrustAccount(): bool

Checks if an account is a trust with another domain. The result is true or false.

A trust lets the users of one domain use the servers and files of another domain. Active Directory creates an account of this type for each trust, and the two domains use it to log in to each other. No person logs in with it.

isInterdomainTrustAccount reads the bit 0x800 of userAccountControl. An account with only this flag is 2048.

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"]

A person is not a trust

<?nvs
// Shows that `isInterdomainTrustAccount` 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 `trust: false`.
echo 'trust: ', $flags->isInterdomainTrustAccount() ? 'true' : 'false', "\n";
}
Output
trust: false

Skip trust accounts

<?nvs
// Shows how to skip trust accounts 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->isInterdomainTrustAccount()) {
$names[] = $account->dn()->rdnValue();
}
}
// The server sends entries in no fixed order, so the names are sorted.
// No account here is a trust. This prints `Anna Berg`, `Ben Kohl`, `Carla Diaz`, `Dora Lind` and `Reader`.
foreach (Core\Arr::sort($names) as tainted string $name) {
echo $name, "\n";
}
Output
Anna Berg
Ben Kohl
Carla Diaz
Dora Lind
Reader

Make a copy a trust

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