Skip to content

Commit 5abd649

Browse files
author
Joshua Hoblitt
committed
add config_ldap param to class pureftpd
To allow passing a hash of pureftpd-ldap.conf configuration values through to class pureftpd::config::ldap
1 parent c3e8fdd commit 5abd649

File tree

4 files changed

+90
-22
lines changed

4 files changed

+90
-22
lines changed

Modulefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ Requirements:
1717
Todo:
1818
- complete the config_mysql and config_pgsql defines
1919
'
20-
21-
## Add dependencies, if any:
20+
dependency 'puppetlabs/stdlib', '>= 2.2.0'

README.md

+23-14
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,29 @@ defaults) and start `pure-ftpd` as a stand alone daemon.
3939

4040
### Enabling LDAP authentication
4141

42-
```
43-
pureftpd::config_ldap { 'ftp-server':
44-
ldap_server => '192.168.100.10',
45-
ldap_basedn => 'ou=Users,dc=company,dc=com',
46-
ldap_filter => '(&(objectClass=posixAccount)(uid=\L))',
47-
ldap_authmethod => 'BIND'
48-
user_bandwidth => '1800:1800'
49-
}
50-
```
51-
```
52-
pureftpd::config_pgsql { 'ftp-server':
53-
user_bandwidth => '1800:1800'
54-
}
55-
```
42+
class { 'pureftpd':
43+
use_selinux => true,
44+
config => {
45+
ipv4only => 'Yes',
46+
passiveportrange => '49999:59999',
47+
}
48+
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',
63+
}
64+
}
5665

5766
### TODO
5867
- add a configuration switch for the pem certificate file, in case TLS is used

manifests/init.pp

+20-1
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,34 @@
1818
class pureftpd (
1919
$use_selinux = false,
2020
$config = {},
21+
$config_ldap = {},
2122
) {
2223
validate_bool($use_selinux)
2324
validate_hash($config)
25+
validate_hash($config_ldap)
2426

2527
include pureftpd::service
2628

2729
class{ 'pureftpd::install': use_selinux => $use_selinux }
2830

29-
create_resources( 'class', { 'pureftpd::config' => $config } )
31+
unless (empty($config_ldap)) {
32+
# insert the path to the ldap conf file into pure-ftpd.conf
33+
$enable_ldap = { ldapconfigfile => $pureftpd::params::ldap_conf_path }
34+
35+
# instantiate pureftpd::config::ldap that will notify the service class
36+
$safe_config_ldap = merge($config,
37+
{ notify => Class[ 'pureftpd::service' ] }
38+
)
39+
create_resources( 'class', { 'pureftpd::config::ldap' => $config_ldap } )
40+
41+
# only try to create the ldap configuration file after the pureftpd package
42+
# is installed and configuration; otherwise the dir may not exist yet
43+
Class[ 'pureftpd::config' ] ->
44+
Class[ 'pureftpd::config::ldap' ]
45+
}
46+
47+
$safe_config = merge($config, $enable_ldap)
48+
create_resources( 'class', { 'pureftpd::config' => $safe_config } )
3049

3150
Class[ 'pureftpd::install' ] ->
3251
Class[ 'pureftpd::config' ] ->

spec/classes/pureftpd_spec.rb

+46-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
should include_class('pureftpd::service')
1212
should contain_package('pure-ftpd').with_ensure('present')
1313
should_not contain_package('pure-ftpd-selinux')
14-
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')
14+
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')\
15+
.with_content('')
1516
should contain_service('pure-ftpd').with({
1617
'ensure' => 'running',
1718
'enable' => 'true',
@@ -28,7 +29,8 @@
2829
should include_class('pureftpd::service')
2930
should contain_package('pure-ftpd').with_ensure('present')
3031
should contain_package('pure-ftpd-selinux').with_ensure('present')
31-
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')
32+
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')\
33+
.with_content('')
3234
should contain_service('pure-ftpd').with({
3335
'ensure' => 'running',
3436
'enable' => 'true',
@@ -45,7 +47,8 @@
4547
should include_class('pureftpd::service')
4648
should contain_package('pure-ftpd').with_ensure('present')
4749
should_not contain_package('pure-ftpd-selinux')
48-
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')
50+
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')\
51+
.with_content('')
4952
should contain_service('pure-ftpd').with({
5053
'ensure' => 'running',
5154
'enable' => 'true',
@@ -71,7 +74,8 @@
7174
should include_class('pureftpd::service')
7275
should contain_package('pure-ftpd').with_ensure('present')
7376
should_not contain_package('pure-ftpd-selinux')
74-
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')
77+
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file')\
78+
.with_content('')
7579
should contain_service('pure-ftpd').with({
7680
'ensure' => 'running',
7781
'enable' => 'true',
@@ -80,7 +84,12 @@
8084
end
8185

8286
describe 'with $config keys' do
83-
let(:params) {{ :config => { 'daemonize' => 'Yes', 'ipv4only' => 'No'} }}
87+
let(:params) {{
88+
:config => {
89+
'daemonize' => 'Yes',
90+
'ipv4only' => 'No',
91+
}
92+
}}
8493
it do
8594
should include_class('pureftpd')
8695
should include_class('pureftpd::install')
@@ -108,4 +117,36 @@
108117
}.to raise_error(Puppet::Error, /is not a Hash/)
109118
end
110119
end
120+
121+
describe 'with $config_ldap => { ldapserver => ldap.example.com }' do
122+
let(:params) {{
123+
:config_ldap => {
124+
'ldapserver' => 'ldap.example.com',
125+
'ldapport' => '389',
126+
}
127+
}}
128+
it do
129+
should include_class('pureftpd')
130+
should include_class('pureftpd::install')
131+
should include_class('pureftpd::config')
132+
should include_class('pureftpd::config::ldap')
133+
should include_class('pureftpd::service')
134+
should contain_package('pure-ftpd').with_ensure('present')
135+
should_not contain_package('pure-ftpd-selinux')
136+
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file') \
137+
.with_content(<<-END.gsub(/^\s+/, ""))
138+
LDAPConfigFile /etc/pure-ftpd/pureftpd-ldap.conf
139+
END
140+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf').with_ensure('file') \
141+
.with_content(<<-END.gsub(/^\s+/, ""))
142+
LDAPServer ldap.example.com
143+
LDAPPort 389
144+
END
145+
should contain_service('pure-ftpd').with({
146+
'ensure' => 'running',
147+
'enable' => 'true',
148+
})
149+
end
150+
end
151+
111152
end

0 commit comments

Comments
 (0)