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