Debian Codegraph @

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

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