[svn] GpgEX - r32 - trunk/src
svn author marcus
cvs at cvs.gnupg.org
Mon Oct 15 21:41:44 CEST 2007
Author: marcus
Date: 2007-10-15 21:41:35 +0200 (Mon, 15 Oct 2007)
New Revision: 32
Added:
trunk/src/debug.h
trunk/src/exechelp.c
trunk/src/exechelp.h
Modified:
trunk/src/ChangeLog
trunk/src/Makefile.am
trunk/src/client.cc
trunk/src/main.cc
trunk/src/main.h
trunk/src/registry.c
trunk/src/registry.h
Log:
2007-10-15 Marcus Brinkmann <marcus at g10code.de>
(client_t::call_assuan): Call uiserver_connect.
* registry.c: Include assert.h. Check return value of malloc.
* exechelp.h, exechelp.c: New files.
* Makefile.am (gpgex_SOURCES): Add exechelp.h and exechelp.c.
* main.h (REGKEY): Move to ...
* registry.h (REGKEY): ... here.
* main.cc (_gpgme_debug): Put into extern C.
* main.h: Move debug stuff into ...
* debug.h: ... this new file.
* client.cc (default_uiserver_name, uiserver_connect): New functions.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/ChangeLog 2007-10-15 19:41:35 UTC (rev 32)
@@ -1,3 +1,16 @@
+2007-10-15 Marcus Brinkmann <marcus at g10code.de>
+
+ (client_t::call_assuan): Call uiserver_connect.
+ * registry.c: Include assert.h. Check return value of malloc.
+ * exechelp.h, exechelp.c: New files.
+ * Makefile.am (gpgex_SOURCES): Add exechelp.h and exechelp.c.
+ * main.h (REGKEY): Move to ...
+ * registry.h (REGKEY): ... here.
+ * main.cc (_gpgme_debug): Put into extern C.
+ * main.h: Move debug stuff into ...
+ * debug.h: ... this new file.
+ * client.cc (default_uiserver_name, uiserver_connect): New functions.
+
2007-10-05 Marcus Brinkmann <marcus at g10code.de>
* main.cc (DllMain): Call WSACleanup.
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/Makefile.am 2007-10-15 19:41:35 UTC (rev 32)
@@ -28,13 +28,14 @@
gpgex.def \
icons.rc \
registry.h registry.c \
+ exechelp.h exechelp.c \
w32-gettext.c w32-gettext.h \
gpgex-class.h gpgex-class.cc \
gpgex-factory.h gpgex-factory.cc \
bitmaps.h bitmaps.cc \
gpgex.h gpgex.cc \
client.h client.cc \
- main.h main.cc \
+ main.h debug.h main.cc \
$(ICONS)
libgpg-error.a:
Modified: trunk/src/client.cc
===================================================================
--- trunk/src/client.cc 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/client.cc 2007-10-15 19:41:35 UTC (rev 32)
@@ -33,13 +33,54 @@
#include <assuan.h>
+#include "main.h"
#include "registry.h"
-#include "main.h"
+#include "exechelp.h"
#include "client.h"
static const char *
+default_uiserver_name (void)
+{
+ static string name;
+
+ if (name.size () == 0)
+ {
+ char *dir = NULL;
+
+ dir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", REGKEY,
+ "Install Directory");
+ if (dir)
+ {
+ char *uiserver = NULL;
+ int uiserver_malloced = 1;
+
+ uiserver = read_w32_registry_string ("HKEY_LOCAL_MACHINE", REGKEY,
+ "UI Server");
+ if (!uiserver)
+ {
+ uiserver = "bin\\kleopatra.exe";
+ uiserver_malloced = 0;
+ }
+
+ /* FIXME: Very dirty work-around to make kleopatra find its
+ DLLs. */
+ if (strcmp (uiserver, "bin\\kleopatra.exe"))
+ chdir (dir);
+
+ try { name = ((string) dir) + "\\" + uiserver; } catch (...) {}
+
+ if (uiserver_malloced)
+ free (uiserver);
+ free ((void *) dir);
+ }
+ }
+
+ return name.c_str ();
+}
+
+static const char *
default_socket_name (void)
{
static string name;
@@ -48,7 +89,6 @@
{
char *dir = NULL;
- /* FIXME: Wrong directory. */
dir = default_homedir ();
if (dir)
{
@@ -126,27 +166,63 @@
}
+static int
+uiserver_connect (assuan_context_t *ctx)
+{
+ int rc;
+ const char *socket_name = NULL;
+
+ TRACE_BEG (DEBUG_ASSUAN, "client_t::uiserver_connect", ctx);
+
+ socket_name = default_socket_name ();
+ if (! socket_name || ! *socket_name)
+ {
+ (void) TRACE_LOG ("invalid socket name");
+ return TRACE_GPGERR (gpg_error (GPG_ERR_INV_ARG));
+ }
+
+ (void) TRACE_LOG1 ("socket name: %s", socket_name);
+ rc = assuan_socket_connect (ctx, socket_name, -1);
+ if (rc)
+ {
+ const char *argv[3];
+ int count;
+
+ (void) TRACE_LOG ("UI server not running, starting it");
+
+ argv[0] = "--uiserver-socket";
+ argv[1] = socket_name;
+ argv[2] = NULL;
+
+ rc = gpgex_spawn_detached (default_uiserver_name (), argv);
+ if (rc)
+ return TRACE_GPGERR (rc);
+
+ /* Give it a bit of time to start up and try a couple of
+ times. */
+ for (count = 0; count < 10; count++)
+ {
+ Sleep (1000);
+ rc = assuan_socket_connect (ctx, socket_name, -1);
+ if (!rc)
+ break;
+ }
+ }
+ return TRACE_GPGERR (rc);
+}
+
+
bool
client_t::call_assuan (const char *cmd, vector<string> &filenames)
{
int rc = 0;
assuan_context_t ctx = NULL;
- const char *socket_name;
string msg;
TRACE_BEG2 (DEBUG_ASSUAN, "client_t::call_assuan", this,
"%s on %u files", cmd, filenames.size ());
- socket_name = default_socket_name ();
- if (! socket_name || ! *socket_name)
- {
- (void) TRACE_LOG ("invalid socket name");
- rc = gpg_error (GPG_ERR_INV_ARG);
- goto leave;
- }
-
- (void) TRACE_LOG1 ("socket name: %s", socket_name);
- rc = assuan_socket_connect (&ctx, socket_name, -1);
+ rc = uiserver_connect (&ctx);
if (rc)
goto leave;
Added: trunk/src/debug.h
===================================================================
--- trunk/src/debug.h 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/debug.h 2007-10-15 19:41:35 UTC (rev 32)
@@ -0,0 +1,201 @@
+/* debug.h - trace prototypes
+ Copyright (C) 2007 g10 Code GmbH
+
+ This file is part of GpgEX.
+
+ GpgEX is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ GpgEX 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#ifndef DEBUG_H
+#define DEBUG_H 1
+
+#include <gpg-error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+}
+#endif
+#endif
+
+
+#define DEBUG_INIT 1
+#define DEBUG_CONTEXT_MENU 2
+#define DEBUG_ASSUAN 4
+
+#define STRINGIFY(v) #v
+
+/* Log the formatted string FORMAT in categories FLAGS. */
+void _gpgex_debug (unsigned int flags, const char *format, ...);
+
+#define _TRACE(lvl, name, tag) \
+ int _gpgex_trace_level = lvl; \
+ const char *const _gpgex_trace_func = name; \
+ const char *const _gpgex_trace_tagname = STRINGIFY (tag); \
+ void *_gpgex_trace_tag = (void *) tag
+
+#define TRACE_BEG(lvl, name, tag) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag)
+#define TRACE_BEG0(lvl, name, tag, fmt) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag)
+#define TRACE_BEG1(lvl, name, tag, fmt, arg1) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1)
+#define TRACE_BEG2(lvl, name, tag, fmt, arg1, arg2) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2)
+#define TRACE_BEG3(lvl, name, tag, fmt, arg1, arg2, arg3) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3)
+#define TRACE_BEG4(lvl, name, tag, fmt, arg1, arg2, arg3, arg4) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4)
+#define TRACE_BEG5(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5)
+#define TRACE_BEG12(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
+ arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6, \
+ arg7, arg8, arg9, arg10, arg11, arg12)
+#define TRACE_BEG13(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
+ arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, \
+ arg13) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6, \
+ arg7, arg8, arg9, arg10, arg11, arg12, arg13)
+#define TRACE_BEG22(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
+ arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, \
+ arg13, arg14, arg15, arg16, arg17, arg18, arg19, \
+ arg20, arg21, arg22) \
+ _TRACE (lvl, name, tag); \
+ _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6, \
+ arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, \
+ arg15, arg16, arg17, arg18, arg19, arg20, arg21, \
+ arg22)
+
+#define TRACE(lvl, name, tag) \
+ (_gpgex_debug (lvl, "%s (%s=0x%x): call\n", \
+ name, STRINGIFY (tag), (void *) tag), 0)
+#define TRACE0(lvl, name, tag, fmt) \
+ (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
+ name, STRINGIFY (tag), (void *) tag), 0)
+#define TRACE1(lvl, name, tag, fmt, arg1) \
+ (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
+ name, STRINGIFY (tag), (void *) tag, arg1), 0)
+#define TRACE2(lvl, name, tag, fmt, arg1, arg2) \
+ (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
+ name, STRINGIFY (tag), (void *) tag, arg1, arg2), 0)
+#define TRACE3(lvl, name, tag, fmt, arg1, arg2, arg3) \
+ (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
+ name, STRINGIFY (tag), (void *) tag, arg1, arg2, \
+ arg3), 0)
+#define TRACE6(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
+ (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
+ name, STRINGIFY (tag), (void *) tag, arg1, arg2, arg3, \
+ arg4, arg5, arg6), 0)
+
+#define TRACE_GPGERR(err) \
+ err == 0 ? (TRACE_SUC ()) : \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): error: %s <%s>\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, gpg_strerror (err), \
+ gpg_strsource (err)), (err))
+
+#define TRACE_RES(err) \
+ err == S_OK ? (TRACE_SUC ()) : \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): %s: ec=%x\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, \
+ SUCCEEDED (err) ? "leave" : "error", \
+ err), (err))
+
+#define TRACE_SUC() \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag), 0)
+#define TRACE_SUC0(fmt) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag), 0)
+#define TRACE_SUC1(fmt, arg1) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1), 0)
+#define TRACE_SUC2(fmt, arg1, arg2) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2), 0)
+#define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5), 0)
+
+#define TRACE_LOG(fmt) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag), 0)
+#define TRACE_LOG1(fmt, arg1) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1), 0)
+#define TRACE_LOG2(fmt, arg1, arg2) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2), 0)
+#define TRACE_LOG3(fmt, arg1, arg2, arg3) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3), 0)
+#define TRACE_LOG4(fmt, arg1, arg2, arg3, arg4) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4), 0)
+#define TRACE_LOG6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
+ (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
+ _gpgex_trace_func, _gpgex_trace_tagname, \
+ _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, \
+ arg6), 0)
+
+#ifdef __cplusplus
+#if 0
+{
+#endif
+}
+#endif
+
+#endif
Added: trunk/src/exechelp.c
===================================================================
--- trunk/src/exechelp.c 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/exechelp.c 2007-10-15 19:41:35 UTC (rev 32)
@@ -0,0 +1,203 @@
+/* exechelp.c - fork and exec helpers
+ * Copyright (C) 2004, 2007 g10 Code GmbH
+ *
+ * This file is part of GpgEX.
+ *
+ * GpgEX 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgEX 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <windows.h>
+
+#include <gpg-error.h>
+
+#include "debug.h"
+#include "exechelp.h"
+
+/* Define to 1 do enable debugging. */
+#define DEBUG_W32_SPAWN 0
+
+
+/* Replacement function. */
+
+#define stpcpy my_sptcpy
+
+static char *
+stpcpy (char *d, const char *s)
+{
+ do
+ *d++ = *s;
+ while (*s++ != '\0');
+
+ return d - 1;
+}
+
+
+/* Helper function to build_w32_commandline. */
+static char *
+build_w32_commandline_copy (char *buffer, const char *string)
+{
+ char *p = buffer;
+ const char *s;
+
+ if (!*string) /* Empty string. */
+ p = stpcpy (p, "\"\"");
+ else if (strpbrk (string, " \t\n\v\f\""))
+ {
+ /* Need to do some kind of quoting. */
+ p = stpcpy (p, "\"");
+ for (s=string; *s; s++)
+ {
+ *p++ = *s;
+ if (*s == '\"')
+ *p++ = *s;
+ }
+ *p++ = '\"';
+ *p = 0;
+ }
+ else
+ p = stpcpy (p, string);
+
+ return p;
+}
+
+/* Build a command line for use with W32's CreateProcess. On success
+ CMDLINE gets the address of a newly allocated string. */
+static gpg_error_t
+build_w32_commandline (const char *pgmname, const char * const *argv,
+ char **cmdline)
+{
+ int i, n;
+ const char *s;
+ char *buf, *p;
+
+ *cmdline = NULL;
+ n = 0;
+ s = pgmname;
+ n += strlen (s) + 1 + 2; /* (1 space, 2 quotes) */
+ for (; *s; s++)
+ if (*s == '\"')
+ n++; /* Need to double inner quotes. */
+ for (i=0; (s=argv[i]); i++)
+ {
+ n += strlen (s) + 1 + 2; /* (1 space, 2 quoting) */
+ for (; *s; s++)
+ if (*s == '\"')
+ n++; /* Need to double inner quotes. */
+ }
+ n++;
+
+ buf = p = malloc (n);
+ if (!buf)
+ return gpg_error_from_syserror ();
+
+ p = build_w32_commandline_copy (p, pgmname);
+ for (i = 0; argv[i]; i++)
+ {
+ *p++ = ' ';
+ p = build_w32_commandline_copy (p, argv[i]);
+ }
+
+ *cmdline = buf;
+ return 0;
+}
+
+
+/* Fork and exec the PGMNAME with /dev/null as stdin, stdout and
+ stderr. The arguments for the process are expected in the NULL
+ terminated array ARGV. The program name itself should not be
+ included there. Returns 0 on success or an error code. */
+gpg_error_t
+gpgex_spawn_detached (const char *pgmname, const char *const argv[])
+{
+ gpg_error_t err;
+ SECURITY_ATTRIBUTES sec_attr;
+ PROCESS_INFORMATION pi =
+ {
+ NULL, /* Returns process handle. */
+ 0, /* Returns primary thread handle. */
+ 0, /* Returns pid. */
+ 0 /* Returns tid. */
+ };
+ STARTUPINFO si;
+ int cr_flags;
+ char *cmdline;
+ int i;
+
+ TRACE_BEG1 (DEBUG_ASSUAN, "gpgex_spawn_detached", pgmname,
+ "pgmname=%s", pgmname);
+ i = 0;
+ while (argv[i])
+ {
+ TRACE_LOG2 ("argv[%2i] = %s", i, argv[i]);
+ i++;
+ }
+
+ /* Build the command line. */
+ err = build_w32_commandline (pgmname, argv, &cmdline);
+ if (err)
+ return err;
+
+ /* Prepare security attributes. */
+ memset (&sec_attr, 0, sizeof sec_attr);
+ sec_attr.nLength = sizeof sec_attr;
+ sec_attr.bInheritHandle = FALSE;
+
+ /* Start the process. Note that we can't run the PREEXEC function
+ because this would change our own environment. */
+ memset (&si, 0, sizeof si);
+ si.cb = sizeof (si);
+ si.dwFlags = STARTF_USESHOWWINDOW;
+ si.wShowWindow = DEBUG_W32_SPAWN ? SW_SHOW : SW_MINIMIZE;
+
+ cr_flags = (CREATE_DEFAULT_ERROR_MODE
+ | GetPriorityClass (GetCurrentProcess ())
+ | CREATE_NEW_PROCESS_GROUP
+ | DETACHED_PROCESS);
+
+ (void) TRACE_LOG2 ("CreateProcess, path=`%s' cmdline=`%s'\n",
+ pgmname, cmdline);
+ if (!CreateProcess (pgmname, /* pgmname; Program to start. */
+ cmdline, /* Command line arguments. */
+ &sec_attr, /* Process security attributes. */
+ &sec_attr, /* Thread security attributes. */
+ TRUE, /* Inherit handles. */
+ cr_flags, /* Creation flags. */
+ NULL, /* Environment. */
+ NULL, /* Use current drive/directory. */
+ &si, /* Startup information. */
+ &pi /* Returns process information. */
+ ))
+ {
+ (void) TRACE_LOG1 ("CreateProcess failed: %i\n", GetLastError ());
+ free (cmdline);
+ return gpg_error (GPG_ERR_GENERAL);
+ }
+ free (cmdline);
+
+ /* Process has been created suspended; resume it now. */
+ CloseHandle (pi.hThread);
+ CloseHandle (pi.hProcess);
+
+ return 0;
+}
Added: trunk/src/exechelp.h
===================================================================
--- trunk/src/exechelp.h 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/exechelp.h 2007-10-15 19:41:35 UTC (rev 32)
@@ -0,0 +1,46 @@
+/* exechelp.h - fork and exec helpers
+ * Copyright (C) 2004, 2007 g10 Code GmbH
+ *
+ * This file is part of GpgEX.
+ *
+ * GpgEX 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgEX 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef GPGEX_EXECHELP_H
+#define GPGEX_EXECHELP_H
+
+#include <gpg-error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+}
+#endif
+#endif
+
+/* Fork and exec the PGMNAME with /dev/null as stdin, stdout and
+ stderr. The arguments for the process are expected in the NULL
+ terminated array ARGV. The program name itself should not be
+ included there. Returns 0 on success or an error code. */
+gpg_error_t gpgex_spawn_detached (const char *pgmname,
+ const char *const argv[]);
+#ifdef __cplusplus
+#if 0
+{
+#endif
+}
+#endif
+
+#endif /* GPGEX_EXECHELP_H */
Modified: trunk/src/main.cc
===================================================================
--- trunk/src/main.cc 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/main.cc 2007-10-15 19:41:35 UTC (rev 32)
@@ -160,7 +160,15 @@
}
+#ifdef __cplusplus
+extern "C" {
+#if 0
+}
+#endif
+#endif
+
/* Log the formatted string FORMAT at debug level LEVEL or higher. */
+extern
void
_gpgex_debug (unsigned int flags, const char *format, ...)
{
@@ -184,6 +192,13 @@
errno = saved_errno;
}
+#ifdef __cplusplus
+#if 0
+{
+#endif
+}
+#endif
+
/* Entry point called by DLL loader. */
STDAPI
Modified: trunk/src/main.h
===================================================================
--- trunk/src/main.h 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/main.h 2007-10-15 19:41:35 UTC (rev 32)
@@ -23,18 +23,15 @@
#include <windows.h>
-#include <gpg-error.h>
+#include "debug.h"
+
#include "w32-gettext.h"
#define _(a) gettext (a)
#define N_(a) gettext_noop (a)
-/* Registry key for this software. */
-#define REGKEY "Software\\GNU\\GnuPG"
-
-
/* We use a class just for namespace cleanliness. */
class gpgex_server
{
@@ -67,169 +64,9 @@
};
-#define DEBUG_INIT 1
-#define DEBUG_CONTEXT_MENU 2
-#define DEBUG_ASSUAN 4
-
-#define STRINGIFY(v) #v
-
#define GUID_FMT "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}"
#define GUID_ARG(x) (x).Data1, (x).Data2, (x).Data3, (x).Data4[0], \
(x).Data4[1], (x).Data4[2], (x).Data4[3], (x).Data4[4], \
(x).Data4[5], (x).Data4[6], (x).Data4[7]
-/* Log the formatted string FORMAT in categories FLAGS. */
-void _gpgex_debug (unsigned int flags, const char *format, ...);
-
-#define _TRACE(lvl, name, tag) \
- int _gpgex_trace_level = lvl; \
- const char *const _gpgex_trace_func = name; \
- const char *const _gpgex_trace_tagname = STRINGIFY (tag); \
- void *_gpgex_trace_tag = (void *) tag
-
-#define TRACE_BEG(lvl, name, tag) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag)
-#define TRACE_BEG0(lvl, name, tag, fmt) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag)
-#define TRACE_BEG1(lvl, name, tag, fmt, arg1) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1)
-#define TRACE_BEG2(lvl, name, tag, fmt, arg1, arg2) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2)
-#define TRACE_BEG3(lvl, name, tag, fmt, arg1, arg2, arg3) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3)
-#define TRACE_BEG4(lvl, name, tag, fmt, arg1, arg2, arg3, arg4) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4)
-#define TRACE_BEG5(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5)
-#define TRACE_BEG12(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
- arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6, \
- arg7, arg8, arg9, arg10, arg11, arg12)
-#define TRACE_BEG13(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
- arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, \
- arg13) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6, \
- arg7, arg8, arg9, arg10, arg11, arg12, arg13)
-#define TRACE_BEG22(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
- arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, \
- arg13, arg14, arg15, arg16, arg17, arg18, arg19, \
- arg20, arg21, arg22) \
- _TRACE (lvl, name, tag); \
- _gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6, \
- arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, \
- arg15, arg16, arg17, arg18, arg19, arg20, arg21, \
- arg22)
-
-#define TRACE(lvl, name, tag) \
- (_gpgex_debug (lvl, "%s (%s=0x%x): call\n", \
- name, STRINGIFY (tag), (void *) tag), 0)
-#define TRACE0(lvl, name, tag, fmt) \
- (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) tag), 0)
-#define TRACE1(lvl, name, tag, fmt, arg1) \
- (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) tag, arg1), 0)
-#define TRACE2(lvl, name, tag, fmt, arg1, arg2) \
- (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) tag, arg1, arg2), 0)
-#define TRACE3(lvl, name, tag, fmt, arg1, arg2, arg3) \
- (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) tag, arg1, arg2, \
- arg3), 0)
-#define TRACE6(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
- (_gpgex_debug (lvl, "%s (%s=0x%x): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) tag, arg1, arg2, arg3, \
- arg4, arg5, arg6), 0)
-
-#define TRACE_GPGERR(err) \
- err == 0 ? (TRACE_SUC ()) : \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): error: %s <%s>\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, gpg_strerror (err), \
- gpg_strsource (err)), (err))
-
-#define TRACE_RES(err) \
- err == S_OK ? (TRACE_SUC ()) : \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): %s: ec=%x\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, \
- SUCCEEDED (err) ? "leave" : "error", \
- err), (err))
-
-#define TRACE_SUC() \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag), 0)
-#define TRACE_SUC0(fmt) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag), 0)
-#define TRACE_SUC1(fmt, arg1) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1), 0)
-#define TRACE_SUC2(fmt, arg1, arg2) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2), 0)
-#define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): leave: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5), 0)
-
-#define TRACE_LOG(fmt) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag), 0)
-#define TRACE_LOG1(fmt, arg1) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1), 0)
-#define TRACE_LOG2(fmt, arg1, arg2) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2), 0)
-#define TRACE_LOG3(fmt, arg1, arg2, arg3) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3), 0)
-#define TRACE_LOG4(fmt, arg1, arg2, arg3, arg4) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4), 0)
-#define TRACE_LOG6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
- (_gpgex_debug (_gpgex_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
- _gpgex_trace_func, _gpgex_trace_tagname, \
- _gpgex_trace_tag, arg1, arg2, arg3, arg4, arg5, \
- arg6), 0)
-
#endif
Modified: trunk/src/registry.c
===================================================================
--- trunk/src/registry.c 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/registry.c 2007-10-15 19:41:35 UTC (rev 32)
@@ -23,6 +23,7 @@
#endif
#include <unistd.h>
+#include <assert.h>
#include <windows.h>
#include <shlobj.h>
@@ -215,6 +216,9 @@
{
char *tmp = malloc (strlen (path) + 6 + 1);
+ /* FIXME. */
+ assert (tmp);
+
strcpy (tmp, path);
strcat (tmp, "\\gnupg");
Modified: trunk/src/registry.h
===================================================================
--- trunk/src/registry.h 2007-10-08 16:48:52 UTC (rev 31)
+++ trunk/src/registry.h 2007-10-15 19:41:35 UTC (rev 32)
@@ -43,6 +43,9 @@
/* Retrieve the default home directory. */
char *default_homedir (void);
+/* Registry key for this software. */
+#define REGKEY "Software\\GNU\\GnuPG"
+
#ifdef __cplusplus
#if 0
{
More information about the Gnupg-commits
mailing list