-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathcurl.patch
5366 lines (5219 loc) · 190 KB
/
curl.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Naur curl-105/Info.plist curl/Info.plist
--- curl-105/Info.plist 1970-01-01 01:00:00.000000000 +0100
+++ curl/Info.plist 2018-12-08 16:03:39.000000000 +0100
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>$(CURRENT_PROJECT_VERSION)</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
diff -Naur curl-105/config_iphone/curl_config.h curl/config_iphone/curl_config.h
--- curl-105/config_iphone/curl_config.h 2017-05-24 02:47:37.000000000 +0200
+++ curl/config_iphone/curl_config.h 2018-12-08 16:03:39.000000000 +0100
@@ -410,6 +410,7 @@
/* Define to 1 if you have the <libssh2.h> header file. */
/* #undef HAVE_LIBSSH2_H */
+#define HAVE_LIBSSH2_H 1
/* Define to 1 if you have the `ssl' library (-lssl). */
/* #undef HAVE_LIBSSL */
@@ -801,6 +802,7 @@
/* cpu-machine-OS */
/* #undef OS */
+#define OS "iPhoneOS"
/* Name of package */
#define PACKAGE "curl"
@@ -952,6 +954,7 @@
/* if libSSH2 is in use */
/* #undef USE_LIBSSH2 */
+#define USE_LIBSSH2
/* If you want to build curl with the built-in manual */
#define USE_MANUAL 1
@@ -963,7 +966,7 @@
/* #undef USE_METALINK */
/* if nghttp2 is in use */
-#define USE_NGHTTP2 1
+// #define USE_NGHTTP2 1
/* if NSS is enabled */
/* #undef USE_NSS */
diff -Naur curl-105/curl/include/curl/curl.h curl/curl/include/curl/curl.h
--- curl-105/curl/include/curl/curl.h 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/include/curl/curl.h 2018-12-08 16:03:39.000000000 +0100
@@ -2391,7 +2391,7 @@
callback functions */
CURLSHOPT_LAST /* never use */
} CURLSHoption;
-
+
CURL_EXTERN CURLSH *curl_share_init(void);
CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...);
CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *);
diff -Naur curl-105/curl/lib/conncache.c curl/curl/lib/conncache.c
--- curl-105/curl/lib/conncache.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/conncache.c 2018-12-08 16:03:39.000000000 +0100
@@ -335,7 +335,7 @@
if(!connc)
return;
- fprintf(stderr, "=Bundle cache=\n");
+ fprintf(thread_stderr, "=Bundle cache=\n");
Curl_hash_start_iterate(connc->hash, &iter);
@@ -346,15 +346,15 @@
bundle = he->ptr;
- fprintf(stderr, "%s -", he->key);
+ fprintf(thread_stderr, "%s -", he->key);
curr = bundle->conn_list->head;
while(curr) {
conn = curr->ptr;
- fprintf(stderr, " [%p %d]", (void *)conn, conn->inuse);
+ fprintf(thread_stderr, " [%p %d]", (void *)conn, conn->inuse);
curr = curr->next;
}
- fprintf(stderr, "\n");
+ fprintf(thread_stderr, "\n");
he = Curl_hash_next_element(&iter);
}
diff -Naur curl-105/curl/lib/cookie.c curl/curl/lib/cookie.c
--- curl-105/curl/lib/cookie.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/cookie.c 2018-12-08 16:03:39.000000000 +0100
@@ -81,6 +81,7 @@
#include "curl_setup.h"
+#include "ios_error.h"
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
@@ -976,7 +977,7 @@
c->running = FALSE; /* this is not running, this is init */
if(file && !strcmp(file, "-")) {
- fp = stdin;
+ fp = thread_stdin;
fromfile=FALSE;
}
else if(file && !*file) {
@@ -1348,7 +1349,7 @@
if(!strcmp("-", dumphere)) {
/* use stdout */
- out = stdout;
+ out = thread_stdout;
use_stdout=TRUE;
}
else {
diff -Naur curl-105/curl/lib/curl_ntlm_wb.c curl/curl/lib/curl_ntlm_wb.c
--- curl-105/curl/lib/curl_ntlm_wb.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/curl_ntlm_wb.c 2018-12-08 16:03:39.000000000 +0100
@@ -52,6 +52,7 @@
#include "url.h"
#include "strerror.h"
#include "strdup.h"
+#include "ios_error.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -207,14 +208,14 @@
/* Don't use sclose in the child since it fools the socket leak detector */
sclose_nolog(sockfds[0]);
- if(dup2(sockfds[1], STDIN_FILENO) == -1) {
+ if(dup2(sockfds[1], fileno(thread_stdin)) == -1) {
error = ERRNO;
failf(conn->data, "Could not redirect child stdin. errno %d: %s",
error, Curl_strerror(conn, error));
exit(1);
}
- if(dup2(sockfds[1], STDOUT_FILENO) == -1) {
+ if(dup2(sockfds[1], fileno(thread_stdout)) == -1) {
error = ERRNO;
failf(conn->data, "Could not redirect child stdout. errno %d: %s",
error, Curl_strerror(conn, error));
@@ -393,7 +394,7 @@
*allocuserpwd = aprintf("%sAuthorization: %s\r\n",
proxy ? "Proxy-" : "",
conn->response_header);
- DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
+ DEBUG_OUT(fprintf(thread_stderr, "**** Header %s\n ", *allocuserpwd));
free(conn->response_header);
conn->response_header = NULL;
break;
@@ -411,7 +412,7 @@
*allocuserpwd = aprintf("%sAuthorization: %s\r\n",
proxy ? "Proxy-" : "",
conn->response_header);
- DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
+ DEBUG_OUT(fprintf(thread_stderr, "**** %s\n ", *allocuserpwd));
ntlm->state = NTLMSTATE_TYPE3; /* we sent a type-3 */
authp->done = TRUE;
Curl_ntlm_wb_cleanup(conn);
diff -Naur curl-105/curl/lib/easy.c curl/curl/lib/easy.c
--- curl-105/curl/lib/easy.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/easy.c 2018-12-08 16:03:39.000000000 +0100
@@ -216,31 +216,31 @@
if(flags & CURL_GLOBAL_SSL)
if(!Curl_ssl_init()) {
- DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: Curl_ssl_init failed\n"));
return CURLE_FAILED_INIT;
}
if(flags & CURL_GLOBAL_WIN32)
if(win32_init()) {
- DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: win32_init failed\n"));
return CURLE_FAILED_INIT;
}
#ifdef __AMIGA__
if(!Curl_amiga_init()) {
- DEBUGF(fprintf(stderr, "Error: Curl_amiga_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: Curl_amiga_init failed\n"));
return CURLE_FAILED_INIT;
}
#endif
#ifdef NETWARE
if(netware_init()) {
- DEBUGF(fprintf(stderr, "Warning: LONG namespace not available\n"));
+ DEBUGF(fprintf(thread_stderr, "Warning: LONG namespace not available\n"));
}
#endif
if(Curl_resolver_global_init()) {
- DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: resolver_global_init failed\n"));
return CURLE_FAILED_INIT;
}
@@ -248,7 +248,7 @@
#if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_INIT)
if(libssh2_init(0)) {
- DEBUGF(fprintf(stderr, "Error: libssh2_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: libssh2_init failed\n"));
return CURLE_FAILED_INIT;
}
#endif
@@ -350,7 +350,7 @@
result = curl_global_init(CURL_GLOBAL_DEFAULT);
if(result) {
/* something in the global init failed, return nothing */
- DEBUGF(fprintf(stderr, "Error: curl_global_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: curl_global_init failed\n"));
return NULL;
}
}
@@ -358,7 +358,7 @@
/* We use curl_open() with undefined URL so far */
result = Curl_open(&data);
if(result) {
- DEBUGF(fprintf(stderr, "Error: Curl_open failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: Curl_open failed\n"));
return NULL;
}
@@ -511,7 +511,7 @@
if(!m) {
if(what == CURL_POLL_REMOVE) {
/* this happens a bit too often, libcurl fix perhaps? */
- /* fprintf(stderr,
+ /* fprintf(thread_stderr,
"%s: socket %d asked to be REMOVED but not present!\n",
__func__, s); */
}
@@ -580,7 +580,7 @@
f->fd = m->socket.fd;
f->events = m->socket.events;
f->revents = 0;
- /* fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); */
+ /* fprintf(thread_stderr, "poll() %d check socket %d\n", numfds, f->fd); */
f++;
numfds++;
}
@@ -598,7 +598,7 @@
if(0 == pollrc) {
/* timeout! */
ev->ms = 0;
- /* fprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
+ /* fprintf(thread_stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
&ev->running_handles);
}
diff -Naur curl-105/curl/lib/formdata.c curl/curl/lib/formdata.c
--- curl-105/curl/lib/formdata.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/formdata.c 2018-12-08 16:03:39.000000000 +0100
@@ -37,6 +37,8 @@
#include "sendf.h"
#include "strdup.h"
#include "rand.h"
+#include "ios_error.h"
+
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -1306,7 +1308,7 @@
FILE *fileread;
fileread = !strcmp("-", file->contents)?
- stdin:fopen(file->contents, "rb"); /* binary read for win32 */
+ thread_stdin:fopen(file->contents, "rb"); /* binary read for win32 */
/*
* VMS: This only allows for stream files on VMS. Stream files are
@@ -1315,7 +1317,7 @@
*/
if(fileread) {
- if(fileread != stdin) {
+ if(fileread != thread_stdin) {
/* close the file */
fclose(fileread);
/* add the file name only - for later reading from this */
diff -Naur curl-105/curl/lib/hash.c curl/curl/lib/hash.c
--- curl-105/curl/lib/hash.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/hash.c 2018-12-08 16:03:39.000000000 +0100
@@ -336,16 +336,16 @@
if(!h)
return;
- fprintf(stderr, "=Hash dump=\n");
+ fprintf(thread_stderr, "=Hash dump=\n");
Curl_hash_start_iterate(h, &iter);
he = Curl_hash_next_element(&iter);
while(he) {
if(iter.slot_index != last_index) {
- fprintf(stderr, "index %d:", iter.slot_index);
+ fprintf(thread_stderr, "index %d:", iter.slot_index);
if(last_index >= 0) {
- fprintf(stderr, "\n");
+ fprintf(thread_stderr, "\n");
}
last_index = iter.slot_index;
}
@@ -353,10 +353,10 @@
if(func)
func(he->ptr);
else
- fprintf(stderr, " [%p]", (void *)he->ptr);
+ fprintf(thread_stderr, " [%p]", (void *)he->ptr);
he = Curl_hash_next_element(&iter);
}
- fprintf(stderr, "\n");
+ fprintf(thread_stderr, "\n");
}
#endif
diff -Naur curl-105/curl/lib/hostip6.c curl/curl/lib/hostip6.c
--- curl-105/curl/lib/hostip6.c 2016-11-04 22:42:50.000000000 +0100
+++ curl/curl/lib/hostip6.c 2018-12-08 16:03:39.000000000 +0100
@@ -132,16 +132,16 @@
#ifdef DEBUG_ADDRINFO
static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai)
{
- printf("dump_addrinfo:\n");
+ fprintf(thread_stdout, "dump_addrinfo:\n");
for(; ai; ai = ai->ai_next) {
char buf[INET6_ADDRSTRLEN];
- printf(" fam %2d, CNAME %s, ",
+ fprintf(thread_stdout, " fam %2d, CNAME %s, ",
ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
if(Curl_printable_address(ai, buf, sizeof(buf)))
- printf("%s\n", buf);
+ fprintf(thread_stdout, "%s\n", buf);
else
- printf("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
+ fprintf(thread_stdout, "failed; %s\n", Curl_strerror(conn, SOCKERRNO));
}
}
#else
diff -Naur curl-105/curl/lib/http_ntlm.c curl/curl/lib/http_ntlm.c
--- curl-105/curl/lib/http_ntlm.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/http_ntlm.c 2018-12-08 16:03:39.000000000 +0100
@@ -184,7 +184,7 @@
if(!*allocuserpwd)
return CURLE_OUT_OF_MEMORY;
- DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
+ DEBUG_OUT(fprintf(thread_stderr, "**** Header %s\n ", *allocuserpwd));
}
break;
@@ -204,7 +204,7 @@
if(!*allocuserpwd)
return CURLE_OUT_OF_MEMORY;
- DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
+ DEBUG_OUT(fprintf(thread_stderr, "**** %s\n ", *allocuserpwd));
ntlm->state = NTLMSTATE_TYPE3; /* we send a type-3 */
authp->done = TRUE;
diff -Naur curl-105/curl/lib/ldap.c curl/curl/lib/ldap.c
--- curl-105/curl/lib/ldap.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/ldap.c 2018-12-08 16:03:39.000000000 +0100
@@ -702,7 +702,7 @@
return;
va_start(args, fmt);
- vfprintf(stderr, fmt, args);
+ vfprintf(thread_stderr, fmt, args);
va_end(args);
}
#endif
diff -Naur curl-105/curl/lib/memdebug.c curl/curl/lib/memdebug.c
--- curl-105/curl/lib/memdebug.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/memdebug.c 2018-12-08 16:03:39.000000000 +0100
@@ -116,7 +116,7 @@
if(logname && *logname)
logfile = fopen(logname, FOPEN_WRITETEXT);
else
- logfile = stderr;
+ logfile = thread_stderr;
#ifdef MEMDEBUG_LOG_SYNC
/* Flush the log file after every line so the log isn't lost in a crash */
setbuf(logfile, (char *)NULL);
@@ -146,7 +146,7 @@
curl_memlog("LIMIT %s:%d %s reached memlimit\n",
source, line, func);
/* log to stderr also */
- fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
+ fprintf(thread_stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func);
fflush(logfile); /* because it might crash now */
}
diff -Naur curl-105/curl/lib/mprintf.c curl/curl/lib/mprintf.c
--- curl-105/curl/lib/mprintf.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/mprintf.c 2018-12-08 16:03:39.000000000 +0100
@@ -39,6 +39,7 @@
#include <curl/mprintf.h>
#include "curl_memory.h"
+#include "ios_error.h"
/* The last #include file should be: */
#include "memdebug.h"
@@ -1149,7 +1150,7 @@
va_list ap_save; /* argument pointer */
va_start(ap_save, format);
- retcode = dprintf_formatf(stdout, fputc, format, ap_save);
+ retcode = dprintf_formatf(thread_stdout, fputc, format, ap_save);
va_end(ap_save);
return retcode;
}
@@ -1174,7 +1175,7 @@
int curl_mvprintf(const char *format, va_list ap_save)
{
- return dprintf_formatf(stdout, fputc, format, ap_save);
+ return dprintf_formatf(thread_stdout, fputc, format, ap_save);
}
int curl_mvfprintf(FILE *whereto, const char *format, va_list ap_save)
diff -Naur curl-105/curl/lib/multi.c curl/curl/lib/multi.c
--- curl-105/curl/lib/multi.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/multi.c 2018-12-08 16:03:39.000000000 +0100
@@ -474,7 +474,7 @@
{
struct Curl_sh_entry *sh = (struct Curl_sh_entry *)p;
- fprintf(stderr, " [easy %p/magic %x/socket %d]",
+ fprintf(thread_stderr, " [easy %p/magic %x/socket %d]",
(void *)sh->data, sh->data->magic, (int)sh->socket);
}
#endif
@@ -3130,29 +3130,29 @@
{
struct Curl_easy *data;
int i;
- fprintf(stderr, "* Multi status: %d handles, %d alive\n",
+ fprintf(thread_stderr, "* Multi status: %d handles, %d alive\n",
multi->num_easy, multi->num_alive);
for(data=multi->easyp; data; data = data->next) {
if(data->mstate < CURLM_STATE_COMPLETED) {
/* only display handles that are not completed */
- fprintf(stderr, "handle %p, state %s, %d sockets\n",
+ fprintf(thread_stderr, "handle %p, state %s, %d sockets\n",
(void *)data,
statename[data->mstate], data->numsocks);
for(i=0; i < data->numsocks; i++) {
curl_socket_t s = data->sockets[i];
struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
- fprintf(stderr, "%d ", (int)s);
+ fprintf(thread_stderr, "%d ", (int)s);
if(!entry) {
- fprintf(stderr, "INTERNAL CONFUSION\n");
+ fprintf(thread_stderr, "INTERNAL CONFUSION\n");
continue;
}
- fprintf(stderr, "[%s %s] ",
+ fprintf(thread_stderr, "[%s %s] ",
entry->action&CURL_POLL_IN?"RECVING":"",
entry->action&CURL_POLL_OUT?"SENDING":"");
}
if(data->numsocks)
- fprintf(stderr, "\n");
+ fprintf(thread_stderr, "\n");
}
}
}
diff -Naur curl-105/curl/lib/netrc.c curl/curl/lib/netrc.c
--- curl-105/curl/lib/netrc.c 2016-11-04 22:42:50.000000000 +0100
+++ curl/curl/lib/netrc.c 2018-12-08 16:03:39.000000000 +0100
@@ -69,7 +69,8 @@
if(!netrcfile) {
bool home_alloc = FALSE;
- char *home = curl_getenv("HOME"); /* portable environment reader */
+ char *home = curl_getenv("CURL_HOME"); /* portable environment reader */
+ if (!home) home = curl_getenv("HOME"); /* portable environment reader */
if(home) {
home_alloc = TRUE;
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
diff -Naur curl-105/curl/lib/ssh.c curl/curl/lib/ssh.c
--- curl-105/curl/lib/ssh.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/ssh.c 2018-12-08 16:03:39.000000000 +0100
@@ -26,6 +26,13 @@
#ifdef USE_LIBSSH2
+// If we have Blinkshell, we use their key management:
+#ifdef BLINKSHELL
+#import "BKDefaults.h"
+#import "BKHosts.h"
+#import "BKPubKey.h"
+#endif
+
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
@@ -218,11 +225,11 @@
struct connectdata *conn = (struct connectdata *)*abstract;
#ifdef CURL_LIBSSH2_DEBUG
- fprintf(stderr, "name=%s\n", name);
- fprintf(stderr, "name_len=%d\n", name_len);
- fprintf(stderr, "instruction=%s\n", instruction);
- fprintf(stderr, "instruction_len=%d\n", instruction_len);
- fprintf(stderr, "num_prompts=%d\n", num_prompts);
+ fprintf(thread_stderr, "name=%s\n", name);
+ fprintf(thread_stderr, "name_len=%d\n", name_len);
+ fprintf(thread_stderr, "instruction=%s\n", instruction);
+ fprintf(thread_stderr, "instruction_len=%d\n", instruction_len);
+ fprintf(thread_stderr, "num_prompts=%d\n", num_prompts);
#else
(void)name;
(void)name_len;
@@ -714,6 +721,16 @@
int err;
int seekerr = CURL_SEEKFUNC_OK;
*block = 0; /* we're not blocking by default */
+ // data->set.verbose = true;
+#ifdef BLINKSHELL // Blinkshell generates keys and stores them
+ // Blinkshell: did we find the keys in the KeyChain?
+ char *publicKeyMemory = NULL;
+ char *privateKeyMemory = NULL;
+ BKHosts *host;
+ BKPubKey *pk;
+
+ host = [BKHosts withHost:[NSString stringWithUTF8String:conn->host.rawalloc]];
+#endif
do {
@@ -810,13 +827,63 @@
/* To ponder about: should really the lib be messing about with the
HOME environment variable etc? */
- home = curl_getenv("HOME");
-
+ // iOS specifics: $HOME/.ssh is unreadable (sandbox), we store keys in ~/Documents/.ssh/
+ home = curl_getenv("SSH_HOME");
+ if (!home) home = curl_getenv("HOME");
+
+ // iOS secure storing options (key, username, password)
+ // Find the private key:
+ // a) if the user specified a private key, use it:
if(data->set.str[STRING_SSH_PRIVATE_KEY])
- sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]);
+ sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); // it's a string
else {
+#ifdef BLINKSHELL
+ // b) if running inside Blinkshell, use their storage options:
+ if (host) {
+ if (!sshc->passphrase && host.password) sshc->passphrase = [host.password UTF8String];
+ // Find the stored key that corresponds to the key name:
+ publicKeyMemory = NULL; privateKeyMemory = NULL;
+ if (data->set.str[STRING_SSH_PRIVATE_KEY]) {
+ // Priority 1: user specified a key name, different from default
+ // key associated with this hostname
+ if ((pk = [BKPubKey withID:[NSString stringWithUTF8String:data->set.str[STRING_SSH_PRIVATE_KEY]]]) != nil) {
+ publicKeyMemory = [pk.publicKey UTF8String];
+ privateKeyMemory = [pk.privateKey UTF8String];
+ sshc->rsa = data->set.str[STRING_SSH_PRIVATE_KEY];
+ }
+ }
+ if (!(privateKeyMemory && publicKeyMemory)) {
+ // Priority 2: default key associated with the host
+ if (host.key) {
+ if ((pk = [BKPubKey withID:host.key]) != nil) {
+ publicKeyMemory = [pk.publicKey UTF8String];
+ privateKeyMemory = [pk.privateKey UTF8String];
+ sshc->rsa = strdup(host.key.UTF8String);
+ }
+ }
+ }
+
+ } else {
+
+ if (!(privateKeyMemory && publicKeyMemory)) {
+ // Priority 2: key named id_rsa:
+ if ((pk = [BKPubKey withID:@"id_rsa"]) != nil) {
+ publicKeyMemory = [pk.publicKey UTF8String];
+ privateKeyMemory = [pk.privateKey UTF8String];
+ sshc->rsa = strdup("id_rsa");
+ }
+ }
+ if (!(privateKeyMemory && publicKeyMemory)) {
+ // Still no luck, try with id_dsa:
+ if ((pk = [BKPubKey withID:@"id_dsa"]) != nil) {
+ publicKeyMemory = [pk.publicKey UTF8String];
+ privateKeyMemory = [pk.privateKey UTF8String];
+ sshc->rsa = strdup("id_dsa");
+ }
+ }
+#endif
/* If no private key file is specified, try some common paths. */
- if(home) {
+ if(home && !sshc->rsa) {
/* Try ~/.ssh first. */
sshc->rsa = aprintf("%s/.ssh/id_rsa", home);
if(!sshc->rsa)
@@ -831,6 +898,9 @@
}
}
}
+#ifdef BLINKSHELL
+ }
+#endif
if(!out_of_memory && !sshc->rsa) {
/* Nothing found; try the current dir. */
sshc->rsa = strdup("id_rsa");
@@ -852,6 +922,9 @@
* libssh2 extract the public key from the private key file.
* This is done by simply passing sshc->rsa_pub = NULL.
*/
+#ifdef BLINKSHELL
+ if (!(privateKeyMemory && publicKeyMemory)) {
+#endif
if(data->set.str[STRING_SSH_PUBLIC_KEY]
/* treat empty string the same way as NULL */
&& data->set.str[STRING_SSH_PUBLIC_KEY][0]) {
@@ -859,6 +932,9 @@
if(!sshc->rsa_pub)
out_of_memory = TRUE;
}
+#ifdef BLINKSHELL
+ }
+#endif
if(out_of_memory || sshc->rsa == NULL) {
free(home);
@@ -869,15 +945,22 @@
break;
}
- sshc->passphrase = data->set.ssl.key_passwd;
- if(!sshc->passphrase)
- sshc->passphrase = "";
+ if (!sshc->passphrase) sshc->passphrase = data->set.ssl.key_passwd;
+ if (!sshc->passphrase) sshc->passphrase = "";
free(home);
+#ifdef BLINKSHELL
+ if (!(privateKeyMemory && publicKeyMemory)) {
+#endif
if(sshc->rsa_pub)
infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
infof(data, "Using SSH private key file '%s'\n", sshc->rsa);
+#ifdef BLINKSHELL
+ } else {
+ infof(data, "Using private key stored in BlinkShell keys: '%s'\n", sshc->rsa);
+ }
+#endif
state(conn, SSH_AUTH_PKEY);
}
@@ -889,12 +972,25 @@
case SSH_AUTH_PKEY:
/* The function below checks if the files exists, no need to stat() here.
*/
- rc = libssh2_userauth_publickey_fromfile_ex(sshc->ssh_session,
+#ifdef BLINKSHELL
+ if (!(privateKeyMemory && publicKeyMemory))
+#endif
+ while ((rc = libssh2_userauth_publickey_fromfile_ex(sshc->ssh_session,
conn->user,
curlx_uztoui(
strlen(conn->user)),
sshc->rsa_pub,
- sshc->rsa, sshc->passphrase);
+ sshc->rsa, sshc->passphrase)) == LIBSSH2_ERROR_EAGAIN) ;
+#ifdef BLINKSHELL
+ else
+ while ((rc = libssh2_userauth_publickey_frommemory(sshc->ssh_session,
+ conn->user,
+ curlx_uztoui(
+ strlen(conn->user)),
+ publicKeyMemory, strlen(publicKeyMemory),
+ privateKeyMemory, strlen(privateKeyMemory),
+ sshc->passphrase)) == LIBSSH2_ERROR_EAGAIN);
+#endif
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
diff -Naur curl-105/curl/lib/url.c curl/curl/lib/url.c
--- curl-105/curl/lib/url.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/url.c 2018-12-08 16:03:39.000000000 +0100
@@ -119,6 +119,18 @@
#include "pipeline.h"
#include "dotdot.h"
#include "strdup.h"
+
+// If we have Blinkshell, we use their key management:
+#ifdef BLINKSHELL
+#import "BKDefaults.h"
+#import "BKHosts.h"
+#endif
+
+// from ios_error.h, but without the compileError:
+// Thread-local input and output streams
+extern __thread FILE* thread_stdin;
+extern __thread FILE* thread_stdout;
+extern __thread FILE* thread_stderr;
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -491,9 +503,9 @@
{
CURLcode result = CURLE_OK;
- set->out = stdout; /* default output to stdout */
- set->in_set = stdin; /* default input from stdin */
- set->err = stderr; /* default stderr to stderr */
+ set->out = thread_stdout; /* default output to stdout */
+ set->in_set = thread_stdin; /* default input from stdin */
+ set->err = thread_stderr; /* default stderr to stderr */
/* use fwrite as default function to store output */
set->fwrite_func = (curl_write_callback)fwrite;
@@ -629,7 +641,7 @@
data = calloc(1, sizeof(struct Curl_easy));
if(!data) {
/* this is a very serious error */
- DEBUGF(fprintf(stderr, "Error: calloc of Curl_easy failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: calloc of Curl_easy failed\n"));
return CURLE_OUT_OF_MEMORY;
}
@@ -637,7 +649,7 @@
result = Curl_resolver_init(&data->state.resolver);
if(result) {
- DEBUGF(fprintf(stderr, "Error: resolver_init failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: resolver_init failed\n"));
free(data);
return result;
}
@@ -646,13 +658,13 @@
data->state.buffer = malloc(BUFSIZE + 1);
if(!data->state.buffer) {
- DEBUGF(fprintf(stderr, "Error: malloc of buffer failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: malloc of buffer failed\n"));
result = CURLE_OUT_OF_MEMORY;
}
data->state.headerbuff = malloc(HEADERSIZE);
if(!data->state.headerbuff) {
- DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: malloc of headerbuff failed\n"));
result = CURLE_OUT_OF_MEMORY;
}
else {
@@ -1881,7 +1893,7 @@
*/
data->set.err = va_arg(param, FILE *);
if(!data->set.err)
- data->set.err = stderr;
+ data->set.err = thread_stderr;
break;
case CURLOPT_HEADERFUNCTION:
/*
@@ -2296,7 +2308,7 @@
data->state.buffer = realloc(data->state.buffer,
data->set.buffer_size + 1);
if(!data->state.buffer) {
- DEBUGF(fprintf(stderr, "Error: realloc of buffer failed\n"));
+ DEBUGF(fprintf(thread_stderr, "Error: realloc of buffer failed\n"));
result = CURLE_OUT_OF_MEMORY;
}
}
@@ -3028,7 +3040,7 @@
data = conn->data;
if(!data) {
- DEBUGF(fprintf(stderr, "DISCONNECT without easy handle, ignoring\n"));
+ DEBUGF(fprintf(thread_stderr, "DISCONNECT without easy handle, ignoring\n"));
return CURLE_OK;
}
@@ -4624,12 +4636,28 @@
result = findprotocol(data, conn, protop);
if(result)
- return result;
+ return result;
/*
* Parse the login details from the URL and strip them out of
* the host name
*/
+#ifdef BLINKSHELL // get user and host from Blinkshell config
+ if ((strcmp(protop, "scp") == 0) || (strcmp(protop, "sftp") == 0)) {
+ BKHosts *host;
+ if (host = [BKHosts withHost:[NSString stringWithUTF8String:conn->host.name]]) {
+ if (host.hostName) conn->host.name = [host.hostName UTF8String];
+ if ([host.user length]) {
+ *userp = strdup([host.user UTF8String]);
+ }
+ // grab remote port from host settings too
+ if (conn->remote_port == -1 && host.port.intValue) {
+ conn->remote_port = host.port.intValue;
+ }
+ }
+ }
+#endif
+
result = parse_url_login(data, conn, userp, passwdp, optionsp);
if(result)
return result;
@@ -6875,7 +6903,7 @@
*/
if((data->set.out)->_handle == NULL) {
- _fsetmode(stdout, "b");
+ _fsetmode(thread_stdout, "b");
}
#endif
diff -Naur curl-105/curl/lib/vauth/ntlm.c curl/curl/lib/vauth/ntlm.c
--- curl-105/curl/lib/vauth/ntlm.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/vauth/ntlm.c 2018-12-08 16:03:39.000000000 +0100
@@ -141,9 +141,9 @@
(void) handle;
- fprintf(stderr, "0x");
+ fprintf(thread_stderr, "0x");
while(len-- > 0)
- fprintf(stderr, "%02.2x", (unsigned int)*p++);
+ fprintf(thread_stderr, "%02.2x", (unsigned int)*p++);
}
#else
# define DEBUG_OUT(x) Curl_nop_stmt
@@ -318,12 +318,12 @@
}
DEBUG_OUT({
- fprintf(stderr, "**** TYPE2 header flags=0x%08.8lx ", ntlm->flags);
- ntlm_print_flags(stderr, ntlm->flags);
- fprintf(stderr, "\n nonce=");
- ntlm_print_hex(stderr, (char *)ntlm->nonce, 8);
- fprintf(stderr, "\n****\n");
- fprintf(stderr, "**** Header %s\n ", header);
+ fprintf(thread_stderr, "**** TYPE2 header flags=0x%08.8lx ", ntlm->flags);
+ ntlm_print_flags(thread_stderr, ntlm->flags);
+ fprintf(thread_stderr, "\n nonce=");
+ ntlm_print_hex(thread_stderr, (char *)ntlm->nonce, 8);
+ fprintf(thread_stderr, "\n****\n");
+ fprintf(thread_stderr, "**** Header %s\n ", header);
});
free(type2);
@@ -436,7 +436,7 @@
size = 32 + hostlen + domlen;
DEBUG_OUT({
- fprintf(stderr, "* TYPE1 header flags=0x%02.2x%02.2x%02.2x%02.2x "
+ fprintf(thread_stderr, "* TYPE1 header flags=0x%02.2x%02.2x%02.2x%02.2x "
"0x%08.8x ",
LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM |
NTLMFLAG_REQUEST_TARGET |
@@ -448,13 +448,13 @@
NTLMFLAG_NEGOTIATE_NTLM_KEY |
NTLM2FLAG |
NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
- ntlm_print_flags(stderr,
+ ntlm_print_flags(thread_stderr,
NTLMFLAG_NEGOTIATE_OEM |
NTLMFLAG_REQUEST_TARGET |
NTLMFLAG_NEGOTIATE_NTLM_KEY |
NTLM2FLAG |
NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
- fprintf(stderr, "\n****\n");
+ fprintf(thread_stderr, "\n****\n");
});
/* Return with binary blob encoded into base64 */
@@ -764,8 +764,8 @@
}
DEBUG_OUT({
- fprintf(stderr, "**** TYPE3 header lmresp=");
- ntlm_print_hex(stderr, (char *)&ntlmbuf[lmrespoff], 0x18);
+ fprintf(thread_stderr, "**** TYPE3 header lmresp=");
+ ntlm_print_hex(thread_stderr, (char *)&ntlmbuf[lmrespoff], 0x18);
});
#ifdef USE_NTRESPONSES
@@ -776,8 +776,8 @@
}
DEBUG_OUT({
- fprintf(stderr, "\n ntresp=");
- ntlm_print_hex(stderr, (char *)&ntlmbuf[ntrespoff], ntresplen);
+ fprintf(thread_stderr, "\n ntresp=");
+ ntlm_print_hex(thread_stderr, (char *)&ntlmbuf[ntrespoff], ntresplen);
});
free(ntlmv2resp);/* Free the dynamic buffer allocated for NTLMv2 */
@@ -785,10 +785,10 @@
#endif
DEBUG_OUT({
- fprintf(stderr, "\n flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ",
+ fprintf(thread_stderr, "\n flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ",
LONGQUARTET(ntlm->flags), ntlm->flags);
- ntlm_print_flags(stderr, ntlm->flags);
- fprintf(stderr, "\n****\n");
+ ntlm_print_flags(thread_stderr, ntlm->flags);
+ fprintf(thread_stderr, "\n****\n");
});
/* Make sure that the domain, user and host strings fit in the
diff -Naur curl-105/curl/lib/vtls/gtls.c curl/curl/lib/vtls/gtls.c
--- curl-105/curl/lib/vtls/gtls.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/lib/vtls/gtls.c 2018-12-08 16:03:39.000000000 +0100
@@ -77,7 +77,7 @@
#ifdef GTLSDEBUG
static void tls_log_func(int level, const char *str)
{
- fprintf(stderr, "|<%d>| %s", level, str);
+ fprintf(thread_stderr, "|<%d>| %s", level, str);
}
#endif
static bool gtls_inited = FALSE;
diff -Naur curl-105/curl/lib/vtls/polarssl_threadlock.c curl/curl/lib/vtls/polarssl_threadlock.c
--- curl-105/curl/lib/vtls/polarssl_threadlock.c 2016-11-04 22:42:50.000000000 +0100
+++ curl/curl/lib/vtls/polarssl_threadlock.c 2018-12-08 16:03:39.000000000 +0100
@@ -107,7 +107,7 @@
if(n < NUMT) {
ret = pthread_mutex_lock(&mutex_buf[n]);
if(ret) {
- DEBUGF(fprintf(stderr,
+ DEBUGF(fprintf(thread_stderr,
"Error: polarsslthreadlock_lock_function failed\n"));
return 0; /* pthread_mutex_lock failed */
}
@@ -116,7 +116,7 @@
if(n < NUMT) {
ret = (WaitForSingleObject(mutex_buf[n], INFINITE)==WAIT_FAILED?1:0);
if(ret) {
- DEBUGF(fprintf(stderr,
+ DEBUGF(fprintf(thread_stderr,
"Error: polarsslthreadlock_lock_function failed\n"));
return 0; /* pthread_mutex_lock failed */
}
@@ -132,7 +132,7 @@
if(n < NUMT) {
ret = pthread_mutex_unlock(&mutex_buf[n]);
if(ret) {
- DEBUGF(fprintf(stderr,
+ DEBUGF(fprintf(thread_stderr,
"Error: polarsslthreadlock_unlock_function failed\n"));
return 0; /* pthread_mutex_unlock failed */
}
@@ -141,7 +141,7 @@
if(n < NUMT) {
ret = ReleaseMutex(mutex_buf[n]);
if(!ret) {
- DEBUGF(fprintf(stderr,
+ DEBUGF(fprintf(thread_stderr,
"Error: polarsslthreadlock_unlock_function failed\n"));
return 0; /* pthread_mutex_lock failed */
}
diff -Naur curl-105/curl/src/tool_cb_dbg.c curl/curl/src/tool_cb_dbg.c
--- curl-105/curl/src/tool_cb_dbg.c 2017-05-17 21:04:33.000000000 +0200
+++ curl/curl/src/tool_cb_dbg.c 2018-12-08 16:03:39.000000000 +0100
@@ -29,6 +29,7 @@
#include "tool_msgs.h"
#include "tool_cb_dbg.h"