Ejemplo n.º 1
0
        //
        // Create a rulelist from an element's children
        //
        static ArrayList RuleListFromElement(ParseState parseState, XmlNode node, bool top)
        {
            ArrayList result = new ArrayList();

            foreach (XmlNode child in node.ChildNodes)
            {
                switch (child.NodeType)
                {
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    top = false;
                    AppendLines(result, child.Value, node);
                    break;

                case XmlNodeType.Element:
                    switch (child.Name)
                    {
                    case "result":
                        if (top)
                        {
                            ProcessResult(parseState.Evaluator, child);
                        }
                        else
                        {
                            throw new ConfigurationErrorsException(
                                      SR.GetString(SR.Result_must_be_at_the_top_browser_section),
                                      child);
                        }
                        break;

                    case "file":
                        if (parseState.IsExternalFile)
                        {
                            throw new ConfigurationErrorsException(
                                      SR.GetString(SR.File_element_only_valid_in_config),
                                      child);
                        }
                        ProcessFile(parseState.FileList, child);
                        break;

                    default:
                        result.Add(RuleFromElement(parseState, child));
                        break;
                    }
                    top = false;
                    break;

                case XmlNodeType.Comment:
                case XmlNodeType.Whitespace:
                    break;

                default:
                    HandlerBase.ThrowUnrecognizedElement(child);
                    break;
                }
            }

            return(result);
        }
        internal ProtocolsConfiguration(XmlNode section)
        {
            // process XML section in order and apply the directives

            HandlerBase.CheckForUnrecognizedAttributes(section);

            foreach (XmlNode child in section.ChildNodes)
            {
                // skip whitespace and comments
                if (IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                // process <add> elements

                if (child.Name == "add")
                {
                    String id     = HandlerBase.RemoveRequiredAttribute(child, "id");
                    String phType = HandlerBase.RemoveRequiredAttribute(child, "processHandlerType");
                    String ahType = HandlerBase.RemoveRequiredAttribute(child, "appDomainHandlerType");

                    bool validate = true;
                    HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForNonCommentChildNodes(child);

                    // check duplicate Id

                    /* TEMPORARY allow duplicates for easy Indigo machine.config update
                     * if (_protocolEntries[id] != null) {
                     *  throw new ConfigurationErrorsException(
                     *                  SR.GetString(SR.Dup_protocol_id, id),
                     *                  child);
                     * }
                     */

                    // add entry

                    /* TEMPORARY hide errors and ignore bad <add> tags
                     * to let breaking changes through */
                    try {
                        _protocolEntries[id] = new ProtocolsConfigurationEntry(
                            id, phType, ahType, validate,
                            ConfigurationErrorsException.GetFilename(child),
                            ConfigurationErrorsException.GetLineNumber(child));
                    }
                    catch {
                    }
                }
                else
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }
            }
        }
        /*
         * Create
         *
         * Given a partially composed config object (possibly null)
         * and some input from the config system, return a
         * further partially composed config object
         */
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            HttpModulesConfiguration appConfig;

            // start list as shallow clone of parent

            if (parent == null)
            {
                appConfig = new HttpModulesConfiguration();
            }
            else
            {
                appConfig = new HttpModulesConfiguration((HttpModulesConfiguration)parent);
            }

            // process XML section in order and apply the directives

            HandlerBase.CheckForUnrecognizedAttributes(section);
            foreach (XmlNode child in section.ChildNodes)
            {
                // skip whitespace and comments
                if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                // process <add> and <clear> elements

                if (child.Name == "add")
                {
                    String name      = HandlerBase.RemoveRequiredAttribute(child, "name");
                    String classname = HandlerBase.RemoveRequiredAttribute(child, "type");
                    bool   insert    = false;

                    /* position and validate removed  See ASURT 96814
                     * int iTemp = 0;
                     * XmlNode attribute = HandlerBase.GetAndRemoveEnumAttribute(child, "position", typeof(HttpModulesConfigurationPosition), ref iTemp);
                     * if (attribute != null) {
                     *  HttpModulesConfigurationPosition pos = (HttpModulesConfigurationPosition)iTemp;
                     *  if (pos == HttpModulesConfigurationPosition.Start) {
                     *      insert = true;
                     *  }
                     * }
                     *
                     * bool validate = true;
                     * HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);
                     */

                    if (IsSpecialModule(classname))
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Special_module_cannot_be_added_manually, classname),
                                  child);
                    }

                    if (IsSpecialModuleName(name))
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Special_module_cannot_be_added_manually, name),
                                  child);
                    }

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (appConfig.ContainsEntry(name))
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Module_already_in_app, name),
                                  child);
                    }
                    else
                    {
                        try {
                            appConfig.Add(name, classname, insert);
                        }
                        catch (Exception e) {
                            throw new ConfigurationException(e.Message, e, child);
                        }
                    }
                }
                else if (child.Name == "remove")
                {
                    String name = HandlerBase.RemoveRequiredAttribute(child, "name");

                    /*
                     * bool validate = true;
                     * HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);
                     */

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (!appConfig.RemoveEntry(name))
                    {
                        if (IsSpecialModuleName(name))
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.Special_module_cannot_be_removed_manually, name),
                                      child);
                        }
                        else
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.Module_not_in_app, name),
                                      child);
                        }
                    }
                }
                else if (child.Name == "clear")
                {
                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);
                    appConfig.RemoveRange(0, appConfig.Count);
                }
                else
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }
            }

            // inheritance rule for modules config:
            // machine-level and site-level config allows inheritance, dir- (app-) level does not.

            return(appConfig);
        }
