diff options
-rw-r--r-- | manifests/server.pp | 16 | ||||
-rw-r--r-- | manifests/server/user.pp | 8 | ||||
-rw-r--r-- | spec/classes/samba__server_spec.rb | 3 | ||||
-rw-r--r-- | spec/defines/samba__server__user_spec.rb | 14 | ||||
-rw-r--r-- | templates/add_samba_user | 16 | ||||
-rw-r--r-- | templates/check_samba_user | 16 |
6 files changed, 19 insertions, 54 deletions
diff --git a/manifests/server.pp b/manifests/server.pp index 550659c..8a5853c 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -58,20 +58,4 @@ class samba::server($interfaces = '', 'os level': value => $os_level; 'preferred master': value => $preferred_master; } - - file {'/sbin/check_samba_user': - # script checks to see if a samba account exists for a given user - owner => root, - group => root, - mode => '0755', - content => template("${module_name}/check_samba_user"), - } - - file {'/sbin/add_samba_user': - # script creates a new samba account for a given user and password - owner => root, - group => root, - mode => '0755', - content => template("${module_name}/add_samba_user"), - } } diff --git a/manifests/server/user.pp b/manifests/server/user.pp index b8f2e61..d10a602 100644 --- a/manifests/server/user.pp +++ b/manifests/server/user.pp @@ -4,10 +4,12 @@ define samba::server::user ( $password, $user_name = $name, ) { + require ::samba::server::install + exec { "add smb account for ${user_name}": - command => "/sbin/add_samba_user '${user_name}' '${password}'" , - unless => "/sbin/check_samba_user '${user_name}'" , + command => "/bin/echo -e '${password}\\n${password}\\n' | /usr/bin/pdbedit --password-from-stdin -a '${user_name}'", + unless => "/usr/bin/pdbedit '${user_name}'", require => [ User[$user_name] ], - notify => Class['samba::server::service'] + notify => Class['samba::server::service'] #TODO: Is this really required?? } } diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb index 69fa0ec..dbf840a 100644 --- a/spec/classes/samba__server_spec.rb +++ b/spec/classes/samba__server_spec.rb @@ -20,7 +20,4 @@ describe 'samba::server' do it { should contain_samba__server__option('printing') } it { should contain_samba__server__option('printcap name') } it { should contain_samba__server__option('disable spoolss') } - - it { should contain_file('/sbin/check_samba_user').with_owner('root') } - it { should contain_file('/sbin/add_samba_user').with_owner('root') } end diff --git a/spec/defines/samba__server__user_spec.rb b/spec/defines/samba__server__user_spec.rb new file mode 100644 index 0000000..c7ae00c --- /dev/null +++ b/spec/defines/samba__server__user_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'samba::server::user', :type => :define do + let(:title) { 'test_user' } + let(:params) {{ :password => 'secret' }} + + it { is_expected.to contain_samba__server__user('test_user') } + it { is_expected.to contain_exec('add smb account for test_user').with( + :command => '/bin/echo -e \'secret\nsecret\n\' | /usr/bin/pdbedit --password-from-stdin -a \'test_user\'', + :unless => '/usr/bin/pdbedit \'test_user\'', + :require => 'User[test_user]', + :notify => 'Class[Samba::Server::Service]' + ) } +end diff --git a/templates/add_samba_user b/templates/add_samba_user deleted file mode 100644 index cc1d56b..0000000 --- a/templates/add_samba_user +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# This script adds a samba account for a given user and password -# call as: -# > add_samba_user "USERNAME" "PASSWORD" - -/bin/echo -e "$2\n$2\n" | sudo /usr/bin/pdbedit -a "$1" -t 1>/dev/null -results=$? - -if [ $results = 0 ]; then - echo "added samba account for '$1'" -else - echo "could not add samba account for '$1'" -fi - -exit $results diff --git a/templates/check_samba_user b/templates/check_samba_user deleted file mode 100644 index 431c3c4..0000000 --- a/templates/check_samba_user +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# This script checks to see if a given user account exists on samba -# if so, it returns 0 -# otherwise it returns 1 - -sudo /usr/bin/pdbedit -L | egrep -q "^$1:" -exists=$? - -if [ $exists = 0 ]; then - echo "'$1' is a samba user" -else - echo "no samba account matching '$1'" -fi - -exit $exists |