Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Modules::mod_auth_file;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Cwd;
8 use File::Path qw(mkpath);
9 use File::Spec;
10 use IO::Handle;
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 auth_user_file_id_range_ok => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 auth_user_file_id_range_failed => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 auth_user_file_home_filter_ok => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 auth_user_file_home_filter_failed => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 auth_user_file_name_filter_ok => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 auth_user_file_name_filter_failed => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 auth_group_file_id_range_ok => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 auth_group_file_id_range_failed => {
56 order => ++$order,
57 test_class => [qw(forking)],
58 },
59
60 auth_group_file_name_filter_ok => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 auth_group_file_name_filter_failed => {
66 order => ++$order,
67 test_class => [qw(forking)],
68 },
69
70 auth_user_file_at_symbol_ok => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 auth_user_file_world_readable_bug3892 => {
76 order => ++$order,
77 test_class => [qw(bug forking)],
78 },
79
80 auth_user_file_world_writable_bug3892 => {
81 order => ++$order,
82 test_class => [qw(bug forking)],
83 },
84
85 auth_user_file_world_readable_insecure_perms_opt => {
86 order => ++$order,
87 test_class => [qw(bug forking)],
88 },
89
90 auth_group_file_world_readable_bug3892 => {
91 order => ++$order,
92 test_class => [qw(bug forking)],
93 },
94
95 auth_group_file_world_writable_bug3892 => {
96 order => ++$order,
97 test_class => [qw(bug forking)],
98 },
99
100 auth_user_file_world_writable_parent_dir_bug3892 => {
101 order => ++$order,
102 test_class => [qw(bug forking)],
103 },
104
105 auth_user_file_symlink_world_writable_parent_dir_bug3892 => {
106 order => ++$order,
107 test_class => [qw(bug forking)],
108 },
109
110 auth_user_file_bad_syntax_bug3985 => {
111 order => ++$order,
112 test_class => [qw(bug forking)],
113 },
114
115 auth_group_file_bad_syntax_bug3985 => {
116 order => ++$order,
117 test_class => [qw(bug forking)],
118 },
119
120 auth_user_file_bad_syntax_check_issue490 => {
121 order => ++$order,
122 test_class => [qw(bug forking)],
123 },
124
125 auth_group_file_bad_syntax_check_issue490 => {
126 order => ++$order,
127 test_class => [qw(bug forking)],
128 },
129
130 auth_file_symlink_segfault_bug4145 => {
131 order => ++$order,
132 test_class => [qw(bug forking)],
133 },
134
135 auth_file_line_too_long_issue1321 => {
136 order => ++$order,
137 test_class => [qw(bug forking)],
138 },
139 };
140
141 sub new {
142 return shift()->SUPER::new(@_);
143 }
144
145 sub list_tests {
146 return testsuite_get_runnable_tests($TESTS);
147 }
148
149 sub auth_user_file_id_range_ok {
150 my $self = shift;
151 my $tmpdir = $self->{tmpdir};
152
153 my $config_file = "$tmpdir/authfile.conf";
154 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
155 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
156
157 my $log_file = test_get_logfile();
158
159 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
160 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
161
162 my $user = 'proftpd';
163 my $passwd = 'test';
164 my $group = 'ftpd';
165 my $home_dir = File::Spec->rel2abs($tmpdir);
166 my $uid = 500;
167 my $gid = 500;
168
169 # Make sure that, if we're running as root, that the home directory has
170 # permissions/privs set for the account we create
171 if ($< == 0) {
172 unless (chmod(0755, $home_dir)) {
173 die("Can't set perms on $home_dir to 0755: $!");
174 }
175
176 unless (chown($uid, $gid, $home_dir)) {
177 die("Can't set owner of $home_dir to $uid/$gid: $!");
178 }
179 }
180
181 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
182 '/bin/bash');
183 auth_group_write($auth_group_file, $group, $gid, $user);
184
185 my $config = {
186 PidFile => $pid_file,
187 ScoreboardFile => $scoreboard_file,
188 SystemLog => $log_file,
189
190 AuthUserFile => "$auth_user_file id 100-500",
191 AuthGroupFile => $auth_group_file,
192 AuthOrder => 'mod_auth_file.c',
193
194 IfModules => {
195 'mod_delay.c' => {
196 DelayEngine => 'off',
197 },
198 },
199 };
200
201 my ($port, $config_user, $config_group) = config_write($config_file, $config);
202
203 # Open pipes, for use between the parent and child processes. Specifically,
204 # the child will indicate when it's done with its test by writing a message
205 # to the parent.
206 my ($rfh, $wfh);
207 unless (pipe($rfh, $wfh)) {
208 die("Can't open pipe: $!");
209 }
210
211 my $ex;
212
213 # Fork child
214 $self->handle_sigchld();
215 defined(my $pid = fork()) or die("Can't fork: $!");
216 if ($pid) {
217 eval {
218 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
219 $client->login($user, $passwd);
220 $client->quit();
221 };
222
223 if ($@) {
224 $ex = $@;
225 }
226
227 $wfh->print("done\n");
228 $wfh->flush();
229
230 } else {
231 eval { server_wait($config_file, $rfh) };
232 if ($@) {
233 warn($@);
234 exit 1;
235 }
236
237 exit 0;
238 }
239
240 # Stop server
241 server_stop($pid_file);
242
243 $self->assert_child_ok($pid);
244
245 if ($ex) {
246 test_append_logfile($log_file, $ex);
247 unlink($log_file);
248
249 die($ex);
250 }
251
252 unlink($log_file);
253 }
254
255 sub auth_user_file_id_range_failed {
256 my $self = shift;
257 my $tmpdir = $self->{tmpdir};
258
259 my $config_file = "$tmpdir/authfile.conf";
260 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
261 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
262
263 my $log_file = test_get_logfile();
264
265 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
266 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
267
268 my $user = 'proftpd';
269 my $passwd = 'test';
270 my $group = 'ftpd';
271 my $home_dir = File::Spec->rel2abs($tmpdir);
272 my $uid = 1000;
273 my $gid = 1000;
274
275 # Make sure that, if we're running as root, that the home directory has
276 # permissions/privs set for the account we create
277 if ($< == 0) {
278 unless (chmod(0755, $home_dir)) {
279 die("Can't set perms on $home_dir to 0755: $!");
280 }
281
282 unless (chown($uid, $gid, $home_dir)) {
283 die("Can't set owner of $home_dir to $uid/$gid: $!");
284 }
285 }
286
287 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
288 '/bin/bash');
289 auth_group_write($auth_group_file, $group, $gid, $user);
290
291 my $config = {
292 PidFile => $pid_file,
293 ScoreboardFile => $scoreboard_file,
294 SystemLog => $log_file,
295
296 AuthUserFile => "$auth_user_file id 100-500",
297 AuthGroupFile => $auth_group_file,
298 AuthOrder => 'mod_auth_file.c',
299
300 IfModules => {
301 'mod_delay.c' => {
302 DelayEngine => 'off',
303 },
304 },
305 };
306
307 my ($port, $config_user, $config_group) = config_write($config_file, $config);
308
309 # Open pipes, for use between the parent and child processes. Specifically,
310 # the child will indicate when it's done with its test by writing a message
311 # to the parent.
312 my ($rfh, $wfh);
313 unless (pipe($rfh, $wfh)) {
314 die("Can't open pipe: $!");
315 }
316
317 my $ex;
318
319 # Fork child
320 $self->handle_sigchld();
321 defined(my $pid = fork()) or die("Can't fork: $!");
322 if ($pid) {
323 eval {
324 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
325 eval { $client->login($user, $passwd) };
326 unless ($@) {
327 die("Login succeeded unexpectedly");
328 }
329
330 $client->quit();
331 };
332
333 if ($@) {
334 $ex = $@;
335 }
336
337 $wfh->print("done\n");
338 $wfh->flush();
339
340 } else {
341 eval { server_wait($config_file, $rfh) };
342 if ($@) {
343 warn($@);
344 exit 1;
345 }
346
347 exit 0;
348 }
349
350 # Stop server
351 server_stop($pid_file);
352
353 $self->assert_child_ok($pid);
354
355 if ($ex) {
356 test_append_logfile($log_file, $ex);
357 unlink($log_file);
358
359 die($ex);
360 }
361
362 unlink($log_file);
363 }
364
365 sub auth_user_file_home_filter_ok {
366 my $self = shift;
367 my $tmpdir = $self->{tmpdir};
368
369 my $config_file = "$tmpdir/authfile.conf";
370 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
371 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
372
373 my $log_file = test_get_logfile();
374
375 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
376 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
377
378 my $user = 'proftpd';
379 my $passwd = 'test';
380 my $group = 'ftpd';
381 my $home_dir = File::Spec->rel2abs("$tmpdir/$user");
382 mkpath($home_dir);
383 my $uid = 500;
384 my $gid = 500;
385
386 # Make sure that, if we're running as root, that the home directory has
387 # permissions/privs set for the account we create
388 if ($< == 0) {
389 unless (chmod(0755, $home_dir)) {
390 die("Can't set perms on $home_dir to 0755: $!");
391 }
392
393 unless (chown($uid, $gid, $home_dir)) {
394 die("Can't set owner of $home_dir to $uid/$gid: $!");
395 }
396 }
397
398 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
399 '/bin/bash');
400 auth_group_write($auth_group_file, $group, $gid, $user);
401
402 my $config = {
403 PidFile => $pid_file,
404 ScoreboardFile => $scoreboard_file,
405 SystemLog => $log_file,
406
407 AuthUserFile => "$auth_user_file home $user\$",
408 AuthGroupFile => $auth_group_file,
409 AuthOrder => 'mod_auth_file.c',
410
411 IfModules => {
412 'mod_delay.c' => {
413 DelayEngine => 'off',
414 },
415 },
416 };
417
418 my ($port, $config_user, $config_group) = config_write($config_file, $config);
419
420 # Open pipes, for use between the parent and child processes. Specifically,
421 # the child will indicate when it's done with its test by writing a message
422 # to the parent.
423 my ($rfh, $wfh);
424 unless (pipe($rfh, $wfh)) {
425 die("Can't open pipe: $!");
426 }
427
428 my $ex;
429
430 # Fork child
431 $self->handle_sigchld();
432 defined(my $pid = fork()) or die("Can't fork: $!");
433 if ($pid) {
434 eval {
435 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
436 $client->login($user, $passwd);
437 $client->quit();
438 };
439
440 if ($@) {
441 $ex = $@;
442 }
443
444 $wfh->print("done\n");
445 $wfh->flush();
446
447 } else {
448 eval { server_wait($config_file, $rfh) };
449 if ($@) {
450 warn($@);
451 exit 1;
452 }
453
454 exit 0;
455 }
456
457 # Stop server
458 server_stop($pid_file);
459
460 $self->assert_child_ok($pid);
461
462 if ($ex) {
463 test_append_logfile($log_file, $ex);
464 unlink($log_file);
465
466 die($ex);
467 }
468
469 unlink($log_file);
470 }
471
472 sub auth_user_file_home_filter_failed {
473 my $self = shift;
474 my $tmpdir = $self->{tmpdir};
475
476 my $config_file = "$tmpdir/authfile.conf";
477 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
478 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
479
480 my $log_file = test_get_logfile();
481
482 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
483 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
484
485 my $user = 'proftpd';
486 my $passwd = 'test';
487 my $group = 'ftpd';
488 my $home_dir = File::Spec->rel2abs($tmpdir);
489 my $uid = 500;
490 my $gid = 500;
491
492 # Make sure that, if we're running as root, that the home directory has
493 # permissions/privs set for the account we create
494 if ($< == 0) {
495 unless (chmod(0755, $home_dir)) {
496 die("Can't set perms on $home_dir to 0755: $!");
497 }
498
499 unless (chown($uid, $gid, $home_dir)) {
500 die("Can't set owner of $home_dir to $uid/$gid: $!");
501 }
502 }
503
504 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
505 '/bin/bash');
506 auth_group_write($auth_group_file, $group, $gid, $user);
507
508 my $config = {
509 PidFile => $pid_file,
510 ScoreboardFile => $scoreboard_file,
511 SystemLog => $log_file,
512
513 AuthUserFile => "$auth_user_file home ^3133tH\@x0R\$",
514 AuthGroupFile => $auth_group_file,
515 AuthOrder => 'mod_auth_file.c',
516
517 IfModules => {
518 'mod_delay.c' => {
519 DelayEngine => 'off',
520 },
521 },
522 };
523
524 my ($port, $config_user, $config_group) = config_write($config_file, $config);
525
526 # Open pipes, for use between the parent and child processes. Specifically,
527 # the child will indicate when it's done with its test by writing a message
528 # to the parent.
529 my ($rfh, $wfh);
530 unless (pipe($rfh, $wfh)) {
531 die("Can't open pipe: $!");
532 }
533
534 my $ex;
535
536 # Fork child
537 $self->handle_sigchld();
538 defined(my $pid = fork()) or die("Can't fork: $!");
539 if ($pid) {
540 eval {
541 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
542 eval { $client->login($user, $passwd) };
543 unless ($@) {
544 die("Login succeeded unexpectedly");
545 }
546
547 $client->quit();
548 };
549
550 if ($@) {
551 $ex = $@;
552 }
553
554 $wfh->print("done\n");
555 $wfh->flush();
556
557 } else {
558 eval { server_wait($config_file, $rfh) };
559 if ($@) {
560 warn($@);
561 exit 1;
562 }
563
564 exit 0;
565 }
566
567 # Stop server
568 server_stop($pid_file);
569
570 $self->assert_child_ok($pid);
571
572 if ($ex) {
573 test_append_logfile($log_file, $ex);
574 unlink($log_file);
575
576 die($ex);
577 }
578
579 unlink($log_file);
580 }
581
582 sub auth_user_file_name_filter_ok {
583 my $self = shift;
584 my $tmpdir = $self->{tmpdir};
585
586 my $config_file = "$tmpdir/authfile.conf";
587 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
588 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
589
590 my $log_file = test_get_logfile();
591
592 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
593 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
594
595 my $user = 'proftpd';
596 my $passwd = 'test';
597 my $group = 'ftpd';
598 my $home_dir = File::Spec->rel2abs($tmpdir);
599 my $uid = 500;
600 my $gid = 500;
601
602 # Make sure that, if we're running as root, that the home directory has
603 # permissions/privs set for the account we create
604 if ($< == 0) {
605 unless (chmod(0755, $home_dir)) {
606 die("Can't set perms on $home_dir to 0755: $!");
607 }
608
609 unless (chown($uid, $gid, $home_dir)) {
610 die("Can't set owner of $home_dir to $uid/$gid: $!");
611 }
612 }
613
614 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
615 '/bin/bash');
616 auth_group_write($auth_group_file, $group, $gid, $user);
617
618 my $config = {
619 PidFile => $pid_file,
620 ScoreboardFile => $scoreboard_file,
621 SystemLog => $log_file,
622
623 AuthUserFile => "$auth_user_file name ^$user\$",
624 AuthGroupFile => $auth_group_file,
625 AuthOrder => 'mod_auth_file.c',
626
627 IfModules => {
628 'mod_delay.c' => {
629 DelayEngine => 'off',
630 },
631 },
632 };
633
634 my ($port, $config_user, $config_group) = config_write($config_file, $config);
635
636 # Open pipes, for use between the parent and child processes. Specifically,
637 # the child will indicate when it's done with its test by writing a message
638 # to the parent.
639 my ($rfh, $wfh);
640 unless (pipe($rfh, $wfh)) {
641 die("Can't open pipe: $!");
642 }
643
644 my $ex;
645
646 # Fork child
647 $self->handle_sigchld();
648 defined(my $pid = fork()) or die("Can't fork: $!");
649 if ($pid) {
650 eval {
651 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
652 $client->login($user, $passwd);
653 $client->quit();
654 };
655
656 if ($@) {
657 $ex = $@;
658 }
659
660 $wfh->print("done\n");
661 $wfh->flush();
662
663 } else {
664 eval { server_wait($config_file, $rfh) };
665 if ($@) {
666 warn($@);
667 exit 1;
668 }
669
670 exit 0;
671 }
672
673 # Stop server
674 server_stop($pid_file);
675
676 $self->assert_child_ok($pid);
677
678 if ($ex) {
679 test_append_logfile($log_file, $ex);
680 unlink($log_file);
681
682 die($ex);
683 }
684
685 unlink($log_file);
686 }
687
688 sub auth_user_file_name_filter_failed {
689 my $self = shift;
690 my $tmpdir = $self->{tmpdir};
691
692 my $config_file = "$tmpdir/authfile.conf";
693 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
694 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
695
696 my $log_file = test_get_logfile();
697
698 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
699 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
700
701 my $user = 'proftpd';
702 my $passwd = 'test';
703 my $group = 'ftpd';
704 my $home_dir = File::Spec->rel2abs($tmpdir);
705 my $uid = 500;
706 my $gid = 500;
707
708 # Make sure that, if we're running as root, that the home directory has
709 # permissions/privs set for the account we create
710 if ($< == 0) {
711 unless (chmod(0755, $home_dir)) {
712 die("Can't set perms on $home_dir to 0755: $!");
713 }
714
715 unless (chown($uid, $gid, $home_dir)) {
716 die("Can't set owner of $home_dir to $uid/$gid: $!");
717 }
718 }
719
720 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
721 '/bin/bash');
722 auth_group_write($auth_group_file, $group, $gid, $user);
723
724 my $config = {
725 PidFile => $pid_file,
726 ScoreboardFile => $scoreboard_file,
727 SystemLog => $log_file,
728
729 AuthUserFile => "$auth_user_file name ^3133tH\@x0R\$",
730 AuthGroupFile => $auth_group_file,
731 AuthOrder => 'mod_auth_file.c',
732
733 IfModules => {
734 'mod_delay.c' => {
735 DelayEngine => 'off',
736 },
737 },
738 };
739
740 my ($port, $config_user, $config_group) = config_write($config_file, $config);
741
742 # Open pipes, for use between the parent and child processes. Specifically,
743 # the child will indicate when it's done with its test by writing a message
744 # to the parent.
745 my ($rfh, $wfh);
746 unless (pipe($rfh, $wfh)) {
747 die("Can't open pipe: $!");
748 }
749
750 my $ex;
751
752 # Fork child
753 $self->handle_sigchld();
754 defined(my $pid = fork()) or die("Can't fork: $!");
755 if ($pid) {
756 eval {
757 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
758 eval { $client->login($user, $passwd) };
759 unless ($@) {
760 die("Login succeeded unexpectedly");
761 }
762
763 $client->quit();
764 };
765
766 if ($@) {
767 $ex = $@;
768 }
769
770 $wfh->print("done\n");
771 $wfh->flush();
772
773 } else {
774 eval { server_wait($config_file, $rfh) };
775 if ($@) {
776 warn($@);
777 exit 1;
778 }
779
780 exit 0;
781 }
782
783 # Stop server
784 server_stop($pid_file);
785
786 $self->assert_child_ok($pid);
787
788 if ($ex) {
789 test_append_logfile($log_file, $ex);
790 unlink($log_file);
791
792 die($ex);
793 }
794
795 unlink($log_file);
796 }
797
798 sub auth_group_file_id_range_ok {
799 my $self = shift;
800 my $tmpdir = $self->{tmpdir};
801
802 my $config_file = "$tmpdir/authfile.conf";
803 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
804 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
805
806 my $log_file = test_get_logfile();
807
808 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
809 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
810
811 my $user = 'proftpd';
812 my $passwd = 'test';
813 my $group = 'ftpd';
814 my $home_dir = File::Spec->rel2abs($tmpdir);
815 my $uid = 500;
816 my $gid = 500;
817
818 # Make sure that, if we're running as root, that the home directory has
819 # permissions/privs set for the account we create
820 if ($< == 0) {
821 unless (chmod(0755, $home_dir)) {
822 die("Can't set perms on $home_dir to 0755: $!");
823 }
824
825 unless (chown($uid, $gid, $home_dir)) {
826 die("Can't set owner of $home_dir to $uid/$gid: $!");
827 }
828 }
829
830 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
831 '/bin/bash');
832 auth_group_write($auth_group_file, $group, $gid, $user);
833
834 my $config = {
835 PidFile => $pid_file,
836 ScoreboardFile => $scoreboard_file,
837 SystemLog => $log_file,
838
839 AuthUserFile => $auth_user_file,
840 AuthGroupFile => "$auth_group_file id 100-500",
841 AuthOrder => 'mod_auth_file.c',
842
843 IfModules => {
844 'mod_delay.c' => {
845 DelayEngine => 'off',
846 },
847 },
848 };
849
850 my ($port, $config_user, $config_group) = config_write($config_file, $config);
851
852 if (open(my $fh, ">> $config_file")) {
853 print $fh <<EOC;
854 <Limit LOGIN>
855 AllowGroup $group
856 DenyAll
857 </Limit>
858 EOC
859
860 unless (close($fh)) {
861 die("Can't write $config_file: $!");
862 }
863
864 } else {
865 die("Can't open $config_file: $!");
866 }
867
868 # Open pipes, for use between the parent and child processes. Specifically,
869 # the child will indicate when it's done with its test by writing a message
870 # to the parent.
871 my ($rfh, $wfh);
872 unless (pipe($rfh, $wfh)) {
873 die("Can't open pipe: $!");
874 }
875
876 my $ex;
877
878 # Fork child
879 $self->handle_sigchld();
880 defined(my $pid = fork()) or die("Can't fork: $!");
881 if ($pid) {
882 eval {
883 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
884 $client->login($user, $passwd);
885 $client->quit();
886 };
887
888 if ($@) {
889 $ex = $@;
890 }
891
892 $wfh->print("done\n");
893 $wfh->flush();
894
895 } else {
896 eval { server_wait($config_file, $rfh) };
897 if ($@) {
898 warn($@);
899 exit 1;
900 }
901
902 exit 0;
903 }
904
905 # Stop server
906 server_stop($pid_file);
907
908 $self->assert_child_ok($pid);
909
910 if ($ex) {
911 test_append_logfile($log_file, $ex);
912 unlink($log_file);
913
914 die($ex);
915 }
916
917 unlink($log_file);
918 }
919
920 sub auth_group_file_id_range_failed {
921 my $self = shift;
922 my $tmpdir = $self->{tmpdir};
923
924 my $config_file = "$tmpdir/authfile.conf";
925 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
926 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
927
928 my $log_file = test_get_logfile();
929
930 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
931 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
932
933 my $user = 'proftpd';
934 my $passwd = 'test';
935 my $group = 'ftpd';
936 my $home_dir = File::Spec->rel2abs($tmpdir);
937 my $uid = 1000;
938 my $gid = 1000;
939
940 # Make sure that, if we're running as root, that the home directory has
941 # permissions/privs set for the account we create
942 if ($< == 0) {
943 unless (chmod(0755, $home_dir)) {
944 die("Can't set perms on $home_dir to 0755: $!");
945 }
946
947 unless (chown($uid, $gid, $home_dir)) {
948 die("Can't set owner of $home_dir to $uid/$gid: $!");
949 }
950 }
951
952 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
953 '/bin/bash');
954 auth_group_write($auth_group_file, $group, $gid, $user);
955
956 my $config = {
957 PidFile => $pid_file,
958 ScoreboardFile => $scoreboard_file,
959 SystemLog => $log_file,
960
961 AuthUserFile => $auth_user_file,
962 AuthGroupFile => "$auth_group_file id 100-500",
963 AuthOrder => 'mod_auth_file.c',
964
965 IfModules => {
966 'mod_delay.c' => {
967 DelayEngine => 'off',
968 },
969 },
970 };
971
972 my ($port, $config_user, $config_group) = config_write($config_file, $config);
973
974 if (open(my $fh, ">> $config_file")) {
975 print $fh <<EOC;
976 <Limit LOGIN>
977 AllowGroup $group
978 DenyAll
979 </Limit>
980 EOC
981
982 unless (close($fh)) {
983 die("Can't write $config_file: $!");
984 }
985
986 } else {
987 die("Can't open $config_file: $!");
988 }
989
990 # Open pipes, for use between the parent and child processes. Specifically,
991 # the child will indicate when it's done with its test by writing a message
992 # to the parent.
993 my ($rfh, $wfh);
994 unless (pipe($rfh, $wfh)) {
995 die("Can't open pipe: $!");
996 }
997
998 my $ex;
999
1000 # Fork child
1001 $self->handle_sigchld();
1002 defined(my $pid = fork()) or die("Can't fork: $!");
1003 if ($pid) {
1004 eval {
1005 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1006 eval { $client->login($user, $passwd) };
1007 unless ($@) {
1008 die("Login succeeded unexpectedly");
1009 }
1010
1011 $client->quit();
1012 };
1013
1014 if ($@) {
1015 $ex = $@;
1016 }
1017
1018 $wfh->print("done\n");
1019 $wfh->flush();
1020
1021 } else {
1022 eval { server_wait($config_file, $rfh) };
1023 if ($@) {
1024 warn($@);
1025 exit 1;
1026 }
1027
1028 exit 0;
1029 }
1030
1031 # Stop server
1032 server_stop($pid_file);
1033
1034 $self->assert_child_ok($pid);
1035
1036 if ($ex) {
1037 test_append_logfile($log_file, $ex);
1038 unlink($log_file);
1039
1040 die($ex);
1041 }
1042
1043 unlink($log_file);
1044 }
1045
1046 sub auth_group_file_name_filter_ok {
1047 my $self = shift;
1048 my $tmpdir = $self->{tmpdir};
1049
1050 my $config_file = "$tmpdir/authfile.conf";
1051 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1052 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1053
1054 my $log_file = test_get_logfile();
1055
1056 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1057 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1058
1059 my $user = 'proftpd';
1060 my $passwd = 'test';
1061 my $group = 'ftpd';
1062 my $home_dir = File::Spec->rel2abs($tmpdir);
1063 my $uid = 500;
1064 my $gid = 500;
1065
1066 # Make sure that, if we're running as root, that the home directory has
1067 # permissions/privs set for the account we create
1068 if ($< == 0) {
1069 unless (chmod(0755, $home_dir)) {
1070 die("Can't set perms on $home_dir to 0755: $!");
1071 }
1072
1073 unless (chown($uid, $gid, $home_dir)) {
1074 die("Can't set owner of $home_dir to $uid/$gid: $!");
1075 }
1076 }
1077
1078 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1079 '/bin/bash');
1080 auth_group_write($auth_group_file, $group, $gid, $user);
1081
1082 my $config = {
1083 PidFile => $pid_file,
1084 ScoreboardFile => $scoreboard_file,
1085 SystemLog => $log_file,
1086
1087 AuthUserFile => $auth_user_file,
1088 AuthGroupFile => "$auth_group_file name ^$group\$",
1089 AuthOrder => 'mod_auth_file.c',
1090
1091 IfModules => {
1092 'mod_delay.c' => {
1093 DelayEngine => 'off',
1094 },
1095 },
1096 };
1097
1098 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1099
1100 if (open(my $fh, ">> $config_file")) {
1101 print $fh <<EOC;
1102 <Limit LOGIN>
1103 AllowGroup $group
1104 DenyAll
1105 </Limit>
1106 EOC
1107
1108 unless (close($fh)) {
1109 die("Can't write $config_file: $!");
1110 }
1111
1112 } else {
1113 die("Can't open $config_file: $!");
1114 }
1115
1116 # Open pipes, for use between the parent and child processes. Specifically,
1117 # the child will indicate when it's done with its test by writing a message
1118 # to the parent.
1119 my ($rfh, $wfh);
1120 unless (pipe($rfh, $wfh)) {
1121 die("Can't open pipe: $!");
1122 }
1123
1124 my $ex;
1125
1126 # Fork child
1127 $self->handle_sigchld();
1128 defined(my $pid = fork()) or die("Can't fork: $!");
1129 if ($pid) {
1130 eval {
1131 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1132 $client->login($user, $passwd);
1133 $client->quit();
1134 };
1135
1136 if ($@) {
1137 $ex = $@;
1138 }
1139
1140 $wfh->print("done\n");
1141 $wfh->flush();
1142
1143 } else {
1144 eval { server_wait($config_file, $rfh) };
1145 if ($@) {
1146 warn($@);
1147 exit 1;
1148 }
1149
1150 exit 0;
1151 }
1152
1153 # Stop server
1154 server_stop($pid_file);
1155
1156 $self->assert_child_ok($pid);
1157
1158 if ($ex) {
1159 test_append_logfile($log_file, $ex);
1160 unlink($log_file);
1161
1162 die($ex);
1163 }
1164
1165 unlink($log_file);
1166 }
1167
1168 sub auth_group_file_name_filter_failed {
1169 my $self = shift;
1170 my $tmpdir = $self->{tmpdir};
1171
1172 my $config_file = "$tmpdir/authfile.conf";
1173 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1174 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1175
1176 my $log_file = test_get_logfile();
1177
1178 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1179 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1180
1181 my $user = 'proftpd';
1182 my $passwd = 'test';
1183 my $group = 'ftpd';
1184 my $home_dir = File::Spec->rel2abs($tmpdir);
1185 my $uid = 500;
1186 my $gid = 500;
1187
1188 # Make sure that, if we're running as root, that the home directory has
1189 # permissions/privs set for the account we create
1190 if ($< == 0) {
1191 unless (chmod(0755, $home_dir)) {
1192 die("Can't set perms on $home_dir to 0755: $!");
1193 }
1194
1195 unless (chown($uid, $gid, $home_dir)) {
1196 die("Can't set owner of $home_dir to $uid/$gid: $!");
1197 }
1198 }
1199
1200 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1201 '/bin/bash');
1202 auth_group_write($auth_group_file, $group, $gid, $user);
1203
1204 my $config = {
1205 PidFile => $pid_file,
1206 ScoreboardFile => $scoreboard_file,
1207 SystemLog => $log_file,
1208
1209 AuthUserFile => $auth_user_file,
1210 AuthGroupFile => "$auth_group_file name ^3133tH\@x0R\$",
1211 AuthOrder => 'mod_auth_file.c',
1212
1213 IfModules => {
1214 'mod_delay.c' => {
1215 DelayEngine => 'off',
1216 },
1217 },
1218 };
1219
1220 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1221
1222 if (open(my $fh, ">> $config_file")) {
1223 print $fh <<EOC;
1224 <Limit LOGIN>
1225 AllowGroup $group
1226 DenyAll
1227 </Limit>
1228 EOC
1229
1230 unless (close($fh)) {
1231 die("Can't write $config_file: $!");
1232 }
1233
1234 } else {
1235 die("Can't open $config_file: $!");
1236 }
1237
1238 # Open pipes, for use between the parent and child processes. Specifically,
1239 # the child will indicate when it's done with its test by writing a message
1240 # to the parent.
1241 my ($rfh, $wfh);
1242 unless (pipe($rfh, $wfh)) {
1243 die("Can't open pipe: $!");
1244 }
1245
1246 my $ex;
1247
1248 # Fork child
1249 $self->handle_sigchld();
1250 defined(my $pid = fork()) or die("Can't fork: $!");
1251 if ($pid) {
1252 eval {
1253 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1254 eval { $client->login($user, $passwd) };
1255 unless ($@) {
1256 die("Login succeeded unexpectedly");
1257 }
1258
1259 $client->quit();
1260 };
1261
1262 if ($@) {
1263 $ex = $@;
1264 }
1265
1266 $wfh->print("done\n");
1267 $wfh->flush();
1268
1269 } else {
1270 eval { server_wait($config_file, $rfh) };
1271 if ($@) {
1272 warn($@);
1273 exit 1;
1274 }
1275
1276 exit 0;
1277 }
1278
1279 # Stop server
1280 server_stop($pid_file);
1281
1282 $self->assert_child_ok($pid);
1283
1284 if ($ex) {
1285 test_append_logfile($log_file, $ex);
1286 unlink($log_file);
1287
1288 die($ex);
1289 }
1290
1291 unlink($log_file);
1292 }
1293
1294 sub auth_user_file_at_symbol_ok {
1295 my $self = shift;
1296 my $tmpdir = $self->{tmpdir};
1297
1298 my $config_file = "$tmpdir/authfile.conf";
1299 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1300 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1301
1302 my $log_file = test_get_logfile();
1303
1304 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1305 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1306
1307 my $user = '[email protected]';
1308 my $passwd = 'test';
1309 my $group = 'ftpd';
1310 my $home_dir = File::Spec->rel2abs($tmpdir);
1311 my $uid = 500;
1312 my $gid = 500;
1313
1314 # Make sure that, if we're running as root, that the home directory has
1315 # permissions/privs set for the account we create
1316 if ($< == 0) {
1317 unless (chmod(0755, $home_dir)) {
1318 die("Can't set perms on $home_dir to 0755: $!");
1319 }
1320
1321 unless (chown($uid, $gid, $home_dir)) {
1322 die("Can't set owner of $home_dir to $uid/$gid: $!");
1323 }
1324 }
1325
1326 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1327 '/bin/bash');
1328 auth_group_write($auth_group_file, $group, $gid, $user);
1329
1330 my $config = {
1331 PidFile => $pid_file,
1332 ScoreboardFile => $scoreboard_file,
1333 SystemLog => $log_file,
1334
1335 AuthUserFile => $auth_user_file,
1336 AuthGroupFile => $auth_group_file,
1337 AuthOrder => 'mod_auth_file.c',
1338
1339 IfModules => {
1340 'mod_delay.c' => {
1341 DelayEngine => 'off',
1342 },
1343 },
1344 };
1345
1346 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1347
1348 # Open pipes, for use between the parent and child processes. Specifically,
1349 # the child will indicate when it's done with its test by writing a message
1350 # to the parent.
1351 my ($rfh, $wfh);
1352 unless (pipe($rfh, $wfh)) {
1353 die("Can't open pipe: $!");
1354 }
1355
1356 my $ex;
1357
1358 # Fork child
1359 $self->handle_sigchld();
1360 defined(my $pid = fork()) or die("Can't fork: $!");
1361 if ($pid) {
1362 eval {
1363 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1364 $client->login($user, $passwd);
1365 $client->quit();
1366 };
1367
1368 if ($@) {
1369 $ex = $@;
1370 }
1371
1372 $wfh->print("done\n");
1373 $wfh->flush();
1374
1375 } else {
1376 eval { server_wait($config_file, $rfh) };
1377 if ($@) {
1378 warn($@);
1379 exit 1;
1380 }
1381
1382 exit 0;
1383 }
1384
1385 # Stop server
1386 server_stop($pid_file);
1387
1388 $self->assert_child_ok($pid);
1389
1390 if ($ex) {
1391 test_append_logfile($log_file, $ex);
1392 unlink($log_file);
1393
1394 die($ex);
1395 }
1396
1397 unlink($log_file);
1398 }
1399
1400 sub auth_user_file_world_readable_bug3892 {
1401 my $self = shift;
1402 my $tmpdir = $self->{tmpdir};
1403
1404 my $config_file = "$tmpdir/authfile.conf";
1405 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1406 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1407
1408 my $log_file = test_get_logfile();
1409
1410 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1411 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1412
1413 my $user = 'proftpd';
1414 my $passwd = 'test';
1415 my $group = 'ftpd';
1416 my $home_dir = File::Spec->rel2abs($tmpdir);
1417 my $uid = 500;
1418 my $gid = 500;
1419
1420 # Make sure that, if we're running as root, that the home directory has
1421 # permissions/privs set for the account we create
1422 if ($< == 0) {
1423 unless (chmod(0755, $home_dir)) {
1424 die("Can't set perms on $home_dir to 0755: $!");
1425 }
1426
1427 unless (chown($uid, $gid, $home_dir)) {
1428 die("Can't set owner of $home_dir to $uid/$gid: $!");
1429 }
1430 }
1431
1432 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1433 '/bin/bash');
1434 auth_group_write($auth_group_file, $group, $gid, $user);
1435
1436 # Deliberately set world-readable perms on the AuthUserFile, to trigger
1437 # the checks done for Bug#3892.
1438 unless (chmod(0444, $auth_user_file)) {
1439 die("Can't set perms on $auth_user_file: $!");
1440 }
1441
1442 my $config = {
1443 PidFile => $pid_file,
1444 ScoreboardFile => $scoreboard_file,
1445 SystemLog => $log_file,
1446
1447 AuthUserFile => $auth_user_file,
1448 AuthGroupFile => $auth_group_file,
1449 AuthOrder => 'mod_auth_file.c',
1450
1451 IfModules => {
1452 'mod_delay.c' => {
1453 DelayEngine => 'off',
1454 },
1455 },
1456 };
1457
1458 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1459
1460 eval { server_start($config_file, $pid_file) };
1461 unless ($@) {
1462 server_stop($pid_file);
1463
1464 my $ex = "Server started up unexpectedly with world-readable AuthUserFile";
1465 test_append_logfile($log_file, $ex);
1466 unlink($log_file);
1467
1468 die($ex);
1469 }
1470
1471 unlink($log_file);
1472 }
1473
1474 sub auth_user_file_world_writable_bug3892 {
1475 my $self = shift;
1476 my $tmpdir = $self->{tmpdir};
1477
1478 my $config_file = "$tmpdir/authfile.conf";
1479 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1480 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1481
1482 my $log_file = test_get_logfile();
1483
1484 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1485 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1486
1487 my $user = 'proftpd';
1488 my $passwd = 'test';
1489 my $group = 'ftpd';
1490 my $home_dir = File::Spec->rel2abs($tmpdir);
1491 my $uid = 500;
1492 my $gid = 500;
1493
1494 # Make sure that, if we're running as root, that the home directory has
1495 # permissions/privs set for the account we create
1496 if ($< == 0) {
1497 unless (chmod(0755, $home_dir)) {
1498 die("Can't set perms on $home_dir to 0755: $!");
1499 }
1500
1501 unless (chown($uid, $gid, $home_dir)) {
1502 die("Can't set owner of $home_dir to $uid/$gid: $!");
1503 }
1504 }
1505
1506 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1507 '/bin/bash');
1508 auth_group_write($auth_group_file, $group, $gid, $user);
1509
1510 # Deliberately set world-writable perms on the AuthUserFile, to trigger
1511 # the checks done for Bug#3892.
1512 unless (chmod(0442, $auth_user_file)) {
1513 die("Can't set perms on $auth_user_file: $!");
1514 }
1515
1516 my $config = {
1517 PidFile => $pid_file,
1518 ScoreboardFile => $scoreboard_file,
1519 SystemLog => $log_file,
1520
1521 AuthUserFile => $auth_user_file,
1522 AuthGroupFile => $auth_group_file,
1523 AuthOrder => 'mod_auth_file.c',
1524
1525 IfModules => {
1526 'mod_delay.c' => {
1527 DelayEngine => 'off',
1528 },
1529 },
1530 };
1531
1532 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1533
1534 eval { server_start($config_file, $pid_file) };
1535 unless ($@) {
1536 server_stop($pid_file);
1537
1538 my $ex = "Server started up unexpectedly with world-writable AuthUserFile";
1539 test_append_logfile($log_file, $ex);
1540 unlink($log_file);
1541
1542 die($ex);
1543 }
1544
1545 unlink($log_file);
1546 }
1547
1548 sub auth_user_file_world_readable_insecure_perms_opt {
1549 my $self = shift;
1550 my $tmpdir = $self->{tmpdir};
1551 my $setup = test_setup($tmpdir, 'authfile');
1552
1553 # Deliberately set world-readable perms on the AuthUserFile, to trigger
1554 # the checks done for Bug#3892.
1555 unless (chmod(0444, $setup->{auth_user_file})) {
1556 die("Can't set perms on $setup->{auth_user_file}: $!");
1557 }
1558
1559 my $config = {
1560 PidFile => $setup->{pid_file},
1561 ScoreboardFile => $setup->{scoreboard_file},
1562 SystemLog => $setup->{log_file},
1563
1564 IfModules => {
1565 'mod_delay.c' => {
1566 DelayEngine => 'off',
1567 },
1568 },
1569 };
1570
1571 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1572 $config);
1573
1574 # Note that we set this AuthFileOption here using an array, so that the
1575 # order of the directives is deterministic!
1576 if (open(my $fh, ">> $setup->{config_file}")) {
1577 print $fh <<EOC;
1578 AuthFileOptions InsecurePerms
1579 AuthUserFile $setup->{auth_user_file}
1580 AuthGroupFile $setup->{auth_group_file}
1581 AuthOrder mod_auth_file.c
1582 EOC
1583 unless (close($fh)) {
1584 die("Can't write $setup->{config_file}: $!");
1585 }
1586
1587 } else {
1588 die("Can't open $setup->{config_file}: $!");
1589 }
1590
1591 my $ex;
1592
1593 eval { server_start($setup->{config_file}, $setup->{pid_file}) };
1594 if ($@) {
1595 $ex = $@;
1596
1597 } else {
1598 server_stop($setup->{pid_file});
1599 }
1600
1601 test_cleanup($setup->{log_file}, $ex);
1602 }
1603
1604 sub auth_group_file_world_readable_bug3892 {
1605 my $self = shift;
1606 my $tmpdir = $self->{tmpdir};
1607
1608 my $config_file = "$tmpdir/authfile.conf";
1609 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1610 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1611
1612 my $log_file = test_get_logfile();
1613
1614 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1615 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1616
1617 my $user = 'proftpd';
1618 my $passwd = 'test';
1619 my $group = 'ftpd';
1620 my $home_dir = File::Spec->rel2abs($tmpdir);
1621 my $uid = 500;
1622 my $gid = 500;
1623
1624 # Make sure that, if we're running as root, that the home directory has
1625 # permissions/privs set for the account we create
1626 if ($< == 0) {
1627 unless (chmod(0755, $home_dir)) {
1628 die("Can't set perms on $home_dir to 0755: $!");
1629 }
1630
1631 unless (chown($uid, $gid, $home_dir)) {
1632 die("Can't set owner of $home_dir to $uid/$gid: $!");
1633 }
1634 }
1635
1636 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1637 '/bin/bash');
1638 auth_group_write($auth_group_file, $group, $gid, $user);
1639
1640 # Deliberately set world-readable perms on the AuthGroupFile, to trigger
1641 # the checks done for Bug#3892.
1642 unless (chmod(0444, $auth_group_file)) {
1643 die("Can't set perms on $auth_group_file: $!");
1644 }
1645
1646 my $config = {
1647 PidFile => $pid_file,
1648 ScoreboardFile => $scoreboard_file,
1649 SystemLog => $log_file,
1650
1651 AuthUserFile => $auth_user_file,
1652 AuthGroupFile => $auth_group_file,
1653 AuthOrder => 'mod_auth_file.c',
1654
1655 IfModules => {
1656 'mod_delay.c' => {
1657 DelayEngine => 'off',
1658 },
1659 },
1660 };
1661
1662 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1663
1664 eval { server_start($config_file, $pid_file) };
1665 if ($@) {
1666 my $ex = $@;
1667 test_append_logfile($log_file, $ex);
1668 unlink($log_file);
1669
1670 die($ex);
1671 }
1672
1673 server_stop($pid_file);
1674 unlink($log_file);
1675 }
1676
1677 sub auth_group_file_world_writable_bug3892 {
1678 my $self = shift;
1679 my $tmpdir = $self->{tmpdir};
1680
1681 my $config_file = "$tmpdir/authfile.conf";
1682 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1683 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1684
1685 my $log_file = test_get_logfile();
1686
1687 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1688 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1689
1690 my $user = 'proftpd';
1691 my $passwd = 'test';
1692 my $group = 'ftpd';
1693 my $home_dir = File::Spec->rel2abs($tmpdir);
1694 my $uid = 500;
1695 my $gid = 500;
1696
1697 # Make sure that, if we're running as root, that the home directory has
1698 # permissions/privs set for the account we create
1699 if ($< == 0) {
1700 unless (chmod(0755, $home_dir)) {
1701 die("Can't set perms on $home_dir to 0755: $!");
1702 }
1703
1704 unless (chown($uid, $gid, $home_dir)) {
1705 die("Can't set owner of $home_dir to $uid/$gid: $!");
1706 }
1707 }
1708
1709 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1710 '/bin/bash');
1711 auth_group_write($auth_group_file, $group, $gid, $user);
1712
1713 # Deliberately set world-writable perms on the AuthGroupFile, to trigger
1714 # the checks done for Bug#3892.
1715 unless (chmod(0442, $auth_group_file)) {
1716 die("Can't set perms on $auth_group_file: $!");
1717 }
1718
1719 my $config = {
1720 PidFile => $pid_file,
1721 ScoreboardFile => $scoreboard_file,
1722 SystemLog => $log_file,
1723
1724 AuthUserFile => $auth_user_file,
1725 AuthGroupFile => $auth_group_file,
1726 AuthOrder => 'mod_auth_file.c',
1727
1728 IfModules => {
1729 'mod_delay.c' => {
1730 DelayEngine => 'off',
1731 },
1732 },
1733 };
1734
1735 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1736
1737 eval { server_start($config_file, $pid_file) };
1738 unless ($@) {
1739 server_stop($pid_file);
1740
1741 my $ex = "Server started up unexpectedly with world-writable AuthGroupFile";
1742 test_append_logfile($log_file, $ex);
1743 unlink($log_file);
1744
1745 die($ex);
1746 }
1747
1748 unlink($log_file);
1749 }
1750
1751 sub auth_user_file_world_writable_parent_dir_bug3892 {
1752 my $self = shift;
1753 my $tmpdir = $self->{tmpdir};
1754
1755 my $config_file = "$tmpdir/authfile.conf";
1756 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1757 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1758
1759 my $log_file = test_get_logfile();
1760
1761 my $auth_user_file = File::Spec->rel2abs("$tmpdir/authfile.passwd");
1762 my $auth_group_file = File::Spec->rel2abs("$tmpdir/authfile.group");
1763
1764 my $user = 'proftpd';
1765 my $passwd = 'test';
1766 my $group = 'ftpd';
1767 my $home_dir = File::Spec->rel2abs($tmpdir);
1768 my $uid = 500;
1769 my $gid = 500;
1770
1771 # Make sure that, if we're running as root, that the home directory has
1772 # permissions/privs set for the account we create
1773 if ($< == 0) {
1774 unless (chmod(0755, $home_dir)) {
1775 die("Can't set perms on $home_dir to 0755: $!");
1776 }
1777
1778 unless (chown($uid, $gid, $home_dir)) {
1779 die("Can't set owner of $home_dir to $uid/$gid: $!");
1780 }
1781 }
1782
1783 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1784 '/bin/bash');
1785 auth_group_write($auth_group_file, $group, $gid, $user);
1786
1787 # Deliberately set world-writable perms on the parent directory of the
1788 # AuthUserFile, to trigger the checks done for Bug#3892.
1789 unless (chmod(0777, $tmpdir)) {
1790 die("Can't set perms on $tmpdir: $!");
1791 }
1792
1793 my $config = {
1794 PidFile => $pid_file,
1795 ScoreboardFile => $scoreboard_file,
1796 SystemLog => $log_file,
1797
1798 AuthUserFile => $auth_user_file,
1799 AuthGroupFile => $auth_group_file,
1800 AuthOrder => 'mod_auth_file.c',
1801
1802 IfModules => {
1803 'mod_delay.c' => {
1804 DelayEngine => 'off',
1805 },
1806 },
1807 };
1808
1809 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1810
1811 eval { server_start($config_file, $pid_file) };
1812 unless ($@) {
1813 server_stop($pid_file);
1814
1815 my $ex = "Server started up unexpectedly with world-writable AuthUserFile parent directory";
1816 test_append_logfile($log_file, $ex);
1817 unlink($log_file);
1818
1819 die($ex);
1820 }
1821
1822 unlink($log_file);
1823 }
1824
1825 sub auth_user_file_symlink_world_writable_parent_dir_bug3892 {
1826 my $self = shift;
1827 my $tmpdir = $self->{tmpdir};
1828
1829 my $config_file = "$tmpdir/authfile.conf";
1830 my $pid_file = File::Spec->rel2abs("$tmpdir/authfile.pid");
1831 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/authfile.scoreboard");
1832
1833 my $log_file = test_get_logfile();
1834
1835 my $etc_dir = File::Spec->rel2abs("$tmpdir/etc");
1836 mkpath($etc_dir);
1837
1838 my $auth_user_file = File::Spec->rel2abs("$tmpdir/etc/authfile.passwd");
1839 my $auth_group_file = File::Spec->rel2abs("$tmpdir/etc/authfile.group");
1840
1841 my $user = 'proftpd';
1842 my $passwd = 'test';
1843 my $group = 'ftpd';
1844 my $home_dir = File::Spec->rel2abs($tmpdir);
1845 my $uid = 500;
1846 my $gid = 500;
1847
1848 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1849 mkpath($test_dir);
1850 my $auth_user_symlink = File::Spec->rel2abs("$tmpdir/test.d/authfile.lnk");
1851
1852 # Make sure that, if we're running as root, that the home directory has
1853 # permissions/privs set for the account we create
1854 #
1855 # Deliberately set world-writable perms on the symlink parent
1856 # directory, to trigger the checks done for Bug#3892.
1857
1858 if ($< == 0) {
1859 unless (chmod(0750, $home_dir, $etc_dir)) {
1860 die("Can't set perms on $home_dir to 0750: $!");
1861 }
1862
1863 unless (chmod(0777, $test_dir)) {
1864 die("Can't set perms on $etc_dir to 0777: $!");
1865 }
1866
1867 unless (chown($uid, $gid, $home_dir, $etc_dir, $test_dir)) {
1868 die("Can't set owner of $home_dir to $uid/$gid: $!");
1869 }
1870
1871 } else {
1872 unless (chmod(0750, $home_dir, $etc_dir)) {
1873 die("Can't set perms on $home_dir to 0750: $!");
1874 }
1875
1876 unless (chmod(0777, $test_dir)) {
1877 die("Can't set perms on $test_dir to 0777: $!");
1878 }
1879 }
1880
1881 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1882 '/bin/bash');
1883 auth_group_write($auth_group_file, $group, $gid, $user);
1884
1885 my $cwd = getcwd();
1886 unless (chdir($test_dir)) {
1887 die("Can't chdir to $test_dir: $!");
1888 }
1889
1890 unless (symlink($auth_user_file, 'authfile.lnk')) {
1891 die("Can't symlink '$auth_user_file' to 'authfile.lnk': $!");
1892 }
1893
1894 unless (chdir($cwd)) {
1895 die("Can't chdir to $cwd: $!");
1896 }
1897
1898 my $config = {
1899 PidFile => $pid_file,
1900 ScoreboardFile => $scoreboard_file,
1901 SystemLog => $log_file,
1902
1903 AuthUserFile => $auth_user_symlink,
1904 AuthGroupFile => $auth_group_file,
1905 AuthOrder => 'mod_auth_file.c',
1906
1907 IfModules => {
1908 'mod_delay.c' => {
1909 DelayEngine => 'off',
1910 },
1911 },
1912 };
1913
1914 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1915
1916 eval { server_start($config_file, $pid_file) };
1917 unless ($@) {
1918 server_stop($pid_file);
1919
1920 my $ex = "Server started up unexpectedly with symlink AuthUserFile";
1921 test_append_logfile($log_file, $ex);
1922 unlink($log_file);
1923
1924 die($ex);
1925 }
1926
1927 unlink($log_file);
1928 }
1929
1930 sub auth_user_file_bad_syntax_bug3985 {
1931 my $self = shift;
1932 my $tmpdir = $self->{tmpdir};
1933
1934 # Test that mod_auth_file correctly deals with malformed AuthUserFile
1935 # entries (per Bug#3985).
1936 my $setup = test_setup($tmpdir, 'authfile', undef, undef, undef, undef, undef,
1937 'FirstName:LastName');
1938
1939 my $config = {
1940 PidFile => $setup->{pid_file},
1941 ScoreboardFile => $setup->{scoreboard_file},
1942 SystemLog => $setup->{log_file},
1943 TraceLog => $setup->{log_file},
1944 Trace => 'auth.file:20',
1945
1946 AuthUserFile => $setup->{auth_user_file},
1947 AuthGroupFile => $setup->{auth_group_file},
1948 AuthOrder => 'mod_auth_file.c',
1949
1950 IfModules => {
1951 'mod_delay.c' => {
1952 DelayEngine => 'off',
1953 },
1954 },
1955 };
1956
1957 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1958 $config);
1959
1960 # Open pipes, for use between the parent and child processes. Specifically,
1961 # the child will indicate when it's done with its test by writing a message
1962 # to the parent.
1963 my ($rfh, $wfh);
1964 unless (pipe($rfh, $wfh)) {
1965 die("Can't open pipe: $!");
1966 }
1967
1968 my $ex;
1969
1970 # Fork child
1971 $self->handle_sigchld();
1972 defined(my $pid = fork()) or die("Can't fork: $!");
1973 if ($pid) {
1974 eval {
1975 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1976 eval { $client->login($setup->{user}, $setup->{passwd}) };
1977 unless ($@) {
1978 $client->quit();
1979 die("Login succeeded unexpectedly");
1980 }
1981 };
1982 if ($@) {
1983 $ex = $@;
1984 }
1985
1986 $wfh->print("done\n");
1987 $wfh->flush();
1988
1989 } else {
1990 eval { server_wait($setup->{config_file}, $rfh) };
1991 if ($@) {
1992 warn($@);
1993 exit 1;
1994 }
1995
1996 exit 0;
1997 }
1998
1999 # Stop server
2000 server_stop($setup->{pid_file});
2001 $self->assert_child_ok($pid);
2002
2003 test_cleanup($setup->{log_file}, $ex);
2004 }
2005
2006 sub auth_group_file_bad_syntax_bug3985 {
2007 my $self = shift;
2008 my $tmpdir = $self->{tmpdir};
2009
2010 # Test that mod_auth_file correctly deals with malformed AuthGroupFile
2011 # entries (per Bug#3985).
2012 my $setup = test_setup($tmpdir, 'authfile', undef, undef, 'yarr:ftpd');
2013
2014 my $config = {
2015 PidFile => $setup->{pid_file},
2016 ScoreboardFile => $setup->{scoreboard_file},
2017 SystemLog => $setup->{log_file},
2018 TraceLog => $setup->{log_file},
2019 Trace => 'auth.file:20',
2020
2021 AuthUserFile => $setup->{auth_user_file},
2022 AuthGroupFile => $setup->{auth_group_file},
2023 AuthOrder => 'mod_auth_file.c',
2024
2025 IfModules => {
2026 'mod_delay.c' => {
2027 DelayEngine => 'off',
2028 },
2029 },
2030 };
2031
2032 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2033 $config);
2034
2035 if (open(my $fh, ">> $setup->{config_file}")) {
2036 print $fh <<EOC;
2037 <Limit LOGIN>
2038 DenyGroup $setup->{group}
2039 AllowAll
2040 </Limit>
2041 EOC
2042
2043 unless (close($fh)) {
2044 die("Can't write $setup->{config_file}: $!");
2045 }
2046
2047 } else {
2048 die("Can't open $setup->{config_file}: $!");
2049 }
2050
2051 # Open pipes, for use between the parent and child processes. Specifically,
2052 # the child will indicate when it's done with its test by writing a message
2053 # to the parent.
2054 my ($rfh, $wfh);
2055 unless (pipe($rfh, $wfh)) {
2056 die("Can't open pipe: $!");
2057 }
2058
2059 my $ex;
2060
2061 # Fork child
2062 $self->handle_sigchld();
2063 defined(my $pid = fork()) or die("Can't fork: $!");
2064 if ($pid) {
2065 eval {
2066 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2067
2068 # Despite the <Limit LOGIN> line for our group, we should still
2069 # succeed in logging in, because of the malformed AuthGroupFile
2070 # entry.
2071 $client->login($setup->{user}, $setup->{passwd});
2072 $client->quit();
2073 };
2074 if ($@) {
2075 $ex = $@;
2076 }
2077
2078 $wfh->print("done\n");
2079 $wfh->flush();
2080
2081 } else {
2082 eval { server_wait($setup->{config_file}, $rfh) };
2083 if ($@) {
2084 warn($@);
2085 exit 1;
2086 }
2087
2088 exit 0;
2089 }
2090
2091 # Stop server
2092 server_stop($setup->{pid_file});
2093 $self->assert_child_ok($pid);
2094
2095 test_cleanup($setup->{log_file}, $ex);
2096 }
2097
2098 sub auth_user_file_bad_syntax_check_issue490 {
2099 my $self = shift;
2100 my $tmpdir = $self->{tmpdir};
2101
2102 # Test that mod_auth_file correctly detects malformed AuthUserFile entries
2103 # on syntax check (per Issue#490).
2104 my $setup = test_setup($tmpdir, 'authfile', 'proftpd::');
2105
2106 my $config = {
2107 PidFile => $setup->{pid_file},
2108 ScoreboardFile => $setup->{scoreboard_file},
2109 SystemLog => $setup->{log_file},
2110 TraceLog => $setup->{log_file},
2111 Trace => 'auth.file:20',
2112
2113 IfModules => {
2114 'mod_delay.c' => {
2115 DelayEngine => 'off',
2116 },
2117 },
2118 };
2119
2120 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2121 $config);
2122
2123 # These entries are written manually, so that the AuthFileOptions directive
2124 # always appears first.
2125 if (open(my $fh, ">> $setup->{config_file}")) {
2126 print $fh <<EOC;
2127 AuthFileOptions SyntaxCheck
2128 AuthUserFile $setup->{auth_user_file}
2129 AuthGroupFile $setup->{auth_group_file}
2130 AuthOrder mod_auth_file.c
2131 EOC
2132 unless (close($fh)) {
2133 die("Can't write $setup->{log_file}: $!");
2134 }
2135
2136 } else {
2137 die("Can't open $setup->{config_file}: $!");
2138 }
2139
2140 my $ex;
2141
2142 eval { server_start($setup->{config_file}, $setup->{pid_file}) };
2143 unless ($@) {
2144 server_stop($setup->{pid_file});
2145 $ex = "Server started up unexpectedly with AuthUserFile with bad entries";
2146 }
2147
2148 test_cleanup($setup->{log_file}, $ex);
2149 }
2150
2151 sub auth_group_file_bad_syntax_check_issue490 {
2152 my $self = shift;
2153 my $tmpdir = $self->{tmpdir};
2154
2155 # Test that mod_auth_file correctly detects malformed AuthUserFile entries
2156 # on syntax check (per Issue#490).
2157 my $setup = test_setup($tmpdir, 'authfile', undef, undef, 'ftpd::');
2158
2159 my $config = {
2160 PidFile => $setup->{pid_file},
2161 ScoreboardFile => $setup->{scoreboard_file},
2162 SystemLog => $setup->{log_file},
2163 TraceLog => $setup->{log_file},
2164 Trace => 'auth.file:20',
2165
2166 IfModules => {
2167 'mod_delay.c' => {
2168 DelayEngine => 'off',
2169 },
2170 },
2171 };
2172
2173 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2174 $config);
2175
2176 # These entries are written manually, so that the AuthFileOptions directive
2177 # always appears after the AuthUserFile, but before the AuthGroupFile.
2178 if (open(my $fh, ">> $setup->{config_file}")) {
2179 print $fh <<EOC;
2180 AuthUserFile $setup->{auth_user_file}
2181
2182 AuthFileOptions SyntaxCheck
2183 AuthGroupFile $setup->{auth_group_file}
2184 AuthOrder mod_auth_file.c
2185 EOC
2186 unless (close($fh)) {
2187 die("Can't write $setup->{log_file}: $!");
2188 }
2189
2190 } else {
2191 die("Can't open $setup->{config_file}: $!");
2192 }
2193
2194 my $ex;
2195
2196 eval { server_start($setup->{config_file}, $setup->{pid_file}) };
2197 unless ($@) {
2198 server_stop($setup->{pid_file});
2199 $ex = "Server started up unexpectedly with AuthUserFile with bad entries";
2200 }
2201
2202 test_cleanup($setup->{log_file}, $ex);
2203 }
2204
2205 sub auth_file_symlink_segfault_bug4145 {
2206 my $self = shift;
2207 my $tmpdir = $self->{tmpdir};
2208 my $setup = test_setup($tmpdir, 'authfile');
2209
2210 my $authfiles_parent_dir = File::Spec->rel2abs("$tmpdir/etc");
2211 mkpath($authfiles_parent_dir);
2212
2213 my $authfiles_dir = File::Spec->rel2abs("$authfiles_parent_dir/proftpd");
2214 mkpath($authfiles_dir);
2215
2216 # Create symlinks using a relative path to the Auth files, to reproduce
2217 # Bug#4145.
2218 my $cwd = getcwd();
2219 unless (chdir($authfiles_dir)) {
2220 die("Can't chdir to $authfiles_dir: $!");
2221 }
2222
2223 my $rel_path = File::Spec->abs2rel($tmpdir);
2224
2225 unless (symlink("$rel_path/authfile.passwd", 'passwd.lnk')) {
2226 die("Can't symlink '$setup->{auth_user_file}' to 'passwd.lnk': $!");
2227 }
2228
2229 unless (symlink("$rel_path/authfile.group", 'group.lnk')) {
2230 die("Can't symlink '$setup->{auth_group_file}' to 'group.lnk': $!");
2231 }
2232
2233 unless (chdir($cwd)) {
2234 die("Can't chdir to $cwd: $!");
2235 }
2236
2237 my $auth_user_symlink = File::Spec->rel2abs($authfiles_dir) . "/passwd.lnk";
2238 my $auth_group_symlink = File::Spec->rel2abs($authfiles_dir) . "/group.lnk";
2239
2240 # Make sure that, if we're running as root, that the home directory has
2241 # permissions/privs set for the account we create
2242 if ($< == 0) {
2243 unless (chmod(0755, $setup->{home_dir}, $authfiles_parent_dir, $authfiles_dir)) {
2244 die("Can't set perms on $setup->{home_dir} to 0755: $!");
2245 }
2246
2247 unless (chown($setup->{uid}, $setup->{gid}, $setup->{home_dir}, $authfiles_parent_dir, $authfiles_dir)) {
2248 die("Can't set owner of $setup->{home_dir} to $setup->{uid}/$setup->{gid}: $!");
2249 }
2250 }
2251
2252 # Test that mod_auth_file correctly deals with malformed AuthGroupFile
2253 # entries (per Bug#3985).
2254 auth_group_write($setup->{auth_group_file}, "yarr:$setup->{group}",
2255 $setup->{gid}, $setup->{user});
2256
2257 my $config = {
2258 PidFile => $setup->{pid_file},
2259 ScoreboardFile => $setup->{scoreboard_file},
2260 SystemLog => $setup->{log_file},
2261
2262 AuthUserFile => $auth_user_symlink,
2263 AuthGroupFile => $auth_group_symlink,
2264 AuthOrder => 'mod_auth_file.c',
2265
2266 IfModules => {
2267 'mod_delay.c' => {
2268 DelayEngine => 'off',
2269 },
2270 },
2271 };
2272
2273 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2274 $config);
2275
2276 # Open pipes, for use between the parent and child processes. Specifically,
2277 # the child will indicate when it's done with its test by writing a message
2278 # to the parent.
2279 my ($rfh, $wfh);
2280 unless (pipe($rfh, $wfh)) {
2281 die("Can't open pipe: $!");
2282 }
2283
2284 my $ex;
2285
2286 # Fork child
2287 $self->handle_sigchld();
2288 defined(my $pid = fork()) or die("Can't fork: $!");
2289 if ($pid) {
2290 eval {
2291 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2292 $client->login($setup->{user}, $setup->{passwd});
2293 $client->quit();
2294 };
2295 if ($@) {
2296 $ex = $@;
2297 }
2298
2299 $wfh->print("done\n");
2300 $wfh->flush();
2301
2302 } else {
2303 eval { server_wait($setup->{config_file}, $rfh) };
2304 if ($@) {
2305 warn($@);
2306 exit 1;
2307 }
2308
2309 exit 0;
2310 }
2311
2312 # Stop server
2313 server_stop($setup->{pid_file});
2314 $self->assert_child_ok($pid);
2315
2316 test_cleanup($setup->{log_file}, $ex);
2317 }
2318
2319 sub auth_file_line_too_long_issue1321 {
2320 my $self = shift;
2321 my $tmpdir = $self->{tmpdir};
2322
2323 # For Issue #1321, we create a very long AuthGroupFile entry with many
2324 # group names.
2325
2326 my $groups = 'proftpd';
2327 for (my $i = 0; $i < 200; $i++) {
2328 $groups .= ",quite.long.example.group.$i";
2329 }
2330
2331 my $setup = test_setup($tmpdir, 'authfile', undef, undef, undef, undef, undef,
2332 undef, $groups);
2333
2334 my $config = {
2335 PidFile => $setup->{pid_file},
2336 ScoreboardFile => $setup->{scoreboard_file},
2337 SystemLog => $setup->{log_file},
2338
2339 AuthUserFile => $setup->{auth_user_file},
2340 AuthGroupFile => $setup->{auth_group_file},
2341 AuthOrder => 'mod_auth_file.c',
2342
2343 IfModules => {
2344 'mod_delay.c' => {
2345 DelayEngine => 'off',
2346 },
2347 },
2348 };
2349
2350 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2351 $config);
2352
2353 # Open pipes, for use between the parent and child processes. Specifically,
2354 # the child will indicate when it's done with its test by writing a message
2355 # to the parent.
2356 my ($rfh, $wfh);
2357 unless (pipe($rfh, $wfh)) {
2358 die("Can't open pipe: $!");
2359 }
2360
2361 my $ex;
2362
2363 # Fork child
2364 $self->handle_sigchld();
2365 defined(my $pid = fork()) or die("Can't fork: $!");
2366 if ($pid) {
2367 eval {
2368 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2369 $client->login($setup->{user}, $setup->{passwd});
2370 $client->quit();
2371 };
2372 if ($@) {
2373 $ex = $@;
2374 }
2375
2376 $wfh->print("done\n");
2377 $wfh->flush();
2378
2379 } else {
2380 eval { server_wait($setup->{config_file}, $rfh) };
2381 if ($@) {
2382 warn($@);
2383 exit 1;
2384 }
2385
2386 exit 0;
2387 }
2388
2389 # Stop server
2390 server_stop($setup->{pid_file});
2391 $self->assert_child_ok($pid);
2392
2393 test_cleanup($setup->{log_file}, $ex);
2394 }
2395
2396 1;