Open SCAP Library: item.h Source File

Open SCAP Library

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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 char *start_time;
143 char *end_time;
144 char *test_system;
145 char *benchmark_uri;
146 char *profile;
147
148 struct oscap_list *identities;
149 struct oscap_list *targets;
150 struct oscap_list *organizations;
151 struct oscap_list *remarks;
152 struct oscap_list *target_addresses;
153 struct oscap_list *target_facts;
154 struct oscap_list *target_id_refs;
155 struct oscap_list *setvalues;
156 struct oscap_list *rule_results;
157 struct oscap_list *scores;
158 };
159
160 struct xccdf_profile_item {
161 char *note_tag;
162 struct oscap_list *selects;
163 struct oscap_list *setvalues;
164 struct oscap_list *refine_values;
165 struct oscap_list *refine_rules;
166 bool tailoring;
167 };
168
169 struct xccdf_tailoring {
170 // optional, only relevant when Tailoring is saved as a root element
171 char *id;
172
173 // The ref is "just informative" according to the spec, we never
174 // interpret it and just load and save it as a string.
175 char *benchmark_ref;
176 // Also just informative
177 char *benchmark_ref_version;
178
179 struct oscap_list *statuses;
180 struct oscap_list *dc_statuses;
181
182 char *version;
183 char *version_update;
184 char *version_time;
185
186 struct oscap_list *metadata;
187
188 struct oscap_list *profiles;
189 };
190
191 struct xccdf_benchmark_item {
192 const struct xccdf_version_info *schema_version;
193
194 struct oscap_htable *items_dict; /* Stores only xccdf:Item */
195 struct oscap_htable *profiles_dict; /* xccdf:Profile */
196 struct oscap_htable *results_dict; /* xccdf:TestResult */
197 struct oscap_htable *clusters_dict; /* xccdf:items by cluster-id */
198 struct oscap_list *notices;
199 struct oscap_list *plain_texts;
200
201 struct cpe_dict_model *cpe_list;
202 struct cpe_lang_model *cpe_lang_model;
203
204 char *style;
205 char *style_href;
206 char *lang;
207
208 struct oscap_list *front_matter;
209 struct oscap_list *rear_matter;
210
211 struct oscap_list *models;
212 struct oscap_list *profiles;
213 struct oscap_list *values;
214 struct oscap_list *content;
215 struct oscap_list *results;
216 };
217
218 struct xccdf_item {
219 xccdf_type_t type;
220 struct xccdf_item_base item;
221 union {
222 struct xccdf_profile_item profile;
223 struct xccdf_benchmark_item benchmark;
224 struct xccdf_rule_item rule;
225 struct xccdf_group_item group;
226 struct xccdf_value_item value;
227 struct xccdf_result_item result;
228 } sub;
229 };
230
231 struct xccdf_warning {
232 struct oscap_text *text;
233 xccdf_warning_category_t category;
234 };
235
236 struct xccdf_notice {
237 char *id;
238 struct oscap_text *text;
239 };
240
241 struct xccdf_status {
242 xccdf_status_type_t status;
243 time_t date;
244 };
245
246 struct xccdf_model {
247 char *system;
248 struct oscap_htable *params; // TODO: to list + accessors
249 };
250
251 struct xccdf_select {
252 char *item;
253 bool selected;
254 struct oscap_list *remarks;
255 };
256
257 struct xccdf_refine_rule {
258 char *item;
259 char *selector;
260 xccdf_role_t role;
261 xccdf_level_t severity;
262 xccdf_numeric weight;
263 struct oscap_list *remarks;
264 };
265
266 struct xccdf_refine_value {
267 char *item;
268 char *selector;
269 xccdf_operator_t oper;
270 struct oscap_list *remarks;
271 };
272
273 struct xccdf_setvalue {
274 char *item;
275 char *value;
276 };
277
278 struct xccdf_ident {
279 char *id;
280 char *system;
281 };
282
283 struct xccdf_check {
284 xccdf_bool_operator_t oper;
285 struct oscap_list *children;
286 char *id;
287 char *system;
288 char *selector;
289 char *content;
290 struct _xccdf_check_flags {
291 bool multicheck:1;
292 bool def_multicheck:1;
293 bool negate:1;
294 bool def_negate:1;
295 } flags;
296 struct oscap_list *imports;
297 struct oscap_list *exports;
298 struct oscap_list *content_refs;
299 };
300
301 struct xccdf_check_content_ref {
302 char *href;
303 char *name;
304 };
305
306 struct xccdf_check_import {
307 char *name;
308 char *xpath;
309 char *content;
310 };
311
312 struct xccdf_check_export {
313 char *name;
314 char *value;
315 };
316
317 struct xccdf_profile_note {
318 struct oscap_text *text;
319 char *reftag;
320 };
321
322 struct xccdf_fix {
323 bool reboot;
324 xccdf_strategy_t strategy;
325 xccdf_level_t disruption;
326 xccdf_level_t complexity;
327 char *id;
328 char *content;
329 char *system;
330 char *platform;
331 };
332
333 struct xccdf_fixtext {
334 struct oscap_text *text;
335 bool reboot;
336 xccdf_strategy_t strategy;
337 xccdf_level_t disruption;
338 xccdf_level_t complexity;
339 char *fixref;
340 };
341
342 struct xccdf_rule_result {
343 char *idref;
344 xccdf_role_t role;
345 char *time;
346 float weight;
347 xccdf_level_t severity;
348 xccdf_test_result_type_t result;
349 char *version;
350
351 struct oscap_list *overrides;
352 struct oscap_list *idents;
353 struct oscap_list *messages;
354 struct oscap_list *instances;
355 struct oscap_list *fixes;
356 struct oscap_list *checks;
357 };
358
359 struct xccdf_identity {
360 struct {
361 bool authenticated : 1;
362 bool privileged : 1;
363 } sub;
364 char *name;
365 };
366
367 struct xccdf_score {
368 xccdf_numeric maximum;
369 xccdf_numeric score;
370 char *system;
371 };
372
373 struct xccdf_override {
374 char *time;
375 char *authority;
376 xccdf_test_result_type_t old_result;
377 xccdf_test_result_type_t new_result;
378 struct oscap_text *remark;
379 };
380
381 struct xccdf_message {
382 xccdf_message_severity_t severity;
383 char *content;
384 };
385
386 struct xccdf_target_fact {
387 xccdf_value_type_t type;
388 char *name;
389 char *value;
390 };
391
392 struct xccdf_target_identifier {
393 bool any_element; // if false, this represents <target-id-ref>, else it's any element
394
395 xmlNodePtr element;
396
397 const char* system;
398 const char* href;
399 const char* name;
400 };
401
402 struct xccdf_instance {
403 char *context;
404 char *parent_context;
405 char *content;
406 };
407
408 struct xccdf_plain_text {
409 char *id;
410 char *text;
411 };
412
413 extern const struct oscap_string_map XCCDF_LEVEL_MAP[];
414 extern const struct oscap_string_map XCCDF_ROLE_MAP[];
415 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[];
416 extern const struct oscap_string_map XCCDF_BOOLOP_MAP[];
417 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[];
418 extern const struct oscap_string_map XCCDF_FACT_TYPE_MAP[];
419 extern const struct oscap_string_map XCCDF_RESULT_MAP[];
420
421 extern const struct oscap_text_traits XCCDF_TEXT_PLAIN;
422 extern const struct oscap_text_traits XCCDF_TEXT_HTML;
423 extern const struct oscap_text_traits XCCDF_TEXT_PLAINSUB;
424 extern const struct oscap_text_traits XCCDF_TEXT_HTMLSUB;
425 extern const struct oscap_text_traits XCCDF_TEXT_NOTICE;
426 extern const struct oscap_text_traits XCCDF_TEXT_PROFNOTE;
427
428 extern const size_t XCCDF_NUMERIC_SIZE;
429 extern const char *XCCDF_NUMERIC_FORMAT;
430
431 struct xccdf_item *xccdf_item_new(xccdf_type_t type, struct xccdf_item *parent);
432 void xccdf_item_release(struct xccdf_item *item);
433 void xccdf_item_print(struct xccdf_item *item, int depth);
434 void xccdf_item_dump(struct xccdf_item *item, int depth);
435 struct xccdf_item* xccdf_item_get_benchmark_internal(struct xccdf_item* item);
436 bool xccdf_benchmark_parse(struct xccdf_item *benchmark, xmlTextReaderPtr reader);
437 void xccdf_benchmark_dump(struct xccdf_benchmark *benchmark);
438 struct oscap_htable_iterator *xccdf_benchmark_get_cluster_items(struct xccdf_benchmark *benchmark, const char *cluster_id);
439 bool xccdf_benchmark_register_item(struct xccdf_benchmark *benchmark, struct xccdf_item *item);
440 bool xccdf_benchmark_unregister_item(struct xccdf_item *item);
441 bool xccdf_benchmark_rename_item(struct xccdf_item *item, const char *newid);
442 char *xccdf_benchmark_gen_id(struct xccdf_benchmark *benchmark, xccdf_type_t type, const char *prefix);
443 struct xccdf_profile *xccdf_benchmark_get_profile_by_id(struct xccdf_benchmark *benchmark, const char *profile_id);
444 struct xccdf_result *xccdf_benchmark_get_result_by_id(struct xccdf_benchmark *benchmark, const char *testresult_id);
445 bool xccdf_add_item(struct oscap_list *list, struct xccdf_item *parent, struct xccdf_item *item, const char *prefix);
446
447 struct xccdf_tailoring *xccdf_tailoring_parse(xmlTextReaderPtr reader, struct xccdf_item* benchmark);
448 xmlNodePtr xccdf_tailoring_to_dom(struct xccdf_tailoring *tailoring, xmlDocPtr doc, xmlNodePtr parent, const struct xccdf_version_info *version_info);
449
450 struct xccdf_item *xccdf_profile_new_internal(struct xccdf_item *bench);
451 struct xccdf_item *xccdf_profile_parse(xmlTextReaderPtr reader, struct xccdf_item *bench);
452 void xccdf_profile_dump(struct xccdf_item *prof, int depth);
453
454 bool xccdf_item_process_attributes(struct xccdf_item *item, xmlTextReaderPtr reader);
455 bool xccdf_item_process_element(struct xccdf_item *item, xmlTextReaderPtr reader);
456
457 bool xccdf_content_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
458 struct xccdf_item *xccdf_group_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
459 struct xccdf_item *xccdf_group_new_internal(struct xccdf_item *parent);
460 void xccdf_group_dump(struct xccdf_item *group, int depth);
461
462 struct xccdf_item *xccdf_rule_new_internal(struct xccdf_item *parent);
463 struct xccdf_item *xccdf_rule_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
464 void xccdf_rule_dump(struct xccdf_item *rule, int depth);
465 struct xccdf_check_iterator *xccdf_rule_get_checks_filtered(struct xccdf_item *rule, char *selector);
466 struct xccdf_check_iterator *xccdf_rule_get_complex_checks(struct xccdf_item *rule);
467
468 struct xccdf_item *xccdf_value_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
469 struct xccdf_item *xccdf_value_new_internal(struct xccdf_item *parent, xccdf_value_type_t type);
470 void xccdf_value_dump(struct xccdf_item *value, int depth);
471
472 struct xccdf_notice *xccdf_notice_new_parse(xmlTextReaderPtr reader);
473 void xccdf_notice_dump(struct xccdf_notice *notice, int depth);
474
475 void xccdf_status_dump(struct xccdf_status *status, int depth);
476
477 struct xccdf_model *xccdf_model_new_xml(xmlTextReaderPtr reader);
478
479 void xccdf_cstring_dump(const char *data, int depth);
480 void xccdf_result_dump(struct xccdf_result *res, int depth);
481 struct xccdf_result *xccdf_result_new_parse(xmlTextReaderPtr reader);
482 int xccdf_rule_result_set_time_current(struct xccdf_rule_result *item);
483 int xccdf_result_set_start_time_current(struct xccdf_result *item);
484 int xccdf_result_set_end_time_current(struct xccdf_result *item);
485
486
487 struct xccdf_check *xccdf_check_parse(xmlTextReaderPtr reader);
488 void xccdf_check_dump(struct xccdf_check *check, int depth);
489 bool xccdf_check_inject_content_ref(struct xccdf_check *check, const struct xccdf_check_content_ref *content, const char *name);
490 void xccdf_check_content_ref_dump(struct xccdf_check_content_ref *ref, int depth);
491 struct xccdf_ident *xccdf_ident_parse(xmlTextReaderPtr reader);
492 void xccdf_ident_dump(struct xccdf_ident *ident, int depth);
493 struct xccdf_fix *xccdf_fix_parse(xmlTextReaderPtr reader);
494 struct xccdf_fixtext *xccdf_fixtext_parse(xmlTextReaderPtr reader);
495
496 struct xccdf_setvalue *xccdf_setvalue_new_parse(xmlTextReaderPtr reader);
497 void xccdf_setvalue_dump(struct xccdf_setvalue *sv, int depth);
498
499 struct xccdf_warning *xccdf_warning_new_parse(xmlTextReaderPtr reader);
500
501 //private methods for cloning items
502 //Will clone the item member of a xccdf_item object
503 void xccdf_item_base_clone(struct xccdf_item_base *new_base, const struct xccdf_item_base *old_base);
504
505 //clones the specific types of items
506 void xccdf_profile_item_clone(struct xccdf_profile_item *clone, const struct xccdf_profile_item * item);
507 struct xccdf_benchmark_item * xccdf_benchmark_item_clone(struct xccdf_item *clone, const struct xccdf_benchmark * bench);
508 void xccdf_rule_item_clone(struct xccdf_rule_item *clone, const struct xccdf_rule_item * item);
509 void xccdf_group_item_clone(struct xccdf_item *parent, const struct xccdf_group_item * item);
510 void xccdf_value_item_clone(struct xccdf_value_item *clone, const struct xccdf_value_item * item);
511 struct xccdf_value_instance * xccdf_value_instance_clone(const struct xccdf_value_instance * val);
512 void xccdf_result_item_clone(struct xccdf_result_item *clone, const struct xccdf_result_item * item);
513 struct xccdf_profile_note * xccdf_profile_note_clone(const struct xccdf_profile_note * note);
514 void xccdf_reparent_list(struct oscap_list * item_list, struct xccdf_item * parent);
515 void xccdf_reparent_item(struct xccdf_item * item, struct xccdf_item * parent);
516
517 void xccdf_texts_to_dom(struct oscap_text_iterator *texts, xmlNode *parent, const char *elname);
518
519 #include "unused.h"
520
521 OSCAP_HIDDEN_END;
522
523 #endif