Example #1
0
        /// <summary>Returns an array of byte values that represents the information contained in this <see cref="GenericSecurityDescriptor"/> object.</summary>
        /// <param name="sd">The <see cref="GenericSecurityDescriptor"/> object.</param>
        /// <returns>The byte array into which the contents of the <see cref="GenericSecurityDescriptor"/> is marshaled.</returns>
        public static byte[] GetBinaryForm(this GenericSecurityDescriptor sd)
        {
            if (sd == null)
            {
                throw new ArgumentNullException(nameof(sd));
            }
            var bin = new byte[sd.BinaryLength];

            sd.GetBinaryForm(bin, 0);
            return(bin);
        }
Example #2
0
        /// <summary>使用指定的字节值数组初始化 <see cref="T:System.Security.AccessControl.RawSecurityDescriptor" /> 类的新实例。</summary>
        /// <param name="binaryForm">用于创建新的 <see cref="T:System.Security.AccessControl.RawSecurityDescriptor" /> 对象的字节值数组。</param>
        /// <param name="offset">
        /// <paramref name="binaryForm" /> 数组中第一个要复制的元素的偏移量。</param>
        public RawSecurityDescriptor(byte[] binaryForm, int offset)
        {
            if (binaryForm == null)
            {
                throw new ArgumentNullException("binaryForm");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (binaryForm.Length - offset < 20)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
            }
            if ((int)binaryForm[offset + 0] != (int)GenericSecurityDescriptor.Revision)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("AccessControl_InvalidSecurityDescriptorRevision"));
            }
            byte         num1  = binaryForm[offset + 1];
            ControlFlags flags = (ControlFlags)((int)binaryForm[offset + 2] + ((int)binaryForm[offset + 3] << 8));

            if ((flags & ControlFlags.SelfRelative) == ControlFlags.None)
            {
                throw new ArgumentException(Environment.GetResourceString("AccessControl_InvalidSecurityDescriptorSelfRelativeForm"), "binaryForm");
            }
            int num2 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 4);
            SecurityIdentifier owner = num2 == 0 ? (SecurityIdentifier)null : new SecurityIdentifier(binaryForm, offset + num2);
            int num3 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 8);
            SecurityIdentifier group = num3 == 0 ? (SecurityIdentifier)null : new SecurityIdentifier(binaryForm, offset + num3);
            int    num4             = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 12);
            RawAcl systemAcl        = (flags & ControlFlags.SystemAclPresent) == ControlFlags.None || num4 == 0 ? (RawAcl)null : new RawAcl(binaryForm, offset + num4);
            int    num5             = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 16);
            RawAcl discretionaryAcl = (flags & ControlFlags.DiscretionaryAclPresent) == ControlFlags.None || num5 == 0 ? (RawAcl)null : new RawAcl(binaryForm, offset + num5);

            this.CreateFromParts(flags, owner, group, systemAcl, discretionaryAcl);
            if ((flags & ControlFlags.RMControlValid) == ControlFlags.None)
            {
                return;
            }
            this.ResourceManagerControl = num1;
        }
Example #3
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);
 }
