Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::RNTO;
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 rnto_ok => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 rnto_abs_symlink => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 rnto_rel_symlink => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 rnto_fails_login_required => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 rnto_fails_no_rnfr => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 rnto_fails_enoent_no_file => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 rnto_fails_enoent_no_dir => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 rnto_fails_eperm => {
56 order => ++$order,
57 test_class => [qw(forking)],
58 },
59
60 rnto_fails_allow_overwrite => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 rnto_fails_allow_overwrite => {
66 order => ++$order,
67 test_class => [qw(forking)],
68 },
69
70 rnto_fails_device_full_bug3354 => {
71 order => ++$order,
72 test_class => [qw(forking os_linux)],
73 },
74
75 rnto_symlink_bug3754 => {
76 order => ++$order,
77 test_class => [qw(bug forking)],
78 },
79
80 rnto_lowercase_issue1023 => {
81 order => ++$order,
82 test_class => [qw(bug forking)],
83 },
84
85 rnto_user_pass_issue2003 => {
86 order => ++$order,
87 test_class => [qw(bug forking)],
88 },
89
90 };
91
92 sub new {
93 return shift()->SUPER::new(@_);
94 }
95
96 sub list_tests {
97 return testsuite_get_runnable_tests($TESTS);
98 }
99
100 sub rnto_ok {
101 my $self = shift;
102 my $tmpdir = $self->{tmpdir};
103 my $setup = test_setup($tmpdir, 'cmds');
104
105 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
106 mkpath($test_dir);
107
108 my $src_file = File::Spec->rel2abs("$test_dir/test.txt");
109 if (open(my $fh, "> $src_file")) {
110 close($fh);
111
112 } else {
113 die("Can't open $src_file: $!");
114 }
115
116 my $dst_file = File::Spec->rel2abs("$test_dir/bar.txt");
117
118 if ($< == 0) {
119 unless (chmod(0755, $test_dir)) {
120 die("Can't set perms on $test_dir to 0755: $!");
121 }
122
123 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
124 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
125 }
126 }
127
128 my $config = {
129 PidFile => $setup->{pid_file},
130 ScoreboardFile => $setup->{scoreboard_file},
131 SystemLog => $setup->{log_file},
132
133 AuthUserFile => $setup->{auth_user_file},
134 AuthGroupFile => $setup->{auth_group_file},
135 AuthOrder => 'mod_auth_file.c',
136
137 IfModules => {
138 'mod_delay.c' => {
139 DelayEngine => 'off',
140 },
141 },
142 };
143
144 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
145 $config);
146
147 # Open pipes, for use between the parent and child processes. Specifically,
148 # the child will indicate when it's done with its test by writing a message
149 # to the parent.
150 my ($rfh, $wfh);
151 unless (pipe($rfh, $wfh)) {
152 die("Can't open pipe: $!");
153 }
154
155 my $ex;
156
157 # Fork child
158 $self->handle_sigchld();
159 defined(my $pid = fork()) or die("Can't fork: $!");
160 if ($pid) {
161 eval {
162 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
163 $client->login($setup->{user}, $setup->{passwd});
164
165 my ($resp_code, $resp_msg) = $client->rnfr($src_file);
166 ($resp_code, $resp_msg) = $client->rnto($dst_file);
167
168 my $expected = 250;
169 $self->assert($expected == $resp_code,
170 test_msg("Expected response code $expected, got $resp_code"));
171
172 $expected = "Rename successful";
173 $self->assert($expected eq $resp_msg,
174 test_msg("Expected response message '$expected', got '$resp_msg'"));
175
176 $self->assert(!-f $src_file,
177 test_msg("File $src_file exists unexpectedly"));
178 $self->assert(-f $dst_file,
179 test_msg("File $dst_file does not exist as expected"));
180 };
181 if ($@) {
182 $ex = $@;
183 }
184
185 $wfh->print("done\n");
186 $wfh->flush();
187
188 } else {
189 eval { server_wait($setup->{config_file}, $rfh) };
190 if ($@) {
191 warn($@);
192 exit 1;
193 }
194
195 exit 0;
196 }
197
198 # Stop server
199 server_stop($setup->{pid_file});
200 $self->assert_child_ok($pid);
201
202 test_cleanup($setup->{log_file}, $ex);
203 }
204
205 sub rnto_abs_symlink {
206 my $self = shift;
207 my $tmpdir = $self->{tmpdir};
208 my $setup = test_setup($tmpdir, 'cmds');
209
210 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
211 mkpath($test_dir);
212
213 my $src_file = File::Spec->rel2abs("$test_dir/foo.txt");
214 if (open(my $fh, "> $src_file")) {
215 close($fh);
216
217 } else {
218 die("Can't open $src_file: $!");
219 }
220
221 my $dst_file = File::Spec->rel2abs("$test_dir/bar.txt");
222 my $dst_symlink = File::Spec->rel2abs("$test_dir/bar.lnk");
223
224 my $dst_path = $dst_file;
225 if ($^O eq 'darwin') {
226 # MacOSX-specific hack
227 $dst_path = '/private' . $dst_path;
228 }
229
230 unless (symlink($dst_path, $dst_symlink)) {
231 die("Can't symlink $dst_symlink to $dst_path: $!");
232 }
233
234 if ($< == 0) {
235 unless (chmod(0755, $test_dir)) {
236 die("Can't set perms on $test_dir to 0755: $!");
237 }
238
239 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
240 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
241 }
242 }
243
244 my $config = {
245 PidFile => $setup->{pid_file},
246 ScoreboardFile => $setup->{scoreboard_file},
247 SystemLog => $setup->{log_file},
248
249 AuthUserFile => $setup->{auth_user_file},
250 AuthGroupFile => $setup->{auth_group_file},
251 AuthOrder => 'mod_auth_file.c',
252
253 IfModules => {
254 'mod_delay.c' => {
255 DelayEngine => 'off',
256 },
257 },
258 };
259
260 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
261 $config);
262
263 # Open pipes, for use between the parent and child processes. Specifically,
264 # the child will indicate when it's done with its test by writing a message
265 # to the parent.
266 my ($rfh, $wfh);
267 unless (pipe($rfh, $wfh)) {
268 die("Can't open pipe: $!");
269 }
270
271 my $ex;
272
273 # Fork child
274 $self->handle_sigchld();
275 defined(my $pid = fork()) or die("Can't fork: $!");
276 if ($pid) {
277 eval {
278 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
279 $client->login($setup->{user}, $setup->{passwd});
280
281 my $src_path = 'test.d/foo.txt';
282 $client->rnfr($src_path);
283
284 $dst_path = 'test.d/bar.lnk';
285 my ($resp_code, $resp_msg) = $client->rnto($dst_path);
286 $client->quit();
287
288 my $expected = 250;
289 $self->assert($expected == $resp_code,
290 test_msg("Expected response code $expected, got $resp_code"));
291
292 $expected = "Rename successful";
293 $self->assert($expected eq $resp_msg,
294 test_msg("Expected response message '$expected', got '$resp_msg'"));
295
296 $self->assert(!-f $src_file,
297 test_msg("File $src_file exists unexpectedly"));
298
299 # rename(2) works by DELETING the destination file, if it exists.
300 # This means that it does NOT follow a symlink link.
301
302 $self->assert(!-f $dst_file,
303 test_msg("File $dst_file exists unexpectedly"));
304
305 $self->assert(!-l $dst_symlink,
306 test_msg("Symlink $dst_symlink exists unexpectedly"));
307
308 $self->assert(-f $dst_symlink,
309 test_msg("File $dst_symlink does not exist as expected"));
310 };
311 if ($@) {
312 $ex = $@;
313 }
314
315 $wfh->print("done\n");
316 $wfh->flush();
317
318 } else {
319 eval { server_wait($setup->{config_file}, $rfh) };
320 if ($@) {
321 warn($@);
322 exit 1;
323 }
324
325 exit 0;
326 }
327
328 # Stop server
329 server_stop($setup->{pid_file});
330 $self->assert_child_ok($pid);
331
332 test_cleanup($setup->{log_file}, $ex);
333 }
334
335 sub rnto_rel_symlink {
336 my $self = shift;
337 my $tmpdir = $self->{tmpdir};
338 my $setup = test_setup($tmpdir, 'cmds');
339
340 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
341 mkpath($test_dir);
342
343 my $src_file = File::Spec->rel2abs("$test_dir/foo.txt");
344 if (open(my $fh, "> $src_file")) {
345 close($fh);
346
347 } else {
348 die("Can't open $src_file: $!");
349 }
350
351 my $dst_file = File::Spec->rel2abs("$test_dir/bar.txt");
352 my $dst_symlink = File::Spec->rel2abs("$test_dir/bar.lnk");
353
354 # Change to the test directory in order to create a relative path in the
355 # symlink we need
356
357 my $cwd = getcwd();
358 unless (chdir($test_dir)) {
359 die("Can't chdir to $test_dir: $!");
360 }
361
362 unless (symlink('./bar.txt', './bar.lnk')) {
363 die("Can't symlink 'bar.lnk' to './bar.txt': $!");
364 }
365
366 unless (chdir($cwd)) {
367 die("Can't chdir to $cwd: $!");
368 }
369
370 if ($< == 0) {
371 unless (chmod(0755, $test_dir)) {
372 die("Can't set perms on $test_dir to 0755: $!");
373 }
374
375 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
376 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
377 }
378 }
379
380 my $config = {
381 PidFile => $setup->{pid_file},
382 ScoreboardFile => $setup->{scoreboard_file},
383 SystemLog => $setup->{log_file},
384
385 AuthUserFile => $setup->{auth_user_file},
386 AuthGroupFile => $setup->{auth_group_file},
387 AuthOrder => 'mod_auth_file.c',
388
389 IfModules => {
390 'mod_delay.c' => {
391 DelayEngine => 'off',
392 },
393 },
394 };
395
396 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
397 $config);
398
399 # Open pipes, for use between the parent and child processes. Specifically,
400 # the child will indicate when it's done with its test by writing a message
401 # to the parent.
402 my ($rfh, $wfh);
403 unless (pipe($rfh, $wfh)) {
404 die("Can't open pipe: $!");
405 }
406
407 my $ex;
408
409 # Fork child
410 $self->handle_sigchld();
411 defined(my $pid = fork()) or die("Can't fork: $!");
412 if ($pid) {
413 eval {
414 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
415 $client->login($setup->{user}, $setup->{passwd});
416
417 my $src_path = 'test.d/foo.txt';
418 $client->rnfr($src_path);
419
420 my $dst_path = 'test.d/bar.lnk';
421 my ($resp_code, $resp_msg) = $client->rnto($dst_path);
422 $client->quit();
423
424 my $expected = 250;
425 $self->assert($expected == $resp_code,
426 test_msg("Expected response code $expected, got $resp_code"));
427
428 $expected = "Rename successful";
429 $self->assert($expected eq $resp_msg,
430 test_msg("Expected response message '$expected', got '$resp_msg'"));
431
432 $self->assert(!-f $src_file,
433 test_msg("File $src_file exists unexpectedly"));
434
435 # rename(2) works by DELETING the destination file, if it exists.
436 # This means that it does NOT follow a symlink link.
437
438 $self->assert(!-f $dst_file,
439 test_msg("File $dst_file exists unexpectedly"));
440
441 $self->assert(!-l $dst_symlink,
442 test_msg("Symlink $dst_symlink exists unexpectedly"));
443
444 $self->assert(-f $dst_symlink,
445 test_msg("File $dst_symlink does not exist as expected"));
446 };
447 if ($@) {
448 $ex = $@;
449 }
450
451 $wfh->print("done\n");
452 $wfh->flush();
453
454 } else {
455 eval { server_wait($setup->{config_file}, $rfh) };
456 if ($@) {
457 warn($@);
458 exit 1;
459 }
460
461 exit 0;
462 }
463
464 # Stop server
465 server_stop($setup->{pid_file});
466 $self->assert_child_ok($pid);
467
468 test_cleanup($setup->{log_file}, $ex);
469 }
470
471 sub rnto_fails_login_required {
472 my $self = shift;
473 my $tmpdir = $self->{tmpdir};
474
475 my $config_file = "$tmpdir/cmds.conf";
476 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
477 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
478
479 my $log_file = test_get_logfile();
480
481 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
482 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
483
484 my $user = 'proftpd';
485 my $passwd = 'test';
486 my $group = 'ftpd';
487 my $home_dir = File::Spec->rel2abs($tmpdir);
488 my $uid = 500;
489 my $gid = 500;
490
491 my $dst_file = File::Spec->rel2abs("$tmpdir/bar");
492
493 # Make sure that, if we're running as root, that the home directory has
494 # permissions/privs set for the account we create
495 if ($< == 0) {
496 unless (chmod(0755, $home_dir)) {
497 die("Can't set perms on $home_dir to 0755: $!");
498 }
499
500 unless (chown($uid, $gid, $home_dir)) {
501 die("Can't set owner of $home_dir to $uid/$gid: $!");
502 }
503 }
504
505 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
506 '/bin/bash');
507 auth_group_write($auth_group_file, $group, $gid, $user);
508
509 my $config = {
510 PidFile => $pid_file,
511 ScoreboardFile => $scoreboard_file,
512 SystemLog => $log_file,
513
514 AuthUserFile => $auth_user_file,
515 AuthGroupFile => $auth_group_file,
516 AuthOrder => 'mod_auth_file.c',
517
518 IfModules => {
519 'mod_delay.c' => {
520 DelayEngine => 'off',
521 },
522 },
523 };
524
525 my ($port, $config_user, $config_group) = config_write($config_file, $config);
526
527 # Open pipes, for use between the parent and child processes. Specifically,
528 # the child will indicate when it's done with its test by writing a message
529 # to the parent.
530 my ($rfh, $wfh);
531 unless (pipe($rfh, $wfh)) {
532 die("Can't open pipe: $!");
533 }
534
535 my $ex;
536
537 # Fork child
538 $self->handle_sigchld();
539 defined(my $pid = fork()) or die("Can't fork: $!");
540 if ($pid) {
541 eval {
542 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
543
544 my ($resp_code, $resp_msg);
545 eval { ($resp_code, $resp_msg) = $client->rnfr($dst_file) };
546 unless ($@) {
547 die("RNFR succeeded unexpectedly");
548
549 } else {
550 $resp_code = $client->response_code();
551 $resp_msg = $client->response_msg();
552 }
553
554 my $expected;
555
556 $expected = 530;
557 $self->assert($expected == $resp_code,
558 test_msg("Expected $expected, got $resp_code"));
559
560 $expected = "Please login with USER and PASS";
561 $self->assert($expected eq $resp_msg,
562 test_msg("Expected '$expected', got '$resp_msg'"));
563 };
564
565 if ($@) {
566 $ex = $@;
567 }
568
569 $wfh->print("done\n");
570 $wfh->flush();
571
572 } else {
573 eval { server_wait($config_file, $rfh) };
574 if ($@) {
575 warn($@);
576 exit 1;
577 }
578
579 exit 0;
580 }
581
582 # Stop server
583 server_stop($pid_file);
584
585 $self->assert_child_ok($pid);
586
587 if ($ex) {
588 test_append_logfile($log_file, $ex);
589 unlink($log_file);
590
591 die($ex);
592 }
593
594 unlink($log_file);
595 }
596
597 sub rnto_fails_no_rnfr {
598 my $self = shift;
599 my $tmpdir = $self->{tmpdir};
600
601 my $config_file = "$tmpdir/cmds.conf";
602 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
603 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
604
605 my $log_file = test_get_logfile();
606
607 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
608 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
609
610 my $user = 'proftpd';
611 my $passwd = 'test';
612 my $group = 'ftpd';
613 my $home_dir = File::Spec->rel2abs($tmpdir);
614 my $uid = 500;
615 my $gid = 500;
616
617 my $dst_file = File::Spec->rel2abs("$tmpdir/foo");
618
619 # Make sure that, if we're running as root, that the home directory has
620 # permissions/privs set for the account we create
621 if ($< == 0) {
622 unless (chmod(0755, $home_dir)) {
623 die("Can't set perms on $home_dir to 0755: $!");
624 }
625
626 unless (chown($uid, $gid, $home_dir)) {
627 die("Can't set owner of $home_dir to $uid/$gid: $!");
628 }
629 }
630
631 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
632 '/bin/bash');
633 auth_group_write($auth_group_file, $group, $gid, $user);
634
635 my $config = {
636 PidFile => $pid_file,
637 ScoreboardFile => $scoreboard_file,
638 SystemLog => $log_file,
639
640 AuthUserFile => $auth_user_file,
641 AuthGroupFile => $auth_group_file,
642 AuthOrder => 'mod_auth_file.c',
643
644 IfModules => {
645 'mod_delay.c' => {
646 DelayEngine => 'off',
647 },
648 },
649 };
650
651 my ($port, $config_user, $config_group) = config_write($config_file, $config);
652
653 # Open pipes, for use between the parent and child processes. Specifically,
654 # the child will indicate when it's done with its test by writing a message
655 # to the parent.
656 my ($rfh, $wfh);
657 unless (pipe($rfh, $wfh)) {
658 die("Can't open pipe: $!");
659 }
660
661 my $ex;
662
663 # Fork child
664 $self->handle_sigchld();
665 defined(my $pid = fork()) or die("Can't fork: $!");
666 if ($pid) {
667 eval {
668 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
669
670 $client->login($user, $passwd);
671
672 my ($resp_code, $resp_msg);
673 eval { ($resp_code, $resp_msg) = $client->rnto($dst_file) };
674 unless ($@) {
675 die("RNFR succeeded unexpectedly");
676
677 } else {
678 $resp_code = $client->response_code();
679 $resp_msg = $client->response_msg();
680 }
681
682 my $expected;
683
684 $expected = 503;
685 $self->assert($expected == $resp_code,
686 test_msg("Expected $expected, got $resp_code"));
687
688 $expected = "Bad sequence of commands";
689 $self->assert($expected eq $resp_msg,
690 test_msg("Expected '$expected', got '$resp_msg'"));
691 };
692
693 if ($@) {
694 $ex = $@;
695 }
696
697 $wfh->print("done\n");
698 $wfh->flush();
699
700 } else {
701 eval { server_wait($config_file, $rfh) };
702 if ($@) {
703 warn($@);
704 exit 1;
705 }
706
707 exit 0;
708 }
709
710 # Stop server
711 server_stop($pid_file);
712
713 $self->assert_child_ok($pid);
714
715 if ($ex) {
716 test_append_logfile($log_file, $ex);
717 unlink($log_file);
718
719 die($ex);
720 }
721
722 unlink($log_file);
723 }
724
725 sub rnto_fails_enoent_no_file {
726 my $self = shift;
727 my $tmpdir = $self->{tmpdir};
728 my $setup = test_setup($tmpdir, 'cmds');
729
730 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
731 mkpath($test_dir);
732
733 my $src_file = File::Spec->rel2abs("$test_dir/src.txt");
734 if (open(my $fh, "> $src_file")) {
735 close($fh);
736
737 } else {
738 die("Can't open $src_file: $!");
739 }
740
741 my $dst_file = File::Spec->rel2abs("$test_dir/dst.txt");
742
743 if ($< == 0) {
744 unless (chmod(0755, $test_dir)) {
745 die("Can't set perms on $test_dir to 0755: $!");
746 }
747
748 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
749 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
750 }
751 }
752
753 my $config = {
754 PidFile => $setup->{pid_file},
755 ScoreboardFile => $setup->{scoreboard_file},
756 SystemLog => $setup->{log_file},
757
758 AuthUserFile => $setup->{auth_user_file},
759 AuthGroupFile => $setup->{auth_group_file},
760 AuthOrder => 'mod_auth_file.c',
761
762 IfModules => {
763 'mod_delay.c' => {
764 DelayEngine => 'off',
765 },
766 },
767 };
768
769 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
770 $config);
771
772 # Open pipes, for use between the parent and child processes. Specifically,
773 # the child will indicate when it's done with its test by writing a message
774 # to the parent.
775 my ($rfh, $wfh);
776 unless (pipe($rfh, $wfh)) {
777 die("Can't open pipe: $!");
778 }
779
780 my $ex;
781
782 # Fork child
783 $self->handle_sigchld();
784 defined(my $pid = fork()) or die("Can't fork: $!");
785 if ($pid) {
786 eval {
787 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
788 $client->login($setup->{user}, $setup->{passwd});
789
790 my ($resp_code, $resp_msg) = $client->rnfr($src_file);
791 unlink($src_file);
792
793 eval { $client->rnto($dst_file) };
794 unless ($@) {
795 die("RNTO succeeded unexpectedly");
796 }
797
798 $resp_code = $client->response_code();
799 $resp_msg = $client->response_msg();
800 $client->quit();
801
802 my $expected = 550;
803 $self->assert($expected == $resp_code,
804 "Expected response code $expected, got $resp_code");
805
806 $expected = "$dst_file: No such file or directory";
807 $self->assert($expected eq $resp_msg,
808 "Expected response message '$expected', got '$resp_msg'");
809 };
810 if ($@) {
811 $ex = $@;
812 }
813
814 $wfh->print("done\n");
815 $wfh->flush();
816
817 } else {
818 eval { server_wait($setup->{config_file}, $rfh) };
819 if ($@) {
820 warn($@);
821 exit 1;
822 }
823
824 exit 0;
825 }
826
827 # Stop server
828 server_stop($setup->{pid_file});
829 $self->assert_child_ok($pid);
830
831 test_cleanup($setup->{log_file}, $ex);
832 }
833
834 sub rnto_fails_enoent_no_dir {
835 my $self = shift;
836 my $tmpdir = $self->{tmpdir};
837 my $setup = test_setup($tmpdir, 'cmds');
838
839 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
840 mkpath($test_dir);
841
842 my $src_file = File::Spec->rel2abs("$test_dir/src.txt");
843 if (open(my $fh, "> $src_file")) {
844 close($fh);
845
846 } else {
847 die("Can't open $src_file: $!");
848 }
849
850 my $dst_file = File::Spec->rel2abs("$test_dir/foo.d/dst.txt");
851
852 if ($< == 0) {
853 unless (chmod(0755, $test_dir)) {
854 die("Can't set perms on $test_dir to 0755: $!");
855 }
856
857 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
858 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
859 }
860 }
861
862 my $config = {
863 PidFile => $setup->{pid_file},
864 ScoreboardFile => $setup->{scoreboard_file},
865 SystemLog => $setup->{log_file},
866
867 AuthUserFile => $setup->{auth_user_file},
868 AuthGroupFile => $setup->{auth_group_file},
869 AuthOrder => 'mod_auth_file.c',
870
871 IfModules => {
872 'mod_delay.c' => {
873 DelayEngine => 'off',
874 },
875 },
876 };
877
878 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
879 $config);
880
881 # Open pipes, for use between the parent and child processes. Specifically,
882 # the child will indicate when it's done with its test by writing a message
883 # to the parent.
884 my ($rfh, $wfh);
885 unless (pipe($rfh, $wfh)) {
886 die("Can't open pipe: $!");
887 }
888
889 my $ex;
890
891 # Fork child
892 $self->handle_sigchld();
893 defined(my $pid = fork()) or die("Can't fork: $!");
894 if ($pid) {
895 eval {
896 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
897 $client->login($setup->{user}, $setup->{passwd});
898
899 $client->rnfr($src_file);
900 eval { $client->rnto($dst_file) };
901 unless ($@) {
902 die("RNTO succeeded unexpectedly");
903 }
904
905 my $resp_code = $client->response_code();
906 my $resp_msg = $client->response_msg();
907 $client->quit();
908
909 my $expected = 550;
910 $self->assert($expected == $resp_code,
911 "Expected response code $expected, got $resp_code");
912
913 $expected = "$dst_file: No such file or directory";
914 $self->assert($expected eq $resp_msg,
915 "Expected response message '$expected', got '$resp_msg'");
916 };
917 if ($@) {
918 $ex = $@;
919 }
920
921 $wfh->print("done\n");
922 $wfh->flush();
923
924 } else {
925 eval { server_wait($setup->{config_file}, $rfh) };
926 if ($@) {
927 warn($@);
928 exit 1;
929 }
930
931 exit 0;
932 }
933
934 # Stop server
935 server_stop($setup->{pid_file});
936 $self->assert_child_ok($pid);
937
938 test_cleanup($setup->{log_file}, $ex);
939 }
940
941 sub rnto_fails_eperm {
942 my $self = shift;
943 my $tmpdir = $self->{tmpdir};
944
945 my $config_file = "$tmpdir/cmds.conf";
946 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
947 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
948
949 my $log_file = test_get_logfile();
950
951 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
952 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
953
954 my $user = 'proftpd';
955 my $passwd = 'test';
956 my $group = 'ftpd';
957 my $home_dir = File::Spec->rel2abs($tmpdir);
958 my $uid = 500;
959 my $gid = 500;
960
961 my $src_file = File::Spec->rel2abs("$tmpdir/foo");
962 if (open(my $fh, "> $src_file")) {
963 close($fh);
964
965 } else {
966 die("Can't open $src_file: $!");
967 }
968
969 my $dst_file = File::Spec->rel2abs("$tmpdir/bar");
970
971 # Make sure that, if we're running as root, that the home directory has
972 # permissions/privs set for the account we create
973 if ($< == 0) {
974 unless (chmod(0755, $home_dir)) {
975 die("Can't set perms on $home_dir to 0755: $!");
976 }
977
978 unless (chown($uid, $gid, $home_dir)) {
979 die("Can't set owner of $home_dir to $uid/$gid: $!");
980 }
981 }
982
983 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
984 '/bin/bash');
985 auth_group_write($auth_group_file, $group, $gid, $user);
986
987 my $config = {
988 PidFile => $pid_file,
989 ScoreboardFile => $scoreboard_file,
990 SystemLog => $log_file,
991
992 AuthUserFile => $auth_user_file,
993 AuthGroupFile => $auth_group_file,
994 AuthOrder => 'mod_auth_file.c',
995
996 IfModules => {
997 'mod_delay.c' => {
998 DelayEngine => 'off',
999 },
1000 },
1001 };
1002
1003 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1004
1005 # Open pipes, for use between the parent and child processes. Specifically,
1006 # the child will indicate when it's done with its test by writing a message
1007 # to the parent.
1008 my ($rfh, $wfh);
1009 unless (pipe($rfh, $wfh)) {
1010 die("Can't open pipe: $!");
1011 }
1012
1013 my $ex;
1014
1015 # Fork child
1016 $self->handle_sigchld();
1017 defined(my $pid = fork()) or die("Can't fork: $!");
1018 if ($pid) {
1019 eval {
1020 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1021
1022 $client->login($user, $passwd);
1023
1024 my ($resp_code, $resp_msg);
1025 ($resp_code, $resp_msg) = $client->rnfr($src_file);
1026
1027 chmod(0550, $home_dir);
1028
1029 eval { ($resp_code, $resp_msg) = $client->rnto($dst_file) };
1030 unless ($@) {
1031 die("RNTO succeeded unexpectedly");
1032
1033 } else {
1034 $resp_code = $client->response_code();
1035 $resp_msg = $client->response_msg();
1036 }
1037
1038 my $expected;
1039
1040 $expected = 550;
1041 $self->assert($expected == $resp_code,
1042 "Expected response code $expected, got $resp_code");
1043
1044 $expected = "$dst_file: Permission denied";
1045 $self->assert($expected eq $resp_msg,
1046 "Expected response message '$expected', got '$resp_msg'");
1047 };
1048 if ($@) {
1049 $ex = $@;
1050 }
1051
1052 $wfh->print("done\n");
1053 $wfh->flush();
1054
1055 } else {
1056 eval { server_wait($config_file, $rfh) };
1057 if ($@) {
1058 warn($@);
1059 exit 1;
1060 }
1061
1062 exit 0;
1063 }
1064
1065 # Stop server
1066 server_stop($pid_file);
1067
1068 $self->assert_child_ok($pid);
1069
1070 if ($ex) {
1071 test_append_logfile($log_file, $ex);
1072 unlink($log_file);
1073
1074 die($ex);
1075 }
1076
1077 unlink($log_file);
1078 }
1079
1080 sub rnto_fails_allow_overwrite {
1081 my $self = shift;
1082 my $tmpdir = $self->{tmpdir};
1083
1084 my $config_file = "$tmpdir/cmds.conf";
1085 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1086 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1087
1088 my $log_file = test_get_logfile();
1089
1090 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1091 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1092
1093 my $user = 'proftpd';
1094 my $passwd = 'test';
1095 my $group = 'ftpd';
1096 my $home_dir = File::Spec->rel2abs($tmpdir);
1097 my $uid = 500;
1098 my $gid = 500;
1099
1100 my $src_file = File::Spec->rel2abs("$tmpdir/foo");
1101 if (open(my $fh, "> $src_file")) {
1102 close($fh);
1103
1104 } else {
1105 die("Can't open $src_file: $!");
1106 }
1107
1108 my $dst_file = File::Spec->rel2abs("$tmpdir/bar");
1109 if (open(my $fh, "> $dst_file")) {
1110 close($fh);
1111
1112 } else {
1113 die("Can't open $dst_file: $!");
1114 }
1115
1116 # Make sure that, if we're running as root, that the home directory has
1117 # permissions/privs set for the account we create
1118 if ($< == 0) {
1119 unless (chmod(0755, $home_dir)) {
1120 die("Can't set perms on $home_dir to 0755: $!");
1121 }
1122
1123 unless (chown($uid, $gid, $home_dir)) {
1124 die("Can't set owner of $home_dir to $uid/$gid: $!");
1125 }
1126 }
1127
1128 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1129 '/bin/bash');
1130 auth_group_write($auth_group_file, $group, $gid, $user);
1131
1132 my $config = {
1133 PidFile => $pid_file,
1134 ScoreboardFile => $scoreboard_file,
1135 SystemLog => $log_file,
1136
1137 AuthUserFile => $auth_user_file,
1138 AuthGroupFile => $auth_group_file,
1139 AuthOrder => 'mod_auth_file.c',
1140
1141 IfModules => {
1142 'mod_delay.c' => {
1143 DelayEngine => 'off',
1144 },
1145 },
1146 };
1147
1148 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1149
1150 # Open pipes, for use between the parent and child processes. Specifically,
1151 # the child will indicate when it's done with its test by writing a message
1152 # to the parent.
1153 my ($rfh, $wfh);
1154 unless (pipe($rfh, $wfh)) {
1155 die("Can't open pipe: $!");
1156 }
1157
1158 my $ex;
1159
1160 # Fork child
1161 $self->handle_sigchld();
1162 defined(my $pid = fork()) or die("Can't fork: $!");
1163 if ($pid) {
1164 eval {
1165 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1166
1167 $client->login($user, $passwd);
1168
1169 my ($resp_code, $resp_msg);
1170 ($resp_code, $resp_msg) = $client->rnfr($src_file);
1171
1172 eval { ($resp_code, $resp_msg) = $client->rnto($dst_file) };
1173 unless ($@) {
1174 die("RNTO succeeded unexpectedly");
1175
1176 } else {
1177 $resp_code = $client->response_code();
1178 $resp_msg = $client->response_msg();
1179 }
1180
1181 my $expected;
1182
1183 $expected = 550;
1184 $self->assert($expected == $resp_code,
1185 test_msg("Expected $expected, got $resp_code"));
1186
1187 $expected = "$dst_file: Rename permission denied";
1188 $self->assert($expected eq $resp_msg,
1189 test_msg("Expected '$expected', got '$resp_msg'"));
1190
1191 $client->quit();
1192
1193 # Make sure our source file has not been deleted
1194 unless (-f $src_file) {
1195 die("File $src_file does not exist as expected");
1196 }
1197 };
1198
1199 if ($@) {
1200 $ex = $@;
1201 }
1202
1203 $wfh->print("done\n");
1204 $wfh->flush();
1205
1206 } else {
1207 eval { server_wait($config_file, $rfh) };
1208 if ($@) {
1209 warn($@);
1210 exit 1;
1211 }
1212
1213 exit 0;
1214 }
1215
1216 # Stop server
1217 server_stop($pid_file);
1218
1219 $self->assert_child_ok($pid);
1220
1221 if ($ex) {
1222 test_append_logfile($log_file, $ex);
1223 unlink($log_file);
1224
1225 die($ex);
1226 }
1227
1228 unlink($log_file);
1229 }
1230
1231 sub rnto_fails_device_full_bug3354 {
1232 my $self = shift;
1233 my $tmpdir = $self->{tmpdir};
1234
1235 my $config_file = "$tmpdir/cmds.conf";
1236 my $pid_file = File::Spec->rel2abs("$tmpdir/cmds.pid");
1237 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/cmds.scoreboard");
1238
1239 my $log_file = test_get_logfile();
1240
1241 my $auth_user_file = File::Spec->rel2abs("$tmpdir/cmds.passwd");
1242 my $auth_group_file = File::Spec->rel2abs("$tmpdir/cmds.group");
1243
1244 my $user = 'proftpd';
1245 my $passwd = 'test';
1246 my $group = 'ftpd';
1247 my $home_dir = File::Spec->rel2abs($tmpdir);
1248 my $uid = 500;
1249 my $gid = 500;
1250
1251 my $src_file = File::Spec->rel2abs("$tmpdir/foo");
1252 if (open(my $fh, "> $src_file")) {
1253 print $fh "Hello, World!\n";
1254 close($fh);
1255
1256 } else {
1257 die("Can't open $src_file: $!");
1258 }
1259
1260 # XXX The /dev/full device only exists on Linux, as far as I know
1261 my $dst_file = '/dev/full';
1262
1263 # Make sure that, if we're running as root, that the home directory has
1264 # permissions/privs set for the account we create
1265 if ($< == 0) {
1266 unless (chmod(0755, $home_dir)) {
1267 die("Can't set perms on $home_dir to 0755: $!");
1268 }
1269
1270 unless (chown($uid, $gid, $home_dir)) {
1271 die("Can't set owner of $home_dir to $uid/$gid: $!");
1272 }
1273 }
1274
1275 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1276 '/bin/bash');
1277 auth_group_write($auth_group_file, $group, $gid, $user);
1278
1279 my $config = {
1280 PidFile => $pid_file,
1281 ScoreboardFile => $scoreboard_file,
1282 SystemLog => $log_file,
1283
1284 AuthUserFile => $auth_user_file,
1285 AuthGroupFile => $auth_group_file,
1286 AuthOrder => 'mod_auth_file.c',
1287
1288 AllowOverwrite => 'on',
1289
1290 IfModules => {
1291 'mod_delay.c' => {
1292 DelayEngine => 'off',
1293 },
1294 },
1295 };
1296
1297 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1298
1299 # Open pipes, for use between the parent and child processes. Specifically,
1300 # the child will indicate when it's done with its test by writing a message
1301 # to the parent.
1302 my ($rfh, $wfh);
1303 unless (pipe($rfh, $wfh)) {
1304 die("Can't open pipe: $!");
1305 }
1306
1307 my $ex;
1308
1309 # Fork child
1310 $self->handle_sigchld();
1311 defined(my $pid = fork()) or die("Can't fork: $!");
1312 if ($pid) {
1313 eval {
1314 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1315
1316 $client->login($user, $passwd);
1317
1318 my ($resp_code, $resp_msg);
1319 ($resp_code, $resp_msg) = $client->rnfr($src_file);
1320
1321 eval { ($resp_code, $resp_msg) = $client->rnto($dst_file) };
1322 unless ($@) {
1323 die("RNTO succeeded unexpectedly");
1324
1325 } else {
1326 $resp_code = $client->response_code();
1327 $resp_msg = $client->response_msg();
1328 }
1329
1330 my $expected;
1331
1332 $expected = 550;
1333 $self->assert($expected == $resp_code,
1334 test_msg("Expected $expected, got $resp_code"));
1335
1336 $expected = "Rename $dst_file: No space left on device";
1337 $self->assert($expected eq $resp_msg,
1338 test_msg("Expected '$expected', got '$resp_msg'"));
1339 };
1340
1341 if ($@) {
1342 $ex = $@;
1343 }
1344
1345 $wfh->print("done\n");
1346 $wfh->flush();
1347
1348 } else {
1349 eval { server_wait($config_file, $rfh) };
1350 if ($@) {
1351 warn($@);
1352 exit 1;
1353 }
1354
1355 exit 0;
1356 }
1357
1358 # Stop server
1359 server_stop($pid_file);
1360
1361 $self->assert_child_ok($pid);
1362
1363 if ($ex) {
1364 test_append_logfile($log_file, $ex);
1365 unlink($log_file);
1366
1367 die($ex);
1368 }
1369
1370 unlink($log_file);
1371 }
1372
1373 sub rnto_symlink_bug3754 {
1374 my $self = shift;
1375 my $tmpdir = $self->{tmpdir};
1376 my $setup = test_setup($tmpdir, 'cmds');
1377
1378 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
1379 if (open(my $fh, "> $test_file")) {
1380 close($fh);
1381
1382 } else {
1383 die("Can't open $test_file: $!");
1384 }
1385
1386 # Create a different directory; this directory will contain the symlink
1387 # which points to the test file. We then use a <Limit> to deny writes
1388 # to the main directory containing the test file, but allow writes in the
1389 # directory containing the symlink. A DELE command for the symlink path
1390 # should still work by deleting the symlink (and NOT the target file).
1391
1392 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1393 mkpath($sub_dir);
1394
1395 # Create a symlink to the test file
1396 my $cwd = getcwd();
1397 unless (chdir($sub_dir)) {
1398 die("Can't chdir to $sub_dir: $!");
1399 }
1400
1401 unless (symlink('../test.txt', 'bar')) {
1402 die("Can't symlink 'bar' to '../test.txt': $!");
1403 }
1404
1405 unless (chdir($cwd)) {
1406 die("Can't chdir to $cwd: $!");
1407 }
1408
1409 my $src_file = File::Spec->rel2abs("$sub_dir/bar");
1410 my $dst_file = File::Spec->rel2abs("$sub_dir/baz");
1411
1412 if ($< == 0) {
1413 unless (chmod(0755, $sub_dir)) {
1414 die("Can't set perms on $sub_dir to 0755: $!");
1415 }
1416
1417 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
1418 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
1419 }
1420 }
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 if (open(my $fh, ">> $setup->{config_file}")) {
1442 print $fh <<EOC;
1443 <Directory ~>
1444 <Limit WRITE>
1445 DenyAll
1446 </Limit>
1447 </Directory>
1448
1449 <Directory ~/sub.d>
1450 <Limit WRITE>
1451 AllowAll
1452 </Limit>
1453 </Directory>
1454 EOC
1455 unless (close($fh)) {
1456 die("Can't write $setup->{config_file}: $!");
1457 }
1458
1459 } else {
1460 die("Can't open $setup->{config_file}: $!");
1461 }
1462
1463 # Open pipes, for use between the parent and child processes. Specifically,
1464 # the child will indicate when it's done with its test by writing a message
1465 # to the parent.
1466 my ($rfh, $wfh);
1467 unless (pipe($rfh, $wfh)) {
1468 die("Can't open pipe: $!");
1469 }
1470
1471 my $ex;
1472
1473 # Fork child
1474 $self->handle_sigchld();
1475 defined(my $pid = fork()) or die("Can't fork: $!");
1476 if ($pid) {
1477 eval {
1478 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1479 $client->login($setup->{user}, $setup->{passwd});
1480 $client->cwd('sub.d');
1481
1482 my ($resp_code, $resp_msg) = $client->rnfr('bar');
1483 ($resp_code, $resp_msg) = $client->rnto('baz');
1484 $client->quit();
1485
1486 my $expected = 250;
1487 $self->assert($expected == $resp_code,
1488 test_msg("Expected response code $expected, got $resp_code"));
1489
1490 $expected = "Rename successful";
1491 $self->assert($expected eq $resp_msg,
1492 test_msg("Expected response message '$expected', got '$resp_msg'"));
1493
1494 $self->assert(-f $test_file,
1495 test_msg("File '$test_file' does not exist as expected"));
1496
1497 $self->assert(!-l $src_file,
1498 test_msg("Symlink '$src_file' exists unexpectedly"));
1499
1500 $self->assert(-l $dst_file,
1501 test_msg("Symlink '$dst_file' does not exist as expected"));
1502 };
1503 if ($@) {
1504 $ex = $@;
1505 }
1506
1507 $wfh->print("done\n");
1508 $wfh->flush();
1509
1510 } else {
1511 eval { server_wait($setup->{config_file}, $rfh) };
1512 if ($@) {
1513 warn($@);
1514 exit 1;
1515 }
1516
1517 exit 0;
1518 }
1519
1520 # Stop server
1521 server_stop($setup->{pid_file});
1522 $self->assert_child_ok($pid);
1523
1524 test_cleanup($setup->{log_file}, $ex);
1525 }
1526
1527 sub rnto_lowercase_issue1023 {
1528 my $self = shift;
1529 my $tmpdir = $self->{tmpdir};
1530 my $setup = test_setup($tmpdir, 'cmds');
1531
1532 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1533 mkpath($test_dir);
1534
1535 my $src_file = File::Spec->rel2abs("$test_dir/test.txt");
1536 if (open(my $fh, "> $src_file")) {
1537 close($fh);
1538
1539 } else {
1540 die("Can't open $src_file: $!");
1541 }
1542
1543 my $dst_file = File::Spec->rel2abs("$test_dir/bar.txt");
1544
1545 if ($< == 0) {
1546 unless (chmod(0755, $test_dir)) {
1547 die("Can't set perms on $test_dir to 0755: $!");
1548 }
1549
1550 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
1551 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1552 }
1553 }
1554
1555 my $config = {
1556 PidFile => $setup->{pid_file},
1557 ScoreboardFile => $setup->{scoreboard_file},
1558 SystemLog => $setup->{log_file},
1559 TraceLog => $setup->{log_file},
1560 Trace => 'command:20',
1561
1562 AuthUserFile => $setup->{auth_user_file},
1563 AuthGroupFile => $setup->{auth_group_file},
1564 AuthOrder => 'mod_auth_file.c',
1565
1566 IfModules => {
1567 'mod_delay.c' => {
1568 DelayEngine => 'off',
1569 },
1570 },
1571 };
1572
1573 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1574 $config);
1575
1576 # Open pipes, for use between the parent and child processes. Specifically,
1577 # the child will indicate when it's done with its test by writing a message
1578 # to the parent.
1579 my ($rfh, $wfh);
1580 unless (pipe($rfh, $wfh)) {
1581 die("Can't open pipe: $!");
1582 }
1583
1584 my $ex;
1585
1586 # Fork child
1587 $self->handle_sigchld();
1588 defined(my $pid = fork()) or die("Can't fork: $!");
1589 if ($pid) {
1590 eval {
1591 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1592 $client->login($setup->{user}, $setup->{passwd});
1593
1594 my ($resp_code, $resp_msg) = $client->rnfr($src_file);
1595 ($resp_code, $resp_msg) = $client->quote_raw('rnto', $dst_file);
1596
1597 my $expected = 250;
1598 $self->assert($expected == $resp_code,
1599 test_msg("Expected response code $expected, got $resp_code"));
1600
1601 $expected = "Rename successful";
1602 $self->assert($expected eq $resp_msg,
1603 test_msg("Expected response message '$expected', got '$resp_msg'"));
1604
1605 $self->assert(!-f $src_file,
1606 test_msg("File $src_file exists unexpectedly"));
1607 $self->assert(-f $dst_file,
1608 test_msg("File $dst_file does not exist as expected"));
1609 };
1610 if ($@) {
1611 $ex = $@;
1612 }
1613
1614 $wfh->print("done\n");
1615 $wfh->flush();
1616
1617 } else {
1618 eval { server_wait($setup->{config_file}, $rfh) };
1619 if ($@) {
1620 warn($@);
1621 exit 1;
1622 }
1623
1624 exit 0;
1625 }
1626
1627 # Stop server
1628 server_stop($setup->{pid_file});
1629 $self->assert_child_ok($pid);
1630
1631 test_cleanup($setup->{log_file}, $ex);
1632 }
1633
1634 sub rnto_user_pass_issue2003 {
1635 my $self = shift;
1636 my $tmpdir = $self->{tmpdir};
1637 my $setup = test_setup($tmpdir, 'cmds');
1638
1639 my $src_file = File::Spec->rel2abs("$setup->{home_dir}/src.dat");
1640 my $dst_file = File::Spec->rel2abs("$setup->{home_dir}/dst.dat");
1641
1642 my $config = {
1643 PidFile => $setup->{pid_file},
1644 ScoreboardFile => $setup->{scoreboard_file},
1645 SystemLog => $setup->{log_file},
1646 TraceLog => $setup->{log_file},
1647 Trace => 'command:20 response:20',
1648
1649 AuthUserFile => $setup->{auth_user_file},
1650 AuthGroupFile => $setup->{auth_group_file},
1651 AuthOrder => 'mod_auth_file.c',
1652
1653 IfModules => {
1654 'mod_delay.c' => {
1655 DelayEngine => 'off',
1656 },
1657 },
1658 };
1659
1660 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1661 $config);
1662
1663 # Open pipes, for use between the parent and child processes. Specifically,
1664 # the child will indicate when it's done with its test by writing a message
1665 # to the parent.
1666 my ($rfh, $wfh);
1667 unless (pipe($rfh, $wfh)) {
1668 die("Can't open pipe: $!");
1669 }
1670
1671 my $ex;
1672
1673 # Fork child
1674 $self->handle_sigchld();
1675 defined(my $pid = fork()) or die("Can't fork: $!");
1676 if ($pid) {
1677 eval {
1678 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1679
1680 eval { $client->rnto($src_file); };
1681 unless ($@) {
1682 die("Unauthenticated RNTO succeeded unexpectedly");
1683 }
1684
1685 my $resp_code = $client->response_code();
1686 my $resp_msg = $client->response_msg();
1687
1688 my $expected = 530;
1689 $self->assert($expected == $resp_code,
1690 test_msg("Expected response code $expected, got $resp_code"));
1691
1692 $expected = 'Please login with USER and PASS';
1693 $self->assert($expected eq $resp_msg,
1694 test_msg("Expected response message '$expected', got '$resp_msg'"));
1695
1696 ($resp_code, $resp_msg) = $client->user($setup->{user});
1697
1698 my $expected = 331;
1699 $self->assert($expected == $resp_code,
1700 test_msg("Expected response code $expected, got $resp_code"));
1701
1702 $expected = "Password required for $setup->{user}";
1703 $self->assert($expected eq $resp_msg,
1704 test_msg("Expected response message '$expected', got '$resp_msg'"));
1705
1706
1707 ($resp_code, $resp_msg) = $client->pass($setup->{passwd});
1708
1709 my $expected = 230;
1710 $self->assert($expected == $resp_code,
1711 test_msg("Expected response code $expected, got $resp_code"));
1712
1713 $expected = "User $setup->{user} logged in";
1714 $self->assert($expected eq $resp_msg,
1715 test_msg("Expected response message '$expected', got '$resp_msg'"));
1716
1717 ($resp_code, $resp_msg) = $client->pwd();
1718
1719 my $expected = 257;
1720 $self->assert($expected == $resp_code,
1721 test_msg("Expected response code $expected, got $resp_code"));
1722
1723 $expected = "\"$setup->{home_dir}\" is the current directory";
1724
1725 if ($^O eq 'darwin') {
1726 # MacOSX-specific hack, due to how it handles tmp files
1727 $expected = '"/private' . "$setup->{home_dir}\" is the current directory";
1728 }
1729
1730 $self->assert($expected eq $resp_msg,
1731 test_msg("Expected response message '$expected', got '$resp_msg'"));
1732
1733 $client->quit();
1734 };
1735 if ($@) {
1736 $ex = $@;
1737 }
1738
1739 $wfh->print("done\n");
1740 $wfh->flush();
1741
1742 } else {
1743 eval { server_wait($setup->{config_file}, $rfh) };
1744 if ($@) {
1745 warn($@);
1746 exit 1;
1747 }
1748
1749 exit 0;
1750 }
1751
1752 # Stop server
1753 server_stop($setup->{pid_file});
1754 $self->assert_child_ok($pid);
1755
1756 test_cleanup($setup->{log_file}, $ex);
1757 }
1758
1759 1;