Debian Codegraph @

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

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