~ubuntu-branches/ubuntu/vivid/389-ds-base/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/admin_scripts.diff/ldap/admin/src/scripts/monitor.in

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2015-01-16 15:40:23 UTC
  • Revision ID: package-import@ubuntu.com-20150116154023-8gelb90338zoenea
Tags: 1.3.3.5-3
use-bash-instead-of-sh.diff: Drop admin_scripts.diff and patch the
scripts to use bash instead of trying to fix bashisms. (Closes:
#772195)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
source @datadir@/@package_name@/data/DSSharedLib
4
 
 
5
 
libpath_add "@libdir@/@package_name@/"
6
 
libpath_add "@ldapsdk_libdir@"
7
 
libpath_add "@libdir@"
8
 
libpath_add "@nss_libdir@"
9
 
 
10
 
export LD_LIBRARY_PATH
11
 
SHLIB_PATH=$LD_LIBRARY_PATH
12
 
export SHLIB_PATH
13
 
PATH=$PATH:@ldaptool_bindir@:@ldaptool_bindir@:/usr/bin/:/usr/lib64/mozldap
14
 
 
15
 
protocol=""
16
 
 
17
 
usage ()
18
 
{
19
 
    echo "Usage: monitor [ -Z serverID ] [ -D rootdn ] [ -w password ] [ -b basedn ] [-P protocol] [-h]"
20
 
    echo "Options:"
21
 
    echo "        -Z serverID  - Server instance identifier"
22
 
    echo "        -D rootdn    - Directory Manager DN"
23
 
    echo "        -w passwd    - Directory Manager password"
24
 
    echo "        -P protocol  - STARTTLS, LDAPS, LDAPI, LDAP"
25
 
    echo "        -h           - Display usage"
26
 
}
27
 
 
28
 
while getopts "Z:b:hP:D:w:" flag
29
 
do
30
 
    case $flag in
31
 
        Z) servid=$OPTARG;;
32
 
        P) protocol=$OPTARG;;
33
 
        b) MDN=$OPTARG;;
34
 
        D) rootdn=$OPTARG;;
35
 
        w) passwd=$OPTARG;;
36
 
        h) usage
37
 
           exit 0;;
38
 
        ?) usage
39
 
           exit 1;;
40
 
    esac
41
 
done
42
 
 
43
 
initfile=$(get_init_file "@initconfigdir@" $servid)
44
 
if [ $? == 1 ]
45
 
then
46
 
    usage
47
 
    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
48
 
    echo "Available instances: $initfile"
49
 
    exit 1
50
 
fi
51
 
 
52
 
if [ -z "$MDN" ]
53
 
then
54
 
    MDN="cn=monitor"
55
 
fi
56
 
 
57
 
. $initfile
58
 
 
59
 
process_dse $CONFIG_DIR $$
60
 
file="/tmp/DSSharedLib.$$"
61
 
port=$(grep -i 'nsslapd-port' $file | awk '{print $2}' )
62
 
host=$(grep -i 'nsslapd-localhost' $file | awk '{print $2}' )
63
 
security=$(grep -i 'nsslapd-security' $file | awk '{print $2}' )
64
 
secure_port=$(grep -i 'nsslapd-secureport' $file | awk '{print $2}' )
65
 
ldapi=$(grep -i 'nsslapd-ldapilisten' $file | awk '{print $2}' )
66
 
ldapiURL=$(grep -i 'nsslapd-ldapifilepath' $file | awk '{print $2}' )
67
 
certdir=$(grep -i 'nsslapd-certdir' $file | awk '{print $2}' )
68
 
autobind=$(grep -i 'nsslapd-ldapiautobind' $file | awk '{print $2}' )
69
 
if [ "$rootdn" == "" ]; then
70
 
    value=$(grep -i 'nsslapd-rootdn' $file)
71
 
    rootdn=`echo "$value" | sed -e 's/nsslapd-rootdn: //i'`
72
 
fi
73
 
rm $file
74
 
 
75
 
if [ "$passwd" != "" ]; then
76
 
    dn="-D $rootdn"
77
 
    passwd="-w$passwd"
78
 
fi
79
 
