Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
ProviderBaseSecurity.cs100 linesDownload Raw Back to namespaces
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Security.AccessControl;5 6namespace System.Management.Automation.Provider7{8    /// <summary>9    /// Defines the base class for all of the classes the provide implementations for a particular10    /// data store or item for the PowerShell core commands.11    /// </summary>12    public abstract partial class CmdletProvider13    {14        #region ISecurityDescriptorCmdletProvider method wrappers15 16        /// <summary>17        /// Internal wrapper for the GetSecurityDescriptor protected method. This method will18        /// only be called if the provider implements the ISecurityDescriptorCmdletProvider interface.19        /// </summary>20        /// <param name="path">21        /// The path to the item to retrieve the security descriptor from.22        /// </param>23        /// <param name="sections">24        /// Specifies the parts of a security descriptor to retrieve.25        /// </param>26        /// <param name="context">27        /// The context under which this method is being called.28        /// </param>29        /// <returns>30        /// Nothing. An instance of an object that represents the security descriptor31        /// for the item specified by the path should be written to the context.32        /// </returns>33        internal void GetSecurityDescriptor(34            string path,35            AccessControlSections sections,36            CmdletProviderContext context)37        {38            Context = context;39 40            ISecurityDescriptorCmdletProvider permissionProvider = this as ISecurityDescriptorCmdletProvider;41 42            //43            // if this is not supported, the fn will throw44            //45            CheckIfSecurityDescriptorInterfaceIsSupported(permissionProvider);46 47            // Call interface method48 49            permissionProvider.GetSecurityDescriptor(path, sections);50        }51 52        /// <summary>53        /// Internal wrapper for the SetSecurityDescriptor protected method. This method will54        /// only be called if the provider implements the ISecurityDescriptorCmdletProvider interface.55        /// </summary>56        /// <param name="path">57        /// The path to the item to set the new security descriptor on.58        /// </param>59        /// <param name="securityDescriptor">60        /// The new security descriptor for the item.61        /// </param>62        /// <param name="context">63        /// The context under which this method is being called.64        /// </param>65        /// <returns>66        /// Nothing. The security descriptor object that was set should be written67        /// to the context.68        /// </returns>69        internal void SetSecurityDescriptor(70            string path,71            ObjectSecurity securityDescriptor,72            CmdletProviderContext context)73        {74            Context = context;75 76            ISecurityDescriptorCmdletProvider permissionProvider = this as ISecurityDescriptorCmdletProvider;77 78            //79            // if this is not supported, the fn will throw80            //81            CheckIfSecurityDescriptorInterfaceIsSupported(permissionProvider);82 83            // Call interface method84 85            permissionProvider.SetSecurityDescriptor(path, securityDescriptor);86        }87 88        private static void CheckIfSecurityDescriptorInterfaceIsSupported(ISecurityDescriptorCmdletProvider permissionProvider)89        {90            if (permissionProvider == null)91            {92                throw93                    PSTraceSource.NewNotSupportedException(94                        ProviderBaseSecurity.ISecurityDescriptorCmdletProvider_NotSupported);95            }96        }97        #endregion ISecurityDescriptorCmdletProvider method wrappers98    }99}100