npipe icon indicating copy to clipboard operation
npipe copied to clipboard

Support non-nil SecurityAttributes

Open chowey opened this issue 11 years ago • 3 comments

I want to create a named pipe with non-default SecurityAttributes. But this is impossible with the current code. The pipe is created with this function:

// createPipe is a helper function to make sure we always create pipes
// with the same arguments, since subsequent calls to create pipe need
// to use the same arguments as the first one. If first is set, fail
// if the pipe already exists.
func createPipe(address string, first bool) (syscall.Handle, error) {
    n, err := syscall.UTF16PtrFromString(address)
    if err != nil {
        return 0, err
    }
    mode := uint32(pipe_access_duplex | syscall.FILE_FLAG_OVERLAPPED)
    if first {
        mode |= file_flag_first_pipe_instance
    }
    return createNamedPipe(n,
        mode,
        pipe_type_byte,
        pipe_unlimited_instances,
        512, 512, 0, nil)
}

I need to specify some SecurityAttributes in that last argument in the createNamedPipe call.

Is there a way to make that something other than nil? Perhaps export it to a global var, like so:

var SecurityAttributes *syscall.SecurityAttributes = nil

func createPipe(address string, first bool) (syscall.Handle, error) {
    // ...
    return createNamedPipe(n,
        mode,
        pipe_type_byte,
        pipe_unlimited_instances,
        512, 512, 0, SecurityAttributes)
}

Not saying that's the best solution, but it wouldn't break anything.

chowey avatar Jul 22 '14 06:07 chowey

That's certainly something that seems like it should be supported. It wouldn't be hard to add another method that lets you set security attributes when the pipe gets created. I'll give it some thought. I don't think a global variable is the best idea.

natefinch avatar Jul 29 '14 14:07 natefinch

I agree with that.

chowey avatar Jul 29 '14 17:07 chowey

@natefinch/@chowey : Can you provide an example for this?

anvik avatar Aug 19 '20 18:08 anvik