[Gpa-commits] r765 - trunk/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jan 29 17:07:21 CET 2007


Author: werner
Date: 2007-01-29 17:07:20 +0100 (Mon, 29 Jan 2007)
New Revision: 765

Modified:
   trunk/src/ChangeLog
   trunk/src/Makefile.am
   trunk/src/gpakeyexpireop.c
   trunk/src/gpgmeedit.c
   trunk/src/gpgmetools.c
   trunk/src/passwddlg.c
Log:
./
	* gpgmeedit.c (struct edit_parms_s): New field
	need_status_passphrase_sym.
	(edit_fnc): Take care of it.
	(PasswdState): New state PASSWD_ENTERNEW.
	(struct passwd_parms_s): Remove REQUEST_COUNTER.
	(edit_passwd_fnc_action): Handle PASSWD_ENTERNEW.
	(edit_passwd_fnc_transit): Test for NEED_PASSPHRASE_SYM.
	(passwd_passphrase_cb): Rewritten to take action directly on the
	current state.
	(gpa_gpgme_edit_passwd_start): Pass the edit parms and not the old
	REQUEST_COUNTER.
	* gpgmetools.c (passphrase_question_label): Take care of a missing
	user-id hint.

	* gpakeyexpireop.c (gpa_key_expire_operation_done_error_cb): Give
	a more specific error message.
	* gpgmeedit.c (edit_expire_fnc_transit): Return a more suitable
	error code for invalid dates.  
	(gpa_gpgme_edit_expire_parms_new): Do not use %F for strftime as
	this is C99 and not supported on all systems (i.e. Windows).


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2006-12-22 14:56:16 UTC (rev 764)
+++ trunk/src/ChangeLog	2007-01-29 16:07:20 UTC (rev 765)
@@ -1,8 +1,37 @@
-2006-11-30  Marcus Brinkmann  <marcus at g10code.de>
+2007-01-29  Werner Koch  <wk at g10code.com>
 
-	* passwddlg.c (gpa_change_passphrase_dialog_run): Initialize
-	PASSWD.  Release PASSWD if set before overwriting it.
+	* gpgmeedit.c (struct edit_parms_s): New field
+	need_status_passphrase_sym.
+	(edit_fnc): Take care of it.
+	(PasswdState): New state PASSWD_ENTERNEW.
+	(struct passwd_parms_s): Remove REQUEST_COUNTER.
+	(edit_passwd_fnc_action): Handle PASSWD_ENTERNEW.
+	(edit_passwd_fnc_transit): Test for NEED_PASSPHRASE_SYM.
+	(passwd_passphrase_cb): Rewritten to take action directly on the
+	current state.
+	(gpa_gpgme_edit_passwd_start): Pass the edit parms and not the old
+	REQUEST_COUNTER.
+	* gpgmetools.c (passphrase_question_label): Take care of a missing
+	user-id hint.
 
+	* gpakeyexpireop.c (gpa_key_expire_operation_done_error_cb): Give
+	a more specific error message.
+	* gpgmeedit.c (edit_expire_fnc_transit): Return a more suitable
+	error code for invalid dates.  
+	(gpa_gpgme_edit_expire_parms_new): Do not use %F for strftime as
+	this is C99 and not supported on all systems (i.e. Windows).
+	
+2007-01-10  Werner Koch  <wk at g10code.com>
+
+	* Makefile.am (INCLUDES): Removed.
+	(AM_CFLAGS, AM_CPPFLAGS): New.
+	(LDADD): Add GPGME and GTK libs.
+
+2006-07-26  Werner Koch  <wk at g10code.com>
+
+	* passwddlg.c (gpa_change_passphrase_dialog_run): Release PASSWD
+	in case the dialog is repeated.  Reported by Timo Schulz.
+
 2006-07-15  Marcus Brinkmann  <marcus at g10code.de>
 
 	* gpa.rc: Move to ...

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2006-12-22 14:56:16 UTC (rev 764)
+++ trunk/src/Makefile.am	2007-01-29 16:07:20 UTC (rev 765)
@@ -22,8 +22,9 @@
 
 bin_PROGRAMS = gpa
 
