diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-28 17:50:02 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-28 18:42:18 +0100 |
commit | 5b12334d35eadf1f45cc3d631fd1a2e72ffaea0a (patch) | |
tree | 55682fbecfeb705adfaf0f78fd76f5c8dc219b1b /src/login | |
parent | 70f75a523b16ad495a7791d595ee3eececf75953 (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/login')
-rw-r--r-- | src/login/logind-dbus.c | 47 | ||||
-rw-r--r-- | src/login/logind-seat-dbus.c | 9 | ||||
-rw-r--r-- | src/login/logind-session-dbus.c | 23 | ||||
-rw-r--r-- | src/login/logind-user-dbus.c | 9 |
4 files changed, 73 insertions, 15 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index a4bdf5f28c..0461d1877e 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -172,7 +172,13 @@ static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void return r; if (pid == 0) { - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; + + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_pid(creds, &pid); if (r < 0) return r; } @@ -234,7 +240,13 @@ static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *us return r; if (pid == 0) { - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; + + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_pid(creds, &pid); if (r < 0) return r; } @@ -543,9 +555,15 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use } if (leader <= 0) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; + + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); + if (r < 0) + return r; + assert_cc(sizeof(uint32_t) == sizeof(pid_t)); - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), (pid_t*) &leader); + r = sd_bus_creds_get_pid(creds, (pid_t*) &leader); if (r < 0) return r; } @@ -1424,6 +1442,7 @@ static int method_do_shutdown_or_sleep( sd_bus_message_handler_t method, sd_bus_error *error) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; bool multiple_sessions, blocked; int interactive, r; uid_t uid; @@ -1455,7 +1474,11 @@ static int method_do_shutdown_or_sleep( return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Sleep verb not supported"); } - r = sd_bus_get_owner_uid(m->bus, sd_bus_message_get_sender(message), &uid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_UID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_uid(creds, &uid); if (r < 0) return r; @@ -1579,6 +1602,7 @@ static int method_can_shutdown_or_sleep( const char *sleep_verb, sd_bus_error *error) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; bool multiple_sessions, challenge, blocked; const char *result = NULL; uid_t uid; @@ -1600,7 +1624,11 @@ static int method_can_shutdown_or_sleep( return sd_bus_reply_method_return(message, "s", "na"); } - r = sd_bus_get_owner_uid(m->bus, sd_bus_message_get_sender(message), &uid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_UID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_uid(creds, &uid); if (r < 0) return r; @@ -1722,6 +1750,7 @@ static int method_can_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *u } static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; const char *who, *why, *what, *mode; _cleanup_free_ char *id = NULL; _cleanup_close_ int fifo_fd = -1; @@ -1774,11 +1803,15 @@ static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata, if (r == 0) return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ - r = sd_bus_get_owner_uid(m->bus, sd_bus_message_get_sender(message), &uid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_uid(creds, &uid); if (r < 0) return r; - r = sd_bus_get_owner_pid(m->bus, sd_bus_message_get_sender(message), &pid); + r = sd_bus_creds_get_pid(creds, &pid); if (r < 0) return r; diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index f274c0d639..76158e501b 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -266,6 +266,7 @@ int seat_object_find(sd_bus *bus, const char *path, const char *interface, void assert(m); if (streq(path, "/org/freedesktop/login1/seat/self")) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; sd_bus_message *message; Session *session; pid_t pid; @@ -274,9 +275,13 @@ int seat_object_find(sd_bus *bus, const char *path, const char *interface, void if (!message) return 0; - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); if (r < 0) - return 0; + return r; + + r = sd_bus_creds_get_pid(creds, &pid); + if (r < 0) + return r; r = manager_get_session_by_pid(m, pid, &session); if (r <= 0) diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index bb62b26ce4..4bbe75e428 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -225,6 +225,7 @@ static int method_lock(sd_bus *bus, sd_bus_message *message, void *userdata, sd_ } static int method_set_idle_hint(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; Session *s = userdata; uid_t uid; int r, b; @@ -237,7 +238,11 @@ static int method_set_idle_hint(sd_bus *bus, sd_bus_message *message, void *user if (r < 0) return r; - r = sd_bus_get_owner_uid(bus, sd_bus_message_get_sender(message), &uid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_UID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_uid(creds, &uid); if (r < 0) return r; @@ -283,6 +288,7 @@ static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_ } static int method_take_control(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; Session *s = userdata; int r, force; uid_t uid; @@ -295,7 +301,11 @@ static int method_take_control(sd_bus *bus, sd_bus_message *message, void *userd if (r < 0) return r; - r = sd_bus_get_owner_uid(bus, sd_bus_message_get_sender(message), &uid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_UID, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_uid(creds, &uid); if (r < 0) return r; @@ -477,6 +487,7 @@ int session_object_find(sd_bus *bus, const char *path, const char *interface, vo assert(m); if (streq(path, "/org/freedesktop/login1/session/self")) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; sd_bus_message *message; pid_t pid; @@ -484,9 +495,13 @@ int session_object_find(sd_bus *bus, const char *path, const char *interface, vo if (!message) return 0; - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); if (r < 0) - return 0; + return r; + + r = sd_bus_creds_get_pid(creds, &pid); + if (r < 0) + return r; r = manager_get_session_by_pid(m, pid, &session); if (r <= 0) diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 6a77e33eea..b034515203 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -247,6 +247,7 @@ int user_object_find(sd_bus *bus, const char *path, const char *interface, void assert(m); if (streq(path, "/org/freedesktop/login1/user/self")) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; sd_bus_message *message; pid_t pid; @@ -254,9 +255,13 @@ int user_object_find(sd_bus *bus, const char *path, const char *interface, void if (!message) return 0; - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); if (r < 0) - return 0; + return r; + + r = sd_bus_creds_get_pid(creds, &pid); + if (r < 0) + return r; r = manager_get_user_by_pid(m, pid, &user); if (r <= 0) |