| 1 | /** |
| 2 | * @file module_entry.c |
| 3 | * \brief Extra Check Engines Module Entry for Script Check Engine |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright 2013 Red Hat Inc., Durham, North Carolina. |
| 8 | * All Rights Reserved. |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2.1 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with this library; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | * |
| 24 | * Authors: |
| 25 | * "Martin Preisler" <[email protected]> |
| 26 | */ |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_H |
| 29 | #include <config.h> |
| 30 | #endif |
| 31 | |
| 32 | #include "sce_engine_api.h" |
| 33 | #include "XCCDF_POLICY/public/check_engine_plugin.h" |
| 34 | |
| 35 | #include <libgen.h> |
| 36 | #include <string.h> |
| 37 | |
| 38 | static int sce_engine_register(struct xccdf_policy_model *model, const char *path_hint, void **user_data) |
| 39 | { |
| 40 | struct sce_parameters *parameters = (struct sce_parameters*) *user_data; |
| 41 | if (parameters != NULL) |
| 42 | sce_parameters_free(parameters); |
| 43 | |
| 44 | parameters = sce_parameters_new(); |
| 45 | sce_parameters_set_xccdf_directory(parameters, path_hint); |
| 46 | sce_parameters_allocate_session(parameters); |
| 47 | |
| 48 | *user_data = (void*)parameters; // This way the data will get freed later |
| 49 | |
| 50 | return !xccdf_policy_model_register_engine_sce(model, parameters); |
| 51 | } |
| 52 | |
| 53 | static int sce_engine_cleanup(struct xccdf_policy_model *model, void **user_data) |
| 54 | { |
| 55 | struct sce_parameters *parameters = (struct sce_parameters*) *user_data; |
| 56 | if (parameters != NULL) |
| 57 | sce_parameters_free(parameters); |
| 58 | |
| 59 | *user_data = NULL; |
| 60 | |
| 61 | // FIXME: Unregister SCE? |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int sce_engine_export_results(struct xccdf_policy_model *model, bool validate, const char *path_hint, void **user_data) |
| 66 | { |
| 67 | struct sce_parameters *parameters = (struct sce_parameters*) *user_data; |
| 68 | if (parameters == NULL) { |
| 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | struct sce_session *sce_session = sce_parameters_get_session(parameters); |
| 73 | if (sce_session == NULL) |
| 74 | return 1; |
| 75 | struct sce_check_result_iterator *it = sce_session_get_check_results(sce_session); |
| 76 | |
| 77 | while(sce_check_result_iterator_has_more(it)) |
| 78 | { |
| 79 | struct sce_check_result *check_result = sce_check_result_iterator_next(it); |
| 80 | char target[2 + strlen(sce_check_result_get_basename(check_result)) + 11 + 1]; |
| 81 | snprintf(target, sizeof(target), "./%s.result.xml", sce_check_result_get_basename(check_result)); |
| 82 | sce_check_result_export(check_result, target); |
| 83 | } |
| 84 | |
| 85 | sce_check_result_iterator_free(it); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static const char *sce_engine_get_capabilities(void **user_data) |
| 91 | { |
| 92 | return "SCE Version: 1.0"; |
| 93 | } |
| 94 | |
| 95 | int OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRY (struct check_engine_plugin_def *plugin); |
| 96 | |
| 97 | int OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRY (struct check_engine_plugin_def *plugin) |
| 98 | { |
| 99 | plugin->register_fn = sce_engine_register; |
| 100 | plugin->cleanup_fn = sce_engine_cleanup; |
| 101 | plugin->export_results_fn = sce_engine_export_results; |
| 102 | plugin->get_capabilities_fn = sce_engine_get_capabilities; |
| 103 | |
| 104 | return 0; |
| 105 | } |