#!/bin/sh set -e # editing nsswitch.conf seems to be ok # http://lists.debian.org/debian-devel/2007/02/msg00076.html # check whether the name is configure to do lookups through # LDAP # Note: this function is in libnss-ldapd.postinst and libnss-ldapd.postrm nss_is_enabled() { name="$1" grep -q '^[[:space:]]*'$name'[[:space:]]*:.*ldap.*' /etc/nsswitch.conf } # check to see if name is configured to do lookups through # LDAP and enable if not nss_enable() { name="$1" if ! nss_is_enabled "$name" then echo "/etc/nsswitch.conf: enable LDAP lookups for $name" >&2 if grep -q '^[[:space:]]*'$name'[[:space:]]*:' /etc/nsswitch.conf then # modify an existing entry by just adding ldap to the end sed -i 's/^\([[:space:]]*'$name'[[:space:]]*:.*[^[:space:]]\)[[:space:]]*$/\1 ldap/' /etc/nsswitch.conf else # append a new line printf '%-15s ldap\n' $name':' >> /etc/nsswitch.conf fi # invalidate nscd cache nscd -i "$name" > /dev/null 2>&1 || true fi # we're done return 0 } # remove NSS lookups though LDAP for the specified service # Note: this function is in libnss-ldapd.postinst and libnss-ldapd.postrm nss_disable() { name="$1" # these functions also remove the lookup result handling part # of the ldap entry (see nsswitch.conf(5)) if nss_is_enabled "$name" then echo "/etc/nsswitch.conf: disable LDAP lookups for $name" >&2 if [ -n "`sed -n '/^[[:space:]]*'$name'[[:space:]]*:[[:space:]]*ldap[[:space:]]*\(\[[^]]*\]\)*[[:space:]]*$/p' /etc/nsswitch.conf`" ] then # the name service only maps to ldap, remove the whole line sed -i '/^[[:space:]]*'$name'[[:space:]]*:[[: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/^\([[:space:]]*'$name'[[:space:]]*:.*\)ldap[[:space:]]*\(\[[^]]*\]\)*[[:space:]]*\(.*\)$/\1\3/' /etc/nsswitch.conf fi # invalidate nscd cache nscd -i "$name" > /dev/null 2>&1 || true fi # we're done return 0 } # real functions begin here if [ "$1" = "configure" ] then # get configuration data from debconf . /usr/share/debconf/confmodule # modify /etc/nsswitch.conf db_get libnss-ldapd/nsswitch enablenss=`echo "$RET" | sed 's/,//g'` for n in aliases ethers group hosts netgroup networks passwd protocols rpc services shadow do if echo ' '$enablenss' ' | grep -q ' '$n' ' then nss_enable $n else nss_disable $n fi done # we're done db_stop fi #DEBHELPER# exit 0