Debian Codegraph @

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

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