5769
5779
unlink($log_file);
5782
sub extlog_xfer_timeout_bug3696 {
5784
my $tmpdir = $self->{tmpdir};
5786
my $config_file = "$tmpdir/extlog.conf";
5787
my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5788
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5790
my $log_file = File::Spec->rel2abs('tests.log');
5792
my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5793
my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5795
my $test_file = File::Spec->rel2abs("$tmpdir/foo.txt");
5797
my $user = 'proftpd';
5798
my $passwd = 'test';
5800
my $home_dir = File::Spec->rel2abs($tmpdir);
5804
# Make sure that, if we're running as root, that the home directory has
5805
# permissions/privs set for the account we create
5807
unless (chmod(0755, $home_dir)) {
5808
die("Can't set perms on $home_dir to 0755: $!");
5811
unless (chown($uid, $gid, $home_dir)) {
5812
die("Can't set owner of $home_dir to $uid/$gid: $!");
5816
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5818
auth_group_write($auth_group_file, $group, $gid, $user);
5820
my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5822
my $timeout_stalled = 2;
5825
PidFile => $pid_file,
5826
ScoreboardFile => $scoreboard_file,
5827
SystemLog => $log_file,
5829
AuthUserFile => $auth_user_file,
5830
AuthGroupFile => $auth_group_file,
5832
LogFormat => 'custom "%f"',
5833
ExtendedLog => "$ext_log WRITE custom",
5835
TimeoutStalled => $timeout_stalled,
5839
DelayEngine => 'off',
5844
my ($port, $config_user, $config_group) = config_write($config_file, $config);
5846
# Open pipes, for use between the parent and child processes. Specifically,
5847
# the child will indicate when it's done with its test by writing a message
5850
unless (pipe($rfh, $wfh)) {
5851
die("Can't open pipe: $!");
5857
$self->handle_sigchld();
5858
defined(my $pid = fork()) or die("Can't fork: $!");
5861
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
5862
$client->login($user, $passwd);
5864
my $conn = $client->stor_raw('foo.txt');
5866
die("Failed to STOR foo.txt: " . $client->response_code() . " " .
5867
$client->response_msg());
5870
# Wait for longer than the TimeoutStalled limit
5871
sleep($timeout_stalled + 2);
5875
$conn->write($buf, length($buf));
5876
eval { $conn->close() };
5886
$wfh->print("done\n");
5890
eval { server_wait($config_file, $rfh) };
5900
server_stop($pid_file);
5902
$self->assert_child_ok($pid);
5904
# Now, read in the ExtendedLog, and see whether the %f variable was
5905
# properly written out. Bug#3696 occurred because mod_log would not
5906
# properly notice that a data transfer was in progress when the
5907
# session was disconnected due to hitting TimeoutStalled.
5909
if (open(my $fh, "< $ext_log")) {
5914
$self->assert($test_file eq $line,
5915
test_msg("Expected '$test_file', got '$line'"));
5918
die("Can't read $ext_log: $!");
5928
sub extlog_sftp_xfer_timeout_bug3696 {
5930
my $tmpdir = $self->{tmpdir};
5932
my $config_file = "$tmpdir/extlog.conf";
5933
my $pid_file = File::Spec->rel2abs("$tmpdir/extlog.pid");
5934
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/extlog.scoreboard");
5936
my $log_file = File::Spec->rel2abs('tests.log');
5938
my $auth_user_file = File::Spec->rel2abs("$tmpdir/extlog.passwd");
5939
my $auth_group_file = File::Spec->rel2abs("$tmpdir/extlog.group");
5941
my $user = 'proftpd';
5942
my $passwd = 'test';
5944
my $home_dir = File::Spec->rel2abs($tmpdir);
5948
# Make sure that, if we're running as root, that the home directory has
5949
# permissions/privs set for the account we create
5951
unless (chmod(0755, $home_dir)) {
5952
die("Can't set perms on $home_dir to 0755: $!");
5955
unless (chown($uid, $gid, $home_dir)) {
5956
die("Can't set owner of $home_dir to $uid/$gid: $!");
5960
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5962
auth_group_write($auth_group_file, $group, $gid, $user);
5964
my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
5965
my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
5967
my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5969
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
5970
my $timeout_stalled = 2;
5973
PidFile => $pid_file,
5974
ScoreboardFile => $scoreboard_file,
5975
SystemLog => $log_file,
5976
TraceLog => $log_file,
5977
Trace => 'DEFAULT:10 ssh2:20 sftp:20 scp:20',
5979
AuthUserFile => $auth_user_file,
5980
AuthGroupFile => $auth_group_file,
5982
LogFormat => 'custom "%f"',
5983
ExtendedLog => "$ext_log WRITE custom",
5985
TimeoutStalled => $timeout_stalled,
5989
DelayEngine => 'off',
5994
"SFTPLog $log_file",
5995
"SFTPHostKey $rsa_host_key",
5996
"SFTPHostKey $dsa_host_key",
6001
my ($port, $config_user, $config_group) = config_write($config_file, $config);
6003
# Open pipes, for use between the parent and child processes. Specifically,
6004
# the child will indicate when it's done with its test by writing a message
6007
unless (pipe($rfh, $wfh)) {
6008
die("Can't open pipe: $!");
6016
local $SIG{PIPE} = sub { };
6019
$self->handle_sigchld();
6020
defined(my $pid = fork()) or die("Can't fork: $!");
6023
my $ssh2 = Net::SSH2->new();
6027
unless ($ssh2->connect('127.0.0.1', $port)) {
6028
my ($err_code, $err_name, $err_str) = $ssh2->error();
6029
die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
6032
unless ($ssh2->auth_password($user, $passwd)) {
6033
my ($err_code, $err_name, $err_str) = $ssh2->error();
6034
die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str");
6037
my $sftp = $ssh2->sftp();
6039
my ($err_code, $err_name, $err_str) = $ssh2->error();
6040
die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str");
6043
my $fh = $sftp->open('test.txt', O_WRONLY|O_CREAT|O_TRUNC, 0644);
6045
my ($err_code, $err_name) = $sftp->error();
6046
die("Can't open test.txt: [$err_name] ($err_code)");
6049
print $fh "ABCD\n" x 8;
6051
# Wait for longer than the TimeoutStalled limit
6052
sleep($timeout_stalled + 2);
6054
# To issue the FXP_CLOSE, we have to explicitly destroy the filehandle
6057
# To issue the CHANNEL_CLOSE, we have to explicitly destroy the sftp
6061
$ssh2->disconnect();
6068
$wfh->print("done\n");
6072
eval { server_wait($config_file, $rfh) };
6082
server_stop($pid_file);
6084
$self->assert_child_ok($pid);
6090
# Now, read in the ExtendedLog, and see whether the %f variable was
6091
# properly written out. Bug#3696 occurred because mod_log would not
6092
# properly notice that a data transfer was in progress when the
6093
# session was disconnected due to hitting TimeoutStalled.
6095
if (open(my $fh, "< $ext_log")) {
6100
$self->assert($test_file eq $line,
6101
test_msg("Expected '$test_file', got '$line'"));
6104
die("Can't read $ext_log: $!");