Core\Ldap\Ad\AccountFlags::with
$accountFlags->with({…}): Core\Ldap\Ad\AccountFlags$accountFlags->with( {…}, ): Core\Ldap\Ad\AccountFlags
Returns a copy of the account flags with some flags set or cleared, such as $flags->with({ disabled: true }). Each option is one flag: true sets it, and false clears it. A flag you do not name stays as it is.
The object you call with on does not change. Call bits() on the copy to get the new number of userAccountControl, for example to write it back to the directory.
There is no option for isLockedOut or isPasswordExpired. Active Directory computes these two flags, so a program cannot set them. The copy keeps their values and the value of mustChangePassword.
Options
scriptbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.disabledbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.homeDirectoryRequiredbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.passwordNotRequiredbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.reversibleEncryptionbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.temporaryDuplicateAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.normalAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.interdomainTrustAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.workstationTrustAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.serverTrustAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.passwordNeverExpiresbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.mnsLogonAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.smartcardRequiredbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.trustedForDelegationbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.notDelegatedbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.useDesKeyOnlybooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.noPreauthRequiredbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.trustedToAuthenticateForDelegationbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.partialSecretsAccountbooloptionaltruesets the flag andfalseclears it. Leave it out to keep the flag as it is.
Return value
Returns Core\Ldap\Ad\AccountFlags. A new Core\Ldap\Ad\AccountFlags. The object you call it on does not change.
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"]Disable an account
<?nvs// Shows how to get the flags of an account after it is disabled.// 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) { // `with` sets the flags you name and keeps every other flag. var $changed = $flags->with({ disabled: true });
// The account stays a normal account. This prints `disabled: true, normal: true`. echo 'disabled: ', $changed->isDisabled() ? 'true' : 'false'; echo ', normal: ', $changed->isNormalAccount() ? 'true' : 'false', "\n";}disabled: true, normal: trueThe original does not change
<?nvs// Shows that `with` returns a new object, and the object you call it on does not change.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Dora Lind,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { var $enabled = $flags->with({ disabled: false });
// This prints `514` and then `512`. echo $flags->bits(), "\n"; echo $enabled->bits(), "\n";}514512Change two flags
<?nvs// Shows how to set one flag and clear another in the same call.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Ben Kohl,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { // Ben Kohl's password never expires. This copy is disabled, and its password expires again. var $changed = $flags->with({ disabled: true, passwordNeverExpires: false });
// This prints `66048` and then `514`. echo $flags->bits(), "\n"; echo $changed->bits(), "\n";}66048514