Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Logging/ExtendedLog.pm

raw
1 package ProFTPD::Tests::Logging::ExtendedLog;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Compress::Raw::Zlib;
8 use Compress::Zlib;
9 use File::Copy;
10 use File::Path qw(mkpath);
11 use File::Spec;
12 use IO::Handle;
13 use IPC::Open3;
14 use Net::Address::IP::Local;
15 use POSIX qw(:fcntl_h);
16
17 use ProFTPD::TestSuite::FTP;
18 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite :features);
19
20 $| = 1;
21
22 my $order = 0;
23
24 my $TESTS = {
25 extlog_retr_default => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 extlog_retr_bug3137 => {
31 order => ++$order,
32 test_class => [qw(bug forking)],
33 },
34
35 extlog_stor_bug3137 => {
36 order => ++$order,
37 test_class => [qw(bug forking)],
38 },
39
40 extlog_site_cmds_bug3171 => {
41 order => ++$order,
42 test_class => [qw(bug forking)],
43 },
44
45 extlog_mlsd_var_d_D_f_F_bug3950 => {
46 order => ++$order,
47 test_class => [qw(bug forking)],
48 },
49
50 extlog_sftp_mlsd_var_d_D_f_F_bug3950 => {
51 order => ++$order,
52 test_class => [qw(bug forking mod_sftp)],
53 },
54
55 extlog_mfmt_var_d_D_f_F => {
56 order => ++$order,
57 test_class => [qw(bug forking)],
58 },
59
60 extlog_protocol => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 extlog_remote_port => {
66 order => ++$order,
67 test_class => [qw(forking)],
68 },
69
70 extlog_protocol_version_quoted_bug3383 => {
71 order => ++$order,
72 test_class => [qw(bug forking)],
73 },
74
75 extlog_rename_from => {
76 order => ++$order,
77 test_class => [qw(forking)],
78 },
79
80 extlog_sftp_rename_from => {
81 order => ++$order,
82 test_class => [qw(bug forking mod_sftp)],
83 },
84
85 extlog_ext_sftp_posix_rename_bug3949 => {
86 order => ++$order,
87 test_class => [qw(bug forking mod_sftp)],
88 },
89
90 extlog_orig_user => {
91 order => ++$order,
92 test_class => [qw(forking)],
93 },
94
95 extlog_bug1908 => {
96 order => ++$order,
97 test_class => [qw(bug forking rootprivs)],
98 },
99
100 extlog_file_modified_bug3457 => {
101 order => ++$order,
102 test_class => [qw(bug forking)],
103 },
104
105 extlog_dele_bug3469 => {
106 order => ++$order,
107 test_class => [qw(bug forking)],
108 },
109
110 extlog_client_dir_bug3395 => {
111 order => ++$order,
112 test_class => [qw(bug forking)],
113 },
114
115 extlog_client_dir_chroot_bug3395 => {
116 order => ++$order,
117 test_class => [qw(bug forking rootprivs)],
118 },
119
120 extlog_device_full => {
121 order => ++$order,
122 test_class => [qw(forking os_linux)],
123 },
124
125 extlog_uid_bug3390 => {
126 order => ++$order,
127 test_class => [qw(bug forking rootprivs)],
128 },
129
130 extlog_gid_bug3390 => {
131 order => ++$order,
132 test_class => [qw(bug forking rootprivs)],
133 },
134
135 extlog_pass_ok_var_s_bug3528 => {
136 order => ++$order,
137 test_class => [qw(bug forking)],
138 },
139
140 extlog_pass_failed_var_s_bug3528 => {
141 order => ++$order,
142 test_class => [qw(bug forking)],
143 },
144
145 extlog_ftp_raw_bytes_bug3554 => {
146 order => ++$order,
147 test_class => [qw(bug forking)],
148 },
149
150 extlog_ftp_sendfile_raw_bytes_bug3554 => {
151 order => ++$order,
152 test_class => [qw(bug feature_sendfile forking)],
153 },
154
155 extlog_ftp_deflate_raw_bytes_bug3554 => {
156 order => ++$order,
157 test_class => [qw(bug forking mod_deflate)],
158 },
159
160 extlog_ftps_raw_bytes_bug3554 => {
161 order => ++$order,
162 test_class => [qw(bug forking mod_tls)],
163 },
164
165 extlog_sftp_raw_bytes_bug3554 => {
166 order => ++$order,
167 test_class => [qw(bug forking mod_sftp)],
168 },
169
170 extlog_scp_raw_bytes_bug3554 => {
171 order => ++$order,
172 test_class => [qw(bug forking mod_sftp)],
173 },
174
175 extlog_exit_bug3559 => {
176 order => ++$order,
177 test_class => [qw(bug forking)],
178 },
179
180 extlog_eos_reason_quit => {
181 order => ++$order,
182 test_class => [qw(forking)],
183 },
184
185 extlog_eos_reason_eof => {
186 order => ++$order,
187 test_class => [qw(forking)],
188 },
189
190 extlog_eos_reason_timeoutidle => {
191 order => ++$order,
192 test_class => [qw(forking)],
193 },
194
195 extlog_eos_reason_timeoutlogin => {
196 order => ++$order,
197 test_class => [qw(forking)],
198 },
199
200 extlog_eos_reason_timeoutnotransfer => {
201 order => ++$order,
202 test_class => [qw(forking)],
203 },
204
205 extlog_eos_reason_timeoutsession => {
206 order => ++$order,
207 test_class => [qw(forking)],
208 },
209
210 extlog_eos_reason_timeoutstalled => {
211 order => ++$order,
212 test_class => [qw(forking)],
213 },
214
215 extlog_vars_H_L_matching_server_bug3620 => {
216 order => ++$order,
217 test_class => [qw(bug forking)],
218 },
219
220 extlog_vars_H_L_default_server_bug3620 => {
221 order => ++$order,
222 test_class => [qw(bug forking)],
223 },
224
225 extlog_user_pass => {
226 order => ++$order,
227 test_class => [qw(forking)],
228 },
229
230 extlog_anon_user_pass => {
231 order => ++$order,
232 test_class => [qw(forking rootprivs)],
233 },
234
235 extlog_cmd_resp => {
236 order => ++$order,
237 test_class => [qw(forking)],
238 },
239
240 extlog_xfer_timeout_bug3696 => {
241 order => ++$order,
242 test_class => [qw(bug forking)],
243 },
244
245 extlog_sftp_xfer_timeout_bug3696 => {
246 order => ++$order,
247 test_class => [qw(bug forking mod_sftp ssh2)],
248 },
249
250 extlog_var_r => {
251 order => ++$order,
252 test_class => [qw(forking)],
253 },
254
255 extlog_pass_var_r => {
256 order => ++$order,
257 test_class => [qw(forking)],
258 },
259
260 extlog_sftp_pass_var_r => {
261 order => ++$order,
262 test_class => [qw(forking mod_sftp)],
263 },
264
265 extlog_sftp_retr_var_s_bug3948 => {
266 order => ++$order,
267 test_class => [qw(bug forking mod_sftp)],
268 },
269
270 extlog_sftp_stor_var_s_bug3948 => {
271 order => ++$order,
272 test_class => [qw(bug forking mod_sftp)],
273 },
274
275 extlog_abor => {
276 order => ++$order,
277 test_class => [qw(forking)],
278 },
279
280 extlog_xfer_status_nonxfer => {
281 order => ++$order,
282 test_class => [qw(forking)],
283 },
284
285 extlog_xfer_status_success => {
286 order => ++$order,
287 test_class => [qw(forking)],
288 },
289
290 extlog_xfer_status_cancelled => {
291 order => ++$order,
292 test_class => [qw(forking)],
293 },
294
295 extlog_xfer_status_failed => {
296 order => ++$order,
297 test_class => [qw(forking)],
298 },
299
300 extlog_xfer_status_timeout => {
301 order => ++$order,
302 test_class => [qw(forking)],
303 },
304
305 extlog_xfer_failure_none => {
306 order => ++$order,
307 test_class => [qw(forking)],
308 },
309
310 extlog_xfer_failure_reason => {
311 order => ++$order,
312 test_class => [qw(forking)],
313 },
314
315 extlog_ftps_xfer_status_cancelled => {
316 order => ++$order,
317 test_class => [qw(forking mod_tls)],
318 },
319
320 extlog_ftps_xfer_status_failed => {
321 order => ++$order,
322 test_class => [qw(forking mod_tls)],
323 },
324
325 extlog_login_maxclients_bug3811 => {
326 order => ++$order,
327 test_class => [qw(bug forking)],
328 },
329
330 extlog_login_maxclientsperclass_bug3811 => {
331 order => ++$order,
332 test_class => [qw(bug forking)],
333 },
334
335 extlog_login_maxclientsperhost_bug3811 => {
336 order => ++$order,
337 test_class => [qw(bug forking)],
338 },
339
340 extlog_login_maxclientsperuser_bug3811 => {
341 order => ++$order,
342 test_class => [qw(bug forking)],
343 },
344
345 extlog_preauth_var_U_bug3822 => {
346 order => ++$order,
347 test_class => [qw(bug forking)],
348 },
349
350 extlog_preauth_var_u_bug3822 => {
351 order => ++$order,
352 test_class => [qw(bug forking)],
353 },
354
355 extlog_micros_ts_bug3889 => {
356 order => ++$order,
357 test_class => [qw(bug forking)],
358 },
359
360 extlog_millis_ts_bug3889 => {
361 order => ++$order,
362 test_class => [qw(bug forking)],
363 },
364
365 extlog_iso8601_ts_bug3889 => {
366 order => ++$order,
367 test_class => [qw(bug forking)],
368 },
369
370 extlog_dirs_class_var_f_bug3966 => {
371 order => ++$order,
372 test_class => [qw(bug forking)],
373 },
374
375 extlog_var_basename_bug3987 => {
376 order => ++$order,
377 test_class => [qw(bug forking)],
378 },
379
380 extlog_exclusion_bug4067 => {
381 order => ++$order,
382 test_class => [qw(bug forking)],
383 },
384
385 extlog_sftp_ssh_ssh_issue1617 => {
386 order => ++$order,
387 test_class => [qw(bug forking mod_sftp)],
388 },
389
390 extlog_sftp_ssh_sftp_bug4067 => {
391 order => ++$order,
392 test_class => [qw(bug forking mod_sftp)],
393 },
394
395 extlog_sftp_ssh_sftp_exclusion_bug4067 => {
396 order => ++$order,
397 test_class => [qw(bug forking mod_sftp)],
398 },
399
400 extlog_sftp_read_write_bug4067 => {
401 order => ++$order,
402 test_class => [qw(bug forking mod_sftp)],
403 },
404
405 extlog_sftp_xfer_status_filtered => {
406 order => ++$order,
407 test_class => [qw(forking mod_sftp)],
408 },
409
410 extlog_var_file_offset => {
411 order => ++$order,
412 test_class => [qw(forking)],
413 },
414
415 extlog_var_file_size_retr => {
416 order => ++$order,
417 test_class => [qw(forking)],
418 },
419
420 extlog_sftp_var_file_size_retr => {
421 order => ++$order,
422 test_class => [qw(forking mod_sftp)],
423 },
424
425 extlog_var_file_size_stor => {
426 order => ++$order,
427 test_class => [qw(forking)],
428 },
429
430 extlog_sftp_var_file_size_stor => {
431 order => ++$order,
432 test_class => [qw(forking mod_sftp)],
433 },
434
435 extlog_var_transfer_type_retr => {
436 order => ++$order,
437 test_class => [qw(forking)],
438 },
439
440 extlog_var_transfer_type_stor => {
441 order => ++$order,
442 test_class => [qw(forking)],
443 },
444
445 extlog_file_transfer_secs => {
446 order => ++$order,
447 test_class => [qw(forking)],
448 },
449
450 extlog_file_transfer_millisecs_bug4218 => {
451 order => ++$order,
452 test_class => [qw(bug forking)],
453 },
454
455 extlog_response_millisecs_bug4218 => {
456 order => ++$order,
457 test_class => [qw(bug forking)],
458 },
459
460 extlog_stor_var_f_xfer_timed_out => {
461 order => ++$order,
462 test_class => [qw(bug forking)],
463 },
464
465 extlog_write_invalid_cmd_bug4313 => {
466 order => ++$order,
467 test_class => [qw(bug forking)],
468 },
469
470 extlog_xfer_port_nonxfer_issue912 => {
471 order => ++$order,
472 test_class => [qw(forking)],
473 },
474
475 extlog_xfer_port_success_issue912 => {
476 order => ++$order,
477 test_class => [qw(forking)],
478 },
479
480 extlog_sftp_xfer_port_issue912 => {
481 order => ++$order,
482 test_class => [qw(forking mod_sftp)],
483 },
484
485 extlog_xfer_speed_nonxfer_issue535 => {
486 order => ++$order,
487 test_class => [qw(forking)],
488 },
489
490 extlog_xfer_speed_download_issue535 => {
491 order => ++$order,
492 test_class => [qw(forking)],
493 },
494
495 extlog_xfer_speed_download_zero_len_issue535 => {
496 order => ++$order,
497 test_class => [qw(forking)],
498 },
499
500 extlog_xfer_speed_upload_issue535 => {
501 order => ++$order,
502 test_class => [qw(forking)],
503 },
504
505 extlog_xfer_speed_upload_zero_len_issue535 => {
506 order => ++$order,
507 test_class => [qw(forking)],
508 },
509
510 # XXX Need unit tests for all LogFormat variables
511 };
512
513 sub new {
514 return shift()->SUPER::new(@_);
515 }
516
517 sub list_tests {
518 return testsuite_get_runnable_tests($TESTS);
519 }
520
521 sub set_up {
522 my $self = shift;
523 $self->SUPER::set_up(@_);
524
525 # Make sure that mod_sftp does not complain about permissions on the hostkey
526 # files.
527
528 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
529 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
530
531 unless (chmod(0400, $rsa_host_key, $dsa_host_key)) {
532 die("Can't set perms on $rsa_host_key, $dsa_host_key: $!");
533 }
534 }
535
536 sub extlog_retr_default {
537 my $self = shift;
538 my $tmpdir = $self->{tmpdir};
539 my $setup = test_setup($tmpdir, 'extlog');
540
541 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
542 if (open(my $fh, "> $test_file")) {
543 print $fh "Hello, World!\n";
544 unless (close($fh)) {
545 die("Can't write $test_file: $!");
546 }
547
548 } else {
549 die("Can't open $test_file: $!");
550 }
551
552 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
553
554 my $config = {
555 PidFile => $setup->{pid_file},
556 ScoreboardFile => $setup->{scoreboard_file},
557 SystemLog => $setup->{log_file},
558 TraceLog => $setup->{log_file},
559 Trace => 'jot:20',
560
561 AuthUserFile => $setup->{auth_user_file},
562 AuthGroupFile => $setup->{auth_group_file},
563 AuthOrder => 'mod_auth_file.c',
564
565 ExtendedLog => "$ext_log ALL",
566
567 IfModules => {
568 'mod_delay.c' => {
569 DelayEngine => 'off',
570 },
571 },
572 };
573
574 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
575 $config);
576
577 # Open pipes, for use between the parent and child processes. Specifically,
578 # the child will indicate when it's done with its test by writing a message
579 # to the parent.
580 my ($rfh, $wfh);
581 unless (pipe($rfh, $wfh)) {
582 die("Can't open pipe: $!");
583 }
584
585 my $ex;
586
587 # Fork child
588 $self->handle_sigchld();
589 defined(my $pid = fork()) or die("Can't fork: $!");
590 if ($pid) {
591 eval {
592 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
593 $client->login($setup->{user}, $setup->{passwd});
594
595 my $conn = $client->retr_raw($test_file);
596 unless ($conn) {
597 die("Failed to RETR: " . $client->response_code() . " " .
598 $client->response_msg());
599 }
600
601 my $buf;
602 $conn->read($buf, 8192, 30);
603 eval { $conn->close() };
604
605 my $resp_code = $client->response_code();
606 my $resp_msg = $client->response_msg();
607 $self->assert_transfer_ok($resp_code, $resp_msg);
608
609 $client->quit();
610 };
611 if ($@) {
612 $ex = $@;
613 }
614
615 $wfh->print("done\n");
616 $wfh->flush();
617
618 } else {
619 eval { server_wait($setup->{config_file}, $rfh) };
620 if ($@) {
621 warn($@);
622 exit 1;
623 }
624
625 exit 0;
626 }
627
628 # Stop server
629 server_stop($setup->{pid_file});
630 $self->assert_child_ok($pid);
631
632 eval {
633 if (open(my $fh, "< $ext_log")) {
634 while (my $line = <$fh>) {
635 chomp($line);
636
637 if ($ENV{TEST_VERBOSE}) {
638 print STDERR "$line\n";
639 }
640
641 if ($line !~ /^127\.0\.0\.1 UNKNOWN/) {
642 die("Unexpected ExtendedLog first line: $line");
643 }
644
645 if ($line =~ /\"USER (\S+)\" (\d+) /) {
646 my $logged_user = $1;
647 my $resp_code = $2;
648
649 my $expected = $setup->{user};
650 $self->assert($expected eq $logged_user,
651 "Expected user '$expected', got '$logged_user'");
652
653 $expected = '331';
654 $self->assert($expected eq $resp_code,
655 "Expected response code '$expected', got '$resp_code'");
656
657 } elsif ($line =~ /\"PASS \(hidden\)\" (\d+) /) {
658 my $resp_code = $1;
659
660 my $expected = '230';
661 $self->assert($expected eq $resp_code,
662 "Expected response code '$expected', got '$resp_code'");
663
664 } elsif ($line =~ /\"PASV\" (\d+) /) {
665 my $resp_code = $1;
666
667 my $expected = '227';
668 $self->assert($expected eq $resp_code,
669 "Expected response code '$expected', got '$resp_code'");
670
671 } elsif ($line =~ /\"RETR (\S+)\" (\d+) (\d+)/) {
672 my $logged_path = $1;
673 my $resp_code = $2;
674 my $xfer_len = $3;
675
676 my $expected = $test_file;
677 $self->assert($expected eq $logged_path,
678 "Expected transferred path '$expected', got '$logged_path'");
679
680 $expected = '226';
681 $self->assert($expected eq $resp_code,
682 "Expected response code '$expected', got '$resp_code'");
683
684 $expected = 14;
685 $self->assert($expected == $xfer_len,
686 "Expected tranferred bytes $expected, got $xfer_len");
687
688 } elsif ($line =~ /\"QUIT\" (\d+) /) {
689 my $resp_code = $1;
690
691 my $expected = '221';
692 $self->assert($expected eq $resp_code,
693 "Expected response code '$expected', got '$resp_code'");
694
695 } else {
696 die("Unexpected ExtendedLog line: $line");
697 }
698 }
699
700 close($fh);
701
702 } else {
703 die("Can't read $ext_log: $!");
704 }
705 };
706 if ($@) {
707 $ex = $@;
708 }
709
710 test_cleanup($setup->{log_file}, $ex);
711 }
712
713 sub extlog_retr_bug3137 {
714 my $self = shift;
715 my $tmpdir = $self->{tmpdir};
716
717 my $config_file = "$tmpdir/extlog.conf";
718 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
719 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
720
721 my $log_file = test_get_logfile();
722
723 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
724 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
725
726 my $test_file = File::Spec->rel2abs($config_file);
727
728 my $user = 'proftpd';
729 my $passwd = 'test';
730 my $group = 'ftpd';
731 my $home_dir = File::Spec->rel2abs($tmpdir);
732 my $uid = 500;
733 my $gid = 500;
734
735 # Make sure that, if we're running as root, that the home directory has
736 # permissions/privs set for the account we create
737 if ($< == 0) {
738 unless (chmod(0755, $home_dir)) {
739 die("Can't set perms on $home_dir to 0755: $!");
740 }
741
742 unless (chown($uid, $gid, $home_dir)) {
743 die("Can't set owner of $home_dir to $uid/$gid: $!");
744 }
745 }
746
747 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
748 '/bin/bash');
749 auth_group_write($auth_group_file, $group, $gid, $user);
750
751 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
752
753 my $config = {
754 PidFile => $pid_file,
755 ScoreboardFile => $scoreboard_file,
756 SystemLog => $log_file,
757
758 AuthUserFile => $auth_user_file,
759 AuthGroupFile => $auth_group_file,
760 AuthOrder => 'mod_auth_file.c',
761
762 LogFormat => 'custom "%f"',
763 ExtendedLog => "$ext_log READ custom",
764
765 IfModules => {
766 'mod_delay.c' => {
767 DelayEngine => 'off',
768 },
769 },
770 };
771
772 my ($port, $config_user, $config_group) = config_write($config_file, $config);
773
774 # Open pipes, for use between the parent and child processes. Specifically,
775 # the child will indicate when it's done with its test by writing a message
776 # to the parent.
777 my ($rfh, $wfh);
778 unless (pipe($rfh, $wfh)) {
779 die("Can't open pipe: $!");
780 }
781
782 my $ex;
783
784 # Fork child
785 $self->handle_sigchld();
786 defined(my $pid = fork()) or die("Can't fork: $!");
787 if ($pid) {
788 eval {
789 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
790 $client->login($user, $passwd);
791
792 my $conn = $client->retr_raw($test_file);
793 unless ($conn) {
794 die("Failed to RETR: " . $client->response_code() . " " .
795 $client->response_msg());
796 }
797
798 my $buf;
799 $conn->read($buf, 8192, 30);
800 eval { $conn->close() };
801
802 my $resp_code = $client->response_code();
803 my $resp_msg = $client->response_msg();
804 $self->assert_transfer_ok($resp_code, $resp_msg);
805
806 $client->quit();
807 };
808
809 if ($@) {
810 $ex = $@;
811 }
812
813 $wfh->print("done\n");
814 $wfh->flush();
815
816 } else {
817 eval { server_wait($config_file, $rfh) };
818 if ($@) {
819 warn($@);
820 exit 1;
821 }
822
823 exit 0;
824 }
825
826 # Stop server
827 server_stop($pid_file);
828
829 $self->assert_child_ok($pid);
830
831 # Now, read in the ExtendedLog, and see whether the %f variable was
832 # properly written out. Bug#3137 occurred because the session.xfer.path
833 # variable was cleared out, as part of cleaning up the data connection,
834 # too early. The fix is to use session.notes, which also has that path
835 # information.
836 if (open(my $fh, "< $ext_log")) {
837 my $line = <$fh>;
838 chomp($line);
839
840 if ($ENV{TEST_VERBOSE}) {
841 print STDERR "$line\n";
842 }
843
844 close($fh);
845
846 if ($^O eq 'darwin') {
847 # MacOSX-specific hack
848 $test_file = '/private' . $test_file;
849 }
850
851 $self->assert($test_file eq $line,
852 test_msg("Expected '$test_file', got '$line'"));
853
854 } else {
855 die("Can't read $ext_log: $!");
856 }
857
858 if ($ex) {
859 test_append_logfile($log_file, $ex);
860 unlink($log_file);
861
862 die($ex);
863 }
864
865 unlink($log_file);
866 }
867
868 sub extlog_stor_bug3137 {
869 my $self = shift;
870 my $tmpdir = $self->{tmpdir};
871
872 my $config_file = "$tmpdir/extlog.conf";
873 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
874 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
875
876 my $log_file = test_get_logfile();
877
878 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
879 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
880
881 my $test_file = File::Spec->rel2abs("$tmpdir/foo");
882
883 my $user = 'proftpd';
884 my $passwd = 'test';
885 my $group = 'ftpd';
886 my $home_dir = File::Spec->rel2abs($tmpdir);
887 my $uid = 500;
888 my $gid = 500;
889
890 # Make sure that, if we're running as root, that the home directory has
891 # permissions/privs set for the account we create
892 if ($< == 0) {
893 unless (chmod(0755, $home_dir)) {
894 die("Can't set perms on $home_dir to 0755: $!");
895 }
896
897 unless (chown($uid, $gid, $home_dir)) {
898 die("Can't set owner of $home_dir to $uid/$gid: $!");
899 }
900 }
901
902 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
903 '/bin/bash');
904 auth_group_write($auth_group_file, $group, $gid, $user);
905
906 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
907
908 my $config = {
909 PidFile => $pid_file,
910 ScoreboardFile => $scoreboard_file,
911 SystemLog => $log_file,
912
913 AuthUserFile => $auth_user_file,
914 AuthGroupFile => $auth_group_file,
915 AuthOrder => 'mod_auth_file.c',
916
917 LogFormat => 'custom "%f"',
918 ExtendedLog => "$ext_log WRITE custom",
919
920 IfModules => {
921 'mod_delay.c' => {
922 DelayEngine => 'off',
923 },
924 },
925 };
926
927 my ($port, $config_user, $config_group) = config_write($config_file, $config);
928
929 # Open pipes, for use between the parent and child processes. Specifically,
930 # the child will indicate when it's done with its test by writing a message
931 # to the parent.
932 my ($rfh, $wfh);
933 unless (pipe($rfh, $wfh)) {
934 die("Can't open pipe: $!");
935 }
936
937 my $ex;
938
939 # Fork child
940 $self->handle_sigchld();
941 defined(my $pid = fork()) or die("Can't fork: $!");
942 if ($pid) {
943 eval {
944 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
945
946 $client->login($user, $passwd);
947
948 my $conn = $client->stor_raw('foo');
949 unless ($conn) {
950 die("Failed to STOR: " . $client->response_code() . " " .
951 $client->response_msg());
952 }
953
954 my $buf = "Foo!\n";
955 $conn->write($buf, length($buf));
956 eval { $conn->close() };
957 };
958
959 if ($@) {
960 $ex = $@;
961 }
962
963 $wfh->print("done\n");
964 $wfh->flush();
965
966 } else {
967 eval { server_wait($config_file, $rfh) };
968 if ($@) {
969 warn($@);
970 exit 1;
971 }
972
973 exit 0;
974 }
975
976 # Stop server
977 server_stop($pid_file);
978
979 $self->assert_child_ok($pid);
980
981 # Now, read in the ExtendedLog, and see whether the %f variable was
982 # properly written out. Bug#3137 occurred because the session.xfer.path
983 # variable was cleared out, as part of cleaning up the data connection,
984 # too early. The fix is to use session.notes, which also has that path
985 # information.
986 if (open(my $fh, "< $ext_log")) {
987 my $line = <$fh>;
988 chomp($line);
989 close($fh);
990
991 if ($^O eq 'darwin') {
992 # MacOSX-specific hack
993 $test_file = '/private' . $test_file;
994 }
995
996 $self->assert($test_file eq $line,
997 test_msg("Expected '$test_file', got '$line'"));
998
999 } else {
1000 die("Can't read $ext_log: $!");
1001 }
1002
1003 if ($ex) {
1004 test_append_logfile($log_file, $ex);
1005 unlink($log_file);
1006
1007 die($ex);
1008 }
1009
1010 unlink($log_file);
1011 }
1012
1013 sub extlog_site_cmds_bug3171 {
1014 my $self = shift;
1015 my $tmpdir = $self->{tmpdir};
1016
1017 my $config_file = "$tmpdir/extlog.conf";
1018 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
1019 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
1020
1021 my $log_file = test_get_logfile();
1022
1023 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
1024 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
1025
1026 my $user = 'proftpd';
1027 my $passwd = 'test';
1028 my $group = 'ftpd';
1029 my $home_dir = File::Spec->rel2abs($tmpdir);
1030 my $uid = 500;
1031 my $gid = 500;
1032
1033 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
1034 if (open(my $fh, "> $test_file")) {
1035 close($fh);
1036
1037 } else {
1038 die("Can't open $test_file: $!");
1039 }
1040
1041 # Make sure that, if we're running as root, that the home directory has
1042 # permissions/privs set for the account we create
1043 if ($< == 0) {
1044 unless (chmod(0755, $home_dir)) {
1045 die("Can't set perms on $home_dir to 0755: $!");
1046 }
1047
1048 unless (chown($uid, $gid, $home_dir, $test_file)) {
1049 die("Can't set owner of $home_dir, $test_file to $uid/$gid: $!");
1050 }
1051 }
1052
1053 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1054 '/bin/bash');
1055 auth_group_write($auth_group_file, $group, $gid, $user);
1056
1057 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
1058
1059 my $config = {
1060 PidFile => $pid_file,
1061 ScoreboardFile => $scoreboard_file,
1062 SystemLog => $log_file,
1063
1064 AuthUserFile => $auth_user_file,
1065 AuthGroupFile => $auth_group_file,
1066 AuthOrder => 'mod_auth_file.c',
1067
1068 LogFormat => 'custom "%m"',
1069 ExtendedLog => "$ext_log ALL custom",
1070
1071 IfModules => {
1072 'mod_delay.c' => {
1073 DelayEngine => 'off',
1074 },
1075 },
1076 };
1077
1078 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1079
1080 # Open pipes, for use between the parent and child processes. Specifically,
1081 # the child will indicate when it's done with its test by writing a message
1082 # to the parent.
1083 my ($rfh, $wfh);
1084 unless (pipe($rfh, $wfh)) {
1085 die("Can't open pipe: $!");
1086 }
1087
1088 my $ex;
1089
1090 # Fork child
1091 $self->handle_sigchld();
1092 defined(my $pid = fork()) or die("Can't fork: $!");
1093 if ($pid) {
1094 eval {
1095 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1096
1097 $client->login($user, $passwd);
1098
1099 # Send a SITE command; Bug#3171 occurred because %m was not expanded
1100 # properly for SITE commands.
1101
1102 my ($resp_code, $resp_msg);
1103
1104 ($resp_code, $resp_msg) = $client->site('CHMOD', '0644', 'test.txt');
1105
1106 my $expected;
1107
1108 $expected = 200;
1109 $self->assert($expected == $resp_code,
1110 test_msg("Expected $expected, got $resp_code"));
1111
1112 $expected = "SITE CHMOD command successful";
1113 $self->assert($expected eq $resp_msg,
1114 test_msg("Expected '$expected', got '$resp_msg'"));
1115 };
1116
1117 if ($@) {
1118 $ex = $@;
1119 }
1120
1121 $wfh->print("done\n");
1122 $wfh->flush();
1123
1124 } else {
1125 eval { server_wait($config_file, $rfh) };
1126 if ($@) {
1127 warn($@);
1128 exit 1;
1129 }
1130
1131 exit 0;
1132 }
1133
1134 # Stop server
1135 server_stop($pid_file);
1136
1137 $self->assert_child_ok($pid);
1138
1139 # Now, read in the ExtendedLog, and see whether the %m variable was
1140 # properly written out. Bug#3171 occurred because %m, for SITE commands,
1141 # only contains 'SITE', and not the actual command used.
1142
1143 if (open(my $fh, "< $ext_log")) {
1144 my $line;
1145
1146 while ($line = <$fh>) {
1147 chomp($line);
1148
1149 if ($line =~ /^SITE/) {
1150 last;
1151 }
1152 }
1153
1154 close($fh);
1155
1156 my $expected = 'SITE CHMOD';
1157 $self->assert($expected eq $line,
1158 test_msg("Expected '$expected', got '$line'"));
1159
1160 } else {
1161 die("Can't read $ext_log: $!");
1162 }
1163
1164 if ($ex) {
1165 test_append_logfile($log_file, $ex);
1166 unlink($log_file);
1167
1168 die($ex);
1169 }
1170
1171 unlink($log_file);
1172 }
1173
1174 sub extlog_mlsd_var_d_D_f_F_bug3950 {
1175 my $self = shift;
1176 my $tmpdir = $self->{tmpdir};
1177
1178 my $config_file = "$tmpdir/extlog.conf";
1179 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
1180 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
1181
1182 my $log_file = test_get_logfile();
1183
1184 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
1185 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
1186
1187 my $user = 'proftpd';
1188 my $passwd = 'test';
1189 my $group = 'ftpd';
1190 my $home_dir = File::Spec->rel2abs($tmpdir);
1191 my $uid = 500;
1192 my $gid = 500;
1193
1194 my $sub_dir = File::Spec->rel2abs("$home_dir/sub.d");
1195 mkpath($sub_dir);
1196
1197 # Make sure that, if we're running as root, that the home directory has
1198 # permissions/privs set for the account we create
1199 if ($< == 0) {
1200 unless (chmod(0755, $home_dir, $sub_dir)) {
1201 die("Can't set perms on $home_dir to 0755: $!");
1202 }
1203
1204 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1205 die("Can't set owner of $home_dir to $uid/$gid: $!");
1206 }
1207 }
1208
1209 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1210 '/bin/bash');
1211 auth_group_write($auth_group_file, $group, $gid, $user);
1212
1213 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
1214
1215 my $config = {
1216 PidFile => $pid_file,
1217 ScoreboardFile => $scoreboard_file,
1218 SystemLog => $log_file,
1219
1220 AuthUserFile => $auth_user_file,
1221 AuthGroupFile => $auth_group_file,
1222 AuthOrder => 'mod_auth_file.c',
1223
1224 LogFormat => 'custom "%d %D %f %F"',
1225 ExtendedLog => "$ext_log DIRS custom",
1226
1227 IfModules => {
1228 'mod_delay.c' => {
1229 DelayEngine => 'off',
1230 },
1231 },
1232 };
1233
1234 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1235
1236 # Open pipes, for use between the parent and child processes. Specifically,
1237 # the child will indicate when it's done with its test by writing a message
1238 # to the parent.
1239 my ($rfh, $wfh);
1240 unless (pipe($rfh, $wfh)) {
1241 die("Can't open pipe: $!");
1242 }
1243
1244 my $ex;
1245
1246 # Fork child
1247 $self->handle_sigchld();
1248 defined(my $pid = fork()) or die("Can't fork: $!");
1249 if ($pid) {
1250 eval {
1251 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1252 $client->login($user, $passwd);
1253
1254 my $conn = $client->mlsd_raw('sub.d');
1255 unless ($conn) {
1256 die("Failed to MLSD sub.d: " . $client->response_code() . " " .
1257 $client->response_msg());
1258 }
1259
1260 my $buf;
1261 $conn->read($buf, 8192, 30);
1262 eval { $conn->close() };
1263
1264 my $resp_code = $client->response_code();
1265 my $resp_msg = $client->response_msg();
1266 $self->assert_transfer_ok($resp_code, $resp_msg);
1267
1268 $client->quit();
1269 };
1270
1271 if ($@) {
1272 $ex = $@;
1273 }
1274
1275 $wfh->print("done\n");
1276 $wfh->flush();
1277
1278 } else {
1279 eval { server_wait($config_file, $rfh) };
1280 if ($@) {
1281 warn($@);
1282 exit 1;
1283 }
1284
1285 exit 0;
1286 }
1287
1288 # Stop server
1289 server_stop($pid_file);
1290
1291 $self->assert_child_ok($pid);
1292
1293 # Now, read in the ExtendedLog, and see whether the %f variable was
1294 # properly written out for MLSD. Specifically, %f should be '-',
1295 # since this is a directory transfer; %d should have the path in question.
1296 eval {
1297 if (open(my $fh, "< $ext_log")) {
1298 my $line = <$fh>;
1299 chomp($line);
1300 close($fh);
1301
1302 if ($line =~ /^(\S+) (\S+) (\S+) (\S+)$/) {
1303 my $dir_name = $1;
1304 my $dir_path = $2;
1305 my $file_name = $3;
1306 my $file_path = $4;
1307
1308 $self->assert('sub.d' eq $dir_name,
1309 test_msg("Expected 'sub.d', got '$dir_name'"));
1310
1311 if ($^O eq 'darwin') {
1312 # MacOSX-specific hack
1313 $sub_dir = '/private' . $sub_dir;
1314 }
1315
1316 $self->assert($sub_dir eq $dir_path,
1317 test_msg("Expected '$sub_dir', got '$dir_path'"));
1318
1319 $self->assert($sub_dir eq $file_name,
1320 test_msg("Expected '-', got '$file_name'"));
1321
1322 $self->assert('-' eq $file_path,
1323 test_msg("Expected '-', got '$file_path'"));
1324
1325 } else {
1326 die("Did not find expected ExtendedLog entries");
1327 }
1328
1329 } else {
1330 die("Can't read $ext_log: $!");
1331 }
1332 };
1333 if ($@) {
1334 $ex = $@;
1335 }
1336
1337 if ($ex) {
1338 test_append_logfile($log_file, $ex);
1339 unlink($log_file);
1340
1341 die($ex);
1342 }
1343
1344 unlink($log_file);
1345 }
1346
1347 sub extlog_sftp_mlsd_var_d_D_f_F_bug3950 {
1348 my $self = shift;
1349 my $tmpdir = $self->{tmpdir};
1350
1351 my $config_file = "$tmpdir/extlog.conf";
1352 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
1353 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
1354
1355 my $log_file = test_get_logfile();
1356
1357 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
1358 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
1359
1360 my $user = 'proftpd';
1361 my $passwd = 'test';
1362 my $group = 'ftpd';
1363 my $home_dir = File::Spec->rel2abs($tmpdir);
1364 my $uid = 500;
1365 my $gid = 500;
1366
1367 my $sub_dir = File::Spec->rel2abs("$home_dir/sub.d");
1368 mkpath($sub_dir);
1369
1370 # Make sure that, if we're running as root, that the home directory has
1371 # permissions/privs set for the account we create
1372 if ($< == 0) {
1373 unless (chmod(0755, $home_dir, $sub_dir)) {
1374 die("Can't set perms on $home_dir to 0755: $!");
1375 }
1376
1377 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
1378 die("Can't set owner of $home_dir to $uid/$gid: $!");
1379 }
1380 }
1381
1382 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1383 '/bin/bash');
1384 auth_group_write($auth_group_file, $group, $gid, $user);
1385
1386 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
1387 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
1388
1389 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
1390
1391 my $config = {
1392 PidFile => $pid_file,
1393 ScoreboardFile => $scoreboard_file,
1394 SystemLog => $log_file,
1395 TraceLog => $log_file,
1396 Trace => 'DEFAULT:10 ssh2:20 sftp:20',
1397
1398 AuthUserFile => $auth_user_file,
1399 AuthGroupFile => $auth_group_file,
1400 AuthOrder => 'mod_auth_file.c',
1401
1402 LogFormat => 'custom "%m: %d %D %f %F"',
1403 ExtendedLog => "$ext_log DIRS custom",
1404
1405 IfModules => {
1406 'mod_delay.c' => {
1407 DelayEngine => 'off',
1408 },
1409
1410 'mod_sftp.c' => [
1411 "SFTPEngine on",
1412 "SFTPLog $log_file",
1413 "SFTPHostKey $rsa_host_key",
1414 "SFTPHostKey $dsa_host_key",
1415 ],
1416 },
1417 };
1418
1419 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1420
1421 # Open pipes, for use between the parent and child processes. Specifically,
1422 # the child will indicate when it's done with its test by writing a message
1423 # to the parent.
1424 my ($rfh, $wfh);
1425 unless (pipe($rfh, $wfh)) {
1426 die("Can't open pipe: $!");
1427 }
1428
1429 require Net::SSH2;
1430
1431 my $ex;
1432
1433 # Ignore SIGPIPE
1434 local $SIG{PIPE} = sub { };
1435
1436 # Fork child
1437 $self->handle_sigchld();
1438 defined(my $pid = fork()) or die("Can't fork: $!");
1439 if ($pid) {
1440 eval {
1441 my $ssh2 = Net::SSH2->new();
1442 sleep(1);
1443
1444 unless ($ssh2->connect('127.0.0.1', $port)) {
1445 my ($err_code, $err_name, $err_str) = $ssh2->error();
1446 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
1447 }
1448
1449 unless ($ssh2->auth_password($user, $passwd)) {
1450 my ($err_code, $err_name, $err_str) = $ssh2->error();
1451 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
1452 }
1453
1454 my $sftp = $ssh2->sftp();
1455 unless ($sftp) {
1456 my ($err_code, $err_name, $err_str) = $ssh2->error();
1457 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
1458 }
1459
1460 my $dir = $sftp->opendir('sub.d');
1461 unless ($dir) {
1462 my ($err_code, $err_name) = $sftp->error();
1463 die("Can't open directory 'sub.d': [$err_name] ($err_code)");
1464 }
1465
1466 my $res = {};
1467
1468 my $file = $dir->read();
1469 while ($file) {
1470 $res->{$file->{name}} = $file;
1471 $file = $dir->read();
1472 }
1473
1474 # To issue the FXP_CLOSE, we have to explicitly destroy the dirhandle
1475 $dir = undef;
1476
1477 # To close the SFTP channel, we have to explicitly destroy the object
1478 $sftp = undef;
1479
1480 $ssh2->disconnect();
1481 };
1482
1483 if ($@) {
1484 $ex = $@;
1485 }
1486
1487 $wfh->print("done\n");
1488 $wfh->flush();
1489
1490 } else {
1491 eval { server_wait($config_file, $rfh) };
1492 if ($@) {
1493 warn($@);
1494 exit 1;
1495 }
1496
1497 exit 0;
1498 }
1499
1500 # Stop server
1501 server_stop($pid_file);
1502
1503 $self->assert_child_ok($pid);
1504
1505 # Now, read in the ExtendedLog, and see whether the %f variable was
1506 # properly written out for MLSD. Specifically, %f should be '-',
1507 # since this is a directory transfer; %d should have the path in question.
1508 eval {
1509 if (open(my $fh, "< $ext_log")) {
1510 my $line;
1511
1512 while ($line = <$fh>) {
1513 chomp($line);
1514
1515 # Look for the MLSD line
1516 if ($line =~ /^MLSD:/) {
1517 last;
1518 }
1519 }
1520
1521 close($fh);
1522
1523 if ($line =~ /^\S+: (\S+) (\S+) (\S+) (\S+)$/) {
1524 my $dir_name = $1;
1525 my $dir_path = $2;
1526 my $file_name = $3;
1527 my $file_path = $4;
1528
1529 $self->assert('sub.d' eq $dir_name,
1530 test_msg("Expected 'sub.d', got '$dir_name'"));
1531
1532 if ($^O eq 'darwin') {
1533 # MacOSX-specific hack
1534 $sub_dir = '/private' . $sub_dir;
1535 }
1536
1537 $self->assert($sub_dir eq $dir_path,
1538 test_msg("Expected '$sub_dir', got '$dir_path'"));
1539
1540 $self->assert($sub_dir eq $file_name,
1541 test_msg("Expected '$sub_dir', got '$file_name'"));
1542
1543 $self->assert('-' eq $file_path,
1544 test_msg("Expected '-', got '$file_path'"));
1545
1546 } else {
1547 die("Did not find expected ExtendedLog entries");
1548 }
1549
1550 } else {
1551 die("Can't read $ext_log: $!");
1552 }
1553 };
1554 if ($@) {
1555 $ex = $@;
1556 }
1557
1558 if ($ex) {
1559 test_append_logfile($log_file, $ex);
1560 unlink($log_file);
1561
1562 die($ex);
1563 }
1564
1565 unlink($log_file);
1566 }
1567
1568 sub extlog_mfmt_var_d_D_f_F {
1569 my $self = shift;
1570 my $tmpdir = $self->{tmpdir};
1571 my $setup = test_setup($tmpdir, 'extlog');
1572
1573 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
1574 if (open(my $fh, "> $test_file")) {
1575 close($fh);
1576
1577 # Make sure that, if we're running as root, that the test file has
1578 # permissions/privs set for the account we create
1579 if ($< == 0) {
1580 unless (chown($setup->{uid}, $setup->{gid}, $test_file)) {
1581 die("Can't set owner of $test_file to $setup->{uid}/$setup->{gid}: $!");
1582 }
1583 }
1584
1585 } else {
1586 die("Can't open $test_file: $!");
1587 }
1588
1589 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
1590
1591 my $config = {
1592 PidFile => $setup->{pid_file},
1593 ScoreboardFile => $setup->{scoreboard_file},
1594 SystemLog => $setup->{log_file},
1595
1596 AuthUserFile => $setup->{auth_user_file},
1597 AuthGroupFile => $setup->{auth_group_file},
1598 AuthOrder => 'mod_auth_file.c',
1599
1600 LogFormat => 'custom "%m: %d %D %f %F"',
1601 ExtendedLog => "$ext_log WRITE custom",
1602
1603 IfModules => {
1604 'mod_delay.c' => {
1605 DelayEngine => 'off',
1606 },
1607 },
1608 };
1609
1610 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1611 $config);
1612
1613 # Open pipes, for use between the parent and child processes. Specifically,
1614 # the child will indicate when it's done with its test by writing a message
1615 # to the parent.
1616 my ($rfh, $wfh);
1617 unless (pipe($rfh, $wfh)) {
1618 die("Can't open pipe: $!");
1619 }
1620
1621 my $ex;
1622
1623 # Fork child
1624 $self->handle_sigchld();
1625 defined(my $pid = fork()) or die("Can't fork: $!");
1626 if ($pid) {
1627 eval {
1628 # Allow for server startup
1629 sleep(1);
1630
1631 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1632 $client->login($setup->{user}, $setup->{passwd});
1633
1634 my ($resp_code, $resp_msg) = $client->mfmt('20020717210715', 'test.txt');
1635
1636 my $expected = 213;
1637 $self->assert($expected == $resp_code,
1638 test_msg("Expected response code $expected, got $resp_code"));
1639
1640 $expected = 'Modify=20020717210715; test.txt';
1641 $self->assert($expected eq $resp_msg,
1642 test_msg("Expected response message '$expected', got '$resp_msg'"));
1643
1644 $client->quit();
1645 };
1646 if ($@) {
1647 $ex = $@;
1648 }
1649
1650 $wfh->print("done\n");
1651 $wfh->flush();
1652
1653 } else {
1654 eval { server_wait($setup->{config_file}, $rfh) };
1655 if ($@) {
1656 warn($@);
1657 exit 1;
1658 }
1659
1660 exit 0;
1661 }
1662
1663 # Stop server
1664 server_stop($setup->{pid_file});
1665 $self->assert_child_ok($pid);
1666
1667 # Now, read in the ExtendedLog, and see whether the %f variable was
1668 # properly written out for MFMT.
1669 eval {
1670 if (open(my $fh, "< $ext_log")) {
1671 my $ok = 0;
1672
1673 while (my $line = <$fh>) {
1674 chomp($line);
1675
1676 # The %D variable should be empty here, since MFMT is not a directory
1677 # specific command.
1678 if ($line =~ /^(\S+): (\S+) (\S+) (\S+)$/) {
1679 my $cmd = $1;
1680 my $dir_path = $2;
1681 my $file_name = $3;
1682 my $xfer_path = $4;
1683
1684 next unless $cmd eq 'MFMT';
1685
1686 my $home_dir = $setup->{home_dir};
1687
1688 if ($^O eq 'darwin') {
1689 # MacOSX-specific hack
1690 $home_dir = '/private' . $home_dir;
1691 }
1692
1693 $self->assert($home_dir eq $dir_path,
1694 test_msg("Expected directory path (%d) '$home_dir', got '$dir_path'"));
1695
1696 if ($^O eq 'darwin') {
1697 # MacOSX-specific hack
1698 $test_file = '/private' . $test_file;
1699 }
1700
1701 $self->assert($test_file eq $file_name,
1702 test_msg("Expected filename (%f) '$test_file', got '$file_name'"));
1703
1704 $self->assert('-' eq $xfer_path,
1705 test_msg("Expected transfer path (%F) '-', got '$xfer_path'"));
1706
1707 $ok = 1;
1708 last;
1709 }
1710 }
1711
1712 close($fh);
1713
1714 $self->assert($ok, test_msg("Did not find expected ExtendedLog entries"));
1715
1716 } else {
1717 die("Can't read $ext_log: $!");
1718 }
1719 };
1720 if ($@) {
1721 $ex = $@;
1722 }
1723
1724 test_cleanup($setup->{log_file}, $ex);
1725 }
1726
1727 sub extlog_protocol {
1728 my $self = shift;
1729 my $tmpdir = $self->{tmpdir};
1730
1731 my $config_file = "$tmpdir/extlog.conf";
1732 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
1733 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
1734
1735 my $log_file = test_get_logfile();
1736
1737 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
1738 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
1739
1740 my $user = 'proftpd';
1741 my $passwd = 'test';
1742 my $group = 'ftpd';
1743 my $home_dir = File::Spec->rel2abs($tmpdir);
1744 my $uid = 500;
1745 my $gid = 500;
1746
1747 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
1748 if (open(my $fh, "> $test_file")) {
1749 close($fh);
1750
1751 } else {
1752 die("Can't open $test_file: $!");
1753 }
1754
1755 # Make sure that, if we're running as root, that the home directory has
1756 # permissions/privs set for the account we create
1757 if ($< == 0) {
1758 unless (chmod(0755, $home_dir)) {
1759 die("Can't set perms on $home_dir to 0755: $!");
1760 }
1761
1762 unless (chown($uid, $gid, $home_dir, $test_file)) {
1763 die("Can't set owner of $home_dir, $test_file to $uid/$gid: $!");
1764 }
1765 }
1766
1767 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1768 '/bin/bash');
1769 auth_group_write($auth_group_file, $group, $gid, $user);
1770
1771 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
1772
1773 my $config = {
1774 PidFile => $pid_file,
1775 ScoreboardFile => $scoreboard_file,
1776 SystemLog => $log_file,
1777
1778 AuthUserFile => $auth_user_file,
1779 AuthGroupFile => $auth_group_file,
1780 AuthOrder => 'mod_auth_file.c',
1781
1782 LogFormat => 'custom "%{protocol}"',
1783 ExtendedLog => "$ext_log ALL custom",
1784
1785 IfModules => {
1786 'mod_delay.c' => {
1787 DelayEngine => 'off',
1788 },
1789 },
1790 };
1791
1792 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1793
1794 # Open pipes, for use between the parent and child processes. Specifically,
1795 # the child will indicate when it's done with its test by writing a message
1796 # to the parent.
1797 my ($rfh, $wfh);
1798 unless (pipe($rfh, $wfh)) {
1799 die("Can't open pipe: $!");
1800 }
1801
1802 my $ex;
1803
1804 # Fork child
1805 $self->handle_sigchld();
1806 defined(my $pid = fork()) or die("Can't fork: $!");
1807 if ($pid) {
1808 eval {
1809 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1810
1811 $client->login($user, $passwd);
1812
1813 # Send a SITE command; Bug#3171 occurred because %m was not expanded
1814 # properly for SITE commands.
1815
1816 my ($resp_code, $resp_msg);
1817
1818 ($resp_code, $resp_msg) = $client->site('CHMOD', '0644', 'test.txt');
1819
1820 my $expected;
1821
1822 $expected = 200;
1823 $self->assert($expected == $resp_code,
1824 test_msg("Expected $expected, got $resp_code"));
1825
1826 $expected = "SITE CHMOD command successful";
1827 $self->assert($expected eq $resp_msg,
1828 test_msg("Expected '$expected', got '$resp_msg'"));
1829 };
1830
1831 if ($@) {
1832 $ex = $@;
1833 }
1834
1835 $wfh->print("done\n");
1836 $wfh->flush();
1837
1838 } else {
1839 eval { server_wait($config_file, $rfh) };
1840 if ($@) {
1841 warn($@);
1842 exit 1;
1843 }
1844
1845 exit 0;
1846 }
1847
1848 # Stop server
1849 server_stop($pid_file);
1850
1851 $self->assert_child_ok($pid);
1852
1853 if (open(my $fh, "< $ext_log")) {
1854 my $line;
1855
1856 while ($line = <$fh>) {
1857 chomp($line);
1858
1859 if ($line =~ /^ftp/) {
1860 last;
1861 }
1862 }
1863
1864 close($fh);
1865
1866 my $expected = 'ftp';
1867 $self->assert($expected eq $line,
1868 test_msg("Expected '$expected', got '$line'"));
1869
1870 } else {
1871 die("Can't read $ext_log: $!");
1872 }
1873
1874 if ($ex) {
1875 test_append_logfile($log_file, $ex);
1876 unlink($log_file);
1877
1878 die($ex);
1879 }
1880
1881 unlink($log_file);
1882 }
1883
1884 sub extlog_protocol_version_quoted_bug3383 {
1885 my $self = shift;
1886 my $tmpdir = $self->{tmpdir};
1887 my $setup = test_setup($tmpdir, 'extlog');
1888
1889 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
1890 if (open(my $fh, "> $test_file")) {
1891 close($fh);
1892
1893 } else {
1894 die("Can't open $test_file: $!");
1895 }
1896
1897 # Make sure that, if we're running as root, that the test file has
1898 # permissions/privs set for the account we create
1899 if ($< == 0) {
1900 unless (chown($setup->{uid}, $setup->{gid}, $test_file)) {
1901 die("Can't set owner of $test_file to $setup->{uid}/$setup->{gid}: $!");
1902 }
1903 }
1904
1905 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
1906
1907 my $config = {
1908 PidFile => $setup->{pid_file},
1909 ScoreboardFile => $setup->{scoreboard_file},
1910 SystemLog => $setup->{log_file},
1911 TraceLog => $setup->{log_file},
1912 Trace => 'jot:20',
1913
1914 AuthUserFile => $setup->{auth_user_file},
1915 AuthGroupFile => $setup->{auth_group_file},
1916 AuthOrder => 'mod_auth_file.c',
1917
1918 LogFormat => 'custom "\"%{protocol}\" \"%{version}\""',
1919 ExtendedLog => "$ext_log ALL custom",
1920
1921 IfModules => {
1922 'mod_delay.c' => {
1923 DelayEngine => 'off',
1924 },
1925 },
1926 };
1927
1928 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1929 $config);
1930
1931 # Open pipes, for use between the parent and child processes. Specifically,
1932 # the child will indicate when it's done with its test by writing a message
1933 # to the parent.
1934 my ($rfh, $wfh);
1935 unless (pipe($rfh, $wfh)) {
1936 die("Can't open pipe: $!");
1937 }
1938
1939 my $ex;
1940
1941 # Fork child
1942 $self->handle_sigchld();
1943 defined(my $pid = fork()) or die("Can't fork: $!");
1944 if ($pid) {
1945 eval {
1946 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
1947 $client->login($setup->{user}, $setup->{passwd});
1948
1949 # Send a SITE command; Bug#3171 occurred because %m was not expanded
1950 # properly for SITE commands.
1951
1952 my ($resp_code, $resp_msg) = $client->site('CHMOD', '0644', 'test.txt');
1953
1954 my $expected = 200;
1955 $self->assert($expected == $resp_code,
1956 "Expected response code $expected, got $resp_code");
1957
1958 $expected = "SITE CHMOD command successful";
1959 $self->assert($expected eq $resp_msg,
1960 "Expected response message '$expected', got '$resp_msg'");
1961 };
1962 if ($@) {
1963 $ex = $@;
1964 }
1965
1966 $wfh->print("done\n");
1967 $wfh->flush();
1968
1969 } else {
1970 eval { server_wait($setup->{config_file}, $rfh) };
1971 if ($@) {
1972 warn($@);
1973 exit 1;
1974 }
1975
1976 exit 0;
1977 }
1978
1979 # Stop server
1980 server_stop($setup->{pid_file});
1981 $self->assert_child_ok($pid);
1982
1983 my $server_version = feature_get_version();
1984
1985 eval {
1986 if (open(my $fh, "< $ext_log")) {
1987 my $line;
1988
1989 while ($line = <$fh>) {
1990 chomp($line);
1991
1992 if ($ENV{TEST_VERBOSE}) {
1993 print STDERR "# ExtendedLog: $line\n";
1994 }
1995
1996 if ($line =~ /^"ftp" "(\S+)"/) {
1997 last;
1998 }
1999 }
2000
2001 close($fh);
2002
2003 my $expected = "\"ftp\" \"$server_version\"";
2004 $self->assert($expected eq $line, "Expected '$expected', got '$line'");
2005
2006 } else {
2007 die("Can't read $ext_log: $!");
2008 }
2009 };
2010 if ($@) {
2011 $ex = $@;
2012 }
2013
2014 test_cleanup($setup->{log_file}, $ex);
2015 }
2016
2017 sub extlog_remote_port {
2018 my $self = shift;
2019 my $tmpdir = $self->{tmpdir};
2020 my $setup = test_setup($tmpdir, 'extlog');
2021
2022 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
2023
2024 my $config = {
2025 PidFile => $setup->{pid_file},
2026 ScoreboardFile => $setup->{scoreboard_file},
2027 SystemLog => $setup->{log_file},
2028
2029 AuthUserFile => $setup->{auth_user_file},
2030 AuthGroupFile => $setup->{auth_group_file},
2031 AuthOrder => 'mod_auth_file.c',
2032
2033 LogFormat => 'custom "%m: %{remote-port}"',
2034 ExtendedLog => "$ext_log ALL custom",
2035
2036 IfModules => {
2037 'mod_delay.c' => {
2038 DelayEngine => 'off',
2039 },
2040 },
2041 };
2042
2043 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2044 $config);
2045
2046 # Open pipes, for use between the parent and child processes. Specifically,
2047 # the child will indicate when it's done with its test by writing a message
2048 # to the parent.
2049 my ($rfh, $wfh);
2050 unless (pipe($rfh, $wfh)) {
2051 die("Can't open pipe: $!");
2052 }
2053
2054 my $ex;
2055
2056 # Fork child
2057 $self->handle_sigchld();
2058 defined(my $pid = fork()) or die("Can't fork: $!");
2059 if ($pid) {
2060 eval {
2061 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
2062 $client->login($setup->{user}, $setup->{passwd});
2063 $client->quit();
2064 };
2065
2066 if ($@) {
2067 $ex = $@;
2068 }
2069
2070 $wfh->print("done\n");
2071 $wfh->flush();
2072
2073 } else {
2074 eval { server_wait($setup->{config_file}, $rfh) };
2075 if ($@) {
2076 warn($@);
2077 exit 1;
2078 }
2079
2080 exit 0;
2081 }
2082
2083 # Stop server
2084 server_stop($setup->{pid_file});
2085 $self->assert_child_ok($pid);
2086
2087 eval {
2088 if (open(my $fh, "< $ext_log")) {
2089 my $ok = 0;
2090 my $line;
2091
2092 while ($line = <$fh>) {
2093 chomp($line);
2094
2095 if ($ENV{TEST_VERBOSE}) {
2096 print STDERR "# line: $line\n";
2097 }
2098
2099 if ($line =~ /^USER: \d+$/) {
2100 $ok = 1;
2101 }
2102 }
2103
2104 close($fh);
2105
2106 $self->assert($ok,
2107 test_msg("Did not see expected remote port in ExtendedLog"));
2108
2109 } else {
2110 die("Can't read $ext_log: $!");
2111 }
2112 };
2113 if ($@) {
2114 $ex = $@;
2115 }
2116
2117 test_cleanup($setup->{log_file}, $ex);
2118 }
2119
2120 sub extlog_rename_from {
2121 my $self = shift;
2122 my $tmpdir = $self->{tmpdir};
2123
2124 my $config_file = "$tmpdir/extlog.conf";
2125 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
2126 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
2127
2128 my $log_file = test_get_logfile();
2129
2130 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
2131 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
2132
2133 my $test_file = File::Spec->rel2abs($config_file);
2134
2135 my $user = 'proftpd';
2136 my $passwd = 'test';
2137 my $group = 'ftpd';
2138 my $home_dir = File::Spec->rel2abs($tmpdir);
2139 my $uid = 500;
2140 my $gid = 500;
2141
2142 # Make sure that, if we're running as root, that the home directory has
2143 # permissions/privs set for the account we create
2144 if ($< == 0) {
2145 unless (chmod(0755, $home_dir)) {
2146 die("Can't set perms on $home_dir to 0755: $!");
2147 }
2148
2149 unless (chown($uid, $gid, $home_dir)) {
2150 die("Can't set owner of $home_dir to $uid/$gid: $!");
2151 }
2152 }
2153
2154 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2155 '/bin/bash');
2156 auth_group_write($auth_group_file, $group, $gid, $user);
2157
2158 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
2159
2160 my $src_file = File::Spec->rel2abs("$tmpdir/test.txt");
2161 if (open(my $fh, "> $src_file")) {
2162 close($fh);
2163
2164 } else {
2165 die("Can't open $src_file: $!");
2166 }
2167
2168 my $dst_file = File::Spec->rel2abs("$tmpdir/foo.txt");
2169
2170 my $config = {
2171 PidFile => $pid_file,
2172 ScoreboardFile => $scoreboard_file,
2173 SystemLog => $log_file,
2174
2175 AuthUserFile => $auth_user_file,
2176 AuthGroupFile => $auth_group_file,
2177 AuthOrder => 'mod_auth_file.c',
2178
2179 LogFormat => 'custom "%m: %w %f"',
2180 ExtendedLog => "$ext_log WRITE custom",
2181
2182 IfModules => {
2183 'mod_delay.c' => {
2184 DelayEngine => 'off',
2185 },
2186 },
2187 };
2188
2189 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2190
2191 # Open pipes, for use between the parent and child processes. Specifically,
2192 # the child will indicate when it's done with its test by writing a message
2193 # to the parent.
2194 my ($rfh, $wfh);
2195 unless (pipe($rfh, $wfh)) {
2196 die("Can't open pipe: $!");
2197 }
2198
2199 my $ex;
2200
2201 # Fork child
2202 $self->handle_sigchld();
2203 defined(my $pid = fork()) or die("Can't fork: $!");
2204 if ($pid) {
2205 eval {
2206 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2207 $client->login($user, $passwd);
2208
2209 $client->rnfr('test.txt');
2210 my ($resp_code, $resp_msg) = $client->rnto('foo.txt');
2211
2212 my $expected;
2213
2214 $expected = 250;
2215 $self->assert($expected == $resp_code,
2216 test_msg("Expected response code $expected, got $resp_code"));
2217
2218 $expected = "Rename successful";
2219 $self->assert($expected eq $resp_msg,
2220 test_msg("Expected response message '$expected', got '$resp_msg'"));
2221
2222 $client->quit();
2223 };
2224
2225 if ($@) {
2226 $ex = $@;
2227 }
2228
2229 $wfh->print("done\n");
2230 $wfh->flush();
2231
2232 } else {
2233 eval { server_wait($config_file, $rfh) };
2234 if ($@) {
2235 warn($@);
2236 exit 1;
2237 }
2238
2239 exit 0;
2240 }
2241
2242 # Stop server
2243 server_stop($pid_file);
2244
2245 $self->assert_child_ok($pid);
2246
2247 # Now, read in the ExtendedLog, and see whether the %f and %w variables were
2248 # properly written out.
2249 if (open(my $fh, "< $ext_log")) {
2250 my $line = <$fh>;
2251 chomp($line);
2252
2253 if ($ENV{TEST_VERBOSE}) {
2254 print STDERR "logged: $line\n";
2255 }
2256
2257 if ($^O eq 'darwin') {
2258 # MacOSX-specific hack
2259 $src_file = '/private' . $src_file;
2260 $dst_file = '/private' . $dst_file;
2261 }
2262
2263 my $expected = "RNFR: - $src_file";
2264 $self->assert($expected eq $line,
2265 test_msg("Expected '$expected', got '$line'"));
2266
2267 $line = <$fh>;
2268 chomp($line);
2269
2270 if ($ENV{TEST_VERBOSE}) {
2271 print STDERR "logged: $line\n";
2272 }
2273
2274 $expected = "RNTO: $src_file $dst_file";
2275 $self->assert($expected eq $line,
2276 test_msg("Expected '$expected', got '$line'"));
2277
2278 close($fh);
2279
2280 } else {
2281 die("Can't read $ext_log: $!");
2282 }
2283
2284 if ($ex) {
2285 test_append_logfile($log_file, $ex);
2286 unlink($log_file);
2287
2288 die($ex);
2289 }
2290
2291 unlink($log_file);
2292 }
2293
2294 sub extlog_sftp_rename_from {
2295 my $self = shift;
2296 my $tmpdir = $self->{tmpdir};
2297
2298 my $config_file = "$tmpdir/extlog.conf";
2299 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
2300 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
2301
2302 my $log_file = test_get_logfile();
2303
2304 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
2305 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
2306
2307 my $user = 'proftpd';
2308 my $passwd = 'test';
2309 my $group = 'ftpd';
2310 my $home_dir = File::Spec->rel2abs($tmpdir);
2311 my $uid = 500;
2312 my $gid = 500;
2313
2314 # Make sure that, if we're running as root, that the home directory has
2315 # permissions/privs set for the account we create
2316 if ($< == 0) {
2317 unless (chmod(0755, $home_dir)) {
2318 die("Can't set perms on $home_dir to 0755: $!");
2319 }
2320
2321 unless (chown($uid, $gid, $home_dir)) {
2322 die("Can't set owner of $home_dir to $uid/$gid: $!");
2323 }
2324 }
2325
2326 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2327 '/bin/bash');
2328 auth_group_write($auth_group_file, $group, $gid, $user);
2329
2330 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
2331 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
2332
2333 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
2334
2335 my $src_file = File::Spec->rel2abs("$tmpdir/test.txt");
2336 if (open(my $fh, "> $src_file")) {
2337 close($fh);
2338
2339 } else {
2340 die("Can't open $src_file: $!");
2341 }
2342
2343 my $dst_file = File::Spec->rel2abs("$tmpdir/foo.txt");
2344
2345 my $config = {
2346 PidFile => $pid_file,
2347 ScoreboardFile => $scoreboard_file,
2348 SystemLog => $log_file,
2349 TraceLog => $log_file,
2350 Trace => 'DEFAULT:10 ssh2:20 sftp:20',
2351
2352 AuthUserFile => $auth_user_file,
2353 AuthGroupFile => $auth_group_file,
2354 AuthOrder => 'mod_auth_file.c',
2355
2356 LogFormat => 'custom "%w %f"',
2357 ExtendedLog => "$ext_log WRITE custom",
2358
2359 IfModules => {
2360 'mod_delay.c' => {
2361 DelayEngine => 'off',
2362 },
2363
2364 'mod_sftp.c' => [
2365 "SFTPEngine on",
2366 "SFTPLog $log_file",
2367 "SFTPHostKey $rsa_host_key",
2368 "SFTPHostKey $dsa_host_key",
2369 ],
2370 },
2371 };
2372
2373 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2374
2375 # Open pipes, for use between the parent and child processes. Specifically,
2376 # the child will indicate when it's done with its test by writing a message
2377 # to the parent.
2378 my ($rfh, $wfh);
2379 unless (pipe($rfh, $wfh)) {
2380 die("Can't open pipe: $!");
2381 }
2382
2383 require Net::SSH2;
2384
2385 my $ex;
2386
2387 # Ignore SIGPIPE
2388 local $SIG{PIPE} = sub { };
2389
2390 # Fork child
2391 $self->handle_sigchld();
2392 defined(my $pid = fork()) or die("Can't fork: $!");
2393 if ($pid) {
2394 eval {
2395 my $ssh2 = Net::SSH2->new();
2396 sleep(1);
2397
2398 unless ($ssh2->connect('127.0.0.1', $port)) {
2399 my ($err_code, $err_name, $err_str) = $ssh2->error();
2400 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
2401 }
2402
2403 unless ($ssh2->auth_password($user, $passwd)) {
2404 my ($err_code, $err_name, $err_str) = $ssh2->error();
2405 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
2406 }
2407
2408 my $sftp = $ssh2->sftp();
2409 unless ($sftp) {
2410 my ($err_code, $err_name, $err_str) = $ssh2->error();
2411 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
2412 }
2413
2414 my $res = $sftp->rename('test.txt', 'foo.txt');
2415 unless ($res) {
2416 my ($err_code, $err_name) = $sftp->error();
2417 die("Can't rename test.txt to foo.txt: [$err_name] ($err_code)");
2418 }
2419
2420 $sftp = undef;
2421 $ssh2->disconnect();
2422
2423 if (-f $src_file) {
2424 die("$src_file file exists unexpectedly");
2425 }
2426
2427 unless (-f $dst_file) {
2428 die("$dst_file file does not exist as expected");
2429 }
2430 };
2431
2432 if ($@) {
2433 $ex = $@;
2434 }
2435
2436 $wfh->print("done\n");
2437 $wfh->flush();
2438
2439 } else {
2440 eval { server_wait($config_file, $rfh) };
2441 if ($@) {
2442 warn($@);
2443 exit 1;
2444 }
2445
2446 exit 0;
2447 }
2448
2449 # Stop server
2450 server_stop($pid_file);
2451
2452 $self->assert_child_ok($pid);
2453
2454 if ($ex) {
2455 test_append_logfile($log_file, $ex);
2456 unlink($log_file);
2457
2458 die($ex);
2459 }
2460
2461 # Now, read in the ExtendedLog, and see whether the %f and %w variables were
2462 # properly written out.
2463 eval {
2464 if (open(my $fh, "< $ext_log")) {
2465 my $line = <$fh>;
2466 chomp($line);
2467
2468 if ($ENV{TEST_VERBOSE}) {
2469 print STDERR "# $line\n";
2470 }
2471
2472 if ($^O eq 'darwin') {
2473 # MacOSX-specific hack
2474 $src_file = '/private' . $src_file;
2475 $dst_file = '/private' . $dst_file;
2476 }
2477
2478 my $expected = "- $src_file";
2479 $self->assert($expected eq $line,
2480 test_msg("Expected '$expected', got '$line'"));
2481
2482 $line = <$fh>;
2483 chomp($line);
2484
2485 if ($ENV{TEST_VERBOSE}) {
2486 print STDERR "# $line\n";
2487 }
2488
2489 $expected = "$src_file $dst_file";
2490 $self->assert($expected eq $line,
2491 test_msg("Expected '$expected', got '$line'"));
2492
2493 close($fh);
2494
2495 } else {
2496 die("Can't read $ext_log: $!");
2497 }
2498 };
2499 if ($@) {
2500 $ex = $@;
2501 }
2502
2503 if ($ex) {
2504 test_append_logfile($log_file, $ex);
2505 unlink($log_file);
2506
2507 die($ex);
2508 }
2509
2510 unlink($log_file);
2511 }
2512
2513 sub extlog_ext_sftp_posix_rename_bug3949 {
2514 my $self = shift;
2515 my $tmpdir = $self->{tmpdir};
2516
2517 my $config_file = "$tmpdir/extlog.conf";
2518 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
2519 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
2520
2521 my $log_file = test_get_logfile();
2522
2523 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
2524 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
2525
2526 my $user = 'proftpd';
2527 my $passwd = 'test';
2528 my $group = 'ftpd';
2529 my $home_dir = File::Spec->rel2abs($tmpdir);
2530 my $uid = 500;
2531 my $gid = 500;
2532
2533 # Make sure that, if we're running as root, that the home directory has
2534 # permissions/privs set for the account we create
2535 if ($< == 0) {
2536 unless (chmod(0755, $home_dir)) {
2537 die("Can't set perms on $home_dir to 0755: $!");
2538 }
2539
2540 unless (chown($uid, $gid, $home_dir)) {
2541 die("Can't set owner of $home_dir to $uid/$gid: $!");
2542 }
2543 }
2544
2545 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2546 '/bin/bash');
2547 auth_group_write($auth_group_file, $group, $gid, $user);
2548
2549 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
2550 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
2551
2552 my $rsa_priv_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/test_rsa_key');
2553 my $rsa_pub_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/test_rsa_key.pub');
2554 my $rsa_rfc4716_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/authorized_rsa_keys');
2555
2556 my $authorized_keys = File::Spec->rel2abs("$tmpdir/.authorized_keys");
2557 unless (copy($rsa_rfc4716_key, $authorized_keys)) {
2558 die("Can't copy $rsa_rfc4716_key to $authorized_keys: $!");
2559 }
2560
2561 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
2562
2563 my $src_file = File::Spec->rel2abs("$tmpdir/test.txt");
2564 if (open(my $fh, "> $src_file")) {
2565 close($fh);
2566
2567 } else {
2568 die("Can't open $src_file: $!");
2569 }
2570
2571 my $dst_file = File::Spec->rel2abs("$tmpdir/foo.txt");
2572
2573 my $batch_file = File::Spec->rel2abs("$tmpdir/sftp-batch.txt");
2574 if (open(my $fh, "> $batch_file")) {
2575 print $fh "rename test.txt foo.txt\n";
2576
2577 unless (close($fh)) {
2578 die("Can't write $batch_file: $!");
2579 }
2580
2581 } else {
2582 die("Can't open $batch_file: $!");
2583 }
2584
2585 my $config = {
2586 PidFile => $pid_file,
2587 ScoreboardFile => $scoreboard_file,
2588 SystemLog => $log_file,
2589 TraceLog => $log_file,
2590 Trace => 'DEFAULT:10 ssh2:20 sftp:20',
2591
2592 AuthUserFile => $auth_user_file,
2593 AuthGroupFile => $auth_group_file,
2594 AuthOrder => 'mod_auth_file.c',
2595
2596 LogFormat => 'custom "%w %f"',
2597 ExtendedLog => "$ext_log WRITE custom",
2598
2599 IfModules => {
2600 'mod_delay.c' => {
2601 DelayEngine => 'off',
2602 },
2603
2604 'mod_sftp.c' => [
2605 "SFTPEngine on",
2606 "SFTPLog $log_file",
2607 "SFTPHostKey $rsa_host_key",
2608 "SFTPHostKey $dsa_host_key",
2609 "SFTPAuthorizedUserKeys file:~/.authorized_keys",
2610 ],
2611 },
2612 };
2613
2614 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2615
2616 # Open pipes, for use between the parent and child processes. Specifically,
2617 # the child will indicate when it's done with its test by writing a message
2618 # to the parent.
2619 my ($rfh, $wfh);
2620 unless (pipe($rfh, $wfh)) {
2621 die("Can't open pipe: $!");
2622 }
2623
2624 require Net::SSH2;
2625
2626 my $ex;
2627
2628 # Ignore SIGPIPE
2629 local $SIG{PIPE} = sub { };
2630
2631 # Fork child
2632 $self->handle_sigchld();
2633 defined(my $pid = fork()) or die("Can't fork: $!");
2634 if ($pid) {
2635 eval {
2636 sleep(1);
2637
2638 my @cmd = (
2639 'sftp',
2640 '-oBatchMode=yes',
2641 '-oCheckHostIP=no',
2642 '-oCompression=yes',
2643 "-oPort=$port",
2644 "-oIdentityFile=$rsa_priv_key",
2645 '-oPubkeyAuthentication=yes',
2646 '-oStrictHostKeyChecking=no',
2647 '-vvv',
2648 '-b',
2649 "$batch_file",
2650 "$user\@127.0.0.1",
2651 );
2652
2653 my $sftp_rh = IO::Handle->new();
2654 my $sftp_wh = IO::Handle->new();
2655 my $sftp_eh = IO::Handle->new();
2656
2657 $sftp_wh->autoflush(1);
2658
2659 local $SIG{CHLD} = 'DEFAULT';
2660
2661 # Make sure that the perms on the priv key are what OpenSSH wants
2662 unless (chmod(0400, $rsa_priv_key)) {
2663 die("Can't set perms on $rsa_priv_key to 0400: $!");
2664 }
2665
2666 if ($ENV{TEST_VERBOSE}) {
2667 print STDERR "Executing: ", join(' ', @cmd), "\n";
2668 }
2669
2670 my $sftp_pid = open3($sftp_wh, $sftp_rh, $sftp_eh, @cmd);
2671 waitpid($sftp_pid, 0);
2672 my $exit_status = $?;
2673
2674 # Restore the perms on the priv key
2675 unless (chmod(0644, $rsa_priv_key)) {
2676 die("Can't set perms on $rsa_priv_key to 0644: $!");
2677 }
2678
2679 my ($res, $errstr);
2680 if ($exit_status >> 8 == 0) {
2681 $errstr = join('', <$sftp_eh>);
2682 $res = 0;
2683
2684 } else {
2685 if ($ENV{TEST_VERBOSE}) {
2686 $errstr = join('', <$sftp_eh>);
2687 print STDERR "Stderr: $errstr\n";
2688 }
2689
2690 $res = 1;
2691 }
2692
2693 unless ($res == 0) {
2694 die("Can't rename $src_file to $dst_file: $errstr");
2695 }
2696
2697 if (-f $src_file) {
2698 die("$src_file file exists unexpectedly");
2699 }
2700
2701 unless (-f $dst_file) {
2702 die("$dst_file file does not exist as expected");
2703 }
2704 };
2705
2706 if ($@) {
2707 $ex = $@;
2708 }
2709
2710 $wfh->print("done\n");
2711 $wfh->flush();
2712
2713 } else {
2714 eval { server_wait($config_file, $rfh) };
2715 if ($@) {
2716 warn($@);
2717 exit 1;
2718 }
2719
2720 exit 0;
2721 }
2722
2723 # Stop server
2724 server_stop($pid_file);
2725
2726 $self->assert_child_ok($pid);
2727
2728 if ($ex) {
2729 test_append_logfile($log_file, $ex);
2730 unlink($log_file);
2731
2732 die($ex);
2733 }
2734
2735 # Now, read in the ExtendedLog, and see whether the %f and %w variables were
2736 # properly written out.
2737 eval {
2738 if (open(my $fh, "< $ext_log")) {
2739 my $line = <$fh>;
2740 chomp($line);
2741
2742 if ($^O eq 'darwin') {
2743 # MacOSX-specific hack
2744 $src_file = '/private' . $src_file;
2745 $dst_file = '/private' . $dst_file;
2746 }
2747
2748 my $expected = "- $src_file";
2749 $self->assert($expected eq $line,
2750 test_msg("Expected '$expected', got '$line'"));
2751
2752 $line = <$fh>;
2753 chomp($line);
2754
2755 $expected = "$src_file $dst_file";
2756 $self->assert($expected eq $line,
2757 test_msg("Expected '$expected', got '$line'"));
2758
2759 close($fh);
2760
2761 } else {
2762 die("Can't read $ext_log: $!");
2763 }
2764 };
2765 if ($@) {
2766 $ex = $@;
2767 }
2768
2769 if ($ex) {
2770 test_append_logfile($log_file, $ex);
2771 unlink($log_file);
2772
2773 die($ex);
2774 }
2775
2776 unlink($log_file);
2777 }
2778
2779 sub extlog_orig_user {
2780 my $self = shift;
2781 my $tmpdir = $self->{tmpdir};
2782
2783 my $config_file = "$tmpdir/extlog.conf";
2784 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
2785 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
2786
2787 my $log_file = test_get_logfile();
2788
2789 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
2790 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
2791
2792 my $test_file = File::Spec->rel2abs($config_file);
2793
2794 my $user = 'proftpd';
2795 my $passwd = 'test';
2796 my $group = 'ftpd';
2797 my $home_dir = File::Spec->rel2abs($tmpdir);
2798 my $uid = 500;
2799 my $gid = 500;
2800
2801 # Make sure that, if we're running as root, that the home directory has
2802 # permissions/privs set for the account we create
2803 if ($< == 0) {
2804 unless (chmod(0755, $home_dir)) {
2805 die("Can't set perms on $home_dir to 0755: $!");
2806 }
2807
2808 unless (chown($uid, $gid, $home_dir)) {
2809 die("Can't set owner of $home_dir to $uid/$gid: $!");
2810 }
2811 }
2812
2813 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2814 '/bin/bash');
2815 auth_group_write($auth_group_file, $group, $gid, $user);
2816
2817 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
2818
2819 my $config = {
2820 PidFile => $pid_file,
2821 ScoreboardFile => $scoreboard_file,
2822 SystemLog => $log_file,
2823
2824 AuthUserFile => $auth_user_file,
2825 AuthGroupFile => $auth_group_file,
2826 AuthOrder => 'mod_auth_file.c',
2827
2828 LogFormat => 'custom "%U"',
2829 ExtendedLog => "$ext_log AUTH custom",
2830
2831 IfModules => {
2832 'mod_delay.c' => {
2833 DelayEngine => 'off',
2834 },
2835 },
2836 };
2837
2838 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2839
2840 # Open pipes, for use between the parent and child processes. Specifically,
2841 # the child will indicate when it's done with its test by writing a message
2842 # to the parent.
2843 my ($rfh, $wfh);
2844 unless (pipe($rfh, $wfh)) {
2845 die("Can't open pipe: $!");
2846 }
2847
2848 my $ex;
2849
2850 # Fork child
2851 $self->handle_sigchld();
2852 defined(my $pid = fork()) or die("Can't fork: $!");
2853 if ($pid) {
2854 eval {
2855 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
2856
2857 $client->login($user, $passwd);
2858 $client->quit();
2859 };
2860
2861 if ($@) {
2862 $ex = $@;
2863 }
2864
2865 $wfh->print("done\n");
2866 $wfh->flush();
2867
2868 } else {
2869 eval { server_wait($config_file, $rfh) };
2870 if ($@) {
2871 warn($@);
2872 exit 1;
2873 }
2874
2875 exit 0;
2876 }
2877
2878 # Stop server
2879 server_stop($pid_file);
2880
2881 $self->assert_child_ok($pid);
2882
2883 # Now, read in the ExtendedLog, and see whether the %f and %w variables were
2884 # properly written out.
2885 if (open(my $fh, "< $ext_log")) {
2886 my $line = <$fh>;
2887 chomp($line);
2888
2889 my $expected = $user;
2890 $self->assert($expected eq $line,
2891 test_msg("Expected '$expected', got '$line'"));
2892
2893 $line = <$fh>;
2894 chomp($line);
2895
2896 $expected = $user;
2897 $self->assert($expected eq $line,
2898 test_msg("Expected '$expected', got '$line'"));
2899
2900 close($fh);
2901
2902 } else {
2903 die("Can't read $ext_log: $!");
2904 }
2905
2906 if ($ex) {
2907 test_append_logfile($log_file, $ex);
2908 unlink($log_file);
2909
2910 die($ex);
2911 }
2912
2913 unlink($log_file);
2914 }
2915
2916 sub extlog_bug1908 {
2917 my $self = shift;
2918 my $tmpdir = $self->{tmpdir};
2919
2920 my $config_file = "$tmpdir/extlog.conf";
2921 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
2922 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
2923
2924 my $log_file = test_get_logfile();
2925
2926 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
2927 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
2928
2929 my $user = 'proftpd';
2930 my $passwd = 'test';
2931 my $group = 'ftpd';
2932 my $home_dir = File::Spec->rel2abs($tmpdir);
2933 my $uid = 500;
2934 my $gid = 500;
2935
2936 # Make sure that, if we're running as root, that the home directory has
2937 # permissions/privs set for the account we create
2938 if ($< == 0) {
2939 unless (chmod(0755, $home_dir)) {
2940 die("Can't set perms on $home_dir to 0755: $!");
2941 }
2942
2943 unless (chown($uid, $gid, $home_dir)) {
2944 die("Can't set owner of $home_dir to $uid/$gid: $!");
2945 }
2946 }
2947
2948 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
2949 if (open(my $fh, "> $test_file")) {
2950 print $fh "Hello, World!\n";
2951
2952 unless (close($fh)) {
2953 die("Can't write $test_file: $!");
2954 }
2955
2956 } else {
2957 die("Can't open $test_file: $!");
2958 }
2959
2960 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
2961 '/bin/bash');
2962 auth_group_write($auth_group_file, $group, $gid, $user);
2963
2964 my $ext_log = File::Spec->rel2abs("$tmpdir/ext.log");
2965 my $anon_ext_log = File::Spec->rel2abs("$tmpdir/anon-ext.log");
2966
2967 my $config = {
2968 PidFile => $pid_file,
2969 ScoreboardFile => $scoreboard_file,
2970 SystemLog => $log_file,
2971
2972 AuthUserFile => $auth_user_file,
2973 AuthGroupFile => $auth_group_file,
2974 AuthOrder => 'mod_auth_file.c',
2975
2976 ExtendedLog => "$ext_log READ",
2977
2978 Anonymous => {
2979 $home_dir => [
2980 "User $user",
2981 "Group $group",
2982 "ExtendedLog $anon_ext_log READ",
2983 "ExtendedLog $ext_log NONE",
2984 ],
2985 },
2986
2987 IfModules => {
2988 'mod_delay.c' => {
2989 DelayEngine => 'off',
2990 },
2991 },
2992 };
2993
2994 my ($port, $config_user, $config_group) = config_write($config_file, $config);
2995
2996 # Open pipes, for use between the parent and child processes. Specifically,
2997 # the child will indicate when it's done with its test by writing a message
2998 # to the parent.
2999 my ($rfh, $wfh);
3000 unless (pipe($rfh, $wfh)) {
3001 die("Can't open pipe: $!");
3002 }
3003
3004 my $ex;
3005
3006 # Fork child
3007 $self->handle_sigchld();
3008 defined(my $pid = fork()) or die("Can't fork: $!");
3009 if ($pid) {
3010 eval {
3011 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3012 $client->login($user, $passwd);
3013
3014 my $conn = $client->retr_raw('test.txt');
3015 unless ($conn) {
3016 die("Failed to RETR: " . $client->response_code() . " " .
3017 $client->response_msg());
3018 }
3019
3020 my $buf;
3021 $conn->read($buf, 8192, 30);
3022 eval { $conn->close() };
3023
3024 $client->quit();
3025 };
3026
3027 if ($@) {
3028 $ex = $@;
3029 }
3030
3031 $wfh->print("done\n");
3032 $wfh->flush();
3033
3034 } else {
3035 eval { server_wait($config_file, $rfh) };
3036 if ($@) {
3037 warn($@);
3038 exit 1;
3039 }
3040
3041 exit 0;
3042 }
3043
3044 # Stop server
3045 server_stop($pid_file);
3046
3047 $self->assert_child_ok($pid);
3048
3049 if ($ex) {
3050 test_append_logfile($log_file, $ex);
3051 unlink($log_file);
3052
3053 die($ex);
3054 }
3055
3056 # Now, read in the ExtendedLogs. Ideally we would NOT see anything in
3057 # the ExtendedLog defined in the "server config" context, and WOULD see
3058 # lines in the ExtendedLog defined in the <Anonymous> context.
3059
3060 my $extlog_nlines = 0;
3061 if (open(my $fh, "< $ext_log")) {
3062 while (my $line = <$fh>) {
3063 $extlog_nlines++;
3064 }
3065 close($fh);
3066
3067 } else {
3068 die("Can't read $ext_log: $!");
3069 }
3070
3071 my $anon_extlog_nlines = 0;
3072 if (open(my $fh, "< $anon_ext_log")) {
3073 while (my $line = <$fh>) {
3074 $anon_extlog_nlines++;
3075 }
3076 close($fh);
3077
3078 } else {
3079 die("Can't read $anon_ext_log: $!");
3080 }
3081
3082 my $expected = 0;
3083 $self->assert($expected == $extlog_nlines,
3084 test_msg("Expected $expected, got $extlog_nlines"));
3085
3086 $expected = 1;
3087 $self->assert($expected == $anon_extlog_nlines,
3088 test_msg("Expected $expected, got $anon_extlog_nlines"));
3089
3090 unlink($log_file);
3091 }
3092
3093 sub extlog_file_modified_bug3457 {
3094 my $self = shift;
3095 my $tmpdir = $self->{tmpdir};
3096 my $setup = test_setup($tmpdir, 'extlog');
3097
3098 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
3099 if (open(my $fh, "> $test_file")) {
3100 print $fh "Hello, world!\n";
3101 unless (close($fh)) {
3102 die("Can't write $test_file: $!");
3103 }
3104
3105 # Make sure that, if we're running as root, that the test file has
3106 # permissions/privs set for the account we create
3107 if ($< == 0) {
3108 unless (chown($setup->{uid}, $setup->{gid}, $test_file)) {
3109 die("Can't set owner of $test_file to $setup->{uid}/$setup->{gid}: $!");
3110 }
3111 }
3112
3113 } else {
3114 die("Can't open $test_file: $!");
3115 }
3116
3117 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
3118
3119 my $config = {
3120 PidFile => $setup->{pid_file},
3121 ScoreboardFile => $setup->{scoreboard_file},
3122 SystemLog => $setup->{log_file},
3123
3124 AuthUserFile => $setup->{auth_user_file},
3125 AuthGroupFile => $setup->{auth_group_file},
3126 AuthOrder => 'mod_auth_file.c',
3127
3128 AllowOverwrite => 'on',
3129 LogFormat => 'custom "%{file-modified}"',
3130 ExtendedLog => "$ext_log WRITE custom",
3131
3132 IfModules => {
3133 'mod_delay.c' => {
3134 DelayEngine => 'off',
3135 },
3136 },
3137 };
3138
3139 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3140 $config);
3141
3142 # Open pipes, for use between the parent and child processes. Specifically,
3143 # the child will indicate when it's done with its test by writing a message
3144 # to the parent.
3145 my ($rfh, $wfh);
3146 unless (pipe($rfh, $wfh)) {
3147 die("Can't open pipe: $!");
3148 }
3149
3150 my $ex;
3151
3152 # Fork child
3153 $self->handle_sigchld();
3154 defined(my $pid = fork()) or die("Can't fork: $!");
3155 if ($pid) {
3156 eval {
3157 # Allow for server startup
3158 sleep(1);
3159
3160 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3161 $client->login($setup->{user}, $setup->{passwd});
3162
3163 my $conn = $client->stor_raw('test.txt');
3164 unless ($conn) {
3165 die("Failed to STOR test.txt: " . $client->response_code() . " " .
3166 $client->response_msg());
3167 }
3168
3169 eval { $conn->close() };
3170 $client->quit();
3171 };
3172
3173 if ($@) {
3174 $ex = $@;
3175 }
3176
3177 $wfh->print("done\n");
3178 $wfh->flush();
3179
3180 } else {
3181 eval { server_wait($setup->{config_file}, $rfh) };
3182 if ($@) {
3183 warn($@);
3184 exit 1;
3185 }
3186
3187 exit 0;
3188 }
3189
3190 # Stop server
3191 server_stop($setup->{pid_file});
3192 $self->assert_child_ok($pid);
3193
3194 # Now, read in the ExtendedLog, and see whether the %{file-modified}
3195 # variable was properly written out.
3196 eval {
3197 if (open(my $fh, "< $ext_log")) {
3198 my $line = <$fh>;
3199 chomp($line);
3200 close($fh);
3201
3202 my $expected = 'true';
3203 $self->assert($expected eq $line,
3204 test_msg("Expected '$expected', got '$line'"));
3205
3206 } else {
3207 die("Can't read $ext_log: $!");
3208 }
3209 };
3210 if ($@) {
3211 $ex = $@;
3212 }
3213
3214 test_cleanup($setup->{log_file}, $ex);
3215 }
3216
3217 sub extlog_dele_bug3469 {
3218 my $self = shift;
3219 my $tmpdir = $self->{tmpdir};
3220
3221 my $config_file = "$tmpdir/extlog.conf";
3222 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
3223 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
3224
3225 my $log_file = test_get_logfile();
3226
3227 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
3228 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
3229
3230 my $user = 'proftpd';
3231 my $passwd = 'test';
3232 my $group = 'ftpd';
3233 my $home_dir = File::Spec->rel2abs($tmpdir);
3234 my $uid = 500;
3235 my $gid = 500;
3236
3237 # Make sure that, if we're running as root, that the home directory has
3238 # permissions/privs set for the account we create
3239 if ($< == 0) {
3240 unless (chmod(0755, $home_dir)) {
3241 die("Can't set perms on $home_dir to 0755: $!");
3242 }
3243
3244 unless (chown($uid, $gid, $home_dir)) {
3245 die("Can't set owner of $home_dir to $uid/$gid: $!");
3246 }
3247 }
3248
3249 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3250 '/bin/bash');
3251 auth_group_write($auth_group_file, $group, $gid, $user);
3252
3253 my $test_file = File::Spec->rel2abs("$tmpdir/~test.txt");
3254 if (open(my $fh, "> $test_file")) {
3255 print $fh "Hello, World!\n";
3256
3257 unless (close($fh)) {
3258 die("Can't write $test_file: $!");
3259 }
3260
3261 } else {
3262 die("Can't open $test_file: $!");
3263 }
3264
3265 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
3266
3267 my $config = {
3268 PidFile => $pid_file,
3269 ScoreboardFile => $scoreboard_file,
3270 SystemLog => $log_file,
3271
3272 AuthUserFile => $auth_user_file,
3273 AuthGroupFile => $auth_group_file,
3274 AuthOrder => 'mod_auth_file.c',
3275
3276 LogFormat => 'custom "%m %f"',
3277 ExtendedLog => "$ext_log ALL custom",
3278
3279 IfModules => {
3280 'mod_delay.c' => {
3281 DelayEngine => 'off',
3282 },
3283 },
3284 };
3285
3286 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3287
3288 # Open pipes, for use between the parent and child processes. Specifically,
3289 # the child will indicate when it's done with its test by writing a message
3290 # to the parent.
3291 my ($rfh, $wfh);
3292 unless (pipe($rfh, $wfh)) {
3293 die("Can't open pipe: $!");
3294 }
3295
3296 my $ex;
3297
3298 # Fork child
3299 $self->handle_sigchld();
3300 defined(my $pid = fork()) or die("Can't fork: $!");
3301 if ($pid) {
3302 eval {
3303 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3304 $client->login($user, $passwd);
3305 $client->dele('~test.txt');
3306 };
3307
3308 if ($@) {
3309 $ex = $@;
3310 }
3311
3312 $wfh->print("done\n");
3313 $wfh->flush();
3314
3315 } else {
3316 eval { server_wait($config_file, $rfh) };
3317 if ($@) {
3318 warn($@);
3319 exit 1;
3320 }
3321
3322 exit 0;
3323 }
3324
3325 # Stop server
3326 server_stop($pid_file);
3327
3328 $self->assert_child_ok($pid);
3329
3330 # Now, read in the ExtendedLog, and see whether the %f variable was
3331 # properly written out. Bug#3469 occurred because the session.xfer.path
3332 # variable was cleared out, as part of cleaning up the data connection,
3333 # too early. The fix is to use session.notes, which also has that path
3334 # information.
3335 if (open(my $fh, "< $ext_log")) {
3336 if ($^O eq 'darwin') {
3337 # MacOSX-specific hack
3338 $test_file = '/private' . $test_file;
3339 }
3340
3341 while (my $line = <$fh>) {
3342 chomp($line);
3343
3344 if ($ENV{TEST_VERBOSE}) {
3345 print STDERR "$line\n";
3346 }
3347
3348 # We're only interested in the DELE log line
3349 unless ($line =~ /^DELE (.*)$/i) {
3350 next;
3351 }
3352
3353 my $name = $1;
3354 my $expected = $test_file;
3355 $self->assert($expected eq $name,
3356 test_msg("Expected '$expected', got '$name'"));
3357 }
3358
3359 close($fh);
3360
3361 } else {
3362 die("Can't read $ext_log: $!");
3363 }
3364
3365 if ($ex) {
3366 test_append_logfile($log_file, $ex);
3367 unlink($log_file);
3368
3369 die($ex);
3370 }
3371
3372 unlink($log_file);
3373 }
3374
3375 sub extlog_client_dir_bug3395 {
3376 my $self = shift;
3377 my $tmpdir = $self->{tmpdir};
3378
3379 my $config_file = "$tmpdir/extlog.conf";
3380 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
3381 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
3382
3383 my $log_file = test_get_logfile();
3384
3385 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
3386 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
3387
3388 my $test_file = File::Spec->rel2abs($config_file);
3389
3390 my $user = 'proftpd';
3391 my $passwd = 'test';
3392 my $group = 'ftpd';
3393 my $home_dir = File::Spec->rel2abs($tmpdir);
3394 my $uid = 500;
3395 my $gid = 500;
3396
3397 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
3398 mkpath($sub_dir);
3399
3400 # Make sure that, if we're running as root, that the home directory has
3401 # permissions/privs set for the account we create
3402 if ($< == 0) {
3403 unless (chmod(0755, $home_dir, $sub_dir)) {
3404 die("Can't set perms on $home_dir to 0755: $!");
3405 }
3406
3407 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
3408 die("Can't set owner of $home_dir to $uid/$gid: $!");
3409 }
3410 }
3411
3412 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3413 '/bin/bash');
3414 auth_group_write($auth_group_file, $group, $gid, $user);
3415
3416 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
3417
3418 my $config = {
3419 PidFile => $pid_file,
3420 ScoreboardFile => $scoreboard_file,
3421 SystemLog => $log_file,
3422
3423 AuthUserFile => $auth_user_file,
3424 AuthGroupFile => $auth_group_file,
3425 AuthOrder => 'mod_auth_file.c',
3426
3427 LogFormat => 'custom "%m %d"',
3428 ExtendedLog => "$ext_log ALL custom",
3429
3430 IfModules => {
3431 'mod_delay.c' => {
3432 DelayEngine => 'off',
3433 },
3434 },
3435 };
3436
3437 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3438
3439 # Open pipes, for use between the parent and child processes. Specifically,
3440 # the child will indicate when it's done with its test by writing a message
3441 # to the parent.
3442 my ($rfh, $wfh);
3443 unless (pipe($rfh, $wfh)) {
3444 die("Can't open pipe: $!");
3445 }
3446
3447 my $ex;
3448
3449 # Fork child
3450 $self->handle_sigchld();
3451 defined(my $pid = fork()) or die("Can't fork: $!");
3452 if ($pid) {
3453 eval {
3454 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3455 $client->login($user, $passwd);
3456 $client->cwd('foo');
3457 $client->quit();
3458 };
3459
3460 if ($@) {
3461 $ex = $@;
3462 }
3463
3464 $wfh->print("done\n");
3465 $wfh->flush();
3466
3467 } else {
3468 eval { server_wait($config_file, $rfh) };
3469 if ($@) {
3470 warn($@);
3471 exit 1;
3472 }
3473
3474 exit 0;
3475 }
3476
3477 # Stop server
3478 server_stop($pid_file);
3479
3480 $self->assert_child_ok($pid);
3481
3482 # Now, read in the ExtendedLog, and see whether the %d variable was
3483 # properly written out. Bug#3395 says that even for QUIT, the %d
3484 # variable should be valid.
3485 if (open(my $fh, "< $ext_log")) {
3486 if ($^O eq 'darwin') {
3487 # MacOSX-specific hack
3488 $sub_dir = '/private' . $sub_dir;
3489 }
3490
3491 while (my $line = <$fh>) {
3492 chomp($line);
3493
3494 # We're only interested in the QUIT log line
3495 unless ($line =~ /^QUIT (.*)$/i) {
3496 next;
3497 }
3498
3499 my $name = $1;
3500 my $expected = $sub_dir;
3501 $self->assert($expected eq $name,
3502 test_msg("Expected '$expected', got '$name'"));
3503 }
3504
3505 close($fh);
3506
3507 } else {
3508 die("Can't read $ext_log: $!");
3509 }
3510
3511 if ($ex) {
3512 test_append_logfile($log_file, $ex);
3513 unlink($log_file);
3514
3515 die($ex);
3516 }
3517
3518 unlink($log_file);
3519 }
3520
3521 sub extlog_client_dir_chroot_bug3395 {
3522 my $self = shift;
3523 my $tmpdir = $self->{tmpdir};
3524
3525 my $config_file = "$tmpdir/extlog.conf";
3526 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
3527 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
3528
3529 my $log_file = test_get_logfile();
3530
3531 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
3532 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
3533
3534 my $test_file = File::Spec->rel2abs($config_file);
3535
3536 my $user = 'proftpd';
3537 my $passwd = 'test';
3538 my $group = 'ftpd';
3539 my $home_dir = File::Spec->rel2abs($tmpdir);
3540 my $uid = 500;
3541 my $gid = 500;
3542
3543 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
3544 mkpath($sub_dir);
3545
3546 # Make sure that, if we're running as root, that the home directory has
3547 # permissions/privs set for the account we create
3548 if ($< == 0) {
3549 unless (chmod(0755, $home_dir, $sub_dir)) {
3550 die("Can't set perms on $home_dir to 0755: $!");
3551 }
3552
3553 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
3554 die("Can't set owner of $home_dir to $uid/$gid: $!");
3555 }
3556 }
3557
3558 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3559 '/bin/bash');
3560 auth_group_write($auth_group_file, $group, $gid, $user);
3561
3562 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
3563
3564 my $config = {
3565 PidFile => $pid_file,
3566 ScoreboardFile => $scoreboard_file,
3567 SystemLog => $log_file,
3568
3569 AuthUserFile => $auth_user_file,
3570 AuthGroupFile => $auth_group_file,
3571 AuthOrder => 'mod_auth_file.c',
3572
3573 DefaultRoot => '~',
3574 LogFormat => 'custom "%m %d"',
3575 ExtendedLog => "$ext_log ALL custom",
3576
3577 IfModules => {
3578 'mod_delay.c' => {
3579 DelayEngine => 'off',
3580 },
3581 },
3582 };
3583
3584 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3585
3586 # Open pipes, for use between the parent and child processes. Specifically,
3587 # the child will indicate when it's done with its test by writing a message
3588 # to the parent.
3589 my ($rfh, $wfh);
3590 unless (pipe($rfh, $wfh)) {
3591 die("Can't open pipe: $!");
3592 }
3593
3594 my $ex;
3595
3596 # Fork child
3597 $self->handle_sigchld();
3598 defined(my $pid = fork()) or die("Can't fork: $!");
3599 if ($pid) {
3600 eval {
3601 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3602 $client->login($user, $passwd);
3603 $client->cwd('foo');
3604 $client->quit();
3605 };
3606
3607 if ($@) {
3608 $ex = $@;
3609 }
3610
3611 $wfh->print("done\n");
3612 $wfh->flush();
3613
3614 } else {
3615 eval { server_wait($config_file, $rfh) };
3616 if ($@) {
3617 warn($@);
3618 exit 1;
3619 }
3620
3621 exit 0;
3622 }
3623
3624 # Stop server
3625 server_stop($pid_file);
3626
3627 $self->assert_child_ok($pid);
3628
3629 # Now, read in the ExtendedLog, and see whether the %d variable was
3630 # properly written out. Bug#3395 says that even for QUIT, the %d
3631 # variable should be valid.
3632 if (open(my $fh, "< $ext_log")) {
3633 while (my $line = <$fh>) {
3634 chomp($line);
3635
3636 # We're only interested in the QUIT log line
3637 unless ($line =~ /^QUIT (.*)$/i) {
3638 next;
3639 }
3640
3641 my $name = $1;
3642 my $expected = '/foo';
3643 $self->assert($expected eq $name,
3644 test_msg("Expected '$expected', got '$name'"));
3645 }
3646
3647 close($fh);
3648
3649 } else {
3650 die("Can't read $ext_log: $!");
3651 }
3652
3653 if ($ex) {
3654 test_append_logfile($log_file, $ex);
3655 unlink($log_file);
3656
3657 die($ex);
3658 }
3659
3660 unlink($log_file);
3661 }
3662
3663 sub extlog_device_full {
3664 my $self = shift;
3665 my $tmpdir = $self->{tmpdir};
3666
3667 my $config_file = "$tmpdir/extlog.conf";
3668 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
3669 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
3670
3671 my $log_file = test_get_logfile();
3672
3673 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
3674 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
3675
3676 my $test_file = File::Spec->rel2abs($config_file);
3677
3678 my $user = 'proftpd';
3679 my $passwd = 'test';
3680 my $group = 'ftpd';
3681 my $home_dir = File::Spec->rel2abs($tmpdir);
3682 my $uid = 500;
3683 my $gid = 500;
3684
3685 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
3686 mkpath($sub_dir);
3687
3688 # Make sure that, if we're running as root, that the home directory has
3689 # permissions/privs set for the account we create
3690 if ($< == 0) {
3691 unless (chmod(0755, $home_dir, $sub_dir)) {
3692 die("Can't set perms on $home_dir to 0755: $!");
3693 }
3694
3695 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
3696 die("Can't set owner of $home_dir to $uid/$gid: $!");
3697 }
3698 }
3699
3700 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3701 '/bin/bash');
3702 auth_group_write($auth_group_file, $group, $gid, $user);
3703
3704 # XXX The /dev/full device only exists on Linux, as far as I know
3705 my $ext_log = File::Spec->rel2abs('/dev/full');
3706
3707 my $config = {
3708 PidFile => $pid_file,
3709 ScoreboardFile => $scoreboard_file,
3710 SystemLog => $log_file,
3711
3712 AuthUserFile => $auth_user_file,
3713 AuthGroupFile => $auth_group_file,
3714 AuthOrder => 'mod_auth_file.c',
3715
3716 LogFormat => 'custom "%m %d"',
3717 ExtendedLog => "$ext_log ALL custom",
3718
3719 IfModules => {
3720 'mod_delay.c' => {
3721 DelayEngine => 'off',
3722 },
3723 },
3724 };
3725
3726 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3727
3728 # Open pipes, for use between the parent and child processes. Specifically,
3729 # the child will indicate when it's done with its test by writing a message
3730 # to the parent.
3731 my ($rfh, $wfh);
3732 unless (pipe($rfh, $wfh)) {
3733 die("Can't open pipe: $!");
3734 }
3735
3736 my $ex;
3737
3738 # Fork child
3739 $self->handle_sigchld();
3740 defined(my $pid = fork()) or die("Can't fork: $!");
3741 if ($pid) {
3742 eval {
3743 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3744 $client->login($user, $passwd);
3745 $client->cwd('foo');
3746 $client->quit();
3747 };
3748
3749 if ($@) {
3750 $ex = $@;
3751 }
3752
3753 $wfh->print("done\n");
3754 $wfh->flush();
3755
3756 } else {
3757 eval { server_wait($config_file, $rfh) };
3758 if ($@) {
3759 warn($@);
3760 exit 1;
3761 }
3762
3763 exit 0;
3764 }
3765
3766 # Stop server
3767 server_stop($pid_file);
3768
3769 $self->assert_child_ok($pid);
3770
3771 if ($ex) {
3772 test_append_logfile($log_file, $ex);
3773 unlink($log_file);
3774
3775 die($ex);
3776 }
3777
3778 unlink($log_file);
3779 }
3780
3781 sub extlog_uid_bug3390 {
3782 my $self = shift;
3783 my $tmpdir = $self->{tmpdir};
3784
3785 my $config_file = "$tmpdir/extlog.conf";
3786 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
3787 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
3788
3789 my $log_file = test_get_logfile();
3790
3791 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
3792 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
3793
3794 my $test_file = File::Spec->rel2abs($config_file);
3795
3796 my $user = 'proftpd';
3797 my $passwd = 'test';
3798 my $group = 'ftpd';
3799 my $home_dir = File::Spec->rel2abs($tmpdir);
3800 my $uid = 500;
3801 my $gid = 500;
3802
3803 # Make sure that, if we're running as root, that the home directory has
3804 # permissions/privs set for the account we create
3805 if ($< == 0) {
3806 unless (chmod(0755, $home_dir)) {
3807 die("Can't set perms on $home_dir to 0755: $!");
3808 }
3809
3810 unless (chown($uid, $gid, $home_dir)) {
3811 die("Can't set owner of $home_dir to $uid/$gid: $!");
3812 }
3813 }
3814
3815 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3816 '/bin/bash');
3817 auth_group_write($auth_group_file, $group, $gid, $user);
3818
3819 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
3820
3821 my $config = {
3822 PidFile => $pid_file,
3823 ScoreboardFile => $scoreboard_file,
3824 SystemLog => $log_file,
3825
3826 AuthUserFile => $auth_user_file,
3827 AuthGroupFile => $auth_group_file,
3828 AuthOrder => 'mod_auth_file.c',
3829
3830 LogFormat => 'custom "%{uid}"',
3831 ExtendedLog => "$ext_log READ custom",
3832
3833 IfModules => {
3834 'mod_delay.c' => {
3835 DelayEngine => 'off',
3836 },
3837 },
3838 };
3839
3840 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3841
3842 # Open pipes, for use between the parent and child processes. Specifically,
3843 # the child will indicate when it's done with its test by writing a message
3844 # to the parent.
3845 my ($rfh, $wfh);
3846 unless (pipe($rfh, $wfh)) {
3847 die("Can't open pipe: $!");
3848 }
3849
3850 my $ex;
3851
3852 # Fork child
3853 $self->handle_sigchld();
3854 defined(my $pid = fork()) or die("Can't fork: $!");
3855 if ($pid) {
3856 eval {
3857 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3858
3859 $client->login($user, $passwd);
3860
3861 my $conn = $client->retr_raw($test_file);
3862 unless ($conn) {
3863 die("Failed to RETR: " . $client->response_code() . " " .
3864 $client->response_msg());
3865 }
3866
3867 my $buf;
3868 $conn->read($buf, 8192, 30);
3869 eval { $conn->close() };
3870 };
3871
3872 if ($@) {
3873 $ex = $@;
3874 }
3875
3876 $wfh->print("done\n");
3877 $wfh->flush();
3878
3879 } else {
3880 eval { server_wait($config_file, $rfh) };
3881 if ($@) {
3882 warn($@);
3883 exit 1;
3884 }
3885
3886 exit 0;
3887 }
3888
3889 # Stop server
3890 server_stop($pid_file);
3891
3892 $self->assert_child_ok($pid);
3893
3894 # Now, read in the ExtendedLog, and see whether the %{uid} variable was
3895 # properly written out.
3896 if (open(my $fh, "< $ext_log")) {
3897 my $line = <$fh>;
3898 chomp($line);
3899 close($fh);
3900
3901 $self->assert($uid == $line,
3902 test_msg("Expected $uid, got '$line'"));
3903
3904 } else {
3905 die("Can't read $ext_log: $!");
3906 }
3907
3908 if ($ex) {
3909 test_append_logfile($log_file, $ex);
3910 unlink($log_file);
3911
3912 die($ex);
3913 }
3914
3915 unlink($log_file);
3916 }
3917
3918 sub extlog_gid_bug3390 {
3919 my $self = shift;
3920 my $tmpdir = $self->{tmpdir};
3921
3922 my $config_file = "$tmpdir/extlog.conf";
3923 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
3924 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
3925
3926 my $log_file = test_get_logfile();
3927
3928 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
3929 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
3930
3931 my $test_file = File::Spec->rel2abs($config_file);
3932
3933 my $user = 'proftpd';
3934 my $passwd = 'test';
3935 my $group = 'ftpd';
3936 my $home_dir = File::Spec->rel2abs($tmpdir);
3937 my $uid = 500;
3938 my $gid = 500;
3939
3940 # Make sure that, if we're running as root, that the home directory has
3941 # permissions/privs set for the account we create
3942 if ($< == 0) {
3943 unless (chmod(0755, $home_dir)) {
3944 die("Can't set perms on $home_dir to 0755: $!");
3945 }
3946
3947 unless (chown($uid, $gid, $home_dir)) {
3948 die("Can't set owner of $home_dir to $uid/$gid: $!");
3949 }
3950 }
3951
3952 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
3953 '/bin/bash');
3954 auth_group_write($auth_group_file, $group, $gid, $user);
3955
3956 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
3957
3958 my $config = {
3959 PidFile => $pid_file,
3960 ScoreboardFile => $scoreboard_file,
3961 SystemLog => $log_file,
3962
3963 AuthUserFile => $auth_user_file,
3964 AuthGroupFile => $auth_group_file,
3965 AuthOrder => 'mod_auth_file.c',
3966
3967 LogFormat => 'custom "%{gid}"',
3968 ExtendedLog => "$ext_log READ custom",
3969
3970 IfModules => {
3971 'mod_delay.c' => {
3972 DelayEngine => 'off',
3973 },
3974 },
3975 };
3976
3977 my ($port, $config_user, $config_group) = config_write($config_file, $config);
3978
3979 # Open pipes, for use between the parent and child processes. Specifically,
3980 # the child will indicate when it's done with its test by writing a message
3981 # to the parent.
3982 my ($rfh, $wfh);
3983 unless (pipe($rfh, $wfh)) {
3984 die("Can't open pipe: $!");
3985 }
3986
3987 my $ex;
3988
3989 # Fork child
3990 $self->handle_sigchld();
3991 defined(my $pid = fork()) or die("Can't fork: $!");
3992 if ($pid) {
3993 eval {
3994 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3995
3996 $client->login($user, $passwd);
3997
3998 my $conn = $client->retr_raw($test_file);
3999 unless ($conn) {
4000 die("Failed to RETR: " . $client->response_code() . " " .
4001 $client->response_msg());
4002 }
4003
4004 my $buf;
4005 $conn->read($buf, 8192, 30);
4006 eval { $conn->close() };
4007 };
4008
4009 if ($@) {
4010 $ex = $@;
4011 }
4012
4013 $wfh->print("done\n");
4014 $wfh->flush();
4015
4016 } else {
4017 eval { server_wait($config_file, $rfh) };
4018 if ($@) {
4019 warn($@);
4020 exit 1;
4021 }
4022
4023 exit 0;
4024 }
4025
4026 # Stop server
4027 server_stop($pid_file);
4028
4029 $self->assert_child_ok($pid);
4030
4031 # Now, read in the ExtendedLog, and see whether the %{gid} variable was
4032 # properly written out.
4033 if (open(my $fh, "< $ext_log")) {
4034 my $line = <$fh>;
4035 chomp($line);
4036 close($fh);
4037
4038 $self->assert($gid == $line,
4039 test_msg("Expected $gid, got '$line'"));
4040
4041 } else {
4042 die("Can't read $ext_log: $!");
4043 }
4044
4045 if ($ex) {
4046 test_append_logfile($log_file, $ex);
4047 unlink($log_file);
4048
4049 die($ex);
4050 }
4051
4052 unlink($log_file);
4053 }
4054
4055 sub extlog_pass_ok_var_s_bug3528 {
4056 my $self = shift;
4057 my $tmpdir = $self->{tmpdir};
4058
4059 my $config_file = "$tmpdir/extlog.conf";
4060 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
4061 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
4062
4063 my $log_file = test_get_logfile();
4064
4065 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
4066 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
4067
4068 my $test_file = File::Spec->rel2abs($config_file);
4069
4070 my $user = 'proftpd';
4071 my $passwd = 'test';
4072 my $group = 'ftpd';
4073 my $home_dir = File::Spec->rel2abs($tmpdir);
4074 my $uid = 500;
4075 my $gid = 500;
4076
4077 # Make sure that, if we're running as root, that the home directory has
4078 # permissions/privs set for the account we create
4079 if ($< == 0) {
4080 unless (chmod(0755, $home_dir)) {
4081 die("Can't set perms on $home_dir to 0755: $!");
4082 }
4083
4084 unless (chown($uid, $gid, $home_dir)) {
4085 die("Can't set owner of $home_dir to $uid/$gid: $!");
4086 }
4087 }
4088
4089 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4090 '/bin/bash');
4091 auth_group_write($auth_group_file, $group, $gid, $user);
4092
4093 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
4094
4095 my $config = {
4096 PidFile => $pid_file,
4097 ScoreboardFile => $scoreboard_file,
4098 SystemLog => $log_file,
4099 TraceLog => $log_file,
4100 Trace => 'response:10',
4101
4102 AuthUserFile => $auth_user_file,
4103 AuthGroupFile => $auth_group_file,
4104 AuthOrder => 'mod_auth_file.c',
4105
4106 LogFormat => 'custom "%m %s %S"',
4107 ExtendedLog => "$ext_log AUTH custom",
4108
4109 IfModules => {
4110 'mod_delay.c' => {
4111 DelayEngine => 'off',
4112 },
4113 },
4114 };
4115
4116 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4117
4118 # Open pipes, for use between the parent and child processes. Specifically,
4119 # the child will indicate when it's done with its test by writing a message
4120 # to the parent.
4121 my ($rfh, $wfh);
4122 unless (pipe($rfh, $wfh)) {
4123 die("Can't open pipe: $!");
4124 }
4125
4126 my $ex;
4127
4128 # Fork child
4129 $self->handle_sigchld();
4130 defined(my $pid = fork()) or die("Can't fork: $!");
4131 if ($pid) {
4132 eval {
4133 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4134 $client->login($user, $passwd);
4135 $client->quit();
4136 };
4137
4138 if ($@) {
4139 $ex = $@;
4140 }
4141
4142 $wfh->print("done\n");
4143 $wfh->flush();
4144
4145 } else {
4146 eval { server_wait($config_file, $rfh) };
4147 if ($@) {
4148 warn($@);
4149 exit 1;
4150 }
4151
4152 exit 0;
4153 }
4154
4155 # Stop server
4156 server_stop($pid_file);
4157
4158 $self->assert_child_ok($pid);
4159
4160 # Now, read in the ExtendedLog, and see whether the %s variable was
4161 # properly written out for the PASS command.
4162 if (open(my $fh, "< $ext_log")) {
4163 while (my $line = <$fh>) {
4164 chomp($line);
4165
4166 if ($line =~ /^(\S+) (\S+) (.*$)$/) {
4167 my $cmd = $1;
4168 my $resp_code = $2;
4169 my $resp_msg = $3;
4170
4171 next unless $cmd eq 'PASS';
4172
4173 my $expected = 230;
4174 $self->assert($expected == $resp_code,
4175 test_msg("Expected $expected, got $resp_code"));
4176
4177 $expected = "User $user logged in";
4178 $self->assert($expected eq $resp_msg,
4179 test_msg("Expected '$expected', got '$resp_msg'"));
4180
4181 last;
4182 }
4183 }
4184
4185 close($fh);
4186
4187 } else {
4188 die("Can't read $ext_log: $!");
4189 }
4190
4191 if ($ex) {
4192 test_append_logfile($log_file, $ex);
4193 unlink($log_file);
4194
4195 die($ex);
4196 }
4197
4198 unlink($log_file);
4199 }
4200
4201 sub extlog_pass_failed_var_s_bug3528 {
4202 my $self = shift;
4203 my $tmpdir = $self->{tmpdir};
4204 my $setup = test_setup($tmpdir, 'extlog');
4205
4206 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
4207
4208 my $config = {
4209 PidFile => $setup->{pid_file},
4210 ScoreboardFile => $setup->{scoreboard_file},
4211 SystemLog => $setup->{log_file},
4212 TraceLog => $setup->{log_file},
4213 Trace => 'extlog:20 jot:20 response:10',
4214
4215 AuthUserFile => $setup->{auth_user_file},
4216 AuthGroupFile => $setup->{auth_group_file},
4217 AuthOrder => 'mod_auth_file.c',
4218
4219 LogFormat => 'custom "%m %s %S"',
4220 ExtendedLog => "$ext_log AUTH custom",
4221
4222 IfModules => {
4223 'mod_delay.c' => {
4224 DelayEngine => 'off',
4225 },
4226 },
4227 };
4228
4229 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4230 $config);
4231
4232 # Open pipes, for use between the parent and child processes. Specifically,
4233 # the child will indicate when it's done with its test by writing a message
4234 # to the parent.
4235 my ($rfh, $wfh);
4236 unless (pipe($rfh, $wfh)) {
4237 die("Can't open pipe: $!");
4238 }
4239
4240 my $ex;
4241
4242 # Fork child
4243 $self->handle_sigchld();
4244 defined(my $pid = fork()) or die("Can't fork: $!");
4245 if ($pid) {
4246 eval {
4247 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4248 eval { $client->login($setup->{user}, 'foobar') };
4249 unless ($@) {
4250 die("Login succeeded unexpectedly");
4251 }
4252
4253 $client->quit();
4254 };
4255 if ($@) {
4256 $ex = $@;
4257 }
4258
4259 $wfh->print("done\n");
4260 $wfh->flush();
4261
4262 } else {
4263 eval { server_wait($setup->{config_file}, $rfh) };
4264 if ($@) {
4265 warn($@);
4266 exit 1;
4267 }
4268
4269 exit 0;
4270 }
4271
4272 # Stop server
4273 server_stop($setup->{pid_file});
4274 $self->assert_child_ok($pid);
4275
4276 # Now, read in the ExtendedLog, and see whether the %s variable was
4277 # properly written out for the PASS command.
4278 eval {
4279 if (open(my $fh, "< $ext_log")) {
4280 my $ok = 0;
4281
4282 while (my $line = <$fh>) {
4283 chomp($line);
4284
4285 if ($ENV{TEST_VERBOSE}) {
4286 print STDERR "# ExtendedLog: $line\n";
4287 }
4288
4289 if ($line =~ /^(\S+) (\S+) (.*$)$/) {
4290 my $cmd = $1;
4291 my $resp_code = $2;
4292 my $resp_msg = $3;
4293
4294 next unless $cmd eq 'PASS';
4295
4296 my $expected = 530;
4297 $self->assert($expected == $resp_code,
4298 test_msg("Expected $expected, got $resp_code"));
4299
4300 $expected = "Login incorrect.";
4301 $self->assert($expected eq $resp_msg,
4302 test_msg("Expected '$expected', got '$resp_msg'"));
4303
4304 $ok = 1;
4305 last;
4306 }
4307 }
4308
4309 close($fh);
4310 $self->assert($ok, "Did not see expected ExtendedLog lines");
4311
4312 } else {
4313 die("Can't read $ext_log: $!");
4314 }
4315 };
4316 if ($@) {
4317 $ex = $@;
4318 }
4319
4320 test_cleanup($setup->{log_file}, $ex);
4321 }
4322
4323 sub extlog_ftp_raw_bytes_bug3554 {
4324 my $self = shift;
4325 my $tmpdir = $self->{tmpdir};
4326
4327 my $config_file = "$tmpdir/extlog.conf";
4328 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
4329 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
4330
4331 my $log_file = test_get_logfile();
4332
4333 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
4334 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
4335
4336 my $test_file = File::Spec->rel2abs($config_file);
4337
4338 my $user = 'proftpd';
4339 my $passwd = 'test';
4340 my $group = 'ftpd';
4341 my $home_dir = File::Spec->rel2abs($tmpdir);
4342 my $uid = 500;
4343 my $gid = 500;
4344
4345 # Make sure that, if we're running as root, that the home directory has
4346 # permissions/privs set for the account we create
4347 if ($< == 0) {
4348 unless (chmod(0755, $home_dir)) {
4349 die("Can't set perms on $home_dir to 0755: $!");
4350 }
4351
4352 unless (chown($uid, $gid, $home_dir)) {
4353 die("Can't set owner of $home_dir to $uid/$gid: $!");
4354 }
4355 }
4356
4357 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4358 '/bin/bash');
4359 auth_group_write($auth_group_file, $group, $gid, $user);
4360
4361 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
4362
4363 my $config = {
4364 PidFile => $pid_file,
4365 ScoreboardFile => $scoreboard_file,
4366 SystemLog => $log_file,
4367 TraceLog => $log_file,
4368 Trace => 'response:10',
4369
4370 AuthUserFile => $auth_user_file,
4371 AuthGroupFile => $auth_group_file,
4372 AuthOrder => 'mod_auth_file.c',
4373
4374 LogFormat => 'custom "%{protocol} %m \"%S\" %I %O"',
4375 ExtendedLog => "$ext_log ALL custom",
4376 ServerIdent => 'on "FTP Server"',
4377
4378 IfModules => {
4379 'mod_delay.c' => {
4380 DelayEngine => 'off',
4381 },
4382 },
4383 };
4384
4385 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4386
4387 # Open pipes, for use between the parent and child processes. Specifically,
4388 # the child will indicate when it's done with its test by writing a message
4389 # to the parent.
4390 my ($rfh, $wfh);
4391 unless (pipe($rfh, $wfh)) {
4392 die("Can't open pipe: $!");
4393 }
4394
4395 my $ex;
4396
4397 # Fork child
4398 $self->handle_sigchld();
4399 defined(my $pid = fork()) or die("Can't fork: $!");
4400 if ($pid) {
4401 eval {
4402 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4403 $client->login($user, $passwd);
4404 $client->type('ascii');
4405
4406 my $conn = $client->stor_raw('test.txt');
4407 unless ($conn) {
4408 die("STOR test.txt failed: " . $client->response_code() . " " .
4409 $client->response_msg());
4410 }
4411
4412 my $buf = "ABCD\n" x 8;
4413 $conn->write($buf, length($buf), 30);
4414 eval { $conn->close() };
4415
4416 my $resp_code = $client->response_code();
4417 my $resp_msg = $client->response_msg();
4418 $client->quit();
4419
4420 $self->assert_transfer_ok($resp_code, $resp_msg);
4421 };
4422
4423 if ($@) {
4424 $ex = $@;
4425 }
4426
4427 $wfh->print("done\n");
4428 $wfh->flush();
4429
4430 } else {
4431 eval { server_wait($config_file, $rfh) };
4432 if ($@) {
4433 warn($@);
4434 exit 1;
4435 }
4436
4437 exit 0;
4438 }
4439
4440 # Stop server
4441 server_stop($pid_file);
4442
4443 $self->assert_child_ok($pid);
4444
4445 # Now, read in the ExtendedLog, and see whether the %I/%O variables
4446 # are properly populated
4447 if (open(my $fh, "< $ext_log")) {
4448 while (my $line = <$fh>) {
4449 chomp($line);
4450
4451 if ($line =~ /^\S+ (\S+) (.*?) (\d+) (\d+)$/) {
4452 my $cmd = $1;
4453 my $resp = $2;
4454 my $bytes_in = $3;
4455 my $bytes_out = $4;
4456
4457 # Only watch for the QUIT command, to get the session total.
4458 next unless $cmd eq 'QUIT';
4459
4460 my $expected = 108;
4461 $self->assert($expected == $bytes_in,
4462 test_msg("Expected $expected, got $bytes_in"));
4463
4464 # Why would this number vary so widely? It's because of the notation
4465 # used to express the port number in a PASV response. That port
4466 # number is ephemeral, chosen by the kernel.
4467
4468 my $expected_min = 232;
4469 my $expected_max = 236;
4470 $self->assert($expected_min <= $bytes_out &&
4471 $expected_max >= $bytes_out,
4472 test_msg("Expected $expected_min - $expected_max, got $bytes_out"));
4473 }
4474 }
4475
4476 close($fh);
4477
4478 } else {
4479 die("Can't read $ext_log: $!");
4480 }
4481
4482 if ($ex) {
4483 test_append_logfile($log_file, $ex);
4484 unlink($log_file);
4485
4486 die($ex);
4487 }
4488
4489 unlink($log_file);
4490 }
4491
4492 sub extlog_ftp_sendfile_raw_bytes_bug3554 {
4493 my $self = shift;
4494 my $tmpdir = $self->{tmpdir};
4495
4496 my $config_file = "$tmpdir/extlog.conf";
4497 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
4498 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
4499
4500 my $log_file = test_get_logfile();
4501
4502 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
4503 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
4504
4505 my $user = 'proftpd';
4506 my $passwd = 'test';
4507 my $group = 'ftpd';
4508 my $home_dir = File::Spec->rel2abs($tmpdir);
4509 my $uid = 500;
4510 my $gid = 500;
4511
4512 # Make sure that, if we're running as root, that the home directory has
4513 # permissions/privs set for the account we create
4514 if ($< == 0) {
4515 unless (chmod(0755, $home_dir)) {
4516 die("Can't set perms on $home_dir to 0755: $!");
4517 }
4518
4519 unless (chown($uid, $gid, $home_dir)) {
4520 die("Can't set owner of $home_dir to $uid/$gid: $!");
4521 }
4522 }
4523
4524 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4525 '/bin/bash');
4526 auth_group_write($auth_group_file, $group, $gid, $user);
4527
4528 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
4529
4530 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
4531 if (open(my $fh, "> $test_file")) {
4532 print $fh "ABCD\n" x 8;
4533 unless (close($fh)) {
4534 die("Can't write $test_file: $!");
4535 }
4536
4537 } else {
4538 die("Can't open $test_file: $!");
4539 }
4540
4541 my $config = {
4542 PidFile => $pid_file,
4543 ScoreboardFile => $scoreboard_file,
4544 SystemLog => $log_file,
4545 TraceLog => $log_file,
4546 Trace => 'response:10',
4547
4548 AuthUserFile => $auth_user_file,
4549 AuthGroupFile => $auth_group_file,
4550 AuthOrder => 'mod_auth_file.c',
4551
4552 LogFormat => 'custom "%{protocol} %m \"%S\" %I %O"',
4553 ExtendedLog => "$ext_log ALL custom",
4554 ServerIdent => 'on "FTP Server"',
4555
4556 UseSendfile => 'on',
4557
4558 IfModules => {
4559 'mod_delay.c' => {
4560 DelayEngine => 'off',
4561 },
4562 },
4563 };
4564
4565 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4566
4567 # Open pipes, for use between the parent and child processes. Specifically,
4568 # the child will indicate when it's done with its test by writing a message
4569 # to the parent.
4570 my ($rfh, $wfh);
4571 unless (pipe($rfh, $wfh)) {
4572 die("Can't open pipe: $!");
4573 }
4574
4575 my $ex;
4576
4577 # Fork child
4578 $self->handle_sigchld();
4579 defined(my $pid = fork()) or die("Can't fork: $!");
4580 if ($pid) {
4581 eval {
4582 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4583 $client->login($user, $passwd);
4584 $client->type('binary');
4585
4586 my $conn = $client->retr_raw('test.txt');
4587 unless ($conn) {
4588 die("RETR test.txt failed: " . $client->response_code() . " " .
4589 $client->response_msg());
4590 }
4591
4592 my $buf;
4593 $conn->read($buf, 16382, 30);
4594 eval { $conn->close() };
4595
4596 my $resp_code = $client->response_code();
4597 my $resp_msg = $client->response_msg();
4598 $client->quit();
4599
4600 $self->assert_transfer_ok($resp_code, $resp_msg);
4601 };
4602
4603 if ($@) {
4604 $ex = $@;
4605 }
4606
4607 $wfh->print("done\n");
4608 $wfh->flush();
4609
4610 } else {
4611 eval { server_wait($config_file, $rfh) };
4612 if ($@) {
4613 warn($@);
4614 exit 1;
4615 }
4616
4617 exit 0;
4618 }
4619
4620 # Stop server
4621 server_stop($pid_file);
4622
4623 $self->assert_child_ok($pid);
4624
4625 # Now, read in the ExtendedLog, and see whether the %I/%O variables
4626 # are properly populated
4627 if (open(my $fh, "< $ext_log")) {
4628 while (my $line = <$fh>) {
4629 chomp($line);
4630
4631 if ($line =~ /^\S+ (\S+) (.*?) (\d+) (\d+)$/) {
4632 my $cmd = $1;
4633 my $resp = $2;
4634 my $bytes_in = $3;
4635 my $bytes_out = $4;
4636
4637 # Only watch for the QUIT command, to get the session total.
4638 next unless $cmd eq 'QUIT';
4639
4640 # Why would this number vary so widely? It's because of the notation
4641 # used to express the port number in a PASV response. That port
4642 # number is ephemeral, chosen by the kernel.
4643
4644 my $expected_min = 60;
4645 my $expected_max = 70;
4646 $self->assert($expected_min <= $bytes_in &&
4647 $expected_max >= $bytes_in,
4648 test_msg("Expected $expected_min - $expected_max, got $bytes_in"));
4649
4650 $expected_min = 284;
4651 $expected_max = 288;
4652 $self->assert($expected_min <= $bytes_out &&
4653 $expected_max >= $bytes_out,
4654 test_msg("Expected $expected_min - $expected_max, got $bytes_out"));
4655 }
4656 }
4657
4658 close($fh);
4659
4660 } else {
4661 die("Can't read $ext_log: $!");
4662 }
4663
4664 if ($ex) {
4665 test_append_logfile($log_file, $ex);
4666 unlink($log_file);
4667
4668 die($ex);
4669 }
4670
4671 unlink($log_file);
4672 }
4673
4674 sub extlog_ftp_deflate_raw_bytes_bug3554 {
4675 my $self = shift;
4676 my $tmpdir = $self->{tmpdir};
4677
4678 my $config_file = "$tmpdir/extlog.conf";
4679 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
4680 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
4681
4682 my $log_file = test_get_logfile();
4683
4684 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
4685 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
4686
4687 my $test_file = File::Spec->rel2abs($config_file);
4688
4689 my $user = 'proftpd';
4690 my $passwd = 'test';
4691 my $group = 'ftpd';
4692 my $home_dir = File::Spec->rel2abs($tmpdir);
4693 my $uid = 500;
4694 my $gid = 500;
4695
4696 # Make sure that, if we're running as root, that the home directory has
4697 # permissions/privs set for the account we create
4698 if ($< == 0) {
4699 unless (chmod(0755, $home_dir)) {
4700 die("Can't set perms on $home_dir to 0755: $!");
4701 }
4702
4703 unless (chown($uid, $gid, $home_dir)) {
4704 die("Can't set owner of $home_dir to $uid/$gid: $!");
4705 }
4706 }
4707
4708 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4709 '/bin/bash');
4710 auth_group_write($auth_group_file, $group, $gid, $user);
4711
4712 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
4713
4714 my $config = {
4715 PidFile => $pid_file,
4716 ScoreboardFile => $scoreboard_file,
4717 SystemLog => $log_file,
4718 TraceLog => $log_file,
4719 Trace => 'DEFAULT:10 deflate:10',
4720
4721 AuthUserFile => $auth_user_file,
4722 AuthGroupFile => $auth_group_file,
4723 AuthOrder => 'mod_auth_file.c',
4724
4725 LogFormat => 'custom "%{protocol} %m \"%S\" %I %O"',
4726 ExtendedLog => "$ext_log ALL custom",
4727 ServerIdent => 'on "FTP Server"',
4728 TimeoutLinger => 1,
4729
4730 IfModules => {
4731 'mod_deflate.c' => {
4732 DeflateEngine => 'on',
4733 DeflateLog => $log_file,
4734 },
4735
4736 'mod_delay.c' => {
4737 DelayEngine => 'off',
4738 },
4739 },
4740 };
4741
4742 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4743
4744 # Open pipes, for use between the parent and child processes. Specifically,
4745 # the child will indicate when it's done with its test by writing a message
4746 # to the parent.
4747 my ($rfh, $wfh);
4748 unless (pipe($rfh, $wfh)) {
4749 die("Can't open pipe: $!");
4750 }
4751
4752 my $ex;
4753
4754 # Fork child
4755 $self->handle_sigchld();
4756 defined(my $pid = fork()) or die("Can't fork: $!");
4757 if ($pid) {
4758 eval {
4759 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
4760 $client->login($user, $passwd);
4761 $client->mode('Z');
4762
4763 my $conn = $client->stor_raw('test.txt');
4764 unless ($conn) {
4765 die("STOR test.txt failed: " . $client->response_code() . " " .
4766 $client->response_msg());
4767 }
4768
4769 my $buf = "ABCD\n" x 8;
4770 my $deflated = compress($buf);
4771 $conn->write($deflated, length($deflated), 30);
4772 eval { $conn->close() };
4773
4774 my $resp_code = $client->response_code();
4775 my $resp_msg = $client->response_msg();
4776 $client->quit();
4777
4778 $self->assert_transfer_ok($resp_code, $resp_msg);
4779 };
4780
4781 if ($@) {
4782 $ex = $@;
4783 }
4784
4785 $wfh->print("done\n");
4786 $wfh->flush();
4787
4788 } else {
4789 eval { server_wait($config_file, $rfh) };
4790 if ($@) {
4791 warn($@);
4792 exit 1;
4793 }
4794
4795 exit 0;
4796 }
4797
4798 # Stop server
4799 server_stop($pid_file);
4800
4801 $self->assert_child_ok($pid);
4802
4803 # Now, read in the ExtendedLog, and see whether the %I/%O variables
4804 # are properly populated
4805 if (open(my $fh, "< $ext_log")) {
4806 while (my $line = <$fh>) {
4807 chomp($line);
4808
4809 if ($line =~ /^\S+ (\S+) (.*?) (\d+) (\d+)$/) {
4810 my $cmd = $1;
4811 my $resp = $2;
4812 my $bytes_in = $3;
4813 my $bytes_out = $4;
4814
4815 # Only watch for the QUIT command, to get the session total.
4816 next unless $cmd eq 'QUIT';
4817
4818 my $expected = 100;
4819 $self->assert($expected == $bytes_in,
4820 test_msg("Expected $expected, got $bytes_in"));
4821
4822 # Why would this number vary so widely? It's because of the notation
4823 # used to express the port number in a PASV response. That port
4824 # number is ephemeral, chosen by the kernel.
4825
4826 my $expected_min = 221;
4827 my $expected_max = 225;
4828 $self->assert($expected_min <= $bytes_out &&
4829 $expected_max >= $bytes_out,
4830 test_msg("Expected $expected_min - $expected_max, got $bytes_out"));
4831 }
4832 }
4833
4834 close($fh);
4835
4836 } else {
4837 die("Can't read $ext_log: $!");
4838 }
4839
4840 if ($ex) {
4841 test_append_logfile($log_file, $ex);
4842 unlink($log_file);
4843
4844 die($ex);
4845 }
4846
4847 unlink($log_file);
4848 }
4849
4850 sub extlog_ftps_raw_bytes_bug3554 {
4851 my $self = shift;
4852 my $tmpdir = $self->{tmpdir};
4853
4854 my $config_file = "$tmpdir/extlog.conf";
4855 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
4856 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
4857
4858 my $log_file = test_get_logfile();
4859
4860 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
4861 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
4862
4863 my $user = 'proftpd';
4864 my $passwd = 'test';
4865 my $group = 'ftpd';
4866 my $home_dir = File::Spec->rel2abs($tmpdir);
4867 my $uid = 500;
4868 my $gid = 500;
4869
4870 # Make sure that, if we're running as root, that the home directory has
4871 # permissions/privs set for the account we create
4872 if ($< == 0) {
4873 unless (chmod(0755, $home_dir)) {
4874 die("Can't set perms on $home_dir to 0755: $!");
4875 }
4876
4877 unless (chown($uid, $gid, $home_dir)) {
4878 die("Can't set owner of $home_dir to $uid/$gid: $!");
4879 }
4880 }
4881
4882 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4883 '/bin/bash');
4884 auth_group_write($auth_group_file, $group, $gid, $user);
4885
4886 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4887 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4888
4889 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
4890
4891 my $src_file = File::Spec->rel2abs("$tmpdir/src.txt");
4892 if (open(my $fh, "> $src_file")) {
4893 print $fh "ABCD\n" x 8192;
4894 unless (close($fh)) {
4895 die("Can't write $src_file: $!");
4896 }
4897
4898 } else {
4899 die("Can't open $src_file: $!");
4900 }
4901
4902 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
4903
4904 my $config = {
4905 PidFile => $pid_file,
4906 ScoreboardFile => $scoreboard_file,
4907 SystemLog => $log_file,
4908 TraceLog => $log_file,
4909 Trace => 'response:10',
4910
4911 AuthUserFile => $auth_user_file,
4912 AuthGroupFile => $auth_group_file,
4913 AuthOrder => 'mod_auth_file.c',
4914
4915 LogFormat => 'custom "%{protocol} %m \"%S\" %I %O"',
4916 ExtendedLog => "$ext_log ALL custom",
4917 ServerIdent => 'on "FTP Server"',
4918
4919 IfModules => {
4920 'mod_delay.c' => {
4921 DelayEngine => 'off',
4922 },
4923
4924 'mod_tls.c' => {
4925 TLSEngine => 'on',
4926 TLSLog => $log_file,
4927 TLSRequired => 'on',
4928 TLSRSACertificateFile => $cert_file,
4929 TLSCACertificateFile => $ca_file,
4930 TLSOptions => 'NoSessionReuseRequired',
4931 },
4932 },
4933 };
4934
4935 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4936
4937 # Open pipes, for use between the parent and child processes. Specifically,
4938 # the child will indicate when it's done with its test by writing a message
4939 # to the parent.
4940 my ($rfh, $wfh);
4941 unless (pipe($rfh, $wfh)) {
4942 die("Can't open pipe: $!");
4943 }
4944
4945 require Net::FTPSSL;
4946
4947 my $ex;
4948
4949 # Fork child
4950 $self->handle_sigchld();
4951 defined(my $pid = fork()) or die("Can't fork: $!");
4952 if ($pid) {
4953 eval {
4954 # Give the server a chance to start up
4955 sleep(2);
4956
4957 my $client = Net::FTPSSL->new('127.0.0.1',
4958 Encryption => 'E',
4959 Port => $port,
4960 );
4961
4962 unless ($client) {
4963 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
4964 }
4965
4966 unless ($client->login($user, $passwd)) {
4967 die("Can't login: " . $client->last_message());
4968 }
4969
4970 unless ($client->binary()) {
4971 die("Can't set transfer mode to binary: " . $client->last_message());
4972 }
4973
4974 unless ($client->put($src_file, 'test.txt')) {
4975 die("Can't upload '$src_file' to 'test.txt': " .
4976 $client->last_message());
4977 }
4978
4979 $client->quit();
4980
4981 unless (-f $test_file) {
4982 die("File $test_file does not exist as expected");
4983 }
4984 };
4985
4986 if ($@) {
4987 $ex = $@;
4988 }
4989
4990 $wfh->print("done\n");
4991 $wfh->flush();
4992
4993 } else {
4994 eval { server_wait($config_file, $rfh, 30) };
4995 if ($@) {
4996 warn($@);
4997 exit 1;
4998 }
4999
5000 exit 0;
5001 }
5002
5003 # Stop server
5004 server_stop($pid_file);
5005
5006 $self->assert_child_ok($pid);
5007
5008 if ($ex) {
5009 test_append_logfile($log_file, $ex);
5010 unlink($log_file);
5011
5012 die($ex);
5013 }
5014
5015 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5016 # are properly populated
5017 if (open(my $fh, "< $ext_log")) {
5018 while (my $line = <$fh>) {
5019 chomp($line);
5020
5021 if ($line =~ /^\S+ (\S+) (.*?) (\d+) (\d+)$/) {
5022 my $cmd = $1;
5023 my $resp = $2;
5024 my $bytes_in = $3;
5025 my $bytes_out = $4;
5026
5027 # Only watch for the QUIT command, to get the session total.
5028 next unless $cmd eq 'QUIT';
5029
5030 # The expected bytes in/out will vary on the ciphers used, etc.
5031 my $expected_min = 42240;
5032 my $expected_max = 42378;
5033 $self->assert($expected_min <= $bytes_in &&
5034 $expected_max >= $bytes_in,
5035 test_msg("Expected $expected_min - $expected_max, got $bytes_in"));
5036
5037 $expected_min = 6828;
5038 $expected_max = 9140;
5039 $self->assert($expected_min <= $bytes_out &&
5040 $expected_max >= $bytes_out,
5041 test_msg("Expected $expected_min - $expected_max, got $bytes_out"));
5042 }
5043 }
5044
5045 close($fh);
5046
5047 } else {
5048 die("Can't read $ext_log: $!");
5049 }
5050
5051 unlink($log_file);
5052 }
5053
5054 sub extlog_sftp_raw_bytes_bug3554 {
5055 my $self = shift;
5056 my $tmpdir = $self->{tmpdir};
5057
5058 my $config_file = "$tmpdir/extlog.conf";
5059 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5060 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5061
5062 my $log_file = test_get_logfile();
5063
5064 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5065 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5066
5067 my $user = 'proftpd';
5068 my $passwd = 'test';
5069 my $group = 'ftpd';
5070 my $home_dir = File::Spec->rel2abs($tmpdir);
5071 my $uid = 500;
5072 my $gid = 500;
5073
5074 # Make sure that, if we're running as root, that the home directory has
5075 # permissions/privs set for the account we create
5076 if ($< == 0) {
5077 unless (chmod(0755, $home_dir)) {
5078 die("Can't set perms on $home_dir to 0755: $!");
5079 }
5080
5081 unless (chown($uid, $gid, $home_dir)) {
5082 die("Can't set owner of $home_dir to $uid/$gid: $!");
5083 }
5084 }
5085
5086 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5087 '/bin/bash');
5088 auth_group_write($auth_group_file, $group, $gid, $user);
5089
5090 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
5091 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
5092
5093 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5094
5095 my $config = {
5096 PidFile => $pid_file,
5097 ScoreboardFile => $scoreboard_file,
5098 SystemLog => $log_file,
5099 TraceLog => $log_file,
5100 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
5101
5102 AuthUserFile => $auth_user_file,
5103 AuthGroupFile => $auth_group_file,
5104 AuthOrder => 'mod_auth_file.c',
5105
5106 LogFormat => 'custom "%{protocol} %m \"%S\" %I %O"',
5107 ExtendedLog => "$ext_log ALL custom",
5108 ServerIdent => 'on "FTP Server"',
5109
5110 IfModules => {
5111 'mod_delay.c' => {
5112 DelayEngine => 'off',
5113 },
5114
5115 'mod_sftp.c' => [
5116 "SFTPEngine on",
5117 "SFTPLog $log_file",
5118 "SFTPHostKey $rsa_host_key",
5119 "SFTPHostKey $dsa_host_key",
5120 ],
5121 },
5122 };
5123
5124 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5125
5126 # Open pipes, for use between the parent and child processes. Specifically,
5127 # the child will indicate when it's done with its test by writing a message
5128 # to the parent.
5129 my ($rfh, $wfh);
5130 unless (pipe($rfh, $wfh)) {
5131 die("Can't open pipe: $!");
5132 }
5133
5134 require Net::SSH2;
5135
5136 my $ex;
5137
5138 # Ignore SIGPIPE
5139 local $SIG{PIPE} = sub { };
5140
5141 # Fork child
5142 $self->handle_sigchld();
5143 defined(my $pid = fork()) or die("Can't fork: $!");
5144 if ($pid) {
5145 eval {
5146 my $ssh2 = Net::SSH2->new();
5147
5148 sleep(1);
5149
5150 unless ($ssh2->connect('127.0.0.1', $port)) {
5151 my ($err_code, $err_name, $err_str) = $ssh2->error();
5152 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
5153 }
5154
5155 unless ($ssh2->auth_password($user, $passwd)) {
5156 my ($err_code, $err_name, $err_str) = $ssh2->error();
5157 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
5158 }
5159
5160 my $sftp = $ssh2->sftp();
5161 unless ($sftp) {
5162 my ($err_code, $err_name, $err_str) = $ssh2->error();
5163 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
5164 }
5165
5166 my $fh = $sftp->open('test.txt', O_WRONLY|O_CREAT|O_TRUNC, 0644);
5167 unless ($fh) {
5168 my ($err_code, $err_name) = $sftp->error();
5169 die("Can't open test.txt: [$err_name] ($err_code)");
5170 }
5171
5172 print $fh "ABCD\n" x 8192;
5173
5174 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
5175 $fh = undef;
5176
5177 # To issue the CHANNEL_CLOSE, we have to explicitly destroy the sftp
5178 # object. Sigh.
5179 $sftp = undef;
5180
5181 $ssh2->disconnect();
5182 };
5183
5184 if ($@) {
5185 $ex = $@;
5186 }
5187
5188 $wfh->print("done\n");
5189 $wfh->flush();
5190
5191 } else {
5192 eval { server_wait($config_file, $rfh) };
5193 if ($@) {
5194 warn($@);
5195 exit 1;
5196 }
5197
5198 exit 0;
5199 }
5200
5201 # Stop server
5202 server_stop($pid_file);
5203
5204 $self->assert_child_ok($pid);
5205
5206 if ($ex) {
5207 test_append_logfile($log_file, $ex);
5208 unlink($log_file);
5209
5210 die($ex);
5211 }
5212
5213 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5214 # are properly populated
5215 if (open(my $fh, "< $ext_log")) {
5216 while (my $line = <$fh>) {
5217 chomp($line);
5218
5219 if ($line =~ /^\S+ (\S+) (.*?) (\d+) (\d+)$/) {
5220 my $cmd = $1;
5221 my $resp = $2;
5222 my $bytes_in = $3;
5223 my $bytes_out = $4;
5224
5225 # Only watch for the CHANNEL_CLOSE command, to get the session total.
5226 next unless $cmd eq 'CHANNEL_CLOSE';
5227
5228 # The expected bytes in/out will vary on the ciphers used, etc.
5229 my $expected_min = 34147;
5230 my $expected_max = 34147;
5231 $self->assert($expected_min <= $bytes_in &&
5232 $expected_max >= $bytes_in,
5233 test_msg("Expected $expected_min - $expected_max, got $bytes_in"));
5234
5235 $expected_min = 2116;
5236 $expected_max = 2196;
5237 $self->assert($expected_min <= $bytes_out &&
5238 $expected_max >= $bytes_out,
5239 test_msg("Expected $expected_min - $expected_max, got $bytes_out"));
5240 }
5241 }
5242
5243 close($fh);
5244
5245 } else {
5246 die("Can't read $ext_log: $!");
5247 }
5248
5249 unlink($log_file);
5250 }
5251
5252 sub extlog_scp_raw_bytes_bug3554 {
5253 my $self = shift;
5254 my $tmpdir = $self->{tmpdir};
5255
5256 my $config_file = "$tmpdir/extlog.conf";
5257 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5258 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5259
5260 my $log_file = test_get_logfile();
5261
5262 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5263 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5264
5265 my $user = 'proftpd';
5266 my $passwd = 'test';
5267 my $group = 'ftpd';
5268 my $home_dir = File::Spec->rel2abs($tmpdir);
5269 my $uid = 500;
5270 my $gid = 500;
5271
5272 # Make sure that, if we're running as root, that the home directory has
5273 # permissions/privs set for the account we create
5274 if ($< == 0) {
5275 unless (chmod(0755, $home_dir)) {
5276 die("Can't set perms on $home_dir to 0755: $!");
5277 }
5278
5279 unless (chown($uid, $gid, $home_dir)) {
5280 die("Can't set owner of $home_dir to $uid/$gid: $!");
5281 }
5282 }
5283
5284 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5285 '/bin/bash');
5286 auth_group_write($auth_group_file, $group, $gid, $user);
5287
5288 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
5289 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
5290
5291 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5292
5293 my $src_file = File::Spec->rel2abs("$tmpdir/src.txt");
5294 if (open(my $fh, "> $src_file")) {
5295 print $fh "ABCD\n" x 8192;
5296 unless (close($fh)) {
5297 die("Can't write $src_file: $!");
5298 }
5299
5300 } else {
5301 die("Can't open $src_file: $!");
5302 }
5303
5304 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
5305
5306 my $config = {
5307 PidFile => $pid_file,
5308 ScoreboardFile => $scoreboard_file,
5309 SystemLog => $log_file,
5310 TraceLog => $log_file,
5311 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
5312
5313 AuthUserFile => $auth_user_file,
5314 AuthGroupFile => $auth_group_file,
5315 AuthOrder => 'mod_auth_file.c',
5316
5317 LogFormat => 'custom "%{protocol} %m \"%S\" %I %O"',
5318 ExtendedLog => "$ext_log ALL custom",
5319 ServerIdent => 'on "FTP Server"',
5320
5321 IfModules => {
5322 'mod_delay.c' => {
5323 DelayEngine => 'off',
5324 },
5325
5326 'mod_sftp.c' => [
5327 "SFTPEngine on",
5328 "SFTPLog $log_file",
5329 "SFTPHostKey $rsa_host_key",
5330 "SFTPHostKey $dsa_host_key",
5331 ],
5332 },
5333 };
5334
5335 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5336
5337 # Open pipes, for use between the parent and child processes. Specifically,
5338 # the child will indicate when it's done with its test by writing a message
5339 # to the parent.
5340 my ($rfh, $wfh);
5341 unless (pipe($rfh, $wfh)) {
5342 die("Can't open pipe: $!");
5343 }
5344
5345 require Net::SSH2;
5346
5347 my $ex;
5348
5349 # Ignore SIGPIPE
5350 local $SIG{PIPE} = sub { };
5351
5352 # Fork child
5353 $self->handle_sigchld();
5354 defined(my $pid = fork()) or die("Can't fork: $!");
5355 if ($pid) {
5356 eval {
5357 my $ssh2 = Net::SSH2->new();
5358
5359 sleep(1);
5360
5361 unless ($ssh2->connect('127.0.0.1', $port)) {
5362 my ($err_code, $err_name, $err_str) = $ssh2->error();
5363 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
5364 }
5365
5366 unless ($ssh2->auth_password($user, $passwd)) {
5367 my ($err_code, $err_name, $err_str) = $ssh2->error();
5368 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
5369 }
5370
5371 my $res = $ssh2->scp_put($src_file, 'test.txt');
5372 unless ($res) {
5373 my ($err_code, $err_name, $err_str) = $ssh2->error();
5374 die("Can't upload $src_file to server: [$err_name] ($err_code) $err_str");
5375 }
5376
5377 $ssh2->disconnect();
5378
5379 unless (-f $test_file) {
5380 die("File $test_file does not exist as expected");
5381 }
5382 };
5383
5384 if ($@) {
5385 $ex = $@;
5386 }
5387
5388 $wfh->print("done\n");
5389 $wfh->flush();
5390
5391 } else {
5392 eval { server_wait($config_file, $rfh) };
5393 if ($@) {
5394 warn($@);
5395 exit 1;
5396 }
5397
5398 exit 0;
5399 }
5400
5401 # Stop server
5402 server_stop($pid_file);
5403
5404 $self->assert_child_ok($pid);
5405
5406 if ($ex) {
5407 test_append_logfile($log_file, $ex);
5408 unlink($log_file);
5409
5410 die($ex);
5411 }
5412
5413 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5414 # are properly populated
5415 if (open(my $fh, "< $ext_log")) {
5416 while (my $line = <$fh>) {
5417 chomp($line);
5418
5419 if ($line =~ /^\S+ (\S+) (.*?) (\d+) (\d+)$/) {
5420 my $cmd = $1;
5421 my $resp = $2;
5422 my $bytes_in = $3;
5423 my $bytes_out = $4;
5424
5425 # Only watch for the CHANNEL_CLOSE command, to get the session total.
5426 next unless $cmd eq 'CHANNEL_CLOSE';
5427
5428 # The expected bytes in/out will vary on the ciphers used, etc.
5429 my $expected_min = 42787;
5430 my $expected_max = 42787;
5431 $self->assert($expected_min <= $bytes_in &&
5432 $expected_max >= $bytes_in,
5433 test_msg("Expected $expected_min - $expected_max, got $bytes_in"));
5434
5435 $expected_min = 1996;
5436 $expected_max = 2036;
5437 $self->assert($expected_min <= $bytes_out &&
5438 $expected_max >= $bytes_out,
5439 test_msg("Expected $expected_min - $expected_max, got $bytes_out"));
5440 }
5441 }
5442
5443 close($fh);
5444
5445 } else {
5446 die("Can't read $ext_log: $!");
5447 }
5448
5449 unlink($log_file);
5450 }
5451
5452 sub extlog_exit_bug3559 {
5453 my $self = shift;
5454 my $tmpdir = $self->{tmpdir};
5455 my $setup = test_setup($tmpdir, 'extlog');
5456
5457 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5458
5459 my $config = {
5460 PidFile => $setup->{pid_file},
5461 ScoreboardFile => $setup->{scoreboard_file},
5462 SystemLog => $setup->{log_file},
5463 TraceLog => $setup->{log_file},
5464 Trace => 'jot:20 response:10',
5465
5466 AuthUserFile => $setup->{auth_user_file},
5467 AuthGroupFile => $setup->{auth_group_file},
5468 AuthOrder => 'mod_auth_file.c',
5469
5470 LogFormat => 'custom "%{protocol} %L %m \"%S\" %I %O"',
5471 ExtendedLog => "$ext_log EXIT custom",
5472
5473 IfModules => {
5474 'mod_delay.c' => {
5475 DelayEngine => 'off',
5476 },
5477 },
5478 };
5479
5480 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
5481 $config);
5482
5483 # Open pipes, for use between the parent and child processes. Specifically,
5484 # the child will indicate when it's done with its test by writing a message
5485 # to the parent.
5486 my ($rfh, $wfh);
5487 unless (pipe($rfh, $wfh)) {
5488 die("Can't open pipe: $!");
5489 }
5490
5491 my $ex;
5492
5493 # Fork child
5494 $self->handle_sigchld();
5495 defined(my $pid = fork()) or die("Can't fork: $!");
5496 if ($pid) {
5497 eval {
5498 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5499 $client->login($setup->{user}, $setup->{passwd});
5500 $client->type('ascii');
5501
5502 my $conn = $client->stor_raw('test.txt');
5503 unless ($conn) {
5504 die("STOR test.txt failed: " . $client->response_code() . " " .
5505 $client->response_msg());
5506 }
5507
5508 my $buf = "ABCD\n" x 8;
5509 $conn->write($buf, length($buf), 30);
5510 eval { $conn->close() };
5511
5512 my $resp_code = $client->response_code();
5513 my $resp_msg = $client->response_msg();
5514 $client->quit();
5515
5516 $self->assert_transfer_ok($resp_code, $resp_msg);
5517 };
5518 if ($@) {
5519 $ex = $@;
5520 }
5521
5522 $wfh->print("done\n");
5523 $wfh->flush();
5524
5525 } else {
5526 eval { server_wait($setup->{config_file}, $rfh) };
5527 if ($@) {
5528 warn($@);
5529 exit 1;
5530 }
5531
5532 exit 0;
5533 }
5534
5535 # Stop server
5536 server_stop($setup->{pid_file});
5537 $self->assert_child_ok($pid);
5538
5539 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5540 # are properly populated
5541 eval {
5542 if (open(my $fh, "< $ext_log")) {
5543 my $ok = 0;
5544
5545 while (my $line = <$fh>) {
5546 chomp($line);
5547
5548 if ($ENV{TEST_VERBOSE}) {
5549 print STDERR "# ExtendedLog: $line\n";
5550 }
5551
5552 if ($line =~ /^\S+ (\S+) (\S+) (.*?) (\d+) (\d+)$/) {
5553 my $local_addr = $1;
5554 my $cmd = $2;
5555 my $resp = $3;
5556 my $bytes_in = $4;
5557 my $bytes_out = $5;
5558
5559 # Only watch for the EXIT command, to get the session total.
5560 next unless $cmd eq 'EXIT';
5561
5562 my $expected = '127.0.0.1';
5563 $self->assert($expected eq $local_addr,
5564 "Expected %L value $expected, got $local_addr");
5565
5566 $expected = 108;
5567 $self->assert($expected == $bytes_in,
5568 "Expected $expected, got $bytes_in");
5569
5570 # Why would this number vary so widely? It's because of the notation
5571 # used to express the port number in a PASV response. That port
5572 # number is ephemeral, chosen by the kernel.
5573
5574 my $expected_min = 232;
5575 my $expected_max = 286;
5576 $self->assert($expected_min <= $bytes_out &&
5577 $expected_max >= $bytes_out,
5578 "Expected $expected_min - $expected_max, got $bytes_out");
5579
5580 $ok = 1;
5581 }
5582 }
5583
5584 close($fh);
5585 $self->assert($ok == 1, "Did not find expected ExtendedLog lines");
5586
5587 } else {
5588 die("Can't read $ext_log: $!");
5589 }
5590 };
5591 if ($@) {
5592 $ex = $@;
5593 }
5594
5595 test_cleanup($setup->{log_file}, $ex);
5596 }
5597
5598 sub extlog_eos_reason_quit {
5599 my $self = shift;
5600 my $tmpdir = $self->{tmpdir};
5601
5602 my $config_file = "$tmpdir/extlog.conf";
5603 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5604 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5605
5606 my $log_file = test_get_logfile();
5607
5608 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5609 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5610
5611 my $test_file = File::Spec->rel2abs($config_file);
5612
5613 my $user = 'proftpd';
5614 my $passwd = 'test';
5615 my $group = 'ftpd';
5616 my $home_dir = File::Spec->rel2abs($tmpdir);
5617 my $uid = 500;
5618 my $gid = 500;
5619
5620 # Make sure that, if we're running as root, that the home directory has
5621 # permissions/privs set for the account we create
5622 if ($< == 0) {
5623 unless (chmod(0755, $home_dir)) {
5624 die("Can't set perms on $home_dir to 0755: $!");
5625 }
5626
5627 unless (chown($uid, $gid, $home_dir)) {
5628 die("Can't set owner of $home_dir to $uid/$gid: $!");
5629 }
5630 }
5631
5632 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5633 '/bin/bash');
5634 auth_group_write($auth_group_file, $group, $gid, $user);
5635
5636 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5637
5638 my $config = {
5639 PidFile => $pid_file,
5640 ScoreboardFile => $scoreboard_file,
5641 SystemLog => $log_file,
5642 TraceLog => $log_file,
5643
5644 AuthUserFile => $auth_user_file,
5645 AuthGroupFile => $auth_group_file,
5646 AuthOrder => 'mod_auth_file.c',
5647
5648 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
5649 ExtendedLog => "$ext_log EXIT custom",
5650
5651 IfModules => {
5652 'mod_delay.c' => {
5653 DelayEngine => 'off',
5654 },
5655 },
5656 };
5657
5658 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5659
5660 # Open pipes, for use between the parent and child processes. Specifically,
5661 # the child will indicate when it's done with its test by writing a message
5662 # to the parent.
5663 my ($rfh, $wfh);
5664 unless (pipe($rfh, $wfh)) {
5665 die("Can't open pipe: $!");
5666 }
5667
5668 my $ex;
5669
5670 # Fork child
5671 $self->handle_sigchld();
5672 defined(my $pid = fork()) or die("Can't fork: $!");
5673 if ($pid) {
5674 eval {
5675 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5676 $client->login($user, $passwd);
5677 $client->quit();
5678 };
5679
5680 if ($@) {
5681 $ex = $@;
5682 }
5683
5684 $wfh->print("done\n");
5685 $wfh->flush();
5686
5687 } else {
5688 eval { server_wait($config_file, $rfh) };
5689 if ($@) {
5690 warn($@);
5691 exit 1;
5692 }
5693
5694 exit 0;
5695 }
5696
5697 # Stop server
5698 server_stop($pid_file);
5699
5700 $self->assert_child_ok($pid);
5701
5702 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5703 # are properly populated
5704 if (open(my $fh, "< $ext_log")) {
5705 my $ok = 0;
5706
5707 while (my $line = <$fh>) {
5708 chomp($line);
5709
5710 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
5711 my $cmd = $1;
5712 my $reason = $2;
5713
5714 # Only watch for the EXIT command, to get the end-of-session reason.
5715 next unless $cmd eq 'EXIT';
5716
5717 my $expected = "Quit";
5718 $self->assert($expected eq $reason,
5719 test_msg("Expected '$expected', got '$reason'"));
5720
5721 $ok = 1;
5722 }
5723 }
5724
5725 close($fh);
5726 $self->assert($ok == 1,
5727 test_msg("Did not find expected ExtendedLog lines"));
5728
5729 } else {
5730 die("Can't read $ext_log: $!");
5731 }
5732
5733 if ($ex) {
5734 test_append_logfile($log_file, $ex);
5735 unlink($log_file);
5736
5737 die($ex);
5738 }
5739
5740 unlink($log_file);
5741 }
5742
5743 sub extlog_eos_reason_eof {
5744 my $self = shift;
5745 my $tmpdir = $self->{tmpdir};
5746
5747 my $config_file = "$tmpdir/extlog.conf";
5748 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5749 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5750
5751 my $log_file = test_get_logfile();
5752
5753 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5754 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5755
5756 my $test_file = File::Spec->rel2abs($config_file);
5757
5758 my $user = 'proftpd';
5759 my $passwd = 'test';
5760 my $group = 'ftpd';
5761 my $home_dir = File::Spec->rel2abs($tmpdir);
5762 my $uid = 500;
5763 my $gid = 500;
5764
5765 # Make sure that, if we're running as root, that the home directory has
5766 # permissions/privs set for the account we create
5767 if ($< == 0) {
5768 unless (chmod(0755, $home_dir)) {
5769 die("Can't set perms on $home_dir to 0755: $!");
5770 }
5771
5772 unless (chown($uid, $gid, $home_dir)) {
5773 die("Can't set owner of $home_dir to $uid/$gid: $!");
5774 }
5775 }
5776
5777 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5778 '/bin/bash');
5779 auth_group_write($auth_group_file, $group, $gid, $user);
5780
5781 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5782
5783 my $config = {
5784 PidFile => $pid_file,
5785 ScoreboardFile => $scoreboard_file,
5786 SystemLog => $log_file,
5787 TraceLog => $log_file,
5788
5789 AuthUserFile => $auth_user_file,
5790 AuthGroupFile => $auth_group_file,
5791 AuthOrder => 'mod_auth_file.c',
5792
5793 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
5794 ExtendedLog => "$ext_log EXIT custom",
5795
5796 IfModules => {
5797 'mod_delay.c' => {
5798 DelayEngine => 'off',
5799 },
5800 },
5801 };
5802
5803 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5804
5805 # Open pipes, for use between the parent and child processes. Specifically,
5806 # the child will indicate when it's done with its test by writing a message
5807 # to the parent.
5808 my ($rfh, $wfh);
5809 unless (pipe($rfh, $wfh)) {
5810 die("Can't open pipe: $!");
5811 }
5812
5813 my $ex;
5814
5815 # Fork child
5816 $self->handle_sigchld();
5817 defined(my $pid = fork()) or die("Can't fork: $!");
5818 if ($pid) {
5819 eval {
5820 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5821 $client->login($user, $passwd);
5822 $client = undef;
5823 };
5824
5825 if ($@) {
5826 $ex = $@;
5827 }
5828
5829 $wfh->print("done\n");
5830 $wfh->flush();
5831
5832 } else {
5833 eval { server_wait($config_file, $rfh) };
5834 if ($@) {
5835 warn($@);
5836 exit 1;
5837 }
5838
5839 exit 0;
5840 }
5841
5842 # Stop server
5843 server_stop($pid_file);
5844
5845 $self->assert_child_ok($pid);
5846
5847 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5848 # are properly populated
5849 if (open(my $fh, "< $ext_log")) {
5850 my $ok = 0;
5851
5852 while (my $line = <$fh>) {
5853 chomp($line);
5854
5855 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
5856 my $cmd = $1;
5857 my $reason = $2;
5858
5859 # Only watch for the EXIT command, to get the end-of-session reason.
5860 next unless $cmd eq 'EXIT';
5861
5862 my $expected = "Read EOF from client";
5863 $self->assert($expected eq $reason,
5864 test_msg("Expected '$expected', got '$reason'"));
5865
5866 $ok = 1;
5867 }
5868 }
5869
5870 close($fh);
5871 $self->assert($ok == 1,
5872 test_msg("Did not find expected ExtendedLog lines"));
5873
5874 } else {
5875 die("Can't read $ext_log: $!");
5876 }
5877
5878 if ($ex) {
5879 test_append_logfile($log_file, $ex);
5880 unlink($log_file);
5881
5882 die($ex);
5883 }
5884
5885 unlink($log_file);
5886 }
5887
5888 sub extlog_eos_reason_timeoutidle {
5889 my $self = shift;
5890 my $tmpdir = $self->{tmpdir};
5891
5892 my $config_file = "$tmpdir/extlog.conf";
5893 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5894 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5895
5896 my $log_file = test_get_logfile();
5897
5898 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5899 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5900
5901 my $test_file = File::Spec->rel2abs($config_file);
5902
5903 my $user = 'proftpd';
5904 my $passwd = 'test';
5905 my $group = 'ftpd';
5906 my $home_dir = File::Spec->rel2abs($tmpdir);
5907 my $uid = 500;
5908 my $gid = 500;
5909
5910 # Make sure that, if we're running as root, that the home directory has
5911 # permissions/privs set for the account we create
5912 if ($< == 0) {
5913 unless (chmod(0755, $home_dir)) {
5914 die("Can't set perms on $home_dir to 0755: $!");
5915 }
5916
5917 unless (chown($uid, $gid, $home_dir)) {
5918 die("Can't set owner of $home_dir to $uid/$gid: $!");
5919 }
5920 }
5921
5922 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5923 '/bin/bash');
5924 auth_group_write($auth_group_file, $group, $gid, $user);
5925
5926 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5927
5928 my $timeout_idle = 3;
5929
5930 my $config = {
5931 PidFile => $pid_file,
5932 ScoreboardFile => $scoreboard_file,
5933 SystemLog => $log_file,
5934 TraceLog => $log_file,
5935
5936 AuthUserFile => $auth_user_file,
5937 AuthGroupFile => $auth_group_file,
5938 AuthOrder => 'mod_auth_file.c',
5939
5940 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
5941 ExtendedLog => "$ext_log EXIT custom",
5942 TimeoutIdle => $timeout_idle,
5943
5944 IfModules => {
5945 'mod_delay.c' => {
5946 DelayEngine => 'off',
5947 },
5948 },
5949 };
5950
5951 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5952
5953 # Open pipes, for use between the parent and child processes. Specifically,
5954 # the child will indicate when it's done with its test by writing a message
5955 # to the parent.
5956 my ($rfh, $wfh);
5957 unless (pipe($rfh, $wfh)) {
5958 die("Can't open pipe: $!");
5959 }
5960
5961 my $ex;
5962
5963 # Fork child
5964 $self->handle_sigchld();
5965 defined(my $pid = fork()) or die("Can't fork: $!");
5966 if ($pid) {
5967 eval {
5968 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5969 $client->login($user, $passwd);
5970
5971 sleep($timeout_idle + 2);
5972
5973 $client->quit();
5974 };
5975
5976 if ($@) {
5977 $ex = $@;
5978 }
5979
5980 $wfh->print("done\n");
5981 $wfh->flush();
5982
5983 } else {
5984 eval { server_wait($config_file, $rfh) };
5985 if ($@) {
5986 warn($@);
5987 exit 1;
5988 }
5989
5990 exit 0;
5991 }
5992
5993 # Stop server
5994 server_stop($pid_file);
5995
5996 $self->assert_child_ok($pid);
5997
5998 # Now, read in the ExtendedLog, and see whether the %I/%O variables
5999 # are properly populated
6000 if (open(my $fh, "< $ext_log")) {
6001 my $ok = 0;
6002
6003 while (my $line = <$fh>) {
6004 chomp($line);
6005
6006 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
6007 my $cmd = $1;
6008 my $reason = $2;
6009
6010 # Only watch for the EXIT command, to get the end-of-session reason.
6011 next unless $cmd eq 'EXIT';
6012
6013 my $expected = "Timeout exceeded: TimeoutIdle";
6014 $self->assert($expected eq $reason,
6015 test_msg("Expected '$expected', got '$reason'"));
6016
6017 $ok = 1;
6018 }
6019 }
6020
6021 close($fh);
6022 $self->assert($ok == 1,
6023 test_msg("Did not find expected ExtendedLog lines"));
6024
6025 } else {
6026 die("Can't read $ext_log: $!");
6027 }
6028
6029 if ($ex) {
6030 test_append_logfile($log_file, $ex);
6031 unlink($log_file);
6032
6033 die($ex);
6034 }
6035
6036 unlink($log_file);
6037 }
6038
6039 sub extlog_eos_reason_timeoutlogin {
6040 my $self = shift;
6041 my $tmpdir = $self->{tmpdir};
6042
6043 my $config_file = "$tmpdir/extlog.conf";
6044 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
6045 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
6046
6047 my $log_file = test_get_logfile();
6048
6049 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
6050 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
6051
6052 my $test_file = File::Spec->rel2abs($config_file);
6053
6054 my $user = 'proftpd';
6055 my $passwd = 'test';
6056 my $group = 'ftpd';
6057 my $home_dir = File::Spec->rel2abs($tmpdir);
6058 my $uid = 500;
6059 my $gid = 500;
6060
6061 # Make sure that, if we're running as root, that the home directory has
6062 # permissions/privs set for the account we create
6063 if ($< == 0) {
6064 unless (chmod(0755, $home_dir)) {
6065 die("Can't set perms on $home_dir to 0755: $!");
6066 }
6067
6068 unless (chown($uid, $gid, $home_dir)) {
6069 die("Can't set owner of $home_dir to $uid/$gid: $!");
6070 }
6071 }
6072
6073 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6074 '/bin/bash');
6075 auth_group_write($auth_group_file, $group, $gid, $user);
6076
6077 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6078
6079 my $timeout_login = 3;
6080
6081 my $config = {
6082 PidFile => $pid_file,
6083 ScoreboardFile => $scoreboard_file,
6084 SystemLog => $log_file,
6085 TraceLog => $log_file,
6086
6087 AuthUserFile => $auth_user_file,
6088 AuthGroupFile => $auth_group_file,
6089 AuthOrder => 'mod_auth_file.c',
6090
6091 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
6092 ExtendedLog => "$ext_log EXIT custom",
6093 TimeoutLogin => $timeout_login,
6094
6095 IfModules => {
6096 'mod_delay.c' => {
6097 DelayEngine => 'off',
6098 },
6099 },
6100 };
6101
6102 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6103
6104 # Open pipes, for use between the parent and child processes. Specifically,
6105 # the child will indicate when it's done with its test by writing a message
6106 # to the parent.
6107 my ($rfh, $wfh);
6108 unless (pipe($rfh, $wfh)) {
6109 die("Can't open pipe: $!");
6110 }
6111
6112 my $ex;
6113
6114 # Fork child
6115 $self->handle_sigchld();
6116 defined(my $pid = fork()) or die("Can't fork: $!");
6117 if ($pid) {
6118 eval {
6119 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6120 sleep($timeout_login + 2);
6121
6122 eval { $client->login($user, $passwd) };
6123 unless ($@) {
6124 die("Login succeeded unexpectedly");
6125 }
6126 };
6127
6128 if ($@) {
6129 $ex = $@;
6130 }
6131
6132 $wfh->print("done\n");
6133 $wfh->flush();
6134
6135 } else {
6136 eval { server_wait($config_file, $rfh) };
6137 if ($@) {
6138 warn($@);
6139 exit 1;
6140 }
6141
6142 exit 0;
6143 }
6144
6145 # Stop server
6146 server_stop($pid_file);
6147
6148 $self->assert_child_ok($pid);
6149
6150 # Now, read in the ExtendedLog, and see whether the %I/%O variables
6151 # are properly populated
6152 if (open(my $fh, "< $ext_log")) {
6153 my $ok = 0;
6154
6155 while (my $line = <$fh>) {
6156 chomp($line);
6157
6158 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
6159 my $cmd = $1;
6160 my $reason = $2;
6161
6162 # Only watch for the EXIT command, to get the end-of-session reason.
6163 next unless $cmd eq 'EXIT';
6164
6165 my $expected = "Timeout exceeded: TimeoutLogin";
6166 $self->assert($expected eq $reason,
6167 test_msg("Expected '$expected', got '$reason'"));
6168
6169 $ok = 1;
6170 }
6171 }
6172
6173 close($fh);
6174 $self->assert($ok == 1,
6175 test_msg("Did not find expected ExtendedLog lines"));
6176
6177 } else {
6178 die("Can't read $ext_log: $!");
6179 }
6180
6181 if ($ex) {
6182 test_append_logfile($log_file, $ex);
6183 unlink($log_file);
6184
6185 die($ex);
6186 }
6187
6188 unlink($log_file);
6189 }
6190
6191 sub extlog_eos_reason_timeoutnotransfer {
6192 my $self = shift;
6193 my $tmpdir = $self->{tmpdir};
6194
6195 my $config_file = "$tmpdir/extlog.conf";
6196 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
6197 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
6198
6199 my $log_file = test_get_logfile();
6200
6201 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
6202 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
6203
6204 my $test_file = File::Spec->rel2abs($config_file);
6205
6206 my $user = 'proftpd';
6207 my $passwd = 'test';
6208 my $group = 'ftpd';
6209 my $home_dir = File::Spec->rel2abs($tmpdir);
6210 my $uid = 500;
6211 my $gid = 500;
6212
6213 # Make sure that, if we're running as root, that the home directory has
6214 # permissions/privs set for the account we create
6215 if ($< == 0) {
6216 unless (chmod(0755, $home_dir)) {
6217 die("Can't set perms on $home_dir to 0755: $!");
6218 }
6219
6220 unless (chown($uid, $gid, $home_dir)) {
6221 die("Can't set owner of $home_dir to $uid/$gid: $!");
6222 }
6223 }
6224
6225 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6226 '/bin/bash');
6227 auth_group_write($auth_group_file, $group, $gid, $user);
6228
6229 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6230
6231 my $timeout_noxfer = 2;
6232
6233 my $config = {
6234 PidFile => $pid_file,
6235 ScoreboardFile => $scoreboard_file,
6236 SystemLog => $log_file,
6237 TraceLog => $log_file,
6238
6239 AuthUserFile => $auth_user_file,
6240 AuthGroupFile => $auth_group_file,
6241 AuthOrder => 'mod_auth_file.c',
6242
6243 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
6244 ExtendedLog => "$ext_log EXIT custom",
6245 TimeoutNoTransfer => $timeout_noxfer,
6246
6247 IfModules => {
6248 'mod_delay.c' => {
6249 DelayEngine => 'off',
6250 },
6251 },
6252 };
6253
6254 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6255
6256 # Open pipes, for use between the parent and child processes. Specifically,
6257 # the child will indicate when it's done with its test by writing a message
6258 # to the parent.
6259 my ($rfh, $wfh);
6260 unless (pipe($rfh, $wfh)) {
6261 die("Can't open pipe: $!");
6262 }
6263
6264 my $ex;
6265
6266 # Fork child
6267 $self->handle_sigchld();
6268 defined(my $pid = fork()) or die("Can't fork: $!");
6269 if ($pid) {
6270 eval {
6271 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6272 $client->login($user, $passwd);
6273
6274 # Wait for one second more than the no-transfer period
6275 sleep($timeout_noxfer + 1);
6276
6277 my $conn = $client->list_raw($home_dir);
6278 if ($conn) {
6279 die("LIST succeeded unexpectedly");
6280 }
6281
6282 my $resp_code = $client->response_code();
6283 my $resp_msg = $client->response_msg();
6284
6285 my $expected;
6286
6287 $expected = 421;
6288 $self->assert($expected == $resp_code,
6289 test_msg("Expected $expected, got $resp_code"));
6290
6291 $expected = "No transfer timeout ($timeout_noxfer seconds): closing control connection";
6292 $self->assert($expected eq $resp_msg,
6293 test_msg("Expected '$expected', got '$resp_msg'"));
6294 };
6295
6296 if ($@) {
6297 $ex = $@;
6298 }
6299
6300 $wfh->print("done\n");
6301 $wfh->flush();
6302
6303 } else {
6304 eval { server_wait($config_file, $rfh) };
6305 if ($@) {
6306 warn($@);
6307 exit 1;
6308 }
6309
6310 exit 0;
6311 }
6312
6313 # Stop server
6314 server_stop($pid_file);
6315
6316 $self->assert_child_ok($pid);
6317
6318 # Now, read in the ExtendedLog, and see whether the %I/%O variables
6319 # are properly populated
6320 if (open(my $fh, "< $ext_log")) {
6321 my $ok = 0;
6322
6323 while (my $line = <$fh>) {
6324 chomp($line);
6325
6326 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
6327 my $cmd = $1;
6328 my $reason = $2;
6329
6330 # Only watch for the EXIT command, to get the end-of-session reason.
6331 next unless $cmd eq 'EXIT';
6332
6333 my $expected = "Timeout exceeded: TimeoutNoTransfer";
6334 $self->assert($expected eq $reason,
6335 test_msg("Expected '$expected', got '$reason'"));
6336
6337 $ok = 1;
6338 }
6339 }
6340
6341 close($fh);
6342 $self->assert($ok == 1,
6343 test_msg("Did not find expected ExtendedLog lines"));
6344
6345 } else {
6346 die("Can't read $ext_log: $!");
6347 }
6348
6349 if ($ex) {
6350 test_append_logfile($log_file, $ex);
6351 unlink($log_file);
6352
6353 die($ex);
6354 }
6355
6356 unlink($log_file);
6357 }
6358
6359 sub extlog_eos_reason_timeoutsession {
6360 my $self = shift;
6361 my $tmpdir = $self->{tmpdir};
6362
6363 my $config_file = "$tmpdir/extlog.conf";
6364 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
6365 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
6366
6367 my $log_file = test_get_logfile();
6368
6369 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
6370 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
6371
6372 my $test_file = File::Spec->rel2abs($config_file);
6373
6374 my $user = 'proftpd';
6375 my $passwd = 'test';
6376 my $group = 'ftpd';
6377 my $home_dir = File::Spec->rel2abs($tmpdir);
6378 my $uid = 500;
6379 my $gid = 500;
6380
6381 # Make sure that, if we're running as root, that the home directory has
6382 # permissions/privs set for the account we create
6383 if ($< == 0) {
6384 unless (chmod(0755, $home_dir)) {
6385 die("Can't set perms on $home_dir to 0755: $!");
6386 }
6387
6388 unless (chown($uid, $gid, $home_dir)) {
6389 die("Can't set owner of $home_dir to $uid/$gid: $!");
6390 }
6391 }
6392
6393 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6394 '/bin/bash');
6395 auth_group_write($auth_group_file, $group, $gid, $user);
6396
6397 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6398
6399 my $timeout_session = 2;
6400
6401 my $config = {
6402 PidFile => $pid_file,
6403 ScoreboardFile => $scoreboard_file,
6404 SystemLog => $log_file,
6405 TraceLog => $log_file,
6406
6407 AuthUserFile => $auth_user_file,
6408 AuthGroupFile => $auth_group_file,
6409 AuthOrder => 'mod_auth_file.c',
6410
6411 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
6412 ExtendedLog => "$ext_log EXIT custom",
6413 TimeoutSession => $timeout_session,
6414
6415 IfModules => {
6416 'mod_delay.c' => {
6417 DelayEngine => 'off',
6418 },
6419 },
6420 };
6421
6422 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6423
6424 # Open pipes, for use between the parent and child processes. Specifically,
6425 # the child will indicate when it's done with its test by writing a message
6426 # to the parent.
6427 my ($rfh, $wfh);
6428 unless (pipe($rfh, $wfh)) {
6429 die("Can't open pipe: $!");
6430 }
6431
6432 my $ex;
6433
6434 # Fork child
6435 $self->handle_sigchld();
6436 defined(my $pid = fork()) or die("Can't fork: $!");
6437 if ($pid) {
6438 eval {
6439 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6440 $client->login($user, $passwd);
6441
6442 # Wait for one second more than the session lifetime
6443 sleep($timeout_session + 1);
6444
6445 $client->quit();
6446 };
6447
6448 if ($@) {
6449 $ex = $@;
6450 }
6451
6452 $wfh->print("done\n");
6453 $wfh->flush();
6454
6455 } else {
6456 eval { server_wait($config_file, $rfh) };
6457 if ($@) {
6458 warn($@);
6459 exit 1;
6460 }
6461
6462 exit 0;
6463 }
6464
6465 # Stop server
6466 server_stop($pid_file);
6467
6468 $self->assert_child_ok($pid);
6469
6470 # Now, read in the ExtendedLog, and see whether the %I/%O variables
6471 # are properly populated
6472 if (open(my $fh, "< $ext_log")) {
6473 my $ok = 0;
6474
6475 while (my $line = <$fh>) {
6476 chomp($line);
6477
6478 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
6479 my $cmd = $1;
6480 my $reason = $2;
6481
6482 # Only watch for the EXIT command, to get the end-of-session reason.
6483 next unless $cmd eq 'EXIT';
6484
6485 my $expected = "Timeout exceeded: TimeoutSession";
6486 $self->assert($expected eq $reason,
6487 test_msg("Expected '$expected', got '$reason'"));
6488
6489 $ok = 1;
6490 }
6491 }
6492
6493 close($fh);
6494 $self->assert($ok == 1,
6495 test_msg("Did not find expected ExtendedLog lines"));
6496
6497 } else {
6498 die("Can't read $ext_log: $!");
6499 }
6500
6501 if ($ex) {
6502 test_append_logfile($log_file, $ex);
6503 unlink($log_file);
6504
6505 die($ex);
6506 }
6507
6508 unlink($log_file);
6509 }
6510
6511 sub extlog_eos_reason_timeoutstalled {
6512 my $self = shift;
6513 my $tmpdir = $self->{tmpdir};
6514 my $setup = test_setup($tmpdir, 'extlog');
6515
6516 my $test_file = File::Spec->rel2abs($setup->{config_file});
6517 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6518
6519 my $timeout_stalled = 1;
6520
6521 my $config = {
6522 PidFile => $setup->{pid_file},
6523 ScoreboardFile => $setup->{scoreboard_file},
6524 SystemLog => $setup->{log_file},
6525 TraceLog => $setup->{log_file},
6526 Trace => 'response:10',
6527
6528 AuthUserFile => $setup->{auth_user_file},
6529 AuthGroupFile => $setup->{auth_group_file},
6530 AuthOrder => 'mod_auth_file.c',
6531
6532 LogFormat => 'custom "%{protocol} %m eos_reason=\"%E\""',
6533 ExtendedLog => "$ext_log EXIT custom",
6534 TimeoutStalled => $timeout_stalled,
6535
6536 IfModules => {
6537 'mod_delay.c' => {
6538 DelayEngine => 'off',
6539 },
6540 },
6541 };
6542
6543 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6544 $config);
6545
6546 # Open pipes, for use between the parent and child processes. Specifically,
6547 # the child will indicate when it's done with its test by writing a message
6548 # to the parent.
6549 my ($rfh, $wfh);
6550 unless (pipe($rfh, $wfh)) {
6551 die("Can't open pipe: $!");
6552 }
6553
6554 my $ex;
6555
6556 # Fork child
6557 $self->handle_sigchld();
6558 defined(my $pid = fork()) or die("Can't fork: $!");
6559 if ($pid) {
6560 eval {
6561 # Allow for server startup
6562 sleep(1);
6563
6564 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6565 $client->login($setup->{user}, $setup->{passwd});
6566
6567 my $conn = $client->list_raw('.');
6568 unless ($conn) {
6569 die("LIST failed: " . $client->response_code() . " " .
6570 $client->response_msg());
6571 }
6572
6573 # Wait for one second more than the stalled period
6574 sleep($timeout_stalled + 1);
6575
6576 my $buf;
6577 $conn->read($buf, 8192, 25);
6578 eval { $conn->close() };
6579
6580 eval { $client->noop() };
6581 unless ($@) {
6582 die("NOOP succeeded unexpectedly");
6583 }
6584
6585 my $resp_code = $client->response_code();
6586 my $resp_msg = $client->response_msg();
6587
6588 # Perl's Net::Cmd module uses a very non-standard 599 code to
6589 # indicate that the connection is closed, depending on version.
6590 $self->assert($resp_code == 421 || $resp_code == 599,
6591 test_msg("Expected response code 421 or 599, got $resp_code"));
6592
6593 my $expected = "Connection closed";
6594 $self->assert(qr/$expected/, $resp_msg,
6595 test_msg("Expected response message '$expected', got '$resp_msg'"));
6596 };
6597 if ($@) {
6598 $ex = $@;
6599 }
6600
6601 $wfh->print("done\n");
6602 $wfh->flush();
6603
6604 } else {
6605 eval { server_wait($setup->{config_file}, $rfh) };
6606 if ($@) {
6607 warn($@);
6608 exit 1;
6609 }
6610
6611 exit 0;
6612 }
6613
6614 # Stop server
6615 server_stop($setup->{pid_file});
6616 $self->assert_child_ok($pid);
6617
6618 # Now, read in the ExtendedLog, and see whether the %E variable is
6619 # properly populated
6620 eval {
6621 if (open(my $fh, "< $ext_log")) {
6622 my $ok = 0;
6623
6624 while (my $line = <$fh>) {
6625 chomp($line);
6626
6627 if ($ENV{TEST_VERBOSE}) {
6628 print STDERR "# $line\n";
6629 }
6630
6631 if ($line =~ /^\S+ (\S+) eos_reason="(.*?)"/) {
6632 my $cmd = $1;
6633 my $reason = $2;
6634
6635 # Only watch for the EXIT command, to get the end-of-session reason.
6636 next unless $cmd eq 'EXIT';
6637
6638 my $expected = "TimeoutStalled during data transfer";
6639 $self->assert(qr/$expected/, $reason,
6640 test_msg("Expected failure reason '$expected', got '$reason'"));
6641
6642 $ok = 1;
6643 }
6644 }
6645
6646 close($fh);
6647 $self->assert($ok == 1,
6648 test_msg("Did not find expected ExtendedLog lines"));
6649
6650 } else {
6651 die("Can't read $ext_log: $!");
6652 }
6653 };
6654 if ($@) {
6655 $ex = $@;
6656 }
6657
6658 test_cleanup($setup->{log_file}, $ex);
6659 }
6660
6661 sub extlog_vars_H_L_matching_server_bug3620 {
6662 my $self = shift;
6663 my $tmpdir = $self->{tmpdir};
6664
6665 my $config_file = "$tmpdir/extlog.conf";
6666 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
6667 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
6668
6669 my $log_file = test_get_logfile();
6670
6671 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
6672 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
6673
6674 my $user = 'proftpd';
6675 my $passwd = 'test';
6676 my $group = 'ftpd';
6677 my $home_dir = File::Spec->rel2abs($tmpdir);
6678 my $uid = 500;
6679 my $gid = 500;
6680
6681 # Make sure that, if we're running as root, that the home directory has
6682 # permissions/privs set for the account we create
6683 if ($< == 0) {
6684 unless (chmod(0755, $home_dir)) {
6685 die("Can't set perms on $home_dir to 0755: $!");
6686 }
6687
6688 unless (chown($uid, $gid, $home_dir)) {
6689 die("Can't set owner of $home_dir to $uid/$gid: $!");
6690 }
6691 }
6692
6693 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6694 '/bin/bash');
6695 auth_group_write($auth_group_file, $group, $gid, $user);
6696
6697 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6698
6699 my $config = {
6700 PidFile => $pid_file,
6701 ScoreboardFile => $scoreboard_file,
6702 SystemLog => $log_file,
6703
6704 AuthUserFile => $auth_user_file,
6705 AuthGroupFile => $auth_group_file,
6706 AuthOrder => 'mod_auth_file.c',
6707
6708 LogFormat => 'custom "%L %H"',
6709 ExtendedLog => "$ext_log AUTH custom",
6710
6711 IfModules => {
6712 'mod_delay.c' => {
6713 DelayEngine => 'off',
6714 },
6715 },
6716 };
6717
6718 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6719
6720 # Open pipes, for use between the parent and child processes. Specifically,
6721 # the child will indicate when it's done with its test by writing a message
6722 # to the parent.
6723 my ($rfh, $wfh);
6724 unless (pipe($rfh, $wfh)) {
6725 die("Can't open pipe: $!");
6726 }
6727
6728 my $ex;
6729
6730 # Fork child
6731 $self->handle_sigchld();
6732 defined(my $pid = fork()) or die("Can't fork: $!");
6733 if ($pid) {
6734 eval {
6735 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6736 $client->login($user, $passwd);
6737 $client->quit();
6738 };
6739
6740 if ($@) {
6741 $ex = $@;
6742 }
6743
6744 $wfh->print("done\n");
6745 $wfh->flush();
6746
6747 } else {
6748 eval { server_wait($config_file, $rfh) };
6749 if ($@) {
6750 warn($@);
6751 exit 1;
6752 }
6753
6754 exit 0;
6755 }
6756
6757 # Stop server
6758 server_stop($pid_file);
6759
6760 $self->assert_child_ok($pid);
6761
6762 # Now, read in the ExtendedLog, and see what values the %L and %H
6763 # variables have.
6764 if (open(my $fh, "< $ext_log")) {
6765 my $ok = 0;
6766
6767 while (my $line = <$fh>) {
6768 chomp($line);
6769
6770 if ($line =~ /^(\S+)\s+(\S+)$/) {
6771 my $conn_addr = $1;
6772 my $sess_server_addr = $2;
6773
6774 $self->assert($conn_addr eq '127.0.0.1',
6775 test_msg("Expected %L value of '127.0.0.1', got '$conn_addr'"));
6776
6777 $self->assert($sess_server_addr eq '127.0.0.1',
6778 test_msg("Expected %H value of '127.0.0.1', got '$sess_server_addr'"));
6779
6780 $ok = 1;
6781 }
6782 }
6783
6784 close($fh);
6785
6786 $self->assert($ok, test_msg("Expected ExtendedLog lines not found"));
6787
6788 } else {
6789 die("Can't read $ext_log: $!");
6790 }
6791
6792 if ($ex) {
6793 test_append_logfile($log_file, $ex);
6794 unlink($log_file);
6795
6796 die($ex);
6797 }
6798
6799 unlink($log_file);
6800 }
6801
6802 sub extlog_vars_H_L_default_server_bug3620 {
6803 my $self = shift;
6804 my $tmpdir = $self->{tmpdir};
6805 my $setup = test_setup($tmpdir, 'extlog');
6806
6807 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6808
6809 my $config = {
6810 PidFile => $setup->{pid_file},
6811 ScoreboardFile => $setup->{scoreboard_file},
6812 SystemLog => $setup->{log_file},
6813
6814 AuthUserFile => $setup->{auth_user_file},
6815 AuthGroupFile => $setup->{auth_group_file},
6816 AuthOrder => 'mod_auth_file.c',
6817
6818 DefaultServer => 'off',
6819 SocketBindTight => 'off',
6820 LogFormat => 'custom "%L %H"',
6821 ExtendedLog => "$ext_log AUTH custom",
6822 Port => '0',
6823
6824 IfModules => {
6825 'mod_delay.c' => {
6826 DelayEngine => 'off',
6827 },
6828 },
6829 };
6830
6831 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6832 $config);
6833
6834 my $real_addr = Net::Address::IP::Local->public_ipv4;
6835 my $real_port = ProFTPD::TestSuite::Utils::get_high_numbered_port();
6836 my $vhost_addr = '0.0.0.0';
6837
6838 if (open(my $fh, ">> $setup->{config_file}")) {
6839 print $fh <<EOC;
6840
6841 <VirtualHost $vhost_addr>
6842 ServerName "DefaultServer VHost"
6843 Port $real_port
6844 DefaultServer on
6845
6846 AuthUserFile $setup->{auth_user_file}
6847 AuthGroupFile $setup->{auth_group_file}
6848 AuthOrder mod_auth_file.c
6849
6850 RequireValidShell off
6851 WtmpLog off
6852
6853 ExtendedLog $ext_log AUTH custom
6854 </VirtualHost>
6855 EOC
6856 unless (close($fh)) {
6857 die("Can't write $setup->{config_file}: $!");
6858 }
6859
6860 } else {
6861 die("Can't open $setup->{config_file}: $!");
6862 }
6863
6864 # Open pipes, for use between the parent and child processes. Specifically,
6865 # the child will indicate when it's done with its test by writing a message
6866 # to the parent.
6867 my ($rfh, $wfh);
6868 unless (pipe($rfh, $wfh)) {
6869 die("Can't open pipe: $!");
6870 }
6871
6872 my $ex;
6873
6874 # Fork child
6875 $self->handle_sigchld();
6876 defined(my $pid = fork()) or die("Can't fork: $!");
6877 if ($pid) {
6878 eval {
6879 my $client = ProFTPD::TestSuite::FTP->new($real_addr, $real_port);
6880 $client->login($setup->{user}, $setup->{passwd});
6881 $client->quit();
6882 };
6883 if ($@) {
6884 $ex = $@;
6885 }
6886
6887 $wfh->print("done\n");
6888 $wfh->flush();
6889
6890 } else {
6891 eval { server_wait($setup->{config_file}, $rfh) };
6892 if ($@) {
6893 warn($@);
6894 exit 1;
6895 }
6896
6897 exit 0;
6898 }
6899
6900 # Stop server
6901 server_stop($setup->{pid_file});
6902 $self->assert_child_ok($pid);
6903
6904 eval {
6905 # Now, read in the ExtendedLog, and see what values the %L and %H
6906 # variables have.
6907 if (open(my $fh, "< $ext_log")) {
6908 my $ok = 0;
6909
6910 while (my $line = <$fh>) {
6911 chomp($line);
6912
6913 if ($line =~ /^(\S+)\s+(\S+)$/) {
6914 my $conn_addr = $1;
6915 my $sess_server_addr = $2;
6916
6917 $self->assert($conn_addr eq $real_addr,
6918 "Expected %L value of '$real_addr', got '$conn_addr'");
6919
6920 $self->assert($sess_server_addr eq $vhost_addr,
6921 "Expected %H value of '$vhost_addr', got '$sess_server_addr'");
6922
6923 $ok = 1;
6924 }
6925 }
6926
6927 close($fh);
6928 $self->assert($ok, "Expected ExtendedLog lines not found");
6929
6930 } else {
6931 die("Can't read $ext_log: $!");
6932 }
6933 };
6934 if ($@) {
6935 $ex = $@;
6936 }
6937
6938 test_cleanup($setup->{log_file}, $ex);
6939 }
6940
6941 sub extlog_user_pass {
6942 my $self = shift;
6943 my $tmpdir = $self->{tmpdir};
6944
6945 my $config_file = "$tmpdir/extlog.conf";
6946 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
6947 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
6948
6949 my $log_file = test_get_logfile();
6950
6951 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
6952 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
6953
6954 my $test_file = File::Spec->rel2abs($config_file);
6955
6956 my $user = 'proftpd';
6957 my $passwd = 'test';
6958 my $group = 'ftpd';
6959 my $home_dir = File::Spec->rel2abs($tmpdir);
6960 my $uid = 500;
6961 my $gid = 500;
6962
6963 # Make sure that, if we're running as root, that the home directory has
6964 # permissions/privs set for the account we create
6965 if ($< == 0) {
6966 unless (chmod(0755, $home_dir)) {
6967 die("Can't set perms on $home_dir to 0755: $!");
6968 }
6969
6970 unless (chown($uid, $gid, $home_dir)) {
6971 die("Can't set owner of $home_dir to $uid/$gid: $!");
6972 }
6973 }
6974
6975 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6976 '/bin/bash');
6977 auth_group_write($auth_group_file, $group, $gid, $user);
6978
6979 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
6980
6981 my $config = {
6982 PidFile => $pid_file,
6983 ScoreboardFile => $scoreboard_file,
6984 SystemLog => $log_file,
6985
6986 AuthUserFile => $auth_user_file,
6987 AuthGroupFile => $auth_group_file,
6988 AuthOrder => 'mod_auth_file.c',
6989
6990 LogFormat => 'custom "%m: %U %A"',
6991 ExtendedLog => "$ext_log AUTH custom",
6992
6993 IfModules => {
6994 'mod_delay.c' => {
6995 DelayEngine => 'off',
6996 },
6997 },
6998 };
6999
7000 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7001
7002 # Open pipes, for use between the parent and child processes. Specifically,
7003 # the child will indicate when it's done with its test by writing a message
7004 # to the parent.
7005 my ($rfh, $wfh);
7006 unless (pipe($rfh, $wfh)) {
7007 die("Can't open pipe: $!");
7008 }
7009
7010 my $ex;
7011
7012 # Fork child
7013 $self->handle_sigchld();
7014 defined(my $pid = fork()) or die("Can't fork: $!");
7015 if ($pid) {
7016 eval {
7017 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7018 $client->login($user, $passwd);
7019 $client->quit();
7020 };
7021
7022 if ($@) {
7023 $ex = $@;
7024 }
7025
7026 $wfh->print("done\n");
7027 $wfh->flush();
7028
7029 } else {
7030 eval { server_wait($config_file, $rfh) };
7031 if ($@) {
7032 warn($@);
7033 exit 1;
7034 }
7035
7036 exit 0;
7037 }
7038
7039 # Stop server
7040 server_stop($pid_file);
7041
7042 $self->assert_child_ok($pid);
7043
7044 # Now, read in the ExtendedLog, and see whether the %U and %A variables were
7045 # properly written out.
7046 if (open(my $fh, "< $ext_log")) {
7047 my $ok = 0;
7048
7049 while (my $line = <$fh>) {
7050 chomp($line);
7051
7052 if ($line =~ /(\S+): (\S+) (\S+)$/) {
7053 my $cmd = $1;
7054 my $log_user = $2;
7055 my $log_pass = $3;
7056
7057 if ($cmd eq 'PASS') {
7058 $self->assert($user eq $log_user,
7059 test_msg("Expected '$user', got '$log_user'"));
7060
7061 my $expected = 'UNKNOWN';
7062 $self->assert($expected eq $log_pass,
7063 test_msg("Expected '$expected', got '$log_pass'"));
7064
7065 $ok = 1;
7066 }
7067 }
7068 }
7069
7070 close($fh);
7071
7072 $self->assert($ok, test_msg("Expected ExtendedLog lines not found"));
7073
7074 } else {
7075 die("Can't read $ext_log: $!");
7076 }
7077
7078 if ($ex) {
7079 test_append_logfile($log_file, $ex);
7080 unlink($log_file);
7081
7082 die($ex);
7083 }
7084
7085 unlink($log_file);
7086 }
7087
7088 sub extlog_anon_user_pass {
7089 my $self = shift;
7090 my $tmpdir = $self->{tmpdir};
7091
7092 my $config_file = "$tmpdir/extlog.conf";
7093 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
7094 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
7095
7096 my $log_file = test_get_logfile();
7097
7098 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
7099 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
7100
7101 my $test_file = File::Spec->rel2abs($config_file);
7102
7103 my ($config_user, $config_group) = config_get_identity();
7104 my $home_dir = File::Spec->rel2abs($tmpdir);
7105 my $uid = 500;
7106 my $gid = 500;
7107
7108 # Make sure that, if we're running as root, that the home directory has
7109 # permissions/privs set for the account we create
7110 if ($< == 0) {
7111 unless (chmod(0755, $home_dir)) {
7112 die("Can't set perms on $home_dir to 0755: $!");
7113 }
7114
7115 unless (chown($uid, $gid, $home_dir)) {
7116 die("Can't set owner of $home_dir to $uid/$gid: $!");
7117 }
7118 }
7119
7120 auth_user_write($auth_user_file, $config_user, 'foo', $uid, $gid, '/tmp',
7121 '/bin/bash');
7122 auth_group_write($auth_group_file, $config_group, $gid, $config_user);
7123
7124 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
7125
7126 my $config = {
7127 PidFile => $pid_file,
7128 ScoreboardFile => $scoreboard_file,
7129 SystemLog => $log_file,
7130
7131 AuthUserFile => $auth_user_file,
7132 AuthGroupFile => $auth_group_file,
7133 AuthOrder => 'mod_auth_file.c',
7134
7135 LogFormat => 'custom "%m: %U %A"',
7136 ExtendedLog => "$ext_log AUTH custom",
7137
7138 Anonymous => {
7139 $home_dir => {
7140 User => $config_user,
7141 Group => $config_group,
7142 UserAlias => "anonymous $config_user",
7143 RequireValidShell => 'off',
7144 },
7145 },
7146
7147 IfModules => {
7148 'mod_delay.c' => {
7149 DelayEngine => 'off',
7150 },
7151 },
7152 };
7153
7154 my ($port, $user, $group) = config_write($config_file, $config);
7155
7156 # Open pipes, for use between the parent and child processes. Specifically,
7157 # the child will indicate when it's done with its test by writing a message
7158 # to the parent.
7159 my ($rfh, $wfh);
7160 unless (pipe($rfh, $wfh)) {
7161 die("Can't open pipe: $!");
7162 }
7163
7164 my $ex;
7165
7166 my $anon_user = 'anonymous';
7167 my $anon_passwd = '[email protected]';
7168
7169 # Fork child
7170 $self->handle_sigchld();
7171 defined(my $pid = fork()) or die("Can't fork: $!");
7172 if ($pid) {
7173 eval {
7174 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7175 my ($resp_code, $resp_msg) = $client->login($anon_user, $anon_passwd);
7176
7177 my $expected;
7178
7179 $expected = 230;
7180 $self->assert($expected == $resp_code,
7181 test_msg("Expected $expected, got $resp_code"));
7182
7183 $expected = 'Anonymous access granted, restrictions apply';
7184 $self->assert($expected eq $resp_msg,
7185 test_msg("Expected '$expected', got '$resp_msg'"));
7186
7187 $client->quit();
7188 };
7189
7190 if ($@) {
7191 $ex = $@;
7192 }
7193
7194 $wfh->print("done\n");
7195 $wfh->flush();
7196
7197 } else {
7198 eval { server_wait($config_file, $rfh) };
7199 if ($@) {
7200 warn($@);
7201 exit 1;
7202 }
7203
7204 exit 0;
7205 }
7206
7207 # Stop server
7208 server_stop($pid_file);
7209
7210 $self->assert_child_ok($pid);
7211
7212 # Now, read in the ExtendedLog, and see whether the %U and %A variables were
7213 # properly written out.
7214 if (open(my $fh, "< $ext_log")) {
7215 my $ok = 0;
7216
7217 while (my $line = <$fh>) {
7218 chomp($line);
7219
7220 if ($line =~ /(\S+): (\S+) (\S+)$/) {
7221 my $cmd = $1;
7222 my $log_user = $2;
7223 my $log_pass = $3;
7224
7225 if ($cmd eq 'PASS') {
7226 $self->assert($anon_user eq $log_user,
7227 test_msg("Expected '$anon_user', got '$log_user'"));
7228
7229 $self->assert($anon_passwd eq $log_pass,
7230 test_msg("Expected '$anon_passwd', got '$log_pass'"));
7231
7232 $ok = 1;
7233 }
7234 }
7235 }
7236
7237 close($fh);
7238
7239 $self->assert($ok, test_msg("Expected ExtendedLog lines not found"));
7240
7241 } else {
7242 die("Can't read $ext_log: $!");
7243 }
7244
7245 if ($ex) {
7246 test_append_logfile($log_file, $ex);
7247 unlink($log_file);
7248
7249 die($ex);
7250 }
7251
7252 unlink($log_file);
7253 }
7254
7255 sub extlog_cmd_resp {
7256 my $self = shift;
7257 my $tmpdir = $self->{tmpdir};
7258
7259 my $config_file = "$tmpdir/extlog.conf";
7260 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
7261 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
7262
7263 my $log_file = test_get_logfile();
7264
7265 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
7266 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
7267
7268 my $test_file = File::Spec->rel2abs($config_file);
7269
7270 my $user = 'proftpd';
7271 my $passwd = 'test';
7272 my $group = 'ftpd';
7273 my $home_dir = File::Spec->rel2abs($tmpdir);
7274 my $uid = 500;
7275 my $gid = 500;
7276
7277 # Make sure that, if we're running as root, that the home directory has
7278 # permissions/privs set for the account we create
7279 if ($< == 0) {
7280 unless (chmod(0755, $home_dir)) {
7281 die("Can't set perms on $home_dir to 0755: $!");
7282 }
7283
7284 unless (chown($uid, $gid, $home_dir)) {
7285 die("Can't set owner of $home_dir to $uid/$gid: $!");
7286 }
7287 }
7288
7289 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7290 '/bin/bash');
7291 auth_group_write($auth_group_file, $group, $gid, $user);
7292
7293 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
7294
7295 my $config = {
7296 PidFile => $pid_file,
7297 ScoreboardFile => $scoreboard_file,
7298 SystemLog => $log_file,
7299
7300 AuthUserFile => $auth_user_file,
7301 AuthGroupFile => $auth_group_file,
7302 AuthOrder => 'mod_auth_file.c',
7303
7304 LogFormat => 'custom "%m %J [%r] = %s %S"',
7305 ExtendedLog => "$ext_log ALL custom",
7306
7307 IfModules => {
7308 'mod_delay.c' => {
7309 DelayEngine => 'off',
7310 },
7311 },
7312 };
7313
7314 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7315
7316 # Open pipes, for use between the parent and child processes. Specifically,
7317 # the child will indicate when it's done with its test by writing a message
7318 # to the parent.
7319 my ($rfh, $wfh);
7320 unless (pipe($rfh, $wfh)) {
7321 die("Can't open pipe: $!");
7322 }
7323
7324 my $ex;
7325
7326 # Fork child
7327 $self->handle_sigchld();
7328 defined(my $pid = fork()) or die("Can't fork: $!");
7329 if ($pid) {
7330 eval {
7331 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7332 $client->login($user, $passwd);
7333
7334 my $conn = $client->retr_raw($test_file);
7335 unless ($conn) {
7336 die("Failed to RETR: " . $client->response_code() . " " .
7337 $client->response_msg());
7338 }
7339
7340 my $buf;
7341 $conn->read($buf, 8192, 25);
7342 eval { $conn->close() };
7343
7344 $client->quit();
7345 };
7346
7347 if ($@) {
7348 $ex = $@;
7349 }
7350
7351 $wfh->print("done\n");
7352 $wfh->flush();
7353
7354 } else {
7355 eval { server_wait($config_file, $rfh) };
7356 if ($@) {
7357 warn($@);
7358 exit 1;
7359 }
7360
7361 exit 0;
7362 }
7363
7364 # Stop server
7365 server_stop($pid_file);
7366
7367 $self->assert_child_ok($pid);
7368
7369 if (open(my $fh, "< $ext_log")) {
7370 my $ok = 0;
7371
7372 while (my $line = <$fh>) {
7373 chomp($line);
7374
7375 if ($line =~ /(\S+) (\S+) \[(.*?)\] = (\d+) (.*?)$/) {
7376 my $cmd = $1;
7377 my $cmd_args = $2;
7378 my $full_cmd = $3;
7379 my $resp_code = $4;
7380 my $resp_msg = $5;
7381
7382 my $expected = "$cmd $cmd_args";
7383 $self->assert($expected eq $full_cmd,
7384 test_msg("Expected '$expected', got '$full_cmd'"));
7385
7386 $ok = 1;
7387 }
7388 }
7389
7390 close($fh);
7391
7392 $self->assert($ok, test_msg("Expected ExtendedLog lines not found"));
7393
7394 } else {
7395 die("Can't read $ext_log: $!");
7396 }
7397
7398 if ($ex) {
7399 test_append_logfile($log_file, $ex);
7400 unlink($log_file);
7401
7402 die($ex);
7403 }
7404
7405 unlink($log_file);
7406 }
7407
7408 sub extlog_xfer_timeout_bug3696 {
7409 my $self = shift;
7410 my $tmpdir = $self->{tmpdir};
7411
7412 my $config_file = "$tmpdir/extlog.conf";
7413 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
7414 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
7415
7416 my $log_file = test_get_logfile();
7417
7418 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
7419 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
7420
7421 my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
7422
7423 my $user = 'proftpd';
7424 my $passwd = 'test';
7425 my $group = 'ftpd';
7426 my $home_dir = File::Spec->rel2abs($tmpdir);
7427 my $uid = 500;
7428 my $gid = 500;
7429
7430 # Make sure that, if we're running as root, that the home directory has
7431 # permissions/privs set for the account we create
7432 if ($< == 0) {
7433 unless (chmod(0755, $home_dir)) {
7434 die("Can't set perms on $home_dir to 0755: $!");
7435 }
7436
7437 unless (chown($uid, $gid, $home_dir)) {
7438 die("Can't set owner of $home_dir to $uid/$gid: $!");
7439 }
7440 }
7441
7442 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7443 '/bin/bash');
7444 auth_group_write($auth_group_file, $group, $gid, $user);
7445
7446 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
7447
7448 my $timeout_stalled = 2;
7449
7450 my $config = {
7451 PidFile => $pid_file,
7452 ScoreboardFile => $scoreboard_file,
7453 SystemLog => $log_file,
7454
7455 AuthUserFile => $auth_user_file,
7456 AuthGroupFile => $auth_group_file,
7457 AuthOrder => 'mod_auth_file.c',
7458
7459 LogFormat => 'custom "%f"',
7460 ExtendedLog => "$ext_log WRITE custom",
7461
7462 TimeoutStalled => $timeout_stalled,
7463
7464 IfModules => {
7465 'mod_delay.c' => {
7466 DelayEngine => 'off',
7467 },
7468 },
7469 };
7470
7471 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7472
7473 # Open pipes, for use between the parent and child processes. Specifically,
7474 # the child will indicate when it's done with its test by writing a message
7475 # to the parent.
7476 my ($rfh, $wfh);
7477 unless (pipe($rfh, $wfh)) {
7478 die("Can't open pipe: $!");
7479 }
7480
7481 my $ex;
7482
7483 # Fork child
7484 $self->handle_sigchld();
7485 defined(my $pid = fork()) or die("Can't fork: $!");
7486 if ($pid) {
7487 eval {
7488 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7489 $client->login($user, $passwd);
7490
7491 my $conn = $client->stor_raw('foo.txt');
7492 unless ($conn) {
7493 die("Failed to STOR foo.txt: " . $client->response_code() . " " .
7494 $client->response_msg());
7495 }
7496
7497 # Wait for longer than the TimeoutStalled limit
7498 sleep($timeout_stalled + 2);
7499
7500 eval {
7501 my $buf = "Foo!\n";
7502 $conn->write($buf, length($buf));
7503 eval { $conn->close() };
7504
7505 $client->quit();
7506 };
7507 };
7508
7509 if ($@) {
7510 $ex = $@;
7511 }
7512
7513 $wfh->print("done\n");
7514 $wfh->flush();
7515
7516 } else {
7517 eval { server_wait($config_file, $rfh) };
7518 if ($@) {
7519 warn($@);
7520 exit 1;
7521 }
7522
7523 exit 0;
7524 }
7525
7526 # Stop server
7527 server_stop($pid_file);
7528
7529 $self->assert_child_ok($pid);
7530
7531 # Now, read in the ExtendedLog, and see whether the %f variable was
7532 # properly written out. Bug#3696 occurred because mod_log would not
7533 # properly notice that a data transfer was in progress when the
7534 # session was disconnected due to hitting TimeoutStalled.
7535 # information.
7536 if (open(my $fh, "< $ext_log")) {
7537 my $line = <$fh>;
7538 chomp($line);
7539 close($fh);
7540
7541 if ($^O eq 'darwin') {
7542 # MacOSX-specific hack
7543 $test_file = '/private' . $test_file;
7544 }
7545
7546 $self->assert($test_file eq $line,
7547 test_msg("Expected '$test_file', got '$line'"));
7548
7549 } else {
7550 die("Can't read $ext_log: $!");
7551 }
7552
7553 if ($ex) {
7554 test_append_logfile($log_file, $ex);
7555 unlink($log_file);
7556
7557 die($ex);
7558 }
7559
7560 unlink($log_file);
7561 }
7562
7563 sub extlog_sftp_xfer_timeout_bug3696 {
7564 my $self = shift;
7565 my $tmpdir = $self->{tmpdir};
7566
7567 my $config_file = "$tmpdir/extlog.conf";
7568 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
7569 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
7570
7571 my $log_file = test_get_logfile();
7572
7573 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
7574 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
7575
7576 my $user = 'proftpd';
7577 my $passwd = 'test';
7578 my $group = 'ftpd';
7579 my $home_dir = File::Spec->rel2abs($tmpdir);
7580 my $uid = 500;
7581 my $gid = 500;
7582
7583 # Make sure that, if we're running as root, that the home directory has
7584 # permissions/privs set for the account we create
7585 if ($< == 0) {
7586 unless (chmod(0755, $home_dir)) {
7587 die("Can't set perms on $home_dir to 0755: $!");
7588 }
7589
7590 unless (chown($uid, $gid, $home_dir)) {
7591 die("Can't set owner of $home_dir to $uid/$gid: $!");
7592 }
7593 }
7594
7595 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7596 '/bin/bash');
7597 auth_group_write($auth_group_file, $group, $gid, $user);
7598
7599 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
7600 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
7601
7602 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
7603
7604 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
7605 my $timeout_stalled = 2;
7606
7607 my $config = {
7608 PidFile => $pid_file,
7609 ScoreboardFile => $scoreboard_file,
7610 SystemLog => $log_file,
7611 TraceLog => $log_file,
7612 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
7613
7614 AuthUserFile => $auth_user_file,
7615 AuthGroupFile => $auth_group_file,
7616 AuthOrder => 'mod_auth_file.c',
7617
7618 LogFormat => 'custom "%f"',
7619 ExtendedLog => "$ext_log WRITE custom",
7620
7621 TimeoutStalled => $timeout_stalled,
7622
7623 IfModules => {
7624 'mod_delay.c' => {
7625 DelayEngine => 'off',
7626 },
7627
7628 'mod_sftp.c' => [
7629 "SFTPEngine on",
7630 "SFTPLog $log_file",
7631 "SFTPHostKey $rsa_host_key",
7632 "SFTPHostKey $dsa_host_key",
7633 ],
7634 },
7635 };
7636
7637 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7638
7639 # Open pipes, for use between the parent and child processes. Specifically,
7640 # the child will indicate when it's done with its test by writing a message
7641 # to the parent.
7642 my ($rfh, $wfh);
7643 unless (pipe($rfh, $wfh)) {
7644 die("Can't open pipe: $!");
7645 }
7646
7647 require Net::SSH2;
7648
7649 my $ex;
7650
7651 # Ignore SIGPIPE
7652 local $SIG{PIPE} = sub { };
7653
7654 # Fork child
7655 $self->handle_sigchld();
7656 defined(my $pid = fork()) or die("Can't fork: $!");
7657 if ($pid) {
7658 eval {
7659 my $ssh2 = Net::SSH2->new();
7660
7661 sleep(1);
7662
7663 unless ($ssh2->connect('127.0.0.1', $port)) {
7664 my ($err_code, $err_name, $err_str) = $ssh2->error();
7665 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
7666 }
7667
7668 unless ($ssh2->auth_password($user, $passwd)) {
7669 my ($err_code, $err_name, $err_str) = $ssh2->error();
7670 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
7671 }
7672
7673 my $sftp = $ssh2->sftp();
7674 unless ($sftp) {
7675 my ($err_code, $err_name, $err_str) = $ssh2->error();
7676 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
7677 }
7678
7679 my $fh = $sftp->open('test.txt', O_WRONLY|O_CREAT|O_TRUNC, 0644);
7680 unless ($fh) {
7681 my ($err_code, $err_name) = $sftp->error();
7682 die("Can't open test.txt: [$err_name] ($err_code)");
7683 }
7684
7685 print $fh "ABCD\n" x 8;
7686
7687 # Wait for longer than the TimeoutStalled limit
7688 sleep($timeout_stalled + 2);
7689
7690 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
7691 $fh = undef;
7692
7693 # To issue the CHANNEL_CLOSE, we have to explicitly destroy the sftp
7694 # object. Sigh.
7695 $sftp = undef;
7696
7697 $ssh2->disconnect();
7698 };
7699
7700 if ($@) {
7701 $ex = $@;
7702 }
7703
7704 $wfh->print("done\n");
7705 $wfh->flush();
7706
7707 } else {
7708 eval { server_wait($config_file, $rfh) };
7709 if ($@) {
7710 warn($@);
7711 exit 1;
7712 }
7713
7714 exit 0;
7715 }
7716
7717 # Stop server
7718 server_stop($pid_file);
7719
7720 $self->assert_child_ok($pid);
7721
7722 if ($ex) {
7723 test_append_logfile($log_file, $ex);
7724 unlink($log_file);
7725
7726 die($ex);
7727 }
7728
7729 # Now, read in the ExtendedLog, and see whether the %f variable was
7730 # properly written out. Bug#3696 occurred because mod_log would not
7731 # properly notice that a data transfer was in progress when the
7732 # session was disconnected due to hitting TimeoutStalled.
7733 # information.
7734 if (open(my $fh, "< $ext_log")) {
7735 my $line = <$fh>;
7736 chomp($line);
7737 close($fh);
7738
7739 if ($^O eq 'darwin') {
7740 # MacOSX-specific hack
7741 $test_file = '/private' . $test_file;
7742 }
7743
7744 $self->assert($test_file eq $line,
7745 test_msg("Expected '$test_file', got '$line'"));
7746
7747 } else {
7748 die("Can't read $ext_log: $!");
7749 }
7750
7751 unlink($log_file);
7752 }
7753
7754 sub extlog_var_r {
7755 my $self = shift;
7756 my $tmpdir = $self->{tmpdir};
7757
7758 my $config_file = "$tmpdir/extlog.conf";
7759 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
7760 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
7761
7762 my $log_file = test_get_logfile();
7763
7764 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
7765 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
7766
7767 my $test_file = File::Spec->rel2abs($config_file);
7768
7769 my $user = 'proftpd';
7770 my $passwd = 'test';
7771 my $group = 'ftpd';
7772 my $home_dir = File::Spec->rel2abs($tmpdir);
7773 my $uid = 500;
7774 my $gid = 500;
7775
7776 # Make sure that, if we're running as root, that the home directory has
7777 # permissions/privs set for the account we create
7778 if ($< == 0) {
7779 unless (chmod(0755, $home_dir)) {
7780 die("Can't set perms on $home_dir to 0755: $!");
7781 }
7782
7783 unless (chown($uid, $gid, $home_dir)) {
7784 die("Can't set owner of $home_dir to $uid/$gid: $!");
7785 }
7786 }
7787
7788 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7789 '/bin/bash');
7790 auth_group_write($auth_group_file, $group, $gid, $user);
7791
7792 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
7793
7794 my $config = {
7795 PidFile => $pid_file,
7796 ScoreboardFile => $scoreboard_file,
7797 SystemLog => $log_file,
7798 TraceLog => $log_file,
7799 Trace => 'response:10',
7800
7801 AuthUserFile => $auth_user_file,
7802 AuthGroupFile => $auth_group_file,
7803 AuthOrder => 'mod_auth_file.c',
7804
7805 LogFormat => 'custom "%r"',
7806 ExtendedLog => "$ext_log ALL custom",
7807
7808 IfModules => {
7809 'mod_delay.c' => {
7810 DelayEngine => 'off',
7811 },
7812 },
7813 };
7814
7815 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7816
7817 # Open pipes, for use between the parent and child processes. Specifically,
7818 # the child will indicate when it's done with its test by writing a message
7819 # to the parent.
7820 my ($rfh, $wfh);
7821 unless (pipe($rfh, $wfh)) {
7822 die("Can't open pipe: $!");
7823 }
7824
7825 my $ex;
7826
7827 # Fork child
7828 $self->handle_sigchld();
7829 defined(my $pid = fork()) or die("Can't fork: $!");
7830 if ($pid) {
7831 eval {
7832 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7833 $client->login($user, $passwd);
7834 eval { $client->site('CHMOD', '777', 'test.txt') };
7835 $client->quit();
7836 };
7837
7838 if ($@) {
7839 $ex = $@;
7840 }
7841
7842 $wfh->print("done\n");
7843 $wfh->flush();
7844
7845 } else {
7846 eval { server_wait($config_file, $rfh) };
7847 if ($@) {
7848 warn($@);
7849 exit 1;
7850 }
7851
7852 exit 0;
7853 }
7854
7855 # Stop server
7856 server_stop($pid_file);
7857
7858 $self->assert_child_ok($pid);
7859
7860 # Now, read in the ExtendedLog, and see whether the %s variable was
7861 # properly written out for the PASS command.
7862 eval {
7863 if (open(my $fh, "< $ext_log")) {
7864 my $user_ok = 0;
7865 my $pass_ok = 0;
7866 my $site_ok = 0;
7867
7868 while (my $line = <$fh>) {
7869 chomp($line);
7870
7871 if ($line =~ /^(.*?)$/) {
7872 my $cmd = $1;
7873
7874 if ($cmd eq "USER $user") {
7875 $user_ok = 1;
7876 next;
7877 }
7878
7879 if ($cmd eq 'PASS (hidden)') {
7880 $pass_ok = 1;
7881 next;
7882 }
7883
7884 if ($cmd eq 'SITE CHMOD 777 test.txt') {
7885 $site_ok = 1;
7886 next;
7887 }
7888 }
7889 }
7890
7891 close($fh);
7892
7893 $self->assert($user_ok,
7894 test_msg("Did not see expected USER command in $ext_log"));
7895 $self->assert($pass_ok,
7896 test_msg("Did not see expected PASS command in $ext_log"));
7897 $self->assert($site_ok,
7898 test_msg("Did not see expected SITE command in $ext_log"));
7899
7900 } else {
7901 die("Can't read $ext_log: $!");
7902 }
7903 };
7904 if ($@) {
7905 $ex = $@;
7906 }
7907
7908 if ($ex) {
7909 test_append_logfile($log_file, $ex);
7910 unlink($log_file);
7911
7912 die($ex);
7913 }
7914
7915 unlink($log_file);
7916 }
7917
7918 sub extlog_pass_var_r {
7919 my $self = shift;
7920 my $tmpdir = $self->{tmpdir};
7921
7922 my $config_file = "$tmpdir/extlog.conf";
7923 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
7924 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
7925
7926 my $log_file = test_get_logfile();
7927
7928 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
7929 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
7930
7931 my $test_file = File::Spec->rel2abs($config_file);
7932
7933 my $user = 'proftpd';
7934 my $passwd = 'test';
7935 my $group = 'ftpd';
7936 my $home_dir = File::Spec->rel2abs($tmpdir);
7937 my $uid = 500;
7938 my $gid = 500;
7939
7940 # Make sure that, if we're running as root, that the home directory has
7941 # permissions/privs set for the account we create
7942 if ($< == 0) {
7943 unless (chmod(0755, $home_dir)) {
7944 die("Can't set perms on $home_dir to 0755: $!");
7945 }
7946
7947 unless (chown($uid, $gid, $home_dir)) {
7948 die("Can't set owner of $home_dir to $uid/$gid: $!");
7949 }
7950 }
7951
7952 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7953 '/bin/bash');
7954 auth_group_write($auth_group_file, $group, $gid, $user);
7955
7956 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
7957
7958 my $config = {
7959 PidFile => $pid_file,
7960 ScoreboardFile => $scoreboard_file,
7961 SystemLog => $log_file,
7962 TraceLog => $log_file,
7963 Trace => 'response:10',
7964
7965 AuthUserFile => $auth_user_file,
7966 AuthGroupFile => $auth_group_file,
7967 AuthOrder => 'mod_auth_file.c',
7968
7969 LogFormat => 'custom "%r"',
7970 ExtendedLog => "$ext_log AUTH custom",
7971
7972 IfModules => {
7973 'mod_delay.c' => {
7974 DelayEngine => 'off',
7975 },
7976 },
7977 };
7978
7979 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7980
7981 # Open pipes, for use between the parent and child processes. Specifically,
7982 # the child will indicate when it's done with its test by writing a message
7983 # to the parent.
7984 my ($rfh, $wfh);
7985 unless (pipe($rfh, $wfh)) {
7986 die("Can't open pipe: $!");
7987 }
7988
7989 my $ex;
7990
7991 # Fork child
7992 $self->handle_sigchld();
7993 defined(my $pid = fork()) or die("Can't fork: $!");
7994 if ($pid) {
7995 eval {
7996 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7997 $client->login($user, $passwd);
7998 $client->quit();
7999 };
8000
8001 if ($@) {
8002 $ex = $@;
8003 }
8004
8005 $wfh->print("done\n");
8006 $wfh->flush();
8007
8008 } else {
8009 eval { server_wait($config_file, $rfh) };
8010 if ($@) {
8011 warn($@);
8012 exit 1;
8013 }
8014
8015 exit 0;
8016 }
8017
8018 # Stop server
8019 server_stop($pid_file);
8020
8021 $self->assert_child_ok($pid);
8022
8023 # Now, read in the ExtendedLog, and see whether the %s variable was
8024 # properly written out for the PASS command.
8025 if (open(my $fh, "< $ext_log")) {
8026 while (my $line = <$fh>) {
8027 chomp($line);
8028
8029 if ($line =~ /^(\S+) (\S+)$/) {
8030 my $cmd = $1;
8031 my $args = $2;
8032
8033 next unless $cmd eq 'PASS';
8034
8035 my $expected = '(hidden)';
8036 $self->assert($expected eq $args,
8037 test_msg("Expected '$expected', got '$args'"));
8038
8039 last;
8040 }
8041 }
8042
8043 close($fh);
8044
8045 } else {
8046 die("Can't read $ext_log: $!");
8047 }
8048
8049 if ($ex) {
8050 test_append_logfile($log_file, $ex);
8051 unlink($log_file);
8052
8053 die($ex);
8054 }
8055
8056 unlink($log_file);
8057 }
8058
8059 sub extlog_sftp_pass_var_r {
8060 my $self = shift;
8061 my $tmpdir = $self->{tmpdir};
8062
8063 my $config_file = "$tmpdir/extlog.conf";
8064 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
8065 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
8066
8067 my $log_file = test_get_logfile();
8068
8069 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
8070 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
8071
8072 my $user = 'proftpd';
8073 my $passwd = 'test';
8074 my $group = 'ftpd';
8075 my $home_dir = File::Spec->rel2abs($tmpdir);
8076 my $uid = 500;
8077 my $gid = 500;
8078
8079 # Make sure that, if we're running as root, that the home directory has
8080 # permissions/privs set for the account we create
8081 if ($< == 0) {
8082 unless (chmod(0755, $home_dir)) {
8083 die("Can't set perms on $home_dir to 0755: $!");
8084 }
8085
8086 unless (chown($uid, $gid, $home_dir)) {
8087 die("Can't set owner of $home_dir to $uid/$gid: $!");
8088 }
8089 }
8090
8091 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8092 '/bin/bash');
8093 auth_group_write($auth_group_file, $group, $gid, $user);
8094
8095 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
8096 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
8097
8098 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
8099
8100 my $config = {
8101 PidFile => $pid_file,
8102 ScoreboardFile => $scoreboard_file,
8103 SystemLog => $log_file,
8104 TraceLog => $log_file,
8105 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
8106
8107 AuthUserFile => $auth_user_file,
8108 AuthGroupFile => $auth_group_file,
8109 AuthOrder => 'mod_auth_file.c',
8110
8111 LogFormat => 'custom "%r"',
8112 ExtendedLog => "$ext_log AUTH custom",
8113
8114 IfModules => {
8115 'mod_delay.c' => {
8116 DelayEngine => 'off',
8117 },
8118
8119 'mod_sftp.c' => [
8120 "SFTPEngine on",
8121 "SFTPLog $log_file",
8122 "SFTPHostKey $rsa_host_key",
8123 "SFTPHostKey $dsa_host_key",
8124 ],
8125 },
8126 };
8127
8128 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8129
8130 # Open pipes, for use between the parent and child processes. Specifically,
8131 # the child will indicate when it's done with its test by writing a message
8132 # to the parent.
8133 my ($rfh, $wfh);
8134 unless (pipe($rfh, $wfh)) {
8135 die("Can't open pipe: $!");
8136 }
8137
8138 require Net::SSH2;
8139
8140 my $ex;
8141
8142 # Ignore SIGPIPE
8143 local $SIG{PIPE} = sub { };
8144
8145 # Fork child
8146 $self->handle_sigchld();
8147 defined(my $pid = fork()) or die("Can't fork: $!");
8148 if ($pid) {
8149 eval {
8150 my $ssh2 = Net::SSH2->new();
8151
8152 sleep(1);
8153
8154 unless ($ssh2->connect('127.0.0.1', $port)) {
8155 my ($err_code, $err_name, $err_str) = $ssh2->error();
8156 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
8157 }
8158
8159 unless ($ssh2->auth_password($user, $passwd)) {
8160 my ($err_code, $err_name, $err_str) = $ssh2->error();
8161 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
8162 }
8163
8164 my $sftp = $ssh2->sftp();
8165 unless ($sftp) {
8166 my ($err_code, $err_name, $err_str) = $ssh2->error();
8167 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
8168 }
8169
8170 # To issue the CHANNEL_CLOSE, we have to explicitly destroy the sftp
8171 # object. Sigh.
8172 $sftp = undef;
8173
8174 $ssh2->disconnect();
8175 };
8176
8177 if ($@) {
8178 $ex = $@;
8179 }
8180
8181 $wfh->print("done\n");
8182 $wfh->flush();
8183
8184 } else {
8185 eval { server_wait($config_file, $rfh) };
8186 if ($@) {
8187 warn($@);
8188 exit 1;
8189 }
8190
8191 exit 0;
8192 }
8193
8194 # Stop server
8195 server_stop($pid_file);
8196
8197 $self->assert_child_ok($pid);
8198
8199 if ($ex) {
8200 test_append_logfile($log_file, $ex);
8201 unlink($log_file);
8202
8203 die($ex);
8204 }
8205
8206 # Now, read in the ExtendedLog, and see whether the %I/%O variables
8207 # are properly populated
8208 if (open(my $fh, "< $ext_log")) {
8209 my $ok = 0;
8210
8211 while (my $line = <$fh>) {
8212 chomp($line);
8213
8214 if ($line =~ /^(\S+) (.*?)$/) {
8215 my $cmd = $1;
8216 my $args = $2;
8217
8218 next unless $cmd eq 'PASS';
8219
8220 my $expected = '(hidden)';
8221 $self->assert($expected eq $args,
8222 test_msg("Expected '$expected', got '$args'"));
8223 $ok = 1;
8224 last;
8225 }
8226 }
8227
8228 close($fh);
8229
8230 $self->assert($ok,
8231 test_msg("ExtendedLog did not contain expected message"));
8232
8233 } else {
8234 die("Can't read $ext_log: $!");
8235 }
8236
8237 unlink($log_file);
8238 }
8239
8240 sub extlog_sftp_retr_var_s_bug3948 {
8241 my $self = shift;
8242 my $tmpdir = $self->{tmpdir};
8243
8244 my $config_file = "$tmpdir/extlog.conf";
8245 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
8246 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
8247
8248 my $log_file = test_get_logfile();
8249
8250 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
8251 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
8252
8253 my $user = 'proftpd';
8254 my $passwd = 'test';
8255 my $group = 'ftpd';
8256 my $home_dir = File::Spec->rel2abs($tmpdir);
8257 my $uid = 500;
8258 my $gid = 500;
8259
8260 # Make sure that, if we're running as root, that the home directory has
8261 # permissions/privs set for the account we create
8262 if ($< == 0) {
8263 unless (chmod(0755, $home_dir)) {
8264 die("Can't set perms on $home_dir to 0755: $!");
8265 }
8266
8267 unless (chown($uid, $gid, $home_dir)) {
8268 die("Can't set owner of $home_dir to $uid/$gid: $!");
8269 }
8270 }
8271
8272 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8273 '/bin/bash');
8274 auth_group_write($auth_group_file, $group, $gid, $user);
8275
8276 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
8277 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
8278
8279 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
8280
8281 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
8282 if (open(my $fh, "> $test_file")) {
8283 my $count = 20;
8284 for (my $i = 0; $i < $count; $i++) {
8285 print $fh "ABCD" x 8192;
8286 }
8287
8288 unless (close($fh)) {
8289 die("Can't write $test_file: $!");
8290 }
8291
8292 } else {
8293 die("Can't open $test_file: $!");
8294 }
8295
8296 my $config = {
8297 PidFile => $pid_file,
8298 ScoreboardFile => $scoreboard_file,
8299 SystemLog => $log_file,
8300 TraceLog => $log_file,
8301 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
8302
8303 AuthUserFile => $auth_user_file,
8304 AuthGroupFile => $auth_group_file,
8305 AuthOrder => 'mod_auth_file.c',
8306
8307 LogFormat => 'custom "%m %s"',
8308 ExtendedLog => "$ext_log READ custom",
8309
8310 IfModules => {
8311 'mod_delay.c' => {
8312 DelayEngine => 'off',
8313 },
8314
8315 'mod_sftp.c' => [
8316 "SFTPEngine on",
8317 "SFTPLog $log_file",
8318 "SFTPHostKey $rsa_host_key",
8319 "SFTPHostKey $dsa_host_key",
8320 ],
8321 },
8322 };
8323
8324 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8325
8326 # Open pipes, for use between the parent and child processes. Specifically,
8327 # the child will indicate when it's done with its test by writing a message
8328 # to the parent.
8329 my ($rfh, $wfh);
8330 unless (pipe($rfh, $wfh)) {
8331 die("Can't open pipe: $!");
8332 }
8333
8334 require Net::SSH2;
8335
8336 my $ex;
8337
8338 # Ignore SIGPIPE
8339 local $SIG{PIPE} = sub { };
8340
8341 # Fork child
8342 $self->handle_sigchld();
8343 defined(my $pid = fork()) or die("Can't fork: $!");
8344 if ($pid) {
8345 eval {
8346 my $ssh2 = Net::SSH2->new();
8347
8348 sleep(1);
8349
8350 unless ($ssh2->connect('127.0.0.1', $port)) {
8351 my ($err_code, $err_name, $err_str) = $ssh2->error();
8352 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
8353 }
8354
8355 unless ($ssh2->auth_password($user, $passwd)) {
8356 my ($err_code, $err_name, $err_str) = $ssh2->error();
8357 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
8358 }
8359
8360 my $sftp = $ssh2->sftp();
8361 unless ($sftp) {
8362 my ($err_code, $err_name, $err_str) = $ssh2->error();
8363 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
8364 }
8365
8366 my $fh = $sftp->open('test.txt', O_RDONLY);
8367 unless ($fh) {
8368 my ($err_code, $err_name) = $sftp->error();
8369 die("Can't open test.txt: [$err_name] ($err_code)");
8370 }
8371
8372 my $buf;
8373 my $size = 0;
8374
8375 my $res = $fh->read($buf, 8192);
8376 while ($res) {
8377 $size += $res;
8378
8379 $res = $fh->read($buf, 8192);
8380 }
8381
8382 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
8383 $fh = undef;
8384
8385 # To close the SFTP channel, we have to explicitly destroy the object
8386 $sftp = undef;
8387
8388 $ssh2->disconnect();
8389 };
8390
8391 if ($@) {
8392 $ex = $@;
8393 }
8394
8395 $wfh->print("done\n");
8396 $wfh->flush();
8397
8398 } else {
8399 eval { server_wait($config_file, $rfh) };
8400 if ($@) {
8401 warn($@);
8402 exit 1;
8403 }
8404
8405 exit 0;
8406 }
8407
8408 # Stop server
8409 server_stop($pid_file);
8410
8411 $self->assert_child_ok($pid);
8412
8413 eval {
8414 if (open(my $fh, "< $ext_log")) {
8415 my $ok = 0;
8416
8417 while (my $line = <$fh>) {
8418 chomp($line);
8419
8420 if ($line =~ /^(\S+) (.*?)$/) {
8421 my $cmd = $1;
8422 my $status = $2;
8423
8424 next unless $cmd eq 'RETR';
8425
8426 my $expected = '226';
8427 $self->assert($expected eq $status,
8428 test_msg("Expected response code '$expected', got '$status'"));
8429 $ok = 1;
8430 last;
8431 }
8432 }
8433
8434 close($fh);
8435
8436 $self->assert($ok,
8437 test_msg("ExtendedLog did not contain expected message"));
8438
8439 } else {
8440 die("Can't read $ext_log: $!");
8441 }
8442 };
8443 if ($@) {
8444 $ex = $@;
8445 }
8446
8447 if ($ex) {
8448 test_append_logfile($log_file, $ex);
8449 unlink($log_file);
8450
8451 die($ex);
8452 }
8453
8454 unlink($log_file);
8455 }
8456
8457 sub extlog_sftp_stor_var_s_bug3948 {
8458 my $self = shift;
8459 my $tmpdir = $self->{tmpdir};
8460
8461 my $config_file = "$tmpdir/extlog.conf";
8462 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
8463 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
8464
8465 my $log_file = test_get_logfile();
8466
8467 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
8468 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
8469
8470 my $user = 'proftpd';
8471 my $passwd = 'test';
8472 my $group = 'ftpd';
8473 my $home_dir = File::Spec->rel2abs($tmpdir);
8474 my $uid = 500;
8475 my $gid = 500;
8476
8477 # Make sure that, if we're running as root, that the home directory has
8478 # permissions/privs set for the account we create
8479 if ($< == 0) {
8480 unless (chmod(0755, $home_dir)) {
8481 die("Can't set perms on $home_dir to 0755: $!");
8482 }
8483
8484 unless (chown($uid, $gid, $home_dir)) {
8485 die("Can't set owner of $home_dir to $uid/$gid: $!");
8486 }
8487 }
8488
8489 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8490 '/bin/bash');
8491 auth_group_write($auth_group_file, $group, $gid, $user);
8492
8493 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
8494 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
8495
8496 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
8497
8498 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
8499
8500 my $config = {
8501 PidFile => $pid_file,
8502 ScoreboardFile => $scoreboard_file,
8503 SystemLog => $log_file,
8504 TraceLog => $log_file,
8505 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
8506
8507 AuthUserFile => $auth_user_file,
8508 AuthGroupFile => $auth_group_file,
8509 AuthOrder => 'mod_auth_file.c',
8510
8511 AllowOverwrite => 'on',
8512 LogFormat => 'custom "%m %s"',
8513 ExtendedLog => "$ext_log WRITE custom",
8514
8515 IfModules => {
8516 'mod_delay.c' => {
8517 DelayEngine => 'off',
8518 },
8519
8520 'mod_sftp.c' => [
8521 "SFTPEngine on",
8522 "SFTPLog $log_file",
8523 "SFTPHostKey $rsa_host_key",
8524 "SFTPHostKey $dsa_host_key",
8525 ],
8526 },
8527 };
8528
8529 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8530
8531 # Open pipes, for use between the parent and child processes. Specifically,
8532 # the child will indicate when it's done with its test by writing a message
8533 # to the parent.
8534 my ($rfh, $wfh);
8535 unless (pipe($rfh, $wfh)) {
8536 die("Can't open pipe: $!");
8537 }
8538
8539 require Net::SSH2;
8540
8541 my $ex;
8542
8543 # Ignore SIGPIPE
8544 local $SIG{PIPE} = sub { };
8545
8546 # Fork child
8547 $self->handle_sigchld();
8548 defined(my $pid = fork()) or die("Can't fork: $!");
8549 if ($pid) {
8550 eval {
8551 my $ssh2 = Net::SSH2->new();
8552
8553 sleep(1);
8554
8555 unless ($ssh2->connect('127.0.0.1', $port)) {
8556 my ($err_code, $err_name, $err_str) = $ssh2->error();
8557 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
8558 }
8559
8560 unless ($ssh2->auth_password($user, $passwd)) {
8561 my ($err_code, $err_name, $err_str) = $ssh2->error();
8562 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
8563 }
8564
8565 my $sftp = $ssh2->sftp();
8566 unless ($sftp) {
8567 my ($err_code, $err_name, $err_str) = $ssh2->error();
8568 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
8569 }
8570
8571 my $fh = $sftp->open('test.txt', O_WRONLY|O_CREAT|O_TRUNC, 0644);
8572 unless ($fh) {
8573 my ($err_code, $err_name) = $sftp->error();
8574 die("Can't open test.txt: [$err_name] ($err_code)");
8575 }
8576
8577 my $count = 20;
8578 for (my $i = 0; $i < $count; $i++) {
8579 print $fh "ABCD" x 8192;
8580 }
8581
8582 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
8583 $fh = undef;
8584
8585 # To close the SFTP channel, we have to explicitly destroy the object
8586 $sftp = undef;
8587
8588 $ssh2->disconnect();
8589 };
8590
8591 if ($@) {
8592 $ex = $@;
8593 }
8594
8595 $wfh->print("done\n");
8596 $wfh->flush();
8597
8598 } else {
8599 eval { server_wait($config_file, $rfh) };
8600 if ($@) {
8601 warn($@);
8602 exit 1;
8603 }
8604
8605 exit 0;
8606 }
8607
8608 # Stop server
8609 server_stop($pid_file);
8610
8611 $self->assert_child_ok($pid);
8612
8613 eval {
8614 if (open(my $fh, "< $ext_log")) {
8615 my $ok = 0;
8616
8617 while (my $line = <$fh>) {
8618 chomp($line);
8619
8620 if ($line =~ /^(\S+) (.*?)$/) {
8621 my $cmd = $1;
8622 my $status = $2;
8623
8624 next unless $cmd eq 'STOR';
8625
8626 my $expected = '226';
8627 $self->assert($expected eq $status,
8628 test_msg("Expected response code '$expected', got '$status'"));
8629 $ok = 1;
8630 last;
8631 }
8632 }
8633
8634 close($fh);
8635
8636 $self->assert($ok,
8637 test_msg("ExtendedLog did not contain expected message"));
8638
8639 } else {
8640 die("Can't read $ext_log: $!");
8641 }
8642 };
8643 if ($@) {
8644 $ex = $@;
8645 }
8646
8647 if ($ex) {
8648 test_append_logfile($log_file, $ex);
8649 unlink($log_file);
8650
8651 die($ex);
8652 }
8653
8654 unlink($log_file);
8655 }
8656
8657 sub extlog_abor {
8658 my $self = shift;
8659 my $tmpdir = $self->{tmpdir};
8660
8661 my $config_file = "$tmpdir/extlog.conf";
8662 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
8663 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
8664
8665 my $log_file = test_get_logfile();
8666
8667 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
8668 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
8669
8670 my $user = 'proftpd';
8671 my $passwd = 'test';
8672 my $group = 'ftpd';
8673 my $home_dir = File::Spec->rel2abs($tmpdir);
8674 my $uid = 500;
8675 my $gid = 500;
8676
8677 # Make sure that, if we're running as root, that the home directory has
8678 # permissions/privs set for the account we create
8679 if ($< == 0) {
8680 unless (chmod(0755, $home_dir)) {
8681 die("Can't set perms on $home_dir to 0755: $!");
8682 }
8683
8684 unless (chown($uid, $gid, $home_dir)) {
8685 die("Can't set owner of $home_dir to $uid/$gid: $!");
8686 }
8687 }
8688
8689 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8690 '/bin/bash');
8691 auth_group_write($auth_group_file, $group, $gid, $user);
8692
8693 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
8694
8695 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
8696 if (open(my $fh, "> $test_file")) {
8697 print $fh "A" x 1024;
8698
8699 unless (close($fh)) {
8700 die("Can't write $test_file: $!");
8701 }
8702
8703 } else {
8704 die("Can't open $test_file: $!");
8705 }
8706
8707 my $config = {
8708 PidFile => $pid_file,
8709 ScoreboardFile => $scoreboard_file,
8710 SystemLog => $log_file,
8711
8712 AuthUserFile => $auth_user_file,
8713 AuthGroupFile => $auth_group_file,
8714 AuthOrder => 'mod_auth_file.c',
8715
8716 LogFormat => 'custom "%m"',
8717 ExtendedLog => "$ext_log ALL custom",
8718
8719 IfModules => {
8720 'mod_delay.c' => {
8721 DelayEngine => 'off',
8722 },
8723 },
8724 };
8725
8726 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8727
8728 # Open pipes, for use between the parent and child processes. Specifically,
8729 # the child will indicate when it's done with its test by writing a message
8730 # to the parent.
8731 my ($rfh, $wfh);
8732 unless (pipe($rfh, $wfh)) {
8733 die("Can't open pipe: $!");
8734 }
8735
8736 my $ex;
8737
8738 # Fork child
8739 $self->handle_sigchld();
8740 defined(my $pid = fork()) or die("Can't fork: $!");
8741 if ($pid) {
8742 eval {
8743 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
8744 $client->login($user, $passwd);
8745
8746 my $conn = $client->retr_raw($test_file);
8747 unless ($conn) {
8748 die("Failed to RETR: " . $client->response_code() . " " .
8749 $client->response_msg());
8750 }
8751
8752 my $buf;
8753 $conn->read($buf, 32, 30);
8754 eval { $conn->abort() };
8755
8756 my $resp_code = $client->response_code();
8757 my $resp_msg = $client->response_msg();
8758
8759 my $expected;
8760
8761 $expected = 226;
8762 $self->assert($expected == $resp_code,
8763 test_msg("Expected $expected, got $resp_code"));
8764
8765 $expected = "Abort successful";
8766 $self->assert($expected eq $resp_msg,
8767 test_msg("Expected '$expected', got '$resp_msg'"));
8768
8769 $client->quit();
8770 };
8771
8772 if ($@) {
8773 $ex = $@;
8774 }
8775
8776 $wfh->print("done\n");
8777 $wfh->flush();
8778
8779 } else {
8780 eval { server_wait($config_file, $rfh) };
8781 if ($@) {
8782 warn($@);
8783 exit 1;
8784 }
8785
8786 exit 0;
8787 }
8788
8789 # Stop server
8790 server_stop($pid_file);
8791
8792 $self->assert_child_ok($pid);
8793
8794 # Now, read in the ExtendedLog, and see whether the %m variable was
8795 # properly written out for the ABOR command.
8796 eval {
8797 if (open(my $fh, "< $ext_log")) {
8798 my $saw_abor = 0;
8799
8800 while (my $line = <$fh>) {
8801 chomp($line);
8802
8803 if ($line eq 'ABOR') {
8804 $saw_abor = 1;
8805 last;
8806 }
8807 }
8808
8809 close($fh);
8810
8811 $self->assert($saw_abor,
8812 test_msg("Expected to see ABOR in ExtendedLog, did not"));
8813
8814 } else {
8815 die("Can't read $ext_log: $!");
8816 }
8817 };
8818
8819 if ($@) {
8820 $ex = $@;
8821 }
8822
8823 if ($ex) {
8824 test_append_logfile($log_file, $ex);
8825 unlink($log_file);
8826
8827 die($ex);
8828 }
8829
8830 unlink($log_file);
8831 }
8832
8833 sub extlog_xfer_status_nonxfer {
8834 my $self = shift;
8835 my $tmpdir = $self->{tmpdir};
8836
8837 my $config_file = "$tmpdir/extlog.conf";
8838 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
8839 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
8840
8841 my $log_file = test_get_logfile();
8842
8843 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
8844 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
8845
8846 my $user = 'proftpd';
8847 my $passwd = 'test';
8848 my $group = 'ftpd';
8849 my $home_dir = File::Spec->rel2abs($tmpdir);
8850 my $uid = 500;
8851 my $gid = 500;
8852
8853 # Make sure that, if we're running as root, that the home directory has
8854 # permissions/privs set for the account we create
8855 if ($< == 0) {
8856 unless (chmod(0755, $home_dir)) {
8857 die("Can't set perms on $home_dir to 0755: $!");
8858 }
8859
8860 unless (chown($uid, $gid, $home_dir)) {
8861 die("Can't set owner of $home_dir to $uid/$gid: $!");
8862 }
8863 }
8864
8865 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8866 '/bin/bash');
8867 auth_group_write($auth_group_file, $group, $gid, $user);
8868
8869 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
8870
8871 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
8872 if (open(my $fh, "> $test_file")) {
8873 print $fh "A" x 1024;
8874
8875 unless (close($fh)) {
8876 die("Can't write $test_file: $!");
8877 }
8878
8879 } else {
8880 die("Can't open $test_file: $!");
8881 }
8882
8883 my $config = {
8884 PidFile => $pid_file,
8885 ScoreboardFile => $scoreboard_file,
8886 SystemLog => $log_file,
8887
8888 AuthUserFile => $auth_user_file,
8889 AuthGroupFile => $auth_group_file,
8890 AuthOrder => 'mod_auth_file.c',
8891
8892 IfModules => {
8893 'mod_delay.c' => {
8894 DelayEngine => 'off',
8895 },
8896 },
8897 };
8898
8899 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8900
8901 if (open(my $fh, ">> $config_file")) {
8902 print $fh <<EOC;
8903 LogFormat custom "%m %{transfer-status}"
8904 ExtendedLog $ext_log ALL custom
8905 EOC
8906 unless (close($fh)) {
8907 die("Can't write $config_file: $!");
8908 }
8909
8910 } else {
8911 die("Can't open $config_file: $!");
8912 }
8913
8914 # Open pipes, for use between the parent and child processes. Specifically,
8915 # the child will indicate when it's done with its test by writing a message
8916 # to the parent.
8917 my ($rfh, $wfh);
8918 unless (pipe($rfh, $wfh)) {
8919 die("Can't open pipe: $!");
8920 }
8921
8922 my $ex;
8923
8924 # Fork child
8925 $self->handle_sigchld();
8926 defined(my $pid = fork()) or die("Can't fork: $!");
8927 if ($pid) {
8928 eval {
8929 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
8930 $client->login($user, $passwd);
8931 $client->pwd();
8932 $client->quit();
8933 };
8934
8935 if ($@) {
8936 $ex = $@;
8937 }
8938
8939 $wfh->print("done\n");
8940 $wfh->flush();
8941
8942 } else {
8943 eval { server_wait($config_file, $rfh) };
8944 if ($@) {
8945 warn($@);
8946 exit 1;
8947 }
8948
8949 exit 0;
8950 }
8951
8952 # Stop server
8953 server_stop($pid_file);
8954
8955 $self->assert_child_ok($pid);
8956
8957 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
8958 # variable was properly written out.
8959 eval {
8960 if (open(my $fh, "< $ext_log")) {
8961 my $unexpected_xfer_status = 0;
8962
8963 while (my $line = <$fh>) {
8964 chomp($line);
8965
8966 if ($line =~ /^(\S+) (.*)?$/) {
8967 my $cmd = $1;
8968 my $xfer_status = $2;
8969
8970 if ($xfer_status ne '-') {
8971 $unexpected_xfer_status = 1;
8972 last;
8973 }
8974 }
8975 }
8976
8977 close($fh);
8978
8979 $self->assert(!$unexpected_xfer_status,
8980 test_msg("Saw unexpected transfer status in ExtendedLog"));
8981
8982 } else {
8983 die("Can't read $ext_log: $!");
8984 }
8985 };
8986
8987 if ($@) {
8988 $ex = $@;
8989 }
8990
8991 if ($ex) {
8992 test_append_logfile($log_file, $ex);
8993 unlink($log_file);
8994
8995 die($ex);
8996 }
8997
8998 unlink($log_file);
8999 }
9000
9001 sub extlog_xfer_status_success {
9002 my $self = shift;
9003 my $tmpdir = $self->{tmpdir};
9004
9005 my $config_file = "$tmpdir/extlog.conf";
9006 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
9007 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
9008
9009 my $log_file = test_get_logfile();
9010
9011 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
9012 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
9013
9014 my $user = 'proftpd';
9015 my $passwd = 'test';
9016 my $group = 'ftpd';
9017 my $home_dir = File::Spec->rel2abs($tmpdir);
9018 my $uid = 500;
9019 my $gid = 500;
9020
9021 # Make sure that, if we're running as root, that the home directory has
9022 # permissions/privs set for the account we create
9023 if ($< == 0) {
9024 unless (chmod(0755, $home_dir)) {
9025 die("Can't set perms on $home_dir to 0755: $!");
9026 }
9027
9028 unless (chown($uid, $gid, $home_dir)) {
9029 die("Can't set owner of $home_dir to $uid/$gid: $!");
9030 }
9031 }
9032
9033 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9034 '/bin/bash');
9035 auth_group_write($auth_group_file, $group, $gid, $user);
9036
9037 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
9038
9039 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9040 if (open(my $fh, "> $test_file")) {
9041 print $fh "A" x 1024;
9042
9043 unless (close($fh)) {
9044 die("Can't write $test_file: $!");
9045 }
9046
9047 } else {
9048 die("Can't open $test_file: $!");
9049 }
9050
9051 my $config = {
9052 PidFile => $pid_file,
9053 ScoreboardFile => $scoreboard_file,
9054 SystemLog => $log_file,
9055
9056 AuthUserFile => $auth_user_file,
9057 AuthGroupFile => $auth_group_file,
9058 AuthOrder => 'mod_auth_file.c',
9059
9060 IfModules => {
9061 'mod_delay.c' => {
9062 DelayEngine => 'off',
9063 },
9064 },
9065 };
9066
9067 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9068
9069 if (open(my $fh, ">> $config_file")) {
9070 print $fh <<EOC;
9071 LogFormat custom "%m %{transfer-status}"
9072 ExtendedLog $ext_log ALL custom
9073 EOC
9074 unless (close($fh)) {
9075 die("Can't write $config_file: $!");
9076 }
9077
9078 } else {
9079 die("Can't open $config_file: $!");
9080 }
9081
9082 # Open pipes, for use between the parent and child processes. Specifically,
9083 # the child will indicate when it's done with its test by writing a message
9084 # to the parent.
9085 my ($rfh, $wfh);
9086 unless (pipe($rfh, $wfh)) {
9087 die("Can't open pipe: $!");
9088 }
9089
9090 my $ex;
9091
9092 # Fork child
9093 $self->handle_sigchld();
9094 defined(my $pid = fork()) or die("Can't fork: $!");
9095 if ($pid) {
9096 eval {
9097 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
9098 $client->login($user, $passwd);
9099
9100 my $conn = $client->retr_raw('test.txt');
9101 unless ($conn) {
9102 die("RETR test.txt failed: " . $client->response_code() . " " .
9103 $client->response_code());
9104 }
9105
9106 my $buf;
9107 while ($conn->read($buf, 16382, 25)) {
9108 }
9109 eval { $conn->close() };
9110
9111 my $resp_code = $client->response_code();
9112 my $resp_msg = $client->response_msg();
9113
9114 $self->assert_transfer_ok($resp_code, $resp_msg);
9115 $client->quit();
9116 };
9117
9118 if ($@) {
9119 $ex = $@;
9120 }
9121
9122 $wfh->print("done\n");
9123 $wfh->flush();
9124
9125 } else {
9126 eval { server_wait($config_file, $rfh) };
9127 if ($@) {
9128 warn($@);
9129 exit 1;
9130 }
9131
9132 exit 0;
9133 }
9134
9135 # Stop server
9136 server_stop($pid_file);
9137
9138 $self->assert_child_ok($pid);
9139
9140 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
9141 # variable was properly written out.
9142 eval {
9143 if (open(my $fh, "< $ext_log")) {
9144 my $expected_xfer_status = 0;
9145
9146 while (my $line = <$fh>) {
9147 chomp($line);
9148
9149 if ($line =~ /^(\S+) (.*)?$/) {
9150 my $cmd = $1;
9151 my $xfer_status = $2;
9152
9153 if ($cmd eq 'RETR') {
9154 if ($xfer_status eq 'success') {
9155 $expected_xfer_status = 1;
9156 last;
9157 }
9158 }
9159 }
9160 }
9161
9162 close($fh);
9163
9164 $self->assert($expected_xfer_status,
9165 test_msg("Did not see expected transfer status in ExtendedLog"));
9166
9167 } else {
9168 die("Can't read $ext_log: $!");
9169 }
9170 };
9171
9172 if ($@) {
9173 $ex = $@;
9174 }
9175
9176 if ($ex) {
9177 test_append_logfile($log_file, $ex);
9178 unlink($log_file);
9179
9180 die($ex);
9181 }
9182
9183 unlink($log_file);
9184 }
9185
9186 sub extlog_xfer_status_cancelled {
9187 my $self = shift;
9188 my $tmpdir = $self->{tmpdir};
9189
9190 my $config_file = "$tmpdir/extlog.conf";
9191 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
9192 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
9193
9194 my $log_file = test_get_logfile();
9195
9196 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
9197 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
9198
9199 my $user = 'proftpd';
9200 my $passwd = 'test';
9201 my $group = 'ftpd';
9202 my $home_dir = File::Spec->rel2abs($tmpdir);
9203 my $uid = 500;
9204 my $gid = 500;
9205
9206 # Make sure that, if we're running as root, that the home directory has
9207 # permissions/privs set for the account we create
9208 if ($< == 0) {
9209 unless (chmod(0755, $home_dir)) {
9210 die("Can't set perms on $home_dir to 0755: $!");
9211 }
9212
9213 unless (chown($uid, $gid, $home_dir)) {
9214 die("Can't set owner of $home_dir to $uid/$gid: $!");
9215 }
9216 }
9217
9218 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9219 '/bin/bash');
9220 auth_group_write($auth_group_file, $group, $gid, $user);
9221
9222 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
9223
9224 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9225 if (open(my $fh, "> $test_file")) {
9226 print $fh "ABCDefgh" x 32768;
9227
9228 unless (close($fh)) {
9229 die("Can't write $test_file: $!");
9230 }
9231
9232 } else {
9233 die("Can't open $test_file: $!");
9234 }
9235
9236 my $config = {
9237 PidFile => $pid_file,
9238 ScoreboardFile => $scoreboard_file,
9239 SystemLog => $log_file,
9240
9241 AuthUserFile => $auth_user_file,
9242 AuthGroupFile => $auth_group_file,
9243 AuthOrder => 'mod_auth_file.c',
9244
9245 IfModules => {
9246 'mod_delay.c' => {
9247 DelayEngine => 'off',
9248 },
9249 },
9250 };
9251
9252 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9253
9254 if (open(my $fh, ">> $config_file")) {
9255 print $fh <<EOC;
9256 LogFormat custom "%m %{transfer-status}"
9257 ExtendedLog $ext_log ALL custom
9258 EOC
9259 unless (close($fh)) {
9260 die("Can't write $config_file: $!");
9261 }
9262
9263 } else {
9264 die("Can't open $config_file: $!");
9265 }
9266
9267 # Open pipes, for use between the parent and child processes. Specifically,
9268 # the child will indicate when it's done with its test by writing a message
9269 # to the parent.
9270 my ($rfh, $wfh);
9271 unless (pipe($rfh, $wfh)) {
9272 die("Can't open pipe: $!");
9273 }
9274
9275 my $ex;
9276
9277 # Fork child
9278 $self->handle_sigchld();
9279 defined(my $pid = fork()) or die("Can't fork: $!");
9280 if ($pid) {
9281 eval {
9282 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
9283 $client->login($user, $passwd);
9284
9285 my $conn = $client->retr_raw('test.txt');
9286 unless ($conn) {
9287 die("RETR test.txt failed: " . $client->response_code() . " " .
9288 $client->response_code());
9289 }
9290
9291 my $buf;
9292 $conn->read($buf, 12, 25);
9293 eval { $conn->abort() };
9294
9295 my $resp_code = $client->response_code();
9296 my $resp_msg = $client->response_msg();
9297
9298 $self->assert_transfer_ok($resp_code, $resp_msg, 1);
9299 $client->quit();
9300 };
9301
9302 if ($@) {
9303 $ex = $@;
9304 }
9305
9306 $wfh->print("done\n");
9307 $wfh->flush();
9308
9309 } else {
9310 eval { server_wait($config_file, $rfh) };
9311 if ($@) {
9312 warn($@);
9313 exit 1;
9314 }
9315
9316 exit 0;
9317 }
9318
9319 # Stop server
9320 server_stop($pid_file);
9321
9322 $self->assert_child_ok($pid);
9323
9324 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
9325 # variable was properly written out.
9326 eval {
9327 if (open(my $fh, "< $ext_log")) {
9328 my $expected_xfer_status = 0;
9329
9330 while (my $line = <$fh>) {
9331 chomp($line);
9332
9333 if ($line =~ /^(\S+) (.*)?$/) {
9334 my $cmd = $1;
9335 my $xfer_status = $2;
9336
9337 if ($cmd eq 'RETR') {
9338 if ($xfer_status eq 'cancelled') {
9339 $expected_xfer_status = 1;
9340 last;
9341 }
9342 }
9343 }
9344 }
9345
9346 close($fh);
9347
9348 $self->assert($expected_xfer_status,
9349 test_msg("Did not see expected transfer status in ExtendedLog"));
9350
9351 } else {
9352 die("Can't read $ext_log: $!");
9353 }
9354 };
9355
9356 if ($@) {
9357 $ex = $@;
9358 }
9359
9360 if ($ex) {
9361 test_append_logfile($log_file, $ex);
9362 unlink($log_file);
9363
9364 die($ex);
9365 }
9366
9367 unlink($log_file);
9368 }
9369
9370 sub extlog_xfer_status_failed {
9371 my $self = shift;
9372 my $tmpdir = $self->{tmpdir};
9373
9374 my $config_file = "$tmpdir/extlog.conf";
9375 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
9376 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
9377
9378 my $log_file = test_get_logfile();
9379
9380 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
9381 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
9382
9383 my $user = 'proftpd';
9384 my $passwd = 'test';
9385 my $group = 'ftpd';
9386 my $home_dir = File::Spec->rel2abs($tmpdir);
9387 my $uid = 500;
9388 my $gid = 500;
9389
9390 # Make sure that, if we're running as root, that the home directory has
9391 # permissions/privs set for the account we create
9392 if ($< == 0) {
9393 unless (chmod(0755, $home_dir)) {
9394 die("Can't set perms on $home_dir to 0755: $!");
9395 }
9396
9397 unless (chown($uid, $gid, $home_dir)) {
9398 die("Can't set owner of $home_dir to $uid/$gid: $!");
9399 }
9400 }
9401
9402 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9403 '/bin/bash');
9404 auth_group_write($auth_group_file, $group, $gid, $user);
9405
9406 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
9407
9408 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9409 if (open(my $fh, "> $test_file")) {
9410 print $fh "ABCDefgh" x 32768;
9411
9412 unless (close($fh)) {
9413 die("Can't write $test_file: $!");
9414 }
9415
9416 } else {
9417 die("Can't open $test_file: $!");
9418 }
9419
9420 my $config = {
9421 PidFile => $pid_file,
9422 ScoreboardFile => $scoreboard_file,
9423 SystemLog => $log_file,
9424
9425 AuthUserFile => $auth_user_file,
9426 AuthGroupFile => $auth_group_file,
9427 AuthOrder => 'mod_auth_file.c',
9428
9429 # This is used to trigger a download failure
9430 MaxRetrieveFileSize => '12 B',
9431
9432 IfModules => {
9433 'mod_delay.c' => {
9434 DelayEngine => 'off',
9435 },
9436 },
9437 };
9438
9439 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9440
9441 if (open(my $fh, ">> $config_file")) {
9442 print $fh <<EOC;
9443 LogFormat custom "%m %{transfer-status}"
9444 ExtendedLog $ext_log ALL custom
9445 EOC
9446 unless (close($fh)) {
9447 die("Can't write $config_file: $!");
9448 }
9449
9450 } else {
9451 die("Can't open $config_file: $!");
9452 }
9453
9454 # Open pipes, for use between the parent and child processes. Specifically,
9455 # the child will indicate when it's done with its test by writing a message
9456 # to the parent.
9457 my ($rfh, $wfh);
9458 unless (pipe($rfh, $wfh)) {
9459 die("Can't open pipe: $!");
9460 }
9461
9462 my $ex;
9463
9464 # Fork child
9465 $self->handle_sigchld();
9466 defined(my $pid = fork()) or die("Can't fork: $!");
9467 if ($pid) {
9468 eval {
9469 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
9470 $client->login($user, $passwd);
9471
9472 my $conn = $client->retr_raw('test.txt');
9473 unless ($conn) {
9474 die("RETR test.txt failed: " . $client->response_code() . " " .
9475 $client->response_code());
9476 }
9477
9478 my $buf;
9479 $conn->read($buf, 12, 25);
9480 eval { $conn->abort() };
9481
9482 my $resp_code = $client->response_code();
9483 my $resp_msg = $client->response_msg();
9484
9485 my $expected = 426;
9486 $self->assert($expected == $resp_code,
9487 test_msg("Expected response code $expected, got $resp_code"));
9488
9489 $expected = 'Transfer aborted';
9490 $self->assert(qr/$expected/, $resp_msg,
9491 test_msg("Expected response message '$expected', got '$resp_msg'"));
9492 };
9493
9494 if ($@) {
9495 $ex = $@;
9496 }
9497
9498 $wfh->print("done\n");
9499 $wfh->flush();
9500
9501 } else {
9502 eval { server_wait($config_file, $rfh) };
9503 if ($@) {
9504 warn($@);
9505 exit 1;
9506 }
9507
9508 exit 0;
9509 }
9510
9511 # Stop server
9512 server_stop($pid_file);
9513
9514 $self->assert_child_ok($pid);
9515
9516 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
9517 # variable was properly written out.
9518 eval {
9519 if (open(my $fh, "< $ext_log")) {
9520 my $expected_xfer_status = 0;
9521
9522 while (my $line = <$fh>) {
9523 chomp($line);
9524
9525 if ($line =~ /^(\S+) (.*)?$/) {
9526 my $cmd = $1;
9527 my $xfer_status = $2;
9528
9529 if ($cmd eq 'RETR') {
9530 if ($xfer_status eq 'failed') {
9531 $expected_xfer_status = 1;
9532 last;
9533 }
9534 }
9535 }
9536 }
9537
9538 close($fh);
9539
9540 $self->assert($expected_xfer_status,
9541 test_msg("Did not see expected transfer status in ExtendedLog"));
9542
9543 } else {
9544 die("Can't read $ext_log: $!");
9545 }
9546 };
9547
9548 if ($@) {
9549 $ex = $@;
9550 }
9551
9552 if ($ex) {
9553 test_append_logfile($log_file, $ex);
9554 unlink($log_file);
9555
9556 die($ex);
9557 }
9558
9559 unlink($log_file);
9560 }
9561
9562 sub extlog_xfer_status_timeout {
9563 my $self = shift;
9564 my $tmpdir = $self->{tmpdir};
9565 my $setup = test_setup($tmpdir, 'extlog');
9566
9567 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
9568
9569 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9570 if (open(my $fh, "> $test_file")) {
9571 print $fh "ABCDefghIJKLmnop" x 65536;
9572
9573 unless (close($fh)) {
9574 die("Can't write $test_file: $!");
9575 }
9576
9577 } else {
9578 die("Can't open $test_file: $!");
9579 }
9580
9581 my $timeout_stalled = 1;
9582
9583 my $config = {
9584 PidFile => $setup->{pid_file},
9585 ScoreboardFile => $setup->{scoreboard_file},
9586 SystemLog => $setup->{log_file},
9587
9588 AuthUserFile => $setup->{auth_user_file},
9589 AuthGroupFile => $setup->{auth_group_file},
9590 AuthOrder => 'mod_auth_file.c',
9591
9592 # This is used to tickle the "timeout" transfer status
9593 TimeoutStalled => $timeout_stalled,
9594
9595 IfModules => {
9596 'mod_delay.c' => {
9597 DelayEngine => 'off',
9598 },
9599 },
9600 };
9601
9602 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
9603 $config);
9604
9605 if (open(my $fh, ">> $setup->{config_file}")) {
9606 print $fh <<EOC;
9607 LogFormat custom "%m %{transfer-status}"
9608 ExtendedLog $ext_log READ custom
9609 EOC
9610 unless (close($fh)) {
9611 die("Can't write $setup->{config_file}: $!");
9612 }
9613
9614 } else {
9615 die("Can't open $setup->{config_file}: $!");
9616 }
9617
9618 # Open pipes, for use between the parent and child processes. Specifically,
9619 # the child will indicate when it's done with its test by writing a message
9620 # to the parent.
9621 my ($rfh, $wfh);
9622 unless (pipe($rfh, $wfh)) {
9623 die("Can't open pipe: $!");
9624 }
9625
9626 my $ex;
9627
9628 # Fork child
9629 $self->handle_sigchld();
9630 defined(my $pid = fork()) or die("Can't fork: $!");
9631 if ($pid) {
9632 eval {
9633 # Allow for server startup
9634 sleep(1);
9635
9636 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
9637 $client->login($setup->{user}, $setup->{passwd});
9638 $client->type('ascii');
9639
9640 my $conn = $client->retr_raw('test.txt');
9641 unless ($conn) {
9642 die("RETR test.txt failed: " . $client->response_code() . " " .
9643 $client->response_code());
9644 }
9645
9646 sleep($timeout_stalled + 1);
9647
9648 my $buf;
9649 $conn->read($buf, 32, 25);
9650 sleep($timeout_stalled);
9651 eval { $conn->close() };
9652
9653 eval { $client->noop() };
9654 unless ($@) {
9655 die("NOOP succeeded unexpectedly");
9656 }
9657
9658 my $resp_code = $client->response_code();
9659 my $resp_msg = $client->response_msg();
9660
9661 # Perl's Net::Cmd module uses a very non-standard 599 code to
9662 # indicate that the connection is closed, depending on version.
9663 $self->assert($resp_code == 421 || $resp_code == 599,
9664 test_msg("Expected response code 421 or 599, got $resp_code"));
9665
9666 my $expected = "Connection closed";
9667 $self->assert(qr/$expected/, $resp_msg,
9668 test_msg("Expected response message '$expected', got '$resp_msg'"));
9669 };
9670 if ($@) {
9671 $ex = $@;
9672 }
9673
9674 $wfh->print("done\n");
9675 $wfh->flush();
9676
9677 } else {
9678 eval { server_wait($setup->{config_file}, $rfh) };
9679 if ($@) {
9680 warn($@);
9681 exit 1;
9682 }
9683
9684 exit 0;
9685 }
9686
9687 # Stop server
9688 server_stop($setup->{pid_file});
9689 $self->assert_child_ok($pid);
9690
9691 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
9692 # variable was properly written out.
9693 eval {
9694 if (open(my $fh, "< $ext_log")) {
9695 my $expected_xfer_status = 0;
9696
9697 while (my $line = <$fh>) {
9698 chomp($line);
9699
9700 if ($ENV{TEST_VERBOSE}) {
9701 print STDERR "# $line\n";
9702 }
9703
9704 if ($line =~ /^(\S+) (.*)?$/) {
9705 my $cmd = $1;
9706 my $xfer_status = $2;
9707
9708 if ($cmd eq 'RETR') {
9709 if ($xfer_status eq 'timeout') {
9710 $expected_xfer_status = 1;
9711 last;
9712 }
9713 }
9714 }
9715 }
9716
9717 close($fh);
9718
9719 $self->assert($expected_xfer_status,
9720 test_msg("Did not see expected transfer status in ExtendedLog"));
9721
9722 } else {
9723 die("Can't read $ext_log: $!");
9724 }
9725 };
9726 if ($@) {
9727 $ex = $@;
9728 }
9729
9730 test_cleanup($setup->{log_file}, $ex);
9731 }
9732
9733 sub extlog_xfer_failure_none {
9734 my $self = shift;
9735 my $tmpdir = $self->{tmpdir};
9736
9737 my $config_file = "$tmpdir/extlog.conf";
9738 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
9739 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
9740
9741 my $log_file = test_get_logfile();
9742
9743 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
9744 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
9745
9746 my $user = 'proftpd';
9747 my $passwd = 'test';
9748 my $group = 'ftpd';
9749 my $home_dir = File::Spec->rel2abs($tmpdir);
9750 my $uid = 500;
9751 my $gid = 500;
9752
9753 # Make sure that, if we're running as root, that the home directory has
9754 # permissions/privs set for the account we create
9755 if ($< == 0) {
9756 unless (chmod(0755, $home_dir)) {
9757 die("Can't set perms on $home_dir to 0755: $!");
9758 }
9759
9760 unless (chown($uid, $gid, $home_dir)) {
9761 die("Can't set owner of $home_dir to $uid/$gid: $!");
9762 }
9763 }
9764
9765 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9766 '/bin/bash');
9767 auth_group_write($auth_group_file, $group, $gid, $user);
9768
9769 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
9770
9771 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9772 if (open(my $fh, "> $test_file")) {
9773 print $fh "A" x 1024;
9774
9775 unless (close($fh)) {
9776 die("Can't write $test_file: $!");
9777 }
9778
9779 } else {
9780 die("Can't open $test_file: $!");
9781 }
9782
9783 my $config = {
9784 PidFile => $pid_file,
9785 ScoreboardFile => $scoreboard_file,
9786 SystemLog => $log_file,
9787
9788 AuthUserFile => $auth_user_file,
9789 AuthGroupFile => $auth_group_file,
9790 AuthOrder => 'mod_auth_file.c',
9791
9792 IfModules => {
9793 'mod_delay.c' => {
9794 DelayEngine => 'off',
9795 },
9796 },
9797 };
9798
9799 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9800
9801 if (open(my $fh, ">> $config_file")) {
9802 print $fh <<EOC;
9803 LogFormat custom "%m %{transfer-failure}"
9804 ExtendedLog $ext_log ALL custom
9805 EOC
9806 unless (close($fh)) {
9807 die("Can't write $config_file: $!");
9808 }
9809
9810 } else {
9811 die("Can't open $config_file: $!");
9812 }
9813
9814 # Open pipes, for use between the parent and child processes. Specifically,
9815 # the child will indicate when it's done with its test by writing a message
9816 # to the parent.
9817 my ($rfh, $wfh);
9818 unless (pipe($rfh, $wfh)) {
9819 die("Can't open pipe: $!");
9820 }
9821
9822 my $ex;
9823
9824 # Fork child
9825 $self->handle_sigchld();
9826 defined(my $pid = fork()) or die("Can't fork: $!");
9827 if ($pid) {
9828 eval {
9829 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
9830 $client->login($user, $passwd);
9831
9832 my $conn = $client->retr_raw('test.txt');
9833 unless ($conn) {
9834 die("RETR test.txt failed: " . $client->response_code() . " " .
9835 $client->response_code());
9836 }
9837
9838 my $buf;
9839 while ($conn->read($buf, 16382, 25)) {
9840 }
9841 eval { $conn->close() };
9842
9843 my $resp_code = $client->response_code();
9844 my $resp_msg = $client->response_msg();
9845
9846 $self->assert_transfer_ok($resp_code, $resp_msg);
9847 $client->quit();
9848 };
9849
9850 if ($@) {
9851 $ex = $@;
9852 }
9853
9854 $wfh->print("done\n");
9855 $wfh->flush();
9856
9857 } else {
9858 eval { server_wait($config_file, $rfh) };
9859 if ($@) {
9860 warn($@);
9861 exit 1;
9862 }
9863
9864 exit 0;
9865 }
9866
9867 # Stop server
9868 server_stop($pid_file);
9869
9870 $self->assert_child_ok($pid);
9871
9872 # Now, read in the ExtendedLog, and see whether the %{transfer-failure}
9873 # variable was properly written out.
9874 eval {
9875 if (open(my $fh, "< $ext_log")) {
9876 my $unexpected_xfer_failure = 0;
9877
9878 while (my $line = <$fh>) {
9879 chomp($line);
9880
9881 if ($line =~ /^(\S+) (.*)?$/) {
9882 my $cmd = $1;
9883 my $xfer_failure = $2;
9884
9885 if ($xfer_failure ne '-') {
9886 $unexpected_xfer_failure = 1;
9887 last;
9888 }
9889 }
9890 }
9891
9892 close($fh);
9893
9894 $self->assert(!$unexpected_xfer_failure,
9895 test_msg("Saw unexpected transfer failure/reason in ExtendedLog"));
9896
9897 } else {
9898 die("Can't read $ext_log: $!");
9899 }
9900 };
9901
9902 if ($@) {
9903 $ex = $@;
9904 }
9905
9906 if ($ex) {
9907 test_append_logfile($log_file, $ex);
9908 unlink($log_file);
9909
9910 die($ex);
9911 }
9912
9913 unlink($log_file);
9914 }
9915
9916 sub extlog_xfer_failure_reason {
9917 my $self = shift;
9918 my $tmpdir = $self->{tmpdir};
9919
9920 my $config_file = "$tmpdir/extlog.conf";
9921 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
9922 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
9923
9924 my $log_file = test_get_logfile();
9925
9926 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
9927 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
9928
9929 my $user = 'proftpd';
9930 my $passwd = 'test';
9931 my $group = 'ftpd';
9932 my $home_dir = File::Spec->rel2abs($tmpdir);
9933 my $uid = 500;
9934 my $gid = 500;
9935
9936 # Make sure that, if we're running as root, that the home directory has
9937 # permissions/privs set for the account we create
9938 if ($< == 0) {
9939 unless (chmod(0755, $home_dir)) {
9940 die("Can't set perms on $home_dir to 0755: $!");
9941 }
9942
9943 unless (chown($uid, $gid, $home_dir)) {
9944 die("Can't set owner of $home_dir to $uid/$gid: $!");
9945 }
9946 }
9947
9948 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9949 '/bin/bash');
9950 auth_group_write($auth_group_file, $group, $gid, $user);
9951
9952 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
9953
9954 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9955 if (open(my $fh, "> $test_file")) {
9956 print $fh "ABCDefgh" x 32768;
9957
9958 unless (close($fh)) {
9959 die("Can't write $test_file: $!");
9960 }
9961
9962 } else {
9963 die("Can't open $test_file: $!");
9964 }
9965
9966 my $config = {
9967 PidFile => $pid_file,
9968 ScoreboardFile => $scoreboard_file,
9969 SystemLog => $log_file,
9970
9971 AuthUserFile => $auth_user_file,
9972 AuthGroupFile => $auth_group_file,
9973 AuthOrder => 'mod_auth_file.c',
9974
9975 # This is used to trigger a download failure
9976 MaxRetrieveFileSize => '12 B',
9977
9978 IfModules => {
9979 'mod_delay.c' => {
9980 DelayEngine => 'off',
9981 },
9982 },
9983 };
9984
9985 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9986
9987 if (open(my $fh, ">> $config_file")) {
9988 print $fh <<EOC;
9989 LogFormat custom "%m %{transfer-failure}"
9990 ExtendedLog $ext_log ALL custom
9991 EOC
9992 unless (close($fh)) {
9993 die("Can't write $config_file: $!");
9994 }
9995
9996 } else {
9997 die("Can't open $config_file: $!");
9998 }
9999
10000 # Open pipes, for use between the parent and child processes. Specifically,
10001 # the child will indicate when it's done with its test by writing a message
10002 # to the parent.
10003 my ($rfh, $wfh);
10004 unless (pipe($rfh, $wfh)) {
10005 die("Can't open pipe: $!");
10006 }
10007
10008 my $ex;
10009
10010 # Fork child
10011 $self->handle_sigchld();
10012 defined(my $pid = fork()) or die("Can't fork: $!");
10013 if ($pid) {
10014 eval {
10015 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
10016 $client->login($user, $passwd);
10017
10018 my $conn = $client->retr_raw('test.txt');
10019 unless ($conn) {
10020 die("RETR test.txt failed: " . $client->response_code() . " " .
10021 $client->response_code());
10022 }
10023
10024 my $buf;
10025 $conn->read($buf, 12, 25);
10026 eval { $conn->abort() };
10027
10028 my $resp_code = $client->response_code();
10029 my $resp_msg = $client->response_msg();
10030
10031 my $expected = 426;
10032 $self->assert($expected == $resp_code,
10033 test_msg("Expected response code $expected, got $resp_code"));
10034
10035 $expected = 'Transfer aborted';
10036 $self->assert(qr/$expected/, $resp_msg,
10037 test_msg("Expected response message '$expected', got '$resp_msg'"));
10038 };
10039
10040 if ($@) {
10041 $ex = $@;
10042 }
10043
10044 $wfh->print("done\n");
10045 $wfh->flush();
10046
10047 } else {
10048 eval { server_wait($config_file, $rfh) };
10049 if ($@) {
10050 warn($@);
10051 exit 1;
10052 }
10053
10054 exit 0;
10055 }
10056
10057 # Stop server
10058 server_stop($pid_file);
10059
10060 $self->assert_child_ok($pid);
10061
10062 # Now, read in the ExtendedLog, and see whether the %{transfer-failure}
10063 # variable was properly written out.
10064 eval {
10065 if (open(my $fh, "< $ext_log")) {
10066 my $expected_xfer_reason = 0;
10067
10068 while (my $line = <$fh>) {
10069 chomp($line);
10070
10071 if ($ENV{TEST_VERBOSE}) {
10072 print STDERR "# $line\n";
10073 }
10074
10075 if ($line =~ /^(\S+) (.*)?$/) {
10076 my $cmd = $1;
10077 my $xfer_failure = $2;
10078
10079 if ($cmd eq 'RETR') {
10080 if ($xfer_failure eq 'Operation not permitted') {
10081 $expected_xfer_reason = 1;
10082 last;
10083 }
10084 }
10085 }
10086 }
10087
10088 close($fh);
10089
10090 $self->assert($expected_xfer_reason,
10091 test_msg("Did not see expected transfer failure/reason in ExtendedLog"));
10092
10093 } else {
10094 die("Can't read $ext_log: $!");
10095 }
10096 };
10097
10098 if ($@) {
10099 $ex = $@;
10100 }
10101
10102 if ($ex) {
10103 test_append_logfile($log_file, $ex);
10104 unlink($log_file);
10105
10106 die($ex);
10107 }
10108
10109 unlink($log_file);
10110 }
10111
10112 sub ftps_data_xfer_cancelled_cb {
10113 my $func_name = shift;
10114 my $data = shift;
10115 my $data_len = shift;
10116 my $total_len = shift;
10117 my $user_data = shift;
10118
10119 if ($total_len > 0) {
10120 $user_data->close();
10121 die("$func_name failed due to test callback (len $total_len > 0)");
10122 }
10123 }
10124
10125 sub ftps_data_close_db {
10126 my $func_name = shift;
10127 my $data = shift;
10128 my $data_len = shift;
10129 my $total_len = shift;
10130 my $user_data = shift;
10131
10132 return undef;
10133 }
10134
10135 sub extlog_ftps_xfer_status_cancelled {
10136 my $self = shift;
10137 my $tmpdir = $self->{tmpdir};
10138
10139 my $config_file = "$tmpdir/extlog.conf";
10140 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
10141 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
10142
10143 my $log_file = test_get_logfile();
10144
10145 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
10146 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
10147
10148 my $user = 'proftpd';
10149 my $passwd = 'test';
10150 my $group = 'ftpd';
10151 my $home_dir = File::Spec->rel2abs($tmpdir);
10152 my $uid = 500;
10153 my $gid = 500;
10154
10155 # Make sure that, if we're running as root, that the home directory has
10156 # permissions/privs set for the account we create
10157 if ($< == 0) {
10158 unless (chmod(0755, $home_dir)) {
10159 die("Can't set perms on $home_dir to 0755: $!");
10160 }
10161
10162 unless (chown($uid, $gid, $home_dir)) {
10163 die("Can't set owner of $home_dir to $uid/$gid: $!");
10164 }
10165 }
10166
10167 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10168 '/bin/bash');
10169 auth_group_write($auth_group_file, $group, $gid, $user);
10170
10171 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
10172 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10173
10174 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
10175
10176 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
10177 if (open(my $fh, "> $test_file")) {
10178 print $fh "ABCDefgh" x 32768;
10179
10180 unless (close($fh)) {
10181 die("Can't write $test_file: $!");
10182 }
10183
10184 } else {
10185 die("Can't open $test_file: $!");
10186 }
10187
10188 my $timeout_idle = 20;
10189
10190 my $config = {
10191 PidFile => $pid_file,
10192 ScoreboardFile => $scoreboard_file,
10193 SystemLog => $log_file,
10194 TraceLog => $log_file,
10195 Trace => 'DEFAULT:10 data:20 tls:20',
10196
10197 AuthUserFile => $auth_user_file,
10198 AuthGroupFile => $auth_group_file,
10199 AuthOrder => 'mod_auth_file.c',
10200
10201 TimeoutIdle => $timeout_idle,
10202
10203 IfModules => {
10204 'mod_delay.c' => {
10205 DelayEngine => 'off',
10206 },
10207
10208 'mod_tls.c' => {
10209 TLSEngine => 'on',
10210 TLSLog => $log_file,
10211 TLSRequired => 'on',
10212 TLSRSACertificateFile => $cert_file,
10213 TLSCACertificateFile => $ca_file,
10214 TLSOptions => 'NoSessionReuseRequired',
10215 },
10216 },
10217 };
10218
10219 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10220
10221 if (open(my $fh, ">> $config_file")) {
10222 print $fh <<EOC;
10223 LogFormat custom "%m %{transfer-status}"
10224 ExtendedLog $ext_log ALL custom
10225 EOC
10226 unless (close($fh)) {
10227 die("Can't write $config_file: $!");
10228 }
10229
10230 } else {
10231 die("Can't open $config_file: $!");
10232 }
10233
10234 # Open pipes, for use between the parent and child processes. Specifically,
10235 # the child will indicate when it's done with its test by writing a message
10236 # to the parent.
10237 my ($rfh, $wfh);
10238 unless (pipe($rfh, $wfh)) {
10239 die("Can't open pipe: $!");
10240 }
10241
10242 require Net::FTPSSL;
10243
10244 my $ex;
10245
10246 # Fork child
10247 $self->handle_sigchld();
10248 defined(my $pid = fork()) or die("Can't fork: $!");
10249 if ($pid) {
10250 eval {
10251 # Give the server a chance to start up
10252 sleep(2);
10253
10254 my $client = Net::FTPSSL->new('127.0.0.1',
10255 Encryption => 'E',
10256 Port => $port,
10257 Croak => 1,
10258 );
10259
10260 unless ($client) {
10261 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
10262 }
10263
10264 unless ($client->login($user, $passwd)) {
10265 die("Can't login: " . $client->last_message());
10266 }
10267
10268 unless ($client->binary()) {
10269 die("Can't set transfer mode to binary: " . $client->last_message());
10270 }
10271
10272 $client->set_callback(\&ftps_data_xfer_cancelled_cb, \&ftps_data_close_cb, $client);
10273
10274 unless ($client->get('test.txt', '/dev/null')) {
10275 die("Can't download 'test.txt': " . $client->last_message());
10276 }
10277
10278 $client->quit();
10279
10280 unless (-f $test_file) {
10281 die("File $test_file does not exist as expected");
10282 }
10283 };
10284
10285 if ($@) {
10286 $ex = $@;
10287 }
10288
10289 $wfh->print("done\n");
10290 $wfh->flush();
10291
10292 } else {
10293 eval { server_wait($config_file, $rfh, $timeout_idle + 3) };
10294 if ($@) {
10295 warn($@);
10296 exit 1;
10297 }
10298
10299 exit 0;
10300 }
10301
10302 # Stop server
10303 server_stop($pid_file);
10304
10305 $self->assert_child_ok($pid);
10306
10307 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
10308 # variable was properly written out.
10309 eval {
10310 if (open(my $fh, "< $ext_log")) {
10311 my $expected_xfer_status = 0;
10312
10313 while (my $line = <$fh>) {
10314 chomp($line);
10315
10316 if ($ENV{TEST_VERBOSE}) {
10317 print STDERR "$line\n";
10318 }
10319
10320 if ($line =~ /^(\S+) (.*)?$/) {
10321 my $cmd = $1;
10322 my $xfer_status = $2;
10323
10324 if ($cmd eq 'RETR') {
10325 if ($xfer_status eq 'cancelled' ||
10326 $xfer_status eq 'failed') {
10327 $expected_xfer_status = 1;
10328 last;
10329 }
10330 }
10331 }
10332 }
10333
10334 close($fh);
10335
10336 $self->assert($expected_xfer_status,
10337 test_msg("Did not see expected transfer status in ExtendedLog"));
10338
10339 } else {
10340 die("Can't read $ext_log: $!");
10341 }
10342 };
10343
10344 if ($@) {
10345 $ex = $@;
10346 }
10347
10348 if ($ex) {
10349 test_append_logfile($log_file, $ex);
10350 unlink($log_file);
10351
10352 die($ex);
10353 }
10354
10355 unlink($log_file);
10356 }
10357
10358 sub ftps_data_xfer_failed_cb {
10359 my $func_name = shift;
10360 my $data = shift;
10361 my $data_len = shift;
10362 my $total_len = shift;
10363 my $user_data = shift;
10364
10365 if ($total_len > 8192) {
10366 $user_data->close(SSL_no_shutdown => 1);
10367 return -1;
10368 }
10369
10370 return $$data_len;
10371 }
10372
10373 sub ftps_data_close_cb {
10374 my $func_name = shift;
10375 my $data = shift;
10376 my $data_len = shift;
10377 my $total_len = shift;
10378 my $user_data = shift;
10379
10380 return undef;
10381 }
10382
10383 sub extlog_ftps_xfer_status_failed {
10384 my $self = shift;
10385 my $tmpdir = $self->{tmpdir};
10386
10387 my $config_file = "$tmpdir/extlog.conf";
10388 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
10389 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
10390
10391 my $log_file = test_get_logfile();
10392
10393 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
10394 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
10395
10396 my $user = 'proftpd';
10397 my $passwd = 'test';
10398 my $group = 'ftpd';
10399 my $home_dir = File::Spec->rel2abs($tmpdir);
10400 my $uid = 500;
10401 my $gid = 500;
10402
10403 # Make sure that, if we're running as root, that the home directory has
10404 # permissions/privs set for the account we create
10405 if ($< == 0) {
10406 unless (chmod(0755, $home_dir)) {
10407 die("Can't set perms on $home_dir to 0755: $!");
10408 }
10409
10410 unless (chown($uid, $gid, $home_dir)) {
10411 die("Can't set owner of $home_dir to $uid/$gid: $!");
10412 }
10413 }
10414
10415 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10416 '/bin/bash');
10417 auth_group_write($auth_group_file, $group, $gid, $user);
10418
10419 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
10420 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10421
10422 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
10423
10424 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
10425 if (open(my $fh, "> $test_file")) {
10426 print $fh "ABCDefgh" x 32768;
10427
10428 unless (close($fh)) {
10429 die("Can't write $test_file: $!");
10430 }
10431
10432 } else {
10433 die("Can't open $test_file: $!");
10434 }
10435
10436 my $timeout_idle = 20;
10437
10438 my $config = {
10439 PidFile => $pid_file,
10440 ScoreboardFile => $scoreboard_file,
10441 SystemLog => $log_file,
10442 TraceLog => $log_file,
10443 Trace => 'DEFAULT:10 data:20 tls:20',
10444
10445 AuthUserFile => $auth_user_file,
10446 AuthGroupFile => $auth_group_file,
10447 AuthOrder => 'mod_auth_file.c',
10448
10449 TimeoutIdle => $timeout_idle,
10450
10451 IfModules => {
10452 'mod_delay.c' => {
10453 DelayEngine => 'off',
10454 },
10455
10456 'mod_tls.c' => {
10457 TLSEngine => 'on',
10458 TLSLog => $log_file,
10459 TLSRequired => 'on',
10460 TLSRSACertificateFile => $cert_file,
10461 TLSCACertificateFile => $ca_file,
10462 TLSOptions => 'NoSessionReuseRequired',
10463 },
10464 },
10465 };
10466
10467 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10468
10469 if (open(my $fh, ">> $config_file")) {
10470 print $fh <<EOC;
10471 LogFormat custom "%m %{transfer-status}"
10472 ExtendedLog $ext_log ALL custom
10473 EOC
10474 unless (close($fh)) {
10475 die("Can't write $config_file: $!");
10476 }
10477
10478 } else {
10479 die("Can't open $config_file: $!");
10480 }
10481
10482 # Open pipes, for use between the parent and child processes. Specifically,
10483 # the child will indicate when it's done with its test by writing a message
10484 # to the parent.
10485 my ($rfh, $wfh);
10486 unless (pipe($rfh, $wfh)) {
10487 die("Can't open pipe: $!");
10488 }
10489
10490 require Net::FTPSSL;
10491
10492 my $ex;
10493
10494 # Fork child
10495 $self->handle_sigchld();
10496 defined(my $pid = fork()) or die("Can't fork: $!");
10497 if ($pid) {
10498 eval {
10499 # Give the server a chance to start up
10500 sleep(2);
10501
10502 my $client = Net::FTPSSL->new('127.0.0.1',
10503 Encryption => 'E',
10504 Port => $port,
10505 );
10506
10507 unless ($client) {
10508 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
10509 }
10510
10511 unless ($client->login($user, $passwd)) {
10512 die("Can't login: " . $client->last_message());
10513 }
10514
10515 unless ($client->binary()) {
10516 die("Can't set transfer mode to binary: " . $client->last_message());
10517 }
10518
10519 $client->set_callback(\&ftps_data_xfer_failed_cb, \&ftps_data_close_cb, $client);
10520
10521 if ($client->get('test.txt', '/dev/null')) {
10522 die("Download of 'test.txt' succeeded unexpectedly");
10523 }
10524 };
10525
10526 if ($@) {
10527 $ex = $@;
10528 }
10529
10530 $wfh->print("done\n");
10531 $wfh->flush();
10532
10533 } else {
10534 eval { server_wait($config_file, $rfh, $timeout_idle + 3) };
10535 if ($@) {
10536 warn($@);
10537 exit 1;
10538 }
10539
10540 exit 0;
10541 }
10542
10543 # Stop server
10544 server_stop($pid_file);
10545
10546 $self->assert_child_ok($pid);
10547
10548 # Now, read in the ExtendedLog, and see whether the %{transfer-status}
10549 # variable was properly written out.
10550 eval {
10551 if (open(my $fh, "< $ext_log")) {
10552 my $expected_xfer_status = 0;
10553
10554 while (my $line = <$fh>) {
10555 chomp($line);
10556
10557 if ($line =~ /^(\S+) (.*)?$/) {
10558 my $cmd = $1;
10559 my $xfer_status = $2;
10560
10561 if ($cmd eq 'RETR') {
10562 if ($xfer_status eq 'failed') {
10563 $expected_xfer_status = 1;
10564 last;
10565 }
10566 }
10567 }
10568 }
10569
10570 close($fh);
10571
10572 $self->assert($expected_xfer_status,
10573 test_msg("Did not see expected transfer status in ExtendedLog"));
10574
10575 } else {
10576 die("Can't read $ext_log: $!");
10577 }
10578 };
10579
10580 if ($@) {
10581 $ex = $@;
10582 }
10583
10584 if ($ex) {
10585 test_append_logfile($log_file, $ex);
10586 unlink($log_file);
10587
10588 die($ex);
10589 }
10590
10591 unlink($log_file);
10592 }
10593
10594 sub extlog_login_maxclients_bug3811 {
10595 my $self = shift;
10596 my $tmpdir = $self->{tmpdir};
10597
10598 my $config_file = "$tmpdir/extlog.conf";
10599 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
10600 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
10601
10602 my $log_file = test_get_logfile();
10603
10604 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
10605 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
10606
10607 my $test_file = File::Spec->rel2abs($config_file);
10608
10609 my $user = 'proftpd';
10610 my $passwd = 'test';
10611 my $group = 'ftpd';
10612 my $home_dir = File::Spec->rel2abs($tmpdir);
10613 my $uid = 500;
10614 my $gid = 500;
10615
10616 # Make sure that, if we're running as root, that the home directory has
10617 # permissions/privs set for the account we create
10618 if ($< == 0) {
10619 unless (chmod(0755, $home_dir)) {
10620 die("Can't set perms on $home_dir to 0755: $!");
10621 }
10622
10623 unless (chown($uid, $gid, $home_dir)) {
10624 die("Can't set owner of $home_dir to $uid/$gid: $!");
10625 }
10626 }
10627
10628 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10629 '/bin/bash');
10630 auth_group_write($auth_group_file, $group, $gid, $user);
10631
10632 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
10633
10634 my $max_clients = 1;
10635
10636 my $config = {
10637 PidFile => $pid_file,
10638 ScoreboardFile => $scoreboard_file,
10639 SystemLog => $log_file,
10640
10641 AuthUserFile => $auth_user_file,
10642 AuthGroupFile => $auth_group_file,
10643 AuthOrder => 'mod_auth_file.c',
10644
10645 LogFormat => 'custom "%m %s"',
10646 ExtendedLog => "$ext_log AUTH custom",
10647
10648 MaxClients => $max_clients,
10649
10650 IfModules => {
10651 'mod_delay.c' => {
10652 DelayEngine => 'off',
10653 },
10654 },
10655 };
10656
10657 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10658
10659 # Open pipes, for use between the parent and child processes. Specifically,
10660 # the child will indicate when it's done with its test by writing a message
10661 # to the parent.
10662 my ($rfh, $wfh);
10663 unless (pipe($rfh, $wfh)) {
10664 die("Can't open pipe: $!");
10665 }
10666
10667 my $ex;
10668
10669 # Fork child
10670 $self->handle_sigchld();
10671 defined(my $pid = fork()) or die("Can't fork: $!");
10672 if ($pid) {
10673 eval {
10674 # First client should be able to log in...
10675 my $client1 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
10676 $client1->login($user, $passwd);
10677
10678 # ...but the second client should fail to login.
10679 my $client2 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
10680 eval { $client2->login($user, $passwd) };
10681 unless ($@) {
10682 die("Second login succeeded unexpectedly");
10683 }
10684 };
10685
10686 if ($@) {
10687 $ex = $@;
10688 }
10689
10690 $wfh->print("done\n");
10691 $wfh->flush();
10692
10693 } else {
10694 eval { server_wait($config_file, $rfh) };
10695 if ($@) {
10696 warn($@);
10697 exit 1;
10698 }
10699
10700 exit 0;
10701 }
10702
10703 # Stop server
10704 server_stop($pid_file);
10705
10706 $self->assert_child_ok($pid);
10707
10708 # Now, read in the ExtendedLog, and see whether the log entries were
10709 # properly written out. Bug#3811 occurred because the session was
10710 # disconnected before mod_log had a chance to do its work.
10711 if (open(my $fh, "< $ext_log")) {
10712 my $nuser = 0;
10713 my $npass = 0;
10714 my $saw_failed_pass = 0;
10715
10716 while (my $line = <$fh>) {
10717 chomp($line);
10718
10719 if ($line =~ /^(\S+)\s+(\d+)$/) {
10720 my $cmd = $1;
10721 my $resp_code = $2;
10722
10723 if ($cmd eq 'USER') {
10724 $nuser++;
10725
10726 } elsif ($cmd eq 'PASS') {
10727 $npass++;
10728
10729 if ($npass == 2) {
10730 if ($resp_code == 530) {
10731 $saw_failed_pass = 1;
10732 }
10733 }
10734 }
10735 }
10736 }
10737
10738 close($fh);
10739
10740 my $expected = 2;
10741 $self->assert($expected == $nuser,
10742 test_msg("Expected $expected USER commands, saw $nuser"));
10743
10744 $self->assert($expected == $npass,
10745 test_msg("Expected $expected PASS commands, saw $npass"));
10746
10747 $self->assert($saw_failed_pass,
10748 test_msg("Did not see second PASS to fail with 530"));
10749
10750 } else {
10751 die("Can't read $ext_log: $!");
10752 }
10753
10754 if ($ex) {
10755 test_append_logfile($log_file, $ex);
10756 unlink($log_file);
10757
10758 die($ex);
10759 }
10760
10761 unlink($log_file);
10762 }
10763
10764 sub extlog_login_maxclientsperclass_bug3811 {
10765 my $self = shift;
10766 my $tmpdir = $self->{tmpdir};
10767
10768 my $config_file = "$tmpdir/extlog.conf";
10769 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
10770 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
10771
10772 my $log_file = test_get_logfile();
10773
10774 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
10775 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
10776
10777 my $test_file = File::Spec->rel2abs($config_file);
10778
10779 my $user = 'proftpd';
10780 my $passwd = 'test';
10781 my $group = 'ftpd';
10782 my $home_dir = File::Spec->rel2abs($tmpdir);
10783 my $uid = 500;
10784 my $gid = 500;
10785
10786 # Make sure that, if we're running as root, that the home directory has
10787 # permissions/privs set for the account we create
10788 if ($< == 0) {
10789 unless (chmod(0755, $home_dir)) {
10790 die("Can't set perms on $home_dir to 0755: $!");
10791 }
10792
10793 unless (chown($uid, $gid, $home_dir)) {
10794 die("Can't set owner of $home_dir to $uid/$gid: $!");
10795 }
10796 }
10797
10798 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10799 '/bin/bash');
10800 auth_group_write($auth_group_file, $group, $gid, $user);
10801
10802 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
10803
10804 my $class_name = "test";
10805 my $max_clients = 1;
10806
10807 my $config = {
10808 PidFile => $pid_file,
10809 ScoreboardFile => $scoreboard_file,
10810 SystemLog => $log_file,
10811
10812 AuthUserFile => $auth_user_file,
10813 AuthGroupFile => $auth_group_file,
10814 AuthOrder => 'mod_auth_file.c',
10815
10816 LogFormat => 'custom "%m %s"',
10817 ExtendedLog => "$ext_log AUTH custom",
10818
10819 MaxClientsPerClass => "$class_name $max_clients",
10820
10821 IfModules => {
10822 'mod_delay.c' => {
10823 DelayEngine => 'off',
10824 },
10825 },
10826 };
10827
10828 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10829
10830 if (open(my $fh, ">> $config_file")) {
10831 print $fh <<EOC;
10832 <Class $class_name>
10833 From all
10834 </Class>
10835 EOC
10836
10837 unless (close($fh)) {
10838 die("Can't write $config_file: $!");
10839 }
10840
10841 } else {
10842 die("Can't open $config_file: $!");
10843 }
10844
10845 # Open pipes, for use between the parent and child processes. Specifically,
10846 # the child will indicate when it's done with its test by writing a message
10847 # to the parent.
10848 my ($rfh, $wfh);
10849 unless (pipe($rfh, $wfh)) {
10850 die("Can't open pipe: $!");
10851 }
10852
10853 my $ex;
10854
10855 # Fork child
10856 $self->handle_sigchld();
10857 defined(my $pid = fork()) or die("Can't fork: $!");
10858 if ($pid) {
10859 eval {
10860 # First client should be able to log in...
10861 my $client1 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
10862 $client1->login($user, $passwd);
10863
10864 # ...but the second client should fail to login.
10865 my $client2 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
10866 eval { $client2->login($user, $passwd) };
10867 unless ($@) {
10868 die("Second login succeeded unexpectedly");
10869 }
10870 };
10871
10872 if ($@) {
10873 $ex = $@;
10874 }
10875
10876 $wfh->print("done\n");
10877 $wfh->flush();
10878
10879 } else {
10880 eval { server_wait($config_file, $rfh) };
10881 if ($@) {
10882 warn($@);
10883 exit 1;
10884 }
10885
10886 exit 0;
10887 }
10888
10889 # Stop server
10890 server_stop($pid_file);
10891
10892 $self->assert_child_ok($pid);
10893
10894 # Now, read in the ExtendedLog, and see whether the log entries were
10895 # properly written out. Bug#3811 occurred because the session was
10896 # disconnected before mod_log had a chance to do its work.
10897 if (open(my $fh, "< $ext_log")) {
10898 my $nuser = 0;
10899 my $npass = 0;
10900 my $saw_failed_pass = 0;
10901
10902 while (my $line = <$fh>) {
10903 chomp($line);
10904
10905 if ($line =~ /^(\S+)\s+(\d+)$/) {
10906 my $cmd = $1;
10907 my $resp_code = $2;
10908
10909 if ($cmd eq 'USER') {
10910 $nuser++;
10911
10912 } elsif ($cmd eq 'PASS') {
10913 $npass++;
10914
10915 if ($npass == 2) {
10916 if ($resp_code == 530) {
10917 $saw_failed_pass = 1;
10918 }
10919 }
10920 }
10921 }
10922 }
10923
10924 close($fh);
10925
10926 my $expected = 2;
10927 $self->assert($expected == $nuser,
10928 test_msg("Expected $expected USER commands, saw $nuser"));
10929
10930 $self->assert($expected == $npass,
10931 test_msg("Expected $expected PASS commands, saw $npass"));
10932
10933 $self->assert($saw_failed_pass,
10934 test_msg("Did not see second PASS to fail with 530"));
10935
10936 } else {
10937 die("Can't read $ext_log: $!");
10938 }
10939
10940 if ($ex) {
10941 test_append_logfile($log_file, $ex);
10942 unlink($log_file);
10943
10944 die($ex);
10945 }
10946
10947 unlink($log_file);
10948 }
10949
10950 sub extlog_login_maxclientsperhost_bug3811 {
10951 my $self = shift;
10952 my $tmpdir = $self->{tmpdir};
10953
10954 my $config_file = "$tmpdir/extlog.conf";
10955 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
10956 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
10957
10958 my $log_file = test_get_logfile();
10959
10960 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
10961 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
10962
10963 my $test_file = File::Spec->rel2abs($config_file);
10964
10965 my $user = 'proftpd';
10966 my $passwd = 'test';
10967 my $group = 'ftpd';
10968 my $home_dir = File::Spec->rel2abs($tmpdir);
10969 my $uid = 500;
10970 my $gid = 500;
10971
10972 # Make sure that, if we're running as root, that the home directory has
10973 # permissions/privs set for the account we create
10974 if ($< == 0) {
10975 unless (chmod(0755, $home_dir)) {
10976 die("Can't set perms on $home_dir to 0755: $!");
10977 }
10978
10979 unless (chown($uid, $gid, $home_dir)) {
10980 die("Can't set owner of $home_dir to $uid/$gid: $!");
10981 }
10982 }
10983
10984 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10985 '/bin/bash');
10986 auth_group_write($auth_group_file, $group, $gid, $user);
10987
10988 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
10989
10990 my $max_clients = 1;
10991
10992 my $config = {
10993 PidFile => $pid_file,
10994 ScoreboardFile => $scoreboard_file,
10995 SystemLog => $log_file,
10996
10997 AuthUserFile => $auth_user_file,
10998 AuthGroupFile => $auth_group_file,
10999 AuthOrder => 'mod_auth_file.c',
11000
11001 LogFormat => 'custom "%m %s"',
11002 ExtendedLog => "$ext_log AUTH custom",
11003
11004 MaxClientsPerHost => $max_clients,
11005
11006 IfModules => {
11007 'mod_delay.c' => {
11008 DelayEngine => 'off',
11009 },
11010 },
11011 };
11012
11013 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11014
11015 # Open pipes, for use between the parent and child processes. Specifically,
11016 # the child will indicate when it's done with its test by writing a message
11017 # to the parent.
11018 my ($rfh, $wfh);
11019 unless (pipe($rfh, $wfh)) {
11020 die("Can't open pipe: $!");
11021 }
11022
11023 my $ex;
11024
11025 # Fork child
11026 $self->handle_sigchld();
11027 defined(my $pid = fork()) or die("Can't fork: $!");
11028 if ($pid) {
11029 eval {
11030 # First client should be able to log in...
11031 my $client1 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11032 $client1->login($user, $passwd);
11033
11034 # ...but the second client should fail to login.
11035 my $client2 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11036 eval { $client2->login($user, $passwd) };
11037 unless ($@) {
11038 die("Second login succeeded unexpectedly");
11039 }
11040 };
11041
11042 if ($@) {
11043 $ex = $@;
11044 }
11045
11046 $wfh->print("done\n");
11047 $wfh->flush();
11048
11049 } else {
11050 eval { server_wait($config_file, $rfh) };
11051 if ($@) {
11052 warn($@);
11053 exit 1;
11054 }
11055
11056 exit 0;
11057 }
11058
11059 # Stop server
11060 server_stop($pid_file);
11061
11062 $self->assert_child_ok($pid);
11063
11064 # Now, read in the ExtendedLog, and see whether the log entries were
11065 # properly written out. Bug#3811 occurred because the session was
11066 # disconnected before mod_log had a chance to do its work.
11067 if (open(my $fh, "< $ext_log")) {
11068 my $nuser = 0;
11069 my $npass = 0;
11070 my $saw_failed_pass = 0;
11071
11072 while (my $line = <$fh>) {
11073 chomp($line);
11074
11075 if ($line =~ /^(\S+)\s+(\d+)$/) {
11076 my $cmd = $1;
11077 my $resp_code = $2;
11078
11079 if ($cmd eq 'USER') {
11080 $nuser++;
11081
11082 } elsif ($cmd eq 'PASS') {
11083 $npass++;
11084
11085 if ($npass == 2) {
11086 if ($resp_code == 530) {
11087 $saw_failed_pass = 1;
11088 }
11089 }
11090 }
11091 }
11092 }
11093
11094 close($fh);
11095
11096 my $expected = 2;
11097 $self->assert($expected == $nuser,
11098 test_msg("Expected $expected USER commands, saw $nuser"));
11099
11100 $self->assert($expected == $npass,
11101 test_msg("Expected $expected PASS commands, saw $npass"));
11102
11103 $self->assert($saw_failed_pass,
11104 test_msg("Did not see second PASS to fail with 530"));
11105
11106 } else {
11107 die("Can't read $ext_log: $!");
11108 }
11109
11110 if ($ex) {
11111 test_append_logfile($log_file, $ex);
11112 unlink($log_file);
11113
11114 die($ex);
11115 }
11116
11117 unlink($log_file);
11118 }
11119
11120 sub extlog_login_maxclientsperuser_bug3811 {
11121 my $self = shift;
11122 my $tmpdir = $self->{tmpdir};
11123
11124 my $config_file = "$tmpdir/extlog.conf";
11125 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
11126 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
11127
11128 my $log_file = test_get_logfile();
11129
11130 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
11131 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
11132
11133 my $test_file = File::Spec->rel2abs($config_file);
11134
11135 my $user = 'proftpd';
11136 my $passwd = 'test';
11137 my $group = 'ftpd';
11138 my $home_dir = File::Spec->rel2abs($tmpdir);
11139 my $uid = 500;
11140 my $gid = 500;
11141
11142 # Make sure that, if we're running as root, that the home directory has
11143 # permissions/privs set for the account we create
11144 if ($< == 0) {
11145 unless (chmod(0755, $home_dir)) {
11146 die("Can't set perms on $home_dir to 0755: $!");
11147 }
11148
11149 unless (chown($uid, $gid, $home_dir)) {
11150 die("Can't set owner of $home_dir to $uid/$gid: $!");
11151 }
11152 }
11153
11154 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11155 '/bin/bash');
11156 auth_group_write($auth_group_file, $group, $gid, $user);
11157
11158 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
11159
11160 my $max_clients = 1;
11161
11162 my $config = {
11163 PidFile => $pid_file,
11164 ScoreboardFile => $scoreboard_file,
11165 SystemLog => $log_file,
11166
11167 AuthUserFile => $auth_user_file,
11168 AuthGroupFile => $auth_group_file,
11169 AuthOrder => 'mod_auth_file.c',
11170
11171 LogFormat => 'custom "%m %s"',
11172 ExtendedLog => "$ext_log AUTH custom",
11173
11174 MaxClientsPerUser => $max_clients,
11175
11176 IfModules => {
11177 'mod_delay.c' => {
11178 DelayEngine => 'off',
11179 },
11180 },
11181 };
11182
11183 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11184
11185 # Open pipes, for use between the parent and child processes. Specifically,
11186 # the child will indicate when it's done with its test by writing a message
11187 # to the parent.
11188 my ($rfh, $wfh);
11189 unless (pipe($rfh, $wfh)) {
11190 die("Can't open pipe: $!");
11191 }
11192
11193 my $ex;
11194
11195 # Fork child
11196 $self->handle_sigchld();
11197 defined(my $pid = fork()) or die("Can't fork: $!");
11198 if ($pid) {
11199 eval {
11200 # First client should be able to log in...
11201 my $client1 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11202 $client1->login($user, $passwd);
11203
11204 # ...but the second client should fail to login.
11205 my $client2 = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11206 eval { $client2->login($user, $passwd) };
11207 unless ($@) {
11208 die("Second login succeeded unexpectedly");
11209 }
11210 };
11211
11212 if ($@) {
11213 $ex = $@;
11214 }
11215
11216 $wfh->print("done\n");
11217 $wfh->flush();
11218
11219 } else {
11220 eval { server_wait($config_file, $rfh) };
11221 if ($@) {
11222 warn($@);
11223 exit 1;
11224 }
11225
11226 exit 0;
11227 }
11228
11229 # Stop server
11230 server_stop($pid_file);
11231
11232 $self->assert_child_ok($pid);
11233
11234 # Now, read in the ExtendedLog, and see whether the log entries were
11235 # properly written out. Bug#3811 occurred because the session was
11236 # disconnected before mod_log had a chance to do its work.
11237 if (open(my $fh, "< $ext_log")) {
11238 my $nuser = 0;
11239 my $npass = 0;
11240 my $saw_failed_pass = 0;
11241
11242 while (my $line = <$fh>) {
11243 chomp($line);
11244
11245 if ($line =~ /^(\S+)\s+(\d+)$/) {
11246 my $cmd = $1;
11247 my $resp_code = $2;
11248
11249 if ($cmd eq 'USER') {
11250 $nuser++;
11251
11252 } elsif ($cmd eq 'PASS') {
11253 $npass++;
11254
11255 if ($npass == 2) {
11256 if ($resp_code == 530) {
11257 $saw_failed_pass = 1;
11258 }
11259 }
11260 }
11261 }
11262 }
11263
11264 close($fh);
11265
11266 my $expected = 2;
11267 $self->assert($expected == $nuser,
11268 test_msg("Expected $expected USER commands, saw $nuser"));
11269
11270 $self->assert($expected == $npass,
11271 test_msg("Expected $expected PASS commands, saw $npass"));
11272
11273 $self->assert($saw_failed_pass,
11274 test_msg("Did not see second PASS to fail with 530"));
11275
11276 } else {
11277 die("Can't read $ext_log: $!");
11278 }
11279
11280 if ($ex) {
11281 test_append_logfile($log_file, $ex);
11282 unlink($log_file);
11283
11284 die($ex);
11285 }
11286
11287 unlink($log_file);
11288 }
11289
11290 sub extlog_preauth_var_U_bug3822 {
11291 my $self = shift;
11292 my $tmpdir = $self->{tmpdir};
11293
11294 my $config_file = "$tmpdir/extlog.conf";
11295 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
11296 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
11297
11298 my $log_file = test_get_logfile();
11299
11300 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
11301 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
11302
11303 my $test_file = File::Spec->rel2abs($config_file);
11304
11305 my $user = 'proftpd';
11306 my $passwd = 'test';
11307 my $group = 'ftpd';
11308 my $home_dir = File::Spec->rel2abs($tmpdir);
11309 my $uid = 500;
11310 my $gid = 500;
11311
11312 # Make sure that, if we're running as root, that the home directory has
11313 # permissions/privs set for the account we create
11314 if ($< == 0) {
11315 unless (chmod(0755, $home_dir)) {
11316 die("Can't set perms on $home_dir to 0755: $!");
11317 }
11318
11319 unless (chown($uid, $gid, $home_dir)) {
11320 die("Can't set owner of $home_dir to $uid/$gid: $!");
11321 }
11322 }
11323
11324 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11325 '/bin/bash');
11326 auth_group_write($auth_group_file, $group, $gid, $user);
11327
11328 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
11329
11330 my $config = {
11331 PidFile => $pid_file,
11332 ScoreboardFile => $scoreboard_file,
11333 SystemLog => $log_file,
11334
11335 AuthUserFile => $auth_user_file,
11336 AuthGroupFile => $auth_group_file,
11337 AuthOrder => 'mod_auth_file.c',
11338
11339 LogFormat => 'custom "%m %U"',
11340 ExtendedLog => "$ext_log ALL custom",
11341
11342 IfModules => {
11343 'mod_delay.c' => {
11344 DelayEngine => 'off',
11345 },
11346 },
11347 };
11348
11349 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11350
11351 # Open pipes, for use between the parent and child processes. Specifically,
11352 # the child will indicate when it's done with its test by writing a message
11353 # to the parent.
11354 my ($rfh, $wfh);
11355 unless (pipe($rfh, $wfh)) {
11356 die("Can't open pipe: $!");
11357 }
11358
11359 my $ex;
11360
11361 # Fork child
11362 $self->handle_sigchld();
11363 defined(my $pid = fork()) or die("Can't fork: $!");
11364 if ($pid) {
11365 eval {
11366 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11367
11368 eval { $client->pwd() };
11369 unless ($@) {
11370 die("PWD succeeded unexpectedly");
11371 }
11372
11373 $client->login($user, $passwd);
11374 $client->quit();
11375 };
11376
11377 if ($@) {
11378 $ex = $@;
11379 }
11380
11381 $wfh->print("done\n");
11382 $wfh->flush();
11383
11384 } else {
11385 eval { server_wait($config_file, $rfh) };
11386 if ($@) {
11387 warn($@);
11388 exit 1;
11389 }
11390
11391 exit 0;
11392 }
11393
11394 # Stop server
11395 server_stop($pid_file);
11396
11397 $self->assert_child_ok($pid);
11398
11399 # Now, read in the ExtendedLog, and see whether the %U variable were
11400 # properly written out.
11401 if (open(my $fh, "< $ext_log")) {
11402 while (my $line = <$fh>) {
11403 chomp($line);
11404
11405 $line =~ /(\S+) (.*)?$/;
11406 my $cmd = $1;
11407 my $name = $2;
11408
11409 my $expected;
11410 if ($cmd eq 'PWD') {
11411 $expected = '-';
11412
11413 } else {
11414 $expected = $user;
11415 }
11416
11417 $self->assert($expected eq $name,
11418 test_msg("Expected name '$expected', got '$name'"));
11419 }
11420
11421 close($fh);
11422
11423 } else {
11424 die("Can't read $ext_log: $!");
11425 }
11426
11427 if ($ex) {
11428 test_append_logfile($log_file, $ex);
11429 unlink($log_file);
11430
11431 die($ex);
11432 }
11433
11434 unlink($log_file);
11435 }
11436
11437 sub extlog_preauth_var_u_bug3822 {
11438 my $self = shift;
11439 my $tmpdir = $self->{tmpdir};
11440
11441 my $config_file = "$tmpdir/extlog.conf";
11442 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
11443 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
11444
11445 my $log_file = test_get_logfile();
11446
11447 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
11448 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
11449
11450 my $test_file = File::Spec->rel2abs($config_file);
11451
11452 my $user = 'proftpd';
11453 my $passwd = 'test';
11454 my $group = 'ftpd';
11455 my $home_dir = File::Spec->rel2abs($tmpdir);
11456 my $uid = 500;
11457 my $gid = 500;
11458
11459 # Make sure that, if we're running as root, that the home directory has
11460 # permissions/privs set for the account we create
11461 if ($< == 0) {
11462 unless (chmod(0755, $home_dir)) {
11463 die("Can't set perms on $home_dir to 0755: $!");
11464 }
11465
11466 unless (chown($uid, $gid, $home_dir)) {
11467 die("Can't set owner of $home_dir to $uid/$gid: $!");
11468 }
11469 }
11470
11471 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11472 '/bin/bash');
11473 auth_group_write($auth_group_file, $group, $gid, $user);
11474
11475 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
11476
11477 my $config = {
11478 PidFile => $pid_file,
11479 ScoreboardFile => $scoreboard_file,
11480 SystemLog => $log_file,
11481
11482 AuthUserFile => $auth_user_file,
11483 AuthGroupFile => $auth_group_file,
11484 AuthOrder => 'mod_auth_file.c',
11485
11486 LogFormat => 'custom "%m %u"',
11487 ExtendedLog => "$ext_log ALL custom",
11488
11489 IfModules => {
11490 'mod_delay.c' => {
11491 DelayEngine => 'off',
11492 },
11493 },
11494 };
11495
11496 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11497
11498 # Open pipes, for use between the parent and child processes. Specifically,
11499 # the child will indicate when it's done with its test by writing a message
11500 # to the parent.
11501 my ($rfh, $wfh);
11502 unless (pipe($rfh, $wfh)) {
11503 die("Can't open pipe: $!");
11504 }
11505
11506 my $ex;
11507
11508 # Fork child
11509 $self->handle_sigchld();
11510 defined(my $pid = fork()) or die("Can't fork: $!");
11511 if ($pid) {
11512 eval {
11513 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11514
11515 eval { $client->pwd() };
11516 unless ($@) {
11517 die("PWD succeeded unexpectedly");
11518 }
11519
11520 $client->login($user, $passwd);
11521 $client->quit();
11522 };
11523
11524 if ($@) {
11525 $ex = $@;
11526 }
11527
11528 $wfh->print("done\n");
11529 $wfh->flush();
11530
11531 } else {
11532 eval { server_wait($config_file, $rfh) };
11533 if ($@) {
11534 warn($@);
11535 exit 1;
11536 }
11537
11538 exit 0;
11539 }
11540
11541 # Stop server
11542 server_stop($pid_file);
11543 $self->assert_child_ok($pid);
11544
11545 $config_user = (config_get_identity())[0];
11546
11547 # Now, read in the ExtendedLog, and see whether the %U variable were
11548 # properly written out.
11549 if (open(my $fh, "< $ext_log")) {
11550 while (my $line = <$fh>) {
11551 chomp($line);
11552
11553 $line =~ /(\S+) (.*)?$/;
11554 my $cmd = $1;
11555 my $name = $2;
11556
11557 my $expected;
11558 if ($cmd eq 'PWD' ||
11559 $cmd eq 'USER') {
11560 $expected = '-';
11561
11562 } else {
11563 $expected = $user;
11564 }
11565
11566 $self->assert($expected eq $name,
11567 test_msg("Expected name '$expected', got '$name'"));
11568 }
11569
11570 close($fh);
11571
11572 } else {
11573 die("Can't read $ext_log: $!");
11574 }
11575
11576 if ($ex) {
11577 test_append_logfile($log_file, $ex);
11578 unlink($log_file);
11579
11580 die($ex);
11581 }
11582
11583 unlink($log_file);
11584 }
11585
11586 sub extlog_micros_ts_bug3889 {
11587 my $self = shift;
11588 my $tmpdir = $self->{tmpdir};
11589 my $setup = test_setup($tmpdir, 'extlog');
11590
11591 my $test_file = File::Spec->rel2abs($setup->{config_file});
11592 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
11593
11594 my $config = {
11595 PidFile => $setup->{pid_file},
11596 ScoreboardFile => $setup->{scoreboard_file},
11597 SystemLog => $setup->{log_file},
11598 TraceLog => $setup->{log_file},
11599 Trace => 'extlog:20 jot:20',
11600
11601 AuthUserFile => $setup->{auth_user_file},
11602 AuthGroupFile => $setup->{auth_group_file},
11603 AuthOrder => 'mod_auth_file.c',
11604
11605 LogFormat => 'custom "%{%Y-%m-%d %H:%M:%S}t,%{microsecs} %f"',
11606 ExtendedLog => "$ext_log READ custom",
11607
11608 IfModules => {
11609 'mod_delay.c' => {
11610 DelayEngine => 'off',
11611 },
11612 },
11613 };
11614
11615 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
11616 $config);
11617
11618 # Open pipes, for use between the parent and child processes. Specifically,
11619 # the child will indicate when it's done with its test by writing a message
11620 # to the parent.
11621 my ($rfh, $wfh);
11622 unless (pipe($rfh, $wfh)) {
11623 die("Can't open pipe: $!");
11624 }
11625
11626 my $ex;
11627
11628 # Fork child
11629 $self->handle_sigchld();
11630 defined(my $pid = fork()) or die("Can't fork: $!");
11631 if ($pid) {
11632 eval {
11633 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11634 $client->login($setup->{user}, $setup->{passwd});
11635
11636 my $conn = $client->retr_raw($test_file);
11637 unless ($conn) {
11638 die("Failed to RETR: " . $client->response_code() . " " .
11639 $client->response_msg());
11640 }
11641
11642 my $buf;
11643 $conn->read($buf, 8192, 30);
11644 eval { $conn->close() };
11645
11646 my $resp_code = $client->response_code();
11647 my $resp_msg = $client->response_msg();
11648 $self->assert_transfer_ok($resp_code, $resp_msg);
11649
11650 $client->quit();
11651 };
11652 if ($@) {
11653 $ex = $@;
11654 }
11655
11656 $wfh->print("done\n");
11657 $wfh->flush();
11658
11659 } else {
11660 eval { server_wait($setup->{config_file}, $rfh) };
11661 if ($@) {
11662 warn($@);
11663 exit 1;
11664 }
11665
11666 exit 0;
11667 }
11668
11669 # Stop server
11670 server_stop($setup->{pid_file});
11671 $self->assert_child_ok($setup->{pid});
11672
11673 eval {
11674 if (open(my $fh, "< $ext_log")) {
11675 my $line = <$fh>;
11676 chomp($line);
11677
11678 if ($ENV{TEST_VERBOSE}) {
11679 print STDERR "# ExtendedLog: $line\n";
11680 }
11681
11682 close($fh);
11683
11684 if ($line =~ /^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2},\d{6}\s+(.*)?$/) {
11685 my $file = $1;
11686
11687 # MacOSX hack
11688 if ($^O eq 'darwin') {
11689 $test_file = ('/private' . $test_file);
11690 }
11691
11692 $self->assert($test_file eq $file,
11693 "Expected '$test_file', got '$file'");
11694
11695 } else {
11696 $self->assert(0, test_msg("Did not see expected ExtendedLog line"));
11697 }
11698
11699 } else {
11700 die("Can't read $ext_log: $!");
11701 }
11702 };
11703 if ($@) {
11704 $ex = $@;
11705 }
11706
11707 test_cleanup($setup->{log_file}, $ex);
11708 }
11709
11710 sub extlog_millis_ts_bug3889 {
11711 my $self = shift;
11712 my $tmpdir = $self->{tmpdir};
11713
11714 my $config_file = "$tmpdir/extlog.conf";
11715 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
11716 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
11717
11718 my $log_file = test_get_logfile();
11719
11720 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
11721 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
11722
11723 my $test_file = File::Spec->rel2abs($config_file);
11724
11725 my $user = 'proftpd';
11726 my $passwd = 'test';
11727 my $group = 'ftpd';
11728 my $home_dir = File::Spec->rel2abs($tmpdir);
11729 my $uid = 500;
11730 my $gid = 500;
11731
11732 # Make sure that, if we're running as root, that the home directory has
11733 # permissions/privs set for the account we create
11734 if ($< == 0) {
11735 unless (chmod(0755, $home_dir)) {
11736 die("Can't set perms on $home_dir to 0755: $!");
11737 }
11738
11739 unless (chown($uid, $gid, $home_dir)) {
11740 die("Can't set owner of $home_dir to $uid/$gid: $!");
11741 }
11742 }
11743
11744 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11745 '/bin/bash');
11746 auth_group_write($auth_group_file, $group, $gid, $user);
11747
11748 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
11749
11750 my $config = {
11751 PidFile => $pid_file,
11752 ScoreboardFile => $scoreboard_file,
11753 SystemLog => $log_file,
11754
11755 AuthUserFile => $auth_user_file,
11756 AuthGroupFile => $auth_group_file,
11757 AuthOrder => 'mod_auth_file.c',
11758
11759 LogFormat => 'custom "%{%Y-%m-%d %H:%M:%S}t,%{millisecs} %f"',
11760 ExtendedLog => "$ext_log READ custom",
11761
11762 IfModules => {
11763 'mod_delay.c' => {
11764 DelayEngine => 'off',
11765 },
11766 },
11767 };
11768
11769 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11770
11771 # Open pipes, for use between the parent and child processes. Specifically,
11772 # the child will indicate when it's done with its test by writing a message
11773 # to the parent.
11774 my ($rfh, $wfh);
11775 unless (pipe($rfh, $wfh)) {
11776 die("Can't open pipe: $!");
11777 }
11778
11779 my $ex;
11780
11781 # Fork child
11782 $self->handle_sigchld();
11783 defined(my $pid = fork()) or die("Can't fork: $!");
11784 if ($pid) {
11785 eval {
11786 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11787 $client->login($user, $passwd);
11788
11789 my $conn = $client->retr_raw($test_file);
11790 unless ($conn) {
11791 die("Failed to RETR: " . $client->response_code() . " " .
11792 $client->response_msg());
11793 }
11794
11795 my $buf;
11796 $conn->read($buf, 8192, 30);
11797 eval { $conn->close() };
11798
11799 my $resp_code = $client->response_code();
11800 my $resp_msg = $client->response_msg();
11801 $self->assert_transfer_ok($resp_code, $resp_msg);
11802
11803 $client->quit();
11804 };
11805
11806 if ($@) {
11807 $ex = $@;
11808 }
11809
11810 $wfh->print("done\n");
11811 $wfh->flush();
11812
11813 } else {
11814 eval { server_wait($config_file, $rfh) };
11815 if ($@) {
11816 warn($@);
11817 exit 1;
11818 }
11819
11820 exit 0;
11821 }
11822
11823 # Stop server
11824 server_stop($pid_file);
11825
11826 $self->assert_child_ok($pid);
11827
11828 if (open(my $fh, "< $ext_log")) {
11829 my $line = <$fh>;
11830 chomp($line);
11831 close($fh);
11832
11833 if ($line =~ /^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2},\d{3}\s+(.*)?$/) {
11834 my $file = $1;
11835
11836 # MacOSX hack
11837 if ($^O eq 'darwin') {
11838 $test_file = ('/private' . $test_file);
11839 }
11840
11841 $self->assert($test_file eq $file,
11842 test_msg("Expected '$test_file', got '$file'"));
11843
11844 } else {
11845 $self->assert(0, test_msg("Did not see expected ExtendedLog line"));
11846 }
11847
11848 } else {
11849 die("Can't read $ext_log: $!");
11850 }
11851
11852 if ($ex) {
11853 test_append_logfile($log_file, $ex);
11854 unlink($log_file);
11855
11856 die($ex);
11857 }
11858
11859 unlink($log_file);
11860 }
11861
11862 sub extlog_iso8601_ts_bug3889 {
11863 my $self = shift;
11864 my $tmpdir = $self->{tmpdir};
11865 my $setup = test_setup($tmpdir, 'extlog');
11866
11867 my $test_file = File::Spec->rel2abs($setup->{config_file});
11868 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
11869
11870 my $config = {
11871 PidFile => $setup->{pid_file},
11872 ScoreboardFile => $setup->{scoreboard_file},
11873 SystemLog => $setup->{log_file},
11874 TraceLog => $setup->{log_file},
11875 Trace => 'extlog:20 jot:20',
11876
11877 AuthUserFile => $setup->{auth_user_file},
11878 AuthGroupFile => $setup->{auth_group_file},
11879 AuthOrder => 'mod_auth_file.c',
11880
11881 LogFormat => 'custom "%{ISO8601} %f"',
11882 ExtendedLog => "$ext_log READ custom",
11883
11884 IfModules => {
11885 'mod_delay.c' => {
11886 DelayEngine => 'off',
11887 },
11888 },
11889 };
11890
11891 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
11892 $config);
11893
11894 # Open pipes, for use between the parent and child processes. Specifically,
11895 # the child will indicate when it's done with its test by writing a message
11896 # to the parent.
11897 my ($rfh, $wfh);
11898 unless (pipe($rfh, $wfh)) {
11899 die("Can't open pipe: $!");
11900 }
11901
11902 my $ex;
11903
11904 # Fork child
11905 $self->handle_sigchld();
11906 defined(my $pid = fork()) or die("Can't fork: $!");
11907 if ($pid) {
11908 eval {
11909 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
11910 $client->login($setup->{user}, $setup->{passwd});
11911
11912 my $conn = $client->retr_raw($test_file);
11913 unless ($conn) {
11914 die("Failed to RETR: " . $client->response_code() . " " .
11915 $client->response_msg());
11916 }
11917
11918 my $buf;
11919 $conn->read($buf, 8192, 30);
11920 eval { $conn->close() };
11921
11922 my $resp_code = $client->response_code();
11923 my $resp_msg = $client->response_msg();
11924 $self->assert_transfer_ok($resp_code, $resp_msg);
11925
11926 $client->quit();
11927 };
11928 if ($@) {
11929 $ex = $@;
11930 }
11931
11932 $wfh->print("done\n");
11933 $wfh->flush();
11934
11935 } else {
11936 eval { server_wait($setup->{config_file}, $rfh) };
11937 if ($@) {
11938 warn($@);
11939 exit 1;
11940 }
11941
11942 exit 0;
11943 }
11944
11945 # Stop server
11946 server_stop($setup->{pid_file});
11947 $self->assert_child_ok($pid);
11948
11949 eval {
11950 if (open(my $fh, "< $ext_log")) {
11951 my $line = <$fh>;
11952 chomp($line);
11953
11954 if ($ENV{TEST_VERBOSE}) {
11955 print STDERR "# ExtendedLog: $line\n";
11956 }
11957
11958 close($fh);
11959
11960 if ($line =~ /^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2},\d{3}\s+(.*)?$/) {
11961 my $file = $1;
11962
11963 # MacOSX hack
11964 if ($^O eq 'darwin') {
11965 $test_file = ('/private' . $test_file);
11966 }
11967
11968 $self->assert($test_file eq $file,
11969 "Expected '$test_file', got '$file'");
11970
11971 } else {
11972 $self->assert(0, "Did not see expected ExtendedLog line");
11973 }
11974
11975 } else {
11976 die("Can't read $ext_log: $!");
11977 }
11978 };
11979 if ($@) {
11980 $ex = $@;
11981 }
11982
11983 test_cleanup($setup->{log_file}, $ex);
11984 }
11985
11986 sub extlog_dirs_class_var_f_bug3966 {
11987 my $self = shift;
11988 my $tmpdir = $self->{tmpdir};
11989
11990 my $config_file = "$tmpdir/extlog.conf";
11991 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
11992 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
11993
11994 my $log_file = test_get_logfile();
11995
11996 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
11997 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
11998
11999 my $user = 'proftpd';
12000 my $passwd = 'test';
12001 my $group = 'ftpd';
12002 my $home_dir = File::Spec->rel2abs($tmpdir);
12003 my $uid = 500;
12004 my $gid = 500;
12005
12006 # Make sure that, if we're running as root, that the home directory has
12007 # permissions/privs set for the account we create
12008 if ($< == 0) {
12009 unless (chmod(0755, $home_dir)) {
12010 die("Can't set perms on $home_dir to 0755: $!");
12011 }
12012
12013 unless (chown($uid, $gid, $home_dir)) {
12014 die("Can't set owner of $home_dir to $uid/$gid: $!");
12015 }
12016 }
12017
12018 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
12019 '/bin/bash');
12020 auth_group_write($auth_group_file, $group, $gid, $user);
12021
12022 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
12023 if (open(my $fh, "> $test_file")) {
12024 close($fh);
12025
12026 } else {
12027 die("Can't open $test_file: $!");
12028 }
12029
12030 my $test_dir = File::Spec->rel2abs("$tmpdir/test.d");
12031 mkpath($test_dir);
12032
12033 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12034
12035 my $config = {
12036 PidFile => $pid_file,
12037 ScoreboardFile => $scoreboard_file,
12038 SystemLog => $log_file,
12039
12040 AuthUserFile => $auth_user_file,
12041 AuthGroupFile => $auth_group_file,
12042 AuthOrder => 'mod_auth_file.c',
12043
12044 LogFormat => 'custom "%m: %f"',
12045 ExtendedLog => "$ext_log DIRS custom",
12046
12047 IfModules => {
12048 'mod_delay.c' => {
12049 DelayEngine => 'off',
12050 },
12051 },
12052 };
12053
12054 my ($port, $config_user, $config_group) = config_write($config_file, $config);
12055
12056 # Open pipes, for use between the parent and child processes. Specifically,
12057 # the child will indicate when it's done with its test by writing a message
12058 # to the parent.
12059 my ($rfh, $wfh);
12060 unless (pipe($rfh, $wfh)) {
12061 die("Can't open pipe: $!");
12062 }
12063
12064 my $ex;
12065
12066 # Fork child
12067 $self->handle_sigchld();
12068 defined(my $pid = fork()) or die("Can't fork: $!");
12069 if ($pid) {
12070 eval {
12071 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
12072 $client->login($user, $passwd);
12073
12074 # Bug#3966 reports that the %f LogFormat variable is not resolved for:
12075 #
12076 # CWD/XCWD, PWD/XPWD, CDUP/XCUP, LIST, MDTM, MLSD, MLST, NLST
12077 #
12078 # So run through all of them, then examine the generated log.
12079
12080 $client->pwd();
12081 $client->xpwd();
12082 $client->cwd('test.d');
12083 $client->cdup();
12084 $client->xcwd('test.d');
12085 $client->xcup();
12086 $client->mdtm('test.txt');
12087 $client->mlst('test.txt');
12088 $client->mlsd('test.d');
12089 $client->list('test.d');
12090 $client->nlst('test.d');
12091
12092 $client->quit();
12093 };
12094
12095 if ($@) {
12096 $ex = $@;
12097 }
12098
12099 $wfh->print("done\n");
12100 $wfh->flush();
12101
12102 } else {
12103 eval { server_wait($config_file, $rfh) };
12104 if ($@) {
12105 warn($@);
12106 exit 1;
12107 }
12108
12109 exit 0;
12110 }
12111
12112 # Stop server
12113 server_stop($pid_file);
12114
12115 $self->assert_child_ok($pid);
12116
12117 # Now, read in the ExtendedLog, and see whether the %f variable was
12118 # properly written out for MFMT.
12119 eval {
12120 if (open(my $fh, "< $ext_log")) {
12121 my $ok = 1;
12122
12123 if ($^O eq 'darwin') {
12124 # MacOSX-specific hack
12125 $home_dir = '/private' . $home_dir;
12126 $test_file = '/private' . $test_file;
12127 $test_dir = '/private' . $test_dir;
12128 }
12129
12130 while (my $line = <$fh>) {
12131 chomp($line);
12132
12133 if ($line =~ /^(\S+): (\S+)$/) {
12134 my $cmd = $1;
12135 my $file_path = $2;
12136
12137 # We don't mind if the path ends in a trailing slash; ignore it
12138 $file_path =~ s/\/$//;
12139
12140 if ($cmd eq 'CWD' || $cmd eq 'XCWD' ||
12141 $cmd eq 'LIST' || $cmd eq 'MLSD' || $cmd eq 'NLST') {
12142 $self->assert($test_dir eq $file_path,
12143 test_msg("Expected file (%f) '$test_dir' for $cmd, got '$file_path'"));
12144
12145 } elsif ($cmd eq 'PWD' || $cmd eq 'XPWD' ||
12146 $cmd eq 'CDUP' || $cmd eq 'XCUP') {
12147 $self->assert($home_dir eq $file_path,
12148 test_msg("Expected file (%f) '$home_dir' for $cmd, got '$file_path'"));
12149
12150 } elsif ($cmd eq 'MDTM' || $cmd eq 'MLST') {
12151 $self->assert($test_file eq $file_path,
12152 test_msg("Expected file (%f) '$test_file' for $cmd, got '$file_path'"));
12153
12154 } else {
12155 $ok = 0;
12156 }
12157
12158 if ($ok == 0) {
12159 last;
12160 }
12161
12162 } else {
12163 $ok = 0;
12164 last;
12165 }
12166 }
12167
12168 close($fh);
12169 $self->assert($ok, test_msg("Did not find expected ExtendedLog entries"));
12170
12171 } else {
12172 die("Can't read $ext_log: $!");
12173 }
12174 };
12175 if ($@) {
12176 $ex = $@;
12177 }
12178
12179 if ($ex) {
12180 test_append_logfile($log_file, $ex);
12181 unlink($log_file);
12182
12183 die($ex);
12184 }
12185
12186 unlink($log_file);
12187 }
12188
12189 sub extlog_var_basename_bug3987 {
12190 my $self = shift;
12191 my $tmpdir = $self->{tmpdir};
12192
12193 my $config_file = "$tmpdir/extlog.conf";
12194 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
12195 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
12196
12197 my $log_file = test_get_logfile();
12198
12199 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
12200 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
12201
12202 my $test_file = File::Spec->rel2abs($config_file);
12203
12204 my $user = 'proftpd';
12205 my $passwd = 'test';
12206 my $group = 'ftpd';
12207 my $home_dir = File::Spec->rel2abs($tmpdir);
12208 my $uid = 500;
12209 my $gid = 500;
12210
12211 # Make sure that, if we're running as root, that the home directory has
12212 # permissions/privs set for the account we create
12213 if ($< == 0) {
12214 unless (chmod(0755, $home_dir)) {
12215 die("Can't set perms on $home_dir to 0755: $!");
12216 }
12217
12218 unless (chown($uid, $gid, $home_dir)) {
12219 die("Can't set owner of $home_dir to $uid/$gid: $!");
12220 }
12221 }
12222
12223 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
12224 '/bin/bash');
12225 auth_group_write($auth_group_file, $group, $gid, $user);
12226
12227 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12228
12229 my $config = {
12230 PidFile => $pid_file,
12231 ScoreboardFile => $scoreboard_file,
12232 SystemLog => $log_file,
12233
12234 AuthUserFile => $auth_user_file,
12235 AuthGroupFile => $auth_group_file,
12236 AuthOrder => 'mod_auth_file.c',
12237
12238 LogFormat => 'custom "%{basename}"',
12239 ExtendedLog => "$ext_log READ custom",
12240
12241 IfModules => {
12242 'mod_delay.c' => {
12243 DelayEngine => 'off',
12244 },
12245 },
12246 };
12247
12248 my ($port, $config_user, $config_group) = config_write($config_file, $config);
12249
12250 # Open pipes, for use between the parent and child processes. Specifically,
12251 # the child will indicate when it's done with its test by writing a message
12252 # to the parent.
12253 my ($rfh, $wfh);
12254 unless (pipe($rfh, $wfh)) {
12255 die("Can't open pipe: $!");
12256 }
12257
12258 my $ex;
12259
12260 # Fork child
12261 $self->handle_sigchld();
12262 defined(my $pid = fork()) or die("Can't fork: $!");
12263 if ($pid) {
12264 eval {
12265 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
12266 $client->login($user, $passwd);
12267
12268 my $conn = $client->retr_raw($test_file);
12269 unless ($conn) {
12270 die("Failed to RETR: " . $client->response_code() . " " .
12271 $client->response_msg());
12272 }
12273
12274 my $buf;
12275 $conn->read($buf, 8192, 30);
12276 eval { $conn->close() };
12277
12278 my $resp_code = $client->response_code();
12279 my $resp_msg = $client->response_msg();
12280 $self->assert_transfer_ok($resp_code, $resp_msg);
12281
12282 $client->quit();
12283 };
12284
12285 if ($@) {
12286 $ex = $@;
12287 }
12288
12289 $wfh->print("done\n");
12290 $wfh->flush();
12291
12292 } else {
12293 eval { server_wait($config_file, $rfh) };
12294 if ($@) {
12295 warn($@);
12296 exit 1;
12297 }
12298
12299 exit 0;
12300 }
12301
12302 # Stop server
12303 server_stop($pid_file);
12304
12305 $self->assert_child_ok($pid);
12306
12307 eval {
12308 if (open(my $fh, "< $ext_log")) {
12309 my $line = <$fh>;
12310 chomp($line);
12311 close($fh);
12312
12313 my $expected = 'extlog.conf';
12314 $self->assert($expected eq $line,
12315 test_msg("Expected '$expected', got '$line'"));
12316
12317 } else {
12318 die("Can't read $ext_log: $!");
12319 }
12320 };
12321 if ($@) {
12322 $ex = $@;
12323 }
12324
12325 if ($ex) {
12326 test_append_logfile($log_file, $ex);
12327 unlink($log_file);
12328
12329 die($ex);
12330 }
12331
12332 unlink($log_file);
12333 }
12334
12335 sub extlog_exclusion_bug4067 {
12336 my $self = shift;
12337 my $tmpdir = $self->{tmpdir};
12338 my $setup = test_setup($tmpdir, 'extlog');
12339
12340 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12341
12342 my $config = {
12343 PidFile => $setup->{pid_file},
12344 ScoreboardFile => $setup->{scoreboard_file},
12345 SystemLog => $setup->{log_file},
12346
12347 AuthUserFile => $setup->{auth_user_file},
12348 AuthGroupFile => $setup->{auth_group_file},
12349 AuthOrder => 'mod_auth_file.c',
12350
12351 LogFormat => 'custom "%m"',
12352 ExtendedLog => "$ext_log ALL,!AUTH custom",
12353
12354 IfModules => {
12355 'mod_delay.c' => {
12356 DelayEngine => 'off',
12357 },
12358 },
12359 };
12360
12361 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12362 $config);
12363
12364 # Open pipes, for use between the parent and child processes. Specifically,
12365 # the child will indicate when it's done with its test by writing a message
12366 # to the parent.
12367 my ($rfh, $wfh);
12368 unless (pipe($rfh, $wfh)) {
12369 die("Can't open pipe: $!");
12370 }
12371
12372 my $ex;
12373
12374 # Fork child
12375 $self->handle_sigchld();
12376 defined(my $pid = fork()) or die("Can't fork: $!");
12377 if ($pid) {
12378 eval {
12379 # Allow for server startup
12380 sleep(2);
12381
12382 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
12383 $client->login($setup->{user}, $setup->{passwd});
12384 $client->feat();
12385 $client->pwd();
12386 $client->quit();
12387 };
12388 if ($@) {
12389 $ex = $@;
12390 }
12391
12392 $wfh->print("done\n");
12393 $wfh->flush();
12394
12395 } else {
12396 eval { server_wait($setup->{config_file}, $rfh) };
12397 if ($@) {
12398 warn($@);
12399 exit 1;
12400 }
12401
12402 exit 0;
12403 }
12404
12405 # Stop server
12406 server_stop($setup->{pid_file});
12407 $self->assert_child_ok($pid);
12408
12409 # Now, read in the ExtendedLog, and see whether the %f variable was
12410 # properly written out. Bug#3137 occurred because the session.xfer.path
12411 # variable was cleared out, as part of cleaning up the data connection,
12412 # too early. The fix is to use session.notes, which also has that path
12413 # information.
12414 eval {
12415 if (open(my $fh, "< $ext_log")) {
12416 my $ok = 1;
12417
12418 while (my $line = <$fh>) {
12419 chomp($line);
12420
12421 if ($ENV{TEST_VERBOSE}) {
12422 print STDERR "# $line\n";
12423 }
12424
12425 if ($line eq 'USER' ||
12426 $line eq 'PASS') {
12427 $ok = 0;
12428 last;
12429 }
12430 }
12431
12432 close($fh);
12433 $self->assert($ok, test_msg("Unexpected ExtendedLog messages logged"));
12434
12435 } else {
12436 die("Can't read $ext_log: $!");
12437 }
12438 };
12439 if ($@) {
12440 $ex = $@;
12441 }
12442
12443 test_cleanup($setup->{log_file}, $ex);
12444 }
12445
12446 sub extlog_sftp_ssh_ssh_issue1617 {
12447 my $self = shift;
12448 my $tmpdir = $self->{tmpdir};
12449 my $setup = test_setup($tmpdir, 'extlog');
12450
12451 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
12452 mkpath($sub_dir);
12453
12454 # Make sure that, if we're running as root, that the home directory has
12455 # permissions/privs set for the account we create
12456 if ($< == 0) {
12457 unless (chmod(0755, $sub_dir)) {
12458 die("Can't set perms on $sub_dir to 0755: $!");
12459 }
12460
12461 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
12462 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
12463 }
12464 }
12465
12466 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
12467 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
12468
12469 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12470
12471 my $config = {
12472 PidFile => $setup->{pid_file},
12473 ScoreboardFile => $setup->{scoreboard_file},
12474 SystemLog => $setup->{log_file},
12475 TraceLog => $setup->{log_file},
12476 Trace => 'jot:30 ssh2:20 sftp:20',
12477
12478 AuthUserFile => $setup->{auth_user_file},
12479 AuthGroupFile => $setup->{auth_group_file},
12480 AuthOrder => 'mod_auth_file.c',
12481
12482 LogFormat => 'custom "%m"',
12483 ExtendedLog => "$ext_log SSH custom",
12484
12485 IfModules => {
12486 'mod_delay.c' => {
12487 DelayEngine => 'off',
12488 },
12489
12490 'mod_sftp.c' => [
12491 "SFTPEngine on",
12492 "SFTPLog $setup->{log_file}",
12493 "SFTPHostKey $rsa_host_key",
12494 "SFTPHostKey $dsa_host_key",
12495 ],
12496 },
12497 };
12498
12499 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12500 $config);
12501
12502 # Open pipes, for use between the parent and child processes. Specifically,
12503 # the child will indicate when it's done with its test by writing a message
12504 # to the parent.
12505 my ($rfh, $wfh);
12506 unless (pipe($rfh, $wfh)) {
12507 die("Can't open pipe: $!");
12508 }
12509
12510 require Net::SSH2;
12511
12512 my $ex;
12513
12514 # Ignore SIGPIPE
12515 local $SIG{PIPE} = sub { };
12516
12517 # Fork child
12518 $self->handle_sigchld();
12519 defined(my $pid = fork()) or die("Can't fork: $!");
12520 if ($pid) {
12521 eval {
12522 # Allow for server startup
12523 sleep(2);
12524
12525 my $ssh2 = Net::SSH2->new();
12526
12527 unless ($ssh2->connect('127.0.0.1', $port)) {
12528 my ($err_code, $err_name, $err_str) = $ssh2->error();
12529 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
12530 }
12531
12532 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
12533 my ($err_code, $err_name, $err_str) = $ssh2->error();
12534 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
12535 }
12536
12537 my $sftp = $ssh2->sftp();
12538 unless ($sftp) {
12539 my ($err_code, $err_name, $err_str) = $ssh2->error();
12540 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
12541 }
12542
12543 my $dir = $sftp->opendir('sub.d');
12544 unless ($dir) {
12545 my ($err_code, $err_name) = $sftp->error();
12546 die("Can't open directory 'sub.d': [$err_name] ($err_code)");
12547 }
12548
12549 my $res = {};
12550
12551 my $file = $dir->read();
12552 while ($file) {
12553 $res->{$file->{name}} = $file;
12554 $file = $dir->read();
12555 }
12556
12557 # To issue the FXP_CLOSE, we have to explicitly destroy the dirhandle
12558 $dir = undef;
12559
12560 # To close the SFTP channel, we have to explicitly destroy the object
12561 $sftp = undef;
12562
12563 $ssh2->disconnect();
12564 };
12565 if ($@) {
12566 $ex = $@;
12567 }
12568
12569 $wfh->print("done\n");
12570 $wfh->flush();
12571
12572 } else {
12573 eval { server_wait($setup->{config_file}, $rfh) };
12574 if ($@) {
12575 warn($@);
12576 exit 1;
12577 }
12578
12579 exit 0;
12580 }
12581
12582 # Stop server
12583 server_stop($setup->{pid_file});
12584 $self->assert_child_ok($pid);
12585
12586 eval {
12587 if (open(my $fh, "< $ext_log")) {
12588 my $ok = 1;
12589
12590 while (my $line = <$fh>) {
12591 chomp($line);
12592
12593 if ($ENV{TEST_VERBOSE}) {
12594 print STDERR "# $line\n";
12595 }
12596
12597 if ($line eq 'USER' ||
12598 $line eq 'PASS') {
12599 $ok = 0;
12600 last;
12601 }
12602 }
12603
12604 close($fh);
12605 $self->assert($ok, test_msg("Unexpected ExtendedLog lines seen"));
12606
12607 } else {
12608 die("Can't read $ext_log: $!");
12609 }
12610 };
12611 if ($@) {
12612 $ex = $@;
12613 }
12614
12615 test_cleanup($setup->{log_file}, $ex);
12616 }
12617
12618 sub extlog_sftp_ssh_sftp_bug4067 {
12619 my $self = shift;
12620 my $tmpdir = $self->{tmpdir};
12621 my $setup = test_setup($tmpdir, 'extlog');
12622
12623 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
12624 mkpath($sub_dir);
12625
12626 # Make sure that, if we're running as root, that the home directory has
12627 # permissions/privs set for the account we create
12628 if ($< == 0) {
12629 unless (chmod(0755, $sub_dir)) {
12630 die("Can't set perms on $sub_dir to 0755: $!");
12631 }
12632
12633 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
12634 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
12635 }
12636 }
12637
12638 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
12639 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
12640
12641 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12642
12643 my $config = {
12644 PidFile => $setup->{pid_file},
12645 ScoreboardFile => $setup->{scoreboard_file},
12646 SystemLog => $setup->{log_file},
12647 TraceLog => $setup->{log_file},
12648 Trace => 'ssh2:20 sftp:20',
12649
12650 AuthUserFile => $setup->{auth_user_file},
12651 AuthGroupFile => $setup->{auth_group_file},
12652 AuthOrder => 'mod_auth_file.c',
12653
12654 LogFormat => 'custom "%m"',
12655 ExtendedLog => "$ext_log SFTP custom",
12656
12657 IfModules => {
12658 'mod_delay.c' => {
12659 DelayEngine => 'off',
12660 },
12661
12662 'mod_sftp.c' => [
12663 "SFTPEngine on",
12664 "SFTPLog $setup->{log_file}",
12665 "SFTPHostKey $rsa_host_key",
12666 "SFTPHostKey $dsa_host_key",
12667 ],
12668 },
12669 };
12670
12671 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12672 $config);
12673
12674 # Open pipes, for use between the parent and child processes. Specifically,
12675 # the child will indicate when it's done with its test by writing a message
12676 # to the parent.
12677 my ($rfh, $wfh);
12678 unless (pipe($rfh, $wfh)) {
12679 die("Can't open pipe: $!");
12680 }
12681
12682 require Net::SSH2;
12683
12684 my $ex;
12685
12686 # Ignore SIGPIPE
12687 local $SIG{PIPE} = sub { };
12688
12689 # Fork child
12690 $self->handle_sigchld();
12691 defined(my $pid = fork()) or die("Can't fork: $!");
12692 if ($pid) {
12693 eval {
12694 # Allow for server startup
12695 sleep(2);
12696
12697 my $ssh2 = Net::SSH2->new();
12698
12699 unless ($ssh2->connect('127.0.0.1', $port)) {
12700 my ($err_code, $err_name, $err_str) = $ssh2->error();
12701 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
12702 }
12703
12704 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
12705 my ($err_code, $err_name, $err_str) = $ssh2->error();
12706 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
12707 }
12708
12709 my $sftp = $ssh2->sftp();
12710 unless ($sftp) {
12711 my ($err_code, $err_name, $err_str) = $ssh2->error();
12712 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
12713 }
12714
12715 my $dir = $sftp->opendir('sub.d');
12716 unless ($dir) {
12717 my ($err_code, $err_name) = $sftp->error();
12718 die("Can't open directory 'sub.d': [$err_name] ($err_code)");
12719 }
12720
12721 my $res = {};
12722
12723 my $file = $dir->read();
12724 while ($file) {
12725 $res->{$file->{name}} = $file;
12726 $file = $dir->read();
12727 }
12728
12729 # To issue the FXP_CLOSE, we have to explicitly destroy the dirhandle
12730 $dir = undef;
12731
12732 # To close the SFTP channel, we have to explicitly destroy the object
12733 $sftp = undef;
12734
12735 $ssh2->disconnect();
12736 };
12737 if ($@) {
12738 $ex = $@;
12739 }
12740
12741 $wfh->print("done\n");
12742 $wfh->flush();
12743
12744 } else {
12745 eval { server_wait($setup->{config_file}, $rfh) };
12746 if ($@) {
12747 warn($@);
12748 exit 1;
12749 }
12750
12751 exit 0;
12752 }
12753
12754 # Stop server
12755 server_stop($setup->{pid_file});
12756 $self->assert_child_ok($pid);
12757
12758 eval {
12759 if (open(my $fh, "< $ext_log")) {
12760 my $ok = 1;
12761
12762 while (my $line = <$fh>) {
12763 chomp($line);
12764
12765 if ($ENV{TEST_VERBOSE}) {
12766 print STDERR "# $line\n";
12767 }
12768
12769 if ($line eq 'USER' ||
12770 $line eq 'PASS' ||
12771 $line eq 'MLSD') {
12772 $ok = 0;
12773 last;
12774 }
12775 }
12776
12777 close($fh);
12778 $self->assert($ok, test_msg("Unexpected ExtendedLog lines seen"));
12779
12780 } else {
12781 die("Can't read $ext_log: $!");
12782 }
12783 };
12784 if ($@) {
12785 $ex = $@;
12786 }
12787
12788 test_cleanup($setup->{log_file}, $ex);
12789 }
12790
12791 sub extlog_sftp_ssh_sftp_exclusion_bug4067 {
12792 my $self = shift;
12793 my $tmpdir = $self->{tmpdir};
12794 my $setup = test_setup($tmpdir, 'extlog');
12795
12796 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
12797 mkpath($sub_dir);
12798
12799 # Make sure that, if we're running as root, that the home directory has
12800 # permissions/privs set for the account we create
12801 if ($< == 0) {
12802 unless (chmod(0755, $sub_dir)) {
12803 die("Can't set perms on $sub_dir to 0755: $!");
12804 }
12805
12806 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
12807 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
12808 }
12809 }
12810
12811 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
12812 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
12813
12814 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12815
12816 my $config = {
12817 PidFile => $setup->{pid_file},
12818 ScoreboardFile => $setup->{scoreboard_file},
12819 SystemLog => $setup->{log_file},
12820 TraceLog => $setup->{log_file},
12821 Trace => 'jot:20 ssh2:20 sftp:20',
12822
12823 AuthUserFile => $setup->{auth_user_file},
12824 AuthGroupFile => $setup->{auth_group_file},
12825 AuthOrder => 'mod_auth_file.c',
12826
12827 LogFormat => 'custom "%m"',
12828 ExtendedLog => "$ext_log DIRS,!SSH,!SFTP custom",
12829
12830 IfModules => {
12831 'mod_delay.c' => {
12832 DelayEngine => 'off',
12833 },
12834
12835 'mod_sftp.c' => [
12836 "SFTPEngine on",
12837 "SFTPLog $setup->{log_file}",
12838 "SFTPHostKey $rsa_host_key",
12839 "SFTPHostKey $dsa_host_key",
12840 ],
12841 },
12842 };
12843
12844 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12845 $config);
12846
12847 # Open pipes, for use between the parent and child processes. Specifically,
12848 # the child will indicate when it's done with its test by writing a message
12849 # to the parent.
12850 my ($rfh, $wfh);
12851 unless (pipe($rfh, $wfh)) {
12852 die("Can't open pipe: $!");
12853 }
12854
12855 require Net::SSH2;
12856
12857 my $ex;
12858
12859 # Ignore SIGPIPE
12860 local $SIG{PIPE} = sub { };
12861
12862 # Fork child
12863 $self->handle_sigchld();
12864 defined(my $pid = fork()) or die("Can't fork: $!");
12865 if ($pid) {
12866 eval {
12867 # Allow for server startup
12868 sleep(2);
12869
12870 my $ssh2 = Net::SSH2->new();
12871
12872 unless ($ssh2->connect('127.0.0.1', $port)) {
12873 my ($err_code, $err_name, $err_str) = $ssh2->error();
12874 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
12875 }
12876
12877 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
12878 my ($err_code, $err_name, $err_str) = $ssh2->error();
12879 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
12880 }
12881
12882 my $sftp = $ssh2->sftp();
12883 unless ($sftp) {
12884 my ($err_code, $err_name, $err_str) = $ssh2->error();
12885 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
12886 }
12887
12888 my $dir = $sftp->opendir('sub.d');
12889 unless ($dir) {
12890 my ($err_code, $err_name) = $sftp->error();
12891 die("Can't open directory 'sub.d': [$err_name] ($err_code)");
12892 }
12893
12894 my $res = {};
12895
12896 my $file = $dir->read();
12897 while ($file) {
12898 $res->{$file->{name}} = $file;
12899 $file = $dir->read();
12900 }
12901
12902 # To issue the FXP_CLOSE, we have to explicitly destroy the dirhandle
12903 $dir = undef;
12904
12905 # To close the SFTP channel, we have to explicitly destroy the object
12906 $sftp = undef;
12907
12908 $ssh2->disconnect();
12909 };
12910 if ($@) {
12911 $ex = $@;
12912 }
12913
12914 $wfh->print("done\n");
12915 $wfh->flush();
12916
12917 } else {
12918 eval { server_wait($setup->{config_file}, $rfh) };
12919 if ($@) {
12920 warn($@);
12921 exit 1;
12922 }
12923
12924 exit 0;
12925 }
12926
12927 # Stop server
12928 server_stop($setup->{pid_file});
12929 $self->assert_child_ok($pid);
12930
12931 eval {
12932 if (open(my $fh, "< $ext_log")) {
12933 my $ok = 1;
12934
12935 while (my $line = <$fh>) {
12936 chomp($line);
12937
12938 if ($ENV{TEST_VERBOSE}) {
12939 print STDERR "# $line\n";
12940 }
12941
12942 if ($line ne 'USER' &&
12943 $line ne 'PASS' &&
12944 $line ne 'MLSD') {
12945 $ok = 0;
12946 last;
12947 }
12948 }
12949
12950 close($fh);
12951 $self->assert($ok, test_msg("Unexpected ExtendedLog lines seen"));
12952
12953 } else {
12954 die("Can't read $ext_log: $!");
12955 }
12956 };
12957 if ($@) {
12958 $ex = $@;
12959 }
12960
12961 test_cleanup($setup->{log_file}, $ex);
12962 }
12963
12964 sub extlog_sftp_read_write_bug4067 {
12965 my $self = shift;
12966 my $tmpdir = $self->{tmpdir};
12967 my $setup = test_setup($tmpdir, 'extlog');
12968
12969 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
12970 mkpath($sub_dir);
12971
12972 # Make sure that, if we're running as root, that the home directory has
12973 # permissions/privs set for the account we create
12974 if ($< == 0) {
12975 unless (chmod(0755, $sub_dir)) {
12976 die("Can't set perms on $sub_dir to 0755: $!");
12977 }
12978
12979 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
12980 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
12981 }
12982 }
12983
12984 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
12985 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
12986
12987 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
12988
12989 my $config = {
12990 PidFile => $setup->{pid_file},
12991 ScoreboardFile => $setup->{scoreboard_file},
12992 SystemLog => $setup->{log_file},
12993 TraceLog => $setup->{log_file},
12994 Trace => 'jot:20 ssh2:20 sftp:20',
12995
12996 AuthUserFile => $setup->{auth_user_file},
12997 AuthGroupFile => $setup->{auth_group_file},
12998 AuthOrder => 'mod_auth_file.c',
12999
13000 LogFormat => 'custom "%m"',
13001 ExtendedLog => "$ext_log READ,WRITE custom",
13002
13003 IfModules => {
13004 'mod_delay.c' => {
13005 DelayEngine => 'off',
13006 },
13007
13008 'mod_sftp.c' => [
13009 "SFTPEngine on",
13010 "SFTPLog $setup->{log_file}",
13011 "SFTPHostKey $rsa_host_key",
13012 "SFTPHostKey $dsa_host_key",
13013 ],
13014 },
13015 };
13016
13017 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13018 $config);
13019
13020 # Open pipes, for use between the parent and child processes. Specifically,
13021 # the child will indicate when it's done with its test by writing a message
13022 # to the parent.
13023 my ($rfh, $wfh);
13024 unless (pipe($rfh, $wfh)) {
13025 die("Can't open pipe: $!");
13026 }
13027
13028 require Net::SSH2;
13029
13030 my $ex;
13031
13032 # Ignore SIGPIPE
13033 local $SIG{PIPE} = sub { };
13034
13035 # Fork child
13036 $self->handle_sigchld();
13037 defined(my $pid = fork()) or die("Can't fork: $!");
13038 if ($pid) {
13039 eval {
13040 # Allow for server startup
13041 sleep(2);
13042
13043 my $ssh2 = Net::SSH2->new();
13044
13045 unless ($ssh2->connect('127.0.0.1', $port)) {
13046 my ($err_code, $err_name, $err_str) = $ssh2->error();
13047 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
13048 }
13049
13050 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
13051 my ($err_code, $err_name, $err_str) = $ssh2->error();
13052 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
13053 }
13054
13055 my $sftp = $ssh2->sftp();
13056 unless ($sftp) {
13057 my ($err_code, $err_name, $err_str) = $ssh2->error();
13058 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
13059 }
13060
13061 my $fh = $sftp->open('test.txt', O_WRONLY|O_CREAT|O_TRUNC, 0644);
13062 unless ($fh) {
13063 my ($err_code, $err_name) = $sftp->error();
13064 die("Can't open test.txt: [$err_name] ($err_code)");
13065 }
13066
13067 my $count = 5;
13068 for (my $i = 0; $i < $count; $i++) {
13069 print $fh "ABCD" x 1024;
13070 }
13071
13072 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
13073 $fh = undef;
13074
13075 $fh = $sftp->open('test.txt', O_RDONLY);
13076 unless ($fh) {
13077 my ($err_code, $err_name) = $sftp->error();
13078 die("Can't open test.txt: [$err_name] ($err_code)");
13079 }
13080
13081 my $buf;
13082 my $size = 0;
13083
13084 my $res = $fh->read($buf, 8192);
13085 while ($res) {
13086 $size += $res;
13087
13088 $res = $fh->read($buf, 8192);
13089 }
13090
13091 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
13092 $fh = undef;
13093
13094 # To close the SFTP channel, we have to explicitly destroy the object
13095 $sftp = undef;
13096
13097 $ssh2->disconnect();
13098 };
13099 if ($@) {
13100 $ex = $@;
13101 }
13102
13103 $wfh->print("done\n");
13104 $wfh->flush();
13105
13106 } else {
13107 eval { server_wait($setup->{config_file}, $rfh) };
13108 if ($@) {
13109 warn($@);
13110 exit 1;
13111 }
13112
13113 exit 0;
13114 }
13115
13116 # Stop server
13117 server_stop($setup->{pid_file});
13118 $self->assert_child_ok($pid);
13119
13120 eval {
13121 if (open(my $fh, "< $ext_log")) {
13122 my $write_ok = 0;
13123 my $read_ok = 0;
13124
13125 while (my $line = <$fh>) {
13126 chomp($line);
13127
13128 if ($ENV{TEST_VERBOSE}) {
13129 print STDERR "# $line\n";
13130 }
13131
13132 if ($write_ok and $read_ok) {
13133 last;
13134 }
13135
13136 if ($line eq 'WRITE') {
13137 $write_ok = 1;
13138 next;
13139 }
13140
13141 if ($line eq 'READ') {
13142 $read_ok = 1;
13143 next;
13144 }
13145 }
13146
13147 close($fh);
13148
13149 $self->assert($write_ok and $read_ok,
13150 test_msg("Unexpected ExtendedLog lines seen"));
13151
13152 } else {
13153 die("Can't read $ext_log: $!");
13154 }
13155 };
13156 if ($@) {
13157 $ex = $@;
13158 }
13159
13160 test_cleanup($setup->{log_file}, $ex);
13161 }
13162
13163 sub extlog_sftp_xfer_status_filtered {
13164 my $self = shift;
13165 my $tmpdir = $self->{tmpdir};
13166
13167 my $config_file = "$tmpdir/extlog.conf";
13168 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
13169 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
13170
13171 my $log_file = test_get_logfile();
13172
13173 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
13174 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
13175
13176 my $user = 'proftpd';
13177 my $passwd = 'test';
13178 my $group = 'ftpd';
13179 my $home_dir = File::Spec->rel2abs($tmpdir);
13180 my $uid = 500;
13181 my $gid = 500;
13182
13183 # Make sure that, if we're running as root, that the home directory has
13184 # permissions/privs set for the account we create
13185 if ($< == 0) {
13186 unless (chmod(0755, $home_dir)) {
13187 die("Can't set perms on $home_dir to 0755: $!");
13188 }
13189
13190 unless (chown($uid, $gid, $home_dir)) {
13191 die("Can't set owner of $home_dir to $uid/$gid: $!");
13192 }
13193 }
13194
13195 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
13196 '/bin/bash');
13197 auth_group_write($auth_group_file, $group, $gid, $user);
13198
13199 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
13200 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
13201
13202 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
13203
13204 my $config = {
13205 PidFile => $pid_file,
13206 ScoreboardFile => $scoreboard_file,
13207 SystemLog => $log_file,
13208 TraceLog => $log_file,
13209 Trace => 'DEFAULT:10 ssh2:20 sftp:20',
13210
13211 AuthUserFile => $auth_user_file,
13212 AuthGroupFile => $auth_group_file,
13213 AuthOrder => 'mod_auth_file.c',
13214
13215 PathDenyFilter => '^.*\.csv$',
13216 LogFormat => 'custom "%m %{transfer-status}"',
13217 ExtendedLog => "$ext_log READ,WRITE custom",
13218
13219 IfModules => {
13220 'mod_delay.c' => {
13221 DelayEngine => 'off',
13222 },
13223
13224 'mod_sftp.c' => [
13225 "SFTPEngine on",
13226 "SFTPLog $log_file",
13227 "SFTPHostKey $rsa_host_key",
13228 "SFTPHostKey $dsa_host_key",
13229 ],
13230 },
13231 };
13232
13233 my ($port, $config_user, $config_group) = config_write($config_file, $config);
13234
13235 # Open pipes, for use between the parent and child processes. Specifically,
13236 # the child will indicate when it's done with its test by writing a message
13237 # to the parent.
13238 my ($rfh, $wfh);
13239 unless (pipe($rfh, $wfh)) {
13240 die("Can't open pipe: $!");
13241 }
13242
13243 require Net::SSH2;
13244
13245 my $ex;
13246
13247 # Ignore SIGPIPE
13248 local $SIG{PIPE} = sub { };
13249
13250 # Fork child
13251 $self->handle_sigchld();
13252 defined(my $pid = fork()) or die("Can't fork: $!");
13253 if ($pid) {
13254 eval {
13255 my $ssh2 = Net::SSH2->new();
13256 sleep(1);
13257
13258 unless ($ssh2->connect('127.0.0.1', $port)) {
13259 my ($err_code, $err_name, $err_str) = $ssh2->error();
13260 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
13261 }
13262
13263 unless ($ssh2->auth_password($user, $passwd)) {
13264 my ($err_code, $err_name, $err_str) = $ssh2->error();
13265 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
13266 }
13267
13268 my $sftp = $ssh2->sftp();
13269 unless ($sftp) {
13270 my ($err_code, $err_name, $err_str) = $ssh2->error();
13271 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
13272 }
13273
13274 my $fh = $sftp->open('test.csv', O_WRONLY|O_CREAT|O_TRUNC, 0644);
13275 if ($fh) {
13276 die("Open of test.csv succeeded unexpectedly");
13277 }
13278
13279 my ($err_code, $err_name) = $sftp->error();
13280 my $expected = 'SSH_FX_PERMISSION_DENIED';
13281 $self->assert($expected eq $err_name,
13282 "Expected error $expected, got $err_name");
13283
13284 # To close the SFTP channel, we have to explicitly destroy the object
13285 $sftp = undef;
13286
13287 $ssh2->disconnect();
13288 };
13289
13290 if ($@) {
13291 $ex = $@;
13292 }
13293
13294 $wfh->print("done\n");
13295 $wfh->flush();
13296
13297 } else {
13298 eval { server_wait($config_file, $rfh) };
13299 if ($@) {
13300 warn($@);
13301 exit 1;
13302 }
13303
13304 exit 0;
13305 }
13306
13307 # Stop server
13308 server_stop($pid_file);
13309 $self->assert_child_ok($pid);
13310
13311 eval {
13312 if (open(my $fh, "< $ext_log")) {
13313 my $saw_failed = 0;
13314
13315 while (my $line = <$fh>) {
13316 chomp($line);
13317
13318 if ($ENV{TEST_VERBOSE}) {
13319 print STDERR "$line\n";
13320 }
13321
13322 if ($line eq 'STOR failed') {
13323 $saw_failed = 1;
13324 last;
13325 }
13326 }
13327
13328 close($fh);
13329 $self->assert($saw_failed, "Expected ExtendedLog line not seen");
13330
13331 } else {
13332 die("Can't read $ext_log: $!");
13333 }
13334 };
13335 if ($@) {
13336 $ex = $@;
13337 }
13338
13339 if ($ex) {
13340 test_append_logfile($log_file, $ex);
13341 unlink($log_file);
13342
13343 die($ex);
13344 }
13345
13346 unlink($log_file);
13347 }
13348
13349 sub extlog_var_file_offset {
13350 my $self = shift;
13351 my $tmpdir = $self->{tmpdir};
13352
13353 my $config_file = "$tmpdir/extlog.conf";
13354 my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
13355 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
13356
13357 my $log_file = test_get_logfile();
13358
13359 my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
13360 my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
13361
13362 my $test_file = File::Spec->rel2abs($config_file);
13363
13364 my $user = 'proftpd';
13365 my $passwd = 'test';
13366 my $group = 'ftpd';
13367 my $home_dir = File::Spec->rel2abs($tmpdir);
13368 my $uid = 500;
13369 my $gid = 500;
13370
13371 # Make sure that, if we're running as root, that the home directory has
13372 # permissions/privs set for the account we create
13373 if ($< == 0) {
13374 unless (chmod(0755, $home_dir)) {
13375 die("Can't set perms on $home_dir to 0755: $!");
13376 }
13377
13378 unless (chown($uid, $gid, $home_dir)) {
13379 die("Can't set owner of $home_dir to $uid/$gid: $!");
13380 }
13381 }
13382
13383 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
13384 '/bin/bash');
13385 auth_group_write($auth_group_file, $group, $gid, $user);
13386
13387 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
13388
13389 my $offset = 1;
13390
13391 my $config = {
13392 PidFile => $pid_file,
13393 ScoreboardFile => $scoreboard_file,
13394 SystemLog => $log_file,
13395
13396 AuthUserFile => $auth_user_file,
13397 AuthGroupFile => $auth_group_file,
13398 AuthOrder => 'mod_auth_file.c',
13399
13400 LogFormat => 'custom "%f: %{file-offset}"',
13401 ExtendedLog => "$ext_log READ custom",
13402 AllowRetrieveRestart => 'true',
13403
13404 IfModules => {
13405 'mod_delay.c' => {
13406 DelayEngine => 'off',
13407 },
13408 },
13409 };
13410
13411 my ($port, $config_user, $config_group) = config_write($config_file, $config);
13412
13413 # Open pipes, for use between the parent and child processes. Specifically,
13414 # the child will indicate when it's done with its test by writing a message
13415 # to the parent.
13416 my ($rfh, $wfh);
13417 unless (pipe($rfh, $wfh)) {
13418 die("Can't open pipe: $!");
13419 }
13420
13421 my $ex;
13422
13423 # Fork child
13424 $self->handle_sigchld();
13425 defined(my $pid = fork()) or die("Can't fork: $!");
13426 if ($pid) {
13427 eval {
13428 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
13429 $client->login($user, $passwd);
13430 $client->type('binary');
13431
13432 my ($resp_code, $resp_msg) = $client->rest($offset);
13433
13434 my $expected = 350;
13435 $self->assert($expected == $resp_code,
13436 test_msg("Expected response code $expected, got $resp_code"));
13437
13438 $expected = "Restarting at $offset. Send STORE or RETRIEVE to initiate transfer";
13439 $self->assert($expected eq $resp_msg,
13440 test_msg("Expected response message '$expected', got '$resp_msg'"));
13441
13442 my $conn = $client->retr_raw($test_file);
13443 unless ($conn) {
13444 die("Failed to RETR: " . $client->response_code() . " " .
13445 $client->response_msg());
13446 }
13447
13448 my $buf;
13449 $conn->read($buf, 8192, 30);
13450 eval { $conn->close() };
13451
13452 $resp_code = $client->response_code();
13453 $resp_msg = $client->response_msg();
13454 $self->assert_transfer_ok($resp_code, $resp_msg);
13455
13456 $client->quit();
13457 };
13458
13459 if ($@) {
13460 $ex = $@;
13461 }
13462
13463 $wfh->print("done\n");
13464 $wfh->flush();
13465
13466 } else {
13467 eval { server_wait($config_file, $rfh) };
13468 if ($@) {
13469 warn($@);
13470 exit 1;
13471 }
13472
13473 exit 0;
13474 }
13475
13476 # Stop server
13477 server_stop($pid_file);
13478
13479 $self->assert_child_ok($pid);
13480
13481 # Now, read in the ExtendedLog, and see whether the %{note:file-offset}
13482 # variable was properly written out.
13483 if (open(my $fh, "< $ext_log")) {
13484 my $ok = 0;
13485
13486 my $line = <$fh>;
13487 chomp($line);
13488 close($fh);
13489
13490 if ($line =~ /^(.*?): (\d+)$/) {
13491 my $path = $1;
13492 my $pos = $2;
13493
13494 if ($^O eq 'darwin') {
13495 # MacOSX-specific hack
13496 $test_file = '/private' . $test_file;
13497 }
13498
13499 $self->assert($test_file eq $path,
13500 test_msg("Expected '$test_file', got '$path'"));
13501
13502 $self->assert($pos == $offset,
13503 test_msg("Expected offset $offset, got $pos"));
13504
13505 $ok = 1;
13506 }
13507
13508 $self->assert($ok,
13509 test_msg("ExtendedLog message '$line' did not contain expected content"));
13510
13511 } else {
13512 die("Can't read $ext_log: $!");
13513 }
13514
13515 if ($ex) {
13516 test_append_logfile($log_file, $ex);
13517 unlink($log_file);
13518
13519 die($ex);
13520 }
13521
13522 unlink($log_file);
13523 }
13524
13525 sub extlog_var_file_size_retr {
13526 my $self = shift;
13527 my $tmpdir = $self->{tmpdir};
13528 my $setup = test_setup($tmpdir, 'extlog');
13529
13530 my $test_file = File::Spec->rel2abs($setup->{config_file});
13531
13532 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
13533
13534 my $config = {
13535 PidFile => $setup->{pid_file},
13536 ScoreboardFile => $setup->{scoreboard_file},
13537 SystemLog => $setup->{log_file},
13538
13539 AuthUserFile => $setup->{auth_user_file},
13540 AuthGroupFile => $setup->{auth_group_file},
13541 AuthOrder => 'mod_auth_file.c',
13542
13543 LogFormat => 'custom "%f: %{file-size}"',
13544 ExtendedLog => "$ext_log READ custom",
13545 AllowRetrieveRestart => 'true',
13546
13547 IfModules => {
13548 'mod_delay.c' => {
13549 DelayEngine => 'off',
13550 },
13551 },
13552 };
13553
13554 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13555 $config);
13556
13557 # Open pipes, for use between the parent and child processes. Specifically,
13558 # the child will indicate when it's done with its test by writing a message
13559 # to the parent.
13560 my ($rfh, $wfh);
13561 unless (pipe($rfh, $wfh)) {
13562 die("Can't open pipe: $!");
13563 }
13564
13565 my $ex;
13566
13567 # Fork child
13568 $self->handle_sigchld();
13569 defined(my $pid = fork()) or die("Can't fork: $!");
13570 if ($pid) {
13571 eval {
13572 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
13573 $client->login($setup->{user}, $setup->{passwd});
13574 $client->type('binary');
13575
13576 my $conn = $client->retr_raw($test_file);
13577 unless ($conn) {
13578 die("Failed to RETR: " . $client->response_code() . " " .
13579 $client->response_msg());
13580 }
13581
13582 my $buf;
13583 $conn->read($buf, 8192, 30);
13584 eval { $conn->close() };
13585
13586 my $resp_code = $client->response_code();
13587 my $resp_msg = $client->response_msg();
13588 $self->assert_transfer_ok($resp_code, $resp_msg);
13589
13590 $client->quit();
13591 };
13592 if ($@) {
13593 $ex = $@;
13594 }
13595
13596 $wfh->print("done\n");
13597 $wfh->flush();
13598
13599 } else {
13600 eval { server_wait($setup->{config_file}, $rfh) };
13601 if ($@) {
13602 warn($@);
13603 exit 1;
13604 }
13605
13606 exit 0;
13607 }
13608
13609 # Stop server
13610 server_stop($setup->{pid_file});
13611 $self->assert_child_ok($pid);
13612
13613 # Now, read in the ExtendedLog, and see whether the %{file-size} variable
13614 # was properly written out.
13615 eval {
13616 if (open(my $fh, "< $ext_log")) {
13617 my $ok = 0;
13618
13619 my $line = <$fh>;
13620 chomp($line);
13621 close($fh);
13622
13623 if ($line =~ /^(.*?): (\d+)$/) {
13624 my $path = $1;
13625 my $size = $2;
13626
13627 if ($^O eq 'darwin') {
13628 # MacOSX-specific hack
13629 $test_file = '/private' . $test_file;
13630 }
13631
13632 $self->assert($test_file eq $path,
13633 test_msg("Expected '$test_file', got '$path'"));
13634
13635 my $expected = -s $setup->{config_file};
13636 $self->assert($expected == $size,
13637 test_msg("Expected size $expected, got $size"));
13638
13639 $ok = 1;
13640 }
13641
13642 $self->assert($ok,
13643 test_msg("ExtendedLog message '$line' did not contain expected content"));
13644
13645 } else {
13646 die("Can't read $ext_log: $!");
13647 }
13648 };
13649 if ($@) {
13650 $ex = $@;
13651 }
13652
13653 test_cleanup($setup->{log_file}, $ex);
13654 }
13655
13656 sub extlog_sftp_var_file_size_retr {
13657 my $self = shift;
13658 my $tmpdir = $self->{tmpdir};
13659 my $setup = test_setup($tmpdir, 'extlog');
13660
13661 my $test_file = File::Spec->rel2abs($setup->{config_file});
13662
13663 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
13664
13665 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
13666 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
13667
13668 my $config = {
13669 PidFile => $setup->{pid_file},
13670 ScoreboardFile => $setup->{scoreboard_file},
13671 SystemLog => $setup->{log_file},
13672 TraceLog => $setup->{log_file},
13673 Trace => 'DEFAULT:10 sftp:20',
13674
13675 AuthUserFile => $setup->{auth_user_file},
13676 AuthGroupFile => $setup->{auth_group_file},
13677 AuthOrder => 'mod_auth_file.c',
13678
13679 LogFormat => 'custom "%m: %f: %{file-size}"',
13680 ExtendedLog => "$ext_log READ custom",
13681 AllowRetrieveRestart => 'true',
13682
13683 IfModules => {
13684 'mod_delay.c' => {
13685 DelayEngine => 'off',
13686 },
13687
13688 'mod_sftp.c' => [
13689 "SFTPEngine on",
13690 "SFTPLog $setup->{log_file}",
13691 "SFTPHostKey $rsa_host_key",
13692 "SFTPHostKey $dsa_host_key",
13693 ],
13694 },
13695 };
13696
13697 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13698 $config);
13699
13700 # Open pipes, for use between the parent and child processes. Specifically,
13701 # the child will indicate when it's done with its test by writing a message
13702 # to the parent.
13703 my ($rfh, $wfh);
13704 unless (pipe($rfh, $wfh)) {
13705 die("Can't open pipe: $!");
13706 }
13707
13708 require Net::SSH2;
13709 my $ex;
13710
13711 # Fork child
13712 $self->handle_sigchld();
13713 defined(my $pid = fork()) or die("Can't fork: $!");
13714 if ($pid) {
13715 eval {
13716 my $ssh2 = Net::SSH2->new();
13717 sleep(1);
13718
13719 unless ($ssh2->connect('127.0.0.1', $port)) {
13720 my ($err_code, $err_name, $err_str) = $ssh2->error();
13721 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
13722 }
13723
13724 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
13725 my ($err_code, $err_name, $err_str) = $ssh2->error();
13726 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
13727 }
13728
13729 my $sftp = $ssh2->sftp();
13730 unless ($sftp) {
13731 my ($err_code, $err_name, $err_str) = $ssh2->error();
13732 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
13733 }
13734
13735 my $path = 'extlog.conf';
13736 my $fh = $sftp->open($path, O_RDONLY);
13737 unless ($fh) {
13738 my ($err_code, $err_name) = $sftp->error();
13739 die("Can't open $path: [$err_name] ($err_code)");
13740 }
13741
13742 my $buf;
13743 my $size = 0;
13744
13745 my $res = $fh->read($buf, 8192);
13746 while ($res) {
13747 $size += $res;
13748 $res = $fh->read($buf, 8192);
13749 }
13750
13751 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
13752 $fh = undef;
13753
13754 # To close the SFTP channel, we have to explicitly destroy the object
13755 $sftp = undef;
13756
13757 $ssh2->disconnect();
13758 };
13759 if ($@) {
13760 $ex = $@;
13761 }
13762
13763 $wfh->print("done\n");
13764 $wfh->flush();
13765
13766 } else {
13767 eval { server_wait($setup->{config_file}, $rfh) };
13768 if ($@) {
13769 warn($@);
13770 exit 1;
13771 }
13772
13773 exit 0;
13774 }
13775
13776 # Stop server
13777 server_stop($setup->{pid_file});
13778 $self->assert_child_ok($pid);
13779
13780 # Now, read in the ExtendedLog, and see whether the %{file-size} variable
13781 # was properly written out.
13782 eval {
13783 if (open(my $fh, "< $ext_log")) {
13784 my $ok = 0;
13785
13786 while (my $line = <$fh>) {
13787 chomp($line);
13788
13789 if ($line =~ /^(\S+): (.*?): (\d+)$/) {
13790 my $req = $1;
13791 my $path = $2;
13792 my $size = $3;
13793
13794 if ($ENV{TEST_VERBOSE}) {
13795 print STDERR "# line: $line\n";
13796 }
13797
13798 if ($req ne 'RETR') {
13799 next;
13800 }
13801
13802 if ($^O eq 'darwin') {
13803 # MacOSX-specific hack
13804 $test_file = '/private' . $test_file;
13805 }
13806
13807 $self->assert($test_file eq $path,
13808 test_msg("Expected '$test_file', got '$path'"));
13809
13810 my $expected = -s $setup->{config_file};
13811 $self->assert($expected == $size,
13812 test_msg("Expected size $expected, got $size"));
13813
13814 $ok = 1;
13815 last;
13816 }
13817 }
13818
13819 close($fh);
13820
13821 $self->assert($ok,
13822 test_msg("ExtendedLog did not contain expected content"));
13823
13824 } else {
13825 die("Can't read $ext_log: $!");
13826 }
13827 };
13828 if ($@) {
13829 $ex = $@;
13830 }
13831
13832 test_cleanup($setup->{log_file}, $ex);
13833 }
13834
13835 sub extlog_var_file_size_stor {
13836 my $self = shift;
13837 my $tmpdir = $self->{tmpdir};
13838 my $setup = test_setup($tmpdir, 'extlog');
13839
13840 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
13841 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
13842
13843 my $config = {
13844 PidFile => $setup->{pid_file},
13845 ScoreboardFile => $setup->{scoreboard_file},
13846 SystemLog => $setup->{log_file},
13847
13848 AuthUserFile => $setup->{auth_user_file},
13849 AuthGroupFile => $setup->{auth_group_file},
13850 AuthOrder => 'mod_auth_file.c',
13851
13852 LogFormat => 'custom "%f: %{file-size}"',
13853 ExtendedLog => "$ext_log WRITE custom",
13854
13855 IfModules => {
13856 'mod_delay.c' => {
13857 DelayEngine => 'off',
13858 },
13859 },
13860 };
13861
13862 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13863 $config);
13864
13865 # Open pipes, for use between the parent and child processes. Specifically,
13866 # the child will indicate when it's done with its test by writing a message
13867 # to the parent.
13868 my ($rfh, $wfh);
13869 unless (pipe($rfh, $wfh)) {
13870 die("Can't open pipe: $!");
13871 }
13872
13873 my $ex;
13874
13875 # Fork child
13876 $self->handle_sigchld();
13877 defined(my $pid = fork()) or die("Can't fork: $!");
13878 if ($pid) {
13879 eval {
13880 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
13881 $client->login($setup->{user}, $setup->{passwd});
13882 $client->type('binary');
13883
13884 my $conn = $client->stor_raw($test_file);
13885 unless ($conn) {
13886 die("Failed to STOR: " . $client->response_code() . " " .
13887 $client->response_msg());
13888 }
13889
13890 my $buf = "Hello, World!\n";
13891 $conn->write($buf, length($buf), 30);
13892 eval { $conn->close() };
13893
13894 my $resp_code = $client->response_code();
13895 my $resp_msg = $client->response_msg();
13896 $self->assert_transfer_ok($resp_code, $resp_msg);
13897
13898 $client->quit();
13899 };
13900 if ($@) {
13901 $ex = $@;
13902 }
13903
13904 $wfh->print("done\n");
13905 $wfh->flush();
13906
13907 } else {
13908 eval { server_wait($setup->{config_file}, $rfh) };
13909 if ($@) {
13910 warn($@);
13911 exit 1;
13912 }
13913
13914 exit 0;
13915 }
13916
13917 # Stop server
13918 server_stop($setup->{pid_file});
13919 $self->assert_child_ok($pid);
13920
13921 # Now, read in the ExtendedLog, and see whether the %{file-size} variable
13922 # was properly written out.
13923 eval {
13924 if (open(my $fh, "< $ext_log")) {
13925 my $ok = 0;
13926
13927 my $line = <$fh>;
13928 chomp($line);
13929 close($fh);
13930
13931 if ($line =~ /^(.*?): (\d+)$/) {
13932 my $path = $1;
13933 my $size = $2;
13934
13935 if ($^O eq 'darwin') {
13936 # MacOSX-specific hack
13937 $test_file = '/private' . $test_file;
13938 }
13939
13940 $self->assert($test_file eq $path,
13941 test_msg("Expected '$test_file', got '$path'"));
13942
13943 my $expected = -s $test_file;
13944 $self->assert($expected == $size,
13945 test_msg("Expected size $expected, got $size"));
13946
13947 $ok = 1;
13948 }
13949
13950 $self->assert($ok,
13951 test_msg("ExtendedLog message '$line' did not contain expected content"));
13952
13953 } else {
13954 die("Can't read $ext_log: $!");
13955 }
13956 };
13957 if ($@) {
13958 $ex = $@;
13959 }
13960
13961 test_cleanup($setup->{log_file}, $ex);
13962 }
13963
13964 sub extlog_sftp_var_file_size_stor {
13965 my $self = shift;
13966 my $tmpdir = $self->{tmpdir};
13967 my $setup = test_setup($tmpdir, 'extlog');
13968
13969 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
13970 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
13971
13972 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
13973 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
13974
13975 my $config = {
13976 PidFile => $setup->{pid_file},
13977 ScoreboardFile => $setup->{scoreboard_file},
13978 SystemLog => $setup->{log_file},
13979 TraceLog => $setup->{log_file},
13980 Trace => 'DEFAULT:10 sftp:20',
13981
13982 AuthUserFile => $setup->{auth_user_file},
13983 AuthGroupFile => $setup->{auth_group_file},
13984 AuthOrder => 'mod_auth_file.c',
13985
13986 LogFormat => 'custom "%m: %f: %{file-size}"',
13987 ExtendedLog => "$ext_log WRITE custom",
13988 AllowRetrieveRestart => 'true',
13989
13990 IfModules => {
13991 'mod_delay.c' => {
13992 DelayEngine => 'off',
13993 },
13994
13995 'mod_sftp.c' => [
13996 "SFTPEngine on",
13997 "SFTPLog $setup->{log_file}",
13998 "SFTPHostKey $rsa_host_key",
13999 "SFTPHostKey $dsa_host_key",
14000 ],
14001 },
14002 };
14003
14004 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14005 $config);
14006
14007 # Open pipes, for use between the parent and child processes. Specifically,
14008 # the child will indicate when it's done with its test by writing a message
14009 # to the parent.
14010 my ($rfh, $wfh);
14011 unless (pipe($rfh, $wfh)) {
14012 die("Can't open pipe: $!");
14013 }
14014
14015 require Net::SSH2;
14016 my $ex;
14017
14018 # Fork child
14019 $self->handle_sigchld();
14020 defined(my $pid = fork()) or die("Can't fork: $!");
14021 if ($pid) {
14022 eval {
14023 my $ssh2 = Net::SSH2->new();
14024 sleep(1);
14025
14026 unless ($ssh2->connect('127.0.0.1', $port)) {
14027 my ($err_code, $err_name, $err_str) = $ssh2->error();
14028 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
14029 }
14030
14031 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
14032 my ($err_code, $err_name, $err_str) = $ssh2->error();
14033 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
14034 }
14035
14036 my $sftp = $ssh2->sftp();
14037 unless ($sftp) {
14038 my ($err_code, $err_name, $err_str) = $ssh2->error();
14039 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
14040 }
14041
14042 my $path = 'test.txt';
14043 my $fh = $sftp->open($path, O_WRONLY|O_CREAT);
14044 unless ($fh) {
14045 my ($err_code, $err_name) = $sftp->error();
14046 die("Can't open $path: [$err_name] ($err_code)");
14047 }
14048
14049 my $buf = "Hello, World!\n";
14050 my $res = $fh->write($buf);
14051
14052 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
14053 $fh = undef;
14054
14055 # To close the SFTP channel, we have to explicitly destroy the object
14056 $sftp = undef;
14057
14058 $ssh2->disconnect();
14059 };
14060 if ($@) {
14061 $ex = $@;
14062 }
14063
14064 $wfh->print("done\n");
14065 $wfh->flush();
14066
14067 } else {
14068 eval { server_wait($setup->{config_file}, $rfh) };
14069 if ($@) {
14070 warn($@);
14071 exit 1;
14072 }
14073
14074 exit 0;
14075 }
14076
14077 # Stop server
14078 server_stop($setup->{pid_file});
14079 $self->assert_child_ok($pid);
14080
14081 # Now, read in the ExtendedLog, and see whether the %{file-size} variable
14082 # was properly written out.
14083 eval {
14084 if (open(my $fh, "< $ext_log")) {
14085 my $ok = 0;
14086
14087 while (my $line = <$fh>) {
14088 chomp($line);
14089
14090 if ($line =~ /^(\S+): (.*?): (\d+)$/) {
14091 my $req = $1;
14092 my $path = $2;
14093 my $size = $3;
14094
14095 if ($ENV{TEST_VERBOSE}) {
14096 print STDERR "# line: $line\n";
14097 }
14098
14099 if ($req ne 'STOR') {
14100 next;
14101 }
14102
14103 if ($^O eq 'darwin') {
14104 # MacOSX-specific hack
14105 $test_file = '/private' . $test_file;
14106 }
14107
14108 $self->assert($test_file eq $path,
14109 test_msg("Expected '$test_file', got '$path'"));
14110
14111 my $expected = -s $test_file;
14112 $self->assert($expected == $size,
14113 test_msg("Expected size $expected, got $size"));
14114
14115 $ok = 1;
14116 last;
14117 }
14118 }
14119
14120 close($fh);
14121
14122 $self->assert($ok,
14123 test_msg("ExtendedLog did not contain expected content"));
14124
14125 } else {
14126 die("Can't read $ext_log: $!");
14127 }
14128 };
14129 if ($@) {
14130 $ex = $@;
14131 }
14132
14133 test_cleanup($setup->{log_file}, $ex);
14134 }
14135
14136 sub extlog_var_transfer_type_retr {
14137 my $self = shift;
14138 my $tmpdir = $self->{tmpdir};
14139 my $setup = test_setup($tmpdir, 'extlog');
14140
14141 my $test_file = File::Spec->rel2abs($setup->{config_file});
14142
14143 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
14144
14145 my $config = {
14146 PidFile => $setup->{pid_file},
14147 ScoreboardFile => $setup->{scoreboard_file},
14148 SystemLog => $setup->{log_file},
14149
14150 AuthUserFile => $setup->{auth_user_file},
14151 AuthGroupFile => $setup->{auth_group_file},
14152 AuthOrder => 'mod_auth_file.c',
14153
14154 LogFormat => 'custom "%f: %{transfer-type}"',
14155 ExtendedLog => "$ext_log READ custom",
14156 AllowRetrieveRestart => 'true',
14157
14158 IfModules => {
14159 'mod_delay.c' => {
14160 DelayEngine => 'off',
14161 },
14162 },
14163 };
14164
14165 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14166 $config);
14167
14168 # Open pipes, for use between the parent and child processes. Specifically,
14169 # the child will indicate when it's done with its test by writing a message
14170 # to the parent.
14171 my ($rfh, $wfh);
14172 unless (pipe($rfh, $wfh)) {
14173 die("Can't open pipe: $!");
14174 }
14175
14176 my $ex;
14177
14178 # Fork child
14179 $self->handle_sigchld();
14180 defined(my $pid = fork()) or die("Can't fork: $!");
14181 if ($pid) {
14182 eval {
14183 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
14184 $client->login($setup->{user}, $setup->{passwd});
14185 $client->type('binary');
14186
14187 my $conn = $client->retr_raw($test_file);
14188 unless ($conn) {
14189 die("Failed to RETR: " . $client->response_code() . " " .
14190 $client->response_msg());
14191 }
14192
14193 my $buf;
14194 $conn->read($buf, 8192, 30);
14195 eval { $conn->close() };
14196
14197 my $resp_code = $client->response_code();
14198 my $resp_msg = $client->response_msg();
14199 $self->assert_transfer_ok($resp_code, $resp_msg);
14200
14201 $client->type('ascii');
14202
14203 $conn = $client->retr_raw($test_file);
14204 unless ($conn) {
14205 die("Failed to RETR: " . $client->response_code() . " " .
14206 $client->response_msg());
14207 }
14208
14209 $conn->read($buf, 8192, 30);
14210 eval { $conn->close() };
14211
14212 $resp_code = $client->response_code();
14213 $resp_msg = $client->response_msg();
14214 $self->assert_transfer_ok($resp_code, $resp_msg);
14215
14216 $client->quit();
14217 };
14218 if ($@) {
14219 $ex = $@;
14220 }
14221
14222 $wfh->print("done\n");
14223 $wfh->flush();
14224
14225 } else {
14226 eval { server_wait($setup->{config_file}, $rfh) };
14227 if ($@) {
14228 warn($@);
14229 exit 1;
14230 }
14231
14232 exit 0;
14233 }
14234
14235 # Stop server
14236 server_stop($setup->{pid_file});
14237 $self->assert_child_ok($pid);
14238
14239 # Now, read in the ExtendedLog, and see whether the %{transfer-type} variable
14240 # was properly written out.
14241 eval {
14242 if (open(my $fh, "< $ext_log")) {
14243 my $ok = 0;
14244
14245 if ($^O eq 'darwin') {
14246 # MacOSX-specific hack
14247 $test_file = '/private' . $test_file;
14248 }
14249
14250 while (my $line = <$fh>) {
14251 chomp($line);
14252
14253 if ($ENV{TEST_VERBOSE}) {
14254 print STDERR "# line: $line\n";
14255 }
14256
14257 if ($line =~ /^(.*?): (\S+)$/) {
14258 my $path = $1;
14259 my $xfer_type = $2;
14260
14261 $self->assert($test_file eq $path,
14262 test_msg("Expected '$test_file', got '$path'"));
14263
14264 my $expected = 'binary';
14265 if ($ok == 1) {
14266 $expected = 'ASCII';
14267 }
14268 $self->assert($expected eq $xfer_type,
14269 test_msg("Expected transfer type '$expected', got '$xfer_type'"));
14270
14271 $ok++;
14272 }
14273 }
14274
14275 close($fh);
14276
14277 $self->assert($ok == 2,
14278 test_msg("ExtendedLog did not contain expected content"));
14279
14280 } else {
14281 die("Can't read $ext_log: $!");
14282 }
14283 };
14284 if ($@) {
14285 $ex = $@;
14286 }
14287
14288 test_cleanup($setup->{log_file}, $ex);
14289 }
14290
14291 sub extlog_var_transfer_type_stor {
14292 my $self = shift;
14293 my $tmpdir = $self->{tmpdir};
14294 my $setup = test_setup($tmpdir, 'extlog');
14295
14296 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
14297
14298 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
14299
14300 my $config = {
14301 PidFile => $setup->{pid_file},
14302 ScoreboardFile => $setup->{scoreboard_file},
14303 SystemLog => $setup->{log_file},
14304
14305 AuthUserFile => $setup->{auth_user_file},
14306 AuthGroupFile => $setup->{auth_group_file},
14307 AuthOrder => 'mod_auth_file.c',
14308
14309 LogFormat => 'custom "%f: %{transfer-type}"',
14310 ExtendedLog => "$ext_log WRITE custom",
14311
14312 AllowOverwrite => 'true',
14313 AllowStoreRestart => 'true',
14314
14315 IfModules => {
14316 'mod_delay.c' => {
14317 DelayEngine => 'off',
14318 },
14319 },
14320 };
14321
14322 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14323 $config);
14324
14325 # Open pipes, for use between the parent and child processes. Specifically,
14326 # the child will indicate when it's done with its test by writing a message
14327 # to the parent.
14328 my ($rfh, $wfh);
14329 unless (pipe($rfh, $wfh)) {
14330 die("Can't open pipe: $!");
14331 }
14332
14333 my $ex;
14334
14335 # Fork child
14336 $self->handle_sigchld();
14337 defined(my $pid = fork()) or die("Can't fork: $!");
14338 if ($pid) {
14339 eval {
14340 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
14341 $client->login($setup->{user}, $setup->{passwd});
14342 $client->type('binary');
14343
14344 my $conn = $client->stor_raw($test_file);
14345 unless ($conn) {
14346 die("Failed to RETR: " . $client->response_code() . " " .
14347 $client->response_msg());
14348 }
14349
14350 my $buf = "Hello, World!\n";
14351 $conn->write($buf, length($buf), 30);
14352 eval { $conn->close() };
14353
14354 my $resp_code = $client->response_code();
14355 my $resp_msg = $client->response_msg();
14356 $self->assert_transfer_ok($resp_code, $resp_msg);
14357
14358 $client->type('ascii');
14359
14360 $conn = $client->stor_raw($test_file);
14361 unless ($conn) {
14362 die("Failed to RETR: " . $client->response_code() . " " .
14363 $client->response_msg());
14364 }
14365
14366 $conn->write($buf, length($buf), 30);
14367 eval { $conn->close() };
14368
14369 $resp_code = $client->response_code();
14370 $resp_msg = $client->response_msg();
14371 $self->assert_transfer_ok($resp_code, $resp_msg);
14372
14373 $client->quit();
14374 };
14375 if ($@) {
14376 $ex = $@;
14377 }
14378
14379 $wfh->print("done\n");
14380 $wfh->flush();
14381
14382 } else {
14383 eval { server_wait($setup->{config_file}, $rfh) };
14384 if ($@) {
14385 warn($@);
14386 exit 1;
14387 }
14388
14389 exit 0;
14390 }
14391
14392 # Stop server
14393 server_stop($setup->{pid_file});
14394 $self->assert_child_ok($pid);
14395
14396 # Now, read in the ExtendedLog, and see whether the %{transfer-type} variable
14397 # was properly written out.
14398 eval {
14399 if (open(my $fh, "< $ext_log")) {
14400 my $ok = 0;
14401
14402 if ($^O eq 'darwin') {
14403 # MacOSX-specific hack
14404 $test_file = '/private' . $test_file;
14405 }
14406
14407 while (my $line = <$fh>) {
14408 chomp($line);
14409
14410 if ($ENV{TEST_VERBOSE}) {
14411 print STDERR "# line: $line\n";
14412 }
14413
14414 if ($line =~ /^(.*?): (\S+)$/) {
14415 my $path = $1;
14416 my $xfer_type = $2;
14417
14418 $self->assert($test_file eq $path,
14419 test_msg("Expected '$test_file', got '$path'"));
14420
14421 my $expected = 'binary';
14422 if ($ok == 1) {
14423 $expected = 'ASCII';
14424 }
14425 $self->assert($expected eq $xfer_type,
14426 test_msg("Expected transfer type '$expected', got '$xfer_type'"));
14427
14428 $ok++;
14429 }
14430 }
14431
14432 close($fh);
14433
14434 $self->assert($ok == 2,
14435 test_msg("ExtendedLog did not contain expected content"));
14436
14437 } else {
14438 die("Can't read $ext_log: $!");
14439 }
14440 };
14441 if ($@) {
14442 $ex = $@;
14443 }
14444
14445 test_cleanup($setup->{log_file}, $ex);
14446 }
14447
14448 sub extlog_file_transfer_secs {
14449 my $self = shift;
14450 my $tmpdir = $self->{tmpdir};
14451 my $setup = test_setup($tmpdir, 'extlog');
14452
14453 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
14454 if (open(my $fh, "> $test_file")) {
14455 print $fh "ABCDefgh" x 8192;
14456 unless (close($fh)) {
14457 die("Can't write $test_file: $!");
14458 }
14459 } else {
14460 die("Can't open $test_file: $!");
14461 }
14462
14463 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
14464
14465 my $config = {
14466 PidFile => $setup->{pid_file},
14467 ScoreboardFile => $setup->{scoreboard_file},
14468 SystemLog => $setup->{log_file},
14469
14470 AuthUserFile => $setup->{auth_user_file},
14471 AuthGroupFile => $setup->{auth_group_file},
14472 AuthOrder => 'mod_auth_file.c',
14473
14474 # Throttle the transfer, to aid in the timing
14475 TransferRate => 'RETR 1',
14476
14477 LogFormat => 'custom "%f: %T"',
14478 ExtendedLog => "$ext_log READ custom",
14479
14480 IfModules => {
14481 'mod_delay.c' => {
14482 DelayEngine => 'off',
14483 },
14484 },
14485 };
14486
14487 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14488 $config);
14489
14490 # Open pipes, for use between the parent and child processes. Specifically,
14491 # the child will indicate when it's done with its test by writing a message
14492 # to the parent.
14493 my ($rfh, $wfh);
14494 unless (pipe($rfh, $wfh)) {
14495 die("Can't open pipe: $!");
14496 }
14497
14498 my $ex;
14499
14500 # Fork child
14501 $self->handle_sigchld();
14502 defined(my $pid = fork()) or die("Can't fork: $!");
14503 if ($pid) {
14504 eval {
14505 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
14506 $client->login($setup->{user}, $setup->{passwd});
14507 $client->type('binary');
14508
14509 my $conn = $client->retr_raw($test_file);
14510 unless ($conn) {
14511 die("Failed to RETR: " . $client->response_code() . " " .
14512 $client->response_msg());
14513 }
14514
14515 my ($buf, $data);
14516 while ($conn->read($data, 8192, 30)) {
14517 $buf .= $data;
14518 }
14519 eval { $conn->close() };
14520
14521 my $resp_code = $client->response_code();
14522 my $resp_msg = $client->response_msg();
14523 $self->assert_transfer_ok($resp_code, $resp_msg);
14524
14525 $client->quit();
14526 };
14527
14528 if ($@) {
14529 $ex = $@;
14530 }
14531
14532 $wfh->print("done\n");
14533 $wfh->flush();
14534
14535 } else {
14536 eval { server_wait($setup->{config_file}, $rfh, 30) };
14537 if ($@) {
14538 warn($@);
14539 exit 1;
14540 }
14541
14542 exit 0;
14543 }
14544
14545 # Stop server
14546 server_stop($setup->{pid_file});
14547 $self->assert_child_ok($pid);
14548
14549 # Now, read in the ExtendedLog, and see whether the %T variable was properly
14550 # written out.
14551 eval {
14552 if (open(my $fh, "< $ext_log")) {
14553 my $ok = 0;
14554
14555 my $line = <$fh>;
14556 chomp($line);
14557 close($fh);
14558
14559 if ($line =~ /^(.*?): (\S+)$/) {
14560 my $path = $1;
14561 my $secs = $2;
14562
14563 if ($ENV{TEST_VERBOSE}) {
14564 print STDERR "# ExtendedLog: $line\n";
14565 }
14566
14567 if ($^O eq 'darwin') {
14568 # MacOSX-specific hack
14569 $test_file = '/private' . $test_file;
14570 }
14571
14572 $self->assert($test_file eq $path,
14573 test_msg("Expected '$test_file', got '$path'"));
14574
14575 my $expected_min = 9;
14576 $self->assert($expected_min < $secs,
14577 test_msg("Expected at least transfer seconds $expected_min, got $secs"));
14578
14579 $ok = 1;
14580 }
14581
14582 $self->assert($ok,
14583 test_msg("ExtendedLog message '$line' did not contain expected content"));
14584
14585 } else {
14586 die("Can't read $ext_log: $!");
14587 }
14588 };
14589 if ($@) {
14590 $ex = $@;
14591 }
14592
14593 test_cleanup($setup->{log_file}, $ex);
14594 }
14595
14596 sub extlog_file_transfer_millisecs_bug4218 {
14597 my $self = shift;
14598 my $tmpdir = $self->{tmpdir};
14599 my $setup = test_setup($tmpdir, 'extlog');
14600
14601 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
14602 if (open(my $fh, "> $test_file")) {
14603 print $fh "ABCDefgh" x 8192;
14604 unless (close($fh)) {
14605 die("Can't write $test_file: $!");
14606 }
14607 } else {
14608 die("Can't open $test_file: $!");
14609 }
14610
14611 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
14612
14613 my $config = {
14614 PidFile => $setup->{pid_file},
14615 ScoreboardFile => $setup->{scoreboard_file},
14616 SystemLog => $setup->{log_file},
14617
14618 AuthUserFile => $setup->{auth_user_file},
14619 AuthGroupFile => $setup->{auth_group_file},
14620 AuthOrder => 'mod_auth_file.c',
14621
14622 # Throttle the transfer, to aid in the timing
14623 TransferRate => 'RETR 1',
14624
14625 LogFormat => 'custom "%f: %{transfer-millisecs}"',
14626 ExtendedLog => "$ext_log READ custom",
14627
14628 IfModules => {
14629 'mod_delay.c' => {
14630 DelayEngine => 'off',
14631 },
14632 },
14633 };
14634
14635 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14636 $config);
14637
14638 # Open pipes, for use between the parent and child processes. Specifically,
14639 # the child will indicate when it's done with its test by writing a message
14640 # to the parent.
14641 my ($rfh, $wfh);
14642 unless (pipe($rfh, $wfh)) {
14643 die("Can't open pipe: $!");
14644 }
14645
14646 my $ex;
14647
14648 # Fork child
14649 $self->handle_sigchld();
14650 defined(my $pid = fork()) or die("Can't fork: $!");
14651 if ($pid) {
14652 eval {
14653 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
14654 $client->login($setup->{user}, $setup->{passwd});
14655 $client->type('binary');
14656
14657 my $conn = $client->retr_raw($test_file);
14658 unless ($conn) {
14659 die("Failed to RETR: " . $client->response_code() . " " .
14660 $client->response_msg());
14661 }
14662
14663 my ($buf, $data);
14664 while ($conn->read($data, 8192, 30)) {
14665 $buf .= $data;
14666 }
14667 eval { $conn->close() };
14668
14669 my $resp_code = $client->response_code();
14670 my $resp_msg = $client->response_msg();
14671 $self->assert_transfer_ok($resp_code, $resp_msg);
14672
14673 $client->quit();
14674 };
14675
14676 if ($@) {
14677 $ex = $@;
14678 }
14679
14680 $wfh->print("done\n");
14681 $wfh->flush();
14682
14683 } else {
14684 eval { server_wait($setup->{config_file}, $rfh, 30) };
14685 if ($@) {
14686 warn($@);
14687 exit 1;
14688 }
14689
14690 exit 0;
14691 }
14692
14693 # Stop server
14694 server_stop($setup->{pid_file});
14695 $self->assert_child_ok($pid);
14696
14697 # Now, read in the ExtendedLog, and see whether the %T variable was properly
14698 # written out.
14699 eval {
14700 if (open(my $fh, "< $ext_log")) {
14701 my $ok = 0;
14702
14703 my $line = <$fh>;
14704 chomp($line);
14705 close($fh);
14706
14707 if ($line =~ /^(.*?): (\d+)$/) {
14708 my $path = $1;
14709 my $secs = $2;
14710
14711 if ($ENV{TEST_VERBOSE}) {
14712 print STDERR "# ExtendedLog: $line\n";
14713 }
14714
14715 if ($^O eq 'darwin') {
14716 # MacOSX-specific hack
14717 $test_file = '/private' . $test_file;
14718 }
14719
14720 $self->assert($test_file eq $path,
14721 test_msg("Expected '$test_file', got '$path'"));
14722
14723 my $expected_min = 9000;
14724 $self->assert($expected_min < $secs,
14725 test_msg("Expected at least transfer seconds $expected_min, got $secs"));
14726
14727 $ok = 1;
14728 }
14729
14730 $self->assert($ok,
14731 test_msg("ExtendedLog message '$line' did not contain expected content"));
14732
14733 } else {
14734 die("Can't read $ext_log: $!");
14735 }
14736 };
14737 if ($@) {
14738 $ex = $@;
14739 }
14740
14741 test_cleanup($setup->{log_file}, $ex);
14742 }
14743
14744 sub extlog_response_millisecs_bug4218 {
14745 my $self = shift;
14746 my $tmpdir = $self->{tmpdir};
14747 my $setup = test_setup($tmpdir, 'extlog');
14748
14749 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
14750 if (open(my $fh, "> $test_file")) {
14751 print $fh "ABCDefgh" x 8192;
14752 unless (close($fh)) {
14753 die("Can't write $test_file: $!");
14754 }
14755 } else {
14756 die("Can't open $test_file: $!");
14757 }
14758
14759 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
14760
14761 my $config = {
14762 PidFile => $setup->{pid_file},
14763 ScoreboardFile => $setup->{scoreboard_file},
14764 SystemLog => $setup->{log_file},
14765
14766 AuthUserFile => $setup->{auth_user_file},
14767 AuthGroupFile => $setup->{auth_group_file},
14768 AuthOrder => 'mod_auth_file.c',
14769
14770 # Throttle the transfer, to aid in the timing
14771 TransferRate => 'RETR 1',
14772
14773 LogFormat => 'custom "%m: %R"',
14774 ExtendedLog => "$ext_log ALL custom",
14775
14776 IfModules => {
14777 'mod_delay.c' => {
14778 DelayEngine => 'off',
14779 },
14780 },
14781 };
14782
14783 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14784 $config);
14785
14786 # Open pipes, for use between the parent and child processes. Specifically,
14787 # the child will indicate when it's done with its test by writing a message
14788 # to the parent.
14789 my ($rfh, $wfh);
14790 unless (pipe($rfh, $wfh)) {
14791 die("Can't open pipe: $!");
14792 }
14793
14794 my $ex;
14795
14796 # Fork child
14797 $self->handle_sigchld();
14798 defined(my $pid = fork()) or die("Can't fork: $!");
14799 if ($pid) {
14800 eval {
14801 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
14802 $client->login($setup->{user}, $setup->{passwd});
14803 $client->type('binary');
14804
14805 my $conn = $client->retr_raw($test_file);
14806 unless ($conn) {
14807 die("Failed to RETR: " . $client->response_code() . " " .
14808 $client->response_msg());
14809 }
14810
14811 my ($buf, $data);
14812 while ($conn->read($data, 8192, 30)) {
14813 $buf .= $data;
14814 }
14815 eval { $conn->close() };
14816
14817 my $resp_code = $client->response_code();
14818 my $resp_msg = $client->response_msg();
14819 $self->assert_transfer_ok($resp_code, $resp_msg);
14820
14821 $client->quit();
14822 };
14823
14824 if ($@) {
14825 $ex = $@;
14826 }
14827
14828 $wfh->print("done\n");
14829 $wfh->flush();
14830
14831 } else {
14832 eval { server_wait($setup->{config_file}, $rfh, 30) };
14833 if ($@) {
14834 warn($@);
14835 exit 1;
14836 }
14837
14838 exit 0;
14839 }
14840
14841 # Stop server
14842 server_stop($setup->{pid_file});
14843 $self->assert_child_ok($pid);
14844
14845 # Now, read in the ExtendedLog, and see whether the %T variable was properly
14846 # written out.
14847 eval {
14848 if (open(my $fh, "< $ext_log")) {
14849 my $ok = 0;
14850
14851 while (my $line = <$fh>) {
14852 chomp($line);
14853
14854 if ($ENV{TEST_VERBOSE}) {
14855 print STDERR "# ExtendedLog: $line\n";
14856 }
14857
14858 if ($line =~ /^(.*?): (\d+)$/) {
14859 $ok = 1;
14860 }
14861 }
14862
14863 close($fh);
14864
14865 $self->assert($ok, test_msg("ExtendedLog contained unexpected content"));
14866
14867 } else {
14868 die("Can't read $ext_log: $!");
14869 }
14870 };
14871 if ($@) {
14872 $ex = $@;
14873 }
14874
14875 test_cleanup($setup->{log_file}, $ex);
14876 }
14877
14878 sub extlog_stor_var_f_xfer_timed_out {
14879 my $self = shift;
14880 my $tmpdir = $self->{tmpdir};
14881 my $setup = test_setup($tmpdir, 'extlog');
14882
14883 my $sub_dir = File::Spec->rel2abs("$tmpdir/sub.d");
14884 mkpath($sub_dir);
14885
14886 # Make sure that, if we're running as root, that the sub directory has
14887 # permissions/privs set for the account we create
14888 if ($< == 0) {
14889 unless (chmod(0755, $sub_dir)) {
14890 die("Can't set perms on $sub_dir to 0755: $!");
14891 }
14892
14893 unless (chown($setup->{uid}, $setup->{gid}, $sub_dir)) {
14894 die("Can't set owner of $sub_dir to $setup->{uid}/$setup->{gid}: $!");
14895 }
14896 }
14897
14898 my $dst_file = File::Spec->rel2abs("$sub_dir/dst.dat");
14899 my $timeout_stalled = 2;
14900
14901 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
14902
14903 my $config = {
14904 PidFile => $setup->{pid_file},
14905 ScoreboardFile => $setup->{scoreboard_file},
14906 SystemLog => $setup->{log_file},
14907 TraceLog => $setup->{log_file},
14908 Trace => 'response:20',
14909
14910 AuthUserFile => $setup->{auth_user_file},
14911 AuthGroupFile => $setup->{auth_group_file},
14912 AuthOrder => 'mod_auth_file.c',
14913
14914 LogFormat => 'custom "%m %s: %f"',
14915 ExtendedLog => "$ext_log ALL custom",
14916 TimeoutStalled => $timeout_stalled,
14917
14918 IfModules => {
14919 'mod_delay.c' => {
14920 DelayEngine => 'off',
14921 },
14922 },
14923 };
14924
14925 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14926 $config);
14927
14928 # Open pipes, for use between the parent and child processes. Specifically,
14929 # the child will indicate when it's done with its test by writing a message
14930 # to the parent.
14931 my ($rfh, $wfh);
14932 unless (pipe($rfh, $wfh)) {
14933 die("Can't open pipe: $!");
14934 }
14935
14936 my $ex;
14937
14938 # Fork child
14939 $self->handle_sigchld();
14940 defined(my $pid = fork()) or die("Can't fork: $!");
14941 if ($pid) {
14942 eval {
14943 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
14944 $client->login($setup->{user}, $setup->{passwd});
14945 $client->cwd('sub.d');
14946
14947 my $conn = $client->stor_raw('dst.dat');
14948 unless ($conn) {
14949 die("Failed to STOR: " . $client->response_code() . " " .
14950 $client->response_msg());
14951 }
14952
14953 my $buf = "Foo";
14954 $conn->write($buf, length($buf));
14955
14956 if ($ENV{TEST_VERBOSE}) {
14957 print STDERR "# Sleeping for $timeout_stalled secs\n";
14958 }
14959 sleep($timeout_stalled + 1);
14960
14961 # Normally we would send a QUIT, but a TimeoutStalled timer would
14962 # have disconnected us.
14963 };
14964 if ($@) {
14965 $ex = $@;
14966 }
14967
14968 $wfh->print("done\n");
14969 $wfh->flush();
14970
14971 } else {
14972 eval { server_wait($setup->{config_file}, $rfh) };
14973 if ($@) {
14974 warn($@);
14975 exit 1;
14976 }
14977
14978 exit 0;
14979 }
14980
14981 # Stop server
14982 server_stop($setup->{pid_file});
14983 $self->assert_child_ok($pid);
14984
14985 # Now, read in the ExtendedLog, and see whether the %f variable was
14986 # properly written out.
14987 eval {
14988 if (open(my $fh, "< $ext_log")) {
14989 my $expected = $dst_file;
14990 my $first_ok = 0;
14991 my $second_ok = 0;
14992
14993 if ($^O eq 'darwin') {
14994 # MacOSX-specific hack
14995 $expected = '/private' . $dst_file;
14996 }
14997
14998 while (my $line = <$fh>) {
14999 chomp($line);
15000
15001 if ($line =~ /^STOR 150: (\S+)$/) {
15002 my $path = $1;
15003
15004 if ($path eq $expected) {
15005 $first_ok = 1;
15006 }
15007 }
15008
15009 if ($line =~ /^STOR 426: (\S+)$/) {
15010 my $path = $1;
15011
15012 if ($path eq $expected) {
15013 $second_ok = 1;
15014 }
15015 }
15016 }
15017
15018 close($fh);
15019
15020 $self->assert($first_ok && $second_ok,
15021 test_msg("Expected ExtendedLog messages did not appear"));
15022
15023 } else {
15024 die("Can't read $ext_log: $!");
15025 }
15026 };
15027 if ($@) {
15028 $ex = $@;
15029 }
15030
15031 test_cleanup($setup->{log_file}, $ex);
15032 }
15033
15034 sub extlog_write_invalid_cmd_bug4313 {
15035 my $self = shift;
15036 my $tmpdir = $self->{tmpdir};
15037 my $setup = test_setup($tmpdir, 'extlog');
15038
15039 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15040
15041 my $config = {
15042 PidFile => $setup->{pid_file},
15043 ScoreboardFile => $setup->{scoreboard_file},
15044 SystemLog => $setup->{log_file},
15045 TraceLog => $setup->{log_file},
15046 Trace => 'response:20',
15047
15048 AuthUserFile => $setup->{auth_user_file},
15049 AuthGroupFile => $setup->{auth_group_file},
15050 AuthOrder => 'mod_auth_file.c',
15051
15052 LogFormat => 'custom "%r"',
15053 ExtendedLog => "$ext_log WRITE custom",
15054
15055 IfModules => {
15056 'mod_delay.c' => {
15057 DelayEngine => 'off',
15058 },
15059 },
15060 };
15061
15062 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15063 $config);
15064
15065 # Open pipes, for use between the parent and child processes. Specifically,
15066 # the child will indicate when it's done with its test by writing a message
15067 # to the parent.
15068 my ($rfh, $wfh);
15069 unless (pipe($rfh, $wfh)) {
15070 die("Can't open pipe: $!");
15071 }
15072
15073 my $ex;
15074
15075 # Fork child
15076 $self->handle_sigchld();
15077 defined(my $pid = fork()) or die("Can't fork: $!");
15078 if ($pid) {
15079 eval {
15080 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 0, 1);
15081 eval { $client->quote('FOO', 'BAR', 'BAZ') };
15082 $client->quit();
15083 };
15084 if ($@) {
15085 $ex = $@;
15086 }
15087
15088 $wfh->print("done\n");
15089 $wfh->flush();
15090
15091 } else {
15092 eval { server_wait($setup->{config_file}, $rfh) };
15093 if ($@) {
15094 warn($@);
15095 exit 1;
15096 }
15097
15098 exit 0;
15099 }
15100
15101 # Stop server
15102 server_stop($setup->{pid_file});
15103 $self->assert_child_ok($pid);
15104
15105 eval {
15106 if (open(my $fh, "< $ext_log")) {
15107 my $ok = 1;
15108
15109 while (my $line = <$fh>) {
15110 chomp($line);
15111
15112 if ($ENV{TEST_VERBOSE}) {
15113 print STDERR "$line\n";
15114 }
15115
15116 $ok = 0;
15117 }
15118
15119 close($fh);
15120 $self->assert($ok, "Unexpected ExtendedLog messages appeared");
15121
15122 } else {
15123 die("Can't read $ext_log: $!");
15124 }
15125 };
15126 if ($@) {
15127 $ex = $@;
15128 }
15129
15130 test_cleanup($setup->{log_file}, $ex);
15131 }
15132
15133 sub extlog_xfer_port_nonxfer_issue912 {
15134 my $self = shift;
15135 my $tmpdir = $self->{tmpdir};
15136 my $setup = test_setup($tmpdir, 'extlog');
15137
15138 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15139
15140 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
15141 if (open(my $fh, "> $test_file")) {
15142 print $fh "A" x 1024;
15143
15144 unless (close($fh)) {
15145 die("Can't write $test_file: $!");
15146 }
15147
15148 } else {
15149 die("Can't open $test_file: $!");
15150 }
15151
15152 my $config = {
15153 PidFile => $setup->{pid_file},
15154 ScoreboardFile => $setup->{scoreboard_file},
15155 SystemLog => $setup->{log_file},
15156
15157 AuthUserFile => $setup->{auth_user_file},
15158 AuthGroupFile => $setup->{auth_group_file},
15159 AuthOrder => 'mod_auth_file.c',
15160
15161 IfModules => {
15162 'mod_delay.c' => {
15163 DelayEngine => 'off',
15164 },
15165 },
15166 };
15167
15168 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15169 $config);
15170
15171 if (open(my $fh, ">> $setup->{config_file}")) {
15172 print $fh <<EOC;
15173 LogFormat custom "%m %{transfer-port}"
15174 ExtendedLog $ext_log ALL custom
15175 EOC
15176 unless (close($fh)) {
15177 die("Can't write $setup->{config_file}: $!");
15178 }
15179
15180 } else {
15181 die("Can't open $setup->{config_file}: $!");
15182 }
15183
15184 # Open pipes, for use between the parent and child processes. Specifically,
15185 # the child will indicate when it's done with its test by writing a message
15186 # to the parent.
15187 my ($rfh, $wfh);
15188 unless (pipe($rfh, $wfh)) {
15189 die("Can't open pipe: $!");
15190 }
15191
15192 my $ex;
15193
15194 # Fork child
15195 $self->handle_sigchld();
15196 defined(my $pid = fork()) or die("Can't fork: $!");
15197 if ($pid) {
15198 eval {
15199 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
15200 $client->login($setup->{user}, $setup->{passwd});
15201 $client->pwd();
15202 $client->quit();
15203 };
15204 if ($@) {
15205 $ex = $@;
15206 }
15207
15208 $wfh->print("done\n");
15209 $wfh->flush();
15210
15211 } else {
15212 eval { server_wait($setup->{config_file}, $rfh) };
15213 if ($@) {
15214 warn($@);
15215 exit 1;
15216 }
15217
15218 exit 0;
15219 }
15220
15221 # Stop server
15222 server_stop($setup->{pid_file});
15223 $self->assert_child_ok($pid);
15224
15225 # Now, read in the ExtendedLog, and see whether the %{transfer-port}
15226 # variable was properly written out.
15227 eval {
15228 if (open(my $fh, "< $ext_log")) {
15229 my $unexpected_xfer_port = 0;
15230
15231 while (my $line = <$fh>) {
15232 chomp($line);
15233
15234 if ($ENV{TEST_VERBOSE}) {
15235 print STDERR "# $line\n";
15236 }
15237
15238 if ($line =~ /^(\S+) (.*)?$/) {
15239 my $cmd = $1;
15240 my $xfer_port = $2;
15241
15242 if ($xfer_port ne '-') {
15243 $unexpected_xfer_port = 1;
15244 last;
15245 }
15246 }
15247 }
15248
15249 close($fh);
15250
15251 $self->assert(!$unexpected_xfer_port,
15252 test_msg("Saw unexpected transfer port in ExtendedLog"));
15253
15254 } else {
15255 die("Can't read $ext_log: $!");
15256 }
15257 };
15258 if ($@) {
15259 $ex = $@;
15260 }
15261
15262 test_cleanup($setup->{log_file}, $ex);
15263 }
15264
15265 sub extlog_xfer_port_success_issue912 {
15266 my $self = shift;
15267 my $tmpdir = $self->{tmpdir};
15268 my $setup = test_setup($tmpdir, 'extlog');
15269
15270 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15271
15272 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
15273 if (open(my $fh, "> $test_file")) {
15274 print $fh "A" x 1024;
15275
15276 unless (close($fh)) {
15277 die("Can't write $test_file: $!");
15278 }
15279
15280 } else {
15281 die("Can't open $test_file: $!");
15282 }
15283
15284 my $config = {
15285 PidFile => $setup->{pid_file},
15286 ScoreboardFile => $setup->{scoreboard_file},
15287 SystemLog => $setup->{log_file},
15288
15289 AuthUserFile => $setup->{auth_user_file},
15290 AuthGroupFile => $setup->{auth_group_file},
15291 AuthOrder => 'mod_auth_file.c',
15292
15293 IfModules => {
15294 'mod_delay.c' => {
15295 DelayEngine => 'off',
15296 },
15297 },
15298 };
15299
15300 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15301 $config);
15302
15303 if (open(my $fh, ">> $setup->{config_file}")) {
15304 print $fh <<EOC;
15305 LogFormat custom "%m %{transfer-port}"
15306 ExtendedLog $ext_log ALL custom
15307 EOC
15308 unless (close($fh)) {
15309 die("Can't write $setup->{config_file}: $!");
15310 }
15311
15312 } else {
15313 die("Can't open $setup->{config_file}: $!");
15314 }
15315
15316 # Open pipes, for use between the parent and child processes. Specifically,
15317 # the child will indicate when it's done with its test by writing a message
15318 # to the parent.
15319 my ($rfh, $wfh);
15320 unless (pipe($rfh, $wfh)) {
15321 die("Can't open pipe: $!");
15322 }
15323
15324 my $ex;
15325
15326 # Fork child
15327 $self->handle_sigchld();
15328 defined(my $pid = fork()) or die("Can't fork: $!");
15329 if ($pid) {
15330 eval {
15331 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
15332 $client->login($setup->{user}, $setup->{passwd});
15333
15334 my $conn = $client->retr_raw('test.txt');
15335 unless ($conn) {
15336 die("RETR test.txt failed: " . $client->response_code() . " " .
15337 $client->response_code());
15338 }
15339
15340 my $buf;
15341 while ($conn->read($buf, 16382, 25)) {
15342 }
15343 eval { $conn->close() };
15344
15345 my $resp_code = $client->response_code();
15346 my $resp_msg = $client->response_msg();
15347
15348 $self->assert_transfer_ok($resp_code, $resp_msg);
15349 $client->quit();
15350
15351 # Now use an active transfer
15352 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
15353 $client->login($setup->{user}, $setup->{passwd});
15354
15355 $conn = $client->retr_raw('test.txt');
15356 unless ($conn) {
15357 die("RETR test.txt failed: " . $client->response_code() . " " .
15358 $client->response_code());
15359 }
15360
15361 $buf = '';
15362 while ($conn->read($buf, 16382, 25)) {
15363 }
15364 eval { $conn->close() };
15365
15366 $resp_code = $client->response_code();
15367 $resp_msg = $client->response_msg();
15368
15369 $self->assert_transfer_ok($resp_code, $resp_msg);
15370 $client->quit();
15371 };
15372 if ($@) {
15373 $ex = $@;
15374 }
15375
15376 $wfh->print("done\n");
15377 $wfh->flush();
15378
15379 } else {
15380 eval { server_wait($setup->{config_file}, $rfh) };
15381 if ($@) {
15382 warn($@);
15383 exit 1;
15384 }
15385
15386 exit 0;
15387 }
15388
15389 # Stop server
15390 server_stop($setup->{pid_file});
15391 $self->assert_child_ok($pid);
15392
15393 # Now, read in the ExtendedLog, and see whether the %{transfer-port}
15394 # variable was properly written out.
15395 eval {
15396 if (open(my $fh, "< $ext_log")) {
15397 my $expected_xfer_port = 0;
15398
15399 while (my $line = <$fh>) {
15400 chomp($line);
15401
15402 if ($ENV{TEST_VERBOSE}) {
15403 print STDERR "# $line\n";
15404 }
15405
15406 if ($line =~ /^(\S+) (.*)?$/) {
15407 my $cmd = $1;
15408 my $xfer_port = $2;
15409
15410 if ($cmd eq 'RETR') {
15411 if ($xfer_port =~ /\d+/) {
15412 $expected_xfer_port = 1;
15413
15414 } else {
15415 $expected_xfer_port = 0;
15416 }
15417 }
15418 }
15419 }
15420
15421 close($fh);
15422
15423 $self->assert($expected_xfer_port,
15424 test_msg("Did not see expected transfer port in ExtendedLog"));
15425
15426 } else {
15427 die("Can't read $ext_log: $!");
15428 }
15429 };
15430 if ($@) {
15431 $ex = $@;
15432 }
15433
15434 test_cleanup($setup->{log_file}, $ex);
15435 }
15436
15437 sub extlog_sftp_xfer_port_issue912 {
15438 my $self = shift;
15439 my $tmpdir = $self->{tmpdir};
15440 my $setup = test_setup($tmpdir, 'extlog');
15441
15442 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
15443 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
15444
15445 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15446 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
15447
15448 my $config = {
15449 PidFile => $setup->{pid_file},
15450 ScoreboardFile => $setup->{scoreboard_file},
15451 SystemLog => $setup->{log_file},
15452 TraceLog => $setup->{log_file},
15453 Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
15454
15455 AuthUserFile => $setup->{auth_user_file},
15456 AuthGroupFile => $setup->{auth_group_file},
15457 AuthOrder => 'mod_auth_file.c',
15458
15459 LogFormat => 'custom "%m %{transfer-port}"',
15460 ExtendedLog => "$ext_log ALL custom",
15461
15462 IfModules => {
15463 'mod_delay.c' => {
15464 DelayEngine => 'off',
15465 },
15466
15467 'mod_sftp.c' => [
15468 "SFTPEngine on",
15469 "SFTPLog $setup->{log_file}",
15470 "SFTPHostKey $rsa_host_key",
15471 "SFTPHostKey $dsa_host_key",
15472 ],
15473 },
15474 };
15475
15476 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15477 $config);
15478
15479 # Open pipes, for use between the parent and child processes. Specifically,
15480 # the child will indicate when it's done with its test by writing a message
15481 # to the parent.
15482 my ($rfh, $wfh);
15483 unless (pipe($rfh, $wfh)) {
15484 die("Can't open pipe: $!");
15485 }
15486
15487 require Net::SSH2;
15488
15489 my $ex;
15490
15491 # Ignore SIGPIPE
15492 local $SIG{PIPE} = sub { };
15493
15494 # Fork child
15495 $self->handle_sigchld();
15496 defined(my $pid = fork()) or die("Can't fork: $!");
15497 if ($pid) {
15498 eval {
15499 my $ssh2 = Net::SSH2->new();
15500
15501 sleep(2);
15502
15503 unless ($ssh2->connect('127.0.0.1', $port)) {
15504 my ($err_code, $err_name, $err_str) = $ssh2->error();
15505 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
15506 }
15507
15508 unless ($ssh2->auth_password($setup->{user}, $setup->{passwd})) {
15509 my ($err_code, $err_name, $err_str) = $ssh2->error();
15510 die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
15511 }
15512
15513 my $sftp = $ssh2->sftp();
15514 unless ($sftp) {
15515 my ($err_code, $err_name, $err_str) = $ssh2->error();
15516 die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
15517 }
15518
15519 my $fh = $sftp->open('test.txt', O_WRONLY|O_CREAT|O_TRUNC, 0644);
15520 unless ($fh) {
15521 my ($err_code, $err_name) = $sftp->error();
15522 die("Can't open test.txt: [$err_name] ($err_code)");
15523 }
15524
15525 print $fh "ABCD\n" x 8;
15526
15527 # To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
15528 $fh = undef;
15529
15530 # To issue the CHANNEL_CLOSE, we have to explicitly destroy the sftp
15531 # object. Sigh.
15532 $sftp = undef;
15533
15534 $ssh2->disconnect();
15535 };
15536 if ($@) {
15537 $ex = $@;
15538 }
15539
15540 $wfh->print("done\n");
15541 $wfh->flush();
15542
15543 } else {
15544 eval { server_wait($setup->{config_file}, $rfh) };
15545 if ($@) {
15546 warn($@);
15547 exit 1;
15548 }
15549
15550 exit 0;
15551 }
15552
15553 # Stop server
15554 server_stop($setup->{pid_file});
15555 $self->assert_child_ok($pid);
15556
15557 # Now, read in the ExtendedLog, and see whether the %{transfer-port} variable
15558 # was properly written out.
15559 eval {
15560 if (open(my $fh, "< $ext_log")) {
15561 my $expected_xfer_port = 0;
15562
15563 while (my $line = <$fh>) {
15564 chomp($line);
15565
15566 if ($ENV{TEST_VERBOSE}) {
15567 print STDERR "# $line\n";
15568 }
15569
15570 if ($line =~ /^(\S+) (.*)?$/) {
15571 my $cmd = $1;
15572 my $xfer_port = $2;
15573
15574 if ($cmd eq 'STOR') {
15575 if ($xfer_port == '-') {
15576 $expected_xfer_port = 1;
15577
15578 } else {
15579 $expected_xfer_port = 0;
15580 }
15581 }
15582 }
15583 }
15584
15585 close($fh);
15586
15587 $self->assert($expected_xfer_port,
15588 test_msg("Did not see expected transfer port in ExtendedLog"));
15589
15590 } else {
15591 die("Can't read $ext_log: $!");
15592 }
15593 };
15594 if ($@) {
15595 $ex = $@;
15596 }
15597
15598 test_cleanup($setup->{log_file}, $ex);
15599 }
15600
15601 sub extlog_xfer_speed_nonxfer_issue535 {
15602 my $self = shift;
15603 my $tmpdir = $self->{tmpdir};
15604 my $setup = test_setup($tmpdir, 'extlog');
15605
15606 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15607
15608 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
15609 if (open(my $fh, "> $test_file")) {
15610 print $fh "A" x 1024;
15611
15612 unless (close($fh)) {
15613 die("Can't write $test_file: $!");
15614 }
15615
15616 } else {
15617 die("Can't open $test_file: $!");
15618 }
15619
15620 my $config = {
15621 PidFile => $setup->{pid_file},
15622 ScoreboardFile => $setup->{scoreboard_file},
15623 SystemLog => $setup->{log_file},
15624
15625 AuthUserFile => $setup->{auth_user_file},
15626 AuthGroupFile => $setup->{auth_group_file},
15627 AuthOrder => 'mod_auth_file.c',
15628
15629 IfModules => {
15630 'mod_delay.c' => {
15631 DelayEngine => 'off',
15632 },
15633 },
15634 };
15635
15636 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15637 $config);
15638
15639 if (open(my $fh, ">> $setup->{config_file}")) {
15640 print $fh <<EOC;
15641 LogFormat custom "%m %{transfer-speed}"
15642 ExtendedLog $ext_log ALL custom
15643 EOC
15644 unless (close($fh)) {
15645 die("Can't write $setup->{config_file}: $!");
15646 }
15647
15648 } else {
15649 die("Can't open $setup->{config_file}: $!");
15650 }
15651
15652 # Open pipes, for use between the parent and child processes. Specifically,
15653 # the child will indicate when it's done with its test by writing a message
15654 # to the parent.
15655 my ($rfh, $wfh);
15656 unless (pipe($rfh, $wfh)) {
15657 die("Can't open pipe: $!");
15658 }
15659
15660 my $ex;
15661
15662 # Fork child
15663 $self->handle_sigchld();
15664 defined(my $pid = fork()) or die("Can't fork: $!");
15665 if ($pid) {
15666 eval {
15667 # Allow for server startup
15668 sleep(2);
15669
15670 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
15671 $client->login($setup->{user}, $setup->{passwd});
15672 $client->pwd();
15673 $client->quit();
15674 };
15675 if ($@) {
15676 $ex = $@;
15677 }
15678
15679 $wfh->print("done\n");
15680 $wfh->flush();
15681
15682 } else {
15683 eval { server_wait($setup->{config_file}, $rfh) };
15684 if ($@) {
15685 warn($@);
15686 exit 1;
15687 }
15688
15689 exit 0;
15690 }
15691
15692 # Stop server
15693 server_stop($setup->{pid_file});
15694 $self->assert_child_ok($pid);
15695
15696 # Now, read in the ExtendedLog, and see whether the %{transfer-speed}
15697 # variable was properly written out.
15698 eval {
15699 if (open(my $fh, "< $ext_log")) {
15700 my $unexpected_xfer_speed = 0;
15701
15702 while (my $line = <$fh>) {
15703 chomp($line);
15704
15705 if ($ENV{TEST_VERBOSE}) {
15706 print STDERR "# $line\n";
15707 }
15708
15709 if ($line =~ /^(\S+) (.*)?$/) {
15710 my $cmd = $1;
15711 my $xfer_speed = $2;
15712
15713 if ($xfer_speed ne '-') {
15714 $unexpected_xfer_speed = 1;
15715 last;
15716 }
15717 }
15718 }
15719
15720 close($fh);
15721
15722 $self->assert(!$unexpected_xfer_speed,
15723 test_msg("Saw unexpected transfer speed in ExtendedLog"));
15724
15725 } else {
15726 die("Can't read $ext_log: $!");
15727 }
15728 };
15729 if ($@) {
15730 $ex = $@;
15731 }
15732
15733 test_cleanup($setup->{log_file}, $ex);
15734 }
15735
15736 sub extlog_xfer_speed_download_issue535 {
15737 my $self = shift;
15738 my $tmpdir = $self->{tmpdir};
15739 my $setup = test_setup($tmpdir, 'extlog');
15740
15741 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15742
15743 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
15744 if (open(my $fh, "> $test_file")) {
15745 print $fh "A" x 1024;
15746
15747 unless (close($fh)) {
15748 die("Can't write $test_file: $!");
15749 }
15750
15751 } else {
15752 die("Can't open $test_file: $!");
15753 }
15754
15755 my $config = {
15756 PidFile => $setup->{pid_file},
15757 ScoreboardFile => $setup->{scoreboard_file},
15758 SystemLog => $setup->{log_file},
15759
15760 AuthUserFile => $setup->{auth_user_file},
15761 AuthGroupFile => $setup->{auth_group_file},
15762 AuthOrder => 'mod_auth_file.c',
15763
15764 IfModules => {
15765 'mod_delay.c' => {
15766 DelayEngine => 'off',
15767 },
15768 },
15769 };
15770
15771 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15772 $config);
15773
15774 if (open(my $fh, ">> $setup->{config_file}")) {
15775 print $fh <<EOC;
15776 LogFormat custom "%m %{transfer-speed}"
15777 ExtendedLog $ext_log ALL custom
15778 EOC
15779 unless (close($fh)) {
15780 die("Can't write $setup->{config_file}: $!");
15781 }
15782
15783 } else {
15784 die("Can't open $setup->{config_file}: $!");
15785 }
15786
15787 # Open pipes, for use between the parent and child processes. Specifically,
15788 # the child will indicate when it's done with its test by writing a message
15789 # to the parent.
15790 my ($rfh, $wfh);
15791 unless (pipe($rfh, $wfh)) {
15792 die("Can't open pipe: $!");
15793 }
15794
15795 my $ex;
15796
15797 # Fork child
15798 $self->handle_sigchld();
15799 defined(my $pid = fork()) or die("Can't fork: $!");
15800 if ($pid) {
15801 eval {
15802 # Allow for server startup
15803 sleep(2);
15804
15805 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
15806 $client->login($setup->{user}, $setup->{passwd});
15807
15808 my $conn = $client->retr_raw('test.txt');
15809 unless ($conn) {
15810 die("RETR test.txt failed: " . $client->response_code() . " " .
15811 $client->response_code());
15812 }
15813
15814 my $buf;
15815 while ($conn->read($buf, 16382, 25)) {
15816 }
15817 eval { $conn->close() };
15818
15819 my $resp_code = $client->response_code();
15820 my $resp_msg = $client->response_msg();
15821
15822 $self->assert_transfer_ok($resp_code, $resp_msg);
15823 $client->quit();
15824
15825 # Now use an active transfer
15826 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
15827 $client->login($setup->{user}, $setup->{passwd});
15828
15829 $conn = $client->retr_raw('test.txt');
15830 unless ($conn) {
15831 die("RETR test.txt failed: " . $client->response_code() . " " .
15832 $client->response_code());
15833 }
15834
15835 $buf = '';
15836 while ($conn->read($buf, 16382, 25)) {
15837 }
15838 eval { $conn->close() };
15839
15840 $resp_code = $client->response_code();
15841 $resp_msg = $client->response_msg();
15842
15843 $self->assert_transfer_ok($resp_code, $resp_msg);
15844 $client->quit();
15845 };
15846 if ($@) {
15847 $ex = $@;
15848 }
15849
15850 $wfh->print("done\n");
15851 $wfh->flush();
15852
15853 } else {
15854 eval { server_wait($setup->{config_file}, $rfh) };
15855 if ($@) {
15856 warn($@);
15857 exit 1;
15858 }
15859
15860 exit 0;
15861 }
15862
15863 # Stop server
15864 server_stop($setup->{pid_file});
15865 $self->assert_child_ok($pid);
15866
15867 # Now, read in the ExtendedLog, and see whether the %{transfer-speed}
15868 # variable was properly written out.
15869 eval {
15870 if (open(my $fh, "< $ext_log")) {
15871 my $expected_xfer_speed = 0;
15872
15873 while (my $line = <$fh>) {
15874 chomp($line);
15875
15876 if ($ENV{TEST_VERBOSE}) {
15877 print STDERR "# $line\n";
15878 }
15879
15880 if ($line =~ /^(\S+) (.*)?$/) {
15881 my $cmd = $1;
15882 my $xfer_speed = $2;
15883
15884 if ($cmd eq 'RETR') {
15885 if ($xfer_speed =~ /\d+KB\/s/) {
15886 $expected_xfer_speed = 1;
15887
15888 } else {
15889 $expected_xfer_speed = 0;
15890 }
15891 }
15892 }
15893 }
15894
15895 close($fh);
15896
15897 $self->assert($expected_xfer_speed,
15898 test_msg("Did not see expected transfer speed in ExtendedLog"));
15899
15900 } else {
15901 die("Can't read $ext_log: $!");
15902 }
15903 };
15904 if ($@) {
15905 $ex = $@;
15906 }
15907
15908 test_cleanup($setup->{log_file}, $ex);
15909 }
15910
15911 sub extlog_xfer_speed_download_zero_len_issue535 {
15912 my $self = shift;
15913 my $tmpdir = $self->{tmpdir};
15914 my $setup = test_setup($tmpdir, 'extlog');
15915
15916 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
15917
15918 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
15919 if (open(my $fh, "> $test_file")) {
15920 unless (close($fh)) {
15921 die("Can't write $test_file: $!");
15922 }
15923
15924 } else {
15925 die("Can't open $test_file: $!");
15926 }
15927
15928 my $config = {
15929 PidFile => $setup->{pid_file},
15930 ScoreboardFile => $setup->{scoreboard_file},
15931 SystemLog => $setup->{log_file},
15932
15933 AuthUserFile => $setup->{auth_user_file},
15934 AuthGroupFile => $setup->{auth_group_file},
15935 AuthOrder => 'mod_auth_file.c',
15936
15937 IfModules => {
15938 'mod_delay.c' => {
15939 DelayEngine => 'off',
15940 },
15941 },
15942 };
15943
15944 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15945 $config);
15946
15947 if (open(my $fh, ">> $setup->{config_file}")) {
15948 print $fh <<EOC;
15949 LogFormat custom "%m %{transfer-speed}"
15950 ExtendedLog $ext_log ALL custom
15951 EOC
15952 unless (close($fh)) {
15953 die("Can't write $setup->{config_file}: $!");
15954 }
15955
15956 } else {
15957 die("Can't open $setup->{config_file}: $!");
15958 }
15959
15960 # Open pipes, for use between the parent and child processes. Specifically,
15961 # the child will indicate when it's done with its test by writing a message
15962 # to the parent.
15963 my ($rfh, $wfh);
15964 unless (pipe($rfh, $wfh)) {
15965 die("Can't open pipe: $!");
15966 }
15967
15968 my $ex;
15969
15970 # Fork child
15971 $self->handle_sigchld();
15972 defined(my $pid = fork()) or die("Can't fork: $!");
15973 if ($pid) {
15974 eval {
15975 # Allow for server startup
15976 sleep(2);
15977
15978 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
15979 $client->login($setup->{user}, $setup->{passwd});
15980
15981 my $conn = $client->retr_raw('test.txt');
15982 unless ($conn) {
15983 die("RETR test.txt failed: " . $client->response_code() . " " .
15984 $client->response_code());
15985 }
15986
15987 my $buf;
15988 while ($conn->read($buf, 16382, 25)) {
15989 }
15990 eval { $conn->close() };
15991
15992 my $resp_code = $client->response_code();
15993 my $resp_msg = $client->response_msg();
15994
15995 $self->assert_transfer_ok($resp_code, $resp_msg);
15996 $client->quit();
15997
15998 # Now use an active transfer
15999 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
16000 $client->login($setup->{user}, $setup->{passwd});
16001
16002 $conn = $client->retr_raw('test.txt');
16003 unless ($conn) {
16004 die("RETR test.txt failed: " . $client->response_code() . " " .
16005 $client->response_code());
16006 }
16007
16008 $buf = '';
16009 while ($conn->read($buf, 16382, 25)) {
16010 }
16011 eval { $conn->close() };
16012
16013 $resp_code = $client->response_code();
16014 $resp_msg = $client->response_msg();
16015
16016 $self->assert_transfer_ok($resp_code, $resp_msg);
16017 $client->quit();
16018 };
16019 if ($@) {
16020 $ex = $@;
16021 }
16022
16023 $wfh->print("done\n");
16024 $wfh->flush();
16025
16026 } else {
16027 eval { server_wait($setup->{config_file}, $rfh) };
16028 if ($@) {
16029 warn($@);
16030 exit 1;
16031 }
16032
16033 exit 0;
16034 }
16035
16036 # Stop server
16037 server_stop($setup->{pid_file});
16038 $self->assert_child_ok($pid);
16039
16040 # Now, read in the ExtendedLog, and see whether the %{transfer-speed}
16041 # variable was properly written out.
16042 eval {
16043 if (open(my $fh, "< $ext_log")) {
16044 my $expected_xfer_speed = 0;
16045
16046 while (my $line = <$fh>) {
16047 chomp($line);
16048
16049 if ($ENV{TEST_VERBOSE}) {
16050 print STDERR "# $line\n";
16051 }
16052
16053 if ($line =~ /^(\S+) (.*)?$/) {
16054 my $cmd = $1;
16055 my $xfer_speed = $2;
16056
16057 if ($cmd eq 'RETR') {
16058 if ($xfer_speed =~ /\d+KB\/s/) {
16059 $expected_xfer_speed = 1;
16060
16061 } else {
16062 $expected_xfer_speed = 0;
16063 }
16064 }
16065 }
16066 }
16067
16068 close($fh);
16069
16070 $self->assert($expected_xfer_speed,
16071 test_msg("Did not see expected transfer speed in ExtendedLog"));
16072
16073 } else {
16074 die("Can't read $ext_log: $!");
16075 }
16076 };
16077 if ($@) {
16078 $ex = $@;
16079 }
16080
16081 test_cleanup($setup->{log_file}, $ex);
16082 }
16083
16084 sub extlog_xfer_speed_upload_issue535 {
16085 my $self = shift;
16086 my $tmpdir = $self->{tmpdir};
16087 my $setup = test_setup($tmpdir, 'extlog');
16088
16089 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
16090
16091 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
16092
16093 my $config = {
16094 PidFile => $setup->{pid_file},
16095 ScoreboardFile => $setup->{scoreboard_file},
16096 SystemLog => $setup->{log_file},
16097
16098 AuthUserFile => $setup->{auth_user_file},
16099 AuthGroupFile => $setup->{auth_group_file},
16100 AuthOrder => 'mod_auth_file.c',
16101
16102 AllowOverwrite => 'on',
16103
16104 IfModules => {
16105 'mod_delay.c' => {
16106 DelayEngine => 'off',
16107 },
16108 },
16109 };
16110
16111 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
16112 $config);
16113
16114 if (open(my $fh, ">> $setup->{config_file}")) {
16115 print $fh <<EOC;
16116 LogFormat custom "%m %{transfer-speed}"
16117 ExtendedLog $ext_log ALL custom
16118 EOC
16119 unless (close($fh)) {
16120 die("Can't write $setup->{config_file}: $!");
16121 }
16122
16123 } else {
16124 die("Can't open $setup->{config_file}: $!");
16125 }
16126
16127 # Open pipes, for use between the parent and child processes. Specifically,
16128 # the child will indicate when it's done with its test by writing a message
16129 # to the parent.
16130 my ($rfh, $wfh);
16131 unless (pipe($rfh, $wfh)) {
16132 die("Can't open pipe: $!");
16133 }
16134
16135 my $ex;
16136
16137 # Fork child
16138 $self->handle_sigchld();
16139 defined(my $pid = fork()) or die("Can't fork: $!");
16140 if ($pid) {
16141 eval {
16142 # Allow for server startup
16143 sleep(2);
16144
16145 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
16146 $client->login($setup->{user}, $setup->{passwd});
16147
16148 my $conn = $client->stor_raw('test.txt');
16149 unless ($conn) {
16150 die("STOR test.txt failed: " . $client->response_code() . " " .
16151 $client->response_code());
16152 }
16153
16154 my $buf = 'A' x 1024;
16155 $conn->write($buf, length($buf), 25);
16156 eval { $conn->close() };
16157
16158 my $resp_code = $client->response_code();
16159 my $resp_msg = $client->response_msg();
16160
16161 $self->assert_transfer_ok($resp_code, $resp_msg);
16162 $client->quit();
16163
16164 # Now use an active transfer
16165 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
16166 $client->login($setup->{user}, $setup->{passwd});
16167
16168 $conn = $client->stor_raw('test.txt');
16169 unless ($conn) {
16170 die("STOR test.txt failed: " . $client->response_code() . " " .
16171 $client->response_code());
16172 }
16173
16174 $buf = 'B' x 1024;
16175 $conn->write($buf, length($buf), 25);
16176
16177 # Now we deliberately delay the close, to see the different transfer
16178 # speed logged.
16179 sleep(2);
16180 eval { $conn->close() };
16181
16182 $resp_code = $client->response_code();
16183 $resp_msg = $client->response_msg();
16184
16185 $self->assert_transfer_ok($resp_code, $resp_msg);
16186 $client->quit();
16187 };
16188 if ($@) {
16189 $ex = $@;
16190 }
16191
16192 $wfh->print("done\n");
16193 $wfh->flush();
16194
16195 } else {
16196 eval { server_wait($setup->{config_file}, $rfh) };
16197 if ($@) {
16198 warn($@);
16199 exit 1;
16200 }
16201
16202 exit 0;
16203 }
16204
16205 # Stop server
16206 server_stop($setup->{pid_file});
16207 $self->assert_child_ok($pid);
16208
16209 # Now, read in the ExtendedLog, and see whether the %{transfer-speed}
16210 # variable was properly written out.
16211 eval {
16212 if (open(my $fh, "< $ext_log")) {
16213 my $expected_xfer_speed = 0;
16214
16215 while (my $line = <$fh>) {
16216 chomp($line);
16217
16218 if ($ENV{TEST_VERBOSE}) {
16219 print STDERR "# $line\n";
16220 }
16221
16222 if ($line =~ /^(\S+) (.*)?$/) {
16223 my $cmd = $1;
16224 my $xfer_speed = $2;
16225
16226 if ($cmd eq 'STOR') {
16227 if ($xfer_speed =~ /\d+KB\/s/) {
16228 $expected_xfer_speed = 1;
16229
16230 } else {
16231 $expected_xfer_speed = 0;
16232 }
16233 }
16234 }
16235 }
16236
16237 close($fh);
16238
16239 $self->assert($expected_xfer_speed,
16240 test_msg("Did not see expected transfer speed in ExtendedLog"));
16241
16242 } else {
16243 die("Can't read $ext_log: $!");
16244 }
16245 };
16246 if ($@) {
16247 $ex = $@;
16248 }
16249
16250 test_cleanup($setup->{log_file}, $ex);
16251 }
16252
16253 sub extlog_xfer_speed_upload_zero_len_issue535 {
16254 my $self = shift;
16255 my $tmpdir = $self->{tmpdir};
16256 my $setup = test_setup($tmpdir, 'extlog');
16257
16258 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
16259
16260 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
16261
16262 my $config = {
16263 PidFile => $setup->{pid_file},
16264 ScoreboardFile => $setup->{scoreboard_file},
16265 SystemLog => $setup->{log_file},
16266
16267 AuthUserFile => $setup->{auth_user_file},
16268 AuthGroupFile => $setup->{auth_group_file},
16269 AuthOrder => 'mod_auth_file.c',
16270
16271 AllowOverwrite => 'on',
16272
16273 IfModules => {
16274 'mod_delay.c' => {
16275 DelayEngine => 'off',
16276 },
16277 },
16278 };
16279
16280 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
16281 $config);
16282
16283 if (open(my $fh, ">> $setup->{config_file}")) {
16284 print $fh <<EOC;
16285 LogFormat custom "%m %{transfer-speed}"
16286 ExtendedLog $ext_log ALL custom
16287 EOC
16288 unless (close($fh)) {
16289 die("Can't write $setup->{config_file}: $!");
16290 }
16291
16292 } else {
16293 die("Can't open $setup->{config_file}: $!");
16294 }
16295
16296 # Open pipes, for use between the parent and child processes. Specifically,
16297 # the child will indicate when it's done with its test by writing a message
16298 # to the parent.
16299 my ($rfh, $wfh);
16300 unless (pipe($rfh, $wfh)) {
16301 die("Can't open pipe: $!");
16302 }
16303
16304 my $ex;
16305
16306 # Fork child
16307 $self->handle_sigchld();
16308 defined(my $pid = fork()) or die("Can't fork: $!");
16309 if ($pid) {
16310 eval {
16311 # Allow for server startup
16312 sleep(2);
16313
16314 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
16315 $client->login($setup->{user}, $setup->{passwd});
16316
16317 my $conn = $client->stor_raw('test.txt');
16318 unless ($conn) {
16319 die("STOR test.txt failed: " . $client->response_code() . " " .
16320 $client->response_code());
16321 }
16322
16323 # Close the data connection without writing anything.
16324 eval { $conn->close(5) };
16325
16326 my $resp_code = $client->response_code();
16327 my $resp_msg = $client->response_msg();
16328
16329 $self->assert_transfer_ok($resp_code, $resp_msg);
16330 $client->quit();
16331
16332 # Now use an active transfer
16333 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, 1);
16334 $client->login($setup->{user}, $setup->{passwd});
16335
16336 $conn = $client->stor_raw('test.txt');
16337 unless ($conn) {
16338 die("STOR test.txt failed: " . $client->response_code() . " " .
16339 $client->response_code());
16340 }
16341
16342 # Now we deliberately delay the close, to see the different transfer
16343 # speed logged.
16344 sleep(2);
16345
16346 eval { $conn->close(5) };
16347
16348 $resp_code = $client->response_code();
16349 $resp_msg = $client->response_msg();
16350
16351 $self->assert_transfer_ok($resp_code, $resp_msg);
16352 $client->quit();
16353 };
16354 if ($@) {
16355 $ex = $@;
16356 }
16357
16358 $wfh->print("done\n");
16359 $wfh->flush();
16360
16361 } else {
16362 eval { server_wait($setup->{config_file}, $rfh) };
16363 if ($@) {
16364 warn($@);
16365 exit 1;
16366 }
16367
16368 exit 0;
16369 }
16370
16371 # Stop server
16372 server_stop($setup->{pid_file});
16373 $self->assert_child_ok($pid);
16374
16375 # Now, read in the ExtendedLog, and see whether the %{transfer-speed}
16376 # variable was properly written out.
16377 eval {
16378 if (open(my $fh, "< $ext_log")) {
16379 my $expected_xfer_speed = 0;
16380
16381 while (my $line = <$fh>) {
16382 chomp($line);
16383
16384 if ($ENV{TEST_VERBOSE}) {
16385 print STDERR "# $line\n";
16386 }
16387
16388 if ($line =~ /^(\S+) (.*)?$/) {
16389 my $cmd = $1;
16390 my $xfer_speed = $2;
16391
16392 if ($cmd eq 'STOR') {
16393 if ($xfer_speed =~ /\d+KB\/s/) {
16394 $expected_xfer_speed = 1;
16395
16396 } else {
16397 $expected_xfer_speed = 0;
16398 }
16399 }
16400 }
16401 }
16402
16403 close($fh);
16404
16405 $self->assert($expected_xfer_speed,
16406 test_msg("Did not see expected transfer speed in ExtendedLog"));
16407
16408 } else {
16409 die("Can't read $ext_log: $!");
16410 }
16411 };
16412 if ($@) {
16413 $ex = $@;
16414 }
16415
16416 test_cleanup($setup->{log_file}, $ex);
16417 }
16418
16419 1;