[git] Pinentry - branch, master, updated. pinentry-1.0.0-14-ge467a00

by Werner Koch cvs at cvs.gnupg.org
Fri Feb 3 21:43:31 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  e467a000f87e87582f5838964b6f1e0a960d4445 (commit)
      from  36d32fbdedb07b285d01871b3ee66400c81681d3 (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 e467a000f87e87582f5838964b6f1e0a960d4445
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Feb 3 21:41:05 2017 +0100

    core: Show the command line in the titlebar.
    
    * pinentry/pinentry.c (get_cmdline): New.
    (pinentry_get_title): Add the cmdline to the title.
    --
    
    This works only on Linux assuming that /proc/PID/cmdline is available.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c
index 7251899..517a033 100644
--- a/pinentry/pinentry.c
+++ b/pinentry/pinentry.c
@@ -390,6 +390,39 @@ copy_and_escape (char *buffer, const void *text, size_t textlen)
 }
 
 
+static char *
+get_cmdline (unsigned long pid)
+{
+  char buffer[200];
+  FILE *fp;
+  size_t i, n;
+
+  snprintf (buffer, sizeof buffer, "/proc/%lu/cmdline", pid);
+  buffer[sizeof buffer - 1] = 0;
+
+  fp = fopen (buffer, "rb");
+  if (!fp)
+    return NULL;
+  n = fread (buffer, 1, sizeof buffer - 1, fp);
+  if (n < sizeof buffer -1 && ferror (fp))
+    {
+      /* Some error occurred.  */
+      fclose (fp);
+      return NULL;
+    }
+  /* Arguments are delimites by Nuls.  We should do proper quoting but
+   * that can be a bit complicated, thus we simply replace the Nuls by
+   * spaces.  */
+  for (i=0; i < n; i++)
+    if (!buffer[i])
+      buffer[i] = ' ';
+  buffer[i] = 0; /* Make sure the last byte is the string terminator.  */
+  fclose (fp);
+
+  return strdup (buffer);
+}
+
+
 /* 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.  */
@@ -402,13 +435,23 @@ pinentry_get_title (pinentry_t pe)
     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);
+      char buf[200];
+      char *cmdline = get_cmdline (pe->owner_pid);
+
+      if (pe->owner_host && cmdline)
+        snprintf (buf, sizeof buf, "[%lu]@%s (%s)",
+                  pe->owner_pid, pe->owner_host, cmdline);
+      else if (cmdline)
+        snprintf (buf, sizeof buf, "[%lu] (%s)",
+                  pe->owner_pid, cmdline);
+      else 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;
+      free (cmdline);
       title = strdup (buf);
     }
   else

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

Summary of changes:
 pinentry/pinentry.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)


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




More information about the Gnupg-commits mailing list