1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7 This file is part of systemd.
9 Copyright 2013 Lennart Poettering
11 systemd is free software; you can redistribute it and/or modify it
12 under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
14 (at your option) any later version.
16 systemd is distributed in the hope that it will be useful, but
17 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.
21 You should have received a copy of the GNU Lesser General Public License
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
32 #include "_sd-common.h"
34 _SD_BEGIN_DECLARATIONS;
38 typedef struct sd_bus sd_bus;
39 typedef struct sd_bus_message sd_bus_message;
40 typedef struct sd_bus_creds sd_bus_creds;
51 SD_BUS_CREDS_PID = 1ULL << 0,
52 SD_BUS_CREDS_PID_STARTTIME = 1ULL << 1,
53 SD_BUS_CREDS_TID = 1ULL << 2,
54 SD_BUS_CREDS_UID = 1ULL << 3,
55 SD_BUS_CREDS_GID = 1ULL << 4,
56 SD_BUS_CREDS_COMM = 1ULL << 5,
57 SD_BUS_CREDS_TID_COMM = 1ULL << 6,
58 SD_BUS_CREDS_EXE = 1ULL << 7,
59 SD_BUS_CREDS_CMDLINE = 1ULL << 8,
60 SD_BUS_CREDS_CGROUP = 1ULL << 9,
61 SD_BUS_CREDS_UNIT = 1ULL << 10,
62 SD_BUS_CREDS_USER_UNIT = 1ULL << 11,
63 SD_BUS_CREDS_SLICE = 1ULL << 12,
64 SD_BUS_CREDS_SESSION = 1ULL << 13,
65 SD_BUS_CREDS_OWNER_UID = 1ULL << 14,
66 SD_BUS_CREDS_EFFECTIVE_CAPS = 1ULL << 15,
67 SD_BUS_CREDS_PERMITTED_CAPS = 1ULL << 16,
68 SD_BUS_CREDS_INHERITABLE_CAPS = 1ULL << 17,
69 SD_BUS_CREDS_BOUNDING_CAPS = 1ULL << 18,
70 SD_BUS_CREDS_SELINUX_CONTEXT = 1ULL << 19,
71 SD_BUS_CREDS_AUDIT_SESSION_ID = 1ULL << 20,
72 SD_BUS_CREDS_AUDIT_LOGIN_UID = 1ULL << 21,
73 SD_BUS_CREDS_UNIQUE_NAME = 1ULL << 22,
74 SD_BUS_CREDS_WELL_KNOWN_NAMES = 1ULL << 23,
75 _SD_BUS_CREDS_ALL = (1ULL << 24) -1,
79 SD_BUS_NAME_REPLACE_EXISTING = 1ULL << 0,
80 SD_BUS_NAME_ALLOW_REPLACEMENT = 1ULL << 1,
81 SD_BUS_NAME_QUEUE = 1ULL << 2,
86 typedef int (*sd_bus_message_handler_t)(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
87 typedef int (*sd_bus_property_get_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
88 typedef int (*sd_bus_property_set_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *ret_error);
89 typedef int (*sd_bus_object_find_t) (sd_bus *bus, const char *path, const char *interface, void *userdata, void **ret_found, sd_bus_error *ret_error);
90 typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *path, void *userdata, char ***ret_nodes, sd_bus_error *ret_error);
92 #include "sd-bus-protocol.h"
93 #include "sd-bus-vtable.h"
97 int sd_bus_default_user(sd_bus **ret);
98 int sd_bus_default_system(sd_bus **ret);
100 int sd_bus_open_user(sd_bus **ret);
101 int sd_bus_open_system(sd_bus **ret);
102 int sd_bus_open_system_remote(const char *host, sd_bus **ret);
103 int sd_bus_open_system_container(const char *machine, sd_bus **ret);
105 int sd_bus_new(sd_bus **ret);
106 int sd_bus_set_address(sd_bus *bus, const char *address);
107 int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd);
108 int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]);
109 int sd_bus_set_bus_client(sd_bus *bus, int b);
110 int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server_id);
111 int sd_bus_set_anonymous(sd_bus *bus, int b);
112 int sd_bus_set_trusted(sd_bus *bus, int b);
113 int sd_bus_negotiate_fds(sd_bus *bus, int b);
114 int sd_bus_negotiate_attach_timestamp(sd_bus *bus, int b);
115 int sd_bus_negotiate_attach_creds(sd_bus *bus, uint64_t creds_mask);
116 int sd_bus_start(sd_bus *ret);
118 int sd_bus_try_close(sd_bus *bus);
119 void sd_bus_close(sd_bus *bus);
121 sd_bus *sd_bus_ref(sd_bus *bus);
122 sd_bus *sd_bus_unref(sd_bus *bus);
124 int sd_bus_is_open(sd_bus *bus);
125 int sd_bus_can_send(sd_bus *bus, char type);
126 int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *peer);
127 int sd_bus_get_peer_creds(sd_bus *bus, uint64_t creds_mask, sd_bus_creds **ret);
129 int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *cookie);
130 int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *cookie);
131 int sd_bus_call(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *ret_error, sd_bus_message **reply);
132 int sd_bus_call_async(sd_bus *bus, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec, uint64_t *cookie);
133 int sd_bus_call_async_cancel(sd_bus *bus, uint64_t cookie);
135 int sd_bus_get_fd(sd_bus *bus);
136 int sd_bus_get_events(sd_bus *bus);
137 int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec);
138 int sd_bus_process(sd_bus *bus, sd_bus_message **r);
139 int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec);
140 int sd_bus_flush(sd_bus *bus);
142 sd_bus_message* sd_bus_get_current(sd_bus *bus);
143 int sd_bus_get_tid(sd_bus *bus, pid_t *tid);
145 int sd_bus_attach_event(sd_bus *bus, sd_event *e, int priority);
146 int sd_bus_detach_event(sd_bus *bus);
147 sd_event *sd_bus_get_event(sd_bus *bus);
149 int sd_bus_add_filter(sd_bus *bus, sd_bus_message_handler_t callback, void *userdata);
150 int sd_bus_remove_filter(sd_bus *bus, sd_bus_message_handler_t callback, void *userdata);
152 int sd_bus_add_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
153 int sd_bus_remove_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
155 int sd_bus_add_object(sd_bus *bus, const char *path, sd_bus_message_handler_t callback, void *userdata);
156 int sd_bus_remove_object(sd_bus *bus, const char *path, sd_bus_message_handler_t callback, void *userdata);
158 int sd_bus_add_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handler_t callback, void *userdata);
159 int sd_bus_remove_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handler_t callback, void *userdata);
161 int sd_bus_add_object_vtable(sd_bus *bus, const char *path, const char *interface, const sd_bus_vtable *vtable, void *userdata);
162 int sd_bus_remove_object_vtable(sd_bus *bus, const char *path, const char *interface, const sd_bus_vtable *vtable, void *userdata);
164 int sd_bus_add_fallback_vtable(sd_bus *bus, const char *path, const char *interface, const sd_bus_vtable *vtable, sd_bus_object_find_t find, void *userdata);
165 int sd_bus_remove_fallback_vtable(sd_bus *bus, const char *path, const char *interface, const sd_bus_vtable *vtable, sd_bus_object_find_t find, void *userdata);
167 int sd_bus_add_node_enumerator(sd_bus *bus, const char *path, sd_bus_node_enumerator_t callback, void *userdata);
168 int sd_bus_remove_node_enumerator(sd_bus *bus, const char *path, sd_bus_node_enumerator_t callback, void *userdata);
170 int sd_bus_add_object_manager(sd_bus *bus, const char *path);
171 int sd_bus_remove_object_manager(sd_bus *bus, const char *path);
175 int sd_bus_message_new_signal(sd_bus *bus, const char *path, const char *interface, const char *member, sd_bus_message **m);
176 int sd_bus_message_new_method_call(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message **m);
177 int sd_bus_message_new_method_return(sd_bus_message *call, sd_bus_message **m);
178 int sd_bus_message_new_method_error(sd_bus_message *call, const sd_bus_error *e, sd_bus_message **m);
179 int sd_bus_message_new_method_errorf(sd_bus_message *call, sd_bus_message **m, const char *name, const char *format, ...) _sd_printf_(4, 5);
180 int sd_bus_message_new_method_errno(sd_bus_message *call, int error, const sd_bus_error *e, sd_bus_message **m);
181 int sd_bus_message_new_method_errnof(sd_bus_message *call, sd_bus_message **m, int error, const char *format, ...) _sd_printf_(4, 5);
183 sd_bus_message* sd_bus_message_ref(sd_bus_message *m);
184 sd_bus_message* sd_bus_message_unref(sd_bus_message *m);
186 sd_bus* sd_bus_message_get_bus(sd_bus_message *m);
188 int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type);
189 int sd_bus_message_get_cookie(sd_bus_message *m, uint64_t *cookie);
190 int sd_bus_message_get_reply_cookie(sd_bus_message *m, uint64_t *cookie);
191 int sd_bus_message_get_no_reply(sd_bus_message *m);
192 int sd_bus_message_get_no_auto_start(sd_bus_message *m);
194 const char *sd_bus_message_get_signature(sd_bus_message *m, int complete);
195 const char *sd_bus_message_get_path(sd_bus_message *m);
196 const char *sd_bus_message_get_interface(sd_bus_message *m);
197 const char *sd_bus_message_get_member(sd_bus_message *m);
198 const char *sd_bus_message_get_destination(sd_bus_message *m);
199 const char *sd_bus_message_get_sender(sd_bus_message *m);
200 const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m);
201 int sd_bus_message_get_errno(sd_bus_message *m);
203 int sd_bus_message_get_monotonic_timestamp(sd_bus_message *m, uint64_t *usec);
204 int sd_bus_message_get_realtime_timestamp(sd_bus_message *m, uint64_t *usec);
205 sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m); /* do not unref the result */
207 int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member);
208 int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, const char *member);
209 int sd_bus_message_is_method_error(sd_bus_message *m, const char *name);
211 int sd_bus_message_set_no_reply(sd_bus_message *m, int b);
212 int sd_bus_message_set_no_auto_start(sd_bus_message *m, int b);
213 int sd_bus_message_set_destination(sd_bus_message *m, const char *destination);
215 int sd_bus_message_append(sd_bus_message *m, const char *types, ...);
216 int sd_bus_message_append_basic(sd_bus_message *m, char type, const void *p);
217 int sd_bus_message_append_array(sd_bus_message *m, char type, const void *ptr, size_t size);
218 int sd_bus_message_append_array_space(sd_bus_message *m, char type, size_t size, void **ptr);
219 int sd_bus_message_append_array_iovec(sd_bus_message *m, char type, const struct iovec *iov, unsigned n);
220 int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, sd_memfd *memfd);
221 int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s);
222 int sd_bus_message_append_string_iovec(sd_bus_message *m, const struct iovec *iov, unsigned n);
223 int sd_bus_message_append_string_memfd(sd_bus_message *m, sd_memfd* memfd);
224 int sd_bus_message_append_strv(sd_bus_message *m, char **l);
225 int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents);
226 int sd_bus_message_close_container(sd_bus_message *m);
227 int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all);
229 int sd_bus_message_read(sd_bus_message *m, const char *types, ...);
230 int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p);
231 int sd_bus_message_read_array(sd_bus_message *m, char type, const void **ptr, size_t *size);
232 int sd_bus_message_read_strv(sd_bus_message *m, char ***l); /* free the result! */
233 int sd_bus_message_skip(sd_bus_message *m, const char *types);
234 int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *contents);
235 int sd_bus_message_exit_container(sd_bus_message *m);
236 int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **contents);
237 int sd_bus_message_verify_type(sd_bus_message *m, char type, const char *contents);
238 int sd_bus_message_at_end(sd_bus_message *m, int complete);
239 int sd_bus_message_rewind(sd_bus_message *m, int complete);
243 int sd_bus_get_unique_name(sd_bus *bus, const char **unique);
244 int sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags);
245 int sd_bus_release_name(sd_bus *bus, const char *name);
246 int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable); /* free the results */
247 int sd_bus_get_owner(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **creds); /* unref the result! */
248 int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine);
250 /* Convenience calls */
252 int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *types, ...);
253 int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *type);
254 int sd_bus_get_property_trivial(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char type, void *ret_ptr);
255 int sd_bus_get_property_string(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char **ret); /* free the result! */
256 int sd_bus_get_property_strv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char ***ret); /* free the result! */
257 int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, const char *ret_type, ...);
259 int sd_bus_reply_method_return(sd_bus_message *call, const char *types, ...);
260 int sd_bus_reply_method_error(sd_bus_message *call, const sd_bus_error *e);
261 int sd_bus_reply_method_errorf(sd_bus_message *call, const char *name, const char *format, ...) _sd_printf_(3, 4);
262 int sd_bus_reply_method_errno(sd_bus_message *call, int error, const sd_bus_error *e);
263 int sd_bus_reply_method_errnof(sd_bus_message *call, int error, const char *format, ...) _sd_printf_(3, 4);
265 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
267 int sd_bus_emit_properties_changed_strv(sd_bus *bus, const char *path, const char *interface, char **names);
268 int sd_bus_emit_properties_changed(sd_bus *bus, const char *path, const char *interface, const char *name, ...) _sd_sentinel_;
270 int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces);
271 int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_;
272 int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces);
273 int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_;
275 int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_bus_creds **creds);
277 /* Credential handling */
279 int sd_bus_creds_new_from_pid(pid_t pid, uint64_t creds_mask, sd_bus_creds **ret);
280 sd_bus_creds *sd_bus_creds_ref(sd_bus_creds *c);
281 sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c);
282 uint64_t sd_bus_creds_get_mask(sd_bus_creds *c);
284 int sd_bus_creds_get_pid(sd_bus_creds *c, pid_t *pid);
285 int sd_bus_creds_get_pid_starttime(sd_bus_creds *c, uint64_t *usec);
286 int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *tid);
287 int sd_bus_creds_get_uid(sd_bus_creds *c, uid_t *uid);
288 int sd_bus_creds_get_gid(sd_bus_creds *c, gid_t *gid);
289 int sd_bus_creds_get_comm(sd_bus_creds *c, const char **r);
290 int sd_bus_creds_get_tid_comm(sd_bus_creds *c, const char **r);
291 int sd_bus_creds_get_exe(sd_bus_creds *c, const char **r);
292 int sd_bus_creds_get_cmdline(sd_bus_creds *c, char ***cmdline);
293 int sd_bus_creds_get_cgroup(sd_bus_creds *c, const char **r);
294 int sd_bus_creds_get_unit(sd_bus_creds *c, const char **unit);
295 int sd_bus_creds_get_user_unit(sd_bus_creds *c, const char **unit);
296 int sd_bus_creds_get_slice(sd_bus_creds *c, const char **slice);
297 int sd_bus_creds_get_session(sd_bus_creds *c, const char **session);
298 int sd_bus_creds_get_owner_uid(sd_bus_creds *c, uid_t *uid);
299 int sd_bus_creds_has_effective_cap(sd_bus_creds *c, int capability);
300 int sd_bus_creds_has_permitted_cap(sd_bus_creds *c, int capability);
301 int sd_bus_creds_has_inheritable_cap(sd_bus_creds *c, int capability);
302 int sd_bus_creds_has_bounding_cap(sd_bus_creds *c, int capability);
303 int sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **r);
304 int sd_bus_creds_get_audit_session_id(sd_bus_creds *c, uint32_t *sessionid);
305 int sd_bus_creds_get_audit_login_uid(sd_bus_creds *c, uid_t *loginuid);
306 int sd_bus_creds_get_unique_name(sd_bus_creds *c, const char **name);
307 int sd_bus_creds_get_well_known_names(sd_bus_creds *c, char ***names);
309 /* Error structures */
311 #define SD_BUS_ERROR_MAKE_CONST(name, message) ((const sd_bus_error) {(name), (message), 0})
312 #define SD_BUS_ERROR_NULL SD_BUS_ERROR_MAKE_CONST(NULL, NULL)
314 void sd_bus_error_free(sd_bus_error *e);
315 int sd_bus_error_set(sd_bus_error *e, const char *name, const char *message);
316 int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...) _sd_printf_(3, 4);
317 int sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message);
318 int sd_bus_error_set_errno(sd_bus_error *e, int error);
319 int sd_bus_error_set_errnof(sd_bus_error *e, int error, const char *format, ...) _sd_printf_(3, 4);
320 int sd_bus_error_get_errno(const sd_bus_error *e);
321 int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e);
322 int sd_bus_error_is_set(const sd_bus_error *e);
323 int sd_bus_error_has_name(const sd_bus_error *e, const char *name);
325 /* Auxiliary macros */
327 #define SD_BUS_MESSAGE_APPEND_ID128(x) 16, \
328 (x).bytes[0], (x).bytes[1], (x).bytes[2], (x).bytes[3], \
329 (x).bytes[4], (x).bytes[5], (x).bytes[6], (x).bytes[7], \
330 (x).bytes[8], (x).bytes[9], (x).bytes[10], (x).bytes[11], \
331 (x).bytes[12], (x).bytes[13], (x).bytes[14], (x).bytes[15]
333 #define SD_BUS_MESSAGE_READ_ID128(x) 16, \
334 &(x).bytes[0], &(x).bytes[1], &(x).bytes[2], &(x).bytes[3], \
335 &(x).bytes[4], &(x).bytes[5], &(x).bytes[6], &(x).bytes[7], \
336 &(x).bytes[8], &(x).bytes[9], &(x).bytes[10], &(x).bytes[11], \
337 &(x).bytes[12], &(x).bytes[13], &(x).bytes[14], &(x).bytes[15]
341 char *sd_bus_label_escape(const char *s);
342 char *sd_bus_label_unescape(const char *f);
344 _SD_END_DECLARATIONS;