| 1 | /* |
| 2 | * Copyright 2009--2014 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * @addtogroup XCCDF_POLICY |
| 24 | * @{ |
| 25 | * @file xccdf_policy.h |
| 26 | * Open-scap XCCDF Policy library interface. |
| 27 | * @author Maros Barabas <[email protected]> |
| 28 | * @author Dave Niemoller <[email protected]> |
| 29 | */ |
| 30 | |
| 31 | #ifndef XCCDF_POLICY_H_ |
| 32 | #define XCCDF_POLICY_H_ |
| 33 | |
| 34 | #include <xccdf_benchmark.h> |
| 35 | #include <stdbool.h> |
| 36 | #include <time.h> |
| 37 | #include <oscap.h> |
| 38 | #include "oscap_export.h" |
| 39 | #include "oval_definitions.h" |
| 40 | |
| 41 | /** |
| 42 | * @struct xccdf_policy_model |
| 43 | * Handle all policies for given XCCDF benchmark |
| 44 | */ |
| 45 | struct xccdf_policy_model; |
| 46 | |
| 47 | /** |
| 48 | * @struct xccdf_policy |
| 49 | * Policy structure that abstract benchmark's profile |
| 50 | */ |
| 51 | struct xccdf_policy; |
| 52 | |
| 53 | /** |
| 54 | * @struct xccdf_value_binding |
| 55 | * Value bindings of policy |
| 56 | */ |
| 57 | struct xccdf_value_binding; |
| 58 | |
| 59 | struct xccdf_value_binding_iterator; |
| 60 | |
| 61 | /** |
| 62 | * @struct xccdf_policy_iterator |
| 63 | * Iterate through policies |
| 64 | * @see xccdf_policy_model_get_policies |
| 65 | */ |
| 66 | struct xccdf_policy_iterator; |
| 67 | |
| 68 | /** |
| 69 | * Type of a query over checking-engine data. |
| 70 | * This allows xccdf_policy module to query checking engine and acquire comprehensive info. |
| 71 | */ |
| 72 | typedef enum { |
| 73 | POLICY_ENGINE_QUERY_NAMES_FOR_HREF = 1, /// Considering xccdf:check-content-ref, what are possible @name attributes for given href? |
| 74 | POLICY_ENGINE_QUERY_OVAL_DEFS_FOR_HREF = 2, /// Considering xccdf:check-content-ref, what are OVAL definitions for given href? |
| 75 | } xccdf_policy_engine_query_t; |
| 76 | |
| 77 | /** |
| 78 | * Type of function which implements queries defined within xccdf_policy_engine_query_t. |
| 79 | * |
| 80 | * Each checking engine may register its own function of the xccdf_policy_engine_query_fn |
| 81 | * type. The registered function is then used by xccdf_policy module to acquire comprehensive |
| 82 | * info about the checking-engine itself or the data fed in. First argument of the function |
| 83 | * is always user data as registered. Second argument defines the query. Third argument is |
| 84 | * dependent on query and defined as follows: |
| 85 | * - (const char *)href -- for POLICY_ENGINE_QUERY_NAMES_FOR_HREF |
| 86 | * - (const char *)href -- for POLICY_ENGINE_QUERY_OVAL_DEFS_FOR_HREF |
| 87 | * |
| 88 | * Expected return type depends also on query as follows: |
| 89 | * - (struct oscap_stringlist *) -- for POLICY_ENGINE_QUERY_NAMES_FOR_HREF |
| 90 | * - (struct oscap_list *) -- for POLICY_ENGINE_QUERY_OVAL_DEFS_FOR_HREF |
| 91 | * - NULL shall be returned if the function doesn't understand the query. |
| 92 | */ |
| 93 | typedef void *(*xccdf_policy_engine_query_fn) (void *, xccdf_policy_engine_query_t, void *); |
| 94 | |
| 95 | /** |
| 96 | * Type of function which implements OpenSCAP checking engine. |
| 97 | * |
| 98 | * This function defines basic interface between XCCDF module and thee checking engine. |
| 99 | * For each checking engine required for evaluation there should be at least one such |
| 100 | * function registerd. The registered function is then used by xccdf_policy module to |
| 101 | * perform evaluation on the machine. |
| 102 | */ |
| 103 | typedef xccdf_test_result_type_t (*xccdf_policy_engine_eval_fn) (struct xccdf_policy *policy, const char *rule_id, const char *definition_id, const char *href_if, struct xccdf_value_binding_iterator *value_binding_it, struct xccdf_check_import_iterator *check_imports_it, void *user_data); |
| 104 | |
| 105 | /************************************************************/ |
| 106 | |
| 107 | /** |
| 108 | * Constructor of Policy Model structure |
| 109 | * @param benchmark Struct xccdf_benchmark with benchmark model |
| 110 | * @return new xccdf_policy_model |
| 111 | * @note |
| 112 | * The policy model will take ownership of given benchmark and free it |
| 113 | * when it's being destructed! |
| 114 | * @memberof xccdf_policy_model |
| 115 | */ |
| 116 | OSCAP_API struct xccdf_policy_model *xccdf_policy_model_new(struct xccdf_benchmark *benchmark); |
| 117 | |
| 118 | /** |
| 119 | * Constructor of Policy structure |
| 120 | * @param model Policy model |
| 121 | * @param profile Profile from XCCDF Benchmark |
| 122 | * @memberof xccdf_policy |
| 123 | */ |
| 124 | OSCAP_API struct xccdf_policy * xccdf_policy_new(struct xccdf_policy_model * model, struct xccdf_profile * profile); |
| 125 | |
| 126 | /** |
| 127 | * Constructor of structure with profile bindings - refine_rules, refine_values and set_values |
| 128 | * @memberof xccdf_value_binding |
| 129 | * @return new structure of xccdf_value_binding |
| 130 | */ |
| 131 | OSCAP_API struct xccdf_value_binding * xccdf_value_binding_new(void); |
| 132 | |
| 133 | /** |
| 134 | * Destructor of Policy Model structure |
| 135 | * @memberof xccdf_policy_model |
| 136 | */ |
| 137 | OSCAP_API void xccdf_policy_model_free(struct xccdf_policy_model *); |
| 138 | |
| 139 | /** |
| 140 | * Destructor of Policy structure |
| 141 | * @memberof xccdf_policy |
| 142 | */ |
| 143 | OSCAP_API void xccdf_policy_free(struct xccdf_policy *); |
| 144 | |
| 145 | /** |
| 146 | * Destructor of Value binding structure |
| 147 | * @memberof xccdf_value_binding |
| 148 | */ |
| 149 | OSCAP_API void xccdf_value_binding_free(struct xccdf_value_binding *); |
| 150 | |
| 151 | /** |
| 152 | * Sets the Tailoring element to use in the policy. |
| 153 | * |
| 154 | * Profiles from the Benchmark *may* be shadowed by profiles in the given |
| 155 | * Tailoring element! Calling this function will affect the results of |
| 156 | * xccdf_policy_model_get_policy_by_id calls. |
| 157 | * |
| 158 | * @important This does INVALIDATE preexisting xccdf_policy pointers in |
| 159 | * this xccdf_policy_model! It is recommended to call this function before |
| 160 | * policy for any profile is queried. |
| 161 | * |
| 162 | * @note |
| 163 | * The policy model will take ownership of given tailoring and free it |
| 164 | * when it's being destructed or when new tailoring is being set. |
| 165 | */ |
| 166 | OSCAP_API bool xccdf_policy_model_set_tailoring(struct xccdf_policy_model *model, struct xccdf_tailoring *tailoring); |
| 167 | |
| 168 | /** |
| 169 | * Retrieves the Tailoring element used in this policy. |
| 170 | * @memberof xccdf_policy_model |
| 171 | */ |
| 172 | OSCAP_API struct xccdf_tailoring *xccdf_policy_model_get_tailoring(struct xccdf_policy_model *model); |
| 173 | |
| 174 | /** |
| 175 | * Get whether rule details such as description or rationale should be shown in command line output. |
| 176 | * @param policy XCCDF policy |
| 177 | * @returns true if rule details should be shown, false otherwise |
| 178 | */ |
| 179 | OSCAP_API bool xccdf_policy_get_show_rule_details(struct xccdf_policy *policy); |
| 180 | |
| 181 | /** |
| 182 | * Set whether rule details such as description or rationale should be shown in command line output. |
| 183 | * @param policy_model XCCDF policy model |
| 184 | * @param show_rule_details true if rule details should be shown, false otherwise |
| 185 | */ |
| 186 | OSCAP_API void xccdf_policy_model_set_show_rule_details(struct xccdf_policy_model *policy_model, bool show_rule_details); |
| 187 | |
| 188 | /** |
| 189 | * Get human readable title of given XCCDF Item. This finds title with best matching language |
| 190 | * and resolves <xccdf:sub> substitution in accordance with the given XCCDF Policy. |
| 191 | * @memberof xccdf_policy |
| 192 | * @param policy XCCDF Policy |
| 193 | * @param item XCCDF Item to query title from |
| 194 | * @param preferred_lang Language of your choice, Null value for the default. |
| 195 | * @returns plaintext C string which must be freed by caller |
| 196 | */ |
| 197 | OSCAP_API char *xccdf_policy_get_readable_item_title(struct xccdf_policy *policy, struct xccdf_item *item, const char *preferred_lang); |
| 198 | |
| 199 | /** |
| 200 | * Get human readable rationale of given XCCDF Item. This function searches for description |
| 201 | * with the best matching language and resolves any inner <xccdf:sub> substitution (in accordance |
| 202 | * with the given XCCDF Policy. |
| 203 | * @memberof xccdf_policy |
| 204 | * @param policy XCCDF Policy |
| 205 | * @param item XCCDF Item to query rationale from |
| 206 | * @param preferred_lang Language of your choice, Null value for the default. |
| 207 | * @returns plaintext C string which must be freed by caller |
| 208 | */ |
| 209 | OSCAP_API char *xccdf_policy_get_readable_item_rationale(struct xccdf_policy *policy, struct xccdf_item *item, const char *preferred_lang); |
| 210 | |
| 211 | /** |
| 212 | * Get human readable description of given XCCDF Item. This function searches for description |
| 213 | * with the best matching language and resolves any inner <xccdf:sub> substitution (in accordance |
| 214 | * with the given XCCDF Policy. |
| 215 | * @memberof xccdf_policy |
| 216 | * @param policy XCCDF Policy |
| 217 | * @param item XCCDF Item to query description from |
| 218 | * @param preferred_lang Language of your choice, Null value for the default. |
| 219 | * @returns plaintext C string which must be freed by caller |
| 220 | */ |
| 221 | OSCAP_API char *xccdf_policy_get_readable_item_description(struct xccdf_policy *policy, struct xccdf_item *item, const char *preferred_lang); |
| 222 | |
| 223 | /** |
| 224 | * Registers an additional CPE dictionary for applicability testing |
| 225 | * The one embedded in the evaluated XCCDF take precedence! |
| 226 | */ |
| 227 | OSCAP_API bool xccdf_policy_model_add_cpe_dict_source(struct xccdf_policy_model * model, struct oscap_source *source); |
| 228 | |
| 229 | /** |
| 230 | * Registers an additional CPE dictionary for applicability testing |
| 231 | * The one embedded in the evaluated XCCDF take precedence! |
| 232 | * |
| 233 | * @deprecated Deprecated in favor of @ref xccdf_policy_model_add_cpe_dict_source |
| 234 | */ |
| 235 | OSCAP_API bool xccdf_policy_model_add_cpe_dict(struct xccdf_policy_model * model, const char * cpe_dict); |
| 236 | |
| 237 | /** |
| 238 | * Registers an additional CPE lang model for applicability testing |
| 239 | * The one embedded in the evaluated XCCDF take precedence! |
| 240 | */ |
| 241 | OSCAP_API bool xccdf_policy_model_add_cpe_lang_model_source(struct xccdf_policy_model * model, struct oscap_source *source); |
| 242 | |
| 243 | /** |
| 244 | * Registers an additional CPE resource (either dictionary or language) |
| 245 | * Autodetects given file and acts accordingly. |
| 246 | * The one embedded in the evaluated XCCDF take precedence! |
| 247 | */ |
| 248 | OSCAP_API bool xccdf_policy_model_add_cpe_autodetect_source(struct xccdf_policy_model *model, struct oscap_source *source); |
| 249 | |
| 250 | /** |
| 251 | * Retrieves an iterator of all OVAL sessions created for CPE applicability evaluation |
| 252 | * key is the OVAL href, value is the OVAL session itself (type oval_agent_session*) |
| 253 | */ |
| 254 | OSCAP_API struct oscap_htable_iterator *xccdf_policy_model_get_cpe_oval_sessions(struct xccdf_policy_model *model); |
| 255 | |
| 256 | /** |
| 257 | * Function to register callback for checking system |
| 258 | * @param model XCCDF Policy Model |
| 259 | * @param sys String representing given checking system |
| 260 | * @param eval_fn Callback - pointer to function called by XCCDF Policy system when rule parsed |
| 261 | * @param usr optional parameter for passing user data to callback |
| 262 | * @param query_fn - optional parameter for providing xccdf_policy_engine_query_fn implementation for given system. |
| 263 | * @memberof xccdf_policy_model |
| 264 | * @return true if callback registered succesfully, false otherwise |
| 265 | */ |
| 266 | OSCAP_API bool xccdf_policy_model_register_engine_and_query_callback(struct xccdf_policy_model *model, char *sys, xccdf_policy_engine_eval_fn eval_fn, void *usr, xccdf_policy_engine_query_fn query_fn); |
| 267 | |
| 268 | typedef int (*policy_reporter_output)(struct xccdf_rule_result *, void *); |
| 269 | |
| 270 | /** |
| 271 | * Function to register output callback for checking system that will be called AFTER each rule evaluation. |
| 272 | * @param model XCCDF Policy Model |
| 273 | * @param func Callback - pointer to function called by XCCDF Policy system when rule parsed |
| 274 | * @param usr optional parameter for passing user data to callback |
| 275 | * @memberof xccdf_policy_model |
| 276 | * @return true if callback registered succesfully, false otherwise |
| 277 | */ |
| 278 | OSCAP_API bool xccdf_policy_model_register_output_callback(struct xccdf_policy_model * model, policy_reporter_output func, void * usr); |
| 279 | |
| 280 | typedef int (*policy_reporter_start)(struct xccdf_rule *, void *); |
| 281 | |
| 282 | /** |
| 283 | * Function to register start callback for checking system that will be called BEFORE each rule evaluation. |
| 284 | * @param model XCCDF Policy Model |
| 285 | * @param func Callback - pointer to function called by XCCDF Policy system when rule parsed |
| 286 | * @param usr optional parameter for passing user data to callback |
| 287 | * @memberof xccdf_policy_model |
| 288 | * @return true if callback registered succesfully, false otherwise |
| 289 | */ |
| 290 | OSCAP_API bool xccdf_policy_model_register_start_callback(struct xccdf_policy_model * model, policy_reporter_start func, void * usr); |
| 291 | |
| 292 | typedef int (*policy_reporter_multicheck)(struct oval_definition*, void *); |
| 293 | /** |
| 294 | * Function to register callback for checking system that will be called |
| 295 | * DURING each rule evaluation if rule sets multi-check="true". |
| 296 | * @param model XCCDF Policy Model |
| 297 | * @param func Callback - pointer to function called by XCCDF Policy system when rule parsed |
| 298 | * @param usr optional parameter for passing user data to callback |
| 299 | * @memberof xccdf_policy_model |
| 300 | * @return true if callback registered successfully, false otherwise |
| 301 | */ |
| 302 | OSCAP_API bool xccdf_policy_model_register_multicheck_callback(struct xccdf_policy_model *model, policy_reporter_multicheck func, void *usr); |
| 303 | |
| 304 | /************************************************************/ |
| 305 | /** |
| 306 | * @name Getters |
| 307 | * Return value is pointer to structure's member. Do not free unless you null the pointer in the structure. |
| 308 | * Use remove function otherwise. |
| 309 | * @{ |
| 310 | * */ |
| 311 | |
| 312 | /** |
| 313 | * Get model from Policy (parent structure of Policy to access the benchmark) |
| 314 | * @param policy XCCDF Policy |
| 315 | * @return Policy model |
| 316 | * @memberof xccdf_policy |
| 317 | */ |
| 318 | OSCAP_API struct xccdf_policy_model * xccdf_policy_get_model(const struct xccdf_policy * policy); |
| 319 | |
| 320 | /** |
| 321 | * Get Benchmark from Policy Model |
| 322 | * @param item Policy model structure |
| 323 | * @return XCCDF Benchmark for given policy model |
| 324 | * @memberof xccdf_policy_model |
| 325 | */ |
| 326 | OSCAP_API struct xccdf_benchmark * xccdf_policy_model_get_benchmark(const struct xccdf_policy_model * item); |
| 327 | |
| 328 | /** |
| 329 | * Get Value Bindings from XCCDF Policy |
| 330 | * @memberof xccdf_policy |
| 331 | */ |
| 332 | OSCAP_API struct xccdf_value_binding_iterator * xccdf_policy_get_values(const struct xccdf_policy * item); |
| 333 | |
| 334 | /** |
| 335 | * Get policies from Policy Model. Be aware, this function returns only a list of previously |
| 336 | * initialized policies. A policy can be initialized by xccdf_policy_model_get_policy_by_id. |
| 337 | * @param model Policy Model |
| 338 | * @return Iterator for list of policies |
| 339 | * @memberof xccdf_policy_model |
| 340 | */ |
| 341 | OSCAP_API struct xccdf_policy_iterator * xccdf_policy_model_get_policies(const struct xccdf_policy_model *model); |
| 342 | |
| 343 | /** |
| 344 | * Build all policies that can be useful for user. The useful policy is any |
| 345 | * that contains at least one Rule. For example the default profile oftentimes |
| 346 | * does not contain any rules. |
| 347 | * @memberof xccdf_policy_model |
| 348 | * @param policy_model - XCCDF Policy Model |
| 349 | * @return 0 on success |
| 350 | */ |
| 351 | OSCAP_API int xccdf_policy_model_build_all_useful_policies(struct xccdf_policy_model *policy_model); |
| 352 | |
| 353 | /** |
| 354 | * Get selected rules from policy |
| 355 | * @memberof xccdf_policy |
| 356 | * @return Pointer to select iterator. |
| 357 | * @retval NULL on faliure |
| 358 | */ |
| 359 | OSCAP_API struct xccdf_select_iterator * xccdf_policy_get_selected_rules(struct xccdf_policy *); |
| 360 | |
| 361 | /** |
| 362 | * Get XCCDF Profile from Policy |
| 363 | * @memberof xccdf_policy |
| 364 | * @return XCCDF Profile |
| 365 | */ |
| 366 | OSCAP_API struct xccdf_profile * xccdf_policy_get_profile(const struct xccdf_policy *); |
| 367 | |
| 368 | /** |
| 369 | * Get rules from Policy |
| 370 | * @memberof xccdf_policy |
| 371 | * @return xccdf_select_iterator |
| 372 | */ |
| 373 | OSCAP_API struct xccdf_select_iterator * xccdf_policy_get_selects(const struct xccdf_policy *); |
| 374 | |
| 375 | /** |
| 376 | * Get variable name from value bindings |
| 377 | * @memberof xccdf_value_binding |
| 378 | * @return String |
| 379 | */ |
| 380 | OSCAP_API char * xccdf_value_binding_get_name(const struct xccdf_value_binding *); |
| 381 | |
| 382 | /** |
| 383 | * Get value from value bindings |
| 384 | * @memberof xccdf_value_binding |
| 385 | * @return String |
| 386 | */ |
| 387 | OSCAP_API char * xccdf_value_binding_get_value(const struct xccdf_value_binding *); |
| 388 | |
| 389 | /** |
| 390 | * get variable type from value bindings |
| 391 | * @memberof xccdf_value_binding |
| 392 | * @return xccdf_value_type_t |
| 393 | */ |
| 394 | OSCAP_API xccdf_value_type_t xccdf_value_binding_get_type(const struct xccdf_value_binding *); |
| 395 | |
| 396 | /** |
| 397 | * get Value operator from value bindings |
| 398 | * @memberof xccdf_value_binding |
| 399 | * @return xccdf_operator_t |
| 400 | */ |
| 401 | OSCAP_API xccdf_operator_t xccdf_value_binding_get_operator(const struct xccdf_value_binding *); |
| 402 | |
| 403 | /** |
| 404 | * get Set Value from value bindings |
| 405 | * @memberof xccdf_value_binding |
| 406 | * @return String |
| 407 | */ |
| 408 | OSCAP_API char * xccdf_value_binding_get_setvalue(const struct xccdf_value_binding *); |
| 409 | |
| 410 | /** |
| 411 | * Get results of all XCCDF Policy results |
| 412 | * @memberof xccdf_policy_model |
| 413 | */ |
| 414 | OSCAP_API struct xccdf_result_iterator * xccdf_policy_get_results(const struct xccdf_policy * policy); |
| 415 | |
| 416 | /** |
| 417 | * Get XCCDF Result structure by it's idetificator if there is one |
| 418 | * @memberof xccdf_policy_model |
| 419 | * @return structure xccdf_result if found, NULL otherwise |
| 420 | */ |
| 421 | OSCAP_API struct xccdf_result * xccdf_policy_get_result_by_id(struct xccdf_policy * policy, const char * id); |
| 422 | |
| 423 | /** |
| 424 | * Get ID of XCCDF Profile that is implemented by XCCDF Policy |
| 425 | * @param policy XCCDF Policy |
| 426 | * @memberof xccdf_policy |
| 427 | * @return ID of Policy's Profile |
| 428 | */ |
| 429 | OSCAP_API const char * xccdf_policy_get_id(struct xccdf_policy * policy); |
| 430 | |
| 431 | /** |
| 432 | * Get XCCDF Policy from Policy model by speciefied ID of Profile |
| 433 | * @param policy_model XCCDF Policy model |
| 434 | * @param id ID of Profile |
| 435 | * @memberof xccdf_policy_model |
| 436 | * @return XCCDF Policy |
| 437 | */ |
| 438 | OSCAP_API struct xccdf_policy * xccdf_policy_model_get_policy_by_id(struct xccdf_policy_model * policy_model, const char * id); |
| 439 | |
| 440 | /************************************************************/ |
| 441 | /** @} End of Getters group */ |
| 442 | |
| 443 | /************************************************************/ |
| 444 | /** |
| 445 | * @name Setters |
| 446 | * For lists use add functions. Parameters of set functions are duplicated in memory and need to |
| 447 | * be freed by caller. |
| 448 | * @{ |
| 449 | */ |
| 450 | |
| 451 | /** |
| 452 | * Add Policy to Policy Model |
| 453 | * @memberof xccdf_policy_model |
| 454 | * @return true if policy has been added succesfully |
| 455 | */ |
| 456 | OSCAP_API bool xccdf_policy_model_add_policy(struct xccdf_policy_model *, struct xccdf_policy *); |
| 457 | |
| 458 | /** |
| 459 | * Add rule to Policy |
| 460 | * @memberof xccdf_policy |
| 461 | * @return true if rule has been added succesfully |
| 462 | */ |
| 463 | OSCAP_API bool xccdf_policy_add_select(struct xccdf_policy *, struct xccdf_select *); |
| 464 | |
| 465 | /** |
| 466 | * Add result to XCCDF Policy Model |
| 467 | * @memberof xccdf_policy_model |
| 468 | */ |
| 469 | OSCAP_API bool xccdf_policy_add_result(struct xccdf_policy * policy, struct xccdf_result * item); |
| 470 | |
| 471 | /** |
| 472 | * Add value binding to the Policy structure |
| 473 | * @memberof xccdf_policy |
| 474 | * @return true if rule has been added succesfully |
| 475 | */ |
| 476 | OSCAP_API bool xccdf_policy_add_value(struct xccdf_policy *, struct xccdf_value_binding *); |
| 477 | |
| 478 | /** |
| 479 | * Get the selection settings of the item. |
| 480 | * @memberof xccdf_policy |
| 481 | * @return true if the item is selected |
| 482 | */ |
| 483 | OSCAP_API bool xccdf_policy_is_item_selected(struct xccdf_policy *policy, const char *id); |
| 484 | |
| 485 | /** |
| 486 | * Retrieves number of selected items in the policy |
| 487 | * @note This is meant to be used to estimate scanning progress for example. |
| 488 | */ |
| 489 | OSCAP_API int xccdf_policy_get_selected_rules_count(struct xccdf_policy *policy); |
| 490 | |
| 491 | /** |
| 492 | * Get select from policy by specified ID of XCCDF Item |
| 493 | * @memberof xccdf_policy |
| 494 | * @return XCCDF Select |
| 495 | */ |
| 496 | OSCAP_API struct xccdf_select * xccdf_policy_get_select_by_id(struct xccdf_policy * policy, const char *item_id); |
| 497 | |
| 498 | /************************************************************/ |
| 499 | /** @} End of Setters group */ |
| 500 | |
| 501 | /************************************************************/ |
| 502 | /** |
| 503 | * @name Evaluators |
| 504 | * @{ |
| 505 | * */ |
| 506 | |
| 507 | /** |
| 508 | * Call the checking engine for each selected rule in given policy structure |
| 509 | * @param policy given Policy to evaluate |
| 510 | * @memberof xccdf_policy |
| 511 | * @return true if evaluation pass or false in case of error |
| 512 | * \par Example |
| 513 | * Before each policy evaluation user has to register callback that will be called for each check. |
| 514 | * Every checking engine must have registered callback or the particular check will be skipped. |
| 515 | * In the code below is used the predefined function \ref oval_agent_eval_rule for evaluation OVAL checks: |
| 516 | * \code |
| 517 | * xccdf_policy_model_register_engine_oval(policy_mode, agent_session) |
| 518 | * \endcode |
| 519 | * \par |
| 520 | * If you use this predefined OVAL callback, user data structure (last parameter of register function) \b MUST be of type \ref\a oval_agent_session_t: |
| 521 | * \code |
| 522 | OSCAP_API * struct oval_agent_session * sess = oval_agent_new_session((struct oval_definition_model *) model, "name-of-file"); |
| 523 | * \endcode |
| 524 | * */ |
| 525 | OSCAP_API struct xccdf_result * xccdf_policy_evaluate(struct xccdf_policy * policy); |
| 526 | |
| 527 | /** |
| 528 | * Resolve benchmark by applying all refine_rules and refine_values to rules / values |
| 529 | * of benchmark. All properties in benchmark will be irreversible changed and user has to |
| 530 | * load benchmark (from XML) again to discard these changes. |
| 531 | * @param policy XCCDF policy containing rules/values that will be applied to benchmark rules/values. |
| 532 | * @return true if process ends succesfuly or false in case of error |
| 533 | * @memberof xccdf_policy |
| 534 | */ |
| 535 | OSCAP_API bool xccdf_policy_resolve(struct xccdf_policy * policy); |
| 536 | |
| 537 | /** |
| 538 | * Generate remediation prescription (presumably a remediation script). |
| 539 | * @memberof xccdf_policy |
| 540 | * @param policy XCCDF Policy |
| 541 | * @param result XCCDF TestResult. This may be omitted to generate the prescription |
| 542 | * based solely on the XCCDF Policy (xccdf:Profile). |
| 543 | * @param sys Consider only those fixes that have @system attribute equal to sys |
| 544 | * @param input_file_name file name of the input SCAP file |
| 545 | * @param tailoring input tailoring file (parsed as oscap source) |
| 546 | * @param output_fd write prescription to this file descriptor |
| 547 | * @param raw controls verbosiness of generated remediation files (if greater than zero, the function won't add commentaries and optional boilerplate instructions) |
| 548 | * @returns zero on success, non-zero indicate partial (incomplete) output. |
| 549 | */ |
| 550 | OSCAP_API int xccdf_policy_generate_fix(struct xccdf_policy *policy, struct xccdf_result *result, const char *sys, const char *input_file_name, struct oscap_source *tailoring, int output_fd, int raw); |
| 551 | |
| 552 | /** |
| 553 | * xccdf_policy_model_get_files and xccdf_item_get_files each return oscap_file_entries instead of raw strings |
| 554 | */ |
| 555 | struct oscap_file_entry; |
| 556 | |
| 557 | /// @memberof oscap_file_entry |
| 558 | OSCAP_API struct oscap_file_entry *oscap_file_entry_new(void); |
| 559 | /// @memberof oscap_file_entry |
| 560 | OSCAP_API struct oscap_file_entry *oscap_file_entry_dup(struct oscap_file_entry* file_entry); |
| 561 | /// @memberof oscap_file_entry |
| 562 | OSCAP_API void oscap_file_entry_free(struct oscap_file_entry* entry); |
| 563 | /// @memberof oscap_file_entry |
| 564 | OSCAP_API const char* oscap_file_entry_get_system(struct oscap_file_entry* entry); |
| 565 | /// @memberof oscap_file_entry |
| 566 | OSCAP_API const char* oscap_file_entry_get_file(struct oscap_file_entry* entry); |
| 567 | |
| 568 | /** @struct oscap_file_entry_iterator |
| 569 | * @see oscap_iterator |
| 570 | */ |
| 571 | struct oscap_file_entry_iterator; |
| 572 | |
| 573 | /// @memberof oscap_file_entry_iterator |
| 574 | OSCAP_API const struct oscap_file_entry *oscap_file_entry_iterator_next(struct oscap_file_entry_iterator *it); |
| 575 | /// @memberof oscap_file_entry_iterator |
| 576 | OSCAP_API bool oscap_file_entry_iterator_has_more(struct oscap_file_entry_iterator *it); |
| 577 | /// @memberof oscap_file_entry_iterator |
| 578 | OSCAP_API void oscap_file_entry_iterator_free(struct oscap_file_entry_iterator *it); |
| 579 | /// @memberof oscap_file_entry_iterator |
| 580 | OSCAP_API void oscap_file_entry_iterator_reset(struct oscap_file_entry_iterator *it); |
| 581 | |
| 582 | /** @struct oscap_file_entry_list |
| 583 | * @see oscap_list |
| 584 | */ |
| 585 | struct oscap_file_entry_list; |
| 586 | |
| 587 | /// @memberof oscap_file_entry_list |
| 588 | OSCAP_API struct oscap_file_entry_list* oscap_file_entry_list_new(void); |
| 589 | /// @memberof oscap_file_entry_list |
| 590 | OSCAP_API void oscap_file_entry_list_free(struct oscap_file_entry_list* list); |
| 591 | /// @memberof oscap_file_entry_list |
| 592 | OSCAP_API struct oscap_file_entry_iterator* oscap_file_entry_list_get_files(struct oscap_file_entry_list* list); |
| 593 | |
| 594 | /** |
| 595 | * Return names of files that are used in checks of particular rules. Every check needs this file to be |
| 596 | * evaluated properly. If this file will not be imported and bind to the XCCDF Policy system the result |
| 597 | * of rule after evaluation will be "Not checked" |
| 598 | * |
| 599 | * |
| 600 | * The resulting list should be freed with oscap_filelist_free. |
| 601 | */ |
| 602 | OSCAP_API struct oscap_file_entry_list * xccdf_policy_model_get_systems_and_files(struct xccdf_policy_model * policy_model); |
| 603 | |
| 604 | /** |
| 605 | * Return names of files that are used in checks of particular rules. Every check needs this file to be |
| 606 | * evaluated properly. If this file will not be imported and bind to the XCCDF Policy system the result |
| 607 | * of rule after evaluation will be "Not checked" |
| 608 | * |
| 609 | * The resulting list should be freed with oscap_filelist_free. |
| 610 | */ |
| 611 | OSCAP_API struct oscap_file_entry_list * xccdf_item_get_systems_and_files(struct xccdf_item * item); |
| 612 | |
| 613 | /** |
| 614 | * Return names of files that are used in checks of particular rules. Every check needs this file to be |
| 615 | * evaluated properly. If this file will not be imported and bind to the XCCDF Policy system the result |
| 616 | * of rule after evaluation will be "Not checked" |
| 617 | */ |
| 618 | OSCAP_API struct oscap_stringlist * xccdf_policy_model_get_files(struct xccdf_policy_model * policy_model); |
| 619 | |
| 620 | /** |
| 621 | * Return names of files that are used in checks of particular rules. Every check needs this file to be |
| 622 | * evaluated properly. If this file will not be imported and bind to the XCCDF Policy system the result |
| 623 | * of rule after evaluation will be "Not checked" |
| 624 | */ |
| 625 | OSCAP_API struct oscap_stringlist * xccdf_item_get_files(struct xccdf_item * item); |
| 626 | |
| 627 | /** |
| 628 | * Return result of the AND operation for two given attributes. |
| 629 | * For more details about the attributes A and B please consult 'Table 26: Possible Results for a Single Test' from NISTIR-7275r4. |
| 630 | * For more details about the AND operation please consult 'Table 12: Truth Table for AND' in the very same document. |
| 631 | */ |
| 632 | OSCAP_API xccdf_test_result_type_t xccdf_test_result_resolve_and_operation(xccdf_test_result_type_t A, xccdf_test_result_type_t B); |
| 633 | |
| 634 | /************************************************************/ |
| 635 | /** @} End of Evaluators group */ |
| 636 | |
| 637 | /************************************************************/ |
| 638 | /** |
| 639 | * @name Iterators |
| 640 | * @{ |
| 641 | * */ |
| 642 | |
| 643 | /** |
| 644 | * Return true if the list is not empty, false otherwise |
| 645 | * @memberof xccdf_policy_iterator |
| 646 | */ |
| 647 | OSCAP_API bool xccdf_policy_iterator_has_more(struct xccdf_policy_iterator *it); |
| 648 | |
| 649 | /** |
| 650 | * Return the next xccdf_policy structure from the list and increment the iterator |
| 651 | * @memberof xccdf_policy_iterator |
| 652 | */ |
| 653 | OSCAP_API struct xccdf_policy * xccdf_policy_iterator_next(struct xccdf_policy_iterator *it); |
| 654 | |
| 655 | /** |
| 656 | * Free the iterator structure (it makes no changes to the list structure) |
| 657 | * @memberof xccdf_policy_iterator |
| 658 | */ |
| 659 | OSCAP_API void xccdf_policy_iterator_free(struct xccdf_policy_iterator *it); |
| 660 | |
| 661 | /** |
| 662 | * Reset the iterator structure (it will point to the first item in the list) |
| 663 | * @memberof xccdf_policy_iterator |
| 664 | */ |
| 665 | OSCAP_API void xccdf_policy_iterator_reset(struct xccdf_policy_iterator *it); |
| 666 | |
| 667 | /** |
| 668 | * Return true if the list is not empty, false otherwise |
| 669 | * @memberof xccdf_value_binding_iterator |
| 670 | */ |
| 671 | OSCAP_API bool xccdf_value_binding_iterator_has_more(struct xccdf_value_binding_iterator *it); |
| 672 | |
| 673 | /** |
| 674 | * Return the next xccdf_value_binding structure from the list and increment the iterator |
| 675 | * @memberof xccdf_value_binding_iterator |
| 676 | */ |
| 677 | OSCAP_API struct xccdf_value_binding * xccdf_value_binding_iterator_next(struct xccdf_value_binding_iterator *it); |
| 678 | |
| 679 | /** |
| 680 | * Free the iterator structure (it makes no changes to the list structure) |
| 681 | * @memberof xccdf_value_binding_iterator |
| 682 | */ |
| 683 | OSCAP_API void xccdf_value_binding_iterator_free(struct xccdf_value_binding_iterator *it); |
| 684 | |
| 685 | /** |
| 686 | * Reset the iterator structure (it will point to the first item in the list) |
| 687 | * @memberof xccdf_value_binding_iterator |
| 688 | */ |
| 689 | OSCAP_API void xccdf_value_binding_iterator_reset(struct xccdf_value_binding_iterator *it); |
| 690 | |
| 691 | /** |
| 692 | * Get score of the XCCDF Benchmark |
| 693 | * @param policy XCCDF Policy |
| 694 | * @param test_result Test Result model |
| 695 | * @param system Score system |
| 696 | * @return XCCDF Score |
| 697 | */ |
| 698 | OSCAP_API struct xccdf_score * xccdf_policy_get_score(struct xccdf_policy * policy, struct xccdf_result * test_result, const char * system); |
| 699 | |
| 700 | /** |
| 701 | * Recalculate score of the XCCDF Benchmark |
| 702 | * @param policy XCCDF Policy |
| 703 | * @param test_result Test Result model |
| 704 | * @returns zero on success |
| 705 | */ |
| 706 | OSCAP_API int xccdf_policy_recalculate_score(struct xccdf_policy * policy, struct xccdf_result * test_result); |
| 707 | |
| 708 | /** |
| 709 | * Get value of given value item in context of given policy |
| 710 | * @memberof xccdf_policy |
| 711 | * @param policy XCCDF policy |
| 712 | * @param item the xccdf:Value to resolve |
| 713 | * @returns string representation of resolved value_instance. |
| 714 | * @retval NULL indicates failure |
| 715 | */ |
| 716 | OSCAP_API const char *xccdf_policy_get_value_of_item(struct xccdf_policy * policy, struct xccdf_item * item); |
| 717 | |
| 718 | /** |
| 719 | * Perform textual substitution of cdf:sub elements with respect to given XCCDF policy. |
| 720 | * @param text text to be substituted |
| 721 | * @param policy policy to be used |
| 722 | */ |
| 723 | OSCAP_API char* xccdf_policy_substitute(const char *text, struct xccdf_policy *policy); |
| 724 | |
| 725 | /************************************************************/ |
| 726 | /** @} End of Iterators group */ |
| 727 | |
| 728 | /** |
| 729 | * @} |
| 730 | */ |
| 731 | #endif |
| 732 | |
| 733 |