// constructor used for a section
 internal FactoryRecord(
         string configKey,
         string group,
         string name,
         string factoryTypeName,
         bool allowLocation,
         ConfigurationAllowDefinition allowDefinition,
         ConfigurationAllowExeDefinition allowExeDefinition,
         OverrideModeSetting             overrideModeDefault,
         bool restartOnExternalChanges,
         bool requirePermission,
         bool isFromTrustedConfigRecord,
         bool isUndeclared,
         string filename,
         int lineNumber)
 {
     _configKey                  = configKey;
     _group                      = group;
     _name                       = name;
     _factoryTypeName            = factoryTypeName;
     _allowDefinition            = allowDefinition;
     _allowExeDefinition         = allowExeDefinition;
     _overrideModeDefault        = overrideModeDefault;
     AllowLocation               = allowLocation;
     RestartOnExternalChanges    = restartOnExternalChanges;
     RequirePermission           = requirePermission;
     IsFromTrustedConfigRecord   = isFromTrustedConfigRecord;
     IsUndeclared                = isUndeclared;
     _filename                   = filename;
     _lineNumber                 = lineNumber;
 }
        private List<ConfigurationException>    _errors;                // errors

        // constructor used for Clone()
        FactoryRecord(
                string              configKey,
                string              group,
                string              name,
                object              factory,
                string              factoryTypeName,
                SimpleBitVector32   flags,
                ConfigurationAllowDefinition    allowDefinition,
                ConfigurationAllowExeDefinition allowExeDefinition,
                OverrideModeSetting             overrideModeDefault,
                string              filename,
                int                 lineNumber,
                ICollection<ConfigurationException> errors) {

            _configKey              = configKey;
            _group                  = group;
            _name                   = name;
            _factory                = factory;
            _factoryTypeName        = factoryTypeName;
            _flags                  = flags;
            _allowDefinition        = allowDefinition;
            _allowExeDefinition     = allowExeDefinition;
            _overrideModeDefault    = overrideModeDefault;
            _filename               = filename;
            _lineNumber             = lineNumber;

            AddErrors(errors);
        }
Exemple #3
0
		public SectionInfo (string sectionName, SectionInformation info)
		{
			Name = sectionName;
			TypeName = info.Type;
			this.allowLocation = info.AllowLocation;
			this.allowDefinition = info.AllowDefinition;
			this.allowExeDefinition = info.AllowExeDefinition;
			this.requirePermission = info.RequirePermission;
			this.restartOnExternalChanges = info.RestartOnExternalChanges;
		}
 internal SectionInformation(ConfigurationSection associatedConfigurationSection)
 {
     this._configurationSection = associatedConfigurationSection;
     this._allowDefinition = ConfigurationAllowDefinition.Everywhere;
     this._allowExeDefinition = ConfigurationAllowExeDefinition.MachineToApplication;
     this._overrideModeDefault = System.Configuration.OverrideModeSetting.SectionDefault;
     this._overrideMode = System.Configuration.OverrideModeSetting.LocationDefault;
     this._flags[8] = true;
     this._flags[0x10] = true;
     this._flags[0x20] = true;
     this._flags[0x100] = true;
     this._flags[0x1000] = false;
     this._modifiedFlags = new SimpleBitVector32();
 }
        //
        // Constructor
        //
        internal SectionInformation(ConfigurationSection associatedConfigurationSection) {
            _configKey = String.Empty;
            _group = String.Empty;
            _name = String.Empty;

            _configurationSection     = associatedConfigurationSection;
            _allowDefinition          = ConfigurationAllowDefinition.Everywhere;
            _allowExeDefinition       = ConfigurationAllowExeDefinition.MachineToApplication;

            _flags[ Flag_AllowLocation            ] = true;
            _flags[ Flag_RestartOnExternalChanges ] = true;
            _flags[ Flag_RequirePermission        ] = true;
            _flags[ Flag_AllowOverride            ] = true;
            _flags[ Flag_InheritInChildApps       ] = true;
            _flags[ Flag_ForceSave                ] = false;

            _modifiedFlags = new SimpleBitVector32();
        }
