// parentConfig contains the config that we'd merge with.
        override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, 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, parentConfig, reader);

            return config;
        }
        //
        // Add a section definition update to the correct location update.
        //
        internal DefinitionUpdate AddUpdate(OverrideModeSetting overrideMode, bool inheritInChildApps, bool moved, string updatedXml, SectionRecord sectionRecord) {
            LocationUpdates locationUpdates = FindLocationUpdates(overrideMode, inheritInChildApps);
            if (locationUpdates == null) {
                locationUpdates = new LocationUpdates(overrideMode, inheritInChildApps);
                _locationUpdatesList.Add(locationUpdates);
            }

            DefinitionUpdate definitionUpdate = new DefinitionUpdate(sectionRecord.ConfigKey, moved, updatedXml, sectionRecord);
            locationUpdates.SectionUpdates.AddSection(definitionUpdate);
            return definitionUpdate;
        }
Exemplo n.º 3
0
        // Add a section definition update to the correct location update.
        internal DefinitionUpdate AddUpdate(OverrideModeSetting overrideMode, bool inheritInChildApps, bool moved,
                                            string updatedXml, SectionRecord sectionRecord)
        {
            LocationUpdates locationUpdates = FindLocationUpdates(overrideMode, inheritInChildApps);

            if (locationUpdates == null)
            {
                locationUpdates = new LocationUpdates(overrideMode, inheritInChildApps);
                LocationUpdatesList.Add(locationUpdates);
            }

            DefinitionUpdate definitionUpdate = new DefinitionUpdate(sectionRecord.ConfigKey, moved, updatedXml,
                                                                     sectionRecord);

            locationUpdates.SectionUpdates.AddSection(definitionUpdate);
            return(definitionUpdate);
        }
        internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord) {
            _flags[ Flag_Attached ] = true;

            // factory info
            _configKey          = factoryRecord.ConfigKey;
            _group              = factoryRecord.Group;
            _name               = factoryRecord.Name;
            _typeName           = factoryRecord.FactoryTypeName;
            _allowDefinition    = factoryRecord.AllowDefinition;
            _allowExeDefinition = factoryRecord.AllowExeDefinition;
            _flags[ Flag_AllowLocation            ] = factoryRecord.AllowLocation;
            _flags[ Flag_RestartOnExternalChanges ] = factoryRecord.RestartOnExternalChanges;
            _flags[ Flag_RequirePermission        ] = factoryRecord.RequirePermission;

            if (factoryRecord.IsUndeclared) {
                _flags[ Flag_IsUndeclared             ] = true;
                _flags[ Flag_Declared                 ] = false;
                _flags[ Flag_DeclarationRequired      ] = false;
            }
            else {
                _flags[ Flag_IsUndeclared             ] = false;
                _flags[ Flag_Declared                 ] = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
                _flags[ Flag_DeclarationRequired      ] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
            }

            // section info
            _flags[ Flag_LocationLocked ]           = sectionRecord.Locked;

            if (sectionRecord.HasFileInput) {
                SectionInput fileInput = sectionRecord.FileInput;

                _flags[ Flag_ProtectionProviderDetermined ] = fileInput.IsProtectionProviderDetermined;
                _protectionProvider                         = fileInput.ProtectionProvider;
                
                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;

                _configSource                       = sectionXmlInfo.ConfigSource;
                _configSourceStreamName             = sectionXmlInfo.ConfigSourceStreamName;
                _flags[ Flag_AllowOverride ]        = !sectionXmlInfo.LockChildren;
                _flags[ Flag_InheritInChildApps ]   = !sectionXmlInfo.SkipInChildApps;
                _protectionProviderName             = sectionXmlInfo.ProtectionProviderName;
            }
            else {
                _flags[ Flag_ProtectionProviderDetermined ] = false;
                _protectionProvider = null;
            }

            // element context information
            _configurationSection.AssociateContext( configRecord );
        }
Exemplo n.º 5
0
        // parentConfig contains the config that we'd merge with.
        override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, 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, parentConfig, reader);

            return(config);
        }
