Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_rewrite.pm

raw
1 package ProFTPD::Tests::Modules::mod_rewrite;
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 use POSIX qw(:fcntl_h);
11 use URI::Escape;
12
13 use ProFTPD::TestSuite::FTP;
14 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
15
16 $| = 1;
17
18 my $order = 0;
19
20 my $TESTS = {
21 rewrite_map_lowercase => {
22 order => ++$order,
23 test_class => [qw(forking)],
24 },
25
26 rewrite_map_spaces_underscores => {
27 order => ++$order,
28 test_class => [qw(forking)],
29 },
30
31 rewrite_map_whitespace_underscores => {
32 order => ++$order,
33 test_class => [qw(forking)],
34 },
35
36 rewrite_map_whitespace_trim => {
37 order => ++$order,
38 test_class => [qw(forking)],
39 },
40
41 rewrite_rule_append_pid => {
42 order => ++$order,
43 test_class => [qw(forking)],
44 },
45
46 rewrite_bug2915 => {
47 order => ++$order,
48 test_class => [qw(bug forking)],
49 },
50
51 rewrite_bug3027 => {
52 order => ++$order,
53 test_class => [qw(bug forking)],
54 },
55
56 rewrite_bug3034 => {
57 order => ++$order,
58 test_class => [qw(bug forking)],
59 },
60
61 rewrite_bug3169 => {
62 order => ++$order,
63 test_class => [qw(bug forking)],
64 },
65
66 rewrite_map_unescape_bug3170 => {
67 order => ++$order,
68 test_class => [qw(bug forking)],
69 },
70
71 rewrite_map_unescape_bad_paths_issue2173 => {
72 order => ++$order,
73 test_class => [qw(bug forking)],
74 },
75
76 rewrite_cond_env_var_failed => {
77 order => ++$order,
78 test_class => [qw(forking)],
79 },
80
81 rewrite_cond_env_var_ok => {
82 order => ++$order,
83 test_class => [qw(forking)],
84 },
85
86 rewrite_rule_env_var_failed => {
87 order => ++$order,
88 test_class => [qw(forking)],
89 },
90
91 rewrite_rule_env_var_ok => {
92 order => ++$order,
93 test_class => [qw(forking)],
94 },
95
96 rewrite_escape_rule_backref_bug3028 => {
97 order => ++$order,
98 test_class => [qw(bug forking)],
99 },
100
101 rewrite_escape_cond_backref_bug3028 => {
102 order => ++$order,
103 test_class => [qw(bug forking)],
104 },
105
106 rewrite_cond_rename_var_bug3029 => {
107 order => ++$order,
108 test_class => [qw(bug forking)],
109 },
110
111 rewrite_cond_or_flags_bug3269 => {
112 order => ++$order,
113 test_class => [qw(bug forking)],
114 },
115
116 rewrite_cond_nc_flags => {
117 order => ++$order,
118 test_class => [qw(forking)],
119 },
120
121 rewrite_map_fifo_bug3611 => {
122 order => ++$order,
123 test_class => [qw(bug forking)],
124 },
125
126 rewrite_rule_replaceall_backslash_with_slash => {
127 order => ++$order,
128 test_class => [qw(forking)],
129 },
130
131 rewrite_map_max_replace_bug3721 => {
132 order => ++$order,
133 test_class => [qw(bug forking)],
134 },
135
136 rewrite_cond_time_var_bug3673 => {
137 order => ++$order,
138 test_class => [qw(forking)],
139 },
140
141 rewrite_cond_time_year_var_bug3673 => {
142 order => ++$order,
143 test_class => [qw(forking)],
144 },
145
146 rewrite_cond_time_mon_var_bug3673 => {
147 order => ++$order,
148 test_class => [qw(forking)],
149 },
150
151 rewrite_cond_time_day_var_bug3673 => {
152 order => ++$order,
153 test_class => [qw(forking)],
154 },
155
156 rewrite_cond_time_wday_var_bug3673 => {
157 order => ++$order,
158 test_class => [qw(forking)],
159 },
160
161 rewrite_cond_time_hour_var_bug3673 => {
162 order => ++$order,
163 test_class => [qw(forking)],
164 },
165
166 rewrite_cond_time_min_var_bug3673 => {
167 order => ++$order,
168 test_class => [qw(forking)],
169 },
170
171 rewrite_cond_time_sec_var_bug3673 => {
172 order => ++$order,
173 test_class => [qw(forking)],
174 },
175
176 rewrite_rule_time_year_var_bug3673 => {
177 order => ++$order,
178 test_class => [qw(forking)],
179 },
180
181 rewrite_rule_time_mon_var_bug3673 => {
182 order => ++$order,
183 test_class => [qw(forking)],
184 },
185
186 rewrite_rule_time_day_var_bug3673 => {
187 order => ++$order,
188 test_class => [qw(forking)],
189 },
190
191 rewrite_rule_time_wday_var_bug3673 => {
192 order => ++$order,
193 test_class => [qw(forking)],
194 },
195
196 rewrite_rule_time_hour_var_bug3673 => {
197 order => ++$order,
198 test_class => [qw(forking)],
199 },
200
201 rewrite_rule_time_min_var_bug3673 => {
202 order => ++$order,
203 test_class => [qw(forking)],
204 },
205
206 rewrite_bug3767 => {
207 order => ++$order,
208 test_class => [qw(bug forking)],
209 },
210
211 rewrite_bug4017 => {
212 order => ++$order,
213 test_class => [qw(bug forking rootprivs)],
214 },
215
216 rewrite_using_pcre_bug4017 => {
217 order => ++$order,
218 test_class => [qw(bug feature_pcre forking rootprivs)],
219 },
220
221 rewrite_using_pcre_issue1300 => {
222 order => ++$order,
223 test_class => [qw(bug feature_pcre forking)],
224 },
225
226 rewrite_rule_missing_condition_bug4495 => {
227 order => ++$order,
228 test_class => [qw(bug feature_pcre forking)],
229 },
230
231 rewrite_rule_with_matchall_condition_bug4495 => {
232 order => ++$order,
233 test_class => [qw(bug feature_pcre forking)],
234 },
235
236 # TODO: Need test for RewriteMap using text file
237 };
238
239 sub new {
240 return shift()->SUPER::new(@_);
241 }
242
243 sub list_tests {
244 my @tests = testsuite_get_runnable_tests($TESTS);
245
246 eval "use DateTime";
247 if ($@) {
248 # If the DateTime module is not present, disable time-related tests
249
250 my $timevar_tests = {
251 rewrite_cond_time_var_bug3673 => 1,
252 rewrite_cond_time_year_var_bug3673 => 1,
253 rewrite_cond_time_mon_var_bug3673 => 1,
254 rewrite_cond_time_day_var_bug3673 => 1,
255 rewrite_cond_time_wday_var_bug3673 => 1,
256 rewrite_cond_time_hour_var_bug3673 => 1,
257 rewrite_cond_time_min_var_bug3673 => 1,
258 rewrite_cond_time_sec_var_bug3673 => 1,
259 rewrite_rule_time_year_var_bug3673 => 1,
260 rewrite_rule_time_mon_var_bug3673 => 1,
261 rewrite_rule_time_day_var_bug3673 => 1,
262 rewrite_rule_time_wday_var_bug3673 => 1,
263 rewrite_rule_time_hour_var_bug3673 => 1,
264 rewrite_rule_time_min_var_bug3673 => 1,
265 };
266
267 # We use arrays, not hashes, here in order to preserve test order
268 foreach my $key (keys(%$timevar_tests)) {
269 my $ntests = scalar(@tests);
270
271 for (my $i = 0; $i < $ntests; $i++) {
272 if ($tests[$i] eq $key) {
273 splice(@tests, $i, 1);
274 last;
275 }
276 }
277 }
278 }
279
280 return @tests;
281 }
282
283 sub rewrite_map_lowercase {
284 my $self = shift;
285 my $tmpdir = $self->{tmpdir};
286
287 my $config_file = "$tmpdir/rewrite.conf";
288 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
289 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
290
291 my $log_file = test_get_logfile();
292
293 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
294 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
295
296 my $user = 'proftpd';
297 my $passwd = 'test';
298 my $group = 'ftpd';
299 my $home_dir = File::Spec->rel2abs($tmpdir);
300 my $uid = 500;
301 my $gid = 500;
302
303 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
304 mkpath($sub_dir);
305
306 my $test_file = 'test.txt';
307 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
308
309 if (open(my $fh, "> $test_path")) {
310 print $fh "Hello, World!\n";
311
312 unless (close($fh)) {
313 die("Can't write $test_path: $!");
314 }
315
316 } else {
317 die("Can't open $test_path: $!");
318 }
319
320 # Make sure that, if we're running as root, that the home directory has
321 # permissions/privs set for the account we create
322 if ($< == 0) {
323 unless (chmod(0755, $home_dir, $sub_dir)) {
324 die("Can't set perms on $home_dir to 0755: $!");
325 }
326
327 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
328 die("Can't set owner of $home_dir to $uid/$gid: $!");
329 }
330 }
331
332 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
333 '/bin/bash');
334 auth_group_write($auth_group_file, $group, $gid, $user);
335
336 my $config = {
337 PidFile => $pid_file,
338 ScoreboardFile => $scoreboard_file,
339 SystemLog => $log_file,
340
341 AuthUserFile => $auth_user_file,
342 AuthGroupFile => $auth_group_file,
343 AuthOrder => 'mod_auth_file.c',
344
345 IfModules => {
346 'mod_delay.c' => {
347 DelayEngine => 'off',
348 },
349
350 'mod_rewrite.c' => [
351 'RewriteEngine on',
352 "RewriteLog $log_file",
353
354 'RewriteCondition %m !PASS',
355 'RewriteMap lowercase int:tolower',
356 'RewriteRule ^(.*) ${lowercase:$1}',
357 ],
358 },
359 };
360
361 my ($port, $config_user, $config_group) = config_write($config_file, $config);
362
363 # Open pipes, for use between the parent and child processes. Specifically,
364 # the child will indicate when it's done with its test by writing a message
365 # to the parent.
366 my ($rfh, $wfh);
367 unless (pipe($rfh, $wfh)) {
368 die("Can't open pipe: $!");
369 }
370
371 my $ex;
372
373 # Fork child
374 $self->handle_sigchld();
375 defined(my $pid = fork()) or die("Can't fork: $!");
376 if ($pid) {
377 eval {
378 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
379
380 my ($resp_code, $resp_msg);
381
382 $client->login($user, $passwd);
383 $client->type('binary');
384
385 # Send the path all in uppercase; the rewrite rules should lowercase
386 # everything.
387 ($resp_code, $resp_msg) = $client->size(uc("tmp/$test_file"));
388
389 my $expected;
390
391 $expected = 213;
392 $self->assert($expected == $resp_code,
393 test_msg("Expected $expected, got $resp_code"));
394
395 $expected = '14';
396 $self->assert($expected eq $resp_msg,
397 test_msg("Expected '$expected', got '$resp_msg'"));
398 };
399
400 if ($@) {
401 $ex = $@;
402 }
403
404 $wfh->print("done\n");
405 $wfh->flush();
406
407 } else {
408 eval { server_wait($config_file, $rfh) };
409 if ($@) {
410 warn($@);
411 exit 1;
412 }
413
414 exit 0;
415 }
416
417 # Stop server
418 server_stop($pid_file);
419
420 $self->assert_child_ok($pid);
421
422 if ($ex) {
423 test_append_logfile($log_file, $ex);
424 unlink($log_file);
425
426 die($ex);
427 }
428
429 unlink($log_file);
430 }
431
432 sub rewrite_map_spaces_underscores {
433 my $self = shift;
434 my $tmpdir = $self->{tmpdir};
435
436 my $config_file = "$tmpdir/rewrite.conf";
437 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
438 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
439
440 my $log_file = test_get_logfile();
441
442 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
443 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
444
445 my $user = 'proftpd';
446 my $passwd = 'test';
447 my $group = 'ftpd';
448 my $home_dir = File::Spec->rel2abs($tmpdir);
449 my $uid = 500;
450 my $gid = 500;
451
452 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
453 mkpath($sub_dir);
454
455 my $cmd_file = 'test file here.txt';
456
457 my $test_file = 'test_file_here.txt';
458 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
459
460 if (open(my $fh, "> $test_path")) {
461 print $fh "Hello, World!\n";
462
463 unless (close($fh)) {
464 die("Can't write $test_path: $!");
465 }
466
467 } else {
468 die("Can't open $test_path: $!");
469 }
470
471 # Make sure that, if we're running as root, that the home directory has
472 # permissions/privs set for the account we create
473 if ($< == 0) {
474 unless (chmod(0755, $home_dir, $sub_dir)) {
475 die("Can't set perms on $home_dir to 0755: $!");
476 }
477
478 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
479 die("Can't set owner of $home_dir to $uid/$gid: $!");
480 }
481 }
482
483 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
484 '/bin/bash');
485 auth_group_write($auth_group_file, $group, $gid, $user);
486
487 my $config = {
488 PidFile => $pid_file,
489 ScoreboardFile => $scoreboard_file,
490 SystemLog => $log_file,
491
492 AuthUserFile => $auth_user_file,
493 AuthGroupFile => $auth_group_file,
494 AuthOrder => 'mod_auth_file.c',
495
496 IfModules => {
497 'mod_delay.c' => {
498 DelayEngine => 'off',
499 },
500
501 'mod_rewrite.c' => [
502 'RewriteEngine on',
503 "RewriteLog $log_file",
504
505 'RewriteMap replace int:replaceall',
506 'RewriteCondition %m SIZE',
507 'RewriteRule ^(.*) "${replace:!$1! !_}"',
508 ],
509 },
510 };
511
512 my ($port, $config_user, $config_group) = config_write($config_file, $config);
513
514 # Open pipes, for use between the parent and child processes. Specifically,
515 # the child will indicate when it's done with its test by writing a message
516 # to the parent.
517 my ($rfh, $wfh);
518 unless (pipe($rfh, $wfh)) {
519 die("Can't open pipe: $!");
520 }
521
522 my $ex;
523
524 # Fork child
525 $self->handle_sigchld();
526 defined(my $pid = fork()) or die("Can't fork: $!");
527 if ($pid) {
528 eval {
529 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
530
531 my ($resp_code, $resp_msg);
532
533 $client->login($user, $passwd);
534 $client->type('binary');
535
536 # Send the path with spaces; the rewrite rules should handle it
537 ($resp_code, $resp_msg) = $client->size("tmp/$cmd_file");
538
539 my $expected;
540
541 $expected = 213;
542 $self->assert($expected == $resp_code,
543 test_msg("Expected $expected, got $resp_code"));
544
545 $expected = '14';
546 $self->assert($expected eq $resp_msg,
547 test_msg("Expected '$expected', got '$resp_msg'"));
548 };
549
550 if ($@) {
551 $ex = $@;
552 }
553
554 $wfh->print("done\n");
555 $wfh->flush();
556
557 } else {
558 eval { server_wait($config_file, $rfh) };
559 if ($@) {
560 warn($@);
561 exit 1;
562 }
563
564 exit 0;
565 }
566
567 # Stop server
568 server_stop($pid_file);
569
570 $self->assert_child_ok($pid);
571
572 if ($ex) {
573 test_append_logfile($log_file, $ex);
574 unlink($log_file);
575
576 die($ex);
577 }
578
579 unlink($log_file);
580 }
581
582 sub rewrite_map_whitespace_underscores {
583 my $self = shift;
584 my $tmpdir = $self->{tmpdir};
585 my $setup = test_setup($tmpdir, 'rewrite');
586
587 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
588 mkpath($sub_dir);
589
590 my $test_file = 'test__file__here.txt';
591 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
592
593 if (open(my $fh, "> $test_path")) {
594 print $fh "Hello, World!\n";
595
596 unless (close($fh)) {
597 die("Can't write $test_path: $!");
598 }
599
600 } else {
601 die("Can't open $test_path: $!");
602 }
603
604 # Make sure that, if we're running as root, that the home directory has
605 # permissions/privs set for the account we create
606 if ($< == 0) {
607 unless (chmod(0755, $sub_dir)) {
608 die("Can't set perms on $sub_dir to 0755: $!");
609 }
610
611 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
612 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
613 }
614 }
615
616 my $config = {
617 PidFile => $setup->{pid_file},
618 ScoreboardFile => $setup->{scoreboard_file},
619 SystemLog => $setup->{log_file},
620
621 AuthUserFile => $setup->{auth_user_file},
622 AuthGroupFile => $setup->{auth_group_file},
623 AuthOrder => 'mod_auth_file.c',
624
625 IfModules => {
626 'mod_delay.c' => {
627 DelayEngine => 'off',
628 },
629
630 'mod_rewrite.c' => [
631 'RewriteEngine on',
632 "RewriteLog $setup->{log_file}",
633
634 'RewriteMap replace int:replaceall',
635 'RewriteCondition %m SIZE',
636 'RewriteRule ^(.*) "${replace:!$1! !_}"',
637
638 # Need a separate rule for matching tabs; the internal replaceall
639 # map doesn't understand regex classes like "[:space:]".
640 'RewriteCondition %m SIZE',
641 'RewriteRule ^(.*) "${replace:!$1! !_}"',
642 ],
643 },
644 };
645
646 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
647 $config);
648
649 # Open pipes, for use between the parent and child processes. Specifically,
650 # the child will indicate when it's done with its test by writing a message
651 # to the parent.
652 my ($rfh, $wfh);
653 unless (pipe($rfh, $wfh)) {
654 die("Can't open pipe: $!");
655 }
656
657 my $ex;
658
659 # Fork child
660 $self->handle_sigchld();
661 defined(my $pid = fork()) or die("Can't fork: $!");
662 if ($pid) {
663 eval {
664 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
665 my ($resp_code, $resp_msg);
666
667 $client->login($setup->{user}, $setup->{passwd});
668 $client->type('binary');
669
670 # Send the path with spaces; the rewrite rules should handle it
671 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
672
673 my $expected = 213;
674 $self->assert($expected == $resp_code,
675 test_msg("Expected response code $expected, got $resp_code"));
676
677 $expected = '14';
678 $self->assert($expected eq $resp_msg,
679 test_msg("Expected response message '$expected', got '$resp_msg'"));
680 };
681 if ($@) {
682 $ex = $@;
683 }
684
685 $wfh->print("done\n");
686 $wfh->flush();
687
688 } else {
689 eval { server_wait($setup->{config_file}, $rfh) };
690 if ($@) {
691 warn($@);
692 exit 1;
693 }
694
695 exit 0;
696 }
697
698 # Stop server
699 server_stop($setup->{pid_file});
700 $self->assert_child_ok($pid);
701
702 test_cleanup($setup->{log_file}, $ex);
703 }
704
705 sub rewrite_map_whitespace_trim {
706 my $self = shift;
707 my $tmpdir = $self->{tmpdir};
708 my $setup = test_setup($tmpdir, 'rewrite');
709
710 my $test_file = 'test.txt';
711 my $test_path = File::Spec->rel2abs("$tmpdir/$test_file");
712
713 if (open(my $fh, "> $test_path")) {
714 print $fh "Hello, World!\n";
715
716 unless (close($fh)) {
717 die("Can't write $test_path: $!");
718 }
719
720 } else {
721 die("Can't open $test_path: $!");
722 }
723
724 my $config = {
725 PidFile => $setup->{pid_file},
726 ScoreboardFile => $setup->{scoreboard_file},
727 SystemLog => $setup->{log_file},
728 TraceLog => $setup->{log_file},
729 Trace => 'regexp:20 rewrite:20',
730
731 AuthUserFile => $setup->{auth_user_file},
732 AuthGroupFile => $setup->{auth_group_file},
733 AuthOrder => 'mod_auth_file.c',
734
735 IfModules => {
736 'mod_delay.c' => {
737 DelayEngine => 'off',
738 },
739
740 'mod_rewrite.c' => [
741 'RewriteEngine on',
742 "RewriteLog $setup->{log_file}",
743
744 'RewriteCondition %m SIZE',
745 'RewriteRule [^[:space:]]+ $0',
746 ],
747 },
748 };
749
750 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
751 $config);
752
753 # Open pipes, for use between the parent and child processes. Specifically,
754 # the child will indicate when it's done with its test by writing a message
755 # to the parent.
756 my ($rfh, $wfh);
757 unless (pipe($rfh, $wfh)) {
758 die("Can't open pipe: $!");
759 }
760
761 my $ex;
762
763 # Fork child
764 $self->handle_sigchld();
765 defined(my $pid = fork()) or die("Can't fork: $!");
766 if ($pid) {
767 eval {
768 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
769 my ($resp_code, $resp_msg);
770
771 $client->login($setup->{user}, $setup->{passwd});
772 $client->type('binary');
773
774 # Send the path with leading spaces; the rewrite rules should handle it
775 ($resp_code, $resp_msg) = $client->size(" test.txt");
776
777 my $expected = 213;
778 $self->assert($expected == $resp_code,
779 test_msg("Expected response code $expected, got $resp_code"));
780
781 $expected = '14';
782 $self->assert($expected eq $resp_msg,
783 test_msg("Expected response message '$expected', got '$resp_msg'"));
784
785 # Send the path with following spaces; the rewrite rules should handle it
786 ($resp_code, $resp_msg) = $client->size("test.txt ");
787
788 $expected = 213;
789 $self->assert($expected == $resp_code,
790 test_msg("Expected response code $expected, got $resp_code"));
791
792 $expected = '14';
793 $self->assert($expected eq $resp_msg,
794 test_msg("Expected response message '$expected', got '$resp_msg'"));
795
796 # Send the path with leading and following spaces; the rewrite rules
797 # should handle it.
798 ($resp_code, $resp_msg) = $client->size(" test.txt ");
799
800 $expected = 213;
801 $self->assert($expected == $resp_code,
802 test_msg("Expected response code $expected, got $resp_code"));
803
804 $expected = '14';
805 $self->assert($expected eq $resp_msg,
806 test_msg("Expected response message '$expected', got '$resp_msg'"));
807
808 $client->quit();
809 };
810 if ($@) {
811 $ex = $@;
812 }
813
814 $wfh->print("done\n");
815 $wfh->flush();
816
817 } else {
818 eval { server_wait($setup->{config_file}, $rfh) };
819 if ($@) {
820 warn($@);
821 exit 1;
822 }
823
824 exit 0;
825 }
826
827 # Stop server
828 server_stop($setup->{pid_file});
829 $self->assert_child_ok($pid);
830
831 test_cleanup($setup->{log_file}, $ex);
832 }
833
834 sub rewrite_rule_append_pid {
835 my $self = shift;
836 my $tmpdir = $self->{tmpdir};
837
838 my $config_file = "$tmpdir/rewrite.conf";
839 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
840 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
841
842 my $log_file = test_get_logfile();
843
844 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
845 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
846
847 my $user = 'proftpd';
848 my $passwd = 'test';
849 my $group = 'ftpd';
850 my $home_dir = File::Spec->rel2abs($tmpdir);
851 my $uid = 500;
852 my $gid = 500;
853
854 # Make sure that, if we're running as root, that the home directory has
855 # permissions/privs set for the account we create
856 if ($< == 0) {
857 unless (chmod(0755, $home_dir)) {
858 die("Can't set perms on $home_dir to 0755: $!");
859 }
860
861 unless (chown($uid, $gid, $home_dir)) {
862 die("Can't set owner of $home_dir to $uid/$gid: $!");
863 }
864 }
865
866 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
867 '/bin/bash');
868 auth_group_write($auth_group_file, $group, $gid, $user);
869
870 my $config = {
871 PidFile => $pid_file,
872 ScoreboardFile => $scoreboard_file,
873 SystemLog => $log_file,
874
875 AuthUserFile => $auth_user_file,
876 AuthGroupFile => $auth_group_file,
877 AuthOrder => 'mod_auth_file.c',
878
879 IfModules => {
880 'mod_delay.c' => {
881 DelayEngine => 'off',
882 },
883
884 'mod_rewrite.c' => [
885 'RewriteEngine on',
886 "RewriteLog $log_file",
887
888 'RewriteCondition %m SIZE',
889 'RewriteRule (.*) $1.%P',
890 ],
891 },
892 };
893
894 my ($port, $config_user, $config_group) = config_write($config_file, $config);
895
896 # Open pipes, for use between the parent and child processes. Specifically,
897 # the child will indicate when it's done with its test by writing a message
898 # to the parent.
899 my ($rfh, $wfh);
900 unless (pipe($rfh, $wfh)) {
901 die("Can't open pipe: $!");
902 }
903
904 my $ex;
905
906 # Fork child
907 $self->handle_sigchld();
908 defined(my $pid = fork()) or die("Can't fork: $!");
909 if ($pid) {
910 eval {
911 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
912
913 my ($resp_code, $resp_msg);
914
915 $client->login($user, $passwd);
916 $client->type('binary');
917
918 eval { $client->size("tmp/test.txt") };
919 unless ($@) {
920 die("SIZE succeeded unexpectedly");
921
922 } else {
923 $resp_code = $client->response_code();
924 $resp_msg = $client->response_msg();
925 }
926
927 my $expected;
928
929 $expected = 550;
930 $self->assert($expected == $resp_code,
931 test_msg("Expected $expected, got $resp_code"));
932
933 $expected = 'tmp/test.txt.(\d+): No such file or directory';
934 $self->assert(qr/$expected/, $resp_msg,
935 test_msg("Expected '$expected', got '$resp_msg'"));
936 };
937
938 if ($@) {
939 $ex = $@;
940 }
941
942 $wfh->print("done\n");
943 $wfh->flush();
944
945 } else {
946 eval { server_wait($config_file, $rfh) };
947 if ($@) {
948 warn($@);
949 exit 1;
950 }
951
952 exit 0;
953 }
954
955 # Stop server
956 server_stop($pid_file);
957
958 $self->assert_child_ok($pid);
959
960 if ($ex) {
961 test_append_logfile($log_file, $ex);
962 unlink($log_file);
963
964 die($ex);
965 }
966
967 unlink($log_file);
968 }
969
970 sub rewrite_bug2915 {
971 my $self = shift;
972 my $tmpdir = $self->{tmpdir};
973
974 my $config_file = "$tmpdir/rewrite.conf";
975 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
976 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
977
978 my $log_file = test_get_logfile();
979
980 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
981 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
982
983 my $user = 'proftpd';
984 my $passwd = 'test';
985 my $group = 'ftpd';
986 my $home_dir = File::Spec->rel2abs($tmpdir);
987 my $uid = 500;
988 my $gid = 500;
989
990 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
991 mkpath($sub_dir);
992
993 my $test_file = 'test.txt';
994 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
995
996 if (open(my $fh, "> $test_path")) {
997 close($fh);
998
999 } else {
1000 die("Can't open $test_path: $!");
1001 }
1002
1003 # Make sure that, if we're running as root, that the home directory has
1004 # permissions/privs set for the account we create
1005 if ($< == 0) {
1006 unless (chmod(0755, $home_dir, $sub_dir)) {
1007 die("Can't set perms on $home_dir to 0755: $!");
1008 }
1009
1010 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1011 die("Can't set owner of $home_dir to $uid/$gid: $!");
1012 }
1013 }
1014
1015 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1016 '/bin/bash');
1017 auth_group_write($auth_group_file, $group, $gid, $user);
1018
1019 my $config = {
1020 PidFile => $pid_file,
1021 ScoreboardFile => $scoreboard_file,
1022 SystemLog => $log_file,
1023
1024 AuthUserFile => $auth_user_file,
1025 AuthGroupFile => $auth_group_file,
1026 AuthOrder => 'mod_auth_file.c',
1027
1028 IfModules => {
1029 'mod_delay.c' => {
1030 DelayEngine => 'off',
1031 },
1032
1033 'mod_rewrite.c' => [
1034 'RewriteEngine on',
1035 "RewriteLog $log_file",
1036 'RewriteMap replace int:replaceall',
1037 'RewriteCondition %m "^SITE CHMOD$" [NC]',
1038
1039 # There are four backslashes here so that Perl's handling of the
1040 # string reduces it to two backslashes in the emitted config
1041 'RewriteRule "^(.*) +(.*)$" "$1 ${replace:!$2!\\\\!/}"',
1042 ],
1043 },
1044 };
1045
1046 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1047
1048 # Open pipes, for use between the parent and child processes. Specifically,
1049 # the child will indicate when it's done with its test by writing a message
1050 # to the parent.
1051 my ($rfh, $wfh);
1052 unless (pipe($rfh, $wfh)) {
1053 die("Can't open pipe: $!");
1054 }
1055
1056 my $ex;
1057
1058 # Fork child
1059 $self->handle_sigchld();
1060 defined(my $pid = fork()) or die("Can't fork: $!");
1061 if ($pid) {
1062 eval {
1063 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1064
1065 my ($resp_code, $resp_msg);
1066
1067 $client->login($user, $passwd);
1068
1069 # Again, we use four backslashes here, so that Perl puts two
1070 # backslashes in the actual string
1071 ($resp_code, $resp_msg) = $client->site("chmod 600 tmp\\\\$test_file");
1072
1073 my $expected;
1074
1075 $expected = 200;
1076 $self->assert($expected == $resp_code,
1077 test_msg("Expected $expected, got $resp_code"));
1078
1079 $expected = "SITE CHMOD command successful";
1080 $self->assert($expected eq $resp_msg,
1081 test_msg("Expected '$expected', got '$resp_msg'"));
1082 };
1083
1084 if ($@) {
1085 $ex = $@;
1086 }
1087
1088 $wfh->print("done\n");
1089 $wfh->flush();
1090
1091 } else {
1092 eval { server_wait($config_file, $rfh) };
1093 if ($@) {
1094 warn($@);
1095 exit 1;
1096 }
1097
1098 exit 0;
1099 }
1100
1101 # Stop server
1102 server_stop($pid_file);
1103
1104 $self->assert_child_ok($pid);
1105
1106 if ($ex) {
1107 test_append_logfile($log_file, $ex);
1108 unlink($log_file);
1109
1110 die($ex);
1111 }
1112
1113 unlink($log_file);
1114 }
1115
1116 sub rewrite_bug3027 {
1117 my $self = shift;
1118 my $tmpdir = $self->{tmpdir};
1119
1120 my $config_file = "$tmpdir/rewrite.conf";
1121 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
1122 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
1123
1124 my $log_file = test_get_logfile();
1125
1126 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
1127 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
1128
1129 my $user = 'proftpd';
1130 my $passwd = 'test';
1131 my $group = 'ftpd';
1132 my $home_dir = File::Spec->rel2abs($tmpdir);
1133 my $uid = 500;
1134 my $gid = 500;
1135
1136 # Make sure that, if we're running as root, that the home directory has
1137 # permissions/privs set for the account we create
1138 if ($< == 0) {
1139 unless (chmod(0755, $home_dir)) {
1140 die("Can't set perms on $home_dir to 0755: $!");
1141 }
1142
1143 unless (chown($uid, $gid, $home_dir)) {
1144 die("Can't set owner of $home_dir to $uid/$gid: $!");
1145 }
1146 }
1147
1148 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1149 '/bin/bash');
1150 auth_group_write($auth_group_file, $group, $gid, $user);
1151
1152 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
1153
1154 my $config = {
1155 PidFile => $pid_file,
1156 ScoreboardFile => $scoreboard_file,
1157 SystemLog => $log_file,
1158
1159 AuthUserFile => $auth_user_file,
1160 AuthGroupFile => $auth_group_file,
1161 AuthOrder => 'mod_auth_file.c',
1162
1163 IfModules => {
1164 'mod_delay.c' => {
1165 DelayEngine => 'off',
1166 },
1167
1168 'mod_rewrite.c' => [
1169 'RewriteEngine on',
1170 "RewriteLog $log_file",
1171 'RewriteMap replace int:replaceall',
1172
1173 # Attempt to handle the case where the filename portion of the
1174 # uploaded path might be prefaced by spaces. Bug#3027 occurred
1175 # because unmatched backreferences in RewriteRule were not being
1176 # substituted properly.
1177
1178 'RewriteCondition %m ^STOR$',
1179 'RewriteRule "^(.*/)? ([^/]*)$" "$1$2"',
1180 ],
1181 },
1182 };
1183
1184 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1185
1186 # Open pipes, for use between the parent and child processes. Specifically,
1187 # the child will indicate when it's done with its test by writing a message
1188 # to the parent.
1189 my ($rfh, $wfh);
1190 unless (pipe($rfh, $wfh)) {
1191 die("Can't open pipe: $!");
1192 }
1193
1194 my $ex;
1195
1196 # Fork child
1197 $self->handle_sigchld();
1198 defined(my $pid = fork()) or die("Can't fork: $!");
1199 if ($pid) {
1200 eval {
1201 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1202
1203 my ($resp_code, $resp_msg);
1204
1205 $client->login($user, $passwd);
1206
1207 my $conn = $client->stor_raw(' test.txt');
1208
1209 my $buf = "Hello, World\n";
1210 $conn->write($buf, length($buf));
1211 eval { $conn->close() };
1212
1213 $resp_code = $client->response_code();
1214 $resp_msg = $client->response_msg();
1215
1216 my $expected;
1217
1218 $expected = 226;
1219 $self->assert($expected == $resp_code,
1220 test_msg("Expected $expected, got $resp_code"));
1221
1222 $expected = "Transfer complete";
1223 $self->assert($expected eq $resp_msg,
1224 test_msg("Expected '$expected', got '$resp_msg'"));
1225
1226 # Had Bug#3027 been present, the file name would have been "$1test.txt",
1227 # not "test.txt".
1228 $self->assert(-f $test_file,
1229 test_msg("$test_file file does not exist as expected"));
1230 };
1231
1232 if ($@) {
1233 $ex = $@;
1234 }
1235
1236 $wfh->print("done\n");
1237 $wfh->flush();
1238
1239 } else {
1240 eval { server_wait($config_file, $rfh) };
1241 if ($@) {
1242 warn($@);
1243 exit 1;
1244 }
1245
1246 exit 0;
1247 }
1248
1249 # Stop server
1250 server_stop($pid_file);
1251
1252 $self->assert_child_ok($pid);
1253
1254 if ($ex) {
1255 test_append_logfile($log_file, $ex);
1256 unlink($log_file);
1257
1258 die($ex);
1259 }
1260
1261 unlink($log_file);
1262 }
1263
1264 sub rewrite_bug3034 {
1265 my $self = shift;
1266 my $tmpdir = $self->{tmpdir};
1267
1268 my $config_file = "$tmpdir/rewrite.conf";
1269 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
1270 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
1271
1272 my $log_file = test_get_logfile();
1273
1274 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
1275 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
1276
1277 my $user = 'proftpd';
1278 my $passwd = 'test';
1279 my $group = 'ftpd';
1280 my $home_dir = File::Spec->rel2abs($tmpdir);
1281 my $uid = 500;
1282 my $gid = 500;
1283
1284 # Make sure that, if we're running as root, that the home directory has
1285 # permissions/privs set for the account we create
1286 if ($< == 0) {
1287 unless (chmod(0755, $home_dir)) {
1288 die("Can't set perms on $home_dir to 0755: $!");
1289 }
1290
1291 unless (chown($uid, $gid, $home_dir)) {
1292 die("Can't set owner of $home_dir to $uid/$gid: $!");
1293 }
1294 }
1295
1296 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1297 '/bin/bash');
1298 auth_group_write($auth_group_file, $group, $gid, $user);
1299
1300 my $config = {
1301 PidFile => $pid_file,
1302 ScoreboardFile => $scoreboard_file,
1303 SystemLog => $log_file,
1304
1305 AuthUserFile => $auth_user_file,
1306 AuthGroupFile => $auth_group_file,
1307 AuthOrder => 'mod_auth_file.c',
1308
1309 AllowForeignAddress => 'on',
1310
1311 IfModules => {
1312 'mod_delay.c' => {
1313 DelayEngine => 'off',
1314 },
1315
1316 'mod_rewrite.c' => [
1317 'RewriteEngine on',
1318 "RewriteLog $log_file",
1319 'RewriteMap replace int:replaceall',
1320
1321 # Substitute in the IP address of the client, regardless of
1322 # the address the client tells us to use in the PORT command
1323 'RewriteCondition %m ^PORT$',
1324 'RewriteRule ([0-9]+,[0-9]+,[0-9]+,[0-9]+)(.*) ${replace:/$1/$1/%a$2}',
1325
1326 # Replace the periods in the client address with commas, as per RFC959
1327 # requirements
1328 'RewriteCondition %m ^PORT$',
1329 'RewriteRule (.*) ${replace:/$1/./,}',
1330 ],
1331 },
1332 };
1333
1334 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1335
1336 # Open pipes, for use between the parent and child processes. Specifically,
1337 # the child will indicate when it's done with its test by writing a message
1338 # to the parent.
1339 my ($rfh, $wfh);
1340 unless (pipe($rfh, $wfh)) {
1341 die("Can't open pipe: $!");
1342 }
1343
1344 my $ex;
1345
1346 # Fork child
1347 $self->handle_sigchld();
1348 defined(my $pid = fork()) or die("Can't fork: $!");
1349 if ($pid) {
1350 eval {
1351 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1352
1353 my ($resp_code, $resp_msg);
1354
1355 $client->login($user, $passwd);
1356
1357 # Deliberately send a bad address; the rewrite rules should handle
1358 # it and do The Right Thing(tm).
1359 ($resp_code, $resp_msg) = $client->port('1,2,3,4,10,11');
1360
1361 my $expected;
1362
1363 $expected = 200;
1364 $self->assert($expected == $resp_code,
1365 test_msg("Expected $expected, got $resp_code"));
1366
1367 $expected = "PORT command successful";
1368 $self->assert($expected eq $resp_msg,
1369 test_msg("Expected '$expected', got '$resp_msg'"));
1370 };
1371
1372 if ($@) {
1373 $ex = $@;
1374 }
1375
1376 $wfh->print("done\n");
1377 $wfh->flush();
1378
1379 } else {
1380 eval { server_wait($config_file, $rfh) };
1381 if ($@) {
1382 warn($@);
1383 exit 1;
1384 }
1385
1386 exit 0;
1387 }
1388
1389 # Stop server
1390 server_stop($pid_file);
1391
1392 $self->assert_child_ok($pid);
1393
1394 if ($ex) {
1395 test_append_logfile($log_file, $ex);
1396 unlink($log_file);
1397
1398 die($ex);
1399 }
1400
1401 unlink($log_file);
1402 }
1403
1404 sub rewrite_bug3169 {
1405 my $self = shift;
1406 my $tmpdir = $self->{tmpdir};
1407
1408 my $config_file = "$tmpdir/rewrite.conf";
1409 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
1410 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
1411
1412 my $log_file = test_get_logfile();
1413
1414 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
1415 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
1416
1417 my $user = 'proftpd';
1418 my $passwd = 'test';
1419 my $group = 'ftpd';
1420 my $home_dir = File::Spec->rel2abs($tmpdir);
1421 my $uid = 500;
1422 my $gid = 500;
1423
1424 # Make sure that, if we're running as root, that the home directory has
1425 # permissions/privs set for the account we create
1426 if ($< == 0) {
1427 unless (chmod(0755, $home_dir)) {
1428 die("Can't set perms on $home_dir to 0755: $!");
1429 }
1430
1431 unless (chown($uid, $gid, $home_dir)) {
1432 die("Can't set owner of $home_dir to $uid/$gid: $!");
1433 }
1434 }
1435
1436 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1437 '/bin/bash');
1438 auth_group_write($auth_group_file, $group, $gid, $user);
1439
1440 my $test_file = File::Spec->rel2abs("$tmpdir/taestoe.txt");
1441
1442 # I have to build up this string, since the editor I'm currently using
1443 # does NOT like handling non-ASCII characters.
1444 my $rewrite_rule1 = 'RewriteRule (.*) ${replace:/$1/' . chr(0xe4) . '/ae}';
1445 my $rewrite_rule2 = 'RewriteRule (.*) ${replace:/$1/' . chr(0xf6) . '/oe}';
1446
1447 my $config = {
1448 PidFile => $pid_file,
1449 ScoreboardFile => $scoreboard_file,
1450 SystemLog => $log_file,
1451
1452 AuthUserFile => $auth_user_file,
1453 AuthGroupFile => $auth_group_file,
1454 AuthOrder => 'mod_auth_file.c',
1455
1456 AllowForeignAddress => 'on',
1457
1458 IfModules => {
1459 'mod_delay.c' => {
1460 DelayEngine => 'off',
1461 },
1462
1463 'mod_rewrite.c' => [
1464 'RewriteEngine on',
1465 "RewriteLog $log_file",
1466 'RewriteMap replace int:replaceall',
1467
1468 # The goal is to substitute away non-ASCII characters, replacing
1469 # them with transliterations. See:
1470 #
1471 # http://forums.proftpd.org/smf/index.php/topic,3726.0.html
1472 #
1473 # The bug (Bug#3169) was that these multiple RewriteRules *should*
1474 # work in conjunction, but were not.
1475
1476 'RewriteCondition %m ^STOR$',
1477 $rewrite_rule1,
1478 $rewrite_rule2,
1479 ],
1480 },
1481 };
1482
1483 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1484
1485 # Open pipes, for use between the parent and child processes. Specifically,
1486 # the child will indicate when it's done with its test by writing a message
1487 # to the parent.
1488 my ($rfh, $wfh);
1489 unless (pipe($rfh, $wfh)) {
1490 die("Can't open pipe: $!");
1491 }
1492
1493 my $ex;
1494
1495 # Fork child
1496 $self->handle_sigchld();
1497 defined(my $pid = fork()) or die("Can't fork: $!");
1498 if ($pid) {
1499 eval {
1500 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1501
1502 my ($resp_code, $resp_msg);
1503
1504 $client->login($user, $passwd);
1505
1506 my $filename = 't' . chr(0xe4) . 'st' . chr(0xf6) . '.txt';
1507
1508 my $conn = $client->stor_raw($filename);
1509 unless ($conn) {
1510 die("STOR $filename failed: " . $client->response_code() . " " .
1511 $client->response_msg());
1512 }
1513
1514 my $buf = "Hello, World\n";
1515 $conn->write($buf, length($buf));
1516 eval { $conn->close() };
1517
1518 $resp_code = $client->response_code();
1519 $resp_msg = $client->response_msg();
1520 $self->assert_transfer_ok($resp_code, $resp_msg);
1521
1522 $self->assert(-f $test_file,
1523 test_msg("$test_file file does not exist as expected"));
1524 };
1525
1526 if ($@) {
1527 $ex = $@;
1528 }
1529
1530 $wfh->print("done\n");
1531 $wfh->flush();
1532
1533 } else {
1534 eval { server_wait($config_file, $rfh) };
1535 if ($@) {
1536 warn($@);
1537 exit 1;
1538 }
1539
1540 exit 0;
1541 }
1542
1543 # Stop server
1544 server_stop($pid_file);
1545
1546 $self->assert_child_ok($pid);
1547
1548 if ($ex) {
1549 test_append_logfile($log_file, $ex);
1550 unlink($log_file);
1551
1552 die($ex);
1553 }
1554
1555 unlink($log_file);
1556 }
1557
1558 sub rewrite_map_unescape_bug3170 {
1559 my $self = shift;
1560 my $tmpdir = $self->{tmpdir};
1561 my $setup = test_setup($tmpdir, 'rewrite');
1562
1563 my $test_file = File::Spec->rel2abs("$tmpdir/test file.txt");
1564
1565 my $config = {
1566 PidFile => $setup->{pid_file},
1567 ScoreboardFile => $setup->{scoreboard_file},
1568 SystemLog => $setup->{log_file},
1569
1570 AuthUserFile => $setup->{auth_user_file},
1571 AuthGroupFile => $setup->{auth_group_file},
1572 AuthOrder => 'mod_auth_file.c',
1573
1574 IfModules => {
1575 'mod_delay.c' => {
1576 DelayEngine => 'off',
1577 },
1578
1579 'mod_rewrite.c' => [
1580 'RewriteEngine on',
1581 "RewriteLog $setup->{log_file}",
1582 'RewriteMap unescape int:unescape',
1583
1584 'RewriteCondition %m ^STOR$',
1585 'RewriteRule (.*) ${unescape:$1}',
1586 ],
1587 },
1588 };
1589
1590 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1591 $config);
1592
1593 # Open pipes, for use between the parent and child processes. Specifically,
1594 # the child will indicate when it's done with its test by writing a message
1595 # to the parent.
1596 my ($rfh, $wfh);
1597 unless (pipe($rfh, $wfh)) {
1598 die("Can't open pipe: $!");
1599 }
1600
1601 my $ex;
1602
1603 # Fork child
1604 $self->handle_sigchld();
1605 defined(my $pid = fork()) or die("Can't fork: $!");
1606 if ($pid) {
1607 eval {
1608 # Allow for server startup
1609 sleep(1);
1610
1611 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1612 $client->login($setup->{user}, $setup->{passwd});
1613
1614 my $filename = "test%20file.txt";
1615
1616 my $conn = $client->stor_raw($filename);
1617 unless ($conn) {
1618 die("STOR $filename failed: " . $client->response_code() . " " .
1619 $client->response_msg());
1620 }
1621
1622 my $buf = "Hello, World\n";
1623 $conn->write($buf, length($buf));
1624 eval { $conn->close() };
1625
1626 my $resp_code = $client->response_code();
1627 my $resp_msg = $client->response_msg();
1628 $self->assert_transfer_ok($resp_code, $resp_msg);
1629
1630 $client->quit();
1631
1632 $self->assert(-f $test_file,
1633 test_msg("$test_file file does not exist as expected"));
1634 };
1635 if ($@) {
1636 $ex = $@;
1637 }
1638
1639 $wfh->print("done\n");
1640 $wfh->flush();
1641
1642 } else {
1643 eval { server_wait($setup->{config_file}, $rfh) };
1644 if ($@) {
1645 warn($@);
1646 exit 1;
1647 }
1648
1649 exit 0;
1650 }
1651
1652 # Stop server
1653 server_stop($setup->{pid_file});
1654 $self->assert_child_ok($pid);
1655
1656 test_cleanup($setup->{log_file}, $ex);
1657 }
1658
1659 sub rewrite_map_unescape_bad_paths_issue2173 {
1660 my $self = shift;
1661 my $tmpdir = $self->{tmpdir};
1662 my $setup = test_setup($tmpdir, 'rewrite');
1663
1664 my $test_file1 = File::Spec->rel2abs("$tmpdir/test%2Ffile.txt");
1665 my $test_file2 = File::Spec->rel2abs("$tmpdir/test%00file.txt");
1666
1667 my $config = {
1668 PidFile => $setup->{pid_file},
1669 ScoreboardFile => $setup->{scoreboard_file},
1670 SystemLog => $setup->{log_file},
1671
1672 AuthUserFile => $setup->{auth_user_file},
1673 AuthGroupFile => $setup->{auth_group_file},
1674 AuthOrder => 'mod_auth_file.c',
1675
1676 IfModules => {
1677 'mod_delay.c' => {
1678 DelayEngine => 'off',
1679 },
1680
1681 'mod_rewrite.c' => [
1682 'RewriteEngine on',
1683 "RewriteLog $setup->{log_file}",
1684 'RewriteMap unescape int:unescape',
1685
1686 'RewriteCondition %m ^STOR$',
1687 'RewriteRule (.*) ${unescape:$1}',
1688 ],
1689 },
1690 };
1691
1692 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1693 $config);
1694
1695 # Open pipes, for use between the parent and child processes. Specifically,
1696 # the child will indicate when it's done with its test by writing a message
1697 # to the parent.
1698 my ($rfh, $wfh);
1699 unless (pipe($rfh, $wfh)) {
1700 die("Can't open pipe: $!");
1701 }
1702
1703 my $ex;
1704
1705 # Fork child
1706 $self->handle_sigchld();
1707 defined(my $pid = fork()) or die("Can't fork: $!");
1708 if ($pid) {
1709 eval {
1710 # Allow for server startup
1711 sleep(1);
1712
1713 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1714 $client->login($setup->{user}, $setup->{passwd});
1715
1716 # Here we encode the illegal '/' character via %2F
1717 my $filename = "test%2Ffile.txt";
1718
1719 my $conn = $client->stor_raw($filename);
1720 unless ($conn) {
1721 die("STOR $filename failed: " . $client->response_code() . " " .
1722 $client->response_msg());
1723 }
1724
1725 my $buf = "Hello, World\n";
1726 $conn->write($buf, length($buf));
1727 eval { $conn->close() };
1728
1729 my $resp_code = $client->response_code();
1730 my $resp_msg = $client->response_msg();
1731 $self->assert_transfer_ok($resp_code, $resp_msg);
1732
1733 # This time, we encode the illegal NUL character via %00
1734 $filename = "test%00file.txt";
1735
1736 $conn = $client->stor_raw($filename);
1737 unless ($conn) {
1738 die("STOR $filename failed: " . $client->response_code() . " " .
1739 $client->response_msg());
1740 }
1741
1742 $buf = "Hello, World\n";
1743 $conn->write($buf, length($buf));
1744 eval { $conn->close() };
1745
1746 $resp_code = $client->response_code();
1747 $resp_msg = $client->response_msg();
1748 $self->assert_transfer_ok($resp_code, $resp_msg);
1749
1750 $client->quit();
1751
1752 $self->assert(-f $test_file1,
1753 test_msg("'$test_file1' file does not exist as expected"));
1754 $self->assert(-f $test_file2,
1755 test_msg("'$test_file2' file does not exist as expected"));
1756 };
1757 if ($@) {
1758 $ex = $@;
1759 }
1760
1761 $wfh->print("done\n");
1762 $wfh->flush();
1763
1764 } else {
1765 eval { server_wait($setup->{config_file}, $rfh) };
1766 if ($@) {
1767 warn($@);
1768 exit 1;
1769 }
1770
1771 exit 0;
1772 }
1773
1774 # Stop server
1775 server_stop($setup->{pid_file});
1776 $self->assert_child_ok($pid);
1777
1778 test_cleanup($setup->{log_file}, $ex);
1779 }
1780
1781 sub rewrite_cond_env_var_failed {
1782 my $self = shift;
1783 my $tmpdir = $self->{tmpdir};
1784
1785 my $config_file = "$tmpdir/rewrite.conf";
1786 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
1787 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
1788
1789 my $log_file = test_get_logfile();
1790
1791 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
1792 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
1793
1794 my $user = 'proftpd';
1795 my $passwd = 'test';
1796 my $group = 'ftpd';
1797 my $home_dir = File::Spec->rel2abs($tmpdir);
1798 my $uid = 500;
1799 my $gid = 500;
1800
1801 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
1802 mkpath($sub_dir);
1803
1804 my $test_file = 'test_file_here.txt';
1805 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
1806
1807 if (open(my $fh, "> $test_path")) {
1808 print $fh "Hello, World!\n";
1809
1810 unless (close($fh)) {
1811 die("Can't write $test_path: $!");
1812 }
1813
1814 } else {
1815 die("Can't open $test_path: $!");
1816 }
1817
1818 # Make sure that, if we're running as root, that the home directory has
1819 # permissions/privs set for the account we create
1820 if ($< == 0) {
1821 unless (chmod(0755, $home_dir, $sub_dir)) {
1822 die("Can't set perms on $home_dir to 0755: $!");
1823 }
1824
1825 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1826 die("Can't set owner of $home_dir to $uid/$gid: $!");
1827 }
1828 }
1829
1830 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1831 '/bin/bash');
1832 auth_group_write($auth_group_file, $group, $gid, $user);
1833
1834 my $config = {
1835 PidFile => $pid_file,
1836 ScoreboardFile => $scoreboard_file,
1837 SystemLog => $log_file,
1838
1839 AuthUserFile => $auth_user_file,
1840 AuthGroupFile => $auth_group_file,
1841 AuthOrder => 'mod_auth_file.c',
1842
1843 IfModules => {
1844 'mod_delay.c' => {
1845 DelayEngine => 'off',
1846 },
1847
1848 'mod_rewrite.c' => [
1849 'RewriteEngine on',
1850 "RewriteLog $log_file",
1851
1852 'RewriteMap replace int:replaceall',
1853
1854 'RewriteCondition %m SIZE',
1855 'RewriteCondition %{ENV:PR_TEST_FOO} foo',
1856 'RewriteRule ^(.*) "${replace:!$1! !_}"',
1857 ],
1858 },
1859 };
1860
1861 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1862
1863 # Open pipes, for use between the parent and child processes. Specifically,
1864 # the child will indicate when it's done with its test by writing a message
1865 # to the parent.
1866 my ($rfh, $wfh);
1867 unless (pipe($rfh, $wfh)) {
1868 die("Can't open pipe: $!");
1869 }
1870
1871 my $ex;
1872
1873 # Fork child
1874 $self->handle_sigchld();
1875 defined(my $pid = fork()) or die("Can't fork: $!");
1876 if ($pid) {
1877 eval {
1878 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1879
1880 my ($resp_code, $resp_msg);
1881
1882 $client->login($user, $passwd);
1883 $client->type('binary');
1884
1885 my $path = "tmp/test file here.txt";
1886
1887 # Send the path with spaces; the rewrite rules should handle it
1888 eval { $client->size($path) };
1889 unless ($@) {
1890 die("SIZE $path succeeded unexpectedly");
1891 }
1892
1893 $resp_code = $client->response_code();
1894 $resp_msg = $client->response_msg();
1895
1896 my $expected;
1897
1898 $expected = 550;
1899 $self->assert($expected == $resp_code,
1900 test_msg("Expected $expected, got $resp_code"));
1901
1902 $expected = "$path: No such file or directory";
1903 $self->assert($expected eq $resp_msg,
1904 test_msg("Expected '$expected', got '$resp_msg'"));
1905 };
1906
1907 if ($@) {
1908 $ex = $@;
1909 }
1910
1911 $wfh->print("done\n");
1912 $wfh->flush();
1913
1914 } else {
1915 eval { server_wait($config_file, $rfh) };
1916 if ($@) {
1917 warn($@);
1918 exit 1;
1919 }
1920
1921 exit 0;
1922 }
1923
1924 # Stop server
1925 server_stop($pid_file);
1926
1927 $self->assert_child_ok($pid);
1928
1929 if ($ex) {
1930 test_append_logfile($log_file, $ex);
1931 unlink($log_file);
1932
1933 die($ex);
1934 }
1935
1936 unlink($log_file);
1937 }
1938
1939 sub rewrite_cond_env_var_ok {
1940 my $self = shift;
1941 my $tmpdir = $self->{tmpdir};
1942
1943 my $config_file = "$tmpdir/rewrite.conf";
1944 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
1945 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
1946
1947 my $log_file = test_get_logfile();
1948
1949 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
1950 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
1951
1952 my $user = 'proftpd';
1953 my $passwd = 'test';
1954 my $group = 'ftpd';
1955 my $home_dir = File::Spec->rel2abs($tmpdir);
1956 my $uid = 500;
1957 my $gid = 500;
1958
1959 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
1960 mkpath($sub_dir);
1961
1962 my $test_file = 'test_file_here.txt';
1963 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
1964
1965 if (open(my $fh, "> $test_path")) {
1966 print $fh "Hello, World!\n";
1967
1968 unless (close($fh)) {
1969 die("Can't write $test_path: $!");
1970 }
1971
1972 } else {
1973 die("Can't open $test_path: $!");
1974 }
1975
1976 # Make sure that, if we're running as root, that the home directory has
1977 # permissions/privs set for the account we create
1978 if ($< == 0) {
1979 unless (chmod(0755, $home_dir, $sub_dir)) {
1980 die("Can't set perms on $home_dir to 0755: $!");
1981 }
1982
1983 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1984 die("Can't set owner of $home_dir to $uid/$gid: $!");
1985 }
1986 }
1987
1988 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1989 '/bin/bash');
1990 auth_group_write($auth_group_file, $group, $gid, $user);
1991
1992 my $config = {
1993 PidFile => $pid_file,
1994 ScoreboardFile => $scoreboard_file,
1995 SystemLog => $log_file,
1996
1997 AuthUserFile => $auth_user_file,
1998 AuthGroupFile => $auth_group_file,
1999 AuthOrder => 'mod_auth_file.c',
2000
2001 SetEnv => 'PR_TEST_FOO foo',
2002
2003 IfModules => {
2004 'mod_delay.c' => {
2005 DelayEngine => 'off',
2006 },
2007
2008 'mod_rewrite.c' => [
2009 'RewriteEngine on',
2010 "RewriteLog $log_file",
2011
2012 'RewriteMap replace int:replaceall',
2013
2014 'RewriteCondition %m SIZE',
2015 'RewriteCondition %{ENV:PR_TEST_FOO} foo',
2016 'RewriteRule ^(.*) "${replace:!$1! !_}"',
2017 ],
2018 },
2019 };
2020
2021 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2022
2023 # Open pipes, for use between the parent and child processes. Specifically,
2024 # the child will indicate when it's done with its test by writing a message
2025 # to the parent.
2026 my ($rfh, $wfh);
2027 unless (pipe($rfh, $wfh)) {
2028 die("Can't open pipe: $!");
2029 }
2030
2031 my $ex;
2032
2033 # Fork child
2034 $self->handle_sigchld();
2035 defined(my $pid = fork()) or die("Can't fork: $!");
2036 if ($pid) {
2037 eval {
2038 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2039
2040 my ($resp_code, $resp_msg);
2041
2042 $client->login($user, $passwd);
2043 $client->type('binary');
2044
2045 # Send the path with spaces; the rewrite rules should handle it
2046 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
2047
2048 my $expected;
2049
2050 $expected = 213;
2051 $self->assert($expected == $resp_code,
2052 test_msg("Expected $expected, got $resp_code"));
2053
2054 $expected = '14';
2055 $self->assert($expected eq $resp_msg,
2056 test_msg("Expected '$expected', got '$resp_msg'"));
2057 };
2058
2059 if ($@) {
2060 $ex = $@;
2061 }
2062
2063 $wfh->print("done\n");
2064 $wfh->flush();
2065
2066 } else {
2067 eval { server_wait($config_file, $rfh) };
2068 if ($@) {
2069 warn($@);
2070 exit 1;
2071 }
2072
2073 exit 0;
2074 }
2075
2076 # Stop server
2077 server_stop($pid_file);
2078
2079 $self->assert_child_ok($pid);
2080
2081 if ($ex) {
2082 test_append_logfile($log_file, $ex);
2083 unlink($log_file);
2084
2085 die($ex);
2086 }
2087
2088 unlink($log_file);
2089 }
2090
2091 sub rewrite_rule_env_var_failed {
2092 my $self = shift;
2093 my $tmpdir = $self->{tmpdir};
2094
2095 my $config_file = "$tmpdir/rewrite.conf";
2096 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2097 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2098
2099 my $log_file = test_get_logfile();
2100
2101 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2102 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2103
2104 my $user = 'proftpd';
2105 my $passwd = 'test';
2106 my $group = 'ftpd';
2107 my $home_dir = File::Spec->rel2abs($tmpdir);
2108 my $uid = 500;
2109 my $gid = 500;
2110
2111 my $test_file = 'foo.txt';
2112 my $test_path = File::Spec->rel2abs("$home_dir/$test_file");
2113
2114 if (open(my $fh, "> $test_path")) {
2115 print $fh "Hello, World!\n";
2116
2117 unless (close($fh)) {
2118 die("Can't write $test_path: $!");
2119 }
2120
2121 } else {
2122 die("Can't open $test_path: $!");
2123 }
2124
2125 # Make sure that, if we're running as root, that the home directory has
2126 # permissions/privs set for the account we create
2127 if ($< == 0) {
2128 unless (chmod(0755, $home_dir)) {
2129 die("Can't set perms on $home_dir to 0755: $!");
2130 }
2131
2132 unless (chown($uid, $gid, $home_dir)) {
2133 die("Can't set owner of $home_dir to $uid/$gid: $!");
2134 }
2135 }
2136
2137 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2138 '/bin/bash');
2139 auth_group_write($auth_group_file, $group, $gid, $user);
2140
2141 my $config = {
2142 PidFile => $pid_file,
2143 ScoreboardFile => $scoreboard_file,
2144 SystemLog => $log_file,
2145
2146 AuthUserFile => $auth_user_file,
2147 AuthGroupFile => $auth_group_file,
2148 AuthOrder => 'mod_auth_file.c',
2149
2150 IfModules => {
2151 'mod_delay.c' => {
2152 DelayEngine => 'off',
2153 },
2154
2155 'mod_rewrite.c' => [
2156 'RewriteEngine on',
2157 "RewriteLog $log_file",
2158
2159 'RewriteCondition %m SIZE',
2160 'RewriteRule ^(.*) %{ENV:PR_TEST_FOO}.txt',
2161 ],
2162 },
2163 };
2164
2165 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2166
2167 # Open pipes, for use between the parent and child processes. Specifically,
2168 # the child will indicate when it's done with its test by writing a message
2169 # to the parent.
2170 my ($rfh, $wfh);
2171 unless (pipe($rfh, $wfh)) {
2172 die("Can't open pipe: $!");
2173 }
2174
2175 my $ex;
2176
2177 # Fork child
2178 $self->handle_sigchld();
2179 defined(my $pid = fork()) or die("Can't fork: $!");
2180 if ($pid) {
2181 eval {
2182 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2183
2184 my ($resp_code, $resp_msg);
2185
2186 $client->login($user, $passwd);
2187 $client->type('binary');
2188
2189 my $path = "foo.txt";
2190
2191 # Send the path with spaces; the rewrite rules should handle it
2192 eval { $client->size($path) };
2193 unless ($@) {
2194 die("SIZE $path succeeded unexpectedly");
2195 }
2196
2197 $resp_code = $client->response_code();
2198 $resp_msg = $client->response_msg();
2199
2200 my $expected;
2201
2202 $expected = 550;
2203 $self->assert($expected == $resp_code,
2204 test_msg("Expected $expected, got $resp_code"));
2205
2206 $expected = ".txt: No such file or directory";
2207 $self->assert($expected eq $resp_msg,
2208 test_msg("Expected '$expected', got '$resp_msg'"));
2209 };
2210
2211 if ($@) {
2212 $ex = $@;
2213 }
2214
2215 $wfh->print("done\n");
2216 $wfh->flush();
2217
2218 } else {
2219 eval { server_wait($config_file, $rfh) };
2220 if ($@) {
2221 warn($@);
2222 exit 1;
2223 }
2224
2225 exit 0;
2226 }
2227
2228 # Stop server
2229 server_stop($pid_file);
2230
2231 $self->assert_child_ok($pid);
2232
2233 if ($ex) {
2234 test_append_logfile($log_file, $ex);
2235 unlink($log_file);
2236
2237 die($ex);
2238 }
2239
2240 unlink($log_file);
2241 }
2242
2243 sub rewrite_rule_env_var_ok {
2244 my $self = shift;
2245 my $tmpdir = $self->{tmpdir};
2246
2247 my $config_file = "$tmpdir/rewrite.conf";
2248 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2249 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2250
2251 my $log_file = test_get_logfile();
2252
2253 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2254 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2255
2256 my $user = 'proftpd';
2257 my $passwd = 'test';
2258 my $group = 'ftpd';
2259 my $home_dir = File::Spec->rel2abs($tmpdir);
2260 my $uid = 500;
2261 my $gid = 500;
2262
2263 my $test_file = 'foo.txt';
2264 my $test_path = File::Spec->rel2abs("$home_dir/$test_file");
2265
2266 if (open(my $fh, "> $test_path")) {
2267 print $fh "Hello, World!\n";
2268
2269 unless (close($fh)) {
2270 die("Can't write $test_path: $!");
2271 }
2272
2273 } else {
2274 die("Can't open $test_path: $!");
2275 }
2276
2277 # Make sure that, if we're running as root, that the home directory has
2278 # permissions/privs set for the account we create
2279 if ($< == 0) {
2280 unless (chmod(0755, $home_dir)) {
2281 die("Can't set perms on $home_dir to 0755: $!");
2282 }
2283
2284 unless (chown($uid, $gid, $home_dir)) {
2285 die("Can't set owner of $home_dir to $uid/$gid: $!");
2286 }
2287 }
2288
2289 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2290 '/bin/bash');
2291 auth_group_write($auth_group_file, $group, $gid, $user);
2292
2293 my $config = {
2294 PidFile => $pid_file,
2295 ScoreboardFile => $scoreboard_file,
2296 SystemLog => $log_file,
2297
2298 AuthUserFile => $auth_user_file,
2299 AuthGroupFile => $auth_group_file,
2300 AuthOrder => 'mod_auth_file.c',
2301
2302 SetEnv => 'PR_TEST_FOO foo',
2303
2304 IfModules => {
2305 'mod_delay.c' => {
2306 DelayEngine => 'off',
2307 },
2308
2309 'mod_rewrite.c' => [
2310 'RewriteEngine on',
2311 "RewriteLog $log_file",
2312
2313 'RewriteCondition %m SIZE',
2314 'RewriteRule ^(.*) %{ENV:PR_TEST_FOO}.txt',
2315 ],
2316 },
2317 };
2318
2319 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2320
2321 # Open pipes, for use between the parent and child processes. Specifically,
2322 # the child will indicate when it's done with its test by writing a message
2323 # to the parent.
2324 my ($rfh, $wfh);
2325 unless (pipe($rfh, $wfh)) {
2326 die("Can't open pipe: $!");
2327 }
2328
2329 my $ex;
2330
2331 # Fork child
2332 $self->handle_sigchld();
2333 defined(my $pid = fork()) or die("Can't fork: $!");
2334 if ($pid) {
2335 eval {
2336 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2337
2338 my ($resp_code, $resp_msg);
2339
2340 $client->login($user, $passwd);
2341 $client->type('binary');
2342
2343 # Send the path with spaces; the rewrite rules should handle it
2344 ($resp_code, $resp_msg) = $client->size("foo.txt");
2345
2346 my $expected;
2347
2348 $expected = 213;
2349 $self->assert($expected == $resp_code,
2350 test_msg("Expected $expected, got $resp_code"));
2351
2352 $expected = '14';
2353 $self->assert($expected eq $resp_msg,
2354 test_msg("Expected '$expected', got '$resp_msg'"));
2355 };
2356
2357 if ($@) {
2358 $ex = $@;
2359 }
2360
2361 $wfh->print("done\n");
2362 $wfh->flush();
2363
2364 } else {
2365 eval { server_wait($config_file, $rfh) };
2366 if ($@) {
2367 warn($@);
2368 exit 1;
2369 }
2370
2371 exit 0;
2372 }
2373
2374 # Stop server
2375 server_stop($pid_file);
2376
2377 $self->assert_child_ok($pid);
2378
2379 if ($ex) {
2380 test_append_logfile($log_file, $ex);
2381 unlink($log_file);
2382
2383 die($ex);
2384 }
2385
2386 unlink($log_file);
2387 }
2388
2389 sub rewrite_escape_rule_backref_bug3028 {
2390 my $self = shift;
2391 my $tmpdir = $self->{tmpdir};
2392
2393 my $config_file = "$tmpdir/rewrite.conf";
2394 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2395 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2396
2397 my $log_file = test_get_logfile();
2398
2399 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2400 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2401
2402 my $user = 'proftpd';
2403 my $passwd = 'test';
2404 my $group = 'ftpd';
2405 my $home_dir = File::Spec->rel2abs($tmpdir);
2406 my $uid = 500;
2407 my $gid = 500;
2408
2409 my $test_file = File::Spec->rel2abs("$tmpdir/" . '$100dollars.txt');
2410 if (open(my $fh, "> $test_file")) {
2411 print $fh "Hello, World!\n";
2412 unless (close($fh)) {
2413 die("Can't write $test_file: $!");
2414 }
2415
2416 } else {
2417 die("Can't open $test_file: $!");
2418 }
2419
2420 # Make sure that, if we're running as root, that the home directory has
2421 # permissions/privs set for the account we create
2422 if ($< == 0) {
2423 unless (chmod(0755, $home_dir)) {
2424 die("Can't set perms on $home_dir to 0755: $!");
2425 }
2426
2427 unless (chown($uid, $gid, $home_dir)) {
2428 die("Can't set owner of $home_dir to $uid/$gid: $!");
2429 }
2430 }
2431
2432 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2433 '/bin/bash');
2434 auth_group_write($auth_group_file, $group, $gid, $user);
2435
2436 my $config = {
2437 PidFile => $pid_file,
2438 ScoreboardFile => $scoreboard_file,
2439 SystemLog => $log_file,
2440
2441 AuthUserFile => $auth_user_file,
2442 AuthGroupFile => $auth_group_file,
2443 AuthOrder => 'mod_auth_file.c',
2444
2445 IfModules => {
2446 'mod_delay.c' => {
2447 DelayEngine => 'off',
2448 },
2449
2450 'mod_rewrite.c' => [
2451 'RewriteEngine on',
2452 "RewriteLog $log_file",
2453
2454 'RewriteCondition %m SIZE',
2455 'RewriteRule (.*) $$100dollars.txt',
2456 ],
2457 },
2458 };
2459
2460 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2461
2462 # Open pipes, for use between the parent and child processes. Specifically,
2463 # the child will indicate when it's done with its test by writing a message
2464 # to the parent.
2465 my ($rfh, $wfh);
2466 unless (pipe($rfh, $wfh)) {
2467 die("Can't open pipe: $!");
2468 }
2469
2470 my $ex;
2471
2472 # Fork child
2473 $self->handle_sigchld();
2474 defined(my $pid = fork()) or die("Can't fork: $!");
2475 if ($pid) {
2476 eval {
2477 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2478
2479 my ($resp_code, $resp_msg);
2480
2481 $client->login($user, $passwd);
2482 $client->type('binary');
2483
2484 ($resp_code, $resp_msg) = $client->size("tmp/test.txt");
2485
2486 my $expected;
2487
2488 $expected = 213;
2489 $self->assert($expected == $resp_code,
2490 test_msg("Expected $expected, got $resp_code"));
2491
2492 $expected = 14;
2493 $self->assert($expected eq $resp_msg,
2494 test_msg("Expected '$expected', got '$resp_msg'"));
2495 };
2496
2497 if ($@) {
2498 $ex = $@;
2499 }
2500
2501 $wfh->print("done\n");
2502 $wfh->flush();
2503
2504 } else {
2505 eval { server_wait($config_file, $rfh) };
2506 if ($@) {
2507 warn($@);
2508 exit 1;
2509 }
2510
2511 exit 0;
2512 }
2513
2514 # Stop server
2515 server_stop($pid_file);
2516
2517 $self->assert_child_ok($pid);
2518
2519 if ($ex) {
2520 test_append_logfile($log_file, $ex);
2521 unlink($log_file);
2522
2523 die($ex);
2524 }
2525
2526 unlink($log_file);
2527 }
2528
2529 sub rewrite_escape_cond_backref_bug3028 {
2530 my $self = shift;
2531 my $tmpdir = $self->{tmpdir};
2532
2533 my $config_file = "$tmpdir/rewrite.conf";
2534 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2535 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2536
2537 my $log_file = test_get_logfile();
2538
2539 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2540 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2541
2542 my $user = 'proftpd';
2543 my $passwd = 'test';
2544 my $group = 'ftpd';
2545 my $home_dir = File::Spec->rel2abs($tmpdir);
2546 my $uid = 500;
2547 my $gid = 500;
2548
2549 my $test_file = File::Spec->rel2abs("$tmpdir/" . '%100dollars.txt');
2550 if (open(my $fh, "> $test_file")) {
2551 print $fh "Hello, World!\n";
2552 unless (close($fh)) {
2553 die("Can't write $test_file: $!");
2554 }
2555
2556 } else {
2557 die("Can't open $test_file: $!");
2558 }
2559
2560 # Make sure that, if we're running as root, that the home directory has
2561 # permissions/privs set for the account we create
2562 if ($< == 0) {
2563 unless (chmod(0755, $home_dir)) {
2564 die("Can't set perms on $home_dir to 0755: $!");
2565 }
2566
2567 unless (chown($uid, $gid, $home_dir)) {
2568 die("Can't set owner of $home_dir to $uid/$gid: $!");
2569 }
2570 }
2571
2572 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2573 '/bin/bash');
2574 auth_group_write($auth_group_file, $group, $gid, $user);
2575
2576 my $config = {
2577 PidFile => $pid_file,
2578 ScoreboardFile => $scoreboard_file,
2579 SystemLog => $log_file,
2580
2581 AuthUserFile => $auth_user_file,
2582 AuthGroupFile => $auth_group_file,
2583 AuthOrder => 'mod_auth_file.c',
2584
2585 IfModules => {
2586 'mod_delay.c' => {
2587 DelayEngine => 'off',
2588 },
2589
2590 'mod_rewrite.c' => [
2591 'RewriteEngine on',
2592 "RewriteLog $log_file",
2593
2594 'RewriteCondition %m SIZE',
2595 'RewriteRule (.*) %%100dollars.txt',
2596 ],
2597 },
2598 };
2599
2600 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2601
2602 # Open pipes, for use between the parent and child processes. Specifically,
2603 # the child will indicate when it's done with its test by writing a message
2604 # to the parent.
2605 my ($rfh, $wfh);
2606 unless (pipe($rfh, $wfh)) {
2607 die("Can't open pipe: $!");
2608 }
2609
2610 my $ex;
2611
2612 # Fork child
2613 $self->handle_sigchld();
2614 defined(my $pid = fork()) or die("Can't fork: $!");
2615 if ($pid) {
2616 eval {
2617 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2618
2619 my ($resp_code, $resp_msg);
2620
2621 $client->login($user, $passwd);
2622 $client->type('binary');
2623
2624 ($resp_code, $resp_msg) = $client->size("tmp/test.txt");
2625
2626 my $expected;
2627
2628 $expected = 213;
2629 $self->assert($expected == $resp_code,
2630 test_msg("Expected $expected, got $resp_code"));
2631
2632 $expected = 14;
2633 $self->assert($expected eq $resp_msg,
2634 test_msg("Expected '$expected', got '$resp_msg'"));
2635 };
2636
2637 if ($@) {
2638 $ex = $@;
2639 }
2640
2641 $wfh->print("done\n");
2642 $wfh->flush();
2643
2644 } else {
2645 eval { server_wait($config_file, $rfh) };
2646 if ($@) {
2647 warn($@);
2648 exit 1;
2649 }
2650
2651 exit 0;
2652 }
2653
2654 # Stop server
2655 server_stop($pid_file);
2656
2657 $self->assert_child_ok($pid);
2658
2659 if ($ex) {
2660 test_append_logfile($log_file, $ex);
2661 unlink($log_file);
2662
2663 die($ex);
2664 }
2665
2666 unlink($log_file);
2667 }
2668
2669 sub rewrite_cond_rename_var_bug3029 {
2670 my $self = shift;
2671 my $tmpdir = $self->{tmpdir};
2672
2673 my $config_file = "$tmpdir/rewrite.conf";
2674 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2675 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2676
2677 my $log_file = test_get_logfile();
2678
2679 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2680 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2681
2682 my $user = 'proftpd';
2683 my $passwd = 'test';
2684 my $group = 'ftpd';
2685 my $home_dir = File::Spec->rel2abs($tmpdir);
2686 my $uid = 500;
2687 my $gid = 500;
2688
2689 my $test_file = File::Spec->rel2abs("$tmpdir/" . '%100dollars.txt');
2690 if (open(my $fh, "> $test_file")) {
2691 print $fh "Hello, World!\n";
2692 unless (close($fh)) {
2693 die("Can't write $test_file: $!");
2694 }
2695
2696 } else {
2697 die("Can't open $test_file: $!");
2698 }
2699
2700 # Make sure that, if we're running as root, that the home directory has
2701 # permissions/privs set for the account we create
2702 if ($< == 0) {
2703 unless (chmod(0755, $home_dir)) {
2704 die("Can't set perms on $home_dir to 0755: $!");
2705 }
2706
2707 unless (chown($uid, $gid, $home_dir)) {
2708 die("Can't set owner of $home_dir to $uid/$gid: $!");
2709 }
2710 }
2711
2712 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2713 '/bin/bash');
2714 auth_group_write($auth_group_file, $group, $gid, $user);
2715
2716 my $src_dir = File::Spec->rel2abs("$tmpdir/srcdir");
2717 mkpath($src_dir);
2718
2719 my $dst_dir = File::Spec->rel2abs("$tmpdir/dstdir");
2720
2721 my $config = {
2722 PidFile => $pid_file,
2723 ScoreboardFile => $scoreboard_file,
2724 SystemLog => $log_file,
2725
2726 AuthUserFile => $auth_user_file,
2727 AuthGroupFile => $auth_group_file,
2728 AuthOrder => 'mod_auth_file.c',
2729
2730 IfModules => {
2731 'mod_delay.c' => {
2732 DelayEngine => 'off',
2733 },
2734
2735 'mod_rewrite.c' => [
2736 'RewriteEngine on',
2737 "RewriteLog $log_file",
2738
2739 'RewriteMap lowercase int:tolower',
2740 'RewriteCondition %m ^RNTO$',
2741 'RewriteCondition %w -d',
2742 'RewriteRule ^(.*) ${lowercase:$0}',
2743 ],
2744 },
2745 };
2746
2747 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2748
2749 # Open pipes, for use between the parent and child processes. Specifically,
2750 # the child will indicate when it's done with its test by writing a message
2751 # to the parent.
2752 my ($rfh, $wfh);
2753 unless (pipe($rfh, $wfh)) {
2754 die("Can't open pipe: $!");
2755 }
2756
2757 my $ex;
2758
2759 # Fork child
2760 $self->handle_sigchld();
2761 defined(my $pid = fork()) or die("Can't fork: $!");
2762 if ($pid) {
2763 eval {
2764 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2765
2766 $client->login($user, $passwd);
2767 $client->rnfr('srcdir');
2768 $client->rnto('DSTDIR');
2769
2770 $self->assert(-d $dst_dir,
2771 test_msg("$dst_dir directory does not exist as expected"));
2772 };
2773
2774 if ($@) {
2775 $ex = $@;
2776 }
2777
2778 $wfh->print("done\n");
2779 $wfh->flush();
2780
2781 } else {
2782 eval { server_wait($config_file, $rfh) };
2783 if ($@) {
2784 warn($@);
2785 exit 1;
2786 }
2787
2788 exit 0;
2789 }
2790
2791 # Stop server
2792 server_stop($pid_file);
2793
2794 $self->assert_child_ok($pid);
2795
2796 if ($ex) {
2797 test_append_logfile($log_file, $ex);
2798 unlink($log_file);
2799
2800 die($ex);
2801 }
2802
2803 unlink($log_file);
2804 }
2805
2806 sub rewrite_cond_or_flags_bug3269 {
2807 my $self = shift;
2808 my $tmpdir = $self->{tmpdir};
2809
2810 my $config_file = "$tmpdir/rewrite.conf";
2811 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2812 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2813
2814 my $log_file = test_get_logfile();
2815
2816 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2817 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2818
2819 my $user = 'proftpd';
2820 my $passwd = 'test';
2821 my $group = 'ftpd';
2822 my $home_dir = File::Spec->rel2abs($tmpdir);
2823 my $uid = 500;
2824 my $gid = 500;
2825
2826 # Make sure that, if we're running as root, that the home directory has
2827 # permissions/privs set for the account we create
2828 if ($< == 0) {
2829 unless (chmod(0755, $home_dir)) {
2830 die("Can't set perms on $home_dir to 0755: $!");
2831 }
2832
2833 unless (chown($uid, $gid, $home_dir)) {
2834 die("Can't set owner of $home_dir to $uid/$gid: $!");
2835 }
2836 }
2837
2838 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2839 '/bin/bash');
2840 auth_group_write($auth_group_file, $group, $gid, $user);
2841
2842 my $config = {
2843 PidFile => $pid_file,
2844 ScoreboardFile => $scoreboard_file,
2845 SystemLog => $log_file,
2846
2847 AuthUserFile => $auth_user_file,
2848 AuthGroupFile => $auth_group_file,
2849 AuthOrder => 'mod_auth_file.c',
2850
2851 IfModules => {
2852 'mod_delay.c' => {
2853 DelayEngine => 'off',
2854 },
2855
2856 'mod_rewrite.c' => [
2857 'RewriteEngine on',
2858 "RewriteLog $log_file",
2859
2860 'RewriteCondition %m SIZE [OR]',
2861 'RewriteCondition %m STOU',
2862 'RewriteRule (.*) $1.%P',
2863 ],
2864 },
2865 };
2866
2867 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2868
2869 # Open pipes, for use between the parent and child processes. Specifically,
2870 # the child will indicate when it's done with its test by writing a message
2871 # to the parent.
2872 my ($rfh, $wfh);
2873 unless (pipe($rfh, $wfh)) {
2874 die("Can't open pipe: $!");
2875 }
2876
2877 my $ex;
2878
2879 # Fork child
2880 $self->handle_sigchld();
2881 defined(my $pid = fork()) or die("Can't fork: $!");
2882 if ($pid) {
2883 eval {
2884 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2885
2886 my ($resp_code, $resp_msg);
2887
2888 $client->login($user, $passwd);
2889 $client->type('binary');
2890
2891 eval { $client->size("tmp/test.txt") };
2892 unless ($@) {
2893 die("SIZE succeeded unexpectedly");
2894
2895 } else {
2896 $resp_code = $client->response_code();
2897 $resp_msg = $client->response_msg();
2898 }
2899
2900 my $expected;
2901
2902 $expected = 550;
2903 $self->assert($expected == $resp_code,
2904 test_msg("Expected $expected, got $resp_code"));
2905
2906 $expected = 'tmp/test.txt.(\d+): No such file or directory';
2907 $self->assert(qr/$expected/, $resp_msg,
2908 test_msg("Expected '$expected', got '$resp_msg'"));
2909 };
2910
2911 if ($@) {
2912 $ex = $@;
2913 }
2914
2915 $wfh->print("done\n");
2916 $wfh->flush();
2917
2918 } else {
2919 eval { server_wait($config_file, $rfh) };
2920 if ($@) {
2921 warn($@);
2922 exit 1;
2923 }
2924
2925 exit 0;
2926 }
2927
2928 # Stop server
2929 server_stop($pid_file);
2930
2931 $self->assert_child_ok($pid);
2932
2933 if ($ex) {
2934 test_append_logfile($log_file, $ex);
2935 unlink($log_file);
2936
2937 die($ex);
2938 }
2939
2940 unlink($log_file);
2941 }
2942
2943 sub rewrite_cond_nc_flags {
2944 my $self = shift;
2945 my $tmpdir = $self->{tmpdir};
2946
2947 my $config_file = "$tmpdir/rewrite.conf";
2948 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
2949 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
2950
2951 my $log_file = test_get_logfile();
2952
2953 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
2954 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
2955
2956 my $user = 'proftpd';
2957 my $passwd = 'test';
2958 my $group = 'ftpd';
2959 my $home_dir = File::Spec->rel2abs($tmpdir);
2960 my $uid = 500;
2961 my $gid = 500;
2962
2963 # Make sure that, if we're running as root, that the home directory has
2964 # permissions/privs set for the account we create
2965 if ($< == 0) {
2966 unless (chmod(0755, $home_dir)) {
2967 die("Can't set perms on $home_dir to 0755: $!");
2968 }
2969
2970 unless (chown($uid, $gid, $home_dir)) {
2971 die("Can't set owner of $home_dir to $uid/$gid: $!");
2972 }
2973 }
2974
2975 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2976 '/bin/bash');
2977 auth_group_write($auth_group_file, $group, $gid, $user);
2978
2979 my $config = {
2980 PidFile => $pid_file,
2981 ScoreboardFile => $scoreboard_file,
2982 SystemLog => $log_file,
2983
2984 AuthUserFile => $auth_user_file,
2985 AuthGroupFile => $auth_group_file,
2986 AuthOrder => 'mod_auth_file.c',
2987
2988 IfModules => {
2989 'mod_delay.c' => {
2990 DelayEngine => 'off',
2991 },
2992
2993 'mod_rewrite.c' => [
2994 'RewriteEngine on',
2995 "RewriteLog $log_file",
2996
2997 'RewriteCondition %u ^ProFTPD$ [NC]',
2998 'RewriteCondition %m SIZE',
2999 'RewriteRule (.*) $1.%P',
3000 ],
3001 },
3002 };
3003
3004 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3005
3006 # Open pipes, for use between the parent and child processes. Specifically,
3007 # the child will indicate when it's done with its test by writing a message
3008 # to the parent.
3009 my ($rfh, $wfh);
3010 unless (pipe($rfh, $wfh)) {
3011 die("Can't open pipe: $!");
3012 }
3013
3014 my $ex;
3015
3016 # Fork child
3017 $self->handle_sigchld();
3018 defined(my $pid = fork()) or die("Can't fork: $!");
3019 if ($pid) {
3020 eval {
3021 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3022
3023 my ($resp_code, $resp_msg);
3024
3025 $client->login($user, $passwd);
3026 $client->type('binary');
3027
3028 eval { $client->size("tmp/test.txt") };
3029 unless ($@) {
3030 die("SIZE succeeded unexpectedly");
3031
3032 } else {
3033 $resp_code = $client->response_code();
3034 $resp_msg = $client->response_msg();
3035 }
3036
3037 my $expected;
3038
3039 $expected = 550;
3040 $self->assert($expected == $resp_code,
3041 test_msg("Expected $expected, got $resp_code"));
3042
3043 $expected = 'tmp/test.txt.(\d+): No such file or directory';
3044 $self->assert(qr/$expected/, $resp_msg,
3045 test_msg("Expected '$expected', got '$resp_msg'"));
3046 };
3047
3048 if ($@) {
3049 $ex = $@;
3050 }
3051
3052 $wfh->print("done\n");
3053 $wfh->flush();
3054
3055 } else {
3056 eval { server_wait($config_file, $rfh) };
3057 if ($@) {
3058 warn($@);
3059 exit 1;
3060 }
3061
3062 exit 0;
3063 }
3064
3065 # Stop server
3066 server_stop($pid_file);
3067
3068 $self->assert_child_ok($pid);
3069
3070 if ($ex) {
3071 test_append_logfile($log_file, $ex);
3072 unlink($log_file);
3073
3074 die($ex);
3075 }
3076
3077 unlink($log_file);
3078 }
3079
3080 sub rewrite_map_fifo_bug3611 {
3081 my $self = shift;
3082 my $tmpdir = $self->{tmpdir};
3083 my $setup = test_setup($tmpdir, 'rewrite');
3084
3085 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
3086 mkpath($sub_dir);
3087
3088 my $test_file = 'test.txt';
3089 my $test_path = File::Spec->rel2abs("$tmpdir/$test_file");
3090
3091 if (open(my $fh, "> $test_path")) {
3092 print $fh "Hello, World!\n";
3093
3094 unless (close($fh)) {
3095 die("Can't write $test_path: $!");
3096 }
3097
3098 } else {
3099 die("Can't open $test_path: $!");
3100 }
3101
3102 # Make sure that, if we're running as root, that the home directory has
3103 # permissions/privs set for the account we create
3104 if ($< == 0) {
3105 unless (chmod(0755, $sub_dir)) {
3106 die("Can't set perms on $sub_dir to 0755: $!");
3107 }
3108
3109 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
3110 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
3111 }
3112 }
3113
3114 my $fifo_script = File::Spec->rel2abs('t/etc/modules/mod_rewrite/reverse.pl');
3115
3116 my $fifo = File::Spec->rel2abs("$setup->{home_dir}/test.fifo");
3117 unless (POSIX::mkfifo($fifo, 0666)) {
3118 die("Can't create fifo $fifo: $!");
3119 }
3120
3121 my $fifo_pidfile = File::Spec->rel2abs("$setup->{home_dir}/fifo.pid");
3122
3123 my $config = {
3124 PidFile => $setup->{pid_file},
3125 ScoreboardFile => $setup->{scoreboard_file},
3126 SystemLog => $setup->{log_file},
3127 TraceLog => $setup->{log_file},
3128 Trace => 'DEFAULT:10',
3129
3130 AuthUserFile => $setup->{auth_user_file},
3131 AuthGroupFile => $setup->{auth_group_file},
3132 AuthOrder => 'mod_auth_file.c',
3133
3134 IfModules => {
3135 'mod_delay.c' => {
3136 DelayEngine => 'off',
3137 },
3138
3139 'mod_rewrite.c' => [
3140 'RewriteEngine on',
3141 "RewriteLog $setup->{log_file}",
3142
3143 'RewriteCondition %m !PASS',
3144 "RewriteMap reverse fifo:$fifo",
3145 'RewriteRule ^(.*) ${reverse:$1}',
3146 ],
3147 },
3148 };
3149
3150 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3151 $config);
3152
3153 # Open pipes, for use between the parent and child processes. Specifically,
3154 # the child will indicate when it's done with its test by writing a message
3155 # to the parent.
3156 my ($rfh, $wfh);
3157 unless (pipe($rfh, $wfh)) {
3158 die("Can't open pipe: $!");
3159 }
3160
3161 my $ex;
3162
3163 # Fork child
3164 $self->handle_sigchld();
3165 defined(my $pid = fork()) or die("Can't fork: $!");
3166 if ($pid) {
3167 eval {
3168 # Allow for server startup
3169 sleep(1);
3170
3171 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3172
3173 my $name = join('', reverse(split//, $setup->{user}));
3174 $client->login($name, $setup->{passwd});
3175 $client->type('binary');
3176
3177 # Send the path in reverse; the rewrite FIFO should reverse
3178 # everything.
3179 my $path = join('', reverse(split(//, $test_file)));
3180 my ($resp_code, $resp_msg) = $client->stat($path);
3181
3182 my $expected = 213;
3183 $self->assert($expected == $resp_code,
3184 test_msg("Expected response code $expected, got $resp_code"));
3185 };
3186 if ($@) {
3187 $ex = $@;
3188 }
3189
3190 $wfh->print("done\n");
3191 $wfh->flush();
3192
3193 } else {
3194 # Start the FIFO script
3195 `$fifo_script --verbose --fifo $fifo --pidfile $fifo_pidfile >> $setup->{log_file} 2>&1 &`;
3196
3197 eval { server_wait($setup->{config_file}, $rfh) };
3198 if ($@) {
3199 warn($@);
3200
3201 if (open(my $fh, "< $fifo_pidfile")) {
3202 my $fifo_pid = <$fh>;
3203 chomp($fifo_pid);
3204
3205 kill('TERM', $fifo_pid);
3206 close($fh);
3207 }
3208
3209 exit 1;
3210 }
3211
3212 if (open(my $fh, "< $fifo_pidfile")) {
3213 my $fifo_pid = <$fh>;
3214 chomp($fifo_pid);
3215
3216 kill('TERM', $fifo_pid);
3217 close($fh);
3218 }
3219
3220 exit 0;
3221 }
3222
3223 if (open(my $fh, "< $fifo_pidfile")) {
3224 my $fifo_pid = <$fh>;
3225 chomp($fifo_pid);
3226
3227 kill('TERM', $fifo_pid);
3228 close($fh);
3229 }
3230
3231 # Stop server
3232 server_stop($setup->{pid_file});
3233 $self->assert_child_ok($pid);
3234
3235 test_cleanup($setup->{log_file}, $ex);
3236 }
3237
3238 sub rewrite_rule_replaceall_backslash_with_slash {
3239 my $self = shift;
3240 my $tmpdir = $self->{tmpdir};
3241
3242 my $config_file = "$tmpdir/rewrite.conf";
3243 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
3244 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
3245
3246 my $log_file = test_get_logfile();
3247
3248 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
3249 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
3250
3251 my $user = 'proftpd';
3252 my $passwd = 'test';
3253 my $group = 'ftpd';
3254 my $home_dir = File::Spec->rel2abs($tmpdir);
3255 my $uid = 500;
3256 my $gid = 500;
3257
3258 # Make sure that, if we're running as root, that the home directory has
3259 # permissions/privs set for the account we create
3260 if ($< == 0) {
3261 unless (chmod(0755, $home_dir)) {
3262 die("Can't set perms on $home_dir to 0755: $!");
3263 }
3264
3265 unless (chown($uid, $gid, $home_dir)) {
3266 die("Can't set owner of $home_dir to $uid/$gid: $!");
3267 }
3268 }
3269
3270 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3271 '/bin/bash');
3272 auth_group_write($auth_group_file, $group, $gid, $user);
3273
3274 my $config = {
3275 PidFile => $pid_file,
3276 ScoreboardFile => $scoreboard_file,
3277 SystemLog => $log_file,
3278
3279 AuthUserFile => $auth_user_file,
3280 AuthGroupFile => $auth_group_file,
3281 AuthOrder => 'mod_auth_file.c',
3282
3283 IfModules => {
3284 'mod_delay.c' => {
3285 DelayEngine => 'off',
3286 },
3287
3288 'mod_rewrite.c' => [
3289 'RewriteEngine on',
3290 "RewriteLog $log_file",
3291
3292 'RewriteMap replace int:replaceall',
3293 'RewriteCondition %m SIZE',
3294 'RewriteRule (.*) "${replace:!$1!\\\\!/}"',
3295 ],
3296 },
3297 };
3298
3299 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3300
3301 # Open pipes, for use between the parent and child processes. Specifically,
3302 # the child will indicate when it's done with its test by writing a message
3303 # to the parent.
3304 my ($rfh, $wfh);
3305 unless (pipe($rfh, $wfh)) {
3306 die("Can't open pipe: $!");
3307 }
3308
3309 my $ex;
3310
3311 # Fork child
3312 $self->handle_sigchld();
3313 defined(my $pid = fork()) or die("Can't fork: $!");
3314 if ($pid) {
3315 eval {
3316 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3317
3318 my ($resp_code, $resp_msg);
3319
3320 $client->login($user, $passwd);
3321 $client->type('binary');
3322
3323 eval { $client->size("tmp\\test.txt") };
3324 unless ($@) {
3325 die("SIZE succeeded unexpectedly");
3326
3327 } else {
3328 $resp_code = $client->response_code();
3329 $resp_msg = $client->response_msg();
3330 }
3331
3332 my $expected;
3333
3334 $expected = 550;
3335 $self->assert($expected == $resp_code,
3336 test_msg("Expected $expected, got $resp_code"));
3337
3338 $expected = 'tmp/test.txt: No such file or directory';
3339 $self->assert(qr/$expected/, $resp_msg,
3340 test_msg("Expected '$expected', got '$resp_msg'"));
3341 };
3342
3343 if ($@) {
3344 $ex = $@;
3345 }
3346
3347 $wfh->print("done\n");
3348 $wfh->flush();
3349
3350 } else {
3351 eval { server_wait($config_file, $rfh) };
3352 if ($@) {
3353 warn($@);
3354 exit 1;
3355 }
3356
3357 exit 0;
3358 }
3359
3360 # Stop server
3361 server_stop($pid_file);
3362
3363 $self->assert_child_ok($pid);
3364
3365 if ($ex) {
3366 test_append_logfile($log_file, $ex);
3367 unlink($log_file);
3368
3369 die($ex);
3370 }
3371
3372 unlink($log_file);
3373 }
3374
3375 sub rewrite_map_max_replace_bug3721 {
3376 my $self = shift;
3377 my $tmpdir = $self->{tmpdir};
3378
3379 my $config_file = "$tmpdir/rewrite.conf";
3380 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
3381 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
3382
3383 my $log_file = test_get_logfile();
3384
3385 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
3386 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
3387
3388 my $user = 'proftpd';
3389 my $passwd = 'test';
3390 my $group = 'ftpd';
3391 my $home_dir = File::Spec->rel2abs($tmpdir);
3392 my $uid = 500;
3393 my $gid = 500;
3394
3395 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
3396 mkpath($sub_dir);
3397
3398 # For Bug#3721, we need to use a pattern which requires more replacements
3399 # than the default (8).
3400 my $cmd_file = 'fil e test 234.jpg';
3401 my $test_file = 'fil_______e_test_234.jpg';
3402 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
3403
3404 if (open(my $fh, "> $test_path")) {
3405 print $fh "Hello, World!\n";
3406
3407 unless (close($fh)) {
3408 die("Can't write $test_path: $!");
3409 }
3410
3411 } else {
3412 die("Can't open $test_path: $!");
3413 }
3414
3415 # Make sure that, if we're running as root, that the home directory has
3416 # permissions/privs set for the account we create
3417 if ($< == 0) {
3418 unless (chmod(0755, $home_dir, $sub_dir)) {
3419 die("Can't set perms on $home_dir to 0755: $!");
3420 }
3421
3422 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
3423 die("Can't set owner of $home_dir to $uid/$gid: $!");
3424 }
3425 }
3426
3427 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3428 '/bin/bash');
3429 auth_group_write($auth_group_file, $group, $gid, $user);
3430
3431 my $config = {
3432 PidFile => $pid_file,
3433 ScoreboardFile => $scoreboard_file,
3434 SystemLog => $log_file,
3435
3436 AuthUserFile => $auth_user_file,
3437 AuthGroupFile => $auth_group_file,
3438 AuthOrder => 'mod_auth_file.c',
3439
3440 IfModules => {
3441 'mod_delay.c' => {
3442 DelayEngine => 'off',
3443 },
3444
3445 'mod_rewrite.c' => [
3446 'RewriteEngine on',
3447 "RewriteLog $log_file",
3448
3449 'RewriteMap replace int:replaceall',
3450 'RewriteCondition %m SIZE',
3451 'RewriteRule ^(.*) "${replace:!$1! !_}"',
3452
3453 'RewriteMaxReplace 32',
3454 ],
3455 },
3456 };
3457
3458 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3459
3460 # Open pipes, for use between the parent and child processes. Specifically,
3461 # the child will indicate when it's done with its test by writing a message
3462 # to the parent.
3463 my ($rfh, $wfh);
3464 unless (pipe($rfh, $wfh)) {
3465 die("Can't open pipe: $!");
3466 }
3467
3468 my $ex;
3469
3470 # Fork child
3471 $self->handle_sigchld();
3472 defined(my $pid = fork()) or die("Can't fork: $!");
3473 if ($pid) {
3474 eval {
3475 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3476
3477 my ($resp_code, $resp_msg);
3478
3479 $client->login($user, $passwd);
3480 $client->type('binary');
3481
3482 # Send the path with spaces; the rewrite rules should handle it
3483 ($resp_code, $resp_msg) = $client->size("tmp/$cmd_file");
3484
3485 my $expected;
3486
3487 $expected = 213;
3488 $self->assert($expected == $resp_code,
3489 test_msg("Expected $expected, got $resp_code"));
3490
3491 $expected = '14';
3492 $self->assert($expected eq $resp_msg,
3493 test_msg("Expected '$expected', got '$resp_msg'"));
3494 };
3495
3496 if ($@) {
3497 $ex = $@;
3498 }
3499
3500 $wfh->print("done\n");
3501 $wfh->flush();
3502
3503 } else {
3504 eval { server_wait($config_file, $rfh) };
3505 if ($@) {
3506 warn($@);
3507 exit 1;
3508 }
3509
3510 exit 0;
3511 }
3512
3513 # Stop server
3514 server_stop($pid_file);
3515
3516 $self->assert_child_ok($pid);
3517
3518 if ($ex) {
3519 test_append_logfile($log_file, $ex);
3520 unlink($log_file);
3521
3522 die($ex);
3523 }
3524
3525 unlink($log_file);
3526 }
3527
3528 sub rewrite_cond_time_var_bug3673 {
3529 my $self = shift;
3530 my $tmpdir = $self->{tmpdir};
3531 my $setup = test_setup($tmpdir, 'rewrite');
3532
3533 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
3534 mkpath($sub_dir);
3535
3536 my $test_file = 'test_file_here.txt';
3537 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
3538
3539 if (open(my $fh, "> $test_path")) {
3540 print $fh "Hello, World!\n";
3541
3542 unless (close($fh)) {
3543 die("Can't write $test_path: $!");
3544 }
3545
3546 } else {
3547 die("Can't open $test_path: $!");
3548 }
3549
3550 # Make sure that, if we're running as root, that the home directory has
3551 # permissions/privs set for the account we create
3552 if ($< == 0) {
3553 unless (chmod(0755, $sub_dir)) {
3554 die("Can't set perms on $sub_dir to 0755: $!");
3555 }
3556
3557 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
3558 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
3559 }
3560 }
3561
3562 require DateTime;
3563
3564 my $dt = DateTime->now();
3565 $dt->set_time_zone('America/Los_Angeles');
3566 $dt->add(seconds => 30);
3567
3568 my $timestamp = ($dt->ymd('') . $dt->hms(''));
3569
3570 my $config = {
3571 PidFile => $setup->{pid_file},
3572 ScoreboardFile => $setup->{scoreboard_file},
3573 SystemLog => $setup->{log_file},
3574 TraceLog => $setup->{log_file},
3575 Trace => 'regexp:20 rewrite:20',
3576
3577 AuthUserFile => $setup->{auth_user_file},
3578 AuthGroupFile => $setup->{auth_group_file},
3579 AuthOrder => 'mod_auth_file.c',
3580
3581 IfModules => {
3582 'mod_delay.c' => {
3583 DelayEngine => 'off',
3584 },
3585
3586 'mod_rewrite.c' => [
3587 'RewriteEngine on',
3588 "RewriteLog $setup->{log_file}",
3589
3590 'RewriteMap replace int:replaceall',
3591
3592 'RewriteCondition %m SIZE',
3593 "RewriteCondition %{TIME} >$timestamp",
3594 'RewriteRule ^(.*) "${replace:!$1! !_}"',
3595 ],
3596 },
3597 };
3598
3599 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3600 $config);
3601
3602 # Open pipes, for use between the parent and child processes. Specifically,
3603 # the child will indicate when it's done with its test by writing a message
3604 # to the parent.
3605 my ($rfh, $wfh);
3606 unless (pipe($rfh, $wfh)) {
3607 die("Can't open pipe: $!");
3608 }
3609
3610 my $ex;
3611
3612 # Fork child
3613 $self->handle_sigchld();
3614 defined(my $pid = fork()) or die("Can't fork: $!");
3615 if ($pid) {
3616 eval {
3617 # Allow for server startup
3618 sleep(1);
3619
3620 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3621 $client->login($setup->{user}, $setup->{passwd});
3622 $client->type('binary');
3623
3624 # Send the path with spaces; the rewrite rules should handle it
3625 my ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
3626
3627 my $expected = 213;
3628 $self->assert($expected == $resp_code,
3629 test_msg("Expected response code $expected, got $resp_code"));
3630
3631 $expected = '14';
3632 $self->assert($expected eq $resp_msg,
3633 test_msg("Expected response message '$expected', got '$resp_msg'"));
3634
3635 $client->quit();
3636 };
3637 if ($@) {
3638 $ex = $@;
3639 }
3640
3641 $wfh->print("done\n");
3642 $wfh->flush();
3643
3644 } else {
3645 eval { server_wait($setup->{config_file}, $rfh) };
3646 if ($@) {
3647 warn($@);
3648 exit 1;
3649 }
3650
3651 exit 0;
3652 }
3653
3654 # Stop server
3655 server_stop($setup->{pid_file});
3656 $self->assert_child_ok($pid);
3657
3658 test_cleanup($setup->{log_file}, $ex);
3659 }
3660
3661 sub rewrite_cond_time_year_var_bug3673 {
3662 my $self = shift;
3663 my $tmpdir = $self->{tmpdir};
3664
3665 my $config_file = "$tmpdir/rewrite.conf";
3666 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
3667 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
3668
3669 my $log_file = test_get_logfile();
3670
3671 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
3672 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
3673
3674 my $user = 'proftpd';
3675 my $passwd = 'test';
3676 my $group = 'ftpd';
3677 my $home_dir = File::Spec->rel2abs($tmpdir);
3678 my $uid = 500;
3679 my $gid = 500;
3680
3681 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
3682 mkpath($sub_dir);
3683
3684 my $test_file = 'test_file_here.txt';
3685 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
3686
3687 if (open(my $fh, "> $test_path")) {
3688 print $fh "Hello, World!\n";
3689
3690 unless (close($fh)) {
3691 die("Can't write $test_path: $!");
3692 }
3693
3694 } else {
3695 die("Can't open $test_path: $!");
3696 }
3697
3698 # Make sure that, if we're running as root, that the home directory has
3699 # permissions/privs set for the account we create
3700 if ($< == 0) {
3701 unless (chmod(0755, $home_dir, $sub_dir)) {
3702 die("Can't set perms on $home_dir to 0755: $!");
3703 }
3704
3705 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
3706 die("Can't set owner of $home_dir to $uid/$gid: $!");
3707 }
3708 }
3709
3710 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3711 '/bin/bash');
3712 auth_group_write($auth_group_file, $group, $gid, $user);
3713
3714 require DateTime;
3715
3716 my $dt = DateTime->now();
3717 $dt->set_time_zone('America/Los_Angeles');
3718 my $timestamp = sprintf("%04d", $dt->year());
3719
3720 my $config = {
3721 PidFile => $pid_file,
3722 ScoreboardFile => $scoreboard_file,
3723 SystemLog => $log_file,
3724
3725 AuthUserFile => $auth_user_file,
3726 AuthGroupFile => $auth_group_file,
3727 AuthOrder => 'mod_auth_file.c',
3728
3729 IfModules => {
3730 'mod_delay.c' => {
3731 DelayEngine => 'off',
3732 },
3733
3734 'mod_rewrite.c' => [
3735 'RewriteEngine on',
3736 "RewriteLog $log_file",
3737
3738 'RewriteMap replace int:replaceall',
3739
3740 'RewriteCondition %m SIZE',
3741 "RewriteCondition %{TIME_YEAR} =$timestamp",
3742 'RewriteRule ^(.*) "${replace:!$1! !_}"',
3743 ],
3744 },
3745 };
3746
3747 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3748
3749 # Open pipes, for use between the parent and child processes. Specifically,
3750 # the child will indicate when it's done with its test by writing a message
3751 # to the parent.
3752 my ($rfh, $wfh);
3753 unless (pipe($rfh, $wfh)) {
3754 die("Can't open pipe: $!");
3755 }
3756
3757 my $ex;
3758
3759 # Fork child
3760 $self->handle_sigchld();
3761 defined(my $pid = fork()) or die("Can't fork: $!");
3762 if ($pid) {
3763 eval {
3764 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3765
3766 my ($resp_code, $resp_msg);
3767
3768 $client->login($user, $passwd);
3769 $client->type('binary');
3770
3771 # Send the path with spaces; the rewrite rules should handle it
3772 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
3773
3774 my $expected;
3775
3776 $expected = 213;
3777 $self->assert($expected == $resp_code,
3778 test_msg("Expected $expected, got $resp_code"));
3779
3780 $expected = '14';
3781 $self->assert($expected eq $resp_msg,
3782 test_msg("Expected '$expected', got '$resp_msg'"));
3783 };
3784
3785 if ($@) {
3786 $ex = $@;
3787 }
3788
3789 $wfh->print("done\n");
3790 $wfh->flush();
3791
3792 } else {
3793 eval { server_wait($config_file, $rfh) };
3794 if ($@) {
3795 warn($@);
3796 exit 1;
3797 }
3798
3799 exit 0;
3800 }
3801
3802 # Stop server
3803 server_stop($pid_file);
3804
3805 $self->assert_child_ok($pid);
3806
3807 if ($ex) {
3808 test_append_logfile($log_file, $ex);
3809 unlink($log_file);
3810
3811 die($ex);
3812 }
3813
3814 unlink($log_file);
3815 }
3816
3817 sub rewrite_cond_time_mon_var_bug3673 {
3818 my $self = shift;
3819 my $tmpdir = $self->{tmpdir};
3820
3821 my $config_file = "$tmpdir/rewrite.conf";
3822 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
3823 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
3824
3825 my $log_file = test_get_logfile();
3826
3827 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
3828 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
3829
3830 my $user = 'proftpd';
3831 my $passwd = 'test';
3832 my $group = 'ftpd';
3833 my $home_dir = File::Spec->rel2abs($tmpdir);
3834 my $uid = 500;
3835 my $gid = 500;
3836
3837 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
3838 mkpath($sub_dir);
3839
3840 my $test_file = 'test_file_here.txt';
3841 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
3842
3843 if (open(my $fh, "> $test_path")) {
3844 print $fh "Hello, World!\n";
3845
3846 unless (close($fh)) {
3847 die("Can't write $test_path: $!");
3848 }
3849
3850 } else {
3851 die("Can't open $test_path: $!");
3852 }
3853
3854 # Make sure that, if we're running as root, that the home directory has
3855 # permissions/privs set for the account we create
3856 if ($< == 0) {
3857 unless (chmod(0755, $home_dir, $sub_dir)) {
3858 die("Can't set perms on $home_dir to 0755: $!");
3859 }
3860
3861 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
3862 die("Can't set owner of $home_dir to $uid/$gid: $!");
3863 }
3864 }
3865
3866 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3867 '/bin/bash');
3868 auth_group_write($auth_group_file, $group, $gid, $user);
3869
3870 require DateTime;
3871
3872 my $dt = DateTime->now();
3873 $dt->set_time_zone('America/Los_Angeles');
3874 my $timestamp = sprintf("%02d", $dt->month());
3875
3876 my $config = {
3877 PidFile => $pid_file,
3878 ScoreboardFile => $scoreboard_file,
3879 SystemLog => $log_file,
3880
3881 AuthUserFile => $auth_user_file,
3882 AuthGroupFile => $auth_group_file,
3883 AuthOrder => 'mod_auth_file.c',
3884
3885 IfModules => {
3886 'mod_delay.c' => {
3887 DelayEngine => 'off',
3888 },
3889
3890 'mod_rewrite.c' => [
3891 'RewriteEngine on',
3892 "RewriteLog $log_file",
3893
3894 'RewriteMap replace int:replaceall',
3895
3896 'RewriteCondition %m SIZE',
3897 "RewriteCondition %{TIME_MON} =$timestamp",
3898 'RewriteRule ^(.*) "${replace:!$1! !_}"',
3899 ],
3900 },
3901 };
3902
3903 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3904
3905 # Open pipes, for use between the parent and child processes. Specifically,
3906 # the child will indicate when it's done with its test by writing a message
3907 # to the parent.
3908 my ($rfh, $wfh);
3909 unless (pipe($rfh, $wfh)) {
3910 die("Can't open pipe: $!");
3911 }
3912
3913 my $ex;
3914
3915 # Fork child
3916 $self->handle_sigchld();
3917 defined(my $pid = fork()) or die("Can't fork: $!");
3918 if ($pid) {
3919 eval {
3920 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3921
3922 my ($resp_code, $resp_msg);
3923
3924 $client->login($user, $passwd);
3925 $client->type('binary');
3926
3927 # Send the path with spaces; the rewrite rules should handle it
3928 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
3929
3930 my $expected;
3931
3932 $expected = 213;
3933 $self->assert($expected == $resp_code,
3934 test_msg("Expected $expected, got $resp_code"));
3935
3936 $expected = '14';
3937 $self->assert($expected eq $resp_msg,
3938 test_msg("Expected '$expected', got '$resp_msg'"));
3939 };
3940
3941 if ($@) {
3942 $ex = $@;
3943 }
3944
3945 $wfh->print("done\n");
3946 $wfh->flush();
3947
3948 } else {
3949 eval { server_wait($config_file, $rfh) };
3950 if ($@) {
3951 warn($@);
3952 exit 1;
3953 }
3954
3955 exit 0;
3956 }
3957
3958 # Stop server
3959 server_stop($pid_file);
3960
3961 $self->assert_child_ok($pid);
3962
3963 if ($ex) {
3964 test_append_logfile($log_file, $ex);
3965 unlink($log_file);
3966
3967 die($ex);
3968 }
3969
3970 unlink($log_file);
3971 }
3972
3973 sub rewrite_cond_time_day_var_bug3673 {
3974 my $self = shift;
3975 my $tmpdir = $self->{tmpdir};
3976
3977 my $config_file = "$tmpdir/rewrite.conf";
3978 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
3979 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
3980
3981 my $log_file = test_get_logfile();
3982
3983 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
3984 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
3985
3986 my $user = 'proftpd';
3987 my $passwd = 'test';
3988 my $group = 'ftpd';
3989 my $home_dir = File::Spec->rel2abs($tmpdir);
3990 my $uid = 500;
3991 my $gid = 500;
3992
3993 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
3994 mkpath($sub_dir);
3995
3996 my $test_file = 'test_file_here.txt';
3997 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
3998
3999 if (open(my $fh, "> $test_path")) {
4000 print $fh "Hello, World!\n";
4001
4002 unless (close($fh)) {
4003 die("Can't write $test_path: $!");
4004 }
4005
4006 } else {
4007 die("Can't open $test_path: $!");
4008 }
4009
4010 # Make sure that, if we're running as root, that the home directory has
4011 # permissions/privs set for the account we create
4012 if ($< == 0) {
4013 unless (chmod(0755, $home_dir, $sub_dir)) {
4014 die("Can't set perms on $home_dir to 0755: $!");
4015 }
4016
4017 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4018 die("Can't set owner of $home_dir to $uid/$gid: $!");
4019 }
4020 }
4021
4022 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4023 '/bin/bash');
4024 auth_group_write($auth_group_file, $group, $gid, $user);
4025
4026 require DateTime;
4027
4028 my $dt = DateTime->now();
4029 $dt->set_time_zone('America/Los_Angeles');
4030 my $timestamp = sprintf("%02d", $dt->day());
4031
4032 my $config = {
4033 PidFile => $pid_file,
4034 ScoreboardFile => $scoreboard_file,
4035 SystemLog => $log_file,
4036
4037 AuthUserFile => $auth_user_file,
4038 AuthGroupFile => $auth_group_file,
4039 AuthOrder => 'mod_auth_file.c',
4040
4041 IfModules => {
4042 'mod_delay.c' => {
4043 DelayEngine => 'off',
4044 },
4045
4046 'mod_rewrite.c' => [
4047 'RewriteEngine on',
4048 "RewriteLog $log_file",
4049
4050 'RewriteMap replace int:replaceall',
4051
4052 'RewriteCondition %m SIZE',
4053 "RewriteCondition %{TIME_DAY} =$timestamp",
4054 'RewriteRule ^(.*) "${replace:!$1! !_}"',
4055 ],
4056 },
4057 };
4058
4059 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4060
4061 # Open pipes, for use between the parent and child processes. Specifically,
4062 # the child will indicate when it's done with its test by writing a message
4063 # to the parent.
4064 my ($rfh, $wfh);
4065 unless (pipe($rfh, $wfh)) {
4066 die("Can't open pipe: $!");
4067 }
4068
4069 my $ex;
4070
4071 # Fork child
4072 $self->handle_sigchld();
4073 defined(my $pid = fork()) or die("Can't fork: $!");
4074 if ($pid) {
4075 eval {
4076 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4077
4078 my ($resp_code, $resp_msg);
4079
4080 $client->login($user, $passwd);
4081 $client->type('binary');
4082
4083 # Send the path with spaces; the rewrite rules should handle it
4084 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
4085
4086 my $expected;
4087
4088 $expected = 213;
4089 $self->assert($expected == $resp_code,
4090 test_msg("Expected $expected, got $resp_code"));
4091
4092 $expected = '14';
4093 $self->assert($expected eq $resp_msg,
4094 test_msg("Expected '$expected', got '$resp_msg'"));
4095 };
4096
4097 if ($@) {
4098 $ex = $@;
4099 }
4100
4101 $wfh->print("done\n");
4102 $wfh->flush();
4103
4104 } else {
4105 eval { server_wait($config_file, $rfh) };
4106 if ($@) {
4107 warn($@);
4108 exit 1;
4109 }
4110
4111 exit 0;
4112 }
4113
4114 # Stop server
4115 server_stop($pid_file);
4116
4117 $self->assert_child_ok($pid);
4118
4119 if ($ex) {
4120 test_append_logfile($log_file, $ex);
4121 unlink($log_file);
4122
4123 die($ex);
4124 }
4125
4126 unlink($log_file);
4127 }
4128
4129 sub rewrite_cond_time_wday_var_bug3673 {
4130 my $self = shift;
4131 my $tmpdir = $self->{tmpdir};
4132
4133 my $config_file = "$tmpdir/rewrite.conf";
4134 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
4135 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
4136
4137 my $log_file = test_get_logfile();
4138
4139 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
4140 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
4141
4142 my $user = 'proftpd';
4143 my $passwd = 'test';
4144 my $group = 'ftpd';
4145 my $home_dir = File::Spec->rel2abs($tmpdir);
4146 my $uid = 500;
4147 my $gid = 500;
4148
4149 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
4150 mkpath($sub_dir);
4151
4152 my $test_file = 'test_file_here.txt';
4153 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
4154
4155 if (open(my $fh, "> $test_path")) {
4156 print $fh "Hello, World!\n";
4157
4158 unless (close($fh)) {
4159 die("Can't write $test_path: $!");
4160 }
4161
4162 } else {
4163 die("Can't open $test_path: $!");
4164 }
4165
4166 # Make sure that, if we're running as root, that the home directory has
4167 # permissions/privs set for the account we create
4168 if ($< == 0) {
4169 unless (chmod(0755, $home_dir, $sub_dir)) {
4170 die("Can't set perms on $home_dir to 0755: $!");
4171 }
4172
4173 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4174 die("Can't set owner of $home_dir to $uid/$gid: $!");
4175 }
4176 }
4177
4178 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4179 '/bin/bash');
4180 auth_group_write($auth_group_file, $group, $gid, $user);
4181
4182 require DateTime;
4183
4184 my $dt = DateTime->now();
4185 $dt->set_time_zone('America/Los_Angeles');
4186 my $timestamp = sprintf("%02d", $dt->day_of_week());
4187
4188 my $config = {
4189 PidFile => $pid_file,
4190 ScoreboardFile => $scoreboard_file,
4191 SystemLog => $log_file,
4192
4193 AuthUserFile => $auth_user_file,
4194 AuthGroupFile => $auth_group_file,
4195 AuthOrder => 'mod_auth_file.c',
4196
4197 IfModules => {
4198 'mod_delay.c' => {
4199 DelayEngine => 'off',
4200 },
4201
4202 'mod_rewrite.c' => [
4203 'RewriteEngine on',
4204 "RewriteLog $log_file",
4205
4206 'RewriteMap replace int:replaceall',
4207
4208 'RewriteCondition %m SIZE',
4209 "RewriteCondition %{TIME_WDAY} =$timestamp",
4210 'RewriteRule ^(.*) "${replace:!$1! !_}"',
4211 ],
4212 },
4213 };
4214
4215 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4216
4217 # Open pipes, for use between the parent and child processes. Specifically,
4218 # the child will indicate when it's done with its test by writing a message
4219 # to the parent.
4220 my ($rfh, $wfh);
4221 unless (pipe($rfh, $wfh)) {
4222 die("Can't open pipe: $!");
4223 }
4224
4225 my $ex;
4226
4227 # Fork child
4228 $self->handle_sigchld();
4229 defined(my $pid = fork()) or die("Can't fork: $!");
4230 if ($pid) {
4231 eval {
4232 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4233
4234 my ($resp_code, $resp_msg);
4235
4236 $client->login($user, $passwd);
4237 $client->type('binary');
4238
4239 # Send the path with spaces; the rewrite rules should handle it
4240 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
4241
4242 my $expected;
4243
4244 $expected = 213;
4245 $self->assert($expected == $resp_code,
4246 test_msg("Expected $expected, got $resp_code"));
4247
4248 $expected = '14';
4249 $self->assert($expected eq $resp_msg,
4250 test_msg("Expected '$expected', got '$resp_msg'"));
4251 };
4252
4253 if ($@) {
4254 $ex = $@;
4255 }
4256
4257 $wfh->print("done\n");
4258 $wfh->flush();
4259
4260 } else {
4261 eval { server_wait($config_file, $rfh) };
4262 if ($@) {
4263 warn($@);
4264 exit 1;
4265 }
4266
4267 exit 0;
4268 }
4269
4270 # Stop server
4271 server_stop($pid_file);
4272
4273 $self->assert_child_ok($pid);
4274
4275 if ($ex) {
4276 test_append_logfile($log_file, $ex);
4277 unlink($log_file);
4278
4279 die($ex);
4280 }
4281
4282 unlink($log_file);
4283 }
4284
4285 sub rewrite_cond_time_hour_var_bug3673 {
4286 my $self = shift;
4287 my $tmpdir = $self->{tmpdir};
4288
4289 my $config_file = "$tmpdir/rewrite.conf";
4290 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
4291 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
4292
4293 my $log_file = test_get_logfile();
4294
4295 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
4296 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
4297
4298 my $user = 'proftpd';
4299 my $passwd = 'test';
4300 my $group = 'ftpd';
4301 my $home_dir = File::Spec->rel2abs($tmpdir);
4302 my $uid = 500;
4303 my $gid = 500;
4304
4305 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
4306 mkpath($sub_dir);
4307
4308 my $test_file = 'test_file_here.txt';
4309 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
4310
4311 if (open(my $fh, "> $test_path")) {
4312 print $fh "Hello, World!\n";
4313
4314 unless (close($fh)) {
4315 die("Can't write $test_path: $!");
4316 }
4317
4318 } else {
4319 die("Can't open $test_path: $!");
4320 }
4321
4322 # Make sure that, if we're running as root, that the home directory has
4323 # permissions/privs set for the account we create
4324 if ($< == 0) {
4325 unless (chmod(0755, $home_dir, $sub_dir)) {
4326 die("Can't set perms on $home_dir to 0755: $!");
4327 }
4328
4329 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4330 die("Can't set owner of $home_dir to $uid/$gid: $!");
4331 }
4332 }
4333
4334 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4335 '/bin/bash');
4336 auth_group_write($auth_group_file, $group, $gid, $user);
4337
4338 require DateTime;
4339
4340 my $dt = DateTime->now();
4341 $dt->set_time_zone('America/Los_Angeles');
4342 my $timestamp = sprintf("%02d", $dt->hour());
4343
4344 my $config = {
4345 PidFile => $pid_file,
4346 ScoreboardFile => $scoreboard_file,
4347 SystemLog => $log_file,
4348
4349 AuthUserFile => $auth_user_file,
4350 AuthGroupFile => $auth_group_file,
4351 AuthOrder => 'mod_auth_file.c',
4352
4353 IfModules => {
4354 'mod_delay.c' => {
4355 DelayEngine => 'off',
4356 },
4357
4358 'mod_rewrite.c' => [
4359 'RewriteEngine on',
4360 "RewriteLog $log_file",
4361
4362 'RewriteMap replace int:replaceall',
4363
4364 'RewriteCondition %m SIZE',
4365 "RewriteCondition %{TIME_HOUR} =$timestamp",
4366 'RewriteRule ^(.*) "${replace:!$1! !_}"',
4367 ],
4368 },
4369 };
4370
4371 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4372
4373 # Open pipes, for use between the parent and child processes. Specifically,
4374 # the child will indicate when it's done with its test by writing a message
4375 # to the parent.
4376 my ($rfh, $wfh);
4377 unless (pipe($rfh, $wfh)) {
4378 die("Can't open pipe: $!");
4379 }
4380
4381 my $ex;
4382
4383 # Fork child
4384 $self->handle_sigchld();
4385 defined(my $pid = fork()) or die("Can't fork: $!");
4386 if ($pid) {
4387 eval {
4388 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4389
4390 my ($resp_code, $resp_msg);
4391
4392 $client->login($user, $passwd);
4393 $client->type('binary');
4394
4395 # Send the path with spaces; the rewrite rules should handle it
4396 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
4397
4398 my $expected;
4399
4400 $expected = 213;
4401 $self->assert($expected == $resp_code,
4402 test_msg("Expected $expected, got $resp_code"));
4403
4404 $expected = '14';
4405 $self->assert($expected eq $resp_msg,
4406 test_msg("Expected '$expected', got '$resp_msg'"));
4407 };
4408
4409 if ($@) {
4410 $ex = $@;
4411 }
4412
4413 $wfh->print("done\n");
4414 $wfh->flush();
4415
4416 } else {
4417 eval { server_wait($config_file, $rfh) };
4418 if ($@) {
4419 warn($@);
4420 exit 1;
4421 }
4422
4423 exit 0;
4424 }
4425
4426 # Stop server
4427 server_stop($pid_file);
4428
4429 $self->assert_child_ok($pid);
4430
4431 if ($ex) {
4432 test_append_logfile($log_file, $ex);
4433 unlink($log_file);
4434
4435 die($ex);
4436 }
4437
4438 unlink($log_file);
4439 }
4440
4441 sub rewrite_cond_time_min_var_bug3673 {
4442 my $self = shift;
4443 my $tmpdir = $self->{tmpdir};
4444
4445 my $config_file = "$tmpdir/rewrite.conf";
4446 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
4447 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
4448
4449 my $log_file = test_get_logfile();
4450
4451 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
4452 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
4453
4454 my $user = 'proftpd';
4455 my $passwd = 'test';
4456 my $group = 'ftpd';
4457 my $home_dir = File::Spec->rel2abs($tmpdir);
4458 my $uid = 500;
4459 my $gid = 500;
4460
4461 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
4462 mkpath($sub_dir);
4463
4464 my $test_file = 'test_file_here.txt';
4465 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
4466
4467 if (open(my $fh, "> $test_path")) {
4468 print $fh "Hello, World!\n";
4469
4470 unless (close($fh)) {
4471 die("Can't write $test_path: $!");
4472 }
4473
4474 } else {
4475 die("Can't open $test_path: $!");
4476 }
4477
4478 # Make sure that, if we're running as root, that the home directory has
4479 # permissions/privs set for the account we create
4480 if ($< == 0) {
4481 unless (chmod(0755, $home_dir, $sub_dir)) {
4482 die("Can't set perms on $home_dir to 0755: $!");
4483 }
4484
4485 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4486 die("Can't set owner of $home_dir to $uid/$gid: $!");
4487 }
4488 }
4489
4490 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4491 '/bin/bash');
4492 auth_group_write($auth_group_file, $group, $gid, $user);
4493
4494 require DateTime;
4495
4496 my $dt = DateTime->now();
4497 $dt->set_time_zone('America/Los_Angeles');
4498 my $timestamp = sprintf("%02d", $dt->minute());
4499
4500 my $config = {
4501 PidFile => $pid_file,
4502 ScoreboardFile => $scoreboard_file,
4503 SystemLog => $log_file,
4504
4505 AuthUserFile => $auth_user_file,
4506 AuthGroupFile => $auth_group_file,
4507 AuthOrder => 'mod_auth_file.c',
4508
4509 IfModules => {
4510 'mod_delay.c' => {
4511 DelayEngine => 'off',
4512 },
4513
4514 'mod_rewrite.c' => [
4515 'RewriteEngine on',
4516 "RewriteLog $log_file",
4517
4518 'RewriteMap replace int:replaceall',
4519
4520 'RewriteCondition %m SIZE',
4521 "RewriteCondition %{TIME_MIN} =$timestamp",
4522 'RewriteRule ^(.*) "${replace:!$1! !_}"',
4523 ],
4524 },
4525 };
4526
4527 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4528
4529 # Open pipes, for use between the parent and child processes. Specifically,
4530 # the child will indicate when it's done with its test by writing a message
4531 # to the parent.
4532 my ($rfh, $wfh);
4533 unless (pipe($rfh, $wfh)) {
4534 die("Can't open pipe: $!");
4535 }
4536
4537 my $ex;
4538
4539 # Fork child
4540 $self->handle_sigchld();
4541 defined(my $pid = fork()) or die("Can't fork: $!");
4542 if ($pid) {
4543 eval {
4544 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4545
4546 my ($resp_code, $resp_msg);
4547
4548 $client->login($user, $passwd);
4549 $client->type('binary');
4550
4551 # Send the path with spaces; the rewrite rules should handle it
4552 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
4553
4554 my $expected;
4555
4556 $expected = 213;
4557 $self->assert($expected == $resp_code,
4558 test_msg("Expected $expected, got $resp_code"));
4559
4560 $expected = '14';
4561 $self->assert($expected eq $resp_msg,
4562 test_msg("Expected '$expected', got '$resp_msg'"));
4563 };
4564
4565 if ($@) {
4566 $ex = $@;
4567 }
4568
4569 $wfh->print("done\n");
4570 $wfh->flush();
4571
4572 } else {
4573 eval { server_wait($config_file, $rfh) };
4574 if ($@) {
4575 warn($@);
4576 exit 1;
4577 }
4578
4579 exit 0;
4580 }
4581
4582 # Stop server
4583 server_stop($pid_file);
4584
4585 $self->assert_child_ok($pid);
4586
4587 if ($ex) {
4588 test_append_logfile($log_file, $ex);
4589 unlink($log_file);
4590
4591 die($ex);
4592 }
4593
4594 unlink($log_file);
4595 }
4596
4597 sub rewrite_cond_time_sec_var_bug3673 {
4598 my $self = shift;
4599 my $tmpdir = $self->{tmpdir};
4600
4601 my $config_file = "$tmpdir/rewrite.conf";
4602 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
4603 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
4604
4605 my $log_file = test_get_logfile();
4606
4607 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
4608 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
4609
4610 my $user = 'proftpd';
4611 my $passwd = 'test';
4612 my $group = 'ftpd';
4613 my $home_dir = File::Spec->rel2abs($tmpdir);
4614 my $uid = 500;
4615 my $gid = 500;
4616
4617 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
4618 mkpath($sub_dir);
4619
4620 my $test_file = 'test_file_here.txt';
4621 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
4622
4623 if (open(my $fh, "> $test_path")) {
4624 print $fh "Hello, World!\n";
4625
4626 unless (close($fh)) {
4627 die("Can't write $test_path: $!");
4628 }
4629
4630 } else {
4631 die("Can't open $test_path: $!");
4632 }
4633
4634 # Make sure that, if we're running as root, that the home directory has
4635 # permissions/privs set for the account we create
4636 if ($< == 0) {
4637 unless (chmod(0755, $home_dir, $sub_dir)) {
4638 die("Can't set perms on $home_dir to 0755: $!");
4639 }
4640
4641 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4642 die("Can't set owner of $home_dir to $uid/$gid: $!");
4643 }
4644 }
4645
4646 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4647 '/bin/bash');
4648 auth_group_write($auth_group_file, $group, $gid, $user);
4649
4650 require DateTime;
4651
4652 my $dt = DateTime->now();
4653 $dt->set_time_zone('America/Los_Angeles');
4654 my $timestamp = sprintf("%02d", $dt->second());
4655
4656 my $config = {
4657 PidFile => $pid_file,
4658 ScoreboardFile => $scoreboard_file,
4659 SystemLog => $log_file,
4660
4661 AuthUserFile => $auth_user_file,
4662 AuthGroupFile => $auth_group_file,
4663 AuthOrder => 'mod_auth_file.c',
4664
4665 IfModules => {
4666 'mod_delay.c' => {
4667 DelayEngine => 'off',
4668 },
4669
4670 'mod_rewrite.c' => [
4671 'RewriteEngine on',
4672 "RewriteLog $log_file",
4673
4674 'RewriteMap replace int:replaceall',
4675
4676 'RewriteCondition %m SIZE',
4677 "RewriteCondition %{TIME_SEC} !=$timestamp",
4678 'RewriteRule ^(.*) "${replace:!$1! !_}"',
4679 ],
4680 },
4681 };
4682
4683 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4684
4685 # Open pipes, for use between the parent and child processes. Specifically,
4686 # the child will indicate when it's done with its test by writing a message
4687 # to the parent.
4688 my ($rfh, $wfh);
4689 unless (pipe($rfh, $wfh)) {
4690 die("Can't open pipe: $!");
4691 }
4692
4693 my $ex;
4694
4695 # Fork child
4696 $self->handle_sigchld();
4697 defined(my $pid = fork()) or die("Can't fork: $!");
4698 if ($pid) {
4699 eval {
4700 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4701
4702 my ($resp_code, $resp_msg);
4703
4704 $client->login($user, $passwd);
4705 $client->type('binary');
4706
4707 # Send the path with spaces; the rewrite rules should handle it
4708 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
4709
4710 my $expected;
4711
4712 $expected = 213;
4713 $self->assert($expected == $resp_code,
4714 test_msg("Expected $expected, got $resp_code"));
4715
4716 $expected = '14';
4717 $self->assert($expected eq $resp_msg,
4718 test_msg("Expected '$expected', got '$resp_msg'"));
4719 };
4720
4721 if ($@) {
4722 $ex = $@;
4723 }
4724
4725 $wfh->print("done\n");
4726 $wfh->flush();
4727
4728 } else {
4729 eval { server_wait($config_file, $rfh) };
4730 if ($@) {
4731 warn($@);
4732 exit 1;
4733 }
4734
4735 exit 0;
4736 }
4737
4738 # Stop server
4739 server_stop($pid_file);
4740
4741 $self->assert_child_ok($pid);
4742
4743 if ($ex) {
4744 test_append_logfile($log_file, $ex);
4745 unlink($log_file);
4746
4747 die($ex);
4748 }
4749
4750 unlink($log_file);
4751 }
4752
4753 sub rewrite_rule_time_year_var_bug3673 {
4754 my $self = shift;
4755 my $tmpdir = $self->{tmpdir};
4756
4757 my $config_file = "$tmpdir/rewrite.conf";
4758 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
4759 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
4760
4761 my $log_file = test_get_logfile();
4762
4763 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
4764 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
4765
4766 my $user = 'proftpd';
4767 my $passwd = 'test';
4768 my $group = 'ftpd';
4769 my $home_dir = File::Spec->rel2abs($tmpdir);
4770 my $uid = 500;
4771 my $gid = 500;
4772
4773 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
4774 mkpath($sub_dir);
4775
4776 require DateTime;
4777
4778 my $dt = DateTime->now();
4779 $dt->set_time_zone('America/Los_Angeles');
4780
4781 my $test_file = sprintf("%04d", $dt->year()) . '.txt';
4782 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
4783
4784 if (open(my $fh, "> $test_path")) {
4785 print $fh "Hello, World!\n";
4786
4787 unless (close($fh)) {
4788 die("Can't write $test_path: $!");
4789 }
4790
4791 } else {
4792 die("Can't open $test_path: $!");
4793 }
4794
4795 # Make sure that, if we're running as root, that the home directory has
4796 # permissions/privs set for the account we create
4797 if ($< == 0) {
4798 unless (chmod(0755, $home_dir, $sub_dir)) {
4799 die("Can't set perms on $home_dir to 0755: $!");
4800 }
4801
4802 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4803 die("Can't set owner of $home_dir to $uid/$gid: $!");
4804 }
4805 }
4806
4807 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4808 '/bin/bash');
4809 auth_group_write($auth_group_file, $group, $gid, $user);
4810
4811 my $config = {
4812 PidFile => $pid_file,
4813 ScoreboardFile => $scoreboard_file,
4814 SystemLog => $log_file,
4815
4816 AuthUserFile => $auth_user_file,
4817 AuthGroupFile => $auth_group_file,
4818 AuthOrder => 'mod_auth_file.c',
4819
4820 IfModules => {
4821 'mod_delay.c' => {
4822 DelayEngine => 'off',
4823 },
4824
4825 'mod_rewrite.c' => [
4826 'RewriteEngine on',
4827 "RewriteLog $log_file",
4828
4829 'RewriteCondition %m SIZE',
4830 'RewriteRule ^(.*) tmp/%{TIME_YEAR}.txt',
4831 ],
4832 },
4833 };
4834
4835 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4836
4837 # Open pipes, for use between the parent and child processes. Specifically,
4838 # the child will indicate when it's done with its test by writing a message
4839 # to the parent.
4840 my ($rfh, $wfh);
4841 unless (pipe($rfh, $wfh)) {
4842 die("Can't open pipe: $!");
4843 }
4844
4845 my $ex;
4846
4847 # Fork child
4848 $self->handle_sigchld();
4849 defined(my $pid = fork()) or die("Can't fork: $!");
4850 if ($pid) {
4851 eval {
4852 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4853
4854 my ($resp_code, $resp_msg);
4855
4856 $client->login($user, $passwd);
4857 $client->type('binary');
4858
4859 # Send the path with spaces; the rewrite rules should handle it
4860 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
4861
4862 my $expected;
4863
4864 $expected = 213;
4865 $self->assert($expected == $resp_code,
4866 test_msg("Expected $expected, got $resp_code"));
4867
4868 $expected = '14';
4869 $self->assert($expected eq $resp_msg,
4870 test_msg("Expected '$expected', got '$resp_msg'"));
4871 };
4872
4873 if ($@) {
4874 $ex = $@;
4875 }
4876
4877 $wfh->print("done\n");
4878 $wfh->flush();
4879
4880 } else {
4881 eval { server_wait($config_file, $rfh) };
4882 if ($@) {
4883 warn($@);
4884 exit 1;
4885 }
4886
4887 exit 0;
4888 }
4889
4890 # Stop server
4891 server_stop($pid_file);
4892
4893 $self->assert_child_ok($pid);
4894
4895 if ($ex) {
4896 test_append_logfile($log_file, $ex);
4897 unlink($log_file);
4898
4899 die($ex);
4900 }
4901
4902 unlink($log_file);
4903 }
4904
4905 sub rewrite_rule_time_mon_var_bug3673 {
4906 my $self = shift;
4907 my $tmpdir = $self->{tmpdir};
4908
4909 my $config_file = "$tmpdir/rewrite.conf";
4910 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
4911 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
4912
4913 my $log_file = test_get_logfile();
4914
4915 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
4916 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
4917
4918 my $user = 'proftpd';
4919 my $passwd = 'test';
4920 my $group = 'ftpd';
4921 my $home_dir = File::Spec->rel2abs($tmpdir);
4922 my $uid = 500;
4923 my $gid = 500;
4924
4925 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
4926 mkpath($sub_dir);
4927
4928 require DateTime;
4929
4930 my $dt = DateTime->now();
4931 $dt->set_time_zone('America/Los_Angeles');
4932
4933 my $test_file = sprintf("%02d", $dt->month()) . '.txt';
4934 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
4935
4936 if (open(my $fh, "> $test_path")) {
4937 print $fh "Hello, World!\n";
4938
4939 unless (close($fh)) {
4940 die("Can't write $test_path: $!");
4941 }
4942
4943 } else {
4944 die("Can't open $test_path: $!");
4945 }
4946
4947 # Make sure that, if we're running as root, that the home directory has
4948 # permissions/privs set for the account we create
4949 if ($< == 0) {
4950 unless (chmod(0755, $home_dir, $sub_dir)) {
4951 die("Can't set perms on $home_dir to 0755: $!");
4952 }
4953
4954 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
4955 die("Can't set owner of $home_dir to $uid/$gid: $!");
4956 }
4957 }
4958
4959 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4960 '/bin/bash');
4961 auth_group_write($auth_group_file, $group, $gid, $user);
4962
4963 my $config = {
4964 PidFile => $pid_file,
4965 ScoreboardFile => $scoreboard_file,
4966 SystemLog => $log_file,
4967
4968 AuthUserFile => $auth_user_file,
4969 AuthGroupFile => $auth_group_file,
4970 AuthOrder => 'mod_auth_file.c',
4971
4972 IfModules => {
4973 'mod_delay.c' => {
4974 DelayEngine => 'off',
4975 },
4976
4977 'mod_rewrite.c' => [
4978 'RewriteEngine on',
4979 "RewriteLog $log_file",
4980
4981 'RewriteCondition %m SIZE',
4982 'RewriteRule ^(.*) tmp/%{TIME_MON}.txt',
4983 ],
4984 },
4985 };
4986
4987 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4988
4989 # Open pipes, for use between the parent and child processes. Specifically,
4990 # the child will indicate when it's done with its test by writing a message
4991 # to the parent.
4992 my ($rfh, $wfh);
4993 unless (pipe($rfh, $wfh)) {
4994 die("Can't open pipe: $!");
4995 }
4996
4997 my $ex;
4998
4999 # Fork child
5000 $self->handle_sigchld();
5001 defined(my $pid = fork()) or die("Can't fork: $!");
5002 if ($pid) {
5003 eval {
5004 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5005
5006 my ($resp_code, $resp_msg);
5007
5008 $client->login($user, $passwd);
5009 $client->type('binary');
5010
5011 # Send the path with spaces; the rewrite rules should handle it
5012 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
5013
5014 my $expected;
5015
5016 $expected = 213;
5017 $self->assert($expected == $resp_code,
5018 test_msg("Expected $expected, got $resp_code"));
5019
5020 $expected = '14';
5021 $self->assert($expected eq $resp_msg,
5022 test_msg("Expected '$expected', got '$resp_msg'"));
5023 };
5024
5025 if ($@) {
5026 $ex = $@;
5027 }
5028
5029 $wfh->print("done\n");
5030 $wfh->flush();
5031
5032 } else {
5033 eval { server_wait($config_file, $rfh) };
5034 if ($@) {
5035 warn($@);
5036 exit 1;
5037 }
5038
5039 exit 0;
5040 }
5041
5042 # Stop server
5043 server_stop($pid_file);
5044
5045 $self->assert_child_ok($pid);
5046
5047 if ($ex) {
5048 test_append_logfile($log_file, $ex);
5049 unlink($log_file);
5050
5051 die($ex);
5052 }
5053
5054 unlink($log_file);
5055 }
5056
5057 sub rewrite_rule_time_day_var_bug3673 {
5058 my $self = shift;
5059 my $tmpdir = $self->{tmpdir};
5060
5061 my $config_file = "$tmpdir/rewrite.conf";
5062 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5063 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5064
5065 my $log_file = test_get_logfile();
5066
5067 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5068 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5069
5070 my $user = 'proftpd';
5071 my $passwd = 'test';
5072 my $group = 'ftpd';
5073 my $home_dir = File::Spec->rel2abs($tmpdir);
5074 my $uid = 500;
5075 my $gid = 500;
5076
5077 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
5078 mkpath($sub_dir);
5079
5080 require DateTime;
5081
5082 my $dt = DateTime->now();
5083 $dt->set_time_zone('America/Los_Angeles');
5084
5085 my $test_file = sprintf("%02d", $dt->day()) . '.txt';
5086 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
5087
5088 if (open(my $fh, "> $test_path")) {
5089 print $fh "Hello, World!\n";
5090
5091 unless (close($fh)) {
5092 die("Can't write $test_path: $!");
5093 }
5094
5095 } else {
5096 die("Can't open $test_path: $!");
5097 }
5098
5099 # Make sure that, if we're running as root, that the home directory has
5100 # permissions/privs set for the account we create
5101 if ($< == 0) {
5102 unless (chmod(0755, $home_dir, $sub_dir)) {
5103 die("Can't set perms on $home_dir to 0755: $!");
5104 }
5105
5106 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5107 die("Can't set owner of $home_dir to $uid/$gid: $!");
5108 }
5109 }
5110
5111 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5112 '/bin/bash');
5113 auth_group_write($auth_group_file, $group, $gid, $user);
5114
5115 my $config = {
5116 PidFile => $pid_file,
5117 ScoreboardFile => $scoreboard_file,
5118 SystemLog => $log_file,
5119
5120 AuthUserFile => $auth_user_file,
5121 AuthGroupFile => $auth_group_file,
5122 AuthOrder => 'mod_auth_file.c',
5123
5124 IfModules => {
5125 'mod_delay.c' => {
5126 DelayEngine => 'off',
5127 },
5128
5129 'mod_rewrite.c' => [
5130 'RewriteEngine on',
5131 "RewriteLog $log_file",
5132
5133 'RewriteCondition %m SIZE',
5134 'RewriteRule ^(.*) tmp/%{TIME_DAY}.txt',
5135 ],
5136 },
5137 };
5138
5139 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5140
5141 # Open pipes, for use between the parent and child processes. Specifically,
5142 # the child will indicate when it's done with its test by writing a message
5143 # to the parent.
5144 my ($rfh, $wfh);
5145 unless (pipe($rfh, $wfh)) {
5146 die("Can't open pipe: $!");
5147 }
5148
5149 my $ex;
5150
5151 # Fork child
5152 $self->handle_sigchld();
5153 defined(my $pid = fork()) or die("Can't fork: $!");
5154 if ($pid) {
5155 eval {
5156 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5157
5158 my ($resp_code, $resp_msg);
5159
5160 $client->login($user, $passwd);
5161 $client->type('binary');
5162
5163 # Send the path with spaces; the rewrite rules should handle it
5164 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
5165
5166 my $expected;
5167
5168 $expected = 213;
5169 $self->assert($expected == $resp_code,
5170 test_msg("Expected $expected, got $resp_code"));
5171
5172 $expected = '14';
5173 $self->assert($expected eq $resp_msg,
5174 test_msg("Expected '$expected', got '$resp_msg'"));
5175 };
5176
5177 if ($@) {
5178 $ex = $@;
5179 }
5180
5181 $wfh->print("done\n");
5182 $wfh->flush();
5183
5184 } else {
5185 eval { server_wait($config_file, $rfh) };
5186 if ($@) {
5187 warn($@);
5188 exit 1;
5189 }
5190
5191 exit 0;
5192 }
5193
5194 # Stop server
5195 server_stop($pid_file);
5196
5197 $self->assert_child_ok($pid);
5198
5199 if ($ex) {
5200 test_append_logfile($log_file, $ex);
5201 unlink($log_file);
5202
5203 die($ex);
5204 }
5205
5206 unlink($log_file);
5207 }
5208
5209 sub rewrite_rule_time_wday_var_bug3673 {
5210 my $self = shift;
5211 my $tmpdir = $self->{tmpdir};
5212
5213 my $config_file = "$tmpdir/rewrite.conf";
5214 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5215 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5216
5217 my $log_file = test_get_logfile();
5218
5219 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5220 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5221
5222 my $user = 'proftpd';
5223 my $passwd = 'test';
5224 my $group = 'ftpd';
5225 my $home_dir = File::Spec->rel2abs($tmpdir);
5226 my $uid = 500;
5227 my $gid = 500;
5228
5229 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
5230 mkpath($sub_dir);
5231
5232 require DateTime;
5233
5234 my $dt = DateTime->now();
5235 $dt->set_time_zone('America/Los_Angeles');
5236
5237 my $test_file = sprintf("%02d", $dt->day_of_week()) . '.txt';
5238 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
5239
5240 if (open(my $fh, "> $test_path")) {
5241 print $fh "Hello, World!\n";
5242
5243 unless (close($fh)) {
5244 die("Can't write $test_path: $!");
5245 }
5246
5247 } else {
5248 die("Can't open $test_path: $!");
5249 }
5250
5251 # Make sure that, if we're running as root, that the home directory has
5252 # permissions/privs set for the account we create
5253 if ($< == 0) {
5254 unless (chmod(0755, $home_dir, $sub_dir)) {
5255 die("Can't set perms on $home_dir to 0755: $!");
5256 }
5257
5258 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5259 die("Can't set owner of $home_dir to $uid/$gid: $!");
5260 }
5261 }
5262
5263 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5264 '/bin/bash');
5265 auth_group_write($auth_group_file, $group, $gid, $user);
5266
5267 my $config = {
5268 PidFile => $pid_file,
5269 ScoreboardFile => $scoreboard_file,
5270 SystemLog => $log_file,
5271
5272 AuthUserFile => $auth_user_file,
5273 AuthGroupFile => $auth_group_file,
5274 AuthOrder => 'mod_auth_file.c',
5275
5276 IfModules => {
5277 'mod_delay.c' => {
5278 DelayEngine => 'off',
5279 },
5280
5281 'mod_rewrite.c' => [
5282 'RewriteEngine on',
5283 "RewriteLog $log_file",
5284
5285 'RewriteCondition %m SIZE',
5286 'RewriteRule ^(.*) tmp/%{TIME_WDAY}.txt',
5287 ],
5288 },
5289 };
5290
5291 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5292
5293 # Open pipes, for use between the parent and child processes. Specifically,
5294 # the child will indicate when it's done with its test by writing a message
5295 # to the parent.
5296 my ($rfh, $wfh);
5297 unless (pipe($rfh, $wfh)) {
5298 die("Can't open pipe: $!");
5299 }
5300
5301 my $ex;
5302
5303 # Fork child
5304 $self->handle_sigchld();
5305 defined(my $pid = fork()) or die("Can't fork: $!");
5306 if ($pid) {
5307 eval {
5308 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5309
5310 my ($resp_code, $resp_msg);
5311
5312 $client->login($user, $passwd);
5313 $client->type('binary');
5314
5315 # Send the path with spaces; the rewrite rules should handle it
5316 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
5317
5318 my $expected;
5319
5320 $expected = 213;
5321 $self->assert($expected == $resp_code,
5322 test_msg("Expected $expected, got $resp_code"));
5323
5324 $expected = '14';
5325 $self->assert($expected eq $resp_msg,
5326 test_msg("Expected '$expected', got '$resp_msg'"));
5327 };
5328
5329 if ($@) {
5330 $ex = $@;
5331 }
5332
5333 $wfh->print("done\n");
5334 $wfh->flush();
5335
5336 } else {
5337 eval { server_wait($config_file, $rfh) };
5338 if ($@) {
5339 warn($@);
5340 exit 1;
5341 }
5342
5343 exit 0;
5344 }
5345
5346 # Stop server
5347 server_stop($pid_file);
5348
5349 $self->assert_child_ok($pid);
5350
5351 if ($ex) {
5352 test_append_logfile($log_file, $ex);
5353 unlink($log_file);
5354
5355 die($ex);
5356 }
5357
5358 unlink($log_file);
5359 }
5360
5361 sub rewrite_rule_time_hour_var_bug3673 {
5362 my $self = shift;
5363 my $tmpdir = $self->{tmpdir};
5364
5365 my $config_file = "$tmpdir/rewrite.conf";
5366 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5367 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5368
5369 my $log_file = test_get_logfile();
5370
5371 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5372 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5373
5374 my $user = 'proftpd';
5375 my $passwd = 'test';
5376 my $group = 'ftpd';
5377 my $home_dir = File::Spec->rel2abs($tmpdir);
5378 my $uid = 500;
5379 my $gid = 500;
5380
5381 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
5382 mkpath($sub_dir);
5383
5384 require DateTime;
5385
5386 my $dt = DateTime->now();
5387 $dt->set_time_zone('America/Los_Angeles');
5388
5389 my $test_file = sprintf("%02d", $dt->hour()) . '.txt';
5390 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
5391
5392 if (open(my $fh, "> $test_path")) {
5393 print $fh "Hello, World!\n";
5394
5395 unless (close($fh)) {
5396 die("Can't write $test_path: $!");
5397 }
5398
5399 } else {
5400 die("Can't open $test_path: $!");
5401 }
5402
5403 # Make sure that, if we're running as root, that the home directory has
5404 # permissions/privs set for the account we create
5405 if ($< == 0) {
5406 unless (chmod(0755, $home_dir, $sub_dir)) {
5407 die("Can't set perms on $home_dir to 0755: $!");
5408 }
5409
5410 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5411 die("Can't set owner of $home_dir to $uid/$gid: $!");
5412 }
5413 }
5414
5415 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5416 '/bin/bash');
5417 auth_group_write($auth_group_file, $group, $gid, $user);
5418
5419 my $config = {
5420 PidFile => $pid_file,
5421 ScoreboardFile => $scoreboard_file,
5422 SystemLog => $log_file,
5423
5424 AuthUserFile => $auth_user_file,
5425 AuthGroupFile => $auth_group_file,
5426 AuthOrder => 'mod_auth_file.c',
5427
5428 IfModules => {
5429 'mod_delay.c' => {
5430 DelayEngine => 'off',
5431 },
5432
5433 'mod_rewrite.c' => [
5434 'RewriteEngine on',
5435 "RewriteLog $log_file",
5436
5437 'RewriteCondition %m SIZE',
5438 'RewriteRule ^(.*) tmp/%{TIME_HOUR}.txt',
5439 ],
5440 },
5441 };
5442
5443 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5444
5445 # Open pipes, for use between the parent and child processes. Specifically,
5446 # the child will indicate when it's done with its test by writing a message
5447 # to the parent.
5448 my ($rfh, $wfh);
5449 unless (pipe($rfh, $wfh)) {
5450 die("Can't open pipe: $!");
5451 }
5452
5453 my $ex;
5454
5455 # Fork child
5456 $self->handle_sigchld();
5457 defined(my $pid = fork()) or die("Can't fork: $!");
5458 if ($pid) {
5459 eval {
5460 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5461
5462 my ($resp_code, $resp_msg);
5463
5464 $client->login($user, $passwd);
5465 $client->type('binary');
5466
5467 # Send the path with spaces; the rewrite rules should handle it
5468 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
5469
5470 my $expected;
5471
5472 $expected = 213;
5473 $self->assert($expected == $resp_code,
5474 test_msg("Expected $expected, got $resp_code"));
5475
5476 $expected = '14';
5477 $self->assert($expected eq $resp_msg,
5478 test_msg("Expected '$expected', got '$resp_msg'"));
5479 };
5480
5481 if ($@) {
5482 $ex = $@;
5483 }
5484
5485 $wfh->print("done\n");
5486 $wfh->flush();
5487
5488 } else {
5489 eval { server_wait($config_file, $rfh) };
5490 if ($@) {
5491 warn($@);
5492 exit 1;
5493 }
5494
5495 exit 0;
5496 }
5497
5498 # Stop server
5499 server_stop($pid_file);
5500
5501 $self->assert_child_ok($pid);
5502
5503 if ($ex) {
5504 test_append_logfile($log_file, $ex);
5505 unlink($log_file);
5506
5507 die($ex);
5508 }
5509
5510 unlink($log_file);
5511 }
5512
5513 sub rewrite_rule_time_min_var_bug3673 {
5514 my $self = shift;
5515 my $tmpdir = $self->{tmpdir};
5516
5517 my $config_file = "$tmpdir/rewrite.conf";
5518 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5519 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5520
5521 my $log_file = test_get_logfile();
5522
5523 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5524 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5525
5526 my $user = 'proftpd';
5527 my $passwd = 'test';
5528 my $group = 'ftpd';
5529 my $home_dir = File::Spec->rel2abs($tmpdir);
5530 my $uid = 500;
5531 my $gid = 500;
5532
5533 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
5534 mkpath($sub_dir);
5535
5536 require DateTime;
5537
5538 my $dt = DateTime->now();
5539 $dt->set_time_zone('America/Los_Angeles');
5540
5541 my $test_file = sprintf("%02d", $dt->minute()) . '.txt';
5542 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
5543
5544 if (open(my $fh, "> $test_path")) {
5545 print $fh "Hello, World!\n";
5546
5547 unless (close($fh)) {
5548 die("Can't write $test_path: $!");
5549 }
5550
5551 } else {
5552 die("Can't open $test_path: $!");
5553 }
5554
5555 # Make sure that, if we're running as root, that the home directory has
5556 # permissions/privs set for the account we create
5557 if ($< == 0) {
5558 unless (chmod(0755, $home_dir, $sub_dir)) {
5559 die("Can't set perms on $home_dir to 0755: $!");
5560 }
5561
5562 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5563 die("Can't set owner of $home_dir to $uid/$gid: $!");
5564 }
5565 }
5566
5567 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5568 '/bin/bash');
5569 auth_group_write($auth_group_file, $group, $gid, $user);
5570
5571 my $config = {
5572 PidFile => $pid_file,
5573 ScoreboardFile => $scoreboard_file,
5574 SystemLog => $log_file,
5575
5576 AuthUserFile => $auth_user_file,
5577 AuthGroupFile => $auth_group_file,
5578 AuthOrder => 'mod_auth_file.c',
5579
5580 IfModules => {
5581 'mod_delay.c' => {
5582 DelayEngine => 'off',
5583 },
5584
5585 'mod_rewrite.c' => [
5586 'RewriteEngine on',
5587 "RewriteLog $log_file",
5588
5589 'RewriteCondition %m SIZE',
5590 'RewriteRule ^(.*) tmp/%{TIME_MIN}.txt',
5591 ],
5592 },
5593 };
5594
5595 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5596
5597 # Open pipes, for use between the parent and child processes. Specifically,
5598 # the child will indicate when it's done with its test by writing a message
5599 # to the parent.
5600 my ($rfh, $wfh);
5601 unless (pipe($rfh, $wfh)) {
5602 die("Can't open pipe: $!");
5603 }
5604
5605 my $ex;
5606
5607 # Fork child
5608 $self->handle_sigchld();
5609 defined(my $pid = fork()) or die("Can't fork: $!");
5610 if ($pid) {
5611 eval {
5612 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5613
5614 my ($resp_code, $resp_msg);
5615
5616 $client->login($user, $passwd);
5617 $client->type('binary');
5618
5619 # Send the path with spaces; the rewrite rules should handle it
5620 ($resp_code, $resp_msg) = $client->size("tmp/test file here.txt");
5621
5622 my $expected;
5623
5624 $expected = 213;
5625 $self->assert($expected == $resp_code,
5626 test_msg("Expected $expected, got $resp_code"));
5627
5628 $expected = '14';
5629 $self->assert($expected eq $resp_msg,
5630 test_msg("Expected '$expected', got '$resp_msg'"));
5631 };
5632
5633 if ($@) {
5634 $ex = $@;
5635 }
5636
5637 $wfh->print("done\n");
5638 $wfh->flush();
5639
5640 } else {
5641 eval { server_wait($config_file, $rfh) };
5642 if ($@) {
5643 warn($@);
5644 exit 1;
5645 }
5646
5647 exit 0;
5648 }
5649
5650 # Stop server
5651 server_stop($pid_file);
5652
5653 $self->assert_child_ok($pid);
5654
5655 if ($ex) {
5656 test_append_logfile($log_file, $ex);
5657 unlink($log_file);
5658
5659 die($ex);
5660 }
5661
5662 unlink($log_file);
5663 }
5664
5665 sub rewrite_bug3767 {
5666 my $self = shift;
5667 my $tmpdir = $self->{tmpdir};
5668
5669 my $config_file = "$tmpdir/rewrite.conf";
5670 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5671 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5672
5673 my $log_file = test_get_logfile();
5674
5675 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5676 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5677
5678 my $user = 'proftpd';
5679 my $passwd = 'test';
5680 my $group = 'ftpd';
5681 my $home_dir = File::Spec->rel2abs($tmpdir);
5682 my $uid = 500;
5683 my $gid = 500;
5684
5685 my $sub_dir = File::Spec->rel2abs("$tmpdir/tmp");
5686 mkpath($sub_dir);
5687
5688 my $test_file = 'test.txt';
5689 my $test_path = File::Spec->rel2abs("$tmpdir/tmp/$test_file");
5690
5691 if (open(my $fh, "> $test_path")) {
5692 close($fh);
5693
5694 } else {
5695 die("Can't open $test_path: $!");
5696 }
5697
5698 # Make sure that, if we're running as root, that the home directory has
5699 # permissions/privs set for the account we create
5700 if ($< == 0) {
5701 unless (chmod(0755, $home_dir, $sub_dir)) {
5702 die("Can't set perms on $home_dir to 0755: $!");
5703 }
5704
5705 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
5706 die("Can't set owner of $home_dir to $uid/$gid: $!");
5707 }
5708 }
5709
5710 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5711 '/bin/bash');
5712 auth_group_write($auth_group_file, $group, $gid, $user);
5713
5714 my $config = {
5715 PidFile => $pid_file,
5716 ScoreboardFile => $scoreboard_file,
5717 SystemLog => $log_file,
5718
5719 AuthUserFile => $auth_user_file,
5720 AuthGroupFile => $auth_group_file,
5721 AuthOrder => 'mod_auth_file.c',
5722
5723 IfModules => {
5724 'mod_delay.c' => {
5725 DelayEngine => 'off',
5726 },
5727
5728 'mod_rewrite.c' => [
5729 'RewriteEngine on',
5730 "RewriteLog $log_file",
5731 'RewriteMap replace int:replaceall',
5732 'RewriteCondition %m STOR',
5733 'RewriteRule ^(.*) "${replace:!$1!ABC!DEF}"',
5734 ],
5735 },
5736 };
5737
5738 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5739
5740 # Open pipes, for use between the parent and child processes. Specifically,
5741 # the child will indicate when it's done with its test by writing a message
5742 # to the parent.
5743 my ($rfh, $wfh);
5744 unless (pipe($rfh, $wfh)) {
5745 die("Can't open pipe: $!");
5746 }
5747
5748 my $ex;
5749
5750 # Fork child
5751 $self->handle_sigchld();
5752 defined(my $pid = fork()) or die("Can't fork: $!");
5753 if ($pid) {
5754 eval {
5755 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5756 $client->login($user, $passwd);
5757
5758 eval { $client->site("chgrp") };
5759 unless ($@) {
5760 die("SITE CHGRP succeeded unexpectedly");
5761 }
5762
5763 my $resp_code = $client->response_code();
5764 my $resp_msg = $client->response_msg();
5765
5766 my $expected;
5767
5768 $expected = 500;
5769 $self->assert($expected == $resp_code,
5770 test_msg("Expected response code $expected, got $resp_code"));
5771
5772 $expected = "SITE not understood";
5773 $self->assert($expected eq $resp_msg,
5774 test_msg("Expected response message '$expected', got '$resp_msg'"));
5775 };
5776
5777 if ($@) {
5778 $ex = $@;
5779 }
5780
5781 $wfh->print("done\n");
5782 $wfh->flush();
5783
5784 } else {
5785 eval { server_wait($config_file, $rfh) };
5786 if ($@) {
5787 warn($@);
5788 exit 1;
5789 }
5790
5791 exit 0;
5792 }
5793
5794 # Stop server
5795 server_stop($pid_file);
5796
5797 $self->assert_child_ok($pid);
5798
5799 if ($ex) {
5800 test_append_logfile($log_file, $ex);
5801 unlink($log_file);
5802
5803 die($ex);
5804 }
5805
5806 unlink($log_file);
5807 }
5808
5809 sub rewrite_bug4017 {
5810 my $self = shift;
5811 my $tmpdir = $self->{tmpdir};
5812
5813 my $config_file = "$tmpdir/rewrite.conf";
5814 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5815 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5816
5817 my $log_file = test_get_logfile();
5818
5819 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5820 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5821
5822 my $user = 'proftpd';
5823 my $passwd = 'test';
5824 my $group = 'ftpd';
5825 my $home_dir = File::Spec->rel2abs($tmpdir);
5826 my $uid = 500;
5827 my $gid = 500;
5828
5829 my $test_dir = File::Spec->rel2abs("$tmpdir/foo.d");
5830 mkpath($test_dir);
5831
5832 # Make sure that, if we're running as root, that the home directory has
5833 # permissions/privs set for the account we create
5834 if ($< == 0) {
5835 unless (chmod(0755, $home_dir)) {
5836 die("Can't set perms on $home_dir to 0755: $!");
5837 }
5838
5839 unless (chown($uid, $gid, $home_dir)) {
5840 die("Can't set owner of $home_dir to $uid/$gid: $!");
5841 }
5842 }
5843
5844 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5845 '/bin/bash');
5846 auth_group_write($auth_group_file, $group, $gid, $user);
5847
5848 my $config = {
5849 PidFile => $pid_file,
5850 ScoreboardFile => $scoreboard_file,
5851 SystemLog => $log_file,
5852
5853 AuthUserFile => $auth_user_file,
5854 AuthGroupFile => $auth_group_file,
5855 AuthOrder => 'mod_auth_file.c',
5856
5857 DefaultRoot => '~',
5858
5859 IfModules => {
5860 'mod_delay.c' => {
5861 DelayEngine => 'off',
5862 },
5863
5864 'mod_rewrite.c' => [
5865 'RewriteEngine on',
5866 "RewriteLog $log_file",
5867 'RewriteMap replace int:replaceall',
5868
5869 'RewriteCondition %m !PASS',
5870 'RewriteCondition %m !USER',
5871 'RewriteRule (^/[^\\\\]*\\\\) /$1',
5872
5873 'RewriteCondition %m !PASS',
5874 'RewriteCondition %m !USER',
5875 'RewriteRule (.*) ${replace:!$1!\\!/}',
5876 ],
5877 },
5878 };
5879
5880 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5881
5882 # Open pipes, for use between the parent and child processes. Specifically,
5883 # the child will indicate when it's done with its test by writing a message
5884 # to the parent.
5885 my ($rfh, $wfh);
5886 unless (pipe($rfh, $wfh)) {
5887 die("Can't open pipe: $!");
5888 }
5889
5890 my $ex;
5891
5892 # Fork child
5893 $self->handle_sigchld();
5894 defined(my $pid = fork()) or die("Can't fork: $!");
5895 if ($pid) {
5896 eval {
5897 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5898 $client->login($user, $passwd);
5899
5900 my ($resp_code, $resp_msg) = $client->stat('/foo.d/\bar.d/\baz.d');
5901
5902 my $expected;
5903
5904 $expected = 211;
5905 $self->assert($expected == $resp_code,
5906 test_msg("Expected response code $expected, got $resp_code"));
5907
5908 ($resp_code, $resp_msg) = $client->stat('/foo.d\bar.d/\baz.d');
5909
5910 $self->assert($expected == $resp_code,
5911 test_msg("Expected response code $expected, got $resp_code"));
5912
5913 $client->quit();
5914 };
5915
5916 if ($@) {
5917 $ex = $@;
5918 }
5919
5920 $wfh->print("done\n");
5921 $wfh->flush();
5922
5923 } else {
5924 eval { server_wait($config_file, $rfh) };
5925 if ($@) {
5926 warn($@);
5927 exit 1;
5928 }
5929
5930 exit 0;
5931 }
5932
5933 # Stop server
5934 server_stop($pid_file);
5935
5936 $self->assert_child_ok($pid);
5937
5938 if ($ex) {
5939 test_append_logfile($log_file, $ex);
5940 unlink($log_file);
5941
5942 die($ex);
5943 }
5944
5945 unlink($log_file);
5946 }
5947
5948 sub rewrite_using_pcre_bug4017 {
5949 my $self = shift;
5950 my $tmpdir = $self->{tmpdir};
5951
5952 my $config_file = "$tmpdir/rewrite.conf";
5953 my $pid_file = File::Spec->rel2abs("$tmpdir/rewrite.pid");
5954 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/rewrite.scoreboard");
5955
5956 my $log_file = test_get_logfile();
5957
5958 my $auth_user_file = File::Spec->rel2abs("$tmpdir/rewrite.passwd");
5959 my $auth_group_file = File::Spec->rel2abs("$tmpdir/rewrite.group");
5960
5961 my $user = 'proftpd';
5962 my $passwd = 'test';
5963 my $group = 'ftpd';
5964 my $home_dir = File::Spec->rel2abs($tmpdir);
5965 my $uid = 500;
5966 my $gid = 500;
5967
5968 my $test_dir = File::Spec->rel2abs("$tmpdir/foo.d");
5969 mkpath($test_dir);
5970
5971 # Make sure that, if we're running as root, that the home directory has
5972 # permissions/privs set for the account we create
5973 if ($< == 0) {
5974 unless (chmod(0755, $home_dir)) {
5975 die("Can't set perms on $home_dir to 0755: $!");
5976 }
5977
5978 unless (chown($uid, $gid, $home_dir)) {
5979 die("Can't set owner of $home_dir to $uid/$gid: $!");
5980 }
5981 }
5982
5983 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5984 '/bin/bash');
5985 auth_group_write($auth_group_file, $group, $gid, $user);
5986
5987 my $config = {
5988 PidFile => $pid_file,
5989 ScoreboardFile => $scoreboard_file,
5990 SystemLog => $log_file,
5991
5992 AuthUserFile => $auth_user_file,
5993 AuthGroupFile => $auth_group_file,
5994 AuthOrder => 'mod_auth_file.c',
5995
5996 DefaultRoot => '~',
5997
5998 IfModules => {
5999 'mod_delay.c' => {
6000 DelayEngine => 'off',
6001 },
6002
6003 'mod_rewrite.c' => [
6004 'RewriteEngine on',
6005 "RewriteLog $log_file",
6006 'RewriteMap replace int:replaceall',
6007
6008 'RewriteCondition %m !PASS',
6009 'RewriteCondition %m !USER',
6010 'RewriteRule ^(.*?\\/\\\\)(.*) /$1',
6011
6012 'RewriteCondition %m !PASS',
6013 'RewriteCondition %m !USER',
6014 'RewriteRule (.*) ${replace:!$1!\\!/}',
6015 ],
6016 },
6017 };
6018
6019 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6020
6021 # Open pipes, for use between the parent and child processes. Specifically,
6022 # the child will indicate when it's done with its test by writing a message
6023 # to the parent.
6024 my ($rfh, $wfh);
6025 unless (pipe($rfh, $wfh)) {
6026 die("Can't open pipe: $!");
6027 }
6028
6029 my $ex;
6030
6031 # Fork child
6032 $self->handle_sigchld();
6033 defined(my $pid = fork()) or die("Can't fork: $!");
6034 if ($pid) {
6035 eval {
6036 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6037 $client->login($user, $passwd);
6038
6039 my ($resp_code, $resp_msg) = $client->stat("/foo.d/\\bar.d/\\baz.d");
6040
6041 my $expected;
6042
6043 $expected = 211;
6044 $self->assert($expected == $resp_code,
6045 test_msg("Expected response code $expected, got $resp_code"));
6046
6047 $client->quit();
6048 };
6049
6050 if ($@) {
6051 $ex = $@;
6052 }
6053
6054 $wfh->print("done\n");
6055 $wfh->flush();
6056
6057 } else {
6058 eval { server_wait($config_file, $rfh) };
6059 if ($@) {
6060 warn($@);
6061 exit 1;
6062 }
6063
6064 exit 0;
6065 }
6066
6067 # Stop server
6068 server_stop($pid_file);
6069
6070 $self->assert_child_ok($pid);
6071
6072 if ($ex) {
6073 test_append_logfile($log_file, $ex);
6074 unlink($log_file);
6075
6076 die($ex);
6077 }
6078
6079 unlink($log_file);
6080 }
6081
6082 sub rewrite_using_pcre_issue1300 {
6083 my $self = shift;
6084 my $tmpdir = $self->{tmpdir};
6085 my $setup = test_setup($tmpdir, 'rewrite');
6086
6087 my $test_dir = File::Spec->rel2abs("$tmpdir/folder1/folder2");
6088 mkpath($test_dir);
6089
6090 my $config = {
6091 PidFile => $setup->{pid_file},
6092 ScoreboardFile => $setup->{scoreboard_file},
6093 SystemLog => $setup->{log_file},
6094 TraceLog => $setup->{log_file},
6095 Trace => 'regexp:20 rewrite:20',
6096
6097 AuthUserFile => $setup->{auth_user_file},
6098 AuthGroupFile => $setup->{auth_group_file},
6099 AuthOrder => 'mod_auth_file.c',
6100
6101 DefaultChdir => '~',
6102 DenyFilter => '\*.*/',
6103
6104 IfModules => {
6105 'mod_delay.c' => {
6106 DelayEngine => 'off',
6107 },
6108
6109 'mod_rewrite.c' => [
6110 'RewriteEngine on',
6111 "RewriteLog $setup->{log_file}",
6112 'RewriteMap replace int:replaceall',
6113
6114 'RewriteCondition %m RETR|SIZE|LIST|CWD',
6115 'RewriteRule (.*) "${replace:!$1!\\\\!/}"',
6116 ],
6117 },
6118 };
6119
6120 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6121 $config);
6122
6123 # Open pipes, for use between the parent and child processes. Specifically,
6124 # the child will indicate when it's done with its test by writing a message
6125 # to the parent.
6126 my ($rfh, $wfh);
6127 unless (pipe($rfh, $wfh)) {
6128 die("Can't open pipe: $!");
6129 }
6130
6131 my $ex;
6132
6133 # Fork child
6134 $self->handle_sigchld();
6135 defined(my $pid = fork()) or die("Can't fork: $!");
6136 if ($pid) {
6137 eval {
6138 # Allow server to start up
6139 sleep(1);
6140
6141 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6142 $client->login($setup->{user}, $setup->{passwd});
6143
6144 my ($resp_code, $resp_msg) = $client->cwd('folder1\folder2');
6145
6146 my $expected = 250;
6147 $self->assert($expected == $resp_code,
6148 test_msg("Expected response code $expected, got $resp_code"));
6149
6150 $client->quit();
6151 };
6152 if ($@) {
6153 $ex = $@;
6154 }
6155
6156 $wfh->print("done\n");
6157 $wfh->flush();
6158
6159 } else {
6160 eval { server_wait($setup->{config_file}, $rfh) };
6161 if ($@) {
6162 warn($@);
6163 exit 1;
6164 }
6165
6166 exit 0;
6167 }
6168
6169 # Stop server
6170 server_stop($setup->{pid_file});
6171 $self->assert_child_ok($pid);
6172
6173 test_cleanup($setup->{log_file}, $ex);
6174 }
6175
6176 sub rewrite_rule_missing_condition_bug4495 {
6177 my $self = shift;
6178 my $tmpdir = $self->{tmpdir};
6179 my $setup = test_setup($tmpdir, 'rewrite');
6180
6181 my $config = {
6182 PidFile => $setup->{pid_file},
6183 ScoreboardFile => $setup->{scoreboard_file},
6184 SystemLog => $setup->{log_file},
6185
6186 AuthUserFile => $setup->{auth_user_file},
6187 AuthGroupFile => $setup->{auth_group_file},
6188 AuthOrder => 'mod_auth_file.c',
6189
6190 IfModules => {
6191 'mod_delay.c' => {
6192 DelayEngine => 'off',
6193 },
6194
6195 'mod_rewrite.c' => [
6196 'RewriteEngine on',
6197 "RewriteLog $setup->{log_file}",
6198
6199 'RewriteMap replace int:replaceall',
6200 'RewriteCondition %m STOR',
6201 'RewriteMaxReplace 60',
6202
6203 # We now expect this to fail parsing, since the second RewriteRule
6204 # lacks a RewriteCondition.
6205 'RewriteRule ^(.*) ${replace:/$1/\//-}',
6206 'RewriteRule ^(.*) ${replace:/$1/\}/-}',
6207 ],
6208 },
6209 };
6210
6211 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6212 $config);
6213
6214 my $ex;
6215
6216 eval { server_start($setup->{config_file}, $setup->{pid_file}) };
6217 unless ($@) {
6218 $ex = 'server started unexpectedly';
6219 }
6220
6221 test_cleanup($setup->{log_file}, $ex);
6222 }
6223
6224 sub rewrite_rule_with_matchall_condition_bug4495 {
6225 my $self = shift;
6226 my $tmpdir = $self->{tmpdir};
6227 my $setup = test_setup($tmpdir, 'rewrite');
6228
6229 my $config = {
6230 PidFile => $setup->{pid_file},
6231 ScoreboardFile => $setup->{scoreboard_file},
6232 SystemLog => $setup->{log_file},
6233
6234 AuthUserFile => $setup->{auth_user_file},
6235 AuthGroupFile => $setup->{auth_group_file},
6236 AuthOrder => 'mod_auth_file.c',
6237
6238 IfModules => {
6239 'mod_delay.c' => {
6240 DelayEngine => 'off',
6241 },
6242
6243 'mod_rewrite.c' => [
6244 'RewriteEngine on',
6245 "RewriteLog $setup->{log_file}",
6246
6247 'RewriteCondition %m .*',
6248 'RewriteMap lowercase int:tolower',
6249 'RewriteRule ^(.*) ${lowercase:$1}',
6250 ],
6251 },
6252 };
6253
6254 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6255 $config);
6256
6257 # Open pipes, for use between the parent and child processes. Specifically,
6258 # the child will indicate when it's done with its test by writing a message
6259 # to the parent.
6260 my ($rfh, $wfh);
6261 unless (pipe($rfh, $wfh)) {
6262 die("Can't open pipe: $!");
6263 }
6264
6265 my $ex;
6266
6267 # Fork child
6268 $self->handle_sigchld();
6269 defined(my $pid = fork()) or die("Can't fork: $!");
6270 if ($pid) {
6271 eval {
6272 # Allow for server startup
6273 sleep(1);
6274
6275 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
6276 $client->login(uc($setup->{user}), uc($setup->{passwd}));
6277
6278 my ($resp_code, $resp_msg) = $client->list();
6279 $client->quit();
6280
6281 my $expected = 226;
6282 $self->assert($expected == $resp_code,
6283 test_msg("Expected response code $expected, got $resp_code"));
6284
6285 $expected = 'Transfer complete';
6286 $self->assert($expected eq $resp_msg,
6287 test_msg("Expected response message '$expected', got '$resp_msg'"));
6288 };
6289 if ($@) {
6290 $ex = $@;
6291 }
6292
6293 $wfh->print("done\n");
6294 $wfh->flush();
6295
6296 } else {
6297 eval { server_wait($setup->{config_file}, $rfh) };
6298 if ($@) {
6299 warn($@);
6300 exit 1;
6301 }
6302
6303 exit 0;
6304 }
6305
6306 # Stop server
6307 server_stop($setup->{pid_file});
6308 $self->assert_child_ok($pid);
6309
6310 test_cleanup($setup->{log_file}, $ex);
6311 }
6312
6313 1;