| 1 |
package ProFTPD::Tests::Modules::mod_ifsession; |
| 2 |
|
| 3 |
use lib qw(t/lib); |
| 4 |
use base qw(ProFTPD::TestSuite::Child); |
| 5 |
use strict; |
| 6 |
|
| 7 |
use File::Copy; |
| 8 |
use File::Path qw(mkpath); |
| 9 |
use File::Spec; |
| 10 |
use IO::Handle; |
| 11 |
use POSIX qw(:fcntl_h); |
| 12 |
|
| 13 |
use ProFTPD::TestSuite::FTP; |
| 14 |
use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite); |
| 15 |
|
| 16 |
$| = 1; |
| 17 |
|
| 18 |
my $order = 0; |
| 19 |
|
| 20 |
my $TESTS = { |
| 21 |
ifuser_allowoverwrite => { |
| 22 |
order => ++$order, |
| 23 |
test_class => [qw(forking)], |
| 24 |
}, |
| 25 |
|
| 26 |
ifgroup_dir_allow_mkd_bug3467 => { |
| 27 |
order => ++$order, |
| 28 |
test_class => [qw(bug forking rootprivs)], |
| 29 |
}, |
| 30 |
|
| 31 |
ifuser_dir_allow_mkd_bug3467 => { |
| 32 |
order => ++$order, |
| 33 |
test_class => [qw(bug forking)], |
| 34 |
}, |
| 35 |
|
| 36 |
ifclass_dir_allow_mkd_bug3467 => { |
| 37 |
order => ++$order, |
| 38 |
test_class => [qw(bug forking)], |
| 39 |
}, |
| 40 |
|
| 41 |
ifuser_login_deny_by_ip => { |
| 42 |
order => ++$order, |
| 43 |
test_class => [qw(forking)], |
| 44 |
}, |
| 45 |
|
| 46 |
ifuser_login_deny_by_user => { |
| 47 |
order => ++$order, |
| 48 |
test_class => [qw(forking)], |
| 49 |
}, |
| 50 |
|
| 51 |
ifgroup_ifclass_login_allowclass_bug3547 => { |
| 52 |
order => ++$order, |
| 53 |
test_class => [qw(bug forking)], |
| 54 |
}, |
| 55 |
|
| 56 |
ifuser_regex_login_deny_by_ip_bug3625 => { |
| 57 |
order => ++$order, |
| 58 |
test_class => [qw(bug forking)], |
| 59 |
}, |
| 60 |
|
| 61 |
ifauthenticated_bug3629 => { |
| 62 |
order => ++$order, |
| 63 |
test_class => [qw(bug forking)], |
| 64 |
}, |
| 65 |
|
| 66 |
ifgroup_displaylogin_bug3882 => { |
| 67 |
order => ++$order, |
| 68 |
test_class => [qw(bug forking rootprivs)], |
| 69 |
}, |
| 70 |
|
| 71 |
ifgroup_dir_allow_stor_bug3881 => { |
| 72 |
order => ++$order, |
| 73 |
test_class => [qw(bug forking rootprivs)], |
| 74 |
}, |
| 75 |
|
| 76 |
ifgroup_dir_allow_stor_bug3881_sftp => { |
| 77 |
order => ++$order, |
| 78 |
test_class => [qw(bug forking mod_sftp rootprivs)], |
| 79 |
}, |
| 80 |
|
| 81 |
ifclass_global_no_logging => { |
| 82 |
order => ++$order, |
| 83 |
test_class => [qw(bug forking)], |
| 84 |
}, |
| 85 |
|
| 86 |
ifuser_no_pass_bug4199 => { |
| 87 |
order => ++$order, |
| 88 |
test_class => [qw(bug mod_tls forking)], |
| 89 |
}, |
| 90 |
|
| 91 |
ifclass_and_not_classes => { |
| 92 |
order => ++$order, |
| 93 |
test_class => [qw(bug forking)], |
| 94 |
}, |
| 95 |
|
| 96 |
ifuser_directory_bug4315 => { |
| 97 |
order => ++$order, |
| 98 |
test_class => [qw(bug forking)], |
| 99 |
}, |
| 100 |
|
| 101 |
ifsess_options_per_unauthenticated_user => { |
| 102 |
order => ++$order, |
| 103 |
test_class => [qw(bug forking)], |
| 104 |
}, |
| 105 |
|
| 106 |
}; |
| 107 |
|
| 108 |
sub new { |
| 109 |
return shift()->SUPER::new(@_); |
| 110 |
} |
| 111 |
|
| 112 |
sub list_tests { |
| 113 |
return testsuite_get_runnable_tests($TESTS); |
| 114 |
} |
| 115 |
|
| 116 |
sub set_up { |
| 117 |
my $self = shift; |
| 118 |
$self->SUPER::set_up(@_); |
| 119 |
|
| 120 |
# Make sure that mod_sftp does not complain about permissions on the hostkey |
| 121 |
# files. |
| 122 |
|
| 123 |
my $rsa_host_key = File::Spec->rel2abs("t/etc/modules/mod_sftp/ssh_host_rsa_key"); |
| 124 |
my $dsa_host_key = File::Spec->rel2abs("t/etc/modules/mod_sftp/ssh_host_dsa_key"); |
| 125 |
|
| 126 |
unless (chmod(0400, $rsa_host_key, $dsa_host_key)) { |
| 127 |
die("Can't set perms on $rsa_host_key, $dsa_host_key: $!"); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
sub ifuser_allowoverwrite { |
| 132 |
my $self = shift; |
| 133 |
my $tmpdir = $self->{tmpdir}; |
| 134 |
|
| 135 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 136 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 137 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 138 |
|
| 139 |
my $log_file = test_get_logfile(); |
| 140 |
|
| 141 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 142 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 143 |
|
| 144 |
my $user = 'proftpd'; |
| 145 |
my $passwd = 'test'; |
| 146 |
my $group = 'ftpd'; |
| 147 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 148 |
my $uid = 500; |
| 149 |
my $gid = 500; |
| 150 |
|
| 151 |
my $ftpaccess_file = File::Spec->rel2abs("$tmpdir/.ftpaccess"); |
| 152 |
if (open(my $fh, "> $ftpaccess_file")) { |
| 153 |
print $fh "AllowOverwrite on\n"; |
| 154 |
|
| 155 |
unless (close($fh)) { |
| 156 |
die("Can't write $ftpaccess_file: $!"); |
| 157 |
} |
| 158 |
|
| 159 |
} else { |
| 160 |
die("Can't open $ftpaccess_file: $!"); |
| 161 |
} |
| 162 |
|
| 163 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 164 |
if (open(my $fh, "> $test_file")) { |
| 165 |
close($fh); |
| 166 |
|
| 167 |
} else { |
| 168 |
die("Can't open $test_file: $!"); |
| 169 |
} |
| 170 |
|
| 171 |
# Make sure that, if we're running as root, that the home directory has |
| 172 |
# permissions/privs set for the account we create |
| 173 |
if ($< == 0) { |
| 174 |
unless (chmod(0755, $home_dir, $test_file)) { |
| 175 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 176 |
} |
| 177 |
|
| 178 |
unless (chown($uid, $gid, $home_dir, $test_file)) { |
| 179 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 184 |
'/bin/bash'); |
| 185 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 186 |
|
| 187 |
my $config = { |
| 188 |
PidFile => $pid_file, |
| 189 |
ScoreboardFile => $scoreboard_file, |
| 190 |
SystemLog => $log_file, |
| 191 |
|
| 192 |
AuthUserFile => $auth_user_file, |
| 193 |
AuthGroupFile => $auth_group_file, |
| 194 |
AuthOrder => 'mod_auth_file.c', |
| 195 |
|
| 196 |
AllowOverride => 'on', |
| 197 |
|
| 198 |
IfModules => { |
| 199 |
'mod_delay.c' => { |
| 200 |
DelayEngine => 'off', |
| 201 |
}, |
| 202 |
}, |
| 203 |
}; |
| 204 |
|
| 205 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 206 |
|
| 207 |
# Append the mod_ifsession config to the end of the config file |
| 208 |
if (open(my $fh, ">> $config_file")) { |
| 209 |
print $fh <<EOC; |
| 210 |
<IfModule mod_ifsession.c> |
| 211 |
<IfUser $user> |
| 212 |
AllowOverride on |
| 213 |
</IfUser> |
| 214 |
|
| 215 |
<IfUser !$user> |
| 216 |
AllowOverride off |
| 217 |
</IfUser> |
| 218 |
</IfModule> |
| 219 |
EOC |
| 220 |
unless (close($fh)) { |
| 221 |
die("Can't write $config_file: $!"); |
| 222 |
} |
| 223 |
|
| 224 |
} else { |
| 225 |
die("Can't open $config_file: $!"); |
| 226 |
} |
| 227 |
|
| 228 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 229 |
# the child will indicate when it's done with its test by writing a message |
| 230 |
# to the parent. |
| 231 |
my ($rfh, $wfh); |
| 232 |
unless (pipe($rfh, $wfh)) { |
| 233 |
die("Can't open pipe: $!"); |
| 234 |
} |
| 235 |
|
| 236 |
my $ex; |
| 237 |
|
| 238 |
# Fork child |
| 239 |
$self->handle_sigchld(); |
| 240 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 241 |
if ($pid) { |
| 242 |
eval { |
| 243 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 244 |
$client->login($user, $passwd); |
| 245 |
|
| 246 |
my $conn = $client->stor_raw('test.txt'); |
| 247 |
unless ($conn) { |
| 248 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 249 |
$client->response_msg()); |
| 250 |
} |
| 251 |
|
| 252 |
eval { $conn->close() }; |
| 253 |
|
| 254 |
my $resp_code = $client->response_code(); |
| 255 |
my $resp_msg = $client->response_msg(); |
| 256 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 257 |
|
| 258 |
$client->quit(); |
| 259 |
}; |
| 260 |
|
| 261 |
if ($@) { |
| 262 |
$ex = $@; |
| 263 |
} |
| 264 |
|
| 265 |
$wfh->print("done\n"); |
| 266 |
$wfh->flush(); |
| 267 |
|
| 268 |
} else { |
| 269 |
eval { server_wait($config_file, $rfh) }; |
| 270 |
if ($@) { |
| 271 |
warn($@); |
| 272 |
exit 1; |
| 273 |
} |
| 274 |
|
| 275 |
exit 0; |
| 276 |
} |
| 277 |
|
| 278 |
# Stop server |
| 279 |
server_stop($pid_file); |
| 280 |
|
| 281 |
$self->assert_child_ok($pid); |
| 282 |
|
| 283 |
if ($ex) { |
| 284 |
test_append_logfile($log_file, $ex); |
| 285 |
unlink($log_file); |
| 286 |
|
| 287 |
die($ex); |
| 288 |
} |
| 289 |
|
| 290 |
unlink($log_file); |
| 291 |
} |
| 292 |
|
| 293 |
sub ifgroup_dir_allow_mkd_bug3467 { |
| 294 |
my $self = shift; |
| 295 |
my $tmpdir = $self->{tmpdir}; |
| 296 |
|
| 297 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 298 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 299 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 300 |
|
| 301 |
my $log_file = test_get_logfile(); |
| 302 |
|
| 303 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 304 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 305 |
|
| 306 |
my $test_file = File::Spec->rel2abs($config_file); |
| 307 |
|
| 308 |
my $user = 'proftpd'; |
| 309 |
my $passwd = 'test'; |
| 310 |
my $group = 'ftpd'; |
| 311 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 312 |
my $uid = 500; |
| 313 |
my $gid = 500; |
| 314 |
|
| 315 |
my $user_dir = File::Spec->rel2abs("$home_dir/$user"); |
| 316 |
mkpath($user_dir); |
| 317 |
|
| 318 |
my $ftpaccess_file = File::Spec->rel2abs("$user_dir/.ftpaccess"); |
| 319 |
if (open(my $fh, "> $ftpaccess_file")) { |
| 320 |
print $fh "Umask 022\n"; |
| 321 |
|
| 322 |
unless (close($fh)) { |
| 323 |
die("Can't write $ftpaccess_file: $!"); |
| 324 |
} |
| 325 |
|
| 326 |
} else { |
| 327 |
die("Can't open $ftpaccess_file: $!"); |
| 328 |
} |
| 329 |
|
| 330 |
# Make sure that, if we're running as root, that the home directory has |
| 331 |
# permissions/privs set for the account we create |
| 332 |
if ($< == 0) { |
| 333 |
unless (chmod(0755, $home_dir, $user_dir)) { |
| 334 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 335 |
} |
| 336 |
|
| 337 |
unless (chown($uid, $gid, $home_dir, $user_dir)) { |
| 338 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 343 |
'/bin/bash'); |
| 344 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 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 |
AllowOverride => 'on', |
| 356 |
DefaultRoot => "~ $group", |
| 357 |
|
| 358 |
IfModules => { |
| 359 |
'mod_delay.c' => { |
| 360 |
DelayEngine => 'off', |
| 361 |
}, |
| 362 |
}, |
| 363 |
}; |
| 364 |
|
| 365 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 366 |
|
| 367 |
# Append the mod_ifsession config to the end of the config file |
| 368 |
if (open(my $fh, ">> $config_file")) { |
| 369 |
print $fh <<EOC; |
| 370 |
<Directory /> |
| 371 |
<Limit ALL> |
| 372 |
DenyAll |
| 373 |
</Limit> |
| 374 |
</Directory> |
| 375 |
|
| 376 |
<IfGroup $group> |
| 377 |
<Directory ~> |
| 378 |
<Limit ALL> |
| 379 |
AllowAll |
| 380 |
</Limit> |
| 381 |
</Directory> |
| 382 |
</IfGroup> |
| 383 |
EOC |
| 384 |
unless (close($fh)) { |
| 385 |
die("Can't write $config_file: $!"); |
| 386 |
} |
| 387 |
|
| 388 |
} else { |
| 389 |
die("Can't open $config_file: $!"); |
| 390 |
} |
| 391 |
|
| 392 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 393 |
# the child will indicate when it's done with its test by writing a message |
| 394 |
# to the parent. |
| 395 |
my ($rfh, $wfh); |
| 396 |
unless (pipe($rfh, $wfh)) { |
| 397 |
die("Can't open pipe: $!"); |
| 398 |
} |
| 399 |
|
| 400 |
my $ex; |
| 401 |
|
| 402 |
# Fork child |
| 403 |
$self->handle_sigchld(); |
| 404 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 405 |
if ($pid) { |
| 406 |
eval { |
| 407 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 408 |
$client->login($user, $passwd); |
| 409 |
|
| 410 |
$client->pwd(); |
| 411 |
$client->mkd('foo'); |
| 412 |
$client->quit(); |
| 413 |
}; |
| 414 |
|
| 415 |
if ($@) { |
| 416 |
$ex = $@; |
| 417 |
} |
| 418 |
|
| 419 |
$wfh->print("done\n"); |
| 420 |
$wfh->flush(); |
| 421 |
|
| 422 |
} else { |
| 423 |
eval { server_wait($config_file, $rfh) }; |
| 424 |
if ($@) { |
| 425 |
warn($@); |
| 426 |
exit 1; |
| 427 |
} |
| 428 |
|
| 429 |
exit 0; |
| 430 |
} |
| 431 |
|
| 432 |
# Stop server |
| 433 |
server_stop($pid_file); |
| 434 |
|
| 435 |
$self->assert_child_ok($pid); |
| 436 |
|
| 437 |
if ($ex) { |
| 438 |
test_append_logfile($log_file, $ex); |
| 439 |
unlink($log_file); |
| 440 |
|
| 441 |
die($ex); |
| 442 |
} |
| 443 |
|
| 444 |
unlink($log_file); |
| 445 |
} |
| 446 |
|
| 447 |
sub ifuser_dir_allow_mkd_bug3467 { |
| 448 |
my $self = shift; |
| 449 |
my $tmpdir = $self->{tmpdir}; |
| 450 |
|
| 451 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 452 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 453 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 454 |
|
| 455 |
my $log_file = test_get_logfile(); |
| 456 |
|
| 457 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 458 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 459 |
|
| 460 |
my $test_file = File::Spec->rel2abs($config_file); |
| 461 |
|
| 462 |
my $user = 'proftpd'; |
| 463 |
my $passwd = 'test'; |
| 464 |
my $group = 'ftpd'; |
| 465 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 466 |
my $uid = 500; |
| 467 |
my $gid = 500; |
| 468 |
|
| 469 |
# Make sure that, if we're running as root, that the home directory has |
| 470 |
# permissions/privs set for the account we create |
| 471 |
if ($< == 0) { |
| 472 |
unless (chmod(0755, $home_dir)) { |
| 473 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 474 |
} |
| 475 |
|
| 476 |
unless (chown($uid, $gid, $home_dir)) { |
| 477 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 482 |
'/bin/bash'); |
| 483 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 484 |
|
| 485 |
my $config = { |
| 486 |
PidFile => $pid_file, |
| 487 |
ScoreboardFile => $scoreboard_file, |
| 488 |
SystemLog => $log_file, |
| 489 |
TraceLog => $log_file, |
| 490 |
Trace => 'directory:20', |
| 491 |
|
| 492 |
AuthUserFile => $auth_user_file, |
| 493 |
AuthGroupFile => $auth_group_file, |
| 494 |
AuthOrder => 'mod_auth_file.c', |
| 495 |
|
| 496 |
IfModules => { |
| 497 |
'mod_delay.c' => { |
| 498 |
DelayEngine => 'off', |
| 499 |
}, |
| 500 |
}, |
| 501 |
}; |
| 502 |
|
| 503 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 504 |
|
| 505 |
# Append the mod_ifsession config to the end of the config file |
| 506 |
if (open(my $fh, ">> $config_file")) { |
| 507 |
my $limit_dir = $home_dir; |
| 508 |
if ($^O eq 'darwin') { |
| 509 |
# MacOSX hack |
| 510 |
$limit_dir = ('/private' . $home_dir); |
| 511 |
} |
| 512 |
|
| 513 |
print $fh <<EOC; |
| 514 |
<Directory /> |
| 515 |
<Limit ALL> |
| 516 |
DenyAll |
| 517 |
</Limit> |
| 518 |
</Directory> |
| 519 |
|
| 520 |
<IfUser $user> |
| 521 |
<Directory $limit_dir> |
| 522 |
<Limit MKD> |
| 523 |
AllowAll |
| 524 |
</Limit> |
| 525 |
</Directory> |
| 526 |
</IfUser> |
| 527 |
EOC |
| 528 |
unless (close($fh)) { |
| 529 |
die("Can't write $config_file: $!"); |
| 530 |
} |
| 531 |
|
| 532 |
} else { |
| 533 |
die("Can't open $config_file: $!"); |
| 534 |
} |
| 535 |
|
| 536 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 537 |
# the child will indicate when it's done with its test by writing a message |
| 538 |
# to the parent. |
| 539 |
my ($rfh, $wfh); |
| 540 |
unless (pipe($rfh, $wfh)) { |
| 541 |
die("Can't open pipe: $!"); |
| 542 |
} |
| 543 |
|
| 544 |
my $ex; |
| 545 |
|
| 546 |
# Fork child |
| 547 |
$self->handle_sigchld(); |
| 548 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 549 |
if ($pid) { |
| 550 |
eval { |
| 551 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 552 |
$client->login($user, $passwd); |
| 553 |
|
| 554 |
$client->mkd('foo'); |
| 555 |
$client->quit(); |
| 556 |
}; |
| 557 |
|
| 558 |
if ($@) { |
| 559 |
$ex = $@; |
| 560 |
} |
| 561 |
|
| 562 |
$wfh->print("done\n"); |
| 563 |
$wfh->flush(); |
| 564 |
|
| 565 |
} else { |
| 566 |
eval { server_wait($config_file, $rfh) }; |
| 567 |
if ($@) { |
| 568 |
warn($@); |
| 569 |
exit 1; |
| 570 |
} |
| 571 |
|
| 572 |
exit 0; |
| 573 |
} |
| 574 |
|
| 575 |
# Stop server |
| 576 |
server_stop($pid_file); |
| 577 |
|
| 578 |
$self->assert_child_ok($pid); |
| 579 |
|
| 580 |
if ($ex) { |
| 581 |
test_append_logfile($log_file, $ex); |
| 582 |
unlink($log_file); |
| 583 |
|
| 584 |
die($ex); |
| 585 |
} |
| 586 |
|
| 587 |
unlink($log_file); |
| 588 |
} |
| 589 |
|
| 590 |
sub ifclass_dir_allow_mkd_bug3467 { |
| 591 |
my $self = shift; |
| 592 |
my $tmpdir = $self->{tmpdir}; |
| 593 |
|
| 594 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 595 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 596 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 597 |
|
| 598 |
my $log_file = test_get_logfile(); |
| 599 |
|
| 600 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 601 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 602 |
|
| 603 |
my $test_file = File::Spec->rel2abs($config_file); |
| 604 |
|
| 605 |
my $user = 'proftpd'; |
| 606 |
my $passwd = 'test'; |
| 607 |
my $group = 'ftpd'; |
| 608 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 609 |
my $uid = 500; |
| 610 |
my $gid = 500; |
| 611 |
|
| 612 |
# Make sure that, if we're running as root, that the home directory has |
| 613 |
# permissions/privs set for the account we create |
| 614 |
if ($< == 0) { |
| 615 |
unless (chmod(0755, $home_dir)) { |
| 616 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 617 |
} |
| 618 |
|
| 619 |
unless (chown($uid, $gid, $home_dir)) { |
| 620 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 625 |
'/bin/bash'); |
| 626 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 627 |
|
| 628 |
my $config = { |
| 629 |
PidFile => $pid_file, |
| 630 |
ScoreboardFile => $scoreboard_file, |
| 631 |
SystemLog => $log_file, |
| 632 |
TraceLog => $log_file, |
| 633 |
Trace => 'directory:20', |
| 634 |
|
| 635 |
AuthUserFile => $auth_user_file, |
| 636 |
AuthGroupFile => $auth_group_file, |
| 637 |
AuthOrder => 'mod_auth_file.c', |
| 638 |
|
| 639 |
IfModules => { |
| 640 |
'mod_delay.c' => { |
| 641 |
DelayEngine => 'off', |
| 642 |
}, |
| 643 |
}, |
| 644 |
}; |
| 645 |
|
| 646 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 647 |
|
| 648 |
# Append the mod_ifsession config to the end of the config file |
| 649 |
if (open(my $fh, ">> $config_file")) { |
| 650 |
my $limit_dir = $home_dir; |
| 651 |
if ($^O eq 'darwin') { |
| 652 |
$limit_dir = ('/private' . $home_dir); |
| 653 |
} |
| 654 |
|
| 655 |
print $fh <<EOC; |
| 656 |
<Class local> |
| 657 |
From 127.0.0.1 |
| 658 |
</Class> |
| 659 |
|
| 660 |
<Directory /> |
| 661 |
<Limit ALL> |
| 662 |
DenyAll |
| 663 |
</Limit> |
| 664 |
</Directory> |
| 665 |
|
| 666 |
<IfClass local> |
| 667 |
<Directory $limit_dir> |
| 668 |
<Limit MKD> |
| 669 |
AllowAll |
| 670 |
</Limit> |
| 671 |
</Directory> |
| 672 |
</IfClass> |
| 673 |
EOC |
| 674 |
unless (close($fh)) { |
| 675 |
die("Can't write $config_file: $!"); |
| 676 |
} |
| 677 |
|
| 678 |
} else { |
| 679 |
die("Can't open $config_file: $!"); |
| 680 |
} |
| 681 |
|
| 682 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 683 |
# the child will indicate when it's done with its test by writing a message |
| 684 |
# to the parent. |
| 685 |
my ($rfh, $wfh); |
| 686 |
unless (pipe($rfh, $wfh)) { |
| 687 |
die("Can't open pipe: $!"); |
| 688 |
} |
| 689 |
|
| 690 |
my $ex; |
| 691 |
|
| 692 |
# Fork child |
| 693 |
$self->handle_sigchld(); |
| 694 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 695 |
if ($pid) { |
| 696 |
eval { |
| 697 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 698 |
$client->login($user, $passwd); |
| 699 |
|
| 700 |
$client->mkd('foo'); |
| 701 |
$client->quit(); |
| 702 |
}; |
| 703 |
|
| 704 |
if ($@) { |
| 705 |
$ex = $@; |
| 706 |
} |
| 707 |
|
| 708 |
$wfh->print("done\n"); |
| 709 |
$wfh->flush(); |
| 710 |
|
| 711 |
} else { |
| 712 |
eval { server_wait($config_file, $rfh) }; |
| 713 |
if ($@) { |
| 714 |
warn($@); |
| 715 |
exit 1; |
| 716 |
} |
| 717 |
|
| 718 |
exit 0; |
| 719 |
} |
| 720 |
|
| 721 |
# Stop server |
| 722 |
server_stop($pid_file); |
| 723 |
|
| 724 |
$self->assert_child_ok($pid); |
| 725 |
|
| 726 |
if ($ex) { |
| 727 |
test_append_logfile($log_file, $ex); |
| 728 |
unlink($log_file); |
| 729 |
|
| 730 |
die($ex); |
| 731 |
} |
| 732 |
|
| 733 |
unlink($log_file); |
| 734 |
} |
| 735 |
|
| 736 |
sub ifuser_login_deny_by_ip { |
| 737 |
my $self = shift; |
| 738 |
my $tmpdir = $self->{tmpdir}; |
| 739 |
my $setup = test_setup($tmpdir, 'ifsess'); |
| 740 |
|
| 741 |
my $config = { |
| 742 |
PidFile => $setup->{pid_file}, |
| 743 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 744 |
SystemLog => $setup->{log_file}, |
| 745 |
|
| 746 |
AuthUserFile => $setup->{auth_user_file}, |
| 747 |
AuthGroupFile => $setup->{auth_group_file}, |
| 748 |
AuthOrder => 'mod_auth_file.c', |
| 749 |
|
| 750 |
IfModules => { |
| 751 |
'mod_delay.c' => { |
| 752 |
DelayEngine => 'off', |
| 753 |
}, |
| 754 |
}, |
| 755 |
}; |
| 756 |
|
| 757 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 758 |
$config); |
| 759 |
|
| 760 |
# Inspired by: |
| 761 |
# |
| 762 |
# http://forums.proftpd.org/smf/index.php/topic,5153.0.html |
| 763 |
# |
| 764 |
# Append the mod_ifsession config to the end of the config file |
| 765 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 766 |
print $fh <<EOC; |
| 767 |
<IfModule mod_ifsession.c> |
| 768 |
<IfUser $setup->{user}> |
| 769 |
<Limit LOGIN> |
| 770 |
Deny from 127.0.0.1 |
| 771 |
</Limit> |
| 772 |
</IfUser> |
| 773 |
</IfModule> |
| 774 |
EOC |
| 775 |
unless (close($fh)) { |
| 776 |
die("Can't write $setup->{config_file}: $!"); |
| 777 |
} |
| 778 |
|
| 779 |
} else { |
| 780 |
die("Can't open $setup->{config_file}: $!"); |
| 781 |
} |
| 782 |
|
| 783 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 784 |
# the child will indicate when it's done with its test by writing a message |
| 785 |
# to the parent. |
| 786 |
my ($rfh, $wfh); |
| 787 |
unless (pipe($rfh, $wfh)) { |
| 788 |
die("Can't open pipe: $!"); |
| 789 |
} |
| 790 |
|
| 791 |
my $ex; |
| 792 |
|
| 793 |
# Fork child |
| 794 |
$self->handle_sigchld(); |
| 795 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 796 |
if ($pid) { |
| 797 |
eval { |
| 798 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 799 |
eval { $client->login($setup->{user}, $setup->{passwd}) }; |
| 800 |
unless ($@) { |
| 801 |
die("Login succeeded unexpectedly"); |
| 802 |
} |
| 803 |
}; |
| 804 |
if ($@) { |
| 805 |
$ex = $@; |
| 806 |
} |
| 807 |
|
| 808 |
$wfh->print("done\n"); |
| 809 |
$wfh->flush(); |
| 810 |
|
| 811 |
} else { |
| 812 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 813 |
if ($@) { |
| 814 |
warn($@); |
| 815 |
exit 1; |
| 816 |
} |
| 817 |
|
| 818 |
exit 0; |
| 819 |
} |
| 820 |
|
| 821 |
# Stop server |
| 822 |
server_stop($setup->{pid_file}); |
| 823 |
$self->assert_child_ok($pid); |
| 824 |
|
| 825 |
test_cleanup($setup->{log_file}, $ex); |
| 826 |
} |
| 827 |
|
| 828 |
sub ifuser_login_deny_by_user { |
| 829 |
my $self = shift; |
| 830 |
my $tmpdir = $self->{tmpdir}; |
| 831 |
my $setup = test_setup($tmpdir, 'ifsess'); |
| 832 |
|
| 833 |
my $config = { |
| 834 |
PidFile => $setup->{pid_file}, |
| 835 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 836 |
SystemLog => $setup->{log_file}, |
| 837 |
|
| 838 |
AuthUserFile => $setup->{auth_user_file}, |
| 839 |
AuthGroupFile => $setup->{auth_group_file}, |
| 840 |
AuthOrder => 'mod_auth_file.c', |
| 841 |
|
| 842 |
IfModules => { |
| 843 |
'mod_delay.c' => { |
| 844 |
DelayEngine => 'off', |
| 845 |
}, |
| 846 |
}, |
| 847 |
}; |
| 848 |
|
| 849 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 850 |
$config); |
| 851 |
|
| 852 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 853 |
print $fh <<EOC; |
| 854 |
<IfModule mod_ifsession.c> |
| 855 |
<IfUser $setup->{user}> |
| 856 |
<Limit LOGIN> |
| 857 |
DenyUser $setup->{user} |
| 858 |
</Limit> |
| 859 |
</IfUser> |
| 860 |
</IfModule> |
| 861 |
EOC |
| 862 |
unless (close($fh)) { |
| 863 |
die("Can't write $setup->{config_file}: $!"); |
| 864 |
} |
| 865 |
|
| 866 |
} else { |
| 867 |
die("Can't open $setup->{config_file}: $!"); |
| 868 |
} |
| 869 |
|
| 870 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 871 |
# the child will indicate when it's done with its test by writing a message |
| 872 |
# to the parent. |
| 873 |
my ($rfh, $wfh); |
| 874 |
unless (pipe($rfh, $wfh)) { |
| 875 |
die("Can't open pipe: $!"); |
| 876 |
} |
| 877 |
|
| 878 |
my $ex; |
| 879 |
|
| 880 |
# Fork child |
| 881 |
$self->handle_sigchld(); |
| 882 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 883 |
if ($pid) { |
| 884 |
eval { |
| 885 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 886 |
eval { $client->login($setup->{user}, $setup->{passwd}) }; |
| 887 |
unless ($@) { |
| 888 |
die("Login succeeded unexpectedly"); |
| 889 |
} |
| 890 |
}; |
| 891 |
if ($@) { |
| 892 |
$ex = $@; |
| 893 |
} |
| 894 |
|
| 895 |
$wfh->print("done\n"); |
| 896 |
$wfh->flush(); |
| 897 |
|
| 898 |
} else { |
| 899 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 900 |
if ($@) { |
| 901 |
warn($@); |
| 902 |
exit 1; |
| 903 |
} |
| 904 |
|
| 905 |
exit 0; |
| 906 |
} |
| 907 |
|
| 908 |
# Stop server |
| 909 |
server_stop($setup->{pid_file}); |
| 910 |
$self->assert_child_ok($pid); |
| 911 |
|
| 912 |
test_cleanup($setup->{log_file}, $ex); |
| 913 |
} |
| 914 |
|
| 915 |
sub ifgroup_ifclass_login_allowclass_bug3547 { |
| 916 |
my $self = shift; |
| 917 |
my $tmpdir = $self->{tmpdir}; |
| 918 |
|
| 919 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 920 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 921 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 922 |
|
| 923 |
my $log_file = test_get_logfile(); |
| 924 |
|
| 925 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 926 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 927 |
|
| 928 |
my $user = 'proftpd'; |
| 929 |
my $passwd = 'test'; |
| 930 |
my $group = 'ftpd'; |
| 931 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 932 |
my $uid = 500; |
| 933 |
my $gid = 500; |
| 934 |
|
| 935 |
# Make sure that, if we're running as root, that the home directory has |
| 936 |
# permissions/privs set for the account we create |
| 937 |
if ($< == 0) { |
| 938 |
unless (chmod(0755, $home_dir)) { |
| 939 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 940 |
} |
| 941 |
|
| 942 |
unless (chown($uid, $gid, $home_dir)) { |
| 943 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
my $test_group = 'test'; |
| 948 |
my $test_gid = 501; |
| 949 |
|
| 950 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 951 |
'/bin/bash'); |
| 952 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 953 |
auth_group_write($auth_group_file, $test_group, $test_gid, $user); |
| 954 |
|
| 955 |
my $config = { |
| 956 |
PidFile => $pid_file, |
| 957 |
ScoreboardFile => $scoreboard_file, |
| 958 |
SystemLog => $log_file, |
| 959 |
TraceLog => $log_file, |
| 960 |
Trace => 'ifsession:20', |
| 961 |
|
| 962 |
AuthUserFile => $auth_user_file, |
| 963 |
AuthGroupFile => $auth_group_file, |
| 964 |
AuthOrder => 'mod_auth_file.c', |
| 965 |
|
| 966 |
IfModules => { |
| 967 |
'mod_delay.c' => { |
| 968 |
DelayEngine => 'off', |
| 969 |
}, |
| 970 |
}, |
| 971 |
}; |
| 972 |
|
| 973 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 974 |
|
| 975 |
if (open(my $fh, ">> $config_file")) { |
| 976 |
print $fh <<EOC; |
| 977 |
<IfModule mod_ifsession.c> |
| 978 |
<Class local> |
| 979 |
From 172.16.0.0/12 |
| 980 |
From 192.168.0.0/16 |
| 981 |
</Class> |
| 982 |
|
| 983 |
<Class test> |
| 984 |
From 127.0.0.1 |
| 985 |
</Class> |
| 986 |
|
| 987 |
<IfGroup $test_group> |
| 988 |
<Limit LOGIN> |
| 989 |
AllowClass test |
| 990 |
AllowClass local |
| 991 |
DenyAll |
| 992 |
</Limit> |
| 993 |
</IfGroup> |
| 994 |
|
| 995 |
<IfGroup !$test_group> |
| 996 |
<Limit LOGIN> |
| 997 |
AllowClass local |
| 998 |
DenyAll |
| 999 |
</Limit> |
| 1000 |
</IfGroup> |
| 1001 |
</IfModule> |
| 1002 |
EOC |
| 1003 |
unless (close($fh)) { |
| 1004 |
die("Can't write $config_file: $!"); |
| 1005 |
} |
| 1006 |
|
| 1007 |
} else { |
| 1008 |
die("Can't open $config_file: $!"); |
| 1009 |
} |
| 1010 |
|
| 1011 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1012 |
# the child will indicate when it's done with its test by writing a message |
| 1013 |
# to the parent. |
| 1014 |
my ($rfh, $wfh); |
| 1015 |
unless (pipe($rfh, $wfh)) { |
| 1016 |
die("Can't open pipe: $!"); |
| 1017 |
} |
| 1018 |
|
| 1019 |
my $ex; |
| 1020 |
|
| 1021 |
# Fork child |
| 1022 |
$self->handle_sigchld(); |
| 1023 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1024 |
if ($pid) { |
| 1025 |
eval { |
| 1026 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1027 |
$client->login($user, $passwd); |
| 1028 |
}; |
| 1029 |
|
| 1030 |
if ($@) { |
| 1031 |
$ex = $@; |
| 1032 |
} |
| 1033 |
|
| 1034 |
$wfh->print("done\n"); |
| 1035 |
$wfh->flush(); |
| 1036 |
|
| 1037 |
} else { |
| 1038 |
eval { server_wait($config_file, $rfh) }; |
| 1039 |
if ($@) { |
| 1040 |
warn($@); |
| 1041 |
exit 1; |
| 1042 |
} |
| 1043 |
|
| 1044 |
exit 0; |
| 1045 |
} |
| 1046 |
|
| 1047 |
# Stop server |
| 1048 |
server_stop($pid_file); |
| 1049 |
|
| 1050 |
$self->assert_child_ok($pid); |
| 1051 |
|
| 1052 |
if ($ex) { |
| 1053 |
test_append_logfile($log_file, $ex); |
| 1054 |
unlink($log_file); |
| 1055 |
|
| 1056 |
die($ex); |
| 1057 |
} |
| 1058 |
|
| 1059 |
unlink($log_file); |
| 1060 |
} |
| 1061 |
|
| 1062 |
sub ifuser_regex_login_deny_by_ip_bug3625 { |
| 1063 |
my $self = shift; |
| 1064 |
my $tmpdir = $self->{tmpdir}; |
| 1065 |
|
| 1066 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 1067 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 1068 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 1069 |
|
| 1070 |
my $log_file = test_get_logfile(); |
| 1071 |
|
| 1072 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 1073 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 1074 |
|
| 1075 |
my $test_file = File::Spec->rel2abs($config_file); |
| 1076 |
|
| 1077 |
my $user = 'proftpd'; |
| 1078 |
my $passwd = 'test'; |
| 1079 |
my $group = 'ftpd'; |
| 1080 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 1081 |
my $uid = 500; |
| 1082 |
my $gid = 500; |
| 1083 |
|
| 1084 |
# Make sure that, if we're running as root, that the home directory has |
| 1085 |
# permissions/privs set for the account we create |
| 1086 |
if ($< == 0) { |
| 1087 |
unless (chmod(0755, $home_dir)) { |
| 1088 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 1089 |
} |
| 1090 |
|
| 1091 |
unless (chown($uid, $gid, $home_dir)) { |
| 1092 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 1097 |
'/bin/bash'); |
| 1098 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 1099 |
|
| 1100 |
my $config = { |
| 1101 |
PidFile => $pid_file, |
| 1102 |
ScoreboardFile => $scoreboard_file, |
| 1103 |
SystemLog => $log_file, |
| 1104 |
|
| 1105 |
AuthUserFile => $auth_user_file, |
| 1106 |
AuthGroupFile => $auth_group_file, |
| 1107 |
AuthOrder => 'mod_auth_file.c', |
| 1108 |
|
| 1109 |
IfModules => { |
| 1110 |
'mod_delay.c' => { |
| 1111 |
DelayEngine => 'off', |
| 1112 |
}, |
| 1113 |
}, |
| 1114 |
}; |
| 1115 |
|
| 1116 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 1117 |
|
| 1118 |
if (open(my $fh, ">> $config_file")) { |
| 1119 |
print $fh <<EOC; |
| 1120 |
<IfModule mod_ifsession.c> |
| 1121 |
<IfUser regex $user> |
| 1122 |
<Limit LOGIN> |
| 1123 |
Deny from 127.0.0.1 |
| 1124 |
</Limit> |
| 1125 |
</IfUser> |
| 1126 |
</IfModule> |
| 1127 |
EOC |
| 1128 |
unless (close($fh)) { |
| 1129 |
die("Can't write $config_file: $!"); |
| 1130 |
} |
| 1131 |
|
| 1132 |
} else { |
| 1133 |
die("Can't open $config_file: $!"); |
| 1134 |
} |
| 1135 |
|
| 1136 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1137 |
# the child will indicate when it's done with its test by writing a message |
| 1138 |
# to the parent. |
| 1139 |
my ($rfh, $wfh); |
| 1140 |
unless (pipe($rfh, $wfh)) { |
| 1141 |
die("Can't open pipe: $!"); |
| 1142 |
} |
| 1143 |
|
| 1144 |
my $ex; |
| 1145 |
|
| 1146 |
# Fork child |
| 1147 |
$self->handle_sigchld(); |
| 1148 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1149 |
if ($pid) { |
| 1150 |
eval { |
| 1151 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1152 |
eval { $client->login($user, $passwd) }; |
| 1153 |
unless ($@) { |
| 1154 |
die("Login succeeded unexpectedly"); |
| 1155 |
} |
| 1156 |
}; |
| 1157 |
|
| 1158 |
if ($@) { |
| 1159 |
$ex = $@; |
| 1160 |
} |
| 1161 |
|
| 1162 |
$wfh->print("done\n"); |
| 1163 |
$wfh->flush(); |
| 1164 |
|
| 1165 |
} else { |
| 1166 |
eval { server_wait($config_file, $rfh) }; |
| 1167 |
if ($@) { |
| 1168 |
warn($@); |
| 1169 |
exit 1; |
| 1170 |
} |
| 1171 |
|
| 1172 |
exit 0; |
| 1173 |
} |
| 1174 |
|
| 1175 |
# Stop server |
| 1176 |
server_stop($pid_file); |
| 1177 |
|
| 1178 |
$self->assert_child_ok($pid); |
| 1179 |
|
| 1180 |
if ($ex) { |
| 1181 |
test_append_logfile($log_file, $ex); |
| 1182 |
unlink($log_file); |
| 1183 |
|
| 1184 |
die($ex); |
| 1185 |
} |
| 1186 |
|
| 1187 |
unlink($log_file); |
| 1188 |
} |
| 1189 |
|
| 1190 |
sub ifauthenticated_bug3629 { |
| 1191 |
my $self = shift; |
| 1192 |
my $tmpdir = $self->{tmpdir}; |
| 1193 |
|
| 1194 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 1195 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 1196 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 1197 |
|
| 1198 |
my $log_file = test_get_logfile(); |
| 1199 |
|
| 1200 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 1201 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 1202 |
|
| 1203 |
my $user = 'proftpd'; |
| 1204 |
my $passwd = 'test'; |
| 1205 |
my $group = 'ftpd'; |
| 1206 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 1207 |
my $uid = 500; |
| 1208 |
my $gid = 500; |
| 1209 |
|
| 1210 |
my $test_file = File::Spec->rel2abs("$tmpdir/test.txt"); |
| 1211 |
if (open(my $fh, "> $test_file")) { |
| 1212 |
close($fh); |
| 1213 |
|
| 1214 |
} else { |
| 1215 |
die("Can't open $test_file: $!"); |
| 1216 |
} |
| 1217 |
|
| 1218 |
# Make sure that, if we're running as root, that the home directory has |
| 1219 |
# permissions/privs set for the account we create |
| 1220 |
if ($< == 0) { |
| 1221 |
unless (chmod(0755, $home_dir, $test_file)) { |
| 1222 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 1223 |
} |
| 1224 |
|
| 1225 |
unless (chown($uid, $gid, $home_dir, $test_file)) { |
| 1226 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 1231 |
'/bin/bash'); |
| 1232 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 1233 |
|
| 1234 |
my $config = { |
| 1235 |
PidFile => $pid_file, |
| 1236 |
ScoreboardFile => $scoreboard_file, |
| 1237 |
SystemLog => $log_file, |
| 1238 |
TraceLog => $log_file, |
| 1239 |
Trace => 'directory:20', |
| 1240 |
|
| 1241 |
AuthUserFile => $auth_user_file, |
| 1242 |
AuthGroupFile => $auth_group_file, |
| 1243 |
AuthOrder => 'mod_auth_file.c', |
| 1244 |
|
| 1245 |
AllowOverwrite => 'on', |
| 1246 |
|
| 1247 |
IfModules => { |
| 1248 |
'mod_delay.c' => { |
| 1249 |
DelayEngine => 'off', |
| 1250 |
}, |
| 1251 |
}, |
| 1252 |
}; |
| 1253 |
|
| 1254 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 1255 |
|
| 1256 |
# Append the mod_ifsession config to the end of the config file |
| 1257 |
if (open(my $fh, ">> $config_file")) { |
| 1258 |
my $limit_dir = $home_dir; |
| 1259 |
if ($^O eq 'darwin') { |
| 1260 |
# MacOSX hack |
| 1261 |
$limit_dir = ('/private' . $home_dir); |
| 1262 |
} |
| 1263 |
|
| 1264 |
print $fh <<EOC; |
| 1265 |
<Directory /> |
| 1266 |
<Limit WRITE> |
| 1267 |
DenyAll |
| 1268 |
</Limit> |
| 1269 |
</Directory> |
| 1270 |
|
| 1271 |
<IfModule mod_ifsession.c> |
| 1272 |
<IfAuthenticated> |
| 1273 |
<Directory $limit_dir> |
| 1274 |
<Limit WRITE> |
| 1275 |
AllowAll |
| 1276 |
</Limit> |
| 1277 |
</Directory> |
| 1278 |
</IfAuthenticated> |
| 1279 |
</IfModule> |
| 1280 |
EOC |
| 1281 |
unless (close($fh)) { |
| 1282 |
die("Can't write $config_file: $!"); |
| 1283 |
} |
| 1284 |
|
| 1285 |
} else { |
| 1286 |
die("Can't open $config_file: $!"); |
| 1287 |
} |
| 1288 |
|
| 1289 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1290 |
# the child will indicate when it's done with its test by writing a message |
| 1291 |
# to the parent. |
| 1292 |
my ($rfh, $wfh); |
| 1293 |
unless (pipe($rfh, $wfh)) { |
| 1294 |
die("Can't open pipe: $!"); |
| 1295 |
} |
| 1296 |
|
| 1297 |
my $ex; |
| 1298 |
|
| 1299 |
# Fork child |
| 1300 |
$self->handle_sigchld(); |
| 1301 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1302 |
if ($pid) { |
| 1303 |
eval { |
| 1304 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1305 |
$client->login($user, $passwd); |
| 1306 |
|
| 1307 |
my $conn = $client->stor_raw('test.txt'); |
| 1308 |
unless ($conn) { |
| 1309 |
die("Failed to STOR test.txt: " . $client->response_code() . " " . |
| 1310 |
$client->response_msg()); |
| 1311 |
} |
| 1312 |
|
| 1313 |
eval { $conn->close() }; |
| 1314 |
|
| 1315 |
my $resp_code = $client->response_code(); |
| 1316 |
my $resp_msg = $client->response_msg(); |
| 1317 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 1318 |
|
| 1319 |
$client->quit(); |
| 1320 |
}; |
| 1321 |
|
| 1322 |
if ($@) { |
| 1323 |
$ex = $@; |
| 1324 |
} |
| 1325 |
|
| 1326 |
$wfh->print("done\n"); |
| 1327 |
$wfh->flush(); |
| 1328 |
|
| 1329 |
} else { |
| 1330 |
eval { server_wait($config_file, $rfh) }; |
| 1331 |
if ($@) { |
| 1332 |
warn($@); |
| 1333 |
exit 1; |
| 1334 |
} |
| 1335 |
|
| 1336 |
exit 0; |
| 1337 |
} |
| 1338 |
|
| 1339 |
# Stop server |
| 1340 |
server_stop($pid_file); |
| 1341 |
|
| 1342 |
$self->assert_child_ok($pid); |
| 1343 |
|
| 1344 |
if ($ex) { |
| 1345 |
test_append_logfile($log_file, $ex); |
| 1346 |
unlink($log_file); |
| 1347 |
|
| 1348 |
die($ex); |
| 1349 |
} |
| 1350 |
|
| 1351 |
unlink($log_file); |
| 1352 |
} |
| 1353 |
|
| 1354 |
sub ifgroup_displaylogin_bug3882 { |
| 1355 |
my $self = shift; |
| 1356 |
my $tmpdir = $self->{tmpdir}; |
| 1357 |
my $setup = test_setup($tmpdir, 'ifsess'); |
| 1358 |
|
| 1359 |
my $login_file = File::Spec->rel2abs("$tmpdir/login.txt"); |
| 1360 |
if (open(my $fh, "> $login_file")) { |
| 1361 |
print $fh "Hello user!\n"; |
| 1362 |
|
| 1363 |
unless (close($fh)) { |
| 1364 |
die("Unable to write $login_file: $!"); |
| 1365 |
} |
| 1366 |
|
| 1367 |
} else { |
| 1368 |
die("Unable to open $login_file: $!"); |
| 1369 |
} |
| 1370 |
|
| 1371 |
my $config = { |
| 1372 |
PidFile => $setup->{pid_file}, |
| 1373 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 1374 |
SystemLog => $setup->{log_file}, |
| 1375 |
TraceLog => $setup->{log_file}, |
| 1376 |
Trace => 'auth:20 auth.file:20 fsio:20', |
| 1377 |
|
| 1378 |
AuthUserFile => $setup->{auth_user_file}, |
| 1379 |
AuthGroupFile => $setup->{auth_group_file}, |
| 1380 |
AuthOrder => 'mod_auth_file.c', |
| 1381 |
|
| 1382 |
DefaultRoot => '~', |
| 1383 |
|
| 1384 |
IfModules => { |
| 1385 |
'mod_delay.c' => { |
| 1386 |
DelayEngine => 'off', |
| 1387 |
}, |
| 1388 |
}, |
| 1389 |
}; |
| 1390 |
|
| 1391 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 1392 |
$config); |
| 1393 |
|
| 1394 |
# Append the mod_ifsession config to the end of the config file |
| 1395 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 1396 |
print $fh <<EOC; |
| 1397 |
<IfModule mod_ifsession.c> |
| 1398 |
<IfGroup $setup->{group}> |
| 1399 |
DisplayLogin $login_file |
| 1400 |
</IfGroup> |
| 1401 |
</IfModule> |
| 1402 |
EOC |
| 1403 |
unless (close($fh)) { |
| 1404 |
die("Can't write $setup->{config_file}: $!"); |
| 1405 |
} |
| 1406 |
|
| 1407 |
} else { |
| 1408 |
die("Can't open $setup->{config_file}: $!"); |
| 1409 |
} |
| 1410 |
|
| 1411 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1412 |
# the child will indicate when it's done with its test by writing a message |
| 1413 |
# to the parent. |
| 1414 |
my ($rfh, $wfh); |
| 1415 |
unless (pipe($rfh, $wfh)) { |
| 1416 |
die("Can't open pipe: $!"); |
| 1417 |
} |
| 1418 |
|
| 1419 |
my $ex; |
| 1420 |
|
| 1421 |
# Fork child |
| 1422 |
$self->handle_sigchld(); |
| 1423 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1424 |
if ($pid) { |
| 1425 |
eval { |
| 1426 |
# Allow for server startup |
| 1427 |
sleep(2); |
| 1428 |
|
| 1429 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1430 |
$client->login($setup->{user}, $setup->{passwd}); |
| 1431 |
|
| 1432 |
my $resp_code = $client->response_code(); |
| 1433 |
my $resp_msg = $client->response_msg(0); |
| 1434 |
|
| 1435 |
my $expected = 230; |
| 1436 |
$self->assert($expected == $resp_code, |
| 1437 |
test_msg("Expected response code $expected, got $resp_code")); |
| 1438 |
|
| 1439 |
$expected = "Hello user!"; |
| 1440 |
$self->assert($expected eq $resp_msg, |
| 1441 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 1442 |
|
| 1443 |
$client->quit(); |
| 1444 |
}; |
| 1445 |
if ($@) { |
| 1446 |
$ex = $@; |
| 1447 |
} |
| 1448 |
|
| 1449 |
$wfh->print("done\n"); |
| 1450 |
$wfh->flush(); |
| 1451 |
|
| 1452 |
} else { |
| 1453 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 1454 |
if ($@) { |
| 1455 |
warn($@); |
| 1456 |
exit 1; |
| 1457 |
} |
| 1458 |
|
| 1459 |
exit 0; |
| 1460 |
} |
| 1461 |
|
| 1462 |
# Stop server |
| 1463 |
server_stop($setup->{pid_file}); |
| 1464 |
$self->assert_child_ok($pid); |
| 1465 |
|
| 1466 |
test_cleanup($setup->{log_file}, $ex); |
| 1467 |
} |
| 1468 |
|
| 1469 |
sub ifgroup_dir_allow_stor_bug3881 { |
| 1470 |
my $self = shift; |
| 1471 |
my $tmpdir = $self->{tmpdir}; |
| 1472 |
|
| 1473 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 1474 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 1475 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 1476 |
|
| 1477 |
my $log_file = test_get_logfile(); |
| 1478 |
|
| 1479 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 1480 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 1481 |
|
| 1482 |
my $test_file = File::Spec->rel2abs($config_file); |
| 1483 |
|
| 1484 |
my $user = 'proftpd'; |
| 1485 |
my $passwd = 'test'; |
| 1486 |
my $group = 'ftpd'; |
| 1487 |
my $home_dir = File::Spec->rel2abs("$tmpdir/users/$user"); |
| 1488 |
mkpath($home_dir); |
| 1489 |
my $uid = 500; |
| 1490 |
my $gid = 500; |
| 1491 |
|
| 1492 |
my $sub_dir = File::Spec->rel2abs("$home_dir/test.d"); |
| 1493 |
mkpath($sub_dir); |
| 1494 |
|
| 1495 |
if ($^O eq 'darwin') { |
| 1496 |
$home_dir = ('/private' . $home_dir); |
| 1497 |
} |
| 1498 |
|
| 1499 |
# Make sure that, if we're running as root, that the home directory has |
| 1500 |
# permissions/privs set for the account we create |
| 1501 |
if ($< == 0) { |
| 1502 |
unless (chmod(0755, $home_dir, $sub_dir)) { |
| 1503 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 1504 |
} |
| 1505 |
|
| 1506 |
unless (chown($uid, $gid, $home_dir, $sub_dir)) { |
| 1507 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 1508 |
} |
| 1509 |
} |
| 1510 |
|
| 1511 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 1512 |
'/bin/bash'); |
| 1513 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 1514 |
|
| 1515 |
my $config = { |
| 1516 |
PidFile => $pid_file, |
| 1517 |
ScoreboardFile => $scoreboard_file, |
| 1518 |
SystemLog => $log_file, |
| 1519 |
TraceLog => $log_file, |
| 1520 |
Trace => 'directory:20 fileperms:10 ifsession:20', |
| 1521 |
|
| 1522 |
AuthUserFile => $auth_user_file, |
| 1523 |
AuthGroupFile => $auth_group_file, |
| 1524 |
AuthOrder => 'mod_auth_file.c', |
| 1525 |
|
| 1526 |
DefaultRoot => '~', |
| 1527 |
|
| 1528 |
IfModules => { |
| 1529 |
'mod_delay.c' => { |
| 1530 |
DelayEngine => 'off', |
| 1531 |
}, |
| 1532 |
}, |
| 1533 |
}; |
| 1534 |
|
| 1535 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 1536 |
|
| 1537 |
# Append the mod_ifsession config to the end of the config file |
| 1538 |
if (open(my $fh, ">> $config_file")) { |
| 1539 |
my ($volume, $parent_dir, $file) = File::Spec->splitpath($home_dir); |
| 1540 |
my $limit_dir = File::Spec->rel2abs("$parent_dir/*/test.d"); |
| 1541 |
if ($^O eq 'darwin') { |
| 1542 |
# MacOSX hack |
| 1543 |
$limit_dir = ('/private' . $limit_dir); |
| 1544 |
} |
| 1545 |
|
| 1546 |
# XXX Hack, for now: |
| 1547 |
$limit_dir = '~/test.d'; |
| 1548 |
|
| 1549 |
print $fh <<EOC; |
| 1550 |
<Directory ~> |
| 1551 |
<Limit WRITE> |
| 1552 |
DenyAll |
| 1553 |
</Limit> |
| 1554 |
</Directory> |
| 1555 |
|
| 1556 |
<IfGroup $group> |
| 1557 |
<Directory $limit_dir> |
| 1558 |
<Limit MKD XMKD RMD XRMD> |
| 1559 |
DenyAll |
| 1560 |
</Limit> |
| 1561 |
|
| 1562 |
<Limit WRITE> |
| 1563 |
AllowAll |
| 1564 |
</Limit> |
| 1565 |
</Directory> |
| 1566 |
</IfGroup> |
| 1567 |
EOC |
| 1568 |
unless (close($fh)) { |
| 1569 |
die("Can't write $config_file: $!"); |
| 1570 |
} |
| 1571 |
|
| 1572 |
} else { |
| 1573 |
die("Can't open $config_file: $!"); |
| 1574 |
} |
| 1575 |
|
| 1576 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1577 |
# the child will indicate when it's done with its test by writing a message |
| 1578 |
# to the parent. |
| 1579 |
my ($rfh, $wfh); |
| 1580 |
unless (pipe($rfh, $wfh)) { |
| 1581 |
die("Can't open pipe: $!"); |
| 1582 |
} |
| 1583 |
|
| 1584 |
my $ex; |
| 1585 |
|
| 1586 |
# Fork child |
| 1587 |
$self->handle_sigchld(); |
| 1588 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1589 |
if ($pid) { |
| 1590 |
eval { |
| 1591 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1592 |
$client->login($user, $passwd); |
| 1593 |
$client->cwd('test.d'); |
| 1594 |
|
| 1595 |
my $path = 'test.txt'; |
| 1596 |
my $conn = $client->stor_raw($path); |
| 1597 |
unless ($conn) { |
| 1598 |
die("Can't STOR $path: " . $client->response_code() . " " . |
| 1599 |
$client->response_msg()); |
| 1600 |
} |
| 1601 |
|
| 1602 |
my $buf = "Hello, World!\n"; |
| 1603 |
$conn->write($buf, length($buf), 25); |
| 1604 |
eval { $conn->close() }; |
| 1605 |
|
| 1606 |
my $resp_code = $client->response_code(); |
| 1607 |
my $resp_msg = $client->response_msg(); |
| 1608 |
$self->assert_transfer_ok($resp_code, $resp_msg); |
| 1609 |
|
| 1610 |
$client->quit(); |
| 1611 |
}; |
| 1612 |
|
| 1613 |
if ($@) { |
| 1614 |
$ex = $@; |
| 1615 |
} |
| 1616 |
|
| 1617 |
$wfh->print("done\n"); |
| 1618 |
$wfh->flush(); |
| 1619 |
|
| 1620 |
} else { |
| 1621 |
eval { server_wait($config_file, $rfh) }; |
| 1622 |
if ($@) { |
| 1623 |
warn($@); |
| 1624 |
exit 1; |
| 1625 |
} |
| 1626 |
|
| 1627 |
exit 0; |
| 1628 |
} |
| 1629 |
|
| 1630 |
# Stop server |
| 1631 |
server_stop($pid_file); |
| 1632 |
|
| 1633 |
$self->assert_child_ok($pid); |
| 1634 |
|
| 1635 |
if ($ex) { |
| 1636 |
test_append_logfile($log_file, $ex); |
| 1637 |
unlink($log_file); |
| 1638 |
|
| 1639 |
die($ex); |
| 1640 |
} |
| 1641 |
|
| 1642 |
unlink($log_file); |
| 1643 |
} |
| 1644 |
|
| 1645 |
sub ifgroup_dir_allow_stor_bug3881_sftp { |
| 1646 |
my $self = shift; |
| 1647 |
my $tmpdir = $self->{tmpdir}; |
| 1648 |
|
| 1649 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 1650 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 1651 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 1652 |
|
| 1653 |
my $log_file = test_get_logfile(); |
| 1654 |
|
| 1655 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 1656 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 1657 |
|
| 1658 |
my $test_file = File::Spec->rel2abs($config_file); |
| 1659 |
|
| 1660 |
my $user = 'proftpd'; |
| 1661 |
my $passwd = 'test'; |
| 1662 |
my $group = 'ftpd'; |
| 1663 |
my $home_dir = File::Spec->rel2abs("$tmpdir/users/$user"); |
| 1664 |
mkpath($home_dir); |
| 1665 |
my $uid = 500; |
| 1666 |
my $gid = 500; |
| 1667 |
|
| 1668 |
my $sub_dir = File::Spec->rel2abs("$home_dir/test.d"); |
| 1669 |
mkpath($sub_dir); |
| 1670 |
|
| 1671 |
if ($^O eq 'darwin') { |
| 1672 |
$home_dir = ('/private' . $home_dir); |
| 1673 |
} |
| 1674 |
|
| 1675 |
# Make sure that, if we're running as root, that the home directory has |
| 1676 |
# permissions/privs set for the account we create |
| 1677 |
if ($< == 0) { |
| 1678 |
unless (chmod(0755, $home_dir, $sub_dir)) { |
| 1679 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 1680 |
} |
| 1681 |
|
| 1682 |
unless (chown($uid, $gid, $home_dir, $sub_dir)) { |
| 1683 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
|
| 1687 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 1688 |
'/bin/bash'); |
| 1689 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 1690 |
|
| 1691 |
my $rsa_host_key = File::Spec->rel2abs("t/etc/modules/mod_sftp/ssh_host_rsa_key"); |
| 1692 |
my $dsa_host_key = File::Spec->rel2abs("t/etc/modules/mod_sftp/ssh_host_dsa_key"); |
| 1693 |
|
| 1694 |
my $config = { |
| 1695 |
PidFile => $pid_file, |
| 1696 |
ScoreboardFile => $scoreboard_file, |
| 1697 |
SystemLog => $log_file, |
| 1698 |
TraceLog => $log_file, |
| 1699 |
Trace => 'directory:20 fileperms:10 ifsession:20', |
| 1700 |
|
| 1701 |
AuthUserFile => $auth_user_file, |
| 1702 |
AuthGroupFile => $auth_group_file, |
| 1703 |
AuthOrder => 'mod_auth_file.c', |
| 1704 |
|
| 1705 |
DefaultRoot => '~', |
| 1706 |
|
| 1707 |
IfModules => { |
| 1708 |
'mod_delay.c' => { |
| 1709 |
DelayEngine => 'off', |
| 1710 |
}, |
| 1711 |
|
| 1712 |
'mod_sftp.c' => [ |
| 1713 |
"SFTPEngine on", |
| 1714 |
"SFTPLog $log_file", |
| 1715 |
"SFTPHostKey $rsa_host_key", |
| 1716 |
"SFTPHostKey $dsa_host_key", |
| 1717 |
], |
| 1718 |
}, |
| 1719 |
}; |
| 1720 |
|
| 1721 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 1722 |
|
| 1723 |
# Append the mod_ifsession config to the end of the config file |
| 1724 |
if (open(my $fh, ">> $config_file")) { |
| 1725 |
my ($volume, $parent_dir, $file) = File::Spec->splitpath($home_dir); |
| 1726 |
my $limit_dir = File::Spec->rel2abs("$parent_dir/*/test.d"); |
| 1727 |
if ($^O eq 'darwin') { |
| 1728 |
# MacOSX hack |
| 1729 |
$limit_dir = ('/private' . $limit_dir); |
| 1730 |
} |
| 1731 |
|
| 1732 |
# XXX Hack, for now: |
| 1733 |
$limit_dir = '~/test.d'; |
| 1734 |
|
| 1735 |
print $fh <<EOC; |
| 1736 |
<Directory ~> |
| 1737 |
<Limit WRITE> |
| 1738 |
DenyAll |
| 1739 |
</Limit> |
| 1740 |
</Directory> |
| 1741 |
|
| 1742 |
<IfGroup $group> |
| 1743 |
<Directory $limit_dir> |
| 1744 |
<Limit MKD XMKD RMD XRMD> |
| 1745 |
DenyAll |
| 1746 |
</Limit> |
| 1747 |
|
| 1748 |
<Limit WRITE> |
| 1749 |
AllowAll |
| 1750 |
</Limit> |
| 1751 |
</Directory> |
| 1752 |
</IfGroup> |
| 1753 |
EOC |
| 1754 |
unless (close($fh)) { |
| 1755 |
die("Can't write $config_file: $!"); |
| 1756 |
} |
| 1757 |
|
| 1758 |
} else { |
| 1759 |
die("Can't open $config_file: $!"); |
| 1760 |
} |
| 1761 |
|
| 1762 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1763 |
# the child will indicate when it's done with its test by writing a message |
| 1764 |
# to the parent. |
| 1765 |
my ($rfh, $wfh); |
| 1766 |
unless (pipe($rfh, $wfh)) { |
| 1767 |
die("Can't open pipe: $!"); |
| 1768 |
} |
| 1769 |
|
| 1770 |
require Net::SSH2; |
| 1771 |
|
| 1772 |
my $ex; |
| 1773 |
|
| 1774 |
# Ignore SIGPIPE |
| 1775 |
local $SIG{PIPE} = sub { }; |
| 1776 |
|
| 1777 |
# Fork child |
| 1778 |
$self->handle_sigchld(); |
| 1779 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1780 |
if ($pid) { |
| 1781 |
eval { |
| 1782 |
my $ssh2 = Net::SSH2->new(); |
| 1783 |
|
| 1784 |
sleep(1); |
| 1785 |
|
| 1786 |
unless ($ssh2->connect('127.0.0.1', $port)) { |
| 1787 |
my ($err_code, $err_name, $err_str) = $ssh2->error(); |
| 1788 |
die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str"); |
| 1789 |
} |
| 1790 |
|
| 1791 |
unless ($ssh2->auth_password($user, $passwd)) { |
| 1792 |
my ($err_code, $err_name, $err_str) = $ssh2->error(); |
| 1793 |
die("Can't login to SSH2 server: [$err_name] ($err_code) $err_str"); |
| 1794 |
} |
| 1795 |
|
| 1796 |
my $sftp = $ssh2->sftp(); |
| 1797 |
unless ($sftp) { |
| 1798 |
my ($err_code, $err_name, $err_str) = $ssh2->error(); |
| 1799 |
die("Can't use SFTP on SSH2 server: [$err_name] ($err_code) $err_str"); |
| 1800 |
} |
| 1801 |
|
| 1802 |
my $path = 'test.d/test.txt'; |
| 1803 |
my $fh = $sftp->open($path, O_WRONLY|O_CREAT|O_TRUNC, 0644); |
| 1804 |
unless ($fh) { |
| 1805 |
my ($err_code, $err_name) = $sftp->error(); |
| 1806 |
die("Can't open $path: [$err_name] ($err_code)"); |
| 1807 |
} |
| 1808 |
|
| 1809 |
my $count = 20; |
| 1810 |
for (my $i = 0; $i < $count; $i++) { |
| 1811 |
print $fh "ABCD" x 8192; |
| 1812 |
} |
| 1813 |
|
| 1814 |
# To issue the FXP_CLOSE, we have to explicitly destroy the filehandle |
| 1815 |
$fh = undef; |
| 1816 |
|
| 1817 |
$sftp = undef; |
| 1818 |
$ssh2->disconnect(); |
| 1819 |
}; |
| 1820 |
|
| 1821 |
if ($@) { |
| 1822 |
$ex = $@; |
| 1823 |
} |
| 1824 |
|
| 1825 |
$wfh->print("done\n"); |
| 1826 |
$wfh->flush(); |
| 1827 |
|
| 1828 |
} else { |
| 1829 |
eval { server_wait($config_file, $rfh) }; |
| 1830 |
if ($@) { |
| 1831 |
warn($@); |
| 1832 |
exit 1; |
| 1833 |
} |
| 1834 |
|
| 1835 |
exit 0; |
| 1836 |
} |
| 1837 |
|
| 1838 |
# Stop server |
| 1839 |
server_stop($pid_file); |
| 1840 |
|
| 1841 |
$self->assert_child_ok($pid); |
| 1842 |
|
| 1843 |
if ($ex) { |
| 1844 |
test_append_logfile($log_file, $ex); |
| 1845 |
unlink($log_file); |
| 1846 |
|
| 1847 |
die($ex); |
| 1848 |
} |
| 1849 |
|
| 1850 |
unlink($log_file); |
| 1851 |
} |
| 1852 |
|
| 1853 |
# Regression test for issues described in: |
| 1854 |
# https://forums.proftpd.org/smf/index.php/topic,11572.0.html |
| 1855 |
sub ifclass_global_no_logging { |
| 1856 |
my $self = shift; |
| 1857 |
my $tmpdir = $self->{tmpdir}; |
| 1858 |
|
| 1859 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 1860 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 1861 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 1862 |
|
| 1863 |
my $log_file = test_get_logfile(); |
| 1864 |
|
| 1865 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 1866 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 1867 |
|
| 1868 |
my $ext_log = File::Spec->rel2abs("$tmpdir/ext.log"); |
| 1869 |
my $xfer_log = File::Spec->rel2abs("$tmpdir/xfer.log"); |
| 1870 |
|
| 1871 |
my $user = 'proftpd'; |
| 1872 |
my $passwd = 'test'; |
| 1873 |
my $group = 'ftpd'; |
| 1874 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 1875 |
my $uid = 500; |
| 1876 |
my $gid = 500; |
| 1877 |
|
| 1878 |
# Make sure that, if we're running as root, that the home directory has |
| 1879 |
# permissions/privs set for the account we create |
| 1880 |
if ($< == 0) { |
| 1881 |
unless (chmod(0755, $home_dir)) { |
| 1882 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 1883 |
} |
| 1884 |
|
| 1885 |
unless (chown($uid, $gid, $home_dir)) { |
| 1886 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 1887 |
} |
| 1888 |
} |
| 1889 |
|
| 1890 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 1891 |
'/bin/bash'); |
| 1892 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 1893 |
|
| 1894 |
my $config = { |
| 1895 |
PidFile => $pid_file, |
| 1896 |
ScoreboardFile => $scoreboard_file, |
| 1897 |
SystemLog => $log_file, |
| 1898 |
TraceLog => $log_file, |
| 1899 |
Trace => 'directory:20', |
| 1900 |
|
| 1901 |
AuthUserFile => $auth_user_file, |
| 1902 |
AuthGroupFile => $auth_group_file, |
| 1903 |
AuthOrder => 'mod_auth_file.c', |
| 1904 |
|
| 1905 |
IfModules => { |
| 1906 |
'mod_delay.c' => { |
| 1907 |
DelayEngine => 'off', |
| 1908 |
}, |
| 1909 |
}, |
| 1910 |
}; |
| 1911 |
|
| 1912 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 1913 |
|
| 1914 |
# Append the mod_ifsession config to the end of the config file |
| 1915 |
if (open(my $fh, ">> $config_file")) { |
| 1916 |
my $limit_dir = $home_dir; |
| 1917 |
if ($^O eq 'darwin') { |
| 1918 |
$limit_dir = ('/private' . $home_dir); |
| 1919 |
} |
| 1920 |
|
| 1921 |
print $fh <<EOC; |
| 1922 |
|
| 1923 |
ExtendedLog $ext_log ALL default |
| 1924 |
TransferLog $xfer_log |
| 1925 |
|
| 1926 |
<Class local> |
| 1927 |
From 127.0.0.1 |
| 1928 |
</Class> |
| 1929 |
|
| 1930 |
<Global> |
| 1931 |
<IfClass local> |
| 1932 |
ExtendedLog $ext_log NONE |
| 1933 |
TransferLog none |
| 1934 |
</IfClass> |
| 1935 |
</Global> |
| 1936 |
EOC |
| 1937 |
unless (close($fh)) { |
| 1938 |
die("Can't write $config_file: $!"); |
| 1939 |
} |
| 1940 |
|
| 1941 |
} else { |
| 1942 |
die("Can't open $config_file: $!"); |
| 1943 |
} |
| 1944 |
|
| 1945 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 1946 |
# the child will indicate when it's done with its test by writing a message |
| 1947 |
# to the parent. |
| 1948 |
my ($rfh, $wfh); |
| 1949 |
unless (pipe($rfh, $wfh)) { |
| 1950 |
die("Can't open pipe: $!"); |
| 1951 |
} |
| 1952 |
|
| 1953 |
my $ex; |
| 1954 |
|
| 1955 |
# Fork child |
| 1956 |
$self->handle_sigchld(); |
| 1957 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 1958 |
if ($pid) { |
| 1959 |
eval { |
| 1960 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 1961 |
$client->login($user, $passwd); |
| 1962 |
$client->mkd('foo'); |
| 1963 |
$client->retr($config_file); |
| 1964 |
$client->quit(); |
| 1965 |
}; |
| 1966 |
|
| 1967 |
if ($@) { |
| 1968 |
$ex = $@; |
| 1969 |
} |
| 1970 |
|
| 1971 |
$wfh->print("done\n"); |
| 1972 |
$wfh->flush(); |
| 1973 |
|
| 1974 |
} else { |
| 1975 |
eval { server_wait($config_file, $rfh) }; |
| 1976 |
if ($@) { |
| 1977 |
warn($@); |
| 1978 |
exit 1; |
| 1979 |
} |
| 1980 |
|
| 1981 |
exit 0; |
| 1982 |
} |
| 1983 |
|
| 1984 |
# Stop server |
| 1985 |
server_stop($pid_file); |
| 1986 |
|
| 1987 |
$self->assert_child_ok($pid); |
| 1988 |
|
| 1989 |
eval { |
| 1990 |
if (open(my $fh, "< $ext_log")) { |
| 1991 |
my $ok = 1; |
| 1992 |
|
| 1993 |
while (my $line = <$fh>) { |
| 1994 |
chomp($line); |
| 1995 |
$ok = 0; |
| 1996 |
|
| 1997 |
if ($ENV{TEST_VERBOSE}) { |
| 1998 |
print STDERR "+ ExtendedLog: $line\n"; |
| 1999 |
} |
| 2000 |
} |
| 2001 |
close($fh); |
| 2002 |
|
| 2003 |
$self->assert($ok, test_msg("Saw ExtendedLog messages unexpectedly")); |
| 2004 |
|
| 2005 |
} else { |
| 2006 |
die("Can't read $ext_log: $!"); |
| 2007 |
} |
| 2008 |
|
| 2009 |
if (open(my $fh, "< $xfer_log")) { |
| 2010 |
close($fh); |
| 2011 |
$self->assert(0, test_msg("Saw TransferLog unexpectedly")); |
| 2012 |
} |
| 2013 |
}; |
| 2014 |
if ($@) { |
| 2015 |
$ex = $@; |
| 2016 |
} |
| 2017 |
|
| 2018 |
if ($ex) { |
| 2019 |
test_append_logfile($log_file, $ex); |
| 2020 |
unlink($log_file); |
| 2021 |
|
| 2022 |
die($ex); |
| 2023 |
} |
| 2024 |
|
| 2025 |
unlink($log_file); |
| 2026 |
} |
| 2027 |
|
| 2028 |
sub ifuser_no_pass_bug4199 { |
| 2029 |
my $self = shift; |
| 2030 |
my $tmpdir = $self->{tmpdir}; |
| 2031 |
|
| 2032 |
my $config_file = "$tmpdir/ifsess.conf"; |
| 2033 |
my $pid_file = File::Spec->rel2abs("$tmpdir/ifsess.pid"); |
| 2034 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/ifsess.scoreboard"); |
| 2035 |
|
| 2036 |
my $log_file = test_get_logfile(); |
| 2037 |
|
| 2038 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/ifsess.passwd"); |
| 2039 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/ifsess.group"); |
| 2040 |
|
| 2041 |
my $test_file = File::Spec->rel2abs($config_file); |
| 2042 |
|
| 2043 |
my $user = 'proftpd'; |
| 2044 |
my $passwd = 'test'; |
| 2045 |
my $group = 'ftpd'; |
| 2046 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 2047 |
my $uid = 500; |
| 2048 |
my $gid = 500; |
| 2049 |
|
| 2050 |
# Make sure that, if we're running as root, that the home directory has |
| 2051 |
# permissions/privs set for the account we create |
| 2052 |
if ($< == 0) { |
| 2053 |
unless (chmod(0755, $home_dir)) { |
| 2054 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 2055 |
} |
| 2056 |
|
| 2057 |
unless (chown($uid, $gid, $home_dir)) { |
| 2058 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
|
| 2062 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 2063 |
'/bin/bash'); |
| 2064 |
auth_group_write($auth_group_file, $group, $gid, $user); |
| 2065 |
|
| 2066 |
my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem'); |
| 2067 |
my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem'); |
| 2068 |
my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem'); |
| 2069 |
|
| 2070 |
my $tlslogin_file = File::Spec->rel2abs("$tmpdir/.tlslogin"); |
| 2071 |
unless (copy($client_cert, $tlslogin_file)) { |
| 2072 |
die("Can't copy $client_cert to $tlslogin_file: $!"); |
| 2073 |
} |
| 2074 |
|
| 2075 |
my $config = { |
| 2076 |
PidFile => $pid_file, |
| 2077 |
ScoreboardFile => $scoreboard_file, |
| 2078 |
SystemLog => $log_file, |
| 2079 |
TraceLog => $log_file, |
| 2080 |
Trace => 'directory:20', |
| 2081 |
|
| 2082 |
AuthUserFile => $auth_user_file, |
| 2083 |
AuthGroupFile => $auth_group_file, |
| 2084 |
AuthOrder => 'mod_auth_file.c', |
| 2085 |
|
| 2086 |
IfModules => { |
| 2087 |
'mod_delay.c' => { |
| 2088 |
DelayEngine => 'off', |
| 2089 |
}, |
| 2090 |
|
| 2091 |
'mod_tls.c' => { |
| 2092 |
TLSEngine => 'on', |
| 2093 |
TLSLog => $log_file, |
| 2094 |
TLSRequired => 'on', |
| 2095 |
TLSRSACertificateFile => $server_cert, |
| 2096 |
TLSCACertificateFile => $ca_cert, |
| 2097 |
|
| 2098 |
TLSOptions => 'AllowDotLogin', |
| 2099 |
}, |
| 2100 |
}, |
| 2101 |
}; |
| 2102 |
|
| 2103 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 2104 |
|
| 2105 |
# Append the mod_ifsession config to the end of the config file |
| 2106 |
if (open(my $fh, ">> $config_file")) { |
| 2107 |
my $limit_dir = $home_dir; |
| 2108 |
if ($^O eq 'darwin') { |
| 2109 |
# MacOSX hack |
| 2110 |
$limit_dir = ('/private' . $home_dir); |
| 2111 |
} |
| 2112 |
|
| 2113 |
print $fh <<EOC; |
| 2114 |
<Directory /> |
| 2115 |
<Limit ALL> |
| 2116 |
DenyAll |
| 2117 |
</Limit> |
| 2118 |
</Directory> |
| 2119 |
|
| 2120 |
<IfUser $user> |
| 2121 |
<Directory $limit_dir> |
| 2122 |
<Limit MKD> |
| 2123 |
AllowAll |
| 2124 |
</Limit> |
| 2125 |
</Directory> |
| 2126 |
</IfUser> |
| 2127 |
EOC |
| 2128 |
unless (close($fh)) { |
| 2129 |
die("Can't write $config_file: $!"); |
| 2130 |
} |
| 2131 |
|
| 2132 |
} else { |
| 2133 |
die("Can't open $config_file: $!"); |
| 2134 |
} |
| 2135 |
|
| 2136 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 2137 |
# the child will indicate when it's done with its test by writing a message |
| 2138 |
# to the parent. |
| 2139 |
my ($rfh, $wfh); |
| 2140 |
unless (pipe($rfh, $wfh)) { |
| 2141 |
die("Can't open pipe: $!"); |
| 2142 |
} |
| 2143 |
|
| 2144 |
require Net::FTPSSL; |
| 2145 |
my $ex; |
| 2146 |
|
| 2147 |
# Fork child |
| 2148 |
$self->handle_sigchld(); |
| 2149 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 2150 |
if ($pid) { |
| 2151 |
eval { |
| 2152 |
# Give the server a chance to start up |
| 2153 |
sleep(2); |
| 2154 |
|
| 2155 |
# IO::Socket::SSL options |
| 2156 |
my $ssl_opts = { |
| 2157 |
SSL_use_cert => 1, |
| 2158 |
SSL_cert_file => $client_cert, |
| 2159 |
SSL_key_file => $client_cert, |
| 2160 |
}; |
| 2161 |
|
| 2162 |
my $client = Net::FTPSSL->new('127.0.0.1', |
| 2163 |
Croak => 1, |
| 2164 |
Encryption => 'E', |
| 2165 |
Port => $port, |
| 2166 |
SSL_Client_Certificate => $ssl_opts, |
| 2167 |
); |
| 2168 |
|
| 2169 |
unless ($client) { |
| 2170 |
die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr()); |
| 2171 |
} |
| 2172 |
|
| 2173 |
unless ($client->_user($user)) { |
| 2174 |
die("USER error: " . $client->last_message()); |
| 2175 |
} |
| 2176 |
|
| 2177 |
my $expected = "232 User $user logged in"; |
| 2178 |
my $resp = $client->last_message(); |
| 2179 |
$self->assert($expected eq $resp, |
| 2180 |
test_msg("Expected response '$expected', got '$resp'")); |
| 2181 |
|
| 2182 |
unless ($client->mkdir('foo')) { |
| 2183 |
die("MKD error: " . $client->last_message()); |
| 2184 |
} |
| 2185 |
|
| 2186 |
$client->quit(); |
| 2187 |
}; |
| 2188 |
|
| 2189 |
if ($@) { |
| 2190 |
$ex = $@; |
| 2191 |
} |
| 2192 |
|
| 2193 |
$wfh->print("done\n"); |
| 2194 |
$wfh->flush(); |
| 2195 |
|
| 2196 |
} else { |
| 2197 |
eval { server_wait($config_file, $rfh) }; |
| 2198 |
if ($@) { |
| 2199 |
warn($@); |
| 2200 |
exit 1; |
| 2201 |
} |
| 2202 |
|
| 2203 |
exit 0; |
| 2204 |
} |
| 2205 |
|
| 2206 |
# Stop server |
| 2207 |
server_stop($pid_file); |
| 2208 |
|
| 2209 |
$self->assert_child_ok($pid); |
| 2210 |
|
| 2211 |
if ($ex) { |
| 2212 |
test_append_logfile($log_file, $ex); |
| 2213 |
unlink($log_file); |
| 2214 |
|
| 2215 |
die($ex); |
| 2216 |
} |
| 2217 |
|
| 2218 |
unlink($log_file); |
| 2219 |
} |
| 2220 |
|
| 2221 |
sub ifclass_and_not_classes { |
| 2222 |
my $self = shift; |
| 2223 |
my $tmpdir = $self->{tmpdir}; |
| 2224 |
my $setup = test_setup($tmpdir, 'ifsess'); |
| 2225 |
|
| 2226 |
my $config = { |
| 2227 |
PidFile => $setup->{pid_file}, |
| 2228 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 2229 |
SystemLog => $setup->{log_file}, |
| 2230 |
TraceLog => $setup->{log_file}, |
| 2231 |
Trace => 'directory:20 ifsession:20', |
| 2232 |
|
| 2233 |
AuthUserFile => $setup->{auth_user_file}, |
| 2234 |
AuthGroupFile => $setup->{auth_group_file}, |
| 2235 |
AuthOrder => 'mod_auth_file.c', |
| 2236 |
|
| 2237 |
IfModules => { |
| 2238 |
'mod_delay.c' => { |
| 2239 |
DelayEngine => 'off', |
| 2240 |
}, |
| 2241 |
}, |
| 2242 |
}; |
| 2243 |
|
| 2244 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 2245 |
$config); |
| 2246 |
|
| 2247 |
# Append the mod_ifsession config to the end of the config file |
| 2248 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 2249 |
print $fh <<EOC; |
| 2250 |
<Class foo> |
| 2251 |
From 1.2.3.4 |
| 2252 |
</Class> |
| 2253 |
|
| 2254 |
<Class bar> |
| 2255 |
From 5.6.7.8 |
| 2256 |
</Class> |
| 2257 |
|
| 2258 |
<IfClass foo> |
| 2259 |
AccessGrantMsg "FOO access granted for %u" |
| 2260 |
</IfClass> |
| 2261 |
|
| 2262 |
<IfClass bar> |
| 2263 |
AccessGrantMsg "BAR access granted for %u" |
| 2264 |
</IfClass> |
| 2265 |
|
| 2266 |
<IfClass !foo AND !bar> |
| 2267 |
AccessGrantMsg "OTHER access granted for %u" |
| 2268 |
</IfClass> |
| 2269 |
EOC |
| 2270 |
unless (close($fh)) { |
| 2271 |
die("Can't write $setup->{config_file}: $!"); |
| 2272 |
} |
| 2273 |
|
| 2274 |
} else { |
| 2275 |
die("Can't open $setup->{config_file}: $!"); |
| 2276 |
} |
| 2277 |
|
| 2278 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 2279 |
# the child will indicate when it's done with its test by writing a message |
| 2280 |
# to the parent. |
| 2281 |
my ($rfh, $wfh); |
| 2282 |
unless (pipe($rfh, $wfh)) { |
| 2283 |
die("Can't open pipe: $!"); |
| 2284 |
} |
| 2285 |
|
| 2286 |
my $ex; |
| 2287 |
|
| 2288 |
# Fork child |
| 2289 |
$self->handle_sigchld(); |
| 2290 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 2291 |
if ($pid) { |
| 2292 |
eval { |
| 2293 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 2294 |
my ($resp_code, $resp_msg) = $client->login($setup->{user}, $setup->{passwd}); |
| 2295 |
$client->quit(); |
| 2296 |
|
| 2297 |
my $expected = '230'; |
| 2298 |
$self->assert($expected == $resp_code, |
| 2299 |
test_msg("Expected response code $expected, got $resp_code")); |
| 2300 |
|
| 2301 |
$expected = "OTHER access granted for $setup->{user}"; |
| 2302 |
$self->assert($expected eq $resp_msg, |
| 2303 |
test_msg("Expected response message '$expected', got '$resp_msg'")); |
| 2304 |
}; |
| 2305 |
if ($@) { |
| 2306 |
$ex = $@; |
| 2307 |
} |
| 2308 |
|
| 2309 |
$wfh->print("done\n"); |
| 2310 |
$wfh->flush(); |
| 2311 |
|
| 2312 |
} else { |
| 2313 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 2314 |
if ($@) { |
| 2315 |
warn($@); |
| 2316 |
exit 1; |
| 2317 |
} |
| 2318 |
|
| 2319 |
exit 0; |
| 2320 |
} |
| 2321 |
|
| 2322 |
# Stop server |
| 2323 |
server_stop($setup->{pid_file}); |
| 2324 |
$self->assert_child_ok($pid); |
| 2325 |
|
| 2326 |
test_cleanup($setup->{log_file}, $ex); |
| 2327 |
} |
| 2328 |
|
| 2329 |
sub ifuser_directory_bug4315 { |
| 2330 |
my $self = shift; |
| 2331 |
my $tmpdir = $self->{tmpdir}; |
| 2332 |
my $setup = test_setup($tmpdir, 'ifsess'); |
| 2333 |
|
| 2334 |
my $config = { |
| 2335 |
PidFile => $setup->{pid_file}, |
| 2336 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 2337 |
SystemLog => $setup->{log_file}, |
| 2338 |
|
| 2339 |
AuthUserFile => $setup->{auth_user_file}, |
| 2340 |
AuthGroupFile => $setup->{auth_group_file}, |
| 2341 |
AuthOrder => 'mod_auth_file.c', |
| 2342 |
|
| 2343 |
IfModules => { |
| 2344 |
'mod_delay.c' => { |
| 2345 |
DelayEngine => 'off', |
| 2346 |
}, |
| 2347 |
}, |
| 2348 |
}; |
| 2349 |
|
| 2350 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 2351 |
$config); |
| 2352 |
|
| 2353 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 2354 |
print $fh <<EOC; |
| 2355 |
<IfModule mod_ifsession.c> |
| 2356 |
<IfUser $setup->{user}> |
| 2357 |
<Directory /> |
| 2358 |
PathAllowFilter ^a |
| 2359 |
</Directory> |
| 2360 |
</IfUser> |
| 2361 |
</IfModule> |
| 2362 |
EOC |
| 2363 |
unless (close($fh)) { |
| 2364 |
die("Can't write $setup->{config_file}: $!"); |
| 2365 |
} |
| 2366 |
|
| 2367 |
} else { |
| 2368 |
die("Can't open $setup->{config_file}: $!"); |
| 2369 |
} |
| 2370 |
|
| 2371 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 2372 |
# the child will indicate when it's done with its test by writing a message |
| 2373 |
# to the parent. |
| 2374 |
my ($rfh, $wfh); |
| 2375 |
unless (pipe($rfh, $wfh)) { |
| 2376 |
die("Can't open pipe: $!"); |
| 2377 |
} |
| 2378 |
|
| 2379 |
my $ex; |
| 2380 |
|
| 2381 |
# Fork child |
| 2382 |
$self->handle_sigchld(); |
| 2383 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 2384 |
if ($pid) { |
| 2385 |
eval { |
| 2386 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 2387 |
$client->login($setup->{user}, $setup->{passwd}); |
| 2388 |
|
| 2389 |
eval { $client->mkd('bad') }; |
| 2390 |
unless ($@) { |
| 2391 |
die("MKD /bad succeeded unexpectedly"); |
| 2392 |
} |
| 2393 |
|
| 2394 |
eval { $client->mkd('bad') }; |
| 2395 |
unless ($@) { |
| 2396 |
die("MKD /bad succeeded unexpectedly"); |
| 2397 |
} |
| 2398 |
|
| 2399 |
$client->quit(); |
| 2400 |
}; |
| 2401 |
if ($@) { |
| 2402 |
$ex = $@; |
| 2403 |
} |
| 2404 |
|
| 2405 |
$wfh->print("done\n"); |
| 2406 |
$wfh->flush(); |
| 2407 |
|
| 2408 |
} else { |
| 2409 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 2410 |
if ($@) { |
| 2411 |
warn($@); |
| 2412 |
exit 1; |
| 2413 |
} |
| 2414 |
|
| 2415 |
exit 0; |
| 2416 |
} |
| 2417 |
|
| 2418 |
# Stop server |
| 2419 |
server_stop($setup->{pid_file}); |
| 2420 |
$self->assert_child_ok($pid); |
| 2421 |
|
| 2422 |
test_cleanup($setup->{log_file}, $ex); |
| 2423 |
} |
| 2424 |
|
| 2425 |
sub ifsess_options_per_unauthenticated_user { |
| 2426 |
my $self = shift; |
| 2427 |
my $tmpdir = $self->{tmpdir}; |
| 2428 |
my $setup = test_setup($tmpdir, 'ifsess'); |
| 2429 |
|
| 2430 |
my $config = { |
| 2431 |
PidFile => $setup->{pid_file}, |
| 2432 |
ScoreboardFile => $setup->{scoreboard_file}, |
| 2433 |
SystemLog => $setup->{log_file}, |
| 2434 |
TraceLog => $setup->{log_file}, |
| 2435 |
Trace => 'ifsession:20', |
| 2436 |
|
| 2437 |
AuthUserFile => $setup->{auth_user_file}, |
| 2438 |
AuthGroupFile => $setup->{auth_group_file}, |
| 2439 |
AuthOrder => 'mod_auth_file.c', |
| 2440 |
|
| 2441 |
IfModules => { |
| 2442 |
'mod_delay.c' => { |
| 2443 |
DelayEngine => 'off', |
| 2444 |
}, |
| 2445 |
}, |
| 2446 |
}; |
| 2447 |
|
| 2448 |
my ($port, $config_user, $config_group) = config_write($setup->{config_file}, |
| 2449 |
$config); |
| 2450 |
|
| 2451 |
if (open(my $fh, ">> $setup->{config_file}")) { |
| 2452 |
print $fh <<EOC; |
| 2453 |
<IfModule mod_ifsession.c> |
| 2454 |
IfSessionOptions PerUnauthenticatedUser |
| 2455 |
|
| 2456 |
<IfUser $setup->{user}> |
| 2457 |
<Limit LOGIN> |
| 2458 |
DenyUser $setup->{user} |
| 2459 |
</Limit> |
| 2460 |
</IfUser> |
| 2461 |
</IfModule> |
| 2462 |
EOC |
| 2463 |
unless (close($fh)) { |
| 2464 |
die("Can't write $setup->{config_file}: $!"); |
| 2465 |
} |
| 2466 |
|
| 2467 |
} else { |
| 2468 |
die("Can't open $setup->{config_file}: $!"); |
| 2469 |
} |
| 2470 |
|
| 2471 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 2472 |
# the child will indicate when it's done with its test by writing a message |
| 2473 |
# to the parent. |
| 2474 |
my ($rfh, $wfh); |
| 2475 |
unless (pipe($rfh, $wfh)) { |
| 2476 |
die("Can't open pipe: $!"); |
| 2477 |
} |
| 2478 |
|
| 2479 |
my $ex; |
| 2480 |
|
| 2481 |
# Fork child |
| 2482 |
$self->handle_sigchld(); |
| 2483 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 2484 |
if ($pid) { |
| 2485 |
eval { |
| 2486 |
# Allow for server startup |
| 2487 |
sleep(2); |
| 2488 |
|
| 2489 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 2490 |
eval { $client->login($setup->{user}, $setup->{passwd}) }; |
| 2491 |
unless ($@) { |
| 2492 |
die("Login succeeded unexpectedly"); |
| 2493 |
} |
| 2494 |
}; |
| 2495 |
if ($@) { |
| 2496 |
$ex = $@; |
| 2497 |
} |
| 2498 |
|
| 2499 |
$wfh->print("done\n"); |
| 2500 |
$wfh->flush(); |
| 2501 |
|
| 2502 |
} else { |
| 2503 |
eval { server_wait($setup->{config_file}, $rfh) }; |
| 2504 |
if ($@) { |
| 2505 |
warn($@); |
| 2506 |
exit 1; |
| 2507 |
} |
| 2508 |
|
| 2509 |
exit 0; |
| 2510 |
} |
| 2511 |
|
| 2512 |
# Stop server |
| 2513 |
server_stop($setup->{pid_file}); |
| 2514 |
$self->assert_child_ok($pid); |
| 2515 |
|
| 2516 |
test_cleanup($setup->{log_file}, $ex); |
| 2517 |
} |
| 2518 |
|
| 2519 |
1; |