Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::DirFakeUser;
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 dirfakeuser_list => {
19 order => ++$order,
20 test_class => [qw(forking)],
21 },
22
23 dirfakeuser_mlsd_bug3604 => {
24 order => ++$order,
25 test_class => [qw(bug forking)],
26 },
27
28 dirfakeuser_mlst_bug3604 => {
29 order => ++$order,
30 test_class => [qw(bug forking)],
31 },
32
33 dirfakeuser_mlsd_bug3715 => {
34 order => ++$order,
35 test_class => [qw(bug forking)],
36 },
37
38 dirfakeuser_off_mlsd_bug3734 => {
39 order => ++$order,
40 test_class => [qw(bug forking)],
41 },
42
43 dirfakeuser_off_mlst_bug3734 => {
44 order => ++$order,
45 test_class => [qw(bug forking)],
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 dirfakeuser_list {
59 my $self = shift;
60 my $tmpdir = $self->{tmpdir};
61
62 my $config_file = "$tmpdir/config.conf";
63 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
64 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
65
66 my $log_file = test_get_logfile();
67
68 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
69 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
70
71 my $user = 'proftpd';
72 my $passwd = 'test';
73 my $group = 'ftpd';
74 my $home_dir = File::Spec->rel2abs($tmpdir);
75 my $uid = 500;
76 my $gid = 500;
77
78 # Make sure that, if we're running as root, that the home directory has
79 # permissions/privs set for the account we create
80 if ($< == 0) {
81 unless (chmod(0755, $home_dir)) {
82 die("Can't set perms on $home_dir to 0755: $!");
83 }
84
85 unless (chown($uid, $gid, $home_dir)) {
86 die("Can't set owner of $home_dir to $uid/$gid: $!");
87 }
88 }
89
90 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
91 '/bin/bash');
92 auth_group_write($auth_group_file, $group, $gid, $user);
93
94 my $fake_user = 'foo';
95
96 my $config = {
97 PidFile => $pid_file,
98 ScoreboardFile => $scoreboard_file,
99 SystemLog => $log_file,
100
101 AuthUserFile => $auth_user_file,
102 AuthGroupFile => $auth_group_file,
103 AuthOrder => 'mod_auth_file.c',
104
105 DirFakeUser => "on $fake_user",
106
107 IfModules => {
108 'mod_delay.c' => {
109 DelayEngine => 'off',
110 },
111 },
112 };
113
114 my ($port, $config_user, $config_group) = config_write($config_file, $config);
115
116 # Open pipes, for use between the parent and child processes. Specifically,
117 # the child will indicate when it's done with its test by writing a message
118 # to the parent.
119 my ($rfh, $wfh);
120 unless (pipe($rfh, $wfh)) {
121 die("Can't open pipe: $!");
122 }
123
124 my $ex;
125
126 # Fork child
127 $self->handle_sigchld();
128 defined(my $pid = fork()) or die("Can't fork: $!");
129 if ($pid) {
130 eval {
131 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
132 $client->login($user, $passwd);
133
134 my $conn = $client->list_raw();
135 unless ($conn) {
136 die("Failed to LIST: " . $client->response_code() . " " .
137 $client->response_msg());
138 }
139
140 my $buf;
141 $conn->read($buf, 16384, 25);
142 eval { $conn->close() };
143
144 my $resp_code = $client->response_code();
145 my $resp_msg = $client->response_msg();
146 $self->assert_transfer_ok($resp_code, $resp_msg);
147
148 $client->quit();
149
150 # We have to be careful of the fact that readdir returns directory
151 # entries in an unordered fashion.
152 my $res = {};
153 my $lines = [split(/\n/, $buf)];
154 foreach my $line (@$lines) {
155 if ($line =~ /^\S+\s+\d+\s+(\S+)\s+\S+\s+.*?\s+(\S+)$/) {
156 $res->{$2} = $1;
157 }
158 }
159
160 # Remove the '.' and '..' entries; they aren't relevant for this test
161 delete($res->{'.'});
162 delete($res->{'..'});
163
164 my $expected = {
165 'config.conf' => $fake_user,
166 'config.group' => $fake_user,
167 'config.passwd' => $fake_user,
168 'config.pid' => $fake_user,
169 'config.scoreboard' => $fake_user,
170 'config.scoreboard.lck' => $fake_user,
171 };
172
173 my $file_ok = 1;
174 my $owner_ok = 1;
175
176 my $mismatch;
177 foreach my $name (keys(%$res)) {
178 unless (defined($expected->{$name})) {
179 $mismatch = $name;
180 $file_ok = 0;
181 last;
182 }
183
184 unless ($res->{$name} eq $expected->{$name}) {
185 $mismatch = "$name: $res->{$name}";
186 $owner_ok = 0;
187 last;
188 }
189 }
190
191 unless ($file_ok) {
192 die("Unexpected name '$mismatch' appeared in LIST data")
193 }
194
195 unless ($owner_ok) {
196 die("Unexpected user owner '$mismatch' appeared in LIST data")
197 }
198
199 };
200
201 if ($@) {
202 $ex = $@;
203 }
204
205 $wfh->print("done\n");
206 $wfh->flush();
207
208 } else {
209 eval { server_wait($config_file, $rfh) };
210 if ($@) {
211 warn($@);
212 exit 1;
213 }
214
215 exit 0;
216 }
217
218 # Stop server
219 server_stop($pid_file);
220
221 $self->assert_child_ok($pid);
222
223 if ($ex) {
224 test_append_logfile($log_file, $ex);
225 unlink($log_file);
226
227 die($ex);
228 }
229
230 unlink($log_file);
231 }
232
233 sub dirfakeuser_mlsd_bug3604 {
234 my $self = shift;
235 my $tmpdir = $self->{tmpdir};
236
237 my $config_file = "$tmpdir/config.conf";
238 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
239 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
240
241 my $log_file = test_get_logfile();
242
243 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
244 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
245
246 my $user = 'proftpd';
247 my $passwd = 'test';
248 my $group = 'ftpd';
249 my $home_dir = File::Spec->rel2abs($tmpdir);
250 my $uid = 500;
251 my $gid = 500;
252
253 my $fake_user = 'foo';
254 my $fake_uid = 2476;
255
256 # Make sure that, if we're running as root, that the home directory has
257 # permissions/privs set for the account we create
258 if ($< == 0) {
259 unless (chmod(0755, $home_dir)) {
260 die("Can't set perms on $home_dir to 0755: $!");
261 }
262
263 unless (chown($uid, $gid, $home_dir)) {
264 die("Can't set owner of $home_dir to $uid/$gid: $!");
265 }
266 }
267
268 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
269 '/bin/bash');
270 auth_user_write($auth_user_file, $fake_user, 'test', $fake_uid, $gid,
271 $home_dir, '/bin/bash');
272 auth_group_write($auth_group_file, $group, $gid, $user);
273
274 my $config = {
275 PidFile => $pid_file,
276 ScoreboardFile => $scoreboard_file,
277 SystemLog => $log_file,
278
279 AuthUserFile => $auth_user_file,
280 AuthGroupFile => $auth_group_file,
281 AuthOrder => 'mod_auth_file.c',
282
283 DirFakeUser => "on $fake_user",
284
285 IfModules => {
286 'mod_delay.c' => {
287 DelayEngine => 'off',
288 },
289 },
290 };
291
292 my ($port, $config_user, $config_group) = config_write($config_file, $config);
293
294 # Open pipes, for use between the parent and child processes. Specifically,
295 # the child will indicate when it's done with its test by writing a message
296 # to the parent.
297 my ($rfh, $wfh);
298 unless (pipe($rfh, $wfh)) {
299 die("Can't open pipe: $!");
300 }
301
302 my $ex;
303
304 # Fork child
305 $self->handle_sigchld();
306 defined(my $pid = fork()) or die("Can't fork: $!");
307 if ($pid) {
308 eval {
309 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
310 $client->login($user, $passwd);
311
312 my $conn = $client->mlsd_raw();
313 unless ($conn) {
314 die("Failed to MLSD: " . $client->response_code() . " " .
315 $client->response_msg());
316 }
317
318 my $buf;
319 $conn->read($buf, 16384, 25);
320 eval { $conn->close() };
321
322 my $resp_code = $client->response_code();
323 my $resp_msg = $client->response_msg();
324 $self->assert_transfer_ok($resp_code, $resp_msg);
325
326 $client->quit();
327
328 # We have to be careful of the fact that readdir returns directory
329 # entries in an unordered fashion.
330 my $res = {};
331 my $lines = [split(/\n/, $buf)];
332 foreach my $line (@$lines) {
333 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.mode=\d+;UNIX.owner=(\d+); (.*?)$/) {
334 $res->{$2} = $1;
335 }
336 }
337
338 # Remove the '.' and '..' entries; they aren't relevant for this test
339 delete($res->{'.'});
340 delete($res->{'..'});
341
342 my $expected = {
343 'config.conf' => $fake_uid,
344 'config.group' => $fake_uid,
345 'config.passwd' => $fake_uid,
346 'config.pid' => $fake_uid,
347 'config.scoreboard' => $fake_uid,
348 'config.scoreboard.lck' => $fake_uid,
349 };
350
351 my $file_ok = 1;
352 my $owner_ok = 1;
353
354 my $mismatch;
355 foreach my $name (keys(%$res)) {
356 unless (defined($expected->{$name})) {
357 $mismatch = $name;
358 $file_ok = 0;
359 last;
360 }
361
362 unless ($res->{$name} == $expected->{$name}) {
363 $mismatch = "$name: $res->{$name}";
364 $owner_ok = 0;
365 last;
366 }
367 }
368
369 unless ($file_ok) {
370 die("Unexpected name '$mismatch' appeared in LIST data")
371 }
372
373 unless ($owner_ok) {
374 die("Unexpected UID owner '$mismatch' appeared in LIST data")
375 }
376
377 };
378
379 if ($@) {
380 $ex = $@;
381 }
382
383 $wfh->print("done\n");
384 $wfh->flush();
385
386 } else {
387 eval { server_wait($config_file, $rfh) };
388 if ($@) {
389 warn($@);
390 exit 1;
391 }
392
393 exit 0;
394 }
395
396 # Stop server
397 server_stop($pid_file);
398
399 $self->assert_child_ok($pid);
400
401 if ($ex) {
402 test_append_logfile($log_file, $ex);
403 unlink($log_file);
404
405 die($ex);
406 }
407
408 unlink($log_file);
409 }
410
411 sub dirfakeuser_mlst_bug3604 {
412 my $self = shift;
413 my $tmpdir = $self->{tmpdir};
414 my $setup = test_setup($tmpdir, 'config');
415
416 my $fake_user = 'foo';
417 my $fake_uid = 2476;
418 my $fake_gid = 500;
419
420 auth_user_write($setup->{auth_user_file}, $fake_user, 'test', $fake_uid,
421 $fake_gid, $setup->{home_dir}, '/bin/bash');
422
423 my $config = {
424 PidFile => $setup->{pid_file},
425 ScoreboardFile => $setup->{scoreboard_file},
426 SystemLog => $setup->{log_file},
427 TraceLog => $setup->{log_file},
428 Trace => 'auth:20',
429
430 AuthUserFile => $setup->{auth_user_file},
431 AuthGroupFile => $setup->{auth_group_file},
432 AuthOrder => 'mod_auth_file.c',
433
434 DirFakeUser => "on $fake_user",
435
436 IfModules => {
437 'mod_delay.c' => {
438 DelayEngine => 'off',
439 },
440 },
441 };
442
443 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
444 $config);
445
446 # Open pipes, for use between the parent and child processes. Specifically,
447 # the child will indicate when it's done with its test by writing a message
448 # to the parent.
449 my ($rfh, $wfh);
450 unless (pipe($rfh, $wfh)) {
451 die("Can't open pipe: $!");
452 }
453
454 my $ex;
455
456 # Fork child
457 $self->handle_sigchld();
458 defined(my $pid = fork()) or die("Can't fork: $!");
459 if ($pid) {
460 eval {
461 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
462 $client->login($setup->{user}, $setup->{passwd});
463
464 my ($resp_code, $resp_msg) = $client->mlst('config.conf');
465
466 my $expected = 250;
467 $self->assert($expected == $resp_code,
468 test_msg("Expected response code $expected, got $resp_code"));
469
470 $expected = 'modify=\d+;perm=adfr(w)?;size=\d+;type=file;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=(\d+);UNIX\.ownername=\S+; (.*?)\/config\.conf$';
471 $self->assert(qr/$expected/, $resp_msg,
472 test_msg("Expected response message '$expected', got '$resp_msg'"));
473
474 $client->quit();
475
476 $resp_msg =~ /$expected/;
477 my $file_uid = $2;
478
479 $self->assert($file_uid == $fake_uid,
480 test_msg("Expected $fake_uid, got $file_uid"));
481 };
482 if ($@) {
483 $ex = $@;
484 }
485
486 $wfh->print("done\n");
487 $wfh->flush();
488
489 } else {
490 eval { server_wait($setup->{config_file}, $rfh) };
491 if ($@) {
492 warn($@);
493 exit 1;
494 }
495
496 exit 0;
497 }
498
499 # Stop server
500 server_stop($setup->{pid_file});
501 $self->assert_child_ok($pid);
502
503 test_cleanup($setup->{log_file}, $ex);
504 }
505
506 sub dirfakeuser_mlsd_bug3715 {
507 my $self = shift;
508 my $tmpdir = $self->{tmpdir};
509
510 my $config_file = "$tmpdir/config.conf";
511 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
512 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
513
514 my $log_file = test_get_logfile();
515
516 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
517 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
518
519 my $user = 'proftpd';
520 my $passwd = 'test';
521 my $group = 'ftpd';
522 my $home_dir = File::Spec->rel2abs($tmpdir);
523 my $uid = 500;
524 my $gid = 500;
525
526 my $expected_uid = $<;
527
528 # Make sure that, if we're running as root, that the home directory has
529 # permissions/privs set for the account we create
530 if ($< == 0) {
531 unless (chmod(0755, $home_dir)) {
532 die("Can't set perms on $home_dir to 0755: $!");
533 }
534
535 unless (chown($uid, $gid, $home_dir)) {
536 die("Can't set owner of $home_dir to $uid/$gid: $!");
537 }
538 }
539
540 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
541 '/bin/bash');
542 auth_group_write($auth_group_file, $group, $gid, $user);
543
544 my $config = {
545 PidFile => $pid_file,
546 ScoreboardFile => $scoreboard_file,
547 SystemLog => $log_file,
548
549 AuthUserFile => $auth_user_file,
550 AuthGroupFile => $auth_group_file,
551 AuthOrder => 'mod_auth_file.c',
552
553 DirFakeUser => 'off',
554
555 IfModules => {
556 'mod_delay.c' => {
557 DelayEngine => 'off',
558 },
559 },
560 };
561
562 my ($port, $config_user, $config_group) = config_write($config_file, $config);
563
564 # Open pipes, for use between the parent and child processes. Specifically,
565 # the child will indicate when it's done with its test by writing a message
566 # to the parent.
567 my ($rfh, $wfh);
568 unless (pipe($rfh, $wfh)) {
569 die("Can't open pipe: $!");
570 }
571
572 my $ex;
573
574 # Fork child
575 $self->handle_sigchld();
576 defined(my $pid = fork()) or die("Can't fork: $!");
577 if ($pid) {
578 eval {
579 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
580 $client->login($user, $passwd);
581
582 my $conn = $client->mlsd_raw();
583 unless ($conn) {
584 die("Failed to MLSD: " . $client->response_code() . " " .
585 $client->response_msg());
586 }
587
588 my $buf;
589 $conn->read($buf, 16384, 25);
590 eval { $conn->close() };
591
592 my $resp_code = $client->response_code();
593 my $resp_msg = $client->response_msg();
594 $self->assert_transfer_ok($resp_code, $resp_msg);
595
596 $client->quit();
597
598 # We have to be careful of the fact that readdir returns directory
599 # entries in an unordered fashion.
600 my $res = {};
601 my $lines = [split(/\n/, $buf)];
602 foreach my $line (@$lines) {
603 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.mode=\d+;UNIX.owner=(\d+); (.*?)$/) {
604 $res->{$2} = $1;
605 }
606 }
607
608 # Remove the '.' and '..' entries; they aren't relevant for this test
609 delete($res->{'.'});
610 delete($res->{'..'});
611
612 my $expected = {
613 'config.conf' => $expected_uid,
614 'config.group' => $expected_uid,
615 'config.passwd' => $expected_uid,
616 'config.pid' => $expected_uid,
617 'config.scoreboard' => $expected_uid,
618 'config.scoreboard.lck' => $expected_uid,
619 };
620
621 my $file_ok = 1;
622 my $owner_ok = 1;
623
624 my $mismatch;
625 foreach my $name (keys(%$res)) {
626 unless (defined($expected->{$name})) {
627 $mismatch = $name;
628 $file_ok = 0;
629 last;
630 }
631
632 unless ($res->{$name} == $expected->{$name}) {
633 $mismatch = "$name: $res->{$name}";
634 $owner_ok = 0;
635 last;
636 }
637 }
638
639 unless ($file_ok) {
640 die("Unexpected name '$mismatch' appeared in LIST data")
641 }
642
643 unless ($owner_ok) {
644 die("Unexpected UID owner '$mismatch' appeared in LIST data")
645 }
646
647 };
648
649 if ($@) {
650 $ex = $@;
651 }
652
653 $wfh->print("done\n");
654 $wfh->flush();
655
656 } else {
657 eval { server_wait($config_file, $rfh) };
658 if ($@) {
659 warn($@);
660 exit 1;
661 }
662
663 exit 0;
664 }
665
666 # Stop server
667 server_stop($pid_file);
668
669 $self->assert_child_ok($pid);
670
671 if ($ex) {
672 test_append_logfile($log_file, $ex);
673 unlink($log_file);
674
675 die($ex);
676 }
677
678 unlink($log_file);
679 }
680
681 sub dirfakeuser_off_mlsd_bug3734 {
682 my $self = shift;
683 my $tmpdir = $self->{tmpdir};
684
685 my $config_file = "$tmpdir/config.conf";
686 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
687 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
688
689 my $log_file = test_get_logfile();
690
691 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
692 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
693
694 my $user = 'proftpd';
695 my $passwd = 'test';
696 my $group = 'ftpd';
697 my $home_dir = File::Spec->rel2abs($tmpdir);
698 my $uid = 500;
699 my $gid = 500;
700
701 my $fake_user = 'foo';
702 my $fake_uid = 2476;
703
704 # Make sure that, if we're running as root, that the home directory has
705 # permissions/privs set for the account we create
706 if ($< == 0) {
707 unless (chmod(0755, $home_dir)) {
708 die("Can't set perms on $home_dir to 0755: $!");
709 }
710
711 unless (chown($uid, $gid, $home_dir)) {
712 die("Can't set owner of $home_dir to $uid/$gid: $!");
713 }
714 }
715
716 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
717 '/bin/bash');
718 auth_user_write($auth_user_file, $fake_user, 'test', $fake_uid, $gid,
719 $home_dir, '/bin/bash');
720 auth_group_write($auth_group_file, $group, $gid, $user);
721
722 my $config = {
723 PidFile => $pid_file,
724 ScoreboardFile => $scoreboard_file,
725 SystemLog => $log_file,
726
727 AuthUserFile => $auth_user_file,
728 AuthGroupFile => $auth_group_file,
729 AuthOrder => 'mod_auth_file.c',
730
731 DirFakeUser => "off $fake_user",
732
733 IfModules => {
734 'mod_delay.c' => {
735 DelayEngine => 'off',
736 },
737 },
738 };
739
740 my ($port, $config_user, $config_group) = config_write($config_file, $config);
741
742 # Open pipes, for use between the parent and child processes. Specifically,
743 # the child will indicate when it's done with its test by writing a message
744 # to the parent.
745 my ($rfh, $wfh);
746 unless (pipe($rfh, $wfh)) {
747 die("Can't open pipe: $!");
748 }
749
750 my $ex;
751
752 # Fork child
753 $self->handle_sigchld();
754 defined(my $pid = fork()) or die("Can't fork: $!");
755 if ($pid) {
756 eval {
757 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
758 $client->login($user, $passwd);
759
760 my $conn = $client->mlsd_raw();
761 unless ($conn) {
762 die("Failed to MLSD: " . $client->response_code() . " " .
763 $client->response_msg());
764 }
765
766 my $buf;
767 $conn->read($buf, 16384, 25);
768 eval { $conn->close() };
769
770 my $resp_code = $client->response_code();
771 my $resp_msg = $client->response_msg();
772 $self->assert_transfer_ok($resp_code, $resp_msg);
773
774 $client->quit();
775
776 # We have to be careful of the fact that readdir returns directory
777 # entries in an unordered fashion.
778 my $res = {};
779 my $lines = [split(/\n/, $buf)];
780 foreach my $line (@$lines) {
781 if ($line =~ /^modify=\S+;perm=\S+;type=\S+;unique=\S+;UNIX\.group=\d+;UNIX\.mode=\d+;UNIX.owner=(\d+); (.*?)$/) {
782 $res->{$2} = $1;
783 }
784 }
785
786 # Remove the '.' and '..' entries; they aren't relevant for this test
787 delete($res->{'.'});
788 delete($res->{'..'});
789
790 my $expected = {
791 'config.conf' => $fake_uid,
792 'config.group' => $fake_uid,
793 'config.passwd' => $fake_uid,
794 'config.pid' => $fake_uid,
795 'config.scoreboard' => $fake_uid,
796 'config.scoreboard.lck' => $fake_uid,
797 };
798
799 my $file_ok = 1;
800 my $owner_ok = 1;
801
802 my $mismatch;
803 foreach my $name (keys(%$res)) {
804 unless (defined($expected->{$name})) {
805 $mismatch = $name;
806 $file_ok = 0;
807 last;
808 }
809
810 unless ($res->{$name} == $expected->{$name}) {
811 $mismatch = "$name: $res->{$name}";
812 $owner_ok = 0;
813 last;
814 }
815 }
816
817 unless ($file_ok) {
818 die("Unexpected name '$mismatch' appeared in LIST data")
819 }
820 };
821
822 if ($@) {
823 $ex = $@;
824 }
825
826 $wfh->print("done\n");
827 $wfh->flush();
828
829 } else {
830 eval { server_wait($config_file, $rfh) };
831 if ($@) {
832 warn($@);
833 exit 1;
834 }
835
836 exit 0;
837 }
838
839 # Stop server
840 server_stop($pid_file);
841
842 $self->assert_child_ok($pid);
843
844 if ($ex) {
845 test_append_logfile($log_file, $ex);
846 unlink($log_file);
847
848 die($ex);
849 }
850
851 unlink($log_file);
852 }
853
854 sub dirfakeuser_off_mlst_bug3734 {
855 my $self = shift;
856 my $tmpdir = $self->{tmpdir};
857 my $setup = test_setup($tmpdir, 'config');
858
859 my $fake_user = 'foo';
860 my $fake_uid = 2476;
861 my $fake_gid = 500;
862
863 auth_user_write($setup->{auth_user_file}, $fake_user, 'test', $fake_uid,
864 $fake_gid, $setup->{home_dir}, '/bin/bash');
865
866 my $config = {
867 PidFile => $setup->{pid_file},
868 ScoreboardFile => $setup->{scoreboard_file},
869 SystemLog => $setup->{log_file},
870
871 AuthUserFile => $setup->{auth_user_file},
872 AuthGroupFile => $setup->{auth_group_file},
873 AuthOrder => 'mod_auth_file.c',
874
875 DirFakeUser => "off $fake_user",
876
877 IfModules => {
878 'mod_delay.c' => {
879 DelayEngine => 'off',
880 },
881 },
882 };
883
884 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
885 $config);
886
887 # Open pipes, for use between the parent and child processes. Specifically,
888 # the child will indicate when it's done with its test by writing a message
889 # to the parent.
890 my ($rfh, $wfh);
891 unless (pipe($rfh, $wfh)) {
892 die("Can't open pipe: $!");
893 }
894
895 my $ex;
896
897 # Fork child
898 $self->handle_sigchld();
899 defined(my $pid = fork()) or die("Can't fork: $!");
900 if ($pid) {
901 eval {
902 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
903 $client->login($setup->{user}, $setup->{passwd});
904
905 my ($resp_code, $resp_msg) = $client->mlst('config.conf');
906 $client->quit();
907
908 my $expected = 250;
909 $self->assert($expected == $resp_code,
910 test_msg("Expected response code $expected, got $resp_code"));
911
912 $expected = 'modify=\d+;perm=adfr(w)?;size=\d+;type=file;unique=\S+;UNIX\.group=\d+;UNIX\.groupname=\S+;UNIX\.mode=\d+;UNIX\.owner=(\d+);UNIX\.ownername=\S+; (.*?)\/config\.conf$';
913 $self->assert(qr/$expected/, $resp_msg,
914 test_msg("Expected response message '$expected', got '$resp_msg'"));
915 };
916 if ($@) {
917 $ex = $@;
918 }
919
920 $wfh->print("done\n");
921 $wfh->flush();
922
923 } else {
924 eval { server_wait($setup->{config_file}, $rfh) };
925 if ($@) {
926 warn($@);
927 exit 1;
928 }
929
930 exit 0;
931 }
932
933 # Stop server
934 server_stop($setup->{pid_file});
935 $self->assert_child_ok($pid);
936
937 test_cleanup($setup->{log_file}, $ex);
938 }
939
940 1;