summaryrefslogtreecommitdiffstats
path: root/modules/ssh
diff options
context:
space:
mode:
authorkolaente <konrad@kola-entertainments.de>2019-06-12 21:41:28 +0200
committertechknowlogick <techknowlogick@gitea.io>2019-06-12 15:41:28 -0400
commitf9ec2f89f2265bc1371a6c62359de9816534fa6b (patch)
treef48b138a457e5ac6cf843bbb38400926704370f7 /modules/ssh
parent5832f8d90df2d72cb38698c3e9050f2b29717dc7 (diff)
downloadgitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.tar.gz
gitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.zip
Add golangci (#6418)
Diffstat (limited to 'modules/ssh')
-rw-r--r--modules/ssh/ssh.go50
1 files changed, 41 insertions, 9 deletions
diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go
index 98ff50bfec..c5251ef23a 100644
--- a/modules/ssh/ssh.go
+++ b/modules/ssh/ssh.go
@@ -37,7 +37,10 @@ func cleanCommand(cmd string) string {
func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
for newChan := range chans {
if newChan.ChannelType() != "session" {
- newChan.Reject(ssh.UnknownChannelType, "unknown channel type")
+ err := newChan.Reject(ssh.UnknownChannelType, "unknown channel type")
+ if err != nil {
+ log.Error("Error rejecting channel: %v", err)
+ }
continue
}
@@ -48,7 +51,11 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
}
go func(in <-chan *ssh.Request) {
- defer ch.Close()
+ defer func() {
+ if err = ch.Close(); err != nil {
+ log.Error("Close: %v", err)
+ }
+ }()
for req := range in {
payload := cleanCommand(string(req.Payload))
switch req.Type {
@@ -87,17 +94,34 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
return
}
- req.Reply(true, nil)
- go io.Copy(input, ch)
- io.Copy(ch, stdout)
- io.Copy(ch.Stderr(), stderr)
+ err = req.Reply(true, nil)
+ if err != nil {
+ log.Error("SSH: Reply: %v", err)
+ }
+ go func() {
+ _, err = io.Copy(input, ch)
+ if err != nil {
+ log.Error("SSH: Copy: %v", err)
+ }
+ }()
+ _, err = io.Copy(ch, stdout)
+ if err != nil {
+ log.Error("SSH: Copy: %v", err)
+ }
+ _, err = io.Copy(ch.Stderr(), stderr)
+ if err != nil {
+ log.Error("SSH: Copy: %v", err)
+ }
if err = cmd.Wait(); err != nil {
log.Error("SSH: Wait: %v", err)
return
}
- ch.SendRequest("exit-status", false, []byte{0, 0, 0, 0})
+ _, err = ch.SendRequest("exit-status", false, []byte{0, 0, 0, 0})
+ if err != nil {
+ log.Error("SSH: SendRequest: %v", err)
+ }
return
default:
}
@@ -203,7 +227,11 @@ func GenKeyPair(keyPath string) error {
if err != nil {
return err
}
- defer f.Close()
+ defer func() {
+ if err = f.Close(); err != nil {
+ log.Error("Close: %v", err)
+ }
+ }()
if err := pem.Encode(f, privateKeyPEM); err != nil {
return err
@@ -220,7 +248,11 @@ func GenKeyPair(keyPath string) error {
if err != nil {
return err
}
- defer p.Close()
+ defer func() {
+ if err = p.Close(); err != nil {
+ log.Error("Close: %v", err)
+ }
+ }()
_, err = p.Write(public)
return err
}