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);
        }
        /*
         * 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);
        }
Example #3
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);
        }