Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_wrap2_file.pm

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