private void AddLocationInputImpl(SectionInput sectionInput, bool isIndirectLocation) { List <SectionInput> list = isIndirectLocation ? this._indirectLocationInputs : this._locationInputs; int num = isIndirectLocation ? 0x20 : 0x10; if (list == null) { list = new List <SectionInput>(1); if (isIndirectLocation) { this._indirectLocationInputs = list; } else { this._locationInputs = list; } } list.Insert(0, sectionInput); if (!sectionInput.HasErrors && !this._flags[num]) { OverrideMode overrideMode = sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode; if (overrideMode != OverrideMode.Inherit) { this.ChangeLockSettings(overrideMode, overrideMode); this._flags[num] = true; } } }
private void AddLocationInputImpl(SectionInput sectionInput, bool isIndirectLocation) { List<SectionInput> list = isIndirectLocation ? this._indirectLocationInputs : this._locationInputs; int num = isIndirectLocation ? 0x20 : 0x10; if (list == null) { list = new List<SectionInput>(1); if (isIndirectLocation) { this._indirectLocationInputs = list; } else { this._locationInputs = list; } } list.Insert(0, sectionInput); if (!sectionInput.HasErrors && !this._flags[num]) { OverrideMode overrideMode = sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode; if (overrideMode != OverrideMode.Inherit) { this.ChangeLockSettings(overrideMode, overrideMode); this._flags[num] = true; } } }
internal void RemoveFileInput() { if (this._fileInput != null) { this._fileInput = null; this._flags[2] = this.Locked; } }
internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord) { _flags[FlagAttached] = true; // factory info ConfigKey = factoryRecord.ConfigKey; Name = factoryRecord.Name; _typeName = factoryRecord.FactoryTypeName; _allowDefinition = factoryRecord.AllowDefinition; _allowExeDefinition = factoryRecord.AllowExeDefinition; _flags[FlagAllowLocation] = factoryRecord.AllowLocation; _flags[FlagRestartOnExternalChanges] = factoryRecord.RestartOnExternalChanges; _flags[FlagRequirePermission] = factoryRecord.RequirePermission; _overrideModeDefault = factoryRecord.OverrideModeDefault; if (factoryRecord.IsUndeclared) { _flags[FlagIsUndeclared] = true; _flags[FlagDeclared] = false; _flags[FlagDeclarationRequired] = false; } else { _flags[FlagIsUndeclared] = false; _flags[FlagDeclared] = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null; _flags[FlagDeclarationRequired] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false); } // section info _flags[FlagLocationLocked] = sectionRecord.Locked; _flags[FlagChildrenLocked] = sectionRecord.LockChildren; _flags[FlagChildrenLockWithoutFileInput] = sectionRecord.LockChildrenWithoutFileInput; if (sectionRecord.HasFileInput) { SectionInput fileInput = sectionRecord.FileInput; _flags[FlagProtectionProviderDetermined] = fileInput.IsProtectionProviderDetermined; _protectionProvider = fileInput.ProtectionProvider; SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo; _configSource = sectionXmlInfo.ConfigSource; ConfigSourceStreamName = sectionXmlInfo.ConfigSourceStreamName; _overrideMode = sectionXmlInfo.OverrideModeSetting; _flags[FlagInheritInChildApps] = !sectionXmlInfo.SkipInChildApps; ProtectionProviderName = sectionXmlInfo.ProtectionProviderName; } else { _flags[FlagProtectionProviderDetermined] = false; _protectionProvider = null; } // element context information _configurationSection.AssociateContext(configRecord); }
internal void AddFileInput(SectionInput sectionInput) { this._fileInput = sectionInput; if (!sectionInput.HasErrors && (sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode != OverrideMode.Inherit)) { this._flags[0x40] = this.LockChildren; this.ChangeLockSettings(OverrideMode.Inherit, sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode); } }
// AddFileInput internal void AddFileInput(SectionInput sectionInput) { _fileInput = sectionInput; // If LockChildren is set, lock our children if (!sectionInput.HasErrors && sectionInput.SectionXmlInfo.LockChildren) { LockChildren = true; } }
internal void RemoveFileInput() { if (_fileInput != null) { _fileInput = null; // Reset LockChildren flag to the value provided by // location input or inherited sections. _flags[Flag_LockChildren] = Locked; } }
AddLocationInputImpl(SectionInput sectionInput, bool isIndirectLocation) { List <SectionInput> inputs = isIndirectLocation ? _indirectLocationInputs : _locationInputs; int flag = isIndirectLocation ? Flag_IndirectLocationInputLockApplied : Flag_LocationInputLockApplied; if (inputs == null) { inputs = new List <SectionInput>(1); if (isIndirectLocation) { _indirectLocationInputs = inputs; } else { _locationInputs = inputs; } } // The list of locationSections is traversed from child to parent, // so insert at the beginning of the list. inputs.Insert(0, sectionInput); // Only the overrideMode from the parent thats closest to the SectionRecord has effect // // For location input: // Remember that this method will be called for location inputs comming from the immediate parent first // and then walking the hierarchy up to the root level // // For indirect location input: // This method will be first called for indirect input closest to the location config if (!sectionInput.HasErrors) { if (!_flags[flag]) { OverrideMode modeLocation = sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode; if (modeLocation != OverrideMode.Inherit) { ChangeLockSettings(modeLocation, modeLocation); _flags[flag] = true; } } } }
internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord) { this._flags[1] = true; this._configKey = factoryRecord.ConfigKey; this._group = factoryRecord.Group; this._name = factoryRecord.Name; this._typeName = factoryRecord.FactoryTypeName; this._allowDefinition = factoryRecord.AllowDefinition; this._allowExeDefinition = factoryRecord.AllowExeDefinition; this._flags[8] = factoryRecord.AllowLocation; this._flags[0x10] = factoryRecord.RestartOnExternalChanges; this._flags[0x20] = factoryRecord.RequirePermission; this._overrideModeDefault = factoryRecord.OverrideModeDefault; if (factoryRecord.IsUndeclared) { this._flags[0x2000] = true; this._flags[2] = false; this._flags[4] = false; } else { this._flags[0x2000] = false; this._flags[2] = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null; this._flags[4] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false); } this._flags[0x40] = sectionRecord.Locked; this._flags[0x80] = sectionRecord.LockChildren; this._flags[0x4000] = sectionRecord.LockChildrenWithoutFileInput; if (sectionRecord.HasFileInput) { SectionInput fileInput = sectionRecord.FileInput; this._flags[0x800] = fileInput.IsProtectionProviderDetermined; this._protectionProvider = fileInput.ProtectionProvider; SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo; this._configSource = sectionXmlInfo.ConfigSource; this._configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName; this._overrideMode = sectionXmlInfo.OverrideModeSetting; this._flags[0x100] = !sectionXmlInfo.SkipInChildApps; this._protectionProviderName = sectionXmlInfo.ProtectionProviderName; } else { this._flags[0x800] = false; this._protectionProvider = null; } this._configurationSection.AssociateContext(configRecord); }
AddLocationInput(SectionInput sectionInput) { if (_locationInputs == null) { _locationInputs = new List <SectionInput>(1); } // The list of locationSections is traversed from child to parent, // so insert at the beginning of the list. _locationInputs.Insert(0, sectionInput); // If LockChildren is set, lock both ourselves and children if (!sectionInput.HasErrors && sectionInput.SectionXmlInfo.LockChildren) { Locked = true; LockChildren = true; } }
// AddFileInput internal void AddFileInput(SectionInput sectionInput) { Debug.Assert(sectionInput != null); FileInput = sectionInput; // If the file input has an explicit value for its children locking - use it // Note we dont change the current lock setting if (!sectionInput.HasErrors && (sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode != OverrideMode.Inherit)) { // Store the current setting before applying the lock from the file input // So that if the user changes the current OverrideMode on this configKey to "Inherit" // we will know what we are going to inherit ( used in SectionInformation.OverrideModeEffective ) // Note that we cannot use BaseConfigurationRecord.ResolveOverrideModeFromParent as it gives us only the lock // resolved up to our immediate parent which does not inlcude normal and indirect location imputs _flags[FlagChildrenLockWithoutFileInput] = LockChildren; ChangeLockSettings(OverrideMode.Inherit, sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode); } }
private object CreateSectionWithRestrictedPermissions( RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) { // run configuration section handlers as if user code was on the stack bool revertPermitOnly = false; try { PermissionSet permissionSet = configRecord.GetRestrictedPermissions(); if (permissionSet != null) { permissionSet.PermitOnly(); revertPermitOnly = true; } return(CreateSectionImpl(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader)); } finally { if (revertPermitOnly) { CodeAccessPermission.RevertPermitOnly(); } } }
internal void AddLocationInput(SectionInput sectionInput) { this.AddLocationInputImpl(sectionInput, false); }
internal void AddIndirectLocationInput(SectionInput sectionInput) { this.AddLocationInputImpl(sectionInput, true); }
AddLocationInput(SectionInput sectionInput) { if (_locationInputs == null) { _locationInputs = new List<SectionInput>(1); } // The list of locationSections is traversed from child to parent, // so insert at the beginning of the list. _locationInputs.Insert(0, sectionInput); // If LockChildren is set, lock both ourselves and children if (!sectionInput.HasErrors && sectionInput.SectionXmlInfo.LockChildren) { Locked = true; LockChildren = true; } }
// After the config file has been written out, update the section records // to reflect changes that were made in the config file. private void UpdateRecords() { if (_factoryRecords != null) { foreach (FactoryRecord factoryRecord in _factoryRecords.Values) { // Update stream information if (String.IsNullOrEmpty(factoryRecord.Filename)) { factoryRecord.Filename = ConfigStreamInfo.StreamName; } factoryRecord.LineNumber = 0; ConfigurationSection configSection = GetConfigSection(factoryRecord.ConfigKey); if (configSection != null) { if (configSection.SectionInformation.Type != null) { factoryRecord.FactoryTypeName = configSection.SectionInformation.Type; } factoryRecord.AllowLocation = configSection.SectionInformation.AllowLocation; factoryRecord.RestartOnExternalChanges = configSection.SectionInformation.RestartOnExternalChanges; factoryRecord.RequirePermission = configSection.SectionInformation.RequirePermission; factoryRecord.AllowDefinition = configSection.SectionInformation.AllowDefinition; factoryRecord.AllowExeDefinition = configSection.SectionInformation.AllowExeDefinition; } } } if (_sectionRecords != null) { string definitionConfigPath = (IsLocationConfig) ? _parent.ConfigPath : ConfigPath; foreach (SectionRecord sectionRecord in _sectionRecords.Values) { string configSource; string configSourceStreamName; object configSourceStreamVersion; ConfigurationSection configSection; if (sectionRecord.HasResult) { configSection = (ConfigurationSection) sectionRecord.Result; configSource = configSection.SectionInformation.ConfigSource; if (String.IsNullOrEmpty(configSource)) { configSource = null; } configSourceStreamName = configSection.SectionInformation.ConfigSourceStreamName; if (String.IsNullOrEmpty(configSourceStreamName)) { configSourceStreamName = null; } } else { configSection = null; configSource = null; configSourceStreamName = null; // If there is no result, then the only way there could be a // section record is: // 1. For there to be input in the file. // 2. A location tag applies to this record Debug.Assert(sectionRecord.HasFileInput || sectionRecord.HasLocationInputs, "sectionRecord.HasFileInput || sectionRecord.HasLocationInputs"); // Note that if it's a location input, we don't need to monitor the configSource because // that stream is monitored by one of our parent's config record if (sectionRecord.HasFileInput) { SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo; configSource = sectionXmlInfo.ConfigSource; configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName; } } if (!String.IsNullOrEmpty(configSource)) { configSourceStreamVersion = MonitorStream(sectionRecord.ConfigKey, configSource, configSourceStreamName); } else { configSourceStreamVersion = null; } if (!sectionRecord.HasResult) { Debug.Assert(sectionRecord.HasFileInput || sectionRecord.HasLocationInputs, "sectionRecord.HasFileInput || sectionRecord.HasLocationInputs"); // Note that if it's a location input, we don't need to monitor the configSource because // that stream is monitored by one of our parent's config record if (sectionRecord.HasFileInput) { SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo; sectionXmlInfo.StreamVersion = ConfigStreamInfo.StreamVersion; sectionXmlInfo.ConfigSourceStreamVersion = configSourceStreamVersion; } } else { configSection.SectionInformation.RawXml = null; bool addUpdate = sectionRecord.AddUpdate; sectionRecord.AddUpdate = false; if (addUpdate) { SectionInput fileInput = sectionRecord.FileInput; if (fileInput == null) { SectionXmlInfo sectionXmlInfo = new SectionXmlInfo( sectionRecord.ConfigKey, definitionConfigPath, _configPath, _locationSubPath, ConfigStreamInfo.StreamName, 0, ConfigStreamInfo.StreamVersion, null, configSource, configSourceStreamName, configSourceStreamVersion, configSection.SectionInformation.ProtectionProviderName, configSection.SectionInformation.OverrideModeSetting, !configSection.SectionInformation.InheritInChildApplications); fileInput = new SectionInput(sectionXmlInfo, null); fileInput.Result = configSection; fileInput.ResultRuntimeObject = configSection; sectionRecord.AddFileInput(fileInput); } else { SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo; sectionXmlInfo.LineNumber = 0; sectionXmlInfo.StreamVersion = ConfigStreamInfo.StreamVersion; sectionXmlInfo.RawXml = null; sectionXmlInfo.ConfigSource = configSource; sectionXmlInfo.ConfigSourceStreamName = configSourceStreamName; sectionXmlInfo.ConfigSourceStreamVersion = configSourceStreamVersion; sectionXmlInfo.ProtectionProviderName = configSection.SectionInformation.ProtectionProviderName; sectionXmlInfo.OverrideModeSetting = configSection.SectionInformation.OverrideModeSetting; sectionXmlInfo.SkipInChildApps = !configSection.SectionInformation.InheritInChildApplications; } fileInput.ProtectionProvider = configSection.SectionInformation.ProtectionProvider; } try { configSection.ResetModified(); } catch (Exception e) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, sectionRecord.ConfigKey), e, ConfigStreamInfo.StreamName, 0); } } } } // Copy remaining stream updates, which correspond to streams used by location sections foreach (StreamInfo streamInfo in _streamInfoUpdates.Values) { if (!ConfigStreamInfo.StreamInfos.Contains(streamInfo.StreamName)) { MonitorStream(streamInfo.SectionName, streamInfo.ConfigSource, streamInfo.StreamName); } } // reinitialize _streamInfoUpdates InitStreamInfoUpdates(); // Update namespace value _flags[ NamespacePresentInFile ] = _flags[ NamespacePresentCurrent ]; // You only have one chance to force the location config, now you // will have to recreate the object _flags[ ForceLocationWritten ] = false; _flags[ SuggestLocationRemoval ] = false; // Handle removed location sections if (!IsLocationConfig && _locationSections != null && _removedSections != null && _removedSections.Count > 0) { int i = 0; while (i < _locationSections.Count) { LocationSectionRecord locationSectionRecord = (LocationSectionRecord) _locationSections[i]; if (_removedSections.Contains(locationSectionRecord.ConfigKey)) { _locationSections.RemoveAt(i); } else { i++; } } } _removedSections = null; _removedSectionGroups = null; }
// parentConfig contains the config that we'd merge with. override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) { // Get the factory used to create a section. RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory)factoryRecord.Factory; // Use the factory to create a section. object config = factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, sectionInput, parentConfig, reader); return(config); }
AddLocationInput(SectionInput sectionInput) { AddLocationInputImpl(sectionInput, false); }
internal void AddLocationInput(SectionInput sectionInput) { AddLocationInputImpl(sectionInput, false); }
private object CreateSectionWithFullTrust( RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) { return(CreateSectionImpl(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader)); }
AddIndirectLocationInput(SectionInput sectionInput) { AddLocationInputImpl(sectionInput, true); }
// AddFileInput internal void AddFileInput(SectionInput sectionInput) { Debug.Assert(sectionInput != null); _fileInput = sectionInput; if (!sectionInput.HasErrors) { // If the file input has an explciti value for its children locking - use it // Note we dont change the current lock setting if (sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode != OverrideMode.Inherit) { // Store the current setting before applying the lock from the file input // So that if the user changes the current OverrideMode on this configKey to "Inherit" // we will know what we are going to inherit ( used in SectionInformation.OverrideModeEffective ) // Note that we cannot use BaseConfigurationRecord.ResolveOverrideModeFromParent as it gives us only the lock // resolved up to our immediate parent which does not inlcude normal and indirect location imputs _flags[Flag_ChildrenLockWithoutFileInput] = LockChildren; ChangeLockSettings(OverrideMode.Inherit, sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode); } } }
private object EvaluateOne( string[] keys, SectionInput input, bool isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentResult) { object result; try { ConfigXmlReader reader = GetSectionXmlReader(keys, input); if (reader == null) { // // If section is not found in a file, use the parent result // result = UseParentResult(factoryRecord.ConfigKey, parentResult, sectionRecord); } else { result = CallCreateSection( isTrusted, factoryRecord, sectionRecord, parentResult, reader, input.SectionXmlInfo.Filename, input.SectionXmlInfo.LineNumber); } } catch (Exception e) { throw ExceptionUtil.WrapAsConfigException( SR.GetString(SR.Config_exception_creating_section, factoryRecord.ConfigKey), e, input.SectionXmlInfo); } catch { throw ExceptionUtil.WrapAsConfigException( SR.GetString(SR.Config_exception_creating_section, factoryRecord.ConfigKey), null, input.SectionXmlInfo); } return result; }
private object CreateSectionImpl( RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) { object config; if (_sectionCtor != null) { ConfigurationSection configSection = (ConfigurationSection)TypeUtil.InvokeCtorWithReflectionPermission(_sectionCtor); configSection.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord); configSection.CallInit(); ConfigurationSection parentSection = (ConfigurationSection)parentConfig; configSection.Reset(parentSection); if (reader != null) { configSection.DeserializeSection(reader); } if (configRecord != null && sectionInput != null && sectionInput.ConfigBuilder != null) { configSection = configRecord.CallHostProcessConfigurationSection(configSection, sectionInput.ConfigBuilder); } // throw if there are any cached errors ConfigurationErrorsException errors = configSection.GetErrors(); if (errors != null) { throw errors; } // don't allow changes to sections at runtime configSection.SetReadOnly(); // reset the modified bit configSection.ResetModified(); config = configSection; } else { if (reader != null) { XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader); CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode); // In v1, our old section handler expects a context that contains the virtualPath from the configPath object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath); config = _sectionHandler.Create(parentConfig, configContext, xmlNode); } else { config = null; } } return(config); }
private void UpdateRecords() { if (base._factoryRecords != null) { foreach (FactoryRecord record in base._factoryRecords.Values) { if (string.IsNullOrEmpty(record.Filename)) { record.Filename = base.ConfigStreamInfo.StreamName; } record.LineNumber = 0; ConfigurationSection configSection = this.GetConfigSection(record.ConfigKey); if (configSection != null) { if (configSection.SectionInformation.Type != null) { record.FactoryTypeName = configSection.SectionInformation.Type; } record.AllowLocation = configSection.SectionInformation.AllowLocation; record.RestartOnExternalChanges = configSection.SectionInformation.RestartOnExternalChanges; record.RequirePermission = configSection.SectionInformation.RequirePermission; record.AllowDefinition = configSection.SectionInformation.AllowDefinition; record.AllowExeDefinition = configSection.SectionInformation.AllowExeDefinition; } } } if (base._sectionRecords != null) { string definitionConfigPath = base.IsLocationConfig ? base._parent.ConfigPath : base.ConfigPath; foreach (SectionRecord record2 in base._sectionRecords.Values) { string configSource; string configSourceStreamName; object obj2; ConfigurationSection result; if (record2.HasResult) { result = (ConfigurationSection) record2.Result; configSource = result.SectionInformation.ConfigSource; if (string.IsNullOrEmpty(configSource)) { configSource = null; } configSourceStreamName = result.SectionInformation.ConfigSourceStreamName; if (string.IsNullOrEmpty(configSourceStreamName)) { configSourceStreamName = null; } } else { result = null; configSource = null; configSourceStreamName = null; if (record2.HasFileInput) { SectionXmlInfo sectionXmlInfo = record2.FileInput.SectionXmlInfo; configSource = sectionXmlInfo.ConfigSource; configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName; } } if (!string.IsNullOrEmpty(configSource)) { obj2 = base.MonitorStream(record2.ConfigKey, configSource, configSourceStreamName); } else { obj2 = null; } if (!record2.HasResult) { if (record2.HasFileInput) { SectionXmlInfo info2 = record2.FileInput.SectionXmlInfo; info2.StreamVersion = base.ConfigStreamInfo.StreamVersion; info2.ConfigSourceStreamVersion = obj2; } } else { result.SectionInformation.RawXml = null; bool addUpdate = record2.AddUpdate; record2.AddUpdate = false; if (addUpdate) { SectionInput fileInput = record2.FileInput; if (fileInput == null) { SectionXmlInfo info3 = new SectionXmlInfo(record2.ConfigKey, definitionConfigPath, base._configPath, base._locationSubPath, base.ConfigStreamInfo.StreamName, 0, base.ConfigStreamInfo.StreamVersion, null, configSource, configSourceStreamName, obj2, result.SectionInformation.ProtectionProviderName, result.SectionInformation.OverrideModeSetting, !result.SectionInformation.InheritInChildApplications); fileInput = new SectionInput(info3, null) { Result = result, ResultRuntimeObject = result }; record2.AddFileInput(fileInput); } else { SectionXmlInfo info4 = fileInput.SectionXmlInfo; info4.LineNumber = 0; info4.StreamVersion = base.ConfigStreamInfo.StreamVersion; info4.RawXml = null; info4.ConfigSource = configSource; info4.ConfigSourceStreamName = configSourceStreamName; info4.ConfigSourceStreamVersion = obj2; info4.ProtectionProviderName = result.SectionInformation.ProtectionProviderName; info4.OverrideModeSetting = result.SectionInformation.OverrideModeSetting; info4.SkipInChildApps = !result.SectionInformation.InheritInChildApplications; } fileInput.ProtectionProvider = result.SectionInformation.ProtectionProvider; } try { result.ResetModified(); } catch (Exception exception) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_exception_in_config_section_handler", new object[] { record2.ConfigKey }), exception, base.ConfigStreamInfo.StreamName, 0); } } } } foreach (StreamInfo info5 in this._streamInfoUpdates.Values) { if (!base.ConfigStreamInfo.StreamInfos.Contains(info5.StreamName)) { base.MonitorStream(info5.SectionName, info5.ConfigSource, info5.StreamName); } } this.InitStreamInfoUpdates(); this._flags[0x200] = this._flags[0x4000000]; this._flags[0x1000000] = false; this._flags[0x2000000] = false; if ((!base.IsLocationConfig && (base._locationSections != null)) && ((this._removedSections != null) && (this._removedSections.Count > 0))) { int index = 0; while (index < base._locationSections.Count) { LocationSectionRecord record3 = (LocationSectionRecord) base._locationSections[index]; if (this._removedSections.Contains(record3.ConfigKey)) { base._locationSections.RemoveAt(index); } else { index++; } } } this._removedSections = null; this._removedSectionGroups = null; }
protected ConfigXmlReader GetSectionXmlReader(string[] keys, SectionInput input) { ConfigXmlReader reader = null; string filename = input.SectionXmlInfo.Filename; int lineNumber = input.SectionXmlInfo.LineNumber; try { string name = keys[keys.Length-1]; string rawXml = input.SectionXmlInfo.RawXml; if (rawXml != null) { // Use the stored raw xml to provide the content of the section. reader = new ConfigXmlReader(rawXml, input.SectionXmlInfo.Filename, input.SectionXmlInfo.LineNumber); } else if (!String.IsNullOrEmpty(input.SectionXmlInfo.ConfigSource)) { // Load the config source to provide the content of the section. filename = input.SectionXmlInfo.ConfigSourceStreamName; lineNumber = 0; reader = LoadConfigSource(name, input.SectionXmlInfo); } else { // Find the content of the section in the config file. lineNumber = 0; reader = FindSection(keys, input.SectionXmlInfo, out lineNumber); } if (reader != null) { if (!input.IsProtectionProviderDetermined) { input.ProtectionProvider = GetProtectionProviderFromName(input.SectionXmlInfo.ProtectionProviderName, false); } if (input.ProtectionProvider != null) { reader = DecryptConfigSection(reader, input.ProtectionProvider); } } } // // Guarantee that exceptions contain the name of the stream and an approximate line number. // catch (Exception e) { throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), e, filename, lineNumber); } catch { throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), null, filename, lineNumber); } return reader; }
internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, SectionInput sectionInput, object parentConfig, ConfigXmlReader reader) { if (inputIsTrusted) { return(CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader)); } else { return(CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, sectionInput, parentConfig, reader)); } }
private void ScanSectionsRecursive( XmlUtil xmlUtil, string parentConfigKey, bool inLocation, string locationSubPath, bool lockChildren, bool skipInChildApps) { // discard any accumulated local errors xmlUtil.SchemaErrors.ResetLocalErrors(); int depth; // only move to child nodes when not on first level (we've already passed the first <configsections>) if (parentConfigKey.Length == 0 && !inLocation) { depth = 0; } else { depth = xmlUtil.Reader.Depth; xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific); } while (xmlUtil.Reader.Depth == depth + 1) { string tagName = xmlUtil.Reader.Name; // // Check for reserved elements before looking up the factory, // which may have the same name if it is in error. // if (tagName == KEYWORD_CONFIGSECTIONS) { // Error: duplicate <configSections> tag, or <configSections> not the first tag under <configuration> xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_client_config_too_many_configsections_elements, tagName), xmlUtil), ExceptionAction.NonSpecific); xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific); continue; } if (tagName == KEYWORD_LOCATION) { if (parentConfigKey.Length > 0 || inLocation) { // Error: <location> section not at top level xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_location_location_not_allowed), xmlUtil), ExceptionAction.Global); xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific); } else { // Recurse into the location section ScanLocationSection(xmlUtil); } continue; } string configKey = CombineConfigKey(parentConfigKey, tagName); FactoryRecord factoryRecord = FindFactoryRecord(configKey, true); if (factoryRecord == null) { // // if (!ClassFlags[ClassIgnoreLocalErrors]) { xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_unrecognized_configuration_section, configKey), xmlUtil), ExceptionAction.Local); } VerifySectionName(tagName, xmlUtil, ExceptionAction.Local, false); factoryRecord = new FactoryRecord( configKey, parentConfigKey, tagName, typeof(DefaultSection).AssemblyQualifiedName, true, // allowLocation ConfigurationAllowDefinition.Everywhere, ConfigurationAllowExeDefinition.MachineToRoamingUser, true, // restartOnExternalChanges true, // requirePermission _flags[IsTrusted], true, // isUndeclared null, -1); // Add any errors we may have encountered to the factory record, // so that child config that also refer to this unrecognized section // get the error. factoryRecord.AddErrors(xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true)); // Add the factory to the list of factories EnsureFactories()[configKey] = factoryRecord; } if (factoryRecord.IsGroup) { // // Section Group // if (factoryRecord.HasErrors) { xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific); } else { if (xmlUtil.Reader.AttributeCount > 0) { while (xmlUtil.Reader.MoveToNextAttribute()) { if (IsReservedAttributeName(xmlUtil.Reader.Name)) { xmlUtil.AddErrorReservedAttribute(ExceptionAction.NonSpecific); } } xmlUtil.Reader.MoveToElement(); // if on an attribute move back to the element } // Recurse into group definition ScanSectionsRecursive(xmlUtil, configKey, inLocation, locationSubPath, lockChildren, skipInChildApps); } } else { // // Section // configKey = factoryRecord.ConfigKey; string fileName = xmlUtil.Filename; int lineNumber = xmlUtil.LineNumber; string rawXml = null; string configSource = null; string configSourceStreamName = null; object configSourceStreamVersion = null; string protectionProviderName = null; bool isSectionLocked = false; bool positionedAtNextElement = false; bool isFileInput = (locationSubPath == null); if (!factoryRecord.HasErrors) { // We have a valid factoryRecord for a section if (inLocation && factoryRecord.AllowLocation == false) { xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_section_cannot_be_used_in_location), xmlUtil), ExceptionAction.Local); } // Verify correctness for file inputs. if (isFileInput) { // Verify that the section is unique SectionRecord sectionRecord = GetSectionRecord(configKey, true); if (sectionRecord != null && sectionRecord.HasFileInput) { xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_sections_must_be_unique), xmlUtil), ExceptionAction.Local); } // Verify that the definition is allowed. try { VerifyDefinitionAllowed(factoryRecord, _configPath, xmlUtil); } catch (ConfigurationException ce) { xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local); } } // Verify that section is unlocked, both for file and location inputs. try { VerifySectionUnlocked(configKey, xmlUtil); } catch (ConfigurationException ce) { isSectionLocked = true; xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local); } // check for configSource or protectionProvider if (xmlUtil.Reader.AttributeCount >= 1) { // First do all the attributes reading without advancing the reader. string configSourceAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_CONFIGSOURCE); if (configSourceAttribute != null) { try { configSource = NormalizeConfigSource(configSourceAttribute, xmlUtil); } catch (ConfigurationException ce) { xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local); } if (xmlUtil.Reader.AttributeCount != 1) { // Error: elements with configSource should not have other attributes xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_source_syntax_error), xmlUtil), ExceptionAction.Local); } } string protectionProviderAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_PROTECTION_PROVIDER); if (protectionProviderAttribute != null) { try { protectionProviderName = ValidateProtectionProviderAttribute(protectionProviderAttribute, xmlUtil); } catch (ConfigurationException ce) { xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local); } if (xmlUtil.Reader.AttributeCount != 1) { // Error: elements with protectionProvider should not have other attributes xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Protection_provider_syntax_error), xmlUtil), ExceptionAction.Local); } } // The 2nd part of the configSource check requires advancing the reader. // Please note that this part should be done only AFTER all other attributes // checking are done. if (configSourceAttribute != null) { if (!xmlUtil.Reader.IsEmptyElement) { while (xmlUtil.Reader.Read()) { XmlNodeType t = xmlUtil.Reader.NodeType; if (t == XmlNodeType.EndElement) break; if (t != XmlNodeType.Comment) { // Error: elements with configSource should not subelements other than comments xmlUtil.SchemaErrors.AddError( new ConfigurationErrorsException(SR.GetString(SR.Config_source_syntax_error), xmlUtil), ExceptionAction.Local); if (t == XmlNodeType.Element) { xmlUtil.StrictSkipToOurParentsEndElement(ExceptionAction.NonSpecific); } else { xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific); } positionedAtNextElement = true; break; } } } } } if (configSource != null) { try { try { configSourceStreamName = Host.GetStreamNameForConfigSource(ConfigStreamInfo.StreamName, configSource); } catch (Exception e) { throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_source_invalid), e, xmlUtil); } ValidateUniqueConfigSource(configKey, configSourceStreamName, configSource, xmlUtil); configSourceStreamVersion = MonitorStream(configKey, configSource, configSourceStreamName); } catch (ConfigurationException ex) { xmlUtil.SchemaErrors.AddError(ex, ExceptionAction.Local); } } // // prefetch the raw xml // if (!xmlUtil.SchemaErrors.HasLocalErrors) { if (configSource == null && ShouldPrefetchRawXml(factoryRecord)) { Debug.Assert(!positionedAtNextElement, "!positionedAtNextElement"); rawXml = xmlUtil.CopySection(); if (xmlUtil.Reader.NodeType != XmlNodeType.Element) { xmlUtil.VerifyIgnorableNodeType(ExceptionAction.NonSpecific); xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific); } positionedAtNextElement = true; } } } // Get the list of errors before advancing the reader List<ConfigurationException> localErrors = xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(isFileInput); // advance the reader to the next element if (!positionedAtNextElement) { xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific); } // Add the input either to: // 1. The file input at the current config level, or // 2. LocationSections, where it will be used in sub paths bool addInput = true; if (isFileInput) { // If isFileInput==true, Input added will be used against this config level. // Need to check if we need to skip it due to inheritInChildApplications. if (ShouldSkipDueToInheritInChildApplications(skipInChildApps)) { addInput = false; } } else { if (!_flags[SupportsLocation]) { // Skip if we have a location input but we don't support location tag. addInput = false; } } if (addInput) { string targetConfigPath = (locationSubPath == null) ? _configPath : null; SectionXmlInfo sectionXmlInfo = new SectionXmlInfo( configKey, _configPath, targetConfigPath, locationSubPath, fileName, lineNumber, ConfigStreamInfo.StreamVersion, rawXml, configSource, configSourceStreamName, configSourceStreamVersion, protectionProviderName, lockChildren, skipInChildApps); if (locationSubPath == null) { // // Add this file input to the section record // // We've already checked for locked above, so use skip the second check // and set the locked bit. SectionRecord sectionRecord = EnsureSectionRecordUnsafe(configKey, true); Debug.Assert(!sectionRecord.Locked || isSectionLocked, "!sectionRecord.Locked || isSectionLocked"); if (isSectionLocked) { sectionRecord.Locked = true; } SectionInput fileInput = new SectionInput(sectionXmlInfo, localErrors); sectionRecord.AddFileInput(fileInput); } else { // // Add this location input to this list of location sections // LocationSectionRecord locationSectionRecord = new LocationSectionRecord(sectionXmlInfo, localErrors); EnsureLocationSections().Add(locationSectionRecord); } } } } }
internal void Init( IInternalConfigRoot configRoot, BaseConfigurationRecord parent, string configPath, string locationSubPath) { _initErrors = new ConfigurationSchemaErrors(); // // try/catch here is only for unexpected exceptions due to errors in // our own code, as we always want the configuration record to be // usable // try { _configRoot = (InternalConfigRoot) configRoot; _parent = parent; _configPath = configPath; _locationSubPath = locationSubPath; _configName = ConfigPathUtility.GetName(configPath); if (IsLocationConfig) { _configStreamInfo = _parent.ConfigStreamInfo; } else { _configStreamInfo = new ConfigRecordStreamInfo(); } // no more initialization in case of root config if (IsRootConfig) return; // determine what features we support _flags[SupportsChangeNotifications] = ClassFlags[ClassSupportsChangeNotifications] && Host.SupportsChangeNotifications; _flags[SupportsRefresh] = ClassFlags[ClassSupportsRefresh] && Host.SupportsRefresh; _flags[SupportsKeepInputs] = ClassFlags[ClassSupportsKeepInputs] || _flags[SupportsRefresh]; _flags[SupportsPath] = Host.SupportsPath; _flags[SupportsLocation] = Host.SupportsLocation; // get static state based on the configPath if (_flags[SupportsLocation]) { _flags[IsAboveApplication] = Host.IsAboveApplication(_configPath); } _flags[IsTrusted] = Host.IsTrustedConfigPath(_configPath); ArrayList locationSubPathInputs = null; if (_flags[SupportsLocation]) { // // Treat location inputs from parent record // as though they were bonafide sections in this record. // if (IsLocationConfig && _parent._locationSections != null) { // Resolve paths and check for errors in location sections. _parent.ResolveLocationSections(); int i = 0; while (i < _parent._locationSections.Count) { LocationSectionRecord locationSectionRecord = (LocationSectionRecord) _parent._locationSections[i]; if (!StringUtil.EqualsIgnoreCase(locationSectionRecord.SectionXmlInfo.SubPath, _locationSubPath)) { i++; } else { // remove the locationSectionRecord from the list _parent._locationSections.RemoveAt(i); if (locationSubPathInputs == null) { locationSubPathInputs = new ArrayList(); } locationSubPathInputs.Add(locationSectionRecord); } } } // // Add location inputs that apply to this path, all the way up the parent hierarchy. // if (Host.IsLocationApplicable(_configPath)) { BaseConfigurationRecord current = _parent; while (!current.IsRootConfig) { if (current._locationSections != null) { current.ResolveLocationSections(); foreach (LocationSectionRecord locationSectionRecord in current._locationSections) { // We use the location tag input if: // - The path matches, and // - It's not skipped due to inheritInChildApplications setting. if (StringUtil.EqualsIgnoreCase(locationSectionRecord.SectionXmlInfo.TargetConfigPath, this._configPath) && !ShouldSkipDueToInheritInChildApplications(locationSectionRecord.SectionXmlInfo.SkipInChildApps)) { // add the location input for this section SectionRecord sectionRecord = EnsureSectionRecord(locationSectionRecord.ConfigKey, true); SectionInput sectionInput = new SectionInput( locationSectionRecord.SectionXmlInfo, locationSectionRecord.ErrorsList); sectionRecord.AddLocationInput(sectionInput); // copy the initialization errors to the record if (locationSectionRecord.HasErrors) { this._initErrors.AddSavedLocalErrors(locationSectionRecord.Errors); } } } } current = current._parent; } } } if (!IsLocationConfig) { // // If config file exists, open it and parse it once so we can // find what to evaluate later. // InitConfigFromFile(); } else { // Add location sections for this record as bonafide sections. if (locationSubPathInputs != null) { foreach (LocationSectionRecord locationSectionRecord in locationSubPathInputs) { // add the file input SectionRecord sectionRecord = EnsureSectionRecord(locationSectionRecord.ConfigKey, true); SectionInput sectionInput = new SectionInput(locationSectionRecord.SectionXmlInfo, locationSectionRecord.ErrorsList); sectionRecord.AddFileInput(sectionInput); // copy the initialization errors to the record if (locationSectionRecord.HasErrors) { this._initErrors.AddSavedLocalErrors(locationSectionRecord.Errors); } } } } } // // Capture all exceptions and include them in initialization errors. // catch (Exception e) { string streamname = (ConfigStreamInfo != null) ? ConfigStreamInfo.StreamName : null; _initErrors.AddError( ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), e, streamname, 0), ExceptionAction.Global); } catch { string streamname = (ConfigStreamInfo != null) ? ConfigStreamInfo.StreamName : null; _initErrors.AddError( ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), null, streamname, 0), ExceptionAction.Global); } }
AddLocationInputImpl(SectionInput sectionInput, bool isIndirectLocation) { List<SectionInput> inputs = isIndirectLocation ? _indirectLocationInputs : _locationInputs; int flag = isIndirectLocation ? Flag_IndirectLocationInputLockApplied : Flag_LocationInputLockApplied; if (inputs == null) { inputs = new List<SectionInput>(1); if (isIndirectLocation) { _indirectLocationInputs = inputs; } else { _locationInputs = inputs; } } // The list of locationSections is traversed from child to parent, // so insert at the beginning of the list. inputs.Insert(0, sectionInput); // Only the overrideMode from the parent thats closest to the SectionRecord has effect // // For location input: // Remember that this method will be called for location inputs comming from the immediate parent first // and then walking the hierarchy up to the root level // // For indirect location input: // This method will be first called for indirect input closest to the location config if (!sectionInput.HasErrors) { if (!_flags[flag]) { OverrideMode modeLocation = sectionInput.SectionXmlInfo.OverrideModeSetting.OverrideMode; if (modeLocation != OverrideMode.Inherit) { ChangeLockSettings(modeLocation, modeLocation); _flags[flag] = true; } } } }
// Recursively clear the result. // If forceEvaluation == true, force a rescan of the config file to find // the section. // Requires the hierarchy lock to be acquired (hl) internal void hlClearResultRecursive(string configKey, bool forceEvaluatation) { SectionRecord sectionRecord; // Refresh it's factory Record RefreshFactoryRecord(configKey); // Clear any stored result in the section sectionRecord = GetSectionRecord(configKey, false); if (sectionRecord != null) { sectionRecord.ClearResult(); sectionRecord.ClearRawXml(); } // // If we need to reevaluate, add a dummy file input so // that we open the file on the next evaluation // if (forceEvaluatation && !IsInitDelayed && !String.IsNullOrEmpty(ConfigStreamInfo.StreamName)) { if (_flags[SupportsPath]) { throw ExceptionUtil.UnexpectedError("BaseConfigurationRecord::hlClearResultRecursive"); } FactoryRecord factoryRecord = FindFactoryRecord(configKey, false); if (factoryRecord != null && !factoryRecord.IsGroup) { configKey = factoryRecord.ConfigKey; sectionRecord = EnsureSectionRecord(configKey, false); if (!sectionRecord.HasFileInput) { SectionXmlInfo sectionXmlInfo = new SectionXmlInfo( configKey, _configPath, _configPath, null, ConfigStreamInfo.StreamName, 0, null, null, null, null, null, null, false, false); SectionInput fileInput = new SectionInput(sectionXmlInfo, null); sectionRecord.AddFileInput(fileInput); } } } // Recurse if (_children != null) { IEnumerable children = _children.Values; foreach (BaseConfigurationRecord child in children) { child.hlClearResultRecursive(configKey, forceEvaluatation); } } }