Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/Limit/MFMT.pm

raw
1 package ProFTPD::Tests::Config::Limit::MFMT;
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 mfmt_limit_bug3399 => {
20 order => ++$order,
21 test_class => [qw(bug forking rootprivs)],
22 },
23
24 };
25
26 sub new {
27 return shift()->SUPER::new(@_);
28 }
29
30 sub list_tests {
31 return testsuite_get_runnable_tests($TESTS);
32 }
33
34 sub mfmt_limit_bug3399 {
35 my $self = shift;
36 my $tmpdir = $self->{tmpdir};
37
38 my $config_file = "$tmpdir/limit.conf";
39 my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
40 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
41
42 my $log_file = File::Spec->rel2abs('tests.log');
43
44 my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
45 my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
46
47 my $user = 'proftpd';
48 my $passwd = 'test';
49 my $home_dir = File::Spec->rel2abs($tmpdir);
50 my $uid = 500;
51 my $gid = 500;
52
53 my $sub_dir = File::Spec->rel2abs("$tmpdir/foo");
54 mkpath($sub_dir);
55
56 # Make sure that, if we're running as root, that the home directory has
57 # permissions/privs set for the account we create
58 if ($< == 0) {
59 unless (chmod(0755, $home_dir, $sub_dir)) {
60 die("Can't set perms on $home_dir to 0755: $!");
61 }
62
63 unless (chown($uid, $gid, $home_dir, $sub_dir)) {
64 die("Can't set owner of $home_dir to $uid/$gid: $!");
65 }
66 }
67
68 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
69 '/bin/bash');
70 auth_group_write($auth_group_file, 'ftpd', $gid, $user);
71
72 my $config = {
73 PidFile => $pid_file,
74 ScoreboardFile => $scoreboard_file,
75 SystemLog => $log_file,
76 TraceLog => $log_file,
77 Trace => 'directory:10',
78
79 AuthUserFile => $auth_user_file,
80 AuthGroupFile => $auth_group_file,
81 AuthOrder => 'mod_auth_file.c',
82
83 DefaultRoot => '~',
84
85 IfModules => {
86 'mod_delay.c' => {
87 DelayEngine => 'off',
88 },
89 },
90 };
91
92 my ($port, $config_user, $config_group) = config_write($config_file, $config);
93
94 if (open(my $fh, ">> $config_file")) {
95 print $fh <<EOC;
96 <Directory $home_dir>
97 <Limit SITE WRITE>
98 DenyAll
99 </Limit>
100 </Directory>
101
102 <Directory $sub_dir/*>
103 <Limit SITE READ WRITE DIRS>
104 AllowAll
105 </Limit>
106 </Directory>
107 EOC
108 unless (close($fh)) {
109 die("Can't write $config_file: $!");
110 }
111
112 } else {
113 die("Can't open $config_file: $!");
114 }
115
116 # Open pipes, for use between the parent and child processes. Specifically,
117 # the child will indicate when it's done with its test by writing a message
118 # to the parent.
119 my ($rfh, $wfh);
120 unless (pipe($rfh, $wfh)) {
121 die("Can't open pipe: $!");
122 }
123
124 my $ex;
125
126 # Fork child
127 $self->handle_sigchld();
128 defined(my $pid = fork()) or die("Can't fork: $!");
129 if ($pid) {
130 eval {
131 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
132 $client->login($user, $passwd);
133 $client->cwd('foo');
134
135 my $conn = $client->stor_raw('test.txt');
136 unless ($conn) {
137 die("STOR test.txt failed: " . $client->response_code() .
138 $client->response_msg());
139 }
140
141 $conn->close();
142
143 my ($resp_code, $resp_msg);
144 ($resp_code, $resp_msg) = $client->mfmt('20020717210715', 'test.txt');
145
146 my $expected;
147
148 $expected = 213;
149 $self->assert($expected == $resp_code,
150 test_msg("Expected $expected, got $resp_code"));
151
152 $expected = 'Modify=20020717210715; test.txt';
153 $self->assert($expected eq $resp_msg,
154 test_msg("Expected '$expected', got '$resp_msg'"));
155
156 $client->quit();
157 };
158
159 if ($@) {
160 $ex = $@;
161 }
162
163 $wfh->print("done\n");
164 $wfh->flush();
165
166 } else {
167 eval { server_wait($config_file, $rfh) };
168 if ($@) {
169 warn($@);
170 exit 1;
171 }
172
173 exit 0;
174 }
175
176 # Stop server
177 server_stop($pid_file);
178
179 $self->assert_child_ok($pid);
180
181 if ($ex) {
182 die($ex);
183 }
184
185 unlink($log_file);
186 }
187
188 1;