Skip to content

Commit

Permalink
Enable Wire 2 for Internal SSH Server (go-gitea#20616)
Browse files Browse the repository at this point in the history
- Git only decides to use the Wire 2 protocol when `git
{receive,upload}-pack` receive the `GIT_PROTOCOL` environment with as
value `version=2`. Currently the internal SSH Server wasn't passing this
environment through. The `gitea serv` code already passed all received
environments to the git command, so no code changes there.
  • Loading branch information
Gusted authored and Sysoev, Vladimir committed Aug 10, 2022
1 parent f7eca50 commit e081930
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,21 @@ func sessionHandler(session ssh.Session) {
ctx, cancel := context.WithCancel(session.Context())
defer cancel()

gitProtocol := ""
for _, env := range session.Environ() {
if strings.HasPrefix(env, "GIT_PROTOCOL=") {
// The value would be version=2, so using normal split doesn't work here.
gitProtocol = strings.SplitN(env, "=", 2)[1]
break
}
}

cmd := exec.CommandContext(ctx, setting.AppPath, args...)
cmd.Env = append(
os.Environ(),
"SSH_ORIGINAL_COMMAND="+command,
"SKIP_MINWINSVC=1",
"GIT_PROTOCOL="+gitProtocol,
)

stdout, err := cmd.StdoutPipe()
Expand Down

0 comments on commit e081930

Please sign in to comment.