aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-02-27 11:06:16 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:15 +0100
commit6a655f5daf63dd3f74b353a269e49d9496ad8cf2 (patch)
tree16c950b5d726c4146fe73aa36f666c3ce7a46c62
parentf2440e9ab2b104d8a9eddbaa5a516461d9fcdf31 (diff)
iface-modem-simple: include policy authorization checks
-rw-r--r--src/mm-iface-modem-simple.c109
1 files changed, 75 insertions, 34 deletions
diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c
index 5d5afc15..0a6a5351 100644
--- a/src/mm-iface-modem-simple.c
+++ b/src/mm-iface-modem-simple.c
@@ -186,6 +186,7 @@ typedef struct {
ConnectionStep step;
/* Expected input properties */
+ GVariant *dictionary;
MMCommonConnectProperties *properties;
/* Results to set */
@@ -195,8 +196,10 @@ typedef struct {
static void
connection_context_free (ConnectionContext *ctx)
{
+ g_variant_unref (ctx->dictionary);
+ if (ctx->properties)
+ g_object_unref (ctx->properties);
g_object_unref (ctx->bearer);
- g_object_unref (ctx->properties);
g_object_unref (ctx->skeleton);
g_object_unref (ctx->invocation);
g_object_unref (ctx->self);
@@ -559,32 +562,50 @@ connection_step (ConnectionContext *ctx)
g_assert_not_reached ();
}
+static void
+connect_auth_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ ConnectionContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_authorize_finish (self, res, &error)) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ connection_context_free (ctx);
+ return;
+ }
+
+ ctx->properties = mm_common_connect_properties_new_from_dictionary (ctx->dictionary, &error);
+ if (!ctx->properties) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ connection_context_free (ctx);
+ return;
+ }
+
+ /* Start */
+ ctx->step = CONNECTION_STEP_FIRST;
+ connection_step (ctx);
+}
+
static gboolean
handle_connect (MmGdbusModemSimple *skeleton,
GDBusMethodInvocation *invocation,
GVariant *dictionary,
MMIfaceModemSimple *self)
{
- GError *error = NULL;
- MMCommonConnectProperties *properties;
ConnectionContext *ctx;
- properties = mm_common_connect_properties_new_from_dictionary (dictionary, &error);
- if (!properties) {
- g_dbus_method_invocation_take_error (invocation, error);
- return TRUE;
- }
-
ctx = g_new0 (ConnectionContext, 1);
ctx->skeleton = g_object_ref (skeleton);
ctx->invocation = g_object_ref (invocation);
ctx->self = g_object_ref (self);
- ctx->step = CONNECTION_STEP_FIRST;
- ctx->properties = properties;
-
- /* Start */
- connection_step (ctx);
+ ctx->dictionary = g_variant_ref (dictionary);
+ mm_base_modem_authorize (MM_BASE_MODEM (self),
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ (GAsyncReadyCallback)connect_auth_ready,
+ ctx);
return TRUE;
}
@@ -661,30 +682,23 @@ build_connected_bearer_list (MMBearer *bearer,
ctx->bearers = g_list_prepend (ctx->bearers, g_object_ref (bearer));
}
-static gboolean
-handle_disconnect (MmGdbusModemSimple *skeleton,
- GDBusMethodInvocation *invocation,
- const gchar *bearer_path,
- MMIfaceModemSimple *self)
+static void
+disconnect_auth_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ DisconnectionContext *ctx)
{
+ GError *error = NULL;
MMBearerList *list = NULL;
- DisconnectionContext *ctx;
+
+ if (!mm_base_modem_authorize_finish (self, res, &error)) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ disconnection_context_free (ctx);
+ return;
+ }
g_object_get (self,
MM_IFACE_MODEM_BEARER_LIST, &list,
NULL);
-
- ctx = g_new0 (DisconnectionContext, 1);
- ctx->skeleton = g_object_ref (skeleton);
- ctx->self = g_object_ref (self);
- ctx->invocation = g_object_ref (invocation);
-
- if (bearer_path &&
- bearer_path[0] == '/' &&
- bearer_path[1]) {
- ctx->bearer_path = g_strdup (ctx->bearer_path);
- }
-
mm_bearer_list_foreach (list,
(MMBearerListForeachFunc)build_connected_bearer_list,
ctx);
@@ -693,16 +707,43 @@ handle_disconnect (MmGdbusModemSimple *skeleton,
if (ctx->bearer_path &&
!ctx->bearers) {
g_dbus_method_invocation_return_error (
- invocation,
+ ctx->invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't disconnect bearer '%s': not found",
ctx->bearer_path);
disconnection_context_free (ctx);
- return TRUE;
+ return;
}
+ /* Go on disconnecting bearers */
disconnect_next_bearer (ctx);
+}
+
+static gboolean
+handle_disconnect (MmGdbusModemSimple *skeleton,
+ GDBusMethodInvocation *invocation,
+ const gchar *bearer_path,
+ MMIfaceModemSimple *self)
+{
+ DisconnectionContext *ctx;
+
+ ctx = g_new0 (DisconnectionContext, 1);
+ ctx->skeleton = g_object_ref (skeleton);
+ ctx->self = g_object_ref (self);
+ ctx->invocation = g_object_ref (invocation);
+
+ if (bearer_path &&
+ bearer_path[0] == '/' &&
+ bearer_path[1]) {
+ ctx->bearer_path = g_strdup (ctx->bearer_path);
+ }
+
+ mm_base_modem_authorize (MM_BASE_MODEM (self),
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ (GAsyncReadyCallback)disconnect_auth_ready,
+ ctx);
return TRUE;
}