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