2 # Author: Jan Vcelak <jvcelak@redhat.com>
4 . /usr/libexec/openldap/functions
8 error "usage: %s [-f config-file] [-F config-dir]\n" "`basename $0`"
14 while getopts :f:F: opt; do
17 SLAPD_CONFIG_FILE="$OPTARG"
20 SLAPD_CONFIG_DIR="$OPTARG"
30 # check source, target
32 if [ ! -f "$SLAPD_CONFIG_FILE" ]; then
33 error "Source configuration file '%s' not found." "$SLAPD_CONFIG_FILE"
37 if grep -iq '^dn: cn=config$' "$SLAPD_CONFIG_FILE"; then
38 SLAPD_CONFIG_FILE_FORMAT=ldif
40 SLAPD_CONFIG_FILE_FORMAT=conf
43 if [ -d "$SLAPD_CONFIG_DIR" ]; then
44 if [ `find "$SLAPD_CONFIG_DIR" -maxdepth 0 -empty | wc -l` -eq 0 ]; then
45 error "Target configuration directory '%s' is not empty." "$SLAPD_CONFIG_DIR"
50 # perform the conversion
52 tmp_convert=`mktemp --tmpdir=/var/run/openldap`
54 if [ `id -u` -eq 0 ]; then
55 install -d --owner $SLAPD_USER --group `id -g $SLAPD_USER` --mode 0750 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
56 if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
57 run_as_ldap "/usr/sbin/slapadd -F \"$SLAPD_CONFIG_DIR\" -n 0 -l \"$SLAPD_CONFIG_FILE\"" &>>$tmp_convert
59 run_as_ldap "/usr/sbin/slaptest -f \"$SLAPD_CONFIG_FILE\" -F \"$SLAPD_CONFIG_DIR\"" &>>$tmp_convert
63 error "You are not root! Permission will not be set."
64 install -d --mode 0750 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
65 if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
66 /usr/sbin/slapadd -F "$SLAPD_CONFIG_DIR" -n 0 -l "$SLAPD_CONFIG_FILE" &>>$tmp_convert
68 /usr/sbin/slaptest -f "$SLAPD_CONFIG_FILE" -F "$SLAPD_CONFIG_DIR" &>>$tmp_convert
73 if [ $retcode -ne 0 ]; then
74 error "Configuration conversion failed:"