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 "public/xccdf.h"
27 #include <assert.h>
28 #include "elements.h"
29 #include "../common/reference_priv.h"
30 #include "../common/list.h"
31 #include "../common/util.h"
32 #include "../common/text_priv.h"
33 
34 OSCAP_HIDDEN_START;
35 
36 struct xccdf_flags {
37  bool selected:1;
38  bool hidden:1;
39  bool resolved:1;
40  bool abstract:1;
41  bool prohibit_changes:1;
42  bool interactive:1;
43  bool multiple:1;
44 };
45 
47  bool selected:1;
48  bool hidden:1;
49  bool resolved:1;
50  bool abstract:1;
51  bool prohibit_changes:1;
52  bool interactive:1;
53  bool multiple:1;
54  bool weight:1;
55  bool role:1;
56  bool severity:1;
57 };
58 
59 struct xccdf_item;
60 struct xccdf_check;
61 
63  char *id;
64  char *cluster_id;
65  float weight;
66 
67  struct oscap_list *title;
68  struct oscap_list *description;
69  struct oscap_list *question;
70  struct oscap_list *rationale;
71  struct oscap_list *warnings;
72 
73  char *version;
74  char *version_update;
75  time_t version_time;
76 
77  struct xccdf_item *parent;
78  char *extends;
79  struct oscap_list *statuses;
80  struct oscap_list *dc_statuses;
81  struct oscap_list *references;
82  struct oscap_list *platforms;
83  struct xccdf_flags flags;
84  struct xccdf_defflags defined_flags;
85 
86  struct oscap_list *metadata;
87 };
88 
90  char *impact_metric;
91  xccdf_role_t role;
92  xccdf_level_t severity;
93 
94  struct oscap_list *requires;
95  struct oscap_list *conflicts;
96 
97  struct oscap_list *profile_notes;
98  struct oscap_list *idents;
99  struct oscap_list *checks;
100  struct oscap_list *fixes;
101  struct oscap_list *fixtexts;
102 };
103 
105  struct oscap_list *requires;
106  struct oscap_list *conflicts;
107 
108  struct oscap_list *values;
109  struct oscap_list *content;
110 };
111 
112 /* This structure is used for multiple-count attributes for Item (0-n) */
114  char *selector;
115  xccdf_value_type_t type; /* Value::type */
116  char *value; /* Value::value */
117  char *defval; /* Value::default */
118  struct oscap_list *choices; /* Value::choices */
119  xccdf_numeric lower_bound;
120  xccdf_numeric upper_bound;
121  char *match;
122  struct {
123  bool value_given : 1;
124  bool defval_given : 1;
125  bool must_match_given : 1;
126  bool must_match : 1;
127  } flags;
128 };
129 
131  xccdf_value_type_t type; /* Value::type */
132  xccdf_interface_hint_t interface_hint; /* Value::interfaceHint */
133  xccdf_operator_t oper; /* Value::operator */
134 
135  struct oscap_list *instances;
136  struct oscap_list *sources; /* Value::source */
137 };
138 
140  time_t start_time;
141  time_t end_time;
142  char *test_system;
143  char *benchmark_uri;
144  char *profile;
145 
146  struct oscap_list *identities;
147  struct oscap_list *targets;
148  struct oscap_list *organizations;
149  struct oscap_list *remarks;
150  struct oscap_list *target_addresses;
151  struct oscap_list *target_facts;
152  struct oscap_list *target_id_refs;
153  struct oscap_list *setvalues;
154  struct oscap_list *rule_results;
155  struct oscap_list *scores;
156 };
157 
159  char *note_tag;
160  struct oscap_list *selects;
161  struct oscap_list *setvalues;
162  struct oscap_list *refine_values;
163  struct oscap_list *refine_rules;
164 };
165 
167  const struct xccdf_version_info *schema_version;
168 
169  struct oscap_htable *items_dict; /* Stores only xccdf:Item */
170  struct oscap_htable *profiles_dict; /* xccdf:Profile */
171  struct oscap_htable *results_dict; /* xccdf:TestResult */
172  struct oscap_list *notices;
173  struct oscap_list *plain_texts;
174 
175  char *style;
176  char *style_href;
177  char *lang;
178 
179  struct oscap_list *front_matter;
180  struct oscap_list *rear_matter;
181 
182  struct oscap_list *models;
183  struct oscap_list *profiles;
184  struct oscap_list *values;
185  struct oscap_list *content;
186  struct oscap_list *results;
187 };
188 
189 struct xccdf_item {
190  xccdf_type_t type;
191  struct xccdf_item_base item;
192  union {
193  struct xccdf_profile_item profile;
194  struct xccdf_benchmark_item benchmark;
195  struct xccdf_rule_item rule;
196  struct xccdf_group_item group;
197  struct xccdf_value_item value;
198  struct xccdf_result_item result;
199  } sub;
200 };
201 
203  struct oscap_text *text;
204  xccdf_warning_category_t category;
205 };
206 
207 struct xccdf_notice {
208  char *id;
209  struct oscap_text *text;
210 };
211 
212 struct xccdf_status {
213  xccdf_status_type_t status;
214  time_t date;
215 };
216 
217 struct xccdf_model {
218  char *system;
219  struct oscap_htable *params; // TODO: to list + accessors
220 };
221 
222 struct xccdf_select {
223  char *item;
224  bool selected;
225  struct oscap_list *remarks;
226 };
227 
229  char *item;
230  char *selector;
231  xccdf_role_t role;
232  xccdf_level_t severity;
233  xccdf_numeric weight;
234  struct oscap_list *remarks;
235 };
236 
238  char *item;
239  char *selector;
240  xccdf_operator_t oper;
241  struct oscap_list *remarks;
242 };
243 
245  char *item;
246  char *value;
247 };
248 
249 struct xccdf_ident {
250  char *id;
251  char *system;
252 };
253 
254 struct xccdf_check {
256  struct oscap_list *children;
257  char *id;
258  char *system;
259  char *selector;
260  char *content;
261  struct oscap_list *imports;
262  struct oscap_list *exports;
263  struct oscap_list *content_refs;
264 };
265 
267  char *href;
268  char *name;
269 };
270 
272  char *name;
273  char *xpath;
274  char *content;
275 };
276 
278  char *name;
279  char *value;
280 };
281 
283  struct oscap_text *text;
284  char *reftag;
285 };
286 
287 struct xccdf_fix {
288  bool reboot;
289  xccdf_strategy_t strategy;
290  xccdf_level_t disruption;
291  xccdf_level_t complexity;
292  char *id;
293  char *content;
294  char *system;
295  char *platform;
296 };
297 
299  struct oscap_text *text;
300  bool reboot;
301  xccdf_strategy_t strategy;
302  xccdf_level_t disruption;
303  xccdf_level_t complexity;
304  char *fixref;
305 };
306 
307 /*
308 struct xccdf_reference {
309  struct oscap_text *text;
310  char *href;
311 };
312 */
313 
315  char *idref;
316  xccdf_role_t role;
317  time_t time;
318  float weight;
319  xccdf_level_t severity;
321  char *version;
322 
323  struct oscap_list *overrides;
324  struct oscap_list *idents;
325  struct oscap_list *messages;
326  struct oscap_list *instances;
327  struct oscap_list *fixes;
328  struct oscap_list *checks;
329 };
330 
332  struct {
333  bool authenticated : 1;
334  bool privileged : 1;
335  } sub;
336  char *name;
337 };
338 
339 struct xccdf_score {
340  xccdf_numeric maximum;
341  xccdf_numeric score;
342  char *system;
343 };
344 
346  time_t time;
347  char *authority;
348  xccdf_test_result_type_t old_result;
349  xccdf_test_result_type_t new_result;
350  struct oscap_text *remark;
351 };
352 
354  xccdf_message_severity_t severity;
355  char *content;
356 };
357 
359  xccdf_value_type_t type;
360  char *name;
361  char *value;
362 };
363 
365  bool any_element; // if false, this represents <target-id-ref>, else it's any element
366 
367  xmlNodePtr element;
368 
369  const char* system;
370  const char* href;
371  const char* name;
372 };
373 
375  char *context;
376  char *parent_context;
377  char *content;
378 };
379 
381  char *id;
382  char *text;
383 };
384 
385 extern const struct oscap_string_map XCCDF_LEVEL_MAP[];
386 extern const struct oscap_string_map XCCDF_ROLE_MAP[];
387 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[];
388 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[];
389 extern const struct oscap_string_map XCCDF_FACT_TYPE_MAP[];
390 extern const struct oscap_string_map XCCDF_RESULT_MAP[];
391 
392 extern const struct oscap_text_traits XCCDF_TEXT_PLAIN;
393 extern const struct oscap_text_traits XCCDF_TEXT_HTML;
394 extern const struct oscap_text_traits XCCDF_TEXT_PLAINSUB;
395 extern const struct oscap_text_traits XCCDF_TEXT_HTMLSUB;
396 extern const struct oscap_text_traits XCCDF_TEXT_NOTICE;
397 extern const struct oscap_text_traits XCCDF_TEXT_PROFNOTE;
398 
399 extern const size_t XCCDF_NUMERIC_SIZE;
400 extern const char *XCCDF_NUMERIC_FORMAT;
401 
402 struct xccdf_item *xccdf_item_new(xccdf_type_t type, struct xccdf_item *parent);
403 void xccdf_item_release(struct xccdf_item *item);
404 void xccdf_item_print(struct xccdf_item *item, int depth);
405 void xccdf_item_dump(struct xccdf_item *item, int depth);
406 struct xccdf_item* xccdf_item_get_benchmark_internal(struct xccdf_item* item);
407 bool xccdf_benchmark_parse(struct xccdf_item *benchmark, xmlTextReaderPtr reader);
408 void xccdf_benchmark_dump(struct xccdf_benchmark *benchmark);
409 bool xccdf_benchmark_register_item(struct xccdf_benchmark *benchmark, struct xccdf_item *item);
410 bool xccdf_benchmark_unregister_item(struct xccdf_item *item);
411 bool xccdf_benchmark_rename_item(struct xccdf_item *item, const char *newid);
412 char *xccdf_benchmark_gen_id(struct xccdf_benchmark *benchmark, xccdf_type_t type, const char *prefix);
413 bool xccdf_add_item(struct oscap_list *list, struct xccdf_item *parent, struct xccdf_item *item, const char *prefix);
414 
415 struct xccdf_item *xccdf_profile_new_internal(struct xccdf_item *bench);
416 struct xccdf_item *xccdf_profile_parse(xmlTextReaderPtr reader, struct xccdf_item *bench);
417 void xccdf_profile_dump(struct xccdf_item *prof, int depth);
418 
419 bool xccdf_item_process_attributes(struct xccdf_item *item, xmlTextReaderPtr reader);
420 bool xccdf_item_process_element(struct xccdf_item *item, xmlTextReaderPtr reader);
421 
422 bool xccdf_content_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
423 struct xccdf_item *xccdf_group_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
424 struct xccdf_item *xccdf_group_new_internal(struct xccdf_item *parent);
425 void xccdf_group_dump(struct xccdf_item *group, int depth);
426 
427 struct xccdf_item *xccdf_rule_new_internal(struct xccdf_item *parent);
428 struct xccdf_item *xccdf_rule_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
429 void xccdf_rule_dump(struct xccdf_item *rule, int depth);
430 
431 struct xccdf_item *xccdf_value_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
432 struct xccdf_item *xccdf_value_new_internal(struct xccdf_item *parent, xccdf_value_type_t type);
433 void xccdf_value_dump(struct xccdf_item *value, int depth);
434 
435 struct xccdf_notice *xccdf_notice_new_parse(xmlTextReaderPtr reader);
436 void xccdf_notice_dump(struct xccdf_notice *notice, int depth);
437 
438 void xccdf_status_dump(struct xccdf_status *status, int depth);
439 
440 struct xccdf_model *xccdf_model_new_xml(xmlTextReaderPtr reader);
441 
442 void xccdf_cstring_dump(const char *data, int depth);
443 void xccdf_result_dump(struct xccdf_result *res, int depth);
444 struct xccdf_result *xccdf_result_new_parse(xmlTextReaderPtr reader);
445 
446 
447 struct xccdf_check *xccdf_check_parse(xmlTextReaderPtr reader);
448 void xccdf_check_dump(struct xccdf_check *check, int depth);
449 void xccdf_check_content_ref_dump(struct xccdf_check_content_ref *ref, int depth);
450 struct xccdf_ident *xccdf_ident_parse(xmlTextReaderPtr reader);
451 void xccdf_ident_dump(struct xccdf_ident *ident, int depth);
452 struct xccdf_fix *xccdf_fix_parse(xmlTextReaderPtr reader);
453 struct xccdf_fixtext *xccdf_fixtext_parse(xmlTextReaderPtr reader);
454 
455 struct xccdf_setvalue *xccdf_setvalue_new_parse(xmlTextReaderPtr reader);
456 void xccdf_setvalue_dump(struct xccdf_setvalue *sv, int depth);
457 
458 struct xccdf_warning *xccdf_warning_new_parse(xmlTextReaderPtr reader);
459 //struct xccdf_reference *xccdf_reference_new_parse(xmlTextReaderPtr reader);
460 
461 //private methods for cloning items
462 //Will clone the item member of a xccdf_item object
463 void xccdf_item_base_clone(struct xccdf_item_base *new_base, const struct xccdf_item_base *old_base);
464 
465 //clones the specific types of items
466 void xccdf_profile_item_clone(struct xccdf_profile_item *clone, const struct xccdf_profile_item * item);
467 struct xccdf_benchmark_item * xccdf_benchmark_item_clone(struct xccdf_item *clone, const struct xccdf_benchmark * bench);
468 void xccdf_rule_item_clone(struct xccdf_rule_item *clone, const struct xccdf_rule_item * item);
469 void xccdf_group_item_clone(struct xccdf_item *parent, const struct xccdf_group_item * item);
470 void xccdf_value_item_clone(struct xccdf_value_item *clone, const struct xccdf_value_item * item);
471 struct xccdf_value_instance * xccdf_value_instance_clone(const struct xccdf_value_instance * val);
472 void xccdf_result_item_clone(struct xccdf_result_item *clone, const struct xccdf_result_item * item);
473 struct xccdf_profile_note * xccdf_profile_note_clone(const struct xccdf_profile_note * note);
474 void xccdf_reparent_list(struct oscap_list * item_list, struct xccdf_item * parent);
475 void xccdf_reparent_item(struct xccdf_item * item, struct xccdf_item * parent);
476 
477 void xccdf_texts_to_dom(struct oscap_text_iterator *texts, xmlNode *parent, const char *elname);
478 
479 #include "unused.h"
480 
481 OSCAP_HIDDEN_END;
482 
483 #endif