[git] Pinentry - branch, master, updated. pinentry-1.0.0-13-g36d32fb

by Werner Koch cvs at cvs.gnupg.org
Fri Feb 3 21:03:13 CET 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The standard pinentry collection".

The branch, master has been updated
       via  36d32fbdedb07b285d01871b3ee66400c81681d3 (commit)
      from  c0d60e130b9bbd21801c8e71e80ab7c36f4ad6bd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 36d32fbdedb07b285d01871b3ee66400c81681d3
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Feb 3 21:00:52 2017 +0100

    Use a shared function to construct the title.
    
    * pinentry/pinentry.c (pinentry_get_title): New.
    * qt/main.cpp (qt_cmd_handler): Use that function for the title.
    * tty/pinentry-tty.c (confirm, password): Ditto.
    * gnome3/pinentry-gnome3.c (create_prompt): Ditto.
    * gtk+-2/pinentry-gtk-2.c (create_window): Ditto.
    * pinentry/pinentry-emacs.c (set_labels): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/gnome3/pinentry-gnome3.c b/gnome3/pinentry-gnome3.c
index c148fd9..27d2132 100644
--- a/gnome3/pinentry-gnome3.c
+++ b/gnome3/pinentry-gnome3.c
@@ -121,7 +121,7 @@ create_prompt (pinentry_t pe, int confirm)
 {
   GcrPrompt *prompt;
   GError *error = NULL;
-  char *msg;
+  char *msg, *p;
   char window_id[32];
 
   /* Create the prompt.  */
@@ -149,9 +149,17 @@ create_prompt (pinentry_t pe, int confirm)
     }
 
   /* Set the messages for the various buttons, etc.  */
