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