]> gitweb.fluxo.info Git - puppet-samba.git/commitdiff
Remove check_samba_user and add_samba_user scripts
authorAlexander Fisher <alex@linfratech.co.uk>
Fri, 22 Jan 2016 15:32:28 +0000 (15:32 +0000)
committerAlexander Fisher <alex@linfratech.co.uk>
Fri, 22 Jan 2016 15:38:12 +0000 (15:38 +0000)
Call the pdbedit commands directly from samba::server::user instead

manifests/server.pp
manifests/server/user.pp
spec/classes/samba__server_spec.rb
spec/defines/samba__server__user_spec.rb [new file with mode: 0644]
templates/add_samba_user [deleted file]
templates/check_samba_user [deleted file]

index 550659c69f75134d6a103a9dcbd5f6475175597c..8a5853cdfb4de5163e08d36c34f1dd7b46d5e8ab 100644 (file)
@@ -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"),
-  }
 }
index b8f2e61ef1d2681d68e768b62ab8b8ca9792f653..d10a602a3558d633b03d86269d87fe1aad6255a9 100644 (file)
@@ -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??
   }
 }
index 69fa0ec7d0cd268c98ce93b90949985517837a4c..dbf840a4511c58d9504c1c09cbf809a29653d0f6 100644 (file)
@@ -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 (file)
index 0000000..c7ae00c
--- /dev/null
@@ -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 (file)
index cc1d56b..0000000
+++ /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 (file)
index 431c3c4..0000000
+++ /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