Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Commands/ABOR.pm

raw
1 package ProFTPD::Tests::Commands::ABOR;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Spec;
8 use IO::Handle;
9 use Socket;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :features :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 # NOTE: Net::FTP::abort() automatically does all of the following, in this
19 # order:
20 # - Sends TCP OOB marker
21 # - Sends ABOR command
22 # - Closes data connection
23 #
24 # Thus for testing other client behavior, where data EOF might occur before
25 # the ABOR command, or ABOR might be sent by itself without OOB, we use other
26 # custom functions.
27 #
28 # "ABOR only" tests will refer to sending _just_ the ABOR command; "data EOF"
29 # tests refer to only closing the data connections. And then we will have
30 # tests for data EOF before ABOR, not after.
31
32 my $TESTS = {
33 abor_retr_binary_ok => {
34 order => ++$order,
35 test_class => [qw(forking)],
36 },
37
38 abor_retr_ascii_ok => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 abor_retr_ascii_largefile_ok => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 abor_retr_ascii_largefile_followed_by_list_ok => {
49 order => ++$order,
50 test_class => [qw(forking)],
51 },
52
53 abor_retr_binary_largefile_followed_by_retr_ok => {
54 order => ++$order,
55 test_class => [qw(forking)],
56 },
57
58 abor_retr_binary_largefile_with_sendfile => {
59 order => ++$order,
60 test_class => [qw(feature_sendfile forking)],
61 },
62
63 abor_retr_binary_largefile_without_sendfile => {
64 order => ++$order,
65 test_class => [qw(forking)],
66 },
67
68 abor_stor_binary_ok => {
69 order => ++$order,
70 test_class => [qw(forking)],
71 },
72
73 abor_stor_ascii_ok => {
74 order => ++$order,
75 test_class => [qw(forking)],
76 },
77
78 abor_with_cyrillic_encoding_ok => {
79 order => ++$order,
80 test_class => [qw(feature_nls forking)],
81 },
82
83 abor_no_xfer_ok => {
84 order => ++$order,
85 test_class => [qw(forking)],
86 },
87
88 abor_list_ok => {
89 order => ++$order,
90 test_class => [qw(forking)],
91 },
92
93 abor_mlsd_ok => {
94 order => ++$order,
95 test_class => [qw(forking)],
96 },
97
98 abor_only_retr_ascii => {
99 order => ++$order,
100 test_class => [qw(forking)],
101 },
102
103 abor_only_retr_binary_with_sendfile => {
104 order => ++$order,
105 test_class => [qw(feature_sendfile forking)],
106 },
107
108 abor_only_retr_binary_without_sendfile => {
109 order => ++$order,
110 test_class => [qw(forking)],
111 },
112
113 abor_only_stor_ascii => {
114 order => ++$order,
115 test_class => [qw(forking)],
116 },
117
118 abor_only_stor_binary => {
119 order => ++$order,
120 test_class => [qw(forking)],
121 },
122
123 abor_only_list => {
124 order => ++$order,
125 test_class => [qw(forking)],
126 },
127
128 abor_only_mlsd => {
129 order => ++$order,
130 test_class => [qw(forking)],
131 },
132
133 abor_only_no_xfer => {
134 order => ++$order,
135 test_class => [qw(forking)],
136 },
137
138 data_eof_retr_ascii => {
139 order => ++$order,
140 test_class => [qw(forking)],
141 },
142
143 data_eof_retr_binary_with_sendfile => {
144 order => ++$order,
145 test_class => [qw(feature_sendfile forking)],
146 },
147
148 data_eof_retr_binary_without_sendfile => {
149 order => ++$order,
150 test_class => [qw(forking)],
151 },
152
153 data_eof_stor_ascii => {
154 order => ++$order,
155 test_class => [qw(forking)],
156 },
157
158 data_eof_stor_binary => {
159 order => ++$order,
160 test_class => [qw(forking)],
161 },
162
163 data_eof_list => {
164 order => ++$order,
165 test_class => [qw(forking)],
166 },
167
168 data_eof_mlsd => {
169 order => ++$order,
170 test_class => [qw(forking)],
171 },
172
173 data_eof_before_abor_retr_ascii => {
174 order => ++$order,
175 test_class => [qw(forking)],
176 },
177
178 data_eof_before_abor_retr_binary_with_sendfile => {
179 order => ++$order,
180 test_class => [qw(feature_sendfile forking)],
181 },
182
183 data_eof_before_abor_retr_binary_without_sendfile => {
184 order => ++$order,
185 test_class => [qw(forking)],
186 },
187
188 data_eof_before_abor_stor_ascii => {
189 order => ++$order,
190 test_class => [qw(forking)],
191 },
192
193 data_eof_before_abor_stor_binary => {
194 order => ++$order,
195 test_class => [qw(forking)],
196 },
197
198 data_eof_before_abor_list => {
199 order => ++$order,
200 test_class => [qw(forking)],
201 },
202
203 data_eof_before_abor_mlsd => {
204 order => ++$order,
205 test_class => [qw(forking)],
206 },
207
208 };
209
210 sub new {
211 return shift()->SUPER::new(@_);
212 }
213
214 sub list_tests {
215 return testsuite_get_runnable_tests($TESTS);
216 }
217
218 sub abor_retr_binary_ok {
219 my $self = shift;
220 my $tmpdir = $self->{tmpdir};
221 my $setup = test_setup($tmpdir, 'abor');
222
223 my $test_file = File::Spec->rel2abs($setup->{config_file});
224
225 my $config = {
226 PidFile => $setup->{pid_file},
227 ScoreboardFile => $setup->{scoreboard_file},
228 SystemLog => $setup->{log_file},
229 TraceLog => $setup->{log_file},
230 Trace => 'DEFAULT:10',
231
232 AuthUserFile => $setup->{auth_user_file},
233 AuthGroupFile => $setup->{auth_group_file},
234 AuthOrder => 'mod_auth_file.c',
235
236 TimeoutLinger => 5,
237
238 IfModules => {
239 'mod_delay.c' => {
240 DelayEngine => 'off',
241 },
242 },
243 };
244
245 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
246 $config);
247
248 # Open pipes, for use between the parent and child processes. Specifically,
249 # the child will indicate when it's done with its test by writing a message
250 # to the parent.
251 my ($rfh, $wfh);
252 unless (pipe($rfh, $wfh)) {
253 die("Can't open pipe: $!");
254 }
255
256 my $ex;
257
258 # Fork child
259 $self->handle_sigchld();
260 defined(my $pid = fork()) or die("Can't fork: $!");
261 if ($pid) {
262 eval {
263 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
264 $client->login($setup->{user}, $setup->{passwd});
265 $client->pasv();
266 $client->type('binary');
267
268 my $conn = $client->retr_raw($test_file);
269 unless ($conn) {
270 die("Failed to RETR: " . $client->response_code() . " " .
271 $client->response_msg());
272 }
273
274 # Read 128 bytes of the file, then abort the download
275 my $buf;
276 $conn->read($buf, 128, 30);
277 eval { $conn->abort() };
278
279 my $resp_code = $client->response_code();
280 my $resp_msg = $client->response_msg();
281 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
282
283 # Make sure the control connection did not close because of the abort.
284 ($resp_code, $resp_msg) = $client->quit();
285
286 my $expected = 221;
287 $self->assert($expected == $resp_code,
288 test_msg("Expected response code $expected, got $resp_code"));
289
290 $expected = 'Goodbye.';
291 $self->assert($expected eq $resp_msg,
292 test_msg("Expected response message '$expected', got '$resp_msg'"));
293 };
294 if ($@) {
295 $ex = $@;
296 }
297
298 $wfh->print("done\n");
299 $wfh->flush();
300
301 } else {
302 eval { server_wait($setup->{config_file}, $rfh) };
303 if ($@) {
304 warn($@);
305 exit 1;
306 }
307
308 exit 0;
309 }
310
311 # Stop server
312 server_stop($setup->{pid_file});
313 $self->assert_child_ok($pid);
314
315 test_cleanup($setup->{log_file}, $ex);
316 }
317
318 sub abor_retr_ascii_ok {
319 my $self = shift;
320 my $tmpdir = $self->{tmpdir};
321 my $setup = test_setup($tmpdir, 'abor');
322
323 my $test_file = File::Spec->rel2abs($setup->{config_file});
324
325 my $config = {
326 PidFile => $setup->{pid_file},
327 ScoreboardFile => $setup->{scoreboard_file},
328 SystemLog => $setup->{log_file},
329 TraceLog => $setup->{log_file},
330 Trace => 'DEFAULT:10',
331
332 AuthUserFile => $setup->{auth_user_file},
333 AuthGroupFile => $setup->{auth_group_file},
334 AuthOrder => 'mod_auth_file.c',
335
336 TimeoutLinger => 5,
337
338 IfModules => {
339 'mod_delay.c' => {
340 DelayEngine => 'off',
341 },
342 },
343 };
344
345 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
346 $config);
347
348 # Open pipes, for use between the parent and child processes. Specifically,
349 # the child will indicate when it's done with its test by writing a message
350 # to the parent.
351 my ($rfh, $wfh);
352 unless (pipe($rfh, $wfh)) {
353 die("Can't open pipe: $!");
354 }
355
356 my $ex;
357
358 # Fork child
359 $self->handle_sigchld();
360 defined(my $pid = fork()) or die("Can't fork: $!");
361 if ($pid) {
362 eval {
363 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
364 $client->login($setup->{user}, $setup->{passwd});
365 $client->pasv();
366 $client->type('ascii');
367
368 my $conn = $client->retr_raw($test_file);
369 unless ($conn) {
370 die("Failed to RETR: " . $client->response_code() . " " .
371 $client->response_msg());
372 }
373
374 # Read 128 bytes of the file, then abort the download
375 my $buf;
376 $conn->read($buf, 128, 30);
377 eval { $conn->abort() };
378
379 my $resp_code = $client->response_code();
380 my $resp_msg = $client->response_msg();
381 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
382
383 # Make sure the control connection did not close because of the abort.
384 ($resp_code, $resp_msg) = $client->quit();
385
386 my $expected = 221;
387 $self->assert($expected == $resp_code,
388 test_msg("Expected response code $expected, got $resp_code"));
389
390 $expected = 'Goodbye.';
391 $self->assert($expected eq $resp_msg,
392 test_msg("Expected response message '$expected', got '$resp_msg'"));
393 };
394 if ($@) {
395 $ex = $@;
396 }
397
398 $wfh->print("done\n");
399 $wfh->flush();
400
401 } else {
402 eval { server_wait($setup->{config_file}, $rfh) };
403 if ($@) {
404 warn($@);
405 exit 1;
406 }
407
408 exit 0;
409 }
410
411 # Stop server
412 server_stop($setup->{pid_file});
413 $self->assert_child_ok($pid);
414
415 test_cleanup($setup->{log_file}, $ex);
416 }
417
418 sub abor_retr_ascii_largefile_ok {
419 my $self = shift;
420 my $tmpdir = $self->{tmpdir};
421 my $setup = test_setup($tmpdir, 'abor');
422
423 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
424 if (open(my $fh, "> $test_file")) {
425 print $fh "ABCDEFG\n" x 40960;
426
427 unless (close($fh)) {
428 die("Can't write $test_file: $!");
429 }
430
431 } else {
432 die("Can't open $test_file: $!");
433 }
434
435 my $config = {
436 PidFile => $setup->{pid_file},
437 ScoreboardFile => $setup->{scoreboard_file},
438 SystemLog => $setup->{log_file},
439 TraceLog => $setup->{log_file},
440 Trace => 'DEFAULT:10',
441
442 AuthUserFile => $setup->{auth_user_file},
443 AuthGroupFile => $setup->{auth_group_file},
444 AuthOrder => 'mod_auth_file.c',
445
446 TimeoutLinger => 5,
447
448 IfModules => {
449 'mod_delay.c' => {
450 DelayEngine => 'off',
451 },
452 },
453 };
454
455 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
456 $config);
457
458 # Open pipes, for use between the parent and child processes. Specifically,
459 # the child will indicate when it's done with its test by writing a message
460 # to the parent.
461 my ($rfh, $wfh);
462 unless (pipe($rfh, $wfh)) {
463 die("Can't open pipe: $!");
464 }
465
466 my $ex;
467
468 # Fork child
469 $self->handle_sigchld();
470 defined(my $pid = fork()) or die("Can't fork: $!");
471 if ($pid) {
472 eval {
473 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
474 $client->login($setup->{user}, $setup->{passwd});
475 $client->pasv();
476 $client->type('ascii');
477
478 my $conn = $client->retr_raw($test_file);
479 unless ($conn) {
480 die("Failed to RETR: " . $client->response_code() . " " .
481 $client->response_msg());
482 }
483
484 # Read 128 bytes of the file, then abort the download
485 my $buf;
486 $conn->read($buf, 128, 30);
487 eval { $conn->abort() };
488
489 my $resp_code = $client->response_code();
490 my $resp_msg = $client->response_msg();
491 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
492
493 # We expect 2 responses here: first, a 426 for the aborted data transfer,
494 # followed by 226 for the successful ABOR command. Order matters.
495 my $resp_msgs = $client->response_msgs();
496
497 my $resp_nmsgs = scalar(@$resp_msgs);
498 $self->assert($resp_nmsgs == 2,
499 test_msg("Expected 2 responses, got $resp_nmsgs"));
500
501 my $expected = 'Transfer aborted. Data connection closed.';
502 $self->assert($expected eq $resp_msgs->[0],
503 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
504
505 $expected = 'Abort successful';
506 $self->assert($expected eq $resp_msgs->[1],
507 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
508
509 # Make sure the control connection did not close because of the abort.
510 ($resp_code, $resp_msg) = $client->quit();
511
512 $expected = 221;
513 $self->assert($expected == $resp_code,
514 test_msg("Expected response code $expected, got $resp_code"));
515
516 $expected = 'Goodbye.';
517 $self->assert($expected eq $resp_msg,
518 test_msg("Expected response message '$expected', got '$resp_msg'"));
519 };
520 if ($@) {
521 $ex = $@;
522 }
523
524 $wfh->print("done\n");
525 $wfh->flush();
526
527 } else {
528 eval { server_wait($setup->{config_file}, $rfh) };
529 if ($@) {
530 warn($@);
531 exit 1;
532 }
533
534 exit 0;
535 }
536
537 # Stop server
538 server_stop($setup->{pid_file});
539 $self->assert_child_ok($pid);
540
541 test_cleanup($setup->{log_file}, $ex);
542 }
543
544 sub abor_retr_ascii_largefile_followed_by_list_ok {
545 my $self = shift;
546 my $tmpdir = $self->{tmpdir};
547 my $setup = test_setup($tmpdir, 'abor');
548
549 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
550 if (open(my $fh, "> $test_file")) {
551 print $fh "ABCDEFG\n" x 4096;
552
553 unless (close($fh)) {
554 die("Can't write $test_file: $!");
555 }
556
557 } else {
558 die("Can't open $test_file: $!");
559 }
560
561 my $config = {
562 PidFile => $setup->{pid_file},
563 ScoreboardFile => $setup->{scoreboard_file},
564 SystemLog => $setup->{log_file},
565 TraceLog => $setup->{log_file},
566 Trace => 'DEFAULT:10',
567
568 AuthUserFile => $setup->{auth_user_file},
569 AuthGroupFile => $setup->{auth_group_file},
570 AuthOrder => 'mod_auth_file.c',
571
572 TimeoutLinger => 5,
573
574 IfModules => {
575 'mod_delay.c' => {
576 DelayEngine => 'off',
577 },
578 },
579 };
580
581 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
582 $config);
583
584 # Open pipes, for use between the parent and child processes. Specifically,
585 # the child will indicate when it's done with its test by writing a message
586 # to the parent.
587 my ($rfh, $wfh);
588 unless (pipe($rfh, $wfh)) {
589 die("Can't open pipe: $!");
590 }
591
592 my $ex;
593
594 # Fork child
595 $self->handle_sigchld();
596 defined(my $pid = fork()) or die("Can't fork: $!");
597 if ($pid) {
598 eval {
599 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
600 $client->login($setup->{user}, $setup->{passwd});
601 $client->pasv();
602 $client->type('ascii');
603
604 my $conn = $client->retr_raw($test_file);
605 unless ($conn) {
606 die("Failed to RETR: " . $client->response_code() . " " .
607 $client->response_msg());
608 }
609
610 # Read 128 bytes of the file, then abort the download
611 my $buf;
612 $conn->read($buf, 128, 30);
613 eval { $conn->abort() };
614
615 my $resp_code = $client->response_code();
616 my $resp_msg = $client->response_msg();
617 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
618
619 # Make sure we can do another data transfer after the abort
620 $conn = $client->list_raw();
621 unless ($conn) {
622 die("Failed to LIST: " . $client->response_code() . " " .
623 $client->response_msg());
624 }
625
626 $buf = '';
627 my $info;
628 while ($conn->read($info, 8192, 30)) {
629 $buf .= $info;
630 }
631
632 eval { $conn->close() };
633
634 # We have to be careful of the fact that readdir returns directory
635 # entries in an unordered fashion.
636 my $res = {};
637 my $lines = [split(/\n/, $buf)];
638 foreach my $line (@$lines) {
639 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
640 $res->{$1} = 1;
641 }
642 }
643
644 my $expected = {
645 'abor.conf' => 1,
646 'abor.group' => 1,
647 'abor.passwd' => 1,
648 'abor.pid' => 1,
649 'abor.scoreboard' => 1,
650 'abor.scoreboard.lck' => 1,
651 'largefile.txt' => 1,
652 };
653
654 my $ok = 1;
655 my $mismatch;
656 foreach my $name (keys(%$res)) {
657 unless (defined($expected->{$name})) {
658 $mismatch = $name;
659 $ok = 0;
660 last;
661 }
662 }
663
664 unless ($ok) {
665 die("Unexpected name '$mismatch' appeared in LIST data")
666 }
667
668 # Make sure the control connection did not close because of the abort.
669 ($resp_code, $resp_msg) = $client->quit();
670
671 $expected = 221;
672 $self->assert($expected == $resp_code,
673 test_msg("Expected response code $expected, got $resp_code"));
674
675 $expected = 'Goodbye.';
676 $self->assert($expected eq $resp_msg,
677 test_msg("Expected response message '$expected', got '$resp_msg'"));
678 };
679 if ($@) {
680 $ex = $@;
681 }
682
683 $wfh->print("done\n");
684 $wfh->flush();
685
686 } else {
687 eval { server_wait($setup->{config_file}, $rfh) };
688 if ($@) {
689 warn($@);
690 exit 1;
691 }
692
693 exit 0;
694 }
695
696 # Stop server
697 server_stop($setup->{pid_file});
698 $self->assert_child_ok($pid);
699
700 test_cleanup($setup->{log_file}, $ex);
701 }
702
703 sub abor_retr_binary_largefile_followed_by_retr_ok {
704 my $self = shift;
705 my $tmpdir = $self->{tmpdir};
706 my $setup = test_setup($tmpdir, 'abor');
707
708 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
709 if (open(my $fh, "> $test_file")) {
710 print $fh "ABCDEFG\n" x 16384;
711
712 unless (close($fh)) {
713 die("Can't write $test_file: $!");
714 }
715
716 } else {
717 die("Can't open $test_file: $!");
718 }
719
720 my $test_filesz = -s $test_file;
721
722 my $config = {
723 PidFile => $setup->{pid_file},
724 ScoreboardFile => $setup->{scoreboard_file},
725 SystemLog => $setup->{log_file},
726 TraceLog => $setup->{log_file},
727 Trace => 'DEFAULT:10',
728
729 AuthUserFile => $setup->{auth_user_file},
730 AuthGroupFile => $setup->{auth_group_file},
731 AuthOrder => 'mod_auth_file.c',
732
733 TimeoutLinger => 1,
734 TimeoutIdle => 15,
735 UseSendfile => 'off',
736
737 IfModules => {
738 'mod_delay.c' => {
739 DelayEngine => 'off',
740 },
741 },
742 };
743
744 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
745 $config);
746
747 # Open pipes, for use between the parent and child processes. Specifically,
748 # the child will indicate when it's done with its test by writing a message
749 # to the parent.
750 my ($rfh, $wfh);
751 unless (pipe($rfh, $wfh)) {
752 die("Can't open pipe: $!");
753 }
754
755 my $ex;
756
757 # Fork child
758 $self->handle_sigchld();
759 defined(my $pid = fork()) or die("Can't fork: $!");
760 if ($pid) {
761 eval {
762 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
763 $client->login($setup->{user}, $setup->{passwd});
764 $client->pasv();
765 $client->type('binary');
766
767 my $conn = $client->retr_raw($test_file);
768 unless ($conn) {
769 die("Failed to RETR: " . $client->response_code() . " " .
770 $client->response_msg());
771 }
772
773 my $buf;
774 my $count = 0;
775 while ($count != $test_filesz) {
776 $count += $conn->read($buf, 8192, 30);
777
778 if ($count > ($test_filesz - 8192)) {
779 eval { $conn->abort() };
780 last;
781 }
782 }
783
784 my $resp_code = $client->response_code();
785 my $resp_msg = $client->response_msg();
786 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
787
788 # Make sure we can do another data transfer (this time, a RETR) after
789 # the abort
790
791 $client->pasv();
792 $client->type('binary');
793 $conn = $client->retr_raw($test_file);
794 unless ($conn) {
795 die("Failed to RETR: " . $client->response_code() . " " .
796 $client->response_msg());
797 }
798
799 while ($conn->read($buf, 8192, 30)) {
800 }
801
802 eval { $conn->close() };
803
804 $resp_code = $client->response_code();
805 $resp_msg = $client->response_msg();
806 $self->assert_transfer_ok($resp_code, $resp_msg);
807
808 # Make sure the control connection did not close because of the abort.
809 ($resp_code, $resp_msg) = $client->quit();
810
811 my $expected = 221;
812 $self->assert($expected == $resp_code,
813 test_msg("Expected response code $expected, got $resp_code"));
814
815 $expected = 'Goodbye.';
816 $self->assert($expected eq $resp_msg,
817 test_msg("Expected response message '$expected', got '$resp_msg'"));
818 };
819 if ($@) {
820 $ex = $@;
821 }
822
823 $wfh->print("done\n");
824 $wfh->flush();
825
826 } else {
827 eval { server_wait($setup->{config_file}, $rfh) };
828 if ($@) {
829 warn($@);
830 exit 1;
831 }
832
833 exit 0;
834 }
835
836 # Stop server
837 server_stop($setup->{pid_file});
838 $self->assert_child_ok($pid);
839
840 test_cleanup($setup->{log_file}, $ex);
841 }
842
843 sub abor_retr_binary_largefile_with_sendfile {
844 my $self = shift;
845 my $tmpdir = $self->{tmpdir};
846 my $setup = test_setup($tmpdir, 'abor');
847
848 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
849 if (open(my $fh, "> $test_file")) {
850 print $fh "ABCDEFG\n" x 40960;
851
852 unless (close($fh)) {
853 die("Can't write $test_file: $!");
854 }
855
856 } else {
857 die("Can't open $test_file: $!");
858 }
859
860 my $config = {
861 PidFile => $setup->{pid_file},
862 ScoreboardFile => $setup->{scoreboard_file},
863 SystemLog => $setup->{log_file},
864 TraceLog => $setup->{log_file},
865 Trace => 'DEFAULT:10',
866
867 AuthUserFile => $setup->{auth_user_file},
868 AuthGroupFile => $setup->{auth_group_file},
869 AuthOrder => 'mod_auth_file.c',
870
871 TimeoutLinger => 5,
872
873 IfModules => {
874 'mod_delay.c' => {
875 DelayEngine => 'off',
876 },
877 },
878 };
879
880 if (feature_have_feature_enabled('sendfile')) {
881 $config->{UseSendfile} = 'on';
882 }
883
884 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
885 $config);
886
887 # Open pipes, for use between the parent and child processes. Specifically,
888 # the child will indicate when it's done with its test by writing a message
889 # to the parent.
890 my ($rfh, $wfh);
891 unless (pipe($rfh, $wfh)) {
892 die("Can't open pipe: $!");
893 }
894
895 my $ex;
896
897 # Fork child
898 $self->handle_sigchld();
899 defined(my $pid = fork()) or die("Can't fork: $!");
900 if ($pid) {
901 eval {
902 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
903 $client->login($setup->{user}, $setup->{passwd});
904 $client->pasv();
905 $client->type('binary');
906
907 my $conn = $client->retr_raw($test_file);
908 unless ($conn) {
909 die("Failed to RETR: " . $client->response_code() . " " .
910 $client->response_msg());
911 }
912
913 # Read 128 bytes of the file, then abort the download
914 my $buf;
915 $conn->read($buf, 128, 30);
916 eval { $conn->abort() };
917
918 my $resp_code = $client->response_code();
919 my $resp_msg = $client->response_msg();
920 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
921
922 # We expect 2 responses here: first, a 426 for the aborted data transfer,
923 # followed by 226 for the successful ABOR command. Order matters.
924 my $resp_msgs = $client->response_msgs();
925
926 my $resp_nmsgs = scalar(@$resp_msgs);
927 $self->assert($resp_nmsgs == 2,
928 test_msg("Expected 2 responses, got $resp_nmsgs"));
929
930 my $expected = 'Transfer aborted. Data connection closed.';
931 $self->assert($expected eq $resp_msgs->[0],
932 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
933
934 $expected = 'Abort successful';
935 $self->assert($expected eq $resp_msgs->[1],
936 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
937
938 # Make sure the control connection did not close because of the abort.
939 ($resp_code, $resp_msg) = $client->quit();
940
941 $expected = 221;
942 $self->assert($expected == $resp_code,
943 test_msg("Expected response code $expected, got $resp_code"));
944
945 $expected = 'Goodbye.';
946 $self->assert($expected eq $resp_msg,
947 test_msg("Expected response message '$expected', got '$resp_msg'"));
948 };
949 if ($@) {
950 $ex = $@;
951 }
952
953 $wfh->print("done\n");
954 $wfh->flush();
955
956 } else {
957 eval { server_wait($setup->{config_file}, $rfh) };
958 if ($@) {
959 warn($@);
960 exit 1;
961 }
962
963 exit 0;
964 }
965
966 # Stop server
967 server_stop($setup->{pid_file});
968 $self->assert_child_ok($pid);
969
970 test_cleanup($setup->{log_file}, $ex);
971 }
972
973 sub abor_retr_binary_largefile_without_sendfile {
974 my $self = shift;
975 my $tmpdir = $self->{tmpdir};
976 my $setup = test_setup($tmpdir, 'abor');
977
978 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
979 if (open(my $fh, "> $test_file")) {
980 print $fh "ABCDEFG\n" x 40960;
981
982 unless (close($fh)) {
983 die("Can't write $test_file: $!");
984 }
985
986 } else {
987 die("Can't open $test_file: $!");
988 }
989
990 my $config = {
991 PidFile => $setup->{pid_file},
992 ScoreboardFile => $setup->{scoreboard_file},
993 SystemLog => $setup->{log_file},
994 TraceLog => $setup->{log_file},
995 Trace => 'DEFAULT:10',
996
997 AuthUserFile => $setup->{auth_user_file},
998 AuthGroupFile => $setup->{auth_group_file},
999 AuthOrder => 'mod_auth_file.c',
1000
1001 TimeoutLinger => 5,
1002 UseSendfile => 'off',
1003
1004 IfModules => {
1005 'mod_delay.c' => {
1006 DelayEngine => 'off',
1007 },
1008 },
1009 };
1010
1011 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1012 $config);
1013
1014 # Open pipes, for use between the parent and child processes. Specifically,
1015 # the child will indicate when it's done with its test by writing a message
1016 # to the parent.
1017 my ($rfh, $wfh);
1018 unless (pipe($rfh, $wfh)) {
1019 die("Can't open pipe: $!");
1020 }
1021
1022 my $ex;
1023
1024 # Fork child
1025 $self->handle_sigchld();
1026 defined(my $pid = fork()) or die("Can't fork: $!");
1027 if ($pid) {
1028 eval {
1029 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1030 $client->login($setup->{user}, $setup->{passwd});
1031 $client->pasv();
1032 $client->type('binary');
1033
1034 my $conn = $client->retr_raw($test_file);
1035 unless ($conn) {
1036 die("Failed to RETR: " . $client->response_code() . " " .
1037 $client->response_msg());
1038 }
1039
1040 # Read 128 bytes of the file, then abort the download
1041 my $buf;
1042 $conn->read($buf, 128, 30);
1043 eval { $conn->abort() };
1044
1045 my $resp_code = $client->response_code();
1046 my $resp_msg = $client->response_msg();
1047 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
1048
1049 # We expect 2 responses here: first, a 426 for the aborted data transfer,
1050 # followed by 226 for the successful ABOR command. Order matters.
1051 my $resp_msgs = $client->response_msgs();
1052
1053 my $resp_nmsgs = scalar(@$resp_msgs);
1054 $self->assert($resp_nmsgs == 2,
1055 test_msg("Expected 2 responses, got $resp_nmsgs"));
1056
1057 my $expected = 'Transfer aborted. Data connection closed.';
1058 $self->assert($expected eq $resp_msgs->[0],
1059 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
1060
1061 $expected = 'Abort successful';
1062 $self->assert($expected eq $resp_msgs->[1],
1063 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
1064
1065 # Make sure the control connection did not close because of the abort.
1066 ($resp_code, $resp_msg) = $client->quit();
1067
1068 $expected = 221;
1069 $self->assert($expected == $resp_code,
1070 test_msg("Expected response code $expected, got $resp_code"));
1071
1072 $expected = 'Goodbye.';
1073 $self->assert($expected eq $resp_msg,
1074 test_msg("Expected response message '$expected', got '$resp_msg'"));
1075 };
1076 if ($@) {
1077 $ex = $@;
1078 }
1079
1080 $wfh->print("done\n");
1081 $wfh->flush();
1082
1083 } else {
1084 eval { server_wait($setup->{config_file}, $rfh) };
1085 if ($@) {
1086 warn($@);
1087 exit 1;
1088 }
1089
1090 exit 0;
1091 }
1092
1093 # Stop server
1094 server_stop($setup->{pid_file});
1095 $self->assert_child_ok($pid);
1096
1097 test_cleanup($setup->{log_file}, $ex);
1098 }
1099
1100 sub abor_stor_binary_ok {
1101 my $self = shift;
1102 my $tmpdir = $self->{tmpdir};
1103 my $setup = test_setup($tmpdir, 'abor');
1104
1105 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
1106
1107 my $config = {
1108 PidFile => $setup->{pid_file},
1109 ScoreboardFile => $setup->{scoreboard_file},
1110 SystemLog => $setup->{log_file},
1111 TraceLog => $setup->{log_file},
1112 Trace => 'DEFAULT:10',
1113
1114 AuthUserFile => $setup->{auth_user_file},
1115 AuthGroupFile => $setup->{auth_group_file},
1116 AuthOrder => 'mod_auth_file.c',
1117
1118 TimeoutLinger => 5,
1119
1120 IfModules => {
1121 'mod_delay.c' => {
1122 DelayEngine => 'off',
1123 },
1124 },
1125 };
1126
1127 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1128 $config);
1129
1130 # Open pipes, for use between the parent and child processes. Specifically,
1131 # the child will indicate when it's done with its test by writing a message
1132 # to the parent.
1133 my ($rfh, $wfh);
1134 unless (pipe($rfh, $wfh)) {
1135 die("Can't open pipe: $!");
1136 }
1137
1138 my $ex;
1139
1140 # Fork child
1141 $self->handle_sigchld();
1142 defined(my $pid = fork()) or die("Can't fork: $!");
1143 if ($pid) {
1144 eval {
1145 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1146 $client->login($setup->{user}, $setup->{passwd});
1147 $client->pasv();
1148 $client->type('binary');
1149
1150 my $conn = $client->stor_raw($test_file);
1151 unless ($conn) {
1152 die("Failed to STOR: " . $client->response_code() . " " .
1153 $client->response_msg());
1154 }
1155
1156 # Write data to the file, then abort the upload
1157 my $buf = "A\r\nB\r\nC\r\nD\r\n";
1158 $conn->write($buf, length($buf));
1159 eval { $conn->abort() };
1160
1161 my $resp_code = $client->response_code();
1162 my $resp_msg = $client->response_msg();
1163 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
1164
1165 # We expect 2 responses here: first, a 426 for the aborted data transfer,
1166 # followed by 226 for the successful ABOR command. Order matters.
1167 my $resp_msgs = $client->response_msgs();
1168
1169 my $resp_nmsgs = scalar(@$resp_msgs);
1170 $self->assert($resp_nmsgs == 2,
1171 test_msg("Expected 2 responses, got $resp_nmsgs"));
1172
1173 my $expected = 'Transfer aborted. Data connection closed.';
1174 $self->assert($expected eq $resp_msgs->[0],
1175 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
1176
1177 $expected = 'Abort successful';
1178 $self->assert($expected eq $resp_msgs->[1],
1179 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
1180
1181 # Make sure the control connection did not close because of the abort.
1182 ($resp_code, $resp_msg) = $client->quit();
1183
1184 $expected = 221;
1185 $self->assert($expected == $resp_code,
1186 test_msg("Expected response message $expected, got $resp_code"));
1187
1188 $expected = 'Goodbye.';
1189 $self->assert($expected eq $resp_msg,
1190 test_msg("Expected response message '$expected', got '$resp_msg'"));
1191 };
1192 if ($@) {
1193 $ex = $@;
1194 }
1195
1196 $wfh->print("done\n");
1197 $wfh->flush();
1198
1199 } else {
1200 eval { server_wait($setup->{config_file}, $rfh) };
1201 if ($@) {
1202 warn($@);
1203 exit 1;
1204 }
1205
1206 exit 0;
1207 }
1208
1209 # Stop server
1210 server_stop($setup->{pid_file});
1211 $self->assert_child_ok($pid);
1212
1213 test_cleanup($setup->{log_file}, $ex);
1214 }
1215
1216 sub abor_stor_ascii_ok {
1217 my $self = shift;
1218 my $tmpdir = $self->{tmpdir};
1219 my $setup = test_setup($tmpdir, 'abor');
1220
1221 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
1222
1223 my $config = {
1224 PidFile => $setup->{pid_file},
1225 ScoreboardFile => $setup->{scoreboard_file},
1226 SystemLog => $setup->{log_file},
1227 TraceLog => $setup->{log_file},
1228 Trace => 'DEFAULT:10',
1229
1230 AuthUserFile => $setup->{auth_user_file},
1231 AuthGroupFile => $setup->{auth_group_file},
1232 AuthOrder => 'mod_auth_file.c',
1233
1234 TimeoutLinger => 5,
1235
1236 IfModules => {
1237 'mod_delay.c' => {
1238 DelayEngine => 'off',
1239 },
1240 },
1241 };
1242
1243 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1244 $config);
1245
1246 # Open pipes, for use between the parent and child processes. Specifically,
1247 # the child will indicate when it's done with its test by writing a message
1248 # to the parent.
1249 my ($rfh, $wfh);
1250 unless (pipe($rfh, $wfh)) {
1251 die("Can't open pipe: $!");
1252 }
1253
1254 my $ex;
1255
1256 # Fork child
1257 $self->handle_sigchld();
1258 defined(my $pid = fork()) or die("Can't fork: $!");
1259 if ($pid) {
1260 eval {
1261 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1262 $client->login($setup->{user}, $setup->{passwd});
1263 $client->pasv();
1264 $client->type('ascii');
1265
1266 my $conn = $client->stor_raw($test_file);
1267 unless ($conn) {
1268 die("Failed to STOR: " . $client->response_code() . " " .
1269 $client->response_msg());
1270 }
1271
1272 # Write data to the file, then abort the upload
1273 my $buf = "A\r\nB\r\nC\r\nD\r\n";
1274 $conn->write($buf, length($buf));
1275 eval { $conn->abort() };
1276
1277 my $resp_code = $client->response_code();
1278 my $resp_msg = $client->response_msg();
1279 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
1280
1281 # We expect 2 responses here: first, a 426 for the aborted data transfer,
1282 # followed by 226 for the successful ABOR command. Order matters.
1283 my $resp_msgs = $client->response_msgs();
1284
1285 my $resp_nmsgs = scalar(@$resp_msgs);
1286 $self->assert($resp_nmsgs == 2,
1287 test_msg("Expected 2 responses, got $resp_nmsgs"));
1288
1289 my $expected = 'Transfer aborted. Data connection closed.';
1290 $self->assert($expected eq $resp_msgs->[0],
1291 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
1292
1293 $expected = 'Abort successful';
1294 $self->assert($expected eq $resp_msgs->[1],
1295 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
1296
1297 # Make sure the control connection did not close because of the abort.
1298 ($resp_code, $resp_msg) = $client->quit();
1299
1300 $expected = 221;
1301 $self->assert($expected == $resp_code,
1302 test_msg("Expected response message $expected, got $resp_code"));
1303
1304 $expected = 'Goodbye.';
1305 $self->assert($expected eq $resp_msg,
1306 test_msg("Expected response message '$expected', got '$resp_msg'"));
1307 };
1308 if ($@) {
1309 $ex = $@;
1310 }
1311
1312 $wfh->print("done\n");
1313 $wfh->flush();
1314
1315 } else {
1316 eval { server_wait($setup->{config_file}, $rfh) };
1317 if ($@) {
1318 warn($@);
1319 exit 1;
1320 }
1321
1322 exit 0;
1323 }
1324
1325 # Stop server
1326 server_stop($setup->{pid_file});
1327 $self->assert_child_ok($pid);
1328
1329 test_cleanup($setup->{log_file}, $ex);
1330 }
1331
1332 sub abor_with_cyrillic_encoding_ok {
1333 my $self = shift;
1334 my $tmpdir = $self->{tmpdir};
1335 my $setup = test_setup($tmpdir, 'abor');
1336
1337 my $test_file = File::Spec->rel2abs($setup->{config_file});
1338
1339 my $config = {
1340 PidFile => $setup->{pid_file},
1341 ScoreboardFile => $setup->{scoreboard_file},
1342 SystemLog => $setup->{log_file},
1343 TraceLog => $setup->{log_file},
1344 Trace => 'DEFAULT:10',
1345
1346 AuthUserFile => $setup->{auth_user_file},
1347 AuthGroupFile => $setup->{auth_group_file},
1348 AuthOrder => 'mod_auth_file.c',
1349
1350 TimeoutLinger => 15,
1351
1352 IfModules => {
1353 'mod_delay.c' => {
1354 DelayEngine => 'off',
1355 },
1356
1357 'mod_lang.c' => {
1358 UseEncoding => 'koi8-r cp1251',
1359 },
1360 },
1361 };
1362
1363 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1364 $config);
1365
1366 # Open pipes, for use between the parent and child processes. Specifically,
1367 # the child will indicate when it's done with its test by writing a message
1368 # to the parent.
1369 my ($rfh, $wfh);
1370 unless (pipe($rfh, $wfh)) {
1371 die("Can't open pipe: $!");
1372 }
1373
1374 my $ex;
1375
1376 # Fork child
1377 $self->handle_sigchld();
1378 defined(my $pid = fork()) or die("Can't fork: $!");
1379 if ($pid) {
1380 eval {
1381 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1382 $client->login($setup->{user}, $setup->{passwd});
1383 $client->pasv();
1384 $client->type('binary');
1385
1386 my $conn = $client->retr_raw($test_file);
1387 unless ($conn) {
1388 die("Failed to RETR: " . $client->response_code() . " " .
1389 $client->response_msg());
1390 }
1391
1392 # Read one byte of the file, then abort the download
1393 my $buf;
1394 $conn->read($buf, 1, 30);
1395 eval { $conn->abort() };
1396
1397 my $resp_code = $client->response_code();
1398 my $resp_msg = $client->response_msg();
1399
1400 my $expected;
1401
1402 # We expect the ABOR command to be misunderstood here, since it will
1403 # be prefaced by the Telnet IAC/IP, IAC/DM sequences. With Cyrillic
1404 # charsets, the Telnet sequences are not stripped out (since the values
1405 # collide with some of the Cyrillic charset values); this means that
1406 # rather than seeing an "ABOR" string, the server sees a string like
1407 # "<FF><F4><FF><F2>ABOR", which it clearly will not handle.
1408
1409 $expected = 500;
1410 $self->assert($expected == $resp_code,
1411 test_msg("Expected response code $expected, got $resp_code"));
1412
1413 $expected = 'ABOR not understood';
1414 $self->assert(qr/$expected/, $resp_msg,
1415 test_msg("Expected response message '$expected', got '$resp_msg'"));
1416
1417 # Make sure the control connection did not close because of the abort.
1418 ($resp_code, $resp_msg) = $client->quit();
1419
1420 $expected = 221;
1421 $self->assert($expected == $resp_code,
1422 test_msg("Expected response code $expected, got $resp_code"));
1423
1424 $expected = 'Goodbye.';
1425 $self->assert($expected eq $resp_msg,
1426 test_msg("Expected response message '$expected', got '$resp_msg'"));
1427 };
1428 if ($@) {
1429 $ex = $@;
1430 }
1431
1432 $wfh->print("done\n");
1433 $wfh->flush();
1434
1435 } else {
1436 eval { server_wait($setup->{config_file}, $rfh) };
1437 if ($@) {
1438 warn($@);
1439 exit 1;
1440 }
1441
1442 exit 0;
1443 }
1444
1445 # Stop server
1446 server_stop($setup->{pid_file});
1447 $self->assert_child_ok($pid);
1448
1449 test_cleanup($setup->{log_file}, $ex);
1450 }
1451
1452 sub abor_no_xfer_ok {
1453 my $self = shift;
1454 my $tmpdir = $self->{tmpdir};
1455 my $setup = test_setup($tmpdir, 'abor');
1456
1457 my $test_file = File::Spec->rel2abs($setup->{config_file});
1458
1459 my $config = {
1460 PidFile => $setup->{pid_file},
1461 ScoreboardFile => $setup->{scoreboard_file},
1462 SystemLog => $setup->{log_file},
1463 TraceLog => $setup->{log_file},
1464 Trace => 'DEFAULT:10',
1465
1466 AuthUserFile => $setup->{auth_user_file},
1467 AuthGroupFile => $setup->{auth_group_file},
1468 AuthOrder => 'mod_auth_file.c',
1469
1470 TimeoutLinger => 5,
1471
1472 IfModules => {
1473 'mod_delay.c' => {
1474 DelayEngine => 'off',
1475 },
1476 },
1477 };
1478
1479 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1480 $config);
1481
1482 # Open pipes, for use between the parent and child processes. Specifically,
1483 # the child will indicate when it's done with its test by writing a message
1484 # to the parent.
1485 my ($rfh, $wfh);
1486 unless (pipe($rfh, $wfh)) {
1487 die("Can't open pipe: $!");
1488 }
1489
1490 my $ex;
1491
1492 # Fork child
1493 $self->handle_sigchld();
1494 defined(my $pid = fork()) or die("Can't fork: $!");
1495 if ($pid) {
1496 eval {
1497 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1498 $client->login($setup->{user}, $setup->{passwd});
1499 $client->abort();
1500
1501 my $resp_code = $client->response_code();
1502 my $resp_msg = $client->response_msg();
1503 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
1504
1505 # Make sure the control connection did not close because of the abort.
1506 ($resp_code, $resp_msg) = $client->quit();
1507
1508 my $expected = 221;
1509 $self->assert($expected == $resp_code,
1510 test_msg("Expected response code $expected, got $resp_code"));
1511
1512 $expected = 'Goodbye.';
1513 $self->assert($expected eq $resp_msg,
1514 test_msg("Expected response message '$expected', got '$resp_msg'"));
1515 };
1516 if ($@) {
1517 $ex = $@;
1518 }
1519
1520 $wfh->print("done\n");
1521 $wfh->flush();
1522
1523 } else {
1524 eval { server_wait($setup->{config_file}, $rfh) };
1525 if ($@) {
1526 warn($@);
1527 exit 1;
1528 }
1529
1530 exit 0;
1531 }
1532
1533 # Stop server
1534 server_stop($setup->{pid_file});
1535 $self->assert_child_ok($pid);
1536
1537 test_cleanup($setup->{log_file}, $ex);
1538 }
1539
1540 sub abor_list_ok {
1541 my $self = shift;
1542 my $tmpdir = $self->{tmpdir};
1543 my $setup = test_setup($tmpdir, 'abor');
1544
1545 my $config = {
1546 PidFile => $setup->{pid_file},
1547 ScoreboardFile => $setup->{scoreboard_file},
1548 SystemLog => $setup->{log_file},
1549 TraceLog => $setup->{log_file},
1550 Trace => 'DEFAULT:10',
1551
1552 AuthUserFile => $setup->{auth_user_file},
1553 AuthGroupFile => $setup->{auth_group_file},
1554 AuthOrder => 'mod_auth_file.c',
1555
1556 TimeoutLinger => 5,
1557
1558 IfModules => {
1559 'mod_delay.c' => {
1560 DelayEngine => 'off',
1561 },
1562 },
1563 };
1564
1565 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1566 $config);
1567
1568 # Open pipes, for use between the parent and child processes. Specifically,
1569 # the child will indicate when it's done with its test by writing a message
1570 # to the parent.
1571 my ($rfh, $wfh);
1572 unless (pipe($rfh, $wfh)) {
1573 die("Can't open pipe: $!");
1574 }
1575
1576 my $ex;
1577
1578 # Fork child
1579 $self->handle_sigchld();
1580 defined(my $pid = fork()) or die("Can't fork: $!");
1581 if ($pid) {
1582 eval {
1583 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1584 $client->login($setup->{user}, $setup->{passwd});
1585
1586 # Use a recursive listing, to generate more data, such that it will
1587 # not all fit in the transfer buffer, so we can interrupt the buffer.
1588 # A too-small request will fit in the buffer, and be fulfilled, before
1589 # our abort is read.
1590 my $conn = $client->list_raw('-R /');
1591 unless ($conn) {
1592 die("Failed to LIST: " . $client->response_code() . " " .
1593 $client->response_msg());
1594 }
1595
1596 # Read 128 bytes of data, then abort the download
1597 my $buf;
1598 $conn->read($buf, 128, 30);
1599 eval { $conn->abort() };
1600
1601 my $resp_code = $client->response_code();
1602 my $resp_msg = $client->response_msg();
1603 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
1604
1605 # We expect 2 responses here: first, a 426 for the aborted data transfer,
1606 # followed by 226 for the successful ABOR command. Order matters.
1607 my $resp_msgs = $client->response_msgs();
1608
1609 my $resp_nmsgs = scalar(@$resp_msgs);
1610 $self->assert($resp_nmsgs == 2,
1611 test_msg("Expected 2 responses, got $resp_nmsgs"));
1612
1613 my $expected = 'Transfer aborted. Data connection closed.';
1614 $self->assert($expected eq $resp_msgs->[0],
1615 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
1616
1617 $expected = 'Abort successful';
1618 $self->assert($expected eq $resp_msgs->[1],
1619 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
1620
1621 # Make sure the control connection did not close because of the abort.
1622 ($resp_code, $resp_msg) = $client->quit();
1623
1624 $expected = 221;
1625 $self->assert($expected == $resp_code,
1626 test_msg("Expected response code $expected, got $resp_code"));
1627
1628 $expected = 'Goodbye.';
1629 $self->assert($expected eq $resp_msg,
1630 test_msg("Expected response message '$expected', got '$resp_msg'"));
1631 };
1632 if ($@) {
1633 $ex = $@;
1634 }
1635
1636 $wfh->print("done\n");
1637 $wfh->flush();
1638
1639 } else {
1640 eval { server_wait($setup->{config_file}, $rfh) };
1641 if ($@) {
1642 warn($@);
1643 exit 1;
1644 }
1645
1646 exit 0;
1647 }
1648
1649 # Stop server
1650 server_stop($setup->{pid_file});
1651 $self->assert_child_ok($pid);
1652
1653 test_cleanup($setup->{log_file}, $ex);
1654 }
1655
1656 sub abor_mlsd_ok {
1657 my $self = shift;
1658 my $tmpdir = $self->{tmpdir};
1659 my $setup = test_setup($tmpdir, 'abor');
1660
1661 # Generate enough files in the directory to lead to a large enough response,
1662 # such that the response does not all fit in the initial transfer buffer.
1663 for (my $i = 0; $i < 5000; $i++) {
1664 my $path = File::Spec->rel2abs("$tmpdir/$i.dat");
1665
1666 if (open(my $fh, "> $path")) {
1667 close($fh);
1668
1669 } else {
1670 die("Can't open $path: $!");
1671 }
1672 }
1673
1674 my $config = {
1675 PidFile => $setup->{pid_file},
1676 ScoreboardFile => $setup->{scoreboard_file},
1677 SystemLog => $setup->{log_file},
1678 TraceLog => $setup->{log_file},
1679 Trace => 'DEFAULT:10',
1680
1681 AuthUserFile => $setup->{auth_user_file},
1682 AuthGroupFile => $setup->{auth_group_file},
1683 AuthOrder => 'mod_auth_file.c',
1684
1685 TimeoutLinger => 5,
1686
1687 IfModules => {
1688 'mod_delay.c' => {
1689 DelayEngine => 'off',
1690 },
1691 },
1692 };
1693
1694 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1695 $config);
1696
1697 # Open pipes, for use between the parent and child processes. Specifically,
1698 # the child will indicate when it's done with its test by writing a message
1699 # to the parent.
1700 my ($rfh, $wfh);
1701 unless (pipe($rfh, $wfh)) {
1702 die("Can't open pipe: $!");
1703 }
1704
1705 my $ex;
1706
1707 # Fork child
1708 $self->handle_sigchld();
1709 defined(my $pid = fork()) or die("Can't fork: $!");
1710 if ($pid) {
1711 eval {
1712 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1713 $client->login($setup->{user}, $setup->{passwd});
1714
1715 my $conn = $client->mlsd_raw($tmpdir);
1716 unless ($conn) {
1717 die("Failed to MLSD: " . $client->response_code() . " " .
1718 $client->response_msg());
1719 }
1720
1721 # Read 128 bytes of data, then abort the download
1722 my $buf;
1723 $conn->read($buf, 128, 30);
1724 eval { $conn->abort() };
1725
1726 my $resp_code = $client->response_code();
1727 my $resp_msg = $client->response_msg();
1728 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
1729
1730 # We expect 2 responses here: first, a 426 for the aborted data transfer,
1731 # followed by 226 for the successful ABOR command. Order matters.
1732 my $resp_msgs = $client->response_msgs();
1733
1734 my $resp_nmsgs = scalar(@$resp_msgs);
1735 $self->assert($resp_nmsgs == 2,
1736 test_msg("Expected 2 responses, got $resp_nmsgs"));
1737
1738 my $expected = 'Transfer aborted. Data connection closed.';
1739 $self->assert($expected eq $resp_msgs->[0],
1740 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
1741
1742 $expected = 'Abort successful';
1743 $self->assert($expected eq $resp_msgs->[1],
1744 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
1745
1746 # Make sure the control connection did not close because of the abort.
1747 ($resp_code, $resp_msg) = $client->quit();
1748
1749 $expected = 221;
1750 $self->assert($expected == $resp_code,
1751 test_msg("Expected response code $expected, got $resp_code"));
1752
1753 $expected = 'Goodbye.';
1754 $self->assert($expected eq $resp_msg,
1755 test_msg("Expected response message '$expected', got '$resp_msg'"));
1756 };
1757 if ($@) {
1758 $ex = $@;
1759 }
1760
1761 $wfh->print("done\n");
1762 $wfh->flush();
1763
1764 } else {
1765 eval { server_wait($setup->{config_file}, $rfh) };
1766 if ($@) {
1767 warn($@);
1768 exit 1;
1769 }
1770
1771 exit 0;
1772 }
1773
1774 # Stop server
1775 server_stop($setup->{pid_file});
1776 $self->assert_child_ok($pid);
1777
1778 test_cleanup($setup->{log_file}, $ex);
1779 }
1780
1781 sub abor_only_retr_ascii {
1782 my $self = shift;
1783 my $tmpdir = $self->{tmpdir};
1784 my $setup = test_setup($tmpdir, 'abor');
1785
1786 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
1787 if (open(my $fh, "> $test_file")) {
1788 print $fh "ABCDEFG\n" x 40960;
1789
1790 unless (close($fh)) {
1791 die("Can't write $test_file: $!");
1792 }
1793
1794 } else {
1795 die("Can't open $test_file: $!");
1796 }
1797
1798 my $config = {
1799 PidFile => $setup->{pid_file},
1800 ScoreboardFile => $setup->{scoreboard_file},
1801 SystemLog => $setup->{log_file},
1802 TraceLog => $setup->{log_file},
1803 Trace => 'DEFAULT:10 data:20',
1804
1805 AuthUserFile => $setup->{auth_user_file},
1806 AuthGroupFile => $setup->{auth_group_file},
1807 AuthOrder => 'mod_auth_file.c',
1808
1809 TimeoutLinger => 5,
1810
1811 IfModules => {
1812 'mod_delay.c' => {
1813 DelayEngine => 'off',
1814 },
1815 },
1816 };
1817
1818 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1819 $config);
1820
1821 # Open pipes, for use between the parent and child processes. Specifically,
1822 # the child will indicate when it's done with its test by writing a message
1823 # to the parent.
1824 my ($rfh, $wfh);
1825 unless (pipe($rfh, $wfh)) {
1826 die("Can't open pipe: $!");
1827 }
1828
1829 my $ex;
1830
1831 # Fork child
1832 $self->handle_sigchld();
1833 defined(my $pid = fork()) or die("Can't fork: $!");
1834 if ($pid) {
1835 eval {
1836 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1837 $client->login($setup->{user}, $setup->{passwd});
1838 $client->pasv();
1839 $client->type('ascii');
1840
1841 my $conn = $client->retr_raw($test_file);
1842 unless ($conn) {
1843 die("Failed to RETR: " . $client->response_code() . " " .
1844 $client->response_msg());
1845 }
1846
1847 # Read 128 bytes of the file, then abort the download
1848 my $buf;
1849 $conn->read($buf, 128, 30);
1850
1851 eval { $client->quote('ABOR') };
1852 unless ($@) {
1853 die("ABOR succeeded unexpectedly");
1854 }
1855
1856 # We expect 2 responses here: first, a 426 for the aborted data transfer,
1857 # followed by 226 for the successful ABOR command. Order matters.
1858 my $resp_msgs = $client->response_msgs();
1859
1860 my $resp_nmsgs = scalar(@$resp_msgs);
1861 $self->assert($resp_nmsgs == 2,
1862 test_msg("Expected 2 responses, got $resp_nmsgs"));
1863
1864 my $expected = 'Transfer aborted. Data connection closed.';
1865 $self->assert($expected eq $resp_msgs->[0],
1866 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
1867
1868 $expected = 'Abort successful';
1869 $self->assert($expected eq $resp_msgs->[1],
1870 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
1871
1872 # Make sure the control connection did not close because of the abort.
1873 my ($resp_code, $resp_msg) = $client->quit();
1874
1875 $expected = 221;
1876 $self->assert($expected == $resp_code,
1877 test_msg("Expected response code $expected, got $resp_code"));
1878
1879 $expected = 'Goodbye.';
1880 $self->assert($expected eq $resp_msg,
1881 test_msg("Expected response message '$expected', got '$resp_msg'"));
1882 };
1883 if ($@) {
1884 $ex = $@;
1885 }
1886
1887 $wfh->print("done\n");
1888 $wfh->flush();
1889
1890 } else {
1891 eval { server_wait($setup->{config_file}, $rfh) };
1892 if ($@) {
1893 warn($@);
1894 exit 1;
1895 }
1896
1897 exit 0;
1898 }
1899
1900 # Stop server
1901 server_stop($setup->{pid_file});
1902 $self->assert_child_ok($pid);
1903
1904 test_cleanup($setup->{log_file}, $ex);
1905 }
1906
1907 sub abor_only_retr_binary_with_sendfile {
1908 my $self = shift;
1909 my $tmpdir = $self->{tmpdir};
1910 my $setup = test_setup($tmpdir, 'abor');
1911
1912 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
1913 if (open(my $fh, "> $test_file")) {
1914 print $fh "ABCDEFG\n" x 40960;
1915
1916 unless (close($fh)) {
1917 die("Can't write $test_file: $!");
1918 }
1919
1920 } else {
1921 die("Can't open $test_file: $!");
1922 }
1923
1924 my $config = {
1925 PidFile => $setup->{pid_file},
1926 ScoreboardFile => $setup->{scoreboard_file},
1927 SystemLog => $setup->{log_file},
1928 TraceLog => $setup->{log_file},
1929 Trace => 'DEFAULT:10 data:20',
1930
1931 AuthUserFile => $setup->{auth_user_file},
1932 AuthGroupFile => $setup->{auth_group_file},
1933 AuthOrder => 'mod_auth_file.c',
1934
1935 TimeoutLinger => 5,
1936
1937 IfModules => {
1938 'mod_delay.c' => {
1939 DelayEngine => 'off',
1940 },
1941 },
1942 };
1943
1944 if (feature_have_feature_enabled('sendfile')) {
1945 $config->{UseSendfile} = 'on';
1946 }
1947
1948 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1949 $config);
1950
1951 # Open pipes, for use between the parent and child processes. Specifically,
1952 # the child will indicate when it's done with its test by writing a message
1953 # to the parent.
1954 my ($rfh, $wfh);
1955 unless (pipe($rfh, $wfh)) {
1956 die("Can't open pipe: $!");
1957 }
1958
1959 my $ex;
1960
1961 # Fork child
1962 $self->handle_sigchld();
1963 defined(my $pid = fork()) or die("Can't fork: $!");
1964 if ($pid) {
1965 eval {
1966 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1967 $client->login($setup->{user}, $setup->{passwd});
1968 $client->type('binary');
1969
1970 my $conn = $client->retr_raw($test_file);
1971 unless ($conn) {
1972 die("Failed to RETR: " . $client->response_code() . " " .
1973 $client->response_msg());
1974 }
1975
1976 # Read 128 bytes of the file, then abort the download
1977 my $buf;
1978 $conn->read($buf, 128, 30);
1979
1980 # With sendfile enabled, it's quite probable that all of the data will
1981 # have been transferred already. Thus we expect to see two success
1982 # responses here.
1983 eval { $client->quote('ABOR') };
1984 if ($@) {
1985 die("ABOR failed unexpectedly");
1986 }
1987
1988 # We expect 2 responses here: first, a 226 for the (completed) data
1989 # transfer, followed by 226 for the successful ABOR command. Order
1990 # matters.
1991 my $resp_msgs = $client->response_msgs();
1992
1993 my $resp_nmsgs = scalar(@$resp_msgs);
1994 $self->assert($resp_nmsgs == 2,
1995 test_msg("Expected 2 responses, got $resp_nmsgs"));
1996
1997 my $expected = 'Transfer complete';
1998 $self->assert($expected eq $resp_msgs->[0],
1999 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
2000
2001 $expected = 'Abort successful';
2002 $self->assert($expected eq $resp_msgs->[1],
2003 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
2004
2005 # Make sure the control connection did not close because of the abort.
2006 my ($resp_code, $resp_msg) = $client->quit();
2007
2008 $expected = 221;
2009 $self->assert($expected == $resp_code,
2010 test_msg("Expected response code $expected, got $resp_code"));
2011
2012 $expected = 'Goodbye.';
2013 $self->assert($expected eq $resp_msg,
2014 test_msg("Expected response message '$expected', got '$resp_msg'"));
2015 };
2016 if ($@) {
2017 $ex = $@;
2018 }
2019
2020 $wfh->print("done\n");
2021 $wfh->flush();
2022
2023 } else {
2024 eval { server_wait($setup->{config_file}, $rfh) };
2025 if ($@) {
2026 warn($@);
2027 exit 1;
2028 }
2029
2030 exit 0;
2031 }
2032
2033 # Stop server
2034 server_stop($setup->{pid_file});
2035 $self->assert_child_ok($pid);
2036
2037 test_cleanup($setup->{log_file}, $ex);
2038 }
2039
2040 sub abor_only_retr_binary_without_sendfile {
2041 my $self = shift;
2042 my $tmpdir = $self->{tmpdir};
2043 my $setup = test_setup($tmpdir, 'abor');
2044
2045 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
2046 if (open(my $fh, "> $test_file")) {
2047 print $fh "ABCDEFG\n" x 40960;
2048
2049 unless (close($fh)) {
2050 die("Can't write $test_file: $!");
2051 }
2052
2053 } else {
2054 die("Can't open $test_file: $!");
2055 }
2056
2057 my $config = {
2058 PidFile => $setup->{pid_file},
2059 ScoreboardFile => $setup->{scoreboard_file},
2060 SystemLog => $setup->{log_file},
2061 TraceLog => $setup->{log_file},
2062 Trace => 'DEFAULT:10 data:20',
2063
2064 AuthUserFile => $setup->{auth_user_file},
2065 AuthGroupFile => $setup->{auth_group_file},
2066 AuthOrder => 'mod_auth_file.c',
2067
2068 TimeoutLinger => 5,
2069 UseSendfile => 'off',
2070
2071 IfModules => {
2072 'mod_delay.c' => {
2073 DelayEngine => 'off',
2074 },
2075 },
2076 };
2077
2078 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2079 $config);
2080
2081 # Open pipes, for use between the parent and child processes. Specifically,
2082 # the child will indicate when it's done with its test by writing a message
2083 # to the parent.
2084 my ($rfh, $wfh);
2085 unless (pipe($rfh, $wfh)) {
2086 die("Can't open pipe: $!");
2087 }
2088
2089 my $ex;
2090
2091 # Fork child
2092 $self->handle_sigchld();
2093 defined(my $pid = fork()) or die("Can't fork: $!");
2094 if ($pid) {
2095 eval {
2096 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2097 $client->login($setup->{user}, $setup->{passwd});
2098 $client->type('binary');
2099
2100 my $conn = $client->retr_raw($test_file);
2101 unless ($conn) {
2102 die("Failed to RETR: " . $client->response_code() . " " .
2103 $client->response_msg());
2104 }
2105
2106 # Read 128 bytes of the file, then abort the download
2107 my $buf;
2108 $conn->read($buf, 128, 30);
2109
2110 # With sendfile enabled, it's quite probable that all of the data will
2111 # have been transferred already. Thus we expect to see two success
2112 # responses here.
2113 eval { $client->quote('ABOR') };
2114 unless ($@) {
2115 die("ABOR succeeded unexpectedly");
2116 }
2117
2118 # We expect 2 responses here: first, a 426 for the aborted data transfer,
2119 # followed by 226 for the successful ABOR command. Order matters.
2120 my $resp_msgs = $client->response_msgs();
2121
2122 my $resp_nmsgs = scalar(@$resp_msgs);
2123 $self->assert($resp_nmsgs == 2,
2124 test_msg("Expected 2 responses, got $resp_nmsgs"));
2125
2126 my $expected = 'Transfer aborted. Data connection closed.';
2127 $self->assert($expected eq $resp_msgs->[0],
2128 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
2129
2130 $expected = 'Abort successful';
2131 $self->assert($expected eq $resp_msgs->[1],
2132 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
2133
2134 # Make sure the control connection did not close because of the abort.
2135 my ($resp_code, $resp_msg) = $client->quit();
2136
2137 $expected = 221;
2138 $self->assert($expected == $resp_code,
2139 test_msg("Expected response code $expected, got $resp_code"));
2140
2141 $expected = 'Goodbye.';
2142 $self->assert($expected eq $resp_msg,
2143 test_msg("Expected response message '$expected', got '$resp_msg'"));
2144 };
2145 if ($@) {
2146 $ex = $@;
2147 }
2148
2149 $wfh->print("done\n");
2150 $wfh->flush();
2151
2152 } else {
2153 eval { server_wait($setup->{config_file}, $rfh) };
2154 if ($@) {
2155 warn($@);
2156 exit 1;
2157 }
2158
2159 exit 0;
2160 }
2161
2162 # Stop server
2163 server_stop($setup->{pid_file});
2164 $self->assert_child_ok($pid);
2165
2166 test_cleanup($setup->{log_file}, $ex);
2167 }
2168
2169 sub abor_only_stor_ascii {
2170 my $self = shift;
2171 my $tmpdir = $self->{tmpdir};
2172 my $setup = test_setup($tmpdir, 'abor');
2173
2174 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
2175
2176 my $config = {
2177 PidFile => $setup->{pid_file},
2178 ScoreboardFile => $setup->{scoreboard_file},
2179 SystemLog => $setup->{log_file},
2180 TraceLog => $setup->{log_file},
2181 Trace => 'DEFAULT:10',
2182
2183 AuthUserFile => $setup->{auth_user_file},
2184 AuthGroupFile => $setup->{auth_group_file},
2185 AuthOrder => 'mod_auth_file.c',
2186
2187 TimeoutLinger => 5,
2188
2189 IfModules => {
2190 'mod_delay.c' => {
2191 DelayEngine => 'off',
2192 },
2193 },
2194 };
2195
2196 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2197 $config);
2198
2199 # Open pipes, for use between the parent and child processes. Specifically,
2200 # the child will indicate when it's done with its test by writing a message
2201 # to the parent.
2202 my ($rfh, $wfh);
2203 unless (pipe($rfh, $wfh)) {
2204 die("Can't open pipe: $!");
2205 }
2206
2207 my $ex;
2208
2209 # Fork child
2210 $self->handle_sigchld();
2211 defined(my $pid = fork()) or die("Can't fork: $!");
2212 if ($pid) {
2213 eval {
2214 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2215 $client->login($setup->{user}, $setup->{passwd});
2216 $client->pasv();
2217 $client->type('ascii');
2218
2219 my $conn = $client->stor_raw($test_file);
2220 unless ($conn) {
2221 die("Failed to STOR: " . $client->response_code() . " " .
2222 $client->response_msg());
2223 }
2224
2225 # Write data to the file, then abort the upload
2226 my $buf = "A\r\nB\r\nC\r\nD\r\n";
2227 $conn->write($buf, length($buf));
2228
2229 eval { $client->quote('ABOR') };
2230 unless ($@) {
2231 die("ABOR succeeded unexpectedly");
2232 }
2233
2234 # We expect 2 responses here: first, a 426 for the aborted data transfer,
2235 # followed by 226 for the successful ABOR command. Order matters.
2236 my $resp_msgs = $client->response_msgs();
2237
2238 my $resp_nmsgs = scalar(@$resp_msgs);
2239 $self->assert($resp_nmsgs == 2,
2240 test_msg("Expected 2 responses, got $resp_nmsgs"));
2241
2242 my $expected = 'Transfer aborted. Data connection closed.';
2243 $self->assert($expected eq $resp_msgs->[0],
2244 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
2245
2246 $expected = 'Abort successful';
2247 $self->assert($expected eq $resp_msgs->[1],
2248 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
2249
2250 # Make sure the control connection did not close because of the abort.
2251 my ($resp_code, $resp_msg) = $client->quit();
2252
2253 $expected = 221;
2254 $self->assert($expected == $resp_code,
2255 test_msg("Expected response message $expected, got $resp_code"));
2256
2257 $expected = 'Goodbye.';
2258 $self->assert($expected eq $resp_msg,
2259 test_msg("Expected response message '$expected', got '$resp_msg'"));
2260 };
2261 if ($@) {
2262 $ex = $@;
2263 }
2264
2265 $wfh->print("done\n");
2266 $wfh->flush();
2267
2268 } else {
2269 eval { server_wait($setup->{config_file}, $rfh) };
2270 if ($@) {
2271 warn($@);
2272 exit 1;
2273 }
2274
2275 exit 0;
2276 }
2277
2278 # Stop server
2279 server_stop($setup->{pid_file});
2280 $self->assert_child_ok($pid);
2281
2282 test_cleanup($setup->{log_file}, $ex);
2283 }
2284
2285 sub abor_only_stor_binary {
2286 my $self = shift;
2287 my $tmpdir = $self->{tmpdir};
2288 my $setup = test_setup($tmpdir, 'abor');
2289
2290 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
2291
2292 my $config = {
2293 PidFile => $setup->{pid_file},
2294 ScoreboardFile => $setup->{scoreboard_file},
2295 SystemLog => $setup->{log_file},
2296 TraceLog => $setup->{log_file},
2297 Trace => 'DEFAULT:10',
2298
2299 AuthUserFile => $setup->{auth_user_file},
2300 AuthGroupFile => $setup->{auth_group_file},
2301 AuthOrder => 'mod_auth_file.c',
2302
2303 TimeoutLinger => 5,
2304
2305 IfModules => {
2306 'mod_delay.c' => {
2307 DelayEngine => 'off',
2308 },
2309 },
2310 };
2311
2312 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2313 $config);
2314
2315 # Open pipes, for use between the parent and child processes. Specifically,
2316 # the child will indicate when it's done with its test by writing a message
2317 # to the parent.
2318 my ($rfh, $wfh);
2319 unless (pipe($rfh, $wfh)) {
2320 die("Can't open pipe: $!");
2321 }
2322
2323 my $ex;
2324
2325 # Fork child
2326 $self->handle_sigchld();
2327 defined(my $pid = fork()) or die("Can't fork: $!");
2328 if ($pid) {
2329 eval {
2330 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2331 $client->login($setup->{user}, $setup->{passwd});
2332 $client->pasv();
2333 $client->type('binary');
2334
2335 my $conn = $client->stor_raw($test_file);
2336 unless ($conn) {
2337 die("Failed to STOR: " . $client->response_code() . " " .
2338 $client->response_msg());
2339 }
2340
2341 # Write data to the file, then abort the upload
2342 my $buf = "A\r\nB\r\nC\r\nD\r\n";
2343 $conn->write($buf, length($buf));
2344
2345 eval { $client->quote('ABOR') };
2346 unless ($@) {
2347 die("ABOR succeeded unexpectedly");
2348 }
2349
2350 # We expect 2 responses here: first, a 426 for the aborted data transfer,
2351 # followed by 226 for the successful ABOR command. Order matters.
2352 my $resp_msgs = $client->response_msgs();
2353
2354 my $resp_nmsgs = scalar(@$resp_msgs);
2355 $self->assert($resp_nmsgs == 2,
2356 test_msg("Expected 2 responses, got $resp_nmsgs"));
2357
2358 my $expected = 'Transfer aborted. Data connection closed.';
2359 $self->assert($expected eq $resp_msgs->[0],
2360 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
2361
2362 $expected = 'Abort successful';
2363 $self->assert($expected eq $resp_msgs->[1],
2364 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
2365
2366 # Make sure the control connection did not close because of the abort.
2367 my ($resp_code, $resp_msg) = $client->quit();
2368
2369 $expected = 221;
2370 $self->assert($expected == $resp_code,
2371 test_msg("Expected response message $expected, got $resp_code"));
2372
2373 $expected = 'Goodbye.';
2374 $self->assert($expected eq $resp_msg,
2375 test_msg("Expected response message '$expected', got '$resp_msg'"));
2376 };
2377 if ($@) {
2378 $ex = $@;
2379 }
2380
2381 $wfh->print("done\n");
2382 $wfh->flush();
2383
2384 } else {
2385 eval { server_wait($setup->{config_file}, $rfh) };
2386 if ($@) {
2387 warn($@);
2388 exit 1;
2389 }
2390
2391 exit 0;
2392 }
2393
2394 # Stop server
2395 server_stop($setup->{pid_file});
2396 $self->assert_child_ok($pid);
2397
2398 test_cleanup($setup->{log_file}, $ex);
2399 }
2400
2401 sub abor_only_list {
2402 my $self = shift;
2403 my $tmpdir = $self->{tmpdir};
2404 my $setup = test_setup($tmpdir, 'abor');
2405
2406 my $config = {
2407 PidFile => $setup->{pid_file},
2408 ScoreboardFile => $setup->{scoreboard_file},
2409 SystemLog => $setup->{log_file},
2410 TraceLog => $setup->{log_file},
2411 Trace => 'DEFAULT:10',
2412
2413 AuthUserFile => $setup->{auth_user_file},
2414 AuthGroupFile => $setup->{auth_group_file},
2415 AuthOrder => 'mod_auth_file.c',
2416
2417 TimeoutLinger => 5,
2418
2419 IfModules => {
2420 'mod_delay.c' => {
2421 DelayEngine => 'off',
2422 },
2423 },
2424 };
2425
2426 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2427 $config);
2428
2429 # Open pipes, for use between the parent and child processes. Specifically,
2430 # the child will indicate when it's done with its test by writing a message
2431 # to the parent.
2432 my ($rfh, $wfh);
2433 unless (pipe($rfh, $wfh)) {
2434 die("Can't open pipe: $!");
2435 }
2436
2437 my $ex;
2438
2439 # Fork child
2440 $self->handle_sigchld();
2441 defined(my $pid = fork()) or die("Can't fork: $!");
2442 if ($pid) {
2443 eval {
2444 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2445 $client->login($setup->{user}, $setup->{passwd});
2446
2447 # Use a recursive listing, to generate more data, such that it will
2448 # not all fit in the transfer buffer, so we can interrupt the buffer.
2449 # A too-small request will fit in the buffer, and be fulfilled, before
2450 # our abort is read.
2451 my $conn = $client->list_raw('-R /');
2452 unless ($conn) {
2453 die("Failed to LIST: " . $client->response_code() . " " .
2454 $client->response_msg());
2455 }
2456
2457 # Read 128 bytes of data, then abort the download
2458 my $buf;
2459 $conn->read($buf, 128, 30);
2460
2461 eval { $client->quote('ABOR') };
2462 unless ($@) {
2463 die("ABOR succeeded unexpectedly");
2464 }
2465
2466 # We expect 2 responses here: first, a 426 for the aborted data transfer,
2467 # followed by 226 for the successful ABOR command. Order matters.
2468 my $resp_msgs = $client->response_msgs();
2469
2470 my $resp_nmsgs = scalar(@$resp_msgs);
2471 $self->assert($resp_nmsgs == 2,
2472 test_msg("Expected 2 responses, got $resp_nmsgs"));
2473
2474 my $expected = 'Transfer aborted. Data connection closed.';
2475 $self->assert($expected eq $resp_msgs->[0],
2476 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
2477
2478 $expected = 'Abort successful';
2479 $self->assert($expected eq $resp_msgs->[1],
2480 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
2481
2482 # Make sure the control connection did not close because of the abort.
2483 my ($resp_code, $resp_msg) = $client->quit();
2484
2485 $expected = 221;
2486 $self->assert($expected == $resp_code,
2487 test_msg("Expected response code $expected, got $resp_code"));
2488
2489 $expected = 'Goodbye.';
2490 $self->assert($expected eq $resp_msg,
2491 test_msg("Expected response message '$expected', got '$resp_msg'"));
2492 };
2493 if ($@) {
2494 $ex = $@;
2495 }
2496
2497 $wfh->print("done\n");
2498 $wfh->flush();
2499
2500 } else {
2501 eval { server_wait($setup->{config_file}, $rfh) };
2502 if ($@) {
2503 warn($@);
2504 exit 1;
2505 }
2506
2507 exit 0;
2508 }
2509
2510 # Stop server
2511 server_stop($setup->{pid_file});
2512 $self->assert_child_ok($pid);
2513
2514 test_cleanup($setup->{log_file}, $ex);
2515 }
2516
2517 sub abor_only_mlsd {
2518 my $self = shift;
2519 my $tmpdir = $self->{tmpdir};
2520 my $setup = test_setup($tmpdir, 'abor');
2521
2522 # Generate enough files in the directory to lead to a large enough response,
2523 # such that the response does not all fit in the initial transfer buffer.
2524 for (my $i = 0; $i < 5000; $i++) {
2525 my $path = File::Spec->rel2abs("$tmpdir/$i.dat");
2526
2527 if (open(my $fh, "> $path")) {
2528 close($fh);
2529
2530 } else {
2531 die("Can't open $path: $!");
2532 }
2533 }
2534
2535 my $config = {
2536 PidFile => $setup->{pid_file},
2537 ScoreboardFile => $setup->{scoreboard_file},
2538 SystemLog => $setup->{log_file},
2539 TraceLog => $setup->{log_file},
2540 Trace => 'DEFAULT:10',
2541
2542 AuthUserFile => $setup->{auth_user_file},
2543 AuthGroupFile => $setup->{auth_group_file},
2544 AuthOrder => 'mod_auth_file.c',
2545
2546 TimeoutLinger => 5,
2547
2548 IfModules => {
2549 'mod_delay.c' => {
2550 DelayEngine => 'off',
2551 },
2552 },
2553 };
2554
2555 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2556 $config);
2557
2558 # Open pipes, for use between the parent and child processes. Specifically,
2559 # the child will indicate when it's done with its test by writing a message
2560 # to the parent.
2561 my ($rfh, $wfh);
2562 unless (pipe($rfh, $wfh)) {
2563 die("Can't open pipe: $!");
2564 }
2565
2566 my $ex;
2567
2568 # Fork child
2569 $self->handle_sigchld();
2570 defined(my $pid = fork()) or die("Can't fork: $!");
2571 if ($pid) {
2572 eval {
2573 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2574 $client->login($setup->{user}, $setup->{passwd});
2575
2576 my $conn = $client->mlsd_raw($tmpdir);
2577 unless ($conn) {
2578 die("Failed to MLSD: " . $client->response_code() . " " .
2579 $client->response_msg());
2580 }
2581
2582 # Read 128 bytes of data, then abort the download
2583 my $buf;
2584 $conn->read($buf, 128, 30);
2585
2586 eval { $client->quote('ABOR') };
2587 unless ($@) {
2588 die("ABOR succeeded unexpectedly");
2589 }
2590
2591 # We expect 2 responses here: first, a 426 for the aborted data transfer,
2592 # followed by 226 for the successful ABOR command. Order matters.
2593 my $resp_msgs = $client->response_msgs();
2594
2595 my $resp_nmsgs = scalar(@$resp_msgs);
2596 $self->assert($resp_nmsgs == 2,
2597 test_msg("Expected 2 responses, got $resp_nmsgs"));
2598
2599 my $expected = 'Transfer aborted. Data connection closed.';
2600 $self->assert($expected eq $resp_msgs->[0],
2601 test_msg("Expected response message '$expected', got '$resp_msgs->[0]'"));
2602
2603 $expected = 'Abort successful';
2604 $self->assert($expected eq $resp_msgs->[1],
2605 test_msg("Expected response message '$expected', got '$resp_msgs->[1]'"));
2606
2607 # Make sure the control connection did not close because of the abort.
2608 my ($resp_code, $resp_msg) = $client->quit();
2609
2610 $expected = 221;
2611 $self->assert($expected == $resp_code,
2612 test_msg("Expected response code $expected, got $resp_code"));
2613
2614 $expected = 'Goodbye.';
2615 $self->assert($expected eq $resp_msg,
2616 test_msg("Expected response message '$expected', got '$resp_msg'"));
2617 };
2618 if ($@) {
2619 $ex = $@;
2620 }
2621
2622 $wfh->print("done\n");
2623 $wfh->flush();
2624
2625 } else {
2626 eval { server_wait($setup->{config_file}, $rfh) };
2627 if ($@) {
2628 warn($@);
2629 exit 1;
2630 }
2631
2632 exit 0;
2633 }
2634
2635 # Stop server
2636 server_stop($setup->{pid_file});
2637 $self->assert_child_ok($pid);
2638
2639 test_cleanup($setup->{log_file}, $ex);
2640 }
2641
2642 sub abor_only_no_xfer {
2643 my $self = shift;
2644 my $tmpdir = $self->{tmpdir};
2645 my $setup = test_setup($tmpdir, 'abor');
2646
2647 my $test_file = File::Spec->rel2abs($setup->{config_file});
2648
2649 my $config = {
2650 PidFile => $setup->{pid_file},
2651 ScoreboardFile => $setup->{scoreboard_file},
2652 SystemLog => $setup->{log_file},
2653 TraceLog => $setup->{log_file},
2654 Trace => 'DEFAULT:10',
2655
2656 AuthUserFile => $setup->{auth_user_file},
2657 AuthGroupFile => $setup->{auth_group_file},
2658 AuthOrder => 'mod_auth_file.c',
2659
2660 TimeoutLinger => 5,
2661
2662 IfModules => {
2663 'mod_delay.c' => {
2664 DelayEngine => 'off',
2665 },
2666 },
2667 };
2668
2669 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2670 $config);
2671
2672 # Open pipes, for use between the parent and child processes. Specifically,
2673 # the child will indicate when it's done with its test by writing a message
2674 # to the parent.
2675 my ($rfh, $wfh);
2676 unless (pipe($rfh, $wfh)) {
2677 die("Can't open pipe: $!");
2678 }
2679
2680 my $ex;
2681
2682 # Fork child
2683 $self->handle_sigchld();
2684 defined(my $pid = fork()) or die("Can't fork: $!");
2685 if ($pid) {
2686 eval {
2687 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2688 $client->login($setup->{user}, $setup->{passwd});
2689
2690 $client->quote('ABOR');
2691
2692 my $resp_code = $client->response_code();
2693 my $resp_msg = $client->response_msg();
2694 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
2695
2696 # Make sure the control connection did not close because of the abort.
2697 ($resp_code, $resp_msg) = $client->quit();
2698
2699 my $expected = 221;
2700 $self->assert($expected == $resp_code,
2701 test_msg("Expected response code $expected, got $resp_code"));
2702
2703 $expected = 'Goodbye.';
2704 $self->assert($expected eq $resp_msg,
2705 test_msg("Expected response message '$expected', got '$resp_msg'"));
2706 };
2707 if ($@) {
2708 $ex = $@;
2709 }
2710
2711 $wfh->print("done\n");
2712 $wfh->flush();
2713
2714 } else {
2715 eval { server_wait($setup->{config_file}, $rfh) };
2716 if ($@) {
2717 warn($@);
2718 exit 1;
2719 }
2720
2721 exit 0;
2722 }
2723
2724 # Stop server
2725 server_stop($setup->{pid_file});
2726 $self->assert_child_ok($pid);
2727
2728 test_cleanup($setup->{log_file}, $ex);
2729 }
2730
2731 sub data_eof_retr_ascii {
2732 my $self = shift;
2733 my $tmpdir = $self->{tmpdir};
2734 my $setup = test_setup($tmpdir, 'abor');
2735
2736 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
2737 if (open(my $fh, "> $test_file")) {
2738 print $fh "ABCDEFG\n" x 40960;
2739
2740 unless (close($fh)) {
2741 die("Can't write $test_file: $!");
2742 }
2743
2744 } else {
2745 die("Can't open $test_file: $!");
2746 }
2747
2748 my $config = {
2749 PidFile => $setup->{pid_file},
2750 ScoreboardFile => $setup->{scoreboard_file},
2751 SystemLog => $setup->{log_file},
2752 TraceLog => $setup->{log_file},
2753 Trace => 'DEFAULT:10 data:20',
2754
2755 AuthUserFile => $setup->{auth_user_file},
2756 AuthGroupFile => $setup->{auth_group_file},
2757 AuthOrder => 'mod_auth_file.c',
2758
2759 TimeoutLinger => 5,
2760
2761 IfModules => {
2762 'mod_delay.c' => {
2763 DelayEngine => 'off',
2764 },
2765 },
2766 };
2767
2768 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2769 $config);
2770
2771 # Open pipes, for use between the parent and child processes. Specifically,
2772 # the child will indicate when it's done with its test by writing a message
2773 # to the parent.
2774 my ($rfh, $wfh);
2775 unless (pipe($rfh, $wfh)) {
2776 die("Can't open pipe: $!");
2777 }
2778
2779 my $ex;
2780
2781 # Fork child
2782 $self->handle_sigchld();
2783 defined(my $pid = fork()) or die("Can't fork: $!");
2784 if ($pid) {
2785 eval {
2786 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2787 $client->login($setup->{user}, $setup->{passwd});
2788 $client->pasv();
2789 $client->type('ascii');
2790
2791 my $conn = $client->retr_raw($test_file);
2792 unless ($conn) {
2793 die("Failed to RETR: " . $client->response_code() . " " .
2794 $client->response_msg());
2795 }
2796
2797 # Read 128 bytes of the file, then abort the download
2798 my $buf;
2799 $conn->read($buf, 128, 30);
2800 $conn->_close();
2801
2802 # There is a potential race here, between data EOF and our next command.
2803 # We thus sleep here, to let the data EOF win the race. With that,
2804 # we should now receive our end-of-transfer response.
2805 sleep(1);
2806
2807 my ($resp_code, $resp_msg) = $client->read_response();
2808
2809 my $expected = 426;
2810 $self->assert($expected == $resp_code,
2811 test_msg("Expected response code $expected, got $resp_code"));
2812
2813 $expected = 'Transfer aborted. Data connection closed';
2814 $self->assert($expected eq $resp_msg,
2815 test_msg("Expected response message '$expected', got '$resp_msg'"));
2816
2817 # Make sure the control connection did not close because of the abort.
2818 ($resp_code, $resp_msg) = $client->quit();
2819
2820 $expected = 221;
2821 $self->assert($expected == $resp_code,
2822 test_msg("Expected response code $expected, got $resp_code"));
2823
2824 $expected = 'Goodbye.';
2825 $self->assert($expected eq $resp_msg,
2826 test_msg("Expected response message '$expected', got '$resp_msg'"));
2827 };
2828 if ($@) {
2829 $ex = $@;
2830 }
2831
2832 $wfh->print("done\n");
2833 $wfh->flush();
2834
2835 } else {
2836 eval { server_wait($setup->{config_file}, $rfh) };
2837 if ($@) {
2838 warn($@);
2839 exit 1;
2840 }
2841
2842 exit 0;
2843 }
2844
2845 # Stop server
2846 server_stop($setup->{pid_file});
2847 $self->assert_child_ok($pid);
2848
2849 test_cleanup($setup->{log_file}, $ex);
2850 }
2851
2852 sub data_eof_retr_binary_with_sendfile {
2853 my $self = shift;
2854 my $tmpdir = $self->{tmpdir};
2855 my $setup = test_setup($tmpdir, 'abor');
2856
2857 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
2858 if (open(my $fh, "> $test_file")) {
2859 print $fh "ABCDEFG\n" x 40960;
2860
2861 unless (close($fh)) {
2862 die("Can't write $test_file: $!");
2863 }
2864
2865 } else {
2866 die("Can't open $test_file: $!");
2867 }
2868
2869 my $config = {
2870 PidFile => $setup->{pid_file},
2871 ScoreboardFile => $setup->{scoreboard_file},
2872 SystemLog => $setup->{log_file},
2873 TraceLog => $setup->{log_file},
2874 Trace => 'DEFAULT:10 data:20',
2875
2876 AuthUserFile => $setup->{auth_user_file},
2877 AuthGroupFile => $setup->{auth_group_file},
2878 AuthOrder => 'mod_auth_file.c',
2879
2880 TimeoutLinger => 5,
2881
2882 IfModules => {
2883 'mod_delay.c' => {
2884 DelayEngine => 'off',
2885 },
2886 },
2887 };
2888
2889 if (feature_have_feature_enabled('sendfile')) {
2890 $config->{UseSendfile} = 'on';
2891 }
2892
2893 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2894 $config);
2895
2896 # Open pipes, for use between the parent and child processes. Specifically,
2897 # the child will indicate when it's done with its test by writing a message
2898 # to the parent.
2899 my ($rfh, $wfh);
2900 unless (pipe($rfh, $wfh)) {
2901 die("Can't open pipe: $!");
2902 }
2903
2904 my $ex;
2905
2906 # Fork child
2907 $self->handle_sigchld();
2908 defined(my $pid = fork()) or die("Can't fork: $!");
2909 if ($pid) {
2910 eval {
2911 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2912 $client->login($setup->{user}, $setup->{passwd});
2913 $client->pasv();
2914 $client->type('binary');
2915
2916 my $conn = $client->retr_raw($test_file);
2917 unless ($conn) {
2918 die("Failed to RETR: " . $client->response_code() . " " .
2919 $client->response_msg());
2920 }
2921
2922 # Read 128 bytes of the file, then abort the download
2923 my $buf;
2924 $conn->read($buf, 128, 30);
2925 $conn->_close();
2926
2927 # With sendfile support, it's probably that the entire file was already
2928 # sent. Thus we need to expect the 226 transfer response here.
2929 my ($resp_code, $resp_msg) = $client->read_response();
2930 $self->assert_transfer_ok($resp_code, $resp_msg);
2931
2932 # Make sure the control connection did not close because of the abort.
2933 ($resp_code, $resp_msg) = $client->quit();
2934
2935 my $expected = 221;
2936 $self->assert($expected == $resp_code,
2937 test_msg("Expected response code $expected, got $resp_code"));
2938
2939 $expected = 'Goodbye.';
2940 $self->assert($expected eq $resp_msg,
2941 test_msg("Expected response message '$expected', got '$resp_msg'"));
2942 };
2943 if ($@) {
2944 $ex = $@;
2945 }
2946
2947 $wfh->print("done\n");
2948 $wfh->flush();
2949
2950 } else {
2951 eval { server_wait($setup->{config_file}, $rfh) };
2952 if ($@) {
2953 warn($@);
2954 exit 1;
2955 }
2956
2957 exit 0;
2958 }
2959
2960 # Stop server
2961 server_stop($setup->{pid_file});
2962 $self->assert_child_ok($pid);
2963
2964 test_cleanup($setup->{log_file}, $ex);
2965 }
2966
2967 sub data_eof_retr_binary_without_sendfile {
2968 my $self = shift;
2969 my $tmpdir = $self->{tmpdir};
2970 my $setup = test_setup($tmpdir, 'abor');
2971
2972 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
2973 if (open(my $fh, "> $test_file")) {
2974 print $fh "ABCDEFG\n" x 40960;
2975
2976 unless (close($fh)) {
2977 die("Can't write $test_file: $!");
2978 }
2979
2980 } else {
2981 die("Can't open $test_file: $!");
2982 }
2983
2984 my $config = {
2985 PidFile => $setup->{pid_file},
2986 ScoreboardFile => $setup->{scoreboard_file},
2987 SystemLog => $setup->{log_file},
2988 TraceLog => $setup->{log_file},
2989 Trace => 'DEFAULT:10 data:20',
2990
2991 AuthUserFile => $setup->{auth_user_file},
2992 AuthGroupFile => $setup->{auth_group_file},
2993 AuthOrder => 'mod_auth_file.c',
2994
2995 TimeoutLinger => 5,
2996 UseSendfile => 'off',
2997
2998 IfModules => {
2999 'mod_delay.c' => {
3000 DelayEngine => 'off',
3001 },
3002 },
3003 };
3004
3005 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3006 $config);
3007
3008 # Open pipes, for use between the parent and child processes. Specifically,
3009 # the child will indicate when it's done with its test by writing a message
3010 # to the parent.
3011 my ($rfh, $wfh);
3012 unless (pipe($rfh, $wfh)) {
3013 die("Can't open pipe: $!");
3014 }
3015
3016 my $ex;
3017
3018 # Fork child
3019 $self->handle_sigchld();
3020 defined(my $pid = fork()) or die("Can't fork: $!");
3021 if ($pid) {
3022 eval {
3023 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3024 $client->login($setup->{user}, $setup->{passwd});
3025 $client->pasv();
3026 $client->type('binary');
3027
3028 my $conn = $client->retr_raw($test_file);
3029 unless ($conn) {
3030 die("Failed to RETR: " . $client->response_code() . " " .
3031 $client->response_msg());
3032 }
3033
3034 # Read 128 bytes of the file, then abort the download
3035 my $buf;
3036 $conn->read($buf, 128, 30);
3037 $conn->_close();
3038
3039 # There is a potential race here, between data EOF and our next command.
3040 # We thus sleep here, to let the data EOF win the race. With that,
3041 # we should now receive our end-of-transfer response.
3042 sleep(1);
3043
3044 my ($resp_code, $resp_msg) = $client->read_response();
3045
3046 my $expected = 426;
3047 $self->assert($expected == $resp_code,
3048 test_msg("Expected response code $expected, got $resp_code"));
3049
3050 $expected = 'Transfer aborted. Data connection closed';
3051 $self->assert($expected eq $resp_msg,
3052 test_msg("Expected response message '$expected', got '$resp_msg'"));
3053
3054 # Make sure the control connection did not close because of the abort.
3055 ($resp_code, $resp_msg) = $client->quit();
3056
3057 $expected = 221;
3058 $self->assert($expected == $resp_code,
3059 test_msg("Expected response code $expected, got $resp_code"));
3060
3061 $expected = 'Goodbye.';
3062 $self->assert($expected eq $resp_msg,
3063 test_msg("Expected response message '$expected', got '$resp_msg'"));
3064 };
3065 if ($@) {
3066 $ex = $@;
3067 }
3068
3069 $wfh->print("done\n");
3070 $wfh->flush();
3071
3072 } else {
3073 eval { server_wait($setup->{config_file}, $rfh) };
3074 if ($@) {
3075 warn($@);
3076 exit 1;
3077 }
3078
3079 exit 0;
3080 }
3081
3082 # Stop server
3083 server_stop($setup->{pid_file});
3084 $self->assert_child_ok($pid);
3085
3086 test_cleanup($setup->{log_file}, $ex);
3087 }
3088
3089 sub data_eof_stor_ascii {
3090 my $self = shift;
3091 my $tmpdir = $self->{tmpdir};
3092 my $setup = test_setup($tmpdir, 'abor');
3093
3094 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
3095
3096 my $config = {
3097 PidFile => $setup->{pid_file},
3098 ScoreboardFile => $setup->{scoreboard_file},
3099 SystemLog => $setup->{log_file},
3100 TraceLog => $setup->{log_file},
3101 Trace => 'DEFAULT:10',
3102
3103 AuthUserFile => $setup->{auth_user_file},
3104 AuthGroupFile => $setup->{auth_group_file},
3105 AuthOrder => 'mod_auth_file.c',
3106
3107 TimeoutLinger => 5,
3108
3109 IfModules => {
3110 'mod_delay.c' => {
3111 DelayEngine => 'off',
3112 },
3113 },
3114 };
3115
3116 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3117 $config);
3118
3119 # Open pipes, for use between the parent and child processes. Specifically,
3120 # the child will indicate when it's done with its test by writing a message
3121 # to the parent.
3122 my ($rfh, $wfh);
3123 unless (pipe($rfh, $wfh)) {
3124 die("Can't open pipe: $!");
3125 }
3126
3127 my $ex;
3128
3129 # Fork child
3130 $self->handle_sigchld();
3131 defined(my $pid = fork()) or die("Can't fork: $!");
3132 if ($pid) {
3133 eval {
3134 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3135 $client->login($setup->{user}, $setup->{passwd});
3136 $client->pasv();
3137 $client->type('ascii');
3138
3139 my $conn = $client->stor_raw($test_file);
3140 unless ($conn) {
3141 die("Failed to STOR: " . $client->response_code() . " " .
3142 $client->response_msg());
3143 }
3144
3145 # Write data to the file, then abort the upload
3146 my $buf = "A\r\nB\r\nC\r\nD\r\n";
3147 $conn->write($buf, length($buf));
3148 $conn->_close();
3149
3150 # There is a potential race here, between data EOF and our next command.
3151 # We thus sleep here, to let the data EOF win the race. With that,
3152 # we should now receive our end-of-transfer response.
3153 sleep(1);
3154
3155 my ($resp_code, $resp_msg) = $client->read_response();
3156
3157 # Since the server does not know, a priori, how much data we will be
3158 # sending, it cannot tell when we completed successfully or not. Thus
3159 # an EOF on upload is always a "successful transfer".
3160 $self->assert_transfer_ok($resp_code, $resp_msg);
3161
3162 # Make sure the control connection did not close because of the abort.
3163 ($resp_code, $resp_msg) = $client->quit();
3164
3165 my $expected = 221;
3166 $self->assert($expected == $resp_code,
3167 test_msg("Expected response message $expected, got $resp_code"));
3168
3169 $expected = 'Goodbye.';
3170 $self->assert($expected eq $resp_msg,
3171 test_msg("Expected response message '$expected', got '$resp_msg'"));
3172 };
3173 if ($@) {
3174 $ex = $@;
3175 }
3176
3177 $wfh->print("done\n");
3178 $wfh->flush();
3179
3180 } else {
3181 eval { server_wait($setup->{config_file}, $rfh) };
3182 if ($@) {
3183 warn($@);
3184 exit 1;
3185 }
3186
3187 exit 0;
3188 }
3189
3190 # Stop server
3191 server_stop($setup->{pid_file});
3192 $self->assert_child_ok($pid);
3193
3194 test_cleanup($setup->{log_file}, $ex);
3195 }
3196
3197 sub data_eof_stor_binary {
3198 my $self = shift;
3199 my $tmpdir = $self->{tmpdir};
3200 my $setup = test_setup($tmpdir, 'abor');
3201
3202 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
3203
3204 my $config = {
3205 PidFile => $setup->{pid_file},
3206 ScoreboardFile => $setup->{scoreboard_file},
3207 SystemLog => $setup->{log_file},
3208 TraceLog => $setup->{log_file},
3209 Trace => 'DEFAULT:10',
3210
3211 AuthUserFile => $setup->{auth_user_file},
3212 AuthGroupFile => $setup->{auth_group_file},
3213 AuthOrder => 'mod_auth_file.c',
3214
3215 TimeoutLinger => 5,
3216
3217 IfModules => {
3218 'mod_delay.c' => {
3219 DelayEngine => 'off',
3220 },
3221 },
3222 };
3223
3224 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3225 $config);
3226
3227 # Open pipes, for use between the parent and child processes. Specifically,
3228 # the child will indicate when it's done with its test by writing a message
3229 # to the parent.
3230 my ($rfh, $wfh);
3231 unless (pipe($rfh, $wfh)) {
3232 die("Can't open pipe: $!");
3233 }
3234
3235 my $ex;
3236
3237 # Fork child
3238 $self->handle_sigchld();
3239 defined(my $pid = fork()) or die("Can't fork: $!");
3240 if ($pid) {
3241 eval {
3242 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3243 $client->login($setup->{user}, $setup->{passwd});
3244 $client->pasv();
3245 $client->type('binary');
3246
3247 my $conn = $client->stor_raw($test_file);
3248 unless ($conn) {
3249 die("Failed to STOR: " . $client->response_code() . " " .
3250 $client->response_msg());
3251 }
3252
3253 # Write data to the file, then abort the upload
3254 my $buf = "A\r\nB\r\nC\r\nD\r\n";
3255 $conn->write($buf, length($buf));
3256 $conn->_close();
3257
3258 # There is a potential race here, between data EOF and our next command.
3259 # We thus sleep here, to let the data EOF win the race. With that,
3260 # we should now receive our end-of-transfer response.
3261 sleep(1);
3262
3263 my ($resp_code, $resp_msg) = $client->read_response();
3264
3265 # Since the server does not know, a priori, how much data we will be
3266 # sending, it cannot tell when we completed successfully or not. Thus
3267 # an EOF on upload is always a "successful transfer".
3268 $self->assert_transfer_ok($resp_code, $resp_msg);
3269
3270 # Make sure the control connection did not close because of the abort.
3271 ($resp_code, $resp_msg) = $client->quit();
3272
3273 my $expected = 221;
3274 $self->assert($expected == $resp_code,
3275 test_msg("Expected response message $expected, got $resp_code"));
3276
3277 $expected = 'Goodbye.';
3278 $self->assert($expected eq $resp_msg,
3279 test_msg("Expected response message '$expected', got '$resp_msg'"));
3280 };
3281 if ($@) {
3282 $ex = $@;
3283 }
3284
3285 $wfh->print("done\n");
3286 $wfh->flush();
3287
3288 } else {
3289 eval { server_wait($setup->{config_file}, $rfh) };
3290 if ($@) {
3291 warn($@);
3292 exit 1;
3293 }
3294
3295 exit 0;
3296 }
3297
3298 # Stop server
3299 server_stop($setup->{pid_file});
3300 $self->assert_child_ok($pid);
3301
3302 test_cleanup($setup->{log_file}, $ex);
3303 }
3304
3305 sub data_eof_list {
3306 my $self = shift;
3307 my $tmpdir = $self->{tmpdir};
3308 my $setup = test_setup($tmpdir, 'abor');
3309
3310 my $config = {
3311 PidFile => $setup->{pid_file},
3312 ScoreboardFile => $setup->{scoreboard_file},
3313 SystemLog => $setup->{log_file},
3314 TraceLog => $setup->{log_file},
3315 Trace => 'DEFAULT:10',
3316
3317 AuthUserFile => $setup->{auth_user_file},
3318 AuthGroupFile => $setup->{auth_group_file},
3319 AuthOrder => 'mod_auth_file.c',
3320
3321 TimeoutLinger => 5,
3322
3323 IfModules => {
3324 'mod_delay.c' => {
3325 DelayEngine => 'off',
3326 },
3327 },
3328 };
3329
3330 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3331 $config);
3332
3333 # Open pipes, for use between the parent and child processes. Specifically,
3334 # the child will indicate when it's done with its test by writing a message
3335 # to the parent.
3336 my ($rfh, $wfh);
3337 unless (pipe($rfh, $wfh)) {
3338 die("Can't open pipe: $!");
3339 }
3340
3341 my $ex;
3342
3343 # Fork child
3344 $self->handle_sigchld();
3345 defined(my $pid = fork()) or die("Can't fork: $!");
3346 if ($pid) {
3347 eval {
3348 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3349 $client->login($setup->{user}, $setup->{passwd});
3350
3351 # Use a recursive listing, to generate more data, such that it will
3352 # not all fit in the transfer buffer, so we can interrupt the buffer.
3353 # A too-small request will fit in the buffer, and be fulfilled, before
3354 # our abort is read.
3355 my $conn = $client->list_raw('-R /');
3356 unless ($conn) {
3357 die("Failed to LIST: " . $client->response_code() . " " .
3358 $client->response_msg());
3359 }
3360
3361 # Read 128 bytes of data, then abort the download
3362 my $buf;
3363 $conn->read($buf, 128, 30);
3364 $conn->_close();
3365
3366 # There is a potential race here, between data EOF and our next command.
3367 # We thus sleep here, to let the data EOF win the race. With that,
3368 # we should now receive our end-of-transfer response.
3369 sleep(1);
3370
3371 my ($resp_code, $resp_msg) = $client->read_response();
3372
3373 my $expected = 426;
3374 $self->assert($expected == $resp_code,
3375 test_msg("Expected response code $expected, got $resp_code"));
3376
3377 $expected = 'Transfer aborted. Data connection closed';
3378 $self->assert($expected eq $resp_msg,
3379 test_msg("Expected response message '$expected', got '$resp_msg'"));
3380
3381 # Make sure the control connection did not close because of the abort.
3382 ($resp_code, $resp_msg) = $client->quit();
3383
3384 $expected = 221;
3385 $self->assert($expected == $resp_code,
3386 test_msg("Expected response code $expected, got $resp_code"));
3387
3388 $expected = 'Goodbye.';
3389 $self->assert($expected eq $resp_msg,
3390 test_msg("Expected response message '$expected', got '$resp_msg'"));
3391 };
3392 if ($@) {
3393 $ex = $@;
3394 }
3395
3396 $wfh->print("done\n");
3397 $wfh->flush();
3398
3399 } else {
3400 eval { server_wait($setup->{config_file}, $rfh) };
3401 if ($@) {
3402 warn($@);
3403 exit 1;
3404 }
3405
3406 exit 0;
3407 }
3408
3409 # Stop server
3410 server_stop($setup->{pid_file});
3411 $self->assert_child_ok($pid);
3412
3413 test_cleanup($setup->{log_file}, $ex);
3414 }
3415
3416 sub data_eof_mlsd {
3417 my $self = shift;
3418 my $tmpdir = $self->{tmpdir};
3419 my $setup = test_setup($tmpdir, 'abor');
3420
3421 # Generate enough files in the directory to lead to a large enough response,
3422 # such that the response does not all fit in the initial transfer buffer.
3423 for (my $i = 0; $i < 5000; $i++) {
3424 my $path = File::Spec->rel2abs("$tmpdir/$i.dat");
3425
3426 if (open(my $fh, "> $path")) {
3427 close($fh);
3428
3429 } else {
3430 die("Can't open $path: $!");
3431 }
3432 }
3433
3434 my $config = {
3435 PidFile => $setup->{pid_file},
3436 ScoreboardFile => $setup->{scoreboard_file},
3437 SystemLog => $setup->{log_file},
3438 TraceLog => $setup->{log_file},
3439 Trace => 'DEFAULT:10 lock:0 scoreboard:0',
3440
3441 AuthUserFile => $setup->{auth_user_file},
3442 AuthGroupFile => $setup->{auth_group_file},
3443 AuthOrder => 'mod_auth_file.c',
3444
3445 TimeoutLinger => 5,
3446
3447 IfModules => {
3448 'mod_delay.c' => {
3449 DelayEngine => 'off',
3450 },
3451 },
3452 };
3453
3454 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3455 $config);
3456
3457 # Open pipes, for use between the parent and child processes. Specifically,
3458 # the child will indicate when it's done with its test by writing a message
3459 # to the parent.
3460 my ($rfh, $wfh);
3461 unless (pipe($rfh, $wfh)) {
3462 die("Can't open pipe: $!");
3463 }
3464
3465 my $ex;
3466
3467 # Fork child
3468 $self->handle_sigchld();
3469 defined(my $pid = fork()) or die("Can't fork: $!");
3470 if ($pid) {
3471 eval {
3472 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3473 $client->login($setup->{user}, $setup->{passwd});
3474
3475 my $conn = $client->mlsd_raw($tmpdir);
3476 unless ($conn) {
3477 die("Failed to MLSD: " . $client->response_code() . " " .
3478 $client->response_msg());
3479 }
3480
3481 # Read 8 bytes of data, then abort the download
3482 my $buf;
3483 $conn->read($buf, 8, 30);
3484 $conn->_close();
3485
3486 # There is a potential race here, between data EOF and our next command.
3487 # We thus sleep here, to let the data EOF win the race. With that,
3488 # we should now receive our end-of-transfer response.
3489 sleep(1);
3490
3491 my ($resp_code, $resp_msg) = $client->read_response();
3492
3493 my $expected = 426;
3494 $self->assert($expected == $resp_code,
3495 test_msg("Expected response code $expected, got $resp_code"));
3496
3497 $expected = 'Transfer aborted. Data connection closed';
3498 $self->assert($expected eq $resp_msg,
3499 test_msg("Expected response message '$expected', got '$resp_msg'"));
3500
3501 # Make sure the control connection did not close because of the abort.
3502 ($resp_code, $resp_msg) = $client->quit();
3503
3504 $expected = 221;
3505 $self->assert($expected == $resp_code,
3506 test_msg("Expected response code $expected, got $resp_code"));
3507
3508 $expected = 'Goodbye.';
3509 $self->assert($expected eq $resp_msg,
3510 test_msg("Expected response message '$expected', got '$resp_msg'"));
3511 };
3512 if ($@) {
3513 $ex = $@;
3514 }
3515
3516 $wfh->print("done\n");
3517 $wfh->flush();
3518
3519 } else {
3520 eval { server_wait($setup->{config_file}, $rfh) };
3521 if ($@) {
3522 warn($@);
3523 exit 1;
3524 }
3525
3526 exit 0;
3527 }
3528
3529 # Stop server
3530 server_stop($setup->{pid_file});
3531 $self->assert_child_ok($pid);
3532
3533 test_cleanup($setup->{log_file}, $ex);
3534 }
3535
3536 sub data_eof_before_abor_retr_ascii {
3537 my $self = shift;
3538 my $tmpdir = $self->{tmpdir};
3539 my $setup = test_setup($tmpdir, 'abor');
3540
3541 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
3542 if (open(my $fh, "> $test_file")) {
3543 print $fh "ABCDEFG\n" x 40960;
3544
3545 unless (close($fh)) {
3546 die("Can't write $test_file: $!");
3547 }
3548
3549 } else {
3550 die("Can't open $test_file: $!");
3551 }
3552
3553 my $config = {
3554 PidFile => $setup->{pid_file},
3555 ScoreboardFile => $setup->{scoreboard_file},
3556 SystemLog => $setup->{log_file},
3557 TraceLog => $setup->{log_file},
3558 Trace => 'DEFAULT:10 data:20',
3559
3560 AuthUserFile => $setup->{auth_user_file},
3561 AuthGroupFile => $setup->{auth_group_file},
3562 AuthOrder => 'mod_auth_file.c',
3563
3564 TimeoutLinger => 5,
3565
3566 IfModules => {
3567 'mod_delay.c' => {
3568 DelayEngine => 'off',
3569 },
3570 },
3571 };
3572
3573 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3574 $config);
3575
3576 # Open pipes, for use between the parent and child processes. Specifically,
3577 # the child will indicate when it's done with its test by writing a message
3578 # to the parent.
3579 my ($rfh, $wfh);
3580 unless (pipe($rfh, $wfh)) {
3581 die("Can't open pipe: $!");
3582 }
3583
3584 my $ex;
3585
3586 # Fork child
3587 $self->handle_sigchld();
3588 defined(my $pid = fork()) or die("Can't fork: $!");
3589 if ($pid) {
3590 eval {
3591 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3592 $client->login($setup->{user}, $setup->{passwd});
3593 $client->pasv();
3594 $client->type('ascii');
3595
3596 my $conn = $client->retr_raw($test_file);
3597 unless ($conn) {
3598 die("Failed to RETR: " . $client->response_code() . " " .
3599 $client->response_msg());
3600 }
3601
3602 # Read 128 bytes of the file, then abort the download
3603 my $buf;
3604 $conn->read($buf, 128, 30);
3605 $conn->_close();
3606
3607 # There is a potential race here, between data EOF and our next command.
3608 # We thus sleep here, to let the data EOF win the race. With that,
3609 # we should now receive our end-of-transfer response.
3610 sleep(1);
3611
3612 my ($resp_code, $resp_msg) = $client->read_response();
3613
3614 my $expected = 426;
3615 $self->assert($expected == $resp_code,
3616 test_msg("Expected response code $expected, got $resp_code"));
3617
3618 $expected = 'Transfer aborted. Data connection closed';
3619 $self->assert($expected eq $resp_msg,
3620 test_msg("Expected response message '$expected', got '$resp_msg'"));
3621
3622 # We use the Net::FTP::abort() method here, so that we use, in this
3623 # order: data EOF, TCP OOB, ABOR.
3624 $client->abort();
3625 $resp_code = $client->response_code();
3626 $resp_msg = $client->response_msg();
3627
3628 $expected = 226;
3629 $self->assert($expected == $resp_code,
3630 test_msg("Expected response code $expected, got $resp_code"));
3631
3632 $expected = 'Abort successful';
3633 $self->assert($expected eq $resp_msg,
3634 test_msg("Expected response message '$expected', got '$resp_msg'"));
3635
3636 # Make sure the control connection did not close because of the abort.
3637 ($resp_code, $resp_msg) = $client->quit();
3638
3639 $expected = 221;
3640 $self->assert($expected == $resp_code,
3641 test_msg("Expected response code $expected, got $resp_code"));
3642
3643 $expected = 'Goodbye.';
3644 $self->assert($expected eq $resp_msg,
3645 test_msg("Expected response message '$expected', got '$resp_msg'"));
3646 };
3647 if ($@) {
3648 $ex = $@;
3649 }
3650
3651 $wfh->print("done\n");
3652 $wfh->flush();
3653
3654 } else {
3655 eval { server_wait($setup->{config_file}, $rfh) };
3656 if ($@) {
3657 warn($@);
3658 exit 1;
3659 }
3660
3661 exit 0;
3662 }
3663
3664 # Stop server
3665 server_stop($setup->{pid_file});
3666 $self->assert_child_ok($pid);
3667
3668 test_cleanup($setup->{log_file}, $ex);
3669 }
3670
3671 sub data_eof_before_abor_retr_binary_with_sendfile {
3672 my $self = shift;
3673 my $tmpdir = $self->{tmpdir};
3674 my $setup = test_setup($tmpdir, 'abor');
3675
3676 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
3677 if (open(my $fh, "> $test_file")) {
3678 print $fh "ABCDEFG\n" x 40960;
3679
3680 unless (close($fh)) {
3681 die("Can't write $test_file: $!");
3682 }
3683
3684 } else {
3685 die("Can't open $test_file: $!");
3686 }
3687
3688 my $config = {
3689 PidFile => $setup->{pid_file},
3690 ScoreboardFile => $setup->{scoreboard_file},
3691 SystemLog => $setup->{log_file},
3692 TraceLog => $setup->{log_file},
3693 Trace => 'DEFAULT:10 data:20',
3694
3695 AuthUserFile => $setup->{auth_user_file},
3696 AuthGroupFile => $setup->{auth_group_file},
3697 AuthOrder => 'mod_auth_file.c',
3698
3699 TimeoutLinger => 5,
3700
3701 IfModules => {
3702 'mod_delay.c' => {
3703 DelayEngine => 'off',
3704 },
3705 },
3706 };
3707
3708 if (feature_have_feature_enabled('sendfile')) {
3709 $config->{UseSendfile} = 'on';
3710 }
3711
3712 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3713 $config);
3714
3715 # Open pipes, for use between the parent and child processes. Specifically,
3716 # the child will indicate when it's done with its test by writing a message
3717 # to the parent.
3718 my ($rfh, $wfh);
3719 unless (pipe($rfh, $wfh)) {
3720 die("Can't open pipe: $!");
3721 }
3722
3723 my $ex;
3724
3725 # Fork child
3726 $self->handle_sigchld();
3727 defined(my $pid = fork()) or die("Can't fork: $!");
3728 if ($pid) {
3729 eval {
3730 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3731 $client->login($setup->{user}, $setup->{passwd});
3732 $client->pasv();
3733 $client->type('binary');
3734
3735 my $conn = $client->retr_raw($test_file);
3736 unless ($conn) {
3737 die("Failed to RETR: " . $client->response_code() . " " .
3738 $client->response_msg());
3739 }
3740
3741 # Read 128 bytes of the file, then abort the download
3742 my $buf;
3743 $conn->read($buf, 128, 30);
3744 $conn->_close();
3745
3746 # There is a potential race here, between data EOF and our next command.
3747 # We thus sleep here, to let the data EOF win the race. With that,
3748 # we should now receive our end-of-transfer response.
3749 sleep(1);
3750
3751 my ($resp_code, $resp_msg) = $client->read_response();
3752
3753 # We expect 226 here because sendfile will probably have successfully
3754 # written all of its bytes to the network.
3755 my $expected = 226;
3756 $self->assert($expected == $resp_code,
3757 test_msg("Expected response code $expected, got $resp_code"));
3758
3759 $expected = 'Transfer complete';
3760 $self->assert($expected eq $resp_msg,
3761 test_msg("Expected response message '$expected', got '$resp_msg'"));
3762
3763 # We use the Net::FTP::abort() method here, so that we use, in this
3764 # order: data EOF, TCP OOB, ABOR.
3765 $client->abort();
3766 $resp_code = $client->response_code();
3767 $resp_msg = $client->response_msg();
3768
3769 $expected = 226;
3770 $self->assert($expected == $resp_code,
3771 test_msg("Expected response code $expected, got $resp_code"));
3772
3773 $expected = 'Abort successful';
3774 $self->assert($expected eq $resp_msg,
3775 test_msg("Expected response message '$expected', got '$resp_msg'"));
3776
3777 # Make sure the control connection did not close because of the abort.
3778 ($resp_code, $resp_msg) = $client->quit();
3779
3780 $expected = 221;
3781 $self->assert($expected == $resp_code,
3782 test_msg("Expected response code $expected, got $resp_code"));
3783
3784 $expected = 'Goodbye.';
3785 $self->assert($expected eq $resp_msg,
3786 test_msg("Expected response message '$expected', got '$resp_msg'"));
3787 };
3788 if ($@) {
3789 $ex = $@;
3790 }
3791
3792 $wfh->print("done\n");
3793 $wfh->flush();
3794
3795 } else {
3796 eval { server_wait($setup->{config_file}, $rfh) };
3797 if ($@) {
3798 warn($@);
3799 exit 1;
3800 }
3801
3802 exit 0;
3803 }
3804
3805 # Stop server
3806 server_stop($setup->{pid_file});
3807 $self->assert_child_ok($pid);
3808
3809 test_cleanup($setup->{log_file}, $ex);
3810 }
3811
3812 sub data_eof_before_abor_retr_binary_without_sendfile {
3813 my $self = shift;
3814 my $tmpdir = $self->{tmpdir};
3815 my $setup = test_setup($tmpdir, 'abor');
3816
3817 my $test_file = File::Spec->rel2abs("$tmpdir/largefile.txt");
3818 if (open(my $fh, "> $test_file")) {
3819 print $fh "ABCDEFG\n" x 40960;
3820
3821 unless (close($fh)) {
3822 die("Can't write $test_file: $!");
3823 }
3824
3825 } else {
3826 die("Can't open $test_file: $!");
3827 }
3828
3829 my $config = {
3830 PidFile => $setup->{pid_file},
3831 ScoreboardFile => $setup->{scoreboard_file},
3832 SystemLog => $setup->{log_file},
3833 TraceLog => $setup->{log_file},
3834 Trace => 'DEFAULT:10 data:20',
3835
3836 AuthUserFile => $setup->{auth_user_file},
3837 AuthGroupFile => $setup->{auth_group_file},
3838 AuthOrder => 'mod_auth_file.c',
3839
3840 TimeoutLinger => 5,
3841 UseSendfile => 'off',
3842
3843 IfModules => {
3844 'mod_delay.c' => {
3845 DelayEngine => 'off',
3846 },
3847 },
3848 };
3849
3850 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3851 $config);
3852
3853 # Open pipes, for use between the parent and child processes. Specifically,
3854 # the child will indicate when it's done with its test by writing a message
3855 # to the parent.
3856 my ($rfh, $wfh);
3857 unless (pipe($rfh, $wfh)) {
3858 die("Can't open pipe: $!");
3859 }
3860
3861 my $ex;
3862
3863 # Fork child
3864 $self->handle_sigchld();
3865 defined(my $pid = fork()) or die("Can't fork: $!");
3866 if ($pid) {
3867 eval {
3868 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3869 $client->login($setup->{user}, $setup->{passwd});
3870 $client->pasv();
3871 $client->type('binary');
3872
3873 my $conn = $client->retr_raw($test_file);
3874 unless ($conn) {
3875 die("Failed to RETR: " . $client->response_code() . " " .
3876 $client->response_msg());
3877 }
3878
3879 # Read 128 bytes of the file, then abort the download
3880 my $buf;
3881 $conn->read($buf, 128, 30);
3882 $conn->_close();
3883
3884 # There is a potential race here, between data EOF and our next command.
3885 # We thus sleep here, to let the data EOF win the race. With that,
3886 # we should now receive our end-of-transfer response.
3887 sleep(1);
3888
3889 my ($resp_code, $resp_msg) = $client->read_response();
3890
3891 my $expected = 426;
3892 $self->assert($expected == $resp_code,
3893 test_msg("Expected response code $expected, got $resp_code"));
3894
3895 $expected = 'Transfer aborted. Data connection closed';
3896 $self->assert($expected eq $resp_msg,
3897 test_msg("Expected response message '$expected', got '$resp_msg'"));
3898
3899 # We use the Net::FTP::abort() method here, so that we use, in this
3900 # order: data EOF, TCP OOB, ABOR.
3901 $client->abort();
3902 $resp_code = $client->response_code();
3903 $resp_msg = $client->response_msg();
3904
3905 $expected = 226;
3906 $self->assert($expected == $resp_code,
3907 test_msg("Expected response code $expected, got $resp_code"));
3908
3909 $expected = 'Abort successful';
3910 $self->assert($expected eq $resp_msg,
3911 test_msg("Expected response message '$expected', got '$resp_msg'"));
3912
3913 # Make sure the control connection did not close because of the abort.
3914 ($resp_code, $resp_msg) = $client->quit();
3915
3916 $expected = 221;
3917 $self->assert($expected == $resp_code,
3918 test_msg("Expected response code $expected, got $resp_code"));
3919
3920 $expected = 'Goodbye.';
3921 $self->assert($expected eq $resp_msg,
3922 test_msg("Expected response message '$expected', got '$resp_msg'"));
3923 };
3924 if ($@) {
3925 $ex = $@;
3926 }
3927
3928 $wfh->print("done\n");
3929 $wfh->flush();
3930
3931 } else {
3932 eval { server_wait($setup->{config_file}, $rfh) };
3933 if ($@) {
3934 warn($@);
3935 exit 1;
3936 }
3937
3938 exit 0;
3939 }
3940
3941 # Stop server
3942 server_stop($setup->{pid_file});
3943 $self->assert_child_ok($pid);
3944
3945 test_cleanup($setup->{log_file}, $ex);
3946 }
3947
3948 sub data_eof_before_abor_stor_ascii {
3949 my $self = shift;
3950 my $tmpdir = $self->{tmpdir};
3951 my $setup = test_setup($tmpdir, 'abor');
3952
3953 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
3954
3955 my $config = {
3956 PidFile => $setup->{pid_file},
3957 ScoreboardFile => $setup->{scoreboard_file},
3958 SystemLog => $setup->{log_file},
3959 TraceLog => $setup->{log_file},
3960 Trace => 'DEFAULT:10',
3961
3962 AuthUserFile => $setup->{auth_user_file},
3963 AuthGroupFile => $setup->{auth_group_file},
3964 AuthOrder => 'mod_auth_file.c',
3965
3966 TimeoutLinger => 5,
3967
3968 IfModules => {
3969 'mod_delay.c' => {
3970 DelayEngine => 'off',
3971 },
3972 },
3973 };
3974
3975 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3976 $config);
3977
3978 # Open pipes, for use between the parent and child processes. Specifically,
3979 # the child will indicate when it's done with its test by writing a message
3980 # to the parent.
3981 my ($rfh, $wfh);
3982 unless (pipe($rfh, $wfh)) {
3983 die("Can't open pipe: $!");
3984 }
3985
3986 my $ex;
3987
3988 # Fork child
3989 $self->handle_sigchld();
3990 defined(my $pid = fork()) or die("Can't fork: $!");
3991 if ($pid) {
3992 eval {
3993 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3994 $client->login($setup->{user}, $setup->{passwd});
3995 $client->pasv();
3996 $client->type('ascii');
3997
3998 my $conn = $client->stor_raw($test_file);
3999 unless ($conn) {
4000 die("Failed to STOR: " . $client->response_code() . " " .
4001 $client->response_msg());
4002 }
4003
4004 # Write data to the file, then abort the upload
4005 my $buf = "A\r\nB\r\nC\r\nD\r\n";
4006 $conn->write($buf, length($buf));
4007 $conn->_close();
4008
4009 # There is a potential race here, between data EOF and our next command.
4010 # We thus sleep here, to let the data EOF win the race. With that,
4011 # we should now receive our end-of-transfer response.
4012 sleep(1);
4013
4014 my ($resp_code, $resp_msg) = $client->read_response();
4015
4016 # Since the server does not know, a priori, how much data we will be
4017 # sending, it cannot tell when we completed successfully or not. Thus
4018 # an EOF on upload is always a "successful transfer".
4019 $self->assert_transfer_ok($resp_code, $resp_msg);
4020
4021 # We use the Net::FTP::abort() method here, so that we use, in this
4022 # order: data EOF, TCP OOB, ABOR.
4023 $client->abort();
4024 $resp_code = $client->response_code();
4025 $resp_msg = $client->response_msg();
4026
4027 my $expected = 226;
4028 $self->assert($expected == $resp_code,
4029 test_msg("Expected response code $expected, got $resp_code"));
4030
4031 $expected = 'Abort successful';
4032 $self->assert($expected eq $resp_msg,
4033 test_msg("Expected response message '$expected', got '$resp_msg'"));
4034
4035 # Make sure the control connection did not close because of the abort.
4036 ($resp_code, $resp_msg) = $client->quit();
4037
4038 $expected = 221;
4039 $self->assert($expected == $resp_code,
4040 test_msg("Expected response message $expected, got $resp_code"));
4041
4042 $expected = 'Goodbye.';
4043 $self->assert($expected eq $resp_msg,
4044 test_msg("Expected response message '$expected', got '$resp_msg'"));
4045 };
4046 if ($@) {
4047 $ex = $@;
4048 }
4049
4050 $wfh->print("done\n");
4051 $wfh->flush();
4052
4053 } else {
4054 eval { server_wait($setup->{config_file}, $rfh) };
4055 if ($@) {
4056 warn($@);
4057 exit 1;
4058 }
4059
4060 exit 0;
4061 }
4062
4063 # Stop server
4064 server_stop($setup->{pid_file});
4065 $self->assert_child_ok($pid);
4066
4067 test_cleanup($setup->{log_file}, $ex);
4068 }
4069
4070 sub data_eof_before_abor_stor_binary {
4071 my $self = shift;
4072 my $tmpdir = $self->{tmpdir};
4073 my $setup = test_setup($tmpdir, 'abor');
4074
4075 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
4076
4077 my $config = {
4078 PidFile => $setup->{pid_file},
4079 ScoreboardFile => $setup->{scoreboard_file},
4080 SystemLog => $setup->{log_file},
4081 TraceLog => $setup->{log_file},
4082 Trace => 'DEFAULT:10',
4083
4084 AuthUserFile => $setup->{auth_user_file},
4085 AuthGroupFile => $setup->{auth_group_file},
4086 AuthOrder => 'mod_auth_file.c',
4087
4088 TimeoutLinger => 5,
4089
4090 IfModules => {
4091 'mod_delay.c' => {
4092 DelayEngine => 'off',
4093 },
4094 },
4095 };
4096
4097 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4098 $config);
4099
4100 # Open pipes, for use between the parent and child processes. Specifically,
4101 # the child will indicate when it's done with its test by writing a message
4102 # to the parent.
4103 my ($rfh, $wfh);
4104 unless (pipe($rfh, $wfh)) {
4105 die("Can't open pipe: $!");
4106 }
4107
4108 my $ex;
4109
4110 # Fork child
4111 $self->handle_sigchld();
4112 defined(my $pid = fork()) or die("Can't fork: $!");
4113 if ($pid) {
4114 eval {
4115 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4116 $client->login($setup->{user}, $setup->{passwd});
4117 $client->pasv();
4118 $client->type('binary');
4119
4120 my $conn = $client->stor_raw($test_file);
4121 unless ($conn) {
4122 die("Failed to STOR: " . $client->response_code() . " " .
4123 $client->response_msg());
4124 }
4125
4126 # Write data to the file, then abort the upload
4127 my $buf = "A\r\nB\r\nC\r\nD\r\n";
4128 $conn->write($buf, length($buf));
4129 $conn->_close();
4130
4131 # There is a potential race here, between data EOF and our next command.
4132 # We thus sleep here, to let the data EOF win the race. With that,
4133 # we should now receive our end-of-transfer response.
4134 sleep(1);
4135
4136 my ($resp_code, $resp_msg) = $client->read_response();
4137
4138 # Since the server does not know, a priori, how much data we will be
4139 # sending, it cannot tell when we completed successfully or not. Thus
4140 # an EOF on upload is always a "successful transfer".
4141 $self->assert_transfer_ok($resp_code, $resp_msg);
4142
4143 # We use the Net::FTP::abort() method here, so that we use, in this
4144 # order: data EOF, TCP OOB, ABOR.
4145 $client->abort();
4146 $resp_code = $client->response_code();
4147 $resp_msg = $client->response_msg();
4148
4149 my $expected = 226;
4150 $self->assert($expected == $resp_code,
4151 test_msg("Expected response code $expected, got $resp_code"));
4152
4153 $expected = 'Abort successful';
4154 $self->assert($expected eq $resp_msg,
4155 test_msg("Expected response message '$expected', got '$resp_msg'"));
4156
4157 # Make sure the control connection did not close because of the abort.
4158 ($resp_code, $resp_msg) = $client->quit();
4159
4160 $expected = 221;
4161 $self->assert($expected == $resp_code,
4162 test_msg("Expected response message $expected, got $resp_code"));
4163
4164 $expected = 'Goodbye.';
4165 $self->assert($expected eq $resp_msg,
4166 test_msg("Expected response message '$expected', got '$resp_msg'"));
4167 };
4168 if ($@) {
4169 $ex = $@;
4170 }
4171
4172 $wfh->print("done\n");
4173 $wfh->flush();
4174
4175 } else {
4176 eval { server_wait($setup->{config_file}, $rfh) };
4177 if ($@) {
4178 warn($@);
4179 exit 1;
4180 }
4181
4182 exit 0;
4183 }
4184
4185 # Stop server
4186 server_stop($setup->{pid_file});
4187 $self->assert_child_ok($pid);
4188
4189 test_cleanup($setup->{log_file}, $ex);
4190 }
4191
4192 sub data_eof_before_abor_list {
4193 my $self = shift;
4194 my $tmpdir = $self->{tmpdir};
4195 my $setup = test_setup($tmpdir, 'abor');
4196
4197 my $config = {
4198 PidFile => $setup->{pid_file},
4199 ScoreboardFile => $setup->{scoreboard_file},
4200 SystemLog => $setup->{log_file},
4201 TraceLog => $setup->{log_file},
4202 Trace => 'DEFAULT:10',
4203
4204 AuthUserFile => $setup->{auth_user_file},
4205 AuthGroupFile => $setup->{auth_group_file},
4206 AuthOrder => 'mod_auth_file.c',
4207
4208 TimeoutLinger => 5,
4209
4210 IfModules => {
4211 'mod_delay.c' => {
4212 DelayEngine => 'off',
4213 },
4214 },
4215 };
4216
4217 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4218 $config);
4219
4220 # Open pipes, for use between the parent and child processes. Specifically,
4221 # the child will indicate when it's done with its test by writing a message
4222 # to the parent.
4223 my ($rfh, $wfh);
4224 unless (pipe($rfh, $wfh)) {
4225 die("Can't open pipe: $!");
4226 }
4227
4228 my $ex;
4229
4230 # Fork child
4231 $self->handle_sigchld();
4232 defined(my $pid = fork()) or die("Can't fork: $!");
4233 if ($pid) {
4234 eval {
4235 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4236 $client->login($setup->{user}, $setup->{passwd});
4237
4238 # Use a recursive listing, to generate more data, such that it will
4239 # not all fit in the transfer buffer, so we can interrupt the buffer.
4240 # A too-small request will fit in the buffer, and be fulfilled, before
4241 # our abort is read.
4242 my $conn = $client->list_raw('-R /');
4243 unless ($conn) {
4244 die("Failed to LIST: " . $client->response_code() . " " .
4245 $client->response_msg());
4246 }
4247
4248 # Read 128 bytes of data, then abort the download
4249 my $buf;
4250 $conn->read($buf, 128, 30);
4251 $conn->_close();
4252
4253 # There is a potential race here, between data EOF and our next command.
4254 # We thus sleep here, to let the data EOF win the race. With that,
4255 # we should now receive our end-of-transfer response.
4256 sleep(1);
4257
4258 my ($resp_code, $resp_msg) = $client->read_response();
4259
4260 my $expected = 426;
4261 $self->assert($expected == $resp_code,
4262 test_msg("Expected response code $expected, got $resp_code"));
4263
4264 $expected = 'Transfer aborted. Data connection closed';
4265 $self->assert($expected eq $resp_msg,
4266 test_msg("Expected response message '$expected', got '$resp_msg'"));
4267
4268 # We use the Net::FTP::abort() method here, so that we use, in this
4269 # order: data EOF, TCP OOB, ABOR.
4270 $client->abort();
4271 $resp_code = $client->response_code();
4272 $resp_msg = $client->response_msg();
4273
4274 $expected = 226;
4275 $self->assert($expected == $resp_code,
4276 test_msg("Expected response code $expected, got $resp_code"));
4277
4278 $expected = 'Abort successful';
4279 $self->assert($expected eq $resp_msg,
4280 test_msg("Expected response message '$expected', got '$resp_msg'"));
4281
4282 # Make sure the control connection did not close because of the abort.
4283 ($resp_code, $resp_msg) = $client->quit();
4284
4285 $expected = 221;
4286 $self->assert($expected == $resp_code,
4287 test_msg("Expected response code $expected, got $resp_code"));
4288
4289 $expected = 'Goodbye.';
4290 $self->assert($expected eq $resp_msg,
4291 test_msg("Expected response message '$expected', got '$resp_msg'"));
4292 };
4293 if ($@) {
4294 $ex = $@;
4295 }
4296
4297 $wfh->print("done\n");
4298 $wfh->flush();
4299
4300 } else {
4301 eval { server_wait($setup->{config_file}, $rfh) };
4302 if ($@) {
4303 warn($@);
4304 exit 1;
4305 }
4306
4307 exit 0;
4308 }
4309
4310 # Stop server
4311 server_stop($setup->{pid_file});
4312 $self->assert_child_ok($pid);
4313
4314 test_cleanup($setup->{log_file}, $ex);
4315 }
4316
4317 sub data_eof_before_abor_mlsd {
4318 my $self = shift;
4319 my $tmpdir = $self->{tmpdir};
4320 my $setup = test_setup($tmpdir, 'abor');
4321
4322 # Generate enough files in the directory to lead to a large enough response,
4323 # such that the response does not all fit in the initial transfer buffer.
4324 for (my $i = 0; $i < 5000; $i++) {
4325 my $path = File::Spec->rel2abs("$tmpdir/$i.dat");
4326
4327 if (open(my $fh, "> $path")) {
4328 close($fh);
4329
4330 } else {
4331 die("Can't open $path: $!");
4332 }
4333 }
4334
4335 my $config = {
4336 PidFile => $setup->{pid_file},
4337 ScoreboardFile => $setup->{scoreboard_file},
4338 SystemLog => $setup->{log_file},
4339 TraceLog => $setup->{log_file},
4340 Trace => 'DEFAULT:10 lock:0 scoreboard:0',
4341
4342 AuthUserFile => $setup->{auth_user_file},
4343 AuthGroupFile => $setup->{auth_group_file},
4344 AuthOrder => 'mod_auth_file.c',
4345
4346 TimeoutLinger => 5,
4347
4348 IfModules => {
4349 'mod_delay.c' => {
4350 DelayEngine => 'off',
4351 },
4352 },
4353 };
4354
4355 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4356 $config);
4357
4358 # Open pipes, for use between the parent and child processes. Specifically,
4359 # the child will indicate when it's done with its test by writing a message
4360 # to the parent.
4361 my ($rfh, $wfh);
4362 unless (pipe($rfh, $wfh)) {
4363 die("Can't open pipe: $!");
4364 }
4365
4366 my $ex;
4367
4368 # Fork child
4369 $self->handle_sigchld();
4370 defined(my $pid = fork()) or die("Can't fork: $!");
4371 if ($pid) {
4372 eval {
4373 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4374 $client->login($setup->{user}, $setup->{passwd});
4375
4376 my $conn = $client->mlsd_raw($tmpdir);
4377 unless ($conn) {
4378 die("Failed to MLSD: " . $client->response_code() . " " .
4379 $client->response_msg());
4380 }
4381
4382 # Read 8 bytes of data, then abort the download
4383 my $buf;
4384 $conn->read($buf, 8, 30);
4385 $conn->_close();
4386
4387 # There is a potential race here, between data EOF and our next command.
4388 # We thus sleep here, to let the data EOF win the race. With that,
4389 # we should now receive our end-of-transfer response.
4390 sleep(1);
4391
4392 my ($resp_code, $resp_msg) = $client->read_response();
4393
4394 my $expected = 426;
4395 $self->assert($expected == $resp_code,
4396 test_msg("Expected response code $expected, got $resp_code"));
4397
4398 $expected = 'Transfer aborted. Data connection closed';
4399 $self->assert($expected eq $resp_msg,
4400 test_msg("Expected response message '$expected', got '$resp_msg'"));
4401
4402 # We use the Net::FTP::abort() method here, so that we use, in this
4403 # order: data EOF, TCP OOB, ABOR.
4404 $client->abort();
4405 $resp_code = $client->response_code();
4406 $resp_msg = $client->response_msg();
4407
4408 $expected = 226;
4409 $self->assert($expected == $resp_code,
4410 test_msg("Expected response code $expected, got $resp_code"));
4411
4412 $expected = 'Abort successful';
4413 $self->assert($expected eq $resp_msg,
4414 test_msg("Expected response message '$expected', got '$resp_msg'"));
4415
4416 # Make sure the control connection did not close because of the abort.
4417 ($resp_code, $resp_msg) = $client->quit();
4418
4419 $expected = 221;
4420 $self->assert($expected == $resp_code,
4421 test_msg("Expected response code $expected, got $resp_code"));
4422
4423 $expected = 'Goodbye.';
4424 $self->assert($expected eq $resp_msg,
4425 test_msg("Expected response message '$expected', got '$resp_msg'"));
4426 };
4427 if ($@) {
4428 $ex = $@;
4429 }
4430
4431 $wfh->print("done\n");
4432 $wfh->flush();
4433
4434 } else {
4435 eval { server_wait($setup->{config_file}, $rfh) };
4436 if ($@) {
4437 warn($@);
4438 exit 1;
4439 }
4440
4441 exit 0;
4442 }
4443
4444 # Stop server
4445 server_stop($setup->{pid_file});
4446 $self->assert_child_ok($pid);
4447
4448 test_cleanup($setup->{log_file}, $ex);
4449 }
4450
4451 1;