Exemplo n.º 6
0
 // for instantiation of a ConfigurationSection from GetConfig
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord,
                                           SectionRecord sectionRecord)
 {
     SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
     _configRecord = configRecord;
 }
        //
        // Create a new ConfigurationSection with the same values as the parent.
        // We must use a different instance than the parent, as the parent is cached
        // by the config system and the child ConfigurationSection may change due to
        // user interaction.
        //
        override protected object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord) {
            FactoryRecord factoryRecord = FindFactoryRecord(configKey, false);
            if (factoryRecord == null) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_unrecognized_configuration_section, configKey));
            }

            object result = CallCreateSection(false, factoryRecord, sectionRecord, parentResult, null, null, -1);
            return result;
        }
Exemplo n.º 8
0
 private object CreateSectionWithFullTrust(
     RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
     object parentConfig, ConfigXmlReader reader)
 {
     return(CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
 }
 private bool IsConfigSectionMoved(SectionRecord sectionRecord, ConfigurationSection configSection)
 {
     return (!sectionRecord.HasFileInput || this.AreLocationAttributesModified(sectionRecord, configSection));
 }
        private bool AreSectionAttributesModified(SectionRecord sectionRecord, ConfigurationSection configSection) {
            string configSource;
            string protectionProviderName;

            if (sectionRecord.HasFileInput) {
                SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
                configSource = sectionXmlInfo.ConfigSource;
                protectionProviderName = sectionXmlInfo.ProtectionProviderName;
            }
            else {
                configSource = null;
                protectionProviderName = null;
            }

            return
                   !StringUtil.EqualsNE(configSource, configSection.SectionInformation.ConfigSource)
                || !StringUtil.EqualsNE(protectionProviderName, configSection.SectionInformation.ProtectionProviderName)
                || AreLocationAttributesModified(sectionRecord, configSection);
        }
            private object CreateSectionImpl(
                    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
                    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);
                    }

                    // 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;
            }
 protected override object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord)
 {
     FactoryRecord factoryRecord = base.FindFactoryRecord(configKey, false);
     if (factoryRecord == null)
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_unrecognized_configuration_section", new object[] { configKey }));
     }
     return base.CallCreateSection(false, factoryRecord, sectionRecord, parentResult, null, null, -1);
 }
Exemplo n.º 13
0
        protected override object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
        {
            RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory)factoryRecord.Factory;

            return(factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, parentConfig, reader));
        }
Exemplo n.º 14
0
            private object CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
            {
                object obj2;
                bool   flag = false;

                try
                {
                    PermissionSet restrictedPermissions = configRecord.GetRestrictedPermissions();
                    if (restrictedPermissions != null)
                    {
                        restrictedPermissions.PermitOnly();
                        flag = true;
                    }
                    obj2 = this.CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
                finally
                {
                    if (flag)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
                return(obj2);
            }
Exemplo n.º 15
0
 private object CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     if (this._sectionCtor != null)
     {
         ConfigurationSection section = (ConfigurationSection)System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(this._sectionCtor);
         section.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
         section.CallInit();
         ConfigurationSection parentElement = (ConfigurationSection)parentConfig;
         section.Reset(parentElement);
         if (reader != null)
         {
             section.DeserializeSection(reader);
         }
         ConfigurationErrorsException errors = section.GetErrors();
         if (errors != null)
         {
             throw errors;
         }
         section.SetReadOnly();
         section.ResetModified();
         return(section);
     }
     if (reader != null)
     {
         XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader);
         CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode);
         object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath);
         return(this._sectionHandler.Create(parentConfig, configContext, xmlNode));
     }
     return(null);
 }
