Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Config/RLimitMemory.pm

raw
1 package ProFTPD::Tests::Config::RLimitMemory;
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 rlimitmemory_max_bug3571 => {
19 order => ++$order,
20 test_class => [qw(bug forking)],
21 },
22
23 rlimitmemory_session_max_bug3571 => {
24 order => ++$order,
25 test_class => [qw(bug forking)],
26 },
27
28 rlimitmemory_daemon_max => {
29 order => ++$order,
30 test_class => [qw(bug forking)],
31 },
32
33 };
34
35 sub new {
36 return shift()->SUPER::new(@_);
37 }
38
39 sub list_tests {
40 return testsuite_get_runnable_tests($TESTS);
41 }
42
43 sub rlimitmemory_max_bug3571 {
44 my $self = shift;
45 my $tmpdir = $self->{tmpdir};
46
47 my $config_file = "$tmpdir/config.conf";
48 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
49 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
50
51 my $log_file = test_get_logfile();
52
53 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
54 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
55
56 my $user = 'proftpd';
57 my $passwd = 'test';
58 my $group = 'ftpd';
59 my $home_dir = File::Spec->rel2abs($tmpdir);
60 my $uid = 500;
61 my $gid = 500;
62
63 # Make sure that, if we're running as root, that the home directory has
64 # permissions/privs set for the account we create
65 if ($< == 0) {
66 unless (chmod(0755, $home_dir)) {
67 die("Can't set perms on $home_dir to 0755: $!");
68 }
69
70 unless (chown($uid, $gid, $home_dir)) {
71 die("Can't set owner of $home_dir to $uid/$gid: $!");
72 }
73 }
74
75 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
76 '/bin/bash');
77 auth_group_write($auth_group_file, $group, $gid, $user);
78
79 my $config = {
80 PidFile => $pid_file,
81 ScoreboardFile => $scoreboard_file,
82 SystemLog => $log_file,
83
84 AuthUserFile => $auth_user_file,
85 AuthGroupFile => $auth_group_file,
86 AuthOrder => 'mod_auth_file.c',
87
88 RLimitMemory => 'max',
89
90 IfModules => {
91 'mod_delay.c' => {
92 DelayEngine => 'off',
93 },
94 },
95 };
96
97 my ($port, $config_user, $config_group) = config_write($config_file, $config);
98
99 # Open pipes, for use between the parent and child processes. Specifically,
100 # the child will indicate when it's done with its test by writing a message
101 # to the parent.
102 my ($rfh, $wfh);
103 unless (pipe($rfh, $wfh)) {
104 die("Can't open pipe: $!");
105 }
106
107 my $ex;
108
109 # Fork child
110 $self->handle_sigchld();
111 defined(my $pid = fork()) or die("Can't fork: $!");
112 if ($pid) {
113 eval {
114 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
115 $client->login($user, $passwd);
116 $client->quit();
117 };
118
119 if ($@) {
120 $ex = $@;
121 }
122
123 $wfh->print("done\n");
124 $wfh->flush();
125
126 } else {
127 eval { server_wait($config_file, $rfh) };
128 if ($@) {
129 warn($@);
130 exit 1;
131 }
132
133 exit 0;
134 }
135
136 # Stop server
137 server_stop($pid_file);
138
139 $self->assert_child_ok($pid);
140
141 if ($ex) {
142 test_append_logfile($log_file, $ex);
143 unlink($log_file);
144
145 die($ex);
146 }
147
148 unlink($log_file);
149 }
150
151 sub rlimitmemory_session_max_bug3571 {
152 my $self = shift;
153 my $tmpdir = $self->{tmpdir};
154
155 my $config_file = "$tmpdir/config.conf";
156 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
157 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
158
159 my $log_file = test_get_logfile();
160
161 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
162 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
163
164 my $user = 'proftpd';
165 my $passwd = 'test';
166 my $group = 'ftpd';
167 my $home_dir = File::Spec->rel2abs($tmpdir);
168 my $uid = 500;
169 my $gid = 500;
170
171 # Make sure that, if we're running as root, that the home directory has
172 # permissions/privs set for the account we create
173 if ($< == 0) {
174 unless (chmod(0755, $home_dir)) {
175 die("Can't set perms on $home_dir to 0755: $!");
176 }
177
178 unless (chown($uid, $gid, $home_dir)) {
179 die("Can't set owner of $home_dir to $uid/$gid: $!");
180 }
181 }
182
183 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
184 '/bin/bash');
185 auth_group_write($auth_group_file, $group, $gid, $user);
186
187 my $config = {
188 PidFile => $pid_file,
189 ScoreboardFile => $scoreboard_file,
190 SystemLog => $log_file,
191
192 AuthUserFile => $auth_user_file,
193 AuthGroupFile => $auth_group_file,
194 AuthOrder => 'mod_auth_file.c',
195
196 RLimitMemory => 'session max',
197
198 IfModules => {
199 'mod_delay.c' => {
200 DelayEngine => 'off',
201 },
202 },
203 };
204
205 my ($port, $config_user, $config_group) = config_write($config_file, $config);
206
207 # Open pipes, for use between the parent and child processes. Specifically,
208 # the child will indicate when it's done with its test by writing a message
209 # to the parent.
210 my ($rfh, $wfh);
211 unless (pipe($rfh, $wfh)) {
212 die("Can't open pipe: $!");
213 }
214
215 my $ex;
216
217 # Fork child
218 $self->handle_sigchld();
219 defined(my $pid = fork()) or die("Can't fork: $!");
220 if ($pid) {
221 eval {
222 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
223 $client->login($user, $passwd);
224 $client->quit();
225 };
226
227 if ($@) {
228 $ex = $@;
229 }
230
231 $wfh->print("done\n");
232 $wfh->flush();
233
234 } else {
235 eval { server_wait($config_file, $rfh) };
236 if ($@) {
237 warn($@);
238 exit 1;
239 }
240
241 exit 0;
242 }
243
244 # Stop server
245 server_stop($pid_file);
246
247 $self->assert_child_ok($pid);
248
249 if ($ex) {
250 test_append_logfile($log_file, $ex);
251 unlink($log_file);
252
253 die($ex);
254 }
255
256 unlink($log_file);
257 }
258
259 sub rlimitmemory_daemon_max {
260 my $self = shift;
261 my $tmpdir = $self->{tmpdir};
262
263 my $config_file = "$tmpdir/config.conf";
264 my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid");
265 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard");
266
267 my $log_file = test_get_logfile();
268
269 my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd");
270 my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group");
271
272 my $user = 'proftpd';
273 my $passwd = 'test';
274 my $group = 'ftpd';
275 my $home_dir = File::Spec->rel2abs($tmpdir);
276 my $uid = 500;
277 my $gid = 500;
278
279 # Make sure that, if we're running as root, that the home directory has
280 # permissions/privs set for the account we create
281 if ($< == 0) {
282 unless (chmod(0755, $home_dir)) {
283 die("Can't set perms on $home_dir to 0755: $!");
284 }
285
286 unless (chown($uid, $gid, $home_dir)) {
287 die("Can't set owner of $home_dir to $uid/$gid: $!");
288 }
289 }
290
291 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
292 '/bin/bash');
293 auth_group_write($auth_group_file, $group, $gid, $user);
294
295 my $config = {
296 PidFile => $pid_file,
297 ScoreboardFile => $scoreboard_file,
298 SystemLog => $log_file,
299
300 AuthUserFile => $auth_user_file,
301 AuthGroupFile => $auth_group_file,
302 AuthOrder => 'mod_auth_file.c',
303
304 RLimitMemory => 'daemon max',
305
306 IfModules => {
307 'mod_delay.c' => {
308 DelayEngine => 'off',
309 },
310 },
311 };
312
313 my ($port, $config_user, $config_group) = config_write($config_file, $config);
314
315 # Open pipes, for use between the parent and child processes. Specifically,
316 # the child will indicate when it's done with its test by writing a message
317 # to the parent.
318 my ($rfh, $wfh);
319 unless (pipe($rfh, $wfh)) {
320 die("Can't open pipe: $!");
321 }
322
323 my $ex;
324
325 # Fork child
326 $self->handle_sigchld();
327 defined(my $pid = fork()) or die("Can't fork: $!");
328 if ($pid) {
329 eval {
330 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
331 $client->login($user, $passwd);
332 $client->quit();
333 };
334
335 if ($@) {
336 $ex = $@;
337 }
338
339 $wfh->print("done\n");
340 $wfh->flush();
341
342 } else {
343 eval { server_wait($config_file, $rfh) };
344 if ($@) {
345 warn($@);
346 exit 1;
347 }
348
349 exit 0;
350 }
351
352 # Stop server
353 server_stop($pid_file);
354
355 $self->assert_child_ok($pid);
356
357 if ($ex) {
358 test_append_logfile($log_file, $ex);
359 unlink($log_file);
360
361 die($ex);
362 }
363
364 unlink($log_file);
365 }
366
367 1;