summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
}