Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/AuthAliasOnly.pm

raw
1 package ProFTPD::Tests::Config::AuthAliasOnly;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Spec;
8 use IO::Handle;
9
10 use ProFTPD::TestSuite::FTP;
11 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
12
13 $| = 1;
14
15 my $order = 0;
16
17 my $TESTS = {
18 authaliasonly_on => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 authaliasonly_off_anon_bug2070 => {
24 order => ++$order,
25 test_class => [qw(bug forking rootprivs)],
26 },
27
28 authaliasonly_on_anon_bug3501 => {
29 order => ++$order,
30 test_class => [qw(bug forking rootprivs)],
31 },
32
33 authaliasonly_on_system_bug3501 => {
34 order => ++$order,
35 test_class => [qw(bug forking rootprivs)],
36 },
37
38 authaliasonly_on_anon_bug4255 => {
39 order => ++$order,
40 test_class => [qw(bug forking rootprivs)],
41 },
42
43 authaliasonly_on_anon_bug4314 => {
44 order => ++$order,
45 test_class => [qw(bug forking rootprivs)],
46 },
47
48 };
49
50 sub new {
51 return shift()->SUPER::new(@_);
52 }
53
54 sub list_tests {
55 return testsuite_get_runnable_tests($TESTS);
56 }
57
58 sub authaliasonly_on {
59 my $self = shift;
60 my $tmpdir = $self->{tmpdir};
61 my $setup = test_setup($tmpdir, 'config');
62
63 my $alias = 'ftp';
64
65 my $config = {
66 PidFile => $setup->{pid_file},
67 ScoreboardFile => $setup->{scoreboard_file},
68 SystemLog => $setup->{log_file},
69
70 AuthUserFile => $setup->{auth_user_file},
71 AuthGroupFile => $setup->{auth_group_file},
72 AuthOrder => 'mod_auth_file.c',
73
74 UserAlias => "$alias $setup->{user}",
75 AuthAliasOnly => 'on',
76
77 IfModules => {
78 'mod_delay.c' => {
79 DelayEngine => 'off',
80 },
81 },
82 };
83
84 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
85 $config);
86
87 # Open pipes, for use between the parent and child processes. Specifically,
88 # the child will indicate when it's done with its test by writing a message
89 # to the parent.
90 my ($rfh, $wfh);
91 unless (pipe($rfh, $wfh)) {
92 die("Can't open pipe: $!");
93 }
94
95 my $ex;
96
97 # Fork child
98 $self->handle_sigchld();
99 defined(my $pid = fork()) or die("Can't fork: $!");
100 if ($pid) {
101 eval {
102 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
103 $client->login($alias, $setup->{passwd});
104 $client->quit();
105
106 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
107 eval { $client->login($setup->{user}, $setup->{passwd}) };
108 unless ($@) {
109 die("Login using user '$setup->{user}' succeeded unexpectedly");
110 }
111 };
112
113 if ($@) {
114 $ex = $@;
115 }
116
117 $wfh->print("done\n");
118 $wfh->flush();
119
120 } else {
121 eval { server_wait($setup->{config_file}, $rfh) };
122 if ($@) {
123 warn($@);
124 exit 1;
125 }
126
127 exit 0;
128 }
129
130 # Stop server
131 server_stop($setup->{pid_file});
132 $self->assert_child_ok($pid);
133
134 test_cleanup($setup->{log_file}, $ex);
135 }
136
137 sub authaliasonly_off_anon_bug2070 {
138 my $self = shift;
139 my $tmpdir = $self->{tmpdir};
140
141 my $config_file = "$tmpdir/config.conf";
142 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
143 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
144
145 my $log_file = File::Spec->rel2abs('tests.log');
146
147 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
148 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
149
150 my $user = 'proftpd';
151 my $passwd = 'test';
152 my $home_dir = File::Spec->rel2abs($tmpdir);
153 my $uid = 500;
154 my $gid = 500;
155
156 # Make sure that, if we're running as root, that the home directory has
157 # permissions/privs set for the account we create
158 if ($< == 0) {
159 unless (chmod(0755, $home_dir)) {
160 die("Can't set perms on $home_dir to 0755: $!");
161 }
162
163 unless (chown($uid, $gid, $home_dir)) {
164 die("Can't set owner of $home_dir to $uid/$gid: $!");
165 }
166 }
167
168 my $alias = 'ftptest';
169
170 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
171 '/bin/bash');
172 auth_user_write($auth_user_file, $alias, $passwd, $uid, $gid, $home_dir,
173 '/bin/bash');
174 auth_group_write($auth_group_file, 'ftpd', $gid, "$user,$alias");
175
176 my $config = {
177 PidFile => $pid_file,
178 ScoreboardFile => $scoreboard_file,
179 SystemLog => $log_file,
180 TraceLog => $log_file,
181 Trace => 'auth:20',
182
183 AuthUserFile => $auth_user_file,
184 AuthGroupFile => $auth_group_file,
185 AuthOrder => 'mod_auth_file.c',
186
187 IfModules => {
188 'mod_delay.c' => {
189 DelayEngine => 'off',
190 },
191 },
192 };
193
194 my ($port, $config_user, $config_group) = config_write($config_file, $config);
195
196 if (open(my $fh, ">> $config_file")) {
197 print $fh <<EOC;
198 <Global>
199 AuthAliasOnly off
200 </Global>
201 <Anonymous $home_dir>
202 User $user
203 Group ftpd
204 UserAlias $alias $user
205 RequireValidShell off
206 AuthAliasOnly on
207 AuthUsingAlias off
208 </Anonymous>
209 EOC
210 unless (close($fh)) {
211 die("Can't write $config_file: $!");
212 }
213
214 } else {
215 die("Can't open $config_file: $!");
216 }
217
218 # Open pipes, for use between the parent and child processes. Specifically,
219 # the child will indicate when it's done with its test by writing a message
220 # to the parent.
221 my ($rfh, $wfh);
222 unless (pipe($rfh, $wfh)) {
223 die("Can't open pipe: $!");
224 }
225
226 my $ex;
227
228 # Fork child
229 $self->handle_sigchld();
230 defined(my $pid = fork()) or die("Can't fork: $!");
231 if ($pid) {
232 eval {
233 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
234
235 # Make sure that we are indeed logging in anonymously
236 my ($resp_code, $resp_msg) = $client->login($alias, '[email protected]');
237
238 my $expected = 230;
239 $self->assert($expected == $resp_code,
240 test_msg("Expected response code $expected, got $resp_code"));
241
242 $expected = 'Anonymous access granted, restrictions apply';
243 $self->assert($expected eq $resp_msg,
244 test_msg("Expected response message '$expected', got '$resp_msg'"));
245
246 $client->quit();
247 };
248
249 if ($@) {
250 $ex = $@;
251 }
252
253 $wfh->print("done\n");
254 $wfh->flush();
255
256 } else {
257 eval { server_wait($config_file, $rfh) };
258 if ($@) {
259 warn($@);
260 exit 1;
261 }
262
263 exit 0;
264 }
265
266 # Stop server
267 server_stop($pid_file);
268
269 $self->assert_child_ok($pid);
270
271 if ($ex) {
272 die($ex);
273 }
274
275 unlink($log_file);
276 }
277
278 sub authaliasonly_on_anon_bug3501 {
279 my $self = shift;
280 my $tmpdir = $self->{tmpdir};
281
282 my $config_file = "$tmpdir/config.conf";
283 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
284 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
285
286 my $log_file = File::Spec->rel2abs('tests.log');
287
288 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
289 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
290
291 my $test_file = File::Spec->rel2abs($config_file);
292
293 my $user = 'proftpd';
294 my $passwd = 'test';
295 my $home_dir = File::Spec->rel2abs($tmpdir);
296 my $uid = 500;
297 my $gid = 500;
298
299 # Make sure that, if we're running as root, that the home directory has
300 # permissions/privs set for the account we create
301 if ($< == 0) {
302 unless (chmod(0755, $home_dir)) {
303 die("Can't set perms on $home_dir to 0755: $!");
304 }
305
306 unless (chown($uid, $gid, $home_dir)) {
307 die("Can't set owner of $home_dir to $uid/$gid: $!");
308 }
309 }
310
311 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
312 '/bin/bash');
313 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
314
315 my ($config_user, $config_group) = config_get_identity();
316
317 my $config = {
318 PidFile => $pid_file,
319 ScoreboardFile => $scoreboard_file,
320 SystemLog => $log_file,
321 User => $config_user,
322 Group => $config_group,
323
324 AuthUserFile => $auth_user_file,
325 AuthGroupFile => $auth_group_file,
326 AuthOrder => 'mod_auth_file.c',
327
328 Anonymous => {
329 $home_dir => {
330 User => $config_user,
331 Group => $config_group,
332 RequireValidShell => 'off',
333 UserAlias => "anonymous $config_user",
334 AuthAliasOnly => 'on',
335 },
336 },
337
338 IfModules => {
339 'mod_delay.c' => {
340 DelayEngine => 'off',
341 },
342 },
343 };
344
345 my $port;
346 ($port, $config_user, $config_group) = config_write($config_file, $config);
347
348 # Open pipes, for use between the parent and child processes. Specifically,
349 # the child will indicate when it's done with its test by writing a message
350 # to the parent.
351 my ($rfh, $wfh);
352 unless (pipe($rfh, $wfh)) {
353 die("Can't open pipe: $!");
354 }
355
356 my $ex;
357
358 # Fork child
359 $self->handle_sigchld();
360 defined(my $pid = fork()) or die("Can't fork: $!");
361 if ($pid) {
362 eval {
363 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
364 my ($resp_code, $resp_msg) = $client->user($config_user);
365
366 my $expected = 331;
367 $self->assert($expected == $resp_code,
368 test_msg("Expected response code $expected, got $resp_code"));
369
370 # Since AuthAliasOnly is true, it means that that anonymous login can
371 # ONLY happen via the alias, NOT via the configured User.
372 $expected = "Password required for $config_user";
373 $self->assert($expected eq $resp_msg,
374 test_msg("Expected response message '$expected', got '$resp_msg'"));
375
376 # What about using the alias, though?
377 ($resp_code, $resp_msg) = $client->user('anonymous');
378
379 $expected = 331;
380 $self->assert($expected == $resp_code,
381 test_msg("Expected response code $expected, got $resp_code"));
382
383 $expected = "Anonymous login ok, send your complete email address as your password";
384 $self->assert($expected eq $resp_msg,
385 test_msg("Expected response message '$expected', got '$resp_msg'"));
386 $client->quit();
387 };
388
389 if ($@) {
390 $ex = $@;
391 }
392
393 $wfh->print("done\n");
394 $wfh->flush();
395
396 } else {
397 eval { server_wait($config_file, $rfh) };
398 if ($@) {
399 warn($@);
400 exit 1;
401 }
402
403 exit 0;
404 }
405
406 # Stop server
407 server_stop($pid_file);
408
409 $self->assert_child_ok($pid);
410 if ($ex) {
411 die($ex);
412 }
413
414 unlink($log_file);
415 }
416
417 sub authaliasonly_on_system_bug3501 {
418 my $self = shift;
419 my $tmpdir = $self->{tmpdir};
420
421 my $config_file = "$tmpdir/config.conf";
422 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
423 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
424
425 my $log_file = File::Spec->rel2abs('tests.log');
426
427 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
428 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
429
430 my $test_file = File::Spec->rel2abs($config_file);
431
432 my $user = 'proftpd';
433 my $passwd = 'test';
434 my $home_dir = File::Spec->rel2abs($tmpdir);
435 my $uid = 500;
436 my $gid = 500;
437
438 # Make sure that, if we're running as root, that the home directory has
439 # permissions/privs set for the account we create
440 if ($< == 0) {
441 unless (chmod(0755, $home_dir)) {
442 die("Can't set perms on $home_dir to 0755: $!");
443 }
444
445 unless (chown($uid, $gid, $home_dir)) {
446 die("Can't set owner of $home_dir to $uid/$gid: $!");
447 }
448 }
449
450 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
451 '/bin/bash');
452 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
453
454 my ($config_user, $config_group) = config_get_identity();
455
456 my $config = {
457 PidFile => $pid_file,
458 ScoreboardFile => $scoreboard_file,
459 SystemLog => $log_file,
460 User => $config_user,
461 Group => $config_group,
462 DefaultServer => 'on',
463 RequireValidShell => 'on',
464
465 AuthUserFile => $auth_user_file,
466 AuthGroupFile => $auth_group_file,
467 AuthOrder => 'mod_auth_file.c',
468
469 Anonymous => {
470 $home_dir => {
471 User => $config_user,
472 Group => $config_group,
473 RequireValidShell => 'on',
474 UserAlias => "anonymous $config_user",
475 AuthAliasOnly => 'on',
476
477 Limit => {
478 WRITE => {
479 DenyAll => '',
480 },
481 },
482 },
483 },
484
485 IfModules => {
486 'mod_delay.c' => {
487 DelayEngine => 'off',
488 },
489 },
490 };
491
492 my $port;
493 ($port, $config_user, $config_group) = config_write($config_file, $config);
494
495 # Open pipes, for use between the parent and child processes. Specifically,
496 # the child will indicate when it's done with its test by writing a message
497 # to the parent.
498 my ($rfh, $wfh);
499 unless (pipe($rfh, $wfh)) {
500 die("Can't open pipe: $!");
501 }
502
503 my $ex;
504
505 # Fork child
506 $self->handle_sigchld();
507 defined(my $pid = fork()) or die("Can't fork: $!");
508 if ($pid) {
509 eval {
510 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
511 my ($resp_code, $resp_msg) = $client->user($user);
512
513 my $expected = 331;
514 $self->assert($expected == $resp_code,
515 test_msg("Expected response code $expected, got $resp_code"));
516
517 $expected = "Password required for $user";
518 $self->assert($expected eq $resp_msg,
519 test_msg("Expected response message '$expected', got '$resp_msg'"));
520
521 $client->quit();
522 };
523
524 if ($@) {
525 $ex = $@;
526 }
527
528 $wfh->print("done\n");
529 $wfh->flush();
530
531 } else {
532 eval { server_wait($config_file, $rfh) };
533 if ($@) {
534 warn($@);
535 exit 1;
536 }
537
538 exit 0;
539 }
540
541 # Stop server
542 server_stop($pid_file);
543
544 $self->assert_child_ok($pid);
545 if ($ex) {
546 die($ex);
547 }
548
549 unlink($log_file);
550 }
551
552 sub authaliasonly_on_anon_bug4255 {
553 my $self = shift;
554 my $tmpdir = $self->{tmpdir};
555 my $setup = test_setup($tmpdir, 'config');
556
557 my ($config_user, $config_group) = config_get_identity();
558
559 my $config = {
560 PidFile => $setup->{pid_file},
561 ScoreboardFile => $setup->{scoreboard_file},
562 SystemLog => $setup->{log_file},
563 TraceLog => $setup->{log_file},
564 Trace => 'auth:20',
565
566 User => $config_user,
567 Group => $config_group,
568
569 AuthUserFile => $setup->{auth_user_file},
570 AuthGroupFile => $setup->{auth_group_file},
571 AuthOrder => 'mod_auth_file.c',
572
573 AuthAliasOnly => 'on',
574
575 Anonymous => {
576 $setup->{home_dir} => {
577 User => $config_user,
578 Group => $config_group,
579 RequireValidShell => 'off',
580 UserAlias => "anonymous $config_user",
581 },
582 },
583
584 IfModules => {
585 'mod_delay.c' => {
586 DelayEngine => 'off',
587 },
588 },
589 };
590
591 my $port;
592 ($port, $config_user, $config_group) = config_write($setup->{config_file},
593 $config);
594
595 # Open pipes, for use between the parent and child processes. Specifically,
596 # the child will indicate when it's done with its test by writing a message
597 # to the parent.
598 my ($rfh, $wfh);
599 unless (pipe($rfh, $wfh)) {
600 die("Can't open pipe: $!");
601 }
602
603 my $ex;
604
605 # Fork child
606 $self->handle_sigchld();
607 defined(my $pid = fork()) or die("Can't fork: $!");
608 if ($pid) {
609 eval {
610 sleep(1);
611
612 # First, try logging in as user 'anonymous', i.e. the alias.
613 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
614 my ($resp_code, $resp_msg) = $client->user("anonymous");
615
616 my $expected = 331;
617 $self->assert($expected == $resp_code,
618 test_msg("Expected response code $expected, got $resp_code"));
619
620 $expected = 'Anonymous login ok, send your complete email address as your password';
621 $self->assert($expected eq $resp_msg,
622 test_msg("Expected response message '$expected', got '$resp_msg'"));
623
624 ($resp_code, $resp_msg) = $client->pass('[email protected]');
625
626 $expected = 230;
627 $self->assert($expected == $resp_code,
628 test_msg("Expected response code $expected, got $resp_code"));
629
630 $expected = 'Anonymous access granted, restrictions apply';
631 $self->assert($expected eq $resp_msg,
632 test_msg("Expected response message '$expected', got '$resp_msg'"));
633
634 $client->quit();
635 };
636
637 if ($@) {
638 $ex = $@;
639 }
640
641 $wfh->print("done\n");
642 $wfh->flush();
643
644 } else {
645 eval { server_wait($setup->{config_file}, $rfh) };
646 if ($@) {
647 warn($@);
648 exit 1;
649 }
650
651 exit 0;
652 }
653
654 # Stop server
655 server_stop($setup->{pid_file});
656 $self->assert_child_ok($pid);
657
658 test_cleanup($setup->{log_file}, $ex);
659 }
660
661 sub authaliasonly_on_anon_bug4314 {
662 my $self = shift;
663 my $tmpdir = $self->{tmpdir};
664 my $setup = test_setup($tmpdir, 'config');
665
666 my ($config_user, $config_group) = config_get_identity();
667
668 my $config = {
669 PidFile => $setup->{pid_file},
670 ScoreboardFile => $setup->{scoreboard_file},
671 SystemLog => $setup->{log_file},
672 TraceLog => $setup->{log_file},
673 Trace => 'auth:20',
674
675 User => $config_user,
676 Group => $config_group,
677
678 AuthUserFile => $setup->{auth_user_file},
679 AuthGroupFile => $setup->{auth_group_file},
680 AuthOrder => 'mod_auth_file.c',
681
682 Anonymous => {
683 $setup->{home_dir} => {
684 User => $setup->{user},
685 Group => $setup->{group},
686 RequireValidShell => 'off',
687 UserAlias => "anonymous $setup->{user}",
688 AuthAliasOnly => 'on',
689 AnonRequirePassword => 'off',
690 },
691 },
692
693 IfModules => {
694 'mod_delay.c' => {
695 DelayEngine => 'off',
696 },
697 },
698 };
699
700 my $port;
701 ($port, $config_user, $config_group) = config_write($setup->{config_file},
702 $config);
703
704 # Open pipes, for use between the parent and child processes. Specifically,
705 # the child will indicate when it's done with its test by writing a message
706 # to the parent.
707 my ($rfh, $wfh);
708 unless (pipe($rfh, $wfh)) {
709 die("Can't open pipe: $!");
710 }
711
712 my $ex;
713
714 # Fork child
715 $self->handle_sigchld();
716 defined(my $pid = fork()) or die("Can't fork: $!");
717 if ($pid) {
718 eval {
719 sleep(1);
720
721 # First, try logging in as user 'anonymous', i.e. the alias.
722 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
723 my ($resp_code, $resp_msg) = $client->user("anonymous");
724
725 my $expected = 331;
726 $self->assert($expected == $resp_code,
727 "Expected response code $expected, got $resp_code");
728
729 $expected = 'Anonymous login ok, send your complete email address as your password';
730 $self->assert($expected eq $resp_msg,
731 "Expected response message '$expected', got '$resp_msg'");
732
733 ($resp_code, $resp_msg) = $client->pass('[email protected]');
734
735 $expected = 230;
736 $self->assert($expected == $resp_code,
737 "Expected response code $expected, got $resp_code");
738
739 $expected = 'Anonymous access granted, restrictions apply';
740 $self->assert($expected eq $resp_msg,
741 "Expected response message '$expected', got '$resp_msg'");
742
743 $client->quit();
744 };
745 if ($@) {
746 $ex = $@;
747 }
748
749 $wfh->print("done\n");
750 $wfh->flush();
751
752 } else {
753 eval { server_wait($setup->{config_file}, $rfh) };
754 if ($@) {
755 warn($@);
756 exit 1;
757 }
758
759 exit 0;
760 }
761
762 # Stop server
763 server_stop($setup->{pid_file});
764 $self->assert_child_ok($pid);
765
766 test_cleanup($setup->{log_file}, $ex);
767 }
768
769 1;