Skip to content

Commit

Permalink
add config_pgsql param to class pureftpd
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Aug 6, 2013
1 parent df44134 commit 8f590be
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 24 deletions.
61 changes: 43 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,49 @@ defaults) and start `pure-ftpd` as a stand alone daemon.
passiveportrange => '49999:59999',
}
config_ldap => {
$ldapserver => 'ldap.example.com',
$ldapauthmethod => 'PASSWORD',
$ldapport => '389',
$ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
$ldapbindpw => 'r00tPaSsw0rD',
$ldapbasedn => 'cn=Users,dc=c9x,dc=org',
$ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
$ldaphomedir => 'homeDirectory',
$ldapversion => '3',
$ldapdefaultuid => '100',
$ldapdefaultgid => '100',
$ldapdefaultgid => '100',
$ldapusetls => 'False',
$ldapauthmethod => 'PASSWORD',
ldapserver => 'ldap.example.com',
ldapauthmethod => 'PASSWORD',
ldapport => '389',
ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
ldapbindpw => 'r00tPaSsw0rD',
ldapbasedn => 'cn=Users,dc=c9x,dc=org',
ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
ldaphomedir => 'homeDirectory',
ldapversion => '3',
ldapdefaultuid => '100',
ldapdefaultgid => '100',
ldapdefaultgid => '100',
ldapusetls => 'False',
ldapauthmethod => 'PASSWORD',
}
}

### TODO
- add a configuration switch for the pem certificate file, in case TLS is used
- Implement configuration variables for postgresql-based authentication
- Implement configuration variables for MySQL-based authentication
### Enabling PGSQL authentication

class { 'pureftpd':
use_selinux => true,
config => {
ipv4only => 'Yes',
passiveportrange => '49999:59999',
}
config_pgsql => {
pgsqlserver => 'localhost',
pgsqlport => '5432',
pgsqluser => 'postgres',
pgsqlpassword => 'rootpw',
pgsqldatabase => 'pureftpd',
pgsqlcrypt => 'cleartext',
pgsqlgetpw => 'SELECT Password FROM users WHERE User=\'\L\'',
pgsqlgetuid => 'SELECT Uid FROM users WHERE User=\'\L\'',
pgsqldefaultuid => '1000',
pgsqlgetgid => 'SELECT Gid FROM users WHERE User=\'\L\'',
pgsqldefaultgid => '1000',
pgsqlgetdir => 'SELECT Dir FROM users WHERE User=\'\L\'',
pgsqlgetqtafs => 'SELECT QuotaFiles FROM users WHERE User=\'\L\'',
pgsqlgetqtasz => 'SELECT QuotaSize FROM users WHERE User=\'\L\'',
pgsqlgetratioul => 'SELECT ULRatio FROM users WHERE User=\'\L\'',
pgsqlgetratiodl => 'SELECT DLRatio FROM users WHERE User=\'\L\'',
pgsqlgetbandwidthul => 'SELECT ULBandwidth FROM users WHERE User=\'\L\'',
pgsqlgetbandwidthdl => 'SELECT DLBandwidth FROM users WHERE User=\'\L\'',
}
}
30 changes: 25 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
# 5Ub-Z3r0
#
class pureftpd (
$use_selinux = false,
$config = {},
$config_ldap = {},
$use_selinux = false,
$config = {},
$config_ldap = {},
$config_pgsql = {},
) {
validate_bool($use_selinux)
validate_hash($config)
validate_hash($config_ldap)
validate_hash($config_pgsql)

include pureftpd::service

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

# instantiate pureftpd::config::ldap that will notify the service class
# instantiate a pureftpd::config::ldap that will notify the service class
$safe_config_ldap = merge($config,
{ notify => Class[ 'pureftpd::service' ] }
)
Expand All @@ -44,10 +46,28 @@
Class[ 'pureftpd::config::ldap' ]
}

unless (empty($config_pgsql)) {
# insert the path to the pgsql conf file into pure-ftpd.conf
$enable_pgsql = { pgsqlconfigfile => $pureftpd::params::pgsql_conf_path }

# instantiate a pureftpd::config::mysql will notify the service class
$safe_config_pgsql = merge($config,
{ notify => Class[ 'pureftpd::service' ] }
)
create_resources( 'class', { 'pureftpd::config::pgsql' => $config_pgsql } )

# only try to create the pgsql configuration file after the pureftpd
# package is installed and configuration; otherwise the dir may not exist
# yet
Class[ 'pureftpd::config' ] ->
Class[ 'pureftpd::config::pgsql' ]
}

$safe_config = merge(
$config,
{ notify => Class[ 'pureftpd::service' ] },
$enable_ldap
$enable_ldap,
$enable_pgsql
)

create_resources( 'class', { 'pureftpd::config' => $safe_config } )
Expand Down
33 changes: 32 additions & 1 deletion spec/classes/pureftpd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
end
end

describe 'with $config_ldap => { ldapserver => ldap.example.com }' do
describe 'with $config_ldap => { ... }' do
let(:params) {{
:config_ldap => {
'ldapserver' => 'ldap.example.com',
Expand Down Expand Up @@ -149,4 +149,35 @@
end
end

describe 'with $config_pgsql => { ... }' do
let(:params) {{
:config_pgsql => {
'pgsqlserver' => 'localhost',
'pgsqlport' => '5432',
}
}}
it do
should include_class('pureftpd')
should include_class('pureftpd::install')
should include_class('pureftpd::config')
should include_class('pureftpd::config::pgsql')
should include_class('pureftpd::service')
should contain_package('pure-ftpd').with_ensure('present')
should_not contain_package('pure-ftpd-selinux')
should contain_file('/etc/pure-ftpd/pure-ftpd.conf').with_ensure('file') \
.with_content(<<-END.gsub(/^\s+/, ""))
PGSQLConfigFile /etc/pure-ftpd/pureftpd-pgsql.conf
END
should contain_file('/etc/pure-ftpd/pureftpd-pgsql.conf').with_ensure('file') \
.with_content(<<-END.gsub(/^\s+/, ""))
PGSQLServer localhost
PGSQLPort 5432
END
should contain_service('pure-ftpd').with({
'ensure' => 'running',
'enable' => 'true',
})
end
end

end

0 comments on commit 8f590be

Please sign in to comment.