Debian Codegraph @

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

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