]>
Commit | Line | Data |
---|---|---|
1 | /*- | |
2 | * Copyright (c) 2008-2019 Apple Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of | |
13 | * its contributors may be used to endorse or promote products derived | |
14 | * from this software without specific prior written permission. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND | |
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR | |
20 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
24 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
25 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | * | |
28 | */ | |
29 | ||
30 | #include <sys/param.h> | |
31 | ||
32 | #include <security/audit/audit.h> | |
33 | ||
34 | #include <bsm/audit_errno.h> | |
35 | #include <bsm/audit_record.h> | |
36 | ||
37 | #include <sys/errno.h> | |
38 | ||
39 | #if CONFIG_AUDIT | |
40 | /* | |
41 | * Different operating systems use different numeric constants for different | |
42 | * error numbers, and sometimes error numbers don't exist in more than one | |
43 | * operating system. These routines convert between BSM and local error | |
44 | * number spaces, subject to the above realities. BSM error numbers are | |
45 | * stored in a single 8-bit character, so don't have a byte order. | |
46 | * | |
47 | * Don't include string definitions when this code is compiled into a kernel. | |
48 | */ | |
49 | struct bsm_errno { | |
50 | int be_bsm_errno; | |
51 | int be_local_errno; | |
52 | #if !defined(KERNEL) && !defined(_KERNEL) | |
53 | const char *be_strerror; | |
54 | #endif | |
55 | }; | |
56 | ||
57 | #define ERRNO_NO_LOCAL_MAPPING -600 | |
58 | ||
59 | #if !defined(KERNEL) && !defined(_KERNEL) | |
60 | #define ES(x) .be_strerror = x | |
61 | #else | |
62 | #define ES(x) | |
63 | #endif | |
64 | ||
65 | /* | |
66 | * Mapping table -- please maintain in numeric sorted order with respect to | |
67 | * the BSM constant. Today we do a linear lookup, but could switch to a | |
68 | * binary search if it makes sense. We only ifdef errors that aren't | |
69 | * generally available, but it does make the table a lot more ugly. | |
70 | * | |
71 | * XXXRW: It would be nice to have a similar ordered table mapping to BSM | |
72 | * constant from local constant, but the order of local constants varies by | |
73 | * OS. Really we need to build that table at compile-time but don't do that | |
74 | * yet. | |
75 | * | |
76 | * XXXRW: We currently embed English-language error strings here, but should | |
77 | * support catalogues; these are only used if the OS doesn't have an error | |
78 | * string using strerror(3). | |
79 | */ | |
80 | static const struct bsm_errno bsm_errnos[] = { | |
81 | { .be_bsm_errno = BSM_ERRNO_ESUCCESS, .be_local_errno = 0, ES("Success") }, | |
82 | { .be_bsm_errno = BSM_ERRNO_EPERM, .be_local_errno = EPERM, ES("Operation not permitted") }, | |
83 | { .be_bsm_errno = BSM_ERRNO_ENOENT, .be_local_errno = ENOENT, ES("No such file or directory") }, | |
84 | { .be_bsm_errno = BSM_ERRNO_ESRCH, .be_local_errno = ESRCH, ES("No such process") }, | |
85 | { .be_bsm_errno = BSM_ERRNO_EINTR, .be_local_errno = EINTR, ES("Interrupted system call") }, | |
86 | { .be_bsm_errno = BSM_ERRNO_EIO, .be_local_errno = EIO, ES("Input/output error") }, | |
87 | { .be_bsm_errno = BSM_ERRNO_ENXIO, .be_local_errno = ENXIO, ES("Device not configured") }, | |
88 | { .be_bsm_errno = BSM_ERRNO_E2BIG, .be_local_errno = E2BIG, ES("Argument list too long") }, | |
89 | { .be_bsm_errno = BSM_ERRNO_ENOEXEC, .be_local_errno = ENOEXEC, ES("Exec format error") }, | |
90 | { .be_bsm_errno = BSM_ERRNO_EBADF, .be_local_errno = EBADF, ES("Bad file descriptor") }, | |
91 | { .be_bsm_errno = BSM_ERRNO_ECHILD, .be_local_errno = ECHILD, ES("No child processes") }, | |
92 | { .be_bsm_errno = BSM_ERRNO_EAGAIN, .be_local_errno = EAGAIN, ES("Resource temporarily unavailable") }, | |
93 | { .be_bsm_errno = BSM_ERRNO_ENOMEM, .be_local_errno = ENOMEM, ES("Cannot allocate memory") }, | |
94 | { .be_bsm_errno = BSM_ERRNO_EACCES, .be_local_errno = EACCES, ES("Permission denied") }, | |
95 | { .be_bsm_errno = BSM_ERRNO_EFAULT, .be_local_errno = EFAULT, ES("Bad address") }, | |
96 | { .be_bsm_errno = BSM_ERRNO_ENOTBLK, .be_local_errno = ENOTBLK, ES("Block device required") }, | |
97 | { .be_bsm_errno = BSM_ERRNO_EBUSY, .be_local_errno = EBUSY, ES("Device busy") }, | |
98 | { .be_bsm_errno = BSM_ERRNO_EEXIST, .be_local_errno = EEXIST, ES("File exists") }, | |
99 | { .be_bsm_errno = BSM_ERRNO_EXDEV, .be_local_errno = EXDEV, ES("Cross-device link") }, | |
100 | { .be_bsm_errno = BSM_ERRNO_ENODEV, .be_local_errno = ENODEV, ES("Operation not supported by device") }, | |
101 | { .be_bsm_errno = BSM_ERRNO_ENOTDIR, .be_local_errno = ENOTDIR, ES("Not a directory") }, | |
102 | { .be_bsm_errno = BSM_ERRNO_EISDIR, .be_local_errno = EISDIR, ES("Is a directory") }, | |
103 | { .be_bsm_errno = BSM_ERRNO_EINVAL, .be_local_errno = EINVAL, ES("Invalid argument") }, | |
104 | { .be_bsm_errno = BSM_ERRNO_ENFILE, .be_local_errno = ENFILE, ES("Too many open files in system") }, | |
105 | { .be_bsm_errno = BSM_ERRNO_EMFILE, .be_local_errno = EMFILE, ES("Too many open files") }, | |
106 | { .be_bsm_errno = BSM_ERRNO_ENOTTY, .be_local_errno = ENOTTY, ES("Inappropriate ioctl for device") }, | |
107 | { .be_bsm_errno = BSM_ERRNO_ETXTBSY, .be_local_errno = ETXTBSY, ES("Text file busy") }, | |
108 | { .be_bsm_errno = BSM_ERRNO_EFBIG, .be_local_errno = EFBIG, ES("File too large") }, | |
109 | { .be_bsm_errno = BSM_ERRNO_ENOSPC, .be_local_errno = ENOSPC, ES("No space left on device") }, | |
110 | { .be_bsm_errno = BSM_ERRNO_ESPIPE, .be_local_errno = ESPIPE, ES("Illegal seek") }, | |
111 | { .be_bsm_errno = BSM_ERRNO_EROFS, .be_local_errno = EROFS, ES("Read-only file system") }, | |
112 | { .be_bsm_errno = BSM_ERRNO_EMLINK, .be_local_errno = EMLINK, ES("Too many links") }, | |
113 | { .be_bsm_errno = BSM_ERRNO_EPIPE, .be_local_errno = EPIPE, ES("Broken pipe") }, | |
114 | { .be_bsm_errno = BSM_ERRNO_EDOM, .be_local_errno = EDOM, ES("Numerical argument out of domain") }, | |
115 | { .be_bsm_errno = BSM_ERRNO_ERANGE, .be_local_errno = ERANGE, ES("Result too large") }, | |
116 | { .be_bsm_errno = BSM_ERRNO_ENOMSG, .be_local_errno = ENOMSG, ES("No message of desired type") }, | |
117 | { .be_bsm_errno = BSM_ERRNO_EIDRM, .be_local_errno = EIDRM, ES("Identifier removed") }, | |
118 | { .be_bsm_errno = BSM_ERRNO_ECHRNG, | |
119 | #ifdef ECHRNG | |
120 | .be_local_errno = ECHRNG, | |
121 | #else | |
122 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
123 | #endif | |
124 | ES("Channel number out of range") }, | |
125 | { .be_bsm_errno = BSM_ERRNO_EL2NSYNC, | |
126 | #ifdef EL2NSYNC | |
127 | .be_local_errno = EL2NSYNC, | |
128 | #else | |
129 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
130 | #endif | |
131 | ES("Level 2 not synchronized") }, | |
132 | { .be_bsm_errno = BSM_ERRNO_EL3HLT, | |
133 | #ifdef EL3HLT | |
134 | .be_local_errno = EL3HLT, | |
135 | #else | |
136 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
137 | #endif | |
138 | ES("Level 3 halted") }, | |
139 | { .be_bsm_errno = BSM_ERRNO_EL3RST, | |
140 | #ifdef EL3RST | |
141 | .be_local_errno = EL3RST, | |
142 | #else | |
143 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
144 | #endif | |
145 | ES("Level 3 reset") }, | |
146 | { .be_bsm_errno = BSM_ERRNO_ELNRNG, | |
147 | #ifdef ELNRNG | |
148 | .be_local_errno = ELNRNG, | |
149 | #else | |
150 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
151 | #endif | |
152 | ES("Link number out of range") }, | |
153 | { .be_bsm_errno = BSM_ERRNO_EUNATCH, | |
154 | #ifdef EUNATCH | |
155 | .be_local_errno = EUNATCH, | |
156 | #else | |
157 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
158 | #endif | |
159 | ES("Protocol driver not attached") }, | |
160 | { .be_bsm_errno = BSM_ERRNO_ENOCSI, | |
161 | #ifdef ENOCSI | |
162 | .be_local_errno = ENOCSI, | |
163 | #else | |
164 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
165 | #endif | |
166 | ES("No CSI structure available") }, | |
167 | { .be_bsm_errno = BSM_ERRNO_EL2HLT, | |
168 | #ifdef EL2HLT | |
169 | .be_local_errno = EL2HLT, | |
170 | #else | |
171 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
172 | #endif | |
173 | ES("Level 2 halted") }, | |
174 | { .be_bsm_errno = BSM_ERRNO_EDEADLK, .be_local_errno = EDEADLK, ES("Resource deadlock avoided") }, | |
175 | { .be_bsm_errno = BSM_ERRNO_ENOLCK, .be_local_errno = ENOLCK, ES("No locks available") }, | |
176 | { .be_bsm_errno = BSM_ERRNO_ECANCELED, .be_local_errno = ECANCELED, ES("Operation canceled") }, | |
177 | { .be_bsm_errno = BSM_ERRNO_ENOTSUP, .be_local_errno = ENOTSUP, ES("Operation not supported") }, | |
178 | { .be_bsm_errno = BSM_ERRNO_EDQUOT, .be_local_errno = EDQUOT, ES("Disc quota exceeded") }, | |
179 | { .be_bsm_errno = BSM_ERRNO_EBADE, | |
180 | #ifdef EBADE | |
181 | .be_local_errno = EBADE, | |
182 | #else | |
183 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
184 | #endif | |
185 | ES("Invalid exchange") }, | |
186 | { .be_bsm_errno = BSM_ERRNO_EBADR, | |
187 | #ifdef EBADR | |
188 | .be_local_errno = EBADR, | |
189 | #else | |
190 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
191 | #endif | |
192 | ES("Invalid request descriptor") }, | |
193 | { .be_bsm_errno = BSM_ERRNO_EXFULL, | |
194 | #ifdef EXFULL | |
195 | .be_local_errno = EXFULL, | |
196 | #else | |
197 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
198 | #endif | |
199 | ES("Exchange full") }, | |
200 | { .be_bsm_errno = BSM_ERRNO_ENOANO, | |
201 | #ifdef ENOANO | |
202 | .be_local_errno = ENOANO, | |
203 | #else | |
204 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
205 | #endif | |
206 | ES("No anode") }, | |
207 | { .be_bsm_errno = BSM_ERRNO_EBADRQC, | |
208 | #ifdef EBADRQC | |
209 | .be_local_errno = EBADRQC, | |
210 | #else | |
211 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
212 | #endif | |
213 | ES("Invalid request descriptor") }, | |
214 | { .be_bsm_errno = BSM_ERRNO_EBADSLT, | |
215 | #ifdef EBADSLT | |
216 | .be_local_errno = EBADSLT, | |
217 | #else | |
218 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
219 | #endif | |
220 | ES("Invalid slot") }, | |
221 | { .be_bsm_errno = BSM_ERRNO_EDEADLOCK, | |
222 | #ifdef EDEADLOCK | |
223 | .be_local_errno = EDEADLOCK, | |
224 | #else | |
225 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
226 | #endif | |
227 | ES("Resource deadlock avoided") }, | |
228 | { .be_bsm_errno = BSM_ERRNO_EBFONT, | |
229 | #ifdef EBFONT | |
230 | .be_local_errno = EBFONT, | |
231 | #else | |
232 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
233 | #endif | |
234 | ES("Bad font file format") }, | |
235 | { .be_bsm_errno = BSM_ERRNO_EOWNERDEAD, | |
236 | #ifdef EOWNERDEAD | |
237 | .be_local_errno = EOWNERDEAD, | |
238 | #else | |
239 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
240 | #endif | |
241 | ES("Process died with the lock") }, | |
242 | { .be_bsm_errno = BSM_ERRNO_ENOTRECOVERABLE, | |
243 | #ifdef ENOTRECOVERABLE | |
244 | .be_local_errno = ENOTRECOVERABLE, | |
245 | #else | |
246 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
247 | #endif | |
248 | ES("Lock is not recoverable") }, | |
249 | { .be_bsm_errno = BSM_ERRNO_ENOSTR, | |
250 | #ifdef ENOSTR | |
251 | .be_local_errno = ENOSTR, | |
252 | #else | |
253 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
254 | #endif | |
255 | ES("Device not a stream") }, | |
256 | { .be_bsm_errno = BSM_ERRNO_ENONET, | |
257 | #ifdef ENONET | |
258 | .be_local_errno = ENONET, | |
259 | #else | |
260 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
261 | #endif | |
262 | ES("Machine is not on the network") }, | |
263 | { .be_bsm_errno = BSM_ERRNO_ENOPKG, | |
264 | #ifdef ENOPKG | |
265 | .be_local_errno = ENOPKG, | |
266 | #else | |
267 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
268 | #endif | |
269 | ES("Package not installed") }, | |
270 | { .be_bsm_errno = BSM_ERRNO_EREMOTE, .be_local_errno = EREMOTE, | |
271 | ES("Too many levels of remote in path") }, | |
272 | { .be_bsm_errno = BSM_ERRNO_ENOLINK, | |
273 | #ifdef ENOLINK | |
274 | .be_local_errno = ENOLINK, | |
275 | #else | |
276 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
277 | #endif | |
278 | ES("Link has been severed") }, | |
279 | { .be_bsm_errno = BSM_ERRNO_EADV, | |
280 | #ifdef EADV | |
281 | .be_local_errno = EADV, | |
282 | #else | |
283 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
284 | #endif | |
285 | ES("Advertise error") }, | |
286 | { .be_bsm_errno = BSM_ERRNO_ESRMNT, | |
287 | #ifdef ESRMNT | |
288 | .be_local_errno = ESRMNT, | |
289 | #else | |
290 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
291 | #endif | |
292 | ES("srmount error") }, | |
293 | { .be_bsm_errno = BSM_ERRNO_ECOMM, | |
294 | #ifdef ECOMM | |
295 | .be_local_errno = ECOMM, | |
296 | #else | |
297 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
298 | #endif | |
299 | ES("Communication error on send") }, | |
300 | { .be_bsm_errno = BSM_ERRNO_EPROTO, | |
301 | #ifdef EPROTO | |
302 | .be_local_errno = EPROTO, | |
303 | #else | |
304 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
305 | #endif | |
306 | ES("Protocol error") }, | |
307 | { .be_bsm_errno = BSM_ERRNO_ELOCKUNMAPPED, | |
308 | #ifdef ELOCKUNMAPPED | |
309 | .be_local_errno = ELOCKUNMAPPED, | |
310 | #else | |
311 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
312 | #endif | |
313 | ES("Locked lock was unmapped") }, | |
314 | { .be_bsm_errno = BSM_ERRNO_ENOTACTIVE, | |
315 | #ifdef ENOTACTIVE | |
316 | .be_local_errno = ENOTACTIVE, | |
317 | #else | |
318 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
319 | #endif | |
320 | ES("Facility is not active") }, | |
321 | { .be_bsm_errno = BSM_ERRNO_EMULTIHOP, | |
322 | #ifdef EMULTIHOP | |
323 | .be_local_errno = EMULTIHOP, | |
324 | #else | |
325 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
326 | #endif | |
327 | ES("Multihop attempted") }, | |
328 | { .be_bsm_errno = BSM_ERRNO_EBADMSG, | |
329 | #ifdef EBADMSG | |
330 | .be_local_errno = EBADMSG, | |
331 | #else | |
332 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
333 | #endif | |
334 | ES("Bad message") }, | |
335 | { .be_bsm_errno = BSM_ERRNO_ENAMETOOLONG, .be_local_errno = ENAMETOOLONG, ES("File name too long") }, | |
336 | { .be_bsm_errno = BSM_ERRNO_EOVERFLOW, .be_local_errno = EOVERFLOW, | |
337 | ES("Value too large to be stored in data type") }, | |
338 | { .be_bsm_errno = BSM_ERRNO_ENOTUNIQ, | |
339 | #ifdef ENOTUNIQ | |
340 | .be_local_errno = ENOTUNIQ, | |
341 | #else | |
342 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
343 | #endif | |
344 | ES("Given log name not unique") }, | |
345 | { .be_bsm_errno = BSM_ERRNO_EBADFD, | |
346 | #ifdef EBADFD | |
347 | .be_local_errno = EBADFD, | |
348 | #else | |
349 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
350 | #endif | |
351 | ES("Given f.d. invalid for this operation") }, | |
352 | { .be_bsm_errno = BSM_ERRNO_EREMCHG, | |
353 | #ifdef EREMCHG | |
354 | .be_local_errno = EREMCHG, | |
355 | #else | |
356 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
357 | #endif | |
358 | ES("Remote address changed") }, | |
359 | { .be_bsm_errno = BSM_ERRNO_ELIBACC, | |
360 | #ifdef ELIBACC | |
361 | .be_local_errno = ELIBACC, | |
362 | #else | |
363 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
364 | #endif | |
365 | ES("Can't access a needed shared lib") }, | |
366 | { .be_bsm_errno = BSM_ERRNO_ELIBBAD, | |
367 | #ifdef ELIBBAD | |
368 | .be_local_errno = ELIBBAD, | |
369 | #else | |
370 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
371 | #endif | |
372 | ES("Accessing a corrupted shared lib") }, | |
373 | { .be_bsm_errno = BSM_ERRNO_ELIBSCN, | |
374 | #ifdef ELIBSCN | |
375 | .be_local_errno = ELIBSCN, | |
376 | #else | |
377 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
378 | #endif | |
379 | ES(".lib section in a.out corrupted") }, | |
380 | { .be_bsm_errno = BSM_ERRNO_ELIBMAX, | |
381 | #ifdef ELIBMAX | |
382 | .be_local_errno = ELIBMAX, | |
383 | #else | |
384 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
385 | #endif | |
386 | ES("Attempting to link in too many libs") }, | |
387 | { .be_bsm_errno = BSM_ERRNO_ELIBEXEC, | |
388 | #ifdef ELIBEXEC | |
389 | .be_local_errno = ELIBEXEC, | |
390 | #else | |
391 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
392 | #endif | |
393 | ES("Attempting to exec a shared library") }, | |
394 | { .be_bsm_errno = BSM_ERRNO_EILSEQ, .be_local_errno = EILSEQ, ES("Illegal byte sequence") }, | |
395 | { .be_bsm_errno = BSM_ERRNO_ENOSYS, .be_local_errno = ENOSYS, ES("Function not implemented") }, | |
396 | { .be_bsm_errno = BSM_ERRNO_ELOOP, .be_local_errno = ELOOP, ES("Too many levels of symbolic links") }, | |
397 | { .be_bsm_errno = BSM_ERRNO_ERESTART, | |
398 | #ifdef ERESTART | |
399 | .be_local_errno = ERESTART, | |
400 | #else | |
401 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
402 | #endif | |
403 | ES("Restart syscall") }, | |
404 | { .be_bsm_errno = BSM_ERRNO_ESTRPIPE, | |
405 | #ifdef ESTRPIPE | |
406 | .be_local_errno = ESTRPIPE, | |
407 | #else | |
408 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
409 | #endif | |
410 | ES("If pipe/FIFO, don't sleep in stream head") }, | |
411 | { .be_bsm_errno = BSM_ERRNO_ENOTEMPTY, .be_local_errno = ENOTEMPTY, ES("Directory not empty") }, | |
412 | { .be_bsm_errno = BSM_ERRNO_EUSERS, .be_local_errno = EUSERS, ES("Too many users") }, | |
413 | { .be_bsm_errno = BSM_ERRNO_ENOTSOCK, .be_local_errno = ENOTSOCK, | |
414 | ES("Socket operation on non-socket") }, | |
415 | { .be_bsm_errno = BSM_ERRNO_EDESTADDRREQ, .be_local_errno = EDESTADDRREQ, | |
416 | ES("Destination address required") }, | |
417 | { .be_bsm_errno = BSM_ERRNO_EMSGSIZE, .be_local_errno = EMSGSIZE, ES("Message too long") }, | |
418 | { .be_bsm_errno = BSM_ERRNO_EPROTOTYPE, .be_local_errno = EPROTOTYPE, | |
419 | ES("Protocol wrong type for socket") }, | |
420 | { .be_bsm_errno = BSM_ERRNO_ENOPROTOOPT, .be_local_errno = ENOPROTOOPT, ES("Protocol not available") }, | |
421 | { .be_bsm_errno = BSM_ERRNO_EPROTONOSUPPORT, .be_local_errno = EPROTONOSUPPORT, | |
422 | ES("Protocol not supported") }, | |
423 | { .be_bsm_errno = BSM_ERRNO_ESOCKTNOSUPPORT, .be_local_errno = ESOCKTNOSUPPORT, | |
424 | ES("Socket type not supported") }, | |
425 | { .be_bsm_errno = BSM_ERRNO_EOPNOTSUPP, .be_local_errno = EOPNOTSUPP, ES("Operation not supported") }, | |
426 | { .be_bsm_errno = BSM_ERRNO_EPFNOSUPPORT, .be_local_errno = EPFNOSUPPORT, | |
427 | ES("Protocol family not supported") }, | |
428 | { .be_bsm_errno = BSM_ERRNO_EAFNOSUPPORT, .be_local_errno = EAFNOSUPPORT, | |
429 | ES("Address family not supported by protocol family") }, | |
430 | { .be_bsm_errno = BSM_ERRNO_EADDRINUSE, .be_local_errno = EADDRINUSE, ES("Address already in use") }, | |
431 | { .be_bsm_errno = BSM_ERRNO_EADDRNOTAVAIL, .be_local_errno = EADDRNOTAVAIL, | |
432 | ES("Can't assign requested address") }, | |
433 | { .be_bsm_errno = BSM_ERRNO_ENETDOWN, .be_local_errno = ENETDOWN, ES("Network is down") }, | |
434 | { .be_bsm_errno = BSM_ERRNO_ENETRESET, .be_local_errno = ENETRESET, | |
435 | ES("Network dropped connection on reset") }, | |
436 | { .be_bsm_errno = BSM_ERRNO_ECONNABORTED, .be_local_errno = ECONNABORTED, | |
437 | ES("Software caused connection abort") }, | |
438 | { .be_bsm_errno = BSM_ERRNO_ECONNRESET, .be_local_errno = ECONNRESET, ES("Connection reset by peer") }, | |
439 | { .be_bsm_errno = BSM_ERRNO_ENOBUFS, .be_local_errno = ENOBUFS, ES("No buffer space available") }, | |
440 | { .be_bsm_errno = BSM_ERRNO_EISCONN, .be_local_errno = EISCONN, ES("Socket is already connected") }, | |
441 | { .be_bsm_errno = BSM_ERRNO_ENOTCONN, .be_local_errno = ENOTCONN, ES("Socket is not connected") }, | |
442 | { .be_bsm_errno = BSM_ERRNO_ESHUTDOWN, .be_local_errno = ESHUTDOWN, | |
443 | ES("Can't send after socket shutdown") }, | |
444 | { .be_bsm_errno = BSM_ERRNO_ETOOMANYREFS, .be_local_errno = ETOOMANYREFS, | |
445 | ES("Too many references: can't splice") }, | |
446 | { .be_bsm_errno = BSM_ERRNO_ETIMEDOUT, .be_local_errno = ETIMEDOUT, ES("Operation timed out") }, | |
447 | { .be_bsm_errno = BSM_ERRNO_ECONNREFUSED, .be_local_errno = ECONNREFUSED, ES("Connection refused") }, | |
448 | { .be_bsm_errno = BSM_ERRNO_EHOSTDOWN, .be_local_errno = EHOSTDOWN, ES("Host is down") }, | |
449 | { .be_bsm_errno = BSM_ERRNO_EHOSTUNREACH, .be_local_errno = EHOSTUNREACH, ES("No route to host") }, | |
450 | { .be_bsm_errno = BSM_ERRNO_EALREADY, .be_local_errno = EALREADY, ES("Operation already in progress") }, | |
451 | { .be_bsm_errno = BSM_ERRNO_EINPROGRESS, .be_local_errno = EINPROGRESS, | |
452 | ES("Operation now in progress") }, | |
453 | { .be_bsm_errno = BSM_ERRNO_ESTALE, .be_local_errno = ESTALE, ES("Stale NFS file handle") }, | |
454 | { .be_bsm_errno = BSM_ERRNO_EQFULL, .be_local_errno = EQFULL, ES("Interface output queue is full") }, | |
455 | { .be_bsm_errno = BSM_ERRNO_EPWROFF, | |
456 | #ifdef EPWROFF | |
457 | .be_local_errno = EPWROFF, | |
458 | #else | |
459 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
460 | #endif | |
461 | ES("Device power is off") }, | |
462 | { .be_bsm_errno = BSM_ERRNO_EDEVERR, | |
463 | #ifdef EDEVERR | |
464 | .be_local_errno = EDEVERR, | |
465 | #else | |
466 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
467 | #endif | |
468 | ES("Device error") }, | |
469 | { .be_bsm_errno = BSM_ERRNO_EBADEXEC, | |
470 | #ifdef EBADEXEC | |
471 | .be_local_errno = EBADEXEC, | |
472 | #else | |
473 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
474 | #endif | |
475 | ES("Bad executable") }, | |
476 | { .be_bsm_errno = BSM_ERRNO_EBADARCH, | |
477 | #ifdef EBADARCH | |
478 | .be_local_errno = EBADARCH, | |
479 | #else | |
480 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
481 | #endif | |
482 | ES("Bad CPU type in executable") }, | |
483 | { .be_bsm_errno = BSM_ERRNO_ESHLIBVERS, | |
484 | #ifdef ESHLIBVERS | |
485 | .be_local_errno = ESHLIBVERS, | |
486 | #else | |
487 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
488 | #endif | |
489 | ES("Shared library version mismatch") }, | |
490 | { .be_bsm_errno = BSM_ERRNO_EBADMACHO, | |
491 | #ifdef EBADMACHO | |
492 | .be_local_errno = EBADMACHO, | |
493 | #else | |
494 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
495 | #endif | |
496 | ES("Malformed Macho file") }, | |
497 | { .be_bsm_errno = BSM_ERRNO_EPOLICY, | |
498 | #ifdef EPOLICY | |
499 | .be_local_errno = EPOLICY, | |
500 | #else | |
501 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
502 | #endif | |
503 | ES("Operation failed by policy") }, | |
504 | { .be_bsm_errno = BSM_ERRNO_EDOTDOT, | |
505 | #ifdef EDOTDOT | |
506 | .be_local_errno = EDOTDOT, | |
507 | #else | |
508 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
509 | #endif | |
510 | ES("RFS specific error") }, | |
511 | { .be_bsm_errno = BSM_ERRNO_EUCLEAN, | |
512 | #ifdef EUCLEAN | |
513 | .be_local_errno = EUCLEAN, | |
514 | #else | |
515 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
516 | #endif | |
517 | ES("Structure needs cleaning") }, | |
518 | { .be_bsm_errno = BSM_ERRNO_ENOTNAM, | |
519 | #ifdef ENOTNAM | |
520 | .be_local_errno = ENOTNAM, | |
521 | #else | |
522 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
523 | #endif | |
524 | ES("Not a XENIX named type file") }, | |
525 | { .be_bsm_errno = BSM_ERRNO_ENAVAIL, | |
526 | #ifdef ENAVAIL | |
527 | .be_local_errno = ENAVAIL, | |
528 | #else | |
529 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
530 | #endif | |
531 | ES("No XENIX semaphores available") }, | |
532 | { .be_bsm_errno = BSM_ERRNO_EISNAM, | |
533 | #ifdef EISNAM | |
534 | .be_local_errno = EISNAM, | |
535 | #else | |
536 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
537 | #endif | |
538 | ES("Is a named type file") }, | |
539 | { .be_bsm_errno = BSM_ERRNO_EREMOTEIO, | |
540 | #ifdef EREMOTEIO | |
541 | .be_local_errno = EREMOTEIO, | |
542 | #else | |
543 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
544 | #endif | |
545 | ES("Remote I/O error") }, | |
546 | { .be_bsm_errno = BSM_ERRNO_ENOMEDIUM, | |
547 | #ifdef ENOMEDIUM | |
548 | .be_local_errno = ENOMEDIUM, | |
549 | #else | |
550 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
551 | #endif | |
552 | ES("No medium found") }, | |
553 | { .be_bsm_errno = BSM_ERRNO_EMEDIUMTYPE, | |
554 | #ifdef EMEDIUMTYPE | |
555 | .be_local_errno = EMEDIUMTYPE, | |
556 | #else | |
557 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
558 | #endif | |
559 | ES("Wrong medium type") }, | |
560 | { .be_bsm_errno = BSM_ERRNO_ENOKEY, | |
561 | #ifdef ENOKEY | |
562 | .be_local_errno = ENOKEY, | |
563 | #else | |
564 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
565 | #endif | |
566 | ES("Required key not available") }, | |
567 | { .be_bsm_errno = BSM_ERRNO_EKEYEXPIRED, | |
568 | #ifdef EKEEXPIRED | |
569 | .be_local_errno = EKEYEXPIRED, | |
570 | #else | |
571 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
572 | #endif | |
573 | ES("Key has expired") }, | |
574 | { .be_bsm_errno = BSM_ERRNO_EKEYREVOKED, | |
575 | #ifdef EKEYREVOKED | |
576 | .be_local_errno = EKEYREVOKED, | |
577 | #else | |
578 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
579 | #endif | |
580 | ES("Key has been revoked") }, | |
581 | { .be_bsm_errno = BSM_ERRNO_EKEYREJECTED, | |
582 | #ifdef EKEREJECTED | |
583 | .be_local_errno = EKEYREJECTED, | |
584 | #else | |
585 | .be_local_errno = ERRNO_NO_LOCAL_MAPPING, | |
586 | #endif | |
587 | ES("Key was rejected by service") }, | |
588 | }; | |
589 | static const int bsm_errnos_count = sizeof(bsm_errnos) / sizeof(bsm_errnos[0]); | |
590 | ||
591 | static const struct bsm_errno * | |
592 | bsm_lookup_errno_local(int local_errno) | |
593 | { | |
594 | int i; | |
595 | ||
596 | for (i = 0; i < bsm_errnos_count; i++) { | |
597 | if (bsm_errnos[i].be_local_errno == local_errno) { | |
598 | return &bsm_errnos[i]; | |
599 | } | |
600 | } | |
601 | return NULL; | |
602 | } | |
603 | ||
604 | /* | |
605 | * Conversion to the BSM errno space isn't allowed to fail; we simply map to | |
606 | * BSM_ERRNO_UNKNOWN and let the remote endpoint deal with it. | |
607 | */ | |
608 | u_char | |
609 | au_errno_to_bsm(int local_errno) | |
610 | { | |
611 | const struct bsm_errno *bsme; | |
612 | ||
613 | bsme = bsm_lookup_errno_local(local_errno); | |
614 | if (bsme == NULL) { | |
615 | return BSM_ERRNO_UNKNOWN; | |
616 | } | |
617 | return bsme->be_bsm_errno; | |
618 | } | |
619 | ||
620 | static const struct bsm_errno * | |
621 | bsm_lookup_errno_bsm(u_char bsm_errno) | |
622 | { | |
623 | int i; | |
624 | ||
625 | for (i = 0; i < bsm_errnos_count; i++) { | |
626 | if (bsm_errnos[i].be_bsm_errno == bsm_errno) { | |
627 | return &bsm_errnos[i]; | |
628 | } | |
629 | } | |
630 | return NULL; | |
631 | } | |
632 | ||
633 | /* | |
634 | * Converstion from a BSM error to a local error number may fail if either | |
635 | * OpenBSM doesn't recognize the error on the wire, or because there is no | |
636 | * appropriate local mapping. | |
637 | */ | |
638 | int | |
639 | au_bsm_to_errno(u_char bsm_errno, int *errorp) | |
640 | { | |
641 | const struct bsm_errno *bsme; | |
642 | ||
643 | bsme = bsm_lookup_errno_bsm(bsm_errno); | |
644 | if (bsme == NULL || bsme->be_local_errno == ERRNO_NO_LOCAL_MAPPING) { | |
645 | return -1; | |
646 | } | |
647 | *errorp = bsme->be_local_errno; | |
648 | return 0; | |
649 | } | |
650 | ||
651 | #if !defined(KERNEL) && !defined(_KERNEL) | |
652 | const char * | |
653 | au_strerror(u_char bsm_errno) | |
654 | { | |
655 | const struct bsm_errno *bsme; | |
656 | ||
657 | bsme = bsm_lookup_errno_bsm(bsm_errno); | |
658 | if (bsme == NULL) { | |
659 | return "Unrecognized BSM error"; | |
660 | } | |
661 | if (bsme->be_local_errno != ERRNO_NO_LOCAL_MAPPING) { | |
662 | return strerror(bsme->be_local_errno); | |
663 | } | |
664 | return bsme->be_strerror; | |
665 | } | |
666 | #endif | |
667 | #endif /* CONFIG_AUDIT */ |