[git] GnuPG - branch, master, updated. gnupg-2.1.8-30-g9e65bbd

by Werner Koch cvs at cvs.gnupg.org
Wed Sep 16 19:10:42 CEST 2015


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 Guard".

The branch, master has been updated
       via  9e65bbd255c43f0e59f35b0003052234d69042be (commit)
      from  8eb3a1797a1e7cb59a8342a8aa917756fe67949f (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 9e65bbd255c43f0e59f35b0003052234d69042be
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Sep 14 18:49:32 2015 +0200

    g13: Move some code to a separate module.
    
    * g13/g13-common.c, g13/g13-common.h: New.
    * g13/Makefile.am (g13_SOURCES): Add new files.
    * g13/g13.c (g13_errors_seen): Move to g13-common.c.
    (cmdline_conttype): New.
    (main): Use g13_init_signals and g13_install_emergency_cleanup.
    (emergency_cleanup, g13_exit): Move to g13-common.c.
    * g13/g13.h: Move OPT and some other code to g13-common.h.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g13/Makefile.am b/g13/Makefile.am
index 7d627cb..152cf36 100644
--- a/g13/Makefile.am
+++ b/g13/Makefile.am
@@ -30,6 +30,7 @@ AM_CFLAGS =  $(LIBGCRYPT_CFLAGS) $(LIBASSUAN_CFLAGS) $(NPTH_CFLAGS)
 
 g13_SOURCES = \
 	g13.c g13.h \
+	g13-common.c g13-common.h \
 	keyblob.h \
 	utils.c utils.h \
 	server.c server.h \
diff --git a/g13/g13-common.c b/g13/g13-common.c
new file mode 100644
index 0000000..e6adcb8
--- /dev/null
+++ b/g13/g13-common.c
@@ -0,0 +1,86 @@
+/* g13-common.c - Common code for G13 modules
+ * Copyright (C) 2009, 2015 Werner Koch
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "g13-common.h"
+#include <gcrypt.h>
+#include <assuan.h>
+#include "i18n.h"
+#include "sysutils.h"
+
+
+
+/* Global variable to keep an error count. */
+int g13_errors_seen = 0;
+
+
+
+/* Note: This function is used by signal handlers!. */
+static void
+emergency_cleanup (void)
+{
+  gcry_control (GCRYCTL_TERM_SECMEM);
+}
+
+
+/* Wrapper around gnupg_init_signals.  */
+void
+g13_init_signals (void)
+{
+  gnupg_init_signals (0, emergency_cleanup);
+}
+
+
+/* Install a regular exit handler to make real sure that the secure
+   memory gets wiped out.  */
+void
+g13_install_emergency_cleanup (void)
+{
+  if (atexit (emergency_cleanup))
+    {
+      log_error ("atexit failed\n");
+      g13_exit (2);
+    }
+}
+
+
+/* Use this function instead of exit() in all g13 modules.  */
+void
+g13_exit (int rc)
+{
+  gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE);
+  if (opt.debug & DBG_MEMSTAT_VALUE)
+    {
+      gcry_control( GCRYCTL_DUMP_MEMORY_STATS );
+      gcry_control( GCRYCTL_DUMP_RANDOM_STATS );
+    }
+  if (opt.debug)
+    gcry_control (GCRYCTL_DUMP_SECMEM_STATS );
+  emergency_cleanup ();
+  rc = rc? rc : log_get_errorcount(0)? 2 : g13_errors_seen? 1 : 0;
+  exit (rc);
+}
diff --git a/g13/g13.h b/g13/g13-common.h
similarity index 74%
copy from g13/g13.h
copy to g13/g13-common.h
index c766813..f27dca4 100644
--- a/g13/g13.h
+++ b/g13/g13-common.h
@@ -1,5 +1,6 @@
 /* g13.h - Global definitions for G13.
  * Copyright (C) 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2009, 2015 Werner Koch.
  *
  * This file is part of GnuPG.
  *
@@ -17,8 +18,8 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef G13_H
-#define G13_H
+#ifndef G13_COMMON_H
+#define G13_COMMON_H
 
 #ifdef GPG_ERR_SOURCE_DEFAULT
 #error GPG_ERR_SOURCE_DEFAULT already defined
@@ -30,7 +31,22 @@
 #include "../common/status.h"
 #include "../common/session-env.h"
 
-/* A large struct named "opt" to keep global flags.  */
+
+/* Debug values and macros.  */
+#define DBG_MOUNT_VALUE     1	/* Debug mount or device stuff. */
+#define DBG_CRYPTO_VALUE    4	/* Debug low level crypto.  */
+#define DBG_MEMORY_VALUE   32	/* Debug memory allocation stuff.  */
+#define DBG_MEMSTAT_VALUE 128	/* Show memory statistics.  */
+#define DBG_IPC_VALUE    1024   /* Debug assuan communication.  */
+
+#define DBG_MOUNT    (opt.debug & DBG_MOUNT_VALUE)
+#define DBG_CRYPTO   (opt.debug & DBG_CRYPTO_VALUE)
+#define DBG_MEMORY   (opt.debug & DBG_MEMORY_VALUE)
+#define DBG_IPC      (opt.debug & DBG_IPC_VALUE)
+
+/* A large struct named "opt" to keep global flags.  Note that this
+   struct is used by g13 and g13-syshelp and thus some fields may only
+   make sense for one of them.  */
 struct
 {
   unsigned int debug; /* Debug flags (DBG_foo_VALUE).  */
@@ -65,48 +81,13 @@ struct
 } opt;
 
 
