setup_testsuite revision 5739
5739N/A#!/bin/ksh93 -p
5739N/A#
5739N/A# CDDL HEADER START
5739N/A#
5739N/A# The contents of this file are subject to the terms of the
5739N/A# Common Development and Distribution License (the "License").
5739N/A# You may not use this file except in compliance with the License.
5739N/A#
5739N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5739N/A# or http://www.opensolaris.org/os/licensing.
5739N/A# See the License for the specific language governing permissions
5739N/A# and limitations under the License.
5739N/A#
5739N/A# When distributing Covered Code, include this CDDL HEADER in each
5739N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5739N/A# If applicable, add the following below this CDDL HEADER, with the
5739N/A# fields enclosed by brackets "[]" replaced with your own identifying
5739N/A# information: Portions Copyright [yyyy] [name of copyright owner]
5739N/A#
5739N/A# CDDL HEADER END
5739N/A#
5739N/A
5739N/A#
5739N/A# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5739N/A#
5739N/A
5739N/A# Run this command as root to set up for sasl testsuite
5739N/A# creates a standard set of sasl users and makes them principals
5739N/A# -- create/recreate the KDC principal DB
5739N/A# -- create a sasldb
5739N/A
5739N/A#TODO
5739N/A# -- create a TestSuite.conf file for a default simple test
5739N/A
5739N/A#PATH=/usr/bin:/usr/sbin:/usr/gnu/bin
5739N/A
5739N/Aexport THIRTYTWO
5739N/Acase `uname -p` in
5739N/A i386)
5739N/A THIRTYTWO="i86"
5739N/A ;;
5739N/A
5739N/A sparc) THIRTYTWO="sparcv7"
5739N/A ;;
5739N/A
5739N/A *) echo "Architecture unknown"
5739N/A exit 1
5739N/A ;;
5739N/Aesac
5739N/A
5739N/A
5739N/A# realm used as default, edit if a different realm is desired.
5739N/Arealm="SASLTEST.NET"
5739N/A# realm for cross-realm auth.
5739N/Acrossrealm=
5739N/A
5739N/A# password for all principals not added to keytab
5739N/Aexport passwd="1234"
5739N/A
5739N/A# Set this to the ID that is allowed to run kadmin
5739N/A# Be default you would do: "kadmin -p kdc/admin" and use the passwd above.
5739N/Aadmin_princ="kdc/admin"
5739N/A
5739N/A# used to determine if in batch/non-intera/home/willf/app_support/etc/krb5/templates/db2ctive mode
5739N/Aforce='false'
5739N/Acheck_leaks='false'
5739N/A
5739N/A# keytab config file
5739N/Akt_config_file=
5739N/Anum_keytabs=0
5739N/Aset -A kt_transfer_command
5739N/A
5739N/Aldap_ds=
5739N/A
5739N/A# should be null if seting up master kdc
5739N/Amaster_kdc=
5739N/A
5739N/A# get the base script name
5739N/Ame=${0##*/}
5739N/A
5739N/Afunction usage {
5739N/A cat >&2 <<EOF
5739N/A
5739N/A -f: Force answer yes (non-interactive mode). Use with caution as
5739N/A this script will delete existing KDB.
5739N/A
5739N/A -?: This help message.
5739N/A
5739N/AEOF
5739N/A exit 1
5739N/A}
5739N/A
5739N/Afunction ask {
5739N/A trap - ERR
5739N/A # ask question, set global answer
5739N/A typeset question=$1 default_answer=$2
5739N/A if [ -z "$default_answer" ]; then
5739N/A print "$question \c"
5739N/A else
5739N/A print "$question [$default_answer]: \c"
5739N/A fi
5739N/A read answer
5739N/A [ -z "$answer" ] && answer="$default_answer"
5739N/A}
5739N/A
5739N/Afunction yesno {
5739N/A trap - ERR
5739N/A typeset question="$1"
5739N/A # answer is a global set by ask
5739N/A answer=
5739N/A while [ -z "$answer" ]; do
5739N/A ask "$question" 'n'
5739N/A case $answer in
5739N/A y|yes) answer=yes;;
5739N/A n|no) answer=no;;
5739N/A *) answer=;;
5739N/A esac
5739N/A done
5739N/A}
5739N/A
5739N/Afunction ok_to_proceed {
5739N/A trap - ERR
5739N/A yesno "$@"
5739N/A if [[ "$answer" == 'no' ]]; then
5739N/A echo "Exiting, no action performed"
5739N/A exit 1
5739N/A fi
5739N/A}
5739N/A
5739N/A
5739N/A################################ Start of Main script #########################
5739N/A
5739N/Awhile getopts f flag
5739N/Ado
5739N/A case "$flag" in
5739N/A f) force=true ;;
5739N/A \?) usage ;;
5739N/A *) usage ;;
5739N/A esac
5739N/Adone
5739N/Ashift $((OPTIND - 1))
5739N/A
5739N/Aif [ -n "$1" ] ; then
5739N/A echo "'$1'" = $1
5739N/A usage
5739N/Afi
5739N/A
5739N/Aif [[ -f .setup ]]
5739N/Athen
5739N/A print -u2 "Notice: $me alread run"
5739N/A exit 0
5739N/Afi
5739N/A
5739N/Aif [[ "$(/usr/bin/id -un)" != "root" ]]
5739N/Athen
5739N/A print -u2 "Error: $me must be run as root. aborting..."
5739N/A exit 1
5739N/Afi
5739N/A
5739N/A# Check for the testsuites we need
5739N/Aif [[ ! -e ./testsuite || ! -e $THIRTYTWO/testsuite ]]
5739N/Athen
5739N/A print -u2 \
5739N/A "Error: testsuite and $THIRTYTWO/testsuite must be in the local \
5739N/Adirectory, Aborting..."
5739N/A exit 1
5739N/Afi
5739N/Aln -s $THIRTYTWO 32
5739N/A
5739N/APACKAGES_NEEDED="service/security/kerberos-5 \
5739N/A system/security/kerberos-5 \
5739N/A system/library/security/sasl/crammd5 \
5739N/A system/library/security/sasl/digestmd5 \
5739N/A system/library/security/sasl/anonymous "
5739N/A
5739N/Apkg list $PACKAGES_NEEDED > /dev/null
5739N/Aif (( $? != 0 ))
5739N/Athen
5739N/A pkg install $PACKAGES_NEEDED
5739N/Afi
5739N/A
5739N/Apkg list $PACKAGES_NEEDED > /dev/null
5739N/Aif (( $? != 0 ))
5739N/Athen
5739N/A echo "One or more packages failed to install"
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Aexport MYLOC=`pwd`
5739N/Aif [[ ! -f /etc/sasl2/TestSuite.conf ]] ; then
5739N/A (cd /etc/sasl2 && ln -s $MYLOC/TestSuite.conf . )
5739N/Aelse
5739N/A print -u2 "Please rename /etc/sasl2/TestSuite.conf and try again"
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Aif [[ ! -f /etc/resolv.conf ]]
5739N/Athen
5739N/A print -u2 "Error: need to configure /etc/resolv.conf."
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Aif [[ -n "$fqdn" ]]
5739N/Athen
5739N/A host=$fqdn
5739N/Aelse
5739N/A host=$(uname -n)
5739N/Afi
5739N/A
5739N/Aif [[ -x /usr/sbin/nslookup ]]
5739N/Athen
5739N/A /usr/sbin/nslookup $host 2>/dev/null | grep '^Name:' |\
5739N/A tr '[:upper:]' '[:lower:]' | read j fqdn
5739N/Aelif [[ -x /usr/sbin/dig ]]
5739N/Athen
5739N/A /usr/sbin/dig +noall +search +answer $host 2>/dev/null |\
5739N/A tr '[:upper:]' '[:lower:]' | read fqdn j
5739N/A fqdn=${fqdn%.}
5739N/Afi
5739N/A
5739N/Aif ! ping $fqdn >/dev/null
5739N/Athen
5739N/A print -u2 "Error: ping full hostname ${fqdn} failed. Aborting..."
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Apasswd="1234"
5739N/A
5739N/Atrap "echo 'A command failed, aborting.'; exit 1" ERR
5739N/A
5739N/Asvcadm disable -s svc:/network/security/krb5kdc:default
5739N/Asvcadm disable -s svc:/network/security/kadmin:default
5739N/Asvcadm disable -s svc:/network/security/krb5_prop:default
5739N/A
5739N/Aif ! $force
5739N/Athen
5739N/A ok_to_proceed "Existing KDC config will be destroyed, okay to proceed?"
5739N/Afi
5739N/A
5739N/Atrap - ERR # in kdcmgr destroy fails, run it again
5739N/Ayes | /usr/sbin/kdcmgr destroy > /dev/null
5739N/Aif (( $? != 0 ))
5739N/Athen
5739N/A yes | /usr/sbin/kdcmgr destroy > /dev/null
5739N/Afi
5739N/Aprint "Existing KDC config destroyed."
5739N/Atrap "echo 'A command failed, aborting.'; exit 1" ERR
5739N/A
5739N/Apasswd_file=$(/usr/bin/mktemp /var/run/setup_kdc_passwd.XXXXXX)
5739N/A
5739N/Aprint $passwd > $passwd_file
5739N/A
5739N/A# create the master KDC
5739N/Aif [[ -n $master_kdc ]]
5739N/Athen
5739N/A /usr/sbin/kdcmgr -a $admin_princ -r $realm -p $passwd_file create -m $master_kdc slave
5739N/Aelse
5739N/A /usr/sbin/kdcmgr -a $admin_princ -r $realm -p $passwd_file create master
5739N/Afi
5739N/A
5739N/Arm -f $passwd_file
5739N/A
5739N/A# Optional stuff follows...
5739N/A
5739N/A# Note, this next section is adding various service principals local to
5739N/A# this system. If you have servers running on other systems, edit this
5739N/A# section to add the services using the FQDN hostnames of those systems
5739N/A# and ouput the keytab to a non-default filename.
5739N/A# You will then either copy the non-default filename created on the
5739N/A# system you ran this script on or login to the other system and do a
5739N/A# kadmin/ktadd to add the service principal to the /etc/krb5/krb5.keytab
5739N/A# located on that server.
5739N/A
5739N/A# addprincs if not in slave mode
5739N/Aif [[ -z $master_kdc ]]
5739N/Athen
5739N/A if [[ -n "$kt_config_file" ]]
5739N/A then
5739N/A if ! $force
5739N/A then
5739N/A ok_to_proceed "Existing keytab files will be modified, okay to proceed?"
5739N/A fi
5739N/A while read host services
5739N/A do
5739N/A if [[ "$host" == "#*" ]]
5739N/A then
5739N/A # skip comments
5739N/A continue
5739N/A fi
5739N/A if [[ "$host" != "localhost" ]]
5739N/A then
5739N/A hostkeytab="/var/run/${host}.keytab"
5739N/A rm -f $hostkeytab
5739N/A kt_transfer_command[num_keytabs]="scp $hostkeytab ${host}:/etc/krb5/krb5.keytab"
5739N/A fi
5739N/A for service in $services
5739N/A do
5739N/A if [[ "$host" == "localhost" ]]
5739N/A then
5739N/A # add service to KDC's keytab
5739N/A kadmin.local -q "addprinc -randkey $service/$fqdn"
5739N/A kadmin.local -q "ktadd $service/$fqdn"
5739N/A print "Added $service/$fqdn to /etc/krb5/krb5.keytab"
5739N/A else
5739N/A # add service to $host's keytab
5739N/A kadmin.local -q "addprinc -randkey $service/$host"
5739N/A kadmin.local -q "ktadd -k $hostkeytab $service/$host"
5739N/A print "\nAdded $service/$host to $hostkeytab"
5739N/A fi
5739N/A done
5739N/A ((num_keytabs = num_keytabs + 1))
5739N/A done < $kt_config_file
5739N/A fi
5739N/A
5739N/A if [[ -n "$crossrealm" ]]
5739N/A then
5739N/A # Setup Cross-realm auth.
5739N/A kadmin.local -q "addprinc -pw $passwd krbtgt/$realm@$crossrealm"
5739N/A kadmin.local -q "addprinc -pw $passwd krbtgt/$crossrealm@$realm"
5739N/A print "\n\nNote, /etc/krb5/krb5.conf will need to be modified to support crossrealm."
5739N/A fi
5739N/A
5739N/A # Optional, Add service principals on KDC
5739N/A for srv in nfs ldap smtp imap cifs
5739N/A do
5739N/A # randomizes the key anyway so use the -randkey option for addprinc).
5739N/A kadmin.local -q "addprinc -randkey $srv/$fqdn"
5739N/A kadmin.local -q "ktadd $srv/$fqdn"
5739N/A done
5739N/A
5739N/A
5739N/A # "tester" needed for setup
5739N/A kadmin.local -q "addprinc -pw $passwd tester"
5739N/A
5739N/A # "ken" needed for test
5739N/A echo "1234" | saslpasswd2 -c -p -f ./sasldb ken
5739N/A kadmin.local -q "addprinc -pw $passwd ken"
5739N/A
5739N/Afi # addprincs if not in slave mode
5739N/A
5739N/A# turn off err trap because svcadm below may return an unimportant error
5739N/Atrap "" ERR
5739N/A
5739N/Aif ! egrep '^[ ]*krb5[ ]+390003' /etc/nfssec.conf > /dev/null
5739N/Athen
5739N/A tmpnfssec=$(/usr/bin/mktemp /tmp/nfssec.conf_XXXXX)
5739N/A [[ -n $tmpnfssec ]] || exit 1
5739N/A sed -e 's/^ *# *krb5/krb5/g' /etc/nfssec.conf > $tmpnfssec
5739N/A mv -f $tmpnfssec /etc/nfssec.conf
5739N/A print 'Enabled krb5 sec in /etc/nfssec.conf.'
5739N/A print 'Copy /etc/nfssec.conf to all systems doing NFS sec=krb5*.'
5739N/A print
5739N/Afi
5739N/A
5739N/A# get time and DNS running
5739N/A
5739N/Aif [[ ! -f /etc/inet/ntp.conf && -f /etc/inet/ntp.client ]]
5739N/Athen
5739N/A cp /etc/inet/ntp.client /etc/inet/ntp.conf
5739N/Afi
5739N/Aif [[ -f /etc/inet/ntp.conf ]]
5739N/Athen
5739N/A svcadm enable -s svc:/network/ntp:default
5739N/Afi
5739N/A
5739N/A
5739N/Asvcadm enable svc:/network/security/ktkt_warn:default
5739N/A
5739N/Aif ! svcadm enable -s svc:/network/security/krb5kdc:default
5739N/Athen
5739N/A svcs -x svc:/network/security/krb5kdc:default
5739N/A cat <<-EOF
5739N/A
5739N/AError, the krb5kdc daemon did not start. You will not be able to do Kerberos
5739N/Aauthentication. Check your kerberos config and rerun this script.
5739N/A
5739N/A EOF
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Aif [[ -z $master_kdc ]] && ! svcadm enable -s svc:/network/security/kadmin:default
5739N/Athen
5739N/A svcs -x svc:/network/security/kadmin:default
5739N/A cat <<-EOF
5739N/A
5739N/AError, the kadmind daemon did not start. You will not be able to change
5739N/Apasswords or run the kadmin command. Make sure /etc/krb5/kadm5.acl is
5739N/Aconfigured properly and rerun this script.
5739N/A
5739N/A EOF
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Aif ! svcadm enable -s svc:/network/rpc/gss:default
5739N/Athen
5739N/A svcs -x svc:/network/rpc/gss:default
5739N/A cat <<-EOF
5739N/A
5739N/AError, the gss service did not start. You will not be able to do nfssec with sec=krb5*
5739N/A
5739N/A EOF
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Atmpccache=$(/usr/bin/mktemp /tmp/ccache_XXXXXX)
5739N/A[[ -n $tmpccache ]] || exit 1
5739N/Aif ! print "$passwd" | kinit -c $tmpccache tester
5739N/Athen
5739N/A print -u2 "Warning, kinit for tester princ failed, kdc setup is not working!"
5739N/A exit 1
5739N/Afi
5739N/A
5739N/Ainteger i=0
5739N/Awhile ((i < num_keytabs))
5739N/Ado
5739N/A if ((i == 0))
5739N/A then
5739N/A print "\nRun the following commands to transfer generated keytabs:"
5739N/A fi
5739N/A print ${kt_transfer_command[i]}
5739N/A ((i = i + 1))
5739N/Adone
5739N/A
5739N/Aprint 1234 | kinit ken
5739N/Atouch .setup