Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::MDTM;
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 mdtm_ok => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 mdtm_abs_symlink => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 mdtm_abs_symlink_chrooted_bug4219 => {
31 order => ++$order,
32 test_class => [qw(bug forking rootprivs)],
33 },
34
35 mdtm_rel_symlink => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 mdtm_rel_symlink_chrooted_bug4219 => {
41 order => ++$order,
42 test_class => [qw(bug forking rootprivs)],
43 },
44
45 mdtm_fails_enoent => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 mdtm_fails_abs_symlink_enoent => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 mdtm_fails_abs_symlink_enoent_chrooted_bug4219 => {
56 order => ++$order,
57 test_class => [qw(bug forking rootprivs)],
58 },
59
60 mdtm_fails_rel_symlink_enoent => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 mdtm_fails_rel_symlink_enoent_chrooted_bug4219 => {
66 order => ++$order,
67 test_class => [qw(bug forking rootprivs)],
68 },
69
70 mdtm_fails_eperm => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 };
76
77 sub new {
78 return shift()->SUPER::new(@_);
79 }
80
81 sub list_tests {
82 return testsuite_get_runnable_tests($TESTS);
83 }
84
85 sub mdtm_ok {
86 my $self = shift;
87 my $tmpdir = $self->{tmpdir};
88 my $setup = test_setup($tmpdir, 'cmds');
89
90 my $test_file = File::Spec->rel2abs("$tmpdir/foo");
91 if (open(my $fh, "> $test_file")) {
92 close($fh);
93
94 } else {
95 die("Can't create $test_file: $!");
96 }
97
98 my $config = {
99 PidFile => $setup->{pid_file},
100 ScoreboardFile => $setup->{scoreboard_file},
101 SystemLog => $setup->{log_file},
102
103 AuthUserFile => $setup->{auth_user_file},
104 AuthGroupFile => $setup->{auth_group_file},
105 AuthOrder => 'mod_auth_file.c',
106
107 IfModules => {
108 'mod_delay.c' => {
109 DelayEngine => 'off',
110 },
111 },
112 };
113
114 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
115 $config);
116
117 # Open pipes, for use between the parent and child processes. Specifically,
118 # the child will indicate when it's done with its test by writing a message
119 # to the parent.
120 my ($rfh, $wfh);
121 unless (pipe($rfh, $wfh)) {
122 die("Can't open pipe: $!");
123 }
124
125 my $ex;
126
127 # Fork child
128 $self->handle_sigchld();
129 defined(my $pid = fork()) or die("Can't fork: $!");
130 if ($pid) {
131 eval {
132 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
133 $client->login($setup->{user}, $setup->{passwd});
134
135 my ($resp_code, $resp_msg) = $client->mdtm($test_file);
136 $client->quit();
137
138 my $expected = 213;
139 $self->assert($expected == $resp_code,
140 test_msg("Expected response code $expected, got $resp_code"));
141
142 $self->assert(qr/\d+/, $resp_msg);
143 };
144
145 if ($@) {
146 $ex = $@;
147 }
148
149 $wfh->print("done\n");
150 $wfh->flush();
151
152 } else {
153 eval { server_wait($setup->{config_file}, $rfh) };
154 if ($@) {
155 warn($@);
156 exit 1;
157 }
158
159 exit 0;
160 }
161
162 # Stop server
163 server_stop($setup->{pid_file});
164 $self->assert_child_ok($pid);
165
166 test_cleanup($setup->{log_file}, $ex);
167 }
168
169 sub mdtm_abs_symlink {
170 my $self = shift;
171 my $tmpdir = $self->{tmpdir};
172 my $setup = test_setup($tmpdir, 'cmds');
173
174 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
175 mkpath($test_dir);
176
177 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
178 if (open(my $fh, "> $test_file")) {
179 close($fh);
180
181 } else {
182 die("Can't create $test_file: $!");
183 }
184
185 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
186
187 my $dst_path = $test_symlink;
188 if ($^O eq 'darwin') {
189 # MacOSX-specific hack
190 $dst_path = '/private' . $dst_path;
191 }
192
193 unless (symlink($test_file, $dst_path)) {
194 die("Can't symlink '$dst_path' to '$test_file': $!");
195 }
196
197 my $config = {
198 PidFile => $setup->{pid_file},
199 ScoreboardFile => $setup->{scoreboard_file},
200 SystemLog => $setup->{log_file},
201
202 AuthUserFile => $setup->{auth_user_file},
203 AuthGroupFile => $setup->{auth_group_file},
204 AuthOrder => 'mod_auth_file.c',
205
206 IfModules => {
207 'mod_delay.c' => {
208 DelayEngine => 'off',
209 },
210 },
211 };
212
213 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
214 $config);
215
216 # Open pipes, for use between the parent and child processes. Specifically,
217 # the child will indicate when it's done with its test by writing a message
218 # to the parent.
219 my ($rfh, $wfh);
220 unless (pipe($rfh, $wfh)) {
221 die("Can't open pipe: $!");
222 }
223
224 my $ex;
225
226 # Fork child
227 $self->handle_sigchld();
228 defined(my $pid = fork()) or die("Can't fork: $!");
229 if ($pid) {
230 eval {
231 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
232 $client->login($setup->{user}, $setup->{passwd});
233
234 my ($resp_code, $resp_msg) = $client->mdtm('test.d/test.lnk');
235 $client->quit();
236
237 my $expected = 213;
238 $self->assert($expected == $resp_code,
239 test_msg("Expected response code $expected, got $resp_code"));
240
241 $self->assert(qr/\d+/, $resp_msg);
242 };
243
244 if ($@) {
245 $ex = $@;
246 }
247
248 $wfh->print("done\n");
249 $wfh->flush();
250
251 } else {
252 eval { server_wait($setup->{config_file}, $rfh) };
253 if ($@) {
254 warn($@);
255 exit 1;
256 }
257
258 exit 0;
259 }
260
261 # Stop server
262 server_stop($setup->{pid_file});
263 $self->assert_child_ok($pid);
264
265 test_cleanup($setup->{log_file}, $ex);
266 }
267
268 sub mdtm_abs_symlink_chrooted_bug4219 {
269 my $self = shift;
270 my $tmpdir = $self->{tmpdir};
271 my $setup = test_setup($tmpdir, 'cmds');
272
273 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
274 mkpath($test_dir);
275
276 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
277 if (open(my $fh, "> $test_file")) {
278 close($fh);
279
280 } else {
281 die("Can't create $test_file: $!");
282 }
283
284 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
285
286 my $dst_path = $test_file;
287 if ($^O eq 'darwin') {
288 # MacOSX-specific hack
289 $dst_path = '/private' . $dst_path;
290 }
291
292 unless (symlink($dst_path, $test_symlink)) {
293 die("Can't symlink '$test_symlink' to '$dst_path': $!");
294 }
295
296 my $config = {
297 PidFile => $setup->{pid_file},
298 ScoreboardFile => $setup->{scoreboard_file},
299 SystemLog => $setup->{log_file},
300 TraceLog => $setup->{log_file},
301 Trace => 'fsio:20',
302
303 AuthUserFile => $setup->{auth_user_file},
304 AuthGroupFile => $setup->{auth_group_file},
305 AuthOrder => 'mod_auth_file.c',
306
307 DefaultRoot => '~',
308
309 IfModules => {
310 'mod_delay.c' => {
311 DelayEngine => 'off',
312 },
313 },
314 };
315
316 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
317 $config);
318
319 # Open pipes, for use between the parent and child processes. Specifically,
320 # the child will indicate when it's done with its test by writing a message
321 # to the parent.
322 my ($rfh, $wfh);
323 unless (pipe($rfh, $wfh)) {
324 die("Can't open pipe: $!");
325 }
326
327 my $ex;
328
329 # Fork child
330 $self->handle_sigchld();
331 defined(my $pid = fork()) or die("Can't fork: $!");
332 if ($pid) {
333 eval {
334 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
335 $client->login($setup->{user}, $setup->{passwd});
336
337 my ($resp_code, $resp_msg) = $client->mdtm('test.d/test.lnk');
338 $client->quit();
339
340 my $expected = 213;
341 $self->assert($expected == $resp_code,
342 test_msg("Expected response code $expected, got $resp_code"));
343
344 $self->assert(qr/\d+/, $resp_msg);
345 };
346
347 if ($@) {
348 $ex = $@;
349 }
350
351 $wfh->print("done\n");
352 $wfh->flush();
353
354 } else {
355 eval { server_wait($setup->{config_file}, $rfh) };
356 if ($@) {
357 warn($@);
358 exit 1;
359 }
360
361 exit 0;
362 }
363
364 # Stop server
365 server_stop($setup->{pid_file});
366 $self->assert_child_ok($pid);
367
368 test_cleanup($setup->{log_file}, $ex);
369 }
370
371 sub mdtm_rel_symlink {
372 my $self = shift;
373 my $tmpdir = $self->{tmpdir};
374 my $setup = test_setup($tmpdir, 'cmds');
375
376 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
377 mkpath($test_dir);
378
379 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
380 if (open(my $fh, "> $test_file")) {
381 close($fh);
382
383 } else {
384 die("Can't create $test_file: $!");
385 }
386
387 # Change to the test directory in order to create a relative path in the
388 # symlink we need
389
390 my $cwd = getcwd();
391 unless (chdir($test_dir)) {
392 die("Can't chdir to $test_dir: $!");
393 }
394
395 unless (symlink('./test.txt', './test.lnk')) {
396 die("Can't symlink 'test.lnk' to './test.txt': $!");
397 }
398
399 unless (chdir($cwd)) {
400 die("Can't chdir to $cwd: $!");
401 }
402
403 my $config = {
404 PidFile => $setup->{pid_file},
405 ScoreboardFile => $setup->{scoreboard_file},
406 SystemLog => $setup->{log_file},
407
408 AuthUserFile => $setup->{auth_user_file},
409 AuthGroupFile => $setup->{auth_group_file},
410 AuthOrder => 'mod_auth_file.c',
411
412 IfModules => {
413 'mod_delay.c' => {
414 DelayEngine => 'off',
415 },
416 },
417 };
418
419 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
420 $config);
421
422 # Open pipes, for use between the parent and child processes. Specifically,
423 # the child will indicate when it's done with its test by writing a message
424 # to the parent.
425 my ($rfh, $wfh);
426 unless (pipe($rfh, $wfh)) {
427 die("Can't open pipe: $!");
428 }
429
430 my $ex;
431
432 # Fork child
433 $self->handle_sigchld();
434 defined(my $pid = fork()) or die("Can't fork: $!");
435 if ($pid) {
436 eval {
437 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
438 $client->login($setup->{user}, $setup->{passwd});
439
440 my ($resp_code, $resp_msg) = $client->mdtm('test.d/test.lnk');
441 $client->quit();
442
443 my $expected = 213;
444 $self->assert($expected == $resp_code,
445 test_msg("Expected response code $expected, got $resp_code"));
446
447 $self->assert(qr/\d+/, $resp_msg);
448 };
449
450 if ($@) {
451 $ex = $@;
452 }
453
454 $wfh->print("done\n");
455 $wfh->flush();
456
457 } else {
458 eval { server_wait($setup->{config_file}, $rfh) };
459 if ($@) {
460 warn($@);
461 exit 1;
462 }
463
464 exit 0;
465 }
466
467 # Stop server
468 server_stop($setup->{pid_file});
469 $self->assert_child_ok($pid);
470
471 test_cleanup($setup->{log_file}, $ex);
472 }
473
474 sub mdtm_rel_symlink_chrooted_bug4219 {
475 my $self = shift;
476 my $tmpdir = $self->{tmpdir};
477 my $setup = test_setup($tmpdir, 'cmds');
478
479 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
480 mkpath($test_dir);
481
482 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
483 if (open(my $fh, "> $test_file")) {
484 close($fh);
485
486 } else {
487 die("Can't create $test_file: $!");
488 }
489
490 # Change to the test directory in order to create a relative path in the
491 # symlink we need
492
493 my $cwd = getcwd();
494 unless (chdir($test_dir)) {
495 die("Can't chdir to $test_dir: $!");
496 }
497
498 unless (symlink('./test.txt', './test.lnk')) {
499 die("Can't symlink 'test.lnk' to './test.txt': $!");
500 }
501
502 unless (chdir($cwd)) {
503 die("Can't chdir to $cwd: $!");
504 }
505
506 my $config = {
507 PidFile => $setup->{pid_file},
508 ScoreboardFile => $setup->{scoreboard_file},
509 SystemLog => $setup->{log_file},
510
511 AuthUserFile => $setup->{auth_user_file},
512 AuthGroupFile => $setup->{auth_group_file},
513 AuthOrder => 'mod_auth_file.c',
514
515 DefaultRoot => '~',
516
517 IfModules => {
518 'mod_delay.c' => {
519 DelayEngine => 'off',
520 },
521 },
522 };
523
524 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
525 $config);
526
527 # Open pipes, for use between the parent and child processes. Specifically,
528 # the child will indicate when it's done with its test by writing a message
529 # to the parent.
530 my ($rfh, $wfh);
531 unless (pipe($rfh, $wfh)) {
532 die("Can't open pipe: $!");
533 }
534
535 my $ex;
536
537 # Fork child
538 $self->handle_sigchld();
539 defined(my $pid = fork()) or die("Can't fork: $!");
540 if ($pid) {
541 eval {
542 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
543 $client->login($setup->{user}, $setup->{passwd});
544
545 my ($resp_code, $resp_msg) = $client->mdtm('test.d/test.lnk');
546 $client->quit();
547
548 my $expected = 213;
549 $self->assert($expected == $resp_code,
550 test_msg("Expected response code $expected, got $resp_code"));
551
552 $self->assert(qr/\d+/, $resp_msg);
553 };
554
555 if ($@) {
556 $ex = $@;
557 }
558
559 $wfh->print("done\n");
560 $wfh->flush();
561
562 } else {
563 eval { server_wait($setup->{config_file}, $rfh) };
564 if ($@) {
565 warn($@);
566 exit 1;
567 }
568
569 exit 0;
570 }
571
572 # Stop server
573 server_stop($setup->{pid_file});
574 $self->assert_child_ok($pid);
575
576 test_cleanup($setup->{log_file}, $ex);
577 }
578
579 sub mdtm_fails_enoent {
580 my $self = shift;
581 my $tmpdir = $self->{tmpdir};
582 my $setup = test_setup($tmpdir, 'cmds');
583
584 my $test_file = File::Spec->rel2abs("$tmpdir/foo");
585
586 my $config = {
587 PidFile => $setup->{pid_file},
588 ScoreboardFile => $setup->{scoreboard_file},
589 SystemLog => $setup->{log_file},
590
591 AuthUserFile => $setup->{auth_user_file},
592 AuthGroupFile => $setup->{auth_group_file},
593 AuthOrder => 'mod_auth_file.c',
594
595 IfModules => {
596 'mod_delay.c' => {
597 DelayEngine => 'off',
598 },
599 },
600 };
601
602 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
603 $config);
604
605 # Open pipes, for use between the parent and child processes. Specifically,
606 # the child will indicate when it's done with its test by writing a message
607 # to the parent.
608 my ($rfh, $wfh);
609 unless (pipe($rfh, $wfh)) {
610 die("Can't open pipe: $!");
611 }
612
613 my $ex;
614
615 # Fork child
616 $self->handle_sigchld();
617 defined(my $pid = fork()) or die("Can't fork: $!");
618 if ($pid) {
619 eval {
620 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
621 $client->login($setup->{user}, $setup->{passwd});
622
623 eval { $client->mdtm($test_file) };
624 unless ($@) {
625 die("MDTM succeeded unexpectedly");
626 }
627
628 my $resp_code = $client->response_code();
629 my $resp_msg = $client->response_msg();
630 $client->quit();
631
632 my $expected = 550;
633 $self->assert($expected == $resp_code,
634 test_msg("Expected response code $expected, got $resp_code"));
635
636 $expected = "$test_file: No such file or directory";
637 $self->assert($expected eq $resp_msg,
638 test_msg("Expected response message '$expected', got '$resp_msg'"));
639 };
640 if ($@) {
641 $ex = $@;
642 }
643
644 $wfh->print("done\n");
645 $wfh->flush();
646
647 } else {
648 eval { server_wait($setup->{config_file}, $rfh) };
649 if ($@) {
650 warn($@);
651 exit 1;
652 }
653
654 exit 0;
655 }
656
657 # Stop server
658 server_stop($setup->{pid_file});
659 $self->assert_child_ok($pid);
660
661 test_cleanup($setup->{log_file}, $ex);
662 }
663
664 sub mdtm_fails_abs_symlink_enoent {
665 my $self = shift;
666 my $tmpdir = $self->{tmpdir};
667 my $setup = test_setup($tmpdir, 'cmds');
668
669 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
670 mkpath($test_dir);
671
672 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
673 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
674
675 my $dst_path = $test_symlink;
676 if ($^O eq 'darwin') {
677 # MacOSX-specific hack
678 $dst_path = '/private' . $dst_path;
679 }
680
681 unless (symlink($test_file, $dst_path)) {
682 die("Can't symlink '$dst_path' to '$test_file': $!");
683 }
684
685 my $config = {
686 PidFile => $setup->{pid_file},
687 ScoreboardFile => $setup->{scoreboard_file},
688 SystemLog => $setup->{log_file},
689
690 AuthUserFile => $setup->{auth_user_file},
691 AuthGroupFile => $setup->{auth_group_file},
692 AuthOrder => 'mod_auth_file.c',
693
694 IfModules => {
695 'mod_delay.c' => {
696 DelayEngine => 'off',
697 },
698 },
699 };
700
701 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
702 $config);
703
704 # Open pipes, for use between the parent and child processes. Specifically,
705 # the child will indicate when it's done with its test by writing a message
706 # to the parent.
707 my ($rfh, $wfh);
708 unless (pipe($rfh, $wfh)) {
709 die("Can't open pipe: $!");
710 }
711
712 my $ex;
713
714 # Fork child
715 $self->handle_sigchld();
716 defined(my $pid = fork()) or die("Can't fork: $!");
717 if ($pid) {
718 eval {
719 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
720 $client->login($setup->{user}, $setup->{passwd});
721
722 eval { $client->mdtm('test.d/test.lnk') };
723 unless ($@) {
724 die("MDTM succeeded unexpectedly");
725 }
726
727 my $resp_code = $client->response_code();
728 my $resp_msg = $client->response_msg();
729 $client->quit();
730
731 my $expected = 550;
732 $self->assert($expected == $resp_code,
733 test_msg("Expected response code $expected, got $resp_code"));
734
735 $expected = 'test.d/test.lnk: No such file or directory';
736 $self->assert($expected eq $resp_msg,
737 test_msg("Expected response message '$expected', got '$resp_msg'"));
738 };
739 if ($@) {
740 $ex = $@;
741 }
742
743 $wfh->print("done\n");
744 $wfh->flush();
745
746 } else {
747 eval { server_wait($setup->{config_file}, $rfh) };
748 if ($@) {
749 warn($@);
750 exit 1;
751 }
752
753 exit 0;
754 }
755
756 # Stop server
757 server_stop($setup->{pid_file});
758 $self->assert_child_ok($pid);
759
760 test_cleanup($setup->{log_file}, $ex);
761 }
762
763 sub mdtm_fails_abs_symlink_enoent_chrooted_bug4219 {
764 my $self = shift;
765 my $tmpdir = $self->{tmpdir};
766 my $setup = test_setup($tmpdir, 'cmds');
767
768 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
769 mkpath($test_dir);
770
771 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
772 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
773
774 my $dst_path = $test_file;
775 if ($^O eq 'darwin') {
776 # MacOSX-specific hack
777 $dst_path = '/private' . $dst_path;
778 }
779
780 unless (symlink($dst_path, $test_symlink)) {
781 die("Can't symlink '$test_symlink' to '$dst_path': $!");
782 }
783
784 my $config = {
785 PidFile => $setup->{pid_file},
786 ScoreboardFile => $setup->{scoreboard_file},
787 SystemLog => $setup->{log_file},
788
789 AuthUserFile => $setup->{auth_user_file},
790 AuthGroupFile => $setup->{auth_group_file},
791 AuthOrder => 'mod_auth_file.c',
792
793 DefaultRoot => '~',
794
795 IfModules => {
796 'mod_delay.c' => {
797 DelayEngine => 'off',
798 },
799 },
800 };
801
802 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
803 $config);
804
805 # Open pipes, for use between the parent and child processes. Specifically,
806 # the child will indicate when it's done with its test by writing a message
807 # to the parent.
808 my ($rfh, $wfh);
809 unless (pipe($rfh, $wfh)) {
810 die("Can't open pipe: $!");
811 }
812
813 my $ex;
814
815 # Fork child
816 $self->handle_sigchld();
817 defined(my $pid = fork()) or die("Can't fork: $!");
818 if ($pid) {
819 eval {
820 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
821 $client->login($setup->{user}, $setup->{passwd});
822
823 eval { $client->mdtm('test.d/test.lnk') };
824 unless ($@) {
825 die("MDTM succeeded unexpectedly");
826 }
827
828 my $resp_code = $client->response_code();
829 my $resp_msg = $client->response_msg();
830 $client->quit();
831
832 my $expected = 550;
833 $self->assert($expected == $resp_code,
834 test_msg("Expected response code $expected, got $resp_code"));
835
836 $expected = 'test.d/test.lnk: No such file or directory';
837 $self->assert($expected eq $resp_msg,
838 test_msg("Expected response message '$expected', got '$resp_msg'"));
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 sub mdtm_fails_rel_symlink_enoent {
865 my $self = shift;
866 my $tmpdir = $self->{tmpdir};
867 my $setup = test_setup($tmpdir, 'cmds');
868
869 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
870 mkpath($test_dir);
871
872 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
873
874 # Change to the test directory in order to create a relative path in the
875 # symlink we need
876
877 my $cwd = getcwd();
878 unless (chdir($test_dir)) {
879 die("Can't chdir to $test_dir: $!");
880 }
881
882 unless (symlink('./test.txt', './test.lnk')) {
883 die("Can't symlink 'test.lnk' to './test.txt': $!");
884 }
885
886 unless (chdir($cwd)) {
887 die("Can't chdir to $cwd: $!");
888 }
889
890 my $config = {
891 PidFile => $setup->{pid_file},
892 ScoreboardFile => $setup->{scoreboard_file},
893 SystemLog => $setup->{log_file},
894
895 AuthUserFile => $setup->{auth_user_file},
896 AuthGroupFile => $setup->{auth_group_file},
897 AuthOrder => 'mod_auth_file.c',
898
899 IfModules => {
900 'mod_delay.c' => {
901 DelayEngine => 'off',
902 },
903 },
904 };
905
906 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
907 $config);
908
909 # Open pipes, for use between the parent and child processes. Specifically,
910 # the child will indicate when it's done with its test by writing a message
911 # to the parent.
912 my ($rfh, $wfh);
913 unless (pipe($rfh, $wfh)) {
914 die("Can't open pipe: $!");
915 }
916
917 my $ex;
918
919 # Fork child
920 $self->handle_sigchld();
921 defined(my $pid = fork()) or die("Can't fork: $!");
922 if ($pid) {
923 eval {
924 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
925 $client->login($setup->{user}, $setup->{passwd});
926
927 eval { $client->mdtm('test.d/test.lnk') };
928 unless ($@) {
929 die("MDTM succeeded unexpectedly");
930 }
931
932 my $resp_code = $client->response_code();
933 my $resp_msg = $client->response_msg();
934 $client->quit();
935
936 my $expected = 550;
937 $self->assert($expected == $resp_code,
938 test_msg("Expected response code $expected, got $resp_code"));
939
940 $expected = 'test.d/test.lnk: No such file or directory';
941 $self->assert($expected eq $resp_msg,
942 test_msg("Expected response message '$expected', got '$resp_msg'"));
943 };
944
945 if ($@) {
946 $ex = $@;
947 }
948
949 $wfh->print("done\n");
950 $wfh->flush();
951
952 } else {
953 eval { server_wait($setup->{config_file}, $rfh) };
954 if ($@) {
955 warn($@);
956 exit 1;
957 }
958
959 exit 0;
960 }
961
962 # Stop server
963 server_stop($setup->{pid_file});
964 $self->assert_child_ok($pid);
965
966 test_cleanup($setup->{log_file}, $ex);
967 }
968
969 sub mdtm_fails_rel_symlink_enoent_chrooted_bug4219 {
970 my $self = shift;
971 my $tmpdir = $self->{tmpdir};
972 my $setup = test_setup($tmpdir, 'cmds');
973
974 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
975 mkpath($test_dir);
976
977 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
978
979 # Change to the test directory in order to create a relative path in the
980 # symlink we need
981
982 my $cwd = getcwd();
983 unless (chdir($test_dir)) {
984 die("Can't chdir to $test_dir: $!");
985 }
986
987 unless (symlink('./test.txt', './test.lnk')) {
988 die("Can't symlink 'test.lnk' to './test.txt': $!");
989 }
990
991 unless (chdir($cwd)) {
992 die("Can't chdir to $cwd: $!");
993 }
994
995 my $config = {
996 PidFile => $setup->{pid_file},
997 ScoreboardFile => $setup->{scoreboard_file},
998 SystemLog => $setup->{log_file},
999
1000 AuthUserFile => $setup->{auth_user_file},
1001 AuthGroupFile => $setup->{auth_group_file},
1002 AuthOrder => 'mod_auth_file.c',
1003
1004 DefaultRoot => '~',
1005
1006 IfModules => {
1007 'mod_delay.c' => {
1008 DelayEngine => 'off',
1009 },
1010 },
1011 };
1012
1013 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1014 $config);
1015
1016 # Open pipes, for use between the parent and child processes. Specifically,
1017 # the child will indicate when it's done with its test by writing a message
1018 # to the parent.
1019 my ($rfh, $wfh);
1020 unless (pipe($rfh, $wfh)) {
1021 die("Can't open pipe: $!");
1022 }
1023
1024 my $ex;
1025
1026 # Fork child
1027 $self->handle_sigchld();
1028 defined(my $pid = fork()) or die("Can't fork: $!");
1029 if ($pid) {
1030 eval {
1031 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1032 $client->login($setup->{user}, $setup->{passwd});
1033
1034 eval { $client->mdtm('test.d/test.lnk') };
1035 unless ($@) {
1036 die("MDTM succeeded unexpectedly");
1037 }
1038
1039 my $resp_code = $client->response_code();
1040 my $resp_msg = $client->response_msg();
1041 $client->quit();
1042
1043 my $expected = 550;
1044 $self->assert($expected == $resp_code,
1045 test_msg("Expected response code $expected, got $resp_code"));
1046
1047 $expected = 'test.d/test.lnk: No such file or directory';
1048 $self->assert($expected eq $resp_msg,
1049 test_msg("Expected response message '$expected', got '$resp_msg'"));
1050 };
1051
1052 if ($@) {
1053 $ex = $@;
1054 }
1055
1056 $wfh->print("done\n");
1057 $wfh->flush();
1058
1059 } else {
1060 eval { server_wait($setup->{config_file}, $rfh) };
1061 if ($@) {
1062 warn($@);
1063 exit 1;
1064 }
1065
1066 exit 0;
1067 }
1068
1069 # Stop server
1070 server_stop($setup->{pid_file});
1071 $self->assert_child_ok($pid);
1072
1073 test_cleanup($setup->{log_file}, $ex);
1074 }
1075
1076 sub mdtm_fails_eperm {
1077 my $self = shift;
1078 my $tmpdir = $self->{tmpdir};
1079 my $setup = test_setup($tmpdir, 'cmds');
1080
1081 my $test_file = File::Spec->rel2abs("$tmpdir/foo");
1082 if (open(my $fh, "> $test_file")) {
1083 close($fh);
1084
1085 } else {
1086 die("Can't create $test_file: $!");
1087 }
1088
1089 my $config = {
1090 PidFile => $setup->{pid_file},
1091 ScoreboardFile => $setup->{scoreboard_file},
1092 SystemLog => $setup->{log_file},
1093
1094 AuthUserFile => $setup->{auth_user_file},
1095 AuthGroupFile => $setup->{auth_group_file},
1096 AuthOrder => 'mod_auth_file.c',
1097
1098 IfModules => {
1099 'mod_delay.c' => {
1100 DelayEngine => 'off',
1101 },
1102 },
1103 };
1104
1105 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1106 $config);
1107
1108 # Open pipes, for use between the parent and child processes. Specifically,
1109 # the child will indicate when it's done with its test by writing a message
1110 # to the parent.
1111 my ($rfh, $wfh);
1112 unless (pipe($rfh, $wfh)) {
1113 die("Can't open pipe: $!");
1114 }
1115
1116 my $ex;
1117
1118 # Fork child
1119 $self->handle_sigchld();
1120 defined(my $pid = fork()) or die("Can't fork: $!");
1121 if ($pid) {
1122 eval {
1123 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1124 $client->login($setup->{user}, $setup->{passwd});
1125
1126 # Make it such that perms on the home do to not allow reads
1127 my $perms = (stat($setup->{home_dir}))[2];
1128 unless (chmod(0220, $setup->{home_dir})) {
1129 die("Failed to change perms on $setup->{home_dir}: $!");
1130 }
1131
1132 eval { $client->mdtm($test_file) };
1133 unless ($@) {
1134 die("MDTM succeeded unexpectedly");
1135 }
1136
1137 my $resp_code = $client->response_code();
1138 my $resp_msg = $client->response_msg();
1139 $client->quit();
1140
1141 chmod($perms, $setup->{home_dir});
1142
1143 my $expected = 550;
1144 $self->assert($expected == $resp_code,
1145 test_msg("Expected response code $expected, got $resp_code"));
1146
1147 $expected = "$test_file: Permission denied";
1148 $self->assert($expected eq $resp_msg,
1149 test_msg("Expected response message '$expected', got '$resp_msg'"));
1150 };
1151 if ($@) {
1152 $ex = $@;
1153 }
1154
1155 $wfh->print("done\n");
1156 $wfh->flush();
1157
1158 } else {
1159 eval { server_wait($setup->{config_file}, $rfh) };
1160 if ($@) {
1161 warn($@);
1162 exit 1;
1163 }
1164
1165 exit 0;
1166 }
1167
1168 # Stop server
1169 server_stop($setup->{pid_file});
1170 $self->assert_child_ok($pid);
1171
1172 test_cleanup($setup->{log_file}, $ex);
1173 }
1174
1175 1;