~ubuntu-branches/ubuntu/trusty/389-ds-base/trusty

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/ldif2ldap.in

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-08-30 00:31:55 UTC
  • mfrom: (1.2.1)
  • Revision ID: package-import@ubuntu.com-20130830003155-oimuzdqopkvp2cd0
Tags: 1.3.1.7-0ubuntu1
Sync from unreleased debian git.

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