Open SCAP Library
|
00001 /* 00002 * Copyright 2009 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 "public/xccdf.h" 00027 #include <assert.h> 00028 #include "elements.h" 00029 #include "../common/reference_priv.h" 00030 #include "../common/list.h" 00031 #include "../common/util.h" 00032 #include "../common/text_priv.h" 00033 00034 OSCAP_HIDDEN_START; 00035 00036 struct xccdf_flags { 00037 bool selected:1; 00038 bool hidden:1; 00039 bool resolved:1; 00040 bool abstract:1; 00041 bool prohibit_changes:1; 00042 bool interactive:1; 00043 bool multiple:1; 00044 }; 00045 00046 struct xccdf_defflags { 00047 bool selected:1; 00048 bool hidden:1; 00049 bool resolved:1; 00050 bool abstract:1; 00051 bool prohibit_changes:1; 00052 bool interactive:1; 00053 bool multiple:1; 00054 bool weight:1; 00055 bool role:1; 00056 bool severity:1; 00057 }; 00058 00059 struct xccdf_item; 00060 struct xccdf_check; 00061 00062 struct xccdf_item_base { 00063 char *id; 00064 char *cluster_id; 00065 float weight; 00066 00067 struct oscap_list *title; 00068 struct oscap_list *description; 00069 struct oscap_list *question; 00070 struct oscap_list *rationale; 00071 struct oscap_list *warnings; 00072 00073 char *version; 00074 char *version_update; 00075 time_t version_time; 00076 00077 struct xccdf_item *parent; 00078 char *extends; 00079 struct oscap_list *statuses; 00080 struct oscap_list *references; 00081 struct oscap_list *platforms; 00082 struct xccdf_flags flags; 00083 struct xccdf_defflags defined_flags; 00084 }; 00085 00086 struct xccdf_rule_item { 00087 char *impact_metric; 00088 xccdf_role_t role; 00089 xccdf_level_t severity; 00090 00091 struct oscap_list *requires; 00092 struct oscap_list *conflicts; 00093 00094 struct oscap_list *profile_notes; 00095 struct oscap_list *idents; 00096 struct oscap_list *checks; 00097 struct oscap_list *fixes; 00098 struct oscap_list *fixtexts; 00099 }; 00100 00101 struct xccdf_group_item { 00102 struct oscap_list *requires; 00103 struct oscap_list *conflicts; 00104 00105 struct oscap_list *values; 00106 struct oscap_list *content; 00107 }; 00108 00109 /* This structure is used for multiple-count attributes for Item (0-n) */ 00110 struct xccdf_value_instance { 00111 char *selector; 00112 xccdf_value_type_t type; /* Value::type */ 00113 char *value; /* Value::value */ 00114 char *defval; /* Value::default */ 00115 struct oscap_list *choices; /* Value::choices */ 00116 xccdf_numeric lower_bound; 00117 xccdf_numeric upper_bound; 00118 char *match; 00119 struct { 00120 bool value_given : 1; 00121 bool defval_given : 1; 00122 bool must_match_given : 1; 00123 bool must_match : 1; 00124 } flags; 00125 }; 00126 00127 struct xccdf_value_item { 00128 xccdf_value_type_t type; /* Value::type */ 00129 xccdf_interface_hint_t interface_hint; /* Value::interfaceHint */ 00130 xccdf_operator_t oper; /* Value::operator */ 00131 00132 struct oscap_list *instances; 00133 struct oscap_list *sources; /* Value::source */ 00134 }; 00135 00136 struct xccdf_result_item { 00137 time_t start_time; 00138 time_t end_time; 00139 char *test_system; 00140 char *benchmark_uri; 00141 char *profile; 00142 00143 struct oscap_list *identities; 00144 struct oscap_list *targets; 00145 struct oscap_list *organizations; 00146 struct oscap_list *remarks; 00147 struct oscap_list *target_addresses; 00148 struct oscap_list *target_facts; 00149 struct oscap_list *setvalues; 00150 struct oscap_list *rule_results; 00151 struct oscap_list *scores; 00152 }; 00153 00154 struct xccdf_profile_item { 00155 char *note_tag; 00156 struct oscap_list *selects; 00157 struct oscap_list *setvalues; 00158 struct oscap_list *refine_values; 00159 struct oscap_list *refine_rules; 00160 }; 00161 00162 struct xccdf_benchmark_item { 00163 00164 struct oscap_htable *dict; 00165 struct oscap_list *notices; 00166 struct oscap_list *plain_texts; 00167 00168 char *style; 00169 char *style_href; 00170 char *metadata; 00171 char *lang; 00172 00173 struct oscap_list *front_matter; 00174 struct oscap_list *rear_matter; 00175 00176 struct oscap_list *models; 00177 struct oscap_list *profiles; 00178 struct oscap_list *values; 00179 struct oscap_list *content; 00180 struct oscap_list *results; 00181 }; 00182 00183 struct xccdf_item { 00184 xccdf_type_t type; 00185 struct xccdf_item_base item; 00186 union { 00187 struct xccdf_profile_item profile; 00188 struct xccdf_benchmark_item benchmark; 00189 struct xccdf_rule_item rule; 00190 struct xccdf_group_item group; 00191 struct xccdf_value_item value; 00192 struct xccdf_result_item result; 00193 } sub; 00194 }; 00195 00196 struct xccdf_warning { 00197 struct oscap_text *text; 00198 xccdf_warning_category_t category; 00199 }; 00200 00201 struct xccdf_notice { 00202 char *id; 00203 struct oscap_text *text; 00204 }; 00205 00206 struct xccdf_status { 00207 xccdf_status_type_t status; 00208 time_t date; 00209 }; 00210 00211 struct xccdf_model { 00212 char *system; 00213 struct oscap_htable *params; // TODO: to list + accessors 00214 }; 00215 00216 struct xccdf_select { 00217 char *item; 00218 bool selected; 00219 struct oscap_list *remarks; 00220 }; 00221 00222 struct xccdf_refine_rule { 00223 char *item; 00224 char *selector; 00225 xccdf_role_t role; 00226 xccdf_level_t severity; 00227 xccdf_numeric weight; 00228 struct oscap_list *remarks; 00229 }; 00230 00231 struct xccdf_refine_value { 00232 char *item; 00233 char *selector; 00234 xccdf_operator_t oper; 00235 struct oscap_list *remarks; 00236 }; 00237 00238 struct xccdf_setvalue { 00239 char *item; 00240 char *value; 00241 }; 00242 00243 struct xccdf_ident { 00244 char *id; 00245 char *system; 00246 }; 00247 00248 struct xccdf_check { 00249 xccdf_bool_operator_t oper; 00250 struct oscap_list *children; 00251 char *id; 00252 char *system; 00253 char *selector; 00254 char *content; 00255 struct oscap_list *imports; 00256 struct oscap_list *exports; 00257 struct oscap_list *content_refs; 00258 }; 00259 00260 struct xccdf_check_content_ref { 00261 char *href; 00262 char *name; 00263 }; 00264 00265 struct xccdf_check_import { 00266 char *name; 00267 char *content; 00268 }; 00269 00270 struct xccdf_check_export { 00271 char *name; 00272 char *value; 00273 }; 00274 00275 struct xccdf_profile_note { 00276 struct oscap_text *text; 00277 char *reftag; 00278 }; 00279 00280 struct xccdf_fix { 00281 bool reboot; 00282 xccdf_strategy_t strategy; 00283 xccdf_level_t disruption; 00284 xccdf_level_t complexity; 00285 char *id; 00286 char *content; 00287 char *system; 00288 char *platform; 00289 }; 00290 00291 struct xccdf_fixtext { 00292 struct oscap_text *text; 00293 bool reboot; 00294 xccdf_strategy_t strategy; 00295 xccdf_level_t disruption; 00296 xccdf_level_t complexity; 00297 char *fixref; 00298 }; 00299 00300 /* 00301 struct xccdf_reference { 00302 struct oscap_text *text; 00303 char *href; 00304 }; 00305 */ 00306 00307 struct xccdf_rule_result { 00308 char *idref; 00309 xccdf_role_t role; 00310 time_t time; 00311 float weight; 00312 xccdf_level_t severity; 00313 xccdf_test_result_type_t result; 00314 char *version; 00315 00316 struct oscap_list *overrides; 00317 struct oscap_list *idents; 00318 struct oscap_list *messages; 00319 struct oscap_list *instances; 00320 struct oscap_list *fixes; 00321 struct oscap_list *checks; 00322 }; 00323 00324 struct xccdf_identity { 00325 struct { 00326 bool authenticated : 1; 00327 bool privileged : 1; 00328 } sub; 00329 char *name; 00330 }; 00331 00332 struct xccdf_score { 00333 xccdf_numeric maximum; 00334 xccdf_numeric score; 00335 char *system; 00336 }; 00337 00338 struct xccdf_override { 00339 time_t time; 00340 char *authority; 00341 xccdf_test_result_type_t old_result; 00342 xccdf_test_result_type_t new_result; 00343 struct oscap_text *remark; 00344 }; 00345 00346 struct xccdf_message { 00347 xccdf_message_severity_t severity; 00348 char *content; 00349 }; 00350 00351 struct xccdf_target_fact { 00352 xccdf_value_type_t type; 00353 char *name; 00354 char *value; 00355 }; 00356 00357 struct xccdf_instance { 00358 char *context; 00359 char *parent_context; 00360 char *content; 00361 }; 00362 00363 struct xccdf_plain_text { 00364 char *id; 00365 char *text; 00366 }; 00367 00368 extern const struct oscap_string_map XCCDF_LEVEL_MAP[]; 00369 extern const struct oscap_string_map XCCDF_ROLE_MAP[]; 00370 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[]; 00371 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[]; 00372 extern const struct oscap_string_map XCCDF_FACT_TYPE_MAP[]; 00373 extern const struct oscap_string_map XCCDF_RESULT_MAP[]; 00374 00375 extern const struct oscap_text_traits XCCDF_TEXT_PLAIN; 00376 extern const struct oscap_text_traits XCCDF_TEXT_HTML; 00377 extern const struct oscap_text_traits XCCDF_TEXT_PLAINSUB; 00378 extern const struct oscap_text_traits XCCDF_TEXT_HTMLSUB; 00379 extern const struct oscap_text_traits XCCDF_TEXT_NOTICE; 00380 extern const struct oscap_text_traits XCCDF_TEXT_PROFNOTE; 00381 00382 extern const size_t XCCDF_NUMERIC_SIZE; 00383 extern const char *XCCDF_NUMERIC_FORMAT; 00384 00385 struct xccdf_item *xccdf_item_new(xccdf_type_t type, struct xccdf_item *parent); 00386 void xccdf_item_release(struct xccdf_item *item); 00387 void xccdf_item_print(struct xccdf_item *item, int depth); 00388 void xccdf_item_dump(struct xccdf_item *item, int depth); 00389 struct xccdf_item* xccdf_item_get_benchmark_internal(struct xccdf_item* item); 00390 00391 bool xccdf_benchmark_parse(struct xccdf_item *benchmark, xmlTextReaderPtr reader); 00392 void xccdf_benchmark_dump(struct xccdf_benchmark *benchmark); 00393 bool xccdf_benchmark_register_item(struct xccdf_benchmark *benchmark, struct xccdf_item *item); 00394 bool xccdf_benchmark_unregister_item(struct xccdf_item *item); 00395 bool xccdf_benchmark_rename_item(struct xccdf_item *item, const char *newid); 00396 char *xccdf_benchmark_gen_id(struct xccdf_benchmark *benchmark, const char *prefix); 00397 bool xccdf_add_item(struct oscap_list *list, struct xccdf_item *parent, struct xccdf_item *item, const char *prefix); 00398 00399 struct xccdf_item *xccdf_profile_new_internal(struct xccdf_item *bench); 00400 struct xccdf_item *xccdf_profile_parse(xmlTextReaderPtr reader, struct xccdf_item *bench); 00401 void xccdf_profile_dump(struct xccdf_item *prof, int depth); 00402 00403 bool xccdf_item_process_attributes(struct xccdf_item *item, xmlTextReaderPtr reader); 00404 bool xccdf_item_process_element(struct xccdf_item *item, xmlTextReaderPtr reader); 00405 00406 bool xccdf_content_parse(xmlTextReaderPtr reader, struct xccdf_item *parent); 00407 struct xccdf_item *xccdf_group_parse(xmlTextReaderPtr reader, struct xccdf_item *parent); 00408 struct xccdf_item *xccdf_group_new_internal(struct xccdf_item *parent); 00409 void xccdf_group_dump(struct xccdf_item *group, int depth); 00410 00411 struct xccdf_item *xccdf_rule_new_internal(struct xccdf_item *parent); 00412 struct xccdf_item *xccdf_rule_parse(xmlTextReaderPtr reader, struct xccdf_item *parent); 00413 void xccdf_rule_dump(struct xccdf_item *rule, int depth); 00414 00415 struct xccdf_item *xccdf_value_parse(xmlTextReaderPtr reader, struct xccdf_item *parent); 00416 struct xccdf_item *xccdf_value_new_internal(struct xccdf_item *parent, xccdf_value_type_t type); 00417 void xccdf_value_dump(struct xccdf_item *value, int depth); 00418 00419 struct xccdf_notice *xccdf_notice_new_parse(xmlTextReaderPtr reader); 00420 void xccdf_notice_dump(struct xccdf_notice *notice, int depth); 00421 00422 void xccdf_status_dump(struct xccdf_status *status, int depth); 00423 00424 struct xccdf_model *xccdf_model_new_xml(xmlTextReaderPtr reader); 00425 00426 void xccdf_cstring_dump(const char *data, int depth); 00427 void xccdf_result_dump(struct xccdf_result *res, int depth); 00428 struct xccdf_result *xccdf_result_new_parse(xmlTextReaderPtr reader); 00429 00430 00431 struct xccdf_check *xccdf_check_parse(xmlTextReaderPtr reader); 00432 void xccdf_check_dump(struct xccdf_check *check, int depth); 00433 void xccdf_check_content_ref_dump(struct xccdf_check_content_ref *ref, int depth); 00434 struct xccdf_ident *xccdf_ident_parse(xmlTextReaderPtr reader); 00435 void xccdf_ident_dump(struct xccdf_ident *ident, int depth); 00436 struct xccdf_fix *xccdf_fix_parse(xmlTextReaderPtr reader); 00437 struct xccdf_fixtext *xccdf_fixtext_parse(xmlTextReaderPtr reader); 00438 00439 struct xccdf_setvalue *xccdf_setvalue_new_parse(xmlTextReaderPtr reader); 00440 void xccdf_setvalue_dump(struct xccdf_setvalue *sv, int depth); 00441 00442 struct xccdf_warning *xccdf_warning_new_parse(xmlTextReaderPtr reader); 00443 //struct xccdf_reference *xccdf_reference_new_parse(xmlTextReaderPtr reader); 00444 00445 //private methods for cloning items 00446 //Will clone the item member of a xccdf_item object 00447 void xccdf_item_base_clone(struct xccdf_item_base *new_base, const struct xccdf_item_base *old_base); 00448 00449 //clones the specific types of items 00450 void xccdf_profile_item_clone(struct xccdf_profile_item *clone, const struct xccdf_profile_item * item); 00451 struct xccdf_benchmark_item * xccdf_benchmark_item_clone(struct xccdf_item *clone, const struct xccdf_benchmark * bench); 00452 void xccdf_rule_item_clone(struct xccdf_rule_item *clone, const struct xccdf_rule_item * item); 00453 void xccdf_group_item_clone(struct xccdf_item *parent, const struct xccdf_group_item * item); 00454 void xccdf_value_item_clone(struct xccdf_value_item *clone, const struct xccdf_value_item * item); 00455 struct xccdf_value_instance * xccdf_value_instance_clone(const struct xccdf_value_instance * val); 00456 void xccdf_result_item_clone(struct xccdf_result_item *clone, const struct xccdf_result_item * item); 00457 struct xccdf_profile_note * xccdf_profile_note_clone(const struct xccdf_profile_note * note); 00458 void xccdf_reparent_list(struct oscap_list * item_list, struct xccdf_item * parent); 00459 void xccdf_reparent_item(struct xccdf_item * item, struct xccdf_item * parent); 00460 00461 void xccdf_texts_to_dom(struct oscap_text_iterator *texts, xmlNode *parent, const char *elname); 00462 00463 #include "unused.h" 00464 00465 OSCAP_HIDDEN_END; 00466 00467 #endif