java - 如何为CreateNamedPipe指定SECURITY_ATTRIBUTES?

标签 java jna named-pipes

我一直在为 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/

相关文章:

java - 从 Java 调用扫描仪 Win32 DLL

java - JNA 数组和指针

java - 使用 JNA-Ptrace 在 Linux 中获取有关外部进程的信息?

C++ 使用 Windows 命名管道

收到信号 SIGTERM 后关闭 FIFO

java - 如何在aws上继续运行java应用程序?

java - 简单的 Java IRC 客户端

java - 为什么我在 Android SDK 中计算的百分比变成负值?

java - @请求参数 : Can not get the 2nd inputted request parameters

c++ - 在不同平台上通过管道传输数据的最佳和安全方式