Exemple #6
0
        internal SectionInformation(ConfigurationSection associatedConfigurationSection)
        {
            ConfigKey = string.Empty;
            Name = string.Empty;

            _configurationSection = associatedConfigurationSection;
            _allowDefinition = ConfigurationAllowDefinition.Everywhere;
            _allowExeDefinition = ConfigurationAllowExeDefinition.MachineToApplication;
            _overrideModeDefault = OverrideModeSetting.s_sectionDefault;
            _overrideMode = OverrideModeSetting.s_locationDefault;

            _flags[FlagAllowLocation] = true;
            _flags[FlagRestartOnExternalChanges] = true;
            _flags[FlagRequirePermission] = true;
            _flags[FlagInheritInChildApps] = true;
            _flags[FlagForceSave] = false;

            _modifiedFlags = new SimpleBitVector32();
        }
 public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) {
     Host.VerifyDefinitionAllowed(configPath, allowDefinition, allowExeDefinition, errorInfo);
 }
        public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) {
            if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) {
                switch (allowDefinition) {
                    case ConfigurationAllowDefinition.MachineOnly:
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_machine), errorInfo.Filename, errorInfo.LineNumber);

                    case ConfigurationAllowDefinition.MachineToWebRoot:
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_webroot), errorInfo.Filename, errorInfo.LineNumber);

                    case ConfigurationAllowDefinition.MachineToApplication:
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_application), errorInfo.Filename, errorInfo.LineNumber);

                    default:
                        // If we have extended ConfigurationAllowDefinition
                        // make sure to update this switch accordingly
                        throw ExceptionUtil.UnexpectedError("WebConfigurationHost::VerifyDefinitionAllowed");
                }
            }
        }
        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 );
        }
 bool IInternalConfigHost.IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition) {
     return true;
 }
Exemple #11
0
		public virtual bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition,
							 ConfigurationAllowExeDefinition allowExeDefinition)
		{
			switch (allowDefinition) {
				case ConfigurationAllowDefinition.MachineOnly:
					return configPath == MachinePath || configPath == MachineWebPath;
				case ConfigurationAllowDefinition.MachineToWebRoot:
				case ConfigurationAllowDefinition.MachineToApplication:
					if (String.IsNullOrEmpty (configPath))
						return true;
					string normalized;

					if (VirtualPathUtility.IsRooted (configPath))
						normalized = VirtualPathUtility.Normalize (configPath);
					else
						normalized = configPath;
					
					if ((String.Compare (normalized, MachinePath, StringComparison.Ordinal) == 0) ||
						(String.Compare (normalized, MachineWebPath, StringComparison.Ordinal) == 0))
							return true;
				
					if ((String.Compare (normalized, appVirtualPath) != 0))
						return IsApplication (normalized);
				
					return true;
				default:
					return true;
			}
		}
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            string str;
            switch (allowExeDefinition)
            {
                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    str = "MACHINE/EXE/ROAMING_USER";
                    break;

                case ConfigurationAllowExeDefinition.MachineToLocalUser:
                    return true;

                case ConfigurationAllowExeDefinition.MachineOnly:
                    str = "MACHINE";
                    break;

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    str = "MACHINE/EXE";
                    break;

                default:
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::IsDefinitionAllowed");
            }
            return (configPath.Length <= str.Length);
        }
        // ExeDefinitionToString
        //
        // Take an ExeDefinition and translate it to a string
        //
        private string ExeDefinitionToString(
            ConfigurationAllowExeDefinition allowDefinition)
        {
            switch (allowDefinition)
            {
                case ConfigurationAllowExeDefinition.MachineOnly:
                    return KeywordSectionAllowdefinitionMachineonly;

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    return KeywordSectionAllowdefinitionMachinetoapplication;

                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    return KeywordSectionAllowexedefinitionMachtoroaming;

                case ConfigurationAllowExeDefinition.MachineToLocalUser:
                    return KeywordSectionAllowexedefinitionMachtolocal;
            }

            throw ExceptionUtil.PropertyInvalid("AllowExeDefinition");
        }
 public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
     if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
     {
         throw new ConfigurationErrorsException("The section can't be defined in this file (the allowed definition context is '" + allowDefinition + "').", errorInfo.Filename, errorInfo.LineNumber);
     }
 }
 public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
 {
     return(true);
 }
        public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
        {
            if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
            {
                switch (allowExeDefinition)
                {
                case ConfigurationAllowExeDefinition.MachineOnly:
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Config_allow_exedefinition_error_machine), errorInfo);

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Config_allow_exedefinition_error_application), errorInfo);

                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Config_allow_exedefinition_error_roaminguser), errorInfo);

                default:
                    // If we have extended ConfigurationAllowExeDefinition
                    // make sure to update this switch accordingly
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed");
                }
            }
        }
        public virtual bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            switch (allowDefinition)
            {
            case ConfigurationAllowDefinition.MachineOnly:
                return(configPath == "machine");

            case ConfigurationAllowDefinition.MachineToApplication:
                return(configPath == "machine" || configPath == "exe");

            default:
                return(true);
            }
        }
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            string allowedConfigPath;

            switch (allowExeDefinition)
            {
            case ConfigurationAllowExeDefinition.MachineOnly:
                allowedConfigPath = MachineConfigPath;
                break;

            case ConfigurationAllowExeDefinition.MachineToApplication:
                allowedConfigPath = ExeConfigPath;
                break;

            case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                allowedConfigPath = RoamingUserConfigPath;
                break;

            // MachineToLocalUser does not current have any definition restrictions
            case ConfigurationAllowExeDefinition.MachineToLocalUser:
                return(true);

            default:
                // If we have extended ConfigurationAllowExeDefinition
                // make sure to update this switch accordingly
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::IsDefinitionAllowed");
            }

            return(configPath.Length <= allowedConfigPath.Length);
        }
