summaryrefslogtreecommitdiff
path: root/src/bus-proxyd
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-01-17 18:23:33 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2015-01-17 18:27:23 +0100
commita80a3a7543975d1268692937d9d1884c6ee6e301 (patch)
tree9afccd95f193b80186f861005f21ae04ad919f94 /src/bus-proxyd
parentc4bc1a8434f2a34840ea6f63064fa998ecfae738 (diff)
bus-proxy: drop privileges if run as root
We cannot use "User=" in unit-files if we want to retain privileges. So make bus-proxy.c explicitly drop privileges. However, only do that if we're root, as there is no need to drop it on the user-bus.
Diffstat (limited to 'src/bus-proxyd')
-rw-r--r--src/bus-proxyd/bus-proxyd.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 72e11467b..3cf35f408 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -292,12 +292,29 @@ static int parse_argv(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
+ const char *user = "systemd-bus-proxy";
int r, accept_fd;
+ uid_t uid;
+ gid_t gid;
log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
log_parse_environment();
log_open();
+ if (geteuid() == 0) {
+ r = get_user_creds(&user, &uid, &gid, NULL, NULL);
+ if (r < 0) {
+ log_error_errno(r, "Cannot resolve user name %s: %m", user);
+ goto finish;
+ }
+
+ r = drop_privileges(uid, gid, 1ULL << CAP_IPC_OWNER);
+ if (r < 0) {
+ log_error_errno(r, "Cannot drop privileges: %m");
+ goto finish;
+ }
+ }
+
r = parse_argv(argc, argv);
if (r <= 0)
goto finish;