-  msg = pinentry_utf8_validate (pe->title ? pe->title : PGMNAME);
-  gcr_prompt_set_title (prompt, msg);
-  g_free (msg);
+  p = pinentry_get_title (pe);
+  if (p)
+    {
+      msg = pinentry_utf8_validate (p);
+      if (msg)
+        {
+          gcr_prompt_set_title (prompt, msg);
+          g_free (msg);
+        }
+      free (p);
+    }
 
   if (pe->description)
     {
diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
index 79cecda..dee0360 100644
--- a/gtk+-2/pinentry-gtk-2.c
+++ b/gtk+-2/pinentry-gtk-2.c
@@ -563,6 +563,7 @@ create_window (pinentry_t ctx)
   GtkWidget *wvbox, *chbox, *bbox;
   GtkAccelGroup *acc;
   gchar *msg;
+  char *p;
 
   repeat_entry = NULL;
 
@@ -626,22 +627,16 @@ create_window (pinentry_t ctx)
   box = gtk_vbox_new (FALSE, HIG_SMALL);
   gtk_box_pack_start (GTK_BOX (chbox), box, TRUE, TRUE, 0);
 
-  if (pinentry->title)
+  p = pinentry_get_title (pinentry);
+  if (p)
     {
-      msg = pinentry_utf8_validate (pinentry->title);
-      gtk_window_set_title (GTK_WINDOW(win), msg);
-    }
-  else if (pinentry->owner_pid)
-    {
-      char buf[100];
-      snprintf (buf, sizeof buf, "%s [%lu]",
-                pinentry->owner_host? pinentry->owner_host:"",
-                pinentry->owner_pid);
-      buf[sizeof buf - 1] = 0;
-      gtk_window_set_title (GTK_WINDOW(win), buf);
+      msg = pinentry_utf8_validate (p);
+      if (msg)
+        gtk_window_set_title (GTK_WINDOW(win), msg);
+      g_free (msg);
+      free (p);
     }
 
-
   if (pinentry->description)
     {
       msg = pinentry_utf8_validate (pinentry->description);
diff --git a/pinentry/pinentry-emacs.c b/pinentry/pinentry-emacs.c
index 50ba406..2f7693b 100644
--- a/pinentry/pinentry-emacs.c
+++ b/pinentry/pinentry-emacs.c
@@ -467,8 +467,14 @@ set_label (pinentry_t pe, const char *name, const char *value)
 static void
 set_labels (pinentry_t pe)
 {
-  if (pe->title)
-    set_label (pe, "SETTITLE", pe->title);
+  char *p;
+
+  p = pinentry_get_title (pe);
+  if (p)
+    {
+      set_label (pe, "SETTITLE", p);
+      free (p);
+    }
   if (pe->description)
     set_label (pe, "SETDESC", pe->description);
   if (pe->error)
diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c
index d33ebe9..7251899 100644
--- a/pinentry/pinentry.c
+++ b/pinentry/pinentry.c
@@ -390,6 +390,33 @@ copy_and_escape (char *buffer, const void *text, size_t textlen)
 }
 
 
+/* Return a malloced string with the title.  The caller mus free the
+ * string.  If no title is available or the title string has an error
+ * NULL is returned.  */
+char *
+pinentry_get_title (pinentry_t pe)
+{
+  char *title;
+
+  if (pe->title)
+    title = strdup (pe->title);
+  else if (pe->owner_pid)
+    {
+      char buf[100];
+      if (pe->owner_host)
+        snprintf (buf, sizeof buf, "[%lu]@%s", pe->owner_pid, pe->owner_host);
+      else
+        snprintf (buf, sizeof buf, "[%lu]",
+                  pe->owner_pid);
+      buf[sizeof buf - 1] = 0;
+      title = strdup (buf);
+    }
+  else
+    title = strdup (this_pgmname);
+
+  return title;
+}
+
 
 /* Run a quality inquiry for PASSPHRASE of LENGTH.  (We need LENGTH
    because not all backends might be able to return a proper
diff --git a/pinentry/pinentry.h b/pinentry/pinentry.h
index 1e891b7..868b4d8 100644
--- a/pinentry/pinentry.h
+++ b/pinentry/pinentry.h
@@ -256,6 +256,7 @@ char *pinentry_utf8_to_local (const char *lc_ctype, const char *text);
    Return NULL on error. */
 char *pinentry_local_to_utf8 (char *lc_ctype, char *text, int secure);
 
+char *pinentry_get_title (pinentry_t pe);
 
 /* Run a quality inquiry for PASSPHRASE of LENGTH. */
 int pinentry_inq_quality (pinentry_t pin,
diff --git a/qt/main.cpp b/qt/main.cpp
index 225c06b..e2af686 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -145,6 +145,7 @@ static int
 qt_cmd_handler(pinentry_t pe)
 {
     QWidget *parent = 0;
+    char *str;
 
     /* FIXME: Add parent window ID to pinentry and GTK.  */
     if (pe->parent_wid) {
@@ -161,9 +162,13 @@ qt_cmd_handler(pinentry_t pe)
         pe->cancel         ? escape_accel(from_utf8(pe->cancel)) :
         pe->default_cancel ? escape_accel(from_utf8(pe->default_cancel)) :
         /* else */           QLatin1String("&Cancel") ;
+
+    str = pinentry_get_title (pe);
     const QString title =
-        pe->title ? from_utf8(pe->title) :
+        str       ? from_utf8(str) :
         /* else */  QLatin1String("pinentry-qt") ;
+    free (str);
+
     const QString repeatError =
         pe->repeat_error_string ? from_utf8(pe->repeat_error_string) :
                                   QLatin1String("Passphrases do not match");
@@ -179,6 +184,8 @@ qt_cmd_handler(pinentry_t pe)
 
 
     if (want_pass) {
+        char *str;
+
         PinEntryDialog pinentry(parent, 0, pe->timeout, true, !!pe->quality_bar,
                                 repeatString, visibilityTT, hideTT);
 
@@ -186,8 +193,11 @@ qt_cmd_handler(pinentry_t pe)
         pinentry.setPrompt(escape_accel(from_utf8(pe->prompt)));
         pinentry.setDescription(from_utf8(pe->description));
         pinentry.setRepeatErrorText(repeatError);
-        if (pe->title) {
-            pinentry.setWindowTitle(from_utf8(pe->title));
+
+        str = pinentry_get_title (pe);
+        if (str) {
+            pinentry.setWindowTitle(from_utf8(str));
+            free (str);
         }
 
         /* If we reuse the same dialog window.  */
diff --git a/tty/pinentry-tty.c b/tty/pinentry-tty.c
index a509d79..8b37340 100644
--- a/tty/pinentry-tty.c
+++ b/tty/pinentry-tty.c
@@ -173,6 +173,7 @@ static int
 confirm (pinentry_t pinentry, FILE *ttyfi, FILE *ttyfo)
 {
   char *msg;
+  char *msgbuffer = NULL;
 
   char ok = 0;
   char notok = 0;
@@ -184,8 +185,10 @@ confirm (pinentry_t pinentry, FILE *ttyfi, FILE *ttyfo)
 
   msg = pinentry->description;
   if (! msg)
-    /* If there is no description, fallback to the title.  */
-    msg = pinentry->title;
+    {
+      /* If there is no description, fallback to the title.  */
+      msg = msgbuffer = pinentry_get_title (pinentry);
+    }
   if (! msg)
     msg = "Confirm:";
 
@@ -194,6 +197,7 @@ confirm (pinentry_t pinentry, FILE *ttyfi, FILE *ttyfo)
       fputs (msg, ttyfo);
       fputc ('\n', ttyfo);
     }
+  free (msgbuffer);
 
   fflush (ttyfo);
 
@@ -377,17 +381,19 @@ static int
 password (pinentry_t pinentry, FILE *ttyfi, FILE *ttyfo)
 {
   char *msg;
+  char *msgbuffer = NULL;
   int done = 0;
 
   msg = pinentry->description;
   if (! msg)
-    msg = pinentry->title;
+    msg = msgbuffer = pinentry_get_title (pinentry);
   if (! msg)
     msg = "Enter your passphrase.";
 
   dump_error_text (ttyfo, pinentry->error);
 
   fprintf (ttyfo, "%s\n", msg);
+  free (msgbuffer);
 
   while (! done)
     {

-----------------------------------------------------------------------

Summary of changes:
 gnome3/pinentry-gnome3.c  | 16 ++++++++++++----
 gtk+-2/pinentry-gtk-2.c   | 21 ++++++++-------------
 pinentry/pinentry-emacs.c | 10 ++++++++--
 pinentry/pinentry.c       | 27 +++++++++++++++++++++++++++
 pinentry/pinentry.h       |  1 +
 qt/main.cpp               | 16 +++++++++++++---
 tty/pinentry-tty.c        | 12 +++++++++---
 7 files changed, 78 insertions(+), 25 deletions(-)


hooks/post-receive
-- 
The standard pinentry collection
http://git.gnupg.org




More information about the Gnupg-commits mailing list