Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::Classes;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Spec;
8 use IO::Handle;
9
10 use ProFTPD::TestSuite::FTP;
11 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
12
13 $| = 1;
14
15 my $order = 0;
16
17 my $TESTS = {
18 class_from_all_allow => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 class_from_none_deny => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 class_from_ipaddr_allow => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 class_from_ipaddr_deny => {
34 order => ++$order,
35 test_class => [qw(forking)],
36 },
37
38 class_from_negated_ipaddr_allow => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 class_from_negated_ipaddr_deny => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 class_from_netmask_allow => {
49 order => ++$order,
50 test_class => [qw(forking)],
51 },
52
53 class_from_netmask_deny => {
54 order => ++$order,
55 test_class => [qw(forking)],
56 },
57
58 class_from_negated_netmask_allow => {
59 order => ++$order,
60 test_class => [qw(forking)],
61 },
62
63 class_from_negated_netmask_deny => {
64 order => ++$order,
65 test_class => [qw(forking)],
66 },
67
68 class_from_dns_name_allow => {
69 order => ++$order,
70 test_class => [qw(forking)],
71 },
72
73 class_from_dns_name_deny => {
74 order => ++$order,
75 test_class => [qw(forking)],
76 },
77
78 class_from_negated_dns_name_allow => {
79 order => ++$order,
80 test_class => [qw(forking)],
81 },
82
83 class_from_negated_dns_name_deny => {
84 order => ++$order,
85 test_class => [qw(forking)],
86 },
87
88 class_from_dns_glob_allow => {
89 order => ++$order,
90 test_class => [qw(forking)],
91 },
92
93 class_from_dns_glob_deny => {
94 order => ++$order,
95 test_class => [qw(forking)],
96 },
97
98 class_from_negated_dns_glob_allow => {
99 order => ++$order,
100 test_class => [qw(forking)],
101 },
102
103 class_from_negated_dns_glob_deny => {
104 order => ++$order,
105 test_class => [qw(forking)],
106 },
107
108 class_satisfy_any => {
109 order => ++$order,
110 test_class => [qw(forking)],
111 },
112
113 class_satisfy_all => {
114 order => ++$order,
115 test_class => [qw(forking)],
116 },
117
118 class_from_global_issue1597 => {
119 order => ++$order,
120 test_class => [qw(bug forking)],
121 },
122
123 };
124
125 sub new {
126 return shift()->SUPER::new(@_);
127 }
128
129 sub list_tests {
130 return testsuite_get_runnable_tests($TESTS);
131 }
132
133 sub class_from_all_allow {
134 my $self = shift;
135 my $tmpdir = $self->{tmpdir};
136
137 my $config_file = "$tmpdir/config.conf";
138 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
139 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
140
141 my $log_file = File::Spec->rel2abs('tests.log');
142
143 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
144 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
145
146 my $user = 'proftpd';
147 my $passwd = 'test';
148 my $home_dir = File::Spec->rel2abs($tmpdir);
149 my $uid = 500;
150 my $gid = 500;
151
152 # Make sure that, if we're running as root, that the home directory has
153 # permissions/privs set for the account we create
154 if ($< == 0) {
155 unless (chmod(0755, $home_dir)) {
156 die("Can't set perms on $home_dir to 0755: $!");
157 }
158
159 unless (chown($uid, $gid, $home_dir)) {
160 die("Can't set owner of $home_dir to $uid/$gid: $!");
161 }
162 }
163
164 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
165 '/bin/bash');
166 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
167
168 my $class_name = 'test-class';
169
170 my $config = {
171 PidFile => $pid_file,
172 ScoreboardFile => $scoreboard_file,
173 SystemLog => $log_file,
174 TraceLog => $log_file,
175 Trace => 'class:10 netaddr:10 netacl:10',
176
177 AuthUserFile => $auth_user_file,
178 AuthGroupFile => $auth_group_file,
179 AuthOrder => 'mod_auth_file.c',
180
181 Limit => {
182 LOGIN => {
183 Order => 'allow,deny',
184 AllowClass => $class_name,
185 DenyAll => '',
186 },
187 },
188
189 IfModules => {
190 'mod_delay.c' => {
191 DelayEngine => 'off',
192 },
193 },
194 };
195
196 my ($port, $config_user, $config_group) = config_write($config_file, $config);
197
198 if (open(my $fh, ">> $config_file")) {
199 print $fh <<EOC;
200 <Class $class_name>
201 From all
202 </Class>
203 EOC
204 unless (close($fh)) {
205 die("Can't write $config_file: $!");
206 }
207
208 } else {
209 die("Can't open $config_file: $!");
210 }
211
212 # Open pipes, for use between the parent and child processes. Specifically,
213 # the child will indicate when it's done with its test by writing a message
214 # to the parent.
215 my ($rfh, $wfh);
216 unless (pipe($rfh, $wfh)) {
217 die("Can't open pipe: $!");
218 }
219
220 my $ex;
221
222 # Fork child
223 $self->handle_sigchld();
224 defined(my $pid = fork()) or die("Can't fork: $!");
225 if ($pid) {
226 eval {
227 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
228 $client->login($user, $passwd);
229 $client->quit();
230 };
231
232 if ($@) {
233 $ex = $@;
234 }
235
236 $wfh->print("done\n");
237 $wfh->flush();
238
239 } else {
240 eval { server_wait($config_file, $rfh) };
241 if ($@) {
242 warn($@);
243 exit 1;
244 }
245
246 exit 0;
247 }
248
249 # Stop server
250 server_stop($pid_file);
251
252 $self->assert_child_ok($pid);
253
254 if ($ex) {
255 die($ex);
256 }
257
258 unlink($log_file);
259 }
260
261 sub class_from_none_deny {
262 my $self = shift;
263 my $tmpdir = $self->{tmpdir};
264
265 my $config_file = "$tmpdir/config.conf";
266 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
267 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
268
269 my $log_file = File::Spec->rel2abs('tests.log');
270
271 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
272 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
273
274 my $user = 'proftpd';
275 my $passwd = 'test';
276 my $home_dir = File::Spec->rel2abs($tmpdir);
277 my $uid = 500;
278 my $gid = 500;
279
280 # Make sure that, if we're running as root, that the home directory has
281 # permissions/privs set for the account we create
282 if ($< == 0) {
283 unless (chmod(0755, $home_dir)) {
284 die("Can't set perms on $home_dir to 0755: $!");
285 }
286
287 unless (chown($uid, $gid, $home_dir)) {
288 die("Can't set owner of $home_dir to $uid/$gid: $!");
289 }
290 }
291
292 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
293 '/bin/bash');
294 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
295
296 my $class_name = 'test-class';
297
298 my $config = {
299 PidFile => $pid_file,
300 ScoreboardFile => $scoreboard_file,
301 SystemLog => $log_file,
302 TraceLog => $log_file,
303 Trace => 'class:10 netaddr:10 netacl:10',
304
305 AuthUserFile => $auth_user_file,
306 AuthGroupFile => $auth_group_file,
307 AuthOrder => 'mod_auth_file.c',
308
309 Limit => {
310 LOGIN => {
311 Order => 'allow,deny',
312 AllowClass => $class_name,
313 DenyAll => '',
314 },
315 },
316
317 IfModules => {
318 'mod_delay.c' => {
319 DelayEngine => 'off',
320 },
321 },
322 };
323
324 my ($port, $config_user, $config_group) = config_write($config_file, $config);
325
326 if (open(my $fh, ">> $config_file")) {
327 print $fh <<EOC;
328 <Class $class_name>
329 From none
330 </Class>
331 EOC
332 unless (close($fh)) {
333 die("Can't write $config_file: $!");
334 }
335
336 } else {
337 die("Can't open $config_file: $!");
338 }
339
340 # Open pipes, for use between the parent and child processes. Specifically,
341 # the child will indicate when it's done with its test by writing a message
342 # to the parent.
343 my ($rfh, $wfh);
344 unless (pipe($rfh, $wfh)) {
345 die("Can't open pipe: $!");
346 }
347
348 my $ex;
349
350 # Fork child
351 $self->handle_sigchld();
352 defined(my $pid = fork()) or die("Can't fork: $!");
353 if ($pid) {
354 eval {
355 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
356
357 # Since class-based ACLs are enforced at connect time, we don't
358 # expect this connection to succeed.
359 unless ($@) {
360 die("Connection succeeded unexpectedly");
361 }
362 };
363
364 if ($@) {
365 $ex = $@;
366 }
367
368 $wfh->print("done\n");
369 $wfh->flush();
370
371 } else {
372 eval { server_wait($config_file, $rfh) };
373 if ($@) {
374 warn($@);
375 exit 1;
376 }
377
378 exit 0;
379 }
380
381 # Stop server
382 server_stop($pid_file);
383
384 $self->assert_child_ok($pid);
385
386 if ($ex) {
387 die($ex);
388 }
389
390 unlink($log_file);
391 }
392
393 sub class_from_ipaddr_allow {
394 my $self = shift;
395 my $tmpdir = $self->{tmpdir};
396
397 my $config_file = "$tmpdir/config.conf";
398 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
399 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
400
401 my $log_file = File::Spec->rel2abs('tests.log');
402
403 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
404 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
405
406 my $user = 'proftpd';
407 my $passwd = 'test';
408 my $home_dir = File::Spec->rel2abs($tmpdir);
409 my $uid = 500;
410 my $gid = 500;
411
412 # Make sure that, if we're running as root, that the home directory has
413 # permissions/privs set for the account we create
414 if ($< == 0) {
415 unless (chmod(0755, $home_dir)) {
416 die("Can't set perms on $home_dir to 0755: $!");
417 }
418
419 unless (chown($uid, $gid, $home_dir)) {
420 die("Can't set owner of $home_dir to $uid/$gid: $!");
421 }
422 }
423
424 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
425 '/bin/bash');
426 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
427
428 my $class_name = 'test-class';
429
430 my $config = {
431 PidFile => $pid_file,
432 ScoreboardFile => $scoreboard_file,
433 SystemLog => $log_file,
434 TraceLog => $log_file,
435 Trace => 'class:10 netaddr:10 netacl:10',
436
437 AuthUserFile => $auth_user_file,
438 AuthGroupFile => $auth_group_file,
439 AuthOrder => 'mod_auth_file.c',
440
441 Limit => {
442 LOGIN => {
443 Order => 'allow,deny',
444 AllowClass => $class_name,
445 DenyAll => '',
446 },
447 },
448
449 IfModules => {
450 'mod_delay.c' => {
451 DelayEngine => 'off',
452 },
453 },
454 };
455
456 my ($port, $config_user, $config_group) = config_write($config_file, $config);
457
458 if (open(my $fh, ">> $config_file")) {
459 print $fh <<EOC;
460 <Class $class_name>
461 From 127.0.0.1
462 </Class>
463 EOC
464 unless (close($fh)) {
465 die("Can't write $config_file: $!");
466 }
467
468 } else {
469 die("Can't open $config_file: $!");
470 }
471
472 # Open pipes, for use between the parent and child processes. Specifically,
473 # the child will indicate when it's done with its test by writing a message
474 # to the parent.
475 my ($rfh, $wfh);
476 unless (pipe($rfh, $wfh)) {
477 die("Can't open pipe: $!");
478 }
479
480 my $ex;
481
482 # Fork child
483 $self->handle_sigchld();
484 defined(my $pid = fork()) or die("Can't fork: $!");
485 if ($pid) {
486 eval {
487 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
488 $client->login($user, $passwd);
489 $client->quit();
490 };
491
492 if ($@) {
493 $ex = $@;
494 }
495
496 $wfh->print("done\n");
497 $wfh->flush();
498
499 } else {
500 eval { server_wait($config_file, $rfh) };
501 if ($@) {
502 warn($@);
503 exit 1;
504 }
505
506 exit 0;
507 }
508
509 # Stop server
510 server_stop($pid_file);
511
512 $self->assert_child_ok($pid);
513
514 if ($ex) {
515 die($ex);
516 }
517
518 unlink($log_file);
519 }
520
521 sub class_from_ipaddr_deny {
522 my $self = shift;
523 my $tmpdir = $self->{tmpdir};
524
525 my $config_file = "$tmpdir/config.conf";
526 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
527 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
528
529 my $log_file = File::Spec->rel2abs('tests.log');
530
531 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
532 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
533
534 my $user = 'proftpd';
535 my $passwd = 'test';
536 my $home_dir = File::Spec->rel2abs($tmpdir);
537 my $uid = 500;
538 my $gid = 500;
539
540 # Make sure that, if we're running as root, that the home directory has
541 # permissions/privs set for the account we create
542 if ($< == 0) {
543 unless (chmod(0755, $home_dir)) {
544 die("Can't set perms on $home_dir to 0755: $!");
545 }
546
547 unless (chown($uid, $gid, $home_dir)) {
548 die("Can't set owner of $home_dir to $uid/$gid: $!");
549 }
550 }
551
552 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
553 '/bin/bash');
554 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
555
556 my $class_name = 'test-class';
557
558 my $config = {
559 PidFile => $pid_file,
560 ScoreboardFile => $scoreboard_file,
561 SystemLog => $log_file,
562 TraceLog => $log_file,
563 Trace => 'class:10 netaddr:10 netacl:10',
564
565 AuthUserFile => $auth_user_file,
566 AuthGroupFile => $auth_group_file,
567 AuthOrder => 'mod_auth_file.c',
568
569 Limit => {
570 LOGIN => {
571 Order => 'allow,deny',
572 AllowClass => 'foo',
573 DenyAll => '',
574 },
575 },
576
577 IfModules => {
578 'mod_delay.c' => {
579 DelayEngine => 'off',
580 },
581 },
582 };
583
584 my ($port, $config_user, $config_group) = config_write($config_file, $config);
585
586 if (open(my $fh, ">> $config_file")) {
587 print $fh <<EOC;
588 <Class $class_name>
589 From 127.0.0.1
590 </Class>
591 EOC
592 unless (close($fh)) {
593 die("Can't write $config_file: $!");
594 }
595
596 } else {
597 die("Can't open $config_file: $!");
598 }
599
600 # Open pipes, for use between the parent and child processes. Specifically,
601 # the child will indicate when it's done with its test by writing a message
602 # to the parent.
603 my ($rfh, $wfh);
604 unless (pipe($rfh, $wfh)) {
605 die("Can't open pipe: $!");
606 }
607
608 my $ex;
609
610 # Fork child
611 $self->handle_sigchld();
612 defined(my $pid = fork()) or die("Can't fork: $!");
613 if ($pid) {
614 eval {
615 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
616
617 # Since class-based ACLs are enforced at connect time, we don't
618 # expect this connection to succeed.
619 unless ($@) {
620 die("Connection succeeded unexpectedly");
621 }
622 };
623
624 if ($@) {
625 $ex = $@;
626 }
627
628 $wfh->print("done\n");
629 $wfh->flush();
630
631 } else {
632 eval { server_wait($config_file, $rfh) };
633 if ($@) {
634 warn($@);
635 exit 1;
636 }
637
638 exit 0;
639 }
640
641 # Stop server
642 server_stop($pid_file);
643
644 $self->assert_child_ok($pid);
645
646 if ($ex) {
647 die($ex);
648 }
649
650 unlink($log_file);
651 }
652
653 sub class_from_negated_ipaddr_allow {
654 my $self = shift;
655 my $tmpdir = $self->{tmpdir};
656
657 my $config_file = "$tmpdir/config.conf";
658 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
659 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
660
661 my $log_file = File::Spec->rel2abs('tests.log');
662
663 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
664 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
665
666 my $user = 'proftpd';
667 my $passwd = 'test';
668 my $home_dir = File::Spec->rel2abs($tmpdir);
669 my $uid = 500;
670 my $gid = 500;
671
672 # Make sure that, if we're running as root, that the home directory has
673 # permissions/privs set for the account we create
674 if ($< == 0) {
675 unless (chmod(0755, $home_dir)) {
676 die("Can't set perms on $home_dir to 0755: $!");
677 }
678
679 unless (chown($uid, $gid, $home_dir)) {
680 die("Can't set owner of $home_dir to $uid/$gid: $!");
681 }
682 }
683
684 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
685 '/bin/bash');
686 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
687
688 my $class_name = 'test-class';
689
690 my $config = {
691 PidFile => $pid_file,
692 ScoreboardFile => $scoreboard_file,
693 SystemLog => $log_file,
694 TraceLog => $log_file,
695 Trace => 'class:10 netaddr:10 netacl:10',
696
697 AuthUserFile => $auth_user_file,
698 AuthGroupFile => $auth_group_file,
699 AuthOrder => 'mod_auth_file.c',
700
701 Limit => {
702 LOGIN => {
703 Order => 'allow,deny',
704 AllowClass => $class_name,
705 DenyAll => '',
706 },
707 },
708
709 IfModules => {
710 'mod_delay.c' => {
711 DelayEngine => 'off',
712 },
713 },
714 };
715
716 my ($port, $config_user, $config_group) = config_write($config_file, $config);
717
718 if (open(my $fh, ">> $config_file")) {
719 print $fh <<EOC;
720 <Class $class_name>
721 From \!127.0.0.2
722 </Class>
723 EOC
724 unless (close($fh)) {
725 die("Can't write $config_file: $!");
726 }
727
728 } else {
729 die("Can't open $config_file: $!");
730 }
731
732 # Open pipes, for use between the parent and child processes. Specifically,
733 # the child will indicate when it's done with its test by writing a message
734 # to the parent.
735 my ($rfh, $wfh);
736 unless (pipe($rfh, $wfh)) {
737 die("Can't open pipe: $!");
738 }
739
740 my $ex;
741
742 # Fork child
743 $self->handle_sigchld();
744 defined(my $pid = fork()) or die("Can't fork: $!");
745 if ($pid) {
746 eval {
747 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
748 $client->login($user, $passwd);
749 $client->quit();
750 };
751
752 if ($@) {
753 $ex = $@;
754 }
755
756 $wfh->print("done\n");
757 $wfh->flush();
758
759 } else {
760 eval { server_wait($config_file, $rfh) };
761 if ($@) {
762 warn($@);
763 exit 1;
764 }
765
766 exit 0;
767 }
768
769 # Stop server
770 server_stop($pid_file);
771
772 $self->assert_child_ok($pid);
773
774 if ($ex) {
775 die($ex);
776 }
777
778 unlink($log_file);
779 }
780
781 sub class_from_negated_ipaddr_deny {
782 my $self = shift;
783 my $tmpdir = $self->{tmpdir};
784
785 my $config_file = "$tmpdir/config.conf";
786 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
787 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
788
789 my $log_file = File::Spec->rel2abs('tests.log');
790
791 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
792 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
793
794 my $user = 'proftpd';
795 my $passwd = 'test';
796 my $home_dir = File::Spec->rel2abs($tmpdir);
797 my $uid = 500;
798 my $gid = 500;
799
800 # Make sure that, if we're running as root, that the home directory has
801 # permissions/privs set for the account we create
802 if ($< == 0) {
803 unless (chmod(0755, $home_dir)) {
804 die("Can't set perms on $home_dir to 0755: $!");
805 }
806
807 unless (chown($uid, $gid, $home_dir)) {
808 die("Can't set owner of $home_dir to $uid/$gid: $!");
809 }
810 }
811
812 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
813 '/bin/bash');
814 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
815
816 my $class_name = 'test-class';
817
818 my $config = {
819 PidFile => $pid_file,
820 ScoreboardFile => $scoreboard_file,
821 SystemLog => $log_file,
822 TraceLog => $log_file,
823 Trace => 'class:10 netaddr:10 netacl:10',
824
825 AuthUserFile => $auth_user_file,
826 AuthGroupFile => $auth_group_file,
827 AuthOrder => 'mod_auth_file.c',
828
829 Limit => {
830 LOGIN => {
831 Order => 'allow,deny',
832 AllowClass => 'foo',
833 DenyAll => '',
834 },
835 },
836
837 IfModules => {
838 'mod_delay.c' => {
839 DelayEngine => 'off',
840 },
841 },
842 };
843
844 my ($port, $config_user, $config_group) = config_write($config_file, $config);
845
846 if (open(my $fh, ">> $config_file")) {
847 print $fh <<EOC;
848 <Class $class_name>
849 From \!127.0.0.2
850 </Class>
851 EOC
852 unless (close($fh)) {
853 die("Can't write $config_file: $!");
854 }
855
856 } else {
857 die("Can't open $config_file: $!");
858 }
859
860 # Open pipes, for use between the parent and child processes. Specifically,
861 # the child will indicate when it's done with its test by writing a message
862 # to the parent.
863 my ($rfh, $wfh);
864 unless (pipe($rfh, $wfh)) {
865 die("Can't open pipe: $!");
866 }
867
868 my $ex;
869
870 # Fork child
871 $self->handle_sigchld();
872 defined(my $pid = fork()) or die("Can't fork: $!");
873 if ($pid) {
874 eval {
875 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
876
877 # Since class-based ACLs are enforced at connect time, we don't
878 # expect this connection to succeed.
879 unless ($@) {
880 die("Connection succeeded unexpectedly");
881 }
882 };
883
884 if ($@) {
885 $ex = $@;
886 }
887
888 $wfh->print("done\n");
889 $wfh->flush();
890
891 } else {
892 eval { server_wait($config_file, $rfh) };
893 if ($@) {
894 warn($@);
895 exit 1;
896 }
897
898 exit 0;
899 }
900
901 # Stop server
902 server_stop($pid_file);
903
904 $self->assert_child_ok($pid);
905
906 if ($ex) {
907 die($ex);
908 }
909
910 unlink($log_file);
911 }
912
913 sub class_from_netmask_allow {
914 my $self = shift;
915 my $tmpdir = $self->{tmpdir};
916
917 my $config_file = "$tmpdir/config.conf";
918 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
919 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
920
921 my $log_file = File::Spec->rel2abs('tests.log');
922
923 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
924 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
925
926 my $user = 'proftpd';
927 my $passwd = 'test';
928 my $home_dir = File::Spec->rel2abs($tmpdir);
929 my $uid = 500;
930 my $gid = 500;
931
932 # Make sure that, if we're running as root, that the home directory has
933 # permissions/privs set for the account we create
934 if ($< == 0) {
935 unless (chmod(0755, $home_dir)) {
936 die("Can't set perms on $home_dir to 0755: $!");
937 }
938
939 unless (chown($uid, $gid, $home_dir)) {
940 die("Can't set owner of $home_dir to $uid/$gid: $!");
941 }
942 }
943
944 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
945 '/bin/bash');
946 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
947
948 my $class_name = 'test-class';
949
950 my $config = {
951 PidFile => $pid_file,
952 ScoreboardFile => $scoreboard_file,
953 SystemLog => $log_file,
954 TraceLog => $log_file,
955 Trace => 'class:10 netaddr:10 netacl:10',
956
957 AuthUserFile => $auth_user_file,
958 AuthGroupFile => $auth_group_file,
959 AuthOrder => 'mod_auth_file.c',
960
961 Limit => {
962 LOGIN => {
963 Order => 'allow,deny',
964 AllowClass => $class_name,
965 DenyAll => '',
966 },
967 },
968
969 IfModules => {
970 'mod_delay.c' => {
971 DelayEngine => 'off',
972 },
973 },
974 };
975
976 my ($port, $config_user, $config_group) = config_write($config_file, $config);
977
978 if (open(my $fh, ">> $config_file")) {
979 print $fh <<EOC;
980 <Class $class_name>
981 From 127.0.0.0/8
982 </Class>
983 EOC
984 unless (close($fh)) {
985 die("Can't write $config_file: $!");
986 }
987
988 } else {
989 die("Can't open $config_file: $!");
990 }
991
992 # Open pipes, for use between the parent and child processes. Specifically,
993 # the child will indicate when it's done with its test by writing a message
994 # to the parent.
995 my ($rfh, $wfh);
996 unless (pipe($rfh, $wfh)) {
997 die("Can't open pipe: $!");
998 }
999
1000 my $ex;
1001
1002 # Fork child
1003 $self->handle_sigchld();
1004 defined(my $pid = fork()) or die("Can't fork: $!");
1005 if ($pid) {
1006 eval {
1007 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
1008 $client->login($user, $passwd);
1009 $client->quit();
1010 };
1011
1012 if ($@) {
1013 $ex = $@;
1014 }
1015
1016 $wfh->print("done\n");
1017 $wfh->flush();
1018
1019 } else {
1020 eval { server_wait($config_file, $rfh) };
1021 if ($@) {
1022 warn($@);
1023 exit 1;
1024 }
1025
1026 exit 0;
1027 }
1028
1029 # Stop server
1030 server_stop($pid_file);
1031
1032 $self->assert_child_ok($pid);
1033
1034 if ($ex) {
1035 die($ex);
1036 }
1037
1038 unlink($log_file);
1039 }
1040
1041 sub class_from_netmask_deny {
1042 my $self = shift;
1043 my $tmpdir = $self->{tmpdir};
1044
1045 my $config_file = "$tmpdir/config.conf";
1046 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1047 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1048
1049 my $log_file = File::Spec->rel2abs('tests.log');
1050
1051 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1052 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1053
1054 my $user = 'proftpd';
1055 my $passwd = 'test';
1056 my $home_dir = File::Spec->rel2abs($tmpdir);
1057 my $uid = 500;
1058 my $gid = 500;
1059
1060 # Make sure that, if we're running as root, that the home directory has
1061 # permissions/privs set for the account we create
1062 if ($< == 0) {
1063 unless (chmod(0755, $home_dir)) {
1064 die("Can't set perms on $home_dir to 0755: $!");
1065 }
1066
1067 unless (chown($uid, $gid, $home_dir)) {
1068 die("Can't set owner of $home_dir to $uid/$gid: $!");
1069 }
1070 }
1071
1072 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1073 '/bin/bash');
1074 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1075
1076 my $class_name = 'test-class';
1077
1078 my $config = {
1079 PidFile => $pid_file,
1080 ScoreboardFile => $scoreboard_file,
1081 SystemLog => $log_file,
1082 TraceLog => $log_file,
1083 Trace => 'class:10 netaddr:10 netacl:10',
1084
1085 AuthUserFile => $auth_user_file,
1086 AuthGroupFile => $auth_group_file,
1087 AuthOrder => 'mod_auth_file.c',
1088
1089 Limit => {
1090 LOGIN => {
1091 Order => 'allow,deny',
1092 AllowClass => 'foo',
1093 DenyAll => '',
1094 },
1095 },
1096
1097 IfModules => {
1098 'mod_delay.c' => {
1099 DelayEngine => 'off',
1100 },
1101 },
1102 };
1103
1104 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1105
1106 if (open(my $fh, ">> $config_file")) {
1107 print $fh <<EOC;
1108 <Class $class_name>
1109 From 127.0.0.0/8
1110 </Class>
1111 EOC
1112 unless (close($fh)) {
1113 die("Can't write $config_file: $!");
1114 }
1115
1116 } else {
1117 die("Can't open $config_file: $!");
1118 }
1119
1120 # Open pipes, for use between the parent and child processes. Specifically,
1121 # the child will indicate when it's done with its test by writing a message
1122 # to the parent.
1123 my ($rfh, $wfh);
1124 unless (pipe($rfh, $wfh)) {
1125 die("Can't open pipe: $!");
1126 }
1127
1128 my $ex;
1129
1130 # Fork child
1131 $self->handle_sigchld();
1132 defined(my $pid = fork()) or die("Can't fork: $!");
1133 if ($pid) {
1134 eval {
1135 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
1136
1137 # Since class-based ACLs are enforced at connect time, we don't
1138 # expect this connection to succeed.
1139 unless ($@) {
1140 die("Connection succeeded unexpectedly");
1141 }
1142 };
1143
1144 if ($@) {
1145 $ex = $@;
1146 }
1147
1148 $wfh->print("done\n");
1149 $wfh->flush();
1150
1151 } else {
1152 eval { server_wait($config_file, $rfh) };
1153 if ($@) {
1154 warn($@);
1155 exit 1;
1156 }
1157
1158 exit 0;
1159 }
1160
1161 # Stop server
1162 server_stop($pid_file);
1163
1164 $self->assert_child_ok($pid);
1165
1166 if ($ex) {
1167 die($ex);
1168 }
1169
1170 unlink($log_file);
1171 }
1172
1173 sub class_from_negated_netmask_allow {
1174 my $self = shift;
1175 my $tmpdir = $self->{tmpdir};
1176
1177 my $config_file = "$tmpdir/config.conf";
1178 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1179 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1180
1181 my $log_file = File::Spec->rel2abs('tests.log');
1182
1183 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1184 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1185
1186 my $user = 'proftpd';
1187 my $passwd = 'test';
1188 my $home_dir = File::Spec->rel2abs($tmpdir);
1189 my $uid = 500;
1190 my $gid = 500;
1191
1192 # Make sure that, if we're running as root, that the home directory has
1193 # permissions/privs set for the account we create
1194 if ($< == 0) {
1195 unless (chmod(0755, $home_dir)) {
1196 die("Can't set perms on $home_dir to 0755: $!");
1197 }
1198
1199 unless (chown($uid, $gid, $home_dir)) {
1200 die("Can't set owner of $home_dir to $uid/$gid: $!");
1201 }
1202 }
1203
1204 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1205 '/bin/bash');
1206 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1207
1208 my $class_name = 'test-class';
1209
1210 my $config = {
1211 PidFile => $pid_file,
1212 ScoreboardFile => $scoreboard_file,
1213 SystemLog => $log_file,
1214 TraceLog => $log_file,
1215 Trace => 'class:10 netaddr:10 netacl:10',
1216
1217 AuthUserFile => $auth_user_file,
1218 AuthGroupFile => $auth_group_file,
1219 AuthOrder => 'mod_auth_file.c',
1220
1221 Limit => {
1222 LOGIN => {
1223 Order => 'allow,deny',
1224 AllowClass => $class_name,
1225 DenyAll => '',
1226 },
1227 },
1228
1229 IfModules => {
1230 'mod_delay.c' => {
1231 DelayEngine => 'off',
1232 },
1233 },
1234 };
1235
1236 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1237
1238 if (open(my $fh, ">> $config_file")) {
1239 print $fh <<EOC;
1240 <Class $class_name>
1241 From \!126.0.0.0/8
1242 </Class>
1243 EOC
1244 unless (close($fh)) {
1245 die("Can't write $config_file: $!");
1246 }
1247
1248 } else {
1249 die("Can't open $config_file: $!");
1250 }
1251
1252 # Open pipes, for use between the parent and child processes. Specifically,
1253 # the child will indicate when it's done with its test by writing a message
1254 # to the parent.
1255 my ($rfh, $wfh);
1256 unless (pipe($rfh, $wfh)) {
1257 die("Can't open pipe: $!");
1258 }
1259
1260 my $ex;
1261
1262 # Fork child
1263 $self->handle_sigchld();
1264 defined(my $pid = fork()) or die("Can't fork: $!");
1265 if ($pid) {
1266 eval {
1267 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
1268 $client->login($user, $passwd);
1269 $client->quit();
1270 };
1271
1272 if ($@) {
1273 $ex = $@;
1274 }
1275
1276 $wfh->print("done\n");
1277 $wfh->flush();
1278
1279 } else {
1280 eval { server_wait($config_file, $rfh) };
1281 if ($@) {
1282 warn($@);
1283 exit 1;
1284 }
1285
1286 exit 0;
1287 }
1288
1289 # Stop server
1290 server_stop($pid_file);
1291
1292 $self->assert_child_ok($pid);
1293
1294 if ($ex) {
1295 die($ex);
1296 }
1297
1298 unlink($log_file);
1299 }
1300
1301 sub class_from_negated_netmask_deny {
1302 my $self = shift;
1303 my $tmpdir = $self->{tmpdir};
1304
1305 my $config_file = "$tmpdir/config.conf";
1306 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1307 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1308
1309 my $log_file = File::Spec->rel2abs('tests.log');
1310
1311 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1312 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1313
1314 my $user = 'proftpd';
1315 my $passwd = 'test';
1316 my $home_dir = File::Spec->rel2abs($tmpdir);
1317 my $uid = 500;
1318 my $gid = 500;
1319
1320 # Make sure that, if we're running as root, that the home directory has
1321 # permissions/privs set for the account we create
1322 if ($< == 0) {
1323 unless (chmod(0755, $home_dir)) {
1324 die("Can't set perms on $home_dir to 0755: $!");
1325 }
1326
1327 unless (chown($uid, $gid, $home_dir)) {
1328 die("Can't set owner of $home_dir to $uid/$gid: $!");
1329 }
1330 }
1331
1332 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1333 '/bin/bash');
1334 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1335
1336 my $class_name = 'test-class';
1337
1338 my $config = {
1339 PidFile => $pid_file,
1340 ScoreboardFile => $scoreboard_file,
1341 SystemLog => $log_file,
1342 TraceLog => $log_file,
1343 Trace => 'class:10 netaddr:10 netacl:10',
1344
1345 AuthUserFile => $auth_user_file,
1346 AuthGroupFile => $auth_group_file,
1347 AuthOrder => 'mod_auth_file.c',
1348
1349 Limit => {
1350 LOGIN => {
1351 Order => 'allow,deny',
1352 AllowClass => 'foo',
1353 DenyAll => '',
1354 },
1355 },
1356
1357 IfModules => {
1358 'mod_delay.c' => {
1359 DelayEngine => 'off',
1360 },
1361 },
1362 };
1363
1364 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1365
1366 if (open(my $fh, ">> $config_file")) {
1367 print $fh <<EOC;
1368 <Class $class_name>
1369 From \!126.0.0.0/8
1370 </Class>
1371 EOC
1372 unless (close($fh)) {
1373 die("Can't write $config_file: $!");
1374 }
1375
1376 } else {
1377 die("Can't open $config_file: $!");
1378 }
1379
1380 # Open pipes, for use between the parent and child processes. Specifically,
1381 # the child will indicate when it's done with its test by writing a message
1382 # to the parent.
1383 my ($rfh, $wfh);
1384 unless (pipe($rfh, $wfh)) {
1385 die("Can't open pipe: $!");
1386 }
1387
1388 my $ex;
1389
1390 # Fork child
1391 $self->handle_sigchld();
1392 defined(my $pid = fork()) or die("Can't fork: $!");
1393 if ($pid) {
1394 eval {
1395 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
1396
1397 # Since class-based ACLs are enforced at connect time, we don't
1398 # expect this connection to succeed.
1399 unless ($@) {
1400 die("Connection succeeded unexpectedly");
1401 }
1402 };
1403
1404 if ($@) {
1405 $ex = $@;
1406 }
1407
1408 $wfh->print("done\n");
1409 $wfh->flush();
1410
1411 } else {
1412 eval { server_wait($config_file, $rfh) };
1413 if ($@) {
1414 warn($@);
1415 exit 1;
1416 }
1417
1418 exit 0;
1419 }
1420
1421 # Stop server
1422 server_stop($pid_file);
1423
1424 $self->assert_child_ok($pid);
1425
1426 if ($ex) {
1427 die($ex);
1428 }
1429
1430 unlink($log_file);
1431 }
1432
1433 sub class_from_dns_name_allow {
1434 my $self = shift;
1435 my $tmpdir = $self->{tmpdir};
1436
1437 my $config_file = "$tmpdir/config.conf";
1438 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1439 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1440
1441 my $log_file = File::Spec->rel2abs('tests.log');
1442
1443 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1444 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1445
1446 my $user = 'proftpd';
1447 my $passwd = 'test';
1448 my $home_dir = File::Spec->rel2abs($tmpdir);
1449 my $uid = 500;
1450 my $gid = 500;
1451
1452 # Make sure that, if we're running as root, that the home directory has
1453 # permissions/privs set for the account we create
1454 if ($< == 0) {
1455 unless (chmod(0755, $home_dir)) {
1456 die("Can't set perms on $home_dir to 0755: $!");
1457 }
1458
1459 unless (chown($uid, $gid, $home_dir)) {
1460 die("Can't set owner of $home_dir to $uid/$gid: $!");
1461 }
1462 }
1463
1464 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1465 '/bin/bash');
1466 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1467
1468 my $class_name = 'test-class';
1469
1470 my $config = {
1471 PidFile => $pid_file,
1472 ScoreboardFile => $scoreboard_file,
1473 SystemLog => $log_file,
1474 TraceLog => $log_file,
1475 Trace => 'class:10 netaddr:10 netacl:10',
1476
1477 AuthUserFile => $auth_user_file,
1478 AuthGroupFile => $auth_group_file,
1479 AuthOrder => 'mod_auth_file.c',
1480
1481 UseReverseDNS => 'on',
1482
1483 Limit => {
1484 LOGIN => {
1485 Order => 'allow,deny',
1486 AllowClass => $class_name,
1487 DenyAll => '',
1488 },
1489 },
1490
1491 IfModules => {
1492 'mod_delay.c' => {
1493 DelayEngine => 'off',
1494 },
1495 },
1496 };
1497
1498 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1499
1500 if (open(my $fh, ">> $config_file")) {
1501 print $fh <<EOC;
1502 <Class $class_name>
1503 From localhost
1504 </Class>
1505 EOC
1506 unless (close($fh)) {
1507 die("Can't write $config_file: $!");
1508 }
1509
1510 } else {
1511 die("Can't open $config_file: $!");
1512 }
1513
1514 # Open pipes, for use between the parent and child processes. Specifically,
1515 # the child will indicate when it's done with its test by writing a message
1516 # to the parent.
1517 my ($rfh, $wfh);
1518 unless (pipe($rfh, $wfh)) {
1519 die("Can't open pipe: $!");
1520 }
1521
1522 my $ex;
1523
1524 # Fork child
1525 $self->handle_sigchld();
1526 defined(my $pid = fork()) or die("Can't fork: $!");
1527 if ($pid) {
1528 eval {
1529 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
1530 $client->login($user, $passwd);
1531 $client->quit();
1532 };
1533
1534 if ($@) {
1535 $ex = $@;
1536 }
1537
1538 $wfh->print("done\n");
1539 $wfh->flush();
1540
1541 } else {
1542 eval { server_wait($config_file, $rfh) };
1543 if ($@) {
1544 warn($@);
1545 exit 1;
1546 }
1547
1548 exit 0;
1549 }
1550
1551 # Stop server
1552 server_stop($pid_file);
1553
1554 $self->assert_child_ok($pid);
1555
1556 if ($ex) {
1557 die($ex);
1558 }
1559
1560 unlink($log_file);
1561 }
1562
1563 sub class_from_dns_name_deny {
1564 my $self = shift;
1565 my $tmpdir = $self->{tmpdir};
1566
1567 my $config_file = "$tmpdir/config.conf";
1568 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1569 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1570
1571 my $log_file = File::Spec->rel2abs('tests.log');
1572
1573 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1574 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1575
1576 my $user = 'proftpd';
1577 my $passwd = 'test';
1578 my $home_dir = File::Spec->rel2abs($tmpdir);
1579 my $uid = 500;
1580 my $gid = 500;
1581
1582 # Make sure that, if we're running as root, that the home directory has
1583 # permissions/privs set for the account we create
1584 if ($< == 0) {
1585 unless (chmod(0755, $home_dir)) {
1586 die("Can't set perms on $home_dir to 0755: $!");
1587 }
1588
1589 unless (chown($uid, $gid, $home_dir)) {
1590 die("Can't set owner of $home_dir to $uid/$gid: $!");
1591 }
1592 }
1593
1594 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1595 '/bin/bash');
1596 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1597
1598 my $class_name = 'test-class';
1599
1600 my $config = {
1601 PidFile => $pid_file,
1602 ScoreboardFile => $scoreboard_file,
1603 SystemLog => $log_file,
1604 TraceLog => $log_file,
1605 Trace => 'class:10 netaddr:10 netacl:10',
1606
1607 AuthUserFile => $auth_user_file,
1608 AuthGroupFile => $auth_group_file,
1609 AuthOrder => 'mod_auth_file.c',
1610
1611 UseReverseDNS => 'on',
1612
1613 Limit => {
1614 LOGIN => {
1615 Order => 'allow,deny',
1616 AllowClass => 'foo',
1617 DenyAll => '',
1618 },
1619 },
1620
1621 IfModules => {
1622 'mod_delay.c' => {
1623 DelayEngine => 'off',
1624 },
1625 },
1626 };
1627
1628 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1629
1630 if (open(my $fh, ">> $config_file")) {
1631 print $fh <<EOC;
1632 <Class $class_name>
1633 From localhost
1634 </Class>
1635 EOC
1636 unless (close($fh)) {
1637 die("Can't write $config_file: $!");
1638 }
1639
1640 } else {
1641 die("Can't open $config_file: $!");
1642 }
1643
1644 # Open pipes, for use between the parent and child processes. Specifically,
1645 # the child will indicate when it's done with its test by writing a message
1646 # to the parent.
1647 my ($rfh, $wfh);
1648 unless (pipe($rfh, $wfh)) {
1649 die("Can't open pipe: $!");
1650 }
1651
1652 my $ex;
1653
1654 # Fork child
1655 $self->handle_sigchld();
1656 defined(my $pid = fork()) or die("Can't fork: $!");
1657 if ($pid) {
1658 eval {
1659 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
1660
1661 # Since class-based ACLs are enforced at connect time, we don't
1662 # expect this connection to succeed.
1663 unless ($@) {
1664 die("Connection succeeded unexpectedly");
1665 }
1666 };
1667
1668 if ($@) {
1669 $ex = $@;
1670 }
1671
1672 $wfh->print("done\n");
1673 $wfh->flush();
1674
1675 } else {
1676 eval { server_wait($config_file, $rfh) };
1677 if ($@) {
1678 warn($@);
1679 exit 1;
1680 }
1681
1682 exit 0;
1683 }
1684
1685 # Stop server
1686 server_stop($pid_file);
1687
1688 $self->assert_child_ok($pid);
1689
1690 if ($ex) {
1691 die($ex);
1692 }
1693
1694 unlink($log_file);
1695 }
1696
1697 sub class_from_negated_dns_name_allow {
1698 my $self = shift;
1699 my $tmpdir = $self->{tmpdir};
1700
1701 my $config_file = "$tmpdir/config.conf";
1702 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1703 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1704
1705 my $log_file = File::Spec->rel2abs('tests.log');
1706
1707 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1708 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1709
1710 my $user = 'proftpd';
1711 my $passwd = 'test';
1712 my $home_dir = File::Spec->rel2abs($tmpdir);
1713 my $uid = 500;
1714 my $gid = 500;
1715
1716 # Make sure that, if we're running as root, that the home directory has
1717 # permissions/privs set for the account we create
1718 if ($< == 0) {
1719 unless (chmod(0755, $home_dir)) {
1720 die("Can't set perms on $home_dir to 0755: $!");
1721 }
1722
1723 unless (chown($uid, $gid, $home_dir)) {
1724 die("Can't set owner of $home_dir to $uid/$gid: $!");
1725 }
1726 }
1727
1728 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1729 '/bin/bash');
1730 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1731
1732 my $class_name = 'test-class';
1733
1734 my $config = {
1735 PidFile => $pid_file,
1736 ScoreboardFile => $scoreboard_file,
1737 SystemLog => $log_file,
1738 TraceLog => $log_file,
1739 Trace => 'class:10 netaddr:10 netacl:10',
1740
1741 AuthUserFile => $auth_user_file,
1742 AuthGroupFile => $auth_group_file,
1743 AuthOrder => 'mod_auth_file.c',
1744
1745 UseReverseDNS => 'on',
1746
1747 Limit => {
1748 LOGIN => {
1749 Order => 'allow,deny',
1750 AllowClass => $class_name,
1751 DenyAll => '',
1752 },
1753 },
1754
1755 IfModules => {
1756 'mod_delay.c' => {
1757 DelayEngine => 'off',
1758 },
1759 },
1760 };
1761
1762 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1763
1764 if (open(my $fh, ">> $config_file")) {
1765 print $fh <<EOC;
1766 <Class $class_name>
1767 From \!remotehost
1768 </Class>
1769 EOC
1770 unless (close($fh)) {
1771 die("Can't write $config_file: $!");
1772 }
1773
1774 } else {
1775 die("Can't open $config_file: $!");
1776 }
1777
1778 # Open pipes, for use between the parent and child processes. Specifically,
1779 # the child will indicate when it's done with its test by writing a message
1780 # to the parent.
1781 my ($rfh, $wfh);
1782 unless (pipe($rfh, $wfh)) {
1783 die("Can't open pipe: $!");
1784 }
1785
1786 my $ex;
1787
1788 # Fork child
1789 $self->handle_sigchld();
1790 defined(my $pid = fork()) or die("Can't fork: $!");
1791 if ($pid) {
1792 eval {
1793 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
1794 $client->login($user, $passwd);
1795 $client->quit();
1796 };
1797
1798 if ($@) {
1799 $ex = $@;
1800 }
1801
1802 $wfh->print("done\n");
1803 $wfh->flush();
1804
1805 } else {
1806 eval { server_wait($config_file, $rfh) };
1807 if ($@) {
1808 warn($@);
1809 exit 1;
1810 }
1811
1812 exit 0;
1813 }
1814
1815 # Stop server
1816 server_stop($pid_file);
1817
1818 $self->assert_child_ok($pid);
1819
1820 if ($ex) {
1821 die($ex);
1822 }
1823
1824 unlink($log_file);
1825 }
1826
1827 sub class_from_negated_dns_name_deny {
1828 my $self = shift;
1829 my $tmpdir = $self->{tmpdir};
1830
1831 my $config_file = "$tmpdir/config.conf";
1832 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1833 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1834
1835 my $log_file = File::Spec->rel2abs('tests.log');
1836
1837 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1838 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1839
1840 my $user = 'proftpd';
1841 my $passwd = 'test';
1842 my $home_dir = File::Spec->rel2abs($tmpdir);
1843 my $uid = 500;
1844 my $gid = 500;
1845
1846 # Make sure that, if we're running as root, that the home directory has
1847 # permissions/privs set for the account we create
1848 if ($< == 0) {
1849 unless (chmod(0755, $home_dir)) {
1850 die("Can't set perms on $home_dir to 0755: $!");
1851 }
1852
1853 unless (chown($uid, $gid, $home_dir)) {
1854 die("Can't set owner of $home_dir to $uid/$gid: $!");
1855 }
1856 }
1857
1858 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1859 '/bin/bash');
1860 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1861
1862 my $class_name = 'test-class';
1863
1864 my $config = {
1865 PidFile => $pid_file,
1866 ScoreboardFile => $scoreboard_file,
1867 SystemLog => $log_file,
1868 TraceLog => $log_file,
1869 Trace => 'class:10 netaddr:10 netacl:10',
1870
1871 AuthUserFile => $auth_user_file,
1872 AuthGroupFile => $auth_group_file,
1873 AuthOrder => 'mod_auth_file.c',
1874
1875 UseReverseDNS => 'on',
1876
1877 Limit => {
1878 LOGIN => {
1879 Order => 'allow,deny',
1880 AllowClass => 'foo',
1881 DenyAll => '',
1882 },
1883 },
1884
1885 IfModules => {
1886 'mod_delay.c' => {
1887 DelayEngine => 'off',
1888 },
1889 },
1890 };
1891
1892 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1893
1894 if (open(my $fh, ">> $config_file")) {
1895 print $fh <<EOC;
1896 <Class $class_name>
1897 From \!remotehost
1898 </Class>
1899 EOC
1900 unless (close($fh)) {
1901 die("Can't write $config_file: $!");
1902 }
1903
1904 } else {
1905 die("Can't open $config_file: $!");
1906 }
1907
1908 # Open pipes, for use between the parent and child processes. Specifically,
1909 # the child will indicate when it's done with its test by writing a message
1910 # to the parent.
1911 my ($rfh, $wfh);
1912 unless (pipe($rfh, $wfh)) {
1913 die("Can't open pipe: $!");
1914 }
1915
1916 my $ex;
1917
1918 # Fork child
1919 $self->handle_sigchld();
1920 defined(my $pid = fork()) or die("Can't fork: $!");
1921 if ($pid) {
1922 eval {
1923 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
1924
1925 # Since class-based ACLs are enforced at connect time, we don't
1926 # expect this connection to succeed.
1927 unless ($@) {
1928 die("Connection succeeded unexpectedly");
1929 }
1930 };
1931
1932 if ($@) {
1933 $ex = $@;
1934 }
1935
1936 $wfh->print("done\n");
1937 $wfh->flush();
1938
1939 } else {
1940 eval { server_wait($config_file, $rfh) };
1941 if ($@) {
1942 warn($@);
1943 exit 1;
1944 }
1945
1946 exit 0;
1947 }
1948
1949 # Stop server
1950 server_stop($pid_file);
1951
1952 $self->assert_child_ok($pid);
1953
1954 if ($ex) {
1955 die($ex);
1956 }
1957
1958 unlink($log_file);
1959 }
1960
1961 sub class_from_dns_glob_allow {
1962 my $self = shift;
1963 my $tmpdir = $self->{tmpdir};
1964
1965 my $config_file = "$tmpdir/config.conf";
1966 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1967 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1968
1969 my $log_file = File::Spec->rel2abs('tests.log');
1970
1971 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1972 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1973
1974 my $user = 'proftpd';
1975 my $passwd = 'test';
1976 my $home_dir = File::Spec->rel2abs($tmpdir);
1977 my $uid = 500;
1978 my $gid = 500;
1979
1980 # Make sure that, if we're running as root, that the home directory has
1981 # permissions/privs set for the account we create
1982 if ($< == 0) {
1983 unless (chmod(0755, $home_dir)) {
1984 die("Can't set perms on $home_dir to 0755: $!");
1985 }
1986
1987 unless (chown($uid, $gid, $home_dir)) {
1988 die("Can't set owner of $home_dir to $uid/$gid: $!");
1989 }
1990 }
1991
1992 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1993 '/bin/bash');
1994 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1995
1996 my $class_name = 'test-class';
1997
1998 my $config = {
1999 PidFile => $pid_file,
2000 ScoreboardFile => $scoreboard_file,
2001 SystemLog => $log_file,
2002 TraceLog => $log_file,
2003 Trace => 'class:10 netaddr:10 netacl:10',
2004
2005 AuthUserFile => $auth_user_file,
2006 AuthGroupFile => $auth_group_file,
2007 AuthOrder => 'mod_auth_file.c',
2008
2009 UseReverseDNS => 'on',
2010
2011 Limit => {
2012 LOGIN => {
2013 Order => 'allow,deny',
2014 AllowClass => $class_name,
2015 DenyAll => '',
2016 },
2017 },
2018
2019 IfModules => {
2020 'mod_delay.c' => {
2021 DelayEngine => 'off',
2022 },
2023 },
2024 };
2025
2026 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2027
2028 if (open(my $fh, ">> $config_file")) {
2029 print $fh <<EOC;
2030 <Class $class_name>
2031 From lo*o?t
2032 </Class>
2033 EOC
2034 unless (close($fh)) {
2035 die("Can't write $config_file: $!");
2036 }
2037
2038 } else {
2039 die("Can't open $config_file: $!");
2040 }
2041
2042 # Open pipes, for use between the parent and child processes. Specifically,
2043 # the child will indicate when it's done with its test by writing a message
2044 # to the parent.
2045 my ($rfh, $wfh);
2046 unless (pipe($rfh, $wfh)) {
2047 die("Can't open pipe: $!");
2048 }
2049
2050 my $ex;
2051
2052 # Fork child
2053 $self->handle_sigchld();
2054 defined(my $pid = fork()) or die("Can't fork: $!");
2055 if ($pid) {
2056 eval {
2057 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
2058 $client->login($user, $passwd);
2059 $client->quit();
2060 };
2061
2062 if ($@) {
2063 $ex = $@;
2064 }
2065
2066 $wfh->print("done\n");
2067 $wfh->flush();
2068
2069 } else {
2070 eval { server_wait($config_file, $rfh) };
2071 if ($@) {
2072 warn($@);
2073 exit 1;
2074 }
2075
2076 exit 0;
2077 }
2078
2079 # Stop server
2080 server_stop($pid_file);
2081
2082 $self->assert_child_ok($pid);
2083
2084 if ($ex) {
2085 die($ex);
2086 }
2087
2088 unlink($log_file);
2089 }
2090
2091 sub class_from_dns_glob_deny {
2092 my $self = shift;
2093 my $tmpdir = $self->{tmpdir};
2094
2095 my $config_file = "$tmpdir/config.conf";
2096 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
2097 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
2098
2099 my $log_file = File::Spec->rel2abs('tests.log');
2100
2101 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
2102 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
2103
2104 my $user = 'proftpd';
2105 my $passwd = 'test';
2106 my $home_dir = File::Spec->rel2abs($tmpdir);
2107 my $uid = 500;
2108 my $gid = 500;
2109
2110 # Make sure that, if we're running as root, that the home directory has
2111 # permissions/privs set for the account we create
2112 if ($< == 0) {
2113 unless (chmod(0755, $home_dir)) {
2114 die("Can't set perms on $home_dir to 0755: $!");
2115 }
2116
2117 unless (chown($uid, $gid, $home_dir)) {
2118 die("Can't set owner of $home_dir to $uid/$gid: $!");
2119 }
2120 }
2121
2122 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2123 '/bin/bash');
2124 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2125
2126 my $class_name = 'test-class';
2127
2128 my $config = {
2129 PidFile => $pid_file,
2130 ScoreboardFile => $scoreboard_file,
2131 SystemLog => $log_file,
2132 TraceLog => $log_file,
2133 Trace => 'class:10 netaddr:10 netacl:10',
2134
2135 AuthUserFile => $auth_user_file,
2136 AuthGroupFile => $auth_group_file,
2137 AuthOrder => 'mod_auth_file.c',
2138
2139 UseReverseDNS => 'on',
2140
2141 Limit => {
2142 LOGIN => {
2143 Order => 'allow,deny',
2144 AllowClass => 'foo',
2145 DenyAll => '',
2146 },
2147 },
2148
2149 IfModules => {
2150 'mod_delay.c' => {
2151 DelayEngine => 'off',
2152 },
2153 },
2154 };
2155
2156 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2157
2158 if (open(my $fh, ">> $config_file")) {
2159 print $fh <<EOC;
2160 <Class $class_name>
2161 From lo*o?t
2162 </Class>
2163 EOC
2164 unless (close($fh)) {
2165 die("Can't write $config_file: $!");
2166 }
2167
2168 } else {
2169 die("Can't open $config_file: $!");
2170 }
2171
2172 # Open pipes, for use between the parent and child processes. Specifically,
2173 # the child will indicate when it's done with its test by writing a message
2174 # to the parent.
2175 my ($rfh, $wfh);
2176 unless (pipe($rfh, $wfh)) {
2177 die("Can't open pipe: $!");
2178 }
2179
2180 my $ex;
2181
2182 # Fork child
2183 $self->handle_sigchld();
2184 defined(my $pid = fork()) or die("Can't fork: $!");
2185 if ($pid) {
2186 eval {
2187 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
2188
2189 # Since class-based ACLs are enforced at connect time, we don't
2190 # expect this connection to succeed.
2191 unless ($@) {
2192 die("Connection succeeded unexpectedly");
2193 }
2194 };
2195
2196 if ($@) {
2197 $ex = $@;
2198 }
2199
2200 $wfh->print("done\n");
2201 $wfh->flush();
2202
2203 } else {
2204 eval { server_wait($config_file, $rfh) };
2205 if ($@) {
2206 warn($@);
2207 exit 1;
2208 }
2209
2210 exit 0;
2211 }
2212
2213 # Stop server
2214 server_stop($pid_file);
2215
2216 $self->assert_child_ok($pid);
2217
2218 if ($ex) {
2219 die($ex);
2220 }
2221
2222 unlink($log_file);
2223 }
2224
2225 sub class_from_negated_dns_glob_allow {
2226 my $self = shift;
2227 my $tmpdir = $self->{tmpdir};
2228
2229 my $config_file = "$tmpdir/config.conf";
2230 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
2231 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
2232
2233 my $log_file = File::Spec->rel2abs('tests.log');
2234
2235 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
2236 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
2237
2238 my $user = 'proftpd';
2239 my $passwd = 'test';
2240 my $home_dir = File::Spec->rel2abs($tmpdir);
2241 my $uid = 500;
2242 my $gid = 500;
2243
2244 # Make sure that, if we're running as root, that the home directory has
2245 # permissions/privs set for the account we create
2246 if ($< == 0) {
2247 unless (chmod(0755, $home_dir)) {
2248 die("Can't set perms on $home_dir to 0755: $!");
2249 }
2250
2251 unless (chown($uid, $gid, $home_dir)) {
2252 die("Can't set owner of $home_dir to $uid/$gid: $!");
2253 }
2254 }
2255
2256 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2257 '/bin/bash');
2258 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2259
2260 my $class_name = 'test-class';
2261
2262 my $config = {
2263 PidFile => $pid_file,
2264 ScoreboardFile => $scoreboard_file,
2265 SystemLog => $log_file,
2266 TraceLog => $log_file,
2267 Trace => 'class:10 netaddr:10 netacl:10',
2268
2269 AuthUserFile => $auth_user_file,
2270 AuthGroupFile => $auth_group_file,
2271 AuthOrder => 'mod_auth_file.c',
2272
2273 UseReverseDNS => 'on',
2274
2275 Limit => {
2276 LOGIN => {
2277 Order => 'allow,deny',
2278 AllowClass => $class_name,
2279 DenyAll => '',
2280 },
2281 },
2282
2283 IfModules => {
2284 'mod_delay.c' => {
2285 DelayEngine => 'off',
2286 },
2287 },
2288 };
2289
2290 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2291
2292 if (open(my $fh, ">> $config_file")) {
2293 print $fh <<EOC;
2294 <Class $class_name>
2295 From \!rem*o?t
2296 </Class>
2297 EOC
2298 unless (close($fh)) {
2299 die("Can't write $config_file: $!");
2300 }
2301
2302 } else {
2303 die("Can't open $config_file: $!");
2304 }
2305
2306 # Open pipes, for use between the parent and child processes. Specifically,
2307 # the child will indicate when it's done with its test by writing a message
2308 # to the parent.
2309 my ($rfh, $wfh);
2310 unless (pipe($rfh, $wfh)) {
2311 die("Can't open pipe: $!");
2312 }
2313
2314 my $ex;
2315
2316 # Fork child
2317 $self->handle_sigchld();
2318 defined(my $pid = fork()) or die("Can't fork: $!");
2319 if ($pid) {
2320 eval {
2321 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
2322 $client->login($user, $passwd);
2323 $client->quit();
2324 };
2325
2326 if ($@) {
2327 $ex = $@;
2328 }
2329
2330 $wfh->print("done\n");
2331 $wfh->flush();
2332
2333 } else {
2334 eval { server_wait($config_file, $rfh) };
2335 if ($@) {
2336 warn($@);
2337 exit 1;
2338 }
2339
2340 exit 0;
2341 }
2342
2343 # Stop server
2344 server_stop($pid_file);
2345
2346 $self->assert_child_ok($pid);
2347
2348 if ($ex) {
2349 die($ex);
2350 }
2351
2352 unlink($log_file);
2353 }
2354
2355 sub class_from_negated_dns_glob_deny {
2356 my $self = shift;
2357 my $tmpdir = $self->{tmpdir};
2358
2359 my $config_file = "$tmpdir/config.conf";
2360 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
2361 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
2362
2363 my $log_file = File::Spec->rel2abs('tests.log');
2364
2365 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
2366 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
2367
2368 my $user = 'proftpd';
2369 my $passwd = 'test';
2370 my $home_dir = File::Spec->rel2abs($tmpdir);
2371 my $uid = 500;
2372 my $gid = 500;
2373
2374 # Make sure that, if we're running as root, that the home directory has
2375 # permissions/privs set for the account we create
2376 if ($< == 0) {
2377 unless (chmod(0755, $home_dir)) {
2378 die("Can't set perms on $home_dir to 0755: $!");
2379 }
2380
2381 unless (chown($uid, $gid, $home_dir)) {
2382 die("Can't set owner of $home_dir to $uid/$gid: $!");
2383 }
2384 }
2385
2386 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2387 '/bin/bash');
2388 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2389
2390 my $class_name = 'test-class';
2391
2392 my $config = {
2393 PidFile => $pid_file,
2394 ScoreboardFile => $scoreboard_file,
2395 SystemLog => $log_file,
2396 TraceLog => $log_file,
2397 Trace => 'class:10 netaddr:10 netacl:10',
2398
2399 AuthUserFile => $auth_user_file,
2400 AuthGroupFile => $auth_group_file,
2401 AuthOrder => 'mod_auth_file.c',
2402
2403 UseReverseDNS => 'on',
2404
2405 Limit => {
2406 LOGIN => {
2407 Order => 'allow,deny',
2408 AllowClass => 'foo',
2409 DenyAll => '',
2410 },
2411 },
2412
2413 IfModules => {
2414 'mod_delay.c' => {
2415 DelayEngine => 'off',
2416 },
2417 },
2418 };
2419
2420 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2421
2422 if (open(my $fh, ">> $config_file")) {
2423 print $fh <<EOC;
2424 <Class $class_name>
2425 From \!rem*o?t
2426 </Class>
2427 EOC
2428 unless (close($fh)) {
2429 die("Can't write $config_file: $!");
2430 }
2431
2432 } else {
2433 die("Can't open $config_file: $!");
2434 }
2435
2436 # Open pipes, for use between the parent and child processes. Specifically,
2437 # the child will indicate when it's done with its test by writing a message
2438 # to the parent.
2439 my ($rfh, $wfh);
2440 unless (pipe($rfh, $wfh)) {
2441 die("Can't open pipe: $!");
2442 }
2443
2444 my $ex;
2445
2446 # Fork child
2447 $self->handle_sigchld();
2448 defined(my $pid = fork()) or die("Can't fork: $!");
2449 if ($pid) {
2450 eval {
2451 eval { my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1) };
2452
2453 # Since class-based ACLs are enforced at connect time, we don't
2454 # expect this connection to succeed.
2455 unless ($@) {
2456 die("Connection succeeded unexpectedly");
2457 }
2458 };
2459
2460 if ($@) {
2461 $ex = $@;
2462 }
2463
2464 $wfh->print("done\n");
2465 $wfh->flush();
2466
2467 } else {
2468 eval { server_wait($config_file, $rfh) };
2469 if ($@) {
2470 warn($@);
2471 exit 1;
2472 }
2473
2474 exit 0;
2475 }
2476
2477 # Stop server
2478 server_stop($pid_file);
2479
2480 $self->assert_child_ok($pid);
2481
2482 if ($ex) {
2483 die($ex);
2484 }
2485
2486 unlink($log_file);
2487 }
2488
2489 sub class_satisfy_any {
2490 my $self = shift;
2491 my $tmpdir = $self->{tmpdir};
2492
2493 my $config_file = "$tmpdir/config.conf";
2494 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
2495 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
2496
2497 my $log_file = File::Spec->rel2abs('tests.log');
2498
2499 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
2500 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
2501
2502 my $user = 'proftpd';
2503 my $passwd = 'test';
2504 my $home_dir = File::Spec->rel2abs($tmpdir);
2505 my $uid = 500;
2506 my $gid = 500;
2507
2508 # Make sure that, if we're running as root, that the home directory has
2509 # permissions/privs set for the account we create
2510 if ($< == 0) {
2511 unless (chmod(0755, $home_dir)) {
2512 die("Can't set perms on $home_dir to 0755: $!");
2513 }
2514
2515 unless (chown($uid, $gid, $home_dir)) {
2516 die("Can't set owner of $home_dir to $uid/$gid: $!");
2517 }
2518 }
2519
2520 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2521 '/bin/bash');
2522 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2523
2524 my $class_name = 'test-class';
2525
2526 my $config = {
2527 PidFile => $pid_file,
2528 ScoreboardFile => $scoreboard_file,
2529 SystemLog => $log_file,
2530 TraceLog => $log_file,
2531 Trace => 'class:10 netaddr:10 netacl:10',
2532
2533 AuthUserFile => $auth_user_file,
2534 AuthGroupFile => $auth_group_file,
2535 AuthOrder => 'mod_auth_file.c',
2536
2537 Limit => {
2538 LOGIN => {
2539 Order => 'allow,deny',
2540 AllowClass => $class_name,
2541 DenyAll => '',
2542 },
2543 },
2544
2545 IfModules => {
2546 'mod_delay.c' => {
2547 DelayEngine => 'off',
2548 },
2549 },
2550 };
2551
2552 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2553
2554 if (open(my $fh, ">> $config_file")) {
2555 print $fh <<EOC;
2556 <Class $class_name>
2557 From 1.2.3.4
2558 From 5.6.7.
2559 From 8.9.10.0/16
2560 From remotehost
2561 From foo*.com
2562 From \!evil.com
2563 From 127.0.0.1
2564 Satisfy any
2565 </Class>
2566 EOC
2567 unless (close($fh)) {
2568 die("Can't write $config_file: $!");
2569 }
2570
2571 } else {
2572 die("Can't open $config_file: $!");
2573 }
2574
2575 # Open pipes, for use between the parent and child processes. Specifically,
2576 # the child will indicate when it's done with its test by writing a message
2577 # to the parent.
2578 my ($rfh, $wfh);
2579 unless (pipe($rfh, $wfh)) {
2580 die("Can't open pipe: $!");
2581 }
2582
2583 my $ex;
2584
2585 # Fork child
2586 $self->handle_sigchld();
2587 defined(my $pid = fork()) or die("Can't fork: $!");
2588 if ($pid) {
2589 eval {
2590 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
2591 $client->login($user, $passwd);
2592 $client->quit();
2593 };
2594
2595 if ($@) {
2596 $ex = $@;
2597 }
2598
2599 $wfh->print("done\n");
2600 $wfh->flush();
2601
2602 } else {
2603 eval { server_wait($config_file, $rfh) };
2604 if ($@) {
2605 warn($@);
2606 exit 1;
2607 }
2608
2609 exit 0;
2610 }
2611
2612 # Stop server
2613 server_stop($pid_file);
2614
2615 $self->assert_child_ok($pid);
2616
2617 if ($ex) {
2618 die($ex);
2619 }
2620
2621 unlink($log_file);
2622 }
2623
2624 sub class_satisfy_all {
2625 my $self = shift;
2626 my $tmpdir = $self->{tmpdir};
2627 my $setup = test_setup($tmpdir, 'config');
2628
2629 my $class_name = 'test-class';
2630
2631 my $config = {
2632 PidFile => $setup->{pid_file},
2633 ScoreboardFile => $setup->{scoreboard_file},
2634 SystemLog => $setup->{log_file},
2635 TraceLog => $setup->{log_file},
2636 Trace => 'class:10 netaddr:10 netacl:10',
2637
2638 AuthUserFile => $setup->{auth_user_file},
2639 AuthGroupFile => $setup->{auth_group_file},
2640 AuthOrder => 'mod_auth_file.c',
2641
2642 UseReverseDNS => 'on',
2643
2644 Limit => {
2645 LOGIN => {
2646 Order => 'allow,deny',
2647 AllowClass => $class_name,
2648 DenyAll => '',
2649 },
2650 },
2651
2652 IfModules => {
2653 'mod_delay.c' => {
2654 DelayEngine => 'off',
2655 },
2656 },
2657 };
2658
2659 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2660 $config);
2661
2662 if (open(my $fh, ">> $setup->{config_file}")) {
2663 print $fh <<EOC;
2664 <Class $class_name>
2665 From 127.0.0.1
2666 From localhost
2667 From \!evil.com
2668 From 127.0.0.0/8
2669 From 127.0.0.
2670 Satisfy all
2671 </Class>
2672 EOC
2673 unless (close($fh)) {
2674 die("Can't write $setup->{config_file}: $!");
2675 }
2676
2677 } else {
2678 die("Can't open $setup->{config_file}: $!");
2679 }
2680
2681 # Open pipes, for use between the parent and child processes. Specifically,
2682 # the child will indicate when it's done with its test by writing a message
2683 # to the parent.
2684 my ($rfh, $wfh);
2685 unless (pipe($rfh, $wfh)) {
2686 die("Can't open pipe: $!");
2687 }
2688
2689 my $ex;
2690
2691 # Fork child
2692 $self->handle_sigchld();
2693 defined(my $pid = fork()) or die("Can't fork: $!");
2694 if ($pid) {
2695 eval {
2696 # Allow for server startup
2697 sleep(1);
2698
2699 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
2700 $client->login($setup->{user}, $setup->{passwd});
2701 $client->quit();
2702 };
2703 if ($@) {
2704 $ex = $@;
2705 }
2706
2707 $wfh->print("done\n");
2708 $wfh->flush();
2709
2710 } else {
2711 eval { server_wait($setup->{config_file}, $rfh) };
2712 if ($@) {
2713 warn($@);
2714 exit 1;
2715 }
2716
2717 exit 0;
2718 }
2719
2720 # Stop server
2721 server_stop($setup->{pid_file});
2722 $self->assert_child_ok($pid);
2723
2724 test_cleanup($setup->{log_file}, $ex);
2725 }
2726
2727 sub class_from_global_issue1597 {
2728 my $self = shift;
2729 my $tmpdir = $self->{tmpdir};
2730 my $setup = test_setup($tmpdir, 'config');
2731
2732 my $class_name = 'test-class';
2733
2734 my $config = {
2735 PidFile => $setup->{pid_file},
2736 ScoreboardFile => $setup->{scoreboard_file},
2737 SystemLog => $setup->{log_file},
2738 TraceLog => $setup->{log_file},
2739 Trace => 'class:10 netaddr:10 netacl:10',
2740
2741 AuthUserFile => $setup->{auth_user_file},
2742 AuthGroupFile => $setup->{auth_group_file},
2743 AuthOrder => 'mod_auth_file.c',
2744
2745 UseReverseDNS => 'on',
2746
2747 Limit => {
2748 LOGIN => {
2749 Order => 'allow,deny',
2750 AllowClass => $class_name,
2751 DenyAll => '',
2752 },
2753 },
2754
2755 IfModules => {
2756 'mod_delay.c' => {
2757 DelayEngine => 'off',
2758 },
2759 },
2760 };
2761
2762 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2763 $config);
2764
2765 if (open(my $fh, ">> $setup->{config_file}")) {
2766 print $fh <<EOC;
2767 <Global>
2768 <Class $class_name>
2769 From 127.0.0.1
2770 From localhost
2771 From \!evil.com
2772 From 127.0.0.0/8
2773 From 127.0.0.
2774 Satisfy all
2775 </Class>
2776 </Global>
2777 EOC
2778 unless (close($fh)) {
2779 die("Can't write $setup->{config_file}: $!");
2780 }
2781
2782 } else {
2783 die("Can't open $setup->{config_file}: $!");
2784 }
2785
2786 # Open pipes, for use between the parent and child processes. Specifically,
2787 # the child will indicate when it's done with its test by writing a message
2788 # to the parent.
2789 my ($rfh, $wfh);
2790 unless (pipe($rfh, $wfh)) {
2791 die("Can't open pipe: $!");
2792 }
2793
2794 my $ex;
2795
2796 # Fork child
2797 $self->handle_sigchld();
2798 defined(my $pid = fork()) or die("Can't fork: $!");
2799 if ($pid) {
2800 eval {
2801 # Allow for server startup
2802 sleep(1);
2803
2804 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
2805 $client->login($setup->{user}, $setup->{passwd});
2806 $client->quit();
2807 };
2808 if ($@) {
2809 $ex = $@;
2810 }
2811
2812 $wfh->print("done\n");
2813 $wfh->flush();
2814
2815 } else {
2816 eval { server_wait($setup->{config_file}, $rfh) };
2817 if ($@) {
2818 warn($@);
2819 exit 1;
2820 }
2821
2822 exit 0;
2823 }
2824
2825 # Stop server
2826 server_stop($setup->{pid_file});
2827 $self->assert_child_ok($pid);
2828
2829 test_cleanup($setup->{log_file}, $ex);
2830 }
2831
2832 1;