| 1 |
package ProFTPD::Tests::Config::HiddenStores; |
| 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 |
hiddenstores_on => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
hiddenstores_bug3156 => { |
| 24 |
order => ++$order, |
| 25 |
test_class => [qw(bug forking)], |
| 26 |
}, |
| 27 |
|
| 28 |
hiddenstores_prefix_bug3294 => { |
| 29 |
order => ++$order, |
| 30 |
test_class => [qw(bug forking)], |
| 31 |
}, |
| 32 |
|
| 33 |
hiddenstores_bool_prefix_bug3294 => { |
| 34 |
order => ++$order, |
| 35 |
test_class => [qw(bug forking)], |
| 36 |
}, |
| 37 |
|
| 38 |
hiddenstores_suffix_bug3872 => { |
| 39 |
order => ++$order, |
| 40 |
test_class => [qw(bug forking)], |
| 41 |
}, |
| 42 |
|
| 43 |
hiddenstores_pid_var_bug4062 => { |
| 44 |
order => ++$order, |
| 45 |
test_class => [qw(bug forking)], |
| 46 |
}, |
| 47 |
|
| 48 |
hiddenstores_timeout_idle_bug4035 => { |
| 49 |
order => ++$order, |
| 50 |
test_class => [qw(bug forking)], |
| 51 |
}, |
| 52 |
|
| 53 |
hiddenstores_timeout_notransfer_bug4035 => { |
| 54 |
order => ++$order, |
| 55 |
test_class => [qw(bug forking)], |
| 56 |
}, |
| 57 |
|
| 58 |
hiddenstores_timeout_stalled_bug4035 => { |
| 59 |
order => ++$order, |
| 60 |
test_class => [qw(bug forking)], |
| 61 |
}, |
| 62 |
|
| 63 |
hiddenstores_timeout_session_bug4035 => { |
| 64 |
order => ++$order, |
| 65 |
test_class => [qw(bug forking)], |
| 66 |
}, |
| 67 |
|
| 68 |
}; |
| 69 |
|
| 70 |
sub new { |
| 71 |
return shift()->SUPER::new(@_); |
| 72 |
} |
| 73 |
|
| 74 |
sub list_tests { |
| 75 |
return testsuite_get_runnable_tests($TESTS); |
| 76 |
} |
| 77 |
|
| 78 |
sub hiddenstores_on { |
| 79 |
my $self = shift; |
| 80 |
my $tmpdir = $self->{tmpdir}; |
| 81 |
|
| 82 |
my $config_file = "$tmpdir/config.conf"; |
| 83 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 84 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 85 |
|
| 86 |
my $log_file = test_get_logfile(); |
| 87 |
|
| 88 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 89 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 90 |
|
| 91 |
my $user = 'proftpd'; |
| 92 |
my $passwd = 'test'; |
| 93 |
my $group = 'ftpd'; |
| 94 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 95 |
my $uid = 500; |
| 96 |
my $gid = 500; |
| 97 |
|
| 98 |
# Make sure that, if we're running as root, that the home directory has |
| 99 |
# permissions/privs set for the account we create |
| 100 |
if ($< == 0) { |
| 101 |
unless (chmod(0755, $home_dir)) { |
| 102 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 103 |
} |
| 104 |
|
| 105 |
unless (chown($uid, $gid, $home_dir)) { |
| 106 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 111 |
'/bin/bash'); |
| 112 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 113 |
|
| 114 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 115 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 116 |
|
| 117 |
my $config = { |
| 118 |
PidFile => $pid_file, |
| 119 |
ScoreboardFile => $scoreboard_file, |
| 120 |
SystemLog => $log_file, |
| 121 |
|
| 122 |
AuthUserFile => $auth_user_file, |
| 123 |
AuthGroupFile => $auth_group_file, |
| 124 |
AuthOrder => 'mod_auth_file.c', |
| 125 |
|
| 126 |
DefaultChdir => '~', |
| 127 |
HiddenStores => 'on', |
| 128 |
|
| 129 |
IfModules => { |
| 130 |
'mod_delay.c' => { |
| 131 |
DelayEngine => 'off', |
| 132 |
}, |
| 133 |
}, |
| 134 |
}; |
| 135 |
|
| 136 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 137 |
|
| 138 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 139 |
# the child will indicate when it's done with its test by writing a message |
| 140 |
# to the parent. |
| 141 |
my ($rfh, $wfh); |
| 142 |
unless (pipe($rfh, $wfh)) { |
| 143 |
die("Can't open pipe: $!"); |
| 144 |
} |
| 145 |
|
| 146 |
my $ex; |
| 147 |
|
| 148 |
# Fork child |
| 149 |
$self->handle_sigchld(); |
| 150 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 151 |
if ($pid) { |
| 152 |
eval { |
| 153 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 154 |
$client->login($user, $passwd); |
| 155 |
|
| 156 |
my $conn = $client->stor_raw('test.txt'); |
| 157 |
unless ($conn) { |
| 158 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 159 |
$client->response_msg()); |
| 160 |
} |
| 161 |
|
| 162 |
my $buf = "Hello, World!\n"; |
| 163 |
$conn->write($buf, length($buf), 25); |
| 164 |
|
| 165 |
unless (-f $hidden_file) { |
| 166 |
die("File $hidden_file does not exist as expected"); |
| 167 |
} |
| 168 |
|
| 169 |
eval { $conn->close() }; |
| 170 |
|
| 171 |
my $resp_code = $client->response_code(); |
| 172 |
my $resp_msg = $client->response_msg(); |
| 173 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 174 |
|
| 175 |
$client->quit(); |
| 176 |
|
| 177 |
unless (-f $test_file) { |
| 178 |
die("File $test_file does not exist as expected"); |
| 179 |
} |
| 180 |
|
| 181 |
if (-f $hidden_file) { |
| 182 |
die("File $hidden_file exists unexpectedly"); |
| 183 |
} |
| 184 |
}; |
| 185 |
|
| 186 |
if ($@) { |
| 187 |
$ex = $@; |
| 188 |
} |
| 189 |
|
| 190 |
$wfh->print("done\n"); |
| 191 |
$wfh->flush(); |
| 192 |
|
| 193 |
} else { |
| 194 |
eval { server_wait($config_file, $rfh) }; |
| 195 |
if ($@) { |
| 196 |
warn($@); |
| 197 |
exit 1; |
| 198 |
} |
| 199 |
|
| 200 |
exit 0; |
| 201 |
} |
| 202 |
|
| 203 |
# Stop server |
| 204 |
server_stop($pid_file); |
| 205 |
|
| 206 |
$self->assert_child_ok($pid); |
| 207 |
|
| 208 |
if ($ex) { |
| 209 |
test_append_logfile($log_file, $ex); |
| 210 |
unlink($log_file); |
| 211 |
|
| 212 |
die($ex); |
| 213 |
} |
| 214 |
|
| 215 |
unlink($log_file); |
| 216 |
} |
| 217 |
|
| 218 |
sub hiddenstores_bug3156 { |
| 219 |
my $self = shift; |
| 220 |
my $tmpdir = $self->{tmpdir}; |
| 221 |
|
| 222 |
my $config_file = "$tmpdir/config.conf"; |
| 223 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 224 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 225 |
|
| 226 |
my $log_file = test_get_logfile(); |
| 227 |
|
| 228 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 229 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 230 |
|
| 231 |
my $user = 'proftpd'; |
| 232 |
my $passwd = 'test'; |
| 233 |
my $group = 'ftpd'; |
| 234 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 235 |
my $uid = 500; |
| 236 |
my $gid = 500; |
| 237 |
|
| 238 |
# Make sure that, if we're running as root, that the home directory has |
| 239 |
# permissions/privs set for the account we create |
| 240 |
if ($< == 0) { |
| 241 |
unless (chmod(0755, $home_dir)) { |
| 242 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 243 |
} |
| 244 |
|
| 245 |
unless (chown($uid, $gid, $home_dir)) { |
| 246 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 251 |
'/bin/bash'); |
| 252 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 253 |
|
| 254 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 255 |
|
| 256 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 257 |
if (open(my $fh, "> $test_file")) { |
| 258 |
print $fh "Hello, World!\n"; |
| 259 |
|
| 260 |
unless (close($fh)) { |
| 261 |
die("Can't write $test_file: $!"); |
| 262 |
} |
| 263 |
|
| 264 |
} else { |
| 265 |
die("Can't open $test_file: $!"); |
| 266 |
} |
| 267 |
|
| 268 |
my $config = { |
| 269 |
PidFile => $pid_file, |
| 270 |
ScoreboardFile => $scoreboard_file, |
| 271 |
SystemLog => $log_file, |
| 272 |
|
| 273 |
AuthUserFile => $auth_user_file, |
| 274 |
AuthGroupFile => $auth_group_file, |
| 275 |
AuthOrder => 'mod_auth_file.c', |
| 276 |
|
| 277 |
DefaultChdir => '~', |
| 278 |
AllowRetrieveRestart => 'on', |
| 279 |
HiddenStores => 'on', |
| 280 |
|
| 281 |
IfModules => { |
| 282 |
'mod_delay.c' => { |
| 283 |
DelayEngine => 'off', |
| 284 |
}, |
| 285 |
}, |
| 286 |
}; |
| 287 |
|
| 288 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 289 |
|
| 290 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 291 |
# the child will indicate when it's done with its test by writing a message |
| 292 |
# to the parent. |
| 293 |
my ($rfh, $wfh); |
| 294 |
unless (pipe($rfh, $wfh)) { |
| 295 |
die("Can't open pipe: $!"); |
| 296 |
} |
| 297 |
|
| 298 |
my $ex; |
| 299 |
|
| 300 |
# Fork child |
| 301 |
$self->handle_sigchld(); |
| 302 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 303 |
if ($pid) { |
| 304 |
eval { |
| 305 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 306 |
$client->login($user, $passwd); |
| 307 |
|
| 308 |
# Make sure we're using binary transfers |
| 309 |
$client->type('binary'); |
| 310 |
|
| 311 |
# Bug#3156 is a request to allow resumed downloads even if HiddenStores |
| 312 |
# is in effect. |
| 313 |
$client->rest(1); |
| 314 |
|
| 315 |
my $conn = $client->retr_raw('test.txt'); |
| 316 |
unless ($conn) { |
| 317 |
die("Failed to RETR test.txt: " . $client->response_code() . " " . |
| 318 |
$client->response_msg()); |
| 319 |
} |
| 320 |
|
| 321 |
my $buf; |
| 322 |
$conn->read($buf, 8192, 30); |
| 323 |
eval { $conn->close() }; |
| 324 |
|
| 325 |
my $resp_code = $client->response_code(); |
| 326 |
my $resp_msg = $client->response_msg(); |
| 327 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 328 |
|
| 329 |
$client->quit(); |
| 330 |
|
| 331 |
unless (-f $test_file) { |
| 332 |
die("File $test_file does not exist as expected"); |
| 333 |
} |
| 334 |
|
| 335 |
if (-f $hidden_file) { |
| 336 |
die("File $hidden_file exists unexpectedly"); |
| 337 |
} |
| 338 |
}; |
| 339 |
|
| 340 |
if ($@) { |
| 341 |
$ex = $@; |
| 342 |
} |
| 343 |
|
| 344 |
$wfh->print("done\n"); |
| 345 |
$wfh->flush(); |
| 346 |
|
| 347 |
} else { |
| 348 |
eval { server_wait($config_file, $rfh) }; |
| 349 |
if ($@) { |
| 350 |
warn($@); |
| 351 |
exit 1; |
| 352 |
} |
| 353 |
|
| 354 |
exit 0; |
| 355 |
} |
| 356 |
|
| 357 |
# Stop server |
| 358 |
server_stop($pid_file); |
| 359 |
|
| 360 |
$self->assert_child_ok($pid); |
| 361 |
|
| 362 |
if ($ex) { |
| 363 |
test_append_logfile($log_file, $ex); |
| 364 |
unlink($log_file); |
| 365 |
|
| 366 |
die($ex); |
| 367 |
} |
| 368 |
|
| 369 |
unlink($log_file); |
| 370 |
} |
| 371 |
|
| 372 |
sub hiddenstores_prefix_bug3294 { |
| 373 |
my $self = shift; |
| 374 |
my $tmpdir = $self->{tmpdir}; |
| 375 |
|
| 376 |
my $config_file = "$tmpdir/config.conf"; |
| 377 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 378 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 379 |
|
| 380 |
my $log_file = test_get_logfile(); |
| 381 |
|
| 382 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 383 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 384 |
|
| 385 |
my $user = 'proftpd'; |
| 386 |
my $passwd = 'test'; |
| 387 |
my $group = 'ftpd'; |
| 388 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 389 |
my $uid = 500; |
| 390 |
my $gid = 500; |
| 391 |
|
| 392 |
# Make sure that, if we're running as root, that the home directory has |
| 393 |
# permissions/privs set for the account we create |
| 394 |
if ($< == 0) { |
| 395 |
unless (chmod(0755, $home_dir)) { |
| 396 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 397 |
} |
| 398 |
|
| 399 |
unless (chown($uid, $gid, $home_dir)) { |
| 400 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 405 |
'/bin/bash'); |
| 406 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 407 |
|
| 408 |
my $hiddenstore_prefix = "foobar"; |
| 409 |
|
| 410 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/." . $hiddenstore_prefix . ".test.txt."); |
| 411 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 412 |
|
| 413 |
my $config = { |
| 414 |
PidFile => $pid_file, |
| 415 |
ScoreboardFile => $scoreboard_file, |
| 416 |
SystemLog => $log_file, |
| 417 |
|
| 418 |
AuthUserFile => $auth_user_file, |
| 419 |
AuthGroupFile => $auth_group_file, |
| 420 |
AuthOrder => 'mod_auth_file.c', |
| 421 |
|
| 422 |
DefaultChdir => '~', |
| 423 |
HiddenStores => $hiddenstore_prefix, |
| 424 |
|
| 425 |
IfModules => { |
| 426 |
'mod_delay.c' => { |
| 427 |
DelayEngine => 'off', |
| 428 |
}, |
| 429 |
}, |
| 430 |
}; |
| 431 |
|
| 432 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 433 |
|
| 434 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 435 |
# the child will indicate when it's done with its test by writing a message |
| 436 |
# to the parent. |
| 437 |
my ($rfh, $wfh); |
| 438 |
unless (pipe($rfh, $wfh)) { |
| 439 |
die("Can't open pipe: $!"); |
| 440 |
} |
| 441 |
|
| 442 |
my $ex; |
| 443 |
|
| 444 |
# Fork child |
| 445 |
$self->handle_sigchld(); |
| 446 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 447 |
if ($pid) { |
| 448 |
eval { |
| 449 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 450 |
$client->login($user, $passwd); |
| 451 |
|
| 452 |
my $conn = $client->stor_raw('test.txt'); |
| 453 |
unless ($conn) { |
| 454 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 455 |
$client->response_msg()); |
| 456 |
} |
| 457 |
|
| 458 |
my $buf = "Hello, World!\n"; |
| 459 |
$conn->write($buf, length($buf), 25); |
| 460 |
|
| 461 |
unless (-f $hidden_file) { |
| 462 |
die("File $hidden_file does not exist as expected"); |
| 463 |
} |
| 464 |
|
| 465 |
eval { $conn->close() }; |
| 466 |
|
| 467 |
my $resp_code = $client->response_code(); |
| 468 |
my $resp_msg = $client->response_msg(); |
| 469 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 470 |
|
| 471 |
$client->quit(); |
| 472 |
|
| 473 |
unless (-f $test_file) { |
| 474 |
die("File $test_file does not exist as expected"); |
| 475 |
} |
| 476 |
|
| 477 |
if (-f $hidden_file) { |
| 478 |
die("File $hidden_file exists unexpectedly"); |
| 479 |
} |
| 480 |
}; |
| 481 |
|
| 482 |
if ($@) { |
| 483 |
$ex = $@; |
| 484 |
} |
| 485 |
|
| 486 |
$wfh->print("done\n"); |
| 487 |
$wfh->flush(); |
| 488 |
|
| 489 |
} else { |
| 490 |
eval { server_wait($config_file, $rfh) }; |
| 491 |
if ($@) { |
| 492 |
warn($@); |
| 493 |
exit 1; |
| 494 |
} |
| 495 |
|
| 496 |
exit 0; |
| 497 |
} |
| 498 |
|
| 499 |
# Stop server |
| 500 |
server_stop($pid_file); |
| 501 |
|
| 502 |
$self->assert_child_ok($pid); |
| 503 |
|
| 504 |
if ($ex) { |
| 505 |
test_append_logfile($log_file, $ex); |
| 506 |
unlink($log_file); |
| 507 |
|
| 508 |
die($ex); |
| 509 |
} |
| 510 |
|
| 511 |
unlink($log_file); |
| 512 |
} |
| 513 |
|
| 514 |
sub hiddenstores_bool_prefix_bug3294 { |
| 515 |
my $self = shift; |
| 516 |
my $tmpdir = $self->{tmpdir}; |
| 517 |
|
| 518 |
my $config_file = "$tmpdir/config.conf"; |
| 519 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 520 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 521 |
|
| 522 |
my $log_file = test_get_logfile(); |
| 523 |
|
| 524 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 525 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 526 |
|
| 527 |
my $user = 'proftpd'; |
| 528 |
my $passwd = 'test'; |
| 529 |
my $group = 'ftpd'; |
| 530 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 531 |
my $uid = 500; |
| 532 |
my $gid = 500; |
| 533 |
|
| 534 |
# Make sure that, if we're running as root, that the home directory has |
| 535 |
# permissions/privs set for the account we create |
| 536 |
if ($< == 0) { |
| 537 |
unless (chmod(0755, $home_dir)) { |
| 538 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 539 |
} |
| 540 |
|
| 541 |
unless (chown($uid, $gid, $home_dir)) { |
| 542 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 547 |
'/bin/bash'); |
| 548 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 549 |
|
| 550 |
my $hiddenstore_prefix = ".off."; |
| 551 |
|
| 552 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/" . $hiddenstore_prefix . "test.txt."); |
| 553 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 554 |
|
| 555 |
my $config = { |
| 556 |
PidFile => $pid_file, |
| 557 |
ScoreboardFile => $scoreboard_file, |
| 558 |
SystemLog => $log_file, |
| 559 |
|
| 560 |
AuthUserFile => $auth_user_file, |
| 561 |
AuthGroupFile => $auth_group_file, |
| 562 |
AuthOrder => 'mod_auth_file.c', |
| 563 |
|
| 564 |
DefaultChdir => '~', |
| 565 |
HiddenStores => $hiddenstore_prefix, |
| 566 |
|
| 567 |
IfModules => { |
| 568 |
'mod_delay.c' => { |
| 569 |
DelayEngine => 'off', |
| 570 |
}, |
| 571 |
}, |
| 572 |
}; |
| 573 |
|
| 574 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 575 |
|
| 576 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 577 |
# the child will indicate when it's done with its test by writing a message |
| 578 |
# to the parent. |
| 579 |
my ($rfh, $wfh); |
| 580 |
unless (pipe($rfh, $wfh)) { |
| 581 |
die("Can't open pipe: $!"); |
| 582 |
} |
| 583 |
|
| 584 |
my $ex; |
| 585 |
|
| 586 |
# Fork child |
| 587 |
$self->handle_sigchld(); |
| 588 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 589 |
if ($pid) { |
| 590 |
eval { |
| 591 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 592 |
$client->login($user, $passwd); |
| 593 |
|
| 594 |
my $conn = $client->stor_raw('test.txt'); |
| 595 |
unless ($conn) { |
| 596 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 597 |
$client->response_msg()); |
| 598 |
} |
| 599 |
|
| 600 |
my $buf = "Hello, World!\n"; |
| 601 |
$conn->write($buf, length($buf), 25); |
| 602 |
|
| 603 |
unless (-f $hidden_file) { |
| 604 |
die("File $hidden_file does not exist as expected"); |
| 605 |
} |
| 606 |
|
| 607 |
eval { $conn->close() }; |
| 608 |
|
| 609 |
my $resp_code = $client->response_code(); |
| 610 |
my $resp_msg = $client->response_msg(); |
| 611 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 612 |
|
| 613 |
$client->quit(); |
| 614 |
|
| 615 |
unless (-f $test_file) { |
| 616 |
die("File $test_file does not exist as expected"); |
| 617 |
} |
| 618 |
|
| 619 |
if (-f $hidden_file) { |
| 620 |
die("File $hidden_file exists unexpectedly"); |
| 621 |
} |
| 622 |
}; |
| 623 |
|
| 624 |
if ($@) { |
| 625 |
$ex = $@; |
| 626 |
} |
| 627 |
|
| 628 |
$wfh->print("done\n"); |
| 629 |
$wfh->flush(); |
| 630 |
|
| 631 |
} else { |
| 632 |
eval { server_wait($config_file, $rfh) }; |
| 633 |
if ($@) { |
| 634 |
warn($@); |
| 635 |
exit 1; |
| 636 |
} |
| 637 |
|
| 638 |
exit 0; |
| 639 |
} |
| 640 |
|
| 641 |
# Stop server |
| 642 |
server_stop($pid_file); |
| 643 |
|
| 644 |
$self->assert_child_ok($pid); |
| 645 |
|
| 646 |
if ($ex) { |
| 647 |
test_append_logfile($log_file, $ex); |
| 648 |
unlink($log_file); |
| 649 |
|
| 650 |
die($ex); |
| 651 |
} |
| 652 |
|
| 653 |
unlink($log_file); |
| 654 |
} |
| 655 |
|
| 656 |
sub hiddenstores_suffix_bug3872 { |
| 657 |
my $self = shift; |
| 658 |
my $tmpdir = $self->{tmpdir}; |
| 659 |
|
| 660 |
my $config_file = "$tmpdir/config.conf"; |
| 661 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 662 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 663 |
|
| 664 |
my $log_file = test_get_logfile(); |
| 665 |
|
| 666 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 667 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 668 |
|
| 669 |
my $user = 'proftpd'; |
| 670 |
my $passwd = 'test'; |
| 671 |
my $group = 'ftpd'; |
| 672 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 673 |
my $uid = 500; |
| 674 |
my $gid = 500; |
| 675 |
|
| 676 |
# Make sure that, if we're running as root, that the home directory has |
| 677 |
# permissions/privs set for the account we create |
| 678 |
if ($< == 0) { |
| 679 |
unless (chmod(0755, $home_dir)) { |
| 680 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 681 |
} |
| 682 |
|
| 683 |
unless (chown($uid, $gid, $home_dir)) { |
| 684 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 689 |
'/bin/bash'); |
| 690 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 691 |
|
| 692 |
my $hiddenstore_prefix = "foobar-"; |
| 693 |
my $hiddenstore_suffix = "-quxx-quzz"; |
| 694 |
|
| 695 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/" . $hiddenstore_prefix . "test.txt" . $hiddenstore_suffix); |
| 696 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 697 |
|
| 698 |
my $config = { |
| 699 |
PidFile => $pid_file, |
| 700 |
ScoreboardFile => $scoreboard_file, |
| 701 |
SystemLog => $log_file, |
| 702 |
|
| 703 |
AuthUserFile => $auth_user_file, |
| 704 |
AuthGroupFile => $auth_group_file, |
| 705 |
AuthOrder => 'mod_auth_file.c', |
| 706 |
|
| 707 |
DefaultChdir => '~', |
| 708 |
HiddenStores => "$hiddenstore_prefix $hiddenstore_suffix", |
| 709 |
|
| 710 |
IfModules => { |
| 711 |
'mod_delay.c' => { |
| 712 |
DelayEngine => 'off', |
| 713 |
}, |
| 714 |
}, |
| 715 |
}; |
| 716 |
|
| 717 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 718 |
|
| 719 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 720 |
# the child will indicate when it's done with its test by writing a message |
| 721 |
# to the parent. |
| 722 |
my ($rfh, $wfh); |
| 723 |
unless (pipe($rfh, $wfh)) { |
| 724 |
die("Can't open pipe: $!"); |
| 725 |
} |
| 726 |
|
| 727 |
my $ex; |
| 728 |
|
| 729 |
# Fork child |
| 730 |
$self->handle_sigchld(); |
| 731 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 732 |
if ($pid) { |
| 733 |
eval { |
| 734 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 735 |
$client->login($user, $passwd); |
| 736 |
|
| 737 |
my $conn = $client->stor_raw('test.txt'); |
| 738 |
unless ($conn) { |
| 739 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 740 |
$client->response_msg()); |
| 741 |
} |
| 742 |
|
| 743 |
my $buf = "Hello, World!\n"; |
| 744 |
$conn->write($buf, length($buf), 25); |
| 745 |
|
| 746 |
unless (-f $hidden_file) { |
| 747 |
die("File $hidden_file does not exist as expected"); |
| 748 |
} |
| 749 |
|
| 750 |
eval { $conn->close() }; |
| 751 |
|
| 752 |
my $resp_code = $client->response_code(); |
| 753 |
my $resp_msg = $client->response_msg(); |
| 754 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 755 |
|
| 756 |
$client->quit(); |
| 757 |
|
| 758 |
unless (-f $test_file) { |
| 759 |
die("File $test_file does not exist as expected"); |
| 760 |
} |
| 761 |
|
| 762 |
if (-f $hidden_file) { |
| 763 |
die("File $hidden_file exists unexpectedly"); |
| 764 |
} |
| 765 |
}; |
| 766 |
|
| 767 |
if ($@) { |
| 768 |
$ex = $@; |
| 769 |
} |
| 770 |
|
| 771 |
$wfh->print("done\n"); |
| 772 |
$wfh->flush(); |
| 773 |
|
| 774 |
} else { |
| 775 |
eval { server_wait($config_file, $rfh) }; |
| 776 |
if ($@) { |
| 777 |
warn($@); |
| 778 |
exit 1; |
| 779 |
} |
| 780 |
|
| 781 |
exit 0; |
| 782 |
} |
| 783 |
|
| 784 |
# Stop server |
| 785 |
server_stop($pid_file); |
| 786 |
|
| 787 |
$self->assert_child_ok($pid); |
| 788 |
|
| 789 |
if ($ex) { |
| 790 |
test_append_logfile($log_file, $ex); |
| 791 |
unlink($log_file); |
| 792 |
|
| 793 |
die($ex); |
| 794 |
} |
| 795 |
|
| 796 |
unlink($log_file); |
| 797 |
} |
| 798 |
|
| 799 |
sub find_hiddenstore_files { |
| 800 |
my $path = shift; |
| 801 |
my $prefix = shift; |
| 802 |
|
| 803 |
my $dirh; |
| 804 |
unless (opendir($dirh, $path)) { |
| 805 |
die("Can't open directory '$path': $!"); |
| 806 |
} |
| 807 |
|
| 808 |
my $files = [grep { /^$prefix/ && -f "$path/$_" } readdir($dirh)]; |
| 809 |
closedir($dirh); |
| 810 |
|
| 811 |
return $files; |
| 812 |
} |
| 813 |
|
| 814 |
sub hiddenstores_pid_var_bug4062 { |
| 815 |
my $self = shift; |
| 816 |
my $tmpdir = $self->{tmpdir}; |
| 817 |
|
| 818 |
my $config_file = "$tmpdir/config.conf"; |
| 819 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 820 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 821 |
|
| 822 |
my $log_file = test_get_logfile(); |
| 823 |
|
| 824 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 825 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 826 |
|
| 827 |
my $user = 'proftpd'; |
| 828 |
my $passwd = 'test'; |
| 829 |
my $group = 'ftpd'; |
| 830 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 831 |
my $uid = 500; |
| 832 |
my $gid = 500; |
| 833 |
|
| 834 |
# Make sure that, if we're running as root, that the home directory has |
| 835 |
# permissions/privs set for the account we create |
| 836 |
if ($< == 0) { |
| 837 |
unless (chmod(0755, $home_dir)) { |
| 838 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 839 |
} |
| 840 |
|
| 841 |
unless (chown($uid, $gid, $home_dir)) { |
| 842 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 847 |
'/bin/bash'); |
| 848 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 849 |
|
| 850 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 851 |
|
| 852 |
my $config = { |
| 853 |
PidFile => $pid_file, |
| 854 |
ScoreboardFile => $scoreboard_file, |
| 855 |
SystemLog => $log_file, |
| 856 |
|
| 857 |
AuthUserFile => $auth_user_file, |
| 858 |
AuthGroupFile => $auth_group_file, |
| 859 |
AuthOrder => 'mod_auth_file.c', |
| 860 |
|
| 861 |
DefaultChdir => '~', |
| 862 |
HiddenStores => '.in. .%P', |
| 863 |
|
| 864 |
IfModules => { |
| 865 |
'mod_delay.c' => { |
| 866 |
DelayEngine => 'off', |
| 867 |
}, |
| 868 |
}, |
| 869 |
}; |
| 870 |
|
| 871 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 872 |
|
| 873 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 874 |
# the child will indicate when it's done with its test by writing a message |
| 875 |
# to the parent. |
| 876 |
my ($rfh, $wfh); |
| 877 |
unless (pipe($rfh, $wfh)) { |
| 878 |
die("Can't open pipe: $!"); |
| 879 |
} |
| 880 |
|
| 881 |
my $ex; |
| 882 |
|
| 883 |
# Fork child |
| 884 |
$self->handle_sigchld(); |
| 885 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 886 |
if ($pid) { |
| 887 |
eval { |
| 888 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 889 |
$client->login($user, $passwd); |
| 890 |
|
| 891 |
my $conn = $client->stor_raw('test.txt'); |
| 892 |
unless ($conn) { |
| 893 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 894 |
$client->response_msg()); |
| 895 |
} |
| 896 |
|
| 897 |
my $buf = "Hello, World!\n"; |
| 898 |
$conn->write($buf, length($buf), 25); |
| 899 |
|
| 900 |
my $hidden_files = find_hiddenstore_files($home_dir, '.in.'); |
| 901 |
unless (defined($hidden_files) && scalar(@$hidden_files) == 1) { |
| 902 |
die("HiddenStores file does not exist as expected"); |
| 903 |
} |
| 904 |
|
| 905 |
eval { $conn->close() }; |
| 906 |
|
| 907 |
my $resp_code = $client->response_code(); |
| 908 |
my $resp_msg = $client->response_msg(); |
| 909 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 910 |
|
| 911 |
$client->quit(); |
| 912 |
|
| 913 |
unless (-f $test_file) { |
| 914 |
die("File $test_file does not exist as expected"); |
| 915 |
} |
| 916 |
|
| 917 |
$hidden_files = find_hiddenstore_files($home_dir, '.in.'); |
| 918 |
if (defined($hidden_files) && scalar(@$hidden_files) > 0) { |
| 919 |
die("HiddenStores file exists unexpectedly"); |
| 920 |
} |
| 921 |
}; |
| 922 |
|
| 923 |
if ($@) { |
| 924 |
$ex = $@; |
| 925 |
} |
| 926 |
|
| 927 |
$wfh->print("done\n"); |
| 928 |
$wfh->flush(); |
| 929 |
|
| 930 |
} else { |
| 931 |
eval { server_wait($config_file, $rfh) }; |
| 932 |
if ($@) { |
| 933 |
warn($@); |
| 934 |
exit 1; |
| 935 |
} |
| 936 |
|
| 937 |
exit 0; |
| 938 |
} |
| 939 |
|
| 940 |
# Stop server |
| 941 |
server_stop($pid_file); |
| 942 |
|
| 943 |
$self->assert_child_ok($pid); |
| 944 |
|
| 945 |
if ($ex) { |
| 946 |
test_append_logfile($log_file, $ex); |
| 947 |
unlink($log_file); |
| 948 |
|
| 949 |
die($ex); |
| 950 |
} |
| 951 |
|
| 952 |
unlink($log_file); |
| 953 |
} |
| 954 |
|
| 955 |
sub hiddenstores_timeout_idle_bug4035 { |
| 956 |
my $self = shift; |
| 957 |
my $tmpdir = $self->{tmpdir}; |
| 958 |
my $setup = test_setup($tmpdir, 'config'); |
| 959 |
|
| 960 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 961 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 962 |
|
| 963 |
my $timeout_idle = 4; |
| 964 |
|
| 965 |
my $config = { |
| 966 |
PidFile => $setup->{pid_file}, |
| 967 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 968 |
SystemLog => $setup->{log_file}, |
| 969 |
|
| 970 |
AuthUserFile => $setup->{auth_user_file}, |
| 971 |
AuthGroupFile => $setup->{auth_group_file}, |
| 972 |
AuthOrder => 'mod_auth_file.c', |
| 973 |
|
| 974 |
DefaultChdir => '~', |
| 975 |
HiddenStores => 'on', |
| 976 |
TimeoutIdle => $timeout_idle, |
| 977 |
|
| 978 |
IfModules => { |
| 979 |
'mod_delay.c' => { |
| 980 |
DelayEngine => 'off', |
| 981 |
}, |
| 982 |
}, |
| 983 |
}; |
| 984 |
|
| 985 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 986 |
$config); |
| 987 |
|
| 988 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 989 |
# the child will indicate when it's done with its test by writing a message |
| 990 |
# to the parent. |
| 991 |
my ($rfh, $wfh); |
| 992 |
unless (pipe($rfh, $wfh)) { |
| 993 |
die("Can't open pipe: $!"); |
| 994 |
} |
| 995 |
|
| 996 |
my $ex; |
| 997 |
|
| 998 |
# Fork child |
| 999 |
$self->handle_sigchld(); |
| 1000 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1001 |
if ($pid) { |
| 1002 |
eval { |
| 1003 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1004 |
$client->login($setup->{user}, $setup->{passwd}); |
| 1005 |
|
| 1006 |
my $conn = $client->stor_raw('test.txt'); |
| 1007 |
unless ($conn) { |
| 1008 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 1009 |
$client->response_msg()); |
| 1010 |
} |
| 1011 |
|
| 1012 |
# Sleep for longer than the TimeoutIdle |
| 1013 |
sleep($timeout_idle + 1); |
| 1014 |
|
| 1015 |
my $buf = "Hello, World!\n"; |
| 1016 |
$conn->write($buf, length($buf), 25); |
| 1017 |
|
| 1018 |
unless (-f $hidden_file) { |
| 1019 |
die("File $hidden_file does not exist as expected"); |
| 1020 |
} |
| 1021 |
|
| 1022 |
eval { $conn->close() }; |
| 1023 |
|
| 1024 |
my $resp_code = $client->response_code(); |
| 1025 |
my $resp_msg = $client->response_msg(); |
| 1026 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 1027 |
|
| 1028 |
$client->quit(); |
| 1029 |
|
| 1030 |
if ($^O eq 'darwin') { |
| 1031 |
# MacOSX hack |
| 1032 |
$test_file = ('/private' . $test_file); |
| 1033 |
$hidden_file = ('/private' . $hidden_file); |
| 1034 |
} |
| 1035 |
|
| 1036 |
if (-f $hidden_file) { |
| 1037 |
die("File $hidden_file exists unexpectedly"); |
| 1038 |
} |
| 1039 |
|
| 1040 |
unless (-f $test_file) { |
| 1041 |
die("File $test_file does not exist as expected"); |
| 1042 |
} |
| 1043 |
}; |
| 1044 |
|
| 1045 |
if ($@) { |
| 1046 |
$ex = $@; |
| 1047 |
} |
| 1048 |
|
| 1049 |
$wfh->print("done\n"); |
| 1050 |
$wfh->flush(); |
| 1051 |
|
| 1052 |
} else { |
| 1053 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 1054 |
if ($@) { |
| 1055 |
warn($@); |
| 1056 |
exit 1; |
| 1057 |
} |
| 1058 |
|
| 1059 |
exit 0; |
| 1060 |
} |
| 1061 |
|
| 1062 |
# Stop server |
| 1063 |
server_stop($setup->{pid_file}); |
| 1064 |
|
| 1065 |
$self->assert_child_ok($pid); |
| 1066 |
|
| 1067 |
test_cleanup($setup->{log_file}, $ex); |
| 1068 |
} |
| 1069 |
|
| 1070 |
sub hiddenstores_timeout_notransfer_bug4035 { |
| 1071 |
my $self = shift; |
| 1072 |
my $tmpdir = $self->{tmpdir}; |
| 1073 |
my $setup = test_setup($tmpdir, 'config'); |
| 1074 |
|
| 1075 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 1076 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 1077 |
|
| 1078 |
my $timeout_noxfer = 2; |
| 1079 |
|
| 1080 |
my $config = { |
| 1081 |
PidFile => $setup->{pid_file}, |
| 1082 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 1083 |
SystemLog => $setup->{log_file}, |
| 1084 |
TraceLog => $setup->{log_file}, |
| 1085 |
Trace => 'timer:20', |
| 1086 |
|
| 1087 |
AuthUserFile => $setup->{auth_user_file}, |
| 1088 |
AuthGroupFile => $setup->{auth_group_file}, |
| 1089 |
AuthOrder => 'mod_auth_file.c', |
| 1090 |
|
| 1091 |
DefaultChdir => '~', |
| 1092 |
HiddenStores => 'on', |
| 1093 |
TimeoutNoTransfer => $timeout_noxfer, |
| 1094 |
|
| 1095 |
IfModules => { |
| 1096 |
'mod_delay.c' => { |
| 1097 |
DelayEngine => 'off', |
| 1098 |
}, |
| 1099 |
}, |
| 1100 |
}; |
| 1101 |
|
| 1102 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 1103 |
$config); |
| 1104 |
|
| 1105 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1106 |
# the child will indicate when it's done with its test by writing a message |
| 1107 |
# to the parent. |
| 1108 |
my ($rfh, $wfh); |
| 1109 |
unless (pipe($rfh, $wfh)) { |
| 1110 |
die("Can't open pipe: $!"); |
| 1111 |
} |
| 1112 |
|
| 1113 |
my $ex; |
| 1114 |
|
| 1115 |
# Fork child |
| 1116 |
$self->handle_sigchld(); |
| 1117 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1118 |
if ($pid) { |
| 1119 |
eval { |
| 1120 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1121 |
$client->login($setup->{user}, $setup->{passwd}); |
| 1122 |
|
| 1123 |
my $conn = $client->stor_raw('test.txt'); |
| 1124 |
unless ($conn) { |
| 1125 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 1126 |
$client->response_msg()); |
| 1127 |
} |
| 1128 |
|
| 1129 |
# Sleep for longer than the TimeoutNoTransfer |
| 1130 |
sleep($timeout_noxfer + 1); |
| 1131 |
|
| 1132 |
my $buf = "Hello, World!\n"; |
| 1133 |
$conn->write($buf, length($buf), 25); |
| 1134 |
|
| 1135 |
unless (-f $hidden_file) { |
| 1136 |
die("File $hidden_file does not exist as expected"); |
| 1137 |
} |
| 1138 |
|
| 1139 |
eval { $conn->close() }; |
| 1140 |
|
| 1141 |
my $resp_code = $client->response_code(); |
| 1142 |
my $resp_msg = $client->response_msg(); |
| 1143 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 1144 |
|
| 1145 |
$client->quit(); |
| 1146 |
|
| 1147 |
if ($^O eq 'darwin') { |
| 1148 |
# MacOSX hack |
| 1149 |
$test_file = ('/private' . $test_file); |
| 1150 |
$hidden_file = ('/private' . $hidden_file); |
| 1151 |
} |
| 1152 |
|
| 1153 |
if (-f $hidden_file) { |
| 1154 |
die("File $hidden_file exists unexpectedly"); |
| 1155 |
} |
| 1156 |
|
| 1157 |
unless (-f $test_file) { |
| 1158 |
die("File $test_file does not exist as expected"); |
| 1159 |
} |
| 1160 |
}; |
| 1161 |
|
| 1162 |
if ($@) { |
| 1163 |
$ex = $@; |
| 1164 |
} |
| 1165 |
|
| 1166 |
$wfh->print("done\n"); |
| 1167 |
$wfh->flush(); |
| 1168 |
|
| 1169 |
} else { |
| 1170 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 1171 |
if ($@) { |
| 1172 |
warn($@); |
| 1173 |
exit 1; |
| 1174 |
} |
| 1175 |
|
| 1176 |
exit 0; |
| 1177 |
} |
| 1178 |
|
| 1179 |
# Stop server |
| 1180 |
server_stop($setup->{pid_file}); |
| 1181 |
|
| 1182 |
$self->assert_child_ok($pid); |
| 1183 |
|
| 1184 |
test_cleanup($setup->{log_file}, $ex); |
| 1185 |
} |
| 1186 |
|
| 1187 |
sub hiddenstores_timeout_stalled_bug4035 { |
| 1188 |
my $self = shift; |
| 1189 |
my $tmpdir = $self->{tmpdir}; |
| 1190 |
my $setup = test_setup($tmpdir, 'config'); |
| 1191 |
|
| 1192 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 1193 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 1194 |
|
| 1195 |
my $timeout_stalled = 2; |
| 1196 |
|
| 1197 |
my $config = { |
| 1198 |
PidFile => $setup->{pid_file}, |
| 1199 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 1200 |
SystemLog => $setup->{log_file}, |
| 1201 |
|
| 1202 |
AuthUserFile => $setup->{auth_user_file}, |
| 1203 |
AuthGroupFile => $setup->{auth_group_file}, |
| 1204 |
AuthOrder => 'mod_auth_file.c', |
| 1205 |
|
| 1206 |
DefaultChdir => '~', |
| 1207 |
HiddenStores => 'on', |
| 1208 |
TimeoutStalled => $timeout_stalled, |
| 1209 |
|
| 1210 |
IfModules => { |
| 1211 |
'mod_delay.c' => { |
| 1212 |
DelayEngine => 'off', |
| 1213 |
}, |
| 1214 |
}, |
| 1215 |
}; |
| 1216 |
|
| 1217 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 1218 |
$config); |
| 1219 |
|
| 1220 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1221 |
# the child will indicate when it's done with its test by writing a message |
| 1222 |
# to the parent. |
| 1223 |
my ($rfh, $wfh); |
| 1224 |
unless (pipe($rfh, $wfh)) { |
| 1225 |
die("Can't open pipe: $!"); |
| 1226 |
} |
| 1227 |
|
| 1228 |
my $ex; |
| 1229 |
|
| 1230 |
# Fork child |
| 1231 |
$self->handle_sigchld(); |
| 1232 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1233 |
if ($pid) { |
| 1234 |
eval { |
| 1235 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1236 |
$client->login($setup->{user}, $setup->{passwd}); |
| 1237 |
|
| 1238 |
my $conn = $client->stor_raw('test.txt'); |
| 1239 |
unless ($conn) { |
| 1240 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 1241 |
$client->response_msg()); |
| 1242 |
} |
| 1243 |
|
| 1244 |
# Sleep for longer than the TimeoutStalled |
| 1245 |
sleep($timeout_stalled + 1); |
| 1246 |
|
| 1247 |
my $buf = "Hello, World!\n"; |
| 1248 |
$conn->write($buf, length($buf), 25); |
| 1249 |
|
| 1250 |
if (-f $hidden_file) { |
| 1251 |
die("File $hidden_file exists unexpectedly"); |
| 1252 |
} |
| 1253 |
|
| 1254 |
eval { $conn->close() }; |
| 1255 |
|
| 1256 |
my $resp_code = $client->response_code(); |
| 1257 |
my $resp_msg = $client->response_msg(); |
| 1258 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 1259 |
|
| 1260 |
eval { $client->quit() }; |
| 1261 |
unless ($@) { |
| 1262 |
die("QUIT succeeded unexpectedly"); |
| 1263 |
} |
| 1264 |
|
| 1265 |
if ($^O eq 'darwin') { |
| 1266 |
# MacOSX hack |
| 1267 |
$test_file = ('/private' . $test_file); |
| 1268 |
$hidden_file = ('/private' . $hidden_file); |
| 1269 |
} |
| 1270 |
|
| 1271 |
if (-f $hidden_file) { |
| 1272 |
die("File $hidden_file exists unexpectedly"); |
| 1273 |
} |
| 1274 |
|
| 1275 |
if (-f $test_file) { |
| 1276 |
die("File $test_file exists unexpectedly"); |
| 1277 |
} |
| 1278 |
}; |
| 1279 |
|
| 1280 |
if ($@) { |
| 1281 |
$ex = $@; |
| 1282 |
} |
| 1283 |
|
| 1284 |
$wfh->print("done\n"); |
| 1285 |
$wfh->flush(); |
| 1286 |
|
| 1287 |
} else { |
| 1288 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 1289 |
if ($@) { |
| 1290 |
warn($@); |
| 1291 |
exit 1; |
| 1292 |
} |
| 1293 |
|
| 1294 |
exit 0; |
| 1295 |
} |
| 1296 |
|
| 1297 |
# Stop server |
| 1298 |
server_stop($setup->{pid_file}); |
| 1299 |
|
| 1300 |
$self->assert_child_ok($pid); |
| 1301 |
|
| 1302 |
test_cleanup($setup->{log_file}, $ex); |
| 1303 |
} |
| 1304 |
|
| 1305 |
sub hiddenstores_timeout_session_bug4035 { |
| 1306 |
my $self = shift; |
| 1307 |
my $tmpdir = $self->{tmpdir}; |
| 1308 |
my $setup = test_setup($tmpdir, 'config'); |
| 1309 |
|
| 1310 |
my $hidden_file = File::Spec->rel2abs("$tmpdir/.in.test.txt."); |
| 1311 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 1312 |
|
| 1313 |
my $timeout_session = 2; |
| 1314 |
|
| 1315 |
my $config = { |
| 1316 |
PidFile => $setup->{pid_file}, |
| 1317 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 1318 |
SystemLog => $setup->{log_file}, |
| 1319 |
TraceLog => $setup->{log_file}, |
| 1320 |
Trace => 'DEFAULT:10', |
| 1321 |
|
| 1322 |
AuthUserFile => $setup->{auth_user_file}, |
| 1323 |
AuthGroupFile => $setup->{auth_group_file}, |
| 1324 |
AuthOrder => 'mod_auth_file.c', |
| 1325 |
|
| 1326 |
DefaultChdir => '~', |
| 1327 |
HiddenStores => 'on', |
| 1328 |
TimeoutSession => $timeout_session, |
| 1329 |
|
| 1330 |
IfModules => { |
| 1331 |
'mod_delay.c' => { |
| 1332 |
DelayEngine => 'off', |
| 1333 |
}, |
| 1334 |
}, |
| 1335 |
}; |
| 1336 |
|
| 1337 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 1338 |
$config); |
| 1339 |
|
| 1340 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1341 |
# the child will indicate when it's done with its test by writing a message |
| 1342 |
# to the parent. |
| 1343 |
my ($rfh, $wfh); |
| 1344 |
unless (pipe($rfh, $wfh)) { |
| 1345 |
die("Can't open pipe: $!"); |
| 1346 |
} |
| 1347 |
|
| 1348 |
my $ex; |
| 1349 |
|
| 1350 |
# Fork child |
| 1351 |
$self->handle_sigchld(); |
| 1352 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1353 |
if ($pid) { |
| 1354 |
eval { |
| 1355 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1356 |
$client->login($setup->{user}, $setup->{passwd}); |
| 1357 |
|
| 1358 |
my $conn = $client->stor_raw('test.txt'); |
| 1359 |
unless ($conn) { |
| 1360 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 1361 |
$client->response_msg()); |
| 1362 |
} |
| 1363 |
|
| 1364 |
# Sleep for longer than the TimeoutSession |
| 1365 |
sleep($timeout_session + 2); |
| 1366 |
|
| 1367 |
my $buf = "Hello, World!\n"; |
| 1368 |
$conn->write($buf, length($buf), 25); |
| 1369 |
|
| 1370 |
eval { $conn->close() }; |
| 1371 |
|
| 1372 |
my $resp_code = $client->response_code(); |
| 1373 |
my $resp_msg = $client->response_msg(); |
| 1374 |
|
| 1375 |
my $expected = 421; |
| 1376 |
$self->assert($expected == $resp_code, |
| 1377 |
test_msg("Expected response code $expected, got $resp_code")); |
| 1378 |
|
| 1379 |
eval { $client->quit() }; |
| 1380 |
unless ($@) { |
| 1381 |
die("QUIT succeeded unexpectedly"); |
| 1382 |
} |
| 1383 |
|
| 1384 |
if ($^O eq 'darwin') { |
| 1385 |
# MacOSX hack |
| 1386 |
$test_file = ('/private' . $test_file); |
| 1387 |
$hidden_file = ('/private' . $hidden_file); |
| 1388 |
} |
| 1389 |
|
| 1390 |
if (-f $hidden_file) { |
| 1391 |
die("File $hidden_file exists unexpectedly"); |
| 1392 |
} |
| 1393 |
|
| 1394 |
if (-f $test_file) { |
| 1395 |
die("File $test_file exists unexpectedly"); |
| 1396 |
} |
| 1397 |
}; |
| 1398 |
|
| 1399 |
if ($@) { |
| 1400 |
$ex = $@; |
| 1401 |
} |
| 1402 |
|
| 1403 |
$wfh->print("done\n"); |
| 1404 |
$wfh->flush(); |
| 1405 |
|
| 1406 |
} else { |
| 1407 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 1408 |
if ($@) { |
| 1409 |
warn($@); |
| 1410 |
exit 1; |
| 1411 |
} |
| 1412 |
|
| 1413 |
exit 0; |
| 1414 |
} |
| 1415 |
|
| 1416 |
# Stop server |
| 1417 |
server_stop($setup->{pid_file}); |
| 1418 |
|
| 1419 |
$self->assert_child_ok($pid); |
| 1420 |
|
| 1421 |
test_cleanup($setup->{log_file}, $ex); |
| 1422 |
} |
| 1423 |
|
| 1424 |
1; |