Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ntSecurityDescriptor utilities #681

Open
stevebauman opened this issue Jan 10, 2024 Discussed in #678 · 0 comments
Open

Create ntSecurityDescriptor utilities #681

stevebauman opened this issue Jan 10, 2024 Discussed in #678 · 0 comments
Labels
enhancement New feature or request

Comments

@stevebauman
Copy link
Member

@kbisignani was able to utilize LdapTool's ntSecurityDescriptor to be able to update them in LdapRecord.

#678 (reply in thread)

$sd = new SecurityDescriptor($user->getAttribute('ntsecuritydescriptor')[0]);

// Flip the Everyone ACE type to deny for the 'WD' SID ('WD' is the SID short name for "Everyone").
foreach ($sd->getDacl()->getAces() as $ace) {
   if ((string) $ace->getTrustee() === SID::SHORT_NAME['WD'] && (string) $ace->getObjectType() === AceRights::EXTENDED['CHANGE_PASSWORD']) {
	   $ace->setType('OD');
   }
}

// OD is short for an object deny ace type...
$ace = (new Ace('OD'))
    // The SID of the user being granted the right ('PS' is the SID short name for "Principal Self").
    ->setTrustee('PS')
    // This is an extended access right for "User cannot change password"...
    ->setObjectType(AceRights::EXTENDED['CHANGE_PASSWORD'])
    // This sets the ACE with the "Control Access" right...
    ->setRights(new AceRights(AceRights::SHORT_NAME['CR']));
$sd->getDacl()->addAce($ace);

// Now set the new Security Descriptor value and save it
$user->setAttribute('ntSecurityDescriptor', $sd->toBinary());
$user->save();

LdapTools is MIT so we can port some of these utilities over and maintain credit to the original author with an @author tag.

@stevebauman stevebauman added the enhancement New feature or request label Jan 10, 2024
@stevebauman stevebauman changed the title Create ntSecurityDescriptor utilities Create ntSecurityDescriptor utilities Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant