fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / adldap2 / adldap2 / src / Objects / AccountControl.php
blob10f0966d4593ed0b9f59cecbe0b5b809530f96c1
1 <?php
3 namespace Adldap\Objects;
5 /**
6 * The Account Control class.
8 * This class is for easily building a user account control value.
10 * https://support.microsoft.com/en-us/kb/305144
12 class AccountControl
14 const SCRIPT = 1;
16 const ACCOUNTDISABLE = 2;
18 const HOMEDIR_REQUIRED = 8;
20 const LOCKOUT = 16;
22 const PASSWD_NOTREQD = 32;
24 const ENCRYPTED_TEXT_PWD_ALLOWED = 128;
26 const TEMP_DUPLICATE_ACCOUNT = 256;
28 const NORMAL_ACCOUNT = 512;
30 const INTERDOMAIN_TRUST_ACCOUNT = 2048;
32 const WORKSTATION_TRUST_ACCOUNT = 4096;
34 const SERVER_TRUST_ACCOUNT = 8192;
36 const DONT_EXPIRE_PASSWORD = 65536;
38 const MNS_LOGON_ACCOUNT = 131072;
40 const SMARTCARD_REQUIRED = 262144;
42 const TRUSTED_FOR_DELEGATION = 524288;
44 const NOT_DELEGATED = 1048576;
46 const USE_DES_KEY_ONLY = 2097152;
48 const DONT_REQ_PREAUTH = 4194304;
50 const PASSWORD_EXPIRED = 8388608;
52 const TRUSTED_TO_AUTH_FOR_DELEGATION = 16777216;
54 const PARTIAL_SECRETS_ACCOUNT = 67108864;
56 /**
57 * Stores the values to be added together to
58 * build the user account control integer.
60 * @var array
62 protected $values = [];
64 /**
65 * Constructor.
67 * @param int $flag
69 public function __construct($flag = null)
71 if (!is_null($flag)) {
72 $this->apply($flag);
76 /**
77 * Returns the account control integer as a string
78 * when the object is casted as a string.
80 * @return string
82 public function __toString()
84 return (string) $this->getValue();
87 /**
88 * Returns the account control integer when
89 * the object is casted as an integer.
91 * @return int
93 public function __toInt()
95 return $this->getValue();
98 /**
99 * Applies the specified flag.
101 * @param int $flag
103 public function apply($flag)
105 $flags = [];
107 for ($i = 0; $i <= 26; $i++) {
108 if ((int) $flag & (1 << $i)) {
109 array_push($flags, 1 << $i);
113 $this->setValues($flags);
117 * The logon script will be run.
119 * @return AccountControl
121 public function runLoginScript()
123 return $this->add(static::SCRIPT);
127 * The user account is locked.
129 * @return AccountControl
131 public function accountIsLocked()
133 return $this->add(static::LOCKOUT);
137 * The user account is disabled.
139 * @return AccountControl
141 public function accountIsDisabled()
143 return $this->add(static::ACCOUNTDISABLE);
147 * This is an account for users whose primary account is in another domain.
149 * This account provides user access to this domain, but not to any domain that
150 * trusts this domain. This is sometimes referred to as a local user account.
152 * @return AccountControl
154 public function accountIsTemporary()
156 return $this->add(static::TEMP_DUPLICATE_ACCOUNT);
160 * This is a default account type that represents a typical user.
162 * @return AccountControl
164 public function accountIsNormal()
166 return $this->add(static::NORMAL_ACCOUNT);
170 * This is a permit to trust an account for a system domain that trusts other domains.
172 * @return AccountControl
174 public function accountIsForInterdomain()
176 return $this->add(static::INTERDOMAIN_TRUST_ACCOUNT);
180 * This is a computer account for a computer that is running Microsoft
181 * Windows NT 4.0 Workstation, Microsoft Windows NT 4.0 Server, Microsoft
182 * Windows 2000 Professional, or Windows 2000 Server and is a member of this domain.
184 * @return AccountControl
186 public function accountIsForWorkstation()
188 return $this->add(static::WORKSTATION_TRUST_ACCOUNT);
192 * This is a computer account for a domain controller that is a member of this domain.
194 * @return AccountControl
196 public function accountIsForServer()
198 return $this->add(static::SERVER_TRUST_ACCOUNT);
202 * This is an MNS logon account.
204 * @return AccountControl
206 public function accountIsMnsLogon()
208 return $this->add(static::MNS_LOGON_ACCOUNT);
212 * (Windows 2000/Windows Server 2003) This account does
213 * not require Kerberos pre-authentication for logging on.
215 * @return AccountControl
217 public function accountDoesNotRequirePreAuth()
219 return $this->add(static::DONT_REQ_PREAUTH);
223 * When this flag is set, it forces the user to log on by using a smart card.
225 * @return AccountControl
227 public function accountRequiresSmartCard()
229 return $this->add(static::SMARTCARD_REQUIRED);
233 * (Windows Server 2008/Windows Server 2008 R2) The account is a read-only domain controller (RODC).
235 * This is a security-sensitive setting. Removing this setting from an RODC compromises security on that server.
237 * @return AccountControl
239 public function accountIsReadOnly()
241 return $this->add(static::PARTIAL_SECRETS_ACCOUNT);
245 * The home folder is required.
247 * @return AccountControl
249 public function homeFolderIsRequired()
251 return $this->add(static::HOMEDIR_REQUIRED);
255 * No password is required.
257 * @return AccountControl
259 public function passwordIsNotRequired()
261 return $this->add(static::PASSWD_NOTREQD);
265 * The user cannot change the password. This is a permission on the user's object.
267 * For information about how to programmatically set this permission, visit the following Web site:
268 * http://msdn2.microsoft.com/en-us/library/aa746398.aspx
270 * @return AccountControl
272 public function passwordCannotBeChanged()
274 return $this->add(static::PASSWD_NOTREQD);
278 * Represents the password, which should never expire on the account.
280 * @return AccountControl
282 public function passwordDoesNotExpire()
284 return $this->add(static::DONT_EXPIRE_PASSWORD);
288 * (Windows 2000/Windows Server 2003) The user's password has expired.
290 * @return AccountControl
292 public function passwordIsExpired()
294 return $this->add(static::PASSWORD_EXPIRED);
298 * The user can send an encrypted password.
300 * @return AccountControl
302 public function allowEncryptedTextPassword()
304 return $this->add(static::ENCRYPTED_TEXT_PWD_ALLOWED);
308 * When this flag is set, the service account (the user or computer account)
309 * under which a service runs is trusted for Kerberos delegation.
311 * Any such service can impersonate a client requesting the service.
313 * To enable a service for Kerberos delegation, you must set this
314 * flag on the userAccountControl property of the service account.
316 * @return AccountControl
318 public function trustForDelegation()
320 return $this->add(static::TRUSTED_FOR_DELEGATION);
324 * (Windows 2000/Windows Server 2003) The account is enabled for delegation.
326 * This is a security-sensitive setting. Accounts that have this option enabled
327 * should be tightly controlled. This setting lets a service that runs under the
328 * account assume a client's identity and authenticate as that user to other remote
329 * servers on the network.
331 * @return AccountControl
333 public function trustToAuthForDelegation()
335 return $this->add(static::TRUSTED_TO_AUTH_FOR_DELEGATION);
339 * When this flag is set, the security context of the user is not delegated to a
340 * service even if the service account is set as trusted for Kerberos delegation.
342 * @return AccountControl
344 public function doNotTrustForDelegation()
346 return $this->add(static::NOT_DELEGATED);
350 * (Windows 2000/Windows Server 2003) Restrict this principal to
351 * use only Data Encryption Standard (DES) encryption types for keys.
353 * @return AccountControl
355 public function useDesKeyOnly()
357 return $this->add(static::USE_DES_KEY_ONLY);
361 * Returns the complete account control value.
363 * @return int
365 public function getValue()
367 $total = 0;
369 foreach ($this->values as $value) {
370 $total = $total + $value;
373 return $total;
377 * Returns the account control's values.
379 * @return array
381 public function getValues()
383 return $this->values;
387 * Sets the account control values.
389 * @param array $flags
391 public function setValues(array $flags)
393 $this->values = $flags;
397 * Applies the inserted value to the values property array.
399 * @param int $value
401 * @return AccountControl
403 protected function add($value)
405 // Use the value as a key so if the same value
406 // is used, it will always be overwritten
407 $this->values[$value] = $value;
409 return $this;