Ejemplo n.º 4
0
        private void ReadFormsSettings(XmlNode node)
        {
            XmlNode tempAttr = HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "name", ref _CookieName);

            //Trace("FormsAuthConfigSettings::ReadSettings cookie name " + _CookieName);

            tempAttr = HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "loginUrl", ref _LoginUrl);
            if (tempAttr != null)
            {
                if (_LoginUrl.StartsWith("\\\\") || (_LoginUrl.Length > 1 && _LoginUrl[1] == ':'))
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Auth_bad_url),
                              tempAttr);
                }
            }
            //Trace("FormsAuthConfigSettings::ReadSettings login url " + _LoginUrl);

            int iTemp = 0;

            tempAttr = HandlerBase.GetAndRemoveEnumAttribute(node, "protection", typeof(FormsProtectionEnum), ref iTemp);
            if (tempAttr != null)
            {
                _Protection = (FormsProtectionEnum)iTemp;
            }

            tempAttr = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "timeout", ref _Timeout);
            tempAttr = HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "path", ref _FormsCookiePath);
            HandlerBase.GetAndRemoveBooleanAttribute(node, "requireSSL", ref _RequireSSL);
            HandlerBase.GetAndRemoveBooleanAttribute(node, "slidingExpiration", ref _SlidingExpiration);
            HandlerBase.CheckForUnrecognizedAttributes(node);

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (child.Name != "credentials")
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }

                tempAttr = HandlerBase.GetAndRemoveEnumAttribute(child, "passwordFormat", typeof(FormsAuthPasswordFormat), ref iTemp);
                if (tempAttr != null)
                {
                    _PasswordFormat = (FormsAuthPasswordFormat)iTemp;
                    //Trace("FormsAuthConfigSettings::ReadSettings password format " + strTemp);
                }

                HandlerBase.CheckForUnrecognizedAttributes(child);

                foreach (XmlNode child2 in child.ChildNodes)
                {
                    if (child2.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (child2.Name != "user")
                    {
                        HandlerBase.ThrowUnrecognizedElement(child2);
                    }

                    string strUser = null;
                    string strPass = null;
                    tempAttr = HandlerBase.GetAndRemoveRequiredStringAttribute(child2, "name", ref strUser);
                    HandlerBase.GetAndRemoveRequiredStringAttribute(child2, "password", ref strPass);
                    HandlerBase.CheckForUnrecognizedAttributes(child2);
                    HandlerBase.CheckForChildNodes(child2);

                    //Trace("FormsAuthConfigSettings::ReadSettings adding user " + strUser + " " + strPass);
                    strUser = strUser.ToLower(CultureInfo.InvariantCulture);
                    String strPassInTable = (String)_Credentials[strUser];
                    if (strPassInTable == null)
                    {
                        _Credentials.Add(strUser, strPass);
                    }
                    else
                    {
                        if (String.Compare(strPassInTable, strPass, false, CultureInfo.InvariantCulture) != 0)
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.User_Already_Specified, strUser), tempAttr);
                        }
                    }
                }
            }
        }
        internal SecurityPolicyConfig(SecurityPolicyConfig parent, XmlNode node, String strFile)
        {
            if (parent != null)
            {
                _PolicyFiles = (Hashtable)parent.PolicyFiles.Clone();
            }
            else
            {
                _PolicyFiles = new Hashtable();
            }


            // CONSIDER: Path.GetDirectoryName()
            String strDir = strFile.Substring(0, strFile.LastIndexOf('\\') + 1);

            foreach (XmlNode child in node.ChildNodes)
            {
                ////////////////////////////////////////////////////////////
                // Step 1: For each child
                if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                if (child.Name != "trustLevel")
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }

                string  name          = null;
                string  file          = null;
                XmlNode nameAttribute = HandlerBase.GetAndRemoveRequiredStringAttribute(child, "name", ref name);
                HandlerBase.GetAndRemoveRequiredStringAttribute(child, "policyFile", ref file);
                HandlerBase.CheckForUnrecognizedAttributes(child);
                HandlerBase.CheckForChildNodes(child);

                bool fAppend = true; // Append dir to filename
                if (file.Length > 1)
                {
                    char c1 = file[1];
                    char c0 = file[0];

                    if (c1 == ':') // Absolute file path
                    {
                        fAppend = false;
                    }
                    else
                    if (c0 == '\\' && c1 == '\\')     // UNC file path
                    {
                        fAppend = false;
                    }
                }

                String strTemp;
                if (fAppend)
                {
                    strTemp = strDir + file;
                }
                else
                {
                    strTemp = file;
                }

                if (_PolicyFiles.Contains(name))
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Security_policy_level_already_defined, name),
                              nameAttribute);
                }
                _PolicyFiles.Add(name, strTemp);
            }

            HandlerBase.CheckForUnrecognizedAttributes(node);
        }
