tst.egid.ksh revision 23b5c241225a8ade2b6b9f06ebb891ee459e3b02
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#!/bin/ksh -p
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# CDDL HEADER START
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# The contents of this file are subject to the terms of the
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# Common Development and Distribution License (the "License").
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# You may not use this file except in compliance with the License.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# or http://www.opensolaris.org/os/licensing.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# See the License for the specific language governing permissions
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# and limitations under the License.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# When distributing Covered Code, include this CDDL HEADER in each
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# If applicable, add the following below this CDDL HEADER, with the
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# fields enclosed by brackets "[]" replaced with your own identifying
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# information: Portions Copyright [yyyy] [name of copyright owner]
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# CDDL HEADER END
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
888e055994b8b0dc77b98c53dd97026237caec5dRobert Johnston#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# Use is subject to license terms.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#ident "%Z%%M% %I% %E% SMI"
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows############################################################################
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# ASSERTION:
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# To verify egid of current process
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
888e055994b8b0dc77b98c53dd97026237caec5dRobert Johnston#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows# SECTION: Scripting
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows############################################################################
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsif [ $# != 1 ]; then
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows echo expected one argument: '<'dtrace-path'>'
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows exit 2
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsfi
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsdtrace=$1
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsbname=`/bin/basename $0`
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsdfilename=/var/tmp/$bname.$$.d
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows## Create .d file
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows##########################################################################
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowscat > $dfilename <<-EOF
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows#!$dtrace -qs
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsBEGIN
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows/\$egid != \$1/
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows{
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows exit(1);
}
BEGIN
/\$egid == \$1/
{
exit(0);
}
EOF
##########################################################################
#chmod 555 the .d file
chmod 555 $dfilename >/dev/null 2>&1
if [ &? -ne 0 ]; then
print -u2 "chmod $dfilename failed"
exit 1
fi
#Get the groupid of the calling process using ps
groupid=`ps -o pid,gid | grep "$$ " | awk '{print $2}' 2>/dev/null`
if [ $? -ne 0 ]; then
print -u2 "unable to get uid of the current process with pid = $$"
exit 1
fi
#Pass groupid as argument to .d file
$dfilename $groupid >/dev/null 2>&1
if [ $? -ne 0 ]; then
print -u2 "Error in executing $dfilename"
exit 1
fi
#Cleanup leftovers
/usr/bin/rm -f $dfilename
exit 0