Core\Ldap\Sid::domain
$sid->domain(): ?Core\Ldap\SidReturns the SID without its last number. For a user or a group, this is the SID of its domain. For S-1-5-21-1004336348-1177238915-682003330-1105 the result is S-1-5-21-1004336348-1177238915-682003330.
Use it to check if two accounts are in the same domain, or to group SIDs by their domain.
Good to know: a SID with only one number after the authority, such as S-1-1-0, has no domain, and the result is null.
Return value
Returns ?Core\Ldap\Sid. The shorter SID, or null when this SID has only one number after the authority.
Examples
Find the domain
<?nvs// Shows how to find the domain of a user's SID.
var $user = Core\Ldap\Sid::parse('S-1-5-21-1004336348-1177238915-682003330-1105');// This prints S-1-5-21-1004336348-1177238915-682003330.echo $user->domain()?->toString() ?? 'none', "\n";S-1-5-21-1004336348-1177238915-682003330Same domain
<?nvs// Shows how to check if two SIDs are in the same domain.
var $ann = Core\Ldap\Sid::parse('S-1-5-21-1004336348-1177238915-682003330-1105');var $ben = Core\Ldap\Sid::parse('S-1-5-21-1004336348-1177238915-682003330-1106');var $other = Core\Ldap\Sid::parse('S-1-5-21-3623811015-3361044348-30300820-1013');// This prints yes and then no.echo $ann->domain()?->toString() == $ben->domain()?->toString() ? 'yes' : 'no', "\n";echo $ann->domain()?->toString() == $other->domain()?->toString() ? 'yes' : 'no', "\n";yesnoNo domain
<?nvs// Shows the result for a SID with only one number after the authority.
var $everyone = Core\Ldap\Sid::parse('S-1-1-0');// The result is `null`, so this prints no domain.if ($everyone->domain() == null) { echo "no domain\n";}no domain