[systemd-commits] 2 commits - Makefile.am src/bus-proxyd test/bus-policy
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Nov 26 12:16:05 PST 2014
Makefile.am | 4 +-
src/bus-proxyd/bus-policy.c | 6 ++-
src/bus-proxyd/test-bus-policy.c | 31 +++++++++++++++++++
test/bus-policy/many-rules.conf | 61 +++++++++++++++++++++++++++++++++++++++
test/bus-policy/test.conf | 20 ++++++++++++
5 files changed, 119 insertions(+), 3 deletions(-)
New commits:
commit 278ebf8d26f0ebf9d63d8aa1b91a2adbdd8aa4e0
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Nov 26 21:15:39 2014 +0100
bus-policy: actually test messages against the newly added test.conf
diff --git a/src/bus-proxyd/bus-policy.c b/src/bus-proxyd/bus-policy.c
index ff6a3e4..d543bf9 100644
--- a/src/bus-proxyd/bus-policy.c
+++ b/src/bus-proxyd/bus-policy.c
@@ -627,7 +627,7 @@ static int check_policy_item(PolicyItem *i, const struct policy_check_filter *fi
if (i->name && !streq_ptr(i->name, filter->name))
break;
- if ((i->message_type != _POLICY_ITEM_CLASS_UNSET) && (i->message_type != filter->message_type))
+ if ((i->message_type != 0) && (i->message_type != filter->message_type))
break;
if (i->path && !streq_ptr(i->path, filter->path))
@@ -688,7 +688,7 @@ static int check_policy_items(PolicyItem *items, const struct policy_check_filte
* and the order of rules in policy definitions matters */
LIST_FOREACH(items, i, items) {
if (i->class != filter->class &&
- IN_SET(i->class, POLICY_ITEM_OWN, POLICY_ITEM_OWN_PREFIX) != IN_SET(filter->class, POLICY_ITEM_OWN, POLICY_ITEM_OWN_PREFIX))
+ !(i->class == POLICY_ITEM_OWN_PREFIX && filter->class == POLICY_ITEM_OWN))
continue;
r = check_policy_item(i, filter);
@@ -707,6 +707,8 @@ static int policy_check(Policy *p, const struct policy_check_filter *filter) {
assert(p);
assert(filter);
+ assert(IN_SET(filter->class, POLICY_ITEM_SEND, POLICY_ITEM_RECV, POLICY_ITEM_OWN, POLICY_ITEM_USER, POLICY_ITEM_GROUP));
+
/*
* The policy check is implemented by the following logic:
*
diff --git a/src/bus-proxyd/test-bus-policy.c b/src/bus-proxyd/test-bus-policy.c
index 3140e08..1c1d1ef 100644
--- a/src/bus-proxyd/test-bus-policy.c
+++ b/src/bus-proxyd/test-bus-policy.c
@@ -157,6 +157,25 @@ int main(int argc, char *argv[]) {
assert_se(test_policy_load(&p, "test.conf") >= 0);
policy_dump(&p);
+
+ ucred.uid = 0;
+ assert_se(policy_check_own(&p, &ucred, "org.foo.FooService") == true);
+ assert_se(policy_check_own(&p, &ucred, "org.foo.FooService2") == false);
+ assert_se(policy_check_send(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.test.test1", "/an/object/path", "org.test.int2", "Member") == false);
+ assert_se(policy_check_send(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.test.test1", "/an/object/path", "org.foo.FooBroadcastInterface", "Member") == true);
+ assert_se(policy_check_recv(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.foo.FooService", "/an/object/path", "org.foo.FooBroadcastInterface", "Member") == true);
+ assert_se(policy_check_recv(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.foo.FooService", "/an/object/path", "org.foo.FooBroadcastInterface2", "Member") == false);
+ assert_se(policy_check_recv(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.foo.FooService2", "/an/object/path", "org.foo.FooBroadcastInterface", "Member") == false);
+
+ ucred.uid = 100;
+ assert_se(policy_check_own(&p, &ucred, "org.foo.FooService") == false);
+ assert_se(policy_check_own(&p, &ucred, "org.foo.FooService2") == false);
+ assert_se(policy_check_send(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.test.test1", "/an/object/path", "org.test.int2", "Member") == false);
+ assert_se(policy_check_send(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.test.test1", "/an/object/path", "org.foo.FooBroadcastInterface", "Member") == false);
+ assert_se(policy_check_recv(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.foo.FooService", "/an/object/path", "org.foo.FooBroadcastInterface", "Member") == true);
+ assert_se(policy_check_recv(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.foo.FooService", "/an/object/path", "org.foo.FooBroadcastInterface2", "Member") == false);
+ assert_se(policy_check_recv(&p, &ucred, SD_BUS_MESSAGE_METHOD_CALL, "org.foo.FooService2", "/an/object/path", "org.foo.FooBroadcastInterface", "Member") == false);
+
policy_free(&p);
return EXIT_SUCCESS;
commit 55e189007c707fb827b8b287903c258de234bd12
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Nov 26 20:58:34 2014 +0100
bus-policy: also add in other bus policy tests from dbus1
dbus1 only checks if these files parse correctly so let's do the same for now.
diff --git a/Makefile.am b/Makefile.am
index 5545aa1..ddd0df1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1384,7 +1384,9 @@ EXTRA_DIST += \
test/bus-policy/methods.conf \
test/bus-policy/ownerships.conf \
test/bus-policy/signals.conf \
- test/bus-policy/check-own-rules.conf
+ test/bus-policy/check-own-rules.conf \
+ test/bus-policy/many-rules.conf \
+ test/bus-policy/test.conf
EXTRA_DIST += \
diff --git a/src/bus-proxyd/test-bus-policy.c b/src/bus-proxyd/test-bus-policy.c
index a4b7b6a..3140e08 100644
--- a/src/bus-proxyd/test-bus-policy.c
+++ b/src/bus-proxyd/test-bus-policy.c
@@ -147,5 +147,17 @@ int main(int argc, char *argv[]) {
policy_free(&p);
+ /* dbus1 test file: many rules */
+
+ assert_se(test_policy_load(&p, "many-rules.conf") >= 0);
+ policy_dump(&p);
+ policy_free(&p);
+
+ /* dbus1 test file: generic test */
+
+ assert_se(test_policy_load(&p, "test.conf") >= 0);
+ policy_dump(&p);
+ policy_free(&p);
+
return EXIT_SUCCESS;
}
diff --git a/test/bus-policy/many-rules.conf b/test/bus-policy/many-rules.conf
new file mode 100644
index 0000000..70dd538
--- /dev/null
+++ b/test/bus-policy/many-rules.conf
@@ -0,0 +1,61 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <user>mybususer</user>
+ <listen>unix:path=/foo/bar</listen>
+ <listen>tcp:port=1234</listen>
+ <includedir>basic.d</includedir>
+ <standard_session_servicedirs />
+ <servicedir>/usr/share/foo</servicedir>
+ <include ignore_missing="yes">nonexistent.conf</include>
+ <policy context="default">
+ <allow user="*"/>
+ <deny send_interface="org.freedesktop.System" send_member="Reboot"/>
+ <deny receive_interface="org.freedesktop.System" receive_member="Reboot"/>
+ <deny send_path="/foo/bar/SystemObjectThing" send_member="Reboot"/>
+ <deny own="org.freedesktop.System"/>
+ <deny own_prefix="org.freedesktop.ManySystems"/>
+ <deny send_destination="org.freedesktop.System"/>
+ <deny receive_sender="org.freedesktop.System"/>
+ <deny user="root"/>
+ <deny group="bin"/>
+ <allow send_type="error"/>
+ <allow send_type="method_call"/>
+ <allow send_type="method_return"/>
+ <allow send_type="signal"/>
+ <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo"/>
+ <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo" send_type="method_call"/>
+ </policy>
+
+ <policy context="mandatory">
+ <allow user="*"/>
+ <deny send_interface="org.freedesktop.System" send_member="Reboot"/>
+ <deny receive_interface="org.freedesktop.System" receive_member="Reboot"/>
+ <deny send_path="/foo/bar/SystemObjectThing" send_member="Reboot"/>
+ <deny own="org.freedesktop.System"/>
+ <deny own_prefix="org.freedesktop.ManySystems"/>
+ <deny send_destination="org.freedesktop.System"/>
+ <deny receive_sender="org.freedesktop.System"/>
+ <deny user="root"/>
+ <deny group="bin"/>
+ <allow send_type="error"/>
+ <allow send_type="method_call"/>
+ <allow send_type="method_return"/>
+ <allow send_type="signal"/>
+ <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo"/>
+ <deny send_destination="org.freedesktop.Bar" send_interface="org.freedesktop.Foo" send_type="method_call"/>
+ </policy>
+
+ <limit name="max_incoming_bytes">5000</limit>
+ <limit name="max_outgoing_bytes">5000</limit>
+ <limit name="max_message_size">300</limit>
+ <limit name="service_start_timeout">5000</limit>
+ <limit name="auth_timeout">6000</limit>
+ <limit name="max_completed_connections">50</limit>
+ <limit name="max_incomplete_connections">80</limit>
+ <limit name="max_connections_per_user">64</limit>
+ <limit name="max_pending_service_starts">64</limit>
+ <limit name="max_names_per_connection">256</limit>
+ <limit name="max_match_rules_per_connection">512</limit>
+
+</busconfig>
diff --git a/test/bus-policy/test.conf b/test/bus-policy/test.conf
new file mode 100644
index 0000000..ee6afcd
--- /dev/null
+++ b/test/bus-policy/test.conf
@@ -0,0 +1,20 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <!-- The following demonstrates how to punch holes in a default deny-all
+ policy so that a particular user can own a service, and other
+ connections can get messages from it -->
+
+ <!-- Only root can own the FooService service, and
+ this user can only send the one kind of message -->
+ <policy user="root">
+ <allow own="org.foo.FooService"/>
+ <allow send_interface="org.foo.FooBroadcastInterface"/>
+ </policy>
+
+ <!-- Allow any connection to receive the message, but
+ only if the message is sent by the owner of FooService -->
+ <policy context="default">
+ <allow receive_interface="org.foo.FooBroadcastInterface" receive_sender="org.foo.FooService"/>
+ </policy>
+</busconfig>
More information about the systemd-commits
mailing list