[openldap] configuration initialization from LDIF file

jvcelak jvcelak at fedoraproject.org
Wed Nov 30 17:59:46 UTC 2011


commit 8bd37126ac724b2988682f4e7f6d7b7a317b5ba2
Author: Jan Vcelak <jvcelak at redhat.com>
Date:   Fri Nov 25 23:14:25 2011 +0100

    configuration initialization from LDIF file

 openldap.spec                   |    7 ++-
 slapd-libexec-convert-config.sh |   18 +++++-
 slapd.conf                      |  141 ---------------------------------------
 slapd.ldif                      |    2 +-
 4 files changed, 22 insertions(+), 146 deletions(-)
---
diff --git a/openldap.spec b/openldap.spec
index 1049230..75153f3 100644
--- a/openldap.spec
+++ b/openldap.spec
@@ -15,7 +15,8 @@ Source0: ftp://ftp.OpenLDAP.org/pub/OpenLDAP/openldap-release/openldap-%{version
 Source1: slapd.service
 Source2: slapd.sysconfig
 Source3: slapd.tmpfiles
-Source4: slapd.conf
+Source4: slapd.conf.obsolete
+Source5: slapd.ldif
 Source50: slapd-libexec-functions
 Source51: slapd-libexec-convert-config.sh
 Source52: slapd-libexec-check-config.sh
@@ -359,8 +360,10 @@ chmod 0644 %{buildroot}%{_libdir}/lib*.*a
 mkdir -p %{buildroot}%{_datadir}
 install -m 0755 -d %{buildroot}%{_datadir}/openldap-servers
 install -m 0644 %SOURCE4 %{buildroot}%{_datadir}/openldap-servers/slapd.conf.obsolete
+install -m 0644 %SOURCE5 %{buildroot}%{_datadir}/openldap-servers/slapd.ldif
 install -m 0700 -d %{buildroot}%{_sysconfdir}/openldap/slapd.d
 rm -f %{buildroot}%{_sysconfdir}/openldap/slapd.conf
+rm -f %{buildroot}%{_sysconfdir}/openldap/slapd.ldif
 
 # move doc files out of _sysconfdir
 mv %{buildroot}%{_sysconfdir}/openldap/schema/README README.schema
@@ -440,7 +443,7 @@ if [ ! -f %{_sysconfdir}/openldap/slapd.d/cn=config.ldif ]; then
 		%{_libexecdir}/slapd/convert-config.sh &>/dev/null
 		mv %{_sysconfdir}/openldap/slapd.conf %{_sysconfdir}/openldap/slapd.conf.bak
 	else
-		%{_libexecdir}/slapd/convert-config.sh -f %{_datadir}/openldap-servers/slapd.conf.obsolete &>/dev/null
+		%{_libexecdir}/slapd/convert-config.sh -f %{_datadir}/openldap-servers/slapd.ldif &>/dev/null
 	fi
 fi
 
diff --git a/slapd-libexec-convert-config.sh b/slapd-libexec-convert-config.sh
index b3f0656..17025bf 100755
--- a/slapd-libexec-convert-config.sh
+++ b/slapd-libexec-convert-config.sh
@@ -34,6 +34,12 @@ if [ ! -f "$SLAPD_CONFIG_FILE" ]; then
 	exit 1
 fi
 
+if grep -iq '^dn: cn=config$' "$SLAPD_CONFIG_FILE"; then
+	SLAPD_CONFIG_FILE_FORMAT=ldif
+else
+	SLAPD_CONFIG_FILE_FORMAT=conf
+fi
+
 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"
@@ -47,12 +53,20 @@ tmp_convert=`mktemp`
 
 if [ `id -u` -eq 0 ]; then
 	install -d --owner $SLAPD_USER --group `id -g $SLAPD_USER` --mode 0700 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
-	run_as_ldap "/usr/sbin/slaptest -f \"$SLAPD_CONFIG_FILE\" -F \"$SLAPD_CONFIG_DIR\"" &>>$tmp_convert
+	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
 	retcode=$?
 else
 	error "You are not root! Permission will not be set."
 	install -d --mode 0700 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
-	/usr/sbin/slaptest -f "$SLAPD_CONFIG_FILE" -F "$SLAPD_CONFIG_DIR" &>>$tmp_convert
+	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
 	retcode=$?
 fi
 
diff --git a/slapd.ldif b/slapd.ldif
index 7f0fa1b..9904767 100644
--- a/slapd.ldif
+++ b/slapd.ldif
@@ -1,5 +1,5 @@
 #
-# See slapd.d(5) for details on configuration options.
+# See slapd-config(5) for details on configuration options.
 # This file should NOT be world readable.
 #
 dn: cn=config


More information about the scm-commits mailing list