Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::STOR;
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 stor_ok_raw_active => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 stor_ok_raw_passive => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 stor_ok_binary_file => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 stor_ok_ascii_file => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 stor_ok_ascii_file_bug4237 => {
41 order => ++$order,
42 test_class => [qw(bug forking)],
43 },
44
45 stor_ok_ascii_file_bug4277 => {
46 order => ++$order,
47 test_class => [qw(bug forking)],
48 },
49
50 stor_abs_symlink => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 stor_abs_symlink_chrooted_bug4219 => {
56 order => ++$order,
57 test_class => [qw(bug forking rootprivs)],
58 },
59
60 stor_rel_symlink => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 stor_rel_symlink_chrooted_bug4219 => {
66 order => ++$order,
67 test_class => [qw(bug forking rootprivs)],
68 },
69
70 stor_fails_not_reg => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 stor_fails_login_required => {
76 order => ++$order,
77 test_class => [qw(forking)],
78 },
79
80 stor_fails_no_path => {
81 order => ++$order,
82 test_class => [qw(forking)],
83 },
84
85 stor_fails_eperm => {
86 order => ++$order,
87 test_class => [qw(forking)],
88 },
89
90 stor_fails_abs_symlink_dir_enoent => {
91 order => ++$order,
92 test_class => [qw(forking)],
93 },
94
95 stor_fails_abs_symlink_dir_enoent_chrooted_bug4219 => {
96 order => ++$order,
97 test_class => [qw(bug forking rootprivs)],
98 },
99
100 stor_fails_rel_symlink_dir_enoent => {
101 order => ++$order,
102 test_class => [qw(forking)],
103 },
104
105 stor_fails_rel_symlink_dir_enoent_chrooted_bug4219 => {
106 order => ++$order,
107 test_class => [qw(bug forking rootprivs)],
108 },
109
110 stor_leading_whitespace => {
111 order => ++$order,
112 test_class => [qw(forking)],
113 },
114
115 stor_multiple_periods => {
116 order => ++$order,
117 test_class => [qw(forking)],
118 },
119
120 };
121
122 sub new {
123 return shift()->SUPER::new(@_);
124 }
125
126 sub list_tests {
127 return testsuite_get_runnable_tests($TESTS);
128 }
129
130 sub stor_ok_raw_active {
131 my $self = shift;
132 my $tmpdir = $self->{tmpdir};
133 my $setup = test_setup($tmpdir, 'cmds');
134
135 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
136
137 my $config = {
138 PidFile => $setup->{pid_file},
139 ScoreboardFile => $setup->{scoreboard_file},
140 SystemLog => $setup->{log_file},
141
142 AuthUserFile => $setup->{auth_user_file},
143 AuthGroupFile => $setup->{auth_group_file},
144 AuthOrder => 'mod_auth_file.c',
145
146 IfModules => {
147 'mod_delay.c' => {
148 DelayEngine => 'off',
149 },
150 },
151 };
152
153 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
154 $config);
155
156 # Open pipes, for use between the parent and child processes. Specifically,
157 # the child will indicate when it's done with its test by writing a message
158 # to the parent.
159 my ($rfh, $wfh);
160 unless (pipe($rfh, $wfh)) {
161 die("Can't open pipe: $!");
162 }
163
164 my $ex;
165
166 # Fork child
167 $self->handle_sigchld();
168 defined(my $pid = fork()) or die("Can't fork: $!");
169 if ($pid) {
170 eval {
171 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
172 $client->login($setup->{user}, $setup->{passwd});
173
174 my $conn = $client->stor_raw('test.txt');
175 unless ($conn) {
176 die("Failed to STOR: " . $client->response_code() . " " .
177 $client->response_msg());
178 }
179
180 my $buf = "Foo!\n";
181 $conn->write($buf, length($buf), 25);
182 eval { $conn->close() };
183
184 my $resp_code = $client->response_code();
185 my $resp_msg = $client->response_msg();
186 $self->assert_transfer_ok($resp_code, $resp_msg);
187
188 $client->quit();
189
190 $self->assert(-f $test_file,
191 test_msg("File $test_file does not exist as expected"));
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 stor_ok_raw_passive {
218 my $self = shift;
219 my $tmpdir = $self->{tmpdir};
220 my $setup = test_setup($tmpdir, 'cmds');
221
222 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
223
224 my $config = {
225 PidFile => $setup->{pid_file},
226 ScoreboardFile => $setup->{scoreboard_file},
227 SystemLog => $setup->{log_file},
228
229 AuthUserFile => $setup->{auth_user_file},
230 AuthGroupFile => $setup->{auth_group_file},
231 AuthOrder => 'mod_auth_file.c',
232
233 IfModules => {
234 'mod_delay.c' => {
235 DelayEngine => 'off',
236 },
237 },
238 };
239
240 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
241 $config);
242
243 # Open pipes, for use between the parent and child processes. Specifically,
244 # the child will indicate when it's done with its test by writing a message
245 # to the parent.
246 my ($rfh, $wfh);
247 unless (pipe($rfh, $wfh)) {
248 die("Can't open pipe: $!");
249 }
250
251 my $ex;
252
253 # Fork child
254 $self->handle_sigchld();
255 defined(my $pid = fork()) or die("Can't fork: $!");
256 if ($pid) {
257 eval {
258 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
259 $client->login($setup->{user}, $setup->{passwd});
260
261 my $conn = $client->stor_raw('test.txt');
262 unless ($conn) {
263 die("Failed to STOR: " . $client->response_code() . " " .
264 $client->response_msg());
265 }
266
267 my $buf = "Foo!\n";
268 $conn->write($buf, length($buf), 25);
269 eval { $conn->close() };
270
271 my $resp_code = $client->response_code();
272 my $resp_msg = $client->response_msg();
273 $self->assert_transfer_ok($resp_code, $resp_msg);
274
275 $client->quit();
276
277 $self->assert(-f $test_file,
278 test_msg("File $test_file does not exist as expected"));
279 };
280 if ($@) {
281 $ex = $@;
282 }
283
284 $wfh->print("done\n");
285 $wfh->flush();
286
287 } else {
288 eval { server_wait($setup->{config_file}, $rfh) };
289 if ($@) {
290 warn($@);
291 exit 1;
292 }
293
294 exit 0;
295 }
296
297 # Stop server
298 server_stop($setup->{pid_file});
299 $self->assert_child_ok($pid);
300
301 test_cleanup($setup->{log_file}, $ex);
302 }
303
304 sub stor_ok_binary_file {
305 my $self = shift;
306 my $tmpdir = $self->{tmpdir};
307 my $setup = test_setup($tmpdir, 'cmds');
308
309 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
310
311 my $config = {
312 PidFile => $setup->{pid_file},
313 ScoreboardFile => $setup->{scoreboard_file},
314 SystemLog => $setup->{log_file},
315
316 AuthUserFile => $setup->{auth_user_file},
317 AuthGroupFile => $setup->{auth_group_file},
318 AuthOrder => 'mod_auth_file.c',
319
320 IfModules => {
321 'mod_delay.c' => {
322 DelayEngine => 'off',
323 },
324 },
325 };
326
327 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
328 $config);
329
330 # Open pipes, for use between the parent and child processes. Specifically,
331 # the child will indicate when it's done with its test by writing a message
332 # to the parent.
333 my ($rfh, $wfh);
334 unless (pipe($rfh, $wfh)) {
335 die("Can't open pipe: $!");
336 }
337
338 my $ex;
339
340 # Fork child
341 $self->handle_sigchld();
342 defined(my $pid = fork()) or die("Can't fork: $!");
343 if ($pid) {
344 eval {
345 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
346 $client->login($setup->{user}, $setup->{passwd});
347 $client->type('binary');
348
349 my $conn = $client->stor_raw('test.dat');
350 unless ($conn) {
351 die("STOR failed: " . $client->response_code() . " " .
352 $client->response_msg());
353 }
354
355 my $buf = "Foo!\r\n";
356 $conn->write($buf, length($buf), 25);
357 eval { $conn->close() };
358
359 my $resp_code = $client->response_code();
360 my $resp_msg = $client->response_msg();
361 $self->assert_transfer_ok($resp_code, $resp_msg);
362
363 $client->quit();
364
365 $self->assert(-f $test_file,
366 test_msg("File $test_file does not exist as expected"));
367
368 my $expected = -s $test_file;
369 my $size = length($buf);
370 $self->assert($expected == $size,
371 test_msg("Expected size $expected, got $size"));
372 };
373 if ($@) {
374 $ex = $@;
375 }
376
377 $wfh->print("done\n");
378 $wfh->flush();
379
380 } else {
381 eval { server_wait($setup->{config_file}, $rfh) };
382 if ($@) {
383 warn($@);
384 exit 1;
385 }
386
387 exit 0;
388 }
389
390 # Stop server
391 server_stop($setup->{pid_file});
392 $self->assert_child_ok($pid);
393
394 test_cleanup($setup->{log_file}, $ex);
395 }
396
397 sub stor_ok_ascii_file {
398 my $self = shift;
399 my $tmpdir = $self->{tmpdir};
400 my $setup = test_setup($tmpdir, 'cmds');
401
402 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
403
404 my $config = {
405 PidFile => $setup->{pid_file},
406 ScoreboardFile => $setup->{scoreboard_file},
407 SystemLog => $setup->{log_file},
408
409 AuthUserFile => $setup->{auth_user_file},
410 AuthGroupFile => $setup->{auth_group_file},
411 AuthOrder => 'mod_auth_file.c',
412
413 IfModules => {
414 'mod_delay.c' => {
415 DelayEngine => 'off',
416 },
417 },
418 };
419
420 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
421 $config);
422
423 # Open pipes, for use between the parent and child processes. Specifically,
424 # the child will indicate when it's done with its test by writing a message
425 # to the parent.
426 my ($rfh, $wfh);
427 unless (pipe($rfh, $wfh)) {
428 die("Can't open pipe: $!");
429 }
430
431 my $ex;
432
433 # Fork child
434 $self->handle_sigchld();
435 defined(my $pid = fork()) or die("Can't fork: $!");
436 if ($pid) {
437 eval {
438 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
439 $client->login($setup->{user}, $setup->{passwd});
440 $client->type('ascii');
441
442 my $conn = $client->stor_raw('test.dat');
443 unless ($conn) {
444 die("STOR failed: " . $client->response_code() . " " .
445 $client->response_msg());
446 }
447
448 my $buf = "Foo!\r\n";
449 $conn->write($buf, length($buf), 25);
450 eval { $conn->close() };
451
452 my $resp_code = $client->response_code();
453 my $resp_msg = $client->response_msg();
454 $self->assert_transfer_ok($resp_code, $resp_msg);
455
456 $client->quit();
457
458 $self->assert(-f $test_file,
459 test_msg("File $test_file does not exist as expected"));
460
461 my $expected = -s $test_file;
462
463 # Take back one byte for whose CR this ASCII file is.
464 my $size = length($buf)-1;
465 $self->assert($expected == $size,
466 test_msg("Expected size $expected, got $size"));
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 stor_ok_ascii_file_bug4237 {
493 my $self = shift;
494 my $tmpdir = $self->{tmpdir};
495 my $setup = test_setup($tmpdir, 'cmds');
496
497 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
498
499 my $config = {
500 PidFile => $setup->{pid_file},
501 ScoreboardFile => $setup->{scoreboard_file},
502 SystemLog => $setup->{log_file},
503
504 AuthUserFile => $setup->{auth_user_file},
505 AuthGroupFile => $setup->{auth_group_file},
506 AuthOrder => 'mod_auth_file.c',
507
508 IfModules => {
509 'mod_delay.c' => {
510 DelayEngine => 'off',
511 },
512 },
513 };
514
515 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
516 $config);
517
518 # Open pipes, for use between the parent and child processes. Specifically,
519 # the child will indicate when it's done with its test by writing a message
520 # to the parent.
521 my ($rfh, $wfh);
522 unless (pipe($rfh, $wfh)) {
523 die("Can't open pipe: $!");
524 }
525
526 my $ex;
527
528 # Fork child
529 $self->handle_sigchld();
530 defined(my $pid = fork()) or die("Can't fork: $!");
531 if ($pid) {
532 eval {
533 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
534 $client->login($setup->{user}, $setup->{passwd});
535 $client->type('ascii');
536
537 my $conn = $client->stor_raw('test.dat');
538 unless ($conn) {
539 die("STOR failed: " . $client->response_code() . " " .
540 $client->response_msg());
541 }
542
543 my $buf = ("\r\r" x 32768) . "\r";
544 $conn->write($buf, length($buf), 25);
545 eval { $conn->close() };
546
547 my $resp_code = $client->response_code();
548 my $resp_msg = $client->response_msg();
549 $self->assert_transfer_ok($resp_code, $resp_msg);
550
551 $self->assert(-f $test_file,
552 test_msg("File $test_file does not exist as expected"));
553
554 my $expected = -s $test_file;
555
556 my $size = length($buf);
557 $self->assert($expected == $size,
558 test_msg("Expected size $expected, got $size"));
559
560 unlink($test_file);
561
562 $conn = $client->stor_raw('test.dat');
563 unless ($conn) {
564 die("STOR failed: " . $client->response_code() . " " .
565 $client->response_msg());
566 }
567
568 $buf = ("\r\n" x 32768);
569 $conn->write($buf, length($buf), 25);
570 eval { $conn->close() };
571
572 $resp_code = $client->response_code();
573 $resp_msg = $client->response_msg();
574 $self->assert_transfer_ok($resp_code, $resp_msg);
575
576 $self->assert(-f $test_file,
577 test_msg("File $test_file does not exist as expected"));
578
579 $expected = -s $test_file;
580
581 # Take back one byte for per CR
582 $size = length($buf) / 2;
583 $self->assert($expected == $size,
584 test_msg("Expected size $expected, got $size"));
585
586 $client->quit();
587 };
588 if ($@) {
589 $ex = $@;
590 }
591
592 $wfh->print("done\n");
593 $wfh->flush();
594
595 } else {
596 eval { server_wait($setup->{config_file}, $rfh) };
597 if ($@) {
598 warn($@);
599 exit 1;
600 }
601
602 exit 0;
603 }
604
605 # Stop server
606 server_stop($setup->{pid_file});
607 $self->assert_child_ok($pid);
608
609 test_cleanup($setup->{log_file}, $ex);
610 }
611
612 sub stor_ok_ascii_file_bug4277 {
613 my $self = shift;
614 my $tmpdir = $self->{tmpdir};
615 my $setup = test_setup($tmpdir, 'cmds');
616
617 use Digest::MD5;
618
619 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
620
621 my $config = {
622 PidFile => $setup->{pid_file},
623 ScoreboardFile => $setup->{scoreboard_file},
624 SystemLog => $setup->{log_file},
625
626 AuthUserFile => $setup->{auth_user_file},
627 AuthGroupFile => $setup->{auth_group_file},
628 AuthOrder => 'mod_auth_file.c',
629
630 IfModules => {
631 'mod_delay.c' => {
632 DelayEngine => 'off',
633 },
634 },
635 };
636
637 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
638 $config);
639
640 # Open pipes, for use between the parent and child processes. Specifically,
641 # the child will indicate when it's done with its test by writing a message
642 # to the parent.
643 my ($rfh, $wfh);
644 unless (pipe($rfh, $wfh)) {
645 die("Can't open pipe: $!");
646 }
647
648 my $ex;
649
650 # Fork child
651 $self->handle_sigchld();
652 defined(my $pid = fork()) or die("Can't fork: $!");
653 if ($pid) {
654 eval {
655 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
656 $client->login($setup->{user}, $setup->{passwd});
657 $client->type('ascii');
658
659 my $conn = $client->stor_raw('test.dat');
660 unless ($conn) {
661 die("STOR failed: " . $client->response_code() . " " .
662 $client->response_msg());
663 }
664
665 my $buf = ("\r\r" x 32768) . "\r";
666 $conn->write($buf, length($buf), 25);
667 eval { $conn->close() };
668
669 my $resp_code = $client->response_code();
670 my $resp_msg = $client->response_msg();
671 $self->assert_transfer_ok($resp_code, $resp_msg);
672
673 $self->assert(-f $test_file,
674 test_msg("File $test_file does not exist as expected"));
675
676 my $expected = -s $test_file;
677
678 my $size = length($buf);
679 $self->assert($expected == $size,
680 test_msg("Expected size $expected, got $size"));
681
682 my $digest;
683 if (open(my $fh, "< $test_file")) {
684 my $ctx = Digest::MD5->new();
685 $ctx->addfile($fh);
686 $digest = lc($ctx->hexdigest);
687
688 } else {
689 die("Can't read $test_file: $!");
690 }
691
692 $expected = '8ed41c85d5ae54141ac1010b34213ba6';
693 $self->assert($expected eq $digest,
694 test_msg("Expected MD5 $expected, got $digest"));
695
696 unlink($test_file);
697
698 $conn = $client->stor_raw('test.dat');
699 unless ($conn) {
700 die("STOR failed: " . $client->response_code() . " " .
701 $client->response_msg());
702 }
703
704 $buf = ("\r\n" x 32768);
705 $conn->write($buf, length($buf), 25);
706 eval { $conn->close() };
707
708 $resp_code = $client->response_code();
709 $resp_msg = $client->response_msg();
710 $self->assert_transfer_ok($resp_code, $resp_msg);
711
712 $self->assert(-f $test_file,
713 test_msg("File $test_file does not exist as expected"));
714
715 $expected = -s $test_file;
716
717 # Take back one byte for per CR
718 $size = length($buf) / 2;
719 $self->assert($expected == $size,
720 test_msg("Expected size $expected, got $size"));
721
722 $digest = '';
723 if (open(my $fh, "< $test_file")) {
724 my $ctx = Digest::MD5->new();
725 $ctx->addfile($fh);
726 $digest = lc($ctx->hexdigest);
727
728 } else {
729 die("Can't read $test_file: $!");
730 }
731
732 $expected = '07f9f47f9ce9f8e6de19c6518dba04ca';
733 $self->assert($expected eq $digest,
734 test_msg("Expected MD5 $expected, got $digest"));
735
736 $client->quit();
737 };
738 if ($@) {
739 $ex = $@;
740 }
741
742 $wfh->print("done\n");
743 $wfh->flush();
744
745 } else {
746 eval { server_wait($setup->{config_file}, $rfh) };
747 if ($@) {
748 warn($@);
749 exit 1;
750 }
751
752 exit 0;
753 }
754
755 # Stop server
756 server_stop($setup->{pid_file});
757 $self->assert_child_ok($pid);
758
759 test_cleanup($setup->{log_file}, $ex);
760 }
761
762 sub stor_abs_symlink {
763 my $self = shift;
764 my $tmpdir = $self->{tmpdir};
765 my $setup = test_setup($tmpdir, 'cmds');
766
767 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
768 mkpath($test_dir);
769
770 my $test_file = File::Spec->rel2abs("$test_dir/test.dat");
771 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
772
773 my $dst_path = $test_file;
774 if ($^O eq 'darwin') {
775 # MacOSX-specific hack
776 $dst_path = '/private' . $dst_path;
777 }
778
779 unless (symlink($dst_path, $test_symlink)) {
780 die("Can't symlink $test_symlink to $dst_path: $!");
781 }
782
783 if ($< == 0) {
784 unless (chmod(0755, $test_dir)) {
785 die("Can't set perms on $test_dir to 0755: $!");
786 }
787
788 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
789 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
790 }
791 }
792
793 my $config = {
794 PidFile => $setup->{pid_file},
795 ScoreboardFile => $setup->{scoreboard_file},
796 SystemLog => $setup->{log_file},
797
798 AuthUserFile => $setup->{auth_user_file},
799 AuthGroupFile => $setup->{auth_group_file},
800 AuthOrder => 'mod_auth_file.c',
801
802 AllowOverwrite => 'on',
803 TransferOptions => 'AllowSymlinkUpload',
804
805 IfModules => {
806 'mod_delay.c' => {
807 DelayEngine => 'off',
808 },
809 },
810 };
811
812 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
813 $config);
814
815 # Open pipes, for use between the parent and child processes. Specifically,
816 # the child will indicate when it's done with its test by writing a message
817 # to the parent.
818 my ($rfh, $wfh);
819 unless (pipe($rfh, $wfh)) {
820 die("Can't open pipe: $!");
821 }
822
823 my $ex;
824
825 # Fork child
826 $self->handle_sigchld();
827 defined(my $pid = fork()) or die("Can't fork: $!");
828 if ($pid) {
829 eval {
830 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
831 $client->login($setup->{user}, $setup->{passwd});
832 $client->type('binary');
833
834 my $path = 'sub.d/test.lnk';
835 my $conn = $client->stor_raw($path);
836 unless ($conn) {
837 die("STOR failed: " . $client->response_code() . " " .
838 $client->response_msg());
839 }
840
841 my $buf = "Foo!\r\n";
842 $conn->write($buf, length($buf), 25);
843 eval { $conn->close() };
844
845 my $resp_code = $client->response_code();
846 my $resp_msg = $client->response_msg();
847 $self->assert_transfer_ok($resp_code, $resp_msg);
848
849 $client->quit();
850
851 $self->assert(-f $test_file,
852 test_msg("File $test_file does not exist as expected"));
853
854 my $expected = -s $test_file;
855 my $size = length($buf);
856 $self->assert($expected == $size,
857 test_msg("Expected size $expected, got $size"));
858 };
859 if ($@) {
860 $ex = $@;
861 }
862
863 $wfh->print("done\n");
864 $wfh->flush();
865
866 } else {
867 eval { server_wait($setup->{config_file}, $rfh) };
868 if ($@) {
869 warn($@);
870 exit 1;
871 }
872
873 exit 0;
874 }
875
876 # Stop server
877 server_stop($setup->{pid_file});
878 $self->assert_child_ok($pid);
879
880 test_cleanup($setup->{log_file}, $ex);
881 }
882
883 sub stor_abs_symlink_chrooted_bug4219 {
884 my $self = shift;
885 my $tmpdir = $self->{tmpdir};
886 my $setup = test_setup($tmpdir, 'cmds');
887
888 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
889 mkpath($test_dir);
890
891 my $test_file = File::Spec->rel2abs("$test_dir/test.dat");
892 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
893
894 my $dst_path = $test_file;
895 if ($^O eq 'darwin') {
896 # MacOSX-specific hack
897 $dst_path = '/private' . $dst_path;
898 }
899
900 unless (symlink($dst_path, $test_symlink)) {
901 die("Can't symlink $test_symlink to $dst_path: $!");
902 }
903
904 if ($< == 0) {
905 unless (chmod(0755, $test_dir)) {
906 die("Can't set perms on $test_dir to 0755: $!");
907 }
908
909 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
910 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
911 }
912 }
913
914 my $config = {
915 PidFile => $setup->{pid_file},
916 ScoreboardFile => $setup->{scoreboard_file},
917 SystemLog => $setup->{log_file},
918
919 AuthUserFile => $setup->{auth_user_file},
920 AuthGroupFile => $setup->{auth_group_file},
921 AuthOrder => 'mod_auth_file.c',
922
923 DefaultRoot => '~',
924
925 IfModules => {
926 'mod_delay.c' => {
927 DelayEngine => 'off',
928 },
929 },
930 };
931
932 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
933 $config);
934
935 # Open pipes, for use between the parent and child processes. Specifically,
936 # the child will indicate when it's done with its test by writing a message
937 # to the parent.
938 my ($rfh, $wfh);
939 unless (pipe($rfh, $wfh)) {
940 die("Can't open pipe: $!");
941 }
942
943 my $ex;
944
945 # Fork child
946 $self->handle_sigchld();
947 defined(my $pid = fork()) or die("Can't fork: $!");
948 if ($pid) {
949 eval {
950 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
951 $client->login($setup->{user}, $setup->{passwd});
952 $client->type('binary');
953
954 my $path = 'sub.d/test.lnk';
955 my $conn = $client->stor_raw($path);
956 unless ($conn) {
957 die("STOR failed: " . $client->response_code() . " " .
958 $client->response_msg());
959 }
960
961 my $buf = "Foo!\r\n";
962 $conn->write($buf, length($buf), 25);
963 eval { $conn->close() };
964
965 my $resp_code = $client->response_code();
966 my $resp_msg = $client->response_msg();
967 $self->assert_transfer_ok($resp_code, $resp_msg);
968
969 $client->quit();
970
971 $self->assert(-f $test_file,
972 test_msg("File $test_file does not exist as expected"));
973
974 my $expected = -s $test_file;
975 my $size = length($buf);
976 $self->assert($expected == $size,
977 test_msg("Expected size $expected, got $size"));
978 };
979 if ($@) {
980 $ex = $@;
981 }
982
983 $wfh->print("done\n");
984 $wfh->flush();
985
986 } else {
987 eval { server_wait($setup->{config_file}, $rfh) };
988 if ($@) {
989 warn($@);
990 exit 1;
991 }
992
993 exit 0;
994 }
995
996 # Stop server
997 server_stop($setup->{pid_file});
998 $self->assert_child_ok($pid);
999
1000 test_cleanup($setup->{log_file}, $ex);
1001 }
1002
1003 sub stor_rel_symlink {
1004 my $self = shift;
1005 my $tmpdir = $self->{tmpdir};
1006 my $setup = test_setup($tmpdir, 'cmds');
1007
1008 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1009 mkpath($test_dir);
1010
1011 my $test_file = File::Spec->rel2abs("$test_dir/test.dat");
1012
1013 # Change to the test directory in order to create a relative path in the
1014 # symlink we need
1015
1016 my $cwd = getcwd();
1017 unless (chdir($test_dir)) {
1018 die("Can't chdir to $test_dir: $!");
1019 }
1020
1021 unless (symlink('./test.dat', './test.lnk')) {
1022 die("Can't symlink 'test.lnk' to './test.dat': $!");
1023 }
1024
1025 unless (chdir($cwd)) {
1026 die("Can't chdir to $cwd: $!");
1027 }
1028
1029 if ($< == 0) {
1030 unless (chmod(0755, $test_dir)) {
1031 die("Can't set perms on $test_dir to 0755: $!");
1032 }
1033
1034 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1035 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1036 }
1037 }
1038
1039 my $config = {
1040 PidFile => $setup->{pid_file},
1041 ScoreboardFile => $setup->{scoreboard_file},
1042 SystemLog => $setup->{log_file},
1043
1044 AuthUserFile => $setup->{auth_user_file},
1045 AuthGroupFile => $setup->{auth_group_file},
1046 AuthOrder => 'mod_auth_file.c',
1047
1048 AllowOverwrite => 'on',
1049 TransferOptions => 'AllowSymlinkUpload',
1050
1051 IfModules => {
1052 'mod_delay.c' => {
1053 DelayEngine => 'off',
1054 },
1055 },
1056 };
1057
1058 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1059 $config);
1060
1061 # Open pipes, for use between the parent and child processes. Specifically,
1062 # the child will indicate when it's done with its test by writing a message
1063 # to the parent.
1064 my ($rfh, $wfh);
1065 unless (pipe($rfh, $wfh)) {
1066 die("Can't open pipe: $!");
1067 }
1068
1069 my $ex;
1070
1071 # Fork child
1072 $self->handle_sigchld();
1073 defined(my $pid = fork()) or die("Can't fork: $!");
1074 if ($pid) {
1075 eval {
1076 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1077 $client->login($setup->{user}, $setup->{passwd});
1078 $client->type('binary');
1079
1080 my $path = 'sub.d/test.lnk';
1081 my $conn = $client->stor_raw($path);
1082 unless ($conn) {
1083 die("STOR failed: " . $client->response_code() . " " .
1084 $client->response_msg());
1085 }
1086
1087 my $buf = "Foo!\r\n";
1088 $conn->write($buf, length($buf), 25);
1089 eval { $conn->close() };
1090
1091 my $resp_code = $client->response_code();
1092 my $resp_msg = $client->response_msg();
1093 $self->assert_transfer_ok($resp_code, $resp_msg);
1094
1095 $client->quit();
1096
1097 $self->assert(-f $test_file,
1098 test_msg("File $test_file does not exist as expected"));
1099
1100 my $expected = -s $test_file;
1101 my $size = length($buf);
1102 $self->assert($expected == $size,
1103 test_msg("Expected size $expected, got $size"));
1104 };
1105 if ($@) {
1106 $ex = $@;
1107 }
1108
1109 $wfh->print("done\n");
1110 $wfh->flush();
1111
1112 } else {
1113 eval { server_wait($setup->{config_file}, $rfh) };
1114 if ($@) {
1115 warn($@);
1116 exit 1;
1117 }
1118
1119 exit 0;
1120 }
1121
1122 # Stop server
1123 server_stop($setup->{pid_file});
1124 $self->assert_child_ok($pid);
1125
1126 test_cleanup($setup->{log_file}, $ex);
1127 }
1128
1129 sub stor_rel_symlink_chrooted_bug4219 {
1130 my $self = shift;
1131 my $tmpdir = $self->{tmpdir};
1132 my $setup = test_setup($tmpdir, 'cmds');
1133
1134 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1135 mkpath($test_dir);
1136
1137 my $test_file = File::Spec->rel2abs("$test_dir/test.dat");
1138
1139 # Change to the test directory in order to create a relative path in the
1140 # symlink we need
1141
1142 my $cwd = getcwd();
1143 unless (chdir($test_dir)) {
1144 die("Can't chdir to $test_dir: $!");
1145 }
1146
1147 unless (symlink('./test.dat', './test.lnk')) {
1148 die("Can't symlink 'test.lnk' to './test.dat': $!");
1149 }
1150
1151 unless (chdir($cwd)) {
1152 die("Can't chdir to $cwd: $!");
1153 }
1154
1155 if ($< == 0) {
1156 unless (chmod(0755, $test_dir)) {
1157 die("Can't set perms on $test_dir to 0755: $!");
1158 }
1159
1160 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1161 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1162 }
1163 }
1164
1165 my $config = {
1166 PidFile => $setup->{pid_file},
1167 ScoreboardFile => $setup->{scoreboard_file},
1168 SystemLog => $setup->{log_file},
1169
1170 AuthUserFile => $setup->{auth_user_file},
1171 AuthGroupFile => $setup->{auth_group_file},
1172 AuthOrder => 'mod_auth_file.c',
1173
1174 DefaultRoot => '~',
1175
1176 IfModules => {
1177 'mod_delay.c' => {
1178 DelayEngine => 'off',
1179 },
1180 },
1181 };
1182
1183 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1184 $config);
1185
1186 # Open pipes, for use between the parent and child processes. Specifically,
1187 # the child will indicate when it's done with its test by writing a message
1188 # to the parent.
1189 my ($rfh, $wfh);
1190 unless (pipe($rfh, $wfh)) {
1191 die("Can't open pipe: $!");
1192 }
1193
1194 my $ex;
1195
1196 # Fork child
1197 $self->handle_sigchld();
1198 defined(my $pid = fork()) or die("Can't fork: $!");
1199 if ($pid) {
1200 eval {
1201 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1202 $client->login($setup->{user}, $setup->{passwd});
1203 $client->type('binary');
1204
1205 my $path = 'sub.d/test.lnk';
1206 my $conn = $client->stor_raw($path);
1207 unless ($conn) {
1208 die("STOR failed: " . $client->response_code() . " " .
1209 $client->response_msg());
1210 }
1211
1212 my $buf = "Foo!\r\n";
1213 $conn->write($buf, length($buf), 25);
1214 eval { $conn->close() };
1215
1216 my $resp_code = $client->response_code();
1217 my $resp_msg = $client->response_msg();
1218 $self->assert_transfer_ok($resp_code, $resp_msg);
1219
1220 $client->quit();
1221
1222 $self->assert(-f $test_file,
1223 test_msg("File $test_file does not exist as expected"));
1224
1225 my $expected = -s $test_file;
1226 my $size = length($buf);
1227 $self->assert($expected == $size,
1228 test_msg("Expected size $expected, got $size"));
1229 };
1230 if ($@) {
1231 $ex = $@;
1232 }
1233
1234 $wfh->print("done\n");
1235 $wfh->flush();
1236
1237 } else {
1238 eval { server_wait($setup->{config_file}, $rfh) };
1239 if ($@) {
1240 warn($@);
1241 exit 1;
1242 }
1243
1244 exit 0;
1245 }
1246
1247 # Stop server
1248 server_stop($setup->{pid_file});
1249 $self->assert_child_ok($pid);
1250
1251 test_cleanup($setup->{log_file}, $ex);
1252 }
1253
1254 sub stor_fails_not_reg {
1255 my $self = shift;
1256 my $tmpdir = $self->{tmpdir};
1257 my $setup = test_setup($tmpdir, 'cmds');
1258
1259 my $config = {
1260 PidFile => $setup->{pid_file},
1261 ScoreboardFile => $setup->{scoreboard_file},
1262 SystemLog => $setup->{log_file},
1263
1264 AuthUserFile => $setup->{auth_user_file},
1265 AuthGroupFile => $setup->{auth_group_file},
1266 AuthOrder => 'mod_auth_file.c',
1267
1268 AllowOverwrite => 'on',
1269
1270 IfModules => {
1271 'mod_delay.c' => {
1272 DelayEngine => 'off',
1273 },
1274 },
1275 };
1276
1277 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1278 $config);
1279
1280 # Open pipes, for use between the parent and child processes. Specifically,
1281 # the child will indicate when it's done with its test by writing a message
1282 # to the parent.
1283 my ($rfh, $wfh);
1284 unless (pipe($rfh, $wfh)) {
1285 die("Can't open pipe: $!");
1286 }
1287
1288 my $ex;
1289
1290 # Fork child
1291 $self->handle_sigchld();
1292 defined(my $pid = fork()) or die("Can't fork: $!");
1293 if ($pid) {
1294 eval {
1295 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1296 $client->login($setup->{user}, $setup->{passwd});
1297
1298 my $conn = $client->stor_raw($setup->{home_dir});
1299 if ($conn) {
1300 die("STOR succeeded unexpectedly");
1301 }
1302
1303 my $resp_code = $client->response_code();
1304 my $resp_msg = $client->response_msg();
1305 $client->quit();
1306
1307 my $expected = 550;
1308 $self->assert($expected == $resp_code,
1309 test_msg("Expected response code $expected, got $resp_code"));
1310
1311 $expected = "$setup->{home_dir}: Not a regular file";
1312 $self->assert($expected eq $resp_msg,
1313 test_msg("Expected response message '$expected', got '$resp_msg'"));
1314 };
1315 if ($@) {
1316 $ex = $@;
1317 }
1318
1319 $wfh->print("done\n");
1320 $wfh->flush();
1321
1322 } else {
1323 eval { server_wait($setup->{config_file}, $rfh) };
1324 if ($@) {
1325 warn($@);
1326 exit 1;
1327 }
1328
1329 exit 0;
1330 }
1331
1332 # Stop server
1333 server_stop($setup->{pid_file});
1334 $self->assert_child_ok($pid);
1335
1336 test_cleanup($setup->{log_file}, $ex);
1337 }
1338
1339 sub stor_fails_login_required {
1340 my $self = shift;
1341 my $tmpdir = $self->{tmpdir};
1342 my $setup = test_setup($tmpdir, 'cmds');
1343
1344 my $config = {
1345 PidFile => $setup->{pid_file},
1346 ScoreboardFile => $setup->{scoreboard_file},
1347 SystemLog => $setup->{log_file},
1348
1349 IfModules => {
1350 'mod_delay.c' => {
1351 DelayEngine => 'off',
1352 },
1353 },
1354 };
1355
1356 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1357 $config);
1358
1359 # Open pipes, for use between the parent and child processes. Specifically,
1360 # the child will indicate when it's done with its test by writing a message
1361 # to the parent.
1362 my ($rfh, $wfh);
1363 unless (pipe($rfh, $wfh)) {
1364 die("Can't open pipe: $!");
1365 }
1366
1367 my $ex;
1368
1369 # Fork child
1370 $self->handle_sigchld();
1371 defined(my $pid = fork()) or die("Can't fork: $!");
1372 if ($pid) {
1373 eval {
1374 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1375
1376 eval { $client->stor($setup->{config_file}, '/dev/null') };
1377 unless ($@) {
1378 die("STOR succeeded unexpectedly");
1379 }
1380
1381 my $resp_code = $client->response_code();
1382 my $resp_msg = $client->response_msg();
1383 $client->quit();
1384
1385 my $expected = 530;
1386 $self->assert($expected == $resp_code,
1387 test_msg("Expected response code $expected, got $resp_code"));
1388
1389 $expected = "Please login with USER and PASS";
1390 $self->assert($expected eq $resp_msg,
1391 test_msg("Expected response message '$expected', got '$resp_msg'"));
1392 };
1393 if ($@) {
1394 $ex = $@;
1395 }
1396
1397 $wfh->print("done\n");
1398 $wfh->flush();
1399
1400 } else {
1401 eval { server_wait($setup->{config_file}, $rfh) };
1402 if ($@) {
1403 warn($@);
1404 exit 1;
1405 }
1406
1407 exit 0;
1408 }
1409
1410 # Stop server
1411 server_stop($setup->{pid_file});
1412 $self->assert_child_ok($pid);
1413
1414 test_cleanup($setup->{log_file}, $ex);
1415 }
1416
1417 sub stor_fails_no_path {
1418 my $self = shift;
1419 my $tmpdir = $self->{tmpdir};
1420 my $setup = test_setup($tmpdir, 'cmds');
1421
1422 my $config = {
1423 PidFile => $setup->{pid_file},
1424 ScoreboardFile => $setup->{scoreboard_file},
1425 SystemLog => $setup->{log_file},
1426
1427 AuthUserFile => $setup->{auth_user_file},
1428 AuthGroupFile => $setup->{auth_group_file},
1429 AuthOrder => 'mod_auth_file.c',
1430
1431 IfModules => {
1432 'mod_delay.c' => {
1433 DelayEngine => 'off',
1434 },
1435 },
1436 };
1437
1438 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1439 $config);
1440
1441 # Open pipes, for use between the parent and child processes. Specifically,
1442 # the child will indicate when it's done with its test by writing a message
1443 # to the parent.
1444 my ($rfh, $wfh);
1445 unless (pipe($rfh, $wfh)) {
1446 die("Can't open pipe: $!");
1447 }
1448
1449 my $ex;
1450
1451 # Fork child
1452 $self->handle_sigchld();
1453 defined(my $pid = fork()) or die("Can't fork: $!");
1454 if ($pid) {
1455 eval {
1456 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1457 $client->login($setup->{user}, $setup->{passwd});
1458
1459 eval { $client->stor($setup->{config_file}, '') };
1460 unless ($@) {
1461 die("STOR succeeded unexpectedly");
1462 }
1463
1464 my $resp_code = $client->response_code();
1465 my $resp_msg = $client->response_msg();
1466 $client->quit();
1467
1468 my $expected = 500;
1469 $self->assert($expected == $resp_code,
1470 test_msg("Expected response code $expected, got $resp_code"));
1471
1472 $expected = "'STOR' not understood";
1473 $self->assert($expected eq $resp_msg,
1474 test_msg("Expected response message '$expected', got '$resp_msg'"));
1475 };
1476 if ($@) {
1477 $ex = $@;
1478 }
1479
1480 print $wfh "done\n";
1481
1482 } else {
1483 eval { server_wait($setup->{config_file}, $rfh) };
1484 if ($@) {
1485 warn($@);
1486 exit 1;
1487 }
1488
1489 exit 0;
1490 }
1491
1492 # Stop server
1493 server_stop($setup->{pid_file});
1494 $self->assert_child_ok($pid);
1495
1496 test_cleanup($setup->{log_file}, $ex);
1497 }
1498
1499 sub stor_fails_eperm {
1500 my $self = shift;
1501 my $tmpdir = $self->{tmpdir};
1502 my $setup = test_setup($tmpdir, 'cmds');
1503
1504 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1505 mkpath($sub_dir);
1506
1507 my $src_file = File::Spec->rel2abs("$tmpdir/foo.txt");
1508 if (open(my $fh, "> $src_file")) {
1509 close($fh);
1510
1511 } else {
1512 die("Can't open $src_file: $!");
1513 }
1514
1515 my $dst_file = File::Spec->rel2abs("$sub_dir/bar.txt");
1516
1517 my $config = {
1518 PidFile => $setup->{pid_file},
1519 ScoreboardFile => $setup->{scoreboard_file},
1520 SystemLog => $setup->{log_file},
1521
1522 AuthUserFile => $setup->{auth_user_file},
1523 AuthGroupFile => $setup->{auth_group_file},
1524 AuthOrder => 'mod_auth_file.c',
1525
1526 IfModules => {
1527 'mod_delay.c' => {
1528 DelayEngine => 'off',
1529 },
1530 },
1531 };
1532
1533 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1534 $config);
1535
1536 # Open pipes, for use between the parent and child processes. Specifically,
1537 # the child will indicate when it's done with its test by writing a message
1538 # to the parent.
1539 my ($rfh, $wfh);
1540 unless (pipe($rfh, $wfh)) {
1541 die("Can't open pipe: $!");
1542 }
1543
1544 my $ex;
1545
1546 # Fork child
1547 $self->handle_sigchld();
1548 defined(my $pid = fork()) or die("Can't fork: $!");
1549 if ($pid) {
1550 eval {
1551 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1, 1);
1552 $client->login($setup->{user}, $setup->{passwd});
1553 $client->port();
1554
1555 chmod(0660, $sub_dir);
1556
1557 eval { $client->stor($src_file, $dst_file) };
1558 unless ($@) {
1559 die("STOR succeeded unexpectedly");
1560 }
1561
1562 my $resp_code = $client->response_code();
1563 my $resp_msg = $client->response_msg();
1564 $client->quit();
1565
1566 my $expected = 550;
1567 $self->assert($expected == $resp_code,
1568 test_msg("Expected response code $expected, got $resp_code"));
1569
1570 $expected = "$dst_file: Permission denied";
1571 $self->assert($expected eq $resp_msg,
1572 test_msg("Expected response message '$expected', got '$resp_msg'"));
1573 };
1574 if ($@) {
1575 $ex = $@;
1576 }
1577
1578 $wfh->print("done\n");
1579 $wfh->flush();
1580
1581 } else {
1582 eval { server_wait($setup->{config_file}, $rfh) };
1583 if ($@) {
1584 warn($@);
1585 exit 1;
1586 }
1587
1588 exit 0;
1589 }
1590
1591 # Stop server
1592 server_stop($setup->{pid_file});
1593 $self->assert_child_ok($pid);
1594
1595 test_cleanup($setup->{log_file}, $ex);
1596 }
1597
1598 sub stor_fails_abs_symlink_dir_enoent {
1599 my $self = shift;
1600 my $tmpdir = $self->{tmpdir};
1601 my $setup = test_setup($tmpdir, 'cmds');
1602
1603 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1604 mkpath($test_dir);
1605
1606 my $test_file = File::Spec->rel2abs("$test_dir/test.d/test.dat");
1607 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
1608
1609 my $dst_path = $test_file;
1610 if ($^O eq 'darwin') {
1611 # MacOSX-specific hack
1612 $dst_path = '/private' . $dst_path;
1613 }
1614
1615 unless (symlink($dst_path, $test_symlink)) {
1616 die("Can't symlink $test_symlink to $dst_path: $!");
1617 }
1618
1619 if ($< == 0) {
1620 unless (chmod(0755, $test_dir)) {
1621 die("Can't set perms on $test_dir to 0755: $!");
1622 }
1623
1624 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1625 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1626 }
1627 }
1628
1629 my $config = {
1630 PidFile => $setup->{pid_file},
1631 ScoreboardFile => $setup->{scoreboard_file},
1632 SystemLog => $setup->{log_file},
1633
1634 AuthUserFile => $setup->{auth_user_file},
1635 AuthGroupFile => $setup->{auth_group_file},
1636 AuthOrder => 'mod_auth_file.c',
1637
1638 AllowOverwrite => 'on',
1639 TransferOptions => 'AllowSymlinkUpload',
1640
1641 IfModules => {
1642 'mod_delay.c' => {
1643 DelayEngine => 'off',
1644 },
1645 },
1646 };
1647
1648 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1649 $config);
1650
1651 # Open pipes, for use between the parent and child processes. Specifically,
1652 # the child will indicate when it's done with its test by writing a message
1653 # to the parent.
1654 my ($rfh, $wfh);
1655 unless (pipe($rfh, $wfh)) {
1656 die("Can't open pipe: $!");
1657 }
1658
1659 my $ex;
1660
1661 # Fork child
1662 $self->handle_sigchld();
1663 defined(my $pid = fork()) or die("Can't fork: $!");
1664 if ($pid) {
1665 eval {
1666 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1667 $client->login($setup->{user}, $setup->{passwd});
1668 $client->type('binary');
1669
1670 my $path = 'sub.d/test.lnk';
1671 my $conn = $client->stor_raw($path);
1672 if ($conn) {
1673 die("STOR succeeded unexpectedly");
1674 }
1675
1676 my $resp_code = $client->response_code();
1677 my $resp_msg = $client->response_msg();
1678 $client->quit();
1679
1680 my $expected = 550;
1681 $self->assert($expected == $resp_code,
1682 test_msg("Expected response code $expected, got $resp_code"));
1683
1684 $expected = "$path: No such file or directory";
1685 $self->assert($expected eq $resp_msg,
1686 test_msg("Expected response message '$expected', got '$resp_msg'"));
1687 };
1688 if ($@) {
1689 $ex = $@;
1690 }
1691
1692 $wfh->print("done\n");
1693 $wfh->flush();
1694
1695 } else {
1696 eval { server_wait($setup->{config_file}, $rfh) };
1697 if ($@) {
1698 warn($@);
1699 exit 1;
1700 }
1701
1702 exit 0;
1703 }
1704
1705 # Stop server
1706 server_stop($setup->{pid_file});
1707 $self->assert_child_ok($pid);
1708
1709 test_cleanup($setup->{log_file}, $ex);
1710 }
1711
1712 sub stor_fails_abs_symlink_dir_enoent_chrooted_bug4219 {
1713 my $self = shift;
1714 my $tmpdir = $self->{tmpdir};
1715 my $setup = test_setup($tmpdir, 'cmds');
1716
1717 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1718 mkpath($test_dir);
1719
1720 my $test_file = File::Spec->rel2abs("$test_dir/test.d/test.dat");
1721 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
1722
1723 my $dst_path = $test_file;
1724 if ($^O eq 'darwin') {
1725 # MacOSX-specific hack
1726 $dst_path = '/private' . $dst_path;
1727 }
1728
1729 unless (symlink($dst_path, $test_symlink)) {
1730 die("Can't symlink $test_symlink to $dst_path: $!");
1731 }
1732
1733 if ($< == 0) {
1734 unless (chmod(0755, $test_dir)) {
1735 die("Can't set perms on $test_dir to 0755: $!");
1736 }
1737
1738 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1739 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1740 }
1741 }
1742
1743 my $config = {
1744 PidFile => $setup->{pid_file},
1745 ScoreboardFile => $setup->{scoreboard_file},
1746 SystemLog => $setup->{log_file},
1747
1748 AuthUserFile => $setup->{auth_user_file},
1749 AuthGroupFile => $setup->{auth_group_file},
1750 AuthOrder => 'mod_auth_file.c',
1751
1752 DefaultRoot => '~',
1753
1754 IfModules => {
1755 'mod_delay.c' => {
1756 DelayEngine => 'off',
1757 },
1758 },
1759 };
1760
1761 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1762 $config);
1763
1764 # Open pipes, for use between the parent and child processes. Specifically,
1765 # the child will indicate when it's done with its test by writing a message
1766 # to the parent.
1767 my ($rfh, $wfh);
1768 unless (pipe($rfh, $wfh)) {
1769 die("Can't open pipe: $!");
1770 }
1771
1772 my $ex;
1773
1774 # Fork child
1775 $self->handle_sigchld();
1776 defined(my $pid = fork()) or die("Can't fork: $!");
1777 if ($pid) {
1778 eval {
1779 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1780 $client->login($setup->{user}, $setup->{passwd});
1781 $client->type('binary');
1782
1783 my $path = 'sub.d/test.lnk';
1784 my $conn = $client->stor_raw($path);
1785 if ($conn) {
1786 die("STOR succeeded unexpectedly");
1787 }
1788
1789 my $resp_code = $client->response_code();
1790 my $resp_msg = $client->response_msg();
1791 $client->quit();
1792
1793 my $expected = 550;
1794 $self->assert($expected == $resp_code,
1795 test_msg("Expected response code $expected, got $resp_code"));
1796
1797 $expected = "$path: No such file or directory";
1798 $self->assert($expected eq $resp_msg,
1799 test_msg("Expected response message '$expected', got '$resp_msg'"));
1800 };
1801 if ($@) {
1802 $ex = $@;
1803 }
1804
1805 $wfh->print("done\n");
1806 $wfh->flush();
1807
1808 } else {
1809 eval { server_wait($setup->{config_file}, $rfh) };
1810 if ($@) {
1811 warn($@);
1812 exit 1;
1813 }
1814
1815 exit 0;
1816 }
1817
1818 # Stop server
1819 server_stop($setup->{pid_file});
1820 $self->assert_child_ok($pid);
1821
1822 test_cleanup($setup->{log_file}, $ex);
1823 }
1824
1825 sub stor_fails_rel_symlink_dir_enoent {
1826 my $self = shift;
1827 my $tmpdir = $self->{tmpdir};
1828 my $setup = test_setup($tmpdir, 'cmds');
1829
1830 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1831 mkpath($test_dir);
1832
1833 my $test_file = File::Spec->rel2abs("$test_dir/test.d/test.dat");
1834
1835 # Change to the test directory in order to create a relative path in the
1836 # symlink we need
1837
1838 my $cwd = getcwd();
1839 unless (chdir($test_dir)) {
1840 die("Can't chdir to $test_dir: $!");
1841 }
1842
1843 unless (symlink('./test.d/test.dat', './test.lnk')) {
1844 die("Can't symlink 'test.lnk' to './test.d/test.dat': $!");
1845 }
1846
1847 unless (chdir($cwd)) {
1848 die("Can't chdir to $cwd: $!");
1849 }
1850
1851 if ($< == 0) {
1852 unless (chmod(0755, $test_dir)) {
1853 die("Can't set perms on $test_dir to 0755: $!");
1854 }
1855
1856 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1857 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1858 }
1859 }
1860
1861 if ($< == 0) {
1862 unless (chmod(0755, $test_dir)) {
1863 die("Can't set perms on $test_dir to 0755: $!");
1864 }
1865
1866 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1867 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1868 }
1869 }
1870
1871 my $config = {
1872 PidFile => $setup->{pid_file},
1873 ScoreboardFile => $setup->{scoreboard_file},
1874 SystemLog => $setup->{log_file},
1875
1876 AuthUserFile => $setup->{auth_user_file},
1877 AuthGroupFile => $setup->{auth_group_file},
1878 AuthOrder => 'mod_auth_file.c',
1879
1880 AllowOverwrite => 'on',
1881 TransferOptions => 'AllowSymlinkUpload',
1882
1883 IfModules => {
1884 'mod_delay.c' => {
1885 DelayEngine => 'off',
1886 },
1887 },
1888 };
1889
1890 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1891 $config);
1892
1893 # Open pipes, for use between the parent and child processes. Specifically,
1894 # the child will indicate when it's done with its test by writing a message
1895 # to the parent.
1896 my ($rfh, $wfh);
1897 unless (pipe($rfh, $wfh)) {
1898 die("Can't open pipe: $!");
1899 }
1900
1901 my $ex;
1902
1903 # Fork child
1904 $self->handle_sigchld();
1905 defined(my $pid = fork()) or die("Can't fork: $!");
1906 if ($pid) {
1907 eval {
1908 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1909 $client->login($setup->{user}, $setup->{passwd});
1910 $client->type('binary');
1911
1912 my $path = 'sub.d/test.lnk';
1913 my $conn = $client->stor_raw($path);
1914 if ($conn) {
1915 die("STOR succeeded unexpectedly");
1916 }
1917
1918 my $resp_code = $client->response_code();
1919 my $resp_msg = $client->response_msg();
1920 $client->quit();
1921
1922 my $expected = 550;
1923 $self->assert($expected == $resp_code,
1924 test_msg("Expected response code $expected, got $resp_code"));
1925
1926 $expected = "$path: No such file or directory";
1927 $self->assert($expected eq $resp_msg,
1928 test_msg("Expected response message '$expected', got '$resp_msg'"));
1929 };
1930 if ($@) {
1931 $ex = $@;
1932 }
1933
1934 $wfh->print("done\n");
1935 $wfh->flush();
1936
1937 } else {
1938 eval { server_wait($setup->{config_file}, $rfh) };
1939 if ($@) {
1940 warn($@);
1941 exit 1;
1942 }
1943
1944 exit 0;
1945 }
1946
1947 # Stop server
1948 server_stop($setup->{pid_file});
1949 $self->assert_child_ok($pid);
1950
1951 test_cleanup($setup->{log_file}, $ex);
1952 }
1953
1954 sub stor_fails_rel_symlink_dir_enoent_chrooted_bug4219 {
1955 my $self = shift;
1956 my $tmpdir = $self->{tmpdir};
1957 my $setup = test_setup($tmpdir, 'cmds');
1958
1959 my $test_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1960 mkpath($test_dir);
1961
1962 my $test_file = File::Spec->rel2abs("$test_dir/test.d/test.dat");
1963
1964 # Change to the test directory in order to create a relative path in the
1965 # symlink we need
1966
1967 my $cwd = getcwd();
1968 unless (chdir($test_dir)) {
1969 die("Can't chdir to $test_dir: $!");
1970 }
1971
1972 unless (symlink('./test.d/test.dat', './test.lnk')) {
1973 die("Can't symlink 'test.lnk' to './test.d/test.dat': $!");
1974 }
1975
1976 unless (chdir($cwd)) {
1977 die("Can't chdir to $cwd: $!");
1978 }
1979
1980 if ($< == 0) {
1981 unless (chmod(0755, $test_dir)) {
1982 die("Can't set perms on $test_dir to 0755: $!");
1983 }
1984
1985 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1986 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1987 }
1988 }
1989
1990 if ($< == 0) {
1991 unless (chmod(0755, $test_dir)) {
1992 die("Can't set perms on $test_dir to 0755: $!");
1993 }
1994
1995 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1996 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1997 }
1998 }
1999
2000 my $config = {
2001 PidFile => $setup->{pid_file},
2002 ScoreboardFile => $setup->{scoreboard_file},
2003 SystemLog => $setup->{log_file},
2004
2005 AuthUserFile => $setup->{auth_user_file},
2006 AuthGroupFile => $setup->{auth_group_file},
2007 AuthOrder => 'mod_auth_file.c',
2008
2009 DefaultRoot => '~',
2010
2011 IfModules => {
2012 'mod_delay.c' => {
2013 DelayEngine => 'off',
2014 },
2015 },
2016 };
2017
2018 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2019 $config);
2020
2021 # Open pipes, for use between the parent and child processes. Specifically,
2022 # the child will indicate when it's done with its test by writing a message
2023 # to the parent.
2024 my ($rfh, $wfh);
2025 unless (pipe($rfh, $wfh)) {
2026 die("Can't open pipe: $!");
2027 }
2028
2029 my $ex;
2030
2031 # Fork child
2032 $self->handle_sigchld();
2033 defined(my $pid = fork()) or die("Can't fork: $!");
2034 if ($pid) {
2035 eval {
2036 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2037 $client->login($setup->{user}, $setup->{passwd});
2038 $client->type('binary');
2039
2040 my $path = 'sub.d/test.lnk';
2041 my $conn = $client->stor_raw($path);
2042 if ($conn) {
2043 die("STOR succeeded unexpectedly");
2044 }
2045
2046 my $resp_code = $client->response_code();
2047 my $resp_msg = $client->response_msg();
2048 $client->quit();
2049
2050 my $expected = 550;
2051 $self->assert($expected == $resp_code,
2052 test_msg("Expected response code $expected, got $resp_code"));
2053
2054 $expected = "$path: No such file or directory";
2055 $self->assert($expected eq $resp_msg,
2056 test_msg("Expected response message '$expected', got '$resp_msg'"));
2057 };
2058 if ($@) {
2059 $ex = $@;
2060 }
2061
2062 $wfh->print("done\n");
2063 $wfh->flush();
2064
2065 } else {
2066 eval { server_wait($setup->{config_file}, $rfh) };
2067 if ($@) {
2068 warn($@);
2069 exit 1;
2070 }
2071
2072 exit 0;
2073 }
2074
2075 # Stop server
2076 server_stop($setup->{pid_file});
2077 $self->assert_child_ok($pid);
2078
2079 test_cleanup($setup->{log_file}, $ex);
2080 }
2081
2082 sub stor_leading_whitespace {
2083 my $self = shift;
2084 my $tmpdir = $self->{tmpdir};
2085 my $setup = test_setup($tmpdir, 'cmds');
2086
2087 my $test_file = File::Spec->rel2abs("$tmpdir/ test.txt");
2088
2089 my $config = {
2090 PidFile => $setup->{pid_file},
2091 ScoreboardFile => $setup->{scoreboard_file},
2092 SystemLog => $setup->{log_file},
2093
2094 AuthUserFile => $setup->{auth_user_file},
2095 AuthGroupFile => $setup->{auth_group_file},
2096 AuthOrder => 'mod_auth_file.c',
2097
2098 IfModules => {
2099 'mod_delay.c' => {
2100 DelayEngine => 'off',
2101 },
2102 },
2103 };
2104
2105 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2106 $config);
2107
2108 # Open pipes, for use between the parent and child processes. Specifically,
2109 # the child will indicate when it's done with its test by writing a message
2110 # to the parent.
2111 my ($rfh, $wfh);
2112 unless (pipe($rfh, $wfh)) {
2113 die("Can't open pipe: $!");
2114 }
2115
2116 my $ex;
2117
2118 # Fork child
2119 $self->handle_sigchld();
2120 defined(my $pid = fork()) or die("Can't fork: $!");
2121 if ($pid) {
2122 eval {
2123 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2124 $client->login($setup->{user}, $setup->{passwd});
2125
2126 my $conn = $client->stor_raw(' test.txt');
2127 unless ($conn) {
2128 die("Failed to STOR: " . $client->response_code() . " " .
2129 $client->response_msg());
2130 }
2131
2132 my $buf = "Foo!\n";
2133 $conn->write($buf, length($buf), 25);
2134 eval { $conn->close() };
2135
2136 my $resp_code = $client->response_code();
2137 my $resp_msg = $client->response_msg();
2138 $self->assert_transfer_ok($resp_code, $resp_msg);
2139 $client->quit();
2140
2141 unless (-f $test_file) {
2142 die("File $test_file does not exist as expected");
2143 }
2144 };
2145 if ($@) {
2146 $ex = $@;
2147 }
2148
2149 $wfh->print("done\n");
2150 $wfh->flush();
2151
2152 } else {
2153 eval { server_wait($setup->{config_file}, $rfh) };
2154 if ($@) {
2155 warn($@);
2156 exit 1;
2157 }
2158
2159 exit 0;
2160 }
2161
2162 # Stop server
2163 server_stop($setup->{pid_file});
2164 $self->assert_child_ok($pid);
2165
2166 test_cleanup($setup->{log_file}, $ex);
2167 }
2168
2169 sub stor_multiple_periods {
2170 my $self = shift;
2171 my $tmpdir = $self->{tmpdir};
2172 my $setup = test_setup($tmpdir, 'cmds');
2173
2174 my $test_file = File::Spec->rel2abs("$tmpdir/multi...dot...file.txt");
2175
2176 my $config = {
2177 PidFile => $setup->{pid_file},
2178 ScoreboardFile => $setup->{scoreboard_file},
2179 SystemLog => $setup->{log_file},
2180
2181 AuthUserFile => $setup->{auth_user_file},
2182 AuthGroupFile => $setup->{auth_group_file},
2183 AuthOrder => 'mod_auth_file.c',
2184
2185 IfModules => {
2186 'mod_delay.c' => {
2187 DelayEngine => 'off',
2188 },
2189 },
2190 };
2191
2192 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2193 $config);
2194
2195 # Open pipes, for use between the parent and child processes. Specifically,
2196 # the child will indicate when it's done with its test by writing a message
2197 # to the parent.
2198 my ($rfh, $wfh);
2199 unless (pipe($rfh, $wfh)) {
2200 die("Can't open pipe: $!");
2201 }
2202
2203 my $ex;
2204
2205 # Fork child
2206 $self->handle_sigchld();
2207 defined(my $pid = fork()) or die("Can't fork: $!");
2208 if ($pid) {
2209 eval {
2210 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2211 $client->login($setup->{user}, $setup->{passwd});
2212
2213 my $conn = $client->stor_raw('multi...dot...file.txt');
2214 unless ($conn) {
2215 die("Failed to STOR: " . $client->response_code() . " " .
2216 $client->response_msg());
2217 }
2218
2219 my $buf = "Foo!\n";
2220 $conn->write($buf, length($buf), 25);
2221 eval { $conn->close() };
2222
2223 my $resp_code = $client->response_code();
2224 my $resp_msg = $client->response_msg();
2225 $self->assert_transfer_ok($resp_code, $resp_msg);
2226
2227 $client->quit();
2228
2229 unless (-f $test_file) {
2230 die("File $test_file does not exist as expected");
2231 }
2232 };
2233 if ($@) {
2234 $ex = $@;
2235 }
2236
2237 $wfh->print("done\n");
2238 $wfh->flush();
2239
2240 } else {
2241 eval { server_wait($setup->{config_file}, $rfh) };
2242 if ($@) {
2243 warn($@);
2244 exit 1;
2245 }
2246
2247 exit 0;
2248 }
2249
2250 # Stop server
2251 server_stop($setup->{pid_file});
2252 $self->assert_child_ok($pid);
2253
2254 test_cleanup($setup->{log_file}, $ex);
2255 }
2256
2257 1;