Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_site_misc.pm

raw
1 package ProFTPD::Tests::Modules::mod_site_misc;
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 site_misc_mkdir_ok => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 site_misc_mkdir_dir_umask_bug4311 => {
26 order => ++$order,
27 test_class => [qw(bug forking)],
28 },
29
30 site_misc_rmdir_ok => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 site_misc_symlink_ok => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 site_misc_utime_ok => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 site_misc_utime_with_sec_ok => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 site_misc_utime_abs_symlink => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 site_misc_utime_abs_symlink_chrooted_bug4219 => {
56 order => ++$order,
57 test_class => [qw(bug forking rootprivs)],
58 },
59
60 site_misc_utime_rel_symlink => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 site_misc_utime_rel_symlink_chrooted_bug4219 => {
66 order => ++$order,
67 test_class => [qw(bug forking rootprivs)],
68 },
69
70 site_feat_ok => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 # This tests the scenario to which NcFTPd was vulnerable
76 #
77 # http://www.doecirc.energy.gov/bulletins/t-195.shtml
78 site_misc_symlink_ncftpd_chroot_bug => {
79 order => ++$order,
80 test_class => [qw(forking rootprivs)],
81 },
82
83 site_misc_mkdir_failed_bug3518 => {
84 order => ++$order,
85 test_class => [qw(bug forking)],
86 },
87
88 site_misc_rmdir_failed_bug3518 => {
89 order => ++$order,
90 test_class => [qw(bug forking)],
91 },
92
93 site_misc_symlink_failed_bug3518 => {
94 order => ++$order,
95 test_class => [qw(bug forking)],
96 },
97
98 site_misc_utime_failed_bug3518 => {
99 order => ++$order,
100 test_class => [qw(bug forking)],
101 },
102
103 site_misc_mkdir_failed_bug3519 => {
104 order => ++$order,
105 test_class => [qw(bug forking)],
106 },
107
108 site_misc_rmdir_failed_bug3519 => {
109 order => ++$order,
110 test_class => [qw(bug forking)],
111 },
112
113 site_misc_symlink_failed_bug3519 => {
114 order => ++$order,
115 test_class => [qw(bug forking)],
116 },
117
118 site_misc_utime_failed_bug3519 => {
119 order => ++$order,
120 test_class => [qw(bug forking)],
121 },
122
123 site_misc_mkdir_failed_limit => {
124 order => ++$order,
125 test_class => [qw(forking)],
126 },
127
128 site_misc_rmdir_failed_limit => {
129 order => ++$order,
130 test_class => [qw(forking)],
131 },
132
133 site_misc_symlink_failed_limit => {
134 order => ++$order,
135 test_class => [qw(forking)],
136 },
137
138 site_misc_utime_failed_limit => {
139 order => ++$order,
140 test_class => [qw(forking)],
141 },
142
143 site_misc_utime_atime_mtime_ctime_bug4130 => {
144 order => ++$order,
145 test_class => [qw(bug forking)],
146 },
147
148 site_misc_utime_atime_mtime_ctime_with_spaces_bug4130 => {
149 order => ++$order,
150 test_class => [qw(bug forking)],
151 },
152
153 site_misc_extlog_rmdir_resp_code_empty_dir => {
154 order => ++$order,
155 test_class => [qw(forking)],
156 },
157
158 site_misc_extlog_rmdir_resp_code_nonempty_dir => {
159 order => ++$order,
160 test_class => [qw(forking)],
161 },
162
163 site_misc_utime_failed_unauthenticated_issue1976 => {
164 order => ++$order,
165 test_class => [qw(bug forking)],
166 },
167
168 };
169
170 sub new {
171 return shift()->SUPER::new(@_);
172 }
173
174 sub list_tests {
175 return testsuite_get_runnable_tests($TESTS);
176 }
177
178 sub site_misc_mkdir_ok {
179 my $self = shift;
180 my $tmpdir = $self->{tmpdir};
181 my $setup = test_setup($tmpdir, 'site');
182
183 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
184
185 # Make sure that, if we're running as root, that the home directory has
186 # permissions/privs set for the account we create
187 if ($< == 0) {
188 unless (chmod(0755, $test_dir)) {
189 die("Can't set perms on $test_dir to 0755: $!");
190 }
191
192 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
193 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
194 }
195 }
196
197 my $config = {
198 PidFile => $setup->{pid_file},
199 ScoreboardFile => $setup->{scoreboard_file},
200 SystemLog => $setup->{log_file},
201 TraceLog => $setup->{log_file},
202 Trace => 'fsio:10',
203
204 AuthUserFile => $setup->{auth_user_file},
205 AuthGroupFile => $setup->{auth_group_file},
206 AuthOrder => 'mod_auth_file.c',
207
208 IfModules => {
209 'mod_delay.c' => {
210 DelayEngine => 'off',
211 },
212 },
213 };
214
215 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
216 $config);
217
218 # Open pipes, for use between the parent and child processes. Specifically,
219 # the child will indicate when it's done with its test by writing a message
220 # to the parent.
221 my ($rfh, $wfh);
222 unless (pipe($rfh, $wfh)) {
223 die("Can't open pipe: $!");
224 }
225
226 my $ex;
227
228 # Fork child
229 $self->handle_sigchld();
230 defined(my $pid = fork()) or die("Can't fork: $!");
231 if ($pid) {
232 eval {
233 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
234 $client->login($setup->{user}, $setup->{passwd});
235
236 my ($resp_code, $resp_msg) = $client->site('MKDIR', 'foo/bar/baz');
237 $client->quit();
238
239 my $expected = 200;
240 $self->assert($expected == $resp_code,
241 "Expected response code $expected, got $resp_code");
242
243 $expected = "SITE MKDIR command successful";
244 $self->assert($expected eq $resp_msg,
245 "Expected response message '$expected', got '$resp_msg'");
246
247 # Make sure that the test dir is present
248 unless (-d $test_dir) {
249 die("Directory $test_dir does not exist");
250 }
251 };
252 if ($@) {
253 $ex = $@;
254 }
255
256 $wfh->print("done\n");
257 $wfh->flush();
258
259 } else {
260 eval { server_wait($setup->{config_file}, $rfh) };
261 if ($@) {
262 warn($@);
263 exit 1;
264 }
265
266 exit 0;
267 }
268
269 # Stop server
270 server_stop($setup->{pid_file});
271 $self->assert_child_ok($pid);
272
273 test_cleanup($setup->{log_file}, $ex);
274 }
275
276 sub site_misc_mkdir_dir_umask_bug4311 {
277 my $self = shift;
278 my $tmpdir = $self->{tmpdir};
279 my $setup = test_setup($tmpdir, 'site');
280
281 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
282
283 # Make sure that, if we're running as root, that the home directory has
284 # permissions/privs set for the account we create
285 if ($< == 0) {
286 unless (chmod(0755, $test_dir)) {
287 die("Can't set perms on $test_dir to 0755: $!");
288 }
289
290 unless (chown($setup->{uid}, $setup->{gid}, $test_dir)) {
291 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
292 }
293 }
294
295 my $config = {
296 PidFile => $setup->{pid_file},
297 ScoreboardFile => $setup->{scoreboard_file},
298 SystemLog => $setup->{log_file},
299 TraceLog => $setup->{log_file},
300 Trace => 'fsio:10',
301
302 AuthUserFile => $setup->{auth_user_file},
303 AuthGroupFile => $setup->{auth_group_file},
304 AuthOrder => 'mod_auth_file.c',
305
306 Umask => '022 066',
307
308 IfModules => {
309 'mod_delay.c' => {
310 DelayEngine => 'off',
311 },
312 },
313 };
314
315 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
316 $config);
317
318 # Open pipes, for use between the parent and child processes. Specifically,
319 # the child will indicate when it's done with its test by writing a message
320 # to the parent.
321 my ($rfh, $wfh);
322 unless (pipe($rfh, $wfh)) {
323 die("Can't open pipe: $!");
324 }
325
326 my $ex;
327
328 # Fork child
329 $self->handle_sigchld();
330 defined(my $pid = fork()) or die("Can't fork: $!");
331 if ($pid) {
332 eval {
333 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
334 $client->login($setup->{user}, $setup->{passwd});
335
336 my ($resp_code, $resp_msg) = $client->site('MKDIR', 'foo/bar/baz');
337 $client->quit();
338
339 my $expected = 200;
340 $self->assert($expected == $resp_code,
341 "Expected response code $expected, got $resp_code");
342
343 $expected = "SITE MKDIR command successful";
344 $self->assert($expected eq $resp_msg,
345 "Expected response message '$expected', got '$resp_msg'");
346
347 # Make sure that the test dir is present
348 unless (-d $test_dir) {
349 die("Directory $test_dir does not exist");
350 }
351
352 my $perms = sprintf("%04o", ((stat($test_dir))[2] & 07777));
353 $expected = '0711';
354 $self->assert($expected eq $perms,
355 "Expected perms $expected, got $perms");
356 };
357 if ($@) {
358 $ex = $@;
359 }
360
361 $wfh->print("done\n");
362 $wfh->flush();
363
364 } else {
365 eval { server_wait($setup->{config_file}, $rfh) };
366 if ($@) {
367 warn($@);
368 exit 1;
369 }
370
371 exit 0;
372 }
373
374 # Stop server
375 server_stop($setup->{pid_file});
376 $self->assert_child_ok($pid);
377
378 test_cleanup($setup->{log_file}, $ex);
379 }
380
381 sub site_misc_rmdir_ok {
382 my $self = shift;
383 my $tmpdir = $self->{tmpdir};
384
385 my $config_file = "$tmpdir/site.conf";
386 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
387 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
388
389 my $log_file = File::Spec->rel2abs('tests.log');
390
391 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
392 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
393
394 my $user = 'proftpd';
395 my $passwd = 'test';
396 my $home_dir = File::Spec->rel2abs($tmpdir);
397 my $uid = 500;
398 my $gid = 500;
399
400 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
401 mkpath($sub_dir);
402
403 my $test_dirs = [
404 File::Spec->rel2abs("$tmpdir/foo"),
405 File::Spec->rel2abs("$tmpdir/foo/bar"),
406 $sub_dir,
407 ];
408
409 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt");
410 if (open(my $fh, "> $test_file")) {
411 print $fh "Quzz\n";
412
413 unless (close($fh)) {
414 die("Can't write $test_file: $!");
415 }
416
417 } else {
418 die("Can't open $test_file: $!");
419 }
420
421 # Make sure that, if we're running as root, that the home directory has
422 # permissions/privs set for the account we create
423 if ($< == 0) {
424 unless (chmod(0755, $home_dir)) {
425 die("Can't set perms on $home_dir to 0755: $!");
426 }
427
428 unless (chown($uid, $gid, $home_dir)) {
429 die("Can't set owner of $home_dir to $uid/$gid: $!");
430 }
431 }
432
433 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
434 '/bin/bash');
435 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
436
437 my $config = {
438 PidFile => $pid_file,
439 ScoreboardFile => $scoreboard_file,
440 SystemLog => $log_file,
441
442 AuthUserFile => $auth_user_file,
443 AuthGroupFile => $auth_group_file,
444 AuthOrder => 'mod_auth_file.c',
445
446 IfModules => {
447 'mod_delay.c' => {
448 DelayEngine => 'off',
449 },
450 },
451 };
452
453 my ($port, $config_user, $config_group) = config_write($config_file, $config);
454
455 # Open pipes, for use between the parent and child processes. Specifically,
456 # the child will indicate when it's done with its test by writing a message
457 # to the parent.
458 my ($rfh, $wfh);
459 unless (pipe($rfh, $wfh)) {
460 die("Can't open pipe: $!");
461 }
462
463 my $ex;
464
465 # Fork child
466 $self->handle_sigchld();
467 defined(my $pid = fork()) or die("Can't fork: $!");
468 if ($pid) {
469 eval {
470 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
471 $client->login($user, $passwd);
472
473 my ($resp_code, $resp_msg);
474 ($resp_code, $resp_msg) = $client->site('RMDIR', 'foo');
475
476 my $expected;
477
478 $expected = 200;
479 $self->assert($expected == $resp_code,
480 test_msg("Expected $expected, got $resp_code"));
481
482 $expected = "SITE RMDIR command successful";
483 $self->assert($expected eq $resp_msg,
484 test_msg("Expected '$expected', got '$resp_msg'"));
485
486 # Make sure that the test file is gone, along with all of the
487 # test dirs.
488 if (-f $test_file) {
489 die("File $test_file exists, should be deleted");
490 }
491
492 foreach my $test_dir (@$test_dirs) {
493 if (-d $test_dir) {
494 die("Directory $test_dir exists, should be deleted");
495 }
496 }
497 };
498
499 if ($@) {
500 $ex = $@;
501 }
502
503 $wfh->print("done\n");
504 $wfh->flush();
505
506 } else {
507 eval { server_wait($config_file, $rfh) };
508 if ($@) {
509 warn($@);
510 exit 1;
511 }
512
513 exit 0;
514 }
515
516 # Stop server
517 server_stop($pid_file);
518
519 $self->assert_child_ok($pid);
520
521 if ($ex) {
522 die($ex);
523 }
524
525 unlink($log_file);
526 }
527
528 sub site_misc_symlink_ok {
529 my $self = shift;
530 my $tmpdir = $self->{tmpdir};
531
532 my $config_file = "$tmpdir/site.conf";
533 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
534 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
535
536 my $log_file = File::Spec->rel2abs('tests.log');
537
538 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
539 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
540
541 my $user = 'proftpd';
542 my $passwd = 'test';
543 my $home_dir = File::Spec->rel2abs($tmpdir);
544 my $uid = 500;
545 my $gid = 500;
546
547 my $test_symlink = File::Spec->rel2abs("$tmpdir/foo");
548
549 # Make sure that, if we're running as root, that the home directory has
550 # permissions/privs set for the account we create
551 if ($< == 0) {
552 unless (chmod(0755, $home_dir)) {
553 die("Can't set perms on $home_dir to 0755: $!");
554 }
555
556 unless (chown($uid, $gid, $home_dir)) {
557 die("Can't set owner of $home_dir to $uid/$gid: $!");
558 }
559 }
560
561 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
562 '/bin/bash');
563 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
564
565 my $config = {
566 PidFile => $pid_file,
567 ScoreboardFile => $scoreboard_file,
568 SystemLog => $log_file,
569
570 AuthUserFile => $auth_user_file,
571 AuthGroupFile => $auth_group_file,
572 AuthOrder => 'mod_auth_file.c',
573
574 IfModules => {
575 'mod_delay.c' => {
576 DelayEngine => 'off',
577 },
578 },
579 };
580
581 my ($port, $config_user, $config_group) = config_write($config_file, $config);
582
583 # Open pipes, for use between the parent and child processes. Specifically,
584 # the child will indicate when it's done with its test by writing a message
585 # to the parent.
586 my ($rfh, $wfh);
587 unless (pipe($rfh, $wfh)) {
588 die("Can't open pipe: $!");
589 }
590
591 my $ex;
592
593 # Fork child
594 $self->handle_sigchld();
595 defined(my $pid = fork()) or die("Can't fork: $!");
596 if ($pid) {
597 eval {
598 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
599 $client->login($user, $passwd);
600
601 my ($resp_code, $resp_msg);
602 ($resp_code, $resp_msg) = $client->site('SYMLINK', 'site.conf', 'foo');
603
604 my $expected;
605
606 $expected = 200;
607 $self->assert($expected == $resp_code,
608 test_msg("Expected $expected, got $resp_code"));
609
610 $expected = "SITE SYMLINK command successful";
611 $self->assert($expected eq $resp_msg,
612 test_msg("Expected '$expected', got '$resp_msg'"));
613
614 unless (-l $test_symlink) {
615 die("Symlink $test_symlink does not exist");
616 }
617 };
618
619 if ($@) {
620 $ex = $@;
621 }
622
623 $wfh->print("done\n");
624 $wfh->flush();
625
626 } else {
627 eval { server_wait($config_file, $rfh) };
628 if ($@) {
629 warn($@);
630 exit 1;
631 }
632
633 exit 0;
634 }
635
636 # Stop server
637 server_stop($pid_file);
638
639 $self->assert_child_ok($pid);
640
641 if ($ex) {
642 die($ex);
643 }
644
645 unlink($log_file);
646 }
647
648 sub site_misc_utime_ok {
649 my $self = shift;
650 my $tmpdir = $self->{tmpdir};
651 my $setup = test_setup($tmpdir, 'site');
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 sleep(1);
688 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
689 $client->login($setup->{user}, $setup->{passwd});
690
691 my $path = 'site.conf';
692 my ($resp_code, $resp_msg) = $client->site('UTIME', '200002240826',
693 $path);
694 $client->quit();
695
696 my $expected = 200;
697 $self->assert($expected == $resp_code,
698 test_msg("Expected response code $expected, got $resp_code"));
699
700 $expected = "SITE UTIME command successful";
701 $self->assert($expected eq $resp_msg,
702 test_msg("Expected response message '$expected', got '$resp_msg'"));
703
704 my ($atime, $mtime) = (stat($setup->{config_file}))[8,9];
705
706 $expected = 951380760;
707 $self->assert($expected == $atime,
708 test_msg("Expected file atime $expected, got $atime"));
709 $self->assert($expected == $mtime,
710 test_msg("Expected file mtime $expected, got $mtime"));
711 };
712 if ($@) {
713 $ex = $@;
714 }
715
716 $wfh->print("done\n");
717 $wfh->flush();
718
719 } else {
720 eval { server_wait($setup->{config_file}, $rfh) };
721 if ($@) {
722 warn($@);
723 exit 1;
724 }
725
726 exit 0;
727 }
728
729 # Stop server
730 server_stop($setup->{pid_file});
731 $self->assert_child_ok($pid);
732
733 test_cleanup($setup->{log_file}, $ex);
734 }
735
736 sub site_misc_utime_with_sec_ok {
737 my $self = shift;
738 my $tmpdir = $self->{tmpdir};
739
740 my $config_file = "$tmpdir/site.conf";
741 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
742 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
743
744 my $log_file = File::Spec->rel2abs('tests.log');
745
746 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
747 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
748
749 my $user = 'proftpd';
750 my $passwd = 'test';
751 my $home_dir = File::Spec->rel2abs($tmpdir);
752 my $uid = 500;
753 my $gid = 500;
754
755 # Make sure that, if we're running as root, that the home directory has
756 # permissions/privs set for the account we create
757 if ($< == 0) {
758 unless (chmod(0755, $home_dir)) {
759 die("Can't set perms on $home_dir to 0755: $!");
760 }
761
762 unless (chown($uid, $gid, $home_dir)) {
763 die("Can't set owner of $home_dir to $uid/$gid: $!");
764 }
765 }
766
767 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
768 '/bin/bash');
769 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
770
771 my $config = {
772 PidFile => $pid_file,
773 ScoreboardFile => $scoreboard_file,
774 SystemLog => $log_file,
775
776 AuthUserFile => $auth_user_file,
777 AuthGroupFile => $auth_group_file,
778 AuthOrder => 'mod_auth_file.c',
779
780 IfModules => {
781 'mod_delay.c' => {
782 DelayEngine => 'off',
783 },
784 },
785 };
786
787 my ($port, $config_user, $config_group) = config_write($config_file, $config);
788
789 # Open pipes, for use between the parent and child processes. Specifically,
790 # the child will indicate when it's done with its test by writing a message
791 # to the parent.
792 my ($rfh, $wfh);
793 unless (pipe($rfh, $wfh)) {
794 die("Can't open pipe: $!");
795 }
796
797 my $ex;
798
799 # Fork child
800 $self->handle_sigchld();
801 defined(my $pid = fork()) or die("Can't fork: $!");
802 if ($pid) {
803 eval {
804 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
805 $client->login($user, $passwd);
806
807 my ($resp_code, $resp_msg);
808 ($resp_code, $resp_msg) = $client->site('UTIME', '20000224082601',
809 'site.conf');
810
811 my $expected;
812
813 $expected = 200;
814 $self->assert($expected == $resp_code,
815 test_msg("Expected $expected, got $resp_code"));
816
817 $expected = "SITE UTIME command successful";
818 $self->assert($expected eq $resp_msg,
819 test_msg("Expected '$expected', got '$resp_msg'"));
820
821 my ($atime, $mtime) = (stat($config_file))[8,9];
822
823 $expected = 951380761;
824 $self->assert($expected == $atime,
825 test_msg("Expected $expected, got $atime"));
826 $self->assert($expected == $mtime,
827 test_msg("Expected $expected, got $mtime"));
828 };
829
830 if ($@) {
831 $ex = $@;
832 }
833
834 $wfh->print("done\n");
835 $wfh->flush();
836
837 } else {
838 eval { server_wait($config_file, $rfh) };
839 if ($@) {
840 warn($@);
841 exit 1;
842 }
843
844 exit 0;
845 }
846
847 # Stop server
848 server_stop($pid_file);
849
850 $self->assert_child_ok($pid);
851
852 if ($ex) {
853 die($ex);
854 }
855
856 unlink($log_file);
857 }
858
859 sub site_misc_utime_abs_symlink {
860 my $self = shift;
861 my $tmpdir = $self->{tmpdir};
862 my $setup = test_setup($tmpdir, 'site');
863
864 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
865 mkpath($test_dir);
866
867 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
868 if (open(my $fh, "> $test_file")) {
869 print $fh "Hello, World!\n";
870 unless (close($fh)) {
871 die("Can't write $test_file: $!");
872 }
873
874 } else {
875 die("Can't open $test_file: $!");
876 }
877
878 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
879
880 my $dst_path = $test_file;
881 if ($^O eq 'darwin') {
882 # MacOSX-specific hack
883 $dst_path = '/private' . $dst_path;
884 }
885
886 unless (symlink($dst_path, $test_symlink)) {
887 die("Can't symlink $test_symlink to $dst_path: $!");
888 }
889
890 if ($< == 0) {
891 unless (chmod(0755, $test_dir)) {
892 die("Can't set perms on $test_dir to 0755: $!");
893 }
894
895 unless (chown($setup->{uid}, $setup->{gid}, $test_dir, $test_file)) {
896 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
897 }
898 }
899
900 my $config = {
901 PidFile => $setup->{pid_file},
902 ScoreboardFile => $setup->{scoreboard_file},
903 SystemLog => $setup->{log_file},
904
905 AuthUserFile => $setup->{auth_user_file},
906 AuthGroupFile => $setup->{auth_group_file},
907 AuthOrder => 'mod_auth_file.c',
908
909 IfModules => {
910 'mod_delay.c' => {
911 DelayEngine => 'off',
912 },
913 },
914 };
915
916 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
917 $config);
918
919 # Open pipes, for use between the parent and child processes. Specifically,
920 # the child will indicate when it's done with its test by writing a message
921 # to the parent.
922 my ($rfh, $wfh);
923 unless (pipe($rfh, $wfh)) {
924 die("Can't open pipe: $!");
925 }
926
927 my $ex;
928
929 # Fork child
930 $self->handle_sigchld();
931 defined(my $pid = fork()) or die("Can't fork: $!");
932 if ($pid) {
933 eval {
934 sleep(1);
935 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
936 $client->login($setup->{user}, $setup->{passwd});
937
938 my $path = 'test.d/test.lnk';
939 my ($resp_code, $resp_msg) = $client->site('UTIME', '200002240826',
940 $path);
941 $client->quit();
942
943 my $expected = 200;
944 $self->assert($expected == $resp_code,
945 test_msg("Expected response code $expected, got $resp_code"));
946
947 $expected = "SITE UTIME command successful";
948 $self->assert($expected eq $resp_msg,
949 test_msg("Expected response message '$expected', got '$resp_msg'"));
950
951 my ($atime, $mtime) = (stat($test_file))[8,9];
952
953 $expected = 951380760;
954 $self->assert($expected == $atime,
955 test_msg("Expected file atime $expected, got $atime"));
956 $self->assert($expected == $mtime,
957 test_msg("Expected file mtime $expected, got $mtime"));
958 };
959 if ($@) {
960 $ex = $@;
961 }
962
963 $wfh->print("done\n");
964 $wfh->flush();
965
966 } else {
967 eval { server_wait($setup->{config_file}, $rfh) };
968 if ($@) {
969 warn($@);
970 exit 1;
971 }
972
973 exit 0;
974 }
975
976 # Stop server
977 server_stop($setup->{pid_file});
978 $self->assert_child_ok($pid);
979
980 test_cleanup($setup->{log_file}, $ex);
981 }
982
983 sub site_misc_utime_abs_symlink_chrooted_bug4219 {
984 my $self = shift;
985 my $tmpdir = $self->{tmpdir};
986 my $setup = test_setup($tmpdir, 'site');
987
988 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
989 mkpath($test_dir);
990
991 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
992 if (open(my $fh, "> $test_file")) {
993 print $fh "Hello, World!\n";
994 unless (close($fh)) {
995 die("Can't write $test_file: $!");
996 }
997
998 } else {
999 die("Can't open $test_file: $!");
1000 }
1001
1002 my $test_symlink = File::Spec->rel2abs("$test_dir/test.lnk");
1003
1004 my $dst_path = $test_file;
1005 if ($^O eq 'darwin') {
1006 # MacOSX-specific hack
1007 $dst_path = '/private' . $dst_path;
1008 }
1009
1010 unless (symlink($dst_path, $test_symlink)) {
1011 die("Can't symlink $test_symlink to $dst_path: $!");
1012 }
1013
1014 if ($< == 0) {
1015 unless (chmod(0755, $test_dir)) {
1016 die("Can't set perms on $test_dir to 0755: $!");
1017 }
1018
1019 unless (chown($setup->{uid}, $setup->{gid}, $test_dir, $test_file)) {
1020 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1021 }
1022 }
1023
1024 my $config = {
1025 PidFile => $setup->{pid_file},
1026 ScoreboardFile => $setup->{scoreboard_file},
1027 SystemLog => $setup->{log_file},
1028
1029 AuthUserFile => $setup->{auth_user_file},
1030 AuthGroupFile => $setup->{auth_group_file},
1031 AuthOrder => 'mod_auth_file.c',
1032
1033 DefaultRoot => '~',
1034
1035 IfModules => {
1036 'mod_delay.c' => {
1037 DelayEngine => 'off',
1038 },
1039 },
1040 };
1041
1042 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1043 $config);
1044
1045 # Open pipes, for use between the parent and child processes. Specifically,
1046 # the child will indicate when it's done with its test by writing a message
1047 # to the parent.
1048 my ($rfh, $wfh);
1049 unless (pipe($rfh, $wfh)) {
1050 die("Can't open pipe: $!");
1051 }
1052
1053 my $ex;
1054
1055 # Fork child
1056 $self->handle_sigchld();
1057 defined(my $pid = fork()) or die("Can't fork: $!");
1058 if ($pid) {
1059 eval {
1060 sleep(1);
1061 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1062 $client->login($setup->{user}, $setup->{passwd});
1063
1064 my $path = 'test.d/test.lnk';
1065 my ($resp_code, $resp_msg) = $client->site('UTIME', '200002240826',
1066 $path);
1067 $client->quit();
1068
1069 my $expected = 200;
1070 $self->assert($expected == $resp_code,
1071 test_msg("Expected response code $expected, got $resp_code"));
1072
1073 $expected = "SITE UTIME command successful";
1074 $self->assert($expected eq $resp_msg,
1075 test_msg("Expected response message '$expected', got '$resp_msg'"));
1076
1077 my ($atime, $mtime) = (stat($test_file))[8,9];
1078
1079 $expected = 951380760;
1080 $self->assert($expected == $atime,
1081 test_msg("Expected file atime $expected, got $atime"));
1082 $self->assert($expected == $mtime,
1083 test_msg("Expected file mtime $expected, got $mtime"));
1084 };
1085 if ($@) {
1086 $ex = $@;
1087 }
1088
1089 $wfh->print("done\n");
1090 $wfh->flush();
1091
1092 } else {
1093 eval { server_wait($setup->{config_file}, $rfh) };
1094 if ($@) {
1095 warn($@);
1096 exit 1;
1097 }
1098
1099 exit 0;
1100 }
1101
1102 # Stop server
1103 server_stop($setup->{pid_file});
1104 $self->assert_child_ok($pid);
1105
1106 test_cleanup($setup->{log_file}, $ex);
1107 }
1108
1109 sub site_misc_utime_rel_symlink {
1110 my $self = shift;
1111 my $tmpdir = $self->{tmpdir};
1112 my $setup = test_setup($tmpdir, 'site');
1113
1114 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1115 mkpath($test_dir);
1116
1117 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
1118 if (open(my $fh, "> $test_file")) {
1119 print $fh "Hello, World!\n";
1120 unless (close($fh)) {
1121 die("Can't write $test_file: $!");
1122 }
1123
1124 } else {
1125 die("Can't open $test_file: $!");
1126 }
1127
1128 # Change to the test directory in order to create a relative path in the
1129 # symlink we need
1130
1131 my $cwd = getcwd();
1132 unless (chdir($test_dir)) {
1133 die("Can't chdir to $test_dir: $!");
1134 }
1135
1136 unless (symlink('./test.txt', './test.lnk')) {
1137 die("Can't symlink 'test.lnk' to './test.txt': $!");
1138 }
1139
1140 unless (chdir($cwd)) {
1141 die("Can't chdir to $cwd: $!");
1142 }
1143
1144 if ($< == 0) {
1145 unless (chmod(0755, $test_dir)) {
1146 die("Can't set perms on $test_dir to 0755: $!");
1147 }
1148
1149 unless (chown($setup->{uid}, $setup->{gid}, $test_dir, $test_file)) {
1150 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1151 }
1152 }
1153
1154 my $config = {
1155 PidFile => $setup->{pid_file},
1156 ScoreboardFile => $setup->{scoreboard_file},
1157 SystemLog => $setup->{log_file},
1158
1159 AuthUserFile => $setup->{auth_user_file},
1160 AuthGroupFile => $setup->{auth_group_file},
1161 AuthOrder => 'mod_auth_file.c',
1162
1163 IfModules => {
1164 'mod_delay.c' => {
1165 DelayEngine => 'off',
1166 },
1167 },
1168 };
1169
1170 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1171 $config);
1172
1173 # Open pipes, for use between the parent and child processes. Specifically,
1174 # the child will indicate when it's done with its test by writing a message
1175 # to the parent.
1176 my ($rfh, $wfh);
1177 unless (pipe($rfh, $wfh)) {
1178 die("Can't open pipe: $!");
1179 }
1180
1181 my $ex;
1182
1183 # Fork child
1184 $self->handle_sigchld();
1185 defined(my $pid = fork()) or die("Can't fork: $!");
1186 if ($pid) {
1187 eval {
1188 sleep(1);
1189 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1190 $client->login($setup->{user}, $setup->{passwd});
1191
1192 my $path = 'test.d/test.lnk';
1193 my ($resp_code, $resp_msg) = $client->site('UTIME', '200002240826',
1194 $path);
1195 $client->quit();
1196
1197 my $expected = 200;
1198 $self->assert($expected == $resp_code,
1199 test_msg("Expected response code $expected, got $resp_code"));
1200
1201 $expected = "SITE UTIME command successful";
1202 $self->assert($expected eq $resp_msg,
1203 test_msg("Expected response message '$expected', got '$resp_msg'"));
1204
1205 my ($atime, $mtime) = (stat($test_file))[8,9];
1206
1207 $expected = 951380760;
1208 $self->assert($expected == $atime,
1209 test_msg("Expected file atime $expected, got $atime"));
1210 $self->assert($expected == $mtime,
1211 test_msg("Expected file mtime $expected, got $mtime"));
1212 };
1213 if ($@) {
1214 $ex = $@;
1215 }
1216
1217 $wfh->print("done\n");
1218 $wfh->flush();
1219
1220 } else {
1221 eval { server_wait($setup->{config_file}, $rfh) };
1222 if ($@) {
1223 warn($@);
1224 exit 1;
1225 }
1226
1227 exit 0;
1228 }
1229
1230 # Stop server
1231 server_stop($setup->{pid_file});
1232 $self->assert_child_ok($pid);
1233
1234 test_cleanup($setup->{log_file}, $ex);
1235 }
1236
1237 sub site_misc_utime_rel_symlink_chrooted_bug4219 {
1238 my $self = shift;
1239 my $tmpdir = $self->{tmpdir};
1240 my $setup = test_setup($tmpdir, 'site');
1241
1242 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
1243 mkpath($test_dir);
1244
1245 my $test_file = File::Spec->rel2abs("$test_dir/test.txt");
1246 if (open(my $fh, "> $test_file")) {
1247 print $fh "Hello, World!\n";
1248 unless (close($fh)) {
1249 die("Can't write $test_file: $!");
1250 }
1251
1252 } else {
1253 die("Can't open $test_file: $!");
1254 }
1255
1256 # Change to the test directory in order to create a relative path in the
1257 # symlink we need
1258
1259 my $cwd = getcwd();
1260 unless (chdir($test_dir)) {
1261 die("Can't chdir to $test_dir: $!");
1262 }
1263
1264 unless (symlink('./test.txt', './test.lnk')) {
1265 die("Can't symlink 'test.lnk' to './test.txt': $!");
1266 }
1267
1268 unless (chdir($cwd)) {
1269 die("Can't chdir to $cwd: $!");
1270 }
1271
1272 if ($< == 0) {
1273 unless (chmod(0755, $test_dir)) {
1274 die("Can't set perms on $test_dir to 0755: $!");
1275 }
1276
1277 unless (chown($setup->{uid}, $setup->{gid}, $test_dir, $test_file)) {
1278 die("Can't set owner of $test_dir to $setup->{uid}/$setup->{gid}: $!");
1279 }
1280 }
1281
1282 my $config = {
1283 PidFile => $setup->{pid_file},
1284 ScoreboardFile => $setup->{scoreboard_file},
1285 SystemLog => $setup->{log_file},
1286
1287 AuthUserFile => $setup->{auth_user_file},
1288 AuthGroupFile => $setup->{auth_group_file},
1289 AuthOrder => 'mod_auth_file.c',
1290
1291 DefaultRoot => '~',
1292
1293 IfModules => {
1294 'mod_delay.c' => {
1295 DelayEngine => 'off',
1296 },
1297 },
1298 };
1299
1300 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1301 $config);
1302
1303 # Open pipes, for use between the parent and child processes. Specifically,
1304 # the child will indicate when it's done with its test by writing a message
1305 # to the parent.
1306 my ($rfh, $wfh);
1307 unless (pipe($rfh, $wfh)) {
1308 die("Can't open pipe: $!");
1309 }
1310
1311 my $ex;
1312
1313 # Fork child
1314 $self->handle_sigchld();
1315 defined(my $pid = fork()) or die("Can't fork: $!");
1316 if ($pid) {
1317 eval {
1318 sleep(1);
1319 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
1320 $client->login($setup->{user}, $setup->{passwd});
1321
1322 my $path = 'test.d/test.lnk';
1323 my ($resp_code, $resp_msg) = $client->site('UTIME', '200002240826',
1324 $path);
1325 $client->quit();
1326
1327 my $expected = 200;
1328 $self->assert($expected == $resp_code,
1329 test_msg("Expected response code $expected, got $resp_code"));
1330
1331 $expected = "SITE UTIME command successful";
1332 $self->assert($expected eq $resp_msg,
1333 test_msg("Expected response message '$expected', got '$resp_msg'"));
1334
1335 my ($atime, $mtime) = (stat($test_file))[8,9];
1336
1337 $expected = 951380760;
1338 $self->assert($expected == $atime,
1339 test_msg("Expected file atime $expected, got $atime"));
1340 $self->assert($expected == $mtime,
1341 test_msg("Expected file mtime $expected, got $mtime"));
1342 };
1343 if ($@) {
1344 $ex = $@;
1345 }
1346
1347 $wfh->print("done\n");
1348 $wfh->flush();
1349
1350 } else {
1351 eval { server_wait($setup->{config_file}, $rfh) };
1352 if ($@) {
1353 warn($@);
1354 exit 1;
1355 }
1356
1357 exit 0;
1358 }
1359
1360 # Stop server
1361 server_stop($setup->{pid_file});
1362 $self->assert_child_ok($pid);
1363
1364 test_cleanup($setup->{log_file}, $ex);
1365 }
1366
1367 sub site_feat_ok {
1368 my $self = shift;
1369 my $tmpdir = $self->{tmpdir};
1370
1371 my $config_file = "$tmpdir/site.conf";
1372 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
1373 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
1374
1375 my $log_file = File::Spec->rel2abs('tests.log');
1376
1377 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
1378 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
1379
1380 my $user = 'proftpd';
1381 my $passwd = 'test';
1382 my $home_dir = File::Spec->rel2abs($tmpdir);
1383 my $uid = 500;
1384 my $gid = 500;
1385
1386 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
1387
1388 # Make sure that, if we're running as root, that the home directory has
1389 # permissions/privs set for the account we create
1390 if ($< == 0) {
1391 unless (chmod(0755, $home_dir)) {
1392 die("Can't set perms on $home_dir to 0755: $!");
1393 }
1394
1395 unless (chown($uid, $gid, $home_dir)) {
1396 die("Can't set owner of $home_dir to $uid/$gid: $!");
1397 }
1398 }
1399
1400 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1401 '/bin/bash');
1402 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1403
1404 my $config = {
1405 PidFile => $pid_file,
1406 ScoreboardFile => $scoreboard_file,
1407 SystemLog => $log_file,
1408
1409 AuthUserFile => $auth_user_file,
1410 AuthGroupFile => $auth_group_file,
1411 AuthOrder => 'mod_auth_file.c',
1412
1413 IfModules => {
1414 'mod_delay.c' => {
1415 DelayEngine => 'off',
1416 },
1417 },
1418 };
1419
1420 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1421
1422 # Open pipes, for use between the parent and child processes. Specifically,
1423 # the child will indicate when it's done with its test by writing a message
1424 # to the parent.
1425 my ($rfh, $wfh);
1426 unless (pipe($rfh, $wfh)) {
1427 die("Can't open pipe: $!");
1428 }
1429
1430 my $ex;
1431
1432 # Fork child
1433 $self->handle_sigchld();
1434 defined(my $pid = fork()) or die("Can't fork: $!");
1435 if ($pid) {
1436 eval {
1437 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1438
1439 $client->feat();
1440 my $resp_code = $client->response_code();
1441 my $resp_msgs = $client->response_msgs();
1442
1443 my $expected;
1444
1445 $expected = 211;
1446 $self->assert($expected == $resp_code,
1447 test_msg("Expected $expected, got $resp_code"));
1448
1449 my $nfeat = scalar(@$resp_msgs);
1450
1451 my $feats = {
1452 ' SITE MKDIR' => 1,
1453 ' SITE RMDIR' => 1,
1454 ' SITE SYMLINK' => 1,
1455 ' SITE UTIME' => 1,
1456 };
1457
1458 for (my $i = 0; $i < $nfeat; $i++) {
1459 if (defined($feats->{$resp_msgs->[$i]})) {
1460 delete($feats->{$resp_msgs->[$i]});
1461 }
1462 }
1463
1464 my $remain_misc_feats = scalar(keys(%$feats));
1465 $self->assert($remain_misc_feats == 0,
1466 test_msg("Unexpected 0, got $remain_misc_feats"));
1467 };
1468
1469 if ($@) {
1470 $ex = $@;
1471 }
1472
1473 $wfh->print("done\n");
1474 $wfh->flush();
1475
1476 } else {
1477 eval { server_wait($config_file, $rfh) };
1478 if ($@) {
1479 warn($@);
1480 exit 1;
1481 }
1482
1483 exit 0;
1484 }
1485
1486 # Stop server
1487 server_stop($pid_file);
1488
1489 $self->assert_child_ok($pid);
1490
1491 if ($ex) {
1492 die($ex);
1493 }
1494
1495 unlink($log_file);
1496 }
1497
1498 sub site_misc_symlink_ncftpd_chroot_bug {
1499 my $self = shift;
1500 my $tmpdir = $self->{tmpdir};
1501
1502 my $config_file = "$tmpdir/site.conf";
1503 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
1504 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
1505
1506 my $log_file = File::Spec->rel2abs('tests.log');
1507
1508 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
1509 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
1510
1511 my $user = 'proftpd';
1512 my $passwd = 'test';
1513 my $home_dir = File::Spec->rel2abs($tmpdir);
1514 my $uid = 500;
1515 my $gid = 500;
1516
1517 my $test_symlink = File::Spec->rel2abs("$home_dir/hack/.message");
1518
1519 # Make sure that, if we're running as root, that the home directory has
1520 # permissions/privs set for the account we create
1521 if ($< == 0) {
1522 unless (chmod(0755, $home_dir)) {
1523 die("Can't set perms on $home_dir to 0755: $!");
1524 }
1525
1526 unless (chown($uid, $gid, $home_dir)) {
1527 die("Can't set owner of $home_dir to $uid/$gid: $!");
1528 }
1529 }
1530
1531 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1532 '/bin/bash');
1533 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1534
1535 my $config = {
1536 PidFile => $pid_file,
1537 ScoreboardFile => $scoreboard_file,
1538 SystemLog => $log_file,
1539
1540 AuthUserFile => $auth_user_file,
1541 AuthGroupFile => $auth_group_file,
1542 AuthOrder => 'mod_auth_file.c',
1543
1544 DefaultRoot => '~',
1545 DisplayChdir => '.message',
1546
1547 IfModules => {
1548 'mod_delay.c' => {
1549 DelayEngine => 'off',
1550 },
1551 },
1552 };
1553
1554 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1555
1556 # Open pipes, for use between the parent and child processes. Specifically,
1557 # the child will indicate when it's done with its test by writing a message
1558 # to the parent.
1559 my ($rfh, $wfh);
1560 unless (pipe($rfh, $wfh)) {
1561 die("Can't open pipe: $!");
1562 }
1563
1564 my $ex;
1565
1566 # Fork child
1567 $self->handle_sigchld();
1568 defined(my $pid = fork()) or die("Can't fork: $!");
1569 if ($pid) {
1570 eval {
1571 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
1572 $client->login($user, $passwd);
1573
1574 my ($expected, $resp_code, $resp_msg);
1575
1576 my $conn = $client->retr_raw('/etc/passwd');
1577 if ($conn) {
1578 die("RETR /etc/passwd succeeded unexpectedly");
1579 }
1580
1581 $resp_code = $client->response_code();
1582 $resp_msg = $client->response_msg();
1583
1584 $expected = 550;
1585 $self->assert($expected == $resp_code,
1586 test_msg("Expected $expected, got $resp_code"));
1587
1588 $expected = "/etc/passwd: No such file or directory";
1589 $self->assert($expected eq $resp_msg,
1590 test_msg("Expected '$expected', got '$resp_msg'"));
1591
1592 ($resp_code, $resp_msg) = $client->mkd('hack');
1593
1594 $expected = 257;
1595 $self->assert($expected == $resp_code,
1596 test_msg("Expected $expected, got $resp_code"));
1597
1598 $expected = "\"/hack\" - Directory successfully created";
1599 $self->assert($expected eq $resp_msg,
1600 test_msg("Expected '$expected', got '$resp_msg'"));
1601
1602 eval { $client->site('SYMLINK', '/etc/passwd', 'hack/.message') };
1603 unless ($@) {
1604 die("SITE SYMLINK succeeded unexpectedly");
1605 }
1606
1607 $resp_code = $client->response_code();
1608 $resp_msg = $client->response_msg();
1609
1610 $expected = 550;
1611 $self->assert($expected == $resp_code,
1612 test_msg("Expected $expected, got $resp_code"));
1613
1614 $expected = "SYMLINK /etc/passwd hack/.message: No such file or directory";
1615 $self->assert($expected eq $resp_msg,
1616 test_msg("Expected '$expected', got '$resp_msg'"));
1617
1618 $client->quit();
1619 };
1620
1621 if ($@) {
1622 $ex = $@;
1623 }
1624
1625 $wfh->print("done\n");
1626 $wfh->flush();
1627
1628 } else {
1629 eval { server_wait($config_file, $rfh) };
1630 if ($@) {
1631 warn($@);
1632 exit 1;
1633 }
1634
1635 exit 0;
1636 }
1637
1638 # Stop server
1639 server_stop($pid_file);
1640
1641 $self->assert_child_ok($pid);
1642
1643 if ($ex) {
1644 die($ex);
1645 }
1646
1647 unlink($log_file);
1648 }
1649
1650 sub site_misc_mkdir_failed_bug3518 {
1651 my $self = shift;
1652 my $tmpdir = $self->{tmpdir};
1653
1654 my $config_file = "$tmpdir/site.conf";
1655 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
1656 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
1657
1658 my $log_file = File::Spec->rel2abs('tests.log');
1659
1660 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
1661 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
1662
1663 my $user = 'proftpd';
1664 my $passwd = 'test';
1665 my $home_dir = File::Spec->rel2abs($tmpdir);
1666 my $uid = 500;
1667 my $gid = 500;
1668
1669 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
1670
1671 # Make sure that, if we're running as root, that the home directory has
1672 # permissions/privs set for the account we create
1673 if ($< == 0) {
1674 unless (chmod(0755, $home_dir)) {
1675 die("Can't set perms on $home_dir to 0755: $!");
1676 }
1677
1678 unless (chown($uid, $gid, $home_dir)) {
1679 die("Can't set owner of $home_dir to $uid/$gid: $!");
1680 }
1681 }
1682
1683 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1684 '/bin/bash');
1685 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1686
1687 my $config = {
1688 PidFile => $pid_file,
1689 ScoreboardFile => $scoreboard_file,
1690 SystemLog => $log_file,
1691
1692 AuthUserFile => $auth_user_file,
1693 AuthGroupFile => $auth_group_file,
1694 AuthOrder => 'mod_auth_file.c',
1695
1696 IfModules => {
1697 'mod_delay.c' => {
1698 DelayEngine => 'off',
1699 },
1700
1701 'mod_site_misc.c' => {
1702 SiteMiscEngine => 'off',
1703 },
1704 },
1705 };
1706
1707 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1708
1709 # Open pipes, for use between the parent and child processes. Specifically,
1710 # the child will indicate when it's done with its test by writing a message
1711 # to the parent.
1712 my ($rfh, $wfh);
1713 unless (pipe($rfh, $wfh)) {
1714 die("Can't open pipe: $!");
1715 }
1716
1717 my $ex;
1718
1719 # Fork child
1720 $self->handle_sigchld();
1721 defined(my $pid = fork()) or die("Can't fork: $!");
1722 if ($pid) {
1723 eval {
1724 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1725 $client->login($user, $passwd);
1726
1727 eval { $client->site('MKDIR', 'foo/bar/baz') };
1728 unless ($@) {
1729 die("SITE MKDIR succeeded unexpectedly");
1730 }
1731
1732 my $resp_code = $client->response_code();
1733 my $resp_msg = $client->response_msg();
1734
1735 my $expected;
1736
1737 $expected = 500;
1738 $self->assert($expected == $resp_code,
1739 test_msg("Expected $expected, got $resp_code"));
1740
1741 $expected = "'SITE MKDIR' not understood";
1742 $self->assert($expected eq $resp_msg,
1743 test_msg("Expected '$expected', got '$resp_msg'"));
1744
1745 # Make sure that the test dir is NOT present
1746 if (-d $test_dir) {
1747 die("Directory $test_dir exists unexpectedly");
1748 }
1749 };
1750
1751 if ($@) {
1752 $ex = $@;
1753 }
1754
1755 $wfh->print("done\n");
1756 $wfh->flush();
1757
1758 } else {
1759 eval { server_wait($config_file, $rfh) };
1760 if ($@) {
1761 warn($@);
1762 exit 1;
1763 }
1764
1765 exit 0;
1766 }
1767
1768 # Stop server
1769 server_stop($pid_file);
1770
1771 $self->assert_child_ok($pid);
1772
1773 if ($ex) {
1774 die($ex);
1775 }
1776
1777 unlink($log_file);
1778 }
1779
1780 sub site_misc_rmdir_failed_bug3518 {
1781 my $self = shift;
1782 my $tmpdir = $self->{tmpdir};
1783
1784 my $config_file = "$tmpdir/site.conf";
1785 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
1786 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
1787
1788 my $log_file = File::Spec->rel2abs('tests.log');
1789
1790 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
1791 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
1792
1793 my $user = 'proftpd';
1794 my $passwd = 'test';
1795 my $home_dir = File::Spec->rel2abs($tmpdir);
1796 my $uid = 500;
1797 my $gid = 500;
1798
1799 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
1800 mkpath($sub_dir);
1801
1802 my $test_dirs = [
1803 File::Spec->rel2abs("$tmpdir/foo"),
1804 File::Spec->rel2abs("$tmpdir/foo/bar"),
1805 $sub_dir,
1806 ];
1807
1808 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt");
1809 if (open(my $fh, "> $test_file")) {
1810 print $fh "Quzz\n";
1811
1812 unless (close($fh)) {
1813 die("Can't write $test_file: $!");
1814 }
1815
1816 } else {
1817 die("Can't open $test_file: $!");
1818 }
1819
1820 # Make sure that, if we're running as root, that the home directory has
1821 # permissions/privs set for the account we create
1822 if ($< == 0) {
1823 unless (chmod(0755, $home_dir)) {
1824 die("Can't set perms on $home_dir to 0755: $!");
1825 }
1826
1827 unless (chown($uid, $gid, $home_dir)) {
1828 die("Can't set owner of $home_dir to $uid/$gid: $!");
1829 }
1830 }
1831
1832 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1833 '/bin/bash');
1834 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1835
1836 my $config = {
1837 PidFile => $pid_file,
1838 ScoreboardFile => $scoreboard_file,
1839 SystemLog => $log_file,
1840
1841 AuthUserFile => $auth_user_file,
1842 AuthGroupFile => $auth_group_file,
1843 AuthOrder => 'mod_auth_file.c',
1844
1845 IfModules => {
1846 'mod_delay.c' => {
1847 DelayEngine => 'off',
1848 },
1849
1850 'mod_site_misc.c' => {
1851 SiteMiscEngine => 'off',
1852 },
1853
1854 },
1855 };
1856
1857 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1858
1859 # Open pipes, for use between the parent and child processes. Specifically,
1860 # the child will indicate when it's done with its test by writing a message
1861 # to the parent.
1862 my ($rfh, $wfh);
1863 unless (pipe($rfh, $wfh)) {
1864 die("Can't open pipe: $!");
1865 }
1866
1867 my $ex;
1868
1869 # Fork child
1870 $self->handle_sigchld();
1871 defined(my $pid = fork()) or die("Can't fork: $!");
1872 if ($pid) {
1873 eval {
1874 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1875 $client->login($user, $passwd);
1876
1877 eval { $client->site('RMDIR', 'foo') };
1878 unless ($@) {
1879 die("SITE RMDIR succeeded unexpectedly");
1880 }
1881
1882 my $resp_code = $client->response_code();
1883 my $resp_msg = $client->response_msg();
1884
1885 my $expected;
1886
1887 $expected = 500;
1888 $self->assert($expected == $resp_code,
1889 test_msg("Expected $expected, got $resp_code"));
1890
1891 $expected = "'SITE RMDIR' not understood";
1892 $self->assert($expected eq $resp_msg,
1893 test_msg("Expected '$expected', got '$resp_msg'"));
1894
1895 # Make sure that the test file is NOT gone, along with all of the
1896 # test dirs.
1897 unless (-f $test_file) {
1898 die("File $test_file does not exist as expected");
1899 }
1900
1901 foreach my $test_dir (@$test_dirs) {
1902 unless (-d $test_dir) {
1903 die("Directory $test_dir does not exist as expected");
1904 }
1905 }
1906 };
1907
1908 if ($@) {
1909 $ex = $@;
1910 }
1911
1912 $wfh->print("done\n");
1913 $wfh->flush();
1914
1915 } else {
1916 eval { server_wait($config_file, $rfh) };
1917 if ($@) {
1918 warn($@);
1919 exit 1;
1920 }
1921
1922 exit 0;
1923 }
1924
1925 # Stop server
1926 server_stop($pid_file);
1927
1928 $self->assert_child_ok($pid);
1929
1930 if ($ex) {
1931 die($ex);
1932 }
1933
1934 unlink($log_file);
1935 }
1936
1937 sub site_misc_symlink_failed_bug3518 {
1938 my $self = shift;
1939 my $tmpdir = $self->{tmpdir};
1940
1941 my $config_file = "$tmpdir/site.conf";
1942 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
1943 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
1944
1945 my $log_file = File::Spec->rel2abs('tests.log');
1946
1947 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
1948 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
1949
1950 my $user = 'proftpd';
1951 my $passwd = 'test';
1952 my $home_dir = File::Spec->rel2abs($tmpdir);
1953 my $uid = 500;
1954 my $gid = 500;
1955
1956 my $test_symlink = File::Spec->rel2abs("$tmpdir/foo");
1957
1958 # Make sure that, if we're running as root, that the home directory has
1959 # permissions/privs set for the account we create
1960 if ($< == 0) {
1961 unless (chmod(0755, $home_dir)) {
1962 die("Can't set perms on $home_dir to 0755: $!");
1963 }
1964
1965 unless (chown($uid, $gid, $home_dir)) {
1966 die("Can't set owner of $home_dir to $uid/$gid: $!");
1967 }
1968 }
1969
1970 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1971 '/bin/bash');
1972 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
1973
1974 my $config = {
1975 PidFile => $pid_file,
1976 ScoreboardFile => $scoreboard_file,
1977 SystemLog => $log_file,
1978
1979 AuthUserFile => $auth_user_file,
1980 AuthGroupFile => $auth_group_file,
1981 AuthOrder => 'mod_auth_file.c',
1982
1983 IfModules => {
1984 'mod_delay.c' => {
1985 DelayEngine => 'off',
1986 },
1987
1988 'mod_site_misc.c' => {
1989 SiteMiscEngine => 'off',
1990 },
1991
1992 },
1993 };
1994
1995 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1996
1997 # Open pipes, for use between the parent and child processes. Specifically,
1998 # the child will indicate when it's done with its test by writing a message
1999 # to the parent.
2000 my ($rfh, $wfh);
2001 unless (pipe($rfh, $wfh)) {
2002 die("Can't open pipe: $!");
2003 }
2004
2005 my $ex;
2006
2007 # Fork child
2008 $self->handle_sigchld();
2009 defined(my $pid = fork()) or die("Can't fork: $!");
2010 if ($pid) {
2011 eval {
2012 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2013 $client->login($user, $passwd);
2014
2015 eval { $client->site('SYMLINK', 'site.conf', 'foo') };
2016 unless ($@) {
2017 die("SITE SYMLINK succeeded unexpectedly");
2018 }
2019
2020 my $resp_code = $client->response_code();
2021 my $resp_msg = $client->response_msg();
2022
2023 my $expected;
2024
2025 $expected = 500;
2026 $self->assert($expected == $resp_code,
2027 test_msg("Expected $expected, got $resp_code"));
2028
2029 $expected = "'SITE SYMLINK' not understood";
2030 $self->assert($expected eq $resp_msg,
2031 test_msg("Expected '$expected', got '$resp_msg'"));
2032
2033 if (-l $test_symlink) {
2034 die("Symlink $test_symlink exists unexpectedly");
2035 }
2036 };
2037
2038 if ($@) {
2039 $ex = $@;
2040 }
2041
2042 $wfh->print("done\n");
2043 $wfh->flush();
2044
2045 } else {
2046 eval { server_wait($config_file, $rfh) };
2047 if ($@) {
2048 warn($@);
2049 exit 1;
2050 }
2051
2052 exit 0;
2053 }
2054
2055 # Stop server
2056 server_stop($pid_file);
2057
2058 $self->assert_child_ok($pid);
2059
2060 if ($ex) {
2061 die($ex);
2062 }
2063
2064 unlink($log_file);
2065 }
2066
2067 sub site_misc_utime_failed_bug3518 {
2068 my $self = shift;
2069 my $tmpdir = $self->{tmpdir};
2070
2071 my $config_file = "$tmpdir/site.conf";
2072 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2073 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2074
2075 my $log_file = File::Spec->rel2abs('tests.log');
2076
2077 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2078 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2079
2080 my $user = 'proftpd';
2081 my $passwd = 'test';
2082 my $home_dir = File::Spec->rel2abs($tmpdir);
2083 my $uid = 500;
2084 my $gid = 500;
2085
2086 # Make sure that, if we're running as root, that the home directory has
2087 # permissions/privs set for the account we create
2088 if ($< == 0) {
2089 unless (chmod(0755, $home_dir)) {
2090 die("Can't set perms on $home_dir to 0755: $!");
2091 }
2092
2093 unless (chown($uid, $gid, $home_dir)) {
2094 die("Can't set owner of $home_dir to $uid/$gid: $!");
2095 }
2096 }
2097
2098 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2099 '/bin/bash');
2100 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2101
2102 my $config = {
2103 PidFile => $pid_file,
2104 ScoreboardFile => $scoreboard_file,
2105 SystemLog => $log_file,
2106
2107 AuthUserFile => $auth_user_file,
2108 AuthGroupFile => $auth_group_file,
2109 AuthOrder => 'mod_auth_file.c',
2110
2111 IfModules => {
2112 'mod_delay.c' => {
2113 DelayEngine => 'off',
2114 },
2115
2116 'mod_site_misc.c' => {
2117 SiteMiscEngine => 'off',
2118 },
2119
2120 },
2121 };
2122
2123 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2124
2125 # Open pipes, for use between the parent and child processes. Specifically,
2126 # the child will indicate when it's done with its test by writing a message
2127 # to the parent.
2128 my ($rfh, $wfh);
2129 unless (pipe($rfh, $wfh)) {
2130 die("Can't open pipe: $!");
2131 }
2132
2133 my $ex;
2134
2135 # Fork child
2136 $self->handle_sigchld();
2137 defined(my $pid = fork()) or die("Can't fork: $!");
2138 if ($pid) {
2139 eval {
2140 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2141 $client->login($user, $passwd);
2142
2143 eval { $client->site('UTIME', '200002240826', 'site.conf') };
2144 unless ($@) {
2145 die("SITE UTIME succeeded unexpectedly");
2146 }
2147
2148 my $resp_code = $client->response_code();
2149 my $resp_msg = $client->response_msg();
2150
2151 my $expected;
2152
2153 $expected = 500;
2154 $self->assert($expected == $resp_code,
2155 test_msg("Expected $expected, got $resp_code"));
2156
2157 $expected = "'SITE UTIME' not understood";
2158 $self->assert($expected eq $resp_msg,
2159 test_msg("Expected '$expected', got '$resp_msg'"));
2160 };
2161
2162 if ($@) {
2163 $ex = $@;
2164 }
2165
2166 $wfh->print("done\n");
2167 $wfh->flush();
2168
2169 } else {
2170 eval { server_wait($config_file, $rfh) };
2171 if ($@) {
2172 warn($@);
2173 exit 1;
2174 }
2175
2176 exit 0;
2177 }
2178
2179 # Stop server
2180 server_stop($pid_file);
2181
2182 $self->assert_child_ok($pid);
2183
2184 if ($ex) {
2185 die($ex);
2186 }
2187
2188 unlink($log_file);
2189 }
2190
2191 sub site_misc_mkdir_failed_bug3519 {
2192 my $self = shift;
2193 my $tmpdir = $self->{tmpdir};
2194
2195 my $config_file = "$tmpdir/site.conf";
2196 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2197 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2198
2199 my $log_file = File::Spec->rel2abs('tests.log');
2200
2201 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2202 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2203
2204 my $user = 'proftpd';
2205 my $passwd = 'test';
2206 my $home_dir = File::Spec->rel2abs($tmpdir);
2207 my $uid = 500;
2208 my $gid = 500;
2209
2210 my $start_dir = File::Spec->rel2abs("$tmpdir/bar");
2211 mkpath($start_dir);
2212
2213 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
2214
2215 # Make sure that, if we're running as root, that the home directory has
2216 # permissions/privs set for the account we create
2217 if ($< == 0) {
2218 unless (chmod(0755, $home_dir)) {
2219 die("Can't set perms on $home_dir to 0755: $!");
2220 }
2221
2222 unless (chown($uid, $gid, $home_dir)) {
2223 die("Can't set owner of $home_dir to $uid/$gid: $!");
2224 }
2225 }
2226
2227 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2228 '/bin/bash');
2229 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2230
2231 my $config = {
2232 PidFile => $pid_file,
2233 ScoreboardFile => $scoreboard_file,
2234 SystemLog => $log_file,
2235
2236 AuthUserFile => $auth_user_file,
2237 AuthGroupFile => $auth_group_file,
2238 AuthOrder => 'mod_auth_file.c',
2239
2240 IfModules => {
2241 'mod_delay.c' => {
2242 DelayEngine => 'off',
2243 },
2244 },
2245 };
2246
2247 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2248
2249 if (open(my $fh, ">> $config_file")) {
2250 my $limit_dir = "$tmpdir/foo";
2251 if ($^O eq 'darwin') {
2252 $limit_dir = '/private' . $limit_dir;
2253 }
2254
2255 print $fh <<EOT;
2256 <Directory $limit_dir>
2257 <Limit WRITE>
2258 DenyAll
2259 </Limit>
2260 </Directory>
2261 EOT
2262
2263 unless (close($fh)) {
2264 die("Can't write $config_file: $!");
2265 }
2266
2267 } else {
2268 die("Can't open $config_file: $!");
2269 }
2270
2271 # Open pipes, for use between the parent and child processes. Specifically,
2272 # the child will indicate when it's done with its test by writing a message
2273 # to the parent.
2274 my ($rfh, $wfh);
2275 unless (pipe($rfh, $wfh)) {
2276 die("Can't open pipe: $!");
2277 }
2278
2279 my $ex;
2280
2281 # Fork child
2282 $self->handle_sigchld();
2283 defined(my $pid = fork()) or die("Can't fork: $!");
2284 if ($pid) {
2285 eval {
2286 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2287 $client->login($user, $passwd);
2288
2289 my $path = 'bar/../foo/bar/baz';
2290
2291 eval { $client->site('MKDIR', $path) };
2292 unless ($@) {
2293 die("SITE MKDIR succeeded unexpectedly");
2294 }
2295
2296 my $resp_code = $client->response_code();
2297 my $resp_msg = $client->response_msg();
2298
2299 my $expected;
2300
2301 $expected = 550;
2302 $self->assert($expected == $resp_code,
2303 test_msg("Expected response code $expected, got $resp_code"));
2304
2305 $expected = "MKDIR $path: Operation not permitted";
2306 $self->assert($expected eq $resp_msg,
2307 test_msg("Expected response message '$expected', got '$resp_msg'"));
2308
2309 $client->quit();
2310
2311 # Make sure the directory doesn't exist
2312 if (-d $test_dir) {
2313 die("Directory $test_dir exists unexpectedly");
2314 }
2315 };
2316
2317 if ($@) {
2318 $ex = $@;
2319 }
2320
2321 $wfh->print("done\n");
2322 $wfh->flush();
2323
2324 } else {
2325 eval { server_wait($config_file, $rfh) };
2326 if ($@) {
2327 warn($@);
2328 exit 1;
2329 }
2330
2331 exit 0;
2332 }
2333
2334 # Stop server
2335 server_stop($pid_file);
2336
2337 $self->assert_child_ok($pid);
2338
2339 if ($ex) {
2340 die($ex);
2341 }
2342
2343 unlink($log_file);
2344 }
2345
2346 sub site_misc_rmdir_failed_bug3519 {
2347 my $self = shift;
2348 my $tmpdir = $self->{tmpdir};
2349
2350 my $config_file = "$tmpdir/site.conf";
2351 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2352 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2353
2354 my $log_file = File::Spec->rel2abs('tests.log');
2355
2356 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2357 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2358
2359 my $user = 'proftpd';
2360 my $passwd = 'test';
2361 my $home_dir = File::Spec->rel2abs($tmpdir);
2362 my $uid = 500;
2363 my $gid = 500;
2364
2365 my $start_dir = File::Spec->rel2abs("$tmpdir/bar");
2366 mkpath($start_dir);
2367
2368 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
2369 mkpath($sub_dir);
2370
2371 my $test_dirs = [
2372 File::Spec->rel2abs("$tmpdir/foo"),
2373 File::Spec->rel2abs("$tmpdir/foo/bar"),
2374 $sub_dir,
2375 ];
2376
2377 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt");
2378 if (open(my $fh, "> $test_file")) {
2379 print $fh "Quzz\n";
2380
2381 unless (close($fh)) {
2382 die("Can't write $test_file: $!");
2383 }
2384
2385 } else {
2386 die("Can't open $test_file: $!");
2387 }
2388
2389 # Make sure that, if we're running as root, that the home directory has
2390 # permissions/privs set for the account we create
2391 if ($< == 0) {
2392 unless (chmod(0755, $home_dir)) {
2393 die("Can't set perms on $home_dir to 0755: $!");
2394 }
2395
2396 unless (chown($uid, $gid, $home_dir)) {
2397 die("Can't set owner of $home_dir to $uid/$gid: $!");
2398 }
2399 }
2400
2401 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2402 '/bin/bash');
2403 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2404
2405 my $config = {
2406 PidFile => $pid_file,
2407 ScoreboardFile => $scoreboard_file,
2408 SystemLog => $log_file,
2409
2410 AuthUserFile => $auth_user_file,
2411 AuthGroupFile => $auth_group_file,
2412 AuthOrder => 'mod_auth_file.c',
2413
2414 IfModules => {
2415 'mod_delay.c' => {
2416 DelayEngine => 'off',
2417 },
2418 },
2419 };
2420
2421 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2422
2423 if (open(my $fh, ">> $config_file")) {
2424 my $limit_dir = "$tmpdir/foo";
2425 if ($^O eq 'darwin') {
2426 $limit_dir = '/private' . $limit_dir;
2427 }
2428
2429 print $fh <<EOT;
2430 <Directory $limit_dir>
2431 <Limit WRITE>
2432 DenyAll
2433 </Limit>
2434 </Directory>
2435 EOT
2436
2437 unless (close($fh)) {
2438 die("Can't write $config_file: $!");
2439 }
2440
2441 } else {
2442 die("Can't open $config_file: $!");
2443 }
2444
2445 # Open pipes, for use between the parent and child processes. Specifically,
2446 # the child will indicate when it's done with its test by writing a message
2447 # to the parent.
2448 my ($rfh, $wfh);
2449 unless (pipe($rfh, $wfh)) {
2450 die("Can't open pipe: $!");
2451 }
2452
2453 my $ex;
2454
2455 # Fork child
2456 $self->handle_sigchld();
2457 defined(my $pid = fork()) or die("Can't fork: $!");
2458 if ($pid) {
2459 eval {
2460 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2461 $client->login($user, $passwd);
2462
2463 my $path = 'bar/../foo';
2464
2465 eval { $client->site('RMDIR', $path) };
2466 unless ($@) {
2467 die("SITE RMDIR succeeded unexpectedly");
2468 }
2469
2470 my $resp_code = $client->response_code();
2471 my $resp_msg = $client->response_msg();
2472
2473 my $expected;
2474
2475 $expected = 550;
2476 $self->assert($expected == $resp_code,
2477 test_msg("Expected $expected, got $resp_code"));
2478
2479 $expected = "RMDIR $path: Operation not permitted";
2480 $self->assert($expected eq $resp_msg,
2481 test_msg("Expected '$expected', got '$resp_msg'"));
2482
2483 # Make sure that the test file is NOT gone, along with all of the
2484 # test dirs.
2485 unless (-f $test_file) {
2486 die("File $test_file does not exist as expected");
2487 }
2488
2489 foreach my $test_dir (@$test_dirs) {
2490 unless (-d $test_dir) {
2491 die("Directory $test_dir does not exist as expected");
2492 }
2493 }
2494 };
2495
2496 if ($@) {
2497 $ex = $@;
2498 }
2499
2500 $wfh->print("done\n");
2501 $wfh->flush();
2502
2503 } else {
2504 eval { server_wait($config_file, $rfh) };
2505 if ($@) {
2506 warn($@);
2507 exit 1;
2508 }
2509
2510 exit 0;
2511 }
2512
2513 # Stop server
2514 server_stop($pid_file);
2515
2516 $self->assert_child_ok($pid);
2517
2518 if ($ex) {
2519 die($ex);
2520 }
2521
2522 unlink($log_file);
2523 }
2524
2525 sub site_misc_symlink_failed_bug3519 {
2526 my $self = shift;
2527 my $tmpdir = $self->{tmpdir};
2528
2529 my $config_file = "$tmpdir/site.conf";
2530 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2531 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2532
2533 my $log_file = File::Spec->rel2abs('tests.log');
2534
2535 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2536 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2537
2538 my $user = 'proftpd';
2539 my $passwd = 'test';
2540 my $home_dir = File::Spec->rel2abs($tmpdir);
2541 my $uid = 500;
2542 my $gid = 500;
2543
2544 my $start_dir = File::Spec->rel2abs("$tmpdir/bar");
2545 mkpath($start_dir);
2546
2547 my $test_symlink = File::Spec->rel2abs("$tmpdir/foo");
2548
2549 # Make sure that, if we're running as root, that the home directory has
2550 # permissions/privs set for the account we create
2551 if ($< == 0) {
2552 unless (chmod(0755, $home_dir)) {
2553 die("Can't set perms on $home_dir to 0755: $!");
2554 }
2555
2556 unless (chown($uid, $gid, $home_dir)) {
2557 die("Can't set owner of $home_dir to $uid/$gid: $!");
2558 }
2559 }
2560
2561 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2562 '/bin/bash');
2563 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2564
2565 my $config = {
2566 PidFile => $pid_file,
2567 ScoreboardFile => $scoreboard_file,
2568 SystemLog => $log_file,
2569
2570 AuthUserFile => $auth_user_file,
2571 AuthGroupFile => $auth_group_file,
2572 AuthOrder => 'mod_auth_file.c',
2573
2574 IfModules => {
2575 'mod_delay.c' => {
2576 DelayEngine => 'off',
2577 },
2578
2579 },
2580 };
2581
2582 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2583
2584 if (open(my $fh, ">> $config_file")) {
2585 my $limit_dir = "$tmpdir/foo";
2586 if ($^O eq 'darwin') {
2587 $limit_dir = '/private' . $limit_dir;
2588 }
2589
2590 print $fh <<EOT;
2591 <Directory $limit_dir>
2592 <Limit WRITE>
2593 DenyAll
2594 </Limit>
2595 </Directory>
2596 EOT
2597
2598 unless (close($fh)) {
2599 die("Can't write $config_file: $!");
2600 }
2601
2602 } else {
2603 die("Can't open $config_file: $!");
2604 }
2605
2606 # Open pipes, for use between the parent and child processes. Specifically,
2607 # the child will indicate when it's done with its test by writing a message
2608 # to the parent.
2609 my ($rfh, $wfh);
2610 unless (pipe($rfh, $wfh)) {
2611 die("Can't open pipe: $!");
2612 }
2613
2614 my $ex;
2615
2616 # Fork child
2617 $self->handle_sigchld();
2618 defined(my $pid = fork()) or die("Can't fork: $!");
2619 if ($pid) {
2620 eval {
2621 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2622 $client->login($user, $passwd);
2623
2624 my $path = "bar/../foo";
2625
2626 eval { $client->site('SYMLINK', 'site.conf', 'foo') };
2627 unless ($@) {
2628 die("SITE SYMLINK succeeded unexpectedly");
2629 }
2630
2631 my $resp_code = $client->response_code();
2632 my $resp_msg = $client->response_msg();
2633
2634 my $expected;
2635
2636 $expected = 550;
2637 $self->assert($expected == $resp_code,
2638 test_msg("Expected $expected, got $resp_code"));
2639
2640 $expected = "foo: Operation not permitted";
2641 $self->assert($expected eq $resp_msg,
2642 test_msg("Expected '$expected', got '$resp_msg'"));
2643
2644 if (-l $test_symlink) {
2645 die("Symlink $test_symlink exists unexpectedly");
2646 }
2647 };
2648
2649 if ($@) {
2650 $ex = $@;
2651 }
2652
2653 $wfh->print("done\n");
2654 $wfh->flush();
2655
2656 } else {
2657 eval { server_wait($config_file, $rfh) };
2658 if ($@) {
2659 warn($@);
2660 exit 1;
2661 }
2662
2663 exit 0;
2664 }
2665
2666 # Stop server
2667 server_stop($pid_file);
2668
2669 $self->assert_child_ok($pid);
2670
2671 if ($ex) {
2672 die($ex);
2673 }
2674
2675 unlink($log_file);
2676 }
2677
2678 sub site_misc_utime_failed_bug3519 {
2679 my $self = shift;
2680 my $tmpdir = $self->{tmpdir};
2681
2682 my $config_file = "$tmpdir/site.conf";
2683 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2684 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2685
2686 my $log_file = File::Spec->rel2abs('tests.log');
2687
2688 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2689 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2690
2691 my $user = 'proftpd';
2692 my $passwd = 'test';
2693 my $home_dir = File::Spec->rel2abs($tmpdir);
2694 my $uid = 500;
2695 my $gid = 500;
2696
2697 my $start_dir = File::Spec->rel2abs("$tmpdir/bar");
2698 mkpath($start_dir);
2699
2700 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
2701 mkpath($sub_dir);
2702
2703 my $test_file = File::Spec->rel2abs("$sub_dir/test.txt");
2704 if (open(my $fh, "> $test_file")) {
2705 print $fh "Hello, World!\n";
2706 unless (close($fh)) {
2707 die("Can't write $test_file: $!");
2708 }
2709
2710 } else {
2711 die("Can't open $test_file: $!");
2712 }
2713
2714 # Make sure that, if we're running as root, that the home directory has
2715 # permissions/privs set for the account we create
2716 if ($< == 0) {
2717 unless (chmod(0755, $home_dir, $start_dir, $sub_dir)) {
2718 die("Can't set perms on $home_dir to 0755: $!");
2719 }
2720
2721 unless (chown($uid, $gid, $home_dir, $start_dir, $sub_dir)) {
2722 die("Can't set owner of $home_dir to $uid/$gid: $!");
2723 }
2724 }
2725
2726 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2727 '/bin/bash');
2728 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2729
2730 my $config = {
2731 PidFile => $pid_file,
2732 ScoreboardFile => $scoreboard_file,
2733 SystemLog => $log_file,
2734
2735 AuthUserFile => $auth_user_file,
2736 AuthGroupFile => $auth_group_file,
2737 AuthOrder => 'mod_auth_file.c',
2738
2739 IfModules => {
2740 'mod_delay.c' => {
2741 DelayEngine => 'off',
2742 },
2743
2744 },
2745 };
2746
2747 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2748
2749 if (open(my $fh, ">> $config_file")) {
2750 my $limit_dir = "$tmpdir/foo";
2751 if ($^O eq 'darwin') {
2752 $limit_dir = '/private' . $limit_dir;
2753 }
2754
2755 print $fh <<EOT;
2756 <Directory $limit_dir>
2757 <Limit WRITE>
2758 DenyAll
2759 </Limit>
2760 </Directory>
2761 EOT
2762
2763 unless (close($fh)) {
2764 die("Can't write $config_file: $!");
2765 }
2766
2767 } else {
2768 die("Can't open $config_file: $!");
2769 }
2770
2771 # Open pipes, for use between the parent and child processes. Specifically,
2772 # the child will indicate when it's done with its test by writing a message
2773 # to the parent.
2774 my ($rfh, $wfh);
2775 unless (pipe($rfh, $wfh)) {
2776 die("Can't open pipe: $!");
2777 }
2778
2779 my $ex;
2780
2781 # Fork child
2782 $self->handle_sigchld();
2783 defined(my $pid = fork()) or die("Can't fork: $!");
2784 if ($pid) {
2785 eval {
2786 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2787 $client->login($user, $passwd);
2788
2789 my $path = 'bar/../foo/test.txt';
2790 my $timestamp = '200002240826';
2791
2792 eval { $client->site('UTIME', $timestamp, $path) };
2793 unless ($@) {
2794 die("SITE UTIME succeeded unexpectedly");
2795 }
2796
2797 my $resp_code = $client->response_code();
2798 my $resp_msg = $client->response_msg();
2799
2800 my $expected;
2801
2802 $expected = 550;
2803 $self->assert($expected == $resp_code,
2804 test_msg("Expected $expected, got $resp_code"));
2805
2806 $expected = "UTIME $timestamp $path: Operation not permitted";
2807 $self->assert($expected eq $resp_msg,
2808 test_msg("Expected '$expected', got '$resp_msg'"));
2809 };
2810
2811 if ($@) {
2812 $ex = $@;
2813 }
2814
2815 $wfh->print("done\n");
2816 $wfh->flush();
2817
2818 } else {
2819 eval { server_wait($config_file, $rfh) };
2820 if ($@) {
2821 warn($@);
2822 exit 1;
2823 }
2824
2825 exit 0;
2826 }
2827
2828 # Stop server
2829 server_stop($pid_file);
2830
2831 $self->assert_child_ok($pid);
2832
2833 if ($ex) {
2834 die($ex);
2835 }
2836
2837 unlink($log_file);
2838 }
2839
2840 sub site_misc_mkdir_failed_limit {
2841 my $self = shift;
2842 my $tmpdir = $self->{tmpdir};
2843
2844 my $config_file = "$tmpdir/site.conf";
2845 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2846 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2847
2848 my $log_file = File::Spec->rel2abs('tests.log');
2849
2850 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2851 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2852
2853 my $user = 'proftpd';
2854 my $passwd = 'test';
2855 my $home_dir = File::Spec->rel2abs($tmpdir);
2856 my $uid = 500;
2857 my $gid = 500;
2858
2859 my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
2860
2861 # Make sure that, if we're running as root, that the home directory has
2862 # permissions/privs set for the account we create
2863 if ($< == 0) {
2864 unless (chmod(0755, $home_dir)) {
2865 die("Can't set perms on $home_dir to 0755: $!");
2866 }
2867
2868 unless (chown($uid, $gid, $home_dir)) {
2869 die("Can't set owner of $home_dir to $uid/$gid: $!");
2870 }
2871 }
2872
2873 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2874 '/bin/bash');
2875 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
2876
2877 my $config = {
2878 PidFile => $pid_file,
2879 ScoreboardFile => $scoreboard_file,
2880 SystemLog => $log_file,
2881
2882 AuthUserFile => $auth_user_file,
2883 AuthGroupFile => $auth_group_file,
2884 AuthOrder => 'mod_auth_file.c',
2885
2886 IfModules => {
2887 'mod_delay.c' => {
2888 DelayEngine => 'off',
2889 },
2890 },
2891
2892 Limit => {
2893 SITE_MKDIR => {
2894 DenyAll => '',
2895 },
2896 },
2897
2898 };
2899
2900 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2901
2902 # Open pipes, for use between the parent and child processes. Specifically,
2903 # the child will indicate when it's done with its test by writing a message
2904 # to the parent.
2905 my ($rfh, $wfh);
2906 unless (pipe($rfh, $wfh)) {
2907 die("Can't open pipe: $!");
2908 }
2909
2910 my $ex;
2911
2912 # Fork child
2913 $self->handle_sigchld();
2914 defined(my $pid = fork()) or die("Can't fork: $!");
2915 if ($pid) {
2916 eval {
2917 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2918 $client->login($user, $passwd);
2919
2920 my $path = 'foo/bar/baz';
2921
2922 eval { $client->site('MKDIR', $path) };
2923 unless ($@) {
2924 die("SITE MKDIR succeeded unexpectedly");
2925 }
2926
2927 my $resp_code = $client->response_code();
2928 my $resp_msg = $client->response_msg();
2929
2930 my $expected;
2931
2932 $expected = 550;
2933 $self->assert($expected == $resp_code,
2934 test_msg("Expected $expected, got $resp_code"));
2935
2936 $expected = "MKDIR $path: Operation not permitted";
2937 $self->assert($expected eq $resp_msg,
2938 test_msg("Expected '$expected', got '$resp_msg'"));
2939
2940 # Make sure that the test dir is NOT present
2941 if (-d $test_dir) {
2942 die("Directory $test_dir exists unexpectedly");
2943 }
2944 };
2945
2946 if ($@) {
2947 $ex = $@;
2948 }
2949
2950 $wfh->print("done\n");
2951 $wfh->flush();
2952
2953 } else {
2954 eval { server_wait($config_file, $rfh) };
2955 if ($@) {
2956 warn($@);
2957 exit 1;
2958 }
2959
2960 exit 0;
2961 }
2962
2963 # Stop server
2964 server_stop($pid_file);
2965
2966 $self->assert_child_ok($pid);
2967
2968 if ($ex) {
2969 die($ex);
2970 }
2971
2972 unlink($log_file);
2973 }
2974
2975 sub site_misc_rmdir_failed_limit {
2976 my $self = shift;
2977 my $tmpdir = $self->{tmpdir};
2978
2979 my $config_file = "$tmpdir/site.conf";
2980 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
2981 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
2982
2983 my $log_file = File::Spec->rel2abs('tests.log');
2984
2985 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
2986 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
2987
2988 my $user = 'proftpd';
2989 my $passwd = 'test';
2990 my $home_dir = File::Spec->rel2abs($tmpdir);
2991 my $uid = 500;
2992 my $gid = 500;
2993
2994 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
2995 mkpath($sub_dir);
2996
2997 my $test_dirs = [
2998 File::Spec->rel2abs("$tmpdir/foo"),
2999 File::Spec->rel2abs("$tmpdir/foo/bar"),
3000 $sub_dir,
3001 ];
3002
3003 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt");
3004 if (open(my $fh, "> $test_file")) {
3005 print $fh "Quzz\n";
3006
3007 unless (close($fh)) {
3008 die("Can't write $test_file: $!");
3009 }
3010
3011 } else {
3012 die("Can't open $test_file: $!");
3013 }
3014
3015 # Make sure that, if we're running as root, that the home directory has
3016 # permissions/privs set for the account we create
3017 if ($< == 0) {
3018 unless (chmod(0755, $home_dir)) {
3019 die("Can't set perms on $home_dir to 0755: $!");
3020 }
3021
3022 unless (chown($uid, $gid, $home_dir)) {
3023 die("Can't set owner of $home_dir to $uid/$gid: $!");
3024 }
3025 }
3026
3027 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3028 '/bin/bash');
3029 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
3030
3031 my $config = {
3032 PidFile => $pid_file,
3033 ScoreboardFile => $scoreboard_file,
3034 SystemLog => $log_file,
3035
3036 AuthUserFile => $auth_user_file,
3037 AuthGroupFile => $auth_group_file,
3038 AuthOrder => 'mod_auth_file.c',
3039
3040 IfModules => {
3041 'mod_delay.c' => {
3042 DelayEngine => 'off',
3043 },
3044 },
3045
3046 Limit => {
3047 SITE_RMDIR => {
3048 DenyAll => '',
3049 },
3050 },
3051 };
3052
3053 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3054
3055 # Open pipes, for use between the parent and child processes. Specifically,
3056 # the child will indicate when it's done with its test by writing a message
3057 # to the parent.
3058 my ($rfh, $wfh);
3059 unless (pipe($rfh, $wfh)) {
3060 die("Can't open pipe: $!");
3061 }
3062
3063 my $ex;
3064
3065 # Fork child
3066 $self->handle_sigchld();
3067 defined(my $pid = fork()) or die("Can't fork: $!");
3068 if ($pid) {
3069 eval {
3070 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3071 $client->login($user, $passwd);
3072
3073 my $path = 'foo';
3074
3075 eval { $client->site('RMDIR', $path) };
3076 unless ($@) {
3077 die("SITE RMDIR succeeded unexpectedly");
3078 }
3079
3080 my $resp_code = $client->response_code();
3081 my $resp_msg = $client->response_msg();
3082
3083 my $expected;
3084
3085 $expected = 550;
3086 $self->assert($expected == $resp_code,
3087 test_msg("Expected $expected, got $resp_code"));
3088
3089 $expected = "RMDIR $path: Operation not permitted";
3090 $self->assert($expected eq $resp_msg,
3091 test_msg("Expected '$expected', got '$resp_msg'"));
3092
3093 # Make sure that the test file is NOT gone, along with all of the
3094 # test dirs.
3095 unless (-f $test_file) {
3096 die("File $test_file does not exist as expected");
3097 }
3098
3099 foreach my $test_dir (@$test_dirs) {
3100 unless (-d $test_dir) {
3101 die("Directory $test_dir does not exist as expected");
3102 }
3103 }
3104 };
3105
3106 if ($@) {
3107 $ex = $@;
3108 }
3109
3110 $wfh->print("done\n");
3111 $wfh->flush();
3112
3113 } else {
3114 eval { server_wait($config_file, $rfh) };
3115 if ($@) {
3116 warn($@);
3117 exit 1;
3118 }
3119
3120 exit 0;
3121 }
3122
3123 # Stop server
3124 server_stop($pid_file);
3125
3126 $self->assert_child_ok($pid);
3127
3128 if ($ex) {
3129 die($ex);
3130 }
3131
3132 unlink($log_file);
3133 }
3134
3135 sub site_misc_symlink_failed_limit {
3136 my $self = shift;
3137 my $tmpdir = $self->{tmpdir};
3138
3139 my $config_file = "$tmpdir/site.conf";
3140 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
3141 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
3142
3143 my $log_file = File::Spec->rel2abs('tests.log');
3144
3145 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
3146 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
3147
3148 my $user = 'proftpd';
3149 my $passwd = 'test';
3150 my $home_dir = File::Spec->rel2abs($tmpdir);
3151 my $uid = 500;
3152 my $gid = 500;
3153
3154 my $test_symlink = File::Spec->rel2abs("$tmpdir/foo");
3155
3156 # Make sure that, if we're running as root, that the home directory has
3157 # permissions/privs set for the account we create
3158 if ($< == 0) {
3159 unless (chmod(0755, $home_dir)) {
3160 die("Can't set perms on $home_dir to 0755: $!");
3161 }
3162
3163 unless (chown($uid, $gid, $home_dir)) {
3164 die("Can't set owner of $home_dir to $uid/$gid: $!");
3165 }
3166 }
3167
3168 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3169 '/bin/bash');
3170 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
3171
3172 my $config = {
3173 PidFile => $pid_file,
3174 ScoreboardFile => $scoreboard_file,
3175 SystemLog => $log_file,
3176
3177 AuthUserFile => $auth_user_file,
3178 AuthGroupFile => $auth_group_file,
3179 AuthOrder => 'mod_auth_file.c',
3180
3181 IfModules => {
3182 'mod_delay.c' => {
3183 DelayEngine => 'off',
3184 },
3185 },
3186
3187 Limit => {
3188 SITE_SYMLINK => {
3189 DenyAll => '',
3190 },
3191 },
3192 };
3193
3194 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3195
3196 # Open pipes, for use between the parent and child processes. Specifically,
3197 # the child will indicate when it's done with its test by writing a message
3198 # to the parent.
3199 my ($rfh, $wfh);
3200 unless (pipe($rfh, $wfh)) {
3201 die("Can't open pipe: $!");
3202 }
3203
3204 my $ex;
3205
3206 # Fork child
3207 $self->handle_sigchld();
3208 defined(my $pid = fork()) or die("Can't fork: $!");
3209 if ($pid) {
3210 eval {
3211 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3212 $client->login($user, $passwd);
3213
3214 my $src = 'site.conf';
3215 my $dst = 'foo';
3216
3217 eval { $client->site('SYMLINK', $src, $dst) };
3218 unless ($@) {
3219 die("SITE SYMLINK succeeded unexpectedly");
3220 }
3221
3222 my $resp_code = $client->response_code();
3223 my $resp_msg = $client->response_msg();
3224
3225 my $expected;
3226
3227 $expected = 550;
3228 $self->assert($expected == $resp_code,
3229 test_msg("Expected $expected, got $resp_code"));
3230
3231 $expected = "$src: Operation not permitted";
3232 $self->assert($expected eq $resp_msg,
3233 test_msg("Expected '$expected', got '$resp_msg'"));
3234
3235 if (-l $test_symlink) {
3236 die("Symlink $test_symlink exists unexpectedly");
3237 }
3238 };
3239
3240 if ($@) {
3241 $ex = $@;
3242 }
3243
3244 $wfh->print("done\n");
3245 $wfh->flush();
3246
3247 } else {
3248 eval { server_wait($config_file, $rfh) };
3249 if ($@) {
3250 warn($@);
3251 exit 1;
3252 }
3253
3254 exit 0;
3255 }
3256
3257 # Stop server
3258 server_stop($pid_file);
3259
3260 $self->assert_child_ok($pid);
3261
3262 if ($ex) {
3263 die($ex);
3264 }
3265
3266 unlink($log_file);
3267 }
3268
3269 sub site_misc_utime_failed_limit {
3270 my $self = shift;
3271 my $tmpdir = $self->{tmpdir};
3272 my $setup = test_setup($tmpdir, 'site');
3273
3274 my $config = {
3275 PidFile => $setup->{pid_file},
3276 ScoreboardFile => $setup->{scoreboard_file},
3277 SystemLog => $setup->{log_file},
3278
3279 AuthUserFile => $setup->{auth_user_file},
3280 AuthGroupFile => $setup->{auth_group_file},
3281 AuthOrder => 'mod_auth_file.c',
3282
3283 IfModules => {
3284 'mod_delay.c' => {
3285 DelayEngine => 'off',
3286 },
3287 },
3288
3289 Limit => {
3290 SITE_UTIME => {
3291 DenyAll => '',
3292 },
3293 },
3294 };
3295
3296 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3297 $config);
3298
3299 # Open pipes, for use between the parent and child processes. Specifically,
3300 # the child will indicate when it's done with its test by writing a message
3301 # to the parent.
3302 my ($rfh, $wfh);
3303 unless (pipe($rfh, $wfh)) {
3304 die("Can't open pipe: $!");
3305 }
3306
3307 my $ex;
3308
3309 # Fork child
3310 $self->handle_sigchld();
3311 defined(my $pid = fork()) or die("Can't fork: $!");
3312 if ($pid) {
3313 eval {
3314 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3315 $client->login($setup->{user}, $setup->{passwd});
3316
3317 my $timestamp = '200002240826';
3318 my $path = 'site.conf';
3319
3320 eval { $client->site('UTIME', $timestamp, $path) };
3321 unless ($@) {
3322 die("SITE UTIME succeeded unexpectedly");
3323 }
3324
3325 my $resp_code = $client->response_code();
3326 my $resp_msg = $client->response_msg();
3327
3328 my $expected = 550;
3329 $self->assert($expected == $resp_code,
3330 test_msg("Expected response code $expected, got $resp_code"));
3331
3332 $expected = "UTIME $timestamp $path: Operation not permitted";
3333 $self->assert($expected eq $resp_msg,
3334 test_msg("Expected response message '$expected', got '$resp_msg'"));
3335 };
3336 if ($@) {
3337 $ex = $@;
3338 }
3339
3340 $wfh->print("done\n");
3341 $wfh->flush();
3342
3343 } else {
3344 eval { server_wait($setup->{config_file}, $rfh) };
3345 if ($@) {
3346 warn($@);
3347 exit 1;
3348 }
3349
3350 exit 0;
3351 }
3352
3353 # Stop server
3354 server_stop($setup->{pid_file});
3355 $self->assert_child_ok($pid);
3356
3357 test_cleanup($setup->{log_file}, $ex);
3358 }
3359
3360 sub site_misc_utime_atime_mtime_ctime_bug4130 {
3361 my $self = shift;
3362 my $tmpdir = $self->{tmpdir};
3363
3364 my $config_file = "$tmpdir/site.conf";
3365 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
3366 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
3367
3368 my $log_file = File::Spec->rel2abs('tests.log');
3369
3370 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
3371 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
3372
3373 my $user = 'proftpd';
3374 my $passwd = 'test';
3375 my $group = 'ftpd';
3376 my $home_dir = File::Spec->rel2abs($tmpdir);
3377 my $uid = 500;
3378 my $gid = 500;
3379
3380 # Make sure that, if we're running as root, that the home directory has
3381 # permissions/privs set for the account we create
3382 if ($< == 0) {
3383 unless (chmod(0755, $home_dir)) {
3384 die("Can't set perms on $home_dir to 0755: $!");
3385 }
3386
3387 unless (chown($uid, $gid, $home_dir)) {
3388 die("Can't set owner of $home_dir to $uid/$gid: $!");
3389 }
3390 }
3391
3392 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3393 '/bin/bash');
3394 auth_group_write($auth_group_file, $group, $gid, $user);
3395
3396 my $config = {
3397 PidFile => $pid_file,
3398 ScoreboardFile => $scoreboard_file,
3399 SystemLog => $log_file,
3400
3401 AuthUserFile => $auth_user_file,
3402 AuthGroupFile => $auth_group_file,
3403 AuthOrder => 'mod_auth_file.c',
3404
3405 IfModules => {
3406 'mod_delay.c' => {
3407 DelayEngine => 'off',
3408 },
3409 },
3410 };
3411
3412 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3413
3414 # Open pipes, for use between the parent and child processes. Specifically,
3415 # the child will indicate when it's done with its test by writing a message
3416 # to the parent.
3417 my ($rfh, $wfh);
3418 unless (pipe($rfh, $wfh)) {
3419 die("Can't open pipe: $!");
3420 }
3421
3422 my $ex;
3423
3424 # Fork child
3425 $self->handle_sigchld();
3426 defined(my $pid = fork()) or die("Can't fork: $!");
3427 if ($pid) {
3428 eval {
3429 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3430 $client->login($user, $passwd);
3431
3432 my ($resp_code, $resp_msg) = $client->site('UTIME', 'site.conf',
3433 '200002240826', '200002240826', '200002240826', 'UTC');
3434
3435 my $expected;
3436
3437 $expected = 200;
3438 $self->assert($expected == $resp_code,
3439 test_msg("Expected response code $expected, got $resp_code"));
3440
3441 $expected = "SITE UTIME command successful";
3442 $self->assert($expected eq $resp_msg,
3443 test_msg("Expected response message '$expected', got '$resp_msg'"));
3444
3445 my ($atime, $mtime) = (stat($config_file))[8,9];
3446
3447 $expected = 951380760;
3448 $self->assert($expected == $atime,
3449 test_msg("Expected $expected, got $atime"));
3450 $self->assert($expected == $mtime,
3451 test_msg("Expected $expected, got $mtime"));
3452 };
3453
3454 if ($@) {
3455 $ex = $@;
3456 }
3457
3458 $wfh->print("done\n");
3459 $wfh->flush();
3460
3461 } else {
3462 eval { server_wait($config_file, $rfh) };
3463 if ($@) {
3464 warn($@);
3465 exit 1;
3466 }
3467
3468 exit 0;
3469 }
3470
3471 # Stop server
3472 server_stop($pid_file);
3473
3474 $self->assert_child_ok($pid);
3475
3476 if ($ex) {
3477 die($ex);
3478 }
3479
3480 unlink($log_file);
3481 }
3482
3483 sub site_misc_utime_atime_mtime_ctime_with_spaces_bug4130 {
3484 my $self = shift;
3485 my $tmpdir = $self->{tmpdir};
3486
3487 my $config_file = "$tmpdir/site.conf";
3488 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
3489 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
3490
3491 my $log_file = File::Spec->rel2abs('tests.log');
3492
3493 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
3494 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
3495
3496 my $user = 'proftpd';
3497 my $passwd = 'test';
3498 my $group = 'ftpd';
3499 my $home_dir = File::Spec->rel2abs($tmpdir);
3500 my $uid = 500;
3501 my $gid = 500;
3502
3503 # Make sure that, if we're running as root, that the home directory has
3504 # permissions/privs set for the account we create
3505 if ($< == 0) {
3506 unless (chmod(0755, $home_dir)) {
3507 die("Can't set perms on $home_dir to 0755: $!");
3508 }
3509
3510 unless (chown($uid, $gid, $home_dir)) {
3511 die("Can't set owner of $home_dir to $uid/$gid: $!");
3512 }
3513 }
3514
3515 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3516 '/bin/bash');
3517 auth_group_write($auth_group_file, $group, $gid, $user);
3518
3519 my $test_file = File::Spec->rel2abs("$tmpdir/test file");
3520 if (open(my $fh, "> $test_file")) {
3521 close($fh);
3522
3523 } else {
3524 die("Can't open $test_file: $!");
3525 }
3526
3527 my $config = {
3528 PidFile => $pid_file,
3529 ScoreboardFile => $scoreboard_file,
3530 SystemLog => $log_file,
3531
3532 AuthUserFile => $auth_user_file,
3533 AuthGroupFile => $auth_group_file,
3534 AuthOrder => 'mod_auth_file.c',
3535
3536 IfModules => {
3537 'mod_delay.c' => {
3538 DelayEngine => 'off',
3539 },
3540 },
3541 };
3542
3543 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3544
3545 # Open pipes, for use between the parent and child processes. Specifically,
3546 # the child will indicate when it's done with its test by writing a message
3547 # to the parent.
3548 my ($rfh, $wfh);
3549 unless (pipe($rfh, $wfh)) {
3550 die("Can't open pipe: $!");
3551 }
3552
3553 my $ex;
3554
3555 # Fork child
3556 $self->handle_sigchld();
3557 defined(my $pid = fork()) or die("Can't fork: $!");
3558 if ($pid) {
3559 eval {
3560 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3561 $client->login($user, $passwd);
3562
3563 my ($resp_code, $resp_msg) = $client->site('UTIME', 'test', 'file',
3564 '200002240826', '200002240826', '200002240826', 'UTC');
3565
3566 my $expected;
3567
3568 $expected = 200;
3569 $self->assert($expected == $resp_code,
3570 test_msg("Expected response code $expected, got $resp_code"));
3571
3572 $expected = "SITE UTIME command successful";
3573 $self->assert($expected eq $resp_msg,
3574 test_msg("Expected response message '$expected', got '$resp_msg'"));
3575
3576 my ($atime, $mtime) = (stat($test_file))[8,9];
3577
3578 $expected = 951380760;
3579 $self->assert($expected == $atime,
3580 test_msg("Expected $expected, got $atime"));
3581 $self->assert($expected == $mtime,
3582 test_msg("Expected $expected, got $mtime"));
3583 };
3584
3585 if ($@) {
3586 $ex = $@;
3587 }
3588
3589 $wfh->print("done\n");
3590 $wfh->flush();
3591
3592 } else {
3593 eval { server_wait($config_file, $rfh) };
3594 if ($@) {
3595 warn($@);
3596 exit 1;
3597 }
3598
3599 exit 0;
3600 }
3601
3602 # Stop server
3603 server_stop($pid_file);
3604
3605 $self->assert_child_ok($pid);
3606
3607 if ($ex) {
3608 die($ex);
3609 }
3610
3611 unlink($log_file);
3612 }
3613
3614 sub site_misc_extlog_rmdir_resp_code_empty_dir {
3615 my $self = shift;
3616 my $tmpdir = $self->{tmpdir};
3617
3618 my $config_file = "$tmpdir/site.conf";
3619 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
3620 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
3621 my $extlog_file = File::Spec->rel2abs("$tmpdir/ext.log");
3622
3623 my $log_file = File::Spec->rel2abs('tests.log');
3624
3625 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
3626 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
3627
3628 my $user = 'proftpd';
3629 my $passwd = 'test';
3630 my $group = 'ftpd';
3631 my $home_dir = File::Spec->rel2abs($tmpdir);
3632 my $uid = 500;
3633 my $gid = 500;
3634
3635 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
3636 mkpath($sub_dir);
3637
3638 my $test_dirs = [
3639 File::Spec->rel2abs("$tmpdir/foo"),
3640 File::Spec->rel2abs("$tmpdir/foo/bar"),
3641 $sub_dir,
3642 ];
3643
3644 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt");
3645 if (open(my $fh, "> $test_file")) {
3646 print $fh "Quzz\n";
3647
3648 unless (close($fh)) {
3649 die("Can't write $test_file: $!");
3650 }
3651
3652 } else {
3653 die("Can't open $test_file: $!");
3654 }
3655
3656 # Make sure that, if we're running as root, that the home directory has
3657 # permissions/privs set for the account we create
3658 if ($< == 0) {
3659 unless (chmod(0755, $home_dir)) {
3660 die("Can't set perms on $home_dir to 0755: $!");
3661 }
3662
3663 unless (chown($uid, $gid, $home_dir)) {
3664 die("Can't set owner of $home_dir to $uid/$gid: $!");
3665 }
3666 }
3667
3668 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3669 '/bin/bash');
3670 auth_group_write($auth_group_file, $group, $gid, $user);
3671
3672 my $config = {
3673 PidFile => $pid_file,
3674 ScoreboardFile => $scoreboard_file,
3675 SystemLog => $log_file,
3676
3677 AuthUserFile => $auth_user_file,
3678 AuthGroupFile => $auth_group_file,
3679 AuthOrder => 'mod_auth_file.c',
3680
3681 LogFormat => 'custom "%r: %s"',
3682 ExtendedLog => "$extlog_file MISC custom",
3683
3684 IfModules => {
3685 'mod_delay.c' => {
3686 DelayEngine => 'off',
3687 },
3688 },
3689 };
3690
3691 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3692
3693 # Open pipes, for use between the parent and child processes. Specifically,
3694 # the child will indicate when it's done with its test by writing a message
3695 # to the parent.
3696 my ($rfh, $wfh);
3697 unless (pipe($rfh, $wfh)) {
3698 die("Can't open pipe: $!");
3699 }
3700
3701 my $ex;
3702
3703 # Fork child
3704 $self->handle_sigchld();
3705 defined(my $pid = fork()) or die("Can't fork: $!");
3706 if ($pid) {
3707 eval {
3708 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3709 $client->login($user, $passwd);
3710
3711 my ($resp_code, $resp_msg) = $client->site('RMDIR', 'foo');
3712
3713 my $expected;
3714
3715 $expected = 200;
3716 $self->assert($expected == $resp_code,
3717 test_msg("Expected response code $expected, got $resp_code"));
3718
3719 $expected = "SITE RMDIR command successful";
3720 $self->assert($expected eq $resp_msg,
3721 test_msg("Expected response message '$expected', got '$resp_msg'"));
3722
3723 # Make sure that the test file is gone, along with all of the
3724 # test dirs.
3725 if (-f $test_file) {
3726 die("File $test_file exists, should be deleted");
3727 }
3728
3729 foreach my $test_dir (@$test_dirs) {
3730 if (-d $test_dir) {
3731 die("Directory $test_dir exists, should be deleted");
3732 }
3733 }
3734 };
3735 if ($@) {
3736 $ex = $@;
3737 }
3738
3739 $wfh->print("done\n");
3740 $wfh->flush();
3741
3742 } else {
3743 eval { server_wait($config_file, $rfh) };
3744 if ($@) {
3745 warn($@);
3746 exit 1;
3747 }
3748
3749 exit 0;
3750 }
3751
3752 # Stop server
3753 server_stop($pid_file);
3754
3755 $self->assert_child_ok($pid);
3756
3757 eval {
3758 if (open(my $fh, "< $extlog_file")) {
3759 my $ok = 0;
3760
3761 while (my $line = <$fh>) {
3762 chomp($line);
3763
3764 if ($ENV{TEST_VERBOSE}) {
3765 print STDERR "# line: $line\n"
3766 }
3767
3768 if ($line =~ /SITE RMDIR (\S+): 200/) {
3769 $ok = 1;
3770 last;
3771 }
3772 }
3773
3774 close($fh);
3775
3776 $self->assert($ok, "ExtendedLog did not contain expected log line");
3777 } else {
3778 die("Can't read $extlog_file: $!");
3779 }
3780 };
3781 if ($@) {
3782 $ex = $@;
3783 }
3784
3785 if ($ex) {
3786 die($ex);
3787 }
3788
3789 unlink($log_file);
3790 }
3791
3792 sub site_misc_extlog_rmdir_resp_code_nonempty_dir {
3793 my $self = shift;
3794 my $tmpdir = $self->{tmpdir};
3795
3796 my $config_file = "$tmpdir/site.conf";
3797 my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid");
3798 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard");
3799 my $extlog_file = File::Spec->rel2abs("$tmpdir/ext.log");
3800
3801 my $log_file = File::Spec->rel2abs('tests.log');
3802
3803 my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd");
3804 my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group");
3805
3806 my $user = 'proftpd';
3807 my $passwd = 'test';
3808 my $group = 'ftpd';
3809 my $home_dir = File::Spec->rel2abs($tmpdir);
3810 my $uid = 500;
3811 my $gid = 500;
3812
3813 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz");
3814 mkpath($sub_dir);
3815
3816 my $test_dirs = [
3817 File::Spec->rel2abs("$tmpdir/foo"),
3818 File::Spec->rel2abs("$tmpdir/foo/bar"),
3819 $sub_dir,
3820 ];
3821
3822 my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt");
3823 if (open(my $fh, "> $test_file")) {
3824 print $fh "Quzz\n";
3825
3826 unless (close($fh)) {
3827 die("Can't write $test_file: $!");
3828 }
3829
3830 } else {
3831 die("Can't open $test_file: $!");
3832 }
3833
3834 # Make sure that, if we're running as root, that the home directory has
3835 # permissions/privs set for the account we create
3836 if ($< == 0) {
3837 unless (chmod(0755, $home_dir)) {
3838 die("Can't set perms on $home_dir to 0755: $!");
3839 }
3840
3841 unless (chown($uid, $gid, $home_dir)) {
3842 die("Can't set owner of $home_dir to $uid/$gid: $!");
3843 }
3844 }
3845
3846 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3847 '/bin/bash');
3848 auth_group_write($auth_group_file, $group, $gid, $user);
3849
3850 my $config = {
3851 PidFile => $pid_file,
3852 ScoreboardFile => $scoreboard_file,
3853 SystemLog => $log_file,
3854
3855 AuthUserFile => $auth_user_file,
3856 AuthGroupFile => $auth_group_file,
3857 AuthOrder => 'mod_auth_file.c',
3858
3859 LogFormat => 'custom "%r: %s"',
3860 ExtendedLog => "$extlog_file ALL custom",
3861
3862 IfModules => {
3863 'mod_delay.c' => {
3864 DelayEngine => 'off',
3865 },
3866 },
3867 };
3868
3869 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3870
3871 # Open pipes, for use between the parent and child processes. Specifically,
3872 # the child will indicate when it's done with its test by writing a message
3873 # to the parent.
3874 my ($rfh, $wfh);
3875 unless (pipe($rfh, $wfh)) {
3876 die("Can't open pipe: $!");
3877 }
3878
3879 my $ex;
3880
3881 # Fork child
3882 $self->handle_sigchld();
3883 defined(my $pid = fork()) or die("Can't fork: $!");
3884 if ($pid) {
3885 eval {
3886 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3887 $client->login($user, $passwd);
3888
3889 my ($resp_code, $resp_msg) = $client->site('RMDIR', 'foo');
3890
3891 my $expected;
3892
3893 $expected = 200;
3894 $self->assert($expected == $resp_code,
3895 test_msg("Expected response code $expected, got $resp_code"));
3896
3897 $expected = "SITE RMDIR command successful";
3898 $self->assert($expected eq $resp_msg,
3899 test_msg("Expected response message '$expected', got '$resp_msg'"));
3900
3901 # Make sure that the test file is gone, along with all of the
3902 # test dirs.
3903 if (-f $test_file) {
3904 die("File $test_file exists, should be deleted");
3905 }
3906
3907 foreach my $test_dir (@$test_dirs) {
3908 if (-d $test_dir) {
3909 die("Directory $test_dir exists, should be deleted");
3910 }
3911 }
3912 };
3913
3914 if ($@) {
3915 $ex = $@;
3916 }
3917
3918 $wfh->print("done\n");
3919 $wfh->flush();
3920
3921 } else {
3922 eval { server_wait($config_file, $rfh) };
3923 if ($@) {
3924 warn($@);
3925 exit 1;
3926 }
3927
3928 exit 0;
3929 }
3930
3931 # Stop server
3932 server_stop($pid_file);
3933
3934 $self->assert_child_ok($pid);
3935
3936 eval {
3937 if (open(my $fh, "< $extlog_file")) {
3938 my $dele_ok = 0;
3939 my $rmd_ok = 0;
3940 my $site_ok = 0;
3941
3942 while (my $line = <$fh>) {
3943 chomp($line);
3944
3945 if ($ENV{TEST_VERBOSE}) {
3946 print STDERR "# line: $line\n"
3947 }
3948
3949 if ($line =~ /DELE .*?250$/) {
3950 $dele_ok = 1;
3951 next;
3952 }
3953
3954 if ($line =~ /RMD .*?257$/) {
3955 $rmd_ok = 1;
3956 next;
3957 }
3958
3959 if ($line =~ /SITE RMDIR (\S+): 200$/) {
3960 $site_ok = 1;
3961 last;
3962 }
3963 }
3964
3965 close($fh);
3966
3967 $self->assert($dele_ok, "ExtendedLog did not contain expected log line for DELE");
3968 $self->assert($rmd_ok, "ExtendedLog did not contain expected log line for RMD");
3969 $self->assert($site_ok, "ExtendedLog did not contain expected log line for SITE RMDIR");
3970
3971 } else {
3972 die("Can't read $extlog_file: $!");
3973 }
3974 };
3975 if ($@) {
3976 $ex = $@;
3977 }
3978
3979 if ($ex) {
3980 die($ex);
3981 }
3982
3983 unlink($log_file);
3984 }
3985
3986 sub site_misc_utime_failed_unauthenticated_issue1976 {
3987 my $self = shift;
3988 my $tmpdir = $self->{tmpdir};
3989 my $setup = test_setup($tmpdir, 'site');
3990
3991 my $config = {
3992 PidFile => $setup->{pid_file},
3993 ScoreboardFile => $setup->{scoreboard_file},
3994 SystemLog => $setup->{log_file},
3995
3996 AuthUserFile => $setup->{auth_user_file},
3997 AuthGroupFile => $setup->{auth_group_file},
3998 AuthOrder => 'mod_auth_file.c',
3999
4000 IfModules => {
4001 'mod_delay.c' => {
4002 DelayEngine => 'off',
4003 },
4004 },
4005
4006 Limit => {
4007 SITE_UTIME => {
4008 DenyAll => '',
4009 },
4010 },
4011 };
4012
4013 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4014 $config);
4015
4016 # Open pipes, for use between the parent and child processes. Specifically,
4017 # the child will indicate when it's done with its test by writing a message
4018 # to the parent.
4019 my ($rfh, $wfh);
4020 unless (pipe($rfh, $wfh)) {
4021 die("Can't open pipe: $!");
4022 }
4023
4024 my $ex;
4025
4026 # Fork child
4027 $self->handle_sigchld();
4028 defined(my $pid = fork()) or die("Can't fork: $!");
4029 if ($pid) {
4030 eval {
4031 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4032 my $timestamp = '200002240826';
4033 my $path = 'site.conf';
4034
4035 eval { $client->site('UTIME', $timestamp, $path) };
4036 unless ($@) {
4037 die("SITE UTIME succeeded unexpectedly");
4038 }
4039
4040 my $resp_code = $client->response_code();
4041 my $resp_msg = $client->response_msg();
4042
4043 my $expected = 530;
4044 $self->assert($expected == $resp_code,
4045 test_msg("Expected response code $expected, got $resp_code"));
4046
4047 $expected = 'Please login with USER and PASS';
4048 $self->assert($expected eq $resp_msg,
4049 test_msg("Expected response message '$expected', got '$resp_msg'"));
4050
4051 $client->quit();
4052 };
4053 if ($@) {
4054 $ex = $@;
4055 }
4056
4057 $wfh->print("done\n");
4058 $wfh->flush();
4059
4060 } else {
4061 eval { server_wait($setup->{config_file}, $rfh) };
4062 if ($@) {
4063 warn($@);
4064 exit 1;
4065 }
4066
4067 exit 0;
4068 }
4069
4070 # Stop server
4071 server_stop($setup->{pid_file});
4072 $self->assert_child_ok($pid);
4073
4074 test_cleanup($setup->{log_file}, $ex);
4075 }
4076
4077 1;