Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/Directory/Lookups.pm

raw
1 package ProFTPD::Tests::Config::Directory::Lookups;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Data::Dumper;
8 use File::Path qw(mkpath);
9 use File::Spec;
10 use IO::Handle;
11 use Time::HiRes qw(gettimeofday tv_interval);
12
13 use ProFTPD::TestSuite::FTP;
14 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
15
16 $| = 1;
17
18 my $order = 0;
19
20 my $TESTS = {
21 dir_lookup_wide_layout_abs_paths => {
22 order => ++$order,
23 test_class => [qw(bug forking slow)],
24 },
25
26 dir_lookup_deep_layout_abs_paths => {
27 order => ++$order,
28 test_class => [qw(bug forking slow)],
29 },
30
31 dir_lookup_wide_layout_rel_paths => {
32 order => ++$order,
33 test_class => [qw(bug forking slow)],
34 },
35
36 dir_lookup_deep_layout_rel_paths => {
37 order => ++$order,
38 test_class => [qw(bug forking slow)],
39 },
40
41 dir_lookup_many_files_hidefiles_bug3526 => {
42 order => ++$order,
43 test_class => [qw(bug forking slow)],
44 },
45
46 # I suspect that, due to the nature of the parser, the order in which
47 # the <Directory> sections appear in the config can affect performance.
48 # If the _last_ <Directory> section is for the most common path referenced,
49 # it could mean longer traversal times (for each lookup) before the
50 # match is made.
51 #
52 # Defining absolute paths in the <Directory> paths, versus relative/runtime
53 # paths, makes a difference at login time. The resolve_deferred_dirs()
54 # function can take a while in the case of relative paths, causing login
55 # timeouts.
56
57 };
58
59 sub new {
60 return shift()->SUPER::new(@_);
61 }
62
63 sub list_tests {
64 # return testsuite_get_runnable_tests($TESTS);
65 return qw(
66 dir_lookup_many_files_hidefiles_bug3526
67 );
68 }
69
70 sub set_up {
71 my $self = shift;
72 $self->SUPER::set_up(@_);
73
74 make_name(0, 0);
75 }
76
77 my ($prev_name, $prev_namelen);
78
79 sub make_name {
80 my $name_len = shift;
81 my $inc = shift;
82
83 if ($name_len == 0) {
84 ($prev_name, $prev_namelen) = (undef, undef);
85 return undef;
86 }
87
88 # If the requested name length has changed, start over
89 if ($name_len != $prev_namelen) {
90 $prev_name = undef;
91 }
92
93 if (defined($prev_name)) {
94 # Split the name into its individual chars, in reverse order
95 my @chars = reverse(split('', $prev_name));
96
97 # Increment the first char, then reassemble the name. We only want
98 # ASCII characters (i.e. A-Za-z inclusive). So if the incremented first
99 # char is outside the range, reset the first char to the range start, and
100 # increment the next char.
101
102 for (my $i = 0; $i < $prev_namelen; $i++) {
103 my $char = $chars[$i];
104 my $val = ord($char);
105
106 $char = chr(++$val);
107
108 my $reset_char = 0;
109 while ($char !~ /[A-Za-z]/o) {
110 ++$val;
111 if ($val > 122) {
112 # Too far; reset to 'A'.
113 $val = 65;
114 $reset_char = 1;
115 }
116
117 $char = chr($val);
118 }
119
120 $chars[$i] = $char;
121
122 unless ($reset_char) {
123 last;
124 }
125 }
126
127 $prev_name = join('', reverse(@chars));
128
129 } else {
130 $prev_name = "A" x $name_len;
131 $prev_namelen = $name_len;
132 }
133
134 return $prev_name;
135 }
136
137 sub dir_lookup_wide_layout_abs_paths {
138 my $self = shift;
139 my $tmpdir = $self->{tmpdir};
140
141 my $config_file = "$tmpdir/dir.conf";
142 my $pid_file = File::Spec->rel2abs("$tmpdir/dir.pid");
143 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/dir.scoreboard");
144
145 my $log_file = File::Spec->rel2abs('tests.log');
146
147 my $auth_user_file = File::Spec->rel2abs("$tmpdir/dir.passwd");
148 my $auth_group_file = File::Spec->rel2abs("$tmpdir/dir.group");
149
150 my $user = 'proftpd';
151 my $passwd = 'test';
152 my $home_dir = File::Spec->rel2abs($tmpdir);
153 my $uid = 500;
154 my $gid = 500;
155
156 # Make sure that, if we're running as root, that the home directory has
157 # permissions/privs set for the account we create
158 if ($< == 0) {
159 unless (chmod(0755, $home_dir)) {
160 die("Can't set perms on $home_dir to 0755: $!");
161 }
162
163 unless (chown($uid, $gid, $home_dir)) {
164 die("Can't set owner of $home_dir to $uid/$gid: $!");
165 }
166 }
167
168 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
169 '/bin/bash');
170 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
171
172 my $timeout = 300;
173
174 my $config = {
175 PidFile => $pid_file,
176 ScoreboardFile => $scoreboard_file,
177 SystemLog => $log_file,
178 TraceLog => $log_file,
179 Trace => 'DEFAULT:10 auth:0 config:0 directory:10 fsio:0 lock:0',
180
181 AuthUserFile => $auth_user_file,
182 AuthGroupFile => $auth_group_file,
183
184 AllowOverwrite => 'on',
185 CommandBufferSize => 1024,
186 TimeoutIdle => $timeout,
187 TimeoutLogin => $timeout,
188
189 Directory => {
190 '/' => {
191 Umask => '066 077',
192 },
193 },
194
195 IfModules => {
196 'mod_delay.c' => {
197 DelayEngine => 'off',
198 },
199 },
200 };
201
202 my ($port, $config_user, $config_group) = config_write($config_file, $config);
203
204 # Append our mess of many wide <Directory> sections to the config:
205 #
206 # <Directory /path/to/a>
207 # Umask 066 077
208 # </Directory>
209 #
210 # <Directory /path/to/b>
211 # Umask 066 077
212 # </Directory>
213
214 my $target_dir;
215
216 if (open(my $fh, ">> $config_file")) {
217 my $count = 1000;
218 print STDOUT "# Creating $count subdirectories\n";
219
220 my $namelen = 3;
221
222 for (my $i = 0; $i < $count; $i++) {
223 $target_dir = make_name($namelen, 1);
224 my $dir = File::Spec->rel2abs("$tmpdir/$target_dir");
225 mkpath($dir);
226
227 print $fh <<EOD;
228 <Directory $dir>
229 Umask 066 077
230 </Directory>
231 EOD
232 }
233
234 unless (close($fh)) {
235 die("Can't write $config_file: $!");
236 }
237
238 } else {
239 die("Can't open $config_file: $!");
240 }
241
242 # To test the worst-case scenario, the target directory (to which we will
243 # write a file) should be the _last_ in the list.
244
245 # Open pipes, for use between the parent and child processes. Specifically,
246 # the child will indicate when it's done with its test by writing a message
247 # to the parent.
248 my ($rfh, $wfh);
249 unless (pipe($rfh, $wfh)) {
250 die("Can't open pipe: $!");
251 }
252
253 my $ex;
254
255 # Fork child
256 $self->handle_sigchld();
257 defined(my $pid = fork()) or die("Can't fork: $!");
258 if ($pid) {
259 eval {
260 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, undef,
261 $timeout);
262
263 # Make sure the underlying Net::FTP uses our long timeout
264 my $old_timeout = $client->{ftp}->timeout($timeout);
265
266 my $start_login = [gettimeofday()];
267 $client->login($user, $passwd, $timeout);
268 my $login_elapsed = tv_interval($start_login);
269 print STDOUT "# Login elapsed: ", Dumper($login_elapsed);
270
271 my ($resp_code, $resp_msg);
272
273 my $start_upload = [gettimeofday()];
274
275 my $conn = $client->stor_raw("$target_dir/test.txt");
276 unless ($conn) {
277 die("Failed to STOR $target_dir/test.txt: " . $client->response_code() .
278 " " . $client->response_msg());
279 }
280
281 my $upload_elapsed = tv_interval($start_upload);
282 print STDOUT "# Upload elapsed: ", Dumper($upload_elapsed);
283
284 $conn->close();
285
286 $resp_code = $client->response_code();
287 $resp_msg = $client->response_msg();
288
289 $client->quit();
290
291 my $expected;
292
293 $expected = 226;
294 $self->assert($expected == $resp_code,
295 test_msg("Expected '$expected', got '$resp_code'"));
296
297 $expected = "Transfer complete";
298 $self->assert($expected eq $resp_msg,
299 test_msg("Expected '$expected', got '$resp_msg'"));
300 };
301
302 if ($@) {
303 $ex = $@;
304 }
305
306 $wfh->print("done\n");
307 $wfh->flush();
308
309 } else {
310 eval { server_wait($config_file, $rfh, $timeout + 5) };
311 if ($@) {
312 warn($@);
313 exit 1;
314 }
315
316 exit 0;
317 }
318
319 # Stop server
320 server_stop($pid_file);
321
322 $self->assert_child_ok($pid);
323
324 if ($ex) {
325 die($ex);
326 }
327
328 unlink($log_file);
329 }
330
331 sub dir_lookup_deep_layout_abs_paths {
332 my $self = shift;
333 my $tmpdir = $self->{tmpdir};
334
335 my $config_file = "$tmpdir/dir.conf";
336 my $pid_file = File::Spec->rel2abs("$tmpdir/dir.pid");
337 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/dir.scoreboard");
338
339 my $log_file = File::Spec->rel2abs('tests.log');
340
341 my $auth_user_file = File::Spec->rel2abs("$tmpdir/dir.passwd");
342 my $auth_group_file = File::Spec->rel2abs("$tmpdir/dir.group");
343
344 my $user = 'proftpd';
345 my $passwd = 'test';
346 my $home_dir = File::Spec->rel2abs($tmpdir);
347 my $uid = 500;
348 my $gid = 500;
349
350 # Make sure that, if we're running as root, that the home directory has
351 # permissions/privs set for the account we create
352 if ($< == 0) {
353 unless (chmod(0755, $home_dir)) {
354 die("Can't set perms on $home_dir to 0755: $!");
355 }
356
357 unless (chown($uid, $gid, $home_dir)) {
358 die("Can't set owner of $home_dir to $uid/$gid: $!");
359 }
360 }
361
362 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
363 '/bin/bash');
364 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
365
366 my $timeout = 300;
367
368 my $config = {
369 PidFile => $pid_file,
370 ScoreboardFile => $scoreboard_file,
371 SystemLog => $log_file,
372 TraceLog => $log_file,
373 Trace => 'DEFAULT:10 auth:0 config:0 directory:10 fsio:10 lock:0',
374
375 AuthUserFile => $auth_user_file,
376 AuthGroupFile => $auth_group_file,
377
378 AllowOverwrite => 'on',
379 CommandBufferSize => 1024,
380 TimeoutIdle => $timeout,
381 TimeoutLogin => $timeout,
382
383 Directory => {
384 '/' => {
385 Umask => '066 077',
386 },
387 },
388
389 IfModules => {
390 'mod_delay.c' => {
391 DelayEngine => 'off',
392 },
393 },
394 };
395
396 my ($port, $config_user, $config_group) = config_write($config_file, $config);
397
398 # Append our mess of many deep <Directory> sections to the config:
399 #
400 # <Directory /path/to/a>
401 # Umask 066 077
402 # </Directory>
403 #
404 # <Directory /path/to/a/b>
405 # Umask 066 077
406 # </Directory>
407
408 my $target_dir;
409 if (open(my $fh, ">> $config_file")) {
410 my $count = 256 - length($home_dir);
411 print STDOUT "# Creating $count subdirectories\n";
412
413 $target_dir = File::Spec->rel2abs("$tmpdir/" . make_name(1, 1));
414
415 for (my $i = 0; $i < $count; $i++) {
416 $target_dir = File::Spec->catdir($target_dir, make_name(1, 1));
417 my $dir = File::Spec->rel2abs($target_dir);
418 mkpath($dir);
419
420 print $fh <<EOD;
421 <Directory $dir>
422 Umask 066 077
423 </Directory>
424 EOD
425 }
426
427 unless (close($fh)) {
428 die("Can't write $config_file: $!");
429 }
430
431 } else {
432 die("Can't open $config_file: $!");
433 }
434
435 # To test the worst-case scenario, the target directory (to which we will
436 # write a file) should be the _last_ in the list.
437
438 # Open pipes, for use between the parent and child processes. Specifically,
439 # the child will indicate when it's done with its test by writing a message
440 # to the parent.
441 my ($rfh, $wfh);
442 unless (pipe($rfh, $wfh)) {
443 die("Can't open pipe: $!");
444 }
445
446 my $ex;
447
448 # Fork child
449 $self->handle_sigchld();
450 defined(my $pid = fork()) or die("Can't fork: $!");
451 if ($pid) {
452 eval {
453 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, undef,
454 $timeout);
455
456 # Make sure the underlying Net::FTP uses our long timeout
457 my $old_timeout = $client->{ftp}->timeout($timeout);
458
459 my $start_login = [gettimeofday()];
460 $client->login($user, $passwd, $timeout);
461 my $login_elapsed = tv_interval($start_login);
462 print STDOUT "# Login elapsed: ", Dumper($login_elapsed);
463
464 my ($resp_code, $resp_msg);
465
466 my $start_upload = [gettimeofday()];
467
468 my $conn = $client->stor_raw("$target_dir/test.txt");
469 unless ($conn) {
470 die("Failed to STOR $target_dir/test.txt: " . $client->response_code() .
471 " " . $client->response_msg());
472 }
473
474 my $upload_elapsed = tv_interval($start_upload);
475 print STDOUT "# Upload elapsed: ", Dumper($upload_elapsed);
476
477 $conn->close();
478
479 $resp_code = $client->response_code();
480 $resp_msg = $client->response_msg();
481
482 $client->quit();
483
484 my $expected;
485
486 $expected = 226;
487 $self->assert($expected == $resp_code,
488 test_msg("Expected '$expected', got '$resp_code'"));
489
490 $expected = "Transfer complete";
491 $self->assert($expected eq $resp_msg,
492 test_msg("Expected '$expected', got '$resp_msg'"));
493 };
494
495 if ($@) {
496 $ex = $@;
497 }
498
499 $wfh->print("done\n");
500 $wfh->flush();
501
502 } else {
503 eval { server_wait($config_file, $rfh, $timeout + 5) };
504 if ($@) {
505 warn($@);
506 exit 1;
507 }
508
509 exit 0;
510 }
511
512 # Stop server
513 server_stop($pid_file);
514
515 $self->assert_child_ok($pid);
516
517 if ($ex) {
518 die($ex);
519 }
520
521 unlink($log_file);
522 }
523
524 sub dir_lookup_wide_layout_rel_paths {
525 my $self = shift;
526 my $tmpdir = $self->{tmpdir};
527
528 my $config_file = "$tmpdir/dir.conf";
529 my $pid_file = File::Spec->rel2abs("$tmpdir/dir.pid");
530 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/dir.scoreboard");
531
532 my $log_file = File::Spec->rel2abs('tests.log');
533
534 my $auth_user_file = File::Spec->rel2abs("$tmpdir/dir.passwd");
535 my $auth_group_file = File::Spec->rel2abs("$tmpdir/dir.group");
536
537 my $user = 'proftpd';
538 my $passwd = 'test';
539 my $home_dir = File::Spec->rel2abs($tmpdir);
540 my $uid = 500;
541 my $gid = 500;
542
543 # Make sure that, if we're running as root, that the home directory has
544 # permissions/privs set for the account we create
545 if ($< == 0) {
546 unless (chmod(0755, $home_dir)) {
547 die("Can't set perms on $home_dir to 0755: $!");
548 }
549
550 unless (chown($uid, $gid, $home_dir)) {
551 die("Can't set owner of $home_dir to $uid/$gid: $!");
552 }
553 }
554
555 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
556 '/bin/bash');
557 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
558
559 my $timeout = 300;
560
561 my $config = {
562 PidFile => $pid_file,
563 ScoreboardFile => $scoreboard_file,
564 SystemLog => $log_file,
565 TraceLog => $log_file,
566 Trace => 'DEFAULT:10 auth:0 config:0 directory:10 fsio:0 lock:0',
567
568 AuthUserFile => $auth_user_file,
569 AuthGroupFile => $auth_group_file,
570
571 AllowOverwrite => 'on',
572 CommandBufferSize => 1024,
573 TimeoutIdle => $timeout,
574 TimeoutLogin => $timeout,
575
576 Directory => {
577 '/' => {
578 Umask => '066 077',
579 },
580 },
581
582 IfModules => {
583 'mod_delay.c' => {
584 DelayEngine => 'off',
585 },
586 },
587 };
588
589 my ($port, $config_user, $config_group) = config_write($config_file, $config);
590
591 # Append our mess of many wide <Directory> sections to the config:
592 #
593 # <Directory ~/a>
594 # Umask 066 077
595 # </Directory>
596 #
597 # <Directory ~/b>
598 # Umask 066 077
599 # </Directory>
600
601 my $target_dir;
602
603 if (open(my $fh, ">> $config_file")) {
604 my $count = 1000;
605 print STDOUT "# Creating $count subdirectories\n";
606
607 my $namelen = 3;
608
609 for (my $i = 0; $i < $count; $i++) {
610 $target_dir = make_name($namelen, 1);
611 my $dir = File::Spec->rel2abs("$tmpdir/$target_dir");
612 mkpath($dir);
613
614 print $fh <<EOD;
615 <Directory ~/$target_dir>
616 Umask 066 077
617 </Directory>
618 EOD
619 }
620
621 unless (close($fh)) {
622 die("Can't write $config_file: $!");
623 }
624
625 } else {
626 die("Can't open $config_file: $!");
627 }
628
629 # To test the worst-case scenario, the target directory (to which we will
630 # write a file) should be the _last_ in the list.
631
632 # Open pipes, for use between the parent and child processes. Specifically,
633 # the child will indicate when it's done with its test by writing a message
634 # to the parent.
635 my ($rfh, $wfh);
636 unless (pipe($rfh, $wfh)) {
637 die("Can't open pipe: $!");
638 }
639
640 my $ex;
641
642 # Fork child
643 $self->handle_sigchld();
644 defined(my $pid = fork()) or die("Can't fork: $!");
645 if ($pid) {
646 eval {
647 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, undef,
648 $timeout);
649
650 # Make sure the underlying Net::FTP uses our long timeout
651 my $old_timeout = $client->{ftp}->timeout($timeout);
652
653 my $start_login = [gettimeofday()];
654 $client->login($user, $passwd, $timeout);
655 my $login_elapsed = tv_interval($start_login);
656 print STDOUT "# Login elapsed: ", Dumper($login_elapsed);
657
658 my ($resp_code, $resp_msg);
659
660 my $start_upload = [gettimeofday()];
661
662 my $conn = $client->stor_raw("$target_dir/test.txt");
663 unless ($conn) {
664 die("Failed to STOR $target_dir/test.txt: " . $client->response_code() .
665 " " . $client->response_msg());
666 }
667
668 my $upload_elapsed = tv_interval($start_upload);
669 print STDOUT "# Upload elapsed: ", Dumper($upload_elapsed);
670
671 $conn->close();
672
673 $resp_code = $client->response_code();
674 $resp_msg = $client->response_msg();
675
676 $client->quit();
677
678 my $expected;
679
680 $expected = 226;
681 $self->assert($expected == $resp_code,
682 test_msg("Expected '$expected', got '$resp_code'"));
683
684 $expected = "Transfer complete";
685 $self->assert($expected eq $resp_msg,
686 test_msg("Expected '$expected', got '$resp_msg'"));
687 };
688
689 if ($@) {
690 $ex = $@;
691 }
692
693 $wfh->print("done\n");
694 $wfh->flush();
695
696 } else {
697 eval { server_wait($config_file, $rfh, $timeout + 5) };
698 if ($@) {
699 warn($@);
700 exit 1;
701 }
702
703 exit 0;
704 }
705
706 # Stop server
707 server_stop($pid_file);
708
709 $self->assert_child_ok($pid);
710
711 if ($ex) {
712 die($ex);
713 }
714
715 unlink($log_file);
716 }
717
718 sub dir_lookup_deep_layout_rel_paths {
719 my $self = shift;
720 my $tmpdir = $self->{tmpdir};
721
722 my $config_file = "$tmpdir/dir.conf";
723 my $pid_file = File::Spec->rel2abs("$tmpdir/dir.pid");
724 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/dir.scoreboard");
725
726 my $log_file = File::Spec->rel2abs('tests.log');
727
728 my $auth_user_file = File::Spec->rel2abs("$tmpdir/dir.passwd");
729 my $auth_group_file = File::Spec->rel2abs("$tmpdir/dir.group");
730
731 my $user = 'proftpd';
732 my $passwd = 'test';
733 my $home_dir = File::Spec->rel2abs($tmpdir);
734 my $uid = 500;
735 my $gid = 500;
736
737 # Make sure that, if we're running as root, that the home directory has
738 # permissions/privs set for the account we create
739 if ($< == 0) {
740 unless (chmod(0755, $home_dir)) {
741 die("Can't set perms on $home_dir to 0755: $!");
742 }
743
744 unless (chown($uid, $gid, $home_dir)) {
745 die("Can't set owner of $home_dir to $uid/$gid: $!");
746 }
747 }
748
749 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
750 '/bin/bash');
751 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
752
753 my $timeout = 300;
754
755 my $config = {
756 PidFile => $pid_file,
757 ScoreboardFile => $scoreboard_file,
758 SystemLog => $log_file,
759 TraceLog => $log_file,
760 Trace => 'DEFAULT:10 auth:0 config:0 directory:10 fsio:0 lock:0',
761
762 AuthUserFile => $auth_user_file,
763 AuthGroupFile => $auth_group_file,
764
765 AllowOverwrite => 'on',
766 CommandBufferSize => 1024,
767 TimeoutIdle => $timeout,
768 TimeoutLogin => $timeout,
769
770 Directory => {
771 '/' => {
772 Umask => '066 077',
773 },
774 },
775
776 IfModules => {
777 'mod_delay.c' => {
778 DelayEngine => 'off',
779 },
780 },
781 };
782
783 my ($port, $config_user, $config_group) = config_write($config_file, $config);
784
785 # Append our mess of many deep <Directory> sections to the config:
786 #
787 # <Directory ~/a>
788 # Umask 066 077
789 # </Directory>
790 #
791 # <Directory ~/a/b>
792 # Umask 066 077
793 # </Directory>
794
795 my $target_dir;
796 if (open(my $fh, ">> $config_file")) {
797 my $count = 256 - length($home_dir);
798 print STDOUT "# Creating $count subdirectories\n";
799
800 $target_dir = File::Spec->rel2abs("$tmpdir/" . make_name(1, 1));
801
802 for (my $i = 0; $i < $count; $i++) {
803 $target_dir = File::Spec->catdir($target_dir, make_name(1, 1));
804 my $dir = File::Spec->rel2abs($target_dir);
805 mkpath($dir);
806
807 print $fh <<EOD;
808 <Directory ~/$target_dir>
809 Umask 066 077
810 </Directory>
811 EOD
812 }
813
814 unless (close($fh)) {
815 die("Can't write $config_file: $!");
816 }
817
818 } else {
819 die("Can't open $config_file: $!");
820 }
821
822 # To test the worst-case scenario, the target directory (to which we will
823 # write a file) should be the _last_ in the list.
824
825 print STDOUT "# target_dir: $target_dir\n";
826
827 # Open pipes, for use between the parent and child processes. Specifically,
828 # the child will indicate when it's done with its test by writing a message
829 # to the parent.
830 my ($rfh, $wfh);
831 unless (pipe($rfh, $wfh)) {
832 die("Can't open pipe: $!");
833 }
834
835 my $ex;
836
837 # Fork child
838 $self->handle_sigchld();
839 defined(my $pid = fork()) or die("Can't fork: $!");
840 if ($pid) {
841 eval {
842 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, undef,
843 $timeout);
844
845 # Make sure the underlying Net::FTP uses our long timeout
846 my $old_timeout = $client->{ftp}->timeout($timeout);
847
848 my $start_login = [gettimeofday()];
849 $client->login($user, $passwd, $timeout);
850 my $login_elapsed = tv_interval($start_login);
851 print STDOUT "# Login elapsed: ", Dumper($login_elapsed);
852
853 my ($resp_code, $resp_msg);
854
855 my $start_upload = [gettimeofday()];
856
857 my $conn = $client->stor_raw("$target_dir/test.txt");
858 unless ($conn) {
859 die("Failed to STOR $target_dir/test.txt: " . $client->response_code() .
860 " " . $client->response_msg());
861 }
862
863 my $upload_elapsed = tv_interval($start_upload);
864 print STDOUT "# Upload elapsed: ", Dumper($upload_elapsed);
865
866 $conn->close();
867
868 $resp_code = $client->response_code();
869 $resp_msg = $client->response_msg();
870
871 $client->quit();
872
873 my $expected;
874
875 $expected = 226;
876 $self->assert($expected == $resp_code,
877 test_msg("Expected '$expected', got '$resp_code'"));
878
879 $expected = "Transfer complete";
880 $self->assert($expected eq $resp_msg,
881 test_msg("Expected '$expected', got '$resp_msg'"));
882 };
883
884 if ($@) {
885 $ex = $@;
886 }
887
888 $wfh->print("done\n");
889 $wfh->flush();
890
891 } else {
892 eval { server_wait($config_file, $rfh, $timeout + 5) };
893 if ($@) {
894 warn($@);
895 exit 1;
896 }
897
898 exit 0;
899 }
900
901 # Stop server
902 server_stop($pid_file);
903
904 $self->assert_child_ok($pid);
905
906 if ($ex) {
907 die($ex);
908 }
909
910 unlink($log_file);
911 }
912
913 sub dir_lookup_many_files_hidefiles_bug3526 {
914 my $self = shift;
915 my $tmpdir = $self->{tmpdir};
916
917 my $config_file = "$tmpdir/dir.conf";
918 my $pid_file = File::Spec->rel2abs("$tmpdir/dir.pid");
919 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/dir.scoreboard");
920
921 my $log_file = File::Spec->rel2abs('tests.log');
922
923 my $auth_user_file = File::Spec->rel2abs("$tmpdir/dir.passwd");
924 my $auth_group_file = File::Spec->rel2abs("$tmpdir/dir.group");
925
926 my $user = 'proftpd';
927 my $passwd = 'test';
928 my $home_dir = File::Spec->rel2abs($tmpdir);
929 my $uid = 500;
930 my $gid = 500;
931
932 # Make sure that, if we're running as root, that the home directory has
933 # permissions/privs set for the account we create
934 if ($< == 0) {
935 unless (chmod(0755, $home_dir)) {
936 die("Can't set perms on $home_dir to 0755: $!");
937 }
938
939 unless (chown($uid, $gid, $home_dir)) {
940 die("Can't set owner of $home_dir to $uid/$gid: $!");
941 }
942 }
943
944 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
945 '/bin/bash');
946 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
947
948 my $timeout = 300;
949
950 my $config = {
951 PidFile => $pid_file,
952 ScoreboardFile => $scoreboard_file,
953 SystemLog => $log_file,
954 TraceLog => $log_file,
955 Trace => 'DEFAULT:10 auth:0 config:0 directory:10 fsio:10 lock:0 ftpaccess:10',
956
957 AuthUserFile => $auth_user_file,
958 AuthGroupFile => $auth_group_file,
959
960 AllowOverride => 'on',
961 TimeoutIdle => $timeout,
962 TimeoutLogin => $timeout,
963
964 Directory => {
965 '/' => {
966 Umask => '066 077',
967 },
968 },
969
970 IfModules => {
971 'mod_delay.c' => {
972 DelayEngine => 'off',
973 },
974 },
975 };
976
977 my ($port, $config_user, $config_group) = config_write($config_file, $config);
978
979 # Create 1500 files in the target directory.
980
981 my $count = 1500;
982 print STDOUT "# Creating $count files\n";
983
984 my $test_dir = File::Spec->rel2abs("$tmpdir/" . make_name(1, 1));
985 mkpath($test_dir);
986
987 for (my $i = 0; $i < $count; $i++) {
988 my $test_file = File::Spec->rel2abs(File::Spec->catdir($test_dir,
989 make_name(5, 1)));
990 $test_file .= ".txt";
991
992 if (open(my $fh, "> $test_file")) {
993 close($fh);
994
995 } else {
996 die("Can't open $test_file: $!");
997 }
998 }
999
1000 # Create a .ftpaccess file in the test directory with a simple HideFiles
1001 # pattern.
1002 my $ftpaccess_file = File::Spec->rel2abs("$test_dir/.ftpaccess");
1003 if (open(my $fh, "> $ftpaccess_file")) {
1004 print $fh <<EOC;
1005 HideFiles ^\\.
1006 EOC
1007
1008 unless (close($fh)) {
1009 die("Can't write $ftpaccess_file: $!");
1010 }
1011
1012 } else {
1013 die("Can't open $ftpaccess_file: $!");
1014 }
1015
1016 # Open pipes, for use between the parent and child processes. Specifically,
1017 # the child will indicate when it's done with its test by writing a message
1018 # to the parent.
1019 my ($rfh, $wfh);
1020 unless (pipe($rfh, $wfh)) {
1021 die("Can't open pipe: $!");
1022 }
1023
1024 my $ex;
1025
1026 # Fork child
1027 $self->handle_sigchld();
1028 defined(my $pid = fork()) or die("Can't fork: $!");
1029 if ($pid) {
1030 eval {
1031 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, undef,
1032 $timeout);
1033
1034 # Make sure the underlying Net::FTP uses our long timeout
1035 my $old_timeout = $client->{ftp}->timeout($timeout);
1036
1037 my $start_login = [gettimeofday()];
1038 $client->login($user, $passwd, $timeout);
1039 my $login_elapsed = tv_interval($start_login);
1040 print STDOUT "# Login elapsed: ", Dumper($login_elapsed);
1041
1042 $client->cwd($test_dir);
1043
1044 my ($resp_code, $resp_msg);
1045
1046 my $nlst_start = [gettimeofday()];
1047
1048 my $conn = $client->nlst_raw($test_dir);
1049 unless ($conn) {
1050 die("Failed to NLST $test_dir: " . $client->response_code() .
1051 " " . $client->response_msg());
1052 }
1053
1054 my $buf;
1055 while ($conn->read($buf, 8192, $timeout)) {
1056 if ($ENV{TEST_VERBOSE}) {
1057 print STDERR "recvd: $buf\n";
1058 }
1059 }
1060
1061 $conn->close();
1062
1063 my $nlst_elapsed = tv_interval($nlst_start);
1064 print STDOUT "# NLST elapsed: ", Dumper($nlst_elapsed);
1065
1066 $resp_code = $client->response_code();
1067 $resp_msg = $client->response_msg();
1068
1069 $client->quit();
1070
1071 my $expected;
1072
1073 $expected = 226;
1074 $self->assert($expected == $resp_code,
1075 test_msg("Expected '$expected', got '$resp_code'"));
1076
1077 $expected = "Transfer complete";
1078 $self->assert($expected eq $resp_msg,
1079 test_msg("Expected '$expected', got '$resp_msg'"));
1080 };
1081
1082 if ($@) {
1083 $ex = $@;
1084 }
1085
1086 $wfh->print("done\n");
1087 $wfh->flush();
1088
1089 } else {
1090 eval { server_wait($config_file, $rfh, $timeout + 5) };
1091 if ($@) {
1092 warn($@);
1093 exit 1;
1094 }
1095
1096 exit 0;
1097 }
1098
1099 # Stop server
1100 server_stop($pid_file);
1101
1102 $self->assert_child_ok($pid);
1103
1104 if ($ex) {
1105 die($ex);
1106 }
1107
1108 unlink($log_file);
1109 }
1110
1111 1;