Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::FactsOptions;
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 factsoptions_use_slink_mlsd_rel_symlinked_file => {
25 order => ++$order,
26 test_class => [qw(forking)],
27 },
28
29 factsoptions_use_slink_mlsd_rel_symlinked_dir => {
30 order => ++$order,
31 test_class => [qw(forking)],
32 },
33
34 factsoptions_use_slink_mlst_rel_symlinked_file => {
35 order => ++$order,
36 test_class => [qw(forking)],
37 },
38
39 factsoptions_use_slink_mlst_rel_symlinked_file_chrooted => {
40 order => ++$order,
41 test_class => [qw(forking rootprivs)],
42 },
43
44 factsoptions_use_slink_mlst_rel_symlinked_dir => {
45 order => ++$order,
46 test_class => [qw(forking)],
47 },
48
49 factsoptions_use_slink_mlst_rel_symlinked_dir_chrooted => {
50 order => ++$order,
51 test_class => [qw(forking rootprivs)],
52 },
53
54 };
55
56 sub new {
57 return shift()->SUPER::new(@_);
58 }
59
60 sub list_tests {
61 return testsuite_get_runnable_tests($TESTS);
62 }
63
64 sub factsoptions_use_slink_mlsd_rel_symlinked_file {
65 my $self = shift;
66 my $tmpdir = $self->{tmpdir};
67 my $setup = test_setup($tmpdir, 'config');
68
69 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
70 mkpath($foo_dir);
71
72 my $test_file = File::Spec->rel2abs("$tmpdir/foo/test.txt");
73 if (open(my $fh, "> $test_file")) {
74 print $fh "Hello, World!\n";
75 unless (close($fh)) {
76 die("Can't write $test_file: $!");
77 }
78
79 } else {
80 die("Can't open $test_file: $!");
81 }
82
83 # Change to the 'foo' directory in order to create a relative path in the
84 # symlink we need
85
86 my $cwd = getcwd();
87 unless (chdir("$foo_dir")) {
88 die("Can't chdir to $foo_dir: $!");
89 }
90
91 unless (symlink('test.txt', 'test.lnk')) {
92 die("Can't symlink 'test.txt' to 'test.lnk': $!");
93 }
94
95 unless (chdir($cwd)) {
96 die("Can't chdir to $cwd: $!");
97 }
98
99 # Make sure that, if we're running as root, that the home directory has
100 # permissions/privs set for the account we create
101 if ($< == 0) {
102 unless (chmod(0755, $foo_dir)) {
103 die("Can't set perms on $foo_dir to 0755: $!");
104 }
105
106 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
107 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
108 }
109 }
110
111 my $config = {
112 PidFile => $setup->{pid_file},
113 ScoreboardFile => $setup->{scoreboard_file},
114 SystemLog => $setup->{log_file},
115
116 AuthUserFile => $setup->{auth_user_file},
117 AuthGroupFile => $setup->{auth_group_file},
118 AuthOrder => 'mod_auth_file.c',
119
120 ShowSymlinks => 'on',
121 FactsOptions => 'UseSlink',
122
123 IfModules => {
124 'mod_delay.c' => {
125 DelayEngine => 'off',
126 },
127 },
128 };
129
130 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
131 $config);
132
133 # Open pipes, for use between the parent and child processes. Specifically,
134 # the child will indicate when it's done with its test by writing a message
135 # to the parent.
136 my ($rfh, $wfh);
137 unless (pipe($rfh, $wfh)) {
138 die("Can't open pipe: $!");
139 }
140
141 my $ex;
142
143 # Fork child
144 $self->handle_sigchld();
145 defined(my $pid = fork()) or die("Can't fork: $!");
146 if ($pid) {
147 eval {
148 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
149 $client->login($setup->{user}, $setup->{passwd});
150
151 my $conn = $client->mlsd_raw('foo');
152 unless ($conn) {
153 die("MLSD failed: " . $client->response_code() . " " .
154 $client->response_msg());
155 }
156
157 my $buf;
158 $conn->read($buf, 8192, 25);
159 eval { $conn->close() };
160
161 my $res = {};
162 my $lines = [split(/\n/, $buf)];
163 foreach my $line (@$lines) {
164 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+; (.*?)$/) {
165 $res->{$3} = { type => $1, unique => $2 };
166 }
167 }
168
169 my $count = scalar(keys(%$res));
170 unless ($count == 4) {
171 die("MLSD returned wrong number of entries (expected 4, got $count)");
172 }
173
174 # test.lnk is a symlink to test.txt. According to RFC3659, the unique
175 # fact for both of these should thus be the same, since they are the
176 # same underlying object.
177
178 my $expected = $res->{'test.txt'}->{unique};
179 my $got = $res->{'test.lnk'}->{unique};
180 $self->assert($expected eq $got,
181 test_msg("Expected '$expected', got '$got'"));
182
183 # Since ShowSymlinks is on, the type for test.lnk should indicate that
184 # it's a symlink. And since the UseSlink FactOption is used, the
185 # type should include the target path.
186 $expected = 'OS.unix=slink:(.*)?';
187 $got = $res->{'test.lnk'}->{type};
188 $self->assert(qr/$expected/i, $got,
189 test_msg("Expected '$expected', got '$got'"));
190
191 $client->quit();
192 };
193 if ($@) {
194 $ex = $@;
195 }
196
197 $wfh->print("done\n");
198 $wfh->flush();
199
200 } else {
201 eval { server_wait($setup->{config_file}, $rfh) };
202 if ($@) {
203 warn($@);
204 exit 1;
205 }
206
207 exit 0;
208 }
209
210 # Stop server
211 server_stop($setup->{pid_file});
212 $self->assert_child_ok($pid);
213
214 test_cleanup($setup->{log_file}, $ex);
215 }
216
217 sub factsoptions_use_slink_mlsd_rel_symlinked_dir {
218 my $self = shift;
219 my $tmpdir = $self->{tmpdir};
220 my $setup = test_setup($tmpdir, 'config');
221
222 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
223 mkpath($foo_dir);
224
225 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/test.d");
226 mkpath($test_dir);
227
228 # Change to the 'foo' directory in order to create a relative path in the
229 # symlink we need
230
231 my $cwd = getcwd();
232 unless (chdir("$foo_dir")) {
233 die("Can't chdir to $foo_dir: $!");
234 }
235
236 unless (symlink('test.d', 'test.lnk')) {
237 die("Can't symlink 'test.d' to 'test.lnk': $!");
238 }
239
240 unless (chdir($cwd)) {
241 die("Can't chdir to $cwd: $!");
242 }
243
244 # Make sure that, if we're running as root, that the home directory has
245 # permissions/privs set for the account we create
246 if ($< == 0) {
247 unless (chmod(0755, $foo_dir)) {
248 die("Can't set perms on $foo_dir to 0755: $!");
249 }
250
251 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
252 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
253 }
254 }
255
256 my $config = {
257 PidFile => $setup->{pid_file},
258 ScoreboardFile => $setup->{scoreboard_file},
259 SystemLog => $setup->{log_file},
260
261 AuthUserFile => $setup->{auth_user_file},
262 AuthGroupFile => $setup->{auth_group_file},
263 AuthOrder => 'mod_auth_file.c',
264
265 ShowSymlinks => 'on',
266 FactsOptions => 'UseSlink',
267
268 IfModules => {
269 'mod_delay.c' => {
270 DelayEngine => 'off',
271 },
272 },
273 };
274
275 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
276 $config);
277
278 # Open pipes, for use between the parent and child processes. Specifically,
279 # the child will indicate when it's done with its test by writing a message
280 # to the parent.
281 my ($rfh, $wfh);
282 unless (pipe($rfh, $wfh)) {
283 die("Can't open pipe: $!");
284 }
285
286 my $ex;
287
288 # Fork child
289 $self->handle_sigchld();
290 defined(my $pid = fork()) or die("Can't fork: $!");
291 if ($pid) {
292 eval {
293 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
294 $client->login($setup->{user}, $setup->{passwd});
295
296 my $conn = $client->mlsd_raw('foo');
297 unless ($conn) {
298 die("MLSD failed: " . $client->response_code() . " " .
299 $client->response_msg());
300 }
301
302 my $buf;
303 $conn->read($buf, 8192, 25);
304 eval { $conn->close() };
305
306 my $res = {};
307 my $lines = [split(/\n/, $buf)];
308 foreach my $line (@$lines) {
309 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+; (.*?)$/) {
310 $res->{$3} = { type => $1, unique => $2 };
311 }
312 }
313
314 my $count = scalar(keys(%$res));
315 unless ($count == 4) {
316 die("MLSD returned wrong number of entries (expected 4, got $count)");
317 }
318
319 # test.lnk is a symlink to test.d. According to RFC3659, the unique
320 # fact for both of these should thus be the same, since they are the
321 # same underlying object.
322
323 my $expected = $res->{'test.d'}->{unique};
324 my $got = $res->{'test.lnk'}->{unique};
325 $self->assert($expected eq $got,
326 test_msg("Expected '$expected', got '$got'"));
327
328 # Since ShowSymlinks is on, the type for test.lnk should indicate that
329 # it's a symlink. And since the UseSlink FactOption is used, the
330 # type should include the target path.
331 $expected = 'OS.unix=slink:(.*)?';
332 $got = $res->{'test.lnk'}->{type};
333 $self->assert(qr/$expected/i, $got,
334 test_msg("Expected '$expected', got '$got'"));
335
336 $client->quit();
337 };
338 if ($@) {
339 $ex = $@;
340 }
341
342 $wfh->print("done\n");
343 $wfh->flush();
344
345 } else {
346 eval { server_wait($setup->{config_file}, $rfh) };
347 if ($@) {
348 warn($@);
349 exit 1;
350 }
351
352 exit 0;
353 }
354
355 # Stop server
356 server_stop($setup->{pid_file});
357 $self->assert_child_ok($pid);
358
359 test_cleanup($setup->{log_file}, $ex);
360 }
361
362 sub factsoptions_use_slink_mlst_rel_symlinked_file {
363 my $self = shift;
364 my $tmpdir = $self->{tmpdir};
365 my $setup = test_setup($tmpdir, 'config');
366
367 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
368 mkpath($foo_dir);
369
370 my $test_file = File::Spec->rel2abs("$tmpdir/foo/test.txt");
371 if (open(my $fh, "> $test_file")) {
372 print $fh "Hello, World!\n";
373 unless (close($fh)) {
374 die("Can't write $test_file: $!");
375 }
376
377 } else {
378 die("Can't open $test_file: $!");
379 }
380
381 my $test_symlink = File::Spec->rel2abs("$tmpdir/foo/test.lnk");
382
383 # Change to the 'foo' directory in order to create a relative path in the
384 # symlink we need
385
386 my $cwd = getcwd();
387 unless (chdir("$foo_dir")) {
388 die("Can't chdir to $foo_dir: $!");
389 }
390
391 unless (symlink('test.txt', 'test.lnk')) {
392 die("Can't symlink 'test.txt' to 'test.lnk': $!");
393 }
394
395 unless (chdir($cwd)) {
396 die("Can't chdir to $cwd: $!");
397 }
398
399 # Make sure that, if we're running as root, that the home directory has
400 # permissions/privs set for the account we create
401 if ($< == 0) {
402 unless (chmod(0755, $foo_dir)) {
403 die("Can't set perms on $foo_dir to 0755: $!");
404 }
405
406 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
407 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
408 }
409 }
410
411 my $config = {
412 PidFile => $setup->{pid_file},
413 ScoreboardFile => $setup->{scoreboard_file},
414 SystemLog => $setup->{log_file},
415
416 AuthUserFile => $setup->{auth_user_file},
417 AuthGroupFile => $setup->{auth_group_file},
418 AuthOrder => 'mod_auth_file.c',
419
420 ShowSymlinks => 'on',
421 FactsOptions => 'UseSlink',
422
423 IfModules => {
424 'mod_delay.c' => {
425 DelayEngine => 'off',
426 },
427 },
428 };
429
430 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
431 $config);
432
433 # Open pipes, for use between the parent and child processes. Specifically,
434 # the child will indicate when it's done with its test by writing a message
435 # to the parent.
436 my ($rfh, $wfh);
437 unless (pipe($rfh, $wfh)) {
438 die("Can't open pipe: $!");
439 }
440
441 my $ex;
442
443 # Fork child
444 $self->handle_sigchld();
445 defined(my $pid = fork()) or die("Can't fork: $!");
446 if ($pid) {
447 eval {
448 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
449 $client->login($setup->{user}, $setup->{passwd});
450
451 my ($resp_code, $resp_msg) = $client->mlst('foo/test.lnk');
452
453 my $expected = 250;
454 $self->assert($expected == $resp_code,
455 test_msg("Expected response code $expected, got $resp_code"));
456
457 if ($^O eq 'darwin') {
458 # MacOSX-specific hack, due to how it handles tmp files
459 $test_symlink = ('/private' . $test_symlink);
460 }
461
462 $expected = 'modify=\d+;perm=adfr(w)?;size=\d+;type=OS\.unix=slink:(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; ' . $test_symlink . '$';
463 $self->assert(qr/$expected/, $resp_msg,
464 test_msg("Expected response message '$expected', got '$resp_msg'"));
465
466 $client->quit();
467 };
468 if ($@) {
469 $ex = $@;
470 }
471
472 $wfh->print("done\n");
473 $wfh->flush();
474
475 } else {
476 eval { server_wait($setup->{config_file}, $rfh) };
477 if ($@) {
478 warn($@);
479 exit 1;
480 }
481
482 exit 0;
483 }
484
485 # Stop server
486 server_stop($setup->{pid_file});
487 $self->assert_child_ok($pid);
488
489 test_cleanup($setup->{log_file}, $ex);
490 }
491
492 sub factsoptions_use_slink_mlst_rel_symlinked_file_chrooted {
493 my $self = shift;
494 my $tmpdir = $self->{tmpdir};
495 my $setup = test_setup($tmpdir, 'config');
496
497 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
498 mkpath($foo_dir);
499
500 my $test_file = File::Spec->rel2abs("$tmpdir/foo/test.txt");
501 if (open(my $fh, "> $test_file")) {
502 print $fh "Hello, World!\n";
503 unless (close($fh)) {
504 die("Can't write $test_file: $!");
505 }
506
507 } else {
508 die("Can't open $test_file: $!");
509 }
510
511 # Since we're chrooting the session, we don't expect to see the real
512 # absolute path.
513 my $test_symlink = "/foo/test.lnk";
514
515 # Change to the 'foo' directory in order to create a relative path in the
516 # symlink we need
517
518 my $cwd = getcwd();
519 unless (chdir("$foo_dir")) {
520 die("Can't chdir to $foo_dir: $!");
521 }
522
523 unless (symlink('test.txt', 'test.lnk')) {
524 die("Can't symlink 'test.txt' to 'test.lnk': $!");
525 }
526
527 unless (chdir($cwd)) {
528 die("Can't chdir to $cwd: $!");
529 }
530
531 # Make sure that, if we're running as root, that the home directory has
532 # permissions/privs set for the account we create
533 if ($< == 0) {
534 unless (chmod(0755, $foo_dir)) {
535 die("Can't set perms on $foo_dir to 0755: $!");
536 }
537
538 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
539 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
540 }
541 }
542
543 my $config = {
544 PidFile => $setup->{pid_file},
545 ScoreboardFile => $setup->{scoreboard_file},
546 SystemLog => $setup->{log_file},
547
548 AuthUserFile => $setup->{auth_user_file},
549 AuthGroupFile => $setup->{auth_group_file},
550 AuthOrder => 'mod_auth_file.c',
551
552 ShowSymlinks => 'on',
553 FactsOptions => 'UseSlink',
554
555 DefaultRoot => '~',
556
557 IfModules => {
558 'mod_delay.c' => {
559 DelayEngine => 'off',
560 },
561 },
562 };
563
564 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
565 $config);
566
567 # Open pipes, for use between the parent and child processes. Specifically,
568 # the child will indicate when it's done with its test by writing a message
569 # to the parent.
570 my ($rfh, $wfh);
571 unless (pipe($rfh, $wfh)) {
572 die("Can't open pipe: $!");
573 }
574
575 my $ex;
576
577 # Fork child
578 $self->handle_sigchld();
579 defined(my $pid = fork()) or die("Can't fork: $!");
580 if ($pid) {
581 eval {
582 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
583 $client->login($setup->{user}, $setup->{passwd});
584
585 my ($resp_code, $resp_msg) = $client->mlst('foo/test.lnk');
586
587 my $expected = 250;
588 $self->assert($expected == $resp_code,
589 test_msg("Expected response code $expected, got $resp_code"));
590
591 $expected = 'modify=\d+;perm=adfr(w)?;size=\d+;type=OS\.unix=slink:(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; ' . $test_symlink . '$';
592 $self->assert(qr/$expected/, $resp_msg,
593 test_msg("Expected response message '$expected', got '$resp_msg'"));
594
595 $client->quit();
596 };
597 if ($@) {
598 $ex = $@;
599 }
600
601 $wfh->print("done\n");
602 $wfh->flush();
603
604 } else {
605 eval { server_wait($setup->{config_file}, $rfh) };
606 if ($@) {
607 warn($@);
608 exit 1;
609 }
610
611 exit 0;
612 }
613
614 # Stop server
615 server_stop($setup->{pid_file});
616 $self->assert_child_ok($pid);
617
618 test_cleanup($setup->{log_file}, $ex);
619 }
620
621 sub factsoptions_use_slink_mlst_rel_symlinked_dir {
622 my $self = shift;
623 my $tmpdir = $self->{tmpdir};
624 my $setup = test_setup($tmpdir, 'config');
625
626 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
627 mkpath($foo_dir);
628
629 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/test.d");
630 mkpath($test_dir);
631
632 my $test_symlink = File::Spec->rel2abs("$tmpdir/foo/test.lnk");
633
634 # Change to the 'foo' directory in order to create a relative path in the
635 # symlink we need
636
637 my $cwd = getcwd();
638 unless (chdir("$foo_dir")) {
639 die("Can't chdir to $foo_dir: $!");
640 }
641
642 unless (symlink('test.d', 'test.lnk')) {
643 die("Can't symlink 'test.d' to 'test.lnk': $!");
644 }
645
646 unless (chdir($cwd)) {
647 die("Can't chdir to $cwd: $!");
648 }
649
650 # Make sure that, if we're running as root, that the home directory has
651 # permissions/privs set for the account we create
652 if ($< == 0) {
653 unless (chmod(0755, $foo_dir)) {
654 die("Can't set perms on $foo_dir to 0755: $!");
655 }
656
657 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
658 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
659 }
660 }
661
662 my $config = {
663 PidFile => $setup->{pid_file},
664 ScoreboardFile => $setup->{scoreboard_file},
665 SystemLog => $setup->{log_file},
666
667 AuthUserFile => $setup->{auth_user_file},
668 AuthGroupFile => $setup->{auth_group_file},
669 AuthOrder => 'mod_auth_file.c',
670
671 ShowSymlinks => 'on',
672 FactsOptions => 'UseSlink',
673
674 IfModules => {
675 'mod_delay.c' => {
676 DelayEngine => 'off',
677 },
678 },
679 };
680
681 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
682 $config);
683
684 # Open pipes, for use between the parent and child processes. Specifically,
685 # the child will indicate when it's done with its test by writing a message
686 # to the parent.
687 my ($rfh, $wfh);
688 unless (pipe($rfh, $wfh)) {
689 die("Can't open pipe: $!");
690 }
691
692 my $ex;
693
694 # Fork child
695 $self->handle_sigchld();
696 defined(my $pid = fork()) or die("Can't fork: $!");
697 if ($pid) {
698 eval {
699 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
700 $client->login($setup->{user}, $setup->{passwd});
701
702 my ($resp_code, $resp_msg) = $client->mlst('foo/test.lnk');
703
704 my $expected = 250;
705 $self->assert($expected == $resp_code,
706 test_msg("Expected response code $expected, got $resp_code"));
707
708 if ($^O eq 'darwin') {
709 # MacOSX-specific hack, due to how it handles tmp files
710 $test_symlink = ('/private' . $test_symlink);
711 }
712
713 $expected = 'modify=\d+;perm=adfr(w)?;size=\d+;type=OS\.unix=slink:(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; ' . $test_symlink . '$';
714 $self->assert(qr/$expected/, $resp_msg,
715 test_msg("Expected response message '$expected', got '$resp_msg'"));
716
717 $client->quit();
718 };
719 if ($@) {
720 $ex = $@;
721 }
722
723 $wfh->print("done\n");
724 $wfh->flush();
725
726 } else {
727 eval { server_wait($setup->{config_file}, $rfh) };
728 if ($@) {
729 warn($@);
730 exit 1;
731 }
732
733 exit 0;
734 }
735
736 # Stop server
737 server_stop($setup->{pid_file});
738 $self->assert_child_ok($pid);
739
740 test_cleanup($setup->{log_file}, $ex);
741 }
742
743 sub factsoptions_use_slink_mlst_rel_symlinked_dir_chrooted {
744 my $self = shift;
745 my $tmpdir = $self->{tmpdir};
746 my $setup = test_setup($tmpdir, 'config');
747
748 my $foo_dir = File::Spec->rel2abs("$tmpdir/foo");
749 mkpath($foo_dir);
750
751 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/test.d");
752 mkpath($test_dir);
753
754 # Since we're chrooting the session, we don't expect to see the real
755 # absolute path
756 my $test_symlink = "/foo/test.lnk";
757
758 # Change to the 'foo' directory in order to create a relative path in the
759 # symlink we need
760
761 my $cwd = getcwd();
762 unless (chdir("$foo_dir")) {
763 die("Can't chdir to $foo_dir: $!");
764 }
765
766 unless (symlink('test.d', 'test.lnk')) {
767 die("Can't symlink 'test.d' to 'test.lnk': $!");
768 }
769
770 unless (chdir($cwd)) {
771 die("Can't chdir to $cwd: $!");
772 }
773
774 # Make sure that, if we're running as root, that the home directory has
775 # permissions/privs set for the account we create
776 if ($< == 0) {
777 unless (chmod(0755, $foo_dir)) {
778 die("Can't set perms on $foo_dir to 0755: $!");
779 }
780
781 unless (chown($setup->{uid}, $setup->{gid}, $foo_dir)) {
782 die("Can't set owner of $foo_dir to $setup->{uid}/$setup->{gid}: $!");
783 }
784 }
785
786 my $config = {
787 PidFile => $setup->{pid_file},
788 ScoreboardFile => $setup->{scoreboard_file},
789 SystemLog => $setup->{log_file},
790
791 AuthUserFile => $setup->{auth_user_file},
792 AuthGroupFile => $setup->{auth_group_file},
793 AuthOrder => 'mod_auth_file.c',
794
795 ShowSymlinks => 'on',
796 FactsOptions => 'UseSlink',
797
798 DefaultRoot => '~',
799
800 IfModules => {
801 'mod_delay.c' => {
802 DelayEngine => 'off',
803 },
804 },
805 };
806
807 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
808 $config);
809
810 # Open pipes, for use between the parent and child processes. Specifically,
811 # the child will indicate when it's done with its test by writing a message
812 # to the parent.
813 my ($rfh, $wfh);
814 unless (pipe($rfh, $wfh)) {
815 die("Can't open pipe: $!");
816 }
817
818 my $ex;
819
820 # Fork child
821 $self->handle_sigchld();
822 defined(my $pid = fork()) or die("Can't fork: $!");
823 if ($pid) {
824 eval {
825 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
826 $client->login($setup->{user}, $setup->{passwd});
827
828 my ($resp_code, $resp_msg) = $client->mlst('foo/test.lnk');
829
830 my $expected = 250;
831 $self->assert($expected == $resp_code,
832 test_msg("Expected response code $expected, got $resp_code"));
833
834 $expected = 'modify=\d+;perm=adfr(w)?;size=\d+;type=OS\.unix=slink:(\S+);unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=\d+;UNIX\.ownername=\S+; ' . $test_symlink . '$';
835 $self->assert(qr/$expected/, $resp_msg,
836 test_msg("Expected response message '$expected', got '$resp_msg'"));
837
838 $client->quit();
839 };
840 if ($@) {
841 $ex = $@;
842 }
843
844 $wfh->print("done\n");
845 $wfh->flush();
846
847 } else {
848 eval { server_wait($setup->{config_file}, $rfh) };
849 if ($@) {
850 warn($@);
851 exit 1;
852 }
853
854 exit 0;
855 }
856
857 # Stop server
858 server_stop($setup->{pid_file});
859 $self->assert_child_ok($pid);
860
861 test_cleanup($setup->{log_file}, $ex);
862 }
863
864 1;