Debian Codegraph @

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

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