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