@@ -6,7 +6,6 @@ package ssh
6
6
7
7
import (
8
8
"context"
9
- "fmt"
10
9
"io"
11
10
"net"
12
11
"os"
@@ -55,26 +54,8 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
55
54
payload := cleanCommand (string (req .Payload ))
56
55
switch req .Type {
57
56
case "env" :
58
- var env struct {
59
- Name string
60
- Value string
61
- }
62
- if err := ssh .Unmarshal (req .Payload , & env ); err != nil {
63
- log .Warn ("SSH: Invalid env payload %q: %v" , req .Payload , err )
64
- continue
65
- }
66
- // Sometimes the client could send malformed command (i.e. missing "="),
67
- // see https://discuss.gogs.io/t/ssh/3106.
68
- if env .Name == "" || env .Value == "" {
69
- log .Warn ("SSH: Invalid env arguments: %+v" , env )
70
- continue
71
- }
72
-
73
- _ , stderr , err := com .ExecCmd ("env" , fmt .Sprintf ("%s=%s" , env .Name , env .Value ))
74
- if err != nil {
75
- log .Error ("env: %v - %s" , err , stderr )
76
- return
77
- }
57
+ // We only need to accept the request and do nothing since whatever environment
58
+ // variables being set here won't be used in subsequent commands anyway.
78
59
79
60
case "exec" :
80
61
cmdName := strings .TrimLeft (payload , "'()" )
@@ -175,7 +156,9 @@ func Listen(opts conf.SSHOpts, appDataPath string) {
175
156
PublicKeyCallback : func (conn ssh.ConnMetadata , key ssh.PublicKey ) (* ssh.Permissions , error ) {
176
157
pkey , err := database .SearchPublicKeyByContent (strings .TrimSpace (string (ssh .MarshalAuthorizedKey (key ))))
177
158
if err != nil {
178
- log .Error ("SearchPublicKeyByContent: %v" , err )
159
+ if ! database .IsErrKeyNotExist (err ) {
160
+ log .Error ("SearchPublicKeyByContent: %v" , err )
161
+ }
179
162
return nil , err
180
163
}
181
164
return & ssh.Permissions {Extensions : map [string ]string {"key-id" : com .ToStr (pkey .ID )}}, nil
0 commit comments