Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
secrules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
tools
secrules
Commits
9eace7214a4c
Commit
9eace7214a4c
authored
1 year ago
by
jfp
Browse files
Options
Downloads
Patches
Plain Diff
Move file as __main__.py into the module
parent
a152158c3b47
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.hgignore
+2
-0
2 additions, 0 deletions
.hgignore
securityrules.py
+0
-164
0 additions, 164 deletions
securityrules.py
with
2 additions
and
164 deletions
.hgignore
+
2
−
0
View file @
9eace721
...
@@ -20,3 +20,5 @@
...
@@ -20,3 +20,5 @@
.*.log\..*
.*.log\..*
.*/\.pytest_cache/
.*/\.pytest_cache/
^\.vscode/sftp\.json
^\.vscode/sftp\.json
^build/
^secrules.egg-info/
This diff is collapsed.
Click to expand it.
securityrules.py
deleted
100644 → 0
+
0
−
164
View file @
a152158c
# -*- coding: iso-8859-1 -*-
import
sys
import
os
import
re
import
argparse
import
importlib
DEBUG
=
False
if
DEBUG
:
import
debugpy
# 5678 is the default attach port in the VS Code debug configurations.
# Unless a host and port are specified, host defaults to 127.0.0.1
debugpy
.
configure
(
subProcess
=
False
)
debugpy
.
listen
((
'
0.0.0.0
'
,
5678
),
in_process_debug_adapter
=
True
)
print
(
'
Waiting for debugger attach
'
)
debugpy
.
wait_for_client
()
debugpy
.
breakpoint
()
print
(
'
break on this line
'
)
all_rules
=
{}
args
=
None
def
rules_exec
(
seclass
,
numrule
=
None
,
info
=
False
,
fo
=
None
,
export
=
None
):
global
all_rules
,
args
rules
=
all_rules
[
seclass
][
1
]
m
=
all_rules
[
seclass
][
0
]
if
numrule
is
None
:
for
r
in
rules
:
if
info
:
print
(
getattr
(
m
,
r
).
__name__
)
print
(
getattr
(
m
,
r
).
__doc__
)
print
()
else
:
getattr
(
m
,
r
)(
fo
,
export
)
else
:
for
n
in
numrule
:
rname
=
'
rule%s%02d
'
%
(
seclass
[
-
2
:],
n
)
if
rname
in
rules
:
if
info
:
print
(
getattr
(
m
,
rname
).
__name__
)
print
(
getattr
(
m
,
rname
).
__doc__
)
print
()
else
:
getattr
(
m
,
rname
)(
fo
,
export
)
class
InflateRange
(
argparse
.
Action
):
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
lst
=
[]
for
string
in
values
:
# type: ignore
string
=
string
.
replace
(
'
(
'
,
''
)
string
=
string
.
replace
(
'
)
'
,
''
)
if
'
-
'
in
string
or
'
:
'
in
string
:
string
=
string
.
replace
(
'
:
'
,
'
-
'
)
m
=
re
.
match
(
r
'
(\d+)(?:-(\d+))?$
'
,
string
)
# ^ (or use .split('-'). anyway you like.)
if
not
m
:
raise
argparse
.
ArgumentTypeError
(
"'"
+
string
+
"'
is not a range of number. Expected forms like
'
0-5
'
or
'
2
'
.
"
)
start
=
m
.
group
(
1
)
end
=
m
.
group
(
2
)
or
start
lst
.
extend
(
list
(
range
(
int
(
start
,
10
),
int
(
end
,
10
)
+
1
)))
else
:
string
=
string
.
replace
(
'
,
'
,
'
'
)
for
string
in
string
.
split
(
'
'
):
if
string
:
lst
.
append
(
int
(
string
))
setattr
(
namespace
,
self
.
dest
,
lst
)
def
load_rules
(
levels
):
global
all_rules
mods
=
[
fn
[:
-
3
]
for
fn
in
os
.
listdir
(
'
./secrules
'
)
if
fn
.
startswith
(
'
rule
'
)
and
fn
[
-
1
:].
lower
()
==
'
y
'
]
all_rules
=
{}
for
modn
in
mods
:
m
=
importlib
.
import_module
(
'
.
'
+
modn
,
'
secrules
'
)
# m = __import__('secrules.' + modn, globals(), locals(), ['*'], -1)
lst
=
[
m
,
[]]
for
r
in
dir
(
m
):
if
r
.
startswith
(
'
rule
'
):
if
(
levels
is
None
or
not
hasattr
(
getattr
(
m
,
r
),
'
rule_level
'
)
or
getattr
(
m
,
r
).
rule_level
in
levels
):
lst
[
1
].
append
(
r
)
all_rules
[
modn
]
=
lst
# all_rules[modn] = (m, [r for r in dir(m) if r.startswith('rule')])
def
main
():
global
args
parser
=
argparse
.
ArgumentParser
(
description
=
'
security checker
'
)
parser
.
add_argument
(
'
--output
'
,
type
=
argparse
.
FileType
(
'
w
'
),
dest
=
'
fo
'
,
metavar
=
'
out-file
'
,
help
=
'
output file
'
,
default
=
sys
.
stdout
,
)
parser
.
add_argument
(
'
--class
'
,
type
=
int
,
dest
=
'
seclass
'
,
help
=
'
security class
'
)
parser
.
add_argument
(
'
--rule
'
,
action
=
InflateRange
,
nargs
=
'
*
'
,
dest
=
'
numrule
'
,
help
=
'
rule number
'
,
)
parser
.
add_argument
(
'
--export
'
,
action
=
'
store_true
'
,
dest
=
'
export
'
,
default
=
False
,
help
=
'
export format
'
,
)
parser
.
add_argument
(
'
--info
'
,
action
=
'
store_true
'
,
dest
=
'
info
'
,
default
=
False
,
help
=
'
Rules info
'
,
)
parser
.
add_argument
(
'
--level
'
,
action
=
InflateRange
,
nargs
=
'
*
'
,
dest
=
'
levels
'
,
help
=
'
rule levels
'
,
)
args
=
parser
.
parse_args
()
load_rules
(
args
.
levels
)
if
args
.
seclass
is
None
:
if
args
.
numrule
is
not
None
:
raise
argparse
.
ArgumentTypeError
(
'
missing seclass argument
'
)
lst
=
list
(
all_rules
.
keys
())
lst
.
sort
()
for
seclass
in
lst
:
# seclass = 'rules%02d' % args.seclass
rules_exec
(
seclass
,
args
.
numrule
,
args
.
info
,
args
.
fo
,
args
.
export
)
else
:
seclass
=
'
rules%02d
'
%
args
.
seclass
rules_exec
(
seclass
,
args
.
numrule
,
args
.
info
,
args
.
fo
,
args
.
export
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment