aboutsummaryrefslogtreecommitdiff
path: root/git_hooks.go
blob: 86300cb2e35754a540c794d8330a496222659a1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import (
	"errors"
	"fmt"
	"net"
	"os"
	"syscall"
)

var err_not_unixconn = errors.New("Not a unix connection")

func hooks_handle_connection(conn net.Conn) (err error) {
	defer conn.Close()

	unix_conn, ok := conn.(*net.UnixConn)
	if !ok {
		return err_not_unixconn
	}

	fd, err := unix_conn.File()
	if err != nil {
		return err
	}
	defer fd.Close()

	ucred, err := get_ucred(fd)
	if err != nil {
		return err
	}

	pid := ucred.Pid

	_ = pid

	return nil
}

func get_ucred(fd *os.File) (*syscall.Ucred, error) {
	ucred, err := syscall.GetsockoptUcred(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
	if err != nil {
		return nil, fmt.Errorf("failed to get credentials: %v", err)
	}
	return ucred, nil
}