#include <unistd.h>
#include <string.h>
#include <errno.h>
-#include <sys/poll.h>
+#include <poll.h>
#include <sys/prctl.h>
#include <stddef.h>
#include <getopt.h>
typedef struct {
int fd;
SharedPolicy *policy;
+ uid_t bus_uid;
} ClientContext;
static ClientContext *client_context_free(ClientContext *c) {
if (!c)
return NULL;
- close(c->fd);
+ safe_close(c->fd);
free(c);
return NULL;
if (r < 0)
goto exit;
+ c->fd = -1;
+
/* set comm to "p$PIDu$UID" and suffix with '*' if truncated */
r = snprintf(comm, sizeof(comm), "p" PID_FMT "u" UID_FMT, p->local_creds.pid, p->local_creds.uid);
if (r >= (ssize_t)sizeof(comm))
if (r < 0)
goto exit;
- r = proxy_hello_policy(p, getuid());
+ r = proxy_hello_policy(p, c->bus_uid);
if (r < 0)
goto exit;
return NULL;
}
-static int loop_clients(int accept_fd) {
+static int loop_clients(int accept_fd, uid_t bus_uid) {
_cleanup_(shared_policy_freep) SharedPolicy *sp = NULL;
pthread_attr_t attr;
int r;
c->fd = fd;
c->policy = sp;
+ c->bus_uid = bus_uid;
r = pthread_create(&tid, &attr, run_client, c);
if (r < 0) {
int main(int argc, char *argv[]) {
const char *user = "systemd-bus-proxy";
int r, accept_fd;
- uid_t uid;
+ uid_t uid, bus_uid;
gid_t gid;
log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
log_parse_environment();
log_open();
+ bus_uid = getuid();
+
if (geteuid() == 0) {
r = get_user_creds(&user, &uid, &gid, NULL, NULL);
if (r < 0) {
goto finish;
}
- r = loop_clients(accept_fd);
+ r = loop_clients(accept_fd, bus_uid);
finish:
sd_notify(false,