@@ -8,6 +8,8 @@ This Source Code Form is subject to the terms of the Mozilla Public
88using System ;
99using System . IO ;
1010using System . IO . Pipes ;
11+ using System . Security . AccessControl ;
12+ using System . Security . Principal ;
1113using System . Text ;
1214using System . Threading ;
1315using System . Threading . Tasks ;
@@ -16,15 +18,25 @@ namespace RepostConfirmationCanceler
1618{
1719 internal static class ProcessCommunicator
1820 {
19- private const string NAMED_PIPE_NAME = "RepostConfirmationCancelerNamedPipe" ;
21+ private const string NAMED_PIPE_NAME_BASE = "RepostConfirmationCancelerNamedPipe" ;
22+
23+ private static string GeneratePipeName ( )
24+ {
25+ WindowsIdentity user = WindowsIdentity . GetCurrent ( ) ;
26+ string sid = user . User . Value ;
27+ return $ "{ NAMED_PIPE_NAME_BASE } _{ sid } ";
28+ }
2029
2130 internal static async void RunNamedPipedServer ( RuntimeContext context )
2231 {
32+ PipeSecurity ps = new PipeSecurity ( ) ;
33+ ps . AddAccessRule ( new PipeAccessRule ( "Everyone" , PipeAccessRights . FullControl , AccessControlType . Allow ) ) ;
34+
2335 context . Logger . Log ( "Start server" ) ;
2436 // FinishTime > DateTime.Nowではなく、trueでも良いが、念のため。
2537 while ( ! context . IsEndTime )
2638 {
27- using ( var pipeServer = new NamedPipeServerStream ( NAMED_PIPE_NAME , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) )
39+ using ( var pipeServer = new NamedPipeServerStream ( GeneratePipeName ( ) , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . Asynchronous , 1024 , 1024 , ps ) )
2840 {
2941 var cancellationTokenSource = new CancellationTokenSource ( ) ;
3042 Task waitTask = pipeServer . WaitForConnectionAsync ( cancellationTokenSource . Token ) ;
@@ -74,7 +86,7 @@ internal static void SendKeepAliveMessage(RuntimeContext context)
7486 context . Logger . Log ( "Start to send keep-alive" ) ;
7587 try
7688 {
77- using ( var pipeClient = new NamedPipeClientStream ( "." , NAMED_PIPE_NAME , PipeDirection . Out ) )
89+ using ( var pipeClient = new NamedPipeClientStream ( "." , GeneratePipeName ( ) , PipeDirection . Out ) )
7890 {
7991 pipeClient . Connect ( 1000 ) ;
8092 using ( var writer = new StreamWriter ( pipeClient ) { AutoFlush = true } )
0 commit comments