Kitxuuu commited on
Commit
09f51e5
·
verified ·
1 Parent(s): 856d9b8

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. local-test-curl-delta-01/afc-curl/include/Makefile.am +28 -0
  3. local-test-curl-delta-01/afc-curl/include/README.md +20 -0
  4. local-test-curl-delta-01/afc-curl/scripts/Makefile.am +83 -0
  5. local-test-curl-delta-01/afc-curl/scripts/cd2cd +226 -0
  6. local-test-curl-delta-01/afc-curl/scripts/cd2nroff +575 -0
  7. local-test-curl-delta-01/afc-curl/scripts/cdall +44 -0
  8. local-test-curl-delta-01/afc-curl/scripts/checksrc.pl +1088 -0
  9. local-test-curl-delta-01/afc-curl/scripts/ciconfig.pl +190 -0
  10. local-test-curl-delta-01/afc-curl/scripts/cijobs.pl +510 -0
  11. local-test-curl-delta-01/afc-curl/scripts/cmakelint.sh +50 -0
  12. local-test-curl-delta-01/afc-curl/scripts/completion.pl +166 -0
  13. local-test-curl-delta-01/afc-curl/scripts/contributors.sh +99 -0
  14. local-test-curl-delta-01/afc-curl/scripts/contrithanks.sh +73 -0
  15. local-test-curl-delta-01/afc-curl/scripts/coverage.sh +41 -0
  16. local-test-curl-delta-01/afc-curl/scripts/delta +169 -0
  17. local-test-curl-delta-01/afc-curl/scripts/dmaketgz +55 -0
  18. local-test-curl-delta-01/afc-curl/scripts/firefox-db2pem.sh +61 -0
  19. local-test-curl-delta-01/afc-curl/scripts/installcheck.sh +52 -0
  20. local-test-curl-delta-01/afc-curl/scripts/maketgz +247 -0
  21. local-test-curl-delta-01/afc-curl/scripts/managen +1279 -0
  22. local-test-curl-delta-01/afc-curl/scripts/mk-ca-bundle.pl +672 -0
  23. local-test-curl-delta-01/afc-curl/scripts/mk-unity.pl +63 -0
  24. local-test-curl-delta-01/afc-curl/scripts/nroff2cd +192 -0
  25. local-test-curl-delta-01/afc-curl/scripts/release-notes.pl +243 -0
  26. local-test-curl-delta-01/afc-curl/scripts/release-tools.sh +79 -0
  27. local-test-curl-delta-01/afc-curl/scripts/schemetable.c +207 -0
  28. local-test-curl-delta-01/afc-curl/scripts/singleuse.pl +244 -0
  29. local-test-curl-delta-01/afc-curl/scripts/verify-release +80 -0
  30. local-test-curl-delta-01/afc-curl/tests/.gitignore +31 -0
  31. local-test-curl-delta-01/afc-curl/tests/Makefile.am +202 -0
  32. local-test-curl-delta-01/afc-curl/tests/appveyor.pm +130 -0
  33. local-test-curl-delta-01/afc-curl/tests/config.in +24 -0
  34. local-test-curl-delta-01/afc-curl/tests/configurehelp.pm.in +45 -0
  35. local-test-curl-delta-01/afc-curl/tests/devtest.pl +202 -0
  36. local-test-curl-delta-01/afc-curl/tests/dictserver.py +186 -0
  37. local-test-curl-delta-01/afc-curl/tests/ech_tests.sh +1156 -0
  38. local-test-curl-delta-01/afc-curl/tests/ftpserver.pl +3376 -0
  39. local-test-curl-delta-01/afc-curl/tests/http3-server.pl +121 -0
  40. local-test-curl-delta-01/afc-curl/tests/memanalyze.pl +434 -0
  41. local-test-curl-delta-01/afc-curl/tests/mk-bundle.pl +162 -0
  42. local-test-curl-delta-01/afc-curl/tests/pathhelp.pm +185 -0
  43. local-test-curl-delta-01/afc-curl/tests/requirements.txt +26 -0
  44. local-test-curl-delta-01/afc-curl/tests/rtspserver.pl +136 -0
  45. local-test-curl-delta-01/afc-curl/tests/secureserver.pl +383 -0
  46. local-test-curl-delta-01/afc-curl/tests/serverhelp.pm +283 -0
  47. local-test-curl-delta-01/afc-curl/tests/smbserver.py +453 -0
  48. local-test-curl-delta-01/afc-curl/tests/sshhelp.pm +427 -0
  49. local-test-curl-delta-01/afc-curl/tests/stunnel.pem +162 -0
  50. local-test-curl-delta-01/afc-curl/tests/test1119.pl +245 -0
.gitattributes CHANGED
@@ -68,3 +68,6 @@ local-test-freerdp-delta-01/fuzz-tooling/infra/cifuzz/test_data/timeout_fuzzer f
68
  local-test-freerdp-delta-01/afc-freerdp/resources/FreeRDP.ico filter=lfs diff=lfs merge=lfs -text
69
  local-test-freerdp-delta-01/afc-freerdp/resources/FreeRDP_Logo_Icon.ai filter=lfs diff=lfs merge=lfs -text
70
  local-test-freerdp-delta-01/afc-freerdp/docs/FreeRDP.vsd filter=lfs diff=lfs merge=lfs -text
 
 
 
 
68
  local-test-freerdp-delta-01/afc-freerdp/resources/FreeRDP.ico filter=lfs diff=lfs merge=lfs -text
69
  local-test-freerdp-delta-01/afc-freerdp/resources/FreeRDP_Logo_Icon.ai filter=lfs diff=lfs merge=lfs -text
70
  local-test-freerdp-delta-01/afc-freerdp/docs/FreeRDP.vsd filter=lfs diff=lfs merge=lfs -text
71
+ local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/dialogs/font/OpenSans-VariableFont_wdth,wght.ttf filter=lfs diff=lfs merge=lfs -text
72
+ local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/dialogs/font/OpenSans-Italic-VariableFont_wdth,wght.ttf filter=lfs diff=lfs merge=lfs -text
73
+ local-test-freerdp-delta-01/afc-freerdp/client/Windows/resource/FreeRDP.ico filter=lfs diff=lfs merge=lfs -text
local-test-curl-delta-01/afc-curl/include/Makefile.am ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+ SUBDIRS = curl
25
+
26
+ EXTRA_DIST = README.md
27
+
28
+ AUTOMAKE_OPTIONS = foreign no-dependencies
local-test-curl-delta-01/afc-curl/include/README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3
+
4
+ SPDX-License-Identifier: curl
5
+ -->
6
+
7
+ # include
8
+
9
+ Public include files for libcurl, external users.
10
+
11
+ They are all placed in the curl subdirectory here for better fit in any kind of
12
+ environment. You must include files from here using...
13
+
14
+ #include <curl/curl.h>
15
+
16
+ ... style and point the compiler's include path to the directory holding the
17
+ curl subdirectory. It makes it more likely to survive future modifications.
18
+
19
+ The public curl include files can be shared freely between different platforms
20
+ and different architectures.
local-test-curl-delta-01/afc-curl/scripts/Makefile.am ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+
25
+ EXTRA_DIST = coverage.sh completion.pl firefox-db2pem.sh checksrc.pl \
26
+ mk-ca-bundle.pl mk-unity.pl schemetable.c cd2nroff nroff2cd cdall cd2cd managen \
27
+ dmaketgz maketgz release-tools.sh verify-release cmakelint.sh
28
+
29
+ ZSH_FUNCTIONS_DIR = @ZSH_FUNCTIONS_DIR@
30
+ FISH_FUNCTIONS_DIR = @FISH_FUNCTIONS_DIR@
31
+ PERL = @PERL@
32
+
33
+ if USE_ZSH_COMPLETION
34
+ ZSH_COMPLETION_FUNCTION_FILENAME = _curl
35
+ endif
36
+ if USE_FISH_COMPLETION
37
+ FISH_COMPLETION_FUNCTION_FILENAME = curl.fish
38
+ endif
39
+
40
+ CLEANFILES = $(ZSH_COMPLETION_FUNCTION_FILENAME) $(FISH_COMPLETION_FUNCTION_FILENAME)
41
+
42
+ all-local: $(ZSH_COMPLETION_FUNCTION_FILENAME) $(FISH_COMPLETION_FUNCTION_FILENAME)
43
+
44
+ if USE_ZSH_COMPLETION
45
+ $(ZSH_COMPLETION_FUNCTION_FILENAME): completion.pl
46
+ if CROSSCOMPILING
47
+ @echo "NOTICE: we can't generate zsh completion when cross-compiling!"
48
+ else # if not cross-compiling:
49
+ if test -z "$(PERL)"; then echo "No perl: can't install completion script"; else \
50
+ $(PERL) $(srcdir)/completion.pl --curl $(top_builddir)/src/curl$(EXEEXT) --shell zsh > $@ ; fi
51
+ endif
52
+ endif
53
+
54
+ if USE_FISH_COMPLETION
55
+ $(FISH_COMPLETION_FUNCTION_FILENAME): completion.pl
56
+ if CROSSCOMPILING
57
+ @echo "NOTICE: we can't generate fish completion when cross-compiling!"
58
+ else # if not cross-compiling:
59
+ if test -z "$(PERL)"; then echo "No perl: can't install completion script"; else \
60
+ $(PERL) $(srcdir)/completion.pl --curl $(top_builddir)/src/curl$(EXEEXT) --shell fish > $@ ; fi
61
+ endif
62
+ endif
63
+
64
+ install-data-local:
65
+ if CROSSCOMPILING
66
+ @echo "NOTICE: we can't install completion scripts when cross-compiling!"
67
+ else # if not cross-compiling:
68
+ if USE_ZSH_COMPLETION
69
+ if test -n "$(PERL)"; then \
70
+ $(MKDIR_P) $(DESTDIR)$(ZSH_FUNCTIONS_DIR); \
71
+ $(INSTALL_DATA) $(ZSH_COMPLETION_FUNCTION_FILENAME) $(DESTDIR)$(ZSH_FUNCTIONS_DIR)/$(ZSH_COMPLETION_FUNCTION_FILENAME) ; \
72
+ fi
73
+ endif
74
+ if USE_FISH_COMPLETION
75
+ if test -n "$(PERL)"; then \
76
+ $(MKDIR_P) $(DESTDIR)$(FISH_FUNCTIONS_DIR); \
77
+ $(INSTALL_DATA) $(FISH_COMPLETION_FUNCTION_FILENAME) $(DESTDIR)$(FISH_FUNCTIONS_DIR)/$(FISH_COMPLETION_FUNCTION_FILENAME) ; \
78
+ fi
79
+ endif
80
+ endif
81
+
82
+ distclean:
83
+ rm -f $(CLEANFILES)
local-test-curl-delta-01/afc-curl/scripts/cd2cd ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ =begin comment
27
+
28
+ This script updates a curldown file to current/better curldown.
29
+
30
+ Example: cd2cd [--in-place] <file.md> > <file.md>
31
+
32
+ --in-place: if used, it replaces the original file with the cleaned up
33
+ version. When this is used, cd2cd accepts multiple files to work
34
+ on and it ignores errors on single files.
35
+
36
+ =end comment
37
+ =cut
38
+
39
+ my $cd2cd = "0.1"; # to keep check
40
+ my $dir;
41
+ my $extension;
42
+ my $inplace = 0;
43
+
44
+ while(1) {
45
+ if($ARGV[0] eq "--in-place") {
46
+ shift @ARGV;
47
+ $inplace = 1;
48
+ }
49
+ else {
50
+ last;
51
+ }
52
+ }
53
+
54
+
55
+ use POSIX qw(strftime);
56
+ my @ts;
57
+ if (defined($ENV{SOURCE_DATE_EPOCH})) {
58
+ @ts = localtime($ENV{SOURCE_DATE_EPOCH});
59
+ } else {
60
+ @ts = localtime;
61
+ }
62
+ my $date = strftime "%B %d %Y", @ts;
63
+
64
+ sub outseealso {
65
+ my (@sa) = @_;
66
+ my $comma = 0;
67
+ my @o;
68
+ push @o, ".SH SEE ALSO\n";
69
+ for my $s (sort @sa) {
70
+ push @o, sprintf "%s.BR $s", $comma ? ",\n": "";
71
+ $comma = 1;
72
+ }
73
+ push @o, "\n";
74
+ return @o;
75
+ }
76
+
77
+ sub single {
78
+ my @head;
79
+ my @seealso;
80
+ my ($f)=@_;
81
+ my $title;
82
+ my $section;
83
+ my $source;
84
+ my $start = 0;
85
+ my $d;
86
+ my $line = 0;
87
+ open(F, "<:crlf", "$f") ||
88
+ return 1;
89
+ while(<F>) {
90
+ $line++;
91
+ $d = $_;
92
+ if(!$start) {
93
+ if(/^---/) {
94
+ # header starts here
95
+ $start = 1;
96
+ push @head, $d;
97
+ }
98
+ next;
99
+ }
100
+ if(/^Title: *(.*)/i) {
101
+ $title=$1;
102
+ }
103
+ elsif(/^Section: *(.*)/i) {
104
+ $section=$1;
105
+ }
106
+ elsif(/^Source: *(.*)/i) {
107
+ $source=$1;
108
+ }
109
+ elsif(/^See-also: +(.*)/i) {
110
+ $salist = 0;
111
+ push @seealso, $1;
112
+ }
113
+ elsif(/^See-also: */i) {
114
+ if($seealso[0]) {
115
+ print STDERR "$f:$line:1:ERROR: bad See-Also, needs list\n";
116
+ return 2;
117
+ }
118
+ $salist = 1;
119
+ }
120
+ elsif(/^ +- (.*)/i) {
121
+ # the only list we support is the see-also
122
+ if($salist) {
123
+ push @seealso, $1;
124
+ }
125
+ }
126
+ # REUSE-IgnoreStart
127
+ elsif(/^C: (.*)/i) {
128
+ $copyright=$1;
129
+ }
130
+ elsif(/^SPDX-License-Identifier: (.*)/i) {
131
+ $spdx=$1;
132
+ }
133
+ # REUSE-IgnoreEnd
134
+ elsif(/^---/) {
135
+ # end of the header section
136
+ if(!$title) {
137
+ print STDERR "ERROR: no 'Title:' in $f\n";
138
+ return 1;
139
+ }
140
+ if(!$section) {
141
+ print STDERR "ERROR: no 'Section:' in $f\n";
142
+ return 2;
143
+ }
144
+ if(!$seealso[0]) {
145
+ print STDERR "$f:$line:1:ERROR: no 'See-also:' present\n";
146
+ return 2;
147
+ }
148
+ if(!$copyright) {
149
+ print STDERR "$f:$line:1:ERROR: no 'C:' field present\n";
150
+ return 2;
151
+ }
152
+ if(!$spdx) {
153
+ print STDERR "$f:$line:1:ERROR: no 'SPDX-License-Identifier:' field present\n";
154
+ return 2;
155
+ }
156
+ last;
157
+ }
158
+ else {
159
+ chomp;
160
+ print STDERR "WARN: unrecognized line in $f, ignoring:\n:'$_';"
161
+ }
162
+ }
163
+
164
+ if(!$start) {
165
+ print STDERR "$f:$line:1:ERROR: no header present\n";
166
+ return 2;
167
+ }
168
+
169
+ my @desc;
170
+
171
+ push @desc, sprintf <<HEAD
172
+ ---
173
+ c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
174
+ SPDX-License-Identifier: curl
175
+ Title: $title
176
+ Section: $section
177
+ Source: $source
178
+ HEAD
179
+ ;
180
+ push @desc, "See-also:\n";
181
+ for my $s (sort @seealso) {
182
+ push @desc, " - $s\n" if($s);
183
+ }
184
+ push @desc, "---\n";
185
+
186
+ my $blankline = 0;
187
+ while(<F>) {
188
+ $d = $_;
189
+ $line++;
190
+ if($d =~ /^[ \t]*\n/) {
191
+ $blankline++;
192
+ }
193
+ else {
194
+ $blankline = 0;
195
+ }
196
+ # *italics* for curl symbol links get the asterisks removed
197
+ $d =~ s/\*((lib|)curl[^ ]*\(3\))\*/$1/gi;
198
+
199
+ if(length($d) > 90) {
200
+ print STDERR "$f:$line:1:WARN: excessive line length\n";
201
+ }
202
+
203
+ push @desc, $d if($blankline < 2);
204
+ }
205
+ close(F);
206
+
207
+ if($inplace) {
208
+ open(O, ">$f") || return 1;
209
+ print O @desc;
210
+ close(O);
211
+ }
212
+ else {
213
+ print @desc;
214
+ }
215
+ return 0;
216
+ }
217
+
218
+ if($inplace) {
219
+ for my $a (@ARGV) {
220
+ # this ignores errors
221
+ single($a);
222
+ }
223
+ }
224
+ else {
225
+ exit single($ARGV[0]);
226
+ }
local-test-curl-delta-01/afc-curl/scripts/cd2nroff ADDED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ =begin comment
27
+
28
+ Converts a curldown file to nroff (manpage).
29
+
30
+ =end comment
31
+ =cut
32
+
33
+ use strict;
34
+ use warnings;
35
+
36
+ my $cd2nroff = "0.1"; # to keep check
37
+ my $dir;
38
+ my $extension;
39
+ my $keepfilename;
40
+
41
+ while(@ARGV) {
42
+ if($ARGV[0] eq "-d") {
43
+ shift @ARGV;
44
+ $dir = shift @ARGV;
45
+ }
46
+ elsif($ARGV[0] eq "-e") {
47
+ shift @ARGV;
48
+ $extension = shift @ARGV;
49
+ }
50
+ elsif($ARGV[0] eq "-k") {
51
+ shift @ARGV;
52
+ $keepfilename = 1;
53
+ }
54
+ elsif($ARGV[0] eq "-h") {
55
+ print <<HELP
56
+ Usage: cd2nroff [options] [file.md]
57
+
58
+ -d <dir> Write the output to the file name from the meta-data in the
59
+ specified directory, instead of writing to stdout
60
+ -e <ext> If -d is used, this option can provide an added "extension", arbitrary
61
+ text really, to append to the file name.
62
+ -h This help text,
63
+ -v Show version then exit
64
+ HELP
65
+ ;
66
+ exit 0;
67
+ }
68
+ elsif($ARGV[0] eq "-v") {
69
+ print "cd2nroff version $cd2nroff\n";
70
+ exit 0;
71
+ }
72
+ else {
73
+ last;
74
+ }
75
+ }
76
+
77
+ use POSIX qw(strftime);
78
+ my @ts;
79
+ if (defined($ENV{SOURCE_DATE_EPOCH})) {
80
+ @ts = gmtime($ENV{SOURCE_DATE_EPOCH});
81
+ } else {
82
+ @ts = localtime;
83
+ }
84
+ my $date = strftime "%Y-%m-%d", @ts;
85
+
86
+ sub outseealso {
87
+ my (@sa) = @_;
88
+ my $comma = 0;
89
+ my @o;
90
+ push @o, ".SH SEE ALSO\n";
91
+ for my $s (sort @sa) {
92
+ push @o, sprintf "%s.BR $s", $comma ? ",\n": "";
93
+ $comma = 1;
94
+ }
95
+ push @o, "\n";
96
+ return @o;
97
+ }
98
+
99
+ sub outprotocols {
100
+ my (@p) = @_;
101
+ my $comma = 0;
102
+ my @o;
103
+ push @o, ".SH PROTOCOLS\n";
104
+
105
+ if($p[0] eq "TLS") {
106
+ push @o, "This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.";
107
+ }
108
+ else {
109
+ my @s = sort @p;
110
+ push @o, "This functionality affects ";
111
+ for my $e (sort @s) {
112
+ push @o, sprintf "%s%s",
113
+ $comma ? (($e eq $s[-1]) ? " and " : ", "): "",
114
+ lc($e);
115
+ $comma = 1;
116
+ }
117
+ if($#s == 0) {
118
+ if($s[0] eq "All") {
119
+ push @o, " supported protocols";
120
+ }
121
+ else {
122
+ push @o, " only";
123
+ }
124
+ }
125
+ }
126
+ push @o, "\n";
127
+ return @o;
128
+ }
129
+
130
+ sub outtls {
131
+ my (@t) = @_;
132
+ my $comma = 0;
133
+ my @o;
134
+ if($t[0] eq "All") {
135
+ push @o, "\nAll TLS backends support this option.";
136
+ }
137
+ else {
138
+ push @o, "\nThis option works only with the following TLS backends:\n";
139
+ my @s = sort @t;
140
+ for my $e (@s) {
141
+ push @o, sprintf "%s$e",
142
+ $comma ? (($e eq $s[-1]) ? " and " : ", "): "";
143
+ $comma = 1;
144
+ }
145
+ }
146
+ push @o, "\n";
147
+ return @o;
148
+ }
149
+
150
+ my %knownprotos = (
151
+ 'DICT' => 1,
152
+ 'FILE' => 1,
153
+ 'FTP' => 1,
154
+ 'FTPS' => 1,
155
+ 'GOPHER' => 1,
156
+ 'GOPHERS' => 1,
157
+ 'HTTP' => 1,
158
+ 'HTTPS' => 1,
159
+ 'IMAP' => 1,
160
+ 'IMAPS' => 1,
161
+ 'LDAP' => 1,
162
+ 'LDAPS' => 1,
163
+ 'MQTT' => 1,
164
+ 'POP3' => 1,
165
+ 'POP3S' => 1,
166
+ 'RTMP' => 1,
167
+ 'RTMPS' => 1,
168
+ 'RTSP' => 1,
169
+ 'SCP' => 1,
170
+ 'SFTP' => 1,
171
+ 'SMB' => 1,
172
+ 'SMBS' => 1,
173
+ 'SMTP' => 1,
174
+ 'SMTPS' => 1,
175
+ 'TELNET' => 1,
176
+ 'TFTP' => 1,
177
+ 'WS' => 1,
178
+ 'WSS' => 1,
179
+ 'TLS' => 1,
180
+ 'TCP' => 1,
181
+ 'QUIC' => 1,
182
+ 'All' => 1
183
+ );
184
+
185
+ my %knowntls = (
186
+ 'BearSSL' => 1,
187
+ 'GnuTLS' => 1,
188
+ 'mbedTLS' => 1,
189
+ 'OpenSSL' => 1,
190
+ 'rustls' => 1,
191
+ 'Schannel' => 1,
192
+ 'Secure Transport' => 1,
193
+ 'wolfSSL' => 1,
194
+ 'All' => 1,
195
+ );
196
+
197
+ sub single {
198
+ my @seealso;
199
+ my @proto;
200
+ my @tls;
201
+ my $d;
202
+ my ($f)=@_;
203
+ my $copyright;
204
+ my $errors = 0;
205
+ my $fh;
206
+ my $line;
207
+ my $list;
208
+ my $tlslist;
209
+ my $section;
210
+ my $source;
211
+ my $addedin;
212
+ my $spdx;
213
+ my $start = 0;
214
+ my $title;
215
+
216
+ if(defined($f)) {
217
+ if(!open($fh, "<:crlf", "$f")) {
218
+ print STDERR "cd2nroff failed to open '$f' for reading: $!\n";
219
+ return 1;
220
+ }
221
+ }
222
+ else {
223
+ $f = "STDIN";
224
+ $fh = \*STDIN;
225
+ binmode($fh, ":crlf");
226
+ }
227
+ while(<$fh>) {
228
+ $line++;
229
+ if(!$start) {
230
+ if(/^---/) {
231
+ # header starts here
232
+ $start = 1;
233
+ }
234
+ next;
235
+ }
236
+ if(/^Title: *(.*)/i) {
237
+ $title=$1;
238
+ }
239
+ elsif(/^Section: *(.*)/i) {
240
+ $section=$1;
241
+ }
242
+ elsif(/^Source: *(.*)/i) {
243
+ $source=$1;
244
+ }
245
+ elsif(/^See-also: +(.*)/i) {
246
+ $list = 1; # 1 for see-also
247
+ push @seealso, $1;
248
+ }
249
+ elsif(/^See-also: */i) {
250
+ if($seealso[0]) {
251
+ print STDERR "$f:$line:1:ERROR: bad See-Also, needs list\n";
252
+ return 2;
253
+ }
254
+ $list = 1; # 1 for see-also
255
+ }
256
+ elsif(/^Protocol:/i) {
257
+ $list = 2; # 2 for protocol
258
+ }
259
+ elsif(/^TLS-backend:/i) {
260
+ $list = 3; # 3 for TLS backend
261
+ }
262
+ elsif(/^Added-in: *(.*)/i) {
263
+ $addedin=$1;
264
+ if(($addedin !~ /^[0-9.]+[0-9]\z/) &&
265
+ ($addedin ne "n/a")) {
266
+ print STDERR "$f:$line:1:ERROR: invalid version number in Added-in line: $addedin\n";
267
+ return 2;
268
+ }
269
+ }
270
+ elsif(/^ +- (.*)/i) {
271
+ # the only lists we support are see-also and protocol
272
+ if($list == 1) {
273
+ push @seealso, $1;
274
+ }
275
+ elsif($list == 2) {
276
+ push @proto, $1;
277
+ }
278
+ elsif($list == 3) {
279
+ push @tls, $1;
280
+ }
281
+ else {
282
+ print STDERR "$f:$line:1:ERROR: list item without owner?\n";
283
+ return 2;
284
+ }
285
+ }
286
+ # REUSE-IgnoreStart
287
+ elsif(/^C: (.*)/i) {
288
+ $copyright=$1;
289
+ }
290
+ elsif(/^SPDX-License-Identifier: (.*)/i) {
291
+ $spdx=$1;
292
+ }
293
+ # REUSE-IgnoreEnd
294
+ elsif(/^---/) {
295
+ # end of the header section
296
+ if(!$title) {
297
+ print STDERR "$f:$line:1:ERROR: no 'Title:' in $f\n";
298
+ return 1;
299
+ }
300
+ if(!$section) {
301
+ print STDERR "$f:$line:1:ERROR: no 'Section:' in $f\n";
302
+ return 2;
303
+ }
304
+ if(!$source) {
305
+ print STDERR "$f:$line:1:ERROR: no 'Source:' in $f\n";
306
+ return 2;
307
+ }
308
+ if(($source eq "libcurl") && !$addedin) {
309
+ print STDERR "$f:$line:1:ERROR: no 'Added-in:' in $f\n";
310
+ return 2;
311
+ }
312
+ if(!$seealso[0]) {
313
+ print STDERR "$f:$line:1:ERROR: no 'See-also:' present\n";
314
+ return 2;
315
+ }
316
+ if(!$copyright) {
317
+ print STDERR "$f:$line:1:ERROR: no 'C:' field present\n";
318
+ return 2;
319
+ }
320
+ if(!$spdx) {
321
+ print STDERR "$f:$line:1:ERROR: no 'SPDX-License-Identifier:' field present\n";
322
+ return 2;
323
+ }
324
+ if($section == 3) {
325
+ if(!$proto[0]) {
326
+ printf STDERR "$f:$line:1:ERROR: missing Protocol:\n";
327
+ exit 2;
328
+ }
329
+ my $tls = 0;
330
+ for my $p (@proto) {
331
+ if($p eq "TLS") {
332
+ $tls = 1;
333
+ }
334
+ if(!$knownprotos{$p}) {
335
+ printf STDERR "$f:$line:1:ERROR: invalid protocol used: $p:\n";
336
+ exit 2;
337
+ }
338
+ }
339
+ # This is for TLS, require TLS-backend:
340
+ if($tls) {
341
+ if(!$tls[0]) {
342
+ printf STDERR "$f:$line:1:ERROR: missing TLS-backend:\n";
343
+ exit 2;
344
+ }
345
+ for my $t (@tls) {
346
+ if(!$knowntls{$t}) {
347
+ printf STDERR "$f:$line:1:ERROR: invalid TLS backend: $t:\n";
348
+ exit 2;
349
+ }
350
+ }
351
+ }
352
+ }
353
+ last;
354
+ }
355
+ else {
356
+ chomp;
357
+ print STDERR "$f:$line:1:ERROR: unrecognized header keyword: '$_'\n";
358
+ $errors++;
359
+ }
360
+ }
361
+
362
+ if(!$start) {
363
+ print STDERR "$f:$line:1:ERROR: no header present\n";
364
+ return 2;
365
+ }
366
+
367
+ my @desc;
368
+ my $quote = 0;
369
+ my $blankline = 0;
370
+ my $header = 0;
371
+
372
+ # cut off the leading path from the file name, if any
373
+ $f =~ s/^(.*[\\\/])//;
374
+
375
+ push @desc, ".\\\" generated by cd2nroff $cd2nroff from $f\n";
376
+ push @desc, ".TH $title $section \"$date\" $source\n";
377
+ while(<$fh>) {
378
+ $line++;
379
+
380
+ $d = $_;
381
+
382
+ if($quote) {
383
+ if($quote == 4) {
384
+ # remove the indentation
385
+ if($d =~ /^ (.*)/) {
386
+ push @desc, "$1\n";
387
+ next;
388
+ }
389
+ else {
390
+ # end of quote
391
+ $quote = 0;
392
+ push @desc, ".fi\n";
393
+ next;
394
+ }
395
+ }
396
+ if(/^~~~/) {
397
+ # end of quote
398
+ $quote = 0;
399
+ push @desc, ".fi\n";
400
+ next;
401
+ }
402
+ # convert single backslahes to doubles
403
+ $d =~ s/\\/\\\\/g;
404
+ # lines starting with a period needs it escaped
405
+ $d =~ s/^\./\\&./;
406
+ push @desc, $d;
407
+ next;
408
+ }
409
+
410
+ # remove single line HTML comments
411
+ $d =~ s/<!--.*?-->//g;
412
+
413
+ # **bold**
414
+ $d =~ s/\*\*(\S.*?)\*\*/\\fB$1\\fP/g;
415
+ # *italics*
416
+ $d =~ s/\*(\S.*?)\*/\\fI$1\\fP/g;
417
+
418
+ if($d =~ /[^\\][\<\>]/) {
419
+ print STDERR "$f:$line:1:ERROR: un-escaped < or > used\n";
420
+ $errors++;
421
+ }
422
+ # convert backslash-'<' or '> to just the second character
423
+ $d =~ s/\\([<>])/$1/g;
424
+
425
+ # mentions of curl symbols with manpages use italics by default
426
+ $d =~ s/((lib|)curl([^ ]*\(3\)))/\\fI$1\\fP/gi;
427
+
428
+ # backticked becomes italics
429
+ $d =~ s/\`(.*?)\`/\\fI$1\\fP/g;
430
+
431
+ if(/^## (.*)/) {
432
+ my $word = $1;
433
+ # if there are enclosing quotes, remove them first
434
+ $word =~ s/[\"\'\`](.*)[\"\'\`]\z/$1/;
435
+
436
+ # enclose in double quotes if there is a space present
437
+ if($word =~ / /) {
438
+ push @desc, ".IP \"$word\"\n";
439
+ }
440
+ else {
441
+ push @desc, ".IP $word\n";
442
+ }
443
+ $header = 1;
444
+ }
445
+ elsif(/^##/) {
446
+ # end of IP sequence
447
+ push @desc, ".PP\n";
448
+ $header = 1;
449
+ }
450
+ elsif(/^# (.*)/) {
451
+ my $word = $1;
452
+ # if there are enclosing quotes, remove them first
453
+ $word =~ s/[\"\'](.*)[\"\']\z/$1/;
454
+
455
+ if($word eq "PROTOCOLS") {
456
+ print STDERR "$f:$line:1:WARN: PROTOCOLS section in source file\n";
457
+ }
458
+ elsif($word eq "AVAILABILITY") {
459
+ print STDERR "$f:$line:1:WARN: AVAILABILITY section in source file\n";
460
+ }
461
+ elsif($word eq "%PROTOCOLS%") {
462
+ # insert the generated PROTOCOLS section
463
+ push @desc, outprotocols(@proto);
464
+
465
+ if($proto[0] eq "TLS") {
466
+ push @desc, outtls(@tls);
467
+ }
468
+ $header = 1;
469
+ next;
470
+ }
471
+ elsif($word eq "%AVAILABILITY%") {
472
+ if($addedin ne "n/a") {
473
+ # insert the generated AVAILABILITY section
474
+ push @desc, ".SH AVAILABILITY\n";
475
+ push @desc, "Added in curl $addedin\n";
476
+ }
477
+ $header = 1;
478
+ next;
479
+ }
480
+ push @desc, ".SH $word\n";
481
+ $header = 1;
482
+ }
483
+ elsif(/^~~~c/) {
484
+ # start of a code section, not indented
485
+ $quote = 1;
486
+ push @desc, "\n" if($blankline && !$header);
487
+ $header = 0;
488
+ push @desc, ".nf\n";
489
+ }
490
+ elsif(/^~~~/) {
491
+ # start of a quote section; not code, not indented
492
+ $quote = 1;
493
+ push @desc, "\n" if($blankline && !$header);
494
+ $header = 0;
495
+ push @desc, ".nf\n";
496
+ }
497
+ elsif(/^ (.*)/) {
498
+ # quoted, indented by 4 space
499
+ $quote = 4;
500
+ push @desc, "\n" if($blankline && !$header);
501
+ $header = 0;
502
+ push @desc, ".nf\n$1\n";
503
+ }
504
+ elsif(/^[ \t]*\n/) {
505
+ # count and ignore blank lines
506
+ $blankline++;
507
+ }
508
+ else {
509
+ # don't output newlines if this is the first content after a
510
+ # header
511
+ push @desc, "\n" if($blankline && !$header);
512
+ $blankline = 0;
513
+ $header = 0;
514
+
515
+ # quote minuses in the output
516
+ $d =~ s/([^\\])-/$1\\-/g;
517
+ # replace single quotes
518
+ $d =~ s/\'/\\(aq/g;
519
+ # handle double quotes first on the line
520
+ $d =~ s/^(\s*)\"/$1\\&\"/;
521
+
522
+ # lines starting with a period needs it escaped
523
+ $d =~ s/^\./\\&./;
524
+
525
+ if($d =~ /^(.*) /) {
526
+ printf STDERR "$f:$line:%d:ERROR: 2 spaces detected\n",
527
+ length($1);
528
+ $errors++;
529
+ }
530
+ if($d =~ /^[ \t]*\n/) {
531
+ # replaced away all contents
532
+ $blankline= 1;
533
+ }
534
+ else {
535
+ push @desc, $d;
536
+ }
537
+ }
538
+ }
539
+ if($fh != \*STDIN) {
540
+ close($fh);
541
+ }
542
+ push @desc, outseealso(@seealso);
543
+ if($dir) {
544
+ if($keepfilename) {
545
+ $title = $f;
546
+ $title =~ s/\.[^.]*$//;
547
+ }
548
+ my $outfile = "$dir/$title.$section";
549
+ if(defined($extension)) {
550
+ $outfile .= $extension;
551
+ }
552
+ if(!open(O, ">", $outfile)) {
553
+ print STDERR "Failed to open $outfile : $!\n";
554
+ return 1;
555
+ }
556
+ print O @desc;
557
+ close(O);
558
+ }
559
+ else {
560
+ print @desc;
561
+ }
562
+ return $errors;
563
+ }
564
+
565
+ if(@ARGV) {
566
+ for my $f (@ARGV) {
567
+ my $r = single($f);
568
+ if($r) {
569
+ exit $r;
570
+ }
571
+ }
572
+ }
573
+ else {
574
+ exit single();
575
+ }
local-test-curl-delta-01/afc-curl/scripts/cdall ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # provide all dir names to scan on the cmdline
27
+
28
+ sub convert {
29
+ my ($dir)=@_;
30
+ opendir(my $dh, $dir) || die "could not open $dir";
31
+ my @cd = grep { /\.md\z/ && -f "$dir/$_" } readdir($dh);
32
+ closedir $dh;
33
+
34
+ for my $cd (@cd) {
35
+ my $nroff = "$cd";
36
+ $nroff =~ s/\.md\z/.3/;
37
+ print "$dir/$cd = $dir/$nroff\n";
38
+ system("./scripts/cd2nroff -d $dir $dir/$cd");
39
+ }
40
+ }
41
+
42
+ for my $d (sort @ARGV) {
43
+ convert($d);
44
+ }
local-test-curl-delta-01/afc-curl/scripts/checksrc.pl ADDED
@@ -0,0 +1,1088 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ use strict;
27
+ use warnings;
28
+
29
+ my $max_column = 79;
30
+ my $indent = 2;
31
+
32
+ my $warnings = 0;
33
+ my $swarnings = 0;
34
+ my $errors = 0;
35
+ my $serrors = 0;
36
+ my $suppressed; # skipped problems
37
+ my $file;
38
+ my $dir=".";
39
+ my $wlist="";
40
+ my @alist;
41
+ my $windows_os = $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys';
42
+ my $verbose;
43
+ my %skiplist;
44
+
45
+ my %ignore;
46
+ my %ignore_set;
47
+ my %ignore_used;
48
+ my @ignore_line;
49
+
50
+ my %warnings_extended = (
51
+ 'COPYRIGHTYEAR' => 'copyright year incorrect',
52
+ 'STRERROR', => 'strerror() detected',
53
+ 'STRNCPY', => 'strncpy() detected',
54
+ 'STDERR', => 'stderr detected',
55
+ );
56
+
57
+ my %warnings = (
58
+ 'ASSIGNWITHINCONDITION' => 'assignment within conditional expression',
59
+ 'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
60
+ 'ASTERISKSPACE' => 'pointer declared with space after asterisk',
61
+ 'BADCOMMAND' => 'bad !checksrc! instruction',
62
+ 'BANNEDFUNC' => 'a banned function was used',
63
+ 'BANNEDPREPROC' => 'a banned symbol was used on a preprocessor line',
64
+ 'BRACEELSE' => '} else on the same line',
65
+ 'BRACEPOS' => 'wrong position for an open brace',
66
+ 'BRACEWHILE' => 'A single space between open brace and while',
67
+ 'COMMANOSPACE' => 'comma without following space',
68
+ 'COMMENTNOSPACEEND' => 'no space before */',
69
+ 'COMMENTNOSPACESTART' => 'no space following /*',
70
+ 'COPYRIGHT' => 'file missing a copyright statement',
71
+ 'CPPCOMMENTS' => '// comment detected',
72
+ 'DOBRACE' => 'A single space between do and open brace',
73
+ 'EMPTYLINEBRACE' => 'Empty line before the open brace',
74
+ 'EQUALSNOSPACE' => 'equals sign without following space',
75
+ 'EQUALSNULL' => 'if/while comparison with == NULL',
76
+ 'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
77
+ 'FOPENMODE' => 'fopen needs a macro for the mode string',
78
+ 'INCLUDEDUP', => 'same file is included again',
79
+ 'INDENTATION' => 'wrong start column for code',
80
+ 'LONGLINE' => "Line longer than $max_column",
81
+ 'SPACEBEFORELABEL' => 'labels not at the start of the line',
82
+ 'MULTISPACE' => 'multiple spaces used when not suitable',
83
+ 'NOSPACEAND' => 'missing space around Logical AND operator',
84
+ 'NOSPACEC' => 'missing space around ternary colon operator',
85
+ 'NOSPACEEQUALS' => 'equals sign without preceding space',
86
+ 'NOSPACEQ' => 'missing space around ternary question mark operator',
87
+ 'NOSPACETHAN' => 'missing space around less or greater than',
88
+ 'NOTEQUALSZERO', => 'if/while comparison with != 0',
89
+ 'ONELINECONDITION' => 'conditional block on the same line as the if()',
90
+ 'OPENCOMMENT' => 'file ended with a /* comment still "open"',
91
+ 'PARENBRACE' => '){ without sufficient space',
92
+ 'RETURNNOSPACE' => 'return without space',
93
+ 'SEMINOSPACE' => 'semicolon without following space',
94
+ 'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
95
+ 'SNPRINTF' => 'use of snprintf',
96
+ 'SPACEAFTERPAREN' => 'space after open parenthesis',
97
+ 'SPACEBEFORECLOSE' => 'space before a close parenthesis',
98
+ 'SPACEBEFORECOMMA' => 'space before a comma',
99
+ 'SPACEBEFOREPAREN' => 'space before an open parenthesis',
100
+ 'SPACESEMICOLON' => 'space before semicolon',
101
+ 'SPACESWITCHCOLON' => 'space before colon of switch label',
102
+ 'TABS' => 'TAB characters not allowed',
103
+ 'TRAILINGSPACE' => 'Trailing whitespace on the line',
104
+ 'TYPEDEFSTRUCT' => 'typedefed struct',
105
+ 'UNUSEDIGNORE' => 'a warning ignore was not used',
106
+ );
107
+
108
+ sub readskiplist {
109
+ open(my $W, '<', "$dir/checksrc.skip") or return;
110
+ my @all=<$W>;
111
+ for(@all) {
112
+ $windows_os ? $_ =~ s/\r?\n$// : chomp;
113
+ $skiplist{$_}=1;
114
+ }
115
+ close($W);
116
+ }
117
+
118
+ # Reads the .checksrc in $dir for any extended warnings to enable locally.
119
+ # Currently there is no support for disabling warnings from the standard set,
120
+ # and since that's already handled via !checksrc! commands there is probably
121
+ # little use to add it.
122
+ sub readlocalfile {
123
+ my ($file) = @_;
124
+ my $i = 0;
125
+ my $rcfile;
126
+
127
+ if(($dir eq ".") && $file =~ /\//) {
128
+ my $ldir;
129
+ if($file =~ /(.*)\//) {
130
+ $ldir = $1;
131
+ open($rcfile, "<", "$dir/$ldir/.checksrc") or return;
132
+ }
133
+ }
134
+ else {
135
+ open($rcfile, "<", "$dir/.checksrc") or return;
136
+ }
137
+
138
+ while(<$rcfile>) {
139
+ $windows_os ? $_ =~ s/\r?\n$// : chomp;
140
+ $i++;
141
+
142
+ # Lines starting with '#' are considered comments
143
+ if (/^\s*(#.*)/) {
144
+ next;
145
+ }
146
+ elsif (/^\s*enable ([A-Z]+)$/) {
147
+ if(!defined($warnings_extended{$1})) {
148
+ print STDERR "invalid warning specified in .checksrc: \"$1\"\n";
149
+ next;
150
+ }
151
+ $warnings{$1} = $warnings_extended{$1};
152
+ }
153
+ elsif (/^\s*disable ([A-Z]+)$/) {
154
+ if(!defined($warnings{$1})) {
155
+ print STDERR "invalid warning specified in .checksrc: \"$1\"\n";
156
+ next;
157
+ }
158
+ # Accept-list
159
+ push @alist, $1;
160
+ }
161
+ else {
162
+ die "Invalid format in $dir/.checksrc on line $i\n";
163
+ }
164
+ }
165
+ close($rcfile);
166
+ }
167
+
168
+ sub checkwarn {
169
+ my ($name, $num, $col, $file, $line, $msg, $error) = @_;
170
+
171
+ my $w=$error?"error":"warning";
172
+ my $nowarn=0;
173
+
174
+ #if(!$warnings{$name}) {
175
+ # print STDERR "Dev! there's no description for $name!\n";
176
+ #}
177
+
178
+ # checksrc.skip
179
+ if($skiplist{$line}) {
180
+ $nowarn = 1;
181
+ }
182
+ # !checksrc! controlled
183
+ elsif($ignore{$name}) {
184
+ $ignore{$name}--;
185
+ $ignore_used{$name}++;
186
+ $nowarn = 1;
187
+ if(!$ignore{$name}) {
188
+ # reached zero, enable again
189
+ enable_warn($name, $num, $file, $line);
190
+ }
191
+ }
192
+
193
+ if($nowarn) {
194
+ $suppressed++;
195
+ if($w) {
196
+ $swarnings++;
197
+ }
198
+ else {
199
+ $serrors++;
200
+ }
201
+ return;
202
+ }
203
+
204
+ if($w) {
205
+ $warnings++;
206
+ }
207
+ else {
208
+ $errors++;
209
+ }
210
+
211
+ $col++;
212
+ print "$file:$num:$col: $w: $msg ($name)\n";
213
+ print " $line\n";
214
+
215
+ if($col < 80) {
216
+ my $pref = (' ' x $col);
217
+ print "${pref}^\n";
218
+ }
219
+ }
220
+
221
+ $file = shift @ARGV;
222
+
223
+ while(defined $file) {
224
+
225
+ if($file =~ /-D(.*)/) {
226
+ $dir = $1;
227
+ $file = shift @ARGV;
228
+ next;
229
+ }
230
+ elsif($file =~ /-W(.*)/) {
231
+ $wlist .= " $1 ";
232
+ $file = shift @ARGV;
233
+ next;
234
+ }
235
+ elsif($file =~ /-A(.+)/) {
236
+ push @alist, $1;
237
+ $file = shift @ARGV;
238
+ next;
239
+ }
240
+ elsif($file =~ /-i([1-9])/) {
241
+ $indent = $1 + 0;
242
+ $file = shift @ARGV;
243
+ next;
244
+ }
245
+ elsif($file =~ /-m([0-9]+)/) {
246
+ $max_column = $1 + 0;
247
+ $file = shift @ARGV;
248
+ next;
249
+ }
250
+ elsif($file =~ /^(-h|--help)/) {
251
+ undef $file;
252
+ last;
253
+ }
254
+
255
+ last;
256
+ }
257
+
258
+ if(!$file) {
259
+ print "checksrc.pl [option] <file1> [file2] ...\n";
260
+ print " Options:\n";
261
+ print " -A[rule] Accept this violation, can be used multiple times\n";
262
+ print " -D[DIR] Directory to prepend file names\n";
263
+ print " -h Show help output\n";
264
+ print " -W[file] Skip the given file - ignore all its flaws\n";
265
+ print " -i<n> Indent spaces. Default: 2\n";
266
+ print " -m<n> Maximum line length. Default: 79\n";
267
+ print "\nDetects and warns for these problems:\n";
268
+ my @allw = keys %warnings;
269
+ push @allw, keys %warnings_extended;
270
+ for my $w (sort @allw) {
271
+ if($warnings{$w}) {
272
+ printf (" %-18s: %s\n", $w, $warnings{$w});
273
+ }
274
+ else {
275
+ printf (" %-18s: %s[*]\n", $w, $warnings_extended{$w});
276
+ }
277
+ }
278
+ print " [*] = disabled by default\n";
279
+ exit;
280
+ }
281
+
282
+ readskiplist();
283
+ readlocalfile($file);
284
+
285
+ do {
286
+ if("$wlist" !~ / $file /) {
287
+ my $fullname = $file;
288
+ $fullname = "$dir/$file" if ($fullname !~ '^\.?\.?/');
289
+ scanfile($fullname);
290
+ }
291
+ $file = shift @ARGV;
292
+
293
+ } while($file);
294
+
295
+ sub accept_violations {
296
+ for my $r (@alist) {
297
+ if(!$warnings{$r}) {
298
+ print "'$r' is not a warning to accept!\n";
299
+ exit;
300
+ }
301
+ $ignore{$r}=999999;
302
+ $ignore_used{$r}=0;
303
+ }
304
+ }
305
+
306
+ sub checksrc_clear {
307
+ undef %ignore;
308
+ undef %ignore_set;
309
+ undef @ignore_line;
310
+ }
311
+
312
+ sub checksrc_endoffile {
313
+ my ($file) = @_;
314
+ for(keys %ignore_set) {
315
+ if($ignore_set{$_} && !$ignore_used{$_}) {
316
+ checkwarn("UNUSEDIGNORE", $ignore_set{$_},
317
+ length($_)+11, $file,
318
+ $ignore_line[$ignore_set{$_}],
319
+ "Unused ignore: $_");
320
+ }
321
+ }
322
+ }
323
+
324
+ sub enable_warn {
325
+ my ($what, $line, $file, $l) = @_;
326
+
327
+ # switch it back on, but warn if not triggered!
328
+ if(!$ignore_used{$what}) {
329
+ checkwarn("UNUSEDIGNORE",
330
+ $line, length($what) + 11, $file, $l,
331
+ "No warning was inhibited!");
332
+ }
333
+ $ignore_set{$what}=0;
334
+ $ignore_used{$what}=0;
335
+ $ignore{$what}=0;
336
+ }
337
+ sub checksrc {
338
+ my ($cmd, $line, $file, $l) = @_;
339
+ if($cmd =~ / *([^ ]*) *(.*)/) {
340
+ my ($enable, $what) = ($1, $2);
341
+ $what =~ s: *\*/$::; # cut off end of C comment
342
+ # print "ENABLE $enable WHAT $what\n";
343
+ if($enable eq "disable") {
344
+ my ($warn, $scope)=($1, $2);
345
+ if($what =~ /([^ ]*) +(.*)/) {
346
+ ($warn, $scope)=($1, $2);
347
+ }
348
+ else {
349
+ $warn = $what;
350
+ $scope = 1;
351
+ }
352
+ # print "IGNORE $warn for SCOPE $scope\n";
353
+ if($scope eq "all") {
354
+ $scope=999999;
355
+ }
356
+
357
+ # Comparing for a literal zero rather than the scalar value zero
358
+ # covers the case where $scope contains the ending '*' from the
359
+ # comment. If we use a scalar comparison (==) we induce warnings
360
+ # on non-scalar contents.
361
+ if($scope eq "0") {
362
+ checkwarn("BADCOMMAND",
363
+ $line, 0, $file, $l,
364
+ "Disable zero not supported, did you mean to enable?");
365
+ }
366
+ elsif($ignore_set{$warn}) {
367
+ checkwarn("BADCOMMAND",
368
+ $line, 0, $file, $l,
369
+ "$warn already disabled from line $ignore_set{$warn}");
370
+ }
371
+ else {
372
+ $ignore{$warn}=$scope;
373
+ $ignore_set{$warn}=$line;
374
+ $ignore_line[$line]=$l;
375
+ }
376
+ }
377
+ elsif($enable eq "enable") {
378
+ enable_warn($what, $line, $file, $l);
379
+ }
380
+ else {
381
+ checkwarn("BADCOMMAND",
382
+ $line, 0, $file, $l,
383
+ "Illegal !checksrc! command");
384
+ }
385
+ }
386
+ }
387
+
388
+ sub nostrings {
389
+ my ($str) = @_;
390
+ $str =~ s/\".*\"//g;
391
+ return $str;
392
+ }
393
+
394
+ sub scanfile {
395
+ my ($file) = @_;
396
+
397
+ my $line = 1;
398
+ my $prevl="";
399
+ my $prevpl="";
400
+ my $l = "";
401
+ my $prep = 0;
402
+ my $prevp = 0;
403
+ open(my $R, '<', $file) || die "failed to open $file";
404
+
405
+ my $incomment=0;
406
+ my @copyright=();
407
+ my %includes;
408
+ checksrc_clear(); # for file based ignores
409
+ accept_violations();
410
+
411
+ while(<$R>) {
412
+ $windows_os ? $_ =~ s/\r?\n$// : chomp;
413
+ my $l = $_;
414
+ my $ol = $l; # keep the unmodified line for error reporting
415
+ my $column = 0;
416
+
417
+ # check for !checksrc! commands
418
+ if($l =~ /\!checksrc\! (.*)/) {
419
+ my $cmd = $1;
420
+ checksrc($cmd, $line, $file, $l)
421
+ }
422
+
423
+ if($l =~ /^#line (\d+) \"([^\"]*)\"/) {
424
+ # a #line instruction
425
+ $file = $2;
426
+ $line = $1;
427
+ next;
428
+ }
429
+
430
+ # check for a copyright statement and save the years
431
+ if($l =~ /\* +copyright .* (\d\d\d\d|)/i) {
432
+ my $count = 0;
433
+ while($l =~ /([\d]{4})/g) {
434
+ push @copyright, {
435
+ year => $1,
436
+ line => $line,
437
+ col => index($l, $1),
438
+ code => $l
439
+ };
440
+ $count++;
441
+ }
442
+ if(!$count) {
443
+ # year-less
444
+ push @copyright, {
445
+ year => -1,
446
+ line => $line,
447
+ col => index($l, $1),
448
+ code => $l
449
+ };
450
+ }
451
+ }
452
+
453
+ # detect long lines
454
+ if(length($l) > $max_column) {
455
+ checkwarn("LONGLINE", $line, length($l), $file, $l,
456
+ "Longer than $max_column columns");
457
+ }
458
+ # detect TAB characters
459
+ if($l =~ /^(.*)\t/) {
460
+ checkwarn("TABS",
461
+ $line, length($1), $file, $l, "Contains TAB character", 1);
462
+ }
463
+ # detect trailing whitespace
464
+ if($l =~ /^(.*)[ \t]+\z/) {
465
+ checkwarn("TRAILINGSPACE",
466
+ $line, length($1), $file, $l, "Trailing whitespace");
467
+ }
468
+
469
+ # no space after comment start
470
+ if($l =~ /^(.*)\/\*\w/) {
471
+ checkwarn("COMMENTNOSPACESTART",
472
+ $line, length($1) + 2, $file, $l,
473
+ "Missing space after comment start");
474
+ }
475
+ # no space at comment end
476
+ if($l =~ /^(.*)\w\*\//) {
477
+ checkwarn("COMMENTNOSPACEEND",
478
+ $line, length($1) + 1, $file, $l,
479
+ "Missing space end comment end");
480
+ }
481
+ # ------------------------------------------------------------
482
+ # Above this marker, the checks were done on lines *including*
483
+ # comments
484
+ # ------------------------------------------------------------
485
+
486
+ # strip off C89 comments
487
+
488
+ comment:
489
+ if(!$incomment) {
490
+ if($l =~ s/\/\*.*\*\// /g) {
491
+ # full /* comments */ were removed!
492
+ }
493
+ if($l =~ s/\/\*.*//) {
494
+ # start of /* comment was removed
495
+ $incomment = 1;
496
+ }
497
+ }
498
+ else {
499
+ if($l =~ s/.*\*\///) {
500
+ # end of comment */ was removed
501
+ $incomment = 0;
502
+ goto comment;
503
+ }
504
+ else {
505
+ # still within a comment
506
+ $l="";
507
+ }
508
+ }
509
+
510
+ # ------------------------------------------------------------
511
+ # Below this marker, the checks were done on lines *without*
512
+ # comments
513
+ # ------------------------------------------------------------
514
+
515
+ # prev line was a preprocessor **and** ended with a backslash
516
+ if($prep && ($prevpl =~ /\\ *\z/)) {
517
+ # this is still a preprocessor line
518
+ $prep = 1;
519
+ goto preproc;
520
+ }
521
+ $prep = 0;
522
+
523
+ # crude attempt to detect // comments without too many false
524
+ # positives
525
+ if($l =~ /^(([^"\*]*)[^:"]|)\/\//) {
526
+ checkwarn("CPPCOMMENTS",
527
+ $line, length($1), $file, $l, "\/\/ comment");
528
+ }
529
+
530
+ if($l =~ /^(\#\s*include\s+)([\">].*[>}"])/) {
531
+ my ($pre, $path) = ($1, $2);
532
+ if($includes{$path}) {
533
+ checkwarn("INCLUDEDUP",
534
+ $line, length($1), $file, $l, "duplicated include");
535
+ }
536
+ $includes{$path} = $l;
537
+ }
538
+
539
+ # detect and strip preprocessor directives
540
+ if($l =~ /^[ \t]*\#/) {
541
+ # preprocessor line
542
+ $prep = 1;
543
+ goto preproc;
544
+ }
545
+
546
+ my $nostr = nostrings($l);
547
+ # check spaces after for/if/while/function call
548
+ if($nostr =~ /^(.*)(for|if|while|switch| ([a-zA-Z0-9_]+)) \((.)/) {
549
+ my ($leading, $word, $extra, $first)=($1,$2,$3,$4);
550
+ if($1 =~ / *\#/) {
551
+ # this is a #if, treat it differently
552
+ }
553
+ elsif(defined $3 && $3 eq "return") {
554
+ # return must have a space
555
+ }
556
+ elsif(defined $3 && $3 eq "case") {
557
+ # case must have a space
558
+ }
559
+ elsif(($first eq "*") && ($word !~ /(for|if|while|switch)/)) {
560
+ # A "(*" beginning makes the space OK because it wants to
561
+ # allow function pointer declared
562
+ }
563
+ elsif($1 =~ / *typedef/) {
564
+ # typedefs can use space-paren
565
+ }
566
+ else {
567
+ checkwarn("SPACEBEFOREPAREN", $line, length($leading)+length($word), $file, $l,
568
+ "$word with space");
569
+ }
570
+ }
571
+ # check for '== NULL' in if/while conditions but not if the thing on
572
+ # the left of it is a function call
573
+ if($nostr =~ /^(.*)(if|while)(\(.*?)([!=]= NULL|NULL [!=]=)/) {
574
+ checkwarn("EQUALSNULL", $line,
575
+ length($1) + length($2) + length($3),
576
+ $file, $l, "we prefer !variable instead of \"== NULL\" comparisons");
577
+ }
578
+
579
+ # check for '!= 0' in if/while conditions but not if the thing on
580
+ # the left of it is a function call
581
+ if($nostr =~ /^(.*)(if|while)(\(.*[^)]) != 0[^x]/) {
582
+ checkwarn("NOTEQUALSZERO", $line,
583
+ length($1) + length($2) + length($3),
584
+ $file, $l, "we prefer if(rc) instead of \"rc != 0\" comparisons");
585
+ }
586
+
587
+ # check spaces in 'do {'
588
+ if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) {
589
+ checkwarn("DOBRACE", $line, length($1) + 2, $file, $l, "one space after do before brace");
590
+ }
591
+ # check spaces in 'do {'
592
+ elsif($nostr =~ /^( *)\}( *)while/ && length($2) != 1) {
593
+ checkwarn("BRACEWHILE", $line, length($1) + 2, $file, $l, "one space between brace and while");
594
+ }
595
+ if($nostr =~ /^((.*\s)(if) *\()(.*)\)(.*)/) {
596
+ my $pos = length($1);
597
+ my $postparen = $5;
598
+ my $cond = $4;
599
+ if($cond =~ / = /) {
600
+ checkwarn("ASSIGNWITHINCONDITION",
601
+ $line, $pos+1, $file, $l,
602
+ "assignment within conditional expression");
603
+ }
604
+ my $temp = $cond;
605
+ $temp =~ s/\(//g; # remove open parens
606
+ my $openc = length($cond) - length($temp);
607
+
608
+ $temp = $cond;
609
+ $temp =~ s/\)//g; # remove close parens
610
+ my $closec = length($cond) - length($temp);
611
+ my $even = $openc == $closec;
612
+
613
+ if($l =~ / *\#/) {
614
+ # this is a #if, treat it differently
615
+ }
616
+ elsif($even && $postparen &&
617
+ ($postparen !~ /^ *$/) && ($postparen !~ /^ *[,{&|\\]+/)) {
618
+ checkwarn("ONELINECONDITION",
619
+ $line, length($l)-length($postparen), $file, $l,
620
+ "conditional block on the same line");
621
+ }
622
+ }
623
+ # check spaces after open parentheses
624
+ if($l =~ /^(.*[a-z])\( /i) {
625
+ checkwarn("SPACEAFTERPAREN",
626
+ $line, length($1)+1, $file, $l,
627
+ "space after open parenthesis");
628
+ }
629
+
630
+ # check spaces before Logical AND operator
631
+ if($nostr =~ /^(.*)\w&&/i) {
632
+ checkwarn("NOSPACEAND",
633
+ $line, length($1)+1, $file, $l,
634
+ "missing space before Logical AND");
635
+ }
636
+
637
+ # check spaces after Logical AND operator
638
+ if($nostr =~ /^(.*&&)\w/i) {
639
+ checkwarn("NOSPACEAND",
640
+ $line, length($1), $file, $l,
641
+ "missing space after Logical AND");
642
+ }
643
+
644
+ # check spaces before colon
645
+ if($nostr =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
646
+ my $m = $1;
647
+ my $e = $nostr;
648
+ $e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that surround colon
649
+ $e =~ s/':'//g; # ignore these
650
+ if($e =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
651
+ checkwarn("NOSPACEC",
652
+ $line, length($m)+1, $file, $l,
653
+ "missing space before colon");
654
+ }
655
+ }
656
+ # check spaces after colon
657
+ if($nostr =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
658
+ my $m = $1;
659
+ my $e = $nostr;
660
+ $e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that surround colon
661
+ $e =~ s/':'//g; # ignore these
662
+ if($e =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
663
+ checkwarn("NOSPACEC",
664
+ $line, length($m)+1, $file, $l,
665
+ "missing space after colon");
666
+ }
667
+ }
668
+
669
+ # check spaces before question mark
670
+ if($nostr =~ /^(.*)(\w|\)|\]|')\?/i) {
671
+ my $m = $1;
672
+ my $e = $nostr;
673
+ $e =~ s/'?'//g; # ignore these
674
+ if($e =~ /^(.*)(\w|\)|\]|')\?/i) {
675
+ checkwarn("NOSPACEQ",
676
+ $line, length($m)+1, $file, $l,
677
+ "missing space before question mark");
678
+ }
679
+ }
680
+ # check spaces after question mark
681
+ if($nostr =~ /^(.*)\?\w/i) {
682
+ checkwarn("NOSPACEQ",
683
+ $line, length($1)+1, $file, $l,
684
+ "missing space after question mark");
685
+ }
686
+
687
+ # check spaces before less or greater than
688
+ if($nostr =~ /^(.*)(\w|\)|\])[<>]/) {
689
+ checkwarn("NOSPACETHAN",
690
+ $line, length($1)+1, $file, $l,
691
+ "missing space before less or greater than");
692
+ }
693
+ # check spaces after less or greater than
694
+ if($nostr =~ /^(.*)[^-][<>](\w|\(|\[)/) {
695
+ checkwarn("NOSPACETHAN",
696
+ $line, length($1)+1, $file, $l,
697
+ "missing space after less or greater than");
698
+ }
699
+
700
+ # check spaces before close parentheses, unless it was a space or a
701
+ # close parenthesis!
702
+ if($l =~ /(.*[^\) ]) \)/) {
703
+ checkwarn("SPACEBEFORECLOSE",
704
+ $line, length($1)+1, $file, $l,
705
+ "space before close parenthesis");
706
+ }
707
+
708
+ # check spaces before comma!
709
+ if($l =~ /(.*[^ ]) ,/) {
710
+ checkwarn("SPACEBEFORECOMMA",
711
+ $line, length($1)+1, $file, $l,
712
+ "space before comma");
713
+ }
714
+
715
+ # check for "return(" without space
716
+ if($l =~ /^(.*)return\(/) {
717
+ if($1 =~ / *\#/) {
718
+ # this is a #if, treat it differently
719
+ }
720
+ else {
721
+ checkwarn("RETURNNOSPACE", $line, length($1)+6, $file, $l,
722
+ "return without space before paren");
723
+ }
724
+ }
725
+
726
+ # check for "sizeof" without parenthesis
727
+ if(($l =~ /^(.*)sizeof *([ (])/) && ($2 ne "(")) {
728
+ if($1 =~ / *\#/) {
729
+ # this is a #if, treat it differently
730
+ }
731
+ else {
732
+ checkwarn("SIZEOFNOPAREN", $line, length($1)+6, $file, $l,
733
+ "sizeof without parenthesis");
734
+ }
735
+ }
736
+
737
+ # check for comma without space
738
+ if($l =~ /^(.*),[^ \n]/) {
739
+ my $pref=$1;
740
+ my $ign=0;
741
+ if($pref =~ / *\#/) {
742
+ # this is a #if, treat it differently
743
+ $ign=1;
744
+ }
745
+ elsif($pref =~ /\/\*/) {
746
+ # this is a comment
747
+ $ign=1;
748
+ }
749
+ elsif($pref =~ /[\"\']/) {
750
+ $ign = 1;
751
+ # There is a quote here, figure out whether the comma is
752
+ # within a string or '' or not.
753
+ if($pref =~ /\"/) {
754
+ # within a string
755
+ }
756
+ elsif($pref =~ /\'$/) {
757
+ # a single letter
758
+ }
759
+ else {
760
+ $ign = 0;
761
+ }
762
+ }
763
+ if(!$ign) {
764
+ checkwarn("COMMANOSPACE", $line, length($pref)+1, $file, $l,
765
+ "comma without following space");
766
+ }
767
+ }
768
+
769
+ # check for "} else"
770
+ if($l =~ /^(.*)\} *else/) {
771
+ checkwarn("BRACEELSE",
772
+ $line, length($1), $file, $l, "else after closing brace on same line");
773
+ }
774
+ # check for "){"
775
+ if($l =~ /^(.*)\)\{/) {
776
+ checkwarn("PARENBRACE",
777
+ $line, length($1)+1, $file, $l, "missing space after close paren");
778
+ }
779
+ # check for "^{" with an empty line before it
780
+ if(($l =~ /^\{/) && ($prevl =~ /^[ \t]*\z/)) {
781
+ checkwarn("EMPTYLINEBRACE",
782
+ $line, 0, $file, $l, "empty line before open brace");
783
+ }
784
+
785
+ # check for space before the semicolon last in a line
786
+ if($l =~ /^(.*[^ ].*) ;$/) {
787
+ checkwarn("SPACESEMICOLON",
788
+ $line, length($1), $file, $ol, "no space before semicolon");
789
+ }
790
+
791
+ # check for space before the colon in a switch label
792
+ if($l =~ /^( *(case .+|default)) :/) {
793
+ checkwarn("SPACESWITCHCOLON",
794
+ $line, length($1), $file, $ol, "no space before colon of switch label");
795
+ }
796
+
797
+ if($prevl !~ /\?\z/ && $l =~ /^ +([A-Za-z_][A-Za-z0-9_]*):$/ && $1 ne 'default') {
798
+ checkwarn("SPACEBEFORELABEL",
799
+ $line, length($1), $file, $ol, "no space before label");
800
+ }
801
+
802
+ # scan for use of banned functions
803
+ if($l =~ /^(.*\W)
804
+ (gmtime|localtime|
805
+ gets|
806
+ strtok|
807
+ v?sprintf|
808
+ (str|_mbs|_tcs|_wcs)n?cat|
809
+ LoadLibrary(Ex)?(A|W)?|
810
+ _?w?access)
811
+ \s*\(
812
+ /x) {
813
+ checkwarn("BANNEDFUNC",
814
+ $line, length($1), $file, $ol,
815
+ "use of $2 is banned");
816
+ }
817
+ if($warnings{"STRERROR"}) {
818
+ # scan for use of banned strerror. This is not a BANNEDFUNC to
819
+ # allow for individual enable/disable of this warning.
820
+ if($l =~ /^(.*\W)(strerror)\s*\(/x) {
821
+ if($1 !~ /^ *\#/) {
822
+ # skip preprocessor lines
823
+ checkwarn("STRERROR",
824
+ $line, length($1), $file, $ol,
825
+ "use of $2 is banned");
826
+ }
827
+ }
828
+ }
829
+ if($warnings{"STRNCPY"}) {
830
+ # scan for use of banned strncpy. This is not a BANNEDFUNC to
831
+ # allow for individual enable/disable of this warning.
832
+ if($l =~ /^(.*\W)(strncpy)\s*\(/x) {
833
+ if($1 !~ /^ *\#/) {
834
+ # skip preprocessor lines
835
+ checkwarn("STRNCPY",
836
+ $line, length($1), $file, $ol,
837
+ "use of $2 is banned");
838
+ }
839
+ }
840
+ }
841
+ if($warnings{"STDERR"}) {
842
+ # scan for use of banned stderr. This is not a BANNEDFUNC to
843
+ # allow for individual enable/disable of this warning.
844
+ if($l =~ /^([^\"-]*\W)(stderr)[^\"_]/x) {
845
+ if($1 !~ /^ *\#/) {
846
+ # skip preprocessor lines
847
+ checkwarn("STDERR",
848
+ $line, length($1), $file, $ol,
849
+ "use of $2 is banned (use tool_stderr instead)");
850
+ }
851
+ }
852
+ }
853
+ # scan for use of snprintf for curl-internals reasons
854
+ if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) {
855
+ checkwarn("SNPRINTF",
856
+ $line, length($1), $file, $ol,
857
+ "use of $2 is banned");
858
+ }
859
+
860
+ # scan for use of non-binary fopen without the macro
861
+ if($l =~ /^(.*\W)fopen\s*\([^,]*, *\"([^"]*)/) {
862
+ my $mode = $2;
863
+ if($mode !~ /b/) {
864
+ checkwarn("FOPENMODE",
865
+ $line, length($1), $file, $ol,
866
+ "use of non-binary fopen without FOPEN_* macro: $mode");
867
+ }
868
+ }
869
+
870
+ # check for open brace first on line but not first column only alert
871
+ # if previous line ended with a close paren and it wasn't a cpp line
872
+ if(($prevl =~ /\)\z/) && ($l =~ /^( +)\{/) && !$prevp) {
873
+ checkwarn("BRACEPOS",
874
+ $line, length($1), $file, $ol, "badly placed open brace");
875
+ }
876
+
877
+ # if the previous line starts with if/while/for AND ends with an open
878
+ # brace, or an else statement, check that this line is indented $indent
879
+ # more steps, if not a cpp line
880
+ if(!$prevp && ($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/)) {
881
+ my $first = length($1);
882
+ # this line has some character besides spaces
883
+ if($l =~ /^( *)[^ ]/) {
884
+ my $second = length($1);
885
+ my $expect = $first+$indent;
886
+ if($expect != $second) {
887
+ my $diff = $second - $first;
888
+ checkwarn("INDENTATION", $line, length($1), $file, $ol,
889
+ "not indented $indent steps (uses $diff)");
890
+
891
+ }
892
+ }
893
+ }
894
+
895
+ # if the previous line starts with if/while/for AND ends with a closed
896
+ # parenthesis and there's an equal number of open and closed
897
+ # parentheses, check that this line is indented $indent more steps, if
898
+ # not a cpp line
899
+ elsif(!$prevp && ($prevl =~ /^( *)(if|while|for)(\(.*\))\z/)) {
900
+ my $first = length($1);
901
+ my $op = $3;
902
+ my $cl = $3;
903
+
904
+ $op =~ s/[^(]//g;
905
+ $cl =~ s/[^)]//g;
906
+
907
+ if(length($op) == length($cl)) {
908
+ # this line has some character besides spaces
909
+ if($l =~ /^( *)[^ ]/) {
910
+ my $second = length($1);
911
+ my $expect = $first+$indent;
912
+ if($expect != $second) {
913
+ my $diff = $second - $first;
914
+ checkwarn("INDENTATION", $line, length($1), $file, $ol,
915
+ "not indented $indent steps (uses $diff)");
916
+ }
917
+ }
918
+ }
919
+ }
920
+
921
+ # check for 'char * name'
922
+ if(($l =~ /(^.*(char|int|long|void|CURL|CURLM|CURLMsg|[cC]url_[A-Za-z_]+|struct [a-zA-Z_]+) *(\*+)) (\w+)/) && ($4 !~ /^(const|volatile)$/)) {
923
+ checkwarn("ASTERISKSPACE",
924
+ $line, length($1), $file, $ol,
925
+ "space after declarative asterisk");
926
+ }
927
+ # check for 'char*'
928
+ if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost|sockaddr_in|FILE)\*)/)) {
929
+ checkwarn("ASTERISKNOSPACE",
930
+ $line, length($1)-1, $file, $ol,
931
+ "no space before asterisk");
932
+ }
933
+
934
+ # check for 'void func() {', but avoid false positives by requiring
935
+ # both an open and closed parentheses before the open brace
936
+ if($l =~ /^((\w).*)\{\z/) {
937
+ my $k = $1;
938
+ $k =~ s/const *//;
939
+ $k =~ s/static *//;
940
+ if($k =~ /\(.*\)/) {
941
+ checkwarn("BRACEPOS",
942
+ $line, length($l)-1, $file, $ol,
943
+ "wrongly placed open brace");
944
+ }
945
+ }
946
+
947
+ # check for equals sign without spaces next to it
948
+ if($nostr =~ /(.*)\=[a-z0-9]/i) {
949
+ checkwarn("EQUALSNOSPACE",
950
+ $line, length($1)+1, $file, $ol,
951
+ "no space after equals sign");
952
+ }
953
+ # check for equals sign without spaces before it
954
+ elsif($nostr =~ /(.*)[a-z0-9]\=/i) {
955
+ checkwarn("NOSPACEEQUALS",
956
+ $line, length($1)+1, $file, $ol,
957
+ "no space before equals sign");
958
+ }
959
+
960
+ # check for plus signs without spaces next to it
961
+ if($nostr =~ /(.*)[^+]\+[a-z0-9]/i) {
962
+ checkwarn("PLUSNOSPACE",
963
+ $line, length($1)+1, $file, $ol,
964
+ "no space after plus sign");
965
+ }
966
+ # check for plus sign without spaces before it
967
+ elsif($nostr =~ /(.*)[a-z0-9]\+[^+]/i) {
968
+ checkwarn("NOSPACEPLUS",
969
+ $line, length($1)+1, $file, $ol,
970
+ "no space before plus sign");
971
+ }
972
+
973
+ # check for semicolons without space next to it
974
+ if($nostr =~ /(.*)\;[a-z0-9]/i) {
975
+ checkwarn("SEMINOSPACE",
976
+ $line, length($1)+1, $file, $ol,
977
+ "no space after semicolon");
978
+ }
979
+
980
+ # typedef struct ... {
981
+ if($nostr =~ /^(.*)typedef struct.*{/) {
982
+ checkwarn("TYPEDEFSTRUCT",
983
+ $line, length($1)+1, $file, $ol,
984
+ "typedef'ed struct");
985
+ }
986
+
987
+ if($nostr =~ /(.*)! +(\w|\()/) {
988
+ checkwarn("EXCLAMATIONSPACE",
989
+ $line, length($1)+1, $file, $ol,
990
+ "space after exclamation mark");
991
+ }
992
+
993
+ # check for more than one consecutive space before open brace or
994
+ # question mark. Skip lines containing strings since they make it hard
995
+ # due to artificially getting multiple spaces
996
+ if(($l eq $nostr) &&
997
+ $nostr =~ /^(.*(\S)) + [{?]/i) {
998
+ checkwarn("MULTISPACE",
999
+ $line, length($1)+1, $file, $ol,
1000
+ "multiple spaces");
1001
+ }
1002
+ preproc:
1003
+ if($prep) {
1004
+ # scan for use of banned symbols on a preprocessor line
1005
+ if($l =~ /^(^|.*\W)
1006
+ (WIN32)
1007
+ (\W|$)
1008
+ /x) {
1009
+ checkwarn("BANNEDPREPROC",
1010
+ $line, length($1), $file, $ol,
1011
+ "use of $2 is banned from preprocessor lines" .
1012
+ (($2 eq "WIN32") ? ", use _WIN32 instead" : ""));
1013
+ }
1014
+ }
1015
+ $line++;
1016
+ $prevp = $prep;
1017
+ $prevl = $ol if(!$prep);
1018
+ $prevpl = $ol if($prep);
1019
+ }
1020
+
1021
+ if(!scalar(@copyright)) {
1022
+ checkwarn("COPYRIGHT", 1, 0, $file, "", "Missing copyright statement", 1);
1023
+ }
1024
+
1025
+ # COPYRIGHTYEAR is an extended warning so we must first see if it has been
1026
+ # enabled in .checksrc
1027
+ if(defined($warnings{"COPYRIGHTYEAR"})) {
1028
+ # The check for updated copyrightyear is overly complicated in order to
1029
+ # not punish current hacking for past sins. The copyright years are
1030
+ # right now a bit behind, so enforcing copyright year checking on all
1031
+ # files would cause hundreds of errors. Instead we only look at files
1032
+ # which are tracked in the Git repo and edited in the workdir, or
1033
+ # committed locally on the branch without being in upstream master.
1034
+ #
1035
+ # The simple and naive test is to simply check for the current year,
1036
+ # but updating the year even without an edit is against project policy
1037
+ # (and it would fail every file on January 1st).
1038
+ #
1039
+ # A rather more interesting, and correct, check would be to not test
1040
+ # only locally committed files but inspect all files wrt the year of
1041
+ # their last commit. Removing the `git rev-list origin/master..HEAD`
1042
+ # condition below will enforce copyright year checks against the year
1043
+ # the file was last committed (and thus edited to some degree).
1044
+ my $commityear = undef;
1045
+ @copyright = sort {$$b{year} cmp $$a{year}} @copyright;
1046
+
1047
+ # if the file is modified, assume commit year this year
1048
+ if(`git status -s -- "$file"` =~ /^ [MARCU]/) {
1049
+ $commityear = (localtime(time))[5] + 1900;
1050
+ }
1051
+ else {
1052
+ # min-parents=1 to ignore wrong initial commit in truncated repos
1053
+ my $grl = `git rev-list --max-count=1 --min-parents=1 --timestamp HEAD -- "$file"`;
1054
+ if($grl) {
1055
+ chomp $grl;
1056
+ $commityear = (localtime((split(/ /, $grl))[0]))[5] + 1900;
1057
+ }
1058
+ }
1059
+
1060
+ if(defined($commityear) && scalar(@copyright) &&
1061
+ $copyright[0]{year} != $commityear) {
1062
+ checkwarn("COPYRIGHTYEAR", $copyright[0]{line}, $copyright[0]{col},
1063
+ $file, $copyright[0]{code},
1064
+ "Copyright year out of date, should be $commityear, " .
1065
+ "is $copyright[0]{year}", 1);
1066
+ }
1067
+ }
1068
+
1069
+ if($incomment) {
1070
+ checkwarn("OPENCOMMENT", 1, 0, $file, "", "Missing closing comment", 1);
1071
+ }
1072
+
1073
+ checksrc_endoffile($file);
1074
+
1075
+ close($R);
1076
+
1077
+ }
1078
+
1079
+
1080
+ if($errors || $warnings || $verbose) {
1081
+ printf "checksrc: %d errors and %d warnings\n", $errors, $warnings;
1082
+ if($suppressed) {
1083
+ printf "checksrc: %d errors and %d warnings suppressed\n",
1084
+ $serrors,
1085
+ $swarnings;
1086
+ }
1087
+ exit 5; # return failure
1088
+ }
local-test-curl-delta-01/afc-curl/scripts/ciconfig.pl ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # these options are enabled by default in the sense that they will attempt to
27
+ # check for and use this feature without the configure flag
28
+ my %defaulton = (
29
+ # --enable-
30
+ 'shared' => 1,
31
+ 'static' => 1,
32
+ 'fast-install' => 1,
33
+ 'silent-rules' => 1,
34
+ 'optimize' => 1,
35
+ 'http' => 1,
36
+ 'ftp' => 1,
37
+ 'file' => 1,
38
+ 'ldap' => 1,
39
+ 'ldaps' => 1,
40
+ 'rtsp' => 1,
41
+ 'proxy' => 1,
42
+ 'dict' => 1,
43
+ 'telnet' => 1,
44
+ 'tftp' => 1,
45
+ 'pop3' => 1,
46
+ 'imap' => 1,
47
+ 'smb' => 1,
48
+ 'smtp' => 1,
49
+ 'gopher' => 1,
50
+ 'mqtt' => 1,
51
+ 'manual' => 1,
52
+ 'libcurl-option' => 1,
53
+ 'libgcc' => 1,
54
+ 'ipv6' => 1,
55
+ 'openssl-auto-load-config' => 1,
56
+ 'versioned-symbols' => 1,
57
+ 'symbol-hiding' => 1,
58
+ 'threaded-resolver' => 1,
59
+ 'pthreads' => 1,
60
+ 'verbose' => 1,
61
+ 'basic-auth' => 1,
62
+ 'bearer-auth' => 1,
63
+ 'digest-auth' => 1,
64
+ 'kerberos-auth' => 1,
65
+ 'negotiate-auth' => 1,
66
+ 'aws' => 1,
67
+ 'ntlm' => 1,
68
+ 'ntlm-wb' => 1,
69
+ 'tls-srp' => 1,
70
+ 'unix-sockets' => 1,
71
+ 'cookies' => 1,
72
+ 'socketpair' => 1,
73
+ 'http-auth' => 1,
74
+ 'doh' => 1,
75
+ 'mime' => 1,
76
+ 'dateparse' => 1,
77
+ 'netrc' => 1,
78
+ 'progress-meter' => 1,
79
+ 'dnsshuffle' => 1,
80
+ 'get-easy-options' => 1,
81
+ 'alt-svc' => 1,
82
+ 'hsts' => 1,
83
+
84
+ # --with-
85
+ 'aix-soname' => 1,
86
+ 'pic' => 1,
87
+ 'zlib' => 1,
88
+ 'zstd' => 1,
89
+ 'brotli' => 1,
90
+ 'random' => 1,
91
+ 'ca-bundle' => 1,
92
+ 'ca-path' => 1,
93
+ 'libssh2' => 1,
94
+ 'nghttp2' => 1,
95
+ 'librtmp' => 1,
96
+ 'libidn2' => 1,
97
+ 'sysroot' => 1,
98
+ 'lber-lib' => 1,
99
+ 'ldap-lib' => 1,
100
+
101
+ );
102
+
103
+
104
+ sub configureopts {
105
+ my ($opts)=@_;
106
+ my %thisin;
107
+ my %thisout;
108
+
109
+ while($opts =~ s/--with-([^ =]*)//) {
110
+ $with{$1}++;
111
+ $used{$1}++;
112
+ $thisin{$1}++;
113
+ }
114
+ while($opts =~ s/--enable-([^ =]*)//) {
115
+ $with{$1}++;
116
+ $used{$1}++;
117
+ $thisin{$1}++;
118
+ }
119
+
120
+ while($opts =~ s/--without-([^ =]*)//) {
121
+ $without{$1}++;
122
+ $used{$1}++;
123
+ $thisout{$1}++;
124
+ }
125
+ while($opts =~ s/--disable-([^ =]*)//) {
126
+ $without{$1}++;
127
+ $used{$1}++;
128
+ $thisout{$1}++;
129
+ }
130
+ return join(" ", sort(keys %thisin), "/", sort(keys %thisout));
131
+ }
132
+
133
+ # run configure --help and check what available WITH/ENABLE options that exist
134
+ sub configurehelp {
135
+ open(C, "./configure --help|");
136
+ while(<C>) {
137
+ if($_ =~ /^ --(with|enable)-([a-z0-9-]+)/) {
138
+ $avail{$2}++;
139
+ }
140
+ }
141
+ close(C);
142
+ }
143
+
144
+ sub scanjobs {
145
+
146
+ my $jobs;
147
+ open(CI, "./scripts/cijobs.pl|");
148
+ while(<CI>) {
149
+ if($_ =~ /^\#\#\#/) {
150
+ $jobs++;
151
+ }
152
+ if($_ =~ /^configure: (.*)/) {
153
+ my $c= configureopts($1);
154
+ #print "C: $c\n";
155
+ }
156
+ }
157
+ close(CI);
158
+ }
159
+
160
+ configurehelp();
161
+ scanjobs();
162
+
163
+ print "Used configure options (with / without)\n";
164
+ for my $w (sort keys %used) {
165
+ printf " %s: %d %d%s\n", $w, $with{$w}, $without{$w},
166
+ $defaulton{$w} ? " (auto)":"";
167
+ }
168
+
169
+ print "Never used configure options\n";
170
+ for my $w (sort keys %avail) {
171
+ if(!$used{$w}) {
172
+ printf " %s%s\n", $w,
173
+ $defaulton{$w} ? " (auto)":"";
174
+ }
175
+ }
176
+
177
+ print "Never ENABLED configure options that aren't on by default\n";
178
+ for my $w (sort keys %avail) {
179
+ if(!$with{$w} && !$defaulton{$w}) {
180
+ printf " %s\n", $w;
181
+ }
182
+ }
183
+
184
+
185
+ print "ENABLED configure options that aren't available\n";
186
+ for my $w (sort keys %with) {
187
+ if(!$avail{$w}) {
188
+ printf " %s\n", $w;
189
+ }
190
+ }
local-test-curl-delta-01/afc-curl/scripts/cijobs.pl ADDED
@@ -0,0 +1,510 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ my %filelevel= ('file' => 1,
27
+ 'service' => 1);
28
+
29
+ my $jobid = 1;
30
+
31
+ sub submit {
32
+ my ($jref)=@_;
33
+ my %job = %$jref;
34
+
35
+ printf "\n##### job %u \n", $jobid++;
36
+ for my $k (sort keys %job) {
37
+ printf "%s: %s\n", $k, $job{$k} if($job{$k});
38
+ undef $$jref{$k} if(!$filelevel{$k});
39
+ }
40
+ }
41
+
42
+ sub githubactions {
43
+ my ($tag)=@_;
44
+ my @files= `git ls-tree -r --name-only $tag .github/workflows 2>/dev/null`;
45
+ my $c = 0;
46
+ foreach my $f (sort @files) {
47
+ my $j = 0;
48
+ my $m = -1;
49
+ my $done = 0;
50
+ chomp $f;
51
+ open(G, "git show $tag:$f 2>/dev/null|");
52
+ # start counting file jobs
53
+ undef %job;
54
+ $job{'file'} = $f;
55
+ $job{'service'} = "gha";
56
+ my @cc;
57
+ my $os;
58
+ my $topname;
59
+ my $line = 1;
60
+ while(<G>) {
61
+ $job{'line'} = $line;
62
+ if($_ =~ /^name: (.*)/) {
63
+ $topname=$1;
64
+ }
65
+ elsif($_ =~ /runs-on: (.*)/) {
66
+ my $r = $1;
67
+ #print "runs-on: $r\n";
68
+ if($r =~ /ubuntu/) {
69
+ $os = "linux";
70
+ }
71
+ elsif($r =~ /macos/) {
72
+ $os = "macos";
73
+ }
74
+ elsif($r =~ /windows/) {
75
+ $os = "windows";
76
+ }
77
+
78
+ # commit previously counted jobs
79
+ $c += $j;
80
+ # non-matrix job
81
+ $j = 1;
82
+ }
83
+ elsif($_ =~ /^\s*matrix:/) {
84
+ # switch to matrix mode
85
+ $m = 0;
86
+ $j = 0;
87
+ }
88
+ elsif($_ =~ /^ - run: .* apt-get install (.*)/) {
89
+ $job{'install'} = $1;
90
+ }
91
+ elsif($m >= 0) {
92
+ if($_ =~ /^ - name: (.*)/) {
93
+ # matrix job
94
+ #print "name: $1\n";
95
+ $job{'name'} = $1;
96
+ $j += ($m?$m:1);
97
+ }
98
+ elsif($_ =~ /install: (.*)/) {
99
+ $job{'install'} = $1;
100
+ }
101
+ elsif($_ =~ /( |curl-)configure: (.*)/) {
102
+ $job{'configure'} = $2;
103
+ $job{'os'}=$os;
104
+ submit(\%job);
105
+ $done++;
106
+ }
107
+ elsif($_ =~ /generate: (.*)/) {
108
+ $job{'cmake'} = $1;
109
+ if($m) {
110
+ # matrix mode, multiple copies
111
+ my %dupe = %job;
112
+ for my $cc (@cc) {
113
+ %job = %dupe;
114
+ $job{'cc'} = $cc;
115
+ $job{'os'}=$os;
116
+ submit(\%job);
117
+ $done++;
118
+ }
119
+ }
120
+ else {
121
+ $job{'os'}=$os;
122
+ submit(\%job);
123
+ $done++;
124
+ }
125
+ }
126
+ elsif($_ =~ /- CC: (.*)/) {
127
+ # matrix multiplier
128
+ push @cc, $1;
129
+ $m++;
130
+ }
131
+ elsif($_ =~ /^\s*steps:/) {
132
+ # disable matrix mode
133
+ $m = -1;
134
+ }
135
+ }
136
+ $line++;
137
+ }
138
+ close(G);
139
+ # commit final counted jobs
140
+ $c += $j;
141
+
142
+ if(!$done) {
143
+ $job{'name'} = $topname? $topname : '[unnamed]';
144
+ $job{'os'}=$os;
145
+ submit(\%job);
146
+ $done++;
147
+ }
148
+ # reset internal job counter
149
+ $j = 0;
150
+ }
151
+ #print "Jobs: $c\n";
152
+ return $c;
153
+ }
154
+
155
+ sub azurepipelines {
156
+ my ($tag)=@_;
157
+ open(G, "git show $tag:.azure-pipelines.yml 2>/dev/null|");
158
+ my $c = 0;
159
+ my $j = 0;
160
+ my $m = -1;
161
+ my $image;
162
+ my %job;
163
+ my $line = 1;
164
+ my $os;
165
+ $job{'file'} = ".azure-pipelines.yml";
166
+ $job{'service'} = "azure";
167
+ while(<G>) {
168
+ if($_ =~ /^ vmImage: (.*)/) {
169
+ my $i = $1;
170
+ if($i =~ /ubuntu/) {
171
+ $os = "linux";
172
+ }
173
+ elsif($i =~ /windows/) {
174
+ $os = "windows";
175
+ }
176
+ }
177
+ elsif($_ =~ /^ - stage: (.*)/) {
178
+ my $topname = $1;
179
+ if($topname !~ /(windows|linux)/) {
180
+ $job{'name'} = $topname;
181
+ $job{'line'}=$line;
182
+ submit(\%job);
183
+ }
184
+ }
185
+ elsif($_ =~ /job:/) {
186
+ # commit previously counted jobs
187
+ $c += $j;
188
+ # initial value for non-matrix job
189
+ $j = 1;
190
+ }
191
+ elsif($_ =~ /matrix:/) {
192
+ # start of new matrix list(!)
193
+ $m = 0;
194
+ $j = 0;
195
+ }
196
+ elsif($m >= 0) {
197
+ if($_ =~ /^ name: (.*)/) {
198
+ # single matrix list entry job
199
+ $j++;
200
+ $job{'name'} = $1;
201
+ }
202
+ # azure matrix is a simple list,
203
+ # therefore no multiplier needed
204
+ elsif($_ =~ /steps:/) {
205
+ # disable matrix mode
206
+ $m = -1;
207
+ }
208
+ elsif($_ =~ /^ configure: (.*)/) {
209
+ $job{'configure'} = $1;
210
+ $job{'line'}=$line;
211
+ $job{'os'}=$os;
212
+ submit(\%job);
213
+ }
214
+ }
215
+ $line++;
216
+ }
217
+ close(G);
218
+ # commit final counted jobs
219
+ $c += $j;
220
+
221
+ return $c;
222
+ }
223
+
224
+ sub appveyor {
225
+ my ($tag)=@_;
226
+ open(G, "git show $tag:appveyor.yml 2>/dev/null|");
227
+ my $c = 0;
228
+ my %job;
229
+ my $line=0;
230
+ $job{'file'} = "appveyor.yml";
231
+ $job{'service'} = "appveyor";
232
+
233
+ while(<G>) {
234
+ $line++;
235
+ if($_ =~ /^( - |install)/) {
236
+ if($job{'image'}) {
237
+ $job{'os'} = "windows";
238
+ submit(\%job);
239
+ $c++;
240
+ }
241
+ }
242
+ $job{'line'} = $line;
243
+ if($_ =~ /^ APPVEYOR_BUILD_WORKER_IMAGE: \'(.*)\'/) {
244
+ $job{'image'}= $1;
245
+ }
246
+ elsif($_ =~ /^ BUILD_SYSTEM: (.*)/) {
247
+ $job{'build'} = lc($1);
248
+ }
249
+ elsif($_ =~ /^ PRJ_GEN: \'(.*)\'/) {
250
+ $job{'compiler'} = $1;
251
+ }
252
+ elsif($_ =~ /^ PRJ_CFG: (.*)/) {
253
+ $job{'config'} = $1;
254
+ }
255
+ elsif($_ =~ /^ OPENSSL: \'(.*)\'/) {
256
+ $job{'openssl'} = $1 eq "ON" ? "true": "false";
257
+ }
258
+ elsif($_ =~ /^ SCHANNEL: \'(.*)\'/) {
259
+ $job{'schannel'} = $1 eq "ON" ? "true": "false";
260
+ }
261
+ elsif($_ =~ /^ ENABLE_UNICODE: \'(.*)\'/) {
262
+ $job{'unicode'} = $1 eq "ON" ? "true": "false";
263
+ }
264
+ elsif($_ =~ /^ HTTP_ONLY: \'(.*)\'/) {
265
+ $job{'http-only'} = $1 eq "ON" ? "true": "false";
266
+ }
267
+ elsif($_ =~ /^ TESTING: \'(.*)\'/) {
268
+ $job{'testing'} = $1 eq "ON" ? "true": "false";
269
+ }
270
+ elsif($_ =~ /^ SHARED: \'(.*)\'/) {
271
+ $job{'shared'} = $1 eq "ON" ? "true": "false";
272
+ }
273
+ elsif($_ =~ /^ TARGET: \'-A (.*)\'/) {
274
+ $job{'target'} = $1;
275
+ }
276
+ }
277
+ close(G);
278
+
279
+ return $c;
280
+ }
281
+
282
+ sub cirrus {
283
+ my ($tag)=@_;
284
+ open(G, "git show $tag:.cirrus.yml 2>/dev/null|");
285
+ my $c = 0;
286
+ my %job;
287
+ my $line=0;
288
+ my $name = 0;
289
+ my $os;
290
+ $job{'file'} = ".cirrus.yml";
291
+ $job{'service'} = "cirrus";
292
+ while(<G>) {
293
+ $line++;
294
+ if($_ =~ /^ ( |-) (name|image_family|image):/) {
295
+ $c++;
296
+ }
297
+ if($_ =~ /^ - name:/) {
298
+ if($name) {
299
+ $job{'os'} = $os;
300
+ $job{'line'} = $line;
301
+ submit(\%job);
302
+ $name = 0;
303
+ }
304
+ }
305
+ if($_ =~ /^ - name: (.*)/) {
306
+ $job{'name'} = $1;
307
+ $name = 1;
308
+ }
309
+ elsif($_ =~ /^ image_family: (.*)/) {
310
+ $os = "freebsd";
311
+ }
312
+ elsif($_ =~ /^windows_task:/) {
313
+ $os = "windows";
314
+ }
315
+ elsif($_ =~ /^ prepare: pacman -S --needed --noconfirm --noprogressbar (.*)/) {
316
+ $job{'install'} = $1;
317
+ }
318
+ elsif($_ =~ /^ configure: (.*)/) {
319
+ $job{'configure'} = $1;
320
+ }
321
+ }
322
+ close(G);
323
+ if($name) {
324
+ $job{'os'} = $os;
325
+ $job{'line'} = $line;
326
+ submit(\%job);
327
+ }
328
+ return $c;
329
+ }
330
+
331
+ sub circle {
332
+ my ($tag)=@_;
333
+ open(G, "git show $tag:.circleci/config.yml 2>/dev/null|");
334
+ my $c = 0;
335
+ my $wf = 0;
336
+ my %job;
337
+ my %cmd;
338
+ my %configure;
339
+ my %target;
340
+ my $line=0;
341
+ my $cmds;
342
+ my $jobs;
343
+ my $workflow;
344
+ $job{'file'} = ".circleci/config.yml";
345
+ $job{'service'} = "circleci";
346
+ while(<G>) {
347
+ $line++;
348
+ if($_ =~ /^commands:/) {
349
+ # we record configure lines in this state
350
+ $cmds = 1;
351
+ }
352
+ elsif($cmds) {
353
+ if($_ =~ /^ ([^ ]*):/) {
354
+ $cmdname = $1;
355
+ }
356
+ elsif($_ =~ /^ .*.\/configure (.*)/) {
357
+ $cmd{$cmdname}=$1;
358
+ }
359
+ }
360
+ if($_ =~ /^jobs:/) {
361
+ # we record which job runs with configure here
362
+ $jobs = 1;
363
+ $cmds = 0;
364
+ }
365
+ elsif($jobs) {
366
+ if($_ =~ /^ ([^ ]*):/) {
367
+ $jobname = $1;
368
+ }
369
+ elsif($_ =~ /^ - (configure.*)/) {
370
+ $configure{$jobname}=$1;
371
+ }
372
+ elsif($_ =~ /^ resource_class: arm.medium/) {
373
+ $target{$jobname}="arm";
374
+ }
375
+ }
376
+ if($_ =~ /^workflows:/) {
377
+ $wf = 1;
378
+ $cmds = 0;
379
+ }
380
+ elsif($wf) {
381
+ if($_ =~ /^ ([^ ]+):/) {
382
+ $workflow = $1;
383
+ }
384
+ elsif($_ =~ /^ - (.*)\n/) {
385
+ my $jb = $1;
386
+ my $cnfgure = $configure{$jb};
387
+ my $trgt = $target{$jb};
388
+ $job{'configure'} = $cmd{$cnfgure};
389
+ $job{'name' }=$workflow;
390
+ $job{'os'} = "linux";
391
+ $job{'line'} = $line;
392
+ $job{'target'} = $trgt if($trgt);
393
+ submit(\%job);
394
+ }
395
+ if($_ =~ / *jobs:/) {
396
+ $c++;
397
+ }
398
+ }
399
+ }
400
+ close(G);
401
+ return $c;
402
+ }
403
+
404
+ sub zuul {
405
+ my ($tag)=@_;
406
+ open(G, "git show $tag:zuul.d/jobs.yaml 2>/dev/null|");
407
+ my $c = 0;
408
+ my %job;
409
+ my $line=0;
410
+ my $type;
411
+ $job{'file'} = "zuul.d/jobs.yaml";
412
+ $job{'service'} = "zuul";
413
+ while(<G>) {
414
+ $line++;
415
+ #print "L: ($jobmode / $env) $_";
416
+ if($_ =~ /^- job:/) {
417
+ $jobmode = 1; # start a new
418
+ $type="configure";
419
+ }
420
+ if($jobmode) {
421
+ if($apt) {
422
+ if($_ =~ /^ - (.*)/) {
423
+ my $value = $1;
424
+ $job{'install'} .= "$value ";
425
+ }
426
+ else {
427
+ $apt = 0; # end of curl_apt_packages
428
+ }
429
+ }
430
+ if($env) {
431
+ if($envcont) {
432
+ if($_ =~ /^ (.*)/) {
433
+ $job{$envcont} .= "$1 ";
434
+ }
435
+ else {
436
+ $envcont = "";
437
+ }
438
+ }
439
+ if($_ =~ /^ ([^:]+): (.*)/) {
440
+ my ($var, $value) = ($1, $2);
441
+
442
+ if($var eq "C") {
443
+ $var = $type;
444
+ }
445
+ elsif($var eq "T") {
446
+ $var = "tests";
447
+ if($value eq "cmake") {
448
+ # otherwise it remains configure
449
+ $type = "cmake";
450
+ }
451
+ }
452
+ elsif($var eq "CC") {
453
+ $var = "compiler";
454
+ }
455
+ elsif($var eq "CHECKSRC") {
456
+ $job{'checksrc'} = $value ? "true": "false";
457
+ $var = "";
458
+ }
459
+ else {
460
+ $var = "";
461
+ }
462
+ if($value eq ">-") {
463
+ $envcont = $var;
464
+ }
465
+ elsif($var) {
466
+ $job{$var} = $value;
467
+ }
468
+ }
469
+ elsif($_ !~ /^ /) {
470
+ # end of envs
471
+ $env = 0;
472
+ }
473
+ }
474
+ if($_ =~ /^ curl_env:/) {
475
+ $env = 1; # start of envs
476
+ }
477
+ elsif($_ =~ /^ curl_apt_packages:/) {
478
+ $apt = 1; # start of apt packages
479
+ }
480
+ elsif($_ =~ /^ name: (.*)/) {
481
+ my $n = $1;
482
+ if($n eq "curl-base") {
483
+ # not counted
484
+ $jobmode = 0;
485
+ next;
486
+ }
487
+ $job{'name'} = $n;
488
+ }
489
+ elsif($_ =~ /^\n\z/) {
490
+ # a job is complete
491
+ $job{'line'}=$line;
492
+ $job{'os'}="linux";
493
+ submit(\%job);
494
+ $jobmode = 0;
495
+ $c++;
496
+ }
497
+ }
498
+ }
499
+ close(G);
500
+ return $c;
501
+ }
502
+
503
+ my $tag = `git rev-parse --abbrev-ref HEAD 2>/dev/null` || "master";
504
+ chomp $tag;
505
+ githubactions($tag);
506
+ azurepipelines($tag);
507
+ appveyor($tag);
508
+ zuul($tag);
509
+ cirrus($tag);
510
+ circle($tag);
local-test-curl-delta-01/afc-curl/scripts/cmakelint.sh ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Dan Fandrich, <dan@coneharvesters.com>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # Run cmakelint on the curl source code. It will check all files given on the
27
+ # command-line, or else all relevant files in git, or if not in a git
28
+ # repository, all files starting in the tree rooted in the current directory.
29
+ #
30
+ # cmakelint can be installed from PyPi with the command "python3 -m pip install
31
+ # cmakelint".
32
+ #
33
+ # The xargs invocation is portable, but does not preserve spaces in file names.
34
+ # If such a file is ever added, then this can be portably fixed by switching to
35
+ # "xargs -I{}" and appending {} to the end of the xargs arguments (which will
36
+ # call cmakelint once per file) or by using the GNU extension "xargs -d'\n'".
37
+ {
38
+ if [ -n "$1" ]; then
39
+ for A in "$@"; do printf "%s\n" "$A"; done
40
+ elif git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
41
+ git ls-files
42
+ else
43
+ # strip off the leading ./ to make the grep regexes work properly
44
+ find . -type f | sed 's@^\./@@'
45
+ fi
46
+ } | grep -E '(^CMake|/CMake|\.cmake$)' | grep -v -E '(\.h\.cmake|\.in)$' \
47
+ | xargs \
48
+ cmakelint \
49
+ --spaces=2 --linelength=132 \
50
+ --filter=-whitespace/indent,-convention/filename,-package/stdargs
local-test-curl-delta-01/afc-curl/scripts/completion.pl ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ use strict;
27
+ use warnings;
28
+ use Getopt::Long();
29
+ use Pod::Usage();
30
+
31
+ my $curl = 'curl';
32
+ my $shell = 'zsh';
33
+ my $help = 0;
34
+ Getopt::Long::GetOptions(
35
+ 'curl=s' => \$curl,
36
+ 'shell=s' => \$shell,
37
+ 'help' => \$help,
38
+ ) or Pod::Usage::pod2usage();
39
+ Pod::Usage::pod2usage() if $help;
40
+
41
+ my $regex = '\s+(?:(-[^\s]+),\s)?(--[^\s]+)\s*(\<.+?\>)?\s+(.*)';
42
+ my @opts = parse_main_opts('--help all', $regex);
43
+
44
+ if ($shell eq 'fish') {
45
+ print "# curl fish completion\n\n";
46
+ print qq{$_ \n} foreach (@opts);
47
+ } elsif ($shell eq 'zsh') {
48
+ my $opts_str;
49
+
50
+ $opts_str .= qq{ $_ \\\n} foreach (@opts);
51
+ chomp $opts_str;
52
+
53
+ my $tmpl = <<"EOS";
54
+ #compdef curl
55
+
56
+ # curl zsh completion
57
+
58
+ local curcontext="\$curcontext" state state_descr line
59
+ typeset -A opt_args
60
+
61
+ local rc=1
62
+
63
+ _arguments -C -S \\
64
+ $opts_str
65
+ '*:URL:_urls' && rc=0
66
+
67
+ return rc
68
+ EOS
69
+
70
+ print $tmpl;
71
+ } else {
72
+ die("Unsupported shell: $shell");
73
+ }
74
+
75
+ sub parse_main_opts {
76
+ my ($cmd, $regex) = @_;
77
+
78
+ my @list;
79
+ my @lines = call_curl($cmd);
80
+
81
+ foreach my $line (@lines) {
82
+ my ($short, $long, $arg, $desc) = ($line =~ /^$regex/) or next;
83
+
84
+ my $option = '';
85
+
86
+ $arg =~ s/\:/\\\:/g if defined $arg;
87
+
88
+ $desc =~ s/'/'\\''/g if defined $desc;
89
+ $desc =~ s/\[/\\\[/g if defined $desc;
90
+ $desc =~ s/\]/\\\]/g if defined $desc;
91
+ $desc =~ s/\:/\\\:/g if defined $desc;
92
+
93
+ if ($shell eq 'fish') {
94
+ $option .= "complete --command curl";
95
+ $option .= " --short-option '" . strip_dash(trim($short)) . "'"
96
+ if defined $short;
97
+ $option .= " --long-option '" . strip_dash(trim($long)) . "'"
98
+ if defined $long;
99
+ $option .= " --description '" . strip_dash(trim($desc)) . "'"
100
+ if defined $desc;
101
+ } elsif ($shell eq 'zsh') {
102
+ $option .= '{' . trim($short) . ',' if defined $short;
103
+ $option .= trim($long) if defined $long;
104
+ $option .= '}' if defined $short;
105
+ $option .= '\'[' . trim($desc) . ']\'' if defined $desc;
106
+
107
+ if (defined $arg) {
108
+ $option .= ":'$arg'";
109
+ if ($arg =~ /<file ?(name)?>|<path>/) {
110
+ $option .= ':_files';
111
+ } elsif ($arg =~ /<dir>/) {
112
+ $option .= ":'_path_files -/'";
113
+ } elsif ($arg =~ /<url>/i) {
114
+ $option .= ':_urls';
115
+ } elsif ($long =~ /ftp/ && $arg =~ /<method>/) {
116
+ $option .= ":'(multicwd nocwd singlecwd)'";
117
+ } elsif ($arg =~ /<method>/) {
118
+ $option .= ":'(DELETE GET HEAD POST PUT)'";
119
+ }
120
+ }
121
+ }
122
+
123
+ push @list, $option;
124
+ }
125
+
126
+ # Sort longest first, because zsh won't complete an option listed
127
+ # after one that's a prefix of it.
128
+ @list = sort {
129
+ $a =~ /([^=]*)/; my $ma = $1;
130
+ $b =~ /([^=]*)/; my $mb = $1;
131
+
132
+ length($mb) <=> length($ma)
133
+ } @list if $shell eq 'zsh';
134
+
135
+ return @list;
136
+ }
137
+
138
+ sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
139
+ sub strip_dash { my $s = shift; $s =~ s/^-+//g; return $s };
140
+
141
+ sub call_curl {
142
+ my ($cmd) = @_;
143
+ my $output = `"$curl" $cmd`;
144
+ if ($? == -1) {
145
+ die "Could not run curl: $!";
146
+ } elsif ((my $exit_code = $? >> 8) != 0) {
147
+ die "curl returned $exit_code with output:\n$output";
148
+ }
149
+ return split /\n/, $output;
150
+ }
151
+
152
+ __END__
153
+
154
+ =head1 NAME
155
+
156
+ completion.pl - Generates tab-completion files for various shells
157
+
158
+ =head1 SYNOPSIS
159
+
160
+ completion.pl [options...]
161
+
162
+ --curl path to curl executable
163
+ --shell zsh/fish
164
+ --help prints this help
165
+
166
+ =cut
local-test-curl-delta-01/afc-curl/scripts/contributors.sh ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ #
27
+ # This script shows all mentioned contributors from the given <hash>/<tag>
28
+ # until HEAD and adds the contributors already mentioned in the existing
29
+ # RELEASE-NOTES.
30
+ #
31
+
32
+ set -eu
33
+
34
+ start="${1:-}"
35
+
36
+ if test "$start" = "-h"; then
37
+ echo "Usage: $0 <since this tag/hash> [--releasenotes]"
38
+ exit
39
+ fi
40
+ if test -z "$start"; then
41
+ start=$(git tag --sort=taggerdate | grep "^curl-" | tail -1)
42
+ echo "Since $start:"
43
+ fi
44
+
45
+ # We also include curl-www if possible. Override by setting CURLWWW
46
+ CURLWWW="${CURLWWW:-../curl-www}"
47
+
48
+ # filter out Author:, Commit: and *by: lines
49
+ # cut off the email parts
50
+ # split list of names at comma
51
+ # split list of names at " and "
52
+ # cut off spaces first and last on the line
53
+ # filter alternatives through THANKS-filter
54
+ # only count names with a space (ie more than one word)
55
+ # sort all unique names
56
+ # awk them into RELEASE-NOTES format
57
+
58
+ {
59
+ {
60
+ git log --pretty=full --use-mailmap "$start..HEAD"
61
+ if [ -d "$CURLWWW" ]; then
62
+ git -C "$CURLWWW" log --pretty=full --use-mailmap "$start..HEAD"
63
+ fi
64
+ } | \
65
+ grep -Eai '(^Author|^Commit|by):' | \
66
+ cut -d: -f2- | \
67
+ cut '-d(' -f1 | \
68
+ cut '-d<' -f1 | \
69
+ tr , '\012' | \
70
+ sed 's/ at github/ on github/' | \
71
+ sed 's/ and /\n/' | \
72
+ sed -e 's/^ *//' -e 's/ $//g' -e 's/@users.noreply.github.com$/ on github/'
73
+
74
+ grep -a "^ [^ \(]" RELEASE-NOTES| \
75
+ sed 's/, */\n/g'| \
76
+ sed 's/^ *//'
77
+ } | \
78
+ sed -f ./docs/THANKS-filter | \
79
+ sort -fu | \
80
+ awk '
81
+ {
82
+ if(length($0)) {
83
+ num++;
84
+ n = sprintf("%s%s%s,", n, length(n)?" ":"", $0);
85
+ #print n;
86
+ if(length(n) > 77) {
87
+ printf(" %s\n", p);
88
+ n=sprintf("%s,", $0);
89
+ }
90
+ p=n;
91
+ }
92
+ }
93
+
94
+ END {
95
+ pp=substr(p,1,length(p)-1);
96
+ printf(" %s\n", pp);
97
+ printf(" (%d contributors)\n", num);
98
+ }
99
+ '
local-test-curl-delta-01/afc-curl/scripts/contrithanks.sh ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ #
27
+ # This script shows all mentioned contributors from <hash> until HEAD and
28
+ # puts them at the end of the THANKS document on stdout
29
+ #
30
+
31
+ set -eu
32
+
33
+ start="${1:-}"
34
+
35
+ if test "$start" = "-h"; then
36
+ echo "Usage: $0 <since this tag/hash>"
37
+ exit
38
+ fi
39
+ if test -z "$start"; then
40
+ start=$(git tag --sort=taggerdate | grep "^curl-" | tail -1)
41
+ fi
42
+
43
+ # We also include curl-www if possible. Override by setting CURLWWW
44
+ CURLWWW="${CURLWWW:-../curl-www}"
45
+
46
+ cat ./docs/THANKS
47
+
48
+ {
49
+ {
50
+ git log --use-mailmap "$start..HEAD"
51
+ if [ -d "$CURLWWW" ]; then
52
+ git -C "$CURLWWW" log --use-mailmap "$start..HEAD"
53
+ fi
54
+ } | \
55
+ grep -Eai '(^Author|^Commit|by):' | \
56
+ cut -d: -f2- | \
57
+ cut '-d(' -f1 | \
58
+ cut '-d<' -f1 | \
59
+ tr , '\012' | \
60
+ sed 's/ at github/ on github/' | \
61
+ sed 's/ and /\n/' | \
62
+ sed -e 's/^ //' -e 's/ $//g' -e 's/@users.noreply.github.com$/ on github/'
63
+
64
+ # grep out the list of names from RELEASE-NOTES
65
+ # split on ", "
66
+ # remove leading whitespace
67
+ grep -a "^ [^ (]" RELEASE-NOTES| \
68
+ sed 's/, */\n/g'| \
69
+ sed 's/^ *//'
70
+ } | \
71
+ sed -f ./docs/THANKS-filter | \
72
+ sort -fu | \
73
+ grep -aixvFf ./docs/THANKS
local-test-curl-delta-01/afc-curl/scripts/coverage.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ set -eu
27
+
28
+ autoreconf -fi
29
+ mkdir -p cvr
30
+ cd cvr
31
+ ../configure --disable-shared --enable-debug --enable-maintainer-mode --enable-code-coverage
32
+ make -sj
33
+ # the regular test run
34
+ make TFLAGS=-n test-nonflaky
35
+ # make all allocs/file operations fail
36
+ #make TFLAGS=-n test-torture
37
+ # do everything event-based
38
+ make TFLAGS=-n test-event
39
+ lcov -d . -c -o cov.lcov
40
+ genhtml cov.lcov --output-directory coverage --title "curl code coverage"
41
+ tar -cjf curl-coverage.tar.bz2 coverage
local-test-curl-delta-01/afc-curl/scripts/delta ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # Display changes done in the repository from [tag] until now.
27
+ #
28
+ # Uses git for repo data.
29
+ # Uses docs/THANKS and RELEASE-NOTES for current status.
30
+ #
31
+ # In the git clone root, invoke 'scripts/delta [release tag]'
32
+
33
+ $start = $ARGV[0];
34
+
35
+ if($start eq "-h") {
36
+ print "Usage: summary [tag]\n";
37
+ exit;
38
+ }
39
+ elsif($start eq "") {
40
+ $start = `git tag --sort=taggerdate | grep "^curl-" | tail -1`;
41
+ chomp $start;
42
+ }
43
+
44
+ $commits = `git log --oneline $start.. | wc -l`;
45
+ $committers = `git shortlog -s $start.. | wc -l`;
46
+ $bcommitters = `git shortlog -s $start | wc -l`;
47
+
48
+ $acommits = `git log --oneline | wc -l`;
49
+ $acommitters = `git shortlog -s | wc -l`;
50
+
51
+ # delta from now compared to before
52
+ $ncommitters = $acommitters - $bcommitters;
53
+
54
+ # number of contributors right now
55
+ $acontribs = `./scripts/contrithanks.sh | grep -c '^[^ ]'`;
56
+ # number when the tag was set
57
+ $bcontribs = `git show $start:docs/THANKS | grep -c '^[^ ]'`;
58
+ # delta
59
+ $contribs = $acontribs - $bcontribs;
60
+
61
+ # number of setops:
62
+ sub setopts {
63
+ my ($f)=@_;
64
+ open(H, "$f");
65
+ my $opts;
66
+ while(<H>) {
67
+ if(/^ CURLOPT(|DEPRECATED)\(/ && ($_ !~ /OBSOLETE/)) {
68
+ $opts++;
69
+ }
70
+ }
71
+ close(H);
72
+ return $opts;
73
+ }
74
+ $asetopts = setopts("<include/curl/curl.h");
75
+ $bsetopts = setopts("git show $start:include/curl/curl.h|");
76
+ $nsetopts = $asetopts - $bsetopts;
77
+
78
+ # Number of command line options:
79
+ $aoptions=`grep -c '{"....--' src/tool_listhelp.c`;
80
+ $boptions=`git show $start:src/tool_listhelp.c 2>/dev/null | grep -c '{"....--'`;
81
+ $noptions=$aoptions - $boptions;
82
+
83
+ # current local branch
84
+ $branch=`git rev-parse --abbrev-ref HEAD 2>/dev/null`;
85
+ chomp $branch;
86
+ # Number of files in git
87
+ $afiles=`git ls-files | wc -l`;
88
+ $deletes=`git diff-tree --diff-filter=A -r --summary origin/$branch $start 2>/dev/null | wc -l`;
89
+ $creates=`git diff-tree --diff-filter=D -r --summary origin/$branch $start 2>/dev/null| wc -l`;
90
+
91
+ # Time since that tag
92
+ $tagged=`git for-each-ref --format="%(refname:short) | %(taggerdate:unix)" refs/tags/* | grep ^$start | cut "-d|" -f2`; # Unix timestamp
93
+ $taggednice=`git for-each-ref --format="%(refname:short) | %(creatordate)" refs/tags/* | grep ^$start | cut '-d|' -f2`; # human readable time
94
+ chomp $taggednice;
95
+ $now=`date +%s`;
96
+ $elapsed=$now - $tagged; # number of seconds since tag
97
+ $total=$now - `date -d 19980320 +%s`;
98
+
99
+ # Number of public functions in libcurl
100
+ $apublic=`git grep ^CURL_EXTERN -- include/curl | wc -l`;
101
+ $bpublic=`git grep ^CURL_EXTERN $start -- include/curl | wc -l`;
102
+ $public = $apublic - $bpublic;
103
+
104
+ # diffstat
105
+ $diffstat=`git diff --stat $start.. | tail -1`;
106
+ if($diffstat =~ /^ *(\d+) files changed, (\d+) insertions\(\+\), (\d+)/) {
107
+ ($fileschanged, $insertions, $deletions)=($1, $2, $3);
108
+ }
109
+
110
+ # Changes/bug-fixes currently logged
111
+ open(F, "<RELEASE-NOTES");
112
+ while(<F>) {
113
+ if($_ =~ /following changes:/) {
114
+ $mode=1;
115
+ }
116
+ elsif($_ =~ /following bugfixes:/) {
117
+ $mode=2;
118
+ }
119
+ elsif($_ =~ /known bugs:/) {
120
+ $mode=3;
121
+ }
122
+ elsif($_ =~ /like these:/) {
123
+ $mode=4;
124
+ }
125
+ if($_ =~ /^ o /) {
126
+ if($mode == 1) {
127
+ $numchanges++;
128
+ }
129
+ elsif($mode == 2) {
130
+ $numbugfixes++;
131
+ }
132
+ }
133
+ if(($mode == 4) && ($_ =~ /^ \((\d+) contributors/)) {
134
+ $numcontributors = $1;
135
+ }
136
+ }
137
+ close(F);
138
+
139
+ ########################################################################
140
+ # Produce the summary
141
+
142
+ print "== Since $start $taggednice ==\n";
143
+ my $days = $elapsed / 3600 / 24;
144
+ printf "Elapsed time: %.1f days (total %d)\n",
145
+ $days, $total / 3600 / 24;
146
+ printf "Commits: %d (total %d)\n",
147
+ $commits, $acommits;
148
+ printf "Commit authors: %d, %d new (total %d)\n",
149
+ $committers, $ncommitters, $acommitters;
150
+ printf "Contributors: %d, %d new (total %d)\n",
151
+ $numcontributors, $contribs, $acontribs;
152
+ printf "New public functions: %d (total %d)\n",
153
+ $public, $apublic;
154
+ printf "New curl_easy_setopt() options: %d (total %d)\n",
155
+ $nsetopts, $asetopts;
156
+ printf "New command line options: %d (total %d)\n",
157
+ $noptions, $aoptions;
158
+ printf "Changes logged: %d\n", $numchanges;
159
+ printf "Bugfixes logged: %d (%.2f per day)\n",
160
+ $numbugfixes, $numbugfixes / $days;
161
+ printf "Added files: %d (total %d)\n",
162
+ $creates, $afiles;
163
+ printf "Deleted files: %d (delta: %d)\n", $deletes,
164
+ $creates - $deletes;
165
+ print "Diffstat:$diffstat" if(!$fileschanged);
166
+ printf "Files changed: %d (%.2f%%)\n", $fileschanged, $fileschanged*100/$afiles;
167
+ printf "Lines inserted: %d\n", $insertions;
168
+ printf "Lines deleted: %d (delta: %d)\n", $deletions,
169
+ $insertions - $deletions;
local-test-curl-delta-01/afc-curl/scripts/dmaketgz ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ # docker-maketgz
3
+ #
4
+ #***************************************************************************
5
+ # _ _ ____ _
6
+ # Project ___| | | | _ \| |
7
+ # / __| | | | |_) | |
8
+ # | (__| |_| | _ <| |___
9
+ # \___|\___/|_| \_\_____|
10
+ #
11
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
12
+ #
13
+ # This software is licensed as described in the file COPYING, which
14
+ # you should have received as part of this distribution. The terms
15
+ # are also available at https://curl.se/docs/copyright.html.
16
+ #
17
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
18
+ # copies of the Software, and permit persons to whom the Software is
19
+ # furnished to do so, under the terms of the COPYING file.
20
+ #
21
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22
+ # KIND, either express or implied.
23
+ #
24
+ # SPDX-License-Identifier: curl
25
+ #
26
+ ###########################################################################
27
+
28
+ set -eu
29
+
30
+ version="${1:-}"
31
+
32
+ if [ -z "$version" ]; then
33
+ echo "Specify a version number!"
34
+ exit
35
+ fi
36
+
37
+ timestamp="${2:-$(date -u +%s)}"
38
+
39
+ if test -f Makefile; then
40
+ make distclean
41
+ fi
42
+ docker build \
43
+ --no-cache \
44
+ --build-arg SOURCE_DATE_EPOCH="$timestamp" \
45
+ --build-arg UID="$(id -u)" \
46
+ --build-arg GID="$(id -g)" \
47
+ -t curl/curl .
48
+
49
+ docker run --rm -u "$(id -u):$(id -g)" \
50
+ -v "$(pwd):/usr/src" -w /usr/src curl/curl sh -c "
51
+ set -e
52
+ autoreconf -fi
53
+ ./configure --without-ssl --without-libpsl
54
+ make -sj8
55
+ ./scripts/maketgz $version"
local-test-curl-delta-01/afc-curl/scripts/firefox-db2pem.sh ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ # ***************************************************************************
3
+ # * _ _ ____ _
4
+ # * Project ___| | | | _ \| |
5
+ # * / __| | | | |_) | |
6
+ # * | (__| |_| | _ <| |___
7
+ # * \___|\___/|_| \_\_____|
8
+ # *
9
+ # * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ # *
11
+ # * This software is licensed as described in the file COPYING, which
12
+ # * you should have received as part of this distribution. The terms
13
+ # * are also available at https://curl.se/docs/copyright.html.
14
+ # *
15
+ # * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # * copies of the Software, and permit persons to whom the Software is
17
+ # * furnished to do so, under the terms of the COPYING file.
18
+ # *
19
+ # * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # * KIND, either express or implied.
21
+ # *
22
+ # * SPDX-License-Identifier: curl
23
+ # *
24
+ # ***************************************************************************
25
+ # This shell script creates a fresh ca-bundle.crt file for use with libcurl.
26
+ # It extracts all ca certs it finds in the local Firefox database and converts
27
+ # them all into PEM format.
28
+ #
29
+ # It uses the "certutil" command line tool from the NSS project to perform the
30
+ # conversion. On Debian it comes in the "libnss3-tools" package.
31
+ #
32
+
33
+ set -eu
34
+
35
+ db=$(ls -1d "$HOME"/.mozilla/firefox/*default*)
36
+ out="${1:-}"
37
+
38
+ if test -z "$out"; then
39
+ out="ca-bundle.crt" # use a sensible default
40
+ fi
41
+
42
+ currentdate=$(date)
43
+
44
+ cat > "$out" <<EOF
45
+ ##
46
+ ## Bundle of CA Root Certificates
47
+ ##
48
+ ## Converted at: ${currentdate}
49
+ ## These were converted from the local Firefox directory by the db2pem script.
50
+ ##
51
+ EOF
52
+
53
+
54
+ certutil -L -h 'Builtin Object Token' -d "$db" | \
55
+ grep ' *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$' | \
56
+ sed -e 's/ *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$//' -e 's/\(.*\)/"\1"/' | \
57
+ sort | \
58
+ while read -r nickname; \
59
+ do echo "$nickname" | sed -e "s/Builtin Object Token://g"; \
60
+ eval certutil -d "$db" -L -n "$nickname" -a ; \
61
+ done >> "$out"
local-test-curl-delta-01/afc-curl/scripts/installcheck.sh ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ set -eu
27
+
28
+ PREFIX="${1:-}"
29
+
30
+ # Run this script in the root of the git clone. Point out the install prefix
31
+ # where 'make install' has already installed curl.
32
+
33
+ if test -z "$PREFIX"; then
34
+ echo "scripts/installcheck.sh [PREFIX]"
35
+ exit
36
+ fi
37
+
38
+ diff -u <(find docs/libcurl/ -name "*.3" -printf "%f\n" | grep -v template | sort) <(find "$PREFIX/share/man/" -name "*.3" -printf "%f\n" | sort)
39
+
40
+ if test "$?" -ne "0"; then
41
+ echo "ERROR: installed libcurl docs mismatch"
42
+ exit 2
43
+ fi
44
+
45
+ diff -u <(find include/ -name "*.h" -printf "%f\n" | sort) <(find "$PREFIX/include/" -name "*.h" -printf "%f\n" | sort)
46
+
47
+ if test "$?" -ne "0"; then
48
+ echo "ERROR: installed include files mismatch"
49
+ exit 1
50
+ fi
51
+
52
+ echo "installcheck: installed libcurl docs and include files look good"
local-test-curl-delta-01/afc-curl/scripts/maketgz ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ # Script to build release-archives with. Note that this requires a checkout
3
+ # from git and you should first run autoreconf -fi and build curl once.
4
+ #
5
+ #***************************************************************************
6
+ # _ _ ____ _
7
+ # Project ___| | | | _ \| |
8
+ # / __| | | | |_) | |
9
+ # | (__| |_| | _ <| |___
10
+ # \___|\___/|_| \_\_____|
11
+ #
12
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
13
+ #
14
+ # This software is licensed as described in the file COPYING, which
15
+ # you should have received as part of this distribution. The terms
16
+ # are also available at https://curl.se/docs/copyright.html.
17
+ #
18
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
19
+ # copies of the Software, and permit persons to whom the Software is
20
+ # furnished to do so, under the terms of the COPYING file.
21
+ #
22
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23
+ # KIND, either express or implied.
24
+ #
25
+ # SPDX-License-Identifier: curl
26
+ #
27
+ ###########################################################################
28
+
29
+ set -eu
30
+
31
+ export LC_ALL=C
32
+ export TZ=UTC
33
+
34
+ version="${1:-}"
35
+ cmd="${2:-}"
36
+
37
+ if [ -z "$version" ]; then
38
+ echo "Specify a version number!"
39
+ exit
40
+ fi
41
+
42
+ echo "$cmd"
43
+
44
+ only=""
45
+ if [ "only" = "$cmd" ]; then
46
+ echo "Setup version number only!"
47
+ only=1
48
+ fi
49
+
50
+ commit=""
51
+ if [ "commit" = "$cmd" ]; then
52
+ commit=1
53
+ fi
54
+
55
+ libversion="$version"
56
+
57
+ # we make curl the same version as libcurl
58
+ curlversion="$libversion"
59
+
60
+ major=$(echo "$libversion" | cut -d. -f1 | sed -e "s/[^0-9]//g")
61
+ minor=$(echo "$libversion" | cut -d. -f2 | sed -e "s/[^0-9]//g")
62
+ patch=$(echo "$libversion" | cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g")
63
+
64
+ if test -z "$patch"; then
65
+ echo "invalid version number? needs to be z.y.z"
66
+ exit
67
+ fi
68
+
69
+ #
70
+ # As a precaution, remove all *.dist files that may be lying around, to reduce
71
+ # the risk of old leftovers getting shipped. The root 'Makefile.dist' is the
72
+ # exception.
73
+ echo "removing all old *.dist files"
74
+ find . -name "*.dist" -a ! -name Makefile.dist -exec rm {} \;
75
+
76
+ numeric="$(printf "%02x%02x%02x\n" "$major" "$minor" "$patch")"
77
+
78
+ HEADER=include/curl/curlver.h
79
+ CHEADER=src/tool_version.h
80
+
81
+ if test -z "$only"; then
82
+ ext=".dist"
83
+ # when not setting up version numbers locally
84
+ for a in $HEADER $CHEADER; do
85
+ cp "$a" "$a$ext"
86
+ done
87
+ HEADER="$HEADER$ext"
88
+ CHEADER="$CHEADER$ext"
89
+ fi
90
+
91
+ # requires a date command that knows + for format and -d for date input
92
+ timestamp=${SOURCE_DATE_EPOCH:-$(date +"%s")}
93
+ datestamp=$(date -d "@$timestamp" +"%F")
94
+ filestamp=$(date -d "@$timestamp" +"%Y%m%d%H%M.%S")
95
+
96
+ # Replace version number in header file:
97
+ sed -i \
98
+ -e "s/^#define LIBCURL_VERSION .*/#define LIBCURL_VERSION \"$libversion\"/g" \
99
+ -e "s/^#define LIBCURL_VERSION_NUM .*/#define LIBCURL_VERSION_NUM 0x$numeric/g" \
100
+ -e "s/^#define LIBCURL_VERSION_MAJOR .*/#define LIBCURL_VERSION_MAJOR $major/g" \
101
+ -e "s/^#define LIBCURL_VERSION_MINOR .*/#define LIBCURL_VERSION_MINOR $minor/g" \
102
+ -e "s/^#define LIBCURL_VERSION_PATCH .*/#define LIBCURL_VERSION_PATCH $patch/g" \
103
+ -e "s/^#define LIBCURL_TIMESTAMP .*/#define LIBCURL_TIMESTAMP \"$datestamp\"/g" \
104
+ "$HEADER"
105
+
106
+ # Replace version number in header file:
107
+ sed -i "s/#define CURL_VERSION .*/#define CURL_VERSION \"$curlversion\"/g" "$CHEADER"
108
+
109
+ if test -n "$only"; then
110
+ # done!
111
+ exit
112
+ fi
113
+
114
+ echo "curl version $curlversion"
115
+ echo "libcurl version $libversion"
116
+ echo "libcurl numerical $numeric"
117
+ echo "datestamp $datestamp"
118
+
119
+ findprog() {
120
+ file="$1"
121
+ for part in $(echo "$PATH" | tr ':' ' '); do
122
+ path="$part/$file"
123
+ if [ -x "$path" ]; then
124
+ # there it is!
125
+ return 1
126
+ fi
127
+ done
128
+
129
+ # no such executable
130
+ return 0
131
+ }
132
+
133
+ ############################################################################
134
+ #
135
+ # Enforce a rerun of configure (updates the VERSION)
136
+ #
137
+
138
+ echo "Re-running config.status"
139
+ ./config.status --recheck >/dev/null
140
+
141
+ echo "Recreate the built-in manual (with correct version)"
142
+ export CURL_MAKETGZ_VERSION="$version"
143
+ rm -f docs/cmdline-opts/curl.txt
144
+ make -C src
145
+
146
+ ############################################################################
147
+ #
148
+ # automake is needed to run to make a non-GNU Makefile.in if Makefile.am has
149
+ # been modified.
150
+ #
151
+
152
+ if { findprog automake >/dev/null 2>/dev/null; } then
153
+ echo "- Could not find or run automake, I hope you know what you are doing!"
154
+ else
155
+ echo "Runs automake --include-deps"
156
+ automake --include-deps Makefile >/dev/null
157
+ fi
158
+
159
+ if test -n "$commit"; then
160
+ echo "produce docs/tarball-commit.txt"
161
+ git rev-parse HEAD >docs/tarball-commit.txt.dist
162
+ fi
163
+
164
+ echo "produce RELEASE-TOOLS.md"
165
+ ./scripts/release-tools.sh "$timestamp" "$version" "$commit" > docs/RELEASE-TOOLS.md.dist
166
+
167
+ ############################################################################
168
+ #
169
+ # Now run make dist to generate a tar.gz archive
170
+ #
171
+
172
+ echo "make dist"
173
+ targz="curl-$version.tar.gz"
174
+ make -sj dist "VERSION=$version"
175
+ res=$?
176
+
177
+ if test "$res" != 0; then
178
+ echo "make dist failed"
179
+ exit 2
180
+ fi
181
+
182
+ retar() {
183
+ tempdir=$1
184
+ rm -rf "$tempdir"
185
+ mkdir "$tempdir"
186
+ cd "$tempdir"
187
+ gzip -dc "../$targz" | tar -xf -
188
+ find curl-* -depth -exec touch -c -t "$filestamp" '{}' +
189
+ tar --create --format=ustar --owner=0 --group=0 --numeric-owner --sort=name curl-* | gzip --best --no-name > out.tar.gz
190
+ mv out.tar.gz ../
191
+ cd ..
192
+ rm -rf "$tempdir"
193
+ }
194
+
195
+ retar ".tarbuild"
196
+ echo "replace $targz with out.tar.gz"
197
+ mv out.tar.gz "$targz"
198
+
199
+ ############################################################################
200
+ #
201
+ # Now make a bz2 archive from the tar.gz original
202
+ #
203
+
204
+ bzip2="curl-$version.tar.bz2"
205
+ echo "Generating $bzip2"
206
+ gzip -dc "$targz" | bzip2 --best > "$bzip2"
207
+
208
+ ############################################################################
209
+ #
210
+ # Now make an xz archive from the tar.gz original
211
+ #
212
+
213
+ xz="curl-$version.tar.xz"
214
+ echo "Generating $xz"
215
+ gzip -dc "$targz" | xz -6e - > "$xz"
216
+
217
+ ############################################################################
218
+ #
219
+ # Now make a zip archive from the tar.gz original
220
+ #
221
+ makezip() {
222
+ rm -rf "$tempdir"
223
+ mkdir "$tempdir"
224
+ cd "$tempdir"
225
+ gzip -dc "../$targz" | tar -xf -
226
+ find . | sort | zip -9 -X "$zip" -@ >/dev/null
227
+ mv "$zip" ../
228
+ cd ..
229
+ rm -rf "$tempdir"
230
+ }
231
+
232
+ zip="curl-$version.zip"
233
+ echo "Generating $zip"
234
+ tempdir=".builddir"
235
+ makezip
236
+
237
+ # Set deterministic timestamp
238
+ touch -c -t "$filestamp" "$targz" "$bzip2" "$xz" "$zip"
239
+
240
+ echo "------------------"
241
+ echo "maketgz report:"
242
+ echo ""
243
+ ls -l "$targz" "$bzip2" "$xz" "$zip"
244
+ sha256sum "$targz" "$bzip2" "$xz" "$zip"
245
+
246
+ echo "Run this:"
247
+ echo "gpg -b -a '$targz' && gpg -b -a '$bzip2' && gpg -b -a '$xz' && gpg -b -a '$zip'"
local-test-curl-delta-01/afc-curl/scripts/managen ADDED
@@ -0,0 +1,1279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ =begin comment
27
+
28
+ This script generates the manpage.
29
+
30
+ Example: managen <command> [files] > curl.1
31
+
32
+ Dev notes:
33
+
34
+ We open *input* files in :crlf translation (a no-op on many platforms) in
35
+ case we have CRLF line endings in Windows but a perl that defaults to LF.
36
+ Unfortunately it seems some perls like msysgit cannot handle a global input-only
37
+ :crlf so it has to be specified on each file open for text input.
38
+
39
+ =end comment
40
+ =cut
41
+
42
+ my %optshort;
43
+ my %optlong;
44
+ my %helplong;
45
+ my %arglong;
46
+ my %redirlong;
47
+ my %protolong;
48
+ my %catlong;
49
+
50
+ use POSIX qw(strftime);
51
+ my @ts;
52
+ if (defined($ENV{SOURCE_DATE_EPOCH})) {
53
+ @ts = gmtime($ENV{SOURCE_DATE_EPOCH});
54
+ } else {
55
+ @ts = localtime;
56
+ }
57
+ my $date = strftime "%Y-%m-%d", @ts;
58
+ my $year = strftime "%Y", @ts;
59
+ my $version = "unknown";
60
+ my $globals;
61
+ my $error = 0;
62
+ my $indent = 4;
63
+
64
+ # get the long name version, return the manpage string
65
+ sub manpageify {
66
+ my ($k)=@_;
67
+ my $l;
68
+ my $trail;
69
+ # the matching pattern might include a trailing dot that cannot be part of
70
+ # the option name
71
+ if($k =~ s/\.$//) {
72
+ # cut off trailing dot
73
+ $trail = ".";
74
+ }
75
+ my $klong = $k;
76
+ # quote "bare" minuses in the long name
77
+ $klong =~ s/-/\\-/g;
78
+ if($optlong{$k}) {
79
+ # both short + long
80
+ $l = "\\fI-".$optlong{$k}.", \\-\\-$klong\\fP$trail";
81
+ }
82
+ else {
83
+ # only long
84
+ $l = "\\fI\\-\\-$klong\\fP$trail";
85
+ }
86
+ return $l;
87
+ }
88
+
89
+
90
+ my $colwidth=79; # max number of columns
91
+
92
+ sub prefixline {
93
+ my ($num) = @_;
94
+ print "\t" x ($num/8);
95
+ print ' ' x ($num%8);
96
+ }
97
+
98
+ sub justline {
99
+ my ($lvl, @line) = @_;
100
+ my $w = -1;
101
+ my $spaces = -1;
102
+ my $width = $colwidth - ($lvl * $indent);
103
+ for(@line) {
104
+ $w += length($_);
105
+ $w++;
106
+ $spaces++;
107
+ }
108
+ my $inject = $width - $w;
109
+ my $ratio = 0; # stay at zero if no spaces at all
110
+ if($spaces) {
111
+ $ratio = $inject / $spaces;
112
+ }
113
+ my $spare = 0;
114
+ prefixline($lvl * $indent);
115
+ my $prev;
116
+ for(@line) {
117
+ while($spare >= 0.90) {
118
+ print " ";
119
+ $spare--;
120
+ }
121
+ printf "%s%s", $prev?" ":"", $_;
122
+ $prev = 1;
123
+ $spare += $ratio;
124
+ }
125
+ print "\n";
126
+ }
127
+
128
+ sub lastline {
129
+ my ($lvl, @line) = @_;
130
+ $line[0] =~ s/^( +)//;
131
+ prefixline($lvl * $indent + length($1));
132
+ my $prev = 0;
133
+ for(@line) {
134
+ printf "%s%s", $prev?" ":"", $_;
135
+ $prev = 1;
136
+ }
137
+ print "\n";
138
+ }
139
+
140
+ sub outputpara {
141
+ my ($lvl, $f) = @_;
142
+ $f =~ s/\n/ /g;
143
+
144
+ my $w = 0;
145
+ my @words = split(/ */, $f);
146
+ my $width = $colwidth - ($lvl * $indent);
147
+
148
+ my @line;
149
+ for my $e (@words) {
150
+ my $l = length($e);
151
+ my $spaces = scalar(@line);
152
+ if(($w + $l + $spaces) >= $width) {
153
+ justline($lvl, @line);
154
+ undef @line;
155
+ $w = 0;
156
+ }
157
+
158
+ push @line, $e;
159
+ $w += $l; # new width
160
+ }
161
+ if($w) {
162
+ lastline($lvl, @line);
163
+ print "\n";
164
+ }
165
+ }
166
+
167
+ sub printdesc {
168
+ my ($manpage, $baselvl, @desc) = @_;
169
+
170
+ if($manpage) {
171
+ for my $d (@desc) {
172
+ print $d;
173
+ }
174
+ }
175
+ else {
176
+ my $p = -1;
177
+ my $para;
178
+ for my $l (@desc) {
179
+ my $lvl;
180
+ if($l !~ /^[\n\r]+/) {
181
+ # get the indent level off the string
182
+ $l =~ s/^\[([0-9q]*)\]//;
183
+ $lvl = $1;
184
+ }
185
+ if(($p =~ /q/) && ($lvl !~ /q/)) {
186
+ # the previous was quoted, this is not
187
+ print "\n";
188
+ }
189
+ if($lvl != $p) {
190
+ outputpara($baselvl + $p, $para);
191
+ $para = "";
192
+ }
193
+ if($lvl =~ /q/) {
194
+ # quoted, do not right-justify
195
+ chomp $l;
196
+ lastline($baselvl + $lvl + 1, $l);
197
+ my $w = ($baselvl + $lvl + 1) * $indent + length($l);
198
+ if ($w > $colwidth) {
199
+ print STDERR "ERROR: $w columns is too long\n";
200
+ print STDERR "$l\n";
201
+ $error++;
202
+ }
203
+ }
204
+ else {
205
+ $para .= $l;
206
+ }
207
+
208
+ $p = $lvl;
209
+ }
210
+ outputpara($baselvl + $p, $para);
211
+ }
212
+ }
213
+
214
+ sub seealso {
215
+ my($standalone, $data)=@_;
216
+ if($standalone) {
217
+ return sprintf
218
+ ".SH \"SEE ALSO\"\n$data\n";
219
+ }
220
+ else {
221
+ return "See also $data. ";
222
+ }
223
+ }
224
+
225
+ sub overrides {
226
+ my ($standalone, $data)=@_;
227
+ if($standalone) {
228
+ return ".SH \"OVERRIDES\"\n$data\n";
229
+ }
230
+ else {
231
+ return $data;
232
+ }
233
+ }
234
+
235
+ sub protocols {
236
+ my ($manpage, $standalone, $data)=@_;
237
+ if($standalone) {
238
+ return ".SH \"PROTOCOLS\"\n$data\n";
239
+ }
240
+ else {
241
+ return "($data) " if($manpage);
242
+ return "[1]($data) " if(!$manpage);
243
+ }
244
+ }
245
+
246
+ sub too_old {
247
+ my ($version)=@_;
248
+ my $a = 999999;
249
+ if($version =~ /^(\d+)\.(\d+)\.(\d+)/) {
250
+ $a = $1 * 1000 + $2 * 10 + $3;
251
+ }
252
+ elsif($version =~ /^(\d+)\.(\d+)/) {
253
+ $a = $1 * 1000 + $2 * 10;
254
+ }
255
+ if($a < 7600) {
256
+ # we consider everything before 7.60.0 to be too old to mention
257
+ # specific changes for
258
+ return 1;
259
+ }
260
+ return 0;
261
+ }
262
+
263
+ sub added {
264
+ my ($standalone, $data)=@_;
265
+ if(too_old($data)) {
266
+ # do not mention ancient additions
267
+ return "";
268
+ }
269
+ if($standalone) {
270
+ return ".SH \"ADDED\"\nAdded in curl version $data\n";
271
+ }
272
+ else {
273
+ return "Added in $data. ";
274
+ }
275
+ }
276
+
277
+ sub render {
278
+ my ($manpage, $fh, $f, $line) = @_;
279
+ my @desc;
280
+ my $tablemode = 0;
281
+ my $header = 0;
282
+ # if $top is TRUE, it means a top-level page and not a command line option
283
+ my $top = ($line == 1);
284
+ my $quote;
285
+ my $level;
286
+ my $finalblank;
287
+ $start = 0;
288
+
289
+ while(<$fh>) {
290
+ my $d = $_;
291
+ $line++;
292
+ $finalblank = ($d eq "\n");
293
+ if($d =~ /^\.(SH|BR|IP|B)/) {
294
+ print STDERR "$f:$line:1:ERROR: nroff instruction in input: \".$1\"\n";
295
+ return 4;
296
+ }
297
+ if(/^ *<!--/) {
298
+ # skip comments
299
+ next;
300
+ }
301
+ if((!$start) && ($_ =~ /^[\r\n]*\z/)) {
302
+ # skip leading blank lines
303
+ next;
304
+ }
305
+ $start = 1;
306
+ if(/^# (.*)/) {
307
+ $header = 1;
308
+ if($top != 1) {
309
+ # ignored for command line options
310
+ $blankline++;
311
+ next;
312
+ }
313
+ push @desc, ".SH $1\n" if($manpage);
314
+ push @desc, "[0]$1\n" if(!$manpage);
315
+ next;
316
+ }
317
+ elsif(/^###/) {
318
+ print STDERR "$f:$line:1:ERROR: ### header is not supported\n";
319
+ exit 3;
320
+ }
321
+ elsif(/^## (.*)/) {
322
+ my $word = $1;
323
+ # if there are enclosing quotes, remove them first
324
+ $word =~ s/[\"\'](.*)[\"\']\z/$1/;
325
+
326
+ # remove backticks from headers
327
+ $word =~ s/\`//g;
328
+
329
+ # if there is a space, it needs quotes for manpage
330
+ if(($word =~ / /) && $manpage) {
331
+ $word = "\"$word\"";
332
+ }
333
+ $level = 1;
334
+ if($top == 1) {
335
+ push @desc, ".IP $word\n" if($manpage);
336
+ push @desc, "\n" if(!$manpage);
337
+ push @desc, "[1]$word\n" if(!$manpage);
338
+ }
339
+ else {
340
+ if(!$tablemode) {
341
+ push @desc, ".RS\n" if($manpage);
342
+ $tablemode = 1;
343
+ }
344
+ push @desc, ".IP $word\n" if($manpage);
345
+ push @desc, "\n" if(!$manpage);
346
+ push @desc, "[1]$word\n" if(!$manpage);
347
+ }
348
+ $header = 1;
349
+ next;
350
+ }
351
+ elsif(/^##/) {
352
+ if($top == 1) {
353
+ print STDERR "$f:$line:1:ERROR: ## empty header top-level mode\n";
354
+ exit 3;
355
+ }
356
+ if($tablemode) {
357
+ # end of table
358
+ push @desc, ".RE\n.IP\n" if($manpage);
359
+ $tablemode = 0;
360
+ }
361
+ $header = 1;
362
+ next;
363
+ }
364
+ elsif(/^\.(IP|RS|RE)/) {
365
+ my ($cmd) = ($1);
366
+ print STDERR "$f:$line:1:ERROR: $cmd detected, use ##-style\n";
367
+ return 3;
368
+ }
369
+ elsif(/^[ \t]*\n/) {
370
+ # count and ignore blank lines
371
+ $blankline++;
372
+ next;
373
+ }
374
+ elsif($d =~ /^ (.*)/) {
375
+ my $word = $1;
376
+ if(!$quote && $manpage) {
377
+ push @desc, "\n" if($blankline);
378
+ push @desc, ".nf\n";
379
+ $blankline = 0;
380
+ }
381
+ $quote = 1;
382
+ $d = "$word\n";
383
+ }
384
+ elsif($quote && ($d !~ /^ (.*)/)) {
385
+ # end of quote
386
+ push @desc, ".fi\n" if($manpage);
387
+ $quote = 0;
388
+ }
389
+
390
+ $d =~ s/`%DATE`/$date/g;
391
+ $d =~ s/`%VERSION`/$version/g;
392
+ $d =~ s/`%GLOBALS`/$globals/g;
393
+
394
+ # convert backticks to double quotes
395
+ $d =~ s/\`/\"/g;
396
+
397
+ if($d =~ /\(added in(.*)/i) {
398
+ if(length($1) < 2) {
399
+ print STDERR "$f:$line:1:ERROR: broken up added-in line:\n";
400
+ print STDERR "$f:$line:1:ERROR: $d";
401
+ return 3;
402
+ }
403
+ }
404
+ again:
405
+ if($d =~ /\(Added in ([0-9.]+)\)/i) {
406
+ my $ver = $1;
407
+ if(too_old($ver)) {
408
+ $d =~ s/ *\(Added in $ver\)//gi;
409
+ goto again;
410
+ }
411
+ }
412
+
413
+ if(!$quote) {
414
+ if($d =~ /^(.*) /) {
415
+ printf STDERR "$f:$line:%d:ERROR: 2 spaces detected\n",
416
+ length($1);
417
+ return 3;
418
+ }
419
+ elsif($d =~ /[^\\][\<\>]/) {
420
+ print STDERR "$f:$line:1:WARN: un-escaped < or > used\n";
421
+ return 3;
422
+ }
423
+ }
424
+ # convert backslash-'<' or '> to just the second character
425
+ $d =~ s/\\([><])/$1/g;
426
+ # convert single backslash to double-backslash
427
+ $d =~ s/\\/\\\\/g if($manpage);
428
+
429
+
430
+ if($manpage) {
431
+ if(!$quote && $d =~ /--/) {
432
+ $d =~ s/--([a-z0-9.-]+)/manpageify($1)/ge;
433
+ }
434
+
435
+ # quote minuses in the output
436
+ $d =~ s/([^\\])-/$1\\-/g;
437
+ # replace single quotes
438
+ $d =~ s/\'/\\(aq/g;
439
+ # handle double quotes or periods first on the line
440
+ $d =~ s/^([\.\"])/\\&$1/;
441
+ # **bold**
442
+ $d =~ s/\*\*(\S.*?)\*\*/\\fB$1\\fP/g;
443
+ # *italics*
444
+ $d =~ s/\*(\S.*?)\*/\\fI$1\\fP/g;
445
+ }
446
+ else {
447
+ # **bold**
448
+ $d =~ s/\*\*(\S.*?)\*\*/$1/g;
449
+ # *italics*
450
+ $d =~ s/\*(\S.*?)\*/$1/g;
451
+ }
452
+ # trim trailing spaces
453
+ $d =~ s/[ \t]+\z//;
454
+ push @desc, "\n" if($blankline && !$header);
455
+ $blankline = 0;
456
+ push @desc, $d if($manpage);
457
+ my $qstr = $quote ? "q": "";
458
+ push @desc, "[".(1 + $level)."$qstr]$d" if(!$manpage);
459
+ $header = 0;
460
+
461
+ }
462
+ if($finalblank) {
463
+ print STDERR "$f:$line:1:ERROR: trailing blank line\n";
464
+ exit 3;
465
+ }
466
+ if($quote) {
467
+ # don't leave the quote "hanging"
468
+ push @desc, ".fi\n" if($manpage);
469
+ }
470
+ if($tablemode) {
471
+ # end of table
472
+ push @desc, ".RE\n.IP\n" if($manpage);
473
+ }
474
+ return @desc;
475
+ }
476
+
477
+ sub maybespace {
478
+ my ($string) = @_;
479
+
480
+ if(($string =~ /(.* )(.*)/) &&
481
+ (length($2) <= 20)) {
482
+ return $1;
483
+ }
484
+ if(($string =~ /(.*:)(.*)/) &&
485
+ (length($2) <= 20)) {
486
+ return $1;
487
+ }
488
+ return $string;
489
+ }
490
+
491
+ sub single {
492
+ my ($dir, $manpage, $f, $standalone)=@_;
493
+ my $fh;
494
+ open($fh, "<:crlf", "$dir/$f") ||
495
+ die "could not find $dir/$f";
496
+ my $short;
497
+ my $long;
498
+ my $tags;
499
+ my $added;
500
+ my $protocols;
501
+ my $arg;
502
+ my $mutexed;
503
+ my $requires;
504
+ my $category;
505
+ my @seealso;
506
+ my $copyright;
507
+ my $spdx;
508
+ my @examples; # there can be more than one
509
+ my $magic; # cmdline special option
510
+ my $line;
511
+ my $dline;
512
+ my $multi;
513
+ my $scope;
514
+ my $experimental;
515
+ my $start;
516
+ my $list; # identifies the list, 1 example, 2 see-also
517
+ while(<$fh>) {
518
+ $line++;
519
+ if(/^ *<!--/) {
520
+ next;
521
+ }
522
+ if(!$start) {
523
+ if(/^---/) {
524
+ $start = 1;
525
+ }
526
+ next;
527
+ }
528
+ if(/^Short: *(.)/i) {
529
+ $short=$1;
530
+ }
531
+ elsif(/^Long: *(.*)/i) {
532
+ $long=$1;
533
+ }
534
+ elsif(/^Added: *(.*)/i) {
535
+ $added=$1;
536
+ }
537
+ elsif(/^Tags: *(.*)/i) {
538
+ $tags=$1;
539
+ }
540
+ elsif(/^Arg: *(.*)/i) {
541
+ $arg=$1;
542
+ }
543
+ elsif(/^Magic: *(.*)/i) {
544
+ $magic=$1;
545
+ }
546
+ elsif(/^Mutexed: *(.*)/i) {
547
+ $mutexed=$1;
548
+ }
549
+ elsif(/^Protocols: *(.*)/i) {
550
+ $protocols=$1;
551
+ }
552
+ elsif(/^See-also: +(.+)/i) {
553
+ if($seealso) {
554
+ print STDERR "ERROR: duplicated See-also in $f\n";
555
+ return 1;
556
+ }
557
+ push @seealso, $1;
558
+ }
559
+ elsif(/^See-also:/i) {
560
+ $list=2;
561
+ }
562
+ elsif(/^ *- (.*)/i && ($list == 2)) {
563
+ push @seealso, $1;
564
+ }
565
+ elsif(/^Requires: *(.*)/i) {
566
+ $requires=$1;
567
+ }
568
+ elsif(/^Category: *(.*)/i) {
569
+ $category=$1;
570
+ }
571
+ elsif(/^Example: +(.+)/i) {
572
+ push @examples, $1;
573
+ }
574
+ elsif(/^Example:/i) {
575
+ # '1' is the example list
576
+ $list = 1;
577
+ }
578
+ elsif(/^ *- (.*)/i && ($list == 1)) {
579
+ push @examples, $1;
580
+ }
581
+ elsif(/^Multi: *(.*)/i) {
582
+ $multi=$1;
583
+ }
584
+ elsif(/^Scope: *(.*)/i) {
585
+ $scope=$1;
586
+ }
587
+ elsif(/^Experimental: yes/i) {
588
+ $experimental=1;
589
+ }
590
+ elsif(/^C: (.*)/i) {
591
+ $copyright=$1;
592
+ }
593
+ elsif(/^SPDX-License-Identifier: (.*)/i) {
594
+ $spdx=$1;
595
+ }
596
+ elsif(/^Help: *(.*)/i) {
597
+ ;
598
+ }
599
+ elsif(/^---/) {
600
+ $start++;
601
+ if(!$long) {
602
+ print STDERR "ERROR: no 'Long:' in $f\n";
603
+ return 1;
604
+ }
605
+ if(!$category) {
606
+ print STDERR "ERROR: no 'Category:' in $f\n";
607
+ return 2;
608
+ }
609
+ if(!$examples[0]) {
610
+ print STDERR "$f:$line:1:ERROR: no 'Example:' present\n";
611
+ return 2;
612
+ }
613
+ if(!$added) {
614
+ print STDERR "$f:$line:1:ERROR: no 'Added:' version present\n";
615
+ return 2;
616
+ }
617
+ if(!$seealso[0]) {
618
+ print STDERR "$f:$line:1:ERROR: no 'See-also:' field present\n";
619
+ return 2;
620
+ }
621
+ if(!$copyright) {
622
+ print STDERR "$f:$line:1:ERROR: no 'C:' field present\n";
623
+ return 2;
624
+ }
625
+ if(!$spdx) {
626
+ print STDERR "$f:$line:1:ERROR: no 'SPDX-License-Identifier:' field present\n";
627
+ return 2;
628
+ }
629
+ last;
630
+ }
631
+ else {
632
+ chomp;
633
+ print STDERR "$f:$line:1:WARN: unrecognized line in $f, ignoring:\n:'$_';"
634
+ }
635
+ }
636
+
637
+ if($start < 2) {
638
+ print STDERR "$f:1:1:ERROR: no proper meta-data header\n";
639
+ return 2;
640
+ }
641
+
642
+ my @desc = render($manpage, $fh, $f, $line);
643
+ close($fh);
644
+ if($tablemode) {
645
+ # end of table
646
+ push @desc, ".RE\n.IP\n";
647
+ }
648
+ my $opt;
649
+
650
+ if(defined($short) && $long) {
651
+ $opt = "-$short, --$long";
652
+ }
653
+ elsif($short && !$long) {
654
+ $opt = "-$short";
655
+ }
656
+ elsif($long && !$short) {
657
+ $opt = "--$long";
658
+ }
659
+
660
+ if($arg) {
661
+ $opt .= " $arg";
662
+ }
663
+
664
+ # quote "bare" minuses in opt
665
+ $opt =~ s/-/\\-/g if($manpage);
666
+ if($standalone) {
667
+ print ".TH curl 1 \"30 Nov 2016\" \"curl 7.52.0\" \"curl manual\"\n";
668
+ print ".SH OPTION\n";
669
+ print "curl $opt\n";
670
+ }
671
+ elsif($manpage) {
672
+ print ".IP \"$opt\"\n";
673
+ }
674
+ else {
675
+ lastline(1, $opt);
676
+ }
677
+ my @leading;
678
+ if($protocols) {
679
+ push @leading, protocols($manpage, $standalone, $protocols);
680
+ }
681
+
682
+ if($standalone) {
683
+ print ".SH DESCRIPTION\n";
684
+ }
685
+
686
+ if($experimental) {
687
+ push @leading, "**WARNING**: this option is experimental. Do not use in production.\n\n";
688
+ }
689
+
690
+ my $pre = $manpage ? "\n": "[1]";
691
+
692
+ if($scope) {
693
+ if($category !~ /global/) {
694
+ print STDERR "$f:$line:1:ERROR: global scope option does not have global category\n";
695
+ return 2;
696
+ }
697
+ if($scope eq "global") {
698
+ push @desc, "\n" if(!$manpage);
699
+ push @desc, "${pre}This option is global and does not need to be specified for each use of --next.\n";
700
+ }
701
+ else {
702
+ print STDERR "$f:$line:1:ERROR: unrecognized scope: '$scope'\n";
703
+ return 2;
704
+ }
705
+ }
706
+
707
+ my @extra;
708
+ if($multi eq "single") {
709
+ push @extra, "${pre}If --$long is provided several times, the last set ".
710
+ "value is used.\n";
711
+ }
712
+ elsif($multi eq "append") {
713
+ push @extra, "${pre}--$long can be used several times in a command line\n";
714
+ }
715
+ elsif($multi eq "boolean") {
716
+ my $rev = "no-$long";
717
+ # for options that start with "no-" the reverse is then without
718
+ # the no- prefix
719
+ if($long =~ /^no-/) {
720
+ $rev = $long;
721
+ $rev =~ s/^no-//;
722
+ }
723
+ my $dashes = $manpage ? "\\-\\-" : "--";
724
+ push @extra,
725
+ "${pre}Providing --$long multiple times has no extra effect.\n".
726
+ "Disable it again with $dashes$rev.\n";
727
+ }
728
+ elsif($multi eq "mutex") {
729
+ push @extra,
730
+ "${pre}Providing --$long multiple times has no extra effect.\n";
731
+ }
732
+ elsif($multi eq "custom") {
733
+ ; # left for the text to describe
734
+ }
735
+ elsif($multi eq "per-URL") {
736
+ push @extra,
737
+ "${pre}--$long is associated with a single URL. Use it once per URL ".
738
+ "when you use several URLs in a command line.\n";
739
+ }
740
+ else {
741
+ print STDERR "$f:$line:1:ERROR: unrecognized Multi: '$multi'\n";
742
+ return 2;
743
+ }
744
+
745
+ printdesc($manpage, 2, (@leading, @desc, @extra));
746
+ undef @desc;
747
+
748
+ my @foot;
749
+
750
+ my $mstr;
751
+ my $and = 0;
752
+ my $num = scalar(@seealso);
753
+ if($num > 2) {
754
+ # use commas up to this point
755
+ $and = $num - 1;
756
+ }
757
+ my $i = 0;
758
+ for my $k (@seealso) {
759
+ if(!$helplong{$k}) {
760
+ print STDERR "$f:$line:1:WARN: see-also a non-existing option: $k\n";
761
+ }
762
+ my $l = $manpage ? manpageify($k) : "--$k";
763
+ my $sep = " and";
764
+ if($and && ($i < $and)) {
765
+ $sep = ",";
766
+ }
767
+ $mstr .= sprintf "%s$l", $mstr?"$sep ":"";
768
+ $i++;
769
+ }
770
+
771
+ if($requires) {
772
+ my $l = $manpage ? manpageify($long) : "--$long";
773
+ push @foot, "$l requires that libcurl".
774
+ " is built to support $requires.\n";
775
+ }
776
+ if($mutexed) {
777
+ my @m=split(/ /, $mutexed);
778
+ my $mstr;
779
+ my $num = scalar(@m);
780
+ my $count;
781
+ for my $k (@m) {
782
+ if(!$helplong{$k}) {
783
+ print STDERR "WARN: $f mutexes a non-existing option: $k\n";
784
+ }
785
+ my $l = $manpage ? manpageify($k) : "--$k";
786
+ my $sep = ", ";
787
+ if($count == ($num -1)) {
788
+ $sep = " and ";
789
+ }
790
+ $mstr .= sprintf "%s$l", $mstr?$sep:"";
791
+ $count++;
792
+ }
793
+ push @foot, overrides($standalone,
794
+ "This option is mutually exclusive with $mstr.\n");
795
+ }
796
+ if($examples[0]) {
797
+ my $s ="";
798
+ $s="s" if($examples[1]);
799
+ if($manpage) {
800
+ print "\nExample$s:\n";
801
+ print ".nf\n";
802
+ foreach my $e (@examples) {
803
+ $e =~ s!\$URL!https://example.com!g;
804
+ # convert single backslahes to doubles
805
+ $e =~ s/\\/\\\\/g;
806
+ print "curl $e\n";
807
+ }
808
+ print ".fi\n";
809
+ }
810
+ else {
811
+ my @ex;
812
+ push @ex, "[0q]Example$s:\n";
813
+ #
814
+ # long ASCII examples are wrapped. Preferably at the last space
815
+ # before the margin. Or at a colon. Otherwise it just cuts at the
816
+ # exact boundary.
817
+ #
818
+ foreach my $e (@examples) {
819
+ $e =~ s!\$URL!https://example.com!g;
820
+ my $maxwidth = 60; # plus the " curl " 18 col prefix
821
+ if(length($e) > $maxwidth) {
822
+ # a long example, shorten it
823
+ my $p = substr($e, 0, $maxwidth);
824
+ $p = maybespace($p);
825
+ push @ex, "[0q] curl ".$p."\\";
826
+ $e = substr($e, length($p));
827
+ do {
828
+ my $r = substr($e, 0, $maxwidth);
829
+ if(length($e) > $maxwidth) {
830
+ $r = maybespace($r);
831
+ }
832
+ my $slash ="";
833
+ $e = substr($e, length($r));
834
+ if(length($e) > 0) {
835
+ $slash = "\\";
836
+ }
837
+
838
+ push @ex, "[0q] $r$slash" if($r);
839
+ } while(length($e));
840
+ }
841
+ else {
842
+ push @ex, "[0q] curl $e\n";
843
+ }
844
+ }
845
+ printdesc($manpage, 2, @ex);
846
+ }
847
+ }
848
+ if($added) {
849
+ push @foot, added($standalone, $added);
850
+ }
851
+ push @foot, seealso($standalone, $mstr);
852
+
853
+ print "\n";
854
+ my $f = join("", @foot);
855
+ if($manpage) {
856
+ $f =~ s/ +\z//; # remove trailing space
857
+ print "$f\n";
858
+ }
859
+ else {
860
+ printdesc($manpage, 2, "[1]$f");
861
+ }
862
+ return 0;
863
+ }
864
+
865
+ sub getshortlong {
866
+ my ($dir, $f)=@_;
867
+ $f =~ s/^.*\///;
868
+ open(F, "<:crlf", "$dir/$f") ||
869
+ die "could not find $dir/$f";
870
+ my $short;
871
+ my $long;
872
+ my $help;
873
+ my $arg;
874
+ my $protocols;
875
+ my $category;
876
+ my $start = 0;
877
+ my $line = 0;
878
+ while(<F>) {
879
+ $line++;
880
+ if(!$start) {
881
+ if(/^---/) {
882
+ $start = 1;
883
+ }
884
+ next;
885
+ }
886
+ if(/^Short: (.)/i) {
887
+ $short=$1;
888
+ }
889
+ elsif(/^Long: (.*)/i) {
890
+ $long=$1;
891
+ }
892
+ elsif(/^Help: (.*)/i) {
893
+ $help=$1;
894
+ my $len = length($help);
895
+ if($len >= 49) {
896
+ printf STDERR "$f:$line:1:WARN: oversized help text: %d characters\n",
897
+ $len;
898
+ }
899
+ }
900
+ elsif(/^Arg: (.*)/i) {
901
+ $arg=$1;
902
+ }
903
+ elsif(/^Protocols: (.*)/i) {
904
+ $protocols=$1;
905
+ }
906
+ elsif(/^Category: (.*)/i) {
907
+ $category=$1;
908
+ }
909
+ elsif(/^---/) {
910
+ last;
911
+ }
912
+ }
913
+ close(F);
914
+ if($short) {
915
+ $optshort{$short}=$long;
916
+ }
917
+ if($long) {
918
+ $optlong{$long}=$short;
919
+ $helplong{$long}=$help;
920
+ $arglong{$long}=$arg;
921
+ $protolong{$long}=$protocols;
922
+ $catlong{$long}=$category;
923
+ }
924
+ }
925
+
926
+ sub indexoptions {
927
+ my ($dir, @files) = @_;
928
+ foreach my $f (@files) {
929
+ getshortlong($dir, $f);
930
+ }
931
+ }
932
+
933
+ sub header {
934
+ my ($dir, $manpage, $f)=@_;
935
+ my $fh;
936
+ open($fh, "<:crlf", "$dir/$f") ||
937
+ die "could not find $dir/$f";
938
+ my @d = render($manpage, $fh, $f, 1);
939
+ close($fh);
940
+ printdesc($manpage, 0, @d);
941
+ }
942
+
943
+
944
+ sub sourcecategories {
945
+ my ($dir) = @_;
946
+ my %cats;
947
+ open(H, "<$dir/../../src/tool_help.h") ||
948
+ die "can't find the header file";
949
+ while(<H>) {
950
+ if(/^\#define CURLHELP_([A-Z0-9]*)/) {
951
+ $cats{lc($1)}++;
952
+ }
953
+ }
954
+ close(H);
955
+ return %cats;
956
+ }
957
+
958
+ sub listhelp {
959
+ my ($dir) = @_;
960
+ my %cats = sourcecategories($dir);
961
+
962
+ print <<HEAD
963
+ /***************************************************************************
964
+ * _ _ ____ _
965
+ * Project ___| | | | _ \\| |
966
+ * / __| | | | |_) | |
967
+ * | (__| |_| | _ <| |___
968
+ * \\___|\\___/|_| \\_\\_____|
969
+ *
970
+ * Copyright (C) Daniel Stenberg, <daniel\@haxx.se>, et al.
971
+ *
972
+ * This software is licensed as described in the file COPYING, which
973
+ * you should have received as part of this distribution. The terms
974
+ * are also available at https://curl.se/docs/copyright.html.
975
+ *
976
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
977
+ * copies of the Software, and permit persons to whom the Software is
978
+ * furnished to do so, under the terms of the COPYING file.
979
+ *
980
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
981
+ * KIND, either express or implied.
982
+ *
983
+ * SPDX-License-Identifier: curl
984
+ *
985
+ ***************************************************************************/
986
+ #include "tool_setup.h"
987
+ #include "tool_help.h"
988
+
989
+ /*
990
+ * DO NOT edit tool_listhelp.c manually.
991
+ * This source file is generated with the following command in an autotools
992
+ * build:
993
+ *
994
+ * "make listhelp"
995
+ */
996
+
997
+ const struct helptxt helptext[] = {
998
+ HEAD
999
+ ;
1000
+ foreach my $f (sort keys %helplong) {
1001
+ my $long = $f;
1002
+ my $short = $optlong{$long};
1003
+ my @categories = split ' ', $catlong{$long};
1004
+ my $bitmask = ' ';
1005
+ my $opt;
1006
+
1007
+ if(defined($short) && $long) {
1008
+ $opt = "-$short, --$long";
1009
+ }
1010
+ elsif($long && !$short) {
1011
+ $opt = " --$long";
1012
+ }
1013
+ for my $i (0 .. $#categories) {
1014
+ if(!$cats{ $categories[$i] }) {
1015
+ printf STDERR "$f.md:ERROR: Unknown category '%s'\n",
1016
+ $categories[$i];
1017
+ exit 3;
1018
+ }
1019
+
1020
+ $bitmask .= 'CURLHELP_' . uc $categories[$i];
1021
+ # If not last element, append |
1022
+ if($i < $#categories) {
1023
+ $bitmask .= ' | ';
1024
+ }
1025
+ }
1026
+ $bitmask =~ s/(?=.{76}).{1,76}\|/$&\n /g;
1027
+ my $arg = $arglong{$long};
1028
+ if($arg) {
1029
+ $opt .= " $arg";
1030
+ }
1031
+ my $desc = $helplong{$f};
1032
+ $desc =~ s/\"/\\\"/g; # escape double quotes
1033
+
1034
+ my $line = sprintf " {\"%s\",\n \"%s\",\n %s},\n", $opt, $desc, $bitmask;
1035
+
1036
+ if(length($opt) > 78) {
1037
+ print STDERR "WARN: the --$long name is too long\n";
1038
+ }
1039
+ elsif(length($desc) > 78) {
1040
+ print STDERR "WARN: the --$long description is too long\n";
1041
+ }
1042
+ print $line;
1043
+ }
1044
+ print <<FOOT
1045
+ { NULL, NULL, 0 }
1046
+ };
1047
+ FOOT
1048
+ ;
1049
+ }
1050
+
1051
+ sub listcats {
1052
+ my %allcats;
1053
+ foreach my $f (sort keys %helplong) {
1054
+ my @categories = split ' ', $catlong{$f};
1055
+ foreach (@categories) {
1056
+ $allcats{$_} = undef;
1057
+ }
1058
+ }
1059
+ my @categories;
1060
+ foreach my $key (keys %allcats) {
1061
+ push @categories, $key;
1062
+ }
1063
+ @categories = sort @categories;
1064
+ for my $i (0..$#categories) {
1065
+ printf("#define CURLHELP_%-10s (%s)\n",
1066
+ uc($categories[$i]), "1u << ${i}u");
1067
+ }
1068
+ }
1069
+
1070
+ sub listglobals {
1071
+ my ($dir, @files) = @_;
1072
+ my @globalopts;
1073
+
1074
+ # Find all global options and output them
1075
+ foreach my $f (sort @files) {
1076
+ open(F, "<:crlf", "$dir/$f") ||
1077
+ die "could not read $dir/$f";
1078
+ my $long;
1079
+ my $start = 0;
1080
+ while(<F>) {
1081
+ if(/^---/) {
1082
+ if(!$start) {
1083
+ $start = 1;
1084
+ next;
1085
+ }
1086
+ else {
1087
+ last;
1088
+ }
1089
+ }
1090
+ if(/^Long: *(.*)/i) {
1091
+ $long=$1;
1092
+ }
1093
+ elsif(/^Scope: global/i) {
1094
+ push @globalopts, $long;
1095
+ last;
1096
+ }
1097
+ }
1098
+ close(F);
1099
+ }
1100
+ return $ret if($ret);
1101
+ for my $e (0 .. $#globalopts) {
1102
+ $globals .= sprintf "%s--%s", $e?($globalopts[$e+1] ? ", " : " and "):"",
1103
+ $globalopts[$e],;
1104
+ }
1105
+ }
1106
+
1107
+ sub noext {
1108
+ my $in = $_[0];
1109
+ $in =~ s/\.md//;
1110
+ return $in;
1111
+ }
1112
+
1113
+ sub sortnames {
1114
+ return noext($a) cmp noext($b);
1115
+ }
1116
+
1117
+ sub mainpage {
1118
+ my ($dir, $manpage, @files) = @_;
1119
+ # $manpage is 1 for nroff, 0 for ASCII
1120
+ my $ret;
1121
+ my $fh;
1122
+ open($fh, "<:crlf", "$dir/mainpage.idx") ||
1123
+ die "no $dir/mainpage.idx file";
1124
+
1125
+ print <<HEADER
1126
+ .\\" **************************************************************************
1127
+ .\\" * _ _ ____ _
1128
+ .\\" * Project ___| | | | _ \\| |
1129
+ .\\" * / __| | | | |_) | |
1130
+ .\\" * | (__| |_| | _ <| |___
1131
+ .\\" * \\___|\\___/|_| \\_\\_____|
1132
+ .\\" *
1133
+ .\\" * Copyright (C) Daniel Stenberg, <daniel\@haxx.se>, et al.
1134
+ .\\" *
1135
+ .\\" * This software is licensed as described in the file COPYING, which
1136
+ .\\" * you should have received as part of this distribution. The terms
1137
+ .\\" * are also available at https://curl.se/docs/copyright.html.
1138
+ .\\" *
1139
+ .\\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1140
+ .\\" * copies of the Software, and permit persons to whom the Software is
1141
+ .\\" * furnished to do so, under the terms of the COPYING file.
1142
+ .\\" *
1143
+ .\\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1144
+ .\\" * KIND, either express or implied.
1145
+ .\\" *
1146
+ .\\" * SPDX-License-Identifier: curl
1147
+ .\\" *
1148
+ .\\" **************************************************************************
1149
+ .\\"
1150
+ .\\" DO NOT EDIT. Generated by the curl project managen manpage generator.
1151
+ .\\"
1152
+ .TH curl 1 "$date" "curl $version" "curl Manual"
1153
+ HEADER
1154
+ if ($manpage);
1155
+
1156
+ while(<$fh>) {
1157
+ my $f = $_;
1158
+ chomp $f;
1159
+ if($f =~ /^#/) {
1160
+ # standard comment
1161
+ next;
1162
+ }
1163
+ if(/^%options/) {
1164
+ # output docs for all options
1165
+ foreach my $f (sort sortnames @files) {
1166
+ $ret += single($dir, $manpage, $f, 0);
1167
+ }
1168
+ }
1169
+ else {
1170
+ # render the file
1171
+ header($dir, $manpage, $f);
1172
+ }
1173
+ }
1174
+ close($fh);
1175
+ exit $ret if($ret);
1176
+ }
1177
+
1178
+ sub showonly {
1179
+ my ($f) = @_;
1180
+ if(single($f, 1)) {
1181
+ print STDERR "$f: failed\n";
1182
+ }
1183
+ }
1184
+
1185
+ sub showprotocols {
1186
+ my %prots;
1187
+ foreach my $f (keys %optlong) {
1188
+ my @p = split(/ /, $protolong{$f});
1189
+ for my $p (@p) {
1190
+ $prots{$p}++;
1191
+ }
1192
+ }
1193
+ for(sort keys %prots) {
1194
+ printf "$_ (%d options)\n", $prots{$_};
1195
+ }
1196
+ }
1197
+
1198
+ sub getargs {
1199
+ my ($dir, $f, @s) = @_;
1200
+ if($f eq "mainpage") {
1201
+ listglobals($dir, @s);
1202
+ mainpage($dir, 1, @s);
1203
+ return;
1204
+ }
1205
+ elsif($f eq "ascii") {
1206
+ listglobals($dir, @s);
1207
+ mainpage($dir, 0, @s);
1208
+ return;
1209
+ }
1210
+ elsif($f eq "listhelp") {
1211
+ listhelp($dir);
1212
+ return;
1213
+ }
1214
+ elsif($f eq "single") {
1215
+ showonly($s[0]);
1216
+ return;
1217
+ }
1218
+ elsif($f eq "protos") {
1219
+ showprotocols();
1220
+ return;
1221
+ }
1222
+ elsif($f eq "listcats") {
1223
+ listcats();
1224
+ return;
1225
+ }
1226
+
1227
+ print "Usage: managen ".
1228
+ "[-d dir] <mainpage/ascii/listhelp/single FILE/protos/listcats> [files]\n";
1229
+ }
1230
+
1231
+ #------------------------------------------------------------------------
1232
+
1233
+ my $dir = ".";
1234
+ my $include = "../../include";
1235
+ my $cmd = shift @ARGV;
1236
+
1237
+ check:
1238
+ if($cmd eq "-d") {
1239
+ # specifies source directory
1240
+ $dir = shift @ARGV;
1241
+ $cmd = shift @ARGV;
1242
+ goto check;
1243
+ }
1244
+ elsif($cmd eq "-I") {
1245
+ # include path root
1246
+ $include = shift @ARGV;
1247
+ $cmd = shift @ARGV;
1248
+ goto check;
1249
+ }
1250
+ elsif($cmd eq "-c") {
1251
+ # Column width
1252
+ $colwidth = 0 + shift @ARGV;
1253
+ $cmd = shift @ARGV;
1254
+ goto check;
1255
+ }
1256
+
1257
+ my @files = @ARGV; # the rest are the files
1258
+
1259
+ # can be overridden for releases
1260
+ if($ENV{'CURL_MAKETGZ_VERSION'}) {
1261
+ $version = $ENV{'CURL_MAKETGZ_VERSION'};
1262
+ }
1263
+ else {
1264
+ open(INC, "<$include/curl/curlver.h");
1265
+ while(<INC>) {
1266
+ if($_ =~ /^#define LIBCURL_VERSION \"([0-9.]*)/) {
1267
+ $version = $1;
1268
+ last;
1269
+ }
1270
+ }
1271
+ close(INC);
1272
+ }
1273
+
1274
+ # learn all existing options
1275
+ indexoptions($dir, @files);
1276
+
1277
+ getargs($dir, $cmd, @files);
1278
+
1279
+ exit $error;
local-test-curl-delta-01/afc-curl/scripts/mk-ca-bundle.pl ADDED
@@ -0,0 +1,672 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ # ***************************************************************************
3
+ # * _ _ ____ _
4
+ # * Project ___| | | | _ \| |
5
+ # * / __| | | | |_) | |
6
+ # * | (__| |_| | _ <| |___
7
+ # * \___|\___/|_| \_\_____|
8
+ # *
9
+ # * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ # *
11
+ # * This software is licensed as described in the file COPYING, which
12
+ # * you should have received as part of this distribution. The terms
13
+ # * are also available at https://curl.se/docs/copyright.html.
14
+ # *
15
+ # * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # * copies of the Software, and permit persons to whom the Software is
17
+ # * furnished to do so, under the terms of the COPYING file.
18
+ # *
19
+ # * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # * KIND, either express or implied.
21
+ # *
22
+ # * SPDX-License-Identifier: curl
23
+ # *
24
+ # ***************************************************************************
25
+ # This Perl script creates a fresh ca-bundle.crt file for use with libcurl.
26
+ # It downloads certdata.txt from Mozilla's source tree (see URL below),
27
+ # then parses certdata.txt and extracts CA Root Certificates into PEM format.
28
+ # These are then processed with the OpenSSL commandline tool to produce the
29
+ # final ca-bundle.crt file.
30
+ # The script is based on the parse-certs script written by Roland Krikava.
31
+ # This Perl script works on almost any platform since its only external
32
+ # dependency is the OpenSSL commandline tool for optional text listing.
33
+ # Hacked by Guenter Knauf.
34
+ #
35
+ use Encode;
36
+ use Getopt::Std;
37
+ use MIME::Base64;
38
+ use strict;
39
+ use warnings;
40
+ use vars qw($opt_b $opt_d $opt_f $opt_h $opt_i $opt_k $opt_l $opt_m $opt_n $opt_p $opt_q $opt_s $opt_t $opt_u $opt_v $opt_w);
41
+ use List::Util;
42
+ use Text::Wrap;
43
+ use Time::Local;
44
+ my $MOD_SHA = "Digest::SHA";
45
+ eval "require $MOD_SHA";
46
+ if ($@) {
47
+ $MOD_SHA = "Digest::SHA::PurePerl";
48
+ eval "require $MOD_SHA";
49
+ }
50
+ eval "require LWP::UserAgent";
51
+
52
+ my %urls = (
53
+ 'nss' =>
54
+ 'https://hg.mozilla.org/projects/nss/raw-file/default/lib/ckfw/builtins/certdata.txt',
55
+ 'central' =>
56
+ 'https://hg.mozilla.org/mozilla-central/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt',
57
+ 'beta' =>
58
+ 'https://hg.mozilla.org/releases/mozilla-beta/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt',
59
+ 'release' =>
60
+ 'https://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt',
61
+ );
62
+
63
+ $opt_d = 'release';
64
+
65
+ # If the OpenSSL commandline is not in search path you can configure it here!
66
+ my $openssl = 'openssl';
67
+
68
+ my $version = '1.29';
69
+
70
+ $opt_w = 76; # default base64 encoded lines length
71
+
72
+ # default cert types to include in the output (default is to include CAs which
73
+ # may issue SSL server certs)
74
+ my $default_mozilla_trust_purposes = "SERVER_AUTH";
75
+ my $default_mozilla_trust_levels = "TRUSTED_DELEGATOR";
76
+ $opt_p = $default_mozilla_trust_purposes . ":" . $default_mozilla_trust_levels;
77
+
78
+ my @valid_mozilla_trust_purposes = (
79
+ "DIGITAL_SIGNATURE",
80
+ "NON_REPUDIATION",
81
+ "KEY_ENCIPHERMENT",
82
+ "DATA_ENCIPHERMENT",
83
+ "KEY_AGREEMENT",
84
+ "KEY_CERT_SIGN",
85
+ "CRL_SIGN",
86
+ "SERVER_AUTH",
87
+ "CLIENT_AUTH",
88
+ "CODE_SIGNING",
89
+ "EMAIL_PROTECTION",
90
+ "IPSEC_END_SYSTEM",
91
+ "IPSEC_TUNNEL",
92
+ "IPSEC_USER",
93
+ "TIME_STAMPING",
94
+ "STEP_UP_APPROVED"
95
+ );
96
+
97
+ my @valid_mozilla_trust_levels = (
98
+ "TRUSTED_DELEGATOR", # CAs
99
+ "NOT_TRUSTED", # Don't trust these certs.
100
+ "MUST_VERIFY_TRUST", # This explicitly tells us that it ISN'T a CA but is
101
+ # otherwise ok. In other words, this should tell the
102
+ # app to ignore any other sources that claim this is
103
+ # a CA.
104
+ "TRUSTED" # This cert is trusted, but only for itself and not
105
+ # for delegates (i.e. it is not a CA).
106
+ );
107
+
108
+ my $default_signature_algorithms = $opt_s = "MD5";
109
+
110
+ my @valid_signature_algorithms = (
111
+ "MD5",
112
+ "SHA1",
113
+ "SHA256",
114
+ "SHA384",
115
+ "SHA512"
116
+ );
117
+
118
+ $0 =~ s@.*(/|\\)@@;
119
+ $Getopt::Std::STANDARD_HELP_VERSION = 1;
120
+ getopts('bd:fhiklmnp:qs:tuvw:');
121
+
122
+ if(!defined($opt_d)) {
123
+ # to make plain "-d" use not cause warnings, and actually still work
124
+ $opt_d = 'release';
125
+ }
126
+
127
+ # Use predefined URL or else custom URL specified on command line.
128
+ my $url;
129
+ if(defined($urls{$opt_d})) {
130
+ $url = $urls{$opt_d};
131
+ if(!$opt_k && $url !~ /^https:\/\//i) {
132
+ die "The URL for '$opt_d' is not HTTPS. Use -k to override (insecure).\n";
133
+ }
134
+ }
135
+ else {
136
+ $url = $opt_d;
137
+ }
138
+
139
+ if ($opt_i) {
140
+ print ("=" x 78 . "\n");
141
+ print "Script Version : $version\n";
142
+ print "Perl Version : $]\n";
143
+ print "Operating System Name : $^O\n";
144
+ print "Getopt::Std.pm Version : ${Getopt::Std::VERSION}\n";
145
+ print "Encode::Encoding.pm Version : ${Encode::Encoding::VERSION}\n";
146
+ print "MIME::Base64.pm Version : ${MIME::Base64::VERSION}\n";
147
+ print "LWP::UserAgent.pm Version : ${LWP::UserAgent::VERSION}\n" if($LWP::UserAgent::VERSION);
148
+ print "LWP.pm Version : ${LWP::VERSION}\n" if($LWP::VERSION);
149
+ print "Digest::SHA.pm Version : ${Digest::SHA::VERSION}\n" if ($Digest::SHA::VERSION);
150
+ print "Digest::SHA::PurePerl.pm Version : ${Digest::SHA::PurePerl::VERSION}\n" if ($Digest::SHA::PurePerl::VERSION);
151
+ print ("=" x 78 . "\n");
152
+ }
153
+
154
+ sub warning_message() {
155
+ if ( $opt_d =~ m/^risk$/i ) { # Long Form Warning and Exit
156
+ print "Warning: Use of this script may pose some risk:\n";
157
+ print "\n";
158
+ print " 1) If you use HTTP URLs they are subject to a man in the middle attack\n";
159
+ print " 2) Default to 'release', but more recent updates may be found in other trees\n";
160
+ print " 3) certdata.txt file format may change, lag time to update this script\n";
161
+ print " 4) Generally unwise to blindly trust CAs without manual review & verification\n";
162
+ print " 5) Mozilla apps use additional security checks aren't represented in certdata\n";
163
+ print " 6) Use of this script will make a security engineer grind his teeth and\n";
164
+ print " swear at you. ;)\n";
165
+ exit;
166
+ } else { # Short Form Warning
167
+ print "Warning: Use of this script may pose some risk, -d risk for more details.\n";
168
+ }
169
+ }
170
+
171
+ sub HELP_MESSAGE() {
172
+ print "Usage:\t${0} [-b] [-d<certdata>] [-f] [-i] [-k] [-l] [-n] [-p<purposes:levels>] [-q] [-s<algorithms>] [-t] [-u] [-v] [-w<l>] [<outputfile>]\n";
173
+ print "\t-b\tbackup an existing version of ca-bundle.crt\n";
174
+ print "\t-d\tspecify Mozilla tree to pull certdata.txt or custom URL\n";
175
+ print "\t\t Valid names are:\n";
176
+ print "\t\t ", join( ", ", map { ( $_ =~ m/$opt_d/ ) ? "$_ (default)" : "$_" } sort keys %urls ), "\n";
177
+ print "\t-f\tforce rebuild even if certdata.txt is current\n";
178
+ print "\t-i\tprint version info about used modules\n";
179
+ print "\t-k\tallow URLs other than HTTPS, enable HTTP fallback (insecure)\n";
180
+ print "\t-l\tprint license info about certdata.txt\n";
181
+ print "\t-m\tinclude meta data in output\n";
182
+ print "\t-n\tno download of certdata.txt (to use existing)\n";
183
+ print wrap("\t","\t\t", "-p\tlist of Mozilla trust purposes and levels for certificates to include in output. Takes the form of a comma separated list of purposes, a colon, and a comma separated list of levels. (default: $default_mozilla_trust_purposes:$default_mozilla_trust_levels)"), "\n";
184
+ print "\t\t Valid purposes are:\n";
185
+ print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_mozilla_trust_purposes ) ), "\n";
186
+ print "\t\t Valid levels are:\n";
187
+ print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_mozilla_trust_levels ) ), "\n";
188
+ print "\t-q\tbe really quiet (no progress output at all)\n";
189
+ print wrap("\t","\t\t", "-s\tcomma separated list of certificate signatures/hashes to output in plain text mode. (default: $default_signature_algorithms)\n");
190
+ print "\t\t Valid signature algorithms are:\n";
191
+ print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_signature_algorithms ) ), "\n";
192
+ print "\t-t\tinclude plain text listing of certificates\n";
193
+ print "\t-u\tunlink (remove) certdata.txt after processing\n";
194
+ print "\t-v\tbe verbose and print out processed CAs\n";
195
+ print "\t-w <l>\twrap base64 output lines after <l> chars (default: ${opt_w})\n";
196
+ exit;
197
+ }
198
+
199
+ sub VERSION_MESSAGE() {
200
+ print "${0} version ${version} running Perl ${]} on ${^O}\n";
201
+ }
202
+
203
+ warning_message() unless ($opt_q || $url =~ m/^(ht|f)tps:/i );
204
+ HELP_MESSAGE() if ($opt_h);
205
+
206
+ sub report($@) {
207
+ my $output = shift;
208
+
209
+ print STDERR $output . "\n" unless $opt_q;
210
+ }
211
+
212
+ sub is_in_list($@) {
213
+ my $target = shift;
214
+
215
+ return defined(List::Util::first { $target eq $_ } @_);
216
+ }
217
+
218
+ # Parses $param_string as a case insensitive comma separated list with optional
219
+ # whitespace validates that only allowed parameters are supplied
220
+ sub parse_csv_param($$@) {
221
+ my $description = shift;
222
+ my $param_string = shift;
223
+ my @valid_values = @_;
224
+
225
+ my @values = map {
226
+ s/^\s+//; # strip leading spaces
227
+ s/\s+$//; # strip trailing spaces
228
+ uc $_ # return the modified string as upper case
229
+ } split( ',', $param_string );
230
+
231
+ # Find all values which are not in the list of valid values or "ALL"
232
+ my @invalid = grep { !is_in_list($_,"ALL",@valid_values) } @values;
233
+
234
+ if ( scalar(@invalid) > 0 ) {
235
+ # Tell the user which parameters were invalid and print the standard help
236
+ # message which will exit
237
+ print "Error: Invalid ", $description, scalar(@invalid) == 1 ? ": " : "s: ", join( ", ", map { "\"$_\"" } @invalid ), "\n";
238
+ HELP_MESSAGE();
239
+ }
240
+
241
+ @values = @valid_values if ( is_in_list("ALL",@values) );
242
+
243
+ return @values;
244
+ }
245
+
246
+ sub sha256 {
247
+ my $result;
248
+ if ($Digest::SHA::VERSION || $Digest::SHA::PurePerl::VERSION) {
249
+ open(FILE, $_[0]) or die "Can't open '$_[0]': $!";
250
+ binmode(FILE);
251
+ $result = $MOD_SHA->new(256)->addfile(*FILE)->hexdigest;
252
+ close(FILE);
253
+ } else {
254
+ # Use OpenSSL command if Perl Digest::SHA modules not available
255
+ $result = `"$openssl" dgst -r -sha256 "$_[0]"`;
256
+ $result =~ s/^([0-9a-f]{64}) .+/$1/is;
257
+ }
258
+ return $result;
259
+ }
260
+
261
+
262
+ sub oldhash {
263
+ my $hash = "";
264
+ open(C, "<$_[0]") || return 0;
265
+ while(<C>) {
266
+ chomp;
267
+ if($_ =~ /^\#\# SHA256: (.*)/) {
268
+ $hash = $1;
269
+ last;
270
+ }
271
+ }
272
+ close(C);
273
+ return $hash;
274
+ }
275
+
276
+ if ( $opt_p !~ m/:/ ) {
277
+ print "Error: Mozilla trust identifier list must include both purposes and levels\n";
278
+ HELP_MESSAGE();
279
+ }
280
+
281
+ (my $included_mozilla_trust_purposes_string, my $included_mozilla_trust_levels_string) = split( ':', $opt_p );
282
+ my @included_mozilla_trust_purposes = parse_csv_param( "trust purpose", $included_mozilla_trust_purposes_string, @valid_mozilla_trust_purposes );
283
+ my @included_mozilla_trust_levels = parse_csv_param( "trust level", $included_mozilla_trust_levels_string, @valid_mozilla_trust_levels );
284
+
285
+ my @included_signature_algorithms = parse_csv_param( "signature algorithm", $opt_s, @valid_signature_algorithms );
286
+
287
+ sub should_output_cert(%) {
288
+ my %trust_purposes_by_level = @_;
289
+
290
+ foreach my $level (@included_mozilla_trust_levels) {
291
+ # for each level we want to output, see if any of our desired purposes are
292
+ # included
293
+ return 1 if ( defined( List::Util::first { is_in_list( $_, @included_mozilla_trust_purposes ) } @{$trust_purposes_by_level{$level}} ) );
294
+ }
295
+
296
+ return 0;
297
+ }
298
+
299
+ my $crt = $ARGV[0] || 'ca-bundle.crt';
300
+ (my $txt = $url) =~ s@(.*/|\?.*)@@g;
301
+
302
+ my $stdout = $crt eq '-';
303
+ my $resp;
304
+ my $fetched;
305
+
306
+ my $oldhash = oldhash($crt);
307
+
308
+ report "SHA256 of old file: $oldhash";
309
+
310
+ if(!$opt_n) {
311
+ report "Downloading $txt ...";
312
+
313
+ # If we have an HTTPS URL then use curl
314
+ if($url =~ /^https:\/\//i) {
315
+ my $curl = `curl -V`;
316
+ if($curl) {
317
+ if($curl =~ /^Protocols:.* https( |$)/m) {
318
+ report "Get certdata with curl!";
319
+ my $proto = !$opt_k ? "--proto =https" : "";
320
+ my $quiet = $opt_q ? "-s" : "";
321
+ my @out = `curl -w %{response_code} $proto $quiet -o "$txt" "$url"`;
322
+ if(!$? && @out && $out[0] == 200) {
323
+ $fetched = 1;
324
+ report "Downloaded $txt";
325
+ }
326
+ else {
327
+ report "Failed downloading via HTTPS with curl";
328
+ if(-e $txt && !unlink($txt)) {
329
+ report "Failed to remove '$txt': $!";
330
+ }
331
+ }
332
+ }
333
+ else {
334
+ report "curl lacks https support";
335
+ }
336
+ }
337
+ else {
338
+ report "curl not found";
339
+ }
340
+ }
341
+
342
+ # If nothing was fetched then use LWP
343
+ if(!$fetched) {
344
+ if($url =~ /^https:\/\//i) {
345
+ report "Falling back to HTTP";
346
+ $url =~ s/^https:\/\//http:\/\//i;
347
+ }
348
+ if(!$opt_k) {
349
+ report "URLs other than HTTPS are disabled by default, to enable use -k";
350
+ exit 1;
351
+ }
352
+ report "Get certdata with LWP!";
353
+ if(!defined(${LWP::UserAgent::VERSION})) {
354
+ report "LWP is not available (LWP::UserAgent not found)";
355
+ exit 1;
356
+ }
357
+ my $ua = new LWP::UserAgent(agent => "$0/$version");
358
+ $ua->env_proxy();
359
+ $resp = $ua->mirror($url, $txt);
360
+ if($resp && $resp->code eq '304') {
361
+ report "Not modified";
362
+ exit 0 if -e $crt && !$opt_f;
363
+ }
364
+ else {
365
+ $fetched = 1;
366
+ report "Downloaded $txt";
367
+ }
368
+ if(!$resp || $resp->code !~ /^(?:200|304)$/) {
369
+ report "Unable to download latest data: "
370
+ . ($resp? $resp->code . ' - ' . $resp->message : "LWP failed");
371
+ exit 1 if -e $crt || ! -r $txt;
372
+ }
373
+ }
374
+ }
375
+
376
+ my $filedate = $resp ? $resp->last_modified : (stat($txt))[9];
377
+ my $datesrc = "as of";
378
+ if(!$filedate) {
379
+ # mxr.mozilla.org gave us a time, hg.mozilla.org does not!
380
+ $filedate = time();
381
+ $datesrc="downloaded on";
382
+ }
383
+
384
+ # get the hash from the download file
385
+ my $newhash= sha256($txt);
386
+
387
+ if(!$opt_f && $oldhash eq $newhash) {
388
+ report "Downloaded file identical to previous run\'s source file. Exiting";
389
+ if($opt_u && -e $txt && !unlink($txt)) {
390
+ report "Failed to remove $txt: $!\n";
391
+ }
392
+ exit;
393
+ }
394
+
395
+ report "SHA256 of new file: $newhash";
396
+
397
+ my $currentdate = scalar gmtime($filedate);
398
+
399
+ my $format = $opt_t ? "plain text and " : "";
400
+ if( $stdout ) {
401
+ open(CRT, '> -') or die "Couldn't open STDOUT: $!\n";
402
+ } else {
403
+ open(CRT,">$crt.~") or die "Couldn't open $crt.~: $!\n";
404
+ }
405
+ print CRT <<EOT;
406
+ ##
407
+ ## Bundle of CA Root Certificates
408
+ ##
409
+ ## Certificate data from Mozilla ${datesrc}: ${currentdate} GMT
410
+ ##
411
+ ## Find updated versions here: https://curl.se/docs/caextract.html
412
+ ##
413
+ ## This is a bundle of X.509 certificates of public Certificate Authorities
414
+ ## (CA). These were automatically extracted from Mozilla's root certificates
415
+ ## file (certdata.txt). This file can be found in the mozilla source tree:
416
+ ## ${url}
417
+ ##
418
+ ## It contains the certificates in ${format}PEM format and therefore
419
+ ## can be directly used with curl / libcurl / php_curl, or with
420
+ ## an Apache+mod_ssl webserver for SSL client authentication.
421
+ ## Just configure this file as the SSLCACertificateFile.
422
+ ##
423
+ ## Conversion done with mk-ca-bundle.pl version $version.
424
+ ## SHA256: $newhash
425
+ ##
426
+
427
+ EOT
428
+
429
+ report "Processing '$txt' ...";
430
+ my $caname;
431
+ my $certnum = 0;
432
+ my $skipnum = 0;
433
+ my $start_of_cert = 0;
434
+ my $main_block = 0;
435
+ my $main_block_name;
436
+ my $trust_block = 0;
437
+ my $trust_block_name;
438
+ my @precert;
439
+ my $cka_value;
440
+ my $valid = 0;
441
+
442
+ open(TXT,"$txt") or die "Couldn't open $txt: $!\n";
443
+ while (<TXT>) {
444
+ if (/\*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*/) {
445
+ print CRT;
446
+ print if ($opt_l);
447
+ while (<TXT>) {
448
+ print CRT;
449
+ print if ($opt_l);
450
+ last if (/\*\*\*\*\* END LICENSE BLOCK \*\*\*\*\*/);
451
+ }
452
+ next;
453
+ }
454
+ # The input file format consists of blocks of Mozilla objects.
455
+ # The blocks are separated by blank lines but may be related.
456
+ elsif(/^\s*$/) {
457
+ $main_block = 0;
458
+ $trust_block = 0;
459
+ next;
460
+ }
461
+ # Each certificate has a main block.
462
+ elsif(/^# Certificate "(.*)"/) {
463
+ (!$main_block && !$trust_block) or die "Unexpected certificate block";
464
+ $main_block = 1;
465
+ $main_block_name = $1;
466
+ # Reset all other certificate variables.
467
+ $trust_block = 0;
468
+ $trust_block_name = "";
469
+ $valid = 0;
470
+ $start_of_cert = 0;
471
+ $caname = "";
472
+ $cka_value = "";
473
+ undef @precert;
474
+ next;
475
+ }
476
+ # Each certificate's main block is followed by a trust block.
477
+ elsif(/^# Trust for (?:Certificate )?"(.*)"/) {
478
+ (!$main_block && !$trust_block) or die "Unexpected trust block";
479
+ $trust_block = 1;
480
+ $trust_block_name = $1;
481
+ if($main_block_name ne $trust_block_name) {
482
+ die "cert name \"$main_block_name\" != trust name \"$trust_block_name\"";
483
+ }
484
+ next;
485
+ }
486
+ # Ignore other blocks.
487
+ #
488
+ # There is a documentation comment block, a BEGINDATA block, and a bunch of
489
+ # blocks starting with "# Explicitly Distrust <certname>".
490
+ #
491
+ # The latter is for certificates that have already been removed and are not
492
+ # included. Not all explicitly distrusted certificates are ignored at this
493
+ # point, just those without an actual certificate.
494
+ elsif(!$main_block && !$trust_block) {
495
+ next;
496
+ }
497
+ elsif(/^#/) {
498
+ # The commented lines in a main block are plaintext metadata that describes
499
+ # the certificate. Issuer, Subject, Fingerprint, etc.
500
+ if($main_block) {
501
+ push @precert, $_ if not /^#$/;
502
+ if(/^# Not Valid After : (.*)/) {
503
+ my $stamp = $1;
504
+ use Time::Piece;
505
+ # Not Valid After : Thu Sep 30 14:01:15 2021
506
+ my $t = Time::Piece->strptime($stamp, "%a %b %d %H:%M:%S %Y");
507
+ my $delta = ($t->epoch - time()); # negative means no longer valid
508
+ if($delta < 0) {
509
+ $skipnum++;
510
+ report "Skipping: $main_block_name is not valid anymore" if ($opt_v);
511
+ $valid = 0;
512
+ }
513
+ else {
514
+ $valid = 1;
515
+ }
516
+ }
517
+ }
518
+ next;
519
+ }
520
+ elsif(!$valid) {
521
+ next;
522
+ }
523
+
524
+ chomp;
525
+
526
+ if($main_block) {
527
+ if(/^CKA_CLASS CK_OBJECT_CLASS CKO_CERTIFICATE/) {
528
+ !$start_of_cert or die "Duplicate CKO_CERTIFICATE object";
529
+ $start_of_cert = 1;
530
+ next;
531
+ }
532
+ elsif(!$start_of_cert) {
533
+ next;
534
+ }
535
+ elsif(/^CKA_LABEL UTF8 \"(.*)\"/) {
536
+ ($caname eq "") or die "Duplicate CKA_LABEL attribute";
537
+ $caname = $1;
538
+ if($caname ne $main_block_name) {
539
+ die "caname \"$caname\" != cert name \"$main_block_name\"";
540
+ }
541
+ next;
542
+ }
543
+ elsif(/^CKA_VALUE MULTILINE_OCTAL/) {
544
+ ($cka_value eq "") or die "Duplicate CKA_VALUE attribute";
545
+ while (<TXT>) {
546
+ last if (/^END/);
547
+ chomp;
548
+ my @octets = split(/\\/);
549
+ shift @octets;
550
+ for (@octets) {
551
+ $cka_value .= chr(oct);
552
+ }
553
+ }
554
+ next;
555
+ }
556
+ else {
557
+ next;
558
+ }
559
+ }
560
+
561
+ if(!$trust_block || !$start_of_cert || $caname eq "" || $cka_value eq "") {
562
+ die "Certificate extraction failed";
563
+ }
564
+
565
+ my %trust_purposes_by_level;
566
+
567
+ if(/^CKA_CLASS CK_OBJECT_CLASS CKO_NSS_TRUST/) {
568
+ # now scan the trust part to determine how we should trust this cert
569
+ while (<TXT>) {
570
+ if(/^\s*$/) {
571
+ $trust_block = 0;
572
+ last;
573
+ }
574
+ if (/^CKA_TRUST_([A-Z_]+)\s+CK_TRUST\s+CKT_NSS_([A-Z_]+)\s*$/) {
575
+ if ( !is_in_list($1,@valid_mozilla_trust_purposes) ) {
576
+ report "Warning: Unrecognized trust purpose for cert: $caname. Trust purpose: $1. Trust Level: $2";
577
+ } elsif ( !is_in_list($2,@valid_mozilla_trust_levels) ) {
578
+ report "Warning: Unrecognized trust level for cert: $caname. Trust purpose: $1. Trust Level: $2";
579
+ } else {
580
+ push @{$trust_purposes_by_level{$2}}, $1;
581
+ }
582
+ }
583
+ }
584
+
585
+ # Sanity check that an explicitly distrusted certificate only has trust
586
+ # purposes with a trust level of NOT_TRUSTED.
587
+ #
588
+ # Certificate objects that are explicitly distrusted are in a certificate
589
+ # block that starts # Certificate "Explicitly Distrust(ed) <certname>",
590
+ # where "Explicitly Distrust(ed) " was prepended to the original cert name.
591
+ if($caname =~ /distrust/i ||
592
+ $main_block_name =~ /distrust/i ||
593
+ $trust_block_name =~ /distrust/i) {
594
+ my @levels = keys %trust_purposes_by_level;
595
+ if(scalar(@levels) != 1 || $levels[0] ne "NOT_TRUSTED") {
596
+ die "\"$caname\" must have all trust purposes at level NOT_TRUSTED.";
597
+ }
598
+ }
599
+
600
+ if ( !should_output_cert(%trust_purposes_by_level) ) {
601
+ $skipnum ++;
602
+ report "Skipping: $caname lacks acceptable trust level" if ($opt_v);
603
+ } else {
604
+ my $encoded = MIME::Base64::encode_base64($cka_value, '');
605
+ $encoded =~ s/(.{1,${opt_w}})/$1\n/g;
606
+ my $pem = "-----BEGIN CERTIFICATE-----\n"
607
+ . $encoded
608
+ . "-----END CERTIFICATE-----\n";
609
+ print CRT "\n$caname\n";
610
+ my $maxStringLength = length(decode('UTF-8', $caname, Encode::FB_CROAK | Encode::LEAVE_SRC));
611
+ print CRT ("=" x $maxStringLength . "\n");
612
+ if ($opt_t) {
613
+ foreach my $key (sort keys %trust_purposes_by_level) {
614
+ my $string = $key . ": " . join(", ", @{$trust_purposes_by_level{$key}});
615
+ print CRT $string . "\n";
616
+ }
617
+ }
618
+ if($opt_m) {
619
+ print CRT for @precert;
620
+ }
621
+ if (!$opt_t) {
622
+ print CRT $pem;
623
+ } else {
624
+ my $pipe = "";
625
+ foreach my $hash (@included_signature_algorithms) {
626
+ $pipe = "|$openssl x509 -" . $hash . " -fingerprint -noout -inform PEM";
627
+ if (!$stdout) {
628
+ $pipe .= " >> $crt.~";
629
+ close(CRT) or die "Couldn't close $crt.~: $!";
630
+ }
631
+ open(TMP, $pipe) or die "Couldn't open openssl pipe: $!";
632
+ print TMP $pem;
633
+ close(TMP) or die "Couldn't close openssl pipe: $!";
634
+ if (!$stdout) {
635
+ open(CRT, ">>$crt.~") or die "Couldn't open $crt.~: $!";
636
+ }
637
+ }
638
+ $pipe = "|$openssl x509 -text -inform PEM";
639
+ if (!$stdout) {
640
+ $pipe .= " >> $crt.~";
641
+ close(CRT) or die "Couldn't close $crt.~: $!";
642
+ }
643
+ open(TMP, $pipe) or die "Couldn't open openssl pipe: $!";
644
+ print TMP $pem;
645
+ close(TMP) or die "Couldn't close openssl pipe: $!";
646
+ if (!$stdout) {
647
+ open(CRT, ">>$crt.~") or die "Couldn't open $crt.~: $!";
648
+ }
649
+ }
650
+ report "Processed: $caname" if ($opt_v);
651
+ $certnum ++;
652
+ }
653
+ }
654
+ }
655
+ close(TXT) or die "Couldn't close $txt: $!\n";
656
+ close(CRT) or die "Couldn't close $crt.~: $!\n";
657
+ unless( $stdout ) {
658
+ if ($opt_b && -e $crt) {
659
+ my $bk = 1;
660
+ while (-e "$crt.~${bk}~") {
661
+ $bk++;
662
+ }
663
+ rename $crt, "$crt.~${bk}~" or die "Failed to create backup $crt.~$bk}~: $!\n";
664
+ } elsif( -e $crt ) {
665
+ unlink( $crt ) or die "Failed to remove $crt: $!\n";
666
+ }
667
+ rename "$crt.~", $crt or die "Failed to rename $crt.~ to $crt: $!\n";
668
+ }
669
+ if($opt_u && -e $txt && !unlink($txt)) {
670
+ report "Failed to remove $txt: $!\n";
671
+ }
672
+ report "Done ($certnum CA certs processed, $skipnum skipped).";
local-test-curl-delta-01/afc-curl/scripts/mk-unity.pl ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Viktor Szakats
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # Helper script for "unity"-like support in autotools, to generate the umbrella
27
+ # C source that includes the individual source files. Reads Makefile.inc and
28
+ # accepts the variable name containing all the source files to include. Also
29
+ # allow a list of exceptions that are to be excluded from the generated file.
30
+
31
+ use strict;
32
+ use warnings;
33
+
34
+ if(!@ARGV) {
35
+ die "Usage: $0 [<c-sources>] [--exclude <exclude-c-sources>]\n";
36
+ }
37
+
38
+ # Specific sources to exclude or add as an extra source file
39
+ my @src;
40
+ my %exclude;
41
+ my $in_exclude = 0;
42
+ foreach my $src (@ARGV) {
43
+ if($in_exclude) {
44
+ $exclude{$src} = 1;
45
+ }
46
+ elsif($src eq "--exclude") {
47
+ $in_exclude = 1;
48
+ }
49
+ else {
50
+ push @src, $src;
51
+ }
52
+ }
53
+
54
+ print <<HEADER
55
+ /* !checksrc! disable COPYRIGHT all */
56
+ HEADER
57
+ ;
58
+
59
+ foreach my $src (@src) {
60
+ if($src =~ /\.c$/g && !exists $exclude{$src}) {
61
+ print "#include \"$src\"\n";
62
+ }
63
+ }
local-test-curl-delta-01/afc-curl/scripts/nroff2cd ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ =begin comment
27
+
28
+ This script converts an nroff file to curldown
29
+
30
+ Example: cd2nroff [options] <file.md> > <file.3>
31
+
32
+ Note: when converting .nf sections, this tool does not know if the
33
+ section is code or just regular quotes. It then assumes and uses ~~~c
34
+ for code.
35
+
36
+ =end comment
37
+ =cut
38
+
39
+ my $nroff2cd = "0.1"; # to keep check
40
+
41
+ sub single {
42
+ my ($f)=@_;
43
+ open(F, "<:crlf", "$f") ||
44
+ return 1;
45
+ my $line;
46
+ my $title;
47
+ my $section;
48
+ my $source;
49
+ my @seealso;
50
+ my @desc;
51
+ my $header; # non-zero when TH is passed
52
+ my $quote = 0; # quote state
53
+ while(<F>) {
54
+ $line++;
55
+ my $d = $_;
56
+ if($_ =~ /^.\\\"/) {
57
+ # a comment we can ignore
58
+ next;
59
+ }
60
+ if(!$header) {
61
+ if($d =~ /.so (.*)/) {
62
+ # this is basically an include, so do that
63
+ my $f = $1;
64
+ # remove leading directory
65
+ $f =~ s/(.*?\/)//;
66
+ close(F);
67
+ open(F, "<:crlf", "$f") || return 1;
68
+ }
69
+ if($d =~ /^\.TH ([^ ]*) (\d) \"(.*?)\" ([^ \n]*)/) {
70
+ # header, this needs to be the first thing after leading comments
71
+ $title = $1;
72
+ $section = $2;
73
+ # date is $3
74
+ $source = $4;
75
+ # if there are enclosing quotes around source, remove them
76
+ $source =~ s/[\"\'](.*)[\"\']\z/$1/;
77
+ $header = 1;
78
+
79
+ print <<HEAD
80
+ ---
81
+ c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
82
+ SPDX-License-Identifier: curl
83
+ Title: $title
84
+ Section: $section
85
+ Source: $source
86
+ HEAD
87
+ ;
88
+ }
89
+ next;
90
+ }
91
+
92
+ if($quote) {
93
+ if($d =~ /^\.SH/) {
94
+ #end of quote without an .fi
95
+ $quote = 0;
96
+ push @desc, "~~~\n";
97
+ }
98
+ elsif($d =~ /^\.fi/) {
99
+ #end of quote
100
+ $quote = 0;
101
+ push @desc, "~~~\n";
102
+ next;
103
+ }
104
+ else {
105
+ # double-backslashes converted to single ones
106
+ $d =~ s/\\\\/\\/g;
107
+ push @desc, $d;
108
+ next;
109
+ }
110
+ }
111
+ if($d =~ /^\.SH (.*)/) {
112
+ my $word = $1;
113
+ # if there are enclosing quotes, remove them first
114
+ $word =~ s/[\"\'](.*)[\"\']\z/$1/;
115
+ if($word eq "SEE ALSO") {
116
+ # we just slurp up this section
117
+ next;
118
+ }
119
+ push @desc, "\n# $word\n\n";
120
+ }
121
+ elsif($d =~ /^\.(RS|RE)/) {
122
+ # ignore these
123
+ }
124
+ elsif($d =~ /^\.IP (.*)/) {
125
+ my $word = $1;
126
+ # if there are enclosing quotes, remove them first
127
+ $word =~ s/[\"\'](.*)[\"\']\z/$1/;
128
+ push @desc, "\n## $word\n\n";
129
+ }
130
+ elsif($d =~ /^\.IP/) {
131
+ # .IP with no text we just skip
132
+ }
133
+ elsif($d =~ /^\.BR (.*)/) {
134
+ # only used for SEE ALSO
135
+ my $word = $1;
136
+ # remove trailing comma
137
+ $word =~ s/,\z//;
138
+
139
+ for my $s (split(/,/, $word)) {
140
+ # remove all double quotes
141
+ $s =~ s/\"//g;
142
+ # tream leading whitespace
143
+ $s =~ s/^ +//g;
144
+ push @seealso, $s;
145
+ }
146
+ }
147
+ elsif($d =~ /^\.I (.*)/) {
148
+ push @desc, "*$1*\n";
149
+ }
150
+ elsif($d =~ /^\.B (.*)/) {
151
+ push @desc, "**$1**\n";
152
+ }
153
+ elsif($d =~ /^\.nf/) {
154
+ push @desc, "~~~c\n";
155
+ $quote = 1;
156
+ }
157
+ else {
158
+ # embolden
159
+ $d =~ s/\\fB(.*?)\\fP/**$1**/g;
160
+ # links to "curl.*()" are left bare since cd2nroff handles them
161
+ # specially
162
+ $d =~ s/\\fI(curl.*?\(3\))\\fP/$1/ig;
163
+ # emphasize
164
+ $d =~ s/\\fI(.*?)\\fP/*$1*/g;
165
+ # emphasize on a split line
166
+ $d =~ s/\\fI/*/g;
167
+ # bold on a split line
168
+ $d =~ s/\\fB/**/g;
169
+ # remove backslash amp
170
+ $d =~ s/\\&//g;
171
+ # remove backslashes
172
+ $d =~ s/\\//g;
173
+ # fix single quotes
174
+ $d =~ s/\(aq/'/g;
175
+ # fix double quotes
176
+ $d =~ s/\(dq/\"/g;
177
+ push @desc, $d;
178
+ }
179
+ }
180
+ close(F);
181
+
182
+ print "See-also:\n";
183
+ for my $s (sort @seealso) {
184
+ print " - $s\n" if($s);
185
+ }
186
+ print "---\n";
187
+ print @desc;
188
+
189
+ return !$header;
190
+ }
191
+
192
+ exit single($ARGV[0]);
local-test-curl-delta-01/afc-curl/scripts/release-notes.pl ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ ###############################################
27
+ #
28
+ # ==== How to use this script ====
29
+ #
30
+ # 1. Get recent commits added to RELEASE-NOTES:
31
+ #
32
+ # $ ./scripts/release-notes.pl
33
+ #
34
+ # 2. Edit RELEASE-NOTES and remove all entries that don't belong. Unused
35
+ # references below will be cleaned up in the next step. Make sure to move
36
+ # "changes" up to the changes section. All entries will by default be listed
37
+ # under bug-fixes as this script can't know where to put them.
38
+ #
39
+ # 3. Run the cleanup script and let it sort the entries and remove unused
40
+ # references from lines you removed in step (2):
41
+ #
42
+ # $ ./scripts/release-notes.pl cleanup
43
+ #
44
+ # 4. Reload RELEASE-NOTES and verify that things look okay. The cleanup
45
+ # procedure can and should be re-run when lines are removed or rephrased.
46
+ #
47
+ # 5. Run ./scripts/contributors.sh and update the contributor list of names
48
+ # The list can also be extended or edited manually.
49
+ #
50
+ # 6. Run ./scripts/delta and update the contributor count at the top, and
51
+ # double-check/update the other counters.
52
+ #
53
+ # 7. Commit the file using "RELEASE-NOTES: synced" as commit message.
54
+ #
55
+ ################################################
56
+
57
+ my $cleanup = ($ARGV[0] eq "cleanup");
58
+ my @gitlog=`git log @^{/RELEASE-NOTES:.synced}..` if(!$cleanup);
59
+ my @releasenotes=`cat RELEASE-NOTES`;
60
+
61
+ my @o; # the entire new RELEASE-NOTES
62
+ my @refused; # [num] = [2 bits of use info]
63
+ my @refs; # [number] = [URL]
64
+ for my $l (@releasenotes) {
65
+ if($l =~ /^ o .*\[(\d+)\]/) {
66
+ # referenced, set bit 0
67
+ $refused[$1]=1;
68
+ }
69
+ elsif($l =~ /^ \[(\d+)\] = (.*)/) {
70
+ # listed in a reference, set bit 1
71
+ $refused[$1] |= 2;
72
+ $refs[$1] = $2;
73
+ }
74
+ }
75
+
76
+ # Return a new fresh reference number
77
+ sub getref {
78
+ for my $r (1 .. $#refs) {
79
+ if(!$refused[$r] & 1) {
80
+ return $r;
81
+ }
82
+ }
83
+ # add at the end
84
+ return $#refs + 1;
85
+ }
86
+
87
+ # '#num'
88
+ # 'num'
89
+ # 'https://github.com/curl/curl/issues/6939'
90
+ # 'https://github.com/curl/curl-www/issues/69'
91
+ # 'https://elsewhere.example.com/discussion'
92
+
93
+ sub extract {
94
+ my ($ref)=@_;
95
+ if($ref =~ /^(\#|)(\d+)/) {
96
+ # return the plain number
97
+ return $2;
98
+ }
99
+ elsif($ref =~ /^https:\/\/github.com\/curl\/curl\/.*\/(\d+)/) {
100
+ # return the plain number
101
+ return $1;
102
+ }
103
+ elsif($ref =~ /:\/\//) {
104
+ # contains a '://', return the URL
105
+ return $ref;
106
+ }
107
+ # false alarm, not a valid line
108
+ }
109
+
110
+ my $short;
111
+ my $first;
112
+ for my $l (@gitlog) {
113
+ chomp $l;
114
+ if($l =~ /^commit/) {
115
+ if($first) {
116
+ onecommit($short);
117
+ }
118
+ # starts a new commit
119
+ undef @fixes;
120
+ undef @closes;
121
+ undef @bug;
122
+ $short = "";
123
+ $first = 0;
124
+ }
125
+ elsif(($l =~ /^ (.*)/) && !$first) {
126
+ # first line
127
+ $short = $1;
128
+ $short =~ s/ ?\[(ci skip|skip ci)\]//g;
129
+ $first = 1;
130
+ push @line, $short;
131
+ }
132
+ elsif(($l =~ /^ (.*)/) && $first) {
133
+ # not the first
134
+ my $line = $1;
135
+
136
+ if($line =~ /^Fixes(:|) *(.*)/i) {
137
+ my $ref = extract($2);
138
+ push @fixes, $ref if($ref);
139
+ }
140
+ elsif($line =~ /^Clo(s|)es(:|) *(.*)/i) {
141
+ my $ref = extract($3);
142
+ push @closes, $ref if($ref);
143
+ }
144
+ elsif($line =~ /^Bug: (.*)/i) {
145
+ my $ref = extract($1);
146
+ push @bug, $ref if($ref);
147
+ }
148
+ }
149
+ }
150
+ if($first) {
151
+ onecommit($short);
152
+ }
153
+
154
+ # call at the end of a parsed commit
155
+ sub onecommit {
156
+ my ($short)=@_;
157
+ my $ref;
158
+
159
+ if($bug[0]) {
160
+ $ref = $bug[0];
161
+ }
162
+ elsif($fixes[0]) {
163
+ $ref = $fixes[0];
164
+ }
165
+ elsif($closes[0]) {
166
+ $ref = $closes[0];
167
+ }
168
+
169
+ if($ref =~ /^#?(\d+)/) {
170
+ $ref = "https://curl.se/bug/?i=$1"
171
+ }
172
+ if($ref) {
173
+ my $r = getref();
174
+ $refs[$r] = $ref;
175
+ $moreinfo{$short}=$r;
176
+ $refused[$r] |= 1;
177
+ }
178
+ }
179
+
180
+ #### Output the new RELEASE-NOTES
181
+
182
+ my @bullets;
183
+ for my $l (@releasenotes) {
184
+ if(($l =~ /^This release includes the following bugfixes:/) && !$cleanup) {
185
+ push @o, $l;
186
+ push @o, "\n";
187
+ for my $f (@line) {
188
+ push @o, sprintf " o %s%s\n", $f,
189
+ $moreinfo{$f}? sprintf(" [%d]", $moreinfo{$f}): "";
190
+ $refused[$moreinfo{$f}]=3;
191
+ }
192
+ push @o, " --- new entries are listed above this ---";
193
+ next;
194
+ }
195
+ elsif($cleanup) {
196
+ if($l =~ /^ --- new entries are listed/) {
197
+ # ignore this if still around
198
+ next;
199
+ }
200
+ elsif($l =~ /^ o .*/) {
201
+ push @bullets, $l;
202
+ next;
203
+ }
204
+ elsif($bullets[0]) {
205
+ # output them case insensitively
206
+ for my $b (sort { "\L$a" cmp "\L$b" } @bullets) {
207
+ push @o, $b;
208
+ }
209
+ undef @bullets;
210
+ }
211
+ }
212
+ if($l =~ /^ \[(\d+)\] = /) {
213
+ # stop now
214
+ last;
215
+ }
216
+ else {
217
+ push @o, $l;
218
+ }
219
+ }
220
+
221
+ my @srefs;
222
+ my $ln;
223
+ for my $n (1 .. $#refs) {
224
+ my $r = $refs[$n];
225
+ if($r && ($refused[$n] & 1)) {
226
+ push @o, sprintf " [%d] = %s\n", $n, $r;
227
+ }
228
+ }
229
+
230
+ open(O, ">RELEASE-NOTES");
231
+ for my $l (@o) {
232
+ print O $l;
233
+ }
234
+ close(O);
235
+
236
+ exit;
237
+
238
+ # Debug: show unused references
239
+ for my $r (1 .. $#refs) {
240
+ if($refused[$r] != 3) {
241
+ printf "%s is %d!\n", $r, $refused[$r];
242
+ }
243
+ }
local-test-curl-delta-01/afc-curl/scripts/release-tools.sh ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ set -eu
27
+
28
+ # this should ideally be passed in
29
+ timestamp=${1:-unknown}
30
+ version=${2:-unknown}
31
+ tag=$(echo "curl-$version" | tr '.' '_')
32
+ commit=${3}
33
+ if [ -n "$commit" ] && [ -r "docs/tarball-commit.txt.dist" ]; then
34
+ # If commit is given, then the tag likely doesn't actually exist
35
+ tag="$(cat docs/tarball-commit.txt.dist)"
36
+ fi
37
+
38
+ cat <<MOO
39
+ # Release tools used for curl $version
40
+
41
+ The following tools and their Debian package version numbers were used to
42
+ produce this release tarball.
43
+
44
+ MOO
45
+
46
+ if ! command -v dpkg >/dev/null; then
47
+ echo "Error: could not find dpkg" >&2
48
+ exit 1
49
+ fi
50
+
51
+ debian() {
52
+ echo "- $1: $(dpkg -l "$1" | grep ^ii | awk '{print $3}')"
53
+ }
54
+ debian autoconf
55
+ debian automake
56
+ debian libtool
57
+ debian make
58
+ debian perl
59
+ debian git
60
+
61
+ cat <<MOO
62
+
63
+ # Reproduce the tarball
64
+
65
+ - Clone the repo and checkout the tag/commit: $tag
66
+ - Install the same set of tools + versions as listed above
67
+
68
+ ## Do a standard build
69
+
70
+ - autoreconf -fi
71
+ - ./configure [...]
72
+ - make
73
+
74
+ ## Generate the tarball with the same timestamp
75
+
76
+ - export SOURCE_DATE_EPOCH=$timestamp
77
+ - ./scripts/maketgz [version]
78
+
79
+ MOO
local-test-curl-delta-01/afc-curl/scripts/schemetable.c ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+ #include <stdio.h>
25
+ #include <curl/curl.h>
26
+
27
+ /*
28
+ * Use this tool to generate an updated table for the Curl_getn_scheme_handler
29
+ * function in url.c.
30
+ */
31
+
32
+ struct detail {
33
+ const char *n;
34
+ const char *ifdef;
35
+ };
36
+
37
+ static const struct detail scheme[] = {
38
+ {"dict", "#ifndef CURL_DISABLE_DICT" },
39
+ {"file", "#ifndef CURL_DISABLE_FILE" },
40
+ {"ftp", "#ifndef CURL_DISABLE_FTP" },
41
+ {"ftps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)" },
42
+ {"gopher", "#ifndef CURL_DISABLE_GOPHER" },
43
+ {"gophers", "#if defined(USE_SSL) && !defined(CURL_DISABLE_GOPHER)" },
44
+ {"http", "#ifndef CURL_DISABLE_HTTP" },
45
+ {"https", "#if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)" },
46
+ {"imap", "#ifndef CURL_DISABLE_IMAP" },
47
+ {"imaps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)" },
48
+ {"ldap", "#ifndef CURL_DISABLE_LDAP" },
49
+ {"ldaps", "#if !defined(CURL_DISABLE_LDAP) && \\\n"
50
+ " !defined(CURL_DISABLE_LDAPS) && \\\n"
51
+ " ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \\\n"
52
+ " (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))" },
53
+ {"mqtt", "#ifndef CURL_DISABLE_MQTT" },
54
+ {"pop3", "#ifndef CURL_DISABLE_POP3" },
55
+ {"pop3s", "#if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)" },
56
+ {"rtmp", "#ifdef USE_LIBRTMP" },
57
+ {"rtmpt", "#ifdef USE_LIBRTMP" },
58
+ {"rtmpe", "#ifdef USE_LIBRTMP" },
59
+ {"rtmpte", "#ifdef USE_LIBRTMP" },
60
+ {"rtmps", "#ifdef USE_LIBRTMP" },
61
+ {"rtmpts", "#ifdef USE_LIBRTMP" },
62
+ {"rtsp", "#ifndef CURL_DISABLE_RTSP" },
63
+ {"scp", "#if defined(USE_SSH) && !defined(USE_WOLFSSH)" },
64
+ {"sftp", "#if defined(USE_SSH)" },
65
+ {"smb", "#if !defined(CURL_DISABLE_SMB) && \\\n"
66
+ " defined(USE_CURL_NTLM_CORE) && (SIZEOF_CURL_OFF_T > 4)" },
67
+ {"smbs", "#if defined(USE_SSL) && !defined(CURL_DISABLE_SMB) && \\\n"
68
+ " defined(USE_CURL_NTLM_CORE) && (SIZEOF_CURL_OFF_T > 4)" },
69
+ {"smtp", "#ifndef CURL_DISABLE_SMTP" },
70
+ {"smtps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)" },
71
+ {"telnet", "#ifndef CURL_DISABLE_TELNET" },
72
+ {"tftp", "#ifndef CURL_DISABLE_TFTP" },
73
+ {"ws",
74
+ "#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)" },
75
+ {"wss", "#if !defined(CURL_DISABLE_WEBSOCKETS) && \\\n"
76
+ " defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)" },
77
+ { NULL, NULL }
78
+ };
79
+
80
+ unsigned int calc(const char *s, int add, int shift)
81
+ {
82
+ const char *so = s;
83
+ unsigned int c = add;
84
+ while(*s) {
85
+ c <<= shift;
86
+ c += *s;
87
+ s++;
88
+ }
89
+ return c;
90
+ }
91
+
92
+ unsigned int num[100];
93
+ unsigned int ix[100];
94
+
95
+ static void showtable(int try, int init, int shift)
96
+ {
97
+ int nulls = 0;
98
+ int i;
99
+ for(i = 0; scheme[i].n; ++i)
100
+ num[i] = calc(scheme[i].n, init, shift);
101
+ for(i = 0; scheme[i].n; ++i)
102
+ ix[i] = num[i] % try;
103
+ printf("/*\n"
104
+ " unsigned int c = %d\n"
105
+ " while(l) {\n"
106
+ " c <<= %d;\n"
107
+ " c += Curl_raw_tolower(*s);\n"
108
+ " s++;\n"
109
+ " l--;\n"
110
+ " }\n"
111
+ "*/\n", init, shift);
112
+
113
+ printf(" static const struct Curl_handler * const protocols[%d] = {", try);
114
+
115
+ /* generate table */
116
+ for(i = 0; i < try; i++) {
117
+ int match = 0;
118
+ int j;
119
+ for(j = 0; scheme[j].n; j++) {
120
+ if(ix[j] == i) {
121
+ printf("\n");
122
+ printf("%s\n", scheme[j].ifdef);
123
+ printf(" &Curl_handler_%s,\n", scheme[j].n);
124
+ printf("#else\n NULL,\n");
125
+ printf("#endif");
126
+ match = 1;
127
+ nulls = 0;
128
+ break;
129
+ }
130
+ }
131
+ if(!match) {
132
+ if(!nulls || (nulls > 10)) {
133
+ printf("\n ");
134
+ nulls = 0;
135
+ }
136
+ printf(" NULL,", nulls);
137
+ nulls++;
138
+ }
139
+ }
140
+ printf("\n };\n");
141
+ }
142
+
143
+ int main(void)
144
+ {
145
+ int i;
146
+ int try;
147
+ int besttry = 9999;
148
+ int bestadd = 0;
149
+ int bestshift = 0;
150
+ int add;
151
+ int shift;
152
+ for(shift = 0; shift < 8; shift++) {
153
+ for(add = 0; add < 999; add++) {
154
+ for(i = 0; scheme[i].n; ++i) {
155
+ unsigned int v = calc(scheme[i].n, add, shift);
156
+ int j;
157
+ int badcombo = 0;
158
+ for(j = 0; j < i; j++) {
159
+
160
+ if(num[j] == v) {
161
+ /*
162
+ printf("NOPE: %u is a dupe (%s and %s)\n",
163
+ v, scheme[i], scheme[j]);
164
+ */
165
+ badcombo = 1;
166
+ break;
167
+ }
168
+ }
169
+ if(badcombo)
170
+ break;
171
+ num[i] = v;
172
+ }
173
+ #if 0
174
+ for(i = 0; scheme[i].n; ++i) {
175
+ printf("%u - %s\n", num[i], scheme[i].n);
176
+ }
177
+ #endif
178
+ /* try different remainders to find smallest possible table */
179
+ for(try = 28; try < 199; try++) {
180
+ int good = 1;
181
+ for(i = 0; scheme[i].n; ++i) {
182
+ ix[i] = num[i] % try;
183
+ }
184
+ /* check for dupes */
185
+ for(i = 0; scheme[i].n && good; ++i) {
186
+ int j;
187
+ for(j = 0; j < i; j++) {
188
+ if(ix[j] == ix[i]) {
189
+ good = 0;
190
+ break;
191
+ }
192
+ }
193
+ }
194
+ if(good) {
195
+ if(try < besttry) {
196
+ besttry = try;
197
+ bestadd = add;
198
+ bestshift = shift;
199
+ }
200
+ break;
201
+ }
202
+ }
203
+ }
204
+ }
205
+
206
+ showtable(besttry, bestadd, bestshift);
207
+ }
local-test-curl-delta-01/afc-curl/scripts/singleuse.pl ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+ #
26
+ # This script is aimed to help scan for and detect globally declared functions
27
+ # that are not used from other source files.
28
+ #
29
+ # Use it like this:
30
+ #
31
+ # $ ./scripts/singleuse.pl [--unit] lib/.libs/libcurl.a
32
+ #
33
+ # --unit : built to support unit tests
34
+ #
35
+
36
+ my $unittests;
37
+ if($ARGV[0] eq "--unit") {
38
+ $unittests = "tests/unit ";
39
+ shift @ARGV;
40
+ }
41
+
42
+ my $file = $ARGV[0];
43
+
44
+ my %wl = (
45
+ 'curlx_uztoso' => 'cmdline tool use',
46
+ 'Curl_xfer_write_resp' => 'internal api',
47
+ 'Curl_creader_def_init' => 'internal api',
48
+ 'Curl_creader_def_close' => 'internal api',
49
+ 'Curl_creader_def_read' => 'internal api',
50
+ 'Curl_creader_def_total_length' => 'internal api',
51
+ );
52
+
53
+ my %api = (
54
+ 'curl_easy_cleanup' => 'API',
55
+ 'curl_easy_duphandle' => 'API',
56
+ 'curl_easy_escape' => 'API',
57
+ 'curl_easy_getinfo' => 'API',
58
+ 'curl_easy_init' => 'API',
59
+ 'curl_easy_pause' => 'API',
60
+ 'curl_easy_perform' => 'API',
61
+ 'curl_easy_recv' => 'API',
62
+ 'curl_easy_reset' => 'API',
63
+ 'curl_easy_send' => 'API',
64
+ 'curl_easy_setopt' => 'API',
65
+ 'curl_easy_strerror' => 'API',
66
+ 'curl_easy_unescape' => 'API',
67
+ 'curl_easy_upkeep' => 'API',
68
+ 'curl_easy_option_by_id' => 'API',
69
+ 'curl_easy_option_by_name' => 'API',
70
+ 'curl_easy_option_next' => 'API',
71
+ 'curl_escape' => 'API',
72
+ 'curl_formadd' => 'API',
73
+ 'curl_formfree' => 'API',
74
+ 'curl_formget' => 'API',
75
+ 'curl_free' => 'API',
76
+ 'curl_getdate' => 'API',
77
+ 'curl_getenv' => 'API',
78
+ 'curl_global_cleanup' => 'API',
79
+ 'curl_global_init' => 'API',
80
+ 'curl_global_init_mem' => 'API',
81
+ 'curl_global_sslset' => 'API',
82
+ 'curl_global_trace' => 'API',
83
+ 'curl_maprintf' => 'API',
84
+ 'curl_mfprintf' => 'API',
85
+ 'curl_mime_addpart' => 'API',
86
+ 'curl_mime_data' => 'API',
87
+ 'curl_mime_data_cb' => 'API',
88
+ 'curl_mime_encoder' => 'API',
89
+ 'curl_mime_filedata' => 'API',
90
+ 'curl_mime_filename' => 'API',
91
+ 'curl_mime_free' => 'API',
92
+ 'curl_mime_headers' => 'API',
93
+ 'curl_mime_init' => 'API',
94
+ 'curl_mime_name' => 'API',
95
+ 'curl_mime_subparts' => 'API',
96
+ 'curl_mime_type' => 'API',
97
+ 'curl_mprintf' => 'API',
98
+ 'curl_msnprintf' => 'API',
99
+ 'curl_msprintf' => 'API',
100
+ 'curl_multi_add_handle' => 'API',
101
+ 'curl_multi_assign' => 'API',
102
+ 'curl_multi_cleanup' => 'API',
103
+ 'curl_multi_fdset' => 'API',
104
+ 'curl_multi_get_handles' => 'API',
105
+ 'curl_multi_info_read' => 'API',
106
+ 'curl_multi_init' => 'API',
107
+ 'curl_multi_perform' => 'API',
108
+ 'curl_multi_remove_handle' => 'API',
109
+ 'curl_multi_setopt' => 'API',
110
+ 'curl_multi_socket' => 'API',
111
+ 'curl_multi_socket_action' => 'API',
112
+ 'curl_multi_socket_all' => 'API',
113
+ 'curl_multi_poll' => 'API',
114
+ 'curl_multi_strerror' => 'API',
115
+ 'curl_multi_timeout' => 'API',
116
+ 'curl_multi_wait' => 'API',
117
+ 'curl_multi_waitfds' => 'API',
118
+ 'curl_multi_wakeup' => 'API',
119
+ 'curl_mvaprintf' => 'API',
120
+ 'curl_mvfprintf' => 'API',
121
+ 'curl_mvprintf' => 'API',
122
+ 'curl_mvsnprintf' => 'API',
123
+ 'curl_mvsprintf' => 'API',
124
+ 'curl_pushheader_byname' => 'API',
125
+ 'curl_pushheader_bynum' => 'API',
126
+ 'curl_share_cleanup' => 'API',
127
+ 'curl_share_init' => 'API',
128
+ 'curl_share_setopt' => 'API',
129
+ 'curl_share_strerror' => 'API',
130
+ 'curl_slist_append' => 'API',
131
+ 'curl_slist_free_all' => 'API',
132
+ 'curl_strequal' => 'API',
133
+ 'curl_strnequal' => 'API',
134
+ 'curl_unescape' => 'API',
135
+ 'curl_url' => 'API',
136
+ 'curl_url_cleanup' => 'API',
137
+ 'curl_url_dup' => 'API',
138
+ 'curl_url_get' => 'API',
139
+ 'curl_url_set' => 'API',
140
+ 'curl_url_strerror' => 'API',
141
+ 'curl_version' => 'API',
142
+ 'curl_version_info' => 'API',
143
+ 'curl_easy_header' => 'API',
144
+ 'curl_easy_nextheader' => 'API',
145
+ 'curl_ws_meta' => 'API',
146
+ 'curl_ws_recv' => 'API',
147
+ 'curl_ws_send' => 'API',
148
+
149
+ # the following functions are provided globally in debug builds
150
+ 'curl_easy_perform_ev' => 'debug-build',
151
+ );
152
+
153
+ sub doublecheck {
154
+ my ($f, $used) = @_;
155
+ open(F, "git grep -Fwle '$f' -- lib ${unittests}packages|");
156
+ my @also;
157
+ while(<F>) {
158
+ my $e = $_;
159
+ chomp $e;
160
+ if($e =~ /\.[c]$/) {
161
+ if($e !~ /^lib\/${used}\.c/) {
162
+ push @also, $e;
163
+ }
164
+ }
165
+ }
166
+ close(F);
167
+ return @also;
168
+ }
169
+
170
+ open(N, "nm $file|") ||
171
+ die;
172
+
173
+ my %exist;
174
+ my %uses;
175
+ my $file;
176
+ while (<N>) {
177
+ my $l = $_;
178
+ chomp $l;
179
+
180
+ if($l =~ /^([0-9a-z_-]+)\.o:/) {
181
+ $file = $1;
182
+ }
183
+ # libcurl.a(unity_0_c.c.o):
184
+ elsif($l =~ /\(([0-9a-z_.-]+)\.o\):/) { # Apple nm
185
+ $file = $1;
186
+ }
187
+ if($l =~ /^([0-9a-f]+) T _?(.*)/) {
188
+ my ($name)=($2);
189
+ #print "Define $name in $file\n";
190
+ $file =~ s/^libcurl_la-//;
191
+ $exist{$name} = $file;
192
+ }
193
+ elsif($l =~ /^ U _?(.*)/) {
194
+ my ($name)=($1);
195
+ #print "Uses $name in $file\n";
196
+ $uses{$name} .= "$file, ";
197
+ }
198
+ }
199
+ close(N);
200
+
201
+ my $err;
202
+ for(sort keys %exist) {
203
+ #printf "%s is defined in %s, used by: %s\n", $_, $exist{$_}, $uses{$_};
204
+ if(!$uses{$_}) {
205
+ # this is a symbol with no "global" user
206
+ if($_ =~ /^curl_dbg_/) {
207
+ # we ignore the memdebug symbols
208
+ }
209
+ elsif($_ =~ /^curl_/) {
210
+ if(!$api{$_}) {
211
+ # not present in the API, or for debug-builds
212
+ print STDERR "Bad curl-prefix: $_\n";
213
+ $err++;
214
+ }
215
+ }
216
+ elsif($wl{$_}) {
217
+ #print "$_ is WL\n";
218
+ }
219
+ else {
220
+ my $c = $_;
221
+ my @also = doublecheck($c, $exist{$c});
222
+ if(!scalar(@also)) {
223
+ printf "%s in %s\n", $c, $exist{$c};
224
+ $err++;
225
+ }
226
+ # foreach my $a (@also) {
227
+ # print " $a\n";
228
+ # }
229
+ }
230
+ }
231
+ elsif($_ =~ /^curl_/) {
232
+ # global prefix, make sure it is "blessed"
233
+ if(!$api{$_}) {
234
+ # not present in the API, or for debug-builds
235
+ if($_ !~ /^curl_dbg_/) {
236
+ # ignore the memdebug symbols
237
+ print STDERR "Bad curl-prefix $_\n";
238
+ $err++;
239
+ }
240
+ }
241
+ }
242
+ }
243
+
244
+ exit $err;
local-test-curl-delta-01/afc-curl/scripts/verify-release ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ #***************************************************************************
4
+ # _ _ ____ _
5
+ # Project ___| | | | _ \| |
6
+ # / __| | | | |_) | |
7
+ # | (__| |_| | _ <| |___
8
+ # \___|\___/|_| \_\_____|
9
+ #
10
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11
+ #
12
+ # This software is licensed as described in the file COPYING, which
13
+ # you should have received as part of this distribution. The terms
14
+ # are also available at https://curl.se/docs/copyright.html.
15
+ #
16
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ # copies of the Software, and permit persons to whom the Software is
18
+ # furnished to do so, under the terms of the COPYING file.
19
+ #
20
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ # KIND, either express or implied.
22
+ #
23
+ # SPDX-License-Identifier: curl
24
+ #
25
+ ###########################################################################
26
+
27
+ # This script remakes a provided curl release and verifies that the newly
28
+ # built version is identical to the original file.
29
+ #
30
+ # It is designed to be invoked in a clean directory with the path to the
31
+ # release tarball as an argument.
32
+ #
33
+
34
+ set -eu
35
+
36
+ tarball="${1:-}"
37
+
38
+ if [ -z "$tarball" ]; then
39
+ echo "Provide a curl release tarball name as argument"
40
+ exit
41
+ fi
42
+
43
+ i="0"
44
+
45
+ # shellcheck disable=SC2034
46
+ for dl in curl-*; do
47
+ i=$((i + 1))
48
+ done
49
+
50
+ if test "$i" -gt 1; then
51
+ echo "multiple curl-* entries found, disambiguate please"
52
+ exit
53
+ fi
54
+
55
+ mkdir -p _tarballs
56
+ rm -rf _tarballs/*
57
+
58
+ # checksum the original tarball to compare with later
59
+ sha256sum "$tarball" >_tarballs/checksum
60
+
61
+ # extract the release contents
62
+ tar xf "$tarball"
63
+
64
+ curlver=$(grep '#define LIBCURL_VERSION ' curl-*/include/curl/curlver.h | sed 's/[^0-9.]//g')
65
+
66
+ echo "version $curlver"
67
+
68
+ timestamp=$(grep -Eo 'SOURCE_DATE_EPOCH=[0-9]*' curl-"$curlver"/docs/RELEASE-TOOLS.md | cut -d= -f2)
69
+
70
+ pwd=$(pwd)
71
+ cd "curl-$curlver"
72
+ ./configure --without-ssl --without-libpsl
73
+ ./scripts/dmaketgz "$curlver" "$timestamp"
74
+
75
+ mv curl-"$curlver"* ../_tarballs/
76
+ cd "$pwd"
77
+ cd "_tarballs"
78
+
79
+ # compare the new tarball against the original
80
+ sha256sum -c checksum
local-test-curl-delta-01/afc-curl/tests/.gitignore ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
2
+ #
3
+ # SPDX-License-Identifier: curl
4
+
5
+ *pid
6
+ *.1.dist
7
+ configurehelp.pm
8
+ curl_client_key
9
+ curl_client_key.pub
10
+ curl_client_knownhosts
11
+ curl_host_rsa_key
12
+ curl_host_rsa_key.pub
13
+ curl_host_rsa_key.pub_md5
14
+ curl_host_rsa_key.pub_sha256
15
+ curl_sftp_cmds
16
+ curl_sftp_config
17
+ curl_ssh_config
18
+ curl_sshd_config
19
+ ftps_stunnel.conf
20
+ https_stunnel.conf
21
+ log
22
+ log*
23
+ runtests.html
24
+ runtests.pdf
25
+ testcurl.html
26
+ testcurl.pdf
27
+ *.port
28
+ config
29
+ second-hsts.txt
30
+ runtests.1
31
+ testcurl.1
local-test-curl-delta-01/afc-curl/tests/Makefile.am ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+
25
+ if BUILD_DOCS
26
+ # if we disable man page building, ignore these
27
+ RUNTESTS_DOCS = runtests.1
28
+ TESTCURL_DOCS = testcurl.1
29
+ MANFILES = $(RUNTESTS_DOCS) $(TESTCURL_DOCS)
30
+ endif
31
+
32
+ CURLPAGES = runtests.md testcurl.md
33
+
34
+ # scripts used in test cases
35
+ TESTSCRIPTS = \
36
+ test1119.pl \
37
+ test1132.pl \
38
+ test1135.pl \
39
+ test1139.pl \
40
+ test1140.pl \
41
+ test1165.pl \
42
+ test1167.pl \
43
+ test1173.pl \
44
+ test1175.pl \
45
+ test1177.pl \
46
+ test1222.pl \
47
+ test1275.pl \
48
+ test1276.pl \
49
+ test1477.pl \
50
+ test1486.pl \
51
+ test1488.pl \
52
+ test1544.pl \
53
+ test1707.pl \
54
+ test971.pl
55
+
56
+ EXTRA_DIST = \
57
+ CMakeLists.txt \
58
+ FILEFORMAT.md \
59
+ README.md \
60
+ appveyor.pm \
61
+ azure.pm \
62
+ devtest.pl \
63
+ dictserver.py \
64
+ directories.pm \
65
+ ech_combos.py \
66
+ ech_tests.sh \
67
+ ftpserver.pl \
68
+ getpart.pm \
69
+ globalconfig.pm \
70
+ http-server.pl \
71
+ http2-server.pl \
72
+ http3-server.pl \
73
+ memanalyze.pl \
74
+ mk-bundle-hints.sh \
75
+ mk-bundle.pl \
76
+ negtelnetserver.py \
77
+ nghttpx.conf \
78
+ pathhelp.pm \
79
+ processhelp.pm \
80
+ requirements.txt \
81
+ rtspserver.pl \
82
+ runner.pm \
83
+ runtests.pl \
84
+ secureserver.pl \
85
+ serverhelp.pm \
86
+ servers.pm \
87
+ smbserver.py \
88
+ sshhelp.pm \
89
+ sshserver.pl \
90
+ stunnel.pem \
91
+ testcurl.pl \
92
+ testutil.pm \
93
+ tftpserver.pl \
94
+ util.py \
95
+ valgrind.pm \
96
+ valgrind.supp \
97
+ $(TESTSCRIPTS) \
98
+ $(CURLPAGES)
99
+
100
+ # we have two variables here to make sure DIST_SUBDIRS won't get 'unit'
101
+ # added twice as then targets such as 'distclean' misbehave and try to
102
+ # do things twice in that subdir at times (and thus fails).
103
+ if BUILD_UNITTESTS
104
+ BUILD_UNIT = unit
105
+ DIST_UNIT =
106
+ else
107
+ BUILD_UNIT =
108
+ DIST_UNIT = unit
109
+ endif
110
+
111
+ SUBDIRS = certs data server libtest http $(BUILD_UNIT)
112
+ DIST_SUBDIRS = $(SUBDIRS) $(DIST_UNIT)
113
+
114
+ PERLFLAGS = -I$(srcdir)
115
+
116
+ CLEANFILES = .http.pid .https.pid .ftp.pid .ftps.pid $(MANDISTPAGES)
117
+
118
+ curl:
119
+ @cd $(top_builddir) && $(MAKE)
120
+
121
+ TEST_COMMON =
122
+
123
+ if CROSSCOMPILING
124
+ TEST = @echo "NOTICE: we can't run the tests when cross-compiling!"
125
+ PYTEST = $(TEST)
126
+ else # if not cross-compiling:
127
+ if USE_TEST_BUNDLES
128
+ TEST_COMMON += -bundle
129
+ endif
130
+
131
+ if BUILD_DOCS
132
+ else
133
+ TEST_COMMON += !documentation
134
+ endif
135
+
136
+ TEST = srcdir=$(srcdir) $(PERL) $(PERLFLAGS) $(srcdir)/runtests.pl $(TEST_COMMON)
137
+ TEST_Q = -a -s
138
+ TEST_AM = -a -am
139
+ TEST_F = -a -p -r
140
+ TEST_T = -a -t -j20
141
+ TEST_E = -a -e
142
+
143
+ # ~<keyword> means that it will run all tests matching the keyword, but will
144
+ # ignore their results (since these ones are likely to fail for no good reason)
145
+ TEST_NF = -a -p ~flaky ~timing-dependent
146
+
147
+ # special CI target derived from nonflaky with CI-specific flags
148
+ TEST_CI = $(TEST_NF) -r -rm -j20
149
+
150
+ PYTEST = pytest
151
+ endif
152
+
153
+ CD2NROFF = $(top_srcdir)/scripts/cd2nroff $< >$@
154
+
155
+ SUFFIXES = .1 .md
156
+
157
+ .md.1:
158
+ $(CD2)$(CD2NROFF)
159
+
160
+ # make sure that PERL is pointing to an executable
161
+ perlcheck:
162
+ @if ! test -x "$(PERL)"; then echo "No perl!"; exit 2; fi
163
+
164
+ test: perlcheck all
165
+ $(TEST) $(TFLAGS)
166
+
167
+ quiet-test: perlcheck all
168
+ $(TEST) $(TEST_Q) $(TFLAGS)
169
+
170
+ am-test: perlcheck all
171
+ $(TEST) $(TEST_AM) $(TFLAGS)
172
+
173
+ ci-test: perlcheck all
174
+ $(TEST) $(TEST_CI) $(TFLAGS)
175
+
176
+ full-test: perlcheck all
177
+ $(TEST) $(TEST_F) $(TFLAGS)
178
+
179
+ nonflaky-test: perlcheck all
180
+ $(TEST) $(TEST_NF) $(TFLAGS)
181
+
182
+ torture-test: perlcheck all
183
+ $(TEST) $(TEST_T) $(TFLAGS)
184
+
185
+ event-test: perlcheck all
186
+ $(TEST) $(TEST_E) $(TFLAGS)
187
+
188
+ default-pytest: ci-pytest
189
+
190
+ ci-pytest: all
191
+ srcdir=$(srcdir) $(PYTEST) -v $(srcdir)/http
192
+
193
+ checksrc:
194
+ (cd libtest && $(MAKE) checksrc)
195
+ (cd unit && $(MAKE) checksrc)
196
+ (cd server && $(MAKE) checksrc)
197
+ (cd http && $(MAKE) checksrc)
198
+
199
+ all-local: $(MANFILES)
200
+
201
+ distclean:
202
+ rm -f $(MANFILES)
local-test-curl-delta-01/afc-curl/tests/appveyor.pm ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ # Copyright (C) Marc Hoersken, <info@marc-hoersken.de>
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ package appveyor;
27
+
28
+ use strict;
29
+ use warnings;
30
+
31
+ BEGIN {
32
+ use base qw(Exporter);
33
+
34
+ our @EXPORT = qw(
35
+ appveyor_check_environment
36
+ appveyor_create_test_result
37
+ appveyor_update_test_result
38
+ );
39
+ }
40
+
41
+
42
+ my %APPVEYOR_TEST_NAMES; # JSON and shell-quoted test names by test number
43
+
44
+ sub appveyor_check_environment {
45
+ if(defined $ENV{'APPVEYOR_API_URL'} && $ENV{'APPVEYOR_API_URL'}) {
46
+ return 1;
47
+ }
48
+ return 0;
49
+ }
50
+
51
+ sub appveyor_create_test_result {
52
+ my ($curl, $testnum, $testname)=@_;
53
+ $testname =~ s/\\/\\\\/g;
54
+ $testname =~ s/\"/\\\"/g;
55
+ $testname =~ s/\'/'"'"'/g;
56
+ my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
57
+ my $appveyor_result=`$curl --silent --noproxy '*' \\
58
+ --header 'Content-Type: application/json' \\
59
+ --data '
60
+ {
61
+ "testName": "$testname",
62
+ "testFramework": "runtests.pl",
63
+ "fileName": "tests/data/test$testnum",
64
+ "outcome": "Running"
65
+ }
66
+ ' \\
67
+ '$appveyor_baseurl/api/tests'`;
68
+ print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
69
+ $APPVEYOR_TEST_NAMES{$testnum}=$testname;
70
+ }
71
+
72
+ sub appveyor_update_test_result {
73
+ my ($curl, $testnum, $error, $start, $stop)=@_;
74
+ my $testname=$APPVEYOR_TEST_NAMES{$testnum};
75
+ if(!defined $testname) {
76
+ return;
77
+ }
78
+ if(!defined $stop) {
79
+ $stop = $start;
80
+ }
81
+ my $appveyor_duration = sprintf("%.0f", ($stop-$start)*1000);
82
+ my $appveyor_outcome;
83
+ my $appveyor_category;
84
+ if($error == 2) {
85
+ $appveyor_outcome = 'Ignored';
86
+ $appveyor_category = 'Error';
87
+ }
88
+ elsif($error < 0) {
89
+ $appveyor_outcome = 'NotRunnable';
90
+ $appveyor_category = 'Warning';
91
+ }
92
+ elsif(!$error) {
93
+ $appveyor_outcome = 'Passed';
94
+ $appveyor_category = 'Information';
95
+ }
96
+ else {
97
+ $appveyor_outcome = 'Failed';
98
+ $appveyor_category = 'Error';
99
+ }
100
+ my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
101
+ my $appveyor_result=`$curl --silent --noproxy '*' --request PUT \\
102
+ --header 'Content-Type: application/json' \\
103
+ --data '
104
+ {
105
+ "testName": "$testname",
106
+ "testFramework": "runtests.pl",
107
+ "fileName": "tests/data/test$testnum",
108
+ "outcome": "$appveyor_outcome",
109
+ "durationMilliseconds": $appveyor_duration,
110
+ "ErrorMessage": "Test $testnum $appveyor_outcome"
111
+ }
112
+ ' \\
113
+ '$appveyor_baseurl/api/tests'`;
114
+ print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
115
+ if($appveyor_category eq 'Error') {
116
+ $appveyor_result=`$curl --silent --noproxy '*' \\
117
+ --header 'Content-Type: application/json' \\
118
+ --data '
119
+ {
120
+ "message": "$appveyor_outcome: $testname",
121
+ "category": "$appveyor_category",
122
+ "details": "Test $testnum $appveyor_outcome"
123
+ }
124
+ ' \\
125
+ '$appveyor_baseurl/api/build/messages'`;
126
+ print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
127
+ }
128
+ }
129
+
130
+ 1;
local-test-curl-delta-01/afc-curl/tests/config.in ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+ NGHTTPX: @TEST_NGHTTPX@
local-test-curl-delta-01/afc-curl/tests/configurehelp.pm.in ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+
25
+ package configurehelp;
26
+
27
+ use strict;
28
+ use warnings;
29
+ use Exporter;
30
+
31
+ use vars qw(
32
+ @ISA
33
+ @EXPORT_OK
34
+ $Cpreprocessor
35
+ );
36
+
37
+ @ISA = qw(Exporter);
38
+
39
+ @EXPORT_OK = qw(
40
+ $Cpreprocessor
41
+ );
42
+
43
+ $Cpreprocessor = '@CURL_CPP@';
44
+
45
+ 1;
local-test-curl-delta-01/afc-curl/tests/devtest.pl ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Fandrich, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # This script is intended for developers to test some internals of the
27
+ # runtests.pl harness. Don't try to use this unless you know what you're
28
+ # doing!
29
+
30
+ # An example command-line that starts a test http server for test 11 and waits
31
+ # for the user before stopping it:
32
+ # ./devtest.pl --verbose serverfortest https echo "Started https" protoport https preprocess 11 pause echo Stopping stopservers echo Done
33
+ # curl can connect to the server while it's running like this:
34
+ # curl -vkL https://localhost:<protoport>/11
35
+
36
+ use strict;
37
+ use warnings;
38
+ use 5.006;
39
+
40
+ BEGIN {
41
+ # Define srcdir to the location of the tests source directory. This is
42
+ # usually set by the Makefile, but for out-of-tree builds with direct
43
+ # invocation of runtests.pl, it may not be set.
44
+ if(!defined $ENV{'srcdir'}) {
45
+ use File::Basename;
46
+ $ENV{'srcdir'} = dirname(__FILE__);
47
+ }
48
+ push(@INC, $ENV{'srcdir'});
49
+ }
50
+
51
+ use globalconfig;
52
+ use servers qw(
53
+ initserverconfig
54
+ protoport
55
+ serverfortest
56
+ stopservers
57
+ );
58
+ use runner qw(
59
+ readtestkeywords
60
+ singletest_preprocess
61
+ );
62
+ use testutil qw(
63
+ setlogfunc
64
+ );
65
+ use getpart;
66
+
67
+
68
+ #######################################################################
69
+ # logmsg is our general message logging subroutine.
70
+ # This function is currently required to be here by servers.pm
71
+ # This is copied from runtests.pl
72
+ #
73
+ my $uname_release = `uname -r`;
74
+ my $is_wsl = $uname_release =~ /Microsoft$/;
75
+ sub logmsg {
76
+ for(@_) {
77
+ my $line = $_;
78
+ if ($is_wsl) {
79
+ # use \r\n for WSL shell
80
+ $line =~ s/\r?\n$/\r\n/g;
81
+ }
82
+ print "$line";
83
+ }
84
+ }
85
+
86
+ #######################################################################
87
+ # Parse and store the protocols in curl's Protocols: line
88
+ # This is copied from runtests.pl
89
+ #
90
+ sub parseprotocols {
91
+ my ($line)=@_;
92
+
93
+ @protocols = split(' ', lc($line));
94
+
95
+ # Generate a "proto-ipv6" version of each protocol to match the
96
+ # IPv6 <server> name and a "proto-unix" to match the variant which
97
+ # uses Unix domain sockets. This works even if support isn't
98
+ # compiled in because the <features> test will fail.
99
+ push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
100
+
101
+ # 'http-proxy' is used in test cases to do CONNECT through
102
+ push @protocols, 'http-proxy';
103
+
104
+ # 'none' is used in test cases to mean no server
105
+ push @protocols, 'none';
106
+ }
107
+
108
+
109
+ #######################################################################
110
+ # Initialize @protocols from the curl binary under test
111
+ #
112
+ sub init_protocols {
113
+ for (`$CURL -V 2>$dev_null`) {
114
+ if(m/^Protocols: (.*)$/) {
115
+ parseprotocols($1);
116
+ }
117
+ }
118
+ }
119
+
120
+
121
+ #######################################################################
122
+ # Initialize the test harness to run tests
123
+ #
124
+ sub init_tests {
125
+ setlogfunc(\&logmsg);
126
+ init_protocols();
127
+ initserverconfig();
128
+ }
129
+
130
+ #######################################################################
131
+ # Main test loop
132
+
133
+ init_tests();
134
+
135
+ #***************************************************************************
136
+ # Parse command-line options and commands
137
+ #
138
+ while(@ARGV) {
139
+ if($ARGV[0] eq "-h") {
140
+ print "Usage: devtest.pl [--verbose] [command [arg]...]\n";
141
+ print "command is one of:\n";
142
+ print " echo X\n";
143
+ print " pause\n";
144
+ print " preprocess\n";
145
+ print " protocols *|X[,Y...]\n";
146
+ print " protoport X\n";
147
+ print " serverfortest X[,Y...]\n";
148
+ print " stopservers\n";
149
+ print " sleep N\n";
150
+ exit 0;
151
+ }
152
+ elsif($ARGV[0] eq "--verbose") {
153
+ $verbose = 1;
154
+ }
155
+ elsif($ARGV[0] eq "sleep") {
156
+ shift @ARGV;
157
+ sleep $ARGV[0];
158
+ }
159
+ elsif($ARGV[0] eq "echo") {
160
+ shift @ARGV;
161
+ print $ARGV[0] . "\n";
162
+ }
163
+ elsif($ARGV[0] eq "pause") {
164
+ print "Press Enter to continue: ";
165
+ readline STDIN;
166
+ }
167
+ elsif($ARGV[0] eq "protocols") {
168
+ shift @ARGV;
169
+ if($ARGV[0] eq "*") {
170
+ init_protocols();
171
+ }
172
+ else {
173
+ @protocols = split(",", $ARGV[0]);
174
+ }
175
+ print "Set " . scalar @protocols . " protocols\n";
176
+ }
177
+ elsif($ARGV[0] eq "preprocess") {
178
+ shift @ARGV;
179
+ loadtest("${TESTDIR}/test${ARGV[0]}");
180
+ readtestkeywords();
181
+ singletest_preprocess($ARGV[0]);
182
+ }
183
+ elsif($ARGV[0] eq "protoport") {
184
+ shift @ARGV;
185
+ my $port = protoport($ARGV[0]);
186
+ print "protoport: $port\n";
187
+ }
188
+ elsif($ARGV[0] eq "serverfortest") {
189
+ shift @ARGV;
190
+ my ($why, $e) = serverfortest(split(/,/, $ARGV[0]));
191
+ print "serverfortest: $e $why\n";
192
+ }
193
+ elsif($ARGV[0] eq "stopservers") {
194
+ my $err = stopservers();
195
+ print "stopservers: $err\n";
196
+ }
197
+ else {
198
+ print "Error: Unknown command: $ARGV[0]\n";
199
+ print "Continuing anyway\n";
200
+ }
201
+ shift @ARGV;
202
+ }
local-test-curl-delta-01/afc-curl/tests/dictserver.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #***************************************************************************
4
+ # _ _ ____ _
5
+ # Project ___| | | | _ \| |
6
+ # / __| | | | |_) | |
7
+ # | (__| |_| | _ <| |___
8
+ # \___|\___/|_| \_\_____|
9
+ #
10
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11
+ #
12
+ # This software is licensed as described in the file COPYING, which
13
+ # you should have received as part of this distribution. The terms
14
+ # are also available at https://curl.se/docs/copyright.html.
15
+ #
16
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ # copies of the Software, and permit persons to whom the Software is
18
+ # furnished to do so, under the terms of the COPYING file.
19
+ #
20
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ # KIND, either express or implied.
22
+ #
23
+ # SPDX-License-Identifier: curl
24
+ #
25
+ ###########################################################################
26
+ #
27
+ """DICT server."""
28
+
29
+ from __future__ import (absolute_import, division, print_function,
30
+ unicode_literals)
31
+
32
+ import argparse
33
+ import logging
34
+ import os
35
+ import sys
36
+
37
+ from util import ClosingFileHandler
38
+
39
+ try: # Python 2
40
+ import SocketServer as socketserver # type: ignore
41
+ except ImportError: # Python 3
42
+ import socketserver
43
+
44
+ log = logging.getLogger(__name__)
45
+ HOST = "localhost"
46
+
47
+ # The strings that indicate the test framework is checking our aliveness
48
+ VERIFIED_REQ = b"verifiedserver"
49
+ VERIFIED_RSP = "WE ROOLZ: {pid}"
50
+
51
+
52
+ def dictserver(options):
53
+ """Start up a TCP server with a DICT handler and serve DICT requests forever."""
54
+ if options.pidfile:
55
+ pid = os.getpid()
56
+ # see tests/server/util.c function write_pidfile
57
+ if os.name == "nt":
58
+ pid += 65536
59
+ with open(options.pidfile, "w") as f:
60
+ f.write(str(pid))
61
+
62
+ local_bind = (options.host, options.port)
63
+ log.info("[DICT] Listening on %s", local_bind)
64
+
65
+ # Need to set the allow_reuse on the class, not on the instance.
66
+ socketserver.TCPServer.allow_reuse_address = True
67
+ server = socketserver.TCPServer(local_bind, DictHandler)
68
+ server.serve_forever()
69
+
70
+ return ScriptRC.SUCCESS
71
+
72
+
73
+ class DictHandler(socketserver.BaseRequestHandler):
74
+ """Handler class for DICT connections."""
75
+
76
+ def handle(self):
77
+ """Respond to all queries with a 552."""
78
+ try:
79
+ # First, send a response to allow the server to continue.
80
+ rsp = "220 dictserver <xnooptions> <msgid@msgid>\n"
81
+ self.request.sendall(rsp.encode("utf-8"))
82
+
83
+ # Receive the request.
84
+ data = self.request.recv(1024).strip()
85
+ log.debug("[DICT] Incoming data: %r", data)
86
+
87
+ if VERIFIED_REQ in data:
88
+ log.debug("[DICT] Received verification request from test "
89
+ "framework")
90
+ pid = os.getpid()
91
+ # see tests/server/util.c function write_pidfile
92
+ if os.name == "nt":
93
+ pid += 65536
94
+ response_data = VERIFIED_RSP.format(pid=pid)
95
+ else:
96
+ log.debug("[DICT] Received normal request")
97
+ response_data = "No matches"
98
+
99
+ # Send back a failure to find.
100
+ response = "552 {0}\n".format(response_data)
101
+ log.debug("[DICT] Responding with %r", response)
102
+ self.request.sendall(response.encode("utf-8"))
103
+
104
+ except IOError:
105
+ log.exception("[DICT] IOError hit during request")
106
+
107
+
108
+ def get_options():
109
+ parser = argparse.ArgumentParser()
110
+
111
+ parser.add_argument("--port", action="store", default=9016,
112
+ type=int, help="port to listen on")
113
+ parser.add_argument("--host", action="store", default=HOST,
114
+ help="host to listen on")
115
+ parser.add_argument("--verbose", action="store", type=int, default=0,
116
+ help="verbose output")
117
+ parser.add_argument("--pidfile", action="store",
118
+ help="file name for the PID")
119
+ parser.add_argument("--logfile", action="store",
120
+ help="file name for the log")
121
+ parser.add_argument("--srcdir", action="store", help="test directory")
122
+ parser.add_argument("--id", action="store", help="server ID")
123
+ parser.add_argument("--ipv4", action="store_true", default=0,
124
+ help="IPv4 flag")
125
+
126
+ return parser.parse_args()
127
+
128
+
129
+ def setup_logging(options):
130
+ """Set up logging from the command line options."""
131
+ root_logger = logging.getLogger()
132
+ add_stdout = False
133
+
134
+ formatter = logging.Formatter("%(asctime)s %(levelname)-5.5s %(message)s")
135
+
136
+ # Write out to a logfile
137
+ if options.logfile:
138
+ handler = ClosingFileHandler(options.logfile)
139
+ handler.setFormatter(formatter)
140
+ handler.setLevel(logging.DEBUG)
141
+ root_logger.addHandler(handler)
142
+ else:
143
+ # The logfile wasn't specified. Add a stdout logger.
144
+ add_stdout = True
145
+
146
+ if options.verbose:
147
+ # Add a stdout logger as well in verbose mode
148
+ root_logger.setLevel(logging.DEBUG)
149
+ add_stdout = True
150
+ else:
151
+ root_logger.setLevel(logging.INFO)
152
+
153
+ if add_stdout:
154
+ stdout_handler = logging.StreamHandler(sys.stdout)
155
+ stdout_handler.setFormatter(formatter)
156
+ stdout_handler.setLevel(logging.DEBUG)
157
+ root_logger.addHandler(stdout_handler)
158
+
159
+
160
+ class ScriptRC(object):
161
+ """Enum for script return codes."""
162
+
163
+ SUCCESS = 0
164
+ FAILURE = 1
165
+ EXCEPTION = 2
166
+
167
+
168
+ if __name__ == '__main__':
169
+ # Get the options from the user.
170
+ options = get_options()
171
+
172
+ # Setup logging using the user options
173
+ setup_logging(options)
174
+
175
+ # Run main script.
176
+ try:
177
+ rc = dictserver(options)
178
+ except Exception:
179
+ log.exception('Error running server')
180
+ rc = ScriptRC.EXCEPTION
181
+
182
+ if options.pidfile and os.path.isfile(options.pidfile):
183
+ os.unlink(options.pidfile)
184
+
185
+ log.info("[DICT] Returning %d", rc)
186
+ sys.exit(rc)
local-test-curl-delta-01/afc-curl/tests/ech_tests.sh ADDED
@@ -0,0 +1,1156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+ #
26
+
27
+ # Run some tests against servers we know to support ECH (CF, defo.ie, etc.).
28
+ # as well as some we know don't do ECH but have an HTTPS RR, and finally some
29
+ # for which neither is the case.
30
+
31
+ # TODO: Translate this into something that approximates a valid curl test:-)
32
+ # Should be useful though even before such translation and a pile less work
33
+ # to do this than that. The pile of work required would include making an
34
+ # ECH-enabled server and a DoH server. For now, this is just run manually.
35
+ #
36
+
37
+ # set -x
38
+
39
+ # Exit with an error if there's an active ech stanza in ~/.curlrc
40
+ # as that'd likely skew some results (e.g. turning a fail into a
41
+ # success or vice versa)
42
+ : "${CURL_CFG_FILE=$HOME/.curlrc}"
43
+ active_ech=$(grep ech "$CURL_CFG_FILE" | grep -v "#.*ech")
44
+ if [[ "$active_ech" != "" ]]
45
+ then
46
+ echo "You seem to have an active ECH setting in $CURL_CFG_FILE"
47
+ echo "That might affect results so please remove that or comment"
48
+ echo "it out - exiting."
49
+ exit 1
50
+ fi
51
+
52
+
53
+ # Targets we expect to be ECH-enabled servers
54
+ # for which an HTTPS RR is published.
55
+ # structure is host:port mapped to pathname
56
+ # TODO: add negative tests for these
57
+ declare -A ech_targets=(
58
+ [my-own.net]="ech-check.php"
59
+ [my-own.net:8443]="ech-check.php"
60
+ [defo.ie]="ech-check.php"
61
+ [cover.defo.ie]=""
62
+ [draft-13.esni.defo.ie:8413]="stats"
63
+ [draft-13.esni.defo.ie:8414]="stats"
64
+ [draft-13.esni.defo.ie:9413]=""
65
+ [draft-13.esni.defo.ie:10413]=""
66
+ [draft-13.esni.defo.ie:11413]=""
67
+ [draft-13.esni.defo.ie:12413]=""
68
+ [draft-13.esni.defo.ie:12414]=""
69
+ [crypto.cloudflare.com]="cdn-cgi/trace"
70
+ [tls-ech.dev]=""
71
+ # this one's gone away for now (possibly temporarily)
72
+ # [epochbelt.com]=""
73
+ )
74
+
75
+ # Targets we expect not to be ECH-enabled servers
76
+ # but for which an HTTPS RR is published.
77
+ declare -A httpsrr_targets=(
78
+ [ietf.org]=""
79
+ [rte.ie]=""
80
+ )
81
+
82
+ # Targets we expect not to be ECH-enabled servers
83
+ # and for which no HTTPS RR is published.
84
+ declare -A neither_targets=(
85
+ [www.tcd.ie]=""
86
+ [jell.ie]=""
87
+ )
88
+
89
+ #
90
+ # Variables that can be over-ridden from environment
91
+ #
92
+
93
+ # Top of curl test tree, assume we're there
94
+ : "${CTOP:=.}"
95
+
96
+ # Place to put test log output
97
+ : "${LTOP:=$CTOP/tests/ech-log/}"
98
+
99
+ # Place to stash outputs when things go wrong
100
+ : "${BTOP:=$LTOP}"
101
+
102
+ # Time to wait for a remote access to work, 10 seconds
103
+ : "${tout:=10s}"
104
+
105
+ # Where we find OpenSSL .so's
106
+ : "${OSSL:=$HOME/code/openssl-local-inst}"
107
+
108
+ # Where we find wolfSSL .so's
109
+ : "${WSSL:=$HOME/code/wolfssl/inst/lib}"
110
+
111
+ # Where we find BoringSSL .so's
112
+ : "${BSSL:=$HOME/code/boringssl/inst/lib}"
113
+
114
+ # Where we send DoH queries when using kdig or curl
115
+ : "${DOHSERVER:=one.one.one.one}"
116
+ : "${DOHPATH:=dns-query}"
117
+
118
+ # Whether to send mail when bad things happen (mostly for cronjob)
119
+ : "${DOMAIL:=no}"
120
+
121
+ # Misc vars and functions
122
+
123
+ DEFPORT=443
124
+
125
+ function whenisitagain()
126
+ {
127
+ /bin/date -u +%Y%m%d-%H%M%S
128
+ }
129
+
130
+ function fileage()
131
+ {
132
+ echo $(($(date +%s) - $(date +%s -r "$1")))
133
+ }
134
+
135
+ function hostport2host()
136
+ {
137
+ case $1 in
138
+ *:*) host=${1%:*} port=${1##*:};;
139
+ *) host=$1 port=$DEFPORT;;
140
+ esac
141
+ echo "$host"
142
+ }
143
+
144
+ function hostport2port()
145
+ {
146
+ case $1 in
147
+ *:*) host=${1%:*} port=${1##*:};;
148
+ *) host=$1 port=$DEFPORT;;
149
+ esac
150
+ echo "$port"
151
+ }
152
+
153
+ function cli_test()
154
+ {
155
+ # 1st param is target URL
156
+ turl=$1
157
+ # 2nd param is 0 if we expect curl to not work or 1 if we expect it
158
+ # to have worked
159
+ curl_winorlose=$2
160
+ # 3rd param is 0 if we expect ECH to not work or 1 if we expect it
161
+ # to have worked
162
+ ech_winorlose=$3
163
+ # remaining params are passed to command line
164
+ # echparms=(${@:4})
165
+ IFS=" " read -r -a echparms <<< "${@:4}"
166
+
167
+ TMPF=$(mktemp)
168
+ cmd="timeout $tout $CURL ${CURL_PARAMS[*]} ${echparms[*]} $turl >$TMPF 2>&1"
169
+ echo "cli_test: $cmd " >> "$logfile"
170
+ timeout "$tout" "$CURL" "${CURL_PARAMS[@]}" "${echparms[@]}" "$turl" >"$TMPF" 2>&1
171
+ eres=$?
172
+ if [[ "$eres" == "124" ]]
173
+ then
174
+ allgood="no"
175
+ echo "cli_test: Timeout running $cmd"
176
+ cat "$TMPF" >> "$logfile"
177
+ echo "cli_test: Timeout running $cmd" >> "$logfile"
178
+ fi
179
+ if [[ "$eres" != "0" && "$curl_winorlose" == "1" ]]
180
+ then
181
+ allgood="no"
182
+ echo "cli_test: curl failure running $cmd"
183
+ cat "$TMPF" >> "$logfile"
184
+ echo "cli_test: curl failure running $cmd" >> "$logfile"
185
+ fi
186
+ ech_success=$(grep -c "ECH: result: status is succeeded" "$TMPF")
187
+ if [[ "$ech_success" == "$ech_winorlose" ]]
188
+ then
189
+ echo "cli_test ok for ${echparms[*]}"
190
+ else
191
+ allgood="no"
192
+ echo "cli_test: ECH failure running $cmd"
193
+ cat "$TMPF" >> "$logfile"
194
+ echo "cli_test: ECH failure running $cmd" >> "$logfile"
195
+ fi
196
+ rm -f "$TMPF"
197
+ }
198
+
199
+ function get_ech_configlist()
200
+ {
201
+ domain=$1
202
+ ecl=$(dig +short https "$domain" | grep "ech=" | sed -e 's/^.*ech=//' | sed -e 's/ .*//')
203
+ echo "$ecl"
204
+ }
205
+
206
+ # start of main script
207
+
208
+ # start by assuming we have nothing we need...
209
+ have_ossl="no"
210
+ have_wolf="no"
211
+ have_bssl="no"
212
+ using_ossl="no"
213
+ using_wolf="no"
214
+ using_bssl="no"
215
+ have_curl="no"
216
+ have_dig="no"
217
+ have_kdig="no"
218
+ have_presout="no"
219
+ have_portsblocked="no"
220
+
221
+ # setup logging
222
+ NOW=$(whenisitagain)
223
+ BINNAME=$(basename "$0" .sh)
224
+ if [ ! -d "$LTOP" ]
225
+ then
226
+ mkdir -p "$LTOP"
227
+ fi
228
+ if [ ! -d "$LTOP" ]
229
+ then
230
+ echo "Can't see $LTOP for logs - exiting"
231
+ exit 1
232
+ fi
233
+ logfile=$LTOP/${BINNAME}_$NOW.log
234
+
235
+ echo "-----" > "$logfile"
236
+ echo "Running $0 at $NOW" >> "$logfile"
237
+ echo "Running $0 at $NOW"
238
+
239
+ # check we have the binaries needed and which TLS library we'll be using
240
+ if [ -f "$OSSL"/libssl.so ]
241
+ then
242
+ have_ossl="yes"
243
+ fi
244
+ if [ -f "$WSSL"/libwolfssl.so ]
245
+ then
246
+ have_wolf="yes"
247
+ fi
248
+ if [ -f "$BSSL"/libssl.so ]
249
+ then
250
+ have_bssl="yes"
251
+ fi
252
+ CURL="$CTOP/src/curl"
253
+ CURL_PARAMS=(-vvv --doh-url https://one.one.one.one/dns-query)
254
+ if [ -f "$CTOP"/src/curl ]
255
+ then
256
+ have_curl="yes"
257
+ fi
258
+ ossl_cnt=$(LD_LIBRARY_PATH=$OSSL $CURL "${CURL_PARAMS[@]}" -V 2> /dev/null | grep -c OpenSSL)
259
+ if ((ossl_cnt == 1))
260
+ then
261
+ using_ossl="yes"
262
+ # setup access to our .so
263
+ export LD_LIBRARY_PATH=$OSSL
264
+ fi
265
+ bssl_cnt=$(LD_LIBRARY_PATH=$BSSL $CURL "${CURL_PARAMS[@]}" -V 2> /dev/null | grep -c BoringSSL)
266
+ if ((bssl_cnt == 1))
267
+ then
268
+ using_bssl="yes"
269
+ # setup access to our .so
270
+ export LD_LIBRARY_PATH=$BSSL
271
+ fi
272
+ wolf_cnt=$($CURL "${CURL_PARAMS[@]}" -V 2> /dev/null | grep -c wolfSSL)
273
+ if ((wolf_cnt == 1))
274
+ then
275
+ using_wolf="yes"
276
+ # for some reason curl+wolfSSL dislikes certs that are ok
277
+ # for browsers, so we'll test using "insecure" mode (-k)
278
+ # but that's ok here as we're only interested in ECH testing
279
+ CURL_PARAMS+=(-k)
280
+ fi
281
+ # check if we have dig and it knows https or not
282
+ digcmd="dig +short"
283
+ wdig=$(type -p dig)
284
+ if [[ "$wdig" != "" ]]
285
+ then
286
+ have_dig="yes"
287
+ fi
288
+ wkdig=$(type -p kdig)
289
+ if [[ "$wkdig" != "" ]]
290
+ then
291
+ have_kdig="yes"
292
+ digcmd="kdig @$DOHSERVER +https +short"
293
+ fi
294
+ # see if our dig version knows HTTPS
295
+ dout=$($digcmd https defo.ie)
296
+ if [[ $dout != "1 . "* ]]
297
+ then
298
+ dout=$($digcmd -t TYPE65 defo.ie)
299
+ if [[ $dout == "1 . "* ]]
300
+ then
301
+ # we're good
302
+ have_presout="yes"
303
+ fi
304
+ else
305
+ have_presout="yes"
306
+ fi
307
+
308
+ # Check if ports other than 443 are blocked from this
309
+ # vantage point (I run tests in a n/w where that's
310
+ # sadly true sometimes;-)
311
+ # echo "Checking if ports other than 443 are maybe blocked"
312
+ not443testurl="https://draft-13.esni.defo.ie:9413/"
313
+ timeout "$tout" "$CURL" "${CURL_PARAMS[@]}" "$not443testurl" >/dev/null 2>&1
314
+ eres=$?
315
+ if [[ "$eres" == "124" ]]
316
+ then
317
+ echo "Timeout running curl for $not443testurl" >> "$logfile"
318
+ echo "Timeout running curl for $not443testurl"
319
+ have_portsblocked="yes"
320
+ fi
321
+
322
+ {
323
+ echo "have_ossl: $have_ossl"
324
+ echo "have_wolf: $have_wolf"
325
+ echo "have_bssl: $have_bssl"
326
+ echo "using_ossl: $using_ossl"
327
+ echo "using_wolf: $using_wolf"
328
+ echo "using_bssl: $using_bssl"
329
+ echo "have_curl: $have_curl"
330
+ echo "have_dig: $have_dig"
331
+ echo "have_kdig: $have_kdig"
332
+ echo "have_presout: $have_presout"
333
+ echo "have_portsblocked: $have_portsblocked"
334
+ } >> "$logfile"
335
+
336
+ echo "curl: have $have_curl, cURL command: |$CURL ${CURL_PARAMS[*]}|"
337
+ echo "ossl: have: $have_ossl, using: $using_ossl"
338
+ echo "wolf: have: $have_wolf, using: $using_wolf"
339
+ echo "bssl: have: $have_bssl, using: $using_bssl"
340
+ echo "dig: $have_dig, kdig: $have_kdig, HTTPS pres format: $have_presout"
341
+ echo "dig command: |$digcmd|"
342
+ echo "ports != 443 blocked: $have_portsblocked"
343
+
344
+ if [[ "$have_curl" == "no" ]]
345
+ then
346
+ echo "Can't proceed without curl - exiting"
347
+ exit 32
348
+ fi
349
+
350
+ allgood="yes"
351
+
352
+ skip="false"
353
+
354
+ if [[ "$skip" != "true" ]]
355
+ then
356
+
357
+ # basic ECH good/bad
358
+ for targ in "${!ech_targets[@]}"
359
+ do
360
+ if [[ "$using_wolf" == "yes" ]]
361
+ then
362
+ case $targ in
363
+ "draft-13.esni.defo.ie:8414" | "tls-ech.dev" | \
364
+ "crypto.cloudflare.com" | "epochbelt.com")
365
+ echo "Skipping $targ 'cause wolf"; continue;;
366
+ *)
367
+ ;;
368
+ esac
369
+ fi
370
+ host=$(hostport2host "$targ")
371
+ port=$(hostport2port "$targ")
372
+ if [[ "$port" != "443" && "$have_portsblocked" == "yes" ]]
373
+ then
374
+ echo "Skipping $targ as ports != 443 seem blocked"
375
+ continue
376
+ fi
377
+ path=${ech_targets[$targ]}
378
+ turl="https://$host:$port/$path"
379
+ echo "ECH check for $turl"
380
+ {
381
+ echo ""
382
+ echo "ECH check for $turl"
383
+ } >> "$logfile"
384
+ timeout "$tout" "$CURL" "${CURL_PARAMS[@]}" --ech hard "$turl" >> "$logfile" 2>&1
385
+ eres=$?
386
+ if [[ "$eres" == "124" ]]
387
+ then
388
+ allgood="no"
389
+ {
390
+ echo "Timeout for $turl"
391
+ echo -e "\tTimeout for $turl"
392
+ echo "Timeout running curl for $host:$port/$path"
393
+ } >> "$logfile"
394
+ fi
395
+ if [[ "$eres" != "0" ]]
396
+ then
397
+ allgood="no"
398
+ echo "Error ($eres) for $turl" >> "$logfile"
399
+ echo -e "\tError ($eres) for $turl"
400
+ fi
401
+ echo "" >> "$logfile"
402
+ done
403
+
404
+ # check if public_name override works (OpenSSL only)
405
+ if [[ "$using_ossl" == "yes" ]]
406
+ then
407
+ for targ in "${!ech_targets[@]}"
408
+ do
409
+ host=$(hostport2host "$targ")
410
+ port=$(hostport2port "$targ")
411
+ if [[ "$port" != "443" && "$have_portsblocked" == "yes" ]]
412
+ then
413
+ echo "Skipping $targ as ports != 443 seem blocked"
414
+ continue
415
+ fi
416
+ if [[ "$host" == "crypto.cloudflare.com" ]]
417
+ then
418
+ echo "Skipping $host as they've blocked PN override"
419
+ continue
420
+ fi
421
+ path=${ech_targets[$targ]}
422
+ turl="https://$host:$port/$path"
423
+ echo "PN override check for $turl"
424
+ {
425
+ echo ""
426
+ echo "PN override check for $turl"
427
+ } >> "$logfile"
428
+ timeout "$tout" "$CURL" "${CURL_PARAMS[@]}" --ech pn:override --ech hard "$turl" >> "$logfile" 2>&1
429
+ eres=$?
430
+ if [[ "$eres" == "124" ]]
431
+ then
432
+ allgood="no"
433
+ {
434
+ echo "Timeout for $turl"
435
+ echo -e "\tTimeout for $turl"
436
+ echo "Timeout running curl for $host:$port/$path"
437
+ } >> "$logfile"
438
+ fi
439
+ if [[ "$eres" != "0" ]]
440
+ then
441
+ allgood="no"
442
+ echo "PN override Error ($eres) for $turl" >> "$logfile"
443
+ echo -e "\tPN override Error ($eres) for $turl"
444
+ fi
445
+ echo "" >> "$logfile"
446
+ done
447
+ fi
448
+
449
+ for targ in "${!httpsrr_targets[@]}"
450
+ do
451
+ host=$(hostport2host "$targ")
452
+ port=$(hostport2port "$targ")
453
+ if [[ "$port" != "443" && "$have_portsblocked" == "yes" ]]
454
+ then
455
+ echo "Skipping $targ as ports != 443 seem blocked"
456
+ continue
457
+ fi
458
+ path=${httpsrr_targets[$targ]}
459
+ turl="https://$host:$port/$path"
460
+ echo "HTTPS RR but no ECHConfig check for $turl"
461
+ {
462
+ echo ""
463
+ echo "HTTPS RR but no ECHConfig check for $turl"
464
+ } >> "$logfile"
465
+ timeout "$tout" "$CURL" "${CURL_PARAMS[@]}" --ech true "$turl" >> "$logfile" 2>&1
466
+ eres=$?
467
+ if [[ "$eres" == "124" ]]
468
+ then
469
+ allgood="no"
470
+ {
471
+ echo "Timeout for $turl"
472
+ echo -e "\tTimeout for $turl"
473
+ echo "Timeout running curl for $host:$port/$path"
474
+ } >> "$logfile"
475
+ fi
476
+ if [[ "$eres" != "0" ]]
477
+ then
478
+ allgood="no"
479
+ echo "Error ($eres) for $turl" >> "$logfile"
480
+ echo -e "\tError ($eres) for $turl"
481
+ fi
482
+ echo "" >> "$logfile"
483
+ done
484
+
485
+ for targ in "${!neither_targets[@]}"
486
+ do
487
+ host=$(hostport2host "$targ")
488
+ port=$(hostport2port "$targ")
489
+ if [[ "$port" != "443" && "$have_portsblocked" == "yes" ]]
490
+ then
491
+ echo "Skipping $targ as ports != 443 seem blocked"
492
+ continue
493
+ fi
494
+ path=${neither_targets[$targ]}
495
+ turl="https://$host:$port/$path"
496
+ echo "Neither HTTPS nor ECHConfig check for $turl"
497
+ {
498
+ echo ""
499
+ echo "Neither HTTPS nor ECHConfig check for $turl"
500
+ } >> "$logfile"
501
+ timeout "$tout" "$CURL" "${CURL_PARAMS[@]}" --ech true "$turl" >> "$logfile" 2>&1
502
+ eres=$?
503
+ if [[ "$eres" == "124" ]]
504
+ then
505
+ allgood="no"
506
+ {
507
+ echo "Timeout for $turl"
508
+ echo -e "\tTimeout for $turl"
509
+ echo "Timeout running curl for $host:$port/$path"
510
+ } >> "$logfile"
511
+ fi
512
+ if [[ "$eres" != "0" ]]
513
+ then
514
+ allgood="no"
515
+ echo "Error ($eres) for $turl" >> "$logfile"
516
+ echo -e "\tError ($eres) for $turl"
517
+ fi
518
+ echo "" >> "$logfile"
519
+ done
520
+
521
+
522
+ # Check various command line options, if we're good so far
523
+ if [[ "$using_ossl" == "yes" && "$allgood" == "yes" ]]
524
+ then
525
+ # use this test URL as it'll tell us if things worked
526
+ turl="https://defo.ie/ech-check.php"
527
+ echo "cli_test with $turl"
528
+ echo "cli_test with $turl" >> "$logfile"
529
+ cli_test "$turl" 1 1 --ech true
530
+ cli_test "$turl" 1 0 --ech false
531
+ cli_test "$turl" 1 1 --ech false --ech true
532
+ cli_test "$turl" 1 1 --ech false --ech true --ech pn:foobar
533
+ cli_test "$turl" 1 1 --ech false --ech pn:foobar --ech true
534
+ echconfiglist=$(get_ech_configlist defo.ie)
535
+ cli_test "$turl" 1 1 --ech ecl:"$echconfiglist"
536
+ cli_test "$turl" 1 0 --ech ecl:
537
+ fi
538
+
539
+ fi # skip
540
+
541
+ # Check combinations of command line options, if we're good so far
542
+ # Most of this only works for OpenSSL, which is ok, as we're checking
543
+ # the argument handling here, not the ECH protocol
544
+ if [[ "$using_ossl" == "yes" && "$allgood" == "yes" ]]
545
+ then
546
+ # ech can be hard, true, grease or false
547
+ # ecl:ecl can be correct, incorrect or missing
548
+ # ech:pn can be correct, incorrect or missing
549
+ # in all cases the "last" argument provided should "win"
550
+ # but only one of hard, true, grease or false will apply
551
+ turl="https://defo.ie/ech-check.php"
552
+ echconfiglist=$(get_ech_configlist defo.ie)
553
+ goodecl=$echconfiglist
554
+ echconfiglist=$(get_ech_configlist hidden.hoba.ie)
555
+ badecl=$echconfiglist
556
+ goodpn="cover.defo.ie"
557
+ badpn="hoba.ie"
558
+ echo "more cli_test with $turl"
559
+ echo "more cli_test with $turl" >> "$logfile"
560
+
561
+ # The combinatorics here are handled via the tests/ech_combos.py script
562
+ # which produces all the relevant combinations or inputs and orders
563
+ # thereof. We have to manually assess whether or not ECH is expected to
564
+ # work for each case.
565
+ cli_test "$turl" 0 0
566
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
567
+ cli_test "$turl" 0 0 --ech ecl:"$badecl"
568
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
569
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech ecl:"$goodecl"
570
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
571
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech ecl:"$goodecl" --ech pn:"$goodpn"
572
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
573
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard
574
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
575
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl"
576
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
577
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
578
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
579
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech pn:"$goodpn"
580
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
581
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech true
582
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
583
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl"
584
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
585
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
586
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
587
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech true --ech pn:"$goodpn"
588
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
589
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn"
590
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
591
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl"
592
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
593
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
594
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
595
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard
596
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
597
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
598
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
599
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
600
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
601
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
602
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
603
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true
604
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
605
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
606
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
607
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
608
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
609
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
610
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
611
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech pn:"$goodpn"
612
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
613
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true
614
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
615
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
616
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
617
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
618
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
619
+ cli_test "$turl" - 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
620
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
621
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$goodpn"
622
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
623
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech true
624
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
625
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl"
626
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
627
+ cli_test "$turl" 1 1 --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
628
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
629
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech true --ech pn:"$goodpn"
630
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
631
+ cli_test "$turl" 1 1 --ech ecl:"$goodecl"
632
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
633
+ cli_test "$turl" 1 1 --ech ecl:"$goodecl" --ech pn:"$goodpn"
634
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
635
+ cli_test "$turl" 1 0 --ech false
636
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
637
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl"
638
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
639
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech ecl:"$goodecl"
640
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
641
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech ecl:"$goodecl" --ech pn:"$goodpn"
642
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
643
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard
644
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
645
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl"
646
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
647
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
648
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
649
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech pn:"$goodpn"
650
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
651
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech true
652
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
653
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl"
654
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
655
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
656
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
657
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech true --ech pn:"$goodpn"
658
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
659
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn"
660
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
661
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl"
662
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
663
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
664
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
665
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard
666
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
667
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
668
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
669
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
670
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
671
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
672
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
673
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true
674
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
675
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
676
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
677
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
678
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
679
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
680
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
681
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech pn:"$goodpn"
682
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
683
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true
684
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
685
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
686
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
687
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
688
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
689
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
690
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
691
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$badecl" --ech pn:"$goodpn"
692
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
693
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech true
694
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
695
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl"
696
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
697
+ cli_test "$turl" 1 1 --ech false --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
698
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
699
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech true --ech pn:"$goodpn"
700
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
701
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$goodecl"
702
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
703
+ cli_test "$turl" 1 0 --ech false --ech ecl:"$goodecl" --ech pn:"$goodpn"
704
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
705
+ cli_test "$turl" 1 1 --ech false --ech hard
706
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
707
+ cli_test "$turl" 1 1 --ech false --ech hard --ech ecl:"$goodecl"
708
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
709
+ cli_test "$turl" 1 1 --ech false --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
710
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
711
+ cli_test "$turl" 1 1 --ech false --ech hard --ech pn:"$goodpn"
712
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
713
+ cli_test "$turl" 1 1 --ech false --ech hard --ech true
714
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
715
+ cli_test "$turl" 1 1 --ech false --ech hard --ech true --ech ecl:"$goodecl"
716
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
717
+ cli_test "$turl" 1 1 --ech false --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
718
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
719
+ cli_test "$turl" 1 1 --ech false --ech hard --ech true --ech pn:"$goodpn"
720
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
721
+ cli_test "$turl" 1 0 --ech false --ech pn:"$badpn"
722
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
723
+ cli_test "$turl" 1 0 --ech false --ech pn:"$badpn" --ech ecl:"$goodecl"
724
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
725
+ cli_test "$turl" 1 0 --ech false --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
726
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
727
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard
728
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
729
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
730
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
731
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
732
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
733
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
734
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
735
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech true
736
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
737
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
738
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
739
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
740
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
741
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
742
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
743
+ cli_test "$turl" 1 0 --ech false --ech pn:"$badpn" --ech pn:"$goodpn"
744
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
745
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech true
746
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
747
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
748
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
749
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
750
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
751
+ cli_test "$turl" 1 1 --ech false --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
752
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
753
+ cli_test "$turl" 1 0 --ech false --ech pn:"$goodpn"
754
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
755
+ cli_test "$turl" 1 1 --ech false --ech true
756
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
757
+ cli_test "$turl" 1 1 --ech false --ech true --ech ecl:"$goodecl"
758
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
759
+ cli_test "$turl" 1 1 --ech false --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
760
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
761
+ cli_test "$turl" 1 1 --ech false --ech true --ech pn:"$goodpn"
762
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
763
+ cli_test "$turl" 1 1 --ech hard
764
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
765
+ cli_test "$turl" 1 1 --ech hard --ech ecl:"$goodecl"
766
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
767
+ cli_test "$turl" 1 1 --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
768
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
769
+ cli_test "$turl" 1 1 --ech hard --ech pn:"$goodpn"
770
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
771
+ cli_test "$turl" 1 1 --ech hard --ech true
772
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
773
+ cli_test "$turl" 1 1 --ech hard --ech true --ech ecl:"$goodecl"
774
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
775
+ cli_test "$turl" 1 1 --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
776
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
777
+ cli_test "$turl" 1 1 --ech hard --ech true --ech pn:"$goodpn"
778
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
779
+ cli_test "$turl" 1 0 --ech pn:"$badpn"
780
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
781
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech ecl:"$goodecl"
782
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
783
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
784
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
785
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard
786
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
787
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
788
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
789
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
790
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
791
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
792
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
793
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech true
794
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
795
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
796
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
797
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
798
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
799
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
800
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
801
+ cli_test "$turl" 1 0 --ech pn:"$badpn" --ech pn:"$goodpn"
802
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
803
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech true
804
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
805
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
806
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
807
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
808
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
809
+ cli_test "$turl" 1 1 --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
810
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
811
+ cli_test "$turl" 1 0 --ech pn:"$goodpn"
812
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
813
+ cli_test "$turl" 1 1 --ech true
814
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
815
+ cli_test "$turl" 1 1 --ech true --ech ecl:"$goodecl"
816
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
817
+ cli_test "$turl" 1 1 --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
818
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
819
+ cli_test "$turl" 1 1 --ech true --ech pn:"$goodpn"
820
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
821
+ cli_test "$turl" 1 0
822
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
823
+ cli_test "$turl" 1 1 --ech ecl:"$goodecl"
824
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
825
+ cli_test "$turl" 1 1 --ech ecl:"$goodecl" --ech pn:"$goodpn"
826
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
827
+ cli_test "$turl" 1 0 --ech pn:"$goodpn"
828
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
829
+ cli_test "$turl" 1 1 --ech true
830
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
831
+ cli_test "$turl" 1 1 --ech true --ech ecl:"$goodecl"
832
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
833
+ cli_test "$turl" 1 1 --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
834
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
835
+ cli_test "$turl" 1 1 --ech true --ech pn:"$goodpn"
836
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
837
+
838
+ # a target URL that doesn't support ECH
839
+ turl="https://tcd.ie"
840
+ echo "cli_test with $turl"
841
+ echo "cli_test with $turl" >> "$logfile"
842
+ # the params below don't matter much here as we'll fail anyway
843
+ echconfiglist=$(get_ech_configlist defo.ie)
844
+ goodecl=$echconfiglist
845
+ badecl="$goodecl"
846
+ goodpn="tcd.ie"
847
+ badpn="tcd.ie"
848
+ cli_test "$turl" 1 0
849
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
850
+ cli_test "$turl" 0 0 --ech ecl:"$badecl"
851
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
852
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech ecl:"$goodecl"
853
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
854
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech ecl:"$goodecl" --ech pn:"$goodpn"
855
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
856
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard
857
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
858
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl"
859
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
860
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
861
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
862
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech pn:"$goodpn"
863
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
864
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech true
865
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
866
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl"
867
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
868
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
869
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
870
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech hard --ech true --ech pn:"$goodpn"
871
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
872
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn"
873
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
874
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl"
875
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
876
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
877
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
878
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard
879
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
880
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
881
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
882
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
883
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
884
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
885
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
886
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true
887
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
888
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
889
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
890
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
891
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
892
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
893
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
894
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech pn:"$goodpn"
895
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
896
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true
897
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
898
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
899
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
900
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
901
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
902
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
903
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
904
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech pn:"$goodpn"
905
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
906
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech true
907
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
908
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl"
909
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
910
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
911
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
912
+ cli_test "$turl" 0 0 --ech ecl:"$badecl" --ech true --ech pn:"$goodpn"
913
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
914
+ cli_test "$turl" 0 0 --ech ecl:"$goodecl"
915
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
916
+ cli_test "$turl" 0 0 --ech ecl:"$goodecl" --ech pn:"$goodpn"
917
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
918
+ cli_test "$turl" 0 0 --ech false
919
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
920
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl"
921
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
922
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech ecl:"$goodecl"
923
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
924
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech ecl:"$goodecl" --ech pn:"$goodpn"
925
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
926
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard
927
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
928
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl"
929
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
930
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
931
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
932
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech pn:"$goodpn"
933
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
934
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech true
935
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
936
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl"
937
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
938
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
939
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
940
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech hard --ech true --ech pn:"$goodpn"
941
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
942
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn"
943
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
944
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl"
945
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
946
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
947
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
948
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard
949
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
950
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
951
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
952
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
953
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
954
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
955
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
956
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true
957
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
958
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
959
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
960
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
961
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
962
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
963
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
964
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech pn:"$goodpn"
965
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
966
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true
967
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
968
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
969
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
970
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
971
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
972
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
973
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
974
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech pn:"$goodpn"
975
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
976
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech true
977
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
978
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl"
979
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
980
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
981
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
982
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$badecl" --ech true --ech pn:"$goodpn"
983
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
984
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$goodecl"
985
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
986
+ cli_test "$turl" 0 0 --ech false --ech ecl:"$goodecl" --ech pn:"$goodpn"
987
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
988
+ cli_test "$turl" 0 0 --ech false --ech hard
989
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
990
+ cli_test "$turl" 0 0 --ech false --ech hard --ech ecl:"$goodecl"
991
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
992
+ cli_test "$turl" 0 0 --ech false --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
993
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
994
+ cli_test "$turl" 0 0 --ech false --ech hard --ech pn:"$goodpn"
995
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
996
+ cli_test "$turl" 0 0 --ech false --ech hard --ech true
997
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
998
+ cli_test "$turl" 0 0 --ech false --ech hard --ech true --ech ecl:"$goodecl"
999
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1000
+ cli_test "$turl" 0 0 --ech false --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1001
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1002
+ cli_test "$turl" 0 0 --ech false --ech hard --ech true --ech pn:"$goodpn"
1003
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1004
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn"
1005
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1006
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech ecl:"$goodecl"
1007
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1008
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
1009
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1010
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard
1011
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1012
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
1013
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1014
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
1015
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1016
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
1017
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1018
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech true
1019
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1020
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
1021
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1022
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1023
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1024
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
1025
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1026
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech pn:"$goodpn"
1027
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1028
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech true
1029
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1030
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
1031
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1032
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1033
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1034
+ cli_test "$turl" 0 0 --ech false --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
1035
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1036
+ cli_test "$turl" 0 0 --ech false --ech pn:"$goodpn"
1037
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1038
+ cli_test "$turl" 0 0 --ech false --ech true
1039
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1040
+ cli_test "$turl" 0 0 --ech false --ech true --ech ecl:"$goodecl"
1041
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1042
+ cli_test "$turl" 0 0 --ech false --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1043
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1044
+ cli_test "$turl" 0 0 --ech false --ech true --ech pn:"$goodpn"
1045
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1046
+ cli_test "$turl" 0 0 --ech hard
1047
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1048
+ cli_test "$turl" 0 0 --ech hard --ech ecl:"$goodecl"
1049
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1050
+ cli_test "$turl" 0 0 --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
1051
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1052
+ cli_test "$turl" 0 0 --ech hard --ech pn:"$goodpn"
1053
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1054
+ cli_test "$turl" 0 0 --ech hard --ech true
1055
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1056
+ cli_test "$turl" 0 0 --ech hard --ech true --ech ecl:"$goodecl"
1057
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1058
+ cli_test "$turl" 0 0 --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1059
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1060
+ cli_test "$turl" 0 0 --ech hard --ech true --ech pn:"$goodpn"
1061
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1062
+ cli_test "$turl" 0 0 --ech pn:"$badpn"
1063
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1064
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech ecl:"$goodecl"
1065
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1066
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech ecl:"$goodecl" --ech pn:"$goodpn"
1067
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1068
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard
1069
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1070
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl"
1071
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1072
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech ecl:"$goodecl" --ech pn:"$goodpn"
1073
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1074
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech pn:"$goodpn"
1075
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1076
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech true
1077
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1078
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl"
1079
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1080
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1081
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1082
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech hard --ech true --ech pn:"$goodpn"
1083
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1084
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech pn:"$goodpn"
1085
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1086
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech true
1087
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1088
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech true --ech ecl:"$goodecl"
1089
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1090
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1091
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1092
+ cli_test "$turl" 0 0 --ech pn:"$badpn" --ech true --ech pn:"$goodpn"
1093
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1094
+ cli_test "$turl" 0 0 --ech pn:"$goodpn"
1095
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1096
+ cli_test "$turl" 0 0 --ech true
1097
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1098
+ cli_test "$turl" 0 0 --ech true --ech ecl:"$goodecl"
1099
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1100
+ cli_test "$turl" 0 0 --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1101
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1102
+ cli_test "$turl" 0 0 --ech true --ech pn:"$goodpn"
1103
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1104
+ cli_test "$turl" 0 0
1105
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1106
+ cli_test "$turl" 0 0 --ech ecl:"$goodecl"
1107
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1108
+ cli_test "$turl" 0 0 --ech ecl:"$goodecl" --ech pn:"$goodpn"
1109
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1110
+ cli_test "$turl" 0 0 --ech pn:"$goodpn"
1111
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1112
+ cli_test "$turl" 0 0 --ech true
1113
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1114
+ cli_test "$turl" 0 0 --ech true --ech ecl:"$goodecl"
1115
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1116
+ cli_test "$turl" 0 0 --ech true --ech ecl:"$goodecl" --ech pn:"$goodpn"
1117
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1118
+ cli_test "$turl" 0 0 --ech true --ech pn:"$goodpn"
1119
+ if [[ "$allgood" != "yes" ]]; then echo "$LINENO"; fi
1120
+ fi
1121
+
1122
+
1123
+ END=$(whenisitagain)
1124
+ echo "Finished $0 at $END" >> "$logfile"
1125
+ echo "-----" >> "$logfile"
1126
+
1127
+ if [[ "$allgood" == "yes" ]]
1128
+ then
1129
+ echo "Finished $0 at $END"
1130
+ echo "All good, log in $logfile"
1131
+ exit 0
1132
+ else
1133
+ echo "Finished $0 at $END"
1134
+ echo "NOT all good, log in $logfile"
1135
+ fi
1136
+
1137
+ # send a mail to root (will be fwd'd) but just once every 24 hours
1138
+ # 'cause we only really need "new" news
1139
+ itsnews="yes"
1140
+ age_of_news=0
1141
+ if [ -f "$LTOP"/bad_runs ]
1142
+ then
1143
+ age_of_news=$(fileage "$LTOP"/bad_runs)
1144
+ # only consider news "new" if we haven't mailed today
1145
+ if ((age_of_news < 24*3600))
1146
+ then
1147
+ itsnews="no"
1148
+ fi
1149
+ fi
1150
+ if [[ "$DOMAIL" == "yes" && "$itsnews" == "yes" ]]
1151
+ then
1152
+ echo "ECH badness at $NOW" | mail -s "ECH badness at $NOW" root
1153
+ fi
1154
+ # add to list of bad runs (updating file age)
1155
+ echo "ECH badness at $NOW" >>"$LTOP"/bad_runs
1156
+ exit 2
local-test-curl-delta-01/afc-curl/tests/ftpserver.pl ADDED
@@ -0,0 +1,3376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # This is a server designed for the curl test suite.
27
+ #
28
+ # In December 2009 we started remaking the server to support more protocols
29
+ # that are similar in spirit. Like POP3, IMAP and SMTP in addition to the FTP
30
+ # it already supported since a long time. Note that it still only supports one
31
+ # protocol per invoke. You need to start multiple servers to support multiple
32
+ # protocols simultaneously.
33
+ #
34
+ # It is meant to exercise curl, it is not meant to be a fully working
35
+ # or even very standard compliant server.
36
+ #
37
+ # You may optionally specify port on the command line, otherwise it'll
38
+ # default to port 8921.
39
+ #
40
+ # All socket/network/TCP related stuff is done by the 'sockfilt' program.
41
+ #
42
+
43
+ use strict;
44
+ use warnings;
45
+
46
+ BEGIN {
47
+ push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
48
+ push(@INC, ".");
49
+ }
50
+
51
+ use IPC::Open2;
52
+ use Digest::MD5;
53
+ use File::Basename;
54
+
55
+ use directories;
56
+
57
+ use getpart qw(
58
+ getpartattr
59
+ getpart
60
+ loadtest
61
+ );
62
+
63
+ use processhelp;
64
+
65
+ use serverhelp qw(
66
+ logmsg
67
+ $logfile
68
+ servername_str
69
+ server_pidfilename
70
+ server_logfilename
71
+ mainsockf_pidfilename
72
+ mainsockf_logfilename
73
+ datasockf_pidfilename
74
+ datasockf_logfilename
75
+ );
76
+
77
+ use pathhelp qw(
78
+ exe_ext
79
+ );
80
+
81
+ use globalconfig qw(
82
+ $SERVERCMD
83
+ $LOCKDIR
84
+ );
85
+
86
+ #**********************************************************************
87
+ # global vars...
88
+ #
89
+ my $verbose = 0; # set to 1 for debugging
90
+ my $idstr = ""; # server instance string
91
+ my $idnum = 1; # server instance number
92
+ my $ipvnum = 4; # server IPv number (4 or 6)
93
+ my $proto = 'ftp'; # default server protocol
94
+ my $srcdir; # directory where ftpserver.pl is located
95
+ my $srvrname; # server name for presentation purposes
96
+ my $cwd_testno; # test case numbers extracted from CWD command
97
+ my $testno = 0; # test case number (read from server.cmd)
98
+ my $path = '.';
99
+ my $logdir = $path .'/log';
100
+ my $piddir;
101
+
102
+ #**********************************************************************
103
+ # global vars used for server address and primary listener port
104
+ #
105
+ my $port = 8921; # default primary listener port
106
+ my $listenaddr = '127.0.0.1'; # default address for listener port
107
+
108
+ #**********************************************************************
109
+ # global vars used for file names
110
+ #
111
+ my $PORTFILE="ftpserver.port"; # server port file name
112
+ my $portfile; # server port file path
113
+ my $pidfile; # server pid file name
114
+ my $mainsockf_pidfile; # pid file for primary connection sockfilt process
115
+ my $mainsockf_logfile; # log file for primary connection sockfilt process
116
+ my $datasockf_pidfile; # pid file for secondary connection sockfilt process
117
+ my $datasockf_logfile; # log file for secondary connection sockfilt process
118
+
119
+ #**********************************************************************
120
+ # global vars used for server logs advisor read lock handling
121
+ #
122
+ my $serverlogs_lockfile;
123
+ my $serverlogslocked = 0;
124
+
125
+ #**********************************************************************
126
+ # global vars used for child processes PID tracking
127
+ #
128
+ my $sfpid; # PID for primary connection sockfilt process
129
+ my $slavepid; # PID for secondary connection sockfilt process
130
+
131
+ #**********************************************************************
132
+ # global typeglob filehandle vars to read/write from/to sockfilters
133
+ #
134
+ local *SFREAD; # used to read from primary connection
135
+ local *SFWRITE; # used to write to primary connection
136
+ local *DREAD; # used to read from secondary connection
137
+ local *DWRITE; # used to write to secondary connection
138
+
139
+ my $sockfilt_timeout = 5; # default timeout for sockfilter eXsysreads
140
+
141
+ #**********************************************************************
142
+ # global vars which depend on server protocol selection
143
+ #
144
+ my %commandfunc; # protocol command specific function callbacks
145
+ my %displaytext; # text returned to client before callback runs
146
+
147
+ #**********************************************************************
148
+ # global vars customized for each test from the server commands file
149
+ #
150
+ my $ctrldelay; # set if server should throttle ctrl stream
151
+ my $datadelay; # set if server should throttle data stream
152
+ my $retrweirdo; # set if ftp server should use RETRWEIRDO
153
+ my $retrnosize; # set if ftp server should use RETRNOSIZE
154
+ my $retrsize; # set if ftp server should use RETRSIZE
155
+ my $pasvbadip; # set if ftp server should use PASVBADIP
156
+ my $nosave; # set if ftp server should not save uploaded data
157
+ my $nodataconn; # set if ftp srvr doesn't establish or accepts data channel
158
+ my $nodataconn425; # set if ftp srvr doesn't establish data ch and replies 425
159
+ my $nodataconn421; # set if ftp srvr doesn't establish data ch and replies 421
160
+ my $nodataconn150; # set if ftp srvr doesn't establish data ch and replies 150
161
+ my $storeresp;
162
+ my $postfetch;
163
+ my @capabilities; # set if server supports capability commands
164
+ my @auth_mechs; # set if server supports authentication commands
165
+ my %fulltextreply; #
166
+ my %commandreply; #
167
+ my %customcount; #
168
+ my %delayreply; #
169
+
170
+ #**********************************************************************
171
+ # global variables for to test ftp wildcardmatching or other test that
172
+ # need flexible LIST responses.. and corresponding files.
173
+ # $ftptargetdir is keeping the fake "name" of LIST directory.
174
+ #
175
+ my $ftplistparserstate;
176
+ my $ftptargetdir="";
177
+
178
+ #**********************************************************************
179
+ # global variables used when running a ftp server to keep state info
180
+ # relative to the secondary or data sockfilt process. Values of these
181
+ # variables should only be modified using datasockf_state() sub, given
182
+ # that they are closely related and relationship is a bit awkward.
183
+ #
184
+ my $datasockf_state = 'STOPPED'; # see datasockf_state() sub
185
+ my $datasockf_mode = 'none'; # ['none','active','passive']
186
+ my $datasockf_runs = 'no'; # ['no','yes']
187
+ my $datasockf_conn = 'no'; # ['no','yes']
188
+
189
+ #**********************************************************************
190
+ # global vars used for signal handling
191
+ #
192
+ my $got_exit_signal = 0; # set if program should finish execution ASAP
193
+ my $exit_signal; # first signal handled in exit_signal_handler
194
+
195
+ #**********************************************************************
196
+ # Mail related definitions
197
+ #
198
+ my $TEXT_PASSWORD = "secret";
199
+ my $POP3_TIMESTAMP = "<1972.987654321\@curl>";
200
+
201
+ #**********************************************************************
202
+ # exit_signal_handler will be triggered to indicate that the program
203
+ # should finish its execution in a controlled way as soon as possible.
204
+ # For now, program will also terminate from within this handler.
205
+ #
206
+ sub exit_signal_handler {
207
+ my $signame = shift;
208
+ # For now, simply mimic old behavior.
209
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
210
+ unlink($pidfile);
211
+ unlink($portfile);
212
+ if($serverlogslocked) {
213
+ $serverlogslocked = 0;
214
+ clear_advisor_read_lock($serverlogs_lockfile);
215
+ }
216
+ exit;
217
+ }
218
+
219
+ sub ftpmsg {
220
+ # append to the server.input file
221
+ open(my $input, ">>", "$logdir/server$idstr.input") ||
222
+ logmsg "failed to open $logdir/server$idstr.input\n";
223
+
224
+ print $input @_;
225
+ close($input);
226
+
227
+ # use this, open->print->close system only to make the file
228
+ # open as little as possible, to make the test suite run
229
+ # better on Windows/Cygwin
230
+ }
231
+
232
+ #**********************************************************************
233
+ # eXsysread is a wrapper around perl's sysread() function. This will
234
+ # repeat the call to sysread() until it has actually read the complete
235
+ # number of requested bytes or an unrecoverable condition occurs.
236
+ # On success returns a positive value, the number of bytes requested.
237
+ # On failure or timeout returns zero.
238
+ #
239
+ sub eXsysread {
240
+ my $FH = shift;
241
+ my $scalar = shift;
242
+ my $nbytes = shift;
243
+ my $timeout = shift; # A zero timeout disables eXsysread() time limit
244
+ #
245
+ my $time_limited = 0;
246
+ my $timeout_rest = 0;
247
+ my $start_time = 0;
248
+ my $nread = 0;
249
+ my $rc;
250
+
251
+ $$scalar = "";
252
+
253
+ if((not defined $nbytes) || ($nbytes < 1)) {
254
+ logmsg "Error: eXsysread() failure: " .
255
+ "length argument must be positive\n";
256
+ return 0;
257
+ }
258
+ if((not defined $timeout) || ($timeout < 0)) {
259
+ logmsg "Error: eXsysread() failure: " .
260
+ "timeout argument must be zero or positive\n";
261
+ return 0;
262
+ }
263
+ if($timeout > 0) {
264
+ # caller sets eXsysread() time limit
265
+ $time_limited = 1;
266
+ $timeout_rest = $timeout;
267
+ $start_time = int(time());
268
+ }
269
+
270
+ while($nread < $nbytes) {
271
+ if($time_limited) {
272
+ eval {
273
+ local $SIG{ALRM} = sub { die "alarm\n"; };
274
+ alarm $timeout_rest;
275
+ $rc = sysread($FH, $$scalar, $nbytes - $nread, $nread);
276
+ alarm 0;
277
+ };
278
+ $timeout_rest = $timeout - (int(time()) - $start_time);
279
+ if($timeout_rest < 1) {
280
+ logmsg "Error: eXsysread() failure: timed out\n";
281
+ return 0;
282
+ }
283
+ }
284
+ else {
285
+ $rc = sysread($FH, $$scalar, $nbytes - $nread, $nread);
286
+ }
287
+ if($got_exit_signal) {
288
+ logmsg "Error: eXsysread() failure: signalled to die\n";
289
+ return 0;
290
+ }
291
+ if(not defined $rc) {
292
+ if($!{EINTR}) {
293
+ logmsg "Warning: retrying sysread() interrupted system call\n";
294
+ next;
295
+ }
296
+ if($!{EAGAIN}) {
297
+ logmsg "Warning: retrying sysread() due to EAGAIN\n";
298
+ next;
299
+ }
300
+ if($!{EWOULDBLOCK}) {
301
+ logmsg "Warning: retrying sysread() due to EWOULDBLOCK\n";
302
+ next;
303
+ }
304
+ logmsg "Error: sysread() failure: $!\n";
305
+ return 0;
306
+ }
307
+ if($rc < 0) {
308
+ logmsg "Error: sysread() failure: returned negative value $rc\n";
309
+ return 0;
310
+ }
311
+ if($rc == 0) {
312
+ logmsg "Error: sysread() failure: read zero bytes\n";
313
+ return 0;
314
+ }
315
+ $nread += $rc;
316
+ }
317
+ return $nread;
318
+ }
319
+
320
+ #**********************************************************************
321
+ # read_mainsockf attempts to read the given amount of output from the
322
+ # sockfilter which is in use for the main or primary connection. This
323
+ # reads untranslated sockfilt lingo which may hold data read from the
324
+ # main or primary socket. On success returns 1, otherwise zero.
325
+ #
326
+ sub read_mainsockf {
327
+ my $scalar = shift;
328
+ my $nbytes = shift;
329
+ my $timeout = shift; # Optional argument, if zero blocks indefinitely
330
+ my $FH = \*SFREAD;
331
+
332
+ if(not defined $timeout) {
333
+ $timeout = $sockfilt_timeout + ($nbytes >> 12);
334
+ }
335
+ if(eXsysread($FH, $scalar, $nbytes, $timeout) != $nbytes) {
336
+ my ($fcaller, $lcaller) = (caller)[1,2];
337
+ logmsg "Error: read_mainsockf() failure at $fcaller " .
338
+ "line $lcaller. Due to eXsysread() failure\n";
339
+ return 0;
340
+ }
341
+ return 1;
342
+ }
343
+
344
+ #**********************************************************************
345
+ # read_datasockf attempts to read the given amount of output from the
346
+ # sockfilter which is in use for the data or secondary connection. This
347
+ # reads untranslated sockfilt lingo which may hold data read from the
348
+ # data or secondary socket. On success returns 1, otherwise zero.
349
+ #
350
+ sub read_datasockf {
351
+ my $scalar = shift;
352
+ my $nbytes = shift;
353
+ my $timeout = shift; # Optional argument, if zero blocks indefinitely
354
+ my $FH = \*DREAD;
355
+
356
+ if(not defined $timeout) {
357
+ $timeout = $sockfilt_timeout + ($nbytes >> 12);
358
+ }
359
+ if(eXsysread($FH, $scalar, $nbytes, $timeout) != $nbytes) {
360
+ my ($fcaller, $lcaller) = (caller)[1,2];
361
+ logmsg "Error: read_datasockf() failure at $fcaller " .
362
+ "line $lcaller. Due to eXsysread() failure\n";
363
+ return 0;
364
+ }
365
+ return 1;
366
+ }
367
+
368
+ sub sysread_or_die {
369
+ my $FH = shift;
370
+ my $scalar = shift;
371
+ my $length = shift;
372
+ my $fcaller;
373
+ my $lcaller;
374
+ my $result;
375
+
376
+ $result = sysread($$FH, $$scalar, $length);
377
+
378
+ if(not defined $result) {
379
+ ($fcaller, $lcaller) = (caller)[1,2];
380
+ logmsg "Failed to read input\n";
381
+ logmsg "Error: $srvrname server, sysread error: $!\n";
382
+ logmsg "Exited from sysread_or_die() at $fcaller " .
383
+ "line $lcaller. $srvrname server, sysread error: $!\n";
384
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
385
+ unlink($pidfile);
386
+ unlink($portfile);
387
+ if($serverlogslocked) {
388
+ $serverlogslocked = 0;
389
+ clear_advisor_read_lock($serverlogs_lockfile);
390
+ }
391
+ exit;
392
+ }
393
+ elsif($result == 0) {
394
+ ($fcaller, $lcaller) = (caller)[1,2];
395
+ logmsg "Failed to read input\n";
396
+ logmsg "Error: $srvrname server, read zero\n";
397
+ logmsg "Exited from sysread_or_die() at $fcaller " .
398
+ "line $lcaller. $srvrname server, read zero\n";
399
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
400
+ unlink($pidfile);
401
+ unlink($portfile);
402
+ if($serverlogslocked) {
403
+ $serverlogslocked = 0;
404
+ clear_advisor_read_lock($serverlogs_lockfile);
405
+ }
406
+ exit;
407
+ }
408
+
409
+ return $result;
410
+ }
411
+
412
+ sub startsf {
413
+ my @mainsockfcmd = ("./server/sockfilt".exe_ext('SRV'),
414
+ "--ipv$ipvnum",
415
+ "--port", $port,
416
+ "--pidfile", $mainsockf_pidfile,
417
+ "--portfile", $portfile,
418
+ "--logfile", $mainsockf_logfile);
419
+ $sfpid = open2(*SFREAD, *SFWRITE, @mainsockfcmd);
420
+
421
+ print STDERR "@mainsockfcmd\n" if($verbose);
422
+
423
+ print SFWRITE "PING\n";
424
+ my $pong;
425
+ sysread_or_die(\*SFREAD, \$pong, 5);
426
+
427
+ if($pong !~ /^PONG/) {
428
+ logmsg "Failed sockfilt command: @mainsockfcmd\n";
429
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
430
+ unlink($pidfile);
431
+ unlink($portfile);
432
+ if($serverlogslocked) {
433
+ $serverlogslocked = 0;
434
+ clear_advisor_read_lock($serverlogs_lockfile);
435
+ }
436
+ die "Failed to start sockfilt!";
437
+ }
438
+ }
439
+
440
+ #**********************************************************************
441
+ # Returns the given test's reply data
442
+ #
443
+ sub getreplydata {
444
+ my ($num) = @_;
445
+ my $testpart = "";
446
+
447
+ $num =~ s/^([^0-9]*)//;
448
+ if($num > 10000) {
449
+ $testpart = $num % 10000;
450
+ }
451
+
452
+ my @data = getpart("reply", "data$testpart");
453
+ if((!@data) && ($testpart ne "")) {
454
+ @data = getpart("reply", "data");
455
+ }
456
+
457
+ return @data;
458
+ }
459
+
460
+ sub sockfilt {
461
+ my $l;
462
+ foreach $l (@_) {
463
+ printf SFWRITE "DATA\n%04x\n", length($l);
464
+ print SFWRITE $l;
465
+ }
466
+ }
467
+
468
+ sub sockfiltsecondary {
469
+ my $l;
470
+ foreach $l (@_) {
471
+ printf DWRITE "DATA\n%04x\n", length($l);
472
+ print DWRITE $l;
473
+ }
474
+ }
475
+
476
+ #**********************************************************************
477
+ # Send data to the client on the control stream, which happens to be plain
478
+ # stdout.
479
+ #
480
+ sub sendcontrol {
481
+ if(!$ctrldelay) {
482
+ # spit it all out at once
483
+ sockfilt @_;
484
+ }
485
+ else {
486
+ my $a = join("", @_);
487
+ my @a = split("", $a);
488
+
489
+ for(@a) {
490
+ sockfilt $_;
491
+ portable_sleep($ctrldelay);
492
+ }
493
+ }
494
+ my $log;
495
+ foreach $log (@_) {
496
+ my $l = $log;
497
+ $l =~ s/\r/[CR]/g;
498
+ $l =~ s/\n/[LF]/g;
499
+ logmsg "> \"$l\"\n";
500
+ }
501
+ }
502
+
503
+ #**********************************************************************
504
+ # Send data to the FTP client on the data stream when data connection
505
+ # is actually established. Given that this sub should only be called
506
+ # when a data connection is supposed to be established, calling this
507
+ # without a data connection is an indication of weak logic somewhere.
508
+ #
509
+ sub senddata {
510
+ my $l;
511
+ if($datasockf_conn eq 'no') {
512
+ logmsg "WARNING: Detected data sending attempt without DATA channel\n";
513
+ foreach $l (@_) {
514
+ logmsg "WARNING: Data swallowed: $l\n"
515
+ }
516
+ return;
517
+ }
518
+
519
+ foreach $l (@_) {
520
+ if(!$datadelay) {
521
+ # spit it all out at once
522
+ sockfiltsecondary $l;
523
+ }
524
+ else {
525
+ # pause between each byte
526
+ for (split(//,$l)) {
527
+ sockfiltsecondary $_;
528
+ portable_sleep($datadelay);
529
+ }
530
+ }
531
+ }
532
+ }
533
+
534
+ #**********************************************************************
535
+ # protocolsetup initializes the 'displaytext' and 'commandfunc' hashes
536
+ # for the given protocol. References to protocol command callbacks are
537
+ # stored in 'commandfunc' hash, and text which will be returned to the
538
+ # client before the command callback runs is stored in 'displaytext'.
539
+ #
540
+ sub protocolsetup {
541
+ my $proto = $_[0];
542
+
543
+ if($proto eq 'ftp') {
544
+ %commandfunc = (
545
+ 'PORT' => \&PORT_ftp,
546
+ 'EPRT' => \&PORT_ftp,
547
+ 'LIST' => \&LIST_ftp,
548
+ 'NLST' => \&NLST_ftp,
549
+ 'PASV' => \&PASV_ftp,
550
+ 'CWD' => \&CWD_ftp,
551
+ 'PWD' => \&PWD_ftp,
552
+ 'EPSV' => \&PASV_ftp,
553
+ 'RETR' => \&RETR_ftp,
554
+ 'SIZE' => \&SIZE_ftp,
555
+ 'REST' => \&REST_ftp,
556
+ 'STOR' => \&STOR_ftp,
557
+ 'APPE' => \&STOR_ftp, # append looks like upload
558
+ 'MDTM' => \&MDTM_ftp,
559
+ );
560
+ %displaytext = (
561
+ 'USER' => '331 We are happy you popped in!',
562
+ 'PASS' => '230 Welcome you silly person',
563
+ 'PORT' => '200 You said PORT - I say FINE',
564
+ 'TYPE' => '200 I modify TYPE as you wanted',
565
+ 'LIST' => '150 here comes a directory',
566
+ 'NLST' => '150 here comes a directory',
567
+ 'CWD' => '250 CWD command successful.',
568
+ 'SYST' => '215 UNIX Type: L8', # just fake something
569
+ 'QUIT' => '221 bye bye baby', # just reply something
570
+ 'MKD' => '257 Created your requested directory',
571
+ 'REST' => '350 Yeah yeah we set it there for you',
572
+ 'DELE' => '200 OK OK OK whatever you say',
573
+ 'RNFR' => '350 Received your order. Please provide more',
574
+ 'RNTO' => '250 Ok, thanks. File renaming completed.',
575
+ 'NOOP' => '200 Yes, I\'m very good at doing nothing.',
576
+ 'PBSZ' => '500 PBSZ not implemented',
577
+ 'PROT' => '500 PROT not implemented',
578
+ 'welcome' => join("",
579
+ '220- _ _ ____ _ '."\r\n",
580
+ '220- ___| | | | _ \| | '."\r\n",
581
+ '220- / __| | | | |_) | | '."\r\n",
582
+ '220- | (__| |_| | _ {| |___ '."\r\n",
583
+ '220 \___|\___/|_| \_\_____|'."\r\n")
584
+ );
585
+ }
586
+ elsif($proto eq 'pop3') {
587
+ %commandfunc = (
588
+ 'APOP' => \&APOP_pop3,
589
+ 'AUTH' => \&AUTH_pop3,
590
+ 'CAPA' => \&CAPA_pop3,
591
+ 'DELE' => \&DELE_pop3,
592
+ 'LIST' => \&LIST_pop3,
593
+ 'NOOP' => \&NOOP_pop3,
594
+ 'PASS' => \&PASS_pop3,
595
+ 'QUIT' => \&QUIT_pop3,
596
+ 'RETR' => \&RETR_pop3,
597
+ 'RSET' => \&RSET_pop3,
598
+ 'STAT' => \&STAT_pop3,
599
+ 'TOP' => \&TOP_pop3,
600
+ 'UIDL' => \&UIDL_pop3,
601
+ 'USER' => \&USER_pop3,
602
+ );
603
+ %displaytext = (
604
+ 'welcome' => join("",
605
+ ' _ _ ____ _ '."\r\n",
606
+ ' ___| | | | _ \| | '."\r\n",
607
+ ' / __| | | | |_) | | '."\r\n",
608
+ ' | (__| |_| | _ {| |___ '."\r\n",
609
+ ' \___|\___/|_| \_\_____|'."\r\n",
610
+ '+OK curl POP3 server ready to serve '."\r\n")
611
+ );
612
+ }
613
+ elsif($proto eq 'imap') {
614
+ %commandfunc = (
615
+ 'APPEND' => \&APPEND_imap,
616
+ 'CAPABILITY' => \&CAPABILITY_imap,
617
+ 'CHECK' => \&CHECK_imap,
618
+ 'CLOSE' => \&CLOSE_imap,
619
+ 'COPY' => \&COPY_imap,
620
+ 'CREATE' => \&CREATE_imap,
621
+ 'DELETE' => \&DELETE_imap,
622
+ 'EXAMINE' => \&EXAMINE_imap,
623
+ 'EXPUNGE' => \&EXPUNGE_imap,
624
+ 'FETCH' => \&FETCH_imap,
625
+ 'LIST' => \&LIST_imap,
626
+ 'LSUB' => \&LSUB_imap,
627
+ 'LOGIN' => \&LOGIN_imap,
628
+ 'LOGOUT' => \&LOGOUT_imap,
629
+ 'NOOP' => \&NOOP_imap,
630
+ 'RENAME' => \&RENAME_imap,
631
+ 'SEARCH' => \&SEARCH_imap,
632
+ 'SELECT' => \&SELECT_imap,
633
+ 'STATUS' => \&STATUS_imap,
634
+ 'STORE' => \&STORE_imap,
635
+ 'UID' => \&UID_imap,
636
+ 'IDLE' => \&IDLE_imap,
637
+ );
638
+ %displaytext = (
639
+ 'welcome' => join("",
640
+ ' _ _ ____ _ '."\r\n",
641
+ ' ___| | | | _ \| | '."\r\n",
642
+ ' / __| | | | |_) | | '."\r\n",
643
+ ' | (__| |_| | _ {| |___ '."\r\n",
644
+ ' \___|\___/|_| \_\_____|'."\r\n",
645
+ '* OK curl IMAP server ready to serve'."\r\n")
646
+ );
647
+ }
648
+ elsif($proto eq 'smtp') {
649
+ %commandfunc = (
650
+ 'DATA' => \&DATA_smtp,
651
+ 'EHLO' => \&EHLO_smtp,
652
+ 'EXPN' => \&EXPN_smtp,
653
+ 'HELO' => \&HELO_smtp,
654
+ 'HELP' => \&HELP_smtp,
655
+ 'MAIL' => \&MAIL_smtp,
656
+ 'NOOP' => \&NOOP_smtp,
657
+ 'RSET' => \&RSET_smtp,
658
+ 'RCPT' => \&RCPT_smtp,
659
+ 'VRFY' => \&VRFY_smtp,
660
+ 'QUIT' => \&QUIT_smtp,
661
+ );
662
+ %displaytext = (
663
+ 'welcome' => join("",
664
+ '220- _ _ ____ _ '."\r\n",
665
+ '220- ___| | | | _ \| | '."\r\n",
666
+ '220- / __| | | | |_) | | '."\r\n",
667
+ '220- | (__| |_| | _ {| |___ '."\r\n",
668
+ '220 \___|\___/|_| \_\_____|'."\r\n")
669
+ );
670
+ }
671
+ }
672
+
673
+ # Perform the disconnect handshake with sockfilt on the secondary connection
674
+ # (the only connection we actively disconnect).
675
+ # This involves waiting for the disconnect acknowledgment after the DISC
676
+ # command, while throwing away anything else that might come in before
677
+ # that.
678
+ sub disc_handshake {
679
+ print DWRITE "DISC\n";
680
+ my $line;
681
+ my $nr;
682
+ while (5 == ($nr = sysread DREAD, $line, 5)) {
683
+ if($line eq "DATA\n") {
684
+ # Must read the data bytes to stay in sync
685
+ my $i;
686
+ sysread DREAD, $i, 5;
687
+
688
+ my $size = 0;
689
+ if($i =~ /^([0-9a-fA-F]{4})\n/) {
690
+ $size = hex($1);
691
+ }
692
+
693
+ logmsg "> Throwing away $size bytes on closed connection\n";
694
+ read_datasockf(\$line, $size);
695
+ }
696
+ elsif($line eq "DISC\n") {
697
+ logmsg "Fancy that; client wants to DISC, too\n";
698
+ printf DWRITE "ACKD\n";
699
+ }
700
+ elsif($line eq "ACKD\n") {
701
+ # Got the ack we were waiting for
702
+ last;
703
+ }
704
+ else {
705
+ logmsg "Ignoring: $line";
706
+ # sockfilt should not be sending us any other commands
707
+ }
708
+ }
709
+ if(!defined($nr)) {
710
+ logmsg "Error: pipe read error ($!) while waiting for ACKD";
711
+ }
712
+ elsif($nr <= 0) {
713
+ logmsg "Error: pipe EOF while waiting for ACKD";
714
+ }
715
+ }
716
+
717
+ sub close_dataconn {
718
+ my ($closed)=@_; # non-zero if already disconnected
719
+
720
+ my $datapid = processexists($datasockf_pidfile);
721
+
722
+ logmsg "=====> Closing $datasockf_mode DATA connection...\n";
723
+
724
+ if(!$closed) {
725
+ if($datapid > 0) {
726
+ logmsg "Server disconnects $datasockf_mode DATA connection\n";
727
+ disc_handshake();
728
+ logmsg "Server disconnected $datasockf_mode DATA connection\n";
729
+ }
730
+ else {
731
+ logmsg "Server finds $datasockf_mode DATA connection already ".
732
+ "disconnected\n";
733
+ }
734
+ }
735
+ else {
736
+ logmsg "Server knows $datasockf_mode DATA connection is already ".
737
+ "disconnected\n";
738
+ }
739
+
740
+ if($datapid > 0) {
741
+ logmsg "DATA sockfilt for $datasockf_mode data channel quits ".
742
+ "(pid $datapid)\n";
743
+ print DWRITE "QUIT\n";
744
+ pidwait($datapid, 0);
745
+ unlink($datasockf_pidfile) if(-f $datasockf_pidfile);
746
+ logmsg "DATA sockfilt for $datasockf_mode data channel quit ".
747
+ "(pid $datapid)\n";
748
+ }
749
+ else {
750
+ logmsg "DATA sockfilt for $datasockf_mode data channel already ".
751
+ "dead\n";
752
+ }
753
+
754
+ logmsg "=====> Closed $datasockf_mode DATA connection\n";
755
+
756
+ datasockf_state('STOPPED');
757
+ }
758
+
759
+ ################
760
+ ################ SMTP commands
761
+ ################
762
+
763
+ # The type of server (SMTP or ESMTP)
764
+ my $smtp_type;
765
+
766
+ # The client (which normally contains the test number)
767
+ my $smtp_client;
768
+
769
+ sub EHLO_smtp {
770
+ my ($client) = @_;
771
+ my @data;
772
+
773
+ # TODO: Get the IP address of the client connection to use in the
774
+ # EHLO response when the client doesn't specify one but for now use
775
+ # 127.0.0.1
776
+ if(!$client) {
777
+ $client = "[127.0.0.1]";
778
+ }
779
+
780
+ # Set the server type to ESMTP
781
+ $smtp_type = "ESMTP";
782
+
783
+ # Calculate the EHLO response
784
+ push @data, "$smtp_type pingpong test server Hello $client";
785
+
786
+ if((@capabilities) || (@auth_mechs)) {
787
+ my $mechs;
788
+
789
+ for my $c (@capabilities) {
790
+ push @data, $c;
791
+ }
792
+
793
+ for my $am (@auth_mechs) {
794
+ if(!$mechs) {
795
+ $mechs = "$am";
796
+ }
797
+ else {
798
+ $mechs .= " $am";
799
+ }
800
+ }
801
+
802
+ if($mechs) {
803
+ push @data, "AUTH $mechs";
804
+ }
805
+ }
806
+
807
+ # Send the EHLO response
808
+ for(my $i = 0; $i < @data; $i++) {
809
+ my $d = $data[$i];
810
+
811
+ if($i < @data - 1) {
812
+ sendcontrol "250-$d\r\n";
813
+ }
814
+ else {
815
+ sendcontrol "250 $d\r\n";
816
+ }
817
+ }
818
+
819
+ # Store the client (as it may contain the test number)
820
+ $smtp_client = $client;
821
+
822
+ return 0;
823
+ }
824
+
825
+ sub HELO_smtp {
826
+ my ($client) = @_;
827
+
828
+ # TODO: Get the IP address of the client connection to use in the HELO
829
+ # response when the client doesn't specify one but for now use 127.0.0.1
830
+ if(!$client) {
831
+ $client = "[127.0.0.1]";
832
+ }
833
+
834
+ # Set the server type to SMTP
835
+ $smtp_type = "SMTP";
836
+
837
+ # Send the HELO response
838
+ sendcontrol "250 $smtp_type pingpong test server Hello $client\r\n";
839
+
840
+ # Store the client (as it may contain the test number)
841
+ $smtp_client = $client;
842
+
843
+ return 0;
844
+ }
845
+
846
+ sub MAIL_smtp {
847
+ my ($args) = @_;
848
+
849
+ logmsg "MAIL_smtp got $args\n";
850
+
851
+ if (!$args) {
852
+ sendcontrol "501 Unrecognized parameter\r\n";
853
+ }
854
+ else {
855
+ my $from;
856
+ my $size;
857
+ my $smtputf8 = grep /^SMTPUTF8$/, @capabilities;
858
+ my @elements = split(/ /, $args);
859
+
860
+ # Get the FROM and SIZE parameters
861
+ for my $e (@elements) {
862
+ if($e =~ /^FROM:(.*)$/) {
863
+ $from = $1;
864
+ }
865
+ elsif($e =~ /^SIZE=(\d+)$/) {
866
+ $size = $1;
867
+ }
868
+ }
869
+
870
+ # this server doesn't "validate" MAIL FROM addresses
871
+ if (length($from)) {
872
+ my @found;
873
+ my $valid = 1;
874
+
875
+ # Check the capabilities for SIZE and if the specified size is
876
+ # greater than the message size then reject it
877
+ if (@found = grep /^SIZE (\d+)$/, @capabilities) {
878
+ if ($found[0] =~ /^SIZE (\d+)$/) {
879
+ if ($size > $1) {
880
+ $valid = 0;
881
+ }
882
+ }
883
+ }
884
+
885
+ if(!$valid) {
886
+ sendcontrol "552 Message size too large\r\n";
887
+ }
888
+ else {
889
+ sendcontrol "250 Sender OK\r\n";
890
+ }
891
+ }
892
+ else {
893
+ sendcontrol "501 Invalid address\r\n";
894
+ }
895
+ }
896
+
897
+ return 0;
898
+ }
899
+
900
+ sub RCPT_smtp {
901
+ my ($args) = @_;
902
+
903
+ logmsg "RCPT_smtp got $args\n";
904
+
905
+ # Get the TO parameter
906
+ if($args !~ /^TO:(.*)/) {
907
+ sendcontrol "501 Unrecognized parameter\r\n";
908
+ }
909
+ else {
910
+ my $smtputf8 = grep /^SMTPUTF8$/, @capabilities;
911
+ my $to = $1;
912
+
913
+ # Validate the to address (only a valid email address inside <> is
914
+ # allowed, such as <user@example.com>)
915
+ if ((!$smtputf8 && $to =~
916
+ /^<([a-zA-Z0-9._%+-]+)\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4})>$/) ||
917
+ ($smtputf8 && $to =~
918
+ /^<([a-zA-Z0-9\x{80}-\x{ff}._%+-]+)\@(([a-zA-Z0-9\x{80}-\x{ff}-]+)\.)+([a-zA-Z]{2,4})>$/)) {
919
+ sendcontrol "250 Recipient OK\r\n";
920
+ }
921
+ else {
922
+ sendcontrol "501 Invalid address\r\n";
923
+ }
924
+ }
925
+
926
+ return 0;
927
+ }
928
+
929
+ sub DATA_smtp {
930
+ my ($args) = @_;
931
+
932
+ if ($args) {
933
+ sendcontrol "501 Unrecognized parameter\r\n";
934
+ }
935
+ elsif ($smtp_client !~ /^(\d*)$/) {
936
+ sendcontrol "501 Invalid arguments\r\n";
937
+ }
938
+ else {
939
+ sendcontrol "354 Show me the mail\r\n";
940
+
941
+ my $testno = $smtp_client;
942
+ my $filename = "$logdir/upload.$testno";
943
+
944
+ logmsg "Store test number $testno in $filename\n";
945
+
946
+ open(my $file, ">", "$filename") ||
947
+ return 0; # failed to open output
948
+
949
+ my $line;
950
+ my $ulsize=0;
951
+ my $disc=0;
952
+ my $raw;
953
+ while (5 == (sysread \*SFREAD, $line, 5)) {
954
+ if($line eq "DATA\n") {
955
+ my $i;
956
+ my $eob;
957
+ sysread \*SFREAD, $i, 5;
958
+
959
+ my $size = 0;
960
+ if($i =~ /^([0-9a-fA-F]{4})\n/) {
961
+ $size = hex($1);
962
+ }
963
+
964
+ read_mainsockf(\$line, $size);
965
+
966
+ $ulsize += $size;
967
+ print $file $line if(!$nosave);
968
+
969
+ $raw .= $line;
970
+ if($raw =~ /(?:^|\x0d\x0a)\x2e\x0d\x0a/) {
971
+ # end of data marker!
972
+ $eob = 1;
973
+ }
974
+
975
+ logmsg "> Appending $size bytes to file\n";
976
+
977
+ if($eob) {
978
+ logmsg "Found SMTP EOB marker\n";
979
+ last;
980
+ }
981
+ }
982
+ elsif($line eq "DISC\n") {
983
+ # disconnect!
984
+ $disc=1;
985
+ printf SFWRITE "ACKD\n";
986
+ last;
987
+ }
988
+ else {
989
+ logmsg "No support for: $line";
990
+ last;
991
+ }
992
+ }
993
+
994
+ if($nosave) {
995
+ print $file "$ulsize bytes would've been stored here\n";
996
+ }
997
+
998
+ close($file);
999
+
1000
+ logmsg "received $ulsize bytes upload\n";
1001
+
1002
+ sendcontrol "250 OK, data received!\r\n";
1003
+ }
1004
+
1005
+ return 0;
1006
+ }
1007
+
1008
+ sub NOOP_smtp {
1009
+ my ($args) = @_;
1010
+
1011
+ if($args) {
1012
+ sendcontrol "501 Unrecognized parameter\r\n";
1013
+ }
1014
+ else {
1015
+ sendcontrol "250 OK\r\n";
1016
+ }
1017
+
1018
+ return 0;
1019
+ }
1020
+
1021
+ sub RSET_smtp {
1022
+ my ($args) = @_;
1023
+
1024
+ if($args) {
1025
+ sendcontrol "501 Unrecognized parameter\r\n";
1026
+ }
1027
+ else {
1028
+ sendcontrol "250 Resetting\r\n";
1029
+ }
1030
+
1031
+ return 0;
1032
+ }
1033
+
1034
+ sub HELP_smtp {
1035
+ my ($args) = @_;
1036
+
1037
+ # One argument is optional
1038
+ if($args) {
1039
+ logmsg "HELP_smtp got $args\n";
1040
+ }
1041
+
1042
+ if($smtp_client eq "verifiedserver") {
1043
+ # This is the secret command that verifies that this actually is
1044
+ # the curl test server
1045
+ sendcontrol "214 WE ROOLZ: $$\r\n";
1046
+
1047
+ if($verbose) {
1048
+ print STDERR "FTPD: We returned proof we are the test server\n";
1049
+ }
1050
+
1051
+ logmsg "return proof we are we\n";
1052
+ }
1053
+ else {
1054
+ sendcontrol "214-This server supports the following commands:\r\n";
1055
+
1056
+ if(@auth_mechs) {
1057
+ sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP AUTH\r\n";
1058
+ }
1059
+ else {
1060
+ sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP\r\n";
1061
+ }
1062
+ }
1063
+
1064
+ return 0;
1065
+ }
1066
+
1067
+ sub VRFY_smtp {
1068
+ my ($args) = @_;
1069
+ my ($username, $address) = split(/ /, $args, 2);
1070
+
1071
+ logmsg "VRFY_smtp got $args\n";
1072
+
1073
+ if($username eq "") {
1074
+ sendcontrol "501 Unrecognized parameter\r\n";
1075
+ }
1076
+ else {
1077
+ my $smtputf8 = grep /^SMTPUTF8$/, @capabilities;
1078
+
1079
+ # Validate the username (only a valid local or external username is
1080
+ # allowed, such as user or user@example.com)
1081
+ if ((!$smtputf8 && $username =~
1082
+ /^([a-zA-Z0-9._%+-]+)(\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4}))?$/) ||
1083
+ ($smtputf8 && $username =~
1084
+ /^([a-zA-Z0-9\x{80}-\x{ff}._%+-]+)(\@(([a-zA-Z0-9\x{80}-\x{ff}-]+)\.)+([a-zA-Z]{2,4}))?$/)) {
1085
+
1086
+ my @data = getreplydata($smtp_client);
1087
+
1088
+ if(!@data) {
1089
+ if ($username !~
1090
+ /^([a-zA-Z0-9._%+-]+)\@(([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,4})$/) {
1091
+ push @data, "250 <$username\@example.com>\r\n"
1092
+ }
1093
+ else {
1094
+ push @data, "250 <$username>\r\n"
1095
+ }
1096
+ }
1097
+
1098
+ for my $d (@data) {
1099
+ sendcontrol $d;
1100
+ }
1101
+ }
1102
+ else {
1103
+ sendcontrol "501 Invalid address\r\n";
1104
+ }
1105
+ }
1106
+
1107
+ return 0;
1108
+ }
1109
+
1110
+ sub EXPN_smtp {
1111
+ my ($list_name) = @_;
1112
+
1113
+ logmsg "EXPN_smtp got $list_name\n";
1114
+
1115
+ if(!$list_name) {
1116
+ sendcontrol "501 Unrecognized parameter\r\n";
1117
+ }
1118
+ else {
1119
+ my @data = getreplydata($smtp_client);
1120
+
1121
+ for my $d (@data) {
1122
+ sendcontrol $d;
1123
+ }
1124
+ }
1125
+
1126
+ return 0;
1127
+ }
1128
+
1129
+ sub QUIT_smtp {
1130
+ sendcontrol "221 curl $smtp_type server signing off\r\n";
1131
+
1132
+ return 0;
1133
+ }
1134
+
1135
+ # What was deleted by IMAP STORE / POP3 DELE commands
1136
+ my @deleted;
1137
+
1138
+ ################
1139
+ ################ IMAP commands
1140
+ ################
1141
+
1142
+ # global to allow the command functions to read it
1143
+ my $cmdid;
1144
+
1145
+ # what was picked by SELECT
1146
+ my $selected;
1147
+
1148
+ # Any IMAP parameter can come in escaped and in double quotes.
1149
+ # This function is dumb (so far) and just removes the quotes if present.
1150
+ sub fix_imap_params {
1151
+ foreach (@_) {
1152
+ $_ = $1 if /^"(.*)"$/;
1153
+ }
1154
+ }
1155
+
1156
+ sub CAPABILITY_imap {
1157
+ if((!@capabilities) && (!@auth_mechs)) {
1158
+ sendcontrol "$cmdid BAD Command\r\n";
1159
+ }
1160
+ else {
1161
+ my $data;
1162
+
1163
+ # Calculate the CAPABILITY response
1164
+ $data = "* CAPABILITY IMAP4";
1165
+
1166
+ for my $c (@capabilities) {
1167
+ $data .= " $c";
1168
+ }
1169
+
1170
+ for my $am (@auth_mechs) {
1171
+ $data .= " AUTH=$am";
1172
+ }
1173
+
1174
+ $data .= " pingpong test server\r\n";
1175
+
1176
+ # Send the CAPABILITY response
1177
+ sendcontrol $data;
1178
+ sendcontrol "$cmdid OK CAPABILITY completed\r\n";
1179
+ }
1180
+
1181
+ return 0;
1182
+ }
1183
+
1184
+ sub LOGIN_imap {
1185
+ my ($args) = @_;
1186
+ my ($user, $password) = split(/ /, $args, 2);
1187
+ fix_imap_params($user, $password);
1188
+
1189
+ logmsg "LOGIN_imap got $args\n";
1190
+
1191
+ if ($user eq "") {
1192
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1193
+ }
1194
+ else {
1195
+ sendcontrol "$cmdid OK LOGIN completed\r\n";
1196
+ }
1197
+
1198
+ return 0;
1199
+ }
1200
+
1201
+ sub SELECT_imap {
1202
+ my ($mailbox) = @_;
1203
+ fix_imap_params($mailbox);
1204
+
1205
+ logmsg "SELECT_imap got test $mailbox\n";
1206
+
1207
+ if($mailbox eq "") {
1208
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1209
+ }
1210
+ else {
1211
+ # Example from RFC 3501, 6.3.1. SELECT Command
1212
+ sendcontrol "* 172 EXISTS\r\n";
1213
+ sendcontrol "* 1 RECENT\r\n";
1214
+ sendcontrol "* OK [UNSEEN 12] Message 12 is first unseen\r\n";
1215
+ sendcontrol "* OK [UIDVALIDITY 3857529045] UIDs valid\r\n";
1216
+ sendcontrol "* OK [UIDNEXT 4392] Predicted next UID\r\n";
1217
+ sendcontrol "* FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\r\n";
1218
+ sendcontrol "* OK [PERMANENTFLAGS (\\Deleted \\Seen \\*)] Limited\r\n";
1219
+ sendcontrol "$cmdid OK [READ-WRITE] SELECT completed\r\n";
1220
+
1221
+ $selected = $mailbox;
1222
+ }
1223
+
1224
+ return 0;
1225
+ }
1226
+
1227
+ sub FETCH_imap {
1228
+ my ($args) = @_;
1229
+ my ($uid, $how) = split(/ /, $args, 2);
1230
+ fix_imap_params($uid, $how);
1231
+
1232
+ logmsg "FETCH_imap got $args\n";
1233
+
1234
+ if ($selected eq "") {
1235
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1236
+ }
1237
+ else {
1238
+ my @data;
1239
+ my $size;
1240
+
1241
+ if($selected eq "verifiedserver") {
1242
+ # this is the secret command that verifies that this actually is
1243
+ # the curl test server
1244
+ my $response = "WE ROOLZ: $$\r\n";
1245
+ if($verbose) {
1246
+ print STDERR "FTPD: We returned proof we are the test server\n";
1247
+ }
1248
+ $data[0] = $response;
1249
+ logmsg "return proof we are we\n";
1250
+ }
1251
+ else {
1252
+ # send mail content
1253
+ logmsg "retrieve a mail\n";
1254
+
1255
+ @data = getreplydata($selected);
1256
+ }
1257
+
1258
+ for (@data) {
1259
+ $size += length($_);
1260
+ }
1261
+
1262
+ sendcontrol "* $uid FETCH ($how {$size}\r\n";
1263
+
1264
+ for my $d (@data) {
1265
+ sendcontrol $d;
1266
+ }
1267
+
1268
+ # Set the custom extra header content with POSTFETCH
1269
+ sendcontrol "$postfetch)\r\n";
1270
+ sendcontrol "$cmdid OK FETCH completed\r\n";
1271
+ }
1272
+
1273
+ return 0;
1274
+ }
1275
+
1276
+ sub APPEND_imap {
1277
+ my ($args) = @_;
1278
+
1279
+ logmsg "APPEND_imap got $args\r\n";
1280
+
1281
+ $args =~ /^([^ ]+) [^{]*\{(\d+)\}$/;
1282
+ my ($mailbox, $size) = ($1, $2);
1283
+ fix_imap_params($mailbox);
1284
+
1285
+ if($mailbox eq "") {
1286
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1287
+ }
1288
+ else {
1289
+ sendcontrol "+ Ready for literal data\r\n";
1290
+
1291
+ my $testno = $mailbox;
1292
+ my $filename = "$logdir/upload.$testno";
1293
+
1294
+ logmsg "Store test number $testno in $filename\n";
1295
+
1296
+ open(my $file, ">", "$filename") ||
1297
+ return 0; # failed to open output
1298
+
1299
+ my $received = 0;
1300
+ my $line;
1301
+ while(5 == (sysread \*SFREAD, $line, 5)) {
1302
+ if($line eq "DATA\n") {
1303
+ sysread \*SFREAD, $line, 5;
1304
+
1305
+ my $chunksize = 0;
1306
+ if($line =~ /^([0-9a-fA-F]{4})\n/) {
1307
+ $chunksize = hex($1);
1308
+ }
1309
+
1310
+ read_mainsockf(\$line, $chunksize);
1311
+
1312
+ my $left = $size - $received;
1313
+ my $datasize = ($left > $chunksize) ? $chunksize : $left;
1314
+
1315
+ if($datasize > 0) {
1316
+ logmsg "> Appending $datasize bytes to file\n";
1317
+ print $file substr($line, 0, $datasize) if(!$nosave);
1318
+ $line = substr($line, $datasize);
1319
+
1320
+ $received += $datasize;
1321
+ if($received == $size) {
1322
+ logmsg "Received all data, waiting for final CRLF.\n";
1323
+ }
1324
+ }
1325
+
1326
+ if($received == $size && $line eq "\r\n") {
1327
+ last;
1328
+ }
1329
+ }
1330
+ elsif($line eq "DISC\n") {
1331
+ logmsg "Unexpected disconnect!\n";
1332
+ printf SFWRITE "ACKD\n";
1333
+ last;
1334
+ }
1335
+ else {
1336
+ logmsg "No support for: $line";
1337
+ last;
1338
+ }
1339
+ }
1340
+
1341
+ if($nosave) {
1342
+ print $file "$size bytes would've been stored here\n";
1343
+ }
1344
+
1345
+ close($file);
1346
+
1347
+ logmsg "received $size bytes upload\n";
1348
+
1349
+ sendcontrol "$cmdid OK APPEND completed\r\n";
1350
+ }
1351
+
1352
+ return 0;
1353
+ }
1354
+
1355
+ sub STORE_imap {
1356
+ my ($args) = @_;
1357
+ my ($uid, $what, $value) = split(/ /, $args, 3);
1358
+ fix_imap_params($uid);
1359
+
1360
+ logmsg "STORE_imap got $args\n";
1361
+
1362
+ if ($selected eq "") {
1363
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1364
+ }
1365
+ elsif (($uid eq "") || ($what ne "+Flags") || ($value eq "")) {
1366
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1367
+ }
1368
+ else {
1369
+ if($value eq "\\Deleted") {
1370
+ push(@deleted, $uid);
1371
+ }
1372
+
1373
+ sendcontrol "* $uid FETCH (FLAGS (\\Seen $value))\r\n";
1374
+ sendcontrol "$cmdid OK STORE completed\r\n";
1375
+ }
1376
+
1377
+ return 0;
1378
+ }
1379
+
1380
+ sub LIST_imap {
1381
+ my ($args) = @_;
1382
+ my ($reference, $mailbox) = split(/ /, $args, 2);
1383
+ fix_imap_params($reference, $mailbox);
1384
+
1385
+ logmsg "LIST_imap got $args\n";
1386
+
1387
+ if ($reference eq "") {
1388
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1389
+ }
1390
+ elsif ($reference eq "verifiedserver") {
1391
+ # this is the secret command that verifies that this actually is
1392
+ # the curl test server
1393
+ sendcontrol "* LIST () \"/\" \"WE ROOLZ: $$\"\r\n";
1394
+ sendcontrol "$cmdid OK LIST Completed\r\n";
1395
+
1396
+ if($verbose) {
1397
+ print STDERR "FTPD: We returned proof we are the test server\n";
1398
+ }
1399
+
1400
+ logmsg "return proof we are we\n";
1401
+ }
1402
+ else {
1403
+ my @data = getreplydata($reference);
1404
+
1405
+ for my $d (@data) {
1406
+ sendcontrol $d;
1407
+ }
1408
+
1409
+ sendcontrol "$cmdid OK LIST Completed\r\n";
1410
+ }
1411
+
1412
+ return 0;
1413
+ }
1414
+
1415
+ sub LSUB_imap {
1416
+ my ($args) = @_;
1417
+ my ($reference, $mailbox) = split(/ /, $args, 2);
1418
+ fix_imap_params($reference, $mailbox);
1419
+
1420
+ logmsg "LSUB_imap got $args\n";
1421
+
1422
+ if ($reference eq "") {
1423
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1424
+ }
1425
+ else {
1426
+ my @data = getreplydata($reference);
1427
+
1428
+ for my $d (@data) {
1429
+ sendcontrol $d;
1430
+ }
1431
+
1432
+ sendcontrol "$cmdid OK LSUB Completed\r\n";
1433
+ }
1434
+
1435
+ return 0;
1436
+ }
1437
+
1438
+ sub EXAMINE_imap {
1439
+ my ($mailbox) = @_;
1440
+ fix_imap_params($mailbox);
1441
+
1442
+ logmsg "EXAMINE_imap got $mailbox\n";
1443
+
1444
+ if ($mailbox eq "") {
1445
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1446
+ }
1447
+ else {
1448
+ my @data = getreplydata($mailbox);
1449
+
1450
+ for my $d (@data) {
1451
+ sendcontrol $d;
1452
+ }
1453
+
1454
+ sendcontrol "$cmdid OK [READ-ONLY] EXAMINE completed\r\n";
1455
+ }
1456
+
1457
+ return 0;
1458
+ }
1459
+
1460
+ sub STATUS_imap {
1461
+ my ($args) = @_;
1462
+ my ($mailbox, $what) = split(/ /, $args, 2);
1463
+ fix_imap_params($mailbox);
1464
+
1465
+ logmsg "STATUS_imap got $args\n";
1466
+
1467
+ if ($mailbox eq "") {
1468
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1469
+ }
1470
+ else {
1471
+ my @data = getreplydata($mailbox);
1472
+
1473
+ for my $d (@data) {
1474
+ sendcontrol $d;
1475
+ }
1476
+
1477
+ sendcontrol "$cmdid OK STATUS completed\r\n";
1478
+ }
1479
+
1480
+ return 0;
1481
+ }
1482
+
1483
+ sub SEARCH_imap {
1484
+ my ($what) = @_;
1485
+ fix_imap_params($what);
1486
+
1487
+ logmsg "SEARCH_imap got $what\n";
1488
+
1489
+ if ($selected eq "") {
1490
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1491
+ }
1492
+ elsif ($what eq "") {
1493
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1494
+ }
1495
+ else {
1496
+ my @data = getreplydata($selected);
1497
+
1498
+ for my $d (@data) {
1499
+ sendcontrol $d;
1500
+ }
1501
+
1502
+ sendcontrol "$cmdid OK SEARCH completed\r\n";
1503
+ }
1504
+
1505
+ return 0;
1506
+ }
1507
+
1508
+ sub CREATE_imap {
1509
+ my ($args) = @_;
1510
+ fix_imap_params($args);
1511
+
1512
+ logmsg "CREATE_imap got $args\n";
1513
+
1514
+ if ($args eq "") {
1515
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1516
+ }
1517
+ else {
1518
+ sendcontrol "$cmdid OK CREATE completed\r\n";
1519
+ }
1520
+
1521
+ return 0;
1522
+ }
1523
+
1524
+ sub DELETE_imap {
1525
+ my ($args) = @_;
1526
+ fix_imap_params($args);
1527
+
1528
+ logmsg "DELETE_imap got $args\n";
1529
+
1530
+ if ($args eq "") {
1531
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1532
+ }
1533
+ else {
1534
+ sendcontrol "$cmdid OK DELETE completed\r\n";
1535
+ }
1536
+
1537
+ return 0;
1538
+ }
1539
+
1540
+ sub RENAME_imap {
1541
+ my ($args) = @_;
1542
+ my ($from_mailbox, $to_mailbox) = split(/ /, $args, 2);
1543
+ fix_imap_params($from_mailbox, $to_mailbox);
1544
+
1545
+ logmsg "RENAME_imap got $args\n";
1546
+
1547
+ if (($from_mailbox eq "") || ($to_mailbox eq "")) {
1548
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1549
+ }
1550
+ else {
1551
+ sendcontrol "$cmdid OK RENAME completed\r\n";
1552
+ }
1553
+
1554
+ return 0;
1555
+ }
1556
+
1557
+ sub CHECK_imap {
1558
+ if ($selected eq "") {
1559
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1560
+ }
1561
+ else {
1562
+ sendcontrol "$cmdid OK CHECK completed\r\n";
1563
+ }
1564
+
1565
+ return 0;
1566
+ }
1567
+
1568
+ sub CLOSE_imap {
1569
+ if ($selected eq "") {
1570
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1571
+ }
1572
+ elsif (!@deleted) {
1573
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1574
+ }
1575
+ else {
1576
+ sendcontrol "$cmdid OK CLOSE completed\r\n";
1577
+
1578
+ @deleted = ();
1579
+ }
1580
+
1581
+ return 0;
1582
+ }
1583
+
1584
+ sub EXPUNGE_imap {
1585
+ if ($selected eq "") {
1586
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1587
+ }
1588
+ else {
1589
+ if (!@deleted) {
1590
+ # Report the number of existing messages as per the SELECT
1591
+ # command
1592
+ sendcontrol "* 172 EXISTS\r\n";
1593
+ }
1594
+ else {
1595
+ # Report the message UIDs being deleted
1596
+ for my $d (@deleted) {
1597
+ sendcontrol "* $d EXPUNGE\r\n";
1598
+ }
1599
+
1600
+ @deleted = ();
1601
+ }
1602
+
1603
+ sendcontrol "$cmdid OK EXPUNGE completed\r\n";
1604
+ }
1605
+
1606
+ return 0;
1607
+ }
1608
+
1609
+ sub COPY_imap {
1610
+ my ($args) = @_;
1611
+ my ($uid, $mailbox) = split(/ /, $args, 2);
1612
+ fix_imap_params($uid, $mailbox);
1613
+
1614
+ logmsg "COPY_imap got $args\n";
1615
+
1616
+ if (($uid eq "") || ($mailbox eq "")) {
1617
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1618
+ }
1619
+ else {
1620
+ sendcontrol "$cmdid OK COPY completed\r\n";
1621
+ }
1622
+
1623
+ return 0;
1624
+ }
1625
+
1626
+ sub IDLE_imap {
1627
+ logmsg "IDLE received\n";
1628
+
1629
+ sendcontrol "+ entering idle mode\r\n";
1630
+ return 0;
1631
+ }
1632
+
1633
+ sub UID_imap {
1634
+ my ($args) = @_;
1635
+ my ($command) = split(/ /, $args, 1);
1636
+ fix_imap_params($command);
1637
+
1638
+ logmsg "UID_imap got $args\n";
1639
+
1640
+ if ($selected eq "") {
1641
+ sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
1642
+ }
1643
+ elsif (substr($command, 0, 5) eq "FETCH"){
1644
+ my $func = $commandfunc{"FETCH"};
1645
+ if($func) {
1646
+ &$func($args, $command);
1647
+ }
1648
+ }
1649
+ elsif (($command ne "COPY") &&
1650
+ ($command ne "STORE") && ($command ne "SEARCH")) {
1651
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1652
+ }
1653
+ else {
1654
+ my @data = getreplydata($selected);
1655
+
1656
+ for my $d (@data) {
1657
+ sendcontrol $d;
1658
+ }
1659
+
1660
+ sendcontrol "$cmdid OK $command completed\r\n";
1661
+ }
1662
+
1663
+ return 0;
1664
+ }
1665
+
1666
+ sub NOOP_imap {
1667
+ my ($args) = @_;
1668
+ my @data = (
1669
+ "* 22 EXPUNGE\r\n",
1670
+ "* 23 EXISTS\r\n",
1671
+ "* 3 RECENT\r\n",
1672
+ "* 14 FETCH (FLAGS (\\Seen \\Deleted))\r\n",
1673
+ );
1674
+
1675
+ if ($args) {
1676
+ sendcontrol "$cmdid BAD Command Argument\r\n";
1677
+ }
1678
+ else {
1679
+ for my $d (@data) {
1680
+ sendcontrol $d;
1681
+ }
1682
+
1683
+ sendcontrol "$cmdid OK NOOP completed\r\n";
1684
+ }
1685
+
1686
+ return 0;
1687
+ }
1688
+
1689
+ sub LOGOUT_imap {
1690
+ sendcontrol "* BYE curl IMAP server signing off\r\n";
1691
+ sendcontrol "$cmdid OK LOGOUT completed\r\n";
1692
+
1693
+ return 0;
1694
+ }
1695
+
1696
+ ################
1697
+ ################ POP3 commands
1698
+ ################
1699
+
1700
+ # Who is attempting to log in
1701
+ my $username;
1702
+
1703
+ sub CAPA_pop3 {
1704
+ my @list = ();
1705
+ my $mechs;
1706
+
1707
+ # Calculate the capability list based on the specified capabilities
1708
+ # (except APOP) and any authentication mechanisms
1709
+ for my $c (@capabilities) {
1710
+ push @list, "$c\r\n" unless $c eq "APOP";
1711
+ }
1712
+
1713
+ for my $am (@auth_mechs) {
1714
+ if(!$mechs) {
1715
+ $mechs = "$am";
1716
+ }
1717
+ else {
1718
+ $mechs .= " $am";
1719
+ }
1720
+ }
1721
+
1722
+ if($mechs) {
1723
+ push @list, "SASL $mechs\r\n";
1724
+ }
1725
+
1726
+ if(!@list) {
1727
+ sendcontrol "-ERR Unrecognized command\r\n";
1728
+ }
1729
+ else {
1730
+ my @data = ();
1731
+
1732
+ # Calculate the CAPA response
1733
+ push @data, "+OK List of capabilities follows\r\n";
1734
+
1735
+ for my $l (@list) {
1736
+ push @data, "$l\r\n";
1737
+ }
1738
+
1739
+ push @data, "IMPLEMENTATION POP3 pingpong test server\r\n";
1740
+
1741
+ # Send the CAPA response
1742
+ for my $d (@data) {
1743
+ sendcontrol $d;
1744
+ }
1745
+
1746
+ # End with the magic 3-byte end of listing marker
1747
+ sendcontrol ".\r\n";
1748
+ }
1749
+
1750
+ return 0;
1751
+ }
1752
+
1753
+ sub APOP_pop3 {
1754
+ my ($args) = @_;
1755
+ my ($user, $secret) = split(/ /, $args, 2);
1756
+
1757
+ if (!grep /^APOP$/, @capabilities) {
1758
+ sendcontrol "-ERR Unrecognized command\r\n";
1759
+ }
1760
+ elsif (($user eq "") || ($secret eq "")) {
1761
+ sendcontrol "-ERR Protocol error\r\n";
1762
+ }
1763
+ else {
1764
+ my $digest = Digest::MD5::md5_hex($POP3_TIMESTAMP, $TEXT_PASSWORD);
1765
+
1766
+ if ($secret ne $digest) {
1767
+ sendcontrol "-ERR Login failure\r\n";
1768
+ }
1769
+ else {
1770
+ sendcontrol "+OK Login successful\r\n";
1771
+ }
1772
+ }
1773
+
1774
+ return 0;
1775
+ }
1776
+
1777
+ sub AUTH_pop3 {
1778
+ if(!@auth_mechs) {
1779
+ sendcontrol "-ERR Unrecognized command\r\n";
1780
+ }
1781
+ else {
1782
+ my @data = ();
1783
+
1784
+ # Calculate the AUTH response
1785
+ push @data, "+OK List of supported mechanisms follows\r\n";
1786
+
1787
+ for my $am (@auth_mechs) {
1788
+ push @data, "$am\r\n";
1789
+ }
1790
+
1791
+ # Send the AUTH response
1792
+ for my $d (@data) {
1793
+ sendcontrol $d;
1794
+ }
1795
+
1796
+ # End with the magic 3-byte end of listing marker
1797
+ sendcontrol ".\r\n";
1798
+ }
1799
+
1800
+ return 0;
1801
+ }
1802
+
1803
+ sub USER_pop3 {
1804
+ my ($user) = @_;
1805
+
1806
+ logmsg "USER_pop3 got $user\n";
1807
+
1808
+ if (!$user) {
1809
+ sendcontrol "-ERR Protocol error\r\n";
1810
+ }
1811
+ else {
1812
+ $username = $user;
1813
+
1814
+ sendcontrol "+OK\r\n";
1815
+ }
1816
+
1817
+ return 0;
1818
+ }
1819
+
1820
+ sub PASS_pop3 {
1821
+ my ($password) = @_;
1822
+
1823
+ logmsg "PASS_pop3 got $password\n";
1824
+
1825
+ sendcontrol "+OK Login successful\r\n";
1826
+
1827
+ return 0;
1828
+ }
1829
+
1830
+ sub RETR_pop3 {
1831
+ my ($msgid) = @_;
1832
+ my @data;
1833
+
1834
+ if($msgid =~ /^verifiedserver$/) {
1835
+ # this is the secret command that verifies that this actually is
1836
+ # the curl test server
1837
+ my $response = "WE ROOLZ: $$\r\n";
1838
+ if($verbose) {
1839
+ print STDERR "FTPD: We returned proof we are the test server\n";
1840
+ }
1841
+ $data[0] = $response;
1842
+ logmsg "return proof we are we\n";
1843
+ }
1844
+ else {
1845
+ # send mail content
1846
+ logmsg "retrieve a mail\n";
1847
+
1848
+ @data = getreplydata($msgid);
1849
+ }
1850
+
1851
+ sendcontrol "+OK Mail transfer starts\r\n";
1852
+
1853
+ for my $d (@data) {
1854
+ sendcontrol $d;
1855
+ }
1856
+
1857
+ # end with the magic 3-byte end of mail marker, assumes that the
1858
+ # mail body ends with a CRLF!
1859
+ sendcontrol ".\r\n";
1860
+
1861
+ return 0;
1862
+ }
1863
+
1864
+ sub LIST_pop3 {
1865
+ my @data = getpart("reply", "data");
1866
+
1867
+ logmsg "retrieve a message list\n";
1868
+
1869
+ sendcontrol "+OK Listing starts\r\n";
1870
+
1871
+ for my $d (@data) {
1872
+ sendcontrol $d;
1873
+ }
1874
+
1875
+ # End with the magic 3-byte end of listing marker
1876
+ sendcontrol ".\r\n";
1877
+
1878
+ return 0;
1879
+ }
1880
+
1881
+ sub DELE_pop3 {
1882
+ my ($msgid) = @_;
1883
+
1884
+ logmsg "DELE_pop3 got $msgid\n";
1885
+
1886
+ if (!$msgid) {
1887
+ sendcontrol "-ERR Protocol error\r\n";
1888
+ }
1889
+ else {
1890
+ push (@deleted, $msgid);
1891
+
1892
+ sendcontrol "+OK\r\n";
1893
+ }
1894
+
1895
+ return 0;
1896
+ }
1897
+
1898
+ sub STAT_pop3 {
1899
+ my ($args) = @_;
1900
+
1901
+ if ($args) {
1902
+ sendcontrol "-ERR Protocol error\r\n";
1903
+ }
1904
+ else {
1905
+ # Send statistics for the built-in fake message list as
1906
+ # detailed in the LIST_pop3 function above
1907
+ sendcontrol "+OK 3 4294967800\r\n";
1908
+ }
1909
+
1910
+ return 0;
1911
+ }
1912
+
1913
+ sub NOOP_pop3 {
1914
+ my ($args) = @_;
1915
+
1916
+ if ($args) {
1917
+ sendcontrol "-ERR Protocol error\r\n";
1918
+ }
1919
+ else {
1920
+ sendcontrol "+OK\r\n";
1921
+ }
1922
+
1923
+ return 0;
1924
+ }
1925
+
1926
+ sub UIDL_pop3 {
1927
+ # This is a built-in fake-message UID list
1928
+ my @data = (
1929
+ "1 1\r\n",
1930
+ "2 2\r\n",
1931
+ "3 4\r\n", # Note that UID 3 is a simulated "deleted" message
1932
+ );
1933
+
1934
+ if (!grep /^UIDL$/, @capabilities) {
1935
+ sendcontrol "-ERR Unrecognized command\r\n";
1936
+ }
1937
+ else {
1938
+ logmsg "retrieve a message UID list\n";
1939
+
1940
+ sendcontrol "+OK Listing starts\r\n";
1941
+
1942
+ for my $d (@data) {
1943
+ sendcontrol $d;
1944
+ }
1945
+
1946
+ # End with the magic 3-byte end of listing marker
1947
+ sendcontrol ".\r\n";
1948
+ }
1949
+
1950
+ return 0;
1951
+ }
1952
+
1953
+ sub TOP_pop3 {
1954
+ my ($args) = @_;
1955
+ my ($msgid, $lines) = split(/ /, $args, 2);
1956
+
1957
+ logmsg "TOP_pop3 got $args\n";
1958
+
1959
+ if (!grep /^TOP$/, @capabilities) {
1960
+ sendcontrol "-ERR Unrecognized command\r\n";
1961
+ }
1962
+ elsif (($msgid eq "") || ($lines eq "")) {
1963
+ sendcontrol "-ERR Protocol error\r\n";
1964
+ }
1965
+ else {
1966
+ if ($lines == "0") {
1967
+ logmsg "retrieve header of mail\n";
1968
+ }
1969
+ else {
1970
+ logmsg "retrieve top $lines lines of mail\n";
1971
+ }
1972
+
1973
+ my @data = getreplydata($msgid);
1974
+
1975
+ sendcontrol "+OK Mail transfer starts\r\n";
1976
+
1977
+ # Send mail content
1978
+ for my $d (@data) {
1979
+ sendcontrol $d;
1980
+ }
1981
+
1982
+ # End with the magic 3-byte end of mail marker, assumes that the
1983
+ # mail body ends with a CRLF!
1984
+ sendcontrol ".\r\n";
1985
+ }
1986
+
1987
+ return 0;
1988
+ }
1989
+
1990
+ sub RSET_pop3 {
1991
+ my ($args) = @_;
1992
+
1993
+ if ($args) {
1994
+ sendcontrol "-ERR Protocol error\r\n";
1995
+ }
1996
+ else {
1997
+ if (@deleted) {
1998
+ logmsg "resetting @deleted message(s)\n";
1999
+
2000
+ @deleted = ();
2001
+ }
2002
+
2003
+ sendcontrol "+OK\r\n";
2004
+ }
2005
+
2006
+ return 0;
2007
+ }
2008
+
2009
+ sub QUIT_pop3 {
2010
+ if(@deleted) {
2011
+ logmsg "deleting @deleted message(s)\n";
2012
+
2013
+ @deleted = ();
2014
+ }
2015
+
2016
+ sendcontrol "+OK curl POP3 server signing off\r\n";
2017
+
2018
+ return 0;
2019
+ }
2020
+
2021
+ ################
2022
+ ################ FTP commands
2023
+ ################
2024
+ my $rest=0;
2025
+ sub REST_ftp {
2026
+ $rest = $_[0];
2027
+ logmsg "Set REST position to $rest\n"
2028
+ }
2029
+
2030
+ sub switch_directory_goto {
2031
+ my $target_dir = $_;
2032
+
2033
+ if(!$ftptargetdir) {
2034
+ $ftptargetdir = "/";
2035
+ }
2036
+
2037
+ if($target_dir eq "") {
2038
+ $ftptargetdir = "/";
2039
+ }
2040
+ elsif($target_dir eq "..") {
2041
+ if($ftptargetdir eq "/") {
2042
+ $ftptargetdir = "/";
2043
+ }
2044
+ else {
2045
+ $ftptargetdir =~ s/[[:alnum:]]+\/$//;
2046
+ }
2047
+ }
2048
+ else {
2049
+ $ftptargetdir .= $target_dir . "/";
2050
+ }
2051
+ }
2052
+
2053
+ sub switch_directory {
2054
+ my $target_dir = $_[0];
2055
+
2056
+ if($target_dir =~ /^test-(\d+)/) {
2057
+ $cwd_testno = $1;
2058
+ }
2059
+ elsif($target_dir eq "/") {
2060
+ $ftptargetdir = "/";
2061
+ }
2062
+ else {
2063
+ my @dirs = split("/", $target_dir);
2064
+ for(@dirs) {
2065
+ switch_directory_goto($_);
2066
+ }
2067
+ }
2068
+ }
2069
+
2070
+ sub CWD_ftp {
2071
+ my ($folder, $fullcommand) = $_[0];
2072
+ switch_directory($folder);
2073
+ if($ftptargetdir =~ /^\/fully_simulated/) {
2074
+ $ftplistparserstate = "enabled";
2075
+ logmsg "enabled FTP list parser mode\n";
2076
+ }
2077
+ else {
2078
+ undef $ftplistparserstate;
2079
+ }
2080
+ }
2081
+
2082
+ sub PWD_ftp {
2083
+ my $mydir;
2084
+ $mydir = $ftptargetdir ? $ftptargetdir : "/";
2085
+
2086
+ if($mydir ne "/") {
2087
+ $mydir =~ s/\/$//;
2088
+ }
2089
+ sendcontrol "257 \"$mydir\" is current directory\r\n";
2090
+ }
2091
+
2092
+ sub LIST_ftp {
2093
+ # print "150 ASCII data connection for /bin/ls (193.15.23.1,59196) (0 bytes)\r\n";
2094
+
2095
+ if($datasockf_conn eq 'no') {
2096
+ if($nodataconn425) {
2097
+ sendcontrol "150 Opening data connection\r\n";
2098
+ sendcontrol "425 Can't open data connection\r\n";
2099
+ }
2100
+ elsif($nodataconn421) {
2101
+ sendcontrol "150 Opening data connection\r\n";
2102
+ sendcontrol "421 Connection timed out\r\n";
2103
+ }
2104
+ elsif($nodataconn150) {
2105
+ sendcontrol "150 Opening data connection\r\n";
2106
+ # client shall timeout
2107
+ }
2108
+ else {
2109
+ # client shall timeout
2110
+ }
2111
+ return 0;
2112
+ }
2113
+
2114
+ logmsg "pass LIST data on data connection\n";
2115
+
2116
+ if($ftplistparserstate) {
2117
+ # provide a synthetic response
2118
+ my @ftpdir = ftp_contentlist($ftptargetdir);
2119
+ # old hard-coded style
2120
+ for(@ftpdir) {
2121
+ senddata $_;
2122
+ }
2123
+ }
2124
+ else {
2125
+ my @data = getpart("reply", "data");
2126
+ for(@data) {
2127
+ my $send = $_;
2128
+ # convert all \n to \r\n for ASCII transfer
2129
+ $send =~ s/\r\n/\n/g;
2130
+ $send =~ s/\n/\r\n/g;
2131
+ logmsg "send $send as data\n";
2132
+ senddata $send;
2133
+ }
2134
+ }
2135
+ close_dataconn(0);
2136
+ sendcontrol "226 ASCII transfer complete\r\n";
2137
+ return 0;
2138
+ }
2139
+
2140
+ sub NLST_ftp {
2141
+ my @ftpdir=("file", "with space", "fake", "..", " ..", "funny", "README");
2142
+
2143
+ if($datasockf_conn eq 'no') {
2144
+ if($nodataconn425) {
2145
+ sendcontrol "150 Opening data connection\r\n";
2146
+ sendcontrol "425 Can't open data connection\r\n";
2147
+ }
2148
+ elsif($nodataconn421) {
2149
+ sendcontrol "150 Opening data connection\r\n";
2150
+ sendcontrol "421 Connection timed out\r\n";
2151
+ }
2152
+ elsif($nodataconn150) {
2153
+ sendcontrol "150 Opening data connection\r\n";
2154
+ # client shall timeout
2155
+ }
2156
+ else {
2157
+ # client shall timeout
2158
+ }
2159
+ return 0;
2160
+ }
2161
+
2162
+ logmsg "pass NLST data on data connection\n";
2163
+ for(@ftpdir) {
2164
+ senddata "$_\r\n";
2165
+ }
2166
+ close_dataconn(0);
2167
+ sendcontrol "226 ASCII transfer complete\r\n";
2168
+ return 0;
2169
+ }
2170
+
2171
+ sub MDTM_ftp {
2172
+ my $testno = $_[0];
2173
+ my $testpart = "";
2174
+ if ($testno > 10000) {
2175
+ $testpart = $testno % 10000;
2176
+ $testno = int($testno / 10000);
2177
+ }
2178
+
2179
+ loadtest("$logdir/test$testno");
2180
+
2181
+ my @data = getpart("reply", "mdtm");
2182
+
2183
+ my $reply = $data[0];
2184
+ chomp $reply if($reply);
2185
+
2186
+ if($reply && ($reply =~ /^[+-]?\d+$/) && ($reply < 0)) {
2187
+ sendcontrol "550 $testno: no such file.\r\n";
2188
+ }
2189
+ elsif($reply) {
2190
+ sendcontrol "$reply\r\n";
2191
+ }
2192
+ else {
2193
+ sendcontrol "500 MDTM: no such command.\r\n";
2194
+ }
2195
+ return 0;
2196
+ }
2197
+
2198
+ sub SIZE_ftp {
2199
+ my $testno = $_[0];
2200
+
2201
+ if($ftplistparserstate) {
2202
+ my $size = wildcard_filesize($ftptargetdir, $testno);
2203
+ if($size == -1) {
2204
+ sendcontrol "550 $testno: No such file or directory.\r\n";
2205
+ }
2206
+ else {
2207
+ sendcontrol "213 $size\r\n";
2208
+ }
2209
+ return 0;
2210
+ }
2211
+
2212
+ if($testno =~ /^verifiedserver$/) {
2213
+ my $response = "WE ROOLZ: $$\r\n";
2214
+ my $size = length($response);
2215
+ sendcontrol "213 $size\r\n";
2216
+ return 0;
2217
+ }
2218
+
2219
+ if($testno =~ /(\d+)\/?$/) {
2220
+ $testno = $1;
2221
+ }
2222
+ else {
2223
+ print STDERR "SIZE_ftp: invalid test number: $testno\n";
2224
+ return 1;
2225
+ }
2226
+
2227
+ my $testpart = "";
2228
+ if($testno > 10000) {
2229
+ $testpart = $testno % 10000;
2230
+ $testno = int($testno / 10000);
2231
+ }
2232
+
2233
+ loadtest("$logdir/test$testno");
2234
+ my @data = getpart("reply", "size");
2235
+
2236
+ my $size = $data[0];
2237
+
2238
+ if($size) {
2239
+ $size += 0; # make it a number
2240
+ if($size > -1) {
2241
+ sendcontrol "213 $size\r\n";
2242
+ }
2243
+ else {
2244
+ sendcontrol "550 $testno: No such file or directory.\r\n";
2245
+ }
2246
+ }
2247
+ else {
2248
+ $size=0;
2249
+ @data = getpart("reply", "data$testpart");
2250
+ for(@data) {
2251
+ $size += length($_);
2252
+ }
2253
+ if($size) {
2254
+ sendcontrol "213 $size\r\n";
2255
+ }
2256
+ else {
2257
+ sendcontrol "550 $testno: No such file or directory.\r\n";
2258
+ }
2259
+ }
2260
+ return 0;
2261
+ }
2262
+
2263
+ sub RETR_ftp {
2264
+ my ($testno) = @_;
2265
+
2266
+ if($datasockf_conn eq 'no') {
2267
+ if($nodataconn425) {
2268
+ sendcontrol "150 Opening data connection\r\n";
2269
+ sendcontrol "425 Can't open data connection\r\n";
2270
+ }
2271
+ elsif($nodataconn421) {
2272
+ sendcontrol "150 Opening data connection\r\n";
2273
+ sendcontrol "421 Connection timed out\r\n";
2274
+ }
2275
+ elsif($nodataconn150) {
2276
+ sendcontrol "150 Opening data connection\r\n";
2277
+ # client shall timeout
2278
+ }
2279
+ else {
2280
+ # client shall timeout
2281
+ }
2282
+ return 0;
2283
+ }
2284
+
2285
+ if($ftplistparserstate) {
2286
+ my @content = wildcard_getfile($ftptargetdir, $testno);
2287
+ if($content[0] == -1) {
2288
+ #file not found
2289
+ }
2290
+ else {
2291
+ my $size = length $content[1];
2292
+ sendcontrol "150 Binary data connection for $testno ($size bytes).\r\n",
2293
+ senddata $content[1];
2294
+ close_dataconn(0);
2295
+ sendcontrol "226 File transfer complete\r\n";
2296
+ }
2297
+ return 0;
2298
+ }
2299
+
2300
+ if($testno =~ /^verifiedserver$/) {
2301
+ # this is the secret command that verifies that this actually is
2302
+ # the curl test server
2303
+ my $response = "WE ROOLZ: $$\r\n";
2304
+ my $len = length($response);
2305
+ sendcontrol "150 Binary junk ($len bytes).\r\n";
2306
+ senddata "WE ROOLZ: $$\r\n";
2307
+ close_dataconn(0);
2308
+ sendcontrol "226 File transfer complete\r\n";
2309
+ if($verbose) {
2310
+ print STDERR "FTPD: We returned proof we are the test server\n";
2311
+ }
2312
+ return 0;
2313
+ }
2314
+
2315
+ $testno =~ s/^([^0-9]*)//;
2316
+ my $testpart = "";
2317
+ if ($testno > 10000) {
2318
+ $testpart = $testno % 10000;
2319
+ $testno = int($testno / 10000);
2320
+ }
2321
+
2322
+ loadtest("$logdir/test$testno");
2323
+
2324
+ my @data = getpart("reply", "data$testpart");
2325
+
2326
+ my $size=0;
2327
+ for(@data) {
2328
+ $size += length($_);
2329
+ }
2330
+
2331
+ my %hash = getpartattr("reply", "data$testpart");
2332
+
2333
+ if($size || $hash{'sendzero'}) {
2334
+
2335
+ if($rest) {
2336
+ # move read pointer forward
2337
+ $size -= $rest;
2338
+ logmsg "REST $rest was removed from size, makes $size left\n";
2339
+ $rest = 0; # reset REST offset again
2340
+ }
2341
+ if($retrweirdo) {
2342
+ sendcontrol "150 Binary data connection for $testno () ($size bytes).\r\n",
2343
+ "226 File transfer complete\r\n";
2344
+
2345
+ for(@data) {
2346
+ my $send = $_;
2347
+ senddata $send;
2348
+ }
2349
+ close_dataconn(0);
2350
+ $retrweirdo=0; # switch off the weirdo again!
2351
+ }
2352
+ else {
2353
+ my $sz = "($size bytes)";
2354
+ if($retrnosize) {
2355
+ $sz = "size?";
2356
+ }
2357
+ elsif($retrsize > 0) {
2358
+ $sz = "($retrsize bytes)";
2359
+ }
2360
+
2361
+ sendcontrol "150 Binary data connection for $testno ($testpart) $sz.\r\n";
2362
+
2363
+ for(@data) {
2364
+ my $send = $_;
2365
+ senddata $send;
2366
+ }
2367
+ close_dataconn(0);
2368
+ sendcontrol "226 File transfer complete\r\n";
2369
+ }
2370
+ }
2371
+ else {
2372
+ sendcontrol "550 $testno: No such file or directory.\r\n";
2373
+ }
2374
+ return 0;
2375
+ }
2376
+
2377
+ sub STOR_ftp {
2378
+ my $testno=$_[0];
2379
+
2380
+ my $filename = "$logdir/upload.$testno";
2381
+
2382
+ if($datasockf_conn eq 'no') {
2383
+ if($nodataconn425) {
2384
+ sendcontrol "150 Opening data connection\r\n";
2385
+ sendcontrol "425 Can't open data connection\r\n";
2386
+ }
2387
+ elsif($nodataconn421) {
2388
+ sendcontrol "150 Opening data connection\r\n";
2389
+ sendcontrol "421 Connection timed out\r\n";
2390
+ }
2391
+ elsif($nodataconn150) {
2392
+ sendcontrol "150 Opening data connection\r\n";
2393
+ # client shall timeout
2394
+ }
2395
+ else {
2396
+ # client shall timeout
2397
+ }
2398
+ return 0;
2399
+ }
2400
+
2401
+ logmsg "STOR test number $testno in $filename\n";
2402
+
2403
+ sendcontrol "125 Gimme gimme gimme!\r\n";
2404
+
2405
+ open(my $file, ">", "$filename") ||
2406
+ return 0; # failed to open output
2407
+
2408
+ my $line;
2409
+ my $ulsize=0;
2410
+ my $disc=0;
2411
+ while (5 == (sysread DREAD, $line, 5)) {
2412
+ if($line eq "DATA\n") {
2413
+ my $i;
2414
+ sysread DREAD, $i, 5;
2415
+
2416
+ my $size = 0;
2417
+ if($i =~ /^([0-9a-fA-F]{4})\n/) {
2418
+ $size = hex($1);
2419
+ }
2420
+
2421
+ read_datasockf(\$line, $size);
2422
+
2423
+ #print STDERR " GOT: $size bytes\n";
2424
+
2425
+ $ulsize += $size;
2426
+ print $file $line if(!$nosave);
2427
+ logmsg "> Appending $size bytes to file\n";
2428
+ }
2429
+ elsif($line eq "DISC\n") {
2430
+ # disconnect!
2431
+ $disc=1;
2432
+ printf DWRITE "ACKD\n";
2433
+ last;
2434
+ }
2435
+ else {
2436
+ logmsg "No support for: $line";
2437
+ last;
2438
+ }
2439
+ if($storeresp) {
2440
+ # abort early
2441
+ last;
2442
+ }
2443
+ }
2444
+ if($nosave) {
2445
+ print $file "$ulsize bytes would've been stored here\n";
2446
+ }
2447
+ close($file);
2448
+ close_dataconn($disc);
2449
+ logmsg "received $ulsize bytes upload\n";
2450
+ if($storeresp) {
2451
+ sendcontrol "$storeresp\r\n";
2452
+ }
2453
+ else {
2454
+ sendcontrol "226 File transfer complete\r\n";
2455
+ }
2456
+ return 0;
2457
+ }
2458
+
2459
+ sub PASV_ftp {
2460
+ my ($arg, $cmd)=@_;
2461
+ my $pasvport;
2462
+
2463
+ # kill previous data connection sockfilt when alive
2464
+ if($datasockf_runs eq 'yes') {
2465
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
2466
+ logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
2467
+ }
2468
+ datasockf_state('STOPPED');
2469
+
2470
+ logmsg "====> Passive DATA channel requested by client\n";
2471
+
2472
+ logmsg "DATA sockfilt for passive data channel starting...\n";
2473
+
2474
+ # We fire up a new sockfilt to do the data transfer for us.
2475
+ my @datasockfcmd = ("./server/sockfilt".exe_ext('SRV'),
2476
+ "--ipv$ipvnum", "--port", 0,
2477
+ "--pidfile", $datasockf_pidfile,
2478
+ "--logfile", $datasockf_logfile);
2479
+ if($nodataconn) {
2480
+ push(@datasockfcmd, '--bindonly');
2481
+ }
2482
+ $slavepid = open2(\*DREAD, \*DWRITE, @datasockfcmd);
2483
+
2484
+ if($nodataconn) {
2485
+ datasockf_state('PASSIVE_NODATACONN');
2486
+ }
2487
+ else {
2488
+ datasockf_state('PASSIVE');
2489
+ }
2490
+
2491
+ print STDERR "@datasockfcmd\n" if($verbose);
2492
+
2493
+ print DWRITE "PING\n";
2494
+ my $pong;
2495
+ sysread_or_die(\*DREAD, \$pong, 5);
2496
+
2497
+ if($pong =~ /^FAIL/) {
2498
+ logmsg "DATA sockfilt said: FAIL\n";
2499
+ logmsg "DATA sockfilt for passive data channel failed\n";
2500
+ logmsg "DATA sockfilt not running\n";
2501
+ datasockf_state('STOPPED');
2502
+ sendcontrol "500 no free ports!\r\n";
2503
+ return;
2504
+ }
2505
+ elsif($pong !~ /^PONG/) {
2506
+ logmsg "DATA sockfilt unexpected response: $pong\n";
2507
+ logmsg "DATA sockfilt for passive data channel failed\n";
2508
+ logmsg "DATA sockfilt killed now\n";
2509
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
2510
+ logmsg "DATA sockfilt not running\n";
2511
+ datasockf_state('STOPPED');
2512
+ sendcontrol "500 no free ports!\r\n";
2513
+ return;
2514
+ }
2515
+
2516
+ logmsg "DATA sockfilt for passive data channel started (pid $slavepid)\n";
2517
+
2518
+ # Find out on what port we listen on or have bound
2519
+ my $i;
2520
+ print DWRITE "PORT\n";
2521
+
2522
+ # READ the response code
2523
+ sysread_or_die(\*DREAD, \$i, 5);
2524
+
2525
+ # READ the response size
2526
+ sysread_or_die(\*DREAD, \$i, 5);
2527
+
2528
+ my $size = 0;
2529
+ if($i =~ /^([0-9a-fA-F]{4})\n/) {
2530
+ $size = hex($1);
2531
+ }
2532
+
2533
+ # READ the response data
2534
+ read_datasockf(\$i, $size);
2535
+
2536
+ # The data is in the format
2537
+ # IPvX/NNN
2538
+
2539
+ if($i =~ /IPv(\d)\/(\d+)/) {
2540
+ # FIX: deal with IP protocol version
2541
+ $pasvport = $2;
2542
+ }
2543
+
2544
+ if(!$pasvport) {
2545
+ logmsg "DATA sockfilt unknown listener port\n";
2546
+ logmsg "DATA sockfilt for passive data channel failed\n";
2547
+ logmsg "DATA sockfilt killed now\n";
2548
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
2549
+ logmsg "DATA sockfilt not running\n";
2550
+ datasockf_state('STOPPED');
2551
+ sendcontrol "500 no free ports!\r\n";
2552
+ return;
2553
+ }
2554
+
2555
+ if($nodataconn) {
2556
+ my $str = nodataconn_str();
2557
+ logmsg "DATA sockfilt for passive data channel ($str) bound on port ".
2558
+ "$pasvport\n";
2559
+ }
2560
+ else {
2561
+ logmsg "DATA sockfilt for passive data channel listens on port ".
2562
+ "$pasvport\n";
2563
+ }
2564
+
2565
+ if($cmd ne "EPSV") {
2566
+ # PASV reply
2567
+ my $p=$listenaddr;
2568
+ $p =~ s/\./,/g;
2569
+ if($pasvbadip) {
2570
+ $p="1,2,3,4";
2571
+ }
2572
+ sendcontrol sprintf("227 Entering Passive Mode ($p,%d,%d)\n",
2573
+ int($pasvport/256), int($pasvport%256));
2574
+ }
2575
+ else {
2576
+ # EPSV reply
2577
+ sendcontrol sprintf("229 Entering Passive Mode (|||%d|)\n", $pasvport);
2578
+ }
2579
+
2580
+ logmsg "Client has been notified that DATA conn ".
2581
+ "will be accepted on port $pasvport\n";
2582
+
2583
+ if($nodataconn) {
2584
+ my $str = nodataconn_str();
2585
+ logmsg "====> Client fooled ($str)\n";
2586
+ return;
2587
+ }
2588
+
2589
+ eval {
2590
+ local $SIG{ALRM} = sub { die "alarm\n" };
2591
+
2592
+ # assume swift operations unless explicitly slow
2593
+ alarm ($datadelay?20:2);
2594
+
2595
+ # Wait for 'CNCT'
2596
+ my $input;
2597
+
2598
+ # FIX: Monitor ctrl conn for disconnect
2599
+
2600
+ while(sysread(DREAD, $input, 5)) {
2601
+
2602
+ if($input !~ /^CNCT/) {
2603
+ # we wait for a connected client
2604
+ logmsg "Odd, we got $input from client\n";
2605
+ next;
2606
+ }
2607
+ logmsg "Client connects to port $pasvport\n";
2608
+ last;
2609
+ }
2610
+ alarm 0;
2611
+ };
2612
+ if ($@) {
2613
+ # timed out
2614
+ logmsg "$srvrname server timed out awaiting data connection ".
2615
+ "on port $pasvport\n";
2616
+ logmsg "accept failed or connection not even attempted\n";
2617
+ logmsg "DATA sockfilt killed now\n";
2618
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
2619
+ logmsg "DATA sockfilt not running\n";
2620
+ datasockf_state('STOPPED');
2621
+ return;
2622
+ }
2623
+ else {
2624
+ logmsg "====> Client established passive DATA connection ".
2625
+ "on port $pasvport\n";
2626
+ }
2627
+
2628
+ return;
2629
+ }
2630
+
2631
+ #
2632
+ # Support both PORT and EPRT here.
2633
+ #
2634
+
2635
+ sub PORT_ftp {
2636
+ my ($arg, $cmd) = @_;
2637
+ my $port;
2638
+ my $addr;
2639
+
2640
+ # kill previous data connection sockfilt when alive
2641
+ if($datasockf_runs eq 'yes') {
2642
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
2643
+ logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
2644
+ }
2645
+ datasockf_state('STOPPED');
2646
+
2647
+ logmsg "====> Active DATA channel requested by client\n";
2648
+
2649
+ # We always ignore the given IP and use localhost.
2650
+
2651
+ if($cmd eq "PORT") {
2652
+ if($arg !~ /(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/) {
2653
+ logmsg "DATA sockfilt for active data channel not started ".
2654
+ "(bad PORT-line: $arg)\n";
2655
+ sendcontrol "500 silly you, go away\r\n";
2656
+ return;
2657
+ }
2658
+ $port = ($5<<8)+$6;
2659
+ $addr = "$1.$2.$3.$4";
2660
+ }
2661
+ # EPRT |2|::1|49706|
2662
+ elsif($cmd eq "EPRT") {
2663
+ if($arg !~ /(\d+)\|([^\|]+)\|(\d+)/) {
2664
+ logmsg "DATA sockfilt for active data channel not started ".
2665
+ "(bad EPRT-line: $arg)\n";
2666
+ sendcontrol "500 silly you, go away\r\n";
2667
+ return;
2668
+ }
2669
+ sendcontrol "200 Thanks for dropping by. We contact you later\r\n";
2670
+ $port = $3;
2671
+ $addr = $2;
2672
+ }
2673
+ else {
2674
+ logmsg "DATA sockfilt for active data channel not started ".
2675
+ "(invalid command: $cmd)\n";
2676
+ sendcontrol "500 we don't like $cmd now\r\n";
2677
+ return;
2678
+ }
2679
+
2680
+ if(!$port || $port > 65535) {
2681
+ logmsg "DATA sockfilt for active data channel not started ".
2682
+ "(illegal PORT number: $port)\n";
2683
+ return;
2684
+ }
2685
+
2686
+ if($nodataconn) {
2687
+ my $str = nodataconn_str();
2688
+ logmsg "DATA sockfilt for active data channel not started ($str)\n";
2689
+ datasockf_state('ACTIVE_NODATACONN');
2690
+ logmsg "====> Active DATA channel not established\n";
2691
+ return;
2692
+ }
2693
+
2694
+ logmsg "DATA sockfilt for active data channel starting...\n";
2695
+
2696
+ # We fire up a new sockfilt to do the data transfer for us.
2697
+ my @datasockfcmd = ("./server/sockfilt".exe_ext('SRV'),
2698
+ "--ipv$ipvnum", "--connect", $port, "--addr", $addr,
2699
+ "--pidfile", $datasockf_pidfile,
2700
+ "--logfile", $datasockf_logfile);
2701
+ $slavepid = open2(\*DREAD, \*DWRITE, @datasockfcmd);
2702
+
2703
+ datasockf_state('ACTIVE');
2704
+
2705
+ print STDERR "@datasockfcmd\n" if($verbose);
2706
+
2707
+ print DWRITE "PING\n";
2708
+ my $pong;
2709
+ sysread_or_die(\*DREAD, \$pong, 5);
2710
+
2711
+ if($pong =~ /^FAIL/) {
2712
+ logmsg "DATA sockfilt said: FAIL\n";
2713
+ logmsg "DATA sockfilt for active data channel failed\n";
2714
+ logmsg "DATA sockfilt not running\n";
2715
+ datasockf_state('STOPPED');
2716
+ # client shall timeout awaiting connection from server
2717
+ return;
2718
+ }
2719
+ elsif($pong !~ /^PONG/) {
2720
+ logmsg "DATA sockfilt unexpected response: $pong\n";
2721
+ logmsg "DATA sockfilt for active data channel failed\n";
2722
+ logmsg "DATA sockfilt killed now\n";
2723
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
2724
+ logmsg "DATA sockfilt not running\n";
2725
+ datasockf_state('STOPPED');
2726
+ # client shall timeout awaiting connection from server
2727
+ return;
2728
+ }
2729
+
2730
+ logmsg "DATA sockfilt for active data channel started (pid $slavepid)\n";
2731
+
2732
+ logmsg "====> Active DATA channel connected to client port $port\n";
2733
+
2734
+ return;
2735
+ }
2736
+
2737
+ #**********************************************************************
2738
+ # datasockf_state is used to change variables that keep state info
2739
+ # relative to the FTP secondary or data sockfilt process as soon as
2740
+ # one of the five possible stable states is reached. Variables that
2741
+ # are modified by this sub may be checked independently but should
2742
+ # not be changed except by calling this sub.
2743
+ #
2744
+ sub datasockf_state {
2745
+ my $state = $_[0];
2746
+
2747
+ if($state eq 'STOPPED') {
2748
+ # Data sockfilter initial state, not running,
2749
+ # not connected and not used.
2750
+ $datasockf_state = $state;
2751
+ $datasockf_mode = 'none';
2752
+ $datasockf_runs = 'no';
2753
+ $datasockf_conn = 'no';
2754
+ }
2755
+ elsif($state eq 'PASSIVE') {
2756
+ # Data sockfilter accepted connection from client.
2757
+ $datasockf_state = $state;
2758
+ $datasockf_mode = 'passive';
2759
+ $datasockf_runs = 'yes';
2760
+ $datasockf_conn = 'yes';
2761
+ }
2762
+ elsif($state eq 'ACTIVE') {
2763
+ # Data sockfilter has connected to client.
2764
+ $datasockf_state = $state;
2765
+ $datasockf_mode = 'active';
2766
+ $datasockf_runs = 'yes';
2767
+ $datasockf_conn = 'yes';
2768
+ }
2769
+ elsif($state eq 'PASSIVE_NODATACONN') {
2770
+ # Data sockfilter bound port without listening,
2771
+ # client won't be able to establish data connection.
2772
+ $datasockf_state = $state;
2773
+ $datasockf_mode = 'passive';
2774
+ $datasockf_runs = 'yes';
2775
+ $datasockf_conn = 'no';
2776
+ }
2777
+ elsif($state eq 'ACTIVE_NODATACONN') {
2778
+ # Data sockfilter does not even run,
2779
+ # client awaits data connection from server in vain.
2780
+ $datasockf_state = $state;
2781
+ $datasockf_mode = 'active';
2782
+ $datasockf_runs = 'no';
2783
+ $datasockf_conn = 'no';
2784
+ }
2785
+ else {
2786
+ die "Internal error. Unknown datasockf state: $state!";
2787
+ }
2788
+ }
2789
+
2790
+ #**********************************************************************
2791
+ # nodataconn_str returns string of effective nodataconn command. Notice
2792
+ # that $nodataconn may be set alone or in addition to a $nodataconnXXX.
2793
+ #
2794
+ sub nodataconn_str {
2795
+ my $str;
2796
+ # order matters
2797
+ $str = 'NODATACONN' if($nodataconn);
2798
+ $str = 'NODATACONN425' if($nodataconn425);
2799
+ $str = 'NODATACONN421' if($nodataconn421);
2800
+ $str = 'NODATACONN150' if($nodataconn150);
2801
+ return "$str";
2802
+ }
2803
+
2804
+ #**********************************************************************
2805
+ # customize configures test server operation for each curl test, reading
2806
+ # configuration commands/parameters from server commands file each time
2807
+ # a new client control connection is established with the test server.
2808
+ # On success returns 1, otherwise zero.
2809
+ #
2810
+ sub customize {
2811
+ my($cmdfile) = @_;
2812
+ $ctrldelay = 0; # default is no throttling of the ctrl stream
2813
+ $datadelay = 0; # default is no throttling of the data stream
2814
+ $retrweirdo = 0; # default is no use of RETRWEIRDO
2815
+ $retrnosize = 0; # default is no use of RETRNOSIZE
2816
+ $retrsize = 0; # default is no use of RETRSIZE
2817
+ $pasvbadip = 0; # default is no use of PASVBADIP
2818
+ $nosave = 0; # default is to actually save uploaded data to file
2819
+ $nodataconn = 0; # default is to establish or accept data channel
2820
+ $nodataconn425 = 0; # default is to not send 425 without data channel
2821
+ $nodataconn421 = 0; # default is to not send 421 without data channel
2822
+ $nodataconn150 = 0; # default is to not send 150 without data channel
2823
+ $storeresp = ""; # send as ultimate STOR response
2824
+ $postfetch = ""; # send as header after a FETCH response
2825
+ @capabilities = (); # default is to not support capability commands
2826
+ @auth_mechs = (); # default is to not support authentication commands
2827
+ %fulltextreply = ();#
2828
+ %commandreply = (); #
2829
+ %customcount = (); #
2830
+ %delayreply = (); #
2831
+
2832
+ open(my $custom, "<", "$logdir/$SERVERCMD") ||
2833
+ return 1;
2834
+
2835
+ logmsg "FTPD: Getting commands from $logdir/$SERVERCMD\n";
2836
+
2837
+ while(<$custom>) {
2838
+ if($_ =~ /REPLY \"([A-Z]+ [A-Za-z0-9+-\/=\*. ]+)\" (.*)/) {
2839
+ $fulltextreply{$1}=eval "qq{$2}";
2840
+ logmsg "FTPD: set custom reply for $1\n";
2841
+ }
2842
+ elsif($_ =~ /REPLY(LF|) ([A-Za-z0-9+\/=\*]*) (.*)/) {
2843
+ $commandreply{$2}=eval "qq{$3}";
2844
+ if($1 ne "LF") {
2845
+ $commandreply{$2}.="\r\n";
2846
+ }
2847
+ else {
2848
+ $commandreply{$2}.="\n";
2849
+ }
2850
+ if($2 eq "") {
2851
+ logmsg "FTPD: set custom reply for empty command\n";
2852
+ }
2853
+ else {
2854
+ logmsg "FTPD: set custom reply for $2 command\n";
2855
+ }
2856
+ }
2857
+ elsif($_ =~ /COUNT ([A-Z]+) (.*)/) {
2858
+ # we blank the custom reply for this command when having
2859
+ # been used this number of times
2860
+ $customcount{$1}=$2;
2861
+ logmsg "FTPD: blank custom reply for $1 command after $2 uses\n";
2862
+ }
2863
+ elsif($_ =~ /DELAY ([A-Z]+) (\d*)/) {
2864
+ $delayreply{$1}=$2;
2865
+ logmsg "FTPD: delay reply for $1 with $2 seconds\n";
2866
+ }
2867
+ elsif($_ =~ /POSTFETCH (.*)/) {
2868
+ logmsg "FTPD: read POSTFETCH header data\n";
2869
+ $postfetch = $1;
2870
+ }
2871
+ elsif($_ =~ /SLOWDOWNDATA/) {
2872
+ $ctrldelay=0;
2873
+ $datadelay=0.005;
2874
+ logmsg "FTPD: send response data with 5ms delay per byte\n";
2875
+ }
2876
+ elsif($_ =~ /SLOWDOWN/) {
2877
+ $ctrldelay=0.005;
2878
+ $datadelay=0.005;
2879
+ logmsg "FTPD: send response with 5ms delay between each byte\n";
2880
+ }
2881
+ elsif($_ =~ /RETRWEIRDO/) {
2882
+ logmsg "FTPD: instructed to use RETRWEIRDO\n";
2883
+ $retrweirdo=1;
2884
+ }
2885
+ elsif($_ =~ /RETRNOSIZE/) {
2886
+ logmsg "FTPD: instructed to use RETRNOSIZE\n";
2887
+ $retrnosize=1;
2888
+ }
2889
+ elsif($_ =~ /RETRSIZE (\d+)/) {
2890
+ $retrsize= $1;
2891
+ logmsg "FTPD: instructed to use RETRSIZE = $1\n";
2892
+ }
2893
+ elsif($_ =~ /PASVBADIP/) {
2894
+ logmsg "FTPD: instructed to use PASVBADIP\n";
2895
+ $pasvbadip=1;
2896
+ }
2897
+ elsif($_ =~ /NODATACONN425/) {
2898
+ # applies to both active and passive FTP modes
2899
+ logmsg "FTPD: instructed to use NODATACONN425\n";
2900
+ $nodataconn425=1;
2901
+ $nodataconn=1;
2902
+ }
2903
+ elsif($_ =~ /NODATACONN421/) {
2904
+ # applies to both active and passive FTP modes
2905
+ logmsg "FTPD: instructed to use NODATACONN421\n";
2906
+ $nodataconn421=1;
2907
+ $nodataconn=1;
2908
+ }
2909
+ elsif($_ =~ /NODATACONN150/) {
2910
+ # applies to both active and passive FTP modes
2911
+ logmsg "FTPD: instructed to use NODATACONN150\n";
2912
+ $nodataconn150=1;
2913
+ $nodataconn=1;
2914
+ }
2915
+ elsif($_ =~ /NODATACONN/) {
2916
+ # applies to both active and passive FTP modes
2917
+ logmsg "FTPD: instructed to use NODATACONN\n";
2918
+ $nodataconn=1;
2919
+ }
2920
+ elsif($_ =~ /^STOR (.*)/) {
2921
+ $storeresp=$1;
2922
+ logmsg "FTPD: instructed to use respond to STOR with '$storeresp'\n";
2923
+ }
2924
+ elsif($_ =~ /CAPA (.*)/) {
2925
+ logmsg "FTPD: instructed to support CAPABILITY command\n";
2926
+ @capabilities = split(/ (?!(?:[^" ]|[^"] [^"])+")/, $1);
2927
+ foreach (@capabilities) {
2928
+ $_ = $1 if /^"(.*)"$/;
2929
+ }
2930
+ }
2931
+ elsif($_ =~ /AUTH (.*)/) {
2932
+ logmsg "FTPD: instructed to support AUTHENTICATION command\n";
2933
+ @auth_mechs = split(/ /, $1);
2934
+ }
2935
+ elsif($_ =~ /NOSAVE/) {
2936
+ # don't actually store the file we upload - to be used when
2937
+ # uploading insanely huge amounts
2938
+ $nosave = 1;
2939
+ logmsg "FTPD: NOSAVE prevents saving of uploaded data\n";
2940
+ }
2941
+ elsif($_ =~ /^Testnum (\d+)/){
2942
+ $testno = $1;
2943
+ logmsg "FTPD: run test case number: $testno\n";
2944
+ }
2945
+ }
2946
+ close($custom);
2947
+ }
2948
+
2949
+ #----------------------------------------------------------------------
2950
+ #----------------------------------------------------------------------
2951
+ #--------------------------- END OF SUBS ----------------------------
2952
+ #----------------------------------------------------------------------
2953
+ #----------------------------------------------------------------------
2954
+
2955
+ #**********************************************************************
2956
+ # Parse command line options
2957
+ #
2958
+ # Options:
2959
+ #
2960
+ # --verbose # verbose
2961
+ # --srcdir # source directory
2962
+ # --id # server instance number
2963
+ # --proto # server protocol
2964
+ # --pidfile # server pid file
2965
+ # --portfile # server port file
2966
+ # --logfile # server log file
2967
+ # --logdir # server log directory
2968
+ # --ipv4 # server IP version 4
2969
+ # --ipv6 # server IP version 6
2970
+ # --port # server listener port
2971
+ # --addr # server address for listener port binding
2972
+ #
2973
+ while(@ARGV) {
2974
+ if($ARGV[0] eq '--verbose') {
2975
+ $verbose = 1;
2976
+ }
2977
+ elsif($ARGV[0] eq '--srcdir') {
2978
+ if($ARGV[1]) {
2979
+ $srcdir = $ARGV[1];
2980
+ shift @ARGV;
2981
+ }
2982
+ }
2983
+ elsif($ARGV[0] eq '--id') {
2984
+ if($ARGV[1] && ($ARGV[1] =~ /^(\d+)$/)) {
2985
+ $idnum = $1 if($1 > 0);
2986
+ shift @ARGV;
2987
+ }
2988
+ }
2989
+ elsif($ARGV[0] eq '--proto') {
2990
+ if($ARGV[1] && ($ARGV[1] =~ /^(ftp|imap|pop3|smtp)$/)) {
2991
+ $proto = $1;
2992
+ shift @ARGV;
2993
+ }
2994
+ else {
2995
+ die "unsupported protocol $ARGV[1]";
2996
+ }
2997
+ }
2998
+ elsif($ARGV[0] eq '--pidfile') {
2999
+ if($ARGV[1]) {
3000
+ $pidfile = $ARGV[1];
3001
+ shift @ARGV;
3002
+ }
3003
+ }
3004
+ elsif($ARGV[0] eq '--portfile') {
3005
+ if($ARGV[1]) {
3006
+ $portfile = $ARGV[1];
3007
+ shift @ARGV;
3008
+ }
3009
+ }
3010
+ elsif($ARGV[0] eq '--logfile') {
3011
+ if($ARGV[1]) {
3012
+ $logfile = $ARGV[1];
3013
+ shift @ARGV;
3014
+ }
3015
+ }
3016
+ elsif($ARGV[0] eq '--logdir') {
3017
+ if($ARGV[1]) {
3018
+ $logdir = $ARGV[1];
3019
+ shift @ARGV;
3020
+ }
3021
+ }
3022
+ elsif($ARGV[0] eq '--ipv4') {
3023
+ $ipvnum = 4;
3024
+ $listenaddr = '127.0.0.1' if($listenaddr eq '::1');
3025
+ }
3026
+ elsif($ARGV[0] eq '--ipv6') {
3027
+ $ipvnum = 6;
3028
+ $listenaddr = '::1' if($listenaddr eq '127.0.0.1');
3029
+ }
3030
+ elsif($ARGV[0] eq '--port') {
3031
+ if($ARGV[1] =~ /^(\d+)$/) {
3032
+ $port = $1;
3033
+ shift @ARGV;
3034
+ }
3035
+ }
3036
+ elsif($ARGV[0] eq '--addr') {
3037
+ if($ARGV[1]) {
3038
+ my $tmpstr = $ARGV[1];
3039
+ if($tmpstr =~ /^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)$/) {
3040
+ $listenaddr = "$1.$2.$3.$4" if($ipvnum == 4);
3041
+ }
3042
+ elsif($ipvnum == 6) {
3043
+ $listenaddr = $tmpstr;
3044
+ $listenaddr =~ s/^\[(.*)\]$/$1/;
3045
+ }
3046
+ shift @ARGV;
3047
+ }
3048
+ }
3049
+ else {
3050
+ print STDERR "\nWarning: ftpserver.pl unknown parameter: $ARGV[0]\n";
3051
+ }
3052
+ shift @ARGV;
3053
+ }
3054
+
3055
+ #***************************************************************************
3056
+ # Initialize command line option dependent variables
3057
+ #
3058
+
3059
+ if($pidfile) {
3060
+ # Use our pidfile directory to store the other pidfiles
3061
+ $piddir = dirname($pidfile);
3062
+ }
3063
+ else {
3064
+ # Use the current directory to store all the pidfiles
3065
+ $piddir = $path;
3066
+ $pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
3067
+ }
3068
+ if(!$portfile) {
3069
+ $portfile = $piddir . "/" . $PORTFILE;
3070
+ }
3071
+ if(!$srcdir) {
3072
+ $srcdir = $ENV{'srcdir'} || '.';
3073
+ }
3074
+ if(!$logfile) {
3075
+ $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
3076
+ }
3077
+
3078
+ $mainsockf_pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
3079
+ $mainsockf_logfile =
3080
+ mainsockf_logfilename($logdir, $proto, $ipvnum, $idnum);
3081
+
3082
+ if($proto eq 'ftp') {
3083
+ $datasockf_pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
3084
+ $datasockf_logfile =
3085
+ datasockf_logfilename($logdir, $proto, $ipvnum, $idnum);
3086
+ }
3087
+
3088
+ $srvrname = servername_str($proto, $ipvnum, $idnum);
3089
+ $serverlogs_lockfile = "$logdir/$LOCKDIR/${srvrname}.lock";
3090
+
3091
+ $idstr = "$idnum" if($idnum > 1);
3092
+
3093
+ protocolsetup($proto);
3094
+
3095
+ $SIG{INT} = \&exit_signal_handler;
3096
+ $SIG{TERM} = \&exit_signal_handler;
3097
+
3098
+ startsf();
3099
+
3100
+ # actual port
3101
+ if($portfile && !$port) {
3102
+ my $aport;
3103
+ open(my $p, "<", "$portfile");
3104
+ $aport = <$p>;
3105
+ close($p);
3106
+ $port = 0 + $aport;
3107
+ }
3108
+
3109
+ logmsg sprintf("%s server listens on port IPv${ipvnum}/${port}\n", uc($proto));
3110
+
3111
+ open(my $pid, ">", "$pidfile");
3112
+ print $pid $$."\n";
3113
+ close($pid);
3114
+
3115
+ logmsg("logged pid $$ in $pidfile\n");
3116
+
3117
+ while(1) {
3118
+
3119
+ # kill previous data connection sockfilt when alive
3120
+ if($datasockf_runs eq 'yes') {
3121
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
3122
+ logmsg "DATA sockfilt for $datasockf_mode data channel killed now\n";
3123
+ }
3124
+ datasockf_state('STOPPED');
3125
+
3126
+ #
3127
+ # We read 'sockfilt' commands.
3128
+ #
3129
+ my $input;
3130
+
3131
+ logmsg "Awaiting input\n";
3132
+ sysread_or_die(\*SFREAD, \$input, 5);
3133
+
3134
+ if($input !~ /^CNCT/) {
3135
+ # we wait for a connected client
3136
+ logmsg "MAIN sockfilt said: $input";
3137
+ next;
3138
+ }
3139
+ logmsg "====> Client connect\n";
3140
+
3141
+ set_advisor_read_lock($serverlogs_lockfile);
3142
+ $serverlogslocked = 1;
3143
+
3144
+ # flush data:
3145
+ $| = 1;
3146
+
3147
+ &customize(); # read test control instructions
3148
+ loadtest("$logdir/test$testno");
3149
+
3150
+ my $welcome = $commandreply{"welcome"};
3151
+ if(!$welcome) {
3152
+ $welcome = $displaytext{"welcome"};
3153
+ }
3154
+ else {
3155
+ # clear it after use
3156
+ $commandreply{"welcome"}="";
3157
+ if($welcome !~ /\r\n\z/) {
3158
+ $welcome .= "\r\n";
3159
+ }
3160
+ }
3161
+ sendcontrol $welcome;
3162
+
3163
+ #remove global variables from last connection
3164
+ if($ftplistparserstate) {
3165
+ undef $ftplistparserstate;
3166
+ }
3167
+ if($ftptargetdir) {
3168
+ $ftptargetdir = "";
3169
+ }
3170
+
3171
+ if($verbose) {
3172
+ print STDERR "OUT: $welcome";
3173
+ }
3174
+
3175
+ my $full = "";
3176
+
3177
+ while(1) {
3178
+ my $i;
3179
+
3180
+ # Now we expect to read DATA\n[hex size]\n[prot], where the [prot]
3181
+ # part only is FTP lingo.
3182
+
3183
+ # COMMAND
3184
+ sysread_or_die(\*SFREAD, \$i, 5);
3185
+
3186
+ if($i !~ /^DATA/) {
3187
+ logmsg "MAIN sockfilt said $i";
3188
+ if($i =~ /^DISC/) {
3189
+ # disconnect
3190
+ printf SFWRITE "ACKD\n";
3191
+ last;
3192
+ }
3193
+ next;
3194
+ }
3195
+
3196
+ # SIZE of data
3197
+ sysread_or_die(\*SFREAD, \$i, 5);
3198
+
3199
+ my $size = 0;
3200
+ if($i =~ /^([0-9a-fA-F]{4})\n/) {
3201
+ $size = hex($1);
3202
+ }
3203
+
3204
+ # data
3205
+ read_mainsockf(\$input, $size);
3206
+
3207
+ ftpmsg $input;
3208
+
3209
+ $full .= $input;
3210
+
3211
+ # Loop until command completion
3212
+ next unless($full =~ /\r\n$/);
3213
+
3214
+ # Remove trailing CRLF.
3215
+ $full =~ s/[\n\r]+$//;
3216
+
3217
+ my $FTPCMD;
3218
+ my $FTPARG;
3219
+ if($proto eq "imap") {
3220
+ # IMAP is different with its identifier first on the command line
3221
+ if(($full =~ /^([^ ]+) ([^ ]+) (.*)/) ||
3222
+ ($full =~ /^([^ ]+) ([^ ]+)/)) {
3223
+ $cmdid=$1; # set the global variable
3224
+ $FTPCMD=$2;
3225
+ $FTPARG=$3;
3226
+ }
3227
+ # IMAP authentication cancellation
3228
+ elsif($full =~ /^\*$/) {
3229
+ # Command id has already been set
3230
+ $FTPCMD="*";
3231
+ $FTPARG="";
3232
+ }
3233
+ # IMAP long "commands" are base64 authentication data
3234
+ elsif($full =~ /^[A-Z0-9+\/]*={0,2}$/i) {
3235
+ # Command id has already been set
3236
+ $FTPCMD=$full;
3237
+ $FTPARG="";
3238
+ }
3239
+ else {
3240
+ sendcontrol "$full BAD Command\r\n";
3241
+ last;
3242
+ }
3243
+ }
3244
+ elsif($full =~ /^([A-Z]{3,4})(\s(.*))?$/i) {
3245
+ $FTPCMD=$1;
3246
+ $FTPARG=$3;
3247
+ }
3248
+ elsif($proto eq "pop3") {
3249
+ # POP3 authentication cancellation
3250
+ if($full =~ /^\*$/) {
3251
+ $FTPCMD="*";
3252
+ $FTPARG="";
3253
+ }
3254
+ # POP3 long "commands" are base64 authentication data
3255
+ elsif($full =~ /^[A-Z0-9+\/]*={0,2}$/i) {
3256
+ $FTPCMD=$full;
3257
+ $FTPARG="";
3258
+ }
3259
+ else {
3260
+ sendcontrol "-ERR Unrecognized command\r\n";
3261
+ last;
3262
+ }
3263
+ }
3264
+ elsif($proto eq "smtp") {
3265
+ # SMTP authentication cancellation
3266
+ if($full =~ /^\*$/) {
3267
+ $FTPCMD="*";
3268
+ $FTPARG="";
3269
+ }
3270
+ # SMTP long "commands" are base64 authentication data
3271
+ elsif($full =~ /^[A-Z0-9+\/]{0,512}={0,2}$/i) {
3272
+ $FTPCMD=$full;
3273
+ $FTPARG="";
3274
+ }
3275
+ else {
3276
+ sendcontrol "500 Unrecognized command\r\n";
3277
+ last;
3278
+ }
3279
+ }
3280
+ else {
3281
+ sendcontrol "500 Unrecognized command\r\n";
3282
+ last;
3283
+ }
3284
+
3285
+ logmsg "< \"$full\"\n";
3286
+
3287
+ if($verbose) {
3288
+ print STDERR "IN: $full\n";
3289
+ }
3290
+
3291
+ $full = "";
3292
+
3293
+ my $delay = $delayreply{$FTPCMD};
3294
+ if($delay) {
3295
+ # just go sleep this many seconds!
3296
+ logmsg("Sleep for $delay seconds\n");
3297
+ my $twentieths = $delay * 20;
3298
+ while($twentieths--) {
3299
+ portable_sleep(0.05) unless($got_exit_signal);
3300
+ }
3301
+ }
3302
+
3303
+ my $check = 1; # no response yet
3304
+
3305
+ # See if there is a custom reply for the full text
3306
+ my $fulltext = $FTPARG ? $FTPCMD . " " . $FTPARG : $FTPCMD;
3307
+ my $text = $fulltextreply{$fulltext};
3308
+ if($text && ($text ne "")) {
3309
+ sendcontrol "$text\r\n";
3310
+ $check = 0;
3311
+ }
3312
+ else {
3313
+ # See if there is a custom reply for the command
3314
+ $text = $commandreply{$FTPCMD};
3315
+ if($text && ($text ne "")) {
3316
+ if($customcount{$FTPCMD} && (!--$customcount{$FTPCMD})) {
3317
+ # used enough times so blank the custom command reply
3318
+ $commandreply{$FTPCMD}="";
3319
+ }
3320
+
3321
+ sendcontrol $text;
3322
+ $check = 0;
3323
+ }
3324
+ else {
3325
+ # See if there is any display text for the command
3326
+ $text = $displaytext{$FTPCMD};
3327
+ if($text && ($text ne "")) {
3328
+ if($proto eq 'imap') {
3329
+ sendcontrol "$cmdid $text\r\n";
3330
+ }
3331
+ else {
3332
+ sendcontrol "$text\r\n";
3333
+ }
3334
+
3335
+ $check = 0;
3336
+ }
3337
+
3338
+ # only perform this if we're not faking a reply
3339
+ my $func = $commandfunc{uc($FTPCMD)};
3340
+ if($func) {
3341
+ &$func($FTPARG, $FTPCMD);
3342
+ $check = 0;
3343
+ }
3344
+ }
3345
+ }
3346
+
3347
+ if($check) {
3348
+ logmsg "$FTPCMD wasn't handled!\n";
3349
+ if($proto eq 'pop3') {
3350
+ sendcontrol "-ERR $FTPCMD is not dealt with!\r\n";
3351
+ }
3352
+ elsif($proto eq 'imap') {
3353
+ sendcontrol "$cmdid BAD $FTPCMD is not dealt with!\r\n";
3354
+ }
3355
+ else {
3356
+ sendcontrol "500 $FTPCMD is not dealt with!\r\n";
3357
+ }
3358
+ }
3359
+
3360
+ } # while(1)
3361
+ logmsg "====> Client disconnected\n";
3362
+
3363
+ if($serverlogslocked) {
3364
+ $serverlogslocked = 0;
3365
+ clear_advisor_read_lock($serverlogs_lockfile);
3366
+ }
3367
+ }
3368
+
3369
+ killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
3370
+ unlink($pidfile);
3371
+ if($serverlogslocked) {
3372
+ $serverlogslocked = 0;
3373
+ clear_advisor_read_lock($serverlogs_lockfile);
3374
+ }
3375
+
3376
+ exit;
local-test-curl-delta-01/afc-curl/tests/http3-server.pl ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ #***************************************************************************
25
+
26
+ # This script invokes nghttpx properly to have it serve HTTP/3 for us.
27
+ # nghttpx runs as a proxy in front of our "actual" HTTP/1 server.
28
+
29
+ use Cwd;
30
+ use Cwd 'abs_path';
31
+ use File::Basename;
32
+
33
+ my $logdir = "log";
34
+ my $pidfile = "$logdir/nghttpx.pid";
35
+ my $logfile = "$logdir/http3.log";
36
+ my $nghttpx = "nghttpx";
37
+ my $listenport = 9017;
38
+ my $connect = "127.0.0.1,8990";
39
+ my $cert = "Server-localhost-sv";
40
+ my $conf = "nghttpx.conf";
41
+ my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
42
+
43
+ #***************************************************************************
44
+ # Process command line options
45
+ #
46
+ while(@ARGV) {
47
+ if($ARGV[0] eq '--verbose') {
48
+ $verbose = 1;
49
+ }
50
+ elsif($ARGV[0] eq '--pidfile') {
51
+ if($ARGV[1]) {
52
+ $pidfile = $ARGV[1];
53
+ shift @ARGV;
54
+ }
55
+ }
56
+ elsif($ARGV[0] eq '--nghttpx') {
57
+ if($ARGV[1]) {
58
+ $nghttpx = $ARGV[1];
59
+ shift @ARGV;
60
+ }
61
+ }
62
+ elsif($ARGV[0] eq '--port') {
63
+ if($ARGV[1]) {
64
+ $listenport = $ARGV[1];
65
+ shift @ARGV;
66
+ }
67
+ }
68
+ elsif($ARGV[0] eq '--connect') {
69
+ if($ARGV[1]) {
70
+ $connect = $ARGV[1];
71
+ $connect =~ s/:/,/;
72
+ shift @ARGV;
73
+ }
74
+ }
75
+ elsif($ARGV[0] eq '--cert') {
76
+ if($ARGV[1]) {
77
+ $cert = $ARGV[1];
78
+ shift @ARGV;
79
+ }
80
+ }
81
+ elsif($ARGV[0] eq '--logfile') {
82
+ if($ARGV[1]) {
83
+ $logfile = $ARGV[1];
84
+ shift @ARGV;
85
+ }
86
+ }
87
+ elsif($ARGV[0] eq '--logdir') {
88
+ if($ARGV[1]) {
89
+ $logdir = $ARGV[1];
90
+ shift @ARGV;
91
+ }
92
+ }
93
+ elsif($ARGV[0] eq '--conf') {
94
+ if($ARGV[1]) {
95
+ $conf = $ARGV[1];
96
+ shift @ARGV;
97
+ }
98
+ }
99
+ else {
100
+ print STDERR "\nWarning: http3-server.pl unknown parameter: $ARGV[0]\n";
101
+ }
102
+ shift @ARGV;
103
+ }
104
+
105
+ my $srcdir = dirname(__FILE__);
106
+ $certfile = "$srcdir/certs/$cert.pem";
107
+ $keyfile = "$srcdir/certs/$cert.key";
108
+ $certfile = abs_path($certfile);
109
+ $keyfile = abs_path($keyfile);
110
+
111
+ my $cmdline="$nghttpx --http2-proxy --backend=$connect ".
112
+ "--backend-keep-alive-timeout=500ms ".
113
+ "--frontend=\"*,$listenport\" ".
114
+ "--frontend=\"*,$listenport;quic\" ".
115
+ "--log-level=INFO ".
116
+ "--pid-file=$pidfile ".
117
+ "--errorlog-file=$logfile ".
118
+ "--conf=$conf ".
119
+ "$keyfile $certfile";
120
+ print "RUN: $cmdline\n" if($verbose);
121
+ exec("exec $cmdline 2>$dev_null");
local-test-curl-delta-01/afc-curl/tests/memanalyze.pl ADDED
@@ -0,0 +1,434 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+ #
26
+ # Example input:
27
+ #
28
+ # MEM mprintf.c:1094 malloc(32) = e5718
29
+ # MEM mprintf.c:1103 realloc(e5718, 64) = e6118
30
+ # MEM sendf.c:232 free(f6520)
31
+
32
+ my $mallocs=0;
33
+ my $callocs=0;
34
+ my $reallocs=0;
35
+ my $strdups=0;
36
+ my $wcsdups=0;
37
+ my $showlimit;
38
+ my $sends=0;
39
+ my $recvs=0;
40
+ my $sockets=0;
41
+
42
+ while(1) {
43
+ if($ARGV[0] eq "-v") {
44
+ $verbose=1;
45
+ shift @ARGV;
46
+ }
47
+ elsif($ARGV[0] eq "-t") {
48
+ $trace=1;
49
+ shift @ARGV;
50
+ }
51
+ elsif($ARGV[0] eq "-l") {
52
+ # only show what alloc that caused a memlimit failure
53
+ $showlimit=1;
54
+ shift @ARGV;
55
+ }
56
+ else {
57
+ last;
58
+ }
59
+ }
60
+
61
+ my $memsum; # the total number of memory allocated over the lifetime
62
+ my $maxmem; # the high water mark
63
+
64
+ sub newtotal {
65
+ my ($newtot)=@_;
66
+ # count a max here
67
+
68
+ if($newtot > $maxmem) {
69
+ $maxmem= $newtot;
70
+ }
71
+ }
72
+
73
+ my $file = $ARGV[0];
74
+
75
+ if(! -f $file) {
76
+ print "Usage: memanalyze.pl [options] <dump file>\n",
77
+ "Options:\n",
78
+ " -l memlimit failure displayed\n",
79
+ " -v Verbose\n",
80
+ " -t Trace\n";
81
+ exit;
82
+ }
83
+
84
+ open(my $fileh, "<", "$file");
85
+
86
+ if($showlimit) {
87
+ while(<$fileh>) {
88
+ if(/^LIMIT.*memlimit$/) {
89
+ print $_;
90
+ last;
91
+ }
92
+ }
93
+ close($fileh);
94
+ exit;
95
+ }
96
+
97
+
98
+ my $lnum=0;
99
+ while(<$fileh>) {
100
+ chomp $_;
101
+ $line = $_;
102
+ $lnum++;
103
+ if($line =~ /^LIMIT ([^ ]*):(\d*) (.*)/) {
104
+ # new memory limit test prefix
105
+ my $i = $3;
106
+ my ($source, $linenum) = ($1, $2);
107
+ if($trace && ($i =~ /([^ ]*) reached memlimit/)) {
108
+ print "LIMIT: $1 returned error at $source:$linenum\n";
109
+ }
110
+ }
111
+ elsif($line =~ /^MEM ([^ ]*):(\d*) (.*)/) {
112
+ # generic match for the filename+linenumber
113
+ $source = $1;
114
+ $linenum = $2;
115
+ $function = $3;
116
+
117
+ if($function =~ /free\((\(nil\)|0x([0-9a-f]*))/) {
118
+ $addr = $2;
119
+ if($1 eq "(nil)") {
120
+ ; # do nothing when free(NULL)
121
+ }
122
+ elsif(!exists $sizeataddr{$addr}) {
123
+ print "FREE ERROR: No memory allocated: $line\n";
124
+ }
125
+ elsif(-1 == $sizeataddr{$addr}) {
126
+ print "FREE ERROR: Memory freed twice: $line\n";
127
+ print "FREE ERROR: Previously freed at: ".$getmem{$addr}."\n";
128
+ }
129
+ else {
130
+ $totalmem -= $sizeataddr{$addr};
131
+ if($trace) {
132
+ print "FREE: malloc at ".$getmem{$addr}." is freed again at $source:$linenum\n";
133
+ printf("FREE: %d bytes freed, left allocated: $totalmem bytes\n", $sizeataddr{$addr});
134
+ }
135
+
136
+ newtotal($totalmem);
137
+ $frees++;
138
+
139
+ $sizeataddr{$addr}=-1; # set -1 to mark as freed
140
+ $getmem{$addr}="$source:$linenum";
141
+
142
+ }
143
+ }
144
+ elsif($function =~ /malloc\((\d*)\) = 0x([0-9a-f]*)/) {
145
+ $size = $1;
146
+ $addr = $2;
147
+
148
+ if($sizeataddr{$addr}>0) {
149
+ # this means weeeeeirdo
150
+ print "Mixed debug compile ($source:$linenum at line $lnum), rebuild curl now\n";
151
+ print "We think $sizeataddr{$addr} bytes are already allocated at that memory address: $addr!\n";
152
+ }
153
+
154
+ $sizeataddr{$addr}=$size;
155
+ $totalmem += $size;
156
+ $memsum += $size;
157
+
158
+ if($trace) {
159
+ print "MALLOC: malloc($size) at $source:$linenum",
160
+ " makes totally $totalmem bytes\n";
161
+ }
162
+
163
+ newtotal($totalmem);
164
+ $mallocs++;
165
+
166
+ $getmem{$addr}="$source:$linenum";
167
+ }
168
+ elsif($function =~ /calloc\((\d*),(\d*)\) = 0x([0-9a-f]*)/) {
169
+ $size = $1*$2;
170
+ $addr = $3;
171
+
172
+ $arg1 = $1;
173
+ $arg2 = $2;
174
+
175
+ if($sizeataddr{$addr}>0) {
176
+ # this means weeeeeirdo
177
+ print "Mixed debug compile, rebuild curl now\n";
178
+ }
179
+
180
+ $sizeataddr{$addr}=$size;
181
+ $totalmem += $size;
182
+ $memsum += $size;
183
+
184
+ if($trace) {
185
+ print "CALLOC: calloc($arg1,$arg2) at $source:$linenum",
186
+ " makes totally $totalmem bytes\n";
187
+ }
188
+
189
+ newtotal($totalmem);
190
+ $callocs++;
191
+
192
+ $getmem{$addr}="$source:$linenum";
193
+ }
194
+ elsif($function =~ /realloc\((\(nil\)|0x([0-9a-f]*)), (\d*)\) = 0x([0-9a-f]*)/) {
195
+ my ($oldaddr, $newsize, $newaddr) = ($2, $3, $4);
196
+
197
+ $totalmem -= $sizeataddr{$oldaddr};
198
+ if($trace) {
199
+ printf("REALLOC: %d less bytes and ", $sizeataddr{$oldaddr});
200
+ }
201
+ $sizeataddr{$oldaddr}=0;
202
+
203
+ $totalmem += $newsize;
204
+ $memsum += $size;
205
+ $sizeataddr{$newaddr}=$newsize;
206
+
207
+ if($trace) {
208
+ printf("%d more bytes ($source:$linenum)\n", $newsize);
209
+ }
210
+
211
+ newtotal($totalmem);
212
+ $reallocs++;
213
+
214
+ $getmem{$oldaddr}="";
215
+ $getmem{$newaddr}="$source:$linenum";
216
+ }
217
+ elsif($function =~ /strdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {
218
+ # strdup(a5b50) (8) = df7c0
219
+
220
+ $dup = $1;
221
+ $size = $2;
222
+ $addr = $3;
223
+ $getmem{$addr}="$source:$linenum";
224
+ $sizeataddr{$addr}=$size;
225
+
226
+ $totalmem += $size;
227
+ $memsum += $size;
228
+
229
+ if($trace) {
230
+ printf("STRDUP: $size bytes at %s, makes totally: %d bytes\n",
231
+ $getmem{$addr}, $totalmem);
232
+ }
233
+
234
+ newtotal($totalmem);
235
+ $strdups++;
236
+ }
237
+ elsif($function =~ /wcsdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {
238
+ # wcsdup(a5b50) (8) = df7c0
239
+
240
+ $dup = $1;
241
+ $size = $2;
242
+ $addr = $3;
243
+ $getmem{$addr}="$source:$linenum";
244
+ $sizeataddr{$addr}=$size;
245
+
246
+ $totalmem += $size;
247
+ $memsum += $size;
248
+
249
+ if($trace) {
250
+ printf("WCSDUP: $size bytes at %s, makes totally: %d bytes\n",
251
+ $getmem{$addr}, $totalmem);
252
+ }
253
+
254
+ newtotal($totalmem);
255
+ $wcsdups++;
256
+ }
257
+ else {
258
+ print "Not recognized input line: $function\n";
259
+ }
260
+ }
261
+ # FD url.c:1282 socket() = 5
262
+ elsif($_ =~ /^FD ([^ ]*):(\d*) (.*)/) {
263
+ # generic match for the filename+linenumber
264
+ $source = $1;
265
+ $linenum = $2;
266
+ $function = $3;
267
+
268
+ if($function =~ /socket\(\) = (\d*)/) {
269
+ $filedes{$1}=1;
270
+ $getfile{$1}="$source:$linenum";
271
+ $openfile++;
272
+ $sockets++; # number of socket() calls
273
+ }
274
+ elsif($function =~ /socketpair\(\) = (\d*) (\d*)/) {
275
+ $filedes{$1}=1;
276
+ $getfile{$1}="$source:$linenum";
277
+ $openfile++;
278
+ $filedes{$2}=1;
279
+ $getfile{$2}="$source:$linenum";
280
+ $openfile++;
281
+ }
282
+ elsif($function =~ /accept\(\) = (\d*)/) {
283
+ $filedes{$1}=1;
284
+ $getfile{$1}="$source:$linenum";
285
+ $openfile++;
286
+ }
287
+ elsif($function =~ /sclose\((\d*)\)/) {
288
+ if($filedes{$1} != 1) {
289
+ print "Close without open: $line\n";
290
+ }
291
+ else {
292
+ $filedes{$1}=0; # closed now
293
+ $openfile--;
294
+ }
295
+ }
296
+ }
297
+ # FILE url.c:1282 fopen("blabla") = 0x5ddd
298
+ elsif($_ =~ /^FILE ([^ ]*):(\d*) (.*)/) {
299
+ # generic match for the filename+linenumber
300
+ $source = $1;
301
+ $linenum = $2;
302
+ $function = $3;
303
+
304
+ if($function =~ /f[d]*open\(\"(.*)\",\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
305
+ if($3 eq "(nil)") {
306
+ ;
307
+ }
308
+ else {
309
+ $fopen{$4}=1;
310
+ $fopenfile{$4}="$source:$linenum";
311
+ $fopens++;
312
+ }
313
+ }
314
+ # fclose(0x1026c8)
315
+ elsif($function =~ /fclose\(0x([0-9a-f]*)\)/) {
316
+ if(!$fopen{$1}) {
317
+ print "fclose() without fopen(): $line\n";
318
+ }
319
+ else {
320
+ $fopen{$1}=0;
321
+ $fopens--;
322
+ }
323
+ }
324
+ }
325
+ # GETNAME url.c:1901 getnameinfo()
326
+ elsif($_ =~ /^GETNAME ([^ ]*):(\d*) (.*)/) {
327
+ # not much to do
328
+ }
329
+ # SEND url.c:1901 send(83) = 83
330
+ elsif($_ =~ /^SEND ([^ ]*):(\d*) (.*)/) {
331
+ $sends++;
332
+ }
333
+ # RECV url.c:1901 recv(102400) = 256
334
+ elsif($_ =~ /^RECV ([^ ]*):(\d*) (.*)/) {
335
+ $recvs++;
336
+ }
337
+
338
+ # ADDR url.c:1282 getaddrinfo() = 0x5ddd
339
+ elsif($_ =~ /^ADDR ([^ ]*):(\d*) (.*)/) {
340
+ # generic match for the filename+linenumber
341
+ $source = $1;
342
+ $linenum = $2;
343
+ $function = $3;
344
+
345
+ if($function =~ /getaddrinfo\(\) = (\(nil\)|0x([0-9a-f]*))/) {
346
+ my $add = $2;
347
+ if($add eq "(nil)") {
348
+ ;
349
+ }
350
+ else {
351
+ $addrinfo{$add}=1;
352
+ $addrinfofile{$add}="$source:$linenum";
353
+ $addrinfos++;
354
+ }
355
+ if($trace) {
356
+ printf("GETADDRINFO ($source:$linenum)\n");
357
+ }
358
+ }
359
+ # fclose(0x1026c8)
360
+ elsif($function =~ /freeaddrinfo\(0x([0-9a-f]*)\)/) {
361
+ if(!$addrinfo{$1}) {
362
+ print "freeaddrinfo() without getaddrinfo(): $line\n";
363
+ }
364
+ else {
365
+ $addrinfo{$1}=0;
366
+ $addrinfos--;
367
+ }
368
+ if($trace) {
369
+ printf("FREEADDRINFO ($source:$linenum)\n");
370
+ }
371
+ }
372
+
373
+ }
374
+ else {
375
+ print "Not recognized prefix line: $line\n";
376
+ }
377
+ }
378
+ close($fileh);
379
+
380
+ if($totalmem) {
381
+ print "Leak detected: memory still allocated: $totalmem bytes\n";
382
+
383
+ for(keys %sizeataddr) {
384
+ $addr = $_;
385
+ $size = $sizeataddr{$addr};
386
+ if($size > 0) {
387
+ print "At $addr, there's $size bytes.\n";
388
+ print " allocated by ".$getmem{$addr}."\n";
389
+ }
390
+ }
391
+ }
392
+
393
+ if($openfile) {
394
+ for(keys %filedes) {
395
+ if($filedes{$_} == 1) {
396
+ print "Open file descriptor created at ".$getfile{$_}."\n";
397
+ }
398
+ }
399
+ }
400
+
401
+ if($fopens) {
402
+ print "Open FILE handles left at:\n";
403
+ for(keys %fopen) {
404
+ if($fopen{$_} == 1) {
405
+ print "fopen() called at ".$fopenfile{$_}."\n";
406
+ }
407
+ }
408
+ }
409
+
410
+ if($addrinfos) {
411
+ print "IPv6-style name resolve data left at:\n";
412
+ for(keys %addrinfofile) {
413
+ if($addrinfo{$_} == 1) {
414
+ print "getaddrinfo() called at ".$addrinfofile{$_}."\n";
415
+ }
416
+ }
417
+ }
418
+
419
+ if($verbose) {
420
+ print "Mallocs: $mallocs\n",
421
+ "Reallocs: $reallocs\n",
422
+ "Callocs: $callocs\n",
423
+ "Strdups: $strdups\n",
424
+ "Wcsdups: $wcsdups\n",
425
+ "Frees: $frees\n",
426
+ "Sends: $sends\n",
427
+ "Recvs: $recvs\n",
428
+ "Sockets: $sockets\n",
429
+ "Allocations: ".($mallocs + $callocs + $reallocs + $strdups + $wcsdups)."\n",
430
+ "Operations: ".($mallocs + $callocs + $reallocs + $strdups + $wcsdups + $sends + $recvs + $sockets)."\n";
431
+
432
+ print "Maximum allocated: $maxmem\n";
433
+ print "Total allocated: $memsum\n";
434
+ }
local-test-curl-delta-01/afc-curl/tests/mk-bundle.pl ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Viktor Szakats
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+
26
+ # Bundle up individual tests into a single binary. The resulting binary can run
27
+ # individual tests by passing their name (without '.c') as the first argument.
28
+ #
29
+ # Usage: mk-bundle.pl [<directory>]
30
+
31
+ use strict;
32
+ use warnings;
33
+
34
+ my $src_dir = @ARGV ? $ARGV[0] : ".";
35
+
36
+ # Read list of tests
37
+ open my $fh, "<", "$src_dir/Makefile.inc" or die "Cannot open '$src_dir/Makefile.inc': $!";
38
+
39
+ print <<HEADER
40
+ /* !checksrc! disable COPYRIGHT all */
41
+ /* !checksrc! disable INCLUDEDUP all */
42
+
43
+ #define CURLTESTS_BUNDLED
44
+ #define CURLTESTS_BUNDLED_TEST_H
45
+ #include "first.h"
46
+ HEADER
47
+ ;
48
+
49
+ # TODO: Some of these might be subject for de-duplication or sync.
50
+ my @reused_symbols = (
51
+ "ReadThis",
52
+ "ReadWriteSockets",
53
+ "Sockets",
54
+ "Tdata",
55
+ "WriteThis",
56
+ "addFd",
57
+ "checkFdSet",
58
+ "checkForCompletion",
59
+ "close_file_descriptors",
60
+ "curl", # shadow
61
+ "curlSocketCallback",
62
+ "curlTimerCallback",
63
+ "cyclic_add",
64
+ "easy", # unit
65
+ "fopen_works",
66
+ "getMicroSecondTimeout",
67
+ "geterr",
68
+ "hash_static", # unit
69
+ "header_callback",
70
+ "ioctlcallback",
71
+ "msgbuff",
72
+ "mydtor", # unit
73
+ "num_open",
74
+ "progress_callback",
75
+ "read_callback",
76
+ "readcallback",
77
+ "recv_pong",
78
+ "removeFd",
79
+ "rlim2str",
80
+ "run_thread",
81
+ "send_ping",
82
+ "showem",
83
+ "store_errmsg",
84
+ "suburl",
85
+ "test_failure", # shadow
86
+ "test_fire",
87
+ "test_lock",
88
+ "test_once",
89
+ "test_parse", # unit
90
+ "test_rlimit",
91
+ "test_unlock",
92
+ "testbuf",
93
+ "testcase", # unit
94
+ "testdata",
95
+ "testfd",
96
+ "testname",
97
+ "testpost",
98
+ "tests", # unit
99
+ "teststring",
100
+ "trailers_callback",
101
+ "transfer_status",
102
+ "unit_setup", # unit
103
+ "unit_stop", # unit
104
+ "updateFdSet",
105
+ "userdata",
106
+ "websocket",
107
+ "websocket_close",
108
+ "write_callback",
109
+ "write_cb",
110
+ "writecb",
111
+ "xferinfo",
112
+ );
113
+
114
+ # TODO: Some of these may be #undef-ed manually at the end of each source
115
+ my @reused_macros = (
116
+ "HEADER_REQUEST",
117
+ "NUM_HANDLES",
118
+ "SAFETY_MARGIN",
119
+ "TEST_HANG_TIMEOUT",
120
+ );
121
+
122
+ my $tlist = "";
123
+
124
+ while(my $line = <$fh>) {
125
+ chomp $line;
126
+ if($line =~ /([a-z0-9]+)_SOURCES\ =\ ([a-z0-9]+)\.c/) {
127
+ my $name = $1;
128
+ my $namu = uc($name);
129
+ my $src = "$2.c";
130
+
131
+ # Make common symbols unique across test sources
132
+ foreach my $symb ("test", @reused_symbols) {
133
+ print "#undef $symb\n";
134
+ print "#define $symb ${symb}_$name\n";
135
+ }
136
+
137
+ print "#define $namu\n";
138
+ print "#include \"$src\"\n";
139
+ print "#undef $namu\n";
140
+
141
+ # Reset macros re-used by multiple tests
142
+ foreach my $undef ("test", @reused_macros) {
143
+ print "#undef $undef\n";
144
+ }
145
+
146
+ print "\n";
147
+
148
+ $tlist .= " {\"$name\", test_$name},\n";
149
+ }
150
+ }
151
+
152
+ close $fh;
153
+
154
+ print <<FOOTER
155
+ static const struct onetest s_tests[] = {
156
+ $tlist};
157
+
158
+ #undef CURLTESTS_BUNDLED_TEST_H
159
+
160
+ #include "first.c"
161
+ FOOTER
162
+ ;
local-test-curl-delta-01/afc-curl/tests/pathhelp.pm ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###########################################################################
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Evgeny Grin (Karlson2k), <k2k@narod.ru>.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+
25
+ # This Perl package helps with path transforming when running curl tests on
26
+ # native Windows and MSYS/Cygwin.
27
+ # Following input formats are supported (via built-in Perl functions):
28
+ # (1) /some/path - absolute path in POSIX-style
29
+ # (2) D:/some/path - absolute path in Windows-style
30
+ # (3) some/path - relative path
31
+ # (4) D:some/path - path relative to current directory on Windows drive
32
+ # (paths like 'D:' are treated as 'D:./') (*)
33
+ # (5) \some/path - path from root directory on current Windows drive (*)
34
+ # All forward '/' and back '\' slashes are treated identically except leading
35
+ # slash in forms (1) and (5).
36
+ # Forward slashes are simpler processed in Perl, do not require extra escaping
37
+ # for shell (unlike back slashes) and accepted by Windows native programs, so
38
+ # all functions return paths with only forward slashes.
39
+ # All returned paths don't contain any duplicated slashes, only single slashes
40
+ # are used as directory separators on output.
41
+ # On non-Windows platforms functions acts as transparent wrappers for similar
42
+ # Perl's functions or return unmodified string (depending on functionality),
43
+ # so all functions can be unconditionally used on all platforms.
44
+ #
45
+ # (*) CAUTION! Forms (4) and (5) are not recommended to use as they can be
46
+ # interpreted incorrectly in Perl and MSYS/Cygwin environment have low
47
+ # control on Windows current drive and Windows current path on specific
48
+ # drive.
49
+
50
+ package pathhelp;
51
+
52
+ use strict;
53
+ use warnings;
54
+ use Cwd 'abs_path';
55
+
56
+ BEGIN {
57
+ use base qw(Exporter);
58
+
59
+ our @EXPORT_OK = qw(
60
+ os_is_win
61
+ exe_ext
62
+ sys_native_abs_path
63
+ sys_native_current_path
64
+ build_sys_abs_path
65
+ );
66
+ }
67
+
68
+
69
+ #######################################################################
70
+ # Block for cached static variables
71
+ #
72
+ {
73
+ # Cached static variable, Perl 5.0-compatible.
74
+ my $is_win = $^O eq 'MSWin32'
75
+ || $^O eq 'cygwin'
76
+ || $^O eq 'msys';
77
+
78
+ # Returns boolean true if OS is any form of Windows.
79
+ sub os_is_win {
80
+ return $is_win;
81
+ }
82
+
83
+ # Cached static variable, Perl 5.0-compatible.
84
+ my $cygdrive_present;
85
+
86
+ # Returns boolean true if Windows drives mounted with '/cygdrive/' prefix.
87
+ sub drives_mounted_on_cygdrive {
88
+ return $cygdrive_present if defined $cygdrive_present;
89
+ $cygdrive_present = ((-e '/cygdrive/') && (-d '/cygdrive/')) ? 1 : 0;
90
+ return $cygdrive_present;
91
+ }
92
+ }
93
+
94
+ #######################################################################
95
+ # Returns current working directory in Windows format on Windows.
96
+ #
97
+ sub sys_native_current_path {
98
+ return Cwd::getcwd() if !os_is_win();
99
+
100
+ my $cur_dir;
101
+ if($^O eq 'MSWin32') {
102
+ $cur_dir = Cwd::getcwd();
103
+ }
104
+ else {
105
+ $cur_dir = Cygwin::posix_to_win_path(Cwd::getcwd());
106
+ }
107
+ $cur_dir =~ s{[/\\]+}{/}g;
108
+ return $cur_dir;
109
+ }
110
+
111
+ #######################################################################
112
+ # Converts given path to system native absolute path, i.e. to Windows
113
+ # absolute format on Windows platform. Both relative and absolute
114
+ # formats are supported for input.
115
+ #
116
+ sub sys_native_abs_path {
117
+ my ($path) = @_;
118
+
119
+ # Return untouched on non-Windows platforms.
120
+ return Cwd::abs_path($path) if !os_is_win();
121
+
122
+ # Do not process empty path.
123
+ return $path if ($path eq '');
124
+
125
+ my $res;
126
+ if($^O eq 'msys' || $^O eq 'cygwin') {
127
+ $res = Cygwin::posix_to_win_path(Cwd::abs_path($path));
128
+ }
129
+ elsif($path =~ m{^/(cygdrive/)?([a-z])/(.*)}) {
130
+ $res = uc($2) . ":/" . $3;
131
+ }
132
+ else {
133
+ $res = Cwd::abs_path($path);
134
+ }
135
+
136
+ $res =~ s{[/\\]+}{/}g;
137
+ return $res;
138
+ }
139
+
140
+ #######################################################################
141
+ # Converts given path to build system format absolute path, i.e. to
142
+ # MSYS/Cygwin POSIX-style absolute format on Windows platform. Both
143
+ # relative and absolute formats are supported for input.
144
+ #
145
+ sub build_sys_abs_path {
146
+ my ($path) = @_;
147
+
148
+ # Return untouched on non-Windows platforms.
149
+ return Cwd::abs_path($path) if !os_is_win();
150
+
151
+ my $res;
152
+ if($^O eq 'msys' || $^O eq 'cygwin') {
153
+ $res = Cygwin::win_to_posix_path($path, 1);
154
+ }
155
+ else {
156
+ $res = Cwd::abs_path($path);
157
+
158
+ if($res =~ m{^([A-Za-z]):(.*)}) {
159
+ $res = "/" . lc($1) . $2;
160
+ $res = '/cygdrive' . $res if(drives_mounted_on_cygdrive());
161
+ }
162
+ }
163
+
164
+ return $res;
165
+ }
166
+
167
+ #***************************************************************************
168
+ # Return file extension for executable files on this operating system
169
+ #
170
+ sub exe_ext {
171
+ my ($component, @arr) = @_;
172
+ if ($ENV{'CURL_TEST_EXE_EXT'}) {
173
+ return $ENV{'CURL_TEST_EXE_EXT'};
174
+ }
175
+ if ($ENV{'CURL_TEST_EXE_EXT_'.$component}) {
176
+ return $ENV{'CURL_TEST_EXE_EXT_'.$component};
177
+ }
178
+ if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys' ||
179
+ $^O eq 'dos' || $^O eq 'os2') {
180
+ return '.exe';
181
+ }
182
+ return '';
183
+ }
184
+
185
+ 1; # End of module
local-test-curl-delta-01/afc-curl/tests/requirements.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+ #
26
+ impacket
local-test-curl-delta-01/afc-curl/tests/rtspserver.pl ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ #***************************************************************************
25
+
26
+ use strict;
27
+ use warnings;
28
+
29
+ BEGIN {
30
+ push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
31
+ push(@INC, ".");
32
+ }
33
+
34
+ use serverhelp qw(
35
+ server_pidfilename
36
+ server_logfilename
37
+ );
38
+
39
+ use pathhelp qw(
40
+ exe_ext
41
+ );
42
+
43
+ my $verbose = 0; # set to 1 for debugging
44
+ my $port = 8990; # just a default
45
+ my $ipvnum = 4; # default IP version of rtsp server
46
+ my $idnum = 1; # default rtsp server instance number
47
+ my $proto = 'rtsp'; # protocol the rtsp server speaks
48
+ my $pidfile; # rtsp server pid file
49
+ my $portfile;
50
+ my $logfile; # rtsp server log file
51
+ my $srcdir;
52
+
53
+ my $flags = "";
54
+ my $path = '.';
55
+ my $logdir = $path .'/log';
56
+
57
+ while(@ARGV) {
58
+ if($ARGV[0] eq '--pidfile') {
59
+ if($ARGV[1]) {
60
+ $pidfile = $ARGV[1];
61
+ shift @ARGV;
62
+ }
63
+ }
64
+ elsif($ARGV[0] eq '--portfile') {
65
+ if($ARGV[1]) {
66
+ $portfile = $ARGV[1];
67
+ shift @ARGV;
68
+ }
69
+ }
70
+ elsif($ARGV[0] eq '--logfile') {
71
+ if($ARGV[1]) {
72
+ $logfile = $ARGV[1];
73
+ shift @ARGV;
74
+ }
75
+ }
76
+ elsif($ARGV[0] eq '--logdir') {
77
+ if($ARGV[1]) {
78
+ $logdir = $ARGV[1];
79
+ shift @ARGV;
80
+ }
81
+ }
82
+ elsif($ARGV[0] eq '--srcdir') {
83
+ if($ARGV[1]) {
84
+ $srcdir = $ARGV[1];
85
+ shift @ARGV;
86
+ }
87
+ }
88
+ elsif($ARGV[0] eq '--ipv4') {
89
+ $ipvnum = 4;
90
+ }
91
+ elsif($ARGV[0] eq '--ipv6') {
92
+ $ipvnum = 6;
93
+ }
94
+ elsif($ARGV[0] eq '--port') {
95
+ if($ARGV[1] =~ /^(\d+)$/) {
96
+ $port = $1;
97
+ shift @ARGV;
98
+ }
99
+ }
100
+ elsif($ARGV[0] eq '--id') {
101
+ if($ARGV[1] =~ /^(\d+)$/) {
102
+ $idnum = $1 if($1 > 0);
103
+ shift @ARGV;
104
+ }
105
+ }
106
+ elsif($ARGV[0] eq '--verbose') {
107
+ $verbose = 1;
108
+ }
109
+ else {
110
+ print STDERR "\nWarning: rtspserver.pl unknown parameter: $ARGV[0]\n";
111
+ }
112
+ shift @ARGV;
113
+ }
114
+
115
+ #***************************************************************************
116
+ # Initialize command line option dependent variables
117
+ #
118
+
119
+ if(!$pidfile) {
120
+ $pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
121
+ }
122
+ if(!$srcdir) {
123
+ $srcdir = $ENV{'srcdir'} || '.';
124
+ }
125
+ if(!$logfile) {
126
+ $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
127
+ }
128
+
129
+ $flags .= "--pidfile \"$pidfile\" ".
130
+ "--portfile \"$portfile\" ".
131
+ "--logfile \"$logfile\" ".
132
+ "--logdir \"$logdir\" ";
133
+ $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
134
+
135
+ $| = 1;
136
+ exec("exec server/rtspd".exe_ext('SRV')." $flags");
local-test-curl-delta-01/afc-curl/tests/secureserver.pl ADDED
@@ -0,0 +1,383 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ #***************************************************************************
25
+
26
+ # This is the HTTPS, FTPS, POP3S, IMAPS, SMTPS, server used for curl test
27
+ # harness. Actually just a layer that runs stunnel properly using the
28
+ # non-secure test harness servers.
29
+
30
+ use strict;
31
+ use warnings;
32
+
33
+ BEGIN {
34
+ push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
35
+ push(@INC, ".");
36
+ }
37
+
38
+ use Cwd;
39
+ use Cwd 'abs_path';
40
+ use File::Basename;
41
+
42
+ use serverhelp qw(
43
+ server_pidfilename
44
+ server_logfilename
45
+ );
46
+
47
+ use pathhelp;
48
+
49
+ my $stunnel = "stunnel";
50
+
51
+ my $verbose=0; # set to 1 for debugging
52
+
53
+ my $accept_port = 8991; # just our default, weird enough
54
+ my $target_port = 8999; # default test http-server port
55
+
56
+ my $stuncert;
57
+
58
+ my $ver_major;
59
+ my $ver_minor;
60
+ my $fips_support;
61
+ my $stunnel_version;
62
+ my $tstunnel_windows;
63
+ my $socketopt;
64
+ my $cmd;
65
+
66
+ my $pidfile; # stunnel pid file
67
+ my $logfile; # stunnel log file
68
+ my $loglevel = 5; # stunnel log level
69
+ my $ipvnum = 4; # default IP version of stunneled server
70
+ my $idnum = 1; # default stunneled server instance number
71
+ my $proto = 'https'; # default secure server protocol
72
+ my $conffile; # stunnel configuration file
73
+ my $capath; # certificate chain PEM folder
74
+ my $certfile; # certificate chain PEM file
75
+
76
+ #***************************************************************************
77
+ # stunnel requires full path specification for several files.
78
+ #
79
+ my $path = getcwd();
80
+ my $srcdir = $path;
81
+ my $logdir = $path .'/log';
82
+ my $piddir;
83
+
84
+ #***************************************************************************
85
+ # Signal handler to remove our stunnel 4.00 and newer configuration file.
86
+ #
87
+ sub exit_signal_handler {
88
+ my $signame = shift;
89
+ local $!; # preserve errno
90
+ local $?; # preserve exit status
91
+ unlink($conffile) if($conffile && (-f $conffile));
92
+ exit;
93
+ }
94
+
95
+ #***************************************************************************
96
+ # Process command line options
97
+ #
98
+ while(@ARGV) {
99
+ if($ARGV[0] eq '--verbose') {
100
+ $verbose = 1;
101
+ }
102
+ elsif($ARGV[0] eq '--proto') {
103
+ if($ARGV[1]) {
104
+ $proto = $ARGV[1];
105
+ shift @ARGV;
106
+ }
107
+ }
108
+ elsif($ARGV[0] eq '--accept') {
109
+ if($ARGV[1]) {
110
+ if($ARGV[1] =~ /^(\d+)$/) {
111
+ $accept_port = $1;
112
+ shift @ARGV;
113
+ }
114
+ }
115
+ }
116
+ elsif($ARGV[0] eq '--connect') {
117
+ if($ARGV[1]) {
118
+ if($ARGV[1] =~ /^(\d+)$/) {
119
+ $target_port = $1;
120
+ shift @ARGV;
121
+ }
122
+ }
123
+ }
124
+ elsif($ARGV[0] eq '--stunnel') {
125
+ if($ARGV[1]) {
126
+ $stunnel = $ARGV[1];
127
+ shift @ARGV;
128
+ }
129
+ }
130
+ elsif($ARGV[0] eq '--srcdir') {
131
+ if($ARGV[1]) {
132
+ $srcdir = $ARGV[1];
133
+ shift @ARGV;
134
+ }
135
+ }
136
+ elsif($ARGV[0] eq '--certfile') {
137
+ if($ARGV[1]) {
138
+ $stuncert = $ARGV[1];
139
+ shift @ARGV;
140
+ }
141
+ }
142
+ elsif($ARGV[0] eq '--id') {
143
+ if($ARGV[1]) {
144
+ if($ARGV[1] =~ /^(\d+)$/) {
145
+ $idnum = $1 if($1 > 0);
146
+ shift @ARGV;
147
+ }
148
+ }
149
+ }
150
+ elsif($ARGV[0] eq '--ipv4') {
151
+ $ipvnum = 4;
152
+ }
153
+ elsif($ARGV[0] eq '--ipv6') {
154
+ $ipvnum = 6;
155
+ }
156
+ elsif($ARGV[0] eq '--pidfile') {
157
+ if($ARGV[1]) {
158
+ $pidfile = "$path/". $ARGV[1];
159
+ shift @ARGV;
160
+ }
161
+ }
162
+ elsif($ARGV[0] eq '--logfile') {
163
+ if($ARGV[1]) {
164
+ $logfile = "$path/". $ARGV[1];
165
+ shift @ARGV;
166
+ }
167
+ }
168
+ elsif($ARGV[0] eq '--logdir') {
169
+ if($ARGV[1]) {
170
+ $logdir = "$path/". $ARGV[1];
171
+ shift @ARGV;
172
+ }
173
+ }
174
+ else {
175
+ print STDERR "\nWarning: secureserver.pl unknown parameter: $ARGV[0]\n";
176
+ }
177
+ shift @ARGV;
178
+ }
179
+
180
+ #***************************************************************************
181
+ # Initialize command line option dependent variables
182
+ #
183
+ if($pidfile) {
184
+ # Use our pidfile directory to store the conf files
185
+ $piddir = dirname($pidfile);
186
+ }
187
+ else {
188
+ # Use the current directory to store the conf files
189
+ $piddir = $path;
190
+ $pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
191
+ }
192
+ if(!$logfile) {
193
+ $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
194
+ }
195
+
196
+ $conffile = "$piddir/${proto}_stunnel.conf";
197
+
198
+ $capath = abs_path($path);
199
+ $certfile = "$srcdir/". ($stuncert?"certs/$stuncert":"stunnel.pem");
200
+ $certfile = abs_path($certfile);
201
+
202
+ my $ssltext = uc($proto) ." SSL/TLS:";
203
+
204
+ my $host_ip = ($ipvnum == 6)? '::1' : '127.0.0.1';
205
+
206
+ #***************************************************************************
207
+ # Find out version info for the given stunnel binary
208
+ #
209
+ foreach my $veropt (('-version', '-V')) {
210
+ foreach my $verstr (qx("$stunnel" $veropt 2>&1)) {
211
+ if($verstr =~ /^stunnel (\d+)\.(\d+) on /) {
212
+ $ver_major = $1;
213
+ $ver_minor = $2;
214
+ }
215
+ elsif($verstr =~ /^sslVersion.*fips *= *yes/) {
216
+ # the fips option causes an error if stunnel doesn't support it
217
+ $fips_support = 1;
218
+ last
219
+ }
220
+ }
221
+ last if($ver_major);
222
+ }
223
+ if((!$ver_major) || !defined($ver_minor)) {
224
+ if(-x "$stunnel" && ! -d "$stunnel") {
225
+ print "$ssltext Unknown stunnel version\n";
226
+ }
227
+ else {
228
+ print "$ssltext No stunnel\n";
229
+ }
230
+ exit 1;
231
+ }
232
+ $stunnel_version = (100*$ver_major) + $ver_minor;
233
+
234
+ #***************************************************************************
235
+ # Verify minimum stunnel required version
236
+ #
237
+ if($stunnel_version < 310) {
238
+ print "$ssltext Unsupported stunnel version $ver_major.$ver_minor\n";
239
+ exit 1;
240
+ }
241
+
242
+ #***************************************************************************
243
+ # Find out if we are running on Windows using the tstunnel binary
244
+ #
245
+ if($stunnel =~ /tstunnel(\.exe)?$/) {
246
+ $tstunnel_windows = 1;
247
+
248
+ # convert Cygwin/MinGW paths to Windows format
249
+ $capath = pathhelp::sys_native_abs_path($capath);
250
+ $certfile = pathhelp::sys_native_abs_path($certfile);
251
+ }
252
+
253
+ #***************************************************************************
254
+ # Build command to execute for stunnel 3.X versions
255
+ #
256
+ if($stunnel_version < 400) {
257
+ if($stunnel_version >= 319) {
258
+ $socketopt = "-O a:SO_REUSEADDR=1";
259
+ }
260
+ # TODO: we do not use $host_ip in this old version. I simply find
261
+ # no documentation how to. But maybe ipv6 is not available anyway?
262
+ $cmd = "\"$stunnel\" -p $certfile -P $pidfile ";
263
+ $cmd .= "-d $accept_port -r $target_port -f -D $loglevel ";
264
+ $cmd .= ($socketopt) ? "$socketopt " : "";
265
+ $cmd .= ">$logfile 2>&1";
266
+ if($verbose) {
267
+ print uc($proto) ." server (stunnel $ver_major.$ver_minor)\n";
268
+ print "cmd: $cmd\n";
269
+ print "pem cert file: $certfile\n";
270
+ print "pid file: $pidfile\n";
271
+ print "log file: $logfile\n";
272
+ print "log level: $loglevel\n";
273
+ print "listen on port: $accept_port\n";
274
+ print "connect to port: $target_port\n";
275
+ }
276
+ }
277
+
278
+ #***************************************************************************
279
+ # Build command to execute for stunnel 4.00 and newer
280
+ #
281
+ if($stunnel_version >= 400) {
282
+ $socketopt = "a:SO_REUSEADDR=1";
283
+ if(($stunnel_version >= 534) && $tstunnel_windows) {
284
+ # SO_EXCLUSIVEADDRUSE is on by default on Vista or newer,
285
+ # but does not work together with SO_REUSEADDR being on.
286
+ $socketopt .= "\nsocket = a:SO_EXCLUSIVEADDRUSE=0";
287
+ }
288
+ $cmd = "\"$stunnel\" $conffile ";
289
+ $cmd .= ">$logfile 2>&1";
290
+ # setup signal handler
291
+ $SIG{INT} = \&exit_signal_handler;
292
+ $SIG{TERM} = \&exit_signal_handler;
293
+ # stunnel configuration file
294
+ if(open(my $stunconf, ">", "$conffile")) {
295
+ print $stunconf "CApath = $capath\n";
296
+ print $stunconf "cert = $certfile\n";
297
+ print $stunconf "debug = $loglevel\n";
298
+ print $stunconf "socket = $socketopt\n";
299
+ if($fips_support) {
300
+ # disable fips in case OpenSSL doesn't support it
301
+ print $stunconf "fips = no\n";
302
+ }
303
+ if(!$tstunnel_windows) {
304
+ # do not use Linux-specific options on Windows
305
+ print $stunconf "output = $logfile\n";
306
+ print $stunconf "pid = $pidfile\n";
307
+ print $stunconf "foreground = yes\n";
308
+ }
309
+ print $stunconf "\n";
310
+ print $stunconf "[curltest]\n";
311
+ print $stunconf "accept = $host_ip:$accept_port\n";
312
+ print $stunconf "connect = $host_ip:$target_port\n";
313
+ if(!close($stunconf)) {
314
+ print "$ssltext Error closing file $conffile\n";
315
+ exit 1;
316
+ }
317
+ }
318
+ else {
319
+ print "$ssltext Error writing file $conffile\n";
320
+ exit 1;
321
+ }
322
+ if($verbose) {
323
+ print uc($proto) ." server (stunnel $ver_major.$ver_minor)\n";
324
+ print "cmd: $cmd\n";
325
+ print "CApath = $capath\n";
326
+ print "cert = $certfile\n";
327
+ print "debug = $loglevel\n";
328
+ print "socket = $socketopt\n";
329
+ if($fips_support) {
330
+ print "fips = no\n";
331
+ }
332
+ if(!$tstunnel_windows) {
333
+ print "pid = $pidfile\n";
334
+ print "output = $logfile\n";
335
+ print "foreground = yes\n";
336
+ }
337
+ print "\n";
338
+ print "[curltest]\n";
339
+ print "accept = $host_ip:$accept_port\n";
340
+ print "connect = $host_ip:$target_port\n";
341
+ }
342
+ }
343
+
344
+ #***************************************************************************
345
+ # Set file permissions on certificate pem file.
346
+ #
347
+ chmod(0600, $certfile) if(-f $certfile);
348
+ print STDERR "RUN: $cmd\n" if($verbose);
349
+
350
+ #***************************************************************************
351
+ # Run tstunnel on Windows.
352
+ #
353
+ if($tstunnel_windows) {
354
+ # Fake pidfile for tstunnel on Windows.
355
+ if(open(my $out, ">", "$pidfile")) {
356
+ print $out $$ . "\n";
357
+ close($out);
358
+ }
359
+
360
+ # Flush output.
361
+ $| = 1;
362
+
363
+ # Put an "exec" in front of the command so that the child process
364
+ # keeps this child's process ID by being tied to the spawned shell.
365
+ exec("exec $cmd") || die "Can't exec() $cmd: $!";
366
+ # exec() will create a new process, but ties the existence of the
367
+ # new process to the parent waiting perl.exe and sh.exe processes.
368
+
369
+ # exec() should never return back here to this process. We protect
370
+ # ourselves by calling die() just in case something goes really bad.
371
+ die "error: exec() has returned";
372
+ }
373
+
374
+ #***************************************************************************
375
+ # Run stunnel.
376
+ #
377
+ my $rc = system($cmd);
378
+
379
+ $rc >>= 8;
380
+
381
+ unlink($conffile) if($conffile && -f $conffile);
382
+
383
+ exit $rc;
local-test-curl-delta-01/afc-curl/tests/serverhelp.pm ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ #***************************************************************************
24
+
25
+ # This perl module contains functions useful in writing test servers.
26
+
27
+ package serverhelp;
28
+
29
+ use strict;
30
+ use warnings;
31
+
32
+ BEGIN {
33
+ use base qw(Exporter);
34
+
35
+ our @EXPORT_OK = qw(
36
+ logmsg
37
+ $logfile
38
+ serverfactors
39
+ servername_id
40
+ servername_str
41
+ servername_canon
42
+ server_pidfilename
43
+ server_portfilename
44
+ server_logfilename
45
+ server_cmdfilename
46
+ server_inputfilename
47
+ server_outputfilename
48
+ mainsockf_pidfilename
49
+ mainsockf_logfilename
50
+ datasockf_pidfilename
51
+ datasockf_logfilename
52
+ );
53
+
54
+ # sub second timestamping needs Time::HiRes
55
+ eval {
56
+ no warnings "all";
57
+ require Time::HiRes;
58
+ import Time::HiRes qw( gettimeofday );
59
+ }
60
+ }
61
+
62
+
63
+ our $logfile; # server log file name, for logmsg
64
+
65
+ #***************************************************************************
66
+ # Just for convenience, test harness uses 'https' and 'httptls' literals as
67
+ # values for 'proto' variable in order to differentiate different servers.
68
+ # 'https' literal is used for stunnel based https test servers, and 'httptls'
69
+ # is used for non-stunnel https test servers.
70
+
71
+ #**********************************************************************
72
+ # logmsg is general message logging subroutine for our test servers.
73
+ #
74
+ sub logmsg {
75
+ my $now;
76
+ # sub second timestamping needs Time::HiRes
77
+ if($Time::HiRes::VERSION) {
78
+ my ($seconds, $usec) = gettimeofday();
79
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
80
+ localtime($seconds);
81
+ $now = sprintf("%02d:%02d:%02d.%06d ", $hour, $min, $sec, $usec);
82
+ }
83
+ else {
84
+ my $seconds = time();
85
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
86
+ localtime($seconds);
87
+ $now = sprintf("%02d:%02d:%02d ", $hour, $min, $sec);
88
+ }
89
+ # we see warnings on Windows run that $logfile is used uninitialized
90
+ # TODO: not found yet where this comes from
91
+ $logfile = "serverhelp_uninitialized.log" if(!$logfile);
92
+ if(open(my $logfilefh, ">>", "$logfile")) {
93
+ print $logfilefh $now;
94
+ print $logfilefh @_;
95
+ close($logfilefh);
96
+ }
97
+ }
98
+
99
+
100
+ #***************************************************************************
101
+ # Return server characterization factors given a server id string.
102
+ #
103
+ sub serverfactors {
104
+ my $server = $_[0];
105
+ my $proto;
106
+ my $ipvnum;
107
+ my $idnum;
108
+
109
+ if($server =~
110
+ /^((ftp|http|imap|pop3|smtp|http-pipe)s?)(\d*)(-ipv6|)$/) {
111
+ $proto = $1;
112
+ $idnum = ($3 && ($3 > 1)) ? $3 : 1;
113
+ $ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4;
114
+ }
115
+ elsif($server =~
116
+ /^(tftp|sftp|socks|ssh|rtsp|gopher|httptls)(\d*)(-ipv6|)$/) {
117
+ $proto = $1;
118
+ $idnum = ($2 && ($2 > 1)) ? $2 : 1;
119
+ $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
120
+ }
121
+ else {
122
+ die "invalid server id: '$server'"
123
+ }
124
+ return($proto, $ipvnum, $idnum);
125
+ }
126
+
127
+
128
+ #***************************************************************************
129
+ # Return server name string formatted for presentation purposes
130
+ #
131
+ sub servername_str {
132
+ my ($proto, $ipver, $idnum) = @_;
133
+
134
+ $proto = uc($proto) if($proto);
135
+ die "unsupported protocol: '$proto'" unless($proto &&
136
+ ($proto =~ /^(((FTP|HTTP|HTTP\/2|HTTP\/3|IMAP|POP3|GOPHER|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|HTTPTLS|DICT|SMB|SMBS|TELNET|MQTT|VERYNORMALPROTOCOL))$/));
137
+
138
+ $ipver = (not $ipver) ? 'ipv4' : lc($ipver);
139
+ die "unsupported IP version: '$ipver'" unless($ipver &&
140
+ ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6|unix)$/));
141
+ $ipver = ($ipver =~ /6$/) ? '-IPv6' : (($ipver =~ /unix$/) ? '-unix' : '');
142
+
143
+ $idnum = 1 if(not $idnum);
144
+ die "unsupported ID number: '$idnum'" unless($idnum &&
145
+ ($idnum =~ /^(\d+)$/));
146
+ $idnum = '' if($idnum <= 1);
147
+
148
+ return "${proto}${idnum}${ipver}";
149
+ }
150
+
151
+
152
+ #***************************************************************************
153
+ # Return server name string formatted for identification purposes
154
+ #
155
+ sub servername_id {
156
+ my ($proto, $ipver, $idnum) = @_;
157
+ return lc(servername_str($proto, $ipver, $idnum));
158
+ }
159
+
160
+
161
+ #***************************************************************************
162
+ # Return server name string formatted for file name purposes
163
+ #
164
+ sub servername_canon {
165
+ my ($proto, $ipver, $idnum) = @_;
166
+ my $string = lc(servername_str($proto, $ipver, $idnum));
167
+ $string =~ tr/-/_/;
168
+ $string =~ s/\//_v/;
169
+ return $string;
170
+ }
171
+
172
+
173
+ #***************************************************************************
174
+ # Return file name for server pid file.
175
+ #
176
+ sub server_pidfilename {
177
+ my ($piddir, $proto, $ipver, $idnum) = @_;
178
+ my $trailer = '_server.pid';
179
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
180
+ }
181
+
182
+ #***************************************************************************
183
+ # Return file name for server port file.
184
+ #
185
+ sub server_portfilename {
186
+ my ($piddir, $proto, $ipver, $idnum) = @_;
187
+ my $trailer = '_server.port';
188
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
189
+ }
190
+
191
+
192
+ #***************************************************************************
193
+ # Return file name for server log file.
194
+ #
195
+ sub server_logfilename {
196
+ my ($logdir, $proto, $ipver, $idnum) = @_;
197
+ my $trailer = '_server.log';
198
+ $trailer = '_stunnel.log' if(lc($proto) =~ /^(ftp|http|imap|pop3|smtp)s$/);
199
+ return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
200
+ }
201
+
202
+
203
+ #***************************************************************************
204
+ # Return file name for server commands file.
205
+ #
206
+ sub server_cmdfilename {
207
+ my ($logdir, $proto, $ipver, $idnum) = @_;
208
+ my $trailer = '_server.cmd';
209
+ return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
210
+ }
211
+
212
+
213
+ #***************************************************************************
214
+ # Return file name for server input file.
215
+ #
216
+ sub server_inputfilename {
217
+ my ($logdir, $proto, $ipver, $idnum) = @_;
218
+ my $trailer = '_server.input';
219
+ return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
220
+ }
221
+
222
+
223
+ #***************************************************************************
224
+ # Return file name for server output file.
225
+ #
226
+ sub server_outputfilename {
227
+ my ($logdir, $proto, $ipver, $idnum) = @_;
228
+ my $trailer = '_server.output';
229
+ return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
230
+ }
231
+
232
+
233
+ #***************************************************************************
234
+ # Return file name for main or primary sockfilter pid file.
235
+ #
236
+ sub mainsockf_pidfilename {
237
+ my ($piddir, $proto, $ipver, $idnum) = @_;
238
+ die "unsupported protocol: '$proto'" unless($proto &&
239
+ (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
240
+ my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.pid':'_sockfilt.pid';
241
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
242
+ }
243
+
244
+
245
+ #***************************************************************************
246
+ # Return file name for main or primary sockfilter log file.
247
+ #
248
+ sub mainsockf_logfilename {
249
+ my ($logdir, $proto, $ipver, $idnum) = @_;
250
+ die "unsupported protocol: '$proto'" unless($proto &&
251
+ (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
252
+ my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.log':'_sockfilt.log';
253
+ return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
254
+ }
255
+
256
+
257
+ #***************************************************************************
258
+ # Return file name for data or secondary sockfilter pid file.
259
+ #
260
+ sub datasockf_pidfilename {
261
+ my ($piddir, $proto, $ipver, $idnum) = @_;
262
+ die "unsupported protocol: '$proto'" unless($proto &&
263
+ (lc($proto) =~ /^ftps?$/));
264
+ my $trailer = '_sockdata.pid';
265
+ return "${piddir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
266
+ }
267
+
268
+
269
+ #***************************************************************************
270
+ # Return file name for data or secondary sockfilter log file.
271
+ #
272
+ sub datasockf_logfilename {
273
+ my ($logdir, $proto, $ipver, $idnum) = @_;
274
+ die "unsupported protocol: '$proto'" unless($proto &&
275
+ (lc($proto) =~ /^ftps?$/));
276
+ my $trailer = '_sockdata.log';
277
+ return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
278
+ }
279
+
280
+
281
+ #***************************************************************************
282
+ # End of library
283
+ 1;
local-test-curl-delta-01/afc-curl/tests/smbserver.py ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ """Server for testing SMB."""
25
+
26
+ from __future__ import (absolute_import, division, print_function,
27
+ unicode_literals)
28
+
29
+ import argparse
30
+ import logging
31
+ import os
32
+ import signal
33
+ import sys
34
+ import tempfile
35
+ import threading
36
+
37
+ # Import our curl test data helper
38
+ from util import ClosingFileHandler, TestData
39
+
40
+ if sys.version_info.major >= 3:
41
+ import configparser
42
+ else:
43
+ import ConfigParser as configparser
44
+
45
+ # impacket needs to be installed in the Python environment
46
+ try:
47
+ import impacket # noqa: F401
48
+ except ImportError:
49
+ sys.stderr.write(
50
+ 'Warning: Python package impacket is required for smb testing; '
51
+ 'use pip or your package manager to install it\n')
52
+ sys.exit(1)
53
+ from impacket import smb as imp_smb
54
+ from impacket import smbserver as imp_smbserver
55
+ from impacket.nt_errors import (STATUS_ACCESS_DENIED, STATUS_NO_SUCH_FILE,
56
+ STATUS_SUCCESS)
57
+
58
+ log = logging.getLogger(__name__)
59
+ SERVER_MAGIC = "SERVER_MAGIC"
60
+ TESTS_MAGIC = "TESTS_MAGIC"
61
+ VERIFIED_REQ = "verifiedserver"
62
+ VERIFIED_RSP = "WE ROOLZ: {pid}\n"
63
+
64
+
65
+ class ShutdownHandler(threading.Thread):
66
+ """
67
+ Cleanly shut down the SMB server.
68
+
69
+ This can only be done from another thread while the server is in
70
+ serve_forever(), so a thread is spawned here that waits for a shutdown
71
+ signal before doing its thing. Use in a with statement around the
72
+ serve_forever() call.
73
+ """
74
+
75
+ def __init__(self, server):
76
+ super(ShutdownHandler, self).__init__()
77
+ self.server = server
78
+ self.shutdown_event = threading.Event()
79
+
80
+ def __enter__(self):
81
+ self.start()
82
+ signal.signal(signal.SIGINT, self._sighandler)
83
+ signal.signal(signal.SIGTERM, self._sighandler)
84
+
85
+ def __exit__(self, *_):
86
+ # Call for shutdown just in case it wasn't done already
87
+ self.shutdown_event.set()
88
+ # Wait for thread, and therefore also the server, to finish
89
+ self.join()
90
+ # Uninstall our signal handlers
91
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
92
+ signal.signal(signal.SIGTERM, signal.SIG_DFL)
93
+ # Delete any temporary files created by the server during its run
94
+ log.info("Deleting %d temporary file(s)", len(self.server.tmpfiles))
95
+ for f in self.server.tmpfiles:
96
+ os.unlink(f)
97
+
98
+ def _sighandler(self, _signum, _frame):
99
+ # Wake up the cleanup task
100
+ self.shutdown_event.set()
101
+
102
+ def run(self):
103
+ # Wait for shutdown signal
104
+ self.shutdown_event.wait()
105
+ # Notify the server to shut down
106
+ self.server.shutdown()
107
+
108
+
109
+ def smbserver(options):
110
+ """Start up a TCP SMB server that serves forever."""
111
+ if options.pidfile:
112
+ pid = os.getpid()
113
+ # see tests/server/util.c function write_pidfile
114
+ if os.name == "nt":
115
+ pid += 65536
116
+ with open(options.pidfile, "w") as f:
117
+ f.write(str(pid))
118
+
119
+ # Here we write a mini config for the server
120
+ smb_config = configparser.ConfigParser()
121
+ smb_config.add_section("global")
122
+ smb_config.set("global", "server_name", "SERVICE")
123
+ smb_config.set("global", "server_os", "UNIX")
124
+ smb_config.set("global", "server_domain", "WORKGROUP")
125
+ smb_config.set("global", "log_file", "None")
126
+ smb_config.set("global", "credentials_file", "")
127
+
128
+ # We need a share which allows us to test that the server is running
129
+ smb_config.add_section("SERVER")
130
+ smb_config.set("SERVER", "comment", "server function")
131
+ smb_config.set("SERVER", "read only", "yes")
132
+ smb_config.set("SERVER", "share type", "0")
133
+ smb_config.set("SERVER", "path", SERVER_MAGIC)
134
+
135
+ # Have a share for tests. These files will be autogenerated from the
136
+ # test input.
137
+ smb_config.add_section("TESTS")
138
+ smb_config.set("TESTS", "comment", "tests")
139
+ smb_config.set("TESTS", "read only", "yes")
140
+ smb_config.set("TESTS", "share type", "0")
141
+ smb_config.set("TESTS", "path", TESTS_MAGIC)
142
+
143
+ if not options.srcdir or not os.path.isdir(options.srcdir):
144
+ raise ScriptError("--srcdir is mandatory")
145
+
146
+ test_data_dir = os.path.join(options.srcdir, "data")
147
+
148
+ smb_server = TestSmbServer((options.host, options.port),
149
+ config_parser=smb_config,
150
+ test_data_directory=test_data_dir)
151
+ log.info("[SMB] setting up SMB server on port %s", options.port)
152
+ smb_server.processConfigFile()
153
+
154
+ # Start a thread that cleanly shuts down the server on a signal
155
+ with ShutdownHandler(smb_server):
156
+ # This will block until smb_server.shutdown() is called
157
+ smb_server.serve_forever()
158
+
159
+ return 0
160
+
161
+
162
+ class TestSmbServer(imp_smbserver.SMBSERVER):
163
+ """
164
+ Test server for SMB which subclasses the impacket SMBSERVER and provides
165
+ test functionality.
166
+ """
167
+
168
+ def __init__(self,
169
+ address,
170
+ config_parser=None,
171
+ test_data_directory=None):
172
+ imp_smbserver.SMBSERVER.__init__(self,
173
+ address,
174
+ config_parser=config_parser)
175
+ self.tmpfiles = []
176
+
177
+ # Set up a test data object so we can get test data later.
178
+ self.ctd = TestData(test_data_directory)
179
+
180
+ # Override smbComNtCreateAndX so we can pretend to have files which
181
+ # don't exist.
182
+ self.hookSmbCommand(imp_smb.SMB.SMB_COM_NT_CREATE_ANDX,
183
+ self.create_and_x)
184
+
185
+ def create_and_x(self, conn_id, smb_server, smb_command, recv_packet):
186
+ """
187
+ Our version of smbComNtCreateAndX looks for special test files and
188
+ fools the rest of the framework into opening them as if they were
189
+ normal files.
190
+ """
191
+ conn_data = smb_server.getConnectionData(conn_id)
192
+
193
+ # Wrap processing in a try block which allows us to throw SmbError
194
+ # to control the flow.
195
+ try:
196
+ ncax_parms = imp_smb.SMBNtCreateAndX_Parameters(
197
+ smb_command["Parameters"])
198
+
199
+ path = self.get_share_path(conn_data,
200
+ ncax_parms["RootFid"],
201
+ recv_packet["Tid"])
202
+ log.info("[SMB] Requested share path: %s", path)
203
+
204
+ disposition = ncax_parms["Disposition"]
205
+ log.debug("[SMB] Requested disposition: %s", disposition)
206
+
207
+ # Currently we only support reading files.
208
+ if disposition != imp_smb.FILE_OPEN:
209
+ raise SmbError(STATUS_ACCESS_DENIED,
210
+ "Only support reading files")
211
+
212
+ # Check to see if the path we were given is actually a
213
+ # magic path which needs generating on the fly.
214
+ if path not in [SERVER_MAGIC, TESTS_MAGIC]:
215
+ # Pass the command onto the original handler.
216
+ return imp_smbserver.SMBCommands.smbComNtCreateAndX(conn_id,
217
+ smb_server,
218
+ smb_command,
219
+ recv_packet)
220
+
221
+ flags2 = recv_packet["Flags2"]
222
+ ncax_data = imp_smb.SMBNtCreateAndX_Data(flags=flags2,
223
+ data=smb_command[
224
+ "Data"])
225
+ requested_file = imp_smbserver.decodeSMBString(
226
+ flags2,
227
+ ncax_data["FileName"])
228
+ log.debug("[SMB] User requested file '%s'", requested_file)
229
+
230
+ if path == SERVER_MAGIC:
231
+ fid, full_path = self.get_server_path(requested_file)
232
+ else:
233
+ assert path == TESTS_MAGIC
234
+ fid, full_path = self.get_test_path(requested_file)
235
+
236
+ self.tmpfiles.append(full_path)
237
+
238
+ resp_parms = imp_smb.SMBNtCreateAndXResponse_Parameters()
239
+ resp_data = ""
240
+
241
+ # Simple way to generate a fid
242
+ if len(conn_data["OpenedFiles"]) == 0:
243
+ fakefid = 1
244
+ else:
245
+ fakefid = conn_data["OpenedFiles"].keys()[-1] + 1
246
+ resp_parms["Fid"] = fakefid
247
+ resp_parms["CreateAction"] = disposition
248
+
249
+ if os.path.isdir(path):
250
+ resp_parms[
251
+ "FileAttributes"] = imp_smb.SMB_FILE_ATTRIBUTE_DIRECTORY
252
+ resp_parms["IsDirectory"] = 1
253
+ else:
254
+ resp_parms["IsDirectory"] = 0
255
+ resp_parms["FileAttributes"] = ncax_parms["FileAttributes"]
256
+
257
+ # Get this file's information
258
+ resp_info, error_code = imp_smbserver.queryPathInformation(
259
+ os.path.dirname(full_path), os.path.basename(full_path),
260
+ level=imp_smb.SMB_QUERY_FILE_ALL_INFO)
261
+
262
+ if error_code != STATUS_SUCCESS:
263
+ raise SmbError(error_code, "Failed to query path info")
264
+
265
+ resp_parms["CreateTime"] = resp_info["CreationTime"]
266
+ resp_parms["LastAccessTime"] = resp_info[
267
+ "LastAccessTime"]
268
+ resp_parms["LastWriteTime"] = resp_info["LastWriteTime"]
269
+ resp_parms["LastChangeTime"] = resp_info[
270
+ "LastChangeTime"]
271
+ resp_parms["FileAttributes"] = resp_info[
272
+ "ExtFileAttributes"]
273
+ resp_parms["AllocationSize"] = resp_info[
274
+ "AllocationSize"]
275
+ resp_parms["EndOfFile"] = resp_info["EndOfFile"]
276
+
277
+ # Let's store the fid for the connection
278
+ # smbServer.log("Create file %s, mode:0x%x" % (pathName, mode))
279
+ conn_data["OpenedFiles"][fakefid] = {}
280
+ conn_data["OpenedFiles"][fakefid]["FileHandle"] = fid
281
+ conn_data["OpenedFiles"][fakefid]["FileName"] = path
282
+ conn_data["OpenedFiles"][fakefid]["DeleteOnClose"] = False
283
+
284
+ except SmbError as s:
285
+ log.debug("[SMB] SmbError hit: %s", s)
286
+ error_code = s.error_code
287
+ resp_parms = ""
288
+ resp_data = ""
289
+
290
+ resp_cmd = imp_smb.SMBCommand(imp_smb.SMB.SMB_COM_NT_CREATE_ANDX)
291
+ resp_cmd["Parameters"] = resp_parms
292
+ resp_cmd["Data"] = resp_data
293
+ smb_server.setConnectionData(conn_id, conn_data)
294
+
295
+ return [resp_cmd], None, error_code
296
+
297
+ def get_share_path(self, conn_data, root_fid, tid):
298
+ conn_shares = conn_data["ConnectedShares"]
299
+
300
+ if tid in conn_shares:
301
+ if root_fid > 0:
302
+ # If we have a rootFid, the path is relative to that fid
303
+ path = conn_data["OpenedFiles"][root_fid]["FileName"]
304
+ log.debug("RootFid present %s!" % path)
305
+ else:
306
+ if "path" in conn_shares[tid]:
307
+ path = conn_shares[tid]["path"]
308
+ else:
309
+ raise SmbError(STATUS_ACCESS_DENIED,
310
+ "Connection share had no path")
311
+ else:
312
+ raise SmbError(imp_smbserver.STATUS_SMB_BAD_TID,
313
+ "TID was invalid")
314
+
315
+ return path
316
+
317
+ def get_server_path(self, requested_filename):
318
+ log.debug("[SMB] Get server path '%s'", requested_filename)
319
+
320
+ if requested_filename not in [VERIFIED_REQ]:
321
+ raise SmbError(STATUS_NO_SUCH_FILE, "Couldn't find the file")
322
+
323
+ fid, filename = tempfile.mkstemp()
324
+ log.debug("[SMB] Created %s (%d) for storing '%s'",
325
+ filename, fid, requested_filename)
326
+
327
+ contents = ""
328
+
329
+ if requested_filename == VERIFIED_REQ:
330
+ log.debug("[SMB] Verifying server is alive")
331
+ pid = os.getpid()
332
+ # see tests/server/util.c function write_pidfile
333
+ if os.name == "nt":
334
+ pid += 65536
335
+ contents = VERIFIED_RSP.format(pid=pid).encode('utf-8')
336
+
337
+ self.write_to_fid(fid, contents)
338
+ return fid, filename
339
+
340
+ def write_to_fid(self, fid, contents):
341
+ # Write the contents to file descriptor
342
+ os.write(fid, contents)
343
+ os.fsync(fid)
344
+
345
+ # Rewind the file to the beginning so a read gets us the contents
346
+ os.lseek(fid, 0, os.SEEK_SET)
347
+
348
+ def get_test_path(self, requested_filename):
349
+ log.info("[SMB] Get reply data from 'test%s'", requested_filename)
350
+
351
+ fid, filename = tempfile.mkstemp()
352
+ log.debug("[SMB] Created %s (%d) for storing test '%s'",
353
+ filename, fid, requested_filename)
354
+
355
+ try:
356
+ contents = self.ctd.get_test_data(requested_filename).encode('utf-8')
357
+ self.write_to_fid(fid, contents)
358
+ return fid, filename
359
+
360
+ except Exception:
361
+ log.exception("Failed to make test file")
362
+ raise SmbError(STATUS_NO_SUCH_FILE, "Failed to make test file")
363
+
364
+
365
+ class SmbError(Exception):
366
+ def __init__(self, error_code, error_message):
367
+ super(SmbError, self).__init__(error_message)
368
+ self.error_code = error_code
369
+
370
+
371
+ class ScriptRC(object):
372
+ """Enum for script return codes."""
373
+
374
+ SUCCESS = 0
375
+ FAILURE = 1
376
+ EXCEPTION = 2
377
+
378
+
379
+ class ScriptError(Exception):
380
+ pass
381
+
382
+
383
+ def get_options():
384
+ parser = argparse.ArgumentParser()
385
+
386
+ parser.add_argument("--port", action="store", default=9017,
387
+ type=int, help="port to listen on")
388
+ parser.add_argument("--host", action="store", default="127.0.0.1",
389
+ help="host to listen on")
390
+ parser.add_argument("--verbose", action="store", type=int, default=0,
391
+ help="verbose output")
392
+ parser.add_argument("--pidfile", action="store",
393
+ help="file name for the PID")
394
+ parser.add_argument("--logfile", action="store",
395
+ help="file name for the log")
396
+ parser.add_argument("--srcdir", action="store", help="test directory")
397
+ parser.add_argument("--id", action="store", help="server ID")
398
+ parser.add_argument("--ipv4", action="store_true", default=0,
399
+ help="IPv4 flag")
400
+
401
+ return parser.parse_args()
402
+
403
+
404
+ def setup_logging(options):
405
+ """Set up logging from the command line options."""
406
+ root_logger = logging.getLogger()
407
+ add_stdout = False
408
+
409
+ formatter = logging.Formatter("%(asctime)s %(levelname)-5.5s %(message)s")
410
+
411
+ # Write out to a logfile
412
+ if options.logfile:
413
+ handler = ClosingFileHandler(options.logfile)
414
+ handler.setFormatter(formatter)
415
+ handler.setLevel(logging.DEBUG)
416
+ root_logger.addHandler(handler)
417
+ else:
418
+ # The logfile wasn't specified. Add a stdout logger.
419
+ add_stdout = True
420
+
421
+ if options.verbose:
422
+ # Add a stdout logger as well in verbose mode
423
+ root_logger.setLevel(logging.DEBUG)
424
+ add_stdout = True
425
+ else:
426
+ root_logger.setLevel(logging.WARNING)
427
+
428
+ if add_stdout:
429
+ stdout_handler = logging.StreamHandler(sys.stdout)
430
+ stdout_handler.setFormatter(formatter)
431
+ stdout_handler.setLevel(logging.DEBUG)
432
+ root_logger.addHandler(stdout_handler)
433
+
434
+
435
+ if __name__ == '__main__':
436
+ # Get the options from the user.
437
+ options = get_options()
438
+
439
+ # Setup logging using the user options
440
+ setup_logging(options)
441
+
442
+ # Run main script.
443
+ try:
444
+ rc = smbserver(options)
445
+ except Exception:
446
+ log.exception('Error in SMB server')
447
+ rc = ScriptRC.EXCEPTION
448
+
449
+ if options.pidfile and os.path.isfile(options.pidfile):
450
+ os.unlink(options.pidfile)
451
+
452
+ log.info("[SMB] Returning %d", rc)
453
+ sys.exit(rc)
local-test-curl-delta-01/afc-curl/tests/sshhelp.pm ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ #***************************************************************************
24
+
25
+ package sshhelp;
26
+
27
+ use strict;
28
+ use warnings;
29
+
30
+ BEGIN {
31
+ use base qw(Exporter);
32
+
33
+ our @EXPORT_OK = qw(
34
+ $sshdexe
35
+ $sshexe
36
+ $sftpsrvexe
37
+ $sftpexe
38
+ $sshkeygenexe
39
+ $sshdconfig
40
+ $sshconfig
41
+ $sftpconfig
42
+ $knownhosts
43
+ $sshdlog
44
+ $sshlog
45
+ $sftplog
46
+ $sftpcmds
47
+ $hstprvkeyf
48
+ $hstpubkeyf
49
+ $hstpubmd5f
50
+ $hstpubsha256f
51
+ $cliprvkeyf
52
+ $clipubkeyf
53
+ display_sshdconfig
54
+ display_sshconfig
55
+ display_sftpconfig
56
+ display_sshdlog
57
+ display_sshlog
58
+ display_sftplog
59
+ dump_array
60
+ find_sshd
61
+ find_ssh
62
+ find_sftpsrv
63
+ find_sftp
64
+ find_sshkeygen
65
+ find_httptlssrv
66
+ sshversioninfo
67
+ );
68
+ }
69
+
70
+ use File::Spec;
71
+
72
+ use pathhelp qw(
73
+ exe_ext
74
+ );
75
+
76
+ #***************************************************************************
77
+ # Global variables initialization
78
+ #
79
+ our $sshdexe = 'sshd' .exe_ext('SSH'); # base name and ext of ssh daemon
80
+ our $sshexe = 'ssh' .exe_ext('SSH'); # base name and ext of ssh client
81
+ our $sftpsrvexe = 'sftp-server' .exe_ext('SSH'); # base name and ext of sftp-server
82
+ our $sftpexe = 'sftp' .exe_ext('SSH'); # base name and ext of sftp client
83
+ our $sshkeygenexe = 'ssh-keygen' .exe_ext('SSH'); # base name and ext of ssh-keygen
84
+ our $httptlssrvexe = 'gnutls-serv' .exe_ext('SSH'); # base name and ext of gnutls-serv
85
+ our $sshdconfig = 'curl_sshd_config'; # ssh daemon config file
86
+ our $sshconfig = 'curl_ssh_config'; # ssh client config file
87
+ our $sftpconfig = 'curl_sftp_config'; # sftp client config file
88
+ our $sshdlog = undef; # ssh daemon log file
89
+ our $sshlog = undef; # ssh client log file
90
+ our $sftplog = undef; # sftp client log file
91
+ our $sftpcmds = 'curl_sftp_cmds'; # sftp client commands batch file
92
+ our $knownhosts = 'curl_client_knownhosts'; # ssh knownhosts file
93
+ our $hstprvkeyf = 'curl_host_rsa_key'; # host private key file
94
+ our $hstpubkeyf = 'curl_host_rsa_key.pub'; # host public key file
95
+ our $hstpubmd5f = 'curl_host_rsa_key.pub_md5'; # md5 hash of host public key
96
+ our $hstpubsha256f = 'curl_host_rsa_key.pub_sha256'; # sha256 hash of host public key
97
+ our $cliprvkeyf = 'curl_client_key'; # client private key file
98
+ our $clipubkeyf = 'curl_client_key.pub'; # client public key file
99
+
100
+
101
+ #***************************************************************************
102
+ # Absolute paths where to look for sftp-server plugin, when not in PATH
103
+ #
104
+ our @sftppath = qw(
105
+ /usr/lib/openssh
106
+ /usr/libexec/openssh
107
+ /usr/libexec
108
+ /usr/local/libexec
109
+ /opt/local/libexec
110
+ /usr/lib/ssh
111
+ /usr/libexec/ssh
112
+ /usr/sbin
113
+ /usr/lib
114
+ /usr/lib/ssh/openssh
115
+ /usr/lib64/ssh
116
+ /usr/lib64/misc
117
+ /usr/lib/misc
118
+ /usr/local/sbin
119
+ /usr/freeware/bin
120
+ /usr/freeware/sbin
121
+ /usr/freeware/libexec
122
+ /opt/ssh/sbin
123
+ /opt/ssh/libexec
124
+ );
125
+
126
+
127
+ #***************************************************************************
128
+ # Absolute paths where to look for httptlssrv (gnutls-serv), when not in PATH
129
+ #
130
+ our @httptlssrvpath = qw(
131
+ /usr/sbin
132
+ /usr/libexec
133
+ /usr/lib
134
+ /usr/lib/misc
135
+ /usr/lib64/misc
136
+ /usr/local/bin
137
+ /usr/local/sbin
138
+ /usr/local/libexec
139
+ /opt/local/bin
140
+ /opt/local/sbin
141
+ /opt/local/libexec
142
+ /usr/freeware/bin
143
+ /usr/freeware/sbin
144
+ /usr/freeware/libexec
145
+ /opt/gnutls/bin
146
+ /opt/gnutls/sbin
147
+ /opt/gnutls/libexec
148
+ );
149
+
150
+
151
+ #***************************************************************************
152
+ # Create or overwrite the given file with lines from an array of strings
153
+ #
154
+ sub dump_array {
155
+ my ($filename, @arr) = @_;
156
+ my $error;
157
+
158
+ if(!$filename) {
159
+ $error = 'Error: Missing argument 1 for dump_array()';
160
+ }
161
+ elsif(open(my $textfh, ">", $filename)) {
162
+ foreach my $line (@arr) {
163
+ $line .= "\n" if($line !~ /\n$/);
164
+ print $textfh $line;
165
+ }
166
+ if(!close($textfh)) {
167
+ $error = "Error: cannot close file $filename";
168
+ }
169
+ }
170
+ else {
171
+ $error = "Error: cannot write file $filename";
172
+ }
173
+ return $error;
174
+ }
175
+
176
+
177
+ #***************************************************************************
178
+ # Display contents of the given file
179
+ #
180
+ sub display_file {
181
+ my $filename = $_[0];
182
+ print "=== Start of file $filename\n";
183
+ if(open(my $displayfh, "<", "$filename")) {
184
+ while(my $line = <$displayfh>) {
185
+ print "$line";
186
+ }
187
+ close $displayfh;
188
+ }
189
+ print "=== End of file $filename\n";
190
+ }
191
+
192
+
193
+ #***************************************************************************
194
+ # Display contents of the ssh daemon config file
195
+ #
196
+ sub display_sshdconfig {
197
+ display_file($sshdconfig);
198
+ }
199
+
200
+
201
+ #***************************************************************************
202
+ # Display contents of the ssh client config file
203
+ #
204
+ sub display_sshconfig {
205
+ display_file($sshconfig);
206
+ }
207
+
208
+
209
+ #***************************************************************************
210
+ # Display contents of the sftp client config file
211
+ #
212
+ sub display_sftpconfig {
213
+ display_file($sftpconfig);
214
+ }
215
+
216
+
217
+ #***************************************************************************
218
+ # Display contents of the ssh daemon log file
219
+ #
220
+ sub display_sshdlog {
221
+ die "error: \$sshdlog uninitialized" if(not defined $sshdlog);
222
+ display_file($sshdlog);
223
+ }
224
+
225
+
226
+ #***************************************************************************
227
+ # Display contents of the ssh client log file
228
+ #
229
+ sub display_sshlog {
230
+ die "error: \$sshlog uninitialized" if(not defined $sshlog);
231
+ display_file($sshlog);
232
+ }
233
+
234
+
235
+ #***************************************************************************
236
+ # Display contents of the sftp client log file
237
+ #
238
+ sub display_sftplog {
239
+ die "error: \$sftplog uninitialized" if(not defined $sftplog);
240
+ display_file($sftplog);
241
+ }
242
+
243
+
244
+ #***************************************************************************
245
+ # Find a file somewhere in the given path
246
+ #
247
+ sub find_file {
248
+ my $fn = $_[0];
249
+ shift;
250
+ my @path = @_;
251
+ foreach (@path) {
252
+ my $file = File::Spec->catfile($_, $fn);
253
+ if(-e $file && ! -d $file) {
254
+ return $file;
255
+ }
256
+ }
257
+ return "";
258
+ }
259
+
260
+
261
+ #***************************************************************************
262
+ # Find an executable file somewhere in the given path
263
+ #
264
+ sub find_exe_file {
265
+ my $fn = $_[0];
266
+ shift;
267
+ my @path = @_;
268
+ my $xext = exe_ext('SSH');
269
+ foreach (@path) {
270
+ my $file = File::Spec->catfile($_, $fn);
271
+ if(-e $file && ! -d $file) {
272
+ return $file if(-x $file);
273
+ return $file if(($xext) && (lc($file) =~ /\Q$xext\E$/));
274
+ }
275
+ }
276
+ return "";
277
+ }
278
+
279
+
280
+ #***************************************************************************
281
+ # Find a file in environment path or in our sftppath
282
+ #
283
+ sub find_file_spath {
284
+ my $filename = $_[0];
285
+ my @spath;
286
+ push(@spath, File::Spec->path());
287
+ push(@spath, @sftppath);
288
+ return find_file($filename, @spath);
289
+ }
290
+
291
+
292
+ #***************************************************************************
293
+ # Find an executable file in environment path or in our httptlssrvpath
294
+ #
295
+ sub find_exe_file_hpath {
296
+ my $filename = $_[0];
297
+ my @hpath;
298
+ push(@hpath, File::Spec->path());
299
+ push(@hpath, @httptlssrvpath);
300
+ return find_exe_file($filename, @hpath);
301
+ }
302
+
303
+
304
+ #***************************************************************************
305
+ # Find ssh daemon and return canonical filename
306
+ #
307
+ sub find_sshd {
308
+ return find_file_spath($sshdexe);
309
+ }
310
+
311
+
312
+ #***************************************************************************
313
+ # Find ssh client and return canonical filename
314
+ #
315
+ sub find_ssh {
316
+ return find_file_spath($sshexe);
317
+ }
318
+
319
+
320
+ #***************************************************************************
321
+ # Find sftp-server plugin and return canonical filename
322
+ #
323
+ sub find_sftpsrv {
324
+ return find_file_spath($sftpsrvexe);
325
+ }
326
+
327
+
328
+ #***************************************************************************
329
+ # Find sftp client and return canonical filename
330
+ #
331
+ sub find_sftp {
332
+ return find_file_spath($sftpexe);
333
+ }
334
+
335
+
336
+ #***************************************************************************
337
+ # Find ssh-keygen and return canonical filename
338
+ #
339
+ sub find_sshkeygen {
340
+ return find_file_spath($sshkeygenexe);
341
+ }
342
+
343
+
344
+ #***************************************************************************
345
+ # Find httptlssrv (gnutls-serv) and return canonical filename
346
+ #
347
+ sub find_httptlssrv {
348
+ my $p = find_exe_file_hpath($httptlssrvexe);
349
+ if($p) {
350
+ my @o = `"$p" -l`;
351
+ my $found;
352
+ for(@o) {
353
+ if(/Key exchange: SRP/) {
354
+ $found = 1;
355
+ last;
356
+ }
357
+ }
358
+ return $p if($found);
359
+ }
360
+ return "";
361
+ }
362
+
363
+
364
+ #***************************************************************************
365
+ # Return version info for the given ssh client or server binaries
366
+ #
367
+ sub sshversioninfo {
368
+ my $sshbin = $_[0]; # canonical filename
369
+ my $major;
370
+ my $minor;
371
+ my $patch;
372
+ my $sshid;
373
+ my $versnum;
374
+ my $versstr;
375
+ my $error;
376
+
377
+ if(!$sshbin) {
378
+ $error = 'Error: Missing argument 1 for sshversioninfo()';
379
+ }
380
+ elsif(! -x $sshbin) {
381
+ $error = "Error: cannot read or execute $sshbin";
382
+ }
383
+ else {
384
+ my $cmd = ($sshbin =~ /$sshdexe$/) ? "\"$sshbin\" -?" : "\"$sshbin\" -V";
385
+ $error = "$cmd\n";
386
+ foreach my $tmpstr (qx($cmd 2>&1)) {
387
+ if($tmpstr =~ /OpenSSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
388
+ $major = $1;
389
+ $minor = $2;
390
+ $patch = $4?$4:0;
391
+ $sshid = 'OpenSSH';
392
+ $versnum = (100*$major) + (10*$minor) + $patch;
393
+ $versstr = "$sshid $major.$minor.$patch";
394
+ $error = undef;
395
+ last;
396
+ }
397
+ if($tmpstr =~ /OpenSSH[_-]for[_-]Windows[_-](\d+)\.(\d+)(\.(\d+))*/i) {
398
+ $major = $1;
399
+ $minor = $2;
400
+ $patch = $4?$4:0;
401
+ $sshid = 'OpenSSH-Windows';
402
+ $versnum = (100*$major) + (10*$minor) + $patch;
403
+ $versstr = "$sshid $major.$minor.$patch";
404
+ $error = undef;
405
+ last;
406
+ }
407
+ if($tmpstr =~ /Sun[_-]SSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
408
+ $major = $1;
409
+ $minor = $2;
410
+ $patch = $4?$4:0;
411
+ $sshid = 'SunSSH';
412
+ $versnum = (100*$major) + (10*$minor) + $patch;
413
+ $versstr = "$sshid $major.$minor.$patch";
414
+ $error = undef;
415
+ last;
416
+ }
417
+ $error .= $tmpstr;
418
+ }
419
+ chomp $error if($error);
420
+ }
421
+ return ($sshid, $versnum, $versstr, $error);
422
+ }
423
+
424
+
425
+ #***************************************************************************
426
+ # End of library
427
+ 1;
local-test-curl-delta-01/afc-curl/tests/stunnel.pem ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extensions = x509v3
2
+
3
+ [ x509v3 ]
4
+ subjectAltName = DNS:localhost
5
+ keyUsage = keyEncipherment,digitalSignature,keyAgreement
6
+ extendedKeyUsage = serverAuth
7
+ subjectKeyIdentifier = hash
8
+ authorityKeyIdentifier = keyid
9
+ basicConstraints = CA:false
10
+ authorityInfoAccess = @issuer_info
11
+ crlDistributionPoints = @crl_info
12
+
13
+ [ crl_ext ]
14
+ authorityKeyIdentifier = keyid:always
15
+ authorityInfoAccess = @issuer_info
16
+
17
+ [ issuer_info ]
18
+ caIssuers;URI.0 = http://test.curl.se/ca/EdelCurlRoot.cer
19
+
20
+ [ crl_info ]
21
+ URI.0 = http://test.curl.se/ca/EdelCurlRoot.crl
22
+
23
+ [ req ]
24
+ default_bits = 12048
25
+ distinguished_name = req_DN
26
+ default_md = sha256
27
+ string_mask = utf8only
28
+
29
+ [ req_DN ]
30
+ countryName = "Country Name is Northern Nowhere"
31
+ countryName_value = NN
32
+ organizationName = "Organization Name"
33
+ organizationName_value = Edel Curl Arctic Illudium Research Cloud
34
+ commonName = "Common Name"
35
+ commonName_value = localhost
36
+ -----BEGIN PRIVATE KEY-----
37
+ MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCrCrAD0Hb+Xs4V
38
+ 3mHV45FvfNa7yiaOeL4mNdGmWfHVPFU+CSzsoNSvDjxaorWweFGVYoCAcchOn1lZ
39
+ k0ASsqnOss0Xi58n8+PPI3gG0gYjX5sg7EJ3Zq2kXoK0TZRy6hNkcvzLgyzXoYv1
40
+ LkzTwYiyyJgZX++Y/GKAs2fMHyP8XzjNgm4tltk1k/4pomllwN9Fqz+sFxgAgEq3
41
+ ybq4Xym7xKwWl8xXNBDJNmVsPtiJRcilQoR8Xs0a6PE+VbMhD9A2E/LEL7lzQfqH
42
+ qtxE1mSW5FpQ+Uqf4KLnafStWs86IOWnCeLP6BmhAK6ouyICNFyzz7UkTHa/renx
43
+ uNOGun2TAgMBAAECggEAH0BsKb5Ax7h90jwYRzL141d9isFkaxq/r46c2FbN24bT
44
+ EmstxKycP8ILoAnjxbMuQOvHC/D+RvNRqY7Aocn4Qdakp50wvuWOpc3Ww/RC/9qb
45
+ pxfUCyn9Jy/HlPcp3RdM5MknzG2S13Fid7F2gyh0+CmztMs1JZBT1S0ylXbJJfbY
46
+ 1pdlHcf9oEbYo36vGd9rtJHAFzsFfwua0idl76XYuOnR3bpOkHl1B5cJ8jpOliPv
47
+ VTmzn0cIgAmk7IByHHqGQ0u30PFiElI9kEbkKWoxAM1hq1pFU58jQhvp0ZkjVENL
48
+ bSFB2B4DbyosxPlbUgvJCN4B7nclqzYqBdrrk6/ZLQKBgQC1lDrPSGIGXLwvkZYS
49
+ xc0wtaCC7u6m7zV8rzh5HGcEoVvtmya/VyoZR8KGIpSor8COIkZqFtan6C77C3MH
50
+ wClbu2Kn3FkGb76D5U2Xwl38zepzjn8Z5qXc3bZfccrsDY1gXPicgsmcKUY9xV5/
51
+ T0RjESDKB+xxkJpCjia6klm2NQKBgQDxJNuqB6frDYKaj7mW/rvyHqkeT94J6eDY
52
+ BcMZVKeHRNWcBMOvJDChVmpsCjJPOWHhHOlAE755NxWn8wpgyiUcac3BiysMgvTT
53
+ pyH8UVWaP/DWYOfpuhtcLPkIjKnPijOvshpyWBxfXNIejiovoT6E3IXKOxr5g5yq
54
+ U/9a5+I9pwKBgDyJG4YpkoyedBrDxa2ihkL7+nRMZgH/c+yKmiA+aNXxWa2AcU2P
55
+ KLje5KpFcxw948s/AAy0aoH19Vu6uHHYDbHIah6eZouvy2s7kj/LC/yRRd2anyMq
56
+ cxeMTxXI4ScLaZu7wyKis8Y9OG61k0iMS7dfaXgRZjGCTPttWtoOmpwVAoGAd2k+
57
+ EXuLDl15UBpd18S6wxGlw2nfVN9oxPBNhUyjTNusP38oe6EbJ7mIJ4oBEbQjoPrV
58
+ EjL0vkelxK4YdIeFSwWlqvLEVYS/wdNgg/auwhxpoW8JSHctNz7Z7v7g0/Hm2FkE
59
+ uZyiKCLptdHGWCGruNUOt27/U5F10e6YY6ayJL8CgYEAoE/ddHIlrKFzcZ0cu47R
60
+ ky4D4x32ceC2au4eGPLMDItPjceXe8I6zgB5P8/U5U3PRw5oWabpAf5lAcRwa12c
61
+ 23xgy9O5QNlyps/rAdnVjwxqGwEd5E2LrZ2+JDflPRGunx2VO5v9CxXvsxu9F3Rj
62
+ tREtebHe2H7u5jNsIQArnRI=
63
+ -----END PRIVATE KEY-----
64
+ Certificate:
65
+ Data:
66
+ Version: 3 (0x2)
67
+ Serial Number: 16717980999635 (0xf3475519fd3)
68
+ Signature Algorithm: sha256WithRSAEncryption
69
+ Issuer:
70
+ countryName = NN
71
+ organizationName = Edel Curl Arctic Illudium Research Cloud
72
+ commonName = Northern Nowhere Trust Anchor
73
+ Validity
74
+ Not Before: Dec 23 12:21:39 2022 GMT
75
+ Not After : Mar 11 12:21:39 2031 GMT
76
+ Subject:
77
+ countryName = NN
78
+ organizationName = Edel Curl Arctic Illudium Research Cloud
79
+ commonName = localhost
80
+ Subject Public Key Info:
81
+ Public Key Algorithm: rsaEncryption
82
+ Public-Key: (2048 bit)
83
+ Modulus:
84
+ 00:ab:0a:b0:03:d0:76:fe:5e:ce:15:de:61:d5:e3:
85
+ 91:6f:7c:d6:bb:ca:26:8e:78:be:26:35:d1:a6:59:
86
+ f1:d5:3c:55:3e:09:2c:ec:a0:d4:af:0e:3c:5a:a2:
87
+ b5:b0:78:51:95:62:80:80:71:c8:4e:9f:59:59:93:
88
+ 40:12:b2:a9:ce:b2:cd:17:8b:9f:27:f3:e3:cf:23:
89
+ 78:06:d2:06:23:5f:9b:20:ec:42:77:66:ad:a4:5e:
90
+ 82:b4:4d:94:72:ea:13:64:72:fc:cb:83:2c:d7:a1:
91
+ 8b:f5:2e:4c:d3:c1:88:b2:c8:98:19:5f:ef:98:fc:
92
+ 62:80:b3:67:cc:1f:23:fc:5f:38:cd:82:6e:2d:96:
93
+ d9:35:93:fe:29:a2:69:65:c0:df:45:ab:3f:ac:17:
94
+ 18:00:80:4a:b7:c9:ba:b8:5f:29:bb:c4:ac:16:97:
95
+ cc:57:34:10:c9:36:65:6c:3e:d8:89:45:c8:a5:42:
96
+ 84:7c:5e:cd:1a:e8:f1:3e:55:b3:21:0f:d0:36:13:
97
+ f2:c4:2f:b9:73:41:fa:87:aa:dc:44:d6:64:96:e4:
98
+ 5a:50:f9:4a:9f:e0:a2:e7:69:f4:ad:5a:cf:3a:20:
99
+ e5:a7:09:e2:cf:e8:19:a1:00:ae:a8:bb:22:02:34:
100
+ 5c:b3:cf:b5:24:4c:76:bf:ad:e9:f1:b8:d3:86:ba:
101
+ 7d:93
102
+ Exponent: 65537 (0x10001)
103
+ X509v3 extensions:
104
+ X509v3 Subject Alternative Name:
105
+ DNS:localhost
106
+ X509v3 Key Usage:
107
+ Digital Signature, Key Encipherment, Key Agreement
108
+ X509v3 Extended Key Usage:
109
+ TLS Web Server Authentication
110
+ X509v3 Subject Key Identifier:
111
+ 9C:97:B0:3D:B3:50:B1:F6:D4:71:E2:EB:CB:80:EA:93:7C:98:CC:72
112
+ X509v3 Authority Key Identifier:
113
+ 87:CB:B1:33:2E:C1:67:7E:71:E3:E5:2B:4C:4D:A4:B3:6E:D2:5B:A9
114
+ X509v3 Basic Constraints:
115
+ CA:FALSE
116
+ Authority Information Access:
117
+ CA Issuers - URI:http://test.curl.se/ca/EdelCurlRoot.cer
118
+ X509v3 CRL Distribution Points:
119
+ Full Name:
120
+ URI:http://test.curl.se/ca/EdelCurlRoot.crl
121
+ Signature Algorithm: sha256WithRSAEncryption
122
+ Signature Value:
123
+ 0b:8a:ed:6a:87:fa:71:15:88:25:58:85:1b:4a:09:bf:43:00:
124
+ 35:93:78:0d:72:14:30:51:e2:93:83:a1:da:1b:2f:a9:31:ae:
125
+ b7:c7:4c:72:c2:5e:32:24:f1:96:93:70:d5:3f:b5:85:80:13:
126
+ 75:32:cf:0e:f8:5d:c4:a2:29:84:43:2c:75:81:26:12:6a:a0:
127
+ cb:7b:57:c1:92:78:85:08:fa:64:50:c2:7b:83:02:4d:79:13:
128
+ bc:61:64:4d:b8:6b:d5:f1:84:6b:12:5c:69:90:ad:40:47:c0:
129
+ ed:dd:ea:8a:66:7e:87:85:19:aa:89:d3:3c:08:72:08:a1:4d:
130
+ 63:60:5b:9b:17:9e:00:12:a1:00:52:ca:78:01:88:18:c7:ed:
131
+ 5b:c7:e4:d9:eb:bd:3f:af:92:53:3f:fe:58:57:0d:fc:f4:7b:
132
+ 7b:a2:4f:e9:b9:5c:b5:a4:52:50:b4:56:5a:44:8e:d9:d0:ed:
133
+ de:8f:7e:ac:1c:58:76:5b:a8:79:c9:95:ab:85:1d:db:4c:13:
134
+ 82:4a:a5:41:1b:29:f5:d3:96:df:80:d1:1e:00:7d:ba:35:94:
135
+ 57:81:e1:08:2a:81:6b:1c:30:50:37:01:1a:0e:26:4f:6b:ed:
136
+ c9:50:17:37:2b:33:3f:68:fe:c6:f0:21:8c:e7:b2:79:55:f2:
137
+ 42:bd:2f:b0
138
+ -----BEGIN CERTIFICATE-----
139
+ MIIERDCCAyygAwIBAgIGDzR1UZ/TMA0GCSqGSIb3DQEBCwUAMGgxCzAJBgNVBAYT
140
+ Ak5OMTEwLwYDVQQKDChFZGVsIEN1cmwgQXJjdGljIElsbHVkaXVtIFJlc2VhcmNo
141
+ IENsb3VkMSYwJAYDVQQDDB1Ob3J0aGVybiBOb3doZXJlIFRydXN0IEFuY2hvcjAe
142
+ Fw0yMjEyMjMxMjIxMzlaFw0zMTAzMTExMjIxMzlaMFQxCzAJBgNVBAYTAk5OMTEw
143
+ LwYDVQQKDChFZGVsIEN1cmwgQXJjdGljIElsbHVkaXVtIFJlc2VhcmNoIENsb3Vk
144
+ MRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
145
+ AoIBAQCrCrAD0Hb+Xs4V3mHV45FvfNa7yiaOeL4mNdGmWfHVPFU+CSzsoNSvDjxa
146
+ orWweFGVYoCAcchOn1lZk0ASsqnOss0Xi58n8+PPI3gG0gYjX5sg7EJ3Zq2kXoK0
147
+ TZRy6hNkcvzLgyzXoYv1LkzTwYiyyJgZX++Y/GKAs2fMHyP8XzjNgm4tltk1k/4p
148
+ omllwN9Fqz+sFxgAgEq3ybq4Xym7xKwWl8xXNBDJNmVsPtiJRcilQoR8Xs0a6PE+
149
+ VbMhD9A2E/LEL7lzQfqHqtxE1mSW5FpQ+Uqf4KLnafStWs86IOWnCeLP6BmhAK6o
150
+ uyICNFyzz7UkTHa/renxuNOGun2TAgMBAAGjggEGMIIBAjAUBgNVHREEDTALggls
151
+ b2NhbGhvc3QwCwYDVR0PBAQDAgOoMBMGA1UdJQQMMAoGCCsGAQUFBwMBMB0GA1Ud
152
+ DgQWBBScl7A9s1Cx9tRx4uvLgOqTfJjMcjAfBgNVHSMEGDAWgBSHy7EzLsFnfnHj
153
+ 5StMTaSzbtJbqTAJBgNVHRMEAjAAMEMGCCsGAQUFBwEBBDcwNTAzBggrBgEFBQcw
154
+ AoYnaHR0cDovL3Rlc3QuY3VybC5zZS9jYS9FZGVsQ3VybFJvb3QuY2VyMDgGA1Ud
155
+ HwQxMC8wLaAroCmGJ2h0dHA6Ly90ZXN0LmN1cmwuc2UvY2EvRWRlbEN1cmxSb290
156
+ LmNybDANBgkqhkiG9w0BAQsFAAOCAQEAC4rtaof6cRWIJViFG0oJv0MANZN4DXIU
157
+ MFHik4Oh2hsvqTGut8dMcsJeMiTxlpNw1T+1hYATdTLPDvhdxKIphEMsdYEmEmqg
158
+ y3tXwZJ4hQj6ZFDCe4MCTXkTvGFkTbhr1fGEaxJcaZCtQEfA7d3qimZ+h4UZqonT
159
+ PAhyCKFNY2BbmxeeABKhAFLKeAGIGMftW8fk2eu9P6+SUz/+WFcN/PR7e6JP6blc
160
+ taRSULRWWkSO2dDt3o9+rBxYdluoecmVq4Ud20wTgkqlQRsp9dOW34DRHgB9ujWU
161
+ V4HhCCqBaxwwUDcBGg4mT2vtyVAXNyszP2j+xvAhjOeyeVXyQr0vsA==
162
+ -----END CERTIFICATE-----
local-test-curl-delta-01/afc-curl/tests/test1119.pl ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env perl
2
+ #***************************************************************************
3
+ # _ _ ____ _
4
+ # Project ___| | | | _ \| |
5
+ # / __| | | | |_) | |
6
+ # | (__| |_| | _ <| |___
7
+ # \___|\___/|_| \_\_____|
8
+ #
9
+ # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10
+ #
11
+ # This software is licensed as described in the file COPYING, which
12
+ # you should have received as part of this distribution. The terms
13
+ # are also available at https://curl.se/docs/copyright.html.
14
+ #
15
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ # copies of the Software, and permit persons to whom the Software is
17
+ # furnished to do so, under the terms of the COPYING file.
18
+ #
19
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ # KIND, either express or implied.
21
+ #
22
+ # SPDX-License-Identifier: curl
23
+ #
24
+ ###########################################################################
25
+ #
26
+ # This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
27
+ # a late evening in the #curl IRC channel.
28
+ #
29
+
30
+ use strict;
31
+ use warnings;
32
+ use vars qw($Cpreprocessor);
33
+
34
+ #
35
+ # configurehelp perl module is generated by configure script
36
+ #
37
+ my $rc = eval {
38
+ require configurehelp;
39
+ configurehelp->import(qw(
40
+ $Cpreprocessor
41
+ ));
42
+ 1;
43
+ };
44
+ # Set default values if configure has not generated a configurehelp.pm file.
45
+ # This is the case with cmake.
46
+ if (!$rc) {
47
+ $Cpreprocessor = 'cpp';
48
+ }
49
+
50
+ # we may get the dir root pointed out
51
+ my $root=$ARGV[0] || ".";
52
+
53
+ # need an include directory when building out-of-tree
54
+ my $i = ($ARGV[1]) ? "-I$ARGV[1] " : '';
55
+
56
+ my $verbose=0;
57
+ my $summary=0;
58
+ my $misses=0;
59
+
60
+ my @manrefs;
61
+ my @syms;
62
+ my %doc;
63
+ my %rem;
64
+
65
+ # scanenum runs the preprocessor on curl.h so it will process all enums
66
+ # included by it, which *should* be all headers
67
+ sub scanenum {
68
+ my ($file) = @_;
69
+ open my $h_in, "-|", "$Cpreprocessor $i$file" || die "Cannot preprocess $file";
70
+ while ( <$h_in> ) {
71
+ if ( /enum\s+(\S+\s+)?{/ .. /}/ ) {
72
+ s/^\s+//;
73
+ next unless /^CURL/;
74
+ chomp;
75
+ s/[,\s].*//;
76
+ push @syms, $_;
77
+ }
78
+ }
79
+ close $h_in || die "Error preprocessing $file";
80
+ }
81
+
82
+ sub scanheader {
83
+ my ($f)=@_;
84
+ open my $h, "<", "$f";
85
+ while(<$h>) {
86
+ if (/^#define ((LIB|)CURL[A-Za-z0-9_]*)/) {
87
+ push @syms, $1;
88
+ }
89
+ }
90
+ close $h;
91
+ }
92
+
93
+ sub scanallheaders {
94
+ my $d = "$root/include/curl";
95
+ opendir(my $dh, $d) ||
96
+ die "Can't opendir: $!";
97
+ my @headers = grep { /.h\z/ } readdir($dh);
98
+ closedir $dh;
99
+ foreach my $h (@headers) {
100
+ scanenum("$d/$h");
101
+ scanheader("$d/$h");
102
+ }
103
+ }
104
+
105
+ sub checkmanpage {
106
+ my ($m) = @_;
107
+
108
+ open(my $mh, "<", "$m");
109
+ my $line = 1;
110
+ while(<$mh>) {
111
+ # strip off formatting
112
+ $_ =~ s/(^|[^A-Z0-9])[*_]+/ /;
113
+ # detect global-looking 'CURL[BLABLA]_*' symbols
114
+ while(s/\W(CURL(AUTH|E|H|MOPT|OPT|SHOPT|UE|M|SSH|SSLBACKEND|HEADER|FORM|FTP|PIPE|MIMEOPT|GSSAPI|ALTSVC|PROTO|PROXY|UPART|USESSL|_READFUNC|_WRITEFUNC|_CSELECT|_FORMADD|_IPRESOLVE|_REDIR|_RTSPREQ|_TIMECOND|_VERSION)_[a-zA-Z0-9_]+)//) {
115
+ my $s = $1;
116
+ # skip two "special" ones
117
+ if($s !~ /^(CURLE_OBSOLETE|CURLOPT_TEMPLATE)/) {
118
+ push @manrefs, "$1:$m:$line";
119
+ }
120
+ }
121
+ $line++;
122
+ }
123
+ close($mh);
124
+ }
125
+
126
+ sub scanman_md_dir {
127
+ my ($d) = @_;
128
+ opendir(my $dh, $d) ||
129
+ die "Can't opendir: $!";
130
+ my @mans = grep { /.md\z/ } readdir($dh);
131
+ closedir $dh;
132
+ for my $m (@mans) {
133
+ checkmanpage("$d/$m");
134
+ }
135
+ }
136
+
137
+
138
+ scanallheaders();
139
+ scanman_md_dir("$root/docs/libcurl");
140
+ scanman_md_dir("$root/docs/libcurl/opts");
141
+
142
+ open my $s, "<", "$root/docs/libcurl/symbols-in-versions";
143
+ while(<$s>) {
144
+ if(/(^[^ \n]+) +(.*)/) {
145
+ my ($sym, $rest)=($1, $2);
146
+ if($doc{$sym}) {
147
+ print "Detected duplicate symbol: $sym\n";
148
+ $misses++;
149
+ next;
150
+ }
151
+ $doc{$sym}=$sym;
152
+ my @a=split(/ +/, $rest);
153
+ if($a[2]) {
154
+ # this symbol is documented to have been present the last time
155
+ # in this release
156
+ $rem{$sym}=$a[2];
157
+ }
158
+ }
159
+ }
160
+ close $s;
161
+
162
+ my $ignored=0;
163
+ for my $e (sort @syms) {
164
+ # OBSOLETE - names that are just placeholders for a position where we
165
+ # previously had a name, that is now removed. The OBSOLETE names should
166
+ # never be used for anything.
167
+ #
168
+ # CURL_EXTERN - is a define used for libcurl functions that are external,
169
+ # public. No app or other code should ever use it.
170
+ #
171
+ # CURLINC_ - defines for header dual-include prevention, ignore those.
172
+ #
173
+ # CURL_TEMP_ - are defined and *undefined* again within the file
174
+ #
175
+ # *_LAST and *_LASTENTRY are just prefix for the placeholders used for the
176
+ # last entry in many enum series.
177
+ #
178
+
179
+ if($e =~ /(OBSOLETE|^CURL_EXTERN|^CURLINC_|_LAST\z|_LASTENTRY\z|^CURL_TEMP_)/) {
180
+ $ignored++;
181
+ next;
182
+ }
183
+ if($doc{$e}) {
184
+ if($verbose) {
185
+ print $e."\n";
186
+ }
187
+ $doc{$e}="used";
188
+ next;
189
+ }
190
+ else {
191
+ print $e."\n";
192
+ $misses++;
193
+ }
194
+ }
195
+
196
+ #
197
+ # now scan through all symbols that were present in the symbols-in-versions
198
+ # but not in the headers
199
+ #
200
+ # If the symbols were marked 'removed' in symbols-in-versions we don't output
201
+ # anything about it since that is perfectly fine.
202
+ #
203
+
204
+ my $anyremoved;
205
+
206
+ for my $e (sort keys %doc) {
207
+ if(($doc{$e} ne "used") && !$rem{$e}) {
208
+
209
+ if(!$anyremoved++) {
210
+ print "Missing symbols mentioned in symbols-in-versions\n";
211
+ print "Add them to a header, or mark them as removed.\n";
212
+ }
213
+
214
+ print "$e\n";
215
+ $misses++;
216
+ }
217
+ }
218
+
219
+ my %warned;
220
+ for my $r (@manrefs) {
221
+ if($r =~ /^([^:]+):(.*)/) {
222
+ my ($sym, $file)=($1, $2);
223
+ if(!$doc{$sym} && !$warned{$sym, $file}) {
224
+ print "$file: $sym is not a public symbol\n";
225
+ $warned{$sym, $file} = 1;
226
+ }
227
+ }
228
+ }
229
+
230
+ if($summary) {
231
+ print "Summary:\n";
232
+ printf "%d symbols in headers (out of which %d are ignored)\n", scalar(@syms),
233
+ $ignored;
234
+ printf "%d symbols in headers are interesting\n",
235
+ scalar(@syms)- $ignored;
236
+ printf "%d symbols are listed in symbols-in-versions\n (out of which %d are listed as removed)\n", scalar(keys %doc), scalar(keys %rem);
237
+ printf "%d symbols in symbols-in-versions should match the ones in headers\n", scalar(keys %doc) - scalar(keys %rem);
238
+ }
239
+
240
+ if($misses) {
241
+ exit 0; # there are stuff to attend to!
242
+ }
243
+ else {
244
+ print "OK\n";
245
+ }