From 8099aafdd72b22dc98a39663d681fd6a5c4660fc Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: May 19 2005 21:19:05 +0000 Subject: - fixup indentation - use a wrapper script which execs slapd with the right arguments so that we can stop worrying about how daemon() handles arguments with whitespace in them --- diff --git a/ldap.init b/ldap.init index a82fca4..a8af4ba 100644 --- a/ldap.init +++ b/ldap.init @@ -20,7 +20,8 @@ if [ -r /etc/sysconfig/network ] ; then fi # Source an auxiliary options file if we have one, and pick up OPTIONS, -# SLAPD_OPTIONS, SLURPD_OPTIONS, and maybe KRB5_KTNAME. +# SLAPD_OPTIONS, SLURPD_OPTIONS, SLAPD_LDAPS, SLAPD_LDAPI, and maybe +# KRB5_KTNAME. if [ -r /etc/sysconfig/ldap ] ; then . /etc/sysconfig/ldap fi @@ -42,13 +43,13 @@ function testasuser() { shift cmd="$@" if test x"$user" != x ; then - if test x"$cmd" != x ; then - /sbin/runuser -f -m -s /bin/sh -c "test $cmd" -- "$user" - else - false - fi + if test x"$cmd" != x ; then + /sbin/runuser -f -m -s /bin/sh -c "test $cmd" -- "$user" + else + false + fi else - false + false fi } @@ -62,34 +63,34 @@ function checkkeytab() { service="$2" default="${3:-false}" if test -x /usr/kerberos/bin/klist ; then - klist=/usr/kerberos/bin/klist + klist=/usr/kerberos/bin/klist elif test -x /usr/bin/klist ; then - klist=/usr/bin/klist + klist=/usr/bin/klist fi KRB5_KTNAME="${KRB5_KTNAME:-/etc/krb5.keytab}" export KRB5_KTNAME if test -s "$KRB5_KTNAME" ; then - if test x"$klist" != x ; then - if LANG=C klist -k "$KRB5_KTNAME" | tail -n 4 | awk '{print $2}' | grep -q ^"$service"/ ; then - if ! testasuser "$user" -r ${KRB5_KTNAME:-/etc/krb5.keytab} ; then - true - else - false - fi - else - false - fi - else - $default - fi + if test x"$klist" != x ; then + if LANG=C klist -k "$KRB5_KTNAME" | tail -n 4 | awk '{print $2}' | grep -q ^"$service"/ ; then + if ! testasuser "$user" -r ${KRB5_KTNAME:-/etc/krb5.keytab} ; then + true + else + false + fi + else + false + fi + else + $default + fi else - false + false fi } function configtest() { local user= ldapuid= dbdir= file= - # Check for simple-but-common errors. + # Check for simple-but-common errors. user=ldap prog=`basename ${slapd}` ldapuid=`id -u $user` @@ -120,38 +121,53 @@ function configtest() { fi done # Check the configuration file. - action "Checking configuration files for $prog: " $slaptest $slaptestflags || exit 1 + action "Checking configuration files for $prog: " $slaptest $slaptestflags || exit 1 } function start() { configtest - # Start daemons. + # Define a couple of local variables which we'll need. Maybe. user=ldap prog=`basename ${slapd}` - echo -n $"Starting $prog: " - if grep -q ^TLS /etc/openldap/slapd.conf ; then - daemon ${slapd} -u ${user} -h "ldap:/// ldaps:///" $OPTIONS $SLAPD_OPTIONS - RETVAL=$? - else - daemon ${slapd} -u ${user} -h "ldap:///" $OPTIONS $SLAPD_OPTIONS - RETVAL=$? + # Build a wrapper script to exec slapd with the right arguments, to + # avoid being tripped out by changes or weirdness in how daemon() + # handles quoted arguments. + wrapper=`mktemp ${TMP:-/tmp}/start-slapd.XXXXXX` + harg="ldap:///" + if grep -q ^TLS /etc/openldap/slapd.conf || test x$SLAPD_LDAPS = xyes ; then + harg="$harg ldaps:///" + fi + if test x$SLAPD_LDAPI = xyes ; then + harg="$harg ldapi:///" fi + if test -z "$wrapper" ; then + return 1 + fi + cat >> $wrapper <<- EOF + exec ${slapd} -h "$harg" -u ${user} $OPTIONS $SLAPD_OPTIONS + EOF + chmod u+x $wrapper + trap "rm -f $wrapper" EXIT + # Start daemons. + echo -n $"Starting $prog: " + daemon --check=$prog $wrapper + RETVAL=$? echo if [ $RETVAL -eq 0 ]; then - if grep -q "^replogfile" /etc/openldap/slapd.conf; then + if grep -q "^replogfile" /etc/openldap/slapd.conf; then prog=`basename ${slurpd}` echo -n $"Starting $prog: " - daemon ${slurpd} $OPTIONS $SLURPD_OPTIONS + daemon ${slurpd} $OPTIONS $SLURPD_OPTIONS RETVAL=$? echo - fi + fi fi [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ldap return $RETVAL } function stop() { - # Stop daemons. + # Stop daemons. prog=`basename ${slapd}` echo -n $"Stopping $prog: " killproc ${slapd} @@ -166,25 +182,25 @@ function stop() { echo fi fi - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ldap /var/run/slapd.args + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ldap /var/run/slapd.args return $RETVAL } # See how we were called. case "$1" in configtest) - configtest - ;; + configtest + ;; start) - start - ;; + start + ;; stop) - stop - ;; + stop + ;; status) - status ${slapd} - if grep -q "^replogfile" /etc/openldap/slapd.conf ; then - status ${slurpd} + status ${slapd} + if grep -q "^replogfile" /etc/openldap/slapd.conf ; then + status ${slurpd} fi ;; restart) @@ -192,10 +208,10 @@ case "$1" in start ;; condrestart) - if [ -f /var/lock/subsys/ldap ] ; then - stop - start - fi + if [ -f /var/lock/subsys/ldap ] ; then + stop + start + fi ;; *) echo $"Usage: $0 {start|stop|restart|status|condrestart}"