internal void LoadValuesFromConfigurationXml(XmlNode node)
        {
            // DO NOT SILENTLY IGNORE BOGUS XML IN THE SECTION!
            HandlerBase.CheckForChildNodes(node);

            foreach (XmlAttribute attribute in node.Attributes)
            {
                String name = attribute.Name;
                String text = attribute.Value;

                try {
                    if (name == "culture")
                    {
                        if (text.Length == 0)
                        {
                            throw new ArgumentException();  // don't allow empty culture string
                        }
                        _culture = HttpServerUtility.CreateReadOnlyCultureInfo(text);
                    }
                    else if (name == "uiCulture")
                    {
                        if (text.Length == 0)
                        {
                            throw new ArgumentException();  // don't allow empty culture string
                        }
                        _uiCulture = HttpServerUtility.CreateReadOnlyCultureInfo(text);
                    }
                    else if (name == "fileEncoding")
                    {
                        _fileEncoding = Encoding.GetEncoding(text);
                    }
                    else if (name == "requestEncoding")
                    {
                        _requestEncoding = Encoding.GetEncoding(text);
                    }
                    else if (name == "responseEncoding")
                    {
                        _responseEncoding = Encoding.GetEncoding(text);
                    }
                    else
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Unknown_globalization_attr, name),
                                  attribute);
                    }
                }
                catch (ConfigurationException) {
                    throw;
                }
                catch (Exception e) {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_value_for_globalization_attr, name),
                              e, attribute);
                }
            }
        }
        //
        // Handle <file src=""/> elements
        //
        static void ProcessFile(ArrayList fileList, XmlNode node)
        {
            string  filename = null;
            XmlNode attr     = HandlerBase.GetAndRemoveRequiredStringAttribute(node, "src", ref filename);

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForChildNodes(node);

            fileList.Add(new Pair(filename, attr));
        }
        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);
            }

            bool   impersonation = false;
            String username      = null;
            String password      = null;

            HandlerBase.CheckForChildNodes(section);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "impersonate", ref impersonation);
            HandlerBase.GetAndRemoveStringAttribute(section, "userName", ref username);
            HandlerBase.GetAndRemoveStringAttribute(section, "password", ref password);

            HandlerBase.CheckForUnrecognizedAttributes(section);
            HandlerBase.CheckForChildNodes(section);
            if (username != null && username.Length < 1)
            {
                username = null;
            }
            if (password != null && (password.StartsWith("registry:") || password.StartsWith("Registry:")))
            {
                StringBuilder str  = new StringBuilder(100);
                int           iRet = UnsafeNativeMethods.GetCredentialFromRegistry(password, str, 100);
                if (iRet == 0)
                {
                    password = str.ToString();
                }
                else
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_credentials_pass),
                              section);
                }
            }
            if (username != null && (username.StartsWith("registry:") || username.StartsWith("Registry:")))
            {
                StringBuilder str  = new StringBuilder(100);
                int           iRet = UnsafeNativeMethods.GetCredentialFromRegistry(username, str, 100);
                if (iRet == 0)
                {
                    username = str.ToString();
                }
                else
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_credentials_name),
                              section);
                }
            }
            return(new IdentityConfig((IdentityConfig)parent, impersonation, username, password, section));
        }
        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);
            }

            bool   bTemp                    = false;
            int    iTemp                    = 0;
            uint   uiTemp                   = 0;
            string sTemp                    = null;
            int    maxWorkerThreads         = 0;
            int    maxIoThreads             = 0;
            int    minWorkerThreads         = 0;
            int    minIoThreads             = 0;
            int    responseDeadlockInterval = 0;

            HandlerBase.GetAndRemoveBooleanAttribute(section, "enable", ref bTemp);
            GetAndRemoveProcessModelTimeout(section, "timeout", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "idleTimeout", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "shutdownTimeout", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "requestLimit", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "requestQueueLimit", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "restartQueueLimit", ref iTemp);
            HandlerBase.GetAndRemoveIntegerAttribute(section, "memoryLimit", ref iTemp);
            GetAndRemoveUnsignedIntegerAttribute(section, "cpuMask", ref uiTemp);
            HandlerBase.GetAndRemoveEnumAttribute(section, "logLevel", typeof(LogLevelEnum), ref iTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "userName", ref sTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "password", ref sTemp);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "webGarden", ref bTemp);
            GetAndRemoveProcessModelTimeout(section, "clientConnectedCheck", ref iTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "comImpersonationLevel", ref sTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "comAuthenticationLevel", ref sTemp);
            GetAndRemoveProcessModelTimeout(section, "responseDeadlockInterval", ref responseDeadlockInterval);
            GetAndRemoveProcessModelTimeout(section, "responseRestartDeadlockInterval", ref iTemp);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "maxWorkerThreads", ref maxWorkerThreads);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "maxIoThreads", ref maxIoThreads);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "minWorkerThreads", ref minWorkerThreads);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "minIoThreads", ref minIoThreads);
            HandlerBase.GetAndRemoveStringAttribute(section, "serverErrorMessageFile", ref sTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "requestAcks", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "pingFrequency", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "pingTimeout", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "asyncOption", ref iTemp);


            HandlerBase.CheckForUnrecognizedAttributes(section);
            HandlerBase.CheckForChildNodes(section);

            return(new ProcessModelConfig(maxWorkerThreads, maxIoThreads, minWorkerThreads, minIoThreads, responseDeadlockInterval));
        }
        internal void LoadValuesFromConfigurationXml(XmlNode section)
        {
            HandlerBase.GetAndRemoveBooleanAttribute(section, "enabled", ref _isEnabled);
            HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(section, "requestLimit", ref _requestLimit);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "pageOutput", ref _pageOutput);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "localOnly", ref _localOnly);

            string [] values = { "SortByTime", "SortByCategory" };
            // TraceMode is in another file in a different namespace ... so lets have some protection if they change
            Debug.Assert(TraceMode.SortByTime == (TraceMode)0);
            Debug.Assert(TraceMode.SortByCategory == (TraceMode)1);
            int     iMode     = 0;
            XmlNode attribute = HandlerBase.GetAndRemoveEnumAttribute(section, "traceMode", values, ref iMode);

            if (attribute != null)
            {
                _outputMode = (TraceMode)iMode;
            }

            HandlerBase.CheckForUnrecognizedAttributes(section);
            // section can have no content
            HandlerBase.CheckForChildNodes(section);
        }
        //
        // Handle the <result> tag
        //
        static void ProcessResult(HttpCapabilitiesEvaluator capabilitiesEvaluator, XmlNode node)
        {
            bool inherit = true;

            HandlerBase.GetAndRemoveBooleanAttribute(node, "inherit", ref inherit);
            if (inherit == false)
            {
                capabilitiesEvaluator.ClearParent();
            }

            Type    resultType = null;
            XmlNode attribute  = HandlerBase.GetAndRemoveTypeAttribute(node, "type", ref resultType);

            if (attribute != null)
            {
                if (resultType.Equals(capabilitiesEvaluator._resultType) == false)
                {
                    // be sure the new type is assignable to the parent type
                    HandlerBase.CheckAssignableType(attribute, capabilitiesEvaluator._resultType, resultType);
                    capabilitiesEvaluator._resultType = resultType;
                }
            }

            int cacheTime = 0;

            attribute = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "cacheTime", ref cacheTime);
            if (attribute != null)
            {
                capabilitiesEvaluator.SetCacheTime(cacheTime);
            }

            HandlerBase.GetAndRemoveBooleanAttribute(node, "cache", ref capabilitiesEvaluator._useCache);

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForChildNodes(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);
        }