Exemple #19
0
 public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition,
                                             ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
     Host.VerifyDefinitionAllowed(configPath, allowDefinition, allowExeDefinition, errorInfo);
 }
 public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
     if (!this.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
     {
         ConfigurationAllowExeDefinition definition = allowExeDefinition;
         if (definition != ConfigurationAllowExeDefinition.MachineOnly)
         {
             if (definition == ConfigurationAllowExeDefinition.MachineToApplication)
             {
                 throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_application"), errorInfo);
             }
             if (definition == ConfigurationAllowExeDefinition.MachineToRoamingUser)
             {
                 throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_roaminguser"), errorInfo);
             }
             throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed");
         }
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_machine"), errorInfo);
     }
 }
        public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
        {
            if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
            {
                switch (allowExeDefinition)
                {
                    case ConfigurationAllowExeDefinition.MachineOnly:
                        throw new ConfigurationErrorsException(
                            SR.GetString(SR.Config_allow_exedefinition_error_machine), errorInfo);

                    case ConfigurationAllowExeDefinition.MachineToApplication:
                        throw new ConfigurationErrorsException(
                            SR.GetString(SR.Config_allow_exedefinition_error_application), errorInfo);

                    case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                        throw new ConfigurationErrorsException(
                            SR.GetString(SR.Config_allow_exedefinition_error_roaminguser), errorInfo);

                    default:
                        // If we have extended ConfigurationAllowExeDefinition
                        // make sure to update this switch accordingly
                        throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed");
                }
            }
        }
 bool IInternalConfigHost.IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
 {
     throw new NotImplementedException();
 }
