PREIN
/bin/sh
/usr/share/rpm-helper/add-user openldap $1 ldap /var/lib/ldap /bin/false
# allowing slapd to read hosts.allow and hosts.deny
/usr/bin/gpasswd -a ldap adm 1>&2 > /dev/null || :
LDAPUSER=ldap
LDAPGROUP=ldap
[ -e "/etc/sysconfig/openldap" ] && . "/etc/sysconfig/openldap"
SLAPDCONF=${SLAPDCONF:-/etc/openldap/slapd.conf}
#decide whether we need to migrate at all:
MIGRATE=`/usr/sbin/slapd -VV 2>&1|while read a b c d e;do case $d in (2.3.*) echo nomigrate;;(2.*) echo migrate;;esac;done`
if [ "$1" -ne 1 -a -e "$SLAPDCONF" -a "$MIGRATE" != "nomigrate" ]
then
SLAPD_STATUS=`LANG=C LC_ALL=C NOLOCALE=1 service ldap status 2>/dev/null|grep -q stopped;echo $?`
[ $SLAPD_STATUS -eq 1 ] && service ldap stop
#`awk '/^[:space:]*directory[:space:]*\w*/ {print $2}' /etc/openldap/slapd.conf`
dbs=`awk 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2;suf="";dir=""}; /^[:space:]*suffix[:space:]*\w*/ {suf=$2;if((db=="bdb"||db=="ldbm"||db=="hdb")&&(suf!=""&&dir!="")) print dir,suf};/^[:space:]*directory[:space:]*\w*/ {dir=$2; if((db=="bdb"||db=="ldbm"||db="hdb")&&(suf!=""&&dir!="")) print dir,suf};' "$SLAPDCONF" $(awk '/^[[:blank:]]*include[[:blank:]]*/ {print $2}' "$SLAPDCONF")|sed -e 's/"//g'`
for db in $dbs
do
dbdir=${db/:*/}
dbsuffix=${db/*:/}
[ -e /etc/sysconfig/ldap ] && . /etc/sysconfig/ldap
# data migration between incompatible versions
# openldap >= 2.2.x have slapcat as a link to slapd, older releases do not
if [ "${AUTOMIGRATE:-yes}" == "yes" -a -f /usr/sbin/slapcat ]
then
ldiffile="rpm-migrate-to-2.3.ldif"
# dont do backups more than onc
if [ ! -e "${dbdir}/${ldiffile}-imported" -a ! -e "${dbdir}/${ldiffile}-import-failed" ];then
echo "Migrating pre-OpenLDAP-2.3 data"
echo "Making a backup of $dbsuffix to ldif file ${dbdir}/$ldiffile"
# For some reason, slapcat works in the shell when slapd is
# running but not via rpm ...
slapcat -b "$dbsuffix" -l ${dbdir}/${ldiffile} ||:
fi
fi
done
[ $SLAPD_STATUS -eq 1 ] && service ldap start || :
fi
PREUN
/bin/sh
/usr/share/rpm-helper/del-service openldap $1 ldap
POSTIN
/bin/sh
/sbin/ldconfig
SLAPD_STATUS=`LANG=C LC_ALL=C NOLOCALE=1 service ldap status 2>/dev/null|grep -q stopped;echo $?`
[ $SLAPD_STATUS -eq 1 ] && service ldap stop
# bgmilne: part 2 of gdbm->dbb conversion for data created with
# original package for 9.1:
dbnum=1
LDAPUSER=ldap
LDAPGROUP=ldap
[ -e "/etc/sysconfig/openldap" ] && . "/etc/sysconfig/openldap"
SLAPDCONF=${SLAPDCONF:-/etc/openldap/slapd.conf}
if [ -e "$SLAPDCONF" ]
then
dbs=`awk 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2;suf="";dir=""}; /^[:space:]*suffix[:space:]*\w*/ {suf=$2;if((db=="bdb"||db=="ldbm")&&(suf!=""&&dir!="")) print dir,suf};/^[:space:]*directory[:space:]*\w*/ {dir=$2; if((db=="bdb"||db=="ldbm")&&(suf!=""&&dir!="")) print dir,suf};' "$SLAPDCONF" $(awk '/^[[:blank:]]*include[[:blank:]]*/ {print $2}' "$SLAPDCONF")|sed -e 's/"//g'`
for db in $dbs
do
dbdir=${db/:*/}
dbsuffix=${db/*:/}
ldiffile="rpm-migrate-to-2.3.ldif"
if [ -e "${dbdir}/${ldiffile}" ]
then
echo -e "\n\nImporting $dbsuffix"
if [ -e ${dbdir}/ldap-rpm-backup ]
then
echo "Warning: Old ldap backup data in ${dbdir}/ldap-rpm-backup"
echo "These files will be removed"
rm -f ${dbdir}/ldap-rpm-backup/*
fi
echo "Moving the database files fom ${dbdir} to ${dbdir}/ldap-rpm-backup"
mkdir -p ${dbdir}/ldap-rpm-backup
mv -f ${dbdir}/{*.bdb,*.gdbm,*.dbb,log.*,__db*} ${dbdir}/ldap-rpm-backup 2>/dev/null
echo "Importing $dbsuffix from ${dbdir}/${ldiffile}"
if slapadd -q -cv -b "$dbsuffix" -l ${dbdir}/${ldiffile} > \
${dbdir}/rpm-ldif-import.log 2>&1
then
mv -f ${dbdir}/${ldiffile} ${dbdir}/${ldiffile}-imported
echo "Import complete, see log ${dbdir}/rpm-ldif-import.log"
echo "If any entries were not migrated, see ${dbdir}/${ldiffile}-imported"
else
mv -f ${dbdir}/${ldiffile} ${dbdir}/${ldiffile}-import-failed
echo "Import failed on ${dbdir}/${ldifffile}, see ${dbdir}/rpm-ldif-import.log"
echo "An ldif dump of $dbsuffix has been saved as ${dbdir}/${ldiffile}-import-failed"
echo -e "\nYou can import it manually by running (as root):"
echo "# service ldap stop"
echo "# slapadd -c -l ${dbdir}/${ldiffile}-import-failed"
echo "# chown $LDAPUSER:$LDAPGROUP ${dbdir}/*"
echo "# service ldap start"
fi
fi
chown ${LDAPUSER}:${LDAPGROUP} -R ${dbdir}
# openldap-2.0.x->2.1.x on ldbm/dbb backend seems to need reindex regardless:
#slapindex -n $dbnum
#dbnum=$[dbnum+1]
done
fi
[ $SLAPD_STATUS -eq 1 ] && service ldap start
# Setup log facility for OpenLDAP on new install
if [ -f /etc/syslog.conf -a $1 -eq 1 ]
then
# clean syslog
perl -pi -e "s|^.*ldap.*\n||g" /etc/syslog.conf
# probe free local-users
cntlog=""
for log in 7 6 5 3 2 1 0 4
do
grep -vE "local${log}[^;]*\.none" /etc/syslog.conf|grep -q local${log} || cntlog="${log}"
done
if [ "${cntlog}" != "" ];then
echo "# added by openldap-2.3.34 rpm $(date)" >> /etc/syslog.conf
# modified by Oden Eriksson
# echo "local${cntlog}.* /var/log/ldap/ldap.log" >> /etc/syslog.conf
echo -e "local${cntlog}.*\t\t\t\t\t\t\t-/var/log/ldap/ldap.log" >> /etc/syslog.conf
# reset syslog daemon
if [ -f /var/lock/subsys/syslog ]; then
service syslog restart > /dev/null 2>/dev/null || :
fi
else
echo "I can't set syslog local-user!"
fi
# set syslog local-user in /etc/sysconfig/ldap
perl -pi -e "s|^.*SLAPDSYSLOGLOCALUSER.*|SLAPDSYSLOGLOCALUSER=\"LOCAL${cntlog}\"|g" /etc/sysconfig/ldap
fi
# generate the ldap.pem cert here instead of the initscript
if [ ! -e /etc/ssl/openldap/ldap.pem ] ; then
if [ -x /usr/share/openldap/gencert.sh ] ; then
echo "Generating self-signed certificate..."
pushd /etc/ssl/openldap/ > /dev/null
yes ""|/usr/share/openldap/gencert.sh >/dev/null 2>&1
chmod 640 ldap.pem
chown root:ldap ldap.pem
popd > /dev/null
fi
echo "To generate a self-signed certificate, you can use the utility"
echo "/usr/share/openldap/gencert.sh..."
fi
pushd /etc/openldap/ > /dev/null
for i in slapd.conf slapd.access.conf ; do
if [ -f $i ]; then
chmod 0640 $i
chown root:ldap $i
fi
done
popd > /dev/null
/usr/share/rpm-helper/add-service openldap $1 ldap
# nscd reset
if [ -f /var/lock/subsys/nscd ]; then
service nscd restart > /dev/null 2>/dev/null || :
fi
POSTUN
/bin/sh
/sbin/ldconfig
if [ $1 = 0 ]; then
# remove ldap entry
perl -pi -e "s|^.*ldap.*\n||g" /etc/syslog.conf
# reset syslog daemon
if [ -f /var/lock/subsys/syslog ]; then
service syslog restart > /dev/null 2>/dev/null || :
fi
fi
/usr/share/rpm-helper/del-user openldap $1 ldap