if [ "$ldapiURL" != "" ]
80
 
then
81
 
    ldapiURL=`echo "$ldapiURL" | sed -e 's/\//%2f/g'`
82
 
    ldapiURL="ldapi://"$ldapiURL
83
 
fi
84
 
 
85
 
client_type=`ldapsearch -V 2>&1`;
86
 
echo "$client_type" | grep -q "OpenLDAP"
87
 
if  [ $? -eq 0 ]
88
 
then
89
 
    openldap="yes"
90
 
    export LDAPTLS_CACERTDIR=$certdir
91
 
fi
92
 
 
93
 
if [ -z $security ]; then
94
 
    security="off"
95
 
fi
96
 
revised_protocol=$(check_protocol $protocol $security $ldapi $openldap)
97
 
if [ "$revised_protocol" != "$protocol" ]; then
98
 
    echo Protocol $protocol requested, but this protocol is not supported
99
 
    error="yes"
100
 
fi
101
 
protocol=$revised_protocol
102
 
 
103
 
#
104
 
# STARTTLS
105
 
#
106
 
if [ "$security" == "on" ]; then
107
 
    if [ "$protocol" == "STARTTLS" ] || [ "$protocol" == "" ]; then
108
 
        if [ "$error" == "yes" ]; then 
109
 
            echo "Using the next most secure protocol(STARTTLS)"
110
 
        fi
111
 
        if [ "$openldap" == "yes" ]; then
112
 
            ldapsearch -x -LLL -ZZ -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
113
 
        else
114
 
            ldapsearch -ZZZ -P $certdir  -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
115
 
        fi
116
 
        exit $?
117
 
    fi
118
 
fi
119
 
 
120
 
#
121
 
# LDAPS
122
 
#
123
 
if [ "$security" == "on" ]; then
124
 
    if [ "$protocol" == "LDAPS" ] || [ "$protocol" == "" ]; then
125
 
        if [ "$error" == "yes" ]; then 
126
 
            echo "Using the next most secure protocol(LDAPS)"
127
 
        fi
128
 
        if [ "$openldap" == "yes" ]; then
129
 
            ldapsearch -x -LLL -H "ldaps://$host:$secure_port" -b "$MDN" -s base $dn $passwd "objectClass=*"
130
 
        else 
131
 
            ldapsearch -Z -P $certdir -p $secure_port -b "$MDN" -s base $dn $passwd "objectClass=*"
132
 
        fi
133
 
        exit $?
134
 
    fi
135
 
fi
136
 
 
137
 
#
138
 
# LDAPI
139
 
#
140
 
if [ "$ldapi" == "on" ] && [ "$openldap" == "yes" ]; then
141
 
    if [ "$protocol" == "LDAPI" ] || [ "$protocol" == "" ]; then
142
 
        if [ "$(id -u)" == "0" ] && [ "$autobind" == "on" ]; then
143
 
            if [ "$error" == "yes" ]; then 
144
 
                echo "Using the next most secure protocol(LDAPI/AUTOBIND)"
145
 
            fi
146
 
            ldapsearch -LLL -H "$ldapiURL" -b "$MDN" -s base -Y EXTERNAL "objectClass=*" 2>/dev/null
147
 
        else
148
 
            if [ "$error" == "yes" ]; then 
149
 
                echo "Using the next most secure protocol(LDAPI)"
150
 
            fi
151
 
            ldapsearch -x -LLL -H "$ldapiURL" -b "$MDN" -s base $dn $passwd "objectClass=*"
152
 
        fi
153
 
        exit $?
154
 
    fi
155
 
fi
156
 
 
157
 
#
158
 
# LDAP
159
 
#
160
 
if [ "$protocol" == "LDAP" ] || [ "$protocol" == "" ]; then
161
 
    if [ "$error" == "yes" ]; then 
162
 
        echo "Using the next most secure protocol(LDAP)"
163
 
    fi
164
 
    if [ "$openldap" == "yes" ]; then
165
 
        ldapsearch -x -LLL -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
166
 
    else
167
 
        ldapsearch -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
168
 
    fi   
169
 
    exit $?
170
 
fi