From 13d05c52ac12f738efbc79e5156836233e3c8205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=E4kinen?= Date: Tue, 27 Oct 2009 10:12:04 +0200 Subject: [PATCH] Added BDC support scripts to samba module. --- samba/files/sync-netlogon.sh | 45 ++++++++++++++++++++++++++++++++++++ samba/manifests/init.pp | 17 ++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 samba/files/sync-netlogon.sh diff --git a/samba/files/sync-netlogon.sh b/samba/files/sync-netlogon.sh new file mode 100755 index 0000000..f5eacdc --- /dev/null +++ b/samba/files/sync-netlogon.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# check that domain controller is alive +smbclient -N -L pdc > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error in netlogon sync, could not open connection to DC" + exit 1 +fi + +# get target directory +TARGETDIR="`echo '' | testparm --section-name netlogon 2> /dev/null | \ + sed -n 's/^[ \t]*path[ ]*=[ ]*\(.*\)$/\1/p'`" +if [ "${TARGETDIR}" = "" ]; then + echo "Error in netlogon sync, failed to determine netlogon directory" + exit 1 +fi +if [ ! -d "${TARGETDIR}" ]; then + echo "Error in netlogon sync, netlogon directory does not exist" + exit 1 +fi + +# create temporary working directory +TMPDIR=/tmp/netlogon.$$ +if [ -d ${TMPDIR} ]; then + echo "Temporary directory ${TMPDIR} already exists." + exit 1 +fi +mkdir ${TMPDIR} + +# copy netlogon data from domain controller +( smbclient //pdc/netlogon -N -Tqc - | (cd ${TMPDIR} ; tar xf - ) ) \ + >> /var/log/samba/log.sync-netlogon 2>&1 +if [ $? -ne 0 ]; then + echo "Error in netlogon sync see /var/log/samba/log.sync-netlogon" + exit 1 +fi + +rsync -a --delete ${TMPDIR}/ ${TARGETDIR}/ +if [ $? -ne 0 ]; then + echo "Error in netlogon sync, rsync failed" + exit 1 +fi +chcon -Rh -u system_u -t samba_share_t ${TARGETDIR}/ + +rm -rf ${TMPDIR} diff --git a/samba/manifests/init.pp b/samba/manifests/init.pp index 88a3076..b1aa4da 100644 --- a/samba/manifests/init.pp +++ b/samba/manifests/init.pp @@ -67,6 +67,23 @@ class samba::server { } +# Install support scripts for Backup Domain Controller +# +class samba::bdc { + + include samba::server + + file { "/etc/cron.hourly/sync-netlogon.sh": + ensure => present, + source => "puppet:///samba/sync-netlogon.sh", + mode => 0755, + owner => root, + group => root, + } + +} + + # Join samba server into domain. # # === Global variables