1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27
28#
29# Affirmative test of less privileged user operation.  We do so by running
30# this test case as root, then as a less privileged user.  The output should
31# be exactly the same.
32#
33
34script()
35{
36	cat <<"EOF"
37
38	BEGIN { trace("trace\n"); }
39	BEGIN { printf("%s\n", "printf"); }
40	BEGIN { printf("strlen(\"strlen\") = %d\n", strlen("strlen")); }
41	BEGIN { x = alloca(10);
42		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