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