Debian Codegraph @

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

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