Exemplo n.º 16
0
 internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     if (inputIsTrusted)
     {
         return(this.CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
     }
     return(this.CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
 }
 protected override object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     ConstructorInfo factory = (ConstructorInfo) factoryRecord.Factory;
     ConfigurationSection section = (ConfigurationSection) System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(factory);
     section.SectionInformation.AttachToConfigurationRecord(this, factoryRecord, sectionRecord);
     section.CallInit();
     ConfigurationSection parentElement = (ConfigurationSection) parentConfig;
     section.Reset(parentElement);
     if (reader != null)
     {
         section.DeserializeSection(reader);
     }
     section.ResetModified();
     return section;
 }
            private object CreateSectionWithRestrictedPermissions(
                    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
                    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, parentConfig, reader);
                }
                finally {
                    if (revertPermitOnly) {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
Exemplo n.º 19
0
 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);
 }
 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);
 }
 private object CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     if (this._sectionCtor != null)
     {
         ConfigurationSection section = (ConfigurationSection) System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(this._sectionCtor);
         section.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
         section.CallInit();
         ConfigurationSection parentElement = (ConfigurationSection) parentConfig;
         section.Reset(parentElement);
         if (reader != null)
         {
             section.DeserializeSection(reader);
         }
         ConfigurationErrorsException errors = section.GetErrors();
         if (errors != null)
         {
             throw errors;
         }
         section.SetReadOnly();
         section.ResetModified();
         return section;
     }
     if (reader != null)
     {
         XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader);
         CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode);
         object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath);
         return this._sectionHandler.Create(parentConfig, configContext, xmlNode);
     }
     return null;
 }
        private bool AreLocationAttributesModified(SectionRecord sectionRecord, ConfigurationSection configSection) {

            OverrideModeSetting overrideMode                = OverrideModeSetting.LocationDefault;
            bool                inheritInChildApplications  = true;

            if (sectionRecord.HasFileInput) {
                SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
                overrideMode = sectionXmlInfo.OverrideModeSetting;
                inheritInChildApplications = !sectionXmlInfo.SkipInChildApps;
            }

            // We will use IsSameForLocation tag so that we flag modes that cant go into the same location tag
            // as different. If we don't do that it will appear like the mode was not changed which will
            // case conflict later when determining if the section is moved ( when writing the new config updates )

            return
                   (!OverrideModeSetting.CanUseSameLocationTag(overrideMode, configSection.SectionInformation.OverrideModeSetting))
                || (inheritInChildApplications != configSection.SectionInformation.InheritInChildApplications);
        }
 private object CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     object obj2;
     bool flag = false;
     try
     {
         PermissionSet restrictedPermissions = configRecord.GetRestrictedPermissions();
         if (restrictedPermissions != null)
         {
             restrictedPermissions.PermitOnly();
             flag = true;
         }
         obj2 = this.CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
     }
     finally
     {
         if (flag)
         {
             CodeAccessPermission.RevertPermitOnly();
         }
     }
     return obj2;
 }
        private bool IsConfigSectionMoved(SectionRecord sectionRecord, ConfigurationSection configSection) {
            if (!sectionRecord.HasFileInput)
                return true;

            return AreLocationAttributesModified(sectionRecord, configSection);
        }
 protected override object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory) factoryRecord.Factory;
     return factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, parentConfig, reader);
 }
Exemplo n.º 26
0
            private object CreateSectionImpl(
                RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
                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);
                    }

                    // 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);
            }
        protected void CreateSectionDefault(
                string configKey, bool getRuntimeObject, FactoryRecord factoryRecord, SectionRecord sectionRecord,
                out object result, out object resultRuntimeObject) {

            result = null;
            resultRuntimeObject = null;

            SectionRecord sectionRecordForDefault;
            if (sectionRecord != null) {
                sectionRecordForDefault = sectionRecord;
            }
            else {
                sectionRecordForDefault = new SectionRecord(configKey);
            }

            object tmpResult = CallCreateSection(true, factoryRecord, sectionRecordForDefault, null, null, null, -1);
            object tmpResultRuntimeObject;
            if (getRuntimeObject) {
                tmpResultRuntimeObject = GetRuntimeObject(tmpResult);
            }
            else {
                tmpResultRuntimeObject = null;
            }

            result = tmpResult;
            resultRuntimeObject = tmpResultRuntimeObject;
        }
