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