Пример #1
0
        /// <summary>
        /// Creates a Security Descriptor from an SDDL string
        /// </summary>
        /// <param name="sddlString">The SDDL string that represents the Security Descriptor</param>
        /// <exception cref="System.FormatException">Invalid SDDL String Format</exception>
        public SecurityDescriptor(SddlString sddlString)
        {
            Match m = CommonRegex.SddlStringRegex.Match(sddlString.ToString());

            if (!m.Success)
            {
                throw new FormatException("Invalid SDDL String Format");
            }

            this.sddlString = sddlString;

            if (m.Groups["owner"] != null && m.Groups["owner"].Success && !String.IsNullOrEmpty(m.Groups["owner"].Value))
            {
                this.Owner = SecurityIdentity.SecurityIdentityFromSIDorAbbreviation(m.Groups["owner"].Value);
            }

            if (m.Groups["group"] != null && m.Groups["group"].Success && !String.IsNullOrEmpty(m.Groups["group"].Value))
            {
                this.Group = SecurityIdentity.SecurityIdentityFromSIDorAbbreviation(m.Groups["group"].Value);
            }

            if (m.Groups["dacl"] != null && m.Groups["dacl"].Success && !String.IsNullOrEmpty(m.Groups["dacl"].Value))
            {
                this.DACL = new AccessControlListEx(m.Groups["dacl"].Value);
            }

            if (m.Groups["sacl"] != null && m.Groups["sacl"].Success && !String.IsNullOrEmpty(m.Groups["sacl"].Value))
            {
                this.SACL = new AccessControlListEx(m.Groups["sacl"].Value);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a Access Control Entry from a ACE string
        /// </summary>
        /// <param name="aceString">ACE string</param>
        public AccessControlEntryEx(string aceString)
        {
            Regex aceRegex = new Regex(cAceExpr, RegexOptions.IgnoreCase);

            Match aceMatch = aceRegex.Match(aceString);

            if (!aceMatch.Success)
            {
                throw new FormatException("Invalid ACE String Format");
            }

            if (aceMatch.Groups["ace_type"] != null && aceMatch.Groups["ace_type"].Success && !String.IsNullOrEmpty(aceMatch.Groups["ace_type"].Value))
            {
                Int32 aceTypeValue = Array.IndexOf <string>(AccessControlEntryEx.aceTypeStrings, aceMatch.Groups["ace_type"].Value.ToUpper());

                if (aceTypeValue == -1)
                {
                    throw new FormatException("Invalid ACE String Format");
                }

                this.aceType = ( AceType )aceTypeValue;
            }
            else
            {
                throw new FormatException("Invalid ACE String Format");
            }

            if (aceMatch.Groups["ace_flags"] != null && aceMatch.Groups["ace_flags"].Success && !String.IsNullOrEmpty(aceMatch.Groups["ace_flags"].Value))
            {
                string aceFlagsValue = aceMatch.Groups["ace_flags"].Value.ToUpper();
                for (Int32 i = 0; i < aceFlagsValue.Length - 1; i += 2)
                {
                    Int32 flagValue = Array.IndexOf <string>(AccessControlEntryEx.aceFlagStrings, aceFlagsValue.Substring(i, 2));

                    if (flagValue == -1)
                    {
                        throw new FormatException("Invalid ACE String Format");
                    }

                    this.flags = this.flags | (( AceFlags )( Int32 )Math.Pow(2.0d, flagValue));
                }
            }

            if (aceMatch.Groups["rights"] != null && aceMatch.Groups["rights"].Success && !String.IsNullOrEmpty(aceMatch.Groups["rights"].Value))
            {
                string rightsValue = aceMatch.Groups["rights"].Value.ToUpper();
                for (Int32 i = 0; i < rightsValue.Length - 1; i += 2)
                {
                    Int32 rightValue = Array.IndexOf <string>(AccessControlEntryEx.rightsStrings, rightsValue.Substring(i, 2));

                    if (rightValue == -1)
                    {
                        throw new FormatException("Invalid ACE String Format");
                    }

                    this.rights = this.rights | ( AceRights )( Int32 )Math.Pow(2.0d, rightValue);
                }
            }

            if (aceMatch.Groups["object_guid"] != null && aceMatch.Groups["object_guid"].Success && !String.IsNullOrEmpty(aceMatch.Groups["object_guid"].Value))
            {
                this.objectGuid = new Guid(aceMatch.Groups["object_guid"].Value);
            }

            if (aceMatch.Groups["inherit_object_guid"] != null && aceMatch.Groups["inherit_object_guid"].Success && !String.IsNullOrEmpty(aceMatch.Groups["inherit_object_guid"].Value))
            {
                this.inheritObjectGuid = new Guid(aceMatch.Groups["inherit_object_guid"].Value);
            }

            if (aceMatch.Groups["account_sid"] != null && aceMatch.Groups["account_sid"].Success && !String.IsNullOrEmpty(aceMatch.Groups["account_sid"].Value))
            {
                this.accountSID = SecurityIdentity.SecurityIdentityFromSIDorAbbreviation(aceMatch.Groups["account_sid"].Value.ToUpper());
            }
            else
            {
                throw new FormatException("Invalid ACE String Format");
            }
        }