1*e0895134Schristos#!/bin/sh 2*e0895134Schristos# 3*e0895134Schristos# Copyright (c) 2007 Kungliga Tekniska Högskolan 4*e0895134Schristos# (Royal Institute of Technology, Stockholm, Sweden). 5*e0895134Schristos# All rights reserved. 6*e0895134Schristos# 7*e0895134Schristos# Redistribution and use in source and binary forms, with or without 8*e0895134Schristos# modification, are permitted provided that the following conditions 9*e0895134Schristos# are met: 10*e0895134Schristos# 11*e0895134Schristos# 1. Redistributions of source code must retain the above copyright 12*e0895134Schristos# notice, this list of conditions and the following disclaimer. 13*e0895134Schristos# 14*e0895134Schristos# 2. Redistributions in binary form must reproduce the above copyright 15*e0895134Schristos# notice, this list of conditions and the following disclaimer in the 16*e0895134Schristos# documentation and/or other materials provided with the distribution. 17*e0895134Schristos# 18*e0895134Schristos# 3. Neither the name of the Institute nor the names of its contributors 19*e0895134Schristos# may be used to endorse or promote products derived from this software 20*e0895134Schristos# without specific prior written permission. 21*e0895134Schristos# 22*e0895134Schristos# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23*e0895134Schristos# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*e0895134Schristos# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*e0895134Schristos# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26*e0895134Schristos# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*e0895134Schristos# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*e0895134Schristos# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*e0895134Schristos# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*e0895134Schristos# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*e0895134Schristos# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*e0895134Schristos# SUCH DAMAGE. 33*e0895134Schristos 34*e0895134Schristostop_builddir="@top_builddir@" 35*e0895134Schristosenv_setup="@env_setup@" 36*e0895134Schristosobjdir="." 37*e0895134Schristos 38*e0895134Schristos. ${env_setup} 39*e0895134Schristos 40*e0895134Schristossrcdir="${top_srcdir}/tests/kdc" 41*e0895134Schristostest_alname="${test_alname} --simple" 42*e0895134Schristos 43*e0895134Schristosrm -f localname 44*e0895134Schristos 45*e0895134Schristoscheck_localname() { 46*e0895134Schristos stderr= 47*e0895134Schristos if test "$2" -ne 0; then 48*e0895134Schristos stderr="2>/dev/null" 49*e0895134Schristos fi 50*e0895134Schristos eval ${test_alname} "'$1'" > localname $stderr 51*e0895134Schristos status=$? 52*e0895134Schristos if test $status -ne "$2"; then 53*e0895134Schristos echo "Unexpected exit code from test_alname $1: $status" 54*e0895134Schristos exit 1 55*e0895134Schristos fi 56*e0895134Schristos if test $status -ne 0; then 57*e0895134Schristos return 0 58*e0895134Schristos fi 59*e0895134Schristos read lname < localname 60*e0895134Schristos if test "X$lname" != "X$3"; then 61*e0895134Schristos echo "Unexpected mapping of $1: $lname" 62*e0895134Schristos exit 1 63*e0895134Schristos fi 64*e0895134Schristos return 0 65*e0895134Schristos} 66*e0895134Schristos 67*e0895134SchristosR=TEST.H5L.SE 68*e0895134SchristosR2=TEST2.H5L.SE 69*e0895134SchristosR3=TEST3.H5L.SE 70*e0895134SchristosR4=TEST4.H5L.SE 71*e0895134Schristos 72*e0895134SchristosKRB5_CONFIG="${objdir}/krb5-authz.conf" 73*e0895134Schristosexport KRB5_CONFIG 74*e0895134Schristos 75*e0895134Schristosecho "Checking 1-component principal names in default realms" 76*e0895134Schristoscheck_localname mapped1@${R} 0 foo || exit 1 77*e0895134Schristoscheck_localname mapped2@${R} 0 bar || exit 1 78*e0895134Schristoscheck_localname mapped1@${R2} 0 m1 || exit 1 79*e0895134Schristoscheck_localname mapped2@${R2} 0 m2 || exit 1 80*e0895134Schristoscheck_localname mapped1@${R3} 0 mapped1 || exit 1 81*e0895134Schristoscheck_localname mapped2@${R3} 0 mapped2 || exit 1 82*e0895134Schristoscheck_localname notmapped1@${R} 0 notmapped1 || exit 1 83*e0895134Schristoscheck_localname notmapped1@${R2} 0 notmapped1 || exit 1 84*e0895134Schristoscheck_localname notmapped1@${R3} 0 notmapped1 || exit 1 85*e0895134Schristos 86*e0895134Schristosecho "Checking 1-component principal names in non-default realm" 87*e0895134Schristoscheck_localname mapped1@${R4} 1 || exit 1 88*e0895134Schristoscheck_localname notmapped1@${R4} 1 || exit 1 89*e0895134Schristos 90*e0895134Schristosecho "Checking 2-component principal names" 91*e0895134Schristoscheck_localname foo/mapped1@${R} 0 foo || exit 1 92*e0895134Schristoscheck_localname foo/mapped2@${R} 0 bar || exit 1 93*e0895134Schristoscheck_localname bar/mapped1@${R2} 0 foobar || exit 1 94*e0895134Schristoscheck_localname bar/mapped2@${R2} 0 foobaz || exit 1 95*e0895134Schristoscheck_localname foo/mapped1@${R3} 1 || exit 1 96*e0895134Schristoscheck_localname bar/mapped1@${R3} 1 || exit 1 97*e0895134Schristoscheck_localname foo/notmapped1@${R} 1 || exit 1 98*e0895134Schristoscheck_localname bar/notmapped1@${R2} 1 || exit 1 99*e0895134Schristos 100*e0895134Schristosecho "Checking 2-component principal names in non-default realm" 101*e0895134Schristoscheck_localname foo/mapped1@${R4} 1 || exit 1 102*e0895134Schristoscheck_localname bar/mapped1@${R4} 1 || exit 1 103*e0895134Schristoscheck_localname foo/notmapped1@${R4} 1 || exit 1 104*e0895134Schristoscheck_localname bar/notmapped1@${R4} 1 || exit 1 105*e0895134Schristos 106*e0895134Schristosecho "Checking for overflow" 107*e0895134Schristostest_alname="${test_alname} --simple --lname-size=1" 108*e0895134Schristoscheck_localname mapped1@${R} 3 || exit 1 109*e0895134Schristoscheck_localname mapped2@${R} 3 || exit 1 110*e0895134Schristoscheck_localname mapped1@${R2} 3 || exit 1 111*e0895134Schristoscheck_localname mapped2@${R2} 3 || exit 1 112*e0895134Schristoscheck_localname mapped1@${R3} 3 || exit 1 113*e0895134Schristoscheck_localname mapped2@${R3} 3 || exit 1 114*e0895134Schristos 115*e0895134Schristosecho "Checking krb5_kuserok()" 116*e0895134Schristos${test_kuserok} random-princ@RANDOM-REALM foo > /dev/null || exit 1 117*e0895134Schristos${test_kuserok} mapped1@${R} foo > /dev/null || exit 1 118*e0895134Schristos${test_kuserok} mapped1@${R2} m1 > /dev/null || exit 1 119*e0895134Schristos${test_kuserok} notmapped1@${R3} notmapped1 > /dev/null || exit 1 120*e0895134Schristos${test_kuserok} this-better-not-exist@NOR-THIS foo > /dev/null && exit 1 121*e0895134Schristos 122*e0895134Schristos# If the user running this test has a ~/.k5login or .k5logind, test 123*e0895134Schristos# based on their content 124*e0895134Schristosif test -n "${HOME}" -a -n "${USER:-${LOGNAME}}" -a -s "${HOME}/.k5login"; then 125*e0895134Schristos echo "Checking ~/.k5login" 126*e0895134Schristos while read princ; do 127*e0895134Schristos ${test_kuserok} "${princ}" "${USER:-${LOGNAME}}" > /dev/null || exit 1 128*e0895134Schristos done < "${HOME}/.k5login" || exit 1 129*e0895134Schristosfi 130*e0895134Schristosif test -n "${HOME}" -a -n "${USER:-${LOGNAME}}" -a -d "${HOME}/.k5login.d"; then 131*e0895134Schristos echo "Checking ~/.k5login.d" 132*e0895134Schristos ls -f "${HOME}/.k5login.d" | egrep -v '^(\.|\.\.|#.*|.*~|\.*.sw.)$' | while read f; do 133*e0895134Schristos f="${HOME}/.k5login.d/$f" 134*e0895134Schristos test -d "${f}" && continue 135*e0895134Schristos while read princ; do 136*e0895134Schristos ${test_kuserok} "${princ}" "${USER:-${LOGNAME}}" > /dev/null || exit 1 137*e0895134Schristos done < "${f}" || exit 1 138*e0895134Schristos done || exit 1 139*e0895134Schristosfi 140*e0895134Schristos 141*e0895134SchristosKRB5_CONFIG="${objdir}/krb5-authz2.conf" 142*e0895134Schristosexport KRB5_CONFIG 143*e0895134Schristos 144*e0895134Schristosecho "Checking krb5_kuserok() (with authoritative k5login files)" 145*e0895134Schristos${test_kuserok} random-princ@RANDOM-REALM foo > /dev/null || exit 1 146*e0895134Schristos${test_kuserok} mapped1@${R} foo > /dev/null && exit 1 147*e0895134Schristos${test_kuserok} mapped1@${R2} m1 > /dev/null || exit 1 148*e0895134Schristos${test_kuserok} notmapped1@${R3} notmapped1 > /dev/null || exit 1 149*e0895134Schristos${test_kuserok} this-better-not-exist@NOR-THIS foo > /dev/null && exit 1 150*e0895134Schristos 151*e0895134Schristosrm -f messages.log 152*e0895134Schristos 153*e0895134Schristosexit 0 154