diff options
Diffstat (limited to '')
-rw-r--r-- | git_hooks_handle.go | 27 | ||||
-rw-r--r-- | ssh_handle_receive_pack.go | 33 |
2 files changed, 29 insertions, 31 deletions
diff --git a/git_hooks_handle.go b/git_hooks_handle.go index 3719933..91f1894 100644 --- a/git_hooks_handle.go +++ b/git_hooks_handle.go @@ -7,12 +7,13 @@ import ( "fmt" "net" "os" + "path/filepath" "syscall" ) var ( - err_get_fd = errors.New("Unable to get file descriptor") - err_get_ucred = errors.New("Failed getsockopt") + err_get_fd = errors.New("Unable to get file descriptor") + err_get_ucred = errors.New("Failed getsockopt") ) func hooks_handle_connection(conn net.Conn) { @@ -38,10 +39,10 @@ func hooks_handle_connection(conn net.Conn) { return } - deployer_chan, ok := hooks_cookie_deployer.Load(string(cookie)) + pack_to_hook, ok := pack_to_hook_by_cookie.Load(string(cookie)) if !ok { conn.Write([]byte{1}) - fmt.Fprintln(conn, "Invalid cookie") + fmt.Fprintln(conn, "Invalid handler cookie") return } @@ -71,14 +72,18 @@ func hooks_handle_connection(conn net.Conn) { args = append(args, arg.String()) } - callback := make(chan struct{}) - - deployer_chan <- hooks_cookie_deployer_return{ - args: args, - callback: callback, - conn: conn, + switch filepath.Base(args[0]) { + case "pre-receive": + if pack_to_hook.direct_access { + conn.Write([]byte{0}) + } else { + conn.Write([]byte{1}) + fmt.Fprintln(conn, "Non-maintainer push access not implemented yet") + } + default: + conn.Write([]byte{1}) + fmt.Fprintln(conn, "Invalid hook:", args[0]) } - <-callback } func serve_git_hooks(listener net.Listener) error { diff --git a/ssh_handle_receive_pack.go b/ssh_handle_receive_pack.go index 85655b1..c680011 100644 --- a/ssh_handle_receive_pack.go +++ b/ssh_handle_receive_pack.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "errors" "fmt" - "net" "os" "os/exec" @@ -14,13 +13,14 @@ import ( var err_unauthorized_push = errors.New("You are not authorized to push to this repository") -type hooks_cookie_deployer_return struct { - args []string - callback chan struct{} - conn net.Conn +type pack_to_hook_t struct { + session *glider_ssh.Session + pubkey string + direct_access bool + repo_path string } -var hooks_cookie_deployer = cmap.ComparableMap[string, chan hooks_cookie_deployer_return]{} +var pack_to_hook_by_cookie = cmap.Map[string, pack_to_hook_t]{} func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_identifier string) (err error) { repo_path, access, err := get_repo_path_perms_from_ssh_path_pubkey(session.Context(), repo_identifier, pubkey) @@ -33,9 +33,13 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide fmt.Fprintln(session.Stderr(), "Error while generating cookie:", err) } - deployer_channel := make(chan hooks_cookie_deployer_return) - hooks_cookie_deployer.Store(cookie, deployer_channel) - defer hooks_cookie_deployer.Delete(cookie) + pack_to_hook_by_cookie.Store(cookie, pack_to_hook_t{ + session: &session, + pubkey: pubkey, + direct_access: access, + repo_path: repo_path, + }) + defer pack_to_hook_by_cookie.Delete(cookie) proc := exec.CommandContext(session.Context(), "git-receive-pack", repo_path) proc.Env = append(os.Environ(), @@ -52,17 +56,6 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide return err } - deployer := <-deployer_channel - - if access { - deployer.conn.Write([]byte{0}) - } else { - deployer.conn.Write([]byte{1}) - fmt.Fprintln(deployer.conn, "Hi! We don't support pushing from non-authorized users yet. This will be implemented soon.") - } - - deployer.callback <- struct{}{} - err = proc.Wait() if exitError, ok := err.(*exec.ExitError); ok { fmt.Fprintln(session.Stderr(), "Process exited with error", exitError.ExitCode()) |