diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/ath.c | 8 | ||||
-rw-r--r-- | src/ath.h | 3 | ||||
-rw-r--r-- | src/data-compat.c | 8 | ||||
-rw-r--r-- | src/data-fd.c | 56 | ||||
-rw-r--r-- | src/debug.c | 14 | ||||
-rw-r--r-- | src/debug.h | 4 | ||||
-rw-r--r-- | src/gpgme-tool.c | 15 | ||||
-rw-r--r-- | src/priv-io.h | 3 | ||||
-rw-r--r-- | src/util.h | 11 | ||||
-rw-r--r-- | src/w32-ce.c | 507 | ||||
-rw-r--r-- | src/w32-ce.h | 91 | ||||
-rw-r--r-- | src/w32-io.c | 307 | ||||
-rw-r--r-- | src/w32-util.c | 79 |
14 files changed, 12 insertions, 1103 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 1394c028..276d9767 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,10 +50,6 @@ system_components = ath.h posix-util.c posix-io.c system_components_not_extra = endif -if HAVE_W32CE_SYSTEM -system_components += w32-ce.h w32-ce.c -endif - if HAVE_UISERVER uiserver_components = engine-uiserver.c else @@ -111,12 +107,7 @@ if HAVE_W32_SYSTEM # Windows provides us with an endless stream of Tough Love. To spawn # processes with a controlled set of inherited handles, we need a # wrapper process. -# Except on Windows CE. There nothing is inheritable anyway. -if HAVE_W32CE_SYSTEM -libexec_PROGRAMS = -else libexec_PROGRAMS = gpgme-w32spawn -endif RCCOMPILE = $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) LTRCCOMPILE = $(LIBTOOL) --mode=compile --tag=RC $(RCCOMPILE) @@ -78,22 +78,14 @@ ath_self (void) gpgme_ssize_t ath_read (int fd, void *buf, size_t nbytes) { -#if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER) - return -1; /* Not supported. */ -#else return read (fd, buf, nbytes); -#endif } gpgme_ssize_t ath_write (int fd, const void *buf, size_t nbytes) { -#if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER) - return -1; /* Not supported. */ -#else return write (fd, buf, nbytes); -#endif } @@ -28,9 +28,6 @@ /* fixme: Check how we did it in libgcrypt. */ struct msghdr { int dummy; }; typedef int socklen_t; -# if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER) -# include <winsock2.h> -# endif # include <windows.h> # include <io.h> diff --git a/src/data-compat.c b/src/data-compat.c index 87eaeef5..1f04c462 100644 --- a/src/data-compat.c +++ b/src/data-compat.c @@ -43,9 +43,6 @@ gpgme_error_t gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname, FILE *stream, gpgme_off_t offset, size_t length) { -#if defined (HAVE_W32CE_SYSTEM) && defined (_MSC_VER) - return gpgme_error (GPG_ERR_NOT_IMPLEMENTED); -#else gpgme_error_t err; char *buf = NULL; int res; @@ -114,7 +111,6 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname, (*r_dh)->data.mem.length = length; return TRACE_SUC1 ("r_dh=%p", *r_dh); -#endif } @@ -123,9 +119,6 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname, gpgme_error_t gpgme_data_new_from_file (gpgme_data_t *r_dh, const char *fname, int copy) { -#if defined (HAVE_W32CE_SYSTEM) && defined (_MSC_VER) - return gpgme_error (GPG_ERR_NOT_IMPLEMENTED); -#else gpgme_error_t err; struct stat statbuf; TRACE_BEG3 (DEBUG_DATA, "gpgme_data_new_from_file", r_dh, @@ -139,7 +132,6 @@ gpgme_data_new_from_file (gpgme_data_t *r_dh, const char *fname, int copy) err = gpgme_data_new_from_filepart (r_dh, fname, NULL, 0, statbuf.st_size); return TRACE_ERR (err); -#endif } diff --git a/src/data-fd.c b/src/data-fd.c index 42d6a0d2..cf17f00e 100644 --- a/src/data-fd.c +++ b/src/data-fd.c @@ -33,62 +33,6 @@ #include "data.h" - -#if defined(HAVE_W32CE_SYSTEM) && !defined(__MINGW32CE__) -/* We need to provide replacements for read, write and lseek. They - are taken from the cegcc runtime files, written by Pedro Alves - <[email protected]> in Feb 2007 and placed in the public - domain. (cf. cegcc/src/mingw/mingwex/wince/) */ - -#include <windows.h> - -static int -read (int fildes, void *buf, unsigned int bufsize) -{ - DWORD NumberOfBytesRead; - if (bufsize > 0x7fffffff) - bufsize = 0x7fffffff; - if (!ReadFile ((HANDLE) fildes, buf, bufsize, &NumberOfBytesRead, NULL)) - return -1; - return (int) NumberOfBytesRead; -} - -static int -write (int fildes, const void *buf, unsigned int bufsize) -{ - DWORD NumberOfBytesWritten; - if (bufsize > 0x7fffffff) - bufsize = 0x7fffffff; - if (!WriteFile ((HANDLE) fildes, buf, bufsize, &NumberOfBytesWritten, NULL)) - return -1; - return (int) NumberOfBytesWritten; -} - -static long -lseek (int fildes, long offset, int whence) -{ - DWORD mode; - switch (whence) - { - case SEEK_SET: - mode = FILE_BEGIN; - break; - case SEEK_CUR: - mode = FILE_CURRENT; - break; - case SEEK_END: - mode = FILE_END; - break; - default: - /* Specify an invalid mode so SetFilePointer catches it. */ - mode = (DWORD)-1; - } - return (long) SetFilePointer ((HANDLE) fildes, offset, NULL, mode); -} -#endif /*HAVE_W32CE_SYSTEM && !__MINGW32CE__*/ - - - static gpgme_ssize_t fd_read (gpgme_data_t dh, void *buffer, size_t size) { diff --git a/src/debug.c b/src/debug.c index 37baabb0..84aa4084 100644 --- a/src/debug.c +++ b/src/debug.c @@ -150,16 +150,12 @@ debug_init (void) } else { -#ifdef HAVE_W32CE_SYSTEM - e = _gpgme_w32ce_get_debug_envvar (); -#else /*!HAVE_W32CE_SYSTEM*/ err = _gpgme_getenv ("GPGME_DEBUG", &e); if (err) { UNLOCK (debug_lock); return; } -#endif /*!HAVE_W32CE_SYSTEM*/ } initialized = 1; @@ -257,15 +253,6 @@ _gpgme_debug (int level, const char *format, ...) va_start (arg_ptr, format); LOCK (debug_lock); { -#ifdef HAVE_W32CE_SYSTEM - SYSTEMTIME t; - - GetLocalTime (&t); - fprintf (errfp, "GPGME %04d-%02d-%02d %02d:%02d:%02d <0x%04llx> ", - t.wYear, t.wMonth, t.wDay, - t.wHour, t.wMinute, t.wSecond, - (unsigned long long) ath_self ()); -#else struct tm *tp; time_t atime = time (NULL); @@ -274,7 +261,6 @@ _gpgme_debug (int level, const char *format, ...) 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, (unsigned long long) ath_self ()); -#endif } #ifdef FRAME_NR { diff --git a/src/debug.h b/src/debug.h index 6bde998f..ca65d9ed 100644 --- a/src/debug.h +++ b/src/debug.h @@ -211,6 +211,10 @@ _gpgme_trace_gpgme_error (gpgme_error_t err, const char *file, int line) #define TRACE_SUC2(fmt, arg1, arg2) \ _gpgme_debug (_gpgme_trace_level, "%s: leave: " fmt "\n", \ _gpgme_trace_func, arg1, arg2), _gpgme_debug_frame_end () +#define TRACE_SUC4(fmt, arg1, arg2, arg3, arg4) \ + _gpgme_debug (_gpgme_trace_level, "%s: leave: " fmt "\n", \ + _gpgme_trace_func, arg1, arg2, arg3, arg4), \ + _gpgme_debug_frame_end () #define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5) \ _gpgme_debug (_gpgme_trace_level, "%s: leave: " fmt "\n", \ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5), \ diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index e7a7a6f3..5c34b0b1 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -3282,15 +3282,11 @@ gpgme_server (gpgme_tool_t gt) gt->write_data_hook = &server; /* We use a pipe based server so that we can work from scripts. - assuan_init_pipe_server will automagically detect when we are - called with a socketpair and ignore FIELDES in this case. */ -#ifdef HAVE_W32CE_SYSTEM - filedes[0] = ASSUAN_STDIN; - filedes[1] = ASSUAN_STDOUT; -#else + * assuan_init_pipe_server will automagically detect when we are + * called with a socketpair and ignore FILEDES in this case. */ filedes[0] = assuan_fdopen (0); filedes[1] = assuan_fdopen (1); -#endif + err = assuan_new (&server.assuan_ctx); if (err) log_error (1, err, "can't create assuan context"); @@ -3439,10 +3435,5 @@ main (int argc, char *argv[]) if (needgt) gpgme_release (gt.ctx); -#ifdef HAVE_W32CE_SYSTEM - /* Give the buggy ssh server time to flush the output buffers. */ - Sleep (300); -#endif - return 0; } diff --git a/src/priv-io.h b/src/priv-io.h index bc9d3d53..d21f1b34 100644 --- a/src/priv-io.h +++ b/src/priv-io.h @@ -23,9 +23,6 @@ #define IO_H #ifdef HAVE_W32_SYSTEM -# ifdef HAVE_W32CE_SYSTEM -# include "w32-ce.h" -# endif # include <winsock2.h> # include <windows.h> #else @@ -23,12 +23,8 @@ #define UTIL_H #ifdef HAVE_W32_SYSTEM -# ifdef HAVE_W32CE_SYSTEM -# include "w32-ce.h" -# else -# include "winsock2.h" -# include "windows.h" -# endif +# include "winsock2.h" +# include "windows.h" #endif /* For pid_t. */ @@ -208,9 +204,6 @@ const char *_gpgme_status_to_string (gpgme_status_code_t code); int _gpgme_mkstemp (int *fd, char **name); const char *_gpgme_get_w32spawn_path (void); #endif /*HAVE_W32_SYSTEM*/ -#ifdef HAVE_W32CE_SYSTEM -char *_gpgme_w32ce_get_debug_envvar (void); -#endif /*HAVE_W32CE_SYSTEM*/ diff --git a/src/w32-ce.c b/src/w32-ce.c deleted file mode 100644 index e326bfef..00000000 --- a/src/w32-ce.c +++ /dev/null @@ -1,507 +0,0 @@ -/* w32-ce.h - Copyright (C) 2010 g10 Code GmbH - Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc. - - This file is part of GPGME. - - GPGME 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. - - GPGME 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 <https://www.gnu.org/licenses/>. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <errno.h> -#include <assert.h> - -#include <gpg-error.h> - -#define _WIN32_IE 0x0400 /* Required for SHGetSpecialFolderPathW. */ - -/* We need to include the windows stuff here prior to shlobj.h so that - we get the right winsock version. This is usually done in w32-ce.h - but that header also redefines some Windows functions which we need - to avoid unless having included shlobj.h. */ -#include <winsock2.h> -#include <ws2tcpip.h> -#include <windows.h> -#include <shlobj.h> - -#include "w32-ce.h" - -/* Return a malloced string encoded in UTF-8 from the wide char input - string STRING. Caller must free this value. Returns NULL and sets - ERRNO on failure. Calling this function with STRING set to NULL is - not defined. */ -char * -wchar_to_utf8 (const wchar_t *string) -{ - int n; - char *result; - - n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL); - if (n < 0) - { - gpg_err_set_errno (EINVAL); - return NULL; - } - - result = malloc (n+1); - if (!result) - return NULL; - - n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL); - if (n < 0) - { - free (result); - gpg_err_set_errno (EINVAL); - result = NULL; - } - return result; -} - - -/* Return a malloced wide char string from an UTF-8 encoded input - string STRING. Caller must free this value. Returns NULL and sets - ERRNO on failure. Calling this function with STRING set to NULL is - not defined. */ -wchar_t * -utf8_to_wchar (const char *string) -{ - int n; - size_t nbytes; - wchar_t *result; - - n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0); - if (n < 0) - { - gpg_err_set_errno (EINVAL); - return NULL; - } - - nbytes = (size_t)(n+1) * sizeof(*result); - if (nbytes / sizeof(*result) != (n+1)) - { - gpg_err_set_errno (ENOMEM); - return NULL; - } - result = malloc (nbytes); - if (!result) - return NULL; - - n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); - if (n < 0) - { - free (result); - gpg_err_set_errno (EINVAL); - result = NULL; - } - return result; -} - - -#define MAX_ENV 30 - -char *environ[MAX_ENV + 1]; - -char * -getenv (const char *name) -{ - static char *past_result; - char **envp; - - if (past_result) - { - free (past_result); - past_result = NULL; - } - -#if 0 - if (! strcmp (name, "DBUS_VERBOSE")) - return past_result = get_verbose_setting (); - else if (! strcmp (name, "HOMEPATH")) - return past_result = find_my_documents_folder (); - else if (! strcmp (name, "DBUS_DATADIR")) - return past_result = find_inst_subdir ("share"); -#endif - - for (envp = environ; *envp != 0; envp++) - { - const char *varp = name; - char *ep = *envp; - - while (*varp == *ep && *varp != '\0') - { - ++ep; - ++varp; - }; - - if (*varp == '\0' && *ep == '=') - return ep + 1; - } - - return NULL; -} - - -void -GetSystemTimeAsFileTime (LPFILETIME ftp) -{ - SYSTEMTIME st; - GetSystemTime (&st); - SystemTimeToFileTime (&st, ftp); -} - - -BOOL -DeleteFileA (LPCSTR lpFileName) -{ - wchar_t *filename; - BOOL result; - int err; - - filename = utf8_to_wchar (lpFileName); - if (!filename) - return FALSE; - - result = DeleteFileW (filename); - - err = GetLastError (); - free (filename); - SetLastError (err); - return result; -} - - -HANDLE -CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwSharedMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile) -{ - wchar_t *filename; - HANDLE result; - int err; - - filename = utf8_to_wchar (lpFileName); - if (!filename) - return INVALID_HANDLE_VALUE; - - result = CreateFileW (filename, dwDesiredAccess, dwSharedMode, - lpSecurityAttributes, dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile); - - err = GetLastError (); - free (filename); - SetLastError (err); - return result; -} - - -BOOL -CreateProcessA (LPCSTR pszImageName, LPSTR pszCmdLine, - LPSECURITY_ATTRIBUTES psaProcess, - LPSECURITY_ATTRIBUTES psaThread, BOOL fInheritHandles, - DWORD fdwCreate, PVOID pvEnvironment, LPCSTR pszCurDir, - LPSTARTUPINFOA psiStartInfo, - LPPROCESS_INFORMATION pProcInfo) -{ - wchar_t *image_name = NULL; - wchar_t *cmd_line = NULL; - BOOL result; - int err; - - assert (psaProcess == NULL); - assert (psaThread == NULL); - assert (fInheritHandles == FALSE); - assert (pvEnvironment == NULL); - assert (pszCurDir == NULL); - /* psiStartInfo is generally not NULL. */ - - if (pszImageName) - { - image_name = utf8_to_wchar (pszImageName); - if (!image_name) - return 0; - } - if (pszCmdLine) - { - cmd_line = utf8_to_wchar (pszCmdLine); - if (!cmd_line) - { - if (image_name) - free (image_name); - return 0; - } - } - - result = CreateProcessW (image_name, cmd_line, NULL, NULL, FALSE, - fdwCreate, NULL, NULL, NULL, pProcInfo); - - err = GetLastError (); - free (image_name); - free (cmd_line); - SetLastError (err); - return result; -} - - -LONG -RegOpenKeyExA (HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, - REGSAM samDesired, PHKEY phkResult) -{ - wchar_t *subkey; - LONG result; - int err; - - if (lpSubKey) - { - subkey = utf8_to_wchar (lpSubKey); - if (!subkey) - return 0; - } - else - subkey = NULL; - - result = RegOpenKeyEx (hKey, subkey, ulOptions, samDesired, phkResult); - - err = GetLastError (); - free (subkey); - SetLastError (err); - return result; -} - - -LONG WINAPI -RegQueryValueExA (HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, - LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) -{ - wchar_t *name; - LONG err; - void *data; - DWORD data_len; - DWORD type; - - if (lpValueName) - { - name = utf8_to_wchar (lpValueName); - if (!name) - return GetLastError (); - } - else - name = NULL; - - data_len = 0; - err = RegQueryValueExW (hKey, name, lpReserved, lpType, NULL, &data_len); - if (err || !lpcbData) - { - free (name); - return err; - } - - data = malloc (data_len + sizeof (wchar_t)); - if (!data) - { - free (name); - return ERROR_NOT_ENOUGH_MEMORY; - } - - err = RegQueryValueExW (hKey, name, lpReserved, &type, data, &data_len); - if (lpType) - *lpType = type; - free (name); - /* If err is ERROR_MORE_DATA, there probably was a race condition. - We can punt this to the caller just as well. */ - if (err) - return err; - - /* NOTE: REG_MULTI_SZ and REG_EXPAND_SZ not supported, because they - are not needed in this module. */ - if (type == REG_SZ) - { - char *data_c; - int data_c_len; - - /* This is valid since we allocated one more above. */ - ((char*)data)[data_len] = '\0'; - ((char*)data)[data_len + 1] = '\0'; - - data_c = wchar_to_utf8 ((wchar_t*) data); - if (!data_c) - return GetLastError(); - - data_c_len = strlen (data_c) + 1; - assert (data_c_len <= data_len + sizeof (wchar_t)); - memcpy (data, data_c, data_c_len); - data_len = data_c_len; - free (data_c); - } - - /* DATA and DATA_LEN now contain the result. */ - if (lpData) - { - if (data_len > *lpcbData) - err = ERROR_MORE_DATA; - else - memcpy (lpData, data, data_len); - } - *lpcbData = data_len; - return err; -} - - -DWORD -GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer) -{ - wchar_t dummy[1]; - DWORD len; - - len = GetTempPathW (0, dummy); - if (len == 0) - return 0; - - assert (len <= MAX_PATH); - - /* Better be safe than sorry. MSDN doesn't say if len is with or - without terminating 0. */ - len++; - - { - wchar_t *buffer_w; - DWORD len_w; - char *buffer_c; - DWORD len_c; - - buffer_w = malloc (sizeof (wchar_t) * len); - if (! buffer_w) - return 0; - - len_w = GetTempPathW (len, buffer_w); - /* Give up if we still can't get at it. */ - if (len_w == 0 || len_w >= len) - { - free (buffer_w); - return 0; - } - - /* Better be really safe. */ - buffer_w[len_w] = '\0'; - - buffer_c = wchar_to_utf8 (buffer_w); - free (buffer_w); - if (! buffer_c) - return 0; - - /* strlen is correct (not _mbstrlen), because we want storage and - not string length. */ - len_c = strlen (buffer_c) + 1; - if (len_c > nBufferLength) - return len_c; - - strcpy (lpBuffer, buffer_c); - free (buffer_c); - return len_c - 1; - } -} - - -/* The symbol is named SHGetSpecialFolderPath and not - SHGetSpecialFolderPathW but shlobj.h from cegcc redefines it to *W - which is a bug. Work around it. */ -#ifdef __MINGW32CE__ -# undef SHGetSpecialFolderPath -#endif -BOOL -SHGetSpecialFolderPathA (HWND hwndOwner, LPSTR lpszPath, int nFolder, - BOOL fCreate) -{ - wchar_t path[MAX_PATH]; - char *path_c; - BOOL result; - - path[0] = (wchar_t) 0; - result = SHGetSpecialFolderPath (hwndOwner, path, nFolder, fCreate); - /* Note: May return false even if succeeds. */ - - path[MAX_PATH - 1] = (wchar_t) 0; - path_c = wchar_to_utf8 (path); - if (! path_c) - return 0; - - strncpy (lpszPath, path_c, MAX_PATH); - free (path_c); - lpszPath[MAX_PATH - 1] = '\0'; - return result; -} - -/* Replacement for the access function. Note that we can't use fopen - here because wince might now allow to have a shared read for an - executable; it is better to to read the file attributes. - - Limitation: Only F_OK is supported. -*/ -int -_gpgme_wince_access (const char *fname, int mode) -{ - DWORD attr; - wchar_t *wfname; - - (void)mode; - - wfname = utf8_to_wchar (fname); - if (!wfname) - return -1; - - attr = GetFileAttributes (wfname); - free (wfname); - if (attr == (DWORD)(-1)) - { - gpg_err_set_errno (ENOENT); - return -1; - } - return 0; -} - - -/* Perform a binary search for KEY in BASE which has NMEMB elements - of SIZE bytes each. The comparisons are done by (*COMPAR)(). - Code taken from glibc-2.6. */ -void * -_gpgme_wince_bsearch (const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *)) -{ - size_t l, u, idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p); - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - diff --git a/src/w32-ce.h b/src/w32-ce.h deleted file mode 100644 index c52ea992..00000000 --- a/src/w32-ce.h +++ /dev/null @@ -1,91 +0,0 @@ -/* w32-ce.h - Copyright (C) 2010 g10 Code GmbH - - This file is part of GPGME. - - GPGME 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. - - GPGME 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, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -#ifndef GPGME_W32_CE_H -#define GPGME_W32_CE_H - -#include <time.h> -#include <stdarg.h> - -#ifdef _MSC_VER -typedef int pid_t; -#define strdup _strdup -#define strcasecmp _stricmp -#endif - -#include <winsock2.h> -#include <ws2tcpip.h> /* For getaddrinfo. */ -#include <windows.h> - -#define getenv _gpgme_wince_getenv -char *getenv (const char *name); - -#include <io.h> -#define isatty(fd) 0 - - -/* Windows CE is missing some Windows functions that we want. */ - -#define GetSystemTimeAsFileTime _gpgme_wince_GetSystemTimeAsFileTime -void GetSystemTimeAsFileTime (LPFILETIME ftp); - -#define DeleteFileA _gpgme_wince_DeleteFileA -BOOL DeleteFileA(LPCSTR); - -#define CreateFileA _gpgme_wince_CreateFileA -HANDLE CreateFileA (LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, - DWORD, DWORD, HANDLE); - -#define CreateProcessA _gpgme_wince_CreateProcessA -BOOL CreateProcessA(LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,PVOID,LPCSTR,LPSTARTUPINFOA,LPPROCESS_INFORMATION); - -#define RegOpenKeyExA _gpgme_wince_RegOpenKeyExA -LONG RegOpenKeyExA(HKEY,LPCSTR,DWORD,REGSAM,PHKEY); - -#define RegQueryValueExA _gpgme_wince_RegQueryValueExA -LONG WINAPI RegQueryValueExA(HKEY,LPCSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD); - -#define GetTempPathA _gpgme_wince_GetTempPathA -DWORD GetTempPathA(DWORD,LPSTR); - -#define SHGetSpecialFolderPathA _gpgme_wince_SHGetSpecialFolderPathA -BOOL SHGetSpecialFolderPathA(HWND,LPSTR,int,BOOL); - -int _gpgme_wince_access (const char *fname, int mode); -#define access(a,b) _gpgme_wince_access ((a), (b)) - -void *_gpgme_wince_bsearch (const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *)); -#define bsearch(a,b,c,d,e) _gpgme_wince_bsearch ((a),(b),(c),(d),(e)) - -#if defined(_MSC_VER) - /* Remove the redefined __leave keyword. It is defined by MSC for - W32 in excpt.h and not in sehmap.h as for the plain windows - version. */ -# undef leave -# define HKEY_PERFORMANCE_DATA ((HKEY)0x80000004) -# define HKEY_CURRENT_CONFIG ((HKEY)0x80000005) - /* Replace the Mingw32CE provided abort function. */ -# define abort() do { TerminateProcess (GetCurrentProcess(), 8); } while (0) -# define _IOLBF 0x40 -#endif - -#endif /* GPGME_W32_CE_H */ diff --git a/src/w32-io.c b/src/w32-io.c index aea0547e..bb59a5e9 100644 --- a/src/w32-io.c +++ b/src/w32-io.c @@ -37,16 +37,6 @@ #include <io.h> #include "util.h" - -#ifdef HAVE_W32CE_SYSTEM -#include <assuan.h> -#include <winioctl.h> -#define GPGCEDEV_IOCTL_UNBLOCK \ - CTL_CODE (FILE_DEVICE_STREAMS, 2050, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define GPGCEDEV_IOCTL_ASSIGN_RVID \ - CTL_CODE (FILE_DEVICE_STREAMS, 2051, METHOD_BUFFERED, FILE_ANY_ACCESS) -#endif - #include "sema.h" #include "priv-io.h" #include "debug.h" @@ -66,9 +56,6 @@ static struct /* If this is not INVALID_SOCKET, then it's a Windows socket. */ int socket; - /* If this is not 0, then it's a rendezvous ID for the pipe server. */ - int rvid; - /* DUP_FROM is -1 if this file descriptor was allocated by pipe or socket functions. Only then should the handle or socket be destroyed when this FD is closed. This, together with the fact @@ -109,7 +96,6 @@ new_fd (void) fd_table[idx].used = 1; fd_table[idx].handle = INVALID_HANDLE_VALUE; fd_table[idx].socket = INVALID_SOCKET; - fd_table[idx].rvid = 0; fd_table[idx].dup_from = -1; } @@ -132,7 +118,6 @@ release_fd (int fd) fd_table[fd].used = 0; fd_table[fd].handle = INVALID_HANDLE_VALUE; fd_table[fd].socket = INVALID_SOCKET; - fd_table[fd].rvid = 0; fd_table[fd].dup_from = -1; } @@ -334,8 +319,6 @@ reader (void *arg) ctx->buffer + ctx->writepos, nbytes, &nread, NULL)) { ctx->error_code = (int) GetLastError (); - /* NOTE (W32CE): Do not ignore ERROR_BUSY! Check at - least stop_me if that happens. */ if (ctx->error_code == ERROR_BROKEN_PIPE) { ctx->eof = 1; @@ -445,12 +428,7 @@ create_reader (int fd) INIT_LOCK (ctx->mutex); -#ifdef HAVE_W32CE_SYSTEM - ctx->thread_hd = CreateThread (&sec_attr, 64 * 1024, reader, ctx, - STACK_SIZE_PARAM_IS_A_RESERVATION, &tid); -#else ctx->thread_hd = CreateThread (&sec_attr, 0, reader, ctx, 0, &tid); -#endif if (!ctx->thread_hd) { @@ -497,22 +475,6 @@ destroy_reader (struct reader_context_s *ctx) SetEvent (ctx->have_space_ev); UNLOCK (ctx->mutex); -#ifdef HAVE_W32CE_SYSTEM - /* Scenario: We never create a full pipe, but already started - reading. Then we need to unblock the reader in the pipe driver - to make our reader thread notice that we want it to go away. */ - - if (ctx->file_hd != INVALID_HANDLE_VALUE) - { - if (!DeviceIoControl (ctx->file_hd, GPGCEDEV_IOCTL_UNBLOCK, - NULL, 0, NULL, 0, NULL, NULL)) - { - TRACE1 (DEBUG_SYSIO, "gpgme:destroy_reader", ctx->file_hd, - "unblock control call failed for thread %p", ctx->thread_hd); - } - } -#endif - /* The reader thread is usually blocking in recv or ReadFile. If the peer does not send an EOF or breaks the pipe the WFSO might get stuck waiting for the termination of the reader thread. This @@ -817,13 +779,7 @@ create_writer (int fd) INIT_LOCK (ctx->mutex); -#ifdef HAVE_W32CE_SYSTEM - ctx->thread_hd = CreateThread (&sec_attr, 64 * 1024, writer, ctx, - STACK_SIZE_PARAM_IS_A_RESERVATION, &tid); -#else ctx->thread_hd = CreateThread (&sec_attr, 0, writer, ctx, 0, &tid ); -#endif - if (!ctx->thread_hd) { TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ()); @@ -869,20 +825,6 @@ destroy_writer (struct writer_context_s *ctx) /* Give the writer a chance to flush the buffer. */ WaitForSingleObject (ctx->is_empty, INFINITE); -#ifdef HAVE_W32CE_SYSTEM - /* Scenario: We never create a full pipe, but already started - writing more than the pipe buffer. Then we need to unblock the - writer in the pipe driver to make our writer thread notice that - we want it to go away. */ - - if (!DeviceIoControl (ctx->file_hd, GPGCEDEV_IOCTL_UNBLOCK, - NULL, 0, NULL, 0, NULL, NULL)) - { - TRACE1 (DEBUG_SYSIO, "gpgme:destroy_writer", ctx->file_hd, - "unblock control call failed for thread %p", ctx->thread_hd); - } -#endif - /* After setting this event CTX is void. */ SetEvent (ctx->close_ev); } @@ -1008,14 +950,9 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx) { int rfd; int wfd; -#ifdef HAVE_W32CE_SYSTEM - HANDLE hd; - int rvid; -#else HANDLE rh; HANDLE wh; SECURITY_ATTRIBUTES sec_attr; -#endif TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_pipe", filedes, "inherit_idx=%i (GPGME uses it for %s)", @@ -1031,32 +968,6 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx) return TRACE_SYSRES (-1); } -#ifdef HAVE_W32CE_SYSTEM - hd = _assuan_w32ce_prepare_pipe (&rvid, !inherit_idx); - if (hd == INVALID_HANDLE_VALUE) - { - TRACE_LOG1 ("_assuan_w32ce_prepare_pipe failed: ec=%d", - (int) GetLastError ()); - release_fd (rfd); - release_fd (wfd); - /* FIXME: Should translate the error code. */ - gpg_err_set_errno (EIO); - return TRACE_SYSRES (-1); - } - - if (inherit_idx == 0) - { - fd_table[rfd].rvid = rvid; - fd_table[wfd].handle = hd; - } - else - { - fd_table[rfd].handle = hd; - fd_table[wfd].rvid = rvid; - } - -#else - memset (&sec_attr, 0, sizeof (sec_attr)); sec_attr.nLength = sizeof (sec_attr); sec_attr.bInheritHandle = FALSE; @@ -1114,13 +1025,11 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx) } fd_table[rfd].handle = rh; fd_table[wfd].handle = wh; -#endif filedes[0] = rfd; filedes[1] = wfd; - return TRACE_SUC6 ("read=0x%x (%p/0x%x), write=0x%x (%p/0x%x)", - rfd, fd_table[rfd].handle, fd_table[rfd].rvid, - wfd, fd_table[wfd].handle, fd_table[wfd].rvid); + return TRACE_SUC4 ("read=0x%x (%p), write=0x%x (%p)", + rfd, fd_table[rfd].handle, wfd, fd_table[wfd].handle); } @@ -1213,7 +1122,6 @@ _gpgme_io_close (int fd) return TRACE_SYSRES (-1); } } - /* Nothing to do for RVIDs. */ } release_fd (fd); @@ -1263,91 +1171,6 @@ _gpgme_io_set_nonblocking (int fd) } -#ifdef HAVE_W32CE_SYSTEM -static char * -build_commandline (char **argv, int fd0, int fd0_isnull, - int fd1, int fd1_isnull, - int fd2, int fd2_isnull) -{ - int i, n; - const char *s; - char *buf, *p; - char fdbuf[3*30]; - - p = fdbuf; - *p = 0; - - if (fd0 != -1) - { - if (fd0_isnull) - strcpy (p, "-&S0=null "); - else - snprintf (p, 25, "-&S0=%d ", fd_table[fd0].rvid); - p += strlen (p); - } - if (fd1 != -1) - { - if (fd1_isnull) - strcpy (p, "-&S1=null "); - else - snprintf (p, 25, "-&S1=%d ", fd_table[fd1].rvid); - p += strlen (p); - } - if (fd2 != -1) - { - if (fd2_isnull) - strcpy (p, "-&S2=null "); - else - snprintf (p, 25, "-&S2=%d ", fd_table[fd2].rvid); - p += strlen (p); - } - strcpy (p, "-&S2=null "); - p += strlen (p); - - n = strlen (fdbuf); - for (i=0; (s = argv[i]); i++) - { - if (!i) - continue; /* Ignore argv[0]. */ - n += strlen (s) + 1 + 2; /* (1 space, 2 quoting) */ - for (; *s; s++) - if (*s == '\"') - n++; /* Need to double inner quotes. */ - } - n++; - buf = p = malloc (n); - if (! buf) - return NULL; - - p = stpcpy (p, fdbuf); - for (i = 0; argv[i]; i++) - { - if (!i) - continue; /* Ignore argv[0]. */ - if (i > 1) - p = stpcpy (p, " "); - - if (! *argv[i]) /* Empty string. */ - p = stpcpy (p, "\"\""); - else if (strpbrk (argv[i], " \t\n\v\f\"")) - { - p = stpcpy (p, "\""); - for (s = argv[i]; *s; s++) - { - *p++ = *s; - if (*s == '\"') - *p++ = *s; - } - *p++ = '\"'; - *p = 0; - } - else - p = stpcpy (p, argv[i]); - } - - return buf; -} -#else static char * build_commandline (char **argv) { @@ -1401,7 +1224,6 @@ build_commandline (char **argv) return buf; } -#endif int @@ -1419,120 +1241,6 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags, }; int i; -#ifdef HAVE_W32CE_SYSTEM - int fd_in = -1; - int fd_out = -1; - int fd_err = -1; - int fd_in_isnull = 1; - int fd_out_isnull = 1; - int fd_err_isnull = 1; - char *cmdline; - HANDLE hd = INVALID_HANDLE_VALUE; - - TRACE_BEG1 (DEBUG_SYSIO, "_gpgme_io_spawn", path, - "path=%s", path); - i = 0; - while (argv[i]) - { - TRACE_LOG2 ("argv[%2i] = %s", i, argv[i]); - i++; - } - - for (i = 0; fd_list[i].fd != -1; i++) - { - int fd = fd_list[i].fd; - - TRACE_LOG3 ("fd_list[%2i] = fd %i, dup_to %i", i, fd, fd_list[i].dup_to); - if (fd < 0 || fd >= MAX_SLAFD || !fd_table[fd].used) - { - TRACE_LOG1 ("invalid fd 0x%x", fd); - gpg_err_set_errno (EBADF); - return TRACE_SYSRES (-1); - } - if (fd_table[fd].rvid == 0) - { - TRACE_LOG1 ("fd 0x%x not inheritable (not an RVID)", fd); - gpg_err_set_errno (EBADF); - return TRACE_SYSRES (-1); - } - - if (fd_list[i].dup_to == 0) - { - fd_in = fd_list[i].fd; - fd_in_isnull = 0; - } - else if (fd_list[i].dup_to == 1) - { - fd_out = fd_list[i].fd; - fd_out_isnull = 0; - } - else if (fd_list[i].dup_to == 2) - { - fd_err = fd_list[i].fd; - fd_err_isnull = 0; - } - } - - cmdline = build_commandline (argv, fd_in, fd_in_isnull, - fd_out, fd_out_isnull, fd_err, fd_err_isnull); - if (!cmdline) - { - TRACE_LOG1 ("build_commandline failed: %s", strerror (errno)); - return TRACE_SYSRES (-1); - } - - if (!CreateProcessA (path, /* Program to start. */ - cmdline, /* Command line arguments. */ - NULL, /* (not supported) */ - NULL, /* (not supported) */ - FALSE, /* (not supported) */ - (CREATE_SUSPENDED), /* Creation flags. */ - NULL, /* (not supported) */ - NULL, /* (not supported) */ - NULL, /* (not supported) */ - &pi /* Returns process information.*/ - )) - { - TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ()); - free (cmdline); - gpg_err_set_errno (EIO); - return TRACE_SYSRES (-1); - } - - /* Create arbitrary pipe descriptor to send in ASSIGN_RVID - commands. Errors are ignored. We don't need read or write access, - as ASSIGN_RVID works without any permissions, yay! */ - hd = CreateFile (L"GPG1:", 0, 0, - NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hd == INVALID_HANDLE_VALUE) - { - TRACE_LOG1 ("CreateFile failed (ignored): ec=%d", - (int) GetLastError ()); - } - - /* Insert the inherited handles. */ - for (i = 0; fd_list[i].fd != -1; i++) - { - /* Return the child name of this handle. */ - fd_list[i].peer_name = fd_table[fd_list[i].fd].rvid; - - if (hd != INVALID_HANDLE_VALUE) - { - DWORD data[2]; - data[0] = (DWORD) fd_table[fd_list[i].fd].rvid; - data[1] = pi.dwProcessId; - if (!DeviceIoControl (hd, GPGCEDEV_IOCTL_ASSIGN_RVID, - data, sizeof (data), NULL, 0, NULL, NULL)) - { - TRACE_LOG3 ("ASSIGN_RVID(%i, %i) failed (ignored): %i", - data[0], data[1], (int) GetLastError ()); - } - } - } - if (hd != INVALID_HANDLE_VALUE) - CloseHandle (hd); - -#else SECURITY_ATTRIBUTES sec_attr; STARTUPINFOA si; int cr_flags = CREATE_DEFAULT_ERROR_MODE; @@ -1729,7 +1437,6 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags, close (tmp_fd); /* The temporary file is deleted by the gpgme-w32spawn process (hopefully). */ -#endif free (tmp_name); free (arg_string); @@ -1954,15 +1661,6 @@ _gpgme_io_subsystem_init (void) int _gpgme_io_fd2str (char *buf, int buflen, int fd) { -#ifdef HAVE_W32CE_SYSTEM - /* FIXME: For now. See above. */ - if (fd < 0 || fd >= MAX_SLAFD || !fd_table[fd].used - || fd_table[fd].rvid == 0) - fd = -1; - else - fd = fd_table[fd].rvid; -#endif - return snprintf (buf, buflen, "%d", fd); } @@ -1989,7 +1687,6 @@ _gpgme_io_dup (int fd) fd_table[newfd].handle = fd_table[fd].handle; fd_table[newfd].socket = fd_table[fd].socket; - fd_table[newfd].rvid = fd_table[fd].rvid; fd_table[newfd].dup_from = fd; rd_ctx = find_reader (fd, 1); diff --git a/src/w32-util.c b/src/w32-util.c index ef9b5f36..79541898 100644 --- a/src/w32-util.c +++ b/src/w32-util.c @@ -65,9 +65,7 @@ #include "sys-util.h" -#ifndef HAVE_W32CE_SYSTEM #define HAVE_ALLOW_SET_FOREGROUND_WINDOW 1 -#endif #ifndef F_OK # define F_OK 0 #endif @@ -303,53 +301,6 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) } result[nbytes] = 0; /* Make sure it is really a string. */ -#ifndef HAVE_W32CE_SYSTEM - /* Windows CE does not have an environment. */ - if (type == REG_EXPAND_SZ && strchr (result, '%')) - { - char *tmp; - - n1 += 1000; - tmp = malloc (n1 + 1); - if (!tmp) - goto leave; - nbytes = ExpandEnvironmentStrings (result, tmp, n1); - if (nbytes && nbytes > n1) - { - free (tmp); - n1 = nbytes; - tmp = malloc (n1 + 1); - if (!tmp) - goto leave; - nbytes = ExpandEnvironmentStrings (result, tmp, n1); - if (nbytes && nbytes > n1) { - free (tmp); /* Oops - truncated, better don't expand at all. */ - goto leave; - } - tmp[nbytes] = 0; - free (result); - result = tmp; - } - else if (nbytes) /* Okay, reduce the length. */ - { - tmp[nbytes] = 0; - free (result); - result = malloc (strlen (tmp)+1); - if (!result) - result = tmp; - else - { - strcpy (result, tmp); - free (tmp); - } - } - else /* Error - don't expand. */ - { - free (tmp); - } - } -#endif - leave: RegCloseKey (key_handle); return result; @@ -652,15 +603,8 @@ _gpgme_get_conf_int (const char *key, int *value) return 1; } - -#ifdef HAVE_W32CE_SYSTEM -int -_gpgme_mkstemp (int *fd, char **name) -{ - return -1; -} -#else + /* mkstemp extracted from libc/sysdeps/posix/tempname.c. Copyright (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc. @@ -794,30 +738,9 @@ _gpgme_mkstemp (int *fd, char **name) *name = tmpname; return 0; } -#endif -#ifdef HAVE_W32CE_SYSTEM -/* Return a malloced string with the replacement value for the - GPGME_DEBUG envvar. Caller must release. Returns NULL if not - set. */ -char * -_gpgme_w32ce_get_debug_envvar (void) -{ - char *tmp; - - tmp = read_w32_registry_string (NULL, "\\Software\\GNU\\gpgme", "debug"); - if (tmp && !*tmp) - { - free (tmp); - tmp = NULL; - } - return tmp; -} -#endif /*HAVE_W32CE_SYSTEM*/ - - /* Entry point called by the DLL loader. */ #ifdef DLL_EXPORT int WINAPI |