Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Modules::mod_lang;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Copy;
8 use File::Path qw(mkpath);
9 use File::Spec;
10 use IO::Handle;
11
12 use ProFTPD::TestSuite::FTP;
13 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
14
15 $| = 1;
16
17 my $order = 0;
18
19 my $TESTS = {
20 lang_feat_default => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 lang_feat_engine_off => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 lang_lang_none_ok => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 lang_lang_env_ok => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 lang_lang_default_ok => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 lang_lang_unknown_failed => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 lang_opts_utf8_ok => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 lang_opts_utf8_nonbool_failed => {
56 order => ++$order,
57 test_class => [qw(forking)],
58 },
59
60 lang_lang_default_en_US => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 lang_lang_default_en_US_UTF8 => {
66 order => ++$order,
67 test_class => [qw(forking)],
68 },
69
70 lang_opts_utf8_useencoding_on => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 lang_opts_utf8_useencoding_off => {
76 order => ++$order,
77 test_class => [qw(forking)],
78 },
79
80 lang_opts_utf8_useencoding_charsets => {
81 order => ++$order,
82 test_class => [qw(forking)],
83 },
84
85 lang_opts_utf8_useencoding_charsets_strict => {
86 order => ++$order,
87 test_class => [qw(forking)],
88 },
89
90 lang_opts_utf8_useencoding_charsets_strict_with_utf8 => {
91 order => ++$order,
92 test_class => [qw(forking)],
93 },
94
95 lang_opts_utf8_useencoding_charsets_with_env => {
96 order => ++$order,
97 test_class => [qw(forking)],
98 },
99
100 lang_useencoding_latin1_utf8 => {
101 order => ++$order,
102 test_class => [qw(forking)],
103 },
104
105 lang_useencoding_utf8_latin1 => {
106 order => ++$order,
107 test_class => [qw(forking)],
108 },
109
110 lang_opts_utf8_prefer_server_encoding_bug4125 => {
111 order => ++$order,
112 test_class => [qw(bug forking)],
113 },
114
115 lang_opts_utf8_useencoding_charsets_prefer_server_encoding_bug4125 => {
116 order => ++$order,
117 test_class => [qw(bug forking)],
118 },
119
120 lang_useencoding_ascii_utf8_require_valid_encoding_bug4125 => {
121 order => ++$order,
122 test_class => [qw(bug forking)],
123 },
124
125 lang_useencoding_latin1_utf8_per_user_bug4214 => {
126 order => ++$order,
127 test_class => [qw(forking mod_ifsession)],
128 },
129
130 lang_useencoding_utf8_latin1_per_user_bug4214 => {
131 order => ++$order,
132 test_class => [qw(forking mod_ifsession)],
133 },
134
135 };
136
137 sub new {
138 return shift()->SUPER::new(@_);
139 }
140
141 sub list_tests {
142 return testsuite_get_runnable_tests($TESTS);
143 }
144
145 sub lang_feat_default {
146 my $self = shift;
147 my $tmpdir = $self->{tmpdir};
148
149 my $config_file = "$tmpdir/lang.conf";
150 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
151 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
152
153 my $log_file = test_get_logfile();
154
155 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
156 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
157
158 my $user = 'proftpd';
159 my $passwd = 'test';
160 my $group = 'ftpd';
161 my $home_dir = File::Spec->rel2abs($tmpdir);
162 my $uid = 500;
163 my $gid = 500;
164
165 # Make sure that, if we're running as root, that the home directory has
166 # permissions/privs set for the account we create
167 if ($< == 0) {
168 unless (chmod(0755, $home_dir)) {
169 die("Can't set perms on $home_dir to 0755: $!");
170 }
171
172 unless (chown($uid, $gid, $home_dir)) {
173 die("Can't set owner of $home_dir to $uid/$gid: $!");
174 }
175 }
176
177 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
178 '/bin/bash');
179 auth_group_write($auth_group_file, $group, $gid, $user);
180
181 my $config = {
182 PidFile => $pid_file,
183 ScoreboardFile => $scoreboard_file,
184 SystemLog => $log_file,
185
186 AuthUserFile => $auth_user_file,
187 AuthGroupFile => $auth_group_file,
188 AuthOrder => 'mod_auth_file.c',
189
190 IfModules => {
191 'mod_delay.c' => {
192 DelayEngine => 'off',
193 },
194 },
195 };
196
197 my ($port, $config_user, $config_group) = config_write($config_file, $config);
198
199 # Open pipes, for use between the parent and child processes. Specifically,
200 # the child will indicate when it's done with its test by writing a message
201 # to the parent.
202 my ($rfh, $wfh);
203 unless (pipe($rfh, $wfh)) {
204 die("Can't open pipe: $!");
205 }
206
207 my $ex;
208
209 # Fork child
210 $self->handle_sigchld();
211 defined(my $pid = fork()) or die("Can't fork: $!");
212 if ($pid) {
213 eval {
214 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
215 $client->login($user, $passwd);
216
217 $client->feat();
218 my $resp_code = $client->response_code();
219 my $resp_msgs = $client->response_msgs();
220
221 my $expected;
222
223 $expected = 211;
224 $self->assert($expected == $resp_code,
225 test_msg("Expected $expected, got $resp_code"));
226
227 my $feats = {
228 ' UTF8' => 1,
229
230 # One of the following will appear in the FEAT list, depending
231 # on the underlying platform.
232 ' LANG en_US' => 1,
233 ' LANG en-US' => 1,
234 ' LANG en-US*' => 1,
235 ' LANG en_US.UTF-8' => 1,
236 ' LANG en-US.UTF-8' => 1,
237 ' LANG en-US.UTF-8*' => 1,
238 };
239
240 my $seen = 0;
241
242 my $nfeat = scalar(@$resp_msgs);
243 for (my $i = 0; $i < $nfeat; $i++) {
244 if (defined($feats->{$resp_msgs->[$i]})) {
245 $seen++;
246 }
247 }
248
249 $expected = 2;
250 $self->assert($expected == $seen,
251 test_msg("Expected $expected, got $seen"));
252 };
253
254 if ($@) {
255 $ex = $@;
256 }
257
258 $wfh->print("done\n");
259 $wfh->flush();
260
261 } else {
262 eval { server_wait($config_file, $rfh) };
263 if ($@) {
264 warn($@);
265 exit 1;
266 }
267
268 exit 0;
269 }
270
271 # Stop server
272 server_stop($pid_file);
273
274 $self->assert_child_ok($pid);
275
276 if ($ex) {
277 test_append_logfile($log_file, $ex);
278 unlink($log_file);
279
280 die($ex);
281 }
282
283 unlink($log_file);
284 }
285
286 sub lang_feat_engine_off {
287 my $self = shift;
288 my $tmpdir = $self->{tmpdir};
289
290 my $config_file = "$tmpdir/lang.conf";
291 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
292 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
293
294 my $log_file = test_get_logfile();
295
296 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
297 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
298
299 my $user = 'proftpd';
300 my $passwd = 'test';
301 my $group = 'ftpd';
302 my $home_dir = File::Spec->rel2abs($tmpdir);
303 my $uid = 500;
304 my $gid = 500;
305
306 # Make sure that, if we're running as root, that the home directory has
307 # permissions/privs set for the account we create
308 if ($< == 0) {
309 unless (chmod(0755, $home_dir)) {
310 die("Can't set perms on $home_dir to 0755: $!");
311 }
312
313 unless (chown($uid, $gid, $home_dir)) {
314 die("Can't set owner of $home_dir to $uid/$gid: $!");
315 }
316 }
317
318 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
319 '/bin/bash');
320 auth_group_write($auth_group_file, $group, $gid, $user);
321
322 my $config = {
323 PidFile => $pid_file,
324 ScoreboardFile => $scoreboard_file,
325 SystemLog => $log_file,
326
327 AuthUserFile => $auth_user_file,
328 AuthGroupFile => $auth_group_file,
329 AuthOrder => 'mod_auth_file.c',
330
331 IfModules => {
332 'mod_delay.c' => {
333 DelayEngine => 'off',
334 },
335
336 'mod_lang.c' => {
337 LangEngine => 'off',
338 },
339 },
340 };
341
342 my ($port, $config_user, $config_group) = config_write($config_file, $config);
343
344 # Open pipes, for use between the parent and child processes. Specifically,
345 # the child will indicate when it's done with its test by writing a message
346 # to the parent.
347 my ($rfh, $wfh);
348 unless (pipe($rfh, $wfh)) {
349 die("Can't open pipe: $!");
350 }
351
352 my $ex;
353
354 # Fork child
355 $self->handle_sigchld();
356 defined(my $pid = fork()) or die("Can't fork: $!");
357 if ($pid) {
358 eval {
359 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
360 $client->login($user, $passwd);
361
362 $client->feat();
363 my $resp_code = $client->response_code();
364 my $resp_msgs = $client->response_msgs();
365
366 my $expected;
367
368 $expected = 211;
369 $self->assert($expected == $resp_code,
370 test_msg("Expected $expected, got $resp_code"));
371
372 my $feats = {
373 # None of the following should appear in the FEAT list
374
375 ' UTF8' => 1,
376 ' LANG en_US' => 1,
377 ' LANG en-US' => 1,
378 ' LANG en-US*' => 1,
379 ' LANG en_US.UTF-8' => 1,
380 ' LANG en-US.UTF-8' => 1,
381 ' LANG en-US.UTF-8*' => 1,
382 };
383
384 my $seen = 0;
385
386 my $nfeat = scalar(@$resp_msgs);
387 for (my $i = 0; $i < $nfeat; $i++) {
388 if (defined($feats->{$resp_msgs->[$i]})) {
389 $seen++;
390 }
391 }
392
393 $expected = 0;
394 $self->assert($expected == $seen,
395 test_msg("Expected $expected, got $seen"));
396 };
397
398 if ($@) {
399 $ex = $@;
400 }
401
402 $wfh->print("done\n");
403 $wfh->flush();
404
405 } else {
406 eval { server_wait($config_file, $rfh) };
407 if ($@) {
408 warn($@);
409 exit 1;
410 }
411
412 exit 0;
413 }
414
415 # Stop server
416 server_stop($pid_file);
417
418 $self->assert_child_ok($pid);
419
420 if ($ex) {
421 test_append_logfile($log_file, $ex);
422 unlink($log_file);
423
424 die($ex);
425 }
426
427 unlink($log_file);
428 }
429
430 sub lang_lang_none_ok {
431 my $self = shift;
432 my $tmpdir = $self->{tmpdir};
433
434 my $config_file = "$tmpdir/lang.conf";
435 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
436 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
437
438 my $log_file = test_get_logfile();
439
440 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
441 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
442
443 my $user = 'proftpd';
444 my $passwd = 'test';
445 my $group = 'ftpd';
446 my $home_dir = File::Spec->rel2abs($tmpdir);
447 my $uid = 500;
448 my $gid = 500;
449
450 # Make sure that, if we're running as root, that the home directory has
451 # permissions/privs set for the account we create
452 if ($< == 0) {
453 unless (chmod(0755, $home_dir)) {
454 die("Can't set perms on $home_dir to 0755: $!");
455 }
456
457 unless (chown($uid, $gid, $home_dir)) {
458 die("Can't set owner of $home_dir to $uid/$gid: $!");
459 }
460 }
461
462 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
463 '/bin/bash');
464 auth_group_write($auth_group_file, $group, $gid, $user);
465
466 my $config = {
467 PidFile => $pid_file,
468 ScoreboardFile => $scoreboard_file,
469 SystemLog => $log_file,
470
471 AuthUserFile => $auth_user_file,
472 AuthGroupFile => $auth_group_file,
473 AuthOrder => 'mod_auth_file.c',
474
475 IfModules => {
476 'mod_delay.c' => {
477 DelayEngine => 'off',
478 },
479 },
480 };
481
482 my ($port, $config_user, $config_group) = config_write($config_file, $config);
483
484 # Open pipes, for use between the parent and child processes. Specifically,
485 # the child will indicate when it's done with its test by writing a message
486 # to the parent.
487 my ($rfh, $wfh);
488 unless (pipe($rfh, $wfh)) {
489 die("Can't open pipe: $!");
490 }
491
492 my $ex;
493
494 # Fork child
495 $self->handle_sigchld();
496 defined(my $pid = fork()) or die("Can't fork: $!");
497 if ($pid) {
498 eval {
499 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
500
501 my ($resp_code, $resp_msg) = $client->lang();
502
503 my $expected;
504
505 $expected = 200;
506 $self->assert($expected == $resp_code,
507 test_msg("Expected $expected, got $resp_code"));
508
509 $expected = 'Using default language \S+';
510 $self->assert(qr/$expected/, $resp_msg,
511 test_msg("Expected '$expected', got '$resp_msg'"));
512 };
513
514 if ($@) {
515 $ex = $@;
516 }
517
518 $wfh->print("done\n");
519 $wfh->flush();
520
521 } else {
522 eval { server_wait($config_file, $rfh) };
523 if ($@) {
524 warn($@);
525 exit 1;
526 }
527
528 exit 0;
529 }
530
531 # Stop server
532 server_stop($pid_file);
533
534 $self->assert_child_ok($pid);
535
536 if ($ex) {
537 test_append_logfile($log_file, $ex);
538 unlink($log_file);
539
540 die($ex);
541 }
542
543 unlink($log_file);
544 }
545
546 sub lang_lang_env_ok {
547 my $self = shift;
548 my $tmpdir = $self->{tmpdir};
549
550 my $config_file = "$tmpdir/lang.conf";
551 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
552 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
553
554 my $log_file = test_get_logfile();
555
556 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
557 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
558
559 my $user = 'proftpd';
560 my $passwd = 'test';
561 my $group = 'ftpd';
562 my $home_dir = File::Spec->rel2abs($tmpdir);
563 my $uid = 500;
564 my $gid = 500;
565
566 # Make sure that, if we're running as root, that the home directory has
567 # permissions/privs set for the account we create
568 if ($< == 0) {
569 unless (chmod(0755, $home_dir)) {
570 die("Can't set perms on $home_dir to 0755: $!");
571 }
572
573 unless (chown($uid, $gid, $home_dir)) {
574 die("Can't set owner of $home_dir to $uid/$gid: $!");
575 }
576 }
577
578 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
579 '/bin/bash');
580 auth_group_write($auth_group_file, $group, $gid, $user);
581
582 my $config = {
583 PidFile => $pid_file,
584 ScoreboardFile => $scoreboard_file,
585 SystemLog => $log_file,
586
587 AuthUserFile => $auth_user_file,
588 AuthGroupFile => $auth_group_file,
589 AuthOrder => 'mod_auth_file.c',
590
591 IfModules => {
592 'mod_delay.c' => {
593 DelayEngine => 'off',
594 },
595 },
596 };
597
598 my ($port, $config_user, $config_group) = config_write($config_file, $config);
599
600 my $lang = 'en_US';
601
602 # Open pipes, for use between the parent and child processes. Specifically,
603 # the child will indicate when it's done with its test by writing a message
604 # to the parent.
605 my ($rfh, $wfh);
606 unless (pipe($rfh, $wfh)) {
607 die("Can't open pipe: $!");
608 }
609
610 my $ex;
611
612 # Fork child
613 $self->handle_sigchld();
614 defined(my $pid = fork()) or die("Can't fork: $!");
615 if ($pid) {
616 eval {
617 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
618
619 my ($resp_code, $resp_msg) = $client->lang();
620
621 my $expected;
622
623 $expected = 200;
624 $self->assert($expected == $resp_code,
625 test_msg("Expected $expected, got $resp_code"));
626
627 $expected = "Using default language $lang";
628 $self->assert(qr/$expected/, $resp_msg,
629 test_msg("Expected '$expected', got '$resp_msg'"));
630 };
631
632 if ($@) {
633 $ex = $@;
634 }
635
636 $wfh->print("done\n");
637 $wfh->flush();
638
639 } else {
640 # Specify a LANG environment variable, for mod_lang to pick up
641 $ENV{LANG} = $lang;
642
643 eval { server_wait($config_file, $rfh) };
644 if ($@) {
645 warn($@);
646 exit 1;
647 }
648
649 exit 0;
650 }
651
652 # Stop server
653 server_stop($pid_file);
654
655 $self->assert_child_ok($pid);
656
657 if ($ex) {
658 test_append_logfile($log_file, $ex);
659 unlink($log_file);
660
661 die($ex);
662 }
663
664 unlink($log_file);
665 }
666
667 sub lang_lang_default_ok {
668 my $self = shift;
669 my $tmpdir = $self->{tmpdir};
670
671 my $config_file = "$tmpdir/lang.conf";
672 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
673 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
674
675 my $log_file = test_get_logfile();
676
677 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
678 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
679
680 my $user = 'proftpd';
681 my $passwd = 'test';
682 my $group = 'ftpd';
683 my $home_dir = File::Spec->rel2abs($tmpdir);
684 my $uid = 500;
685 my $gid = 500;
686
687 # Make sure that, if we're running as root, that the home directory has
688 # permissions/privs set for the account we create
689 if ($< == 0) {
690 unless (chmod(0755, $home_dir)) {
691 die("Can't set perms on $home_dir to 0755: $!");
692 }
693
694 unless (chown($uid, $gid, $home_dir)) {
695 die("Can't set owner of $home_dir to $uid/$gid: $!");
696 }
697 }
698
699 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
700 '/bin/bash');
701 auth_group_write($auth_group_file, $group, $gid, $user);
702
703 my $config = {
704 PidFile => $pid_file,
705 ScoreboardFile => $scoreboard_file,
706 SystemLog => $log_file,
707
708 AuthUserFile => $auth_user_file,
709 AuthGroupFile => $auth_group_file,
710 AuthOrder => 'mod_auth_file.c',
711
712 IfModules => {
713 'mod_delay.c' => {
714 DelayEngine => 'off',
715 },
716 },
717 };
718
719 my ($port, $config_user, $config_group) = config_write($config_file, $config);
720
721 # Open pipes, for use between the parent and child processes. Specifically,
722 # the child will indicate when it's done with its test by writing a message
723 # to the parent.
724 my ($rfh, $wfh);
725 unless (pipe($rfh, $wfh)) {
726 die("Can't open pipe: $!");
727 }
728
729 my $ex;
730
731 # Fork child
732 $self->handle_sigchld();
733 defined(my $pid = fork()) or die("Can't fork: $!");
734 if ($pid) {
735 eval {
736 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
737
738 my ($resp_code, $resp_msg);
739
740 # First, find out what the default language is.
741 ($resp_code, $resp_msg) = $client->lang();
742
743 my $expected;
744
745 $expected = 200;
746 $self->assert($expected == $resp_code,
747 test_msg("Expected $expected, got $resp_code"));
748
749 $expected = '^Using default language (\S+)$';
750 $self->assert(qr/$expected/, $resp_msg,
751 test_msg("Expected '$expected', got '$resp_msg'"));
752
753 $resp_msg =~ /$expected/;
754 my $default_lang = $1;
755
756 ($resp_code, $resp_msg) = $client->lang($default_lang);
757
758 $expected = 200;
759 $self->assert($expected == $resp_code,
760 test_msg("Expected $expected, got $resp_code"));
761
762 $expected = "Using language $default_lang";
763 $self->assert($expected eq $resp_msg,
764 test_msg("Expected '$expected', got '$resp_msg'"));
765 };
766
767 if ($@) {
768 $ex = $@;
769 }
770
771 $wfh->print("done\n");
772 $wfh->flush();
773
774 } else {
775 eval { server_wait($config_file, $rfh) };
776 if ($@) {
777 warn($@);
778 exit 1;
779 }
780
781 exit 0;
782 }
783
784 # Stop server
785 server_stop($pid_file);
786
787 $self->assert_child_ok($pid);
788
789 if ($ex) {
790 test_append_logfile($log_file, $ex);
791 unlink($log_file);
792
793 die($ex);
794 }
795
796 unlink($log_file);
797 }
798
799 sub lang_lang_unknown_failed {
800 my $self = shift;
801 my $tmpdir = $self->{tmpdir};
802
803 my $config_file = "$tmpdir/lang.conf";
804 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
805 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
806
807 my $log_file = test_get_logfile();
808
809 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
810 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
811
812 my $user = 'proftpd';
813 my $passwd = 'test';
814 my $group = 'ftpd';
815 my $home_dir = File::Spec->rel2abs($tmpdir);
816 my $uid = 500;
817 my $gid = 500;
818
819 # Make sure that, if we're running as root, that the home directory has
820 # permissions/privs set for the account we create
821 if ($< == 0) {
822 unless (chmod(0755, $home_dir)) {
823 die("Can't set perms on $home_dir to 0755: $!");
824 }
825
826 unless (chown($uid, $gid, $home_dir)) {
827 die("Can't set owner of $home_dir to $uid/$gid: $!");
828 }
829 }
830
831 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
832 '/bin/bash');
833 auth_group_write($auth_group_file, $group, $gid, $user);
834
835 my $config = {
836 PidFile => $pid_file,
837 ScoreboardFile => $scoreboard_file,
838 SystemLog => $log_file,
839
840 AuthUserFile => $auth_user_file,
841 AuthGroupFile => $auth_group_file,
842 AuthOrder => 'mod_auth_file.c',
843
844 IfModules => {
845 'mod_delay.c' => {
846 DelayEngine => 'off',
847 },
848 },
849 };
850
851 my ($port, $config_user, $config_group) = config_write($config_file, $config);
852
853 # Open pipes, for use between the parent and child processes. Specifically,
854 # the child will indicate when it's done with its test by writing a message
855 # to the parent.
856 my ($rfh, $wfh);
857 unless (pipe($rfh, $wfh)) {
858 die("Can't open pipe: $!");
859 }
860
861 my $ex;
862
863 # Fork child
864 $self->handle_sigchld();
865 defined(my $pid = fork()) or die("Can't fork: $!");
866 if ($pid) {
867 eval {
868 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
869
870 my ($resp_code, $resp_msg);
871
872 eval { $client->lang('foobarbaz') };
873 unless ($@) {
874 die("LANG succeeded unexpectedly");
875
876 } else {
877 $resp_code = $client->response_code();
878 $resp_msg = $client->response_msg();
879 }
880
881 my $expected;
882
883 $expected = 504;
884 $self->assert($expected == $resp_code,
885 test_msg("Expected $expected, got $resp_code"));
886
887 $expected = 'Language foobarbaz not supported';
888 $self->assert($expected eq $resp_msg,
889 test_msg("Expected '$expected', got '$resp_msg'"));
890 };
891
892 if ($@) {
893 $ex = $@;
894 }
895
896 $wfh->print("done\n");
897 $wfh->flush();
898
899 } else {
900 eval { server_wait($config_file, $rfh) };
901 if ($@) {
902 warn($@);
903 exit 1;
904 }
905
906 exit 0;
907 }
908
909 # Stop server
910 server_stop($pid_file);
911
912 $self->assert_child_ok($pid);
913
914 if ($ex) {
915 test_append_logfile($log_file, $ex);
916 unlink($log_file);
917
918 die($ex);
919 }
920
921 unlink($log_file);
922 }
923
924 sub lang_opts_utf8_ok {
925 my $self = shift;
926 my $tmpdir = $self->{tmpdir};
927
928 my $config_file = "$tmpdir/lang.conf";
929 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
930 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
931
932 my $log_file = test_get_logfile();
933
934 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
935 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
936
937 my $user = 'proftpd';
938 my $passwd = 'test';
939 my $group = 'ftpd';
940 my $home_dir = File::Spec->rel2abs($tmpdir);
941 my $uid = 500;
942 my $gid = 500;
943
944 # Make sure that, if we're running as root, that the home directory has
945 # permissions/privs set for the account we create
946 if ($< == 0) {
947 unless (chmod(0755, $home_dir)) {
948 die("Can't set perms on $home_dir to 0755: $!");
949 }
950
951 unless (chown($uid, $gid, $home_dir)) {
952 die("Can't set owner of $home_dir to $uid/$gid: $!");
953 }
954 }
955
956 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
957 '/bin/bash');
958 auth_group_write($auth_group_file, $group, $gid, $user);
959
960 my $config = {
961 PidFile => $pid_file,
962 ScoreboardFile => $scoreboard_file,
963 SystemLog => $log_file,
964
965 AuthUserFile => $auth_user_file,
966 AuthGroupFile => $auth_group_file,
967 AuthOrder => 'mod_auth_file.c',
968
969 IfModules => {
970 'mod_delay.c' => {
971 DelayEngine => 'off',
972 },
973 },
974 };
975
976 my ($port, $config_user, $config_group) = config_write($config_file, $config);
977
978 # Open pipes, for use between the parent and child processes. Specifically,
979 # the child will indicate when it's done with its test by writing a message
980 # to the parent.
981 my ($rfh, $wfh);
982 unless (pipe($rfh, $wfh)) {
983 die("Can't open pipe: $!");
984 }
985
986 my $ex;
987
988 # Fork child
989 $self->handle_sigchld();
990 defined(my $pid = fork()) or die("Can't fork: $!");
991 if ($pid) {
992 eval {
993 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
994 my ($resp_code, $resp_msg) = $client->opts('UTF8', 'off');
995
996 my $expected;
997
998 $expected = 200;
999 $self->assert($expected == $resp_code,
1000 test_msg("Expected response code $expected, got $resp_code"));
1001
1002 $expected = 'UTF8 set to off';
1003 $self->assert($expected eq $resp_msg,
1004 test_msg("Expected response message '$expected', got '$resp_msg'"));
1005
1006 ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
1007
1008 $expected = 200;
1009 $self->assert($expected == $resp_code,
1010 test_msg("Expected response code $expected, got $resp_code"));
1011
1012 $expected = 'UTF8 set to on';
1013 $self->assert($expected eq $resp_msg,
1014 test_msg("Expected response message '$expected', got '$resp_msg'"));
1015 };
1016
1017 if ($@) {
1018 $ex = $@;
1019 }
1020
1021 $wfh->print("done\n");
1022 $wfh->flush();
1023
1024 } else {
1025 eval { server_wait($config_file, $rfh) };
1026 if ($@) {
1027 warn($@);
1028 exit 1;
1029 }
1030
1031 exit 0;
1032 }
1033
1034 # Stop server
1035 server_stop($pid_file);
1036
1037 $self->assert_child_ok($pid);
1038
1039 if ($ex) {
1040 test_append_logfile($log_file, $ex);
1041 unlink($log_file);
1042
1043 die($ex);
1044 }
1045
1046 unlink($log_file);
1047 }
1048
1049 sub lang_opts_utf8_nonbool_failed {
1050 my $self = shift;
1051 my $tmpdir = $self->{tmpdir};
1052
1053 my $config_file = "$tmpdir/lang.conf";
1054 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1055 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1056
1057 my $log_file = test_get_logfile();
1058
1059 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1060 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1061
1062 my $user = 'proftpd';
1063 my $passwd = 'test';
1064 my $group = 'ftpd';
1065 my $home_dir = File::Spec->rel2abs($tmpdir);
1066 my $uid = 500;
1067 my $gid = 500;
1068
1069 # Make sure that, if we're running as root, that the home directory has
1070 # permissions/privs set for the account we create
1071 if ($< == 0) {
1072 unless (chmod(0755, $home_dir)) {
1073 die("Can't set perms on $home_dir to 0755: $!");
1074 }
1075
1076 unless (chown($uid, $gid, $home_dir)) {
1077 die("Can't set owner of $home_dir to $uid/$gid: $!");
1078 }
1079 }
1080
1081 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1082 '/bin/bash');
1083 auth_group_write($auth_group_file, $group, $gid, $user);
1084
1085 my $config = {
1086 PidFile => $pid_file,
1087 ScoreboardFile => $scoreboard_file,
1088 SystemLog => $log_file,
1089
1090 AuthUserFile => $auth_user_file,
1091 AuthGroupFile => $auth_group_file,
1092 AuthOrder => 'mod_auth_file.c',
1093
1094 IfModules => {
1095 'mod_delay.c' => {
1096 DelayEngine => 'off',
1097 },
1098 },
1099 };
1100
1101 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1102
1103 # Open pipes, for use between the parent and child processes. Specifically,
1104 # the child will indicate when it's done with its test by writing a message
1105 # to the parent.
1106 my ($rfh, $wfh);
1107 unless (pipe($rfh, $wfh)) {
1108 die("Can't open pipe: $!");
1109 }
1110
1111 my $ex;
1112
1113 # Fork child
1114 $self->handle_sigchld();
1115 defined(my $pid = fork()) or die("Can't fork: $!");
1116 if ($pid) {
1117 eval {
1118 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1119
1120 my ($resp_code, $resp_msg);
1121
1122 eval { $client->opts('UTF8', 'foobar') };
1123 unless ($@) {
1124 die("OPTS UTF8 succeeded unexpectedly");
1125
1126 } else {
1127 $resp_code = $client->response_code();
1128 $resp_msg = $client->response_msg();
1129 }
1130
1131 my $expected;
1132
1133 $expected = 501;
1134 $self->assert($expected == $resp_code,
1135 test_msg("Expected $expected, got $resp_code"));
1136
1137 $expected = "'OPTS UTF8' not understood";
1138 $self->assert($expected eq $resp_msg,
1139 test_msg("Expected '$expected', got '$resp_msg'"));
1140 };
1141
1142 if ($@) {
1143 $ex = $@;
1144 }
1145
1146 $wfh->print("done\n");
1147 $wfh->flush();
1148
1149 } else {
1150 eval { server_wait($config_file, $rfh) };
1151 if ($@) {
1152 warn($@);
1153 exit 1;
1154 }
1155
1156 exit 0;
1157 }
1158
1159 # Stop server
1160 server_stop($pid_file);
1161
1162 $self->assert_child_ok($pid);
1163
1164 if ($ex) {
1165 test_append_logfile($log_file, $ex);
1166 unlink($log_file);
1167
1168 die($ex);
1169 }
1170
1171 unlink($log_file);
1172 }
1173
1174 sub lang_lang_default_en_US {
1175 my $self = shift;
1176 my $tmpdir = $self->{tmpdir};
1177
1178 my $config_file = "$tmpdir/lang.conf";
1179 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1180 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1181
1182 my $log_file = test_get_logfile();
1183
1184 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1185 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1186
1187 my $user = 'proftpd';
1188 my $passwd = 'test';
1189 my $group = 'ftpd';
1190 my $home_dir = File::Spec->rel2abs($tmpdir);
1191 my $uid = 500;
1192 my $gid = 500;
1193
1194 # Make sure that, if we're running as root, that the home directory has
1195 # permissions/privs set for the account we create
1196 if ($< == 0) {
1197 unless (chmod(0755, $home_dir)) {
1198 die("Can't set perms on $home_dir to 0755: $!");
1199 }
1200
1201 unless (chown($uid, $gid, $home_dir)) {
1202 die("Can't set owner of $home_dir to $uid/$gid: $!");
1203 }
1204 }
1205
1206 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1207 '/bin/bash');
1208 auth_group_write($auth_group_file, $group, $gid, $user);
1209
1210 # Copy the en_US.mo file from the locale/ directory into a directory
1211 # that we can tell mod_lang to find.
1212
1213 my $lang_path = File::Spec->rel2abs("$tmpdir/locale");
1214 mkpath("$lang_path/en_US/LC_MESSAGES");
1215
1216 copy("../locale/en_US.mo", "$lang_path/en_US/LC_MESSAGES/proftpd.mo");
1217
1218 my $config = {
1219 PidFile => $pid_file,
1220 ScoreboardFile => $scoreboard_file,
1221 SystemLog => $log_file,
1222
1223 AuthUserFile => $auth_user_file,
1224 AuthGroupFile => $auth_group_file,
1225 AuthOrder => 'mod_auth_file.c',
1226
1227 IfModules => {
1228 'mod_delay.c' => {
1229 DelayEngine => 'off',
1230 },
1231
1232 'mod_lang.c' => {
1233 LangPath => $lang_path,
1234 LangDefault => 'en_US',
1235 },
1236 },
1237 };
1238
1239 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1240
1241 # Open pipes, for use between the parent and child processes. Specifically,
1242 # the child will indicate when it's done with its test by writing a message
1243 # to the parent.
1244 my ($rfh, $wfh);
1245 unless (pipe($rfh, $wfh)) {
1246 die("Can't open pipe: $!");
1247 }
1248
1249 my $ex;
1250
1251 # Fork child
1252 $self->handle_sigchld();
1253 defined(my $pid = fork()) or die("Can't fork: $!");
1254 if ($pid) {
1255 eval {
1256 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1257 my ($resp_code, $resp_msg) = $client->user($user);
1258
1259 my $expected;
1260
1261 $expected = 331;
1262 $self->assert($expected == $resp_code,
1263 test_msg("Expected $expected, got $resp_code"));
1264
1265 $expected = "Password required for $user";
1266 $self->assert($expected eq $resp_msg,
1267 test_msg("Expected '$expected', got '$resp_msg'"));
1268 };
1269
1270 if ($@) {
1271 $ex = $@;
1272 }
1273
1274 $wfh->print("done\n");
1275 $wfh->flush();
1276
1277 } else {
1278 eval { server_wait($config_file, $rfh) };
1279 if ($@) {
1280 warn($@);
1281 exit 1;
1282 }
1283
1284 exit 0;
1285 }
1286
1287 # Stop server
1288 server_stop($pid_file);
1289
1290 $self->assert_child_ok($pid);
1291
1292 if ($ex) {
1293 test_append_logfile($log_file, $ex);
1294 unlink($log_file);
1295
1296 die($ex);
1297 }
1298
1299 unlink($log_file);
1300 }
1301
1302 sub lang_lang_default_en_US_UTF8 {
1303 my $self = shift;
1304 my $tmpdir = $self->{tmpdir};
1305
1306 my $config_file = "$tmpdir/lang.conf";
1307 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1308 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1309
1310 my $log_file = test_get_logfile();
1311
1312 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1313 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1314
1315 my $user = 'proftpd';
1316 my $passwd = 'test';
1317 my $group = 'ftpd';
1318 my $home_dir = File::Spec->rel2abs($tmpdir);
1319 my $uid = 500;
1320 my $gid = 500;
1321
1322 # Make sure that, if we're running as root, that the home directory has
1323 # permissions/privs set for the account we create
1324 if ($< == 0) {
1325 unless (chmod(0755, $home_dir)) {
1326 die("Can't set perms on $home_dir to 0755: $!");
1327 }
1328
1329 unless (chown($uid, $gid, $home_dir)) {
1330 die("Can't set owner of $home_dir to $uid/$gid: $!");
1331 }
1332 }
1333
1334 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1335 '/bin/bash');
1336 auth_group_write($auth_group_file, $group, $gid, $user);
1337
1338 # Copy the en_US.mo file from the locale/ directory into a directory
1339 # that we can tell mod_lang to find.
1340
1341 my $lang_path = File::Spec->rel2abs("$tmpdir/locale");
1342 mkpath("$lang_path/en_US/LC_MESSAGES");
1343
1344 copy("../locale/en_US.mo", "$lang_path/en_US/LC_MESSAGES/proftpd.mo");
1345
1346 my $config = {
1347 PidFile => $pid_file,
1348 ScoreboardFile => $scoreboard_file,
1349 SystemLog => $log_file,
1350
1351 AuthUserFile => $auth_user_file,
1352 AuthGroupFile => $auth_group_file,
1353 AuthOrder => 'mod_auth_file.c',
1354
1355 IfModules => {
1356 'mod_delay.c' => {
1357 DelayEngine => 'off',
1358 },
1359
1360 'mod_lang.c' => {
1361 LangPath => $lang_path,
1362 LangDefault => 'en_US.UTF-8',
1363 },
1364 },
1365 };
1366
1367 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1368
1369 # Open pipes, for use between the parent and child processes. Specifically,
1370 # the child will indicate when it's done with its test by writing a message
1371 # to the parent.
1372 my ($rfh, $wfh);
1373 unless (pipe($rfh, $wfh)) {
1374 die("Can't open pipe: $!");
1375 }
1376
1377 my $ex;
1378
1379 # Fork child
1380 $self->handle_sigchld();
1381 defined(my $pid = fork()) or die("Can't fork: $!");
1382 if ($pid) {
1383 eval {
1384 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1385 my ($resp_code, $resp_msg) = $client->user($user);
1386
1387 my $expected;
1388
1389 $expected = 331;
1390 $self->assert($expected == $resp_code,
1391 test_msg("Expected $expected, got $resp_code"));
1392
1393 $expected = "Password required for $user";
1394 $self->assert($expected eq $resp_msg,
1395 test_msg("Expected '$expected', got '$resp_msg'"));
1396 };
1397
1398 if ($@) {
1399 $ex = $@;
1400 }
1401
1402 $wfh->print("done\n");
1403 $wfh->flush();
1404
1405 } else {
1406 eval { server_wait($config_file, $rfh) };
1407 if ($@) {
1408 warn($@);
1409 exit 1;
1410 }
1411
1412 exit 0;
1413 }
1414
1415 # Stop server
1416 server_stop($pid_file);
1417
1418 $self->assert_child_ok($pid);
1419
1420 if ($ex) {
1421 test_append_logfile($log_file, $ex);
1422 unlink($log_file);
1423
1424 die($ex);
1425 }
1426
1427 unlink($log_file);
1428 }
1429
1430 sub lang_opts_utf8_useencoding_on {
1431 my $self = shift;
1432 my $tmpdir = $self->{tmpdir};
1433
1434 my $config_file = "$tmpdir/lang.conf";
1435 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1436 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1437
1438 my $log_file = test_get_logfile();
1439
1440 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1441 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1442
1443 my $user = 'proftpd';
1444 my $passwd = 'test';
1445 my $group = 'ftpd';
1446 my $home_dir = File::Spec->rel2abs($tmpdir);
1447 my $uid = 500;
1448 my $gid = 500;
1449
1450 # Make sure that, if we're running as root, that the home directory has
1451 # permissions/privs set for the account we create
1452 if ($< == 0) {
1453 unless (chmod(0755, $home_dir)) {
1454 die("Can't set perms on $home_dir to 0755: $!");
1455 }
1456
1457 unless (chown($uid, $gid, $home_dir)) {
1458 die("Can't set owner of $home_dir to $uid/$gid: $!");
1459 }
1460 }
1461
1462 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1463 '/bin/bash');
1464 auth_group_write($auth_group_file, $group, $gid, $user);
1465
1466 my $config = {
1467 PidFile => $pid_file,
1468 ScoreboardFile => $scoreboard_file,
1469 SystemLog => $log_file,
1470
1471 AuthUserFile => $auth_user_file,
1472 AuthGroupFile => $auth_group_file,
1473 AuthOrder => 'mod_auth_file.c',
1474
1475 IfModules => {
1476 'mod_delay.c' => {
1477 DelayEngine => 'off',
1478 },
1479
1480 'mod_lang.c' => {
1481 UseEncoding => 'on',
1482 },
1483 },
1484 };
1485
1486 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1487
1488 # Open pipes, for use between the parent and child processes. Specifically,
1489 # the child will indicate when it's done with its test by writing a message
1490 # to the parent.
1491 my ($rfh, $wfh);
1492 unless (pipe($rfh, $wfh)) {
1493 die("Can't open pipe: $!");
1494 }
1495
1496 my $ex;
1497
1498 # Fork child
1499 $self->handle_sigchld();
1500 defined(my $pid = fork()) or die("Can't fork: $!");
1501 if ($pid) {
1502 eval {
1503 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1504
1505 eval { $client->opts('UTF8', 'off') };
1506 unless ($@) {
1507 die("OPTS UTF8 off succeeded unexpectedly");
1508 }
1509
1510 my $resp_code = $client->response_code();
1511 my $resp_msg = $client->response_msg();
1512
1513 my $expected;
1514
1515 $expected = 451;
1516 $self->assert($expected == $resp_code,
1517 test_msg("Expected response code $expected, got $resp_code"));
1518
1519 $expected = 'Unable to accept OPTS UTF8';
1520 $self->assert($expected eq $resp_msg,
1521 test_msg("Expected response message '$expected', got '$resp_msg'"));
1522
1523 ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
1524
1525 $expected = 200;
1526 $self->assert($expected == $resp_code,
1527 test_msg("Expected response code $expected, got $resp_code"));
1528
1529 $expected = 'UTF8 set to on';
1530 $self->assert($expected eq $resp_msg,
1531 test_msg("Expected '$expected', got '$resp_msg'"));
1532 };
1533
1534 if ($@) {
1535 $ex = $@;
1536 }
1537
1538 $wfh->print("done\n");
1539 $wfh->flush();
1540
1541 } else {
1542 eval { server_wait($config_file, $rfh) };
1543 if ($@) {
1544 warn($@);
1545 exit 1;
1546 }
1547
1548 exit 0;
1549 }
1550
1551 # Stop server
1552 server_stop($pid_file);
1553
1554 $self->assert_child_ok($pid);
1555
1556 if ($ex) {
1557 test_append_logfile($log_file, $ex);
1558 unlink($log_file);
1559
1560 die($ex);
1561 }
1562
1563 unlink($log_file);
1564 }
1565
1566 sub lang_opts_utf8_useencoding_off {
1567 my $self = shift;
1568 my $tmpdir = $self->{tmpdir};
1569
1570 my $config_file = "$tmpdir/lang.conf";
1571 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1572 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1573
1574 my $log_file = test_get_logfile();
1575
1576 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1577 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1578
1579 my $user = 'proftpd';
1580 my $passwd = 'test';
1581 my $group = 'ftpd';
1582 my $home_dir = File::Spec->rel2abs($tmpdir);
1583 my $uid = 500;
1584 my $gid = 500;
1585
1586 # Make sure that, if we're running as root, that the home directory has
1587 # permissions/privs set for the account we create
1588 if ($< == 0) {
1589 unless (chmod(0755, $home_dir)) {
1590 die("Can't set perms on $home_dir to 0755: $!");
1591 }
1592
1593 unless (chown($uid, $gid, $home_dir)) {
1594 die("Can't set owner of $home_dir to $uid/$gid: $!");
1595 }
1596 }
1597
1598 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1599 '/bin/bash');
1600 auth_group_write($auth_group_file, $group, $gid, $user);
1601
1602 my $config = {
1603 PidFile => $pid_file,
1604 ScoreboardFile => $scoreboard_file,
1605 SystemLog => $log_file,
1606
1607 AuthUserFile => $auth_user_file,
1608 AuthGroupFile => $auth_group_file,
1609 AuthOrder => 'mod_auth_file.c',
1610
1611 IfModules => {
1612 'mod_delay.c' => {
1613 DelayEngine => 'off',
1614 },
1615
1616 'mod_lang.c' => {
1617 UseEncoding => 'off',
1618 },
1619 },
1620 };
1621
1622 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1623
1624 # Open pipes, for use between the parent and child processes. Specifically,
1625 # the child will indicate when it's done with its test by writing a message
1626 # to the parent.
1627 my ($rfh, $wfh);
1628 unless (pipe($rfh, $wfh)) {
1629 die("Can't open pipe: $!");
1630 }
1631
1632 my $ex;
1633
1634 # Fork child
1635 $self->handle_sigchld();
1636 defined(my $pid = fork()) or die("Can't fork: $!");
1637 if ($pid) {
1638 eval {
1639 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1640
1641 my ($resp_code, $resp_msg);
1642
1643 ($resp_code, $resp_msg) = $client->opts('UTF8', 'off');
1644
1645 my $expected;
1646
1647 $expected = 200;
1648 $self->assert($expected == $resp_code,
1649 test_msg("Expected $expected, got $resp_code"));
1650
1651 $expected = 'UTF8 set to off';
1652 $self->assert($expected eq $resp_msg,
1653 test_msg("Expected '$expected', got '$resp_msg'"));
1654
1655 $expected = 200;
1656 $self->assert($expected == $resp_code,
1657 test_msg("Expected $expected, got $resp_code"));
1658
1659 eval { $client->opts('UTF8', 'on') };
1660 unless ($@) {
1661 die("OPTS UTF8 on succeeded unexpectedly");
1662 }
1663
1664 $resp_code = $client->response_code();
1665 $resp_msg = $client->response_msg();
1666
1667 $expected = 451;
1668 $self->assert($expected == $resp_code,
1669 test_msg("Expected response code $expected, got $resp_code"));
1670
1671 $expected = 'Unable to accept OPTS UTF8';
1672 $self->assert($expected eq $resp_msg,
1673 test_msg("Expected response message '$expected', got '$resp_msg'"));
1674 };
1675
1676 if ($@) {
1677 $ex = $@;
1678 }
1679
1680 $wfh->print("done\n");
1681 $wfh->flush();
1682
1683 } else {
1684 eval { server_wait($config_file, $rfh) };
1685 if ($@) {
1686 warn($@);
1687 exit 1;
1688 }
1689
1690 exit 0;
1691 }
1692
1693 # Stop server
1694 server_stop($pid_file);
1695
1696 $self->assert_child_ok($pid);
1697
1698 if ($ex) {
1699 test_append_logfile($log_file, $ex);
1700 unlink($log_file);
1701
1702 die($ex);
1703 }
1704
1705 unlink($log_file);
1706 }
1707
1708 sub lang_opts_utf8_useencoding_charsets {
1709 my $self = shift;
1710 my $tmpdir = $self->{tmpdir};
1711
1712 my $config_file = "$tmpdir/lang.conf";
1713 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1714 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1715
1716 my $log_file = test_get_logfile();
1717
1718 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1719 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1720
1721 my $user = 'proftpd';
1722 my $passwd = 'test';
1723 my $group = 'ftpd';
1724 my $home_dir = File::Spec->rel2abs($tmpdir);
1725 my $uid = 500;
1726 my $gid = 500;
1727
1728 # Make sure that, if we're running as root, that the home directory has
1729 # permissions/privs set for the account we create
1730 if ($< == 0) {
1731 unless (chmod(0755, $home_dir)) {
1732 die("Can't set perms on $home_dir to 0755: $!");
1733 }
1734
1735 unless (chown($uid, $gid, $home_dir)) {
1736 die("Can't set owner of $home_dir to $uid/$gid: $!");
1737 }
1738 }
1739
1740 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1741 '/bin/bash');
1742 auth_group_write($auth_group_file, $group, $gid, $user);
1743
1744 my $config = {
1745 PidFile => $pid_file,
1746 ScoreboardFile => $scoreboard_file,
1747 SystemLog => $log_file,
1748 TraceLog => $log_file,
1749 Trace => 'encode:10',
1750
1751 AuthUserFile => $auth_user_file,
1752 AuthGroupFile => $auth_group_file,
1753 AuthOrder => 'mod_auth_file.c',
1754
1755 IfModules => {
1756 'mod_delay.c' => {
1757 DelayEngine => 'off',
1758 },
1759
1760 'mod_lang.c' => {
1761 UseEncoding => 'iso-8859-1 iso-8859-1',
1762 },
1763 },
1764 };
1765
1766 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1767
1768 # Open pipes, for use between the parent and child processes. Specifically,
1769 # the child will indicate when it's done with its test by writing a message
1770 # to the parent.
1771 my ($rfh, $wfh);
1772 unless (pipe($rfh, $wfh)) {
1773 die("Can't open pipe: $!");
1774 }
1775
1776 my $ex;
1777
1778 # Fork child
1779 $self->handle_sigchld();
1780 defined(my $pid = fork()) or die("Can't fork: $!");
1781 if ($pid) {
1782 eval {
1783 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1784 my ($resp_code, $resp_msg) = $client->opts('UTF8', 'off');
1785
1786 my $expected;
1787
1788 $expected = 200;
1789 $self->assert($expected == $resp_code,
1790 test_msg("Expected response code $expected, got $resp_code"));
1791
1792 $expected = 'UTF8 set to off';
1793 $self->assert($expected eq $resp_msg,
1794 test_msg("Expected response message '$expected', got '$resp_msg'"));
1795
1796 ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
1797
1798 $expected = 200;
1799 $self->assert($expected == $resp_code,
1800 test_msg("Expected response code $expected, got $resp_code"));
1801
1802 $expected = 'UTF8 set to on';
1803 $self->assert($expected eq $resp_msg,
1804 test_msg("Expected response message '$expected', got '$resp_msg'"));
1805 };
1806
1807 if ($@) {
1808 $ex = $@;
1809 }
1810
1811 $wfh->print("done\n");
1812 $wfh->flush();
1813
1814 } else {
1815 eval { server_wait($config_file, $rfh) };
1816 if ($@) {
1817 warn($@);
1818 exit 1;
1819 }
1820
1821 exit 0;
1822 }
1823
1824 # Stop server
1825 server_stop($pid_file);
1826
1827 $self->assert_child_ok($pid);
1828
1829 if ($ex) {
1830 test_append_logfile($log_file, $ex);
1831 unlink($log_file);
1832
1833 die($ex);
1834 }
1835
1836 unlink($log_file);
1837 }
1838
1839 sub lang_opts_utf8_useencoding_charsets_strict {
1840 my $self = shift;
1841 my $tmpdir = $self->{tmpdir};
1842
1843 my $config_file = "$tmpdir/lang.conf";
1844 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
1845 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
1846
1847 my $log_file = test_get_logfile();
1848
1849 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
1850 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
1851
1852 my $user = 'proftpd';
1853 my $passwd = 'test';
1854 my $group = 'ftpd';
1855 my $home_dir = File::Spec->rel2abs($tmpdir);
1856 my $uid = 500;
1857 my $gid = 500;
1858
1859 # Make sure that, if we're running as root, that the home directory has
1860 # permissions/privs set for the account we create
1861 if ($< == 0) {
1862 unless (chmod(0755, $home_dir)) {
1863 die("Can't set perms on $home_dir to 0755: $!");
1864 }
1865
1866 unless (chown($uid, $gid, $home_dir)) {
1867 die("Can't set owner of $home_dir to $uid/$gid: $!");
1868 }
1869 }
1870
1871 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1872 '/bin/bash');
1873 auth_group_write($auth_group_file, $group, $gid, $user);
1874
1875 my $config = {
1876 PidFile => $pid_file,
1877 ScoreboardFile => $scoreboard_file,
1878 SystemLog => $log_file,
1879 TraceLog => $log_file,
1880 Trace => 'encode:10',
1881
1882 AuthUserFile => $auth_user_file,
1883 AuthGroupFile => $auth_group_file,
1884 AuthOrder => 'mod_auth_file.c',
1885
1886 IfModules => {
1887 'mod_delay.c' => {
1888 DelayEngine => 'off',
1889 },
1890
1891 'mod_lang.c' => {
1892 UseEncoding => 'iso-8859-1 iso-8859-1 strict',
1893 },
1894 },
1895 };
1896
1897 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1898
1899 # Open pipes, for use between the parent and child processes. Specifically,
1900 # the child will indicate when it's done with its test by writing a message
1901 # to the parent.
1902 my ($rfh, $wfh);
1903 unless (pipe($rfh, $wfh)) {
1904 die("Can't open pipe: $!");
1905 }
1906
1907 my $ex;
1908
1909 # Fork child
1910 $self->handle_sigchld();
1911 defined(my $pid = fork()) or die("Can't fork: $!");
1912 if ($pid) {
1913 eval {
1914 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1915
1916 # Make sure the OPTS UTF8 command does not appear in the FEAT listing;
1917 # see Bug#3737.
1918 $client->feat();
1919 my $resp_code = $client->response_code();
1920 my $resp_msgs = $client->response_msgs();
1921
1922 my $expected;
1923
1924 $expected = 211;
1925 $self->assert($expected == $resp_code,
1926 test_msg("Expected response code $expected, got $resp_code"));
1927
1928 foreach my $feat (@$resp_msgs) {
1929 if ($feat =~ /^ UTF8$/) {
1930 die("'$feat' feature listed unexpectedly via FEAT");
1931 }
1932 }
1933
1934 my $resp_msg;
1935 ($resp_code, $resp_msg) = $client->opts('UTF8', 'off');
1936
1937 $expected = 200;
1938 $self->assert($expected == $resp_code,
1939 test_msg("Expected response code $expected, got $resp_code"));
1940
1941 $expected = 'UTF8 set to off';
1942 $self->assert($expected eq $resp_msg,
1943 test_msg("Expected response message '$expected', got '$resp_msg'"));
1944
1945 eval { $client->opts('UTF8', 'on') };
1946 unless ($@) {
1947 die("OPTS UTF8 on succeeded unexpectedly");
1948 }
1949
1950 $resp_code = $client->response_code();
1951 $resp_msg = $client->response_msg();
1952
1953 $expected = 451;
1954 $self->assert($expected == $resp_code,
1955 test_msg("Expected response code $expected, got $resp_code"));
1956
1957 $expected = 'Unable to accept OPTS UTF8';
1958 $self->assert($expected eq $resp_msg,
1959 test_msg("Expected response message '$expected', got '$resp_msg'"));
1960 };
1961
1962 if ($@) {
1963 $ex = $@;
1964 }
1965
1966 $wfh->print("done\n");
1967 $wfh->flush();
1968
1969 } else {
1970 eval { server_wait($config_file, $rfh) };
1971 if ($@) {
1972 warn($@);
1973 exit 1;
1974 }
1975
1976 exit 0;
1977 }
1978
1979 # Stop server
1980 server_stop($pid_file);
1981
1982 $self->assert_child_ok($pid);
1983
1984 if ($ex) {
1985 test_append_logfile($log_file, $ex);
1986 unlink($log_file);
1987
1988 die($ex);
1989 }
1990
1991 unlink($log_file);
1992 }
1993
1994 sub lang_opts_utf8_useencoding_charsets_strict_with_utf8 {
1995 my $self = shift;
1996 my $tmpdir = $self->{tmpdir};
1997
1998 my $config_file = "$tmpdir/lang.conf";
1999 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2000 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2001
2002 my $log_file = test_get_logfile();
2003
2004 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2005 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2006
2007 my $user = 'proftpd';
2008 my $passwd = 'test';
2009 my $group = 'ftpd';
2010 my $home_dir = File::Spec->rel2abs($tmpdir);
2011 my $uid = 500;
2012 my $gid = 500;
2013
2014 # Make sure that, if we're running as root, that the home directory has
2015 # permissions/privs set for the account we create
2016 if ($< == 0) {
2017 unless (chmod(0755, $home_dir)) {
2018 die("Can't set perms on $home_dir to 0755: $!");
2019 }
2020
2021 unless (chown($uid, $gid, $home_dir)) {
2022 die("Can't set owner of $home_dir to $uid/$gid: $!");
2023 }
2024 }
2025
2026 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2027 '/bin/bash');
2028 auth_group_write($auth_group_file, $group, $gid, $user);
2029
2030 my $config = {
2031 PidFile => $pid_file,
2032 ScoreboardFile => $scoreboard_file,
2033 SystemLog => $log_file,
2034 TraceLog => $log_file,
2035 Trace => 'encode:10',
2036
2037 AuthUserFile => $auth_user_file,
2038 AuthGroupFile => $auth_group_file,
2039 AuthOrder => 'mod_auth_file.c',
2040
2041 IfModules => {
2042 'mod_delay.c' => {
2043 DelayEngine => 'off',
2044 },
2045
2046 'mod_lang.c' => {
2047 UseEncoding => 'iso-8859-1 utf-8 strict',
2048 },
2049 },
2050 };
2051
2052 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2053
2054 # Open pipes, for use between the parent and child processes. Specifically,
2055 # the child will indicate when it's done with its test by writing a message
2056 # to the parent.
2057 my ($rfh, $wfh);
2058 unless (pipe($rfh, $wfh)) {
2059 die("Can't open pipe: $!");
2060 }
2061
2062 my $ex;
2063
2064 # Fork child
2065 $self->handle_sigchld();
2066 defined(my $pid = fork()) or die("Can't fork: $!");
2067 if ($pid) {
2068 eval {
2069 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2070
2071 # Make sure the OPTS UTF8 command does not appear in the FEAT listing;
2072 # see Bug#3737.
2073 $client->feat();
2074 my $resp_code = $client->response_code();
2075 my $resp_msgs = $client->response_msgs();
2076
2077 my $expected;
2078
2079 $expected = 211;
2080 $self->assert($expected == $resp_code,
2081 test_msg("Expected response code $expected, got $resp_code"));
2082
2083 # Since our strict UseEncoding expects UTF8, we should see UTF8
2084 # listed in the FEAT output (see Bug#3737).
2085 my $have_utf8 = 0;
2086 foreach my $feat (@$resp_msgs) {
2087 if ($feat =~ /^ UTF8$/) {
2088 $have_utf8 = 1;
2089 last;
2090 }
2091 }
2092
2093 $self->assert($have_utf8,
2094 test_msg("UTF8 feature not listed as expected via FEAT"));
2095
2096 eval { $client->opts('UTF8', 'off') };
2097 unless ($@) {
2098 die("OPTS UTF8 off succeeded unexpectedly");
2099 }
2100
2101 $resp_code = $client->response_code();
2102 my $resp_msg = $client->response_msg();
2103
2104 $expected = 451;
2105 $self->assert($expected == $resp_code,
2106 test_msg("Expected response code $expected, got $resp_code"));
2107
2108 $expected = 'Unable to accept OPTS UTF8';
2109 $self->assert($expected eq $resp_msg,
2110 test_msg("Expected response message '$expected', got '$resp_msg'"));
2111
2112 ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
2113
2114 $expected = 200;
2115 $self->assert($expected == $resp_code,
2116 test_msg("Expected response code $expected, got $resp_code"));
2117
2118 $expected = 'UTF8 set to on';
2119 $self->assert($expected eq $resp_msg,
2120 test_msg("Expected response message '$expected', got '$resp_msg'"));
2121 };
2122
2123 if ($@) {
2124 $ex = $@;
2125 }
2126
2127 $wfh->print("done\n");
2128 $wfh->flush();
2129
2130 } else {
2131 eval { server_wait($config_file, $rfh) };
2132 if ($@) {
2133 warn($@);
2134 exit 1;
2135 }
2136
2137 exit 0;
2138 }
2139
2140 # Stop server
2141 server_stop($pid_file);
2142
2143 $self->assert_child_ok($pid);
2144
2145 if ($ex) {
2146 test_append_logfile($log_file, $ex);
2147 unlink($log_file);
2148
2149 die($ex);
2150 }
2151
2152 unlink($log_file);
2153 }
2154
2155 sub lang_opts_utf8_useencoding_charsets_with_env {
2156 my $self = shift;
2157 my $tmpdir = $self->{tmpdir};
2158
2159 my $config_file = "$tmpdir/lang.conf";
2160 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2161 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2162
2163 my $log_file = test_get_logfile();
2164
2165 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2166 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2167
2168 my $user = 'proftpd';
2169 my $passwd = 'test';
2170 my $group = 'ftpd';
2171 my $home_dir = File::Spec->rel2abs($tmpdir);
2172 my $uid = 500;
2173 my $gid = 500;
2174
2175 # Make sure that, if we're running as root, that the home directory has
2176 # permissions/privs set for the account we create
2177 if ($< == 0) {
2178 unless (chmod(0755, $home_dir)) {
2179 die("Can't set perms on $home_dir to 0755: $!");
2180 }
2181
2182 unless (chown($uid, $gid, $home_dir)) {
2183 die("Can't set owner of $home_dir to $uid/$gid: $!");
2184 }
2185 }
2186
2187 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2188 '/bin/bash');
2189 auth_group_write($auth_group_file, $group, $gid, $user);
2190
2191 # Copy the en_US.mo file from the locale/ directory into a directory
2192 # that we can tell mod_lang to find.
2193
2194 my $lang_path = File::Spec->rel2abs("$tmpdir/locale");
2195 mkpath("$lang_path/en_US/LC_MESSAGES");
2196
2197 copy("../locale/en_US.mo", "$lang_path/en_US/LC_MESSAGES/proftpd.mo");
2198
2199 my $config = {
2200 PidFile => $pid_file,
2201 ScoreboardFile => $scoreboard_file,
2202 SystemLog => $log_file,
2203 TraceLog => $log_file,
2204 Trace => 'encode:10',
2205
2206 AuthUserFile => $auth_user_file,
2207 AuthGroupFile => $auth_group_file,
2208 AuthOrder => 'mod_auth_file.c',
2209
2210 IfModules => {
2211 'mod_delay.c' => {
2212 DelayEngine => 'off',
2213 },
2214
2215 'mod_lang.c' => {
2216 UseEncoding => 'iso-8859-1 iso-8859-1',
2217 },
2218 },
2219 };
2220
2221 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2222
2223 # Open pipes, for use between the parent and child processes. Specifically,
2224 # the child will indicate when it's done with its test by writing a message
2225 # to the parent.
2226 my ($rfh, $wfh);
2227 unless (pipe($rfh, $wfh)) {
2228 die("Can't open pipe: $!");
2229 }
2230
2231 my $ex;
2232
2233 # Fork child
2234 $self->handle_sigchld();
2235 defined(my $pid = fork()) or die("Can't fork: $!");
2236 if ($pid) {
2237 eval {
2238 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2239 my ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
2240
2241 my $expected;
2242
2243 $expected = 200;
2244 $self->assert($expected == $resp_code,
2245 test_msg("Expected response code $expected, got $resp_code"));
2246
2247 $expected = 'UTF8 set to on';
2248 $self->assert($expected eq $resp_msg,
2249 test_msg("Expected response message '$expected', got '$resp_msg'"));
2250
2251 ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
2252
2253 $expected = 200;
2254 $self->assert($expected == $resp_code,
2255 test_msg("Expected response code $expected, got $resp_code"));
2256
2257 $expected = 'UTF8 set to on';
2258 $self->assert($expected eq $resp_msg,
2259 test_msg("Expected response message '$expected', got '$resp_msg'"));
2260 };
2261
2262 if ($@) {
2263 $ex = $@;
2264 }
2265
2266 $wfh->print("done\n");
2267 $wfh->flush();
2268
2269 } else {
2270 # Before we start the server, set the LANG environment variable to
2271 # something like "en_US.utf8", see what happens.
2272 #
2273 # Note: The list of allowed values here should be dynamically determined
2274 # by calling `locale -a'.
2275 $ENV{LANG} = "en_US.utf8";
2276
2277 eval { server_wait($config_file, $rfh) };
2278 if ($@) {
2279 warn($@);
2280 exit 1;
2281 }
2282
2283 exit 0;
2284 }
2285
2286 # Stop server
2287 server_stop($pid_file);
2288
2289 $self->assert_child_ok($pid);
2290
2291 if ($ex) {
2292 test_append_logfile($log_file, $ex);
2293 unlink($log_file);
2294
2295 die($ex);
2296 }
2297
2298 unlink($log_file);
2299 }
2300
2301 sub lang_useencoding_latin1_utf8 {
2302 my $self = shift;
2303 my $tmpdir = $self->{tmpdir};
2304
2305 my $config_file = "$tmpdir/lang.conf";
2306 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2307 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2308
2309 my $log_file = test_get_logfile();
2310
2311 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2312 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2313
2314 my $user = 'proftpd';
2315 my $passwd = 'test';
2316 my $group = 'ftpd';
2317 my $home_dir = File::Spec->rel2abs($tmpdir);
2318 my $uid = 500;
2319 my $gid = 500;
2320
2321 # Make sure that, if we're running as root, that the home directory has
2322 # permissions/privs set for the account we create
2323 if ($< == 0) {
2324 unless (chmod(0755, $home_dir)) {
2325 die("Can't set perms on $home_dir to 0755: $!");
2326 }
2327
2328 unless (chown($uid, $gid, $home_dir)) {
2329 die("Can't set owner of $home_dir to $uid/$gid: $!");
2330 }
2331 }
2332
2333 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2334 '/bin/bash');
2335 auth_group_write($auth_group_file, $group, $gid, $user);
2336
2337 my $test_file = File::Spec->rel2abs("$home_dir/üöä");
2338
2339 my $config = {
2340 PidFile => $pid_file,
2341 ScoreboardFile => $scoreboard_file,
2342 SystemLog => $log_file,
2343 TraceLog => $log_file,
2344 Trace => 'encode:20',
2345
2346 AuthUserFile => $auth_user_file,
2347 AuthGroupFile => $auth_group_file,
2348 AuthOrder => 'mod_auth_file.c',
2349
2350 IfModules => {
2351 'mod_delay.c' => {
2352 DelayEngine => 'off',
2353 },
2354
2355 'mod_lang.c' => {
2356 UseEncoding => 'utf-8 iso-8859-1',
2357 },
2358 },
2359 };
2360
2361 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2362
2363 # Open pipes, for use between the parent and child processes. Specifically,
2364 # the child will indicate when it's done with its test by writing a message
2365 # to the parent.
2366 my ($rfh, $wfh);
2367 unless (pipe($rfh, $wfh)) {
2368 die("Can't open pipe: $!");
2369 }
2370
2371 my $ex;
2372
2373 # Fork child
2374 $self->handle_sigchld();
2375 defined(my $pid = fork()) or die("Can't fork: $!");
2376 if ($pid) {
2377 eval {
2378 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2379 $client->login($user, $passwd);
2380
2381 my $name = "üöä";
2382
2383 my $conn = $client->stor_raw($name);
2384 unless ($conn) {
2385 die("STOR $name failed: " . $client->response_code() . " " .
2386 $client->response_msg());
2387 }
2388
2389 my $buf = "Hello, world\n";
2390 $conn->write($buf, length($buf), 15);
2391 eval { $conn->close() };
2392
2393 my $resp_code = $client->response_code();
2394 my $resp_msg = $client->response_msg();
2395 $self->assert_transfer_ok($resp_code, $resp_msg);
2396
2397 $client->quit();
2398
2399 $self->assert(-f $test_file,
2400 test_msg("File $test_file does not exist as expected"));
2401 };
2402
2403 if ($@) {
2404 $ex = $@;
2405 }
2406
2407 $wfh->print("done\n");
2408 $wfh->flush();
2409
2410 } else {
2411 eval { server_wait($config_file, $rfh) };
2412 if ($@) {
2413 warn($@);
2414 exit 1;
2415 }
2416
2417 exit 0;
2418 }
2419
2420 # Stop server
2421 server_stop($pid_file);
2422
2423 $self->assert_child_ok($pid);
2424
2425 if ($ex) {
2426 test_append_logfile($log_file, $ex);
2427 unlink($log_file);
2428
2429 die($ex);
2430 }
2431
2432 unlink($log_file);
2433 }
2434
2435 sub lang_useencoding_utf8_latin1 {
2436 my $self = shift;
2437 my $tmpdir = $self->{tmpdir};
2438
2439 my $config_file = "$tmpdir/lang.conf";
2440 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2441 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2442
2443 my $log_file = test_get_logfile();
2444
2445 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2446 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2447
2448 my $user = 'proftpd';
2449 my $passwd = 'test';
2450 my $group = 'ftpd';
2451 my $home_dir = File::Spec->rel2abs($tmpdir);
2452 my $uid = 500;
2453 my $gid = 500;
2454
2455 # Make sure that, if we're running as root, that the home directory has
2456 # permissions/privs set for the account we create
2457 if ($< == 0) {
2458 unless (chmod(0755, $home_dir)) {
2459 die("Can't set perms on $home_dir to 0755: $!");
2460 }
2461
2462 unless (chown($uid, $gid, $home_dir)) {
2463 die("Can't set owner of $home_dir to $uid/$gid: $!");
2464 }
2465 }
2466
2467 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2468 '/bin/bash');
2469 auth_group_write($auth_group_file, $group, $gid, $user);
2470
2471 my $test_file = File::Spec->rel2abs("$home_dir/Grafik-Zentrumäüu.png");
2472 if ($^O eq 'darwin') {
2473 # MacOSX hack
2474 $test_file = ('/private' . $test_file);
2475 }
2476
2477 my $config = {
2478 PidFile => $pid_file,
2479 ScoreboardFile => $scoreboard_file,
2480 SystemLog => $log_file,
2481 TraceLog => $log_file,
2482 Trace => 'encode:20',
2483
2484 AuthUserFile => $auth_user_file,
2485 AuthGroupFile => $auth_group_file,
2486 AuthOrder => 'mod_auth_file.c',
2487
2488 IfModules => {
2489 'mod_delay.c' => {
2490 DelayEngine => 'off',
2491 },
2492
2493 'mod_lang.c' => {
2494 UseEncoding => 'utf-8 iso-8859-1',
2495 },
2496 },
2497 };
2498
2499 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2500
2501 # Open pipes, for use between the parent and child processes. Specifically,
2502 # the child will indicate when it's done with its test by writing a message
2503 # to the parent.
2504 my ($rfh, $wfh);
2505 unless (pipe($rfh, $wfh)) {
2506 die("Can't open pipe: $!");
2507 }
2508
2509 my $ex;
2510
2511 # Fork child
2512 $self->handle_sigchld();
2513 defined(my $pid = fork()) or die("Can't fork: $!");
2514 if ($pid) {
2515 eval {
2516 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2517 $client->login($user, $passwd);
2518
2519 my $name = "Grafik-Zentrumäüu.png";
2520
2521 my $conn = $client->stor_raw($name);
2522 unless ($conn) {
2523 die("STOR $name failed: " . $client->response_code() . " " .
2524 $client->response_msg());
2525 }
2526
2527 my $buf = "Hello, world\n";
2528 $conn->write($buf, length($buf), 15);
2529 eval { $conn->close() };
2530
2531 my $resp_code = $client->response_code();
2532 my $resp_msg = $client->response_msg();
2533 $self->assert_transfer_ok($resp_code, $resp_msg);
2534
2535 $client->quit();
2536
2537 $self->assert(-f $test_file,
2538 test_msg("File $test_file does not exist as expected"));
2539 };
2540
2541 if ($@) {
2542 $ex = $@;
2543 }
2544
2545 $wfh->print("done\n");
2546 $wfh->flush();
2547
2548 } else {
2549 eval { server_wait($config_file, $rfh) };
2550 if ($@) {
2551 warn($@);
2552 exit 1;
2553 }
2554
2555 exit 0;
2556 }
2557
2558 # Stop server
2559 server_stop($pid_file);
2560
2561 $self->assert_child_ok($pid);
2562
2563 if ($ex) {
2564 test_append_logfile($log_file, $ex);
2565 unlink($log_file);
2566
2567 die($ex);
2568 }
2569
2570 unlink($log_file);
2571 }
2572
2573 sub lang_opts_utf8_prefer_server_encoding_bug4125 {
2574 my $self = shift;
2575 my $tmpdir = $self->{tmpdir};
2576
2577 my $config_file = "$tmpdir/lang.conf";
2578 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2579 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2580
2581 my $log_file = test_get_logfile();
2582
2583 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2584 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2585
2586 my $user = 'proftpd';
2587 my $passwd = 'test';
2588 my $group = 'ftpd';
2589 my $home_dir = File::Spec->rel2abs($tmpdir);
2590 my $uid = 500;
2591 my $gid = 500;
2592
2593 # Make sure that, if we're running as root, that the home directory has
2594 # permissions/privs set for the account we create
2595 if ($< == 0) {
2596 unless (chmod(0755, $home_dir)) {
2597 die("Can't set perms on $home_dir to 0755: $!");
2598 }
2599
2600 unless (chown($uid, $gid, $home_dir)) {
2601 die("Can't set owner of $home_dir to $uid/$gid: $!");
2602 }
2603 }
2604
2605 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2606 '/bin/bash');
2607 auth_group_write($auth_group_file, $group, $gid, $user);
2608
2609 my $config = {
2610 PidFile => $pid_file,
2611 ScoreboardFile => $scoreboard_file,
2612 SystemLog => $log_file,
2613 TraceLog => $log_file,
2614 Trace => 'encode:10',
2615
2616 AuthUserFile => $auth_user_file,
2617 AuthGroupFile => $auth_group_file,
2618 AuthOrder => 'mod_auth_file.c',
2619
2620 IfModules => {
2621 'mod_delay.c' => {
2622 DelayEngine => 'off',
2623 },
2624
2625 'mod_lang.c' => {
2626 LangOptions => 'PreferServerEncoding',
2627 UseEncoding => 'iso-8859-1 iso-8859-1',
2628 },
2629 },
2630 };
2631
2632 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2633
2634 # Open pipes, for use between the parent and child processes. Specifically,
2635 # the child will indicate when it's done with its test by writing a message
2636 # to the parent.
2637 my ($rfh, $wfh);
2638 unless (pipe($rfh, $wfh)) {
2639 die("Can't open pipe: $!");
2640 }
2641
2642 my $ex;
2643
2644 # Fork child
2645 $self->handle_sigchld();
2646 defined(my $pid = fork()) or die("Can't fork: $!");
2647 if ($pid) {
2648 eval {
2649 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2650
2651 # Make sure the OPTS UTF8 command does not appear in the FEAT listing;
2652 # see Bug#3737.
2653 $client->feat();
2654 my $resp_code = $client->response_code();
2655 my $resp_msgs = $client->response_msgs();
2656
2657 my $expected;
2658
2659 $expected = 211;
2660 $self->assert($expected == $resp_code,
2661 test_msg("Expected response code $expected, got $resp_code"));
2662
2663 foreach my $feat (@$resp_msgs) {
2664 if ($feat =~ /^ UTF8$/) {
2665 die("'$feat' feature listed unexpectedly via FEAT");
2666 }
2667 }
2668
2669 my $resp_msg;
2670 ($resp_code, $resp_msg) = $client->opts('UTF8', 'off');
2671
2672 $expected = 200;
2673 $self->assert($expected == $resp_code,
2674 test_msg("Expected response code $expected, got $resp_code"));
2675
2676 $expected = 'UTF8 set to off';
2677 $self->assert($expected eq $resp_msg,
2678 test_msg("Expected response message '$expected', got '$resp_msg'"));
2679
2680 eval { $client->opts('UTF8', 'on') };
2681 unless ($@) {
2682 die("OPTS UTF8 on succeeded unexpectedly");
2683 }
2684
2685 $resp_code = $client->response_code();
2686 $resp_msg = $client->response_msg();
2687
2688 $expected = 451;
2689 $self->assert($expected == $resp_code,
2690 test_msg("Expected response code $expected, got $resp_code"));
2691
2692 $expected = 'Unable to accept OPTS UTF8';
2693 $self->assert($expected eq $resp_msg,
2694 test_msg("Expected response message '$expected', got '$resp_msg'"));
2695 };
2696
2697 if ($@) {
2698 $ex = $@;
2699 }
2700
2701 $wfh->print("done\n");
2702 $wfh->flush();
2703
2704 } else {
2705 eval { server_wait($config_file, $rfh) };
2706 if ($@) {
2707 warn($@);
2708 exit 1;
2709 }
2710
2711 exit 0;
2712 }
2713
2714 # Stop server
2715 server_stop($pid_file);
2716
2717 $self->assert_child_ok($pid);
2718
2719 if ($ex) {
2720 test_append_logfile($log_file, $ex);
2721 unlink($log_file);
2722
2723 die($ex);
2724 }
2725
2726 unlink($log_file);
2727 }
2728
2729 sub lang_opts_utf8_useencoding_charsets_prefer_server_encoding_bug4125 {
2730 my $self = shift;
2731 my $tmpdir = $self->{tmpdir};
2732
2733 my $config_file = "$tmpdir/lang.conf";
2734 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2735 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2736
2737 my $log_file = test_get_logfile();
2738
2739 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2740 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2741
2742 my $user = 'proftpd';
2743 my $passwd = 'test';
2744 my $group = 'ftpd';
2745 my $home_dir = File::Spec->rel2abs($tmpdir);
2746 my $uid = 500;
2747 my $gid = 500;
2748
2749 # Make sure that, if we're running as root, that the home directory has
2750 # permissions/privs set for the account we create
2751 if ($< == 0) {
2752 unless (chmod(0755, $home_dir)) {
2753 die("Can't set perms on $home_dir to 0755: $!");
2754 }
2755
2756 unless (chown($uid, $gid, $home_dir)) {
2757 die("Can't set owner of $home_dir to $uid/$gid: $!");
2758 }
2759 }
2760
2761 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2762 '/bin/bash');
2763 auth_group_write($auth_group_file, $group, $gid, $user);
2764
2765 my $config = {
2766 PidFile => $pid_file,
2767 ScoreboardFile => $scoreboard_file,
2768 SystemLog => $log_file,
2769 TraceLog => $log_file,
2770 Trace => 'encode:10',
2771
2772 AuthUserFile => $auth_user_file,
2773 AuthGroupFile => $auth_group_file,
2774 AuthOrder => 'mod_auth_file.c',
2775
2776 IfModules => {
2777 'mod_delay.c' => {
2778 DelayEngine => 'off',
2779 },
2780
2781 'mod_lang.c' => {
2782 LangOptions => 'PreferServerEncoding',
2783 UseEncoding => 'iso-8859-1 utf-8',
2784 },
2785 },
2786 };
2787
2788 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2789
2790 # Open pipes, for use between the parent and child processes. Specifically,
2791 # the child will indicate when it's done with its test by writing a message
2792 # to the parent.
2793 my ($rfh, $wfh);
2794 unless (pipe($rfh, $wfh)) {
2795 die("Can't open pipe: $!");
2796 }
2797
2798 my $ex;
2799
2800 # Fork child
2801 $self->handle_sigchld();
2802 defined(my $pid = fork()) or die("Can't fork: $!");
2803 if ($pid) {
2804 eval {
2805 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2806
2807 # Make sure the OPTS UTF8 command does not appear in the FEAT listing;
2808 # see Bug#3737.
2809 $client->feat();
2810 my $resp_code = $client->response_code();
2811 my $resp_msgs = $client->response_msgs();
2812
2813 my $expected;
2814
2815 $expected = 211;
2816 $self->assert($expected == $resp_code,
2817 test_msg("Expected response code $expected, got $resp_code"));
2818
2819 # Since our strict UseEncoding expects UTF8, we should see UTF8
2820 # listed in the FEAT output (see Bug#3737).
2821 my $have_utf8 = 0;
2822 foreach my $feat (@$resp_msgs) {
2823 if ($feat =~ /^ UTF8$/) {
2824 $have_utf8 = 1;
2825 last;
2826 }
2827 }
2828
2829 $self->assert($have_utf8,
2830 test_msg("UTF8 feature not listed as expected via FEAT"));
2831
2832 eval { $client->opts('UTF8', 'off') };
2833 unless ($@) {
2834 die("OPTS UTF8 off succeeded unexpectedly");
2835 }
2836
2837 $resp_code = $client->response_code();
2838 my $resp_msg = $client->response_msg();
2839
2840 $expected = 451;
2841 $self->assert($expected == $resp_code,
2842 test_msg("Expected response code $expected, got $resp_code"));
2843
2844 $expected = 'Unable to accept OPTS UTF8';
2845 $self->assert($expected eq $resp_msg,
2846 test_msg("Expected response message '$expected', got '$resp_msg'"));
2847
2848 ($resp_code, $resp_msg) = $client->opts('UTF8', 'on');
2849
2850 $expected = 200;
2851 $self->assert($expected == $resp_code,
2852 test_msg("Expected response code $expected, got $resp_code"));
2853
2854 $expected = 'UTF8 set to on';
2855 $self->assert($expected eq $resp_msg,
2856 test_msg("Expected response message '$expected', got '$resp_msg'"));
2857 };
2858
2859 if ($@) {
2860 $ex = $@;
2861 }
2862
2863 $wfh->print("done\n");
2864 $wfh->flush();
2865
2866 } else {
2867 eval { server_wait($config_file, $rfh) };
2868 if ($@) {
2869 warn($@);
2870 exit 1;
2871 }
2872
2873 exit 0;
2874 }
2875
2876 # Stop server
2877 server_stop($pid_file);
2878
2879 $self->assert_child_ok($pid);
2880
2881 if ($ex) {
2882 test_append_logfile($log_file, $ex);
2883 unlink($log_file);
2884
2885 die($ex);
2886 }
2887
2888 unlink($log_file);
2889 }
2890
2891 sub lang_useencoding_ascii_utf8_require_valid_encoding_bug4125 {
2892 my $self = shift;
2893 my $tmpdir = $self->{tmpdir};
2894
2895 my $config_file = "$tmpdir/lang.conf";
2896 my $pid_file = File::Spec->rel2abs("$tmpdir/lang.pid");
2897 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/lang.scoreboard");
2898
2899 my $log_file = test_get_logfile();
2900
2901 my $auth_user_file = File::Spec->rel2abs("$tmpdir/lang.passwd");
2902 my $auth_group_file = File::Spec->rel2abs("$tmpdir/lang.group");
2903
2904 my $user = 'proftpd';
2905 my $passwd = 'test';
2906 my $group = 'ftpd';
2907 my $home_dir = File::Spec->rel2abs($tmpdir);
2908 my $uid = 500;
2909 my $gid = 500;
2910
2911 # Make sure that, if we're running as root, that the home directory has
2912 # permissions/privs set for the account we create
2913 if ($< == 0) {
2914 unless (chmod(0755, $home_dir)) {
2915 die("Can't set perms on $home_dir to 0755: $!");
2916 }
2917
2918 unless (chown($uid, $gid, $home_dir)) {
2919 die("Can't set owner of $home_dir to $uid/$gid: $!");
2920 }
2921 }
2922
2923 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2924 '/bin/bash');
2925 auth_group_write($auth_group_file, $group, $gid, $user);
2926
2927 my $test_file = File::Spec->rel2abs("$home_dir/üöä");
2928
2929 my $config = {
2930 PidFile => $pid_file,
2931 ScoreboardFile => $scoreboard_file,
2932 SystemLog => $log_file,
2933 TraceLog => $log_file,
2934 Trace => 'encode:20',
2935
2936 AuthUserFile => $auth_user_file,
2937 AuthGroupFile => $auth_group_file,
2938 AuthOrder => 'mod_auth_file.c',
2939
2940 IfModules => {
2941 'mod_delay.c' => {
2942 DelayEngine => 'off',
2943 },
2944
2945 'mod_lang.c' => {
2946 LangOptions => 'RequireValidEncoding',
2947 UseEncoding => 'utf-8 us-ascii',
2948 },
2949 },
2950 };
2951
2952 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2953
2954 # Open pipes, for use between the parent and child processes. Specifically,
2955 # the child will indicate when it's done with its test by writing a message
2956 # to the parent.
2957 my ($rfh, $wfh);
2958 unless (pipe($rfh, $wfh)) {
2959 die("Can't open pipe: $!");
2960 }
2961
2962 my $ex;
2963
2964 # Fork child
2965 $self->handle_sigchld();
2966 defined(my $pid = fork()) or die("Can't fork: $!");
2967 if ($pid) {
2968 eval {
2969 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2970 $client->login($user, $passwd);
2971
2972 my $name = "üöä";
2973
2974 my $conn = $client->stor_raw($name);
2975 if ($conn) {
2976 die("STORE $name succeeded unexpectedly");
2977 }
2978
2979 my $resp_code = $client->response_code();
2980 my $resp_msg = $client->response_msg();
2981
2982 $client->quit();
2983
2984 my $expected = 550;
2985 $self->assert($expected == $resp_code,
2986 test_msg("Expected response code $expected, got $resp_code"));
2987
2988 $expected = 'Illegal character sequence';
2989 $self->assert(qr/$expected/, $resp_msg,
2990 test_msg("Expected response message '$expected', got '$resp_msg'"));
2991 };
2992
2993 if ($@) {
2994 $ex = $@;
2995 }
2996
2997 $wfh->print("done\n");
2998 $wfh->flush();
2999
3000 } else {
3001 eval { server_wait($config_file, $rfh) };
3002 if ($@) {
3003 warn($@);
3004 exit 1;
3005 }
3006
3007 exit 0;
3008 }
3009
3010 # Stop server
3011 server_stop($pid_file);
3012
3013 $self->assert_child_ok($pid);
3014
3015 if ($ex) {
3016 test_append_logfile($log_file, $ex);
3017 unlink($log_file);
3018
3019 die($ex);
3020 }
3021
3022 unlink($log_file);
3023 }
3024
3025 sub lang_useencoding_latin1_utf8_per_user_bug4214 {
3026 my $self = shift;
3027 my $tmpdir = $self->{tmpdir};
3028 my $setup = test_setup($tmpdir, 'lang');
3029
3030 my $test_file = File::Spec->rel2abs("$setup->{home_dir}/üöä");
3031
3032 my $config = {
3033 PidFile => $setup->{pid_file},
3034 ScoreboardFile => $setup->{scoreboard_file},
3035 SystemLog => $setup->{log_file},
3036 TraceLog => $setup->{log_file},
3037 Trace => 'encode:20',
3038
3039 AuthUserFile => $setup->{auth_user_file},
3040 AuthGroupFile => $setup->{auth_group_file},
3041 AuthOrder => 'mod_auth_file.c',
3042
3043 IfModules => {
3044 'mod_delay.c' => {
3045 DelayEngine => 'off',
3046 },
3047 },
3048 };
3049
3050 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3051 $config);
3052
3053 if (open(my $fh, ">> $setup->{config_file}")) {
3054 print $fh <<EOC;
3055 <IfModule mod_lang.c>
3056 <IfUser $setup->{user}>
3057 UseEncoding utf-8 iso-8859-1
3058 </IfUser>
3059 </IfModule>
3060 EOC
3061 unless (close($fh)) {
3062 die("Can't write $setup->{config_file}: $!");
3063 }
3064
3065 } else {
3066 die("Can't open $setup->{config_file}: $!");
3067 }
3068
3069 # Open pipes, for use between the parent and child processes. Specifically,
3070 # the child will indicate when it's done with its test by writing a message
3071 # to the parent.
3072 my ($rfh, $wfh);
3073 unless (pipe($rfh, $wfh)) {
3074 die("Can't open pipe: $!");
3075 }
3076
3077 my $ex;
3078
3079 # Fork child
3080 $self->handle_sigchld();
3081 defined(my $pid = fork()) or die("Can't fork: $!");
3082 if ($pid) {
3083 eval {
3084 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3085 $client->login($setup->{user}, $setup->{passwd});
3086
3087 my $name = "üöä";
3088
3089 my $conn = $client->stor_raw($name);
3090 unless ($conn) {
3091 die("STOR $name failed: " . $client->response_code() . " " .
3092 $client->response_msg());
3093 }
3094
3095 my $buf = "Hello, world\n";
3096 $conn->write($buf, length($buf), 15);
3097 eval { $conn->close() };
3098
3099 my $resp_code = $client->response_code();
3100 my $resp_msg = $client->response_msg();
3101 $self->assert_transfer_ok($resp_code, $resp_msg);
3102
3103 $client->quit();
3104
3105 $self->assert(-f $test_file,
3106 test_msg("File $test_file does not exist as expected"));
3107 };
3108
3109 if ($@) {
3110 $ex = $@;
3111 }
3112
3113 $wfh->print("done\n");
3114 $wfh->flush();
3115
3116 } else {
3117 eval { server_wait($setup->{config_file}, $rfh) };
3118 if ($@) {
3119 warn($@);
3120 exit 1;
3121 }
3122
3123 exit 0;
3124 }
3125
3126 # Stop server
3127 server_stop($setup->{pid_file});
3128 $self->assert_child_ok($pid);
3129 test_cleanup($setup->{log_file}, $ex);
3130 }
3131
3132 sub lang_useencoding_utf8_latin1_per_user_bug4214 {
3133 my $self = shift;
3134 my $tmpdir = $self->{tmpdir};
3135 my $setup = test_setup($tmpdir, 'lang');
3136
3137 my $test_file = File::Spec->rel2abs("$setup->{home_dir}/Grafik-Zentrumäüu.png");
3138 if ($^O eq 'darwin') {
3139 # MacOSX hack
3140 $test_file = ('/private' . $test_file);
3141 }
3142
3143 my $config = {
3144 PidFile => $setup->{pid_file},
3145 ScoreboardFile => $setup->{scoreboard_file},
3146 SystemLog => $setup->{log_file},
3147 TraceLog => $setup->{log_file},
3148 Trace => 'encode:20',
3149
3150 AuthUserFile => $setup->{auth_user_file},
3151 AuthGroupFile => $setup->{auth_group_file},
3152 AuthOrder => 'mod_auth_file.c',
3153
3154 IfModules => {
3155 'mod_delay.c' => {
3156 DelayEngine => 'off',
3157 },
3158 },
3159 };
3160
3161 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3162 $config);
3163
3164 if (open(my $fh, ">> $setup->{config_file}")) {
3165 print $fh <<EOC;
3166 <IfModule mod_lang.c>
3167 <IfUser $setup->{user}>
3168 UseEncoding utf-8 iso-8859-1
3169 </IfUser>
3170 </IfModule>
3171 EOC
3172 unless (close($fh)) {
3173 die("Can't write $setup->{config_file}: $!");
3174 }
3175
3176 } else {
3177 die("Can't open $setup->{config_file}: $!");
3178 }
3179
3180 # Open pipes, for use between the parent and child processes. Specifically,
3181 # the child will indicate when it's done with its test by writing a message
3182 # to the parent.
3183 my ($rfh, $wfh);
3184 unless (pipe($rfh, $wfh)) {
3185 die("Can't open pipe: $!");
3186 }
3187
3188 my $ex;
3189
3190 # Fork child
3191 $self->handle_sigchld();
3192 defined(my $pid = fork()) or die("Can't fork: $!");
3193 if ($pid) {
3194 eval {
3195 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3196 $client->login($setup->{user}, $setup->{passwd});
3197
3198 my $name = "Grafik-Zentrumäüu.png";
3199
3200 my $conn = $client->stor_raw($name);
3201 unless ($conn) {
3202 die("STOR $name failed: " . $client->response_code() . " " .
3203 $client->response_msg());
3204 }
3205
3206 my $buf = "Hello, world\n";
3207 $conn->write($buf, length($buf), 15);
3208 eval { $conn->close() };
3209
3210 my $resp_code = $client->response_code();
3211 my $resp_msg = $client->response_msg();
3212 $self->assert_transfer_ok($resp_code, $resp_msg);
3213
3214 $client->quit();
3215
3216 $self->assert(-f $test_file,
3217 test_msg("File $test_file does not exist as expected"));
3218 };
3219
3220 if ($@) {
3221 $ex = $@;
3222 }
3223
3224 $wfh->print("done\n");
3225 $wfh->flush();
3226
3227 } else {
3228 eval { server_wait($setup->{config_file}, $rfh) };
3229 if ($@) {
3230 warn($@);
3231 exit 1;
3232 }
3233
3234 exit 0;
3235 }
3236
3237 # Stop server
3238 server_stop($setup->{pid_file});
3239 $self->assert_child_ok($pid);
3240 test_cleanup($setup->{log_file}, $ex);
3241 }
3242
3243 1;