Debian Codegraph @

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

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