| 1 |
package ProFTPD::Tests::Commands::FEAT; |
| 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 |
use Socket; |
| 10 |
|
| 11 |
use ProFTPD::TestSuite::FTP; |
| 12 |
use ProFTPD::TestSuite::Utils qw(:auth :config :features :running :test :testsuite); |
| 13 |
|
| 14 |
$| = 1; |
| 15 |
|
| 16 |
my $order = 0; |
| 17 |
|
| 18 |
my $TESTS = { |
| 19 |
feat_ok => { |
| 20 |
order => ++$order, |
| 21 |
test_class => [qw(forking)], |
| 22 |
}, |
| 23 |
|
| 24 |
feat_crlf => { |
| 25 |
order => ++$order, |
| 26 |
test_class => [qw(forking bug)], |
| 27 |
}, |
| 28 |
|
| 29 |
feat_eprt_limit_issue1383 => { |
| 30 |
order => ++$order, |
| 31 |
test_class => [qw(forking bug)], |
| 32 |
}, |
| 33 |
|
| 34 |
feat_epsv_limit_issue1383 => { |
| 35 |
order => ++$order, |
| 36 |
test_class => [qw(forking bug)], |
| 37 |
}, |
| 38 |
|
| 39 |
feat_eprt_epsv_limit_issue1383 => { |
| 40 |
order => ++$order, |
| 41 |
test_class => [qw(forking bug)], |
| 42 |
}, |
| 43 |
|
| 44 |
}; |
| 45 |
|
| 46 |
sub new { |
| 47 |
return shift()->SUPER::new(@_); |
| 48 |
} |
| 49 |
|
| 50 |
sub list_tests { |
| 51 |
return testsuite_get_runnable_tests($TESTS); |
| 52 |
} |
| 53 |
|
| 54 |
sub feat_ok { |
| 55 |
my $self = shift; |
| 56 |
my $tmpdir = $self->{tmpdir}; |
| 57 |
my $setup = test_setup($tmpdir, 'cmds'); |
| 58 |
|
| 59 |
my $config = { |
| 60 |
PidFile => $setup->{pid_file}, |
| 61 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 62 |
SystemLog => $setup->{log_file}, |
| 63 |
|
| 64 |
AuthUserFile => $setup->{auth_user_file}, |
| 65 |
AuthGroupFile => $setup->{auth_group_file}, |
| 66 |
AuthOrder => 'mod_auth_file.c', |
| 67 |
|
| 68 |
IfModules => { |
| 69 |
'mod_delay.c' => { |
| 70 |
DelayEngine => 'off', |
| 71 |
}, |
| 72 |
}, |
| 73 |
}; |
| 74 |
|
| 75 |
# By default, we expect to see 15 lines in the FEAT response |
| 76 |
my $expected_nfeat = 15; |
| 77 |
|
| 78 |
my $have_nls = feature_have_feature_enabled('nls'); |
| 79 |
if ($have_nls) { |
| 80 |
$expected_nfeat += 2; |
| 81 |
} |
| 82 |
|
| 83 |
my $have_site_misc = feature_have_module_compiled('mod_site_misc.c'); |
| 84 |
if ($have_site_misc) { |
| 85 |
# For the following SITE commands added by mod_site_misc: MKDIR, |
| 86 |
# RMDIR, UTIME, and SYMLINK. |
| 87 |
$expected_nfeat += 4; |
| 88 |
} |
| 89 |
|
| 90 |
my $have_copy = feature_have_module_compiled('mod_copy.c'); |
| 91 |
if ($have_copy) { |
| 92 |
# For the following SITE commands added by mod_copy: COPY. |
| 93 |
$expected_nfeat += 1; |
| 94 |
} |
| 95 |
|
| 96 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 97 |
$config); |
| 98 |
|
| 99 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 100 |
# the child will indicate when it's done with its test by writing a message |
| 101 |
# to the parent. |
| 102 |
my ($rfh, $wfh); |
| 103 |
unless (pipe($rfh, $wfh)) { |
| 104 |
die("Can't open pipe: $!"); |
| 105 |
} |
| 106 |
|
| 107 |
my $ex; |
| 108 |
|
| 109 |
# Fork child |
| 110 |
$self->handle_sigchld(); |
| 111 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 112 |
if ($pid) { |
| 113 |
eval { |
| 114 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 115 |
|
| 116 |
$client->feat(); |
| 117 |
my $resp_code = $client->response_code(); |
| 118 |
my $resp_msgs = $client->response_msgs(); |
| 119 |
|
| 120 |
my $expected = 211; |
| 121 |
$self->assert($expected == $resp_code, |
| 122 |
test_msg("Expected response code $expected, got $resp_code")); |
| 123 |
|
| 124 |
my $nfeat = scalar(@$resp_msgs); |
| 125 |
$self->assert($expected_nfeat == $nfeat, |
| 126 |
test_msg("Expected $expected_nfeat features, got $nfeat")); |
| 127 |
|
| 128 |
my $feats = { |
| 129 |
'Features:' => 1, |
| 130 |
' CLNT' => 1, |
| 131 |
' CSID' => 1, |
| 132 |
' EPRT' => 1, |
| 133 |
' EPSV' => 1, |
| 134 |
' HOST' => 1, |
| 135 |
' MDTM' => 1, |
| 136 |
' MFMT' => 1, |
| 137 |
' TVFS' => 1, |
| 138 |
' MFF modify;UNIX.group;UNIX.mode;' => 1, |
| 139 |
' MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.groupname*;UNIX.mode*;UNIX.owner*;UNIX.ownername*;' => 1, |
| 140 |
' RANG STREAM' => 1, |
| 141 |
' REST STREAM' => 1, |
| 142 |
' SIZE' => 1, |
| 143 |
'End' => 1, |
| 144 |
}; |
| 145 |
|
| 146 |
if ($have_nls) { |
| 147 |
$feats->{' UTF8'} = 1; |
| 148 |
|
| 149 |
# One of the following will appear in the FEAT list, depending |
| 150 |
# on the underlying platform. |
| 151 |
$feats->{' LANG en_US'} = 1; |
| 152 |
$feats->{' LANG en-US'} = 1; |
| 153 |
$feats->{' LANG en-US*'} = 1; |
| 154 |
$feats->{' LANG en_US.UTF-8'} = 1; |
| 155 |
$feats->{' LANG en-US.UTF-8'} = 1; |
| 156 |
$feats->{' LANG en-US.UTF-8*'} = 1; |
| 157 |
} |
| 158 |
|
| 159 |
if ($have_site_misc) { |
| 160 |
$feats->{' SITE MKDIR'} = 1; |
| 161 |
$feats->{' SITE RMDIR'} = 1; |
| 162 |
$feats->{' SITE SYMLINK'} = 1; |
| 163 |
$feats->{' SITE UTIME'} = 1; |
| 164 |
} |
| 165 |
|
| 166 |
if ($have_copy) { |
| 167 |
$feats->{' SITE COPY'} = 1; |
| 168 |
} |
| 169 |
|
| 170 |
for (my $i = 0; $i < $nfeat; $i++) { |
| 171 |
$self->assert(defined($feats->{$resp_msgs->[$i]}), , |
| 172 |
test_msg("Unexpected FEAT '$resp_msgs->[$i]'")); |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
if ($@) { |
| 177 |
$ex = $@; |
| 178 |
} |
| 179 |
|
| 180 |
$wfh->print("done\n"); |
| 181 |
$wfh->flush(); |
| 182 |
|
| 183 |
} else { |
| 184 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 185 |
if ($@) { |
| 186 |
warn($@); |
| 187 |
exit 1; |
| 188 |
} |
| 189 |
|
| 190 |
exit 0; |
| 191 |
} |
| 192 |
|
| 193 |
# Stop server |
| 194 |
server_stop($setup->{pid_file}); |
| 195 |
$self->assert_child_ok($pid); |
| 196 |
|
| 197 |
test_cleanup($setup->{log_file}, $ex); |
| 198 |
} |
| 199 |
|
| 200 |
sub feat_crlf { |
| 201 |
my $self = shift; |
| 202 |
my $tmpdir = $self->{tmpdir}; |
| 203 |
my $setup = test_setup($tmpdir, 'cmds'); |
| 204 |
|
| 205 |
my $config = { |
| 206 |
PidFile => $setup->{pid_file}, |
| 207 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 208 |
SystemLog => $setup->{log_file}, |
| 209 |
|
| 210 |
AuthUserFile => $setup->{auth_user_file}, |
| 211 |
AuthGroupFile => $setup->{auth_group_file}, |
| 212 |
AuthOrder => 'mod_auth_file.c', |
| 213 |
|
| 214 |
IfModules => { |
| 215 |
'mod_delay.c' => { |
| 216 |
DelayEngine => 'off', |
| 217 |
}, |
| 218 |
}, |
| 219 |
}; |
| 220 |
|
| 221 |
# By default, we expect to see 12 lines in the FEAT response |
| 222 |
my $expected_nfeat = 12; |
| 223 |
|
| 224 |
my $have_nls = feature_have_feature_enabled('nls'); |
| 225 |
if ($have_nls) { |
| 226 |
$expected_nfeat += 2; |
| 227 |
} |
| 228 |
|
| 229 |
my $have_site_misc = feature_have_module_compiled('mod_site_misc.c'); |
| 230 |
if ($have_site_misc) { |
| 231 |
# For the following SITE commands added by mod_site_misc: MKDIR, |
| 232 |
# RMDIR, UTIME, and SYMLINK. |
| 233 |
$expected_nfeat += 4; |
| 234 |
} |
| 235 |
|
| 236 |
my $have_copy = feature_have_module_compiled('mod_copy.c'); |
| 237 |
if ($have_copy) { |
| 238 |
# For the following SITE commands added by mod_copy: COPY. |
| 239 |
$expected_nfeat += 1; |
| 240 |
} |
| 241 |
|
| 242 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 243 |
$config); |
| 244 |
|
| 245 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 246 |
# the child will indicate when it's done with its test by writing a message |
| 247 |
# to the parent. |
| 248 |
my ($rfh, $wfh); |
| 249 |
unless (pipe($rfh, $wfh)) { |
| 250 |
die("Can't open pipe: $!"); |
| 251 |
} |
| 252 |
|
| 253 |
my $ex; |
| 254 |
|
| 255 |
# Fork child |
| 256 |
$self->handle_sigchld(); |
| 257 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 258 |
if ($pid) { |
| 259 |
eval { |
| 260 |
# Give the server time to start up |
| 261 |
sleep(2); |
| 262 |
|
| 263 |
# To ensure that we are properly using CRLF line endings in the FEAT |
| 264 |
# response, we use the Telnet client, rather than the FTP client. |
| 265 |
my $client_opts = { |
| 266 |
PeerHost => '127.0.0.1', |
| 267 |
PeerPort => $port, |
| 268 |
Proto => 'tcp', |
| 269 |
Type => SOCK_STREAM, |
| 270 |
Timeout => 3, |
| 271 |
}; |
| 272 |
|
| 273 |
my $client = IO::Socket::INET->new(%$client_opts); |
| 274 |
unless ($client) { |
| 275 |
die("Can't connect to 127.0.0.1:$port: $!"); |
| 276 |
} |
| 277 |
|
| 278 |
my $banner = <$client>; |
| 279 |
if ($ENV{TEST_VEBOSE}) { |
| 280 |
print STDERR "# Received banner: $banner"; |
| 281 |
} |
| 282 |
|
| 283 |
my $cmd = "FEAT\r\n"; |
| 284 |
if ($ENV{TEST_VERBOSE}) { |
| 285 |
print STDERR "# Sending command: $cmd"; |
| 286 |
} |
| 287 |
$client->print($cmd); |
| 288 |
$client->flush(); |
| 289 |
|
| 290 |
my $resp = []; |
| 291 |
while (my $line = <$client>) { |
| 292 |
push(@$resp, $line); |
| 293 |
|
| 294 |
if ($ENV{TEST_VERBOSE}) { |
| 295 |
my $line2 = $line; |
| 296 |
$line2 =~ s/\r/\\r/g; |
| 297 |
$line2 =~ s/\n/\\n/g; |
| 298 |
print STDERR "# Received response: $line2\n"; |
| 299 |
} |
| 300 |
|
| 301 |
if ($line =~ /End/i) { |
| 302 |
last; |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
if ($ENV{TEST_VERBOSE}) { |
| 307 |
use Data::Dumper; |
| 308 |
print STDERR "# FEAT:\n", Dumper($resp), "\n"; |
| 309 |
} |
| 310 |
|
| 311 |
$cmd = "QUIT\r\n"; |
| 312 |
if ($ENV{TEST_VERBOSE}) { |
| 313 |
print STDERR "# Sending command: $cmd"; |
| 314 |
} |
| 315 |
$client->print($cmd); |
| 316 |
$client->flush(); |
| 317 |
|
| 318 |
my $quit = <$client>; |
| 319 |
$client->close(); |
| 320 |
|
| 321 |
if ($ENV{TEST_VERBOSE}) { |
| 322 |
print STDERR "# Received response: $quit"; |
| 323 |
} |
| 324 |
|
| 325 |
# Ensure that all FEAT response lines are properly CRLF-terminated, |
| 326 |
# per RFC 2389. |
| 327 |
foreach my $line (@$resp) { |
| 328 |
$self->assert(qr/\r\n$/, $line, |
| 329 |
"Expected FEAT line $line to end with CRLF"); |
| 330 |
} |
| 331 |
}; |
| 332 |
|
| 333 |
if ($@) { |
| 334 |
$ex = $@; |
| 335 |
} |
| 336 |
|
| 337 |
$wfh->print("done\n"); |
| 338 |
$wfh->flush(); |
| 339 |
|
| 340 |
} else { |
| 341 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 342 |
if ($@) { |
| 343 |
warn($@); |
| 344 |
exit 1; |
| 345 |
} |
| 346 |
|
| 347 |
exit 0; |
| 348 |
} |
| 349 |
|
| 350 |
# Stop server |
| 351 |
server_stop($setup->{pid_file}); |
| 352 |
$self->assert_child_ok($pid); |
| 353 |
|
| 354 |
test_cleanup($setup->{log_file}, $ex); |
| 355 |
} |
| 356 |
|
| 357 |
sub feat_eprt_limit_issue1383 { |
| 358 |
my $self = shift; |
| 359 |
my $tmpdir = $self->{tmpdir}; |
| 360 |
my $setup = test_setup($tmpdir, 'cmds'); |
| 361 |
|
| 362 |
my $config = { |
| 363 |
PidFile => $setup->{pid_file}, |
| 364 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 365 |
SystemLog => $setup->{log_file}, |
| 366 |
|
| 367 |
AuthUserFile => $setup->{auth_user_file}, |
| 368 |
AuthGroupFile => $setup->{auth_group_file}, |
| 369 |
AuthOrder => 'mod_auth_file.c', |
| 370 |
|
| 371 |
IfModules => { |
| 372 |
'mod_delay.c' => { |
| 373 |
DelayEngine => 'off', |
| 374 |
}, |
| 375 |
}, |
| 376 |
}; |
| 377 |
|
| 378 |
# By default, we expect to see 14 lines in the FEAT response |
| 379 |
my $expected_nfeat = 14; |
| 380 |
|
| 381 |
my $have_nls = feature_have_feature_enabled('nls'); |
| 382 |
if ($have_nls) { |
| 383 |
$expected_nfeat += 2; |
| 384 |
} |
| 385 |
|
| 386 |
my $have_site_misc = feature_have_module_compiled('mod_site_misc.c'); |
| 387 |
if ($have_site_misc) { |
| 388 |
# For the following SITE commands added by mod_site_misc: MKDIR, |
| 389 |
# RMDIR, UTIME, and SYMLINK. |
| 390 |
$expected_nfeat += 4; |
| 391 |
} |
| 392 |
|
| 393 |
my $have_copy = feature_have_module_compiled('mod_copy.c'); |
| 394 |
if ($have_copy) { |
| 395 |
# For the following SITE commands added by mod_copy: COPY. |
| 396 |
$expected_nfeat += 1; |
| 397 |
} |
| 398 |
|
| 399 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 400 |
$config); |
| 401 |
|
| 402 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 403 |
print $fh <<EOC; |
| 404 |
<Limit EPRT> |
| 405 |
DenyAll |
| 406 |
</Limit> |
| 407 |
EOC |
| 408 |
unless (close($fh)) { |
| 409 |
die("Can't write $setup->{config_file}: $!"); |
| 410 |
} |
| 411 |
|
| 412 |
} else { |
| 413 |
die("Can't open $setup->{config_file}: $!"); |
| 414 |
} |
| 415 |
|
| 416 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 417 |
# the child will indicate when it's done with its test by writing a message |
| 418 |
# to the parent. |
| 419 |
my ($rfh, $wfh); |
| 420 |
unless (pipe($rfh, $wfh)) { |
| 421 |
die("Can't open pipe: $!"); |
| 422 |
} |
| 423 |
|
| 424 |
my $ex; |
| 425 |
|
| 426 |
# Fork child |
| 427 |
$self->handle_sigchld(); |
| 428 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 429 |
if ($pid) { |
| 430 |
eval { |
| 431 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 432 |
|
| 433 |
$client->feat(); |
| 434 |
my $resp_code = $client->response_code(); |
| 435 |
my $resp_msgs = $client->response_msgs(); |
| 436 |
|
| 437 |
my $expected = 211; |
| 438 |
$self->assert($expected == $resp_code, |
| 439 |
test_msg("Expected response code $expected, got $resp_code")); |
| 440 |
|
| 441 |
my $nfeat = scalar(@$resp_msgs); |
| 442 |
$self->assert($expected_nfeat == $nfeat, |
| 443 |
test_msg("Expected $expected_nfeat features, got $nfeat")); |
| 444 |
|
| 445 |
my $feats = { |
| 446 |
'Features:' => 1, |
| 447 |
' CLNT' => 1, |
| 448 |
' CSID' => 1, |
| 449 |
' EPSV' => 1, |
| 450 |
' HOST' => 1, |
| 451 |
' MDTM' => 1, |
| 452 |
' MFMT' => 1, |
| 453 |
' TVFS' => 1, |
| 454 |
' MFF modify;UNIX.group;UNIX.mode;' => 1, |
| 455 |
' MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.groupname*;UNIX.mode*;UNIX.owner*;UNIX.ownername*;' => 1, |
| 456 |
' RANG STREAM' => 1, |
| 457 |
' REST STREAM' => 1, |
| 458 |
' SIZE' => 1, |
| 459 |
'End' => 1, |
| 460 |
}; |
| 461 |
|
| 462 |
if ($have_nls) { |
| 463 |
$feats->{' UTF8'} = 1; |
| 464 |
|
| 465 |
# One of the following will appear in the FEAT list, depending |
| 466 |
# on the underlying platform. |
| 467 |
$feats->{' LANG en_US'} = 1; |
| 468 |
$feats->{' LANG en-US'} = 1; |
| 469 |
$feats->{' LANG en-US*'} = 1; |
| 470 |
$feats->{' LANG en_US.UTF-8'} = 1; |
| 471 |
$feats->{' LANG en-US.UTF-8'} = 1; |
| 472 |
$feats->{' LANG en-US.UTF-8*'} = 1; |
| 473 |
} |
| 474 |
|
| 475 |
if ($have_site_misc) { |
| 476 |
$feats->{' SITE MKDIR'} = 1; |
| 477 |
$feats->{' SITE RMDIR'} = 1; |
| 478 |
$feats->{' SITE SYMLINK'} = 1; |
| 479 |
$feats->{' SITE UTIME'} = 1; |
| 480 |
} |
| 481 |
|
| 482 |
if ($have_copy) { |
| 483 |
$feats->{' SITE COPY'} = 1; |
| 484 |
} |
| 485 |
|
| 486 |
for (my $i = 0; $i < $nfeat; $i++) { |
| 487 |
$self->assert(defined($feats->{$resp_msgs->[$i]}), , |
| 488 |
test_msg("Unexpected FEAT '$resp_msgs->[$i]'")); |
| 489 |
} |
| 490 |
}; |
| 491 |
|
| 492 |
if ($@) { |
| 493 |
$ex = $@; |
| 494 |
} |
| 495 |
|
| 496 |
$wfh->print("done\n"); |
| 497 |
$wfh->flush(); |
| 498 |
|
| 499 |
} else { |
| 500 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 501 |
if ($@) { |
| 502 |
warn($@); |
| 503 |
exit 1; |
| 504 |
} |
| 505 |
|
| 506 |
exit 0; |
| 507 |
} |
| 508 |
|
| 509 |
# Stop server |
| 510 |
server_stop($setup->{pid_file}); |
| 511 |
$self->assert_child_ok($pid); |
| 512 |
|
| 513 |
test_cleanup($setup->{log_file}, $ex); |
| 514 |
} |
| 515 |
|
| 516 |
sub feat_epsv_limit_issue1383 { |
| 517 |
my $self = shift; |
| 518 |
my $tmpdir = $self->{tmpdir}; |
| 519 |
my $setup = test_setup($tmpdir, 'cmds'); |
| 520 |
|
| 521 |
my $config = { |
| 522 |
PidFile => $setup->{pid_file}, |
| 523 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 524 |
SystemLog => $setup->{log_file}, |
| 525 |
|
| 526 |
AuthUserFile => $setup->{auth_user_file}, |
| 527 |
AuthGroupFile => $setup->{auth_group_file}, |
| 528 |
AuthOrder => 'mod_auth_file.c', |
| 529 |
|
| 530 |
IfModules => { |
| 531 |
'mod_delay.c' => { |
| 532 |
DelayEngine => 'off', |
| 533 |
}, |
| 534 |
}, |
| 535 |
}; |
| 536 |
|
| 537 |
# By default, we expect to see 14 lines in the FEAT response |
| 538 |
my $expected_nfeat = 14; |
| 539 |
|
| 540 |
my $have_nls = feature_have_feature_enabled('nls'); |
| 541 |
if ($have_nls) { |
| 542 |
$expected_nfeat += 2; |
| 543 |
} |
| 544 |
|
| 545 |
my $have_site_misc = feature_have_module_compiled('mod_site_misc.c'); |
| 546 |
if ($have_site_misc) { |
| 547 |
# For the following SITE commands added by mod_site_misc: MKDIR, |
| 548 |
# RMDIR, UTIME, and SYMLINK. |
| 549 |
$expected_nfeat += 4; |
| 550 |
} |
| 551 |
|
| 552 |
my $have_copy = feature_have_module_compiled('mod_copy.c'); |
| 553 |
if ($have_copy) { |
| 554 |
# For the following SITE commands added by mod_copy: COPY. |
| 555 |
$expected_nfeat += 1; |
| 556 |
} |
| 557 |
|
| 558 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 559 |
$config); |
| 560 |
|
| 561 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 562 |
print $fh <<EOC; |
| 563 |
<Limit EPSV> |
| 564 |
DenyAll |
| 565 |
</Limit> |
| 566 |
EOC |
| 567 |
unless (close($fh)) { |
| 568 |
die("Can't write $setup->{config_file}: $!"); |
| 569 |
} |
| 570 |
|
| 571 |
} else { |
| 572 |
die("Can't open $setup->{config_file}: $!"); |
| 573 |
} |
| 574 |
|
| 575 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 576 |
# the child will indicate when it's done with its test by writing a message |
| 577 |
# to the parent. |
| 578 |
my ($rfh, $wfh); |
| 579 |
unless (pipe($rfh, $wfh)) { |
| 580 |
die("Can't open pipe: $!"); |
| 581 |
} |
| 582 |
|
| 583 |
my $ex; |
| 584 |
|
| 585 |
# Fork child |
| 586 |
$self->handle_sigchld(); |
| 587 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 588 |
if ($pid) { |
| 589 |
eval { |
| 590 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 591 |
|
| 592 |
$client->feat(); |
| 593 |
my $resp_code = $client->response_code(); |
| 594 |
my $resp_msgs = $client->response_msgs(); |
| 595 |
|
| 596 |
my $expected = 211; |
| 597 |
$self->assert($expected == $resp_code, |
| 598 |
test_msg("Expected response code $expected, got $resp_code")); |
| 599 |
|
| 600 |
my $nfeat = scalar(@$resp_msgs); |
| 601 |
$self->assert($expected_nfeat == $nfeat, |
| 602 |
test_msg("Expected $expected_nfeat features, got $nfeat")); |
| 603 |
|
| 604 |
my $feats = { |
| 605 |
'Features:' => 1, |
| 606 |
' CLNT' => 1, |
| 607 |
' CSID' => 1, |
| 608 |
' EPRT' => 1, |
| 609 |
' HOST' => 1, |
| 610 |
' MDTM' => 1, |
| 611 |
' MFMT' => 1, |
| 612 |
' TVFS' => 1, |
| 613 |
' MFF modify;UNIX.group;UNIX.mode;' => 1, |
| 614 |
' MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.groupname*;UNIX.mode*;UNIX.owner*;UNIX.ownername*;' => 1, |
| 615 |
' RANG STREAM' => 1, |
| 616 |
' REST STREAM' => 1, |
| 617 |
' SIZE' => 1, |
| 618 |
'End' => 1, |
| 619 |
}; |
| 620 |
|
| 621 |
if ($have_nls) { |
| 622 |
$feats->{' UTF8'} = 1; |
| 623 |
|
| 624 |
# One of the following will appear in the FEAT list, depending |
| 625 |
# on the underlying platform. |
| 626 |
$feats->{' LANG en_US'} = 1; |
| 627 |
$feats->{' LANG en-US'} = 1; |
| 628 |
$feats->{' LANG en-US*'} = 1; |
| 629 |
$feats->{' LANG en_US.UTF-8'} = 1; |
| 630 |
$feats->{' LANG en-US.UTF-8'} = 1; |
| 631 |
$feats->{' LANG en-US.UTF-8*'} = 1; |
| 632 |
} |
| 633 |
|
| 634 |
if ($have_site_misc) { |
| 635 |
$feats->{' SITE MKDIR'} = 1; |
| 636 |
$feats->{' SITE RMDIR'} = 1; |
| 637 |
$feats->{' SITE SYMLINK'} = 1; |
| 638 |
$feats->{' SITE UTIME'} = 1; |
| 639 |
} |
| 640 |
|
| 641 |
if ($have_copy) { |
| 642 |
$feats->{' SITE COPY'} = 1; |
| 643 |
} |
| 644 |
|
| 645 |
for (my $i = 0; $i < $nfeat; $i++) { |
| 646 |
$self->assert(defined($feats->{$resp_msgs->[$i]}), , |
| 647 |
test_msg("Unexpected FEAT '$resp_msgs->[$i]'")); |
| 648 |
} |
| 649 |
}; |
| 650 |
|
| 651 |
if ($@) { |
| 652 |
$ex = $@; |
| 653 |
} |
| 654 |
|
| 655 |
$wfh->print("done\n"); |
| 656 |
$wfh->flush(); |
| 657 |
|
| 658 |
} else { |
| 659 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 660 |
if ($@) { |
| 661 |
warn($@); |
| 662 |
exit 1; |
| 663 |
} |
| 664 |
|
| 665 |
exit 0; |
| 666 |
} |
| 667 |
|
| 668 |
# Stop server |
| 669 |
server_stop($setup->{pid_file}); |
| 670 |
$self->assert_child_ok($pid); |
| 671 |
|
| 672 |
test_cleanup($setup->{log_file}, $ex); |
| 673 |
} |
| 674 |
|
| 675 |
sub feat_eprt_epsv_limit_issue1383 { |
| 676 |
my $self = shift; |
| 677 |
my $tmpdir = $self->{tmpdir}; |
| 678 |
my $setup = test_setup($tmpdir, 'cmds'); |
| 679 |
|
| 680 |
my $config = { |
| 681 |
PidFile => $setup->{pid_file}, |
| 682 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 683 |
SystemLog => $setup->{log_file}, |
| 684 |
|
| 685 |
AuthUserFile => $setup->{auth_user_file}, |
| 686 |
AuthGroupFile => $setup->{auth_group_file}, |
| 687 |
AuthOrder => 'mod_auth_file.c', |
| 688 |
|
| 689 |
IfModules => { |
| 690 |
'mod_delay.c' => { |
| 691 |
DelayEngine => 'off', |
| 692 |
}, |
| 693 |
}, |
| 694 |
}; |
| 695 |
|
| 696 |
# By default, we expect to see 13 lines in the FEAT response |
| 697 |
my $expected_nfeat = 13; |
| 698 |
|
| 699 |
my $have_nls = feature_have_feature_enabled('nls'); |
| 700 |
if ($have_nls) { |
| 701 |
$expected_nfeat += 2; |
| 702 |
} |
| 703 |
|
| 704 |
my $have_site_misc = feature_have_module_compiled('mod_site_misc.c'); |
| 705 |
if ($have_site_misc) { |
| 706 |
# For the following SITE commands added by mod_site_misc: MKDIR, |
| 707 |
# RMDIR, UTIME, and SYMLINK. |
| 708 |
$expected_nfeat += 4; |
| 709 |
} |
| 710 |
|
| 711 |
my $have_copy = feature_have_module_compiled('mod_copy.c'); |
| 712 |
if ($have_copy) { |
| 713 |
# For the following SITE commands added by mod_copy: COPY. |
| 714 |
$expected_nfeat += 1; |
| 715 |
} |
| 716 |
|
| 717 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 718 |
$config); |
| 719 |
|
| 720 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 721 |
print $fh <<EOC; |
| 722 |
<Limit EPRT EPSV> |
| 723 |
DenyAll |
| 724 |
</Limit> |
| 725 |
EOC |
| 726 |
unless (close($fh)) { |
| 727 |
die("Can't write $setup->{config_file}: $!"); |
| 728 |
} |
| 729 |
|
| 730 |
} else { |
| 731 |
die("Can't open $setup->{config_file}: $!"); |
| 732 |
} |
| 733 |
|
| 734 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 735 |
# the child will indicate when it's done with its test by writing a message |
| 736 |
# to the parent. |
| 737 |
my ($rfh, $wfh); |
| 738 |
unless (pipe($rfh, $wfh)) { |
| 739 |
die("Can't open pipe: $!"); |
| 740 |
} |
| 741 |
|
| 742 |
my $ex; |
| 743 |
|
| 744 |
# Fork child |
| 745 |
$self->handle_sigchld(); |
| 746 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 747 |
if ($pid) { |
| 748 |
eval { |
| 749 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 750 |
|
| 751 |
$client->feat(); |
| 752 |
my $resp_code = $client->response_code(); |
| 753 |
my $resp_msgs = $client->response_msgs(); |
| 754 |
|
| 755 |
my $expected = 211; |
| 756 |
$self->assert($expected == $resp_code, |
| 757 |
test_msg("Expected response code $expected, got $resp_code")); |
| 758 |
|
| 759 |
my $nfeat = scalar(@$resp_msgs); |
| 760 |
$self->assert($expected_nfeat == $nfeat, |
| 761 |
test_msg("Expected $expected_nfeat features, got $nfeat")); |
| 762 |
|
| 763 |
my $feats = { |
| 764 |
'Features:' => 1, |
| 765 |
' CLNT' => 1, |
| 766 |
' CSID' => 1, |
| 767 |
' HOST' => 1, |
| 768 |
' MDTM' => 1, |
| 769 |
' MFMT' => 1, |
| 770 |
' TVFS' => 1, |
| 771 |
' MFF modify;UNIX.group;UNIX.mode;' => 1, |
| 772 |
' MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.groupname*;UNIX.mode*;UNIX.owner*;UNIX.ownername*;' => 1, |
| 773 |
' RANG STREAM' => 1, |
| 774 |
' REST STREAM' => 1, |
| 775 |
' SIZE' => 1, |
| 776 |
'End' => 1, |
| 777 |
}; |
| 778 |
|
| 779 |
if ($have_nls) { |
| 780 |
$feats->{' UTF8'} = 1; |
| 781 |
|
| 782 |
# One of the following will appear in the FEAT list, depending |
| 783 |
# on the underlying platform. |
| 784 |
$feats->{' LANG en_US'} = 1; |
| 785 |
$feats->{' LANG en-US'} = 1; |
| 786 |
$feats->{' LANG en-US*'} = 1; |
| 787 |
$feats->{' LANG en_US.UTF-8'} = 1; |
| 788 |
$feats->{' LANG en-US.UTF-8'} = 1; |
| 789 |
$feats->{' LANG en-US.UTF-8*'} = 1; |
| 790 |
} |
| 791 |
|
| 792 |
if ($have_site_misc) { |
| 793 |
$feats->{' SITE MKDIR'} = 1; |
| 794 |
$feats->{' SITE RMDIR'} = 1; |
| 795 |
$feats->{' SITE SYMLINK'} = 1; |
| 796 |
$feats->{' SITE UTIME'} = 1; |
| 797 |
} |
| 798 |
|
| 799 |
if ($have_copy) { |
| 800 |
$feats->{' SITE COPY'} = 1; |
| 801 |
} |
| 802 |
|
| 803 |
for (my $i = 0; $i < $nfeat; $i++) { |
| 804 |
$self->assert(defined($feats->{$resp_msgs->[$i]}), , |
| 805 |
test_msg("Unexpected FEAT '$resp_msgs->[$i]'")); |
| 806 |
} |
| 807 |
}; |
| 808 |
|
| 809 |
if ($@) { |
| 810 |
$ex = $@; |
| 811 |
} |
| 812 |
|
| 813 |
$wfh->print("done\n"); |
| 814 |
$wfh->flush(); |
| 815 |
|
| 816 |
} else { |
| 817 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 818 |
if ($@) { |
| 819 |
warn($@); |
| 820 |
exit 1; |
| 821 |
} |
| 822 |
|
| 823 |
exit 0; |
| 824 |
} |
| 825 |
|
| 826 |
# Stop server |
| 827 |
server_stop($setup->{pid_file}); |
| 828 |
$self->assert_child_ok($pid); |
| 829 |
|
| 830 |
test_cleanup($setup->{log_file}, $ex); |
| 831 |
} |
| 832 |
|
| 833 |
1; |