Beispiel #8
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);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        internal AuthenticationConfig(AuthenticationConfig parent, XmlNode section)
        {
            if (parent != null)
            {
                _CookieName        = parent.CookieName;
                _LoginUrl          = parent.LoginUrl;
                _PasswordFormat    = parent.PasswordFormat;
                _Credentials       = (Hashtable)parent.Credentials.Clone();
                _Mode              = parent.Mode;
                _PassportUrl       = parent.PassportUrl;
                _Protection        = parent.Protection;
                _FormsCookiePath   = parent.FormsCookiePath;
                _Timeout           = parent.Timeout;
                _RequireSSL        = parent.RequireSSL;
                _SlidingExpiration = parent.SlidingExpiration;
            }
            else
            {
                _Credentials = new Hashtable();
            }

            ////////////////////////////////////////////////////////////
            // Step 1: Read the mode
            int     iMode     = 0;
            XmlNode attribute = HandlerBase.GetAndRemoveEnumAttribute(section, "mode", typeof(AuthenticationMode), ref iMode);

            if (attribute != null)
            {
                _Mode = (AuthenticationMode)iMode;
                if (_Mode == AuthenticationMode.Passport && UnsafeNativeMethods.PassportVersion() < 0)
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Passport_not_installed),
                              attribute);
                }
            }
            HandlerBase.CheckForUnrecognizedAttributes(section);

            ////////////////////////////////////////////////////////////
            // Step 2: Read children nodes
            foreach (XmlNode child in section.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (child.Name == "forms")
                {
                    ReadFormsSettings(child);
                }
                else if (child.Name == "passport")
                {
                    attribute = child.Attributes.RemoveNamedItem("redirectUrl");
                    if (attribute != null)
                    {
                        _PassportUrl = attribute.Value;
                        if (_PassportUrl.StartsWith("\\\\") || (_PassportUrl.Length > 1 && _PassportUrl[1] == ':'))
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.Auth_bad_url),
                                      attribute);
                        }
                    }

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);
                }
                else
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Auth_unrecognized_tag, child.Name),
                              child);
                }
            }
        }
        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);
        }
