Ejemplo n.º 1
0
        private RoleEntry Clone(ICollection <string> parameters, bool performValidation, string newName = null)
        {
            RoleEntry roleEntry;

            if (this is CmdletRoleEntry)
            {
                roleEntry = new CmdletRoleEntry((CmdletRoleEntry)this, newName);
            }
            else if (this is ScriptRoleEntry)
            {
                roleEntry = new ScriptRoleEntry();
            }
            else if (this is ApplicationPermissionRoleEntry)
            {
                roleEntry = new ApplicationPermissionRoleEntry();
            }
            else if (this is WebServiceRoleEntry)
            {
                roleEntry = new WebServiceRoleEntry();
            }
            else
            {
                roleEntry = new UnknownRoleEntry();
            }
            if (string.IsNullOrWhiteSpace(newName))
            {
                roleEntry.name = this.Name;
            }
            else
            {
                roleEntry.name = newName;
            }
            roleEntry.SetParameters(parameters, performValidation);
            return(roleEntry);
        }
Ejemplo n.º 2
0
        internal static int CompareRoleEntriesByName(RoleEntry a, RoleEntry b)
        {
            CmdletRoleEntry cmdletRoleEntry  = a as CmdletRoleEntry;
            CmdletRoleEntry cmdletRoleEntry2 = b as CmdletRoleEntry;

            if (a == null || b == null)
            {
                if (a == null && b == null)
                {
                    return(0);
                }
                if (!(a == null))
                {
                    return(1);
                }
                return(-1);
            }
            else if (cmdletRoleEntry == null != (cmdletRoleEntry2 == null))
            {
                if (!(cmdletRoleEntry == null))
                {
                    return(1);
                }
                return(-1);
            }
            else
            {
                if (cmdletRoleEntry != null)
                {
                    return(string.Compare(cmdletRoleEntry.FullName, cmdletRoleEntry2.FullName, StringComparison.OrdinalIgnoreCase));
                }
                return(string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase));
            }
        }
Ejemplo n.º 3
0
        public static RoleEntry Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (input.Length < 3)
            {
                throw new FormatException(DataStrings.RoleEntryNameTooShort);
            }
            if (input[1] != ',')
            {
                throw new FormatException(DataStrings.RoleEntryStringMustBeCommaSeparated);
            }
            RoleEntry roleEntry = null;

            if (RoleEntry.roleEntryCache.TryGetValue(input, out roleEntry))
            {
                return(roleEntry);
            }
            char c = input[0];

            switch (c)
            {
            case 'a':
                roleEntry = new ApplicationPermissionRoleEntry(input);
                goto IL_A9;

            case 'b':
                break;

            case 'c':
                roleEntry = new CmdletRoleEntry(input);
                goto IL_A9;

            default:
                if (c == 's')
                {
                    roleEntry = new ScriptRoleEntry(input);
                    goto IL_A9;
                }
                if (c == 'w')
                {
                    roleEntry = new WebServiceRoleEntry(input);
                    goto IL_A9;
                }
                break;
            }
            roleEntry = new UnknownRoleEntry(input);
IL_A9:
            RoleEntry.roleEntryCache.Add(input, roleEntry);
            return(roleEntry);
        }
Ejemplo n.º 4
0
        internal RoleEntry IntersectParameters(RoleEntry entry)
        {
            List <string> list = null;
            bool          flag = false;
            int           i    = 0;

            for (int j = 0; j < this.Parameters.Count; j++)
            {
                string text = this.parameters[j];
                int    num  = 1;
                while (i < entry.Parameters.Count)
                {
                    num = string.Compare(text, entry.parameters[i], StringComparison.OrdinalIgnoreCase);
                    if (num >= 0)
                    {
                        i++;
                    }
                    if (num <= 0)
                    {
                        break;
                    }
                }
                if (num == 0)
                {
                    if (flag)
                    {
                        list.Add(text);
                    }
                }
                else if (!flag)
                {
                    flag = true;
                    list = new List <string>(this.Parameters.Count);
                    for (int k = 0; k < j; k++)
                    {
                        list.Add(this.parameters[k]);
                    }
                }
            }
            if (!flag)
            {
                return(this);
            }
            CmdletRoleEntry cmdletRoleEntry = this as CmdletRoleEntry;

            if (cmdletRoleEntry != null)
            {
                return(new CmdletRoleEntry(cmdletRoleEntry.Name, cmdletRoleEntry.PSSnapinName, list.ToArray()));
            }
            throw new NotSupportedException("Parameter intersection for RoleEntry other than CmdletRoleEntry is not supported.");
        }
