C# NET中安全标识的本地化

C# NET中安全标识的本地化,c#,.net,windows,security,sid,C#,.net,Windows,Security,Sid,我想在.NET中为服务/客户机通信实现一个命名管道,但在初始化管道的服务器端时遇到了这个问题,因此必须为管道设置一个安全描述符。他们是这样做的: PipeSecurity pipeSecurity = new PipeSecurity(); // Allow Everyone read and write access to the pipe. pipeSecurity.SetAccessRule(new PipeAccessRule("Authenticated Users", Pi

我想在.NET中为服务/客户机通信实现一个命名管道,但在初始化管道的服务器端时遇到了这个问题,因此必须为管道设置一个安全描述符。他们是这样做的:

PipeSecurity pipeSecurity = new PipeSecurity();

// Allow Everyone read and write access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule("Authenticated Users",
    PipeAccessRights.ReadWrite, AccessControlType.Allow));

// Allow the Administrators group full access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule("Administrators",
    PipeAccessRights.FullControl, AccessControlType.Allow));
但我正在研究它,我关心的是将SID指定为字符串,或
经过身份验证的用户
管理员
部分。有什么保证可以用中文或其他语言来称呼他们?

(摘自OP的原始问题)

我想出了一个替代方案:

PipeSecurity pipeSecurity = new PipeSecurity();

// Allow Everyone read and write access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule(
    "Authenticated Users",
    new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null),   
    PipeAccessRights.ReadWrite, AccessControlType.Allow));

// Allow the Administrators group full access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule(
    "Administrators",
    new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null),   
    PipeAccessRights.FullControl, AccessControlType.Allow));

您可以使用WellKnownSidType枚举获取sid并转换为IdentityReference:

        var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
        var everyone = sid.Translate(typeof(NTAccount));
        security.AddAccessRule(new PipeAccessRule(everyone, PipeAccessRights.ReadWrite, AccessControlType.Allow));

好啊我自己证实了。这似乎是可行的。你应该考虑把这个问题分成一个合适的问题/答案对。是的,你可以回答你自己的问题。答案是提取的。将在OP发布或请求时删除。这对我不起作用,没有重载会占用字符串和
SecurityIdentifier
。删除字符串文本“Authenticated Users”和“Administrators”“Everyone”不是一个好主意。您可能至少需要
WellKnownSidType.AuthenticatedUserSid
。除了偏执狂之外,你使用
WorldSid
(每个人)有什么特别的原因吗?没错!当你遇到未知的安全问题时,每个人都是一个好主意,使用它可以让你通过一个健全的测试,确保你的代码正常工作,然后你可以缩小真正需要的安全级别。