Skip to content

Commit 2e25017

Browse files
author
Martin Preisler
committed
Merge branch 'maint-1.2'
2 parents 620a836 + 2a739d4 commit 2e25017

File tree

13 files changed

+246
-131
lines changed

13 files changed

+246
-131
lines changed

cpe/openscap-cpe-dict.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
<title xml:lang="en-us">Fedora 29</title>
110110
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="openscap-cpe-oval.xml">oval:org.open-scap.cpe.fedora:def:29</check>
111111
</cpe-item>
112+
<cpe-item name="cpe:/o:fedoraproject:fedora:30">
113+
<title xml:lang="en-us">Fedora 30</title>
114+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="openscap-cpe-oval.xml">oval:org.open-scap.cpe.fedora:def:30</check>
115+
</cpe-item>
112116
<cpe-item name="cpe:/o:suse:sle">
113117
<title xml:lang="en-us">SUSE Linux Enterprise all versions</title>
114118
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="openscap-cpe-oval.xml">oval:org.open-scap.cpe.sle:def:1</check>

cpe/openscap-cpe-oval.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,19 @@
367367
<criterion comment="Fedora 29 is installed" test_ref="oval:org.open-scap.cpe.fedora:tst:29"/>
368368
</criteria>
369369
</definition>
370+
<definition class="inventory" id="oval:org.open-scap.cpe.fedora:def:30" version="1">
371+
<metadata>
372+
<title>Fedora 30</title>
373+
<affected family="unix">
374+
<platform>Fedora 30</platform>
375+
</affected>
376+
<reference ref_id="cpe:/o:fedoraproject:fedora:30" source="CPE"/>
377+
<description>The operating system installed on the system is Fedora 30</description>
378+
</metadata>
379+
<criteria>
380+
<criterion comment="Fedora 30 is installed" test_ref="oval:org.open-scap.cpe.fedora:tst:30"/>
381+
</criteria>
382+
</definition>
370383

371384
<definition class="inventory" id="oval:org.open-scap.cpe.sle:def:1" version="1">
372385
<metadata>
@@ -735,6 +748,11 @@
735748
<object object_ref="oval:org.open-scap.cpe.fedora-release:obj:2"/>
736749
<state state_ref="oval:org.open-scap.cpe.fedora:ste:29"/>
737750
</rpminfo_test>
751+
<rpminfo_test check_existence="at_least_one_exists" id="oval:org.open-scap.cpe.fedora:tst:30" version="1" check="at least one" comment="fedora-release is version Fedora 30"
752+
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
753+
<object object_ref="oval:org.open-scap.cpe.fedora-release:obj:2"/>
754+
<state state_ref="oval:org.open-scap.cpe.fedora:ste:30"/>
755+
</rpminfo_test>
738756
<rpminfo_test check_existence="at_least_one_exists" id="oval:org.open-scap.cpe.sles:tst:1" version="1" check="at least one" comment="/etc/sles-release is provided by sles-release package"
739757
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
740758
<object object_ref="oval:org.open-scap.cpe.sles-release:obj:1"/>
@@ -999,6 +1017,9 @@
9991017
<rpminfo_state id="oval:org.open-scap.cpe.fedora:ste:29" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
10001018
<version operation="pattern match">^29$</version>
10011019
</rpminfo_state>
1020+
<rpminfo_state id="oval:org.open-scap.cpe.fedora:ste:30" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
1021+
<version operation="pattern match">^30$</version>
1022+
</rpminfo_state>
10021023
<rpminfo_state id="oval:org.open-scap.cpe.sles:ste:1" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
10031024
<name operation="pattern match">^sles-release</name>
10041025
</rpminfo_state>

