Skip to content

Commit 8f590be

Browse files
author
Joshua Hoblitt
committed
add config_pgsql param to class pureftpd
1 parent df44134 commit 8f590be

File tree

3 files changed

+100
-24
lines changed

3 files changed

+100
-24
lines changed

README.md

+43-18
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,49 @@ defaults) and start `pure-ftpd` as a stand alone daemon.
4646
passiveportrange => '49999:59999',
4747
}
4848
config_ldap => {
49-
$ldapserver => 'ldap.example.com',
50-
$ldapauthmethod => 'PASSWORD',
51-
$ldapport => '389',
52-
$ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
53-
$ldapbindpw => 'r00tPaSsw0rD',
54-
$ldapbasedn => 'cn=Users,dc=c9x,dc=org',
55-
$ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
56-
$ldaphomedir => 'homeDirectory',
57-
$ldapversion => '3',
58-
$ldapdefaultuid => '100',
59-
$ldapdefaultgid => '100',
60-
$ldapdefaultgid => '100',
61-
$ldapusetls => 'False',
62-
$ldapauthmethod => 'PASSWORD',
49+
ldapserver => 'ldap.example.com',
50+
ldapauthmethod => 'PASSWORD',
51+
ldapport => '389',
52+
ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
53+
ldapbindpw => 'r00tPaSsw0rD',
54+
ldapbasedn => 'cn=Users,dc=c9x,dc=org',
55+
ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
56+
ldaphomedir => 'homeDirectory',
57+
ldapversion => '3',
58+
ldapdefaultuid => '100',
59+
ldapdefaultgid => '100',
60+
ldapdefaultgid => '100',
61+
ldapusetls => 'False',
62+
ldapauthmethod => 'PASSWORD',
6363
}
6464
}
6565

66-
### TODO
67-
- add a configuration switch for the pem certificate file, in case TLS is used
68-
- Implement configuration variables for postgresql-based authentication
69-
- Implement configuration variables for MySQL-based authentication
66+
### Enabling PGSQL authentication
67+
68+
class { 'pureftpd':
69+
use_selinux => true,
70+
config => {
71+
ipv4only => 'Yes',
72+
passiveportrange => '49999:59999',
73+
}
74+
config_pgsql => {
75+
pgsqlserver => 'localhost',
76+
pgsqlport => '5432',
77+
pgsqluser => 'postgres',
78+
pgsqlpassword => 'rootpw',
79+
pgsqldatabase => 'pureftpd',
80+
pgsqlcrypt => 'cleartext',
81+
pgsqlgetpw => 'SELECT Password FROM users WHERE User=\'\L\'',
82+
pgsqlgetuid => 'SELECT Uid FROM users WHERE User=\'\L\'',
83+
pgsqldefaultuid => '1000',
84+
pgsqlgetgid => 'SELECT Gid FROM users WHERE User=\'\L\'',
85+
pgsqldefaultgid => '1000',
86+
pgsqlgetdir => 'SELECT Dir FROM users WHERE User=\'\L\'',
87+
pgsqlgetqtafs => 'SELECT QuotaFiles FROM users WHERE User=\'\L\'',
88+
pgsqlgetqtasz => 'SELECT QuotaSize FROM users WHERE User=\'\L\'',
89+
pgsqlgetratioul => 'SELECT ULRatio FROM users WHERE User=\'\L\'',
90+
pgsqlgetratiodl => 'SELECT DLRatio FROM users WHERE User=\'\L\'',
91+
pgsqlgetbandwidthul => 'SELECT ULBandwidth FROM users WHERE User=\'\L\'',
92+
pgsqlgetbandwidthdl => 'SELECT DLBandwidth FROM users WHERE User=\'\L\'',
93+
}
94+
}

manifests/init.pp

+25-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
# 5Ub-Z3r0
1717
#
1818
class pureftpd (
19-
$use_selinux = false,
20-
$config = {},
21-
$config_ldap = {},
19+
$use_selinux = false,
20+
$config = {},
21+
$config_ldap = {},
22+
$config_pgsql = {},
2223
) {
2324
validate_bool($use_selinux)
2425
validate_hash($config)
2526
validate_hash($config_ldap)
27+
validate_hash($config_pgsql)
2628

2729
include pureftpd::service
2830

@@ -32,7 +34,7 @@
3234
# insert the path to the ldap conf file into pure-ftpd.conf
3335
$enable_ldap = { ldapconfigfile => $pureftpd::params::ldap_conf_path }
3436

35-
# instantiate pureftpd::config::ldap that will notify the service class
37+
# instantiate a pureftpd::config::ldap that will notify the service class
3638
$safe_config_ldap = merge($config,
3739
{ notify => Class[ 'pureftpd::service' ] }
3840
)
@@ -44,10 +46,28 @@
4446
Class[ 'pureftpd::config::ldap' ]
4547
}
4648

49+
unless (empty($config_pgsql)) {
50+
# insert the path to the pgsql conf file into pure-ftpd.conf
51+
$enable_pgsql = { pgsqlconfigfile => $pureftpd::params::pgsql_conf_path }
52+
53+
# instantiate a pureftpd::config::mysql will notify the service class
54+
$safe_config_pgsql = merge($config,
55+
{ notify => Class[ 'pureftpd::service' ] }
56+
)
57+
create_resources( 'class', { 'pureftpd::config::pgsql' => $config_pgsql } )
58+
59+
# only try to create the pgsql configuration file after the pureftpd
60+
# package is installed and configuration; otherwise the dir may not exist
61+
# yet
62+
Class[ 'pureftpd::config' ] ->
63+
Class[ 'pureftpd::config::pgsql' ]
64+
}
65+
4766
$safe_config = merge(
4867
$config,
4968
{ notify => Class[ 'pureftpd::service' ] },
50-
$enable_ldap
69+
$enable_ldap,
70+
$enable_pgsql
5171
)
5272

5373
create_resources( 'class', { 'pureftpd::config' => $safe_config } )

spec/classes/pureftpd_spec.rb

+32-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
end
119119
end
120120

121-
describe 'with $config_ldap => { ldapserver => ldap.example.com }' do
121+
describe 'with $config_ldap => { ... }' do
122122
let(:params) {{
123123
:config_ldap => {
124124
'ldapserver' => 'ldap.example.com',
@@ -149,4 +149,35 @@
149149
end
150150
end
151151

152+
describe 'with $config_pgsql => { ... }' do
153+
let(:params) {{
154+
:config_pgsql => {
155+
'pgsqlserver' => 'localhost',
156+
'pgsqlport' => '5432',
157+
}
158+
}}
159+
it do
160+
should include_class('pureftpd')
161+
should include_class('pureftpd::install')
162+
should include_class('pureftpd::config')
163+
should include_class('pureftpd::config::pgsql')
164+
should include_class('pureftpd::service')
165+
should contain_package('pure-ftpd').with_ensure('present')
166+
should_not contain_package('pure-ftpd-selinux')
167+
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file') \
168+
.with_content(<<-END.gsub(/^\s+/, ""))
169+
PGSQLConfigFile /etc/pure-ftpd/pureftpd-pgsql.conf
170+
END
171+
should contain_file('/etc/pure-ftpd/pureftpd-pgsql.conf').with_ensure('file') \
172+
.with_content(<<-END.gsub(/^\s+/, ""))
173+
PGSQLServer localhost
174+
PGSQLPort 5432
175+
END
176+
should contain_service('pure-ftpd').with({
177+
'ensure' => 'running',
178+
'enable' => 'true',
179+
})
180+
end
181+
end
182+
152183
end

0 commit comments

Comments
 (0)