gpt4 book ai didi

java - 如何为CreateNamedPipe指定SECURITY_ATTRIBUTES?

转载 作者:太空宇宙 更新时间:2023-11-04 12:29:14 28 4
gpt4 key购买 nike

我一直在为 CreateNamedPipe 方法指定 SECURITY_ATTRIBUTES (最后一个参数)。我希望允许每个人完全访问。

我能汇编的最深入的代码是这样的:

public static HANDLE CreateNamedPipe(String pipeName, PipeDirection pipeDirection, int maxConnections) throws NamedPipeException {
WinBase.SECURITY_ATTRIBUTES saAttr = new WinBase.SECURITY_ATTRIBUTES();
saAttr.dwLength = new WinDef.DWORD(saAttr.size());
saAttr.bInheritHandle = true;
saAttr.lpSecurityDescriptor = null; // it gives default access rights. I need full control for everyone

HANDLE handle = Kernel32.INSTANCE.CreateNamedPipe(pipeName,
pipeDirection.getValue(),
WinBase.PIPE_TYPE_BYTE | WinBase.PIPE_WAIT,
maxConnections,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
0,
saAttr);

int error = Kernel32.INSTANCE.GetLastError();
if(error != 0) {
throw new NamedPipeException(error);
}
return handle;
}

lpSecurityDescriptor 设置为 null 会提供默认访问权限,但我希望每个人都能完全控制。

最佳答案

这并不完全是完整的答案,但我希望它有所帮助。

如果您不想对 saAttr 执行任何操作,则只需将 null 作为最后一个参数(而不是 saAttr),这样管道就会获得默认的安全描述符。引用 Microsoft(https://msdn.microsoft.com/en-us/library/windows/desktop/aa365150(v=vs.85).aspxlpSecurityAttributes):

The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.

关于java - 如何为CreateNamedPipe指定SECURITY_ATTRIBUTES?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38033156/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com