Skip to content

Commit

Permalink
chore: fix linter findings
Browse files Browse the repository at this point in the history
Notable change : remove deprecated and unneeded rand.Seed()
No longer required since Go 1.20
https://stackoverflow.com/questions/12321133/how-to-properly-seed-random-number-generator/74077488#74077488
  • Loading branch information
libvoid committed Jul 17, 2023
1 parent 54ecd39 commit 388b5cc
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 24 deletions.
4 changes: 1 addition & 3 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//go:build tools
// +build tools

package tools

import (
// required by depaware
_ "github.com/tailscale/depaware/depaware"

// required by goimports
_ "golang.org/x/tools/cover"
)
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package main // import "moul.io/sshportal"

import (
"log"
"math/rand"
"os"
"path"

"github.com/urfave/cli"
"moul.io/srand"
)

var (
Expand All @@ -18,8 +16,6 @@ var (
)

func main() {
rand.Seed(srand.MustSecure())

app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Author = "Manfred Touron"
Expand Down
4 changes: 2 additions & 2 deletions pkg/bastion/dbinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bastion // import "moul.io/sshportal/pkg/bastion"
import (
"crypto/rand"
"fmt"
"io/ioutil"
"io"
"log"
"math/big"
"os"
Expand All @@ -19,7 +19,7 @@ import (
)

func DBInit(db *gorm.DB) error {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
log.SetOutput(os.Stderr)

m := gormigrate.New(db, gormigrate.DefaultOptions, []*gormigrate.Migration{
Expand Down
2 changes: 1 addition & 1 deletion pkg/bastion/logtunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newLogTunnel(channel ssh.Channel, writer io.WriteCloser, host string) io.Re
}
}

func (l *logTunnel) Read(data []byte) (int, error) {
func (l *logTunnel) Read(_ []byte) (int, error) {
return 0, errors.New("logTunnel.Read is not implemented")
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/bastion/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bastion // import "moul.io/sshportal/pkg/bastion"
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -129,7 +128,7 @@ func pipe(lreqs, rreqs <-chan *gossh.Request, lch, rch gossh.Channel, sessConfig
quit := make(chan string, 1)
channeltype := newChan.ChannelType()

var logWriter io.WriteCloser = newDiscardWriteCloser()
var logWriter = newDiscardWriteCloser()
if sessConfig.LoggingMode != "disabled" {
filename := filepath.Join(sessConfig.LogsLocation, fmt.Sprintf("%s-%s-%s-%d-%s", user, username, channeltype, sessionID, time.Now().Format(time.RFC3339)))
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0440)
Expand Down Expand Up @@ -253,7 +252,7 @@ func pipe(lreqs, rreqs <-chan *gossh.Request, lch, rch gossh.Channel, sessConfig
}
}

func newDiscardWriteCloser() io.WriteCloser { return &discardWriteCloser{ioutil.Discard} }
func newDiscardWriteCloser() io.WriteCloser { return &discardWriteCloser{io.Discard} }

type discardWriteCloser struct {
io.Writer
Expand Down
8 changes: 4 additions & 4 deletions pkg/bastion/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,12 +1632,12 @@ GLOBAL OPTIONS:
if err := myself.CheckRoles([]string{"admin"}); err != nil {
return err
}

var users []*dbmodels.User
if err := dbmodels.UsersByIdentifiers(db, c.Args()).Find(&users).Error; err != nil {
return err
}

for _, user := range users {
if err := db.Model(&dbmodels.Session{}).Where(&dbmodels.Session{User: user, Status: string(dbmodels.SessionStatusActive)}).Update("status", "closed").Error; err != nil {
return err
Expand All @@ -1657,12 +1657,12 @@ GLOBAL OPTIONS:
if err := myself.CheckRoles([]string{"admin"}); err != nil {
return err
}

var users []*dbmodels.User
if err := dbmodels.UsersByIdentifiers(db, c.Args()).Find(&users).Error; err != nil {
return err
}

for _, user := range users {
if err := db.Where("user_id = ?", user.ID).Delete(&dbmodels.UserKey{}).Error; err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/bastion/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func ChannelHandler(srv *ssh.Server, conn *gossh.ServerConn, newChan gossh.NewCh
_ = ch.Close()
return
}
go func(cnx *gossh.ServerConn, dbConn *gorm.DB, sessionID uint) {
go func(_ *gossh.ServerConn, dbConn *gorm.DB, sessionID uint) {
for {
sess := dbmodels.Session{Model: gorm.Model{ID: sessionID}, Status: string(dbmodels.SessionStatusActive)}
if err := dbConn.First(&sess).Error; err != nil || sess.Status != string(dbmodels.SessionStatusActive) {
Expand Down Expand Up @@ -222,7 +222,7 @@ func bastionClientConfig(ctx ssh.Context, host *dbmodels.Host) (*gossh.ClientCon

crypto.HostDecrypt(actx.aesKey, host)
if host.SSHKey != nil {
crypto.SSHKeyDecrypt(actx.aesKey, host.SSHKey)
crypto.SSHKeyDecrypt(actx.aesKey, host.SSHKey)
}

clientConfig, err := host.ClientConfig(dynamicHostKey(actx.db, host))
Expand Down
2 changes: 1 addition & 1 deletion pkg/bastion/telnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type bastionTelnetCaller struct {
ssh ssh.Session
}

func (caller bastionTelnetCaller) CallTELNET(ctx telnet.Context, w telnet.Writer, r telnet.Reader) {
func (caller bastionTelnetCaller) CallTELNET(_ telnet.Context, w telnet.Writer, r telnet.Reader) {
go func(writer io.Writer, reader io.Reader) {
var buffer [1]byte // Seems like the length of the buffer needs to be small, otherwise will have to wait for buffer to fill up.
p := buffer[:]
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func server(c *serverConfig) (err error) {
}()

if err = sqlDB.Ping(); err != nil {
return
return err
}

if err = bastion.DBInit(db); err != nil {
return
return err
}

// create TCP listening socket
Expand All @@ -115,7 +115,7 @@ func server(c *serverConfig) (err error) {
srv := &ssh.Server{
Addr: c.bindAddr,
Handler: func(s ssh.Session) { bastion.ShellHandler(s, GitTag, GitSha, GitTag) }, // ssh.Server.Handler is the handler for the DefaultSessionHandler
Version: fmt.Sprintf("sshportal"),
Version: "sshportal",
ChannelHandlers: map[string]ssh.ChannelHandler{
"default": bastion.ChannelHandler,
},
Expand Down
2 changes: 1 addition & 1 deletion testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// testServer is an hidden handler used for integration tests
func testServer(c *cli.Context) error {
func testServer(_ *cli.Context) error {
ssh.Handle(func(s ssh.Session) {
helloMsg := struct {
User string
Expand Down
1 change: 1 addition & 0 deletions testserver_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package main
Expand Down

0 comments on commit 388b5cc

Please sign in to comment.