Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::EPRT;
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 eprt_ipv4_ok => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 eprt_ipv6_ok => {
24 order => ++$order,
25 test_class => [qw(feature_ipv6 forking)],
26 },
27
28 eprt_fails_login_required => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 eprt_fails_bad_format => {
34 order => ++$order,
35 test_class => [qw(forking)],
36 },
37
38 eprt_fails_bad_values => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 eprt_fails_bad_proto => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 eprt_fails_bad_addr => {
49 order => ++$order,
50 test_class => [qw(forking)],
51 },
52
53 eprt_fails_bad_port => {
54 order => ++$order,
55 test_class => [qw(forking)],
56 },
57
58 eprt_during_xfer_bug3487 => {
59 order => ++$order,
60 test_class => [qw(bug forking)],
61 },
62
63 };
64
65 sub new {
66 return shift()->SUPER::new(@_);
67 }
68
69 sub list_tests {
70 return testsuite_get_runnable_tests($TESTS);
71 }
72
73 sub eprt_ipv4_ok {
74 my $self = shift;
75 my $tmpdir = $self->{tmpdir};
76
77 my $config_file = "$tmpdir/cmds.conf";
78 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
79 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
80
81 my $log_file = test_get_logfile();
82
83 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
84 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
85
86 my $user = 'proftpd';
87 my $passwd = 'test';
88 my $home_dir = File::Spec->rel2abs($tmpdir);
89 my $uid = 500;
90 my $gid = 500;
91
92 # Make sure that, if we're running as root, that the home directory has
93 # permissions/privs set for the account we create
94 if ($< == 0) {
95 unless (chmod(0755, $home_dir)) {
96 die("Can't set perms on $home_dir to 0755: $!");
97 }
98
99 unless (chown($uid, $gid, $home_dir)) {
100 die("Can't set owner of $home_dir to $uid/$gid: $!");
101 }
102 }
103
104 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
105 '/bin/bash');
106 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
107
108 my $config = {
109 PidFile => $pid_file,
110 ScoreboardFile => $scoreboard_file,
111 SystemLog => $log_file,
112
113 AuthUserFile => $auth_user_file,
114 AuthGroupFile => $auth_group_file,
115 AuthOrder => 'mod_auth_file.c',
116
117 IfModules => {
118 'mod_delay.c' => {
119 DelayEngine => 'off',
120 },
121 },
122 };
123
124 my ($port, $config_user, $config_group) = config_write($config_file, $config);
125
126 # Open pipes, for use between the parent and child processes. Specifically,
127 # the child will indicate when it's done with its test by writing a message
128 # to the parent.
129 my ($rfh, $wfh);
130 unless (pipe($rfh, $wfh)) {
131 die("Can't open pipe: $!");
132 }
133
134 my $ex;
135
136 # Fork child
137 $self->handle_sigchld();
138 defined(my $pid = fork()) or die("Can't fork: $!");
139 if ($pid) {
140 eval {
141 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
142 $client->login($user, $passwd);
143
144 my ($resp_code, $resp_msg);
145 ($resp_code, $resp_msg) = $client->eprt('|1|127.0.0.1|4856|');
146
147 my $expected;
148
149 $expected = 200;
150 $self->assert($expected == $resp_code,
151 test_msg("Expected $expected, got $resp_code"));
152
153 $expected = "EPRT command successful";
154 $self->assert($expected eq $resp_msg,
155 test_msg("Expected '$expected', got '$resp_msg'"));
156 };
157
158 if ($@) {
159 $ex = $@;
160 }
161
162 $wfh->print("done\n");
163 $wfh->flush();
164
165 } else {
166 eval { server_wait($config_file, $rfh) };
167 if ($@) {
168 warn($@);
169 exit 1;
170 }
171
172 exit 0;
173 }
174
175 # Stop server
176 server_stop($pid_file);
177
178 $self->assert_child_ok($pid);
179
180 if ($ex) {
181 test_append_logfile($log_file, $ex);
182 unlink($log_file);
183
184 die($ex);
185 }
186
187 unlink($log_file);
188 }
189
190 sub eprt_ipv6_ok {
191 my $self = shift;
192 my $tmpdir = $self->{tmpdir};
193
194 my $config_file = "$tmpdir/cmds.conf";
195 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
196 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
197
198 my $log_file = test_get_logfile();
199
200 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
201 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
202
203 my $user = 'proftpd';
204 my $passwd = 'test';
205 my $home_dir = File::Spec->rel2abs($tmpdir);
206 my $uid = 500;
207 my $gid = 500;
208
209 # Make sure that, if we're running as root, that the home directory has
210 # permissions/privs set for the account we create
211 if ($< == 0) {
212 unless (chmod(0755, $home_dir)) {
213 die("Can't set perms on $home_dir to 0755: $!");
214 }
215
216 unless (chown($uid, $gid, $home_dir)) {
217 die("Can't set owner of $home_dir to $uid/$gid: $!");
218 }
219 }
220
221 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
222 '/bin/bash');
223 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
224
225 my $config = {
226 PidFile => $pid_file,
227 ScoreboardFile => $scoreboard_file,
228 SystemLog => $log_file,
229
230 AuthUserFile => $auth_user_file,
231 AuthGroupFile => $auth_group_file,
232 AuthOrder => 'mod_auth_file.c',
233
234 UseIPv6 => 'on',
235
236 IfModules => {
237 'mod_delay.c' => {
238 DelayEngine => 'off',
239 },
240 },
241 };
242
243 my ($port, $config_user, $config_group) = config_write($config_file, $config);
244
245 # Open pipes, for use between the parent and child processes. Specifically,
246 # the child will indicate when it's done with its test by writing a message
247 # to the parent.
248 my ($rfh, $wfh);
249 unless (pipe($rfh, $wfh)) {
250 die("Can't open pipe: $!");
251 }
252
253 my $ex;
254
255 # Fork child
256 $self->handle_sigchld();
257 defined(my $pid = fork()) or die("Can't fork: $!");
258 if ($pid) {
259 eval {
260 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
261 $client->login($user, $passwd);
262
263 my ($resp_code, $resp_msg);
264 ($resp_code, $resp_msg) = $client->eprt('|2|::ffff:127.0.0.1|4856|');
265
266 my $expected;
267
268 $expected = 200;
269 $self->assert($expected == $resp_code,
270 test_msg("Expected $expected, got $resp_code"));
271
272 $expected = "EPRT command successful";
273 $self->assert($expected eq $resp_msg,
274 test_msg("Expected '$expected', got '$resp_msg'"));
275 };
276
277 if ($@) {
278 $ex = $@;
279 }
280
281 $wfh->print("done\n");
282 $wfh->flush();
283
284 } else {
285 eval { server_wait($config_file, $rfh) };
286 if ($@) {
287 warn($@);
288 exit 1;
289 }
290
291 exit 0;
292 }
293
294 # Stop server
295 server_stop($pid_file);
296
297 $self->assert_child_ok($pid);
298
299 if ($ex) {
300 test_append_logfile($log_file, $ex);
301 unlink($log_file);
302
303 die($ex);
304 }
305
306 unlink($log_file);
307 }
308
309 sub eprt_fails_login_required {
310 my $self = shift;
311 my $tmpdir = $self->{tmpdir};
312
313 my $config_file = "$tmpdir/cmds.conf";
314 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
315 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
316
317 my $log_file = test_get_logfile();
318
319 my $config = {
320 PidFile => $pid_file,
321 ScoreboardFile => $scoreboard_file,
322 SystemLog => $log_file,
323
324 IfModules => {
325 'mod_delay.c' => {
326 DelayEngine => 'off',
327 },
328 },
329 };
330
331 my ($port, $config_user, $config_group) = config_write($config_file, $config);
332
333 # Open pipes, for use between the parent and child processes. Specifically,
334 # the child will indicate when it's done with its test by writing a message
335 # to the parent.
336 my ($rfh, $wfh);
337 unless (pipe($rfh, $wfh)) {
338 die("Can't open pipe: $!");
339 }
340
341 my $ex;
342
343 # Fork child
344 $self->handle_sigchld();
345 defined(my $pid = fork()) or die("Can't fork: $!");
346 if ($pid) {
347 eval {
348 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
349
350 my ($resp_code, $resp_msg);
351 eval { ($resp_code, $resp_msg) = $client->eprt() };
352 unless ($@) {
353 die("EPRT succeeded unexpectedly");
354
355 } else {
356 $resp_code = $client->response_code();
357 $resp_msg = $client->response_msg();
358 }
359
360 my $expected;
361
362 $expected = 530;
363 $self->assert($expected == $resp_code,
364 test_msg("Expected $expected, got $resp_code"));
365
366 $expected = "Please login with USER and PASS";
367 $self->assert($expected eq $resp_msg,
368 test_msg("Expected '$expected', got '$resp_msg'"));
369 };
370
371 if ($@) {
372 $ex = $@;
373 }
374
375 $wfh->print("done\n");
376 $wfh->flush();
377
378 } else {
379 eval { server_wait($config_file, $rfh) };
380 if ($@) {
381 warn($@);
382 exit 1;
383 }
384
385 exit 0;
386 }
387
388 # Stop server
389 server_stop($pid_file);
390
391 $self->assert_child_ok($pid);
392
393 if ($ex) {
394 test_append_logfile($log_file, $ex);
395 unlink($log_file);
396
397 die($ex);
398 }
399
400 unlink($log_file);
401 }
402
403 sub eprt_fails_bad_format {
404 my $self = shift;
405 my $tmpdir = $self->{tmpdir};
406
407 my $config_file = "$tmpdir/cmds.conf";
408 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
409 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
410
411 my $log_file = test_get_logfile();
412
413 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
414 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
415
416 my $user = 'proftpd';
417 my $passwd = 'test';
418 my $home_dir = File::Spec->rel2abs($tmpdir);
419 my $uid = 500;
420 my $gid = 500;
421
422 # Make sure that, if we're running as root, that the home directory has
423 # permissions/privs set for the account we create
424 if ($< == 0) {
425 unless (chmod(0755, $home_dir)) {
426 die("Can't set perms on $home_dir to 0755: $!");
427 }
428
429 unless (chown($uid, $gid, $home_dir)) {
430 die("Can't set owner of $home_dir to $uid/$gid: $!");
431 }
432 }
433
434 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
435 '/bin/bash');
436 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
437
438 my $config = {
439 PidFile => $pid_file,
440 ScoreboardFile => $scoreboard_file,
441 SystemLog => $log_file,
442
443 AuthUserFile => $auth_user_file,
444 AuthGroupFile => $auth_group_file,
445 AuthOrder => 'mod_auth_file.c',
446
447 IfModules => {
448 'mod_delay.c' => {
449 DelayEngine => 'off',
450 },
451 },
452 };
453
454 my ($port, $config_user, $config_group) = config_write($config_file, $config);
455
456 # Open pipes, for use between the parent and child processes. Specifically,
457 # the child will indicate when it's done with its test by writing a message
458 # to the parent.
459 my ($rfh, $wfh);
460 unless (pipe($rfh, $wfh)) {
461 die("Can't open pipe: $!");
462 }
463
464 my $ex;
465
466 # Fork child
467 $self->handle_sigchld();
468 defined(my $pid = fork()) or die("Can't fork: $!");
469 if ($pid) {
470 eval {
471 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
472
473 $client->login($user, $passwd);
474
475 my ($resp_code, $resp_msg);
476 eval { ($resp_code, $resp_msg) = $client->eprt(',1,2,3') };
477 unless ($@) {
478 die("EPRT succeeded unexpectedly");
479
480 } else {
481 $resp_code = $client->response_code();
482 $resp_msg = $client->response_msg();
483 }
484
485 my $expected;
486
487 $expected = 501;
488 $self->assert($expected == $resp_code,
489 test_msg("Expected $expected, got $resp_code"));
490
491 $expected = "Illegal EPRT command";
492 $self->assert($expected eq $resp_msg,
493 test_msg("Expected '$expected', got '$resp_msg'"));
494 };
495
496 if ($@) {
497 $ex = $@;
498 }
499
500 $wfh->print("done\n");
501 $wfh->flush();
502
503 } else {
504 eval { server_wait($config_file, $rfh) };
505 if ($@) {
506 warn($@);
507 exit 1;
508 }
509
510 exit 0;
511 }
512
513 # Stop server
514 server_stop($pid_file);
515
516 $self->assert_child_ok($pid);
517
518 if ($ex) {
519 test_append_logfile($log_file, $ex);
520 unlink($log_file);
521
522 die($ex);
523 }
524
525 unlink($log_file);
526 }
527
528 sub eprt_fails_bad_values {
529 my $self = shift;
530 my $tmpdir = $self->{tmpdir};
531
532 my $config_file = "$tmpdir/cmds.conf";
533 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
534 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
535
536 my $log_file = test_get_logfile();
537
538 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
539 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
540
541 my $user = 'proftpd';
542 my $passwd = 'test';
543 my $home_dir = File::Spec->rel2abs($tmpdir);
544 my $uid = 500;
545 my $gid = 500;
546
547 # Make sure that, if we're running as root, that the home directory has
548 # permissions/privs set for the account we create
549 if ($< == 0) {
550 unless (chmod(0755, $home_dir)) {
551 die("Can't set perms on $home_dir to 0755: $!");
552 }
553
554 unless (chown($uid, $gid, $home_dir)) {
555 die("Can't set owner of $home_dir to $uid/$gid: $!");
556 }
557 }
558
559 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
560 '/bin/bash');
561 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
562
563 my $config = {
564 PidFile => $pid_file,
565 ScoreboardFile => $scoreboard_file,
566 SystemLog => $log_file,
567
568 AuthUserFile => $auth_user_file,
569 AuthGroupFile => $auth_group_file,
570 AuthOrder => 'mod_auth_file.c',
571
572 IfModules => {
573 'mod_delay.c' => {
574 DelayEngine => 'off',
575 },
576 },
577 };
578
579 my ($port, $config_user, $config_group) = config_write($config_file, $config);
580
581 # Open pipes, for use between the parent and child processes. Specifically,
582 # the child will indicate when it's done with its test by writing a message
583 # to the parent.
584 my ($rfh, $wfh);
585 unless (pipe($rfh, $wfh)) {
586 die("Can't open pipe: $!");
587 }
588
589 my $ex;
590
591 # Fork child
592 $self->handle_sigchld();
593 defined(my $pid = fork()) or die("Can't fork: $!");
594 if ($pid) {
595 eval {
596 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
597 $client->login($user, $passwd);
598
599 my ($resp_code, $resp_msg);
600 eval { ($resp_code, $resp_msg) = $client->eprt('|1|100.200.300.400|0|') };
601 unless ($@) {
602 die("EPRT succeeded unexpectedly");
603
604 } else {
605 $resp_code = $client->response_code();
606 $resp_msg = $client->response_msg();
607 }
608
609 my $expected;
610
611 $expected = 501;
612 $self->assert($expected == $resp_code,
613 test_msg("Expected $expected, got $resp_code"));
614
615 $expected = "Illegal EPRT command";
616 $self->assert($expected eq $resp_msg,
617 test_msg("Expected '$expected', got '$resp_msg'"));
618 };
619
620 if ($@) {
621 $ex = $@;
622 }
623
624 $wfh->print("done\n");
625 $wfh->flush();
626
627 } else {
628 eval { server_wait($config_file, $rfh) };
629 if ($@) {
630 warn($@);
631 exit 1;
632 }
633
634 exit 0;
635 }
636
637 # Stop server
638 server_stop($pid_file);
639
640 $self->assert_child_ok($pid);
641
642 if ($ex) {
643 test_append_logfile($log_file, $ex);
644 unlink($log_file);
645
646 die($ex);
647 }
648
649 unlink($log_file);
650 }
651
652 sub eprt_fails_bad_proto {
653 my $self = shift;
654 my $tmpdir = $self->{tmpdir};
655
656 my $config_file = "$tmpdir/cmds.conf";
657 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
658 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
659
660 my $log_file = test_get_logfile();
661
662 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
663 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
664
665 my $user = 'proftpd';
666 my $passwd = 'test';
667 my $home_dir = File::Spec->rel2abs($tmpdir);
668 my $uid = 500;
669 my $gid = 500;
670
671 # Make sure that, if we're running as root, that the home directory has
672 # permissions/privs set for the account we create
673 if ($< == 0) {
674 unless (chmod(0755, $home_dir)) {
675 die("Can't set perms on $home_dir to 0755: $!");
676 }
677
678 unless (chown($uid, $gid, $home_dir)) {
679 die("Can't set owner of $home_dir to $uid/$gid: $!");
680 }
681 }
682
683 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
684 '/bin/bash');
685 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
686
687 my $config = {
688 PidFile => $pid_file,
689 ScoreboardFile => $scoreboard_file,
690 SystemLog => $log_file,
691
692 AuthUserFile => $auth_user_file,
693 AuthGroupFile => $auth_group_file,
694 AuthOrder => 'mod_auth_file.c',
695
696 IfModules => {
697 'mod_delay.c' => {
698 DelayEngine => 'off',
699 },
700 },
701 };
702
703 my $have_ipv6 = feature_have_feature_enabled('ipv6');
704 if ($have_ipv6) {
705 $config->{UseIPv6} = 'on';
706 }
707
708 my ($port, $config_user, $config_group) = config_write($config_file, $config);
709
710 # Open pipes, for use between the parent and child processes. Specifically,
711 # the child will indicate when it's done with its test by writing a message
712 # to the parent.
713 my ($rfh, $wfh);
714 unless (pipe($rfh, $wfh)) {
715 die("Can't open pipe: $!");
716 }
717
718 my $ex;
719
720 # Fork child
721 $self->handle_sigchld();
722 defined(my $pid = fork()) or die("Can't fork: $!");
723 if ($pid) {
724 eval {
725 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
726 $client->login($user, $passwd);
727
728 my ($resp_code, $resp_msg);
729
730 eval { ($resp_code, $resp_msg) = $client->eprt('|3|127.0.0.1|4856|') };
731 unless ($@) {
732 die("EPRT succeeded unexpectedly");
733
734 } else {
735 $resp_code = $client->response_code();
736 $resp_msg = $client->response_msg();
737 }
738
739 my $expected;
740
741 $expected = 522;
742 $self->assert($expected == $resp_code,
743 test_msg("Expected $expected, got $resp_code"));
744
745 if ($have_ipv6) {
746 $expected = "Network protocol not supported, use (1,2)";
747
748 } else {
749 $expected = "Network protocol not supported, use (1)";
750 }
751
752 $self->assert($expected eq $resp_msg,
753 test_msg("Expected '$expected', got '$resp_msg'"));
754 };
755
756 if ($@) {
757 $ex = $@;
758 }
759
760 $wfh->print("done\n");
761 $wfh->flush();
762
763 } else {
764 eval { server_wait($config_file, $rfh) };
765 if ($@) {
766 warn($@);
767 exit 1;
768 }
769
770 exit 0;
771 }
772
773 # Stop server
774 server_stop($pid_file);
775
776 $self->assert_child_ok($pid);
777
778 if ($ex) {
779 test_append_logfile($log_file, $ex);
780 unlink($log_file);
781
782 die($ex);
783 }
784
785 unlink($log_file);
786 }
787
788 sub eprt_fails_bad_addr {
789 my $self = shift;
790 my $tmpdir = $self->{tmpdir};
791
792 my $config_file = "$tmpdir/cmds.conf";
793 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
794 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
795
796 my $log_file = test_get_logfile();
797
798 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
799 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
800
801 my $user = 'proftpd';
802 my $passwd = 'test';
803 my $home_dir = File::Spec->rel2abs($tmpdir);
804 my $uid = 500;
805 my $gid = 500;
806
807 # Make sure that, if we're running as root, that the home directory has
808 # permissions/privs set for the account we create
809 if ($< == 0) {
810 unless (chmod(0755, $home_dir)) {
811 die("Can't set perms on $home_dir to 0755: $!");
812 }
813
814 unless (chown($uid, $gid, $home_dir)) {
815 die("Can't set owner of $home_dir to $uid/$gid: $!");
816 }
817 }
818
819 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
820 '/bin/bash');
821 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
822
823 my $config = {
824 PidFile => $pid_file,
825 ScoreboardFile => $scoreboard_file,
826 SystemLog => $log_file,
827
828 AuthUserFile => $auth_user_file,
829 AuthGroupFile => $auth_group_file,
830 AuthOrder => 'mod_auth_file.c',
831
832 IfModules => {
833 'mod_delay.c' => {
834 DelayEngine => 'off',
835 },
836 },
837 };
838
839 my ($port, $config_user, $config_group) = config_write($config_file, $config);
840
841 # Open pipes, for use between the parent and child processes. Specifically,
842 # the child will indicate when it's done with its test by writing a message
843 # to the parent.
844 my ($rfh, $wfh);
845 unless (pipe($rfh, $wfh)) {
846 die("Can't open pipe: $!");
847 }
848
849 my $ex;
850
851 # Fork child
852 $self->handle_sigchld();
853 defined(my $pid = fork()) or die("Can't fork: $!");
854 if ($pid) {
855 eval {
856 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
857 $client->login($user, $passwd);
858
859 my ($resp_code, $resp_msg);
860
861 # XXX Hopefully this address is NOT configured on this box.
862 eval { ($resp_code, $resp_msg) = $client->eprt('|1|127.77.88.99|4856|') };
863 unless ($@) {
864 die("EPRT succeeded unexpectedly");
865
866 } else {
867 $resp_code = $client->response_code();
868 $resp_msg = $client->response_msg();
869 }
870
871 my $expected;
872
873 $expected = 500;
874 $self->assert($expected == $resp_code,
875 test_msg("Expected $expected, got $resp_code"));
876
877 $expected = "Illegal EPRT command";
878 $self->assert($expected eq $resp_msg,
879 test_msg("Expected '$expected', got '$resp_msg'"));
880 };
881
882 if ($@) {
883 $ex = $@;
884 }
885
886 $wfh->print("done\n");
887 $wfh->flush();
888
889 } else {
890 eval { server_wait($config_file, $rfh) };
891 if ($@) {
892 warn($@);
893 exit 1;
894 }
895
896 exit 0;
897 }
898
899 # Stop server
900 server_stop($pid_file);
901
902 $self->assert_child_ok($pid);
903
904 if ($ex) {
905 test_append_logfile($log_file, $ex);
906 unlink($log_file);
907
908 die($ex);
909 }
910
911 unlink($log_file);
912 }
913
914 sub eprt_fails_bad_port {
915 my $self = shift;
916 my $tmpdir = $self->{tmpdir};
917
918 my $config_file = "$tmpdir/cmds.conf";
919 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
920 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
921
922 my $log_file = test_get_logfile();
923
924 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
925 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
926
927 my $user = 'proftpd';
928 my $passwd = 'test';
929 my $home_dir = File::Spec->rel2abs($tmpdir);
930 my $uid = 500;
931 my $gid = 500;
932
933 # Make sure that, if we're running as root, that the home directory has
934 # permissions/privs set for the account we create
935 if ($< == 0) {
936 unless (chmod(0755, $home_dir)) {
937 die("Can't set perms on $home_dir to 0755: $!");
938 }
939
940 unless (chown($uid, $gid, $home_dir)) {
941 die("Can't set owner of $home_dir to $uid/$gid: $!");
942 }
943 }
944
945 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
946 '/bin/bash');
947 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
948
949 my $config = {
950 PidFile => $pid_file,
951 ScoreboardFile => $scoreboard_file,
952 SystemLog => $log_file,
953
954 AuthUserFile => $auth_user_file,
955 AuthGroupFile => $auth_group_file,
956 AuthOrder => 'mod_auth_file.c',
957
958 IfModules => {
959 'mod_delay.c' => {
960 DelayEngine => 'off',
961 },
962 },
963 };
964
965 my ($port, $config_user, $config_group) = config_write($config_file, $config);
966
967 # Open pipes, for use between the parent and child processes. Specifically,
968 # the child will indicate when it's done with its test by writing a message
969 # to the parent.
970 my ($rfh, $wfh);
971 unless (pipe($rfh, $wfh)) {
972 die("Can't open pipe: $!");
973 }
974
975 my $ex;
976
977 # Fork child
978 $self->handle_sigchld();
979 defined(my $pid = fork()) or die("Can't fork: $!");
980 if ($pid) {
981 eval {
982 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
983 $client->login($user, $passwd);
984
985 my ($resp_code, $resp_msg);
986
987 # XXX Hopefully this address is NOT configured on this box.
988 eval { ($resp_code, $resp_msg) = $client->eprt('|1|127.0.0.1|123|') };
989 unless ($@) {
990 die("EPRT succeeded unexpectedly");
991
992 } else {
993 $resp_code = $client->response_code();
994 $resp_msg = $client->response_msg();
995 }
996
997 my $expected;
998
999 $expected = 500;
1000 $self->assert($expected == $resp_code,
1001 test_msg("Expected $expected, got $resp_code"));
1002
1003 $expected = "Illegal EPRT command";
1004 $self->assert($expected eq $resp_msg,
1005 test_msg("Expected '$expected', got '$resp_msg'"));
1006 };
1007
1008 if ($@) {
1009 $ex = $@;
1010 }
1011
1012 $wfh->print("done\n");
1013 $wfh->flush();
1014
1015 } else {
1016 eval { server_wait($config_file, $rfh) };
1017 if ($@) {
1018 warn($@);
1019 exit 1;
1020 }
1021
1022 exit 0;
1023 }
1024
1025 # Stop server
1026 server_stop($pid_file);
1027
1028 $self->assert_child_ok($pid);
1029
1030 if ($ex) {
1031 test_append_logfile($log_file, $ex);
1032 unlink($log_file);
1033
1034 die($ex);
1035 }
1036
1037 unlink($log_file);
1038 }
1039
1040 sub eprt_during_xfer_bug3487 {
1041 my $self = shift;
1042 my $tmpdir = $self->{tmpdir};
1043
1044 my $config_file = "$tmpdir/cmds.conf";
1045 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1046 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1047
1048 my $log_file = test_get_logfile();
1049
1050 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1051 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1052
1053 my $user = 'proftpd';
1054 my $passwd = 'test';
1055 my $home_dir = File::Spec->rel2abs($tmpdir);
1056 my $uid = 500;
1057 my $gid = 500;
1058
1059 # Make sure that, if we're running as root, that the home directory has
1060 # permissions/privs set for the account we create
1061 if ($< == 0) {
1062 unless (chmod(0755, $home_dir)) {
1063 die("Can't set perms on $home_dir to 0755: $!");
1064 }
1065
1066 unless (chown($uid, $gid, $home_dir)) {
1067 die("Can't set owner of $home_dir to $uid/$gid: $!");
1068 }
1069 }
1070
1071 # For this test, we need to create many files in the home directory
1072 my $test_file_prefix = File::Spec->rel2abs("$tmpdir/test_");
1073
1074 my $count = 7000;
1075 for (my $i = 1; $i <= $count; $i++) {
1076 my $test_file = 'test_' . sprintf("%07s", $i);
1077 my $test_path = "$home_dir/$test_file";
1078
1079 if (open(my $fh, "> $test_path")) {
1080 close($fh);
1081
1082 } else {
1083 die("Can't open $test_path: $!");
1084 }
1085 }
1086
1087 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1088 '/bin/bash');
1089 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1090
1091 my $config = {
1092 PidFile => $pid_file,
1093 ScoreboardFile => $scoreboard_file,
1094 SystemLog => $log_file,
1095 TraceLog => $log_file,
1096 Trace => 'DEFAULT:10',
1097
1098 AuthUserFile => $auth_user_file,
1099 AuthGroupFile => $auth_group_file,
1100 AuthOrder => 'mod_auth_file.c',
1101
1102 IfModules => {
1103 'mod_delay.c' => {
1104 DelayEngine => 'off',
1105 },
1106 },
1107 };
1108
1109 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1110
1111 # Open pipes, for use between the parent and child processes. Specifically,
1112 # the child will indicate when it's done with its test by writing a message
1113 # to the parent.
1114 my ($rfh, $wfh);
1115 unless (pipe($rfh, $wfh)) {
1116 die("Can't open pipe: $!");
1117 }
1118
1119 my $ex;
1120
1121 # Fork child
1122 $self->handle_sigchld();
1123 defined(my $pid = fork()) or die("Can't fork: $!");
1124 if ($pid) {
1125 eval {
1126 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1127 $client->login($user, $passwd);
1128
1129 my $conn = $client->list_raw();
1130 unless ($conn) {
1131 die("Failed to LIST: " . $client->response_code() . " " .
1132 $client->response_msg());
1133 }
1134
1135 my ($buf, $tmp);
1136 $conn->read($tmp, 8, 30);
1137 $buf .= $tmp;
1138
1139 eval { $client->eprt('|1|127.0.0.1|4856|') };
1140 unless ($@) {
1141 die("EPRT succeeded unexpectedly");
1142 }
1143
1144 my $resp_code = $client->response_code();
1145 my $resp_msg = $client->response_msg();
1146
1147 my $expected;
1148
1149 $expected = 450;
1150 $self->assert($expected == $resp_code,
1151 test_msg("Expected $expected, got $resp_code"));
1152
1153 $expected = 'EPRT: data transfer in progress';
1154 $self->assert($expected eq $resp_msg,
1155 test_msg("Expected '$expected', got '$resp_msg'"));
1156
1157 # Finish reading the data
1158 while ($conn->read($tmp, 32768, 30)) {
1159 $buf .= $tmp;
1160 }
1161 $conn->close();
1162
1163 $resp_code = $client->response_code();
1164 $resp_msg = $client->response_msg();
1165
1166 $expected = 226;
1167 $self->assert($expected == $resp_code,
1168 test_msg("Expected $expected, got $resp_code"));
1169
1170 $expected = 'Transfer complete';
1171 $self->assert($expected eq $resp_msg,
1172 test_msg("Expected '$expected', got '$resp_msg'"));
1173 };
1174
1175 if ($@) {
1176 $ex = $@;
1177 }
1178
1179 $wfh->print("done\n");
1180 $wfh->flush();
1181
1182 } else {
1183 eval { server_wait($config_file, $rfh) };
1184 if ($@) {
1185 warn($@);
1186 exit 1;
1187 }
1188
1189 exit 0;
1190 }
1191
1192 # Stop server
1193 server_stop($pid_file);
1194
1195 $self->assert_child_ok($pid);
1196
1197 if ($ex) {
1198 test_append_logfile($log_file, $ex);
1199 unlink($log_file);
1200
1201 die($ex);
1202 }
1203
1204 unlink($log_file);
1205 }
1206
1207 1;