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

More changes for CE. gpgsm does now build and run a keylisting.

This commit is contained in:
Werner Koch 2010-03-24 12:15:30 +00:00
parent d1591a97f4
commit f080b353ed
28 changed files with 595 additions and 329 deletions

View File

@ -1,3 +1,14 @@
2010-03-24 Werner Koch <wk@g10code.com>
* configure.ac (AH_BOTTOM): Use /gnupg as the default homedir on
dosish systems which don't support drive letters (e.g. W32CE).
* am/cmacros.am (extra_sys_libs): New.
2010-03-23 Werner Koch <wk@g10code.com>
* configure.ac (W32SOCKLIBS): Change value for W32CE.
2010-03-12 Werner Koch <wk@g10code.com> 2010-03-12 Werner Koch <wk@g10code.com>
* configure.ac (AC_INIT): Prepare for using git. * configure.ac (AC_INIT): Prepare for using git.

View File

@ -48,6 +48,15 @@ if GNUPG_PROTECT_TOOL_PGM
AM_CPPFLAGS += -DGNUPG_DEFAULT_PROTECT_TOOL="\"@GNUPG_PROTECT_TOOL_PGM@\"" AM_CPPFLAGS += -DGNUPG_DEFAULT_PROTECT_TOOL="\"@GNUPG_PROTECT_TOOL_PGM@\""
endif endif
# Under Windows we use LockFileEx. WindowsCE provides this only on
# the WindowsMobile 6 platform and thus we need to use the coredll6
# import library.
if HAVE_W32CE_SYSTEM
extra_sys_libs = -lcoredll6
else
extra_sys_libs =
endif
# Convenience macros # Convenience macros
libcommon = ../common/libcommon.a libcommon = ../common/libcommon.a

View File

@ -1,3 +1,34 @@
2010-03-24 Werner Koch <wk@g10code.com>
* stringhelp.c (change_slashes, compare_filenames): Replace
HAVE_DRIVE_LETTERS by HAVE_DOSISH_SYSTEM.
(make_basename, make_dirname): Detect backslashes and drive
letters separately.
* dotlock.c (make_dotlock, create_dotlock, release_dotlock): Use
LockFileEx and UnlockFileEx to support W32CE.
* ttyio.c (USE_W32_CONSOLE): Replace all _WIN32 by this.
(init_ttyfp) [W32CE]: Use stderr.
* iobuf.c (FD_FOR_STDIN, FD_FOR_STDOUT) [W32CE]: Use estream.
(translate_file_handle) [W32CE]: Remove handle translation.
2010-03-23 Werner Koch <wk@g10code.com>
* sysutils.c (gnupg_remove): New.
2010-03-22 Werner Koch <wk@g10code.com>
* exechelp-w32ce.c (build_w32_commandline): Replace by code from
libassuan.
(create_inheritable_pipe): Use _assuan_w32ce_prepare_pipe.
(build_w32_commandline_copy, do_create_pipe): Remove.
* exechelp-posix.c (gnupg_spawn_process): Change to use estream
also for INFILE and STATUSFILE.
* exechelp-w32.c (gnupg_spawn_process): Ditto.
2010-03-22 Werner Koch <wk@g10code.com> 2010-03-22 Werner Koch <wk@g10code.com>
* exechelp.c: Remove after factoring all code out to ... * exechelp.c: Remove after factoring all code out to ...

View File

@ -1,6 +1,6 @@
/* dotlock.c - dotfile locking /* dotlock.c - dotfile locking
* Copyright (C) 1998, 2000, 2001, 2003, 2004, * Copyright (C) 1998, 2000, 2001, 2003, 2004,
* 2005, 2006, 2008 Free Software Foundation, Inc. * 2005, 2006, 2008, 2010 Free Software Foundation, Inc.
* *
* This file is part of JNLIB. * This file is part of JNLIB.
* *
@ -362,7 +362,10 @@ destroy_dotlock (dotlock_t h)
#ifdef HAVE_DOSISH_SYSTEM #ifdef HAVE_DOSISH_SYSTEM
if (h->locked) if (h->locked)
{ {
UnlockFile (h->lockhd, 0, 0, 1, 0); OVERLAPPED ovl;
memset (&ovl, 0, sizeof ovl);
UnlockFileEx (h->lockhd, 0, 1, 0, &ovl);
} }
CloseHandle (h->lockhd); CloseHandle (h->lockhd);
#else /* !HAVE_DOSISH_SYSTEM */ #else /* !HAVE_DOSISH_SYSTEM */
@ -497,8 +500,12 @@ make_dotlock (dotlock_t h, long timeout)
return -1; return -1;
#else /*HAVE_DOSISH_SYSTEM*/ #else /*HAVE_DOSISH_SYSTEM*/
int w32err; int w32err;
OVERLAPPED ovl;
if (LockFile (h->lockhd, 0, 0, 1, 0)) /* Lock one byte at offset 0. The offset is given by OVL. */
memset (&ovl, 0, sizeof ovl);
if (LockFileEx (h->lockhd, (LOCKFILE_EXCLUSIVE_LOCK
| LOCKFILE_FAIL_IMMEDIATELY), 0, 1, 0, &ovl))
{ {
h->locked = 1; h->locked = 1;
return 0; /* okay */ return 0; /* okay */
@ -552,12 +559,17 @@ release_dotlock (dotlock_t h)
} }
#ifdef HAVE_DOSISH_SYSTEM #ifdef HAVE_DOSISH_SYSTEM
if (!UnlockFile (h->lockhd, 0, 0, 1, 0)) {
OVERLAPPED ovl;
memset (&ovl, 0, sizeof ovl);
if (!UnlockFileEx (h->lockhd, 0, 1, 0, &ovl))
{ {
log_error ("release_dotlock: error removing lockfile `%s': %s\n", log_error ("release_dotlock: error removing lockfile `%s': %s\n",
h->lockname, w32_strerror (-1)); h->lockname, w32_strerror (-1));
return -1; return -1;
} }
}
#else #else
pid = read_lockfile (h, &same_node); pid = read_lockfile (h, &same_node);

View File

