Use plugin specific compiler includes for AT chat library
[connman] / plugins / polkit.c
index 7bed0b1..16dd9d5 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
 #include <glib.h>
 #include <polkit-dbus/polkit-dbus.h>
 
+#define CONNMAN_API_SUBJECT_TO_CHANGE
 #include <connman/plugin.h>
 #include <connman/security.h>
+#include <connman/dbus.h>
 #include <connman/log.h>
 
-#define ACTION "org.moblin.connman.modify"
+#define ACTION_MODIFY "org.moblin.connman.modify"
+#define ACTION_SECRET "org.moblin.connman.secret"
 
 static DBusConnection *connection;
 static PolKitContext *polkit_context;
 
-static int polkit_authorize(const char *sender)
+static int polkit_authorize(const char *sender,
+                               enum connman_security_privilege privilege)
 {
        DBusError error;
        PolKitCaller *caller;
        PolKitAction *action;
        PolKitResult result;
+       const char *id = NULL;
 
        DBG("sender %s", sender);
 
+       switch (privilege) {
+       case CONNMAN_SECURITY_PRIVILEGE_PUBLIC:
+               return 0;
+       case CONNMAN_SECURITY_PRIVILEGE_MODIFY:
+               id = ACTION_MODIFY;
+               break;
+       case CONNMAN_SECURITY_PRIVILEGE_SECRET:
+               id = ACTION_SECRET;
+               break;
+       }
+
        dbus_error_init(&error);
 
        caller = polkit_caller_new_from_dbus_name(connection, sender, &error);
@@ -59,7 +75,7 @@ static int polkit_authorize(const char *sender)
        }
 
        action = polkit_action_new();
-       polkit_action_set_action_id(action, ACTION);
+       polkit_action_set_action_id(action, id);
 
        result = polkit_context_is_caller_authorized(polkit_context,
                                                action, caller, TRUE, NULL);
@@ -124,7 +140,7 @@ static int polkit_init(void)
 {
        int err;
 
-       connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+       connection = connman_dbus_get_connection();
        if (connection == NULL)
                return -EIO;
 
@@ -159,5 +175,5 @@ static void polkit_exit(void)
        dbus_connection_unref(connection);
 }
 
-CONNMAN_PLUGIN_DEFINE("polkit", "PolicyKit authorization plugin", VERSION,
-                                               polkit_init, polkit_exit)
+CONNMAN_PLUGIN_DEFINE(polkit, "PolicyKit authorization plugin", VERSION,
+               CONNMAN_PLUGIN_PRIORITY_DEFAULT, polkit_init, polkit_exit)