core: implement optional PolicyKit-based authentication
This commit is contained in:
@@ -12,6 +12,13 @@
|
|||||||
The rest are restricted to root for security.
|
The rest are restricted to root for security.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<allow send_destination="org.freedesktop.ModemManager"
|
||||||
|
send_interface="org.freedesktop.ModemManager"
|
||||||
|
send_member="EnumerateDevices"/>
|
||||||
|
|
||||||
|
<allow send_destination="org.freedesktop.ModemManager"
|
||||||
|
send_interface="org.freedesktop.DBus.Properties"/>
|
||||||
|
|
||||||
<allow send_destination="org.freedesktop.ModemManager"
|
<allow send_destination="org.freedesktop.ModemManager"
|
||||||
send_interface="org.freedesktop.ModemManager.Modem"
|
send_interface="org.freedesktop.ModemManager.Modem"
|
||||||
send_member="GetInfo"/>
|
send_member="GetInfo"/>
|
||||||
|
@@ -33,15 +33,26 @@ if WITH_POLKIT
|
|||||||
modem_manager_LDADD += $(POLKIT_LIBS)
|
modem_manager_LDADD += $(POLKIT_LIBS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
modem_manager_SOURCES = \
|
auth_sources = \
|
||||||
main.c \
|
|
||||||
mm-callback-info.c \
|
|
||||||
mm-callback-info.h \
|
|
||||||
mm-auth-request.c \
|
mm-auth-request.c \
|
||||||
mm-auth-request.h \
|
mm-auth-request.h \
|
||||||
mm-auth-provider.h \
|
mm-auth-provider.h \
|
||||||
mm-auth-provider.c \
|
mm-auth-provider.c \
|
||||||
mm-auth-provider-factory.c \
|
mm-auth-provider-factory.c
|
||||||
|
|
||||||
|
if WITH_POLKIT
|
||||||
|
auth_sources += \
|
||||||
|
mm-auth-request-polkit.c \
|
||||||
|
mm-auth-request-polkit.h \
|
||||||
|
mm-auth-provider-polkit.c \
|
||||||
|
mm-auth-provider-polkit.h
|
||||||
|
endif
|
||||||
|
|
||||||
|
modem_manager_SOURCES = \
|
||||||
|
main.c \
|
||||||
|
mm-callback-info.c \
|
||||||
|
mm-callback-info.h \
|
||||||
|
$(auth_sources) \
|
||||||
mm-manager.c \
|
mm-manager.c \
|
||||||
mm-manager.h \
|
mm-manager.h \
|
||||||
mm-modem.c \
|
mm-modem.c \
|
||||||
@@ -78,14 +89,6 @@ modem_manager_SOURCES = \
|
|||||||
mm-properties-changed-signal.c \
|
mm-properties-changed-signal.c \
|
||||||
mm-properties-changed-signal.h
|
mm-properties-changed-signal.h
|
||||||
|
|
||||||
if WITH_POLKIT
|
|
||||||
modem_manager_SOURCES += \
|
|
||||||
mm-auth-request-polkit.c \
|
|
||||||
mm-auth-request-polkit.h \
|
|
||||||
mm-auth-provider-polkit.c \
|
|
||||||
mm-auth-provider-polkit.h
|
|
||||||
endif
|
|
||||||
|
|
||||||
mm-manager-glue.h: $(top_srcdir)/introspection/mm-manager.xml
|
mm-manager-glue.h: $(top_srcdir)/introspection/mm-manager.xml
|
||||||
dbus-binding-tool --prefix=mm_manager --mode=glib-server --output=$@ $<
|
dbus-binding-tool --prefix=mm_manager --mode=glib-server --output=$@ $<
|
||||||
|
|
||||||
|
153
src/mm-auth-provider-polkit.c
Normal file
153
src/mm-auth-provider-polkit.c
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <polkit/polkit.h>
|
||||||
|
|
||||||
|
#include "mm-auth-request-polkit.h"
|
||||||
|
#include "mm-auth-provider-polkit.h"
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (MMAuthProviderPolkit, mm_auth_provider_polkit, MM_TYPE_AUTH_PROVIDER)
|
||||||
|
|
||||||
|
#define MM_AUTH_PROVIDER_POLKIT_GET_PRIVATE(o) \
|
||||||
|
(G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_AUTH_PROVIDER_POLKIT, MMAuthProviderPolkitPrivate))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PolkitAuthority *authority;
|
||||||
|
guint auth_changed_id;
|
||||||
|
} MMAuthProviderPolkitPrivate;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROP_NAME = 1000,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
GObject *
|
||||||
|
mm_auth_provider_polkit_new (void)
|
||||||
|
{
|
||||||
|
return g_object_new (MM_TYPE_AUTH_PROVIDER_POLKIT, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
pk_authority_changed_cb (GObject *object, gpointer user_data)
|
||||||
|
{
|
||||||
|
/* Let clients know they should re-check their authorization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static MMAuthRequest *
|
||||||
|
real_create_request (MMAuthProvider *provider,
|
||||||
|
const char *authorization,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
MMAuthRequestCb callback,
|
||||||
|
gpointer callback_data,
|
||||||
|
GDestroyNotify notify)
|
||||||
|
{
|
||||||
|
MMAuthProviderPolkitPrivate *priv = MM_AUTH_PROVIDER_POLKIT_GET_PRIVATE (provider);
|
||||||
|
|
||||||
|
return (MMAuthRequest *) mm_auth_request_polkit_new (priv->authority,
|
||||||
|
authorization,
|
||||||
|
owner,
|
||||||
|
context,
|
||||||
|
callback,
|
||||||
|
callback_data,
|
||||||
|
notify);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
mm_auth_provider_polkit_init (MMAuthProviderPolkit *self)
|
||||||
|
{
|
||||||
|
MMAuthProviderPolkitPrivate *priv = MM_AUTH_PROVIDER_POLKIT_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
priv->authority = polkit_authority_get ();
|
||||||
|
if (priv->authority) {
|
||||||
|
priv->auth_changed_id = g_signal_connect (priv->authority,
|
||||||
|
"changed",
|
||||||
|
G_CALLBACK (pk_authority_changed_cb),
|
||||||
|
self);
|
||||||
|
} else
|
||||||
|
g_warning ("%s: failed to create PolicyKit authority.", __func__);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_NAME:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_NAME:
|
||||||
|
g_value_set_string (value, "polkit");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dispose (GObject *object)
|
||||||
|
{
|
||||||
|
MMAuthProviderPolkit *self = MM_AUTH_PROVIDER_POLKIT (object);
|
||||||
|
MMAuthProviderPolkitPrivate *priv = MM_AUTH_PROVIDER_POLKIT_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
if (priv->auth_changed_id) {
|
||||||
|
g_signal_handler_disconnect (priv->authority, priv->auth_changed_id);
|
||||||
|
priv->auth_changed_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (mm_auth_provider_polkit_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mm_auth_provider_polkit_class_init (MMAuthProviderPolkitClass *class)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
MMAuthProviderClass *ap_class = MM_AUTH_PROVIDER_CLASS (class);
|
||||||
|
|
||||||
|
mm_auth_provider_polkit_parent_class = g_type_class_peek_parent (class);
|
||||||
|
g_type_class_add_private (class, sizeof (MMAuthProviderPolkitPrivate));
|
||||||
|
|
||||||
|
/* Virtual methods */
|
||||||
|
object_class->set_property = set_property;
|
||||||
|
object_class->get_property = get_property;
|
||||||
|
object_class->dispose = dispose;
|
||||||
|
ap_class->create_request = real_create_request;
|
||||||
|
|
||||||
|
/* Properties */
|
||||||
|
g_object_class_override_property (object_class, PROP_NAME, MM_AUTH_PROVIDER_NAME);
|
||||||
|
}
|
||||||
|
|
43
src/mm-auth-provider-polkit.h
Normal file
43
src/mm-auth-provider-polkit.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MM_AUTH_PROVIDER_POLKIT_H
|
||||||
|
#define MM_AUTH_PROVIDER_POLKIT_H
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
|
||||||
|
#include "mm-auth-provider.h"
|
||||||
|
|
||||||
|
#define MM_TYPE_AUTH_PROVIDER_POLKIT (mm_auth_provider_polkit_get_type ())
|
||||||
|
#define MM_AUTH_PROVIDER_POLKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_AUTH_PROVIDER_POLKIT, MMAuthProviderPolkit))
|
||||||
|
#define MM_AUTH_PROVIDER_POLKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_AUTH_PROVIDER_POLKIT, MMAuthProviderPolkitClass))
|
||||||
|
#define MM_IS_AUTH_PROVIDER_POLKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_AUTH_PROVIDER_POLKIT))
|
||||||
|
#define MM_IS_AUTH_PROVIDER_POLKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_AUTH_PROVIDER_POLKIT))
|
||||||
|
#define MM_AUTH_PROVIDER_POLKIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_AUTH_PROVIDER_POLKIT, MMAuthProviderPolkitClass))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMAuthProvider parent;
|
||||||
|
} MMAuthProviderPolkit;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMAuthProviderClass parent;
|
||||||
|
} MMAuthProviderPolkitClass;
|
||||||
|
|
||||||
|
GType mm_auth_provider_polkit_get_type (void);
|
||||||
|
|
||||||
|
GObject *mm_auth_provider_polkit_new (void);
|
||||||
|
|
||||||
|
#endif /* MM_AUTH_PROVIDER_POLKIT_H */
|
||||||
|
|
@@ -58,55 +58,6 @@ remove_requests (MMAuthProvider *self, GSList *remove)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
process_complete_requests (gpointer user_data)
|
|
||||||
{
|
|
||||||
MMAuthProvider *self = MM_AUTH_PROVIDER (user_data);
|
|
||||||
MMAuthProviderPrivate *priv = MM_AUTH_PROVIDER_GET_PRIVATE (self);
|
|
||||||
GHashTableIter iter;
|
|
||||||
gpointer value;
|
|
||||||
GSList *remove = NULL;
|
|
||||||
MMAuthRequest *req;
|
|
||||||
|
|
||||||
priv->process_id = 0;
|
|
||||||
|
|
||||||
/* Call finished request's callbacks */
|
|
||||||
g_hash_table_iter_init (&iter, priv->requests);
|
|
||||||
while (g_hash_table_iter_next (&iter, NULL, &value)) {
|
|
||||||
req = MM_AUTH_REQUEST (value);
|
|
||||||
|
|
||||||
if (mm_auth_request_get_authorization (req) != MM_AUTH_RESULT_UNKNOWN) {
|
|
||||||
mm_auth_request_complete (req);
|
|
||||||
remove = g_slist_prepend (remove, req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And remove those requests from our pending request list */
|
|
||||||
remove_requests (self, remove);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
mm_auth_provider_finish_request (MMAuthProvider *provider,
|
|
||||||
MMAuthRequest *req,
|
|
||||||
MMAuthResult result)
|
|
||||||
{
|
|
||||||
MMAuthProviderPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (provider != NULL);
|
|
||||||
g_return_if_fail (MM_IS_AUTH_PROVIDER (provider));
|
|
||||||
g_return_if_fail (req != NULL);
|
|
||||||
g_return_if_fail (result != MM_AUTH_RESULT_UNKNOWN);
|
|
||||||
|
|
||||||
priv = MM_AUTH_PROVIDER_GET_PRIVATE (provider);
|
|
||||||
g_return_if_fail (g_hash_table_lookup (priv->requests, req) != NULL);
|
|
||||||
|
|
||||||
mm_auth_request_set_result (req, result);
|
|
||||||
if (priv->process_id == 0)
|
|
||||||
priv->process_id = g_idle_add (process_complete_requests, provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mm_auth_provider_cancel_request (MMAuthProvider *provider, MMAuthRequest *req)
|
mm_auth_provider_cancel_request (MMAuthProvider *provider, MMAuthRequest *req)
|
||||||
{
|
{
|
||||||
@@ -149,31 +100,72 @@ mm_auth_provider_cancel_for_owner (MMAuthProvider *self, GObject *owner)
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static gboolean
|
|
||||||
real_request_auth (MMAuthProvider *provider,
|
|
||||||
MMAuthRequest *req,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
/* This class provides null authentication; all requests pass */
|
|
||||||
mm_auth_provider_finish_request (provider, req, MM_AUTH_RESULT_AUTHORIZED);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static MMAuthRequest *
|
static MMAuthRequest *
|
||||||
real_create_request (MMAuthProvider *provider,
|
real_create_request (MMAuthProvider *provider,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
GObject *owner,
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
return (MMAuthRequest *) mm_auth_request_new (authorization, owner, callback, callback_data, notify);
|
return (MMAuthRequest *) mm_auth_request_new (0,
|
||||||
|
authorization,
|
||||||
|
owner,
|
||||||
|
context,
|
||||||
|
callback,
|
||||||
|
callback_data,
|
||||||
|
notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
process_complete_requests (gpointer user_data)
|
||||||
|
{
|
||||||
|
MMAuthProvider *self = MM_AUTH_PROVIDER (user_data);
|
||||||
|
MMAuthProviderPrivate *priv = MM_AUTH_PROVIDER_GET_PRIVATE (self);
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer value;
|
||||||
|
GSList *remove = NULL;
|
||||||
|
MMAuthRequest *req;
|
||||||
|
|
||||||
|
priv->process_id = 0;
|
||||||
|
|
||||||
|
/* Call finished request's callbacks */
|
||||||
|
g_hash_table_iter_init (&iter, priv->requests);
|
||||||
|
while (g_hash_table_iter_next (&iter, NULL, &value)) {
|
||||||
|
req = MM_AUTH_REQUEST (value);
|
||||||
|
|
||||||
|
if (mm_auth_request_get_authorization (req) != MM_AUTH_RESULT_UNKNOWN) {
|
||||||
|
mm_auth_request_callback (req);
|
||||||
|
remove = g_slist_prepend (remove, req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* And remove those requests from our pending request list */
|
||||||
|
remove_requests (self, remove);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
auth_result_cb (MMAuthRequest *req, gpointer user_data)
|
||||||
|
{
|
||||||
|
MMAuthProvider *self = MM_AUTH_PROVIDER (user_data);
|
||||||
|
MMAuthProviderPrivate *priv = MM_AUTH_PROVIDER_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
/* Process results from an idle handler */
|
||||||
|
if (priv->process_id == 0)
|
||||||
|
priv->process_id = g_idle_add (process_complete_requests, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RESULT_SIGID_TAG "result-sigid"
|
||||||
|
|
||||||
MMAuthRequest *
|
MMAuthRequest *
|
||||||
mm_auth_provider_request_auth (MMAuthProvider *self,
|
mm_auth_provider_request_auth (MMAuthProvider *self,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
GObject *owner,
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify,
|
GDestroyNotify notify,
|
||||||
@@ -181,6 +173,7 @@ mm_auth_provider_request_auth (MMAuthProvider *self,
|
|||||||
{
|
{
|
||||||
MMAuthProviderPrivate *priv;
|
MMAuthProviderPrivate *priv;
|
||||||
MMAuthRequest *req;
|
MMAuthRequest *req;
|
||||||
|
guint32 sigid;
|
||||||
|
|
||||||
g_return_val_if_fail (self != NULL, 0);
|
g_return_val_if_fail (self != NULL, 0);
|
||||||
g_return_val_if_fail (MM_IS_AUTH_PROVIDER (self), 0);
|
g_return_val_if_fail (MM_IS_AUTH_PROVIDER (self), 0);
|
||||||
@@ -192,13 +185,17 @@ mm_auth_provider_request_auth (MMAuthProvider *self,
|
|||||||
req = MM_AUTH_PROVIDER_GET_CLASS (self)->create_request (self,
|
req = MM_AUTH_PROVIDER_GET_CLASS (self)->create_request (self,
|
||||||
authorization,
|
authorization,
|
||||||
owner,
|
owner,
|
||||||
|
context,
|
||||||
callback,
|
callback,
|
||||||
callback_data,
|
callback_data,
|
||||||
notify);
|
notify);
|
||||||
g_assert (req);
|
g_assert (req);
|
||||||
|
|
||||||
|
sigid = g_signal_connect (req, "result", G_CALLBACK (auth_result_cb), self);
|
||||||
|
g_object_set_data (G_OBJECT (req), RESULT_SIGID_TAG, GUINT_TO_POINTER (sigid));
|
||||||
|
|
||||||
g_hash_table_insert (priv->requests, req, req);
|
g_hash_table_insert (priv->requests, req, req);
|
||||||
if (!MM_AUTH_PROVIDER_GET_CLASS (self)->request_auth (self, req, error)) {
|
if (!mm_auth_request_authenticate (req, error)) {
|
||||||
/* Error */
|
/* Error */
|
||||||
g_hash_table_remove (priv->requests, req);
|
g_hash_table_remove (priv->requests, req);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -209,6 +206,19 @@ mm_auth_provider_request_auth (MMAuthProvider *self,
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
dispose_auth_request (gpointer data)
|
||||||
|
{
|
||||||
|
MMAuthRequest *req = MM_AUTH_REQUEST (data);
|
||||||
|
guint sigid;
|
||||||
|
|
||||||
|
sigid = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (req), RESULT_SIGID_TAG));
|
||||||
|
if (sigid)
|
||||||
|
g_signal_handler_disconnect (req, sigid);
|
||||||
|
mm_auth_request_dispose (req);
|
||||||
|
g_object_unref (req);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mm_auth_provider_init (MMAuthProvider *self)
|
mm_auth_provider_init (MMAuthProvider *self)
|
||||||
{
|
{
|
||||||
@@ -217,7 +227,7 @@ mm_auth_provider_init (MMAuthProvider *self)
|
|||||||
priv->requests = g_hash_table_new_full (g_direct_hash,
|
priv->requests = g_hash_table_new_full (g_direct_hash,
|
||||||
g_direct_equal,
|
g_direct_equal,
|
||||||
NULL,
|
NULL,
|
||||||
(GDestroyNotify) g_object_unref);
|
dispose_auth_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -277,7 +287,6 @@ mm_auth_provider_class_init (MMAuthProviderClass *class)
|
|||||||
object_class->set_property = set_property;
|
object_class->set_property = set_property;
|
||||||
object_class->get_property = get_property;
|
object_class->get_property = get_property;
|
||||||
object_class->dispose = dispose;
|
object_class->dispose = dispose;
|
||||||
class->request_auth = real_request_auth;
|
|
||||||
class->create_request = real_create_request;
|
class->create_request = real_create_request;
|
||||||
|
|
||||||
/* Properties */
|
/* Properties */
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#define MM_AUTH_PROVIDER_H
|
#define MM_AUTH_PROVIDER_H
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
|
|
||||||
#include "mm-auth-request.h"
|
#include "mm-auth-request.h"
|
||||||
|
|
||||||
@@ -43,13 +44,10 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
GObjectClass parent;
|
GObjectClass parent;
|
||||||
|
|
||||||
gboolean (*request_auth) (MMAuthProvider *provider,
|
|
||||||
MMAuthRequest *req,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
MMAuthRequest * (*create_request) (MMAuthProvider *provider,
|
MMAuthRequest * (*create_request) (MMAuthProvider *provider,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
GObject *owner,
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify);
|
GDestroyNotify notify);
|
||||||
@@ -57,9 +55,11 @@ typedef struct {
|
|||||||
|
|
||||||
GType mm_auth_provider_get_type (void);
|
GType mm_auth_provider_get_type (void);
|
||||||
|
|
||||||
|
/* Don't do anything clever from the notify callback... */
|
||||||
MMAuthRequest *mm_auth_provider_request_auth (MMAuthProvider *provider,
|
MMAuthRequest *mm_auth_provider_request_auth (MMAuthProvider *provider,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
GObject *owner,
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify,
|
GDestroyNotify notify,
|
||||||
@@ -68,6 +68,8 @@ MMAuthRequest *mm_auth_provider_request_auth (MMAuthProvider *provider,
|
|||||||
void mm_auth_provider_cancel_for_owner (MMAuthProvider *provider,
|
void mm_auth_provider_cancel_for_owner (MMAuthProvider *provider,
|
||||||
GObject *owner);
|
GObject *owner);
|
||||||
|
|
||||||
|
/* Subclass API */
|
||||||
|
|
||||||
/* To get an auth provider instance, implemented in mm-auth-provider-factory.c */
|
/* To get an auth provider instance, implemented in mm-auth-provider-factory.c */
|
||||||
MMAuthProvider *mm_auth_provider_get (void);
|
MMAuthProvider *mm_auth_provider_get (void);
|
||||||
|
|
||||||
|
175
src/mm-auth-request-polkit.c
Normal file
175
src/mm-auth-request-polkit.c
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
#include "mm-auth-request-polkit.h"
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (MMAuthRequestPolkit, mm_auth_request_polkit, MM_TYPE_AUTH_REQUEST)
|
||||||
|
|
||||||
|
#define MM_AUTH_REQUEST_POLKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_AUTH_REQUEST_POLKIT, MMAuthRequestPolkitPrivate))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PolkitAuthority *authority;
|
||||||
|
GCancellable *cancellable;
|
||||||
|
PolkitSubject *subject;
|
||||||
|
} MMAuthRequestPolkitPrivate;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
GObject *
|
||||||
|
mm_auth_request_polkit_new (PolkitAuthority *authority,
|
||||||
|
const char *authorization,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
MMAuthRequestCb callback,
|
||||||
|
gpointer callback_data,
|
||||||
|
GDestroyNotify notify)
|
||||||
|
{
|
||||||
|
GObject *obj;
|
||||||
|
MMAuthRequestPolkitPrivate *priv;
|
||||||
|
char *sender;
|
||||||
|
|
||||||
|
g_return_val_if_fail (authorization != NULL, NULL);
|
||||||
|
g_return_val_if_fail (owner != NULL, NULL);
|
||||||
|
g_return_val_if_fail (callback != NULL, NULL);
|
||||||
|
g_return_val_if_fail (context != NULL, NULL);
|
||||||
|
|
||||||
|
obj = mm_auth_request_new (MM_TYPE_AUTH_REQUEST_POLKIT,
|
||||||
|
authorization,
|
||||||
|
owner,
|
||||||
|
context,
|
||||||
|
callback,
|
||||||
|
callback_data,
|
||||||
|
notify);
|
||||||
|
if (obj) {
|
||||||
|
priv = MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (obj);
|
||||||
|
priv->authority = authority;
|
||||||
|
priv->cancellable = g_cancellable_new ();
|
||||||
|
|
||||||
|
sender = dbus_g_method_get_sender (context);
|
||||||
|
priv->subject = polkit_system_bus_name_new (sender);
|
||||||
|
g_free (sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
pk_auth_cb (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||||
|
{
|
||||||
|
MMAuthRequestPolkit *self = user_data;
|
||||||
|
MMAuthRequestPolkitPrivate *priv;
|
||||||
|
PolkitAuthorizationResult *pk_result;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
g_return_if_fail (self != NULL);
|
||||||
|
g_return_if_fail (MM_IS_AUTH_REQUEST_POLKIT (self));
|
||||||
|
|
||||||
|
priv = MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (self);
|
||||||
|
if (!g_cancellable_is_cancelled (priv->cancellable)) {
|
||||||
|
pk_result = polkit_authority_check_authorization_finish (priv->authority,
|
||||||
|
result,
|
||||||
|
&error);
|
||||||
|
if (error) {
|
||||||
|
mm_auth_request_set_result (MM_AUTH_REQUEST (self), MM_AUTH_RESULT_INTERNAL_FAILURE);
|
||||||
|
g_warning ("%s: PolicyKit authentication error: (%d) %s",
|
||||||
|
__func__,
|
||||||
|
error ? error->code : -1,
|
||||||
|
error && error->message ? error->message : "(unknown)");
|
||||||
|
} else if (polkit_authorization_result_get_is_authorized (pk_result))
|
||||||
|
mm_auth_request_set_result (MM_AUTH_REQUEST (self), MM_AUTH_RESULT_AUTHORIZED);
|
||||||
|
else if (polkit_authorization_result_get_is_challenge (pk_result))
|
||||||
|
mm_auth_request_set_result (MM_AUTH_REQUEST (self), MM_AUTH_RESULT_CHALLENGE);
|
||||||
|
else
|
||||||
|
mm_auth_request_set_result (MM_AUTH_REQUEST (self), MM_AUTH_RESULT_NOT_AUTHORIZED);
|
||||||
|
|
||||||
|
g_signal_emit_by_name (self, "result");
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
real_authenticate (MMAuthRequest *self, GError **error)
|
||||||
|
{
|
||||||
|
MMAuthRequestPolkitPrivate *priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail (self != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (MM_IS_AUTH_REQUEST_POLKIT (self), FALSE);
|
||||||
|
|
||||||
|
/* We ref ourselves across the polkit call, because we can't get
|
||||||
|
* disposed of while the call is still in-progress, and even if we
|
||||||
|
* cancel ourselves we'll still get the callback.
|
||||||
|
*/
|
||||||
|
g_object_ref (self);
|
||||||
|
|
||||||
|
priv = MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (self);
|
||||||
|
polkit_authority_check_authorization (priv->authority,
|
||||||
|
priv->subject,
|
||||||
|
mm_auth_request_get_authorization (MM_AUTH_REQUEST (self)),
|
||||||
|
NULL,
|
||||||
|
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
|
||||||
|
priv->cancellable,
|
||||||
|
pk_auth_cb,
|
||||||
|
self);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
real_dispose (MMAuthRequest *req)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
g_return_if_fail (MM_IS_AUTH_REQUEST_POLKIT (req));
|
||||||
|
|
||||||
|
g_cancellable_cancel (MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (req)->cancellable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
mm_auth_request_polkit_init (MMAuthRequestPolkit *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dispose (GObject *object)
|
||||||
|
{
|
||||||
|
MMAuthRequestPolkitPrivate *priv = MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (object);
|
||||||
|
|
||||||
|
g_object_unref (priv->cancellable);
|
||||||
|
g_object_unref (priv->subject);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (mm_auth_request_polkit_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mm_auth_request_polkit_class_init (MMAuthRequestPolkitClass *class)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
MMAuthRequestClass *ar_class = MM_AUTH_REQUEST_CLASS (class);
|
||||||
|
|
||||||
|
mm_auth_request_polkit_parent_class = g_type_class_peek_parent (class);
|
||||||
|
g_type_class_add_private (class, sizeof (MMAuthRequestPolkitPrivate));
|
||||||
|
|
||||||
|
/* Virtual methods */
|
||||||
|
object_class->dispose = dispose;
|
||||||
|
ar_class->authenticate = real_authenticate;
|
||||||
|
ar_class->dispose = real_dispose;
|
||||||
|
}
|
||||||
|
|
53
src/mm-auth-request-polkit.h
Normal file
53
src/mm-auth-request-polkit.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MM_AUTH_REQUEST_POLKIT_H
|
||||||
|
#define MM_AUTH_REQUEST_POLKIT_H
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
#include <polkit/polkit.h>
|
||||||
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
|
|
||||||
|
#include "mm-auth-request.h"
|
||||||
|
|
||||||
|
#define MM_TYPE_AUTH_REQUEST_POLKIT (mm_auth_request_polkit_get_type ())
|
||||||
|
#define MM_AUTH_REQUEST_POLKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_AUTH_REQUEST_POLKIT, MMAuthRequestPolkit))
|
||||||
|
#define MM_AUTH_REQUEST_POLKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_AUTH_REQUEST_POLKIT, MMAuthRequestPolkitClass))
|
||||||
|
#define MM_IS_AUTH_REQUEST_POLKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_AUTH_REQUEST_POLKIT))
|
||||||
|
#define MM_IS_AUTH_REQUEST_POLKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_AUTH_REQUEST_POLKIT))
|
||||||
|
#define MM_AUTH_REQUEST_POLKIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_AUTH_REQUEST_POLKIT, MMAuthRequestPolkitClass))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMAuthRequest parent;
|
||||||
|
} MMAuthRequestPolkit;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMAuthRequestClass parent;
|
||||||
|
} MMAuthRequestPolkitClass;
|
||||||
|
|
||||||
|
GType mm_auth_request_polkit_get_type (void);
|
||||||
|
|
||||||
|
GObject *mm_auth_request_polkit_new (PolkitAuthority *authority,
|
||||||
|
const char *authorization,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
MMAuthRequestCb callback,
|
||||||
|
gpointer callback_data,
|
||||||
|
GDestroyNotify notify);
|
||||||
|
|
||||||
|
void mm_auth_request_polkit_cancel (MMAuthRequestPolkit *self);
|
||||||
|
|
||||||
|
#endif /* MM_AUTH_REQUEST_POLKIT_H */
|
||||||
|
|
@@ -218,6 +218,7 @@ mm_modem_base_set_unlock_required (MMModemBase *self, const char *unlock_require
|
|||||||
static gboolean
|
static gboolean
|
||||||
modem_auth_request (MMModem *modem,
|
modem_auth_request (MMModem *modem,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify,
|
GDestroyNotify notify,
|
||||||
@@ -230,6 +231,7 @@ modem_auth_request (MMModem *modem,
|
|||||||
return !!mm_auth_provider_request_auth (priv->authp,
|
return !!mm_auth_provider_request_auth (priv->authp,
|
||||||
authorization,
|
authorization,
|
||||||
G_OBJECT (self),
|
G_OBJECT (self),
|
||||||
|
context,
|
||||||
callback,
|
callback,
|
||||||
callback_data,
|
callback_data,
|
||||||
notify,
|
notify,
|
||||||
|
@@ -189,10 +189,12 @@ mm_modem_cdma_get_esn (MMModemCdma *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
esn_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
esn_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemCdma *self = MM_MODEM_CDMA (owner);
|
MMModemCdma *self = MM_MODEM_CDMA (owner);
|
||||||
DBusGMethodInvocation *context = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise get the ESN */
|
/* Return any authorization error, otherwise get the ESN */
|
||||||
@@ -211,8 +213,9 @@ impl_modem_cdma_get_esn (MMModemCdma *self, DBusGMethodInvocation *context)
|
|||||||
/* Make sure the caller is authorized to get the ESN */
|
/* Make sure the caller is authorized to get the ESN */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (self),
|
if (!mm_modem_auth_request (MM_MODEM (self),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
esn_auth_cb,
|
|
||||||
context,
|
context,
|
||||||
|
esn_auth_cb,
|
||||||
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&error)) {
|
&error)) {
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
|
@@ -202,10 +202,12 @@ mm_modem_gsm_card_change_pin (MMModemGsmCard *self,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
imei_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
imei_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
||||||
DBusGMethodInvocation *context = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise get the IMEI */
|
/* Return any authorization error, otherwise get the IMEI */
|
||||||
@@ -224,8 +226,9 @@ impl_gsm_modem_get_imei (MMModemGsmCard *modem, DBusGMethodInvocation *context)
|
|||||||
/* Make sure the caller is authorized to get the IMEI */
|
/* Make sure the caller is authorized to get the IMEI */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
imei_auth_cb,
|
|
||||||
context,
|
context,
|
||||||
|
imei_auth_cb,
|
||||||
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&error)) {
|
&error)) {
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
@@ -236,10 +239,12 @@ impl_gsm_modem_get_imei (MMModemGsmCard *modem, DBusGMethodInvocation *context)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
imsi_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
imsi_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
||||||
DBusGMethodInvocation *context = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise get the IMSI */
|
/* Return any authorization error, otherwise get the IMSI */
|
||||||
@@ -258,8 +263,9 @@ impl_gsm_modem_get_imsi (MMModemGsmCard *modem, DBusGMethodInvocation *context)
|
|||||||
/* Make sure the caller is authorized to get the IMSI */
|
/* Make sure the caller is authorized to get the IMSI */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
imsi_auth_cb,
|
|
||||||
context,
|
context,
|
||||||
|
imsi_auth_cb,
|
||||||
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&error)) {
|
&error)) {
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
@@ -274,7 +280,6 @@ typedef struct {
|
|||||||
char *pin;
|
char *pin;
|
||||||
char *pin2;
|
char *pin2;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
DBusGMethodInvocation *context;
|
|
||||||
} SendPinPukInfo;
|
} SendPinPukInfo;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -293,8 +298,7 @@ static SendPinPukInfo *
|
|||||||
send_pin_puk_info_new (const char *puk,
|
send_pin_puk_info_new (const char *puk,
|
||||||
const char *pin,
|
const char *pin,
|
||||||
const char *pin2,
|
const char *pin2,
|
||||||
gboolean enabled,
|
gboolean enabled)
|
||||||
DBusGMethodInvocation *context)
|
|
||||||
{
|
{
|
||||||
SendPinPukInfo *info;
|
SendPinPukInfo *info;
|
||||||
|
|
||||||
@@ -303,14 +307,16 @@ send_pin_puk_info_new (const char *puk,
|
|||||||
info->pin = g_strdup (pin);
|
info->pin = g_strdup (pin);
|
||||||
info->pin2 = g_strdup (pin2);
|
info->pin2 = g_strdup (pin2);
|
||||||
info->enabled = enabled;
|
info->enabled = enabled;
|
||||||
info->context = context;
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_puk_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
send_puk_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
||||||
SendPinPukInfo *info = user_data;
|
SendPinPukInfo *info = user_data;
|
||||||
@@ -318,10 +324,10 @@ send_puk_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
|||||||
|
|
||||||
/* Return any authorization error, otherwise send the PUK */
|
/* Return any authorization error, otherwise send the PUK */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
mm_modem_gsm_card_send_puk (self, info->puk, info->pin, async_call_done, info->context);
|
mm_modem_gsm_card_send_puk (self, info->puk, info->pin, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -333,11 +339,12 @@ impl_gsm_modem_send_puk (MMModemGsmCard *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SendPinPukInfo *info;
|
SendPinPukInfo *info;
|
||||||
|
|
||||||
info = send_pin_puk_info_new (puk, pin, NULL, FALSE, context);
|
info = send_pin_puk_info_new (puk, pin, NULL, FALSE);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to send the PUK */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
|
context,
|
||||||
send_puk_auth_cb,
|
send_puk_auth_cb,
|
||||||
info,
|
info,
|
||||||
send_pin_puk_info_destroy,
|
send_pin_puk_info_destroy,
|
||||||
@@ -350,7 +357,10 @@ impl_gsm_modem_send_puk (MMModemGsmCard *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_pin_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
send_pin_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
||||||
SendPinPukInfo *info = user_data;
|
SendPinPukInfo *info = user_data;
|
||||||
@@ -358,10 +368,10 @@ send_pin_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
|||||||
|
|
||||||
/* Return any authorization error, otherwise unlock the modem */
|
/* Return any authorization error, otherwise unlock the modem */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
mm_modem_gsm_card_send_pin (self, info->pin, async_call_done, info->context);
|
mm_modem_gsm_card_send_pin (self, info->pin, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -372,11 +382,12 @@ impl_gsm_modem_send_pin (MMModemGsmCard *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SendPinPukInfo *info;
|
SendPinPukInfo *info;
|
||||||
|
|
||||||
info = send_pin_puk_info_new (NULL, pin, NULL, FALSE, context);
|
info = send_pin_puk_info_new (NULL, pin, NULL, FALSE);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to unlock the modem */
|
/* Make sure the caller is authorized to unlock the modem */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
|
context,
|
||||||
send_pin_auth_cb,
|
send_pin_auth_cb,
|
||||||
info,
|
info,
|
||||||
send_pin_puk_info_destroy,
|
send_pin_puk_info_destroy,
|
||||||
@@ -389,7 +400,10 @@ impl_gsm_modem_send_pin (MMModemGsmCard *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable_pin_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
enable_pin_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
||||||
SendPinPukInfo *info = user_data;
|
SendPinPukInfo *info = user_data;
|
||||||
@@ -397,10 +411,10 @@ enable_pin_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
|||||||
|
|
||||||
/* Return any authorization error, otherwise enable the PIN */
|
/* Return any authorization error, otherwise enable the PIN */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
mm_modem_gsm_card_enable_pin (self, info->pin, info->enabled, async_call_done, info->context);
|
mm_modem_gsm_card_enable_pin (self, info->pin, info->enabled, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -412,11 +426,12 @@ impl_gsm_modem_enable_pin (MMModemGsmCard *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SendPinPukInfo *info;
|
SendPinPukInfo *info;
|
||||||
|
|
||||||
info = send_pin_puk_info_new (NULL, pin, NULL, enabled, context);
|
info = send_pin_puk_info_new (NULL, pin, NULL, enabled);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to enable a PIN */
|
/* Make sure the caller is authorized to enable a PIN */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
|
context,
|
||||||
enable_pin_auth_cb,
|
enable_pin_auth_cb,
|
||||||
info,
|
info,
|
||||||
send_pin_puk_info_destroy,
|
send_pin_puk_info_destroy,
|
||||||
@@ -429,7 +444,10 @@ impl_gsm_modem_enable_pin (MMModemGsmCard *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
change_pin_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
change_pin_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
|
||||||
SendPinPukInfo *info = user_data;
|
SendPinPukInfo *info = user_data;
|
||||||
@@ -437,10 +455,10 @@ change_pin_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
|||||||
|
|
||||||
/* Return any authorization error, otherwise change the PIN */
|
/* Return any authorization error, otherwise change the PIN */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
mm_modem_gsm_card_change_pin (self, info->pin, info->pin2, async_call_done, info->context);
|
mm_modem_gsm_card_change_pin (self, info->pin, info->pin2, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -452,11 +470,12 @@ impl_gsm_modem_change_pin (MMModemGsmCard *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SendPinPukInfo *info;
|
SendPinPukInfo *info;
|
||||||
|
|
||||||
info = send_pin_puk_info_new (NULL, old_pin, new_pin, FALSE, context);
|
info = send_pin_puk_info_new (NULL, old_pin, new_pin, FALSE);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to change the PIN */
|
/* Make sure the caller is authorized to change the PIN */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
|
context,
|
||||||
change_pin_auth_cb,
|
change_pin_auth_cb,
|
||||||
info,
|
info,
|
||||||
send_pin_puk_info_destroy,
|
send_pin_puk_info_destroy,
|
||||||
|
@@ -398,10 +398,12 @@ impl_gsm_modem_register (MMModemGsmNetwork *modem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
scan_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
scan_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmNetwork *self = MM_MODEM_GSM_NETWORK (owner);
|
MMModemGsmNetwork *self = MM_MODEM_GSM_NETWORK (owner);
|
||||||
DBusGMethodInvocation *context = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise get the IMEI */
|
/* Return any authorization error, otherwise get the IMEI */
|
||||||
@@ -421,8 +423,9 @@ impl_gsm_modem_scan (MMModemGsmNetwork *modem,
|
|||||||
/* Make sure the caller is authorized to request a scan */
|
/* Make sure the caller is authorized to request a scan */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_DEVICE,
|
MM_AUTHORIZATION_DEVICE,
|
||||||
scan_auth_cb,
|
|
||||||
context,
|
context,
|
||||||
|
scan_auth_cb,
|
||||||
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&error)) {
|
&error)) {
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
|
@@ -137,7 +137,6 @@ typedef struct {
|
|||||||
guint num5;
|
guint num5;
|
||||||
char *str;
|
char *str;
|
||||||
GHashTable *hash;
|
GHashTable *hash;
|
||||||
DBusGMethodInvocation *context;
|
|
||||||
} SmsAuthInfo;
|
} SmsAuthInfo;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -167,8 +166,7 @@ sms_auth_info_new (guint num1,
|
|||||||
guint num4,
|
guint num4,
|
||||||
guint num5,
|
guint num5,
|
||||||
const char *str,
|
const char *str,
|
||||||
GHashTable *hash,
|
GHashTable *hash)
|
||||||
DBusGMethodInvocation *context)
|
|
||||||
{
|
{
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
@@ -179,7 +177,6 @@ sms_auth_info_new (guint num1,
|
|||||||
info->num4 = num4;
|
info->num4 = num4;
|
||||||
info->num5 = num5;
|
info->num5 = num5;
|
||||||
info->str = g_strdup (str);
|
info->str = g_strdup (str);
|
||||||
info->context = context;
|
|
||||||
|
|
||||||
/* Copy the hash table if we're given one */
|
/* Copy the hash table if we're given one */
|
||||||
if (hash) {
|
if (hash) {
|
||||||
@@ -207,18 +204,20 @@ sms_auth_info_new (guint num1,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_delete_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_delete_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise delete the SMS */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -229,11 +228,12 @@ impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL, context);
|
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to delete an SMS */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_delete_auth_cb,
|
sms_delete_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
@@ -246,18 +246,20 @@ impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_get_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_get_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise get the SMS */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -268,11 +270,12 @@ impl_gsm_modem_sms_get (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL, context);
|
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to get an SMS */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_get_auth_cb,
|
sms_get_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
@@ -309,18 +312,20 @@ impl_gsm_modem_sms_get_smsc (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_set_smsc_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_set_smsc_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise set the SMS service center */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -331,11 +336,12 @@ impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (0, 0, 0, 0, 0, smsc, NULL, context);
|
info = sms_auth_info_new (0, 0, 0, 0, 0, smsc, NULL);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to set the SMS service center */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_set_smsc_auth_cb,
|
sms_set_smsc_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
@@ -348,18 +354,20 @@ impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_list_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_list_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise list SMSs */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -367,16 +375,14 @@ impl_gsm_modem_sms_list (MMModemGsmSms *modem,
|
|||||||
DBusGMethodInvocation *context)
|
DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
|
||||||
|
|
||||||
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, NULL, context);
|
/* Make sure the caller is authorized to list SMSs */
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_list_auth_cb,
|
sms_list_auth_cb,
|
||||||
info,
|
NULL,
|
||||||
sms_auth_info_destroy,
|
NULL,
|
||||||
&error)) {
|
&error)) {
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
@@ -386,18 +392,20 @@ impl_gsm_modem_sms_list (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_save_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_save_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise save the SMS */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -408,11 +416,12 @@ impl_gsm_modem_sms_save (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, properties, context);
|
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, properties);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to save the SMS */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_save_auth_cb,
|
sms_save_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
@@ -425,7 +434,10 @@ impl_gsm_modem_sms_save (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_send_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_send_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
SmsAuthInfo *info = user_data;
|
||||||
@@ -471,10 +483,10 @@ sms_send_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
if (error) {
|
if (error) {
|
||||||
async_call_done (MM_MODEM (self), error, info->context);
|
async_call_done (MM_MODEM (self), error, context);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
mm_modem_gsm_sms_send (self, number, text, smsc, validity, class, async_call_done, info->context);
|
mm_modem_gsm_sms_send (self, number, text, smsc, validity, class, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -485,11 +497,12 @@ impl_gsm_modem_sms_send (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, properties, context);
|
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, properties);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to send the PUK */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_send_auth_cb,
|
sms_send_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
@@ -502,18 +515,20 @@ impl_gsm_modem_sms_send (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_send_from_storage_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_send_from_storage_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise delete the SMS */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -524,11 +539,12 @@ impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, NULL, context);
|
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to send the PUK */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_send_from_storage_auth_cb,
|
sms_send_from_storage_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
@@ -541,18 +557,20 @@ impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sms_set_indication_auth_cb (MMAuthRequest *req, GObject *owner, gpointer user_data)
|
sms_set_indication_auth_cb (MMAuthRequest *req,
|
||||||
|
GObject *owner,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
|
||||||
SmsAuthInfo *info = user_data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Return any authorization error, otherwise delete the SMS */
|
/* Return any authorization error, otherwise delete the SMS */
|
||||||
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
|
||||||
dbus_g_method_return_error (info->context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
} else
|
} else
|
||||||
async_call_not_supported (self, async_call_done, info->context);
|
async_call_not_supported (self, async_call_done, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -567,11 +585,12 @@ impl_gsm_modem_sms_set_indication (MMModemGsmSms *modem,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SmsAuthInfo *info;
|
SmsAuthInfo *info;
|
||||||
|
|
||||||
info = sms_auth_info_new (mode, mt, bm, ds, bfr, NULL, NULL, context);
|
info = sms_auth_info_new (mode, mt, bm, ds, bfr, NULL, NULL);
|
||||||
|
|
||||||
/* Make sure the caller is authorized to send the PUK */
|
/* Make sure the caller is authorized to send the PUK */
|
||||||
if (!mm_modem_auth_request (MM_MODEM (modem),
|
if (!mm_modem_auth_request (MM_MODEM (modem),
|
||||||
MM_AUTHORIZATION_SMS,
|
MM_AUTHORIZATION_SMS,
|
||||||
|
context,
|
||||||
sms_set_indication_auth_cb,
|
sms_set_indication_auth_cb,
|
||||||
info,
|
info,
|
||||||
sms_auth_info_destroy,
|
sms_auth_info_destroy,
|
||||||
|
@@ -611,6 +611,7 @@ mm_modem_set_state (MMModem *self,
|
|||||||
gboolean
|
gboolean
|
||||||
mm_modem_auth_request (MMModem *self,
|
mm_modem_auth_request (MMModem *self,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify,
|
GDestroyNotify notify,
|
||||||
@@ -619,11 +620,13 @@ mm_modem_auth_request (MMModem *self,
|
|||||||
g_return_val_if_fail (self != NULL, FALSE);
|
g_return_val_if_fail (self != NULL, FALSE);
|
||||||
g_return_val_if_fail (MM_IS_MODEM (self), FALSE);
|
g_return_val_if_fail (MM_IS_MODEM (self), FALSE);
|
||||||
g_return_val_if_fail (authorization != NULL, FALSE);
|
g_return_val_if_fail (authorization != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (context != NULL, FALSE);
|
||||||
g_return_val_if_fail (callback != NULL, FALSE);
|
g_return_val_if_fail (callback != NULL, FALSE);
|
||||||
|
|
||||||
g_return_val_if_fail (MM_MODEM_GET_INTERFACE (self)->auth_request, FALSE);
|
g_return_val_if_fail (MM_MODEM_GET_INTERFACE (self)->auth_request, FALSE);
|
||||||
return MM_MODEM_GET_INTERFACE (self)->auth_request (self,
|
return MM_MODEM_GET_INTERFACE (self)->auth_request (self,
|
||||||
authorization,
|
authorization,
|
||||||
|
context,
|
||||||
callback,
|
callback,
|
||||||
callback_data,
|
callback_data,
|
||||||
notify,
|
notify,
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#define MM_MODEM_H
|
#define MM_MODEM_H
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
|
|
||||||
#include "mm-port.h"
|
#include "mm-port.h"
|
||||||
#include "mm-auth-provider.h"
|
#include "mm-auth-provider.h"
|
||||||
@@ -162,6 +163,7 @@ struct _MMModem {
|
|||||||
*/
|
*/
|
||||||
gboolean (*auth_request) (MMModem *self,
|
gboolean (*auth_request) (MMModem *self,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify,
|
GDestroyNotify notify,
|
||||||
@@ -238,6 +240,7 @@ GError *mm_modem_check_removed (MMModem *self, const GError *error);
|
|||||||
*/
|
*/
|
||||||
gboolean mm_modem_auth_request (MMModem *self,
|
gboolean mm_modem_auth_request (MMModem *self,
|
||||||
const char *authorization,
|
const char *authorization,
|
||||||
|
DBusGMethodInvocation *context,
|
||||||
MMAuthRequestCb callback,
|
MMAuthRequestCb callback,
|
||||||
gpointer callback_data,
|
gpointer callback_data,
|
||||||
GDestroyNotify notify,
|
GDestroyNotify notify,
|
||||||
|
Reference in New Issue
Block a user