Exemplo n.º 28
0
            private object CreateSectionWithRestrictedPermissions(
                RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
                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, parentConfig, reader));
                }
                finally {
                    if (revertPermitOnly)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
        // 
        // Evaluate the input.
        //
        // If Evaluate() encounters an error, it may not throw an exception
        // when getLkg == true.
        //
        // The complete success of the evaluation is determined by the return value.
        //
        private bool Evaluate(
                FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentResult, 
                bool getLkg, bool getRuntimeObject, out object result, out object resultRuntimeObject) {

            result = null;
            resultRuntimeObject = null;

            //
            // Store results in temporary variables, because we don't want to return
            // results if an exception is thrown.
            //
            object tmpResult = null;
            object tmpResultRuntimeObject = null;

            // Factory record should be error-free.
            Debug.Assert(!factoryRecord.HasErrors, "!factoryRecord.HasErrors");

            // We should have some input
            Debug.Assert(sectionRecord.HasInput, "sectionRecord.HasInput");

            //
            // Grab inputs before checking result, 
            // as inputs may be cleared once the result is set.
            //
            List<SectionInput> locationInputs = sectionRecord.LocationInputs;
            SectionInput fileInput = sectionRecord.FileInput;

            //
            // Now that we have our inputs, lets check if there
            // is a result, because if there is, our inputs might
            // have been invalidated.
            //
            bool success = false;
            if (sectionRecord.HasResult) {
                // Results should never be stored if the section has errors.
                Debug.Assert(!sectionRecord.HasErrors, "!sectionRecord.HasErrors");

                // Create the runtime object if requested and it does not yet exist.
                if (getRuntimeObject && !sectionRecord.HasResultRuntimeObject) {
                    try {
                        sectionRecord.ResultRuntimeObject = GetRuntimeObject(sectionRecord.Result);
                    }
                    catch {
                        //
                        // Ignore the error if we are attempting to retreive
                        // the last known good configuration.
                        //
                        if (!getLkg) {
                            throw;
                        }
                    }
                }

                // Get the cached result.
                if (!getRuntimeObject || sectionRecord.HasResultRuntimeObject) {
                    tmpResult = sectionRecord.Result;
                    if (getRuntimeObject) {
                        tmpResultRuntimeObject = sectionRecord.ResultRuntimeObject;
                    }

                    success = true;
                }
            }

            if (!success) {
                Exception savedException = null;
                try {
                    string configKey = factoryRecord.ConfigKey;
                    string [] keys = configKey.Split(ConfigPathSeparatorParams);
                    object currentResult = parentResult;

                    //
                    // Evaluate location inputs
                    //
                    if (locationInputs != null) {
                        foreach (SectionInput locationInput in locationInputs) {
                            if (!locationInput.HasResult) {
                                locationInput.ThrowOnErrors();
                                bool isTrusted = Host.IsTrustedConfigPath(locationInput.SectionXmlInfo.DefinitionConfigPath);
                                locationInput.Result = EvaluateOne(keys, locationInput, isTrusted, factoryRecord, sectionRecord, currentResult);
                            }

                            currentResult = locationInput.Result;
                        }
                    }

                    //
                    // Evaluate file input
                    //
                    if (fileInput != null) {
                        if (!fileInput.HasResult) {
                            fileInput.ThrowOnErrors();
                            bool isTrusted = _flags[IsTrusted];
                            fileInput.Result = EvaluateOne(keys, fileInput, isTrusted, factoryRecord, sectionRecord, currentResult);
                        }

                        currentResult = fileInput.Result;
                    }
                    else {
                        //
                        // The section needs its own copy of the result that is distinct
                        // from its location parent result.
                        //
                        Debug.Assert(locationInputs != null, "locationInputs != null");
                        currentResult = UseParentResult(configKey, currentResult, sectionRecord);
                    }

                    if (getRuntimeObject) {
                        tmpResultRuntimeObject = GetRuntimeObject(currentResult);
                    }

                    tmpResult = currentResult;
                    success = true;
                }
                catch (Exception e) {
                    //
                    // Catch the exception if LKG is requested and we have
                    // location input to fall back on.
                    //
                    if (getLkg && locationInputs != null) {
                        savedException = e;
                    }
                    else {
                        throw;
                    }

                }

                //
                // If getLkg, then return a result from the last valid location input.
                //
                if (!success) {
                    Debug.Assert(getLkg == true, "getLkg == true");

                    int i = locationInputs.Count;
                    while (--i >= 0) {
                        SectionInput locationInput = locationInputs[i];
                        if (locationInput.HasResult) {
                            if (getRuntimeObject && !locationInput.HasResultRuntimeObject) {
                                try {
                                    locationInput.ResultRuntimeObject = GetRuntimeObject(locationInput.Result);
                                }
                                catch {
                                }
                            }

                            if (!getRuntimeObject || locationInput.HasResultRuntimeObject) {
                                tmpResult = locationInput.Result;
                                if (getRuntimeObject) {
                                    tmpResultRuntimeObject = locationInput.ResultRuntimeObject;
                                }

                                break;
                            }
                        }
                    }

                    if (i < 0) {
                        throw savedException;
                    }
                }
            }

            //
            // If evaluation was successful, we can remove any saved rawXml.
            //
            if (success && !_flags[SupportsKeepInputs]) {
                sectionRecord.ClearRawXml();
            }

            result = tmpResult;
            if (getRuntimeObject) {
                resultRuntimeObject = tmpResultRuntimeObject;
            }

            return success;
        }
Exemplo n.º 30
0
 protected override object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord)
 {
     return(parentResult);
 }
        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;
        }
