[git] GPA - branch, master, updated. gpa-0.9.4-26-gcff7479

by Werner Koch cvs at cvs.gnupg.org
Fri Apr 11 18:26:31 CEST 2014


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 GNU Privacy Assistant".

The branch, master has been updated
       via  cff74792b61c71a19ca51eb954e3540f2433e9bb (commit)
       via  b73dc82317f0b33a3d45f84ecff18509d7042b2e (commit)
       via  d27c16b339a1f66df3eb62904e57c1b98d64d90b (commit)
       via  a38c5db8c932fb1c17841e1ebbc732733c6bdf28 (commit)
       via  3bd2c29a371ef676e745b03fbc35d50f916a1542 (commit)
       via  a733996b26996a84f82efa60085ebdca4b3b78d6 (commit)
      from  63c1b56a0ec6641534c2ffaff174fe7e46dc9fbd (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 cff74792b61c71a19ca51eb954e3540f2433e9bb
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 11 18:26:40 2014 +0200

    Use the gnupg homedir as default backup directory.
    
    * src/gpabackupop.c (gpa_backup_operation_dialog_run): Apply
    gnupg_homedir.
    --
    
    The user knows that .gnupg/ has sensitive data, thus it is better to
    store backups  by default in that directory.

diff --git a/src/gpabackupop.c b/src/gpabackupop.c
index ff67b71..8a48c03 100644
--- a/src/gpabackupop.c
+++ b/src/gpabackupop.c
@@ -146,7 +146,7 @@ static void
 gpa_backup_operation_class_init (GpaBackupOperationClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->constructor = gpa_backup_operation_constructor;
@@ -157,13 +157,13 @@ gpa_backup_operation_class_init (GpaBackupOperationClass *klass)
   /* Properties */
   g_object_class_install_property (object_class,
 				   PROP_KEY,
-				   g_param_spec_pointer 
+				   g_param_spec_pointer
 				   ("key", "Key",
 				    "Key",
 				    G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
   g_object_class_install_property (object_class,
 				   PROP_FINGERPRINT,
-				   g_param_spec_pointer 
+				   g_param_spec_pointer
 				   ("fpr", "fpr",
 				    "Fingerprint",
 				    G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
@@ -173,7 +173,7 @@ GType
 gpa_backup_operation_get_type (void)
 {
   static GType file_operation_type = 0;
-  
+
   if (!file_operation_type)
     {
       static const GTypeInfo file_operation_info =
@@ -188,12 +188,12 @@ gpa_backup_operation_get_type (void)
         0,              /* n_preallocs */
         (GInstanceInitFunc) gpa_backup_operation_init,
       };
-      
+
       file_operation_type = g_type_register_static (GPA_OPERATION_TYPE,
 						    "GpaBackupOperation",
 						    &file_operation_info, 0);
     }
-  
+
   return file_operation_type;
 }
 
@@ -259,7 +259,8 @@ gpa_backup_operation_dialog_run (GtkWidget *parent, const gchar *key_id)
     }
 
   /* Set the default file name.  */
-  default_comp = g_strdup_printf ("secret-key-%s.asc", key_id);
+  default_comp = g_strdup_printf ("%s/secret-key-%s.asc",
+                                  gnupg_homedir, key_id);
   gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), default_comp);
   g_free (default_comp);
 
@@ -308,15 +309,15 @@ gpa_backup_operation_new (GtkWidget *window, gpgme_key_t key)
   return op;
 }
 
-GpaBackupOperation* 
+GpaBackupOperation*
 gpa_backup_operation_new_from_fpr (GtkWidget *window, const gchar *fpr)
 {
   GpaBackupOperation *op;
-  
+
   op = g_object_new (GPA_BACKUP_OPERATION_TYPE,
 		     "window", window,
 		     "fpr", fpr,
 		     NULL);
-  
+
   return op;
 }

commit b73dc82317f0b33a3d45f84ecff18509d7042b2e
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 11 18:20:35 2014 +0200

    Add creation date column to allow sorting keys by age.
    
    * src/keylist.c (GPA_KEYLIST_COLUMN_CREATED): New.
    (GPA_KEYLIST_COLUMN_CREATED_TS): New.
    (gpa_keylist_init): Add columns.
    (setup_columns): Setup new columns.
    (gpa_keylist_next): Fill new columns.

diff --git a/src/keylist.c b/src/keylist.c
index 51cf401..2932d41 100644
--- a/src/keylist.c
+++ b/src/keylist.c
@@ -56,6 +56,7 @@ typedef enum
   GPA_KEYLIST_COLUMN_IMAGE,
   GPA_KEYLIST_COLUMN_KEYTYPE,
   GPA_KEYLIST_COLUMN_KEYID,
+  GPA_KEYLIST_COLUMN_CREATED,
   GPA_KEYLIST_COLUMN_EXPIRY,
   GPA_KEYLIST_COLUMN_OWNERTRUST,
   GPA_KEYLIST_COLUMN_VALIDITY,
@@ -64,6 +65,7 @@ typedef enum
   GPA_KEYLIST_COLUMN_KEY,
   /* These columns are used only internally for sorting */
   GPA_KEYLIST_COLUMN_HAS_SECRET,
+  GPA_KEYLIST_COLUMN_CREATED_TS,
   GPA_KEYLIST_COLUMN_EXPIRY_TS,
   GPA_KEYLIST_COLUMN_OWNERTRUST_VALUE,
   GPA_KEYLIST_COLUMN_VALIDITY_VALUE,
@@ -199,10 +201,12 @@ gpa_keylist_init (GTypeInstance *instance, void *class_ptr)
 			      G_TYPE_STRING,
 			      G_TYPE_STRING,
 			      G_TYPE_STRING,
+			      G_TYPE_STRING,
 			      G_TYPE_POINTER,
 			      G_TYPE_INT,
 			      G_TYPE_ULONG,
 			      G_TYPE_ULONG,
+			      G_TYPE_ULONG,
 			      G_TYPE_LONG);
 
   /* Setup the view.  */
