Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/Limit/XMKD.pm

raw
1 package ProFTPD::Tests::Config::Limit::XMKD;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Path qw(rmtree);
8 use File::Spec;
9 use IO::Handle;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 my $TESTS = {
19 mkd_allowed => {
20 order => ++$order,
21 test_class => [qw(forking)],
22 },
23
24 mkd_denied => {
25 order => ++$order,
26 test_class => [qw(forking)],
27 },
28
29 mkd_denied_group_allowed => {
30 order => ++$order,
31 test_class => [qw(forking)],
32 },
33
34 mkd_denied_class_allowed => {
35 order => ++$order,
36 test_class => [qw(forking)],
37 },
38
39 mkd_denied_classes_allowed => {
40 order => ++$order,
41 test_class => [qw(forking)],
42 },
43
44 xmkd_allowed => {
45 order => ++$order,
46 test_class => [qw(forking)],
47 },
48
49 xmkd_denied => {
50 order => ++$order,
51 test_class => [qw(forking)],
52 },
53
54 xmkd_denied_group_allowed => {
55 order => ++$order,
56 test_class => [qw(forking)],
57 },
58
59 xmkd_denied_class_allowed => {
60 order => ++$order,
61 test_class => [qw(forking)],
62 },
63
64 xmkd_denied_classes_allowed => {
65 order => ++$order,
66 test_class => [qw(forking)],
67 },
68
69 };
70
71 sub new {
72 return shift()->SUPER::new(@_);
73 }
74
75 sub list_tests {
76 return testsuite_get_runnable_tests($TESTS);
77 }
78
79 sub mkd_allowed {
80 my $self = shift;
81 my $tmpdir = $self->{tmpdir};
82
83 my $config_file = "$tmpdir/limit.conf";
84 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
85 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
86
87 my $log_file = File::Spec->rel2abs('tests.log');
88
89 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
90 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
91
92 my $user = 'proftpd';
93 my $passwd = 'test';
94 my $home_dir = File::Spec->rel2abs($tmpdir);
95 my $uid = 500;
96 my $gid = 500;
97
98 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
99 # Make sure that, if we're running as root, that the home directory has
100
101 # permissions/privs set for the account we create
102 if ($< == 0) {
103 unless (chmod(0755, $home_dir)) {
104 die("Can't set perms on $home_dir to 0755: $!");
105 }
106
107 unless (chown($uid, $gid, $home_dir)) {
108 die("Can't set owner of $home_dir to $uid/$gid: $!");
109 }
110 }
111
112 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
113 '/bin/bash');
114 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
115
116 my $config = {
117 PidFile => $pid_file,
118 ScoreboardFile => $scoreboard_file,
119 SystemLog => $log_file,
120
121 AuthUserFile => $auth_user_file,
122 AuthGroupFile => $auth_group_file,
123 AuthOrder => 'mod_auth_file.c',
124
125 IfModules => {
126 'mod_delay.c' => {
127 DelayEngine => 'off',
128 },
129 },
130
131 Limit => {
132 'MKD' => {
133 AllowAll => '',
134 },
135 },
136
137 };
138
139 my ($port, $config_user, $config_group) = config_write($config_file, $config);
140
141 # Open pipes, for use between the parent and child processes. Specifically,
142 # the child will indicate when it's done with its test by writing a message
143 # to the parent.
144 my ($rfh, $wfh);
145 unless (pipe($rfh, $wfh)) {
146 die("Can't open pipe: $!");
147 }
148
149 my $ex;
150
151 # Fork child
152 $self->handle_sigchld();
153 defined(my $pid = fork()) or die("Can't fork: $!");
154 if ($pid) {
155 eval {
156 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
157 $client->login($user, $passwd);
158
159 my ($resp_code, $resp_msg);
160 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
161
162 my $expected;
163
164 $expected = 257;
165 $self->assert($expected == $resp_code,
166 test_msg("Expected $expected, got $resp_code"));
167
168 $expected = "\"$sub_dir\" - Directory successfully created";
169 $self->assert($expected eq $resp_msg,
170 test_msg("Expected '$expected', got '$resp_msg'"));
171
172 eval { rmtree($sub_dir) };
173
174 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
175
176 $expected = 257;
177 $self->assert($expected == $resp_code,
178 test_msg("Expected $expected, got $resp_code"));
179
180 $expected = "\"$sub_dir\" - Directory successfully created";
181 $self->assert($expected eq $resp_msg,
182 test_msg("Expected '$expected', got '$resp_msg'"));
183 };
184
185 if ($@) {
186 $ex = $@;
187 }
188
189 $wfh->print("done\n");
190 $wfh->flush();
191
192 } else {
193 eval { server_wait($config_file, $rfh) };
194 if ($@) {
195 warn($@);
196 exit 1;
197 }
198
199 exit 0;
200 }
201
202 # Stop server
203 server_stop($pid_file);
204
205 $self->assert_child_ok($pid);
206
207 if ($ex) {
208 die($ex);
209 }
210
211 unlink($log_file);
212 }
213
214 sub mkd_denied {
215 my $self = shift;
216 my $tmpdir = $self->{tmpdir};
217
218 my $config_file = "$tmpdir/limit.conf";
219 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
220 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
221
222 my $log_file = File::Spec->rel2abs('tests.log');
223
224 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
225 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
226
227 my $user = 'proftpd';
228 my $passwd = 'test';
229 my $home_dir = File::Spec->rel2abs($tmpdir);
230 my $uid = 500;
231 my $gid = 500;
232
233 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
234
235 # Make sure that, if we're running as root, that the home directory has
236 # permissions/privs set for the account we create
237 if ($< == 0) {
238 unless (chmod(0755, $home_dir)) {
239 die("Can't set perms on $home_dir to 0755: $!");
240 }
241
242 unless (chown($uid, $gid, $home_dir)) {
243 die("Can't set owner of $home_dir to $uid/$gid: $!");
244 }
245 }
246
247 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
248 '/bin/bash');
249 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
250
251 my $config = {
252 PidFile => $pid_file,
253 ScoreboardFile => $scoreboard_file,
254 SystemLog => $log_file,
255
256 AuthUserFile => $auth_user_file,
257 AuthGroupFile => $auth_group_file,
258 AuthOrder => 'mod_auth_file.c',
259
260 IfModules => {
261 'mod_delay.c' => {
262 DelayEngine => 'off',
263 },
264 },
265
266 Limit => {
267 'MKD' => {
268 DenyAll => '',
269 },
270 },
271
272 };
273
274 my ($port, $config_user, $config_group) = config_write($config_file, $config);
275
276 # Open pipes, for use between the parent and child processes. Specifically,
277 # the child will indicate when it's done with its test by writing a message
278 # to the parent.
279 my ($rfh, $wfh);
280 unless (pipe($rfh, $wfh)) {
281 die("Can't open pipe: $!");
282 }
283
284 my $ex;
285
286 # Fork child
287 $self->handle_sigchld();
288 defined(my $pid = fork()) or die("Can't fork: $!");
289 if ($pid) {
290 eval {
291 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
292 $client->login($user, $passwd);
293
294 my ($resp_code, $resp_msg);
295 eval { ($resp_code, $resp_msg) = $client->mkd($sub_dir) };
296 unless ($@) {
297 die("MKD succeeded unexpectedly");
298
299 } else {
300 $resp_code = $client->response_code();
301 $resp_msg = $client->response_msg();
302 }
303
304 my $expected;
305
306 $expected = 550;
307 $self->assert($expected == $resp_code,
308 test_msg("Expected $expected, got $resp_code"));
309
310 $expected = "$sub_dir: Permission denied";
311 $self->assert($expected eq $resp_msg,
312 test_msg("Expected '$expected', got '$resp_msg'"));
313
314 eval { ($resp_code, $resp_msg) = $client->xmkd($sub_dir) };
315 unless ($@) {
316 die("XMKD succeeded unexpectedly");
317
318 } else {
319 $resp_code = $client->response_code();
320 $resp_msg = $client->response_msg();
321 }
322
323 $expected = 550;
324 $self->assert($expected == $resp_code,
325 test_msg("Expected $expected, got $resp_code"));
326
327 $expected = "$sub_dir: Permission denied";
328 $self->assert($expected eq $resp_msg,
329 test_msg("Expected '$expected', got '$resp_msg'"));
330 };
331
332 if ($@) {
333 $ex = $@;
334 }
335
336 $wfh->print("done\n");
337 $wfh->flush();
338
339 } else {
340 eval { server_wait($config_file, $rfh) };
341 if ($@) {
342 warn($@);
343 exit 1;
344 }
345
346 exit 0;
347 }
348
349 # Stop server
350 server_stop($pid_file);
351
352 $self->assert_child_ok($pid);
353
354 if ($ex) {
355 die($ex);
356 }
357
358 unlink($log_file);
359 }
360
361 sub mkd_denied_group_allowed {
362 my $self = shift;
363 my $tmpdir = $self->{tmpdir};
364
365 my $config_file = "$tmpdir/limit.conf";
366 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
367 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
368
369 my $log_file = File::Spec->rel2abs('tests.log');
370
371 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
372 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
373
374 my $user = 'proftpd';
375 my $passwd = 'test';
376 my $group = 'ftpd';
377 my $home_dir = File::Spec->rel2abs($tmpdir);
378 my $uid = 500;
379 my $gid = 500;
380
381 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
382
383 # Make sure that, if we're running as root, that the home directory has
384 # permissions/privs set for the account we create
385 if ($< == 0) {
386 unless (chmod(0755, $home_dir)) {
387 die("Can't set perms on $home_dir to 0755: $!");
388 }
389
390 unless (chown($uid, $gid, $home_dir)) {
391 die("Can't set owner of $home_dir to $uid/$gid: $!");
392 }
393 }
394
395 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
396 '/bin/bash');
397 auth_group_write($auth_group_file, $group, $gid, $user);
398
399 my $config = {
400 PidFile => $pid_file,
401 ScoreboardFile => $scoreboard_file,
402 SystemLog => $log_file,
403
404 AuthUserFile => $auth_user_file,
405 AuthGroupFile => $auth_group_file,
406 AuthOrder => 'mod_auth_file.c',
407
408 IfModules => {
409 'mod_delay.c' => {
410 DelayEngine => 'off',
411 },
412 },
413
414 Limit => {
415 MKD => [
416 'Order allow,deny',
417 "AllowGroup $group",
418 'DenyAll',
419 ],
420 },
421
422 };
423
424 my ($port, $config_user, $config_group) = config_write($config_file, $config);
425
426 # Open pipes, for use between the parent and child processes. Specifically,
427 # the child will indicate when it's done with its test by writing a message
428 # to the parent.
429 my ($rfh, $wfh);
430 unless (pipe($rfh, $wfh)) {
431 die("Can't open pipe: $!");
432 }
433
434 my $ex;
435
436 # Fork child
437 $self->handle_sigchld();
438 defined(my $pid = fork()) or die("Can't fork: $!");
439 if ($pid) {
440 eval {
441 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
442 $client->login($user, $passwd);
443
444 my ($resp_code, $resp_msg);
445 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
446
447 my $expected;
448
449 $expected = 257;
450 $self->assert($expected == $resp_code,
451 test_msg("Expected $expected, got $resp_code"));
452
453 $expected = "\"$sub_dir\" - Directory successfully created";
454 $self->assert($expected eq $resp_msg,
455 test_msg("Expected '$expected', got '$resp_msg'"));
456
457 eval { rmtree($sub_dir) };
458
459 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
460
461 $expected = 257;
462 $self->assert($expected == $resp_code,
463 test_msg("Expected $expected, got $resp_code"));
464
465 $expected = "\"$sub_dir\" - Directory successfully created";
466 $self->assert($expected eq $resp_msg,
467 test_msg("Expected '$expected', got '$resp_msg'"));
468 };
469
470 if ($@) {
471 $ex = $@;
472 }
473
474 $wfh->print("done\n");
475 $wfh->flush();
476
477 } else {
478 eval { server_wait($config_file, $rfh) };
479 if ($@) {
480 warn($@);
481 exit 1;
482 }
483
484 exit 0;
485 }
486
487 # Stop server
488 server_stop($pid_file);
489
490 $self->assert_child_ok($pid);
491
492 if ($ex) {
493 die($ex);
494 }
495
496 unlink($log_file);
497 }
498
499 sub mkd_denied_class_allowed {
500 my $self = shift;
501 my $tmpdir = $self->{tmpdir};
502
503 my $config_file = "$tmpdir/limit.conf";
504 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
505 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
506
507 my $log_file = File::Spec->rel2abs('tests.log');
508
509 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
510 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
511
512 my $user = 'proftpd';
513 my $passwd = 'test';
514 my $group = 'ftpd';
515 my $home_dir = File::Spec->rel2abs($tmpdir);
516 my $uid = 500;
517 my $gid = 500;
518 my $class = 'test';
519
520 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
521
522 # Make sure that, if we're running as root, that the home directory has
523 # permissions/privs set for the account we create
524 if ($< == 0) {
525 unless (chmod(0755, $home_dir)) {
526 die("Can't set perms on $home_dir to 0755: $!");
527 }
528
529 unless (chown($uid, $gid, $home_dir)) {
530 die("Can't set owner of $home_dir to $uid/$gid: $!");
531 }
532 }
533
534 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
535 '/bin/bash');
536 auth_group_write($auth_group_file, $group, $gid, $user);
537
538 my $config = {
539 PidFile => $pid_file,
540 ScoreboardFile => $scoreboard_file,
541 SystemLog => $log_file,
542
543 AuthUserFile => $auth_user_file,
544 AuthGroupFile => $auth_group_file,
545 AuthOrder => 'mod_auth_file.c',
546
547 IfModules => {
548 'mod_delay.c' => {
549 DelayEngine => 'off',
550 },
551 },
552
553 Class => {
554 $class => {
555 From => '127.0.0.1',
556 },
557 },
558
559 Limit => {
560 MKD => [
561 'Order allow,deny',
562 "AllowClass $class",
563 'DenyAll',
564 ],
565 },
566
567 };
568
569 my ($port, $config_user, $config_group) = config_write($config_file, $config);
570
571 # Open pipes, for use between the parent and child processes. Specifically,
572 # the child will indicate when it's done with its test by writing a message
573 # to the parent.
574 my ($rfh, $wfh);
575 unless (pipe($rfh, $wfh)) {
576 die("Can't open pipe: $!");
577 }
578
579 my $ex;
580
581 # Fork child
582 $self->handle_sigchld();
583 defined(my $pid = fork()) or die("Can't fork: $!");
584 if ($pid) {
585 eval {
586 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
587 $client->login($user, $passwd);
588
589 my ($resp_code, $resp_msg);
590 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
591
592 my $expected;
593
594 $expected = 257;
595 $self->assert($expected == $resp_code,
596 test_msg("Expected $expected, got $resp_code"));
597
598 $expected = "\"$sub_dir\" - Directory successfully created";
599 $self->assert($expected eq $resp_msg,
600 test_msg("Expected '$expected', got '$resp_msg'"));
601
602 eval { rmtree($sub_dir) };
603
604 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
605
606 $expected = 257;
607 $self->assert($expected == $resp_code,
608 test_msg("Expected $expected, got $resp_code"));
609
610 $expected = "\"$sub_dir\" - Directory successfully created";
611 $self->assert($expected eq $resp_msg,
612 test_msg("Expected '$expected', got '$resp_msg'"));
613 };
614
615 if ($@) {
616 $ex = $@;
617 }
618
619 $wfh->print("done\n");
620 $wfh->flush();
621
622 } else {
623 eval { server_wait($config_file, $rfh) };
624 if ($@) {
625 warn($@);
626 exit 1;
627 }
628
629 exit 0;
630 }
631
632 # Stop server
633 server_stop($pid_file);
634
635 $self->assert_child_ok($pid);
636
637 if ($ex) {
638 die($ex);
639 }
640
641 unlink($log_file);
642 }
643
644 sub mkd_denied_classes_allowed {
645 my $self = shift;
646 my $tmpdir = $self->{tmpdir};
647
648 my $config_file = "$tmpdir/limit.conf";
649 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
650 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
651
652 my $log_file = File::Spec->rel2abs('tests.log');
653
654 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
655 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
656
657 my $user = 'proftpd';
658 my $passwd = 'test';
659 my $group = 'ftpd';
660 my $home_dir = File::Spec->rel2abs($tmpdir);
661 my $uid = 500;
662 my $gid = 500;
663 my $class = 'test';
664
665 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
666
667 # Make sure that, if we're running as root, that the home directory has
668 # permissions/privs set for the account we create
669 if ($< == 0) {
670 unless (chmod(0755, $home_dir)) {
671 die("Can't set perms on $home_dir to 0755: $!");
672 }
673
674 unless (chown($uid, $gid, $home_dir)) {
675 die("Can't set owner of $home_dir to $uid/$gid: $!");
676 }
677 }
678
679 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
680 '/bin/bash');
681 auth_group_write($auth_group_file, $group, $gid, $user);
682
683 my $config = {
684 PidFile => $pid_file,
685 ScoreboardFile => $scoreboard_file,
686 SystemLog => $log_file,
687
688 AuthUserFile => $auth_user_file,
689 AuthGroupFile => $auth_group_file,
690 AuthOrder => 'mod_auth_file.c',
691
692 IfModules => {
693 'mod_delay.c' => {
694 DelayEngine => 'off',
695 },
696 },
697
698 Class => {
699 $class => {
700 From => '127.0.0.1',
701 },
702
703 foo => {
704 From => '127.0.0.2',
705 },
706 },
707
708 Limit => {
709 MKD => [
710 'Order allow,deny',
711 "AllowClass foo,$class",
712 'DenyAll',
713 ],
714 },
715
716 };
717
718 my ($port, $config_user, $config_group) = config_write($config_file, $config);
719
720 # Open pipes, for use between the parent and child processes. Specifically,
721 # the child will indicate when it's done with its test by writing a message
722 # to the parent.
723 my ($rfh, $wfh);
724 unless (pipe($rfh, $wfh)) {
725 die("Can't open pipe: $!");
726 }
727
728 my $ex;
729
730 # Fork child
731 $self->handle_sigchld();
732 defined(my $pid = fork()) or die("Can't fork: $!");
733 if ($pid) {
734 eval {
735 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
736 $client->login($user, $passwd);
737
738 my ($resp_code, $resp_msg);
739 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
740
741 my $expected;
742
743 $expected = 257;
744 $self->assert($expected == $resp_code,
745 test_msg("Expected $expected, got $resp_code"));
746
747 $expected = "\"$sub_dir\" - Directory successfully created";
748 $self->assert($expected eq $resp_msg,
749 test_msg("Expected '$expected', got '$resp_msg'"));
750
751 eval { rmtree($sub_dir) };
752
753 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
754
755 $expected = 257;
756 $self->assert($expected == $resp_code,
757 test_msg("Expected $expected, got $resp_code"));
758
759 $expected = "\"$sub_dir\" - Directory successfully created";
760 $self->assert($expected eq $resp_msg,
761 test_msg("Expected '$expected', got '$resp_msg'"));
762 };
763
764 if ($@) {
765 $ex = $@;
766 }
767
768 $wfh->print("done\n");
769 $wfh->flush();
770
771 } else {
772 eval { server_wait($config_file, $rfh) };
773 if ($@) {
774 warn($@);
775 exit 1;
776 }
777
778 exit 0;
779 }
780
781 # Stop server
782 server_stop($pid_file);
783
784 $self->assert_child_ok($pid);
785
786 if ($ex) {
787 die($ex);
788 }
789
790 unlink($log_file);
791 }
792
793 sub xmkd_allowed {
794 my $self = shift;
795 my $tmpdir = $self->{tmpdir};
796
797 my $config_file = "$tmpdir/limit.conf";
798 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
799 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
800
801 my $log_file = File::Spec->rel2abs('tests.log');
802
803 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
804 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
805
806 my $user = 'proftpd';
807 my $passwd = 'test';
808 my $home_dir = File::Spec->rel2abs($tmpdir);
809 my $uid = 500;
810 my $gid = 500;
811
812 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
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, $home_dir)) {
818 die("Can't set perms on $home_dir to 0755: $!");
819 }
820
821 unless (chown($uid, $gid, $home_dir)) {
822 die("Can't set owner of $home_dir to $uid/$gid: $!");
823 }
824 }
825
826 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
827 '/bin/bash');
828 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
829
830 my $config = {
831 PidFile => $pid_file,
832 ScoreboardFile => $scoreboard_file,
833 SystemLog => $log_file,
834
835 AuthUserFile => $auth_user_file,
836 AuthGroupFile => $auth_group_file,
837 AuthOrder => 'mod_auth_file.c',
838
839 IfModules => {
840 'mod_delay.c' => {
841 DelayEngine => 'off',
842 },
843 },
844
845 Limit => {
846 'XMKD' => {
847 AllowAll => '',
848 },
849 },
850 };
851
852 my ($port, $config_user, $config_group) = config_write($config_file, $config);
853
854 # Open pipes, for use between the parent and child processes. Specifically,
855 # the child will indicate when it's done with its test by writing a message
856 # to the parent.
857 my ($rfh, $wfh);
858 unless (pipe($rfh, $wfh)) {
859 die("Can't open pipe: $!");
860 }
861
862 my $ex;
863
864 # Fork child
865 $self->handle_sigchld();
866 defined(my $pid = fork()) or die("Can't fork: $!");
867 if ($pid) {
868 eval {
869 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
870 $client->login($user, $passwd);
871
872 my ($resp_code, $resp_msg);
873 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
874
875 my $expected;
876
877 $expected = 257;
878 $self->assert($expected == $resp_code,
879 test_msg("Expected $expected, got $resp_code"));
880
881 $expected = "\"$sub_dir\" - Directory successfully created";
882 $self->assert($expected eq $resp_msg,
883 test_msg("Expected '$expected', got '$resp_msg'"));
884
885 eval { rmtree($sub_dir) };
886
887 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
888
889 $expected = 257;
890 $self->assert($expected == $resp_code,
891 test_msg("Expected $expected, got $resp_code"));
892
893 $expected = "\"$sub_dir\" - Directory successfully created";
894 $self->assert($expected eq $resp_msg,
895 test_msg("Expected '$expected', got '$resp_msg'"));
896 };
897
898 if ($@) {
899 $ex = $@;
900 }
901
902 $wfh->print("done\n");
903 $wfh->flush();
904
905 } else {
906 eval { server_wait($config_file, $rfh) };
907 if ($@) {
908 warn($@);
909 exit 1;
910 }
911
912 exit 0;
913 }
914
915 # Stop server
916 server_stop($pid_file);
917
918 $self->assert_child_ok($pid);
919
920 if ($ex) {
921 die($ex);
922 }
923
924 unlink($log_file);
925 }
926
927 sub xmkd_denied {
928 my $self = shift;
929 my $tmpdir = $self->{tmpdir};
930
931 my $config_file = "$tmpdir/limit.conf";
932 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
933 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
934
935 my $log_file = File::Spec->rel2abs('tests.log');
936
937 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
938 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
939
940 my $user = 'proftpd';
941 my $passwd = 'test';
942 my $home_dir = File::Spec->rel2abs($tmpdir);
943 my $uid = 500;
944 my $gid = 500;
945
946 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
947
948 # Make sure that, if we're running as root, that the home directory has
949 # permissions/privs set for the account we create
950 if ($< == 0) {
951 unless (chmod(0755, $home_dir)) {
952 die("Can't set perms on $home_dir to 0755: $!");
953 }
954
955 unless (chown($uid, $gid, $home_dir)) {
956 die("Can't set owner of $home_dir to $uid/$gid: $!");
957 }
958 }
959
960 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
961 '/bin/bash');
962 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
963
964 my $config = {
965 PidFile => $pid_file,
966 ScoreboardFile => $scoreboard_file,
967 SystemLog => $log_file,
968
969 AuthUserFile => $auth_user_file,
970 AuthGroupFile => $auth_group_file,
971 AuthOrder => 'mod_auth_file.c',
972
973 IfModules => {
974 'mod_delay.c' => {
975 DelayEngine => 'off',
976 },
977 },
978
979 Limit => {
980 'XMKD' => {
981 DenyAll => '',
982 },
983 },
984 };
985
986 my ($port, $config_user, $config_group) = config_write($config_file, $config);
987
988 # Open pipes, for use between the parent and child processes. Specifically,
989 # the child will indicate when it's done with its test by writing a message
990 # to the parent.
991 my ($rfh, $wfh);
992 unless (pipe($rfh, $wfh)) {
993 die("Can't open pipe: $!");
994 }
995
996 my $ex;
997
998 # Fork child
999 $self->handle_sigchld();
1000 defined(my $pid = fork()) or die("Can't fork: $!");
1001 if ($pid) {
1002 eval {
1003 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1004 $client->login($user, $passwd);
1005
1006 my ($resp_code, $resp_msg);
1007 eval { ($resp_code, $resp_msg) = $client->xmkd($sub_dir) };
1008 unless ($@) {
1009 die("XMKD succeeded unexpectedly");
1010
1011 } else {
1012 $resp_code = $client->response_code();
1013 $resp_msg = $client->response_msg();
1014 }
1015
1016 my $expected;
1017
1018 $expected = 550;
1019 $self->assert($expected == $resp_code,
1020 test_msg("Expected $expected, got $resp_code"));
1021
1022 $expected = "$sub_dir: Permission denied";
1023 $self->assert($expected eq $resp_msg,
1024 test_msg("Expected '$expected', got '$resp_msg'"));
1025
1026 eval { ($resp_code, $resp_msg) = $client->mkd($sub_dir) };
1027 unless ($@) {
1028 die("MKD succeeded unexpectedly");
1029
1030 } else {
1031 $resp_code = $client->response_code();
1032 $resp_msg = $client->response_msg();
1033 }
1034
1035 $expected = 550;
1036 $self->assert($expected == $resp_code,
1037 test_msg("Expected $expected, got $resp_code"));
1038
1039 $expected = "$sub_dir: Permission denied";
1040 $self->assert($expected eq $resp_msg,
1041 test_msg("Expected '$expected', got '$resp_msg'"));
1042 };
1043
1044 if ($@) {
1045 $ex = $@;
1046 }
1047
1048 $wfh->print("done\n");
1049 $wfh->flush();
1050
1051 } else {
1052 eval { server_wait($config_file, $rfh) };
1053 if ($@) {
1054 warn($@);
1055 exit 1;
1056 }
1057
1058 exit 0;
1059 }
1060
1061 # Stop server
1062 server_stop($pid_file);
1063
1064 $self->assert_child_ok($pid);
1065
1066 if ($ex) {
1067 die($ex);
1068 }
1069
1070 unlink($log_file);
1071 }
1072
1073 sub xmkd_denied_group_allowed {
1074 my $self = shift;
1075 my $tmpdir = $self->{tmpdir};
1076
1077 my $config_file = "$tmpdir/limit.conf";
1078 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
1079 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
1080
1081 my $log_file = File::Spec->rel2abs('tests.log');
1082
1083 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
1084 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
1085
1086 my $user = 'proftpd';
1087 my $passwd = 'test';
1088 my $group = 'ftpd';
1089 my $home_dir = File::Spec->rel2abs($tmpdir);
1090 my $uid = 500;
1091 my $gid = 500;
1092
1093 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1094
1095 # Make sure that, if we're running as root, that the home directory has
1096 # permissions/privs set for the account we create
1097 if ($< == 0) {
1098 unless (chmod(0755, $home_dir)) {
1099 die("Can't set perms on $home_dir to 0755: $!");
1100 }
1101
1102 unless (chown($uid, $gid, $home_dir)) {
1103 die("Can't set owner of $home_dir to $uid/$gid: $!");
1104 }
1105 }
1106
1107 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1108 '/bin/bash');
1109 auth_group_write($auth_group_file, $group, $gid, $user);
1110
1111 my $config = {
1112 PidFile => $pid_file,
1113 ScoreboardFile => $scoreboard_file,
1114 SystemLog => $log_file,
1115
1116 AuthUserFile => $auth_user_file,
1117 AuthGroupFile => $auth_group_file,
1118 AuthOrder => 'mod_auth_file.c',
1119
1120 IfModules => {
1121 'mod_delay.c' => {
1122 DelayEngine => 'off',
1123 },
1124 },
1125
1126 Limit => {
1127 XMKD => [
1128 'Order allow,deny',
1129 "AllowGroup $group",
1130 'DenyAll',
1131 ],
1132 },
1133 };
1134
1135 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1136
1137 # Open pipes, for use between the parent and child processes. Specifically,
1138 # the child will indicate when it's done with its test by writing a message
1139 # to the parent.
1140 my ($rfh, $wfh);
1141 unless (pipe($rfh, $wfh)) {
1142 die("Can't open pipe: $!");
1143 }
1144
1145 my $ex;
1146
1147 # Fork child
1148 $self->handle_sigchld();
1149 defined(my $pid = fork()) or die("Can't fork: $!");
1150 if ($pid) {
1151 eval {
1152 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1153 $client->login($user, $passwd);
1154
1155 my ($resp_code, $resp_msg);
1156 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
1157
1158 my $expected;
1159
1160 $expected = 257;
1161 $self->assert($expected == $resp_code,
1162 test_msg("Expected $expected, got $resp_code"));
1163
1164 $expected = "\"$sub_dir\" - Directory successfully created";
1165 $self->assert($expected eq $resp_msg,
1166 test_msg("Expected '$expected', got '$resp_msg'"));
1167
1168 eval { rmtree($sub_dir) };
1169
1170 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
1171
1172 $expected = 257;
1173 $self->assert($expected == $resp_code,
1174 test_msg("Expected $expected, got $resp_code"));
1175
1176 $expected = "\"$sub_dir\" - Directory successfully created";
1177 $self->assert($expected eq $resp_msg,
1178 test_msg("Expected '$expected', got '$resp_msg'"));
1179 };
1180
1181 if ($@) {
1182 $ex = $@;
1183 }
1184
1185 $wfh->print("done\n");
1186 $wfh->flush();
1187
1188 } else {
1189 eval { server_wait($config_file, $rfh) };
1190 if ($@) {
1191 warn($@);
1192 exit 1;
1193 }
1194
1195 exit 0;
1196 }
1197
1198 # Stop server
1199 server_stop($pid_file);
1200
1201 $self->assert_child_ok($pid);
1202
1203 if ($ex) {
1204 die($ex);
1205 }
1206
1207 unlink($log_file);
1208 }
1209
1210 sub xmkd_denied_class_allowed {
1211 my $self = shift;
1212 my $tmpdir = $self->{tmpdir};
1213
1214 my $config_file = "$tmpdir/limit.conf";
1215 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
1216 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
1217
1218 my $log_file = File::Spec->rel2abs('tests.log');
1219
1220 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
1221 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
1222
1223 my $user = 'proftpd';
1224 my $passwd = 'test';
1225 my $group = 'ftpd';
1226 my $home_dir = File::Spec->rel2abs($tmpdir);
1227 my $uid = 500;
1228 my $gid = 500;
1229 my $class = 'test';
1230
1231 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1232
1233 # Make sure that, if we're running as root, that the home directory has
1234 # permissions/privs set for the account we create
1235 if ($< == 0) {
1236 unless (chmod(0755, $home_dir)) {
1237 die("Can't set perms on $home_dir to 0755: $!");
1238 }
1239
1240 unless (chown($uid, $gid, $home_dir)) {
1241 die("Can't set owner of $home_dir to $uid/$gid: $!");
1242 }
1243 }
1244
1245 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1246 '/bin/bash');
1247 auth_group_write($auth_group_file, $group, $gid, $user);
1248
1249 my $config = {
1250 PidFile => $pid_file,
1251 ScoreboardFile => $scoreboard_file,
1252 SystemLog => $log_file,
1253
1254 AuthUserFile => $auth_user_file,
1255 AuthGroupFile => $auth_group_file,
1256 AuthOrder => 'mod_auth_file.c',
1257
1258 IfModules => {
1259 'mod_delay.c' => {
1260 DelayEngine => 'off',
1261 },
1262 },
1263
1264 Class => {
1265 $class => {
1266 From => '127.0.0.1',
1267 },
1268 },
1269
1270 Limit => {
1271 XMKD => [
1272 'Order allow,deny',
1273 "AllowClass $class",
1274 'DenyAll',
1275 ],
1276 },
1277 };
1278
1279 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1280
1281 # Open pipes, for use between the parent and child processes. Specifically,
1282 # the child will indicate when it's done with its test by writing a message
1283 # to the parent.
1284 my ($rfh, $wfh);
1285 unless (pipe($rfh, $wfh)) {
1286 die("Can't open pipe: $!");
1287 }
1288
1289 my $ex;
1290
1291 # Fork child
1292 $self->handle_sigchld();
1293 defined(my $pid = fork()) or die("Can't fork: $!");
1294 if ($pid) {
1295 eval {
1296 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1297 $client->login($user, $passwd);
1298
1299 my ($resp_code, $resp_msg);
1300 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
1301
1302 my $expected;
1303
1304 $expected = 257;
1305 $self->assert($expected == $resp_code,
1306 test_msg("Expected $expected, got $resp_code"));
1307
1308 $expected = "\"$sub_dir\" - Directory successfully created";
1309 $self->assert($expected eq $resp_msg,
1310 test_msg("Expected '$expected', got '$resp_msg'"));
1311
1312 eval { rmtree($sub_dir) };
1313
1314 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
1315
1316 $expected = 257;
1317 $self->assert($expected == $resp_code,
1318 test_msg("Expected $expected, got $resp_code"));
1319
1320 $expected = "\"$sub_dir\" - Directory successfully created";
1321 $self->assert($expected eq $resp_msg,
1322 test_msg("Expected '$expected', got '$resp_msg'"));
1323 };
1324
1325 if ($@) {
1326 $ex = $@;
1327 }
1328
1329 $wfh->print("done\n");
1330 $wfh->flush();
1331
1332 } else {
1333 eval { server_wait($config_file, $rfh) };
1334 if ($@) {
1335 warn($@);
1336 exit 1;
1337 }
1338
1339 exit 0;
1340 }
1341
1342 # Stop server
1343 server_stop($pid_file);
1344
1345 $self->assert_child_ok($pid);
1346
1347 if ($ex) {
1348 die($ex);
1349 }
1350
1351 unlink($log_file);
1352 }
1353
1354 sub xmkd_denied_classes_allowed {
1355 my $self = shift;
1356 my $tmpdir = $self->{tmpdir};
1357
1358 my $config_file = "$tmpdir/limit.conf";
1359 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
1360 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
1361
1362 my $log_file = File::Spec->rel2abs('tests.log');
1363
1364 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
1365 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
1366
1367 my $user = 'proftpd';
1368 my $passwd = 'test';
1369 my $group = 'ftpd';
1370 my $home_dir = File::Spec->rel2abs($tmpdir);
1371 my $uid = 500;
1372 my $gid = 500;
1373 my $class = 'test';
1374
1375 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
1376
1377 # Make sure that, if we're running as root, that the home directory has
1378 # permissions/privs set for the account we create
1379 if ($< == 0) {
1380 unless (chmod(0755, $home_dir)) {
1381 die("Can't set perms on $home_dir to 0755: $!");
1382 }
1383
1384 unless (chown($uid, $gid, $home_dir)) {
1385 die("Can't set owner of $home_dir to $uid/$gid: $!");
1386 }
1387 }
1388
1389 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1390 '/bin/bash');
1391 auth_group_write($auth_group_file, $group, $gid, $user);
1392
1393 my $config = {
1394 PidFile => $pid_file,
1395 ScoreboardFile => $scoreboard_file,
1396 SystemLog => $log_file,
1397
1398 AuthUserFile => $auth_user_file,
1399 AuthGroupFile => $auth_group_file,
1400 AuthOrder => 'mod_auth_file.c',
1401
1402 IfModules => {
1403 'mod_delay.c' => {
1404 DelayEngine => 'off',
1405 },
1406 },
1407
1408 Class => {
1409 $class => {
1410 From => '127.0.0.1',
1411 },
1412
1413 foo => {
1414 From => '127.0.0.2',
1415 },
1416 },
1417
1418 Limit => {
1419 XMKD => [
1420 'Order allow,deny',
1421 "AllowClass foo,$class",
1422 'DenyAll',
1423 ],
1424 },
1425 };
1426
1427 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1428
1429 # Open pipes, for use between the parent and child processes. Specifically,
1430 # the child will indicate when it's done with its test by writing a message
1431 # to the parent.
1432 my ($rfh, $wfh);
1433 unless (pipe($rfh, $wfh)) {
1434 die("Can't open pipe: $!");
1435 }
1436
1437 my $ex;
1438
1439 # Fork child
1440 $self->handle_sigchld();
1441 defined(my $pid = fork()) or die("Can't fork: $!");
1442 if ($pid) {
1443 eval {
1444 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1445 $client->login($user, $passwd);
1446
1447 my ($resp_code, $resp_msg);
1448 ($resp_code, $resp_msg) = $client->mkd($sub_dir);
1449
1450 my $expected;
1451
1452 $expected = 257;
1453 $self->assert($expected == $resp_code,
1454 test_msg("Expected $expected, got $resp_code"));
1455
1456 $expected = "\"$sub_dir\" - Directory successfully created";
1457 $self->assert($expected eq $resp_msg,
1458 test_msg("Expected '$expected', got '$resp_msg'"));
1459
1460 eval { rmtree($sub_dir) };
1461
1462 ($resp_code, $resp_msg) = $client->xmkd($sub_dir);
1463
1464 $expected = 257;
1465 $self->assert($expected == $resp_code,
1466 test_msg("Expected $expected, got $resp_code"));
1467
1468 $expected = "\"$sub_dir\" - Directory successfully created";
1469 $self->assert($expected eq $resp_msg,
1470 test_msg("Expected '$expected', got '$resp_msg'"));
1471 };
1472
1473 if ($@) {
1474 $ex = $@;
1475 }
1476
1477 $wfh->print("done\n");
1478 $wfh->flush();
1479
1480 } else {
1481 eval { server_wait($config_file, $rfh) };
1482 if ($@) {
1483 warn($@);
1484 exit 1;
1485 }
1486
1487 exit 0;
1488 }
1489
1490 # Stop server
1491 server_stop($pid_file);
1492
1493 $self->assert_child_ok($pid);
1494
1495 if ($ex) {
1496 die($ex);
1497 }
1498
1499 unlink($log_file);
1500 }
1501
1502 1;