aboutsummaryrefslogtreecommitdiffstats
path: root/src/system-w32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/system-w32.c')
-rw-r--r--src/system-w32.c258
1 files changed, 0 insertions, 258 deletions
diff --git a/src/system-w32.c b/src/system-w32.c
index 1d06cd6..9248edf 100644
--- a/src/system-w32.c
+++ b/src/system-w32.c
@@ -64,33 +64,6 @@ __assuan_usleep (assuan_context_t ctx, unsigned int usec)
-/* Three simple wrappers, only used because thes function are named in
- the def file. */
-HANDLE
-_assuan_w32ce_prepare_pipe (int *r_rvid, int write_end)
-{
- (void)r_rvid;
- (void)write_end;
- return INVALID_HANDLE_VALUE;
-}
-
-HANDLE
-_assuan_w32ce_finish_pipe (int rvid, int write_end)
-{
- (void)rvid;
- (void)write_end;
- return INVALID_HANDLE_VALUE;
-}
-
-DWORD
-_assuan_w32ce_create_pipe (HANDLE *read_hd, HANDLE *write_hd,
- LPSECURITY_ATTRIBUTES sec_attr, DWORD size)
-{
- return CreatePipe (read_hd, write_hd, sec_attr, size);
-}
-
-
-
/* Create a pipe with one inheritable end. Default implementation. */
int
__assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
@@ -399,237 +372,6 @@ __assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
gpg_err_set_errno (ENOSYS);
return -1;
}
-
-
-
-
-/* Build a command line for use with W32's CreateProcess. On success
- CMDLINE gets the address of a newly allocated string. */
-static int
-build_w32_commandline (assuan_context_t ctx, const char * const *argv,
- char **cmdline)
-{
- int i, n;
- const char *s;
- char *buf, *p;
-
- *cmdline = NULL;
- n = 0;
- for (i=0; (s = argv[i]); i++)
- {
- n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */
- for (; *s; s++)
- if (*s == '\"')
- n++; /* Need to double inner quotes. */
- }
- n++;
-
- buf = p = _assuan_malloc (ctx, n);
- if (! buf)
- return -1;
-
- for (i = 0; argv[i]; i++)
- {
- if (i)
- 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]);
- }
-
- *cmdline= buf;
- return 0;
-}
-
-
-int
-__assuan_spawn (assuan_context_t ctx, assuan_pid_t *r_pid, const char *name,
- const char **argv,
- assuan_fd_t fd_in, assuan_fd_t fd_out,
- assuan_fd_t *fd_child_list,
- void (*atfork) (void *opaque, int reserved),
- void *atforkvalue, unsigned int flags)
-{
- SECURITY_ATTRIBUTES sec_attr;
- PROCESS_INFORMATION pi =
- {
- NULL, /* Returns process handle. */
- 0, /* Returns primary thread handle. */
- 0, /* Returns pid. */
- 0 /* Returns tid. */
- };
- STARTUPINFOW si;
- assuan_fd_t fd;
- assuan_fd_t *fdp;
- char *cmdline;
- wchar_t *wcmdline = NULL;
- wchar_t *wname = NULL;
- HANDLE nullfd = INVALID_HANDLE_VALUE;
- int rc;
-
- /* fixme: Actually we should set the "_assuan_pipe_connect_pid" env
- variable. However this requires us to write a full environment
- handler, because the strings are expected in sorted order. The
- suggestion given in the MS Reference Library, to save the old
- value, change it, create process and restore it, is not thread
- safe. */
-
- /* Build the command line. */
- if (build_w32_commandline (ctx, argv, &cmdline))
- return -1;
-
- /* Start the process. */
- memset (&sec_attr, 0, sizeof sec_attr);
- sec_attr.nLength = sizeof sec_attr;
- sec_attr.bInheritHandle = FALSE;
-
- memset (&si, 0, sizeof si);
- si.cb = sizeof (si);
- si.dwFlags = STARTF_USESTDHANDLES;
- /* FIXME: Dup to nul if ASSUAN_INVALID_FD. */
- si.hStdInput = fd_in;
- si.hStdOutput = fd_out;
-
- /* Dup stderr to /dev/null unless it is in the list of FDs to be
- passed to the child. */
- fd = assuan_fd_from_posix_fd (fileno (stderr));
- fdp = fd_child_list;
- if (fdp)
- {
- for (; *fdp != ASSUAN_INVALID_FD && *fdp != fd; fdp++)
- ;
- }
- if (!fdp || *fdp == ASSUAN_INVALID_FD)
- {
- nullfd = CreateFileW (L"nul", GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, 0, NULL);
- if (nullfd == INVALID_HANDLE_VALUE)
- {
- TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx,
- "can't open `nul': %s", _assuan_w32_strerror (ctx, -1));
- _assuan_free (ctx, cmdline);
- gpg_err_set_errno (EIO);
- return -1;
- }
- si.hStdError = nullfd;
- }
- else
- si.hStdError = fd;
-
- /* Note: We inherit all handles flagged as inheritable. This seems
- to be a security flaw but there seems to be no way of selecting
- handles to inherit. A fix for this would be to use a helper
- process like we have in gpgme.
- Take care: CreateProcessW may modify wpgmname */
- /* _assuan_log_printf ("CreateProcess, path=`%s' cmdline=`%s'\n", */
- /* name, cmdline); */
- if (name && !(wname = _assuan_utf8_to_wchar (name)))
- rc = 0;
- else if (!(wcmdline = _assuan_utf8_to_wchar (cmdline)))
- rc = 0;
- else
- rc = CreateProcessW (wname, /* Program to start. */
- wcmdline, /* Command line arguments. */
- &sec_attr, /* Process security attributes. */
- &sec_attr, /* Thread security attributes. */
- TRUE, /* Inherit handles. */
- (CREATE_DEFAULT_ERROR_MODE
- | ((flags & 128)? DETACHED_PROCESS : 0)
- | GetPriorityClass (GetCurrentProcess ())
- | CREATE_SUSPENDED), /* Creation flags. */
- NULL, /* Environment. */
- NULL, /* Use current drive/directory. */
- &si, /* Startup information. */
- &pi /* Returns process information. */
- );
- if (!rc)
- {
- TRACE1 (ctx, ASSUAN_LOG_SYSIO, "pipe_connect_w32", ctx,
- "CreateProcess failed%s: %s", _assuan_w32_strerror (ctx, -1));
- free (wname);
- free (wcmdline);
- _assuan_free (ctx, cmdline);
- if (nullfd != INVALID_HANDLE_VALUE)
- CloseHandle (nullfd);
-
- gpg_err_set_errno (EIO);
- return -1;
- }
-
- free (wname);
- free (wcmdline);
- _assuan_free (ctx, cmdline);
- if (nullfd != INVALID_HANDLE_VALUE)
- CloseHandle (nullfd);
-
- ResumeThread (pi.hThread);
- CloseHandle (pi.hThread);
-
- /* _assuan_log_printf ("CreateProcess ready: hProcess=%p hThread=%p" */
- /* " dwProcessID=%d dwThreadId=%d\n", */
- /* pi.hProcess, pi.hThread, */
- /* (int) pi.dwProcessId, (int) pi.dwThreadId); */
-
- *r_pid = (assuan_pid_t) pi.hProcess;
-
- /* No need to modify peer process, as we don't change the handle
- names. However this also means we are not safe, as we inherit
- too many handles. Should use approach similar to gpgme and glib
- using a helper process. */
-
- return 0;
-}
-
-
-
-
-/* FIXME: Add some sort of waitpid function that covers GPGME and
- gpg-agent's use of assuan. */
-assuan_pid_t
-__assuan_waitpid (assuan_context_t ctx, assuan_pid_t pid, int nowait,
- int *status, int options)
-{
- int code;
- DWORD exit_code;
-
- (void)ctx;
-
- if (nowait)
- return 0;
-
- code = WaitForSingleObject ((HANDLE)pid, options? 0: INFINITE);
-
- if (code == WAIT_OBJECT_0)
- {
- if (status)
- {
- GetExitCodeProcess ((HANDLE)pid, &exit_code);
- *status = (int)exit_code;
- }
- CloseHandle ((HANDLE)pid);
- return pid;
- }
- else if (code == WAIT_TIMEOUT)
- return 0;
- else
- return -1;
-}
-
-
int
__assuan_socketpair (assuan_context_t ctx, int namespace, int style,