-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnWorker.go
51 lines (41 loc) · 1.14 KB
/
connWorker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"net"
"os"
"strconv"
"golang.org/x/crypto/ssh"
)
type connWorker struct {
adapters *adaptersType
cid string
id int
uid int
defaultShell string
}
func (c *connWorker) run(tcpConn net.Conn, config *ssh.ServerConfig) {
sshConn, chans, reqs, err := ssh.NewServerConn(tcpConn, config)
if err != nil {
log.Printf("Failed to handshake (%s)", err)
return
}
c.id, _ = strconv.Atoi(sshConn.Permissions.CriticalOptions[permIDKey])
c.cid = sshConn.Permissions.CriticalOptions[permCIDKey]
c.uid, _ = strconv.Atoi(sshConn.Permissions.CriticalOptions[permUIDKey])
c.defaultShell = sshConn.Permissions.CriticalOptions[permShellKey]
if c.defaultShell == "" {
if p, err := c.adapters.consul.Client.Get(fmt.Sprint(defaultShellKVFormat, c.uid)); err == nil {
c.defaultShell = string(p.Value)
}
}
if c.defaultShell == "" {
c.defaultShell = os.Getenv("MODOKI_DEFAULT_SHELL")
}
if c.defaultShell == "" {
c.defaultShell = "sh"
}
log.Printf("New SSH connection from %s (%s)", sshConn.RemoteAddr(), sshConn.ClientVersion())
go ssh.DiscardRequests(reqs)
go c.handleChannels(chans)
}