Beispiel #11
0
            // CTor
            internal MachineKeyConfig(object parentObject, object contextObject, XmlNode node)
            {
                MachineKeyConfig parent = (MachineKeyConfig)parentObject;

                HttpConfigurationContext configContext = contextObject as HttpConfigurationContext;

                if (HandlerBase.IsPathAtAppLevel(configContext.VirtualPath) == PathLevel.BelowApp)
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.No_MachineKey_Config_In_subdir),
                              node);
                }

                if (parent != null)
                {
                    _ValidationKey  = parent.ValidationKey;
                    _DecryptionKey  = parent.DecryptionKey;
                    _ValidationMode = parent.ValidationMode;
                    _AutogenKey     = parent.AutogenKey;
                }

                XmlNode vNode = node.Attributes.RemoveNamedItem("validationKey");
                XmlNode dNode = node.Attributes.RemoveNamedItem("decryptionKey");

                int iMode = 0;

                string [] modeStrings = { "SHA1", "MD5", "3DES" };
                XmlNode   mNode       = HandlerBase.GetAndRemoveEnumAttribute(node, "validation", modeStrings, ref iMode);

                if (mNode != null)
                {
                    _ValidationMode = (MachineKeyValidationMode)iMode;
                }
                HandlerBase.CheckForUnrecognizedAttributes(node);
                HandlerBase.CheckForChildNodes(node);

                if (vNode != null && vNode.Value != null)
                {
                    String strKey       = vNode.Value;
                    bool   fAppSpecific = strKey.EndsWith(",IsolateApps");

                    if (fAppSpecific)
                    {
                        strKey = strKey.Substring(0, strKey.Length - ",IsolateApps".Length);
                    }

                    if (strKey == "AutoGenerate")   // case sensitive
                    {
                        _ValidationKey = new byte[64];
                        Buffer.BlockCopy(HttpRuntime.s_autogenKeys, 0, _ValidationKey, 0, 64);
                    }
                    else
                    {
                        if (strKey.Length > 128 || strKey.Length < 40)
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(
                                          SR.Unable_to_get_cookie_authentication_validation_key, strKey.Length.ToString()),
                                      vNode);
                        }

                        _ValidationKey = HexStringToByteArray(strKey);
                        if (_ValidationKey == null)
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(
                                          SR.Invalid_validation_key),
                                      vNode);
                        }
                    }

                    if (fAppSpecific)
                    {
                        int dwCode = SymbolHashCodeProvider.Default.GetHashCode(HttpContext.Current.Request.ApplicationPath);
                        _ValidationKey[0] = (byte)(dwCode & 0xff);
                        _ValidationKey[1] = (byte)((dwCode & 0xff00) >> 8);
                        _ValidationKey[2] = (byte)((dwCode & 0xff0000) >> 16);
                        _ValidationKey[3] = (byte)((dwCode & 0xff000000) >> 24);
                    }
                }

                if (dNode != null)
                {
                    String strKey       = dNode.Value;
                    bool   fAppSpecific = strKey.EndsWith(",IsolateApps");

                    if (fAppSpecific)
                    {
                        strKey = strKey.Substring(0, strKey.Length - ",IsolateApps".Length);
                    }

                    if (strKey == "AutoGenerate")   // case sensitive
                    {
                        _DecryptionKey = new byte[24];
                        Buffer.BlockCopy(HttpRuntime.s_autogenKeys, 64, _DecryptionKey, 0, 24);
                        _AutogenKey = true;
                    }
                    else
                    {
                        _AutogenKey = false;

                        if (strKey.Length == 48)   // Make sure Triple DES is installed
                        {
                            TripleDESCryptoServiceProvider oTemp = null;
                            try {
                                oTemp = new TripleDESCryptoServiceProvider();
                            }
                            catch (Exception) {
                            }
                            if (oTemp == null)
                            {
                                throw new ConfigurationException(
                                          HttpRuntime.FormatResourceString(
                                              SR.cannot_use_Triple_DES),
                                          dNode);
                            }
                        }

                        if (strKey.Length != 48 && strKey.Length != 16)
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(
                                          SR.Unable_to_get_cookie_authentication_decryption_key, strKey.Length.ToString()),
                                      dNode);
                        }

                        _DecryptionKey = HexStringToByteArray(strKey);
                        if (_DecryptionKey == null)
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(
                                          SR.Invalid_decryption_key),
                                      dNode);
                        }
                    }
                    if (fAppSpecific)
                    {
                        int dwCode = SymbolHashCodeProvider.Default.GetHashCode(HttpContext.Current.Request.ApplicationPath);
                        _DecryptionKey[0] = (byte)(dwCode & 0xff);
                        _DecryptionKey[1] = (byte)((dwCode & 0xff00) >> 8);
                        _DecryptionKey[2] = (byte)((dwCode & 0xff0000) >> 16);
                        _DecryptionKey[3] = (byte)((dwCode & 0xff000000) >> 24);
                    }
                }
            }
        //
        // Create a rule from an element
        //
        static CapabilitiesRule RuleFromElement(ParseState parseState, XmlNode element)
        {
            int                 ruletype;
            DelayedRegex        regex;
            CapabilitiesPattern pat;

            // grab tag name

            if (element.Name == "filter")
            {
                ruletype = CapabilitiesRule.Filter;
            }
            else if (element.Name == "case")
            {
                ruletype = CapabilitiesRule.Case;
            }
            else if (element.Name == "use")
            {
                HandlerBase.CheckForChildNodes(element);

                string var   = HandlerBase.RemoveRequiredAttribute(element, "var");
                string strAs = HandlerBase.RemoveAttribute(element, "as");
                HandlerBase.CheckForUnrecognizedAttributes(element);

                if (strAs == null)
                {
                    strAs = "";
                }

                parseState.Evaluator.AddDependency(var);

                return(new CapabilitiesUse(var, strAs));
            }
            else
            {
                throw new ConfigurationException(
                          HttpRuntime.FormatResourceString(SR.Unknown_tag_in_caps_config, element.Name),
                          element);
            }

            // grab attributes
            String matchpat = HandlerBase.RemoveAttribute(element, "match");
            String testpat  = HandlerBase.RemoveAttribute(element, "with");

            HandlerBase.CheckForUnrecognizedAttributes(element);

            if (matchpat == null)
            {
                if (testpat != null)
                {
                    throw new ConfigurationException(HttpRuntime.FormatResourceString(SR.Cannot_specify_test_without_match), element);
                }
                regex = null;
                pat   = null;
            }
            else
            {
                try {
                    regex = new DelayedRegex(matchpat);
                }
                catch (Exception e) {
                    throw new ConfigurationException(e.Message, e, element);
                }

                if (testpat == null)
                {
                    pat = CapabilitiesPattern.Default;
                }
                else
                {
                    pat = new CapabilitiesPattern(testpat);
                }
            }

            // grab contents
            ArrayList subrules = RuleListFromElement(parseState, element, false);

            return(new CapabilitiesSection(ruletype, regex, pat, subrules));
        }
