31#ifndef OPENSCAP_OVAL_PROBES_SYSTEMDSHARED_H_
32#define OPENSCAP_OVAL_PROBES_SYSTEMDSHARED_H_
41#include "oscap_helpers.h"
45static char *get_path_by_unit(DBusConnection *conn,
const char *unit)
47 DBusMessage *msg = NULL;
48 DBusPendingCall *pending = NULL;
52 msg = dbus_message_new_method_call(
53 "org.freedesktop.systemd1",
54 "/org/freedesktop/systemd1",
55 "org.freedesktop.systemd1.Manager",
60 dD(
"LoadUnit: %s", unit);
63 dD(
"Failed to create dbus_message via dbus_message_new_method_call!");
69 dbus_message_iter_init_append(msg, &args);
70 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &unit)) {
71 dD(
"Failed to append unit '%s' string parameter to dbus message!", unit);
75 if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
76 dD(
"Failed to send message via dbus!");
79 if (pending == NULL) {
80 dD(
"Invalid dbus pending call!");
84 dbus_connection_flush(conn);
85 dbus_message_unref(msg); msg = NULL;
87 dbus_pending_call_block(pending);
88 msg = dbus_pending_call_steal_reply(pending);
90 dD(
"Failed to steal dbus pending call reply.");
93 dbus_pending_call_unref(pending); pending = NULL;
95 if (!dbus_message_iter_init(msg, &args)) {
96 dD(
"Failed to initialize iterator over received dbus message.");
100 if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH) {
101 dD(
"Expected object path argument in reply. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args)));
105 dbus_message_iter_get_basic(&args, &path);
106 ret = oscap_strdup(path.
str);
107 dbus_message_unref(msg); msg = NULL;
111 dbus_pending_call_unref(pending);
114 dbus_message_unref(msg);
119static int get_all_systemd_units(DBusConnection* conn,
int(*callback)(
const char *,
void *),
void *cbarg)
121 DBusMessage *msg = NULL;
122 DBusPendingCall *pending = NULL;
125 msg = dbus_message_new_method_call(
126 "org.freedesktop.systemd1",
127 "/org/freedesktop/systemd1",
128 "org.freedesktop.systemd1.Manager",
132 dD(
"Failed to create dbus_message via dbus_message_new_method_call!");
136 DBusMessageIter args, unit_iter;
139 dbus_message_iter_init_append(msg, &args);
141 if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
142 dD(
"Failed to send message via dbus!");
145 if (pending == NULL) {
146 dD(
"Invalid dbus pending call!");
150 dbus_connection_flush(conn);
151 dbus_message_unref(msg); msg = NULL;
153 dbus_pending_call_block(pending);
154 msg = dbus_pending_call_steal_reply(pending);
156 dD(
"Failed to steal dbus pending call reply.");
159 dbus_pending_call_unref(pending); pending = NULL;
161 if (!dbus_message_iter_init(msg, &args)) {
162 dD(
"Failed to initialize iterator over received dbus message.");
166 if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) {
167 dD(
"Expected array of structs in reply. Instead received: %s.", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args)));
171 dbus_message_iter_recurse(&args, &unit_iter);
173 if (dbus_message_iter_get_arg_type(&unit_iter) != DBUS_TYPE_STRUCT) {
174 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)));
178 DBusMessageIter unit_full_path_and_name;
179 dbus_message_iter_recurse(&unit_iter, &unit_full_path_and_name);
181 if (dbus_message_iter_get_arg_type(&unit_full_path_and_name) != DBUS_TYPE_STRING) {
182 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)));
187 dbus_message_iter_get_basic(&unit_full_path_and_name, &value);
188 char *unit_name_s = oscap_strdup(basename(value.
str));
189 oscap_strrm(unit_name_s,
"@");
190 int cbret = callback(unit_name_s, cbarg);
196 while (dbus_message_iter_next(&unit_iter));
198 dbus_message_unref(msg); msg = NULL;
204 dbus_pending_call_unref(pending);
207 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