Esempio n. 1
0
func getUcred(fd int) (uint32, uint32, int32, error) {
	cred, err := syscall.GetsockoptUcred(fd, syscall.SOL_SOCKET, syscall.SO_PEERCRED)
	if err != nil {
		return 0, 0, -1, err
	}

	return cred.Uid, cred.Gid, cred.Pid, nil
}
Esempio n. 2
0
func getPid(conn *net.UnixConn) (int32, error) {
	fd := extractUnderlyingFd(conn)
	cred, err := syscall.GetsockoptUcred(fd, syscall.SOL_SOCKET, syscall.SO_PEERCRED)
	if err != nil {
		return -1, err
	}

	return cred.Pid, nil
}
Esempio n. 3
0
File: socket.go Progetto: droyo/styx
// Return the uid/gid of the other side of a unix connection.
// This may have to be factored out into OS-specific syscalls.
func getpeereid(conn interface{}) (uid, gid string, err error) {
	sock, ok := conn.(*net.UnixConn)
	if !ok {
		return "", "", errSocketConn
	}
	file, err := sock.File()
	if err != nil {
		return "", "", err
	}

	fd := int(file.Fd())
	acct, err := syscall.GetsockoptUcred(fd, syscall.SOL_SOCKET, syscall.SO_PEERCRED)
	file.Close()
	if err != nil {
		return "", "", err
	}

	uid = strconv.FormatUint(uint64(acct.Uid), 10)
	gid = strconv.FormatUint(uint64(acct.Gid), 10)
	return uid, gid, nil
}