Open SCAP Library

item.h
1 /*
2 * Copyright 2009--2013 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors:
20 * Lukas Kuklinek <lkuklinek@redhat.com>
21 */
22
23 #ifndef XCCDF_ITEM_
24 #define XCCDF_ITEM_
25
26 #include <assert.h>
27
28 #include "public/xccdf_benchmark.h"
29 #include "elements.h"
30
31 #include "common/reference_priv.h"
32 #include "common/list.h"
33 #include "common/util.h"
34 #include "common/text_priv.h"
35
36 OSCAP_HIDDEN_START;
37
38 struct xccdf_flags {
39 bool selected:1;
40 bool hidden:1;
41 bool resolved:1;
42 bool abstract:1;
43 bool prohibit_changes:1;
44 bool interactive:1;
45 bool multiple:1;
46 };
47
48 struct xccdf_defflags {
49 bool selected:1;
50 bool hidden:1;
51 bool resolved:1;
52 bool abstract:1;
53 bool prohibit_changes:1;
54 bool interactive:1;
55 bool multiple:1;
56 bool weight:1;
57 bool role:1;
58 bool severity:1;
59 };
60
61 struct xccdf_item;
62 struct xccdf_check;
63
64 struct xccdf_item_base {
65 char *id;
66 char *cluster_id;
67 float weight;
68
69 struct oscap_list *title;
70 struct oscap_list *description;
71 struct oscap_list *question;
72 struct oscap_list *rationale;
73 struct oscap_list *warnings;
74
75 char *version;
76 char *version_update;
77 char *version_time;
78
79 struct xccdf_item *parent;
80 char *extends;
81 struct oscap_list *statuses;
82 struct oscap_list *dc_statuses;
83 struct oscap_list *references;
84 struct oscap_list *platforms;
85 struct xccdf_flags flags;
86 struct xccdf_defflags defined_flags;
87
88 struct oscap_list *metadata;
89 };
90
91 struct xccdf_rule_item {
92 char *impact_metric;
93 xccdf_role_t role;
94 xccdf_level_t severity;
95
96 struct oscap_list *requires;
97 struct oscap_list *conflicts;
98
99 struct oscap_list *profile_notes;
100 struct oscap_list *idents;
101 struct oscap_list *checks;
102 struct oscap_list *fixes;
103 struct oscap_list *fixtexts;
104 };
105
106 struct xccdf_group_item {
107 struct oscap_list *requires;
108 struct oscap_list *conflicts;
109
110 struct oscap_list *values;
111 struct oscap_list *content;
112 };
113
114 /* This structure is used for multiple-count attributes for Item (0-n) */
115 struct xccdf_value_instance {
116 char *selector;
117 xccdf_value_type_t type; /* Value::type */
118 char *value; /* Value::value */
119 char *defval; /* Value::default */
120 struct oscap_list *choices; /* Value::choices */
121 xccdf_numeric lower_bound;
122 xccdf_numeric upper_bound;
123 char *match;
124 struct {
125 bool value_given : 1;
126 bool defval_given : 1;
127 bool must_match_given : 1;
128 bool must_match : 1;
129 } flags;
130 };
131
132 struct xccdf_value_item {
133 xccdf_value_type_t type; /* Value::type */
134 xccdf_interface_hint_t interface_hint; /* Value::interfaceHint */
135 xccdf_operator_t oper; /* Value::operator */
136
137 struct oscap_list *instances;
138 struct oscap_list *sources; /* Value::source */
139 };
140
141 struct xccdf_result_item {
142 const struct xccdf_version_info *schema_version;
143
144 char *start_time;
145 char *end_time;
146 char *test_system;
147 char *benchmark_uri;
148 char *profile;
149
150 struct oscap_list *identities;
151 struct oscap_list *targets;
152 struct oscap_list *organizations;
153 struct oscap_list *remarks;
154 struct oscap_list *target_addresses;
155 struct oscap_list *target_facts;
156 struct oscap_list *target_id_refs;
157 struct oscap_list *applicable_platforms;
158 struct oscap_list *setvalues;
159 struct oscap_list *rule_results;
160 struct oscap_list *scores;
161 };
162
163 struct xccdf_profile_item {
164 char *note_tag;
165 struct oscap_list *selects;
166 struct oscap_list *setvalues;
167 struct oscap_list *refine_values;
168 struct oscap_list *refine_rules;
169 bool tailoring;
170 };
171
172 struct xccdf_tailoring {
173 // optional, only relevant when Tailoring is saved as a root element
174 char *id;
175
176 // The ref is "just informative" according to the spec, we never
177 // interpret it and just load and save it as a string.
178 char *benchmark_ref;
179 // Also just informative
180 char *benchmark_ref_version;
181
182 struct oscap_list *statuses;
183 struct oscap_list *dc_statuses;
184
185 char *version;
186 char *version_update;
187 char *version_time;
188
189 struct oscap_list *metadata;
190
191 struct oscap_list *profiles;
192 };
193
194 struct xccdf_benchmark_item {
195 const struct xccdf_version_info *schema_version;
196
197 struct oscap_htable *items_dict; /* Stores only xccdf:Item */
198 struct oscap_htable *profiles_dict; /* xccdf:Profile */
199 struct oscap_htable *results_dict; /* xccdf:TestResult */
200 struct oscap_htable *clusters_dict; /* xccdf:items by cluster-id */
201 struct oscap_list *notices;
202 struct oscap_list *plain_texts;
203
204 struct cpe_dict_model *cpe_list;
205 struct cpe_lang_model *cpe_lang_model;
206
207 char *style;
208 char *style_href;
209 char *lang;
210
211 struct oscap_list *front_matter;
212 struct oscap_list *rear_matter;
213
214 struct oscap_list *models;
215 struct oscap_list *profiles;
216 struct oscap_list *values;
217 struct oscap_list *content;
218 struct oscap_list *results;
219 };
220
221 struct xccdf_item {
222 xccdf_type_t type;
223 struct xccdf_item_base item;
224 union {
225 struct xccdf_profile_item profile;
226 struct xccdf_benchmark_item benchmark;
227 struct xccdf_rule_item rule;
228 struct xccdf_group_item group;
229 struct xccdf_value_item value;
230 struct xccdf_result_item result;
231 } sub;
232 };
233
234 struct xccdf_warning {
235 struct oscap_text *text;
236 xccdf_warning_category_t category;
237 };
238
239 struct xccdf_notice {
240 char *id;
241 struct oscap_text *text;
242 };
243
244 struct xccdf_status {
245 xccdf_status_type_t status;
246 time_t date;
247 };
248
249 struct xccdf_model {
250 char *system;
251 struct oscap_htable *params; // TODO: to list + accessors
252 };
253
254 struct xccdf_select {
255 char *item;
256 bool selected;
257 struct oscap_list *remarks;
258 };
259
260 struct xccdf_refine_rule {
261 char *item;
262 char *selector;
263 xccdf_role_t role;
264 xccdf_level_t severity;
265 xccdf_numeric weight;
266 struct oscap_list *remarks;
267 };
268
269 struct xccdf_refine_value {
270 char *item;
271 char *selector;
272 xccdf_operator_t oper;
273 struct oscap_list *remarks;
274 };
275
276 struct xccdf_setvalue {
277 char *item;
278 char *value;
279 };
280
281 struct xccdf_ident {
282 char *id;
283 char *system;
284 };
285
286 struct xccdf_check {
287 xccdf_bool_operator_t oper;
288 struct oscap_list *children;
289 char *id;
290 char *system;
291 char *selector;
292 char *content;
293 struct _xccdf_check_flags {
294 bool multicheck:1;
295 bool def_multicheck:1;
296 bool negate:1;
297 bool def_negate:1;
298 } flags;
299 struct oscap_list *imports;
300 struct oscap_list *exports;
301 struct oscap_list *content_refs;
302 };
303
304 struct xccdf_check_content_ref {
305 char *href;
306 char *name;
307 };
308
309 struct xccdf_check_import {
310 char *name;
311 char *xpath;
312 char *content;
313 };
314
315 struct xccdf_check_export {
316 char *name;
317 char *value;
318 };
319
320 struct xccdf_profile_note {
321 struct oscap_text *text;
322 char *reftag;
323 };
324
325 struct xccdf_fix {
326 bool reboot;
327 xccdf_strategy_t strategy;
328 xccdf_level_t disruption;
329 xccdf_level_t complexity;
330 char *id;
331 char *content;
332 char *system;
333 char *platform;
334 };
335
336 struct xccdf_fixtext {
337 struct oscap_text *text;
338 bool reboot;
339 xccdf_strategy_t strategy;
340 xccdf_level_t disruption;
341 xccdf_level_t complexity;
342 char *fixref;
343 };
344
345 struct xccdf_rule_result {
346 char *idref;
347 xccdf_role_t role;
348 char *time;
349 float weight;
350 xccdf_level_t severity;
351 xccdf_test_result_type_t result;
352 char *version;
353
354 struct oscap_list *overrides;
355 struct oscap_list *idents;
356 struct oscap_list *messages;
357 struct oscap_list *instances;
358 struct oscap_list *fixes;
359 struct oscap_list *checks;
360 };
361
362 struct xccdf_identity {
363 struct {
364 bool authenticated : 1;
365 bool privileged : 1;
366 } sub;
367 char *name;
368 };
369
370 struct xccdf_score {
371 xccdf_numeric maximum;
372 xccdf_numeric score;
373 char *system;
374 };
375
376 struct xccdf_override {
377 char *time;
378 char *authority;
379 xccdf_test_result_type_t old_result;
380 xccdf_test_result_type_t new_result;
381 struct oscap_text *remark;
382 };
383
384 struct xccdf_message {
385 xccdf_message_severity_t severity;
386 char *content;
387 };
388
389 struct xccdf_target_fact {
390 xccdf_value_type_t type;
391 char *name;
392 char *value;
393 };
394
395 struct xccdf_target_identifier {
396 bool any_element; // if false, this represents <target-id-ref>, else it's any element
397
398 xmlNodePtr element;
399
400 char *system;
401 char *href;
402 char *name;
403 };
404
405 struct xccdf_instance {
406 char *context;
407 char *parent_context;
408 char *content;
409 };
410
411 struct xccdf_plain_text {
412 char *id;
413 char *text;
414 };
415
416 extern const struct oscap_string_map XCCDF_LEVEL_MAP[];
417 extern const struct oscap_string_map XCCDF_ROLE_MAP[];
418 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[];
419 extern const struct oscap_string_map XCCDF_BOOLOP_MAP[];
420 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[];
421 extern const struct oscap_string_map XCCDF_FACT_TYPE_MAP[];
422 extern const struct oscap_string_map XCCDF_RESULT_MAP[];
423
424 extern const struct oscap_text_traits XCCDF_TEXT_PLAIN;
425 extern const struct oscap_text_traits XCCDF_TEXT_HTML;
426 extern const struct oscap_text_traits XCCDF_TEXT_PLAINSUB;
427 extern const struct oscap_text_traits XCCDF_TEXT_HTMLSUB;
428 extern const struct oscap_text_traits XCCDF_TEXT_NOTICE;
429 extern const struct oscap_text_traits XCCDF_TEXT_PROFNOTE;
430
431 extern const size_t XCCDF_NUMERIC_SIZE;
432 extern const char *XCCDF_NUMERIC_FORMAT;
433
434 struct xccdf_item *xccdf_item_new(xccdf_type_t type, struct xccdf_item *parent);
435 void xccdf_item_release(struct xccdf_item *item);
436 void xccdf_item_print(struct xccdf_item *item, int depth);
437 void xccdf_item_dump(struct xccdf_item *item, int depth);
438 struct xccdf_item* xccdf_item_get_benchmark_internal(struct xccdf_item* item);
439 bool xccdf_benchmark_parse(struct xccdf_item *benchmark, xmlTextReaderPtr reader);
440 void xccdf_benchmark_dump(struct xccdf_benchmark *benchmark);
441 struct oscap_htable_iterator *xccdf_benchmark_get_cluster_items(struct xccdf_benchmark *benchmark, const char *cluster_id);
442 bool xccdf_benchmark_register_item(struct xccdf_benchmark *benchmark, struct xccdf_item *item);
443 bool xccdf_benchmark_unregister_item(struct xccdf_item *item);
444 bool xccdf_benchmark_rename_item(struct xccdf_item *item, const char *newid);
445 char *xccdf_benchmark_gen_id(struct xccdf_benchmark *benchmark, xccdf_type_t type, const char *prefix);
446 struct xccdf_result *xccdf_benchmark_get_result_by_id(struct xccdf_benchmark *benchmark, const char *testresult_id);
447 struct xccdf_result *xccdf_benchmark_get_result_by_id_suffix(struct xccdf_benchmark *benchmark, const char *testresult_suffix);
448 bool xccdf_add_item(struct oscap_list *list, struct xccdf_item *parent, struct xccdf_item *item, const char *prefix);
449
450 struct xccdf_tailoring *xccdf_tailoring_parse(xmlTextReaderPtr reader, struct xccdf_item* benchmark);
451 xmlNodePtr xccdf_tailoring_to_dom(struct xccdf_tailoring *tailoring, xmlDocPtr doc, xmlNodePtr parent, const struct xccdf_version_info *version_info);
452
453 struct xccdf_item *xccdf_profile_new_internal(struct xccdf_item *bench);
454 struct xccdf_item *xccdf_profile_parse(xmlTextReaderPtr reader, struct xccdf_item *bench);
455 void xccdf_profile_dump(struct xccdf_item *prof, int depth);
456
457 bool xccdf_item_process_attributes(struct xccdf_item *item, xmlTextReaderPtr reader);
458 bool xccdf_item_process_element(struct xccdf_item *item, xmlTextReaderPtr reader);
459
460 bool xccdf_content_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
461 struct xccdf_item *xccdf_group_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
462 struct xccdf_item *xccdf_group_new_internal(struct xccdf_item *parent);
463 void xccdf_group_dump(struct xccdf_item *group, int depth);
464
465 struct xccdf_item *xccdf_rule_new_internal(struct xccdf_item *parent);
466 struct xccdf_item *xccdf_rule_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
467 void xccdf_rule_dump(struct xccdf_item *rule, int depth);
468 struct xccdf_check_iterator *xccdf_rule_get_checks_filtered(struct xccdf_item *rule, char *selector);
469 struct xccdf_check_iterator *xccdf_rule_get_complex_checks(struct xccdf_item *rule);
470
471 struct xccdf_item *xccdf_value_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
472 struct xccdf_item *xccdf_value_new_internal(struct xccdf_item *parent, xccdf_value_type_t type);
473 void xccdf_value_dump(struct xccdf_item *value, int depth);
474
475 struct xccdf_notice *xccdf_notice_new_parse(xmlTextReaderPtr reader);
476 void xccdf_notice_dump(struct xccdf_notice *notice, int depth);
477
478 void xccdf_status_dump(struct xccdf_status *status, int depth);
479
480 struct xccdf_model *xccdf_model_new_xml(xmlTextReaderPtr reader);
481
482 void xccdf_cstring_dump(const char *data, int depth);
483 void xccdf_result_dump(struct xccdf_result *res, int depth);
484 struct xccdf_result *xccdf_result_new_parse(xmlTextReaderPtr reader);
485 int xccdf_rule_result_set_time_current(struct xccdf_rule_result *item);
486 int xccdf_result_set_start_time_current(struct xccdf_result *item);
487 int xccdf_result_set_end_time_current(struct xccdf_result *item);
488 const struct xccdf_version_info* xccdf_result_get_schema_version(const struct xccdf_result *item);
489 bool xccdf_result_set_schema_version(struct xccdf_result *item, const struct xccdf_version_info* newval);
490
491
492 struct xccdf_check *xccdf_check_parse(xmlTextReaderPtr reader);
493 void xccdf_check_dump(struct xccdf_check *check, int depth);
494 bool xccdf_check_inject_content_ref(struct xccdf_check *check, const struct xccdf_check_content_ref *content, const char *name);
495 void xccdf_check_content_ref_dump(struct xccdf_check_content_ref *ref, int depth);
496 struct xccdf_ident *xccdf_ident_parse(xmlTextReaderPtr reader);
497 void xccdf_ident_dump(struct xccdf_ident *ident, int depth);
498 struct xccdf_fix *xccdf_fix_parse(xmlTextReaderPtr reader);
499 struct xccdf_fixtext *xccdf_fixtext_parse(xmlTextReaderPtr reader);
500
501 struct xccdf_setvalue *xccdf_setvalue_new_parse(xmlTextReaderPtr reader);
502 void xccdf_setvalue_dump(struct xccdf_setvalue *sv, int depth);
503
504 struct xccdf_warning *xccdf_warning_new_parse(xmlTextReaderPtr reader);
505
506 //private methods for cloning items
507 //Will clone the item member of a xccdf_item object
508 void xccdf_item_base_clone(struct xccdf_item_base *new_base, const struct xccdf_item_base *old_base);
509
510 //clones the specific types of items
511 void xccdf_profile_item_clone(struct xccdf_profile_item *clone, const struct xccdf_profile_item * item);
512 struct xccdf_benchmark_item * xccdf_benchmark_item_clone(struct xccdf_item *clone, const struct xccdf_benchmark * bench);
513 void xccdf_rule_item_clone(struct xccdf_rule_item *clone, const struct xccdf_rule_item * item);
514 void xccdf_group_item_clone(struct xccdf_item *parent, const struct xccdf_group_item * item);
515 void xccdf_value_item_clone(struct xccdf_value_item *clone, const struct xccdf_value_item * item);
516 struct xccdf_value_instance * xccdf_value_instance_clone(const struct xccdf_value_instance * val);
517 void xccdf_result_item_clone(struct xccdf_result_item *clone, const struct xccdf_result_item * item);
518 struct xccdf_profile_note * xccdf_profile_note_clone(const struct xccdf_profile_note * note);
519 void xccdf_reparent_list(struct oscap_list * item_list, struct xccdf_item * parent);
520 void xccdf_reparent_item(struct xccdf_item * item, struct xccdf_item * parent);
521
522 void xccdf_texts_to_dom(struct oscap_text_iterator *texts, xmlNode *parent, const char *elname);
523
524 #include "unused.h"
525
526 OSCAP_HIDDEN_END;
527
528 #endif
xccdf_plain_text
XCCDF target fact.
Definition: item.h:411
xccdf_tailoring
Stores content from xccdf:Tailoring element which can be loaded from a separate file.
Definition: item.h:172
cpe_lang_model
CPE platform specification.
Definition: cpelang_priv.c:63
xccdf_refine_rule
XCCDF refine rule option used in the profile.
Definition: item.h:260
xccdf_level_t
xccdf_level_t
XCCDF error, complexity, disruption, or severity level.
Definition: xccdf_benchmark.h:117
xccdf_profile_note
XCCDF note for given rule in context of given profile.
Definition: item.h:320
xccdf_instance
XCCDF instance.
Definition: item.h:405
oscap_string_map
Define mapping between symbolic constant and its string representation.
Definition: util.h:310
xccdf_model
XCCDF scoring model.
Definition: item.h:249
xccdf_warning_category_t
xccdf_warning_category_t
Category of xccdf_warning.
Definition: xccdf_benchmark.h:141
xccdf_score
XCCDF score.
Definition: item.h:370
oscap_htable_iterator
Definition: list.c:548
xccdf_operator_t
xccdf_operator_t
Operator to be applied on an xccdf_value.
Definition: xccdf_benchmark.h:100
xccdf_version_info
Definition: XCCDF/elements.c:43
xccdf_benchmark
Top level XCCDF structure containing profiles, rules, values and results.
xccdf_select
XCCDF select option usen in the profile.
Definition: item.h:254
xccdf_message
XCCDF message.
Definition: item.h:384
xccdf_setvalue
XCCDF set value option used in the profile.
Definition: item.h:276
xccdf_rule_item
Definition: item.h:91
xccdf_benchmark_item
Definition: item.h:194
oscap_text_iterator
Internationalized string iterator.
xccdf_check
XCCDF simple or complex check.
Definition: item.h:286
xccdf_type_t
xccdf_type_t
Type of an XCCDF object.
Definition: xccdf_benchmark.h:56
xccdf_fixtext
XCCDF textual fix instructions.
Definition: item.h:336
xccdf_result
Actual results of running a XCCDF test or profile.
Definition: xccdf_benchmark.h:232
xccdf_benchmark.h
Open-scap XCCDF library interface.
xccdf_test_result_type_t
xccdf_test_result_type_t
Test result.
Definition: xccdf_benchmark.h:168
xccdf_role_t
xccdf_role_t
XCCDF role.
Definition: xccdf_benchmark.h:134
xccdf_result_item
Definition: item.h:141
xccdf_check_export
XCCDF check export.
Definition: item.h:315
xccdf_override
XCCDF override.
Definition: item.h:376
xccdf_value_type_t
xccdf_value_type_t
Type of an xccdf_value.
Definition: xccdf_benchmark.h:93
xccdf_status_type_t
xccdf_status_type_t
Status of an XCCDF item.
Definition: xccdf_benchmark.h:83
xccdf_value_item
Definition: item.h:132
xccdf_identity
XCCDF identity.
Definition: item.h:362
xccdf_value_instance
Definition: item.h:115
oscap_list
Definition: list.h:54
xccdf_target_fact
XCCDF target fact.
Definition: item.h:389
xccdf_flags
Definition: item.h:38
cpe_dict_model
Structure representing a CPE dictionary.
Definition: cpedict_priv.h:126
xccdf_check::_xccdf_check_flags
Definition: item.h:293
xccdf_message_severity_t
xccdf_message_severity_t
Severity of an xccdf_message.
Definition: xccdf_benchmark.h:127
xccdf_rule_result
XCCDF rule result.
Definition: item.h:345
xccdf_group_item
Definition: item.h:106
xccdf_status
XCCDF item status.
Definition: item.h:244
xccdf_ident
XCCDF rule ident URI.
Definition: item.h:281
oscap_text
Representation of internationalizable character strings.
Definition: text_priv.h:47
xccdf_strategy_t
xccdf_strategy_t
Fix strategy type.
Definition: xccdf_benchmark.h:155
xccdf_interface_hint_t
xccdf_interface_hint_t
Interface hint.
Definition: xccdf_benchmark.h:73
oscap_htable
Definition: list.h:183
xccdf_bool_operator_t
xccdf_bool_operator_t
Boolean operators for logical expressions.
Definition: xccdf_benchmark.h:111
xccdf_fix
XCCDF automatic fix.
Definition: item.h:325
xccdf_check_import
XCCDF check import.
Definition: item.h:309
xccdf_item_base
Definition: item.h:64
xccdf_check_iterator
Check iterator.
Definition: xccdf_benchmark.h:511
xccdf_target_identifier
Can be either <target-id-ref> or some other element.
Definition: item.h:395
xccdf_defflags
Definition: item.h:48
xccdf_profile_item
Definition: item.h:163
xccdf_notice
XCCDF benchmark legal notice.
Definition: item.h:239
xccdf_numeric
float xccdf_numeric
Type of a numerical content for a XCCDF value.
Definition: xccdf_benchmark.h:196
xccdf_warning
XCCDF warning.
Definition: item.h:234
oscap_text_traits
oscap_text traits
Definition: text_priv.h:39
xccdf_item
A base class for XCCDF items.
Definition: item.h:221
xccdf_refine_value
XCCDF refine value option used in the profile.
Definition: item.h:269
xccdf_check_content_ref
XCCDF check content reference.
Definition: item.h:304