summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-bus/bus-creds.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-23 19:43:40 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-14 08:12:58 +0100
commit62a9d858d1c8103f9bc6d89bb69ab21c14acd4c7 (patch)
tree9833a2163dca58e94f1f07afc56a704fb16a095c /src/libelogind/sd-bus/bus-creds.c
parent3d3b472432f270299c6d5ddc58443eee852b0550 (diff)
sd-bus: add controlling tty field to sd_creds object
This is useful to print wall messages from logind with the right client tty. (to be added in a later patch)
Diffstat (limited to 'src/libelogind/sd-bus/bus-creds.c')
-rw-r--r--src/libelogind/sd-bus/bus-creds.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libelogind/sd-bus/bus-creds.c b/src/libelogind/sd-bus/bus-creds.c
index 9d519c473..1ac12a7bf 100644
--- a/src/libelogind/sd-bus/bus-creds.c
+++ b/src/libelogind/sd-bus/bus-creds.c
@@ -24,6 +24,8 @@
#include "util.h"
#include "formats-util.h"
+#include "process-util.h"
+#include "terminal-util.h"
#include "capability.h"
#include "cgroup-util.h"
#include "fileio.h"
@@ -53,6 +55,7 @@ void bus_creds_done(sd_bus_creds *c) {
free(c->slice);
free(c->unescaped_description);
free(c->supplementary_gids);
+ free(c->tty);
free(c->well_known_names); /* note that this is an strv, but
* we only free the array, not the
@@ -509,6 +512,17 @@ _public_ int sd_bus_creds_get_audit_login_uid(sd_bus_creds *c, uid_t *uid) {
return 0;
}
+_public_ int sd_bus_creds_get_tty(sd_bus_creds *c, const char **ret) {
+ assert_return(c, -EINVAL);
+ assert_return(ret, -EINVAL);
+
+ if (!(c->mask & SD_BUS_CREDS_TTY))
+ return -ENODATA;
+
+ *ret = c->tty;
+ return 0;
+}
+
_public_ int sd_bus_creds_get_unique_name(sd_bus_creds *c, const char **unique_name) {
assert_return(c, -EINVAL);
assert_return(unique_name, -EINVAL);
@@ -974,6 +988,15 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
c->mask |= SD_BUS_CREDS_AUDIT_LOGIN_UID;
}
+ if (missing & SD_BUS_CREDS_TTY) {
+ r = get_ctty(pid, NULL, &c->tty);
+ if (r < 0) {
+ if (r != -EPERM && r != -EACCES && r != -ENOENT)
+ return r;
+ } else
+ c->mask |= SD_BUS_CREDS_TTY;
+ }
+
c->augmented = missing & c->mask;
return 0;
@@ -1132,6 +1155,16 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret)
n->mask |= SD_BUS_CREDS_AUDIT_LOGIN_UID;
}
+ if (c->mask & mask & SD_BUS_CREDS_TTY) {
+ if (c->tty) {
+ n->tty = strdup(c->tty);
+ if (!n->tty)
+ return -ENOMEM;
+ } else
+ n->tty = NULL;
+ n->mask |= SD_BUS_CREDS_TTY;
+ }
+
if (c->mask & mask & SD_BUS_CREDS_UNIQUE_NAME) {
n->unique_name = strdup(c->unique_name);
if (!n->unique_name)