Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::EPSV;
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
10 use ProFTPD::TestSuite::FTP;
11 use ProFTPD::TestSuite::Utils qw(:auth :config :features :running :test :testsuite);
12
13 $| = 1;
14
15 my $order = 0;
16
17 my $TESTS = {
18 epsv_ok => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 epsv_ipv4_ok => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 epsv_ipv6_ok => {
29 order => ++$order,
30 test_class => [qw(feature_ipv6 forking)],
31 },
32
33 epsv_all_ok => {
34 order => ++$order,
35 test_class => [qw(feature_ipv6 forking)],
36 },
37
38 epsv_fails_login_required => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 epsv_fails_bad_proto => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 epsv_during_xfer_bug3487 => {
49 order => ++$order,
50 test_class => [qw(bug forking)],
51 },
52
53 };
54
55 sub new {
56 return shift()->SUPER::new(@_);
57 }
58
59 sub list_tests {
60 return testsuite_get_runnable_tests($TESTS);
61 }
62
63 sub epsv_ok {
64 my $self = shift;
65 my $tmpdir = $self->{tmpdir};
66
67 my $config_file = "$tmpdir/cmds.conf";
68 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
69 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
70
71 my $log_file = test_get_logfile();
72
73 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
74 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
75
76 my $user = 'proftpd';
77 my $passwd = 'test';
78 my $home_dir = File::Spec->rel2abs($tmpdir);
79 my $uid = 500;
80 my $gid = 500;
81
82 # Make sure that, if we're running as root, that the home directory has
83 # permissions/privs set for the account we create
84 if ($< == 0) {
85 unless (chmod(0755, $home_dir)) {
86 die("Can't set perms on $home_dir to 0755: $!");
87 }
88
89 unless (chown($uid, $gid, $home_dir)) {
90 die("Can't set owner of $home_dir to $uid/$gid: $!");
91 }
92 }
93
94 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
95 '/bin/bash');
96 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
97
98 my $config = {
99 PidFile => $pid_file,
100 ScoreboardFile => $scoreboard_file,
101 SystemLog => $log_file,
102
103 AuthUserFile => $auth_user_file,
104 AuthGroupFile => $auth_group_file,
105 AuthOrder => 'mod_auth_file.c',
106
107 IfModules => {
108 'mod_delay.c' => {
109 DelayEngine => 'off',
110 },
111 },
112 };
113
114 my ($port, $config_user, $config_group) = config_write($config_file, $config);
115
116 # Open pipes, for use between the parent and child processes. Specifically,
117 # the child will indicate when it's done with its test by writing a message
118 # to the parent.
119 my ($rfh, $wfh);
120 unless (pipe($rfh, $wfh)) {
121 die("Can't open pipe: $!");
122 }
123
124 my $ex;
125
126 # Fork child
127 $self->handle_sigchld();
128 defined(my $pid = fork()) or die("Can't fork: $!");
129 if ($pid) {
130 eval {
131 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
132 $client->login($user, $passwd);;
133
134 my ($resp_code, $resp_msg);
135 ($resp_code, $resp_msg) = $client->epsv();
136
137 my $expected;
138
139 $expected = 229;
140 $self->assert($expected == $resp_code,
141 test_msg("Expected $expected, got $resp_code"));
142
143 $expected = '^Entering Extended Passive Mode \(\|\|\|\d+\|\)';
144 $self->assert(qr/$expected/, $resp_msg,
145 test_msg("Expected '$expected', got '$resp_msg'"));
146 };
147
148 if ($@) {
149 $ex = $@;
150 }
151
152 $wfh->print("done\n");
153 $wfh->flush();
154
155 } else {
156 eval { server_wait($config_file, $rfh) };
157 if ($@) {
158 warn($@);
159 exit 1;
160 }
161
162 exit 0;
163 }
164
165 # Stop server
166 server_stop($pid_file);
167
168 $self->assert_child_ok($pid);
169
170 if ($ex) {
171 test_append_logfile($log_file, $ex);
172 unlink($log_file);
173
174 die($ex);
175 }
176
177 unlink($log_file);
178 }
179
180 sub epsv_ipv4_ok {
181 my $self = shift;
182 my $tmpdir = $self->{tmpdir};
183
184 my $config_file = "$tmpdir/cmds.conf";
185 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
186 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
187
188 my $log_file = test_get_logfile();
189
190 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
191 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
192
193 my $user = 'proftpd';
194 my $passwd = 'test';
195 my $home_dir = File::Spec->rel2abs($tmpdir);
196 my $uid = 500;
197 my $gid = 500;
198
199 # Make sure that, if we're running as root, that the home directory has
200 # permissions/privs set for the account we create
201 if ($< == 0) {
202 unless (chmod(0755, $home_dir)) {
203 die("Can't set perms on $home_dir to 0755: $!");
204 }
205
206 unless (chown($uid, $gid, $home_dir)) {
207 die("Can't set owner of $home_dir to $uid/$gid: $!");
208 }
209 }
210
211 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
212 '/bin/bash');
213 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
214
215 my $config = {
216 PidFile => $pid_file,
217 ScoreboardFile => $scoreboard_file,
218 SystemLog => $log_file,
219
220 AuthUserFile => $auth_user_file,
221 AuthGroupFile => $auth_group_file,
222 AuthOrder => 'mod_auth_file.c',
223
224 IfModules => {
225 'mod_delay.c' => {
226 DelayEngine => 'off',
227 },
228 },
229 };
230
231 my ($port, $config_user, $config_group) = config_write($config_file, $config);
232
233 # Open pipes, for use between the parent and child processes. Specifically,
234 # the child will indicate when it's done with its test by writing a message
235 # to the parent.
236 my ($rfh, $wfh);
237 unless (pipe($rfh, $wfh)) {
238 die("Can't open pipe: $!");
239 }
240
241 my $ex;
242
243 # Fork child
244 $self->handle_sigchld();
245 defined(my $pid = fork()) or die("Can't fork: $!");
246 if ($pid) {
247 eval {
248 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
249 $client->login($user, $passwd);;
250
251 my ($resp_code, $resp_msg);
252 ($resp_code, $resp_msg) = $client->epsv('1');
253
254 my $expected;
255
256 $expected = 229;
257 $self->assert($expected == $resp_code,
258 test_msg("Expected $expected, got $resp_code"));
259
260 $expected = '^Entering Extended Passive Mode \(\|\|\|\d+\|\)';
261 $self->assert(qr/$expected/, $resp_msg,
262 test_msg("Expected '$expected', got '$resp_msg'"));
263 };
264
265 if ($@) {
266 $ex = $@;
267 }
268
269 $wfh->print("done\n");
270 $wfh->flush();
271
272 } else {
273 eval { server_wait($config_file, $rfh) };
274 if ($@) {
275 warn($@);
276 exit 1;
277 }
278
279 exit 0;
280 }
281
282 # Stop server
283 server_stop($pid_file);
284
285 $self->assert_child_ok($pid);
286
287 if ($ex) {
288 test_append_logfile($log_file, $ex);
289 unlink($log_file);
290
291 die($ex);
292 }
293
294 unlink($log_file);
295 }
296
297 sub epsv_ipv6_ok {
298 my $self = shift;
299 my $tmpdir = $self->{tmpdir};
300
301 my $config_file = "$tmpdir/cmds.conf";
302 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
303 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
304
305 my $log_file = test_get_logfile();
306
307 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
308 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
309
310 my $user = 'proftpd';
311 my $passwd = 'test';
312 my $home_dir = File::Spec->rel2abs($tmpdir);
313 my $uid = 500;
314 my $gid = 500;
315
316 # Make sure that, if we're running as root, that the home directory has
317 # permissions/privs set for the account we create
318 if ($< == 0) {
319 unless (chmod(0755, $home_dir)) {
320 die("Can't set perms on $home_dir to 0755: $!");
321 }
322
323 unless (chown($uid, $gid, $home_dir)) {
324 die("Can't set owner of $home_dir to $uid/$gid: $!");
325 }
326 }
327
328 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
329 '/bin/bash');
330 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
331
332 my $config = {
333 PidFile => $pid_file,
334 ScoreboardFile => $scoreboard_file,
335 SystemLog => $log_file,
336
337 AuthUserFile => $auth_user_file,
338 AuthGroupFile => $auth_group_file,
339 AuthOrder => 'mod_auth_file.c',
340
341 UseIPv6 => 'on',
342
343 IfModules => {
344 'mod_delay.c' => {
345 DelayEngine => 'off',
346 },
347 },
348 };
349
350 my ($port, $config_user, $config_group) = config_write($config_file, $config);
351
352 # Open pipes, for use between the parent and child processes. Specifically,
353 # the child will indicate when it's done with its test by writing a message
354 # to the parent.
355 my ($rfh, $wfh);
356 unless (pipe($rfh, $wfh)) {
357 die("Can't open pipe: $!");
358 }
359
360 my $ex;
361
362 # Fork child
363 $self->handle_sigchld();
364 defined(my $pid = fork()) or die("Can't fork: $!");
365 if ($pid) {
366 eval {
367 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
368 $client->login($user, $passwd);;
369
370 my ($resp_code, $resp_msg);
371 ($resp_code, $resp_msg) = $client->epsv('2');
372
373 my $expected;
374
375 $expected = 229;
376 $self->assert($expected == $resp_code,
377 test_msg("Expected $expected, got $resp_code"));
378
379 $expected = '^Entering Extended Passive Mode \(\|\|\|\d+\|\)';
380 $self->assert(qr/$expected/, $resp_msg,
381 test_msg("Expected '$expected', got '$resp_msg'"));
382 };
383
384 if ($@) {
385 $ex = $@;
386 }
387
388 $wfh->print("done\n");
389 $wfh->flush();
390
391 } else {
392 eval { server_wait($config_file, $rfh) };
393 if ($@) {
394 warn($@);
395 exit 1;
396 }
397
398 exit 0;
399 }
400
401 # Stop server
402 server_stop($pid_file);
403
404 $self->assert_child_ok($pid);
405
406 if ($ex) {
407 test_append_logfile($log_file, $ex);
408 unlink($log_file);
409
410 die($ex);
411 }
412
413 unlink($log_file);
414 }
415
416 sub epsv_all_ok {
417 my $self = shift;
418 my $tmpdir = $self->{tmpdir};
419
420 my $config_file = "$tmpdir/cmds.conf";
421 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
422 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
423
424 my $log_file = test_get_logfile();
425
426 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
427 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
428
429 my $user = 'proftpd';
430 my $passwd = 'test';
431 my $home_dir = File::Spec->rel2abs($tmpdir);
432 my $uid = 500;
433 my $gid = 500;
434
435 # Make sure that, if we're running as root, that the home directory has
436 # permissions/privs set for the account we create
437 if ($< == 0) {
438 unless (chmod(0755, $home_dir)) {
439 die("Can't set perms on $home_dir to 0755: $!");
440 }
441
442 unless (chown($uid, $gid, $home_dir)) {
443 die("Can't set owner of $home_dir to $uid/$gid: $!");
444 }
445 }
446
447 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
448 '/bin/bash');
449 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
450
451 my $config = {
452 PidFile => $pid_file,
453 ScoreboardFile => $scoreboard_file,
454 SystemLog => $log_file,
455
456 AuthUserFile => $auth_user_file,
457 AuthGroupFile => $auth_group_file,
458 AuthOrder => 'mod_auth_file.c',
459
460 IfModules => {
461 'mod_delay.c' => {
462 DelayEngine => 'off',
463 },
464 },
465 };
466
467 my ($port, $config_user, $config_group) = config_write($config_file, $config);
468
469 # Open pipes, for use between the parent and child processes. Specifically,
470 # the child will indicate when it's done with its test by writing a message
471 # to the parent.
472 my ($rfh, $wfh);
473 unless (pipe($rfh, $wfh)) {
474 die("Can't open pipe: $!");
475 }
476
477 my $ex;
478
479 # Fork child
480 $self->handle_sigchld();
481 defined(my $pid = fork()) or die("Can't fork: $!");
482 if ($pid) {
483 eval {
484 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
485 $client->login($user, $passwd);;
486
487 my ($resp_code, $resp_msg);
488 ($resp_code, $resp_msg) = $client->epsv('all');
489
490 my $expected;
491
492 $expected = 200;
493 $self->assert($expected == $resp_code,
494 test_msg("Expected $expected, got $resp_code"));
495
496 $expected = 'EPSV ALL command successful';
497 $self->assert($expected eq $resp_msg,
498 test_msg("Expected '$expected', got '$resp_msg'"));
499 };
500
501 if ($@) {
502 $ex = $@;
503 }
504
505 $wfh->print("done\n");
506 $wfh->flush();
507
508 } else {
509 eval { server_wait($config_file, $rfh) };
510 if ($@) {
511 warn($@);
512 exit 1;
513 }
514
515 exit 0;
516 }
517
518 # Stop server
519 server_stop($pid_file);
520
521 $self->assert_child_ok($pid);
522
523 if ($ex) {
524 test_append_logfile($log_file, $ex);
525 unlink($log_file);
526
527 die($ex);
528 }
529
530 unlink($log_file);
531 }
532
533 sub epsv_fails_login_required {
534 my $self = shift;
535 my $tmpdir = $self->{tmpdir};
536
537 my $config_file = "$tmpdir/cmds.conf";
538 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
539 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
540
541 my $log_file = test_get_logfile();
542
543 my $config = {
544 PidFile => $pid_file,
545 ScoreboardFile => $scoreboard_file,
546 SystemLog => $log_file,
547
548 IfModules => {
549 'mod_delay.c' => {
550 DelayEngine => 'off',
551 },
552 },
553 };
554
555 my ($port, $config_user, $config_group) = config_write($config_file, $config);
556
557 # Open pipes, for use between the parent and child processes. Specifically,
558 # the child will indicate when it's done with its test by writing a message
559 # to the parent.
560 my ($rfh, $wfh);
561 unless (pipe($rfh, $wfh)) {
562 die("Can't open pipe: $!");
563 }
564
565 my $ex;
566
567 # Fork child
568 $self->handle_sigchld();
569 defined(my $pid = fork()) or die("Can't fork: $!");
570 if ($pid) {
571 eval {
572 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
573
574 my ($resp_code, $resp_msg);
575 eval { ($resp_code, $resp_msg) = $client->epsv() };
576 unless ($@) {
577 die("PASV succeeded unexpectedly");
578
579 } else {
580 $resp_code = $client->response_code();
581 $resp_msg = $client->response_msg();
582 }
583
584 my $expected;
585
586 $expected = 530;
587 $self->assert($expected == $resp_code,
588 test_msg("Expected $expected, got $resp_code"));
589
590 $expected = "Please login with USER and PASS";
591 $self->assert($expected eq $resp_msg,
592 test_msg("Expected '$expected', got '$resp_msg'"));
593 };
594
595 if ($@) {
596 $ex = $@;
597 }
598
599 $wfh->print("done\n");
600 $wfh->flush();
601
602 } else {
603 eval { server_wait($config_file, $rfh) };
604 if ($@) {
605 warn($@);
606 exit 1;
607 }
608
609 exit 0;
610 }
611
612 # Stop server
613 server_stop($pid_file);
614
615 $self->assert_child_ok($pid);
616
617 if ($ex) {
618 test_append_logfile($log_file, $ex);
619 unlink($log_file);
620
621 die($ex);
622 }
623
624 unlink($log_file);
625 }
626
627 sub epsv_fails_bad_proto {
628 my $self = shift;
629 my $tmpdir = $self->{tmpdir};
630
631 my $config_file = "$tmpdir/cmds.conf";
632 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
633 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
634
635 my $log_file = test_get_logfile();
636
637 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
638 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
639
640 my $user = 'proftpd';
641 my $passwd = 'test';
642 my $home_dir = File::Spec->rel2abs($tmpdir);
643 my $uid = 500;
644 my $gid = 500;
645
646 # Make sure that, if we're running as root, that the home directory has
647 # permissions/privs set for the account we create
648 if ($< == 0) {
649 unless (chmod(0755, $home_dir)) {
650 die("Can't set perms on $home_dir to 0755: $!");
651 }
652
653 unless (chown($uid, $gid, $home_dir)) {
654 die("Can't set owner of $home_dir to $uid/$gid: $!");
655 }
656 }
657
658 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
659 '/bin/bash');
660 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
661
662 my $config = {
663 PidFile => $pid_file,
664 ScoreboardFile => $scoreboard_file,
665 SystemLog => $log_file,
666
667 AuthUserFile => $auth_user_file,
668 AuthGroupFile => $auth_group_file,
669 AuthOrder => 'mod_auth_file.c',
670
671 IfModules => {
672 'mod_delay.c' => {
673 DelayEngine => 'off',
674 },
675 },
676 };
677
678 my $have_ipv6 = feature_have_feature_enabled('ipv6');
679 if ($have_ipv6) {
680 $config->{UseIPv6} = 'on';
681 }
682
683 my ($port, $config_user, $config_group) = config_write($config_file, $config);
684
685 # Open pipes, for use between the parent and child processes. Specifically,
686 # the child will indicate when it's done with its test by writing a message
687 # to the parent.
688 my ($rfh, $wfh);
689 unless (pipe($rfh, $wfh)) {
690 die("Can't open pipe: $!");
691 }
692
693 my $ex;
694
695 # Fork child
696 $self->handle_sigchld();
697 defined(my $pid = fork()) or die("Can't fork: $!");
698 if ($pid) {
699 eval {
700 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
701 $client->login($user, $passwd);;
702
703 my ($resp_code, $resp_msg);
704 eval { $client->epsv('4') };
705 unless ($@) {
706 die("EPSV succeeded unexpectedly: " . $client->response_code() . " " .
707 $client->response_msg());
708
709 } else {
710 $resp_code = $client->response_code();
711 $resp_msg = $client->response_msg();
712 }
713
714 my $expected;
715
716 $expected = 522;
717 $self->assert($expected == $resp_code,
718 test_msg("Expected $expected, got $resp_code"));
719
720 if ($have_ipv6) {
721 $expected = "Network protocol not supported, use (1,2)";
722
723 } else {
724 $expected = "Network protocol not supported, use (1)";
725 }
726
727 $self->assert($expected eq $resp_msg,
728 test_msg("Expected '$expected', got '$resp_msg'"));
729 };
730
731 if ($@) {
732 $ex = $@;
733 }
734
735 $wfh->print("done\n");
736 $wfh->flush();
737
738 } else {
739 eval { server_wait($config_file, $rfh) };
740 if ($@) {
741 warn($@);
742 exit 1;
743 }
744
745 exit 0;
746 }
747
748 # Stop server
749 server_stop($pid_file);
750
751 $self->assert_child_ok($pid);
752
753 if ($ex) {
754 test_append_logfile($log_file, $ex);
755 unlink($log_file);
756
757 die($ex);
758 }
759
760 unlink($log_file);
761 }
762
763 sub epsv_during_xfer_bug3487 {
764 my $self = shift;
765 my $tmpdir = $self->{tmpdir};
766
767 my $config_file = "$tmpdir/cmds.conf";
768 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
769 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
770
771 my $log_file = test_get_logfile();
772
773 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
774 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
775
776 my $user = 'proftpd';
777 my $passwd = 'test';
778 my $home_dir = File::Spec->rel2abs($tmpdir);
779 my $uid = 500;
780 my $gid = 500;
781
782 # Make sure that, if we're running as root, that the home directory has
783 # permissions/privs set for the account we create
784 if ($< == 0) {
785 unless (chmod(0755, $home_dir)) {
786 die("Can't set perms on $home_dir to 0755: $!");
787 }
788
789 unless (chown($uid, $gid, $home_dir)) {
790 die("Can't set owner of $home_dir to $uid/$gid: $!");
791 }
792 }
793
794 # For this test, we need to create many files in the home directory
795 my $test_file_prefix = File::Spec->rel2abs("$tmpdir/test_");
796
797 my $count = 7000;
798 for (my $i = 1; $i <= $count; $i++) {
799 my $test_file = 'test_' . sprintf("%07s", $i);
800 my $test_path = "$home_dir/$test_file";
801
802 if (open(my $fh, "> $test_path")) {
803 close($fh);
804
805 } else {
806 die("Can't open $test_path: $!");
807 }
808 }
809
810 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
811 '/bin/bash');
812 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
813
814 my $config = {
815 PidFile => $pid_file,
816 ScoreboardFile => $scoreboard_file,
817 SystemLog => $log_file,
818
819 AuthUserFile => $auth_user_file,
820 AuthGroupFile => $auth_group_file,
821 AuthOrder => 'mod_auth_file.c',
822
823 IfModules => {
824 'mod_delay.c' => {
825 DelayEngine => 'off',
826 },
827 },
828 };
829
830 my ($port, $config_user, $config_group) = config_write($config_file, $config);
831
832 # Open pipes, for use between the parent and child processes. Specifically,
833 # the child will indicate when it's done with its test by writing a message
834 # to the parent.
835 my ($rfh, $wfh);
836 unless (pipe($rfh, $wfh)) {
837 die("Can't open pipe: $!");
838 }
839
840 my $ex;
841
842 # Fork child
843 $self->handle_sigchld();
844 defined(my $pid = fork()) or die("Can't fork: $!");
845 if ($pid) {
846 eval {
847 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
848 $client->login($user, $passwd);
849
850 my $conn = $client->list_raw();
851 unless ($conn) {
852 die("Failed to LIST: " . $client->response_code() . " " .
853 $client->response_msg());
854 }
855
856 my ($buf, $tmp);
857 $conn->read($tmp, 8, 30);
858 $buf .= $tmp;
859
860 eval { $client->epsv() };
861 unless ($@) {
862 die("EPSV succeeded unexpectedly");
863 }
864
865 my $resp_code = $client->response_code();
866 my $resp_msg = $client->response_msg();
867
868 my $expected;
869
870 $expected = 450;
871 $self->assert($expected == $resp_code,
872 test_msg("Expected $expected, got $resp_code"));
873
874 $expected = 'EPSV: data transfer in progress';
875 $self->assert($expected eq $resp_msg,
876 test_msg("Expected '$expected', got '$resp_msg'"));
877
878 # Finish reading the data
879 while ($conn->read($tmp, 32768, 30)) {
880 $buf .= $tmp;
881 }
882 $conn->close();
883
884 $resp_code = $client->response_code();
885 $resp_msg = $client->response_msg();
886
887 $expected = 226;
888 $self->assert($expected == $resp_code,
889 test_msg("Expected $expected, got $resp_code"));
890
891 $expected = 'Transfer complete';
892 $self->assert($expected eq $resp_msg,
893 test_msg("Expected '$expected', got '$resp_msg'"));
894 };
895
896 if ($@) {
897 $ex = $@;
898 }
899
900 $wfh->print("done\n");
901 $wfh->flush();
902
903 } else {
904 eval { server_wait($config_file, $rfh) };
905 if ($@) {
906 warn($@);
907 exit 1;
908 }
909
910 exit 0;
911 }
912
913 # Stop server
914 server_stop($pid_file);
915
916 $self->assert_child_ok($pid);
917
918 if ($ex) {
919 test_append_logfile($log_file, $ex);
920 unlink($log_file);
921
922 die($ex);
923 }
924
925 unlink($log_file);
926 }
927
928 1;