| 1 |
package ProFTPD::Tests::Config::Protocols; |
| 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 |
protocols_default => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
protocols_with_ftp => { |
| 24 |
order => ++$order, |
| 25 |
test_class => [qw(forking)], |
| 26 |
}, |
| 27 |
|
| 28 |
protocols_without_ftp => { |
| 29 |
order => ++$order, |
| 30 |
test_class => [qw(forking)], |
| 31 |
}, |
| 32 |
|
| 33 |
protocols_ifsess_with_ftp => { |
| 34 |
order => ++$order, |
| 35 |
test_class => [qw(forking mod_ifsession)], |
| 36 |
}, |
| 37 |
|
| 38 |
protocols_ifsess_without_ftp => { |
| 39 |
order => ++$order, |
| 40 |
test_class => [qw(forking mod_ifsession)], |
| 41 |
}, |
| 42 |
|
| 43 |
}; |
| 44 |
|
| 45 |
sub new { |
| 46 |
return shift()->SUPER::new(@_); |
| 47 |
} |
| 48 |
|
| 49 |
sub list_tests { |
| 50 |
return testsuite_get_runnable_tests($TESTS); |
| 51 |
} |
| 52 |
|
| 53 |
sub protocols_default { |
| 54 |
my $self = shift; |
| 55 |
my $tmpdir = $self->{tmpdir}; |
| 56 |
|
| 57 |
my $config_file = "$tmpdir/config.conf"; |
| 58 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 59 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 60 |
|
| 61 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 62 |
|
| 63 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 64 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 65 |
|
| 66 |
my $user = 'proftpd'; |
| 67 |
my $passwd = 'test'; |
| 68 |
my $group = 'ftpd'; |
| 69 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 70 |
my $uid = 500; |
| 71 |
my $gid = 500; |
| 72 |
|
| 73 |
# Make sure that, if we're running as root, that the home directory has |
| 74 |
# permissions/privs set for the account we create |
| 75 |
if ($< == 0) { |
| 76 |
unless (chmod(0755, $home_dir)) { |
| 77 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 78 |
} |
| 79 |
|
| 80 |
unless (chown($uid, $gid, $home_dir)) { |
| 81 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 86 |
'/bin/bash'); |
| 87 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 88 |
|
| 89 |
my $config = { |
| 90 |
PidFile => $pid_file, |
| 91 |
ScoreboardFile => $scoreboard_file, |
| 92 |
SystemLog => $log_file, |
| 93 |
|
| 94 |
AuthUserFile => $auth_user_file, |
| 95 |
AuthGroupFile => $auth_group_file, |
| 96 |
AuthOrder => 'mod_auth_file.c', |
| 97 |
|
| 98 |
IfModules => { |
| 99 |
'mod_delay.c' => { |
| 100 |
DelayEngine => 'off', |
| 101 |
}, |
| 102 |
}, |
| 103 |
}; |
| 104 |
|
| 105 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 106 |
|
| 107 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 108 |
# the child will indicate when it's done with its test by writing a message |
| 109 |
# to the parent. |
| 110 |
my ($rfh, $wfh); |
| 111 |
unless (pipe($rfh, $wfh)) { |
| 112 |
die("Can't open pipe: $!"); |
| 113 |
} |
| 114 |
|
| 115 |
my $ex; |
| 116 |
|
| 117 |
# Fork child |
| 118 |
$self->handle_sigchld(); |
| 119 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 120 |
if ($pid) { |
| 121 |
eval { |
| 122 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 123 |
$client->login($user, $passwd); |
| 124 |
|
| 125 |
my ($resp_code, $resp_msg) = $client->syst(); |
| 126 |
|
| 127 |
my $expected; |
| 128 |
|
| 129 |
$expected = 215; |
| 130 |
$self->assert($expected == $resp_code, |
| 131 |
test_msg("Expected $expected, got $resp_code")); |
| 132 |
|
| 133 |
$expected = "UNIX Type: L8"; |
| 134 |
$self->assert($expected eq $resp_msg, |
| 135 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 136 |
|
| 137 |
$client->quit(); |
| 138 |
}; |
| 139 |
|
| 140 |
if ($@) { |
| 141 |
$ex = $@; |
| 142 |
} |
| 143 |
|
| 144 |
$wfh->print("done\n"); |
| 145 |
$wfh->flush(); |
| 146 |
|
| 147 |
} else { |
| 148 |
eval { server_wait($config_file, $rfh) }; |
| 149 |
if ($@) { |
| 150 |
warn($@); |
| 151 |
exit 1; |
| 152 |
} |
| 153 |
|
| 154 |
exit 0; |
| 155 |
} |
| 156 |
|
| 157 |
# Stop server |
| 158 |
server_stop($pid_file); |
| 159 |
|
| 160 |
$self->assert_child_ok($pid); |
| 161 |
|
| 162 |
if ($ex) { |
| 163 |
die($ex); |
| 164 |
} |
| 165 |
|
| 166 |
unlink($log_file); |
| 167 |
} |
| 168 |
|
| 169 |
sub protocols_with_ftp { |
| 170 |
my $self = shift; |
| 171 |
my $tmpdir = $self->{tmpdir}; |
| 172 |
|
| 173 |
my $config_file = "$tmpdir/config.conf"; |
| 174 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 175 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 176 |
|
| 177 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 178 |
|
| 179 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 180 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 181 |
|
| 182 |
my $user = 'proftpd'; |
| 183 |
my $passwd = 'test'; |
| 184 |
my $group = 'ftpd'; |
| 185 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 186 |
my $uid = 500; |
| 187 |
my $gid = 500; |
| 188 |
|
| 189 |
# Make sure that, if we're running as root, that the home directory has |
| 190 |
# permissions/privs set for the account we create |
| 191 |
if ($< == 0) { |
| 192 |
unless (chmod(0755, $home_dir)) { |
| 193 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 194 |
} |
| 195 |
|
| 196 |
unless (chown($uid, $gid, $home_dir)) { |
| 197 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 202 |
'/bin/bash'); |
| 203 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 204 |
|
| 205 |
my $config = { |
| 206 |
PidFile => $pid_file, |
| 207 |
ScoreboardFile => $scoreboard_file, |
| 208 |
SystemLog => $log_file, |
| 209 |
|
| 210 |
AuthUserFile => $auth_user_file, |
| 211 |
AuthGroupFile => $auth_group_file, |
| 212 |
AuthOrder => 'mod_auth_file.c', |
| 213 |
|
| 214 |
Protocols => 'ftp', |
| 215 |
|
| 216 |
IfModules => { |
| 217 |
'mod_delay.c' => { |
| 218 |
DelayEngine => 'off', |
| 219 |
}, |
| 220 |
}, |
| 221 |
}; |
| 222 |
|
| 223 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 224 |
|
| 225 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 226 |
# the child will indicate when it's done with its test by writing a message |
| 227 |
# to the parent. |
| 228 |
my ($rfh, $wfh); |
| 229 |
unless (pipe($rfh, $wfh)) { |
| 230 |
die("Can't open pipe: $!"); |
| 231 |
} |
| 232 |
|
| 233 |
my $ex; |
| 234 |
|
| 235 |
# Fork child |
| 236 |
$self->handle_sigchld(); |
| 237 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 238 |
if ($pid) { |
| 239 |
eval { |
| 240 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 241 |
$client->login($user, $passwd); |
| 242 |
|
| 243 |
my ($resp_code, $resp_msg) = $client->syst(); |
| 244 |
|
| 245 |
my $expected; |
| 246 |
|
| 247 |
$expected = 215; |
| 248 |
$self->assert($expected == $resp_code, |
| 249 |
test_msg("Expected $expected, got $resp_code")); |
| 250 |
|
| 251 |
$expected = "UNIX Type: L8"; |
| 252 |
$self->assert($expected eq $resp_msg, |
| 253 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 254 |
|
| 255 |
$client->quit(); |
| 256 |
}; |
| 257 |
|
| 258 |
if ($@) { |
| 259 |
$ex = $@; |
| 260 |
} |
| 261 |
|
| 262 |
$wfh->print("done\n"); |
| 263 |
$wfh->flush(); |
| 264 |
|
| 265 |
} else { |
| 266 |
eval { server_wait($config_file, $rfh) }; |
| 267 |
if ($@) { |
| 268 |
warn($@); |
| 269 |
exit 1; |
| 270 |
} |
| 271 |
|
| 272 |
exit 0; |
| 273 |
} |
| 274 |
|
| 275 |
# Stop server |
| 276 |
server_stop($pid_file); |
| 277 |
|
| 278 |
$self->assert_child_ok($pid); |
| 279 |
|
| 280 |
if ($ex) { |
| 281 |
die($ex); |
| 282 |
} |
| 283 |
|
| 284 |
unlink($log_file); |
| 285 |
} |
| 286 |
|
| 287 |
sub protocols_without_ftp { |
| 288 |
my $self = shift; |
| 289 |
my $tmpdir = $self->{tmpdir}; |
| 290 |
|
| 291 |
my $config_file = "$tmpdir/config.conf"; |
| 292 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 293 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 294 |
|
| 295 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 296 |
|
| 297 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 298 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 299 |
|
| 300 |
my $user = 'proftpd'; |
| 301 |
my $passwd = 'test'; |
| 302 |
my $group = 'ftpd'; |
| 303 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 304 |
my $uid = 500; |
| 305 |
my $gid = 500; |
| 306 |
|
| 307 |
# Make sure that, if we're running as root, that the home directory has |
| 308 |
# permissions/privs set for the account we create |
| 309 |
if ($< == 0) { |
| 310 |
unless (chmod(0755, $home_dir)) { |
| 311 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 312 |
} |
| 313 |
|
| 314 |
unless (chown($uid, $gid, $home_dir)) { |
| 315 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 320 |
'/bin/bash'); |
| 321 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 322 |
|
| 323 |
my $config = { |
| 324 |
PidFile => $pid_file, |
| 325 |
ScoreboardFile => $scoreboard_file, |
| 326 |
SystemLog => $log_file, |
| 327 |
|
| 328 |
AuthUserFile => $auth_user_file, |
| 329 |
AuthGroupFile => $auth_group_file, |
| 330 |
AuthOrder => 'mod_auth_file.c', |
| 331 |
|
| 332 |
Protocols => 'foo bar', |
| 333 |
|
| 334 |
IfModules => { |
| 335 |
'mod_delay.c' => { |
| 336 |
DelayEngine => 'off', |
| 337 |
}, |
| 338 |
}, |
| 339 |
}; |
| 340 |
|
| 341 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 342 |
|
| 343 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 344 |
# the child will indicate when it's done with its test by writing a message |
| 345 |
# to the parent. |
| 346 |
my ($rfh, $wfh); |
| 347 |
unless (pipe($rfh, $wfh)) { |
| 348 |
die("Can't open pipe: $!"); |
| 349 |
} |
| 350 |
|
| 351 |
my $ex; |
| 352 |
|
| 353 |
# Fork child |
| 354 |
$self->handle_sigchld(); |
| 355 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 356 |
if ($pid) { |
| 357 |
eval { |
| 358 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 359 |
|
| 360 |
eval { $client->login($user, $passwd) }; |
| 361 |
unless ($@) { |
| 362 |
die("Login succeeded unexpectedly"); |
| 363 |
} |
| 364 |
|
| 365 |
my $resp_code = $client->response_code(); |
| 366 |
my $resp_msg = $client->response_msg(); |
| 367 |
|
| 368 |
my $expected; |
| 369 |
|
| 370 |
$expected = 530; |
| 371 |
$self->assert($expected == $resp_code, |
| 372 |
test_msg("Expected $expected, got $resp_code")); |
| 373 |
|
| 374 |
$expected = "Login incorrect."; |
| 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 |
die($ex); |
| 403 |
} |
| 404 |
|
| 405 |
unlink($log_file); |
| 406 |
} |
| 407 |
|
| 408 |
sub protocols_ifsess_with_ftp { |
| 409 |
my $self = shift; |
| 410 |
my $tmpdir = $self->{tmpdir}; |
| 411 |
|
| 412 |
my $config_file = "$tmpdir/config.conf"; |
| 413 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 414 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 415 |
|
| 416 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 417 |
|
| 418 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 419 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 420 |
|
| 421 |
my $user = 'proftpd'; |
| 422 |
my $passwd = 'test'; |
| 423 |
my $group = 'ftpd'; |
| 424 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 425 |
my $uid = 500; |
| 426 |
my $gid = 500; |
| 427 |
|
| 428 |
# Make sure that, if we're running as root, that the home directory has |
| 429 |
# permissions/privs set for the account we create |
| 430 |
if ($< == 0) { |
| 431 |
unless (chmod(0755, $home_dir)) { |
| 432 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 433 |
} |
| 434 |
|
| 435 |
unless (chown($uid, $gid, $home_dir)) { |
| 436 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 441 |
'/bin/bash'); |
| 442 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 443 |
|
| 444 |
my $config = { |
| 445 |
PidFile => $pid_file, |
| 446 |
ScoreboardFile => $scoreboard_file, |
| 447 |
SystemLog => $log_file, |
| 448 |
|
| 449 |
AuthUserFile => $auth_user_file, |
| 450 |
AuthGroupFile => $auth_group_file, |
| 451 |
AuthOrder => 'mod_auth_file.c', |
| 452 |
|
| 453 |
IfModules => { |
| 454 |
'mod_delay.c' => { |
| 455 |
DelayEngine => 'off', |
| 456 |
}, |
| 457 |
}, |
| 458 |
}; |
| 459 |
|
| 460 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 461 |
|
| 462 |
if (open(my $fh, ">> $config_file")) { |
| 463 |
print $fh <<EOC; |
| 464 |
<IfModule mod_ifsession.c> |
| 465 |
<IfUser foo> |
| 466 |
Protocols ftps sftp |
| 467 |
</IfUser> |
| 468 |
|
| 469 |
<IfUser $user> |
| 470 |
Protocols ftp |
| 471 |
</IfUser> |
| 472 |
</IfModule> |
| 473 |
EOC |
| 474 |
unless (close($fh)) { |
| 475 |
die("Can't write $config_file: $!"); |
| 476 |
} |
| 477 |
|
| 478 |
} else { |
| 479 |
die("Can't open $config_file: $!"); |
| 480 |
} |
| 481 |
|
| 482 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 483 |
# the child will indicate when it's done with its test by writing a message |
| 484 |
# to the parent. |
| 485 |
my ($rfh, $wfh); |
| 486 |
unless (pipe($rfh, $wfh)) { |
| 487 |
die("Can't open pipe: $!"); |
| 488 |
} |
| 489 |
|
| 490 |
my $ex; |
| 491 |
|
| 492 |
# Fork child |
| 493 |
$self->handle_sigchld(); |
| 494 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 495 |
if ($pid) { |
| 496 |
eval { |
| 497 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 498 |
$client->login($user, $passwd); |
| 499 |
|
| 500 |
my ($resp_code, $resp_msg) = $client->syst(); |
| 501 |
|
| 502 |
my $expected; |
| 503 |
|
| 504 |
$expected = 215; |
| 505 |
$self->assert($expected == $resp_code, |
| 506 |
test_msg("Expected $expected, got $resp_code")); |
| 507 |
|
| 508 |
$expected = "UNIX Type: L8"; |
| 509 |
$self->assert($expected eq $resp_msg, |
| 510 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 511 |
|
| 512 |
$client->quit(); |
| 513 |
}; |
| 514 |
|
| 515 |
if ($@) { |
| 516 |
$ex = $@; |
| 517 |
} |
| 518 |
|
| 519 |
$wfh->print("done\n"); |
| 520 |
$wfh->flush(); |
| 521 |
|
| 522 |
} else { |
| 523 |
eval { server_wait($config_file, $rfh) }; |
| 524 |
if ($@) { |
| 525 |
warn($@); |
| 526 |
exit 1; |
| 527 |
} |
| 528 |
|
| 529 |
exit 0; |
| 530 |
} |
| 531 |
|
| 532 |
# Stop server |
| 533 |
server_stop($pid_file); |
| 534 |
|
| 535 |
$self->assert_child_ok($pid); |
| 536 |
|
| 537 |
if ($ex) { |
| 538 |
die($ex); |
| 539 |
} |
| 540 |
|
| 541 |
unlink($log_file); |
| 542 |
} |
| 543 |
|
| 544 |
sub protocols_ifsess_without_ftp { |
| 545 |
my $self = shift; |
| 546 |
my $tmpdir = $self->{tmpdir}; |
| 547 |
|
| 548 |
my $config_file = "$tmpdir/config.conf"; |
| 549 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 550 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 551 |
|
| 552 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 553 |
|
| 554 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 555 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 556 |
|
| 557 |
my $user = 'proftpd'; |
| 558 |
my $passwd = 'test'; |
| 559 |
my $group = 'ftpd'; |
| 560 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 561 |
my $uid = 500; |
| 562 |
my $gid = 500; |
| 563 |
|
| 564 |
# Make sure that, if we're running as root, that the home directory has |
| 565 |
# permissions/privs set for the account we create |
| 566 |
if ($< == 0) { |
| 567 |
unless (chmod(0755, $home_dir)) { |
| 568 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 569 |
} |
| 570 |
|
| 571 |
unless (chown($uid, $gid, $home_dir)) { |
| 572 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 577 |
'/bin/bash'); |
| 578 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 579 |
|
| 580 |
my $config = { |
| 581 |
PidFile => $pid_file, |
| 582 |
ScoreboardFile => $scoreboard_file, |
| 583 |
SystemLog => $log_file, |
| 584 |
|
| 585 |
AuthUserFile => $auth_user_file, |
| 586 |
AuthGroupFile => $auth_group_file, |
| 587 |
AuthOrder => 'mod_auth_file.c', |
| 588 |
|
| 589 |
IfModules => { |
| 590 |
'mod_delay.c' => { |
| 591 |
DelayEngine => 'off', |
| 592 |
}, |
| 593 |
}, |
| 594 |
}; |
| 595 |
|
| 596 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 597 |
|
| 598 |
if (open(my $fh, ">> $config_file")) { |
| 599 |
print $fh <<EOC; |
| 600 |
<IfModule mod_ifsession.c> |
| 601 |
<IfUser foo> |
| 602 |
Protocols ftps sftp |
| 603 |
</IfUser> |
| 604 |
|
| 605 |
<IfUser $user> |
| 606 |
Protocols scp |
| 607 |
</IfUser> |
| 608 |
</IfModule> |
| 609 |
EOC |
| 610 |
unless (close($fh)) { |
| 611 |
die("Can't write $config_file: $!"); |
| 612 |
} |
| 613 |
|
| 614 |
} else { |
| 615 |
die("Can't open $config_file: $!"); |
| 616 |
} |
| 617 |
|
| 618 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 619 |
# the child will indicate when it's done with its test by writing a message |
| 620 |
# to the parent. |
| 621 |
my ($rfh, $wfh); |
| 622 |
unless (pipe($rfh, $wfh)) { |
| 623 |
die("Can't open pipe: $!"); |
| 624 |
} |
| 625 |
|
| 626 |
my $ex; |
| 627 |
|
| 628 |
# Fork child |
| 629 |
$self->handle_sigchld(); |
| 630 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 631 |
if ($pid) { |
| 632 |
eval { |
| 633 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 634 |
|
| 635 |
eval { $client->login($user, $passwd) }; |
| 636 |
unless ($@) { |
| 637 |
die("Login succeeded unexpectedly"); |
| 638 |
} |
| 639 |
|
| 640 |
my $resp_code = $client->response_code(); |
| 641 |
my $resp_msg = $client->response_msg(); |
| 642 |
|
| 643 |
my $expected; |
| 644 |
|
| 645 |
$expected = 530; |
| 646 |
$self->assert($expected == $resp_code, |
| 647 |
test_msg("Expected $expected, got $resp_code")); |
| 648 |
|
| 649 |
$expected = "Login incorrect."; |
| 650 |
$self->assert($expected eq $resp_msg, |
| 651 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 652 |
|
| 653 |
}; |
| 654 |
|
| 655 |
if ($@) { |
| 656 |
$ex = $@; |
| 657 |
} |
| 658 |
|
| 659 |
$wfh->print("done\n"); |
| 660 |
$wfh->flush(); |
| 661 |
|
| 662 |
} else { |
| 663 |
eval { server_wait($config_file, $rfh) }; |
| 664 |
if ($@) { |
| 665 |
warn($@); |
| 666 |
exit 1; |
| 667 |
} |
| 668 |
|
| 669 |
exit 0; |
| 670 |
} |
| 671 |
|
| 672 |
# Stop server |
| 673 |
server_stop($pid_file); |
| 674 |
|
| 675 |
$self->assert_child_ok($pid); |
| 676 |
|
| 677 |
if ($ex) { |
| 678 |
die($ex); |
| 679 |
} |
| 680 |
|
| 681 |
unlink($log_file); |
| 682 |
} |
| 683 |
|
| 684 |
1; |