aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpgetput.c6
-rw-r--r--networking/nc.c41
-rw-r--r--networking/ssl_client.c20
-rw-r--r--networking/tls.c6
-rw-r--r--networking/wget.c33
5 files changed, 89 insertions, 17 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index cb6910fb0..bff90538f 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -106,6 +106,9 @@ static int ftpcmd(const char *s1, const char *s2)
106 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3), 106 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3),
107 s1, s2); 107 s1, s2);
108 fflush(control_stream); 108 fflush(control_stream);
109#if ENABLE_PLATFORM_MINGW32
110 fseek(control_stream, 0L, SEEK_CUR);
111#endif
109 } 112 }
110 113
111 do { 114 do {
@@ -114,6 +117,9 @@ static int ftpcmd(const char *s1, const char *s2)
114 ftp_die(NULL); 117 ftp_die(NULL);
115 } 118 }
116 } while (!isdigit(buf[0]) || buf[3] != ' '); 119 } while (!isdigit(buf[0]) || buf[3] != ' ');
120#if ENABLE_PLATFORM_MINGW32
121 fseek(control_stream, 0L, SEEK_CUR);
122#endif
117 123
118 buf[3] = '\0'; 124 buf[3] = '\0';
119 n = xatou(buf); 125 n = xatou(buf);
diff --git a/networking/nc.c b/networking/nc.c
index b208f46c6..3e122b787 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -110,10 +110,12 @@
110 * when compared to "standard" nc 110 * when compared to "standard" nc
111 */ 111 */
112 112
113#if ENABLE_NC_EXTRA
113static void timeout(int signum UNUSED_PARAM) 114static void timeout(int signum UNUSED_PARAM)
114{ 115{
115 bb_error_msg_and_die("timed out"); 116 bb_error_msg_and_die("timed out");
116} 117}
118#endif
117 119
118int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 120int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
119int nc_main(int argc, char **argv) 121int nc_main(int argc, char **argv)
@@ -127,7 +129,7 @@ int nc_main(int argc, char **argv)
127 IF_NOT_NC_EXTRA (const) unsigned delay = 0; 129 IF_NOT_NC_EXTRA (const) unsigned delay = 0;
128 IF_NOT_NC_EXTRA (const int execparam = 0;) 130 IF_NOT_NC_EXTRA (const int execparam = 0;)
129 IF_NC_EXTRA (char **execparam = NULL;) 131 IF_NC_EXTRA (char **execparam = NULL;)
130 struct pollfd pfds[2]; 132 fd_set readfds, testfds;
131 int opt; /* must be signed (getopt returns -1) */ 133 int opt; /* must be signed (getopt returns -1) */
132 134
133 if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) { 135 if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) {
@@ -187,10 +189,12 @@ int nc_main(int argc, char **argv)
187 argv++; 189 argv++;
188 } 190 }
189 191
192#if ENABLE_NC_EXTRA
190 if (wsecs) { 193 if (wsecs) {
191 signal(SIGALRM, timeout); 194 signal(SIGALRM, timeout);
192 alarm(wsecs); 195 alarm(wsecs);
193 } 196 }
197#endif
194 198
195 if (!cfd) { 199 if (!cfd) {
196 if (do_listen) { 200 if (do_listen) {
@@ -208,7 +212,7 @@ int nc_main(int argc, char **argv)
208 } 212 }
209#endif 213#endif
210 close_on_exec_on(sfd); 214 close_on_exec_on(sfd);
211 accept_again: 215 IF_NC_EXTRA(accept_again:)
212 cfd = accept(sfd, NULL, 0); 216 cfd = accept(sfd, NULL, 0);
213 if (cfd < 0) 217 if (cfd < 0)
214 bb_perror_msg_and_die("accept"); 218 bb_perror_msg_and_die("accept");
@@ -226,6 +230,7 @@ int nc_main(int argc, char **argv)
226 /*signal(SIGALRM, SIG_DFL);*/ 230 /*signal(SIGALRM, SIG_DFL);*/
227 } 231 }
228 232
233#if ENABLE_NC_EXTRA
229 /* -e given? */ 234 /* -e given? */
230 if (execparam) { 235 if (execparam) {
231 pid_t pid; 236 pid_t pid;
@@ -244,29 +249,31 @@ int nc_main(int argc, char **argv)
244 IF_NC_EXTRA(BB_EXECVP(execparam[0], execparam);) 249 IF_NC_EXTRA(BB_EXECVP(execparam[0], execparam);)
245 IF_NC_EXTRA(bb_perror_msg_and_die("can't execute '%s'", execparam[0]);) 250 IF_NC_EXTRA(bb_perror_msg_and_die("can't execute '%s'", execparam[0]);)
246 } 251 }
252#endif
247 253
248 /* loop copying stdin to cfd, and cfd to stdout */ 254 /* Select loop copying stdin to cfd, and cfd to stdout */
249 255
250 pfds[0].fd = STDIN_FILENO; 256 FD_ZERO(&readfds);
251 pfds[0].events = POLLIN; 257 FD_SET(cfd, &readfds);
252 pfds[1].fd = cfd; 258 FD_SET(STDIN_FILENO, &readfds);
253 pfds[1].events = POLLIN;
254 259
255#define iobuf bb_common_bufsiz1 260#define iobuf bb_common_bufsiz1
256 setup_common_bufsiz(); 261 setup_common_bufsiz();
257 for (;;) { 262 for (;;) {
258 int fdidx; 263 int fd;
259 int ofd; 264 int ofd;
260 int nread; 265 int nread;
261 266
262 if (safe_poll(pfds, 2, -1) < 0) 267 testfds = readfds;
263 bb_perror_msg_and_die("poll"); 268
269 if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0)
270 bb_perror_msg_and_die("select");
264 271
265 fdidx = 0; 272 fd = STDIN_FILENO;
266 while (1) { 273 while (1) {
267 if (pfds[fdidx].revents) { 274 if (FD_ISSET(fd, &testfds)) {
268 nread = safe_read(pfds[fdidx].fd, iobuf, COMMON_BUFSIZE); 275 nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
269 if (fdidx != 0) { 276 if (fd == cfd) {
270 if (nread < 1) 277 if (nread < 1)
271 exit(EXIT_SUCCESS); 278 exit(EXIT_SUCCESS);
272 ofd = STDOUT_FILENO; 279 ofd = STDOUT_FILENO;
@@ -275,7 +282,7 @@ int nc_main(int argc, char **argv)
275 /* Close outgoing half-connection so they get EOF, 282 /* Close outgoing half-connection so they get EOF,
276 * but leave incoming alone so we can see response */ 283 * but leave incoming alone so we can see response */
277 shutdown(cfd, SHUT_WR); 284 shutdown(cfd, SHUT_WR);
278 pfds[0].fd = -1; 285 FD_CLR(STDIN_FILENO, &readfds);
279 } 286 }
280 ofd = cfd; 287 ofd = cfd;
281 } 288 }
@@ -283,9 +290,9 @@ int nc_main(int argc, char **argv)
283 if (delay > 0) 290 if (delay > 0)
284 sleep(delay); 291 sleep(delay);
285 } 292 }
286 if (fdidx == 1) 293 if (fd == cfd)
287 break; 294 break;
288 fdidx++; 295 fd = cfd;
289 } 296 }
290 } 297 }
291} 298}
diff --git a/networking/ssl_client.c b/networking/ssl_client.c
index 397aad297..cd0ee5722 100644
--- a/networking/ssl_client.c
+++ b/networking/ssl_client.c
@@ -15,7 +15,12 @@
15//kbuild:lib-$(CONFIG_SSL_CLIENT) += ssl_client.o 15//kbuild:lib-$(CONFIG_SSL_CLIENT) += ssl_client.o
16 16
17//usage:#define ssl_client_trivial_usage 17//usage:#define ssl_client_trivial_usage
18//usage: IF_NOT_PLATFORM_MINGW32(
18//usage: "[-e] -s FD [-r FD] [-n SNI]" 19//usage: "[-e] -s FD [-r FD] [-n SNI]"
20//usage: )
21//usage: IF_PLATFORM_MINGW32(
22//usage: "[-e] -h handle [-n SNI]"
23//usage: )
19//usage:#define ssl_client_full_usage "" 24//usage:#define ssl_client_full_usage ""
20 25
21#include "libbb.h" 26#include "libbb.h"
@@ -26,15 +31,23 @@ int ssl_client_main(int argc UNUSED_PARAM, char **argv)
26 tls_state_t *tls; 31 tls_state_t *tls;
27 const char *sni = NULL; 32 const char *sni = NULL;
28 int opt; 33 int opt;
34#if ENABLE_PLATFORM_MINGW32
35 char *hstr = NULL;
36 HANDLE h;
37#endif
29 38
30 // INIT_G(); 39 // INIT_G();
31 40
32 tls = new_tls_state(); 41 tls = new_tls_state();
42#if !ENABLE_PLATFORM_MINGW32
33 opt = getopt32(argv, "es:+r:+n:", &tls->ofd, &tls->ifd, &sni); 43 opt = getopt32(argv, "es:+r:+n:", &tls->ofd, &tls->ifd, &sni);
34 if (!(opt & (1<<2))) { 44 if (!(opt & (1<<2))) {
35 /* -r N defaults to -s N */ 45 /* -r N defaults to -s N */
36 tls->ifd = tls->ofd; 46 tls->ifd = tls->ofd;
37 } 47 }
48#else
49 opt = getopt32(argv, "eh:n:", &hstr, &sni);
50#endif
38 51
39 if (!(opt & (3<<1))) { 52 if (!(opt & (3<<1))) {
40 if (!argv[1]) 53 if (!argv[1])
@@ -47,6 +60,13 @@ int ssl_client_main(int argc UNUSED_PARAM, char **argv)
47 sni = argv[1]; 60 sni = argv[1];
48 tls->ifd = tls->ofd = create_and_connect_stream_or_die(argv[1], 443); 61 tls->ifd = tls->ofd = create_and_connect_stream_or_die(argv[1], 443);
49 } 62 }
63#if ENABLE_PLATFORM_MINGW32
64 else {
65 if (!hstr || sscanf(hstr, "%p", &h) != 1)
66 bb_error_msg_and_die("invalid handle");
67 tls->ifd = tls->ofd = _open_osfhandle((intptr_t)h, _O_RDWR|_O_BINARY);
68 }
69#endif
50 70
51 tls_handshake(tls, sni); 71 tls_handshake(tls, sni);
52 72
diff --git a/networking/tls.c b/networking/tls.c
index db7be07f3..d1a0204ed 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -351,8 +351,14 @@ static void dump_tls_record(const void *vp, int len)
351 351
352void FAST_FUNC tls_get_random(void *buf, unsigned len) 352void FAST_FUNC tls_get_random(void *buf, unsigned len)
353{ 353{
354#if !ENABLE_PLATFORM_MINGW32
354 if (len != open_read_close("/dev/urandom", buf, len)) 355 if (len != open_read_close("/dev/urandom", buf, len))
355 xfunc_die(); 356 xfunc_die();
357#else
358 int fd = mingw_open("/dev/urandom", O_RDONLY|O_SPECIAL);
359 if (fd < 0 || len != read_close(fd, buf, len))
360 xfunc_die();
361#endif
356} 362}
357 363
358static void xorbuf3(void *dst, const void *src1, const void *src2, unsigned count) 364static void xorbuf3(void *dst, const void *src1, const void *src2, unsigned count)
diff --git a/networking/wget.c b/networking/wget.c
index b6f9d605a..44cec2cb5 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -486,6 +486,9 @@ static int ftpcmd(const char *s1, const char *s2, FILE *fp)
486 fprintf(stderr, "--> %s%s\n\n", s1, s2); 486 fprintf(stderr, "--> %s%s\n\n", s1, s2);
487 fflush(fp); 487 fflush(fp);
488 log_io("> %s%s", s1, s2); 488 log_io("> %s%s", s1, s2);
489#if ENABLE_PLATFORM_MINGW32
490 fseek(fp, 0L, SEEK_CUR);
491#endif
489 } 492 }
490 493
491 /* Read until "Nxx something" is received */ 494 /* Read until "Nxx something" is received */
@@ -493,6 +496,9 @@ static int ftpcmd(const char *s1, const char *s2, FILE *fp)
493 do { 496 do {
494 fgets_trim_sanitize(fp, "%s\n"); 497 fgets_trim_sanitize(fp, "%s\n");
495 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' '); 498 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' ');
499#if ENABLE_PLATFORM_MINGW32
500 fseek(fp, 0L, SEEK_CUR);
501#endif
496 502
497 G.wget_buf[3] = '\0'; 503 G.wget_buf[3] = '\0';
498 result = xatoi_positive(G.wget_buf); 504 result = xatoi_positive(G.wget_buf);
@@ -716,6 +722,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
716#endif 722#endif
717 723
718#if ENABLE_FEATURE_WGET_HTTPS 724#if ENABLE_FEATURE_WGET_HTTPS
725# if !ENABLE_PLATFORM_MINGW32
719static void spawn_ssl_client(const char *host, int network_fd, int flags) 726static void spawn_ssl_client(const char *host, int network_fd, int flags)
720{ 727{
721 int sp[2]; 728 int sp[2];
@@ -770,6 +777,32 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags)
770 close(sp[1]); 777 close(sp[1]);
771 xmove_fd(sp[0], network_fd); 778 xmove_fd(sp[0], network_fd);
772} 779}
780# else
781static void spawn_ssl_client(const char *host, int network_fd, int flags)
782{
783 int fd1;
784 char *servername, *p, *cmd;
785
786 servername = xstrdup(host);
787 p = strrchr(servername, ':');
788 if (p) *p = '\0';
789
790 fflush_all();
791
792 cmd = xasprintf("%s --busybox ssl_client -h %p -n %s%s",
793 bb_busybox_exec_path,
794 (void *)_get_osfhandle(network_fd), servername,
795 flags & TLSLOOP_EXIT_ON_LOCAL_EOF ? " -e" : "");
796
797 if ( (fd1=mingw_popen_fd(cmd, "b", -1, NULL)) == -1 ) {
798 bb_perror_msg_and_die("can't execute ssl_client");
799 }
800
801 free(cmd);
802 free(servername);
803 xmove_fd(fd1, network_fd);
804}
805# endif
773#endif 806#endif
774 807
775static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) 808static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)