2 * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include <sys/param.h>
32 #include <security/audit/audit.h>
34 #include <bsm/audit_errno.h>
35 #include <bsm/audit_record.h>
37 #include <sys/errno.h>
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.
47 * Don't include string definitions when this code is compiled into a kernel.
52 #if !defined(KERNEL) && !defined(_KERNEL)
53 const char *be_strerror
;
57 #define ERRNO_NO_LOCAL_MAPPING -600
59 #if !defined(KERNEL) && !defined(_KERNEL)
60 #define ES(x) .be_strerror = x
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.
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
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).
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
,
120 .be_local_errno
= ECHRNG
,
122 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
124 ES("Channel number out of range") },
125 { .be_bsm_errno
= BSM_ERRNO_EL2NSYNC
,
127 .be_local_errno
= EL2NSYNC
,
129 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
131 ES("Level 2 not synchronized") },
132 { .be_bsm_errno
= BSM_ERRNO_EL3HLT
,
134 .be_local_errno
= EL3HLT
,
136 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
138 ES("Level 3 halted") },
139 { .be_bsm_errno
= BSM_ERRNO_EL3RST
,
141 .be_local_errno
= EL3RST
,
143 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
145 ES("Level 3 reset") },
146 { .be_bsm_errno
= BSM_ERRNO_ELNRNG
,
148 .be_local_errno
= ELNRNG
,
150 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
152 ES("Link number out of range") },
153 { .be_bsm_errno
= BSM_ERRNO_EUNATCH
,
155 .be_local_errno
= EUNATCH
,
157 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
159 ES("Protocol driver not attached") },
160 { .be_bsm_errno
= BSM_ERRNO_ENOCSI
,
162 .be_local_errno
= ENOCSI
,
164 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
166 ES("No CSI structure available") },
167 { .be_bsm_errno
= BSM_ERRNO_EL2HLT
,
169 .be_local_errno
= EL2HLT
,
171 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
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
,
181 .be_local_errno
= EBADE
,
183 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
185 ES("Invalid exchange") },
186 { .be_bsm_errno
= BSM_ERRNO_EBADR
,
188 .be_local_errno
= EBADR
,
190 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
192 ES("Invalid request descriptor") },
193 { .be_bsm_errno
= BSM_ERRNO_EXFULL
,
195 .be_local_errno
= EXFULL
,
197 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
199 ES("Exchange full") },
200 { .be_bsm_errno
= BSM_ERRNO_ENOANO
,
202 .be_local_errno
= ENOANO
,
204 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
207 { .be_bsm_errno
= BSM_ERRNO_EBADRQC
,
209 .be_local_errno
= EBADRQC
,
211 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
213 ES("Invalid request descriptor") },
214 { .be_bsm_errno
= BSM_ERRNO_EBADSLT
,
216 .be_local_errno
= EBADSLT
,
218 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
220 ES("Invalid slot") },
221 { .be_bsm_errno
= BSM_ERRNO_EDEADLOCK
,
223 .be_local_errno
= EDEADLOCK
,
225 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
227 ES("Resource deadlock avoided") },
228 { .be_bsm_errno
= BSM_ERRNO_EBFONT
,
230 .be_local_errno
= EBFONT
,
232 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
234 ES("Bad font file format") },
235 { .be_bsm_errno
= BSM_ERRNO_EOWNERDEAD
,
237 .be_local_errno
= EOWNERDEAD
,
239 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
241 ES("Process died with the lock") },
242 { .be_bsm_errno
= BSM_ERRNO_ENOTRECOVERABLE
,
243 #ifdef ENOTRECOVERABLE
244 .be_local_errno
= ENOTRECOVERABLE
,
246 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
248 ES("Lock is not recoverable") },
249 { .be_bsm_errno
= BSM_ERRNO_ENOSTR
,
251 .be_local_errno
= ENOSTR
,
253 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
255 ES("Device not a stream") },
256 { .be_bsm_errno
= BSM_ERRNO_ENONET
,
258 .be_local_errno
= ENONET
,
260 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
262 ES("Machine is not on the network") },
263 { .be_bsm_errno
= BSM_ERRNO_ENOPKG
,
265 .be_local_errno
= ENOPKG
,
267 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
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
,
274 .be_local_errno
= ENOLINK
,
276 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
278 ES("Link has been severed") },
279 { .be_bsm_errno
= BSM_ERRNO_EADV
,
281 .be_local_errno
= EADV
,
283 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
285 ES("Advertise error") },
286 { .be_bsm_errno
= BSM_ERRNO_ESRMNT
,
288 .be_local_errno
= ESRMNT
,
290 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
292 ES("srmount error") },
293 { .be_bsm_errno
= BSM_ERRNO_ECOMM
,
295 .be_local_errno
= ECOMM
,
297 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
299 ES("Communication error on send") },
300 { .be_bsm_errno
= BSM_ERRNO_EPROTO
,
302 .be_local_errno
= EPROTO
,
304 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
306 ES("Protocol error") },
307 { .be_bsm_errno
= BSM_ERRNO_ELOCKUNMAPPED
,
309 .be_local_errno
= ELOCKUNMAPPED
,
311 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
313 ES("Locked lock was unmapped") },
314 { .be_bsm_errno
= BSM_ERRNO_ENOTACTIVE
,
316 .be_local_errno
= ENOTACTIVE
,
318 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
320 ES("Facility is not active") },
321 { .be_bsm_errno
= BSM_ERRNO_EMULTIHOP
,
323 .be_local_errno
= EMULTIHOP
,
325 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
327 ES("Multihop attempted") },
328 { .be_bsm_errno
= BSM_ERRNO_EBADMSG
,
330 .be_local_errno
= EBADMSG
,
332 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
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
,
340 .be_local_errno
= ENOTUNIQ
,
342 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
344 ES("Given log name not unique") },
345 { .be_bsm_errno
= BSM_ERRNO_EBADFD
,
347 .be_local_errno
= EBADFD
,
349 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
351 ES("Given f.d. invalid for this operation") },
352 { .be_bsm_errno
= BSM_ERRNO_EREMCHG
,
354 .be_local_errno
= EREMCHG
,
356 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
358 ES("Remote address changed") },
359 { .be_bsm_errno
= BSM_ERRNO_ELIBACC
,
361 .be_local_errno
= ELIBACC
,
363 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
365 ES("Can't access a needed shared lib") },
366 { .be_bsm_errno
= BSM_ERRNO_ELIBBAD
,
368 .be_local_errno
= ELIBBAD
,
370 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
372 ES("Accessing a corrupted shared lib") },
373 { .be_bsm_errno
= BSM_ERRNO_ELIBSCN
,
375 .be_local_errno
= ELIBSCN
,
377 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
379 ES(".lib section in a.out corrupted") },
380 { .be_bsm_errno
= BSM_ERRNO_ELIBMAX
,
382 .be_local_errno
= ELIBMAX
,
384 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
386 ES("Attempting to link in too many libs") },
387 { .be_bsm_errno
= BSM_ERRNO_ELIBEXEC
,
389 .be_local_errno
= ELIBEXEC
,
391 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
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
,
399 .be_local_errno
= ERESTART
,
401 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
403 ES("Restart syscall") },
404 { .be_bsm_errno
= BSM_ERRNO_ESTRPIPE
,
406 .be_local_errno
= ESTRPIPE
,
408 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
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
,
457 .be_local_errno
= EPWROFF
,
459 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
461 ES("Device power is off") },
462 { .be_bsm_errno
= BSM_ERRNO_EDEVERR
,
464 .be_local_errno
= EDEVERR
,
466 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
468 ES("Device error") },
469 { .be_bsm_errno
= BSM_ERRNO_EBADEXEC
,
471 .be_local_errno
= EBADEXEC
,
473 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
475 ES("Bad executable") },
476 { .be_bsm_errno
= BSM_ERRNO_EBADARCH
,
478 .be_local_errno
= EBADARCH
,
480 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
482 ES("Bad CPU type in executable") },
483 { .be_bsm_errno
= BSM_ERRNO_ESHLIBVERS
,
485 .be_local_errno
= ESHLIBVERS
,
487 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
489 ES("Shared library version mismatch") },
490 { .be_bsm_errno
= BSM_ERRNO_EBADMACHO
,
492 .be_local_errno
= EBADMACHO
,
494 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
496 ES("Malformed Macho file") },
497 { .be_bsm_errno
= BSM_ERRNO_EPOLICY
,
499 .be_local_errno
= EPOLICY
,
501 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
503 ES("Operation failed by policy") },
504 { .be_bsm_errno
= BSM_ERRNO_EDOTDOT
,
506 .be_local_errno
= EDOTDOT
,
508 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
510 ES("RFS specific error") },
511 { .be_bsm_errno
= BSM_ERRNO_EUCLEAN
,
513 .be_local_errno
= EUCLEAN
,
515 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
517 ES("Structure needs cleaning") },
518 { .be_bsm_errno
= BSM_ERRNO_ENOTNAM
,
520 .be_local_errno
= ENOTNAM
,
522 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
524 ES("Not a XENIX named type file") },
525 { .be_bsm_errno
= BSM_ERRNO_ENAVAIL
,
527 .be_local_errno
= ENAVAIL
,
529 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
531 ES("No XENIX semaphores available") },
532 { .be_bsm_errno
= BSM_ERRNO_EISNAM
,
534 .be_local_errno
= EISNAM
,
536 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
538 ES("Is a named type file") },
539 { .be_bsm_errno
= BSM_ERRNO_EREMOTEIO
,
541 .be_local_errno
= EREMOTEIO
,
543 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
545 ES("Remote I/O error") },
546 { .be_bsm_errno
= BSM_ERRNO_ENOMEDIUM
,
548 .be_local_errno
= ENOMEDIUM
,
550 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
552 ES("No medium found") },
553 { .be_bsm_errno
= BSM_ERRNO_EMEDIUMTYPE
,
555 .be_local_errno
= EMEDIUMTYPE
,
557 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
559 ES("Wrong medium type") },
560 { .be_bsm_errno
= BSM_ERRNO_ENOKEY
,
562 .be_local_errno
= ENOKEY
,
564 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
566 ES("Required key not available") },
567 { .be_bsm_errno
= BSM_ERRNO_EKEYEXPIRED
,
569 .be_local_errno
= EKEYEXPIRED
,
571 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
573 ES("Key has expired") },
574 { .be_bsm_errno
= BSM_ERRNO_EKEYREVOKED
,
576 .be_local_errno
= EKEYREVOKED
,
578 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
580 ES("Key has been revoked") },
581 { .be_bsm_errno
= BSM_ERRNO_EKEYREJECTED
,
583 .be_local_errno
= EKEYREJECTED
,
585 .be_local_errno
= ERRNO_NO_LOCAL_MAPPING
,
587 ES("Key was rejected by service") },
589 static const int bsm_errnos_count
= sizeof(bsm_errnos
) / sizeof(bsm_errnos
[0]);
591 static const struct bsm_errno
*
592 bsm_lookup_errno_local(int local_errno
)
596 for (i
= 0; i
< bsm_errnos_count
; i
++) {
597 if (bsm_errnos
[i
].be_local_errno
== local_errno
) {
598 return &bsm_errnos
[i
];
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.
609 au_errno_to_bsm(int local_errno
)
611 const struct bsm_errno
*bsme
;
613 bsme
= bsm_lookup_errno_local(local_errno
);
615 return BSM_ERRNO_UNKNOWN
;
617 return bsme
->be_bsm_errno
;
620 static const struct bsm_errno
*
621 bsm_lookup_errno_bsm(u_char bsm_errno
)
625 for (i
= 0; i
< bsm_errnos_count
; i
++) {
626 if (bsm_errnos
[i
].be_bsm_errno
== bsm_errno
) {
627 return &bsm_errnos
[i
];
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.
639 au_bsm_to_errno(u_char bsm_errno
, int *errorp
)
641 const struct bsm_errno
*bsme
;
643 bsme
= bsm_lookup_errno_bsm(bsm_errno
);
644 if (bsme
== NULL
|| bsme
->be_local_errno
== ERRNO_NO_LOCAL_MAPPING
) {
647 *errorp
= bsme
->be_local_errno
;
651 #if !defined(KERNEL) && !defined(_KERNEL)
653 au_strerror(u_char bsm_errno
)
655 const struct bsm_errno
*bsme
;
657 bsme
= bsm_lookup_errno_bsm(bsm_errno
);
659 return "Unrecognized BSM error";
661 if (bsme
->be_local_errno
!= ERRNO_NO_LOCAL_MAPPING
) {
662 return strerror(bsme
->be_local_errno
);
664 return bsme
->be_strerror
;
667 #endif /* CONFIG_AUDIT */