network-manager-applet r719 - in trunk: . src/connection-editor src/gconf-helpers
- From: tambeti svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r719 - in trunk: . src/connection-editor src/gconf-helpers
- Date: Fri, 9 May 2008 07:34:48 +0100 (BST)
Author: tambeti
Date: Fri May 9 06:34:48 2008
New Revision: 719
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=719&view=rev
Log:
2008-05-02 Tambet Ingo <tambet gmail com>
Use PolicyKit to authorize the system connection handling.
* src/gconf-helpers/nma-gconf-connection.c (update, delete): Update,
NMExportedConnection::update and ::delete now handle errors.
* src/connection-editor/nm-connection-list.c
(delete_connection_auth_cb): Implement
(delete_connection): Implement.
(delete_connection_cb): Use PolicyKit.
* src/connection-editor/nm-connection-editor.c
(connection_editor_update_connection): Use a PolicyKit aware helper
function to update connections.
(update_connection): Implmenet.
(update_connection_auth_cb): Implement.
* src/connection-editor/nm-connection-list.c (add_done_cb): Use the
PolicyKit aware helper function to add new system connection.
(add_system_connection): Implement. If the request fails because of
authorization, use PolicyKit gnome helper to request the authorization.
(add_system_connection_auth_cb): Implement. Try again if the
authorization was granted.
(add_connection_treeview): Rename an internal variable, 'select' clashes
with a syscall name.
* configure.ac: Require PolicyKit-gnome.
Modified:
trunk/ChangeLog
trunk/configure.ac
trunk/src/connection-editor/nm-connection-editor.c
trunk/src/connection-editor/nm-connection-list.c
trunk/src/gconf-helpers/nma-gconf-connection.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri May 9 06:34:48 2008
@@ -76,7 +76,8 @@
gmodule-export-2.0
gconf-2.0
gnome-keyring-1
- libnotify >= 0.4.3])
+ libnotify >= 0.4.3
+ polkit-gnome])
##### Find out the version of DBUS we're using
dbus_version=`pkg-config --modversion dbus-1`
Modified: trunk/src/connection-editor/nm-connection-editor.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.c (original)
+++ trunk/src/connection-editor/nm-connection-editor.c Fri May 9 06:34:48 2008
@@ -21,6 +21,8 @@
*/
#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <gtk/gtk.h>
#include <gtk/gtkcombobox.h>
@@ -31,6 +33,7 @@
#include <gtk/gtknotebook.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkmessagedialog.h>
+#include <polkit-gnome/polkit-gnome.h>
#include <glib/gi18n.h>
#include <nm-setting-connection.h>
@@ -72,6 +75,8 @@
static void nm_connection_editor_set_connection (NMConnectionEditor *editor,
NMExportedConnection *exported);
+static void update_connection (NMExportedConnection *exported);
+
static void
dialog_response_cb (GtkDialog *dialog, guint response, gpointer user_data)
{
@@ -413,12 +418,78 @@
}
static void
+update_connection_auth_cb (PolKitAction *action,
+ gboolean gained_privilege,
+ GError *error,
+ gpointer user_data)
+{
+ NMExportedConnection *exported = NM_EXPORTED_CONNECTION (user_data);
+
+ if (gained_privilege)
+ update_connection (exported);
+ else if (error) {
+ g_warning ("Could not obtain required privileges: %s", error->message);
+ g_error_free (error);
+ } else
+ g_warning ("Could not update system connection, permission denied");
+
+ g_object_unref (exported);
+}
+
+static void
+update_connection (NMExportedConnection *exported)
+{
+ GHashTable *settings;
+ gboolean success;
+ GError *err = NULL;
+
+ settings = nm_connection_to_hash (nm_exported_connection_get_connection (exported));
+ success = nm_exported_connection_update (exported, settings, &err);
+ g_hash_table_destroy (settings);
+
+ if (success)
+ return;
+
+ if (dbus_g_error_has_name (err, "org.freedesktop.NetworkManagerSettings.Connection.NotPrivileged")) {
+ PolKitAction *pk_action;
+ char **tokens;
+ guint xid;
+ pid_t pid;
+
+ tokens = g_strsplit (err->message, " ", 2);
+ if (g_strv_length (tokens) != 2) {
+ g_warning ("helper return string malformed");
+ g_strfreev (tokens);
+ goto out;
+ }
+
+ pk_action = polkit_action_new ();
+ polkit_action_set_action_id (pk_action, tokens[0]);
+ g_strfreev (tokens);
+
+ xid = 0;
+ pid = getpid ();
+
+ g_error_free (err);
+ err = NULL;
+
+ if (polkit_gnome_auth_obtain (pk_action, xid, pid, update_connection_auth_cb, exported, &err))
+ g_object_ref (exported);
+ }
+
+ out:
+ if (err) {
+ g_warning ("Updating the connection failed: %s", err->message);
+ g_error_free (err);
+ }
+}
+
+static void
connection_editor_update_connection (NMConnectionEditor *editor)
{
NMSettingConnection *s_con;
GtkWidget *widget;
const char *name;
- GHashTable *settings;
gboolean autoconnect = FALSE;
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
@@ -449,9 +520,7 @@
}
utils_clear_filled_connection_certs (editor->connection);
- settings = nm_connection_to_hash (editor->connection);
- nm_exported_connection_update (editor->exported, settings);
- /* FIXME: destroy hash? */
+ update_connection (editor->exported);
}
static void
Modified: trunk/src/connection-editor/nm-connection-list.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-list.c (original)
+++ trunk/src/connection-editor/nm-connection-list.c Fri May 9 06:34:48 2008
@@ -21,6 +21,8 @@
*/
#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkdialog.h>
@@ -31,7 +33,7 @@
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkstock.h>
#include <gconf/gconf-client.h>
-
+#include <polkit-gnome/polkit-gnome.h>
#include <glib/gi18n.h>
#include <nm-setting-connection.h>
@@ -70,6 +72,9 @@
GtkTreeView *treeview;
} ActionInfo;
+static void add_system_connection (NMConnectionList *self, NMConnection *connection);
+static void delete_connection (NMExportedConnection *exported);
+
static NMExportedConnection *
get_active_connection (GtkTreeView *treeview)
{
@@ -242,6 +247,82 @@
g_free (last_used);
}
+typedef struct {
+ NMConnectionList *list;
+ NMConnection *connection;
+} AddSystemConnectionInfo;
+
+static void
+add_system_connection_auth_cb (PolKitAction *action,
+ gboolean gained_privilege,
+ GError *error,
+ gpointer user_data)
+{
+ AddSystemConnectionInfo *info = (AddSystemConnectionInfo *) user_data;
+
+ if (gained_privilege)
+ add_system_connection (info->list, info->connection);
+ else if (error) {
+ g_warning ("Could not obtain required privileges: %s", error->message);
+ g_error_free (error);
+ } else
+ g_warning ("Could not add system connection, permission denied");
+
+ g_object_unref (info->list);
+ g_object_unref (info->connection);
+ g_free (info);
+}
+
+static void
+add_system_connection (NMConnectionList *self, NMConnection *connection)
+{
+ GError *err = NULL;
+
+ if (nm_dbus_settings_system_add_connection (self->system_settings, connection, &err))
+ /* Done */
+ return;
+
+ if (dbus_g_error_has_name (err, "org.freedesktop.NetworkManagerSettings.System.NotPrivileged")) {
+ AddSystemConnectionInfo *info;
+ PolKitAction *pk_action;
+ char **tokens;
+ guint xid;
+ pid_t pid;
+
+ tokens = g_strsplit (err->message, " ", 2);
+ if (g_strv_length (tokens) != 2) {
+ g_warning ("helper return string malformed");
+ g_strfreev (tokens);
+ goto out;
+ }
+
+ pk_action = polkit_action_new ();
+ polkit_action_set_action_id (pk_action, tokens[0]);
+ g_strfreev (tokens);
+
+ xid = 0;
+ pid = getpid ();
+
+ g_error_free (err);
+ err = NULL;
+
+ info = g_new (AddSystemConnectionInfo, 1);
+ info->list = g_object_ref (self);
+ info->connection = g_object_ref (connection);
+ if (!polkit_gnome_auth_obtain (pk_action, xid, pid, add_system_connection_auth_cb, info, &err)) {
+ g_object_unref (info->list);
+ g_object_unref (info->connection);
+ g_free (info);
+ }
+ }
+
+ out:
+ if (err) {
+ g_warning ("Could not add system settings: %s", err->message);
+ g_error_free (err);
+ }
+}
+
static void
add_done_cb (NMConnectionEditor *editor, gint response, gpointer user_data)
{
@@ -256,7 +337,7 @@
connection = nm_exported_connection_get_connection (exported);
if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM)
- nm_dbus_settings_system_add_connection (info->list->system_settings, connection);
+ add_system_connection (info->list, connection);
else
nma_gconf_settings_add_connection (info->list->gconf_settings, connection);
}
@@ -529,6 +610,68 @@
}
static void
+delete_connection_auth_cb (PolKitAction *action,
+ gboolean gained_privilege,
+ GError *error,
+ gpointer user_data)
+{
+ NMExportedConnection *exported = NM_EXPORTED_CONNECTION (user_data);
+
+ if (gained_privilege)
+ delete_connection (exported);
+ else if (error) {
+ g_warning ("Could not obtain required privileges: %s", error->message);
+ g_error_free (error);
+ } else
+ g_warning ("Could not remove system connection, permission denied");
+
+ g_object_unref (exported);
+}
+
+static void
+delete_connection (NMExportedConnection *exported)
+{
+ GError *err = NULL;
+
+ if (nm_exported_connection_delete (exported, &err))
+ /* Done */
+ return;
+
+ if (dbus_g_error_has_name (err, "org.freedesktop.NetworkManagerSettings.Connection.NotPrivileged")) {
+ PolKitAction *pk_action;
+ char **tokens;
+ guint xid;
+ pid_t pid;
+
+ tokens = g_strsplit (err->message, " ", 2);
+ if (g_strv_length (tokens) != 2) {
+ g_warning ("helper return string malformed");
+ g_strfreev (tokens);
+ goto out;
+ }
+
+ pk_action = polkit_action_new ();
+ polkit_action_set_action_id (pk_action, tokens[0]);
+ g_strfreev (tokens);
+
+ xid = 0;
+ pid = getpid ();
+
+ g_error_free (err);
+ err = NULL;
+
+ if (polkit_gnome_auth_obtain (pk_action, xid, pid, delete_connection_auth_cb, exported, &err))
+ g_object_ref (exported);
+ }
+
+ out:
+ if (err) {
+ g_warning ("Deleting the connection failed: %s", err->message);
+ g_error_free (err);
+ }
+}
+
+static void
delete_connection_cb (GtkButton *button, gpointer user_data)
{
ActionInfo *info = (ActionInfo *) user_data;
@@ -564,7 +707,7 @@
/* Close any open editor windows for this connection */
g_hash_table_remove (info->list->editors, exported);
- nm_exported_connection_delete (exported);
+ delete_connection (exported);
}
static void
@@ -666,7 +809,7 @@
GtkTreeModel *model;
GtkTreeModel *sort_model;
GtkCellRenderer *renderer;
- GtkTreeSelection *select;
+ GtkTreeSelection *selection;
GValue val = { 0, };
char *name;
GtkTreeView *treeview;
@@ -701,8 +844,8 @@
NULL);
/* Selection */
- select = gtk_tree_view_get_selection (treeview);
- gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
+ selection = gtk_tree_view_get_selection (treeview);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
return treeview;
}
Modified: trunk/src/gconf-helpers/nma-gconf-connection.c
==============================================================================
--- trunk/src/gconf-helpers/nma-gconf-connection.c (original)
+++ trunk/src/gconf-helpers/nma-gconf-connection.c Fri May 9 06:34:48 2008
@@ -290,29 +290,31 @@
return NMA_GCONF_CONNECTION_GET_PRIVATE (self)->id;
}
-static void
-update (NMExportedConnection *exported, GHashTable *new_settings)
+static gboolean
+update (NMExportedConnection *exported, GHashTable *new_settings, GError **err)
{
NMAGConfConnectionPrivate *priv = NMA_GCONF_CONNECTION_GET_PRIVATE (exported);
+ NMConnection *tmp;
- nm_gconf_write_connection (nm_exported_connection_get_connection (exported),
+ tmp = nm_connection_new_from_hash (new_settings);
+ nm_gconf_write_connection (tmp,
priv->client,
priv->dir,
priv->id);
+ g_object_unref (tmp);
+
gconf_client_notify (priv->client, priv->dir);
gconf_client_suggest_sync (priv->client, NULL);
+
+ return TRUE;
}
-static void
-delete (NMExportedConnection *exported)
+static gboolean
+delete (NMExportedConnection *exported, GError **err)
{
NMAGConfConnectionPrivate *priv = NMA_GCONF_CONNECTION_GET_PRIVATE (exported);
- GError *err = NULL;
- if (!gconf_client_recursive_unset (priv->client, priv->dir, 0, &err)) {
- g_warning ("Can not delete GConf connection: %s", err->message);
- g_error_free (err);
- }
+ return gconf_client_recursive_unset (priv->client, priv->dir, 0, err);
}
/* GObject */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]