From 05c65fb594db885bc1579874e079519dec98fc8a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 7 Sep 2017 23:31:05 -0400 Subject: nslcd_systemd: Use go 1.9 syscall.RawConn to implement getpeercred() Eh. I'm not really sure how I feel about this change. I feel better about the syscalls that the program makes. But the code is longer. There's more boilerplate. I wish syscall.RawConn let our function return an error that would bubble up. --- nslcd_systemd/nslcd_systemd.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nslcd_systemd/nslcd_systemd.go b/nslcd_systemd/nslcd_systemd.go index df6ca71..2ba9899 100644 --- a/nslcd_systemd/nslcd_systemd.go +++ b/nslcd_systemd/nslcd_systemd.go @@ -67,12 +67,22 @@ func get_socket() (socket net.Listener, err error) { } func getpeercred(conn *net.UnixConn) (cred unix.Ucred, err error) { - file, err := conn.File() + rawconn, err := conn.SyscallConn() if err != nil { return } - defer file.Close() - _cred, err := unix.GetsockoptUcred(int(file.Fd()), unix.SOL_SOCKET, unix.SO_PEERCRED) + var _cred *unix.Ucred + var _err error + err = rawconn.Control(func(fd uintptr) { + _cred, _err = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) + }) + if err != nil { + return + } + if _err != nil { + err = _err + return + } cred = *_cred return } -- cgit v1.2.3