Exemple #23
0
        public static string GenerateFileContent(
            List <Tuple <string, string, string> > SettingPropertiesList,
            Type applicationSettingsBaseType,
            bool hasUserSettings = true,
            bool hasAppSettings  = false,
            ConfigurationAllowExeDefinition allowExeDefinition = ConfigurationAllowExeDefinition.MachineOnly,
            ConfigurationAllowDefinition allowDefinition       = ConfigurationAllowDefinition.Everywhere,
            bool allowLocation = true)
        {
            var settingsClassType = applicationSettingsBaseType.Namespace + '.' + applicationSettingsBaseType.Name;

            string       SettingContent = string.Empty;
            MemoryStream stream         = new MemoryStream();
            XmlDocument  doc            = new XmlDocument();

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
            var config = doc.CreateElement(Consts.Config);

            doc.AppendChild(config);

            XmlElement settings;

            if (hasUserSettings)
            {
                settings = doc.CreateElement(Consts.UserSettings);
            }
            else if (hasAppSettings)
            {
                settings = doc.CreateElement(Consts.ApplicationSettings);
            }
            else
            {
                throw new Exception();
            }
            config.AppendChild(settings);

            var propertiesSettings =
                doc.CreateElement(settingsClassType);

            settings.AppendChild(propertiesSettings);

            //if (hasUserSettings)
            //{
            //    var userSectionGroupNode = doc.CreateElement(Consts.SectionGroup);

            //    var userSectionGroupNameAttribute = doc.CreateAttribute("name");
            //    userSectionGroupNameAttribute.InnerXml = Consts.UserSettings;
            //    userSectionGroupNode.Attributes.Append(userSectionGroupNameAttribute);

            //    var userSectionNode = doc.CreateElement(Consts.Section);

            //    var userSectionNameAttribute = doc.CreateAttribute("name");
            //    userSectionNameAttribute.InnerXml = settingsClassType;
            //    userSectionNode.Attributes.Append(userSectionNameAttribute);

            //    var userSectionTypeAttribute = doc.CreateAttribute("type");
            //    userSectionTypeAttribute.InnerXml = Assembly.GetCallingAssembly().GetType().AssemblyQualifiedName;
            //    userSectionNode.Attributes.Append(userSectionTypeAttribute);

            //    if (allowDefinition != ConfigurationAllowDefinition.Everywhere)
            //    {
            //        var allowDefinitionAttribute = doc.CreateAttribute("allowDefinition");
            //        allowDefinitionAttribute.InnerXml = allowDefinition.ToString();
            //        userSectionNode.Attributes.Append(allowDefinitionAttribute);
            //    }

            //    if (allowExeDefinition != ConfigurationAllowExeDefinition.MachineOnly)
            //    {
            //        var allowExeDefinitionAttribute = doc.CreateAttribute("allowExeDefinition");
            //        allowExeDefinitionAttribute.InnerXml = allowExeDefinition.ToString();
            //        userSectionNode.Attributes.Append(allowExeDefinitionAttribute);
            //    }

            //    if (allowLocation != true)
            //    {
            //        var allowLocationAttribute = doc.CreateAttribute("allowLocation");
            //        allowLocationAttribute.InnerXml = allowLocation.ToString();
            //        userSectionNode.Attributes.Append(allowLocationAttribute);
            //    }
            //    userSectionGroupNode.AppendChild(userSectionNode);
            //    configSectionsNode.AppendChild(userSectionGroupNode);
            //}

            //if (hasAppSettings)
            //{
            //    // TODO
            //}


            foreach (var SettingProperty in SettingPropertiesList)
            {
                var     settingName        = SettingProperty.Item1;
                var     settingValue       = SettingProperty.Item2;
                var     settingSerializeAs = SettingProperty.Item3;
                XmlNode setting            = GenerateSettingNode(doc, settingName, settingValue, settingSerializeAs);
                propertiesSettings.AppendChild(setting);
            }

            StringWriter sw     = new StringWriter();
            XmlWriter    writer = XmlWriter.Create(sw, new XmlWriterSettings {
                Encoding = new UTF8Encoding(false, true)
            });

            doc.WriteTo(writer);
            writer.Flush();
            sw.Flush();
            return(sw.ToString());
        }
 void IInternalConfigHost.VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
     throw new NotImplementedException();
 }
Exemple #25
0
		public override void ReadConfig (Configuration cfg, string streamName, XmlReader reader)
		{
			StreamName = streamName;
			ConfigHost = cfg.ConfigHost;

			while (reader.MoveToNextAttribute ()) {
				switch (reader.Name)
				{
					case "allowLocation":
						string allowLoc = reader.Value;
						allowLocation = (allowLoc == "true");
						if (!allowLocation && allowLoc != "false")
							ThrowException ("Invalid attribute value", reader);
						break;
	
					case "allowDefinition":
						string allowDef = reader.Value;
						try {
							allowDefinition = (ConfigurationAllowDefinition) Enum.Parse (
									   typeof (ConfigurationAllowDefinition), allowDef);
						} catch {
							ThrowException ("Invalid attribute value", reader);
						}
						break;
	
					case "allowExeDefinition":
						string allowExeDef = reader.Value;
						try {
							allowExeDefinition = (ConfigurationAllowExeDefinition) Enum.Parse (
									   typeof (ConfigurationAllowExeDefinition), allowExeDef);
						} catch {
							ThrowException ("Invalid attribute value", reader);
						}
						break;
	
					case "type":
						TypeName = reader.Value;
						break;
					
					case "name":
						Name = reader.Value;
						if (Name == "location")
							ThrowException ("location is a reserved section name", reader);
						break;
						
					case "requirePermission":
						string reqPerm = reader.Value;
						bool reqPermValue = (reqPerm == "true");
						if (!reqPermValue && reqPerm != "false")
							ThrowException ("Invalid attribute value", reader);
						requirePermission = reqPermValue;
						break;

					case "restartOnExternalChanges":
						string restart = reader.Value;
						bool restartValue = (restart == "true");
						if (!restartValue && restart != "false")
							ThrowException ("Invalid attribute value", reader);
						restartOnExternalChanges = restartValue;
						break;

					default:
						ThrowException (String.Format ("Unrecognized attribute: {0}", reader.Name), reader);
						break;
				}
			}

			if (Name == null || TypeName == null)
				ThrowException ("Required attribute missing", reader);

			reader.MoveToElement();
			reader.Skip ();
		}