Ejemplo n.º 6
0
        /*
         * Create
         *
         * Given a partially composed config object (possibly null)
         * and some input from the config system, return a
         * further partially composed config object
         */
        internal Object InternalCreate(Object parent, XmlNode node)
        {
            HandlerMap map;

            // start list as shallow clone of parent

            if (parent == null)
            {
                map = new HandlerMap();
            }
            else
            {
                map = new HandlerMap((HandlerMap)parent);
            }

            map.BeginGroup();

            // process XML section
            HandlerBase.CheckForUnrecognizedAttributes(node);

            foreach (XmlNode child in node.ChildNodes)
            {
                // skip whitespace and comments

                if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                // process <add> and <clear> elements

                if (child.Name.Equals("add"))
                {
                    String verb      = HandlerBase.RemoveRequiredAttribute(child, "verb");
                    String path      = HandlerBase.RemoveRequiredAttribute(child, "path");
                    String classname = HandlerBase.RemoveRequiredAttribute(child, "type");

                    int     phase     = 1;
                    XmlNode phaseNode = HandlerBase.GetAndRemoveIntegerAttribute(child, "phase", ref phase);
                    if (phaseNode != null)
                    {
                        ValidatePhase(phase, phaseNode);
                    }

                    bool validate = true;
                    HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);


                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    try {
                        map.Add(new HandlerMapping(verb, path, classname, !validate), phase);
                    }
                    catch (Exception e) {
                        throw new ConfigurationException(e.Message, e, child);
                    }
                }
                else if (child.Name.Equals("remove"))
                {
                    String verb     = HandlerBase.RemoveRequiredAttribute(child, "verb");
                    String path     = HandlerBase.RemoveRequiredAttribute(child, "path");
                    bool   validate = true;
                    HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);


                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (!map.RemoveMapping(verb, path) && validate)
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.No_mapping_to_remove, verb, path),
                                  child);
                    }
                }
                else if (child.Name.Equals("clear"))
                {
                    int     phase     = 1;
                    XmlNode phaseNode = HandlerBase.GetAndRemoveIntegerAttribute(child, "phase", ref phase);
                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (phaseNode == null)
                    {
                        map.ClearAll();
                    }
                    else
                    {
                        ValidatePhase(phase, phaseNode);
                        map.ClearPhase(phase);
                    }
                }
                else
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }
            }

            map.EndGroup();

            return(map);
        }