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