d133c5
#!/bin/sh
d133c5
#
d133c5
# Turns on or off the nss-sysinit module db by editing the
d133c5
# global PKCS #11 congiguration file. Displays the status.
d133c5
#
d133c5
# This script can be invoked by the user as super user.
d133c5
# It is invoked at nss-sysinit post install time with argument on.
d133c5
#
d133c5
usage()
d133c5
{
d133c5
  cat <
d133c5
Usage: setup-nsssysinit [on|off]
d133c5
  on     - turns on nsssysinit
d133c5
  off    - turns off nsssysinit
d133c5
  status - reports whether nsssysinit is turned on or off
d133c5
EOF
d133c5
  exit $1
d133c5
}
d133c5
d133c5
# validate
d133c5
if [ $# -eq 0 ]; then
d133c5
  usage 1 1>&2
d133c5
fi
d133c5
d133c5
# the system-wide configuration file
d133c5
p11conf="/etc/pki/nssdb/pkcs11.txt"
d133c5
# must exist, otherwise report it and exit with failure
d133c5
if [ ! -f $p11conf ]; then
d133c5
  echo "Could not find ${p11conf}"
d133c5
  exit 1
d133c5
fi
d133c5
d133c5
# check if nsssysinit is currently enabled or disabled
d133c5
sysinit_enabled()
d133c5
{
d133c5
  grep -q '^library=libnsssysinit' ${p11conf}
d133c5
}
d133c5
d133c5
umask 022
d133c5
case "$1" in
d133c5
  on | ON )
d133c5
    if sysinit_enabled; then 
d133c5
      exit 0 
d133c5
    fi
d133c5
    cat ${p11conf} | \
d133c5
    sed -e 's/^library=$/library=libnsssysinit.so/' \
d133c5
        -e '/^NSS/s/\(Flags=internal\)\(,[^m]\)/\1,moduleDBOnly\2/' > \
d133c5
        ${p11conf}.on
d133c5
    mv ${p11conf}.on ${p11conf}
d133c5
    ;;
d133c5
  off | OFF )
d133c5
    if ! sysinit_enabled; then
d133c5
      exit 0
d133c5
    fi
d133c5
    cat ${p11conf} | \
d133c5
    sed -e 's/^library=libnsssysinit.so/library=/' \
d133c5
        -e '/^NSS/s/Flags=internal,moduleDBOnly/Flags=internal/' > \
d133c5
        ${p11conf}.off
d133c5
    mv ${p11conf}.off ${p11conf}
d133c5
    ;;
d133c5
  status )
d133c5
    echo -n 'NSS sysinit is '
d133c5
    sysinit_enabled && echo 'enabled' || echo 'disabled'
d133c5
    ;;
d133c5
  * )
d133c5
    usage 1 1>&2
d133c5
    ;;
d133c5
esac