xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/privs/tst.getf.ksh (revision 1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9f)
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 (c) 2012, Joyent, Inc. All rights reserved.
24#
25
26ppriv -s A=basic,dtrace_proc,dtrace_user $$
27
28/usr/sbin/dtrace -q -Cs /dev/stdin <<EOF
29
30#define CANREAD(field) \
31	BEGIN { this->fp = getf(0); errmsg = "can't read field"; \
32	    printf("field: "); trace(this->fp->field); printf("\n"); }
33
34#define CANTREAD(field) \
35	BEGIN { errmsg = ""; this->fp = getf(0); trace(this->fp->field); \
36	    printf("\nable to successfully read field!"); exit(1); }
37
38CANREAD(f_flag)
39CANREAD(f_flag2)
40CANREAD(f_vnode)
41CANREAD(f_offset)
42CANREAD(f_cred)
43CANREAD(f_audit_data)
44CANREAD(f_count)
45
46/*
47 * We can potentially read parts of our cred, but we can't dereference
48 * through cr_zone.
49 */
50CANTREAD(f_cred->cr_zone->zone_id)
51
52CANREAD(f_vnode->v_path)
53CANREAD(f_vnode->v_op)
54CANREAD(f_vnode->v_op->vnop_name)
55
56CANTREAD(f_vnode->v_flag)
57CANTREAD(f_vnode->v_count)
58CANTREAD(f_vnode->v_pages)
59CANTREAD(f_vnode->v_type)
60CANTREAD(f_vnode->v_vfsmountedhere)
61CANTREAD(f_vnode->v_op->vop_open)
62
63BEGIN
64{
65	errmsg = "";
66	this->fp = getf(0);
67	this->fp2 = getf(1);
68
69	trace(this->fp->f_vnode);
70	printf("\nable to successfully read this->fp!");
71	exit(1);
72}
73
74BEGIN
75{
76	errmsg = "";
77	this->fp = getf(0);
78}
79
80BEGIN
81{
82	trace(this->fp->f_vnode);
83	printf("\nable to successfully read this->fp from prior clause!");
84}
85
86BEGIN
87{
88	exit(0);
89}
90
91ERROR
92/errmsg != ""/
93{
94	printf("fatal error: %s", errmsg);
95	exit(1);
96}
97	
98EOF
99