private NamedPipeProcessMediator( RemoteSessionNamedPipeServer namedPipeServer) : base(false) { if (namedPipeServer == null) { throw new PSArgumentNullException("namedPipeServer"); } _namedPipeServer = namedPipeServer; // Create transport reader/writers from named pipe. originalStdIn = namedPipeServer.TextReader; originalStdOut = new OutOfProcessTextWriter(namedPipeServer.TextWriter); originalStdErr = new NamedPipeErrorTextWriter(namedPipeServer.TextWriter); // Flow impersonation if requested. WindowsIdentity currentIdentity = null; try { currentIdentity = WindowsIdentity.GetCurrent(); } catch (System.Security.SecurityException) { } _windowsIdentityToImpersonate = ((currentIdentity != null) && (currentIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation)) ? currentIdentity : null; }
internal StreamingMessage ProcessWorkerInitRequest(StreamingMessage request) { var workerInitRequest = request.WorkerInitRequest; Environment.SetEnvironmentVariable("AZUREPS_HOST_ENVIRONMENT", $"AzureFunctions/{workerInitRequest.HostVersion}"); StreamingMessage response = NewStreamingMessageTemplate( request.RequestId, StreamingMessage.ContentOneofCase.WorkerInitResponse, out StatusResult status); response.WorkerInitResponse.Capabilities.Add("RpcHttpBodyOnly", "true"); // If the environment variable is set, spin up the custom named pipe server. // This is typically used for debugging. It will throw a friendly exception if the // pipe name is not a valid pipename. string pipeName = Environment.GetEnvironmentVariable("PSWorkerCustomPipeName"); if (!string.IsNullOrEmpty(pipeName)) { RpcLogger.WriteSystemLog(LogLevel.Trace, string.Format(PowerShellWorkerStrings.SpecifiedCustomPipeName, pipeName)); RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeName); } return(response); }
public void TestCustomPipeNameCreationTooLongOnNonWindows() { var longPipeName = "DoggoipsumwaggywagssmolborkingdoggowithalongsnootforpatsdoingmeafrightenporgoYapperporgolongwatershoobcloudsbigolpupperlengthboy"; if (!Platform.IsWindows) { Assert.Throws <InvalidOperationException>(() => RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(longPipeName)); } else { RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(longPipeName); Assert.True(File.Exists(GetPipePath(longPipeName))); } }
public void TestCustomPipeNameCreation() { string pipeNameForFirstCall = Path.GetRandomFileName(); string pipeNameForSecondCall = Path.GetRandomFileName(); RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeNameForFirstCall); Assert.True(File.Exists(GetPipePath(pipeNameForFirstCall))); // The second call to this method would override the first named pipe. RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeNameForSecondCall); Assert.True(File.Exists(GetPipePath(pipeNameForSecondCall))); // Previous pipe should have been cleaned up. Assert.False(File.Exists(GetPipePath(pipeNameForFirstCall))); }
private NamedPipeProcessMediator( RemoteSessionNamedPipeServer namedPipeServer) : base(false) { if (namedPipeServer == null) { throw new PSArgumentNullException("namedPipeServer"); } _namedPipeServer = namedPipeServer; // Create transport reader/writers from named pipe. originalStdIn = namedPipeServer.TextReader; originalStdOut = new OutOfProcessTextWriter(namedPipeServer.TextWriter); originalStdErr = new NamedPipeErrorTextWriter(namedPipeServer.TextWriter); #if !UNIX // Flow impersonation as needed. Utils.TryGetWindowsImpersonatedIdentity(out _windowsIdentityToImpersonate); #endif }
internal StreamingMessage ProcessWorkerInitRequest(StreamingMessage request) { StreamingMessage response = NewStreamingMessageTemplate( request.RequestId, StreamingMessage.ContentOneofCase.WorkerInitResponse, out StatusResult status); // If the environment variable is set, spin up the custom named pipe server. // This is typically used for debugging. It will throw a friendly exception if the // pipe name is not a valid pipename. string pipeName = Environment.GetEnvironmentVariable("PSWorkerCustomPipeName"); if (!string.IsNullOrEmpty(pipeName)) { RpcLogger.WriteSystemLog(LogLevel.Trace, string.Format(PowerShellWorkerStrings.SpecifiedCustomPipeName, pipeName)); RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeName); } return(response); }
internal static void Run( string initialCommand, RemoteSessionNamedPipeServer namedPipeServer) { lock (SyncObject) { if (s_singletonInstance != null && !s_singletonInstance.IsDisposed) { Dbg.Assert(false, "Run should not be called multiple times, unless the singleton was disposed."); return; } s_singletonInstance = new NamedPipeProcessMediator(namedPipeServer); } #if !CORECLR // AppDomain is not available in CoreCLR AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomainUnhandledException); #endif s_singletonInstance.Start(initialCommand, new PSRemotingCryptoHelperServer(), namedPipeServer.ConfigurationName); }
internal static void Run( string initialCommand, RemoteSessionNamedPipeServer namedPipeServer) { lock (SyncObject) { if (s_singletonInstance != null && !s_singletonInstance.IsDisposed) { Dbg.Assert(false, "Run should not be called multiple times, unless the singleton was disposed."); return; } s_singletonInstance = new NamedPipeProcessMediator(namedPipeServer); } s_singletonInstance.Start( initialCommand: initialCommand, cryptoHelper: new PSRemotingCryptoHelperServer(), workingDirectory: null, configurationName: namedPipeServer.ConfigurationName); }
internal static void Run( string initialCommand, RemoteSessionNamedPipeServer namedPipeServer) { lock (SyncObject) { if (s_singletonInstance != null && !s_singletonInstance.IsDisposed) { Dbg.Assert(false, "Run should not be called multiple times, unless the singleton was disposed."); return; } s_singletonInstance = new NamedPipeProcessMediator(namedPipeServer); } #if !CORECLR // AppDomain is not available in CoreCLR AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomainUnhandledException); #endif s_singletonInstance.Start(initialCommand, new PSRemotingCryptoHelperServer(), namedPipeServer.ConfigurationName); }
private NamedPipeProcessMediator( RemoteSessionNamedPipeServer namedPipeServer) : base(false) { if (namedPipeServer == null) { throw new PSArgumentNullException("namedPipeServer"); } _namedPipeServer = namedPipeServer; // Create transport reader/writers from named pipe. originalStdIn = namedPipeServer.TextReader; originalStdOut = new OutOfProcessTextWriter(namedPipeServer.TextWriter); originalStdErr = new NamedPipeErrorTextWriter(namedPipeServer.TextWriter); // Flow impersonation if requested. WindowsIdentity currentIdentity = null; try { currentIdentity = WindowsIdentity.GetCurrent(); } catch (System.Security.SecurityException) { } _windowsIdentityToImpersonate = ((currentIdentity != null) && (currentIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation)) ? currentIdentity : null; }