Add a vim modeline with indentation settings.
[matthijs/upstream/backupninja.git] / handlers / ldap.helper.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
3
4 HELPERS="$HELPERS ldap:ldap_database_backup"
5
6 ldap_create_file() {
7    while true; do
8       checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \
9          "slapcat" "export ldif using slapcat" yes \
10          "ldapsearch" "export ldif using ldapsearch" no \
11          "compress" "compress the ldif output files" yes \
12          "ssl" "use SSL (deprecated)" no \
13          "tls" "use TLS extended operations (RFC2246, RFC2830)" yes
14       status=$?
15       compress="compress = no"
16       method="method = <unset>"
17       restart="restart = no"
18       binddn=""
19       passwordfile=""
20       ssl="ssl = no"
21       tls="tls = no"
22       [ $status = 1 ] && return;
23       result="$REPLY"
24       for opt in $result; do
25          case $opt in
26             '"compress"') compress="compress = yes";;
27             '"slapcat"')
28                method="method = slapcat"
29                [ "$_RESTART" == "yes" ] && restart="restart = yes"
30                ;;
31             '"ldapsearch"')
32                method="method = ldapsearch"
33                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."
34                [ $? = 1 ] && return
35                passwordfile="passwordfile = $REPLY"
36                inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:"
37                [ $? = 1 ] && return
38                binddn="binddn = $REPLY"
39                require_packages ldap-utils
40                ;;
41             '"ssl"') ssl="ssl = yes";;
42             '"tls"') tls="tls = yes";;
43          esac
44       done
45       get_next_filename $configdirectory/30.ldap
46       cat > $next_filename <<EOF
47 $method
48 $compress
49 $restart
50 $binddn
51 $passwordfile
52 $ssl
53 $tls
54 # backupdir = /var/backups/ldap
55 # conf = /etc/ldap/slapd.conf
56 # databases = all
57 EOF
58       chmod 600 $next_filename
59       return
60    done
61 }
62
63 ldap_wizard() {
64    bdb=no
65    hdb=no
66    ldbm=no
67    for backend in `grep -e "^backend" /etc/ldap/slapd.conf | @AWK@ '{print $2}'`; do
68       if [ "$backend" == "bdb" ]; then
69          bdb=yes
70       elif [ "$backend" == "hdb" ]; then
71          hdb=yes
72       elif [ "$backend" == "ldbm" ]; then
73          ldbm=yes
74       fi
75    done
76
77    if [ "$bdb" == "yes" -o "$hdb" == "yes" ]; then
78       if [ "$ldbm" == "no" ]; then
79          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."
80          _RESTART=no
81          ldap_create_file
82       fi
83    elif [ "$ldbm" == "yes" ]; then
84       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)."
85       _RESTART=yes
86       ldap_create_file
87    else
88       msgBox "ldap action wizard" "I couldn't find any supported backend in your slapd.conf. Bailing out."
89       return
90    fi
91 }