# Install saslauthd daemon.
#
class saslauthd::server {

    package { "cyrus-sasl":
        ensure => installed,
    }

    service { "saslauthd":
        ensure  => running,
        enable  => true,
        require => Package["cyrus-sasl"],
    }

    file { "/etc/sasldb2":
        ensure  => present,
        mode    => 0644,
        owner   => root,
        group   => root,
        require => Exec["generate-sasldb2"],
    }
    exec { "generate-sasldb2":
        command => "saslpasswd2 -d foobar ; true",
        path    => "/bin:/usr/bin:/sbin:/usr/sbin",
        creates => "/etc/sasldb2",
        require => Package["cyrus-sasl"],
    }
    
}


# Install saslauthd service config
#
# === Parameters
#
#   $name:
#       Service name.
#
# === Sample usage
#
# saslauthd::service { "Sendmail": }
#
define saslauthd::service() {

    case $architecture {
        i386: { $libdir = "/usr/lib/sasl2" }
        x86_64: { $libdir = "/usr/lib64/sasl2" }
    }

    file { "${libdir}/${name}.conf":
        ensure  => present,
        source  => [ "puppet:///files/saslauthd/${name}.${fqdn}.conf",
                     "puppet:///files/saslauthd/${name}.conf",
                     "puppet:///files/saslauthd/service.conf",
                     "puppet:///modules/saslauthd/service.conf", ],
        mode    => 0644,
        owner   => root,
        group   => root,
        require => Service["saslauthd"],
    }

}
