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