Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Commands::MKD;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Cwd;
8 use Encode;
9 use File::Path qw(mkpath);
10 use File::Spec;
11 use IO::Handle;
12 use IO::Socket::INET;
13
14 use ProFTPD::TestSuite::FTP;
15 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
16
17 $| = 1;
18
19 my $order = 0;
20
21 my $TESTS = {
22 mkd_ok => {
23 order => ++$order,
24 test_class => [qw(forking)],
25 },
26
27 mkd_fails_abs_symlink_new => {
28 order => ++$order,
29 test_class => [qw(forking)],
30 },
31
32 mkd_fails_abs_symlink_new_chrooted_bug4219 => {
33 order => ++$order,
34 test_class => [qw(bug forking rootprivs)],
35 },
36
37 mkd_fails_rel_symlink_new => {
38 order => ++$order,
39 test_class => [qw(forking)],
40 },
41
42 mkd_fails_rel_symlink_new_chrooted_bug4219 => {
43 order => ++$order,
44 test_class => [qw(bug forking rootprivs)],
45 },
46
47 mkd_umask_one_param_ok => {
48 order => ++$order,
49 test_class => [qw(forking)],
50 },
51
52 mkd_umask_two_params_ok => {
53 order => ++$order,
54 test_class => [qw(forking)],
55 },
56
57 mkd_with_spaces_ok => {
58 order => ++$order,
59 test_class => [qw(forking)],
60 },
61
62 mkd_utf8_with_spaces_ok => {
63 order => ++$order,
64 test_class => [qw(feature_nls forking)],
65 },
66
67 mkd_chrooted_ok => {
68 order => ++$order,
69 test_class => [qw(forking rootprivs)],
70 },
71
72 mkd_chrooted_with_cwd_ok => {
73 order => ++$order,
74 test_class => [qw(forking rootprivs)],
75 },
76
77 mkd_sgid_umask_one_param_ok => {
78 order => ++$order,
79 test_class => [qw(forking)],
80 },
81
82 mkd_sgid_umask_two_params_ok => {
83 order => ++$order,
84 test_class => [qw(forking)],
85 },
86
87 mkd_fails_enoent => {
88 order => ++$order,
89 test_class => [qw(forking)],
90 },
91
92 mkd_fails_eperm => {
93 order => ++$order,
94 test_class => [qw(forking)],
95 },
96
97 mkd_fails_eexists => {
98 order => ++$order,
99 test_class => [qw(forking)],
100 },
101
102 xmkd_ok => {
103 order => ++$order,
104 test_class => [qw(forking)],
105 },
106
107 mkd_digits_ok => {
108 order => ++$order,
109 test_class => [qw(forking)],
110 },
111
112 mkd_embedded_cr_bug4167 => {
113 order => ++$order,
114 test_class => [qw(bug forking)],
115 },
116
117 mkd_embedded_lf_bug4167 => {
118 order => ++$order,
119 test_class => [qw(bug forking)],
120 },
121
122 mkd_already_exists_issue1639 => {
123 order => ++$order,
124 test_class => [qw(bug forking)],
125 },
126
127 };
128
129 sub new {
130 return shift()->SUPER::new(@_);
131 }
132
133 sub list_tests {
134 return testsuite_get_runnable_tests($TESTS);
135 }
136
137 sub mkd_ok {
138 my $self = shift;
139 my $tmpdir = $self->{tmpdir};
140 my $setup = test_setup($tmpdir, 'cmds');
141
142 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
143
144 my $config = {
145 PidFile => $setup->{pid_file},
146 ScoreboardFile => $setup->{scoreboard_file},
147 SystemLog => $setup->{log_file},
148
149 AuthUserFile => $setup->{auth_user_file},
150 AuthGroupFile => $setup->{auth_group_file},
151 AuthOrder => 'mod_auth_file.c',
152
153 IfModules => {
154 'mod_delay.c' => {
155 DelayEngine => 'off',
156 },
157 },
158 };
159
160 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
161 $config);
162
163 # Open pipes, for use between the parent and child processes. Specifically,
164 # the child will indicate when it's done with its test by writing a message
165 # to the parent.
166 my ($rfh, $wfh);
167 unless (pipe($rfh, $wfh)) {
168 die("Can't open pipe: $!");
169 }
170
171 my $ex;
172
173 # Fork child
174 $self->handle_sigchld();
175 defined(my $pid = fork()) or die("Can't fork: $!");
176 if ($pid) {
177 eval {
178 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
179 $client->login($setup->{user}, $setup->{passwd});
180
181 my ($resp_code, $resp_msg) = $client->mkd($sub_dir);
182 $client->quit();
183
184 my $expected = 257;
185 $self->assert($expected == $resp_code,
186 test_msg("Expected response code $expected, got $resp_code"));
187
188 $expected = "\"$sub_dir\" - Directory successfully created";
189 $self->assert($expected eq $resp_msg,
190 test_msg("Expected response message '$expected', got '$resp_msg'"));
191
192 $self->assert(-d $sub_dir,
193 test_msg("$sub_dir directory does not exist as expected"));
194
195 my $perms = ((stat($sub_dir))[2] & 07777);
196 $expected = 0755;
197 $self->assert($expected == $perms,
198 test_msg("Expected perms $expected, got $perms"));
199 };
200 if ($@) {
201 $ex = $@;
202 }
203
204 $wfh->print("done\n");
205 $wfh->flush();
206
207 } else {
208 eval { server_wait($setup->{config_file}, $rfh) };
209 if ($@) {
210 warn($@);
211 exit 1;
212 }
213
214 exit 0;
215 }
216
217 # Stop server
218 server_stop($setup->{pid_file});
219 $self->assert_child_ok($pid);
220
221 test_cleanup($setup->{log_file}, $ex);
222 }
223
224 sub mkd_fails_abs_symlink_new {
225 my $self = shift;
226 my $tmpdir = $self->{tmpdir};
227 my $setup = test_setup($tmpdir, 'cmds');
228
229 my $test_dir = File::Spec->rel2abs("$tmpdir/foo.d");
230 my $test_symlink = File::Spec->rel2abs("$tmpdir/test.lnk");
231
232 my $dst_path = $test_dir;
233 if ($^O eq 'darwin') {
234 # MacOSX-related hack
235 $dst_path = '/private' . $dst_path;
236 }
237
238 unless (symlink($dst_path, $test_symlink)) {
239 die("Can't symlink '$test_symlink' to '$dst_path': $!");
240 }
241
242 my $config = {
243 PidFile => $setup->{pid_file},
244 ScoreboardFile => $setup->{scoreboard_file},
245 SystemLog => $setup->{log_file},
246 TraceLog => $setup->{log_file},
247 Trace => 'fsio:20',
248
249 AuthUserFile => $setup->{auth_user_file},
250 AuthGroupFile => $setup->{auth_group_file},
251 AuthOrder => 'mod_auth_file.c',
252
253 IfModules => {
254 'mod_delay.c' => {
255 DelayEngine => 'off',
256 },
257 },
258 };
259
260 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
261 $config);
262
263 # Open pipes, for use between the parent and child processes. Specifically,
264 # the child will indicate when it's done with its test by writing a message
265 # to the parent.
266 my ($rfh, $wfh);
267 unless (pipe($rfh, $wfh)) {
268 die("Can't open pipe: $!");
269 }
270
271 my $ex;
272
273 # Fork child
274 $self->handle_sigchld();
275 defined(my $pid = fork()) or die("Can't fork: $!");
276 if ($pid) {
277 eval {
278 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
279 $client->login($setup->{user}, $setup->{passwd});
280
281 eval { $client->mkd('test.lnk') };
282 unless ($@) {
283 die("MKD succeeded unexpectedly");
284 }
285
286 my $resp_code = $client->response_code();
287 my $resp_msg = $client->response_msg();
288 $client->quit();
289
290 my $expected = 550;
291 $self->assert($expected == $resp_code,
292 test_msg("Expected response code $expected, got $resp_code"));
293
294 if ($^O eq 'darwin') {
295 # MacOSX-specific hack
296 $test_symlink = '/private' . $test_symlink;
297 }
298
299 $expected = "test.lnk: File exists";
300 $self->assert($expected eq $resp_msg,
301 test_msg("Expected response message '$expected', got '$resp_msg'"));
302
303 $self->assert(!-d $test_dir,
304 test_msg("$test_dir directory does not exist as expected"));
305 };
306 if ($@) {
307 $ex = $@;
308 }
309
310 $wfh->print("done\n");
311 $wfh->flush();
312
313 } else {
314 eval { server_wait($setup->{config_file}, $rfh) };
315 if ($@) {
316 warn($@);
317 exit 1;
318 }
319
320 exit 0;
321 }
322
323 # Stop server
324 server_stop($setup->{pid_file});
325 $self->assert_child_ok($pid);
326
327 test_cleanup($setup->{log_file}, $ex);
328 }
329
330 sub mkd_fails_abs_symlink_new_chrooted_bug4219 {
331 my $self = shift;
332 my $tmpdir = $self->{tmpdir};
333 my $setup = test_setup($tmpdir, 'cmds');
334
335 my $test_dir = File::Spec->rel2abs("$tmpdir/foo.d");
336 my $test_symlink = File::Spec->rel2abs("$tmpdir/test.lnk");
337
338 my $dst_path = $test_dir;
339 if ($^O eq 'darwin') {
340 # MacOSX-related hack
341 $dst_path = '/private' . $dst_path;
342 }
343
344 unless (symlink($dst_path, $test_symlink)) {
345 die("Can't symlink '$test_symlink' to '$dst_path': $!");
346 }
347
348 my $config = {
349 PidFile => $setup->{pid_file},
350 ScoreboardFile => $setup->{scoreboard_file},
351 SystemLog => $setup->{log_file},
352 TraceLog => $setup->{log_file},
353 Trace => 'fsio:20',
354
355 AuthUserFile => $setup->{auth_user_file},
356 AuthGroupFile => $setup->{auth_group_file},
357 AuthOrder => 'mod_auth_file.c',
358
359 DefaultRoot => '~',
360
361 IfModules => {
362 'mod_delay.c' => {
363 DelayEngine => 'off',
364 },
365 },
366 };
367
368 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
369 $config);
370
371 # Open pipes, for use between the parent and child processes. Specifically,
372 # the child will indicate when it's done with its test by writing a message
373 # to the parent.
374 my ($rfh, $wfh);
375 unless (pipe($rfh, $wfh)) {
376 die("Can't open pipe: $!");
377 }
378
379 my $ex;
380
381 # Fork child
382 $self->handle_sigchld();
383 defined(my $pid = fork()) or die("Can't fork: $!");
384 if ($pid) {
385 eval {
386 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
387 $client->login($setup->{user}, $setup->{passwd});
388
389 eval { $client->mkd('test.lnk') };
390 unless ($@) {
391 die("MKD succeeded unexpectedly");
392 }
393
394 my $resp_code = $client->response_code();
395 my $resp_msg = $client->response_msg();
396 $client->quit();
397
398 my $expected = 550;
399 $self->assert($expected == $resp_code,
400 test_msg("Expected response code $expected, got $resp_code"));
401
402 if ($^O eq 'darwin') {
403 # MacOSX-specific hack
404 $test_symlink = '/private' . $test_symlink;
405 }
406
407 $expected = "test.lnk: File exists";
408 $self->assert($expected eq $resp_msg,
409 test_msg("Expected response message '$expected', got '$resp_msg'"));
410
411 $self->assert(!-d $test_dir,
412 test_msg("$test_dir directory does not exist as expected"));
413 };
414 if ($@) {
415 $ex = $@;
416 }
417
418 $wfh->print("done\n");
419 $wfh->flush();
420
421 } else {
422 eval { server_wait($setup->{config_file}, $rfh) };
423 if ($@) {
424 warn($@);
425 exit 1;
426 }
427
428 exit 0;
429 }
430
431 # Stop server
432 server_stop($setup->{pid_file});
433 $self->assert_child_ok($pid);
434
435 test_cleanup($setup->{log_file}, $ex);
436 }
437
438 sub mkd_fails_rel_symlink_new {
439 my $self = shift;
440 my $tmpdir = $self->{tmpdir};
441 my $setup = test_setup($tmpdir, 'cmds');
442
443 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
444 mkpath($test_dir);
445
446 # Change to the test directory in order to create a relative path in the
447 # symlink we need
448
449 my $cwd = getcwd();
450 unless (chdir($test_dir)) {
451 die("Can't chdir to $test_dir: $!");
452 }
453
454 unless (symlink('./test.d', './test.lnk')) {
455 die("Can't symlink 'test.lnk' to './test.d': $!");
456 }
457
458 unless (chdir($cwd)) {
459 die("Can't chdir to $cwd: $!");
460 }
461
462 my $config = {
463 PidFile => $setup->{pid_file},
464 ScoreboardFile => $setup->{scoreboard_file},
465 SystemLog => $setup->{log_file},
466 TraceLog => $setup->{log_file},
467 Trace => 'fsio:20',
468
469 AuthUserFile => $setup->{auth_user_file},
470 AuthGroupFile => $setup->{auth_group_file},
471 AuthOrder => 'mod_auth_file.c',
472
473 IfModules => {
474 'mod_delay.c' => {
475 DelayEngine => 'off',
476 },
477 },
478 };
479
480 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
481 $config);
482
483 # Open pipes, for use between the parent and child processes. Specifically,
484 # the child will indicate when it's done with its test by writing a message
485 # to the parent.
486 my ($rfh, $wfh);
487 unless (pipe($rfh, $wfh)) {
488 die("Can't open pipe: $!");
489 }
490
491 my $ex;
492
493 # Fork child
494 $self->handle_sigchld();
495 defined(my $pid = fork()) or die("Can't fork: $!");
496 if ($pid) {
497 eval {
498 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
499 $client->login($setup->{user}, $setup->{passwd});
500
501 eval { $client->mkd('test.d/test.lnk') };
502 unless ($@) {
503 die("MKD succeeded unexpectedly");
504 }
505
506 my $resp_code = $client->response_code();
507 my $resp_msg = $client->response_msg();
508 $client->quit();
509
510 my $expected = 550;
511 $self->assert($expected == $resp_code,
512 test_msg("Expected response code $expected, got $resp_code"));
513
514 $expected = "test.d\/test.lnk: File exists";
515 $self->assert($expected eq $resp_msg,
516 test_msg("Expected response message '$expected', got '$resp_msg'"));
517 };
518 if ($@) {
519 $ex = $@;
520 }
521
522 $wfh->print("done\n");
523 $wfh->flush();
524
525 } else {
526 eval { server_wait($setup->{config_file}, $rfh) };
527 if ($@) {
528 warn($@);
529 exit 1;
530 }
531
532 exit 0;
533 }
534
535 # Stop server
536 server_stop($setup->{pid_file});
537 $self->assert_child_ok($pid);
538
539 test_cleanup($setup->{log_file}, $ex);
540 }
541
542 sub mkd_fails_rel_symlink_new_chrooted_bug4219 {
543 my $self = shift;
544 my $tmpdir = $self->{tmpdir};
545 my $setup = test_setup($tmpdir, 'cmds');
546
547 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
548 mkpath($test_dir);
549
550 # Change to the test directory in order to create a relative path in the
551 # symlink we need
552
553 my $cwd = getcwd();
554 unless (chdir($test_dir)) {
555 die("Can't chdir to $test_dir: $!");
556 }
557
558 unless (symlink('./test.d', './test.lnk')) {
559 die("Can't symlink 'test.lnk' to './test.d': $!");
560 }
561
562 unless (chdir($cwd)) {
563 die("Can't chdir to $cwd: $!");
564 }
565
566 my $config = {
567 PidFile => $setup->{pid_file},
568 ScoreboardFile => $setup->{scoreboard_file},
569 SystemLog => $setup->{log_file},
570 TraceLog => $setup->{log_file},
571 Trace => 'fsio:20',
572
573 AuthUserFile => $setup->{auth_user_file},
574 AuthGroupFile => $setup->{auth_group_file},
575 AuthOrder => 'mod_auth_file.c',
576
577 DefaultRoot => '~',
578
579 IfModules => {
580 'mod_delay.c' => {
581 DelayEngine => 'off',
582 },
583 },
584 };
585
586 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
587 $config);
588
589 # Open pipes, for use between the parent and child processes. Specifically,
590 # the child will indicate when it's done with its test by writing a message
591 # to the parent.
592 my ($rfh, $wfh);
593 unless (pipe($rfh, $wfh)) {
594 die("Can't open pipe: $!");
595 }
596
597 my $ex;
598
599 # Fork child
600 $self->handle_sigchld();
601 defined(my $pid = fork()) or die("Can't fork: $!");
602 if ($pid) {
603 eval {
604 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
605 $client->login($setup->{user}, $setup->{passwd});
606
607 eval { $client->mkd('test.d/test.lnk') };
608 unless ($@) {
609 die("MKD succeeded unexpectedly");
610 }
611
612 my $resp_code = $client->response_code();
613 my $resp_msg = $client->response_msg();
614 $client->quit();
615
616 my $expected = 550;
617 $self->assert($expected == $resp_code,
618 test_msg("Expected response code $expected, got $resp_code"));
619
620 $expected = "test.d\/test.lnk: File exists";
621 $self->assert($expected eq $resp_msg,
622 test_msg("Expected response message '$expected', got '$resp_msg'"));
623 };
624 if ($@) {
625 $ex = $@;
626 }
627
628 $wfh->print("done\n");
629 $wfh->flush();
630
631 } else {
632 eval { server_wait($setup->{config_file}, $rfh) };
633 if ($@) {
634 warn($@);
635 exit 1;
636 }
637
638 exit 0;
639 }
640
641 # Stop server
642 server_stop($setup->{pid_file});
643 $self->assert_child_ok($pid);
644
645 test_cleanup($setup->{log_file}, $ex);
646 }
647
648 sub mkd_umask_one_param_ok {
649 my $self = shift;
650 my $tmpdir = $self->{tmpdir};
651 my $setup = test_setup($tmpdir, 'cmds');
652
653 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
654
655 my $config = {
656 PidFile => $setup->{pid_file},
657 ScoreboardFile => $setup->{scoreboard_file},
658 SystemLog => $setup->{log_file},
659
660 AuthUserFile => $setup->{auth_user_file},
661 AuthGroupFile => $setup->{auth_group_file},
662 AuthOrder => 'mod_auth_file.c',
663
664 Umask => '077',
665
666 IfModules => {
667 'mod_delay.c' => {
668 DelayEngine => 'off',
669 },
670 },
671 };
672
673 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
674 $config);
675
676 # Open pipes, for use between the parent and child processes. Specifically,
677 # the child will indicate when it's done with its test by writing a message
678 # to the parent.
679 my ($rfh, $wfh);
680 unless (pipe($rfh, $wfh)) {
681 die("Can't open pipe: $!");
682 }
683
684 my $ex;
685
686 # Fork child
687 $self->handle_sigchld();
688 defined(my $pid = fork()) or die("Can't fork: $!");
689 if ($pid) {
690 eval {
691 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
692 $client->login($setup->{user}, $setup->{passwd});
693
694 my ($resp_code, $resp_msg) = $client->mkd($sub_dir);
695 $client->quit();
696
697 my $expected = 257;
698 $self->assert($expected == $resp_code,
699 test_msg("Expected response code $expected, got $resp_code"));
700
701 $expected = "\"$sub_dir\" - Directory successfully created";
702 $self->assert($expected eq $resp_msg,
703 test_msg("Expected response message '$expected', got '$resp_msg'"));
704
705 $self->assert(-d $sub_dir,
706 test_msg("$sub_dir directory does not exist as expected"));
707
708 my $perms = ((stat($sub_dir))[2] & 07777);
709 $expected = 0700;
710 $self->assert($expected == $perms,
711 test_msg("Expected perms $expected, got $perms"));
712 };
713 if ($@) {
714 $ex = $@;
715 }
716
717 $wfh->print("done\n");
718 $wfh->flush();
719
720 } else {
721 eval { server_wait($setup->{config_file}, $rfh) };
722 if ($@) {
723 warn($@);
724 exit 1;
725 }
726
727 exit 0;
728 }
729
730 # Stop server
731 server_stop($setup->{pid_file});
732 $self->assert_child_ok($pid);
733
734 test_cleanup($setup->{log_file}, $ex);
735 }
736
737 sub mkd_umask_two_params_ok {
738 my $self = shift;
739 my $tmpdir = $self->{tmpdir};
740 my $setup = test_setup($tmpdir, 'cmds');
741
742 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
743
744 my $config = {
745 PidFile => $setup->{pid_file},
746 ScoreboardFile => $setup->{scoreboard_file},
747 SystemLog => $setup->{log_file},
748
749 AuthUserFile => $setup->{auth_user_file},
750 AuthGroupFile => $setup->{auth_group_file},
751 AuthOrder => 'mod_auth_file.c',
752
753 Umask => '022 077',
754
755 IfModules => {
756 'mod_delay.c' => {
757 DelayEngine => 'off',
758 },
759 },
760 };
761
762 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
763 $config);
764
765 # Open pipes, for use between the parent and child processes. Specifically,
766 # the child will indicate when it's done with its test by writing a message
767 # to the parent.
768 my ($rfh, $wfh);
769 unless (pipe($rfh, $wfh)) {
770 die("Can't open pipe: $!");
771 }
772
773 my $ex;
774
775 # Fork child
776 $self->handle_sigchld();
777 defined(my $pid = fork()) or die("Can't fork: $!");
778 if ($pid) {
779 eval {
780 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
781 $client->login($setup->{user}, $setup->{passwd});
782
783 my ($resp_code, $resp_msg) = $client->mkd($sub_dir);
784 $client->quit();
785
786 my $expected = 257;
787 $self->assert($expected == $resp_code,
788 test_msg("Expected response code $expected, got $resp_code"));
789
790 $expected = "\"$sub_dir\" - Directory successfully created";
791 $self->assert($expected eq $resp_msg,
792 test_msg("Expected response message '$expected', got '$resp_msg'"));
793
794 $self->assert(-d $sub_dir,
795 test_msg("$sub_dir directory does not exist as expected"));
796
797 my $perms = ((stat($sub_dir))[2] & 07777);
798 $expected = 0700;
799 $self->assert($expected == $perms,
800 test_msg("Expected perms $expected, got $perms"));
801 };
802 if ($@) {
803 $ex = $@;
804 }
805
806 $wfh->print("done\n");
807 $wfh->flush();
808
809 } else {
810 eval { server_wait($setup->{config_file}, $rfh) };
811 if ($@) {
812 warn($@);
813 exit 1;
814 }
815
816 exit 0;
817 }
818
819 # Stop server
820 server_stop($setup->{pid_file});
821 $self->assert_child_ok($pid);
822
823 test_cleanup($setup->{log_file}, $ex);
824 }
825
826 sub mkd_with_spaces_ok {
827 my $self = shift;
828 my $tmpdir = $self->{tmpdir};
829 my $setup = test_setup($tmpdir, 'cmds');
830
831 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo bar");
832
833 my $config = {
834 PidFile => $setup->{pid_file},
835 ScoreboardFile => $setup->{scoreboard_file},
836 SystemLog => $setup->{log_file},
837
838 AuthUserFile => $setup->{auth_user_file},
839 AuthGroupFile => $setup->{auth_group_file},
840 AuthOrder => 'mod_auth_file.c',
841
842 IfModules => {
843 'mod_delay.c' => {
844 DelayEngine => 'off',
845 },
846 },
847 };
848
849 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
850 $config);
851
852 # Open pipes, for use between the parent and child processes. Specifically,
853 # the child will indicate when it's done with its test by writing a message
854 # to the parent.
855 my ($rfh, $wfh);
856 unless (pipe($rfh, $wfh)) {
857 die("Can't open pipe: $!");
858 }
859
860 my $ex;
861
862 # Fork child
863 $self->handle_sigchld();
864 defined(my $pid = fork()) or die("Can't fork: $!");
865 if ($pid) {
866 eval {
867 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
868 $client->login($setup->{user}, $setup->{passwd});
869
870 my ($resp_code, $resp_msg) = $client->mkd($sub_dir);
871 $client->quit();
872
873 my $expected = 257;
874 $self->assert($expected == $resp_code,
875 test_msg("Expected response code $expected, got $resp_code"));
876
877 $expected = "\"$sub_dir\" - Directory successfully created";
878 $self->assert($expected eq $resp_msg,
879 test_msg("Expected response message '$expected', got '$resp_msg'"));
880
881 $self->assert(-d $sub_dir,
882 test_msg("$sub_dir directory does not exist as expected"));
883 };
884 if ($@) {
885 $ex = $@;
886 }
887
888 $wfh->print("done\n");
889 $wfh->flush();
890
891 } else {
892 eval { server_wait($setup->{config_file}, $rfh) };
893 if ($@) {
894 warn($@);
895 exit 1;
896 }
897
898 exit 0;
899 }
900
901 # Stop server
902 server_stop($setup->{pid_file});
903 $self->assert_child_ok($pid);
904
905 test_cleanup($setup->{log_file}, $ex);
906 }
907
908 sub mkd_utf8_with_spaces_ok {
909 my $self = shift;
910 my $tmpdir = $self->{tmpdir};
911 my $setup = test_setup($tmpdir, 'cmds');
912
913 my $sub_dir = 'olá çim poi...!#$%#%$>= ü';
914 my $utf8_dir = encode_utf8($sub_dir);
915
916 my $sub_path = File::Spec->rel2abs("$tmpdir/$sub_dir");
917 my $utf8_path = encode_utf8($sub_path);
918
919 my $config = {
920 PidFile => $setup->{pid_file},
921 ScoreboardFile => $setup->{scoreboard_file},
922 SystemLog => $setup->{log_file},
923 TraceLog => $setup->{log_file},
924 Trace => 'encode:10',
925
926 AuthUserFile => $setup->{auth_user_file},
927 AuthGroupFile => $setup->{auth_group_file},
928 AuthOrder => 'mod_auth_file.c',
929
930 IfModules => {
931 'mod_delay.c' => {
932 DelayEngine => 'off',
933 },
934
935 'mod_lang.c' => {
936 UseEncoding => 'on',
937 },
938 },
939 };
940
941 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
942 $config);
943
944 # Open pipes, for use between the parent and child processes. Specifically,
945 # the child will indicate when it's done with its test by writing a message
946 # to the parent.
947 my ($rfh, $wfh);
948 unless (pipe($rfh, $wfh)) {
949 die("Can't open pipe: $!");
950 }
951
952 my $ex;
953
954 # Fork child
955 $self->handle_sigchld();
956 defined(my $pid = fork()) or die("Can't fork: $!");
957 if ($pid) {
958 eval {
959 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
960 $client->login($setup->{user}, $setup->{passwd});
961
962 my ($resp_code, $resp_msg) = $client->mkd($utf8_dir);
963 $client->quit();
964
965 my $expected = 257;
966 $self->assert($expected == $resp_code,
967 test_msg("Expected response code $expected, got $resp_code"));
968
969 $expected = "\"$utf8_path\" - Directory successfully created";
970 $self->assert($expected eq $resp_msg,
971 test_msg("Expected response message '$expected', got '$resp_msg'"));
972
973 $self->assert(-d $utf8_path,
974 test_msg("$utf8_path directory does not exist as expected"));
975 };
976 if ($@) {
977 $ex = $@;
978 }
979
980 $wfh->print("done\n");
981 $wfh->flush();
982
983 } else {
984 eval { server_wait($setup->{config_file}, $rfh) };
985 if ($@) {
986 warn($@);
987 exit 1;
988 }
989
990 exit 0;
991 }
992
993 # Stop server
994 server_stop($setup->{pid_file});
995 $self->assert_child_ok($pid);
996
997 test_cleanup($setup->{log_file}, $ex);
998 }
999
1000 sub mkd_chrooted_ok {
1001 my $self = shift;
1002 my $tmpdir = $self->{tmpdir};
1003 my $setup = test_setup($tmpdir, 'cmds');
1004
1005 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1006
1007 my $config = {
1008 PidFile => $setup->{pid_file},
1009 ScoreboardFile => $setup->{scoreboard_file},
1010 SystemLog => $setup->{log_file},
1011
1012 AuthUserFile => $setup->{auth_user_file},
1013 AuthGroupFile => $setup->{auth_group_file},
1014 AuthOrder => 'mod_auth_file.c',
1015
1016 DefaultRoot => '~',
1017
1018 IfModules => {
1019 'mod_delay.c' => {
1020 DelayEngine => 'off',
1021 },
1022 },
1023 };
1024
1025 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1026 $config);
1027
1028 # Open pipes, for use between the parent and child processes. Specifically,
1029 # the child will indicate when it's done with its test by writing a message
1030 # to the parent.
1031 my ($rfh, $wfh);
1032 unless (pipe($rfh, $wfh)) {
1033 die("Can't open pipe: $!");
1034 }
1035
1036 my $ex;
1037
1038 # Fork child
1039 $self->handle_sigchld();
1040 defined(my $pid = fork()) or die("Can't fork: $!");
1041 if ($pid) {
1042 eval {
1043 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1044 $client->login($setup->{user}, $setup->{passwd});
1045
1046 my ($resp_code, $resp_msg) = $client->mkd('foo');
1047 $client->quit();
1048
1049 my $expected = 257;
1050 $self->assert($expected == $resp_code,
1051 test_msg("Expected response code $expected, got $resp_code"));
1052
1053 $expected = "\"/foo\" - Directory successfully created";
1054 $self->assert($expected eq $resp_msg,
1055 test_msg("Expected response message '$expected', got '$resp_msg'"));
1056
1057 $self->assert(-d $sub_dir,
1058 test_msg("$sub_dir directory does not exist as expected"));
1059
1060 my $perms = ((stat($sub_dir))[2] & 07777);
1061 $expected = 0755;
1062 $self->assert($expected == $perms,
1063 test_msg("Expected perms $expected, got $perms"));
1064 };
1065 if ($@) {
1066 $ex = $@;
1067 }
1068
1069 $wfh->print("done\n");
1070 $wfh->flush();
1071
1072 } else {
1073 eval { server_wait($setup->{config_file}, $rfh) };
1074 if ($@) {
1075 warn($@);
1076 exit 1;
1077 }
1078
1079 exit 0;
1080 }
1081
1082 # Stop server
1083 server_stop($setup->{pid_file});
1084 $self->assert_child_ok($pid);
1085
1086 test_cleanup($setup->{log_file}, $ex);
1087 }
1088
1089 sub mkd_chrooted_with_cwd_ok {
1090 my $self = shift;
1091 my $tmpdir = $self->{tmpdir};
1092 my $setup = test_setup($tmpdir, 'cmds');
1093
1094 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1095 mkpath($sub_dir);
1096
1097 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar");
1098
1099 if ($< == 0) {
1100 unless (chmod(0755, $sub_dir)) {
1101 die("Can't set perms on $sub_dir to 0755: $!");
1102 }
1103
1104 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
1105 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
1106 }
1107 }
1108
1109 my $config = {
1110 PidFile => $setup->{pid_file},
1111 ScoreboardFile => $setup->{scoreboard_file},
1112 SystemLog => $setup->{log_file},
1113
1114 AuthUserFile => $setup->{auth_user_file},
1115 AuthGroupFile => $setup->{auth_group_file},
1116 AuthOrder => 'mod_auth_file.c',
1117
1118 DefaultRoot => '~',
1119
1120 IfModules => {
1121 'mod_delay.c' => {
1122 DelayEngine => 'off',
1123 },
1124 },
1125 };
1126
1127 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1128 $config);
1129
1130 # Open pipes, for use between the parent and child processes. Specifically,
1131 # the child will indicate when it's done with its test by writing a message
1132 # to the parent.
1133 my ($rfh, $wfh);
1134 unless (pipe($rfh, $wfh)) {
1135 die("Can't open pipe: $!");
1136 }
1137
1138 my $ex;
1139
1140 # Fork child
1141 $self->handle_sigchld();
1142 defined(my $pid = fork()) or die("Can't fork: $!");
1143 if ($pid) {
1144 eval {
1145 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1146 $client->login($setup->{user}, $setup->{passwd});
1147 $client->cwd('foo');
1148
1149 my ($resp_code, $resp_msg) = $client->xmkd('bar');
1150 $client->quit();
1151
1152 my $expected = 257;
1153 $self->assert($expected == $resp_code,
1154 test_msg("Expected response code $expected, got $resp_code"));
1155
1156 $expected = "\"/foo/bar\" - Directory successfully created";
1157 $self->assert($expected eq $resp_msg,
1158 test_msg("Expected response message '$expected', got '$resp_msg'"));
1159
1160 $self->assert(-d $test_dir,
1161 test_msg("$test_dir directory does not exist as expected"));
1162
1163 my $perms = ((stat($sub_dir))[2] & 07777);
1164 $expected = 0755;
1165 $self->assert($expected == $perms,
1166 test_msg("Expected perms $expected, got $perms"));
1167 };
1168 if ($@) {
1169 $ex = $@;
1170 }
1171
1172 $wfh->print("done\n");
1173 $wfh->flush();
1174
1175 } else {
1176 eval { server_wait($setup->{config_file}, $rfh) };
1177 if ($@) {
1178 warn($@);
1179 exit 1;
1180 }
1181
1182 exit 0;
1183 }
1184
1185 # Stop server
1186 server_stop($setup->{pid_file});
1187 $self->assert_child_ok($pid);
1188
1189 test_cleanup($setup->{log_file}, $ex);
1190 }
1191
1192 sub mkd_sgid_umask_one_param_ok {
1193 my $self = shift;
1194 my $tmpdir = $self->{tmpdir};
1195 my $setup = test_setup($tmpdir, 'cmds');
1196
1197 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1198 mkpath($sub_dir);
1199
1200 my $test_dir = File::Spec->rel2abs("$sub_dir/test.d");
1201
1202 if ($< == 0) {
1203 unless (chmod(0755, $sub_dir)) {
1204 die("Can't set perms on $sub_dir to 0755: $!");
1205 }
1206
1207 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
1208 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
1209 }
1210 }
1211
1212 # Make sure that our sub directory has the SGID bit set
1213 my $mode = 2755;
1214 unless (chmod($mode, $sub_dir)) {
1215 die("Can't set perms on $sub_dir: $!");
1216 }
1217
1218 my $config = {
1219 PidFile => $setup->{pid_file},
1220 ScoreboardFile => $setup->{scoreboard_file},
1221 SystemLog => $setup->{log_file},
1222
1223 AuthUserFile => $setup->{auth_user_file},
1224 AuthGroupFile => $setup->{auth_group_file},
1225 AuthOrder => 'mod_auth_file.c',
1226
1227 Umask => '077',
1228
1229 IfModules => {
1230 'mod_delay.c' => {
1231 DelayEngine => 'off',
1232 },
1233 },
1234 };
1235
1236 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1237 $config);
1238
1239 # Open pipes, for use between the parent and child processes. Specifically,
1240 # the child will indicate when it's done with its test by writing a message
1241 # to the parent.
1242 my ($rfh, $wfh);
1243 unless (pipe($rfh, $wfh)) {
1244 die("Can't open pipe: $!");
1245 }
1246
1247 my $ex;
1248
1249 # Fork child
1250 $self->handle_sigchld();
1251 defined(my $pid = fork()) or die("Can't fork: $!");
1252 if ($pid) {
1253 eval {
1254 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1255 $client->login($setup->{user}, $setup->{passwd});
1256
1257 my ($resp_code, $resp_msg) = $client->mkd($test_dir);
1258 $client->quit();
1259
1260 my $expected = 257;
1261 $self->assert($expected == $resp_code,
1262 test_msg("Expected response code $expected, got $resp_code"));
1263
1264 $expected = "\"$test_dir\" - Directory successfully created";
1265 $self->assert($expected eq $resp_msg,
1266 test_msg("Expected response message '$expected', got '$resp_msg'"));
1267
1268 $self->assert(-d $test_dir,
1269 test_msg("$test_dir directory does not exist as expected"));
1270
1271 my $perms = sprintf("%04o", ((stat($test_dir))[2] & 07777));
1272 $expected = '0700';
1273 if ($^O =~ /bsd/i) {
1274 # *BSD filesystems inherit their SGID bit from parent directories
1275 $expected = '2700';
1276 }
1277
1278 $self->assert($expected eq $perms,
1279 "Expected perms $expected, got $perms");
1280 };
1281 if ($@) {
1282 $ex = $@;
1283 }
1284
1285 $wfh->print("done\n");
1286 $wfh->flush();
1287
1288 } else {
1289 eval { server_wait($setup->{config_file}, $rfh) };
1290 if ($@) {
1291 warn($@);
1292 exit 1;
1293 }
1294
1295 exit 0;
1296 }
1297
1298 # Stop server
1299 server_stop($setup->{pid_file});
1300 $self->assert_child_ok($pid);
1301
1302 test_cleanup($setup->{log_file}, $ex);
1303 }
1304
1305 sub mkd_sgid_umask_two_params_ok {
1306 my $self = shift;
1307 my $tmpdir = $self->{tmpdir};
1308 my $setup = test_setup($tmpdir, 'cmds');
1309
1310 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
1311 mkpath($sub_dir);
1312
1313 my $test_dir = File::Spec->rel2abs("$sub_dir/test.d");
1314
1315 if ($< == 0) {
1316 unless (chmod(0755, $sub_dir)) {
1317 die("Can't set perms on $sub_dir to 0755: $!");
1318 }
1319
1320 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
1321 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
1322 }
1323 }
1324
1325 # Make sure that our sub directory has the SGID bit set
1326 my $mode = 2755;
1327 unless (chmod($mode, $sub_dir)) {
1328 die("Can't set perms on $sub_dir: $!");
1329 }
1330
1331 my $config = {
1332 PidFile => $setup->{pid_file},
1333 ScoreboardFile => $setup->{scoreboard_file},
1334 SystemLog => $setup->{log_file},
1335
1336 AuthUserFile => $setup->{auth_user_file},
1337 AuthGroupFile => $setup->{auth_group_file},
1338 AuthOrder => 'mod_auth_file.c',
1339
1340 Umask => '022 077',
1341
1342 IfModules => {
1343 'mod_delay.c' => {
1344 DelayEngine => 'off',
1345 },
1346 },
1347 };
1348
1349 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1350 $config);
1351
1352 # Open pipes, for use between the parent and child processes. Specifically,
1353 # the child will indicate when it's done with its test by writing a message
1354 # to the parent.
1355 my ($rfh, $wfh);
1356 unless (pipe($rfh, $wfh)) {
1357 die("Can't open pipe: $!");
1358 }
1359
1360 my $ex;
1361
1362 # Fork child
1363 $self->handle_sigchld();
1364 defined(my $pid = fork()) or die("Can't fork: $!");
1365 if ($pid) {
1366 eval {
1367 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1368 $client->login($setup->{user}, $setup->{passwd});
1369
1370 my ($resp_code, $resp_msg) = $client->mkd($test_dir);
1371 $client->quit();
1372
1373 my $expected = 257;
1374 $self->assert($expected == $resp_code,
1375 test_msg("Expected response code $expected, got $resp_code"));
1376
1377 $expected = "\"$test_dir\" - Directory successfully created";
1378 $self->assert($expected eq $resp_msg,
1379 test_msg("Expected response message '$expected', got '$resp_msg'"));
1380
1381 $self->assert(-d $test_dir,
1382 test_msg("$test_dir directory does not exist as expected"));
1383
1384 my $perms = sprintf("%04o", ((stat($test_dir))[2] & 07777));
1385 $expected = '0700';
1386 if ($^O =~ /bsd/i) {
1387 # *BSD filesystems inherit their SGID bit from parent directories
1388 $expected = '2700';
1389 }
1390
1391 $self->assert($expected eq $perms,
1392 "Expected perms $expected, got $perms");
1393 };
1394 if ($@) {
1395 $ex = $@;
1396 }
1397
1398 $wfh->print("done\n");
1399 $wfh->flush();
1400
1401 } else {
1402 eval { server_wait($setup->{config_file}, $rfh) };
1403 if ($@) {
1404 warn($@);
1405 exit 1;
1406 }
1407
1408 exit 0;
1409 }
1410
1411 # Stop server
1412 server_stop($setup->{pid_file});
1413 $self->assert_child_ok($pid);
1414
1415 test_cleanup($setup->{log_file}, $ex);
1416 }
1417
1418 sub mkd_fails_enoent {
1419 my $self = shift;
1420 my $tmpdir = $self->{tmpdir};
1421 my $setup = test_setup($tmpdir, 'cmds');
1422
1423 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar");
1424
1425 my $config = {
1426 PidFile => $setup->{pid_file},
1427 ScoreboardFile => $setup->{scoreboard_file},
1428 SystemLog => $setup->{log_file},
1429
1430 AuthUserFile => $setup->{auth_user_file},
1431 AuthGroupFile => $setup->{auth_group_file},
1432 AuthOrder => 'mod_auth_file.c',
1433
1434 IfModules => {
1435 'mod_delay.c' => {
1436 DelayEngine => 'off',
1437 },
1438 },
1439 };
1440
1441 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1442 $config);
1443
1444 # Open pipes, for use between the parent and child processes. Specifically,
1445 # the child will indicate when it's done with its test by writing a message
1446 # to the parent.
1447 my ($rfh, $wfh);
1448 unless (pipe($rfh, $wfh)) {
1449 die("Can't open pipe: $!");
1450 }
1451
1452 my $ex;
1453
1454 # Fork child
1455 $self->handle_sigchld();
1456 defined(my $pid = fork()) or die("Can't fork: $!");
1457 if ($pid) {
1458 eval {
1459 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1460 $client->login($setup->{user}, $setup->{passwd});
1461
1462 eval { $client->mkd($sub_dir) };
1463 unless ($@) {
1464 die("MKD succeeded unexpectedly");
1465 }
1466
1467 my $resp_code = $client->response_code();
1468 my $resp_msg = $client->response_msg();
1469 $client->quit();
1470
1471 my $expected = 550;
1472 $self->assert($expected == $resp_code,
1473 test_msg("Expected response code $expected, got $resp_code"));
1474
1475 $expected = "$sub_dir: No such file or directory";
1476 $self->assert($expected eq $resp_msg,
1477 test_msg("Expected response message '$expected', got '$resp_msg'"));
1478
1479 $self->assert(!-d $sub_dir,
1480 test_msg("$sub_dir directory exists unexpectedly"));
1481 };
1482 if ($@) {
1483 $ex = $@;
1484 }
1485
1486 $wfh->print("done\n");
1487 $wfh->flush();
1488
1489 } else {
1490 eval { server_wait($setup->{config_file}, $rfh) };
1491 if ($@) {
1492 warn($@);
1493 exit 1;
1494 }
1495
1496 exit 0;
1497 }
1498
1499 # Stop server
1500 server_stop($setup->{pid_file});
1501 $self->assert_child_ok($pid);
1502
1503 test_cleanup($setup->{log_file}, $ex);
1504 }
1505
1506 sub mkd_fails_eperm {
1507 my $self = shift;
1508 my $tmpdir = $self->{tmpdir};
1509 my $setup = test_setup($tmpdir, 'cmds');
1510
1511 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1512
1513 my $config = {
1514 PidFile => $setup->{pid_file},
1515 ScoreboardFile => $setup->{scoreboard_file},
1516 SystemLog => $setup->{log_file},
1517
1518 AuthUserFile => $setup->{auth_user_file},
1519 AuthGroupFile => $setup->{auth_group_file},
1520 AuthOrder => 'mod_auth_file.c',
1521
1522 IfModules => {
1523 'mod_delay.c' => {
1524 DelayEngine => 'off',
1525 },
1526 },
1527 };
1528
1529 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1530 $config);
1531
1532 # Open pipes, for use between the parent and child processes. Specifically,
1533 # the child will indicate when it's done with its test by writing a message
1534 # to the parent.
1535 my ($rfh, $wfh);
1536 unless (pipe($rfh, $wfh)) {
1537 die("Can't open pipe: $!");
1538 }
1539
1540 my $ex;
1541
1542 # Fork child
1543 $self->handle_sigchld();
1544 defined(my $pid = fork()) or die("Can't fork: $!");
1545 if ($pid) {
1546 eval {
1547 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1548 $client->login($setup->{user}, $setup->{passwd});
1549
1550 # Make it such that perms on the parent dir do not allow writes
1551 my $perms = (stat($setup->{home_dir}))[2];
1552 unless (chmod(0550, $setup->{home_dir})) {
1553 die("Failed to change perms on $setup->{home_dir}: $!");
1554 }
1555
1556 eval { $client->mkd($sub_dir) };
1557 unless ($@) {
1558 die("MKD succeeded unexpectedly");
1559 }
1560
1561 my $resp_code = $client->response_code();
1562 my $resp_msg = $client->response_msg();
1563 $client->quit();
1564
1565 # Restore the perms
1566 chmod($perms, $setup->{home_dir});
1567
1568 my $expected = 550;
1569 $self->assert($expected == $resp_code,
1570 test_msg("Expected response code $expected, got $resp_code"));
1571
1572 $expected = "\/foo: (Operation not permitted|Permission denied)";
1573 $self->assert(qr/$expected/, $resp_msg,
1574 test_msg("Expected response message '$expected', got '$resp_msg'"));
1575
1576 $self->assert(!-d $sub_dir,
1577 test_msg("$sub_dir directory exists unexpectedly"));
1578 };
1579 if ($@) {
1580 $ex = $@;
1581 }
1582
1583 $wfh->print("done\n");
1584 $wfh->flush();
1585
1586 } else {
1587 eval { server_wait($setup->{config_file}, $rfh) };
1588 if ($@) {
1589 warn($@);
1590 exit 1;
1591 }
1592
1593 exit 0;
1594 }
1595
1596 # Stop server
1597 server_stop($setup->{pid_file});
1598 $self->assert_child_ok($pid);
1599
1600 test_cleanup($setup->{log_file}, $ex);
1601 }
1602
1603 sub mkd_fails_eexists {
1604 my $self = shift;
1605 my $tmpdir = $self->{tmpdir};
1606 my $setup = test_setup($tmpdir, 'cmds');
1607
1608 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1609 mkpath($sub_dir);
1610
1611 my $config = {
1612 PidFile => $setup->{pid_file},
1613 ScoreboardFile => $setup->{scoreboard_file},
1614 SystemLog => $setup->{log_file},
1615
1616 AuthUserFile => $setup->{auth_user_file},
1617 AuthGroupFile => $setup->{auth_group_file},
1618 AuthOrder => 'mod_auth_file.c',
1619
1620 IfModules => {
1621 'mod_delay.c' => {
1622 DelayEngine => 'off',
1623 },
1624 },
1625 };
1626
1627 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1628 $config);
1629
1630 # Open pipes, for use between the parent and child processes. Specifically,
1631 # the child will indicate when it's done with its test by writing a message
1632 # to the parent.
1633 my ($rfh, $wfh);
1634 unless (pipe($rfh, $wfh)) {
1635 die("Can't open pipe: $!");
1636 }
1637
1638 my $ex;
1639
1640 # Fork child
1641 $self->handle_sigchld();
1642 defined(my $pid = fork()) or die("Can't fork: $!");
1643 if ($pid) {
1644 eval {
1645 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1646 $client->login($setup->{user}, $setup->{passwd});
1647
1648 eval { $client->mkd($sub_dir) };
1649 unless ($@) {
1650 die("MKD succeeded unexpectedly");
1651 }
1652
1653 my $resp_code = $client->response_code();
1654 my $resp_msg = $client->response_msg();
1655 $client->quit();
1656
1657 my $expected = 550;
1658 $self->assert($expected == $resp_code,
1659 test_msg("Expected response code $expected, got $resp_code"));
1660
1661 $expected = "\/foo: File exists";
1662 $self->assert(qr/$expected/, $resp_msg,
1663 test_msg("Expected response message '$expected', got '$resp_msg'"));
1664 };
1665 if ($@) {
1666 $ex = $@;
1667 }
1668
1669 $wfh->print("done\n");
1670 $wfh->flush();
1671
1672 } else {
1673 eval { server_wait($setup->{config_file}, $rfh) };
1674 if ($@) {
1675 warn($@);
1676 exit 1;
1677 }
1678
1679 exit 0;
1680 }
1681
1682 # Stop server
1683 server_stop($setup->{pid_file});
1684 $self->assert_child_ok($pid);
1685
1686 test_cleanup($setup->{log_file}, $ex);
1687 }
1688
1689 sub xmkd_ok {
1690 my $self = shift;
1691 my $tmpdir = $self->{tmpdir};
1692 my $setup = test_setup($tmpdir, 'cmds');
1693
1694 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1695
1696 my $config = {
1697 PidFile => $setup->{pid_file},
1698 ScoreboardFile => $setup->{scoreboard_file},
1699 SystemLog => $setup->{log_file},
1700
1701 AuthUserFile => $setup->{auth_user_file},
1702 AuthGroupFile => $setup->{auth_group_file},
1703 AuthOrder => 'mod_auth_file.c',
1704
1705 IfModules => {
1706 'mod_delay.c' => {
1707 DelayEngine => 'off',
1708 },
1709 },
1710 };
1711
1712 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1713 $config);
1714
1715 # Open pipes, for use between the parent and child processes. Specifically,
1716 # the child will indicate when it's done with its test by writing a message
1717 # to the parent.
1718 my ($rfh, $wfh);
1719 unless (pipe($rfh, $wfh)) {
1720 die("Can't open pipe: $!");
1721 }
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, 0, 1);
1731 $client->login($setup->{user}, $setup->{passwd});
1732
1733 my ($resp_code, $resp_msg) = $client->xmkd($sub_dir);;
1734 $client->quit();
1735
1736 my $expected = 257;
1737 $self->assert($expected == $resp_code,
1738 test_msg("Expected response code $expected, got $resp_code"));
1739
1740 $expected = "\"$sub_dir\" - Directory successfully created";
1741 $self->assert($expected eq $resp_msg,
1742 test_msg("Expected response message '$expected', got '$resp_msg'"));
1743
1744 $self->assert(-d $sub_dir,
1745 test_msg("$sub_dir directory does not exist as expected"));
1746 };
1747 if ($@) {
1748 $ex = $@;
1749 }
1750
1751 $wfh->print("done\n");
1752 $wfh->flush();
1753
1754 } else {
1755 eval { server_wait($setup->{config_file}, $rfh) };
1756 if ($@) {
1757 warn($@);
1758 exit 1;
1759 }
1760
1761 exit 0;
1762 }
1763
1764 # Stop server
1765 server_stop($setup->{pid_file});
1766 $self->assert_child_ok($pid);
1767
1768 test_cleanup($setup->{log_file}, $ex);
1769 }
1770
1771 sub mkd_digits_ok {
1772 my $self = shift;
1773 my $tmpdir = $self->{tmpdir};
1774 my $setup = test_setup($tmpdir, 'cmds');
1775
1776 my $sub_dir = File::Spec->rel2abs("$tmpdir/001");
1777
1778 my $config = {
1779 PidFile => $setup->{pid_file},
1780 ScoreboardFile => $setup->{scoreboard_file},
1781 SystemLog => $setup->{log_file},
1782
1783 AuthUserFile => $setup->{auth_user_file},
1784 AuthGroupFile => $setup->{auth_group_file},
1785 AuthOrder => 'mod_auth_file.c',
1786
1787 IfModules => {
1788 'mod_delay.c' => {
1789 DelayEngine => 'off',
1790 },
1791 },
1792 };
1793
1794 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1795 $config);
1796
1797 # Open pipes, for use between the parent and child processes. Specifically,
1798 # the child will indicate when it's done with its test by writing a message
1799 # to the parent.
1800 my ($rfh, $wfh);
1801 unless (pipe($rfh, $wfh)) {
1802 die("Can't open pipe: $!");
1803 }
1804
1805 my $ex;
1806
1807 # Fork child
1808 $self->handle_sigchld();
1809 defined(my $pid = fork()) or die("Can't fork: $!");
1810 if ($pid) {
1811 eval {
1812 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1813 $client->login($setup->{user}, $setup->{passwd});
1814
1815 my $dir = "001";
1816
1817 my ($resp_code, $resp_msg) = $client->mkd($dir);
1818 $client->quit();
1819
1820 my $expected = 257;
1821 $self->assert($expected == $resp_code,
1822 test_msg("Expected response code $expected, got $resp_code"));
1823
1824 if ($^O eq 'darwin') {
1825 # MacOSX hack
1826 $sub_dir = '/private' . $sub_dir;
1827 }
1828
1829 $expected = "\"$sub_dir\" - Directory successfully created";
1830 $self->assert($expected eq $resp_msg,
1831 test_msg("Expected response message '$expected', got '$resp_msg'"));
1832
1833 $self->assert(-d $sub_dir,
1834 test_msg("$sub_dir directory does not exist as expected"));
1835 };
1836 if ($@) {
1837 $ex = $@;
1838 }
1839
1840 $wfh->print("done\n");
1841 $wfh->flush();
1842
1843 } else {
1844 eval { server_wait($setup->{config_file}, $rfh) };
1845 if ($@) {
1846 warn($@);
1847 exit 1;
1848 }
1849
1850 exit 0;
1851 }
1852
1853 # Stop server
1854 server_stop($setup->{pid_file});
1855 $self->assert_child_ok($pid);
1856
1857 test_cleanup($setup->{log_file}, $ex);
1858 }
1859
1860 sub mkd_embedded_cr_bug4167 {
1861 my $self = shift;
1862 my $tmpdir = $self->{tmpdir};
1863 my $setup = test_setup($tmpdir, 'cmds');
1864
1865 my $sub_dir = File::Spec->rel2abs("$tmpdir/ab\015cd");
1866
1867 my $config = {
1868 PidFile => $setup->{pid_file},
1869 ScoreboardFile => $setup->{scoreboard_file},
1870 SystemLog => $setup->{log_file},
1871
1872 AuthUserFile => $setup->{auth_user_file},
1873 AuthGroupFile => $setup->{auth_group_file},
1874 AuthOrder => 'mod_auth_file.c',
1875
1876 IfModules => {
1877 'mod_delay.c' => {
1878 DelayEngine => 'off',
1879 },
1880 },
1881 };
1882
1883 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1884 $config);
1885
1886 # Open pipes, for use between the parent and child processes. Specifically,
1887 # the child will indicate when it's done with its test by writing a message
1888 # to the parent.
1889 my ($rfh, $wfh);
1890 unless (pipe($rfh, $wfh)) {
1891 die("Can't open pipe: $!");
1892 }
1893
1894 my $ex;
1895
1896 # Fork child
1897 $self->handle_sigchld();
1898 defined(my $pid = fork()) or die("Can't fork: $!");
1899 if ($pid) {
1900 eval {
1901 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1902 $client->login($setup->{user}, $setup->{passwd});
1903
1904 my $dir = "ab\015\00cd";
1905
1906 my ($resp_code, $resp_msg) = $client->mkd($dir);
1907 $client->quit();
1908
1909 my $expected = 257;
1910 $self->assert($expected == $resp_code,
1911 test_msg("Expected response code $expected, got $resp_code"));
1912
1913 if ($^O eq 'darwin') {
1914 # MacOSX hack
1915 $sub_dir = '/private' . $sub_dir;
1916 }
1917
1918 $expected = "\"$sub_dir\" - Directory successfully created";
1919 $self->assert($expected eq $resp_msg,
1920 test_msg("Expected response message '$expected', got '$resp_msg'"));
1921
1922 $self->assert(-d $sub_dir,
1923 test_msg("$sub_dir directory does not exist as expected"));
1924 };
1925 if ($@) {
1926 $ex = $@;
1927 }
1928
1929 $wfh->print("done\n");
1930 $wfh->flush();
1931
1932 } else {
1933 eval { server_wait($setup->{config_file}, $rfh) };
1934 if ($@) {
1935 warn($@);
1936 exit 1;
1937 }
1938
1939 exit 0;
1940 }
1941
1942 # Stop server
1943 server_stop($setup->{pid_file});
1944 $self->assert_child_ok($pid);
1945
1946 test_cleanup($setup->{log_file}, $ex);
1947 }
1948
1949 sub mkd_embedded_lf_bug4167 {
1950 my $self = shift;
1951 my $tmpdir = $self->{tmpdir};
1952 my $setup = test_setup($tmpdir, 'cmds');
1953
1954 my $sub_dir = File::Spec->rel2abs("$tmpdir/ab\012cd");
1955
1956 my $config = {
1957 PidFile => $setup->{pid_file},
1958 ScoreboardFile => $setup->{scoreboard_file},
1959 SystemLog => $setup->{log_file},
1960 TraceLog => $setup->{log_file},
1961 Trace => 'DEFAULT:20',
1962
1963 AuthUserFile => $setup->{auth_user_file},
1964 AuthGroupFile => $setup->{auth_group_file},
1965 AuthOrder => 'mod_auth_file.c',
1966
1967 IfModules => {
1968 'mod_delay.c' => {
1969 DelayEngine => 'off',
1970 },
1971 },
1972 };
1973
1974 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1975 $config);
1976
1977 # Open pipes, for use between the parent and child processes. Specifically,
1978 # the child will indicate when it's done with its test by writing a message
1979 # to the parent.
1980 my ($rfh, $wfh);
1981 unless (pipe($rfh, $wfh)) {
1982 die("Can't open pipe: $!");
1983 }
1984
1985 my $ex;
1986
1987 # Fork child
1988 $self->handle_sigchld();
1989 defined(my $pid = fork()) or die("Can't fork: $!");
1990 if ($pid) {
1991 eval {
1992 # Note: the Net::Cmd module's command() method automatically translates
1993 # all LF to spaces! Crap! That is why we can't Net::FTP (it's based on
1994 # Net::Cmd), and instead have to do the socket IO manually. Sigh.
1995
1996 sleep(2);
1997
1998 my $client = IO::Socket::INET->new(
1999 PeerAddr => '127.0.0.1',
2000 PeerPort => $port,
2001 Proto => 'tcp',
2002 Timeout => 5
2003 );
2004 unless ($client) {
2005 die("Can't connect to 127.0.0.1:$port: $!");
2006 }
2007
2008 # Read the banner
2009 my $banner = <$client>;
2010
2011 # Send the USER command
2012 my $cmd = "USER $setup->{user}\r\n";
2013 if ($ENV{TEST_VERBOSE}) {
2014 print STDERR "# Sending: $cmd";
2015 }
2016 $client->print($cmd);
2017 $client->flush();
2018
2019 # Read USER response
2020 my $resp = <$client>;
2021 if ($ENV{TEST_VERBOSE}) {
2022 print STDERR "# Received: $resp";
2023 }
2024
2025 my $expected = "331 Password required for $setup->{user}\r\n";
2026 $self->assert($expected eq $resp,
2027 test_msg("Expected response '$expected', got '$resp'"));
2028
2029 # Send the PASS command
2030 $cmd = "PASS $setup->{passwd}\r\n";
2031 if ($ENV{TEST_VERBOSE}) {
2032 print STDERR "# Sending: $cmd";
2033 }
2034 $client->print($cmd);
2035 $client->flush();
2036
2037 # Read PASS response
2038 $resp = <$client>;
2039 if ($ENV{TEST_VERBOSE}) {
2040 print STDERR "# Received: $resp";
2041 }
2042
2043 $expected = "230 User $setup->{user} logged in\r\n";
2044 $self->assert($expected eq $resp,
2045 test_msg("Expected response '$expected', got '$resp'"));
2046
2047 my $dir = "ab\012cd";
2048
2049 # Send the MKD command
2050 $cmd = "MKD $dir\r\n";
2051 if ($ENV{TEST_VERBOSE}) {
2052 print STDERR "# Sending: $cmd";
2053 }
2054
2055 $client->print($cmd);
2056 $client->flush();
2057
2058 # Read MKD response. Note that perl's <> operator reads until
2059 # end of line -- and that means just LF, not necessarily CRLF. Thus
2060 # we deliberate do TWO reads here to get the entire response.
2061 $resp = <$client>;
2062 $resp .= <$client>;
2063
2064 if ($ENV{TEST_VERBOSE}) {
2065 print STDERR "# Received: $resp";
2066 }
2067
2068 if ($^O eq 'darwin') {
2069 # MacOSX hack
2070 $sub_dir = '/private' . $sub_dir;
2071 }
2072
2073 $expected = "257 \"$sub_dir\" - Directory successfully created\r\n";
2074 $self->assert($expected eq $resp,
2075 test_msg("Expected response '$expected', got '$resp'"));
2076
2077 $cmd = "QUIT\r\n";
2078 if ($ENV{TEST_VERBOSE}) {
2079 print STDERR "# Sending: $cmd";
2080 }
2081
2082 $client->print($cmd);
2083 $client->flush();
2084
2085 $resp = <$client>;
2086 if ($ENV{TEST_VERBOSE}) {
2087 print STDERR "# Received: $resp";
2088 }
2089
2090 $client->close();
2091
2092 $self->assert(-d $sub_dir,
2093 test_msg("$sub_dir directory does not exist as expected"));
2094 };
2095 if ($@) {
2096 $ex = $@;
2097 }
2098
2099 $wfh->print("done\n");
2100 $wfh->flush();
2101
2102 } else {
2103 eval { server_wait($setup->{config_file}, $rfh) };
2104 if ($@) {
2105 warn($@);
2106 exit 1;
2107 }
2108
2109 exit 0;
2110 }
2111
2112 # Stop server
2113 server_stop($setup->{pid_file});
2114 $self->assert_child_ok($pid);
2115
2116 test_cleanup($setup->{log_file}, $ex);
2117 }
2118
2119 sub mkd_already_exists_issue1639 {
2120 my $self = shift;
2121 my $tmpdir = $self->{tmpdir};
2122 my $setup = test_setup($tmpdir, 'cmds');
2123
2124 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
2125
2126 my $config = {
2127 PidFile => $setup->{pid_file},
2128 ScoreboardFile => $setup->{scoreboard_file},
2129 SystemLog => $setup->{log_file},
2130
2131 AuthUserFile => $setup->{auth_user_file},
2132 AuthGroupFile => $setup->{auth_group_file},
2133 AuthOrder => 'mod_auth_file.c',
2134
2135 IfModules => {
2136 'mod_delay.c' => {
2137 DelayEngine => 'off',
2138 },
2139 },
2140 };
2141
2142 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2143 $config);
2144
2145 # Open pipes, for use between the parent and child processes. Specifically,
2146 # the child will indicate when it's done with its test by writing a message
2147 # to the parent.
2148 my ($rfh, $wfh);
2149 unless (pipe($rfh, $wfh)) {
2150 die("Can't open pipe: $!");
2151 }
2152
2153 my $ex;
2154
2155 # Fork child
2156 $self->handle_sigchld();
2157 defined(my $pid = fork()) or die("Can't fork: $!");
2158 if ($pid) {
2159 eval {
2160 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2161 $client->login($setup->{user}, $setup->{passwd});
2162
2163 my ($resp_code, $resp_msg) = $client->mkd($sub_dir);
2164
2165 my $expected = 257;
2166 $self->assert($expected == $resp_code,
2167 test_msg("Expected response code $expected, got $resp_code"));
2168
2169 $expected = "\"$sub_dir\" - Directory successfully created";
2170 $self->assert($expected eq $resp_msg,
2171 test_msg("Expected response message '$expected', got '$resp_msg'"));
2172
2173 # Now send the same command again, even though the directory should
2174 # already exist. Ideally we do not fail with an EEXIST error
2175 # (Issue #1639).
2176
2177 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
2178
2179 $expected = 257;
2180 $self->assert($expected == $resp_code,
2181 test_msg("Expected response code $expected, got $resp_code"));
2182
2183 $expected = "\"$sub_dir\" - Directory successfully created";
2184 $self->assert($expected eq $resp_msg,
2185 test_msg("Expected response message '$expected', got '$resp_msg'"));
2186
2187 $client->quit();
2188 $self->assert(-d $sub_dir,
2189 test_msg("$sub_dir directory does not exist as expected"));
2190
2191 my $perms = ((stat($sub_dir))[2] & 07777);
2192 $expected = 0755;
2193 $self->assert($expected == $perms,
2194 test_msg("Expected perms $expected, got $perms"));
2195 };
2196 if ($@) {
2197 $ex = $@;
2198 }
2199
2200 $wfh->print("done\n");
2201 $wfh->flush();
2202
2203 } else {
2204 eval { server_wait($setup->{config_file}, $rfh) };
2205 if ($@) {
2206 warn($@);
2207 exit 1;
2208 }
2209
2210 exit 0;
2211 }
2212
2213 # Stop server
2214 server_stop($setup->{pid_file});
2215 $self->assert_child_ok($pid);
2216
2217 test_cleanup($setup->{log_file}, $ex);
2218 }
2219
2220 1;