Open SCAP Library

item.h

00001 /*
00002  * Copyright 2009--2013 Red Hat Inc., Durham, North Carolina.
00003  * All Rights Reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful, 
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software 
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  * Authors:
00020  *      Lukas Kuklinek <lkuklinek@redhat.com>
00021  */
00022 
00023 #ifndef XCCDF_ITEM_
00024 #define XCCDF_ITEM_
00025 
00026 #include <assert.h>
00027 
00028 #include "public/xccdf_benchmark.h"
00029 #include "elements.h"
00030 
00031 #include "common/reference_priv.h"
00032 #include "common/list.h"
00033 #include "common/util.h"
00034 #include "common/text_priv.h"
00035 
00036 OSCAP_HIDDEN_START;
00037 
00038 struct xccdf_flags {
00039         bool selected:1;
00040         bool hidden:1;
00041         bool resolved:1;
00042         bool abstract:1;
00043         bool prohibit_changes:1;
00044         bool interactive:1;
00045         bool multiple:1;
00046 };
00047 
00048 struct xccdf_defflags {
00049         bool selected:1;
00050         bool hidden:1;
00051         bool resolved:1;
00052         bool abstract:1;
00053         bool prohibit_changes:1;
00054         bool interactive:1;
00055         bool multiple:1;
00056         bool weight:1;
00057         bool role:1;
00058         bool severity:1;
00059 };
00060 
00061 struct xccdf_item;
00062 struct xccdf_check;
00063 
00064 struct xccdf_item_base {
00065         char *id;
00066         char *cluster_id;
00067         float weight;
00068 
00069         struct oscap_list *title;
00070         struct oscap_list *description;
00071         struct oscap_list *question;
00072         struct oscap_list *rationale;
00073         struct oscap_list *warnings;
00074 
00075         char *version;
00076         char *version_update;
00077         char *version_time;
00078 
00079         struct xccdf_item *parent;
00080         char *extends;
00081         struct oscap_list *statuses;
00082         struct oscap_list *dc_statuses;
00083         struct oscap_list *references;
00084         struct oscap_list *platforms;
00085         struct xccdf_flags flags;
00086         struct xccdf_defflags defined_flags;
00087 
00088         struct oscap_list *metadata;
00089 };
00090 
00091 struct xccdf_rule_item {
00092         char *impact_metric;
00093         xccdf_role_t role;
00094         xccdf_level_t severity;
00095 
00096         struct oscap_list *requires;
00097         struct oscap_list *conflicts;
00098 
00099         struct oscap_list *profile_notes;
00100         struct oscap_list *idents;
00101         struct oscap_list *checks;
00102         struct oscap_list *fixes;
00103         struct oscap_list *fixtexts;
00104 };
00105 
00106 struct xccdf_group_item {
00107         struct oscap_list *requires;
00108         struct oscap_list *conflicts;
00109 
00110         struct oscap_list *values;
00111         struct oscap_list *content;
00112 };
00113 
00114 /* This structure is used for multiple-count attributes for Item (0-n) */
00115 struct xccdf_value_instance {
00116         char *selector;
00117         xccdf_value_type_t type;                    /* Value::type */
00118         char *value;               /* Value::value   */
00119         char *defval;              /* Value::default */
00120         struct oscap_list *choices;                 /* Value::choices */
00121     xccdf_numeric lower_bound;
00122     xccdf_numeric upper_bound;
00123     char *match;
00124         struct {
00125                 bool value_given : 1;
00126                 bool defval_given : 1;
00127                 bool must_match_given : 1;
00128                 bool must_match : 1;
00129         } flags;
00130 };
00131 
00132 struct xccdf_value_item {
00133         xccdf_value_type_t type;                    /* Value::type */
00134         xccdf_interface_hint_t interface_hint;      /* Value::interfaceHint */
00135         xccdf_operator_t oper;                      /* Value::operator */
00136 
00137         struct oscap_list *instances;
00138         struct oscap_list *sources;                 /* Value::source */
00139 };
00140 
00141 struct xccdf_result_item {
00142         const struct xccdf_version_info *schema_version;
00143 
00144         char *start_time;
00145         char *end_time;
00146         char *test_system;
00147         char *benchmark_uri;
00148         char *profile;
00149 
00150         struct oscap_list *identities;
00151         struct oscap_list *targets;
00152         struct oscap_list *organizations;
00153         struct oscap_list *remarks;
00154         struct oscap_list *target_addresses;
00155         struct oscap_list *target_facts;
00156         struct oscap_list *target_id_refs;
00157         struct oscap_list *applicable_platforms;
00158         struct oscap_list *setvalues;
00159         struct oscap_list *rule_results;
00160         struct oscap_list *scores;
00161 };
00162 
00163 struct xccdf_profile_item {
00164         char *note_tag;
00165         struct oscap_list *selects;
00166         struct oscap_list *setvalues;
00167         struct oscap_list *refine_values;
00168         struct oscap_list *refine_rules;
00169         bool tailoring;
00170 };
00171 
00172 struct xccdf_tailoring {
00173         // optional, only relevant when Tailoring is saved as a root element
00174         char *id;
00175 
00176         // The ref is "just informative" according to the spec, we never
00177         // interpret it and just load and save it as a string.
00178         char *benchmark_ref;
00179         // Also just informative
00180         char *benchmark_ref_version;
00181 
00182         struct oscap_list *statuses;
00183         struct oscap_list *dc_statuses;
00184 
00185         char *version;
00186         char *version_update;
00187         char *version_time;
00188 
00189         struct oscap_list *metadata;
00190 
00191         struct oscap_list *profiles;
00192 };
00193 
00194 struct xccdf_benchmark_item {
00195         const struct xccdf_version_info *schema_version;
00196 
00197         struct oscap_htable *items_dict;                /* Stores only xccdf:Item */
00198         struct oscap_htable *profiles_dict;             /* xccdf:Profile */
00199         struct oscap_htable *results_dict;              /* xccdf:TestResult */
00200         struct oscap_htable *clusters_dict;             /* xccdf:items by cluster-id */
00201         struct oscap_list *notices;
00202         struct oscap_list *plain_texts;
00203 
00204         struct cpe_dict_model *cpe_list;
00205         struct cpe_lang_model *cpe_lang_model;
00206 
00207         char *style;
00208         char *style_href;
00209         char *lang;
00210 
00211         struct oscap_list *front_matter;
00212         struct oscap_list *rear_matter;
00213 
00214         struct oscap_list *models;
00215         struct oscap_list *profiles;
00216         struct oscap_list *values;
00217         struct oscap_list *content;
00218         struct oscap_list *results;
00219 };
00220 
00221 struct xccdf_item {
00222         xccdf_type_t type;
00223         struct xccdf_item_base item;
00224         union {
00225                 struct xccdf_profile_item profile;
00226                 struct xccdf_benchmark_item benchmark;
00227                 struct xccdf_rule_item rule;
00228                 struct xccdf_group_item group;
00229                 struct xccdf_value_item value;
00230                 struct xccdf_result_item result;
00231         } sub;
00232 };
00233 
00234 struct xccdf_warning {
00235     struct oscap_text *text;
00236     xccdf_warning_category_t category;
00237 };
00238 
00239 struct xccdf_notice {
00240         char *id;
00241         struct oscap_text *text;
00242 };
00243 
00244 struct xccdf_status {
00245         xccdf_status_type_t status;
00246         time_t date;
00247 };
00248 
00249 struct xccdf_model {
00250         char *system;
00251         struct oscap_htable *params; // TODO: to list + accessors
00252 };
00253 
00254 struct xccdf_select {
00255         char *item;
00256         bool selected;
00257         struct oscap_list *remarks;
00258 };
00259 
00260 struct xccdf_refine_rule {
00261         char *item;
00262         char *selector;
00263         xccdf_role_t role;
00264         xccdf_level_t severity;
00265         xccdf_numeric weight;
00266         struct oscap_list *remarks;
00267 };
00268 
00269 struct xccdf_refine_value {
00270         char *item;
00271         char *selector;
00272         xccdf_operator_t oper;
00273         struct oscap_list *remarks;
00274 };
00275 
00276 struct xccdf_setvalue {
00277         char *item;
00278         char *value;
00279 };
00280 
00281 struct xccdf_ident {
00282         char *id;
00283         char *system;
00284 };
00285 
00286 struct xccdf_check {
00287         xccdf_bool_operator_t oper;
00288         struct oscap_list *children;
00289         char *id;
00290         char *system;
00291         char *selector;
00292         char *content;
00293         struct _xccdf_check_flags {
00294                 bool multicheck:1;
00295                 bool def_multicheck:1;
00296                 bool negate:1;
00297                 bool def_negate:1;
00298         } flags;
00299         struct oscap_list *imports;
00300         struct oscap_list *exports;
00301         struct oscap_list *content_refs;
00302 };
00303 
00304 struct xccdf_check_content_ref {
00305         char *href;
00306         char *name;
00307 };
00308 
00309 struct xccdf_check_import {
00310         char *name;
00311         char *xpath;
00312         char *content;
00313 };
00314 
00315 struct xccdf_check_export {
00316         char *name;
00317         char *value;
00318 };
00319 
00320 struct xccdf_profile_note {
00321         struct oscap_text *text;
00322         char *reftag;
00323 };
00324 
00325 struct xccdf_fix {
00326         bool reboot;
00327         xccdf_strategy_t strategy;
00328         xccdf_level_t disruption;
00329         xccdf_level_t complexity;
00330         char *id;
00331         char *content;
00332         char *system;
00333         char *platform;
00334 };
00335 
00336 struct xccdf_fixtext {
00337         struct oscap_text *text;
00338         bool reboot;
00339         xccdf_strategy_t strategy;
00340         xccdf_level_t disruption;
00341         xccdf_level_t complexity;
00342         char *fixref;
00343 };
00344 
00345 struct xccdf_rule_result {
00346         char *idref;
00347         xccdf_role_t role;
00348         char *time;
00349         float weight;
00350         xccdf_level_t severity;
00351         xccdf_test_result_type_t result;
00352         char *version;
00353 
00354         struct oscap_list *overrides;
00355         struct oscap_list *idents;
00356         struct oscap_list *messages;
00357         struct oscap_list *instances;
00358         struct oscap_list *fixes;
00359         struct oscap_list *checks;
00360 };
00361 
00362 struct xccdf_identity {
00363         struct {
00364                 bool authenticated : 1;
00365                 bool privileged    : 1;
00366         } sub;
00367         char *name;
00368 };
00369 
00370 struct xccdf_score {
00371         xccdf_numeric maximum;
00372         xccdf_numeric score;
00373         char *system;
00374 };
00375 
00376 struct xccdf_override {
00377         char *time;
00378         char *authority;
00379         xccdf_test_result_type_t old_result;
00380         xccdf_test_result_type_t new_result;
00381         struct oscap_text *remark;
00382 };
00383 
00384 struct xccdf_message {
00385         xccdf_message_severity_t severity;
00386         char *content;
00387 };
00388 
00389 struct xccdf_target_fact {
00390         xccdf_value_type_t type;
00391         char *name;
00392         char *value;
00393 };
00394 
00395 struct xccdf_target_identifier {
00396         bool any_element; // if false, this represents <target-id-ref>, else it's any element
00397 
00398         xmlNodePtr element;
00399 
00400         char *system;
00401         char *href;
00402         char *name;
00403 };
00404 
00405 struct xccdf_instance {
00406     char *context;
00407     char *parent_context;
00408     char *content;
00409 };
00410 
00411 struct xccdf_plain_text {
00412     char *id;
00413     char *text;
00414 };
00415 
00416 extern const struct oscap_string_map XCCDF_LEVEL_MAP[];
00417 extern const struct oscap_string_map XCCDF_ROLE_MAP[];
00418 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[];
00419 extern const struct oscap_string_map XCCDF_BOOLOP_MAP[];
00420 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[];
00421 extern const struct oscap_string_map XCCDF_FACT_TYPE_MAP[];
00422 extern const struct oscap_string_map XCCDF_RESULT_MAP[];
00423 
00424 extern const struct oscap_text_traits XCCDF_TEXT_PLAIN;
00425 extern const struct oscap_text_traits XCCDF_TEXT_HTML;
00426 extern const struct oscap_text_traits XCCDF_TEXT_PLAINSUB;
00427 extern const struct oscap_text_traits XCCDF_TEXT_HTMLSUB;
00428 extern const struct oscap_text_traits XCCDF_TEXT_NOTICE;
00429 extern const struct oscap_text_traits XCCDF_TEXT_PROFNOTE;
00430 
00431 extern const size_t XCCDF_NUMERIC_SIZE;
00432 extern const char *XCCDF_NUMERIC_FORMAT;
00433 
00434 struct xccdf_item *xccdf_item_new(xccdf_type_t type, struct xccdf_item *parent);
00435 void xccdf_item_release(struct xccdf_item *item);
00436 void xccdf_item_print(struct xccdf_item *item, int depth);
00437 void xccdf_item_dump(struct xccdf_item *item, int depth);
00438 struct xccdf_item* xccdf_item_get_benchmark_internal(struct xccdf_item* item);
00439 bool xccdf_benchmark_parse(struct xccdf_item *benchmark, xmlTextReaderPtr reader);
00440 void xccdf_benchmark_dump(struct xccdf_benchmark *benchmark);
00441 struct oscap_htable_iterator *xccdf_benchmark_get_cluster_items(struct xccdf_benchmark *benchmark, const char *cluster_id);
00442 bool xccdf_benchmark_register_item(struct xccdf_benchmark *benchmark, struct xccdf_item *item);
00443 bool xccdf_benchmark_unregister_item(struct xccdf_item *item);
00444 bool xccdf_benchmark_rename_item(struct xccdf_item *item, const char *newid);
00445 char *xccdf_benchmark_gen_id(struct xccdf_benchmark *benchmark, xccdf_type_t type, const char *prefix);
00446 struct xccdf_profile *xccdf_benchmark_get_profile_by_id(struct xccdf_benchmark *benchmark, const char *profile_id);
00447 struct xccdf_result *xccdf_benchmark_get_result_by_id(struct xccdf_benchmark *benchmark, const char *testresult_id);
00448 struct xccdf_result *xccdf_benchmark_get_result_by_id_suffix(struct xccdf_benchmark *benchmark, const char *testresult_suffix);
00449 bool xccdf_add_item(struct oscap_list *list, struct xccdf_item *parent, struct xccdf_item *item, const char *prefix);
00450 
00451 struct xccdf_tailoring *xccdf_tailoring_parse(xmlTextReaderPtr reader, struct xccdf_item* benchmark);
00452 xmlNodePtr xccdf_tailoring_to_dom(struct xccdf_tailoring *tailoring, xmlDocPtr doc, xmlNodePtr parent, const struct xccdf_version_info *version_info);
00453 
00454 struct xccdf_item *xccdf_profile_new_internal(struct xccdf_item *bench);
00455 struct xccdf_item *xccdf_profile_parse(xmlTextReaderPtr reader, struct xccdf_item *bench);
00456 void xccdf_profile_dump(struct xccdf_item *prof, int depth);
00457 
00458 bool xccdf_item_process_attributes(struct xccdf_item *item, xmlTextReaderPtr reader);
00459 bool xccdf_item_process_element(struct xccdf_item *item, xmlTextReaderPtr reader);
00460 
00461 bool xccdf_content_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
00462 struct xccdf_item *xccdf_group_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
00463 struct xccdf_item *xccdf_group_new_internal(struct xccdf_item *parent);
00464 void xccdf_group_dump(struct xccdf_item *group, int depth);
00465 
00466 struct xccdf_item *xccdf_rule_new_internal(struct xccdf_item *parent);
00467 struct xccdf_item *xccdf_rule_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
00468 void xccdf_rule_dump(struct xccdf_item *rule, int depth);
00469 struct xccdf_check_iterator *xccdf_rule_get_checks_filtered(struct xccdf_item *rule, char *selector);
00470 struct xccdf_check_iterator *xccdf_rule_get_complex_checks(struct xccdf_item *rule);
00471 
00472 struct xccdf_item *xccdf_value_parse(xmlTextReaderPtr reader, struct xccdf_item *parent);
00473 struct xccdf_item *xccdf_value_new_internal(struct xccdf_item *parent, xccdf_value_type_t type);
00474 void xccdf_value_dump(struct xccdf_item *value, int depth);
00475 
00476 struct xccdf_notice *xccdf_notice_new_parse(xmlTextReaderPtr reader);
00477 void xccdf_notice_dump(struct xccdf_notice *notice, int depth);
00478 
00479 void xccdf_status_dump(struct xccdf_status *status, int depth);
00480 
00481 struct xccdf_model *xccdf_model_new_xml(xmlTextReaderPtr reader);
00482 
00483 void xccdf_cstring_dump(const char *data, int depth);
00484 void xccdf_result_dump(struct xccdf_result *res, int depth);
00485 struct xccdf_result *xccdf_result_new_parse(xmlTextReaderPtr reader);
00486 int xccdf_rule_result_set_time_current(struct xccdf_rule_result *item);
00487 int xccdf_result_set_start_time_current(struct xccdf_result *item);
00488 int xccdf_result_set_end_time_current(struct xccdf_result *item);
00489 const struct xccdf_version_info* xccdf_result_get_schema_version(const struct xccdf_result *item);
00490 bool xccdf_result_set_schema_version(struct xccdf_result *item, const struct xccdf_version_info* newval);
00491 
00492 
00493 struct xccdf_check *xccdf_check_parse(xmlTextReaderPtr reader);
00494 void xccdf_check_dump(struct xccdf_check *check, int depth);
00495 bool xccdf_check_inject_content_ref(struct xccdf_check *check, const struct xccdf_check_content_ref *content, const char *name);
00496 void xccdf_check_content_ref_dump(struct xccdf_check_content_ref *ref, int depth);
00497 struct xccdf_ident *xccdf_ident_parse(xmlTextReaderPtr reader);
00498 void xccdf_ident_dump(struct xccdf_ident *ident, int depth);
00499 struct xccdf_fix *xccdf_fix_parse(xmlTextReaderPtr reader);
00500 struct xccdf_fixtext *xccdf_fixtext_parse(xmlTextReaderPtr reader);
00501 
00502 struct xccdf_setvalue *xccdf_setvalue_new_parse(xmlTextReaderPtr reader);
00503 void xccdf_setvalue_dump(struct xccdf_setvalue *sv, int depth);
00504 
00505 struct xccdf_warning *xccdf_warning_new_parse(xmlTextReaderPtr reader);
00506 
00507 //private methods for cloning items
00508 //Will clone the item member of a xccdf_item object
00509 void xccdf_item_base_clone(struct xccdf_item_base *new_base, const struct xccdf_item_base *old_base);
00510 
00511 //clones the specific types of items
00512 void xccdf_profile_item_clone(struct xccdf_profile_item *clone, const struct xccdf_profile_item * item);
00513 struct xccdf_benchmark_item * xccdf_benchmark_item_clone(struct xccdf_item *clone, const struct xccdf_benchmark * bench);
00514 void xccdf_rule_item_clone(struct xccdf_rule_item *clone, const struct xccdf_rule_item * item);
00515 void xccdf_group_item_clone(struct xccdf_item *parent, const struct xccdf_group_item * item);
00516 void xccdf_value_item_clone(struct xccdf_value_item *clone, const struct xccdf_value_item * item);
00517 struct xccdf_value_instance * xccdf_value_instance_clone(const struct xccdf_value_instance * val);
00518 void xccdf_result_item_clone(struct xccdf_result_item *clone, const struct xccdf_result_item * item);
00519 struct xccdf_profile_note * xccdf_profile_note_clone(const struct xccdf_profile_note * note);
00520 void xccdf_reparent_list(struct oscap_list * item_list, struct xccdf_item * parent);
00521 void xccdf_reparent_item(struct xccdf_item * item, struct xccdf_item * parent);
00522 
00523 void xccdf_texts_to_dom(struct oscap_text_iterator *texts, xmlNode *parent, const char *elname);
00524 
00525 #include "unused.h"
00526 
00527 OSCAP_HIDDEN_END;
00528 
00529 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines