Debian Codegraph @

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

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