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