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