kov changed libgksu/branches/libgksu2/configure.ac,
libgksu/branches/libgksu2/libgksu/ChangeLog,
libgksu/branches/libgksu2/libgksu/defines.h,
libgksu/branches/libgksu2/libgksu/libgksu.c,
libgksu/branches/libgksu2/libgksuui/ChangeLog,
libgksu/branches/libgksu2/libgksuui/Makefile.am,
libgksu/branches/libgksu2/libgksuui/defines.h,
libgksu/branches/libgksu2/libgksuui/gksuui-dialog.c
Gustavo Noronha
kov at costa.debian.org
Sun Mar 12 13:54:05 UTC 2006
Mensagem de log:
Preliminary support for gnome-keyring imported from the
gksu app code; it now removes the password from the
keyring in case it tries with it and fails
-----
Modified: libgksu/branches/libgksu2/configure.ac
===================================================================
--- libgksu/branches/libgksu2/configure.ac 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/configure.ac 2006-03-12 13:54:03 UTC (rev 517)
@@ -32,7 +32,7 @@
AC_PATH_PROG(GCONFTOOL, gconftool-2)
AM_GCONF_SOURCE_2
-PKG_CHECK_MODULES(LIBGKSU, [gtk+-2.0 >= 2.4.0, gconf-2.0, libstartup-notification-1.0])
+PKG_CHECK_MODULES(LIBGKSU, [gtk+-2.0 >= 2.4.0, gconf-2.0, libstartup-notification-1.0, gnome-keyring-1])
# Checks for library functions.
ALL_LINGUAS="ca cs da de es eu hu pl pt_BR ro ru sk nb nl"
Modified: libgksu/branches/libgksu2/libgksu/ChangeLog
===================================================================
--- libgksu/branches/libgksu2/libgksu/ChangeLog 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksu/ChangeLog 2006-03-12 13:54:03 UTC (rev 517)
@@ -1,3 +1,10 @@
+2006-03-12 Gustavo Noronha Silva <kov at debian.org>
+
+ * libgksu.c:
+ - Preliminary support for gnome-keyring imported from the
+ gksu app code; it now removes the password from the
+ keyring in case it tries with it and fails
+
2006-03-02 Gustavo Noronha Silva <kov at debian.org>
* test-gksu.c:
Modified: libgksu/branches/libgksu2/libgksu/defines.h
===================================================================
--- libgksu/branches/libgksu2/libgksu/defines.h 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksu/defines.h 2006-03-12 13:54:03 UTC (rev 517)
@@ -21,6 +21,8 @@
#ifndef __DEFINES_H__
#define __DEFINES_H__
+#define BASE_PATH "/apps/gksu/"
+
/* Gettext */
#include <libintl.h>
#define _(String) dgettext (DOMAIN, String)
Modified: libgksu/branches/libgksu2/libgksu/libgksu.c
===================================================================
--- libgksu/branches/libgksu2/libgksu/libgksu.c 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksu/libgksu.c 2006-03-12 13:54:03 UTC (rev 517)
@@ -35,17 +35,17 @@
#include <libsn/sn.h>
#include <gtk/gtk.h>
-#include <gconf/gconf-client.h>
#include <locale.h>
+#include <gconf/gconf-client.h>
+#include <gnome-keyring.h>
+
#include "defines.h"
#include "../config.h"
#include "libgksu.h"
#include "../libgksuui/gksuui-dialog.h"
-#define BASE_PATH "/apps/gksu/"
-
/* GLOBALS */
gboolean message_changed = FALSE;
@@ -280,6 +280,173 @@
close(lock);
}
+static gchar*
+get_gnome_keyring_password (GksuContext *context)
+{
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attribute;
+ GnomeKeyringResult result;
+ GList *list;
+
+ attributes = gnome_keyring_attribute_list_new ();
+
+ attribute.name = g_strdup ("user");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup (gksu_context_get_user (context));
+ g_array_append_val (attributes, attribute);
+
+ attribute.name = g_strdup ("type");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup ("local");
+ g_array_append_val (attributes, attribute);
+
+ attribute.name = g_strdup ("creator");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup ("gksu");
+ g_array_append_val (attributes, attribute);
+
+ list = g_list_alloc();
+
+ result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ attributes,
+ &list);
+ gnome_keyring_attribute_list_free (attributes);
+ if (
+ (result == GNOME_KEYRING_RESULT_OK) &&
+ (g_list_length(list) == 1)
+ )
+ {
+ GnomeKeyringFound *found = list->data;
+ gint password_length = strlen (found->secret);
+ gchar *password;
+
+ password = g_locale_from_utf8 (found->secret,
+ password_length,
+ NULL, NULL, NULL);
+ /* strip the \n that is always stored in gnome-keyring */
+ password[password_length - 1] = '\0';
+ return password;
+ }
+
+ return NULL;
+}
+
+static void
+keyring_create_item_cb (GnomeKeyringResult result,
+ guint32 id, gpointer keyring_loop)
+{
+ g_main_loop_quit (keyring_loop);
+}
+
+static void
+set_gnome_keyring_password (GksuContext *context, gchar *password)
+{
+ GConfClient *gconf_client;
+ gboolean save_to_keyring;
+
+ gconf_client = context->gconf_client;
+ save_to_keyring = gconf_client_get_bool (gconf_client, BASE_PATH"save-to-keyring", NULL);
+
+ if (password && save_to_keyring)
+ {
+ static GMainLoop *keyring_loop = NULL;
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attribute;
+
+ gchar *keyring_name;
+ gchar *key_name;
+
+ attributes = gnome_keyring_attribute_list_new ();
+
+ attribute.name = g_strdup ("user");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup (gksu_context_get_user (context));
+ g_array_append_val (attributes, attribute);
+
+ attribute.name = g_strdup ("type");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup ("local");
+ g_array_append_val (attributes, attribute);
+
+ attribute.name = g_strdup ("creator");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup ("gksu");
+ g_array_append_val (attributes, attribute);
+
+ key_name = g_strdup_printf ("Local password for user %s",
+ gksu_context_get_user (context));
+
+ keyring_loop = g_main_loop_new (NULL, FALSE);
+
+ keyring_name = gconf_client_get_string (gconf_client, BASE_PATH"save-keyring", NULL);
+ if (keyring_name == NULL)
+ keyring_name = g_strdup ("session");
+ gnome_keyring_item_create (keyring_name,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ key_name,
+ attributes,
+ password,
+ TRUE,
+ keyring_create_item_cb,
+ keyring_loop, NULL);
+ gnome_keyring_attribute_list_free (attributes);
+ g_free (keyring_name);
+ g_main_loop_run (keyring_loop);
+ }
+}
+
+static void
+unset_gnome_keyring_password (GksuContext *context)
+{
+ GConfClient *gconf_client;
+ gboolean save_to_keyring;
+
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attribute;
+ GnomeKeyringResult result;
+ GList *list;
+
+ gconf_client = context->gconf_client;
+ save_to_keyring = gconf_client_get_bool (gconf_client, BASE_PATH"save-to-keyring", NULL);
+
+ if (save_to_keyring)
+ {
+ attributes = gnome_keyring_attribute_list_new ();
+
+ attribute.name = g_strdup ("user");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup (gksu_context_get_user (context));
+ g_array_append_val (attributes, attribute);
+
+ attribute.name = g_strdup ("type");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup ("local");
+ g_array_append_val (attributes, attribute);
+
+ attribute.name = g_strdup ("creator");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup ("gksu");
+ g_array_append_val (attributes, attribute);
+
+ list = g_list_alloc();
+
+ result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ attributes,
+ &list);
+ gnome_keyring_attribute_list_free (attributes);
+ if (
+ (result == GNOME_KEYRING_RESULT_OK) &&
+ (g_list_length(list) == 1)
+ )
+ {
+ GnomeKeyringFound *found = list->data;
+
+ gnome_keyring_item_delete_sync (found->keyring,
+ found->item_id);
+ }
+ }
+}
+
void
get_configuration_options (GksuContext *context)
{
@@ -365,16 +532,6 @@
}
static void
-set_sensitivity_cb (GtkWidget *button, gpointer data)
-{
- GtkWidget *widget = (GtkWidget*)data;
- gboolean sensitive;
-
- sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button));
- gtk_widget_set_sensitive (widget, sensitive);
-}
-
-static void
cb_toggled_cb (GtkWidget *button, gpointer data)
{
GConfClient *gconf_client;
@@ -391,15 +548,8 @@
key = g_strdup_printf (BASE_PATH "%s", key_name);
- if (!strcmp (key_name, "save-keyring"))
+ if (!strcmp (key_name, "display-no-pass-info"))
{
- if (toggled)
- gconf_client_set_string (gconf_client, key, "session", NULL);
- else
- gconf_client_set_string (gconf_client, key, "default", NULL);
- }
- else if (!strcmp (key_name, "display-no-pass-info"))
- {
/* the meaning of the key is the exact opposite of the meaning
of the answer - when the check button is checked the key must
be off
@@ -1065,6 +1215,7 @@
gchar buf[256] = {0};
gint status;
+ gchar *password = NULL;
gchar *cmdline = NULL;
gboolean password_needed = FALSE;
@@ -1099,7 +1250,6 @@
if (!(tio.c_lflag & ECHO))
{
- gchar *password = NULL;
gchar *tmp = NULL;
gboolean prompt_grab;
@@ -1108,7 +1258,12 @@
if (prompt_grab)
gksu_prompt_grab (context);
- tmp = ask_pass (context, buf, ask_pass_data, error);
+ /* try to get the password from the GNOME Keyring first */
+ tmp = get_gnome_keyring_password (context);
+ fprintf (stderr, "tmp: %s\n", tmp);
+ if (tmp == NULL)
+ tmp = ask_pass (context, buf, ask_pass_data, error);
+
g_return_val_if_fail (tmp != NULL, -1);
usleep (100);
@@ -1118,8 +1273,6 @@
write (fdpty, password, strlen(password));
- nullify_password (password);
-
password_needed = TRUE;
}
}
@@ -1153,6 +1306,12 @@
if (!strncmp (buf, "su: Authentication failure", 26))
{
+ if (password)
+ {
+ nullify_password (password);
+ unset_gnome_keyring_password (context);
+ }
+
g_set_error (error, gksu_quark,
GKSU_ERROR_WRONGPASS,
_("Wrong password."));
@@ -1163,6 +1322,12 @@
{
gchar *line;
+ if (password)
+ {
+ set_gnome_keyring_password (context, password);
+ nullify_password (password);
+ }
+
if (context->debug)
fprintf (stderr, "DEBUG (gksu: waiting) buf: -%s-\n", buf);
@@ -1190,6 +1355,9 @@
g_set_error (error, gksu_quark, GKSU_ERROR_HELPER, emsg);
g_free (emsg);
+ if (password)
+ nullify_password (password);
+
if (context->debug)
fprintf (stderr, "DEBUG (failed!) buf: -%s-\n", buf);
Modified: libgksu/branches/libgksu2/libgksuui/ChangeLog
===================================================================
--- libgksu/branches/libgksu2/libgksuui/ChangeLog 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksuui/ChangeLog 2006-03-12 13:54:03 UTC (rev 517)
@@ -1,3 +1,8 @@
+2006-03-12 Gustavo Noronha Silva <kov at debian.org>
+
+ * gksuui-dialog.c:
+ - added UI for the gnome-keyring support in the main widget
+
2006-01-24 Gustavo Noronha Silva <kov at debian.org>
* gksuui-dialog.{c,h}:
Modified: libgksu/branches/libgksu2/libgksuui/Makefile.am
===================================================================
--- libgksu/branches/libgksu2/libgksuui/Makefile.am 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksuui/Makefile.am 2006-03-12 13:54:03 UTC (rev 517)
@@ -1,10 +1,10 @@
AM_CFLAGS = -g -O2 -Wall
-INCLUDES = `pkg-config --cflags gtk+-2.0`
+INCLUDES = `pkg-config --cflags gtk+-2.0 gconf-2.0`
AM_CPPFLAGS = -DLOCALEDIR=\"$(datadir)/locale\" -DDATA_DIR=\"$(datadir)\" -DPREFIX=\"$(prefix)\"
noinst_LTLIBRARIES = libgksuui1.0.la
libgksuui1_0_la_SOURCES = gksuui-dialog.c
-libgksuui1_0_la_LDFLAGS = -Wl,-O1 -static `pkg-config --libs gtk+-2.0`
+libgksuui1_0_la_LDFLAGS = -Wl,-O1 -static `pkg-config --libs gtk+-2.0 gconf-2.0`
noinst_HEADERS = defines.h gksuui.h gksuui-dialog.h
includedir = ${prefix}/include/$(PACKAGE)
Modified: libgksu/branches/libgksu2/libgksuui/defines.h
===================================================================
--- libgksu/branches/libgksu2/libgksuui/defines.h 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksuui/defines.h 2006-03-12 13:54:03 UTC (rev 517)
@@ -21,6 +21,8 @@
#ifndef __DEFINES_H__
#define __DEFINES_H__
+#define BASE_PATH "/apps/gksu/"
+
/* Gettext */
#include <libintl.h>
#define _(String) dgettext (PACKAGE, String)
Modified: libgksu/branches/libgksu2/libgksuui/gksuui-dialog.c
===================================================================
--- libgksu/branches/libgksu2/libgksuui/gksuui-dialog.c 2006-03-12 13:39:58 UTC (rev 516)
+++ libgksu/branches/libgksu2/libgksuui/gksuui-dialog.c 2006-03-12 13:54:03 UTC (rev 517)
@@ -18,10 +18,14 @@
* Boston, MA 02111-1307, USA.
*/
+#include <string.h>
+
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <X11/XKBlib.h>
+#include <gconf/gconf-client.h>
+
#include "defines.h"
#include "../config.h"
@@ -94,13 +98,65 @@
return FALSE;
}
+void
+set_sensitivity_cb (GtkWidget *button, gpointer data)
+{
+ GtkWidget *widget = (GtkWidget*)data;
+ gboolean sensitive;
+ sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button));
+ gtk_widget_set_sensitive (widget, sensitive);
+}
+
static void
+cb_toggled_cb (GtkWidget *button, gpointer data)
+{
+ GConfClient *gconf_client;
+ gchar *key;
+ gboolean toggled;
+ gchar *key_name;
+
+ g_return_if_fail (data != NULL);
+
+ key_name = (gchar*)data;
+
+ gconf_client = gconf_client_get_default ();
+ toggled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button));
+
+ key = g_strdup_printf (BASE_PATH "%s", key_name);
+
+ if (!strcmp (key_name, "save-keyring"))
+ {
+ if (toggled)
+ gconf_client_set_string (gconf_client, key, "session", NULL);
+ else
+ gconf_client_set_string (gconf_client, key, "default", NULL);
+ }
+ else
+ gconf_client_set_bool (gconf_client, key, toggled, NULL);
+
+ g_object_unref (gconf_client);
+
+ g_free (key);
+}
+
+static void
gksuui_dialog_init (GksuuiDialog *gksuui_dialog)
{
GtkDialog *dialog;
GtkWidget *hbox; /* aditional hbox for 'password: entry' label */
+ /* gnome-keyring stuff */
+ GtkWidget *vbox;
+ GtkWidget *check_button;
+ GtkWidget *alignment;
+ GtkWidget *radio_vbox;
+ GtkWidget *radio_session, *radio_default;
+
+ GConfClient *gconf_client;
+ gboolean remember_password;
+ gchar *tmp = NULL;
+
/*
make sure we're using UTF-8 and getting our locale files
from the right place
@@ -204,6 +260,48 @@
gtk_box_pack_start (GTK_BOX(gksuui_dialog->entry_vbox),
gksuui_dialog->label_warn_capslock, TRUE, TRUE, 0);
+ /* gnome-keyring stuff */
+ gconf_client = gconf_client_get_default ();
+
+ vbox = gtk_vbox_new (2, TRUE);
+ gtk_box_pack_start (GTK_BOX(GKSUUI_DIALOG(dialog)->entry_vbox), vbox, TRUE, TRUE, 0);
+ gtk_widget_show (vbox);
+
+ check_button = gtk_check_button_new_with_label (_("Remember password"));
+ g_signal_connect (G_OBJECT(check_button), "toggled", G_CALLBACK(cb_toggled_cb), "save-to-keyring");
+
+ remember_password = gconf_client_get_bool (gconf_client, BASE_PATH"save-to-keyring", NULL);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(check_button), remember_password);
+ gtk_box_pack_start (GTK_BOX(vbox), check_button, TRUE, TRUE, 0);
+ gtk_widget_show (check_button);
+
+ alignment = gtk_alignment_new (0.5, 0.5, 0.6, 1);
+ gtk_box_pack_start (GTK_BOX(vbox), alignment, TRUE, TRUE, 2);
+ gtk_widget_show (alignment);
+
+ radio_vbox = gtk_vbox_new (2, TRUE);
+ gtk_container_add (GTK_CONTAINER(alignment), radio_vbox);
+ gtk_widget_set_sensitive (radio_vbox, remember_password);
+ gtk_widget_show (radio_vbox);
+
+ radio_session = gtk_radio_button_new_with_label (NULL, _("Save for this session"));
+ g_signal_connect (G_OBJECT(radio_session), "toggled", G_CALLBACK(cb_toggled_cb), "save-keyring");
+ gtk_box_pack_start (GTK_BOX(radio_vbox), radio_session, TRUE, TRUE, 0);
+ gtk_widget_show (radio_session);
+
+ radio_default = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON(radio_session), _("Save in the keyring"));
+ gtk_box_pack_start (GTK_BOX(radio_vbox), radio_default, TRUE, TRUE, 0);
+ gtk_widget_show (radio_default);
+
+ g_signal_connect (G_OBJECT(check_button), "toggled", G_CALLBACK(set_sensitivity_cb), radio_vbox);
+
+ tmp = gconf_client_get_string (gconf_client, BASE_PATH"save-keyring", NULL);
+ if (tmp && (!strcmp (tmp, "default")))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio_default), TRUE);
+ g_free (tmp);
+
+ g_object_unref (gconf_client);
+
/* expose event */
g_signal_connect (G_OBJECT(gksuui_dialog), "focus-in-event",
G_CALLBACK(verify_capslock_cb), gksuui_dialog);
More information about the gksu-commits
mailing list