[rygel/wip/acl: 304/306] WIP



commit 166d2065202445557e548d47caf9d35eba8f3306
Author: Jens Georg <mail jensge org>
Date:   Tue Aug 19 21:20:06 2014 +0200

    WIP

 src/rygel/Makefile.am       |   22 ++++++++++++
 src/rygel/acl-provider.vala |   75 +++++++++++++++++++++++++++++++++++++++++++
 src/rygel/acl-store.vala    |    4 ++
 3 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index a912eec..594a6ab 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -1,6 +1,7 @@
 include $(top_srcdir)/common.am
 
 bin_PROGRAMS = rygel
+libexec_PROGRAMS = rygel-acl-provider
 
 rygel_SOURCES = \
        rygel-acl.vala \
@@ -27,6 +28,27 @@ rygel_LDADD = \
        $(RYGEL_DEPS_LIBS) \
        $(RYGEL_COMMON_LIBRYGEL_SERVER_LIBS)
 
+rygel_acl_provider_SOURCES = \
+       acl-provider.vala \
+       acl-store.vala
+
+rygel_acl_provider_VALAFLAGS = \
+       $(RYGEL_COMMON_LIBRYGEL_CORE_VALAFLAGS) \
+       $(RYGEL_COMMON_VALAFLAGS)
+
+rygel_acl_provider_CFLAGS = \
+       $(RYGEL_DEPS_CFLAGS) \
+       $(RYGEL_COMMON_LIBRYGEL_CORE_CFLAGS) \
+       -include config.h \
+       -DLOCALEDIR=\""$(datadir)/locale"\" \
+       -DG_LOG_DOMAIN='"RygelAcl"' \
+       -DSYS_CONFIG_DIR='"$(sysconfigdir)"'
+
+rygel_acl_provider_LDADD = \
+       $(RYGEL_DEPS_LIBS) \
+       $(RYGEL_COMMON_LIBRYGEL_CORE_LIBS)
+
+
 vapidir = $(VAPIDIR)
 vapi_DATA = $(VAPI_FILES) $(DEPS_FILES)
 
diff --git a/src/rygel/acl-provider.vala b/src/rygel/acl-provider.vala
new file mode 100644
index 0000000..8648c0a
--- /dev/null
+++ b/src/rygel/acl-provider.vala
@@ -0,0 +1,75 @@
+
+public class Rygel.AclProvider : DBusAclProvider, 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;
+
+
+        if (device.size () == 0 || service.size () == 0) {
+            message ("Nothing to decide on, passing true");
+
+            return true;
+        }
+
+        message ("%s from %s is trying to access %s. Allow?",
+                 agent, address, device["FriendlyName"]);
+
+        if (path.has_prefix ("/Event")) {
+            message ("Trying to subscribe to events of %s on %s",
+                     service["Type"], device["FriendlyName"]);
+        } else if (path.has_prefix ("/Control")) {
+            message ("Trying to access control of %s on %s",
+                     service["Type"], device["FriendlyName"]);
+        } else {
+            return true;
+        }
+
+        return true;
+    }
+
+    private void on_bus_aquired (DBusConnection connection) {
+        try {
+            debug ("Trying to register ourselves at path %s",
+                   DBusAclProvider.OBJECT_PATH);
+            connection.register_object (DBusAclProvider.OBJECT_PATH,
+                                        this as DBusAclProvider);
+            debug ("Success.");
+        } catch (IOError error) {
+            warning (_("Failed to register service: %s"), error.message);
+        }
+    }
+
+    public void register () {
+        debug ("Trying to aquire name %s on session DBus",
+               DBusAclProvider.SERVICE_NAME);
+        Bus.own_name (BusType.SESSION,
+                      DBusAclProvider.SERVICE_NAME,
+                      BusNameOwnerFlags.NONE,
+                      this.on_bus_aquired,
+                      () => {},
+                      () => { warning (_("Could not aquire bus name %s"),
+                                       DBusAclProvider.SERVICE_NAME);
+                      });
+    }
+
+    public int run () {
+        message (_("Rygel ACL Provider v%s starting."),
+                 BuildConfig.PACKAGE_VERSION);
+        MainLoop loop = new MainLoop ();
+        this.register ();
+        loop.run ();
+        message (_("Rygel ACL Provider done."));
+
+        return 0;
+    }
+
+    public static int main (string[] args) {
+        return new AclProvider().run();
+    }
+}
diff --git a/src/rygel/acl-store.vala b/src/rygel/acl-store.vala
new file mode 100644
index 0000000..6ad2ac2
--- /dev/null
+++ b/src/rygel/acl-store.vala
@@ -0,0 +1,4 @@
+internal class Rygel.AclStorage : Object {
+    public AclStorage () {
+    }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]