Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Commands/LIST.pm

raw
1 package ProFTPD::Tests::Commands::LIST;
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 use Time::HiRes qw(gettimeofday tv_interval);
12
13 use ProFTPD::TestSuite::FTP;
14 use ProFTPD::TestSuite::Utils qw(:auth :config :features :running :test :testsuite);
15
16 $| = 1;
17
18 my $order = 0;
19
20 my $TESTS = {
21 list_ok_raw_active => {
22 order => ++$order,
23 test_class => [qw(forking)],
24 },
25
26 list_ok_raw_passive => {
27 order => ++$order,
28 test_class => [qw(forking)],
29 },
30
31 list_ok_file => {
32 order => ++$order,
33 test_class => [qw(forking)],
34 },
35
36 list_file_rel_paths_bug4259 => {
37 order => ++$order,
38 test_class => [qw(bug forking)],
39 },
40
41 list_file_after_upload => {
42 order => ++$order,
43 test_class => [qw(forking)],
44 },
45
46 list_ok_dir => {
47 order => ++$order,
48 test_class => [qw(forking)],
49 },
50
51 list_dir_twice => {
52 order => ++$order,
53 test_class => [qw(forking)],
54 },
55
56 list_ok_no_path => {
57 order => ++$order,
58 test_class => [qw(forking)],
59 },
60
61 list_ok_glob => {
62 order => ++$order,
63 test_class => [qw(forking)],
64 },
65
66 list_fails_login_required => {
67 order => ++$order,
68 test_class => [qw(forking)],
69 },
70
71 list_fails_enoent => {
72 order => ++$order,
73 test_class => [qw(forking)],
74 },
75
76 list_fails_enoent_glob => {
77 order => ++$order,
78 test_class => [qw(forking)],
79 },
80
81 list_fails_eperm => {
82 order => ++$order,
83 test_class => [qw(forking)],
84 },
85
86 list_bug2821 => {
87 order => ++$order,
88 test_class => [qw(bug forking slow)],
89 },
90
91 list_unsorted_buffering_bug4060 => {
92 order => ++$order,
93 test_class => [qw(bug forking slow)],
94 },
95
96 list_opt_C => {
97 order => ++$order,
98 test_class => [qw(bug forking)],
99 },
100
101 list_nonascii_chars_bug3032 => {
102 order => ++$order,
103 test_class => [qw(bug forking)],
104 },
105
106 list_leading_whitespace_bug3268 => {
107 order => ++$order,
108 test_class => [qw(bug forking)],
109 },
110
111 list_leading_whitespace_with_opts_bug3268 => {
112 order => ++$order,
113 test_class => [qw(bug forking)],
114 },
115
116 list_leading_whitespace_with_strict_opts_bug3268 => {
117 order => ++$order,
118 test_class => [qw(bug forking)],
119 },
120
121 list_symlink_bug3254 => {
122 order => ++$order,
123 test_class => [qw(bug forking rootprivs)],
124 },
125
126 list_symlink_issue697 => {
127 order => ++$order,
128 test_class => [qw(bug forking rootprivs)],
129 },
130
131 list_symlink_issue940 => {
132 order => ++$order,
133 test_class => [qw(bug forking)],
134 },
135
136 list_symlink_rel_with_double_slash_bug3719 => {
137 order => ++$order,
138 test_class => [qw(bug forking rootprivs)],
139 },
140
141 list_showsymlinks_off => {
142 order => ++$order,
143 test_class => [qw(forking)],
144 },
145
146 list_showsymlinks_off_chrooted_bug4219 => {
147 order => ++$order,
148 test_class => [qw(bug forking rootprivs)],
149 },
150
151 list_showsymlinks_on => {
152 order => ++$order,
153 test_class => [qw(forking)],
154 },
155
156 list_showsymlinks_on_chrooted_bug4219 => {
157 order => ++$order,
158 test_class => [qw(bug forking rootprivs)],
159 },
160
161 list_glob_bug2367 => {
162 order => ++$order,
163 test_class => [qw(bug forking)],
164 },
165
166 list_glob_legit_dir_name => {
167 order => ++$order,
168 test_class => [qw(forking)],
169 },
170
171 list_glob_legit_dir_name_bug3407 => {
172 order => ++$order,
173 test_class => [qw(forking)],
174 },
175
176 list_opt_c => {
177 order => ++$order,
178 test_class => [qw(bug forking)],
179 },
180
181 list_opt_u => {
182 order => ++$order,
183 test_class => [qw(bug forking)],
184 },
185
186 list_dash_filename_bug3476 => {
187 order => ++$order,
188 test_class => [qw(bug forking)],
189 },
190
191 list_opt_noerrorifabsent_bug3506 => {
192 order => ++$order,
193 test_class => [qw(bug forking)],
194 },
195
196 list_slashstar_bug3529 => {
197 order => ++$order,
198 test_class => [qw(bug forking rootprivs)],
199 },
200
201 list_star_bug3529 => {
202 order => ++$order,
203 test_class => [qw(bug forking)],
204 },
205
206 list_opt_R => {
207 order => ++$order,
208 test_class => [qw(forking)],
209 },
210
211 list_opt_R_self_symlinked_dir_bug3719 => {
212 order => ++$order,
213 test_class => [qw(bug forking)],
214 },
215
216 list_opt_R_self_complex_symlinked_dir_bug3719 => {
217 order => ++$order,
218 test_class => [qw(bug forking)],
219 },
220
221 list_opt_R_rel_symlinked_file_bug3719 => {
222 order => ++$order,
223 test_class => [qw(bug forking)],
224 },
225
226 list_option_parsing => {
227 order => ++$order,
228 test_class => [qw(bug forking)],
229 },
230
231 list_symlink_rel_path_chrooted_bug4322 => {
232 order => ++$order,
233 test_class => [qw(bug forking rootprivs)],
234 },
235
236 list_symlink_rel_path_subdir_chrooted_bug4322 => {
237 order => ++$order,
238 test_class => [qw(bug forking rootprivs)],
239 },
240
241 list_symlink_rel_path_subdir_cwd_chrooted_bug4322 => {
242 order => ++$order,
243 test_class => [qw(bug forking rootprivs)],
244 },
245
246 list_style_windows => {
247 order => ++$order,
248 test_class => [qw(forking)],
249 },
250
251 # XXX Plenty of other tests needed: params, maxfiles, maxdirs, depth, etc
252 };
253
254 sub new {
255 return shift()->SUPER::new(@_);
256 }
257
258 sub list_tests {
259 return testsuite_get_runnable_tests($TESTS);
260 }
261
262 sub list_ok_raw_active {
263 my $self = shift;
264 my $tmpdir = $self->{tmpdir};
265 my $setup = test_setup($tmpdir, 'cmds');
266
267 my $config = {
268 PidFile => $setup->{pid_file},
269 ScoreboardFile => $setup->{scoreboard_file},
270 SystemLog => $setup->{log_file},
271
272 AuthUserFile => $setup->{auth_user_file},
273 AuthGroupFile => $setup->{auth_group_file},
274 AuthOrder => 'mod_auth_file.c',
275
276 IfModules => {
277 'mod_delay.c' => {
278 DelayEngine => 'off',
279 },
280 },
281 };
282
283 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
284 $config);
285
286 # Open pipes, for use between the parent and child processes. Specifically,
287 # the child will indicate when it's done with its test by writing a message
288 # to the parent.
289 my ($rfh, $wfh);
290 unless (pipe($rfh, $wfh)) {
291 die("Can't open pipe: $!");
292 }
293
294 my $ex;
295
296 # Fork child
297 $self->handle_sigchld();
298 defined(my $pid = fork()) or die("Can't fork: $!");
299 if ($pid) {
300 eval {
301 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
302 $client->login($setup->{user}, $setup->{passwd});
303
304 my $conn = $client->list_raw();
305 unless ($conn) {
306 die("Failed to LIST: " . $client->response_code() . " " .
307 $client->response_msg());
308 }
309
310 my $buf;
311 $conn->read($buf, 8192, 30);
312 eval { $conn->close() };
313
314 my $resp_code = $client->response_code();
315 my $resp_msg = $client->response_msg();
316 $client->quit();
317
318 $self->assert_transfer_ok($resp_code, $resp_msg);
319
320 # We have to be careful of the fact that readdir returns directory
321 # entries in an unordered fashion.
322 my $res = {};
323 my $lines = [split(/\n/, $buf)];
324 foreach my $line (@$lines) {
325 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
326 $res->{$1} = 1;
327 }
328 }
329
330 my $expected = {
331 'cmds.conf' => 1,
332 'cmds.group' => 1,
333 'cmds.passwd' => 1,
334 'cmds.pid' => 1,
335 'cmds.scoreboard' => 1,
336 'cmds.scoreboard.lck' => 1,
337 };
338
339 my $ok = 1;
340 my $mismatch;
341 foreach my $name (keys(%$res)) {
342 unless (defined($expected->{$name})) {
343 $mismatch = $name;
344 $ok = 0;
345 last;
346 }
347 }
348
349 unless ($ok) {
350 die("Unexpected name '$mismatch' appeared in LIST data")
351 }
352 };
353 if ($@) {
354 $ex = $@;
355 }
356
357 $wfh->print("done\n");
358 $wfh->flush();
359
360 } else {
361 eval { server_wait($setup->{config_file}, $rfh) };
362 if ($@) {
363 warn($@);
364 exit 1;
365 }
366
367 exit 0;
368 }
369
370 # Stop server
371 server_stop($setup->{pid_file});
372 $self->assert_child_ok($pid);
373
374 test_cleanup($setup->{log_file}, $ex);
375 }
376
377 sub list_ok_raw_passive {
378 my $self = shift;
379 my $tmpdir = $self->{tmpdir};
380 my $setup = test_setup($tmpdir, 'cmds');
381
382 my $config = {
383 PidFile => $setup->{pid_file},
384 ScoreboardFile => $setup->{scoreboard_file},
385 SystemLog => $setup->{log_file},
386
387 AuthUserFile => $setup->{auth_user_file},
388 AuthGroupFile => $setup->{auth_group_file},
389 AuthOrder => 'mod_auth_file.c',
390
391 IfModules => {
392 'mod_delay.c' => {
393 DelayEngine => 'off',
394 },
395 },
396 };
397
398 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
399 $config);
400
401 # Open pipes, for use between the parent and child processes. Specifically,
402 # the child will indicate when it's done with its test by writing a message
403 # to the parent.
404 my ($rfh, $wfh);
405 unless (pipe($rfh, $wfh)) {
406 die("Can't open pipe: $!");
407 }
408
409 my $ex;
410
411 # Fork child
412 $self->handle_sigchld();
413 defined(my $pid = fork()) or die("Can't fork: $!");
414 if ($pid) {
415 eval {
416 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
417 $client->login($setup->{user}, $setup->{passwd});
418
419 my $conn = $client->list_raw();
420 unless ($conn) {
421 die("Failed to LIST: " . $client->response_code() . " " .
422 $client->response_msg());
423 }
424
425 my $buf;
426 $conn->read($buf, 8192, 30);
427 eval { $conn->close() };
428
429 my $resp_code = $client->response_code();
430 my $resp_msg = $client->response_msg();
431 $client->quit();
432
433 $self->assert_transfer_ok($resp_code, $resp_msg);
434
435 # We have to be careful of the fact that readdir returns directory
436 # entries in an unordered fashion.
437 my $res = {};
438 my $lines = [split(/(\r)?\n/, $buf)];
439 foreach my $line (@$lines) {
440 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
441 $res->{$1} = 1;
442 }
443 }
444
445 my $expected = {
446 'cmds.conf' => 1,
447 'cmds.group' => 1,
448 'cmds.passwd' => 1,
449 'cmds.pid' => 1,
450 'cmds.scoreboard' => 1,
451 'cmds.scoreboard.lck' => 1,
452 };
453
454 my $ok = 1;
455 my $mismatch;
456 foreach my $name (keys(%$res)) {
457 unless (defined($expected->{$name})) {
458 $mismatch = $name;
459 $ok = 0;
460 last;
461 }
462 }
463
464 unless ($ok) {
465 die("Unexpected name '$mismatch' appeared in LIST data")
466 }
467 };
468 if ($@) {
469 $ex = $@;
470 }
471
472 $wfh->print("done\n");
473 $wfh->flush();
474
475 } else {
476 eval { server_wait($setup->{config_file}, $rfh) };
477 if ($@) {
478 warn($@);
479 exit 1;
480 }
481
482 exit 0;
483 }
484
485 # Stop server
486 server_stop($setup->{pid_file});
487 $self->assert_child_ok($pid);
488
489 test_cleanup($setup->{log_file}, $ex);
490 }
491
492 sub list_ok_file {
493 my $self = shift;
494 my $tmpdir = $self->{tmpdir};
495 my $setup = test_setup($tmpdir, 'cmds');
496
497 my $test_file = File::Spec->rel2abs($setup->{config_file});
498
499 my $config = {
500 PidFile => $setup->{pid_file},
501 ScoreboardFile => $setup->{scoreboard_file},
502 SystemLog => $setup->{log_file},
503
504 AuthUserFile => $setup->{auth_user_file},
505 AuthGroupFile => $setup->{auth_group_file},
506 AuthOrder => 'mod_auth_file.c',
507
508 IfModules => {
509 'mod_delay.c' => {
510 DelayEngine => 'off',
511 },
512 },
513 };
514
515 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
516 $config);
517
518 # Open pipes, for use between the parent and child processes. Specifically,
519 # the child will indicate when it's done with its test by writing a message
520 # to the parent.
521 my ($rfh, $wfh);
522 unless (pipe($rfh, $wfh)) {
523 die("Can't open pipe: $!");
524 }
525
526 my $ex;
527
528 # Fork child
529 $self->handle_sigchld();
530 defined(my $pid = fork()) or die("Can't fork: $!");
531 if ($pid) {
532 eval {
533 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
534 $client->login($setup->{user}, $setup->{passwd});
535
536 my $conn = $client->list_raw($test_file);
537 unless ($conn) {
538 die("LIST failed: " . $client->response_code() . " " .
539 $client->response_msg());
540 }
541
542 my $buf;
543 $conn->read($buf, 8192, 30);
544 eval { $conn->close() };
545
546 my $resp_code = $client->response_code();
547 my $resp_msg = $client->response_msg();
548 $client->quit();
549
550 $self->assert_transfer_ok($resp_code, $resp_msg);
551
552 my $res = {};
553 my $lines = [split(/\n/, $buf)];
554 foreach my $line (@$lines) {
555 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
556 $res->{$1} = 1;
557 }
558 }
559
560 my $count = scalar(keys(%$res));
561 unless ($count == 1) {
562 die("LIST returned wrong number of entries (expected 1, got $count)");
563 }
564
565 unless (defined($res->{$test_file})) {
566 die("LIST failed to return $test_file");
567 }
568 };
569 if ($@) {
570 $ex = $@;
571 }
572
573 $wfh->print("done\n");
574 $wfh->flush();
575
576 } else {
577 eval { server_wait($setup->{config_file}, $rfh) };
578 if ($@) {
579 warn($@);
580 exit 1;
581 }
582
583 exit 0;
584 }
585
586 # Stop server
587 server_stop($setup->{pid_file});
588 $self->assert_child_ok($pid);
589
590 test_cleanup($setup->{log_file}, $ex);
591 }
592
593 # See: https://forums.proftpd.org/smf/index.php/topic,12000.0.html
594 sub list_file_rel_paths_bug4259 {
595 my $self = shift;
596 my $tmpdir = $self->{tmpdir};
597 my $setup = test_setup($tmpdir, 'cmds');
598
599 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
600 if (open(my $fh, "> $test_file")) {
601 print $fh "Hello, World!\n";
602 unless (close($fh)) {
603 die("Can't write $test_file: $!");
604 }
605
606 } else {
607 die("Can't open $test_file: $!");
608 }
609
610 my $config = {
611 PidFile => $setup->{pid_file},
612 ScoreboardFile => $setup->{scoreboard_file},
613 SystemLog => $setup->{log_file},
614
615 AuthUserFile => $setup->{auth_user_file},
616 AuthGroupFile => $setup->{auth_group_file},
617 AuthOrder => 'mod_auth_file.c',
618
619 IfModules => {
620 'mod_delay.c' => {
621 DelayEngine => 'off',
622 },
623 },
624 };
625
626 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
627 $config);
628
629 # Open pipes, for use between the parent and child processes. Specifically,
630 # the child will indicate when it's done with its test by writing a message
631 # to the parent.
632 my ($rfh, $wfh);
633 unless (pipe($rfh, $wfh)) {
634 die("Can't open pipe: $!");
635 }
636
637 my $ex;
638
639 # Fork child
640 $self->handle_sigchld();
641 defined(my $pid = fork()) or die("Can't fork: $!");
642 if ($pid) {
643 eval {
644 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
645 $client->login($setup->{user}, $setup->{passwd});
646
647 my $rel_path = 'test.dat';
648 my $conn = $client->list_raw($rel_path);
649 unless ($conn) {
650 die("LIST failed: " . $client->response_code() . " " .
651 $client->response_msg());
652 }
653
654 my $buf;
655 $conn->read($buf, 8192, 30);
656 eval { $conn->close() };
657
658 my $resp_code = $client->response_code();
659 my $resp_msg = $client->response_msg();
660 $self->assert_transfer_ok($resp_code, $resp_msg);
661
662 if ($ENV{TEST_VERBOSE}) {
663 print STDERR "# response: $buf\n";
664 }
665
666 my $res = {};
667 my $lines = [split(/\n/, $buf)];
668 foreach my $line (@$lines) {
669 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
670 $res->{$1} = 1;
671 }
672 }
673
674 my $count = scalar(keys(%$res));
675 unless ($count == 1) {
676 die("LIST returned wrong number of entries (expected 1, got $count)");
677 }
678
679 unless (defined($res->{$rel_path})) {
680 die("LIST failed to return $rel_path");
681 }
682
683 # Now list using a different relative path syntax
684 $rel_path = './test.dat';
685 $conn = $client->list_raw($rel_path);
686 unless ($conn) {
687 die("LIST failed: " . $client->response_code() . " " .
688 $client->response_msg());
689 }
690
691 $buf = '';
692 $conn->read($buf, 8192, 30);
693 eval { $conn->close() };
694
695 $resp_code = $client->response_code();
696 $resp_msg = $client->response_msg();
697 $self->assert_transfer_ok($resp_code, $resp_msg);
698
699 if ($ENV{TEST_VERBOSE}) {
700 print STDERR "# response: $buf\n";
701 }
702
703 $res = {};
704 $lines = [split(/\n/, $buf)];
705 foreach my $line (@$lines) {
706 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
707 $res->{$1} = 1;
708 }
709 }
710
711 $count = scalar(keys(%$res));
712 unless ($count == 1) {
713 die("LIST returned wrong number of entries (expected 1, got $count)");
714 }
715
716 unless (defined($res->{$rel_path})) {
717 die("LIST failed to return $rel_path");
718 }
719
720 $client->quit();
721 };
722 if ($@) {
723 $ex = $@;
724 }
725
726 $wfh->print("done\n");
727 $wfh->flush();
728
729 } else {
730 eval { server_wait($setup->{config_file}, $rfh) };
731 if ($@) {
732 warn($@);
733 exit 1;
734 }
735
736 exit 0;
737 }
738
739 # Stop server
740 server_stop($setup->{pid_file});
741 $self->assert_child_ok($pid);
742
743 test_cleanup($setup->{log_file}, $ex);
744 }
745
746 sub list_file_after_upload {
747 my $self = shift;
748 my $tmpdir = $self->{tmpdir};
749
750 my $config_file = "$tmpdir/cmds.conf";
751 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
752 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
753
754 my $log_file = test_get_logfile();
755
756 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
757 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
758
759 my $user = 'proftpd';
760 my $passwd = 'test';
761 my $group = 'ftpd';
762 my $home_dir = File::Spec->rel2abs($tmpdir);
763 my $uid = 500;
764 my $gid = 500;
765
766 # Make sure that, if we're running as root, that the home directory has
767 # permissions/privs set for the account we create
768 if ($< == 0) {
769 unless (chmod(0755, $home_dir)) {
770 die("Can't set perms on $home_dir to 0755: $!");
771 }
772
773 unless (chown($uid, $gid, $home_dir)) {
774 die("Can't set owner of $home_dir to $uid/$gid: $!");
775 }
776 }
777
778 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
779 '/bin/bash');
780 auth_group_write($auth_group_file, $group, $gid, $user);
781
782 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
783
784 my $config = {
785 PidFile => $pid_file,
786 ScoreboardFile => $scoreboard_file,
787 SystemLog => $log_file,
788 TraceLog => $log_file,
789 Trace => 'fsio:10 fs.statcache:20',
790
791 AuthUserFile => $auth_user_file,
792 AuthGroupFile => $auth_group_file,
793 AuthOrder => 'mod_auth_file.c',
794
795 IfModules => {
796 'mod_delay.c' => {
797 DelayEngine => 'off',
798 },
799 },
800 };
801
802 my ($port, $config_user, $config_group) = config_write($config_file, $config);
803
804 # Open pipes, for use between the parent and child processes. Specifically,
805 # the child will indicate when it's done with its test by writing a message
806 # to the parent.
807 my ($rfh, $wfh);
808 unless (pipe($rfh, $wfh)) {
809 die("Can't open pipe: $!");
810 }
811
812 my $ex;
813
814 # Fork child
815 $self->handle_sigchld();
816 defined(my $pid = fork()) or die("Can't fork: $!");
817 if ($pid) {
818 eval {
819 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
820 $client->login($user, $passwd);
821 $client->type('binary');
822
823 if ($ENV{TEST_VERBOSE}) {
824 print STDOUT "# Logged in, sending STOR\n";
825 }
826
827 my $conn = $client->stor_raw('test.dat');
828 unless ($conn) {
829 die("STOR test.dat failed: " . $client->response_code() . " " .
830 $client->response_msg());
831 }
832
833 if ($ENV{TEST_VERBOSE}) {
834 print STDOUT "# Data connection opened, writing data\n";
835 }
836
837 my $start = [gettimeofday()];
838 my $buf = "ABCD" x 10240;
839 $conn->write($buf, length($buf), 30);
840 eval { $conn->close() };
841
842 my $resp_code = $client->response_code();
843 my $resp_msg = $client->response_msg();
844 $self->assert_transfer_ok($resp_code, $resp_msg);
845
846 my $elapsed = tv_interval($start);
847 if ($ENV{TEST_VERBOSE}) {
848 print STDOUT "# elapsed upload duration: $elapsed\n";
849 }
850
851 if ($ENV{TEST_VERBOSE}) {
852 print STDOUT "# File uploaded, sending LIST\n";
853 }
854
855 $conn = $client->list_raw($test_file);
856 unless ($conn) {
857 die("LIST $test_file failed: " . $client->response_code() . " " .
858 $client->response_msg());
859 }
860
861 $buf = '';
862 $conn->read($buf, 8192, 30);
863 eval { $conn->close() };
864
865 $resp_code = $client->response_code();
866 $resp_msg = $client->response_msg();
867 $self->assert_transfer_ok($resp_code, $resp_msg);
868
869 $client->quit();
870
871 my $res = {};
872 my $lines = [split(/\r?\n/, $buf)];
873 foreach my $line (@$lines) {
874 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
875 my $path = $1;
876 $res->{$path} = 1;
877 }
878 }
879
880 my $count = scalar(keys(%$res));
881 unless ($count == 1) {
882 die("LIST returned wrong number of entries (expected 1, got $count)");
883 }
884
885 unless (defined($res->{$test_file})) {
886 die("LIST failed to return $test_file");
887 }
888 };
889
890 if ($@) {
891 $ex = $@;
892 }
893
894 $wfh->print("done\n");
895 $wfh->flush();
896
897 } else {
898 eval { server_wait($config_file, $rfh) };
899 if ($@) {
900 warn($@);
901 exit 1;
902 }
903
904 exit 0;
905 }
906
907 # Stop server
908 server_stop($pid_file);
909
910 $self->assert_child_ok($pid);
911
912 if ($ex) {
913 test_append_logfile($log_file, $ex);
914 unlink($log_file);
915
916 die($ex);
917 }
918
919 unlink($log_file);
920 }
921
922 sub list_ok_dir {
923 my $self = shift;
924 my $tmpdir = $self->{tmpdir};
925
926 my $config_file = "$tmpdir/cmds.conf";
927 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
928 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
929
930 my $log_file = test_get_logfile();
931
932 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
933 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
934
935 my $user = 'proftpd';
936 my $passwd = 'test';
937 my $home_dir = File::Spec->rel2abs($tmpdir);
938 my $uid = 500;
939 my $gid = 500;
940
941 # Make sure that, if we're running as root, that the home directory has
942 # permissions/privs set for the account we create
943 if ($< == 0) {
944 unless (chmod(0755, $home_dir)) {
945 die("Can't set perms on $home_dir to 0755: $!");
946 }
947
948 unless (chown($uid, $gid, $home_dir)) {
949 die("Can't set owner of $home_dir to $uid/$gid: $!");
950 }
951 }
952
953 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
954 '/bin/bash');
955 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
956
957 my $config = {
958 PidFile => $pid_file,
959 ScoreboardFile => $scoreboard_file,
960 SystemLog => $log_file,
961
962 AuthUserFile => $auth_user_file,
963 AuthGroupFile => $auth_group_file,
964 AuthOrder => 'mod_auth_file.c',
965
966 IfModules => {
967 'mod_delay.c' => {
968 DelayEngine => 'off',
969 },
970 },
971 };
972
973 my ($port, $config_user, $config_group) = config_write($config_file, $config);
974
975 # Open pipes, for use between the parent and child processes. Specifically,
976 # the child will indicate when it's done with its test by writing a message
977 # to the parent.
978 my ($rfh, $wfh);
979 unless (pipe($rfh, $wfh)) {
980 die("Can't open pipe: $!");
981 }
982
983 my $ex;
984
985 # Fork child
986 $self->handle_sigchld();
987 defined(my $pid = fork()) or die("Can't fork: $!");
988 if ($pid) {
989 eval {
990 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
991
992 $client->login($user, $passwd);
993
994 my $conn = $client->list_raw($home_dir);
995 unless ($conn) {
996 die("LIST failed: " . $client->response_code() . " " .
997 $client->response_msg());
998 }
999
1000 my $buf;
1001 $conn->read($buf, 8192, 30);
1002 eval { $conn->close() };
1003
1004 my $res = {};
1005 my $lines = [split(/\n/, $buf)];
1006 foreach my $line (@$lines) {
1007 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1008 $res->{$1} = 1;
1009 }
1010 }
1011
1012 my $count = scalar(keys(%$res));
1013 my $expected = 6;
1014 unless ($count == $expected) {
1015 if ($ENV{TEST_VERBOSE}) {
1016 print STDERR "Received:\n$buf\n";
1017 }
1018
1019 die("LIST returned wrong number of entries (expected $expected, got $count)");
1020 }
1021 };
1022
1023 if ($@) {
1024 $ex = $@;
1025 }
1026
1027 $wfh->print("done\n");
1028 $wfh->flush();
1029
1030 } else {
1031 eval { server_wait($config_file, $rfh) };
1032 if ($@) {
1033 warn($@);
1034 exit 1;
1035 }
1036
1037 exit 0;
1038 }
1039
1040 # Stop server
1041 server_stop($pid_file);
1042
1043 $self->assert_child_ok($pid);
1044
1045 if ($ex) {
1046 test_append_logfile($log_file, $ex);
1047 unlink($log_file);
1048
1049 die($ex);
1050 }
1051
1052 unlink($log_file);
1053 }
1054
1055 sub list_dir_twice {
1056 my $self = shift;
1057 my $tmpdir = $self->{tmpdir};
1058
1059 my $config_file = "$tmpdir/cmds.conf";
1060 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1061 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1062
1063 my $log_file = test_get_logfile();
1064
1065 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1066 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1067
1068 my $user = 'proftpd';
1069 my $passwd = 'test';
1070 my $group = 'ftpd';
1071 my $home_dir = File::Spec->rel2abs($tmpdir);
1072 my $uid = 500;
1073 my $gid = 500;
1074
1075 # Make sure that, if we're running as root, that the home directory has
1076 # permissions/privs set for the account we create
1077 if ($< == 0) {
1078 unless (chmod(0755, $home_dir)) {
1079 die("Can't set perms on $home_dir to 0755: $!");
1080 }
1081
1082 unless (chown($uid, $gid, $home_dir)) {
1083 die("Can't set owner of $home_dir to $uid/$gid: $!");
1084 }
1085 }
1086
1087 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1088 '/bin/bash');
1089 auth_group_write($auth_group_file, $group, $gid, $user);
1090
1091 my $config = {
1092 PidFile => $pid_file,
1093 ScoreboardFile => $scoreboard_file,
1094 SystemLog => $log_file,
1095
1096 AuthUserFile => $auth_user_file,
1097 AuthGroupFile => $auth_group_file,
1098 AuthOrder => 'mod_auth_file.c',
1099
1100 IfModules => {
1101 'mod_delay.c' => {
1102 DelayEngine => 'off',
1103 },
1104 },
1105 };
1106
1107 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1108
1109 # Open pipes, for use between the parent and child processes. Specifically,
1110 # the child will indicate when it's done with its test by writing a message
1111 # to the parent.
1112 my ($rfh, $wfh);
1113 unless (pipe($rfh, $wfh)) {
1114 die("Can't open pipe: $!");
1115 }
1116
1117 my $ex;
1118
1119 # Fork child
1120 $self->handle_sigchld();
1121 defined(my $pid = fork()) or die("Can't fork: $!");
1122 if ($pid) {
1123 eval {
1124 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1125 $client->login($user, $passwd);
1126
1127 my $conn = $client->list_raw($home_dir);
1128 unless ($conn) {
1129 die("LIST failed: " . $client->response_code() . " " .
1130 $client->response_msg());
1131 }
1132
1133 my $buf;
1134 $conn->read($buf, 8192, 30);
1135 eval { $conn->close() };
1136
1137 my $res = {};
1138 my $lines = [split(/\r?\n/, $buf)];
1139 foreach my $line (@$lines) {
1140 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1141 $res->{$1} = 1;
1142 }
1143 }
1144
1145 my $count = scalar(keys(%$res));
1146 my $expected = 6;
1147 unless ($count == $expected) {
1148 if ($ENV{TEST_VERBOSE}) {
1149 print STDERR "Received:\n$buf\n";
1150 }
1151
1152 die("LIST returned wrong number of entries (expected $expected, got $count)");
1153 }
1154
1155 $conn = $client->list_raw($home_dir);
1156 unless ($conn) {
1157 die("LIST failed: " . $client->response_code() . " " .
1158 $client->response_msg());
1159 }
1160
1161 $buf = '';
1162 $conn->read($buf, 8192, 30);
1163 eval { $conn->close() };
1164
1165 my $res2 = {};
1166 $lines = [split(/\r?\n/, $buf)];
1167 foreach my $line (@$lines) {
1168 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1169 $res2->{$1} = 1;
1170 }
1171 }
1172
1173 my $count2 = scalar(keys(%$res2));
1174 unless ($count2 == $count) {
1175 if ($ENV{TEST_VERBOSE}) {
1176 print STDERR "Received:\n$buf\n";
1177 }
1178
1179 die("Second LIST returned wrong number of entries (expected $count, got $count2)");
1180 }
1181
1182 $client->quit();
1183 };
1184
1185 if ($@) {
1186 $ex = $@;
1187 }
1188
1189 $wfh->print("done\n");
1190 $wfh->flush();
1191
1192 } else {
1193 eval { server_wait($config_file, $rfh) };
1194 if ($@) {
1195 warn($@);
1196 exit 1;
1197 }
1198
1199 exit 0;
1200 }
1201
1202 # Stop server
1203 server_stop($pid_file);
1204
1205 $self->assert_child_ok($pid);
1206
1207 if ($ex) {
1208 test_append_logfile($log_file, $ex);
1209 unlink($log_file);
1210
1211 die($ex);
1212 }
1213
1214 unlink($log_file);
1215 }
1216
1217 sub list_ok_no_path {
1218 my $self = shift;
1219 my $tmpdir = $self->{tmpdir};
1220
1221 my $config_file = "$tmpdir/cmds.conf";
1222 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1223 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1224
1225 my $log_file = test_get_logfile();
1226
1227 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1228 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1229
1230 my $user = 'proftpd';
1231 my $passwd = 'test';
1232 my $home_dir = File::Spec->rel2abs($tmpdir);
1233 my $uid = 500;
1234 my $gid = 500;
1235
1236 # Make sure that, if we're running as root, that the home directory has
1237 # permissions/privs set for the account we create
1238 if ($< == 0) {
1239 unless (chmod(0755, $home_dir)) {
1240 die("Can't set perms on $home_dir to 0755: $!");
1241 }
1242
1243 unless (chown($uid, $gid, $home_dir)) {
1244 die("Can't set owner of $home_dir to $uid/$gid: $!");
1245 }
1246 }
1247
1248 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1249 '/bin/bash');
1250 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1251
1252 my $config = {
1253 PidFile => $pid_file,
1254 ScoreboardFile => $scoreboard_file,
1255 SystemLog => $log_file,
1256
1257 AuthUserFile => $auth_user_file,
1258 AuthGroupFile => $auth_group_file,
1259 AuthOrder => 'mod_auth_file.c',
1260
1261 IfModules => {
1262 'mod_delay.c' => {
1263 DelayEngine => 'off',
1264 },
1265 },
1266 };
1267
1268 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1269
1270 # Open pipes, for use between the parent and child processes. Specifically,
1271 # the child will indicate when it's done with its test by writing a message
1272 # to the parent.
1273 my ($rfh, $wfh);
1274 unless (pipe($rfh, $wfh)) {
1275 die("Can't open pipe: $!");
1276 }
1277
1278 my $ex;
1279
1280 # Fork child
1281 $self->handle_sigchld();
1282 defined(my $pid = fork()) or die("Can't fork: $!");
1283 if ($pid) {
1284 eval {
1285 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1286
1287 $client->login($user, $passwd);
1288
1289 my $conn = $client->list_raw();
1290 unless ($conn) {
1291 die("LIST failed: " . $client->response_code() . " " .
1292 $client->response_msg());
1293 }
1294
1295 my $buf;
1296 $conn->read($buf, 8192, 30);
1297 eval { $conn->close() };
1298
1299 my $res = {};
1300 my $lines = [split(/\n/, $buf)];
1301 foreach my $line (@$lines) {
1302 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1303 $res->{$1} = 1;
1304 }
1305 }
1306
1307 my $count = scalar(keys(%$res));
1308 my $expected = 6;
1309 unless ($count == $expected) {
1310 die("LIST returned wrong number of entries (expected $expected, got $count)");
1311 }
1312 };
1313
1314 if ($@) {
1315 $ex = $@;
1316 }
1317
1318 print $wfh "done\n";
1319
1320 } else {
1321 eval { server_wait($config_file, $rfh) };
1322 if ($@) {
1323 warn($@);
1324 exit 1;
1325 }
1326
1327 exit 0;
1328 }
1329
1330 # Stop server
1331 server_stop($pid_file);
1332
1333 $self->assert_child_ok($pid);
1334
1335 if ($ex) {
1336 test_append_logfile($log_file, $ex);
1337 unlink($log_file);
1338
1339 die($ex);
1340 }
1341
1342 unlink($log_file);
1343 }
1344
1345 sub list_ok_glob {
1346 my $self = shift;
1347 my $tmpdir = $self->{tmpdir};
1348
1349 my $config_file = "$tmpdir/cmds.conf";
1350 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1351 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1352
1353 my $log_file = test_get_logfile();
1354
1355 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1356 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1357
1358 my $user = 'proftpd';
1359 my $passwd = 'test';
1360 my $home_dir = File::Spec->rel2abs($tmpdir);
1361 my $uid = 500;
1362 my $gid = 500;
1363
1364 # Make sure that, if we're running as root, that the home directory has
1365 # permissions/privs set for the account we create
1366 if ($< == 0) {
1367 unless (chmod(0755, $home_dir)) {
1368 die("Can't set perms on $home_dir to 0755: $!");
1369 }
1370
1371 unless (chown($uid, $gid, $home_dir)) {
1372 die("Can't set owner of $home_dir to $uid/$gid: $!");
1373 }
1374 }
1375
1376 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1377 '/bin/bash');
1378 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1379
1380 my $config = {
1381 PidFile => $pid_file,
1382 ScoreboardFile => $scoreboard_file,
1383 SystemLog => $log_file,
1384
1385 AuthUserFile => $auth_user_file,
1386 AuthGroupFile => $auth_group_file,
1387 AuthOrder => 'mod_auth_file.c',
1388
1389 IfModules => {
1390 'mod_delay.c' => {
1391 DelayEngine => 'off',
1392 },
1393 },
1394 };
1395
1396 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1397
1398 # Open pipes, for use between the parent and child processes. Specifically,
1399 # the child will indicate when it's done with its test by writing a message
1400 # to the parent.
1401 my ($rfh, $wfh);
1402 unless (pipe($rfh, $wfh)) {
1403 die("Can't open pipe: $!");
1404 }
1405
1406 my $ex;
1407
1408 # Fork child
1409 $self->handle_sigchld();
1410 defined(my $pid = fork()) or die("Can't fork: $!");
1411 if ($pid) {
1412 eval {
1413 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1414
1415 $client->login($user, $passwd);
1416
1417 my $conn = $client->list_raw("*.conf");
1418 unless ($conn) {
1419 die("LIST failed: " . $client->response_code() . " " .
1420 $client->response_msg());
1421 }
1422
1423 my $buf;
1424 $conn->read($buf, 8192, 30);
1425 eval { $conn->close() };
1426
1427 my $res = {};
1428 my $lines = [split(/\n/, $buf)];
1429 foreach my $line (@$lines) {
1430 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
1431 $res->{$1} = 1;
1432 }
1433 }
1434
1435 my $count = scalar(keys(%$res));
1436 unless ($count == 1) {
1437 die("LIST returned wrong number of entries (expected 1, got $count)");
1438 }
1439
1440 my $test_file = 'cmds.conf';
1441 unless (defined($res->{$test_file})) {
1442 die("LIST failed to return $test_file");
1443 }
1444 };
1445
1446 if ($@) {
1447 $ex = $@;
1448 }
1449
1450 $wfh->print("done\n");
1451 $wfh->flush();
1452
1453 } else {
1454 eval { server_wait($config_file, $rfh) };
1455 if ($@) {
1456 warn($@);
1457 exit 1;
1458 }
1459
1460 exit 0;
1461 }
1462
1463 # Stop server
1464 server_stop($pid_file);
1465
1466 $self->assert_child_ok($pid);
1467
1468 if ($ex) {
1469 test_append_logfile($log_file, $ex);
1470 unlink($log_file);
1471
1472 die($ex);
1473 }
1474
1475 unlink($log_file);
1476 }
1477
1478 sub list_fails_login_required {
1479 my $self = shift;
1480 my $tmpdir = $self->{tmpdir};
1481
1482 my $config_file = "$tmpdir/cmds.conf";
1483 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1484 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1485
1486 my $log_file = test_get_logfile();
1487
1488 my $config = {
1489 PidFile => $pid_file,
1490 ScoreboardFile => $scoreboard_file,
1491 SystemLog => $log_file,
1492
1493 IfModules => {
1494 'mod_delay.c' => {
1495 DelayEngine => 'off',
1496 },
1497 },
1498 };
1499
1500 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1501
1502 # Open pipes, for use between the parent and child processes. Specifically,
1503 # the child will indicate when it's done with its test by writing a message
1504 # to the parent.
1505 my ($rfh, $wfh);
1506 unless (pipe($rfh, $wfh)) {
1507 die("Can't open pipe: $!");
1508 }
1509
1510 my $ex;
1511
1512 # Fork child
1513 $self->handle_sigchld();
1514 defined(my $pid = fork()) or die("Can't fork: $!");
1515 if ($pid) {
1516 eval {
1517 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1518
1519 my ($resp_code, $resp_msg);
1520 eval { ($resp_code, $resp_msg) = $client->list() };
1521 unless ($@) {
1522 die("LIST succeeded unexpectedly ($resp_code $resp_msg)");
1523
1524 } else {
1525 $resp_code = $client->response_code();
1526 $resp_msg = $client->response_msg();
1527 }
1528
1529 my $expected;
1530
1531 $expected = 530;
1532 $self->assert($expected == $resp_code,
1533 test_msg("Expected $expected, got $resp_code"));
1534
1535 $expected = "Please login with USER and PASS";
1536 $self->assert($expected eq $resp_msg,
1537 test_msg("Expected '$expected', got '$resp_msg'"));
1538 };
1539
1540 if ($@) {
1541 $ex = $@;
1542 }
1543
1544 $wfh->print("done\n");
1545 $wfh->flush();
1546
1547 } else {
1548 eval { server_wait($config_file, $rfh) };
1549 if ($@) {
1550 warn($@);
1551 exit 1;
1552 }
1553
1554 exit 0;
1555 }
1556
1557 # Stop server
1558 server_stop($pid_file);
1559
1560 $self->assert_child_ok($pid);
1561
1562 if ($ex) {
1563 test_append_logfile($log_file, $ex);
1564 unlink($log_file);
1565
1566 die($ex);
1567 }
1568
1569 unlink($log_file);
1570 }
1571
1572 sub list_fails_enoent {
1573 my $self = shift;
1574 my $tmpdir = $self->{tmpdir};
1575
1576 my $config_file = "$tmpdir/cmds.conf";
1577 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1578 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1579
1580 my $log_file = test_get_logfile();
1581
1582 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1583 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1584
1585 my $user = 'proftpd';
1586 my $passwd = 'test';
1587 my $home_dir = File::Spec->rel2abs($tmpdir);
1588 my $uid = 500;
1589 my $gid = 500;
1590
1591 # Make sure that, if we're running as root, that the home directory has
1592 # permissions/privs set for the account we create
1593 if ($< == 0) {
1594 unless (chmod(0755, $home_dir)) {
1595 die("Can't set perms on $home_dir to 0755: $!");
1596 }
1597
1598 unless (chown($uid, $gid, $home_dir)) {
1599 die("Can't set owner of $home_dir to $uid/$gid: $!");
1600 }
1601 }
1602
1603 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1604 '/bin/bash');
1605 auth_group_write($auth_group_file, 'ftpd', $uid, $user);
1606
1607 my $config = {
1608 PidFile => $pid_file,
1609 ScoreboardFile => $scoreboard_file,
1610 SystemLog => $log_file,
1611
1612 AuthUserFile => $auth_user_file,
1613 AuthGroupFile => $auth_group_file,
1614 AuthOrder => 'mod_auth_file.c',
1615
1616 IfModules => {
1617 'mod_delay.c' => {
1618 DelayEngine => 'off',
1619 },
1620 },
1621 };
1622
1623 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1624
1625 # Open pipes, for use between the parent and child processes. Specifically,
1626 # the child will indicate when it's done with its test by writing a message
1627 # to the parent.
1628 my ($rfh, $wfh);
1629 unless (pipe($rfh, $wfh)) {
1630 die("Can't open pipe: $!");
1631 }
1632
1633 my $ex;
1634
1635 # Fork child
1636 $self->handle_sigchld();
1637 defined(my $pid = fork()) or die("Can't fork: $!");
1638 if ($pid) {
1639 eval {
1640 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1641
1642 $client->login($user, $passwd);
1643
1644 my ($resp_code, $resp_msg);
1645 $client->port();
1646
1647 my $test_file = 'foo/bar/baz';
1648
1649 eval { ($resp_code, $resp_msg) = $client->list($test_file) };
1650 unless ($@) {
1651 die("LIST succeeded unexpectedly ($resp_code $resp_msg)");
1652
1653 } else {
1654 $resp_code = $client->response_code();
1655 $resp_msg = $client->response_msg();
1656 }
1657
1658 my $expected;
1659
1660 $expected = 450;
1661 $self->assert($expected == $resp_code,
1662 test_msg("Expected $expected, got $resp_code"));
1663
1664 $expected = "$test_file: No such file or directory";
1665 $self->assert($expected eq $resp_msg,
1666 test_msg("Expected '$expected', got '$resp_msg'"));
1667 };
1668
1669 if ($@) {
1670 $ex = $@;
1671 }
1672
1673 $wfh->print("done\n");
1674 $wfh->flush();
1675
1676 } else {
1677 eval { server_wait($config_file, $rfh) };
1678 if ($@) {
1679 warn($@);
1680 exit 1;
1681 }
1682
1683 exit 0;
1684 }
1685
1686 # Stop server
1687 server_stop($pid_file);
1688
1689 $self->assert_child_ok($pid);
1690
1691 if ($ex) {
1692 test_append_logfile($log_file, $ex);
1693 unlink($log_file);
1694
1695 die($ex);
1696 }
1697
1698 unlink($log_file);
1699 }
1700
1701 sub list_fails_enoent_glob {
1702 my $self = shift;
1703 my $tmpdir = $self->{tmpdir};
1704
1705 my $config_file = "$tmpdir/cmds.conf";
1706 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1707 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1708
1709 my $log_file = test_get_logfile();
1710
1711 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1712 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1713
1714 my $user = 'proftpd';
1715 my $passwd = 'test';
1716 my $home_dir = File::Spec->rel2abs($tmpdir);
1717 my $uid = 500;
1718 my $gid = 500;
1719
1720 # Make sure that, if we're running as root, that the home directory has
1721 # permissions/privs set for the account we create
1722 if ($< == 0) {
1723 unless (chmod(0755, $home_dir)) {
1724 die("Can't set perms on $home_dir to 0755: $!");
1725 }
1726
1727 unless (chown($uid, $gid, $home_dir)) {
1728 die("Can't set owner of $home_dir to $uid/$gid: $!");
1729 }
1730 }
1731
1732 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1733 '/bin/bash');
1734 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1735
1736 my $config = {
1737 PidFile => $pid_file,
1738 ScoreboardFile => $scoreboard_file,
1739 SystemLog => $log_file,
1740
1741 AuthUserFile => $auth_user_file,
1742 AuthGroupFile => $auth_group_file,
1743 AuthOrder => 'mod_auth_file.c',
1744
1745 IfModules => {
1746 'mod_delay.c' => {
1747 DelayEngine => 'off',
1748 },
1749 },
1750 };
1751
1752 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1753
1754 # Open pipes, for use between the parent and child processes. Specifically,
1755 # the child will indicate when it's done with its test by writing a message
1756 # to the parent.
1757 my ($rfh, $wfh);
1758 unless (pipe($rfh, $wfh)) {
1759 die("Can't open pipe: $!");
1760 }
1761
1762 my $ex;
1763
1764 # Fork child
1765 $self->handle_sigchld();
1766 defined(my $pid = fork()) or die("Can't fork: $!");
1767 if ($pid) {
1768 eval {
1769 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1770
1771 $client->login($user, $passwd);
1772 $client->port();
1773
1774 my $test_glob = '*foo';
1775
1776 my ($resp_code, $resp_msg);
1777 ($resp_code, $resp_msg) = $client->list($test_glob);
1778
1779 # Unlike NLST, for LIST proftpd returns 226, and simply sends an
1780 # empty list.
1781
1782 $self->assert_transfer_ok($resp_code, $resp_msg);
1783 };
1784
1785 if ($@) {
1786 $ex = $@;
1787 }
1788
1789 $wfh->print("done\n");
1790 $wfh->flush();
1791
1792 } else {
1793 eval { server_wait($config_file, $rfh) };
1794 if ($@) {
1795 warn($@);
1796 exit 1;
1797 }
1798
1799 exit 0;
1800 }
1801
1802 # Stop server
1803 server_stop($pid_file);
1804
1805 $self->assert_child_ok($pid);
1806
1807 if ($ex) {
1808 test_append_logfile($log_file, $ex);
1809 unlink($log_file);
1810
1811 die($ex);
1812 }
1813
1814 unlink($log_file);
1815 }
1816
1817 sub list_fails_eperm {
1818 my $self = shift;
1819 my $tmpdir = $self->{tmpdir};
1820
1821 my $config_file = "$tmpdir/cmds.conf";
1822 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1823 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1824
1825 my $log_file = test_get_logfile();
1826
1827 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1828 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1829
1830 my $user = 'proftpd';
1831 my $passwd = 'test';
1832 my $home_dir = File::Spec->rel2abs($tmpdir);
1833 my $uid = 500;
1834 my $gid = 500;
1835
1836 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1837 mkpath($sub_dir);
1838
1839 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar");
1840 if (open(my $fh, "> $test_file")) {
1841 close($fh);
1842
1843 } else {
1844 die("Can't open $test_file: $!");
1845 }
1846
1847 # Make sure that, if we're running as root, that the home directory has
1848 # permissions/privs set for the account we create
1849 if ($< == 0) {
1850 unless (chmod(0755, $home_dir, $sub_dir)) {
1851 die("Can't set perms on $home_dir, $sub_dir to 0755: $!");
1852 }
1853
1854 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1855 die("Can't set owner of $home_dir, $sub_dir to $uid/$gid: $!");
1856 }
1857 }
1858
1859 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1860 '/bin/bash');
1861 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1862
1863 my $config = {
1864 PidFile => $pid_file,
1865 ScoreboardFile => $scoreboard_file,
1866 SystemLog => $log_file,
1867
1868 AuthUserFile => $auth_user_file,
1869 AuthGroupFile => $auth_group_file,
1870 AuthOrder => 'mod_auth_file.c',
1871
1872 IfModules => {
1873 'mod_delay.c' => {
1874 DelayEngine => 'off',
1875 },
1876 },
1877 };
1878
1879 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1880
1881 # Open pipes, for use between the parent and child processes. Specifically,
1882 # the child will indicate when it's done with its test by writing a message
1883 # to the parent.
1884 my ($rfh, $wfh);
1885 unless (pipe($rfh, $wfh)) {
1886 die("Can't open pipe: $!");
1887 }
1888
1889 my $ex;
1890
1891 # Fork child
1892 $self->handle_sigchld();
1893 defined(my $pid = fork()) or die("Can't fork: $!");
1894 if ($pid) {
1895 eval {
1896 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1897
1898 $client->login($user, $passwd);
1899 $client->port();
1900
1901 chmod(0660, $sub_dir);
1902
1903 my ($resp_code, $resp_msg);
1904 eval { ($resp_code, $resp_msg) = $client->list($test_file) };
1905 unless ($@) {
1906 die("LIST succeeded unexpectedly ($resp_code $resp_msg)");
1907
1908 } else {
1909 $resp_code = $client->response_code();
1910 $resp_msg = $client->response_msg();
1911 }
1912
1913 my $expected;
1914
1915 $expected = 450;
1916 $self->assert($expected == $resp_code,
1917 test_msg("Expected $expected, got $resp_code"));
1918
1919 $expected = "$test_file: Permission denied";
1920 $self->assert($expected eq $resp_msg,
1921 test_msg("Expected '$expected', got '$resp_msg'"));
1922 };
1923
1924 if ($@) {
1925 $ex = $@;
1926 }
1927
1928 $wfh->print("done\n");
1929 $wfh->flush();
1930
1931 } else {
1932 eval { server_wait($config_file, $rfh) };
1933 if ($@) {
1934 warn($@);
1935 exit 1;
1936 }
1937
1938 exit 0;
1939 }
1940
1941 # Stop server
1942 server_stop($pid_file);
1943
1944 $self->assert_child_ok($pid);
1945
1946 if ($ex) {
1947 test_append_logfile($log_file, $ex);
1948 unlink($log_file);
1949
1950 die($ex);
1951 }
1952
1953 unlink($log_file);
1954 }
1955
1956 sub list_bug2821 {
1957 my $self = shift;
1958 my $tmpdir = $self->{tmpdir};
1959
1960 my $config_file = "$tmpdir/cmds.conf";
1961 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1962 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1963
1964 my $log_file = test_get_logfile();
1965
1966 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1967 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1968
1969 my $user = 'proftpd';
1970 my $passwd = 'test';
1971 my $home_dir = File::Spec->rel2abs($tmpdir);
1972 my $uid = 500;
1973 my $gid = 500;
1974
1975 # Make sure that, if we're running as root, that the home directory has
1976 # permissions/privs set for the account we create
1977 if ($< == 0) {
1978 unless (chmod(0755, $home_dir)) {
1979 die("Can't set perms on $home_dir to 0755: $!");
1980 }
1981
1982 unless (chown($uid, $gid, $home_dir)) {
1983 die("Can't set owner of $home_dir to $uid/$gid: $!");
1984 }
1985 }
1986
1987 # For this test, we need to create MANY (i.e. 110K) files in the
1988 # home directory.
1989 my $test_file_prefix = File::Spec->rel2abs("$tmpdir/test_");
1990
1991 my $count = 110000;
1992 print STDOUT "# Creating $count files in $tmpdir\n";
1993 for (my $i = 1; $i <= $count; $i++) {
1994 my $test_file = 'test_' . sprintf("%07s", $i);
1995 my $test_path = "$home_dir/$test_file";
1996
1997 if (open(my $fh, "> $test_path")) {
1998 close($fh);
1999
2000 } else {
2001 die("Can't open $test_path: $!");
2002 }
2003
2004 if ($i % 10000 == 0) {
2005 print STDOUT "# Created file $test_file\n";
2006 }
2007 }
2008
2009 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2010 '/bin/bash');
2011 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2012
2013 my $timeout = 900;
2014
2015 my $config = {
2016 PidFile => $pid_file,
2017 ScoreboardFile => $scoreboard_file,
2018 SystemLog => $log_file,
2019 TraceLog => $log_file,
2020 Trace => 'DEFAULT:10 fsio:0 lock:0',
2021
2022 AuthUserFile => $auth_user_file,
2023 AuthGroupFile => $auth_group_file,
2024 AuthOrder => 'mod_auth_file.c',
2025
2026 TimeoutIdle => $timeout + 15,
2027 TimeoutNoTransfer => $timeout + 15,
2028
2029 IfModules => {
2030 'mod_delay.c' => {
2031 DelayEngine => 'off',
2032 },
2033 },
2034 };
2035
2036 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2037
2038 # Open pipes, for use between the parent and child processes. Specifically,
2039 # the child will indicate when it's done with its test by writing a message
2040 # to the parent.
2041 my ($rfh, $wfh);
2042 unless (pipe($rfh, $wfh)) {
2043 die("Can't open pipe: $!");
2044 }
2045
2046 my $ex;
2047
2048 # Fork child
2049 $self->handle_sigchld();
2050 defined(my $pid = fork()) or die("Can't fork: $!");
2051 if ($pid) {
2052 eval {
2053 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2054
2055 $client->login($user, $passwd);
2056
2057 # One of the symptoms of Bug#2821 is that a LIST (or NLST) glob
2058 # which matches more than 99999 files will not receive the full
2059 # list.
2060 #
2061 # The issue turned out to be the MAX_RESULTS (now
2062 # PR_TUNABLE_GLOBBING_MAX_MATCHES) limit in lib/glibc-glob.c.
2063 # So now, we deliberate make sure that the number of files returned
2064 # is less than the number of potential matches.
2065
2066 my $conn = $client->list_raw("-C test_*");
2067 unless ($conn) {
2068 die("LIST failed: " . $client->response_code() . " " .
2069 $client->response_msg());
2070 }
2071
2072 my $buf;
2073 my $tmp;
2074 while ($conn->read($tmp, 32768, $timeout)) {
2075 $buf .= $tmp;
2076 }
2077 eval { $conn->close() };
2078 $client->quit();
2079
2080 my $res = {};
2081
2082 # Preallocate memory for the expected hash size, to help speed up the
2083 # evaluation of the results.
2084 keys(%$res) = $count;
2085
2086 my $lines = [split(/\n/, $buf)];
2087 foreach my $line (@$lines) {
2088 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
2089 $res->{$line} = 1;
2090 }
2091 }
2092
2093 my $list_count = scalar(keys(%$res));
2094 if ($list_count >= $count) {
2095 die("LIST returned wrong number of entries (expected less than $count, got $list_count); check the PR_TUNABLE_GLOBBING_MAX_MATCHES value");
2096 }
2097
2098 };
2099
2100 if ($@) {
2101 $ex = $@;
2102 }
2103
2104 $wfh->print("done\n");
2105 $wfh->flush();
2106
2107 } else {
2108 eval { server_wait($config_file, $rfh, $timeout * 2) };
2109 if ($@) {
2110 warn($@);
2111 exit 1;
2112 }
2113
2114 exit 0;
2115 }
2116
2117 # Stop server
2118 server_stop($pid_file);
2119
2120 $self->assert_child_ok($pid);
2121
2122 if ($ex) {
2123 test_append_logfile($log_file, $ex);
2124 unlink($log_file);
2125
2126 die($ex);
2127 }
2128
2129 unlink($log_file);
2130 }
2131
2132 sub list_unsorted_buffering_bug4060 {
2133 my $self = shift;
2134 my $tmpdir = $self->{tmpdir};
2135
2136 my $config_file = "$tmpdir/cmds.conf";
2137 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2138 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2139
2140 my $log_file = test_get_logfile();
2141
2142 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2143 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2144
2145 my $user = 'proftpd';
2146 my $passwd = 'test';
2147 my $group = 'ftpd';
2148 my $home_dir = File::Spec->rel2abs($tmpdir);
2149 my $uid = 500;
2150 my $gid = 500;
2151
2152 # Make sure that, if we're running as root, that the home directory has
2153 # permissions/privs set for the account we create
2154 if ($< == 0) {
2155 unless (chmod(0755, $home_dir)) {
2156 die("Can't set perms on $home_dir to 0755: $!");
2157 }
2158
2159 unless (chown($uid, $gid, $home_dir)) {
2160 die("Can't set owner of $home_dir to $uid/$gid: $!");
2161 }
2162 }
2163
2164 # For this test, we need to create MANY (i.e. 110K) files in a subdirectory.
2165 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
2166 mkpath($test_dir);
2167
2168 my $count = 100000;
2169 print STDOUT "# Creating $count files in $test_dir\n";
2170 for (my $i = 1; $i <= $count; $i++) {
2171 my $test_file = 'test_' . sprintf("%07s", $i);
2172 my $test_path = "$test_dir/$test_file";
2173
2174 if (open(my $fh, "> $test_path")) {
2175 close($fh);
2176
2177 } else {
2178 die("Can't open $test_path: $!");
2179 }
2180
2181 if ($i % 10000 == 0) {
2182 print STDOUT "# Created file $test_file\n";
2183 }
2184 }
2185
2186 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2187 '/bin/bash');
2188 auth_group_write($auth_group_file, $group, $gid, $user);
2189
2190 my $timeout = 900;
2191
2192 my $config = {
2193 PidFile => $pid_file,
2194 ScoreboardFile => $scoreboard_file,
2195 SystemLog => $log_file,
2196 TraceLog => $log_file,
2197 Trace => 'DEFAULT:0 data:10 fsio:0 lock:0',
2198
2199 AuthUserFile => $auth_user_file,
2200 AuthGroupFile => $auth_group_file,
2201 AuthOrder => 'mod_auth_file.c',
2202
2203 TimeoutIdle => $timeout + 15,
2204 TimeoutNoTransfer => $timeout + 15,
2205
2206 IfModules => {
2207 'mod_delay.c' => {
2208 DelayEngine => 'off',
2209 },
2210 },
2211 };
2212
2213 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2214
2215 # Open pipes, for use between the parent and child processes. Specifically,
2216 # the child will indicate when it's done with its test by writing a message
2217 # to the parent.
2218 my ($rfh, $wfh);
2219 unless (pipe($rfh, $wfh)) {
2220 die("Can't open pipe: $!");
2221 }
2222
2223 my $ex;
2224
2225 # Fork child
2226 $self->handle_sigchld();
2227 defined(my $pid = fork()) or die("Can't fork: $!");
2228 if ($pid) {
2229 eval {
2230 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2231 $client->login($user, $passwd);
2232
2233 my $conn = $client->list_raw('-U test.d');
2234 unless ($conn) {
2235 die("LIST failed: " . $client->response_code() . " " .
2236 $client->response_msg());
2237 }
2238
2239 my $list_start = [gettimeofday()];
2240
2241 my $buf;
2242 my $tmp;
2243 while ($conn->read($tmp, 32768, $timeout)) {
2244 $buf .= $tmp;
2245 }
2246 eval { $conn->close() };
2247
2248 my $list_elapsed = tv_interval($list_start);
2249
2250 $client->quit();
2251
2252 my $res = {};
2253
2254 # Preallocate memory for the expected hash size, to help speed up the
2255 # evaluation of the results.
2256 keys(%$res) = $count;
2257
2258 my $lines = [split(/\n/, $buf)];
2259 foreach my $line (@$lines) {
2260 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
2261 $res->{$line} = 1;
2262 }
2263 }
2264
2265 my $list_count = scalar(keys(%$res));
2266 $self->assert($list_count == $count,
2267 test_msg("LIST returned wrong number of entries (expected $count, got $list_count)"));
2268
2269 if ($ENV{TEST_VERBOSE}) {
2270 print STDERR "# LIST elapsed time: $list_elapsed\n";
2271 }
2272 };
2273
2274 if ($@) {
2275 $ex = $@;
2276 }
2277
2278 $wfh->print("done\n");
2279 $wfh->flush();
2280
2281 } else {
2282 eval { server_wait($config_file, $rfh, $timeout * 2) };
2283 if ($@) {
2284 warn($@);
2285 exit 1;
2286 }
2287
2288 exit 0;
2289 }
2290
2291 # Stop server
2292 server_stop($pid_file);
2293
2294 $self->assert_child_ok($pid);
2295
2296 if ($ex) {
2297 test_append_logfile($log_file, $ex);
2298 unlink($log_file);
2299
2300 die($ex);
2301 }
2302
2303 unlink($log_file);
2304 }
2305
2306 sub list_opt_C {
2307 my $self = shift;
2308 my $tmpdir = $self->{tmpdir};
2309
2310 my $config_file = "$tmpdir/cmds.conf";
2311 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2312 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2313
2314 my $log_file = test_get_logfile();
2315
2316 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2317 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2318
2319 my $user = 'proftpd';
2320 my $passwd = 'test';
2321 my $home_dir = File::Spec->rel2abs($tmpdir);
2322 my $uid = 500;
2323 my $gid = 500;
2324
2325 # Make sure that, if we're running as root, that the home directory has
2326 # permissions/privs set for the account we create
2327 if ($< == 0) {
2328 unless (chmod(0755, $home_dir)) {
2329 die("Can't set perms on $home_dir to 0755: $!");
2330 }
2331
2332 unless (chown($uid, $gid, $home_dir)) {
2333 die("Can't set owner of $home_dir to $uid/$gid: $!");
2334 }
2335 }
2336
2337 # For this test, we need to create about 100 files in home directory.
2338 my $test_file_prefix = File::Spec->rel2abs($tmpdir);
2339
2340 my $count = 100;
2341 print STDOUT "# Creating $count files in $tmpdir\n";
2342 for (my $i = 1; $i <= $count; $i++) {
2343 my $test_file = sprintf("%04s", $i);
2344 my $test_path = "$home_dir/$test_file";
2345
2346 if (open(my $fh, "> $test_path")) {
2347 close($fh);
2348
2349 } else {
2350 die("Can't open $test_path: $!");
2351 }
2352 }
2353
2354 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2355 '/bin/bash');
2356 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2357
2358 my $config = {
2359 PidFile => $pid_file,
2360 ScoreboardFile => $scoreboard_file,
2361 SystemLog => $log_file,
2362
2363 AuthUserFile => $auth_user_file,
2364 AuthGroupFile => $auth_group_file,
2365 AuthOrder => 'mod_auth_file.c',
2366
2367 IfModules => {
2368 'mod_delay.c' => {
2369 DelayEngine => 'off',
2370 },
2371 },
2372 };
2373
2374 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2375
2376 # Open pipes, for use between the parent and child processes. Specifically,
2377 # the child will indicate when it's done with its test by writing a message
2378 # to the parent.
2379 my ($rfh, $wfh);
2380 unless (pipe($rfh, $wfh)) {
2381 die("Can't open pipe: $!");
2382 }
2383
2384 my $ex;
2385
2386 # Fork child
2387 $self->handle_sigchld();
2388 defined(my $pid = fork()) or die("Can't fork: $!");
2389 if ($pid) {
2390 eval {
2391 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2392
2393 $client->login($user, $passwd);
2394
2395 my $conn = $client->list_raw("-C 0*");
2396 unless ($conn) {
2397 die("LIST failed: " . $client->response_code() . " " .
2398 $client->response_msg());
2399 }
2400
2401 my $buf;
2402 $conn->read($buf, 32768, 30);
2403 eval { $conn->close() };
2404
2405 my $res = {};
2406 my $lines = [split(/\n/, $buf)];
2407 foreach my $line (@$lines) {
2408 if ($line =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/) {
2409 $res->{$1} = 1;
2410 $res->{$2} = 1;
2411 $res->{$3} = 1;
2412 $res->{$4} = 1;
2413 $res->{$5} = 1;
2414 $res->{$6} = 1;
2415 $res->{$7} = 1;
2416 $res->{$8} = 1;
2417 $res->{$9} = 1;
2418
2419 } elsif ($line =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/) {
2420 $res->{$1} = 1;
2421 $res->{$2} = 1;
2422 $res->{$3} = 1;
2423 $res->{$4} = 1;
2424 $res->{$5} = 1;
2425 $res->{$6} = 1;
2426 $res->{$7} = 1;
2427 $res->{$8} = 1;
2428 }
2429 }
2430
2431 my $list_count = scalar(keys(%$res));
2432 unless ($list_count == $count) {
2433 die("LIST returned wrong number of entries (expected $count, got $list_count)");
2434 }
2435 };
2436
2437 if ($@) {
2438 $ex = $@;
2439 }
2440
2441 $wfh->print("done\n");
2442 $wfh->flush();
2443
2444 } else {
2445 eval { server_wait($config_file, $rfh) };
2446 if ($@) {
2447 warn($@);
2448 exit 1;
2449 }
2450
2451 exit 0;
2452 }
2453
2454 # Stop server
2455 server_stop($pid_file);
2456
2457 $self->assert_child_ok($pid);
2458
2459 if ($ex) {
2460 test_append_logfile($log_file, $ex);
2461 unlink($log_file);
2462
2463 die($ex);
2464 }
2465
2466 unlink($log_file);
2467 }
2468
2469 sub list_nonascii_chars_bug3032 {
2470 my $self = shift;
2471 my $tmpdir = $self->{tmpdir};
2472
2473 if (feature_have_feature_enabled('nls')) {
2474 # This test is only valid if NLS support is not enabled.
2475 return;
2476 }
2477
2478 my $config_file = "$tmpdir/cmds.conf";
2479 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2480 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2481
2482 my $log_file = test_get_logfile();
2483
2484 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2485 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2486
2487 my $user = 'proftpd';
2488 my $passwd = 'test';
2489 my $home_dir = File::Spec->rel2abs($tmpdir);
2490 my $uid = 500;
2491 my $gid = 500;
2492
2493 # Make sure that, if we're running as root, that the home directory has
2494 # permissions/privs set for the account we create
2495 if ($< == 0) {
2496 unless (chmod(0755, $home_dir)) {
2497 die("Can't set perms on $home_dir to 0755: $!");
2498 }
2499
2500 unless (chown($uid, $gid, $home_dir)) {
2501 die("Can't set owner of $home_dir to $uid/$gid: $!");
2502 }
2503 }
2504
2505 my $test_file = File::Spec->rel2abs("$tmpdir/" . sprintf("test\b"));
2506 if (open(my $fh, "> $test_file")) {
2507 close($fh);
2508
2509 } else {
2510 die("Can't open $test_file: $!");
2511 }
2512
2513 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2514 '/bin/bash');
2515 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2516
2517 my $config = {
2518 PidFile => $pid_file,
2519 ScoreboardFile => $scoreboard_file,
2520 SystemLog => $log_file,
2521
2522 AuthUserFile => $auth_user_file,
2523 AuthGroupFile => $auth_group_file,
2524 AuthOrder => 'mod_auth_file.c',
2525
2526 IfModules => {
2527 'mod_delay.c' => {
2528 DelayEngine => 'off',
2529 },
2530 },
2531 };
2532
2533 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2534
2535 # Open pipes, for use between the parent and child processes. Specifically,
2536 # the child will indicate when it's done with its test by writing a message
2537 # to the parent.
2538 my ($rfh, $wfh);
2539 unless (pipe($rfh, $wfh)) {
2540 die("Can't open pipe: $!");
2541 }
2542
2543 my $ex;
2544
2545 # Fork child
2546 $self->handle_sigchld();
2547 defined(my $pid = fork()) or die("Can't fork: $!");
2548 if ($pid) {
2549 eval {
2550 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2551
2552 $client->login($user, $passwd);
2553
2554 my $conn = $client->list_raw("-B test*");
2555 unless ($conn) {
2556 die("LIST failed: " . $client->response_code() . " " .
2557 $client->response_msg());
2558 }
2559
2560 my $buf;
2561 $conn->read($buf, 32768, 30);
2562 eval { $conn->close() };
2563
2564 my $res = {};
2565 my $lines = [split(/\n/, $buf)];
2566 foreach my $line (@$lines) {
2567 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
2568 $res->{$1} = 1;
2569 }
2570 }
2571
2572 my $expected = {
2573 'test\010' => 1,
2574 };
2575
2576 my $ok = 1;
2577 my $mismatch;
2578 foreach my $name (keys(%$res)) {
2579 unless (defined($expected->{$name})) {
2580 $mismatch = $name;
2581 $ok = 0;
2582 last;
2583 }
2584 }
2585
2586 unless ($ok) {
2587 die("Unexpected name '$mismatch' appeared in LIST data")
2588 }
2589 };
2590
2591 if ($@) {
2592 $ex = $@;
2593 }
2594
2595 $wfh->print("done\n");
2596 $wfh->flush();
2597
2598 } else {
2599 eval { server_wait($config_file, $rfh) };
2600 if ($@) {
2601 warn($@);
2602 exit 1;
2603 }
2604
2605 exit 0;
2606 }
2607
2608 # Stop server
2609 server_stop($pid_file);
2610
2611 $self->assert_child_ok($pid);
2612
2613 if ($ex) {
2614 test_append_logfile($log_file, $ex);
2615 unlink($log_file);
2616
2617 die($ex);
2618 }
2619
2620 unlink($log_file);
2621 }
2622
2623 sub list_leading_whitespace_bug3268 {
2624 my $self = shift;
2625 my $tmpdir = $self->{tmpdir};
2626
2627 my $config_file = "$tmpdir/cmds.conf";
2628 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2629 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2630
2631 my $log_file = test_get_logfile();
2632
2633 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2634 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2635
2636 my $user = 'proftpd';
2637 my $passwd = 'test';
2638 my $home_dir = File::Spec->rel2abs($tmpdir);
2639 my $uid = 500;
2640 my $gid = 500;
2641
2642 # Make sure that, if we're running as root, that the home directory has
2643 # permissions/privs set for the account we create
2644 if ($< == 0) {
2645 unless (chmod(0755, $home_dir)) {
2646 die("Can't set perms on $home_dir to 0755: $!");
2647 }
2648
2649 unless (chown($uid, $gid, $home_dir)) {
2650 die("Can't set owner of $home_dir to $uid/$gid: $!");
2651 }
2652 }
2653
2654 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2655 '/bin/bash');
2656 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2657
2658 my $test_file = File::Spec->rel2abs("$tmpdir/ test.txt");
2659 if (open(my $fh, "> $test_file")) {
2660 close($fh);
2661
2662 } else {
2663 die("Can't open '$test_file': $!");
2664 }
2665
2666 my $config = {
2667 PidFile => $pid_file,
2668 ScoreboardFile => $scoreboard_file,
2669 SystemLog => $log_file,
2670
2671 AuthUserFile => $auth_user_file,
2672 AuthGroupFile => $auth_group_file,
2673 AuthOrder => 'mod_auth_file.c',
2674
2675 IfModules => {
2676 'mod_delay.c' => {
2677 DelayEngine => 'off',
2678 },
2679 },
2680 };
2681
2682 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2683
2684 # Open pipes, for use between the parent and child processes. Specifically,
2685 # the child will indicate when it's done with its test by writing a message
2686 # to the parent.
2687 my ($rfh, $wfh);
2688 unless (pipe($rfh, $wfh)) {
2689 die("Can't open pipe: $!");
2690 }
2691
2692 my $ex;
2693
2694 # Fork child
2695 $self->handle_sigchld();
2696 defined(my $pid = fork()) or die("Can't fork: $!");
2697 if ($pid) {
2698 eval {
2699 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2700 $client->login($user, $passwd);
2701
2702 my $conn = $client->list_raw(' test.txt');
2703 unless ($conn) {
2704 die("Failed to LIST: " . $client->response_code() . " " .
2705 $client->response_msg());
2706 }
2707
2708 my $buf;
2709 $conn->read($buf, 8192, 30);
2710 eval { $conn->close() };
2711
2712 my $resp_code = $client->response_code();
2713 my $resp_msg = $client->response_msg();
2714 $self->assert_transfer_ok($resp_code, $resp_msg);
2715
2716 # We have to be careful of the fact that readdir returns directory
2717 # entries in an unordered fashion.
2718 my $res = {};
2719 my $lines = [split(/\n/, $buf)];
2720 foreach my $line (@$lines) {
2721 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+ (.*?)$/) {
2722 $res->{$1} = 1;
2723 }
2724 }
2725
2726 my $expected = {
2727 ' test.txt' => 1,
2728 };
2729
2730 my $ok = 1;
2731 my $mismatch;
2732 foreach my $name (keys(%$res)) {
2733 unless (defined($expected->{$name})) {
2734 $mismatch = $name;
2735 $ok = 0;
2736 last;
2737 }
2738 }
2739
2740 unless ($ok) {
2741 die("Unexpected name '$mismatch' appeared in LIST data")
2742 }
2743 };
2744
2745 if ($@) {
2746 $ex = $@;
2747 }
2748
2749 $wfh->print("done\n");
2750 $wfh->flush();
2751
2752 } else {
2753 eval { server_wait($config_file, $rfh) };
2754 if ($@) {
2755 warn($@);
2756 exit 1;
2757 }
2758
2759 exit 0;
2760 }
2761
2762 # Stop server
2763 server_stop($pid_file);
2764
2765 $self->assert_child_ok($pid);
2766
2767 if ($ex) {
2768 test_append_logfile($log_file, $ex);
2769 unlink($log_file);
2770
2771 die($ex);
2772 }
2773
2774 unlink($log_file);
2775 }
2776
2777 sub list_leading_whitespace_with_opts_bug3268 {
2778 my $self = shift;
2779 my $tmpdir = $self->{tmpdir};
2780
2781 my $config_file = "$tmpdir/cmds.conf";
2782 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2783 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2784
2785 my $log_file = test_get_logfile();
2786
2787 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2788 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2789
2790 my $user = 'proftpd';
2791 my $passwd = 'test';
2792 my $home_dir = File::Spec->rel2abs($tmpdir);
2793 my $uid = 500;
2794 my $gid = 500;
2795
2796 # Make sure that, if we're running as root, that the home directory has
2797 # permissions/privs set for the account we create
2798 if ($< == 0) {
2799 unless (chmod(0755, $home_dir)) {
2800 die("Can't set perms on $home_dir to 0755: $!");
2801 }
2802
2803 unless (chown($uid, $gid, $home_dir)) {
2804 die("Can't set owner of $home_dir to $uid/$gid: $!");
2805 }
2806 }
2807
2808 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2809 '/bin/bash');
2810 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2811
2812 my $test_file = File::Spec->rel2abs("$tmpdir/ test.txt");
2813 if (open(my $fh, "> $test_file")) {
2814 close($fh);
2815
2816 } else {
2817 die("Can't open '$test_file': $!");
2818 }
2819
2820 my $config = {
2821 PidFile => $pid_file,
2822 ScoreboardFile => $scoreboard_file,
2823 SystemLog => $log_file,
2824
2825 AuthUserFile => $auth_user_file,
2826 AuthGroupFile => $auth_group_file,
2827 AuthOrder => 'mod_auth_file.c',
2828
2829 IfModules => {
2830 'mod_delay.c' => {
2831 DelayEngine => 'off',
2832 },
2833 },
2834 };
2835
2836 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2837
2838 # Open pipes, for use between the parent and child processes. Specifically,
2839 # the child will indicate when it's done with its test by writing a message
2840 # to the parent.
2841 my ($rfh, $wfh);
2842 unless (pipe($rfh, $wfh)) {
2843 die("Can't open pipe: $!");
2844 }
2845
2846 my $ex;
2847
2848 # Fork child
2849 $self->handle_sigchld();
2850 defined(my $pid = fork()) or die("Can't fork: $!");
2851 if ($pid) {
2852 eval {
2853 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2854 $client->login($user, $passwd);
2855
2856 my $conn = $client->list_raw('-a -b test.txt');
2857 unless ($conn) {
2858 die("Failed to LIST: " . $client->response_code() . " " .
2859 $client->response_msg());
2860 }
2861
2862 my $buf;
2863 $conn->read($buf, 8192, 30);
2864 eval { $conn->close() };
2865
2866 my $resp_code = $client->response_code();
2867 my $resp_msg = $client->response_msg();
2868 $self->assert_transfer_ok($resp_code, $resp_msg);
2869
2870 # We have to be careful of the fact that readdir returns directory
2871 # entries in an unordered fashion.
2872 my $res = {};
2873 my $lines = [split(/\n/, $buf)];
2874 foreach my $line (@$lines) {
2875 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+ (.*?)$/) {
2876 $res->{$1} = 1;
2877 }
2878 }
2879
2880 my $expected = {
2881 ' test.txt' => 1,
2882 };
2883
2884 my $ok = 1;
2885 my $mismatch;
2886 foreach my $name (keys(%$res)) {
2887 unless (defined($expected->{$name})) {
2888 $mismatch = $name;
2889 $ok = 0;
2890 last;
2891 }
2892 }
2893
2894 unless ($ok) {
2895 die("Unexpected name '$mismatch' appeared in LIST data")
2896 }
2897 };
2898
2899 if ($@) {
2900 $ex = $@;
2901 }
2902
2903 $wfh->print("done\n");
2904 $wfh->flush();
2905
2906 } else {
2907 eval { server_wait($config_file, $rfh) };
2908 if ($@) {
2909 warn($@);
2910 exit 1;
2911 }
2912
2913 exit 0;
2914 }
2915
2916 # Stop server
2917 server_stop($pid_file);
2918
2919 $self->assert_child_ok($pid);
2920
2921 if ($ex) {
2922 test_append_logfile($log_file, $ex);
2923 unlink($log_file);
2924
2925 die($ex);
2926 }
2927
2928 unlink($log_file);
2929 }
2930
2931 sub list_leading_whitespace_with_strict_opts_bug3268 {
2932 my $self = shift;
2933 my $tmpdir = $self->{tmpdir};
2934
2935 my $config_file = "$tmpdir/cmds.conf";
2936 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2937 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2938
2939 my $log_file = test_get_logfile();
2940
2941 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2942 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2943
2944 my $user = 'proftpd';
2945 my $passwd = 'test';
2946 my $home_dir = File::Spec->rel2abs($tmpdir);
2947 my $uid = 500;
2948 my $gid = 500;
2949
2950 # Make sure that, if we're running as root, that the home directory has
2951 # permissions/privs set for the account we create
2952 if ($< == 0) {
2953 unless (chmod(0755, $home_dir)) {
2954 die("Can't set perms on $home_dir to 0755: $!");
2955 }
2956
2957 unless (chown($uid, $gid, $home_dir)) {
2958 die("Can't set owner of $home_dir to $uid/$gid: $!");
2959 }
2960 }
2961
2962 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2963 '/bin/bash');
2964 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2965
2966 my $test_file = File::Spec->rel2abs("$tmpdir/ test.txt");
2967 if (open(my $fh, "> $test_file")) {
2968 close($fh);
2969
2970 } else {
2971 die("Can't open '$test_file': $!");
2972 }
2973
2974 my $config = {
2975 PidFile => $pid_file,
2976 ScoreboardFile => $scoreboard_file,
2977 SystemLog => $log_file,
2978
2979 AuthUserFile => $auth_user_file,
2980 AuthGroupFile => $auth_group_file,
2981 AuthOrder => 'mod_auth_file.c',
2982
2983 ListOptions => '"-a +R" strict',
2984
2985 IfModules => {
2986 'mod_delay.c' => {
2987 DelayEngine => 'off',
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 $client->login($user, $passwd);
3011
3012 my $conn = $client->list_raw('-a -b test.txt');
3013 unless ($conn) {
3014 die("Failed to LIST: " . $client->response_code() . " " .
3015 $client->response_msg());
3016 }
3017
3018 my $buf;
3019 $conn->read($buf, 8192, 30);
3020 eval { $conn->close() };
3021
3022 my $resp_code = $client->response_code();
3023 my $resp_msg = $client->response_msg();
3024 $self->assert_transfer_ok($resp_code, $resp_msg);
3025
3026 # We have to be careful of the fact that readdir returns directory
3027 # entries in an unordered fashion.
3028 my $res = {};
3029 my $lines = [split(/\n/, $buf)];
3030 foreach my $line (@$lines) {
3031 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+ (.*?)$/) {
3032 $res->{$1} = 1;
3033 }
3034 }
3035
3036 my $expected = {
3037 ' test.txt' => 1,
3038 };
3039
3040 my $ok = 1;
3041 my $mismatch;
3042 foreach my $name (keys(%$res)) {
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 LIST data")
3052 }
3053 };
3054
3055 if ($@) {
3056 $ex = $@;
3057 }
3058
3059 $wfh->print("done\n");
3060 $wfh->flush();
3061
3062 } else {
3063 eval { server_wait($config_file, $rfh) };
3064 if ($@) {
3065 warn($@);
3066 exit 1;
3067 }
3068
3069 exit 0;
3070 }
3071
3072 # Stop server
3073 server_stop($pid_file);
3074
3075 $self->assert_child_ok($pid);
3076
3077 if ($ex) {
3078 test_append_logfile($log_file, $ex);
3079 unlink($log_file);
3080
3081 die($ex);
3082 }
3083
3084 unlink($log_file);
3085 }
3086
3087 sub list_symlink_bug3254 {
3088 my $self = shift;
3089 my $tmpdir = $self->{tmpdir};
3090
3091 my $config_file = "$tmpdir/cmds.conf";
3092 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
3093 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
3094
3095 my $log_file = test_get_logfile();
3096
3097 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
3098 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
3099
3100 my $user = 'proftpd';
3101 my $passwd = 'test';
3102 my $home_dir = File::Spec->rel2abs($tmpdir);
3103 my $uid = 500;
3104 my $gid = 500;
3105
3106 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
3107 my $bar_dir = File::Spec->rel2abs("$tmpdir/bar");
3108 my $baz_dir = File::Spec->rel2abs("$tmpdir/bar/baz");
3109 my $quxx_dir = File::Spec->rel2abs("$tmpdir/bar/quxx");
3110 mkpath([$foo_dir, $bar_dir, $baz_dir, $quxx_dir]);
3111
3112 # Change to the 'foo' directory in order to create a relative path in the
3113 # symlink we need
3114
3115 my $cwd = getcwd();
3116 unless (chdir("$foo_dir")) {
3117 die("Can't chdir to $foo_dir: $!");
3118 }
3119
3120 unless (symlink('../bar/baz', 'baz')) {
3121 die("Can't symlink '../bar/baz' to 'baz': $!");
3122 }
3123
3124 unless (chdir($cwd)) {
3125 die("Can't chdir to $cwd: $!");
3126 }
3127
3128 my $ftpaccess_file = File::Spec->rel2abs("$foo_dir/.ftpaccess");
3129 if (open(my $fh, "> $ftpaccess_file")) {
3130 print $fh <<EOL;
3131 <Limit ALL>
3132 AllowUser $user
3133 DenyAll
3134 </Limit>
3135 EOL
3136 unless (close($fh)) {
3137 die("Can't write $ftpaccess_file: $!");
3138 }
3139
3140 } else {
3141 die("Can't open $ftpaccess_file: $!");
3142 }
3143
3144 $ftpaccess_file = File::Spec->rel2abs("$bar_dir/.ftpaccess");
3145 if (open(my $fh, "> $ftpaccess_file")) {
3146 print $fh <<EOL;
3147 <Limit ALL>
3148 AllowUser bar
3149 DenyAll
3150 </Limit>
3151 EOL
3152 unless (close($fh)) {
3153 die("Can't write $ftpaccess_file: $!");
3154 }
3155
3156 } else {
3157 die("Can't open $ftpaccess_file: $!");
3158 }
3159
3160 $ftpaccess_file = File::Spec->rel2abs("$baz_dir/.ftpaccess");
3161 if (open(my $fh, "> $ftpaccess_file")) {
3162 print $fh <<EOL;
3163 <Limit ALL>
3164 AllowUser bar,$user
3165 DenyAll
3166 </Limit>
3167 EOL
3168 unless (close($fh)) {
3169 die("Can't write $ftpaccess_file: $!");
3170 }
3171
3172 } else {
3173 die("Can't open $ftpaccess_file: $!");
3174 }
3175
3176 $ftpaccess_file = File::Spec->rel2abs("$quxx_dir/.ftpaccess");
3177 if (open(my $fh, "> $ftpaccess_file")) {
3178 print $fh <<EOL;
3179 <Limit ALL>
3180 AllowUser bar,$user,
3181 DenyAll
3182 </Limit>
3183 EOL
3184 unless (close($fh)) {
3185 die("Can't write $ftpaccess_file: $!");
3186 }
3187
3188 } else {
3189 die("Can't open $ftpaccess_file: $!");
3190 }
3191
3192 # Make sure that, if we're running as root, that the home directory has
3193 # permissions/privs set for the account we create
3194 if ($< == 0) {
3195 unless (chmod(0755, $home_dir, $foo_dir, $bar_dir, $baz_dir, $quxx_dir)) {
3196 die("Can't set perms on dirs to 0755: $!");
3197 }
3198
3199 unless (chown($uid, $gid, $home_dir, $foo_dir, $bar_dir, $baz_dir, $quxx_dir)) {
3200 die("Can't set owner of dirs to $uid/$gid: $!");
3201 }
3202 }
3203
3204 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3205 '/bin/bash');
3206 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
3207
3208 my $config = {
3209 PidFile => $pid_file,
3210 ScoreboardFile => $scoreboard_file,
3211 SystemLog => $log_file,
3212
3213 AuthUserFile => $auth_user_file,
3214 AuthGroupFile => $auth_group_file,
3215 AuthOrder => 'mod_auth_file.c',
3216
3217 AllowOverride => 'on',
3218 DefaultRoot => '~',
3219 ShowSymlinks => 'off',
3220
3221 IfModules => {
3222 'mod_delay.c' => {
3223 DelayEngine => 'off',
3224 },
3225 },
3226 };
3227
3228 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3229
3230 # Open pipes, for use between the parent and child processes. Specifically,
3231 # the child will indicate when it's done with its test by writing a message
3232 # to the parent.
3233 my ($rfh, $wfh);
3234 unless (pipe($rfh, $wfh)) {
3235 die("Can't open pipe: $!");
3236 }
3237
3238 my $ex;
3239
3240 # Fork child
3241 $self->handle_sigchld();
3242 defined(my $pid = fork()) or die("Can't fork: $!");
3243 if ($pid) {
3244 eval {
3245 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3246
3247 $client->login($user, $passwd);
3248
3249 $client->cwd("foo/baz");
3250 my $conn = $client->list_raw();
3251 unless ($conn) {
3252 die("Failed to LIST: " . $client->response_code() . " " .
3253 $client->response_msg());
3254 }
3255
3256 my $buf;
3257 $conn->read($buf, 8192, 30);
3258 eval { $conn->close() };
3259
3260 my $resp_code = $client->response_code();
3261 my $resp_msg = $client->response_msg();
3262 $self->assert_transfer_ok($resp_code, $resp_msg);
3263
3264 $client->quote('CWD', '..');
3265 $client->quit();
3266 };
3267
3268 if ($@) {
3269 $ex = $@;
3270 }
3271
3272 $wfh->print("done\n");
3273 $wfh->flush();
3274
3275 } else {
3276 eval { server_wait($config_file, $rfh) };
3277 if ($@) {
3278 warn($@);
3279 exit 1;
3280 }
3281
3282 exit 0;
3283 }
3284
3285 # Stop server
3286 server_stop($pid_file);
3287
3288 $self->assert_child_ok($pid);
3289
3290 if ($ex) {
3291 test_append_logfile($log_file, $ex);
3292 unlink($log_file);
3293
3294 die($ex);
3295 }
3296
3297 unlink($log_file);
3298 }
3299
3300 sub list_symlink_issue697 {
3301 my $self = shift;
3302 my $tmpdir = $self->{tmpdir};
3303
3304 my $config_file = "$tmpdir/cmds.conf";
3305 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
3306 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
3307
3308 my $log_file = test_get_logfile();
3309
3310 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
3311 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
3312
3313 my $user = 'proftpd';
3314 my $passwd = 'test';
3315 my $home_dir = File::Spec->rel2abs($tmpdir);
3316 my $uid = 500;
3317 my $gid = 500;
3318
3319 my $a_dir = File::Spec->rel2abs("$tmpdir/a");
3320 my $b_dir = File::Spec->rel2abs("$tmpdir/b");
3321 mkpath([$a_dir, $b_dir]);
3322
3323 my $a_file = File::Spec->rel2abs("$a_dir/file");
3324 if (open(my $fh, "> $a_file")) {
3325 close($fh);
3326
3327 } else {
3328 die("Can't open $a_file: $!");
3329 }
3330
3331 # Change to the 'b' directory in order to create a relative path in the
3332 # symlink we need
3333
3334 my $cwd = getcwd();
3335 unless (chdir("$b_dir")) {
3336 die("Can't chdir to $b_dir: $!");
3337 }
3338
3339 unless (symlink('../file', 'link')) {
3340 die("Can't symlink '../file' to 'link': $!");
3341 }
3342
3343 unless (chdir($cwd)) {
3344 die("Can't chdir to $cwd: $!");
3345 }
3346
3347 # Make sure that, if we're running as root, that the home directory has
3348 # permissions/privs set for the account we create
3349 if ($< == 0) {
3350 unless (chmod(0755, $home_dir, $a_dir, $b_dir)) {
3351 die("Can't set perms on dirs to 0755: $!");
3352 }
3353
3354 unless (chown($uid, $gid, $home_dir, $a_dir, $b_dir)) {
3355 die("Can't set owner of dirs to $uid/$gid: $!");
3356 }
3357 }
3358
3359 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3360 '/bin/bash');
3361 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
3362
3363 my $config = {
3364 PidFile => $pid_file,
3365 ScoreboardFile => $scoreboard_file,
3366 SystemLog => $log_file,
3367
3368 AuthUserFile => $auth_user_file,
3369 AuthGroupFile => $auth_group_file,
3370 AuthOrder => 'mod_auth_file.c',
3371
3372 AllowOverride => 'on',
3373 DefaultRoot => '~',
3374 ListOptions => '-al NoAdjustedSymlinks',
3375
3376 IfModules => {
3377 'mod_delay.c' => {
3378 DelayEngine => 'off',
3379 },
3380 },
3381 };
3382
3383 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3384
3385 # Open pipes, for use between the parent and child processes. Specifically,
3386 # the child will indicate when it's done with its test by writing a message
3387 # to the parent.
3388 my ($rfh, $wfh);
3389 unless (pipe($rfh, $wfh)) {
3390 die("Can't open pipe: $!");
3391 }
3392
3393 my $ex;
3394
3395 # Fork child
3396 $self->handle_sigchld();
3397 defined(my $pid = fork()) or die("Can't fork: $!");
3398 if ($pid) {
3399 eval {
3400 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3401
3402 $client->login($user, $passwd);
3403
3404 $client->cwd("b");
3405 my $conn = $client->list_raw();
3406 unless ($conn) {
3407 die("Failed to LIST: " . $client->response_code() . " " .
3408 $client->response_msg());
3409 }
3410
3411 my $buf;
3412 $conn->read($buf, 8192, 30);
3413 eval { $conn->close() };
3414
3415 if ($ENV{TEST_VERBOSE}) {
3416 print STDERR "# LIST:\n$buf\n";
3417 }
3418
3419 my $resp_code = $client->response_code();
3420 my $resp_msg = $client->response_msg();
3421 $self->assert_transfer_ok($resp_code, $resp_msg);
3422
3423 $client->quit();
3424 };
3425
3426 if ($@) {
3427 $ex = $@;
3428 }
3429
3430 $wfh->print("done\n");
3431 $wfh->flush();
3432
3433 } else {
3434 eval { server_wait($config_file, $rfh) };
3435 if ($@) {
3436 warn($@);
3437 exit 1;
3438 }
3439
3440 exit 0;
3441 }
3442
3443 # Stop server
3444 server_stop($pid_file);
3445
3446 $self->assert_child_ok($pid);
3447
3448 if ($ex) {
3449 test_append_logfile($log_file, $ex);
3450 unlink($log_file);
3451
3452 die($ex);
3453 }
3454
3455 unlink($log_file);
3456 }
3457
3458 sub list_symlink_issue940 {
3459 my $self = shift;
3460 my $tmpdir = $self->{tmpdir};
3461 my $setup = test_setup($tmpdir, 'list');
3462
3463 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
3464 mkpath($test_dir);
3465
3466 my $dst_dir = File::Spec->rel2abs("$test_dir/dst.d");
3467 my $src_symlink = File::Spec->rel2abs("$test_dir/src.lnk");
3468 mkpath($dst_dir);
3469
3470 my $cwd = getcwd();
3471 unless (chdir($test_dir)) {
3472 die("Can't chdir to $test_dir: $!");
3473 }
3474
3475 unless (symlink('dst.d', 'src.link')) {
3476 die("Can't symlink 'dst.d' to 'src.lnk': $!");
3477 }
3478
3479 unless (chdir($cwd)) {
3480 die("Can't chdir to $cwd: $!");
3481 }
3482
3483 my $config = {
3484 PidFile => $setup->{pid_file},
3485 ScoreboardFile => $setup->{scoreboard_file},
3486 SystemLog => $setup->{log_file},
3487 TraceLog => $setup->{log_file},
3488
3489 AuthUserFile => $setup->{auth_user_file},
3490 AuthGroupFile => $setup->{auth_group_file},
3491 AuthOrder => 'mod_auth_file.c',
3492
3493 ListOptions => '-la',
3494
3495 IfModules => {
3496 'mod_delay.c' => {
3497 DelayEngine => 'off',
3498 },
3499 },
3500 };
3501
3502 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3503 $config);
3504
3505 # Open pipes, for use between the parent and child processes. Specifically,
3506 # the child will indicate when it's done with its test by writing a message
3507 # to the parent.
3508 my ($rfh, $wfh);
3509 unless (pipe($rfh, $wfh)) {
3510 die("Can't open pipe: $!");
3511 }
3512 my $ex;
3513 # Fork child
3514 $self->handle_sigchld();
3515 defined(my $pid = fork()) or die("Can't fork: $!");
3516 if ($pid) {
3517 eval {
3518 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3519 $client->login($setup->{user}, $setup->{passwd});
3520
3521 my $list_target = 'test.d';
3522 my $conn = $client->list_raw($list_target);
3523 unless ($conn) {
3524 die("Failed to LIST: " . $client->response_code() . " " .
3525 $client->response_msg());
3526 }
3527
3528 my $buf;
3529 $conn->read($buf, 8192, 30);
3530 eval { $conn->close() };
3531
3532 my $resp_code = $client->response_code();
3533 my $resp_msg = $client->response_msg();
3534 $self->assert_transfer_ok($resp_code, $resp_msg);
3535
3536 if ($ENV{TEST_VERBOSE}) {
3537 print STDERR "# RESPONSE:\n$buf\n";
3538 }
3539
3540 # We have to be careful of the fact that readdir returns directory
3541 # entries in an unordered fashion.
3542 my $res = {};
3543 my $lines = [split(/\n/, $buf)];
3544 foreach my $line (@$lines) {
3545 if ($line =~ /^(\S+)\s+\d+\s+\S+\s+\S+\s+.*?:\d+\s+(.*?)$/) {
3546 my $file_info = $1;
3547 my $file = $2;
3548 $res->{$2} = $1;
3549 }
3550 }
3551
3552 my $file = 'src.link -> dst.d';
3553 my $expected = 'lrwxr-xr-x';
3554 $self->assert($res->{$file} eq $expected,
3555 test_msg("Expected '$expected', got '$res->{$file}' for '$file'"));
3556
3557 # Per the issue, we need to do the LIST command again, to see that
3558 # symlink is still reported the same way.
3559
3560 $conn = $client->list_raw($list_target);
3561 unless ($conn) {
3562 die("Failed to LIST: " . $client->response_code() . " " .
3563 $client->response_msg());
3564 }
3565
3566 $buf = '';
3567 $conn->read($buf, 8192, 30);
3568 eval { $conn->close() };
3569
3570 $resp_code = $client->response_code();
3571 $resp_msg = $client->response_msg();
3572 $self->assert_transfer_ok($resp_code, $resp_msg);
3573
3574 if ($ENV{TEST_VERBOSE}) {
3575 print STDERR "# RESPONSE:\n$buf\n";
3576 }
3577
3578 # We have to be careful of the fact that readdir returns directory
3579 # entries in an unordered fashion.
3580 $res = {};
3581 $lines = [split(/\n/, $buf)];
3582 foreach my $line (@$lines) {
3583 if ($line =~ /^(\S+)\s+\d+\s+\S+\s+\S+\s+.*?:\d+\s+(.*?)$/) {
3584 my $file_info = $1;
3585 my $file = $2;
3586 $res->{$2} = $1;
3587 }
3588 }
3589
3590 $self->assert($res->{$file} eq $expected,
3591 test_msg("Expected '$expected', got '$res->{$file}' for '$file'"));
3592 $client->quit();
3593 };
3594 if ($@) {
3595 $ex = $@;
3596 }
3597
3598 $wfh->print("done\n");
3599 $wfh->flush();
3600
3601 } else {
3602 eval { server_wait($setup->{config_file}, $rfh) };
3603 if ($@) {
3604 warn($@);
3605 exit 1;
3606 }
3607
3608 exit 0;
3609 }
3610
3611 # Stop server
3612 server_stop($setup->{pid_file});
3613 $self->assert_child_ok($pid);
3614
3615 test_cleanup($setup->{log_file}, $ex);
3616 }
3617
3618 sub list_symlink_rel_with_double_slash_bug3719 {
3619 my $self = shift;
3620 my $tmpdir = $self->{tmpdir};
3621
3622 my $config_file = "$tmpdir/cmds.conf";
3623 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
3624 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
3625
3626 my $log_file = test_get_logfile();
3627
3628 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
3629 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
3630
3631 my $user = 'proftpd';
3632 my $passwd = 'test';
3633 my $group = 'ftpd';
3634 my $home_dir = File::Spec->rel2abs($tmpdir);
3635 my $uid = 500;
3636 my $gid = 500;
3637
3638 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
3639 my $bar_dir = File::Spec->rel2abs("$tmpdir/bar");
3640 my $baz_dir = File::Spec->rel2abs("$tmpdir/bar/baz");
3641 mkpath([$foo_dir, $bar_dir, $baz_dir]);
3642
3643 # Change to the 'foo' directory in order to create a relative path in the
3644 # symlink we need
3645
3646 my $cwd = getcwd();
3647 unless (chdir("$foo_dir")) {
3648 die("Can't chdir to $foo_dir: $!");
3649 }
3650
3651 unless (symlink('../bar//baz', 'baz')) {
3652 die("Can't symlink '../bar//baz' to 'baz': $!");
3653 }
3654
3655 unless (chdir($cwd)) {
3656 die("Can't chdir to $cwd: $!");
3657 }
3658
3659 # Make sure that, if we're running as root, that the home directory has
3660 # permissions/privs set for the account we create
3661 if ($< == 0) {
3662 unless (chmod(0755, $home_dir, $foo_dir, $bar_dir, $baz_dir)) {
3663 die("Can't set perms on dirs to 0755: $!");
3664 }
3665
3666 unless (chown($uid, $gid, $home_dir, $foo_dir, $bar_dir, $baz_dir)) {
3667 die("Can't set owner of dirs to $uid/$gid: $!");
3668 }
3669 }
3670
3671 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3672 '/bin/bash');
3673 auth_group_write($auth_group_file, $group, $gid, $user);
3674
3675 my $config = {
3676 PidFile => $pid_file,
3677 ScoreboardFile => $scoreboard_file,
3678 SystemLog => $log_file,
3679
3680 AuthUserFile => $auth_user_file,
3681 AuthGroupFile => $auth_group_file,
3682 AuthOrder => 'mod_auth_file.c',
3683
3684 DefaultRoot => '~',
3685
3686 IfModules => {
3687 'mod_delay.c' => {
3688 DelayEngine => 'off',
3689 },
3690 },
3691 };
3692
3693 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3694
3695 # Open pipes, for use between the parent and child processes. Specifically,
3696 # the child will indicate when it's done with its test by writing a message
3697 # to the parent.
3698 my ($rfh, $wfh);
3699 unless (pipe($rfh, $wfh)) {
3700 die("Can't open pipe: $!");
3701 }
3702
3703 my $ex;
3704
3705 # Fork child
3706 $self->handle_sigchld();
3707 defined(my $pid = fork()) or die("Can't fork: $!");
3708 if ($pid) {
3709 eval {
3710 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3711
3712 $client->login($user, $passwd);
3713
3714 $client->cwd("foo");
3715 my $conn = $client->list_raw();
3716 unless ($conn) {
3717 die("Failed to LIST: " . $client->response_code() . " " .
3718 $client->response_msg());
3719 }
3720
3721 my $buf;
3722 $conn->read($buf, 8192, 30);
3723 eval { $conn->close() };
3724
3725 my $resp_code = $client->response_code();
3726 my $resp_msg = $client->response_msg();
3727 $self->assert_transfer_ok($resp_code, $resp_msg);
3728
3729 $client->quit();
3730
3731 # We have to be careful of the fact that readdir returns directory
3732 # entries in an unordered fashion.
3733 my $res = {};
3734 my $lines = [split(/\n/, $buf)];
3735 foreach my $line (@$lines) {
3736 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
3737 $res->{$1} = 1;
3738 }
3739 }
3740
3741 my $expected = {
3742 '../bar//baz' => 1,
3743 };
3744
3745 my $ok = 1;
3746 my $mismatch;
3747 foreach my $name (keys(%$res)) {
3748 unless (defined($expected->{$name})) {
3749 $mismatch = $name;
3750 $ok = 0;
3751 last;
3752 }
3753 }
3754
3755 unless ($ok) {
3756 die("Unexpected name '$mismatch' appeared in LIST data")
3757 }
3758 };
3759
3760 if ($@) {
3761 $ex = $@;
3762 }
3763
3764 $wfh->print("done\n");
3765 $wfh->flush();
3766
3767 } else {
3768 eval { server_wait($config_file, $rfh) };
3769 if ($@) {
3770 warn($@);
3771 exit 1;
3772 }
3773
3774 exit 0;
3775 }
3776
3777 # Stop server
3778 server_stop($pid_file);
3779
3780 $self->assert_child_ok($pid);
3781
3782 if ($ex) {
3783 test_append_logfile($log_file, $ex);
3784 unlink($log_file);
3785
3786 die($ex);
3787 }
3788
3789 unlink($log_file);
3790 }
3791
3792 sub list_showsymlinks_off {
3793 my $self = shift;
3794 my $tmpdir = $self->{tmpdir};
3795 my $setup = test_setup($tmpdir, 'cmds');
3796
3797 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
3798 my $bar_dir = File::Spec->rel2abs("$tmpdir/bar");
3799 my $baz_dir = File::Spec->rel2abs("$tmpdir/bar/baz");
3800 mkpath([$foo_dir, $bar_dir, $baz_dir]);
3801
3802 # Change to the 'foo' directory in order to create a relative path in the
3803 # symlink we need
3804
3805 my $cwd = getcwd();
3806 unless (chdir($foo_dir)) {
3807 die("Can't chdir to $foo_dir: $!");
3808 }
3809
3810 unless (symlink('../bar/baz', 'baz')) {
3811 die("Can't symlink '../bar/baz' to 'baz': $!");
3812 }
3813
3814 unless (chdir($cwd)) {
3815 die("Can't chdir to $cwd: $!");
3816 }
3817
3818 # Make sure that, if we're running as root, that the directories have
3819 # permissions/privs set for the account we create
3820 if ($< == 0) {
3821 unless (chmod(0755, $foo_dir, $bar_dir, $baz_dir)) {
3822 die("Can't set perms on dirs to 0755: $!");
3823 }
3824
3825 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir, $bar_dir, $baz_dir)) {
3826 die("Can't set owner of dirs to $setup->{uid}/$setup->{gid}: $!");
3827 }
3828 }
3829
3830 my $config = {
3831 PidFile => $setup->{pid_file},
3832 ScoreboardFile => $setup->{scoreboard_file},
3833 SystemLog => $setup->{log_file},
3834
3835 AuthUserFile => $setup->{auth_user_file},
3836 AuthGroupFile => $setup->{auth_group_file},
3837 AuthOrder => 'mod_auth_file.c',
3838
3839 ShowSymlinks => 'off',
3840
3841 IfModules => {
3842 'mod_delay.c' => {
3843 DelayEngine => 'off',
3844 },
3845 },
3846 };
3847
3848 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3849 $config);
3850
3851 # Open pipes, for use between the parent and child processes. Specifically,
3852 # the child will indicate when it's done with its test by writing a message
3853 # to the parent.
3854 my ($rfh, $wfh);
3855 unless (pipe($rfh, $wfh)) {
3856 die("Can't open pipe: $!");
3857 }
3858
3859 my $ex;
3860
3861 # Fork child
3862 $self->handle_sigchld();
3863 defined(my $pid = fork()) or die("Can't fork: $!");
3864 if ($pid) {
3865 eval {
3866 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
3867 $client->login($setup->{user}, $setup->{passwd});
3868
3869 $client->cwd("foo");
3870 my $conn = $client->list_raw('-l');
3871 unless ($conn) {
3872 die("Failed to LIST: " . $client->response_code() . " " .
3873 $client->response_msg());
3874 }
3875
3876 my $buf;
3877 $conn->read($buf, 8192, 30);
3878 eval { $conn->close() };
3879
3880 my $resp_code = $client->response_code();
3881 my $resp_msg = $client->response_msg();
3882 $client->quit();
3883
3884 $self->assert_transfer_ok($resp_code, $resp_msg);
3885
3886 chomp($buf);
3887
3888 if ($ENV{TEST_VERBOSE}) {
3889 print STDERR "# Response:\n$buf\n";
3890 }
3891
3892 my $expected = '^d\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+\s+(.*?)$';
3893 $self->assert(qr/$expected/, $buf,
3894 test_msg("Expected '$expected', got '$buf'"));
3895
3896 $buf =~ /$expected/;
3897 my $finfo = $1;
3898
3899 $expected = 'baz';
3900 $self->assert($expected eq $finfo,
3901 test_msg("Expected '$expected', got '$finfo'"));
3902 };
3903 if ($@) {
3904 $ex = $@;
3905 }
3906
3907 $wfh->print("done\n");
3908 $wfh->flush();
3909
3910 } else {
3911 eval { server_wait($setup->{config_file}, $rfh) };
3912 if ($@) {
3913 warn($@);
3914 exit 1;
3915 }
3916
3917 exit 0;
3918 }
3919
3920 # Stop server
3921 server_stop($setup->{pid_file});
3922 $self->assert_child_ok($pid);
3923
3924 test_cleanup($setup->{log_file}, $ex);
3925 }
3926
3927 sub list_showsymlinks_off_chrooted_bug4219 {
3928 my $self = shift;
3929 my $tmpdir = $self->{tmpdir};
3930 my $setup = test_setup($tmpdir, 'cmds');
3931
3932 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
3933 my $bar_dir = File::Spec->rel2abs("$tmpdir/bar");
3934 my $baz_dir = File::Spec->rel2abs("$tmpdir/bar/baz");
3935 mkpath([$foo_dir, $bar_dir, $baz_dir]);
3936
3937 # Change to the 'foo' directory in order to create a relative path in the
3938 # symlink we need
3939
3940 my $cwd = getcwd();
3941 unless (chdir($foo_dir)) {
3942 die("Can't chdir to $foo_dir: $!");
3943 }
3944
3945 unless (symlink('../bar/baz', 'baz')) {
3946 die("Can't symlink '../bar/baz' to 'baz': $!");
3947 }
3948
3949 unless (chdir($cwd)) {
3950 die("Can't chdir to $cwd: $!");
3951 }
3952
3953 # Make sure that, if we're running as root, that the directories have
3954 # permissions/privs set for the account we create
3955 if ($< == 0) {
3956 unless (chmod(0755, $foo_dir, $bar_dir, $baz_dir)) {
3957 die("Can't set perms on dirs to 0755: $!");
3958 }
3959
3960 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir, $bar_dir, $baz_dir)) {
3961 die("Can't set owner of dirs to $setup->{uid}/$setup->{gid}: $!");
3962 }
3963 }
3964
3965 my $config = {
3966 PidFile => $setup->{pid_file},
3967 ScoreboardFile => $setup->{scoreboard_file},
3968 SystemLog => $setup->{log_file},
3969
3970 AuthUserFile => $setup->{auth_user_file},
3971 AuthGroupFile => $setup->{auth_group_file},
3972 AuthOrder => 'mod_auth_file.c',
3973
3974 DefaultRoot => '~',
3975 ShowSymlinks => 'off',
3976
3977 IfModules => {
3978 'mod_delay.c' => {
3979 DelayEngine => 'off',
3980 },
3981 },
3982 };
3983
3984 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3985 $config);
3986
3987 # Open pipes, for use between the parent and child processes. Specifically,
3988 # the child will indicate when it's done with its test by writing a message
3989 # to the parent.
3990 my ($rfh, $wfh);
3991 unless (pipe($rfh, $wfh)) {
3992 die("Can't open pipe: $!");
3993 }
3994
3995 my $ex;
3996
3997 # Fork child
3998 $self->handle_sigchld();
3999 defined(my $pid = fork()) or die("Can't fork: $!");
4000 if ($pid) {
4001 eval {
4002 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
4003 $client->login($setup->{user}, $setup->{passwd});
4004
4005 $client->cwd("foo");
4006 my $conn = $client->list_raw('-l');
4007 unless ($conn) {
4008 die("Failed to LIST: " . $client->response_code() . " " .
4009 $client->response_msg());
4010 }
4011
4012 my $buf;
4013 $conn->read($buf, 8192, 30);
4014 eval { $conn->close() };
4015
4016 my $resp_code = $client->response_code();
4017 my $resp_msg = $client->response_msg();
4018 $client->quit();
4019
4020 $self->assert_transfer_ok($resp_code, $resp_msg);
4021
4022 chomp($buf);
4023
4024 if ($ENV{TEST_VERBOSE}) {
4025 print STDERR "# Response:\n$buf\n";
4026 }
4027
4028 my $expected = '^d\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+\s+(.*?)$';
4029 $self->assert(qr/$expected/, $buf,
4030 test_msg("Expected '$expected', got '$buf'"));
4031
4032 $buf =~ /$expected/;
4033 my $finfo = $1;
4034
4035 $expected = 'baz';
4036 $self->assert($expected eq $finfo,
4037 test_msg("Expected '$expected', got '$finfo'"));
4038 };
4039 if ($@) {
4040 $ex = $@;
4041 }
4042
4043 $wfh->print("done\n");
4044 $wfh->flush();
4045
4046 } else {
4047 eval { server_wait($setup->{config_file}, $rfh) };
4048 if ($@) {
4049 warn($@);
4050 exit 1;
4051 }
4052
4053 exit 0;
4054 }
4055
4056 # Stop server
4057 server_stop($setup->{pid_file});
4058 $self->assert_child_ok($pid);
4059
4060 test_cleanup($setup->{log_file}, $ex);
4061 }
4062
4063 sub list_showsymlinks_on {
4064 my $self = shift;
4065 my $tmpdir = $self->{tmpdir};
4066 my $setup = test_setup($tmpdir, 'cmds');
4067
4068 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
4069 my $bar_dir = File::Spec->rel2abs("$tmpdir/bar");
4070 my $baz_dir = File::Spec->rel2abs("$tmpdir/bar/baz");
4071 mkpath([$foo_dir, $bar_dir, $baz_dir]);
4072
4073 # Change to the 'foo' directory in order to create a relative path in the
4074 # symlink we need
4075
4076 my $cwd = getcwd();
4077 unless (chdir($foo_dir)) {
4078 die("Can't chdir to $foo_dir: $!");
4079 }
4080
4081 unless (symlink('../bar/baz', 'baz')) {
4082 die("Can't symlink '../bar/baz' to 'baz': $!");
4083 }
4084
4085 unless (chdir($cwd)) {
4086 die("Can't chdir to $cwd: $!");
4087 }
4088
4089 # Make sure that, if we're running as root, that the directories have
4090 # permissions/privs set for the account we create
4091 if ($< == 0) {
4092 unless (chmod(0755, $foo_dir, $bar_dir, $baz_dir)) {
4093 die("Can't set perms on dirs to 0755: $!");
4094 }
4095
4096 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir, $bar_dir, $baz_dir)) {
4097 die("Can't set owner of dirs to $setup->{uid}/$setup->{gid}: $!");
4098 }
4099 }
4100
4101 my $config = {
4102 PidFile => $setup->{pid_file},
4103 ScoreboardFile => $setup->{scoreboard_file},
4104 SystemLog => $setup->{log_file},
4105
4106 AuthUserFile => $setup->{auth_user_file},
4107 AuthGroupFile => $setup->{auth_group_file},
4108 AuthOrder => 'mod_auth_file.c',
4109
4110 ShowSymlinks => 'on',
4111
4112 IfModules => {
4113 'mod_delay.c' => {
4114 DelayEngine => 'off',
4115 },
4116 },
4117 };
4118
4119 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4120 $config);
4121
4122 # Open pipes, for use between the parent and child processes. Specifically,
4123 # the child will indicate when it's done with its test by writing a message
4124 # to the parent.
4125 my ($rfh, $wfh);
4126 unless (pipe($rfh, $wfh)) {
4127 die("Can't open pipe: $!");
4128 }
4129
4130 my $ex;
4131
4132 # Fork child
4133 $self->handle_sigchld();
4134 defined(my $pid = fork()) or die("Can't fork: $!");
4135 if ($pid) {
4136 eval {
4137 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
4138 $client->login($setup->{user}, $setup->{passwd});
4139
4140 $client->cwd("foo");
4141 my $conn = $client->list_raw('-l');
4142 unless ($conn) {
4143 die("Failed to LIST: " . $client->response_code() . " " .
4144 $client->response_msg());
4145 }
4146
4147 my $buf;
4148 $conn->read($buf, 8192, 30);
4149 eval { $conn->close() };
4150
4151 my $resp_code = $client->response_code();
4152 my $resp_msg = $client->response_msg();
4153 $client->quit();
4154
4155 $self->assert_transfer_ok($resp_code, $resp_msg);
4156
4157 chomp($buf);
4158
4159 if ($ENV{TEST_VERBOSE}) {
4160 print STDERR "# Response:\n$buf\n";
4161 }
4162
4163 my $expected = '^l\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+\s+(.*?)$';
4164 $self->assert(qr/$expected/, $buf,
4165 test_msg("Expected '$expected', got '$buf'"));
4166
4167 $buf =~ /$expected/;
4168 my $finfo = $1;
4169
4170 $expected = 'baz -> ../bar/baz';
4171 $self->assert($expected eq $finfo,
4172 test_msg("Expected '$expected', got '$finfo'"));
4173 };
4174 if ($@) {
4175 $ex = $@;
4176 }
4177
4178 $wfh->print("done\n");
4179 $wfh->flush();
4180
4181 } else {
4182 eval { server_wait($setup->{config_file}, $rfh) };
4183 if ($@) {
4184 warn($@);
4185 exit 1;
4186 }
4187
4188 exit 0;
4189 }
4190
4191 # Stop server
4192 server_stop($setup->{pid_file});
4193 $self->assert_child_ok($pid);
4194
4195 test_cleanup($setup->{log_file}, $ex);
4196 }
4197
4198 sub list_showsymlinks_on_chrooted_bug4219 {
4199 my $self = shift;
4200 my $tmpdir = $self->{tmpdir};
4201 my $setup = test_setup($tmpdir, 'cmds');
4202
4203 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
4204 my $bar_dir = File::Spec->rel2abs("$tmpdir/bar");
4205 my $baz_dir = File::Spec->rel2abs("$tmpdir/bar/baz");
4206 mkpath([$foo_dir, $bar_dir, $baz_dir]);
4207
4208 # Change to the 'foo' directory in order to create a relative path in the
4209 # symlink we need
4210
4211 my $cwd = getcwd();
4212 unless (chdir($foo_dir)) {
4213 die("Can't chdir to $foo_dir: $!");
4214 }
4215
4216 unless (symlink('../bar/baz', 'baz')) {
4217 die("Can't symlink '../bar/baz' to 'baz': $!");
4218 }
4219
4220 unless (chdir($cwd)) {
4221 die("Can't chdir to $cwd: $!");
4222 }
4223
4224 # Make sure that, if we're running as root, that the directories have
4225 # permissions/privs set for the account we create
4226 if ($< == 0) {
4227 unless (chmod(0755, $foo_dir, $bar_dir, $baz_dir)) {
4228 die("Can't set perms on dirs to 0755: $!");
4229 }
4230
4231 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir, $bar_dir, $baz_dir)) {
4232 die("Can't set owner of dirs to $setup->{uid}/$setup->{gid}: $!");
4233 }
4234 }
4235
4236 my $config = {
4237 PidFile => $setup->{pid_file},
4238 ScoreboardFile => $setup->{scoreboard_file},
4239 SystemLog => $setup->{log_file},
4240
4241 AuthUserFile => $setup->{auth_user_file},
4242 AuthGroupFile => $setup->{auth_group_file},
4243 AuthOrder => 'mod_auth_file.c',
4244
4245 DefaultRoot => '~',
4246 ShowSymlinks => 'on',
4247
4248 IfModules => {
4249 'mod_delay.c' => {
4250 DelayEngine => 'off',
4251 },
4252 },
4253 };
4254
4255 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4256 $config);
4257
4258 # Open pipes, for use between the parent and child processes. Specifically,
4259 # the child will indicate when it's done with its test by writing a message
4260 # to the parent.
4261 my ($rfh, $wfh);
4262 unless (pipe($rfh, $wfh)) {
4263 die("Can't open pipe: $!");
4264 }
4265
4266 my $ex;
4267
4268 # Fork child
4269 $self->handle_sigchld();
4270 defined(my $pid = fork()) or die("Can't fork: $!");
4271 if ($pid) {
4272 eval {
4273 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
4274 $client->login($setup->{user}, $setup->{passwd});
4275
4276 $client->cwd("foo");
4277 my $conn = $client->list_raw('-l');
4278 unless ($conn) {
4279 die("Failed to LIST: " . $client->response_code() . " " .
4280 $client->response_msg());
4281 }
4282
4283 my $buf;
4284 $conn->read($buf, 8192, 30);
4285 eval { $conn->close() };
4286
4287 my $resp_code = $client->response_code();
4288 my $resp_msg = $client->response_msg();
4289 $client->quit();
4290
4291 $self->assert_transfer_ok($resp_code, $resp_msg);
4292
4293 chomp($buf);
4294
4295 if ($ENV{TEST_VERBOSE}) {
4296 print STDERR "# Response:\n$buf\n";
4297 }
4298
4299 my $expected = '^l\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+\s+(.*?)$';
4300 $self->assert(qr/$expected/, $buf,
4301 test_msg("Expected '$expected', got '$buf'"));
4302
4303 $buf =~ /$expected/;
4304 my $finfo = $1;
4305
4306 $expected = 'baz -> /bar/baz';
4307 $self->assert($expected eq $finfo,
4308 test_msg("Expected '$expected', got '$finfo'"));
4309 };
4310 if ($@) {
4311 $ex = $@;
4312 }
4313
4314 $wfh->print("done\n");
4315 $wfh->flush();
4316
4317 } else {
4318 eval { server_wait($setup->{config_file}, $rfh) };
4319 if ($@) {
4320 warn($@);
4321 exit 1;
4322 }
4323
4324 exit 0;
4325 }
4326
4327 # Stop server
4328 server_stop($setup->{pid_file});
4329 $self->assert_child_ok($pid);
4330
4331 test_cleanup($setup->{log_file}, $ex);
4332 }
4333
4334 sub list_glob_bug2367 {
4335 my $self = shift;
4336 my $tmpdir = $self->{tmpdir};
4337
4338 my $config_file = "$tmpdir/cmds.conf";
4339 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
4340 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
4341
4342 my $log_file = test_get_logfile();
4343
4344 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
4345 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
4346
4347 my $user = 'proftpd';
4348 my $passwd = 'test';
4349 my $home_dir = File::Spec->rel2abs($tmpdir);
4350 my $uid = 500;
4351 my $gid = 500;
4352
4353 my $test_dir = File::Spec->rel2abs("$home_dir/foo");
4354 mkpath($test_dir);
4355
4356 # Make sure that, if we're running as root, that the home directory has
4357 # permissions/privs set for the account we create
4358 if ($< == 0) {
4359 unless (chmod(0755, $home_dir, $test_dir)) {
4360 die("Can't set perms on $home_dir to 0755: $!");
4361 }
4362
4363 unless (chown($uid, $gid, $home_dir, $test_dir)) {
4364 die("Can't set owner of $home_dir to $uid/$gid: $!");
4365 }
4366 }
4367
4368 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4369 '/bin/bash');
4370 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
4371
4372 my $config = {
4373 PidFile => $pid_file,
4374 ScoreboardFile => $scoreboard_file,
4375 SystemLog => $log_file,
4376
4377 AuthUserFile => $auth_user_file,
4378 AuthGroupFile => $auth_group_file,
4379 AuthOrder => 'mod_auth_file.c',
4380
4381 IfModules => {
4382 'mod_delay.c' => {
4383 DelayEngine => 'off',
4384 },
4385 },
4386 };
4387
4388 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4389
4390 # Open pipes, for use between the parent and child processes. Specifically,
4391 # the child will indicate when it's done with its test by writing a message
4392 # to the parent.
4393 my ($rfh, $wfh);
4394 unless (pipe($rfh, $wfh)) {
4395 die("Can't open pipe: $!");
4396 }
4397
4398 my $ex;
4399
4400 # Fork child
4401 $self->handle_sigchld();
4402 defined(my $pid = fork()) or die("Can't fork: $!");
4403 if ($pid) {
4404 eval {
4405 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4406
4407 $client->login($user, $passwd);
4408 $client->cwd($test_dir);
4409
4410 my $conn = $client->list_raw("*.*");
4411 unless ($conn) {
4412 die("LIST failed: " . $client->response_code() . " " .
4413 $client->response_msg());
4414 }
4415
4416 my $buf;
4417 $conn->read($buf, 8192, 30);
4418 eval { $conn->close() };
4419
4420 my $res = {};
4421 my $lines = [split(/\n/, $buf)];
4422 foreach my $line (@$lines) {
4423 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
4424 $res->{$1} = 1;
4425 }
4426 }
4427
4428 my $count = scalar(keys(%$res));
4429 unless ($count == 0) {
4430 die("LIST returned wrong number of entries (expected 0, got $count)");
4431 }
4432 };
4433
4434 if ($@) {
4435 $ex = $@;
4436 }
4437
4438 $wfh->print("done\n");
4439 $wfh->flush();
4440
4441 } else {
4442 eval { server_wait($config_file, $rfh) };
4443 if ($@) {
4444 warn($@);
4445 exit 1;
4446 }
4447
4448 exit 0;
4449 }
4450
4451 # Stop server
4452 server_stop($pid_file);
4453
4454 $self->assert_child_ok($pid);
4455
4456 if ($ex) {
4457 test_append_logfile($log_file, $ex);
4458 unlink($log_file);
4459
4460 die($ex);
4461 }
4462
4463 unlink($log_file);
4464 }
4465
4466 sub list_glob_legit_dir_name {
4467 my $self = shift;
4468 my $tmpdir = $self->{tmpdir};
4469
4470 my $config_file = "$tmpdir/cmds.conf";
4471 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
4472 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
4473
4474 my $log_file = test_get_logfile();
4475
4476 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
4477 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
4478
4479 my $user = 'proftpd';
4480 my $passwd = 'test';
4481 my $home_dir = File::Spec->rel2abs($tmpdir);
4482 my $uid = 500;
4483 my $gid = 500;
4484
4485 my $test_dir = File::Spec->rel2abs("$home_dir/\[foo bar");
4486 mkpath($test_dir);
4487
4488 # Make sure that, if we're running as root, that the home directory has
4489 # permissions/privs set for the account we create
4490 if ($< == 0) {
4491 unless (chmod(0755, $home_dir, $test_dir)) {
4492 die("Can't set perms on $home_dir to 0755: $!");
4493 }
4494
4495 unless (chown($uid, $gid, $home_dir, $test_dir)) {
4496 die("Can't set owner of $home_dir to $uid/$gid: $!");
4497 }
4498 }
4499
4500 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4501 '/bin/bash');
4502 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
4503
4504 my $config = {
4505 PidFile => $pid_file,
4506 ScoreboardFile => $scoreboard_file,
4507 SystemLog => $log_file,
4508
4509 AuthUserFile => $auth_user_file,
4510 AuthGroupFile => $auth_group_file,
4511 AuthOrder => 'mod_auth_file.c',
4512
4513 IfModules => {
4514 'mod_delay.c' => {
4515 DelayEngine => 'off',
4516 },
4517 },
4518 };
4519
4520 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4521
4522 # Open pipes, for use between the parent and child processes. Specifically,
4523 # the child will indicate when it's done with its test by writing a message
4524 # to the parent.
4525 my ($rfh, $wfh);
4526 unless (pipe($rfh, $wfh)) {
4527 die("Can't open pipe: $!");
4528 }
4529
4530 my $ex;
4531
4532 # Fork child
4533 $self->handle_sigchld();
4534 defined(my $pid = fork()) or die("Can't fork: $!");
4535 if ($pid) {
4536 eval {
4537 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4538
4539 $client->login($user, $passwd);
4540 $client->cwd($test_dir);
4541
4542 my $conn = $client->list_raw("-a $test_dir");
4543 unless ($conn) {
4544 die("LIST failed: " . $client->response_code() . " " .
4545 $client->response_msg());
4546 }
4547
4548 my $buf;
4549 $conn->read($buf, 8192, 30);
4550 eval { $conn->close() };
4551
4552 my $res = {};
4553 my $lines = [split(/\n/, $buf)];
4554 foreach my $line (@$lines) {
4555 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
4556 $res->{$1} = 1;
4557 }
4558 }
4559
4560 my $count = scalar(keys(%$res));
4561 unless ($count == 2) {
4562 die("LIST returned wrong number of entries (expected 2, got $count)");
4563 }
4564 };
4565
4566 if ($@) {
4567 $ex = $@;
4568 }
4569
4570 $wfh->print("done\n");
4571 $wfh->flush();
4572
4573 } else {
4574 eval { server_wait($config_file, $rfh) };
4575 if ($@) {
4576 warn($@);
4577 exit 1;
4578 }
4579
4580 exit 0;
4581 }
4582
4583 # Stop server
4584 server_stop($pid_file);
4585
4586 $self->assert_child_ok($pid);
4587
4588 if ($ex) {
4589 test_append_logfile($log_file, $ex);
4590 unlink($log_file);
4591
4592 die($ex);
4593 }
4594
4595 unlink($log_file);
4596 }
4597
4598 sub list_glob_legit_dir_name_bug3407 {
4599 my $self = shift;
4600 my $tmpdir = $self->{tmpdir};
4601
4602 my $config_file = "$tmpdir/cmds.conf";
4603 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
4604 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
4605
4606 my $log_file = test_get_logfile();
4607
4608 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
4609 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
4610
4611 my $user = 'proftpd';
4612 my $passwd = 'test';
4613 my $home_dir = File::Spec->rel2abs($tmpdir);
4614 my $uid = 500;
4615 my $gid = 500;
4616
4617 my $test_dir = File::Spec->rel2abs("$home_dir/\[foo bar\]");
4618 mkpath($test_dir);
4619
4620 # Make sure that, if we're running as root, that the home directory has
4621 # permissions/privs set for the account we create
4622 if ($< == 0) {
4623 unless (chmod(0755, $home_dir, $test_dir)) {
4624 die("Can't set perms on $home_dir to 0755: $!");
4625 }
4626
4627 unless (chown($uid, $gid, $home_dir, $test_dir)) {
4628 die("Can't set owner of $home_dir to $uid/$gid: $!");
4629 }
4630 }
4631
4632 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4633 '/bin/bash');
4634 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
4635
4636 my $config = {
4637 PidFile => $pid_file,
4638 ScoreboardFile => $scoreboard_file,
4639 SystemLog => $log_file,
4640
4641 AuthUserFile => $auth_user_file,
4642 AuthGroupFile => $auth_group_file,
4643 AuthOrder => 'mod_auth_file.c',
4644
4645 IfModules => {
4646 'mod_delay.c' => {
4647 DelayEngine => 'off',
4648 },
4649 },
4650 };
4651
4652 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4653
4654 # Open pipes, for use between the parent and child processes. Specifically,
4655 # the child will indicate when it's done with its test by writing a message
4656 # to the parent.
4657 my ($rfh, $wfh);
4658 unless (pipe($rfh, $wfh)) {
4659 die("Can't open pipe: $!");
4660 }
4661
4662 my $ex;
4663
4664 # Fork child
4665 $self->handle_sigchld();
4666 defined(my $pid = fork()) or die("Can't fork: $!");
4667 if ($pid) {
4668 eval {
4669 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4670
4671 $client->login($user, $passwd);
4672 $client->cwd($test_dir);
4673
4674 my $conn = $client->list_raw("-a $test_dir");
4675 unless ($conn) {
4676 die("LIST failed: " . $client->response_code() . " " .
4677 $client->response_msg());
4678 }
4679
4680 my $buf;
4681 $conn->read($buf, 8192, 30);
4682 eval { $conn->close() };
4683
4684 my $res = {};
4685 my $lines = [split(/\n/, $buf)];
4686 foreach my $line (@$lines) {
4687 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
4688 $res->{$1} = 1;
4689 }
4690 }
4691
4692 my $count = scalar(keys(%$res));
4693 unless ($count == 2) {
4694 die("LIST returned wrong number of entries (expected 2, got $count)");
4695 }
4696 };
4697
4698 if ($@) {
4699 $ex = $@;
4700 }
4701
4702 $wfh->print("done\n");
4703 $wfh->flush();
4704
4705 } else {
4706 eval { server_wait($config_file, $rfh) };
4707 if ($@) {
4708 warn($@);
4709 exit 1;
4710 }
4711
4712 exit 0;
4713 }
4714
4715 # Stop server
4716 server_stop($pid_file);
4717
4718 $self->assert_child_ok($pid);
4719
4720 if ($ex) {
4721 test_append_logfile($log_file, $ex);
4722 unlink($log_file);
4723
4724 die($ex);
4725 }
4726
4727 unlink($log_file);
4728 }
4729
4730 sub list_opt_c {
4731 my $self = shift;
4732 my $tmpdir = $self->{tmpdir};
4733
4734 my $config_file = "$tmpdir/cmds.conf";
4735 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
4736 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
4737
4738 my $log_file = test_get_logfile();
4739
4740 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
4741 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
4742
4743 my $user = 'proftpd';
4744 my $passwd = 'test';
4745 my $home_dir = File::Spec->rel2abs($tmpdir);
4746 my $uid = 500;
4747 my $gid = 500;
4748
4749 # Make sure that, if we're running as root, that the home directory has
4750 # permissions/privs set for the account we create
4751 if ($< == 0) {
4752 unless (chmod(0755, $home_dir)) {
4753 die("Can't set perms on $home_dir to 0755: $!");
4754 }
4755
4756 unless (chown($uid, $gid, $home_dir)) {
4757 die("Can't set owner of $home_dir to $uid/$gid: $!");
4758 }
4759 }
4760
4761 # For this test, we need to create about 3 files in home directory.
4762
4763 my $count = 3;
4764 for (my $i = 1; $i <= $count; $i++) {
4765 my $test_file = sprintf("%04s", $i);
4766 my $test_path = "$home_dir/$test_file";
4767
4768 if (open(my $fh, "> $test_path")) {
4769 close($fh);
4770
4771 } else {
4772 die("Can't open $test_path: $!");
4773 }
4774
4775 my $timestamp = time() - ($i * 5);
4776 unless (utime($timestamp, $timestamp, $test_path)) {
4777 die("Can't change times on $test_path: $!");
4778 }
4779
4780 # Delay between file creations, to make the ctimes different
4781 sleep(1);
4782 }
4783
4784 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4785 '/bin/bash');
4786 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
4787
4788 my $config = {
4789 PidFile => $pid_file,
4790 ScoreboardFile => $scoreboard_file,
4791 SystemLog => $log_file,
4792
4793 AuthUserFile => $auth_user_file,
4794 AuthGroupFile => $auth_group_file,
4795 AuthOrder => 'mod_auth_file.c',
4796
4797 IfModules => {
4798 'mod_delay.c' => {
4799 DelayEngine => 'off',
4800 },
4801 },
4802 };
4803
4804 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4805
4806 # Open pipes, for use between the parent and child processes. Specifically,
4807 # the child will indicate when it's done with its test by writing a message
4808 # to the parent.
4809 my ($rfh, $wfh);
4810 unless (pipe($rfh, $wfh)) {
4811 die("Can't open pipe: $!");
4812 }
4813
4814 my $ex;
4815
4816 # Fork child
4817 $self->handle_sigchld();
4818 defined(my $pid = fork()) or die("Can't fork: $!");
4819 if ($pid) {
4820 eval {
4821 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4822
4823 $client->login($user, $passwd);
4824
4825 # Use the -t option to sort by time, and the -c option to sort by
4826 # st_ctime. Thus the last file we created should appear first in the
4827 # returned list.
4828 my $conn = $client->list_raw("-ct 0*");
4829 unless ($conn) {
4830 die("LIST failed: " . $client->response_code() . " " .
4831 $client->response_msg());
4832 }
4833
4834 my $buf;
4835 $conn->read($buf, 32768, 30);
4836 eval { $conn->close() };
4837
4838 my $res = {};
4839 my $lines = [split(/\n/, $buf)];
4840
4841 my $fileno = 3;
4842 foreach my $line (@$lines) {
4843 if ($line =~ /\s+(\S+)$/) {
4844 my $filename = $1;
4845
4846 my $expected = sprintf("%04s", $fileno--);
4847
4848 $self->assert($expected eq $filename,
4849 test_msg("Expected '$expected', got '$filename'"));
4850
4851 $res->{$filename} = 1;
4852 }
4853 }
4854
4855 my $list_count = scalar(keys(%$res));
4856 unless ($list_count == $count) {
4857 die("LIST returned wrong number of entries (expected $count, got $list_count)");
4858 }
4859 };
4860
4861 if ($@) {
4862 $ex = $@;
4863 }
4864
4865 $wfh->print("done\n");
4866 $wfh->flush();
4867
4868 } else {
4869 eval { server_wait($config_file, $rfh) };
4870 if ($@) {
4871 warn($@);
4872 exit 1;
4873 }
4874
4875 exit 0;
4876 }
4877
4878 # Stop server
4879 server_stop($pid_file);
4880
4881 $self->assert_child_ok($pid);
4882
4883 if ($ex) {
4884 test_append_logfile($log_file, $ex);
4885 unlink($log_file);
4886
4887 die($ex);
4888 }
4889
4890 unlink($log_file);
4891 }
4892
4893 sub list_opt_u {
4894 my $self = shift;
4895 my $tmpdir = $self->{tmpdir};
4896
4897 my $config_file = "$tmpdir/cmds.conf";
4898 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
4899 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
4900
4901 my $log_file = test_get_logfile();
4902
4903 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
4904 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
4905
4906 my $user = 'proftpd';
4907 my $passwd = 'test';
4908 my $home_dir = File::Spec->rel2abs($tmpdir);
4909 my $uid = 500;
4910 my $gid = 500;
4911
4912 # Make sure that, if we're running as root, that the home directory has
4913 # permissions/privs set for the account we create
4914 if ($< == 0) {
4915 unless (chmod(0755, $home_dir)) {
4916 die("Can't set perms on $home_dir to 0755: $!");
4917 }
4918
4919 unless (chown($uid, $gid, $home_dir)) {
4920 die("Can't set owner of $home_dir to $uid/$gid: $!");
4921 }
4922 }
4923
4924 # For this test, we need to create about 3 files in home directory.
4925
4926 my $count = 3;
4927 for (my $i = 1; $i <= $count; $i++) {
4928 my $test_file = sprintf("%04s", $i);
4929 my $test_path = "$home_dir/$test_file";
4930
4931 if (open(my $fh, "> $test_path")) {
4932 close($fh);
4933
4934 } else {
4935 die("Can't open $test_path: $!");
4936 }
4937
4938 my $atime = time() + ($i * 5);
4939 my $mtime = time() - ($i * 5);
4940 unless (utime($atime, $mtime, $test_path)) {
4941 die("Can't change times on $test_path: $!");
4942 }
4943 }
4944
4945 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4946 '/bin/bash');
4947 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
4948
4949 my $config = {
4950 PidFile => $pid_file,
4951 ScoreboardFile => $scoreboard_file,
4952 SystemLog => $log_file,
4953
4954 AuthUserFile => $auth_user_file,
4955 AuthGroupFile => $auth_group_file,
4956 AuthOrder => 'mod_auth_file.c',
4957
4958 IfModules => {
4959 'mod_delay.c' => {
4960 DelayEngine => 'off',
4961 },
4962 },
4963 };
4964
4965 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4966
4967 # Open pipes, for use between the parent and child processes. Specifically,
4968 # the child will indicate when it's done with its test by writing a message
4969 # to the parent.
4970 my ($rfh, $wfh);
4971 unless (pipe($rfh, $wfh)) {
4972 die("Can't open pipe: $!");
4973 }
4974
4975 my $ex;
4976
4977 # Fork child
4978 $self->handle_sigchld();
4979 defined(my $pid = fork()) or die("Can't fork: $!");
4980 if ($pid) {
4981 eval {
4982 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4983
4984 $client->login($user, $passwd);
4985
4986 # Use the -t option to sort by time, and the -u option to sort by
4987 # st_atime. Thus the last file we created should appear first in the
4988 # returned list.
4989 my $conn = $client->list_raw("-ut 0*");
4990 unless ($conn) {
4991 die("LIST failed: " . $client->response_code() . " " .
4992 $client->response_msg());
4993 }
4994
4995 my $buf;
4996 $conn->read($buf, 32768, 30);
4997 eval { $conn->close() };
4998
4999 my $res = {};
5000 my $lines = [split(/\n/, $buf)];
5001
5002 my $fileno = 3;
5003 foreach my $line (@$lines) {
5004 if ($line =~ /\s+(\S+)$/) {
5005 my $filename = $1;
5006
5007 my $expected = sprintf("%04s", $fileno--);
5008
5009 $self->assert($expected eq $filename,
5010 test_msg("Expected '$expected', got '$filename'"));
5011
5012 $res->{$filename} = 1;
5013 }
5014 }
5015
5016 my $list_count = scalar(keys(%$res));
5017 unless ($list_count == $count) {
5018 die("LIST returned wrong number of entries (expected $count, got $list_count)");
5019 }
5020 };
5021
5022 if ($@) {
5023 $ex = $@;
5024 }
5025
5026 $wfh->print("done\n");
5027 $wfh->flush();
5028
5029 } else {
5030 eval { server_wait($config_file, $rfh) };
5031 if ($@) {
5032 warn($@);
5033 exit 1;
5034 }
5035
5036 exit 0;
5037 }
5038
5039 # Stop server
5040 server_stop($pid_file);
5041
5042 $self->assert_child_ok($pid);
5043
5044 if ($ex) {
5045 test_append_logfile($log_file, $ex);
5046 unlink($log_file);
5047
5048 die($ex);
5049 }
5050
5051 unlink($log_file);
5052 }
5053
5054 sub list_dash_filename_bug3476 {
5055 my $self = shift;
5056 my $tmpdir = $self->{tmpdir};
5057
5058 my $config_file = "$tmpdir/cmds.conf";
5059 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
5060 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
5061
5062 my $log_file = test_get_logfile();
5063
5064 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
5065 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
5066
5067 my $user = 'proftpd';
5068 my $passwd = 'test';
5069 my $home_dir = File::Spec->rel2abs($tmpdir);
5070 my $uid = 500;
5071 my $gid = 500;
5072
5073 # Make sure that, if we're running as root, that the home directory has
5074 # permissions/privs set for the account we create
5075 if ($< == 0) {
5076 unless (chmod(0755, $home_dir)) {
5077 die("Can't set perms on $home_dir to 0755: $!");
5078 }
5079
5080 unless (chown($uid, $gid, $home_dir)) {
5081 die("Can't set owner of $home_dir to $uid/$gid: $!");
5082 }
5083 }
5084
5085 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5086 '/bin/bash');
5087 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
5088
5089 my $test_file = File::Spec->rel2abs("$tmpdir/-test.txt");
5090 if (open(my $fh, "> $test_file")) {
5091 close($fh);
5092
5093 } else {
5094 die("Can't open $test_file: $!");
5095 }
5096
5097 my $config = {
5098 PidFile => $pid_file,
5099 ScoreboardFile => $scoreboard_file,
5100 SystemLog => $log_file,
5101
5102 AuthUserFile => $auth_user_file,
5103 AuthGroupFile => $auth_group_file,
5104 AuthOrder => 'mod_auth_file.c',
5105
5106 IfModules => {
5107 'mod_delay.c' => {
5108 DelayEngine => 'off',
5109 },
5110 },
5111 };
5112
5113 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5114
5115 # Open pipes, for use between the parent and child processes. Specifically,
5116 # the child will indicate when it's done with its test by writing a message
5117 # to the parent.
5118 my ($rfh, $wfh);
5119 unless (pipe($rfh, $wfh)) {
5120 die("Can't open pipe: $!");
5121 }
5122
5123 my $ex;
5124
5125 # Fork child
5126 $self->handle_sigchld();
5127 defined(my $pid = fork()) or die("Can't fork: $!");
5128 if ($pid) {
5129 eval {
5130 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5131 $client->login($user, $passwd);
5132
5133 my $conn = $client->list_raw('-test.txt');
5134 unless ($conn) {
5135 die("LIST failed: " . $client->response_code() . " " .
5136 $client->response_msg());
5137 }
5138
5139 my $buf;
5140 $conn->read($buf, 8192, 30);
5141 eval { $conn->close() };
5142
5143 my $res = {};
5144 my $lines = [split(/\n/, $buf)];
5145 foreach my $line (@$lines) {
5146 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*\s+(.*?)$/) {
5147 my $filename = $1;
5148 $res->{$filename} = 1;
5149 }
5150 }
5151
5152 my $count = scalar(keys(%$res));
5153 unless ($count == 1) {
5154 die("LIST returned wrong number of entries (expected 1, got $count)");
5155 }
5156
5157 my $expected = '-test.txt';
5158 unless (defined($res->{$expected})) {
5159 die("LIST failed to return $expected");
5160 }
5161 };
5162
5163 if ($@) {
5164 $ex = $@;
5165 }
5166
5167 $wfh->print("done\n");
5168 $wfh->flush();
5169
5170 } else {
5171 eval { server_wait($config_file, $rfh) };
5172 if ($@) {
5173 warn($@);
5174 exit 1;
5175 }
5176
5177 exit 0;
5178 }
5179
5180 # Stop server
5181 server_stop($pid_file);
5182
5183 $self->assert_child_ok($pid);
5184
5185 if ($ex) {
5186 test_append_logfile($log_file, $ex);
5187 unlink($log_file);
5188
5189 die($ex);
5190 }
5191
5192 unlink($log_file);
5193 }
5194
5195 sub list_opt_noerrorifabsent_bug3506 {
5196 my $self = shift;
5197 my $tmpdir = $self->{tmpdir};
5198
5199 my $config_file = "$tmpdir/cmds.conf";
5200 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
5201 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
5202
5203 my $log_file = test_get_logfile();
5204
5205 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
5206 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
5207
5208 my $user = 'proftpd';
5209 my $passwd = 'test';
5210 my $home_dir = File::Spec->rel2abs($tmpdir);
5211 my $uid = 500;
5212 my $gid = 500;
5213
5214 # Make sure that, if we're running as root, that the home directory has
5215 # permissions/privs set for the account we create
5216 if ($< == 0) {
5217 unless (chmod(0755, $home_dir)) {
5218 die("Can't set perms on $home_dir to 0755: $!");
5219 }
5220
5221 unless (chown($uid, $gid, $home_dir)) {
5222 die("Can't set owner of $home_dir to $uid/$gid: $!");
5223 }
5224 }
5225
5226 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5227 '/bin/bash');
5228 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
5229
5230 my $test_file = File::Spec->rel2abs('foo-bar.txt');
5231
5232 my $config = {
5233 PidFile => $pid_file,
5234 ScoreboardFile => $scoreboard_file,
5235 SystemLog => $log_file,
5236
5237 AuthUserFile => $auth_user_file,
5238 AuthGroupFile => $auth_group_file,
5239 AuthOrder => 'mod_auth_file.c',
5240
5241 ListOptions => '"" NoErrorIfAbsent',
5242
5243 IfModules => {
5244 'mod_delay.c' => {
5245 DelayEngine => 'off',
5246 },
5247 },
5248 };
5249
5250 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5251
5252 # Open pipes, for use between the parent and child processes. Specifically,
5253 # the child will indicate when it's done with its test by writing a message
5254 # to the parent.
5255 my ($rfh, $wfh);
5256 unless (pipe($rfh, $wfh)) {
5257 die("Can't open pipe: $!");
5258 }
5259
5260 my $ex;
5261
5262 # Fork child
5263 $self->handle_sigchld();
5264 defined(my $pid = fork()) or die("Can't fork: $!");
5265 if ($pid) {
5266 eval {
5267 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5268
5269 $client->login($user, $passwd);
5270
5271 my $conn = $client->list_raw($test_file);
5272 unless ($conn) {
5273 die("LIST failed: " . $client->response_code() . " " .
5274 $client->response_msg());
5275 }
5276
5277 my $buf;
5278 $conn->read($buf, 8192, 30);
5279 eval { $conn->close() };
5280
5281 my $resp_code = $client->response_code();
5282 my $resp_msg = $client->response_msg();
5283 $self->assert_transfer_ok($resp_code, $resp_msg);
5284
5285 my $res = {};
5286 my $lines = [split(/\n/, $buf)];
5287 foreach my $line (@$lines) {
5288 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
5289 $res->{$1} = 1;
5290 }
5291 }
5292
5293 my $count = scalar(keys(%$res));
5294 unless ($count == 0) {
5295 die("LIST returned wrong number of entries (expected 0, got $count)");
5296 }
5297 };
5298
5299 if ($@) {
5300 $ex = $@;
5301 }
5302
5303 $wfh->print("done\n");
5304 $wfh->flush();
5305
5306 } else {
5307 eval { server_wait($config_file, $rfh) };
5308 if ($@) {
5309 warn($@);
5310 exit 1;
5311 }
5312
5313 exit 0;
5314 }
5315
5316 # Stop server
5317 server_stop($pid_file);
5318
5319 $self->assert_child_ok($pid);
5320
5321 if ($ex) {
5322 test_append_logfile($log_file, $ex);
5323 unlink($log_file);
5324
5325 die($ex);
5326 }
5327
5328 unlink($log_file);
5329 }
5330
5331 sub list_slashstar_bug3529 {
5332 my $self = shift;
5333 my $tmpdir = $self->{tmpdir};
5334
5335 my $config_file = "$tmpdir/cmds.conf";
5336 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
5337 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
5338
5339 my $log_file = test_get_logfile();
5340
5341 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
5342 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
5343
5344 my $user = 'proftpd';
5345 my $passwd = 'test';
5346 my $home_dir = File::Spec->rel2abs($tmpdir);
5347 my $uid = 500;
5348 my $gid = 500;
5349
5350 my $sub_dir = File::Spec->rel2abs("$tmpdir/AAA");
5351 mkpath($sub_dir);
5352
5353 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
5354 if (open(my $fh, "> $test_file")) {
5355 close($fh);
5356
5357 } else {
5358 die("Can't open $test_file: $!");
5359 }
5360
5361 $test_file = File::Spec->rel2abs("$tmpdir/.dotfile");
5362 if (open(my $fh, "> $test_file")) {
5363 close($fh);
5364
5365 } else {
5366 die("Can't open $test_file: $!");
5367 }
5368
5369 $test_file = File::Spec->rel2abs("$sub_dir/bar.txt");
5370 if (open(my $fh, "> $test_file")) {
5371 close($fh);
5372
5373 } else {
5374 die("Can't open $test_file: $!");
5375 }
5376
5377 # Make sure that, if we're running as root, that the home directory has
5378 # permissions/privs set for the account we create
5379 if ($< == 0) {
5380 unless (chmod(0755, $home_dir, $sub_dir)) {
5381 die("Can't set perms on dirs to 0755: $!");
5382 }
5383
5384 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5385 die("Can't set owner of dirs to $uid/$gid: $!");
5386 }
5387 }
5388
5389 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5390 '/bin/bash');
5391 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
5392
5393 my $config = {
5394 PidFile => $pid_file,
5395 ScoreboardFile => $scoreboard_file,
5396 SystemLog => $log_file,
5397
5398 AuthUserFile => $auth_user_file,
5399 AuthGroupFile => $auth_group_file,
5400 AuthOrder => 'mod_auth_file.c',
5401
5402 DefaultRoot => '~',
5403
5404 IfModules => {
5405 'mod_delay.c' => {
5406 DelayEngine => 'off',
5407 },
5408 },
5409 };
5410
5411 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5412
5413 # Open pipes, for use between the parent and child processes. Specifically,
5414 # the child will indicate when it's done with its test by writing a message
5415 # to the parent.
5416 my ($rfh, $wfh);
5417 unless (pipe($rfh, $wfh)) {
5418 die("Can't open pipe: $!");
5419 }
5420
5421 my $ex;
5422
5423 # Fork child
5424 $self->handle_sigchld();
5425 defined(my $pid = fork()) or die("Can't fork: $!");
5426 if ($pid) {
5427 eval {
5428 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5429 $client->login($user, $passwd);
5430
5431 my $conn = $client->list_raw('/*');
5432 unless ($conn) {
5433 die("Failed to LIST: " . $client->response_code() . " " .
5434 $client->response_msg());
5435 }
5436
5437 my $buf;
5438 $conn->read($buf, 8192, 30);
5439 eval { $conn->close() };
5440
5441 my $resp_code = $client->response_code();
5442 my $resp_msg = $client->response_msg();
5443 $self->assert_transfer_ok($resp_code, $resp_msg);
5444
5445 $client->quit();
5446
5447 # We have to be careful of the fact that readdir returns directory
5448 # entries in an unordered fashion.
5449 my $res = {};
5450 my $lines = [split(/\n/, $buf)];
5451 foreach my $line (@$lines) {
5452 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
5453 $res->{$1} = 1;
5454 }
5455 }
5456
5457 my $expected = {
5458 '/AAA' => 1,
5459 '/cmds.conf' => 1,
5460 '/cmds.group' => 1,
5461 '/cmds.passwd' => 1,
5462 '/cmds.pid' => 1,
5463 '/cmds.scoreboard' => 1,
5464 '/cmds.scoreboard.lck' => 1,
5465 '/foo.txt' => 1,
5466 };
5467
5468 my $ok = 1;
5469 my $mismatch;
5470 foreach my $name (keys(%$res)) {
5471 unless (defined($expected->{$name})) {
5472 $mismatch = $name;
5473 $ok = 0;
5474 last;
5475 }
5476 }
5477
5478 unless ($ok) {
5479 die("Unexpected name '$mismatch' appeared in LIST data")
5480 }
5481 };
5482
5483 if ($@) {
5484 $ex = $@;
5485 }
5486
5487 $wfh->print("done\n");
5488 $wfh->flush();
5489
5490 } else {
5491 eval { server_wait($config_file, $rfh) };
5492 if ($@) {
5493 warn($@);
5494 exit 1;
5495 }
5496
5497 exit 0;
5498 }
5499
5500 # Stop server
5501 server_stop($pid_file);
5502
5503 $self->assert_child_ok($pid);
5504
5505 if ($ex) {
5506 test_append_logfile($log_file, $ex);
5507 unlink($log_file);
5508
5509 die($ex);
5510 }
5511
5512 unlink($log_file);
5513 }
5514
5515 sub list_star_bug3529 {
5516 my $self = shift;
5517 my $tmpdir = $self->{tmpdir};
5518
5519 my $config_file = "$tmpdir/cmds.conf";
5520 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
5521 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
5522
5523 my $log_file = test_get_logfile();
5524
5525 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
5526 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
5527
5528 my $user = 'proftpd';
5529 my $passwd = 'test';
5530 my $home_dir = File::Spec->rel2abs($tmpdir);
5531 my $uid = 500;
5532 my $gid = 500;
5533
5534 my $sub_dir = File::Spec->rel2abs("$tmpdir/AAA");
5535 mkpath($sub_dir);
5536
5537 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
5538 if (open(my $fh, "> $test_file")) {
5539 close($fh);
5540
5541 } else {
5542 die("Can't open $test_file: $!");
5543 }
5544
5545 $test_file = File::Spec->rel2abs("$tmpdir/.dotfile");
5546 if (open(my $fh, "> $test_file")) {
5547 close($fh);
5548
5549 } else {
5550 die("Can't open $test_file: $!");
5551 }
5552
5553 $test_file = File::Spec->rel2abs("$sub_dir/bar.txt");
5554 if (open(my $fh, "> $test_file")) {
5555 close($fh);
5556
5557 } else {
5558 die("Can't open $test_file: $!");
5559 }
5560
5561 # Make sure that, if we're running as root, that the home directory has
5562 # permissions/privs set for the account we create
5563 if ($< == 0) {
5564 unless (chmod(0755, $home_dir, $sub_dir)) {
5565 die("Can't set perms on dirs to 0755: $!");
5566 }
5567
5568 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5569 die("Can't set owner of dirs to $uid/$gid: $!");
5570 }
5571 }
5572
5573 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5574 '/bin/bash');
5575 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
5576
5577 my $config = {
5578 PidFile => $pid_file,
5579 ScoreboardFile => $scoreboard_file,
5580 SystemLog => $log_file,
5581
5582 AuthUserFile => $auth_user_file,
5583 AuthGroupFile => $auth_group_file,
5584 AuthOrder => 'mod_auth_file.c',
5585
5586 IfModules => {
5587 'mod_delay.c' => {
5588 DelayEngine => 'off',
5589 },
5590 },
5591 };
5592
5593 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5594
5595 # Open pipes, for use between the parent and child processes. Specifically,
5596 # the child will indicate when it's done with its test by writing a message
5597 # to the parent.
5598 my ($rfh, $wfh);
5599 unless (pipe($rfh, $wfh)) {
5600 die("Can't open pipe: $!");
5601 }
5602
5603 my $ex;
5604
5605 # Fork child
5606 $self->handle_sigchld();
5607 defined(my $pid = fork()) or die("Can't fork: $!");
5608 if ($pid) {
5609 eval {
5610 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5611 $client->login($user, $passwd);
5612
5613 my $conn = $client->list_raw('*');
5614 unless ($conn) {
5615 die("Failed to LIST: " . $client->response_code() . " " .
5616 $client->response_msg());
5617 }
5618
5619 my $buf;
5620 $conn->read($buf, 8192, 30);
5621 eval { $conn->close() };
5622
5623 my $resp_code = $client->response_code();
5624 my $resp_msg = $client->response_msg();
5625 $self->assert_transfer_ok($resp_code, $resp_msg);
5626
5627 $client->quit();
5628
5629 # We have to be careful of the fact that readdir returns directory
5630 # entries in an unordered fashion.
5631 my $res = {};
5632 my $lines = [split(/\n/, $buf)];
5633 foreach my $line (@$lines) {
5634 if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) {
5635 $res->{$1} = 1;
5636 }
5637 }
5638
5639 my $expected = {
5640 'AAA' => 1,
5641 'cmds.conf' => 1,
5642 'cmds.group' => 1,
5643 'cmds.passwd' => 1,
5644 'cmds.pid' => 1,
5645 'cmds.scoreboard' => 1,
5646 'cmds.scoreboard.lck' => 1,
5647 'foo.txt' => 1,
5648 };
5649
5650 my $ok = 1;
5651 my $mismatch;
5652 foreach my $name (keys(%$res)) {
5653 unless (defined($expected->{$name})) {
5654 $mismatch = $name;
5655 $ok = 0;
5656 last;
5657 }
5658 }
5659
5660 unless ($ok) {
5661 die("Unexpected name '$mismatch' appeared in LIST data")
5662 }
5663 };
5664
5665 if ($@) {
5666 $ex = $@;
5667 }
5668
5669 $wfh->print("done\n");
5670 $wfh->flush();
5671
5672 } else {
5673 eval { server_wait($config_file, $rfh) };
5674 if ($@) {
5675 warn($@);
5676 exit 1;
5677 }
5678
5679 exit 0;
5680 }
5681
5682 # Stop server
5683 server_stop($pid_file);
5684
5685 $self->assert_child_ok($pid);
5686
5687 if ($ex) {
5688 test_append_logfile($log_file, $ex);
5689 unlink($log_file);
5690
5691 die($ex);
5692 }
5693
5694 unlink($log_file);
5695 }
5696
5697 sub list_opt_R {
5698 my $self = shift;
5699 my $tmpdir = $self->{tmpdir};
5700
5701 my $config_file = "$tmpdir/cmds.conf";
5702 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
5703 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
5704
5705 my $log_file = test_get_logfile();
5706
5707 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
5708 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
5709
5710 my $user = 'proftpd';
5711 my $passwd = 'test';
5712 my $group = 'ftpd';
5713 my $home_dir = File::Spec->rel2abs($tmpdir);
5714 my $uid = 500;
5715 my $gid = 500;
5716
5717 # Make sure that, if we're running as root, that the home directory has
5718 # permissions/privs set for the account we create
5719 if ($< == 0) {
5720 unless (chmod(0755, $home_dir)) {
5721 die("Can't set perms on $home_dir to 0755: $!");
5722 }
5723
5724 unless (chown($uid, $gid, $home_dir)) {
5725 die("Can't set owner of $home_dir to $uid/$gid: $!");
5726 }
5727 }
5728
5729 # For this test, we need to create about 100 files in home directory.
5730 my $test_file_prefix = File::Spec->rel2abs($tmpdir);
5731
5732 my $dir_count = 10;
5733 my $file_count = 10;
5734
5735 print STDOUT "# Creating $dir_count directories in $tmpdir\n";
5736 for (my $i = 1; $i <= $dir_count; $i++) {
5737 my $test_dir = sprintf("%04s", $i);
5738 my $dir_path = "$home_dir/$test_dir";
5739
5740 mkpath($dir_path);
5741
5742 print STDOUT "# Creating $file_count files in $dir_path\n";
5743 for (my $j = 1; $j <= $file_count; $j++) {
5744 my $test_file = sprintf("%02s%02s", $i, $j);
5745 my $file_path = "$dir_path/$test_file";
5746
5747 if (open(my $fh, "> $file_path")) {
5748 close($fh);
5749
5750 } else {
5751 die("Can't open $file_path: $!");
5752 }
5753 }
5754 }
5755
5756 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5757 '/bin/bash');
5758 auth_group_write($auth_group_file, $group, $gid, $user);
5759
5760 my $config = {
5761 PidFile => $pid_file,
5762 ScoreboardFile => $scoreboard_file,
5763 SystemLog => $log_file,
5764
5765 AuthUserFile => $auth_user_file,
5766 AuthGroupFile => $auth_group_file,
5767 AuthOrder => 'mod_auth_file.c',
5768
5769 IfModules => {
5770 'mod_delay.c' => {
5771 DelayEngine => 'off',
5772 },
5773 },
5774 };
5775
5776 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5777
5778 # Open pipes, for use between the parent and child processes. Specifically,
5779 # the child will indicate when it's done with its test by writing a message
5780 # to the parent.
5781 my ($rfh, $wfh);
5782 unless (pipe($rfh, $wfh)) {
5783 die("Can't open pipe: $!");
5784 }
5785
5786 my $ex;
5787
5788 # Fork child
5789 $self->handle_sigchld();
5790 defined(my $pid = fork()) or die("Can't fork: $!");
5791 if ($pid) {
5792 eval {
5793 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5794 $client->login($user, $passwd);
5795
5796 my $conn = $client->list_raw("-R");
5797 unless ($conn) {
5798 die("LIST failed: " . $client->response_code() . " " .
5799 $client->response_msg());
5800 }
5801
5802 my $buf;
5803 my $tmp;
5804
5805 my $res = $conn->read($tmp, 32768, 25);
5806 while ($res) {
5807 $buf .= $tmp;
5808 $tmp = undef;
5809
5810 $res = $conn->read($tmp, 32768, 25);
5811 }
5812
5813 eval { $conn->close() };
5814
5815 $res = {};
5816 my $lines = [split(/\n/, $buf)];
5817 foreach my $line (@$lines) {
5818 if ($line =~ /\s+(\S+)$/) {
5819 $res->{$1} = 1;
5820 }
5821 }
5822
5823 my $list_count = scalar(keys(%$res));
5824
5825 # There are 10 directories, with 10 files in each. That's 100 files.
5826 # Plus 10 for the directory names themselves. Plus 6 files for the
5827 # config, scoreboard, etc. That gives a total of 116 files expected.
5828 # The extra files are for the config file, scoreboard, etc.
5829 my $expected_count = ($dir_count * $file_count) + 16;
5830 unless ($list_count == $expected_count) {
5831 die("LIST returned wrong number of entries (expected $expected_count, got $list_count)");
5832 }
5833 };
5834
5835 if ($@) {
5836 $ex = $@;
5837 }
5838
5839 $wfh->print("done\n");
5840 $wfh->flush();
5841
5842 } else {
5843 eval { server_wait($config_file, $rfh) };
5844 if ($@) {
5845 warn($@);
5846 exit 1;
5847 }
5848
5849 exit 0;
5850 }
5851
5852 # Stop server
5853 server_stop($pid_file);
5854
5855 $self->assert_child_ok($pid);
5856
5857 if ($ex) {
5858 test_append_logfile($log_file, $ex);
5859 unlink($log_file);
5860
5861 die($ex);
5862 }
5863
5864 unlink($log_file);
5865 }
5866
5867 sub list_opt_R_self_symlinked_dir_bug3719 {
5868 my $self = shift;
5869 my $tmpdir = $self->{tmpdir};
5870
5871 my $config_file = "$tmpdir/cmds.conf";
5872 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
5873 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
5874
5875 my $log_file = test_get_logfile();
5876
5877 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
5878 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
5879
5880 my $user = 'proftpd';
5881 my $passwd = 'test';
5882 my $group = 'ftpd';
5883 my $home_dir = File::Spec->rel2abs($tmpdir);
5884 my $uid = 500;
5885 my $gid = 500;
5886
5887 # Make sure that, if we're running as root, that the home directory has
5888 # permissions/privs set for the account we create
5889 if ($< == 0) {
5890 unless (chmod(0755, $home_dir)) {
5891 die("Can't set perms on $home_dir to 0755: $!");
5892 }
5893
5894 unless (chown($uid, $gid, $home_dir)) {
5895 die("Can't set owner of $home_dir to $uid/$gid: $!");
5896 }
5897 }
5898
5899 # For this test, we need to create about 100 files in a sub directory.
5900 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
5901 mkpath($test_dir);
5902
5903 my $test_file_prefix = $test_dir;
5904
5905 my $dir_count = 10;
5906 my $file_count = 10;
5907
5908 if ($ENV{TEST_VERBOSE}) {
5909 print STDOUT "# Creating $dir_count directories in $tmpdir\n";
5910 }
5911
5912 for (my $i = 1; $i <= $dir_count; $i++) {
5913 my $sub_dir = sprintf("%04s", $i);
5914 my $dir_path = "$home_dir/$sub_dir";
5915
5916 mkpath($dir_path);
5917
5918 if ($ENV{TEST_VERBOSE}) {
5919 print STDOUT "# Creating $file_count files in $dir_path\n";
5920 }
5921
5922 for (my $j = 1; $j <= $file_count; $j++) {
5923 my $test_file = sprintf("%02s%02s", $i, $j);
5924 my $file_path = "$dir_path/$test_file";
5925
5926 if (open(my $fh, "> $file_path")) {
5927 close($fh);
5928
5929 } else {
5930 die("Can't open $file_path: $!");
5931 }
5932 }
5933 }
5934
5935 # Now create a directory symlink, in the home directory, pointing to itself.
5936 # This self-symlink is what caused Bug#3719 - proftpd would loop endlessly.
5937
5938 my $cwd = getcwd();
5939
5940 unless (chdir($test_dir)) {
5941 die("Can't chdir to $test_dir: $!");
5942 }
5943
5944 unless (symlink('.', 'self.d')) {
5945 die("Can't symlink '.' to 'self.d': $!");
5946 }
5947
5948 unless (chdir($cwd)) {
5949 die("Can't chdir to $cwd: $!");
5950 }
5951
5952 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5953 '/bin/bash');
5954 auth_group_write($auth_group_file, $group, $gid, $user);
5955
5956 my $config = {
5957 PidFile => $pid_file,
5958 ScoreboardFile => $scoreboard_file,
5959 SystemLog => $log_file,
5960
5961 AuthUserFile => $auth_user_file,
5962 AuthGroupFile => $auth_group_file,
5963 AuthOrder => 'mod_auth_file.c',
5964
5965 IfModules => {
5966 'mod_delay.c' => {
5967 DelayEngine => 'off',
5968 },
5969 },
5970 };
5971
5972 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5973
5974 # Open pipes, for use between the parent and child processes. Specifically,
5975 # the child will indicate when it's done with its test by writing a message
5976 # to the parent.
5977 my ($rfh, $wfh);
5978 unless (pipe($rfh, $wfh)) {
5979 die("Can't open pipe: $!");
5980 }
5981
5982 my $ex;
5983
5984 # Fork child
5985 $self->handle_sigchld();
5986 defined(my $pid = fork()) or die("Can't fork: $!");
5987 if ($pid) {
5988 eval {
5989 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5990 $client->login($user, $passwd);
5991
5992 my $conn = $client->list_raw("-R");
5993 unless ($conn) {
5994 die("LIST failed: " . $client->response_code() . " " .
5995 $client->response_msg());
5996 }
5997
5998 my $buf;
5999 my $tmp;
6000
6001 my $res = $conn->read($tmp, 32768, 25);
6002 while ($res) {
6003 $buf .= $tmp;
6004 $tmp = undef;
6005
6006 $res = $conn->read($tmp, 32768, 25);
6007 }
6008
6009 eval { $conn->close() };
6010
6011 $res = {};
6012 my $lines = [split(/\n/, $buf)];
6013 foreach my $line (@$lines) {
6014 if ($line =~ /\s+(\S+)$/) {
6015 $res->{$1} = 1;
6016 }
6017 }
6018
6019 my $list_count = scalar(keys(%$res));
6020
6021 # There are 10 directories, with 10 files in each. That's 100 files.
6022 # Plus 10 for the directory names themselves. Plus 6 files for the
6023 # config, scoreboard, etc, and one for the symlink. That gives a total
6024 # of 116 files expected. The extra files are for the config file,
6025 # scoreboard, etc.
6026 my $expected_count = ($dir_count * $file_count) + 17;
6027 unless ($list_count == $expected_count) {
6028 die("LIST returned wrong number of entries (expected $expected_count, got $list_count)");
6029 }
6030 };
6031
6032 if ($@) {
6033 $ex = $@;
6034 }
6035
6036 $wfh->print("done\n");
6037 $wfh->flush();
6038
6039 } else {
6040 eval { server_wait($config_file, $rfh) };
6041 if ($@) {
6042 warn($@);
6043 exit 1;
6044 }
6045
6046 exit 0;
6047 }
6048
6049 # Stop server
6050 server_stop($pid_file);
6051
6052 $self->assert_child_ok($pid);
6053
6054 if ($ex) {
6055 test_append_logfile($log_file, $ex);
6056 unlink($log_file);
6057
6058 die($ex);
6059 }
6060
6061 unlink($log_file);
6062 }
6063
6064 sub list_opt_R_self_complex_symlinked_dir_bug3719 {
6065 my $self = shift;
6066 my $tmpdir = $self->{tmpdir};
6067
6068 my $config_file = "$tmpdir/cmds.conf";
6069 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
6070 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
6071
6072 my $log_file = test_get_logfile();
6073
6074 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
6075 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
6076
6077 my $user = 'proftpd';
6078 my $passwd = 'test';
6079 my $group = 'ftpd';
6080 my $home_dir = File::Spec->rel2abs($tmpdir);
6081 my $uid = 500;
6082 my $gid = 500;
6083
6084 # Make sure that, if we're running as root, that the home directory has
6085 # permissions/privs set for the account we create
6086 if ($< == 0) {
6087 unless (chmod(0755, $home_dir)) {
6088 die("Can't set perms on $home_dir to 0755: $!");
6089 }
6090
6091 unless (chown($uid, $gid, $home_dir)) {
6092 die("Can't set owner of $home_dir to $uid/$gid: $!");
6093 }
6094 }
6095
6096 # For this test, we need to create about 100 files in a sub directory.
6097 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
6098 mkpath($test_dir);
6099
6100 my $test_file_prefix = $test_dir;
6101
6102 my $dir_count = 10;
6103 my $file_count = 10;
6104
6105 if ($ENV{TEST_VERBOSE}) {
6106 print STDOUT "# Creating $dir_count directories in $tmpdir\n";
6107 }
6108
6109 for (my $i = 1; $i <= $dir_count; $i++) {
6110 my $sub_dir = sprintf("%04s", $i);
6111 my $dir_path = "$home_dir/$sub_dir";
6112
6113 mkpath($dir_path);
6114
6115 if ($ENV{TEST_VERBOSE}) {
6116 print STDOUT "# Creating $file_count files in $dir_path\n";
6117 }
6118
6119 for (my $j = 1; $j <= $file_count; $j++) {
6120 my $test_file = sprintf("%02s%02s", $i, $j);
6121 my $file_path = "$dir_path/$test_file";
6122
6123 if (open(my $fh, "> $file_path")) {
6124 close($fh);
6125
6126 } else {
6127 die("Can't open $file_path: $!");
6128 }
6129 }
6130 }
6131
6132 # Now create a directory symlink, in the home directory, pointing to itself.
6133 # This self-symlink is what caused Bug#3719 - proftpd would loop endlessly.
6134
6135 my $cwd = getcwd();
6136
6137 unless (chdir($test_dir)) {
6138 die("Can't chdir to $test_dir: $!");
6139 }
6140
6141 unless (symlink('../.././././.././', 'self.d')) {
6142 die("Can't symlink '../.././././.././' to 'self.d': $!");
6143 }
6144
6145 unless (chdir($cwd)) {
6146 die("Can't chdir to $cwd: $!");
6147 }
6148
6149 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6150 '/bin/bash');
6151 auth_group_write($auth_group_file, $group, $gid, $user);
6152
6153 my $config = {
6154 PidFile => $pid_file,
6155 ScoreboardFile => $scoreboard_file,
6156 SystemLog => $log_file,
6157
6158 AuthUserFile => $auth_user_file,
6159 AuthGroupFile => $auth_group_file,
6160 AuthOrder => 'mod_auth_file.c',
6161
6162 IfModules => {
6163 'mod_delay.c' => {
6164 DelayEngine => 'off',
6165 },
6166 },
6167 };
6168
6169 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6170
6171 # Open pipes, for use between the parent and child processes. Specifically,
6172 # the child will indicate when it's done with its test by writing a message
6173 # to the parent.
6174 my ($rfh, $wfh);
6175 unless (pipe($rfh, $wfh)) {
6176 die("Can't open pipe: $!");
6177 }
6178
6179 my $ex;
6180
6181 # Fork child
6182 $self->handle_sigchld();
6183 defined(my $pid = fork()) or die("Can't fork: $!");
6184 if ($pid) {
6185 eval {
6186 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6187 $client->login($user, $passwd);
6188
6189 my $conn = $client->list_raw("-R");
6190 unless ($conn) {
6191 die("LIST failed: " . $client->response_code() . " " .
6192 $client->response_msg());
6193 }
6194
6195 my $buf;
6196 my $tmp;
6197
6198 my $res = $conn->read($tmp, 32768, 25);
6199 while ($res) {
6200 $buf .= $tmp;
6201 $tmp = undef;
6202
6203 $res = $conn->read($tmp, 32768, 25);
6204 }
6205
6206 eval { $conn->close() };
6207
6208 $res = {};
6209 my $lines = [split(/\n/, $buf)];
6210 foreach my $line (@$lines) {
6211 if ($line =~ /\s+(\S+)$/) {
6212 $res->{$1} = 1;
6213 }
6214 }
6215
6216 my $list_count = scalar(keys(%$res));
6217
6218 # There are 10 directories, with 10 files in each. That's 100 files.
6219 # Plus 10 for the directory names themselves. Plus 6 files for the
6220 # config, scoreboard, etc, and one for the symlink. That gives a total
6221 # of 116 files expected. The extra files are for the config file,
6222 # scoreboard, etc.
6223 my $expected_count = ($dir_count * $file_count) + 17;
6224 unless ($list_count == $expected_count) {
6225 die("LIST returned wrong number of entries (expected $expected_count, got $list_count)");
6226 }
6227 };
6228
6229 if ($@) {
6230 $ex = $@;
6231 }
6232
6233 $wfh->print("done\n");
6234 $wfh->flush();
6235
6236 } else {
6237 eval { server_wait($config_file, $rfh) };
6238 if ($@) {
6239 warn($@);
6240 exit 1;
6241 }
6242
6243 exit 0;
6244 }
6245
6246 # Stop server
6247 server_stop($pid_file);
6248
6249 $self->assert_child_ok($pid);
6250
6251 if ($ex) {
6252 test_append_logfile($log_file, $ex);
6253 unlink($log_file);
6254
6255 die($ex);
6256 }
6257
6258 unlink($log_file);
6259 }
6260
6261 sub list_opt_R_rel_symlinked_file_bug3719 {
6262 my $self = shift;
6263 my $tmpdir = $self->{tmpdir};
6264
6265 my $config_file = "$tmpdir/cmds.conf";
6266 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
6267 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
6268
6269 my $log_file = test_get_logfile();
6270
6271 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
6272 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
6273
6274 my $user = 'proftpd';
6275 my $passwd = 'test';
6276 my $group = 'ftpd';
6277 my $home_dir = File::Spec->rel2abs($tmpdir);
6278 my $uid = 500;
6279 my $gid = 500;
6280
6281 # Make sure that, if we're running as root, that the home directory has
6282 # permissions/privs set for the account we create
6283 if ($< == 0) {
6284 unless (chmod(0755, $home_dir)) {
6285 die("Can't set perms on $home_dir to 0755: $!");
6286 }
6287
6288 unless (chown($uid, $gid, $home_dir)) {
6289 die("Can't set owner of $home_dir to $uid/$gid: $!");
6290 }
6291 }
6292
6293 # For this test, we need to create about 100 files in a sub directory.
6294 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
6295 mkpath($test_dir);
6296
6297 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
6298 if (open(my $fh, "> $test_file")) {
6299 close($fh);
6300
6301 } else {
6302 die("Can't open $test_file: $!");
6303 }
6304
6305 my $test_file_prefix = $test_dir;
6306
6307 my $dir_count = 10;
6308 my $file_count = 10;
6309
6310 if ($ENV{TEST_VERBOSE}) {
6311 print STDOUT "# Creating $dir_count directories in $tmpdir\n";
6312 }
6313
6314 for (my $i = 1; $i <= $dir_count; $i++) {
6315 my $sub_dir = sprintf("%04s", $i);
6316 my $dir_path = "$home_dir/$sub_dir";
6317
6318 mkpath($dir_path);
6319
6320 if ($ENV{TEST_VERBOSE}) {
6321 print STDOUT "# Creating $file_count files in $dir_path\n";
6322 }
6323
6324 for (my $j = 1; $j <= $file_count; $j++) {
6325 my $test_file = sprintf("%02s%02s", $i, $j);
6326 my $file_path = "$dir_path/$test_file";
6327
6328 if (open(my $fh, "> $file_path")) {
6329 close($fh);
6330
6331 } else {
6332 die("Can't open $file_path: $!");
6333 }
6334 }
6335 }
6336
6337 my $cwd = getcwd();
6338
6339 unless (chdir($test_dir)) {
6340 die("Can't chdir to $test_dir: $!");
6341 }
6342
6343 unless (symlink('./test.txt', 'test.lnk')) {
6344 die("Can't symlink './test.txt' to 'test.lnk': $!");
6345 }
6346
6347 unless (chdir($cwd)) {
6348 die("Can't chdir to $cwd: $!");
6349 }
6350
6351 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6352 '/bin/bash');
6353 auth_group_write($auth_group_file, $group, $gid, $user);
6354
6355 my $config = {
6356 PidFile => $pid_file,
6357 ScoreboardFile => $scoreboard_file,
6358 SystemLog => $log_file,
6359
6360 AuthUserFile => $auth_user_file,
6361 AuthGroupFile => $auth_group_file,
6362 AuthOrder => 'mod_auth_file.c',
6363
6364 IfModules => {
6365 'mod_delay.c' => {
6366 DelayEngine => 'off',
6367 },
6368 },
6369 };
6370
6371 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6372
6373 # Open pipes, for use between the parent and child processes. Specifically,
6374 # the child will indicate when it's done with its test by writing a message
6375 # to the parent.
6376 my ($rfh, $wfh);
6377 unless (pipe($rfh, $wfh)) {
6378 die("Can't open pipe: $!");
6379 }
6380
6381 my $ex;
6382
6383 # Fork child
6384 $self->handle_sigchld();
6385 defined(my $pid = fork()) or die("Can't fork: $!");
6386 if ($pid) {
6387 eval {
6388 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6389 $client->login($user, $passwd);
6390
6391 my $conn = $client->list_raw("-R");
6392 unless ($conn) {
6393 die("LIST failed: " . $client->response_code() . " " .
6394 $client->response_msg());
6395 }
6396
6397 my $buf;
6398 my $tmp;
6399
6400 my $res = $conn->read($tmp, 32768, 25);
6401 while ($res) {
6402 $buf .= $tmp;
6403 $tmp = undef;
6404
6405 $res = $conn->read($tmp, 32768, 25);
6406 }
6407
6408 eval { $conn->close() };
6409
6410 $res = {};
6411 my $lines = [split(/\n/, $buf)];
6412 foreach my $line (@$lines) {
6413 if ($line =~ /\s+(\S+)$/) {
6414 $res->{$1} = 1;
6415 }
6416 }
6417
6418 my $list_count = scalar(keys(%$res));
6419
6420 # There are 10 directories, with 10 files in each. That's 100 files.
6421 # Plus 10 for the directory names themselves. Plus 6 files for the
6422 # config, scoreboard, etc, and one for the symlink. That gives a total
6423 # of 116 files expected. The extra files are for the config file,
6424 # scoreboard, etc.
6425 my $expected_count = ($dir_count * $file_count) + 19;
6426 unless ($list_count == $expected_count) {
6427 die("LIST returned wrong number of entries (expected $expected_count, got $list_count)");
6428 }
6429 };
6430
6431 if ($@) {
6432 $ex = $@;
6433 }
6434
6435 $wfh->print("done\n");
6436 $wfh->flush();
6437
6438 } else {
6439 eval { server_wait($config_file, $rfh) };
6440 if ($@) {
6441 warn($@);
6442 exit 1;
6443 }
6444
6445 exit 0;
6446 }
6447
6448 # Stop server
6449 server_stop($pid_file);
6450
6451 $self->assert_child_ok($pid);
6452
6453 if ($ex) {
6454 test_append_logfile($log_file, $ex);
6455 unlink($log_file);
6456
6457 die($ex);
6458 }
6459
6460 unlink($log_file);
6461 }
6462
6463 sub list_option_parsing {
6464 my $self = shift;
6465 my $tmpdir = $self->{tmpdir};
6466
6467 my $config_file = "$tmpdir/cmds.conf";
6468 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
6469 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
6470
6471 my $log_file = test_get_logfile();
6472
6473 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
6474 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
6475
6476 my $user = 'proftpd';
6477 my $passwd = 'test';
6478 my $group = 'ftpd';
6479 my $home_dir = File::Spec->rel2abs($tmpdir);
6480 my $uid = 500;
6481 my $gid = 500;
6482
6483 # Make sure that, if we're running as root, that the home directory has
6484 # permissions/privs set for the account we create
6485 if ($< == 0) {
6486 unless (chmod(0755, $home_dir)) {
6487 die("Can't set perms on $home_dir to 0755: $!");
6488 }
6489
6490 unless (chown($uid, $gid, $home_dir)) {
6491 die("Can't set owner of $home_dir to $uid/$gid: $!");
6492 }
6493 }
6494
6495 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6496 '/bin/bash');
6497 auth_group_write($auth_group_file, $group, $gid, $user);
6498
6499 my $config = {
6500 PidFile => $pid_file,
6501 ScoreboardFile => $scoreboard_file,
6502 SystemLog => $log_file,
6503
6504 AuthUserFile => $auth_user_file,
6505 AuthGroupFile => $auth_group_file,
6506 AuthOrder => 'mod_auth_file.c',
6507
6508 IfModules => {
6509 'mod_delay.c' => {
6510 DelayEngine => 'off',
6511 },
6512 },
6513 };
6514
6515 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6516
6517 # Open pipes, for use between the parent and child processes. Specifically,
6518 # the child will indicate when it's done with its test by writing a message
6519 # to the parent.
6520 my ($rfh, $wfh);
6521 unless (pipe($rfh, $wfh)) {
6522 die("Can't open pipe: $!");
6523 }
6524
6525 my $ex;
6526
6527 # Fork child
6528 $self->handle_sigchld();
6529 defined(my $pid = fork()) or die("Can't fork: $!");
6530 if ($pid) {
6531 eval {
6532 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6533 $client->login($user, $passwd);
6534
6535 for (my $i = 0; $i < 5; $i++) {
6536 my $conn = $client->list_raw("-a ");
6537 unless ($conn) {
6538 die("LIST failed: " . $client->response_code() . " " .
6539 $client->response_msg());
6540 }
6541
6542 my $buf;
6543 my $tmp;
6544
6545 my $res = $conn->read($tmp, 32768, 25);
6546 while ($res) {
6547 $buf .= $tmp;
6548 $tmp = undef;
6549
6550 $res = $conn->read($tmp, 32768, 25);
6551 }
6552
6553 eval { $conn->close() };
6554
6555 my $resp_code = $client->response_code();
6556 my $resp_msg = $client->response_msg();
6557 $self->assert_transfer_ok($resp_code, $resp_msg);
6558 }
6559
6560 $client->quit();
6561 };
6562
6563 if ($@) {
6564 $ex = $@;
6565 }
6566
6567 $wfh->print("done\n");
6568 $wfh->flush();
6569
6570 } else {
6571 eval { server_wait($config_file, $rfh) };
6572 if ($@) {
6573 warn($@);
6574 exit 1;
6575 }
6576
6577 exit 0;
6578 }
6579
6580 # Stop server
6581 server_stop($pid_file);
6582
6583 $self->assert_child_ok($pid);
6584
6585 if ($ex) {
6586 test_append_logfile($log_file, $ex);
6587 unlink($log_file);
6588
6589 die($ex);
6590 }
6591
6592 unlink($log_file);
6593 }
6594
6595 sub list_symlink_rel_path_chrooted_bug4322 {
6596 my $self = shift;
6597 my $tmpdir = $self->{tmpdir};
6598 my $setup = test_setup($tmpdir, 'cmds');
6599
6600 my $dst_path = 'domains/test.oxilion.nl/public_html';
6601 my $dst_dir = File::Spec->rel2abs("$tmpdir/$dst_path");
6602 mkpath($dst_dir);
6603
6604 my $cwd = getcwd();
6605 unless (chdir("$tmpdir")) {
6606 die("Can't chdir to $tmpdir: $!");
6607 }
6608
6609 unless (symlink("./$dst_path", 'public_html')) {
6610 die("Can't symlink 'public_html' to './$dst_path': $!");
6611 }
6612
6613 unless (symlink("$dst_path", 'public_html2')) {
6614 die("Can't symlink 'public_html2' to '$dst_path': $!");
6615 }
6616
6617 unless (chdir($cwd)) {
6618 die("Can't chdir to $cwd: $!");
6619 }
6620
6621 if ($< == 0) {
6622 unless (chmod(0755, $dst_dir)) {
6623 die("Can't set perms on $dst_dir to 0755: $!");
6624 }
6625
6626 unless (chown($setup->{uid}, $setup->{gid}, $dst_dir)) {
6627 die("Can't set owner of $dst_dir to $setup->{uid}/$setup->{gid}: $!");
6628 }
6629 }
6630
6631 my $config = {
6632 PidFile => $setup->{pid_file},
6633 ScoreboardFile => $setup->{scoreboard_file},
6634 SystemLog => $setup->{log_file},
6635
6636 AuthUserFile => $setup->{auth_user_file},
6637 AuthGroupFile => $setup->{auth_group_file},
6638 AuthOrder => 'mod_auth_file.c',
6639
6640 DefaultRoot => '~',
6641
6642 IfModules => {
6643 'mod_delay.c' => {
6644 DelayEngine => 'off',
6645 },
6646 },
6647 };
6648
6649 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6650 $config);
6651
6652 # Open pipes, for use between the parent and child processes. Specifically,
6653 # the child will indicate when it's done with its test by writing a message
6654 # to the parent.
6655 my ($rfh, $wfh);
6656 unless (pipe($rfh, $wfh)) {
6657 die("Can't open pipe: $!");
6658 }
6659
6660 my $ex;
6661
6662 # Fork child
6663 $self->handle_sigchld();
6664 defined(my $pid = fork()) or die("Can't fork: $!");
6665 if ($pid) {
6666 eval {
6667 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6668 $client->login($setup->{user}, $setup->{passwd});
6669
6670 my $conn = $client->list_raw();
6671 unless ($conn) {
6672 die("LIST failed: " . $client->response_code() . " " .
6673 $client->response_msg());
6674 }
6675
6676 my $buf;
6677 my $res = $conn->read($buf, 8192, 25);
6678 eval { $conn->close() };
6679
6680 my $resp_code = $client->response_code();
6681 my $resp_msg = $client->response_msg();
6682 $self->assert_transfer_ok($resp_code, $resp_msg);
6683 $client->quit();
6684
6685 if ($ENV{TEST_VERBOSE}) {
6686 print STDERR "# LIST:\n$buf\n";
6687 }
6688
6689 $res = {};
6690 my $lines = [split(/(\r)?\n/, $buf)];
6691 my $line_count = 0;
6692 foreach my $line (@$lines) {
6693 if ($line =~ /\s+(\S+)$/) {
6694 $line_count++;
6695 $res->{$1} = 1;
6696 }
6697 }
6698
6699 my $expected = 9;
6700 $self->assert($line_count == $expected,
6701 "Expected $expected lines, got $line_count");
6702
6703 # The keys are the filenames; we have two symlinks pointing to the same
6704 # file. Hence the different line vs key counts.
6705 my $list_count = scalar(keys(%$res));
6706 $expected = 8;
6707 $self->assert($list_count == $expected,
6708 "Expected $expected entries, got $list_count");
6709
6710 $self->assert($res->{'/domains/test.oxilion.nl/public_html'},
6711 "Expected '/domains/test.oxilion.nl/public_html'");
6712 };
6713 if ($@) {
6714 $ex = $@;
6715 }
6716
6717 $wfh->print("done\n");
6718 $wfh->flush();
6719
6720 } else {
6721 eval { server_wait($setup->{config_file}, $rfh) };
6722 if ($@) {
6723 warn($@);
6724 exit 1;
6725 }
6726
6727 exit 0;
6728 }
6729
6730 # Stop server
6731 server_stop($setup->{pid_file});
6732 $self->assert_child_ok($pid);
6733
6734 test_cleanup($setup->{log_file}, $ex);
6735 }
6736
6737 sub list_symlink_rel_path_subdir_chrooted_bug4322 {
6738 my $self = shift;
6739 my $tmpdir = $self->{tmpdir};
6740 my $setup = test_setup($tmpdir, 'cmds');
6741
6742 my $dst_path = 'domains/test.oxilion.nl/public_html';
6743 my $dst_dir = File::Spec->rel2abs("$tmpdir/test.d/$dst_path");
6744 mkpath($dst_dir);
6745
6746 my $cwd = getcwd();
6747 unless (chdir("$tmpdir/test.d")) {
6748 die("Can't chdir to $tmpdir: $!");
6749 }
6750
6751 unless (symlink("./$dst_path", 'public_html')) {
6752 die("Can't symlink 'public_html' to './$dst_path': $!");
6753 }
6754
6755 unless (symlink("$dst_path", 'public_html2')) {
6756 die("Can't symlink 'public_html2' to '$dst_path': $!");
6757 }
6758
6759 unless (chdir($cwd)) {
6760 die("Can't chdir to $cwd: $!");
6761 }
6762
6763 if ($< == 0) {
6764 unless (chmod(0755, $dst_dir)) {
6765 die("Can't set perms on $dst_dir to 0755: $!");
6766 }
6767
6768 unless (chown($setup->{uid}, $setup->{gid}, $dst_dir)) {
6769 die("Can't set owner of $dst_dir to $setup->{uid}/$setup->{gid}: $!");
6770 }
6771 }
6772
6773 my $config = {
6774 PidFile => $setup->{pid_file},
6775 ScoreboardFile => $setup->{scoreboard_file},
6776 SystemLog => $setup->{log_file},
6777
6778 AuthUserFile => $setup->{auth_user_file},
6779 AuthGroupFile => $setup->{auth_group_file},
6780 AuthOrder => 'mod_auth_file.c',
6781
6782 DefaultRoot => '~',
6783
6784 IfModules => {
6785 'mod_delay.c' => {
6786 DelayEngine => 'off',
6787 },
6788 },
6789 };
6790
6791 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6792 $config);
6793
6794 # Open pipes, for use between the parent and child processes. Specifically,
6795 # the child will indicate when it's done with its test by writing a message
6796 # to the parent.
6797 my ($rfh, $wfh);
6798 unless (pipe($rfh, $wfh)) {
6799 die("Can't open pipe: $!");
6800 }
6801
6802 my $ex;
6803
6804 # Fork child
6805 $self->handle_sigchld();
6806 defined(my $pid = fork()) or die("Can't fork: $!");
6807 if ($pid) {
6808 eval {
6809 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6810 $client->login($setup->{user}, $setup->{passwd});
6811
6812 my $conn = $client->list_raw('test.d');
6813 unless ($conn) {
6814 die("LIST test.d failed: " . $client->response_code() . " " .
6815 $client->response_msg());
6816 }
6817
6818 my $buf;
6819 my $res = $conn->read($buf, 8192, 25);
6820 eval { $conn->close() };
6821
6822 my $resp_code = $client->response_code();
6823 my $resp_msg = $client->response_msg();
6824 $self->assert_transfer_ok($resp_code, $resp_msg);
6825 $client->quit();
6826
6827 if ($ENV{TEST_VERBOSE}) {
6828 print STDERR "# LIST:\n$buf\n";
6829 }
6830
6831 $res = {};
6832 my $lines = [split(/(\r)?\n/, $buf)];
6833 my $line_count = 0;
6834 foreach my $line (@$lines) {
6835 if ($line =~ /\s+(\S+)$/) {
6836 $line_count++;
6837 $res->{$1} = 1;
6838 }
6839 }
6840
6841 my $expected = 3;
6842 $self->assert($line_count == $expected,
6843 "Expected $expected lines, got $line_count");
6844
6845 # The keys are the filenames; we have two symlinks pointing to the same
6846 # file. Hence the different line vs key counts.
6847 my $list_count = scalar(keys(%$res));
6848 $expected = 2;
6849 $self->assert($list_count == $expected,
6850 "Expected $expected entries, got $list_count");
6851
6852 $self->assert($res->{'/domains/test.oxilion.nl/public_html'},
6853 "Expected '/domains/test.oxilion.nl/public_html'");
6854 };
6855 if ($@) {
6856 $ex = $@;
6857 }
6858
6859 $wfh->print("done\n");
6860 $wfh->flush();
6861
6862 } else {
6863 eval { server_wait($setup->{config_file}, $rfh) };
6864 if ($@) {
6865 warn($@);
6866 exit 1;
6867 }
6868
6869 exit 0;
6870 }
6871
6872 # Stop server
6873 server_stop($setup->{pid_file});
6874 $self->assert_child_ok($pid);
6875
6876 test_cleanup($setup->{log_file}, $ex);
6877 }
6878
6879 sub list_symlink_rel_path_subdir_cwd_chrooted_bug4322 {
6880 my $self = shift;
6881 my $tmpdir = $self->{tmpdir};
6882 my $setup = test_setup($tmpdir, 'cmds');
6883
6884 my $dst_path = 'domains/test.oxilion.nl/public_html';
6885 my $dst_dir = File::Spec->rel2abs("$tmpdir/test.d/$dst_path");
6886 mkpath($dst_dir);
6887
6888 my $cwd = getcwd();
6889 unless (chdir("$tmpdir/test.d")) {
6890 die("Can't chdir to $tmpdir: $!");
6891 }
6892
6893 unless (symlink("./$dst_path", 'public_html')) {
6894 die("Can't symlink 'public_html' to './$dst_path': $!");
6895 }
6896
6897 unless (symlink("$dst_path", 'public_html2')) {
6898 die("Can't symlink 'public_html2' to '$dst_path': $!");
6899 }
6900
6901 unless (chdir($cwd)) {
6902 die("Can't chdir to $cwd: $!");
6903 }
6904
6905 if ($< == 0) {
6906 unless (chmod(0755, $dst_dir)) {
6907 die("Can't set perms on $dst_dir to 0755: $!");
6908 }
6909
6910 unless (chown($setup->{uid}, $setup->{gid}, $dst_dir)) {
6911 die("Can't set owner of $dst_dir to $setup->{uid}/$setup->{gid}: $!");
6912 }
6913 }
6914
6915 my $config = {
6916 PidFile => $setup->{pid_file},
6917 ScoreboardFile => $setup->{scoreboard_file},
6918 SystemLog => $setup->{log_file},
6919
6920 AuthUserFile => $setup->{auth_user_file},
6921 AuthGroupFile => $setup->{auth_group_file},
6922 AuthOrder => 'mod_auth_file.c',
6923
6924 DefaultRoot => '~',
6925
6926 IfModules => {
6927 'mod_delay.c' => {
6928 DelayEngine => 'off',
6929 },
6930 },
6931 };
6932
6933 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6934 $config);
6935
6936 # Open pipes, for use between the parent and child processes. Specifically,
6937 # the child will indicate when it's done with its test by writing a message
6938 # to the parent.
6939 my ($rfh, $wfh);
6940 unless (pipe($rfh, $wfh)) {
6941 die("Can't open pipe: $!");
6942 }
6943
6944 my $ex;
6945
6946 # Fork child
6947 $self->handle_sigchld();
6948 defined(my $pid = fork()) or die("Can't fork: $!");
6949 if ($pid) {
6950 eval {
6951 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6952 $client->login($setup->{user}, $setup->{passwd});
6953 $client->cwd('test.d');
6954
6955 my $conn = $client->list_raw();
6956 unless ($conn) {
6957 die("LIST failed: " . $client->response_code() . " " .
6958 $client->response_msg());
6959 }
6960
6961 my $buf;
6962 my $res = $conn->read($buf, 8192, 25);
6963 eval { $conn->close() };
6964
6965 my $resp_code = $client->response_code();
6966 my $resp_msg = $client->response_msg();
6967 $self->assert_transfer_ok($resp_code, $resp_msg);
6968 $client->quit();
6969
6970 if ($ENV{TEST_VERBOSE}) {
6971 print STDERR "# LIST:\n$buf\n";
6972 }
6973
6974 $res = {};
6975 my $lines = [split(/(\r)?\n/, $buf)];
6976 my $line_count = 0;
6977 foreach my $line (@$lines) {
6978 if ($line =~ /\s+(\S+)$/) {
6979 $line_count++;
6980 $res->{$1} = 1;
6981 }
6982 }
6983
6984 my $expected = 3;
6985 $self->assert($line_count == $expected,
6986 "Expected $expected lines, got $line_count");
6987
6988 # The keys are the filenames; we have two symlinks pointing to the same
6989 # file. Hence the different line vs key counts.
6990 my $list_count = scalar(keys(%$res));
6991 $expected = 2;
6992 $self->assert($list_count == $expected,
6993 "Expected $expected entries, got $list_count");
6994
6995 $self->assert($res->{'/domains/test.oxilion.nl/public_html'},
6996 "Expected '/domains/test.oxilion.nl/public_html'");
6997 };
6998 if ($@) {
6999 $ex = $@;
7000 }
7001
7002 $wfh->print("done\n");
7003 $wfh->flush();
7004
7005 } else {
7006 eval { server_wait($setup->{config_file}, $rfh) };
7007 if ($@) {
7008 warn($@);
7009 exit 1;
7010 }
7011
7012 exit 0;
7013 }
7014
7015 # Stop server
7016 server_stop($setup->{pid_file});
7017 $self->assert_child_ok($pid);
7018
7019 test_cleanup($setup->{log_file}, $ex);
7020 }
7021
7022 sub list_style_windows {
7023 my $self = shift;
7024 my $tmpdir = $self->{tmpdir};
7025 my $setup = test_setup($tmpdir, 'cmds');
7026
7027 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
7028 mkpath($test_dir);
7029
7030 my $config = {
7031 PidFile => $setup->{pid_file},
7032 ScoreboardFile => $setup->{scoreboard_file},
7033 SystemLog => $setup->{log_file},
7034
7035 AuthUserFile => $setup->{auth_user_file},
7036 AuthGroupFile => $setup->{auth_group_file},
7037 AuthOrder => 'mod_auth_file.c',
7038
7039 ListStyle => 'Windows',
7040
7041 IfModules => {
7042 'mod_delay.c' => {
7043 DelayEngine => 'off',
7044 },
7045 },
7046 };
7047
7048 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
7049 $config);
7050
7051 # Open pipes, for use between the parent and child processes. Specifically,
7052 # the child will indicate when it's done with its test by writing a message
7053 # to the parent.
7054 my ($rfh, $wfh);
7055 unless (pipe($rfh, $wfh)) {
7056 die("Can't open pipe: $!");
7057 }
7058
7059 my $ex;
7060
7061 # Fork child
7062 $self->handle_sigchld();
7063 defined(my $pid = fork()) or die("Can't fork: $!");
7064 if ($pid) {
7065 eval {
7066 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
7067 $client->login($setup->{user}, $setup->{passwd});
7068
7069 my $conn = $client->list_raw('-al');
7070 unless ($conn) {
7071 die("Failed to LIST: " . $client->response_code() . " " .
7072 $client->response_msg());
7073 }
7074
7075 my $buf;
7076 $conn->read($buf, 8192, 30);
7077 eval { $conn->close() };
7078
7079 if ($ENV{TEST_VERBOSE}) {
7080 print STDERR "# Response:\n$buf\n";
7081 }
7082
7083 my $resp_code = $client->response_code();
7084 my $resp_msg = $client->response_msg();
7085 $client->quit();
7086
7087 $self->assert_transfer_ok($resp_code, $resp_msg);
7088
7089 # We have to be careful of the fact that readdir returns directory
7090 # entries in an unordered fashion.
7091
7092 my $res = {};
7093 my $lines = [split(/(\r)?\n/, $buf)];
7094 foreach my $line (@$lines) {
7095 if ($line =~ /^\S+\s+\S+\s+(\S+)?\s+(\d+)?\s+(\S+)$/) {
7096 $res->{$3} = 1;
7097 }
7098 }
7099
7100 if (scalar(keys(%$res)) == 0) {
7101 die("Failed to parse Windows-style LIST data");
7102 }
7103
7104 my $expected = {
7105 'cmds.conf' => 1,
7106 'cmds.group' => 1,
7107 'cmds.passwd' => 1,
7108 'cmds.pid' => 1,
7109 'cmds.scoreboard' => 1,
7110 'cmds.scoreboard.lck' => 1,
7111 'test.d' => 1,
7112 };
7113
7114 my $ok = 1;
7115 my $mismatch;
7116 foreach my $name (keys(%$res)) {
7117 unless (defined($expected->{$name})) {
7118 $mismatch = $name;
7119 $ok = 0;
7120 last;
7121 }
7122 }
7123
7124 unless ($ok) {
7125 die("Unexpected name '$mismatch' appeared in Windows-style LIST data")
7126 }
7127 };
7128 if ($@) {
7129 $ex = $@;
7130 }
7131
7132 $wfh->print("done\n");
7133 $wfh->flush();
7134
7135 } else {
7136 eval { server_wait($setup->{config_file}, $rfh) };
7137 if ($@) {
7138 warn($@);
7139 exit 1;
7140 }
7141
7142 exit 0;
7143 }
7144
7145 # Stop server
7146 server_stop($setup->{pid_file});
7147 $self->assert_child_ok($pid);
7148
7149 test_cleanup($setup->{log_file}, $ex);
7150 }
7151
7152 1;