| 1 |
package ProFTPD::Tests::Config::MaxStoreFileSize; |
| 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 |
maxstorefilesize_ok => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
maxstorefilesize_exceeded => { |
| 24 |
order => ++$order, |
| 25 |
test_class => [qw(forking)], |
| 26 |
}, |
| 27 |
|
| 28 |
maxstorefilesize_appe_bug3649 => { |
| 29 |
order => ++$order, |
| 30 |
test_class => [qw(bug forking)], |
| 31 |
}, |
| 32 |
|
| 33 |
}; |
| 34 |
|
| 35 |
sub new { |
| 36 |
return shift()->SUPER::new(@_); |
| 37 |
} |
| 38 |
|
| 39 |
sub list_tests { |
| 40 |
return testsuite_get_runnable_tests($TESTS); |
| 41 |
} |
| 42 |
|
| 43 |
sub maxstorefilesize_ok { |
| 44 |
my $self = shift; |
| 45 |
my $tmpdir = $self->{tmpdir}; |
| 46 |
|
| 47 |
my $config_file = "$tmpdir/config.conf"; |
| 48 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 49 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 50 |
|
| 51 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 52 |
|
| 53 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 54 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 55 |
|
| 56 |
my $user = 'proftpd'; |
| 57 |
my $passwd = 'test'; |
| 58 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 59 |
my $uid = 500; |
| 60 |
my $gid = 500; |
| 61 |
|
| 62 |
# Make sure that, if we're running as root, that the home directory has |
| 63 |
# permissions/privs set for the account we create |
| 64 |
if ($< == 0) { |
| 65 |
unless (chmod(0755, $home_dir)) { |
| 66 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 67 |
} |
| 68 |
|
| 69 |
unless (chown($uid, $gid, $home_dir)) { |
| 70 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 75 |
'/bin/bash'); |
| 76 |
auth_group_write($auth_group_file, 'ftpd', $gid, $user); |
| 77 |
|
| 78 |
my $dst_file = File::Spec->rel2abs("$tmpdir/foo"); |
| 79 |
|
| 80 |
my $config = { |
| 81 |
PidFile => $pid_file, |
| 82 |
ScoreboardFile => $scoreboard_file, |
| 83 |
SystemLog => $log_file, |
| 84 |
|
| 85 |
AuthUserFile => $auth_user_file, |
| 86 |
AuthGroupFile => $auth_group_file, |
| 87 |
AuthOrder => 'mod_auth_file.c', |
| 88 |
|
| 89 |
MaxStoreFileSize => '100 B', |
| 90 |
|
| 91 |
IfModules => { |
| 92 |
'mod_delay.c' => { |
| 93 |
DelayEngine => 'off', |
| 94 |
}, |
| 95 |
}, |
| 96 |
}; |
| 97 |
|
| 98 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 99 |
|
| 100 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 101 |
# the child will indicate when it's done with its test by writing a message |
| 102 |
# to the parent. |
| 103 |
my ($rfh, $wfh); |
| 104 |
unless (pipe($rfh, $wfh)) { |
| 105 |
die("Can't open pipe: $!"); |
| 106 |
} |
| 107 |
|
| 108 |
my $ex; |
| 109 |
|
| 110 |
# Fork child |
| 111 |
$self->handle_sigchld(); |
| 112 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 113 |
if ($pid) { |
| 114 |
eval { |
| 115 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 116 |
|
| 117 |
$client->login($user, $passwd); |
| 118 |
|
| 119 |
my $conn = $client->stor_raw('foo'); |
| 120 |
unless ($conn) { |
| 121 |
die("STOR failed: " . $client->response_code() . " " . |
| 122 |
$client->response_msg()); |
| 123 |
} |
| 124 |
|
| 125 |
my $buf = "Hello, World!\n"; |
| 126 |
$conn->write($buf, length($buf)); |
| 127 |
eval { $conn->close() }; |
| 128 |
|
| 129 |
my $expected; |
| 130 |
|
| 131 |
$expected = 14; |
| 132 |
my $filelen = -s $dst_file; |
| 133 |
$self->assert($expected == $filelen, |
| 134 |
test_msg("Expected $expected, got $filelen")); |
| 135 |
}; |
| 136 |
|
| 137 |
if ($@) { |
| 138 |
$ex = $@; |
| 139 |
} |
| 140 |
|
| 141 |
$wfh->print("done\n"); |
| 142 |
$wfh->flush(); |
| 143 |
|
| 144 |
} else { |
| 145 |
eval { server_wait($config_file, $rfh) }; |
| 146 |
if ($@) { |
| 147 |
warn($@); |
| 148 |
exit 1; |
| 149 |
} |
| 150 |
|
| 151 |
exit 0; |
| 152 |
} |
| 153 |
|
| 154 |
# Stop server |
| 155 |
server_stop($pid_file); |
| 156 |
|
| 157 |
$self->assert_child_ok($pid); |
| 158 |
|
| 159 |
if ($ex) { |
| 160 |
die($ex); |
| 161 |
} |
| 162 |
|
| 163 |
unlink($log_file); |
| 164 |
} |
| 165 |
|
| 166 |
sub maxstorefilesize_exceeded { |
| 167 |
my $self = shift; |
| 168 |
my $tmpdir = $self->{tmpdir}; |
| 169 |
|
| 170 |
my $config_file = "$tmpdir/config.conf"; |
| 171 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 172 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 173 |
|
| 174 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 175 |
|
| 176 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 177 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 178 |
|
| 179 |
my $user = 'proftpd'; |
| 180 |
my $passwd = 'test'; |
| 181 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 182 |
my $uid = 500; |
| 183 |
my $gid = 500; |
| 184 |
|
| 185 |
# Make sure that, if we're running as root, that the home directory has |
| 186 |
# permissions/privs set for the account we create |
| 187 |
if ($< == 0) { |
| 188 |
unless (chmod(0755, $home_dir)) { |
| 189 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 190 |
} |
| 191 |
|
| 192 |
unless (chown($uid, $gid, $home_dir)) { |
| 193 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 198 |
'/bin/bash'); |
| 199 |
auth_group_write($auth_group_file, 'ftpd', $gid, $user); |
| 200 |
|
| 201 |
my $dst_file = File::Spec->rel2abs("$tmpdir/foo"); |
| 202 |
|
| 203 |
my $config = { |
| 204 |
PidFile => $pid_file, |
| 205 |
ScoreboardFile => $scoreboard_file, |
| 206 |
SystemLog => $log_file, |
| 207 |
|
| 208 |
AuthUserFile => $auth_user_file, |
| 209 |
AuthGroupFile => $auth_group_file, |
| 210 |
AuthOrder => 'mod_auth_file.c', |
| 211 |
|
| 212 |
MaxStoreFileSize => '4 B', |
| 213 |
|
| 214 |
IfModules => { |
| 215 |
'mod_delay.c' => { |
| 216 |
DelayEngine => 'off', |
| 217 |
}, |
| 218 |
}, |
| 219 |
}; |
| 220 |
|
| 221 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 222 |
|
| 223 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 224 |
# the child will indicate when it's done with its test by writing a message |
| 225 |
# to the parent. |
| 226 |
my ($rfh, $wfh); |
| 227 |
unless (pipe($rfh, $wfh)) { |
| 228 |
die("Can't open pipe: $!"); |
| 229 |
} |
| 230 |
|
| 231 |
my $ex; |
| 232 |
|
| 233 |
# Fork child |
| 234 |
$self->handle_sigchld(); |
| 235 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 236 |
if ($pid) { |
| 237 |
eval { |
| 238 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 239 |
|
| 240 |
$client->login($user, $passwd); |
| 241 |
|
| 242 |
my ($resp_code, $resp_msg); |
| 243 |
|
| 244 |
my $conn = $client->stor_raw('foo'); |
| 245 |
unless ($conn) { |
| 246 |
die("STOR failed: " . $client->response_code() . " " . |
| 247 |
$client->response_msg()); |
| 248 |
} |
| 249 |
|
| 250 |
my $buf = "Hello, World!\n"; |
| 251 |
$conn->write($buf, length($buf)); |
| 252 |
eval { $conn->close() }; |
| 253 |
|
| 254 |
$resp_code = $client->response_code(); |
| 255 |
$resp_msg = $client->response_msg(); |
| 256 |
|
| 257 |
my $expected; |
| 258 |
|
| 259 |
$expected = 552; |
| 260 |
$self->assert($expected == $resp_code, |
| 261 |
test_msg("Expected $expected, got $resp_code")); |
| 262 |
|
| 263 |
$expected = 'Transfer aborted. ((Disc|Disk) quota exceeded|File too large)'; |
| 264 |
$self->assert(qr/$expected/, $resp_msg, |
| 265 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 266 |
}; |
| 267 |
|
| 268 |
if ($@) { |
| 269 |
$ex = $@; |
| 270 |
} |
| 271 |
|
| 272 |
$wfh->print("done\n"); |
| 273 |
$wfh->flush(); |
| 274 |
|
| 275 |
} else { |
| 276 |
eval { server_wait($config_file, $rfh) }; |
| 277 |
if ($@) { |
| 278 |
warn($@); |
| 279 |
exit 1; |
| 280 |
} |
| 281 |
|
| 282 |
exit 0; |
| 283 |
} |
| 284 |
|
| 285 |
# Stop server |
| 286 |
server_stop($pid_file); |
| 287 |
|
| 288 |
$self->assert_child_ok($pid); |
| 289 |
|
| 290 |
if ($ex) { |
| 291 |
die($ex); |
| 292 |
} |
| 293 |
|
| 294 |
unlink($log_file); |
| 295 |
} |
| 296 |
|
| 297 |
sub maxstorefilesize_appe_bug3649 { |
| 298 |
my $self = shift; |
| 299 |
my $tmpdir = $self->{tmpdir}; |
| 300 |
|
| 301 |
my $config_file = "$tmpdir/config.conf"; |
| 302 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 303 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 304 |
|
| 305 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 306 |
|
| 307 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 308 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 309 |
|
| 310 |
my $user = 'proftpd'; |
| 311 |
my $passwd = 'test'; |
| 312 |
my $group = 'ftpd'; |
| 313 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 314 |
my $uid = 500; |
| 315 |
my $gid = 500; |
| 316 |
|
| 317 |
# Make sure that, if we're running as root, that the home directory has |
| 318 |
# permissions/privs set for the account we create |
| 319 |
if ($< == 0) { |
| 320 |
unless (chmod(0755, $home_dir)) { |
| 321 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 322 |
} |
| 323 |
|
| 324 |
unless (chown($uid, $gid, $home_dir)) { |
| 325 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 330 |
'/bin/bash'); |
| 331 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 332 |
|
| 333 |
my $dst_file = File::Spec->rel2abs("$tmpdir/foo.txt"); |
| 334 |
if (open(my $fh, "> $dst_file")) { |
| 335 |
print $fh "ABC" x 32; |
| 336 |
unless (close($fh)) { |
| 337 |
die("Can't write $dst_file: $!"); |
| 338 |
} |
| 339 |
|
| 340 |
} else { |
| 341 |
die("Can't open $dst_file: $!"); |
| 342 |
} |
| 343 |
|
| 344 |
my $max_sz = 128; |
| 345 |
|
| 346 |
my $config = { |
| 347 |
PidFile => $pid_file, |
| 348 |
ScoreboardFile => $scoreboard_file, |
| 349 |
SystemLog => $log_file, |
| 350 |
|
| 351 |
AuthUserFile => $auth_user_file, |
| 352 |
AuthGroupFile => $auth_group_file, |
| 353 |
AuthOrder => 'mod_auth_file.c', |
| 354 |
|
| 355 |
AllowOverwrite => 'on', |
| 356 |
AllowStoreRestart => 'on', |
| 357 |
MaxStoreFileSize => "$max_sz B", |
| 358 |
|
| 359 |
IfModules => { |
| 360 |
'mod_delay.c' => { |
| 361 |
DelayEngine => 'off', |
| 362 |
}, |
| 363 |
}, |
| 364 |
}; |
| 365 |
|
| 366 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 367 |
|
| 368 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 369 |
# the child will indicate when it's done with its test by writing a message |
| 370 |
# to the parent. |
| 371 |
my ($rfh, $wfh); |
| 372 |
unless (pipe($rfh, $wfh)) { |
| 373 |
die("Can't open pipe: $!"); |
| 374 |
} |
| 375 |
|
| 376 |
my $ex; |
| 377 |
|
| 378 |
# Fork child |
| 379 |
$self->handle_sigchld(); |
| 380 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 381 |
if ($pid) { |
| 382 |
eval { |
| 383 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 384 |
$client->login($user, $passwd); |
| 385 |
|
| 386 |
my ($resp_code, $resp_msg); |
| 387 |
|
| 388 |
my $conn = $client->appe_raw('foo.txt'); |
| 389 |
unless ($conn) { |
| 390 |
die("APPE failed: " . $client->response_code() . " " . |
| 391 |
$client->response_msg()); |
| 392 |
} |
| 393 |
|
| 394 |
my $buf = "DEF" x 32; |
| 395 |
$conn->write($buf, length($buf), 25); |
| 396 |
eval { $conn->close() }; |
| 397 |
|
| 398 |
$resp_code = $client->response_code(); |
| 399 |
$resp_msg = $client->response_msg(); |
| 400 |
|
| 401 |
my $expected; |
| 402 |
|
| 403 |
$expected = 552; |
| 404 |
$self->assert($expected == $resp_code, |
| 405 |
test_msg("Expected $expected, got $resp_code")); |
| 406 |
|
| 407 |
$expected = 'Transfer aborted. ((Disc|Disk) quota exceeded|File too large)'; |
| 408 |
$self->assert(qr/$expected/, $resp_msg, |
| 409 |
test_msg("Expected '$expected', got '$resp_msg'")); |
| 410 |
|
| 411 |
my $sz = -s $dst_file; |
| 412 |
$self->assert($sz <= $max_sz, |
| 413 |
test_msg("Expected <= $max_sz, got $sz")); |
| 414 |
}; |
| 415 |
|
| 416 |
if ($@) { |
| 417 |
$ex = $@; |
| 418 |
} |
| 419 |
|
| 420 |
$wfh->print("done\n"); |
| 421 |
$wfh->flush(); |
| 422 |
|
| 423 |
} else { |
| 424 |
eval { server_wait($config_file, $rfh) }; |
| 425 |
if ($@) { |
| 426 |
warn($@); |
| 427 |
exit 1; |
| 428 |
} |
| 429 |
|
| 430 |
exit 0; |
| 431 |
} |
| 432 |
|
| 433 |
# Stop server |
| 434 |
server_stop($pid_file); |
| 435 |
|
| 436 |
$self->assert_child_ok($pid); |
| 437 |
|
| 438 |
if ($ex) { |
| 439 |
die($ex); |
| 440 |
} |
| 441 |
|
| 442 |
unlink($log_file); |
| 443 |
} |
| 444 |
|
| 445 |
1; |