2011-10-25 14:33:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Author: Jan Vcelak <jvcelak@redhat.com>
|
|
|
|
|
2012-02-14 12:21:32 +00:00
|
|
|
. /usr/libexec/openldap/functions
|
2011-10-25 14:33:20 +00:00
|
|
|
|
|
|
|
function help()
|
|
|
|
{
|
|
|
|
error "usage: %s [-f config-file] [-F config-dir]\n" "`basename $0`"
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
load_sysconfig
|
|
|
|
|
|
|
|
while getopts :f:F: opt; do
|
|
|
|
case "$opt" in
|
|
|
|
f)
|
|
|
|
SLAPD_CONFIG_FILE="$OPTARG"
|
|
|
|
;;
|
|
|
|
F)
|
|
|
|
SLAPD_CONFIG_DIR="$OPTARG"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
[ -n "$1" ] && help
|
|
|
|
|
|
|
|
# check source, target
|
|
|
|
|
|
|
|
if [ ! -f "$SLAPD_CONFIG_FILE" ]; then
|
|
|
|
error "Source configuration file '%s' not found." "$SLAPD_CONFIG_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-11-25 22:14:25 +00:00
|
|
|
if grep -iq '^dn: cn=config$' "$SLAPD_CONFIG_FILE"; then
|
|
|
|
SLAPD_CONFIG_FILE_FORMAT=ldif
|
|
|
|
else
|
|
|
|
SLAPD_CONFIG_FILE_FORMAT=conf
|
|
|
|
fi
|
|
|
|
|
2011-10-25 14:33:20 +00:00
|
|
|
if [ -d "$SLAPD_CONFIG_DIR" ]; then
|
|
|
|
if [ `find "$SLAPD_CONFIG_DIR" -maxdepth 0 -empty | wc -l` -eq 0 ]; then
|
|
|
|
error "Target configuration directory '%s' is not empty." "$SLAPD_CONFIG_DIR"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# perform the conversion
|
|
|
|
|
2012-10-11 09:56:59 +00:00
|
|
|
tmp_convert=`mktemp --tmpdir=/var/run/openldap`
|
2011-10-25 14:33:20 +00:00
|
|
|
|
|
|
|
if [ `id -u` -eq 0 ]; then
|
|
|
|
install -d --owner $SLAPD_USER --group `id -g $SLAPD_USER` --mode 0700 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
|
2011-11-25 22:14:25 +00:00
|
|
|
if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
|
|
|
|
run_as_ldap "/usr/sbin/slapadd -F \"$SLAPD_CONFIG_DIR\" -n 0 -l \"$SLAPD_CONFIG_FILE\"" &>>$tmp_convert
|
|
|
|
else
|
|
|
|
run_as_ldap "/usr/sbin/slaptest -f \"$SLAPD_CONFIG_FILE\" -F \"$SLAPD_CONFIG_DIR\"" &>>$tmp_convert
|
|
|
|
fi
|
2011-10-25 14:33:20 +00:00
|
|
|
retcode=$?
|
|
|
|
else
|
|
|
|
error "You are not root! Permission will not be set."
|
|
|
|
install -d --mode 0700 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
|
2011-11-25 22:14:25 +00:00
|
|
|
if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
|
|
|
|
/usr/sbin/slapadd -F "$SLAPD_CONFIG_DIR" -n 0 -l "$SLAPD_CONFIG_FILE" &>>$tmp_convert
|
|
|
|
else
|
|
|
|
/usr/sbin/slaptest -f "$SLAPD_CONFIG_FILE" -F "$SLAPD_CONFIG_DIR" &>>$tmp_convert
|
|
|
|
fi
|
2011-10-25 14:33:20 +00:00
|
|
|
retcode=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $retcode -ne 0 ]; then
|
|
|
|
error "Configuration conversion failed:"
|
|
|
|
cat $tmp_convert >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm $tmp_convert
|
|
|
|
exit $retcode
|