#!/bin/sh set -e CONFFILE="/etc/nss-ldapd.conf" # remove NSS lookups though LDAP for the specified service nss_disable() { name="$1" # these functions also remove the lookup result handling part # of the ldap entry (see nsswitch.conf(5)) if grep -q '^'$name':.*ldap.*' /etc/nsswitch.conf then echo "/etc/nsswitch.conf: disable LDAP lookups for $name" >&2 if [ -n "`sed -n '/^'$name':[[:space:]]*ldap[[:space:]]*\(\[[^]]*\]\)*[[:space:]]*$/p' /etc/nsswitch.conf`" ] then # the name service only maps to ldap, remove the whole line sed -i '/^'$name':[[:space:]]*ldap[[:space:]]*\(\[[^]]*\]\)*[[:space:]]*$/d' /etc/nsswitch.conf else # remove ldap part from existing line, keeping other methods intact # TODO: remove trailing space sed -i 's/^\('$name':.*\)ldap[[:space:]]*\(\[[^]]*\]\)*[[:space:]]*\(.*\)$/\1\3/' /etc/nsswitch.conf fi fi # we're done return 0 } # remove /var/run/nslcd directory rm -rf /var/run/nslcd # offer to remove ldap from nsswitch.conf if ( [ "$1" = "remove" ] || [ "$1" = "purge" ] ) then # check which naming services are configured configured=`sed -n 's/^\([a-z]*\):.*[[:space:]]ldap\([[:space:]].*\)\?/\1/p' /etc/nsswitch.conf` if [ -n "$configured" ] then # if we have debconf, use debconf to ask, otherwise just shout if [ -e /usr/share/debconf/confmodule ] then # ask with debconf . /usr/share/debconf/confmodule db_title "Removing libnss-ldapd" db_subst libnss-ldapd/clean_nsswitch services "`echo $configured | sed 's/ /, /g'`" db_fset libnss-ldapd/clean_nsswitch seen false if db_input high libnss-ldapd/clean_nsswitch then db_go db_get libnss-ldapd/clean_nsswitch if [ "$RET" = "true" ] then for n in $configured do nss_disable $n done fi fi # re-check which services are left enabled configured=`sed -n 's/^\([a-z]*\):.*[[:space:]]ldap\([[:space:]].*\)\?/\1/p' /etc/nsswitch.conf` fi # check if ldap is still configured if [ -n "$configured" ] then echo "WARNING: LDAP is still configured in /etc/nsswitch.conf" >&2 fi fi fi # remove our configuration file (not a conffile) on purge if [ "$1" = "purge" ] then rm -f "$CONFFILE" fi # call ldconfig to signal the removal of our NSS library if [ "$1" = "remove" ] then ldconfig fi #DEBHELPER#