Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::MLSD;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Cwd;
8 use File::Path qw(mkpath);
9 use File::Spec;
10 use IO::Handle;
11
12 use ProFTPD::TestSuite::FTP;
13 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
14
15 $| = 1;
16
17 my $order = 0;
18
19 my $TESTS = {
20 mlsd_ok_raw_active => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 mlsd_ok_raw_passive => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 mlsd_fails_file => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 mlsd_ok_cwd_dir => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 mlsd_ok_other_dir_bug4198 => {
41 order => ++$order,
42 test_class => [qw(bug forking)],
43 },
44
45 mlsd_ok_chrooted_dir => {
46 order => ++$order,
47 test_class => [qw(forking rootprivs)],
48 },
49
50 mlsd_ok_empty_dir => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 mlsd_ok_no_path => {
56 order => ++$order,
57 test_class => [qw(forking)],
58 },
59
60 mlsd_ok_glob => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 mlsd_fails_login_required => {
66 order => ++$order,
67 test_class => [qw(forking)],
68 },
69
70 mlsd_fails_enoent => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 mlsd_fails_eperm => {
76 order => ++$order,
77 test_class => [qw(forking)],
78 },
79
80 mlsd_ok_hidden_file => {
81 order => ++$order,
82 test_class => [qw(bug forking)],
83 },
84
85 mlsd_ok_path_with_spaces => {
86 order => ++$order,
87 test_class => [qw(bug forking)],
88 },
89
90 mlsd_nonascii_chars_bug3032 => {
91 order => ++$order,
92 test_class => [qw(bug forking)],
93 },
94
95 mlsd_symlink_showsymlinks_off_bug3318 => {
96 order => ++$order,
97 test_class => [qw(bug forking)],
98 },
99
100 mlsd_symlink_showsymlinks_on_bug3318 => {
101 order => ++$order,
102 test_class => [qw(bug forking)],
103 },
104
105 mlsd_symlink_showsymlinks_on_chrooted_bug4219 => {
106 order => ++$order,
107 test_class => [qw(bug forking rootprivs)],
108 },
109
110 mlsd_symlink_showsymlinks_on_use_slink_chrooted_bug4219 => {
111 order => ++$order,
112 test_class => [qw(bug forking rootprivs)],
113 },
114
115 mlsd_symlinked_dir_bug3859 => {
116 order => ++$order,
117 test_class => [qw(bug forking)],
118 },
119
120 mlsd_symlinked_dir_showsymlinks_off_bug3859 => {
121 order => ++$order,
122 test_class => [qw(bug forking)],
123 },
124
125 mlsd_wide_dir => {
126 order => ++$order,
127 test_class => [qw(bug forking)],
128 },
129
130 mlsd_symlink_rel_path_chrooted_bug4322 => {
131 order => ++$order,
132 test_class => [qw(bug forking rootprivs)],
133 },
134
135 mlsd_symlink_rel_path_subdir_chrooted_bug4322 => {
136 order => ++$order,
137 test_class => [qw(bug forking rootprivs)],
138 },
139
140 mlsd_symlink_rel_path_subdir_cwd_chrooted_bug4322 => {
141 order => ++$order,
142 test_class => [qw(bug forking rootprivs)],
143 },
144
145 # XXX Plenty of other tests needed: params, maxfiles, maxdirs, depth, etc
146 };
147
148 sub new {
149 return shift()->SUPER::new(@_);
150 }
151
152 sub list_tests {
153 return testsuite_get_runnable_tests($TESTS);
154 }
155
156 sub mlsd_ok_raw_active {
157 my $self = shift;
158 my $tmpdir = $self->{tmpdir};
159 my $setup = test_setup($tmpdir, 'cmds');
160
161 my $config = {
162 PidFile => $setup->{pid_file},
163 ScoreboardFile => $setup->{scoreboard_file},
164 SystemLog => $setup->{log_file},
165
166 AuthUserFile => $setup->{auth_user_file},
167 AuthGroupFile => $setup->{auth_group_file},
168 AuthOrder => 'mod_auth_file.c',
169
170 IfModules => {
171 'mod_delay.c' => {
172 DelayEngine => 'off',
173 },
174 },
175 };
176
177 my ($port, $config_user, $config_group) = config_write($setup->{config_file}, $config);
178
179 # Open pipes, for use between the parent and child processes. Specifically,
180 # the child will indicate when it's done with its test by writing a message
181 # to the parent.
182 my ($rfh, $wfh);
183 unless (pipe($rfh, $wfh)) {
184 die("Can't open pipe: $!");
185 }
186
187 my $ex;
188
189 # Fork child
190 $self->handle_sigchld();
191 defined(my $pid = fork()) or die("Can't fork: $!");
192 if ($pid) {
193 eval {
194 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0);
195 $client->login($setup->{user}, $setup->{passwd});
196 $client->type('binary');
197
198 my $conn = $client->mlsd_raw();
199 unless ($conn) {
200 die("Failed to MLSD: " . $client->response_code() . " " .
201 $client->response_msg());
202 }
203
204 my $buf;
205 $conn->read($buf, 8192, 30);
206 eval { $conn->close() };
207
208 if ($ENV{TEST_VERBOSE}) {
209 print STDERR "# Response:\n$buf\n";
210 }
211
212 # We have to be careful of the fact that readdir returns directory
213 # entries in an unordered fashion.
214 my $res = {};
215 my $lines = [split(/\r\n/, $buf)];
216 $self->assert(scalar(@$lines) > 1,
217 test_msg("Expected several MLSD lines, got " . scalar(@$lines)));
218
219 foreach my $line (@$lines) {
220 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
221 $res->{$1} = 1;
222 }
223 }
224
225 my $expected = {
226 '.' => 1,
227 '..' => 1,
228 'cmds.conf' => 1,
229 'cmds.group' => 1,
230 'cmds.passwd' => 1,
231 'cmds.pid' => 1,
232 'cmds.scoreboard' => 1,
233 'cmds.scoreboard.lck' => 1,
234 };
235
236 my $ok = 1;
237 my $mismatch;
238 foreach my $name (keys(%$res)) {
239 unless (defined($expected->{$name})) {
240 $mismatch = $name;
241 $ok = 0;
242 last;
243 }
244 }
245
246 unless ($ok) {
247 die("Unexpected name '$mismatch' appeared in MLSD data")
248 }
249 };
250
251 if ($@) {
252 $ex = $@;
253 }
254
255 $wfh->print("done\n");
256 $wfh->flush();
257
258 } else {
259 eval { server_wait($setup->{config_file}, $rfh) };
260 if ($@) {
261 warn($@);
262 exit 1;
263 }
264
265 exit 0;
266 }
267
268 # Stop server
269 server_stop($setup->{pid_file});
270 $self->assert_child_ok($pid);
271
272 test_cleanup($setup->{log_file}, $ex);
273 }
274
275 sub mlsd_ok_raw_passive {
276 my $self = shift;
277 my $tmpdir = $self->{tmpdir};
278
279 my $config_file = "$tmpdir/cmds.conf";
280 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
281 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
282
283 my $log_file = test_get_logfile();
284
285 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
286 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
287
288 my $user = 'proftpd';
289 my $passwd = 'test';
290 my $home_dir = File::Spec->rel2abs($tmpdir);
291 my $uid = 500;
292 my $gid = 500;
293
294 # Make sure that, if we're running as root, that the home directory has
295 # permissions/privs set for the account we create
296 if ($< == 0) {
297 unless (chmod(0755, $home_dir)) {
298 die("Can't set perms on $home_dir to 0755: $!");
299 }
300
301 unless (chown($uid, $gid, $home_dir)) {
302 die("Can't set owner of $home_dir to $uid/$gid: $!");
303 }
304 }
305
306 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
307 '/bin/bash');
308 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
309
310 my $config = {
311 PidFile => $pid_file,
312 ScoreboardFile => $scoreboard_file,
313 SystemLog => $log_file,
314
315 AuthUserFile => $auth_user_file,
316 AuthGroupFile => $auth_group_file,
317 AuthOrder => 'mod_auth_file.c',
318
319 IfModules => {
320 'mod_delay.c' => {
321 DelayEngine => 'off',
322 },
323 },
324 };
325
326 my ($port, $config_user, $config_group) = config_write($config_file, $config);
327
328 # Open pipes, for use between the parent and child processes. Specifically,
329 # the child will indicate when it's done with its test by writing a message
330 # to the parent.
331 my ($rfh, $wfh);
332 unless (pipe($rfh, $wfh)) {
333 die("Can't open pipe: $!");
334 }
335
336 my $ex;
337
338 # Fork child
339 $self->handle_sigchld();
340 defined(my $pid = fork()) or die("Can't fork: $!");
341 if ($pid) {
342 eval {
343 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
344 $client->login($user, $passwd);
345
346 my $conn = $client->mlsd_raw();
347 unless ($conn) {
348 die("Failed to MLSD: " . $client->response_code() . " " .
349 $client->response_msg());
350 }
351
352 my $buf;
353 $conn->read($buf, 8192, 30);
354 eval { $conn->close() };
355
356 # We have to be careful of the fact that readdir returns directory
357 # entries in an unordered fashion.
358 my $res = {};
359 my $lines = [split(/\r\n/, $buf)];
360 foreach my $line (@$lines) {
361 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
362 $res->{$1} = 1;
363 }
364 }
365
366 my $expected = {
367 '.' => 1,
368 '..' => 1,
369 'cmds.conf' => 1,
370 'cmds.group' => 1,
371 'cmds.passwd' => 1,
372 'cmds.pid' => 1,
373 'cmds.scoreboard' => 1,
374 'cmds.scoreboard.lck' => 1,
375 };
376
377 my $ok = 1;
378 my $mismatch;
379 foreach my $name (keys(%$res)) {
380 unless (defined($expected->{$name})) {
381 $mismatch = $name;
382 $ok = 0;
383 last;
384 }
385 }
386
387 unless ($ok) {
388 die("Unexpected name '$mismatch' appeared in MLSD data")
389 }
390 };
391
392 if ($@) {
393 $ex = $@;
394 }
395
396 $wfh->print("done\n");
397 $wfh->flush();
398
399 } else {
400 eval { server_wait($config_file, $rfh) };
401 if ($@) {
402 warn($@);
403 exit 1;
404 }
405
406 exit 0;
407 }
408
409 # Stop server
410 server_stop($pid_file);
411
412 $self->assert_child_ok($pid);
413
414 if ($ex) {
415 test_append_logfile($log_file);
416 unlink($log_file);
417
418 die($ex);
419 }
420
421 unlink($log_file);
422 }
423
424 sub mlsd_fails_file {
425 my $self = shift;
426 my $tmpdir = $self->{tmpdir};
427
428 my $config_file = "$tmpdir/cmds.conf";
429 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
430 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
431
432 my $log_file = test_get_logfile();
433
434 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
435 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
436
437 my $user = 'proftpd';
438 my $passwd = 'test';
439 my $home_dir = File::Spec->rel2abs($tmpdir);
440 my $uid = 500;
441 my $gid = 500;
442
443 # Make sure that, if we're running as root, that the home directory has
444 # permissions/privs set for the account we create
445 if ($< == 0) {
446 unless (chmod(0755, $home_dir)) {
447 die("Can't set perms on $home_dir to 0755: $!");
448 }
449
450 unless (chown($uid, $gid, $home_dir)) {
451 die("Can't set owner of $home_dir to $uid/$gid: $!");
452 }
453 }
454
455 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
456 '/bin/bash');
457 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
458
459 my $test_file = File::Spec->rel2abs($config_file);
460
461 my $config = {
462 PidFile => $pid_file,
463 ScoreboardFile => $scoreboard_file,
464 SystemLog => $log_file,
465
466 AuthUserFile => $auth_user_file,
467 AuthGroupFile => $auth_group_file,
468 AuthOrder => 'mod_auth_file.c',
469
470 IfModules => {
471 'mod_delay.c' => {
472 DelayEngine => 'off',
473 },
474 },
475 };
476
477 my ($port, $config_user, $config_group) = config_write($config_file, $config);
478
479 # Open pipes, for use between the parent and child processes. Specifically,
480 # the child will indicate when it's done with its test by writing a message
481 # to the parent.
482 my ($rfh, $wfh);
483 unless (pipe($rfh, $wfh)) {
484 die("Can't open pipe: $!");
485 }
486
487 my $ex;
488
489 # Fork child
490 $self->handle_sigchld();
491 defined(my $pid = fork()) or die("Can't fork: $!");
492 if ($pid) {
493 eval {
494 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
495 $client->login($user, $passwd);
496
497 my $conn = $client->mlsd_raw($test_file);
498 if ($conn) {
499 die("MLSD succeeded unexpectedly");
500 }
501
502 my $resp_code = $client->response_code();
503 my $resp_msg = $client->response_msg();
504
505 my $expected;
506
507 $expected = 550;
508 $self->assert($expected == $resp_code,
509 test_msg("Expected response code $expected, got $resp_code"));
510
511 $expected = "'$test_file' is not a directory";
512 $self->assert($expected eq $resp_msg,
513 test_msg("Expected response message '$expected', got '$resp_msg'"));
514 };
515
516 if ($@) {
517 $ex = $@;
518 }
519
520 $wfh->print("done\n");
521 $wfh->flush();
522
523 } else {
524 eval { server_wait($config_file, $rfh) };
525 if ($@) {
526 warn($@);
527 exit 1;
528 }
529
530 exit 0;
531 }
532
533 # Stop server
534 server_stop($pid_file);
535
536 $self->assert_child_ok($pid);
537
538 if ($ex) {
539 test_append_logfile($log_file);
540 unlink($log_file);
541
542 die($ex);
543 }
544
545 unlink($log_file);
546 }
547
548 sub mlsd_ok_cwd_dir {
549 my $self = shift;
550 my $tmpdir = $self->{tmpdir};
551
552 my $config_file = "$tmpdir/cmds.conf";
553 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
554 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
555
556 my $log_file = test_get_logfile();
557
558 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
559 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
560
561 my $user = 'proftpd';
562 my $passwd = 'test';
563 my $home_dir = File::Spec->rel2abs($tmpdir);
564 my $uid = 500;
565 my $gid = 500;
566
567 # Make sure that, if we're running as root, that the home directory has
568 # permissions/privs set for the account we create
569 if ($< == 0) {
570 unless (chmod(0755, $home_dir)) {
571 die("Can't set perms on $home_dir to 0755: $!");
572 }
573
574 unless (chown($uid, $gid, $home_dir)) {
575 die("Can't set owner of $home_dir to $uid/$gid: $!");
576 }
577 }
578
579 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
580 '/bin/bash');
581 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
582
583 my $config = {
584 PidFile => $pid_file,
585 ScoreboardFile => $scoreboard_file,
586 SystemLog => $log_file,
587
588 AuthUserFile => $auth_user_file,
589 AuthGroupFile => $auth_group_file,
590 AuthOrder => 'mod_auth_file.c',
591
592 IfModules => {
593 'mod_delay.c' => {
594 DelayEngine => 'off',
595 },
596 },
597 };
598
599 my ($port, $config_user, $config_group) = config_write($config_file, $config);
600
601 # Open pipes, for use between the parent and child processes. Specifically,
602 # the child will indicate when it's done with its test by writing a message
603 # to the parent.
604 my ($rfh, $wfh);
605 unless (pipe($rfh, $wfh)) {
606 die("Can't open pipe: $!");
607 }
608
609 my $ex;
610
611 # Fork child
612 $self->handle_sigchld();
613 defined(my $pid = fork()) or die("Can't fork: $!");
614 if ($pid) {
615 eval {
616 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
617 $client->login($user, $passwd);
618 $client->type('binary');
619
620 my $conn = $client->mlsd_raw($home_dir);
621 unless ($conn) {
622 die("MLSD failed: " . $client->response_code() . " " .
623 $client->response_msg());
624 }
625
626 my $buf;
627 $conn->read($buf, 8192, 30);
628 eval { $conn->close() };
629
630 my $res = {};
631 my $lines = [split(/\r\n/, $buf)];
632 foreach my $line (@$lines) {
633 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
634 $res->{$2} = $1;
635 }
636 }
637
638 my $count = scalar(keys(%$res));
639 my $expected = 8;
640 unless ($count == $expected) {
641 die("MLSD returned wrong number of entries (expected $expected, got $count)");
642 }
643
644 # Make sure that the 'type' fact for the current directory is
645 # "cdir" (Bug#4198).
646 my $type = $res->{'.'};
647 $expected = 'cdir';
648 $self->assert($expected eq $type,
649 test_msg("Expected type '$expected', got '$type'"));
650 };
651
652 if ($@) {
653 $ex = $@;
654 }
655
656 $wfh->print("done\n");
657 $wfh->flush();
658
659 } else {
660 eval { server_wait($config_file, $rfh) };
661 if ($@) {
662 warn($@);
663 exit 1;
664 }
665
666 exit 0;
667 }
668
669 # Stop server
670 server_stop($pid_file);
671
672 $self->assert_child_ok($pid);
673
674 if ($ex) {
675 test_append_logfile($log_file);
676 unlink($log_file);
677
678 die($ex);
679 }
680
681 unlink($log_file);
682 }
683
684 sub mlsd_ok_other_dir_bug4198 {
685 my $self = shift;
686 my $tmpdir = $self->{tmpdir};
687
688 my $config_file = "$tmpdir/cmds.conf";
689 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
690 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
691
692 my $log_file = test_get_logfile();
693
694 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
695 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
696
697 my $user = 'proftpd';
698 my $passwd = 'test';
699 my $home_dir = File::Spec->rel2abs($tmpdir);
700 my $uid = 500;
701 my $gid = 500;
702
703 # Make sure that, if we're running as root, that the home directory has
704 # permissions/privs set for the account we create
705 if ($< == 0) {
706 unless (chmod(0755, $home_dir)) {
707 die("Can't set perms on $home_dir to 0755: $!");
708 }
709
710 unless (chown($uid, $gid, $home_dir)) {
711 die("Can't set owner of $home_dir to $uid/$gid: $!");
712 }
713 }
714
715 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
716 '/bin/bash');
717 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
718
719 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
720 my $sub_dir = File::Spec->rel2abs("$test_dir/sub.d");
721 mkpath($sub_dir);
722
723 my $config = {
724 PidFile => $pid_file,
725 ScoreboardFile => $scoreboard_file,
726 SystemLog => $log_file,
727
728 AuthUserFile => $auth_user_file,
729 AuthGroupFile => $auth_group_file,
730 AuthOrder => 'mod_auth_file.c',
731
732 IfModules => {
733 'mod_delay.c' => {
734 DelayEngine => 'off',
735 },
736 },
737 };
738
739 my ($port, $config_user, $config_group) = config_write($config_file, $config);
740
741 # Open pipes, for use between the parent and child processes. Specifically,
742 # the child will indicate when it's done with its test by writing a message
743 # to the parent.
744 my ($rfh, $wfh);
745 unless (pipe($rfh, $wfh)) {
746 die("Can't open pipe: $!");
747 }
748
749 my $ex;
750
751 # Fork child
752 $self->handle_sigchld();
753 defined(my $pid = fork()) or die("Can't fork: $!");
754 if ($pid) {
755 eval {
756 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
757 $client->login($user, $passwd);
758 $client->type('binary');
759
760 # First, change to some other directory
761 $client->cwd($sub_dir);
762
763 my $conn = $client->mlsd_raw($test_dir);
764 unless ($conn) {
765 die("MLSD failed: " . $client->response_code() . " " .
766 $client->response_msg());
767 }
768
769 my $buf;
770 $conn->read($buf, 8192, 30);
771 eval { $conn->close() };
772
773 my $res = {};
774 my $lines = [split(/\r\n/, $buf)];
775 foreach my $line (@$lines) {
776 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
777 $res->{$2} = $1;
778 }
779 }
780
781 my $count = scalar(keys(%$res));
782 my $expected = 3;
783 unless ($count == $expected) {
784 die("MLSD returned wrong number of entries (expected $expected, got $count)");
785 }
786
787 # Make sure that the 'type' fact for the current directory is
788 # "cdir" (Bug#4198).
789 my $type = $res->{'.'};
790 $expected = 'cdir';
791 $self->assert($expected eq $type,
792 test_msg("Expected type '$expected', got '$type'"));
793
794 # Similarly, make sure that the 'type' fact for parent directory
795 # (by name) is NOT "cdir", but is just "dir" (Bug#4198).
796 $type = $res->{'sub.d'};
797 $expected = 'dir';
798 $self->assert($expected eq $type,
799 test_msg("Expected type '$expected', got '$type'"));
800 };
801
802 if ($@) {
803 $ex = $@;
804 }
805
806 $wfh->print("done\n");
807 $wfh->flush();
808
809 } else {
810 eval { server_wait($config_file, $rfh) };
811 if ($@) {
812 warn($@);
813 exit 1;
814 }
815
816 exit 0;
817 }
818
819 # Stop server
820 server_stop($pid_file);
821
822 $self->assert_child_ok($pid);
823
824 if ($ex) {
825 test_append_logfile($log_file);
826 unlink($log_file);
827
828 die($ex);
829 }
830
831 unlink($log_file);
832 }
833
834 sub mlsd_ok_chrooted_dir {
835 my $self = shift;
836 my $tmpdir = $self->{tmpdir};
837 my $setup = test_setup($tmpdir, 'cmds');
838
839 my $config = {
840 PidFile => $setup->{pid_file},
841 ScoreboardFile => $setup->{scoreboard_file},
842 SystemLog => $setup->{log_file},
843
844 AuthUserFile => $setup->{auth_user_file},
845 AuthGroupFile => $setup->{auth_group_file},
846 AuthOrder => 'mod_auth_file.c',
847
848 DefaultRoot => '~',
849
850 IfModules => {
851 'mod_delay.c' => {
852 DelayEngine => 'off',
853 },
854 },
855 };
856
857 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
858 $config);
859
860 # Open pipes, for use between the parent and child processes. Specifically,
861 # the child will indicate when it's done with its test by writing a message
862 # to the parent.
863 my ($rfh, $wfh);
864 unless (pipe($rfh, $wfh)) {
865 die("Can't open pipe: $!");
866 }
867
868 my $ex;
869
870 # Fork child
871 $self->handle_sigchld();
872 defined(my $pid = fork()) or die("Can't fork: $!");
873 if ($pid) {
874 eval {
875 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
876 $client->login($setup->{user}, $setup->{passwd});
877 $client->type('binary');
878
879 my $conn = $client->mlsd_raw('/');
880 unless ($conn) {
881 die("MLSD failed: " . $client->response_code() . " " .
882 $client->response_msg());
883 }
884
885 my $buf;
886 $conn->read($buf, 8192, 30);
887 eval { $conn->close() };
888
889 if ($ENV{TEST_VERBOSE}) {
890 print STDERR "# Response:\n$buf\n";
891 }
892
893 my $res = {};
894 my $lines = [split(/\r\n/, $buf)];
895 foreach my $line (@$lines) {
896 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
897 $res->{$1} = 1;
898 }
899 }
900
901 my $count = scalar(keys(%$res));
902 unless ($count == 8) {
903 die("MLSD returned wrong number of entries (expected 7, got $count)");
904 }
905 };
906 if ($@) {
907 $ex = $@;
908 }
909
910 $wfh->print("done\n");
911 $wfh->flush();
912
913 } else {
914 eval { server_wait($setup->{config_file}, $rfh) };
915 if ($@) {
916 warn($@);
917 exit 1;
918 }
919
920 exit 0;
921 }
922
923 # Stop server
924 server_stop($setup->{pid_file});
925 $self->assert_child_ok($pid);
926
927 test_cleanup($setup->{log_file}, $ex);
928 }
929
930 sub mlsd_ok_empty_dir {
931 my $self = shift;
932 my $tmpdir = $self->{tmpdir};
933
934 my $config_file = "$tmpdir/cmds.conf";
935 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
936 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
937
938 my $log_file = test_get_logfile();
939
940 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
941 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
942
943 my $user = 'proftpd';
944 my $passwd = 'test';
945 my $home_dir = File::Spec->rel2abs($tmpdir);
946 my $uid = 500;
947 my $gid = 500;
948
949 my $test_dir = File::Spec->rel2abs("$tmpdir/testdir");
950 mkpath($test_dir);
951
952 # Make sure that, if we're running as root, that the home directory has
953 # permissions/privs set for the account we create
954 if ($< == 0) {
955 unless (chmod(0755, $home_dir, $test_dir)) {
956 die("Can't set perms on $home_dir, $test_dir to 0755: $!");
957 }
958
959 unless (chown($uid, $gid, $home_dir, $test_dir)) {
960 die("Can't set owner of $home_dir, $test_dir to $uid/$gid: $!");
961 }
962 }
963
964 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
965 '/bin/bash');
966 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
967
968 my $config = {
969 PidFile => $pid_file,
970 ScoreboardFile => $scoreboard_file,
971 SystemLog => $log_file,
972
973 AuthUserFile => $auth_user_file,
974 AuthGroupFile => $auth_group_file,
975 AuthOrder => 'mod_auth_file.c',
976
977 IfModules => {
978 'mod_delay.c' => {
979 DelayEngine => 'off',
980 },
981 },
982 };
983
984 my ($port, $config_user, $config_group) = config_write($config_file, $config);
985
986 # Open pipes, for use between the parent and child processes. Specifically,
987 # the child will indicate when it's done with its test by writing a message
988 # to the parent.
989 my ($rfh, $wfh);
990 unless (pipe($rfh, $wfh)) {
991 die("Can't open pipe: $!");
992 }
993
994 my $ex;
995
996 # Fork child
997 $self->handle_sigchld();
998 defined(my $pid = fork()) or die("Can't fork: $!");
999 if ($pid) {
1000 eval {
1001 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1002 $client->login($user, $passwd);
1003 $client->type('binary');
1004
1005 my $conn = $client->mlsd_raw($test_dir);
1006 unless ($conn) {
1007 die("MLSD failed: " . $client->response_code() . " " .
1008 $client->response_msg());
1009 }
1010
1011 my $buf;
1012 $conn->read($buf, 8192, 30);
1013 eval { $conn->close() };
1014
1015 my $res = {};
1016 my $lines = [split(/\r\n/, $buf)];
1017 foreach my $line (@$lines) {
1018 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
1019 $res->{$2} = $1;
1020 }
1021 }
1022
1023 my $count = scalar(keys(%$res));
1024 unless ($count == 2) {
1025 die("MLSD returned wrong number of entries (expected 2, got $count)");
1026 }
1027
1028 # Make sure that the type reported by mod_facts for the '..' directory
1029 # is 'pdir', where the type for '.' is 'cdir'.
1030
1031 my $type = $res->{'.'};
1032 my $expected = 'cdir';
1033 $self->assert($expected eq $type,
1034 test_msg("Expected type '$expected', got '$type'"));
1035
1036 $type = $res->{'..'};
1037 $expected = 'pdir';
1038 $self->assert($expected eq $type,
1039 test_msg("Expected type '$expected', got '$type'"));
1040 };
1041
1042 if ($@) {
1043 $ex = $@;
1044 }
1045
1046 $wfh->print("done\n");
1047 $wfh->flush();
1048
1049 } else {
1050 eval { server_wait($config_file, $rfh) };
1051 if ($@) {
1052 warn($@);
1053 exit 1;
1054 }
1055
1056 exit 0;
1057 }
1058
1059 # Stop server
1060 server_stop($pid_file);
1061
1062 $self->assert_child_ok($pid);
1063
1064 if ($ex) {
1065 test_append_logfile($log_file);
1066 unlink($log_file);
1067
1068 die($ex);
1069 }
1070
1071 unlink($log_file);
1072 }
1073
1074 sub mlsd_ok_no_path {
1075 my $self = shift;
1076 my $tmpdir = $self->{tmpdir};
1077
1078 my $config_file = "$tmpdir/cmds.conf";
1079 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1080 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1081
1082 my $log_file = test_get_logfile();
1083
1084 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1085 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1086
1087 my $user = 'proftpd';
1088 my $passwd = 'test';
1089 my $home_dir = File::Spec->rel2abs($tmpdir);
1090 my $uid = 500;
1091 my $gid = 500;
1092
1093 # Make sure that, if we're running as root, that the home directory has
1094 # permissions/privs set for the account we create
1095 if ($< == 0) {
1096 unless (chmod(0755, $home_dir)) {
1097 die("Can't set perms on $home_dir to 0755: $!");
1098 }
1099
1100 unless (chown($uid, $gid, $home_dir)) {
1101 die("Can't set owner of $home_dir to $uid/$gid: $!");
1102 }
1103 }
1104
1105 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1106 '/bin/bash');
1107 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1108
1109 my $config = {
1110 PidFile => $pid_file,
1111 ScoreboardFile => $scoreboard_file,
1112 SystemLog => $log_file,
1113
1114 AuthUserFile => $auth_user_file,
1115 AuthGroupFile => $auth_group_file,
1116 AuthOrder => 'mod_auth_file.c',
1117
1118 IfModules => {
1119 'mod_delay.c' => {
1120 DelayEngine => 'off',
1121 },
1122 },
1123 };
1124
1125 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1126
1127 # Open pipes, for use between the parent and child processes. Specifically,
1128 # the child will indicate when it's done with its test by writing a message
1129 # to the parent.
1130 my ($rfh, $wfh);
1131 unless (pipe($rfh, $wfh)) {
1132 die("Can't open pipe: $!");
1133 }
1134
1135 my $ex;
1136
1137 # Fork child
1138 $self->handle_sigchld();
1139 defined(my $pid = fork()) or die("Can't fork: $!");
1140 if ($pid) {
1141 eval {
1142 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1143 $client->login($user, $passwd);
1144 $client->type('binary');
1145
1146 my $conn = $client->mlsd_raw();
1147 unless ($conn) {
1148 die("MLSD failed: " . $client->response_code() . " " .
1149 $client->response_msg());
1150 }
1151
1152 my $buf;
1153 $conn->read($buf, 8192, 30);
1154 eval { $conn->close() };
1155
1156 my $res = {};
1157 my $lines = [split(/\r\n/, $buf)];
1158 foreach my $line (@$lines) {
1159 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
1160 $res->{$1} = 1;
1161 }
1162 }
1163
1164 my $count = scalar(keys(%$res));
1165 my $expected = 8;
1166 unless ($count == $expected) {
1167 die("MLSD returned wrong number of entries (expected $expected, got $count)");
1168 }
1169 };
1170
1171 if ($@) {
1172 $ex = $@;
1173 }
1174
1175 print $wfh "done\n";
1176
1177 } else {
1178 eval { server_wait($config_file, $rfh) };
1179 if ($@) {
1180 warn($@);
1181 exit 1;
1182 }
1183
1184 exit 0;
1185 }
1186
1187 # Stop server
1188 server_stop($pid_file);
1189
1190 $self->assert_child_ok($pid);
1191
1192 if ($ex) {
1193 test_append_logfile($log_file);
1194 unlink($log_file);
1195
1196 die($ex);
1197 }
1198
1199 unlink($log_file);
1200 }
1201
1202 sub mlsd_ok_glob {
1203 my $self = shift;
1204 my $tmpdir = $self->{tmpdir};
1205
1206 my $config_file = "$tmpdir/cmds.conf";
1207 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1208 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1209
1210 my $log_file = test_get_logfile();
1211
1212 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1213 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1214
1215 my $user = 'proftpd';
1216 my $passwd = 'test';
1217 my $home_dir = File::Spec->rel2abs($tmpdir);
1218 my $uid = 500;
1219 my $gid = 500;
1220
1221 my $test_dir = File::Spec->rel2abs("$tmpdir/?foo*");
1222 mkpath($test_dir);
1223
1224 # Make sure that, if we're running as root, that the home directory has
1225 # permissions/privs set for the account we create
1226 if ($< == 0) {
1227 unless (chmod(0755, $home_dir)) {
1228 die("Can't set perms on $home_dir to 0755: $!");
1229 }
1230
1231 unless (chown($uid, $gid, $home_dir)) {
1232 die("Can't set owner of $home_dir to $uid/$gid: $!");
1233 }
1234 }
1235
1236 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1237 '/bin/bash');
1238 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1239
1240 my $config = {
1241 PidFile => $pid_file,
1242 ScoreboardFile => $scoreboard_file,
1243 SystemLog => $log_file,
1244
1245 AuthUserFile => $auth_user_file,
1246 AuthGroupFile => $auth_group_file,
1247 AuthOrder => 'mod_auth_file.c',
1248
1249 IfModules => {
1250 'mod_delay.c' => {
1251 DelayEngine => 'off',
1252 },
1253 },
1254 };
1255
1256 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1257
1258 # Open pipes, for use between the parent and child processes. Specifically,
1259 # the child will indicate when it's done with its test by writing a message
1260 # to the parent.
1261 my ($rfh, $wfh);
1262 unless (pipe($rfh, $wfh)) {
1263 die("Can't open pipe: $!");
1264 }
1265
1266 my $ex;
1267
1268 # Fork child
1269 $self->handle_sigchld();
1270 defined(my $pid = fork()) or die("Can't fork: $!");
1271 if ($pid) {
1272 eval {
1273 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1274 $client->login($user, $passwd);
1275 $client->type('binary');
1276
1277 my $conn = $client->mlsd('?foo*');
1278 unless ($conn) {
1279 die("MLSD failed unexpectedly: " . $client->response_code() . " " .
1280 $client->response_msg());
1281 }
1282
1283 my $resp_code = $client->response_code();
1284 my $resp_msg = $client->response_msg();
1285
1286 my $expected;
1287
1288 $expected = 226;
1289 $self->assert($expected == $resp_code,
1290 test_msg("Expected response code $expected, got $resp_code"));
1291
1292 $expected = "Transfer complete";
1293 $self->assert($expected eq $resp_msg,
1294 test_msg("Expected response message '$expected', got '$resp_msg'"));
1295 };
1296
1297 if ($@) {
1298 $ex = $@;
1299 }
1300
1301 $wfh->print("done\n");
1302 $wfh->flush();
1303
1304 } else {
1305 eval { server_wait($config_file, $rfh) };
1306 if ($@) {
1307 warn($@);
1308 exit 1;
1309 }
1310
1311 exit 0;
1312 }
1313
1314 # Stop server
1315 server_stop($pid_file);
1316
1317 $self->assert_child_ok($pid);
1318
1319 if ($ex) {
1320 test_append_logfile($log_file);
1321 unlink($log_file);
1322
1323 die($ex);
1324 }
1325
1326 unlink($log_file);
1327 }
1328
1329 sub mlsd_fails_login_required {
1330 my $self = shift;
1331 my $tmpdir = $self->{tmpdir};
1332
1333 my $config_file = "$tmpdir/cmds.conf";
1334 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1335 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1336
1337 my $log_file = test_get_logfile();
1338
1339 my $config = {
1340 PidFile => $pid_file,
1341 ScoreboardFile => $scoreboard_file,
1342 SystemLog => $log_file,
1343
1344 IfModules => {
1345 'mod_delay.c' => {
1346 DelayEngine => 'off',
1347 },
1348 },
1349 };
1350
1351 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1352
1353 # Open pipes, for use between the parent and child processes. Specifically,
1354 # the child will indicate when it's done with its test by writing a message
1355 # to the parent.
1356 my ($rfh, $wfh);
1357 unless (pipe($rfh, $wfh)) {
1358 die("Can't open pipe: $!");
1359 }
1360
1361 my $ex;
1362
1363 # Fork child
1364 $self->handle_sigchld();
1365 defined(my $pid = fork()) or die("Can't fork: $!");
1366 if ($pid) {
1367 eval {
1368 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1369
1370 eval { $client->mlsd() };
1371 unless ($@) {
1372 die("MLSD succeeded unexpectedly");
1373 }
1374
1375 my $resp_code = $client->response_code();
1376 my $resp_msg = $client->response_msg();
1377
1378 my $expected;
1379
1380 $expected = 530;
1381 $self->assert($expected == $resp_code,
1382 test_msg("Expected response code $expected, got $resp_code"));
1383
1384 $expected = "Please login with USER and PASS";
1385 $self->assert($expected eq $resp_msg,
1386 test_msg("Expected response message '$expected', got '$resp_msg'"));
1387 };
1388
1389 if ($@) {
1390 $ex = $@;
1391 }
1392
1393 $wfh->print("done\n");
1394 $wfh->flush();
1395
1396 } else {
1397 eval { server_wait($config_file, $rfh) };
1398 if ($@) {
1399 warn($@);
1400 exit 1;
1401 }
1402
1403 exit 0;
1404 }
1405
1406 # Stop server
1407 server_stop($pid_file);
1408
1409 $self->assert_child_ok($pid);
1410
1411 if ($ex) {
1412 test_append_logfile($log_file);
1413 unlink($log_file);
1414
1415 die($ex);
1416 }
1417
1418 unlink($log_file);
1419 }
1420
1421 sub mlsd_fails_enoent {
1422 my $self = shift;
1423 my $tmpdir = $self->{tmpdir};
1424
1425 my $config_file = "$tmpdir/cmds.conf";
1426 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1427 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1428
1429 my $log_file = test_get_logfile();
1430
1431 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1432 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1433
1434 my $user = 'proftpd';
1435 my $passwd = 'test';
1436 my $home_dir = File::Spec->rel2abs($tmpdir);
1437 my $uid = 500;
1438 my $gid = 500;
1439
1440 # Make sure that, if we're running as root, that the home directory has
1441 # permissions/privs set for the account we create
1442 if ($< == 0) {
1443 unless (chmod(0755, $home_dir)) {
1444 die("Can't set perms on $home_dir to 0755: $!");
1445 }
1446
1447 unless (chown($uid, $gid, $home_dir)) {
1448 die("Can't set owner of $home_dir to $uid/$gid: $!");
1449 }
1450 }
1451
1452 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1453 '/bin/bash');
1454 auth_group_write($auth_group_file, 'ftpd', $uid, $user);
1455
1456 my $config = {
1457 PidFile => $pid_file,
1458 ScoreboardFile => $scoreboard_file,
1459 SystemLog => $log_file,
1460
1461 AuthUserFile => $auth_user_file,
1462 AuthGroupFile => $auth_group_file,
1463 AuthOrder => 'mod_auth_file.c',
1464
1465 IfModules => {
1466 'mod_delay.c' => {
1467 DelayEngine => 'off',
1468 },
1469 },
1470 };
1471
1472 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1473
1474 # Open pipes, for use between the parent and child processes. Specifically,
1475 # the child will indicate when it's done with its test by writing a message
1476 # to the parent.
1477 my ($rfh, $wfh);
1478 unless (pipe($rfh, $wfh)) {
1479 die("Can't open pipe: $!");
1480 }
1481
1482 my $ex;
1483
1484 # Fork child
1485 $self->handle_sigchld();
1486 defined(my $pid = fork()) or die("Can't fork: $!");
1487 if ($pid) {
1488 eval {
1489 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1490 $client->login($user, $passwd);
1491 $client->type('binary');
1492 $client->port();
1493
1494 my $test_file = 'foo/bar/baz';
1495
1496 eval { $client->mlsd($test_file) };
1497 unless ($@) {
1498 die("MLSD succeeded unexpectedly: " . $client->response_code() . " " .
1499 $client->response_msg());
1500 }
1501
1502 my $resp_code = $client->response_code();
1503 my $resp_msg = $client->response_msg();
1504
1505 my $expected;
1506
1507 $expected = 550;
1508 $self->assert($expected == $resp_code,
1509 test_msg("Expected response code $expected, got $resp_code"));
1510
1511 $expected = "$test_file: No such file or directory";
1512 $self->assert($expected eq $resp_msg,
1513 test_msg("Expected response message '$expected', got '$resp_msg'"));
1514 };
1515
1516 if ($@) {
1517 $ex = $@;
1518 }
1519
1520 $wfh->print("done\n");
1521 $wfh->flush();
1522
1523 } else {
1524 eval { server_wait($config_file, $rfh) };
1525 if ($@) {
1526 warn($@);
1527 exit 1;
1528 }
1529
1530 exit 0;
1531 }
1532
1533 # Stop server
1534 server_stop($pid_file);
1535
1536 $self->assert_child_ok($pid);
1537
1538 if ($ex) {
1539 test_append_logfile($log_file);
1540 unlink($log_file);
1541
1542 die($ex);
1543 }
1544
1545 unlink($log_file);
1546 }
1547
1548 sub mlsd_fails_eperm {
1549 my $self = shift;
1550 my $tmpdir = $self->{tmpdir};
1551
1552 my $config_file = "$tmpdir/cmds.conf";
1553 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1554 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1555
1556 my $log_file = test_get_logfile();
1557
1558 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1559 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1560
1561 my $user = 'proftpd';
1562 my $passwd = 'test';
1563 my $home_dir = File::Spec->rel2abs($tmpdir);
1564 my $uid = 500;
1565 my $gid = 500;
1566
1567 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1568 mkpath($sub_dir);
1569
1570 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar");
1571 if (open(my $fh, "> $test_file")) {
1572 close($fh);
1573
1574 } else {
1575 die("Can't open $test_file: $!");
1576 }
1577
1578 # Make sure that, if we're running as root, that the home directory has
1579 # permissions/privs set for the account we create
1580 if ($< == 0) {
1581 unless (chmod(0755, $home_dir, $sub_dir)) {
1582 die("Can't set perms on $home_dir, $sub_dir to 0755: $!");
1583 }
1584
1585 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1586 die("Can't set owner of $home_dir, $sub_dir to $uid/$gid: $!");
1587 }
1588 }
1589
1590 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1591 '/bin/bash');
1592 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1593
1594 my $config = {
1595 PidFile => $pid_file,
1596 ScoreboardFile => $scoreboard_file,
1597 SystemLog => $log_file,
1598
1599 AuthUserFile => $auth_user_file,
1600 AuthGroupFile => $auth_group_file,
1601 AuthOrder => 'mod_auth_file.c',
1602
1603 IfModules => {
1604 'mod_delay.c' => {
1605 DelayEngine => 'off',
1606 },
1607 },
1608 };
1609
1610 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1611
1612 # Open pipes, for use between the parent and child processes. Specifically,
1613 # the child will indicate when it's done with its test by writing a message
1614 # to the parent.
1615 my ($rfh, $wfh);
1616 unless (pipe($rfh, $wfh)) {
1617 die("Can't open pipe: $!");
1618 }
1619
1620 my $ex;
1621
1622 # Fork child
1623 $self->handle_sigchld();
1624 defined(my $pid = fork()) or die("Can't fork: $!");
1625 if ($pid) {
1626 eval {
1627 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1628 $client->login($user, $passwd);
1629 $client->type('binary');
1630 $client->port();
1631
1632 chmod(0660, $sub_dir);
1633
1634 eval { $client->mlsd($test_file) };
1635 unless ($@) {
1636 die("MLSD succeeded unexpectedly: " . $client->response_code() . " " .
1637 $client->response_msg());
1638 }
1639
1640 my $resp_code = $client->response_code();
1641 my $resp_msg = $client->response_msg();
1642
1643 my $expected;
1644
1645 $expected = 550;
1646 $self->assert($expected == $resp_code,
1647 test_msg("Expected response code $expected, got $resp_code"));
1648
1649 $expected = "$test_file: Permission denied";
1650 $self->assert($expected eq $resp_msg,
1651 test_msg("Expected response message '$expected', got '$resp_msg'"));
1652 };
1653
1654 if ($@) {
1655 $ex = $@;
1656 }
1657
1658 $wfh->print("done\n");
1659 $wfh->flush();
1660
1661 } else {
1662 eval { server_wait($config_file, $rfh) };
1663 if ($@) {
1664 warn($@);
1665 exit 1;
1666 }
1667
1668 exit 0;
1669 }
1670
1671 # Stop server
1672 server_stop($pid_file);
1673
1674 $self->assert_child_ok($pid);
1675
1676 if ($ex) {
1677 test_append_logfile($log_file);
1678 unlink($log_file);
1679
1680 die($ex);
1681 }
1682
1683 unlink($log_file);
1684 }
1685
1686 sub mlsd_ok_hidden_file {
1687 my $self = shift;
1688 my $tmpdir = $self->{tmpdir};
1689
1690 my $config_file = "$tmpdir/cmds.conf";
1691 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1692 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1693
1694 my $log_file = test_get_logfile();
1695
1696 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1697 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1698
1699 my $user = 'proftpd';
1700 my $passwd = 'test';
1701 my $home_dir = File::Spec->rel2abs($tmpdir);
1702 my $uid = 500;
1703 my $gid = 500;
1704
1705 # Make sure that, if we're running as root, that the home directory has
1706 # permissions/privs set for the account we create
1707 if ($< == 0) {
1708 unless (chmod(0755, $home_dir)) {
1709 die("Can't set perms on $home_dir to 0755: $!");
1710 }
1711
1712 unless (chown($uid, $gid, $home_dir)) {
1713 die("Can't set owner of $home_dir to $uid/$gid: $!");
1714 }
1715 }
1716
1717 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1718 '/bin/bash');
1719 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1720
1721 my $test_file = File::Spec->rel2abs("$tmpdir/test.foo");
1722 if (open(my $fh, "> $test_file")) {
1723 close($fh);
1724
1725 } else {
1726 die("Can't open $test_file: $!");
1727 }
1728
1729 my $config = {
1730 PidFile => $pid_file,
1731 ScoreboardFile => $scoreboard_file,
1732 SystemLog => $log_file,
1733
1734 AuthUserFile => $auth_user_file,
1735 AuthGroupFile => $auth_group_file,
1736 AuthOrder => 'mod_auth_file.c',
1737
1738 Directory => {
1739 '/' => {
1740 HideFiles => '\.foo$',
1741 },
1742 },
1743
1744 IfModules => {
1745 'mod_delay.c' => {
1746 DelayEngine => 'off',
1747 },
1748 },
1749 };
1750
1751 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1752
1753 # Open pipes, for use between the parent and child processes. Specifically,
1754 # the child will indicate when it's done with its test by writing a message
1755 # to the parent.
1756 my ($rfh, $wfh);
1757 unless (pipe($rfh, $wfh)) {
1758 die("Can't open pipe: $!");
1759 }
1760
1761 my $ex;
1762
1763 # Fork child
1764 $self->handle_sigchld();
1765 defined(my $pid = fork()) or die("Can't fork: $!");
1766 if ($pid) {
1767 eval {
1768 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1769 $client->login($user, $passwd);
1770 $client->type('binary');
1771
1772 my $conn = $client->mlsd_raw($home_dir);
1773 unless ($conn) {
1774 die("MLSD failed: " . $client->response_code() . " " .
1775 $client->response_msg());
1776 }
1777
1778 my $buf;
1779 $conn->read($buf, 8192, 30);
1780 eval { $conn->close() };
1781
1782 my $res = {};
1783 my $lines = [split(/\r\n/, $buf)];
1784 foreach my $line (@$lines) {
1785 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
1786 $res->{$1} = 1;
1787 }
1788 }
1789
1790 # Bug#3190 occurred because mod_facts' handling of MLSD was not checking
1791 # to see if a listed file has been hidden (e.g. via HideFiles).
1792
1793 my $count = scalar(keys(%$res));
1794 my $expected = 8;
1795 unless ($count == $expected) {
1796 die("MLSD returned wrong number of entries (expected $expected, got $count)");
1797 }
1798 };
1799
1800 if ($@) {
1801 $ex = $@;
1802 }
1803
1804 $wfh->print("done\n");
1805 $wfh->flush();
1806
1807 } else {
1808 eval { server_wait($config_file, $rfh) };
1809 if ($@) {
1810 warn($@);
1811 exit 1;
1812 }
1813
1814 exit 0;
1815 }
1816
1817 # Stop server
1818 server_stop($pid_file);
1819
1820 $self->assert_child_ok($pid);
1821
1822 if ($ex) {
1823 test_append_logfile($log_file);
1824 unlink($log_file);
1825
1826 die($ex);
1827 }
1828
1829 unlink($log_file);
1830 }
1831
1832 sub mlsd_ok_path_with_spaces {
1833 my $self = shift;
1834 my $tmpdir = $self->{tmpdir};
1835
1836 my $config_file = "$tmpdir/cmds.conf";
1837 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1838 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1839
1840 my $log_file = test_get_logfile();
1841
1842 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1843 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1844
1845 my $user = 'proftpd';
1846 my $passwd = 'test';
1847 my $home_dir = File::Spec->rel2abs($tmpdir);
1848 my $uid = 500;
1849 my $gid = 500;
1850
1851 # Make sure that, if we're running as root, that the home directory has
1852 # permissions/privs set for the account we create
1853 if ($< == 0) {
1854 unless (chmod(0755, $home_dir)) {
1855 die("Can't set perms on $home_dir to 0755: $!");
1856 }
1857
1858 unless (chown($uid, $gid, $home_dir)) {
1859 die("Can't set owner of $home_dir to $uid/$gid: $!");
1860 }
1861 }
1862
1863 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1864 '/bin/bash');
1865 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1866
1867 my $test_dir = File::Spec->rel2abs("$tmpdir/test foo");
1868 mkpath($test_dir);
1869
1870 my $config = {
1871 PidFile => $pid_file,
1872 ScoreboardFile => $scoreboard_file,
1873 SystemLog => $log_file,
1874
1875 AuthUserFile => $auth_user_file,
1876 AuthGroupFile => $auth_group_file,
1877 AuthOrder => 'mod_auth_file.c',
1878
1879 IfModules => {
1880 'mod_delay.c' => {
1881 DelayEngine => 'off',
1882 },
1883 },
1884 };
1885
1886 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1887
1888 # Open pipes, for use between the parent and child processes. Specifically,
1889 # the child will indicate when it's done with its test by writing a message
1890 # to the parent.
1891 my ($rfh, $wfh);
1892 unless (pipe($rfh, $wfh)) {
1893 die("Can't open pipe: $!");
1894 }
1895
1896 my $ex;
1897
1898 # Fork child
1899 $self->handle_sigchld();
1900 defined(my $pid = fork()) or die("Can't fork: $!");
1901 if ($pid) {
1902 eval {
1903 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1904 $client->login($user, $passwd);
1905 $client->type('binary');
1906
1907 my $conn = $client->mlsd_raw('test foo');
1908 unless ($conn) {
1909 die("MLSD failed: " . $client->response_code() . " " .
1910 $client->response_msg());
1911 }
1912
1913 my $buf;
1914 $conn->read($buf, 8192, 30);
1915 eval { $conn->close() };
1916
1917 my $res = {};
1918 my $lines = [split(/\r\n/, $buf)];
1919 foreach my $line (@$lines) {
1920 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
1921 $res->{$1} = 1;
1922 }
1923 }
1924
1925 my $count = scalar(keys(%$res));
1926 unless ($count == 2) {
1927 die("MLSD returned wrong number of entries (expected 2, got $count)");
1928 }
1929 };
1930
1931 if ($@) {
1932 $ex = $@;
1933 }
1934
1935 $wfh->print("done\n");
1936 $wfh->flush();
1937
1938 } else {
1939 eval { server_wait($config_file, $rfh) };
1940 if ($@) {
1941 warn($@);
1942 exit 1;
1943 }
1944
1945 exit 0;
1946 }
1947
1948 # Stop server
1949 server_stop($pid_file);
1950
1951 $self->assert_child_ok($pid);
1952
1953 if ($ex) {
1954 test_append_logfile($log_file);
1955 unlink($log_file);
1956
1957 die($ex);
1958 }
1959
1960 unlink($log_file);
1961 }
1962
1963 sub mlsd_nonascii_chars_bug3032 {
1964 my $self = shift;
1965 my $tmpdir = $self->{tmpdir};
1966
1967 my $config_file = "$tmpdir/cmds.conf";
1968 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1969 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1970
1971 my $log_file = test_get_logfile();
1972
1973 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1974 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1975
1976 my $user = 'proftpd';
1977 my $passwd = 'test';
1978 my $home_dir = File::Spec->rel2abs($tmpdir);
1979 my $uid = 500;
1980 my $gid = 500;
1981
1982 # Make sure that, if we're running as root, that the home directory has
1983 # permissions/privs set for the account we create
1984 if ($< == 0) {
1985 unless (chmod(0755, $home_dir)) {
1986 die("Can't set perms on $home_dir to 0755: $!");
1987 }
1988
1989 unless (chown($uid, $gid, $home_dir)) {
1990 die("Can't set owner of $home_dir to $uid/$gid: $!");
1991 }
1992 }
1993
1994 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1995 '/bin/bash');
1996 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1997
1998 my $test_dir = File::Spec->rel2abs("$tmpdir/test\b");
1999 mkpath($test_dir);
2000
2001 my $config = {
2002 PidFile => $pid_file,
2003 ScoreboardFile => $scoreboard_file,
2004 SystemLog => $log_file,
2005
2006 AuthUserFile => $auth_user_file,
2007 AuthGroupFile => $auth_group_file,
2008 AuthOrder => 'mod_auth_file.c',
2009
2010 IfModules => {
2011 'mod_delay.c' => {
2012 DelayEngine => 'off',
2013 },
2014 },
2015 };
2016
2017 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2018
2019 # Open pipes, for use between the parent and child processes. Specifically,
2020 # the child will indicate when it's done with its test by writing a message
2021 # to the parent.
2022 my ($rfh, $wfh);
2023 unless (pipe($rfh, $wfh)) {
2024 die("Can't open pipe: $!");
2025 }
2026
2027 my $ex;
2028
2029 # Fork child
2030 $self->handle_sigchld();
2031 defined(my $pid = fork()) or die("Can't fork: $!");
2032 if ($pid) {
2033 eval {
2034 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2035 $client->login($user, $passwd);
2036 $client->type('binary');
2037
2038 my $conn = $client->mlsd_raw("test\b");
2039 unless ($conn) {
2040 die("MLSD failed: " . $client->response_code() . " " .
2041 $client->response_msg());
2042 }
2043
2044 my $buf;
2045 $conn->read($buf, 8192, 30);
2046 eval { $conn->close() };
2047
2048 my $res = {};
2049 my $lines = [split(/\r\n/, $buf)];
2050 foreach my $line (@$lines) {
2051 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2052 $res->{$1} = 1;
2053 }
2054 }
2055
2056 my $count = scalar(keys(%$res));
2057 unless ($count == 2) {
2058 die("MLSD returned wrong number of entries (expected 2, got $count)");
2059 }
2060 };
2061
2062 if ($@) {
2063 $ex = $@;
2064 }
2065
2066 $wfh->print("done\n");
2067 $wfh->flush();
2068
2069 } else {
2070 eval { server_wait($config_file, $rfh) };
2071 if ($@) {
2072 warn($@);
2073 exit 1;
2074 }
2075
2076 exit 0;
2077 }
2078
2079 # Stop server
2080 server_stop($pid_file);
2081
2082 $self->assert_child_ok($pid);
2083
2084 if ($ex) {
2085 test_append_logfile($log_file);
2086 unlink($log_file);
2087
2088 die($ex);
2089 }
2090
2091 unlink($log_file);
2092 }
2093
2094 sub mlsd_symlink_showsymlinks_off_bug3318 {
2095 my $self = shift;
2096 my $tmpdir = $self->{tmpdir};
2097 my $setup = test_setup($tmpdir, 'cmds');
2098
2099 my $foo_dir = File::Spec->rel2abs("$setup->{home_dir}/foo");
2100 mkpath($foo_dir);
2101
2102 my $test_file = File::Spec->rel2abs("$foo_dir/test.txt");
2103 if (open(my $fh, "> $test_file")) {
2104 print $fh "Hello, World!\n";
2105 unless (close($fh)) {
2106 die("Can't write $test_file: $!");
2107 }
2108
2109 } else {
2110 die("Can't open $test_file: $!");
2111 }
2112
2113 # Change to the 'foo' directory in order to create a relative path in the
2114 # symlink we need
2115
2116 my $cwd = getcwd();
2117 unless (chdir($foo_dir)) {
2118 die("Can't chdir to $foo_dir: $!");
2119 }
2120
2121 unless (symlink('./test.txt', './test.lnk')) {
2122 die("Can't symlink 'test.lnk' to './test.txt': $!");
2123 }
2124
2125 unless (chdir($cwd)) {
2126 die("Can't chdir to $cwd: $!");
2127 }
2128
2129 if ($< == 0) {
2130 unless (chmod(0755, $foo_dir)) {
2131 die("Can't set perms on $foo_dir to 0755: $!");
2132 }
2133
2134 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
2135 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
2136 }
2137 }
2138
2139 my $config = {
2140 PidFile => $setup->{pid_file},
2141 ScoreboardFile => $setup->{scoreboard_file},
2142 SystemLog => $setup->{log_file},
2143 TraceLog => $setup->{log_file},
2144 Trace => 'fsio:20 fs.statcache:20',
2145
2146 AuthUserFile => $setup->{auth_user_file},
2147 AuthGroupFile => $setup->{auth_group_file},
2148 AuthOrder => 'mod_auth_file.c',
2149
2150 ShowSymlinks => 'off',
2151
2152 IfModules => {
2153 'mod_delay.c' => {
2154 DelayEngine => 'off',
2155 },
2156 },
2157 };
2158
2159 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2160 $config);
2161
2162 # Open pipes, for use between the parent and child processes. Specifically,
2163 # the child will indicate when it's done with its test by writing a message
2164 # to the parent.
2165 my ($rfh, $wfh);
2166 unless (pipe($rfh, $wfh)) {
2167 die("Can't open pipe: $!");
2168 }
2169
2170 my $ex;
2171
2172 # Fork child
2173 $self->handle_sigchld();
2174 defined(my $pid = fork()) or die("Can't fork: $!");
2175 if ($pid) {
2176 eval {
2177 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2178 $client->login($setup->{user}, $setup->{passwd});
2179 $client->type('binary');
2180
2181 my $conn = $client->mlsd_raw('foo');
2182 unless ($conn) {
2183 die("MLSD failed: " . $client->response_code() . " " .
2184 $client->response_msg());
2185 }
2186
2187 my $buf;
2188 $conn->read($buf, 8192, 30);
2189 eval { $conn->close() };
2190
2191 if ($ENV{TEST_VERBOSE}) {
2192 print STDERR "# Response:\n$buf\n";
2193 }
2194
2195 my $res = {};
2196 my $lines = [split(/\r\n/, $buf)];
2197 foreach my $line (@$lines) {
2198 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2199 $res->{$2} = $1;
2200 }
2201 }
2202
2203 my $count = scalar(keys(%$res));
2204 unless ($count == 4) {
2205 die("MLSD returned wrong number of entries (expected 4, got $count)");
2206 }
2207
2208 # test.lnk is a symlink to test.txt. According to RFC 3659, the unique
2209 # fact for both of these should thus be the same, since they are the
2210 # same underlying object.
2211
2212 my $expected = $res->{'test.txt'};
2213 my $got = $res->{'test.lnk'};
2214 $self->assert($expected eq $got,
2215 test_msg("Expected '$expected', got '$got'"));
2216 };
2217 if ($@) {
2218 $ex = $@;
2219 }
2220
2221 $wfh->print("done\n");
2222 $wfh->flush();
2223
2224 } else {
2225 eval { server_wait($setup->{config_file}, $rfh) };
2226 if ($@) {
2227 warn($@);
2228 exit 1;
2229 }
2230
2231 exit 0;
2232 }
2233
2234 # Stop server
2235 server_stop($setup->{pid_file});
2236 $self->assert_child_ok($pid);
2237
2238 test_cleanup($setup->{log_file}, $ex);
2239 }
2240
2241 sub mlsd_symlink_showsymlinks_on_bug3318 {
2242 my $self = shift;
2243 my $tmpdir = $self->{tmpdir};
2244 my $setup = test_setup($tmpdir, 'cmds');
2245
2246 my $foo_dir = File::Spec->rel2abs("$setup->{home_dir}/foo");
2247 mkpath($foo_dir);
2248
2249 my $test_file = File::Spec->rel2abs("$foo_dir/test.txt");
2250 if (open(my $fh, "> $test_file")) {
2251 print $fh "Hello, World!\n";
2252 unless (close($fh)) {
2253 die("Can't write $test_file: $!");
2254 }
2255
2256 } else {
2257 die("Can't open $test_file: $!");
2258 }
2259
2260 # Change to the 'foo' directory in order to create a relative path in the
2261 # symlink we need
2262
2263 my $cwd = getcwd();
2264 unless (chdir("$foo_dir")) {
2265 die("Can't chdir to $foo_dir: $!");
2266 }
2267
2268 unless (symlink('test.txt', 'test.lnk')) {
2269 die("Can't symlink 'test.txt' to 'test.lnk': $!");
2270 }
2271
2272 unless (chdir($cwd)) {
2273 die("Can't chdir to $cwd: $!");
2274 }
2275
2276 # Make sure that, if we're running as root, that the home directory has
2277 # permissions/privs set for the account we create
2278 if ($< == 0) {
2279 unless (chmod(0755, $foo_dir)) {
2280 die("Can't set perms on $foo_dir to 0755: $!");
2281 }
2282
2283 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
2284 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
2285 }
2286 }
2287
2288 my $config = {
2289 PidFile => $setup->{pid_file},
2290 ScoreboardFile => $setup->{scoreboard_file},
2291 SystemLog => $setup->{log_file},
2292
2293 AuthUserFile => $setup->{auth_user_file},
2294 AuthGroupFile => $setup->{auth_group_file},
2295 AuthOrder => 'mod_auth_file.c',
2296
2297 ShowSymlinks => 'on',
2298
2299 IfModules => {
2300 'mod_delay.c' => {
2301 DelayEngine => 'off',
2302 },
2303 },
2304 };
2305
2306 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2307 $config);
2308
2309 # Open pipes, for use between the parent and child processes. Specifically,
2310 # the child will indicate when it's done with its test by writing a message
2311 # to the parent.
2312 my ($rfh, $wfh);
2313 unless (pipe($rfh, $wfh)) {
2314 die("Can't open pipe: $!");
2315 }
2316
2317 my $ex;
2318
2319 # Fork child
2320 $self->handle_sigchld();
2321 defined(my $pid = fork()) or die("Can't fork: $!");
2322 if ($pid) {
2323 eval {
2324 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2325 $client->login($setup->{user}, $setup->{passwd});
2326 $client->type('binary');
2327
2328 my $conn = $client->mlsd_raw('foo');
2329 unless ($conn) {
2330 die("MLSD failed: " . $client->response_code() . " " .
2331 $client->response_msg());
2332 }
2333
2334 my $buf;
2335 $conn->read($buf, 8192, 30);
2336 eval { $conn->close() };
2337
2338 if ($ENV{TEST_VERBOSE}) {
2339 print STDERR "# Response:\n$buf\n";
2340 }
2341
2342 my $res = {};
2343 my $lines = [split(/\r\n/, $buf)];
2344 foreach my $line (@$lines) {
2345 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2346 $res->{$3} = { type => $1, unique => $2 };
2347 }
2348 }
2349
2350 my $count = scalar(keys(%$res));
2351 unless ($count == 4) {
2352 die("MLSD returned wrong number of entries (expected 4, got $count)");
2353 }
2354
2355 # test.lnk is a symlink to test.txt. According to RFC3659, the unique
2356 # fact for both of these should thus be the same, since they are the
2357 # same underlying object.
2358
2359 my $expected = $res->{'test.txt'}->{unique};
2360 my $got = $res->{'test.lnk'}->{unique};
2361 $self->assert($expected eq $got,
2362 test_msg("Expected '$expected', got '$got'"));
2363
2364 # Since ShowSymlinks is on, the type for test.lnk should indicate that
2365 # it's a symlink
2366 $expected = 'OS.unix=symlink';
2367 $got = $res->{'test.lnk'}->{type};
2368 $self->assert(qr/$expected/i, $got,
2369 test_msg("Expected '$expected', got '$got'"));
2370 };
2371 if ($@) {
2372 $ex = $@;
2373 }
2374
2375 $wfh->print("done\n");
2376 $wfh->flush();
2377
2378 } else {
2379 eval { server_wait($setup->{config_file}, $rfh) };
2380 if ($@) {
2381 warn($@);
2382 exit 1;
2383 }
2384
2385 exit 0;
2386 }
2387
2388 # Stop server
2389 server_stop($setup->{pid_file});
2390 $self->assert_child_ok($pid);
2391
2392 test_cleanup($setup->{log_file}, $ex);
2393 }
2394
2395 sub mlsd_symlink_showsymlinks_on_chrooted_bug4219 {
2396 my $self = shift;
2397 my $tmpdir = $self->{tmpdir};
2398 my $setup = test_setup($tmpdir, 'cmds');
2399
2400 my $foo_dir = File::Spec->rel2abs("$setup->{home_dir}/foo");
2401 mkpath($foo_dir);
2402
2403 my $test_file = File::Spec->rel2abs("$foo_dir/test.txt");
2404 if (open(my $fh, "> $test_file")) {
2405 print $fh "Hello, World!\n";
2406 unless (close($fh)) {
2407 die("Can't write $test_file: $!");
2408 }
2409
2410 } else {
2411 die("Can't open $test_file: $!");
2412 }
2413
2414 # Change to the 'foo' directory in order to create a relative path in the
2415 # symlink we need
2416
2417 my $cwd = getcwd();
2418 unless (chdir("$foo_dir")) {
2419 die("Can't chdir to $foo_dir: $!");
2420 }
2421
2422 unless (symlink('test.txt', 'test.lnk')) {
2423 die("Can't symlink 'test.txt' to 'test.lnk': $!");
2424 }
2425
2426 unless (chdir($cwd)) {
2427 die("Can't chdir to $cwd: $!");
2428 }
2429
2430 # Make sure that, if we're running as root, that the home directory has
2431 # permissions/privs set for the account we create
2432 if ($< == 0) {
2433 unless (chmod(0755, $foo_dir)) {
2434 die("Can't set perms on $foo_dir to 0755: $!");
2435 }
2436
2437 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
2438 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
2439 }
2440 }
2441
2442 my $config = {
2443 PidFile => $setup->{pid_file},
2444 ScoreboardFile => $setup->{scoreboard_file},
2445 SystemLog => $setup->{log_file},
2446 TraceLog => $setup->{log_file},
2447 Trace => 'fsio:20',
2448
2449 AuthUserFile => $setup->{auth_user_file},
2450 AuthGroupFile => $setup->{auth_group_file},
2451 AuthOrder => 'mod_auth_file.c',
2452
2453 DefaultRoot => '~',
2454 ShowSymlinks => 'on',
2455
2456 IfModules => {
2457 'mod_delay.c' => {
2458 DelayEngine => 'off',
2459 },
2460 },
2461 };
2462
2463 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2464 $config);
2465
2466 # Open pipes, for use between the parent and child processes. Specifically,
2467 # the child will indicate when it's done with its test by writing a message
2468 # to the parent.
2469 my ($rfh, $wfh);
2470 unless (pipe($rfh, $wfh)) {
2471 die("Can't open pipe: $!");
2472 }
2473
2474 my $ex;
2475
2476 # Fork child
2477 $self->handle_sigchld();
2478 defined(my $pid = fork()) or die("Can't fork: $!");
2479 if ($pid) {
2480 eval {
2481 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2482 $client->login($setup->{user}, $setup->{passwd});
2483 $client->type('binary');
2484
2485 my $conn = $client->mlsd_raw('foo');
2486 unless ($conn) {
2487 die("MLSD failed: " . $client->response_code() . " " .
2488 $client->response_msg());
2489 }
2490
2491 my $buf;
2492 $conn->read($buf, 8192, 30);
2493 eval { $conn->close() };
2494
2495 if ($ENV{TEST_VERBOSE}) {
2496 print STDERR "# Response:\n$buf\n";
2497 }
2498
2499 my $res = {};
2500 my $lines = [split(/\r\n/, $buf)];
2501 foreach my $line (@$lines) {
2502 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2503 $res->{$3} = { type => $1, unique => $2 };
2504 }
2505 }
2506
2507 my $count = scalar(keys(%$res));
2508 unless ($count == 4) {
2509 die("MLSD returned wrong number of entries (expected 4, got $count)");
2510 }
2511
2512 # test.lnk is a symlink to test.txt. According to RFC3659, the unique
2513 # fact for both of these should thus be the same, since they are the
2514 # same underlying object.
2515
2516 my $expected = $res->{'test.txt'}->{unique};
2517 my $got = $res->{'test.lnk'}->{unique};
2518 $self->assert($expected eq $got,
2519 test_msg("Expected '$expected', got '$got'"));
2520
2521 # Since ShowSymlinks is on, the type for test.lnk should indicate that
2522 # it's a symlink
2523 $expected = 'OS.unix=symlink';
2524 $got = $res->{'test.lnk'}->{type};
2525 $self->assert(qr/$expected/i, $got,
2526 test_msg("Expected '$expected', got '$got'"));
2527 };
2528 if ($@) {
2529 $ex = $@;
2530 }
2531
2532 $wfh->print("done\n");
2533 $wfh->flush();
2534
2535 } else {
2536 eval { server_wait($setup->{config_file}, $rfh) };
2537 if ($@) {
2538 warn($@);
2539 exit 1;
2540 }
2541
2542 exit 0;
2543 }
2544
2545 # Stop server
2546 server_stop($setup->{pid_file});
2547 $self->assert_child_ok($pid);
2548
2549 test_cleanup($setup->{log_file}, $ex);
2550 }
2551
2552 sub mlsd_symlink_showsymlinks_on_use_slink_chrooted_bug4219 {
2553 my $self = shift;
2554 my $tmpdir = $self->{tmpdir};
2555 my $setup = test_setup($tmpdir, 'cmds');
2556
2557 my $foo_dir = File::Spec->rel2abs("$setup->{home_dir}/foo");
2558 mkpath($foo_dir);
2559
2560 my $test_file = File::Spec->rel2abs("$foo_dir/test.txt");
2561 if (open(my $fh, "> $test_file")) {
2562 print $fh "Hello, World!\n";
2563 unless (close($fh)) {
2564 die("Can't write $test_file: $!");
2565 }
2566
2567 } else {
2568 die("Can't open $test_file: $!");
2569 }
2570
2571 # Change to the 'foo' directory in order to create a relative path in the
2572 # symlink we need
2573
2574 my $cwd = getcwd();
2575 unless (chdir("$foo_dir")) {
2576 die("Can't chdir to $foo_dir: $!");
2577 }
2578
2579 unless (symlink('test.txt', 'test.lnk')) {
2580 die("Can't symlink 'test.txt' to 'test.lnk': $!");
2581 }
2582
2583 unless (chdir($cwd)) {
2584 die("Can't chdir to $cwd: $!");
2585 }
2586
2587 # Make sure that, if we're running as root, that the home directory has
2588 # permissions/privs set for the account we create
2589 if ($< == 0) {
2590 unless (chmod(0755, $foo_dir)) {
2591 die("Can't set perms on $foo_dir to 0755: $!");
2592 }
2593
2594 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
2595 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
2596 }
2597 }
2598
2599 my $config = {
2600 PidFile => $setup->{pid_file},
2601 ScoreboardFile => $setup->{scoreboard_file},
2602 SystemLog => $setup->{log_file},
2603 TraceLog => $setup->{log_file},
2604 Trace => 'fsio:20',
2605
2606 AuthUserFile => $setup->{auth_user_file},
2607 AuthGroupFile => $setup->{auth_group_file},
2608 AuthOrder => 'mod_auth_file.c',
2609
2610 DefaultRoot => '~',
2611 FactsOptions => 'UseSlink',
2612 ShowSymlinks => 'on',
2613
2614 IfModules => {
2615 'mod_delay.c' => {
2616 DelayEngine => 'off',
2617 },
2618 },
2619 };
2620
2621 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2622 $config);
2623
2624 # Open pipes, for use between the parent and child processes. Specifically,
2625 # the child will indicate when it's done with its test by writing a message
2626 # to the parent.
2627 my ($rfh, $wfh);
2628 unless (pipe($rfh, $wfh)) {
2629 die("Can't open pipe: $!");
2630 }
2631
2632 my $ex;
2633
2634 # Fork child
2635 $self->handle_sigchld();
2636 defined(my $pid = fork()) or die("Can't fork: $!");
2637 if ($pid) {
2638 eval {
2639 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2640 $client->login($setup->{user}, $setup->{passwd});
2641 $client->type('binary');
2642
2643 my $conn = $client->mlsd_raw('foo');
2644 unless ($conn) {
2645 die("MLSD failed: " . $client->response_code() . " " .
2646 $client->response_msg());
2647 }
2648
2649 my $buf;
2650 $conn->read($buf, 8192, 30);
2651 eval { $conn->close() };
2652
2653 if ($ENV{TEST_VERBOSE}) {
2654 print STDERR "# Response:\n$buf\n";
2655 }
2656
2657 my $res = {};
2658 my $lines = [split(/\r\n/, $buf)];
2659 foreach my $line (@$lines) {
2660 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2661 $res->{$3} = { type => $1, unique => $2 };
2662 }
2663 }
2664
2665 my $count = scalar(keys(%$res));
2666 unless ($count == 4) {
2667 die("MLSD returned wrong number of entries (expected 4, got $count)");
2668 }
2669
2670 # test.lnk is a symlink to test.txt. According to RFC3659, the unique
2671 # fact for both of these should thus be the same, since they are the
2672 # same underlying object.
2673
2674 my $expected = $res->{'test.txt'}->{unique};
2675 my $got = $res->{'test.lnk'}->{unique};
2676 $self->assert($expected eq $got,
2677 test_msg("Expected '$expected', got '$got'"));
2678
2679 # Since ShowSymlinks is on, the type for test.lnk should indicate that
2680 # it's a symlink
2681 $expected = 'OS.unix=slink:/foo/test.txt';
2682 $got = $res->{'test.lnk'}->{type};
2683 $self->assert(qr/$expected/i, $got,
2684 test_msg("Expected '$expected', got '$got'"));
2685 };
2686 if ($@) {
2687 $ex = $@;
2688 }
2689
2690 $wfh->print("done\n");
2691 $wfh->flush();
2692
2693 } else {
2694 eval { server_wait($setup->{config_file}, $rfh) };
2695 if ($@) {
2696 warn($@);
2697 exit 1;
2698 }
2699
2700 exit 0;
2701 }
2702
2703 # Stop server
2704 server_stop($setup->{pid_file});
2705 $self->assert_child_ok($pid);
2706
2707 test_cleanup($setup->{log_file}, $ex);
2708 }
2709
2710 # See also:
2711 # Tests/Config/ShowSymlinks.pm::showsymlinks_on_mlsd_rel_symlinked_dir()
2712 sub mlsd_symlinked_dir_bug3859 {
2713 my $self = shift;
2714 my $tmpdir = $self->{tmpdir};
2715
2716 my $config_file = "$tmpdir/cmds.conf";
2717 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2718 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2719
2720 my $log_file = test_get_logfile();
2721
2722 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2723 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2724
2725 my $user = 'proftpd';
2726 my $passwd = 'test';
2727 my $group = 'ftpd';
2728 my $home_dir = File::Spec->rel2abs($tmpdir);
2729 my $uid = 500;
2730 my $gid = 500;
2731
2732 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
2733 mkpath($foo_dir);
2734
2735 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/test.d");
2736 mkpath($test_dir);
2737
2738 # Change to the 'foo' directory in order to create a relative path in the
2739 # symlink we need
2740
2741 my $cwd = getcwd();
2742 unless (chdir("$foo_dir")) {
2743 die("Can't chdir to $foo_dir: $!");
2744 }
2745
2746 unless (symlink('test.d', 'test.lnk')) {
2747 die("Can't symlink 'test.d' to 'test.lnk': $!");
2748 }
2749
2750 unless (chdir($cwd)) {
2751 die("Can't chdir to $cwd: $!");
2752 }
2753
2754 # Make sure that, if we're running as root, that the home directory has
2755 # permissions/privs set for the account we create
2756 if ($< == 0) {
2757 unless (chmod(0755, $home_dir, $foo_dir)) {
2758 die("Can't set perms on $home_dir to 0755: $!");
2759 }
2760
2761 unless (chown($uid, $gid, $home_dir, $foo_dir)) {
2762 die("Can't set owner of $home_dir to $uid/$gid: $!");
2763 }
2764 }
2765
2766 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2767 '/bin/bash');
2768 auth_group_write($auth_group_file, $group, $gid, $user);
2769
2770 my $config = {
2771 PidFile => $pid_file,
2772 ScoreboardFile => $scoreboard_file,
2773 SystemLog => $log_file,
2774
2775 AuthUserFile => $auth_user_file,
2776 AuthGroupFile => $auth_group_file,
2777 AuthOrder => 'mod_auth_file.c',
2778
2779 # Note: use the default ShowSymlinks setting
2780
2781 IfModules => {
2782 'mod_delay.c' => {
2783 DelayEngine => 'off',
2784 },
2785 },
2786 };
2787
2788 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2789
2790 # Open pipes, for use between the parent and child processes. Specifically,
2791 # the child will indicate when it's done with its test by writing a message
2792 # to the parent.
2793 my ($rfh, $wfh);
2794 unless (pipe($rfh, $wfh)) {
2795 die("Can't open pipe: $!");
2796 }
2797
2798 my $ex;
2799
2800 # Fork child
2801 $self->handle_sigchld();
2802 defined(my $pid = fork()) or die("Can't fork: $!");
2803 if ($pid) {
2804 eval {
2805 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2806 $client->login($user, $passwd);
2807 $client->type('binary');
2808
2809 my $conn = $client->mlsd_raw('foo');
2810 unless ($conn) {
2811 die("MLSD failed: " . $client->response_code() . " " .
2812 $client->response_msg());
2813 }
2814
2815 my $buf;
2816 $conn->read($buf, 8192, 30);
2817 eval { $conn->close() };
2818
2819 my $res = {};
2820 my $lines = [split(/\r\n/, $buf)];
2821 foreach my $line (@$lines) {
2822 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2823 $res->{$3} = { type => $1, unique => $2 };
2824 }
2825 }
2826
2827 my $count = scalar(keys(%$res));
2828 unless ($count == 4) {
2829 die("MLSD returned wrong number of entries (expected 4, got $count)");
2830 }
2831
2832 # test.lnk is a symlink to test.d. According to RFC3659, the unique
2833 # fact for both of these should thus be the same, since they are the
2834 # same underlying object.
2835
2836 my $expected = $res->{'test.d'}->{unique};
2837 my $got = $res->{'test.lnk'}->{unique};
2838 $self->assert($expected eq $got,
2839 test_msg("Expected unique fact '$expected', got '$got'"));
2840
2841 # Since ShowSymlinks is on by default, the type for test.lnk should
2842 # indicate that it's a symlink
2843 $expected = 'OS.unix=symlink';
2844 $got = $res->{'test.lnk'}->{type};
2845 $self->assert(qr/$expected/i, $got,
2846 test_msg("Expected type fact '$expected', got '$got'"));
2847 };
2848
2849 if ($@) {
2850 $ex = $@;
2851 }
2852
2853 $wfh->print("done\n");
2854 $wfh->flush();
2855
2856 } else {
2857 eval { server_wait($config_file, $rfh) };
2858 if ($@) {
2859 warn($@);
2860 exit 1;
2861 }
2862
2863 exit 0;
2864 }
2865
2866 # Stop server
2867 server_stop($pid_file);
2868
2869 $self->assert_child_ok($pid);
2870
2871 if ($ex) {
2872 test_append_logfile($log_file);
2873 unlink($log_file);
2874
2875 die($ex);
2876 }
2877
2878 unlink($log_file);
2879 }
2880
2881 sub mlsd_symlinked_dir_showsymlinks_off_bug3859 {
2882 my $self = shift;
2883 my $tmpdir = $self->{tmpdir};
2884
2885 my $config_file = "$tmpdir/cmds.conf";
2886 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
2887 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
2888
2889 my $log_file = test_get_logfile();
2890
2891 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
2892 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
2893
2894 my $user = 'proftpd';
2895 my $passwd = 'test';
2896 my $group = 'ftpd';
2897 my $home_dir = File::Spec->rel2abs($tmpdir);
2898 my $uid = 500;
2899 my $gid = 500;
2900
2901 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
2902 mkpath($foo_dir);
2903
2904 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/test.d");
2905 mkpath($test_dir);
2906
2907 # Change to the 'foo' directory in order to create a relative path in the
2908 # symlink we need
2909
2910 my $cwd = getcwd();
2911 unless (chdir("$foo_dir")) {
2912 die("Can't chdir to $foo_dir: $!");
2913 }
2914
2915 unless (symlink('test.d', 'test.lnk')) {
2916 die("Can't symlink 'test.d' to 'test.lnk': $!");
2917 }
2918
2919 unless (chdir($cwd)) {
2920 die("Can't chdir to $cwd: $!");
2921 }
2922
2923 # Make sure that, if we're running as root, that the home directory has
2924 # permissions/privs set for the account we create
2925 if ($< == 0) {
2926 unless (chmod(0755, $home_dir, $foo_dir)) {
2927 die("Can't set perms on $home_dir to 0755: $!");
2928 }
2929
2930 unless (chown($uid, $gid, $home_dir, $foo_dir)) {
2931 die("Can't set owner of $home_dir to $uid/$gid: $!");
2932 }
2933 }
2934
2935 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2936 '/bin/bash');
2937 auth_group_write($auth_group_file, $group, $gid, $user);
2938
2939 my $config = {
2940 PidFile => $pid_file,
2941 ScoreboardFile => $scoreboard_file,
2942 SystemLog => $log_file,
2943
2944 AuthUserFile => $auth_user_file,
2945 AuthGroupFile => $auth_group_file,
2946 AuthOrder => 'mod_auth_file.c',
2947
2948 ShowSymlinks => 'off',
2949
2950 IfModules => {
2951 'mod_delay.c' => {
2952 DelayEngine => 'off',
2953 },
2954 },
2955 };
2956
2957 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2958
2959 # Open pipes, for use between the parent and child processes. Specifically,
2960 # the child will indicate when it's done with its test by writing a message
2961 # to the parent.
2962 my ($rfh, $wfh);
2963 unless (pipe($rfh, $wfh)) {
2964 die("Can't open pipe: $!");
2965 }
2966
2967 my $ex;
2968
2969 # Fork child
2970 $self->handle_sigchld();
2971 defined(my $pid = fork()) or die("Can't fork: $!");
2972 if ($pid) {
2973 eval {
2974 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2975 $client->login($user, $passwd);
2976 $client->type('binary');
2977
2978 my $conn = $client->mlsd_raw('foo');
2979 unless ($conn) {
2980 die("MLSD failed: " . $client->response_code() . " " .
2981 $client->response_msg());
2982 }
2983
2984 my $buf;
2985 $conn->read($buf, 8192, 30);
2986 eval { $conn->close() };
2987
2988 my $res = {};
2989 my $lines = [split(/\r\n/, $buf)];
2990 foreach my $line (@$lines) {
2991 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
2992 $res->{$3} = { type => $1, unique => $2 };
2993 }
2994 }
2995
2996 my $count = scalar(keys(%$res));
2997 unless ($count == 4) {
2998 die("MLSD returned wrong number of entries (expected 4, got $count)");
2999 }
3000
3001 # test.lnk is a symlink to test.d. According to RFC3659, the unique
3002 # fact for both of these should thus be the same, since they are the
3003 # same underlying object.
3004
3005 my $expected = $res->{'test.d'}->{unique};
3006 my $got = $res->{'test.lnk'}->{unique};
3007 $self->assert($expected eq $got,
3008 test_msg("Expected unique fact '$expected', got '$got'"));
3009
3010 # For ShowSymlinks off, the type for test.lnk should indicate that it's
3011 # a directory
3012 $expected = 'dir';
3013 $got = $res->{'test.lnk'}->{type};
3014 $self->assert(qr/$expected/i, $got,
3015 test_msg("Expected type fact '$expected', got '$got'"));
3016 };
3017
3018 if ($@) {
3019 $ex = $@;
3020 }
3021
3022 $wfh->print("done\n");
3023 $wfh->flush();
3024
3025 } else {
3026 eval { server_wait($config_file, $rfh) };
3027 if ($@) {
3028 warn($@);
3029 exit 1;
3030 }
3031
3032 exit 0;
3033 }
3034
3035 # Stop server
3036 server_stop($pid_file);
3037
3038 $self->assert_child_ok($pid);
3039
3040 if ($ex) {
3041 test_append_logfile($log_file);
3042 unlink($log_file);
3043
3044 die($ex);
3045 }
3046
3047 unlink($log_file);
3048 }
3049
3050 sub mlsd_wide_dir {
3051 my $self = shift;
3052 my $tmpdir = $self->{tmpdir};
3053 my $setup = test_setup($tmpdir, 'cmds');
3054
3055 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
3056 mkpath($test_dir);
3057
3058 my $expected = {
3059 '.' => 1,
3060 '..' => 1,
3061 };
3062
3063 my $max_nfiles = 500;
3064 for (my $i = 0; $i < $max_nfiles; $i++) {
3065 my $test_filename = 'SomeReallyLongAndObnoxiousTestFileNameTemplate' . $i;
3066
3067 # The expected hash is used later for verifying the results of the READDIR
3068 $expected->{$test_filename} = 1;
3069
3070 my $test_path = File::Spec->rel2abs("$test_dir/$test_filename");
3071
3072 if (open(my $fh, "> $test_path")) {
3073 close($fh);
3074
3075 } else {
3076 die("Can't open $test_path: $!");
3077 }
3078 }
3079
3080 my $config = {
3081 PidFile => $setup->{pid_file},
3082 ScoreboardFile => $setup->{scoreboard_file},
3083 SystemLog => $setup->{log_file},
3084 TraceLog => $setup->{log_file},
3085 Trace => 'pool:20',
3086
3087 AuthUserFile => $setup->{auth_user_file},
3088 AuthGroupFile => $setup->{auth_group_file},
3089 AuthOrder => 'mod_auth_file.c',
3090
3091 IfModules => {
3092 'mod_delay.c' => {
3093 DelayEngine => 'off',
3094 },
3095 },
3096 };
3097
3098 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3099 $config);
3100
3101 # Open pipes, for use between the parent and child processes. Specifically,
3102 # the child will indicate when it's done with its test by writing a message
3103 # to the parent.
3104 my ($rfh, $wfh);
3105 unless (pipe($rfh, $wfh)) {
3106 die("Can't open pipe: $!");
3107 }
3108
3109 my $ex;
3110
3111 # Fork child
3112 $self->handle_sigchld();
3113 defined(my $pid = fork()) or die("Can't fork: $!");
3114 if ($pid) {
3115 eval {
3116 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
3117 $client->login($setup->{user}, $setup->{passwd});
3118
3119 for (my $i = 0; $i < 10; $i++) {
3120 my $conn = $client->mlsd_raw($test_dir);
3121 unless ($conn) {
3122 die("Failed to MLSD: " . $client->response_code() . " " .
3123 $client->response_msg());
3124 }
3125
3126 my $buf;
3127 my $tmp;
3128 while ($conn->read($tmp, 16382, 25)) {
3129 $buf .= $tmp;
3130 $tmp = '';
3131 }
3132 eval { $conn->close() };
3133
3134 if ($ENV{TEST_VERBOSE}) {
3135 print STDERR "buf:\n$buf\n";
3136 }
3137
3138 # We have to be careful of the fact that readdir returns directory
3139 # entries in an unordered fashion.
3140 my $res = {};
3141 my $lines = [split(/\r\n/, $buf)];
3142 foreach my $line (@$lines) {
3143 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
3144 $res->{$1} = 1;
3145 }
3146 }
3147
3148 my $ok = 1;
3149 my $mismatch;
3150 foreach my $name (keys(%$res)) {
3151 unless (defined($expected->{$name})) {
3152 $mismatch = $name;
3153 $ok = 0;
3154 last;
3155 }
3156 }
3157
3158 unless ($ok) {
3159 die("Unexpected name '$mismatch' appeared in MLSD data")
3160 }
3161 }
3162
3163 $client->quit();
3164 };
3165
3166 if ($@) {
3167 $ex = $@;
3168 }
3169
3170 $wfh->print("done\n");
3171 $wfh->flush();
3172
3173 } else {
3174 eval { server_wait($setup->{config_file}, $rfh) };
3175 if ($@) {
3176 warn($@);
3177 exit 1;
3178 }
3179
3180 exit 0;
3181 }
3182
3183 # Stop server
3184 server_stop($setup->{pid_file});
3185 $self->assert_child_ok($pid);
3186
3187 test_cleanup($setup->{log_file}, $ex);
3188 }
3189
3190 sub mlsd_symlink_rel_path_chrooted_bug4322 {
3191 my $self = shift;
3192 my $tmpdir = $self->{tmpdir};
3193 my $setup = test_setup($tmpdir, 'cmds');
3194
3195 my $dst_path = 'domains/test.oxilion.nl/public_html';
3196 my $dst_dir = File::Spec->rel2abs("$tmpdir/$dst_path");
3197 mkpath($dst_dir);
3198
3199 my $cwd = getcwd();
3200 unless (chdir("$tmpdir")) {
3201 die("Can't chdir to $tmpdir: $!");
3202 }
3203
3204 unless (symlink("./$dst_path", 'public_html')) {
3205 die("Can't symlink 'public_html' to './$dst_path': $!");
3206 }
3207
3208 unless (symlink("$dst_path", 'public_html2')) {
3209 die("Can't symlink 'public_html2' to '$dst_path': $!");
3210 }
3211
3212 unless (chdir($cwd)) {
3213 die("Can't chdir to $cwd: $!");
3214 }
3215
3216 if ($< == 0) {
3217 unless (chmod(0755, $dst_dir)) {
3218 die("Can't set perms on $dst_dir to 0755: $!");
3219 }
3220
3221 unless (chown($setup->{uid}, $setup->{gid}, $dst_dir)) {
3222 die("Can't set owner of $dst_dir to $setup->{uid}/$setup->{gid}: $!");
3223 }
3224 }
3225
3226 my $config = {
3227 PidFile => $setup->{pid_file},
3228 ScoreboardFile => $setup->{scoreboard_file},
3229 SystemLog => $setup->{log_file},
3230
3231 AuthUserFile => $setup->{auth_user_file},
3232 AuthGroupFile => $setup->{auth_group_file},
3233 AuthOrder => 'mod_auth_file.c',
3234
3235 ShowSymlinks => 'on',
3236 DefaultRoot => '~',
3237
3238 IfModules => {
3239 'mod_delay.c' => {
3240 DelayEngine => 'off',
3241 },
3242 },
3243 };
3244
3245 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3246 $config);
3247
3248 # Open pipes, for use between the parent and child processes. Specifically,
3249 # the child will indicate when it's done with its test by writing a message
3250 # to the parent.
3251 my ($rfh, $wfh);
3252 unless (pipe($rfh, $wfh)) {
3253 die("Can't open pipe: $!");
3254 }
3255
3256 my $ex;
3257
3258 # Fork child
3259 $self->handle_sigchld();
3260 defined(my $pid = fork()) or die("Can't fork: $!");
3261 if ($pid) {
3262 eval {
3263 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3264 $client->login($setup->{user}, $setup->{passwd});
3265
3266 my $conn = $client->mlsd_raw();
3267 unless ($conn) {
3268 die("MLSD failed: " . $client->response_code() . " " .
3269 $client->response_msg());
3270 }
3271
3272 my $buf;
3273 $conn->read($buf, 8192, 30);
3274 eval { $conn->close() };
3275 $client->quit();
3276
3277 if ($ENV{TEST_VERBOSE}) {
3278 print STDERR "# MLSD:\n$buf\n";
3279 }
3280
3281 my $res = {};
3282 my $lines = [split(/(\r)?\n/, $buf)];
3283
3284 foreach my $line (@$lines) {
3285 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
3286 $res->{$3} = { type => $1, unique => $2 };
3287 }
3288 }
3289
3290 my $count = scalar(keys(%$res));
3291 my $expected = 11;
3292 unless ($count == $expected) {
3293 die("MLSD returned wrong number of entries (expected $expected, got $count)");
3294 }
3295
3296 # public_html and public_html2 are symlinks to
3297 # domains/test.oxilion.nl/public_html. According to RFC3659, the unique
3298 # fact for both of these should thus be the same, since they are the same
3299 # underlying object.
3300
3301 $expected = 'OS.unix=symlink';
3302 my $got = $res->{'public_html'}->{type};
3303 $self->assert(qr/$expected/i, $got,
3304 "Expected type fact '$expected', got '$got'");
3305
3306 $got = $res->{'public_html2'}->{type};
3307 $self->assert(qr/$expected/i, $got,
3308 "Expected type fact '$expected', got '$got'");
3309 };
3310 if ($@) {
3311 $ex = $@;
3312 }
3313
3314 $wfh->print("done\n");
3315 $wfh->flush();
3316
3317 } else {
3318 eval { server_wait($setup->{config_file}, $rfh) };
3319 if ($@) {
3320 warn($@);
3321 exit 1;
3322 }
3323
3324 exit 0;
3325 }
3326
3327 # Stop server
3328 server_stop($setup->{pid_file});
3329 $self->assert_child_ok($pid);
3330
3331 test_cleanup($setup->{log_file}, $ex);
3332 }
3333
3334 sub mlsd_symlink_rel_path_subdir_chrooted_bug4322 {
3335 my $self = shift;
3336 my $tmpdir = $self->{tmpdir};
3337 my $setup = test_setup($tmpdir, 'cmds');
3338
3339 my $dst_path = 'domains/test.oxilion.nl/public_html';
3340 my $dst_dir = File::Spec->rel2abs("$tmpdir/test.d/$dst_path");
3341 mkpath($dst_dir);
3342
3343 my $cwd = getcwd();
3344 unless (chdir("$tmpdir/test.d")) {
3345 die("Can't chdir to $tmpdir/test.d: $!");
3346 }
3347
3348 unless (symlink("./$dst_path", 'public_html')) {
3349 die("Can't symlink 'public_html' to './$dst_path': $!");
3350 }
3351
3352 unless (symlink("$dst_path", 'public_html2')) {
3353 die("Can't symlink 'public_html2' to '$dst_path': $!");
3354 }
3355
3356 unless (chdir($cwd)) {
3357 die("Can't chdir to $cwd: $!");
3358 }
3359
3360 if ($< == 0) {
3361 unless (chmod(0755, $dst_dir)) {
3362 die("Can't set perms on $dst_dir to 0755: $!");
3363 }
3364
3365 unless (chown($setup->{uid}, $setup->{gid}, $dst_dir)) {
3366 die("Can't set owner of $dst_dir to $setup->{uid}/$setup->{gid}: $!");
3367 }
3368 }
3369
3370 my $config = {
3371 PidFile => $setup->{pid_file},
3372 ScoreboardFile => $setup->{scoreboard_file},
3373 SystemLog => $setup->{log_file},
3374
3375 AuthUserFile => $setup->{auth_user_file},
3376 AuthGroupFile => $setup->{auth_group_file},
3377 AuthOrder => 'mod_auth_file.c',
3378
3379 ShowSymlinks => 'on',
3380 DefaultRoot => '~',
3381
3382 IfModules => {
3383 'mod_delay.c' => {
3384 DelayEngine => 'off',
3385 },
3386 },
3387 };
3388
3389 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3390 $config);
3391
3392 # Open pipes, for use between the parent and child processes. Specifically,
3393 # the child will indicate when it's done with its test by writing a message
3394 # to the parent.
3395 my ($rfh, $wfh);
3396 unless (pipe($rfh, $wfh)) {
3397 die("Can't open pipe: $!");
3398 }
3399
3400 my $ex;
3401
3402 # Fork child
3403 $self->handle_sigchld();
3404 defined(my $pid = fork()) or die("Can't fork: $!");
3405 if ($pid) {
3406 eval {
3407 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3408 $client->login($setup->{user}, $setup->{passwd});
3409
3410 my $conn = $client->mlsd_raw('test.d');
3411 unless ($conn) {
3412 die("MLSD test.d failed: " . $client->response_code() . " " .
3413 $client->response_msg());
3414 }
3415
3416 my $buf;
3417 $conn->read($buf, 8192, 30);
3418 eval { $conn->close() };
3419 $client->quit();
3420
3421 if ($ENV{TEST_VERBOSE}) {
3422 print STDERR "# MLSD:\n$buf\n";
3423 }
3424
3425 my $res = {};
3426 my $lines = [split(/(\r)?\n/, $buf)];
3427
3428 foreach my $line (@$lines) {
3429 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
3430 $res->{$3} = { type => $1, unique => $2 };
3431 }
3432 }
3433
3434 my $count = scalar(keys(%$res));
3435 my $expected = 5;
3436 unless ($count == $expected) {
3437 die("MLSD returned wrong number of entries (expected $expected, got $count)");
3438 }
3439
3440 # public_html and public_html2 are symlinks to
3441 # domains/test.oxilion.nl/public_html. According to RFC3659, the unique
3442 # fact for both of these should thus be the same, since they are the same
3443 # underlying object.
3444
3445 $expected = 'OS.unix=symlink';
3446 my $got = $res->{'public_html'}->{type};
3447 $self->assert(qr/$expected/i, $got,
3448 "Expected type fact '$expected', got '$got'");
3449
3450 $got = $res->{'public_html2'}->{type};
3451 $self->assert(qr/$expected/i, $got,
3452 "Expected type fact '$expected', got '$got'");
3453 };
3454 if ($@) {
3455 $ex = $@;
3456 }
3457
3458 $wfh->print("done\n");
3459 $wfh->flush();
3460
3461 } else {
3462 eval { server_wait($setup->{config_file}, $rfh) };
3463 if ($@) {
3464 warn($@);
3465 exit 1;
3466 }
3467
3468 exit 0;
3469 }
3470
3471 # Stop server
3472 server_stop($setup->{pid_file});
3473 $self->assert_child_ok($pid);
3474
3475 test_cleanup($setup->{log_file}, $ex);
3476 }
3477
3478 sub mlsd_symlink_rel_path_subdir_cwd_chrooted_bug4322 {
3479 my $self = shift;
3480 my $tmpdir = $self->{tmpdir};
3481 my $setup = test_setup($tmpdir, 'cmds');
3482
3483 my $dst_path = 'domains/test.oxilion.nl/public_html';
3484 my $dst_dir = File::Spec->rel2abs("$tmpdir/test.d/$dst_path");
3485 mkpath($dst_dir);
3486
3487 my $cwd = getcwd();
3488 unless (chdir("$tmpdir/test.d")) {
3489 die("Can't chdir to $tmpdir/test.d: $!");
3490 }
3491
3492 unless (symlink("./$dst_path", 'public_html')) {
3493 die("Can't symlink 'public_html' to './$dst_path': $!");
3494 }
3495
3496 unless (symlink("$dst_path", 'public_html2')) {
3497 die("Can't symlink 'public_html2' to '$dst_path': $!");
3498 }
3499
3500 unless (chdir($cwd)) {
3501 die("Can't chdir to $cwd: $!");
3502 }
3503
3504 if ($< == 0) {
3505 unless (chmod(0755, $dst_dir)) {
3506 die("Can't set perms on $dst_dir to 0755: $!");
3507 }
3508
3509 unless (chown($setup->{uid}, $setup->{gid}, $dst_dir)) {
3510 die("Can't set owner of $dst_dir to $setup->{uid}/$setup->{gid}: $!");
3511 }
3512 }
3513
3514 my $config = {
3515 PidFile => $setup->{pid_file},
3516 ScoreboardFile => $setup->{scoreboard_file},
3517 SystemLog => $setup->{log_file},
3518
3519 AuthUserFile => $setup->{auth_user_file},
3520 AuthGroupFile => $setup->{auth_group_file},
3521 AuthOrder => 'mod_auth_file.c',
3522
3523 ShowSymlinks => 'on',
3524 DefaultRoot => '~',
3525
3526 IfModules => {
3527 'mod_delay.c' => {
3528 DelayEngine => 'off',
3529 },
3530 },
3531 };
3532
3533 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3534 $config);
3535
3536 # Open pipes, for use between the parent and child processes. Specifically,
3537 # the child will indicate when it's done with its test by writing a message
3538 # to the parent.
3539 my ($rfh, $wfh);
3540 unless (pipe($rfh, $wfh)) {
3541 die("Can't open pipe: $!");
3542 }
3543
3544 my $ex;
3545
3546 # Fork child
3547 $self->handle_sigchld();
3548 defined(my $pid = fork()) or die("Can't fork: $!");
3549 if ($pid) {
3550 eval {
3551 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3552 $client->login($setup->{user}, $setup->{passwd});
3553 $client->cwd('test.d');
3554
3555 my $conn = $client->mlsd_raw();
3556 unless ($conn) {
3557 die("MLSD failed: " . $client->response_code() . " " .
3558 $client->response_msg());
3559 }
3560
3561 my $buf;
3562 $conn->read($buf, 8192, 30);
3563 eval { $conn->close() };
3564 $client->quit();
3565
3566 if ($ENV{TEST_VERBOSE}) {
3567 print STDERR "# MLSD:\n$buf\n";
3568 }
3569
3570 my $res = {};
3571 my $lines = [split(/(\r)?\n/, $buf)];
3572
3573 foreach my $line (@$lines) {
3574 if ($line =~ /^modify=\S+;perm=\S+;type=(\S+);unique=(\S+);UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; (.*?)$/) {
3575 $res->{$3} = { type => $1, unique => $2 };
3576 }
3577 }
3578
3579 my $count = scalar(keys(%$res));
3580 my $expected = 5;
3581 unless ($count == $expected) {
3582 die("MLSD returned wrong number of entries (expected $expected, got $count)");
3583 }
3584
3585 # public_html and public_html2 are symlinks to
3586 # domains/test.oxilion.nl/public_html. According to RFC3659, the unique
3587 # fact for both of these should thus be the same, since they are the same
3588 # underlying object.
3589
3590 $expected = 'OS.unix=symlink';
3591 my $got = $res->{'public_html'}->{type};
3592 $self->assert(qr/$expected/i, $got,
3593 "Expected type fact '$expected', got '$got'");
3594
3595 $got = $res->{'public_html2'}->{type};
3596 $self->assert(qr/$expected/i, $got,
3597 "Expected type fact '$expected', got '$got'");
3598 };
3599 if ($@) {
3600 $ex = $@;
3601 }
3602
3603 $wfh->print("done\n");
3604 $wfh->flush();
3605
3606 } else {
3607 eval { server_wait($setup->{config_file}, $rfh) };
3608 if ($@) {
3609 warn($@);
3610 exit 1;
3611 }
3612
3613 exit 0;
3614 }
3615
3616 # Stop server
3617 server_stop($setup->{pid_file});
3618 $self->assert_child_ok($pid);
3619
3620 test_cleanup($setup->{log_file}, $ex);
3621 }
3622
3623 1;