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