2008-11-03 04:45:50 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager system settings service
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* (C) Copyright 2008 Novell, Inc.
|
2011-01-26 10:17:07 -06:00
|
|
|
* (C) Copyright 2008 - 2011 Red Hat, Inc.
|
2008-11-03 04:45:50 +00:00
|
|
|
*/
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
#include <NetworkManager.h>
|
2009-07-23 09:20:52 -04:00
|
|
|
#include <dbus/dbus-glib-lowlevel.h>
|
2010-08-02 20:15:16 -04:00
|
|
|
#include <nm-setting-connection.h>
|
2010-08-15 03:25:58 -04:00
|
|
|
#include <nm-utils.h>
|
2009-07-23 09:20:52 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
#include "nm-settings-connection.h"
|
2010-10-26 11:15:19 -05:00
|
|
|
#include "nm-session-monitor.h"
|
2010-08-15 03:25:58 -04:00
|
|
|
#include "nm-dbus-manager.h"
|
2010-10-27 20:38:26 -05:00
|
|
|
#include "nm-settings-error.h"
|
2009-04-04 11:37:11 -04:00
|
|
|
#include "nm-dbus-glib-types.h"
|
2009-07-23 09:20:52 -04:00
|
|
|
#include "nm-polkit-helpers.h"
|
2010-04-07 12:27:34 -07:00
|
|
|
#include "nm-logging.h"
|
2010-08-26 14:26:12 -05:00
|
|
|
#include "nm-manager-auth.h"
|
2011-01-26 17:13:15 -06:00
|
|
|
#include "nm-marshal.h"
|
2011-01-27 10:41:02 -06:00
|
|
|
#include "nm-agent-manager.h"
|
2009-07-23 09:20:52 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
static void impl_settings_connection_get_settings (NMSettingsConnection *connection,
|
|
|
|
|
DBusGMethodInvocation *context);
|
2010-08-02 20:15:16 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
static void impl_settings_connection_update (NMSettingsConnection *connection,
|
|
|
|
|
GHashTable *new_settings,
|
|
|
|
|
DBusGMethodInvocation *context);
|
2010-08-02 20:15:16 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
static void impl_settings_connection_delete (NMSettingsConnection *connection,
|
|
|
|
|
DBusGMethodInvocation *context);
|
2010-08-02 20:15:16 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
static void impl_settings_connection_get_secrets (NMSettingsConnection *connection,
|
|
|
|
|
const gchar *setting_name,
|
|
|
|
|
DBusGMethodInvocation *context);
|
2010-08-02 20:15:16 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
#include "nm-settings-connection-glue.h"
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
G_DEFINE_TYPE (NMSettingsConnection, nm_settings_connection, NM_TYPE_CONNECTION)
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
#define NM_SETTINGS_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
|
|
|
|
NM_TYPE_SETTINGS_CONNECTION, \
|
|
|
|
|
NMSettingsConnectionPrivate))
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
enum {
|
|
|
|
|
PROP_0 = 0,
|
|
|
|
|
PROP_VISIBLE,
|
|
|
|
|
};
|
|
|
|
|
|
2010-08-05 18:25:15 -04:00
|
|
|
enum {
|
|
|
|
|
UPDATED,
|
|
|
|
|
REMOVED,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
typedef struct {
|
2011-01-26 17:13:15 -06:00
|
|
|
gboolean disposed;
|
|
|
|
|
|
2011-01-27 10:41:02 -06:00
|
|
|
NMDBusManager *dbus_mgr;
|
|
|
|
|
NMAgentManager *agent_mgr;
|
|
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
PolkitAuthority *authority;
|
2010-11-18 14:24:58 -06:00
|
|
|
GSList *pending_auths; /* List of pending authentication requests */
|
2009-11-16 16:48:59 -08:00
|
|
|
NMConnection *secrets;
|
2010-08-15 03:25:58 -04:00
|
|
|
gboolean visible; /* Is this connection is visible by some session? */
|
2010-10-26 16:33:47 -05:00
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
GSList *reqs; /* in-progress secrets requests */
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
NMSessionMonitor *session_monitor;
|
2010-10-26 16:33:47 -05:00
|
|
|
guint session_changed_id;
|
2011-01-26 11:38:12 -06:00
|
|
|
} NMSettingsConnectionPrivate;
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
#define USER_TAG "user:"
|
|
|
|
|
|
|
|
|
|
/* Extract the username from the permission string and dump to a buffer */
|
2010-08-15 03:25:58 -04:00
|
|
|
static gboolean
|
2010-10-26 11:15:19 -05:00
|
|
|
perm_to_user (const char *perm, char *out_user, gsize out_user_size)
|
2010-08-15 03:25:58 -04:00
|
|
|
{
|
2010-10-26 11:15:19 -05:00
|
|
|
const char *end;
|
|
|
|
|
gsize userlen;
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
g_return_val_if_fail (perm != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (out_user != NULL, FALSE);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
if (!g_str_has_prefix (perm, USER_TAG))
|
|
|
|
|
return FALSE;
|
|
|
|
|
perm += strlen (USER_TAG);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
/* Look for trailing ':' */
|
|
|
|
|
end = strchr (perm, ':');
|
|
|
|
|
if (!end)
|
|
|
|
|
end = perm + strlen (perm);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
userlen = end - perm;
|
|
|
|
|
if (userlen > (out_user_size + 1))
|
|
|
|
|
return FALSE;
|
|
|
|
|
memcpy (out_user, perm, userlen);
|
|
|
|
|
out_user[userlen] = '\0';
|
|
|
|
|
return TRUE;
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
set_visible (NMSettingsConnection *self, gboolean new_visible)
|
2010-08-15 03:25:58 -04:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
if (new_visible == priv->visible)
|
|
|
|
|
return;
|
|
|
|
|
priv->visible = new_visible;
|
2011-01-26 11:38:12 -06:00
|
|
|
g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTION_VISIBLE);
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_is_visible (NMSettingsConnection *self)
|
2010-08-15 03:25:58 -04:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
g_return_val_if_fail (NM_SETTINGS_CONNECTION (self), FALSE);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->visible;
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
void
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_recheck_visibility (NMSettingsConnection *self)
|
2010-08-15 03:25:58 -04:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnectionPrivate *priv;
|
2010-10-26 11:15:19 -05:00
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
guint32 num, i;
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
g_return_if_fail (NM_SETTINGS_CONNECTION (self));
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (self), NM_TYPE_SETTING_CONNECTION);
|
2010-10-26 11:15:19 -05:00
|
|
|
g_assert (s_con);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
/* Check every user in the ACL for a session */
|
|
|
|
|
num = nm_setting_connection_get_num_permissions (s_con);
|
|
|
|
|
if (num == 0) {
|
|
|
|
|
/* Visible to all */
|
|
|
|
|
set_visible (self, TRUE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
|
const char *perm;
|
|
|
|
|
char buf[75];
|
|
|
|
|
|
|
|
|
|
perm = nm_setting_connection_get_permission (s_con, i);
|
|
|
|
|
g_assert (perm);
|
|
|
|
|
if (perm_to_user (perm, buf, sizeof (buf))) {
|
|
|
|
|
if (nm_session_monitor_user_has_session (priv->session_monitor, buf, NULL, NULL)) {
|
|
|
|
|
set_visible (self, TRUE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_visible (self, FALSE);
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2010-10-26 16:33:47 -05:00
|
|
|
static void
|
|
|
|
|
session_changed_cb (NMSessionMonitor *self, gpointer user_data)
|
|
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_recheck_visibility (NM_SETTINGS_CONNECTION (user_data));
|
2010-10-26 16:33:47 -05:00
|
|
|
}
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
2010-08-04 04:45:43 -04:00
|
|
|
/* Update the settings of this connection to match that of 'new', taking care to
|
|
|
|
|
* make a private copy of secrets. */
|
2009-11-16 15:51:40 -08:00
|
|
|
gboolean
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_replace_settings (NMSettingsConnection *self,
|
|
|
|
|
NMConnection *new,
|
|
|
|
|
GError **error)
|
2009-11-16 15:51:40 -08:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnectionPrivate *priv;
|
2009-11-16 15:51:40 -08:00
|
|
|
GHashTable *new_settings;
|
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
2009-11-16 16:48:59 -08:00
|
|
|
g_return_val_if_fail (self != NULL, FALSE);
|
2011-01-26 11:38:12 -06:00
|
|
|
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE);
|
2009-11-16 16:48:59 -08:00
|
|
|
g_return_val_if_fail (new != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (NM_IS_CONNECTION (new), FALSE);
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2009-11-16 16:48:59 -08:00
|
|
|
|
2011-01-26 14:14:37 -06:00
|
|
|
new_settings = nm_connection_to_hash (new, NM_SETTING_HASH_FLAG_ALL);
|
2009-11-16 15:51:40 -08:00
|
|
|
g_assert (new_settings);
|
|
|
|
|
if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, error)) {
|
2009-11-16 16:48:59 -08:00
|
|
|
/* Copy the connection to keep its secrets around even if NM
|
|
|
|
|
* calls nm_connection_clear_secrets().
|
|
|
|
|
*/
|
|
|
|
|
if (priv->secrets)
|
|
|
|
|
g_object_unref (priv->secrets);
|
|
|
|
|
priv->secrets = nm_connection_duplicate (NM_CONNECTION (self));
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_recheck_visibility (self);
|
2009-11-16 15:51:40 -08:00
|
|
|
success = TRUE;
|
|
|
|
|
}
|
|
|
|
|
g_hash_table_destroy (new_settings);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-04 04:45:43 -04:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
ignore_cb (NMSettingsConnection *connection,
|
2010-08-04 04:45:43 -04:00
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Replaces the settings in this connection with those in 'new'. If any changes
|
|
|
|
|
* are made, commits them to permanent storage and to any other subsystems
|
|
|
|
|
* watching this connection. Before returning, 'callback' is run with the given
|
|
|
|
|
* 'user_data' along with any errors encountered.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_replace_and_commit (NMSettingsConnection *self,
|
|
|
|
|
NMConnection *new,
|
|
|
|
|
NMSettingsConnectionCommitFunc callback,
|
|
|
|
|
gpointer user_data)
|
2010-08-04 04:45:43 -04:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (self != NULL);
|
2011-01-26 11:38:12 -06:00
|
|
|
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
|
2010-08-04 04:45:43 -04:00
|
|
|
g_return_if_fail (new != NULL);
|
|
|
|
|
g_return_if_fail (NM_IS_CONNECTION (new));
|
|
|
|
|
|
|
|
|
|
if (!callback)
|
|
|
|
|
callback = ignore_cb;
|
|
|
|
|
|
|
|
|
|
/* Do nothing if there's nothing to update */
|
|
|
|
|
if (nm_connection_compare (NM_CONNECTION (self),
|
|
|
|
|
NM_CONNECTION (new),
|
|
|
|
|
NM_SETTING_COMPARE_FLAG_EXACT)) {
|
2011-01-26 11:38:12 -06:00
|
|
|
callback (self, NULL, user_data);
|
|
|
|
|
return;
|
2010-08-04 04:45:43 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
if (nm_settings_connection_replace_settings (self, new, &error)) {
|
|
|
|
|
nm_settings_connection_commit_changes (self, callback, user_data);
|
2010-08-04 04:45:43 -04:00
|
|
|
} else {
|
2010-08-05 18:25:15 -04:00
|
|
|
callback (self, error, user_data);
|
2010-08-04 04:45:43 -04:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-05 18:25:15 -04:00
|
|
|
void
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_commit_changes (NMSettingsConnection *connection,
|
|
|
|
|
NMSettingsConnectionCommitFunc callback,
|
|
|
|
|
gpointer user_data)
|
2010-08-05 18:25:15 -04:00
|
|
|
{
|
|
|
|
|
g_return_if_fail (connection != NULL);
|
2011-01-26 11:38:12 -06:00
|
|
|
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
|
2010-08-05 18:25:15 -04:00
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
if (NM_SETTINGS_CONNECTION_GET_CLASS (connection)->commit_changes) {
|
|
|
|
|
NM_SETTINGS_CONNECTION_GET_CLASS (connection)->commit_changes (connection,
|
|
|
|
|
callback,
|
|
|
|
|
user_data);
|
2010-08-05 18:25:15 -04:00
|
|
|
} else {
|
2010-10-27 20:38:26 -05:00
|
|
|
GError *error = g_error_new (NM_SETTINGS_ERROR,
|
|
|
|
|
NM_SETTINGS_ERROR_INTERNAL_ERROR,
|
2010-08-05 18:25:15 -04:00
|
|
|
"%s: %s:%d commit_changes() unimplemented", __func__, __FILE__, __LINE__);
|
|
|
|
|
callback (connection, error, user_data);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_delete (NMSettingsConnection *connection,
|
|
|
|
|
NMSettingsConnectionDeleteFunc callback,
|
|
|
|
|
gpointer user_data)
|
2010-08-05 18:25:15 -04:00
|
|
|
{
|
|
|
|
|
g_return_if_fail (connection != NULL);
|
2011-01-26 11:38:12 -06:00
|
|
|
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
|
2010-08-05 18:25:15 -04:00
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
if (NM_SETTINGS_CONNECTION_GET_CLASS (connection)->delete) {
|
|
|
|
|
NM_SETTINGS_CONNECTION_GET_CLASS (connection)->delete (connection,
|
|
|
|
|
callback,
|
|
|
|
|
user_data);
|
2010-08-05 18:25:15 -04:00
|
|
|
} else {
|
2010-10-27 20:38:26 -05:00
|
|
|
GError *error = g_error_new (NM_SETTINGS_ERROR,
|
|
|
|
|
NM_SETTINGS_ERROR_INTERNAL_ERROR,
|
2010-08-05 18:25:15 -04:00
|
|
|
"%s: %s:%d delete() unimplemented", __func__, __FILE__, __LINE__);
|
|
|
|
|
callback (connection, error, user_data);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
commit_changes (NMSettingsConnection *connection,
|
|
|
|
|
NMSettingsConnectionCommitFunc callback,
|
2010-08-05 18:25:15 -04:00
|
|
|
gpointer user_data)
|
2010-08-02 20:15:16 -04:00
|
|
|
{
|
|
|
|
|
g_object_ref (connection);
|
2010-12-02 14:34:38 -06:00
|
|
|
g_signal_emit (connection, signals[UPDATED], 0);
|
2010-08-02 20:15:16 -04:00
|
|
|
callback (connection, NULL, user_data);
|
|
|
|
|
g_object_unref (connection);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-05 18:25:15 -04:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
do_delete (NMSettingsConnection *connection,
|
|
|
|
|
NMSettingsConnectionDeleteFunc callback,
|
|
|
|
|
gpointer user_data)
|
2010-08-02 20:15:16 -04:00
|
|
|
{
|
|
|
|
|
g_object_ref (connection);
|
2010-10-26 11:15:19 -05:00
|
|
|
set_visible (connection, FALSE);
|
2010-10-26 11:36:38 -05:00
|
|
|
g_signal_emit (connection, signals[REMOVED], 0);
|
2010-08-02 20:15:16 -04:00
|
|
|
callback (connection, NULL, user_data);
|
|
|
|
|
g_object_unref (connection);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-12 21:17:34 -06:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-01-26 11:38:12 -06:00
|
|
|
supports_secrets (NMSettingsConnection *connection, const char *setting_name)
|
2010-12-12 21:17:34 -06:00
|
|
|
{
|
|
|
|
|
/* All secrets supported */
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 10:41:02 -06:00
|
|
|
static void
|
|
|
|
|
agent_secrets_done_cb (NMAgentManager *manager,
|
|
|
|
|
guint32 call_id,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
GHashTable *secrets,
|
|
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
gpointer other_data2,
|
|
|
|
|
gpointer other_data3)
|
|
|
|
|
{
|
|
|
|
|
NMSettingsConnection *self = NM_SETTINGS_CONNECTION (user_data);
|
|
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
|
|
|
|
NMSettingsConnectionSecretsFunc callback = other_data2;
|
|
|
|
|
gpointer callback_data = other_data3;
|
|
|
|
|
GError *local = NULL;
|
|
|
|
|
GHashTable *hash;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
callback (self, call_id, setting_name, error, callback_data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Update the connection with the agent's secrets */
|
|
|
|
|
nm_connection_clear_secrets (NM_CONNECTION (self));
|
|
|
|
|
if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets, &local)) {
|
|
|
|
|
/* FIXME: if the agent's owner has "modify" permission, then agent
|
|
|
|
|
* supplied secrets should overwrite existing secrets, and those agent
|
|
|
|
|
* supplied secrets should get written back out to persistent storage.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
hash = nm_connection_to_hash (priv->secrets, NM_SETTING_HASH_FLAG_ONLY_SECRETS);
|
|
|
|
|
nm_connection_update_secrets (NM_CONNECTION (self), setting_name, hash, &local);
|
|
|
|
|
g_hash_table_destroy (hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback (self, call_id, setting_name, local, callback_data);
|
|
|
|
|
g_clear_error (&local);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-26 10:17:07 -06:00
|
|
|
/**
|
2011-01-26 11:38:12 -06:00
|
|
|
* nm_settings_connection_get_secrets:
|
|
|
|
|
* @connection: the #NMSettingsConnection
|
2011-01-27 10:41:02 -06:00
|
|
|
* @filter_by_uid: if TRUE, only request secrets from agents registered by the
|
|
|
|
|
* same UID as @uid.
|
|
|
|
|
* @uid: when @filter_by_uid is TRUE, only request secrets from agents belonging
|
|
|
|
|
* to this UID
|
2011-01-26 10:17:07 -06:00
|
|
|
* @setting_name: the setting to return secrets for
|
2011-01-27 10:41:02 -06:00
|
|
|
* @flags: flags to modify the secrets request
|
|
|
|
|
* @hint: the name of a key in @setting_name for which a secret may be required
|
|
|
|
|
* @callback: the function to call with returned secrets
|
|
|
|
|
* @callback_data: user data to pass to @callback
|
2011-01-26 10:17:07 -06:00
|
|
|
*
|
2011-01-27 10:41:02 -06:00
|
|
|
* Retrieves secrets from persistent storage and queries any secret agents for
|
|
|
|
|
* additional secrets.
|
2011-01-26 17:13:15 -06:00
|
|
|
*
|
2011-01-27 10:41:02 -06:00
|
|
|
* Returns: a call ID which may be used to cancel the ongoing secrets request
|
2011-01-26 10:17:07 -06:00
|
|
|
**/
|
2011-01-27 10:41:02 -06:00
|
|
|
guint32
|
|
|
|
|
nm_settings_connection_get_secrets (NMSettingsConnection *self,
|
|
|
|
|
gboolean filter_by_uid,
|
|
|
|
|
gulong uid,
|
2011-01-26 11:38:12 -06:00
|
|
|
const char *setting_name,
|
2011-01-27 10:41:02 -06:00
|
|
|
guint32 flags,
|
|
|
|
|
const char *hint,
|
|
|
|
|
NMSettingsConnectionSecretsFunc callback,
|
|
|
|
|
gpointer callback_data,
|
2011-01-26 11:38:12 -06:00
|
|
|
GError **error)
|
2009-04-04 11:37:11 -04:00
|
|
|
{
|
2011-01-27 10:41:02 -06:00
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
|
|
|
|
GHashTable *existing_secrets;
|
|
|
|
|
guint32 call_id = 0;
|
2009-04-04 11:37:11 -04:00
|
|
|
|
2009-11-16 16:48:59 -08:00
|
|
|
/* Use priv->secrets to work around the fact that nm_connection_clear_secrets()
|
|
|
|
|
* will clear secrets on this object's settings. priv->secrets should be
|
|
|
|
|
* a complete copy of this object and kept in sync by
|
2011-01-26 11:38:12 -06:00
|
|
|
* nm_settings_connection_replace_settings().
|
2009-11-16 16:48:59 -08:00
|
|
|
*/
|
|
|
|
|
if (!priv->secrets) {
|
2010-12-12 21:17:34 -06:00
|
|
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
|
|
|
|
"%s.%d - Internal error; secrets cache invalid.",
|
|
|
|
|
__FILE__, __LINE__);
|
2011-01-27 10:41:02 -06:00
|
|
|
return 0;
|
2009-11-16 16:48:59 -08:00
|
|
|
}
|
|
|
|
|
|
2011-01-26 10:17:07 -06:00
|
|
|
/* FIXME: if setting_name is empty, return all secrets */
|
|
|
|
|
|
2011-01-27 10:41:02 -06:00
|
|
|
if (!nm_connection_get_setting_by_name (priv->secrets, setting_name)) {
|
2010-12-12 21:17:34 -06:00
|
|
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_SETTING,
|
|
|
|
|
"%s.%d - Connection didn't have requested setting '%s'.",
|
|
|
|
|
__FILE__, __LINE__, setting_name);
|
2011-01-27 10:41:02 -06:00
|
|
|
return 0;
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-27 10:41:02 -06:00
|
|
|
existing_secrets = nm_connection_to_hash (priv->secrets, NM_SETTING_HASH_FLAG_ONLY_SECRETS);
|
|
|
|
|
call_id = nm_agent_manager_get_secrets (priv->agent_mgr,
|
|
|
|
|
NM_CONNECTION (self),
|
|
|
|
|
filter_by_uid,
|
|
|
|
|
uid,
|
|
|
|
|
existing_secrets,
|
|
|
|
|
setting_name,
|
|
|
|
|
flags,
|
|
|
|
|
hint,
|
|
|
|
|
agent_secrets_done_cb,
|
|
|
|
|
self,
|
|
|
|
|
callback,
|
|
|
|
|
callback_data);
|
|
|
|
|
g_hash_table_unref (existing_secrets);
|
|
|
|
|
|
|
|
|
|
return call_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_settings_connection_cancel_secrets (NMSettingsConnection *self,
|
|
|
|
|
guint32 call_id)
|
|
|
|
|
{
|
|
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id));
|
|
|
|
|
nm_agent_manager_cancel_secrets (priv->agent_mgr, call_id);
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
/**** User authorization **************************************/
|
2009-07-23 09:20:52 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
typedef void (*AuthCallback) (NMSettingsConnection *connection,
|
|
|
|
|
DBusGMethodInvocation *context,
|
2011-01-30 13:49:56 -06:00
|
|
|
gulong sender_uid,
|
2011-01-26 11:38:12 -06:00
|
|
|
GError *error,
|
|
|
|
|
gpointer data);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2011-01-30 13:49:56 -06:00
|
|
|
typedef struct {
|
|
|
|
|
AuthCallback callback;
|
|
|
|
|
gpointer callback_data;
|
|
|
|
|
gulong sender_uid;
|
|
|
|
|
} PkAuthInfo;
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
static void
|
2010-11-18 14:24:58 -06:00
|
|
|
pk_auth_cb (NMAuthChain *chain,
|
|
|
|
|
GError *chain_error,
|
|
|
|
|
DBusGMethodInvocation *context,
|
|
|
|
|
gpointer user_data)
|
2010-08-15 03:25:58 -04:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnection *self = NM_SETTINGS_CONNECTION (user_data);
|
|
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2010-08-15 03:25:58 -04:00
|
|
|
GError *error = NULL;
|
2010-11-18 14:24:58 -06:00
|
|
|
NMAuthCallResult result;
|
2011-01-30 13:49:56 -06:00
|
|
|
PkAuthInfo *info;
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-11-18 14:24:58 -06:00
|
|
|
priv->pending_auths = g_slist_remove (priv->pending_auths, chain);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
/* If our NMSettingsConnection is already gone, do nothing */
|
2010-11-18 14:24:58 -06:00
|
|
|
if (chain_error) {
|
|
|
|
|
error = g_error_new (NM_SETTINGS_ERROR,
|
|
|
|
|
NM_SETTINGS_ERROR_GENERAL,
|
|
|
|
|
"Error checking authorization: %s",
|
|
|
|
|
chain_error->message ? chain_error->message : "(unknown)");
|
|
|
|
|
} else {
|
|
|
|
|
result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_SETTINGS_CONNECTION_MODIFY);
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-11-18 14:24:58 -06:00
|
|
|
/* Caller didn't successfully authenticate */
|
|
|
|
|
if (result != NM_AUTH_CALL_RESULT_YES) {
|
|
|
|
|
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
2011-01-26 11:38:12 -06:00
|
|
|
NM_SETTINGS_ERROR_NOT_PRIVILEGED,
|
|
|
|
|
"Insufficient privileges.");
|
2010-11-18 14:24:58 -06:00
|
|
|
}
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-30 13:49:56 -06:00
|
|
|
info = nm_auth_chain_get_data (chain, "pk-auth-info");
|
|
|
|
|
info->callback (self, context, info->sender_uid, error, info->callback_data);
|
2010-10-26 11:15:19 -05:00
|
|
|
|
2010-11-18 14:24:58 -06:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
nm_auth_chain_unref (chain);
|
2010-08-05 01:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
auth_start (NMSettingsConnection *self,
|
2010-10-26 11:15:19 -05:00
|
|
|
DBusGMethodInvocation *context,
|
|
|
|
|
gboolean check_modify,
|
|
|
|
|
AuthCallback callback,
|
|
|
|
|
gpointer callback_data)
|
2010-08-15 03:25:58 -04:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2010-11-18 14:24:58 -06:00
|
|
|
NMAuthChain *chain;
|
2010-10-26 11:15:19 -05:00
|
|
|
gulong sender_uid = G_MAXULONG;
|
2011-01-30 13:49:56 -06:00
|
|
|
PkAuthInfo *info;
|
2010-08-15 03:25:58 -04:00
|
|
|
GError *error = NULL;
|
2010-11-18 13:47:04 -06:00
|
|
|
char *error_desc = NULL;
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
/* Get the caller's UID */
|
|
|
|
|
if (!nm_auth_get_caller_uid (context, NULL, &sender_uid, &error_desc)) {
|
2010-10-27 20:38:26 -05:00
|
|
|
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
|
|
|
|
NM_SETTINGS_ERROR_PERMISSION_DENIED,
|
2010-10-26 11:15:19 -05:00
|
|
|
error_desc);
|
2011-01-30 13:49:56 -06:00
|
|
|
g_free (error_desc);
|
2010-10-26 11:15:19 -05:00
|
|
|
goto error;
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
/* Make sure the UID can view this connection */
|
|
|
|
|
if (0 != sender_uid) {
|
2010-11-18 14:05:33 -06:00
|
|
|
if (!nm_auth_uid_in_acl (NM_CONNECTION (self),
|
|
|
|
|
priv->session_monitor,
|
|
|
|
|
sender_uid,
|
|
|
|
|
&error_desc)) {
|
|
|
|
|
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
2011-01-26 11:38:12 -06:00
|
|
|
NM_SETTINGS_ERROR_PERMISSION_DENIED,
|
|
|
|
|
error_desc);
|
2010-11-18 14:05:33 -06:00
|
|
|
g_free (error_desc);
|
2010-10-26 11:15:19 -05:00
|
|
|
goto error;
|
|
|
|
|
}
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2010-11-18 14:24:58 -06:00
|
|
|
if (check_modify) {
|
|
|
|
|
chain = nm_auth_chain_new (priv->authority, context, NULL, pk_auth_cb, self);
|
|
|
|
|
g_assert (chain);
|
2011-01-30 13:49:56 -06:00
|
|
|
|
|
|
|
|
info = g_malloc0 (sizeof (*info));
|
|
|
|
|
info->callback = callback;
|
|
|
|
|
info->callback_data = callback_data;
|
|
|
|
|
info->sender_uid = sender_uid;
|
|
|
|
|
nm_auth_chain_set_data (chain, "pk-auth-info", info, g_free);
|
|
|
|
|
|
2010-11-18 14:24:58 -06:00
|
|
|
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SETTINGS_CONNECTION_MODIFY, TRUE);
|
2011-01-30 13:49:56 -06:00
|
|
|
priv->pending_auths = g_slist_append (priv->pending_auths, chain);
|
2010-11-18 14:24:58 -06:00
|
|
|
} else {
|
|
|
|
|
/* Don't need polkit auth, automatic success */
|
2011-01-30 13:49:56 -06:00
|
|
|
callback (self, context, sender_uid, NULL, callback_data);
|
2010-10-26 11:15:19 -05:00
|
|
|
}
|
2010-08-15 03:25:58 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2011-01-30 13:49:56 -06:00
|
|
|
callback (self, context, G_MAXULONG, error, callback_data);
|
2010-10-26 11:15:19 -05:00
|
|
|
g_error_free (error);
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**** DBus method handlers ************************************/
|
|
|
|
|
|
2010-08-02 20:15:16 -04:00
|
|
|
static gboolean
|
|
|
|
|
check_writable (NMConnection *connection, GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (connection != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
2010-08-02 20:15:16 -04:00
|
|
|
if (!s_con) {
|
|
|
|
|
g_set_error_literal (error,
|
2010-10-27 20:38:26 -05:00
|
|
|
NM_SETTINGS_ERROR,
|
|
|
|
|
NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
2010-08-02 20:15:16 -04:00
|
|
|
"Connection did not have required 'connection' setting");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the connection is read-only, that has to be changed at the source of
|
|
|
|
|
* the problem (ex a system settings plugin that can't write connections out)
|
|
|
|
|
* instead of over D-Bus.
|
|
|
|
|
*/
|
|
|
|
|
if (nm_setting_connection_get_read_only (s_con)) {
|
|
|
|
|
g_set_error_literal (error,
|
2010-10-27 20:38:26 -05:00
|
|
|
NM_SETTINGS_ERROR,
|
|
|
|
|
NM_SETTINGS_ERROR_READ_ONLY_CONNECTION,
|
2010-08-02 20:15:16 -04:00
|
|
|
"Connection is read-only");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
get_settings_auth_cb (NMSettingsConnection *self,
|
2010-08-15 03:25:58 -04:00
|
|
|
DBusGMethodInvocation *context,
|
2011-01-30 13:49:56 -06:00
|
|
|
gulong sender_uid,
|
2010-08-15 03:25:58 -04:00
|
|
|
GError *error,
|
|
|
|
|
gpointer data)
|
2009-04-04 11:37:11 -04:00
|
|
|
{
|
2011-01-26 14:14:37 -06:00
|
|
|
if (error)
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return_error (context, error);
|
2011-01-26 14:14:37 -06:00
|
|
|
else {
|
|
|
|
|
GHashTable *settings;
|
2009-07-23 09:20:52 -04:00
|
|
|
|
2011-01-26 14:14:37 -06:00
|
|
|
/* Secrets should *never* be returned by the GetSettings method, they
|
|
|
|
|
* get returned by the GetSecrets method which can be better
|
|
|
|
|
* protected against leakage of secrets to unprivileged callers.
|
|
|
|
|
*/
|
|
|
|
|
settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_NO_SECRETS);
|
|
|
|
|
g_assert (settings);
|
|
|
|
|
dbus_g_method_return (context, settings);
|
|
|
|
|
g_hash_table_destroy (settings);
|
|
|
|
|
}
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
impl_settings_connection_get_settings (NMSettingsConnection *self,
|
|
|
|
|
DBusGMethodInvocation *context)
|
2009-04-04 11:37:11 -04:00
|
|
|
{
|
2010-08-15 03:25:58 -04:00
|
|
|
auth_start (self, context, FALSE, get_settings_auth_cb, NULL);
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
con_update_cb (NMSettingsConnection *connection,
|
2009-07-23 09:20:52 -04:00
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
2009-04-04 11:37:11 -04:00
|
|
|
{
|
2010-08-15 03:25:58 -04:00
|
|
|
DBusGMethodInvocation *context = user_data;
|
2009-04-04 11:37:11 -04:00
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
if (error)
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return_error (context, error);
|
2009-07-23 09:20:52 -04:00
|
|
|
else
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return (context);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
2009-04-04 11:37:11 -04:00
|
|
|
|
2011-01-31 23:10:33 -06:00
|
|
|
static void
|
|
|
|
|
only_agent_secrets_cb (NMSetting *setting,
|
|
|
|
|
const char *key,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamFlags flags,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
if (flags & NM_SETTING_PARAM_SECRET) {
|
|
|
|
|
NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_SYSTEM_OWNED;
|
|
|
|
|
|
|
|
|
|
/* Clear out system-owned or always-ask secrets */
|
|
|
|
|
nm_setting_get_secret_flags (setting, key, &secret_flags, NULL);
|
|
|
|
|
if (secret_flags != NM_SETTING_SECRET_FLAG_AGENT_OWNED)
|
|
|
|
|
g_object_set (G_OBJECT (setting), key, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
static void
|
2011-01-30 13:49:56 -06:00
|
|
|
update_auth_cb (NMSettingsConnection *self,
|
2011-01-26 11:38:12 -06:00
|
|
|
DBusGMethodInvocation *context,
|
2011-01-30 13:49:56 -06:00
|
|
|
gulong sender_uid,
|
2011-01-26 11:38:12 -06:00
|
|
|
GError *error,
|
|
|
|
|
gpointer data)
|
2009-07-23 09:20:52 -04:00
|
|
|
{
|
2011-01-31 23:10:33 -06:00
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2010-08-15 03:25:58 -04:00
|
|
|
NMConnection *new_settings = data;
|
2011-01-31 23:10:33 -06:00
|
|
|
NMConnection *for_agent;
|
2009-10-21 14:19:01 -07:00
|
|
|
|
2011-01-31 23:10:33 -06:00
|
|
|
if (error)
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return_error (context, error);
|
2011-01-31 23:10:33 -06:00
|
|
|
else {
|
|
|
|
|
/* Update and commit our settings. */
|
|
|
|
|
nm_settings_connection_replace_and_commit (self,
|
|
|
|
|
new_settings,
|
|
|
|
|
con_update_cb,
|
|
|
|
|
context);
|
|
|
|
|
|
|
|
|
|
/* Dupe the connection and clear out non-agent-owned secrets so we can
|
|
|
|
|
* send the agent-owned ones to agents to be saved. Only send them to
|
|
|
|
|
* agents of the same UID as the Update() request sender.
|
|
|
|
|
*/
|
|
|
|
|
for_agent = nm_connection_duplicate (NM_CONNECTION (self));
|
|
|
|
|
nm_connection_for_each_setting_value (for_agent, only_agent_secrets_cb, NULL);
|
|
|
|
|
nm_agent_manager_save_secrets (priv->agent_mgr, for_agent, TRUE, sender_uid);
|
|
|
|
|
g_object_unref (for_agent);
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
g_object_unref (new_settings);
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
impl_settings_connection_update (NMSettingsConnection *self,
|
|
|
|
|
GHashTable *new_settings,
|
|
|
|
|
DBusGMethodInvocation *context)
|
2009-04-04 11:37:11 -04:00
|
|
|
{
|
2009-07-23 09:20:52 -04:00
|
|
|
NMConnection *tmp;
|
2009-04-04 11:37:11 -04:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2010-08-05 01:39:13 -04:00
|
|
|
/* If the connection is read-only, that has to be changed at the source of
|
|
|
|
|
* the problem (ex a system settings plugin that can't write connections out)
|
|
|
|
|
* instead of over D-Bus.
|
|
|
|
|
*/
|
|
|
|
|
if (!check_writable (NM_CONNECTION (self), &error)) {
|
|
|
|
|
dbus_g_method_return_error (context, error);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
/* Check if the settings are valid first */
|
|
|
|
|
tmp = nm_connection_new_from_hash (new_settings, &error);
|
|
|
|
|
if (!tmp) {
|
|
|
|
|
g_assert (error);
|
|
|
|
|
dbus_g_method_return_error (context, error);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
auth_start (self, context, TRUE, update_auth_cb, tmp);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
con_delete_cb (NMSettingsConnection *connection,
|
2009-07-23 09:20:52 -04:00
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2010-08-15 03:25:58 -04:00
|
|
|
DBusGMethodInvocation *context = user_data;
|
2009-07-23 09:20:52 -04:00
|
|
|
|
|
|
|
|
if (error)
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return_error (context, error);
|
2009-07-23 09:20:52 -04:00
|
|
|
else
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return (context);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
delete_auth_cb (NMSettingsConnection *self,
|
|
|
|
|
DBusGMethodInvocation *context,
|
2011-01-30 13:49:56 -06:00
|
|
|
gulong sender_uid,
|
2011-01-26 11:38:12 -06:00
|
|
|
GError *error,
|
|
|
|
|
gpointer data)
|
2009-07-23 09:20:52 -04:00
|
|
|
{
|
|
|
|
|
if (error) {
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return_error (context, error);
|
2009-07-23 09:20:52 -04:00
|
|
|
return;
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_delete (self, con_delete_cb, context);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
impl_settings_connection_delete (NMSettingsConnection *self,
|
|
|
|
|
DBusGMethodInvocation *context)
|
2009-07-23 09:20:52 -04:00
|
|
|
{
|
2010-08-05 01:39:13 -04:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
if (!check_writable (NM_CONNECTION (self), &error)) {
|
|
|
|
|
dbus_g_method_return_error (context, error);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-07-23 09:20:52 -04:00
|
|
|
|
2010-08-15 03:25:58 -04:00
|
|
|
auth_start (self, context, TRUE, delete_auth_cb, NULL);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
static void
|
2011-01-26 17:13:15 -06:00
|
|
|
dbus_get_agent_secrets_cb (NMSettingsConnection *self,
|
|
|
|
|
guint32 call_id,
|
2011-01-27 10:41:02 -06:00
|
|
|
const char *setting_name,
|
2011-01-26 17:13:15 -06:00
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
2009-07-23 09:20:52 -04:00
|
|
|
{
|
2011-01-26 17:13:15 -06:00
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
|
|
|
|
DBusGMethodInvocation *context = user_data;
|
|
|
|
|
GHashTable *hash;
|
2009-10-21 14:19:01 -07:00
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id));
|
|
|
|
|
|
|
|
|
|
/* The connection's secrets will have been updated by the agent manager,
|
2011-01-31 23:10:33 -06:00
|
|
|
* so we want to refresh the secrets cache. Note that we will never save
|
|
|
|
|
* new secrets to backing storage here because D-Bus initated requests will
|
|
|
|
|
* never ask for completely new secrets from agents. Thus system-owned
|
|
|
|
|
* secrets should not have changed from backing storage. We also don't
|
|
|
|
|
* send agent-owned back out to be saved since we assume the agent that
|
|
|
|
|
* provided the secrets saved them itself.
|
2011-01-26 17:13:15 -06:00
|
|
|
*/
|
|
|
|
|
if (priv->secrets)
|
|
|
|
|
g_object_unref (priv->secrets);
|
|
|
|
|
priv->secrets = nm_connection_duplicate (NM_CONNECTION (self));
|
|
|
|
|
|
|
|
|
|
if (error)
|
2010-08-15 03:25:58 -04:00
|
|
|
dbus_g_method_return_error (context, error);
|
2011-01-26 17:13:15 -06:00
|
|
|
else {
|
|
|
|
|
hash = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ONLY_SECRETS);
|
|
|
|
|
dbus_g_method_return (context, hash);
|
|
|
|
|
g_hash_table_destroy (hash);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
2011-01-26 17:13:15 -06:00
|
|
|
}
|
2009-07-23 09:20:52 -04:00
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
static void
|
|
|
|
|
dbus_secrets_auth_cb (NMSettingsConnection *self,
|
|
|
|
|
DBusGMethodInvocation *context,
|
2011-01-30 13:49:56 -06:00
|
|
|
gulong sender_uid,
|
2011-01-26 17:13:15 -06:00
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2011-01-30 13:49:56 -06:00
|
|
|
char *setting_name = user_data;
|
2011-01-26 17:13:15 -06:00
|
|
|
guint32 call_id = 0;
|
|
|
|
|
GError *local = NULL;
|
|
|
|
|
|
2011-01-30 13:53:37 -06:00
|
|
|
if (!error) {
|
2011-01-30 13:49:56 -06:00
|
|
|
call_id = nm_settings_connection_get_secrets (self,
|
|
|
|
|
TRUE,
|
|
|
|
|
sender_uid,
|
|
|
|
|
setting_name,
|
|
|
|
|
0, /* GET_SECRETS_FLAG_NONE */
|
|
|
|
|
NULL,
|
|
|
|
|
dbus_get_agent_secrets_cb,
|
|
|
|
|
context,
|
|
|
|
|
&local);
|
|
|
|
|
if (call_id > 0) {
|
|
|
|
|
/* track the request and wait for the callback */
|
|
|
|
|
priv->reqs = g_slist_append (priv->reqs, GUINT_TO_POINTER (call_id));
|
|
|
|
|
}
|
2011-01-27 10:41:02 -06:00
|
|
|
}
|
|
|
|
|
|
2011-01-30 13:53:37 -06:00
|
|
|
if (error || local) {
|
2011-01-26 18:36:08 -06:00
|
|
|
dbus_g_method_return_error (context, error ? error : local);
|
2011-01-30 13:49:56 -06:00
|
|
|
g_clear_error (&local);
|
|
|
|
|
}
|
2011-01-26 18:36:08 -06:00
|
|
|
|
2011-01-26 10:17:07 -06:00
|
|
|
g_free (setting_name);
|
2009-07-23 09:20:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
impl_settings_connection_get_secrets (NMSettingsConnection *self,
|
|
|
|
|
const gchar *setting_name,
|
|
|
|
|
DBusGMethodInvocation *context)
|
2009-07-23 09:20:52 -04:00
|
|
|
{
|
2011-01-26 17:13:15 -06:00
|
|
|
auth_start (self, context, TRUE, dbus_secrets_auth_cb, g_strdup (setting_name));
|
2009-04-04 11:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
2009-07-23 09:20:52 -04:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_init (NMSettingsConnection *self)
|
2008-05-09 06:33:30 +00:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2010-08-15 03:25:58 -04:00
|
|
|
static guint32 dbus_counter = 0;
|
|
|
|
|
char *dbus_path;
|
2010-08-17 09:35:41 -05:00
|
|
|
GError *error = NULL;
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2011-01-27 10:41:02 -06:00
|
|
|
priv->dbus_mgr = nm_dbus_manager_get ();
|
|
|
|
|
|
2010-08-17 09:35:41 -05:00
|
|
|
priv->authority = polkit_authority_get_sync (NULL, NULL);
|
2010-04-07 12:27:34 -07:00
|
|
|
if (!priv->authority) {
|
2010-12-10 12:32:22 -06:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "failed to create PolicyKit authority: (%d) %s",
|
2010-08-17 09:35:41 -05:00
|
|
|
error ? error->code : -1,
|
|
|
|
|
error && error->message ? error->message : "(unknown)");
|
|
|
|
|
g_clear_error (&error);
|
2010-04-07 12:27:34 -07:00
|
|
|
}
|
2010-08-15 03:25:58 -04:00
|
|
|
|
|
|
|
|
dbus_path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, dbus_counter++);
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_connection_set_path (NM_CONNECTION (self), dbus_path);
|
2010-08-15 03:25:58 -04:00
|
|
|
g_free (dbus_path);
|
|
|
|
|
priv->visible = FALSE;
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
priv->session_monitor = nm_session_monitor_get ();
|
2010-10-26 16:33:47 -05:00
|
|
|
priv->session_changed_id = g_signal_connect (priv->session_monitor,
|
|
|
|
|
NM_SESSION_MONITOR_CHANGED,
|
|
|
|
|
G_CALLBACK (session_changed_cb),
|
|
|
|
|
self);
|
2011-01-27 10:41:02 -06:00
|
|
|
|
|
|
|
|
priv->agent_mgr = nm_agent_manager_get ();
|
2010-08-15 03:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
static void
|
2009-04-04 11:37:11 -04:00
|
|
|
dispose (GObject *object)
|
2008-05-09 06:33:30 +00:00
|
|
|
{
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnection *self = NM_SETTINGS_CONNECTION (object);
|
|
|
|
|
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
2009-10-21 14:19:01 -07:00
|
|
|
GSList *iter;
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
if (priv->disposed)
|
|
|
|
|
goto out;
|
|
|
|
|
priv->disposed = TRUE;
|
|
|
|
|
|
2009-11-16 16:48:59 -08:00
|
|
|
if (priv->secrets)
|
|
|
|
|
g_object_unref (priv->secrets);
|
|
|
|
|
|
2009-10-21 14:19:01 -07:00
|
|
|
/* Cancel PolicyKit requests */
|
2010-11-18 14:24:58 -06:00
|
|
|
for (iter = priv->pending_auths; iter; iter = g_slist_next (iter))
|
|
|
|
|
nm_auth_chain_unref ((NMAuthChain *) iter->data);
|
2010-08-15 03:25:58 -04:00
|
|
|
g_slist_free (priv->pending_auths);
|
|
|
|
|
priv->pending_auths = NULL;
|
|
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
/* Cancel in-progress secrets requests */
|
|
|
|
|
for (iter = priv->reqs; iter; iter = g_slist_next (iter))
|
2011-01-27 10:41:02 -06:00
|
|
|
nm_agent_manager_cancel_secrets (priv->agent_mgr, GPOINTER_TO_UINT (iter->data));
|
2011-01-26 17:13:15 -06:00
|
|
|
g_slist_free (priv->reqs);
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
set_visible (self, FALSE);
|
2010-08-27 12:49:01 -05:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
g_object_unref (priv->session_monitor);
|
2011-01-27 10:41:02 -06:00
|
|
|
g_object_unref (priv->agent_mgr);
|
|
|
|
|
g_object_unref (priv->dbus_mgr);
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2011-01-26 17:13:15 -06:00
|
|
|
out:
|
2011-01-26 11:38:12 -06:00
|
|
|
G_OBJECT_CLASS (nm_settings_connection_parent_class)->dispose (object);
|
2008-05-09 06:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
2011-01-26 11:38:12 -06:00
|
|
|
GValue *value, GParamSpec *pspec)
|
2010-10-26 11:15:19 -05:00
|
|
|
{
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_VISIBLE:
|
2011-01-26 11:38:12 -06:00
|
|
|
g_value_set_boolean (value, NM_SETTINGS_CONNECTION_GET_PRIVATE (object)->visible);
|
2010-10-26 11:15:19 -05:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
2011-01-26 11:38:12 -06:00
|
|
|
const GValue *value, GParamSpec *pspec)
|
2010-10-26 11:15:19 -05:00
|
|
|
{
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
static void
|
2011-01-26 11:38:12 -06:00
|
|
|
nm_settings_connection_class_init (NMSettingsConnectionClass *class)
|
2008-05-09 06:33:30 +00:00
|
|
|
{
|
2009-07-23 09:20:52 -04:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
g_type_class_add_private (class, sizeof (NMSettingsConnectionPrivate));
|
2008-05-09 06:33:30 +00:00
|
|
|
|
|
|
|
|
/* Virtual methods */
|
2009-04-04 11:37:11 -04:00
|
|
|
object_class->dispose = dispose;
|
2010-10-26 11:15:19 -05:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
|
2010-08-05 18:25:15 -04:00
|
|
|
class->commit_changes = commit_changes;
|
|
|
|
|
class->delete = do_delete;
|
2010-12-12 21:17:34 -06:00
|
|
|
class->supports_secrets = supports_secrets;
|
2010-08-05 18:25:15 -04:00
|
|
|
|
2010-10-26 11:15:19 -05:00
|
|
|
/* Properties */
|
|
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_VISIBLE,
|
2011-01-26 11:38:12 -06:00
|
|
|
g_param_spec_boolean (NM_SETTINGS_CONNECTION_VISIBLE,
|
2010-10-26 11:15:19 -05:00
|
|
|
"Visible",
|
|
|
|
|
"Visible",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
2010-08-05 18:25:15 -04:00
|
|
|
/* Signals */
|
|
|
|
|
signals[UPDATED] =
|
2011-01-26 11:38:12 -06:00
|
|
|
g_signal_new (NM_SETTINGS_CONNECTION_UPDATED,
|
2010-08-05 18:25:15 -04:00
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
0,
|
|
|
|
|
NULL, NULL,
|
2010-12-02 14:34:38 -06:00
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
2010-08-05 18:25:15 -04:00
|
|
|
|
|
|
|
|
signals[REMOVED] =
|
2011-01-26 11:38:12 -06:00
|
|
|
g_signal_new (NM_SETTINGS_CONNECTION_REMOVED,
|
2010-08-05 18:25:15 -04:00
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
0,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
2010-08-02 20:15:16 -04:00
|
|
|
|
|
|
|
|
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
|
2011-01-26 11:38:12 -06:00
|
|
|
&dbus_glib_nm_settings_connection_object_info);
|
2008-05-09 06:33:30 +00:00
|
|
|
}
|