92518265b62b1eddf3fdc229a494c74d23944d83
[matthijs/upstream/backupninja.git] / handlers / ldap.helper.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2
3 HELPERS="$HELPERS ldap:ldap_database_backup"
4
5 ldap_create_file() {
6 while true; do
7       checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \
8          "slapcat" "export ldif using slapcat" yes \
9          "ldapsearch" "export ldif using ldapsearch" no \
10          "compress" "compress the ldif output files" yes \
11          "ssl" "use SSL (deprecated)" no \
12          "tls" "use TLS extended operations (RFC2246, RFC2830)" yes
13       status=$?
14       compress="compress = no"
15       method="method = <unset>"
16       restart="restart = no"
17       binddn=""
18       passwordfile=""
19       ssl="ssl = no"
20       tls="tls = no"
21       [ $status = 1 ] && return;
22       result="$REPLY"
23       for opt in $result; do
24          case $opt in
25            '"compress"') compress="compress = yes";;
26            '"slapcat"')
27               method="method = slapcat"
28               [ "$_RESTART" == "yes" ] && restart="restart = yes"
29               ;;
30            '"ldapsearch"')
31               method="method = ldapsearch"
32               inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what password file to use. It must have the password with no trailing return and it should not be world readable."
33               [ $? = 1 ] && return
34               passwordfile="passwordfile = $REPLY"
35               inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:"
36               [ $? = 1 ] && return
37               binddn="binddn = $REPLY"
38               require_packages ldap-utils
39               ;;
40             '"ssl"') ssl="ssl = yes";;
41             '"tls"') tls="tls = yes";;
42          esac
43       done
44       get_next_filename $configdirectory/30.ldap
45       cat > $next_filename <<EOF
46 $method
47 $compress
48 $restart
49 $binddn
50 $passwordfile
51 $ssl
52 $tls
53 # backupdir = /var/backups/ldap
54 # conf = /etc/ldap/slapd.conf
55 # databases = all
56 EOF
57      chmod 600 $next_filename
58      return
59 done
60 }
61
62 ldap_wizard() {
63    bdb=no
64    hdb=no
65    ldbm=no
66    for backend in `grep -e "^backend" /etc/ldap/slapd.conf | @AWK@ '{print $2}'`; do
67       if [ "$backend" == "bdb" ]; then
68          bdb=yes
69       elif [ "$backend" == "hdb" ]; then
70          hdb=yes
71       elif [ "$backend" == "ldbm" ]; then
72          ldbm=yes
73       fi
74    done    
75
76    if [ "$bdb" == "yes" -o "$hdb" == "yes" ]; then
77       if [ "$ldbm" == "no" ]; then
78          msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to BDB or HDB. If this is not the case, exit this wizard! From this point on, we will assume BDB or HDB backend, which might have disasterious consequences if this is incorrect."
79          _RESTART=no
80          ldap_create_file
81       fi
82    elif [ "$ldbm" == "yes" ]; then
83      msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to LDBM. Because of this, you will have less options (because it is not safe to use slapcat while slapd is running LDBM)." 
84      _RESTART=yes
85      ldap_create_file
86    else
87      msgBox "ldap action wizard" "I couldn't find any supported backend in your slapd.conf. Bailing out." 
88      return
89    fi
90 }