]> git.saurik.com Git - apple/xnu.git/blame - bsd/security/audit/audit_bsm_errno.c
xnu-6153.41.3.tar.gz
[apple/xnu.git] / bsd / security / audit / audit_bsm_errno.c
CommitLineData
b0d623f7 1/*-
cb323159 2 * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
b0d623f7
A
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 */
49struct bsm_errno {
0a7de745
A
50 int be_bsm_errno;
51 int be_local_errno;
b0d623f7 52#if !defined(KERNEL) && !defined(_KERNEL)
0a7de745 53 const char *be_strerror;
b0d623f7
A
54#endif
55};
56
0a7de745 57#define ERRNO_NO_LOCAL_MAPPING -600
b0d623f7
A
58
59#if !defined(KERNEL) && !defined(_KERNEL)
cb323159 60#define ES(x) .be_strerror = x
b0d623f7 61#else
0a7de745 62#define ES(x)
b0d623f7
A
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 */
80static const struct bsm_errno bsm_errnos[] = {
cb323159
A
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,
b0d623f7 119#ifdef ECHRNG
cb323159 120 .be_local_errno = ECHRNG,
b0d623f7 121#else
cb323159 122 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 123#endif
0a7de745 124 ES("Channel number out of range") },
cb323159 125 { .be_bsm_errno = BSM_ERRNO_EL2NSYNC,
b0d623f7 126#ifdef EL2NSYNC
cb323159 127 .be_local_errno = EL2NSYNC,
b0d623f7 128#else
cb323159 129 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 130#endif
0a7de745 131 ES("Level 2 not synchronized") },
cb323159 132 { .be_bsm_errno = BSM_ERRNO_EL3HLT,
b0d623f7 133#ifdef EL3HLT
cb323159 134 .be_local_errno = EL3HLT,
b0d623f7 135#else
cb323159 136 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 137#endif
0a7de745 138 ES("Level 3 halted") },
cb323159 139 { .be_bsm_errno = BSM_ERRNO_EL3RST,
b0d623f7 140#ifdef EL3RST
cb323159 141 .be_local_errno = EL3RST,
b0d623f7 142#else
cb323159 143 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 144#endif
0a7de745 145 ES("Level 3 reset") },
cb323159 146 { .be_bsm_errno = BSM_ERRNO_ELNRNG,
b0d623f7 147#ifdef ELNRNG
cb323159 148 .be_local_errno = ELNRNG,
b0d623f7 149#else
cb323159 150 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 151#endif
0a7de745 152 ES("Link number out of range") },
cb323159 153 { .be_bsm_errno = BSM_ERRNO_EUNATCH,
b0d623f7 154#ifdef EUNATCH
cb323159 155 .be_local_errno = EUNATCH,
b0d623f7 156#else
cb323159 157 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 158#endif
0a7de745 159 ES("Protocol driver not attached") },
cb323159 160 { .be_bsm_errno = BSM_ERRNO_ENOCSI,
b0d623f7 161#ifdef ENOCSI
cb323159 162 .be_local_errno = ENOCSI,
b0d623f7 163#else
cb323159 164 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 165#endif
0a7de745 166 ES("No CSI structure available") },
cb323159 167 { .be_bsm_errno = BSM_ERRNO_EL2HLT,
b0d623f7 168#ifdef EL2HLT
cb323159 169 .be_local_errno = EL2HLT,
b0d623f7 170#else
cb323159 171 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 172#endif
0a7de745 173 ES("Level 2 halted") },
cb323159
A
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,
b0d623f7 180#ifdef EBADE
cb323159 181 .be_local_errno = EBADE,
b0d623f7 182#else
cb323159 183 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 184#endif
0a7de745 185 ES("Invalid exchange") },
cb323159 186 { .be_bsm_errno = BSM_ERRNO_EBADR,
b0d623f7 187#ifdef EBADR
cb323159 188 .be_local_errno = EBADR,
b0d623f7 189#else
cb323159 190 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 191#endif
0a7de745 192 ES("Invalid request descriptor") },
cb323159 193 { .be_bsm_errno = BSM_ERRNO_EXFULL,
b0d623f7 194#ifdef EXFULL
cb323159 195 .be_local_errno = EXFULL,
b0d623f7 196#else
cb323159 197 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 198#endif
0a7de745 199 ES("Exchange full") },
cb323159 200 { .be_bsm_errno = BSM_ERRNO_ENOANO,
b0d623f7 201#ifdef ENOANO
cb323159 202 .be_local_errno = ENOANO,
b0d623f7 203#else
cb323159 204 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 205#endif
0a7de745 206 ES("No anode") },
cb323159 207 { .be_bsm_errno = BSM_ERRNO_EBADRQC,
b0d623f7 208#ifdef EBADRQC
cb323159 209 .be_local_errno = EBADRQC,
b0d623f7 210#else
cb323159 211 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 212#endif
0a7de745 213 ES("Invalid request descriptor") },
cb323159 214 { .be_bsm_errno = BSM_ERRNO_EBADSLT,
b0d623f7 215#ifdef EBADSLT
cb323159 216 .be_local_errno = EBADSLT,
b0d623f7 217#else
cb323159 218 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 219#endif
0a7de745 220 ES("Invalid slot") },
cb323159 221 { .be_bsm_errno = BSM_ERRNO_EDEADLOCK,
b0d623f7 222#ifdef EDEADLOCK
cb323159 223 .be_local_errno = EDEADLOCK,
b0d623f7 224#else
cb323159 225 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 226#endif
0a7de745 227 ES("Resource deadlock avoided") },
cb323159 228 { .be_bsm_errno = BSM_ERRNO_EBFONT,
b0d623f7 229#ifdef EBFONT
cb323159 230 .be_local_errno = EBFONT,
b0d623f7 231#else
cb323159 232 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 233#endif
0a7de745 234 ES("Bad font file format") },
cb323159 235 { .be_bsm_errno = BSM_ERRNO_EOWNERDEAD,
b0d623f7 236#ifdef EOWNERDEAD
cb323159 237 .be_local_errno = EOWNERDEAD,
b0d623f7 238#else
cb323159 239 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 240#endif
0a7de745 241 ES("Process died with the lock") },
cb323159 242 { .be_bsm_errno = BSM_ERRNO_ENOTRECOVERABLE,
b0d623f7 243#ifdef ENOTRECOVERABLE
cb323159 244 .be_local_errno = ENOTRECOVERABLE,
b0d623f7 245#else
cb323159 246 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 247#endif
0a7de745 248 ES("Lock is not recoverable") },
cb323159 249 { .be_bsm_errno = BSM_ERRNO_ENOSTR,
b0d623f7 250#ifdef ENOSTR
cb323159 251 .be_local_errno = ENOSTR,
b0d623f7 252#else
cb323159 253 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 254#endif
0a7de745 255 ES("Device not a stream") },
cb323159 256 { .be_bsm_errno = BSM_ERRNO_ENONET,
b0d623f7 257#ifdef ENONET
cb323159 258 .be_local_errno = ENONET,
b0d623f7 259#else
cb323159 260 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 261#endif
0a7de745 262 ES("Machine is not on the network") },
cb323159 263 { .be_bsm_errno = BSM_ERRNO_ENOPKG,
b0d623f7 264#ifdef ENOPKG
cb323159 265 .be_local_errno = ENOPKG,
b0d623f7 266#else
cb323159 267 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 268#endif
0a7de745 269 ES("Package not installed") },
cb323159 270 { .be_bsm_errno = BSM_ERRNO_EREMOTE, .be_local_errno = EREMOTE,
0a7de745 271 ES("Too many levels of remote in path") },
cb323159 272 { .be_bsm_errno = BSM_ERRNO_ENOLINK,
b0d623f7 273#ifdef ENOLINK
cb323159 274 .be_local_errno = ENOLINK,
b0d623f7 275#else
cb323159 276 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 277#endif
0a7de745 278 ES("Link has been severed") },
cb323159 279 { .be_bsm_errno = BSM_ERRNO_EADV,
b0d623f7 280#ifdef EADV
cb323159 281 .be_local_errno = EADV,
b0d623f7 282#else
cb323159 283 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 284#endif
0a7de745 285 ES("Advertise error") },
cb323159 286 { .be_bsm_errno = BSM_ERRNO_ESRMNT,
b0d623f7 287#ifdef ESRMNT
cb323159 288 .be_local_errno = ESRMNT,
b0d623f7 289#else
cb323159 290 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 291#endif
0a7de745 292 ES("srmount error") },
cb323159 293 { .be_bsm_errno = BSM_ERRNO_ECOMM,
b0d623f7 294#ifdef ECOMM
cb323159 295 .be_local_errno = ECOMM,
b0d623f7 296#else
cb323159 297 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 298#endif
0a7de745 299 ES("Communication error on send") },
cb323159 300 { .be_bsm_errno = BSM_ERRNO_EPROTO,
b0d623f7 301#ifdef EPROTO
cb323159 302 .be_local_errno = EPROTO,
b0d623f7 303#else
cb323159 304 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 305#endif
0a7de745 306 ES("Protocol error") },
cb323159 307 { .be_bsm_errno = BSM_ERRNO_ELOCKUNMAPPED,
b0d623f7 308#ifdef ELOCKUNMAPPED
cb323159 309 .be_local_errno = ELOCKUNMAPPED,
b0d623f7 310#else
cb323159 311 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 312#endif
0a7de745 313 ES("Locked lock was unmapped") },
cb323159 314 { .be_bsm_errno = BSM_ERRNO_ENOTACTIVE,
b0d623f7 315#ifdef ENOTACTIVE
cb323159 316 .be_local_errno = ENOTACTIVE,
b0d623f7 317#else
cb323159 318 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 319#endif
0a7de745 320 ES("Facility is not active") },
cb323159 321 { .be_bsm_errno = BSM_ERRNO_EMULTIHOP,
b0d623f7 322#ifdef EMULTIHOP
cb323159 323 .be_local_errno = EMULTIHOP,
b0d623f7 324#else
cb323159 325 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 326#endif
0a7de745 327 ES("Multihop attempted") },
cb323159 328 { .be_bsm_errno = BSM_ERRNO_EBADMSG,
b0d623f7 329#ifdef EBADMSG
cb323159 330 .be_local_errno = EBADMSG,
b0d623f7 331#else
cb323159 332 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 333#endif
0a7de745 334 ES("Bad message") },
cb323159
A
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,
0a7de745 337 ES("Value too large to be stored in data type") },
cb323159 338 { .be_bsm_errno = BSM_ERRNO_ENOTUNIQ,
b0d623f7 339#ifdef ENOTUNIQ
cb323159 340 .be_local_errno = ENOTUNIQ,
b0d623f7 341#else
cb323159 342 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 343#endif
0a7de745 344 ES("Given log name not unique") },
cb323159 345 { .be_bsm_errno = BSM_ERRNO_EBADFD,
b0d623f7 346#ifdef EBADFD
cb323159 347 .be_local_errno = EBADFD,
b0d623f7 348#else
cb323159 349 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 350#endif
0a7de745 351 ES("Given f.d. invalid for this operation") },
cb323159 352 { .be_bsm_errno = BSM_ERRNO_EREMCHG,
b0d623f7 353#ifdef EREMCHG
cb323159 354 .be_local_errno = EREMCHG,
b0d623f7 355#else
cb323159 356 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 357#endif
0a7de745 358 ES("Remote address changed") },
cb323159 359 { .be_bsm_errno = BSM_ERRNO_ELIBACC,
b0d623f7 360#ifdef ELIBACC
cb323159 361 .be_local_errno = ELIBACC,
b0d623f7 362#else
cb323159 363 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 364#endif
0a7de745 365 ES("Can't access a needed shared lib") },
cb323159 366 { .be_bsm_errno = BSM_ERRNO_ELIBBAD,
b0d623f7 367#ifdef ELIBBAD
cb323159 368 .be_local_errno = ELIBBAD,
b0d623f7 369#else
cb323159 370 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 371#endif
0a7de745 372 ES("Accessing a corrupted shared lib") },
cb323159 373 { .be_bsm_errno = BSM_ERRNO_ELIBSCN,
b0d623f7 374#ifdef ELIBSCN
cb323159 375 .be_local_errno = ELIBSCN,
b0d623f7 376#else
cb323159 377 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 378#endif
0a7de745 379 ES(".lib section in a.out corrupted") },
cb323159 380 { .be_bsm_errno = BSM_ERRNO_ELIBMAX,
b0d623f7 381#ifdef ELIBMAX
cb323159 382 .be_local_errno = ELIBMAX,
b0d623f7 383#else
cb323159 384 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 385#endif
0a7de745 386 ES("Attempting to link in too many libs") },
cb323159 387 { .be_bsm_errno = BSM_ERRNO_ELIBEXEC,
b0d623f7 388#ifdef ELIBEXEC
cb323159 389 .be_local_errno = ELIBEXEC,
b0d623f7 390#else
cb323159 391 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 392#endif
0a7de745 393 ES("Attempting to exec a shared library") },
cb323159
A
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,
b0d623f7 398#ifdef ERESTART
cb323159 399 .be_local_errno = ERESTART,
b0d623f7 400#else
cb323159 401 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 402#endif
0a7de745 403 ES("Restart syscall") },
cb323159 404 { .be_bsm_errno = BSM_ERRNO_ESTRPIPE,
b0d623f7 405#ifdef ESTRPIPE
cb323159 406 .be_local_errno = ESTRPIPE,
b0d623f7 407#else
cb323159 408 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 409#endif
0a7de745 410 ES("If pipe/FIFO, don't sleep in stream head") },
cb323159
A
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,
0a7de745 414 ES("Socket operation on non-socket") },
cb323159 415 { .be_bsm_errno = BSM_ERRNO_EDESTADDRREQ, .be_local_errno = EDESTADDRREQ,
0a7de745 416 ES("Destination address required") },
cb323159
A
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,
0a7de745 419 ES("Protocol wrong type for socket") },
cb323159
A
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,
0a7de745 422 ES("Protocol not supported") },
cb323159 423 { .be_bsm_errno = BSM_ERRNO_ESOCKTNOSUPPORT, .be_local_errno = ESOCKTNOSUPPORT,
0a7de745 424 ES("Socket type not supported") },
cb323159
A
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,
0a7de745 427 ES("Protocol family not supported") },
cb323159 428 { .be_bsm_errno = BSM_ERRNO_EAFNOSUPPORT, .be_local_errno = EAFNOSUPPORT,
0a7de745 429 ES("Address family not supported by protocol family") },
cb323159
A
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,
0a7de745 432 ES("Can't assign requested address") },
cb323159
A
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,
0a7de745 435 ES("Network dropped connection on reset") },
cb323159 436 { .be_bsm_errno = BSM_ERRNO_ECONNABORTED, .be_local_errno = ECONNABORTED,
0a7de745 437 ES("Software caused connection abort") },
cb323159
A
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,
0a7de745 443 ES("Can't send after socket shutdown") },
cb323159 444 { .be_bsm_errno = BSM_ERRNO_ETOOMANYREFS, .be_local_errno = ETOOMANYREFS,
0a7de745 445 ES("Too many references: can't splice") },
cb323159
A
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,
0a7de745 452 ES("Operation now in progress") },
cb323159
A
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,
b0d623f7 456#ifdef EPWROFF
cb323159 457 .be_local_errno = EPWROFF,
b0d623f7 458#else
cb323159 459 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 460#endif
0a7de745 461 ES("Device power is off") },
cb323159 462 { .be_bsm_errno = BSM_ERRNO_EDEVERR,
b0d623f7 463#ifdef EDEVERR
cb323159 464 .be_local_errno = EDEVERR,
b0d623f7 465#else
cb323159 466 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 467#endif
0a7de745 468 ES("Device error") },
cb323159 469 { .be_bsm_errno = BSM_ERRNO_EBADEXEC,
b0d623f7 470#ifdef EBADEXEC
cb323159 471 .be_local_errno = EBADEXEC,
b0d623f7 472#else
cb323159 473 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 474#endif
0a7de745 475 ES("Bad executable") },
cb323159 476 { .be_bsm_errno = BSM_ERRNO_EBADARCH,
b0d623f7 477#ifdef EBADARCH
cb323159 478 .be_local_errno = EBADARCH,
b0d623f7 479#else
cb323159 480 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 481#endif
0a7de745 482 ES("Bad CPU type in executable") },
cb323159 483 { .be_bsm_errno = BSM_ERRNO_ESHLIBVERS,
b0d623f7 484#ifdef ESHLIBVERS
cb323159 485 .be_local_errno = ESHLIBVERS,
b0d623f7 486#else
cb323159 487 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 488#endif
0a7de745 489 ES("Shared library version mismatch") },
cb323159 490 { .be_bsm_errno = BSM_ERRNO_EBADMACHO,
b0d623f7 491#ifdef EBADMACHO
cb323159 492 .be_local_errno = EBADMACHO,
b0d623f7 493#else
cb323159 494 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 495#endif
0a7de745 496 ES("Malformed Macho file") },
cb323159 497 { .be_bsm_errno = BSM_ERRNO_EPOLICY,
b0d623f7 498#ifdef EPOLICY
cb323159 499 .be_local_errno = EPOLICY,
b0d623f7 500#else
cb323159 501 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 502#endif
0a7de745 503 ES("Operation failed by policy") },
cb323159 504 { .be_bsm_errno = BSM_ERRNO_EDOTDOT,
b0d623f7 505#ifdef EDOTDOT
cb323159 506 .be_local_errno = EDOTDOT,
b0d623f7 507#else
cb323159 508 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 509#endif
0a7de745 510 ES("RFS specific error") },
cb323159 511 { .be_bsm_errno = BSM_ERRNO_EUCLEAN,
b0d623f7 512#ifdef EUCLEAN
cb323159 513 .be_local_errno = EUCLEAN,
b0d623f7 514#else
cb323159 515 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 516#endif
0a7de745 517 ES("Structure needs cleaning") },
cb323159 518 { .be_bsm_errno = BSM_ERRNO_ENOTNAM,
b0d623f7 519#ifdef ENOTNAM
cb323159 520 .be_local_errno = ENOTNAM,
b0d623f7 521#else
cb323159 522 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 523#endif
0a7de745 524 ES("Not a XENIX named type file") },
cb323159 525 { .be_bsm_errno = BSM_ERRNO_ENAVAIL,
b0d623f7 526#ifdef ENAVAIL
cb323159 527 .be_local_errno = ENAVAIL,
b0d623f7 528#else
cb323159 529 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 530#endif
0a7de745 531 ES("No XENIX semaphores available") },
cb323159 532 { .be_bsm_errno = BSM_ERRNO_EISNAM,
b0d623f7 533#ifdef EISNAM
cb323159 534 .be_local_errno = EISNAM,
b0d623f7 535#else
cb323159 536 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 537#endif
0a7de745 538 ES("Is a named type file") },
cb323159 539 { .be_bsm_errno = BSM_ERRNO_EREMOTEIO,
b0d623f7 540#ifdef EREMOTEIO
cb323159 541 .be_local_errno = EREMOTEIO,
b0d623f7 542#else
cb323159 543 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 544#endif
0a7de745 545 ES("Remote I/O error") },
cb323159 546 { .be_bsm_errno = BSM_ERRNO_ENOMEDIUM,
b0d623f7 547#ifdef ENOMEDIUM
cb323159 548 .be_local_errno = ENOMEDIUM,
b0d623f7 549#else
cb323159 550 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 551#endif
0a7de745 552 ES("No medium found") },
cb323159 553 { .be_bsm_errno = BSM_ERRNO_EMEDIUMTYPE,
b0d623f7 554#ifdef EMEDIUMTYPE
cb323159 555 .be_local_errno = EMEDIUMTYPE,
b0d623f7 556#else
cb323159 557 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 558#endif
0a7de745 559 ES("Wrong medium type") },
cb323159 560 { .be_bsm_errno = BSM_ERRNO_ENOKEY,
b0d623f7 561#ifdef ENOKEY
cb323159 562 .be_local_errno = ENOKEY,
b0d623f7 563#else
cb323159 564 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 565#endif
0a7de745 566 ES("Required key not available") },
cb323159 567 { .be_bsm_errno = BSM_ERRNO_EKEYEXPIRED,
b0d623f7 568#ifdef EKEEXPIRED
cb323159 569 .be_local_errno = EKEYEXPIRED,
b0d623f7 570#else
cb323159 571 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 572#endif
0a7de745 573 ES("Key has expired") },
cb323159 574 { .be_bsm_errno = BSM_ERRNO_EKEYREVOKED,
b0d623f7 575#ifdef EKEYREVOKED
cb323159 576 .be_local_errno = EKEYREVOKED,
b0d623f7 577#else
cb323159 578 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 579#endif
0a7de745 580 ES("Key has been revoked") },
cb323159 581 { .be_bsm_errno = BSM_ERRNO_EKEYREJECTED,
b0d623f7 582#ifdef EKEREJECTED
cb323159 583 .be_local_errno = EKEYREJECTED,
b0d623f7 584#else
cb323159 585 .be_local_errno = ERRNO_NO_LOCAL_MAPPING,
b0d623f7 586#endif
0a7de745 587 ES("Key was rejected by service") },
b0d623f7
A
588};
589static const int bsm_errnos_count = sizeof(bsm_errnos) / sizeof(bsm_errnos[0]);
590
591static const struct bsm_errno *
592bsm_lookup_errno_local(int local_errno)
593{
594 int i;
595
596 for (i = 0; i < bsm_errnos_count; i++) {
0a7de745
A
597 if (bsm_errnos[i].be_local_errno == local_errno) {
598 return &bsm_errnos[i];
599 }
b0d623f7 600 }
0a7de745 601 return NULL;
b0d623f7
A
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 */
608u_char
609au_errno_to_bsm(int local_errno)
610{
611 const struct bsm_errno *bsme;
612
613 bsme = bsm_lookup_errno_local(local_errno);
0a7de745
A
614 if (bsme == NULL) {
615 return BSM_ERRNO_UNKNOWN;
616 }
617 return bsme->be_bsm_errno;
b0d623f7
A
618}
619
620static const struct bsm_errno *
621bsm_lookup_errno_bsm(u_char bsm_errno)
622{
623 int i;
624
625 for (i = 0; i < bsm_errnos_count; i++) {
0a7de745
A
626 if (bsm_errnos[i].be_bsm_errno == bsm_errno) {
627 return &bsm_errnos[i];
628 }
b0d623f7 629 }
0a7de745 630 return NULL;
b0d623f7
A
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 */
638int
639au_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);
0a7de745
A
644 if (bsme == NULL || bsme->be_local_errno == ERRNO_NO_LOCAL_MAPPING) {
645 return -1;
646 }
b0d623f7 647 *errorp = bsme->be_local_errno;
0a7de745 648 return 0;
b0d623f7
A
649}
650
651#if !defined(KERNEL) && !defined(_KERNEL)
652const char *
653au_strerror(u_char bsm_errno)
654{
655 const struct bsm_errno *bsme;
656
657 bsme = bsm_lookup_errno_bsm(bsm_errno);
0a7de745
A
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;
b0d623f7
A
665}
666#endif
667#endif /* CONFIG_AUDIT */