Inheritance: IConfigHandler
Exemplo n.º 1
0
        [System.Security.SecurityCritical]  // auto-generated
        private Hashtable GetSatelliteAssembliesFromConfig()
        {
#if FEATURE_FUSION

            String fileName = AppDomain.CurrentDomain.FusionStore.ConfigurationFileInternal;
            if (fileName == null) {
                return null;
            }

            // Don't do a security assert.  We need to support semi-trusted 
            // scenarios, but asserting here causes infinite resource lookups
            // while initializing security & looking up mscorlib's config file.
            // Use internal methods to bypass security checks.

            // If we're dealing with a local file name or a UNC path instead 
            // of a URL, check to see if the file exists here for perf (avoids
            // throwing a FileNotFoundException).
            if (fileName.Length >= 2 && 
                ((fileName[1] == Path.VolumeSeparatorChar) || (fileName[0] == Path.DirectorySeparatorChar && fileName[1] == Path.DirectorySeparatorChar)) &&
                !File.InternalExists(fileName))
                return null;

            ConfigTreeParser parser = new ConfigTreeParser();
            String queryPath = "/configuration/satelliteassemblies";
            ConfigNode node = null;
            // Catch exceptions in case a web app doesn't have a config file.
            try {
                node = parser.Parse(fileName, queryPath, true);
            }
            catch(Exception) {}

            if (node == null) {
                return null;
            }

            // The application config file will contain sections like this:
            // <?xml version="1.0"?>
            // <configuration>
            //     <satelliteassemblies>
            //         <assembly name="mscorlib, Version=..., PublicKeyToken=...">
            //             <culture>fr</culture>
            //         </assembly>
            //         <assembly name="UserAssembly, ...">
            //             <culture>fr-FR</culture>
            //             <culture>de-CH</culture>
            //         </assembly>
            //         <assembly name="UserAssembly2, ...">
            //         </assembly>
            //    </satelliteassemblies>
            // </configuration>
            Hashtable satelliteInfo = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach(ConfigNode assemblyNode in node.Children) {
                if (!String.Equals(assemblyNode.Name, "assembly"))
                    throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTag", Path.GetFileName(fileName), assemblyNode.Name));

                if (assemblyNode.Attributes.Count == 0)
                    throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagNoAttr", Path.GetFileName(fileName)));

                DictionaryEntry de = (DictionaryEntry) assemblyNode.Attributes[0];
                String assemblyName = (String) de.Value;
                if (!String.Equals(de.Key, "name") || String.IsNullOrEmpty(assemblyName) || assemblyNode.Attributes.Count > 1) 
                    throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagBadAttr", Path.GetFileName(fileName), de.Key, de.Value));

                ArrayList list = new ArrayList(5);
                foreach(ConfigNode child in assemblyNode.Children)
                    if (child.Value != null)
                        list.Add(child.Value);

                String[] satellites = new String[list.Count];
                for(int i=0; i<satellites.Length; i++) {
                    String cultureName = (String)list[i];
                    satellites[i] = cultureName;
#if !FEATURE_CORECLR
                    if (FrameworkEventSource.IsInitialized)
                    {
                        FrameworkEventSource.Log.ResourceManagerAddingCultureFromConfigFile(BaseNameField, MainAssembly, cultureName);
                    }
#endif
                }

                satelliteInfo.Add(assemblyName, satellites);
            }

            return satelliteInfo;
#else
            return null;
#endif //FEATURE_FUSION

        }
