Skip to content

Adding New-Service to -SecurityDescriptorSDDL parameter like Set-Service - #10483

Merged
Aditya Patwardhan (adityapatwardhan) merged 11 commits into
PowerShell:masterfrom
kvprasoon:new-srv-sdset
Oct 4, 2019
Merged

Aditya Patwardhan (adityapatwardhan) merged 11 commits into
PowerShell:masterfrom
kvprasoon:new-srv-sdset

Conversation

@kvprasoon

@kvprasoon PRASOON KARUNAN V (kvprasoon) commented Sep 4, 2019 •

Copy link
Copy Markdown
Contributor

PR Summary

This PR is to add -SecurityDescriptorSDDL parameter to New-Service cmdlet so that its in par with Set-Service in setting sddl for a service.

PR Checklist

{
var rawSecurityDescriptor = new RawSecurityDescriptor(securityDescriptorSddl);
RawAcl rawDiscretionaryAcl = rawSecurityDescriptor.DiscretionaryAcl ;
var discretionaryAcl = new DiscretionaryAcl (false, false, rawDiscretionaryAcl);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra spaces in two lines above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, why didn't CodeFactor catch this ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes it is not predictable :-)

bool status = NativeMethods.SetServiceObjectSecurity(
hService,
SecurityInfos.DiscretionaryAcl,
securityDescriptorByte);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation must be 4 spaces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, why didn't CodeFactor catch this ?

@adityapatwardhan

Copy link
Copy Markdown
Member

PoshChan-Bot (@PoshChan) please retry static

}
}

if (!string.IsNullOrEmpty(SecurityDescriptorSddl))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this work?

service = new ServiceController(Name);

if (!string.IsNullOrEmpty(SecurityDescriptorSddl))
{
    SetServiceSecurityDescriptor(service, SecurityDescriptorSddl, hService);
}

@vexx32 Rain Sallow (/u/ta11ow) (vexx32) Sep 5, 2019 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a parameter, right? Shouldn't we be using if (MyInvocation.BoundParameters.ContainsKey(nameof(SecurityDescriptorSddl))) { ... } for parameters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aditya Patwardhan (@adityapatwardhan) Rain Sallow (/u/ta11ow) (@vexx32) yes, I've used the same way how its implemented for Set-Service. I referred

L1883 if (!string.IsNullOrEmpty(Status)) which is used for -Status parameter in Set-Service.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Sep 5, 2019
@adityapatwardhan

Copy link
Copy Markdown
Member

PRASOON KARUNAN V (@kvprasoon) Please follow the template and file a doc issue for the new parameter. If it is filed, please paste the link here.

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Sep 6, 2019
@kvprasoon

Copy link
Copy Markdown
Contributor Author

doc changes MicrosoftDocs/PowerShell-Docs#4735

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 768e79a into PowerShell:master Oct 4, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

PRASOON KARUNAN V (@kvprasoon) Thanks for your contribution! Sorry for delay.

@kvprasoon
PRASOON KARUNAN V (kvprasoon) deleted the new-srv-sdset branch October 4, 2019 04:13
@ghost

Copy link
Copy Markdown

🎉v7.0.0-preview.5 has been released which incorporates this pull request.:tada:

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants