1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

* configure.ac: Add PATHSEP_C and PATHSEP_S. For W32 let all

directories default to c:/gnupg.  Require libassuan 0.6.9.

* 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.

* sysutils.h [W32]: Define sleep.
* util.h: Add prototype for mkdtemp.

* 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.
This commit is contained in:
Werner Koch 2004-12-20 16:17:25 +00:00
parent f105ceb39c
commit 581f5ddb17
18 changed files with 272 additions and 116 deletions

View File

@ -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.

6
NEWS
View File

@ -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)
-------------------------------------------------

7
TODO
View File

@ -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

View File

@ -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.

View File

@ -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, 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 != 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 */
{
infostr = make_filename (opt.homedir, "S.gpg-agent", NULL);
}
infostr = xstrdup (infostr);
if ( !(p = strchr (infostr, ':')) || p == infostr)
{
log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
xfree (infostr);
return;
}
*p++ = 0;
pid = atoi (p);
while (*p && *p != ':')
p++;
prot = *p? atoi (p+1) : 0;
if (prot != 1)
{
log_error (_("gpg-agent protocol version %d is not supported\n"),
prot);
xfree (infostr);
return;
}
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;
}

View File

@ -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;

View File

@ -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>

View File

@ -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;

View File

@ -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*/

View File

@ -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')

View File

@ -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. */

View File

@ -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}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -25,6 +25,7 @@
#include <errno.h>
#include <time.h>
#include <assert.h>
#include <unistd.h>
#include "gpgsm.h"
#include <gcrypt.h>