bus-convenience.c revision 0f51442056157cfec2efc52ddbff7392b0ff674a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-signature.h"
#include "bus-util.h"
#include "bus-type.h"
const char *path,
const char *interface,
const char *member,
const char *types, ...) {
int r;
return -ENOTCONN;
if (r < 0)
return r;
if (r < 0)
return r;
}
}
const char *destination,
const char *path,
const char *interface,
const char *member,
const char *types, ...) {
int r;
return -ENOTCONN;
if (r < 0)
return r;
if (r < 0)
return r;
}
}
const char *types, ...) {
int r;
return -ENOTCONN;
return 0;
r = sd_bus_message_new_method_return(call, &m);
if (r < 0)
return r;
if (r < 0)
return r;
}
}
const sd_bus_error *e) {
int r;
return -ENOTCONN;
return 0;
r = sd_bus_message_new_method_error(call, &m, e);
if (r < 0)
return r;
}
const char *name,
const char *format,
...) {
return -ENOTCONN;
return 0;
}
int error,
const sd_bus_error *p) {
return -ENOTCONN;
return 0;
if (sd_bus_error_is_set(p))
return sd_bus_reply_method_error(call, p);
}
int error,
const char *format,
...) {
return -ENOTCONN;
return 0;
}
const char *destination,
const char *path,
const char *interface,
const char *member,
const char *type) {
int r;
return -ENOTCONN;
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &rep, "ss", strempty(interface), member);
if (r < 0)
return r;
if (r < 0) {
return r;
}
return 0;
}
const char *destination,
const char *path,
const char *interface,
const char *member,
int r;
return -ENOTCONN;
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
const char *destination,
const char *path,
const char *interface,
const char *member,
char **ret) {
const char *s;
char *n;
int r;
return -ENOTCONN;
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
n = strdup(s);
if (!n)
return -ENOMEM;
*ret = n;
return 0;
}
const char *destination,
const char *path,
const char *interface,
const char *member,
char ***ret) {
int r;
return -ENOTCONN;
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
const char *destination,
const char *path,
const char *interface,
const char *member,
const char *type, ...) {
int r;
return -ENOTCONN;
r = sd_bus_message_new_method_call(bus, &m, destination, path, "org.freedesktop.DBus.Properties", "Set");
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
}
sd_bus_creds *c;
return -ENOTCONN;
c = sd_bus_message_get_creds(call);
/* All data we need? */
*creds = sd_bus_creds_ref(c);
return 0;
}
/* No data passed? Or not enough data passed to retrieve the missing bits? */
if (!c || !(c->mask & SD_BUS_CREDS_PID)) {
/* We couldn't read anything from the call, let's try
* to get it from the sender or peer. */
/* There's a sender, but the creds are
* missing. This means we are talking via
* dbus1, or are getting a message that was
* sent to us via kdbus, but was converted
* from a dbus1 message by the bus-proxy and
* thus also lacks the creds. */
else
/* There's no sender, hence we are on a dbus1
* direct connection. For direct connections
* the credentials of the AF_UNIX peer matter,
* which may be queried via
* sd_bus_get_owner_creds(). */
}
}
bool know_caps = false;
int r;
return -ENOTCONN;
if (capability >= 0) {
r = sd_bus_query_sender_creds(call, SD_BUS_CREDS_UID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_EFFECTIVE_CAPS, &creds);
if (r < 0)
return r;
/* We cannot use augmented caps for authorization,
* since then data is acquired raceful from
* /proc. This can never actually happen, but let's
* better be safe than sorry, and do an extra check
* here. */
/* Note that not even on kdbus we might have the caps
* field, due to faked identities, or namespace
* translation issues. */
if (r > 0)
return 1;
if (r == 0)
know_caps = true;
} else {
if (r < 0)
return r;
}
/* Now, check the UID, but only if the capability check wasn't
* sufficient */
* since then data is acquired raceful from
* /proc. This can never actually happen, but let's
* better be safe than sorry, and do an extra check
* here. */
assert_return((sd_bus_creds_get_augmented_mask(creds) & (SD_BUS_CREDS_UID|SD_BUS_CREDS_EUID)) == 0, -EPERM);
/* Try to use the EUID, if we have it. */
if (r < 0)
if (r >= 0) {
/* Sender has same UID as us, then let's grant access */
if (sender_uid == our_uid)
return 1;
/* Sender is root, we are not root. */
if (our_uid != 0 && sender_uid == 0)
return 1;
}
}
return 0;
}