| 1 |
package ProFTPD::Tests::Config::Limit::Anonymous; |
| 2 |
|
| 3 |
use lib qw(t/lib); |
| 4 |
use base qw(ProFTPD::TestSuite::Child); |
| 5 |
use strict; |
| 6 |
|
| 7 |
use File::Path qw(mkpath); |
| 8 |
use File::Spec; |
| 9 |
use IO::Handle; |
| 10 |
|
| 11 |
use ProFTPD::TestSuite::FTP; |
| 12 |
use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite); |
| 13 |
|
| 14 |
$| = 1; |
| 15 |
|
| 16 |
my $order = 0; |
| 17 |
|
| 18 |
my $TESTS = { |
| 19 |
anon_limit_write => { |
| 20 |
order => ++$order, |
| 21 |
test_class => [qw(forking rootprivs)], |
| 22 |
}, |
| 23 |
|
| 24 |
anon_limit_write_changing_dirs => { |
| 25 |
order => ++$order, |
| 26 |
test_class => [qw(forking rootprivs)], |
| 27 |
}, |
| 28 |
|
| 29 |
anon_limit_write_with_ftpaccess => { |
| 30 |
order => ++$order, |
| 31 |
test_class => [qw(forking rootprivs)], |
| 32 |
}, |
| 33 |
|
| 34 |
anon_limit_login_dns_name => { |
| 35 |
order => ++$order, |
| 36 |
test_class => [qw(forking rootprivs)], |
| 37 |
}, |
| 38 |
|
| 39 |
anon_limit_write_allow_stor_using_abs_path => { |
| 40 |
order => ++$order, |
| 41 |
test_class => [qw(forking rootprivs)], |
| 42 |
}, |
| 43 |
|
| 44 |
anon_limit_write_allow_stor_using_rel_path => { |
| 45 |
order => ++$order, |
| 46 |
test_class => [qw(forking rootprivs)], |
| 47 |
}, |
| 48 |
|
| 49 |
}; |
| 50 |
|
| 51 |
sub new { |
| 52 |
return shift()->SUPER::new(@_); |
| 53 |
} |
| 54 |
|
| 55 |
sub list_tests { |
| 56 |
return testsuite_get_runnable_tests($TESTS); |
| 57 |
} |
| 58 |
|
| 59 |
sub anon_limit_write { |
| 60 |
my $self = shift; |
| 61 |
my $tmpdir = $self->{tmpdir}; |
| 62 |
|
| 63 |
my $config_file = "$tmpdir/limit.conf"; |
| 64 |
my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid"); |
| 65 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard"); |
| 66 |
|
| 67 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 68 |
|
| 69 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd"); |
| 70 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group"); |
| 71 |
|
| 72 |
my ($config_user, $config_group) = config_get_identity(); |
| 73 |
|
| 74 |
my $anon_dir = File::Spec->rel2abs($tmpdir); |
| 75 |
my $uid = 500; |
| 76 |
my $gid = 500; |
| 77 |
|
| 78 |
# Make sure that, if we're running as root, that the home directory has |
| 79 |
# permissions/privs set for the account we create |
| 80 |
if ($< == 0) { |
| 81 |
unless (chmod(0755, $anon_dir)) { |
| 82 |
die("Can't set perms on $anon_dir to 0755: $!"); |
| 83 |
} |
| 84 |
|
| 85 |
unless (chown($uid, $gid, $anon_dir)) { |
| 86 |
die("Can't set owner of $anon_dir to $uid/$gid: $!"); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
auth_user_write($auth_user_file, $config_user, 'test', $uid, $gid, '/tmp', |
| 91 |
'/bin/bash'); |
| 92 |
auth_group_write($auth_group_file, $config_group, $gid, $config_user); |
| 93 |
|
| 94 |
# Test the config mentioned here: |
| 95 |
# |
| 96 |
# http://forums.proftpd.org/smf/index.php/topic,4076.0.html |
| 97 |
# |
| 98 |
# Specifically this portion: |
| 99 |
# |
| 100 |
# <Anonymous> |
| 101 |
# <Directory *> |
| 102 |
# <Limit WRITE> |
| 103 |
# DenyAll |
| 104 |
# </Limit> |
| 105 |
# </Directory> |
| 106 |
# </Anonymous> |
| 107 |
# |
| 108 |
# Does the use of '*' there allow creation of directories there? |
| 109 |
|
| 110 |
my $config = { |
| 111 |
PidFile => $pid_file, |
| 112 |
ScoreboardFile => $scoreboard_file, |
| 113 |
SystemLog => $log_file, |
| 114 |
|
| 115 |
AuthUserFile => $auth_user_file, |
| 116 |
AuthGroupFile => $auth_group_file, |
| 117 |
AuthOrder => 'mod_auth_file.c', |
| 118 |
|
| 119 |
IfModules => { |
| 120 |
'mod_delay.c' => { |
| 121 |
DelayEngine => 'off', |
| 122 |
}, |
| 123 |
}, |
| 124 |
}; |
| 125 |
|
| 126 |
my ($port, $user, $group) = config_write($config_file, $config); |
| 127 |
|
| 128 |
if (open(my $fh, ">> $config_file")) { |
| 129 |
print $fh <<EOC; |
| 130 |
<Anonymous $anon_dir> |
| 131 |
User $config_user |
| 132 |
Group $config_group |
| 133 |
UserAlias anonymous $config_user |
| 134 |
RequireValidShell off |
| 135 |
|
| 136 |
<Directory *> |
| 137 |
<Limit WRITE> |
| 138 |
DenyAll |
| 139 |
</Limit> |
| 140 |
</Directory> |
| 141 |
</Anonymous> |
| 142 |
EOC |
| 143 |
unless (close($fh)) { |
| 144 |
die("Can't write $config_file: $!"); |
| 145 |
} |
| 146 |
|
| 147 |
} else { |
| 148 |
die("Can't open $config_file: $!"); |
| 149 |
} |
| 150 |
|
| 151 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 152 |
# the child will indicate when it's done with its test by writing a message |
| 153 |
# to the parent. |
| 154 |
my ($rfh, $wfh); |
| 155 |
unless (pipe($rfh, $wfh)) { |
| 156 |
die("Can't open pipe: $!"); |
| 157 |
} |
| 158 |
|
| 159 |
my $ex; |
| 160 |
|
| 161 |
# Fork child |
| 162 |
$self->handle_sigchld(); |
| 163 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 164 |
if ($pid) { |
| 165 |
eval { |
| 166 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 167 |
$client->login('anonymous', '[email protected]'); |
| 168 |
|
| 169 |
eval { $client->mkd('testdir') }; |
| 170 |
unless ($@) { |
| 171 |
die("MKD testdir succeeded unexpectedly"); |
| 172 |
} |
| 173 |
|
| 174 |
my $resp_code = $client->response_code(); |
| 175 |
my $resp_msg = $client->response_msg(); |
| 176 |
|
| 177 |
my $expected; |
| 178 |
|
| 179 |
$expected = 550; |
| 180 |
$self->assert($expected == $resp_code, |
| 181 |
test_msg("Expected response code $expected, got $resp_code")); |
| 182 |
|
| 183 |
$expected = "testdir: Permission denied"; |
| 184 |
$self->assert($expected eq $resp_msg, |
| 185 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 186 |
}; |
| 187 |
|
| 188 |
if ($@) { |
| 189 |
$ex = $@; |
| 190 |
} |
| 191 |
|
| 192 |
$wfh->print("done\n"); |
| 193 |
$wfh->flush(); |
| 194 |
|
| 195 |
} else { |
| 196 |
eval { server_wait($config_file, $rfh) }; |
| 197 |
if ($@) { |
| 198 |
warn($@); |
| 199 |
exit 1; |
| 200 |
} |
| 201 |
|
| 202 |
exit 0; |
| 203 |
} |
| 204 |
|
| 205 |
# Stop server |
| 206 |
server_stop($pid_file); |
| 207 |
|
| 208 |
$self->assert_child_ok($pid); |
| 209 |
|
| 210 |
if ($ex) { |
| 211 |
die($ex); |
| 212 |
} |
| 213 |
|
| 214 |
unlink($log_file); |
| 215 |
} |
| 216 |
|
| 217 |
sub anon_limit_write_changing_dirs { |
| 218 |
my $self = shift; |
| 219 |
my $tmpdir = $self->{tmpdir}; |
| 220 |
|
| 221 |
my $config_file = "$tmpdir/limit.conf"; |
| 222 |
my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid"); |
| 223 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard"); |
| 224 |
|
| 225 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 226 |
|
| 227 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd"); |
| 228 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group"); |
| 229 |
|
| 230 |
my ($config_user, $config_group) = config_get_identity(); |
| 231 |
|
| 232 |
my $anon_dir = File::Spec->rel2abs($tmpdir); |
| 233 |
my $uid = 500; |
| 234 |
my $gid = 500; |
| 235 |
|
| 236 |
my $sub_dir = File::Spec->rel2abs("$tmpdir/subdir"); |
| 237 |
mkpath($sub_dir); |
| 238 |
|
| 239 |
# Make sure that, if we're running as root, that the home directory has |
| 240 |
# permissions/privs set for the account we create |
| 241 |
if ($< == 0) { |
| 242 |
unless (chmod(0755, $anon_dir, $sub_dir)) { |
| 243 |
die("Can't set perms on $anon_dir, $sub_dir to 0755: $!"); |
| 244 |
} |
| 245 |
|
| 246 |
unless (chown($uid, $gid, $anon_dir, $sub_dir)) { |
| 247 |
die("Can't set owner of $anon_dir, $sub_dir to $uid/$gid: $!"); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
auth_user_write($auth_user_file, $config_user, 'test', $uid, $gid, '/tmp', |
| 252 |
'/bin/bash'); |
| 253 |
auth_group_write($auth_group_file, $config_group, $gid, $config_user); |
| 254 |
|
| 255 |
# Test the config mentioned here: |
| 256 |
# |
| 257 |
# http://forums.proftpd.org/smf/index.php/topic,4076.0.html |
| 258 |
# |
| 259 |
# Specifically this portion: |
| 260 |
# |
| 261 |
# <Anonymous> |
| 262 |
# <Directory *> |
| 263 |
# <Limit WRITE> |
| 264 |
# DenyAll |
| 265 |
# </Limit> |
| 266 |
# </Directory> |
| 267 |
# </Anonymous> |
| 268 |
# |
| 269 |
# Does the use of '*' there allow creation of directories there? |
| 270 |
|
| 271 |
my $config = { |
| 272 |
PidFile => $pid_file, |
| 273 |
ScoreboardFile => $scoreboard_file, |
| 274 |
SystemLog => $log_file, |
| 275 |
|
| 276 |
AuthUserFile => $auth_user_file, |
| 277 |
AuthGroupFile => $auth_group_file, |
| 278 |
AuthOrder => 'mod_auth_file.c', |
| 279 |
|
| 280 |
IfModules => { |
| 281 |
'mod_delay.c' => { |
| 282 |
DelayEngine => 'off', |
| 283 |
}, |
| 284 |
}, |
| 285 |
}; |
| 286 |
|
| 287 |
my ($port, $user, $group) = config_write($config_file, $config); |
| 288 |
|
| 289 |
if (open(my $fh, ">> $config_file")) { |
| 290 |
print $fh <<EOC; |
| 291 |
<Anonymous $anon_dir> |
| 292 |
User $config_user |
| 293 |
Group $config_group |
| 294 |
UserAlias anonymous $config_user |
| 295 |
RequireValidShell off |
| 296 |
|
| 297 |
<Directory *> |
| 298 |
<Limit WRITE> |
| 299 |
DenyAll |
| 300 |
</Limit> |
| 301 |
</Directory> |
| 302 |
</Anonymous> |
| 303 |
EOC |
| 304 |
unless (close($fh)) { |
| 305 |
die("Can't write $config_file: $!"); |
| 306 |
} |
| 307 |
|
| 308 |
} else { |
| 309 |
die("Can't open $config_file: $!"); |
| 310 |
} |
| 311 |
|
| 312 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 313 |
# the child will indicate when it's done with its test by writing a message |
| 314 |
# to the parent. |
| 315 |
my ($rfh, $wfh); |
| 316 |
unless (pipe($rfh, $wfh)) { |
| 317 |
die("Can't open pipe: $!"); |
| 318 |
} |
| 319 |
|
| 320 |
my $ex; |
| 321 |
|
| 322 |
# Fork child |
| 323 |
$self->handle_sigchld(); |
| 324 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 325 |
if ($pid) { |
| 326 |
eval { |
| 327 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 328 |
$client->login('anonymous', '[email protected]'); |
| 329 |
$client->cwd('subdir'); |
| 330 |
|
| 331 |
eval { $client->mkd('testdir') }; |
| 332 |
unless ($@) { |
| 333 |
die("MKD testdir succeeded unexpectedly"); |
| 334 |
} |
| 335 |
|
| 336 |
my $resp_code = $client->response_code(); |
| 337 |
my $resp_msg = $client->response_msg(); |
| 338 |
|
| 339 |
my $expected; |
| 340 |
|
| 341 |
$expected = 550; |
| 342 |
$self->assert($expected == $resp_code, |
| 343 |
test_msg("Expected response code $expected, got $resp_code")); |
| 344 |
|
| 345 |
$expected = "testdir: Permission denied"; |
| 346 |
$self->assert($expected eq $resp_msg, |
| 347 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 348 |
|
| 349 |
# Now try to create a directory one level up from where we are |
| 350 |
eval { $client->mkd('../testdir') }; |
| 351 |
unless ($@) { |
| 352 |
die("MKD ../testdir succeeded unexpectedly"); |
| 353 |
} |
| 354 |
|
| 355 |
$resp_code = $client->response_code(); |
| 356 |
$resp_msg = $client->response_msg(); |
| 357 |
|
| 358 |
$expected = 550; |
| 359 |
$self->assert($expected == $resp_code, |
| 360 |
test_msg("Expected response code $expected, got $resp_code")); |
| 361 |
|
| 362 |
$expected = "../testdir: Permission denied"; |
| 363 |
$self->assert($expected eq $resp_msg, |
| 364 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 365 |
}; |
| 366 |
|
| 367 |
if ($@) { |
| 368 |
$ex = $@; |
| 369 |
} |
| 370 |
|
| 371 |
$wfh->print("done\n"); |
| 372 |
$wfh->flush(); |
| 373 |
|
| 374 |
} else { |
| 375 |
eval { server_wait($config_file, $rfh) }; |
| 376 |
if ($@) { |
| 377 |
warn($@); |
| 378 |
exit 1; |
| 379 |
} |
| 380 |
|
| 381 |
exit 0; |
| 382 |
} |
| 383 |
|
| 384 |
# Stop server |
| 385 |
server_stop($pid_file); |
| 386 |
|
| 387 |
$self->assert_child_ok($pid); |
| 388 |
|
| 389 |
if ($ex) { |
| 390 |
die($ex); |
| 391 |
} |
| 392 |
|
| 393 |
unlink($log_file); |
| 394 |
} |
| 395 |
|
| 396 |
sub anon_limit_write_with_ftpaccess { |
| 397 |
my $self = shift; |
| 398 |
my $tmpdir = $self->{tmpdir}; |
| 399 |
|
| 400 |
my $config_file = "$tmpdir/limit.conf"; |
| 401 |
my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid"); |
| 402 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard"); |
| 403 |
|
| 404 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 405 |
|
| 406 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd"); |
| 407 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group"); |
| 408 |
|
| 409 |
my ($config_user, $config_group) = config_get_identity(); |
| 410 |
|
| 411 |
my $anon_dir = File::Spec->rel2abs($tmpdir); |
| 412 |
my $uid = 500; |
| 413 |
my $gid = 500; |
| 414 |
|
| 415 |
my $sub_dir = File::Spec->rel2abs("$tmpdir/subdir"); |
| 416 |
mkpath($sub_dir); |
| 417 |
|
| 418 |
# Make sure that, if we're running as root, that the home directory has |
| 419 |
# permissions/privs set for the account we create |
| 420 |
if ($< == 0) { |
| 421 |
unless (chmod(0755, $anon_dir, $sub_dir)) { |
| 422 |
die("Can't set perms on $anon_dir, $sub_dir to 0755: $!"); |
| 423 |
} |
| 424 |
|
| 425 |
unless (chown($uid, $gid, $anon_dir, $sub_dir)) { |
| 426 |
die("Can't set owner of $anon_dir, $sub_dir to $uid/$gid: $!"); |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
# Create a .ftpaccess file in the sub-directory. |
| 431 |
if (open(my $fh, "> $anon_dir/.ftpaccess")) { |
| 432 |
print $fh <<EOC; |
| 433 |
DirFakeUser on foo |
| 434 |
EOC |
| 435 |
unless (close($fh)) { |
| 436 |
die("Can't write $anon_dir/.ftpaccess: $!"); |
| 437 |
} |
| 438 |
|
| 439 |
} else { |
| 440 |
die("Can't open $anon_dir/.ftpaccess: $!"); |
| 441 |
} |
| 442 |
|
| 443 |
auth_user_write($auth_user_file, $config_user, 'test', $uid, $gid, '/tmp', |
| 444 |
'/bin/bash'); |
| 445 |
auth_group_write($auth_group_file, $config_group, $gid, $config_user); |
| 446 |
|
| 447 |
# Test the config mentioned here: |
| 448 |
# |
| 449 |
# http://forums.proftpd.org/smf/index.php/topic,4076.0.html |
| 450 |
# |
| 451 |
# Specifically this portion: |
| 452 |
# |
| 453 |
# <Anonymous> |
| 454 |
# <Directory *> |
| 455 |
# <Limit WRITE> |
| 456 |
# DenyAll |
| 457 |
# </Limit> |
| 458 |
# </Directory> |
| 459 |
# </Anonymous> |
| 460 |
# |
| 461 |
# Does the use of '*' there allow creation of directories there? |
| 462 |
|
| 463 |
my $config = { |
| 464 |
PidFile => $pid_file, |
| 465 |
ScoreboardFile => $scoreboard_file, |
| 466 |
SystemLog => $log_file, |
| 467 |
|
| 468 |
AuthUserFile => $auth_user_file, |
| 469 |
AuthGroupFile => $auth_group_file, |
| 470 |
AuthOrder => 'mod_auth_file.c', |
| 471 |
|
| 472 |
AllowOverride => 'on', |
| 473 |
|
| 474 |
IfModules => { |
| 475 |
'mod_delay.c' => { |
| 476 |
DelayEngine => 'off', |
| 477 |
}, |
| 478 |
}, |
| 479 |
}; |
| 480 |
|
| 481 |
my ($port, $user, $group) = config_write($config_file, $config); |
| 482 |
|
| 483 |
if (open(my $fh, ">> $config_file")) { |
| 484 |
print $fh <<EOC; |
| 485 |
<Anonymous $anon_dir> |
| 486 |
User $config_user |
| 487 |
Group $config_group |
| 488 |
UserAlias anonymous $config_user |
| 489 |
RequireValidShell off |
| 490 |
|
| 491 |
<Directory *> |
| 492 |
<Limit WRITE> |
| 493 |
DenyAll |
| 494 |
</Limit> |
| 495 |
</Directory> |
| 496 |
</Anonymous> |
| 497 |
EOC |
| 498 |
unless (close($fh)) { |
| 499 |
die("Can't write $config_file: $!"); |
| 500 |
} |
| 501 |
|
| 502 |
} else { |
| 503 |
die("Can't open $config_file: $!"); |
| 504 |
} |
| 505 |
|
| 506 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 507 |
# the child will indicate when it's done with its test by writing a message |
| 508 |
# to the parent. |
| 509 |
my ($rfh, $wfh); |
| 510 |
unless (pipe($rfh, $wfh)) { |
| 511 |
die("Can't open pipe: $!"); |
| 512 |
} |
| 513 |
|
| 514 |
my $ex; |
| 515 |
|
| 516 |
# Fork child |
| 517 |
$self->handle_sigchld(); |
| 518 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 519 |
if ($pid) { |
| 520 |
eval { |
| 521 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 522 |
$client->login('anonymous', '[email protected]'); |
| 523 |
$client->cwd('subdir'); |
| 524 |
|
| 525 |
eval { $client->mkd('testdir') }; |
| 526 |
unless ($@) { |
| 527 |
die("MKD testdir succeeded unexpectedly"); |
| 528 |
} |
| 529 |
|
| 530 |
my $resp_code = $client->response_code(); |
| 531 |
my $resp_msg = $client->response_msg(); |
| 532 |
|
| 533 |
my $expected; |
| 534 |
|
| 535 |
$expected = 550; |
| 536 |
$self->assert($expected == $resp_code, |
| 537 |
test_msg("Expected response code $expected, got $resp_code")); |
| 538 |
|
| 539 |
$expected = "testdir: Permission denied"; |
| 540 |
$self->assert($expected eq $resp_msg, |
| 541 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 542 |
|
| 543 |
# Now try to create a directory one level up from where we are |
| 544 |
eval { $client->mkd('../testdir') }; |
| 545 |
unless ($@) { |
| 546 |
die("MKD ../testdir succeeded unexpectedly"); |
| 547 |
} |
| 548 |
|
| 549 |
$resp_code = $client->response_code(); |
| 550 |
$resp_msg = $client->response_msg(); |
| 551 |
|
| 552 |
$expected = 550; |
| 553 |
$self->assert($expected == $resp_code, |
| 554 |
test_msg("Expected response code $expected, got $resp_code")); |
| 555 |
|
| 556 |
$expected = "../testdir: Permission denied"; |
| 557 |
$self->assert($expected eq $resp_msg, |
| 558 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 559 |
|
| 560 |
$client->cwd('/'); |
| 561 |
|
| 562 |
eval { $client->mkd('testdir') }; |
| 563 |
unless ($@) { |
| 564 |
die("MKD testdir succeeded unexpectedly"); |
| 565 |
} |
| 566 |
|
| 567 |
$resp_code = $client->response_code(); |
| 568 |
$resp_msg = $client->response_msg(); |
| 569 |
|
| 570 |
$expected = 550; |
| 571 |
$self->assert($expected == $resp_code, |
| 572 |
test_msg("Expected response code $expected, got $resp_code")); |
| 573 |
|
| 574 |
$expected = "testdir: Permission denied"; |
| 575 |
$self->assert($expected eq $resp_msg, |
| 576 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 577 |
}; |
| 578 |
|
| 579 |
if ($@) { |
| 580 |
$ex = $@; |
| 581 |
} |
| 582 |
|
| 583 |
$wfh->print("done\n"); |
| 584 |
$wfh->flush(); |
| 585 |
|
| 586 |
} else { |
| 587 |
eval { server_wait($config_file, $rfh) }; |
| 588 |
if ($@) { |
| 589 |
warn($@); |
| 590 |
exit 1; |
| 591 |
} |
| 592 |
|
| 593 |
exit 0; |
| 594 |
} |
| 595 |
|
| 596 |
# Stop server |
| 597 |
server_stop($pid_file); |
| 598 |
|
| 599 |
$self->assert_child_ok($pid); |
| 600 |
|
| 601 |
if ($ex) { |
| 602 |
die($ex); |
| 603 |
} |
| 604 |
|
| 605 |
unlink($log_file); |
| 606 |
} |
| 607 |
|
| 608 |
sub anon_limit_login_dns_name { |
| 609 |
my $self = shift; |
| 610 |
my $tmpdir = $self->{tmpdir}; |
| 611 |
|
| 612 |
my $config_file = "$tmpdir/limit.conf"; |
| 613 |
my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid"); |
| 614 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard"); |
| 615 |
|
| 616 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 617 |
|
| 618 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd"); |
| 619 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group"); |
| 620 |
|
| 621 |
my ($config_user, $config_group) = config_get_identity(); |
| 622 |
|
| 623 |
my $anon_dir = File::Spec->rel2abs($tmpdir); |
| 624 |
my $uid = 500; |
| 625 |
my $gid = 500; |
| 626 |
|
| 627 |
# Make sure that, if we're running as root, that the home directory has |
| 628 |
# permissions/privs set for the account we create |
| 629 |
if ($< == 0) { |
| 630 |
unless (chmod(0755, $anon_dir)) { |
| 631 |
die("Can't set perms on $anon_dir to 0755: $!"); |
| 632 |
} |
| 633 |
|
| 634 |
unless (chown($uid, $gid, $anon_dir)) { |
| 635 |
die("Can't set owner of $anon_dir to $uid/$gid: $!"); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
auth_user_write($auth_user_file, $config_user, 'test', $uid, $gid, '/tmp', |
| 640 |
'/bin/bash'); |
| 641 |
auth_group_write($auth_group_file, $config_group, $gid, $config_user); |
| 642 |
|
| 643 |
# Test the config mentioned here: |
| 644 |
# |
| 645 |
# http://forums.proftpd.org/smf/index.php/topic,4436.0.html |
| 646 |
# |
| 647 |
# Specifically this portion: |
| 648 |
# |
| 649 |
# <Anonymous> |
| 650 |
# <Limit LOGIN> |
| 651 |
# Allow from <dns-name> |
| 652 |
# DenyAll |
| 653 |
# </Limit> |
| 654 |
# </Anonymous> |
| 655 |
|
| 656 |
my $config = { |
| 657 |
PidFile => $pid_file, |
| 658 |
ScoreboardFile => $scoreboard_file, |
| 659 |
SystemLog => $log_file, |
| 660 |
TraceLog => $log_file, |
| 661 |
Trace => 'DEFAULT:10 netacl:10 netaddr:10 dns:10', |
| 662 |
|
| 663 |
AuthUserFile => $auth_user_file, |
| 664 |
AuthGroupFile => $auth_group_file, |
| 665 |
AuthOrder => 'mod_auth_file.c', |
| 666 |
|
| 667 |
UseReverseDNS => 'on', |
| 668 |
|
| 669 |
IfModules => { |
| 670 |
'mod_delay.c' => { |
| 671 |
DelayEngine => 'off', |
| 672 |
}, |
| 673 |
}, |
| 674 |
}; |
| 675 |
|
| 676 |
my ($port, $user, $group) = config_write($config_file, $config); |
| 677 |
|
| 678 |
if (open(my $fh, ">> $config_file")) { |
| 679 |
print $fh <<EOC; |
| 680 |
<Anonymous $anon_dir> |
| 681 |
User $config_user |
| 682 |
Group $config_group |
| 683 |
UserAlias anonymous $config_user |
| 684 |
RequireValidShell off |
| 685 |
|
| 686 |
<Limit LOGIN> |
| 687 |
Allow from localhost |
| 688 |
DenyAll |
| 689 |
</Limit> |
| 690 |
</Anonymous> |
| 691 |
EOC |
| 692 |
unless (close($fh)) { |
| 693 |
die("Can't write $config_file: $!"); |
| 694 |
} |
| 695 |
|
| 696 |
} else { |
| 697 |
die("Can't open $config_file: $!"); |
| 698 |
} |
| 699 |
|
| 700 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 701 |
# the child will indicate when it's done with its test by writing a message |
| 702 |
# to the parent. |
| 703 |
my ($rfh, $wfh); |
| 704 |
unless (pipe($rfh, $wfh)) { |
| 705 |
die("Can't open pipe: $!"); |
| 706 |
} |
| 707 |
|
| 708 |
my $ex; |
| 709 |
|
| 710 |
# Fork child |
| 711 |
$self->handle_sigchld(); |
| 712 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 713 |
if ($pid) { |
| 714 |
eval { |
| 715 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 716 |
$client->login('anonymous', '[email protected]'); |
| 717 |
}; |
| 718 |
|
| 719 |
if ($@) { |
| 720 |
$ex = $@; |
| 721 |
} |
| 722 |
|
| 723 |
$wfh->print("done\n"); |
| 724 |
$wfh->flush(); |
| 725 |
|
| 726 |
} else { |
| 727 |
eval { server_wait($config_file, $rfh) }; |
| 728 |
if ($@) { |
| 729 |
warn($@); |
| 730 |
exit 1; |
| 731 |
} |
| 732 |
|
| 733 |
exit 0; |
| 734 |
} |
| 735 |
|
| 736 |
# Stop server |
| 737 |
server_stop($pid_file); |
| 738 |
|
| 739 |
$self->assert_child_ok($pid); |
| 740 |
|
| 741 |
if ($ex) { |
| 742 |
die($ex); |
| 743 |
} |
| 744 |
|
| 745 |
unlink($log_file); |
| 746 |
} |
| 747 |
|
| 748 |
sub anon_limit_write_allow_stor_using_abs_path { |
| 749 |
my $self = shift; |
| 750 |
my $tmpdir = $self->{tmpdir}; |
| 751 |
|
| 752 |
my $config_file = "$tmpdir/limit.conf"; |
| 753 |
my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid"); |
| 754 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard"); |
| 755 |
|
| 756 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 757 |
|
| 758 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd"); |
| 759 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group"); |
| 760 |
|
| 761 |
my ($config_user, $config_group) = config_get_identity(); |
| 762 |
|
| 763 |
my $anon_dir = File::Spec->rel2abs($tmpdir); |
| 764 |
my $uid = 500; |
| 765 |
my $gid = 500; |
| 766 |
|
| 767 |
my $uploads_dir = File::Spec->rel2abs("$anon_dir/uploads"); |
| 768 |
mkpath($uploads_dir); |
| 769 |
|
| 770 |
my $test_file = File::Spec->rel2abs("$uploads_dir/test.txt"); |
| 771 |
|
| 772 |
# Make sure that, if we're running as root, that the home directory has |
| 773 |
# permissions/privs set for the account we create |
| 774 |
if ($< == 0) { |
| 775 |
unless (chmod(0755, $anon_dir, $uploads_dir)) { |
| 776 |
die("Can't set perms on $anon_dir to 0755: $!"); |
| 777 |
} |
| 778 |
|
| 779 |
unless (chown($uid, $gid, $anon_dir, $uploads_dir)) { |
| 780 |
die("Can't set owner of $anon_dir to $uid/$gid: $!"); |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
auth_user_write($auth_user_file, $config_user, 'test', $uid, $gid, '/tmp', |
| 785 |
'/bin/bash'); |
| 786 |
auth_group_write($auth_group_file, $config_group, $gid, $config_user); |
| 787 |
|
| 788 |
# Test this config: |
| 789 |
# |
| 790 |
# <Anonymous> |
| 791 |
# <Limit WRITE SITE_CHMOD> |
| 792 |
# DenyAll |
| 793 |
# </Limit> |
| 794 |
# |
| 795 |
# <Directory uploads/*> |
| 796 |
# <Limit STOR> |
| 797 |
# AllowAll |
| 798 |
# </Limit> |
| 799 |
# </Directory> |
| 800 |
# </Anonymous> |
| 801 |
|
| 802 |
my $config = { |
| 803 |
PidFile => $pid_file, |
| 804 |
ScoreboardFile => $scoreboard_file, |
| 805 |
SystemLog => $log_file, |
| 806 |
|
| 807 |
AuthUserFile => $auth_user_file, |
| 808 |
AuthGroupFile => $auth_group_file, |
| 809 |
AuthOrder => 'mod_auth_file.c', |
| 810 |
|
| 811 |
IfModules => { |
| 812 |
'mod_delay.c' => { |
| 813 |
DelayEngine => 'off', |
| 814 |
}, |
| 815 |
}, |
| 816 |
}; |
| 817 |
|
| 818 |
my ($port, $user, $group) = config_write($config_file, $config); |
| 819 |
|
| 820 |
if (open(my $fh, ">> $config_file")) { |
| 821 |
print $fh <<EOC; |
| 822 |
<Anonymous $anon_dir> |
| 823 |
User $config_user |
| 824 |
Group $config_group |
| 825 |
UserAlias anonymous $config_user |
| 826 |
RequireValidShell off |
| 827 |
|
| 828 |
<Limit WRITE SITE_CHMOD> |
| 829 |
DenyAll |
| 830 |
</Limit> |
| 831 |
|
| 832 |
<Directory uploads/*> |
| 833 |
<Limit STOR> |
| 834 |
AllowAll |
| 835 |
</Limit> |
| 836 |
</Directory> |
| 837 |
</Anonymous> |
| 838 |
EOC |
| 839 |
unless (close($fh)) { |
| 840 |
die("Can't write $config_file: $!"); |
| 841 |
} |
| 842 |
|
| 843 |
} else { |
| 844 |
die("Can't open $config_file: $!"); |
| 845 |
} |
| 846 |
|
| 847 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 848 |
# the child will indicate when it's done with its test by writing a message |
| 849 |
# to the parent. |
| 850 |
my ($rfh, $wfh); |
| 851 |
unless (pipe($rfh, $wfh)) { |
| 852 |
die("Can't open pipe: $!"); |
| 853 |
} |
| 854 |
|
| 855 |
my $ex; |
| 856 |
|
| 857 |
# Fork child |
| 858 |
$self->handle_sigchld(); |
| 859 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 860 |
if ($pid) { |
| 861 |
eval { |
| 862 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 863 |
$client->login('anonymous', '[email protected]'); |
| 864 |
|
| 865 |
my $conn = $client->stor_raw('uploads/test.txt'); |
| 866 |
unless ($conn) { |
| 867 |
die("STOR uploads/test.txt failed:" . $client->response_code() . " " . |
| 868 |
$client->response_msg()); |
| 869 |
} |
| 870 |
|
| 871 |
my $buf = "Hello, World!\n"; |
| 872 |
$conn->write($buf, length($buf), 15); |
| 873 |
eval { $conn->close() }; |
| 874 |
|
| 875 |
my $resp_code = $client->response_code(); |
| 876 |
my $resp_msg = $client->response_msg(); |
| 877 |
|
| 878 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 879 |
|
| 880 |
$client->quit(); |
| 881 |
|
| 882 |
$self->assert(-f $test_file, |
| 883 |
test_msg("File $test_file does not exist as expected")); |
| 884 |
}; |
| 885 |
|
| 886 |
if ($@) { |
| 887 |
$ex = $@; |
| 888 |
} |
| 889 |
|
| 890 |
$wfh->print("done\n"); |
| 891 |
$wfh->flush(); |
| 892 |
|
| 893 |
} else { |
| 894 |
eval { server_wait($config_file, $rfh) }; |
| 895 |
if ($@) { |
| 896 |
warn($@); |
| 897 |
exit 1; |
| 898 |
} |
| 899 |
|
| 900 |
exit 0; |
| 901 |
} |
| 902 |
|
| 903 |
# Stop server |
| 904 |
server_stop($pid_file); |
| 905 |
|
| 906 |
$self->assert_child_ok($pid); |
| 907 |
|
| 908 |
if ($ex) { |
| 909 |
die($ex); |
| 910 |
} |
| 911 |
|
| 912 |
unlink($log_file); |
| 913 |
} |
| 914 |
|
| 915 |
sub anon_limit_write_allow_stor_using_rel_path { |
| 916 |
my $self = shift; |
| 917 |
my $tmpdir = $self->{tmpdir}; |
| 918 |
|
| 919 |
my $config_file = "$tmpdir/limit.conf"; |
| 920 |
my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid"); |
| 921 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard"); |
| 922 |
|
| 923 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 924 |
|
| 925 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd"); |
| 926 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group"); |
| 927 |
|
| 928 |
my ($config_user, $config_group) = config_get_identity(); |
| 929 |
|
| 930 |
my $anon_dir = File::Spec->rel2abs($tmpdir); |
| 931 |
my $uid = 500; |
| 932 |
my $gid = 500; |
| 933 |
|
| 934 |
my $uploads_dir = File::Spec->rel2abs("$anon_dir/uploads"); |
| 935 |
mkpath($uploads_dir); |
| 936 |
|
| 937 |
my $test_file = File::Spec->rel2abs("$uploads_dir/test.txt"); |
| 938 |
|
| 939 |
# Make sure that, if we're running as root, that the home directory has |
| 940 |
# permissions/privs set for the account we create |
| 941 |
if ($< == 0) { |
| 942 |
unless (chmod(0755, $anon_dir, $uploads_dir)) { |
| 943 |
die("Can't set perms on $anon_dir to 0755: $!"); |
| 944 |
} |
| 945 |
|
| 946 |
unless (chown($uid, $gid, $anon_dir, $uploads_dir)) { |
| 947 |
die("Can't set owner of $anon_dir to $uid/$gid: $!"); |
| 948 |
} |
| 949 |
} |
| 950 |
|
| 951 |
auth_user_write($auth_user_file, $config_user, 'test', $uid, $gid, '/tmp', |
| 952 |
'/bin/bash'); |
| 953 |
auth_group_write($auth_group_file, $config_group, $gid, $config_user); |
| 954 |
|
| 955 |
# Test this config: |
| 956 |
# |
| 957 |
# <Anonymous> |
| 958 |
# <Limit WRITE SITE_CHMOD> |
| 959 |
# DenyAll |
| 960 |
# </Limit> |
| 961 |
# |
| 962 |
# <Directory uploads/*> |
| 963 |
# <Limit STOR> |
| 964 |
# AllowAll |
| 965 |
# </Limit> |
| 966 |
# </Directory> |
| 967 |
# </Anonymous> |
| 968 |
|
| 969 |
my $config = { |
| 970 |
PidFile => $pid_file, |
| 971 |
ScoreboardFile => $scoreboard_file, |
| 972 |
SystemLog => $log_file, |
| 973 |
|
| 974 |
AuthUserFile => $auth_user_file, |
| 975 |
AuthGroupFile => $auth_group_file, |
| 976 |
AuthOrder => 'mod_auth_file.c', |
| 977 |
|
| 978 |
IfModules => { |
| 979 |
'mod_delay.c' => { |
| 980 |
DelayEngine => 'off', |
| 981 |
}, |
| 982 |
}, |
| 983 |
}; |
| 984 |
|
| 985 |
my ($port, $user, $group) = config_write($config_file, $config); |
| 986 |
|
| 987 |
if (open(my $fh, ">> $config_file")) { |
| 988 |
print $fh <<EOC; |
| 989 |
<Anonymous $anon_dir> |
| 990 |
User $config_user |
| 991 |
Group $config_group |
| 992 |
UserAlias anonymous $config_user |
| 993 |
RequireValidShell off |
| 994 |
|
| 995 |
<Limit WRITE SITE_CHMOD> |
| 996 |
DenyAll |
| 997 |
</Limit> |
| 998 |
|
| 999 |
<Directory uploads/*> |
| 1000 |
<Limit STOR> |
| 1001 |
AllowAll |
| 1002 |
</Limit> |
| 1003 |
</Directory> |
| 1004 |
</Anonymous> |
| 1005 |
EOC |
| 1006 |
unless (close($fh)) { |
| 1007 |
die("Can't write $config_file: $!"); |
| 1008 |
} |
| 1009 |
|
| 1010 |
} else { |
| 1011 |
die("Can't open $config_file: $!"); |
| 1012 |
} |
| 1013 |
|
| 1014 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1015 |
# the child will indicate when it's done with its test by writing a message |
| 1016 |
# to the parent. |
| 1017 |
my ($rfh, $wfh); |
| 1018 |
unless (pipe($rfh, $wfh)) { |
| 1019 |
die("Can't open pipe: $!"); |
| 1020 |
} |
| 1021 |
|
| 1022 |
my $ex; |
| 1023 |
|
| 1024 |
# Fork child |
| 1025 |
$self->handle_sigchld(); |
| 1026 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1027 |
if ($pid) { |
| 1028 |
eval { |
| 1029 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1030 |
$client->login('anonymous', '[email protected]'); |
| 1031 |
$client->cwd('uploads'); |
| 1032 |
|
| 1033 |
my $conn = $client->stor_raw('test.txt'); |
| 1034 |
unless ($conn) { |
| 1035 |
die("STOR test.txt failed:" . $client->response_code() . " " . |
| 1036 |
$client->response_msg()); |
| 1037 |
} |
| 1038 |
|
| 1039 |
my $buf = "Hello, World!\n"; |
| 1040 |
$conn->write($buf, length($buf), 15); |
| 1041 |
eval { $conn->close() }; |
| 1042 |
|
| 1043 |
my $resp_code = $client->response_code(); |
| 1044 |
my $resp_msg = $client->response_msg(); |
| 1045 |
|
| 1046 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 1047 |
|
| 1048 |
$client->quit(); |
| 1049 |
|
| 1050 |
$self->assert(-f $test_file, |
| 1051 |
test_msg("File $test_file does not exist as expected")); |
| 1052 |
}; |
| 1053 |
|
| 1054 |
if ($@) { |
| 1055 |
$ex = $@; |
| 1056 |
} |
| 1057 |
|
| 1058 |
$wfh->print("done\n"); |
| 1059 |
$wfh->flush(); |
| 1060 |
|
| 1061 |
} else { |
| 1062 |
eval { server_wait($config_file, $rfh) }; |
| 1063 |
if ($@) { |
| 1064 |
warn($@); |
| 1065 |
exit 1; |
| 1066 |
} |
| 1067 |
|
| 1068 |
exit 0; |
| 1069 |
} |
| 1070 |
|
| 1071 |
# Stop server |
| 1072 |
server_stop($pid_file); |
| 1073 |
|
| 1074 |
$self->assert_child_ok($pid); |
| 1075 |
|
| 1076 |
if ($ex) { |
| 1077 |
die($ex); |
| 1078 |
} |
| 1079 |
|
| 1080 |
unlink($log_file); |
| 1081 |
} |
| 1082 |
|
| 1083 |
1; |