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