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