Пример #1
0
        public Ace(string ace, SecurableObjectType type = SecurableObjectType.Unknown)
        {
            Raw = ace;

            var parts = Raw.Split(SeparatorToken);

            if (parts.Length < 6)
            {
                Report(Error.SDP003.Format(parts.Length.ToString()));
            }

            // ace_type
            if (parts.Length > 0 && parts[0].Length > 0)
            {
                string aceType = Match.OneByPrefix(parts[0], AceTypesDict, out var reminder);

                if (aceType == null || !string.IsNullOrEmpty(reminder))
                {
                    aceType = Format.Unknown(parts[0]);
                }

                AceType = aceType;
            }

            // ace_flags
            if (parts.Length > 1 && parts[1].Length > 0)
            {
                var flags = Match.ManyByPrefix(parts[1], AceFlagsDict, out var reminder);

                if (!string.IsNullOrEmpty(reminder))
                {
                    flags.AddLast(Format.Unknown(reminder));
                }

                AceFlags = flags.ToArray();
            }

            // rights
            if (parts.Length > 2 && parts[2].Length > 0)
            {
                if (TryParseHex(parts[2], out uint accessMask))
                {
                    IEnumerable <string> rights = Enumerable.Empty <string>();

                    if (AceUintSpecificRightsDict.TryGetValue(type, out var aceUintSpecificRightsForType))
                    {
                        rights = rights.Concat(Match.ManyByUint(accessMask, aceUintSpecificRightsForType, out accessMask));
                    }

                    rights = rights.Concat(Match.ManyByUint(accessMask, AceUintRightsDict, out accessMask));

                    if (accessMask > 0)
                    {
                        rights = rights.Concat(new[] { Format.Unknown($"0x{accessMask:X}") });
                    }

                    Rights = rights.ToArray();
                }
                else
                {
                    var rights = Match.ManyByPrefix(parts[2], AceAliasRightsDict, out var reminder);

                    if (!string.IsNullOrEmpty(reminder))
                    {
                        rights.AddLast(Format.Unknown(reminder));
                    }

                    Rights = rights.ToArray();
                }
            }

            // object_guid
            if (parts.Length > 3 && parts[3].Length > 0)
            {
                ObjectGuid = parts[3];
            }

            // inherit_object_guid
            if (parts.Length > 4 && parts[4].Length > 0)
            {
                InheritObjectGuid = parts[4];
            }

            // account_sid
            if (parts.Length > 5 && parts[5].Length > 0)
            {
                AceSid = new Sid(parts[5]);
            }

            // resource_attribute
            if (parts.Length > 6)
            {
                // unsupported
            }
        }
Пример #2
0
        public Ace(string ace, SecurableObjectType type = SecurableObjectType.Unknown)
        {
            string[] parts = ace.Split(SeparatorToken);

            if (parts.Length < 6)
            {
                Utility.Output.DebugWrite("Incorrect ACE format?");
                Utility.Output.DebugWrite(ace.ToString());
                // ERROR Ace have incorrect format - less parts than 6.
            }

            // ace_type
            if (parts.Length > 0 && parts[0].Length > 0)
            {
                string aceType = Match.OneByPrefix(parts[0], AceTypesDict, out string reminder);

                if (aceType == null || !string.IsNullOrEmpty(reminder))
                {
                    aceType = Format.Unknown(parts[0]);
                }

                AceType = aceType;
            }

            // ace_flags
            if (parts.Length > 1 && parts[1].Length > 0)
            {
                LinkedList <string> flags = Match.ManyByPrefix(parts[1], AceFlagsDict, out string reminder);

                if (!string.IsNullOrEmpty(reminder))
                {
                    flags.AddLast(Format.Unknown(reminder));
                }

                AceFlags = flags.ToArray();
            }

            // rights
            if (parts.Length > 2 && parts[2].Length > 0)
            {
                if (TryParseHex(parts[2], out uint accessMask))
                {
                    IEnumerable <string> rights = Enumerable.Empty <string>();

                    if (AceUintSpecificRightsDict.TryGetValue(type, out Dictionary <uint, string> aceUintSpecificRightsForType))
                    {
                        rights = rights.Concat(Match.ManyByUint(accessMask, aceUintSpecificRightsForType, out accessMask));
                    }

                    rights = rights.Concat(Match.ManyByUint(accessMask, AceUintRightsDict, out accessMask));

                    if (accessMask > 0)
                    {
                        rights = rights.Concat(new[] { Format.Unknown($"0x{accessMask:X}") });
                    }

                    Rights = rights.ToArray();
                }
                else
                {
                    LinkedList <string> rights = Match.ManyByPrefix(parts[2], AceAliasRightsDict, out string reminder);

                    if (!string.IsNullOrEmpty(reminder))
                    {
                        rights.AddLast(Format.Unknown(reminder));
                    }

                    Rights = rights.ToArray();
                }
            }

            // object_guid
            if (parts.Length > 3 && parts[3].Length > 0)
            {
                ObjectGuid = parts[3];
            }

            // inherit_object_guid
            if (parts.Length > 4 && parts[4].Length > 0)
            {
                InheritObjectGuid = parts[4];
            }

            // account_sid
            if (parts.Length > 5 && parts[5].Length > 0)
            {
                AceSid = new Sid(parts[5]);
            }

            // resource_attribute
            if (parts.Length > 6)
            {
                // unsupported
            }
        }