diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-15 10:32:23 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-15 10:39:20 +0000 |
commit | 7cc082e2370da69c8783812c251190d316ce82b3 (patch) | |
tree | 8a6224f8dd28fb1ffd3e6ef111efcc8b82f429b8 /win32 | |
parent | f011d7284d8cabe5d453b43d4df44d0423db22c8 (diff) | |
download | busybox-w32-7cc082e2370da69c8783812c251190d316ce82b3.tar.gz busybox-w32-7cc082e2370da69c8783812c251190d316ce82b3.tar.bz2 busybox-w32-7cc082e2370da69c8783812c251190d316ce82b3.zip |
wget: add support for https
Allow wget to support https URLs. Changes are:
- Add mingw_popen2 which uses a named pipe to allow bidirectional
communication with a child process;
- Modify ssl_client to accept a WIN32 handle instead of a file
descriptor as an argument;
- Allow tls_get_random to open /dev/urandom;
- Using the above changes implement a WIN32 version of spawn_ssl_client
in wget.
This closes GitHub issue #75.
Also, enable authentication in wget.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/popen.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/win32/popen.c b/win32/popen.c index 59f5ca9f0..c075e2144 100644 --- a/win32/popen.c +++ b/win32/popen.c | |||
@@ -288,6 +288,109 @@ finito: | |||
288 | return fd; | 288 | return fd; |
289 | } | 289 | } |
290 | 290 | ||
291 | /* | ||
292 | * Open a bidirectional pipe to a command. The pid of the command is | ||
293 | * returned in the variable pid, which can be NULL. | ||
294 | */ | ||
295 | int mingw_popen2(const char *cmd, pid_t *pid) | ||
296 | { | ||
297 | pipe_data *p; | ||
298 | char *name = NULL; | ||
299 | SECURITY_ATTRIBUTES sa; | ||
300 | STARTUPINFO siStartInfo; | ||
301 | int success; | ||
302 | int fd = -1; | ||
303 | const int ip = 1; /* index of parent end of pipe */ | ||
304 | const int ic = 0; /* index of child end of pipe */ | ||
305 | |||
306 | if ( cmd == NULL || *cmd == '\0' ) { | ||
307 | return -1; | ||
308 | } | ||
309 | |||
310 | /* find an unused pipe structure */ | ||
311 | if ( (p=find_pipe()) == NULL ) { | ||
312 | return -1; | ||
313 | } | ||
314 | |||
315 | /* Create the pipe */ | ||
316 | name = xasprintf("\\\\.\\pipe\\bb_pipe.%d.%d", getpid(), (int)(p-pipes)); | ||
317 | |||
318 | sa.nLength = sizeof(sa); /* Length in bytes */ | ||
319 | sa.bInheritHandle = 1; /* the child must inherit these handles */ | ||
320 | sa.lpSecurityDescriptor = NULL; | ||
321 | |||
322 | p->pipe[ip] = CreateNamedPipe(name, | ||
323 | PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED, | ||
324 | PIPE_TYPE_BYTE|PIPE_WAIT, | ||
325 | 1, 4096, 4096, 0, &sa); | ||
326 | if (p->pipe[ip] == INVALID_HANDLE_VALUE) { | ||
327 | goto finito; | ||
328 | } | ||
329 | |||
330 | /* Connect to the pipe */ | ||
331 | p->pipe[ic] = CreateFile(name, GENERIC_READ|GENERIC_WRITE, 0, &sa, | ||
332 | OPEN_EXISTING, | ||
333 | FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, | ||
334 | NULL); | ||
335 | if (p->pipe[ic] == INVALID_HANDLE_VALUE) { | ||
336 | goto finito; | ||
337 | } | ||
338 | |||
339 | /* Make the parent end of the pipe non-inheritable */ | ||
340 | SetHandleInformation(p->pipe[ip], HANDLE_FLAG_INHERIT, 0); | ||
341 | |||
342 | /* Now create the child process */ | ||
343 | ZeroMemory(&siStartInfo, sizeof(STARTUPINFO)); | ||
344 | siStartInfo.cb = sizeof(STARTUPINFO); | ||
345 | siStartInfo.wShowWindow = SW_HIDE; | ||
346 | siStartInfo.hStdInput = p->pipe[ic]; | ||
347 | siStartInfo.hStdOutput = p->pipe[ic]; | ||
348 | siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); | ||
349 | siStartInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; | ||
350 | |||
351 | success = CreateProcess(NULL, | ||
352 | (LPTSTR)cmd, /* command line */ | ||
353 | NULL, /* process security attributes */ | ||
354 | NULL, /* primary thread security attributes */ | ||
355 | TRUE, /* handles are inherited */ | ||
356 | 0, /* creation flags */ | ||
357 | NULL, /* use parent's environment */ | ||
358 | NULL, /* use parent's current directory */ | ||
359 | &siStartInfo, /* STARTUPINFO pointer */ | ||
360 | &p->piProcInfo); /* receives PROCESS_INFORMATION */ | ||
361 | |||
362 | if ( !success ) { | ||
363 | goto finito; | ||
364 | } | ||
365 | |||
366 | /* close child end of pipe */ | ||
367 | CloseHandle(p->pipe[ic]); | ||
368 | p->pipe[ic] = INVALID_HANDLE_VALUE; | ||
369 | |||
370 | fd = _open_osfhandle((intptr_t)p->pipe[ip], _O_RDWR|_O_BINARY); | ||
371 | |||
372 | finito: | ||
373 | free(name); | ||
374 | if ( fd == -1 ) { | ||
375 | errno = err_win_to_posix(GetLastError()); | ||
376 | if ( p->pipe[0] != INVALID_HANDLE_VALUE ) { | ||
377 | CloseHandle(p->pipe[0]); | ||
378 | } | ||
379 | if ( p->pipe[1] != INVALID_HANDLE_VALUE ) { | ||
380 | CloseHandle(p->pipe[1]); | ||
381 | } | ||
382 | } | ||
383 | else { | ||
384 | p->mode = 'r'; | ||
385 | p->fd = fd; | ||
386 | if ( pid ) { | ||
387 | *pid = (pid_t)p->piProcInfo.dwProcessId; | ||
388 | } | ||
389 | } | ||
390 | |||
391 | return fd; | ||
392 | } | ||
393 | |||
291 | int mingw_pclose(FILE *fp) | 394 | int mingw_pclose(FILE *fp) |
292 | { | 395 | { |
293 | int i, ip, fd; | 396 | int i, ip, fd; |