Example #4
0
 /// <summary>
 ///   Creates a folder for related tasks. Not available to Task Scheduler 1.0.
 /// </summary>
 /// <param name="subFolderName"> The name used to identify the folder. If "FolderName\SubFolder1\SubFolder2" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see
 ///    cref="TaskFolder" /> instance. The root task folder is specified with a backslash (\). An example of a task folder path, under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path. </param>
 /// <param name="sd"> The security descriptor associated with the folder. </param>
 /// <returns> A <see cref="TaskFolder" /> instance that represents the new subfolder. </returns>
 public TaskFolder CreateFolder(string subFolderName, GenericSecurityDescriptor sd)
 {
     return CreateFolder(subFolderName, sd.GetSddlForm(AccessControlSections.All));
 }
        public RawSecurityDescriptor(byte[] binaryForm, int offset)
        {
            SecurityIdentifier identifier;
            SecurityIdentifier identifier2;
            RawAcl             acl;
            RawAcl             acl2;

            if (binaryForm == null)
            {
                throw new ArgumentNullException("binaryForm");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if ((binaryForm.Length - offset) < 20)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
            }
            if (binaryForm[offset] != GenericSecurityDescriptor.Revision)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("AccessControl_InvalidSecurityDescriptorRevision"));
            }
            byte num = binaryForm[offset + 1];

            System.Security.AccessControl.ControlFlags flags = (System.Security.AccessControl.ControlFlags)(binaryForm[offset + 2] + (binaryForm[offset + 3] << 8));
            if ((flags & System.Security.AccessControl.ControlFlags.SelfRelative) == System.Security.AccessControl.ControlFlags.None)
            {
                throw new ArgumentException(Environment.GetResourceString("AccessControl_InvalidSecurityDescriptorSelfRelativeForm"), "binaryForm");
            }
            int num2 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 4);

            if (num2 != 0)
            {
                identifier = new SecurityIdentifier(binaryForm, offset + num2);
            }
            else
            {
                identifier = null;
            }
            int num3 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 8);

            if (num3 != 0)
            {
                identifier2 = new SecurityIdentifier(binaryForm, offset + num3);
            }
            else
            {
                identifier2 = null;
            }
            int num4 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 12);

            if (((flags & System.Security.AccessControl.ControlFlags.SystemAclPresent) != System.Security.AccessControl.ControlFlags.None) && (num4 != 0))
            {
                acl = new RawAcl(binaryForm, offset + num4);
            }
            else
            {
                acl = null;
            }
            int num5 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 0x10);

            if (((flags & System.Security.AccessControl.ControlFlags.DiscretionaryAclPresent) != System.Security.AccessControl.ControlFlags.None) && (num5 != 0))
            {
                acl2 = new RawAcl(binaryForm, offset + num5);
            }
            else
            {
                acl2 = null;
            }
            this.CreateFromParts(flags, identifier, identifier2, acl, acl2);
            if ((flags & System.Security.AccessControl.ControlFlags.RMControlValid) != System.Security.AccessControl.ControlFlags.None)
            {
                this.ResourceManagerControl = num;
            }
        }
Example #6
0
        /// <summary>Returns an array of byte values that represents the information contained in this <see cref="T:System.Security.AccessControl.GenericSecurityDescriptor" /> object.</summary>
        /// <param name="binaryForm">The byte array into which the contents of the <see cref="T:System.Security.AccessControl.GenericSecurityDescriptor" /> is marshaled.</param>
        /// <param name="offset">The offset at which to start marshaling.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="offset" /> is negative or too high to allow the entire <see cref="T:System.Security.AccessControl.GenericSecurityDescriptor" /> to be copied into <paramref name="array" />.</exception>
        // Token: 0x0600205D RID: 8285 RVA: 0x00071708 File Offset: 0x0006F908
        public void GetBinaryForm(byte[] binaryForm, int offset)
        {
            if (binaryForm == null)
            {
                throw new ArgumentNullException("binaryForm");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (binaryForm.Length - offset < this.BinaryLength)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
            }
            int  num          = offset;
            int  binaryLength = this.BinaryLength;
            byte b            = (this is RawSecurityDescriptor && (this.ControlFlags & ControlFlags.RMControlValid) != ControlFlags.None) ? (this as RawSecurityDescriptor).ResourceManagerControl : 0;
            int  num2         = (int)this.ControlFlags;

            if (this.IsCraftedAefaDacl)
            {
                num2 &= -5;
            }
            binaryForm[offset]     = GenericSecurityDescriptor.Revision;
            binaryForm[offset + 1] = b;
            binaryForm[offset + 2] = (byte)num2;
            binaryForm[offset + 3] = (byte)(num2 >> 8);
            int offset2 = offset + 4;
            int offset3 = offset + 8;
            int offset4 = offset + 12;
            int offset5 = offset + 16;

            offset += 20;
            if (this.Owner != null)
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset2, offset - num);
                this.Owner.GetBinaryForm(binaryForm, offset);
                offset += this.Owner.BinaryLength;
            }
            else
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset2, 0);
            }
            if (this.Group != null)
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset3, offset - num);
                this.Group.GetBinaryForm(binaryForm, offset);
                offset += this.Group.BinaryLength;
            }
            else
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset3, 0);
            }
            if ((this.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None && this.GenericSacl != null)
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset4, offset - num);
                this.GenericSacl.GetBinaryForm(binaryForm, offset);
                offset += this.GenericSacl.BinaryLength;
            }
            else
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset4, 0);
            }
            if ((this.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None && this.GenericDacl != null && !this.IsCraftedAefaDacl)
            {
                GenericSecurityDescriptor.MarshalInt(binaryForm, offset5, offset - num);
                this.GenericDacl.GetBinaryForm(binaryForm, offset);
                offset += this.GenericDacl.BinaryLength;
                return;
            }
            GenericSecurityDescriptor.MarshalInt(binaryForm, offset5, 0);
        }
 public static bool IsSddlConversionSupported()
 {
     return(GenericSecurityDescriptor.IsSddlConversionSupported());
 }
