Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::AuthGroupFile;
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 authgroupfile_bug3347 => {
19 order => ++$order,
20 test_class => [qw(bug forking rootprivs)],
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 authgroupfile_bug3347 {
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 = test_get_logfile();
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, $group) = config_get_identity();
47 my $passwd = 'test';
48 my $home_dir = File::Spec->rel2abs($tmpdir);
49 my $uid = 500;
50 my $gid = (getgrnam($group))[2];
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(0775, $home_dir)) {
56 die("Can't set perms on $home_dir to 0755: $!");
57 }
58
59 # Use a UID different that the user's UID for the home dir ownership
60 unless (chown(100, $gid, $home_dir)) {
61 die("Can't set owner of $home_dir to 100/$gid: $!");
62 }
63 }
64
65 auth_user_write($auth_user_file, 'foo', 'bar', $uid, $gid, $home_dir,
66 '/bin/bash');
67 auth_group_write($auth_group_file, 'pirates', 999, '');
68
69 my $user_password = ProFTPD::TestSuite::Utils::get_passwd($passwd);
70
71 my $config = {
72 PidFile => $pid_file,
73 ScoreboardFile => $scoreboard_file,
74 SystemLog => $log_file,
75 TraceLog => $log_file,
76 Trace => 'auth:10',
77
78 User => $user,
79 Group => $group,
80 DefaultRoot => $home_dir,
81 PersistentPasswd => 'off',
82 UserPassword => "$user $user_password",
83
84 AuthUserFile => $auth_user_file,
85 AuthGroupFile => $auth_group_file,
86 AuthOrder => 'mod_auth_file.c',
87
88 IfModules => {
89 'mod_delay.c' => {
90 DelayEngine => 'off',
91 },
92 },
93 };
94
95 my ($port, $config_user, $config_group) = config_write($config_file, $config);
96
97 # Open pipes, for use between the parent and child processes. Specifically,
98 # the child will indicate when it's done with its test by writing a message
99 # to the parent.
100 my ($rfh, $wfh);
101 unless (pipe($rfh, $wfh)) {
102 die("Can't open pipe: $!");
103 }
104
105 my $ex;
106
107 # Fork child
108 $self->handle_sigchld();
109 defined(my $pid = fork()) or die("Can't fork: $!");
110 if ($pid) {
111 eval {
112 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
113 $client->login($user, $passwd);
114
115 my $conn = $client->stor_raw('test.txt');
116 unless ($conn) {
117 die("STOR test.txt failed: " . $client->response_code() . " " .
118 $client->response_msg());
119 }
120
121 my $buf = "Hello, World!\n";
122 $conn->write($buf, length($buf));
123 $conn->close();
124
125 my $resp_code = $client->response_code();
126 my $resp_msg = $client->response_msg();
127
128 $self->assert_transfer_ok($resp_code, $resp_msg);
129
130 $client->quit();
131 };
132
133 if ($@) {
134 $ex = $@;
135 }
136
137 $wfh->print("done\n");
138 $wfh->flush();
139
140 } else {
141 eval { server_wait($config_file, $rfh) };
142 if ($@) {
143 warn($@);
144 exit 1;
145 }
146
147 exit 0;
148 }
149
150 # Stop server
151 server_stop($pid_file);
152
153 $self->assert_child_ok($pid);
154
155 if ($ex) {
156 test_append_logfile($log_file, $ex);
157 unlink($log_file);
158
159 die($ex);
160 }
161
162 unlink($log_file);
163 }
164
165 1;