Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Commands/CWD.pm

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