private Configuration(GlobalConfiguration/*!*/ global, LocalConfiguration/*!*/ defaultLocal) { this.global = global; this.defaultLocal = defaultLocal; }
/// <summary> /// Makes a copy (child) of this instance (parent) deeply copying the confgiuration fields. /// </summary> internal PhpConfigurationContext(ApplicationContext/*!*/ applicationContext, string virtualPath, PhpConfigurationContext parent) { Debug.Assert(applicationContext != null); this.virtualPath = virtualPath; this.applicationContext = applicationContext; // section tables are shared: this.sections = parent.sections; this.sealedSections = parent.sealedSections; this.librariesList = parent.librariesList; // configuration records are copied: this.local = (LocalConfiguration)parent.local.DeepCopy(); this.global = (GlobalConfiguration)parent.global.DeepCopy(); }
/// <summary> /// Creates an empty configuration context used as a root context. /// </summary> internal PhpConfigurationContext(ApplicationContext/*!*/ applicationContext, string virtualPath) { Debug.Assert(applicationContext != null); this.virtualPath = virtualPath; this.applicationContext = applicationContext; this.sections = new Dictionary<string, LibrarySection>(); this.sealedSections = new Dictionary<string, string>(); this.librariesList = new LibrariesConfigurationList(); this.local = new LocalConfiguration(); this.global = new GlobalConfiguration(); }
/// <summary> /// Writes Core legacy options and their values to XML text stream. /// Skips options whose values are the same as default values of Phalanger. /// </summary> /// <param name="writer">XML writer.</param> /// <param name="options">A hashtable containing PHP names and option values. Consumed options are removed from the table.</param> /// <param name="writePhpNames">Whether to add "phpName" attribute to option nodes.</param> public static void CoreOptionsToXml(XmlTextWriter writer, Hashtable options, bool writePhpNames) // GENERICS: <string,string> { if (writer == null) throw new ArgumentNullException("writer"); if (options == null) throw new ArgumentNullException("options"); ApplicationConfiguration app = new ApplicationConfiguration(); GlobalConfiguration global = new GlobalConfiguration(); LocalConfiguration local = new LocalConfiguration(); PhpIniXmlWriter ow = new PhpIniXmlWriter(writer, options, writePhpNames); ow.StartSection("compiler"); ow.WriteOption("short_open_tag", "ShortOpenTag", true, app.Compiler.ShortOpenTags); ow.WriteOption("asp_tags", "AspTags", false, app.Compiler.AspTags); ow.StartSection("variables"); //ow.WriteOption("zend.ze1_compatibility_mode", "ZendEngineV1Compatible", false, local.Variables.ZendEngineV1Compatible); ow.WriteOption("register_globals", "RegisterGlobals", false, global.GlobalVariables.RegisterGlobals); ow.WriteOption("register_argc_argv", "RegisterArgcArgv", true, global.GlobalVariables.RegisterArgcArgv); ow.WriteOption("register_long_arrays", "RegisterLongArrays", true, global.GlobalVariables.RegisterLongArrays); ow.WriteOption("variables_order", "RegisteringOrder", "EGPCS", local.Variables.RegisteringOrder); //ow.WriteOption("magic_quotes_gpc", "QuoteGpcVariables", true, global.GlobalVariables.QuoteGpcVariables); ow.WriteOption("magic_quotes_runtime", "QuoteRuntimeVariables", false, local.Variables.QuoteRuntimeVariables); //ow.WriteOption("magic_quotes_sybase", "QuoteInDbManner", false, local.Variables.QuoteInDbManner); ow.WriteOption("unserialize_callback_func", "DeserializationCallback", null, local.Variables.DeserializationCallback); ow.StartSection("output-control"); ow.WriteOption("output_buffering", "OutputBuffering", false, local.OutputControl.OutputBuffering); ow.WriteOption("output_handler", "OutputHandler", null, local.OutputControl.OutputHandler); ow.WriteOption("implicit_flush", "ImplicitFlush", false, local.OutputControl.ImplicitFlush); ow.WriteOption("default_mimetype", "ContentType", "text/html", DefaultMimetype); ow.WriteOption("default_charset", "Charset", "", DefaultCharset); ow.StartSection("request-control"); ow.WriteOption("max_execution_time", "ExecutionTimeout", 30, local.RequestControl.ExecutionTimeout); ow.WriteOption("ignore_user_abort", "IgnoreUserAbort", false, local.RequestControl.IgnoreUserAbort); ow.StartSection("error-control"); ow.WriteEnumOption("error_reporting", "ReportErrors", (int)PhpErrorSet.AllButStrict, (int)local.ErrorControl.ReportErrors, typeof(PhpError)); ow.WriteOption("display_errors", "DisplayErrors", true, local.ErrorControl.DisplayErrors); ow.WriteOption("html_errors", "HtmlMessages", true, local.ErrorControl.HtmlMessages); ow.WriteOption("docref_root", "DocRefRoot", null, local.ErrorControl.DocRefRoot.ToString()); ow.WriteOption("docref_ext", "DocRefExtension", null, local.ErrorControl.DocRefExtension); ow.WriteErrorLog("error_log", null, local.ErrorControl.SysLog, local.ErrorControl.LogFile); ow.WriteOption("log_errors", "EnableLogging", false, local.ErrorControl.EnableLogging); ow.WriteOption("error_prepend_string", "ErrorPrependString", null, local.ErrorControl.ErrorPrependString); ow.WriteOption("error_append_string", "ErrorAppendString", null, local.ErrorControl.ErrorAppendString); ow.StartSection("session-control"); ow.WriteOption("session.auto_start", "AutoStart", false, local.Session.AutoStart); ow.WriteOption("session.save_handler", "Handler", "files", local.Session.Handler.Name); ow.StartSection("assertion"); ow.WriteOption("assert.active", "Active", true, local.Assertion.Active); ow.WriteOption("assert.warning", "ReportWarning", true, local.Assertion.ReportWarning); ow.WriteOption("assert.bail", "Terminate", false, local.Assertion.Terminate); ow.WriteOption("assert.quiet_eval", "Quiet", false, local.Assertion.Quiet); ow.WriteOption("assert.callback", "Callback", null, local.Assertion.Callback); ow.StartSection("safe-mode"); ow.WriteOption("safe_mode", "Enabled", false, global.SafeMode.Enabled); ow.WriteOption("open_basedir", "AllowedPathPrefixes", null, global.SafeMode.GetAllowedPathPrefixesJoin()); ow.WriteOption("safe_mode_exec_dir", "ExecutionDirectory", null, global.SafeMode.ExecutionDirectory); ow.StartSection("posted-files"); ow.WriteOption("file_uploads", "Accept", true, global.PostedFiles.Accept); ow.WriteOption("upload_tmp_dir", "TempPath", null, global.PostedFiles.TempPath); ow.StartSection("file-system"); ow.WriteOption("allow_url_fopen", "AllowUrlFopen", true, local.FileSystem.AllowUrlFopen); ow.WriteOption("default_socket_timeout", "DefaultSocketTimeout", 60, local.FileSystem.DefaultSocketTimeout); ow.WriteOption("user_agent", "UserAgent", null, local.FileSystem.UserAgent); ow.WriteOption("from", "AnonymousFtpPassword", null, local.FileSystem.AnonymousFtpPassword); ow.WriteOption("include_path", "IncludePaths", ".", local.FileSystem.IncludePaths); ow.WriteEnd(); }
/// <summary> /// Creates an instance of <see cref="GlobalConfiguration"/> initialized by values /// copied from the specified instance. /// </summary> /// <param name="source">The configuration from which to copy values.</param> private GlobalConfiguration(GlobalConfiguration/*!*/ source) { Debug.Assert(source != null); this.GlobalVariables = source.GlobalVariables.DeepCopy(); this.Library = source.Library.DeepCopy(); #if !SILVERLIGHT this.PostedFiles = source.PostedFiles.DeepCopy(); this.SafeMode = source.SafeMode.DeepCopy(); #endif this.LastConfigurationModificationTime = source.LastConfigurationModificationTime; }
/// <summary> /// Merges the path with the current working directory /// to get a canonicalized absolute pathname representing the same file. /// </summary> /// <remarks> /// This method is an analogy of <c>main/safe_mode.c: php_checkuid</c>. /// Looks for the file in the <c>include_path</c> and checks for <c>open_basedir</c> restrictions. /// </remarks> /// <param name="path">An absolute or relative path to a file.</param> /// <param name="wrapper">The wrapper found for the specified file or <c>null</c> if the path resolution fails.</param> /// <param name="mode">The checking mode of the <see cref="CheckAccess"/> method (file, directory etc.).</param> /// <param name="options">Additional options for the <see cref="CheckAccess"/> method.</param> /// <returns><c>true</c> if all the resolution and checking passed without an error, <b>false</b> otherwise.</returns> /// <exception cref="PhpException">Security violation - when the target file /// lays outside the tree defined by <c>open_basedir</c> configuration option.</exception> public static bool ResolvePath(ref string path, out StreamWrapper wrapper, CheckAccessMode mode, CheckAccessOptions options) { // Path will contain the absolute path without file:// or the complete URL; filename is the relative path. string filename, scheme = GetSchemeInternal(path, out filename); wrapper = StreamWrapper.GetWrapper(scheme, (StreamOptions)options); if (wrapper == null) { return(false); } if (wrapper.IsUrl) { // Note: path contains the whole URL, filename the same without the scheme:// portion. // What to check more? } else if (scheme != "php") { try { // Filename contains the original path without the scheme:// portion, check for include path. bool isInclude = false; if ((options & CheckAccessOptions.UseIncludePath) > 0) { isInclude = CheckIncludePath(filename, ref path); } // Path will now contain an absolute path (either to an include or actual directory). if (!isInclude) { path = Path.GetFullPath(Path.Combine(ScriptContext.CurrentContext.WorkingDirectory, filename)); } } catch (Exception) { if ((options & CheckAccessOptions.Quiet) == 0) { PhpException.Throw(PhpError.Warning, CoreResources.GetString("stream_filename_invalid", FileSystemUtils.StripPassword(path))); } return(false); } GlobalConfiguration global_config = Configuration.Global; // Note: extensions check open_basedir too -> double check.. if (!global_config.SafeMode.IsPathAllowed(path)) { if ((options & CheckAccessOptions.Quiet) == 0) { PhpException.Throw(PhpError.Warning, CoreResources.GetString("open_basedir_effect", path, global_config.SafeMode.GetAllowedPathPrefixesJoin())); } return(false); } // Replace all '/' with '\'. // path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); Debug.Assert( path.IndexOf(Path.AltDirectorySeparatorChar) == -1 || (Path.AltDirectorySeparatorChar == Path.DirectorySeparatorChar), // on Mono, so ignore it string.Format("'{0}' should not contain '{1}' char.", path, Path.AltDirectorySeparatorChar)); // The file wrapper expects an absolute path w/o the scheme, others expect the scheme://url. if (scheme != "file") { path = String.Format("{0}://{1}", scheme, path); } } return(true); }