Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/TimeoutStalled.pm

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