31#ifndef OPENSCAP_OVAL_PROBES_SYSTEMDSHARED_H_
32#define OPENSCAP_OVAL_PROBES_SYSTEMDSHARED_H_
42#include "oscap_helpers.h"
46static char *get_path_by_unit(DBusConnection *conn,
const char *unit)
48 DBusMessage *msg = NULL;
49 DBusPendingCall *pending = NULL;
53 msg = dbus_message_new_method_call(
54 "org.freedesktop.systemd1",
55 "/org/freedesktop/systemd1",
56 "org.freedesktop.systemd1.Manager",
61 dD(
"LoadUnit: %s", unit);
64 dD(
"Failed to create dbus_message via dbus_message_new_method_call!");
70 dbus_message_iter_init_append(msg, &args);
71 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &unit)) {
72 dD(
"Failed to append unit '%s' string parameter to dbus message!", unit);
76 if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
77 dD(
"Failed to send message via dbus!");
80 if (pending == NULL) {
81 dD(
"Invalid dbus pending call!");
85 dbus_connection_flush(conn);
86 dbus_message_unref(msg); msg = NULL;
88 dbus_pending_call_block(pending);
89 msg = dbus_pending_call_steal_reply(pending);
91 dD(
"Failed to steal dbus pending call reply.");
94 dbus_pending_call_unref(pending); pending = NULL;
96 if (!dbus_message_iter_init(msg, &args)) {
97 dD(
"Failed to initialize iterator over received dbus message.");
101 if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH) {
102 dD(
"Expected object path argument in reply. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args)));
106 dbus_message_iter_get_basic(&args, &path);
107 ret = oscap_strdup(path.
str);
108 dbus_message_unref(msg); msg = NULL;
112 dbus_pending_call_unref(pending);
115 dbus_message_unref(msg);
120static int get_all_systemd_units(DBusConnection* conn,
int(*callback)(
const char *,
void *),
void *cbarg)
122 DBusMessage *msg = NULL;
123 DBusPendingCall *pending = NULL;
126 msg = dbus_message_new_method_call(
127 "org.freedesktop.systemd1",
128 "/org/freedesktop/systemd1",
129 "org.freedesktop.systemd1.Manager",
133 dD(
"Failed to create dbus_message via dbus_message_new_method_call!");
137 DBusMessageIter args, unit_iter;
140 dbus_message_iter_init_append(msg, &args);
142 if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
143 dD(
"Failed to send message via dbus!");
146 if (pending == NULL) {
147 dD(
"Invalid dbus pending call!");
151 dbus_connection_flush(conn);
152 dbus_message_unref(msg); msg = NULL;
154 dbus_pending_call_block(pending);
155 msg = dbus_pending_call_steal_reply(pending);
157 dD(
"Failed to steal dbus pending call reply.");
160 dbus_pending_call_unref(pending); pending = NULL;
162 if (!dbus_message_iter_init(msg, &args)) {
163 dD(
"Failed to initialize iterator over received dbus message.");
167 if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) {
168 dD(
"Expected array of structs in reply. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args)));
172 dbus_message_iter_recurse(&args, &unit_iter);
174 if (dbus_message_iter_get_arg_type(&unit_iter) != DBUS_TYPE_STRUCT) {
175 dD(
"Expected unit struct as elements in returned array. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&unit_iter)));
179 DBusMessageIter unit_full_path_and_name;
180 dbus_message_iter_recurse(&unit_iter, &unit_full_path_and_name);
182 if (dbus_message_iter_get_arg_type(&unit_full_path_and_name) != DBUS_TYPE_STRING) {
183 dD(
"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)));
188 dbus_message_iter_get_basic(&unit_full_path_and_name, &value);
189 char *unit_name_s = oscap_strdup(basename(value.
str));
190 oscap_strrm(unit_name_s,
"@");
191 int cbret = callback(unit_name_s, cbarg);
197 while (dbus_message_iter_next(&unit_iter));
199 dbus_message_unref(msg); msg = NULL;
205 dbus_pending_call_unref(pending);
208 dbus_message_unref(msg);
oscap debug helpers private header
Definition oval_dbus.h:40
char * str
as char* (string, object path or signature)
Definition oval_dbus.h:54