summaryrefslogtreecommitdiff
path: root/src/login/logind-session-dbus.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-01-18 12:59:39 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2015-01-18 12:59:39 +0100
commitca56b0a68300b035c605bedc5b339128897debfc (patch)
treeb28a9af6a18fdecd0a1db0927322734b65a2285f /src/login/logind-session-dbus.c
parent7447362c530e3f7128f16a35d1e43da4251144cc (diff)
logind: hide 'self' links if not available
If the caller does not run in a session/seat or has no tracked user, hide the /org/freedesktop/login1/.../self links in introspection data. Otherwise, "busctl tree org.freedesktop.login1" tries to query those nodes even though it cant.
Diffstat (limited to 'src/login/logind-session-dbus.c')
-rw-r--r--src/login/logind-session-dbus.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index d3411314d8..e3486fe5fc 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -541,6 +541,7 @@ char *session_bus_path(Session *s) {
int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
+ sd_bus_message *message;
Manager *m = userdata;
Session *session;
Iterator i;
@@ -562,9 +563,24 @@ int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
return r;
}
- r = strv_extend(&l, "/org/freedesktop/login1/session/self");
- if (r < 0)
- return r;
+ message = sd_bus_get_current_message(bus);
+ if (message) {
+ _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+ const char *name;
+
+ r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_SESSION|SD_BUS_CREDS_AUGMENT, &creds);
+ if (r >= 0) {
+ r = sd_bus_creds_get_session(creds, &name);
+ if (r >= 0) {
+ session = hashmap_get(m->sessions, name);
+ if (session) {
+ r = strv_extend(&l, "/org/freedesktop/login1/session/self");
+ if (r < 0)
+ return r;
+ }
+ }
+ }
+ }
*nodes = l;
l = NULL;