Debian Codegraph @

ssh/ssh.go

raw symbols SCIP
1 package sshscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
5 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
6 "pathscip-go gomod github.com/golang/go/src go1.25.0 path/"
7 "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/"
8 "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/"
9 "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/"
10 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
11
12 "github.com/git-lfs/git-lfs/v3/configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/"
13 "github.com/git-lfs/git-lfs/v3/subprocessscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/"
14 "github.com/git-lfs/git-lfs/v3/toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/"
15 "github.com/rubyist/tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/"
16 )
17
18 type sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant# string
19
20 const (
21 variantSSHscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantSSH. = sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant#("ssh")
22 variantSimplescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantSimple. = sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant#("simple")
23 variantPuttyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantPutty. = sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant#("putty")
24 variantTortoisescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantTortoise. = sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant#("tortoiseplink")
25 )
26
27 type SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata# struct {
28 UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost. string
29 Portscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Port. string
30 Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Path. string
31 }
32
33 func FormatArgsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/FormatArgs().(cmd string, args []string, needShell bool) (string, []string) {
34 if !needShell {
35 return cmd, args
36 }
37
38 return subprocessscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/.FormatForShellQuotedArgsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/FormatForShellQuotedArgs().(cmd, args)
39 }
40
41 func GetLFSExeAndArgsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/GetLFSExeAndArgs().(osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, gitEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, meta *SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#, command, operation string, multiplexDesired bool, multiplexControlPath string) (exe string, args []string, multiplexing bool, controlPath string) {
42 exe, args, needShell, multiplexing, controlPath := GetExeAndArgsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/GetExeAndArgs().(osEnv, gitEnv, meta, multiplexDesired, multiplexControlPath)
43 args = append(args, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s %s %s", command, meta.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Path., operation))
44 exe, args = FormatArgsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/FormatArgs().(exe, args, needShell)
45 tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("run_command: %s %s", exe, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(args, " "))
46 return exe, args, multiplexing, controlPath
47 }
48
49 // Parse command, and if it looks like a valid command, return the ssh binary
50 // name, the command to run, and whether we need a shell. If not, return
51 // existing as the ssh binary name.
52 func parseShellCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/parseShellCommand().(command string, existing string) (ssh string, cmd string, needShell bool) {
53 ssh = existing
54 if cmdArgs := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.QuotedFieldsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/QuotedFields().(command); len(cmdArgs) > 0 {
55 needShell = true
56 ssh = cmdArgs[0]
57 cmd = command
58 }
59 return
60 }
61
62 func findVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/findVariant().(variant string) (bool, sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant#) {
63 switch variant {
64 case "ssh", "simple", "putty", "tortoiseplink":
65 return false, sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant#(variant)
66 case "plink":
67 return false, variantPuttyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantPutty.
68 case "auto":
69 return true, ""
70 default:
71 return false, variantSSHscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantSSH.
72 }
73 }
74
75 func autodetectVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/autodetectVariant().(osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, gitEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, basessh string) sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant# {
76 if basessh != defaultSSHCmdscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/defaultSSHCmd. {
77 // Strip extension for easier comparison
78 if ext := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Extscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Ext().(basessh); len(ext) > 0 {
79 basessh = basessh[:len(basessh)-len(ext)]
80 }
81 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.25.0 strings/EqualFold().(basessh, "plink") {
82 return variantPuttyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantPutty.
83 }
84 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.25.0 strings/EqualFold().(basessh, "tortoiseplink") {
85 return variantTortoisescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantTortoise.
86 }
87 }
88 return "ssh"
89 }
90
91 func getVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/getVariant().(osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, gitEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, basessh string) sshVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshVariant# {
92 variant, ok := osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("GIT_SSH_VARIANT")
93 if !ok {
94 variant, ok = gitEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("ssh.variant")
95 }
96 autodetect, val := findVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/findVariant().(variant)
97 if ok && !autodetect {
98 return val
99 }
100 return autodetectVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/autodetectVariant().(osEnv, gitEnv, basessh)
101 }
102
103 // findRuntimeDir returns a path to the runtime directory if one exists and is
104 // guaranteed to be private.
105 func findRuntimeDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/findRuntimeDir().(osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#) string {
106 if dir, ok := osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("XDG_RUNTIME_DIR"); ok {
107 return dir
108 }
109 return ""
110 }
111
112 func getControlDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/getControlDir().(osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#) (string, error) {
113 tmpdir, pattern := "", "sock-*"
114 if runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS. == "darwin" {
115 // On Darwin, the default temporary directory results in a socket path that's too long.
116 tmpdir = "/tmp"
117 }
118 dir := findRuntimeDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/findRuntimeDir().(osEnv)
119 if dir == "" {
120 return osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirTempscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirTemp().(tmpdir, pattern)
121 }
122 return osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirTempscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirTemp().(dir, pattern)
123 }
124
125 // Return the executable name for ssh on this machine and the base args
126 // Base args includes port settings, user/host, everything pre the command to execute
127 func GetExeAndArgsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/GetExeAndArgs().(osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, gitEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#, meta *SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#, multiplexDesired bool, multiplexControlPath string) (exe string, baseargs []string, needShell bool, multiplexing bool, controlPath string) {
128 var cmd string
129
130 ssh, _ := osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("GIT_SSH")
131 sshCmd, _ := osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("GIT_SSH_COMMAND")
132 ssh, cmd, needShell = parseShellCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/parseShellCommand().(sshCmd, ssh)
133
134 if ssh == "" {
135 sshCmd, _ := gitEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("core.sshcommand")
136 ssh, cmd, needShell = parseShellCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/parseShellCommand().(sshCmd, defaultSSHCmdscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/defaultSSHCmd.)
137 }
138
139 if cmd == "" {
140 cmd = ssh
141 }
142
143 basessh := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Base().(ssh)
144 variant := getVariantscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/getVariant().(osEnv, gitEnv, basessh)
145
146 args := make([]string, 0, 7)
147
148 if variant == variantTortoisescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantTortoise. {
149 // TortoisePlink requires the -batch argument to behave like ssh/plink
150 args = append(args, "-batch")
151 }
152
153 multiplexing = false
154 multiplexEnabled := gitEnv.Boolscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Bool.("lfs.ssh.automultiplex", runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS. != "windows")
155 if variant == variantSSHscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantSSH. && multiplexDesired && multiplexEnabled {
156 controlMasterArg := "-oControlMaster=no"
157 controlPath = multiplexControlPath
158 if multiplexControlPath == "" {
159 controlMasterArg = "-oControlMaster=yes"
160 controlDir, err := getControlDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/getControlDir().(osEnv)
161 if err == nil {
162 controlPath = pathscip-go gomod github.com/golang/go/src go1.25.0 path/.Joinscip-go gomod github.com/golang/go/src go1.25.0 path/Join().(controlDir, "lfs.sock")
163 }
164 }
165 if controlPath != "" {
166 multiplexing = true
167 args = append(args, controlMasterArg, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("-oControlPath=%s", controlPath))
168 }
169 }
170
171 if len(meta.Portscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Port.) > 0 {
172 if variant == variantPuttyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantPutty. || variant == variantTortoisescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantTortoise. {
173 args = append(args, "-P")
174 } else {
175 args = append(args, "-p")
176 }
177 args = append(args, meta.Portscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Port.)
178 }
179
180 if sshOptPrefixREscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshOptPrefixRE..MatchStringscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#MatchString().(meta.UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost.) {
181 if variant == variantSSHscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/variantSSH. {
182 // inserts a separator between cli -options and host/cmd commands
183 // example: $ ssh -p 12345 -- [email protected] git-lfs-authenticate ...
184 args = append(args, "--", meta.UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost.)
185 } else {
186 // no prefix supported, strip leading - off host to prevent cmd like:
187 // $ git config lfs.url ssh://-proxycmd=whatever
188 // $ plink -P 12345 -proxycmd=foo git-lfs-authenticate ...
189 //
190 // Instead, it'll attempt this, and eventually return an error
191 // $ plink -P 12345 proxycmd=foo git-lfs-authenticate ...
192 args = append(args, sshOptPrefixREscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshOptPrefixRE..ReplaceAllStringscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#ReplaceAllString().(meta.UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost., ""))
193 }
194 } else {
195 args = append(args, meta.UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost.)
196 }
197
198 return cmd, args, needShell, multiplexing, controlPath
199 }
200
201 const defaultSSHCmdscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/defaultSSHCmd. = "ssh"
202
203 var (
204 sshOptPrefixREscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/sshOptPrefixRE. = regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`\A\-+`)
205 )