Debian Codegraph @

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

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