Debian Codegraph @

src/XCCDF/item.h

raw symbols SCIP
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * Lukas Kuklinek <[email protected]>
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
37 struct xccdf_flags {
38 bool selected:1;
39 bool hidden:1;
40 bool resolved:1;
41 bool abstract:1;
42 bool prohibit_changes:1;
43 bool interactive:1;
44 bool multiple:1;
45 };
46
47 struct xccdf_defflags {
48 bool selected:1;
49 bool hidden:1;
50 bool resolved:1;
51 bool abstract:1;
52 bool prohibit_changes:1;
53 bool interactive:1;
54 bool multiple:1;
55 bool weight:1;
56 bool role:1;
57 bool severity:1;
58 };
59
60 struct xccdf_item;
61 struct xccdf_check;
62
63 struct xccdf_item_base {
64 char *id;
65 char *cluster_id;
66 float weight;
67
68 struct oscap_list *title;
69 struct oscap_list *description;
70 struct oscap_list *question;
71 struct oscap_list *rationale;
72 struct oscap_list *warnings;
73
74 char *version;
75 char *version_update;
76 char *version_time;
77
78 struct xccdf_item *parent;
79 char *extends;
80 struct oscap_list *statuses;
81 struct oscap_list *dc_statuses;
82 struct oscap_list *references;
83 struct oscap_list *platforms;
84 struct xccdf_flags flags;
85 struct xccdf_defflags defined_flags;
86
87 struct oscap_list *metadata;
88 };
89
90 struct xccdf_rule_item {
91 char *impact_metric;
92 xccdf_role_t role;
93 xccdf_level_t severity;
94
95 struct oscap_list *requires_;
96 struct oscap_list *conflicts;
97
98 struct oscap_list *profile_notes;
99 struct oscap_list *idents;
100 struct oscap_list *checks;
101 struct oscap_list *fixes;
102 struct oscap_list *fixtexts;
103 };
104
105 struct xccdf_group_item {
106 struct oscap_list *requires_;
107 struct oscap_list *conflicts;
108
109 struct oscap_list *values;
110 struct oscap_list *content;
111 };
112
113 /* This structure is used for multiple-count attributes for Item (0-n) */
114 struct xccdf_value_instance {
115 char *selector;
116 xccdf_value_type_t type; /* Value::type */
117 char *value; /* Value::value */
118 char *defval; /* Value::default */
119 struct oscap_list *choices; /* Value::choices */
120 xccdf_numeric lower_bound;
121 xccdf_numeric upper_bound;
122 char *match;
123 struct {
124 bool value_given : 1;
125 bool defval_given : 1;
126 bool must_match_given : 1;
127 bool must_match : 1;
128 } flags;
129 };
130
131 struct xccdf_value_item {
132 xccdf_value_type_t type; /* Value::type */
133 xccdf_interface_hint_t interface_hint; /* Value::interfaceHint */
134 xccdf_operator_t oper; /* Value::operator */
135
136 struct oscap_list *instances;
137 struct oscap_list *sources; /* Value::source */
138 };
139
140 struct xccdf_result_item {
141 const struct xccdf_version_info *schema_version;
142
143 char *start_time;
144 char *end_time;
145 char *test_system;
146 char *benchmark_uri;
147 char *profile;
148
149 struct oscap_list *identities;
150 struct oscap_list *targets;
151 struct oscap_list *organizations;
152 struct oscap_list *remarks;
153 struct oscap_list *target_addresses;
154 struct oscap_list *target_facts;
155 struct oscap_list *target_id_refs;
156 struct oscap_list *applicable_platforms;
157 struct oscap_list *setvalues;
158 struct oscap_list *rule_results;
159 struct oscap_list *scores;
160 };
161
162 struct xccdf_profile_item {
163 char *note_tag;
164 struct oscap_list *selects;
165 struct oscap_list *setvalues;
166 struct oscap_list *refine_values;
167 struct oscap_list *refine_rules;
168 bool tailoring;
169 };
170
171 struct xccdf_tailoring {
172 // optional, only relevant when Tailoring is saved as a root element
173 char *id;
174
175 // The ref is "just informative" according to the spec, we never
176 // interpret it and just load and save it as a string.
177 char *benchmark_ref;
178 // Also just informative
179 char *benchmark_ref_version;
180
181 struct oscap_list *statuses;
182 struct oscap_list *dc_statuses;
183
184 char *version;
185 char *version_update;
186 char *version_time;
187
188 struct oscap_list *metadata;
189
190 struct oscap_list *profiles;
191 };
192
193 struct xccdf_benchmark_item {
194 const struct xccdf_version_info *schema_version;
195
196 struct oscap_htable *items_dict; /* Stores only xccdf:Item */
197 struct oscap_htable *profiles_dict; /* xccdf:Profile */
198 struct oscap_htable *results_dict; /* xccdf:TestResult */
199 struct oscap_htable *clusters_dict; /* xccdf:items by cluster-id */
200 struct oscap_list *notices;
201 struct oscap_list *plain_texts;
202
203 struct cpe_dict_model *cpe_list;
204 struct cpe_lang_model *cpe_lang_model;
205
206 char *style;
207 char *style_href;
208 char *lang;
209
210 struct oscap_list *front_matter;
211 struct oscap_list *rear_matter;
212
213 struct oscap_list *models;
214 struct oscap_list *profiles;
215 struct oscap_list *values;
216 struct oscap_list *content;
217 struct oscap_list *results;
218 };
219
220 struct xccdf_item {
221 xccdf_type_t type;
222 struct xccdf_item_base item;
223 union {
224 struct xccdf_profile_item profile;
225 struct xccdf_benchmark_item benchmark;
226 struct xccdf_rule_item rule;
227 struct xccdf_group_item group;
228 struct xccdf_value_item value;
229 struct xccdf_result_item result;
230 } sub;
231 };
232
233 struct xccdf_warning {
234 struct oscap_text *text;
235 xccdf_warning_category_t category;
236 };
237
238 struct xccdf_notice {
239 char *id;
240 struct oscap_text *text;
241 };
242
243 struct xccdf_status {
244 xccdf_status_type_t status;
245 time_t date;
246 };
247
248 struct xccdf_model {
249 char *system;
250 struct oscap_htable *params; // TODO: to list + accessors
251 };
252
253 struct xccdf_select {
254 char *item;
255 bool selected;
256 struct oscap_list *remarks;
257 };
258
259 struct xccdf_refine_rule {
260 char *item;
261 char *selector;
262 xccdf_role_t role;
263 xccdf_level_t severity;
264 xccdf_numeric weight;
265 struct oscap_list *remarks;
266 };
267
268 struct xccdf_refine_value {
269 char *item;
270 char *selector;
271 xccdf_operator_t oper;
272 struct oscap_list *remarks;
273 };
274
275 struct xccdf_setvalue {
276 char *item;
277 char *value;
278 };
279
280 struct xccdf_ident {
281 char *id;
282 char *system;
283 };
284
285 struct xccdf_check {
286 xccdf_bool_operator_t oper;
287 struct oscap_list *children;
288 char *id;
289 char *system;
290 char *selector;
291 char *content;
292 struct _xccdf_check_flags {
293 bool multicheck:1;
294 bool def_multicheck:1;
295 bool negate:1;
296 bool def_negate:1;
297 } flags;
298 struct oscap_list *imports;
299 struct oscap_list *exports;
300 struct oscap_list *content_refs;
301 };
302
303 struct xccdf_check_content_ref {
304 char *href;
305 char *name;
306 };
307
308 struct xccdf_check_import {
309 char *name;
310 char *xpath;
311 char *content;
312 };
313
314 struct xccdf_check_export {
315 char *name;
316 char *value;
317 };
318
319 struct xccdf_profile_note {
320 struct oscap_text *text;
321 char *reftag;
322 };
323
324 struct xccdf_fix {
325 bool reboot;
326 xccdf_strategy_t strategy;
327 xccdf_level_t disruption;
328 xccdf_level_t complexity;
329 char *id;
330 char *content;
331 char *system;
332 char *platform;
333 };
334
335 struct xccdf_fixtext {
336 struct oscap_text *text;
337 bool reboot;
338 xccdf_strategy_t strategy;
339 xccdf_level_t disruption;
340 xccdf_level_t complexity;
341 char *fixref;
342 };
343
344 struct xccdf_rule_result {
345 char *idref;
346 xccdf_role_t role;
347 char *time;
348 float weight;
349 xccdf_level_t severity;
350 xccdf_test_result_type_t result;
351 char *version;
352
353 struct oscap_list *overrides;
354 struct oscap_list *idents;
355 struct oscap_list *messages;
356 struct oscap_list *instances;
357 struct oscap_list *fixes;
358 struct oscap_list *checks;
359 };
360
361 struct xccdf_identity {
362 struct {
363 bool authenticated : 1;
364 bool privileged : 1;
365 } sub;
366 char *name;
367 };
368
369 struct xccdf_score {
370 xccdf_numeric maximum;
371 xccdf_numeric score;
372 char *system;
373 };
374
375 struct xccdf_override {
376 char *time;
377 char *authority;
378 xccdf_test_result_type_t old_result;
379 xccdf_test_result_type_t new_result;
380 struct oscap_text *remark;
381 };
382
383 struct xccdf_message {
384 xccdf_message_severity_t severity;
385 char *content;
386 };
387
388 struct xccdf_target_fact {
389 xccdf_value_type_t type;
390 char *name;
391 char *value;
392 };
393
394 struct xccdf_target_identifier {
395 bool any_element; // if false, this represents <target-id-ref>, else it's any element
396
397 xmlNodePtr element;
398
399 char *system;
400 char *href;
401 char *name;
402 };
403
404 struct xccdf_instance {
405 char *context;
406 char *parent_context;
407 char *content;
408 };
409
410 struct xccdf_plain_text {
411 char *id;
412 char *text;
413 };
414
415 extern const struct oscap_string_map XCCDF_LEVEL_MAP[];
416 extern const struct oscap_string_map XCCDF_ROLE_MAP[];
417 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[];
418 extern const struct oscap_string_map XCCDF_BOOLOP_MAP[];
419 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[];
420 extern const struct oscap_string_map XCCDF_FACT_TYPE_MAP[];
421 extern const struct oscap_string_map XCCDF_RESULT_MAP[];
422
423 extern const struct oscap_text_traits XCCDF_TEXT_PLAIN;
424 extern const struct oscap_text_traits XCCDF_TEXT_HTML;
425 extern const struct oscap_text_traits XCCDF_TEXT_PLAINSUB;
426 extern const struct oscap_text_traits XCCDF_TEXT_HTMLSUB;
427 extern const struct oscap_text_traits XCCDF_TEXT_NOTICE;
428 extern const struct oscap_text_traits XCCDF_TEXT_PROFNOTE;
429
430 extern const size_t XCCDF_NUMERIC_SIZE;
431 extern const char *XCCDF_NUMERIC_FORMAT;
432
433 struct xccdf_item *xccdf_item_new(xccdf_type_t type, struct xccdf_item *parent);
434 void xccdf_item_release(struct xccdf_item *item);
435 void xccdf_item_print(struct xccdf_item *item, int depth);
436 void xccdf_item_dump(struct xccdf_item *item, int depth);
437 struct xccdf_item* xccdf_item_get_benchmark_internal(struct xccdf_item* item);
438 bool xccdf_benchmark_parse(struct xccdf_item *benchmark, xmlTextReaderPtr reader);
439 void xccdf_benchmark_dump(struct xccdf_benchmark *benchmark);
440 int xccdf_benchmark_include_tailored_profiles(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 void xccdf_item_add_applicable_platform(struct xccdf_item *item, xmlTextReaderPtr reader);
525
526 #include "unused.h"
527
528
529 #endif