Added the "Emacs comment line" on top of every shell file.
[matthijs/upstream/backupninja.git] / handlers / ldap.helper
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 HELPERS="$HELPERS ldap:ldap_database_backup"
3
4 ldap_create_file() {
5 while true; do
6       checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \
7          "slapcat" "export ldif using slapcat" on \
8          "ldapsearch" "export ldif using ldapsearch" off \
9          "compress" "compress the ldif output files" on
10       status=$?
11       compress="compress = off"
12       method="method = <unset>"
13       restart="restart = no"
14       binddn=""
15       passwordfile=""
16       [ $status = 1 ] && return;
17       result="$REPLY"
18       for opt in $result; do
19          case $opt in
20            '"compress"') compress="compress = on";;
21            '"slapcat"')
22               method="method = slapcat"
23               [ "$_RESTART" == "yes" ] && restart="restart = yes"
24               ;;
25            '"ldapsearch"')
26               method="method = ldapsearch"
27               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."
28               [ $? = 1 ] && return
29               passwordfile="passwordfile = $REPLY"
30               inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:"
31               [ $? = 1 ] && return
32               binddn="binddn = $REPLY"
33               require_packages ldap-utils
34               ;;
35          esac
36       done
37       get_next_filename $configdirectory/30.ldap
38       cat > $next_filename <<EOF
39 $method
40 $compress
41 $restart
42 $binddn
43 $passwordfile
44 # backupdir = /var/backups/ldap
45 # conf = /etc/ldap/slapd.conf
46 # databases = all
47 EOF
48      chmod 600 $next_filename
49      return
50 done
51 }
52
53 ldap_wizard() {
54    bdb=no
55    ldbm=no
56    for backend in `grep -e "^backend" /etc/ldap/slapd.conf | awk '{print $2}'`; do
57       if [ "$backend" == "bdb" -a "$bdb" == "no" ]; then
58          bdb=yes
59       elif [ "$backend" == "ldbm" -a "$ldbm" == "no" ]; then
60          ldbm=yes
61       fi
62    done    
63
64    if [ "$bdb" == "yes" -a "$ldbm" == "no" ]; then
65      msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to BDB. If this is not the case, exit this wizard! From this point on, we will assume BDB backend, which might have disasterious consequences if this is incorrect."
66      _RESTART=no
67      ldap_create_file
68    elif [ "$ldbm" == "yes" ]; then
69      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)." 
70      _RESTART=yes
71      ldap_create_file
72    else
73      msgBox "ldap action wizard" "I couldn't find any backends in your slapd.conf. Bailing out." 
74      return
75    fi
76 }
77