Exemplo n.º 2
0
        [System.Security.SecurityCritical]  // auto-generated
        private static ConfigNode OpenCryptoConfig()
        {
            string machineConfigFile = System.Security.Util.Config.MachineDirectory + MachineConfigFilename;
            new FileIOPermission(FileIOPermissionAccess.Read, machineConfigFile).Assert();
            if (!File.Exists(machineConfigFile))
                return null;
            CodeAccessPermission.RevertAssert();

            ConfigTreeParser parser = new ConfigTreeParser();
            ConfigNode rootNode = parser.Parse(machineConfigFile, "configuration", true);
            if (rootNode == null)
                return null;

            // now, find the mscorlib tag with our version
            ConfigNode mscorlibNode = null;
            foreach (ConfigNode node in rootNode.Children)
            {
                bool versionSpecificMscorlib = false;

                if (String.Compare(node.Name, "mscorlib", StringComparison.Ordinal) == 0)
                {
                    foreach (DictionaryEntry attribute in node.Attributes)
                    {
                        if (String.Compare((string)attribute.Key, "version", StringComparison.Ordinal) == 0)
                        {
                            versionSpecificMscorlib = true;

                            if (String.Compare((string)attribute.Value, Version, StringComparison.Ordinal) == 0)
                            {
                                mscorlibNode = node;
                                break;
                            }
                        }
                    }

                    // if this mscorlib element did not have a version attribute, then use it
                    if (!versionSpecificMscorlib)
                        mscorlibNode = node;
                }

                // use the first matching mscorlib we find
                if (mscorlibNode != null)
                    break;
            }

            if (mscorlibNode == null)
                return null;

            // now look for the first crypto settings element
            foreach (ConfigNode node in mscorlibNode.Children)
            {
                if (String.Compare(node.Name, "cryptographySettings", StringComparison.Ordinal) == 0)
                    return node;
            }

            return null;
        }
Exemplo n.º 3
0
        public static RemotingXmlConfigFileData ParseConfigFile(String filename)
        {
            ConfigTreeParser parser = new ConfigTreeParser();
            ConfigNode rootNode = parser.Parse(filename, "/configuration/system.runtime.remoting");

            return ParseConfigNode(rootNode);
        }
 private static ConfigNode OpenCryptoConfig()
 {
     string path = Config.MachineDirectory + "machine.config";
     new FileIOPermission(FileIOPermissionAccess.Read, path).Assert();
     if (File.Exists(path))
     {
         CodeAccessPermission.RevertAssert();
         ConfigNode node = new ConfigTreeParser().Parse(path, "configuration", true);
         if (node == null)
         {
             return null;
         }
         ConfigNode node2 = null;
         foreach (ConfigNode node3 in node.Children)
         {
             bool flag = false;
             if (string.Compare(node3.Name, "mscorlib", StringComparison.Ordinal) == 0)
             {
                 foreach (DictionaryEntry entry in node3.Attributes)
                 {
                     if (string.Compare((string) entry.Key, "version", StringComparison.Ordinal) == 0)
                     {
                         flag = true;
                         if (string.Compare((string) entry.Value, Version, StringComparison.Ordinal) == 0)
                         {
                             node2 = node3;
                             break;
                         }
                     }
                 }
                 if (!flag)
                 {
                     node2 = node3;
                 }
             }
             if (node2 != null)
             {
                 break;
             }
         }
         if (node2 != null)
         {
             foreach (ConfigNode node4 in node2.Children)
             {
                 if (string.Compare(node4.Name, "cryptographySettings", StringComparison.Ordinal) == 0)
                 {
                     return node4;
                 }
             }
         }
     }
     return null;
 }
 private Hashtable GetSatelliteAssembliesFromConfig()
 {
     string configurationFileInternal = AppDomain.CurrentDomain.FusionStore.ConfigurationFileInternal;
     if (configurationFileInternal == null)
     {
         return null;
     }
     if (((configurationFileInternal.Length >= 2) && ((configurationFileInternal[1] == Path.VolumeSeparatorChar) || ((configurationFileInternal[0] == Path.DirectorySeparatorChar) && (configurationFileInternal[1] == Path.DirectorySeparatorChar)))) && !File.InternalExists(configurationFileInternal))
     {
         return null;
     }
     ConfigTreeParser parser = new ConfigTreeParser();
     string configPath = "/configuration/satelliteassemblies";
     ConfigNode node = null;
     try
     {
         node = parser.Parse(configurationFileInternal, configPath, true);
     }
     catch (Exception)
     {
     }
     if (node == null)
     {
         return null;
     }
     Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);
     foreach (ConfigNode node2 in node.Children)
     {
         if (!string.Equals(node2.Name, "assembly"))
         {
             throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTag", new object[] { Path.GetFileName(configurationFileInternal), node2.Name }));
         }
         if (node2.Attributes.Count == 0)
         {
             throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagNoAttr", new object[] { Path.GetFileName(configurationFileInternal) }));
         }
         DictionaryEntry entry = node2.Attributes[0];
         string str3 = (string) entry.Value;
         if ((!object.Equals(entry.Key, "name") || string.IsNullOrEmpty(str3)) || (node2.Attributes.Count > 1))
         {
             throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagBadAttr", new object[] { Path.GetFileName(configurationFileInternal), entry.Key, entry.Value }));
         }
         ArrayList list = new ArrayList(5);
         foreach (ConfigNode node3 in node2.Children)
         {
             if (node3.Value != null)
             {
                 list.Add(node3.Value);
             }
         }
         string[] strArray = new string[list.Count];
         for (int i = 0; i < strArray.Length; i++)
         {
             string cultureName = (string) list[i];
             strArray[i] = cultureName;
             if (FrameworkEventSource.IsInitialized)
             {
                 FrameworkEventSource.Log.ResourceManagerAddingCultureFromConfigFile(this.BaseNameField, this.MainAssembly, cultureName);
             }
         }
         hashtable.Add(str3, strArray);
     }
     return hashtable;
 }
