bus-proxyd.c revision 210a68826fac0f6525719cc6044c7858c655986a
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering This file is part of systemd.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering Copyright 2010 Lennart Poettering
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers Copyright 2013 Daniel Mack
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering Copyright 2014 Kay Sievers
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering systemd is free software; you can redistribute it and/or modify it
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering under the terms of the GNU Lesser General Public License as published by
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering (at your option) any later version.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering systemd is distributed in the hope that it will be useful, but
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering Lesser General Public License for more details.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering You should have received a copy of the GNU Lesser General Public License
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic char *arg_command_line_buffer = NULL;
1b12a7b5896f94bdf33b3a6661ebabd761ea6adcHarald Hoyerstatic bool arg_drop_privileges = false;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int help(void) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "Connect STDIO or a socket to a given bus address.\n\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " -h --help Show this help\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " --version Show package version\n"
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering " --drop-privileges Drop privileges\n"
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering " --configuration=PATH Configuration file or directory\n"
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering " --machine=MACHINE Connect to specified machine\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " --address=ADDRESS Connect to the bus specified by ADDRESS\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " (default: " DEFAULT_SYSTEM_BUS_ADDRESS ")\n",
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers { "address", required_argument, NULL, ARG_ADDRESS },
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers { "drop-privileges", no_argument, NULL, ARG_DROP_PRIVILEGES },
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers { "configuration", required_argument, NULL, ARG_CONFIGURATION },
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers { "machine", required_argument, NULL, ARG_MACHINE },
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers switch (c) {
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek r = strv_extend(&arg_configuration, optarg);
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek a = strjoin("x-machine-kernel:machine=", e, ";x-machine-unix:machine=", e, NULL);
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers a = strjoin("x-machine-unix:machine=", e, NULL);
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen assert_not_reached("Unhandled option");
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen /* If the first command line argument is only "x" characters
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen * we'll write who we are talking to into it, so that "ps" is
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen arg_command_line_buffer = argv[optind];
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen if (argc > optind + 1 || (arg_command_line_buffer && !in_charset(arg_command_line_buffer, "x"))) {
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen log_error("Too many arguments");
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen arg_address = strdup(DEFAULT_SYSTEM_BUS_ADDRESS);
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmekstatic int rename_service(sd_bus *a, sd_bus *b) {
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen _cleanup_free_ char *p = NULL, *name = NULL;
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers r = sd_bus_get_owner_creds(b, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_CMDLINE|SD_BUS_CREDS_COMM, &creds);
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers /* The status string gets the full command line ... */
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers "STATUS=Processing requests from client PID "PID_FMT" (%s); UID "UID_FMT" (%s)",
adacb9575a09981fcf11279f2f661e3fc21e58ffLennart Poettering /* ... and the argv line only the short comm */
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen memzero(arg_command_line_buffer + w, m - w);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_debug("Running on behalf of PID "PID_FMT" (%s), UID "UID_FMT" (%s), %s",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int synthesize_name_acquired(sd_bus *a, sd_bus *b, sd_bus_message *m) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering _cleanup_bus_message_unref_ sd_bus_message *n = NULL;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering const char *name, *old_owner, *new_owner;
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen /* If we get NameOwnerChanged for our own name, we need to
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen * synthesize NameLost/NameAcquired, since socket clients need
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen * that, even though it is obsoleted on kdbus */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (!sd_bus_message_is_signal(m, "org.freedesktop.DBus", "NameOwnerChanged") ||
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering !streq_ptr(m->path, "/org/freedesktop/DBus") ||
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen !streq_ptr(m->sender, "org.freedesktop.DBus"))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = sd_bus_message_read(m, "sss", &name, &old_owner, &new_owner);
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen if (streq(old_owner, a->unique_name)) {
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen r = sd_bus_message_new_signal(
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen "org.freedesktop.DBus",
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen } else if (streq(new_owner, a->unique_name)) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "org.freedesktop.DBus",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "NameAcquired");
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen r = bus_message_append_sender(n, "org.freedesktop.DBus");
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen r = bus_seal_synthetic_message(b, n);
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen return sd_bus_send(b, n, NULL);
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersenstatic int synthetic_driver_send(sd_bus *b, sd_bus_message *m) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = bus_message_append_sender(m, "org.freedesktop.DBus");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int synthetic_reply_method_error(sd_bus_message *call, const sd_bus_error *e) {
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen r = sd_bus_message_new_method_error(call, &m, e);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return synthetic_driver_send(call->bus, m);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int synthetic_reply_method_errorf(sd_bus_message *call, const char *name, const char *format, ...) {
7568345034f2890af745747783c5abfbf6eccf0fLennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering bus_error_setfv(&error, name, format, ap);
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt return synthetic_reply_method_error(call, &error);
7c2d80944afb4196f2eff614e8da1450dffcbeaaThomas Hindoe Paaboel Andersenstatic int synthetic_reply_method_errno(sd_bus_message *call, int error, const sd_bus_error *p) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
7591abd48079edc1f2adbd922e4b83eb73abeabeLennart Poettering if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
4f8f66cb4236783cd3cbee97fefc9aaa8469ac08Zbigniew Jędrzejewski-Szmek return synthetic_reply_method_error(call, p);
4f8f66cb4236783cd3cbee97fefc9aaa8469ac08Zbigniew Jędrzejewski-Szmek sd_bus_error_set_errno(&berror, error);
4f8f66cb4236783cd3cbee97fefc9aaa8469ac08Zbigniew Jędrzejewski-Szmek return synthetic_reply_method_error(call, &berror);
4f8f66cb4236783cd3cbee97fefc9aaa8469ac08Zbigniew Jędrzejewski-Szmekstatic int synthetic_reply_method_return(sd_bus_message *call, const char *types, ...) {
07a062a79374406e8f6b5a1e2f80c80baf031567Jason St. John _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = sd_bus_message_new_method_return(call, &m);
c978343015c787713651dff571acb5207367f5f2Lennart Poettering return synthetic_driver_send(call->bus, m);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int synthetic_reply_return_strv(sd_bus_message *call, char **l) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = sd_bus_message_new_method_return(call, &m);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return synthetic_reply_method_errno(call, r, NULL);
601185b43da638b1c74153deae01dbd518680889Zbigniew Jędrzejewski-Szmek return synthetic_reply_method_errno(call, r, NULL);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return synthetic_driver_send(call->bus, m);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int get_creds_by_name(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **_creds, sd_bus_error *error) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen r = sd_bus_get_name_creds(bus, name, mask, &c);
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen return sd_bus_error_setf(error, SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Name %s is currently not owned by anyone.", name);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int get_creds_by_message(sd_bus *bus, sd_bus_message *m, uint64_t mask, sd_bus_creds **_creds, sd_bus_error *error) {
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen return get_creds_by_name(bus, name, mask, _creds, error);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *policy, const struct ucred *ucred, Set *owned_names) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (!streq_ptr(sd_bus_message_get_destination(m), "org.freedesktop.DBus"))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* The "Hello()" call is is handled in process_hello() */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (!sd_bus_message_has_signature(m, ""))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return synthetic_reply_method_return(m, "s",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" "
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"Introspect\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </interface>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <interface name=\"org.freedesktop.DBus\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"AddMatch\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"RemoveMatch\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"GetConnectionSELinuxSecurityContext\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"ay\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"GetConnectionUnixProcessID\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"u\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"GetConnectionUnixUser\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"u\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"GetId\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"GetNameOwner\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"Hello\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"ListActivatableNames\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"as\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"ListNames\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"as\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"ListQueuedOwners\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"as\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"NameHasOwner\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"b\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"ReleaseName\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"u\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"ReloadConfig\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
249968612f16a71df909d6e73785c18a9ff36a65Lennart Poettering " <method name=\"RequestName\">\n"
84f6181c2ac99a0514ca5e0c8fc8c8e284caf789Lennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"u\" direction=\"in\"/>\n"
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner " <arg type=\"u\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"StartServiceByName\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\" direction=\"in\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"u\" direction=\"in\"/>\n"
84f6181c2ac99a0514ca5e0c8fc8c8e284caf789Lennart Poettering " <arg type=\"u\" direction=\"out\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </method>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <method name=\"UpdateActivationEnvironment\">\n"
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen " <arg type=\"a{ss}\" direction=\"in\"/>\n"
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt " <signal name=\"NameAcquired\">\n"
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen " <arg type=\"s\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </signal>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <signal name=\"NameLost\">\n"
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen " <arg type=\"s\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </signal>\n"
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen " <signal name=\"NameOwnerChanged\">\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " <arg type=\"s\"/>\n"
84f6181c2ac99a0514ca5e0c8fc8c8e284caf789Lennart Poettering " <arg type=\"s\"/>\n"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering " </signal>\n"
const char *match;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
const char *match;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_MATCH_RULE_NOT_FOUND, "Match rule not found"));
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetConnectionSELinuxSecurityContext")) {
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetConnectionUnixProcessID")) {
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
const char *name;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
char *arg0;
int err = 0;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
sd_bus_error_setf(&error, SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Could not get owners of name '%s': no such name.", arg0);
err = r;
if (err < 0)
const char *name;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
const char *name;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
if (r == -ESRCH)
if (r == -EADDRINUSE)
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
r = sd_bus_error_setf(&error, SD_BUS_ERROR_NOT_SUPPORTED, "%s() is not supported", sd_bus_message_get_member(m));
const char *name;
bool in_queue;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
param = 0;
if (r == -EALREADY)
if (r == -EEXIST)
in_queue = (r == 0);
if (in_queue)
const char *name;
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
if (flags != 0)
if (r != -ESRCH)
&msg,
name,
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "UpdateActivationEnvironment")) {
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
const char *key;
const char *value;
r = sd_bus_message_exit_container(m);
r = sd_bus_message_exit_container(m);
if (!args)
&msg,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return synthetic_reply_method_errorf(m, SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Name %s is currently not owned by anyone.", m->destination);
static int process_policy(sd_bus *from, sd_bus *to, sd_bus_message *m, Policy *policy, const struct ucred *our_ucred, Set *owned_names) {
assert(m);
if (!policy)
bool granted = false;
if (policy_check_send(policy, sender_uid, sender_gid, m->header->type, NULL, m->path, m->interface, m->member))
granted = true;
Iterator i;
if (policy_check_send(policy, sender_uid, sender_gid, m->header->type, n, m->path, m->interface, m->member)) {
granted = true;
if (granted) {
if (policy_check_recv(policy, our_ucred->uid, our_ucred->gid, m->header->type, NULL, m->path, m->interface, m->member))
if (policy_check_recv(policy, our_ucred->uid, our_ucred->gid, m->header->type, *n, m->path, m->interface, m->member))
return synthetic_reply_method_errorf(m, SD_BUS_ERROR_ACCESS_DENIED, "Access prohibited by XML receiver policy.");
bool granted = false;
if (m->destination) {
true, &destination_creds);
return handle_policy_error(m, r);
return handle_policy_error(m, r);
if (policy_check_send(policy, our_ucred->uid, our_ucred->gid, m->header->type, NULL, m->path, m->interface, m->member))
granted = true;
if (policy_check_send(policy, our_ucred->uid, our_ucred->gid, m->header->type, *n, m->path, m->interface, m->member)) {
granted = true;
if (granted) {
if (policy_check_recv(policy, destination_uid, destination_gid, m->header->type, NULL, m->path, m->interface, m->member))
Iterator i;
if (policy_check_recv(policy, destination_uid, destination_gid, m->header->type, n, m->path, m->interface, m->member))
return synthetic_reply_method_errorf(m, SD_BUS_ERROR_ACCESS_DENIED, "Access prohibited by XML sender policy.");
bool is_hello;
assert(a);
assert(b);
assert(m);
is_hello =
if (!is_hello) {
if (*got_hello)
return -EIO;
if (*got_hello) {
return -EIO;
*got_hello = true;
if (!a->is_kernel)
r = sd_bus_message_new_method_return(m, &n);
r = bus_seal_synthetic_message(b, n);
n = sd_bus_message_unref(n);
"/org/freedesktop/DBus",
r = bus_seal_synthetic_message(b, n);
sd_bus_creds *c;
assert(a);
assert(m);
if (!a->is_kernel)
c = sd_bus_message_get_creds(m);
#ifdef HAVE_SMACK
if (!mac_smack_use())
bool got_hello = false;
bool is_unix;
log_open();
goto finish;
r = sd_listen_fds(0);
goto finish;
is_unix =
if (is_unix) {
if (arg_drop_privileges) {
goto finish;
goto finish;
if (!owned_names) {
log_oom();
goto finish;
r = sd_bus_new(&a);
goto finish;
goto finish;
goto finish;
goto finish;
r = sd_bus_negotiate_creds(a, true, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_GID|SD_BUS_CREDS_SELINUX_CONTEXT);
goto finish;
a->fake_pids_valid = true;
a->fake_creds_valid = true;
if (peersec) {
a->manual_peer_interface = true;
r = sd_bus_start(a);
goto finish;
goto finish;
if (a->is_kernel) {
if (!arg_configuration) {
const char *scope;
goto finish;
"/etc/dbus-1/system.conf",
NULL);
"/etc/dbus-1/session.conf",
NULL);
goto finish;
if (!arg_configuration) {
r = log_oom();
goto finish;
goto finish;
goto finish;
r = sd_bus_new(&b);
goto finish;
goto finish;
goto finish;
goto finish;
r = sd_bus_negotiate_creds(b, true, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_GID|SD_BUS_CREDS_SELINUX_CONTEXT);
goto finish;
r = sd_bus_set_anonymous(b, true);
goto finish;
b->manual_peer_interface = true;
r = sd_bus_start(b);
goto finish;
r = rename_service(a, b);
if (a->is_kernel) {
const char *unique;
goto finish;
"path='/org/freedesktop/DBus',"
NULL);
if (!match) {
log_oom();
goto finish;
goto finish;
"path='/org/freedesktop/DBus',"
NULL);
if (!match) {
log_oom();
goto finish;
goto finish;
if (got_hello) {
r = sd_bus_process(a, &m);
if (r == -ECONNRESET)
goto finish;
bool processed = false;
goto finish;
k = synthesize_name_acquired(a, b, m);
goto finish;
patch_sender(a, m);
if (policy) {
goto finish;
processed = true;
if (!processed) {
if (k == -ECONNRESET)
goto finish;
r = sd_bus_process(b, &m);
if (r == -ECONNRESET)
goto finish;
bool processed = false;
goto finish;
goto finish;
processed = true;
if (!processed) {
goto finish;
processed = true;
if (!processed) {
if (policy) {
goto finish;
processed = true;
if (k == -EREMCHG)
else if (k == -ECONNRESET)
goto finish;
if (fd < 0) {
goto finish;
if (events_a < 0) {
goto finish;
goto finish;
if (events_b < 0) {
goto finish;
goto finish;
t = timeout_a;
t = timeout_b;
if (t > nw)
t -= nw;
goto finish;
sd_notify(false,