Exemple #26
0
 bool IInternalConfigHost.IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
 {
     return(true);
 }
        // ExeDefinitionToString
        //
        // Take an ExeDefinition and translate it to a string
        //
        private string ExeDefinitionToString(
                ConfigurationAllowExeDefinition allowDefinition ) {
            switch (allowDefinition) {
                case ConfigurationAllowExeDefinition.MachineOnly:
                    return KEYWORD_SECTION_ALLOWDEFINITION_MACHINEONLY;

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    return KEYWORD_SECTION_ALLOWDEFINITION_MACHINETOAPPLICATION;

                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    return KEYWORD_SECTION_ALLOWEXEDEFINITION_MACHTOROAMING;

                case ConfigurationAllowExeDefinition.MachineToLocalUser:
                    return KEYWORD_SECTION_ALLOWEXEDEFINITION_MACHTOLOCAL;
            }

            throw ExceptionUtil.PropertyInvalid("AllowExeDefinition");
        }
Exemple #28
0
 void IInternalConfigHost.VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
 }
 void IInternalConfigHost.VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) {
 }
Exemple #30
0
 public virtual bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
 {
     return(Host.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition));
 }
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition) {
            switch (allowDefinition) {
                case ConfigurationAllowDefinition.MachineOnly:
                    return configPath.Length <= MachineConfigPath.Length;

                case ConfigurationAllowDefinition.MachineToWebRoot:
                    return configPath.Length <= RootWebConfigPath.Length;

                case ConfigurationAllowDefinition.MachineToApplication:
                    // In some scenarios the host does not have an application path.
                    // Allow all definitions in this case.
                    return  String.IsNullOrEmpty(_appConfigPath) ||
                            (configPath.Length <= _appConfigPath.Length) ||
                            IsApplication(configPath);

                // MachineToLocalUser does not current have any definition restrictions
                case ConfigurationAllowDefinition.Everywhere:
                    return true;

                default:
                    // If we have extended ConfigurationAllowDefinition
                    // make sure to update this switch accordingly
                    throw ExceptionUtil.UnexpectedError("WebConfigurationHost::IsDefinitionAllowed");
            }
        }
 internal bool IsDefinitionAllowed(ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition) {
     return Host.IsDefinitionAllowed(_configPath, allowDefinition, allowExeDefinition);
 }
