From f8e9b4a1b3b6572f92e7d85b7ae6007640562195 Mon Sep 17 00:00:00 2001
From: Lightczx <1686188646@qq.com>
Date: Thu, 30 May 2024 12:36:30 +0800
Subject: [PATCH] fix pipe access control
---
.../Snap.Hutao/Control/Theme/InfoBarOverride.xaml | 2 +-
.../InterProcess/PrivateNamedPipeServer.cs | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/InfoBarOverride.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/InfoBarOverride.xaml
index 4151e2af..76af69ff 100644
--- a/src/Snap.Hutao/Snap.Hutao/Control/Theme/InfoBarOverride.xaml
+++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/InfoBarOverride.xaml
@@ -244,7 +244,7 @@
-
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/InterProcess/PrivateNamedPipeServer.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/InterProcess/PrivateNamedPipeServer.cs
index 2d61d09b..3cb7894e 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/InterProcess/PrivateNamedPipeServer.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/InterProcess/PrivateNamedPipeServer.cs
@@ -4,6 +4,8 @@
using Snap.Hutao.Core.ExceptionService;
using System.IO.Hashing;
using System.IO.Pipes;
+using System.Security.AccessControl;
+using System.Security.Principal;
namespace Snap.Hutao.Core.LifeCycle.InterProcess;
@@ -12,7 +14,7 @@ namespace Snap.Hutao.Core.LifeCycle.InterProcess;
internal sealed partial class PrivateNamedPipeServer : IDisposable
{
private readonly PrivateNamedPipeMessageDispatcher messageDispatcher;
-
+ private readonly RuntimeOptions runtimeOptions;
private readonly NamedPipeServerStream serverStream = new("Snap.Hutao.PrivateNamedPipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
private readonly CancellationTokenSource serverTokenSource = new();
private readonly SemaphoreSlim serverSemaphore = new(1);
@@ -31,6 +33,17 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
{
using (await serverSemaphore.EnterAsync(serverTokenSource.Token).ConfigureAwait(false))
{
+ if (runtimeOptions.IsElevated)
+ {
+ SecurityIdentifier everyOne = new(WellKnownSidType.WorldSid, null);
+ SecurityIdentifier users = new(WellKnownSidType.BuiltinUsersSid, null);
+
+ PipeSecurity pipeSecurity = new();
+ pipeSecurity.AddAccessRule(new PipeAccessRule(everyOne, PipeAccessRights.ReadWrite, AccessControlType.Allow));
+ pipeSecurity.AddAccessRule(new PipeAccessRule(users, PipeAccessRights.ReadWrite, AccessControlType.Allow));
+ serverStream.SetAccessControl(pipeSecurity);
+ }
+
while (!serverTokenSource.IsCancellationRequested)
{
try