mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 07:26:33 -04:00
refactor(git): simplify SSH command guard
Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
9fd40479b7
commit
168442467f
|
|
@ -310,25 +310,24 @@ func prepareCLIAuth(auth *AuthMethod) ([]string, []string, func(), error) {
|
|||
// an identity or passphrase. Overriding it unconditionally would bypass
|
||||
// the user's core.sshCommand and GIT_SSH_COMMAND settings, including any
|
||||
// host-key/known_hosts handling configured there.
|
||||
if auth.KeyFile == "" && auth.KeyPassphrase == "" {
|
||||
break
|
||||
}
|
||||
sshCommand := "ssh"
|
||||
if auth.KeyFile != "" {
|
||||
sshCommand += " -i " + shellQuote(auth.KeyFile) + " -o IdentitiesOnly=yes"
|
||||
}
|
||||
env = append(env, "GIT_SSH_COMMAND="+sshCommand)
|
||||
if auth.KeyPassphrase != "" {
|
||||
askPassPath, err := writeAskPassScript(auth.KeyPassphrase)
|
||||
if err != nil {
|
||||
return nil, nil, cleanup, err
|
||||
if auth.KeyFile != "" || auth.KeyPassphrase != "" {
|
||||
sshCommand := "ssh"
|
||||
if auth.KeyFile != "" {
|
||||
sshCommand += " -i " + shellQuote(auth.KeyFile) + " -o IdentitiesOnly=yes"
|
||||
}
|
||||
env = append(env, "GIT_SSH_COMMAND="+sshCommand)
|
||||
if auth.KeyPassphrase != "" {
|
||||
askPassPath, err := writeAskPassScript(auth.KeyPassphrase)
|
||||
if err != nil {
|
||||
return nil, nil, cleanup, err
|
||||
}
|
||||
cleanup = func() { _ = os.Remove(askPassPath) }
|
||||
env = append(env,
|
||||
"SSH_ASKPASS="+askPassPath,
|
||||
"SSH_ASKPASS_REQUIRE=force",
|
||||
"DISPLAY=tea",
|
||||
)
|
||||
}
|
||||
cleanup = func() { _ = os.Remove(askPassPath) }
|
||||
env = append(env,
|
||||
"SSH_ASKPASS="+askPassPath,
|
||||
"SSH_ASKPASS_REQUIRE=force",
|
||||
"DISPLAY=tea",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue