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