| 1 | /** |
| 2 | * @file systemdshared.c |
| 3 | * @brief functionality shared between systemdunitproperty and systemdunitdependency tests |
| 4 | * @author |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Copyright 2014 Red Hat Inc., Durham, North Carolina. |
| 9 | * All Rights Reserved. |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2.1 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Lesser General Public |
| 22 | * License along with this library; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | * |
| 25 | * Authors: |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #pragma once |
| 30 | |
| 31 | #ifndef OPENSCAP_OVAL_PROBES_SYSTEMDSHARED_H_ |
| 32 | #define OPENSCAP_OVAL_PROBES_SYSTEMDSHARED_H_cxx . . $ `src/OVAL/probes/unix/linux/systemdshared.h:32:9`! |
| 33 | |
| 34 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 35 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 36 | #endif |
| 37 | |
| 38 | #include <libgen.h> |
| 39 | #include <stdio.h> |
| 40 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 41 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 42 | #include "oval_dbus.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/oval_dbus.h`/ |
| 43 | |
| 44 | |
| 45 | static char *get_path_by_unitcxx . . $ get_path_by_unit(9da5f9108eb37f8b).(DBusConnectioncxx . . $ DBusConnection# *conn, const char *unit) |
| 46 | { |
| 47 | DBusMessagecxx . . $ DBusMessage# *msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 48 | DBusPendingCallcxx . . $ DBusPendingCall# *pending = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 49 | _DBusBasicValuecxx . . $ _DBusBasicValue# path; |
| 50 | char *ret = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 51 | |
| 52 | msg = dbus_message_new_method_callcxx . . $ dbus_message_new_method_call(a937a8c9de1028ff).( |
| 53 | "org.freedesktop.systemd1", |
| 54 | "/org/freedesktop/systemd1", |
| 55 | "org.freedesktop.systemd1.Manager", |
| 56 | // LoadUnit is similar to GetUnit except it will load the unit file |
| 57 | // if it hasn't been loaded yet. |
| 58 | "LoadUnit" |
| 59 | ); |
| 60 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("LoadUnit: %s", unit); |
| 61 | |
| 62 | if (msg == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 63 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to create dbus_message via dbus_message_new_method_call!"); |
| 64 | goto cleanup; |
| 65 | } |
| 66 | |
| 67 | DBusMessageItercxx . . $ DBusMessageIter# args; |
| 68 | |
| 69 | dbus_message_iter_init_appendcxx . . $ dbus_message_iter_init_append(bdfd43ed78e92566).(msg, &args); |
| 70 | if (!dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&args, DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!, &unit)) { |
| 71 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to append unit '%s' string parameter to dbus message!", unit); |
| 72 | goto cleanup; |
| 73 | } |
| 74 | |
| 75 | if (!dbus_connection_send_with_replycxx . . $ dbus_connection_send_with_reply(ab3797bd4df020e).(conn, msg, &pending, -1)) { |
| 76 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to send message via dbus!"); |
| 77 | goto cleanup; |
| 78 | } |
| 79 | if (pending == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 80 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Invalid dbus pending call!"); |
| 81 | goto cleanup; |
| 82 | } |
| 83 | |
| 84 | dbus_connection_flushcxx . . $ dbus_connection_flush(5ffe6e60e141c747).(conn); |
| 85 | dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 86 | |
| 87 | dbus_pending_call_blockcxx . . $ dbus_pending_call_block(f8094f87eabead78).(pending); |
| 88 | msg = dbus_pending_call_steal_replycxx . . $ dbus_pending_call_steal_reply(5c89f41a44f43d9f).(pending); |
| 89 | if (msg == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 90 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to steal dbus pending call reply."); |
| 91 | goto cleanup; |
| 92 | } |
| 93 | dbus_pending_call_unrefcxx . . $ dbus_pending_call_unref(f8094f87eabead78).(pending); pending = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 94 | |
| 95 | if (!dbus_message_iter_initcxx . . $ dbus_message_iter_init(ffe71547a19cf1fb).(msg, &args)) { |
| 96 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to initialize iterator over received dbus message."); |
| 97 | goto cleanup; |
| 98 | } |
| 99 | |
| 100 | if (dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(&args) != DBUS_TYPE_OBJECT_PATHcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:108:9`!) { |
| 101 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Expected object path argument in reply. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args))); |
| 102 | goto cleanup; |
| 103 | } |
| 104 | |
| 105 | dbus_message_iter_get_basiccxx . . $ dbus_message_iter_get_basic(5a06ffdfd9031a8).(&args, &path); |
| 106 | ret = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(path.strcxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#str.); |
| 107 | dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 108 | |
| 109 | cleanup: |
| 110 | if (pending != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 111 | dbus_pending_call_unrefcxx . . $ dbus_pending_call_unref(f8094f87eabead78).(pending); |
| 112 | |
| 113 | if (msg != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 114 | dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); |
| 115 | |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | static int get_all_systemd_unitscxx . . $ get_all_systemd_units(cc44debc175259da).(DBusConnectioncxx . . $ DBusConnection#* conn, int(*callback)(const char *, void *), void *cbarg) |
| 120 | { |
| 121 | DBusMessagecxx . . $ DBusMessage# *msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 122 | DBusPendingCallcxx . . $ DBusPendingCall# *pending = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 123 | char ret = 1; |
| 124 | |
| 125 | msg = dbus_message_new_method_callcxx . . $ dbus_message_new_method_call(a937a8c9de1028ff).( |
| 126 | "org.freedesktop.systemd1", |
| 127 | "/org/freedesktop/systemd1", |
| 128 | "org.freedesktop.systemd1.Manager", |
| 129 | "ListUnitFiles" |
| 130 | ); |
| 131 | if (msg == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 132 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to create dbus_message via dbus_message_new_method_call!"); |
| 133 | goto cleanup; |
| 134 | } |
| 135 | |
| 136 | DBusMessageItercxx . . $ DBusMessageIter# args, unit_iter; |
| 137 | |
| 138 | // the args should be empty for this call |
| 139 | dbus_message_iter_init_appendcxx . . $ dbus_message_iter_init_append(bdfd43ed78e92566).(msg, &args); |
| 140 | |
| 141 | if (!dbus_connection_send_with_replycxx . . $ dbus_connection_send_with_reply(ab3797bd4df020e).(conn, msg, &pending, -1)) { |
| 142 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to send message via dbus!"); |
| 143 | goto cleanup; |
| 144 | } |
| 145 | if (pending == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 146 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Invalid dbus pending call!"); |
| 147 | goto cleanup; |
| 148 | } |
| 149 | |
| 150 | dbus_connection_flushcxx . . $ dbus_connection_flush(5ffe6e60e141c747).(conn); |
| 151 | dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 152 | |
| 153 | dbus_pending_call_blockcxx . . $ dbus_pending_call_block(f8094f87eabead78).(pending); |
| 154 | msg = dbus_pending_call_steal_replycxx . . $ dbus_pending_call_steal_reply(5c89f41a44f43d9f).(pending); |
| 155 | if (msg == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 156 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to steal dbus pending call reply."); |
| 157 | goto cleanup; |
| 158 | } |
| 159 | dbus_pending_call_unrefcxx . . $ dbus_pending_call_unref(f8094f87eabead78).(pending); pending = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 160 | |
| 161 | if (!dbus_message_iter_initcxx . . $ dbus_message_iter_init(ffe71547a19cf1fb).(msg, &args)) { |
| 162 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Failed to initialize iterator over received dbus message."); |
| 163 | goto cleanup; |
| 164 | } |
| 165 | |
| 166 | if (dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(&args) != DBUS_TYPE_ARRAYcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:122:9`!) { |
| 167 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Expected array of structs in reply. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args))); |
| 168 | goto cleanup; |
| 169 | } |
| 170 | |
| 171 | dbus_message_iter_recursecxx . . $ dbus_message_iter_recurse(6e42dd501f62eaf0).(&args, &unit_iter); |
| 172 | do { |
| 173 | if (dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(&unit_iter) != DBUS_TYPE_STRUCTcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:138:9`!) { |
| 174 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Expected unit struct as elements in returned array. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&unit_iter))); |
| 175 | goto cleanup; |
| 176 | } |
| 177 | |
| 178 | DBusMessageItercxx . . $ DBusMessageIter# unit_full_path_and_name; |
| 179 | dbus_message_iter_recursecxx . . $ dbus_message_iter_recurse(6e42dd501f62eaf0).(&unit_iter, &unit_full_path_and_name); |
| 180 | |
| 181 | if (dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(&unit_full_path_and_name) != DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!) { |
| 182 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Expected string as the first element in the unit struct. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&unit_full_path_and_name))); |
| 183 | goto cleanup; |
| 184 | } |
| 185 | |
| 186 | _DBusBasicValuecxx . . $ _DBusBasicValue# value; |
| 187 | dbus_message_iter_get_basiccxx . . $ dbus_message_iter_get_basic(5a06ffdfd9031a8).(&unit_full_path_and_name, &value); |
| 188 | char *unit_name_s = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(value.strcxx . . $ $anonymous_type_4cbcdbc067a1c97e_1#str.)); |
| 189 | oscap_strrmcxx . . $ oscap_strrm(72c91e5e80d20bae).(unit_name_s, "@"); |
| 190 | int cbret = callback(unit_name_s, cbarg); |
| 191 | freecxx . . $ free(5d22bdacc48458e8).(unit_name_s); |
| 192 | if (cbret != 0) { |
| 193 | goto cleanup; |
| 194 | } |
| 195 | } |
| 196 | while (dbus_message_iter_nextcxx . . $ dbus_message_iter_next(e45094e8c4b79815).(&unit_iter)); |
| 197 | |
| 198 | dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 199 | |
| 200 | ret = 0; |
| 201 | |
| 202 | cleanup: |
| 203 | if (pending != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 204 | dbus_pending_call_unrefcxx . . $ dbus_pending_call_unref(f8094f87eabead78).(pending); |
| 205 | |
| 206 | if (msg != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 207 | dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); |
| 208 | |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | #endif |