Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::ListOptions;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Path qw(mkpath);
8 use File::Spec;
9 use IO::Handle;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 my $TESTS = {
19 listoptions_opt_t => {
20 order => ++$order,
21 test_class => [qw(forking)],
22 },
23
24 listoptions_opt_1_list => {
25 order => ++$order,
26 test_class => [qw(bug forking)],
27 },
28
29 listoptions_opt_1_nlst => {
30 order => ++$order,
31 test_class => [qw(bug forking)],
32 },
33
34 listoptions_opt_1_nlst_simple_glob => {
35 order => ++$order,
36 test_class => [qw(bug forking)],
37 },
38
39 listoptions_opt_1_nlst_complex_glob => {
40 order => ++$order,
41 test_class => [qw(bug forking rootprivs)],
42 },
43
44 listoptions_listonly => {
45 order => ++$order,
46 test_class => [qw(bug forking)],
47 },
48
49 listoptions_nlstonly => {
50 order => ++$order,
51 test_class => [qw(bug forking)],
52 },
53
54 listoptions_sortednlst_bug4267 => {
55 order => ++$order,
56 test_class => [qw(bug forking)],
57 },
58
59 listoptions_maxfiles => {
60 order => ++$order,
61 test_class => [qw(forking slow)],
62 },
63
64 listoptions_nlstnamesonly_issue251 => {
65 order => ++$order,
66 test_class => [qw(bug forking)],
67 },
68
69 };
70
71 sub new {
72 return shift()->SUPER::new(@_);
73 }
74
75 sub list_tests {
76 return testsuite_get_runnable_tests($TESTS);
77 }
78
79 sub listoptions_opt_t {
80 my $self = shift;
81 my $tmpdir = $self->{tmpdir};
82
83 my $config_file = "$tmpdir/config.conf";
84 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
85 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
86
87 my $log_file = test_get_logfile();
88
89 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
90 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
91
92 my $user = 'proftpd';
93 my $passwd = 'test';
94 my $group = 'ftpd';
95 my $home_dir = File::Spec->rel2abs($tmpdir);
96 my $uid = 500;
97 my $gid = 500;
98
99 # Make sure that, if we're running as root, that the home directory has
100 # permissions/privs set for the account we create
101 if ($< == 0) {
102 unless (chmod(0755, $home_dir)) {
103 die("Can't set perms on $home_dir to 0755: $!");
104 }
105
106 unless (chown($uid, $gid, $home_dir)) {
107 die("Can't set owner of $home_dir to $uid/$gid: $!");
108 }
109 }
110
111 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
112 '/bin/bash');
113 auth_group_write($auth_group_file, $group, $gid, $user);
114
115 # Create three files, and use utime() to modify the last-mod time of
116 # each.
117 my $test_files = [qw(
118 a.txt
119 b.txt
120 c.txt
121 d.txt
122 e.txt
123 f.txt
124 g.txt
125 h.txt
126 i.txt
127 )];
128
129 my $count = scalar(@$test_files);
130 foreach my $test_file (sort { $a cmp $b } @$test_files) {
131 $count--;
132
133 my $path = File::Spec->rel2abs("$tmpdir/$test_file");
134 if (open(my $fh, "> $path")) {
135 print $fh "Hello, World!\n";
136 unless (close($fh)) {
137 die("Can't write $path: $!");
138 }
139
140 my $mtime = (time() - ($count * 10));
141 unless (utime(undef, $mtime, $path)) {
142 die("Can't change mtime for $path: $!");
143 }
144
145 } else {
146 die("Can't open $path: $!");
147 }
148 }
149
150 my $config = {
151 PidFile => $pid_file,
152 ScoreboardFile => $scoreboard_file,
153 SystemLog => $log_file,
154
155 AuthUserFile => $auth_user_file,
156 AuthGroupFile => $auth_group_file,
157 AuthOrder => 'mod_auth_file.c',
158
159 ListOptions => '-t',
160
161 IfModules => {
162 'mod_delay.c' => {
163 DelayEngine => 'off',
164 },
165 },
166 };
167
168 my ($port, $config_user, $config_group) = config_write($config_file, $config);
169
170 # Open pipes, for use between the parent and child processes. Specifically,
171 # the child will indicate when it's done with its test by writing a message
172 # to the parent.
173 my ($rfh, $wfh);
174 unless (pipe($rfh, $wfh)) {
175 die("Can't open pipe: $!");
176 }
177
178 my $ex;
179
180 # Fork child
181 $self->handle_sigchld();
182 defined(my $pid = fork()) or die("Can't fork: $!");
183 if ($pid) {
184 eval {
185 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
186 $client->login($user, $passwd);
187
188 my $conn = $client->list_raw("*.txt");
189 unless ($conn) {
190 die("Failed to LIST: " . $client->response_code() . " " .
191 $client->response_msg());
192 }
193
194 my $buf = '';
195 my $tmp;
196 while ($conn->read($tmp, 8192, 25)) {
197 $buf .= $tmp;
198 }
199 eval { $conn->close() };
200
201 my $resp_code = $client->response_code();
202 my $resp_msg = $client->response_msg();
203
204 my $expected;
205
206 $expected = 226;
207 $self->assert($expected == $resp_code,
208 test_msg("Expected $expected, got $resp_code"));
209
210 $expected = "Transfer complete";
211 $self->assert($expected eq $resp_msg,
212 test_msg("Expected '$expected', got '$resp_msg'"));
213
214 $client->quit();
215
216 # We have to be careful of the fact that readdir returns directory
217 # entries in an unordered fashion.
218 my $res = [];
219 my $lines = [split(/\n/, $buf)];
220 foreach my $line (@$lines) {
221 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
222 push(@$res, $1);
223 }
224 }
225
226 $expected = [reverse(@$test_files)];
227
228 my $nexpected = scalar(@$expected);
229 my $nres = scalar(@$res);
230
231 $self->assert($nexpected == $nres,
232 test_msg("Expected $nexpected items, got $nres"));
233 for (my $i = 0; $i < $nexpected; $i++) {
234 $self->assert($expected->[$i] eq $res->[$i],
235 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
236 }
237 };
238
239 if ($@) {
240 $ex = $@;
241 }
242
243 $wfh->print("done\n");
244 $wfh->flush();
245
246 } else {
247 eval { server_wait($config_file, $rfh) };
248 if ($@) {
249 warn($@);
250 exit 1;
251 }
252
253 exit 0;
254 }
255
256 # Stop server
257 server_stop($pid_file);
258
259 $self->assert_child_ok($pid);
260
261 if ($ex) {
262 test_append_logfile($log_file, $ex);
263 unlink($log_file);
264
265 die($ex);
266 }
267
268 unlink($log_file);
269 }
270
271 sub listoptions_opt_1_list {
272 my $self = shift;
273 my $tmpdir = $self->{tmpdir};
274 my $setup = test_setup($tmpdir, 'config');
275
276 my $test_files = [qw(
277 a.txt
278 b.txt
279 c.txt
280 d.txt
281 e.txt
282 f.txt
283 g.txt
284 h.txt
285 i.txt
286 )];
287
288 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
289 mkpath($test_dir);
290
291 my $count = scalar(@$test_files);
292 foreach my $test_file (@$test_files) {
293 my $path = File::Spec->rel2abs("$test_dir/$test_file");
294 if (open(my $fh, "> $path")) {
295 print $fh "Hello, World!\n";
296 unless (close($fh)) {
297 die("Can't write $path: $!");
298 }
299
300 } else {
301 die("Can't open $path: $!");
302 }
303 }
304
305 my $config = {
306 PidFile => $setup->{pid_file},
307 ScoreboardFile => $setup->{scoreboard_file},
308 SystemLog => $setup->{log_file},
309
310 AuthUserFile => $setup->{auth_user_file},
311 AuthGroupFile => $setup->{auth_group_file},
312 AuthOrder => 'mod_auth_file.c',
313
314 ListOptions => '"-A -1" strict',
315
316 IfModules => {
317 'mod_delay.c' => {
318 DelayEngine => 'off',
319 },
320 },
321 };
322
323 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
324 $config);
325
326 # Open pipes, for use between the parent and child processes. Specifically,
327 # the child will indicate when it's done with its test by writing a message
328 # to the parent.
329 my ($rfh, $wfh);
330 unless (pipe($rfh, $wfh)) {
331 die("Can't open pipe: $!");
332 }
333
334 my $ex;
335
336 # Fork child
337 $self->handle_sigchld();
338 defined(my $pid = fork()) or die("Can't fork: $!");
339 if ($pid) {
340 eval {
341 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
342 $client->login($setup->{user}, $setup->{passwd});
343
344 my $conn = $client->list_raw('test.d');
345 unless ($conn) {
346 die("Failed to LIST: " . $client->response_code() . " " .
347 $client->response_msg());
348 }
349
350 my $buf;
351 $conn->read($buf, 16384, 25);
352 eval { $conn->close() };
353
354 my $resp_code = $client->response_code();
355 my $resp_msg = $client->response_msg();
356 $self->assert_transfer_ok($resp_code, $resp_msg);
357
358 $client->quit();
359
360 if ($ENV{TEST_VERBOSE}) {
361 print STDERR "Data:\n$buf\n";
362 }
363
364 # We have to be careful of the fact that readdir returns directory
365 # entries in an unordered fashion.
366 my $res = [];
367 my $lines = [split(/\n/, $buf)];
368 foreach my $line (@$lines) {
369 push(@$res, $line);
370 }
371
372 my $expected = [@$test_files];
373 my $nexpected = scalar(@$expected);
374 my $nres = scalar(@$res);
375
376 $self->assert($nexpected == $nres,
377 "Expected $nexpected items, got $nres");
378 for (my $i = 0; $i < $nexpected; $i++) {
379 $self->assert($expected->[$i] eq $res->[$i],
380 "Expected '$expected->[$i]' at index $i, got '$res->[$i]'");
381 }
382 };
383 if ($@) {
384 $ex = $@;
385 }
386
387 $wfh->print("done\n");
388 $wfh->flush();
389
390 } else {
391 eval { server_wait($setup->{config_file}, $rfh) };
392 if ($@) {
393 warn($@);
394 exit 1;
395 }
396
397 exit 0;
398 }
399
400 # Stop server
401 server_stop($setup->{pid_file});
402 $self->assert_child_ok($pid);
403
404 test_cleanup($setup->{log_file}, $ex);
405 }
406
407 sub listoptions_opt_1_nlst {
408 my $self = shift;
409 my $tmpdir = $self->{tmpdir};
410 my $setup = test_setup($tmpdir, 'config');
411
412 my $test_files = [qw(
413 a.txt
414 b.txt
415 c.txt
416 d.txt
417 e.txt
418 f.txt
419 g.txt
420 h.txt
421 i.txt
422 )];
423
424 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
425 mkpath($test_dir);
426
427 my $count = scalar(@$test_files);
428 foreach my $test_file (@$test_files) {
429 my $path = File::Spec->rel2abs("$test_dir/$test_file");
430 if (open(my $fh, "> $path")) {
431 print $fh "Hello, World!\n";
432 unless (close($fh)) {
433 die("Can't write $path: $!");
434 }
435
436 } else {
437 die("Can't open $path: $!");
438 }
439 }
440
441 my $config = {
442 PidFile => $setup->{pid_file},
443 ScoreboardFile => $setup->{scoreboard_file},
444 SystemLog => $setup->{log_file},
445
446 AuthUserFile => $setup->{auth_user_file},
447 AuthGroupFile => $setup->{auth_group_file},
448 AuthOrder => 'mod_auth_file.c',
449
450 ListOptions => '"-A -1" strict',
451
452 IfModules => {
453 'mod_delay.c' => {
454 DelayEngine => 'off',
455 },
456 },
457 };
458
459 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
460 $config);
461
462 # Open pipes, for use between the parent and child processes. Specifically,
463 # the child will indicate when it's done with its test by writing a message
464 # to the parent.
465 my ($rfh, $wfh);
466 unless (pipe($rfh, $wfh)) {
467 die("Can't open pipe: $!");
468 }
469
470 my $ex;
471
472 # Fork child
473 $self->handle_sigchld();
474 defined(my $pid = fork()) or die("Can't fork: $!");
475 if ($pid) {
476 eval {
477 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
478 $client->login($setup->{user}, $setup->{passwd});
479
480 my $conn = $client->nlst_raw('test.d');
481 unless ($conn) {
482 die("Failed to NLST: " . $client->response_code() . " " .
483 $client->response_msg());
484 }
485
486 my $buf;
487 $conn->read($buf, 16384, 25);
488 eval { $conn->close() };
489
490 my $resp_code = $client->response_code();
491 my $resp_msg = $client->response_msg();
492 $self->assert_transfer_ok($resp_code, $resp_msg);
493
494 $client->quit();
495
496 if ($ENV{TEST_VERBOSE}) {
497 print STDERR "Data:\n$buf\n";
498 }
499
500 # We have to be careful of the fact that readdir returns directory
501 # entries in an unordered fashion.
502 my $res = [];
503 my $lines = [split(/\n/, $buf)];
504 foreach my $line (@$lines) {
505 push(@$res, $line);
506 }
507
508 # Sort the results, so that they match the expected list.
509 $res = [sort { $a cmp $b } @$res];
510
511 my $expected = [@$test_files];
512 my $nexpected = scalar(@$expected);
513 my $nres = scalar(@$res);
514
515 $self->assert($nexpected == $nres,
516 "Expected $nexpected items, got $nres");
517
518 for (my $i = 0; $i < $nexpected; $i++) {
519 $self->assert($expected->[$i] eq $res->[$i],
520 "Expected '$expected->[$i]' at index $i, got '$res->[$i]'");
521 }
522 };
523 if ($@) {
524 $ex = $@;
525 }
526
527 $wfh->print("done\n");
528 $wfh->flush();
529
530 } else {
531 eval { server_wait($setup->{config_file}, $rfh) };
532 if ($@) {
533 warn($@);
534 exit 1;
535 }
536
537 exit 0;
538 }
539
540 # Stop server
541 server_stop($setup->{pid_file});
542 $self->assert_child_ok($pid);
543
544 test_cleanup($setup->{log_file}, $ex);
545 }
546
547 sub listoptions_opt_1_nlst_simple_glob {
548 my $self = shift;
549 my $tmpdir = $self->{tmpdir};
550
551 my $config_file = "$tmpdir/config.conf";
552 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
553 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
554
555 my $log_file = test_get_logfile();
556
557 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
558 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
559
560 my $user = 'proftpd';
561 my $passwd = 'test';
562 my $group = 'ftpd';
563 my $home_dir = File::Spec->rel2abs($tmpdir);
564 my $uid = 500;
565 my $gid = 500;
566
567 # Make sure that, if we're running as root, that the home directory has
568 # permissions/privs set for the account we create
569 if ($< == 0) {
570 unless (chmod(0755, $home_dir)) {
571 die("Can't set perms on $home_dir to 0755: $!");
572 }
573
574 unless (chown($uid, $gid, $home_dir)) {
575 die("Can't set owner of $home_dir to $uid/$gid: $!");
576 }
577 }
578
579 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
580 '/bin/bash');
581 auth_group_write($auth_group_file, $group, $gid, $user);
582
583 my $test_files = [qw(
584 a.txt
585 b.txt
586 c.txt
587 d.txt
588 e.txt
589 f.txt
590 g.txt
591 h.txt
592 i.txt
593 )];
594
595 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
596 mkpath($test_dir);
597
598 my $count = scalar(@$test_files);
599 foreach my $test_file (@$test_files) {
600 my $path = File::Spec->rel2abs("$test_dir/$test_file");
601 if (open(my $fh, "> $path")) {
602 print $fh "Hello, World!\n";
603 unless (close($fh)) {
604 die("Can't write $path: $!");
605 }
606
607 } else {
608 die("Can't open $path: $!");
609 }
610 }
611
612 my $config = {
613 PidFile => $pid_file,
614 ScoreboardFile => $scoreboard_file,
615 SystemLog => $log_file,
616
617 AuthUserFile => $auth_user_file,
618 AuthGroupFile => $auth_group_file,
619 AuthOrder => 'mod_auth_file.c',
620
621 ListOptions => '"-A -1" strict',
622
623 IfModules => {
624 'mod_delay.c' => {
625 DelayEngine => 'off',
626 },
627 },
628 };
629
630 my ($port, $config_user, $config_group) = config_write($config_file, $config);
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);
648 $client->login($user, $passwd);
649
650 my $conn = $client->nlst_raw('test.d/*');
651 unless ($conn) {
652 die("Failed to NLST: " . $client->response_code() . " " .
653 $client->response_msg());
654 }
655
656 my $buf;
657 $conn->read($buf, 16384, 25);
658 eval { $conn->close() };
659
660 my $resp_code = $client->response_code();
661 my $resp_msg = $client->response_msg();
662 $client->quit();
663
664 $self->assert_transfer_ok($resp_code, $resp_msg);
665
666 # We have to be careful of the fact that readdir returns directory
667 # entries in an unordered fashion.
668 my $res = [];
669 my $lines = [split(/\n/, $buf)];
670 foreach my $line (@$lines) {
671 push(@$res, $line);
672 }
673
674 # Sort the results, so that they match the expected list.
675 $res = [sort { $a cmp $b } @$res];
676
677 my $expected = [@$test_files];
678 my $nexpected = scalar(@$expected);
679 my $nres = scalar(@$res);
680
681 $self->assert($nexpected == $nres,
682 test_msg("Expected $nexpected items, got $nres"));
683
684 for (my $i = 0; $i < $nexpected; $i++) {
685 $self->assert($expected->[$i] eq $res->[$i],
686 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
687 }
688 };
689
690 if ($@) {
691 $ex = $@;
692 }
693
694 $wfh->print("done\n");
695 $wfh->flush();
696
697 } else {
698 eval { server_wait($config_file, $rfh) };
699 if ($@) {
700 warn($@);
701 exit 1;
702 }
703
704 exit 0;
705 }
706
707 # Stop server
708 server_stop($pid_file);
709
710 $self->assert_child_ok($pid);
711
712 if ($ex) {
713 test_append_logfile($log_file, $ex);
714 unlink($log_file);
715
716 die($ex);
717 }
718
719 unlink($log_file);
720 }
721
722 sub listoptions_opt_1_nlst_complex_glob {
723 my $self = shift;
724 my $tmpdir = $self->{tmpdir};
725
726 my $config_file = "$tmpdir/config.conf";
727 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
728 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
729
730 my $log_file = test_get_logfile();
731
732 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
733 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
734
735 my $user = 'proftpd';
736 my $passwd = 'test';
737 my $group = 'ftpd';
738 my $home_dir = File::Spec->rel2abs($tmpdir);
739 my $uid = 500;
740 my $gid = 500;
741
742 # Make sure that, if we're running as root, that the home directory has
743 # permissions/privs set for the account we create
744 if ($< == 0) {
745 unless (chmod(0755, $home_dir)) {
746 die("Can't set perms on $home_dir to 0755: $!");
747 }
748
749 unless (chown($uid, $gid, $home_dir)) {
750 die("Can't set owner of $home_dir to $uid/$gid: $!");
751 }
752 }
753
754 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
755 '/bin/bash');
756 auth_group_write($auth_group_file, $group, $gid, $user);
757
758 my $test_files = [qw(
759 2a-a.txt
760 2b-b.txt
761 2c-c.txt
762 2d-d.txt
763 2e-e.txt
764 2f-f.txt
765 2g-g.txt
766 2h-h.txt
767 2i-i.txt
768 )];
769
770 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d/sub.d");
771 mkpath($test_dir);
772
773 my $count = scalar(@$test_files);
774 foreach my $test_file (@$test_files) {
775 my $path = File::Spec->rel2abs("$test_dir/$test_file");
776 if (open(my $fh, "> $path")) {
777 print $fh "Hello, World!\n";
778 unless (close($fh)) {
779 die("Can't write $path: $!");
780 }
781
782 } else {
783 die("Can't open $path: $!");
784 }
785 }
786
787 my $config = {
788 PidFile => $pid_file,
789 ScoreboardFile => $scoreboard_file,
790 SystemLog => $log_file,
791
792 AuthUserFile => $auth_user_file,
793 AuthGroupFile => $auth_group_file,
794 AuthOrder => 'mod_auth_file.c',
795
796 DefaultRoot => '~',
797 ListOptions => '"-A -1" strict',
798
799 IfModules => {
800 'mod_delay.c' => {
801 DelayEngine => 'off',
802 },
803 },
804 };
805
806 my ($port, $config_user, $config_group) = config_write($config_file, $config);
807
808 # Open pipes, for use between the parent and child processes. Specifically,
809 # the child will indicate when it's done with its test by writing a message
810 # to the parent.
811 my ($rfh, $wfh);
812 unless (pipe($rfh, $wfh)) {
813 die("Can't open pipe: $!");
814 }
815
816 my $ex;
817
818 # Fork child
819 $self->handle_sigchld();
820 defined(my $pid = fork()) or die("Can't fork: $!");
821 if ($pid) {
822 eval {
823 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
824 $client->login($user, $passwd);
825
826 my $conn = $client->nlst_raw('/test.d/sub.d/2?-*.txt');
827 unless ($conn) {
828 die("Failed to NLST: " . $client->response_code() . " " .
829 $client->response_msg());
830 }
831
832 my $buf;
833 $conn->read($buf, 16384, 25);
834 eval { $conn->close() };
835
836 my $resp_code = $client->response_code();
837 my $resp_msg = $client->response_msg();
838 $client->quit();
839
840 $self->assert_transfer_ok($resp_code, $resp_msg);
841
842 # We have to be careful of the fact that readdir returns directory
843 # entries in an unordered fashion.
844 my $res = [];
845 my $lines = [split(/\n/, $buf)];
846 foreach my $line (@$lines) {
847 push(@$res, $line);
848 }
849
850 # Sort the results, so that they match the expected list.
851 $res = [sort { $a cmp $b } @$res];
852
853 my $expected = [@$test_files];
854 my $nexpected = scalar(@$expected);
855 my $nres = scalar(@$res);
856
857 $self->assert($nexpected == $nres,
858 test_msg("Expected $nexpected items, got $nres"));
859
860 for (my $i = 0; $i < $nexpected; $i++) {
861 $self->assert($expected->[$i] eq $res->[$i],
862 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
863 }
864 };
865
866 if ($@) {
867 $ex = $@;
868 }
869
870 $wfh->print("done\n");
871 $wfh->flush();
872
873 } else {
874 eval { server_wait($config_file, $rfh) };
875 if ($@) {
876 warn($@);
877 exit 1;
878 }
879
880 exit 0;
881 }
882
883 # Stop server
884 server_stop($pid_file);
885
886 $self->assert_child_ok($pid);
887
888 if ($ex) {
889 test_append_logfile($log_file, $ex);
890 unlink($log_file);
891
892 die($ex);
893 }
894
895 unlink($log_file);
896 }
897
898 sub listoptions_listonly {
899 my $self = shift;
900 my $tmpdir = $self->{tmpdir};
901
902 my $config_file = "$tmpdir/config.conf";
903 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
904 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
905
906 my $log_file = test_get_logfile();
907
908 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
909 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
910
911 my $user = 'proftpd';
912 my $passwd = 'test';
913 my $group = 'ftpd';
914 my $home_dir = File::Spec->rel2abs($tmpdir);
915 my $uid = 500;
916 my $gid = 500;
917
918 # Make sure that, if we're running as root, that the home directory has
919 # permissions/privs set for the account we create
920 if ($< == 0) {
921 unless (chmod(0755, $home_dir)) {
922 die("Can't set perms on $home_dir to 0755: $!");
923 }
924
925 unless (chown($uid, $gid, $home_dir)) {
926 die("Can't set owner of $home_dir to $uid/$gid: $!");
927 }
928 }
929
930 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
931 '/bin/bash');
932 auth_group_write($auth_group_file, $group, $gid, $user);
933
934 my $test_files = [qw(
935 a.txt
936 b.txt
937 c.txt
938 d.txt
939 e.txt
940 f.txt
941 g.txt
942 h.txt
943 i.txt
944 )];
945
946 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
947 mkpath($test_dir);
948
949 my $count = scalar(@$test_files);
950 foreach my $test_file (@$test_files) {
951 my $path = File::Spec->rel2abs("$test_dir/$test_file");
952 if (open(my $fh, "> $path")) {
953 print $fh "Hello, World!\n";
954 unless (close($fh)) {
955 die("Can't write $path: $!");
956 }
957
958 } else {
959 die("Can't open $path: $!");
960 }
961 }
962
963 my $config = {
964 PidFile => $pid_file,
965 ScoreboardFile => $scoreboard_file,
966 SystemLog => $log_file,
967
968 AuthUserFile => $auth_user_file,
969 AuthGroupFile => $auth_group_file,
970 AuthOrder => 'mod_auth_file.c',
971
972 TimeoutLinger => 1,
973 ListOptions => '"-A -1" LISTOnly',
974
975 IfModules => {
976 'mod_delay.c' => {
977 DelayEngine => 'off',
978 },
979 },
980 };
981
982 my ($port, $config_user, $config_group) = config_write($config_file, $config);
983
984 # Open pipes, for use between the parent and child processes. Specifically,
985 # the child will indicate when it's done with its test by writing a message
986 # to the parent.
987 my ($rfh, $wfh);
988 unless (pipe($rfh, $wfh)) {
989 die("Can't open pipe: $!");
990 }
991
992 my $ex;
993
994 # Fork child
995 $self->handle_sigchld();
996 defined(my $pid = fork()) or die("Can't fork: $!");
997 if ($pid) {
998 eval {
999 # First, connect, do a LIST, examine the results
1000 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1001 $client->login($user, $passwd);
1002
1003 # First, do a LIST and see what we get
1004 my $conn = $client->list_raw('test.d');
1005 unless ($conn) {
1006 die("Failed to LIST: " . $client->response_code() . " " .
1007 $client->response_msg());
1008 }
1009
1010 my $buf;
1011 $conn->read($buf, 16384, 25);
1012 eval { $conn->close() };
1013 sleep(2);
1014
1015 my $resp_code = $client->response_code();
1016 my $resp_msg = $client->response_msg();
1017 $self->assert_transfer_ok($resp_code, $resp_msg);
1018 $client->quit();
1019
1020 # We have to be careful of the fact that readdir returns directory
1021 # entries in an unordered fashion.
1022 my $res = [];
1023 my $lines = [split(/\n/, $buf)];
1024 foreach my $line (@$lines) {
1025 push(@$res, $line);
1026 }
1027
1028 my $expected = [@$test_files];
1029 my $nexpected = scalar(@$expected);
1030 my $nres = scalar(@$res);
1031
1032 $self->assert($nexpected == $nres,
1033 test_msg("Expected $nexpected items, got $nres"));
1034 for (my $i = 0; $i < $nexpected; $i++) {
1035 $self->assert($expected->[$i] eq $res->[$i],
1036 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
1037 }
1038
1039 # Next, connect, do a NLST, examine the results
1040 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1041 $client->login($user, $passwd);
1042
1043 $conn = $client->nlst_raw('test.d');
1044 unless ($conn) {
1045 die("Failed to NLST: " . $client->response_code() . " " .
1046 $client->response_msg());
1047 }
1048
1049 $buf = '';
1050 $conn->read($buf, 16384, 25);
1051 eval { $conn->close() };
1052 sleep(2);
1053
1054 $resp_code = $client->response_code();
1055 $resp_msg = $client->response_msg();
1056 $self->assert_transfer_ok($resp_code, $resp_msg);
1057 $client->quit();
1058
1059 # We have to be careful of the fact that readdir returns directory
1060 # entries in an unordered fashion.
1061 $res = [];
1062 $lines = [split(/\n/, $buf)];
1063 foreach my $line (@$lines) {
1064 push(@$res, $line);
1065 }
1066
1067 # Sort the results, so that they match the expected list.
1068 $res = [sort { $a cmp $b } @$res];
1069
1070 $expected = [map { "test.d/$_" } @$test_files];
1071 $nexpected = scalar(@$expected);
1072 $nres = scalar(@$res);
1073
1074 $self->assert($nexpected == $nres,
1075 test_msg("Expected $nexpected items, got $nres"));
1076 for (my $i = 0; $i < $nexpected; $i++) {
1077 $self->assert($expected->[$i] eq $res->[$i],
1078 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
1079 }
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, 30) };
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 test_append_logfile($log_file, $ex);
1106 unlink($log_file);
1107
1108 die($ex);
1109 }
1110
1111 unlink($log_file);
1112 }
1113
1114 sub listoptions_nlstonly {
1115 my $self = shift;
1116 my $tmpdir = $self->{tmpdir};
1117
1118 my $config_file = "$tmpdir/config.conf";
1119 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1120 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1121
1122 my $log_file = test_get_logfile();
1123
1124 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1125 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1126
1127 my $user = 'proftpd';
1128 my $passwd = 'test';
1129 my $group = 'ftpd';
1130 my $home_dir = File::Spec->rel2abs($tmpdir);
1131 my $uid = 500;
1132 my $gid = 500;
1133
1134 # Make sure that, if we're running as root, that the home directory has
1135 # permissions/privs set for the account we create
1136 if ($< == 0) {
1137 unless (chmod(0755, $home_dir)) {
1138 die("Can't set perms on $home_dir to 0755: $!");
1139 }
1140
1141 unless (chown($uid, $gid, $home_dir)) {
1142 die("Can't set owner of $home_dir to $uid/$gid: $!");
1143 }
1144 }
1145
1146 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1147 '/bin/bash');
1148 auth_group_write($auth_group_file, $group, $gid, $user);
1149
1150 my $test_files = [qw(
1151 a.txt
1152 b.txt
1153 c.txt
1154 d.txt
1155 e.txt
1156 f.txt
1157 g.txt
1158 h.txt
1159 i.txt
1160 )];
1161
1162 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1163 mkpath($test_dir);
1164
1165 my $count = scalar(@$test_files);
1166 foreach my $test_file (@$test_files) {
1167 my $path = File::Spec->rel2abs("$test_dir/$test_file");
1168 if (open(my $fh, "> $path")) {
1169 print $fh "Hello, World!\n";
1170 unless (close($fh)) {
1171 die("Can't write $path: $!");
1172 }
1173
1174 } else {
1175 die("Can't open $path: $!");
1176 }
1177 }
1178
1179 my $config = {
1180 PidFile => $pid_file,
1181 ScoreboardFile => $scoreboard_file,
1182 SystemLog => $log_file,
1183
1184 AuthUserFile => $auth_user_file,
1185 AuthGroupFile => $auth_group_file,
1186 AuthOrder => 'mod_auth_file.c',
1187
1188 TimeoutLinger => 1,
1189 ListOptions => '"-A -1" NLSTOnly',
1190
1191 IfModules => {
1192 'mod_delay.c' => {
1193 DelayEngine => 'off',
1194 },
1195 },
1196 };
1197
1198 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1199
1200 # Open pipes, for use between the parent and child processes. Specifically,
1201 # the child will indicate when it's done with its test by writing a message
1202 # to the parent.
1203 my ($rfh, $wfh);
1204 unless (pipe($rfh, $wfh)) {
1205 die("Can't open pipe: $!");
1206 }
1207
1208 my $ex;
1209
1210 # Fork child
1211 $self->handle_sigchld();
1212 defined(my $pid = fork()) or die("Can't fork: $!");
1213 if ($pid) {
1214 eval {
1215 # First, connect, do a LIST, examine the results
1216 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1217 $client->login($user, $passwd);
1218
1219 # First, do a LIST and see what we get
1220 my $conn = $client->list_raw('test.d');
1221 unless ($conn) {
1222 die("Failed to LIST: " . $client->response_code() . " " .
1223 $client->response_msg());
1224 }
1225
1226 my $buf;
1227 $conn->read($buf, 16384, 25);
1228 eval { $conn->close() };
1229 sleep(2);
1230
1231 my $resp_code = $client->response_code();
1232 my $resp_msg = $client->response_msg();
1233 $self->assert_transfer_ok($resp_code, $resp_msg);
1234 $client->quit();
1235
1236 # We have to be careful of the fact that readdir returns directory
1237 # entries in an unordered fashion.
1238 my $res = [];
1239 my $lines = [split(/\n/, $buf)];
1240 foreach my $line (@$lines) {
1241 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1242 push(@$res, $1);
1243 }
1244 }
1245
1246 my $expected = [@$test_files];
1247 my $nexpected = scalar(@$expected);
1248 my $nres = scalar(@$res);
1249
1250 $self->assert($nexpected == $nres,
1251 test_msg("Expected $nexpected items, got $nres"));
1252 for (my $i = 0; $i < $nexpected; $i++) {
1253 $self->assert($expected->[$i] eq $res->[$i],
1254 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
1255 }
1256
1257 # Next, connect, do a NLST, examine the results
1258 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1259 $client->login($user, $passwd);
1260
1261 $conn = $client->nlst_raw('test.d');
1262 unless ($conn) {
1263 die("Failed to NLST: " . $client->response_code() . " " .
1264 $client->response_msg());
1265 }
1266
1267 $buf = '';
1268 $conn->read($buf, 16384, 25);
1269 eval { $conn->close() };
1270 sleep(2);
1271
1272 $resp_code = $client->response_code();
1273 $resp_msg = $client->response_msg();
1274 $self->assert_transfer_ok($resp_code, $resp_msg);
1275 $client->quit();
1276
1277 # We have to be careful of the fact that readdir returns directory
1278 # entries in an unordered fashion.
1279 $res = [];
1280 $lines = [split(/\n/, $buf)];
1281 foreach my $line (@$lines) {
1282 push(@$res, $line);
1283 }
1284
1285 # Sort the results, so that they match the expected list.
1286 $res = [sort { $a cmp $b } @$res];
1287
1288 $expected = [@$test_files];
1289 $nexpected = scalar(@$expected);
1290 $nres = scalar(@$res);
1291
1292 $self->assert($nexpected == $nres,
1293 test_msg("Expected $nexpected items, got $nres"));
1294 for (my $i = 0; $i < $nexpected; $i++) {
1295 $self->assert($expected->[$i] eq $res->[$i],
1296 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
1297 }
1298 };
1299
1300 if ($@) {
1301 $ex = $@;
1302 }
1303
1304 $wfh->print("done\n");
1305 $wfh->flush();
1306
1307 } else {
1308 eval { server_wait($config_file, $rfh, 30) };
1309 if ($@) {
1310 warn($@);
1311 exit 1;
1312 }
1313
1314 exit 0;
1315 }
1316
1317 # Stop server
1318 server_stop($pid_file);
1319
1320 $self->assert_child_ok($pid);
1321
1322 if ($ex) {
1323 test_append_logfile($log_file, $ex);
1324 unlink($log_file);
1325
1326 die($ex);
1327 }
1328
1329 unlink($log_file);
1330 }
1331
1332 sub listoptions_sortednlst_bug4267 {
1333 my $self = shift;
1334 my $tmpdir = $self->{tmpdir};
1335 my $setup = test_setup($tmpdir, 'config');
1336
1337 my $test_files = [];
1338 my $nfiles = 1000;
1339 for (my $i = 0; $i < $nfiles; $i++) {
1340 my $fileno = sprintf("%04d", $i);
1341 push(@$test_files, "$fileno.dat");
1342 }
1343
1344 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1345 mkpath($test_dir);
1346
1347 if ($ENV{TEST_VERBOSE}) {
1348 print STDERR "# Writing out files..."
1349 }
1350
1351 my $count = scalar(@$test_files);
1352 foreach my $test_file (@$test_files) {
1353 my $path = File::Spec->rel2abs("$test_dir/$test_file");
1354 if (open(my $fh, "> $path")) {
1355 print $fh "Hello, World!\n";
1356 unless (close($fh)) {
1357 die("Can't write $path: $!");
1358 }
1359
1360 } else {
1361 die("Can't open $path: $!");
1362 }
1363 }
1364
1365 if ($ENV{TEST_VERBOSE}) {
1366 print STDERR "done\n";
1367 }
1368
1369 my $config = {
1370 PidFile => $setup->{pid_file},
1371 ScoreboardFile => $setup->{scoreboard_file},
1372 SystemLog => $setup->{log_file},
1373
1374 AuthUserFile => $setup->{auth_user_file},
1375 AuthGroupFile => $setup->{auth_group_file},
1376 AuthOrder => 'mod_auth_file.c',
1377
1378 TimeoutLinger => 1,
1379 ListOptions => '"" SortedNLST',
1380
1381 IfModules => {
1382 'mod_delay.c' => {
1383 DelayEngine => 'off',
1384 },
1385 },
1386 };
1387
1388 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1389 $config);
1390
1391 # Open pipes, for use between the parent and child processes. Specifically,
1392 # the child will indicate when it's done with its test by writing a message
1393 # to the parent.
1394 my ($rfh, $wfh);
1395 unless (pipe($rfh, $wfh)) {
1396 die("Can't open pipe: $!");
1397 }
1398
1399 my $ex;
1400
1401 # Fork child
1402 $self->handle_sigchld();
1403 defined(my $pid = fork()) or die("Can't fork: $!");
1404 if ($pid) {
1405 eval {
1406 sleep(1);
1407
1408 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1409 $client->login($setup->{user}, $setup->{passwd});
1410 $client->cwd('test.d');
1411
1412 my $conn = $client->nlst_raw();
1413 unless ($conn) {
1414 die("Failed to NLST: " . $client->response_code() . " " .
1415 $client->response_msg());
1416 }
1417
1418 my ($buf, $tmp);
1419 my $res = $conn->read($tmp, 8192, 5);
1420 while ($res) {
1421 $buf .= $tmp;
1422 $tmp = '';
1423 $res = $conn->read($tmp, 8192, 5);
1424 }
1425 eval { $conn->close() };
1426 sleep(2);
1427
1428 my $resp_code = $client->response_code();
1429 my $resp_msg = $client->response_msg();
1430 $self->assert_transfer_ok($resp_code, $resp_msg);
1431
1432 if ($ENV{TEST_VERBOSE}) {
1433 print STDERR "buf:\n$buf\n";
1434 }
1435
1436 # Do NOT sort the results; we expect them to match the expected list.
1437 $res = [];
1438 my $lines = [split(/\n/, $buf)];
1439 foreach my $line (@$lines) {
1440 push(@$res, $line);
1441 }
1442
1443 my $expected = [@$test_files];
1444 my $nexpected = scalar(@$expected);
1445 my $nres = scalar(@$res);
1446
1447 $self->assert($nexpected == $nres,
1448 test_msg("Expected $nexpected items, got $nres"));
1449 for (my $i = 0; $i < $nexpected; $i++) {
1450 $self->assert($expected->[$i] eq $res->[$i],
1451 test_msg("Expected '$expected->[$i]' at index $i, got '$res->[$i]'"));
1452 }
1453
1454 $client->quit();
1455 };
1456
1457 if ($@) {
1458 $ex = $@;
1459 }
1460
1461 $wfh->print("done\n");
1462 $wfh->flush();
1463
1464 } else {
1465 eval { server_wait($setup->{config_file}, $rfh, 180) };
1466 if ($@) {
1467 warn($@);
1468 exit 1;
1469 }
1470
1471 exit 0;
1472 }
1473
1474 # Stop server
1475 server_stop($setup->{pid_file});
1476 $self->assert_child_ok($pid);
1477
1478 test_cleanup($setup->{log_file}, $ex);
1479 }
1480
1481 sub listoptions_maxfiles {
1482 my $self = shift;
1483 my $tmpdir = $self->{tmpdir};
1484
1485 my $config_file = "$tmpdir/config.conf";
1486 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
1487 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
1488
1489 my $log_file = test_get_logfile();
1490
1491 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
1492 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
1493
1494 my $user = 'proftpd';
1495 my $passwd = 'test';
1496 my $group = 'ftpd';
1497 my $home_dir = File::Spec->rel2abs($tmpdir);
1498 my $uid = 500;
1499 my $gid = 500;
1500
1501 # Make sure that, if we're running as root, that the home directory has
1502 # permissions/privs set for the account we create
1503 if ($< == 0) {
1504 unless (chmod(0755, $home_dir)) {
1505 die("Can't set perms on $home_dir to 0755: $!");
1506 }
1507
1508 unless (chown($uid, $gid, $home_dir)) {
1509 die("Can't set owner of $home_dir to $uid/$gid: $!");
1510 }
1511 }
1512
1513 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1514 '/bin/bash');
1515 auth_group_write($auth_group_file, $group, $gid, $user);
1516
1517 # For this test, we need to create MANY (i.e. 110K) files in the
1518 # home directory.
1519 my $test_file_prefix = File::Spec->rel2abs("$tmpdir/test_");
1520
1521 my $max_files = 100000;
1522
1523 my $count = $max_files + 10000;
1524 print STDOUT "# Creating $count files in $tmpdir\n";
1525 for (my $i = 1; $i <= $count; $i++) {
1526 my $test_file = 'test_' . sprintf("%07s", $i);
1527 my $test_path = "$home_dir/$test_file";
1528
1529 if (open(my $fh, "> $test_path")) {
1530 close($fh);
1531
1532 } else {
1533 die("Can't open $test_path: $!");
1534 }
1535
1536 if ($i % 10000 == 0) {
1537 print STDOUT "# Created file $test_file\n";
1538 }
1539 }
1540
1541 $max_files = 100000;
1542 my $timeout = 900;
1543
1544 my $config = {
1545 PidFile => $pid_file,
1546 ScoreboardFile => $scoreboard_file,
1547 SystemLog => $log_file,
1548
1549 AuthUserFile => $auth_user_file,
1550 AuthGroupFile => $auth_group_file,
1551 AuthOrder => 'mod_auth_file.c',
1552
1553 TimeoutIdle => $timeout + 15,
1554 TimeoutNoTransfer => $timeout + 15,
1555
1556 ListOptions => "-al maxfiles $max_files",
1557
1558 IfModules => {
1559 'mod_delay.c' => {
1560 DelayEngine => 'off',
1561 },
1562 },
1563 };
1564
1565 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1566
1567 # Open pipes, for use between the parent and child processes. Specifically,
1568 # the child will indicate when it's done with its test by writing a message
1569 # to the parent.
1570 my ($rfh, $wfh);
1571 unless (pipe($rfh, $wfh)) {
1572 die("Can't open pipe: $!");
1573 }
1574
1575 my $ex;
1576
1577 # Fork child
1578 $self->handle_sigchld();
1579 defined(my $pid = fork()) or die("Can't fork: $!");
1580 if ($pid) {
1581 eval {
1582 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1583 $client->login($user, $passwd);
1584
1585 my $conn = $client->list_raw();
1586 unless ($conn) {
1587 die("Failed to LIST: " . $client->response_code() . " " .
1588 $client->response_msg());
1589 }
1590
1591 my $buf;
1592
1593 my $tmp;
1594 while ($conn->read($tmp, 16384, 25)) {
1595 $buf .= $tmp;
1596 }
1597
1598 eval { $conn->close() };
1599
1600 my $resp_code = $client->response_code();
1601 my $resp_msg = $client->response_msg();
1602
1603 $self->assert_transfer_ok($resp_code, $resp_msg);
1604 $client->quit();
1605
1606 # We have to be careful of the fact that readdir returns directory
1607 # entries in an unordered fashion.
1608 my $res = [];
1609 my $lines = [split(/\n/, $buf)];
1610 foreach my $line (@$lines) {
1611 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1612 push(@$res, $1);
1613 }
1614 }
1615
1616 my $nexpected = $max_files;
1617 my $nres = scalar(@$res);
1618
1619 $self->assert($nexpected == $nres,
1620 test_msg("Expected $nexpected items, got $nres"));
1621 };
1622
1623 if ($@) {
1624 $ex = $@;
1625 }
1626
1627 $wfh->print("done\n");
1628 $wfh->flush();
1629
1630 } else {
1631 eval { server_wait($config_file, $rfh, $timeout) };
1632 if ($@) {
1633 warn($@);
1634 exit 1;
1635 }
1636
1637 exit 0;
1638 }
1639
1640 # Stop server
1641 server_stop($pid_file);
1642
1643 $self->assert_child_ok($pid);
1644
1645 if ($ex) {
1646 test_append_logfile($log_file, $ex);
1647 unlink($log_file);
1648
1649 die($ex);
1650 }
1651
1652 unlink($log_file);
1653 }
1654
1655 sub listoptions_nlstnamesonly_issue251 {
1656 my $self = shift;
1657 my $tmpdir = $self->{tmpdir};
1658 my $setup = test_setup($tmpdir, 'config');
1659
1660 my $test_files = [qw(
1661 a.txt
1662 b.txt
1663 c.txt
1664 d.txt
1665 e.txt
1666 f.txt
1667 g.txt
1668 h.txt
1669 i.txt
1670 )];
1671
1672 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1673 mkpath($test_dir);
1674
1675 my $count = scalar(@$test_files);
1676 foreach my $test_file (@$test_files) {
1677 my $path = File::Spec->rel2abs("$test_dir/$test_file");
1678 if (open(my $fh, "> $path")) {
1679 print $fh "Hello, World!\n";
1680 unless (close($fh)) {
1681 die("Can't write $path: $!");
1682 }
1683
1684 } else {
1685 die("Can't open $path: $!");
1686 }
1687 }
1688
1689 my $config = {
1690 PidFile => $setup->{pid_file},
1691 ScoreboardFile => $setup->{scoreboard_file},
1692 SystemLog => $setup->{log_file},
1693
1694 AuthUserFile => $setup->{auth_user_file},
1695 AuthGroupFile => $setup->{auth_group_file},
1696 AuthOrder => 'mod_auth_file.c',
1697
1698 ListOptions => '"-A -1 NLSTOnly"',
1699
1700 IfModules => {
1701 'mod_delay.c' => {
1702 DelayEngine => 'off',
1703 },
1704 },
1705 };
1706
1707 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1708 $config);
1709
1710 # Open pipes, for use between the parent and child processes. Specifically,
1711 # the child will indicate when it's done with its test by writing a message
1712 # to the parent.
1713 my ($rfh, $wfh);
1714 unless (pipe($rfh, $wfh)) {
1715 die("Can't open pipe: $!");
1716 }
1717
1718 my $ex;
1719
1720 # Fork child
1721 $self->handle_sigchld();
1722 defined(my $pid = fork()) or die("Can't fork: $!");
1723 if ($pid) {
1724 eval {
1725 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1726 $client->login($setup->{user}, $setup->{passwd});
1727
1728 my $conn = $client->nlst_raw('test.d');
1729 unless ($conn) {
1730 die("Failed to NLST: " . $client->response_code() . " " .
1731 $client->response_msg());
1732 }
1733
1734 my $buf;
1735 $conn->read($buf, 16384, 25);
1736 eval { $conn->close() };
1737
1738 my $resp_code = $client->response_code();
1739 my $resp_msg = $client->response_msg();
1740 $self->assert_transfer_ok($resp_code, $resp_msg);
1741
1742 $client->quit();
1743
1744 if ($ENV{TEST_VERBOSE}) {
1745 print STDERR "Data:\n$buf\n";
1746 }
1747
1748 # We have to be careful of the fact that readdir returns directory
1749 # entries in an unordered fashion.
1750 my $res = [];
1751 my $lines = [split(/\n/, $buf)];
1752 foreach my $line (@$lines) {
1753 push(@$res, $line);
1754 }
1755
1756 # Sort the results, so that they match the expected list.
1757 $res = [sort { $a cmp $b } @$res];
1758
1759 my $expected = [@$test_files];
1760 my $nexpected = scalar(@$expected);
1761 my $nres = scalar(@$res);
1762
1763 $self->assert($nexpected == $nres,
1764 "Expected $nexpected items, got $nres");
1765
1766 for (my $i = 0; $i < $nexpected; $i++) {
1767 $self->assert($expected->[$i] eq $res->[$i],
1768 "Expected '$expected->[$i]' at index $i, got '$res->[$i]'");
1769 }
1770 };
1771 if ($@) {
1772 $ex = $@;
1773 }
1774
1775 $wfh->print("done\n");
1776 $wfh->flush();
1777
1778 } else {
1779 eval { server_wait($setup->{config_file}, $rfh) };
1780 if ($@) {
1781 warn($@);
1782 exit 1;
1783 }
1784
1785 exit 0;
1786 }
1787
1788 # Stop server
1789 server_stop($setup->{pid_file});
1790 $self->assert_child_ok($pid);
1791
1792 test_cleanup($setup->{log_file}, $ex);
1793 }
1794
1795 1;