| 1 |
package ProFTPD::Tests::Config::DeferWelcome; |
| 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 |
# Need to document the interaction between DeferWelcome and ServerIdent |
| 18 |
# somewhere; in the mod_core docs for DeferWelcome (need to be added)? |
| 19 |
# |
| 20 |
# Note: "DeferWelcome" is a really bad name/description for what this |
| 21 |
# directive controls. Given ServerIdent's capabilities, is DeferWelcome |
| 22 |
# needed anymore? |
| 23 |
# |
| 24 |
# Specifically: |
| 25 |
# DeferWelcome only used in the following cases: |
| 26 |
# ServerIdent NOT configured OR |
| 27 |
# "ServerIdent on ..." configured |
| 28 |
# |
| 29 |
# if "ServerIdent on" WITH string, then DeferWelcome is ignored (admin |
| 30 |
# configured what they want specifically in the greeting. |
| 31 |
# |
| 32 |
# So "DeferWelcome on/off", with "ServerIdent off", should have no effect. |
| 33 |
# |
| 34 |
# Where exactly does DeferWelcome help? Answer: for the following config: |
| 35 |
# |
| 36 |
# ServerIdent on |
| 37 |
# |
| 38 |
# Usually results in: |
| 39 |
# |
| 40 |
# 220 ProFTPD 1.3.5rc4 Server (ServerName) [1.2.3.4] |
| 41 |
# |
| 42 |
# But: |
| 43 |
# |
| 44 |
# ServerIdent on |
| 45 |
# DeferWelcome on |
| 46 |
# |
| 47 |
# Results in: |
| 48 |
# |
| 49 |
# 220 ProFTPD 1.3.5rc4 Server ready. |
| 50 |
# |
| 51 |
# Exactly the same result can be done using just ServerIdent: |
| 52 |
# |
| 53 |
# ServerIdent on "ProFTPD Server ready." |
| 54 |
# |
| 55 |
# Well, almost. ServerIdent supports the %v variable for ServerName, but |
| 56 |
# currently has no variable for version (e.g. %{version}) or server address. |
| 57 |
# And %L really should reflect a MasquerAddress setting. |
| 58 |
|
| 59 |
my $TESTS = { |
| 60 |
deferwelcome_off_serverident_off => { |
| 61 |
order => ++$order, |
| 62 |
test_class => [qw(forking)], |
| 63 |
}, |
| 64 |
|
| 65 |
deferwelcome_off_serverident_on => { |
| 66 |
order => ++$order, |
| 67 |
test_class => [qw(forking)], |
| 68 |
}, |
| 69 |
|
| 70 |
deferwelcome_on_serverident_off => { |
| 71 |
order => ++$order, |
| 72 |
test_class => [qw(forking)], |
| 73 |
}, |
| 74 |
|
| 75 |
deferwelcome_on_serverident_on => { |
| 76 |
order => ++$order, |
| 77 |
test_class => [qw(forking)], |
| 78 |
}, |
| 79 |
|
| 80 |
deferwelcome_on_serverident_on_custom => { |
| 81 |
order => ++$order, |
| 82 |
test_class => [qw(forking)], |
| 83 |
}, |
| 84 |
|
| 85 |
}; |
| 86 |
|
| 87 |
sub new { |
| 88 |
return shift()->SUPER::new(@_); |
| 89 |
} |
| 90 |
|
| 91 |
sub list_tests { |
| 92 |
return testsuite_get_runnable_tests($TESTS); |
| 93 |
} |
| 94 |
|
| 95 |
sub deferwelcome_off_serverident_off { |
| 96 |
my $self = shift; |
| 97 |
my $tmpdir = $self->{tmpdir}; |
| 98 |
|
| 99 |
my $config_file = "$tmpdir/config.conf"; |
| 100 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 101 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 102 |
|
| 103 |
my $log_file = test_get_logfile(); |
| 104 |
|
| 105 |
my $config = { |
| 106 |
PidFile => $pid_file, |
| 107 |
ScoreboardFile => $scoreboard_file, |
| 108 |
SystemLog => $log_file, |
| 109 |
|
| 110 |
ServerIdent => 'off', |
| 111 |
DeferWelcome => 'off', |
| 112 |
|
| 113 |
IfModules => { |
| 114 |
'mod_delay.c' => { |
| 115 |
DelayEngine => 'off', |
| 116 |
}, |
| 117 |
}, |
| 118 |
}; |
| 119 |
|
| 120 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 121 |
|
| 122 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 123 |
# the child will indicate when it's done with its test by writing a message |
| 124 |
# to the parent. |
| 125 |
my ($rfh, $wfh); |
| 126 |
unless (pipe($rfh, $wfh)) { |
| 127 |
die("Can't open pipe: $!"); |
| 128 |
} |
| 129 |
|
| 130 |
my $ex; |
| 131 |
|
| 132 |
# Fork child |
| 133 |
$self->handle_sigchld(); |
| 134 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 135 |
if ($pid) { |
| 136 |
eval { |
| 137 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 138 |
|
| 139 |
my $resp_code = $client->response_code(); |
| 140 |
my $resp_msg = $client->response_msg(); |
| 141 |
|
| 142 |
my $expected; |
| 143 |
$expected = 220; |
| 144 |
$self->assert($expected == $resp_code, |
| 145 |
test_msg("Expected response code $expected, got $resp_code")); |
| 146 |
|
| 147 |
$expected = '127.0.0.1 FTP server ready'; |
| 148 |
$self->assert($expected eq $resp_msg, |
| 149 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 150 |
}; |
| 151 |
|
| 152 |
if ($@) { |
| 153 |
$ex = $@; |
| 154 |
} |
| 155 |
|
| 156 |
$wfh->print("done\n"); |
| 157 |
$wfh->flush(); |
| 158 |
|
| 159 |
} else { |
| 160 |
eval { server_wait($config_file, $rfh) }; |
| 161 |
if ($@) { |
| 162 |
warn($@); |
| 163 |
exit 1; |
| 164 |
} |
| 165 |
|
| 166 |
exit 0; |
| 167 |
} |
| 168 |
|
| 169 |
# Stop server |
| 170 |
server_stop($pid_file); |
| 171 |
|
| 172 |
$self->assert_child_ok($pid); |
| 173 |
|
| 174 |
if ($ex) { |
| 175 |
test_append_logfile($log_file, $ex); |
| 176 |
unlink($log_file); |
| 177 |
|
| 178 |
die($ex); |
| 179 |
} |
| 180 |
|
| 181 |
unlink($log_file); |
| 182 |
} |
| 183 |
|
| 184 |
sub deferwelcome_off_serverident_on { |
| 185 |
my $self = shift; |
| 186 |
my $tmpdir = $self->{tmpdir}; |
| 187 |
|
| 188 |
my $config_file = "$tmpdir/config.conf"; |
| 189 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 190 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 191 |
|
| 192 |
my $log_file = test_get_logfile(); |
| 193 |
|
| 194 |
my $config = { |
| 195 |
PidFile => $pid_file, |
| 196 |
ScoreboardFile => $scoreboard_file, |
| 197 |
SystemLog => $log_file, |
| 198 |
|
| 199 |
ServerIdent => 'on', |
| 200 |
DeferWelcome => 'off', |
| 201 |
|
| 202 |
IfModules => { |
| 203 |
'mod_delay.c' => { |
| 204 |
DelayEngine => 'off', |
| 205 |
}, |
| 206 |
}, |
| 207 |
}; |
| 208 |
|
| 209 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 210 |
|
| 211 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 212 |
# the child will indicate when it's done with its test by writing a message |
| 213 |
# to the parent. |
| 214 |
my ($rfh, $wfh); |
| 215 |
unless (pipe($rfh, $wfh)) { |
| 216 |
die("Can't open pipe: $!"); |
| 217 |
} |
| 218 |
|
| 219 |
my $ex; |
| 220 |
|
| 221 |
# Fork child |
| 222 |
$self->handle_sigchld(); |
| 223 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 224 |
if ($pid) { |
| 225 |
eval { |
| 226 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 227 |
|
| 228 |
my $resp_code = $client->response_code(); |
| 229 |
my $resp_msg = $client->response_msg(); |
| 230 |
|
| 231 |
my $expected; |
| 232 |
$expected = 220; |
| 233 |
$self->assert($expected == $resp_code, |
| 234 |
test_msg("Expected response code $expected, got $resp_code")); |
| 235 |
|
| 236 |
$expected = 'ProFTPD \S+ Server \(ProFTPD\) \[\S+\]'; |
| 237 |
$self->assert(qr/$expected/, $resp_msg, |
| 238 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 239 |
}; |
| 240 |
|
| 241 |
if ($@) { |
| 242 |
$ex = $@; |
| 243 |
} |
| 244 |
|
| 245 |
$wfh->print("done\n"); |
| 246 |
$wfh->flush(); |
| 247 |
|
| 248 |
} else { |
| 249 |
eval { server_wait($config_file, $rfh) }; |
| 250 |
if ($@) { |
| 251 |
warn($@); |
| 252 |
exit 1; |
| 253 |
} |
| 254 |
|
| 255 |
exit 0; |
| 256 |
} |
| 257 |
|
| 258 |
# Stop server |
| 259 |
server_stop($pid_file); |
| 260 |
|
| 261 |
$self->assert_child_ok($pid); |
| 262 |
|
| 263 |
if ($ex) { |
| 264 |
test_append_logfile($log_file, $ex); |
| 265 |
unlink($log_file); |
| 266 |
|
| 267 |
die($ex); |
| 268 |
} |
| 269 |
|
| 270 |
unlink($log_file); |
| 271 |
} |
| 272 |
|
| 273 |
sub deferwelcome_on_serverident_off { |
| 274 |
my $self = shift; |
| 275 |
my $tmpdir = $self->{tmpdir}; |
| 276 |
|
| 277 |
my $config_file = "$tmpdir/config.conf"; |
| 278 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 279 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 280 |
|
| 281 |
my $log_file = test_get_logfile(); |
| 282 |
|
| 283 |
my $config = { |
| 284 |
PidFile => $pid_file, |
| 285 |
ScoreboardFile => $scoreboard_file, |
| 286 |
SystemLog => $log_file, |
| 287 |
|
| 288 |
ServerIdent => 'off', |
| 289 |
DeferWelcome => 'on', |
| 290 |
|
| 291 |
IfModules => { |
| 292 |
'mod_delay.c' => { |
| 293 |
DelayEngine => 'off', |
| 294 |
}, |
| 295 |
}, |
| 296 |
}; |
| 297 |
|
| 298 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 299 |
|
| 300 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 301 |
# the child will indicate when it's done with its test by writing a message |
| 302 |
# to the parent. |
| 303 |
my ($rfh, $wfh); |
| 304 |
unless (pipe($rfh, $wfh)) { |
| 305 |
die("Can't open pipe: $!"); |
| 306 |
} |
| 307 |
|
| 308 |
my $ex; |
| 309 |
|
| 310 |
# Fork child |
| 311 |
$self->handle_sigchld(); |
| 312 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 313 |
if ($pid) { |
| 314 |
eval { |
| 315 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 316 |
|
| 317 |
my $resp_code = $client->response_code(); |
| 318 |
my $resp_msg = $client->response_msg(); |
| 319 |
|
| 320 |
my $expected; |
| 321 |
$expected = 220; |
| 322 |
$self->assert($expected == $resp_code, |
| 323 |
test_msg("Expected response code $expected, got $resp_code")); |
| 324 |
|
| 325 |
$expected = '127.0.0.1 FTP server ready'; |
| 326 |
$self->assert($expected eq $resp_msg, |
| 327 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 328 |
}; |
| 329 |
|
| 330 |
if ($@) { |
| 331 |
$ex = $@; |
| 332 |
} |
| 333 |
|
| 334 |
$wfh->print("done\n"); |
| 335 |
$wfh->flush(); |
| 336 |
|
| 337 |
} else { |
| 338 |
eval { server_wait($config_file, $rfh) }; |
| 339 |
if ($@) { |
| 340 |
warn($@); |
| 341 |
exit 1; |
| 342 |
} |
| 343 |
|
| 344 |
exit 0; |
| 345 |
} |
| 346 |
|
| 347 |
# Stop server |
| 348 |
server_stop($pid_file); |
| 349 |
|
| 350 |
$self->assert_child_ok($pid); |
| 351 |
|
| 352 |
if ($ex) { |
| 353 |
test_append_logfile($log_file, $ex); |
| 354 |
unlink($log_file); |
| 355 |
|
| 356 |
die($ex); |
| 357 |
} |
| 358 |
|
| 359 |
unlink($log_file); |
| 360 |
} |
| 361 |
|
| 362 |
sub deferwelcome_on_serverident_on { |
| 363 |
my $self = shift; |
| 364 |
my $tmpdir = $self->{tmpdir}; |
| 365 |
|
| 366 |
my $config_file = "$tmpdir/config.conf"; |
| 367 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 368 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 369 |
|
| 370 |
my $log_file = test_get_logfile(); |
| 371 |
|
| 372 |
my $config = { |
| 373 |
PidFile => $pid_file, |
| 374 |
ScoreboardFile => $scoreboard_file, |
| 375 |
SystemLog => $log_file, |
| 376 |
|
| 377 |
ServerIdent => 'on', |
| 378 |
DeferWelcome => 'on', |
| 379 |
|
| 380 |
IfModules => { |
| 381 |
'mod_delay.c' => { |
| 382 |
DelayEngine => 'off', |
| 383 |
}, |
| 384 |
}, |
| 385 |
}; |
| 386 |
|
| 387 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 388 |
|
| 389 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 390 |
# the child will indicate when it's done with its test by writing a message |
| 391 |
# to the parent. |
| 392 |
my ($rfh, $wfh); |
| 393 |
unless (pipe($rfh, $wfh)) { |
| 394 |
die("Can't open pipe: $!"); |
| 395 |
} |
| 396 |
|
| 397 |
my $ex; |
| 398 |
|
| 399 |
# Fork child |
| 400 |
$self->handle_sigchld(); |
| 401 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 402 |
if ($pid) { |
| 403 |
eval { |
| 404 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 405 |
|
| 406 |
my $resp_code = $client->response_code(); |
| 407 |
my $resp_msg = $client->response_msg(); |
| 408 |
|
| 409 |
my $expected; |
| 410 |
$expected = 220; |
| 411 |
$self->assert($expected == $resp_code, |
| 412 |
test_msg("Expected response code $expected, got $resp_code")); |
| 413 |
|
| 414 |
$expected = 'ProFTPD \S+ Server ready\.'; |
| 415 |
$self->assert(qr/$expected/, $resp_msg, |
| 416 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 417 |
}; |
| 418 |
|
| 419 |
if ($@) { |
| 420 |
$ex = $@; |
| 421 |
} |
| 422 |
|
| 423 |
$wfh->print("done\n"); |
| 424 |
$wfh->flush(); |
| 425 |
|
| 426 |
} else { |
| 427 |
eval { server_wait($config_file, $rfh) }; |
| 428 |
if ($@) { |
| 429 |
warn($@); |
| 430 |
exit 1; |
| 431 |
} |
| 432 |
|
| 433 |
exit 0; |
| 434 |
} |
| 435 |
|
| 436 |
# Stop server |
| 437 |
server_stop($pid_file); |
| 438 |
|
| 439 |
$self->assert_child_ok($pid); |
| 440 |
|
| 441 |
if ($ex) { |
| 442 |
test_append_logfile($log_file, $ex); |
| 443 |
unlink($log_file); |
| 444 |
|
| 445 |
die($ex); |
| 446 |
} |
| 447 |
|
| 448 |
unlink($log_file); |
| 449 |
} |
| 450 |
|
| 451 |
sub deferwelcome_on_serverident_on_custom { |
| 452 |
my $self = shift; |
| 453 |
my $tmpdir = $self->{tmpdir}; |
| 454 |
|
| 455 |
my $config_file = "$tmpdir/config.conf"; |
| 456 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 457 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 458 |
|
| 459 |
my $log_file = test_get_logfile(); |
| 460 |
|
| 461 |
my $banner = "Greetings, Stranger. The Notworks are treacherous today."; |
| 462 |
|
| 463 |
my $config = { |
| 464 |
PidFile => $pid_file, |
| 465 |
ScoreboardFile => $scoreboard_file, |
| 466 |
SystemLog => $log_file, |
| 467 |
|
| 468 |
ServerIdent => "on \"$banner\"", |
| 469 |
DeferWelcome => 'on', |
| 470 |
|
| 471 |
IfModules => { |
| 472 |
'mod_delay.c' => { |
| 473 |
DelayEngine => 'off', |
| 474 |
}, |
| 475 |
}, |
| 476 |
}; |
| 477 |
|
| 478 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 479 |
|
| 480 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 481 |
# the child will indicate when it's done with its test by writing a message |
| 482 |
# to the parent. |
| 483 |
my ($rfh, $wfh); |
| 484 |
unless (pipe($rfh, $wfh)) { |
| 485 |
die("Can't open pipe: $!"); |
| 486 |
} |
| 487 |
|
| 488 |
my $ex; |
| 489 |
|
| 490 |
# Fork child |
| 491 |
$self->handle_sigchld(); |
| 492 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 493 |
if ($pid) { |
| 494 |
eval { |
| 495 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 496 |
|
| 497 |
my $resp_code = $client->response_code(); |
| 498 |
my $resp_msg = $client->response_msg(); |
| 499 |
|
| 500 |
my $expected; |
| 501 |
$expected = 220; |
| 502 |
$self->assert($expected == $resp_code, |
| 503 |
test_msg("Expected response code $expected, got $resp_code")); |
| 504 |
|
| 505 |
# Even though we configured "DeferWelcome on", we expect the |
| 506 |
# customised ServerIdent banner to be displayed. |
| 507 |
|
| 508 |
$expected = $banner; |
| 509 |
$self->assert($expected eq $resp_msg, |
| 510 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 511 |
}; |
| 512 |
|
| 513 |
if ($@) { |
| 514 |
$ex = $@; |
| 515 |
} |
| 516 |
|
| 517 |
$wfh->print("done\n"); |
| 518 |
$wfh->flush(); |
| 519 |
|
| 520 |
} else { |
| 521 |
eval { server_wait($config_file, $rfh) }; |
| 522 |
if ($@) { |
| 523 |
warn($@); |
| 524 |
exit 1; |
| 525 |
} |
| 526 |
|
| 527 |
exit 0; |
| 528 |
} |
| 529 |
|
| 530 |
# Stop server |
| 531 |
server_stop($pid_file); |
| 532 |
|
| 533 |
$self->assert_child_ok($pid); |
| 534 |
|
| 535 |
if ($ex) { |
| 536 |
test_append_logfile($log_file, $ex); |
| 537 |
unlink($log_file); |
| 538 |
|
| 539 |
die($ex); |
| 540 |
} |
| 541 |
|
| 542 |
unlink($log_file); |
| 543 |
} |
| 544 |
|
| 545 |
1; |