[rygel/wip/acl: 29/30] Add DBus ACL provider
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/acl: 29/30] Add DBus ACL provider
- Date: Sun, 1 Jun 2014 16:25:18 +0000 (UTC)
commit a8ee372d365b96e82e89a4862678713e7a0e08f5
Author: Jens Georg <mail jensge org>
Date: Sun Jun 1 17:58:46 2014 +0200
Add DBus ACL provider
Signed-off-by: Jens Georg <mail jensge org>
src/rygel/rygel-acl.vala | 74 ++++++++++++++++++++++++++++-----
src/ui/Makefile.am | 1 +
src/ui/rygel-acl-provider.vala | 47 +++++++++++++++++++++
src/ui/rygel-preferences-dialog.vala | 3 +
tests/Makefile.am | 2 +
5 files changed, 115 insertions(+), 12 deletions(-)
---
diff --git a/src/rygel/rygel-acl.vala b/src/rygel/rygel-acl.vala
index 28b4a24..f1c294f 100644
--- a/src/rygel/rygel-acl.vala
+++ b/src/rygel/rygel-acl.vala
@@ -21,32 +21,82 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+[DBus (name = "org.gnome.Rygel1.AclProvider1")]
+public interface Rygel.IAclProvider : Object {
+ public abstract async bool is_allowed (GLib.HashTable<string, string> device,
+ GLib.HashTable<string, string> service,
+ string path,
+ string address,
+ string? agent)
+ throws DBusError, IOError;
+}
+
internal class Rygel.Acl : GLib.Object, GUPnP.Acl
{
- public bool can_sync () { return true; }
+ private Rygel.IAclProvider provider;
+
+ public Acl () {
+ Bus.watch_name (BusType.SESSION,
+ "org.gnome.Rygel1.AclProvider1",
+ BusNameWatcherFlags.AUTO_START,
+ this.on_name_appeared,
+ this.on_name_vanished);
+ }
+
+ public bool can_sync () { return false; }
public bool is_allowed (GUPnP.Device? device,
GUPnP.Service? service,
string path,
string address,
- string agent) {
- message ("%s at %s is trying to access %s/%s (%s)",
- agent,
- address,
- device == null ? "(unknown)" : device.get_friendly_name (),
- service == null ? "(unknown)" : service.get_id (),
- path);
-
- return true;
+ string? agent) {
+ assert_not_reached ();
}
public async bool is_allowed_async (GUPnP.Device? device,
GUPnP.Service? service,
string path,
string address,
- string agent,
+ string? agent,
GLib.Cancellable? cancellable)
throws GLib.Error {
- assert_not_reached ();
+ if (provider == null) {
+ message ("No external provider found, denying access…");
+
+ return false;
+ }
+
+ try {
+ var allowed = yield provider.is_allowed (new HashTable<string,
+ string> (null, null),
+ new HashTable<string,
+ string> (null, null),
+ path,
+ address,
+ agent);
+ return allowed;
+ } catch (Error error) {
+ message ("=> Error: %s", error.message);
+ }
+
+ return false;
+ }
+
+ private void on_name_appeared (DBusConnection connection,
+ string name,
+ string name_owner) {
+ message ("Found ACL provider %s (%s), creating object",
+ name, name_owner);
+ try {
+ this.provider = Bus.get_proxy_sync (BusType.SESSION,
+ name,
+ "/org/gnome/Rygel1/AclProvider1");
+ } catch (Error error) {
+ message ("Error creating proxy: %s", error.message);
+ }
+ }
+
+ private void on_name_vanished (DBusConnection connection, string name) {
+ this.provider = null;
}
}
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 2fb7440..a7980ca 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -8,6 +8,7 @@ rygel_preferences_SOURCES = \
rygel-media-pref-section.vala \
rygel-writable-user-config.vala \
rygel-network-pref-section.vala \
+ rygel-acl-provider.vala \
rygel-user-config.vala
rygel_preferences_VALAFLAGS = \
diff --git a/src/ui/rygel-acl-provider.vala b/src/ui/rygel-acl-provider.vala
new file mode 100644
index 0000000..3ce9e42
--- /dev/null
+++ b/src/ui/rygel-acl-provider.vala
@@ -0,0 +1,47 @@
+[DBus (name = "org.gnome.Rygel1.AclProvider1")]
+public interface Rygel.IAclProvider : Object {
+ public abstract async bool is_allowed (GLib.HashTable<string, string> device,
+ GLib.HashTable<string, string> service,
+ string path,
+ string address,
+ string? agent)
+ throws DBusError, IOError;
+}
+
+public class Rygel.AclProvider : IAclProvider, Object {
+ public async bool is_allowed (GLib.HashTable<string, string> device,
+ GLib.HashTable<string, string> service,
+ string path,
+ string address,
+ string? agent)
+ throws DBusError, IOError {
+ Idle.add (() => { is_allowed.callback (); return false; });
+ yield;
+
+ message ("=======> Request");
+
+ if (device.size () == 0 || service.size () == 0) {
+
+ return true;
+ }
+
+ return true;
+ }
+
+ private void on_bus_aquired (DBusConnection connection) {
+ try {
+ connection.register_object ("/org/gnome/Rygel1/AclProvider1",
+ this as IAclProvider);
+ } catch (IOError error) {
+ warning ("Failed to register service");
+ }
+ }
+
+ public void register () {
+ Bus.own_name (BusType.SESSION, "org.gnome.Rygel1.AclProvider1",
+ BusNameOwnerFlags.NONE,
+ on_bus_aquired,
+ () => {},
+ () => { warning ("Could not aquire bus name"); });
+ }
+}
diff --git a/src/ui/rygel-preferences-dialog.vala b/src/ui/rygel-preferences-dialog.vala
index 18cbfd9..3ff1894 100644
--- a/src/ui/rygel-preferences-dialog.vala
+++ b/src/ui/rygel-preferences-dialog.vala
@@ -88,6 +88,9 @@ public class Rygel.PreferencesDialog : GLib.Object {
MetaConfig.register_configuration (UserConfig.get_default ());
var dialog = new PreferencesDialog ();
+ var provider = new AclProvider ();
+ provider.register ();
+
dialog.run ();
} catch (Error err) {
error (_("Failed to create preferences dialog: %s"), err.message);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 38070c2..442d9e9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,7 @@
include $(top_srcdir)/common.am
+AUTOMAKE_OPTIONS = subdir-objects
+
check_PROGRAMS = rygel-http-item-uri-test \
rygel-http-response-test \
rygel-http-byte-seek-test \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]