1*b30d1939SAndy Fiddaman# 2*b30d1939SAndy Fiddaman# CDDL HEADER START 3*b30d1939SAndy Fiddaman# 4*b30d1939SAndy Fiddaman# The contents of this file are subject to the terms of the 5*b30d1939SAndy Fiddaman# Common Development and Distribution License (the "License"). 6*b30d1939SAndy Fiddaman# You may not use this file except in compliance with the License. 7*b30d1939SAndy Fiddaman# 8*b30d1939SAndy Fiddaman# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*b30d1939SAndy Fiddaman# or http://www.opensolaris.org/os/licensing. 10*b30d1939SAndy Fiddaman# See the License for the specific language governing permissions 11*b30d1939SAndy Fiddaman# and limitations under the License. 12*b30d1939SAndy Fiddaman# 13*b30d1939SAndy Fiddaman# When distributing Covered Code, include this CDDL HEADER in each 14*b30d1939SAndy Fiddaman# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*b30d1939SAndy Fiddaman# If applicable, add the following below this CDDL HEADER, with the 16*b30d1939SAndy Fiddaman# fields enclosed by brackets "[]" replaced with your own identifying 17*b30d1939SAndy Fiddaman# information: Portions Copyright [yyyy] [name of copyright owner] 18*b30d1939SAndy Fiddaman# 19*b30d1939SAndy Fiddaman# CDDL HEADER END 20*b30d1939SAndy Fiddaman# 21*b30d1939SAndy Fiddaman 22*b30d1939SAndy Fiddaman# 23*b30d1939SAndy Fiddaman# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 24*b30d1939SAndy Fiddaman# 25*b30d1939SAndy Fiddaman 26*b30d1939SAndy Fiddaman# 27*b30d1939SAndy Fiddaman# This test checks whether ksh93 does unneccesaty |libc::getpwnam()| 28*b30d1939SAndy Fiddaman# calls for "~(modifer)pattern"-style shell patterns 29*b30d1939SAndy Fiddaman# 30*b30d1939SAndy Fiddaman# This was reported as CR #6807179 ("ksh93 does unneccesary |libc::getpwnam()| lookups for ~(modifier) pattern patterns"): 31*b30d1939SAndy Fiddaman# ------------ snip ------------ 32*b30d1939SAndy Fiddaman# ksh93 does unneccesary |libc::getpwnam()| lookups for 33*b30d1939SAndy Fiddaman# ~(modifer)pattern patterns, e.g. [[ $foo == ~(E)hello.*world ]]. 34*b30d1939SAndy Fiddaman# The problem is that the shell ~(modifer)pattern is an extended 35*b30d1939SAndy Fiddaman# pattern syntax which allows to specify a "modifer" to change 36*b30d1939SAndy Fiddaman# the behaviour for "pattern". However the '~' at the beginning 37*b30d1939SAndy Fiddaman# of this string is causing a tilde expansion (or better: It's 38*b30d1939SAndy Fiddaman# filling an internal buffer as preparation for tilde expansion 39*b30d1939SAndy Fiddaman# and this code calls |libc::getpwnam()|) which shouldn't be 40*b30d1939SAndy Fiddaman# done in this case. 41*b30d1939SAndy Fiddaman# [1]=For example the "modifer" allows to specifcy "perl", 42*b30d1939SAndy Fiddaman# "fgrep", "grep", "egrep", "POSIX shell", "korn shell" and 43*b30d1939SAndy Fiddaman# other types of pattern matching systems (or select stuff 44*b30d1939SAndy Fiddaman# like archors, case-insensitive matching etc. etc.). 45*b30d1939SAndy Fiddaman# ------------ snip ------------ 46*b30d1939SAndy Fiddaman# 47*b30d1939SAndy Fiddaman 48*b30d1939SAndy Fiddaman# test setup 49*b30d1939SAndy Fiddamanfunction err_exit 50*b30d1939SAndy Fiddaman{ 51*b30d1939SAndy Fiddaman print -u2 -n "\t" 52*b30d1939SAndy Fiddaman print -u2 -r ${Command}[$1]: "${@:2}" 53*b30d1939SAndy Fiddaman (( Errors < 127 && Errors++ )) 54*b30d1939SAndy Fiddaman} 55*b30d1939SAndy Fiddamanalias err_exit='err_exit $LINENO' 56*b30d1939SAndy Fiddaman 57*b30d1939SAndy Fiddamanset -o nounset 58*b30d1939SAndy FiddamanCommand=${0##*/} 59*b30d1939SAndy Fiddamaninteger Errors=0 60*b30d1939SAndy Fiddaman 61*b30d1939SAndy Fiddamantypeset tmpfile 62*b30d1939SAndy Fiddaman 63*b30d1939SAndy Fiddamantmpfile="$(mktemp -t "sun_solaris_cr_6807179_shellpattern_uses_getpwnam.${PPID}.$$.XXXXXX")" || err_exit "Cannot create temporary file." 64*b30d1939SAndy Fiddamanrm -f "${tmpfile}" 65*b30d1939SAndy Fiddaman 66*b30d1939SAndy Fiddaman 67*b30d1939SAndy Fiddaman# test 1: Check if the shell uses |libc::getpwnam()| for pattern "~(Elr)wo.*ld" 68*b30d1939SAndy Fiddamantruss -u :: -o "${tmpfile}" ${SHELL} -c '[[ ${hello} == ~(Elr)wo.*ld ]] ; true' || err_exit "truss returned failure=$?" 69*b30d1939SAndy Fiddaman[[ "$( < "${tmpfile}")" != *getpwnam* ]] || err_exit "truss log reports the use of getpwnam() for pattern ~(Elr)wo.*ld" 70*b30d1939SAndy Fiddamanrm "${tmpfile}" || err_exit "rm ${tmpfile} failed." 71*b30d1939SAndy Fiddaman 72*b30d1939SAndy Fiddaman 73*b30d1939SAndy Fiddaman# test 2: Check if the shell uses |libc::getpwnam()| for pattern "~(Si)wo*ld" 74*b30d1939SAndy Fiddamantruss -u :: -o "${tmpfile}" ${SHELL} -c '[[ ${hello} == ~(Si)wo*ld ]] ; true' || err_exit "truss returned failure=$?" 75*b30d1939SAndy Fiddaman[[ "$( < "${tmpfile}")" != *getpwnam* ]] || err_exit "truss log reports the use of getpwnam() for pattern ~(Si)wo*ld" 76*b30d1939SAndy Fiddamanrm "${tmpfile}" || err_exit "rm ${tmpfile} failed." 77*b30d1939SAndy Fiddaman 78*b30d1939SAndy Fiddaman 79*b30d1939SAndy Fiddaman# test 3: Same as test 1 but uses ~root/ as pattern which will force the use of |libc::getpwnam()| 80*b30d1939SAndy Fiddamangetent passwd root >/dev/null || err_exit "getent passwd root failed" # safeguard to make sure we get a warning if user root is missing 81*b30d1939SAndy Fiddaman 82*b30d1939SAndy Fiddamantruss -u :: -o "${tmpfile}" ${SHELL} -c '[[ ${hello} == ~root/ ]] ; true' || err_exit "truss returned failure=$?" 83*b30d1939SAndy Fiddaman[[ "$( < "${tmpfile}" )" == *getpwnam* ]] || err_exit "truss log reports the use of getpwnam() for pattern ~root/" 84*b30d1939SAndy Fiddamanrm "${tmpfile}" || err_exit "rm ${tmpfile} failed." 85*b30d1939SAndy Fiddaman 86*b30d1939SAndy Fiddaman 87*b30d1939SAndy Fiddaman# tests done 88*b30d1939SAndy Fiddamanexit $((Errors)) 89