fix static check warnings

ws
dingjun 2 years ago
parent 267134144f
commit b0a539ca99

@ -38,8 +38,6 @@ type Client struct {
// addr is server address // addr is server address
// //
// conf is the client configure // conf is the client configure
//
//
func NewClient(c net.Conn, config *ssh.ClientConfig, addr string, conf *Conf) (*Client, error) { func NewClient(c net.Conn, config *ssh.ClientConfig, addr string, conf *Conf) (*Client, error) {
//obfsConn := &TimedOutConn{c, conf.Timeout} //obfsConn := &TimedOutConn{c, conf.Timeout}
sshConn, newch, reqs, err := ssh.NewClientConn(c, addr, config) sshConn, newch, reqs, err := ssh.NewClientConn(c, addr, config)
@ -73,9 +71,8 @@ func (cc *Client) Run() error {
go cc.registerSignal() go cc.registerSignal()
select { time.Sleep(1 * time.Second)
case <-time.After(1 * time.Second):
}
// wait port forward to finish // wait port forward to finish
if cc.listeners != nil { if cc.listeners != nil {
log.Debugf("wait all channel to be done") log.Debugf("wait all channel to be done")
@ -420,7 +417,8 @@ func (cc *Client) registerSignal() {
} }
// AddDynamicHTTPForward add a http dynamic forward through // AddDynamicHTTPForward add a http dynamic forward through
// secure channel //
// secure channel
func (cc *Client) AddDynamicHTTPForward(addr string) error { func (cc *Client) AddDynamicHTTPForward(addr string) error {
log.Debugf("add dynamic http listen: %s", addr) log.Debugf("add dynamic http listen: %s", addr)
l, err := net.Listen("tcp", addr) l, err := net.Listen("tcp", addr)

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package obfssh package obfssh

@ -1,3 +1,4 @@
//go:build darwin || freebsd || linux || openbsd || solaris
// +build darwin freebsd linux openbsd solaris // +build darwin freebsd linux openbsd solaris
package obfssh package obfssh

@ -233,13 +233,11 @@ func main() {
timeout := time.Duration(cfg.KeepaliveInterval*2) * time.Second timeout := time.Duration(cfg.KeepaliveInterval*2) * time.Second
var _conn = c var _conn net.Conn = &obfssh.TimedOutConn{Conn: c, Timeout: timeout}
conn := &obfssh.TimedOutConn{Conn: c, Timeout: timeout}
if cfg.TLS { if cfg.TLS {
log.Debugf("begin tls handshake") log.Debugf("begin tls handshake")
_conn = tls.Client(conn, &tls.Config{ _conn = tls.Client(_conn, &tls.Config{
ServerName: host, ServerName: host,
InsecureSkipVerify: cfg.TLSInsecure, InsecureSkipVerify: cfg.TLSInsecure,
}) })
@ -310,7 +308,7 @@ func main() {
} }
for _, p := range cfg.DynamicForwards { for _, p := range cfg.DynamicForwards {
if strings.Index(p, ":") == -1 { if !strings.Contains(p, ":") {
local = fmt.Sprintf(":%s", p) local = fmt.Sprintf(":%s", p)
} else { } else {
local = p local = p
@ -322,7 +320,7 @@ func main() {
} }
for _, p := range cfg.DynamicHTTP { for _, p := range cfg.DynamicHTTP {
if strings.Index(p, ":") == -1 { if !strings.Contains(p, ":") {
local = fmt.Sprintf(":%s", p) local = fmt.Sprintf(":%s", p)
} else { } else {
local = p local = p
@ -363,10 +361,7 @@ func main() {
func parseForwardAddr(s string) []string { func parseForwardAddr(s string) []string {
ss := strings.FieldsFunc(s, func(c rune) bool { ss := strings.FieldsFunc(s, func(c rune) bool {
if c == ':' { return c == ':'
return true
}
return false
}) })
return ss return ss
} }

@ -74,7 +74,7 @@ func main() {
if u, err := conf.getUser(c.User()); err == nil { if u, err := conf.getUser(c.User()); err == nil {
for _, pk := range u.publicKeys { for _, pk := range u.publicKeys {
if k.Type() == pk.Type() && if k.Type() == pk.Type() &&
bytes.Compare(k.Marshal(), pk.Marshal()) == 0 { bytes.Equal(k.Marshal(), pk.Marshal()) {
return true return true
} }
} }

@ -1,3 +1,4 @@
//go:build !linux
// +build !linux // +build !linux
package obfssh package obfssh

@ -1,3 +1,4 @@
//go:build linux && !cgo
// +build linux,!cgo // +build linux,!cgo
package obfssh package obfssh

@ -1,3 +1,4 @@
//go:build linux && cgo
// +build linux,cgo // +build linux,cgo
package obfssh package obfssh

@ -34,8 +34,6 @@ type Server struct {
// config is &ssh.ServerConfig // config is &ssh.ServerConfig
// //
// conf is the server configure // conf is the server configure
//
//
func NewServer(c net.Conn, config *ssh.ServerConfig, conf *Conf) (*Server, error) { func NewServer(c net.Conn, config *ssh.ServerConfig, conf *Conf) (*Server, error) {
sshConn, ch, req, err := ssh.NewServerConn(&TimedOutConn{c, 15 * 60 * time.Second}, config) sshConn, ch, req, err := ssh.NewServerConn(&TimedOutConn{c, 15 * 60 * time.Second}, config)
if err != nil { if err != nil {
@ -211,10 +209,10 @@ func (s *session) handleSubsystem(payload []byte) bool {
func (s *session) handleShell() bool { func (s *session) handleShell() bool {
var cmd *exec.Cmd var cmd *exec.Cmd
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
s.env = append(s.env, fmt.Sprintf("SHELL=powershell")) s.env = append(s.env, "SHELL=powershell")
cmd = exec.Command("powershell") cmd = exec.Command("powershell")
} else { } else {
s.env = append(s.env, fmt.Sprintf("SHELL=/bin/bash")) s.env = append(s.env, "SHELL=/bin/bash")
cmd = exec.Command("/bin/bash", "-l") cmd = exec.Command("/bin/bash", "-l")
} }
s.cmd = cmd s.cmd = cmd
@ -232,10 +230,10 @@ func (s *session) handleExec(payload []byte) bool {
} }
log.Infoln("execute command", _cmd.Arg) log.Infoln("execute command", _cmd.Arg)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
s.env = append(s.env, fmt.Sprintf("SHELL=powershell")) s.env = append(s.env, "SHELL=powershell")
cmd = exec.Command("powershell", "-Command", _cmd.Arg) cmd = exec.Command("powershell", "-Command", _cmd.Arg)
} else { } else {
s.env = append(s.env, fmt.Sprintf("SHELL=/bin/bash")) s.env = append(s.env, "SHELL=/bin/bash")
cmd = exec.Command("/bin/bash", "-c", _cmd.Arg) cmd = exec.Command("/bin/bash", "-c", _cmd.Arg)
} }
s.cmd = cmd s.cmd = cmd
@ -273,7 +271,7 @@ func (s *session) handlePtyReq(payload []byte) bool {
s.env = append(s.env, fmt.Sprintf("SSH_TTY=%s", s.ptsname)) s.env = append(s.env, fmt.Sprintf("SSH_TTY=%s", s.ptsname))
s.env = append(s.env, fmt.Sprintf("TERM=%s", _ptyReq.Term)) s.env = append(s.env, fmt.Sprintf("TERM=%s", _ptyReq.Term))
ws, err := s._console.Size() ws, _ := s._console.Size()
log.Debugf("current console %+v", ws) log.Debugf("current console %+v", ws)
ws.Height = uint16(_ptyReq.Rows) ws.Height = uint16(_ptyReq.Rows)
ws.Width = uint16(_ptyReq.Columns) ws.Width = uint16(_ptyReq.Columns)
@ -566,7 +564,7 @@ func (sc *Server) handleTcpipForward(req *ssh.Request) {
return return
} }
if addr.Port > 65535 || addr.Port < 0 { if addr.Port > 65535 {
log.Errorf("invalid port %d", addr.Port) log.Errorf("invalid port %d", addr.Port)
if req.WantReply { if req.WantReply {
req.Reply(false, nil) req.Reply(false, nil)

Loading…
Cancel
Save