src/CVRF/cvrf_priv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,7 @@ struct cvrf_product_tree *cvrf_product_tree_parse(xmlTextReaderPtr reader) {
19831983
struct cvrf_product_tree *tree = cvrf_product_tree_new();
19841984
if (xmlTextReaderIsEmptyElement(reader) == 1) {
19851985
cvrf_set_parsing_error("ProductTree");
1986+
cvrf_product_tree_free(tree);
19861987
return NULL;
19871988
}
19881989
xmlTextReaderNextElementWE(reader, TAG_PRODUCT_TREE);
@@ -2088,6 +2089,7 @@ struct cvrf_note *cvrf_note_parse(xmlTextReaderPtr reader) {
20882089
struct cvrf_note *note = cvrf_note_new();
20892090
if (xmlTextReaderIsEmptyElement(reader) == 1) {
20902091
cvrf_set_parsing_error("Note");
2092+
cvrf_note_free(note);
20912093
return NULL;
20922094
}
20932095

@@ -2146,6 +2148,7 @@ struct cvrf_doc_tracking *cvrf_doc_tracking_parse(xmlTextReaderPtr reader) {
21462148
struct cvrf_doc_tracking *tracking = cvrf_doc_tracking_new();
21472149
if (xmlTextReaderIsEmptyElement(reader) == 1) {
21482150
cvrf_set_parsing_error("DocumentTracking");
2151+
cvrf_doc_tracking_free(tracking);
21492152
return NULL;
21502153
}
21512154

@@ -2217,6 +2220,7 @@ struct cvrf_doc_publisher *cvrf_doc_publisher_parse(xmlTextReaderPtr reader) {
22172220
publisher->type = cvrf_doc_publisher_type_parse(reader);
22182221
if (publisher->type == CVRF_DOC_PUBLISHER_UNKNOWN && xmlTextReaderIsEmptyElement(reader) == 1) {
22192222
cvrf_set_parsing_error("DocumentPublisher");
2223+
cvrf_doc_publisher_free(publisher);
22202224
return NULL;
22212225
}
22222226
publisher->vendor_id = (char *)xmlTextReaderGetAttribute(reader, ATTR_VENDOR_ID);

src/OVAL/oval_message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct oval_message *oval_message_clone(struct oval_message *old_message)
6565
oval_message_level_t level = oval_message_get_level(old_message);
6666
oval_message_set_level(new_message, level);
6767
char *text = oval_message_get_text(old_message);
68-
oval_message_set_text(new_message, oscap_strdup(text));
68+
oval_message_set_text(new_message, text);
6969
return new_message;
7070
}
7171

src/OVAL/oval_sysEnt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct oval_sysent *oval_sysent_clone(struct oval_syschar_model *new_model, stru
7777

7878
char *old_value = oval_sysent_get_value(old_item);
7979
if (old_value) {
80-
oval_sysent_set_value(new_item, oscap_strdup(old_value));
80+
oval_sysent_set_value(new_item, old_value);
8181
}
8282

8383
char *old_name = oval_sysent_get_name(old_item);

src/OVAL/probes/fsdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ fsdev_t *fsdev_strinit(const char *fs_names)
408408
e = errno;
409409
free(fs_arr);
410410
errno = e;
411+
free(pstr);
411412

412413
return (lfs);
413414
}

src/XCCDF_POLICY/xccdf_policy.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,8 +2156,10 @@ void xccdf_policy_free(struct xccdf_policy * policy) {
21562156
/* A policy which is set to use default profile has its profile member set to NULL,
21572157
* check it so we don't try to get the ID from a NULL profile.
21582158
* */
2159-
if (policy->profile && xccdf_profile_get_id(policy->profile) == NULL)
2160-
/* If ID of policy's profile is NULL then this
2159+
if (policy->profile && (
2160+
(xccdf_profile_get_id(policy->profile) == NULL) ||
2161+
(strcmp(xccdf_profile_get_id(policy->profile), "(all)") == 0)))
2162+
/* If ID of policy's profile is NULL or "(all)" then this
21612163
* profile is created by Policy layer and need
21622164
* to be freed
21632165
*/

src/XCCDF_POLICY/xccdf_policy_model.c

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "xccdf_policy_model_priv.h"
3232
#include "xccdf_policy_priv.h"
3333
#include "XCCDF/item.h"
34+
#include "XCCDF/helpers.h"
3435

3536
struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_policy_model *policy_model, const char *profile_id)
3637
{
@@ -46,6 +47,33 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
4647
return NULL;
4748
}
4849

50+
static void _add_selectors_for_all_xccdf_items(struct xccdf_profile *profile, struct xccdf_item *item)
51+
{
52+
struct xccdf_item_iterator *children = NULL;
53+
if (xccdf_item_get_type(item) == XCCDF_BENCHMARK) {
54+
children = xccdf_benchmark_get_content(XBENCHMARK(item));
55+
} else if (xccdf_item_get_type(item) == XCCDF_GROUP) {
56+
children = xccdf_group_get_content(XGROUP(item));
57+
}
58+
59+
if (xccdf_item_get_type(item) == XCCDF_RULE ||
60+
xccdf_item_get_type(item) == XCCDF_GROUP)
61+
{
62+
struct xccdf_select *select = xccdf_select_new();
63+
xccdf_select_set_item(select, xccdf_item_get_id(item));
64+
xccdf_select_set_selected(select, true);
65+
xccdf_profile_add_select(profile, select);
66+
}
67+
68+
if (children) {
69+
while (xccdf_item_iterator_has_more(children)) {
70+
struct xccdf_item *current = xccdf_item_iterator_next(children);
71+
_add_selectors_for_all_xccdf_items(profile, current);
72+
}
73+
xccdf_item_iterator_free(children);
74+
}
75+
}
76+
4977
struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_model *policy_model, const char *id)
5078
{
5179
struct xccdf_profile *profile = NULL;
@@ -56,6 +84,9 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
5684
profile = xccdf_tailoring_get_profile_by_id(tailoring, id);
5785
}
5886

87+
// The (default) and (all) profiles are de-facto owned by the xccdf_policy
88+
// and will be freed by it when it's freed. See xccdf_policy_free.
89+
5990
if (!profile) {
6091
if (id == NULL) {
6192
profile = xccdf_profile_new();
@@ -64,16 +95,27 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
6495
oscap_text_set_text(title, "No profile (default benchmark)");
6596
oscap_text_set_lang(title, "en");
6697
xccdf_profile_add_title(profile, title);
67-
}
68-
else {
98+
} else {
6999
struct xccdf_benchmark *benchmark = xccdf_policy_model_get_benchmark(policy_model);
70100
if (benchmark == NULL) {
71101
assert(benchmark != NULL);
72102
return NULL;
73103
}
74-
profile = xccdf_benchmark_get_profile_by_id(benchmark, id);
75-
if (profile == NULL)
76-
return NULL;
104+
105+
if (strcmp(id, "(all)") == 0) {
106+
profile = xccdf_profile_new();
107+
xccdf_profile_set_id(profile, "(all)");
108+
struct oscap_text *title = oscap_text_new();
109+
oscap_text_set_text(title, "(all) profile (all rules selected)");
110+
oscap_text_set_lang(title, "en");
111+
xccdf_profile_add_title(profile, title);
112+
113+
_add_selectors_for_all_xccdf_items(profile, XITEM(benchmark));
114+
} else {
115+
profile = xccdf_benchmark_get_profile_by_id(benchmark, id);
116+
if (profile == NULL)
117+
return NULL;
118+
}
77119
}
78120
}
79121

utils/oscap-docker.in

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,18 @@ import sys
2626
from requests import exceptions
2727

2828

29-
class OscapDocker(object):
30-
''' Generic class to call the scans '''
31-
def __init__(self):
32-
pass
33-
34-
def set_args(self, args, unknown):
35-
'''
36-
Sets arguments for argparse into the oscapDocker class
37-
'''
38-
self.args = args
39-
self.unknown_args = unknown
40-
41-
def cve_scan(self):
42-
''' Wrapper function for container/image scanning '''
43-
OS = OscapScan()
44-
result = OS.scan_cve(self.args.scan_target, self.unknown_args)
45-
if result is not None:
46-
print(result)
47-
48-
def scan(self):
49-
''' Wrapper functiopn to scan with openscap'''
50-
OS = OscapScan()
51-
result = OS.scan(self.args.scan_target, self.unknown_args)
52-
if result is not None:
53-
print(result)
29+
def cve_scan(scan_target, other_scan_args):
30+
''' Wrapper function for container/image scanning '''
31+
OS = OscapScan()
32+
result = OS.scan_cve(scan_target, other_scan_args)
33+
return result
34+
35+
36+
def scan(scan_target, other_scan_args):
37+
''' Wrapper function to scan with openscap'''
38+
OS = OscapScan()
39+
result = OS.scan(scan_target, other_scan_args)
40+
return result
5441

5542

5643
def ping_docker():
@@ -63,10 +50,8 @@ def ping_docker():
6350
client = docker.Client()
6451
client.ping()
6552

66-
if __name__ == '__main__':
67-
68-
OD = OscapDocker()
6953

54+
if __name__ == '__main__':
7055
parser = argparse.ArgumentParser(description='oscap docker',
7156
epilog='See `man oscap` to learn \
7257
more about OSCAP-ARGUMENTS')
@@ -75,32 +60,32 @@ if __name__ == '__main__':
7560
# Scan CVEs in image
7661
image_cve = subparser.add_parser('image-cve', help='Scan a docker image \
7762
for known vulnerabilities.')
78-
image_cve.set_defaults(func=OD.cve_scan)
63+
image_cve.set_defaults(func=cve_scan)
7964
image_cve.add_argument('scan_target', help='Container or image to scan')
8065

8166
# Scan an Image
8267
image = subparser.add_parser('image', help='Scan a docker image')
8368
image.add_argument('scan_target',
8469
help='Container or image to scan')
8570

86-
image.set_defaults(func=OD.scan)
71+
image.set_defaults(func=scan)
8772
# Scan a container
8873
container = subparser.add_parser('container', help='Scan a running docker\
8974
container of given name.')
9075
container.add_argument('scan_target',
9176
help='Container or image to scan')
92-
container.set_defaults(func=OD.scan)
77+
container.set_defaults(func=scan)
9378

9479
# Scan CVEs in container
9580
container_cve = subparser.add_parser('container-cve', help='Scan a \
9681
running container for known \
9782
vulnerabilities.')
9883

99-
container_cve.set_defaults(func=OD.cve_scan)
84+
container_cve.set_defaults(func=cve_scan)
10085
container_cve.add_argument('scan_target',
10186
help='Container or image to scan')
10287

103-
args, unknown = parser.parse_known_args()
88+
args, leftover_args = parser.parse_known_args()
10489

10590
if "func" not in args:
10691
parser.print_help()
@@ -113,5 +98,10 @@ if __name__ == '__main__':
11398
print("The docker daemon does not appear to be running")
11499
sys.exit(1)
115100

116-
OD.set_args(args, unknown)
117-
args.func()
101+
try:
102+
rc = args.func(args.scan_target, leftover_args)
103+
except Exception as exc:
104+
sys.exit(255)
105+
raise exc
106+
107+
sys.exit(rc)

0 commit comments

Comments
 (0)