Exemple #33
0
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            switch (allowDefinition)
            {
            case ConfigurationAllowDefinition.MachineOnly:
                return(configPath.Length <= MachineConfigPath.Length);

            case ConfigurationAllowDefinition.MachineToWebRoot:
                return(configPath.Length <= RootWebConfigPath.Length);

            case ConfigurationAllowDefinition.MachineToApplication:
                // In some scenarios the host does not have an application path.
                // Allow all definitions in this case.
                return(String.IsNullOrEmpty(_appConfigPath) ||
                       (configPath.Length <= _appConfigPath.Length) ||
                       IsApplication(configPath));

            // MachineToLocalUser does not current have any definition restrictions
            case ConfigurationAllowDefinition.Everywhere:
                return(true);

            default:
                // If we have extended ConfigurationAllowDefinition
                // make sure to update this switch accordingly
                throw ExceptionUtil.UnexpectedError("WebConfigurationHost::IsDefinitionAllowed");
            }
        }
		public virtual void VerifyDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
		{
			if (!IsDefinitionAllowed (configPath, allowDefinition, allowExeDefinition))
				throw new ConfigurationErrorsException ("The section can't be defined in this file (the allowed definition context is '" + allowDefinition + "').", errorInfo.Filename, errorInfo.LineNumber);
		}
 public virtual bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition) {
     return Host.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition);
 }
 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);
 }
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            string allowedConfigPath;

            switch (allowExeDefinition)
            {
                case ConfigurationAllowExeDefinition.MachineOnly:
                    allowedConfigPath = MachineConfigPath;
                    break;

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    allowedConfigPath = ExeConfigPath;
                    break;

                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    allowedConfigPath = RoamingUserConfigPath;
                    break;

                // MachineToLocalUser does not current have any definition restrictions
                case ConfigurationAllowExeDefinition.MachineToLocalUser:
                    return true;

                default:
                    // If we have extended ConfigurationAllowExeDefinition
                    // make sure to update this switch accordingly
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::IsDefinitionAllowed");
            }

            return configPath.Length <= allowedConfigPath.Length;
        }
        private string ExeDefinitionToString(ConfigurationAllowExeDefinition allowDefinition)
        {
            switch (allowDefinition)
            {
                case ConfigurationAllowExeDefinition.MachineOnly:
                    return "MachineOnly";

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    return "MachineToApplication";

                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    return "MachineToRoamingUser";

                case ConfigurationAllowExeDefinition.MachineToLocalUser:
                    return "MachineToLocalUser";
            }
            throw ExceptionUtil.PropertyInvalid("AllowExeDefinition");
        }
        internal bool IsEquivalentSectionFactory(
            IInternalConfigHost             host,
            string                          typeName,
            bool                            allowLocation,
            ConfigurationAllowDefinition    allowDefinition,
            ConfigurationAllowExeDefinition allowExeDefinition,
            bool                            restartOnExternalChanges,
            bool                            requirePermission) {

            if (    allowLocation               != this.AllowLocation               ||
                    allowDefinition             != this.AllowDefinition             ||
                    allowExeDefinition          != this.AllowExeDefinition          ||
                    restartOnExternalChanges    != this.RestartOnExternalChanges    ||
                    requirePermission           != this.RequirePermission) {

                return false;
            }

            return IsEquivalentType(host, typeName);
        }
Exemple #40
0
        public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
        {
            if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
            {
                switch (allowDefinition)
                {
                case ConfigurationAllowDefinition.MachineOnly:
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_machine), errorInfo.Filename, errorInfo.LineNumber);

                case ConfigurationAllowDefinition.MachineToWebRoot:
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_webroot), errorInfo.Filename, errorInfo.LineNumber);

                case ConfigurationAllowDefinition.MachineToApplication:
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_application), errorInfo.Filename, errorInfo.LineNumber);

                default:
                    // If we have extended ConfigurationAllowDefinition
                    // make sure to update this switch accordingly
                    throw ExceptionUtil.UnexpectedError("WebConfigurationHost::VerifyDefinitionAllowed");
                }
            }
        }
		public virtual bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
		{
			switch (allowDefinition) {
				case ConfigurationAllowDefinition.MachineOnly:
					return configPath == "machine";
				case ConfigurationAllowDefinition.MachineToApplication:
					return configPath == "machine" || configPath == "exe";
				default:
					return true;
			}
		}
