允许远程桌面用户访问全局 Windows 互斥体

问题描述 投票:0回答:1

我的环境:

  • 安装了远程桌面服务的 Windows Server 2012 R2。
  • 用C编程

问题:

  1. 用户 U1 通过 RDP 连接到 Windows Server 并创建全局互斥体 (CreateMutex 带有 Global\ 前缀)

    • 用户 U1 创建具有以下权限的全局 Windows 互斥锁:
      • 创造者
      • 系统
      • 管理员
  2. 用户 U2 通过 RDP 连接到 Windows Server 并尝试获取 全局互斥体

  3. U2 由于缺乏访问权限而失败(因为 U2 不是管理员,不是 一个系统,他也不是创造者)

    • 收到“访问被拒绝”

我尝试通过为当前 AD 域用户添加一项权限来解决该问题,并且成功了。

这个解决方案足够安全吗?换句话说,授予访问权限以允许多个 RDP 用户访问互斥锁的正确方法是什么?

谢谢你

c windows winapi mutex rdp
1个回答
0
投票

我将此代码用于远程桌面和互斥体。 MutexSecurity 对于访问其他 RDP 会话上已打开的互斥体是必需的。

        var mSec = new System.Security.AccessControl.MutexSecurity();

        // Add a rule that grants the current user the 
        // right to enter or release the mutex.
        System.Security.Principal.SecurityIdentifier everyone = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);

        var rule = new System.Security.AccessControl.MutexAccessRule(everyone,
            System.Security.AccessControl.MutexRights.Synchronize | System.Security.AccessControl.MutexRights.Modify,
            System.Security.AccessControl.AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the 
        // right to change permissions on the mutex.
        rule = new System.Security.AccessControl.MutexAccessRule(everyone,
            System.Security.AccessControl.MutexRights.ChangePermissions,
            System.Security.AccessControl.AccessControlType.Deny);
        mSec.AddAccessRule(rule);

        using (var mutex = new System.Threading.Mutex(false, $"Global\\AnDietzeMutex", out bool createdNew, mSec)); {
        }
© www.soinside.com 2019 - 2024. All rights reserved.