summaryrefslogtreecommitdiff
path: root/populate-ldap/10d-test-use-detected-vlv.sh
blob: 3c8e24a34042622f14a24b1627ff8042e70e169d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash

 . ./settings.sh

vlvbasedn=""
vlvscope=""
vlvfilter=""
vlvsort=""

(
    ldapsearch -o ldif-wrap=no -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "cn=ldbm database,cn=plugins,cn=config" "(objectclass=vlvsearch)" entrydn | sed -e '/^dn:/{
    $!{ N
    s/dn: //
    s/\n\s//
}};') | grep -v '^$' | while read vlvsearch; do

    vlvbasedn=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvbase | sed '/^vlvbase:/{
    $!{ N
    s/vlvbase: //
    s/\n\s//
}}' | grep -vE "^(dn|\s)"`

    vlvscope=`ldapsearch -o ldif-wrap=no -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvscope | sed '/^vlvscope:/{
    $!{ N
    s/vlvscope: //
    s/\n\s//
}}' | grep -vE "^(dn|\s)"`

    vlvfilter=`ldapsearch -o ldif-wrap=no -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvfilter | sed '/^vlvfilter:/{
    $!{ N
    s/vlvfilter: //
    s/\n\s//
}}' | grep -vE "^(dn|\s)"`

    vlvsort=`ldapsearch -o ldif-wrap=no -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s sub "(objectclass=vlvIndex)" vlvsort | sed '/^vlvsort:/{
    $!{ N
    s/vlvsort: //
    s/\n\s//
}}' | grep -vE "^(dn|\s)"`

    echo "Found a VLV index and search with parameters:"
    echo " - Base: ${vlvbasedn}"
    echo -n " - Scope: "

    case ${vlvscope} in
        0)
            echo "base"
            vlvscope="base"
        ;;

        1)
            echo "one"
            vlvscope="one"
        ;;

        2)
            echo "sub"
            vlvscope="sub"
        ;;
    esac

    echo " - Filter: ${vlvfilter}"
    echo " - Sorting by: ${vlvsort}"

    # Use it

    uses_before=`ldapsearch \
        -o ldif-wrap=no \
	-x \
        -h ${ldap_host} \
        -D "${ldap_binddn}" \
        -w "${ldap_bindpw}" \
        -b "${vlvsearch}" \
        -s sub \
        "(&(objectclass=vlvindex)(vlvsort=${vlvsort}))" \
        -LLL \
        vlvuses | \
        grep -i ^vlvuses | awk '{print $2}'`

    if [ -z "${uses_before}" ]; then
        uses_before=0
    fi

    echo "Searching '${vlvbasedn}'"

    echo "after" | ldapsearch \
        -o ldif-wrap=no \
	-x \
        -h ${ldap_host} \
        -D "${ldap_binddn}" \
        -w "${ldap_bindpw}" \
        -b "${vlvbasedn}" \
        -s ${vlvscope} "${vlvfilter}" \
        -E '!vlv=5/5/1/10' \
        -E "!sss=$(echo ${vlvsort} | sed -e 's| |/|g')" >/dev/null 2>&1

    echo "Searching '${vlvsearch}'"

    uses_after=`ldapsearch \
        -o ldif-wrap=no \
	-x \
        -h ${ldap_host} \
        -D "${ldap_binddn}" \
        -w "${ldap_bindpw}" \
        -b "${vlvsearch}" \
        -s sub \
        "(&(objectclass=vlvindex)(vlvsort=${vlvsort}))" \
        -LLL \
        vlvuses | \
        grep -i ^vlvuses | awk '{print $2}'`

    if [ -z "${uses_after}" ]; then
        uses_after=0
    fi

    if [ ${uses_before} -lt ${uses_after} ]; then
        echo "Actually works, too (before: ${uses_before}, after: ${uses_after})"
    else
        echo "Does not seem to work (uses before -eq after)"
        echo "Used: ldapsearch -x -h '${ldap_host}' -D '${ldap_binddn}' -w '${ldap_bindpw}' -b '${vlvbasedn}' -s ${vlvscope} '${vlvfilter}' -E '!vlv=5/5/1/10' -E '!sss=$(echo ${vlvsort} | sed -e 's| |/|g')'"
    fi
done