Debian Codegraph @

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

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