aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog25
-rw-r--r--src/Makefile.am2
-rw-r--r--src/assuan-defs.h10
-rw-r--r--src/assuan-handler.c4
-rw-r--r--src/assuan-logging.c2
-rw-r--r--src/assuan-socket-server.c7
-rw-r--r--src/assuan-socket.c5
-rw-r--r--src/assuan.h9
-rw-r--r--src/system.c12
-rw-r--r--src/sysutils.c130
10 files changed, 198 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 098f3f5..3cc263a 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,24 @@
+2010-01-28 Werner Koch <[email protected]>
+
+ * assuan.h: Remove ranges in list of copyright years.
+ (getenv) [W32CE]: Provide macro.
+ * sysutils.c: New.
+ (_assuan_sysutils_blurb): New.
+ (_assuan_getenv): new.
+ * assuan-logging.c: Call _assuan_sysutils_blurb.
+
+2010-01-27 Werner Koch <[email protected]>
+
+ * assuan-socket.c (_assuan_sock_bind): Replace remove by DeleteFile.
+
+ * assuan-handler.c (assuan_get_active_fds) [W32CE]: Remove use of
+ _get_osfhandle.
+ * assuan.h (assuan_fd_from_posix_fd) [__MINGW32CE__]: Ditto.
+ * system.c (assuan_fdopen): Ditto.
+ (__assuan_spawn) [W32CE]: Do not use GetPriorityClass.
+
+ * assuan-defs.h (getpid) [W32CE]: New.
+
2010-01-22 Werner Koch <[email protected]>
* setenv.c [W32CE]: Make it a dummy.
@@ -691,7 +712,7 @@
2007-10-04 Werner Koch <[email protected]>
* mkerrors: Map EAGAIN to GPG_ERR_EAGAIN for read and write
- errors.
+ errors.
2007-10-02 Werner Koch <[email protected]>
@@ -707,7 +728,7 @@
* assuan.h (ASSUAN_INT2FD, ASSUAN_FD2INT): New.
* assuan-socket.c: Rewritten.
- (assuan_sock_new, assuan_sock_connect, assuan_sock_bind)
+ (assuan_sock_new, assuan_sock_connect, assuan_sock_bind)
(assuan_sock_get_nonce, assuan_sock_check_nonce): New APIs.
* assuan-io.c (_assuan_simple_read, _assuan_simple_write):
diff --git a/src/Makefile.am b/src/Makefile.am
index d2f1af0..5895bc5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,7 +37,7 @@ endif
common_sources = \
assuan-defs.h \
assuan.c context.c system.c \
- debug.c debug.h conversion.c \
+ debug.c debug.h conversion.c sysutils.c \
client.c server.c \
assuan-error.c \
assuan-buffer.c \
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index 5e61bcb..1f288f4 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -335,6 +335,16 @@ FILE *_assuan_funopen(void *cookie,
#define funopen(a,r,w,s,c) _assuan_funopen ((a), (r), (w), (s), (c))
#endif /*HAVE_FOPENCOOKIE*/
+/*-- sysutils.c --*/
+const char *_assuan_sysutils_blurb (void);
+
+#ifdef HAVE_W32CE_SYSTEM
+#define getpid() GetCurrentProcessId ()
+char *_assuan_getenv (const char *name);
+#define getenv(a) _assuan_getenv ((a))
+#endif
+
+
/* Prototypes for replacement functions. */
#ifndef HAVE_MEMRCHR
void *memrchr (const void *block, int c, size_t size);
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index f77d59b..eacbeb3 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -811,7 +811,9 @@ assuan_get_active_fds (assuan_context_t ctx, int what,
if (ctx->outbound.fd != ASSUAN_INVALID_FD)
fdarray[n++] = ctx->outbound.fd;
if (ctx->outbound.data.fp)
-#ifdef HAVE_W32_SYSTEM
+#if defined(HAVE_W32CE_SYSTEM)
+ fdarray[n++] = (void*)fileno (ctx->outbound.data.fp);
+#elif defined(HAVE_W32_SYSTEM)
fdarray[n++] = (void*)_get_osfhandle (fileno (ctx->outbound.data.fp));
#else
fdarray[n++] = fileno (ctx->outbound.data.fp);
diff --git a/src/assuan-logging.c b/src/assuan-logging.c
index 13af63a..b7b3895 100644
--- a/src/assuan-logging.c
+++ b/src/assuan-logging.c
@@ -65,6 +65,8 @@ assuan_set_assuan_log_stream (FILE *fp)
flagstr = getenv ("ASSUAN_DEBUG");
if (flagstr)
log_cats = atoi (flagstr);
+
+ _assuan_sysutils_blurb (); /* Make sure this code gets linked in. */
}
diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c
index 84b980e..031ee88 100644
--- a/src/assuan-socket-server.c
+++ b/src/assuan-socket-server.c
@@ -46,6 +46,8 @@ accept_connection_bottom (assuan_context_t ctx)
{
assuan_fd_t fd = ctx->connected_fd;
+ TRACE (ctx, ASSUAN_LOG_SYSIO, "accept_connection_bottom", ctx);
+
ctx->peercred_valid = 0;
#ifdef HAVE_SO_PEERCRED
{
@@ -90,12 +92,17 @@ accept_connection (assuan_context_t ctx)
struct sockaddr_un clnt_addr;
socklen_t len = sizeof clnt_addr;
+ TRACE1 (ctx, ASSUAN_LOG_SYSIO, "accept_connection", ctx,
+ "listen_fd=0x%x", ctx->listen_fd);
+
fd = SOCKET2HANDLE(accept (HANDLE2SOCKET(ctx->listen_fd),
(struct sockaddr*)&clnt_addr, &len ));
if (fd == ASSUAN_INVALID_FD)
{
return _assuan_error (ctx, gpg_err_code_from_syserror ());
}
+ TRACE1 (ctx, ASSUAN_LOG_SYSIO, "accept_connection", ctx,
+ "fd->0x%x", fd);
if (_assuan_sock_check_nonce (ctx, fd, &ctx->listen_nonce))
{
_assuan_close (ctx, fd);
diff --git a/src/assuan-socket.c b/src/assuan-socket.c
index 6a8954d..ca0609a 100644
--- a/src/assuan-socket.c
+++ b/src/assuan-socket.c
@@ -38,6 +38,7 @@
#include <assert.h>
#include "assuan-defs.h"
+#include "debug.h"
/* Hacks for Slowaris. */
#ifndef PF_LOCAL
@@ -268,7 +269,7 @@ _assuan_sock_bind (assuan_context_t ctx, assuan_fd_t sockfd,
{
int save_e = errno;
fclose (fp);
- remove (unaddr->sun_path);
+ DeleteFile (unaddr->sun_path);
gpg_err_set_errno (save_e);
return rc;
}
@@ -313,7 +314,7 @@ _assuan_sock_get_nonce (assuan_context_t ctx, struct sockaddr *addr,
}
else
{
- nonce->length = 42; /* Arbitrary valuie to detect unitialized nonce. */
+ nonce->length = 42; /* Arbitrary value to detect unitialized nonce. */
nonce->nonce[0] = 42;
}
#else
diff --git a/src/assuan.h b/src/assuan.h
index 0cd943b..ebc4bae 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -1,5 +1,6 @@
/* assuan.h - Definitions for the Assuan IPC library
- Copyright (C) 2001-2003, 2005, 2007-2009 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2003, 2005, 2007, 2008, 2009,
+ 2010 Free Software Foundation, Inc.
This file is part of Assuan.
@@ -88,10 +89,14 @@ typedef void *assuan_fd_t;
static inline assuan_fd_t
assuan_fd_from_posix_fd (int fd)
{
+#ifdef __MINGW32CE__
+ return (assuan_fd_t)(fd);
+#else
if (fd < 0)
return ASSUAN_INVALID_FD;
else
return (assuan_fd_t) _get_osfhandle (fd);
+#endif
}
#else
typedef int assuan_fd_t;
@@ -109,7 +114,7 @@ assuan_fd_t assuan_fdopen (int fd);
/* Assuan features an emulation of Unix domain sockets based on a
local TCP connections. To implement access permissions based on
- file permissions a nonce is used which is expected by th server as
+ file permissions a nonce is used which is expected by the server as
the first bytes received. This structure is used by the server to
save the nonce created initially by bind. On POSIX systems this is
a dummy operation. */
diff --git a/src/system.c b/src/system.c
index 45f1d9a..09c2b8c 100644
--- a/src/system.c
+++ b/src/system.c
@@ -50,7 +50,11 @@ assuan_fd_t
assuan_fdopen (int fd)
{
#ifdef HAVE_W32_SYSTEM
+#ifdef HAVE_W32CE_SYSTEM
+ assuan_fd_t ifd = (assuan_fd_t)fd;
+#else
assuan_fd_t ifd = (assuan_fd_t) _get_osfhandle (fd);
+#endif
assuan_fd_t ofd;
if (! DuplicateHandle(GetCurrentProcess(), ifd,
@@ -199,6 +203,11 @@ __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
sec_attr.nLength = sizeof (sec_attr);
sec_attr.bInheritHandle = FALSE;
+#ifdef HAVE_W32CE_SYSTEM
+# warning Implement a CreatePipe Replacement.
+ gpg_err_set_errno (EIO);
+ return -1;
+#else
if (! CreatePipe (&rh, &wh, &sec_attr, 0))
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx,
@@ -206,6 +215,7 @@ __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
gpg_err_set_errno (EIO);
return -1;
}
+#endif
if (! DuplicateHandle (GetCurrentProcess(), (inherit_idx == 0) ? rh : wh,
GetCurrentProcess(), &th, 0,
@@ -663,7 +673,9 @@ __assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
TRUE, /* Inherit handles. */
(CREATE_DEFAULT_ERROR_MODE
| ((flags & 128)? DETACHED_PROCESS : 0)
+#ifndef HAVE_W32CE_SYSTEM
| GetPriorityClass (GetCurrentProcess ())
+#endif
| CREATE_SUSPENDED), /* Creation flags. */
NULL, /* Environment. */
NULL, /* Use current drive/directory. */
diff --git a/src/sysutils.c b/src/sysutils.c
new file mode 100644
index 0000000..448f803
--- /dev/null
+++ b/src/sysutils.c
@@ -0,0 +1,130 @@
+/* sysutils.c - System utilities
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ Assuan is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ Assuan is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#ifdef HAVE_W32_SYSTEM
+#include <windows.h>
+#endif /*HAVE_W32_SYSTEM*/
+
+#include "assuan-defs.h"
+
+
+/* This is actually a dummy function to make sure that is module is
+ not empty. Sokme compilers barf on that. */
+const char *
+_assuan_sysutils_blurb (void)
+{
+ static const char blurb[] =
+ "\n\n"
+ "This is Libassuan - The GnuPG IPC Library\n"
+ "Copyright 2000, 2002, 2003, 2004, 2007, 2008, 2009,\n"
+ " 2010 Free Software Foundation, Inc.\n"
+ "\n\n";
+ return blurb;
+}
+
+
+/* Return a string from the Win32 Registry or NULL in case of error.
+ The returned string is allocated using a plain malloc and thus the
+ caller needs to call the standard free(). The string is looked up
+ under HKEY_LOCAL_MACHINE. */
+#ifdef HAVE_W32CE_SYSTEM
+static char *
+w32_read_registry (const wchar_t *dir, const wchar_t *name)
+{
+ HKEY handle;
+ DWORD n, nbytes;
+ wchar_t *buffer = NULL;
+ char *result = NULL;
+
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &handle))
+ return NULL; /* No need for a RegClose, so return immediately. */
+
+ nbytes = 1;
+ if (RegQueryValueEx (handle, name, 0, NULL, NULL, &nbytes))
+ goto leave;
+ buffer = malloc ((n=nbytes+2));
+ if (!buffer)
+ goto leave;
+ if (RegQueryValueEx (handle, name, 0, NULL, (PBYTE)buffer, &n))
+ {
+ free (buffer);
+ buffer = NULL;
+ goto leave;
+ }
+
+ n = WideCharToMultiByte (CP_UTF8, 0, buffer, nbytes, NULL, 0, NULL, NULL);
+ if (n < 0 || (n+1) <= 0)
+ goto leave;
+ result = malloc (n+1);
+ if (!result)
+ goto leave;
+ n = WideCharToMultiByte (CP_UTF8, 0, buffer, nbytes, result, n, NULL, NULL);
+ if (n < 0)
+ {
+ free (result);
+ result = NULL;
+ goto leave;
+ }
+ result[n] = 0;
+
+ leave:
+ free (buffer);
+ RegCloseKey (handle);
+ return result;
+}
+#endif /*HAVE_W32CE_SYSTEM*/
+
+
+
+#ifdef HAVE_W32CE_SYSTEM
+/* Replacement for getenv which takes care of the our use of getenv.
+ The code is not thread safe but we expect it to work in all cases
+ because it is called for the first time early enough. */
+char *
+_assuan_getenv (const char *name)
+{
+ static int initialized;
+ static char *val_debug;
+ static char *val_full_logging;
+
+ if (!initialized)
+ {
+ val_debug = w32_read_registry (L"\\Software\\GNU\\libassuan",
+ L"debug");
+ val_full_logging = w32_read_registry (L"\\Software\\GNU\\libassuan",
+ L"full_logging");
+ initialized = 1;
+ }
+
+
+ if (!strcmp (name, "ASSUAN_DEBUG"))
+ return val_debug;
+ else if (!strcmp (name, "ASSUAN_FULL_LOGGING"))
+ return val_full_logging;
+ else
+ return NULL;
+}
+#endif /*HAVE_W32CE_SYSTEM*/