Exemple #42
0
        public override void ReadConfig(Configuration cfg, string streamName, XmlReader reader)
        {
            StreamName = streamName;
            ConfigHost = cfg.ConfigHost;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "allowLocation":
                    string allowLoc = reader.Value;
                    _allowLocation = allowLoc == "true";
                    if (!_allowLocation && allowLoc != "false")
                    {
                        ThrowException("Invalid attribute value", reader);
                    }
                    break;

                case "allowDefinition":
                    string allowDef = reader.Value;
                    try
                    {
                        _allowDefinition = (ConfigurationAllowDefinition)Enum.Parse(
                            typeof(ConfigurationAllowDefinition), allowDef);
                    }
                    catch
                    {
                        ThrowException("Invalid attribute value", reader);
                    }
                    break;

                case "allowExeDefinition":
                    string allowExeDef = reader.Value;
                    try
                    {
                        _allowExeDefinition = (ConfigurationAllowExeDefinition)Enum.Parse(
                            typeof(ConfigurationAllowExeDefinition), allowExeDef);
                    }
                    catch
                    {
                        ThrowException("Invalid attribute value", reader);
                    }
                    break;

                case "type":
                    TypeName = reader.Value;
                    break;

                case "name":
                    Name = reader.Value;
                    if (Name == "location")
                    {
                        ThrowException("location is a reserved section name", reader);
                    }
                    break;

                case "requirePermission":
                    string reqPerm      = reader.Value;
                    var    reqPermValue = reqPerm == "true";
                    if (!reqPermValue && reqPerm != "false")
                    {
                        ThrowException("Invalid attribute value", reader);
                    }
                    _requirePermission = reqPermValue;
                    break;

                case "restartOnExternalChanges":
                    string restart      = reader.Value;
                    var    restartValue = restart == "true";
                    if (!restartValue && restart != "false")
                    {
                        ThrowException("Invalid attribute value", reader);
                    }
                    _restartOnExternalChanges = restartValue;
                    break;

                default:
                    ThrowException(string.Format("Unrecognized attribute: {0}", reader.Name), reader);
                    break;
                }
            }

            if (Name == null || TypeName == null)
            {
                ThrowException("Required attribute missing", reader);
            }

            reader.MoveToElement();
            reader.Skip();
        }
		public override bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
		{
			return true;
		}
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            switch (allowDefinition)
            {
                case ConfigurationAllowDefinition.MachineToApplication:
                    if (!string.IsNullOrEmpty(this._appConfigPath) && (configPath.Length > this._appConfigPath.Length))
                    {
                        return this.IsApplication(configPath);
                    }
                    return true;

                case ConfigurationAllowDefinition.Everywhere:
                    return true;

                case ConfigurationAllowDefinition.MachineOnly:
                    return (configPath.Length <= "machine".Length);

                case ConfigurationAllowDefinition.MachineToWebRoot:
                    return (configPath.Length <= "machine/webroot".Length);
            }
            throw System.Web.Util.ExceptionUtil.UnexpectedError("WebConfigurationHost::IsDefinitionAllowed");
        }
 public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
     if (!this.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
     {
         ConfigurationAllowDefinition definition = allowDefinition;
         if (definition != ConfigurationAllowDefinition.MachineOnly)
         {
             if (definition == ConfigurationAllowDefinition.MachineToWebRoot)
             {
                 throw new ConfigurationErrorsException(System.Web.SR.GetString("Config_allow_definition_error_webroot"), errorInfo.Filename, errorInfo.LineNumber);
             }
             if (definition == ConfigurationAllowDefinition.MachineToApplication)
             {
                 throw new ConfigurationErrorsException(System.Web.SR.GetString("Config_allow_definition_error_application"), errorInfo.Filename, errorInfo.LineNumber);
             }
             throw System.Web.Util.ExceptionUtil.UnexpectedError("WebConfigurationHost::VerifyDefinitionAllowed");
         }
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Config_allow_definition_error_machine"), errorInfo.Filename, errorInfo.LineNumber);
     }
 }
Exemple #46
0
        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;
            _overrideModeDefault                  = factoryRecord.OverrideModeDefault;

            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;
            _flags[Flag_ChildrenLocked] = sectionRecord.LockChildren;
            _flags[Flag_ChildrenLockWithoutFileInput] = sectionRecord.LockChildrenWithoutFileInput;

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

                _flags[Flag_ConfigBuilderDetermined] = fileInput.IsConfigBuilderDetermined;
                _configBuilder = fileInput.ConfigBuilder;
                _flags[Flag_ProtectionProviderDetermined] = fileInput.IsProtectionProviderDetermined;
                _protectionProvider = fileInput.ProtectionProvider;

                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;

                _configSource                   = sectionXmlInfo.ConfigSource;
                _configSourceStreamName         = sectionXmlInfo.ConfigSourceStreamName;
                _overrideMode                   = sectionXmlInfo.OverrideModeSetting;
                _flags[Flag_InheritInChildApps] = !sectionXmlInfo.SkipInChildApps;
                _configBuilderName              = sectionXmlInfo.ConfigBuilderName;
                _protectionProviderName         = sectionXmlInfo.ProtectionProviderName;
            }
            else
            {
                _flags[Flag_ConfigBuilderDetermined] = false;
                _configBuilder = null;
                _flags[Flag_ProtectionProviderDetermined] = false;
                _protectionProvider = null;
            }

            // element context information
            _configurationSection.AssociateContext(configRecord);
        }