Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands;
2
3 use lib qw(t/lib);
4 use base qw(Test::Unit::TestCase ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Path qw(mkpath rmtree);
8 use File::Spec;
9 use IO::Handle;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :features :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 my $TESTS = {
19 cmds_pwd_ok => {
20 order => ++$order,
21 test_class => [qw(forking)],
22 },
23
24 cmds_xpwd_ok => {
25 order => ++$order,
26 test_class => [qw(forking)],
27 },
28
29 cmds_cwd_ok => {
30 order => ++$order,
31 test_class => [qw(forking)],
32 },
33
34 cmds_cwd_fails_enoent => {
35 order => ++$order,
36 test_class => [qw(forking)],
37 },
38
39 cmds_cwd_fails_eperm => {
40 order => ++$order,
41 test_class => [qw(forking)],
42 },
43
44 cmds_xcwd_ok => {
45 order => ++$order,
46 test_class => [qw(forking)],
47 },
48
49 cmds_cdup_ok => {
50 order => ++$order,
51 test_class => [qw(forking)],
52 },
53
54 cmds_xcup_ok => {
55 order => ++$order,
56 test_class => [qw(forking)],
57 },
58
59 cmds_syst_ok => {
60 order => ++$order,
61 test_class => [qw(forking)],
62 },
63
64 cmds_type_ascii_ok => {
65 order => ++$order,
66 test_class => [qw(forking)],
67 },
68
69 cmds_type_binary_ok => {
70 order => ++$order,
71 test_class => [qw(forking)],
72 },
73
74 cmds_type_other_fails => {
75 order => ++$order,
76 test_class => [qw(forking)],
77 },
78
79 cmds_mkd_ok => {
80 order => ++$order,
81 test_class => [qw(forking)],
82 },
83
84 cmds_mkd_fails_enoent => {
85 order => ++$order,
86 test_class => [qw(forking)],
87 },
88
89 cmds_mkd_fails_eperm => {
90 order => ++$order,
91 test_class => [qw(forking)],
92 },
93
94 cmds_xmkd_ok => {
95 order => ++$order,
96 test_class => [qw(forking)],
97 },
98
99 cmds_rmd_ok => {
100 order => ++$order,
101 test_class => [qw(forking)],
102 },
103
104 cmds_rmd_fails_enoent => {
105 order => ++$order,
106 test_class => [qw(forking)],
107 },
108
109 cmds_rmd_fails_eperm => {
110 order => ++$order,
111 test_class => [qw(forking)],
112 },
113
114 cmds_xrmd_ok => {
115 order => ++$order,
116 test_class => [qw(forking)],
117 },
118
119 cmds_dele_ok => {
120 order => ++$order,
121 test_class => [qw(forking)],
122 },
123
124 cmds_dele_fails_enoent => {
125 order => ++$order,
126 test_class => [qw(forking)],
127 },
128
129 cmds_dele_fails_eperm => {
130 order => ++$order,
131 test_class => [qw(forking)],
132 },
133
134 cmds_mdtm_ok => {
135 order => ++$order,
136 test_class => [qw(forking)],
137 },
138
139 cmds_mdtm_fails_enoent => {
140 order => ++$order,
141 test_class => [qw(forking)],
142 },
143
144 cmds_mdtm_fails_eperm => {
145 order => ++$order,
146 test_class => [qw(forking)],
147 },
148
149 cmds_size_ok => {
150 order => ++$order,
151 test_class => [qw(forking)],
152 },
153
154 cmds_size_fails_ascii => {
155 order => ++$order,
156 test_class => [qw(forking)],
157 },
158
159 cmds_size_fails_enoent => {
160 order => ++$order,
161 test_class => [qw(forking)],
162 },
163
164 cmds_size_fails_eperm => {
165 order => ++$order,
166 test_class => [qw(forking)],
167 },
168
169 };
170
171 sub new {
172 return shift()->SUPER::new(@_);
173 }
174
175 sub list_tests {
176 return testsuite_get_runnable_tests($TESTS);
177 }
178
179 sub set_up {
180 my $self = shift;
181
182 # Create temporary scratch dir
183 eval { mkpath('tmp') };
184 if ($@) {
185 my $abs_path = File::Spec->rel2abs('tmp');
186 die("Can't create dir $abs_path: $@");
187 }
188 }
189
190 sub tear_down {
191 my $self = shift;
192 undef $self;
193
194 # Remove temporary scratch dir
195 eval { rmtree('tmp') };
196 };
197
198 sub cmds_pwd_ok {
199 my $self = shift;
200
201 my $config_file = 'tmp/cmds.conf';
202 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
203 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
204 my $log_file = File::Spec->rel2abs('cmds.log');
205
206 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
207 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
208
209 my $user = 'proftpd';
210 my $passwd = 'test';
211 my $home_dir = File::Spec->rel2abs('tmp');
212
213 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
214 '/bin/bash');
215 auth_group_write($auth_group_file, 'ftpd', 500, $user);
216
217 my $config = {
218 PidFile => $pid_file,
219 ScoreboardFile => $scoreboard_file,
220 SystemLog => $log_file,
221
222 AuthUserFile => $auth_user_file,
223 AuthGroupFile => $auth_group_file,
224 AuthOrder => 'mod_auth_file.c',
225
226 IfModules => {
227 'mod_delay.c' => {
228 DelayEngine => 'off',
229 },
230 },
231 };
232
233 my ($port, $config_user, $config_group) = config_write($config_file, $config);
234
235 # Open pipes, for use between the parent and child processes. Specifically,
236 # the child will indicate when it's done with its test by writing a message
237 # to the parent.
238 my ($readh, $writeh);
239 unless (pipe($readh, $writeh)) {
240 die("Can't open pipe: $!");
241 }
242
243 $writeh->autoflush(1);
244
245 my $ex;
246
247 # Fork child
248 $self->handle_sigchld();
249 defined(my $pid = fork()) or die("Can't fork: $!");
250 if ($pid) {
251 eval {
252 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
253
254 eval { $client->login($user, $passwd) };
255 if ($@) {
256 my $err = $@;
257 print $writeh "done\n";
258 die("Failed to log in: $err");
259 }
260
261 my ($resp_code, $resp_msg);
262 eval { ($resp_code, $resp_msg) = $client->pwd() };
263 if ($@) {
264 my $err = $@;
265 print $writeh "done\n";
266 die("Failed to PWD: $err");
267 }
268
269 my $expected;
270
271 $expected = 257;
272 $self->assert($expected == $resp_code,
273 test_msg("Expected $expected, got $resp_code"));
274
275 $expected = "\"$home_dir\" is the current directory";
276 chomp($resp_msg);
277 $self->assert($expected eq $resp_msg,
278 test_msg("Expected '$expected', got '$resp_msg'"));
279 };
280
281 if ($@) {
282 $ex = $@;
283 }
284
285 print $writeh "done\n";
286
287 } else {
288 # Start server
289 server_start($config_file);
290
291 # Wait until we receive word from the child that it has finished its
292 # test.
293 while (my $msg = <$readh>) {
294 chomp($msg);
295
296 if ($msg eq 'done') {
297 last;
298 }
299 }
300
301 exit 0;
302 }
303
304 # Stop server
305 server_stop($pid_file);
306
307 $self->assert_child_ok($pid);
308
309 if ($ex) {
310 die($ex);
311 }
312
313 unlink($log_file);
314 }
315
316 sub cmds_xpwd_ok {
317 my $self = shift;
318
319 my $config_file = 'tmp/cmds.conf';
320 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
321 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
322 my $log_file = File::Spec->rel2abs('cmds.log');
323
324 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
325 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
326
327 my $user = 'proftpd';
328 my $passwd = 'test';
329 my $home_dir = File::Spec->rel2abs('tmp');
330
331 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
332 '/bin/bash');
333 auth_group_write($auth_group_file, 'ftpd', 500, $user);
334
335 my $config = {
336 PidFile => $pid_file,
337 ScoreboardFile => $scoreboard_file,
338 SystemLog => $log_file,
339
340 AuthUserFile => $auth_user_file,
341 AuthGroupFile => $auth_group_file,
342 AuthOrder => 'mod_auth_file.c',
343
344 IfModules => {
345 'mod_delay.c' => {
346 DelayEngine => 'off',
347 },
348 },
349 };
350
351 my ($port, $config_user, $config_group) = config_write($config_file, $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 ($readh, $writeh);
357 unless (pipe($readh, $writeh)) {
358 die("Can't open pipe: $!");
359 }
360
361 $writeh->autoflush(1);
362
363 my $ex;
364
365 # Fork child
366 $self->handle_sigchld();
367 defined(my $pid = fork()) or die("Can't fork: $!");
368 if ($pid) {
369 eval {
370 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
371
372 eval { $client->login($user, $passwd) };
373 if ($@) {
374 my $err = $@;
375 print $writeh "done\n";
376 die("Failed to log in: $err");
377 }
378
379 my ($resp_code, $resp_msg);
380 eval { ($resp_code, $resp_msg) = $client->xpwd() };
381 if ($@) {
382 my $err = $@;
383 print $writeh "done\n";
384 die("Failed to XPWD: $err");
385 }
386
387 my $expected;
388
389 $expected = 257;
390 $self->assert($expected == $resp_code,
391 test_msg("Expected $expected, got $resp_code"));
392
393 $expected = "\"$home_dir\" is the current directory";
394 chomp($resp_msg);
395 $self->assert($expected eq $resp_msg,
396 test_msg("Expected '$expected', got '$resp_msg'"));
397 };
398
399 if ($@) {
400 $ex = $@;
401 }
402
403 print $writeh "done\n";
404
405 } else {
406 # Start server
407 server_start($config_file);
408
409 # Wait until we receive word from the child that it has finished its
410 # test.
411 while (my $msg = <$readh>) {
412 chomp($msg);
413
414 if ($msg eq 'done') {
415 last;
416 }
417 }
418
419 exit 0;
420 }
421
422 # Stop server
423 server_stop($pid_file);
424
425 $self->assert_child_ok($pid);
426
427 if ($ex) {
428 die($ex);
429 }
430
431 unlink($log_file);
432 }
433
434 sub cmds_cwd_ok {
435 my $self = shift;
436
437 my $config_file = 'tmp/cmds.conf';
438 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
439 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
440 my $log_file = File::Spec->rel2abs('cmds.log');
441
442 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
443 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
444
445 my $user = 'proftpd';
446 my $passwd = 'test';
447 my $home_dir = File::Spec->rel2abs('tmp');
448
449 my $sub_dir = File::Spec->rel2abs('tmp/foo');
450 mkpath($sub_dir);
451
452 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
453 '/bin/bash');
454 auth_group_write($auth_group_file, 'ftpd', 500, $user);
455
456 my $config = {
457 PidFile => $pid_file,
458 ScoreboardFile => $scoreboard_file,
459 SystemLog => $log_file,
460
461 AuthUserFile => $auth_user_file,
462 AuthGroupFile => $auth_group_file,
463 AuthOrder => 'mod_auth_file.c',
464
465 IfModules => {
466 'mod_delay.c' => {
467 DelayEngine => 'off',
468 },
469 },
470 };
471
472 my ($port, $config_user, $config_group) = config_write($config_file, $config);
473
474 # Open pipes, for use between the parent and child processes. Specifically,
475 # the child will indicate when it's done with its test by writing a message
476 # to the parent.
477 my ($readh, $writeh);
478 unless (pipe($readh, $writeh)) {
479 die("Can't open pipe: $!");
480 }
481
482 $writeh->autoflush(1);
483
484 my $ex;
485
486 # Fork child
487 $self->handle_sigchld();
488 defined(my $pid = fork()) or die("Can't fork: $!");
489 if ($pid) {
490 eval {
491 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
492
493 eval { $client->login($user, $passwd) };
494 if ($@) {
495 my $err = $@;
496 print $writeh "done\n";
497 die("Failed to log in: $err");
498 }
499
500 my ($resp_code, $resp_msg);
501 eval { ($resp_code, $resp_msg) = $client->cwd($sub_dir) };
502 if ($@) {
503 my $err = $@;
504 print $writeh "done\n";
505 die("Failed to CWD: $err");
506 }
507
508 my $expected;
509
510 $expected = 250;
511 $self->assert($expected == $resp_code,
512 test_msg("Expected $expected, got $resp_code"));
513
514 $expected = "CWD command successful";
515 chomp($resp_msg);
516 $self->assert($expected eq $resp_msg,
517 test_msg("Expected '$expected', got '$resp_msg'"));
518 };
519
520 if ($@) {
521 $ex = $@;
522 }
523
524 print $writeh "done\n";
525
526 } else {
527 # Start server
528 server_start($config_file);
529
530 # Wait until we receive word from the child that it has finished its
531 # test.
532 while (my $msg = <$readh>) {
533 chomp($msg);
534
535 if ($msg eq 'done') {
536 last;
537 }
538 }
539
540 exit 0;
541 }
542
543 # Stop server
544 server_stop($pid_file);
545
546 $self->assert_child_ok($pid);
547
548 if ($ex) {
549 die($ex);
550 }
551
552 unlink($log_file);
553 }
554
555 sub cmds_cwd_fails_enoent {
556 my $self = shift;
557
558 my $config_file = 'tmp/cmds.conf';
559 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
560 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
561 my $log_file = File::Spec->rel2abs('cmds.log');
562
563 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
564 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
565
566 my $user = 'proftpd';
567 my $passwd = 'test';
568 my $home_dir = File::Spec->rel2abs('tmp');
569
570 my $sub_dir = File::Spec->rel2abs('tmp/foo');
571
572 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
573 '/bin/bash');
574 auth_group_write($auth_group_file, 'ftpd', 500, $user);
575
576 my $config = {
577 PidFile => $pid_file,
578 ScoreboardFile => $scoreboard_file,
579 SystemLog => $log_file,
580
581 AuthUserFile => $auth_user_file,
582 AuthGroupFile => $auth_group_file,
583 AuthOrder => 'mod_auth_file.c',
584
585 IfModules => {
586 'mod_delay.c' => {
587 DelayEngine => 'off',
588 },
589 },
590 };
591
592 my ($port, $config_user, $config_group) = config_write($config_file, $config);
593
594 # Open pipes, for use between the parent and child processes. Specifically,
595 # the child will indicate when it's done with its test by writing a message
596 # to the parent.
597 my ($readh, $writeh);
598 unless (pipe($readh, $writeh)) {
599 die("Can't open pipe: $!");
600 }
601
602 $writeh->autoflush(1);
603
604 my $ex;
605
606 # Fork child
607 $self->handle_sigchld();
608 defined(my $pid = fork()) or die("Can't fork: $!");
609 if ($pid) {
610 eval {
611 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
612
613 eval { $client->login($user, $passwd) };
614 if ($@) {
615 my $err = $@;
616 print $writeh "done\n";
617 die("Failed to log in: $err");
618 }
619
620 my ($resp_code, $resp_msg);
621 eval { ($resp_code, $resp_msg) = $client->cwd($sub_dir) };
622 unless ($@) {
623 print $writeh "done\n";
624 die("CWD succeeded unexpectedly");
625
626 } else {
627 $resp_code = $client->response_code();
628 $resp_msg = $client->response_msg();
629 }
630
631 my $expected;
632
633 $expected = 550;
634 $self->assert($expected == $resp_code,
635 test_msg("Expected $expected, got $resp_code"));
636
637 $expected = "$sub_dir: No such file or directory";
638 chomp($resp_msg);
639 $self->assert($expected eq $resp_msg,
640 test_msg("Expected '$expected', got '$resp_msg'"));
641 };
642
643 if ($@) {
644 $ex = $@;
645 }
646
647 print $writeh "done\n";
648
649 } else {
650 # Start server
651 server_start($config_file);
652
653 # Wait until we receive word from the child that it has finished its
654 # test.
655 while (my $msg = <$readh>) {
656 chomp($msg);
657
658 if ($msg eq 'done') {
659 last;
660 }
661 }
662
663 exit 0;
664 }
665
666 # Stop server
667 server_stop($pid_file);
668
669 $self->assert_child_ok($pid);
670
671 if ($ex) {
672 die($ex);
673 }
674
675 unlink($log_file);
676 }
677
678 sub cmds_cwd_fails_eperm {
679 my $self = shift;
680
681 my $config_file = 'tmp/cmds.conf';
682 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
683 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
684 my $log_file = File::Spec->rel2abs('cmds.log');
685
686 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
687 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
688
689 my $user = 'proftpd';
690 my $passwd = 'test';
691 my $home_dir = File::Spec->rel2abs('tmp');
692
693 my $sub_dir = File::Spec->rel2abs('tmp/foo');
694 mkpath($sub_dir);
695
696 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
697 '/bin/bash');
698 auth_group_write($auth_group_file, 'ftpd', 500, $user);
699
700 my $config = {
701 PidFile => $pid_file,
702 ScoreboardFile => $scoreboard_file,
703 SystemLog => $log_file,
704
705 AuthUserFile => $auth_user_file,
706 AuthGroupFile => $auth_group_file,
707 AuthOrder => 'mod_auth_file.c',
708
709 IfModules => {
710 'mod_delay.c' => {
711 DelayEngine => 'off',
712 },
713 },
714 };
715
716 my ($port, $config_user, $config_group) = config_write($config_file, $config);
717
718 # Open pipes, for use between the parent and child processes. Specifically,
719 # the child will indicate when it's done with its test by writing a message
720 # to the parent.
721 my ($readh, $writeh);
722 unless (pipe($readh, $writeh)) {
723 die("Can't open pipe: $!");
724 }
725
726 $writeh->autoflush(1);
727
728 my $ex;
729
730 # Fork child
731 $self->handle_sigchld();
732 defined(my $pid = fork()) or die("Can't fork: $!");
733 if ($pid) {
734 eval {
735 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
736
737 eval { $client->login($user, $passwd) };
738 if ($@) {
739 my $err = $@;
740 print $writeh "done\n";
741 die("Failed to log in: $err");
742 }
743
744 # Make it such that perms on the dir do not allow chdirs
745 unless (chmod(0440, $sub_dir)) {
746 my $err = $!;
747 print $writeh "done\n";
748 die("Failed to change perms on $sub_dir: $err");
749 }
750
751 my ($resp_code, $resp_msg);
752 eval { ($resp_code, $resp_msg) = $client->cwd($sub_dir) };
753 unless ($@) {
754 print $writeh "done\n";
755 die("CWD succeeded unexpectedly");
756
757 } else {
758 $resp_code = $client->response_code();
759 $resp_msg = $client->response_msg();
760 }
761
762 my $expected;
763
764 $expected = 550;
765 $self->assert($expected == $resp_code,
766 test_msg("Expected $expected, got $resp_code"));
767
768 $expected = "$sub_dir: No such file or directory";
769 chomp($resp_msg);
770 $self->assert($expected eq $resp_msg,
771 test_msg("Expected '$expected', got '$resp_msg'"));
772 };
773
774 if ($@) {
775 $ex = $@;
776 }
777
778 print $writeh "done\n";
779
780 } else {
781 # Start server
782 server_start($config_file);
783
784 # Wait until we receive word from the child that it has finished its
785 # test.
786 while (my $msg = <$readh>) {
787 chomp($msg);
788
789 if ($msg eq 'done') {
790 last;
791 }
792 }
793
794 exit 0;
795 }
796
797 # Stop server
798 server_stop($pid_file);
799
800 $self->assert_child_ok($pid);
801
802 if ($ex) {
803 die($ex);
804 }
805
806 unlink($log_file);
807 }
808
809 sub cmds_xcwd_ok {
810 my $self = shift;
811
812 my $config_file = 'tmp/cmds.conf';
813 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
814 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
815 my $log_file = File::Spec->rel2abs('cmds.log');
816
817 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
818 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
819
820 my $user = 'proftpd';
821 my $passwd = 'test';
822 my $home_dir = File::Spec->rel2abs('tmp');
823
824 my $sub_dir = File::Spec->rel2abs('tmp/foo');
825 mkpath($sub_dir);
826
827 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
828 '/bin/bash');
829 auth_group_write($auth_group_file, 'ftpd', 500, $user);
830
831 my $config = {
832 PidFile => $pid_file,
833 ScoreboardFile => $scoreboard_file,
834 SystemLog => $log_file,
835
836 AuthUserFile => $auth_user_file,
837 AuthGroupFile => $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($config_file, $config);
848
849 # Open pipes, for use between the parent and child processes. Specifically,
850 # the child will indicate when it's done with its test by writing a message
851 # to the parent.
852 my ($readh, $writeh);
853 unless (pipe($readh, $writeh)) {
854 die("Can't open pipe: $!");
855 }
856
857 $writeh->autoflush(1);
858
859 my $ex;
860
861 # Fork child
862 $self->handle_sigchld();
863 defined(my $pid = fork()) or die("Can't fork: $!");
864 if ($pid) {
865 eval {
866 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
867
868 eval { $client->login($user, $passwd) };
869 if ($@) {
870 my $err = $@;
871 print $writeh "done\n";
872 die("Failed to log in: $err");
873 }
874
875 my ($resp_code, $resp_msg);
876 eval { ($resp_code, $resp_msg) = $client->xcwd($sub_dir) };
877 if ($@) {
878 my $err = $@;
879 print $writeh "done\n";
880 die("Failed to XCWD: $err");
881 }
882
883 my $expected;
884
885 $expected = 250;
886 $self->assert($expected == $resp_code,
887 test_msg("Expected $expected, got $resp_code"));
888
889 $expected = "XCWD command successful";
890 chomp($resp_msg);
891 $self->assert($expected eq $resp_msg,
892 test_msg("Expected '$expected', got '$resp_msg'"));
893 };
894
895 if ($@) {
896 $ex = $@;
897 }
898
899 print $writeh "done\n";
900
901 } else {
902 # Start server
903 server_start($config_file);
904
905 # Wait until we receive word from the child that it has finished its
906 # test.
907 while (my $msg = <$readh>) {
908 chomp($msg);
909
910 if ($msg eq 'done') {
911 last;
912 }
913 }
914
915 exit 0;
916 }
917
918 # Stop server
919 server_stop($pid_file);
920
921 $self->assert_child_ok($pid);
922
923 if ($ex) {
924 die($ex);
925 }
926
927 unlink($log_file);
928 }
929
930 sub cmds_cdup_ok {
931 my $self = shift;
932
933 my $config_file = 'tmp/cmds.conf';
934 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
935 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
936 my $log_file = File::Spec->rel2abs('cmds.log');
937
938 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
939 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
940
941 my $user = 'proftpd';
942 my $passwd = 'test';
943 my $home_dir = File::Spec->rel2abs('tmp');
944
945 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
946 '/bin/bash');
947 auth_group_write($auth_group_file, 'ftpd', 500, $user);
948
949 my $config = {
950 PidFile => $pid_file,
951 ScoreboardFile => $scoreboard_file,
952 SystemLog => $log_file,
953
954 AuthUserFile => $auth_user_file,
955 AuthGroupFile => $auth_group_file,
956 AuthOrder => 'mod_auth_file.c',
957
958 IfModules => {
959 'mod_delay.c' => {
960 DelayEngine => 'off',
961 },
962 },
963 };
964
965 my ($port, $config_user, $config_group) = config_write($config_file, $config);
966
967 # Open pipes, for use between the parent and child processes. Specifically,
968 # the child will indicate when it's done with its test by writing a message
969 # to the parent.
970 my ($readh, $writeh);
971 unless (pipe($readh, $writeh)) {
972 die("Can't open pipe: $!");
973 }
974
975 $writeh->autoflush(1);
976
977 my $ex;
978
979 # Fork child
980 $self->handle_sigchld();
981 defined(my $pid = fork()) or die("Can't fork: $!");
982 if ($pid) {
983 eval {
984 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
985
986 eval { $client->login($user, $passwd) };
987 if ($@) {
988 my $err = $@;
989 print $writeh "done\n";
990 die("Failed to log in: $err");
991 }
992
993 my ($resp_code, $resp_msg);
994 eval { ($resp_code, $resp_msg) = $client->cdup() };
995 if ($@) {
996 my $err = $@;
997 print $writeh "done\n";
998 die("Failed to CDUP: $err");
999 }
1000
1001 my $expected;
1002
1003 $expected = 250;
1004 $self->assert($expected == $resp_code,
1005 test_msg("Expected $expected, got $resp_code"));
1006
1007 $expected = "CDUP command successful";
1008 chomp($resp_msg);
1009 $self->assert($expected eq $resp_msg,
1010 test_msg("Expected '$expected', got '$resp_msg'"));
1011 };
1012
1013 if ($@) {
1014 $ex = $@;
1015 }
1016
1017 print $writeh "done\n";
1018
1019 } else {
1020 # Start server
1021 server_start($config_file);
1022
1023 # Wait until we receive word from the child that it has finished its
1024 # test.
1025 while (my $msg = <$readh>) {
1026 chomp($msg);
1027
1028 if ($msg eq 'done') {
1029 last;
1030 }
1031 }
1032
1033 exit 0;
1034 }
1035
1036 # Stop server
1037 server_stop($pid_file);
1038
1039 $self->assert_child_ok($pid);
1040
1041 if ($ex) {
1042 die($ex);
1043 }
1044
1045 unlink($log_file);
1046 }
1047
1048 sub cmds_xcup_ok {
1049 my $self = shift;
1050
1051 my $config_file = 'tmp/cmds.conf';
1052 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1053 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1054 my $log_file = File::Spec->rel2abs('cmds.log');
1055
1056 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
1057 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
1058
1059 my $user = 'proftpd';
1060 my $passwd = 'test';
1061 my $home_dir = File::Spec->rel2abs('tmp');
1062
1063 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
1064 '/bin/bash');
1065 auth_group_write($auth_group_file, 'ftpd', 500, $user);
1066
1067 my $config = {
1068 PidFile => $pid_file,
1069 ScoreboardFile => $scoreboard_file,
1070 SystemLog => $log_file,
1071
1072 AuthUserFile => $auth_user_file,
1073 AuthGroupFile => $auth_group_file,
1074 AuthOrder => 'mod_auth_file.c',
1075
1076 IfModules => {
1077 'mod_delay.c' => {
1078 DelayEngine => 'off',
1079 },
1080 },
1081 };
1082
1083 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1084
1085 # Open pipes, for use between the parent and child processes. Specifically,
1086 # the child will indicate when it's done with its test by writing a message
1087 # to the parent.
1088 my ($readh, $writeh);
1089 unless (pipe($readh, $writeh)) {
1090 die("Can't open pipe: $!");
1091 }
1092
1093 $writeh->autoflush(1);
1094
1095 my $ex;
1096
1097 # Fork child
1098 $self->handle_sigchld();
1099 defined(my $pid = fork()) or die("Can't fork: $!");
1100 if ($pid) {
1101 eval {
1102 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1103
1104 eval { $client->login($user, $passwd) };
1105 if ($@) {
1106 my $err = $@;
1107 print $writeh "done\n";
1108 die("Failed to log in: $err");
1109 }
1110
1111 my ($resp_code, $resp_msg);
1112 eval { ($resp_code, $resp_msg) = $client->xcup() };
1113 if ($@) {
1114 my $err = $@;
1115 print $writeh "done\n";
1116 die("Failed to XCUP: $err");
1117 }
1118
1119 my $expected;
1120
1121 $expected = 250;
1122 $self->assert($expected == $resp_code,
1123 test_msg("Expected $expected, got $resp_code"));
1124
1125 $expected = "XCUP command successful";
1126 chomp($resp_msg);
1127 $self->assert($expected eq $resp_msg,
1128 test_msg("Expected '$expected', got '$resp_msg'"));
1129 };
1130
1131 if ($@) {
1132 $ex = $@;
1133 }
1134
1135 print $writeh "done\n";
1136
1137 } else {
1138 # Start server
1139 server_start($config_file);
1140
1141 # Wait until we receive word from the child that it has finished its
1142 # test.
1143 while (my $msg = <$readh>) {
1144 chomp($msg);
1145
1146 if ($msg eq 'done') {
1147 last;
1148 }
1149 }
1150
1151 exit 0;
1152 }
1153
1154 # Stop server
1155 server_stop($pid_file);
1156
1157 $self->assert_child_ok($pid);
1158
1159 if ($ex) {
1160 die($ex);
1161 }
1162
1163 unlink($log_file);
1164 }
1165
1166 sub cmds_syst_ok {
1167 my $self = shift;
1168
1169 my $config_file = 'tmp/cmds.conf';
1170 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1171 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1172 my $log_file = File::Spec->rel2abs('cmds.log');
1173
1174 my $config = {
1175 PidFile => $pid_file,
1176 ScoreboardFile => $scoreboard_file,
1177 SystemLog => $log_file,
1178
1179 IfModules => {
1180 'mod_delay.c' => {
1181 DelayEngine => 'off',
1182 },
1183 },
1184 };
1185
1186 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1187
1188 # Open pipes, for use between the parent and child processes. Specifically,
1189 # the child will indicate when it's done with its test by writing a message
1190 # to the parent.
1191 my ($readh, $writeh);
1192 unless (pipe($readh, $writeh)) {
1193 die("Can't open pipe: $!");
1194 }
1195
1196 $writeh->autoflush(1);
1197
1198 my $ex;
1199
1200 # Fork child
1201 $self->handle_sigchld();
1202 defined(my $pid = fork()) or die("Can't fork: $!");
1203 if ($pid) {
1204 eval {
1205 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1206
1207 my ($resp_code, $resp_msg);
1208 eval { ($resp_code, $resp_msg) = $client->syst() };
1209 if ($@) {
1210 my $err = $@;
1211 print $writeh "done\n";
1212 die("Failed to SYST: $err");
1213 }
1214
1215 my $expected;
1216
1217 $expected = 215;
1218 $self->assert($expected == $resp_code,
1219 test_msg("Expected $expected, got $resp_code"));
1220
1221 $expected = "UNIX Type: L8";
1222 chomp($resp_msg);
1223 $self->assert($expected eq $resp_msg,
1224 test_msg("Expected '$expected', got '$resp_msg'"));
1225 };
1226
1227 if ($@) {
1228 $ex = $@;
1229 }
1230
1231 print $writeh "done\n";
1232
1233 } else {
1234 # Start server
1235 server_start($config_file);
1236
1237 # Wait until we receive word from the child that it has finished its
1238 # test.
1239 while (my $msg = <$readh>) {
1240 chomp($msg);
1241
1242 if ($msg eq 'done') {
1243 last;
1244 }
1245 }
1246
1247 exit 0;
1248 }
1249
1250 # Stop server
1251 server_stop($pid_file);
1252
1253 $self->assert_child_ok($pid);
1254
1255 if ($ex) {
1256 die($ex);
1257 }
1258
1259 unlink($log_file);
1260 }
1261
1262 sub cmds_type_ascii_ok {
1263 my $self = shift;
1264
1265 my $config_file = 'tmp/cmds.conf';
1266 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1267 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1268 my $log_file = File::Spec->rel2abs('cmds.log');
1269
1270 my $config = {
1271 PidFile => $pid_file,
1272 ScoreboardFile => $scoreboard_file,
1273 SystemLog => $log_file,
1274
1275 IfModules => {
1276 'mod_delay.c' => {
1277 DelayEngine => 'off',
1278 },
1279 },
1280 };
1281
1282 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1283
1284 # Open pipes, for use between the parent and child processes. Specifically,
1285 # the child will indicate when it's done with its test by writing a message
1286 # to the parent.
1287 my ($readh, $writeh);
1288 unless (pipe($readh, $writeh)) {
1289 die("Can't open pipe: $!");
1290 }
1291
1292 $writeh->autoflush(1);
1293
1294 my $ex;
1295
1296 # Fork child
1297 $self->handle_sigchld();
1298 defined(my $pid = fork()) or die("Can't fork: $!");
1299 if ($pid) {
1300 eval {
1301 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1302
1303 my ($resp_code, $resp_msg);
1304 eval { ($resp_code, $resp_msg) = $client->type('ascii') };
1305 if ($@) {
1306 my $err = $@;
1307 print $writeh "done\n";
1308 die("Failed to TYPE: $err");
1309 }
1310
1311 my $expected;
1312
1313 $expected = 200;
1314 $self->assert($expected == $resp_code,
1315 test_msg("Expected $expected, got $resp_code"));
1316
1317 $expected = "Type set to A";
1318 chomp($resp_msg);
1319 $self->assert($expected eq $resp_msg,
1320 test_msg("Expected '$expected', got '$resp_msg'"));
1321 };
1322
1323 if ($@) {
1324 $ex = $@;
1325 }
1326
1327 print $writeh "done\n";
1328
1329 } else {
1330 # Start server
1331 server_start($config_file);
1332
1333 # Wait until we receive word from the child that it has finished its
1334 # test.
1335 while (my $msg = <$readh>) {
1336 chomp($msg);
1337
1338 if ($msg eq 'done') {
1339 last;
1340 }
1341 }
1342
1343 exit 0;
1344 }
1345
1346 # Stop server
1347 server_stop($pid_file);
1348
1349 $self->assert_child_ok($pid);
1350
1351 if ($ex) {
1352 die($ex);
1353 }
1354
1355 unlink($log_file);
1356 }
1357
1358 sub cmds_type_binary_ok {
1359 my $self = shift;
1360
1361 my $config_file = 'tmp/cmds.conf';
1362 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1363 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1364 my $log_file = File::Spec->rel2abs('cmds.log');
1365
1366 my $config = {
1367 PidFile => $pid_file,
1368 ScoreboardFile => $scoreboard_file,
1369 SystemLog => $log_file,
1370
1371 IfModules => {
1372 'mod_delay.c' => {
1373 DelayEngine => 'off',
1374 },
1375 },
1376 };
1377
1378 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1379
1380 # Open pipes, for use between the parent and child processes. Specifically,
1381 # the child will indicate when it's done with its test by writing a message
1382 # to the parent.
1383 my ($readh, $writeh);
1384 unless (pipe($readh, $writeh)) {
1385 die("Can't open pipe: $!");
1386 }
1387
1388 $writeh->autoflush(1);
1389
1390 my $ex;
1391
1392 # Fork child
1393 $self->handle_sigchld();
1394 defined(my $pid = fork()) or die("Can't fork: $!");
1395 if ($pid) {
1396 eval {
1397 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1398
1399 my ($resp_code, $resp_msg);
1400 eval { ($resp_code, $resp_msg) = $client->type('binary') };
1401 if ($@) {
1402 my $err = $@;
1403 print $writeh "done\n";
1404 die("Failed to TYPE: $err");
1405 }
1406
1407 my $expected;
1408
1409 $expected = 200;
1410 $self->assert($expected == $resp_code,
1411 test_msg("Expected $expected, got $resp_code"));
1412
1413 $expected = "Type set to I";
1414 chomp($resp_msg);
1415 $self->assert($expected eq $resp_msg,
1416 test_msg("Expected '$expected', got '$resp_msg'"));
1417 };
1418
1419 if ($@) {
1420 $ex = $@;
1421 }
1422
1423 print $writeh "done\n";
1424
1425 } else {
1426 # Start server
1427 server_start($config_file);
1428
1429 # Wait until we receive word from the child that it has finished its
1430 # test.
1431 while (my $msg = <$readh>) {
1432 chomp($msg);
1433
1434 if ($msg eq 'done') {
1435 last;
1436 }
1437 }
1438
1439 exit 0;
1440 }
1441
1442 # Stop server
1443 server_stop($pid_file);
1444
1445 $self->assert_child_ok($pid);
1446
1447 if ($ex) {
1448 die($ex);
1449 }
1450
1451 unlink($log_file);
1452 }
1453
1454 sub cmds_type_other_fails {
1455 my $self = shift;
1456
1457 my $config_file = 'tmp/cmds.conf';
1458 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1459 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1460 my $log_file = File::Spec->rel2abs('cmds.log');
1461
1462 my $config = {
1463 PidFile => $pid_file,
1464 ScoreboardFile => $scoreboard_file,
1465 SystemLog => $log_file,
1466
1467 IfModules => {
1468 'mod_delay.c' => {
1469 DelayEngine => 'off',
1470 },
1471 },
1472 };
1473
1474 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1475
1476 # Open pipes, for use between the parent and child processes. Specifically,
1477 # the child will indicate when it's done with its test by writing a message
1478 # to the parent.
1479 my ($readh, $writeh);
1480 unless (pipe($readh, $writeh)) {
1481 die("Can't open pipe: $!");
1482 }
1483
1484 $writeh->autoflush(1);
1485
1486 my $ex;
1487
1488 # Fork child
1489 $self->handle_sigchld();
1490 defined(my $pid = fork()) or die("Can't fork: $!");
1491 if ($pid) {
1492 eval {
1493 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1494
1495 my ($resp_code, $resp_msg);
1496 eval { ($resp_code, $resp_msg) = $client->type('other') };
1497 unless ($@) {
1498 my $err = $@;
1499 print $writeh "done\n";
1500 die("TYPE succeeded unexpectedly");
1501
1502 } else {
1503 $resp_code = $client->response_code();
1504 $resp_msg = $client->response_msg();
1505 }
1506
1507 my $expected;
1508
1509 $expected = 500;
1510 $self->assert($expected == $resp_code,
1511 test_msg("Expected $expected, got $resp_code"));
1512
1513 $expected = "'TYPE other' not understood";
1514 chomp($resp_msg);
1515 $self->assert($expected eq $resp_msg,
1516 test_msg("Expected '$expected', got '$resp_msg'"));
1517 };
1518
1519 if ($@) {
1520 $ex = $@;
1521 }
1522
1523 print $writeh "done\n";
1524
1525 } else {
1526 # Start server
1527 server_start($config_file);
1528
1529 # Wait until we receive word from the child that it has finished its
1530 # test.
1531 while (my $msg = <$readh>) {
1532 chomp($msg);
1533
1534 if ($msg eq 'done') {
1535 last;
1536 }
1537 }
1538
1539 exit 0;
1540 }
1541
1542 # Stop server
1543 server_stop($pid_file);
1544
1545 $self->assert_child_ok($pid);
1546
1547 if ($ex) {
1548 die($ex);
1549 }
1550
1551 unlink($log_file);
1552 }
1553
1554 sub cmds_mkd_ok {
1555 my $self = shift;
1556
1557 my $config_file = 'tmp/cmds.conf';
1558 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1559 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1560 my $log_file = File::Spec->rel2abs('cmds.log');
1561
1562 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
1563 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
1564
1565 my $user = 'proftpd';
1566 my $passwd = 'test';
1567 my $home_dir = File::Spec->rel2abs('tmp');
1568
1569 my $sub_dir = File::Spec->rel2abs('tmp/foo');
1570
1571 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
1572 '/bin/bash');
1573 auth_group_write($auth_group_file, 'ftpd', 500, $user);
1574
1575 my $config = {
1576 PidFile => $pid_file,
1577 ScoreboardFile => $scoreboard_file,
1578 SystemLog => $log_file,
1579
1580 AuthUserFile => $auth_user_file,
1581 AuthGroupFile => $auth_group_file,
1582 AuthOrder => 'mod_auth_file.c',
1583
1584 IfModules => {
1585 'mod_delay.c' => {
1586 DelayEngine => 'off',
1587 },
1588 },
1589 };
1590
1591 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1592
1593 # Open pipes, for use between the parent and child processes. Specifically,
1594 # the child will indicate when it's done with its test by writing a message
1595 # to the parent.
1596 my ($readh, $writeh);
1597 unless (pipe($readh, $writeh)) {
1598 die("Can't open pipe: $!");
1599 }
1600
1601 $writeh->autoflush(1);
1602
1603 my $ex;
1604
1605 # Fork child
1606 $self->handle_sigchld();
1607 defined(my $pid = fork()) or die("Can't fork: $!");
1608 if ($pid) {
1609 eval {
1610 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1611
1612 eval { $client->login($user, $passwd) };
1613 if ($@) {
1614 my $err = $@;
1615 print $writeh "done\n";
1616 die("Failed to log in: $err");
1617 }
1618
1619 my ($resp_code, $resp_msg);
1620 eval { ($resp_code, $resp_msg) = $client->mkd($sub_dir) };
1621 if ($@) {
1622 my $err = $@;
1623 print $writeh "done\n";
1624 die("Failed to MKD: $err");
1625 }
1626
1627 my $expected;
1628
1629 $expected = 257;
1630 $self->assert($expected == $resp_code,
1631 test_msg("Expected $expected, got $resp_code"));
1632
1633 $expected = "\"$sub_dir\" - Directory successfully created";
1634 chomp($resp_msg);
1635 $self->assert($expected eq $resp_msg,
1636 test_msg("Expected '$expected', got '$resp_msg'"));
1637 };
1638
1639 if ($@) {
1640 $ex = $@;
1641 }
1642
1643 print $writeh "done\n";
1644
1645 } else {
1646 # Start server
1647 server_start($config_file);
1648
1649 # Wait until we receive word from the child that it has finished its
1650 # test.
1651 while (my $msg = <$readh>) {
1652 chomp($msg);
1653
1654 if ($msg eq 'done') {
1655 last;
1656 }
1657 }
1658
1659 exit 0;
1660 }
1661
1662 # Stop server
1663 server_stop($pid_file);
1664
1665 $self->assert_child_ok($pid);
1666
1667 if ($ex) {
1668 die($ex);
1669 }
1670
1671 unlink($log_file);
1672 }
1673
1674 sub cmds_mkd_fails_enoent {
1675 my $self = shift;
1676
1677 my $config_file = 'tmp/cmds.conf';
1678 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1679 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1680 my $log_file = File::Spec->rel2abs('cmds.log');
1681
1682 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
1683 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
1684
1685 my $user = 'proftpd';
1686 my $passwd = 'test';
1687 my $home_dir = File::Spec->rel2abs('tmp');
1688
1689 my $sub_dir = File::Spec->rel2abs('tmp/foo/bar');
1690
1691 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
1692 '/bin/bash');
1693 auth_group_write($auth_group_file, 'ftpd', 500, $user);
1694
1695 my $config = {
1696 PidFile => $pid_file,
1697 ScoreboardFile => $scoreboard_file,
1698 SystemLog => $log_file,
1699
1700 AuthUserFile => $auth_user_file,
1701 AuthGroupFile => $auth_group_file,
1702 AuthOrder => 'mod_auth_file.c',
1703
1704 IfModules => {
1705 'mod_delay.c' => {
1706 DelayEngine => 'off',
1707 },
1708 },
1709 };
1710
1711 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1712
1713 # Open pipes, for use between the parent and child processes. Specifically,
1714 # the child will indicate when it's done with its test by writing a message
1715 # to the parent.
1716 my ($readh, $writeh);
1717 unless (pipe($readh, $writeh)) {
1718 die("Can't open pipe: $!");
1719 }
1720
1721 $writeh->autoflush(1);
1722
1723 my $ex;
1724
1725 # Fork child
1726 $self->handle_sigchld();
1727 defined(my $pid = fork()) or die("Can't fork: $!");
1728 if ($pid) {
1729 eval {
1730 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1731
1732 eval { $client->login($user, $passwd) };
1733 if ($@) {
1734 my $err = $@;
1735 print $writeh "done\n";
1736 die("Failed to log in: $err");
1737 }
1738
1739 my ($resp_code, $resp_msg);
1740 eval { ($resp_code, $resp_msg) = $client->mkd($sub_dir) };
1741 unless ($@) {
1742 print $writeh "done\n";
1743 die("MKD succeeded unexpectedly");
1744
1745 } else {
1746 $resp_code = $client->response_code();
1747 $resp_msg = $client->response_msg();
1748 }
1749
1750 my $expected;
1751
1752 $expected = 550;
1753 $self->assert($expected == $resp_code,
1754 test_msg("Expected $expected, got $resp_code"));
1755
1756 $expected = "$sub_dir: Operation not permitted";
1757 chomp($resp_msg);
1758 $self->assert($expected eq $resp_msg,
1759 test_msg("Expected '$expected', got '$resp_msg'"));
1760 };
1761
1762 if ($@) {
1763 $ex = $@;
1764 }
1765
1766 print $writeh "done\n";
1767
1768 } else {
1769 # Start server
1770 server_start($config_file);
1771
1772 # Wait until we receive word from the child that it has finished its
1773 # test.
1774 while (my $msg = <$readh>) {
1775 chomp($msg);
1776
1777 if ($msg eq 'done') {
1778 last;
1779 }
1780 }
1781
1782 exit 0;
1783 }
1784
1785 # Stop server
1786 server_stop($pid_file);
1787
1788 $self->assert_child_ok($pid);
1789
1790 if ($ex) {
1791 die($ex);
1792 }
1793
1794 unlink($log_file);
1795 }
1796
1797 sub cmds_mkd_fails_eperm {
1798 my $self = shift;
1799
1800 my $config_file = 'tmp/cmds.conf';
1801 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1802 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1803 my $log_file = File::Spec->rel2abs('cmds.log');
1804
1805 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
1806 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
1807
1808 my $user = 'proftpd';
1809 my $passwd = 'test';
1810 my $home_dir = File::Spec->rel2abs('tmp');
1811
1812 my $sub_dir = File::Spec->rel2abs('tmp/foo');
1813
1814 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
1815 '/bin/bash');
1816 auth_group_write($auth_group_file, 'ftpd', 500, $user);
1817
1818 my $config = {
1819 PidFile => $pid_file,
1820 ScoreboardFile => $scoreboard_file,
1821 SystemLog => $log_file,
1822
1823 AuthUserFile => $auth_user_file,
1824 AuthGroupFile => $auth_group_file,
1825 AuthOrder => 'mod_auth_file.c',
1826
1827 IfModules => {
1828 'mod_delay.c' => {
1829 DelayEngine => 'off',
1830 },
1831 },
1832 };
1833
1834 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1835
1836 # Open pipes, for use between the parent and child processes. Specifically,
1837 # the child will indicate when it's done with its test by writing a message
1838 # to the parent.
1839 my ($readh, $writeh);
1840 unless (pipe($readh, $writeh)) {
1841 die("Can't open pipe: $!");
1842 }
1843
1844 $writeh->autoflush(1);
1845
1846 my $ex;
1847
1848 # Fork child
1849 $self->handle_sigchld();
1850 defined(my $pid = fork()) or die("Can't fork: $!");
1851 if ($pid) {
1852 eval {
1853 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1854
1855 eval { $client->login($user, $passwd) };
1856 if ($@) {
1857 my $err = $@;
1858 print $writeh "done\n";
1859 die("Failed to log in: $err");
1860 }
1861
1862 # Make it such that perms on the parent dir do not allow writes
1863 my $perms = (stat($home_dir))[2];
1864 unless (chmod(0550, $home_dir)) {
1865 my $err = $!;
1866 print $writeh "done\n";
1867 die("Failed to change perms on $home_dir: $err");
1868 }
1869
1870 my ($resp_code, $resp_msg);
1871 eval { ($resp_code, $resp_msg) = $client->mkd($sub_dir) };
1872 unless ($@) {
1873 print $writeh "done\n";
1874 die("MKD succeeded unexpectedly");
1875
1876 } else {
1877 $resp_code = $client->response_code();
1878 $resp_msg = $client->response_msg();
1879 }
1880
1881 # Restore the perms
1882 chmod($perms, $home_dir);
1883
1884 my $expected;
1885
1886 $expected = 550;
1887 $self->assert($expected == $resp_code,
1888 test_msg("Expected $expected, got $resp_code"));
1889
1890 $expected = "$sub_dir: Operation not permitted";
1891 chomp($resp_msg);
1892 $self->assert($expected eq $resp_msg,
1893 test_msg("Expected '$expected', got '$resp_msg'"));
1894 };
1895
1896 if ($@) {
1897 $ex = $@;
1898 }
1899
1900 print $writeh "done\n";
1901
1902 } else {
1903 # Start server
1904 server_start($config_file);
1905
1906 # Wait until we receive word from the child that it has finished its
1907 # test.
1908 while (my $msg = <$readh>) {
1909 chomp($msg);
1910
1911 if ($msg eq 'done') {
1912 last;
1913 }
1914 }
1915
1916 exit 0;
1917 }
1918
1919 # Stop server
1920 server_stop($pid_file);
1921
1922 $self->assert_child_ok($pid);
1923
1924 if ($ex) {
1925 die($ex);
1926 }
1927
1928 unlink($log_file);
1929 }
1930
1931 sub cmds_xmkd_ok {
1932 my $self = shift;
1933
1934 my $config_file = 'tmp/cmds.conf';
1935 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
1936 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
1937 my $log_file = File::Spec->rel2abs('cmds.log');
1938
1939 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
1940 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
1941
1942 my $user = 'proftpd';
1943 my $passwd = 'test';
1944 my $home_dir = File::Spec->rel2abs('tmp');
1945
1946 my $sub_dir = File::Spec->rel2abs('tmp/foo');
1947
1948 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
1949 '/bin/bash');
1950 auth_group_write($auth_group_file, 'ftpd', 500, $user);
1951
1952 my $config = {
1953 PidFile => $pid_file,
1954 ScoreboardFile => $scoreboard_file,
1955 SystemLog => $log_file,
1956
1957 AuthUserFile => $auth_user_file,
1958 AuthGroupFile => $auth_group_file,
1959 AuthOrder => 'mod_auth_file.c',
1960
1961 IfModules => {
1962 'mod_delay.c' => {
1963 DelayEngine => 'off',
1964 },
1965 },
1966 };
1967
1968 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1969
1970 # Open pipes, for use between the parent and child processes. Specifically,
1971 # the child will indicate when it's done with its test by writing a message
1972 # to the parent.
1973 my ($readh, $writeh);
1974 unless (pipe($readh, $writeh)) {
1975 die("Can't open pipe: $!");
1976 }
1977
1978 $writeh->autoflush(1);
1979
1980 my $ex;
1981
1982 # Fork child
1983 $self->handle_sigchld();
1984 defined(my $pid = fork()) or die("Can't fork: $!");
1985 if ($pid) {
1986 eval {
1987 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1988
1989 eval { $client->login($user, $passwd) };
1990 if ($@) {
1991 my $err = $@;
1992 print $writeh "done\n";
1993 die("Failed to log in: $err");
1994 }
1995
1996 my ($resp_code, $resp_msg);
1997 eval { ($resp_code, $resp_msg) = $client->xmkd($sub_dir) };
1998 if ($@) {
1999 my $err = $@;
2000 print $writeh "done\n";
2001 die("Failed to XMKD: $err");
2002 }
2003
2004 my $expected;
2005
2006 $expected = 257;
2007 $self->assert($expected == $resp_code,
2008 test_msg("Expected $expected, got $resp_code"));
2009
2010 $expected = "\"$sub_dir\" - Directory successfully created";
2011 chomp($resp_msg);
2012 $self->assert($expected eq $resp_msg,
2013 test_msg("Expected '$expected', got '$resp_msg'"));
2014 };
2015
2016 if ($@) {
2017 $ex = $@;
2018 }
2019
2020 print $writeh "done\n";
2021
2022 } else {
2023 # Start server
2024 server_start($config_file);
2025
2026 # Wait until we receive word from the child that it has finished its
2027 # test.
2028 while (my $msg = <$readh>) {
2029 chomp($msg);
2030
2031 if ($msg eq 'done') {
2032 last;
2033 }
2034 }
2035
2036 exit 0;
2037 }
2038
2039 # Stop server
2040 server_stop($pid_file);
2041
2042 $self->assert_child_ok($pid);
2043
2044 if ($ex) {
2045 die($ex);
2046 }
2047
2048 unlink($log_file);
2049 }
2050
2051 sub cmds_rmd_ok {
2052 my $self = shift;
2053
2054 my $config_file = 'tmp/cmds.conf';
2055 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2056 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2057 my $log_file = File::Spec->rel2abs('cmds.log');
2058
2059 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2060 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2061
2062 my $user = 'proftpd';
2063 my $passwd = 'test';
2064 my $home_dir = File::Spec->rel2abs('tmp');
2065
2066 my $sub_dir = File::Spec->rel2abs('tmp/foo');
2067 mkpath($sub_dir);
2068
2069 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2070 '/bin/bash');
2071 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2072
2073 my $config = {
2074 PidFile => $pid_file,
2075 ScoreboardFile => $scoreboard_file,
2076 SystemLog => $log_file,
2077
2078 AuthUserFile => $auth_user_file,
2079 AuthGroupFile => $auth_group_file,
2080 AuthOrder => 'mod_auth_file.c',
2081
2082 IfModules => {
2083 'mod_delay.c' => {
2084 DelayEngine => 'off',
2085 },
2086 },
2087 };
2088
2089 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2090
2091 # Open pipes, for use between the parent and child processes. Specifically,
2092 # the child will indicate when it's done with its test by writing a message
2093 # to the parent.
2094 my ($readh, $writeh);
2095 unless (pipe($readh, $writeh)) {
2096 die("Can't open pipe: $!");
2097 }
2098
2099 $writeh->autoflush(1);
2100
2101 my $ex;
2102
2103 # Fork child
2104 $self->handle_sigchld();
2105 defined(my $pid = fork()) or die("Can't fork: $!");
2106 if ($pid) {
2107 eval {
2108 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2109
2110 eval { $client->login($user, $passwd) };
2111 if ($@) {
2112 my $err = $@;
2113 print $writeh "done\n";
2114 die("Failed to log in: $err");
2115 }
2116
2117 my ($resp_code, $resp_msg);
2118 eval { ($resp_code, $resp_msg) = $client->rmd($sub_dir) };
2119 if ($@) {
2120 my $err = $@;
2121 print $writeh "done\n";
2122 die("Failed to RMD: $err");
2123 }
2124
2125 my $expected;
2126
2127 $expected = 250;
2128 $self->assert($expected == $resp_code,
2129 test_msg("Expected $expected, got $resp_code"));
2130
2131 $expected = "RMD command successful";
2132 chomp($resp_msg);
2133 $self->assert($expected eq $resp_msg,
2134 test_msg("Expected '$expected', got '$resp_msg'"));
2135 };
2136
2137 if ($@) {
2138 $ex = $@;
2139 }
2140
2141 print $writeh "done\n";
2142
2143 } else {
2144 # Start server
2145 server_start($config_file);
2146
2147 # Wait until we receive word from the child that it has finished its
2148 # test.
2149 while (my $msg = <$readh>) {
2150 chomp($msg);
2151
2152 if ($msg eq 'done') {
2153 last;
2154 }
2155 }
2156
2157 exit 0;
2158 }
2159
2160 # Stop server
2161 server_stop($pid_file);
2162
2163 $self->assert_child_ok($pid);
2164
2165 if ($ex) {
2166 die($ex);
2167 }
2168
2169 unlink($log_file);
2170 }
2171
2172 sub cmds_rmd_fails_enoent {
2173 my $self = shift;
2174
2175 my $config_file = 'tmp/cmds.conf';
2176 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2177 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2178 my $log_file = File::Spec->rel2abs('cmds.log');
2179
2180 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2181 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2182
2183 my $user = 'proftpd';
2184 my $passwd = 'test';
2185 my $home_dir = File::Spec->rel2abs('tmp');
2186
2187 my $sub_dir = File::Spec->rel2abs('tmp/foo');
2188
2189 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2190 '/bin/bash');
2191 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2192
2193 my $config = {
2194 PidFile => $pid_file,
2195 ScoreboardFile => $scoreboard_file,
2196 SystemLog => $log_file,
2197
2198 AuthUserFile => $auth_user_file,
2199 AuthGroupFile => $auth_group_file,
2200 AuthOrder => 'mod_auth_file.c',
2201
2202 IfModules => {
2203 'mod_delay.c' => {
2204 DelayEngine => 'off',
2205 },
2206 },
2207 };
2208
2209 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2210
2211 # Open pipes, for use between the parent and child processes. Specifically,
2212 # the child will indicate when it's done with its test by writing a message
2213 # to the parent.
2214 my ($readh, $writeh);
2215 unless (pipe($readh, $writeh)) {
2216 die("Can't open pipe: $!");
2217 }
2218
2219 $writeh->autoflush(1);
2220
2221 my $ex;
2222
2223 # Fork child
2224 $self->handle_sigchld();
2225 defined(my $pid = fork()) or die("Can't fork: $!");
2226 if ($pid) {
2227 eval {
2228 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2229
2230 eval { $client->login($user, $passwd) };
2231 if ($@) {
2232 my $err = $@;
2233 print $writeh "done\n";
2234 die("Failed to log in: $err");
2235 }
2236
2237 my ($resp_code, $resp_msg);
2238 eval { ($resp_code, $resp_msg) = $client->rmd($sub_dir) };
2239 unless ($@) {
2240 print $writeh "done\n";
2241 die("RMD succeeded unexpectedly");
2242
2243 } else {
2244 $resp_code = $client->response_code();
2245 $resp_msg = $client->response_msg();
2246 }
2247
2248 my $expected;
2249
2250 $expected = 550;
2251 $self->assert($expected == $resp_code,
2252 test_msg("Expected $expected, got $resp_code"));
2253
2254 $expected = "$sub_dir: Operation not permitted";
2255 chomp($resp_msg);
2256 $self->assert($expected eq $resp_msg,
2257 test_msg("Expected '$expected', got '$resp_msg'"));
2258 };
2259
2260 if ($@) {
2261 $ex = $@;
2262 }
2263
2264 print $writeh "done\n";
2265
2266 } else {
2267 # Start server
2268 server_start($config_file);
2269
2270 # Wait until we receive word from the child that it has finished its
2271 # test.
2272 while (my $msg = <$readh>) {
2273 chomp($msg);
2274
2275 if ($msg eq 'done') {
2276 last;
2277 }
2278 }
2279
2280 exit 0;
2281 }
2282
2283 # Stop server
2284 server_stop($pid_file);
2285
2286 $self->assert_child_ok($pid);
2287
2288 if ($ex) {
2289 die($ex);
2290 }
2291
2292 unlink($log_file);
2293 }
2294
2295 sub cmds_rmd_fails_eperm {
2296 my $self = shift;
2297
2298 my $config_file = 'tmp/cmds.conf';
2299 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2300 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2301 my $log_file = File::Spec->rel2abs('cmds.log');
2302
2303 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2304 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2305
2306 my $user = 'proftpd';
2307 my $passwd = 'test';
2308 my $home_dir = File::Spec->rel2abs('tmp');
2309
2310 my $sub_dir = File::Spec->rel2abs('tmp/foo');
2311
2312 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2313 '/bin/bash');
2314 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2315
2316 my $config = {
2317 PidFile => $pid_file,
2318 ScoreboardFile => $scoreboard_file,
2319 SystemLog => $log_file,
2320
2321 AuthUserFile => $auth_user_file,
2322 AuthGroupFile => $auth_group_file,
2323 AuthOrder => 'mod_auth_file.c',
2324
2325 IfModules => {
2326 'mod_delay.c' => {
2327 DelayEngine => 'off',
2328 },
2329 },
2330 };
2331
2332 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2333
2334 # Open pipes, for use between the parent and child processes. Specifically,
2335 # the child will indicate when it's done with its test by writing a message
2336 # to the parent.
2337 my ($readh, $writeh);
2338 unless (pipe($readh, $writeh)) {
2339 die("Can't open pipe: $!");
2340 }
2341
2342 $writeh->autoflush(1);
2343
2344 my $ex;
2345
2346 # Fork child
2347 $self->handle_sigchld();
2348 defined(my $pid = fork()) or die("Can't fork: $!");
2349 if ($pid) {
2350 eval {
2351 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2352
2353 eval { $client->login($user, $passwd) };
2354 if ($@) {
2355 my $err = $@;
2356 print $writeh "done\n";
2357 die("Failed to log in: $err");
2358 }
2359
2360 # Make it such that perms on the parent dir do not allow writes
2361 my $perms = (stat($home_dir))[2];
2362 unless (chmod(0550, $home_dir)) {
2363 my $err = $!;
2364 print $writeh "done\n";
2365 die("Failed to change perms on $home_dir: $err");
2366 }
2367
2368 my ($resp_code, $resp_msg);
2369 eval { ($resp_code, $resp_msg) = $client->rmd($sub_dir) };
2370 unless ($@) {
2371 print $writeh "done\n";
2372 die("RMD succeeded unexpectedly");
2373
2374 } else {
2375 $resp_code = $client->response_code();
2376 $resp_msg = $client->response_msg();
2377 }
2378
2379 # Restore the perms
2380 chmod($perms, $home_dir);
2381
2382 my $expected;
2383
2384 $expected = 550;
2385 $self->assert($expected == $resp_code,
2386 test_msg("Expected $expected, got $resp_code"));
2387
2388 $expected = "$sub_dir: Operation not permitted";
2389 chomp($resp_msg);
2390 $self->assert($expected eq $resp_msg,
2391 test_msg("Expected '$expected', got '$resp_msg'"));
2392 };
2393
2394 if ($@) {
2395 $ex = $@;
2396 }
2397
2398 print $writeh "done\n";
2399
2400 } else {
2401 # Start server
2402 server_start($config_file);
2403
2404 # Wait until we receive word from the child that it has finished its
2405 # test.
2406 while (my $msg = <$readh>) {
2407 chomp($msg);
2408
2409 if ($msg eq 'done') {
2410 last;
2411 }
2412 }
2413
2414 exit 0;
2415 }
2416
2417 # Stop server
2418 server_stop($pid_file);
2419
2420 $self->assert_child_ok($pid);
2421
2422 if ($ex) {
2423 die($ex);
2424 }
2425
2426 unlink($log_file);
2427 }
2428
2429 sub cmds_xrmd_ok {
2430 my $self = shift;
2431
2432 my $config_file = 'tmp/cmds.conf';
2433 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2434 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2435 my $log_file = File::Spec->rel2abs('cmds.log');
2436
2437 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2438 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2439
2440 my $user = 'proftpd';
2441 my $passwd = 'test';
2442 my $home_dir = File::Spec->rel2abs('tmp');
2443
2444 my $sub_dir = File::Spec->rel2abs('tmp/foo');
2445 mkpath($sub_dir);
2446
2447 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2448 '/bin/bash');
2449 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2450
2451 my $config = {
2452 PidFile => $pid_file,
2453 ScoreboardFile => $scoreboard_file,
2454 SystemLog => $log_file,
2455
2456 AuthUserFile => $auth_user_file,
2457 AuthGroupFile => $auth_group_file,
2458 AuthOrder => 'mod_auth_file.c',
2459
2460 IfModules => {
2461 'mod_delay.c' => {
2462 DelayEngine => 'off',
2463 },
2464 },
2465 };
2466
2467 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2468
2469 # Open pipes, for use between the parent and child processes. Specifically,
2470 # the child will indicate when it's done with its test by writing a message
2471 # to the parent.
2472 my ($readh, $writeh);
2473 unless (pipe($readh, $writeh)) {
2474 die("Can't open pipe: $!");
2475 }
2476
2477 $writeh->autoflush(1);
2478
2479 my $ex;
2480
2481 # Fork child
2482 $self->handle_sigchld();
2483 defined(my $pid = fork()) or die("Can't fork: $!");
2484 if ($pid) {
2485 eval {
2486 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2487
2488 eval { $client->login($user, $passwd) };
2489 if ($@) {
2490 my $err = $@;
2491 print $writeh "done\n";
2492 die("Failed to log in: $err");
2493 }
2494
2495 my ($resp_code, $resp_msg);
2496 eval { ($resp_code, $resp_msg) = $client->xrmd($sub_dir) };
2497 if ($@) {
2498 my $err = $@;
2499 print $writeh "done\n";
2500 die("Failed to XRMD: $err");
2501 }
2502
2503 my $expected;
2504
2505 $expected = 250;
2506 $self->assert($expected == $resp_code,
2507 test_msg("Expected $expected, got $resp_code"));
2508
2509 $expected = "XRMD command successful";
2510 chomp($resp_msg);
2511 $self->assert($expected eq $resp_msg,
2512 test_msg("Expected '$expected', got '$resp_msg'"));
2513 };
2514
2515 if ($@) {
2516 $ex = $@;
2517 }
2518
2519 print $writeh "done\n";
2520
2521 } else {
2522 # Start server
2523 server_start($config_file);
2524
2525 # Wait until we receive word from the child that it has finished its
2526 # test.
2527 while (my $msg = <$readh>) {
2528 chomp($msg);
2529
2530 if ($msg eq 'done') {
2531 last;
2532 }
2533 }
2534
2535 exit 0;
2536 }
2537
2538 # Stop server
2539 server_stop($pid_file);
2540
2541 $self->assert_child_ok($pid);
2542
2543 if ($ex) {
2544 die($ex);
2545 }
2546
2547 unlink($log_file);
2548 }
2549
2550 sub cmds_dele_ok {
2551 my $self = shift;
2552
2553 my $config_file = 'tmp/cmds.conf';
2554 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2555 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2556 my $log_file = File::Spec->rel2abs('cmds.log');
2557
2558 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2559 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2560
2561 my $user = 'proftpd';
2562 my $passwd = 'test';
2563 my $home_dir = File::Spec->rel2abs('tmp');
2564
2565 my $test_file = File::Spec->rel2abs('tmp/foo');
2566 if (open(my $fh, "> $test_file")) {
2567 close($fh);
2568
2569 } else {
2570 die("Can't create $test_file: $!");
2571 }
2572
2573 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2574 '/bin/bash');
2575 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2576
2577 my $config = {
2578 PidFile => $pid_file,
2579 ScoreboardFile => $scoreboard_file,
2580 SystemLog => $log_file,
2581
2582 AuthUserFile => $auth_user_file,
2583 AuthGroupFile => $auth_group_file,
2584 AuthOrder => 'mod_auth_file.c',
2585
2586 IfModules => {
2587 'mod_delay.c' => {
2588 DelayEngine => 'off',
2589 },
2590 },
2591 };
2592
2593 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2594
2595 # Open pipes, for use between the parent and child processes. Specifically,
2596 # the child will indicate when it's done with its test by writing a message
2597 # to the parent.
2598 my ($readh, $writeh);
2599 unless (pipe($readh, $writeh)) {
2600 die("Can't open pipe: $!");
2601 }
2602
2603 $writeh->autoflush(1);
2604
2605 my $ex;
2606
2607 # Fork child
2608 $self->handle_sigchld();
2609 defined(my $pid = fork()) or die("Can't fork: $!");
2610 if ($pid) {
2611 eval {
2612 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2613
2614 eval { $client->login($user, $passwd) };
2615 if ($@) {
2616 my $err = $@;
2617 print $writeh "done\n";
2618 die("Failed to log in: $err");
2619 }
2620
2621 my ($resp_code, $resp_msg);
2622 eval { ($resp_code, $resp_msg) = $client->dele($test_file) };
2623 if ($@) {
2624 my $err = $@;
2625 print $writeh "done\n";
2626 die("Failed to DELE: $err");
2627 }
2628
2629 my $expected;
2630
2631 $expected = 250;
2632 $self->assert($expected == $resp_code,
2633 test_msg("Expected $expected, got $resp_code"));
2634
2635 $expected = "DELE command successful";
2636 chomp($resp_msg);
2637 $self->assert($expected eq $resp_msg,
2638 test_msg("Expected '$expected', got '$resp_msg'"));
2639 };
2640
2641 if ($@) {
2642 $ex = $@;
2643 }
2644
2645 print $writeh "done\n";
2646
2647 } else {
2648 # Start server
2649 server_start($config_file);
2650
2651 # Wait until we receive word from the child that it has finished its
2652 # test.
2653 while (my $msg = <$readh>) {
2654 chomp($msg);
2655
2656 if ($msg eq 'done') {
2657 last;
2658 }
2659 }
2660
2661 exit 0;
2662 }
2663
2664 # Stop server
2665 server_stop($pid_file);
2666
2667 $self->assert_child_ok($pid);
2668
2669 if ($ex) {
2670 die($ex);
2671 }
2672
2673 unlink($log_file);
2674 }
2675
2676 sub cmds_dele_fails_enoent {
2677 my $self = shift;
2678
2679 my $config_file = 'tmp/cmds.conf';
2680 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2681 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2682 my $log_file = File::Spec->rel2abs('cmds.log');
2683
2684 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2685 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2686
2687 my $user = 'proftpd';
2688 my $passwd = 'test';
2689 my $home_dir = File::Spec->rel2abs('tmp');
2690
2691 my $test_file = File::Spec->rel2abs('tmp/foo');
2692
2693 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2694 '/bin/bash');
2695 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2696
2697 my $config = {
2698 PidFile => $pid_file,
2699 ScoreboardFile => $scoreboard_file,
2700 SystemLog => $log_file,
2701
2702 AuthUserFile => $auth_user_file,
2703 AuthGroupFile => $auth_group_file,
2704 AuthOrder => 'mod_auth_file.c',
2705
2706 IfModules => {
2707 'mod_delay.c' => {
2708 DelayEngine => 'off',
2709 },
2710 },
2711 };
2712
2713 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2714
2715 # Open pipes, for use between the parent and child processes. Specifically,
2716 # the child will indicate when it's done with its test by writing a message
2717 # to the parent.
2718 my ($readh, $writeh);
2719 unless (pipe($readh, $writeh)) {
2720 die("Can't open pipe: $!");
2721 }
2722
2723 $writeh->autoflush(1);
2724
2725 my $ex;
2726
2727 # Fork child
2728 $self->handle_sigchld();
2729 defined(my $pid = fork()) or die("Can't fork: $!");
2730 if ($pid) {
2731 eval {
2732 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2733
2734 eval { $client->login($user, $passwd) };
2735 if ($@) {
2736 my $err = $@;
2737 print $writeh "done\n";
2738 die("Failed to log in: $err");
2739 }
2740
2741 my ($resp_code, $resp_msg);
2742 eval { ($resp_code, $resp_msg) = $client->dele($test_file) };
2743 unless ($@) {
2744 print $writeh "done\n";
2745 die("DELE succeeded unexpectedly");
2746
2747 } else {
2748 $resp_code = $client->response_code();
2749 $resp_msg = $client->response_msg();
2750 }
2751
2752 my $expected;
2753
2754 $expected = 550;
2755 $self->assert($expected == $resp_code,
2756 test_msg("Expected $expected, got $resp_code"));
2757
2758 $expected = "$test_file: No such file or directory";
2759 chomp($resp_msg);
2760 $self->assert($expected eq $resp_msg,
2761 test_msg("Expected '$expected', got '$resp_msg'"));
2762 };
2763
2764 if ($@) {
2765 $ex = $@;
2766 }
2767
2768 print $writeh "done\n";
2769
2770 } else {
2771 # Start server
2772 server_start($config_file);
2773
2774 # Wait until we receive word from the child that it has finished its
2775 # test.
2776 while (my $msg = <$readh>) {
2777 chomp($msg);
2778
2779 if ($msg eq 'done') {
2780 last;
2781 }
2782 }
2783
2784 exit 0;
2785 }
2786
2787 # Stop server
2788 server_stop($pid_file);
2789
2790 $self->assert_child_ok($pid);
2791
2792 if ($ex) {
2793 die($ex);
2794 }
2795
2796 unlink($log_file);
2797 }
2798
2799 sub cmds_dele_fails_eperm {
2800 my $self = shift;
2801
2802 my $config_file = 'tmp/cmds.conf';
2803 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2804 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2805 my $log_file = File::Spec->rel2abs('cmds.log');
2806
2807 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2808 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2809
2810 my $user = 'proftpd';
2811 my $passwd = 'test';
2812 my $home_dir = File::Spec->rel2abs('tmp');
2813
2814 my $test_file = File::Spec->rel2abs('tmp/foo');
2815 if (open(my $fh, "> $test_file")) {
2816 close($fh);
2817
2818 } else {
2819 die("Can't create $test_file: $!");
2820 }
2821
2822 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2823 '/bin/bash');
2824 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2825
2826 my $config = {
2827 PidFile => $pid_file,
2828 ScoreboardFile => $scoreboard_file,
2829 SystemLog => $log_file,
2830
2831 AuthUserFile => $auth_user_file,
2832 AuthGroupFile => $auth_group_file,
2833 AuthOrder => 'mod_auth_file.c',
2834
2835 IfModules => {
2836 'mod_delay.c' => {
2837 DelayEngine => 'off',
2838 },
2839 },
2840 };
2841
2842 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2843
2844 # Open pipes, for use between the parent and child processes. Specifically,
2845 # the child will indicate when it's done with its test by writing a message
2846 # to the parent.
2847 my ($readh, $writeh);
2848 unless (pipe($readh, $writeh)) {
2849 die("Can't open pipe: $!");
2850 }
2851
2852 $writeh->autoflush(1);
2853
2854 my $ex;
2855
2856 # Fork child
2857 $self->handle_sigchld();
2858 defined(my $pid = fork()) or die("Can't fork: $!");
2859 if ($pid) {
2860 eval {
2861 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2862
2863 eval { $client->login($user, $passwd) };
2864 if ($@) {
2865 my $err = $@;
2866 print $writeh "done\n";
2867 die("Failed to log in: $err");
2868 }
2869
2870 # Make it such that perms on the dir do not allow writes
2871 my $perms = (stat($home_dir))[2];
2872 unless (chmod(0550, $home_dir)) {
2873 my $err = $!;
2874 print $writeh "done\n";
2875 die("Failed to change perms on $home_dir: $err");
2876 }
2877
2878 my ($resp_code, $resp_msg);
2879 eval { ($resp_code, $resp_msg) = $client->dele($test_file) };
2880 unless ($@) {
2881 print $writeh "done\n";
2882 die("DELE succeeded unexpectedly");
2883
2884 } else {
2885 $resp_code = $client->response_code();
2886 $resp_msg = $client->response_msg();
2887 }
2888
2889 chmod($perms, $home_dir);
2890
2891 my $expected;
2892
2893 $expected = 550;
2894 $self->assert($expected == $resp_code,
2895 test_msg("Expected $expected, got $resp_code"));
2896
2897 $expected = "$test_file: Operation not permitted";
2898 chomp($resp_msg);
2899 $self->assert($expected eq $resp_msg,
2900 test_msg("Expected '$expected', got '$resp_msg'"));
2901 };
2902
2903 if ($@) {
2904 $ex = $@;
2905 }
2906
2907 print $writeh "done\n";
2908
2909 } else {
2910 # Start server
2911 server_start($config_file);
2912
2913 # Wait until we receive word from the child that it has finished its
2914 # test.
2915 while (my $msg = <$readh>) {
2916 chomp($msg);
2917
2918 if ($msg eq 'done') {
2919 last;
2920 }
2921 }
2922
2923 exit 0;
2924 }
2925
2926 # Stop server
2927 server_stop($pid_file);
2928
2929 $self->assert_child_ok($pid);
2930
2931 if ($ex) {
2932 die($ex);
2933 }
2934
2935 unlink($log_file);
2936 }
2937
2938 sub cmds_mdtm_ok {
2939 my $self = shift;
2940
2941 my $config_file = 'tmp/cmds.conf';
2942 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
2943 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
2944 my $log_file = File::Spec->rel2abs('cmds.log');
2945
2946 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
2947 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
2948
2949 my $user = 'proftpd';
2950 my $passwd = 'test';
2951 my $home_dir = File::Spec->rel2abs('tmp');
2952
2953 my $test_file = File::Spec->rel2abs('tmp/foo');
2954 if (open(my $fh, "> $test_file")) {
2955 close($fh);
2956
2957 } else {
2958 die("Can't create $test_file: $!");
2959 }
2960
2961 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
2962 '/bin/bash');
2963 auth_group_write($auth_group_file, 'ftpd', 500, $user);
2964
2965 my $config = {
2966 PidFile => $pid_file,
2967 ScoreboardFile => $scoreboard_file,
2968 SystemLog => $log_file,
2969
2970 AuthUserFile => $auth_user_file,
2971 AuthGroupFile => $auth_group_file,
2972 AuthOrder => 'mod_auth_file.c',
2973
2974 IfModules => {
2975 'mod_delay.c' => {
2976 DelayEngine => 'off',
2977 },
2978 },
2979 };
2980
2981 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2982
2983 # Open pipes, for use between the parent and child processes. Specifically,
2984 # the child will indicate when it's done with its test by writing a message
2985 # to the parent.
2986 my ($readh, $writeh);
2987 unless (pipe($readh, $writeh)) {
2988 die("Can't open pipe: $!");
2989 }
2990
2991 $writeh->autoflush(1);
2992
2993 my $ex;
2994
2995 # Fork child
2996 $self->handle_sigchld();
2997 defined(my $pid = fork()) or die("Can't fork: $!");
2998 if ($pid) {
2999 eval {
3000 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3001
3002 eval { $client->login($user, $passwd) };
3003 if ($@) {
3004 my $err = $@;
3005 print $writeh "done\n";
3006 die("Failed to log in: $err");
3007 }
3008
3009 my ($resp_code, $resp_msg);
3010 eval { ($resp_code, $resp_msg) = $client->mdtm($test_file) };
3011 if ($@) {
3012 my $err = $@;
3013 print $writeh "done\n";
3014 die("Failed to MDTM: $err");
3015 }
3016
3017 my $expected;
3018
3019 $expected = 213;
3020 $self->assert($expected == $resp_code,
3021 test_msg("Expected $expected, got $resp_code"));
3022
3023 chomp($resp_msg);
3024 $self->assert(qr/\d+/, $resp_msg);
3025 };
3026
3027 if ($@) {
3028 $ex = $@;
3029 }
3030
3031 print $writeh "done\n";
3032
3033 } else {
3034 # Start server
3035 server_start($config_file);
3036
3037 # Wait until we receive word from the child that it has finished its
3038 # test.
3039 while (my $msg = <$readh>) {
3040 chomp($msg);
3041
3042 if ($msg eq 'done') {
3043 last;
3044 }
3045 }
3046
3047 exit 0;
3048 }
3049
3050 # Stop server
3051 server_stop($pid_file);
3052
3053 $self->assert_child_ok($pid);
3054
3055 if ($ex) {
3056 die($ex);
3057 }
3058
3059 unlink($log_file);
3060 }
3061
3062 sub cmds_mdtm_fails_enoent {
3063 my $self = shift;
3064
3065 my $config_file = 'tmp/cmds.conf';
3066 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
3067 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
3068 my $log_file = File::Spec->rel2abs('cmds.log');
3069
3070 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
3071 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
3072
3073 my $user = 'proftpd';
3074 my $passwd = 'test';
3075 my $home_dir = File::Spec->rel2abs('tmp');
3076
3077 my $test_file = File::Spec->rel2abs('tmp/foo');
3078
3079 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
3080 '/bin/bash');
3081 auth_group_write($auth_group_file, 'ftpd', 500, $user);
3082
3083 my $config = {
3084 PidFile => $pid_file,
3085 ScoreboardFile => $scoreboard_file,
3086 SystemLog => $log_file,
3087
3088 AuthUserFile => $auth_user_file,
3089 AuthGroupFile => $auth_group_file,
3090 AuthOrder => 'mod_auth_file.c',
3091
3092 IfModules => {
3093 'mod_delay.c' => {
3094 DelayEngine => 'off',
3095 },
3096 },
3097 };
3098
3099 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3100
3101 # Open pipes, for use between the parent and child processes. Specifically,
3102 # the child will indicate when it's done with its test by writing a message
3103 # to the parent.
3104 my ($readh, $writeh);
3105 unless (pipe($readh, $writeh)) {
3106 die("Can't open pipe: $!");
3107 }
3108
3109 $writeh->autoflush(1);
3110
3111 my $ex;
3112
3113 # Fork child
3114 $self->handle_sigchld();
3115 defined(my $pid = fork()) or die("Can't fork: $!");
3116 if ($pid) {
3117 eval {
3118 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3119
3120 eval { $client->login($user, $passwd) };
3121 if ($@) {
3122 my $err = $@;
3123 print $writeh "done\n";
3124 die("Failed to log in: $err");
3125 }
3126
3127 my ($resp_code, $resp_msg);
3128 eval { ($resp_code, $resp_msg) = $client->mdtm($test_file) };
3129 unless ($@) {
3130 print $writeh "done\n";
3131 die("MDTM succeeded unexpectedly");
3132
3133 } else {
3134 $resp_code = $client->response_code();
3135 $resp_msg = $client->response_msg();
3136 }
3137
3138 my $expected;
3139
3140 $expected = 550;
3141 $self->assert($expected == $resp_code,
3142 test_msg("Expected $expected, got $resp_code"));
3143
3144 $expected = "$test_file: No such file or directory";
3145 chomp($resp_msg);
3146 $self->assert($expected eq $resp_msg,
3147 test_msg("Expected '$expected', got '$resp_msg'"));
3148 };
3149
3150 if ($@) {
3151 $ex = $@;
3152 }
3153
3154 print $writeh "done\n";
3155
3156 } else {
3157 # Start server
3158 server_start($config_file);
3159
3160 # Wait until we receive word from the child that it has finished its
3161 # test.
3162 while (my $msg = <$readh>) {
3163 chomp($msg);
3164
3165 if ($msg eq 'done') {
3166 last;
3167 }
3168 }
3169
3170 exit 0;
3171 }
3172
3173 # Stop server
3174 server_stop($pid_file);
3175
3176 $self->assert_child_ok($pid);
3177
3178 if ($ex) {
3179 die($ex);
3180 }
3181
3182 unlink($log_file);
3183 }
3184
3185 sub cmds_mdtm_fails_eperm {
3186 my $self = shift;
3187
3188 my $config_file = 'tmp/cmds.conf';
3189 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
3190 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
3191 my $log_file = File::Spec->rel2abs('cmds.log');
3192
3193 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
3194 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
3195
3196 my $user = 'proftpd';
3197 my $passwd = 'test';
3198 my $home_dir = File::Spec->rel2abs('tmp');
3199
3200 my $test_file = File::Spec->rel2abs('tmp/foo');
3201 if (open(my $fh, "> $test_file")) {
3202 close($fh);
3203
3204 } else {
3205 die("Can't create $test_file: $!");
3206 }
3207
3208 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
3209 '/bin/bash');
3210 auth_group_write($auth_group_file, 'ftpd', 500, $user);
3211
3212 my $config = {
3213 PidFile => $pid_file,
3214 ScoreboardFile => $scoreboard_file,
3215 SystemLog => $log_file,
3216
3217 AuthUserFile => $auth_user_file,
3218 AuthGroupFile => $auth_group_file,
3219 AuthOrder => 'mod_auth_file.c',
3220
3221 IfModules => {
3222 'mod_delay.c' => {
3223 DelayEngine => 'off',
3224 },
3225 },
3226 };
3227
3228 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3229
3230 # Open pipes, for use between the parent and child processes. Specifically,
3231 # the child will indicate when it's done with its test by writing a message
3232 # to the parent.
3233 my ($readh, $writeh);
3234 unless (pipe($readh, $writeh)) {
3235 die("Can't open pipe: $!");
3236 }
3237
3238 $writeh->autoflush(1);
3239
3240 my $ex;
3241
3242 # Fork child
3243 $self->handle_sigchld();
3244 defined(my $pid = fork()) or die("Can't fork: $!");
3245 if ($pid) {
3246 eval {
3247 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3248
3249 eval { $client->login($user, $passwd) };
3250 if ($@) {
3251 my $err = $@;
3252 print $writeh "done\n";
3253 die("Failed to log in: $err");
3254 }
3255
3256 # Make it such that perms on the home do to not allow reads
3257 my $perms = (stat($home_dir))[2];
3258 unless (chmod(0220, $home_dir)) {
3259 my $err = $!;
3260 print $writeh "done\n";
3261 die("Failed to change perms on $home_dir: $err");
3262 }
3263
3264 my ($resp_code, $resp_msg);
3265 eval { ($resp_code, $resp_msg) = $client->mdtm($test_file) };
3266 unless ($@) {
3267 print $writeh "done\n";
3268 die("MDTM succeeded unexpectedly");
3269
3270 } else {
3271 $resp_code = $client->response_code();
3272 $resp_msg = $client->response_msg();
3273 }
3274
3275 chmod($perms, $home_dir);
3276
3277 my $expected;
3278
3279 $expected = 550;
3280 $self->assert($expected == $resp_code,
3281 test_msg("Expected $expected, got $resp_code"));
3282
3283 $expected = "$test_file: Permission denied";
3284 chomp($resp_msg);
3285 $self->assert($expected eq $resp_msg,
3286 test_msg("Expected '$expected', got '$resp_msg'"));
3287 };
3288
3289 if ($@) {
3290 $ex = $@;
3291 }
3292
3293 print $writeh "done\n";
3294
3295 } else {
3296 # Start server
3297 server_start($config_file);
3298
3299 # Wait until we receive word from the child that it has finished its
3300 # test.
3301 while (my $msg = <$readh>) {
3302 chomp($msg);
3303
3304 if ($msg eq 'done') {
3305 last;
3306 }
3307 }
3308
3309 exit 0;
3310 }
3311
3312 # Stop server
3313 server_stop($pid_file);
3314
3315 $self->assert_child_ok($pid);
3316
3317 if ($ex) {
3318 die($ex);
3319 }
3320
3321 unlink($log_file);
3322 }
3323
3324 sub cmds_size_ok {
3325 my $self = shift;
3326
3327 my $config_file = 'tmp/cmds.conf';
3328 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
3329 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
3330 my $log_file = File::Spec->rel2abs('cmds.log');
3331
3332 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
3333 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
3334
3335 my $user = 'proftpd';
3336 my $passwd = 'test';
3337 my $home_dir = File::Spec->rel2abs('tmp');
3338
3339 my $test_file = File::Spec->rel2abs('tmp/foo');
3340 if (open(my $fh, "> $test_file")) {
3341 print $fh "Hello, World!\n";
3342 close($fh);
3343
3344 } else {
3345 die("Can't create $test_file: $!");
3346 }
3347
3348 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
3349 '/bin/bash');
3350 auth_group_write($auth_group_file, 'ftpd', 500, $user);
3351
3352 my $config = {
3353 PidFile => $pid_file,
3354 ScoreboardFile => $scoreboard_file,
3355 SystemLog => $log_file,
3356
3357 AuthUserFile => $auth_user_file,
3358 AuthGroupFile => $auth_group_file,
3359 AuthOrder => 'mod_auth_file.c',
3360
3361 IfModules => {
3362 'mod_delay.c' => {
3363 DelayEngine => 'off',
3364 },
3365 },
3366 };
3367
3368 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3369
3370 # Open pipes, for use between the parent and child processes. Specifically,
3371 # the child will indicate when it's done with its test by writing a message
3372 # to the parent.
3373 my ($readh, $writeh);
3374 unless (pipe($readh, $writeh)) {
3375 die("Can't open pipe: $!");
3376 }
3377
3378 $writeh->autoflush(1);
3379
3380 my $ex;
3381
3382 # Fork child
3383 $self->handle_sigchld();
3384 defined(my $pid = fork()) or die("Can't fork: $!");
3385 if ($pid) {
3386 eval {
3387 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3388
3389 eval { $client->login($user, $passwd) };
3390 if ($@) {
3391 my $err = $@;
3392 print $writeh "done\n";
3393 die("Failed to log in: $err");
3394 }
3395
3396 eval { $client->type('binary') };
3397 if ($@) {
3398 my $err = $@;
3399 print $writeh "done\n";
3400 die("Failed to TYPE: $err");
3401 }
3402
3403 my ($resp_code, $resp_msg);
3404 eval { ($resp_code, $resp_msg) = $client->size($test_file) };
3405 if ($@) {
3406 my $err = $@;
3407 print $writeh "done\n";
3408 die("Failed to SIZE: $err");
3409 }
3410
3411 my $expected;
3412
3413 $expected = 213;
3414 $self->assert($expected == $resp_code,
3415 test_msg("Expected $expected, got $resp_code"));
3416
3417 $expected = 14;
3418 chomp($resp_msg);
3419 $self->assert($expected == $resp_msg,
3420 test_msg("Expected $expected, got $resp_msg"));
3421 };
3422
3423 if ($@) {
3424 $ex = $@;
3425 }
3426
3427 print $writeh "done\n";
3428
3429 } else {
3430 # Start server
3431 server_start($config_file);
3432
3433 # Wait until we receive word from the child that it has finished its
3434 # test.
3435 while (my $msg = <$readh>) {
3436 chomp($msg);
3437
3438 if ($msg eq 'done') {
3439 last;
3440 }
3441 }
3442
3443 exit 0;
3444 }
3445
3446 # Stop server
3447 server_stop($pid_file);
3448
3449 $self->assert_child_ok($pid);
3450
3451 if ($ex) {
3452 die($ex);
3453 }
3454
3455 unlink($log_file);
3456 }
3457
3458 sub cmds_size_fails_ascii {
3459 my $self = shift;
3460
3461 my $config_file = 'tmp/cmds.conf';
3462 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
3463 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
3464 my $log_file = File::Spec->rel2abs('cmds.log');
3465
3466 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
3467 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
3468
3469 my $user = 'proftpd';
3470 my $passwd = 'test';
3471 my $home_dir = File::Spec->rel2abs('tmp');
3472
3473 my $test_file = File::Spec->rel2abs('tmp/foo');
3474
3475 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
3476 '/bin/bash');
3477 auth_group_write($auth_group_file, 'ftpd', 500, $user);
3478
3479 my $config = {
3480 PidFile => $pid_file,
3481 ScoreboardFile => $scoreboard_file,
3482 SystemLog => $log_file,
3483
3484 AuthUserFile => $auth_user_file,
3485 AuthGroupFile => $auth_group_file,
3486 AuthOrder => 'mod_auth_file.c',
3487
3488 IfModules => {
3489 'mod_delay.c' => {
3490 DelayEngine => 'off',
3491 },
3492 },
3493 };
3494
3495 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3496
3497 # Open pipes, for use between the parent and child processes. Specifically,
3498 # the child will indicate when it's done with its test by writing a message
3499 # to the parent.
3500 my ($readh, $writeh);
3501 unless (pipe($readh, $writeh)) {
3502 die("Can't open pipe: $!");
3503 }
3504
3505 $writeh->autoflush(1);
3506
3507 my $ex;
3508
3509 # Fork child
3510 $self->handle_sigchld();
3511 defined(my $pid = fork()) or die("Can't fork: $!");
3512 if ($pid) {
3513 eval {
3514 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3515
3516 eval { $client->login($user, $passwd) };
3517 if ($@) {
3518 my $err = $@;
3519 print $writeh "done\n";
3520 die("Failed to log in: $err");
3521 }
3522
3523 eval { $client->type('ascii') };
3524 if ($@) {
3525 my $err = $@;
3526 print $writeh "done\n";
3527 die("Failed to TYPE: $err");
3528 }
3529
3530 my ($resp_code, $resp_msg);
3531 eval { ($resp_code, $resp_msg) = $client->size($test_file) };
3532 unless ($@) {
3533 print $writeh "done\n";
3534 die("SIZE succeeded unexpectedly");
3535
3536 } else {
3537 $resp_code = $client->response_code();
3538 $resp_msg = $client->response_msg();
3539 }
3540
3541 my $expected;
3542
3543 $expected = 550;
3544 $self->assert($expected == $resp_code,
3545 test_msg("Expected $expected, got $resp_code"));
3546
3547 $expected = "SIZE not allowed in ASCII mode";
3548 chomp($resp_msg);
3549 $self->assert($expected eq $resp_msg,
3550 test_msg("Expected '$expected', got '$resp_msg'"));
3551 };
3552
3553 if ($@) {
3554 $ex = $@;
3555 }
3556
3557 print $writeh "done\n";
3558
3559 } else {
3560 # Start server
3561 server_start($config_file);
3562
3563 # Wait until we receive word from the child that it has finished its
3564 # test.
3565 while (my $msg = <$readh>) {
3566 chomp($msg);
3567
3568 if ($msg eq 'done') {
3569 last;
3570 }
3571 }
3572
3573 exit 0;
3574 }
3575
3576 # Stop server
3577 server_stop($pid_file);
3578
3579 $self->assert_child_ok($pid);
3580
3581 if ($ex) {
3582 die($ex);
3583 }
3584
3585 unlink($log_file);
3586 }
3587
3588 sub cmds_size_fails_enoent {
3589 my $self = shift;
3590
3591 my $config_file = 'tmp/cmds.conf';
3592 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
3593 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
3594 my $log_file = File::Spec->rel2abs('cmds.log');
3595
3596 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
3597 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
3598
3599 my $user = 'proftpd';
3600 my $passwd = 'test';
3601 my $home_dir = File::Spec->rel2abs('tmp');
3602
3603 my $test_file = File::Spec->rel2abs('tmp/foo');
3604
3605 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
3606 '/bin/bash');
3607 auth_group_write($auth_group_file, 'ftpd', 500, $user);
3608
3609 my $config = {
3610 PidFile => $pid_file,
3611 ScoreboardFile => $scoreboard_file,
3612 SystemLog => $log_file,
3613
3614 AuthUserFile => $auth_user_file,
3615 AuthGroupFile => $auth_group_file,
3616 AuthOrder => 'mod_auth_file.c',
3617
3618 IfModules => {
3619 'mod_delay.c' => {
3620 DelayEngine => 'off',
3621 },
3622 },
3623 };
3624
3625 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3626
3627 # Open pipes, for use between the parent and child processes. Specifically,
3628 # the child will indicate when it's done with its test by writing a message
3629 # to the parent.
3630 my ($readh, $writeh);
3631 unless (pipe($readh, $writeh)) {
3632 die("Can't open pipe: $!");
3633 }
3634
3635 $writeh->autoflush(1);
3636
3637 my $ex;
3638
3639 # Fork child
3640 $self->handle_sigchld();
3641 defined(my $pid = fork()) or die("Can't fork: $!");
3642 if ($pid) {
3643 eval {
3644 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3645
3646 eval { $client->login($user, $passwd) };
3647 if ($@) {
3648 my $err = $@;
3649 print $writeh "done\n";
3650 die("Failed to log in: $err");
3651 }
3652
3653 eval { $client->type('binary') };
3654 if ($@) {
3655 my $err = $@;
3656 print $writeh "done\n";
3657 die("Failed to TYPE: $err");
3658 }
3659
3660 my ($resp_code, $resp_msg);
3661 eval { ($resp_code, $resp_msg) = $client->size($test_file) };
3662 unless ($@) {
3663 print $writeh "done\n";
3664 die("SIZE succeeded unexpectedly");
3665
3666 } else {
3667 $resp_code = $client->response_code();
3668 $resp_msg = $client->response_msg();
3669 }
3670
3671 my $expected;
3672
3673 $expected = 550;
3674 $self->assert($expected == $resp_code,
3675 test_msg("Expected $expected, got $resp_code"));
3676
3677 $expected = "$test_file: No such file or directory";
3678 chomp($resp_msg);
3679 $self->assert($expected eq $resp_msg,
3680 test_msg("Expected '$expected', got '$resp_msg'"));
3681 };
3682
3683 if ($@) {
3684 $ex = $@;
3685 }
3686
3687 print $writeh "done\n";
3688
3689 } else {
3690 # Start server
3691 server_start($config_file);
3692
3693 # Wait until we receive word from the child that it has finished its
3694 # test.
3695 while (my $msg = <$readh>) {
3696 chomp($msg);
3697
3698 if ($msg eq 'done') {
3699 last;
3700 }
3701 }
3702
3703 exit 0;
3704 }
3705
3706 # Stop server
3707 server_stop($pid_file);
3708
3709 $self->assert_child_ok($pid);
3710
3711 if ($ex) {
3712 die($ex);
3713 }
3714
3715 unlink($log_file);
3716 }
3717
3718 sub cmds_size_fails_eperm {
3719 my $self = shift;
3720
3721 my $config_file = 'tmp/cmds.conf';
3722 my $pid_file = File::Spec->rel2abs('tmp/cmds.pid');
3723 my $scoreboard_file = File::Spec->rel2abs('tmp/cmds.scoreboard');
3724 my $log_file = File::Spec->rel2abs('cmds.log');
3725
3726 my $auth_user_file = File::Spec->rel2abs('tmp/cmds.passwd');
3727 my $auth_group_file = File::Spec->rel2abs('tmp/cmds.group');
3728
3729 my $user = 'proftpd';
3730 my $passwd = 'test';
3731 my $home_dir = File::Spec->rel2abs('tmp');
3732
3733 my $test_file = File::Spec->rel2abs('tmp/foo');
3734 if (open(my $fh, "> $test_file")) {
3735 close($fh);
3736
3737 } else {
3738 die("Can't create $test_file: $!");
3739 }
3740
3741 auth_user_write($auth_user_file, $user, $passwd, 500, 500, $home_dir,
3742 '/bin/bash');
3743 auth_group_write($auth_group_file, 'ftpd', 500, $user);
3744
3745 my $config = {
3746 PidFile => $pid_file,
3747 ScoreboardFile => $scoreboard_file,
3748 SystemLog => $log_file,
3749
3750 AuthUserFile => $auth_user_file,
3751 AuthGroupFile => $auth_group_file,
3752 AuthOrder => 'mod_auth_file.c',
3753
3754 IfModules => {
3755 'mod_delay.c' => {
3756 DelayEngine => 'off',
3757 },
3758 },
3759 };
3760
3761 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3762
3763 # Open pipes, for use between the parent and child processes. Specifically,
3764 # the child will indicate when it's done with its test by writing a message
3765 # to the parent.
3766 my ($readh, $writeh);
3767 unless (pipe($readh, $writeh)) {
3768 die("Can't open pipe: $!");
3769 }
3770
3771 $writeh->autoflush(1);
3772
3773 my $ex;
3774
3775 # Fork child
3776 $self->handle_sigchld();
3777 defined(my $pid = fork()) or die("Can't fork: $!");
3778 if ($pid) {
3779 eval {
3780 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3781
3782 eval { $client->login($user, $passwd) };
3783 if ($@) {
3784 my $err = $@;
3785 print $writeh "done\n";
3786 die("Failed to log in: $err");
3787 }
3788
3789 eval { $client->type('binary') };
3790 if ($@) {
3791 my $err = $@;
3792 print $writeh "done\n";
3793 die("Failed to TYPE: $err");
3794 }
3795
3796 # Make it such that perms on the home dir do not allow reads
3797 my $perms = (stat($home_dir))[2];
3798 unless (chmod(0220, $home_dir)) {
3799 my $err = $!;
3800 print $writeh "done\n";
3801 die("Failed to change perms on $home_dir: $err");
3802 }
3803
3804 my ($resp_code, $resp_msg);
3805 eval { ($resp_code, $resp_msg) = $client->mdtm($test_file) };
3806 unless ($@) {
3807 print $writeh "done\n";
3808 die("MDTM succeeded unexpectedly");
3809
3810 } else {
3811 $resp_code = $client->response_code();
3812 $resp_msg = $client->response_msg();
3813 }
3814
3815 chmod($perms, $home_dir);
3816
3817 my $expected;
3818
3819 $expected = 550;
3820 $self->assert($expected == $resp_code,
3821 test_msg("Expected $expected, got $resp_code"));
3822
3823 $expected = "$test_file: Permission denied";
3824 chomp($resp_msg);
3825 $self->assert($expected eq $resp_msg,
3826 test_msg("Expected '$expected', got '$resp_msg'"));
3827 };
3828
3829 if ($@) {
3830 $ex = $@;
3831 }
3832
3833 print $writeh "done\n";
3834
3835 } else {
3836 # Start server
3837 server_start($config_file);
3838
3839 # Wait until we receive word from the child that it has finished its
3840 # test.
3841 while (my $msg = <$readh>) {
3842 chomp($msg);
3843
3844 if ($msg eq 'done') {
3845 last;
3846 }
3847 }
3848
3849 exit 0;
3850 }
3851
3852 # Stop server
3853 server_stop($pid_file);
3854
3855 $self->assert_child_ok($pid);
3856
3857 if ($ex) {
3858 die($ex);
3859 }
3860
3861 unlink($log_file);
3862 }
3863
3864 1;