Fixes #1 segmentation violation with unprivileged user
This commit is contained in:
parent
38d9c881b3
commit
ffa3b6f3d2
3 changed files with 14 additions and 14 deletions
|
@ -15,18 +15,18 @@ func checkStateFile() error {
|
||||||
// Finds the state file to parse
|
// Finds the state file to parse
|
||||||
if stateFileName != "" {
|
if stateFileName != "" {
|
||||||
stateFileName = filepath.Join(workDir, stateFileName)
|
stateFileName = filepath.Join(workDir, stateFileName)
|
||||||
info, err := os.Stat(stateFileName)
|
_, err := os.Stat(stateFileName)
|
||||||
if os.IsNotExist(err) || info.IsDir() {
|
if err != nil {
|
||||||
return fmt.Errorf("The state file %s does not exist", stateFileName)
|
return fmt.Errorf("Could not open state file %s", stateFileName)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stateFileName = filepath.Join(workDir, bareosStateFile)
|
stateFileName = filepath.Join(workDir, bareosStateFile)
|
||||||
info, err := os.Stat(stateFileName)
|
_, err := os.Stat(stateFileName)
|
||||||
if os.IsNotExist(err) || info.IsDir() {
|
if err != nil {
|
||||||
stateFileName = filepath.Join(workDir, baculaStateFile)
|
stateFileName = filepath.Join(workDir, baculaStateFile)
|
||||||
info, err = os.Stat(stateFileName)
|
_, err = os.Stat(stateFileName)
|
||||||
if os.IsNotExist(err) || info.IsDir() {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not find a suitable state file. Has a job ever run?")
|
return fmt.Errorf("Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func checkWorkDir() error {
|
||||||
workDir = filepath.Join(root, baculaWorkDir)
|
workDir = filepath.Join(root, baculaWorkDir)
|
||||||
info, err := os.Stat(workDir)
|
info, err := os.Stat(workDir)
|
||||||
if os.IsNotExist(err) || !info.IsDir() {
|
if os.IsNotExist(err) || !info.IsDir() {
|
||||||
return fmt.Errorf("Could not find a suitable work directory. Is bareos or bacula installed?")
|
return fmt.Errorf("Could not autodetect a suitable work directory. Is bareos or bacula installed?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,12 @@ func TestMain(t *testing.T) {
|
||||||
args []string
|
args []string
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{"failed bacula_auto_detect", 0, "tmp/bacula_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not find a suitable state file. Has a job ever run?"},
|
{"failed bacula_auto_detect", 0, "tmp/bacula_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use."},
|
||||||
{"failed bareos_auto_detect", 0, "tmp/bareos_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not find a suitable state file. Has a job ever run?"},
|
{"failed bareos_auto_detect", 0, "tmp/bareos_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use."},
|
||||||
{"failed auto_detect", 0, "tmp/non_existent", []string{}, "INFO Failed to init programm : Could not find a suitable work directory. Is bareos or bacula installed?"},
|
{"failed auto_detect", 0, "tmp/non_existent", []string{}, "INFO Failed to init programm : Could not autodetect a suitable work directory. Is bareos or bacula installed?"},
|
||||||
{"no work directory", 0, "tmp", []string{"-w", "/non_existent"}, fmt.Sprintf("INFO Failed to init programm : Invalid work directory %s/tmp/non_existent : it does not exist or is not a directory", wd)},
|
{"no work directory", 0, "tmp", []string{"-w", "/non_existent"}, fmt.Sprintf("INFO Failed to init programm : Invalid work directory %s/tmp/non_existent : it does not exist or is not a directory", wd)},
|
||||||
{"no state file auto_detect", 0, "tmp", []string{"-w", "/no_state_file"}, "INFO Failed to init programm : Could not find a suitable state file. Has a job ever run?"},
|
{"no state file auto_detect", 0, "tmp", []string{"-w", "/no_state_file"}, "INFO Failed to init programm : Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use."},
|
||||||
{"no state file", 0, "tmp", []string{"-w", "/no_state_file", "-f", "test"}, fmt.Sprintf("INFO Failed to init programm : The state file %s/tmp/no_state_file/test does not exist", wd)},
|
{"no state file", 0, "tmp", []string{"-w", "/no_state_file", "-f", "test"}, fmt.Sprintf("INFO Failed to init programm : Could not open state file %s/tmp/no_state_file/test", wd)},
|
||||||
{"ok bareos 18.2", 1582579731, "tmp/ok-18.2", []string{"-w", "/", "-f", "state"}, "OK"},
|
{"ok bareos 18.2", 1582579731, "tmp/ok-18.2", []string{"-w", "/", "-f", "state"}, "OK"},
|
||||||
{"ok bareos 17.2", 1582579731, "tmp/ok-17.2", []string{"-w", "/", "-f", "state"}, "OK"},
|
{"ok bareos 17.2", 1582579731, "tmp/ok-17.2", []string{"-w", "/", "-f", "state"}, "OK"},
|
||||||
{"missing", 1582709331, "tmp/ok-18.2", []string{"-w", "/", "-f", "state"}, "AVERAGE: missing: awhphpipam1_percona_xtrabackup, awhphpipam1_LinuxAll, awhphpipam1_www"},
|
{"missing", 1582709331, "tmp/ok-18.2", []string{"-w", "/", "-f", "state"}, "AVERAGE: missing: awhphpipam1_percona_xtrabackup, awhphpipam1_LinuxAll, awhphpipam1_www"},
|
||||||
|
|
Loading…
Add table
Reference in a new issue