コード例 #1
0
        // Token: 0x060013A3 RID: 5027 RVA: 0x00078BD8 File Offset: 0x00076DD8
        internal static SerializedClientSecurityContext Deserialize(XmlTextReader reader)
        {
            SerializedClientSecurityContext serializedClientSecurityContext = new SerializedClientSecurityContext();

            serializedClientSecurityContext.UserSid             = null;
            serializedClientSecurityContext.GroupSids           = null;
            serializedClientSecurityContext.RestrictedGroupSids = null;
            try
            {
                List <SidStringAndAttributes> list  = new List <SidStringAndAttributes>();
                List <SidStringAndAttributes> list2 = new List <SidStringAndAttributes>();
                if (!reader.Read() || XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.rootElementName) != 0)
                {
                    SerializedClientSecurityContext.ThrowParserException(reader, "Missing or invalid root node");
                }
                if (reader.MoveToFirstAttribute())
                {
                    do
                    {
                        if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.authenticationTypeAttributeName) == 0)
                        {
                            if (serializedClientSecurityContext.authenticationType != null)
                            {
                                SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Duplicated attribute {0}", SerializedClientSecurityContext.authenticationTypeAttributeName));
                            }
                            serializedClientSecurityContext.authenticationType = reader.Value;
                        }
                        else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.logonNameAttributeName) == 0)
                        {
                            if (serializedClientSecurityContext.logonName != null)
                            {
                                SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Duplicated attribute {0}", SerializedClientSecurityContext.logonNameAttributeName));
                            }
                            serializedClientSecurityContext.logonName = reader.Value;
                        }
                        else
                        {
                            SerializedClientSecurityContext.ThrowParserException(reader, "Found invalid attribute in root element");
                        }
                    }while (reader.MoveToNextAttribute());
                }
                if (serializedClientSecurityContext.authenticationType == null || serializedClientSecurityContext.logonName == null)
                {
                    SerializedClientSecurityContext.ThrowParserException(reader, "Auth type or logon name attributes are missing");
                }
                bool flag = false;
                int  num  = 0;
                while (reader.Read())
                {
                    if (XmlNodeType.EndElement == reader.NodeType && StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.rootElementName) == 0)
                    {
                        flag = true;
                        break;
                    }
                    if (XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.sidElementName) != 0)
                    {
                        SerializedClientSecurityContext.ThrowParserException(reader, "Expecting SID node");
                    }
                    SerializedClientSecurityContext.SidType sidType = SerializedClientSecurityContext.SidType.User;
                    uint num2 = 0U;
                    if (reader.MoveToFirstAttribute())
                    {
                        do
                        {
                            if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.sidTypeAttributeName) == 0)
                            {
                                int num3 = int.Parse(reader.Value);
                                if (num3 == 1)
                                {
                                    sidType = SerializedClientSecurityContext.SidType.Group;
                                }
                                else if (num3 == 2)
                                {
                                    sidType = SerializedClientSecurityContext.SidType.RestrictedGroup;
                                }
                                else
                                {
                                    SerializedClientSecurityContext.ThrowParserException(reader, "Invalid SID type");
                                }
                            }
                            else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.sidAttributesAttributeName) == 0)
                            {
                                num2 = uint.Parse(reader.Value);
                            }
                            else
                            {
                                SerializedClientSecurityContext.ThrowParserException(reader, "Found invalid attribute in SID element");
                            }
                        }while (reader.MoveToNextAttribute());
                    }
                    if (sidType == SerializedClientSecurityContext.SidType.User)
                    {
                        if (num2 != 0U)
                        {
                            SerializedClientSecurityContext.ThrowParserException(reader, "'Attributes' shouldn't be set in an user SID");
                        }
                        else if (serializedClientSecurityContext.UserSid != null)
                        {
                            SerializedClientSecurityContext.ThrowParserException(reader, "There can only be one user SID in the XML document");
                        }
                    }
                    if (!reader.Read() || XmlNodeType.Text != reader.NodeType || string.IsNullOrEmpty(reader.Value))
                    {
                        SerializedClientSecurityContext.ThrowParserException(reader, "Expecting SID value in SDDL format");
                    }
                    string value = reader.Value;
                    if (sidType == SerializedClientSecurityContext.SidType.User)
                    {
                        serializedClientSecurityContext.UserSid = value;
                    }
                    else if (sidType == SerializedClientSecurityContext.SidType.Group)
                    {
                        SidStringAndAttributes item = new SidStringAndAttributes(value, num2);
                        list.Add(item);
                    }
                    else if (sidType == SerializedClientSecurityContext.SidType.RestrictedGroup)
                    {
                        SidStringAndAttributes item2 = new SidStringAndAttributes(value, num2);
                        list2.Add(item2);
                    }
                    if (!reader.Read() || XmlNodeType.EndElement != reader.NodeType)
                    {
                        SerializedClientSecurityContext.ThrowParserException(reader, "Expected end of SID node");
                    }
                    num++;
                    if (num > SerializedClientSecurityContext.MaximumSidsPerContext)
                    {
                        throw new OwaSecurityContextSidLimitException(string.Format("Too many SID nodes in the request, maximum is {0}", SerializedClientSecurityContext.MaximumSidsPerContext), serializedClientSecurityContext.logonName, serializedClientSecurityContext.authenticationType);
                    }
                }
                if (serializedClientSecurityContext.UserSid == null)
                {
                    SerializedClientSecurityContext.ThrowParserException(reader, "Serialized context should at least contain an user SID");
                }
                if (!flag)
                {
                    SerializedClientSecurityContext.ThrowParserException(reader, "Parsing error");
                }
                if (list.Count > 0)
                {
                    serializedClientSecurityContext.GroupSids = list.ToArray();
                }
                if (list2.Count > 0)
                {
                    serializedClientSecurityContext.RestrictedGroupSids = list2.ToArray();
                }
            }
            catch (XmlException ex)
            {
                SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Parser threw an XML exception: {0}", ex.Message));
            }
            return(serializedClientSecurityContext);
        }