@ -299,31 +299,12 @@ gnupg_create_outbound_pipe (int filedes[2])
} }
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to /* Fork and exec the PGMNAME, see exechelp.h for details. */
stdin, write the output to OUTFILE, return a new stream in
STATUSFILE for stderr and the pid of the process in PID. The
arguments for the process are expected in the NULL terminated array
ARGV. The program name itself should not be included there. If
PREEXEC is not NULL, that function will be called right before the
exec. Calling gnupg_wait_process is required.
FLAGS is a bit vector with just one bit defined for now:
Bit 7: If set the process will be started as a background process.
This flag is only useful under W32 systems, so that no new
console is created and pops up a console window when
starting the server
Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to
error problems this actually allows SetForegroundWindow for
childs of this process.
Returns 0 on success or an error code. */
gpg_error_t gpg_error_t
gnupg_spawn_process (const char *pgmname, const char *argv[], gnupg_spawn_process (const char *pgmname, const char *argv[],
FILE *infile, estream_t outfile, estream_t infile, estream_t outfile,
void (*preexec)(void), unsigned int flags, void (*preexec)(void), unsigned int flags,
FILE **statusfile, pid_t *pid) estream_t *statusfile, pid_t *pid)
{ {
gpg_error_t err; gpg_error_t err;
int fd, fdout, rp[2]; int fd, fdout, rp[2];
@ -332,9 +313,9 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
*statusfile = NULL; *statusfile = NULL;
*pid = (pid_t)(-1); *pid = (pid_t)(-1);
fflush (infile); es_fflush (infile);
rewind (infile); es_rewind (infile);
fd = fileno (infile); fd = es_fileno (infile);
fdout = es_fileno (outfile); fdout = es_fileno (outfile);
if (fd == -1 || fdout == -1) if (fd == -1 || fdout == -1)
log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n");
@ -371,7 +352,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
/* Parent. */ /* Parent. */
close (rp[1]); close (rp[1]);
*statusfile = fdopen (rp[0], "r"); *statusfile = es_fdopen (rp[0], "r");
if (!*statusfile) if (!*statusfile)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();

View File

@ -362,31 +362,12 @@ gnupg_create_outbound_pipe (int filedes[2])
} }
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to /* Fork and exec the PGMNAME, see exechelp.h for details. */
stdin, write the output to OUTFILE, return a new stream in
STATUSFILE for stderr and the pid of the process in PID. The
arguments for the process are expected in the NULL terminated array
ARGV. The program name itself should not be included there. If
PREEXEC is not NULL, that function will be called right before the
exec. Calling gnupg_wait_process is required.
FLAGS is a bit vector with just one bit defined for now:
Bit 7: If set the process will be started as a background process.
This flag is only useful under W32 systems, so that no new
console is created and pops up a console window when
starting the server
Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to
error problems this actually allows SetForegroundWindow for
childs of this process.
Returns 0 on success or an error code. */
gpg_error_t gpg_error_t
gnupg_spawn_process (const char *pgmname, const char *argv[], gnupg_spawn_process (const char *pgmname, const char *argv[],
FILE *infile, estream_t outfile, estream_t infile, estream_t outfile,
void (*preexec)(void), unsigned int flags, void (*preexec)(void), unsigned int flags,
FILE **statusfile, pid_t *pid) estream_t *statusfile, pid_t *pid)
{ {
gpg_error_t err; gpg_error_t err;
SECURITY_ATTRIBUTES sec_attr; SECURITY_ATTRIBUTES sec_attr;
@ -407,9 +388,9 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
/* Setup return values. */ /* Setup return values. */
*statusfile = NULL; *statusfile = NULL;
*pid = (pid_t)(-1); *pid = (pid_t)(-1);
fflush (infile); es_fflush (infile);
rewind (infile); es_rewind (infile);
fd = _get_osfhandle (fileno (infile)); fd = _get_osfhandle (es_fileno (infile));
fdout = _get_osfhandle (es_fileno (outfile)); fdout = _get_osfhandle (es_fileno (outfile));
if (fd == -1 || fdout == -1) if (fd == -1 || fdout == -1)
log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n");
@ -494,7 +475,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
if (x == -1) if (x == -1)
log_error ("failed to translate osfhandle %p\n", (void*)rp[0] ); log_error ("failed to translate osfhandle %p\n", (void*)rp[0] );
else else
*statusfile = fdopen (x, "r"); *statusfile = es_fdopen (x, "r");
} }
if (!*statusfile) if (!*statusfile)
{ {

View File

@ -48,6 +48,7 @@
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
#include <assuan.h>
#include "util.h" #include "util.h"
#include "i18n.h" #include "i18n.h"
@ -71,7 +72,128 @@
#define pid_to_handle(a) ((HANDLE)(a)) #define pid_to_handle(a) ((HANDLE)(a))
#define handle_to_pid(a) ((int)(a)) #define handle_to_pid(a) ((int)(a))
#ifdef USE_GNU_PTH
/* The data passed to the feeder_thread. */
struct feeder_thread_parms
{
estream_t stream;
int fd;
int direction;
};
/* The thread started by start_feeded. */
static void *
feeder_thread (void *arg)
{
struct feeder_thread_parms *parm = arg;
char buffer[4096];
if (parm->direction)
{
size_t nread;
DWORD nwritten;
while (!es_read (parm->stream, buffer, sizeof buffer, &nread))
{
do
{
if (!WriteFile (fd_to_handle (parm->fd),
buffer, nread, &nwritten, NULL))
{
log_debug ("feeder(%d): WriteFile error: rc=%d\n",
parm->fd, (int)GetLastError ());
goto leave;
}
nread -= nwritten;
}
while (nread);
}
if (nread)
log_debug ("feeder(%d): es_read error: %s\n",
parm->fd, strerror (errno));
}
else
{
DWORD nread;
size_t nwritten;
while (ReadFile (fd_to_handle (parm->fd),
buffer, sizeof buffer, &nread, NULL) && nread)
{
do
{
if (es_write (parm->stream, buffer, nread, &nwritten))
{
log_debug ("feeder(%d): es_write error: %s\n",
parm->fd, strerror (errno));
goto leave;
}
nread -= nwritten;
}
while (nread);
}
if (nread)
log_debug ("feeder(%d): ReadFile error: rc=%d\n",
parm->fd, (int)GetLastError ());
else
log_debug ("feeder(%d): eof\n", parm->fd);
}
leave:
CloseHandle (fd_to_handle (parm->fd));
xfree (parm);
return NULL;
}
#endif /*USE_GNU_PTH*/
/* Fire up a thread to copy data between STREAM and a pipe's
descriptor FD. With DIRECTION set to true the copy takes place
from the stream to the pipe, otherwise from the pipe to the
stream. */
static gpg_error_t
start_feeder (estream_t stream, int fd, int direction)
{
#ifdef USE_GNU_PTH
gpg_error_t err;
struct feeder_thread_parms *parm;
pth_attr_t tattr;
parm = xtrymalloc (sizeof *parm);
if (!parm)
return gpg_error_from_syserror ();
parm->stream = stream;
parm->fd = fd;
parm->direction = direction;
tattr = pth_attr_new ();
pth_attr_set (tattr, PTH_ATTR_JOINABLE, 0);
pth_attr_set (tattr, PTH_ATTR_STACK_SIZE, 64*1024);
pth_attr_set (tattr, PTH_ATTR_NAME, "exec-feeder");
log_error ("spawning new feeder(%p, %d, %d)\n", stream, fd, direction);
if(!pth_spawn (tattr, feeder_thread, parm))
{
err = gpg_error_from_syserror ();
log_error ("error spawning feeder: %s\n", gpg_strerror (err));
xfree (parm);
}
else
err = 0;
pth_attr_destroy (tattr);
return err;
#else
(void)stream;
(void)fd;
(void)direction;
return gpg_error (GPG_ERR_NOT_IMPLEMENTED); /* No Pth. */
#endif
}
/* Return the maximum number of currently allowed open file /* Return the maximum number of currently allowed open file
descriptors. Only useful on POSIX systems but returns a value on descriptors. Only useful on POSIX systems but returns a value on
other systems too. */ other systems too. */
@ -182,20 +304,18 @@ get_all_open_fds (void)
} }
/* Helper function to build_w32_commandline. */
static char * static char *
build_w32_commandline_copy (char *buffer, const char *string) copy_quoted (char *p, const char *string)
{ {
char *p = buffer;
const char *s; const char *s;
if (!*string) /* Empty string. */ if (!*string) /* Empty string. */
p = stpcpy (p, "\"\""); p = stpcpy (p, "\"\"");
else if (strpbrk (string, " \t\n\v\f\"")) else if (strpbrk (string, " \t\n\v\f\"")) /* Need quotes. */
{ {
/* Need to do some kind of quoting. */
p = stpcpy (p, "\""); p = stpcpy (p, "\"");
for (s=string; *s; s++) for (s = string; *s; s++)
{ {
*p++ = *s; *p++ = *s;
if (*s == '\"') if (*s == '\"')
@ -204,32 +324,52 @@ build_w32_commandline_copy (char *buffer, const char *string)
*p++ = '\"'; *p++ = '\"';
*p = 0; *p = 0;
} }
else else /* Copy verbatim. */
p = stpcpy (p, string); p = stpcpy (p, string);
return p; return p;
} }
/* Build a command line for use with W32's CreateProcess. On success /* Build a command line for use with W32's CreateProcess. On success
CMDLINE gets the address of a newly allocated string. */ CMDLINE gets the address of a newly allocated string. */
static gpg_error_t static int
build_w32_commandline (const char *pgmname, const char * const *argv, build_w32_commandline (const char *pgmname, const char * const *argv,
int fd0, int fd1, int fd2, int fd2_isnull,
char **cmdline) char **cmdline)
{ {
int i, n; int i, n;
const char *s; const char *s;
char *buf, *p; char *buf, *p;
char fdbuf[3*30];
p = fdbuf;
*p = 0;
if (fd0)
{
snprintf (p, 25, "-&S0=%d ", fd0);
p += strlen (p);
}
if (fd1)
{
snprintf (p, 25, "-&S1=%d ", fd1);
p += strlen (p);
}
if (fd2)
{
if (fd2_isnull)
strcpy (p, "-&S2=null ");
else
snprintf (p, 25, "-&S2=%d ", fd2);
p += strlen (p);
}
*cmdline = NULL; *cmdline = NULL;
n = 0; n = strlen (fdbuf);
s = pgmname; n += strlen (pgmname) + 1 + 2; /* (1 space, 2 quoting) */
n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ for (i=0; (s = argv[i]); i++)
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 */ n += strlen (s) + 1 + 2; /* (1 space, 2 quoting) */
for (; *s; s++) for (; *s; s++)
if (*s == '\"') if (*s == '\"')
n++; /* Need to double inner quotes. */ n++; /* Need to double inner quotes. */
@ -237,183 +377,91 @@ build_w32_commandline (const char *pgmname, const char * const *argv,
n++; n++;
buf = p = xtrymalloc (n); buf = p = xtrymalloc (n);
if (!buf) if (! buf)
return gpg_error_from_syserror (); return -1;
p = build_w32_commandline_copy (p, pgmname); p = stpcpy (p, fdbuf);
for (i=0; argv[i]; i++) p = copy_quoted (p, pgmname);
for (i = 0; argv[i]; i++)
{ {
*p++ = ' '; *p++ = ' ';
p = build_w32_commandline_copy (p, argv[i]); p = copy_quoted (p, argv[i]);
} }
*cmdline= buf; *cmdline = buf;
return 0; return 0;
} }
/* Create pipe where one end is inheritable: With an INHERIT_IDX of 0 /* Create pipe where one end is inheritable: With an INHERIT_IDX of 0
the read end is inheritable, with 1 the write end is inheritable. */ the read end is inheritable, with 1 the write end is inheritable.
static int Note that the inheritable ends are rendezvous ids and no file
descriptors or handles. */
static gpg_error_t
create_inheritable_pipe (int filedes[2], int inherit_idx) create_inheritable_pipe (int filedes[2], int inherit_idx)
{ {
HANDLE r, w, h; HANDLE hd;
int rvid;
if (!CreatePipe (&r, &w, NULL, 0)) filedes[0] = filedes[1] = -1;
return -1; hd = _assuan_w32ce_prepare_pipe (&rvid, !inherit_idx);
if (hd == INVALID_HANDLE_VALUE)
if (!DuplicateHandle (GetCurrentProcess(), inherit_idx? w : r,
GetCurrentProcess(), &h, 0,
TRUE, DUPLICATE_SAME_ACCESS ))
{ {
log_error ("DuplicateHandle failed: %s\n", w32_strerror (-1)); log_error ("_assuan_w32ce_prepare_pipe failed: %s\n", w32_strerror (-1));
CloseHandle (r); gpg_err_set_errno (EIO);
CloseHandle (w); return gpg_error_from_syserror ();
return -1;
} }
if (inherit_idx) if (inherit_idx)
{ {
CloseHandle (w); filedes[0] = handle_to_fd (hd);
w = h; filedes[1] = rvid;
} }
else else
{ {
CloseHandle (r); filedes[0] = rvid;
r = h; filedes[1] = handle_to_fd (hd);
} }
filedes[0] = handle_to_fd (r);
filedes[1] = handle_to_fd (w);
return 0; return 0;
} }
static gpg_error_t
do_create_pipe (int filedes[2], int inherit_idx)
{
gpg_error_t err = 0;
int fds[2];
filedes[0] = filedes[1] = -1;
err = gpg_error (GPG_ERR_GENERAL);
if (!create_inheritable_pipe (fds, inherit_idx))
{
filedes[0] = _open_osfhandle (fds[0], 0);
if (filedes[0] == -1)
{
log_error ("failed to translate osfhandle %p\n", (void*)fds[0]);
CloseHandle (fd_to_handle (fds[1]));
}
else
{
filedes[1] = _open_osfhandle (fds[1], 1);
if (filedes[1] == -1)
{
log_error ("failed to translate osfhandle %p\n", (void*)fds[1]);
close (filedes[0]);
filedes[0] = -1;
CloseHandle (fd_to_handle (fds[1]));
}
else
err = 0;
}
}
return err;
}
/* Portable function to create a pipe. Under Windows the write end is /* Portable function to create a pipe. Under Windows the write end is
inheritable. */ inheritable (i.e. an rendezvous id). */
gpg_error_t gpg_error_t
gnupg_create_inbound_pipe (int filedes[2]) gnupg_create_inbound_pipe (int filedes[2])
{ {
return do_create_pipe (filedes, 1); return create_inheritable_pipe (filedes, 1);
} }
/* Portable function to create a pipe. Under Windows the read end is /* Portable function to create a pipe. Under Windows the read end is
inheritable. */ inheritable (i.e. an rendezvous id). */
gpg_error_t gpg_error_t
gnupg_create_outbound_pipe (int filedes[2]) gnupg_create_outbound_pipe (int filedes[2])
{ {
return do_create_pipe (filedes, 0); return create_inheritable_pipe (filedes, 0);
} }
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to static int
stdin, write the output to OUTFILE, return a new stream in create_process (const char *pgmname, const char *cmdline,
STATUSFILE for stderr and the pid of the process in PID. The PROCESS_INFORMATION *pi)
arguments for the process are expected in the NULL terminated array
ARGV. The program name itself should not be included there. If
PREEXEC is not NULL, that function will be called right before the
exec. Calling gnupg_wait_process is required.
FLAGS is a bit vector with just one bit defined for now:
Bit 7: If set the process will be started as a background process.
This flag is only useful under W32 systems, so that no new
console is created and pops up a console window when
starting the server. Does not work on W32CE.
Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to
error problems this actually allows SetForegroundWindow for
childs of this process.
Returns 0 on success or an error code. */
gpg_error_t
gnupg_spawn_process (const char *pgmname, const char *argv[],
FILE *infile, estream_t outfile,
void (*preexec)(void), unsigned int flags,
FILE **statusfile, pid_t *pid)
{ {
gpg_error_t err; int res;
PROCESS_INFORMATION pi = wchar_t *wpgmname, *wcmdline;
wpgmname = utf8_to_wchar (pgmname);
if (!wpgmname)
return 0;
wcmdline = utf8_to_wchar (cmdline);
if (!wcmdline)
{ {
NULL, /* Returns process handle. */ xfree (wpgmname);
0, /* Returns primary thread handle. */ return 0;
0, /* Returns pid. */
0 /* Returns tid. */
};
STARTUPINFO si;
char *cmdline;
int fd, fdout, rp[2];
(void)preexec;
/* Setup return values. */
*statusfile = NULL;
*pid = (pid_t)(-1);
fflush (infile);
rewind (infile);
fd = _get_osfhandle (fileno (infile));
fdout = _get_osfhandle (es_fileno (outfile));
if (fd == -1 || fdout == -1)
log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n");
/* Build the command line. */
err = build_w32_commandline (pgmname, argv, &cmdline);
if (err)
return err;
/* Create a pipe. */
if (create_inheritable_pipe (rp, 1))
{
err = gpg_error (GPG_ERR_GENERAL);
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
xfree (cmdline);
return err;
} }
res = CreateProcess (wpgmname, /* Program to start. */
/* Start the process. Note that we can't run the PREEXEC function wcmdline, /* Command line arguments. */
because this would change our own environment. */
/* si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; */
/* si.hStdInput = fd_to_handle (fd); */
/* si.hStdOutput = fd_to_handle (fdout); */
/* si.hStdError = fd_to_handle (rp[1]); */
/* log_debug ("CreateProcess, path=`%s' cmdline=`%s'\n", pgmname, cmdline); */
if (!CreateProcess (pgmname, /* Program to start. */
cmdline, /* Command line arguments. */
NULL, /* Process security attributes. */ NULL, /* Process security attributes. */
NULL, /* Thread security attributes. */ NULL, /* Thread security attributes. */
FALSE, /* Inherit handles. */ FALSE, /* Inherit handles. */
@ -421,45 +469,111 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
NULL, /* Environment. */ NULL, /* Environment. */
NULL, /* Use current drive/directory. */ NULL, /* Use current drive/directory. */
NULL, /* Startup information. */ NULL, /* Startup information. */
&pi /* Returns process information. */ pi); /* Returns process information. */
)) xfree (wcmdline);
xfree (wpgmname);
return res;
}
/* Fork and exec the PGMNAME, see exechelp.h for details. */
gpg_error_t
gnupg_spawn_process (const char *pgmname, const char *argv[],
estream_t infile, estream_t outfile,
void (*preexec)(void), unsigned int flags,
estream_t *statusfile, pid_t *pid)
{
gpg_error_t err;
PROCESS_INFORMATION pi = {NULL };
char *cmdline;
int inpipe[2], outpipe[2], errpipe[2];
(void)preexec;
(void)flags;
/* Setup return values. */
*statusfile = NULL;
*pid = (pid_t)(-1);
es_fflush (infile);
es_rewind (infile);
/* Create a pipe to copy our infile to the stdin of the child
process. On success inpipe[1] is owned by the feeder. */
err = create_inheritable_pipe (inpipe, 0);
if (err)
{
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
return err;
}
err = start_feeder (infile, inpipe[1], 1);
if (err)
{
log_error (_("error spawning feeder: %s\n"), gpg_strerror (err));
CloseHandle (fd_to_handle (inpipe[1]));
return err;
}
/* Create a pipe to copy stdout of the child process to our
outfile. On success outpipe[0] is owned by the feeded. */
err = create_inheritable_pipe (outpipe, 1);
if (err)
{
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
return err;
}
err = start_feeder (outfile, outpipe[0], 0);
if (err)
{
log_error (_("error spawning feeder: %s\n"), gpg_strerror (err));
CloseHandle (fd_to_handle (outpipe[0]));
return err;
}
/* Create a pipe for use with stderr of the child process. */
err = create_inheritable_pipe (errpipe, 1);
if (err)
{
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
return err;
}
/* Build the command line. */
err = build_w32_commandline (pgmname, argv, inpipe[0], outpipe[1], errpipe[1],
0, &cmdline);
if (err)
{
CloseHandle (fd_to_handle (errpipe[0]));
return err;
}
log_debug ("CreateProcess, path=`%s' cmdline=`%s'\n", pgmname, cmdline);
if (!create_process (pgmname, cmdline, &pi))
{ {
log_error ("CreateProcess failed: %s\n", w32_strerror (-1)); log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
xfree (cmdline); xfree (cmdline);
CloseHandle (fd_to_handle (rp[0])); CloseHandle (fd_to_handle (errpipe[0]));
CloseHandle (fd_to_handle (rp[1]));
return gpg_error (GPG_ERR_GENERAL); return gpg_error (GPG_ERR_GENERAL);
} }
xfree (cmdline); xfree (cmdline);
cmdline = NULL; cmdline = NULL;
/* Close the other end of the pipe. */ /* Note: The other end of the pipe is a rendezvous id and thus there
CloseHandle (fd_to_handle (rp[1])); is no need to close. */
/* log_debug ("CreateProcess ready: hProcess=%p hThread=%p" */ log_debug ("CreateProcess ready: hProcess=%p hThread=%p"
/* " dwProcessID=%d dwThreadId=%d\n", */ " dwProcessID=%d dwThreadId=%d\n",
/* pi.hProcess, pi.hThread, */ pi.hProcess, pi.hThread,
/* (int) pi.dwProcessId, (int) pi.dwThreadId); */ (int) pi.dwProcessId, (int) pi.dwThreadId);
/* Fixme: For unknown reasons AllowSetForegroundWindow returns an
invalid argument error if we pass the correct processID to
it. As a workaround we use -1 (ASFW_ANY). */
if ( (flags & 64) )
gnupg_allow_set_foregound_window ((pid_t)(-1)/*pi.dwProcessId*/);
/* Process has been created suspended; resume it now. */ /* Process has been created suspended; resume it now. */
ResumeThread (pi.hThread); ResumeThread (pi.hThread);
CloseHandle (pi.hThread); CloseHandle (pi.hThread);
{ *statusfile = es_fdopen (handle_to_fd (errpipe[0]), "r");
int x;
x = _open_osfhandle (rp[0], 0);
if (x == -1)
log_error ("failed to translate osfhandle %p\n", (void*)rp[0] );
else
*statusfile = fdopen (x, "r");
}
if (!*statusfile) if (!*statusfile)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -487,6 +601,8 @@ gpg_error_t
gnupg_spawn_process_fd (const char *pgmname, const char *argv[], gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
int infd, int outfd, int errfd, pid_t *pid) int infd, int outfd, int errfd, pid_t *pid)
{ {
return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
#if 0
gpg_error_t err; gpg_error_t err;
PROCESS_INFORMATION pi = { NULL, 0, 0, 0 }; PROCESS_INFORMATION pi = { NULL, 0, 0, 0 };
STARTUPINFO si; STARTUPINFO si;
@ -546,10 +662,9 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
*pid = handle_to_pid (pi.hProcess); *pid = handle_to_pid (pi.hProcess);
return 0; return 0;
#endif
} }
/* Wait for the process identified by PID to terminate. PGMNAME should /* Wait for the process identified by PID to terminate. PGMNAME should
be the same as supplied to the spawn function and is only used for be the same as supplied to the spawn function and is only used for
diagnostics. Returns 0 if the process succeeded, GPG_ERR_GENERAL diagnostics. Returns 0 if the process succeeded, GPG_ERR_GENERAL
@ -628,6 +743,8 @@ gpg_error_t
gnupg_spawn_process_detached (const char *pgmname, const char *argv[], gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
const char *envp[] ) const char *envp[] )
{ {
return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
#if 0
gpg_error_t err; gpg_error_t err;
PROCESS_INFORMATION pi = PROCESS_INFORMATION pi =
{ {
@ -678,9 +795,9 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
CloseHandle (pi.hThread); CloseHandle (pi.hThread);
return 0; return 0;
#endif
} }
/* Kill a process; that is send an appropriate signal to the process. /* Kill a process; that is send an appropriate signal to the process.
gnupg_wait_process must be called to actually remove the process gnupg_wait_process must be called to actually remove the process
from the system. An invalid PID is ignored. */ from the system. An invalid PID is ignored. */

View File

@ -1,5 +1,5 @@
/* exechelp.h - Definitions for the fork and exec helpers /* exechelp.h - Definitions for the fork and exec helpers
* Copyright (C) 2004, 2009 Free Software Foundation, Inc. * Copyright (C) 2004, 2009, 2010 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -58,13 +58,25 @@ gpg_error_t gnupg_create_outbound_pipe (int filedes[2]);
arguments for the process are expected in the NULL terminated array arguments for the process are expected in the NULL terminated array
ARGV. The program name itself should not be included there. If ARGV. The program name itself should not be included there. If
PREEXEC is not NULL, that function will be called right before the PREEXEC is not NULL, that function will be called right before the
exec. FLAGS is currently only useful for W32, see the source for exec. Calling gnupg_wait_process is required. Returns 0 on
details. Calling gnupg_wait_process is required. Returns 0 on success or an error code.
success or an error code. */
FLAGS is a bit vector:
Bit 7: If set the process will be started as a background process.
This flag is only useful under W32 (but not W32CE) systems,
so that no new console is created and pops up a console
window when starting the server. Does not work on W32CE.
Bit 6: On W32 (but not on W32CE) run AllowSetForegroundWindow for
the child. Note that due to unknown problems this actually
allows SetForegroundWindow for all childs of this process.
*/
gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[],
FILE *infile, estream_t outfile, estream_t infile, estream_t outfile,
void (*preexec)(void), unsigned int flags, void (*preexec)(void), unsigned int flags,
FILE **statusfile, pid_t *pid); estream_t *statusfile, pid_t *pid);
/* Simplified version of gnupg_spawn_process. This function forks and /* Simplified version of gnupg_spawn_process. This function forks and

View File

@ -101,7 +101,7 @@ init_common_subsystems (int *argcp, char ***argvp)
SetStdioPath set and restore game. The caller needs to pass the SetStdioPath set and restore game. The caller needs to pass the
rendezvous ids using up to three options: rendezvous ids using up to three options:
-&S0=<handle> -&S1=<handle> -&S2=<handle> -&S0=<rvid> -&S1=<rvid> -&S2=<rvid>
They are all optional but they must be the first arguments on the They are all optional but they must be the first arguments on the
command line. Parsing stops as soon as an invalid option is found. command line. Parsing stops as soon as an invalid option is found.

View File

@ -52,8 +52,13 @@
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
# ifdef HAVE_W32CE_SYSTEM
# define FD_FOR_STDIN (es_fileno (es_stdin))
# define FD_FOR_STDOUT (es_fileno (es_stdout))
# else
# define FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) # define FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE))
# define FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) # define FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE))
# endif
#else /*!HAVE_W32_SYSTEM*/ #else /*!HAVE_W32_SYSTEM*/
# define FD_FOR_STDIN (0) # define FD_FOR_STDIN (0)
# define FD_FOR_STDOUT (1) # define FD_FOR_STDOUT (1)
@ -2361,7 +2366,7 @@ iobuf_read_line (iobuf_t a, byte ** addr_of_buffer,
static int static int
translate_file_handle (int fd, int for_write) translate_file_handle (int fd, int for_write)
{ {
#ifdef HAVE_W32_SYSTEM #if defined(HAVE_W32_SYSTEM) && !defined (HAVE_W32CE_SYSTEM)
{ {
int x; int x;

View File

@ -1,4 +1,4 @@
/* se4ssiobn-env.c - session environment helper functions. /* session-env.c - Session environment helper functions.
* Copyright (C) 2009 Free Software Foundation, Inc. * Copyright (C) 2009 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
@ -300,7 +300,7 @@ session_env_getenv (session_env_t se, const char *name)
/* Return the value of the environment variable NAME from the SE /* Return the value of the environment variable NAME from the SE
object. The returned value is valid as long as SE is valid and as object. The returned value is valid as long as SE is valid and as
long it has not been removed or updated by a call to long it has not been removed or updated by a call to
session_env_putenv. If the variable does not exist, the fucntion session_env_putenv. If the variable does not exist, the function
tries to return the value trough a call to getenv; if that returns tries to return the value trough a call to getenv; if that returns
a value, this value is recorded and and used. If no value could be a value, this value is recorded and and used. If no value could be
found, returns NULL. The caller must not change the returned found, returns NULL. The caller must not change the returned
@ -325,7 +325,7 @@ session_env_getenv_or_default (session_env_t se, const char *name,
return se->array[idx]->value; return se->array[idx]->value;
} }
/* Get the default value with and additional fallback for GPG_TTY. */ /* Get the default value with an additional fallback for GPG_TTY. */
defvalue = getenv (name); defvalue = getenv (name);
if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY") && ttyname (0)) if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY") && ttyname (0))
defvalue = ttyname (0); defvalue = ttyname (0);

View File

@ -1,6 +1,6 @@
/* stringhelp.c - standard string helper functions /* stringhelp.c - standard string helper functions
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007,
* 2006, 2007, 2008, 2009 Free Software Foundation, Inc. * 2008, 2009, 2010 Free Software Foundation, Inc.
* *
* This file is part of JNLIB. * This file is part of JNLIB.
* *
@ -48,7 +48,7 @@
static inline char * static inline char *
change_slashes (char *name) change_slashes (char *name)
{ {
#ifdef HAVE_DRIVE_LETTERS #ifdef HAVE_DOSISH_SYSTEM
char *p; char *p;
if (strchr (name, '\\')) if (strchr (name, '\\'))
@ -57,7 +57,7 @@ change_slashes (char *name)
if (*p == '/') if (*p == '/')
*p = '\\'; *p = '\\';
} }
#endif /*HAVE_DRIVE_LETTERS*/ #endif /*HAVE_DOSISH_SYSTEM*/
return name; return name;
} }
@ -273,8 +273,10 @@ make_basename(const char *filepath, const char *inputpath)
(void)inputpath; /* Only required for riscos. */ (void)inputpath; /* Only required for riscos. */
if ( !(p=strrchr(filepath, '/')) ) if ( !(p=strrchr(filepath, '/')) )
#ifdef HAVE_DRIVE_LETTERS #ifdef HAVE_DOSISH_SYSTEM
if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, '\\')) )
#endif
#ifdef HAVE_DRIVE_LETTERS
if ( !(p=strrchr(filepath, ':')) ) if ( !(p=strrchr(filepath, ':')) )
#endif #endif
{ {
@ -300,8 +302,10 @@ make_dirname(const char *filepath)
char *p; char *p;
if ( !(p=strrchr(filepath, '/')) ) if ( !(p=strrchr(filepath, '/')) )
#ifdef HAVE_DRIVE_LETTERS #ifdef HAVE_DOSISH_SYSTEM
if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, '\\')) )
#endif
#ifdef HAVE_DRIVE_LETTERS
if ( !(p=strrchr(filepath, ':')) ) if ( !(p=strrchr(filepath, ':')) )
#endif #endif
{ {
@ -479,12 +483,12 @@ make_filename_try (const char *first_part, ... )
/* Compare whether the filenames are identical. This is a /* Compare whether the filenames are identical. This is a
special version of strcmp() taking the semantics of filenames in special version of strcmp() taking the semantics of filenames in
account. Note that this function works only on the supplied names account. Note that this function works only on the supplied names
without considereing any context like the current directory. See without considering any context like the current directory. See
also same_file_p(). */ also same_file_p(). */
int int
compare_filenames (const char *a, const char *b) compare_filenames (const char *a, const char *b)
{ {
#ifdef HAVE_DRIVE_LETTERS #ifdef HAVE_DOSISH_SYSTEM
for ( ; *a && *b; a++, b++ ) for ( ; *a && *b; a++, b++ )
{ {
if (*a != *b if (*a != *b

View File

@ -505,6 +505,30 @@ gnupg_allow_set_foregound_window (pid_t pid)
#endif #endif
} }
int
gnupg_remove (const char *fname)
{
#ifdef HAVE_W32CE_SYSTEM
int rc;
wchar_t *wfname;
wfname = utf8_to_wchar (fname);
if (!wfname)
rc = 0;
else
{
rc = DeleteFile (wfname);
xfree (wfname);
}
if (!rc)
gpg_err_set_errno (EIO);
return !rc;
#else
return remove;
#endif
}
#ifdef HAVE_W32CE_SYSTEM #ifdef HAVE_W32CE_SYSTEM

View File

@ -48,7 +48,7 @@ int translate_sys2libc_fd_int (int fd, int for_write);
FILE *gnupg_tmpfile (void); FILE *gnupg_tmpfile (void);
void gnupg_reopen_std (const char *pgmname); void gnupg_reopen_std (const char *pgmname);
void gnupg_allow_set_foregound_window (pid_t pid); void gnupg_allow_set_foregound_window (pid_t pid);
int gnupg_remove (const char *fname);
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM

View File

@ -24,6 +24,11 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM)
# define USE_W32_CONSOLE 1
#endif
#ifdef HAVE_TCGETATTR #ifdef HAVE_TCGETATTR
#include <termios.h> #include <termios.h>
#else #else
@ -37,11 +42,11 @@
#define HAVE_TCGETATTR #define HAVE_TCGETATTR
#endif #endif
#endif #endif
#ifdef _WIN32 /* use the odd Win32 functions */ #ifdef USE_W32_CONSOLE
#include <windows.h> # include <windows.h>
#ifdef HAVE_TCGETATTR # ifdef HAVE_TCGETATTR
#error mingw32 and termios # error mingw32 and termios
#endif # endif
#endif #endif
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
@ -52,7 +57,8 @@
#define CONTROL_D ('D' - 'A' + 1) #define CONTROL_D ('D' - 'A' + 1)
#ifdef _WIN32 /* use the odd Win32 functions */
#ifdef USE_W32_CONSOLE
static struct { static struct {
HANDLE in, out; HANDLE in, out;
} con; } con;
@ -116,7 +122,7 @@ tty_get_ttyname (void)
} }
#endif /*HAVE_CTERMID*/ #endif /*HAVE_CTERMID*/
/* Assume the standard tty on memory error or when tehre is no /* Assume the standard tty on memory error or when tehre is no
certmid. */ ctermid. */
return name? name : "/dev/tty"; return name? name : "/dev/tty";
} }
@ -140,7 +146,7 @@ init_ttyfp(void)
if( initialized ) if( initialized )
return; return;
#if defined(_WIN32) #if defined(USE_W32_CONSOLE)
{ {
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
@ -168,6 +174,8 @@ init_ttyfp(void)
ttyfp = stdout; /* Fixme: replace by the real functions: see wklib */ ttyfp = stdout; /* Fixme: replace by the real functions: see wklib */
if (my_rl_init_stream) if (my_rl_init_stream)
my_rl_init_stream (ttyfp); my_rl_init_stream (ttyfp);
#elif defined (HAVE_W32CE_SYSTEM)
ttyfp = stderr;
#else #else
ttyfp = batchmode? stderr : fopen (tty_get_ttyname (), "r+"); ttyfp = batchmode? stderr : fopen (tty_get_ttyname (), "r+");
if( !ttyfp ) { if( !ttyfp ) {
@ -216,7 +224,7 @@ tty_printf( const char *fmt, ... )
init_ttyfp(); init_ttyfp();
va_start( arg_ptr, fmt ) ; va_start( arg_ptr, fmt ) ;
#ifdef _WIN32 #ifdef USE_W32_CONSOLE
{ {
char *buf = NULL; char *buf = NULL;
int n; int n;
@ -263,7 +271,7 @@ tty_fprintf (estream_t fp, const char *fmt, ... )
init_ttyfp (); init_ttyfp ();
va_start (arg_ptr, fmt); va_start (arg_ptr, fmt);
#ifdef _WIN32 #ifdef USE_W32_CONSOLE
{ {
char *buf = NULL; char *buf = NULL;
int n; int n;
@ -300,7 +308,7 @@ tty_print_string ( const byte *p, size_t n )
if( !initialized ) if( !initialized )
init_ttyfp(); init_ttyfp();
#ifdef _WIN32 #ifdef USE_W32_CONSOLE
/* not so effective, change it if you want */ /* not so effective, change it if you want */
for( ; n; n--, p++ ) for( ; n; n--, p++ )
if( iscntrl( *p ) ) { if( iscntrl( *p ) ) {
@ -394,7 +402,7 @@ do_get( const char *prompt, int hidden )
buf = xmalloc((n=50)); buf = xmalloc((n=50));
i = 0; i = 0;
#ifdef _WIN32 /* windoze version */ #ifdef USE_W32_CONSOLE
if( hidden ) if( hidden )
SetConsoleMode(con.in, HID_INPMODE ); SetConsoleMode(con.in, HID_INPMODE );
@ -428,9 +436,17 @@ do_get( const char *prompt, int hidden )
if( hidden ) if( hidden )
SetConsoleMode(con.in, DEF_INPMODE ); SetConsoleMode(con.in, DEF_INPMODE );
#elif defined(__riscos__) #elif defined(__riscos__) || defined(HAVE_W32CE_SYSTEM)
do { do {
#ifdef HAVE_W32CE_SYSTEM
/* Using getchar is not a correct solution but for now it
doesn't matter becuase we have no real console at all. We
should rework this as soon as we have switched this entire
module to estream. */
c = getchar();
#else
c = riscos_getchar(); c = riscos_getchar();
#endif
if (c == 0xa || c == 0xd) { /* Return || Enter */ if (c == 0xa || c == 0xd) { /* Return || Enter */
c = (int) '\n'; c = (int) '\n';
} else if (c == 0x8 || c == 0x7f) { /* Backspace || Delete */ } else if (c == 0x8 || c == 0x7f) { /* Backspace || Delete */
@ -468,7 +484,7 @@ do_get( const char *prompt, int hidden )
} }
} while (c != '\n'); } while (c != '\n');
i = (i>0) ? i-1 : 0; i = (i>0) ? i-1 : 0;
#else /* unix version */ #else /* Other systems. */
if( hidden ) { if( hidden ) {
#ifdef HAVE_TCGETATTR #ifdef HAVE_TCGETATTR
struct termios term; struct termios term;
@ -509,7 +525,6 @@ do_get( const char *prompt, int hidden )
i = 1; i = 1;
} }
if( hidden ) { if( hidden ) {
#ifdef HAVE_TCGETATTR #ifdef HAVE_TCGETATTR
if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) ) if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
@ -601,7 +616,7 @@ tty_kill_prompt()
last_prompt_len = 0; last_prompt_len = 0;
if( !last_prompt_len ) if( !last_prompt_len )
return; return;
#ifdef _WIN32 #ifdef USE_W32_CONSOLE
tty_printf("\r%*s\r", last_prompt_len, ""); tty_printf("\r%*s\r", last_prompt_len, "");
#else #else
{ {

View File

@ -364,8 +364,12 @@ AH_BOTTOM([
#define SAFE_VERSION_DASH '-' #define SAFE_VERSION_DASH '-'
/* Some global constants. */ /* Some global constants. */
#ifdef HAVE_DRIVE_LETTERS #ifdef HAVE_DOSISH_SYSTEM
#define GNUPG_DEFAULT_HOMEDIR "c:/gnupg" # ifdef HAVE_DRIVE_LETTERS
# define GNUPG_DEFAULT_HOMEDIR "c:/gnupg"
# else
# define GNUPG_DEFAULT_HOMEDIR "/gnupg"
# endif
#elif defined(__VMS) #elif defined(__VMS)
#define GNUPG_DEFAULT_HOMEDIR "/SYS\$LOGIN/gnupg" #define GNUPG_DEFAULT_HOMEDIR "/SYS\$LOGIN/gnupg"
#else #else
@ -376,15 +380,22 @@ AH_BOTTOM([
/* For some systems (DOS currently), we hardcode the path here. For /* For some systems (DOS currently), we hardcode the path here. For
POSIX systems the values are constructed by the Makefiles, so that POSIX systems the values are constructed by the Makefiles, so that
the values may be overridden by the make invocations; this is to the values may be overridden by the make invocations; this is to
comply with the GNU coding standards. */ comply with the GNU coding standards. Note that these values are
#ifdef HAVE_DRIVE_LETTERS only defaults. */
/* FIXME: We need to use a function to determine these values depending #ifdef HAVE_DOSISH_SYSTEM
on the actual installation directory. */ # ifdef HAVE_DRIVE_LETTERS
#define GNUPG_BINDIR "c:\\gnupg" # define GNUPG_BINDIR "c:\\gnupg"
#define GNUPG_LIBEXECDIR "c:\\gnupg" # define GNUPG_LIBEXECDIR "c:\\gnupg"
#define GNUPG_LIBDIR "c:\\gnupg" # define GNUPG_LIBDIR "c:\\gnupg"
#define GNUPG_DATADIR "c:\\gnupg" # define GNUPG_DATADIR "c:\\gnupg"
#define GNUPG_SYSCONFDIR "c:\\gnupg" # define GNUPG_SYSCONFDIR "c:\\gnupg"
# else
# define GNUPG_BINDIR "\\gnupg"
# define GNUPG_LIBEXECDIR "\\gnupg"
# define GNUPG_LIBDIR "\\gnupg"
# define GNUPG_DATADIR "\\gnupg"
# define GNUPG_SYSCONFDIR "\\gnupg"
# endif
#endif #endif
/* Derive some other constants. */ /* Derive some other constants. */
@ -509,17 +520,23 @@ case "${host}" in
# special stuff for Windoze NT # special stuff for Windoze NT
ac_cv_have_dev_random=no ac_cv_have_dev_random=no
AC_DEFINE(USE_ONLY_8DOT3,1, AC_DEFINE(USE_ONLY_8DOT3,1,
[set this to limit filenames to the 8.3 format]) [Set this to limit filenames to the 8.3 format])
AC_DEFINE(HAVE_DRIVE_LETTERS,1,
[defined if we must run on a stupid file system])
AC_DEFINE(USE_SIMPLE_GETTEXT,1, AC_DEFINE(USE_SIMPLE_GETTEXT,1,
[because the Unix gettext has too much overhead on [Because the Unix gettext has too much overhead on
MingW32 systems and these systems lack Posix functions, MingW32 systems and these systems lack Posix functions,
we use a simplified version of gettext]) we use a simplified version of gettext])
disable_keyserver_path=yes disable_keyserver_path=yes
have_dosish_system=yes have_dosish_system=yes
have_w32_system=yes have_w32_system=yes
case "${host}" in *-mingw32ce*) have_w32ce_system=yes ;; esac case "${host}" in
*-mingw32ce*)
have_w32ce_system=yes
;;
*)
AC_DEFINE(HAVE_DRIVE_LETTERS,1,
[Defined if the OS supports drive letters.])
;;
esac
try_gettext="no" try_gettext="no"
use_simple_gettext=yes use_simple_gettext=yes
;; ;;
@ -576,7 +593,8 @@ if test "$have_dosish_system" = yes; then
AC_DEFINE(HAVE_DOSISH_SYSTEM,1, AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
[Defined if we run on some of the PCDOS like systems [Defined if we run on some of the PCDOS like systems
(DOS, Windoze. OS/2) with special properties like (DOS, Windoze. OS/2) with special properties like
no file modes]) no file modes, case insensitive file names and preferred
use of backslashes as directory name separators.])
fi fi
AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes) AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
@ -1272,9 +1290,13 @@ GNUPG_CHECK_GNUMAKE
# mysterious reasons - the final link step should bail out. # mysterious reasons - the final link step should bail out.
# W32SOCKLIBS is also defined so that if can be used for tools not # W32SOCKLIBS is also defined so that if can be used for tools not
# requiring any network stuff but linking to code in libcommon which # requiring any network stuff but linking to code in libcommon which
# tracks in winsock stuff (e.g. init_common_subsystems. # tracks in winsock stuff (e.g. init_common_subsystems).
if test "$have_w32_system" = yes; then if test "$have_w32_system" = yes; then
if test "$have_w32ce_system" = yes; then
W32SOCKLIBS="-lws2"
else
W32SOCKLIBS="-lws2_32" W32SOCKLIBS="-lws2_32"
fi
NETLIBS="${NETLIBS} ${W32SOCKLIBS}" NETLIBS="${NETLIBS} ${W32SOCKLIBS}"
fi fi

View File

@ -1,3 +1,8 @@
2010-03-24 Werner Koch <wk@g10code.com>
* openfile.c (CMP_FILENAME): Depend on HAVE_DOSISH_SYSTEM instead
of HAVE_DRIVE_LETTERS.
2010-03-15 Werner Koch <wk@g10code.com> 2010-03-15 Werner Koch <wk@g10code.com>
* card-util.c: Replace stdio by estream. * card-util.c: Replace stdio by estream.

View File

@ -1,3 +1,12 @@
2010-03-23 Werner Koch <wk@g10code.com>
* Makefile.am (extra_libs): New.
(kbxutil_LDADD): Use it.
* keybox-update.c: [HAVE_DOSISH_SYSTEM]: Include sysutils.h.
(keybox_compress): Replace rewind by fseek+clearerr.
(rename_tmp_file, keybox_compress): s/remove/gnupg_remove/.
2010-03-10 Werner Koch <wk@g10code.com> 2010-03-10 Werner Koch <wk@g10code.com>
* Makefile.am (kbxutil_LDADD, $(PROGRAMS)): Remove libjnlib.a. * Makefile.am (kbxutil_LDADD, $(PROGRAMS)): Remove libjnlib.a.

View File

@ -28,6 +28,12 @@ AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_srcdir)/common -I$(top_srcdir)/intl \
noinst_LIBRARIES = libkeybox.a noinst_LIBRARIES = libkeybox.a
bin_PROGRAMS = kbxutil bin_PROGRAMS = kbxutil
if HAVE_W32CE_SYSTEM
extra_libs = $(LIBASSUAN_LIBS)
else
extra_libs =
endif
common_sources = \ common_sources = \
keybox.h keybox-defs.h keybox-search-desc.h \ keybox.h keybox-defs.h keybox-search-desc.h \
keybox-util.c \ keybox-util.c \
@ -47,7 +53,7 @@ libkeybox_a_SOURCES = $(common_sources)
# to do it this way. # to do it this way.
kbxutil_SOURCES = kbxutil.c $(common_sources) kbxutil_SOURCES = kbxutil.c $(common_sources)
kbxutil_LDADD = ../common/libcommon.a ../gl/libgnu.a \ kbxutil_LDADD = ../common/libcommon.a ../gl/libgnu.a \
$(KSBA_LIBS) $(LIBGCRYPT_LIBS) \ $(KSBA_LIBS) $(LIBGCRYPT_LIBS) $(extra_libs) \
$(GPG_ERROR_LIBS) $(LIBINTL) $(LIBICONV) $(W32SOCKLIBS) $(GPG_ERROR_LIBS) $(LIBINTL) $(LIBICONV) $(W32SOCKLIBS)
$(PROGRAMS) : ../common/libcommon.a ../gl/libgnu.a $(PROGRAMS) : ../common/libcommon.a ../gl/libgnu.a

View File

@ -26,6 +26,9 @@
#include <unistd.h> #include <unistd.h>
#include "keybox-defs.h" #include "keybox-defs.h"
#ifdef HAVE_DOSISH_SYSTEM
#include "../common/sysutils.h"
#endif
#define EXTSEP_S "." #define EXTSEP_S "."
@ -174,7 +177,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
if (!secret) if (!secret)
{ {
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
remove (bakfname); gnupg_remove (bakfname);
#endif #endif
if (rename (fname, bakfname) ) if (rename (fname, bakfname) )
{ {
@ -184,7 +187,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
/* Then rename the file. */ /* Then rename the file. */
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
remove (fname); gnupg_remove (fname);
#endif #endif
if (rename (tmpfname, fname) ) if (rename (tmpfname, fname) )
{ {
@ -607,7 +610,8 @@ keybox_compress (KEYBOX_HANDLE hd)
} }
} }
_keybox_release_blob (blob); _keybox_release_blob (blob);
rewind (fp); fseek (fp, 0, SEEK_SET);
clearerr (fp);
} }
/* Create the new file. */ /* Create the new file. */
@ -709,7 +713,7 @@ keybox_compress (KEYBOX_HANDLE hd)
/* Rename or remove the temporary file. */ /* Rename or remove the temporary file. */
if (rc || !any_changes) if (rc || !any_changes)
remove (tmpfname); gnupg_remove (tmpfname);
else else
rc = rename_tmp_file (bakfname, tmpfname, fname, hd->secret); rc = rename_tmp_file (bakfname, tmpfname, fname, hd->secret);

View File

@ -1,3 +1,17 @@
2010-03-24 Werner Koch <wk@g10code.com>
* Makefile.am (gpgsm_LDADD): Add extra_sys_libs.
2010-03-23 Werner Koch <wk@g10code.com>
* qualified.c (gpgsm_is_in_qualified_list): Replace rewind by
fseek+clearerr.
2010-03-22 Werner Koch <wk@g10code.com>
* import.c (parse_p12): Use estream functions for the tmp streams.
* export.c (export_p12): Ditto.
2010-03-11 Werner Koch <wk@g10code.com> 2010-03-11 Werner Koch <wk@g10code.com>
* verify.c (gpgsm_verify): Use gpgsm_es_print_name. * verify.c (gpgsm_verify): Use gpgsm_es_print_name.

View File

@ -56,7 +56,8 @@ common_libs = ../kbx/libkeybox.a $(libcommon) ../gl/libgnu.a
gpgsm_LDADD = $(common_libs) ../common/libgpgrl.a \ gpgsm_LDADD = $(common_libs) ../common/libgpgrl.a \
$(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \ $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \
$(GPG_ERROR_LIBS) $(LIBREADLINE) $(LIBINTL) $(ZLIBS) $(LIBICONV) $(GPG_ERROR_LIBS) $(LIBREADLINE) $(LIBINTL) $(ZLIBS) \
$(LIBICONV) $(extra_sys_libs)
# Make sure that all libs are build before we use them. This is # Make sure that all libs are build before we use them. This is
# important for things like make -j2. # important for things like make -j2.

View File

@ -786,7 +786,7 @@ format_name_writer (void *cookie, const void *buffer, size_t size)
else if (c->len + size < c->len) else if (c->len + size < c->len)
{ {
p = NULL; p = NULL;
errno = ENOMEM; gpg_err_set_errno (ENOMEM);
} }
else if (c->size < c->len + size) else if (c->size < c->len + size)
{ {
@ -804,7 +804,7 @@ format_name_writer (void *cookie, const void *buffer, size_t size)
c->error = errno; c->error = errno;
xfree (c->buffer); xfree (c->buffer);
c->buffer = NULL; c->buffer = NULL;
errno = c->error; gpg_err_set_errno (c->error);
return -1; return -1;
} }
memcpy (p + c->len, buffer, size); memcpy (p + c->len, buffer, size);
@ -834,8 +834,8 @@ gpgsm_format_name2 (const char *name, int translate)
if (!fp) if (!fp)
{ {
int save_errno = errno; int save_errno = errno;
log_error ("error creating memory stream: %s\n", strerror (errno)); log_error ("error creating memory stream: %s\n", strerror (save_errno));
errno = save_errno; gpg_err_set_errno (save_errno);
return NULL; return NULL;
} }
gpgsm_es_print_name2 (fp, name, translate); gpgsm_es_print_name2 (fp, name, translate);
@ -843,7 +843,7 @@ gpgsm_format_name2 (const char *name, int translate)
if (cookie.error || !cookie.buffer) if (cookie.error || !cookie.buffer)
{ {
xfree (cookie.buffer); xfree (cookie.buffer);
errno = cookie.error; gpg_err_set_errno (cookie.error);
return NULL; return NULL;
} }
return cookie.buffer; return cookie.buffer;

View File

@ -561,7 +561,8 @@ print_short_info (ksba_cert_t cert, FILE *fp, estream_t stream)
static gpg_error_t static gpg_error_t
popen_protect_tool (ctrl_t ctrl, const char *pgmname, popen_protect_tool (ctrl_t ctrl, const char *pgmname,
FILE *infile, estream_t outfile, FILE **statusfile, estream_t infile, estream_t outfile,
estream_t *statusfile,
const char *prompt, const char *keygrip, const char *prompt, const char *keygrip,
pid_t *pid) pid_t *pid)
{ {
@ -611,7 +612,8 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen,
gpg_error_t err = 0, child_err = 0; gpg_error_t err = 0, child_err = 0;
int c, cont_line; int c, cont_line;
unsigned int pos; unsigned int pos;
FILE *infp = NULL, *fp = NULL; estream_t infp = NULL;
estream_t fp = NULL;
estream_t outfp = NULL; estream_t outfp = NULL;
char buffer[1024]; char buffer[1024];
pid_t pid = -1; pid_t pid = -1;
@ -622,7 +624,7 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen,
else else
pgmname = opt.protect_tool_program; pgmname = opt.protect_tool_program;
infp = gnupg_tmpfile (); infp = es_tmpfile ();
if (!infp) if (!infp)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -630,7 +632,7 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen,
goto cleanup; goto cleanup;
} }
if (fwrite (certimg, certimglen, 1, infp) != 1) if (es_fwrite (certimg, certimglen, 1, infp) != 1)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
log_error (_("error writing to temporary file: %s\n"), log_error (_("error writing to temporary file: %s\n"),
@ -653,13 +655,13 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen,
pid = -1; pid = -1;
goto cleanup; goto cleanup;
} }
fclose (infp); es_fclose (infp);
infp = NULL; infp = NULL;
/* Read stderr of the protect tool. */ /* Read stderr of the protect tool. */
pos = 0; pos = 0;
cont_line = 0; cont_line = 0;
while ((c=getc (fp)) != EOF) while ((c=es_getc (fp)) != EOF)
{ {
/* fixme: We could here grep for status information of the /* fixme: We could here grep for status information of the
protect tool to figure out better error codes for protect tool to figure out better error codes for
@ -709,10 +711,8 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen,
child_err = gpg_error (GPG_ERR_DECRYPT_FAILED); child_err = gpg_error (GPG_ERR_DECRYPT_FAILED);
cleanup: cleanup:
if (infp) es_fclose (infp);
fclose (infp); es_fclose (fp);
if (fp)
fclose (fp);
if (pid != -1) if (pid != -1)
{ {
if (!gnupg_wait_process (pgmname, pid, NULL)) if (!gnupg_wait_process (pgmname, pid, NULL))
@ -721,9 +721,7 @@ export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen,
if (!err) if (!err)
err = child_err; err = child_err;
if (err) if (err)
{
es_fclose (outfp); es_fclose (outfp);
}
else else
*retfp = outfp; *retfp = outfp;
if (bad_pass) if (bad_pass)

View File

@ -1969,6 +1969,7 @@ static void
emergency_cleanup (void) emergency_cleanup (void)
{ {
gcry_control (GCRYCTL_TERM_SECMEM ); gcry_control (GCRYCTL_TERM_SECMEM );
gnupg_sleep (2);
} }
@ -2105,7 +2106,8 @@ open_fwrite (const char *filename)
fd = check_special_filename (filename, 1); fd = check_special_filename (filename, 1);
if (fd != -1) if (fd != -1)
{ {
fp = fdopen (dup (fd), "wb"); #warning replace the line below
fp = NULL; /*fdopen (dup (fd), "wb"); */
if (!fp) if (!fp)
{ {
log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno)); log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno));

View File

@ -1,5 +1,5 @@
/* import.c - Import certificates /* import.c - Import certificates
* Copyright (C) 2001, 2003, 2004, 2009 Free Software Foundation, Inc. * Copyright (C) 2001, 2003, 2004, 2009, 2010 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -578,14 +578,14 @@ gpgsm_import_files (ctrl_t ctrl, int nfiles, char **files,
} }
/* Fork and exec the protecttool, connect the file descriptor of /* Fork and exec the protect tool, connect the file descriptor of
INFILE to stdin, return a new stream in STATUSFILE, write the INFILE to stdin, return a new estream in STATUSFILE, write the
output to OUTFILE and the pid of the process in PID. Returns 0 on output to OUTFILE and the pid of the process in PID. Returns 0 on
success or an error code. */ success or an error code. */
static gpg_error_t static gpg_error_t
popen_protect_tool (ctrl_t ctrl, const char *pgmname, popen_protect_tool (ctrl_t ctrl, const char *pgmname,
FILE *infile, estream_t outfile, estream_t infile, estream_t outfile,
FILE **statusfile, pid_t *pid) estream_t *statusfile, pid_t *pid)
{ {
const char *argv[22]; const char *argv[22];
int i=0; int i=0;
@ -637,7 +637,8 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader,
gpg_error_t err = 0, child_err = 0; gpg_error_t err = 0, child_err = 0;
int c, cont_line; int c, cont_line;
unsigned int pos; unsigned int pos;
FILE *tmpfp, *fp = NULL; estream_t tmpfp;
estream_t fp = NULL;
estream_t certfp = NULL; estream_t certfp = NULL;
char buffer[1024]; char buffer[1024];
size_t nread; size_t nread;
@ -655,7 +656,7 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader,
gpg-protect-tool will anyway parse the entire pkcs#12 message in gpg-protect-tool will anyway parse the entire pkcs#12 message in
memory, we simply use tempfiles here and pass them to memory, we simply use tempfiles here and pass them to
the gpg-protect-tool. */ the gpg-protect-tool. */
tmpfp = gnupg_tmpfile (); tmpfp = es_tmpfile ();
if (!tmpfp) if (!tmpfp)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -664,7 +665,7 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader,
} }
while (!(err = ksba_reader_read (reader, buffer, sizeof buffer, &nread))) while (!(err = ksba_reader_read (reader, buffer, sizeof buffer, &nread)))
{ {
if (nread && fwrite (buffer, nread, 1, tmpfp) != 1) if (nread && es_fwrite (buffer, nread, 1, tmpfp) != 1)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
log_error (_("error writing to temporary file: %s\n"), log_error (_("error writing to temporary file: %s\n"),
@ -694,13 +695,13 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader,
pid = -1; pid = -1;
goto cleanup; goto cleanup;
} }
fclose (tmpfp); es_fclose (tmpfp);
tmpfp = NULL; tmpfp = NULL;
/* Read stderr of the protect tool. */ /* Read stderr of the protect tool. */
pos = 0; pos = 0;
cont_line = 0; cont_line = 0;
while ((c=getc (fp)) != EOF) while ((c=es_getc (fp)) != EOF)
{ {
/* fixme: We could here grep for status information of the /* fixme: We could here grep for status information of the
protect tool to figure out better error codes for protect tool to figure out better error codes for
@ -768,10 +769,8 @@ parse_p12 (ctrl_t ctrl, ksba_reader_t reader,
child_err = gpg_error (GPG_ERR_DECRYPT_FAILED); child_err = gpg_error (GPG_ERR_DECRYPT_FAILED);
cleanup: cleanup:
if (tmpfp) es_fclose (tmpfp);
fclose (tmpfp); es_fclose (fp);
if (fp)
fclose (fp);
if (pid != -1) if (pid != -1)
{ {
if (!gnupg_wait_process (pgmname, pid, NULL)) if (!gnupg_wait_process (pgmname, pid, NULL))

View File

@ -161,7 +161,11 @@ gpgsm_is_in_qualified_list (ctrl_t ctrl, ksba_cert_t cert, char *country)
return gpg_error (GPG_ERR_GENERAL); return gpg_error (GPG_ERR_GENERAL);
if (listfp) if (listfp)
rewind (listfp); {
/* W32ce has no rewind, thus we use the equivalent code. */
fseek (listfp, 0, SEEK_SET);
clearerr (listfp);
}
while (!(err = read_list (key, mycountry, &lnr))) while (!(err = read_list (key, mycountry, &lnr)))
{ {
if (!strcmp (key, fpr)) if (!strcmp (key, fpr))

View File

@ -136,7 +136,7 @@ data_line_cookie_write (void *cookie, const void *buffer, size_t size)
if (assuan_send_data (ctx, buffer, size)) if (assuan_send_data (ctx, buffer, size))
{ {
errno = EIO; gpg_err_set_errno (EIO);
return -1; return -1;
} }
@ -150,7 +150,7 @@ data_line_cookie_close (void *cookie)
if (assuan_send_data (ctx, NULL, 0)) if (assuan_send_data (ctx, NULL, 0))
{ {
errno = EIO; gpg_err_set_errno (EIO);
return -1; return -1;
} }