You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
eglib
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Reflection.DispatchProxy
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.InteropServices.RuntimeInformation
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
System.Xml.XPath.XmlDocument
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
SMDiagnostics
System
System.Activities
System.Activities.Core.Presentation
System.Activities.DurableInstancing
System.Activities.Presentation
System.ComponentModel.DataAnnotations
System.Configuration
Microsoft
System
Configuration
Internal
AppSettingsSection.cs
BaseConfigurationRecord.cs.REMOVED.git-id
CRYPTPROTECT_PROMPTSTRUCT.cs
CallbackValidator.cs
CallbackValidatorAttribute.cs
ClientConfigPaths.cs
ClientConfigPerf.cs
ClientConfigurationHost.cs
ClientConfigurationSystem.cs
CommaDelimitedStringAttributeCollectionConverter.cs
ConfigDefinitionUpdates.cs
ConfigXmlAttribute.cs
ConfigXmlCDataSection.cs
ConfigXmlComment.cs
ConfigXmlElement.cs
ConfigXmlReader.cs
ConfigXmlSignificantWhitespace.cs
ConfigXmlText.cs
ConfigXmlWhitespace.cs
Configuration.cs
ConfigurationAllowDefinition.cs
ConfigurationAllowExeDefinition.cs
ConfigurationCollectionAttribute.cs
ConfigurationConverterBase.cs
ConfigurationElement.cs
ConfigurationElementCollection.cs
ConfigurationElementCollectionType.cs
ConfigurationElementProperty.cs
ConfigurationErrorsException.cs
ConfigurationFileMap.cs
ConfigurationLocation.cs
ConfigurationLocationCollection.cs
ConfigurationLockCollection.cs
ConfigurationLockCollectionType.cs
ConfigurationManager.cs
ConfigurationManagerHelperFactory.cs
ConfigurationPermission.cs
ConfigurationProperty.cs
ConfigurationPropertyAttribute.cs
ConfigurationPropertyCollection.cs
ConfigurationPropertyOptions.cs
ConfigurationSaveMode.cs
ConfigurationSchemaErrors.cs
ConfigurationSection.cs
ConfigurationSectionCollection.cs
ConfigurationSectionGroup.cs
ConfigurationSectionGroupCollection.cs
ConfigurationUserLevel.cs
ConfigurationValidatorAttribute.cs
ConfigurationValidatorBase.cs
ConfigurationValue.cs
ConfigurationValueFlags.cs
ConfigurationValues.cs
ConnectionStringSettings.cs
ConnectionStringSettingsCollection.cs
ConnectionStringsSection.cs
ContextInformation.cs
DATA_BLOB.cs
DPAPIProtectedConfigurationProvider.cs
DateTimeConfigurationCollection.cs
DateTimeConfigurationElement.cs
Debug.cs
DeclarationUpdate.cs
DefaultSection.cs
DefaultValidator.cs
DefinitionUpdate.cs
EmptyImpersonationContext.cs
ErrorInfoXmlDocument.cs
ErrorsHelper.cs
ExceptionAction.cs
ExceptionUtil.cs
ExeConfigurationFileMap.cs
ExeContext.cs
FactoryId.cs
FactoryRecord.cs
FileUtil.cs
FipsAwareEncryptedXml.cs
GenericEnumConverter.cs
IgnoreSection.cs
InfiniteIntConverter.cs
InfiniteTimeSpanConverter.cs
IntegerValidator.cs
IntegerValidatorAttribute.cs
InvalidPropValue.cs
KeyValueConfigurationCollection.cs
KeyValueConfigurationElement.cs
KeyValueInternalCollection.cs
LocationSectionRecord.cs
LocationUpdates.cs
LongValidator.cs
LongValidatorAttribute.cs
MgmtConfigurationRecord.cs.REMOVED.git-id
NameValueConfigurationCollection.cs
NameValueConfigurationElement.cs
NamespaceChange.cs
OverrideMode.cs
PositiveTimeSpanValidator.cs
PositiveTimeSpanValidatorAttribute.cs
PropertyInformation.cs
PropertyInformationCollection.cs
PropertySourceInfo.cs
PropertyValueOrigin.cs
ProtectedConfiguration.cs
ProtectedConfigurationProvider.cs
ProtectedConfigurationProviderCollection.cs
ProtectedConfigurationSection.cs
ProtectedProviderSettings.cs
ProviderBase.cs
ProviderCollection.cs
ProviderException.cs
ProviderSettings.cs
ProviderSettingsCollection.cs
RSAProtectedConfigurationProvider.cs
RegexStringValidator.cs
RegexStringValidatorAttribute.cs
RuntimeConfigurationRecord.cs
SafeBitVector32.cs
SectionInformation.cs
SectionInput.cs
SectionRecord.cs
SectionUpdates.cs
SectionXmlInfo.cs
SimpleBitVector32.cs
StreamInfo.cs
StreamUpdate.cs
StringAttributeCollection.cs
StringUtil.cs
StringValidator.cs
StringValidatorAttribute.cs
SubclassTypeValidator.cs
SubclassTypeValidatorAttribute.cs
TimeSpanMinutesConverter.cs
TimeSpanMinutesOrInfiniteConverter.cs
TimeSpanSecondsConverter.cs
TimeSpanSecondsOrInfiniteConverter.cs
TimeSpanValidator.cs
TimeSpanValidatorAttribute.cs
TypeNameConverter.cs
TypeUtil.cs
Update.cs
UrlPath.cs
ValidatorCallback.cs
ValidatorUtils.cs
WhiteSpaceTrimStringConverter.cs
XmlUtil.cs
XmlUtilWriter.cs
elementinformation.cs
updateconfighost.cs
misc
GlobalSuppressions.cs
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.IdentityModel
System.IdentityModel.Selectors
System.Net
System.Numerics
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.Serialization
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.WorkflowServices
System.Xaml.Hosting
System.Xml
System.Xml.Linq
XamlBuildTask
mscorlib
LICENSE.txt
PATENTS.TXT
README.Mono
README.md
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
nunit24
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
winexe.in
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
625 lines
24 KiB
C#
625 lines
24 KiB
C#
//------------------------------------------------------------------------------
|
|
// <copyright file="ClientConfigurationHost.cs" company="Microsoft">
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// </copyright>
|
|
//------------------------------------------------------------------------------
|
|
|
|
namespace System.Configuration {
|
|
using System.Configuration.Internal;
|
|
using System.IO;
|
|
using System.Security.Policy;
|
|
using System.Security.Permissions;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Security;
|
|
using System.Net;
|
|
using System.Security.Principal;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
internal sealed class ClientConfigurationHost : DelegatingConfigHost, IInternalConfigClientHost {
|
|
internal const string MachineConfigName = "MACHINE";
|
|
internal const string ExeConfigName = "EXE";
|
|
internal const string RoamingUserConfigName = "ROAMING_USER";
|
|
internal const string LocalUserConfigName = "LOCAL_USER";
|
|
|
|
internal const string MachineConfigPath = MachineConfigName;
|
|
internal const string ExeConfigPath = MachineConfigPath + "/" + ExeConfigName;
|
|
internal const string RoamingUserConfigPath = ExeConfigPath + "/" + RoamingUserConfigName;
|
|
internal const string LocalUserConfigPath = RoamingUserConfigPath + "/" + LocalUserConfigName;
|
|
|
|
private const string ConfigExtension = ".config";
|
|
private const string MachineConfigFilename = "machine.config";
|
|
private const string MachineConfigSubdirectory = "Config";
|
|
|
|
private static object s_init = new object();
|
|
private static object s_version = new object();
|
|
private static volatile string s_machineConfigFilePath;
|
|
|
|
private string _exePath; // the physical path to the exe being configured
|
|
private ClientConfigPaths _configPaths; // physical paths to client config files
|
|
private ExeConfigurationFileMap _fileMap; // optional file map
|
|
private bool _initComplete;
|
|
|
|
internal ClientConfigurationHost() {
|
|
Host = new InternalConfigHost();
|
|
}
|
|
|
|
internal ClientConfigPaths ConfigPaths {
|
|
get {
|
|
if (_configPaths == null) {
|
|
_configPaths = ClientConfigPaths.GetPaths(_exePath, _initComplete);
|
|
}
|
|
|
|
return _configPaths;
|
|
}
|
|
}
|
|
|
|
internal void RefreshConfigPaths() {
|
|
// Refresh current config paths.
|
|
if (_configPaths != null && !_configPaths.HasEntryAssembly && _exePath == null) {
|
|
ClientConfigPaths.RefreshCurrent();
|
|
_configPaths = null;
|
|
}
|
|
}
|
|
|
|
static internal string MachineConfigFilePath {
|
|
[FileIOPermissionAttribute(SecurityAction.Assert, AllFiles = FileIOPermissionAccess.PathDiscovery)]
|
|
[SuppressMessage("Microsoft.Security", "CA2106:SecureAsserts", Justification = "The callers do not expose this information without performing the appropriate demands themselves.")]
|
|
get {
|
|
if (s_machineConfigFilePath == null) {
|
|
string directory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
|
|
s_machineConfigFilePath = Path.Combine(Path.Combine(directory, MachineConfigSubdirectory), MachineConfigFilename);
|
|
}
|
|
|
|
return s_machineConfigFilePath;
|
|
}
|
|
}
|
|
|
|
internal bool HasRoamingConfig {
|
|
get {
|
|
if (_fileMap != null) {
|
|
return !String.IsNullOrEmpty(_fileMap.RoamingUserConfigFilename);
|
|
}
|
|
else {
|
|
return ConfigPaths.HasRoamingConfig;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal bool HasLocalConfig {
|
|
get {
|
|
if (_fileMap != null) {
|
|
return !String.IsNullOrEmpty(_fileMap.LocalUserConfigFilename);
|
|
}
|
|
else {
|
|
return ConfigPaths.HasLocalConfig;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal bool IsAppConfigHttp {
|
|
get {
|
|
return !IsFile(GetStreamName(ExeConfigPath));
|
|
}
|
|
}
|
|
|
|
// IInternalConfigClientHost methods are used by Venus and Whitehorse
|
|
// so as not to require explicit knowledge of the contents of the
|
|
// config path.
|
|
|
|
// return true if the config path is for an exe config, false otherwise.
|
|
bool IInternalConfigClientHost.IsExeConfig(string configPath) {
|
|
return StringUtil.EqualsIgnoreCase(configPath, ExeConfigPath);
|
|
}
|
|
|
|
bool IInternalConfigClientHost.IsRoamingUserConfig(string configPath) {
|
|
return StringUtil.EqualsIgnoreCase(configPath, RoamingUserConfigPath);
|
|
}
|
|
|
|
bool IInternalConfigClientHost.IsLocalUserConfig(string configPath) {
|
|
return StringUtil.EqualsIgnoreCase(configPath, LocalUserConfigPath);
|
|
}
|
|
|
|
// Return true if the config path is for a user.config file, false otherwise.
|
|
private bool IsUserConfig(string configPath) {
|
|
return StringUtil.EqualsIgnoreCase(configPath, RoamingUserConfigPath) ||
|
|
StringUtil.EqualsIgnoreCase(configPath, LocalUserConfigPath);
|
|
}
|
|
|
|
string IInternalConfigClientHost.GetExeConfigPath() {
|
|
return ExeConfigPath;
|
|
}
|
|
|
|
string IInternalConfigClientHost.GetRoamingUserConfigPath() {
|
|
return RoamingUserConfigPath;
|
|
}
|
|
|
|
string IInternalConfigClientHost.GetLocalUserConfigPath() {
|
|
return LocalUserConfigPath;
|
|
}
|
|
|
|
public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams) {
|
|
try {
|
|
ConfigurationFileMap fileMap = (ConfigurationFileMap) hostInitParams[0];
|
|
_exePath = (string) hostInitParams[1];
|
|
|
|
Host.Init(configRoot, hostInitParams);
|
|
|
|
// Do not complete initialization in runtime config, to avoid expense of
|
|
// loading user.config files that may not be required.
|
|
_initComplete = configRoot.IsDesignTime;
|
|
|
|
if (fileMap != null && !String.IsNullOrEmpty(_exePath)) {
|
|
throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
|
|
}
|
|
|
|
if (String.IsNullOrEmpty(_exePath)) {
|
|
_exePath = null;
|
|
}
|
|
|
|
// Initialize the fileMap, if provided.
|
|
if (fileMap != null) {
|
|
_fileMap = new ExeConfigurationFileMap();
|
|
if (!String.IsNullOrEmpty(fileMap.MachineConfigFilename)) {
|
|
_fileMap.MachineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename);
|
|
}
|
|
|
|
ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
|
|
if (exeFileMap != null) {
|
|
if (!String.IsNullOrEmpty(exeFileMap.ExeConfigFilename)) {
|
|
_fileMap.ExeConfigFilename = Path.GetFullPath(exeFileMap.ExeConfigFilename);
|
|
}
|
|
|
|
if (!String.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename)) {
|
|
_fileMap.RoamingUserConfigFilename = Path.GetFullPath(exeFileMap.RoamingUserConfigFilename);
|
|
}
|
|
|
|
if (!String.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename)) {
|
|
_fileMap.LocalUserConfigFilename = Path.GetFullPath(exeFileMap.LocalUserConfigFilename);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (SecurityException) {
|
|
// Lets try to give them some information telling them
|
|
// they don't have enough security privileges
|
|
throw new ConfigurationErrorsException(
|
|
SR.GetString(SR.Config_client_config_init_security));
|
|
}
|
|
catch {
|
|
throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
|
|
}
|
|
}
|
|
|
|
public override void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath,
|
|
IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams) {
|
|
|
|
locationSubPath = null;
|
|
configPath = (string) hostInitConfigurationParams[2];
|
|
locationConfigPath = null;
|
|
|
|
Init(configRoot, hostInitConfigurationParams);
|
|
}
|
|
|
|
// Delay init if we have not been asked to complete init, and it is a user.config file.
|
|
public override bool IsInitDelayed(IInternalConfigRecord configRecord) {
|
|
return !_initComplete && IsUserConfig(configRecord.ConfigPath);
|
|
}
|
|
|
|
public override void RequireCompleteInit(IInternalConfigRecord record) {
|
|
// Loading information about user.config files is expensive,
|
|
// so do it just once by locking.
|
|
lock (this) {
|
|
if (!_initComplete) {
|
|
// Note that all future requests for config must be complete.
|
|
_initComplete = true;
|
|
|
|
// Throw out the ConfigPath for this exe.
|
|
ClientConfigPaths.RefreshCurrent();
|
|
|
|
// Throw out our cached copy.
|
|
_configPaths = null;
|
|
|
|
// Force loading of user.config file information under lock.
|
|
ClientConfigPaths configPaths = ConfigPaths;
|
|
}
|
|
}
|
|
}
|
|
|
|
// config path support
|
|
public override bool IsConfigRecordRequired(string configPath) {
|
|
string configName = ConfigPathUtility.GetName(configPath);
|
|
switch (configName) {
|
|
default:
|
|
// should never get here
|
|
return false;
|
|
|
|
case MachineConfigName:
|
|
case ExeConfigName:
|
|
return true;
|
|
|
|
case RoamingUserConfigName:
|
|
// Makes the design easier even if we only have an empty Roaming config record.
|
|
return HasRoamingConfig || HasLocalConfig;
|
|
|
|
case LocalUserConfigName:
|
|
return HasLocalConfig;
|
|
}
|
|
}
|
|
|
|
// stream support
|
|
public override string GetStreamName(string configPath) {
|
|
string configName = ConfigPathUtility.GetName(configPath);
|
|
if (_fileMap != null) {
|
|
switch (configName) {
|
|
default:
|
|
// should never get here
|
|
goto case MachineConfigName;
|
|
|
|
case MachineConfigName:
|
|
return _fileMap.MachineConfigFilename;
|
|
|
|
case ExeConfigName:
|
|
return _fileMap.ExeConfigFilename;
|
|
|
|
case RoamingUserConfigName:
|
|
return _fileMap.RoamingUserConfigFilename;
|
|
|
|
case LocalUserConfigName:
|
|
return _fileMap.LocalUserConfigFilename;
|
|
}
|
|
}
|
|
else {
|
|
switch (configName) {
|
|
default:
|
|
// should never get here
|
|
goto case MachineConfigName;
|
|
|
|
case MachineConfigName:
|
|
return MachineConfigFilePath;
|
|
|
|
case ExeConfigName:
|
|
return ConfigPaths.ApplicationConfigUri;
|
|
|
|
case RoamingUserConfigName:
|
|
return ConfigPaths.RoamingConfigFilename;
|
|
|
|
case LocalUserConfigName:
|
|
return ConfigPaths.LocalConfigFilename;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string GetStreamNameForConfigSource(string streamName, string configSource) {
|
|
if (IsFile(streamName)) {
|
|
return Host.GetStreamNameForConfigSource(streamName, configSource);
|
|
}
|
|
|
|
int index = streamName.LastIndexOf('/');
|
|
if (index < 0)
|
|
return null;
|
|
|
|
string parentUri = streamName.Substring(0, index + 1);
|
|
string result = parentUri + configSource.Replace('\\', '/');
|
|
|
|
return result;
|
|
}
|
|
|
|
public override object GetStreamVersion(string streamName) {
|
|
if (IsFile(streamName)) {
|
|
return Host.GetStreamVersion(streamName);
|
|
}
|
|
|
|
// assume it is the same
|
|
return s_version;
|
|
}
|
|
|
|
|
|
// default impl treats name as a file name
|
|
// null means stream doesn't exist for this name
|
|
public override Stream OpenStreamForRead(string streamName) {
|
|
// the streamName can either be a file name, or a URI
|
|
if (IsFile(streamName)) {
|
|
return Host.OpenStreamForRead(streamName);
|
|
}
|
|
|
|
if (streamName == null) {
|
|
return null;
|
|
}
|
|
|
|
// scheme is http
|
|
WebClient client = new WebClient();
|
|
|
|
// Try using default credentials
|
|
try {
|
|
client.Credentials = CredentialCache.DefaultCredentials;
|
|
}
|
|
catch {
|
|
}
|
|
|
|
byte[] fileData = null;
|
|
try {
|
|
fileData = client.DownloadData(streamName);
|
|
}
|
|
catch {
|
|
}
|
|
|
|
if (fileData == null) {
|
|
return null;
|
|
}
|
|
|
|
MemoryStream stream = new MemoryStream(fileData);
|
|
return stream;
|
|
}
|
|
|
|
public override Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext) {
|
|
// only support files, not URIs
|
|
if (!IsFile(streamName)) {
|
|
throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::OpenStreamForWrite");
|
|
}
|
|
|
|
return Host.OpenStreamForWrite(streamName, templateStreamName, ref writeContext);
|
|
}
|
|
|
|
public override void DeleteStream(string streamName) {
|
|
// only support files, not URIs
|
|
if (!IsFile(streamName)) {
|
|
throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Delete");
|
|
}
|
|
|
|
Host.DeleteStream(streamName);
|
|
}
|
|
|
|
// RefreshConfig support - runtime only
|
|
public override bool SupportsRefresh {
|
|
get {return true;}
|
|
}
|
|
|
|
// path support
|
|
public override bool SupportsPath {
|
|
get {return false;}
|
|
}
|
|
|
|
// Do we support location tags?
|
|
public override bool SupportsLocation {
|
|
get {return false;}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|
|
}
|
|
|
|
// prefetch support
|
|
public override bool PrefetchAll(string configPath, string streamName) {
|
|
// If it's a file, we don't need to. Otherwise (e.g. it's from the web), we'll prefetch everything.
|
|
return !IsFile(streamName);
|
|
}
|
|
|
|
public override bool PrefetchSection(string sectionGroupName, string sectionName) {
|
|
return sectionGroupName == "system.net";
|
|
}
|
|
|
|
// we trust machine.config - admins settings do not have security restrictions.
|
|
public override bool IsTrustedConfigPath(string configPath) {
|
|
return configPath == MachineConfigPath;
|
|
}
|
|
|
|
[SecurityPermission(SecurityAction.Assert, ControlEvidence=true)]
|
|
public override void GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady) {
|
|
// Get the stream name as a URL
|
|
string url;
|
|
bool isFile = IsFile(configRecord.StreamName);
|
|
if (isFile) {
|
|
url = UrlPath.ConvertFileNameToUrl(configRecord.StreamName);
|
|
}
|
|
else {
|
|
url = configRecord.StreamName;
|
|
}
|
|
|
|
Evidence evidence = new Evidence();
|
|
|
|
// Add Url evidence, which is simply the URL.
|
|
evidence.AddHostEvidence(new Url(url));
|
|
|
|
// Add Zone evidence - My Computer, Intranet, Internet, etc.
|
|
evidence.AddHostEvidence(Zone.CreateFromUrl(url));
|
|
|
|
// Add Site evidence if the url is http.
|
|
if (!isFile) {
|
|
evidence.AddHostEvidence(Site.CreateFromUrl(url));
|
|
}
|
|
|
|
// Get the resulting permission set.
|
|
permissionSet = SecurityManager.GetStandardSandbox(evidence);
|
|
|
|
// Client host is always ready to return permissions.
|
|
isHostReady = true;
|
|
}
|
|
|
|
//
|
|
// Impersonate for Client Config
|
|
// Use the process identity
|
|
//
|
|
[SecurityPermissionAttribute(SecurityAction.Assert, Flags=SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode)]
|
|
public override IDisposable Impersonate() {
|
|
// Use the process identity
|
|
return WindowsIdentity.Impersonate(IntPtr.Zero);
|
|
}
|
|
|
|
// context support
|
|
public override object CreateDeprecatedConfigContext(string configPath) {
|
|
return null;
|
|
}
|
|
|
|
// CreateConfigurationContext
|
|
//
|
|
// Create the new context
|
|
//
|
|
public override object
|
|
CreateConfigurationContext( string configPath,
|
|
string locationSubPath )
|
|
{
|
|
return new ExeContext(GetUserLevel(configPath), ConfigPaths.ApplicationUri);
|
|
}
|
|
|
|
// GetUserLevel
|
|
//
|
|
// Given a configPath, determine what the user level is?
|
|
//
|
|
private ConfigurationUserLevel GetUserLevel(string configPath)
|
|
{
|
|
ConfigurationUserLevel level;
|
|
|
|
switch (ConfigPathUtility.GetName(configPath)) {
|
|
case MachineConfigName:
|
|
// Machine Level
|
|
level = ConfigurationUserLevel.None;
|
|
break;
|
|
|
|
case ExeConfigName:
|
|
// Exe Level
|
|
level = ConfigurationUserLevel.None;
|
|
break;
|
|
|
|
case LocalUserConfigName:
|
|
// User Level
|
|
level = ConfigurationUserLevel.PerUserRoamingAndLocal;
|
|
break;
|
|
|
|
case RoamingUserConfigName:
|
|
// Roaming Level
|
|
level = ConfigurationUserLevel.PerUserRoaming;
|
|
break;
|
|
|
|
default:
|
|
Debug.Fail("unrecognized configPath " + configPath);
|
|
level = ConfigurationUserLevel.None;
|
|
break;
|
|
}
|
|
|
|
return level;
|
|
}
|
|
|
|
//
|
|
// Create a Configuration object.
|
|
//
|
|
static internal Configuration OpenExeConfiguration(ConfigurationFileMap fileMap, bool isMachine, ConfigurationUserLevel userLevel, string exePath) {
|
|
// validate userLevel argument
|
|
switch (userLevel) {
|
|
default:
|
|
throw ExceptionUtil.ParameterInvalid("userLevel");
|
|
|
|
case ConfigurationUserLevel.None:
|
|
case ConfigurationUserLevel.PerUserRoaming:
|
|
case ConfigurationUserLevel.PerUserRoamingAndLocal:
|
|
break;
|
|
}
|
|
|
|
// validate fileMap arguments
|
|
if (fileMap != null) {
|
|
if (String.IsNullOrEmpty(fileMap.MachineConfigFilename)) {
|
|
throw ExceptionUtil.ParameterNullOrEmpty("fileMap.MachineConfigFilename");
|
|
}
|
|
|
|
ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
|
|
if (exeFileMap != null) {
|
|
switch (userLevel) {
|
|
case ConfigurationUserLevel.None:
|
|
if (String.IsNullOrEmpty(exeFileMap.ExeConfigFilename)) {
|
|
throw ExceptionUtil.ParameterNullOrEmpty("fileMap.ExeConfigFilename");
|
|
}
|
|
|
|
break;
|
|
|
|
case ConfigurationUserLevel.PerUserRoaming:
|
|
if (String.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename)) {
|
|
throw ExceptionUtil.ParameterNullOrEmpty("fileMap.RoamingUserConfigFilename");
|
|
}
|
|
|
|
goto case ConfigurationUserLevel.None;
|
|
|
|
case ConfigurationUserLevel.PerUserRoamingAndLocal:
|
|
if (String.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename)) {
|
|
throw ExceptionUtil.ParameterNullOrEmpty("fileMap.LocalUserConfigFilename");
|
|
}
|
|
|
|
goto case ConfigurationUserLevel.PerUserRoaming;
|
|
}
|
|
}
|
|
}
|
|
|
|
string configPath = null;
|
|
if (isMachine) {
|
|
configPath = MachineConfigPath;
|
|
}
|
|
else {
|
|
switch (userLevel) {
|
|
case ConfigurationUserLevel.None:
|
|
configPath = ExeConfigPath;
|
|
break;
|
|
|
|
case ConfigurationUserLevel.PerUserRoaming:
|
|
configPath = RoamingUserConfigPath;
|
|
break;
|
|
|
|
case ConfigurationUserLevel.PerUserRoamingAndLocal:
|
|
configPath = LocalUserConfigPath;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Configuration configuration = new Configuration(null, typeof(ClientConfigurationHost), fileMap, exePath, configPath);
|
|
|
|
return configuration;
|
|
}
|
|
}
|
|
}
|