Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/debian/libnss-ldapd.postinst
blob: 34c55be7608306ee4339342185e3a15d60914cf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh

set -e

# editing nsswitch.conf seems to be ok
# http://lists.debian.org/debian-devel/2007/02/msg00076.html

# check to see if name is configured to do lookups through
# LDAP and enable if not
nss_enable()
{
  name="$1"
  if ! grep -q '^'$name':.*ldap.*' /etc/nsswitch.conf
  then
    echo "/etc/nsswitch.conf: enable LDAP lookups for $name" >&2
    if grep -q '^'$name':' /etc/nsswitch.conf
    then
      # modify an existing entry by just adding ldap to the end
      sed -i 's/^\('$name':.*[^[:space:]]\)[[:space:]]*$/\1 ldap/' /etc/nsswitch.conf
    else
      # append a new line
      printf '%-15s ldap\n' $name':' >> /etc/nsswitch.conf
    fi
  fi
  # we're done
  return 0
}

# 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
}

# 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
  # restart nscd to pick up changes in nsswitch.conf
  # (other processes will have to be restarted manually)
  if [ -x /etc/init.d/nscd ] && [ `pidof -s nscd` ]
  then
    if which invoke-rc.d >/dev/null 2>&1
    then
      invoke-rc.d nscd restart
    else
      /etc/init.d/nscd restart
    fi
  fi
  # update the cache of the dynamic linker
  # (we don't use dh_makeshlibs because that also installs a shlibs file
  # which we don't need)
  ldconfig
fi

#DEBHELPER#

exit 0