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