Debian Codegraph @

libselinux/man/man3/avc_has_perm.3

raw
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Author: Eamon Walsh ([email protected]) 2004
4 .TH "avc_has_perm" "3" "27 May 2004" "" "SELinux API documentation"
5 .SH "NAME"
6 avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \- obtain and audit SELinux access decisions
7 .
8 .SH "SYNOPSIS"
9 .B #include <selinux/selinux.h>
10 .br
11 .B #include <selinux/avc.h>
12 .sp
13 .BI "void avc_entry_ref_init(struct avc_entry_ref *" aeref ");"
14 .sp
15 .BI "int avc_has_perm(security_id_t " ssid ", security_id_t " tsid ,
16 .in +\w'int avc_has_perm('u
17 .BI "security_class_t " tclass ", access_vector_t " requested ,
18 .br
19 .BI "struct avc_entry_ref *" aeref ", void *" auditdata ");"
20 .in
21 .sp
22 .BI "int avc_has_perm_noaudit(security_id_t " ssid ", security_id_t " tsid ,
23 .in +\w'int avc_has_perm('u
24 .BI "security_class_t " tclass ", access_vector_t " requested ,
25 .br
26 .BI "struct avc_entry_ref *" aeref ", struct av_decision *" avd ");"
27 .in
28 .sp
29 .BI "void avc_audit(security_id_t " ssid ", security_id_t " tsid ,
30 .in +\w'void avc_audit('u
31 .BI "security_class_t " tclass ", access_vector_t " requested ,
32 .br
33 .BI "struct av_decision *" avd ", int " result ", void *" auditdata ");"
34 .in
35 .
36 .SH "DESCRIPTION"
37 .BR avc_entry_ref_init ()
38 initializes an
39 .B avc_entry_ref
40 structure; see
41 .B ENTRY REFERENCES
42 below. This function may be implemented as a macro.
43
44 .BR avc_has_perm ()
45 checks whether the
46 .I requested
47 permissions are granted
48 for subject SID
49 .IR ssid
50 and target SID
51 .IR tsid ,
52 interpreting the permissions
53 based on
54 .I tclass
55 and updating
56 .IR aeref ,
57 if non-NULL, to refer to a cache entry with the resulting decision. The granting or denial of permissions is audited in accordance with the policy. The
58 .I auditdata
59 parameter is for supplemental auditing; see
60 .BR avc_audit ()
61 below.
62
63 .BR avc_has_perm_noaudit ()
64 behaves as
65 .BR avc_has_perm ()
66 without producing an audit message. The access decision is returned in
67 .I avd
68 and can be passed to
69 .BR avc_audit ()
70 explicitly.
71
72 .BR avc_audit ()
73 produces an audit message for the access query represented by
74 .IR ssid ,
75 .IR tsid ,
76 .IR tclass ,
77 and
78 .IR requested ,
79 with a decision represented by
80 .IR avd .
81 Pass the value returned by
82 .BR avc_has_perm_noaudit ()
83 as
84 .IR result .
85 The
86 .I auditdata
87 parameter is passed to the user-supplied
88 .B func_audit
89 callback and can be used to add supplemental information to the audit message; see
90 .BR avc_init (3).
91 .
92 .SH "ENTRY REFERENCES"
93 Entry references can be used to speed cache performance for repeated queries on the same subject and target. The userspace AVC will check the
94 .I aeref
95 argument, if supplied, before searching the cache on a permission query. After a query is performed,
96 .I aeref
97 will be updated to reference the cache entry for that query. A subsequent query on the same subject and target will then have the decision at hand without having to walk the cache.
98
99 After declaring an
100 .B avc_entry_ref
101 structure, use
102 .BR avc_entry_ref_init ()
103 to initialize it before passing it to
104 .BR avc_has_perm ()
105 or
106 .BR \%avc_has_perm_noaudit ()
107 for the first time.
108 Using an uninitialized structure will produce undefined behavior.
109 .
110 .SH "RETURN VALUE"
111 If requested permissions are granted, zero is returned. If requested permissions are denied or an error occurred, \-1 is returned and
112 .I errno
113 is set appropriately.
114
115 In permissive mode, zero will be returned and
116 .I errno
117 unchanged even if permissions were denied.
118 .BR avc_has_perm ()
119 will still produce an audit message in this case.
120 .
121 .SH "ERRORS"
122 .TP
123 .B EACCES
124 A requested permission was denied.
125 .TP
126 .B EINVAL
127 The
128 .I tclass
129 and/or the security contexts referenced by
130 .I ssid
131 and
132 .I tsid
133 are not recognized by the currently loaded policy.
134 .TP
135 .B ENOMEM
136 An attempt to allocate memory failed.
137 .
138 .SH "NOTES"
139 Internal errors encountered by the userspace AVC may cause certain values of
140 .I errno
141 to be returned unexpectedly. For example, netlink socket errors may produce
142 .B EACCES
143 or
144 .BR EINVAL .
145 Make sure that userspace object managers are granted appropriate access to
146 netlink by the policy.
147 .
148 .SH "AUTHOR"
149 Eamon Walsh <[email protected]>
150 .
151 .SH "SEE ALSO"
152 .ad l
153 .nh
154 .BR avc_init (3),
155 .BR avc_context_to_sid (3),
156 .BR avc_cache_stats (3),
157 .BR avc_add_callback (3),
158 .BR security_compute_av (3),
159 .BR selinux (8)