From 7abac21ba553c8c1468b82456a7e44a4e245ff02 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Thu, 23 Mar 2017 20:52:25 +0900 Subject: [PATCH] Add timeout option to configtest (#400) --- README.ja.md | 3 +++ README.md | 4 ++++ commands/configtest.go | 8 ++++++-- scan/serverapi.go | 6 ++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.ja.md b/README.ja.md index d46626383d..8aaf3245dc 100644 --- a/README.ja.md +++ b/README.ja.md @@ -668,6 +668,7 @@ configtest: [-log-dir=/path/to/log] [-ask-key-password] [-ssh-external] + [-timeout=300] [-http-proxy=http://192.168.0.1:8080] [-debug] @@ -684,6 +685,8 @@ configtest: /path/to/log (default "/var/log/vuls") -ssh-external Use external ssh command. Default: Use the Go native implementation + -timeout int + Timeout(Sec) (default 300) ``` configtestサブコマンドは以下をチェックする diff --git a/README.md b/README.md index 1286331336..0d8b4dfa46 100644 --- a/README.md +++ b/README.md @@ -676,6 +676,7 @@ configtest: [-log-dir=/path/to/log] [-ask-key-password] [-ssh-external] + [-timeout=300] [-debug] [SERVER]... @@ -691,6 +692,9 @@ configtest: /path/to/log (default "/var/log/vuls") -ssh-external Use external ssh command. Default: Use the Go native implementation + -timeout int + Timeout(Sec) (default 300) + ``` The configtest subcommand checks the following diff --git a/commands/configtest.go b/commands/configtest.go index 8f0a3bed22..07a6308a93 100644 --- a/commands/configtest.go +++ b/commands/configtest.go @@ -37,6 +37,7 @@ type ConfigtestCmd struct { askKeyPassword bool sshExternal bool httpProxy string + timeoutSec int debug bool } @@ -54,6 +55,7 @@ func (*ConfigtestCmd) Usage() string { [-config=/path/to/config.toml] [-log-dir=/path/to/log] [-ask-key-password] + [-timeout=300] [-ssh-external] [-http-proxy=http://192.168.0.1:8080] [-debug] @@ -73,6 +75,8 @@ func (p *ConfigtestCmd) SetFlags(f *flag.FlagSet) { f.BoolVar(&p.debug, "debug", false, "debug mode") + f.IntVar(&p.timeoutSec, "timeout", 5*60, "Timeout(Sec)") + f.BoolVar( &p.askKeyPassword, "ask-key-password", @@ -157,10 +161,10 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa } util.Log.Info("Checking dependendies...") - scan.CheckDependencies() + scan.CheckDependencies(p.timeoutSec) util.Log.Info("Checking sudo settings...") - scan.CheckIfSudoNoPasswd() + scan.CheckIfSudoNoPasswd(p.timeoutSec) scan.PrintSSHableServerNames() return subcommands.ExitSuccess diff --git a/scan/serverapi.go b/scan/serverapi.go index 487da40019..3636be0425 100644 --- a/scan/serverapi.go +++ b/scan/serverapi.go @@ -342,8 +342,7 @@ func detectContainerOSesOnServer(containerHost osTypeInterface) (oses []osTypeIn } // CheckDependencies checks dependencies are installed on target servers. -func CheckDependencies() { - timeoutSec := 5 * 60 +func CheckDependencies(timeoutSec int) { parallelExec(func(o osTypeInterface) error { return o.checkDependencies() }, timeoutSec) @@ -351,8 +350,7 @@ func CheckDependencies() { } // CheckIfSudoNoPasswd checks whether vuls can sudo with nopassword via SSH -func CheckIfSudoNoPasswd() { - timeoutSec := 5 * 60 +func CheckIfSudoNoPasswd(timeoutSec int) { parallelExec(func(o osTypeInterface) error { return o.checkIfSudoNoPasswd() }, timeoutSec)