summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/busctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-28 17:50:02 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-28 18:42:18 +0100
commit5b12334d35eadf1f45cc3d631fd1a2e72ffaea0a (patch)
tree55682fbecfeb705adfaf0f78fd76f5c8dc219b1b /src/libsystemd-bus/busctl.c
parent70f75a523b16ad495a7791d595ee3eececf75953 (diff)
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.
Diffstat (limited to 'src/libsystemd-bus/busctl.c')
-rw-r--r--src/libsystemd-bus/busctl.c44
1 files changed, 25 insertions, 19 deletions
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)