| 1 |
package ProFTPD::Tests::Config::UseGlobbing; |
| 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 |
useglobbing_off => { |
| 19 |
order => ++$order, |
| 20 |
test_class => [qw(forking)], |
| 21 |
}, |
| 22 |
|
| 23 |
}; |
| 24 |
|
| 25 |
sub new { |
| 26 |
return shift()->SUPER::new(@_); |
| 27 |
} |
| 28 |
|
| 29 |
sub list_tests { |
| 30 |
return testsuite_get_runnable_tests($TESTS); |
| 31 |
} |
| 32 |
|
| 33 |
sub useglobbing_off { |
| 34 |
my $self = shift; |
| 35 |
my $tmpdir = $self->{tmpdir}; |
| 36 |
|
| 37 |
my $config_file = "$tmpdir/config.conf"; |
| 38 |
my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); |
| 39 |
my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); |
| 40 |
|
| 41 |
my $log_file = File::Spec->rel2abs('tests.log'); |
| 42 |
|
| 43 |
my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); |
| 44 |
my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); |
| 45 |
|
| 46 |
my $user = 'proftpd'; |
| 47 |
my $passwd = 'test'; |
| 48 |
my $home_dir = File::Spec->rel2abs($tmpdir); |
| 49 |
my $uid = 500; |
| 50 |
my $gid = 500; |
| 51 |
|
| 52 |
# Make sure that, if we're running as root, that the home directory has |
| 53 |
# permissions/privs set for the account we create |
| 54 |
if ($< == 0) { |
| 55 |
unless (chmod(0755, $home_dir)) { |
| 56 |
die("Can't set perms on $home_dir to 0755: $!"); |
| 57 |
} |
| 58 |
|
| 59 |
unless (chown($uid, $gid, $home_dir)) { |
| 60 |
die("Can't set owner of $home_dir to $uid/$gid: $!"); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, |
| 65 |
'/bin/bash'); |
| 66 |
auth_group_write($auth_group_file, 'ftpd', $gid, $user); |
| 67 |
|
| 68 |
my $config = { |
| 69 |
PidFile => $pid_file, |
| 70 |
ScoreboardFile => $scoreboard_file, |
| 71 |
SystemLog => $log_file, |
| 72 |
|
| 73 |
AuthUserFile => $auth_user_file, |
| 74 |
AuthGroupFile => $auth_group_file, |
| 75 |
AuthOrder => 'mod_auth_file.c', |
| 76 |
|
| 77 |
UseGlobbing => 'off', |
| 78 |
|
| 79 |
IfModules => { |
| 80 |
'mod_delay.c' => { |
| 81 |
DelayEngine => 'off', |
| 82 |
}, |
| 83 |
}, |
| 84 |
}; |
| 85 |
|
| 86 |
my ($port, $config_user, $config_group) = config_write($config_file, $config); |
| 87 |
|
| 88 |
# Open pipes, for use between the parent and child processes. Specifically, |
| 89 |
# the child will indicate when it's done with its test by writing a message |
| 90 |
# to the parent. |
| 91 |
my ($rfh, $wfh); |
| 92 |
unless (pipe($rfh, $wfh)) { |
| 93 |
die("Can't open pipe: $!"); |
| 94 |
} |
| 95 |
|
| 96 |
my $ex; |
| 97 |
|
| 98 |
# Fork child |
| 99 |
$self->handle_sigchld(); |
| 100 |
defined(my $pid = fork()) or die("Can't fork: $!"); |
| 101 |
if ($pid) { |
| 102 |
eval { |
| 103 |
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); |
| 104 |
$client->login($user, $passwd); |
| 105 |
|
| 106 |
my $conn = $client->list_raw("*.conf"); |
| 107 |
unless ($conn) { |
| 108 |
die("LIST failed: " . $client->response_code() . " " . |
| 109 |
$client->response_msg()); |
| 110 |
} |
| 111 |
|
| 112 |
my $buf; |
| 113 |
$conn->read($buf, 8192, 30); |
| 114 |
$conn->close(); |
| 115 |
|
| 116 |
my $res = {}; |
| 117 |
my $lines = [split(/\n/, $buf)]; |
| 118 |
foreach my $line (@$lines) { |
| 119 |
if ($line =~ /^\S+\s+\d+\s+\S+\s+\S+\s+.*?\s+(\S+)$/) { |
| 120 |
$res->{$1} = 1; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
my $count = scalar(keys(%$res)); |
| 125 |
unless ($count == 0) { |
| 126 |
die("LIST returned wrong number of entries (expected 0, got $count)"); |
| 127 |
} |
| 128 |
}; |
| 129 |
|
| 130 |
if ($@) { |
| 131 |
$ex = $@; |
| 132 |
} |
| 133 |
|
| 134 |
$wfh->print("done\n"); |
| 135 |
$wfh->flush(); |
| 136 |
|
| 137 |
} else { |
| 138 |
eval { server_wait($config_file, $rfh) }; |
| 139 |
if ($@) { |
| 140 |
warn($@); |
| 141 |
exit 1; |
| 142 |
} |
| 143 |
|
| 144 |
exit 0; |
| 145 |
} |
| 146 |
|
| 147 |
# Stop server |
| 148 |
server_stop($pid_file); |
| 149 |
|
| 150 |
$self->assert_child_ok($pid); |
| 151 |
|
| 152 |
if ($ex) { |
| 153 |
die($ex); |
| 154 |
} |
| 155 |
|
| 156 |
unlink($log_file); |
| 157 |
} |
| 158 |
|
| 159 |
1; |