|
Packit |
79f644 |
/*
|
|
Packit |
79f644 |
* Copyright (C) 2010 Collabora Ltd.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
79f644 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License as published by the Free Software Foundation; either
|
|
Packit |
79f644 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
79f644 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
79f644 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
79f644 |
* Lesser General Public License for more details.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
79f644 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "config.h"
|
|
Packit |
79f644 |
#include "tpaw-keyring.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include <glib/gi18n-lib.h>
|
|
Packit |
79f644 |
#include <libsecret/secret.h>
|
|
Packit |
79f644 |
#include <telepathy-glib/telepathy-glib-dbus.h>
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef HAVE_UOA
|
|
Packit |
79f644 |
#include <libaccounts-glib/ag-account.h>
|
|
Packit |
79f644 |
#include <libaccounts-glib/ag-account-service.h>
|
|
Packit |
79f644 |
#include <libaccounts-glib/ag-auth-data.h>
|
|
Packit |
79f644 |
#include <libaccounts-glib/ag-manager.h>
|
|
Packit |
79f644 |
#include <libaccounts-glib/ag-service.h>
|
|
Packit |
79f644 |
#include <libsignon-glib/signon-identity.h>
|
|
Packit |
79f644 |
#include "tpaw-uoa-utils.h"
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "tpaw-utils.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#define DEBUG_FLAG TPAW_DEBUG_OTHER
|
|
Packit |
79f644 |
#include "tpaw-debug.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* We cannot change the schema name for compatibility, so it's still
|
|
Packit |
79f644 |
* referring to Empathy */
|
|
Packit |
79f644 |
static const SecretSchema account_keyring_schema =
|
|
Packit |
79f644 |
{ "org.gnome.Empathy.Account", SECRET_SCHEMA_DONT_MATCH_NAME,
|
|
Packit |
79f644 |
{ { "account-id", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
|
Packit |
79f644 |
{ "param-name", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
|
Packit |
79f644 |
{ NULL } } };
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static const SecretSchema room_keyring_schema =
|
|
Packit |
79f644 |
{ "org.gnome.Empathy.Room", SECRET_SCHEMA_DONT_MATCH_NAME,
|
|
Packit |
79f644 |
{ { "account-id", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
|
Packit |
79f644 |
{ "room-id", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
|
Packit |
79f644 |
{ NULL } } };
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* get */
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
lookup_item_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
gchar *password;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
password = secret_password_lookup_finish (result, &error);
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (simple, TP_ERROR,
|
|
Packit |
79f644 |
TP_ERROR_DOES_NOT_EXIST, "%s", error->message);
|
|
Packit |
79f644 |
g_clear_error (&error);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (password == NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (simple, TP_ERROR,
|
|
Packit |
79f644 |
TP_ERROR_DOES_NOT_EXIST, _("Password not found"));
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_simple_async_result_set_op_res_gpointer (simple, password,
|
|
Packit |
79f644 |
(GDestroyNotify) secret_password_free);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
out:
|
|
Packit |
79f644 |
g_simple_async_result_complete (simple);
|
|
Packit |
79f644 |
g_object_unref (simple);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef HAVE_UOA
|
|
Packit |
79f644 |
static AgAccountService *
|
|
Packit |
79f644 |
uoa_password_common (TpAccount *tp_account,
|
|
Packit |
79f644 |
GSimpleAsyncResult *result,
|
|
Packit |
79f644 |
AgAuthData **ret_auth_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const GValue *storage_id;
|
|
Packit |
79f644 |
AgAccountId account_id;
|
|
Packit |
79f644 |
AgManager *manager = NULL;
|
|
Packit |
79f644 |
AgAccount *account = NULL;
|
|
Packit |
79f644 |
GList *l;
|
|
Packit |
79f644 |
AgAccountService *service = NULL;
|
|
Packit |
79f644 |
AgAuthData *auth_data = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_assert (ret_auth_data != NULL);
|
|
Packit |
79f644 |
*ret_auth_data = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
storage_id = tp_account_get_storage_identifier (tp_account);
|
|
Packit |
79f644 |
account_id = g_value_get_uint (storage_id);
|
|
Packit |
79f644 |
if (account_id == 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (result,
|
|
Packit |
79f644 |
TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
|
|
Packit |
79f644 |
"StorageId is invalid, cannot get the AgAccount for this TpAccount");
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (result);
|
|
Packit |
79f644 |
goto error;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
manager = tpaw_uoa_manager_dup ();
|
|
Packit |
79f644 |
account = ag_manager_get_account (manager, account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* Assuming there is only one IM service */
|
|
Packit |
79f644 |
l = ag_account_list_services_by_type (account, TPAW_UOA_SERVICE_TYPE);
|
|
Packit |
79f644 |
if (l == NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (result,
|
|
Packit |
79f644 |
TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
|
|
Packit |
79f644 |
"AgAccount has no IM service");
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (result);
|
|
Packit |
79f644 |
goto error;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
service = ag_account_service_new (account, l->data);
|
|
Packit |
79f644 |
ag_service_list_free (l);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
auth_data = ag_account_service_get_auth_data (service);
|
|
Packit |
79f644 |
if (auth_data == NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (result,
|
|
Packit |
79f644 |
TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
|
|
Packit |
79f644 |
"Service has no AgAuthData");
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (result);
|
|
Packit |
79f644 |
goto error;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (tp_strdiff (ag_auth_data_get_mechanism (auth_data), "password") ||
|
|
Packit |
79f644 |
tp_strdiff (ag_auth_data_get_method (auth_data), "password"))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (result,
|
|
Packit |
79f644 |
TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
|
|
Packit |
79f644 |
"Service does not use password authentication");
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (result);
|
|
Packit |
79f644 |
goto error;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_object_unref (manager);
|
|
Packit |
79f644 |
g_object_unref (account);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
*ret_auth_data = auth_data;
|
|
Packit |
79f644 |
return service;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
error:
|
|
Packit |
79f644 |
g_clear_object (&manager);
|
|
Packit |
79f644 |
g_clear_object (&account);
|
|
Packit |
79f644 |
g_clear_object (&service);
|
|
Packit |
79f644 |
tp_clear_pointer (&auth_data, ag_auth_data_unref);
|
|
Packit |
79f644 |
return NULL;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_session_process_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *res,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
SignonAuthSession *session = (SignonAuthSession *) source;
|
|
Packit |
79f644 |
GSimpleAsyncResult *result = user_data;
|
|
Packit |
79f644 |
GVariant *session_data;
|
|
Packit |
79f644 |
gchar *password;
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
session_data = signon_auth_session_process_finish (session, res, &error);
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_take_error (result, error);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!g_variant_lookup (session_data, "Secret", "s", &password))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (result, TP_ERROR,
|
|
Packit |
79f644 |
TP_ERROR_DOES_NOT_EXIST, _("Password not found"));
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_simple_async_result_set_op_res_gpointer (result, password, g_free);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
out:
|
|
Packit |
79f644 |
g_simple_async_result_complete (result);
|
|
Packit |
79f644 |
g_object_unref (result);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_get_account_password (TpAccount *tp_account,
|
|
Packit |
79f644 |
GSimpleAsyncResult *result)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
AgAccountService *service;
|
|
Packit |
79f644 |
AgAuthData *auth_data;
|
|
Packit |
79f644 |
guint cred_id;
|
|
Packit |
79f644 |
SignonIdentity *identity;
|
|
Packit |
79f644 |
SignonAuthSession *session;
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Store password for %s in signond",
|
|
Packit |
79f644 |
tp_account_get_path_suffix (tp_account));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
service = uoa_password_common (tp_account, result, &auth_data);
|
|
Packit |
79f644 |
if (service == NULL)
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
cred_id = ag_auth_data_get_credentials_id (auth_data);
|
|
Packit |
79f644 |
if (cred_id == 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (result,
|
|
Packit |
79f644 |
TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
|
|
Packit |
79f644 |
"AgAccount has no CredentialsId");
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (result);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
identity = signon_identity_new_from_db (cred_id);
|
|
Packit |
79f644 |
session = signon_identity_create_session (identity,
|
|
Packit |
79f644 |
ag_auth_data_get_method (auth_data), &error);
|
|
Packit |
79f644 |
g_object_unref (identity);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (session == NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_from_error (result, error);
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (result);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
signon_auth_session_process_async (session,
|
|
Packit |
79f644 |
ag_auth_data_get_login_parameters (auth_data, NULL),
|
|
Packit |
79f644 |
ag_auth_data_get_mechanism (auth_data),
|
|
Packit |
79f644 |
NULL,
|
|
Packit |
79f644 |
uoa_session_process_cb,
|
|
Packit |
79f644 |
g_object_ref (result));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_object_unref (session);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
out:
|
|
Packit |
79f644 |
ag_auth_data_unref (auth_data);
|
|
Packit |
79f644 |
g_object_unref (service);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_keyring_get_account_password_async (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple;
|
|
Packit |
79f644 |
const gchar *account_id;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_if_fail (TP_IS_ACCOUNT (account));
|
|
Packit |
79f644 |
g_return_if_fail (callback != NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
simple = g_simple_async_result_new (G_OBJECT (account), callback,
|
|
Packit |
79f644 |
user_data, tpaw_keyring_get_account_password_async);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
account_id = tp_proxy_get_object_path (account) +
|
|
Packit |
79f644 |
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Trying to get password for: %s", account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef HAVE_UOA
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *provider;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
provider = tp_account_get_storage_provider (account);
|
|
Packit |
79f644 |
if (!tp_strdiff (provider, TPAW_UOA_PROVIDER))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
uoa_get_account_password (account, simple);
|
|
Packit |
79f644 |
g_object_unref (simple);
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
secret_password_lookup (&account_keyring_schema, NULL,
|
|
Packit |
79f644 |
lookup_item_cb, simple,
|
|
Packit |
79f644 |
"account-id", account_id,
|
|
Packit |
79f644 |
"param-name", "password",
|
|
Packit |
79f644 |
NULL);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_keyring_get_room_password_async (TpAccount *account,
|
|
Packit |
79f644 |
const gchar *id,
|
|
Packit |
79f644 |
GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple;
|
|
Packit |
79f644 |
const gchar *account_id;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_if_fail (TP_IS_ACCOUNT (account));
|
|
Packit |
79f644 |
g_return_if_fail (id != NULL);
|
|
Packit |
79f644 |
g_return_if_fail (callback != NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
simple = g_simple_async_result_new (G_OBJECT (account), callback,
|
|
Packit |
79f644 |
user_data, tpaw_keyring_get_room_password_async);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
account_id = tp_proxy_get_object_path (account) +
|
|
Packit |
79f644 |
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Trying to get password for room '%s' on account '%s'",
|
|
Packit |
79f644 |
id, account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
secret_password_lookup (&room_keyring_schema, NULL,
|
|
Packit |
79f644 |
lookup_item_cb, simple,
|
|
Packit |
79f644 |
"account-id", account_id,
|
|
Packit |
79f644 |
"room-id", id,
|
|
Packit |
79f644 |
NULL);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_keyring_get_account_password_finish (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
GError **error)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
tpaw_implement_finish_return_pointer (account,
|
|
Packit |
79f644 |
tpaw_keyring_get_account_password_async);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_keyring_get_room_password_finish (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
GError **error)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
tpaw_implement_finish_return_pointer (account,
|
|
Packit |
79f644 |
tpaw_keyring_get_room_password_async);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* set */
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
store_password_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!secret_password_store_finish (result, &error))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (simple, TP_ERROR,
|
|
Packit |
79f644 |
TP_ERROR_DOES_NOT_EXIST, "%s", error->message);
|
|
Packit |
79f644 |
g_error_free (error);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_simple_async_result_complete (simple);
|
|
Packit |
79f644 |
g_object_unref (simple);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef HAVE_UOA
|
|
Packit |
79f644 |
typedef struct
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
AgAccountService *service;
|
|
Packit |
79f644 |
gchar *password;
|
|
Packit |
79f644 |
gboolean remember;
|
|
Packit |
79f644 |
GSimpleAsyncResult *result;
|
|
Packit |
79f644 |
} UoaChangePasswordData;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static UoaChangePasswordData *
|
|
Packit |
79f644 |
uoa_change_password_data_new (AgAccountService *service,
|
|
Packit |
79f644 |
const gchar *password,
|
|
Packit |
79f644 |
gboolean remember,
|
|
Packit |
79f644 |
GSimpleAsyncResult *result)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
UoaChangePasswordData *data;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
data = g_slice_new0 (UoaChangePasswordData);
|
|
Packit |
79f644 |
data->service = g_object_ref (service);
|
|
Packit |
79f644 |
data->password = g_strdup (password);
|
|
Packit |
79f644 |
data->remember = remember;
|
|
Packit |
79f644 |
data->result = g_object_ref (result);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return data;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_change_password_data_free (UoaChangePasswordData *data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_object_unref (data->service);
|
|
Packit |
79f644 |
g_free (data->password);
|
|
Packit |
79f644 |
g_object_unref (data->result);
|
|
Packit |
79f644 |
g_slice_free (UoaChangePasswordData, data);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_identity_store_cb (SignonIdentity *identity,
|
|
Packit |
79f644 |
guint32 id,
|
|
Packit |
79f644 |
const GError *error,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
UoaChangePasswordData *data = user_data;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
g_simple_async_result_set_from_error (data->result, error);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_simple_async_result_complete (data->result);
|
|
Packit |
79f644 |
uoa_change_password_data_free (data);
|
|
Packit |
79f644 |
g_object_unref (identity);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_identity_query_info_cb (SignonIdentity *identity,
|
|
Packit |
79f644 |
const SignonIdentityInfo *info,
|
|
Packit |
79f644 |
const GError *error,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
UoaChangePasswordData *data = user_data;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_from_error (data->result, error);
|
|
Packit |
79f644 |
/* libaccounts-glib API does not guarantee the callback happens after
|
|
Packit |
79f644 |
* reentering mainloop */
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (data->result);
|
|
Packit |
79f644 |
uoa_change_password_data_free (data);
|
|
Packit |
79f644 |
g_object_unref (identity);
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* const SignonIdentityInfo is a lie, cast it! - Mardy */
|
|
Packit |
79f644 |
signon_identity_info_set_secret ((SignonIdentityInfo *) info,
|
|
Packit |
79f644 |
data->password, data->remember);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
signon_identity_store_credentials_with_info (identity, info,
|
|
Packit |
79f644 |
uoa_identity_store_cb, data);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_initial_account_store_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
AgAccount *account = (AgAccount *) source;
|
|
Packit |
79f644 |
UoaChangePasswordData *data = user_data;
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!ag_account_store_finish (account, result, &error))
|
|
Packit |
79f644 |
g_simple_async_result_take_error (data->result, error);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_simple_async_result_complete (data->result);
|
|
Packit |
79f644 |
uoa_change_password_data_free (data);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_initial_identity_store_cb (SignonIdentity *identity,
|
|
Packit |
79f644 |
guint32 id,
|
|
Packit |
79f644 |
const GError *error,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
UoaChangePasswordData *data = user_data;
|
|
Packit |
79f644 |
AgAccount *account = ag_account_service_get_account (data->service);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_from_error (data->result, error);
|
|
Packit |
79f644 |
/* libaccounts-glib API does not guarantee the callback happens after
|
|
Packit |
79f644 |
* reentering mainloop */
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (data->result);
|
|
Packit |
79f644 |
uoa_change_password_data_free (data);
|
|
Packit |
79f644 |
g_object_unref (identity);
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
ag_account_select_service (account, NULL);
|
|
Packit |
79f644 |
ag_account_set_variant (account, "CredentialsId", g_variant_new_uint32 (id));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
ag_account_store_async (account, NULL, uoa_initial_account_store_cb, data);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_object_unref (identity);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
uoa_set_account_password (TpAccount *tp_account,
|
|
Packit |
79f644 |
const gchar *password,
|
|
Packit |
79f644 |
gboolean remember,
|
|
Packit |
79f644 |
GSimpleAsyncResult *result)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
AgAccountService *service;
|
|
Packit |
79f644 |
AgAuthData *auth_data;
|
|
Packit |
79f644 |
guint cred_id;
|
|
Packit |
79f644 |
UoaChangePasswordData *data;
|
|
Packit |
79f644 |
SignonIdentity *identity;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Store password for %s in signond",
|
|
Packit |
79f644 |
tp_account_get_path_suffix (tp_account));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
service = uoa_password_common (tp_account, result, &auth_data);
|
|
Packit |
79f644 |
if (service == NULL)
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
data = uoa_change_password_data_new (service, password, remember, result);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
cred_id = ag_auth_data_get_credentials_id (auth_data);
|
|
Packit |
79f644 |
if (cred_id == 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
SignonIdentityInfo *info;
|
|
Packit |
79f644 |
const GHashTable *params;
|
|
Packit |
79f644 |
const gchar *username;
|
|
Packit |
79f644 |
const gchar *acl_all[] = { "*", NULL };
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* This is the first time we store password for this account.
|
|
Packit |
79f644 |
* First check if we have an 'username' param as this is more accurate
|
|
Packit |
79f644 |
* in the tp-idle case. */
|
|
Packit |
79f644 |
params = tp_account_get_parameters (tp_account);
|
|
Packit |
79f644 |
username = tp_asv_get_string (params, "username");
|
|
Packit |
79f644 |
if (username == NULL)
|
|
Packit |
79f644 |
username = tp_asv_get_string (params, "account");
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
identity = signon_identity_new ();
|
|
Packit |
79f644 |
info = signon_identity_info_new ();
|
|
Packit |
79f644 |
signon_identity_info_set_username (info, username);
|
|
Packit |
79f644 |
signon_identity_info_set_secret (info, password, remember);
|
|
Packit |
79f644 |
signon_identity_info_set_access_control_list (info, acl_all);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* Give identity and data ownership to the callback */
|
|
Packit |
79f644 |
signon_identity_store_credentials_with_info (identity, info,
|
|
Packit |
79f644 |
uoa_initial_identity_store_cb, data);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
signon_identity_info_free (info);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
else
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
/* There is already a password stored, query info to update it.
|
|
Packit |
79f644 |
* Give identity and data ownership to the callback */
|
|
Packit |
79f644 |
identity = signon_identity_new_from_db (cred_id);
|
|
Packit |
79f644 |
signon_identity_query_info (identity,
|
|
Packit |
79f644 |
uoa_identity_query_info_cb, data);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_object_unref (service);
|
|
Packit |
79f644 |
ag_auth_data_unref (auth_data);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_keyring_set_account_password_async (TpAccount *account,
|
|
Packit |
79f644 |
const gchar *password,
|
|
Packit |
79f644 |
gboolean remember,
|
|
Packit |
79f644 |
GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple;
|
|
Packit |
79f644 |
const gchar *account_id;
|
|
Packit |
79f644 |
gchar *name;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_if_fail (TP_IS_ACCOUNT (account));
|
|
Packit |
79f644 |
g_return_if_fail (password != NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
simple = g_simple_async_result_new (G_OBJECT (account), callback,
|
|
Packit |
79f644 |
user_data, tpaw_keyring_set_account_password_async);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
account_id = tp_proxy_get_object_path (account) +
|
|
Packit |
79f644 |
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Remembering password for %s", account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef HAVE_UOA
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *provider;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
provider = tp_account_get_storage_provider (account);
|
|
Packit |
79f644 |
if (!tp_strdiff (provider, TPAW_UOA_PROVIDER))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
uoa_set_account_password (account, password, remember, simple);
|
|
Packit |
79f644 |
g_object_unref (simple);
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
name = g_strdup_printf (_("IM account password for %s (%s)"),
|
|
Packit |
79f644 |
tp_account_get_display_name (account), account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
secret_password_store (&account_keyring_schema,
|
|
Packit |
79f644 |
remember ? NULL : SECRET_COLLECTION_SESSION,
|
|
Packit |
79f644 |
name, password,
|
|
Packit |
79f644 |
NULL, store_password_cb, simple,
|
|
Packit |
79f644 |
"account-id", account_id,
|
|
Packit |
79f644 |
"param-name", "password",
|
|
Packit |
79f644 |
NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (name);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_keyring_set_room_password_async (TpAccount *account,
|
|
Packit |
79f644 |
const gchar *id,
|
|
Packit |
79f644 |
const gchar *password,
|
|
Packit |
79f644 |
GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple;
|
|
Packit |
79f644 |
const gchar *account_id;
|
|
Packit |
79f644 |
gchar *name;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_if_fail (TP_IS_ACCOUNT (account));
|
|
Packit |
79f644 |
g_return_if_fail (id != NULL);
|
|
Packit |
79f644 |
g_return_if_fail (password != NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
simple = g_simple_async_result_new (G_OBJECT (account), callback,
|
|
Packit |
79f644 |
user_data, tpaw_keyring_set_room_password_async);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
account_id = tp_proxy_get_object_path (account) +
|
|
Packit |
79f644 |
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Remembering password for room '%s' on account '%s'", id, account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
name = g_strdup_printf (_("Password for chatroom ā%sā on account %s (%s)"),
|
|
Packit |
79f644 |
id, tp_account_get_display_name (account), account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
secret_password_store (&room_keyring_schema, NULL, name, password,
|
|
Packit |
79f644 |
NULL, store_password_cb, simple,
|
|
Packit |
79f644 |
"account-id", account_id,
|
|
Packit |
79f644 |
"room-id", id,
|
|
Packit |
79f644 |
NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (name);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gboolean
|
|
Packit |
79f644 |
tpaw_keyring_set_account_password_finish (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
GError **error)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
tpaw_implement_finish_void (account, tpaw_keyring_set_account_password_async);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gboolean
|
|
Packit |
79f644 |
tpaw_keyring_set_room_password_finish (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
GError **error)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
tpaw_implement_finish_void (account, tpaw_keyring_set_room_password_async);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* delete */
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
items_delete_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
secret_password_clear_finish (result, &error);
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_set_error (simple, TP_ERROR,
|
|
Packit |
79f644 |
TP_ERROR_DOES_NOT_EXIST, "%s", error->message);
|
|
Packit |
79f644 |
g_error_free (error);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_simple_async_result_complete (simple);
|
|
Packit |
79f644 |
g_object_unref (simple);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_keyring_delete_account_password_async (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple;
|
|
Packit |
79f644 |
const gchar *account_id;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_if_fail (TP_IS_ACCOUNT (account));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
simple = g_simple_async_result_new (G_OBJECT (account), callback,
|
|
Packit |
79f644 |
user_data, tpaw_keyring_delete_account_password_async);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
account_id = tp_proxy_get_object_path (account) +
|
|
Packit |
79f644 |
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
DEBUG ("Deleting password for %s", account_id);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef HAVE_UOA
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *provider;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
provider = tp_account_get_storage_provider (account);
|
|
Packit |
79f644 |
if (!tp_strdiff (provider, TPAW_UOA_PROVIDER))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
/* I see no other way to forget the stored password than overwriting
|
|
Packit |
79f644 |
* with an empty one. */
|
|
Packit |
79f644 |
uoa_set_account_password (account, "", FALSE, simple);
|
|
Packit |
79f644 |
g_object_unref (simple);
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
secret_password_clear (&account_keyring_schema, NULL,
|
|
Packit |
79f644 |
items_delete_cb, simple,
|
|
Packit |
79f644 |
"account-id", account_id,
|
|
Packit |
79f644 |
"param-name", "password",
|
|
Packit |
79f644 |
NULL);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gboolean
|
|
Packit |
79f644 |
tpaw_keyring_delete_account_password_finish (TpAccount *account,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
GError **error)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
tpaw_implement_finish_void (account, tpaw_keyring_delete_account_password_async);
|
|
Packit |
79f644 |
}
|