| 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 | * Authors: |
| 20 | * Lukas Kuklinek <[email protected]> |
| 21 | * Peter Vrabec <[email protected]> |
| 22 | */ |
| 23 | |
| 24 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 25 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 26 | #endif |
| 27 | |
| 28 | #include <libxml/parser.h> |
| 29 | #include <libxml/xmlschemas.h> |
| 30 | #include <libxslt/xslt.h> |
| 31 | #include <libxslt/xsltInternals.h> |
| 32 | #include <libxslt/transform.h> |
| 33 | #include <libxslt/xsltutils.h> |
| 34 | #include <libexslt/exslt.h> |
| 35 | #include <string.h> |
| 36 | #ifndef OS_WINDOWS |
| 37 | #include <unistd.h> |
| 38 | #else |
| 39 | #include <io.h> |
| 40 | #include <windows.h> |
| 41 | #endif |
| 42 | #include <fcntl.h> |
| 43 | |
| 44 | #include "public/oscap.h"cxx . . $ `<file>/src/common/public/oscap.h`/ |
| 45 | #include "_error.h"cxx . . $ `<file>/src/common/_error.h`/ |
| 46 | #include "util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 47 | #include "list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 48 | #include "elements.h"cxx . . $ `<file>/src/common/elements.h`/ |
| 49 | #include "debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 50 | #include "oscap_source.h"cxx . . $ `<file>/src/source/public/oscap_source.h`/ |
| 51 | #include "oscapxml.h"cxx . . $ `<file>/src/common/oscapxml.h`/ |
| 52 | #include "source/schematron_priv.h"cxx . . $ `<file>/src/source/schematron_priv.h`/ |
| 53 | #include "source/validate_priv.h"cxx . . $ `<file>/src/source/validate_priv.h`/ |
| 54 | #include "source/xslt_priv.h"cxx . . $ `<file>/src/source/xslt_priv.h`/ |
| 55 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 56 | |
| 57 | const char *const OSCAP_SCHEMA_PATHcxx . . $ OSCAP_SCHEMA_PATH. = OSCAP_DEFAULT_SCHEMA_PATHcxx . . $ `build/config.h:27:9`!; |
| 58 | const char *const OSCAP_XSLT_PATHcxx . . $ OSCAP_XSLT_PATH. = OSCAP_DEFAULT_XSLT_PATHcxx . . $ `build/config.h:28:9`!; |
| 59 | const char *const OSCAP_CPE_PATHcxx . . $ OSCAP_CPE_PATH. = OSCAP_DEFAULT_CPE_PATHcxx . . $ `build/config.h:29:9`!; |
| 60 | |
| 61 | #ifdef OS_WINDOWS |
| 62 | static const char *_get_default_path(const char *defpath) |
| 63 | { |
| 64 | /* On Windows, default paths are directory names of directories that are |
| 65 | * located in the same directory as oscap.exe. We will make a full path |
| 66 | * based on oscap.exe location. |
| 67 | */ |
| 68 | char oscap_path[PATH_MAX]; |
| 69 | GetModuleFileName(NULL, oscap_path, PATH_MAX); |
| 70 | char *oscap_path_dirname = oscap_dirname(oscap_path); |
| 71 | const char *path = oscap_sprintf("%s\\%s", oscap_path_dirname, defpath); |
| 72 | free(oscap_path_dirname); |
| 73 | return path; |
| 74 | } |
| 75 | #else |
| 76 | static const char *_get_default_pathcxx . . $ _get_default_path(fb58d2e09a2a1ce6).(const char *defpath) |
| 77 | { |
| 78 | return defpath; |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | /* |
| 83 | * If environment variable specified by 'pathvar' is defined, returns value of this environment variable. |
| 84 | * If this environment variable is not defined, returns default path, provided by 'defpath' argument. |
| 85 | */ |
| 86 | static const char * oscap_path_tocxx . . $ oscap_path_to(1320557f0feba62c).(const char *pathvar, const char *defpath) { |
| 87 | const char *path = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 88 | |
| 89 | if (pathvar != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 90 | path = getenvcxx . . $ getenv(a8b8e32347182212).(pathvar); |
| 91 | |
| 92 | if (path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || oscap_streqcxx . . $ oscap_streq(b7a7aa4a824b7595).(path, "")) { |
| 93 | path = _get_default_pathcxx . . $ _get_default_path(fb58d2e09a2a1ce6).(defpath); |
| 94 | } |
| 95 | |
| 96 | return path; |
| 97 | } |
| 98 | |
| 99 | const char * oscap_path_to_schemascxx . . $ oscap_path_to_schemas(33a1f659e94feb42).() { |
| 100 | return oscap_path_tocxx . . $ oscap_path_to(1320557f0feba62c).("OSCAP_SCHEMA_PATH", OSCAP_SCHEMA_PATHcxx . . $ OSCAP_SCHEMA_PATH.); |
| 101 | } |
| 102 | |
| 103 | const char *oscap_path_to_xsltcxx . . $ oscap_path_to_xslt(33a1f659e94feb42).(void) |
| 104 | { |
| 105 | return oscap_path_tocxx . . $ oscap_path_to(1320557f0feba62c).("OSCAP_XSLT_PATH", OSCAP_XSLT_PATHcxx . . $ OSCAP_XSLT_PATH.); |
| 106 | } |
| 107 | |
| 108 | const char * oscap_path_to_cpecxx . . $ oscap_path_to_cpe(33a1f659e94feb42).() { |
| 109 | return oscap_path_tocxx . . $ oscap_path_to(1320557f0feba62c).("OSCAP_CPE_PATH", OSCAP_CPE_PATHcxx . . $ OSCAP_CPE_PATH.); |
| 110 | } |
| 111 | |
| 112 | void oscap_initcxx . . $ oscap_init(49f6e7a06ebc5aa8).(void) |
| 113 | { |
| 114 | xmlInitParsercxx . . $ xmlInitParser(49f6e7a06ebc5aa8).(); |
| 115 | xsltInitcxx . . $ xsltInit(49f6e7a06ebc5aa8).(); |
| 116 | exsltRegisterAllcxx . . $ exsltRegisterAll(49f6e7a06ebc5aa8).(); |
| 117 | } |
| 118 | |
| 119 | void oscap_cleanupcxx . . $ oscap_cleanup(49f6e7a06ebc5aa8).(void) |
| 120 | { |
| 121 | oscap_clearerrcxx . . $ oscap_clearerr(49f6e7a06ebc5aa8).(); |
| 122 | xsltCleanupGlobalscxx . . $ xsltCleanupGlobals(49f6e7a06ebc5aa8).(); |
| 123 | xmlCleanupParsercxx . . $ xmlCleanupParser(49f6e7a06ebc5aa8).(); |
| 124 | } |
| 125 | |
| 126 | const char *oscap_get_versioncxx . . $ oscap_get_version(33a1f659e94feb42).(void) { return OPENSCAP_VERSIONcxx . . $ `build/config.h:4:9`!; } |
| 127 | |
| 128 | int oscap_apply_xsltcxx . . $ oscap_apply_xslt(94a5cfe74efaac1c).(const char *xmlfile, const char *xsltfile, const char *outfile, const char **params) |
| 129 | { |
| 130 | struct oscap_sourcecxx . . $ oscap_source# *source = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(xmlfile); |
| 131 | int ret = oscap_source_apply_xslt_pathcxx . . $ oscap_source_apply_xslt_path(55db94cfa4db2719).(source, xsltfile, outfile, params, oscap_path_to_xsltcxx . . $ oscap_path_to_xslt(33a1f659e94feb42).()); |
| 132 | oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(source); |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | const char *oscap_document_type_to_stringcxx . . $ oscap_document_type_to_string(1cec73a42285d610).(oscap_document_type_tcxx . . $ oscap_document_type_t# type) |
| 137 | { |
| 138 | switch (type) { |
| 139 | case OSCAP_DOCUMENT_OVAL_DEFINITIONScxx . . $ OSCAP_DOCUMENT_OVAL_DEFINITIONS.: |
| 140 | return "OVAL Definition"; |
| 141 | case OSCAP_DOCUMENT_OVAL_DIRECTIVEScxx . . $ OSCAP_DOCUMENT_OVAL_DIRECTIVES.: |
| 142 | return "OVAL Directives"; |
| 143 | case OSCAP_DOCUMENT_OVAL_RESULTScxx . . $ OSCAP_DOCUMENT_OVAL_RESULTS.: |
| 144 | return "OVAL Results"; |
| 145 | case OSCAP_DOCUMENT_OVAL_SYSCHARcxx . . $ OSCAP_DOCUMENT_OVAL_SYSCHAR.: |
| 146 | return "OVAL System Characteristics"; |
| 147 | case OSCAP_DOCUMENT_OVAL_VARIABLEScxx . . $ OSCAP_DOCUMENT_OVAL_VARIABLES.: |
| 148 | return "OVAL Variables"; |
| 149 | case OSCAP_DOCUMENT_SDScxx . . $ OSCAP_DOCUMENT_SDS.: |
| 150 | return "SCAP Source Datastream"; |
| 151 | case OSCAP_DOCUMENT_XCCDFcxx . . $ OSCAP_DOCUMENT_XCCDF.: |
| 152 | return "XCCDF Checklist"; |
| 153 | case OSCAP_DOCUMENT_XCCDF_TAILORINGcxx . . $ OSCAP_DOCUMENT_XCCDF_TAILORING.: |
| 154 | return "XCCDF Tailoring"; |
| 155 | case OSCAP_DOCUMENT_SCE_RESULTcxx . . $ OSCAP_DOCUMENT_SCE_RESULT.: |
| 156 | return "SCE Results"; |
| 157 | case OSCAP_DOCUMENT_CPE_DICTIONARYcxx . . $ OSCAP_DOCUMENT_CPE_DICTIONARY.: |
| 158 | return "CPE Dictionary"; |
| 159 | case OSCAP_DOCUMENT_CPE_LANGUAGEcxx . . $ OSCAP_DOCUMENT_CPE_LANGUAGE.: |
| 160 | return "CPE Language"; |
| 161 | case OSCAP_DOCUMENT_ARFcxx . . $ OSCAP_DOCUMENT_ARF.: |
| 162 | return "ARF Result Datastream"; |
| 163 | case OSCAP_DOCUMENT_OCILcxx . . $ OSCAP_DOCUMENT_OCIL.: |
| 164 | return "OCIL Questionnaire"; |
| 165 | default: |
| 166 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 167 | } |
| 168 | } |