| 1 | /* |
| 2 | * Copyright 2023 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 | * Evgenii Kolesnikov <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 24 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 25 | #endif |
| 26 | |
| 27 | #include <limits.h> |
| 28 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 29 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 30 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 31 | #include "oval_dbus.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/oval_dbus.h`/ |
| 32 | |
| 33 | |
| 34 | char *oval_dbus_value_to_stringcxx . . $ oval_dbus_value_to_string(c8641a873d86c3b).(DBusMessageItercxx . . $ DBusMessageIter# *iter) |
| 35 | { |
| 36 | const int arg_type = dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(iter); |
| 37 | if (dbus_type_is_basiccxx . . $ dbus_type_is_basic(46cc46841198e427).(arg_type)) { |
| 38 | _DBusBasicValuecxx . . $ _DBusBasicValue# value; |
| 39 | dbus_message_iter_get_basiccxx . . $ dbus_message_iter_get_basic(5a06ffdfd9031a8).(iter, &value); |
| 40 | |
| 41 | switch (arg_type) |
| 42 | { |
| 43 | case DBUS_TYPE_BYTEcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:68:9`!: |
| 44 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%c", value.bytcxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#byt.); |
| 45 | |
| 46 | case DBUS_TYPE_BOOLEANcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:72:9`!: |
| 47 | return oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(value.bool_valcxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#bool_val. ? "true" : "false"); |
| 48 | |
| 49 | case DBUS_TYPE_INT16cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:76:9`!: |
| 50 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%i", value.i16cxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#i16.); |
| 51 | |
| 52 | case DBUS_TYPE_UINT16cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:80:9`!: |
| 53 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%u", value.u16cxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#u16.); |
| 54 | |
| 55 | case DBUS_TYPE_INT32cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:84:9`!: |
| 56 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%i", value.i32cxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#i32.); |
| 57 | |
| 58 | case DBUS_TYPE_UINT32cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:88:9`!: |
| 59 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%u", value.u32cxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#u32.); |
| 60 | |
| 61 | #ifdef DBUS_HAVE_INT64cxx . . $ `<external>/14376914409977772024/dbus-arch-deps.h:36:9`! |
| 62 | case DBUS_TYPE_INT64cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:92:9`!: |
| 63 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%li", value.i64cxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#i64.); |
| 64 | |
| 65 | case DBUS_TYPE_UINT64cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:96:9`!: |
| 66 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%lu", value.u64cxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#u64.); |
| 67 | #endif |
| 68 | |
| 69 | case DBUS_TYPE_DOUBLEcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:100:9`!: |
| 70 | return oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%g", value.dblcxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#dbl.); |
| 71 | |
| 72 | case DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!: |
| 73 | case DBUS_TYPE_OBJECT_PATHcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:108:9`!: |
| 74 | case DBUS_TYPE_SIGNATUREcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:112:9`!: |
| 75 | return oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(value.strcxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#str.); |
| 76 | |
| 77 | // We skip non-basic types for now |
| 78 | //case DBUS_TYPE_ARRAY: |
| 79 | //case DBUS_TYPE_STRUCT: |
| 80 | //case DBUS_TYPE_DICT_ENTRY: |
| 81 | //case DBUS_TYPE_VARIANT: |
| 82 | //case DBUS_TYPE_UNIX_FD: |
| 83 | // return oscap_sprintf("%i", value.fd); |
| 84 | |
| 85 | default: |
| 86 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Encountered unknown D-Bus basic type: %d!", arg_type); |
| 87 | return oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).("error, unknown basic type!"); |
| 88 | } |
| 89 | } else if (arg_type == DBUS_TYPE_ARRAYcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:122:9`!) { |
| 90 | DBusMessageItercxx . . $ DBusMessageIter# array; |
| 91 | dbus_message_iter_recursecxx . . $ dbus_message_iter_recurse(6e42dd501f62eaf0).(iter, &array); |
| 92 | |
| 93 | char *ret = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 94 | do { |
| 95 | char *element = oval_dbus_value_to_stringcxx . . $ oval_dbus_value_to_string(c8641a873d86c3b).(&array); |
| 96 | |
| 97 | if (element == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 98 | continue; |
| 99 | |
| 100 | char *old_ret = ret; |
| 101 | if (old_ret == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 102 | ret = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s", element); |
| 103 | else |
| 104 | ret = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s, %s", old_ret, element); |
| 105 | |
| 106 | freecxx . . $ free(5d22bdacc48458e8).(old_ret); |
| 107 | freecxx . . $ free(5d22bdacc48458e8).(element); |
| 108 | } |
| 109 | while (dbus_message_iter_nextcxx . . $ dbus_message_iter_next(e45094e8c4b79815).(&array)); |
| 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 115 | } |
| 116 | |
| 117 | DBusConnectioncxx . . $ DBusConnection# *oval_connect_dbuscxx . . $ oval_connect_dbus(f89cc4e9350282f7).(void) |
| 118 | { |
| 119 | DBusConnectioncxx . . $ DBusConnection# *conn = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 120 | |
| 121 | DBusErrorcxx . . $ DBusError# err; |
| 122 | dbus_error_initcxx . . $ dbus_error_init(b79b632916b634d5).(&err); |
| 123 | |
| 124 | const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT"); |
| 125 | if (prefix != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 126 | char dbus_address[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!] = {0}; |
| 127 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(dbus_address, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "unix:path=%s/run/dbus/system_bus_socket", prefix); |
| 128 | setenvcxx . . $ setenv(f0be30763a490cce).("DBUS_SYSTEM_BUS_ADDRESS", dbus_address, 0); |
| 129 | /* We won't overwrite DBUS_SYSTEM_BUS_ADDRESS so that |
| 130 | * user could have a way to define some non-standard system bus socket location */ |
| 131 | } |
| 132 | |
| 133 | conn = dbus_bus_getcxx . . $ dbus_bus_get(55765b610750c92d).(DBUS_BUS_SYSTEMcxx . . $ DBUS_BUS_SYSTEM., &err); |
| 134 | if (dbus_error_is_setcxx . . $ dbus_error_is_set(bfe7bc821936b44).(&err)) { |
| 135 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to get DBUS_BUS_SYSTEM connection - %s", err.message); |
| 136 | goto cleanup; |
| 137 | } |
| 138 | if (conn == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 139 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("DBusConnection == NULL!"); |
| 140 | goto cleanup; |
| 141 | } |
| 142 | |
| 143 | dbus_bus_registercxx . . $ dbus_bus_register(56a1e6f40a4832a8).(conn, &err); |
| 144 | if (dbus_error_is_setcxx . . $ dbus_error_is_set(bfe7bc821936b44).(&err)) { |
| 145 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to register on dbus - %s", err.message); |
| 146 | goto cleanup; |
| 147 | } |
| 148 | |
| 149 | cleanup: |
| 150 | dbus_error_freecxx . . $ dbus_error_free(b79b632916b634d5).(&err); |
| 151 | |
| 152 | return conn; |
| 153 | } |
| 154 | |
| 155 | void oval_disconnect_dbuscxx . . $ oval_disconnect_dbus(5ffe6e60e141c747).(DBusConnectioncxx . . $ DBusConnection# *conn) |
| 156 | { |
| 157 | // NOOP |
| 158 | |
| 159 | // Connections retrieved via dbus_bus_get shall not be destroyed, |
| 160 | // these connections are shared. |
| 161 | } |