System.Security.AccessControl.GenericSecurityDescriptor.GetSddlForm C# (CSharp) Method

GetSddlForm() public method

public GetSddlForm ( AccessControlSections includeSections ) : string
includeSections AccessControlSections
return string
        public string GetSddlForm(AccessControlSections includeSections)
        {
            byte[] binaryForm = new byte[BinaryLength];
            string resultSddl;
            int error;

            GetBinaryForm(binaryForm, 0);

            SecurityInfos flags = 0;

            if ((includeSections & AccessControlSections.Owner) != 0)
            {
                flags |= SecurityInfos.Owner;
            }

            if ((includeSections & AccessControlSections.Group) != 0)
            {
                flags |= SecurityInfos.Group;
            }

            if ((includeSections & AccessControlSections.Audit) != 0)
            {
                flags |= SecurityInfos.SystemAcl;
            }

            if ((includeSections & AccessControlSections.Access) != 0)
            {
                flags |= SecurityInfos.DiscretionaryAcl;
            }

            error = Win32.ConvertSdToSddl(binaryForm, 1, flags, out resultSddl);

            if (error == Interop.Errors.ERROR_INVALID_PARAMETER ||
                error == Interop.Errors.ERROR_UNKNOWN_REVISION)
            {
                //
                // Indicates that the marshaling logic in GetBinaryForm is busted
                //

                Debug.Assert(false, "binaryForm produced invalid output");
                throw new InvalidOperationException();
            }
            else if (error != Interop.Errors.ERROR_SUCCESS)
            {
                Debug.Assert(false, string.Format(CultureInfo.InvariantCulture, "Win32.ConvertSdToSddl returned {0}", error));
                throw new InvalidOperationException();
            }

            return resultSddl;
        }

Same methods

GenericSecurityDescriptor::GetSddlForm ( System includeSections ) : string

Usage Example

Beispiel #1
0
 /// <summary>
 ///   Sets the security descriptor for the folder. Not available to Task Scheduler 1.0.
 /// </summary>
 /// <param name="sd"> The security descriptor for the folder. </param>
 /// <param name="includeSections"> Section(s) of the security descriptor to set. </param>
 public void SetSecurityDescriptor(GenericSecurityDescriptor sd, AccessControlSections includeSections)
 {
     SetSecurityDescriptorSddlForm(sd.GetSddlForm(includeSections), includeSections);
 }
All Usage Examples Of System.Security.AccessControl.GenericSecurityDescriptor::GetSddlForm