| 1 |
package ProFTPD::Tests::Config::DeleteAbortedStores; |
| 2 |
|
| 3 |
use lib qw(t/lib); |
| 4 |
use base qw(ProFTPD::TestSuite::Child); |
| 5 |
use strict; |
| 6 |
|
| 7 |
use File::Spec; |
| 8 |
use IO::Handle; |
| 9 |
|
| 10 |
use ProFTPD::TestSuite::FTP; |
| 11 |
use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite); |
| 12 |
|
| 13 |
$| = 1; |
| 14 |
|
| 15 |
my $order = 0; |
| 16 |
|
| 17 |
my $TESTS = { |
| 18 |
deleteabortedstores_conn_aborted_ok => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
deleteabortedstores_cmd_abort_ok => { |
| 24 |
order => ++$order, |
| 25 |
test_class => [qw(forking)], |
| 26 |
}, |
| 27 |
|
| 28 |
deleteabortedstores_conn_aborted_bug3917 => { |
| 29 |
order => ++$order, |
| 30 |
test_class => [qw(bug forking)], |
| 31 |
}, |
| 32 |
|
| 33 |
deleteabortedstores_hiddenstores_on_timeout_idle_bug4035 => { |
| 34 |
order => ++$order, |
| 35 |
test_class => [qw(bug forking)], |
| 36 |
}, |
| 37 |
|
| 38 |
deleteabortedstores_hiddenstores_on_timeout_stalled_bug4035 => { |
| 39 |
order => ++$order, |
| 40 |
test_class => [qw(bug forking)], |
| 41 |
}, |
| 42 |
|
| 43 |
deleteabortedstores_hiddenstores_on_xfer_aborted_bug4467 => { |
| 44 |
order => ++$order, |
| 45 |
test_class => [qw(bug forking)], |
| 46 |
}, |
| 47 |
|
| 48 |
}; |
| 49 |
|
| 50 |
sub new { |
| 51 |
return shift()->SUPER::new(@_); |
| 52 |
} |
| 53 |
|
| 54 |
sub list_tests { |
| 55 |
return testsuite_get_runnable_tests($TESTS); |
| 56 |
} |
| 57 |
|
| 58 |
sub deleteabortedstores_conn_aborted_ok { |
| 59 |
my $self = shift; |
| 60 |
my $tmpdir = $self->{tmpdir}; |
| 61 |
|
| 62 |
my $config_file = "$tmpdir/config.conf"; |
| 63 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 64 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 65 |
|
| 66 |
my $log_file = test_get_logfile(); |
| 67 |
|
| 68 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 69 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 70 |
|
| 71 |
my $user = 'proftpd'; |
| 72 |
my $passwd = 'test'; |
| 73 |
my $group = 'ftpd'; |
| 74 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 75 |
my $uid = 500; |
| 76 |
my $gid = 500; |
| 77 |
|
| 78 |
# Make sure that, if we're running as root, that the home directory has |
| 79 |
# permissions/privs set for the account we create |
| 80 |
if ($< == 0) { |
| 81 |
unless (chmod(0755, $home_dir)) { |
| 82 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 83 |
} |
| 84 |
|
| 85 |
unless (chown($uid, $gid, $home_dir)) { |
| 86 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 91 |
'/bin/bash'); |
| 92 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 93 |
|
| 94 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 95 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 96 |
|
| 97 |
my $config = { |
| 98 |
PidFile => $pid_file, |
| 99 |
ScoreboardFile => $scoreboard_file, |
| 100 |
SystemLog => $log_file, |
| 101 |
|
| 102 |
AuthUserFile => $auth_user_file, |
| 103 |
AuthGroupFile => $auth_group_file, |
| 104 |
AuthOrder => 'mod_auth_file.c', |
| 105 |
|
| 106 |
DefaultChdir => '~', |
| 107 |
HiddenStores => 'on', |
| 108 |
DeleteAbortedStores => 'on', |
| 109 |
|
| 110 |
IfModules => { |
| 111 |
'mod_delay.c' => { |
| 112 |
DelayEngine => 'off', |
| 113 |
}, |
| 114 |
}, |
| 115 |
}; |
| 116 |
|
| 117 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 118 |
|
| 119 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 120 |
# the child will indicate when it's done with its test by writing a message |
| 121 |
# to the parent. |
| 122 |
my ($rfh, $wfh); |
| 123 |
unless (pipe($rfh, $wfh)) { |
| 124 |
die("Can't open pipe: $!"); |
| 125 |
} |
| 126 |
|
| 127 |
my $ex; |
| 128 |
|
| 129 |
# Fork child |
| 130 |
$self->handle_sigchld(); |
| 131 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 132 |
if ($pid) { |
| 133 |
eval { |
| 134 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 135 |
$client->login($user, $passwd); |
| 136 |
|
| 137 |
my $conn = $client->stor_raw('test.txt'); |
| 138 |
unless ($conn) { |
| 139 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 140 |
$client->response_msg()); |
| 141 |
} |
| 142 |
|
| 143 |
my $buf = "Hello, World!\n"; |
| 144 |
$conn->write($buf, length($buf), 25); |
| 145 |
|
| 146 |
unless (-f $hidden_file) { |
| 147 |
die("File $hidden_file does not exist as expected"); |
| 148 |
} |
| 149 |
|
| 150 |
eval { $conn->abort() }; |
| 151 |
|
| 152 |
my $resp_code = $client->response_code(); |
| 153 |
my $resp_msg = $client->response_msg(); |
| 154 |
$self->assert_transfer_ok($resp_code, $resp_msg, 1); |
| 155 |
|
| 156 |
$client->quit(); |
| 157 |
|
| 158 |
if (-f $test_file) { |
| 159 |
die("File $test_file exists unexpectedly"); |
| 160 |
} |
| 161 |
|
| 162 |
if (-f $hidden_file) { |
| 163 |
die("File $hidden_file exists unexpectedly"); |
| 164 |
} |
| 165 |
}; |
| 166 |
|
| 167 |
if ($@) { |
| 168 |
$ex = $@; |
| 169 |
} |
| 170 |
|
| 171 |
$wfh->print("done\n"); |
| 172 |
$wfh->flush(); |
| 173 |
|
| 174 |
} else { |
| 175 |
eval { server_wait($config_file, $rfh) }; |
| 176 |
if ($@) { |
| 177 |
warn($@); |
| 178 |
exit 1; |
| 179 |
} |
| 180 |
|
| 181 |
exit 0; |
| 182 |
} |
| 183 |
|
| 184 |
# Stop server |
| 185 |
server_stop($pid_file); |
| 186 |
|
| 187 |
$self->assert_child_ok($pid); |
| 188 |
|
| 189 |
if ($ex) { |
| 190 |
test_append_logfile($log_file, $ex); |
| 191 |
unlink($log_file); |
| 192 |
|
| 193 |
die($ex); |
| 194 |
} |
| 195 |
|
| 196 |
unlink($log_file); |
| 197 |
} |
| 198 |
|
| 199 |
sub deleteabortedstores_cmd_abort_ok { |
| 200 |
my $self = shift; |
| 201 |
my $tmpdir = $self->{tmpdir}; |
| 202 |
|
| 203 |
my $config_file = "$tmpdir/config.conf"; |
| 204 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 205 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 206 |
|
| 207 |
my $log_file = test_get_logfile(); |
| 208 |
|
| 209 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 210 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 211 |
|
| 212 |
my $user = 'proftpd'; |
| 213 |
my $passwd = 'test'; |
| 214 |
my $group = 'ftpd'; |
| 215 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 216 |
my $uid = 500; |
| 217 |
my $gid = 500; |
| 218 |
|
| 219 |
# Make sure that, if we're running as root, that the home directory has |
| 220 |
# permissions/privs set for the account we create |
| 221 |
if ($< == 0) { |
| 222 |
unless (chmod(0755, $home_dir)) { |
| 223 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 224 |
} |
| 225 |
|
| 226 |
unless (chown($uid, $gid, $home_dir)) { |
| 227 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 232 |
'/bin/bash'); |
| 233 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 234 |
|
| 235 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 236 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 237 |
|
| 238 |
my $config = { |
| 239 |
PidFile => $pid_file, |
| 240 |
ScoreboardFile => $scoreboard_file, |
| 241 |
SystemLog => $log_file, |
| 242 |
TraceLog => $log_file, |
| 243 |
Trace => 'DEFAULT:10', |
| 244 |
|
| 245 |
AuthUserFile => $auth_user_file, |
| 246 |
AuthGroupFile => $auth_group_file, |
| 247 |
AuthOrder => 'mod_auth_file.c', |
| 248 |
|
| 249 |
DefaultChdir => '~', |
| 250 |
HiddenStores => 'on', |
| 251 |
DeleteAbortedStores => 'on', |
| 252 |
TimeoutLinger => 1, |
| 253 |
|
| 254 |
IfModules => { |
| 255 |
'mod_delay.c' => { |
| 256 |
DelayEngine => 'off', |
| 257 |
}, |
| 258 |
}, |
| 259 |
}; |
| 260 |
|
| 261 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 262 |
|
| 263 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 264 |
# the child will indicate when it's done with its test by writing a message |
| 265 |
# to the parent. |
| 266 |
my ($rfh, $wfh); |
| 267 |
unless (pipe($rfh, $wfh)) { |
| 268 |
die("Can't open pipe: $!"); |
| 269 |
} |
| 270 |
|
| 271 |
my $ex; |
| 272 |
|
| 273 |
# Fork child |
| 274 |
$self->handle_sigchld(); |
| 275 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 276 |
if ($pid) { |
| 277 |
eval { |
| 278 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 279 |
$client->login($user, $passwd); |
| 280 |
|
| 281 |
my $conn = $client->stor_raw('test.txt'); |
| 282 |
unless ($conn) { |
| 283 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 284 |
$client->response_msg()); |
| 285 |
} |
| 286 |
|
| 287 |
my $buf = "Hello, World!\n"; |
| 288 |
$conn->write($buf, length($buf), 25); |
| 289 |
|
| 290 |
unless (-f $hidden_file) { |
| 291 |
die("File $hidden_file does not exist as expected"); |
| 292 |
} |
| 293 |
|
| 294 |
eval { $client->quote('ABOR') }; |
| 295 |
|
| 296 |
my $resp_code = $client->response_code(); |
| 297 |
my $resp_msg = $client->response_msg(); |
| 298 |
$self->assert_transfer_ok($resp_code, $resp_msg, 1); |
| 299 |
|
| 300 |
eval { $conn->close() }; |
| 301 |
|
| 302 |
$client->quit(); |
| 303 |
|
| 304 |
if (-f $test_file) { |
| 305 |
die("File $test_file exists unexpectedly"); |
| 306 |
} |
| 307 |
|
| 308 |
if (-f $hidden_file) { |
| 309 |
die("File $hidden_file exists unexpectedly"); |
| 310 |
} |
| 311 |
}; |
| 312 |
|
| 313 |
if ($@) { |
| 314 |
$ex = $@; |
| 315 |
} |
| 316 |
|
| 317 |
$wfh->print("done\n"); |
| 318 |
$wfh->flush(); |
| 319 |
|
| 320 |
} else { |
| 321 |
eval { server_wait($config_file, $rfh) }; |
| 322 |
if ($@) { |
| 323 |
warn($@); |
| 324 |
exit 1; |
| 325 |
} |
| 326 |
|
| 327 |
exit 0; |
| 328 |
} |
| 329 |
|
| 330 |
# Stop server |
| 331 |
server_stop($pid_file); |
| 332 |
|
| 333 |
$self->assert_child_ok($pid); |
| 334 |
|
| 335 |
if ($ex) { |
| 336 |
test_append_logfile($log_file, $ex); |
| 337 |
unlink($log_file); |
| 338 |
|
| 339 |
die($ex); |
| 340 |
} |
| 341 |
|
| 342 |
unlink($log_file); |
| 343 |
} |
| 344 |
|
| 345 |
sub deleteabortedstores_conn_aborted_bug3917 { |
| 346 |
my $self = shift; |
| 347 |
my $tmpdir = $self->{tmpdir}; |
| 348 |
|
| 349 |
my $config_file = "$tmpdir/config.conf"; |
| 350 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 351 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 352 |
|
| 353 |
my $log_file = test_get_logfile(); |
| 354 |
|
| 355 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 356 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 357 |
|
| 358 |
my $user = 'proftpd'; |
| 359 |
my $passwd = 'test'; |
| 360 |
my $group = 'ftpd'; |
| 361 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 362 |
my $uid = 500; |
| 363 |
my $gid = 500; |
| 364 |
|
| 365 |
# Make sure that, if we're running as root, that the home directory has |
| 366 |
# permissions/privs set for the account we create |
| 367 |
if ($< == 0) { |
| 368 |
unless (chmod(0755, $home_dir)) { |
| 369 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 370 |
} |
| 371 |
|
| 372 |
unless (chown($uid, $gid, $home_dir)) { |
| 373 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 378 |
'/bin/bash'); |
| 379 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 380 |
|
| 381 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 382 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 383 |
|
| 384 |
my $config = { |
| 385 |
PidFile => $pid_file, |
| 386 |
ScoreboardFile => $scoreboard_file, |
| 387 |
SystemLog => $log_file, |
| 388 |
|
| 389 |
AuthUserFile => $auth_user_file, |
| 390 |
AuthGroupFile => $auth_group_file, |
| 391 |
AuthOrder => 'mod_auth_file.c', |
| 392 |
|
| 393 |
DefaultChdir => '~', |
| 394 |
HiddenStores => 'on', |
| 395 |
|
| 396 |
IfModules => { |
| 397 |
'mod_delay.c' => { |
| 398 |
DelayEngine => 'off', |
| 399 |
}, |
| 400 |
}, |
| 401 |
}; |
| 402 |
|
| 403 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 404 |
|
| 405 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 406 |
# the child will indicate when it's done with its test by writing a message |
| 407 |
# to the parent. |
| 408 |
my ($rfh, $wfh); |
| 409 |
unless (pipe($rfh, $wfh)) { |
| 410 |
die("Can't open pipe: $!"); |
| 411 |
} |
| 412 |
|
| 413 |
my $ex; |
| 414 |
|
| 415 |
# Fork child |
| 416 |
$self->handle_sigchld(); |
| 417 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 418 |
if ($pid) { |
| 419 |
eval { |
| 420 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 421 |
$client->login($user, $passwd); |
| 422 |
|
| 423 |
my $conn = $client->stor_raw('test.txt'); |
| 424 |
unless ($conn) { |
| 425 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 426 |
$client->response_msg()); |
| 427 |
} |
| 428 |
|
| 429 |
my $buf = "Hello, World!\n"; |
| 430 |
$conn->write($buf, length($buf), 25); |
| 431 |
|
| 432 |
unless (-f $hidden_file) { |
| 433 |
die("File $hidden_file does not exist as expected"); |
| 434 |
} |
| 435 |
|
| 436 |
eval { $conn->abort() }; |
| 437 |
|
| 438 |
my $resp_code = $client->response_code(); |
| 439 |
my $resp_msg = $client->response_msg(); |
| 440 |
$self->assert_transfer_ok($resp_code, $resp_msg, 1); |
| 441 |
|
| 442 |
$client->quit(); |
| 443 |
|
| 444 |
if (-f $test_file) { |
| 445 |
die("File $test_file exists unexpectedly"); |
| 446 |
} |
| 447 |
|
| 448 |
if (-f $hidden_file) { |
| 449 |
die("File $hidden_file exists unexpectedly"); |
| 450 |
} |
| 451 |
}; |
| 452 |
|
| 453 |
if ($@) { |
| 454 |
$ex = $@; |
| 455 |
} |
| 456 |
|
| 457 |
$wfh->print("done\n"); |
| 458 |
$wfh->flush(); |
| 459 |
|
| 460 |
} else { |
| 461 |
eval { server_wait($config_file, $rfh) }; |
| 462 |
if ($@) { |
| 463 |
warn($@); |
| 464 |
exit 1; |
| 465 |
} |
| 466 |
|
| 467 |
exit 0; |
| 468 |
} |
| 469 |
|
| 470 |
# Stop server |
| 471 |
server_stop($pid_file); |
| 472 |
|
| 473 |
$self->assert_child_ok($pid); |
| 474 |
|
| 475 |
if ($ex) { |
| 476 |
test_append_logfile($log_file, $ex); |
| 477 |
unlink($log_file); |
| 478 |
|
| 479 |
die($ex); |
| 480 |
} |
| 481 |
|
| 482 |
unlink($log_file); |
| 483 |
} |
| 484 |
|
| 485 |
sub deleteabortedstores_hiddenstores_on_timeout_idle_bug4035 { |
| 486 |
my $self = shift; |
| 487 |
my $tmpdir = $self->{tmpdir}; |
| 488 |
my $setup = test_setup($tmpdir, 'config'); |
| 489 |
|
| 490 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 491 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 492 |
|
| 493 |
my $timeout_idle = 2; |
| 494 |
|
| 495 |
my $config = { |
| 496 |
PidFile => $setup->{pid_file}, |
| 497 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 498 |
SystemLog => $setup->{log_file}, |
| 499 |
|
| 500 |
AuthUserFile => $setup->{auth_user_file}, |
| 501 |
AuthGroupFile => $setup->{auth_group_file}, |
| 502 |
AuthOrder => 'mod_auth_file.c', |
| 503 |
|
| 504 |
DefaultChdir => '~', |
| 505 |
HiddenStores => 'on', |
| 506 |
DeleteAbortedStores => 'on', |
| 507 |
TimeoutIdle => $timeout_idle, |
| 508 |
|
| 509 |
IfModules => { |
| 510 |
'mod_delay.c' => { |
| 511 |
DelayEngine => 'off', |
| 512 |
}, |
| 513 |
}, |
| 514 |
}; |
| 515 |
|
| 516 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 517 |
$config); |
| 518 |
|
| 519 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 520 |
# the child will indicate when it's done with its test by writing a message |
| 521 |
# to the parent. |
| 522 |
my ($rfh, $wfh); |
| 523 |
unless (pipe($rfh, $wfh)) { |
| 524 |
die("Can't open pipe: $!"); |
| 525 |
} |
| 526 |
|
| 527 |
my $ex; |
| 528 |
|
| 529 |
# Fork child |
| 530 |
$self->handle_sigchld(); |
| 531 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 532 |
if ($pid) { |
| 533 |
eval { |
| 534 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 535 |
$client->login($setup->{user}, $setup->{passwd}); |
| 536 |
|
| 537 |
my $conn = $client->stor_raw('test.txt'); |
| 538 |
unless ($conn) { |
| 539 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 540 |
$client->response_msg()); |
| 541 |
} |
| 542 |
|
| 543 |
my $buf = "Hello, World!\n"; |
| 544 |
$conn->write($buf, length($buf), 25); |
| 545 |
|
| 546 |
unless (-f $hidden_file) { |
| 547 |
die("File $hidden_file does not exist as expected"); |
| 548 |
} |
| 549 |
|
| 550 |
# Now wait for more than the TimeoutIdle time |
| 551 |
if ($ENV{TEST_VERBOSE}) { |
| 552 |
print STDERR "+ sleeping for more than TimeoutIdle $timeout_idle secs\n"; |
| 553 |
} |
| 554 |
|
| 555 |
sleep($timeout_idle + 2); |
| 556 |
|
| 557 |
eval { $conn->close() }; |
| 558 |
|
| 559 |
my $resp_code = $client->response_code(); |
| 560 |
my $resp_msg = $client->response_msg(); |
| 561 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 562 |
|
| 563 |
$client->quit(); |
| 564 |
|
| 565 |
$self->assert(-f $test_file, |
| 566 |
test_msg("File $test_file does not exist as expected")); |
| 567 |
|
| 568 |
$self->assert(!-f $hidden_file, |
| 569 |
test_msg("File $hidden_file exists unexpectedly")); |
| 570 |
}; |
| 571 |
if ($@) { |
| 572 |
$ex = $@; |
| 573 |
} |
| 574 |
|
| 575 |
$wfh->print("done\n"); |
| 576 |
$wfh->flush(); |
| 577 |
|
| 578 |
} else { |
| 579 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 580 |
if ($@) { |
| 581 |
warn($@); |
| 582 |
exit 1; |
| 583 |
} |
| 584 |
|
| 585 |
exit 0; |
| 586 |
} |
| 587 |
|
| 588 |
# Stop server |
| 589 |
server_stop($setup->{pid_file}); |
| 590 |
$self->assert_child_ok($pid); |
| 591 |
|
| 592 |
test_cleanup($setup->{log_file}, $ex); |
| 593 |
} |
| 594 |
|
| 595 |
sub deleteabortedstores_hiddenstores_on_timeout_stalled_bug4035 { |
| 596 |
my $self = shift; |
| 597 |
my $tmpdir = $self->{tmpdir}; |
| 598 |
my $setup = test_setup($tmpdir, 'config'); |
| 599 |
|
| 600 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 601 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 602 |
|
| 603 |
my $timeout_stalled = 2; |
| 604 |
|
| 605 |
my $config = { |
| 606 |
PidFile => $setup->{pid_file}, |
| 607 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 608 |
SystemLog => $setup->{log_file}, |
| 609 |
|
| 610 |
AuthUserFile => $setup->{auth_user_file}, |
| 611 |
AuthGroupFile => $setup->{auth_group_file}, |
| 612 |
AuthOrder => 'mod_auth_file.c', |
| 613 |
|
| 614 |
DefaultChdir => '~', |
| 615 |
HiddenStores => 'on', |
| 616 |
DeleteAbortedStores => 'on', |
| 617 |
TimeoutStalled => $timeout_stalled, |
| 618 |
|
| 619 |
IfModules => { |
| 620 |
'mod_delay.c' => { |
| 621 |
DelayEngine => 'off', |
| 622 |
}, |
| 623 |
}, |
| 624 |
}; |
| 625 |
|
| 626 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 627 |
$config); |
| 628 |
|
| 629 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 630 |
# the child will indicate when it's done with its test by writing a message |
| 631 |
# to the parent. |
| 632 |
my ($rfh, $wfh); |
| 633 |
unless (pipe($rfh, $wfh)) { |
| 634 |
die("Can't open pipe: $!"); |
| 635 |
} |
| 636 |
|
| 637 |
my $ex; |
| 638 |
|
| 639 |
# Fork child |
| 640 |
$self->handle_sigchld(); |
| 641 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 642 |
if ($pid) { |
| 643 |
eval { |
| 644 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 645 |
$client->login($setup->{user}, $setup->{passwd}); |
| 646 |
|
| 647 |
my $conn = $client->stor_raw('test.txt'); |
| 648 |
unless ($conn) { |
| 649 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 650 |
$client->response_msg()); |
| 651 |
} |
| 652 |
|
| 653 |
my $buf = "Hello, World!\n"; |
| 654 |
$conn->write($buf, length($buf), 25); |
| 655 |
|
| 656 |
unless (-f $hidden_file) { |
| 657 |
die("File $hidden_file does not exist as expected"); |
| 658 |
} |
| 659 |
|
| 660 |
# Now wait for more than the TimeoutStalled time |
| 661 |
if ($ENV{TEST_VERBOSE}) { |
| 662 |
print STDERR "+ sleeping for more than TimeoutStalled $timeout_stalled secs\n"; |
| 663 |
} |
| 664 |
|
| 665 |
sleep($timeout_stalled + 2); |
| 666 |
|
| 667 |
eval { $conn->close() }; |
| 668 |
|
| 669 |
my $resp_code = $client->response_code(); |
| 670 |
my $resp_msg = $client->response_msg(); |
| 671 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 672 |
|
| 673 |
$self->assert(!-f $test_file, |
| 674 |
test_msg("File $test_file exists unexpectedly")); |
| 675 |
|
| 676 |
$self->assert(!-f $hidden_file, |
| 677 |
test_msg("File $hidden_file exists unexpectedly")); |
| 678 |
}; |
| 679 |
if ($@) { |
| 680 |
$ex = $@; |
| 681 |
} |
| 682 |
|
| 683 |
$wfh->print("done\n"); |
| 684 |
$wfh->flush(); |
| 685 |
|
| 686 |
} else { |
| 687 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 688 |
if ($@) { |
| 689 |
warn($@); |
| 690 |
exit 1; |
| 691 |
} |
| 692 |
|
| 693 |
exit 0; |
| 694 |
} |
| 695 |
|
| 696 |
# Stop server |
| 697 |
server_stop($setup->{pid_file}); |
| 698 |
$self->assert_child_ok($pid); |
| 699 |
|
| 700 |
eval { |
| 701 |
if (open(my $fh, "< $setup->{log_file}")) { |
| 702 |
my $ok = 0; |
| 703 |
|
| 704 |
while (my $line = <$fh>) { |
| 705 |
chomp($line); |
| 706 |
|
| 707 |
if ($ENV{TEST_VERBOSE}) { |
| 708 |
print STDERR "# $line\n"; |
| 709 |
} |
| 710 |
|
| 711 |
if ($line =~ /removing aborted HiddenStores file '(.*?)'$/) { |
| 712 |
my $hidden_path = $1; |
| 713 |
|
| 714 |
if ($hidden_path =~ /\.in\.test\.txt\.$/) { |
| 715 |
$ok = 1; |
| 716 |
} |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
close($fh); |
| 721 |
$self->assert($ok, test_msg("Did not see expected debug log messages")); |
| 722 |
|
| 723 |
} else { |
| 724 |
die("Can't read $setup->{log_file}: $!"); |
| 725 |
} |
| 726 |
}; |
| 727 |
if ($@) { |
| 728 |
$ex = $@; |
| 729 |
} |
| 730 |
|
| 731 |
test_cleanup($setup->{log_file}, $ex); |
| 732 |
} |
| 733 |
|
| 734 |
sub deleteabortedstores_hiddenstores_on_xfer_aborted_bug4467 { |
| 735 |
my $self = shift; |
| 736 |
my $tmpdir = $self->{tmpdir}; |
| 737 |
my $setup = test_setup($tmpdir, 'config'); |
| 738 |
|
| 739 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 740 |
|
| 741 |
# For this bug, we ensure that this file already exists, as if we are going |
| 742 |
# to overwrite it. Our upload is to the HiddenStores file, which will be |
| 743 |
# aborted (and the HiddenStores file cleaned up); we want to ensure that |
| 744 |
# this actual file still remains. |
| 745 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 746 |
if (open(my $fh, "> $test_file")) { |
| 747 |
unless (close($fh)) { |
| 748 |
die("Can't write $test_file: $!"); |
| 749 |
} |
| 750 |
|
| 751 |
} else { |
| 752 |
die("Can't open $test_file: $!"); |
| 753 |
} |
| 754 |
|
| 755 |
my $config = { |
| 756 |
PidFile => $setup->{pid_file}, |
| 757 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 758 |
SystemLog => $setup->{log_file}, |
| 759 |
|
| 760 |
AuthUserFile => $setup->{auth_user_file}, |
| 761 |
AuthGroupFile => $setup->{auth_group_file}, |
| 762 |
AuthOrder => 'mod_auth_file.c', |
| 763 |
|
| 764 |
DefaultChdir => '~', |
| 765 |
HiddenStores => 'on', |
| 766 |
DeleteAbortedStores => 'on', |
| 767 |
AllowOverwrite => 'on', |
| 768 |
|
| 769 |
IfModules => { |
| 770 |
'mod_delay.c' => { |
| 771 |
DelayEngine => 'off', |
| 772 |
}, |
| 773 |
}, |
| 774 |
}; |
| 775 |
|
| 776 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 777 |
$config); |
| 778 |
|
| 779 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 780 |
# the child will indicate when it's done with its test by writing a message |
| 781 |
# to the parent. |
| 782 |
my ($rfh, $wfh); |
| 783 |
unless (pipe($rfh, $wfh)) { |
| 784 |
die("Can't open pipe: $!"); |
| 785 |
} |
| 786 |
|
| 787 |
my $ex; |
| 788 |
|
| 789 |
# Fork child |
| 790 |
$self->handle_sigchld(); |
| 791 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 792 |
if ($pid) { |
| 793 |
eval { |
| 794 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 795 |
$client->login($setup->{user}, $setup->{passwd}); |
| 796 |
|
| 797 |
my $conn = $client->stor_raw('test.txt'); |
| 798 |
unless ($conn) { |
| 799 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 800 |
$client->response_msg()); |
| 801 |
} |
| 802 |
|
| 803 |
my $buf = "Hello, World!\n"; |
| 804 |
$conn->write($buf, length($buf), 25); |
| 805 |
|
| 806 |
unless (-f $hidden_file) { |
| 807 |
die("File $hidden_file does not exist as expected"); |
| 808 |
} |
| 809 |
|
| 810 |
eval { $conn->abort() }; |
| 811 |
|
| 812 |
my $resp_code = $client->response_code(); |
| 813 |
my $resp_msg = $client->response_msg(); |
| 814 |
$self->assert_transfer_ok($resp_code, $resp_msg, 1); |
| 815 |
|
| 816 |
eval { $conn->close() }; |
| 817 |
|
| 818 |
$self->assert(-f $test_file, |
| 819 |
test_msg("File $test_file does not exist as expected")); |
| 820 |
|
| 821 |
$self->assert(!-f $hidden_file, |
| 822 |
test_msg("File $hidden_file exists unexpectedly")); |
| 823 |
}; |
| 824 |
if ($@) { |
| 825 |
$ex = $@; |
| 826 |
} |
| 827 |
|
| 828 |
$wfh->print("done\n"); |
| 829 |
$wfh->flush(); |
| 830 |
|
| 831 |
} else { |
| 832 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 833 |
if ($@) { |
| 834 |
warn($@); |
| 835 |
exit 1; |
| 836 |
} |
| 837 |
|
| 838 |
exit 0; |
| 839 |
} |
| 840 |
|
| 841 |
# Stop server |
| 842 |
server_stop($setup->{pid_file}); |
| 843 |
$self->assert_child_ok($pid); |
| 844 |
|
| 845 |
eval { |
| 846 |
if (open(my $fh, "< $setup->{log_file}")) { |
| 847 |
my $hidden_path_ok = 0; |
| 848 |
my $actual_path_ok = 1; |
| 849 |
|
| 850 |
while (my $line = <$fh>) { |
| 851 |
chomp($line); |
| 852 |
|
| 853 |
if ($ENV{TEST_VERBOSE}) { |
| 854 |
print STDERR "# $line\n"; |
| 855 |
} |
| 856 |
|
| 857 |
if ($line =~ /removing aborted HiddenStores file '(.*?)'$/) { |
| 858 |
my $hidden_path = $1; |
| 859 |
|
| 860 |
if ($hidden_path =~ /\.in\.test\.txt\.$/) { |
| 861 |
$hidden_path_ok = 1; |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
if ($line =~ /removing aborted file '(.*?)'$/) { |
| 866 |
my $actual_path = $1; |
| 867 |
|
| 868 |
if ($actual_path =~ /test\.txt$/) { |
| 869 |
$actual_path_ok = 0; |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
close($fh); |
| 875 |
$self->assert($hidden_path_ok, |
| 876 |
test_msg("Did not see expected HiddenStores debug log messages")); |
| 877 |
$self->assert($actual_path_ok, |
| 878 |
test_msg("Saw unexpected actual path debug log messages")); |
| 879 |
|
| 880 |
} else { |
| 881 |
die("Can't read $setup->{log_file}: $!"); |
| 882 |
} |
| 883 |
}; |
| 884 |
if ($@) { |
| 885 |
$ex = $@; |
| 886 |
} |
| 887 |
|
| 888 |
test_cleanup($setup->{log_file}, $ex); |
| 889 |
} |
| 890 |
|
| 891 |
1; |