@@ -423,7 +427,7 @@ gpa_keylist_next (gpgme_key_t key, gpointer data)
   GtkListStore *store;
   GtkTreeIter iter;
   const gchar *keyid, *ownertrust, *validity;
-  gchar *userid, *expiry;
+  gchar *userid, *created, *expiry;
   gboolean has_secret;
   long int val_value;
   const char *keytype;
@@ -471,6 +475,7 @@ gpa_keylist_next (gpgme_key_t key, gpointer data)
   keyid = gpa_gpgme_key_get_short_keyid (key);
   keytype = (key->protocol == GPGME_PROTOCOL_OpenPGP? "P" :
              key->protocol == GPGME_PROTOCOL_CMS? "X" : "?");
+  created = gpa_creation_date_string (key->subkeys->timestamp);
   expiry = gpa_expiry_date_string (key->subkeys->expires);
   ownertrust = gpa_key_ownertrust_string (key);
   validity = gpa_key_validity_string (key);
@@ -503,16 +508,20 @@ gpa_keylist_next (gpgme_key_t key, gpointer data)
   gtk_list_store_set (store, &iter,
 		      GPA_KEYLIST_COLUMN_KEYTYPE, keytype,
 		      GPA_KEYLIST_COLUMN_KEYID, keyid,
+		      GPA_KEYLIST_COLUMN_CREATED, created,
 		      GPA_KEYLIST_COLUMN_EXPIRY, expiry,
 		      GPA_KEYLIST_COLUMN_OWNERTRUST, ownertrust,
 		      GPA_KEYLIST_COLUMN_VALIDITY, validity,
 		      GPA_KEYLIST_COLUMN_USERID, userid,
 		      GPA_KEYLIST_COLUMN_KEY, key,
 		      GPA_KEYLIST_COLUMN_HAS_SECRET, has_secret,
+		      GPA_KEYLIST_COLUMN_CREATED_TS, key->subkeys->timestamp,
+
 		      /* Set "no expiration" to a large value for sorting */
 		      GPA_KEYLIST_COLUMN_EXPIRY_TS,
 		      key->subkeys->expires ?
 		      key->subkeys->expires : G_MAXULONG,
+
 		      GPA_KEYLIST_COLUMN_OWNERTRUST_VALUE,
 		      key->owner_trust,
 		      /* Set revoked and expired keys to "never trust"
@@ -524,6 +533,7 @@ gpa_keylist_next (gpgme_key_t key, gpointer data)
 		      -1);
   /* Clean up */
   g_free (userid);
+  g_free (created);
   g_free (expiry);
 }
 
@@ -623,6 +633,16 @@ setup_columns (GpaKeyList *keylist, gboolean detailed)
   gtk_tree_view_column_set_sort_column_id (column, GPA_KEYLIST_COLUMN_KEYID);
   gtk_tree_view_column_set_sort_indicator (column, TRUE);
 
+  renderer = gtk_cell_renderer_text_new ();
+  column = gtk_tree_view_column_new_with_attributes
+    (NULL, renderer, "text", GPA_KEYLIST_COLUMN_CREATED, NULL);
+  gpa_set_column_title
+    (column, _("Created"),
+     _("The Creation Date is the date the certificate was created."));
+  gtk_tree_view_append_column (GTK_TREE_VIEW (keylist), column);
+  gtk_tree_view_column_set_sort_column_id
+    (column, GPA_KEYLIST_COLUMN_CREATED_TS);
+  gtk_tree_view_column_set_sort_indicator (column, TRUE);
 
   if (detailed)
     {

commit d27c16b339a1f66df3eb62904e57c1b98d64d90b
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 11 18:06:39 2014 +0200

    Fix segv due to wrong signal handler args.
    
    * src/gpagenkeysimpleop.c
    (gpa_gen_key_simple_operation_backup_complete): Add missing arg ERR.

diff --git a/src/gpabackupop.c b/src/gpabackupop.c
index 79cbf75..ff67b71 100644
--- a/src/gpabackupop.c
+++ b/src/gpabackupop.c
@@ -282,23 +282,24 @@ gpa_backup_operation_idle_cb (gpointer data)
   GpaBackupOperation *op = data;
   gchar *file;
 
-  if ((file = gpa_backup_operation_dialog_run (GPA_OPERATION (op)->window,
-					       op->key_id)))
+  file = gpa_backup_operation_dialog_run (GPA_OPERATION (op)->window,
+                                          op->key_id);
+  if (file)
     gpa_backup_operation_do_backup (op, file);
 
   /* FIXME: Error handling.  */
   g_signal_emit_by_name (GPA_OPERATION (op), "completed", 0);
 
-  return FALSE;
+  return FALSE;  /* Remove us from the idle chain.  */
 }
 
 /* API */
 
