Skip to content

Commit ba3b31c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ptysess
2 parents c29875a + 8867fb1 commit ba3b31c

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

circle.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
- run: go get
1010
- run: go test -v -race
1111

12-
build-go-1.13:
12+
build-go-1.17:
1313
docker:
14-
- image: golang:1.13
14+
- image: golang:1.17
1515
working_directory: /go/src/github.com/gliderlabs/ssh
1616
steps:
1717
- checkout
@@ -23,4 +23,4 @@ workflows:
2323
build:
2424
jobs:
2525
- build-go-latest
26-
- build-go-1.13
26+
- build-go-1.17

context.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ type Context interface {
9595
type sshContext struct {
9696
ctx context.Context
9797
mtx *sync.RWMutex
98+
99+
values map[interface{}]interface{}
100+
valuesMu sync.Mutex
98101
}
99102

100103
var _ context.Context = &sshContext{}
@@ -103,7 +106,11 @@ var _ sync.Locker = &sshContext{}
103106

104107
func newContext(srv *Server) (*sshContext, context.CancelFunc) {
105108
innerCtx, cancel := context.WithCancel(context.Background())
106-
ctx := &sshContext{innerCtx, &sync.RWMutex{}}
109+
ctx := &sshContext{
110+
ctx: innerCtx,
111+
mtx: &sync.RWMutex{},
112+
values: make(map[interface{}]interface{}),
113+
}
107114
ctx.SetValue(ContextKeyServer, srv)
108115
perms := &Permissions{&gossh.Permissions{}}
109116
ctx.SetValue(ContextKeyPermissions, perms)
@@ -124,18 +131,21 @@ func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) {
124131
ctx.SetValue(ContextKeyRemoteAddr, conn.RemoteAddr())
125132
}
126133

127-
func (ctx *sshContext) SetValue(key, value interface{}) {
128-
ctx.mtx.Lock()
129-
defer ctx.mtx.Unlock()
130-
ctx.ctx = context.WithValue(ctx.ctx, key, value)
131-
}
132-
133134
func (ctx *sshContext) Value(key interface{}) interface{} {
134-
ctx.mtx.RLock()
135-
defer ctx.mtx.RUnlock()
135+
ctx.valuesMu.Lock()
136+
defer ctx.valuesMu.Unlock()
137+
if v, ok := ctx.values[key]; ok {
138+
return v
139+
}
136140
return ctx.ctx.Value(key)
137141
}
138142

143+
func (ctx *sshContext) SetValue(key, value interface{}) {
144+
ctx.valuesMu.Lock()
145+
defer ctx.valuesMu.Unlock()
146+
ctx.values[key] = value
147+
}
148+
139149
func (ctx *sshContext) Done() <-chan struct{} {
140150
ctx.mtx.RLock()
141151
defer ctx.mtx.RUnlock()

go.mod

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
module github.com/charmbracelet/ssh
22

3-
go 1.12
3+
go 1.17
44

55
require (
66
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
77
github.com/aymanbagabas/go-pty v0.2.1
8-
golang.org/x/crypto v0.16.0
8+
golang.org/x/crypto v0.17.0
9+
)
10+
11+
require (
12+
github.com/creack/pty v1.1.15 // indirect
13+
github.com/u-root/u-root v0.11.0 // indirect
14+
golang.org/x/sys v0.15.0 // indirect
915
)

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf
224224
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
225225
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
226226
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
227-
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
228227
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
228+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
229+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
229230
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
230231
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
231232
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=

server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Server struct {
3737
Handler Handler // handler to invoke, ssh.DefaultHandler if nil
3838
HostSigners []Signer // private keys for the host key, must have at least one
3939
Version string // server version to be sent before the initial handshake
40+
Banner string // server banner
4041

4142
KeyboardInteractiveHandler KeyboardInteractiveHandler // keyboard-interactive authentication handler
4243
PasswordHandler PasswordHandler // password authentication handler
@@ -132,6 +133,11 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
132133
if srv.Version != "" {
133134
config.ServerVersion = "SSH-2.0-" + srv.Version
134135
}
136+
if srv.Banner != "" {
137+
config.BannerCallback = func(conn gossh.ConnMetadata) string {
138+
return srv.Banner
139+
}
140+
}
135141
if srv.PasswordHandler != nil {
136142
config.PasswordCallback = func(conn gossh.ConnMetadata, password []byte) (*gossh.Permissions, error) {
137143
applyConnMetadata(ctx, conn)

0 commit comments

Comments
 (0)