From 5b12334d35eadf1f45cc3d631fd1a2e72ffaea0a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 28 Nov 2013 17:50:02 +0100 Subject: bus: add new sd_bus_creds object to encapsulate process credentials This way we can unify handling of credentials that are attached to messages, or can be queried for bus name owners or connection peers. This also adds the ability to extend incomplete credential information with data from /proc, Also, provide a convenience call that will automatically determine the most appropriate credential object for an incoming message, by using the the attached information if possible, the sending name information if available and otherwise the peer's credentials. --- src/libsystemd-bus/busctl.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/libsystemd-bus/busctl.c') diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c index 4204adb5bc..24db48a7e6 100644 --- a/src/libsystemd-bus/busctl.c +++ b/src/libsystemd-bus/busctl.c @@ -75,41 +75,47 @@ static int list_bus_names(sd_bus *bus, char **argv) { (int) max_i, "NAME", 10, "PID", 15, "PROCESS", 16, "USER", 20, "CONNECTION"); STRV_FOREACH(i, l) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; _cleanup_free_ char *owner = NULL; sd_id128_t mid; - pid_t pid; - uid_t uid; if (arg_no_unique && (*i)[0] == ':') continue; printf("%-*s", (int) max_i, *i); - r = sd_bus_get_owner_pid(bus, *i, &pid); + r = sd_bus_get_owner_creds(bus, *i, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_COMM, &creds); if (r >= 0) { - _cleanup_free_ char *comm = NULL; + pid_t pid; + uid_t uid; - printf(" %10lu", (unsigned long) pid); + r = sd_bus_creds_get_pid(creds, &pid); + if (r >= 0) { + const char *comm = NULL; - get_process_comm(pid, &comm); - printf(" %-15s", strna(comm)); - } else - printf(" - - "); + sd_bus_creds_get_comm(creds, &comm); - r = sd_bus_get_owner_uid(bus, *i, &uid); - if (r >= 0) { - _cleanup_free_ char *u = NULL; + printf(" %10lu %-15s", (unsigned long) pid, strna(comm)); + } else + printf(" - - "); - u = uid_to_name(uid); - if (!u) - return log_oom(); + r = sd_bus_creds_get_uid(creds, &uid); + if (r >= 0) { + _cleanup_free_ char *u = NULL; - if (strlen(u) > 16) - u[16] = 0; + u = uid_to_name(uid); + if (!u) + return log_oom(); - printf(" %-16s", u); + if (strlen(u) > 16) + u[16] = 0; + + printf(" %-16s", u); + } else + printf(" - "); } else - printf(" - "); + printf(" - - - "); + r = sd_bus_get_owner(bus, *i, &owner); if (r >= 0) -- cgit v1.2.3-54-g00ecf