Debian Codegraph @

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

raw
1 package ProFTPD::Tests::Config::AuthUserFile;
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 authuserfile_empty_passwd => {
19 order => ++$order,
20 test_class => [qw(bug forking os_darwin)],
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 authuserfile_empty_passwd {
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 = 'proftpd';
47
48 # On Mac, creating an AuthUserFile with an empty password value is NOT
49 # handled the same as on other platforms.
50 my $passwd = '';
51
52 my $group = 'ftpd';
53 my $home_dir = File::Spec->rel2abs($tmpdir);
54 my $uid = 500;
55 my $gid = 500;
56
57 # Make sure that, if we're running as root, that the home directory has
58 # permissions/privs set for the account we create
59 if ($< == 0) {
60 unless (chmod(0755, $home_dir)) {
61 die("Can't set perms on $home_dir to 0755: $!");
62 }
63
64 # Use a UID different that the user's UID for the home dir ownership
65 unless (chown($uid, $gid, $home_dir)) {
66 die("Can't set owner of $home_dir to $uid/$gid: $!");
67 }
68 }
69
70 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
71 '/bin/bash');
72 auth_group_write($auth_group_file, $group, $gid, $user);
73
74 my $user_password = ProFTPD::TestSuite::Utils::get_passwd($passwd);
75
76 my $config = {
77 PidFile => $pid_file,
78 ScoreboardFile => $scoreboard_file,
79 SystemLog => $log_file,
80 TraceLog => $log_file,
81 Trace => 'auth:10',
82
83 AuthUserFile => $auth_user_file,
84 AuthGroupFile => $auth_group_file,
85 AuthOrder => 'mod_auth_file.c',
86
87 IfModules => {
88 'mod_delay.c' => {
89 DelayEngine => 'off',
90 },
91 },
92 };
93
94 my ($port, $config_user, $config_group) = config_write($config_file, $config);
95
96 # Open pipes, for use between the parent and child processes. Specifically,
97 # the child will indicate when it's done with its test by writing a message
98 # to the parent.
99 my ($rfh, $wfh);
100 unless (pipe($rfh, $wfh)) {
101 die("Can't open pipe: $!");
102 }
103
104 my $ex;
105
106 # Fork child
107 $self->handle_sigchld();
108 defined(my $pid = fork()) or die("Can't fork: $!");
109 if ($pid) {
110 eval {
111 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
112 $client->login($user, $passwd);
113 $client->quit();
114 };
115
116 if ($@) {
117 $ex = $@;
118 }
119
120 $wfh->print("done\n");
121 $wfh->flush();
122
123 } else {
124 eval { server_wait($config_file, $rfh) };
125 if ($@) {
126 warn($@);
127 exit 1;
128 }
129
130 exit 0;
131 }
132
133 # Stop server
134 server_stop($pid_file);
135
136 $self->assert_child_ok($pid);
137
138 if ($ex) {
139 test_append_logfile($log_file, $ex);
140 unlink($log_file);
141
142 die($ex);
143 }
144
145 unlink($log_file);
146 }
147
148 1;