Ejemplo n.º 5
0
        internal static RoleEntry MergeParameters(IList <RoleEntry> entries)
        {
            if (entries == null)
            {
                throw new ArgumentNullException("entries");
            }
            if (entries.Count == 0)
            {
                throw new ArgumentException("entries");
            }
            if (entries.Count == 1)
            {
                return(entries[0]);
            }
            int             num             = 0;
            int             count           = entries[0].Parameters.Count;
            int             index           = 0;
            string          b               = entries[0].Name;
            CmdletRoleEntry cmdletRoleEntry = entries[0] as CmdletRoleEntry;
            string          text            = (cmdletRoleEntry == null) ? null : cmdletRoleEntry.PSSnapinName;

            int[] array = new int[entries.Count];
            for (int i = 0; i < entries.Count; i++)
            {
                RoleEntry roleEntry = entries[i];
                if (i > 0 && object.ReferenceEquals(roleEntry, entries[i - 1]))
                {
                    array[i] = -1;
                }
                else
                {
                    if (!string.Equals(roleEntry.Name, b, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ArgumentException("entries");
                    }
                    if (text != null)
                    {
                        CmdletRoleEntry cmdletRoleEntry2 = roleEntry as CmdletRoleEntry;
                        if (roleEntry == null)
                        {
                            throw new ArgumentException("entries");
                        }
                        if (!string.Equals(cmdletRoleEntry2.PSSnapinName, text, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new ArgumentException("entries");
                        }
                    }
                    else if (roleEntry == null)
                    {
                        throw new ArgumentException("entries");
                    }
                    if (count < roleEntry.Parameters.Count)
                    {
                        count = roleEntry.Parameters.Count;
                        index = i;
                    }
                    num += roleEntry.Parameters.Count;
                    if (roleEntry.Parameters.Count == 0)
                    {
                        array[i] = -1;
                    }
                }
            }
            if (num == entries[0].Parameters.Count)
            {
                return(entries[0]);
            }
            List <string> list  = new List <string>(num);
            string        b2    = string.Empty;
            string        text2 = null;

            for (;;)
            {
                for (int j = 0; j < entries.Count; j++)
                {
                    if (array[j] != -1)
                    {
                        string text3 = entries[j].parameters[array[j]];
                        if (string.Equals(text3, b2, StringComparison.OrdinalIgnoreCase))
                        {
                            int num2 = ++array[j];
                            if (num2 >= entries[j].parameters.Length)
                            {
                                array[j] = -1;
                                goto IL_242;
                            }
                            text3 = entries[j].parameters[array[j]];
                        }
                        if (text2 == null || string.Compare(text3, text2, StringComparison.OrdinalIgnoreCase) < 0)
                        {
                            text2 = text3;
                        }
                    }
                    IL_242 :;
                }
                if (text2 == null)
                {
                    break;
                }
                list.Add(text2);
                b2    = text2;
                text2 = null;
            }
            if (list.Count == count)
            {
                return(entries[index]);
            }
            RoleEntry roleEntry2 = entries[0].Clone(list, false, null);
            string    token      = roleEntry2.ToADString();
            RoleEntry result     = null;

            if (RoleEntry.roleEntryCache.TryGetValue(token, out result))
            {
                return(result);
            }
            RoleEntry.roleEntryCache.Add(token, roleEntry2);
            return(roleEntry2);
        }