diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-17 00:40:15 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-17 00:40:15 +0800 |
commit | 54125fb6438e492e2bc1cf4b1c49f4ac94138ed6 (patch) | |
tree | d7b6d01cb82192d7af819c033ee7cabd63fa0d85 /git_hooks.go | |
parent | TODO: Add accessibility notes (diff) | |
download | forge-54125fb6438e492e2bc1cf4b1c49f4ac94138ed6.tar.gz forge-54125fb6438e492e2bc1cf4b1c49f4ac94138ed6.tar.zst forge-54125fb6438e492e2bc1cf4b1c49f4ac94138ed6.zip |
git_hooks{.go,_client}: Add stub for git hook clients
Diffstat (limited to 'git_hooks.go')
-rw-r--r-- | git_hooks.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/git_hooks.go b/git_hooks.go new file mode 100644 index 0000000..86300cb --- /dev/null +++ b/git_hooks.go @@ -0,0 +1,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 +} |