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