-/* Debug values and macros.  */
-#define DBG_MOUNT_VALUE     1	/* Debug mount or device stuff. */
-#define DBG_CRYPTO_VALUE    4	/* Debug low level crypto.  */
-#define DBG_MEMORY_VALUE   32	/* Debug memory allocation stuff.  */
-#define DBG_MEMSTAT_VALUE 128	/* Show memory statistics.  */
-#define DBG_IPC_VALUE    1024   /* Debug assuan communication.  */
-
-#define DBG_MOUNT    (opt.debug & DBG_MOUNT_VALUE)
-#define DBG_CRYPTO   (opt.debug & DBG_CRYPTO_VALUE)
-#define DBG_MEMORY   (opt.debug & DBG_MEMORY_VALUE)
-#define DBG_IPC      (opt.debug & DBG_IPC_VALUE)
-
-/* Forward declaration for an object defined in server.c.  */
-struct server_local_s;
-
-/* Session control object.  This object is passed down to most
-   functions.  The default values for it are set by
-   g13_init_default_ctrl(). */
-struct server_control_s
-{
-  int no_server;      /* We are not running under server control */
-  int  status_fd;     /* Only for non-server mode */
-  struct server_local_s *server_local;
-
-  int agent_seen;     /* Flag indicating that the gpg-agent has been
-                         accessed.  */
-
-  int with_colons;    /* Use column delimited output format */
-
-  /* Type of the current container.  See the CONTTYPE_ constants.  */
-  int conttype;
-
-};
-
-
-

-/*-- g13.c --*/
+/*-- g13-common.c --*/
+void g13_init_signals (void);
+void g13_install_emergency_cleanup (void);
 void g13_exit (int rc);
-void g13_init_default_ctrl (struct server_control_s *ctrl);
 
-/*-- server.c (commonly used, thus declared here) --*/
+/*-- server.c and g13-sh-cmd.c --*/
 gpg_error_t g13_status (ctrl_t ctrl, int no, ...) GPGRT_ATTR_SENTINEL(0);
 
 
-#endif /*G13_H*/
+#endif /*G13_COMMON_H*/
diff --git a/g13/g13.c b/g13/g13.c
index a6fddd0..e6c7613 100644
--- a/g13/g13.c
+++ b/g13/g13.c
@@ -186,10 +186,6 @@ static struct debug_flags_s debug_flags [] =
 /* The timer tick interval used by the idle task.  */
 #define TIMERTICK_INTERVAL_SEC     (1)
 
-
-/* Global variable to keep an error count. */
-int g13_errors_seen = 0;
-
 /* It is possible that we are currently running under setuid permissions.  */
 static int maybe_setuid = 1;
 
@@ -204,11 +200,14 @@ static int shutdown_pending;
 static npth_t idle_task_thread;
 
 
+/* The container type as specified on the command line.  */
+static int cmdline_conttype;
+
+
 

 static void set_cmd (enum cmd_and_opt_values *ret_cmd,
                      enum cmd_and_opt_values new_cmd );
 
-static void emergency_cleanup (void);
 static void start_idle_task (void);
 static void join_idle_task (void);
 
@@ -374,7 +373,7 @@ main ( int argc, char **argv)
 
   may_coredump = disable_core_dumps ();
 
-  gnupg_init_signals (0, emergency_cleanup);
+  g13_init_signals ();
 
   dotlock_create (NULL, 0); /* Register locking cleanup.  */
 
@@ -646,13 +645,8 @@ main ( int argc, char **argv)
   /* Setup the debug flags for all subsystems.  */
   set_debug ();
 
-  /* Install a regular exit handler to make real sure that the secure
-     memory gets wiped out.  */
-  if (atexit (emergency_cleanup))
-    {
-      log_error ("atexit failed\n");
-      g13_exit (2);
-    }
+  /* Install emergency cleanup handler.  */
+  g13_install_emergency_cleanup ();
 
   /* Terminate if we found any error until now.  */
   if (log_get_errorcount(0))
@@ -761,36 +755,11 @@ main ( int argc, char **argv)
 }
 
 