Example #8
0
        /// <summary>Initializes a new instance of the <see cref="T:System.Security.AccessControl.RawSecurityDescriptor" /> class from the specified array of byte values.</summary>
        /// <param name="binaryForm">The array of byte values from which to create the new <see cref="T:System.Security.AccessControl.RawSecurityDescriptor" /> object.</param>
        /// <param name="offset">The offset in the  <paramref name="binaryForm" /> array at which to begin copying.</param>
        // Token: 0x06002063 RID: 8291 RVA: 0x0007194C File Offset: 0x0006FB4C
        public RawSecurityDescriptor(byte[] binaryForm, int offset)
        {
            if (binaryForm == null)
            {
                throw new ArgumentNullException("binaryForm");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (binaryForm.Length - offset < 20)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
            }
            if (binaryForm[offset] != GenericSecurityDescriptor.Revision)
            {
                throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("AccessControl_InvalidSecurityDescriptorRevision"));
            }
            byte         resourceManagerControl = binaryForm[offset + 1];
            ControlFlags controlFlags           = (ControlFlags)((int)binaryForm[offset + 2] + ((int)binaryForm[offset + 3] << 8));

            if ((controlFlags & ControlFlags.SelfRelative) == ControlFlags.None)
            {
                throw new ArgumentException(Environment.GetResourceString("AccessControl_InvalidSecurityDescriptorSelfRelativeForm"), "binaryForm");
            }
            int num = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 4);
            SecurityIdentifier owner;

            if (num != 0)
            {
                owner = new SecurityIdentifier(binaryForm, offset + num);
            }
            else
            {
                owner = null;
            }
            int num2 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 8);
            SecurityIdentifier group;

            if (num2 != 0)
            {
                group = new SecurityIdentifier(binaryForm, offset + num2);
            }
            else
            {
                group = null;
            }
            int    num3 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 12);
            RawAcl systemAcl;

            if ((controlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None && num3 != 0)
            {
                systemAcl = new RawAcl(binaryForm, offset + num3);
            }
            else
            {
                systemAcl = null;
            }
            int    num4 = GenericSecurityDescriptor.UnmarshalInt(binaryForm, offset + 16);
            RawAcl discretionaryAcl;

            if ((controlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None && num4 != 0)
            {
                discretionaryAcl = new RawAcl(binaryForm, offset + num4);
            }
            else
            {
                discretionaryAcl = null;
            }
            this.CreateFromParts(controlFlags, owner, group, systemAcl, discretionaryAcl);
            if ((controlFlags & ControlFlags.RMControlValid) != ControlFlags.None)
            {
                this.ResourceManagerControl = resourceManagerControl;
            }
        }