Exemplo n.º 32
0
        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);
        }
 // Create the configuration object
 protected abstract object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader);
 // Use the parent result in creating the child
 protected abstract object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord);
        protected object CallCreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader, string filename, int line) {
            object config;

            // Call into config section while impersonating process or UNC identity
            // so that the section could read files from disk if needed
            try {
                using (Impersonate()) {
                    config = CreateSection(inputIsTrusted, factoryRecord, sectionRecord, parentConfig, reader);
                    if (config == null && parentConfig != null) {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_object_is_null), filename, line);
                    }
                }
            }
            catch (Exception e) {
                throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_exception_creating_section_handler, factoryRecord.ConfigKey), e, filename, line);
            }
            catch {
                throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_exception_creating_section_handler, factoryRecord.ConfigKey), null, filename, line);
            }

            return config;
        }
            private object CreateSectionWithFullTrust(
                    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
                    object parentConfig, ConfigXmlReader reader) {

                return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
            }
        // Return an existing SectionRecord, or create one if one does not exist.
        // If desired, set the locked bit if locked by a parent.
        private SectionRecord EnsureSectionRecordImpl(string configKey, bool permitErrors, bool checkIfLocked) {
            SectionRecord sectionRecord = GetSectionRecord(configKey, permitErrors);
            if (sectionRecord == null) {
                bool sectionAdded = false;
                lock (this) {
                    if (_sectionRecords == null) {
                        _sectionRecords = new Hashtable();
                    }
                    else {
                        sectionRecord = GetSectionRecord(configKey, permitErrors);
                    }

                    if (sectionRecord == null) {
                        sectionRecord = new SectionRecord(configKey);
                        _sectionRecords.Add(configKey, sectionRecord);
                        sectionAdded = true;
                    }
                }

                if (checkIfLocked && sectionAdded) {
                    sectionRecord.Locked = IsParentCausingLock(configKey);
                }
            }

            return sectionRecord;
        }
            internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord, 
                    FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {

                if (inputIsTrusted) {
                    return CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
                else {
                    return CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
            }
 private object CreateSectionWithRestrictedPermissions(
         RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
         object parentConfig, ConfigXmlReader reader)
 {
     return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
 }
 override protected object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord) {
     return parentResult;
 }
        //
        // Create the ConfigurationSection.
        //
        override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {
            // Create an instance of the ConfigurationSection
            ConstructorInfo ctor = (ConstructorInfo) factoryRecord.Factory;
            ConfigurationSection configSection = (ConfigurationSection) TypeUtil.InvokeCtorWithReflectionPermission(ctor);

            // Attach the ConfigurationSection to this record
            configSection.SectionInformation.AttachToConfigurationRecord(this, factoryRecord, sectionRecord);
            configSection.CallInit();

            // Initialize the ConfigurationSection with XML or just its parent.
            ConfigurationSection parentConfigSection = (ConfigurationSection) parentConfig;
            configSection.Reset(parentConfigSection);
            if (reader != null) {
                configSection.DeserializeSection(reader);
            }

            // Clear the modified bit.
            configSection.ResetModified();

            return configSection;
        }
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord)
 {
     this.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
     this._configRecord = configRecord;
 }
 private bool AreLocationAttributesModified(SectionRecord sectionRecord, ConfigurationSection configSection)
 {
     OverrideModeSetting locationDefault = OverrideModeSetting.LocationDefault;
     bool flag = true;
     if (sectionRecord.HasFileInput)
     {
         SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
         locationDefault = sectionXmlInfo.OverrideModeSetting;
         flag = !sectionXmlInfo.SkipInChildApps;
     }
     if (OverrideModeSetting.CanUseSameLocationTag(locationDefault, configSection.SectionInformation.OverrideModeSetting))
     {
         return (flag != configSection.SectionInformation.InheritInChildApplications);
     }
     return true;
 }