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