| 1 | /* |
| 2 | * Copyright 2012 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 | * Authors: |
| 20 | * "Martin Preisler" <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #ifndef SCE_ENGINE_API_H_ |
| 26 | #define SCE_ENGINE_API_H_ |
| 27 | |
| 28 | #include <xccdf_benchmark.h> |
| 29 | #include <xccdf_policy.h> |
| 30 | #include "oscap_export.h" |
| 31 | |
| 32 | /** |
| 33 | * @memberof sce_check_result |
| 34 | */ |
| 35 | OSCAP_API struct sce_check_result* sce_check_result_new(void); |
| 36 | |
| 37 | /** |
| 38 | * @memberof sce_check_result |
| 39 | */ |
| 40 | OSCAP_API void sce_check_result_free(struct sce_check_result* v); |
| 41 | |
| 42 | /** |
| 43 | * Sets the href used to execute the check that yielded given check result |
| 44 | * |
| 45 | * @memberof sce_check_result |
| 46 | */ |
| 47 | OSCAP_API void sce_check_result_set_href(struct sce_check_result* v, const char* href); |
| 48 | |
| 49 | /** |
| 50 | * @memberof sce_check_result |
| 51 | */ |
| 52 | OSCAP_API const char* sce_check_result_get_href(struct sce_check_result* v); |
| 53 | |
| 54 | /** |
| 55 | * Sets basename of the script that was used for check evaluation |
| 56 | * |
| 57 | * @memberof sce_check_result |
| 58 | */ |
| 59 | OSCAP_API void sce_check_result_set_basename(struct sce_check_result* v, const char* basename); |
| 60 | |
| 61 | /** |
| 62 | * @memberof sce_check_result |
| 63 | */ |
| 64 | OSCAP_API const char* sce_check_result_get_basename(struct sce_check_result* v); |
| 65 | |
| 66 | /** |
| 67 | * Sets stdout that was captured while script was evaluating |
| 68 | * |
| 69 | * @param stdout should contain output only from stdout |
| 70 | * @memberof sce_check_result |
| 71 | */ |
| 72 | OSCAP_API void sce_check_result_set_stdout(struct sce_check_result* v, const char* details); |
| 73 | |
| 74 | /** |
| 75 | * @memberof sce_check_result |
| 76 | */ |
| 77 | OSCAP_API const char* sce_check_result_get_stdout(struct sce_check_result* v); |
| 78 | |
| 79 | /** |
| 80 | * Sets stderr that was captured while script was evaluating |
| 81 | * |
| 82 | * @param stderr should contain output only from stderr |
| 83 | * @memberof sce_check_result |
| 84 | */ |
| 85 | OSCAP_API void sce_check_result_set_stderr(struct sce_check_result* v, const char* details); |
| 86 | |
| 87 | /** |
| 88 | * @memberof sce_check_result |
| 89 | */ |
| 90 | OSCAP_API const char* sce_check_result_get_stderr(struct sce_check_result* v); |
| 91 | |
| 92 | /** |
| 93 | * Sets exit code with which the script ended execution after evaluation |
| 94 | * @memberof sce_check_result |
| 95 | */ |
| 96 | OSCAP_API void sce_check_result_set_exit_code(struct sce_check_result* v, int exit_code); |
| 97 | |
| 98 | /** |
| 99 | * @memberof sce_check_result |
| 100 | */ |
| 101 | OSCAP_API int sce_check_result_get_exit_code(struct sce_check_result* v); |
| 102 | |
| 103 | /** |
| 104 | * Clears the list of passed environment variables |
| 105 | * |
| 106 | * @memberof sce_check_result |
| 107 | */ |
| 108 | OSCAP_API void sce_check_result_reset_environment_variables(struct sce_check_result* v); |
| 109 | |
| 110 | /** |
| 111 | * Adds an environment variable entry to list of environment variables that |
| 112 | * were passed to the script. These include XCCDF result codes, |
| 113 | * bound XCCDF variables and possibly more. |
| 114 | * |
| 115 | * sce_check_result contains these mostly for debugging purposes. |
| 116 | * |
| 117 | * @param var entry that will be added, in "VARIABLE_NAME=VARIABLE_VALUE" form |
| 118 | * @memberof sce_check_result |
| 119 | */ |
| 120 | OSCAP_API void sce_check_result_add_environment_variable(struct sce_check_result* v, const char* var); |
| 121 | |
| 122 | /** |
| 123 | * Sets the final xccdf result (after exit code to xccdf mapping takes place) |
| 124 | * |
| 125 | * @memberof sce_check_result |
| 126 | */ |
| 127 | OSCAP_API void sce_check_result_set_xccdf_result(struct sce_check_result* v, xccdf_test_result_type_t result); |
| 128 | |
| 129 | /** |
| 130 | * @memberof sce_check_result |
| 131 | */ |
| 132 | OSCAP_API xccdf_test_result_type_t sce_check_result_get_xccdf_result(struct sce_check_result* v); |
| 133 | |
| 134 | /** |
| 135 | * Exports details (in XML form) of given check result to given file |
| 136 | * |
| 137 | * @memberof sce_check_result |
| 138 | */ |
| 139 | OSCAP_API void sce_check_result_export(struct sce_check_result* v, const char* target_file); |
| 140 | |
| 141 | /** |
| 142 | * @memberof sce_session |
| 143 | */ |
| 144 | OSCAP_API struct sce_session* sce_session_new(void); |
| 145 | |
| 146 | /** |
| 147 | * @memberof sce_session |
| 148 | */ |
| 149 | OSCAP_API void sce_session_free(struct sce_session* s); |
| 150 | |
| 151 | /** |
| 152 | * Removes all check results from the session |
| 153 | * |
| 154 | * @memberof sce_session |
| 155 | */ |
| 156 | OSCAP_API void sce_session_reset(struct sce_session* s); |
| 157 | |
| 158 | /** |
| 159 | * Adds a check result to the session |
| 160 | * |
| 161 | * @param s session to add the check result to |
| 162 | * @param result result to be added (the session takes ownership of it, don't deallocate it!) |
| 163 | * @memberof sce_session |
| 164 | */ |
| 165 | OSCAP_API void sce_session_add_check_result(struct sce_session* s, struct sce_check_result* result); |
| 166 | |
| 167 | /** |
| 168 | * @struct sce_check_result_iterator |
| 169 | * Iterator over collections of sce_check_results. |
| 170 | * @see sce_check_result_iterator |
| 171 | */ |
| 172 | struct sce_check_result_iterator; |
| 173 | OSCAP_API struct sce_check_result *sce_check_result_iterator_next(struct sce_check_result_iterator *it); |
| 174 | /// @memberof sce_check_result_iterator |
| 175 | OSCAP_API bool sce_check_result_iterator_has_more(struct sce_check_result_iterator *it); |
| 176 | /// @memberof sce_check_result_iterator |
| 177 | OSCAP_API void sce_check_result_iterator_free(struct sce_check_result_iterator *it); |
| 178 | /// @memberof sce_check_result_iterator |
| 179 | OSCAP_API void sce_check_result_iterator_reset(struct sce_check_result_iterator *it); |
| 180 | |
| 181 | OSCAP_API struct sce_check_result_iterator *sce_session_get_check_results(struct sce_session* s); |
| 182 | |
| 183 | /** |
| 184 | * Exports all check results to given directory |
| 185 | * |
| 186 | * @memberof sce_session |
| 187 | */ |
| 188 | OSCAP_API void sce_session_export_to_directory(struct sce_session* s, const char* directory); |
| 189 | |
| 190 | /** |
| 191 | * @memberof sce_parameters |
| 192 | */ |
| 193 | OSCAP_API struct sce_parameters* sce_parameters_new(void); |
| 194 | |
| 195 | /** |
| 196 | * @memberof sce_parameters |
| 197 | */ |
| 198 | OSCAP_API void sce_parameters_free(struct sce_parameters* v); |
| 199 | |
| 200 | /** |
| 201 | * Sets the directory that contains XCCDF that will reference SCE checks |
| 202 | * |
| 203 | * @internal This is used to figure out where to look for the scripts |
| 204 | * @memberof sce_parameters |
| 205 | */ |
| 206 | OSCAP_API void sce_parameters_set_xccdf_directory(struct sce_parameters* v, const char* value); |
| 207 | |
| 208 | /** |
| 209 | * @memberof sce_parameters |
| 210 | */ |
| 211 | OSCAP_API const char* sce_parameters_get_xccdf_directory(struct sce_parameters* v); |
| 212 | |
| 213 | /** |
| 214 | * Sets SCE session to use for check results storage |
| 215 | * |
| 216 | * @param v |
| 217 | * @param value SCE session to use (sce_parameters take ownership of it, don't deallocate it!) |
| 218 | * @memberof sce_parameters |
| 219 | */ |
| 220 | OSCAP_API void sce_parameters_set_session(struct sce_parameters* v, struct sce_session* value); |
| 221 | |
| 222 | /** |
| 223 | * @memberof sce_parameters |
| 224 | */ |
| 225 | OSCAP_API struct sce_session* sce_parameters_get_session(struct sce_parameters* v); |
| 226 | |
| 227 | /** |
| 228 | * Just a convenience shortcut of setting a session to a newly allocated session |
| 229 | * |
| 230 | * The session gets automatically freed when sce_parameters are freed, don't deallocate it! |
| 231 | * @memberof sce_parameters |
| 232 | */ |
| 233 | OSCAP_API void sce_parameters_allocate_session(struct sce_parameters* v); |
| 234 | |
| 235 | /** |
| 236 | * Internal rule evaluation callback, don't use directly |
| 237 | * |
| 238 | * @see xccdf_policy_model_register_engine_sce |
| 239 | */ |
| 240 | xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const char *rule_id, const char *id, const char *href, |
| 241 | struct xccdf_value_binding_iterator *value_binding_it, |
| 242 | struct xccdf_check_import_iterator *check_import_it, |
| 243 | void *usr); |
| 244 | |
| 245 | /** |
| 246 | * Registers SCE to given policy model |
| 247 | * |
| 248 | * @param model model to register SCE to |
| 249 | * @param sce_parameters various parameters to be used with SCE (you are responsible to deallocate them!) |
| 250 | */ |
| 251 | OSCAP_API bool xccdf_policy_model_register_engine_sce(struct xccdf_policy_model * model, struct sce_parameters *sce_parameters); |
| 252 | |
| 253 | #endif |