-GpaBackupOperation* 
+GpaBackupOperation*
 gpa_backup_operation_new (GtkWidget *window, gpgme_key_t key)
 {
   GpaBackupOperation *op;
-  
+
   op = g_object_new (GPA_BACKUP_OPERATION_TYPE,
 		     "window", window,
 		     "key", key,
diff --git a/src/gpagenkeysimpleop.c b/src/gpagenkeysimpleop.c
index 20b9c53..fd6c21a 100644
--- a/src/gpagenkeysimpleop.c
+++ b/src/gpagenkeysimpleop.c
@@ -30,14 +30,14 @@
 
 static GObjectClass *parent_class = NULL;
 
-static void gpa_gen_key_simple_operation_done_cb (GpaContext *context, 
+static void gpa_gen_key_simple_operation_done_cb (GpaContext *context,
 						    gpg_error_t err,
 						    GpaGenKeySimpleOperation *op);
-static void gpa_gen_key_simple_operation_done_error_cb (GpaContext *context, 
+static void gpa_gen_key_simple_operation_done_error_cb (GpaContext *context,
 							  gpg_error_t err,
 							  GpaGenKeySimpleOperation *op);
 
-static gboolean 
+static gboolean
 gpa_gen_key_simple_operation_generate (gpa_keygen_para_t *params,
 				       gboolean do_backup, gpointer data);
 
@@ -94,7 +94,7 @@ static void
 gpa_gen_key_simple_operation_class_init (GpaGenKeySimpleOperationClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->constructor = gpa_gen_key_simple_operation_constructor;
@@ -105,7 +105,7 @@ GType
 gpa_gen_key_simple_operation_get_type (void)
 {
   static GType operation_type = 0;
-  
+
   if (!operation_type)
     {
       static const GTypeInfo operation_info =
@@ -120,22 +120,22 @@ gpa_gen_key_simple_operation_get_type (void)
         0,              /* n_preallocs */
         (GInstanceInitFunc) gpa_gen_key_simple_operation_init,
       };
-      
+
       operation_type = g_type_register_static (GPA_GEN_KEY_OPERATION_TYPE,
 					       "GpaGenKeySimpleOperation",
 					       &operation_info, 0);
     }
-  
+
   return operation_type;
 }
 
 /* API */
 
-GpaGenKeySimpleOperation* 
+GpaGenKeySimpleOperation*
 gpa_gen_key_simple_operation_new (GtkWidget *window)
 {
   GpaGenKeySimpleOperation *op;
-  
+
   op = g_object_new (GPA_GEN_KEY_SIMPLE_OPERATION_TYPE,
 		     "window", window, NULL);
 
@@ -144,7 +144,7 @@ gpa_gen_key_simple_operation_new (GtkWidget *window)
 
 /* Internal */
 
-static gboolean 
+static gboolean
 gpa_gen_key_simple_operation_generate (gpa_keygen_para_t *params,
 				       gboolean do_backup, gpointer data)
 {
@@ -165,10 +165,12 @@ gpa_gen_key_simple_operation_generate (gpa_keygen_para_t *params,
 
 static void
 gpa_gen_key_simple_operation_backup_complete (GpaBackupOperation *backup,
+                                              gpg_error_t err,
 					      GpaGenKeySimpleOperation *op)
 {
-  gpgme_genkey_result_t result = gpgme_op_genkey_result 
-    (GPA_OPERATION (op)->context->ctx);
+  gpgme_genkey_result_t result;
+
+  result = gpgme_op_genkey_result(GPA_OPERATION (op)->context->ctx);
 
   g_signal_emit_by_name (op, "generated_key", result->fpr);
 
@@ -178,7 +180,7 @@ gpa_gen_key_simple_operation_backup_complete (GpaBackupOperation *backup,
 }
 
 static void
-gpa_gen_key_simple_operation_done_cb (GpaContext *context, 
+gpa_gen_key_simple_operation_done_cb (GpaContext *context,
 				      gpg_error_t err,
 				      GpaGenKeySimpleOperation *op)
 {
@@ -188,11 +190,12 @@ gpa_gen_key_simple_operation_done_cb (GpaContext *context,
 
       if (op->do_backup)
 	{
-	  GpaBackupOperation *backup = gpa_backup_operation_new_from_fpr 
-	    (op->wizard, result->fpr);
+	  GpaBackupOperation *backup;
+
+          backup = gpa_backup_operation_new_from_fpr (op->wizard, result->fpr);
 
-	  g_signal_connect (backup, "completed", G_CALLBACK 
-			    (gpa_gen_key_simple_operation_backup_complete), 
+	  g_signal_connect (backup, "completed", G_CALLBACK
+			    (gpa_gen_key_simple_operation_backup_complete),
 			    op);
 	}
       else
@@ -206,7 +209,7 @@ gpa_gen_key_simple_operation_done_cb (GpaContext *context,
 }
 
 static void
-gpa_gen_key_simple_operation_done_error_cb (GpaContext *context, 
+gpa_gen_key_simple_operation_done_error_cb (GpaContext *context,
 					      gpg_error_t err,
 					      GpaGenKeySimpleOperation *op)
 {

commit a38c5db8c932fb1c17841e1ebbc732733c6bdf28
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 11 14:15:57 2014 +0200

    Make use of a running GPA server.
    
    * src/server.c (cmd_start_clipboard): New.
    (cmd_start_filemanager): New.
    (register_commands): Add new commands.
    (cmd_getinfo): Add sub-command "name".
    (check_name_cb, gpa_check_server, gpa_send_to_server): New.
    * src/gpa.c (option_entries): Add option --no-remote.  Remove
    options --gpg-binary and --gpgsm-binary.
    (struct gpa_args_t): Add no_remote.  Remove gpg_binary and
    gpgsm_binary.
    (dummy_arg): New.
    (main): Check for running server and start if desired.  Factor some
    code out to ...
    (open_requested_window): new.  Add code to connect to a running server.

diff --git a/doc/gpa.1 b/doc/gpa.1
index 86cf625..454fe29 100644
--- a/doc/gpa.1
+++ b/doc/gpa.1
@@ -24,7 +24,11 @@ Open the clipboard.
 Start with the card-manager open.
 .TP
 .B \-d, \-\-daemon
-Enable the UI server.
+Only start the UI server and no user interface.
+.TP
+.B \-\-no-remote
+Do not connect to a running instance but start a new one.  This can
+also be used to not start an UI server.
 .TP
 .B \-\-debug-edit-fsm
 Debug the Finite State Machine (FSM).
@@ -42,18 +46,6 @@ Enable logging on Win32 systems.
 Start with the file-manager open. This is the \fIdefault\fP if one or more
 \fIFILE(S)\fP are added to the command arguments.
 .TP
-.B \-\-gpg-binary=\fIFILE\fP
-Path to the
-.BR gpg (1)
-or
-.BR gpg2 (1)
-binary.
-.TP
-.B \-\-gpgsm-binary=\fIFILE\fP
-Path to the
-.BR gpgsm (1)
-binary.
-.TP
 .B \-k, \-\-keyring
 Start with the keyring editor. This is the \fIdefault\fP.
 .TP
@@ -77,6 +69,9 @@ Print usage information and exit.
 .TP
 .I ~/.gnupg/gpa.conf
 Standard user configuration file read by \fBgpa\fP on startup.
+.TP
+.I ~/.gnupg/S.uiserver
+Socket listening for commands to the UI server.
 
 .SH "BUGS"
 Please report bugs to
diff --git a/src/gpa.c b/src/gpa.c
index 2b2ec64..4e67bb2 100644
--- a/src/gpa.c
+++ b/src/gpa.c
@@ -70,19 +70,20 @@ typedef struct
   gboolean start_settings;
   gboolean start_only_server;
   gboolean disable_x509;
+  gboolean no_remote;
   gboolean enable_logging;
   gchar *options_filename;
-  char  *gpg_binary;
-  char  *gpgsm_binary;
 } gpa_args_t;
 
+static char *dummy_arg;
+
 static gpa_args_t args;
 
 
 /* The copyright notice.  */
 static const char *copyright =
 "Copyright (C) 2000-2002 Miguel Coca, G-N-U GmbH, Intevation GmbH.\n"
-"Copyright (C) 2005-2013 g10 Code GmbH.\n"
+"Copyright (C) 2005-2014 g10 Code GmbH.\n"
 "This program comes with ABSOLUTELY NO WARRANTY.\n"
 "This is free software, and you are welcome to redistribute it\n"
 "under certain conditions.  See the file COPYING for details.\n";
@@ -113,11 +114,13 @@ static GOptionEntry option_entries[] =
     { "settings", 's', 0, G_OPTION_ARG_NONE, &args.start_settings,
       N_("Open the settings dialog"), NULL },
     { "daemon", 'd', 0, G_OPTION_ARG_NONE, &args.start_only_server,
-      N_("Enable the UI server"), NULL },
+      N_("Only start the UI server"), NULL },
     { "disable-x509", 0, 0, G_OPTION_ARG_NONE, &args.disable_x509,
       N_("Disable support for X.509"), NULL },
     { "options", 'o', 0, G_OPTION_ARG_FILENAME, &args.options_filename,
       N_("Read options from file"), "FILE" },
+    { "no-remote", 0, 0, G_OPTION_ARG_NONE, &args.no_remote,
+      N_("Do not connect to a running instance"), NULL },
     /* Note:  the cms option will eventually be removed.  */
     { "cms", 'x', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
       &cms_hack, NULL, NULL },
@@ -128,9 +131,9 @@ static GOptionEntry option_entries[] =
     { "enable-logging", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
       &args.enable_logging, NULL, NULL },
     { "gpg-binary", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
-      &args.gpg_binary, NULL, NULL },
+      &dummy_arg, NULL, NULL },
     { "gpgsm-binary", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
-      &args.gpgsm_binary, NULL, NULL },
+      &dummy_arg, NULL, NULL },
     { NULL }
   };
 
@@ -315,6 +318,97 @@ dummy_log_func (const gchar *log_domain, GLogLevelFlags log_level,
 }
 
 
+
+/* Helper for main.  */
+static gpg_error_t
+open_requested_window (int argc, char **argv, int use_server)
+{
+  gpg_error_t err = 0;
+  int did_server = 0;
+  int i;
+
+  /* Don't open the key manager if any files are given on the command
+     line.  Ditto for the clipboard.  */
+  if (args.start_key_manager && (optind >= argc))
+    {
+      if (use_server)
+        {
+          did_server = 1;
+          err = gpa_send_to_server ("START_KEYMANAGER");
+        }
+      else
+        gpa_open_key_manager (NULL, NULL);
+    }
+
+  if (args.start_clipboard && (optind >= argc))
+    {
+      if (use_server)
+        {
+          did_server = 1;
+          err = gpa_send_to_server ("START_CLIPBOARD");
+        }
+      else
+        gpa_open_clipboard (NULL, NULL);
+    }
+
+  if (args.start_file_manager || (optind < argc))
+    {
+      /* Do not use the server if there are file args - see below.  */
+      if (use_server && !(optind < argc))
+        {
+          did_server = 1;
+          err = gpa_send_to_server ("START_FILEMANAGER");
+        }
+      else
+        gpa_open_filemanager (NULL, NULL);
+    }
+
+#ifdef ENABLE_CARD_MANAGER
+  if (args.start_card_manager)
+    {
+      if (use_server)
+        {
+          did_server = 1;
+          err = gpa_send_to_server ("START_CARDMANAGER");
+        }
+      else
+        gpa_open_cardmanager (NULL, NULL);
+    }
+#endif /*ENABLE_CARD_MANAGER*/
+
+  if (args.start_settings)
+    {
+      if (use_server)
+        {
+          did_server = 1;
+          err = gpa_send_to_server ("START_CONFDIALOG");
+        }
+      else
+        gpa_open_settings_dialog (NULL, NULL);
+    }
+
+  /* If there are any command line arguments that are not options, try
+     to open them as files in the filemanager.  However if we are to
+     connect to a server this can't be done because the running
+     instance may already have files in the file manager and thus we
+     better do not add new files.  Instead we start a new instance. */
+  if (use_server)
+    {
+      if (!did_server)
+        err = -1; /* Create a new instance.  */
+    }
+  else
+    {
+      for (i = optind; i < argc; i++)
+        gpa_file_manager_open_file (GPA_FILE_MANAGER
+                                    (gpa_file_manager_get_instance ()),
+                                    argv[i]);
+    }
+
+  return err;
+}
+
+
 int
 main (int argc, char *argv[])
 {
@@ -322,7 +416,6 @@ main (int argc, char *argv[])
   GOptionContext *context;
   char *configname = NULL;
   char *keyservers_configname = NULL;
-  int i;
 
   /* Under W32 logging is disabled by default to prevent MS Windows NT
      from opening a console.  */
@@ -452,6 +545,26 @@ main (int argc, char *argv[])
   gpa_options_set_file (gpa_options_get_instance (), configname);
   g_free (configname);
 
+  /* Check whether we need to start a server or to simply open a
+     windowin an existing server.  */
+  switch (gpa_check_server ())
+    {
+    case 0: /* No running server on the expected socket.  Start one.  */
+      gpa_start_server ();
+      break;
+    case 1: /* An old instance or a differen UI server is already running.
+               Do not start a server.  */
+      break;
+    case 2: /* An instance is already running - open the appropriate
+               window and terminate.  */
+      if (args.no_remote)
+        break;
+      if (!open_requested_window (argc, argv, 1))
+        return 0; /* ready */
+      /* Start a new instance on error.  */
+      break;
+    }
+
   /* Locate the list of keyservers.  */
   keyservers_configname = g_build_filename (gnupg_homedir, "keyservers", NULL);
 
@@ -472,43 +585,10 @@ main (int argc, char *argv[])
   gpa_init_filewatch ();
 
   /* Startup whatever has been requested by the user.  */
-  if (args.start_only_server)
-    {
-      /* Fire up the server.  Note that the server allows to start the
-         other parts too.  */
-      gpa_start_server ();
-    }
-  else
-    {
-      /* Don't open the key manager if any files are given on the
-         command line.  Ditto for the clipboard.  */
-      if (args.start_key_manager && (optind >= argc))
-	gpa_open_key_manager (NULL, NULL);
-
-      if (args.start_clipboard && (optind >= argc))
-	gpa_open_clipboard (NULL, NULL);
-
-      if (args.start_file_manager || (optind < argc))
-	gpa_open_filemanager (NULL, NULL);
-
-#ifdef ENABLE_CARD_MANAGER
-      if (args.start_card_manager)
-	gpa_open_cardmanager (NULL, NULL);
-#endif /*ENABLE_CARD_MANAGER*/
-
-      if (args.start_settings)
-	gpa_open_settings_dialog (NULL, NULL);
-
-      /* If there are any command line arguments that are not options,
-	 try to open them as files in the filemanager */
-      for (i = optind; i < argc; i++)
-	gpa_file_manager_open_file (GPA_FILE_MANAGER
-				    (gpa_file_manager_get_instance ()),
-				    argv[i]);
-    }
+  if (!args.start_only_server)
+    open_requested_window (argc, argv, 0);
 
   gtk_main ();
 
   return 0;
 }
-
diff --git a/src/gpa.h b/src/gpa.h
index 1003a2f..b21a0d0 100644
--- a/src/gpa.h
+++ b/src/gpa.h
@@ -108,6 +108,8 @@ typedef void (*GPADefaultKeyChanged) (gpointer user_data);
 void gpa_run_server_continuation (assuan_context_t ctx, gpg_error_t err);
 void gpa_start_server (void);
 void gpa_stop_server (void);
+int  gpa_check_server (void);
+gpg_error_t gpa_send_to_server (const char *cmd);
 
 
 typedef struct gpa_filewatch_id_s *gpa_filewatch_id_t;
diff --git a/src/server.c b/src/server.c
index 6bbbef3..78bb4b9 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1161,6 +1161,34 @@ cmd_start_keymanager (assuan_context_t ctx, char *line)
   return assuan_process_done (ctx, 0);
 }
 
+static const char hlp_start_clipboard[] =
+  "START_CLIPBOARD\n"
+  "\n"
+  "Pop up the clipboard window.  The client expects that the\n"
+  "clipboard is brought into the foregound and that this command\n"
+  "immediatley returns.";
+static gpg_error_t
+cmd_start_clipboard (assuan_context_t ctx, char *line)
+{
+  gpa_open_clipboard (NULL, NULL);
+
+  return assuan_process_done (ctx, 0);
+}
+
+static const char hlp_start_filemanager[] =
+  "START_FILEMANAGER\n"
+  "\n"
+  "Pop up the file manager window.  The client expects that the file\n"
+  "manager is brought into the foregound and that this command\n"
+  "immediatley returns.";
+static gpg_error_t
+cmd_start_filemanager (assuan_context_t ctx, char *line)
+{
+  gpa_open_filemanager (NULL, NULL);
+
+  return assuan_process_done (ctx, 0);
+}
+
 
 #ifdef ENABLE_CARD_MANAGER
 static const char hlp_start_cardmanager[] =
@@ -1202,6 +1230,7 @@ static const char hlp_getinfo[] =
   "Supported values for WHAT are:\n"
   "\n"
   "  version     - Return the version of the program.\n"
+  "  name        - Return the name of the program\n"
   "  pid         - Return the process id of the server.";
 static gpg_error_t
 cmd_getinfo (assuan_context_t ctx, char *line)
@@ -1220,6 +1249,11 @@ cmd_getinfo (assuan_context_t ctx, char *line)
       snprintf (numbuf, sizeof numbuf, "%lu", (unsigned long)getpid ());
       err = assuan_send_data (ctx, numbuf, strlen (numbuf));
     }
+  else if (!strcmp (line, "name"))
+    {
+      const char *s = PACKAGE_NAME;
+      err = assuan_send_data (ctx, s, strlen (s));
+    }
   else
     err = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
 
@@ -1617,10 +1651,12 @@ register_commands (assuan_context_t ctx)
     { "DECRYPT", cmd_decrypt, hlp_decrypt },
     { "VERIFY", cmd_verify, hlp_verify },
     { "START_KEYMANAGER", cmd_start_keymanager, hlp_start_keymanager },
-    { "START_CONFDIALOG", cmd_start_confdialog, hlp_start_confdialog },
+    { "START_CLIPBOARD", cmd_start_clipboard, hlp_start_clipboard },
+    { "START_FILEMANAGER", cmd_start_filemanager, hlp_start_filemanager },
 #ifdef ENABLE_CARD_MANAGER
     { "START_CARDMANAGER", cmd_start_cardmanager, hlp_start_cardmanager },
 #endif /*ENABLE_CARD_MANAGER*/
+    { "START_CONFDIALOG", cmd_start_confdialog, hlp_start_confdialog },
     { "GETINFO", cmd_getinfo, hlp_getinfo },
     { "FILE", cmd_file },
     { "ENCRYPT_FILES", cmd_encrypt_files },
@@ -1998,3 +2034,100 @@ gpa_stop_server (void)
   if (!connection_counter)
     gtk_main_quit ();
 }
+
+
+/* Helper for gpa_check-server.  */
+static gpg_error_t
+check_name_cb (void *opaque, const void *buffer, size_t length)
+{
+  int *result = opaque;
+  const char *name = PACKAGE_NAME;
+
+  if (length == strlen (name) && !strcmp (name, buffer))
+    *result = 1;
+
+  return 0;
+}
+
+
+/* Check whether an UI server is already running:
+   0  = no
+   1  = yes
+   2  = yes - same program
+ */
+int
+gpa_check_server (void)
+{
+  gpg_error_t err;
+  assuan_context_t ctx;
+  int name_check = 0;
+  int result;
+
+  err = assuan_new (&ctx);
+  if (!err)
+    err = assuan_socket_connect (ctx,
+                                 gpgme_get_dirinfo ("uiserver-socket"), 0, 0);
+  if (err)
+    {
+      g_message ("error connecting an UI server: %s - %s",
+                 gpg_strerror (err), "assuming not running");
+      result = 0;
+      goto leave;
+    }
+
+  err = assuan_transact (ctx, "GETINFO name",
+                         check_name_cb, &name_check, NULL, NULL, NULL, NULL);
+  if (err)
+    {
+      g_message ("requesting name of UI server failed: %s - %s",
+                 gpg_strerror (err), "assuming not running");
+      result = 1;
+      goto leave;
+    }
+
+  if (name_check)
+    {
+      g_message ("an instance of this program is already running");
+      result = 2;
+    }
+  else
+    {
+      g_message ("an different UI server is already running");
+      result = 1;
+    }
+
+ leave:
+  assuan_release (ctx);
+  return result;
+}
+
+
+/* Send a command to the server.  */
+gpg_error_t
+gpa_send_to_server (const char *cmd)
+{
+  gpg_error_t err;
+  assuan_context_t ctx;
+
+  err = assuan_new (&ctx);
+  if (!err)
+    err = assuan_socket_connect (ctx,
+                                 gpgme_get_dirinfo ("uiserver-socket"), 0, 0);
+  if (err)
+    {
+      g_message ("error connecting the UI server: %s", gpg_strerror (err));
+      goto leave;
+    }
+
+  err = assuan_transact (ctx, cmd, NULL, NULL, NULL, NULL, NULL, NULL);
+  if (err)
+    {
+      g_message ("error sending '%s' to the UI server: %s",
+                 cmd, gpg_strerror (err));
+      goto leave;
+    }
+
+ leave:
+  assuan_release (ctx);
+  return err;
+}

commit 3bd2c29a371ef676e745b03fbc35d50f916a1542
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Apr 10 14:24:56 2014 +0200

    w32: Inhibit console window while trying to start the agent.
    
    * src/gpgmetools.c (gpa_start_agent): Use gpgme_op_spawn to start the
    agent.

diff --git a/src/gpgmetools.c b/src/gpgmetools.c
index 607e9eb..8c16622 100644
--- a/src/gpgmetools.c
+++ b/src/gpgmetools.c
@@ -1562,8 +1562,29 @@ gpa_start_simple_gpg_command (gboolean (*cb)(void *opaque, char *line),
 void
 gpa_start_agent (void)
 {
-  gpa_start_simple_gpg_command (NULL, NULL, GPGME_PROTOCOL_ASSUAN, 1,
-                                "NOP", "/bye", NULL);
+  gpg_error_t err;
+  gpgme_ctx_t ctx;
+  char *pgm;
+  const char *argv[3];
+
+  pgm = get_gpg_connect_agent_path ();
+  if (!pgm)
+    {
+      g_message ("tool to start the agent is not available");
+      return;
+    }
+
+  ctx = gpa_gpgme_new ();
+  gpgme_set_protocol (ctx, GPGME_PROTOCOL_SPAWN);
+  argv[0] = "";   /* Auto-insert the basename.  */
+  argv[1] = "NOP";
+  argv[2] = NULL;
+  err = gpgme_op_spawn (ctx, pgm, argv, NULL, NULL, NULL, GPGME_SPAWN_DETACHED);
+  if (err)
+    g_message ("error running '%s': %s", pgm, gpg_strerror (err));
+  g_free (pgm);
+  gpgme_release (ctx);
+
 }
 
 

commit a733996b26996a84f82efa60085ebdca4b3b78d6
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Apr 9 08:34:42 2014 +0200

    Use gpgme to get the standard home directory.
    
    * src/get-path.c (homedir_from_gpgconf_parser): Remove.
    (homedir_from_gpgconf): Remove.
    (default_homedir): Use gpgme_get_dirinfo.

diff --git a/src/get-path.c b/src/get-path.c
index 71fe0e1..8ccaa63 100644
--- a/src/get-path.c
+++ b/src/get-path.c
@@ -147,81 +147,19 @@ w32_shgetfolderpath (HWND a, int b, HANDLE c, DWORD d, LPSTR e)
 #endif	/* G_OS_WIN32 */
 
 
-
-
 

-struct homedir_from_gpgconf_s
-{
-  GMainLoop *loop;
-  char *homedir;
-};
-
-static gboolean
-homedir_from_gpgconf_parser (void *opaque, char *line)
-{
-  struct homedir_from_gpgconf_s *parm = opaque;
-  char *value, *p;
-
-  if (!line)
-    {
-      /* We are finished with the command.  Stop the loop.  */
-      g_main_loop_quit (parm->loop);
-      return FALSE; /* (The return code does not matter here.)  */
-    }
-
-  value = strchr (line, ':');
-  if (!value)
-    return TRUE; /* Invalid line - keep on running.  */;
-  *value++ = 0;
-  if (strcmp (line, "homedir"))
-    return TRUE; /* Not the right item - keep on running.  */
-
-  p = strchr (value, ':');
-  if (p)
-    *p = 0;
-  decode_percent_string (value);
-  parm->homedir = g_strdup (value);
-  return FALSE; /* Ready - force an EOF.  */
-}
-
-
-/* Retrieve the default home directory via gpgconf and return it as a
-   malloced string.  If this is not possible, return NULL.  */
-static char *
-homedir_from_gpgconf (void)
-{
-  struct homedir_from_gpgconf_s parm;
-
-  memset (&parm, 0, sizeof parm);
-
-  parm.loop = g_main_loop_new (NULL, TRUE);
-
-  if (gpa_start_simple_gpg_command
-      (homedir_from_gpgconf_parser, &parm,
-       GPGME_PROTOCOL_GPGCONF, 0, "--list-dirs", NULL))
-    {
-      g_main_loop_unref (parm.loop);
-      return NULL;
-    }
-
-  g_main_loop_run (parm.loop);
-  g_main_loop_unref (parm.loop);
-  return parm.homedir;
-}
-
-
 /* Get the path to the default home directory.  */
 gchar *
 default_homedir (void)
 {
-  gchar *dir;
+  const char *s;
+  gchar *dir = NULL;
 
-  dir = homedir_from_gpgconf ();
-  if (dir)
-    {
-      g_debug ("Found homedir '%s' via gpgconf", dir);
-      return dir;
-    }
+  s = gpgme_get_dirinfo ("homedir");
+  if (s)
+    return g_strdup (s);
+
+  /* No gpgconf installed.  That is we are using GnuPG-1.  */
 
   /* g_getenv returns string in filename encoding.  */
   dir = (gchar *) g_getenv ("GNUPGHOME");
diff --git a/src/gpgmetools.c b/src/gpgmetools.c
index 23db6c1..607e9eb 100644
--- a/src/gpgmetools.c
+++ b/src/gpgmetools.c
@@ -1447,21 +1447,14 @@ gpg_simple_stdio_cb (GIOChannel *channel, GIOCondition condition,
    This function is used to run
 
     gpgsm --learn-card
-    gpgconf --list-dirs
     gpg-connect-agent NOP /bye
 
    The problem is that under Windows g_spawn does not allow to specify
    flags for the underlying CreateProcess.  Thus it is not possible to
-   create a process detached (i.e. without a console); the result is
-   that a windows pops up.  I can see two solutions: (1) Use a wrapper
-   process to start them detached. or (2) move the required function
-   into GPGME and use that new API.
-
-   With the latest GnuPG we can even forget about gpg-connect-agent
-   and use "gpgconf --launch gpg-agent" instead.  However that is no
-   solution if we are required to use an old gnupg.
-
-
+   create a detached process (i.e. without a console); the result is
+   that a console window pops up.  I can see two solutions: (1) Use a
+   wrapper process to start them detached, or (2) move the required
+   function into GPGME and use that new API.
   */
 gpg_error_t
 gpa_start_simple_gpg_command (gboolean (*cb)(void *opaque, char *line),

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

Summary of changes:
 doc/gpa.1               |   21 +++---
 src/get-path.c          |   76 ++--------------------
 src/gpa.c               |  164 +++++++++++++++++++++++++++++++++++------------
 src/gpa.h               |    2 +
 src/gpabackupop.c       |   32 ++++-----
 src/gpagenkeysimpleop.c |   39 +++++------
 src/gpgmetools.c        |   40 ++++++++----
 src/keylist.c           |   22 ++++++-
 src/server.c            |  135 +++++++++++++++++++++++++++++++++++++-
 9 files changed, 359 insertions(+), 172 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Assistant
http://git.gnupg.org




More information about the Gnupg-commits mailing list