natefinch / npipe

A Windows named pipe implementation written in pure Go.
MIT License
297 stars 73 forks source link

Support non-nil SecurityAttributes #5

Open chowey opened 10 years ago

chowey commented 10 years ago

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.

natefinch commented 10 years ago

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.

chowey commented 10 years ago

I agree with that.

anvik commented 3 years ago

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