/////////////////////////////////////////////////////////////////////// public static ReturnCode GetCertificate2( string fileName, ref X509Certificate2 certificate2, ref Result error ) { X509Certificate certificate = null; if (GetCertificate(fileName, ref certificate, ref error) == ReturnCode.Ok) { if (certificate != null) { try { certificate2 = new X509Certificate2(certificate); return(ReturnCode.Ok); } catch (Exception e) { error = e; } } else { error = "invalid certificate"; } } #if DEBUG if (!PathOps.IsSameFile( Interpreter.GetActive(), fileName, GlobalState.GetAssemblyLocation())) #endif { TraceOps.DebugTrace(String.Format( "GetCertificate2: file {0} query failure, error = {1}", FormatOps.WrapOrNull(fileName), FormatOps.WrapOrNull(true, true, error)), typeof(CertificateOps).Name, TracePriority.SecurityError); } return(ReturnCode.Error); }
/////////////////////////////////////////////////////////////////////////////////////////////// public static bool MatchFileName( Interpreter interpreter, string path1, string path2 ) { // // BUGBUG: This might be too slow? // if (PathOps.HasPathWildcard(path2)) { return(StringOps.Match( interpreter, StringOps.DefaultMatchMode, path1, path2, PathOps.NoCase)); } else { return(PathOps.IsSameFile(interpreter, path1, path2)); } }
/////////////////////////////////////////////////////////////////////// #region Public Certificate Methods public static ReturnCode GetCertificate( string fileName, ref X509Certificate certificate, ref Result error ) { if (!String.IsNullOrEmpty(fileName)) { try { certificate = X509Certificate.CreateFromSignedFile( fileName); return(ReturnCode.Ok); } catch (Exception e) { error = e; } } else { error = "invalid file name"; } #if DEBUG if (!PathOps.IsSameFile( Interpreter.GetActive(), fileName, GlobalState.GetAssemblyLocation())) #endif { TraceOps.DebugTrace(String.Format( "GetCertificate: file {0} query failure, error = {1}", FormatOps.WrapOrNull(fileName), FormatOps.WrapOrNull(true, true, error)), typeof(CertificateOps).Name, TracePriority.SecurityError); } return(ReturnCode.Error); }
public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Result result ) { ReturnCode code; if (interpreter != null) { if (arguments != null) { if (arguments.Count >= 2) { OptionDictionary options = new OptionDictionary( new IOption[] { new Option(null, OptionFlags.MustHaveObjectValue, Index.Invalid, Index.Invalid, "-clientdata", null), new Option(null, OptionFlags.MustHaveObjectValue, Index.Invalid, Index.Invalid, "-data", null), new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-nocase", null), new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-keeplibrary", null), new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-nocomplain", null), new Option(null, OptionFlags.MustHaveMatchModeValue, Index.Invalid, Index.Invalid, "-match", new Variant(StringOps.DefaultUnloadMatchMode)), new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, Option.EndOfOptions, null) }); int argumentIndex = Index.Invalid; code = interpreter.GetOptions(options, arguments, 0, 1, Index.Invalid, false, ref argumentIndex, ref result); if (code == ReturnCode.Ok) { // // NOTE: There should be a minimum of one and a maximum // of three arguments after the final option. // if ((argumentIndex != Index.Invalid) && ((argumentIndex + 3) >= arguments.Count)) { string path = ((argumentIndex + 2) < arguments.Count) ? (string)arguments[argumentIndex + 2] : String.Empty; Interpreter slaveInterpreter = null; code = interpreter.GetNestedSlaveInterpreter( path, LookupFlags.Interpreter, false, ref slaveInterpreter, ref result); if (code == ReturnCode.Ok) { Variant value = null; IClientData localClientData = clientData; if (options.IsPresent("-clientdata", ref value)) { IObject @object = (IObject)value.Value; if ((@object.Value == null) || (@object.Value is IClientData)) { localClientData = (IClientData)@object.Value; } else { result = "option value has invalid clientData"; code = ReturnCode.Error; } } if (code == ReturnCode.Ok) { if (options.IsPresent("-data", ref value)) { IObject @object = (IObject)value.Value; localClientData = _Public.ClientData.WrapOrReplace( localClientData, @object.Value); } MatchMode mode = StringOps.DefaultUnloadMatchMode; if (options.IsPresent("-match", ref value)) { mode = (MatchMode)value.Value; } bool noCase = false; if (options.IsPresent("-nocase")) { noCase = true; } if (slaveInterpreter.HasPlugins(ref result)) { string fileName = PathOps.ResolveFullPath( interpreter, arguments[argumentIndex]); if (!String.IsNullOrEmpty(fileName)) { string typeName = null; if ((argumentIndex + 1) < arguments.Count) { typeName = arguments[argumentIndex + 1]; } // // NOTE: Grab the plugin flags to match from the target // interpreter and add the Demand flag to them. // PluginFlags pluginFlags = slaveInterpreter.PluginFlags | PluginFlags.Demand; // // FIXME: PRI 4: Threading. // bool unload = false; StringList list = slaveInterpreter.CopyPluginKeys(); foreach (string name in list) { IPluginData pluginData = slaveInterpreter.GetPluginData(name); // // NOTE: Check that this plugin represents a loaded // assembly. // if (pluginData != null) { if ((pluginData.FileName != null) && PathOps.IsSameFile(interpreter, pluginData.FileName, fileName)) { if (String.IsNullOrEmpty(typeName) || StringOps.Match(interpreter, mode, pluginData.TypeName, typeName, noCase) || StringOps.Match(interpreter, mode, pluginData.Name, typeName, noCase)) { code = slaveInterpreter.UnloadPlugin( name, localClientData, pluginFlags, ref result); if (code == ReturnCode.Ok) { unload = true; } // // NOTE: Stop as soon as we match and // attempt to unload a plugin, // whether or not we actually // unloaded it. We always halt // on errors and since we only // support unloading a single // plugin at a time (even if // there are multiple plugins // contained in a particular // assembly file), we know it // is safe to stop now. // break; } } } } if ((code == ReturnCode.Ok) && !unload) { if (typeName != null) { result = String.Format( "type \"{0}\" and file \"{1}\" have never been loaded", typeName, fileName); } else { result = String.Format( "file \"{0}\" has never been loaded", fileName); } code = ReturnCode.Error; } } else { result = "invalid file name"; code = ReturnCode.Error; } } else { code = ReturnCode.Error; } } } } else { if ((argumentIndex != Index.Invalid) && Option.LooksLikeOption(arguments[argumentIndex])) { result = OptionDictionary.BadOption(options, arguments[argumentIndex]); } else { result = "wrong # args: should be \"unload ?options? fileName ?packageName? ?interp?\""; } code = ReturnCode.Error; } } } else { result = "wrong # args: should be \"unload ?options? fileName ?packageName? ?interp?\""; code = ReturnCode.Error; } } else { result = "invalid argument list"; code = ReturnCode.Error; } } else { result = "invalid interpreter"; code = ReturnCode.Error; } return(code); }