Debian Codegraph @

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

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