summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2014-10-23 13:06:38 +0200
committerDaniel Mack <daniel@zonque.org>2014-11-11 14:14:01 +0100
commit5bb24cccbce846c0d77e71b70a3be7f4b2ba6c0e (patch)
treeae9194d2e03acb84f699f63900a44792054ea357 /src
parent2a2be74654f0511220cf9a8a72f60ab5705abb87 (diff)
bus-proxyd: make policy checks optional
Retrieve the bus owner creds, and when the uid matches the current user's uid and is non-null, don't check the bus policy.
Diffstat (limited to 'src')
-rw-r--r--src/bus-proxyd/bus-proxyd.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 3fc341eaed..c5aeaacf42 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -475,6 +475,9 @@ static int process_policy(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic
assert(b);
assert(m);
+ if (!policy)
+ return 0;
+
if (b->is_kernel) {
/* The message came from the kernel, and is sent to our legacy client. */
@@ -849,7 +852,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic
if (r < 0)
return synthetic_reply_method_errno(m, r, NULL);
- if (!policy_check_own(policy, ucred, name))
+ if (policy && !policy_check_own(policy, ucred, name))
return synthetic_reply_method_errno(m, -EPERM, NULL);
if (!service_name_is_valid(name))
@@ -1022,7 +1025,7 @@ static int process_hello(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *policy
return -EIO;
}
- if (!policy_check_hello(policy, ucred)) {
+ if (policy && !policy_check_hello(policy, ucred)) {
log_error("Policy denied HELLO");
return -EPERM;
}
@@ -1133,6 +1136,7 @@ static int patch_sender(sd_bus *a, sd_bus_message *m) {
int main(int argc, char *argv[]) {
+ _cleanup_bus_creds_unref_ sd_bus_creds *bus_creds = NULL;
_cleanup_bus_close_unref_ sd_bus *a = NULL, *b = NULL;
sd_id128_t server_id;
int r, in_fd, out_fd;
@@ -1251,6 +1255,12 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ r = sd_bus_get_owner_creds(a, SD_BUS_CREDS_UID, &bus_creds);
+ if (r < 0) {
+ log_error("Failed to get bus creds: %s", strerror(-r));
+ goto finish;
+ }
+
r = sd_bus_new(&b);
if (r < 0) {
log_error("Failed to allocate bus: %s", strerror(-r));
@@ -1410,13 +1420,21 @@ int main(int argc, char *argv[]) {
}
if (m) {
+ Policy *p = NULL;
+ uid_t uid;
+
+ assert_se(sd_bus_creds_get_uid(bus_creds, &uid) == 0);
+
+ if (uid == 0 || uid != ucred.uid)
+ p = &policy;
+
/* We officially got EOF, let's quit */
if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected")) {
r = 0;
goto finish;
}
- k = process_hello(a, b, m, &policy, &ucred, &got_hello);
+ k = process_hello(a, b, m, p, &ucred, &got_hello);
if (k < 0) {
r = k;
log_error("Failed to process HELLO: %s", strerror(-r));
@@ -1426,7 +1444,7 @@ int main(int argc, char *argv[]) {
if (k > 0)
r = k;
else {
- k = process_driver(a, b, m, &policy, &ucred);
+ k = process_driver(a, b, m, p, &ucred);
if (k < 0) {
r = k;
log_error("Failed to process driver calls: %s", strerror(-r));
@@ -1448,6 +1466,9 @@ int main(int argc, char *argv[]) {
if (k == -ECONNRESET)
r = 0;
else {
+
+ k = process_policy(a, b, m, p, &ucred);
+ if (k < 0) {
r = k;
log_error("Failed to send message: %s", strerror(-r));
}