Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kernel-hardening-checker
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
kernel-hardening-checker
Commits
e31b7f2a
Commit
e31b7f2a
authored
Jul 09, 2018
by
anthraxx
Committed by
Alexander Popov
Jul 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
argparse: using python module instead of manual getopt
parent
a2b319a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
26 deletions
+22
-26
kconfig-hardened-check.py
kconfig-hardened-check.py
+22
-26
No files found.
kconfig-hardened-check.py
View file @
e31b7f2a
...
...
@@ -16,8 +16,9 @@
# pti=on
# kernel.kptr_restrict=1
import
sys
,
getopt
import
sys
from
collections
import
namedtuple
from
argparse
import
ArgumentParser
import
re
debug_mode
=
False
# set it to True to print the unknown options from the config
...
...
@@ -213,33 +214,28 @@ def check_config_file(fname):
f
.
close
()
def
usage
(
name
):
print
(
'Usage: {} [-p | -c <config_file>] '
.
format
(
name
))
print
(
' -p, --print
\n\t
print hardening preferences'
)
print
(
' -c <config_file>, --config=<config_file>
\n\t
check the config_file against these preferences'
)
sys
.
exit
(
1
)
if
__name__
==
'__main__'
:
parser
=
ArgumentParser
(
description
=
'Kconfig hardened check'
)
parser
.
add_argument
(
'-p'
,
'--print'
,
default
=
False
,
action
=
'store_true'
,
help
=
'print hardening preferences'
)
parser
.
add_argument
(
'-c'
,
'--config'
,
help
=
'check the config_file against these preferences'
)
parser
.
add_argument
(
'--debug'
,
default
=
False
,
action
=
'store_true'
,
help
=
'enable internal debug mode'
)
args
=
parser
.
parse_args
()
construct_opt_list
()
def
main
(
argv
):
try
:
opts
,
args
=
getopt
.
getopt
(
argv
[
1
:],
'pc:'
,
[
'print'
,
'config='
])
except
getopt
.
GetoptError
:
usage
(
argv
[
0
])
if
not
opts
:
usage
(
argv
[
0
])
if
args
.
print
:
print_opt_list
()
sys
.
exit
(
0
)
construct_opt_list
()
if
args
.
debug
:
debug_mode
=
True
for
opt
,
arg
in
opts
:
if
opt
in
(
'-p'
,
'--print'
):
print_opt_list
()
sys
.
exit
()
elif
opt
in
(
'-c'
,
'--config'
):
check_config_file
(
arg
)
if
error_count
==
0
:
print
(
'[+] config check is PASSED'
)
else
:
sys
.
exit
(
'[-] config check is NOT PASSED: {} errors'
.
format
(
error_count
))
if
args
.
config
:
check_config_file
(
args
.
config
)
if
error_count
==
0
:
print
(
'[+] config check is PASSED'
)
sys
.
exit
(
0
)
else
:
sys
.
exit
(
'[-] config check is NOT PASSED: {} errors'
.
format
(
error_count
))
main
(
sys
.
argv
)
parser
.
print_help
(
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment