我正在寻找在.NET中实现一个命名pipe道的服务/客户端通信,并遇到这个代码 ,当初始化pipe道的服务器端必须build立一个pipe道的安全描述符。 他们这样做:
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作为string或Authenticated Users和Administrators部分。 有什么保证他们会用中文或其他语言来称呼他们呢?
.net – 如何连接windows服务与系统托pipe应用程序
旧的本地应用程序可以在Windows8平板电脑版上运行吗
如何在dotnet核心中运行F#interactive(fsi.exe)? 它是否支持?
VC ++ MFC在不久的将来会过时吗?
使用logonUser后出现UnauthorizedAccessException
(摘自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),AccessControlType.Allow)); // Allow the Administrators group full access to the pipe. pipeSecurity.SetAccessRule(new PipeAccessRule( "Administrators",new SecurityIdentifier(WellKNownSidType.BuiltinAdministratoRSSid,AccessControlType.Allow));
您可以使用WellKNownSidType枚举来获取sid并转换成IdentityReference:
var sid = new SecurityIdentifier(WellKNownSidType.AuthenticatedUserSid,null); var everyone = sid.Translate(typeof(NTAccount)); security.AddAccessRule(new PipeAccessRule(everyone,AccessControlType.Allow));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。