-INCLUDES = -I$(top_srcdir)/intl -I$(top_srcdir)/pixmaps
-LDADD = @LIBINTL@
+AM_CPPFLAGS = -I$(top_srcdir)/intl -I$(top_srcdir)/pixmaps
+AM_CFLAGS = $(GPGME_CFLAGS) $(GTK_CFLAGS)
+LDADD = $(GPGME_LIBS) $(GTK_LIBS) $(LIBINTL)
 
 gpa_LDFLAGS = $(gpa_res_ldflag)
 gpa_DEPENDENCIES = $(gpa_deps)

Modified: trunk/src/gpakeyexpireop.c
===================================================================
--- trunk/src/gpakeyexpireop.c	2006-12-22 14:56:16 UTC (rev 764)
+++ trunk/src/gpakeyexpireop.c	2007-01-29 16:07:20 UTC (rev 765)
@@ -217,9 +217,10 @@
     }
 }
 
-static void gpa_key_expire_operation_done_error_cb (GpaContext *context, 
-						  gpg_error_t err,
-						  GpaKeyExpireOperation *op)
+static void 
+gpa_key_expire_operation_done_error_cb (GpaContext *context, 
+                                        gpg_error_t err,
+                                        GpaKeyExpireOperation *op)
 {
   switch (gpg_err_code (err))
     {
@@ -231,15 +232,22 @@
     case GPG_ERR_BAD_PASSPHRASE:
       gpa_window_error (_("Wrong passphrase!"), GPA_OPERATION (op)->window);
       break;
+    case GPG_ERR_INV_TIME:
+      gpa_window_error 
+        (_("Invalid time given.\n"
+           "(you may not set the expiration time to the past.)"),
+         GPA_OPERATION (op)->window);
+      break;
     default:
       gpa_gpgme_warning (err);
       break;
     }
 }
 