Exemplo n.º 6
0
        public static RemotingXmlConfigFileData ParseConfigFile(String filename)
        {
            RemotingXmlConfigFileData configData = new RemotingXmlConfigFileData();
        
            ConfigTreeParser parser = new ConfigTreeParser();
            ConfigNode rootNode = parser.Parse(filename, "/configuration/system.runtime.remoting");

            // check to see if this file has a system.runtime.remoting section
            if (rootNode == null)
                return null;

            // process attributes
            foreach (DictionaryEntry entry in rootNode.Attributes)
            {
                String key = entry.Key.ToString();
                switch (key)
                {
                case "version":
                {
                    // we ignore the version attribute because this may be used
                    //   by the configuration system
                    break;
                }                
                    
                default: ReportUnknownAttributeError(rootNode, key, configData); break;                
                } // switch
            } // foreach

            ConfigNode appNode = null;       // "application" node
            ConfigNode channelsNode = null;  // "channels" node
            ConfigNode providerNode = null;  // "channelSinkProviders" node
            ConfigNode debugNode = null;     // "debug" node
            
            foreach (ConfigNode node in rootNode.Children)
            {
                switch (node.Name)
                {
                
                case "application":
                {
                    // there can only be one application node in a config file
                    if (appNode != null)
                        ReportUniqueSectionError(rootNode, appNode, configData);

                    appNode = node;
                    break;
                } // case "application"
                
                case "channels":
                {
                    if (channelsNode != null)
                        ReportUniqueSectionError(rootNode, channelsNode, configData);
                
                    channelsNode = node;
                    break;
                } // case "channels"

                case "channelSinkProviders":
                {
                    if (providerNode != null)
                        ReportUniqueSectionError(rootNode, providerNode, configData);
                
                    providerNode = node;
                    break;
                } // case "channelSinkProviders"

                case "debug":
                {
                    if (debugNode != null)
                        ReportUniqueSectionError(rootNode, debugNode, configData);
                
                    debugNode = node;
                    break;
                } // case "debug"

                default: ReportUnknownChildError(rootNode, node, configData); break;
                } // switch
            } // foreach


            if (debugNode != null)
                ProcessDebugNode(debugNode, configData);

            if (providerNode != null)
                ProcessChannelSinkProviderTemplates(providerNode, configData);

            if (channelsNode != null)
                ProcessChannelTemplates(channelsNode, configData);

            if (appNode != null)
                ProcessApplicationNode(appNode, configData);

            return configData;
        } // ParseConfigFile