summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-09-07 23:31:05 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-09-08 16:55:55 -0400
commit05c65fb594db885bc1579874e079519dec98fc8a (patch)
tree17e0f8d10f5d016dce6027f73b196cab3bca2226
parent18e8503091575892b161a1bf9af0b3f64d6c64f2 (diff)
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.
-rw-r--r--nslcd_systemd/nslcd_systemd.go16
1 files 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
}