summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--NEWS6
-rw-r--r--TODO7
-rw-r--r--agent/ChangeLog6
-rw-r--r--agent/gpg-agent.c181
-rw-r--r--agent/protect-tool.c14
-rw-r--r--common/ChangeLog3
-rw-r--r--common/mkdtemp.c3
-rw-r--r--common/sysutils.h8
-rw-r--r--common/util.h4
-rw-r--r--configure.ac16
-rw-r--r--doc/gpg-agent.texi29
-rw-r--r--doc/gpgsm.texi10
-rw-r--r--doc/scdaemon.texi9
-rw-r--r--sm/ChangeLog8
-rw-r--r--sm/call-agent.c72
-rw-r--r--sm/call-dirmngr.c2
-rw-r--r--sm/import.c1
18 files changed, 270 insertions, 114 deletions
diff --git a/ChangeLog b/ChangeLog
index 3db690f2d..1ca430c63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-20 Werner Koch <wk@g10code.com>
+
+ * configure.ac: Add PATHSEP_C and PATHSEP_S. For W32 let all
+ directories default to c:/gnupg. Require libassuan 0.6.9.
+
2004-12-18 Werner Koch <wk@g10code.com>
* configure.ac (AH_BOTTOM): Define EXEEXT_S.
diff --git a/NEWS b/NEWS
index 0d0a7058f..525fdbe72 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,12 @@
Noteworthy changes in version 1.9.14
-------------------------------------------------
+ * [gpg-agent] New option --use-standard-socket to allow the use of a
+ fixed socket. gpgsm falls back to this socket if GPG_AGENT_INFO
+ has not been set.
+
+ * Ported to MS Windows.
+
Noteworthy changes in version 1.9.13 (2004-12-03)
-------------------------------------------------
diff --git a/TODO b/TODO
index 138f9bade..c7eca304e 100644
--- a/TODO
+++ b/TODO
@@ -95,3 +95,10 @@ might want to have an agent context for each service request
This needs support in libksba/src/cert.c as well as in sm/*.c.
Need test certs as well. Same goes for CRL authorityKeyIdentifier.
+
+* Windows port
+** gpgsm's LISTKEYS does not yet work
+ Fix is to change everything to libestream
+** Signals are not support
+ This means we can't reread a configuration
+
diff --git a/agent/ChangeLog b/agent/ChangeLog
index f2b82466c..507a90c9d 100644
--- a/agent/ChangeLog
+++ b/agent/ChangeLog
@@ -1,5 +1,11 @@
2004-12-20 Werner Koch <wk@g10code.com>
+ * gpg-agent.c (main) [W32]: Now that Mutexes work we can remove
+ the pth_init kludge.
+ (main): Add new options --[no-]use-standard-socket.
+ (check_for_running_agent): Check whether it is running on the
+ standard socket.
+
* call-scd.c (init_membuf, put_membuf, get_membuf): Removed. We
now use the identical implementation from ../common/membuf.c.
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index 65d5fd5a6..911afb881 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -84,13 +84,14 @@ enum cmd_and_opt_values
oDisablePth,
oDefCacheTTL,
oMaxCacheTTL,
+ oUseStandardSocket,
+ oNoUseStandardSocket,
oIgnoreCacheForSigning,
oAllowMarkTrusted,
oKeepTTY,
- oKeepDISPLAY,
-
-aTest };
+ oKeepDISPLAY
+};
@@ -115,6 +116,9 @@ static ARGPARSE_OPTS opts[] = {
{ oNoGrab, "no-grab" ,0, N_("do not grab keyboard and mouse")},
{ oLogFile, "log-file" ,2, N_("use a log file for the server")},
{ oDisablePth, "disable-pth", 0, N_("do not allow multiple connections")},
+ { oUseStandardSocket, "use-standard-socket", 0,
+ N_("use a standard location for the socket")},
+ { oNoUseStandardSocket, "no-use-standard-socket", 0, "@"},
{ oPinentryProgram, "pinentry-program", 2 ,
N_("|PGM|use PGM as the PIN-Entry program") },
@@ -154,7 +158,7 @@ static int shutdown_pending;
static int maybe_setuid = 1;
/* Name of the communication socket */
-static char socket_name[128];
+static char *socket_name;
/* Default values for options passed to the pinentry. */
static char *default_display;
@@ -177,12 +181,11 @@ static char *current_logfile;
static void create_directories (void);
#ifdef USE_GNU_PTH
static void handle_connections (int listen_fd);
-
/* Pth wrapper function definitions. */
GCRY_THREAD_OPTION_PTH_IMPL;
-
#endif /*USE_GNU_PTH*/
-static void check_for_running_agent (void);
+
+static int check_for_running_agent (int);
@@ -293,7 +296,7 @@ set_debug (void)
static void
cleanup (void)
{
- if (*socket_name)
+ if (socket_name && *socket_name)
{
char *p;
@@ -419,6 +422,7 @@ main (int argc, char **argv )
int debug_wait = 0;
int disable_pth = 0;
int gpgconf_list = 0;
+ int standard_socket = 0;
gpg_error_t err;
@@ -437,17 +441,12 @@ main (int argc, char **argv )
/* Libgcrypt requires us to register the threading model first.
Note that this will also do the pth_init. */
#ifdef USE_GNU_PTH
-#ifdef HAVE_W32_SYSTEM
- /* For W32 we need pth. */
- pth_init ();
-#else
err = gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pth);
if (err)
{
log_fatal ("can't register GNU Pth with Libgcrypt: %s\n",
gpg_strerror (err));
}
-#endif
#endif /*USE_GNU_PTH*/
@@ -468,18 +467,28 @@ main (int argc, char **argv )
may_coredump = disable_core_dumps ();
+ /* Set default options. */
parse_rereadable_options (NULL, 0); /* Reset them to default values. */
-
+#ifdef HAVE_W32_SYSTEM
+ standard_socket = 1; /* Under Windows we always use a standard
+ socket. */
+#endif
+
shell = getenv ("SHELL");
if (shell && strlen (shell) >= 3 && !strcmp (shell+strlen (shell)-3, "csh") )
csh_style = 1;
-
+
+
opt.homedir = getenv("GNUPGHOME");
+#ifdef HAVE_W32_SYSTEM
+ if (!opt.homedir || !*opt.homedir)
+ opt.homedir = read_w32_registry_string (NULL,
+ "Software\\GNU\\GnuPG", "HomeDir");
+#endif /*HAVE_W32_SYSTEM*/
if (!opt.homedir || !*opt.homedir)
opt.homedir = GNUPG_DEFAULT_HOMEDIR;
-
- /* check whether we have a config file on the commandline */
+ /* Check whether we have a config file on the commandline */
orig_argc = argc;
orig_argv = argv;
pargs.argc = &argc;
@@ -509,7 +518,6 @@ main (int argc, char **argv )
Now we are now working under our real uid
*/
-
if (default_config)
configname = make_filename (opt.homedir, "gpg-agent.conf", NULL );
@@ -584,6 +592,9 @@ main (int argc, char **argv )
case oLCmessages: default_lc_messages = xstrdup (pargs.r.ret_str);
break;
+ case oUseStandardSocket: standard_socket = 1; break;
+ case oNoUseStandardSocket: standard_socket = 0; break;
+
case oKeepTTY: opt.keep_tty = 1; break;
case oKeepDISPLAY: opt.keep_display = 1; break;
@@ -695,7 +706,7 @@ main (int argc, char **argv )
if (!pipe_server && !is_daemon)
{
log_set_prefix (NULL, JNLIB_LOG_WITH_PREFIX);
- check_for_running_agent ();
+ check_for_running_agent (0);
agent_exit (0);
}
@@ -736,6 +747,7 @@ main (int argc, char **argv )
else
{ /* Regular server mode */
int fd;
+ int rc;
pid_t pid;
int len;
struct sockaddr_un serv_addr;
@@ -750,28 +762,28 @@ main (int argc, char **argv )
unsetenv ("DISPLAY");
#endif
- *socket_name = 0;
- snprintf (socket_name, DIM(socket_name)-1,
- "/tmp/gpg-XXXXXX/S.gpg-agent");
- socket_name[DIM(socket_name)-1] = 0;
- p = strrchr (socket_name, '/');
- if (!p)
- BUG ();
- *p = 0;;
-
-#ifndef HAVE_W32_SYSTEM
- if (!mkdtemp(socket_name))
+ /* Create the socket name . */
+ if (standard_socket)
+ socket_name = make_filename (opt.homedir, "S.gpg-agent", NULL);
+ else
{
- log_error ("can't create directory `%s': %s\n",
- socket_name, strerror(errno) );
- exit (1);
+ socket_name = xstrdup ("/tmp/gpg-XXXXXX/S.gpg-agent");
+ p = strrchr (socket_name, '/');
+ if (!p)
+ BUG ();
+ *p = 0;;
+ if (!mkdtemp(socket_name))
+ {
+ log_error (_("can't create directory `%s': %s\n"),
+ socket_name, strerror(errno) );
+ exit (1);
+ }
+ *p = '/';
}
-#endif
- *p = '/';
- if (strchr (socket_name, ':') )
+ if (strchr (socket_name, PATHSEP_C) )
{
- log_error ("colons are not allowed in the socket name\n");
+ log_error ("`%s' are not allowed in the socket name\n", PATHSEP_S);
exit (1);
}
if (strlen (socket_name)+1 >= sizeof serv_addr.sun_path )
@@ -797,13 +809,22 @@ main (int argc, char **argv )
len = (offsetof (struct sockaddr_un, sun_path)
+ strlen(serv_addr.sun_path) + 1);
- if (
#ifdef HAVE_W32_SYSTEM
- _w32_sock_bind
+ rc = _w32_sock_bind (fd, (struct sockaddr*)&serv_addr, len);
+ if (rc == -1 && standard_socket)
+ {
+ remove (socket_name);
+ rc = bind (fd, (struct sockaddr*)&serv_addr, len);
+ }
#else
- bind
+ rc = bind (fd, (struct sockaddr*)&serv_addr, len);
+ if (rc == -1 && standard_socket && errno == EADDRINUSE)
+ {
+ remove (socket_name);
+ rc = bind (fd, (struct sockaddr*)&serv_addr, len);
+ }
#endif
- (fd, (struct sockaddr*)&serv_addr, len) == -1)
+ if (rc == -1)
{
log_error ("error binding socket to `%s': %s\n",
serv_addr.sun_path, strerror (errno) );
@@ -823,7 +844,10 @@ main (int argc, char **argv )
fflush (NULL);
-#ifndef HAVE_W32_SYSTEM
+#ifdef HAVE_W32_SYSTEM
+ pid = getpid ();
+ printf ("set GPG_AGENT_INFO=%s;%lu;1\n", socket_name, (ulong)pid);
+#else /*!HAVE_W32_SYSTEM*/
pid = fork ();
if (pid == (pid_t)-1)
{
@@ -1286,53 +1310,72 @@ handle_connections (int listen_fd)
/* Figure out whether an agent is available and running. Prints an
- error if not. */
-static void
-check_for_running_agent ()
+ error if not. Usually started with MODE 0. */
+static int
+check_for_running_agent (int mode)
{
int rc;
char *infostr, *p;
assuan_context_t ctx;
int prot, pid;
- infostr = getenv ("GPG_AGENT_INFO");
- if (!infostr || !*infostr)
+ if (!mode)
{
- log_error (_("no gpg-agent running in this session\n"));
- return;
- }
+ infostr = getenv ("GPG_AGENT_INFO");
+ if (!infostr || !*infostr)
+ {
+ if (!check_for_running_agent (1))
+ return 0; /* Okay, its running on the standard socket. */
+ log_error (_("no gpg-agent running in this session\n"));
+ return -1;
+ }
- infostr = xstrdup (infostr);
- if ( !(p = strchr (infostr, ':')) || p == infostr)
- {
- log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
- xfree (infostr);
- return;
- }
+ infostr = xstrdup (infostr);
+ if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
+ {
+ xfree (infostr);
+ if (!check_for_running_agent (1))
+ return 0; /* Okay, its running on the standard socket. */
+ log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
+ return -1;
+ }
- *p++ = 0;
- pid = atoi (p);
- while (*p && *p != ':')
- p++;
- prot = *p? atoi (p+1) : 0;
- if (prot != 1)
+ *p++ = 0;
+ pid = atoi (p);
+ while (*p && *p != PATHSEP_C)
+ p++;
+ prot = *p? atoi (p+1) : 0;
+ if (prot != 1)
+ {
+ xfree (infostr);
+ log_error (_("gpg-agent protocol version %d is not supported\n"),
+ prot);
+ if (!check_for_running_agent (1))
+ return 0; /* Okay, its running on the standard socket. */
+ return -1;
+ }
+ }
+ else /* MODE != 0 */
{
- log_error (_("gpg-agent protocol version %d is not supported\n"),
- prot);
- xfree (infostr);
- return;
+ infostr = make_filename (opt.homedir, "S.gpg-agent", NULL);
}
+
rc = assuan_socket_connect (&ctx, infostr, pid);
xfree (infostr);
if (rc)
{
- log_error ("can't connect to the agent: %s\n", assuan_strerror (rc));
- return;
+ if (!mode && !check_for_running_agent (1))
+ return 0; /* Okay, its running on the standard socket. */
+
+ if (!mode)
+ log_error ("can't connect to the agent: %s\n", assuan_strerror (rc));
+ return -1;
}
if (!opt.quiet)
log_info ("gpg-agent running and available\n");
assuan_disconnect (ctx);
+ return 0;
}
diff --git a/agent/protect-tool.c b/agent/protect-tool.c
index ef8a50916..43dd67eea 100644
--- a/agent/protect-tool.c
+++ b/agent/protect-tool.c
@@ -44,6 +44,8 @@
#include "minip12.h"
#include "simple-pwquery.h"
#include "i18n.h"
+#include "sysutils.h"
+
enum cmd_and_opt_values
{ aNull = 0,
@@ -1065,12 +1067,12 @@ main (int argc, char **argv )
gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
-#ifdef HAVE_W32_SYSTEM
- opt_homedir = read_w32_registry_string ( NULL,
- "Software\\GNU\\GnuPG", "HomeDir" );
-#else /*!HAVE_W32_SYSTEM*/
opt_homedir = getenv ("GNUPGHOME");
-#endif /*!HAVE_W32_SYSTEM*/
+#ifdef HAVE_W32_SYSTEM
+ if (!opt_homedir || !*opt_homedir)
+ opt_homedir = read_w32_registry_string (NULL,
+ "Software\\GNU\\GnuPG", "HomeDir");
+#endif /*HAVE_W32_SYSTEM*/
if (!opt_homedir || !*opt_homedir)
opt_homedir = GNUPG_DEFAULT_HOMEDIR;
@@ -1162,7 +1164,9 @@ get_passphrase (int promptno)
char *pw;
int err;
const char *desc;
+#ifdef HAVE_LANGINFO_CODESET
char *orig_codeset = NULL;
+#endif
int error_msgno;
diff --git a/common/ChangeLog b/common/ChangeLog
index eeba09341..11bf8029a 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,5 +1,8 @@
2004-12-20 Werner Koch <wk@g10code.com>
+ * sysutils.h [W32]: Define sleep.
+ * util.h: Add prototype for mkdtemp.
+
* membuf.c (put_membuf): Wipe out buffer after a failed realloc.
2004-12-19 Werner Koch <wk@g10code.com>
diff --git a/common/mkdtemp.c b/common/mkdtemp.c
index abe731e0a..a85b89eb4 100644
--- a/common/mkdtemp.c
+++ b/common/mkdtemp.c
@@ -35,7 +35,8 @@
# define mkdir(a,b) mkdir(a)
#endif
-char *mkdtemp(char *template)
+char *
+mkdtemp (char *template)
{
int attempts,idx,count=0;
unsigned char *ch;
diff --git a/common/sysutils.h b/common/sysutils.h
index 9df292031..08198f685 100644
--- a/common/sysutils.h
+++ b/common/sysutils.h
@@ -28,11 +28,19 @@ const unsigned char *get_session_marker (size_t *rlen);
int check_permissions (const char *path,int extension,int checkonly);
#ifdef HAVE_W32_SYSTEM
+/* Windows declares sleep as obsolete, but provides a definition for
+ _sleep but non for the still existing sleep. */
+#define sleep(a) _sleep ((a))
+
/*-- w32reg.c --*/
char *read_w32_registry_string( const char *root,
const char *dir, const char *name );
int write_w32_registry_string(const char *root, const char *dir,
const char *name, const char *value);
+
#endif /*HAVE_W32_SYSTEM*/
+
+
+
#endif /*GNUPG_COMMON_SYSUTILS_H*/
diff --git a/common/util.h b/common/util.h
index 835be4e0e..1159da925 100644
--- a/common/util.h
+++ b/common/util.h
@@ -150,6 +150,10 @@ char *strsep (char **stringp, const char *delim);
#ifndef HAVE_TTYNAME
char *ttyname (int fd);
#endif
+#ifndef HAVE_MKDTEMP
+char *mkdtemp (char *template);
+#endif
+
/*-- some macros to replace ctype ones and avoid locale problems --*/
#define spacep(p) (*(p) == ' ' || *(p) == '\t')
diff --git a/configure.ac b/configure.ac
index 463358f28..7eb3a6b71 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ NEED_GPG_ERROR_VERSION=0.7
NEED_LIBGCRYPT_API=1
NEED_LIBGCRYPT_VERSION=1.1.94
-NEED_LIBASSUAN_VERSION=0.6.6
+NEED_LIBASSUAN_VERSION=0.6.9
NEED_KSBA_VERSION=0.9.7
@@ -252,15 +252,19 @@ AH_BOTTOM([
than one character because the code assumes strlen()==1 */
#ifdef HAVE_DOSISH_SYSTEM
#define DIRSEP_C '\\'
-#define EXTSEP_C '.'
#define DIRSEP_S "\\"
+#define EXTSEP_C '.'
#define EXTSEP_S "."
+#define PATHSEP_C ';'
+#define PATHSEP_S ";"
#define EXEEXT_S ".exe"
#else
#define DIRSEP_C '/'
-#define EXTSEP_C '.'
#define DIRSEP_S "/"
+#define EXTSEP_C '.'
#define EXTSEP_S "."
+#define PATHSEP_C ':'
+#define PATHSEP_S ":"
#define EXEEXT_S ""
#endif
@@ -278,9 +282,9 @@ AH_BOTTOM([
comply with the GNU coding standards. */
#ifdef HAVE_DRIVE_LETTERS
#define GNUPG_BINDIR "c:\\gnupg"
-#define GNUPG_LIBEXECDIR "c:\\lib\\gnupg"
-#define GNUPG_LIBDIR "c:\\lib\\gnupg"
-#define GNUPG_DATADIR "c:\\lib\\gnupg"
+#define GNUPG_LIBEXECDIR "c:\\gnupg"
+#define GNUPG_LIBDIR "c:\\gnupg"
+#define GNUPG_DATADIR "c:\\gnupg"
#endif
/* Setup the hardwired names of modules. */
diff --git a/doc/gpg-agent.texi b/doc/gpg-agent.texi
index cccbef02a..28d99673d 100644
--- a/doc/gpg-agent.texi
+++ b/doc/gpg-agent.texi
@@ -43,7 +43,7 @@ fi
@end smallexample
@noindent
-You should aleways add the following lines to your @code{.bashrc} or
+You should always add the following lines to your @code{.bashrc} or
whatever initialization file is used for all shell invocations:
@smallexample
@@ -53,7 +53,8 @@ export GPG_TTY
@noindent
It is important that this environment variable always reflects the
-output of the @code{tty} command.
+output of the @code{tty} command. For W32 systems this option is not
+required.
Please make sure that a proper pinentry program has been installed
under the default filename (which is system dependant) or use the
@@ -129,6 +130,15 @@ per-user configuration file. The default configuration file is named
@file{gpg-agent.conf} and expected in the @file{.gnupg} directory directly
below the home directory of the user.
+@item --homedir @var{dir}
+@opindex homedir
+Set the name of the home directory to @var{dir}. If his option is not
+used, the home directory defaults to @file{~/.gnupg}. It is only
+recognized when given on the command line. It also overrides any home
+directory stated through the environment variable @var{GNUPGHOME} or
+(on W32 systems) by means on the Registry entry
+@var{HKCU\Software\GNU\GnuPG:HomeDir}.
+
@item -v
@item --verbose
@opindex v
@@ -279,6 +289,21 @@ Use program @var{filename} as the Smartcard daemon. The default is
installation dependend and can be shown with the @code{--version}
command.
+@item --use-standard-socket
+@itemx --no-use-standard-socket
+@opindex use-standard-socket
+@opindex no-use-standard-socket
+By enabling this option @command{gpg-agent} will listen on the socket
+named @file{S.gpg-agent}, located in the home directory, and not create
+a random socket below a temporary directory. Tools connecting to
+@command{gpg-agent} should first try to connect to the socket given in
+environment variable @var{GPG_AGENT_INFO} and the fall back to this
+socket. This option may not be used if the home directory is mounted as
+a remote file system.
+
+@noindent
+Note, that as of now, W32 systems default to this option.
+
@item --display @var{string}
@itemx --ttyname @var{string}
diff --git a/doc/gpgsm.texi b/doc/gpgsm.texi
index beedab7b7..4c167ebf5 100644
--- a/doc/gpgsm.texi
+++ b/doc/gpgsm.texi
@@ -236,6 +236,16 @@ per-user configuration file. The default configuration file is named
@file{gpgsm.conf} and expected in the @file{.gnupg} directory directly
below the home directory of the user.
+@item --homedir @var{dir}
+@opindex homedir
+Set the name of the home directory to @var{dir}. If his option is not
+used, the home directory defaults to @file{~/.gnupg}. It is only
+recognized when given on the command line. It also overrides any home
+directory stated through the environment variable @var{GNUPGHOME} or
+(on W32 systems) by means on the Registry entry
+@var{HKCU\Software\GNU\GnuPG:HomeDir}.
+
+
@item -v
@item --verbose
@opindex v
diff --git a/doc/scdaemon.texi b/doc/scdaemon.texi
index 872000175..5265ed21e 100644
--- a/doc/scdaemon.texi
+++ b/doc/scdaemon.texi
@@ -81,6 +81,15 @@ per-user configuration file. The default configuration file is named
@file{scdaemon.conf} and expected in the @file{.gnupg} directory directly
below the home directory of the user.
+@item --homedir @var{dir}
+@opindex homedir
+Set the name of the home directory to @var{dir}. If his option is not
+used, the home directory defaults to @file{~/.gnupg}. It is only
+recognized when given on the command line. It also overrides any home
+directory stated through the environment variable @var{GNUPGHOME} or
+(on W32 systems) by means on the Registry entry
+@var{HKCU\Software\GNU\GnuPG:HomeDir}.
+
@item -v
@item --verbose
@opindex v
diff --git a/sm/ChangeLog b/sm/ChangeLog
index 167ec8753..19e7b0e8d 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,3 +1,11 @@
+2004-12-20 Werner Koch <wk@g10code.com>
+
+ * call-agent.c (start_agent): Before starting a pipe server start
+ to connect to a server on the standard socket. Use PATHSEP
+ * call-dirmngr.c (start_dirmngr): Use PATHSEP.
+
+ * import.c: Include unistd.h for dup and close.
+
2004-12-18 Werner Koch <wk@g10code.com>
* gpgsm.h (map_assuan_err): Define in terms of
diff --git a/sm/call-agent.c b/sm/call-agent.c
index 0d15a5595..0647acbb8 100644
--- a/sm/call-agent.c
+++ b/sm/call-agent.c
@@ -81,41 +81,53 @@ start_agent (ctrl_t ctrl)
{
const char *pgmname;
const char *argv[3];
+ char *sockname;
int no_close_list[3];
int i;
- if (opt.verbose)
- log_info (_("no running gpg-agent - starting one\n"));
-
- gpgsm_status (ctrl, STATUS_PROGRESS, "starting_agent ? 0 0");
+ /* First check whether we can connect at the standard
+ socket. */
+ sockname = make_filename (opt.homedir, "S.gpg-agent", NULL);
+ rc = assuan_socket_connect (&ctx, sockname, 0);
+ xfree (sockname);
- if (fflush (NULL))
+ if (rc)
{
- gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
- log_error ("error flushing pending output: %s\n", strerror (errno));
- return tmperr;
+ /* With no success start a new server. */
+ if (opt.verbose)
+ log_info (_("no running gpg-agent - starting one\n"));
+
+ gpgsm_status (ctrl, STATUS_PROGRESS, "starting_agent ? 0 0");
+
+ if (fflush (NULL))
+ {
+ gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
+ log_error ("error flushing pending output: %s\n",
+ strerror (errno));
+ return tmperr;
+ }
+
+ if (!opt.agent_program || !*opt.agent_program)
+ opt.agent_program = GNUPG_DEFAULT_AGENT;
+ if ( !(pgmname = strrchr (opt.agent_program, '/')))
+ pgmname = opt.agent_program;
+ else
+ pgmname++;
+
+ argv[0] = pgmname;
+ argv[1] = "--server";
+ argv[2] = NULL;
+
+ i=0;
+ if (log_get_fd () != -1)
+ no_close_list[i++] = log_get_fd ();
+ no_close_list[i++] = fileno (stderr);
+ no_close_list[i] = -1;
+
+ /* Connect to the agent and perform initial handshaking. */
+ rc = assuan_pipe_connect (&ctx, opt.agent_program, (char**)argv,
+ no_close_list);
}
-
- if (!opt.agent_program || !*opt.agent_program)
- opt.agent_program = GNUPG_DEFAULT_AGENT;
- if ( !(pgmname = strrchr (opt.agent_program, '/')))
- pgmname = opt.agent_program;
- else
- pgmname++;
-
- argv[0] = pgmname;
- argv[1] = "--server";
- argv[2] = NULL;
-
- i=0;
- if (log_get_fd () != -1)
- no_close_list[i++] = log_get_fd ();
- no_close_list[i++] = fileno (stderr);
- no_close_list[i] = -1;
-
- /* Connect to the agent and perform initial handshaking. */
- rc = assuan_pipe_connect (&ctx, opt.agent_program, (char**)argv,
- no_close_list);
}
else
{
@@ -123,7 +135,7 @@ start_agent (ctrl_t ctrl)
int pid;
infostr = xstrdup (infostr);
- if ( !(p = strchr (infostr, ':')) || p == infostr)
+ if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
{
log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
xfree (infostr);
diff --git a/sm/call-dirmngr.c b/sm/call-dirmngr.c
index d00a53db5..9c4a5f22f 100644
--- a/sm/call-dirmngr.c
+++ b/sm/call-dirmngr.c
@@ -209,7 +209,7 @@ start_dirmngr (void)
infostr = xstrdup (infostr);
if (!try_default && *infostr)
{
- if ( !(p = strchr (infostr, ':')) || p == infostr)
+ if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
{
log_error (_("malformed DIRMNGR_INFO environment variable\n"));
xfree (infostr);
diff --git a/sm/import.c b/sm/import.c
index 457ef6423..6d00e91ea 100644
--- a/sm/import.c
+++ b/sm/import.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <time.h>
#include <assert.h>
+#include <unistd.h>
#include "gpgsm.h"
#include <gcrypt.h>