Blame SOURCES/libexec-create-certdb.sh

103552
#!/bin/bash
103552
# Author: Jan Vcelak <jvcelak@redhat.com>
103552
103552
set -e
103552
103552
# default options
103552
103552
CERTDB_DIR=/etc/openldap/certs
103552
103552
# internals
103552
103552
MODULE_CKBI="$(rpm --eval %{_libdir})/libnssckbi.so"
103552
RANDOM_SOURCE=/dev/urandom
103552
PASSWORD_BYTES=32
103552
103552
# parse arguments
103552
103552
usage() {
103552
	printf "usage: create-certdb.sh [-d certdb]\n" >&2
103552
	exit 1
103552
}
103552
103552
while getopts "d:" opt; do
103552
	case "$opt" in
103552
	d)
103552
		CERTDB_DIR="$OPTARG"
103552
		;;
103552
	\?)
103552
		usage
103552
		;;
103552
	esac
103552
done
103552
103552
[ "$OPTIND" -le "$#" ] && usage
103552
103552
# verify target location
103552
103552
if [ ! -d "$CERTDB_DIR" ]; then
103552
	printf "Directory '%s' does not exist.\n" "$CERTDB_DIR" >&2
103552
	exit 1
103552
fi
103552
103552
if [ ! "$(find "$CERTDB_DIR"  -maxdepth 0 -empty | wc -l)" -eq 1 ]; then
103552
	printf "Directory '%s' is not empty.\n" "$CERTDB_DIR" >&2
103552
	exit 1
103552
fi
103552
103552
# create the database
103552
103552
printf "Creating certificate database in '%s'.\n" "$CERTDB_DIR" >&2
103552
103552
PASSWORD_FILE="$CERTDB_DIR/password"
103552
OLD_UMASK="$(umask)"
103552
umask 0377
103552
dd if=$RANDOM_SOURCE bs=$PASSWORD_BYTES count=1 2>/dev/null | base64 > "$PASSWORD_FILE"
103552
umask "$OLD_UMASK"
103552
103552
certutil -d "$CERTDB_DIR" -N -f "$PASSWORD_FILE" &>/dev/null
103552
103552
# load module with builtin CA certificates
103552
103552
echo | modutil -dbdir "$CERTDB_DIR" -add "Root Certs" -libfile "$MODULE_CKBI" &>/dev/null
103552
103552
# tune permissions
103552
103552
for dbfile in "$CERTDB_DIR"/*.db; do
103552
	chmod 0644 "$dbfile"
103552
done
103552
103552
exit 0