aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/estream.c3
-rw-r--r--common/homedir.c39
-rw-r--r--common/http.c3
-rw-r--r--common/init.c7
-rw-r--r--common/iobuf.c69
-rw-r--r--common/sysutils.c27
-rw-r--r--common/ttyio.c43
7 files changed, 107 insertions, 84 deletions
diff --git a/common/estream.c b/common/estream.c
index 3b6139eb2..9c781a0f1 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -79,6 +79,9 @@
#include <stddef.h>
#include <assert.h>
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#endif
#ifdef HAVE_W32CE_SYSTEM
diff --git a/common/homedir.c b/common/homedir.c
index d0fc5c631..5adf46a62 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -23,6 +23,9 @@
#include <fcntl.h>
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
#include <shlobj.h>
#ifndef CSIDL_APPDATA
#define CSIDL_APPDATA 0x001a
@@ -97,7 +100,7 @@ standard_homedir (void)
if (!dir)
{
char path[MAX_PATH];
-
+
/* It might be better to use LOCAL_APPDATA because this is
defined as "non roaming" and thus more likely to be kept
locally. For private keys this is desired. However, given
@@ -105,13 +108,13 @@ standard_homedir (void)
using a system roaming services might be better than to let
them do it manually. A security conscious user will anyway
use the registry entry to have better control. */
- if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE,
- NULL, 0, path) >= 0)
+ if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE,
+ NULL, 0, path) >= 0)
{
char *tmp = xmalloc (strlen (path) + 6 +1);
strcpy (stpcpy (tmp, path), "\\gnupg");
dir = tmp;
-
+
/* Try to create the directory if it does not yet exists. */
if (access (dir, F_OK))
CreateDirectory (dir, NULL);
@@ -137,7 +140,7 @@ default_homedir (void)
if (!dir || !*dir)
{
static const char *saved_dir;
-
+
if (!saved_dir)
{
if (!dir || !*dir)
@@ -154,7 +157,7 @@ default_homedir (void)
if (tmp)
saved_dir = tmp;
}
-
+
if (!saved_dir)
saved_dir = standard_homedir ();
}
@@ -191,7 +194,7 @@ w32_rootdir (void)
else
{
log_debug ("bad filename `%s' returned for this process\n", dir);
- *dir = 0;
+ *dir = 0;
}
}
@@ -210,8 +213,8 @@ w32_commondir (void)
{
char path[MAX_PATH];
- if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA,
- NULL, 0, path) >= 0)
+ if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA,
+ NULL, 0, path) >= 0)
{
char *tmp = xmalloc (strlen (path) + 4 +1);
strcpy (stpcpy (tmp, path), "\\GNU");
@@ -226,7 +229,7 @@ w32_commondir (void)
dir = xstrdup (w32_rootdir ());
}
}
-
+
return dir;
}
#endif /*HAVE_W32_SYSTEM*/
@@ -388,42 +391,42 @@ gnupg_module_name (int which)
strcpy (stpcpy (name, s), s2); \
} \
return name; \
- } while (0)
+ } while (0)
switch (which)
{
case GNUPG_MODULE_NAME_AGENT:
#ifdef GNUPG_DEFAULT_AGENT
return GNUPG_DEFAULT_AGENT;
-#else
+#else
X(bindir, "gpg-agent");
#endif
-
+
case GNUPG_MODULE_NAME_PINENTRY:
#ifdef GNUPG_DEFAULT_PINENTRY
return GNUPG_DEFAULT_PINENTRY;
-#else
+#else
X(bindir, "pinentry");
#endif
case GNUPG_MODULE_NAME_SCDAEMON:
#ifdef GNUPG_DEFAULT_SCDAEMON
return GNUPG_DEFAULT_SCDAEMON;
-#else
+#else
X(libexecdir, "scdaemon");
#endif
case GNUPG_MODULE_NAME_DIRMNGR:
#ifdef GNUPG_DEFAULT_DIRMNGR
return GNUPG_DEFAULT_DIRMNGR;
-#else
+#else
X(bindir, "dirmngr");
#endif
case GNUPG_MODULE_NAME_PROTECT_TOOL:
#ifdef GNUPG_DEFAULT_PROTECT_TOOL
return GNUPG_DEFAULT_PROTECT_TOOL;
-#else
+#else
X(libexecdir, "gpg-protect-tool");
#endif
@@ -442,7 +445,7 @@ gnupg_module_name (int which)
case GNUPG_MODULE_NAME_GPGCONF:
X(bindir, "gpgconf");
- default:
+ default:
BUG ();
}
#undef X
diff --git a/common/http.c b/common/http.c
index 49859fa02..15d64c496 100644
--- a/common/http.c
+++ b/common/http.c
@@ -46,6 +46,9 @@
#include <unistd.h>
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#else /*!HAVE_W32_SYSTEM*/
# include <sys/types.h>
diff --git a/common/init.c b/common/init.c
index 5425acee8..7be8af062 100644
--- a/common/init.c
+++ b/common/init.c
@@ -25,9 +25,12 @@
#endif
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
#include <windows.h>
#endif
-#ifdef HAVE_PTH
+#ifdef HAVE_PTH
#include <pth.h>
#endif
@@ -46,7 +49,7 @@ void
init_common_subsystems (void)
{
/* Try to auto set the character set. */
- set_native_charset (NULL);
+ set_native_charset (NULL);
#ifdef HAVE_W32_SYSTEM
/* For W32 we need to initialize the socket layer. This is because
diff --git a/common/iobuf.c b/common/iobuf.c
index 04b17ff17..1a84f3f41 100644
--- a/common/iobuf.c
+++ b/common/iobuf.c
@@ -30,6 +30,9 @@
#include <fcntl.h>
#include <unistd.h>
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#endif
#ifdef __riscos__
@@ -43,7 +46,7 @@
/*-- Begin configurable part. --*/
-/* The size of the internal buffers.
+/* The size of the internal buffers.
NOTE: If you change this value you MUST also adjust the regression
test "armored_key_8192" in armor.test! */
#define IOBUF_BUFFER_SIZE 8192
@@ -66,15 +69,15 @@
implementation. What we define here are 3 macros to make the
appropriate calls:
- my_fileno
+ my_fileno
Is expanded to fileno(a) if using a stdion backend and to a if we
are using the low-level backend.
- my_fopen
+ my_fopen
Is defined to fopen for the stdio backend and to direct_open if
we are using the low-evel backend.
- my_fopen_ro
+ my_fopen_ro
Is defined to fopen for the stdio backend and to fd_cache_open if
we are using the low-evel backend.
@@ -117,7 +120,7 @@
typedef struct
{
fp_or_fd_t fp; /* Open file pointer or handle. */
- int keep_open;
+ int keep_open;
int no_cache;
int eof_seen;
int print_only_name; /* Flags indicating that fname is not a real file. */
@@ -196,7 +199,7 @@ fd_cache_strcmp (const char *a, const char *b)
#ifdef HAVE_DOSISH_SYSTEM
for (; *a && *b; a++, b++)
{
- if (*a != *b && !((*a == '/' && *b == '\\')
+ if (*a != *b && !((*a == '/' && *b == '\\')
|| (*a == '\\' && *b == '/')) )
break;
}
@@ -353,7 +356,7 @@ direct_open (const char *fname, const char *mode)
/*
- * Instead of closing an FD we keep it open and cache it for later reuse
+ * Instead of closing an FD we keep it open and cache it for later reuse
* Note that this caching strategy only works if the process does not chdir.
*/
static void
@@ -477,13 +480,13 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
{
assert (size); /* We need a buffer. */
if (feof (f))
- {
+ {
/* On terminals you could easily read as many EOFs as you
call fread() or fgetc() repeatly. Every call will block
until you press CTRL-D. So we catch this case before we
call fread() again. */
- rc = -1;
- *ret_len = 0;
+ rc = -1;
+ *ret_len = 0;
}
else
{
@@ -891,7 +894,7 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer,
/* log_debug("partial: ctx=%p c=%02x size=%u\n", a, c, a->size); */
}
else
- BUG ();
+ BUG ();
}
while (!rc && size && a->size)
@@ -1506,7 +1509,7 @@ iobuf_ioctl (iobuf_t a, int cmd, int intval, void *ptrval)
{ /* keep system filepointer/descriptor open */
if (DBG_IOBUF)
log_debug ("iobuf-%d.%d: ioctl `%s' keep=%d\n",
- a ? a->no : -1, a ? a->subno : -1,
+ a ? a->no : -1, a ? a->subno : -1,
a && a->desc ? a->desc : "?",
intval);
for (; a; a = a->chain)
@@ -1543,7 +1546,7 @@ iobuf_ioctl (iobuf_t a, int cmd, int intval, void *ptrval)
{ /* disallow/allow caching */
if (DBG_IOBUF)
log_debug ("iobuf-%d.%d: ioctl `%s' no_cache=%d\n",
- a ? a->no : -1, a ? a->subno : -1,
+ a ? a->no : -1, a ? a->subno : -1,
a && a->desc? a->desc : "?",
intval);
for (; a; a = a->chain)
@@ -1663,7 +1666,7 @@ iobuf_push_filter2 (iobuf_t a,
if (DBG_IOBUF)
{
- log_debug ("iobuf-%d.%d: push `%s'\n", a->no, a->subno,
+ log_debug ("iobuf-%d.%d: push `%s'\n", a->no, a->subno,
a->desc?a->desc:"?");
print_chain (a);
}
@@ -2170,24 +2173,24 @@ iobuf_get_filelength (iobuf_t a, int *overflow)
if (overflow)
*overflow = 0;
-
- if ( a->directfp )
+
+ if ( a->directfp )
{
FILE *fp = a->directfp;
-
+
if ( !fstat(fileno(fp), &st) )
return st.st_size;
log_error("fstat() failed: %s\n", strerror(errno) );
return 0;
}
-
+
/* Hmmm: file_filter may have already been removed */
for ( ; a; a = a->chain )
if ( !a->chain && a->filter == file_filter )
{
file_filter_ctx_t *b = a->filter_ov;
fp_or_fd_t fp = b->fp;
-
+
#if defined(HAVE_W32_SYSTEM) && !defined(FILE_FILTER_USES_STDIO)
ulong size;
static int (* __stdcall get_file_size_ex) (void *handle,
@@ -2197,7 +2200,7 @@ iobuf_get_filelength (iobuf_t a, int *overflow)
if (!get_file_size_ex_initialized)
{
void *handle;
-
+
handle = dlopen ("kernel32.dll", RTLD_LAZY);
if (handle)
{
@@ -2207,21 +2210,21 @@ iobuf_get_filelength (iobuf_t a, int *overflow)
}
get_file_size_ex_initialized = 1;
}
-
+
if (get_file_size_ex)
{
/* This is a newer system with GetFileSizeEx; we use this
then because it seem that GetFileSize won't return a
proper error in case a file is larger than 4GB. */
LARGE_INTEGER exsize;
-
+
if (get_file_size_ex (fp, &exsize))
{
if (!exsize.u.HighPart)
return exsize.u.LowPart;
if (overflow)
*overflow = 1;
- return 0;
+ return 0;
}
}
else
@@ -2238,14 +2241,14 @@ iobuf_get_filelength (iobuf_t a, int *overflow)
#endif
break/*the for loop*/;
}
-
+
return 0;
}
/* Return the file descriptor of the underlying file or -1 if it is
not available. */
-int
+int
iobuf_get_fd (iobuf_t a)
{
if (a->directfp)
@@ -2518,7 +2521,7 @@ translate_file_handle (int fd, int for_write)
# else
{
int x;
-
+
(void)for_write;
if (fd == 0)
@@ -2551,13 +2554,13 @@ iobuf_skip_rest (iobuf_t a, unsigned long n, int partial)
{
for (;;)
{
- if (a->nofast || a->d.start >= a->d.len)
+ if (a->nofast || a->d.start >= a->d.len)
{
if (iobuf_readbyte (a) == -1)
{
break;
}
- }
+ }
else
{
unsigned long count = a->d.len - a->d.start;
@@ -2565,11 +2568,11 @@ iobuf_skip_rest (iobuf_t a, unsigned long n, int partial)
a->d.start = a->d.len;
}
}
- }
+ }
else
{
unsigned long remaining = n;
- while (remaining > 0)
+ while (remaining > 0)
{
if (a->nofast || a->d.start >= a->d.len)
{
@@ -2578,11 +2581,11 @@ iobuf_skip_rest (iobuf_t a, unsigned long n, int partial)
break;
}
--remaining;
- }
- else
+ }
+ else
{
unsigned long count = a->d.len - a->d.start;
- if (count > remaining)
+ if (count > remaining)
{
count = remaining;
}
diff --git a/common/sysutils.c b/common/sysutils.c
index 8e0c75c1a..82bc81f56 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -43,10 +43,15 @@
# include <sys/resource.h>
#endif
#ifdef HAVE_W32_SYSTEM
-# define WINVER 0x0500 /* Required for AllowSetForegroundWindow. */
+# ifndef WINVER
+# define WINVER 0x0500 /* Required for AllowSetForegroundWindow. */
+# endif
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#endif
-#ifdef HAVE_PTH
+#ifdef HAVE_PTH
# include <pth.h>
#endif
#include <fcntl.h>
@@ -144,8 +149,8 @@ get_session_marker( size_t *rlen )
initialized = 1;
/* Although this marker is guessable it is not easy to use
* for a faked control packet because an attacker does not
- * have enough control about the time the verification does
- * take place. Of course, we can add just more random but
+ * have enough control about the time the verification does
+ * take place. Of course, we can add just more random but
* than we need the random generator even for verification
* tasks - which does not make sense. */
a = aa ^ (ulong)getpid();
@@ -260,7 +265,7 @@ gnupg_sleep (unsigned int seconds)
the process will give up its timeslot. */
if (!seconds)
{
-# ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_W32_SYSTEM
Sleep (0);
# else
sleep (0);
@@ -269,7 +274,7 @@ gnupg_sleep (unsigned int seconds)
pth_sleep (seconds);
#else
/* Fixme: make sure that a sleep won't wake up to early. */
-# ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_W32_SYSTEM
Sleep (seconds*1000);
# else
sleep (seconds);
@@ -291,7 +296,7 @@ translate_sys2libc_fd (gnupg_fd_t fd, int for_write)
if (fd == GNUPG_INVALID_FD)
return -1;
-
+
/* Note that _open_osfhandle is currently defined to take and return
a long. */
x = _open_osfhandle ((long)fd, for_write ? 1 : 0);
@@ -414,7 +419,7 @@ gnupg_tmpfile (void)
Must be called before we open any files! */
void
gnupg_reopen_std (const char *pgmname)
-{
+{
#if defined(HAVE_STAT) && !defined(HAVE_W32_SYSTEM)
struct stat statbuf;
int did_stdin = 0;
@@ -429,7 +434,7 @@ gnupg_reopen_std (const char *pgmname)
else
did_stdin = 2;
}
-
+
if (fstat (STDOUT_FILENO, &statbuf) == -1 && errno == EBADF)
{
if (open ("/dev/null",O_WRONLY) == STDOUT_FILENO)
@@ -478,13 +483,13 @@ gnupg_reopen_std (const char *pgmname)
/* Hack required for Windows. */
-void
+void
gnupg_allow_set_foregound_window (pid_t pid)
{
if (!pid)
log_info ("%s called with invalid pid %lu\n",
"gnupg_allow_set_foregound_window", (unsigned long)pid);
-#ifdef HAVE_W32_SYSTEM
+#ifdef HAVE_W32_SYSTEM
else if (!AllowSetForegroundWindow ((pid_t)pid == (pid_t)(-1)?ASFW_ANY:pid))
log_info ("AllowSetForegroundWindow(%lu) failed: %s\n",
(unsigned long)pid, w32_strerror (-1));
diff --git a/common/ttyio.c b/common/ttyio.c
index fc274070c..e70a205ba 100644
--- a/common/ttyio.c
+++ b/common/ttyio.c
@@ -25,23 +25,26 @@
#include <stdarg.h>
#include <unistd.h>
#ifdef HAVE_TCGETATTR
-#include <termios.h>
+# include <termios.h>
#else
-#ifdef HAVE_TERMIO_H
-/* simulate termios with termio */
-#include <termio.h>
-#define termios termio
-#define tcsetattr ioctl
-#define TCSAFLUSH TCSETAF
-#define tcgetattr(A,B) ioctl(A,TCGETA,B)
-#define HAVE_TCGETATTR
-#endif
+# ifdef HAVE_TERMIO_H
+ /* Simulate termios with termio. */
+# include <termio.h>
+# define termios termio
+# define tcsetattr ioctl
+# define TCSAFLUSH TCSETAF
+# define tcgetattr(A,B) ioctl(A,TCGETA,B)
+# define HAVE_TCGETATTR
+# endif
#endif
#ifdef _WIN32 /* use the odd Win32 functions */
-#include <windows.h>
-#ifdef HAVE_TCGETATTR
-#error mingw32 and termios
-#endif
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
+# include <windows.h>
+# ifdef HAVE_TCGETATTR
+# error mingw32 and termios
+# endif
#endif
#include <errno.h>
#include <ctype.h>
@@ -179,7 +182,7 @@ init_ttyfp(void)
if (my_rl_init_stream)
my_rl_init_stream (ttyfp);
#endif
-
+
#ifdef HAVE_TCGETATTR
atexit( cleanup );
@@ -218,7 +221,7 @@ tty_printf( const char *fmt, ... )
va_start( arg_ptr, fmt ) ;
#ifdef _WIN32
- {
+ {
char *buf = NULL;
int n;
DWORD nwritten;
@@ -226,7 +229,7 @@ tty_printf( const char *fmt, ... )
n = vasprintf(&buf, fmt, arg_ptr);
if( !buf )
log_bug("vasprintf() failed\n");
-
+
if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) )
log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
if( n != nwritten )
@@ -265,7 +268,7 @@ tty_fprintf (FILE *fp, const char *fmt, ... )
va_start( arg_ptr, fmt ) ;
#ifdef _WIN32
- {
+ {
char *buf = NULL;
int n;
DWORD nwritten;
@@ -273,7 +276,7 @@ tty_fprintf (FILE *fp, const char *fmt, ... )
n = vasprintf(&buf, fmt, arg_ptr);
if( !buf )
log_bug("vasprintf() failed\n");
-
+
if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) )
log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
if( n != nwritten )
@@ -531,7 +534,7 @@ tty_get( const char *prompt )
{
char *line;
char *buf;
-
+
if (!initialized)
init_ttyfp();