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.
This commit is contained in:
David Herrmann
2015-01-17 18:27:23 +01:00
parent c4bc1a8434
commit a80a3a7543
+17
View File
@@ -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;