-static void gpa_key_expire_operation_done_cb (GpaContext *context,
-					      gpg_error_t err,
-					      GpaKeyExpireOperation *op)
+static void 
+gpa_key_expire_operation_done_cb (GpaContext *context,
+                                  gpg_error_t err,
+                                  GpaKeyExpireOperation *op)
 {
   if (gpg_err_code (err) == GPG_ERR_NO_ERROR)
     {

Modified: trunk/src/gpgmeedit.c
===================================================================
--- trunk/src/gpgmeedit.c	2006-12-22 14:56:16 UTC (rev 764)
+++ trunk/src/gpgmeedit.c	2007-01-29 16:07:20 UTC (rev 765)
@@ -71,6 +71,10 @@
   gulong signal_id;
   /* Data to be passed to the previous functions */
   void *opaque;
+  /* The passwd dialog needs to see GPGME_STATUS_NEED_PASSPHRASE_SYM.
+     To make thinks easier it is only passed to the FSM if this flag
+     has been set. */
+  int need_status_passphrase_sym;
 };
 
 /* The edit callback proper */
@@ -82,18 +86,23 @@
   char *result = NULL;
 
   /* Ignore these status lines, as they don't require any response */
-  if (status == GPGME_STATUS_EOF ||
-      status == GPGME_STATUS_GOT_IT ||
-      status == GPGME_STATUS_NEED_PASSPHRASE ||
-      status == GPGME_STATUS_NEED_PASSPHRASE_SYM ||
-      status == GPGME_STATUS_GOOD_PASSPHRASE ||
-      status == GPGME_STATUS_BAD_PASSPHRASE ||
-      status == GPGME_STATUS_USERID_HINT ||
-      status == GPGME_STATUS_SIGEXPIRED ||
-      status == GPGME_STATUS_KEYEXPIRED)
+  if (status == GPGME_STATUS_EOF 
+      || status == GPGME_STATUS_GOT_IT
+      || status == GPGME_STATUS_NEED_PASSPHRASE
+      || status == GPGME_STATUS_NEED_PASSPHRASE_SYM
+      || status == GPGME_STATUS_GOOD_PASSPHRASE
+      || status == GPGME_STATUS_BAD_PASSPHRASE
+      || status == GPGME_STATUS_USERID_HINT
+      || status == GPGME_STATUS_SIGEXPIRED
+      || status == GPGME_STATUS_KEYEXPIRED)
     {
       return parms->err;
     }
+  else if (!parms->need_status_passphrase_sym
+           && status == GPGME_STATUS_NEED_PASSPHRASE_SYM)
+    {
+      return parms->err;
+    }
 
 #if DEBUG_FSM
   g_debug ("edit_fnc: state=%d input=%d (%s)", parms->state, status, args);
@@ -216,6 +225,12 @@
         {
           next_state = EXPIRE_QUIT;
         }
+      else if (status == GPGME_STATUS_GET_LINE &&
+               g_str_equal (args, "keygen.valid"))
+        {
+          next_state = EXPIRE_ERROR;
+          *err = gpg_error (GPG_ERR_INV_TIME);
+        }
       else
         {
           next_state = EXPIRE_ERROR;
@@ -629,6 +644,7 @@
 {
   PASSWD_START,
   PASSWD_COMMAND,
+  PASSWD_ENTERNEW,
   PASSWD_QUIT,
   PASSWD_SAVE,
   PASSWD_ERROR
@@ -638,7 +654,6 @@
 {
   gpgme_passphrase_cb_t func;
   void *opaque;
-  int request_count;
 };
 
 static gpg_error_t
@@ -646,23 +661,27 @@
 {
   switch (state)
     {
+    case PASSWD_COMMAND:
       /* Start the operation */
-    case PASSWD_COMMAND:
       *result = "passwd";
       break;
+    case PASSWD_ENTERNEW:
+      /* No action required.  This state is only used by the
+         passphrase callback.  */
+      break;
+    case PASSWD_QUIT:
       /* End the operation */
-    case PASSWD_QUIT:
       *result = "quit";
       break;
+    case PASSWD_SAVE:
       /* Save */
-    case PASSWD_SAVE:
       *result = "Y";
       break;
+    case PASSWD_ERROR:
       /* Special state: an error ocurred. Do nothing until we can quit */
-    case PASSWD_ERROR:
       break;
+    default:
       /* Can't happen */
-    default:
       return gpg_error (GPG_ERR_GENERAL);
     }
   return gpg_error (GPG_ERR_NO_ERROR);
@@ -689,11 +708,16 @@
         }
       break;
     case PASSWD_COMMAND:
+    case PASSWD_ENTERNEW:
       if (status == GPGME_STATUS_GET_LINE &&
           g_str_equal (args, "keyedit.prompt"))
         {
           next_state = PASSWD_QUIT;
         }
+      else if (status == GPGME_STATUS_NEED_PASSPHRASE_SYM)
+        {
+          next_state = PASSWD_ENTERNEW;
+        }
       else
         {
           next_state = PASSWD_ERROR;
@@ -830,7 +854,7 @@
   /* The new expiration date */
   if (date)
     {
-      g_date_strftime (buf, buf_len, "%F", date);
+      g_date_strftime (buf, buf_len, "%Y-%m-%d", date);
     }
   else
     {
@@ -934,32 +958,33 @@
   return err;
 }
 
-/* Change the passphrase of the key.
+
+/*
+ * Change the passphrase of the key.
  */
 
 /* Special passphrase callback for use within the passwd command */
-gpg_error_t passwd_passphrase_cb (void *hook, const char *uid_hint,
-				  const char *passphrase_info, 
-				  int prev_was_bad, int fd)
+gpg_error_t 
+passwd_passphrase_cb (void *hook, const char *uid_hint,
+                      const char *passphrase_info, 
+                      int prev_was_bad, int fd)
 {
-  int *i = hook;
-
-  if (!prev_was_bad) /* It's the beginning of a passphrase question */
+  struct edit_parms_s *parms = hook;
+  
+  if (parms->state == PASSWD_ENTERNEW)
     {
-      (*i)++;
+      /* Gpg is asking for the new passphrase.  Run the dialog to
+         enter and re-enter the new passphrase.  */
+      return gpa_change_passphrase_dialog_run (hook, uid_hint, 
+					       passphrase_info, 
+					       prev_was_bad, fd);
     }
-  
-  if (*i == 1)
+  else
     {
+      /* Gpg is asking for the passphrase to unprotect the key.  */
       return gpa_passphrase_cb (hook, uid_hint, passphrase_info, 
 				prev_was_bad, fd);
     }
-  else
-    {
-      return gpa_change_passphrase_dialog_run (hook, uid_hint, 
-					       passphrase_info, 
-					       prev_was_bad, fd);
-    }
 }
 
 
@@ -1003,7 +1028,6 @@
   edit_parms->signal_id = 0;
   edit_parms->out = out;
   edit_parms->opaque = passwd_parms;
-  passwd_parms->request_count = 0;
   gpgme_get_passphrase_cb (ctx->ctx, &passwd_parms->func,
 			   &passwd_parms->opaque);
 
@@ -1016,7 +1040,8 @@
   return edit_parms;
 }
 
-gpg_error_t gpa_gpgme_edit_passwd_start (GpaContext *ctx, gpgme_key_t key)
+gpg_error_t 
+gpa_gpgme_edit_passwd_start (GpaContext *ctx, gpgme_key_t key)
 {
   struct edit_parms_s *parms;
   gpg_error_t err;
@@ -1027,13 +1052,13 @@
     {
       return err;
     }
+
   parms = gpa_gpgme_edit_passwd_parms_new (ctx, out);
 
-  /* Use our own passphrase callback: the data is a pointer to an int
-   * that counts the passphrase requests received */
-  gpgme_set_passphrase_cb (ctx->ctx, passwd_passphrase_cb,
-			   &(((struct passwd_parms_s*) 
-			      parms->opaque)->request_count));
+  /* Use our own passphrase callback: The data are the actual edit
+     parms.  */
+  gpgme_set_passphrase_cb (ctx->ctx, passwd_passphrase_cb, parms);
+
   err = gpgme_op_edit_start (ctx->ctx, key, edit_fnc, parms, out);
 
   return err;

Modified: trunk/src/gpgmetools.c
===================================================================
--- trunk/src/gpgmetools.c	2006-12-22 14:56:16 UTC (rev 764)
+++ trunk/src/gpgmetools.c	2007-01-29 16:07:20 UTC (rev 765)
@@ -601,6 +601,12 @@
   gchar *text;
   gchar *keyid, *userid;
   gint i;
+
+  /* Just in case this is called without a user id hint we return a
+     simple text to avoid a crash.  */
+  if (!uid_hint)
+    return gtk_label_new ("Passphrase?");
+
   input = g_strdup (uid_hint);
   /* The first word in the hint is the key ID */
   keyid = input;

Modified: trunk/src/passwddlg.c
===================================================================
--- trunk/src/passwddlg.c	2006-12-22 14:56:16 UTC (rev 764)
+++ trunk/src/passwddlg.c	2007-01-29 16:07:20 UTC (rev 765)
@@ -135,8 +135,7 @@
       gtk_widget_grab_focus (passwd_entry);
       gtk_widget_show_all (dialog);
       response = gtk_dialog_run (GTK_DIALOG (dialog));
-      if (passwd)
-	g_free (passwd);
+      g_free (passwd);
       passwd = g_strdup (gtk_entry_get_text (GTK_ENTRY (passwd_entry)));
       repeat = gtk_entry_get_text (GTK_ENTRY (repeat_entry));
     } 



More information about the Gpa-commits mailing list