-/* Note: This function is used by signal handlers!. */
-static void
-emergency_cleanup (void)
-{
-  gcry_control (GCRYCTL_TERM_SECMEM );
-}
-
-
-void
-g13_exit (int rc)
-{
-  gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE);
-  if (opt.debug & DBG_MEMSTAT_VALUE)
-    {
-      gcry_control( GCRYCTL_DUMP_MEMORY_STATS );
-      gcry_control( GCRYCTL_DUMP_RANDOM_STATS );
-    }
-  if (opt.debug)
-    gcry_control (GCRYCTL_DUMP_SECMEM_STATS );
-  emergency_cleanup ();
-  rc = rc? rc : log_get_errorcount(0)? 2 : g13_errors_seen? 1 : 0;
-  exit (rc);
-}
-
-
 /* Store defaults into the per-connection CTRL object.  */
 void
 g13_init_default_ctrl (struct server_control_s *ctrl)
 {
-  ctrl->conttype = CONTTYPE_ENCFS;
+  ctrl->conttype = cmdline_conttype? cmdline_conttype : CONTTYPE_ENCFS;
 }
 
 
diff --git a/g13/g13.h b/g13/g13.h
index c766813..303c84b 100644
--- a/g13/g13.h
+++ b/g13/g13.h
@@ -20,62 +20,8 @@
 #ifndef G13_H
 #define G13_H
 
-#ifdef GPG_ERR_SOURCE_DEFAULT
-#error GPG_ERR_SOURCE_DEFAULT already defined
-#endif
-#define GPG_ERR_SOURCE_DEFAULT  GPG_ERR_SOURCE_G13
-#include <gpg-error.h>
+#include "g13-common.h"
 
-#include "../common/util.h"
-#include "../common/status.h"
-#include "../common/session-env.h"
-
-/* A large struct named "opt" to keep global flags.  */
-struct
-{
-  unsigned int debug; /* Debug flags (DBG_foo_VALUE).  */
-  int verbose;        /* Verbosity level.  */
-  int quiet;          /* Be as quiet as possible.  */
-  int dry_run;        /* Don't change any persistent data.  */
-
-  const char *homedir;         /* Configuration directory name.  */
-  const char *config_filename; /* Name of the used config file.  */
-
-  /* Filename of the AGENT program.  */
-  const char *agent_program;
-
-  /* Filename of the GPG program.  Unless set via an program option it
-     is initialzed at the first engine startup to the standard gpg
-     filename.  */
-  const char *gpg_program;
-
-  /* Environment variables passed along to the engine.  */
-  char *display;
-  char *ttyname;
-  char *ttytype;
-  char *lc_ctype;
-  char *lc_messages;
-  char *xauthority;
-  char *pinentry_user_data;
-  session_env_t session_env;
-
-  /* Name of the output file - FIXME: what is this?  */
-  const char *outfile;
-
-} opt;
-
-
-/* Debug values and macros.  */
-#define DBG_MOUNT_VALUE     1	/* Debug mount or device stuff. */
-#define DBG_CRYPTO_VALUE    4	/* Debug low level crypto.  */
-#define DBG_MEMORY_VALUE   32	/* Debug memory allocation stuff.  */
-#define DBG_MEMSTAT_VALUE 128	/* Show memory statistics.  */
-#define DBG_IPC_VALUE    1024   /* Debug assuan communication.  */
-
-#define DBG_MOUNT    (opt.debug & DBG_MOUNT_VALUE)
-#define DBG_CRYPTO   (opt.debug & DBG_CRYPTO_VALUE)
-#define DBG_MEMORY   (opt.debug & DBG_MEMORY_VALUE)
-#define DBG_IPC      (opt.debug & DBG_IPC_VALUE)
 
 /* Forward declaration for an object defined in server.c.  */
 struct server_local_s;
@@ -100,13 +46,7 @@ struct server_control_s
 };
 
 
-

 /*-- g13.c --*/
-void g13_exit (int rc);
 void g13_init_default_ctrl (struct server_control_s *ctrl);
 
-/*-- server.c (commonly used, thus declared here) --*/
-gpg_error_t g13_status (ctrl_t ctrl, int no, ...) GPGRT_ATTR_SENTINEL(0);
-
-
 #endif /*G13_H*/
diff --git a/g13/runner.c b/g13/runner.c
index 905a0d1..35c6843 100644
--- a/g13/runner.c
+++ b/g13/runner.c
@@ -470,7 +470,7 @@ runner_cancel (runner_t runner)
     {
       runner->canceled = 1;  /* Mark that we canceled this one already.  */
       /* FIXME: This does only work if the thread emits status lines.  We
-         need to change the trhead to wait on an event.  */
+         need to change the thread to wait on an event.  */
       runner->cancel_flag = 1;
       /* For now we use the brutal way and kill the process. */
       gnupg_kill_process (runner->pid);

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

Summary of changes:
 g13/Makefile.am             |  1 +
 g13/g13-common.c            | 86 +++++++++++++++++++++++++++++++++++++++++++++
 g13/{g13.h => g13-common.h} | 67 +++++++++++++----------------------
 g13/g13.c                   | 47 +++++--------------------
 g13/g13.h                   | 62 +-------------------------------
 g13/runner.c                |  2 +-
 6 files changed, 121 insertions(+), 144 deletions(-)
 create mode 100644 g13/g13-common.c
 copy g13/{g13.h => g13-common.h} (74%)


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




More information about the Gnupg-commits mailing list