added some fixes from ale for the ldap handler
[matthijs/upstream/backupninja.git] / handlers / ldap
index 7492e691f57192538227f5fa5f026eb180945918..242755edcd8b393e2c7b639fbba9ec823d5cf453 100644 (file)
@@ -12,6 +12,14 @@ getconf restart no
 getconf method ldapsearch
 getconf passwordfile
 getconf binddn
+getconf ldaphost
+getconf tls yes
+
+if [ $tls = 'yes' ]; then
+   URLBASE="ldaps"
+else
+   URLBASE="ldap"
+fi
 
 status="ok"
 
@@ -49,7 +57,11 @@ if [ "$ldif" == "yes" ]; then
          execstr="$SLAPCAT -f $conf -b $dbsuffix"
          debug "$execstr"
       else
-         execstr="$LDAPSEARCH -x -L -b ""$dbsuffix"" -D ""$binddn"" -y $passwordfile"
+         if [ -n "$ldaphost" ]; then
+            execstr="$LDAPSEARCH -H $URLBASE://$ldaphost -x -L -b ""$dbsuffix"" -D ""$binddn"" -y $passwordfile"
+         else
+            execstr="$LDAPSEARCH -x -L -b ""$dbsuffix"" -D ""$binddn"" -y $passwordfile"
+         fi
          [ -f "$passwordfile" ] || fatal "Password file $passwordfile not found. When method is set to ldapsearch, you must also specify a password file."
          debug "$execstr"
       fi
@@ -59,12 +71,20 @@ if [ "$ldif" == "yes" ]; then
             /etc/init.d/slapd stop
          fi
          
-         touch $dumpdir/$dbsuffix.ldif
-         if [ ! -f $dumpdir/$dbsuffix.ldif ]; then
-            fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif"
+        ext=
+        if [ "$compress" == "yes" ]; then
+           ext=".gz"
+        fi
+         touch $dumpdir/$dbsuffix.ldif$ext
+         if [ ! -f $dumpdir/$dbsuffix.ldif$ext ]; then
+            fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif$ext"
          fi
          
-         output=`$execstr > $dumpdir/$dbsuffix.ldif`
+         if [ "$compress" == "yes" ]; then
+            output=`$execstr | $GZIP > $dumpdir/$dbsuffix.ldif.gz`
+         else
+            output=`$execstr > $dumpdir/$dbsuffix.ldif`
+         fi
          code=$?
          if [ "$code" == "0" ]; then
             debug $output
@@ -73,10 +93,6 @@ if [ "$ldif" == "yes" ]; then
             warning $output
             warning "Failed ldif export of $dbsuffix"
          fi
-         if [ "$compress" == "yes" ]; then
-            output=`$GZIP -f "$dumpdir/$dbsuffix.ldif" 2>&1`
-            debug $output
-         fi
          
          if [ "$restart" == "yes" ]; then
             debug "Starting ldap server..."