From 0e112aec65c4c36a36c1df9ecfb87b20ad1d7f38 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 05 Apr 2025 20:39:08 +0800 Subject: [PATCH] packPasses shall no longer be a global variable --- git_hooks_handle_linux.go | 2 +- git_hooks_handle_other.go | 2 +- server.go | 4 ++++ ssh_handle_receive_pack.go | 8 ++------ diff --git a/git_hooks_handle_linux.go b/git_hooks_handle_linux.go index fde4c7e98599266050728b967c5a26963249a426..097f236ac2cc7b86b2752cfb9a6fea9ef33cd995 100644 --- a/git_hooks_handle_linux.go +++ b/git_hooks_handle_linux.go @@ -77,7 +77,7 @@ } { var ok bool - packPass, ok = packPasses.Load(misc.BytesToString(cookie)) + packPass, ok = s.packPasses.Load(misc.BytesToString(cookie)) if !ok { if _, err = conn.Write([]byte{1}); err != nil { return diff --git a/git_hooks_handle_other.go b/git_hooks_handle_other.go index 8b99285072967aea282a3f3b60e1a38a40323357..687bd8f1c115c921ef519c8a67f2ad643aefcdfb 100644 --- a/git_hooks_handle_other.go +++ b/git_hooks_handle_other.go @@ -55,7 +55,7 @@ } { var ok bool - packPass, ok = packPasses.Load(misc.BytesToString(cookie)) + packPass, ok = s.packPasses.Load(misc.BytesToString(cookie)) if !ok { if _, err = conn.Write([]byte{1}); err != nil { return diff --git a/server.go b/server.go index 71e123263da9783b7dc9bb537c3dd8eaa146604e..c99596886f89609b44e908e284fc24691dccd9a1 100644 --- a/server.go +++ b/server.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/jackc/pgx/v5/pgxpool" + "go.lindenii.runxiyu.org/lindenii-common/cmap" goSSH "golang.org/x/crypto/ssh" ) @@ -27,4 +28,7 @@ serverPubkeyString string serverPubkeyFP string serverPubkey goSSH.PublicKey + + // packPasses contains hook cookies mapped to their packPass. + packPasses cmap.Map[string, packPass] } diff --git a/ssh_handle_receive_pack.go b/ssh_handle_receive_pack.go index 317609f8c260da152b7b0df5330dbe0b7b5dd396..33262e4a3bd04998d00bed8bfbc010e87be1e57f 100644 --- a/ssh_handle_receive_pack.go +++ b/ssh_handle_receive_pack.go @@ -11,7 +11,6 @@ "os/exec" gliderSSH "github.com/gliderlabs/ssh" "github.com/go-git/go-git/v5" - "go.lindenii.runxiyu.org/lindenii-common/cmap" ) // packPass contains information known when handling incoming SSH connections @@ -29,9 +28,6 @@ groupPath []string repoName string contribReq string } - -// packPasses contains hook cookies mapped to their packPass. -var packPasses = cmap.Map[string, packPass]{} // sshHandleRecvPack handles attempts to push to repos. func (s *server) sshHandleRecvPack(session gliderSSH.Session, pubkey, repoIdentifier string) (err error) { @@ -95,7 +91,7 @@ if err != nil { fmt.Fprintln(session.Stderr(), "Error while generating cookie:", err) } - packPasses.Store(cookie, packPass{ + s.packPasses.Store(cookie, packPass{ session: session, pubkey: pubkey, directAccess: directAccess, @@ -108,7 +104,7 @@ repo: repo, contribReq: contribReq, userType: userType, }) - defer packPasses.Delete(cookie) + defer s.packPasses.Delete(cookie) // The Delete won't execute until proc.Wait returns unless something // horribly wrong such as a panic occurs. -- 2.48.1