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