00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef XCCDF_ITEM_
00026 #define XCCDF_ITEM_
00027
00028 #include "public/xccdf.h"
00029 #include <assert.h>
00030 #include "elements.h"
00031 #include "../common/list.h"
00032 #include "../common/util.h"
00033
00034 OSCAP_HIDDEN_START;
00035
00036 struct xccdf_flags {
00037 unsigned selected : 1;
00038 unsigned hidden : 1;
00039 unsigned resolved : 1;
00040 unsigned abstract : 1;
00041 unsigned prohibit_changes : 1;
00042 unsigned interactive : 1;
00043 unsigned multiple : 1;
00044 };
00045
00046 struct xccdf_item;
00047 struct xccdf_check;
00048
00049 struct xccdf_item_base {
00050 char* id;
00051 char* title;
00052 char* description;
00053 char* question;
00054 char* rationale;
00055 char* cluster_id;
00056 float weight;
00057
00058 char* version;
00059 char* version_update;
00060 time_t version_time;
00061
00062 struct xccdf_item* extends;
00063 struct xccdf_item* parent;
00064 struct oscap_list* statuses;
00065 struct oscap_list* references;
00066 struct oscap_list* platforms;
00067 struct xccdf_flags flags;
00068 struct xccdf_item* benchmark;
00069 };
00070
00071 struct xccdf_rule_item {
00072 char* impact_metric;
00073 xccdf_role_t role;
00074 xccdf_level_t severity;
00075 struct xccdf_check* check;
00076
00077 struct oscap_list* requires;
00078 struct oscap_list* conflicts;
00079
00080 struct oscap_list* profile_notes;
00081 struct oscap_list* idents;
00082 struct oscap_list* checks;
00083 struct oscap_list* fixes;
00084 struct oscap_list* fixtexts;
00085 };
00086
00087 struct xccdf_group_item {
00088 struct oscap_list* requires;
00089 struct oscap_list* conflicts;
00090
00091 struct oscap_list* values;
00092 struct oscap_list* content;
00093 };
00094
00095 union xccdf_value_unit {
00096 xccdf_numeric n;
00097 char* s;
00098 bool b;
00099 };
00100
00101 struct xccdf_value_val {
00102 union xccdf_value_unit value;
00103 union xccdf_value_unit defval;
00104 struct oscap_list* choices;
00105 bool must_match;
00106 union {
00107 struct {
00108 xccdf_numeric lower_bound;
00109 xccdf_numeric upper_bound;
00110 } n;
00111 struct {
00112 char* match;
00113 } s;
00114 } limits;
00115 };
00116
00117 struct xccdf_value_item {
00118 xccdf_value_type_t type;
00119 xccdf_interface_hint_t interface_hint;
00120 xccdf_operator_t oper;
00121 char* selector;
00122
00123 struct xccdf_value_val* value;
00124 struct oscap_htable* values;
00125
00126 struct oscap_list* sources;
00127 };
00128
00129
00130
00131
00132 struct xccdf_result_item {
00133 struct oscap_list* status;
00134 time_t start_time;
00135 time_t end_time;
00136 char* test_system;
00137 char* remark;
00138 char* organization;
00139 char* benchmark_uri;
00140
00141 struct xccdf_item* profile;
00142 struct oscap_list* identities;
00143 struct oscap_list* targets;
00144 struct oscap_list* target_addresses;
00145 struct oscap_list* target_facts;
00146 struct oscap_list* set_values;
00147 struct oscap_list* rule_results;
00148 struct oscap_list* scores;
00149 };
00150
00151 struct xccdf_profile_item {
00152 char* note_tag;
00153 struct oscap_list* selects;
00154 struct oscap_list* set_values;
00155 struct oscap_list* refine_values;
00156 struct oscap_list* refine_rules;
00157 };
00158
00159 struct xccdf_benchmark_item {
00160
00161 struct oscap_htable* dict;
00162 struct oscap_htable* auxdict;
00163 struct oscap_list* idrefs;
00164 struct oscap_list* notices;
00165 struct oscap_htable* plain_texts;
00166
00167 char* style;
00168 char* style_href;
00169 char* front_matter;
00170 char* rear_matter;
00171 char* metadata;
00172
00173 struct oscap_list* models;
00174 struct oscap_list* profiles;
00175 struct oscap_list* values;
00176 struct oscap_list* content;
00177 struct oscap_list* results;
00178 };
00179
00180
00181 struct xccdf_item {
00182 xccdf_type_t type;
00183 struct xccdf_item_base item;
00184 union {
00185 struct xccdf_profile_item profile;
00186 struct xccdf_benchmark_item bench;
00187 struct xccdf_rule_item rule;
00188 struct xccdf_group_item group;
00189 struct xccdf_value_item value;
00190 struct xccdf_result_item result;
00191 } sub;
00192 };
00193
00194 struct xccdf_notice {
00195 char* id;
00196 char* text;
00197 };
00198
00199 struct xccdf_status {
00200 xccdf_status_type_t status;
00201 time_t date;
00202 };
00203
00204 struct xccdf_model {
00205 char* system;
00206 struct oscap_htable* params;
00207 };
00208
00209 struct xccdf_selected {
00210 struct xccdf_item* item;
00211 bool selected;
00212 };
00213
00214 struct xccdf_refine_rule {
00215 struct xccdf_item* item;
00216 char* remark;
00217 char* selector;
00218 xccdf_role_t role;
00219 xccdf_level_t severity;
00220 float weight;
00221 };
00222
00223 struct xccdf_refine_value {
00224 struct xccdf_item* item;
00225 char* remark;
00226 char* selector;
00227 xccdf_operator_t oper;
00228 };
00229
00230 struct xccdf_set_value {
00231 struct xccdf_item* item;
00232 char* value;
00233 };
00234
00235 struct xccdf_ident {
00236 char* id;
00237 char* system;
00238 };
00239
00240 struct xccdf_check {
00241 xccdf_bool_operator_t oper;
00242 struct oscap_list* children;
00243 struct xccdf_item* parent;
00244 char* id;
00245 char* system;
00246 char* selector;
00247 char* content;
00248 struct oscap_list* imports;
00249 struct oscap_list* exports;
00250 struct oscap_list* content_refs;
00251 };
00252
00253 struct xccdf_check_content_ref {
00254 char* href;
00255 char* name;
00256 };
00257
00258 struct xccdf_check_import {
00259 char* name;
00260 char* content;
00261 };
00262
00263 struct xccdf_check_export {
00264 char* name;
00265 struct xccdf_item* value;
00266 };
00267
00268 struct xccdf_profile_note {
00269 char* reftag;
00270 char* text;
00271 };
00272
00273 struct xccdf_fix {
00274 bool reboot;
00275 xccdf_strategy_t strategy;
00276 xccdf_level_t disruption;
00277 xccdf_level_t complexity;
00278 char* id;
00279 char* content;
00280 char* system;
00281 char* platform;
00282 };
00283
00284 struct xccdf_fixtext {
00285 bool reboot;
00286 xccdf_strategy_t strategy;
00287 xccdf_level_t disruption;
00288 xccdf_level_t complexity;
00289 struct xccdf_fix* fixref;
00290 char* content;
00291 };
00292
00293 extern const struct oscap_string_map XCCDF_LEVEL_MAP[];
00294 extern const struct oscap_string_map XCCDF_ROLE_MAP[];
00295 extern const struct oscap_string_map XCCDF_OPERATOR_MAP[];
00296 extern const struct oscap_string_map XCCDF_STRATEGY_MAP[];
00297
00298 struct xccdf_item* xccdf_item_new(xccdf_type_t type, struct xccdf_item* bench, struct xccdf_item* parent);
00299 void xccdf_item_release(struct xccdf_item* item);
00300 void xccdf_item_get_print(struct xccdf_item* item, int depth);
00301 void xccdf_item_dump(struct xccdf_item* item, int depth);
00302 void xccdf_item_free(struct xccdf_item* item);
00303
00304 struct xccdf_item* xccdf_benchmark_new_empty(void);
00305 bool xccdf_benchmark_get_parse(struct xccdf_item* benchmark, xmlTextReaderPtr reader);
00306 bool xccdf_benchmark_add_ref(struct xccdf_item* benchmark, struct xccdf_item** ptr, const char* id, xccdf_type_t type);
00307 void xccdf_benchmark_dump(struct xccdf_benchmark* benchmark);
00308
00309 struct xccdf_item* xccdf_profile_new_empty(struct xccdf_item* bench);
00310 struct xccdf_item* xccdf_profile_new_parse(xmlTextReaderPtr reader, struct xccdf_item* bench);
00311 void xccdf_profile_dump(struct xccdf_item* prof, int depth);
00312 void xccdf_profile_free(struct xccdf_item* prof);
00313
00314 bool xccdf_item_get_process_attributes(struct xccdf_item* item, xmlTextReaderPtr reader);
00315 bool xccdf_item_get_process_element(struct xccdf_item* item, xmlTextReaderPtr reader);
00316
00317 bool xccdf_content_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00318 struct xccdf_item* xccdf_group_new_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00319 void xccdf_group_dump(struct xccdf_item* group, int depth);
00320 void xccdf_group_free(struct xccdf_item* group);
00321
00322 struct xccdf_item* xccdf_rule_new_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00323 void xccdf_rule_dump(struct xccdf_item* rule, int depth);
00324 void xccdf_rule_free(struct xccdf_item* rule);
00325
00326 struct xccdf_item* xccdf_value_new_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00327 void xccdf_value_dump(struct xccdf_item* value, int depth);
00328 void xccdf_value_free(struct xccdf_item* val);
00329
00330 struct xccdf_notice* xccdf_notice_new(const char* id, char* text);
00331 void xccdf_notice_dump(struct xccdf_notice* notice, int depth);
00332 void xccdf_notice_free(struct xccdf_notice* notice);
00333
00334 struct xccdf_status* xccdf_status_new(const char* status, const char* date);
00335 void xccdf_status_dump(struct xccdf_status* status, int depth);
00336 void xccdf_status_free(struct xccdf_status* status);
00337
00338 struct xccdf_model* xccdf_model_new_xml(xmlTextReaderPtr reader);
00339 void xccdf_model_free(struct xccdf_model* model);
00340
00341 void xccdf_cstring_dump(const char* data, int depth);
00342
00343 struct xccdf_ident* xccdf_ident_new(const char* id, const char* system);
00344 void xccdf_ident_free(struct xccdf_ident* ident);
00345
00346 struct xccdf_check* xccdf_check_new_empty(struct xccdf_item* parent);
00347 struct xccdf_check* xccdf_check_new_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00348 void xccdf_check_dump(struct xccdf_check* check, int depth);
00349 void xccdf_check_free(struct xccdf_check* check);
00350 void xccdf_check_content_ref_free(struct xccdf_check_content_ref* ref);
00351 void xccdf_check_content_ref_dump(struct xccdf_check_content_ref* ref, int depth);
00352 struct xccdf_ident* xccdf_ident_new(const char* id, const char* system);
00353 struct xccdf_ident* xccdf_ident_new_parse(xmlTextReaderPtr reader);
00354 void xccdf_ident_dump(struct xccdf_ident* ident, int depth);
00355 void xccdf_ident_free(struct xccdf_ident* ident);
00356 void xccdf_profile_note_free(struct xccdf_profile_note* note);
00357 void xccdf_check_import_free(struct xccdf_check_import* item);
00358 void xccdf_check_export_free(struct xccdf_check_export* item);
00359 struct xccdf_fix* xccdf_fix_new_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00360 struct xccdf_fixtext* xccdf_fixtext_new_parse(xmlTextReaderPtr reader, struct xccdf_item* parent);
00361 void xccdf_fixtext_free(struct xccdf_fixtext* item);
00362 void xccdf_fix_free(struct xccdf_fix* item);
00363 void xccdf_set_value_free(struct xccdf_set_value* sv);
00364
00365
00366
00367 #define MACRO_BLOCK(code) do { code } while(false)
00368 #define ASSERT_TYPE(item,t) assert((item)->type & t)
00369 #define ASSERT_BENCHMARK(item) ASSERT_TYPE(item, XCCDF_BENCHMARK)
00370 #define XBENCHMARK(item) ((struct xccdf_benchmark*)item)
00371 #define XPROFILE(item) ((struct xccdf_profile*)item)
00372 #define XGROUP(item) ((struct xccdf_group*)item)
00373 #define XRULE(item) ((struct xccdf_rule*)item)
00374 #define XITEM(item) ((struct xccdf_item*)item)
00375
00376 #define XCCDF_STATUS_CURRENT(TYPE) \
00377 xccdf_status_type_t xccdf_##TYPE##_get_status_current(const struct xccdf_##TYPE* item) {\
00378 return xccdf_item_get_status_current(XITEM(item)); }
00379
00380 #define XCCDF_GENERIC_GETTER(RTYPE,TNAME,MEMBER) \
00381 RTYPE xccdf_##TNAME##_get_##MEMBER(const struct xccdf_##TNAME* item) { return (RTYPE)((item)->MEMBER); }
00382 #define XCCDF_GENERIC_IGETTER(ITYPE,TNAME,MNAME) \
00383 struct xccdf_##ITYPE##_iterator* xccdf_##TNAME##_get_##MNAME(const struct xccdf_##TNAME* item) \
00384 { return oscap_iterator_new(item->MNAME); }
00385 #define XCCDF_ABSTRACT_GETTER(RTYPE,TNAME,MNAME,MEMBER) \
00386 RTYPE xccdf_##TNAME##_get_##MNAME(const struct xccdf_##TNAME* item) { return (RTYPE)(XITEM(item)->MEMBER); }
00387 #define XCCDF_ITERATOR_GETTER(ITYPE,TNAME,MNAME,MEMBER) \
00388 struct xccdf_##ITYPE##_iterator* xccdf_##TNAME##_get_##MNAME(const struct xccdf_##TNAME* item) \
00389 { return oscap_iterator_new(XITEM(item)->MEMBER); }
00390 #define XCCDF_SITERATOR_GETTER(TNAME,MNAME,MEMBER) \
00391 struct oscap_string_iterator* xccdf_##TNAME##_get_##MNAME(const struct xccdf_##TNAME* item) \
00392 { return oscap_iterator_new(XITEM(item)->MEMBER); }
00393 #define XCCDF_HTABLE_GETTER(RTYPE,TNAME,MNAME,MEMBER) \
00394 RTYPE xccdf_##TNAME##_get_##MNAME(const struct xccdf_##TNAME* item, const char* key) \
00395 { return (RTYPE)oscap_htable_get(XITEM(item)->MEMBER, key); }
00396 #define XCCDF_SIGETTER(TNAME,MNAME) \
00397 struct oscap_string_iterator* xccdf_##TNAME##_get_##MNAME(const struct xccdf_##TNAME* item) \
00398 { return oscap_iterator_new(XITEM(item)->sub.TNAME.MNAME); }
00399
00400 #define XCCDF_BENCHMARK_GETTER_A(RTYPE,MNAME,MEMBER) XCCDF_ABSTRACT_GETTER(RTYPE,benchmark,MNAME,MEMBER)
00401 #define XCCDF_BENCHMARK_GETTER_I(RTYPE,MNAME) XCCDF_BENCHMARK_GETTER_A(RTYPE,MNAME,item.MNAME)
00402 #define XCCDF_BENCHMARK_IGETTER_I(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,benchmark,MNAME,item.MNAME)
00403 #define XCCDF_BENCHMARK_GETTER(RTYPE,MNAME) XCCDF_BENCHMARK_GETTER_A(RTYPE,MNAME,sub.bench.MNAME)
00404 #define XCCDF_BENCHMARK_IGETTER(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,benchmark,MNAME,sub.bench.MNAME)
00405
00406 #define XCCDF_PROFILE_GETTER_A(RTYPE,MNAME,MEMBER) XCCDF_ABSTRACT_GETTER(RTYPE,profile,MNAME,MEMBER)
00407 #define XCCDF_PROFILE_GETTER_I(RTYPE,MNAME) XCCDF_PROFILE_GETTER_A(RTYPE,MNAME,item.MNAME)
00408 #define XCCDF_PROFILE_IGETTER_I(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,profile,MNAME,item.MNAME)
00409 #define XCCDF_PROFILE_GETTER(RTYPE,MNAME) XCCDF_PROFILE_GETTER_A(RTYPE,MNAME,sub.profile.MNAME)
00410 #define XCCDF_PROFILE_IGETTER(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,profile,MNAME,sub.profile.MNAME)
00411
00412 #define XCCDF_RULE_GETTER_A(RTYPE,MNAME,MEMBER) XCCDF_ABSTRACT_GETTER(RTYPE,rule,MNAME,MEMBER)
00413 #define XCCDF_RULE_GETTER_I(RTYPE,MNAME) XCCDF_RULE_GETTER_A(RTYPE,MNAME,item.MNAME)
00414 #define XCCDF_RULE_IGETTER_I(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,rule,MNAME,item.MNAME)
00415 #define XCCDF_RULE_GETTER(RTYPE,MNAME) XCCDF_RULE_GETTER_A(RTYPE,MNAME,sub.rule.MNAME)
00416 #define XCCDF_RULE_IGETTER(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,rule,MNAME,sub.rule.MNAME)
00417
00418 #define XCCDF_GROUP_GETTER_A(RTYPE,MNAME,MEMBER) XCCDF_ABSTRACT_GETTER(RTYPE,group,MNAME,MEMBER)
00419 #define XCCDF_GROUP_GETTER_I(RTYPE,MNAME) XCCDF_GROUP_GETTER_A(RTYPE,MNAME,item.MNAME)
00420 #define XCCDF_GROUP_IGETTER_I(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,group,MNAME,item.MNAME)
00421 #define XCCDF_GROUP_GETTER(RTYPE,MNAME) XCCDF_GROUP_GETTER_A(RTYPE,MNAME,sub.group.MNAME)
00422 #define XCCDF_GROUP_IGETTER(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,group,MNAME,sub.group.MNAME)
00423
00424 #define XCCDF_VALUE_GETTER_A(RTYPE,MNAME,MEMBER) XCCDF_ABSTRACT_GETTER(RTYPE,value,MNAME,MEMBER)
00425 #define XCCDF_VALUE_GETTER_I(RTYPE,MNAME) XCCDF_VALUE_GETTER_A(RTYPE,MNAME,item.MNAME)
00426 #define XCCDF_VALUE_IGETTER_I(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,value,MNAME,item.MNAME)
00427 #define XCCDF_VALUE_GETTER(RTYPE,MNAME) XCCDF_VALUE_GETTER_A(RTYPE,MNAME,sub.value.MNAME)
00428 #define XCCDF_VALUE_IGETTER(ITYPE,MNAME) XCCDF_ITERATOR_GETTER(ITYPE,value,MNAME,sub.value.MNAME)
00429
00430 #define XCCDF_ITEM_GETTER(RTYPE,MNAME) \
00431 XCCDF_ABSTRACT_GETTER(RTYPE,item,MNAME,item.MNAME) \
00432 XCCDF_BENCHMARK_GETTER_A(RTYPE,MNAME,item.MNAME) \
00433 XCCDF_PROFILE_GETTER_A(RTYPE,MNAME,item.MNAME) \
00434 XCCDF_RULE_GETTER_A(RTYPE,MNAME,item.MNAME) \
00435 XCCDF_VALUE_GETTER_A(RTYPE,MNAME,item.MNAME) \
00436 XCCDF_GROUP_GETTER_A(RTYPE,MNAME,item.MNAME)
00437 #define XCCDF_ITEM_IGETTER(RTYPE,MNAME) \
00438 XCCDF_ITERATOR_GETTER(RTYPE,item,MNAME,item.MNAME) \
00439 XCCDF_ITERATOR_GETTER(RTYPE,benchmark,MNAME,item.MNAME) \
00440 XCCDF_ITERATOR_GETTER(RTYPE,profile,MNAME,item.MNAME) \
00441 XCCDF_ITERATOR_GETTER(RTYPE,rule,MNAME,item.MNAME) \
00442 XCCDF_ITERATOR_GETTER(RTYPE,value,MNAME,item.MNAME) \
00443 XCCDF_ITERATOR_GETTER(RTYPE,group,MNAME,item.MNAME)
00444 #define XCCDF_ITEM_SIGETTER(MNAME) \
00445 XCCDF_SITERATOR_GETTER(item,MNAME,item.MNAME) \
00446 XCCDF_SITERATOR_GETTER(benchmark,MNAME,item.MNAME) \
00447 XCCDF_SITERATOR_GETTER(profile,MNAME,item.MNAME) \
00448 XCCDF_SITERATOR_GETTER(rule,MNAME,item.MNAME) \
00449 XCCDF_SITERATOR_GETTER(value,MNAME,item.MNAME) \
00450 XCCDF_SITERATOR_GETTER(group,MNAME,item.MNAME)
00451 #define XCCDF_FLAG_GETTER(MNAME) \
00452 XCCDF_BENCHMARK_GETTER_A(bool,MNAME,item.flags.MNAME) \
00453 XCCDF_PROFILE_GETTER_A(bool,MNAME,item.flags.MNAME) \
00454 XCCDF_RULE_GETTER_A(bool,MNAME,item.flags.MNAME) \
00455 XCCDF_VALUE_GETTER_A(bool,MNAME,item.flags.MNAME) \
00456 XCCDF_GROUP_GETTER_A(bool,MNAME,item.flags.MNAME)
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 #define XITERATOR(x) ((struct oscap_iterator*)(x))
00468 #define XCCDF_ITERATOR(n) struct xccdf_##n##_iterator*
00469 #define XCCDF_ITERATOR_FWD(n) struct xccdf_##n##_iterator;
00470 #define XCCDF_ITERATOR_HAS_MORE(n) bool xccdf_##n##_iterator_has_more(XCCDF_ITERATOR(n) it) { return oscap_iterator_has_more(XITERATOR(it)); }
00471 #define XCCDF_ITERATOR_NEXT(t,n) t xccdf_##n##_iterator_next(XCCDF_ITERATOR(n) it) { return oscap_iterator_next(XITERATOR(it)); }
00472 #define XCCDF_ITERATOR_FREE(n) void xccdf_##n##_iterator_free(XCCDF_ITERATOR(n) it) { oscap_iterator_free(XITERATOR(it)); }
00473 #define XCCDF_ITERATOR_GEN_T(t,n) XCCDF_ITERATOR_FWD(n) XCCDF_ITERATOR_HAS_MORE(n) XCCDF_ITERATOR_NEXT(t,n) XCCDF_ITERATOR_FREE(n)
00474 #define XCCDF_ITERATOR_GEN_S(n) XCCDF_ITERATOR_GEN_T(struct xccdf_##n*,n)
00475
00476 OSCAP_HIDDEN_END;
00477
00478 #endif
00479