192 |
- |
1 |
|
|
|
2 |
# check for non-parametric options
|
|
|
3 |
# returns number of params
|
|
|
4 |
function _oscap_noarg {
|
|
|
5 |
case "$1" in
|
203 |
- |
6 |
--definitions|--syschar|--results|--skip-schematron|-f|--force|-q|--quiet|--oval-results) return 0 ;;
|
192 |
- |
7 |
--version|--help|-V|-h) return 256 ;; # stop cmdline processing
|
|
|
8 |
*) return 1 ;;
|
|
|
9 |
esac
|
|
|
10 |
}
|
|
|
11 |
|
|
|
12 |
function _oscap {
|
|
|
13 |
|
|
|
14 |
# commands for individual modules
|
|
|
15 |
local -A cmds=()
|
|
|
16 |
cmds[oscap]="info oval xccdf ds cpe cvss cve"
|
|
|
17 |
cmds[oscap:oval]="collect eval analyse validate generate"
|
|
|
18 |
cmds[oscap:oval:generate]="report"
|
|
|
19 |
cmds[oscap:cvss]="score describe"
|
|
|
20 |
cmds[oscap:xccdf]="eval remediate resolve validate export-oval-variables generate"
|
|
|
21 |
cmds[oscap:xccdf:generate]="report guide fix custom"
|
|
|
22 |
cmds[oscap:ds]="sds-add sds-compose sds-split sds-validate rds-create rds-split rds-validate"
|
|
|
23 |
cmds[oscap:cpe]="check match validate"
|
|
|
24 |
cmds[oscap:cve]="validate find"
|
|
|
25 |
|
|
|
26 |
# command options
|
|
|
27 |
local -A opts=()
|
|
|
28 |
opts[oscap]="--version --quiet --help -V -q -h"
|
203 |
- |
29 |
opts[oscap:oval:validate]="--version --definitions --variables --syschar --results --directives --skip-schematron"
|
204 |
- |
30 |
opts[oscap:oval:eval]="--datastream-id --oval-id --id --variables --directives --without-syschar --results --report --skip-valid --skip-validation --fetch-remote-resources --local-files --verbose --verbose-log-file"
|
203 |
- |
31 |
opts[oscap:oval:analyse]="--variables --directives --verbose --verbose-log-file --skip-valid --skip-validation"
|
|
|
32 |
opts[oscap:oval:collect]="--id --syschar --skip-valid --skip-validation --variables --verbose --verbose-log-file"
|
192 |
- |
33 |
opts[oscap:oval:generate:report]="-o --output"
|
209 |
- |
34 |
opts[oscap:xccdf:eval]="--benchmark-id --check-engine-results --cpe --datastream-id --enforce-signature --export-variables --fetch-remote-resources --local-files --oval-results --profile --progress --progress-full --remediate --report --results --results-arf --rule --skip-rule --skip-valid --skip-validation --skip-signature-validation --stig-viewer --tailoring-file --tailoring-id --thin-results --verbose --verbose-log-file --without-syschar --xccdf-id"
|
203 |
- |
35 |
opts[oscap:xccdf:validate]="--skip-schematron"
|
204 |
- |
36 |
opts[oscap:xccdf:export-oval-variables]="--datastream-id --xccdf-id --profile --skip-valid --skip-validation --fetch-remote-resources --local-files --cpe"
|
209 |
- |
37 |
opts[oscap:xccdf:remediate]="--result-id --skip-valid --skip-validation --fetch-remote-resources --local-files --results --results-arf --report --oval-results --export-variables --cpe --check-engine-results --progress --progress-full"
|
192 |
- |
38 |
opts[oscap:xccdf:resolve]="-o --output -f --force"
|
|
|
39 |
opts[oscap:xccdf:generate]="--profile"
|
203 |
- |
40 |
opts[oscap:xccdf:generate:report]="-o --output --result-id --profile --oval-template --sce-template"
|
|
|
41 |
opts[oscap:xccdf:generate:guide]="-o --output --hide-profile-info --profile --benchmark-id --xccdf-id --tailoring-file --tailoring-id --skip-signature-validation --enforce-signature"
|
|
|
42 |
opts[oscap:xccdf:generate:fix]="-o --output --template --profile --result-id --profile --fix-type --xccdf-id --benchmark-id --tailoring-file --tailoring-id --skip-signature-validation --enforce-signature"
|
192 |
- |
43 |
opts[oscap:xccdf:generate:custom]="-o --output --stylesheet"
|
203 |
- |
44 |
opts[oscap:ds:sds-add]="--datastream-id --skip-valid --skip-validation"
|
|
|
45 |
opts[oscap:ds:sds-compose]="--skip-valid --skip-validation"
|
204 |
- |
46 |
opts[oscap:ds:sds-split]="--datastream-id --xccdf-id --skip-valid --skip-validation --fetch-remote-resources --local-files"
|
203 |
- |
47 |
opts[oscap:ds:rds-create]="--skip-valid --skip-validation"
|
|
|
48 |
opts[oscap:ds:rds-split]="--report-id --skip-valid --skip-validation"
|
192 |
- |
49 |
opts[oscap:cvss:score]=""
|
|
|
50 |
opts[oscap:cvss:describe]=""
|
204 |
- |
51 |
opts[oscap:info]="--fetch-remote-resources --local-files --profile --profiles"
|
192 |
- |
52 |
|
|
|
53 |
# local variables
|
|
|
54 |
local std cmd i prev
|
|
|
55 |
local c=1
|
|
|
56 |
local cur="`_get_cword`"
|
|
|
57 |
local prog="${COMP_WORDS[0]}"
|
|
|
58 |
local modpath='oscap'
|
|
|
59 |
_split_longopt || prev="${COMP_WORDS[$COMP_CWORD-1]}"
|
|
|
60 |
|
|
|
61 |
# get module path
|
|
|
62 |
while [ $c -lt $COMP_CWORD ]; do
|
|
|
63 |
i="${COMP_WORDS[c]}"
|
|
|
64 |
case "$i" in
|
|
|
65 |
# TODO handle generic switches
|
|
|
66 |
-*) _oscap_noarg "$i"; c=$((c + $?)) ;;
|
|
|
67 |
*) modpath="$modpath:$i" ;;
|
|
|
68 |
esac
|
|
|
69 |
c=$((c + 1))
|
|
|
70 |
done
|
|
|
71 |
|
|
|
72 |
if [ "x${prev:0:1}" == "x-" ] && ! _oscap_noarg "$prev"; then
|
|
|
73 |
# an option argument
|
|
|
74 |
|
|
|
75 |
local cmd=${modpath##*:}
|
|
|
76 |
|
|
|
77 |
case "$prev" in
|
|
|
78 |
--AV|--AC|--AU|--CI|--II|--AI|--EX|--RL|--RC|--CD|--TD|--CR|--IR|--AR)
|
|
|
79 |
COMPREPLY=( $(compgen -W "`$prog cvss $cmd -h | sed -r -n -e "s:^\s+$prev=\[(.+)\].+$:\1:gp" | tr '|' ' '`" -- ${cur}) ) ;;
|
|
|
80 |
--results|-o|--output|--template|--oval-template) _filedir 'xml.bz2|xml' ;;
|
|
|
81 |
--report) _filedir 'html' ;;
|
|
|
82 |
esac
|
|
|
83 |
|
|
|
84 |
elif [ "x${cur:0:1}" == "x-" ] || [ "${modpath:0:11}" == 'oscap:cvss:' ]; then
|
|
|
85 |
# an option
|
|
|
86 |
COMPREPLY=( $(compgen -W "${opts[$modpath]}" -- ${cur}) )
|
|
|
87 |
elif [ "x${cmds[$modpath]}" != 'x' ]; then
|
|
|
88 |
# a submodule
|
|
|
89 |
COMPREPLY=( $(compgen -W "${cmds[$modpath]}" -- ${cur}) )
|
|
|
90 |
else
|
|
|
91 |
# a positional argument
|
|
|
92 |
|
|
|
93 |
case "$modpath" in
|
|
|
94 |
oscap:cvss:*) ;; # no positional args for cvss
|
|
|
95 |
*) _filedir 'xml.bz2|xml' ;;
|
|
|
96 |
esac
|
|
|
97 |
|
|
|
98 |
fi
|
|
|
99 |
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
[ "${BASH_VERSINFO[0]}" -ge '4' ] && complete -F _oscap -o filenames oscap
|
|
|
103 |
|