Beispiel #13
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);
        }
        internal void LoadValuesFromConfigurationInput(XmlNode node)
        {
            XmlNode n;

            // executionTimeout
            HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "executionTimeout", ref _executionTimeout);

            // maxRequestLength
            int limit = 0;

            if (HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "maxRequestLength", ref limit) != null)
            {
                _maxRequestLength = limit * 1024;
            }

            // useFullyQualifiedRedirectUrl
            HandlerBase.GetAndRemoveBooleanAttribute(node, "useFullyQualifiedRedirectUrl", ref _useFullyQualifiedRedirectUrl);

            // minFreeThreads
            n = HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "minFreeThreads", ref _minFreeThreads);

            int workerMax, ioMax;

            System.Threading.ThreadPool.GetMaxThreads(out workerMax, out ioMax);
            int maxThreads = (workerMax < ioMax) ? workerMax : ioMax;

            if (_minFreeThreads >= maxThreads)
            {
                throw new ConfigurationException(HttpRuntime.FormatResourceString(SR.Min_free_threads_must_be_under_thread_pool_limits, maxThreads.ToString()), (n != null) ? n : node);
            }

            // minLocalRequestFreeThreads
            n = HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "minLocalRequestFreeThreads", ref _minLocalRequestFreeThreads);
            if (_minLocalRequestFreeThreads > _minFreeThreads)
            {
                throw new ConfigurationException(HttpRuntime.FormatResourceString(SR.Local_free_threads_cannot_exceed_free_threads), (n != null) ? n : node);
            }

            // appRequestQueueLimit
            HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "appRequestQueueLimit", ref _appRequestQueueLimit);

            // shutdownTimeout
            HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "shutdownTimeout", ref _shutdownTimeout);

            // delayNotificationTimeout
            HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "delayNotificationTimeout", ref _delayNotificationTimeout);

            // waitChangeNotification
            HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "waitChangeNotification", ref _waitChangeNotification);

            // maxWaitChangeNotification
            HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node, "maxWaitChangeNotification", ref _maxWaitChangeNotification);

            // enableKernelOutputCache
            HandlerBase.GetAndRemoveBooleanAttribute(node, "enableKernelOutputCache", ref _enableKernelOutputCache);

            // enableVersionHeader
            HandlerBase.GetAndRemoveBooleanAttribute(node, "enableVersionHeader", ref _enableVersionHeader);

#if USE_REGEX_CSS_VALIDATION // ASURT 122278
            // If we find a requestValidationRegex string, create a new regex
            string  requestValidationRegexString = null;
            XmlNode attrib = HandlerBase.GetAndRemoveStringAttribute(node, "requestValidationRegex", ref requestValidationRegexString);
            if (attrib != null)
            {
                // REVIEW: consider using a compiled regex, though that is slow on first hit (and a memory hog).
                // Obviously, we can't precompile it since it's not know ahead of time.
                try {
                    _requestValidationRegex = new Regex(requestValidationRegexString, RegexOptions.IgnoreCase /*| RegexOptions.Compiled*/);
                }
                catch (Exception e) {
                    throw new ConfigurationException(e.Message, e, attrib);
                }
            }
#endif

            // error on unrecognized attributes and nodes
            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForChildNodes(node);
        }