diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-12-02 18:40:19 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-12-02 18:40:43 +0100 |
commit | 95c4fe827195b47fad7cc87a3f84bf3af6b657c2 (patch) | |
tree | 7fe47e1521c7ae3846c8a71327af37efd23609e2 /src/libsystemd-bus/busctl.c | |
parent | a009c158b098e961fd71db47a31ca15048c9816e (diff) |
busctl: add command to dump creds of a peer or pid
(also, rename _SD_BUS_CREDS_MAX to _SD_BUX_CRED_ALL, since "MAX" so far
was used to indicate one higher than the highest valid value, and this
is not correct here.)
Diffstat (limited to 'src/libsystemd-bus/busctl.c')
-rw-r--r-- | src/libsystemd-bus/busctl.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c index f557e50036..f1ae051c9b 100644 --- a/src/libsystemd-bus/busctl.c +++ b/src/libsystemd-bus/busctl.c @@ -215,8 +215,33 @@ static int monitor(sd_bus *bus, char *argv[]) { return r; } } +} - return -EINVAL; +static int status(sd_bus *bus, char *argv[]) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; + pid_t pid; + int r; + + assert(bus); + + if (strv_length(argv) != 2) { + log_error("Expects one argument."); + return -EINVAL; + } + + r = parse_pid(argv[1], &pid); + if (r < 0) + r = sd_bus_get_owner(bus, argv[1], _SD_BUS_CREDS_ALL, &creds); + else + r = sd_bus_creds_new_from_pid(pid, _SD_BUS_CREDS_ALL, &creds); + + if (r < 0) { + log_error("Failed to get credentials: %s", strerror(-r)); + return r; + } + + bus_creds_dump(creds, NULL); + return 0; } static int help(void) { @@ -347,6 +372,9 @@ static int busctl_main(sd_bus *bus, int argc, char *argv[]) { if (streq(argv[optind], "monitor")) return monitor(bus, argv + optind); + if (streq(argv[optind], "status")) + return status(bus, argv + optind); + if (streq(argv[optind], "help")) return help(); |