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