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