tst.unpriv_funcs.ksh revision 2870:a343ed00e23c
1238603Sjoerg#
2238603Sjoerg# CDDL HEADER START
3238603Sjoerg#
4238603Sjoerg# The contents of this file are subject to the terms of the
5238603Sjoerg# Common Development and Distribution License (the "License").
6238603Sjoerg# You may not use this file except in compliance with the License.
7238603Sjoerg#
8238603Sjoerg# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9238603Sjoerg# or http://www.opensolaris.org/os/licensing.
10238603Sjoerg# See the License for the specific language governing permissions
11238603Sjoerg# and limitations under the License.
12238603Sjoerg#
13238603Sjoerg# When distributing Covered Code, include this CDDL HEADER in each
14238603Sjoerg# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15238603Sjoerg# If applicable, add the following below this CDDL HEADER, with the
16238603Sjoerg# fields enclosed by brackets "[]" replaced with your own identifying
17238603Sjoerg# information: Portions Copyright [yyyy] [name of copyright owner]
18238603Sjoerg#
19238603Sjoerg# CDDL HEADER END
20238603Sjoerg#
21238603Sjoerg
22238603Sjoerg#
23238603Sjoerg# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24238603Sjoerg# Use is subject to license terms.
25238603Sjoerg#
26238603Sjoerg#ident	"%Z%%M%	%I%	%E% SMI"
27238603Sjoerg
28238603Sjoerg#
29238603Sjoerg# Affirmative test of less privileged user operation.  We do so by running
30238603Sjoerg# this test case as root, then as a less privileged user.  The output should
31238603Sjoerg# be exactly the same.
32238603Sjoerg#
33238603Sjoerg
34238603Sjoergscript()
35238603Sjoerg{
36238603Sjoerg	cat <<"EOF"
37238603Sjoerg
38238603Sjoerg	BEGIN { trace("trace\n"); }
39238603Sjoerg	BEGIN { printf("%s\n", "printf"); }
40238603Sjoerg	BEGIN { printf("strlen(\"strlen\") = %d\n", strlen("strlen")); }
41238603Sjoerg	BEGIN { x = alloca(10);
42238603Sjoerg		bcopy("alloca\n", x, 7);
43		trace(stringof(x)); }
44
45	BEGIN { printf("index(\"index\", \"x\") = %d\n",
46	    index("index", "x")); }
47	BEGIN { printf("strchr(\"strchr\", \'t\') = %s\n",
48	    strchr("strchr", 't')); }
49
50	BEGIN { printf("strtok(\"strtok\", \"t\") = %s\n",
51	    strtok("strtok", "t")); }
52	BEGIN { printf("strtok(NULL, \"t\") = %s\n",
53	    strtok(NULL, "t")); }
54	BEGIN { printf("strtok(NULL, \"t\") = %s\n",
55	    strtok(NULL, "t")); }
56	BEGIN { printf("substr(\"substr\", 2, 2) = %s\n",
57	    substr("substr", 2, 2)); }
58	BEGIN { trace(strjoin("str", "join\n")); }
59	BEGIN { trace(basename("dirname/basename")); trace("/"); }
60	BEGIN { trace(dirname("dirname/basename")); }
61
62	BEGIN { exit(0); }
63	ERROR { exit(1); }
64EOF
65}
66
67privout=/tmp/$$.priv_output
68unprivout=/tmp/$$.unpriv_output
69
70script | /usr/sbin/dtrace -q -s /dev/stdin > $privout
71ppriv -s A=basic,dtrace_user $$
72script | /usr/sbin/dtrace -q -s /dev/stdin > $unprivout
73
74diff $privout $unprivout
75res=$?
76
77/bin/rm -f $privout $unprivout
78
79exit $res
80