set SO_PASSCRED on listening socket to avoid this problem:

4dde1cb060
networking
brl 10 years ago
parent 5c9f8b40ad
commit 93715e7602

@ -42,6 +42,9 @@ func NewServer(address string, factory MsgFactory, log *logging.Logger, handlers
} }
listener, err := net.ListenUnix("unix", &net.UnixAddr{address, "unix"}) listener, err := net.ListenUnix("unix", &net.UnixAddr{address, "unix"})
if err := setPassCred(listener); err != nil {
return nil, errors.New("Failed to set SO_PASSCRED on listening socket: " + err.Error())
}
if err != nil { if err != nil {
md.close() md.close()
return nil, err return nil, err

@ -1,17 +1,16 @@
package ipc package ipc
import ( import (
"net"
"reflect" "reflect"
"syscall" "syscall"
) )
func setPassCred(c net.Conn) error { func setPassCred(c interface{}) error {
fd := reflectFD(c) fd := reflectFD(c)
return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1) return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1)
} }
func reflectFD(c net.Conn) int { func reflectFD(c interface{}) int {
sysfd := extractField(c, "fd", "sysfd") sysfd := extractField(c, "fd", "sysfd")
return int(sysfd.Int()) return int(sysfd.Int())
} }

Loading…
Cancel
Save