1186647Srwatson/*- 2186647Srwatson * Copyright (c) 2008 Apple Inc. 3186647Srwatson * All rights reserved. 4186647Srwatson * 5186647Srwatson * Redistribution and use in source and binary forms, with or without 6186647Srwatson * modification, are permitted provided that the following conditions 7186647Srwatson * are met: 8186647Srwatson * 1. Redistributions of source code must retain the above copyright 9186647Srwatson * notice, this list of conditions and the following disclaimer. 10186647Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11186647Srwatson * notice, this list of conditions and the following disclaimer in the 12186647Srwatson * documentation and/or other materials provided with the distribution. 13186647Srwatson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14186647Srwatson * its contributors may be used to endorse or promote products derived 15186647Srwatson * from this software without specific prior written permission. 16186647Srwatson * 17186647Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 18186647Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19186647Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20186647Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 21186647Srwatson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22186647Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23186647Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24186647Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25186647Srwatson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26186647Srwatson * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27186647Srwatson * POSSIBILITY OF SUCH DAMAGE. 28186647Srwatson * 29243751Srwatson * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#22 30186647Srwatson */ 31186647Srwatson 32186647Srwatson#include <sys/cdefs.h> 33186647Srwatson__FBSDID("$FreeBSD$"); 34186647Srwatson 35186650Srwatson#include <sys/param.h> 36186647Srwatson 37186650Srwatson#include <security/audit/audit.h> 38186650Srwatson 39186647Srwatson#include <bsm/audit_errno.h> 40186650Srwatson#include <bsm/audit_record.h> 41186647Srwatson 42186647Srwatson#include <sys/errno.h> 43186647Srwatson 44186647Srwatson/* 45186647Srwatson * Different operating systems use different numeric constants for different 46186647Srwatson * error numbers, and sometimes error numbers don't exist in more than one 47186647Srwatson * operating system. These routines convert between BSM and local error 48186647Srwatson * number spaces, subject to the above realities. BSM error numbers are 49186647Srwatson * stored in a single 8-bit character, so don't have a byte order. 50187214Srwatson * 51187214Srwatson * Don't include string definitions when this code is compiled into a kernel. 52186647Srwatson */ 53187214Srwatsonstruct bsm_errno { 54187214Srwatson int be_bsm_errno; 55187214Srwatson int be_local_errno; 56187214Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 57186647Srwatson const char *be_strerror; 58187214Srwatson#endif 59186647Srwatson}; 60186647Srwatson 61186647Srwatson#define ERRNO_NO_LOCAL_MAPPING -600 62186647Srwatson 63187214Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 64187214Srwatson#define ES(x) x 65187214Srwatson#else 66187214Srwatson#define ES(x) 67187214Srwatson#endif 68187214Srwatson 69186647Srwatson/* 70186647Srwatson * Mapping table -- please maintain in numeric sorted order with respect to 71186647Srwatson * the BSM constant. Today we do a linear lookup, but could switch to a 72186647Srwatson * binary search if it makes sense. We only ifdef errors that aren't 73186647Srwatson * generally available, but it does make the table a lot more ugly. 74186647Srwatson * 75186647Srwatson * XXXRW: It would be nice to have a similar ordered table mapping to BSM 76186647Srwatson * constant from local constant, but the order of local constants varies by 77186647Srwatson * OS. Really we need to build that table at compile-time but don't do that 78186647Srwatson * yet. 79186647Srwatson * 80186647Srwatson * XXXRW: We currently embed English-language error strings here, but should 81186647Srwatson * support catalogues; these are only used if the OS doesn't have an error 82186647Srwatson * string using strerror(3). 83186647Srwatson */ 84187214Srwatsonstatic const struct bsm_errno bsm_errnos[] = { 85187214Srwatson { BSM_ERRNO_ESUCCESS, 0, ES("Success") }, 86187214Srwatson { BSM_ERRNO_EPERM, EPERM, ES("Operation not permitted") }, 87187214Srwatson { BSM_ERRNO_ENOENT, ENOENT, ES("No such file or directory") }, 88187214Srwatson { BSM_ERRNO_ESRCH, ESRCH, ES("No such process") }, 89187214Srwatson { BSM_ERRNO_EINTR, EINTR, ES("Interrupted system call") }, 90187214Srwatson { BSM_ERRNO_EIO, EIO, ES("Input/output error") }, 91187214Srwatson { BSM_ERRNO_ENXIO, ENXIO, ES("Device not configured") }, 92187214Srwatson { BSM_ERRNO_E2BIG, E2BIG, ES("Argument list too long") }, 93187214Srwatson { BSM_ERRNO_ENOEXEC, ENOEXEC, ES("Exec format error") }, 94187214Srwatson { BSM_ERRNO_EBADF, EBADF, ES("Bad file descriptor") }, 95187214Srwatson { BSM_ERRNO_ECHILD, ECHILD, ES("No child processes") }, 96187214Srwatson { BSM_ERRNO_EAGAIN, EAGAIN, ES("Resource temporarily unavailable") }, 97187214Srwatson { BSM_ERRNO_ENOMEM, ENOMEM, ES("Cannot allocate memory") }, 98187214Srwatson { BSM_ERRNO_EACCES, EACCES, ES("Permission denied") }, 99187214Srwatson { BSM_ERRNO_EFAULT, EFAULT, ES("Bad address") }, 100187214Srwatson { BSM_ERRNO_ENOTBLK, ENOTBLK, ES("Block device required") }, 101187214Srwatson { BSM_ERRNO_EBUSY, EBUSY, ES("Device busy") }, 102187214Srwatson { BSM_ERRNO_EEXIST, EEXIST, ES("File exists") }, 103187214Srwatson { BSM_ERRNO_EXDEV, EXDEV, ES("Cross-device link") }, 104187214Srwatson { BSM_ERRNO_ENODEV, ENODEV, ES("Operation not supported by device") }, 105187214Srwatson { BSM_ERRNO_ENOTDIR, ENOTDIR, ES("Not a directory") }, 106187214Srwatson { BSM_ERRNO_EISDIR, EISDIR, ES("Is a directory") }, 107187214Srwatson { BSM_ERRNO_EINVAL, EINVAL, ES("Invalid argument") }, 108187214Srwatson { BSM_ERRNO_ENFILE, ENFILE, ES("Too many open files in system") }, 109187214Srwatson { BSM_ERRNO_EMFILE, EMFILE, ES("Too many open files") }, 110187214Srwatson { BSM_ERRNO_ENOTTY, ENOTTY, ES("Inappropriate ioctl for device") }, 111187214Srwatson { BSM_ERRNO_ETXTBSY, ETXTBSY, ES("Text file busy") }, 112187214Srwatson { BSM_ERRNO_EFBIG, EFBIG, ES("File too large") }, 113187214Srwatson { BSM_ERRNO_ENOSPC, ENOSPC, ES("No space left on device") }, 114187214Srwatson { BSM_ERRNO_ESPIPE, ESPIPE, ES("Illegal seek") }, 115187214Srwatson { BSM_ERRNO_EROFS, EROFS, ES("Read-only file system") }, 116187214Srwatson { BSM_ERRNO_EMLINK, EMLINK, ES("Too many links") }, 117187214Srwatson { BSM_ERRNO_EPIPE, EPIPE, ES("Broken pipe") }, 118187214Srwatson { BSM_ERRNO_EDOM, EDOM, ES("Numerical argument out of domain") }, 119187214Srwatson { BSM_ERRNO_ERANGE, ERANGE, ES("Result too large") }, 120187214Srwatson { BSM_ERRNO_ENOMSG, ENOMSG, ES("No message of desired type") }, 121187214Srwatson { BSM_ERRNO_EIDRM, EIDRM, ES("Identifier removed") }, 122187214Srwatson { BSM_ERRNO_ECHRNG, 123186647Srwatson#ifdef ECHRNG 124186647Srwatson ECHRNG, 125186647Srwatson#else 126186647Srwatson ERRNO_NO_LOCAL_MAPPING, 127186647Srwatson#endif 128187214Srwatson ES("Channel number out of range") }, 129187214Srwatson { BSM_ERRNO_EL2NSYNC, 130186647Srwatson#ifdef EL2NSYNC 131186647Srwatson EL2NSYNC, 132186647Srwatson#else 133186647Srwatson ERRNO_NO_LOCAL_MAPPING, 134186647Srwatson#endif 135187214Srwatson ES("Level 2 not synchronized") }, 136187214Srwatson { BSM_ERRNO_EL3HLT, 137186647Srwatson#ifdef EL3HLT 138186647Srwatson EL3HLT, 139186647Srwatson#else 140186647Srwatson ERRNO_NO_LOCAL_MAPPING, 141186647Srwatson#endif 142187214Srwatson ES("Level 3 halted") }, 143187214Srwatson { BSM_ERRNO_EL3RST, 144186647Srwatson#ifdef EL3RST 145186647Srwatson EL3RST, 146186647Srwatson#else 147186647Srwatson ERRNO_NO_LOCAL_MAPPING, 148186647Srwatson#endif 149187214Srwatson ES("Level 3 reset") }, 150187214Srwatson { BSM_ERRNO_ELNRNG, 151186647Srwatson#ifdef ELNRNG 152186647Srwatson ELNRNG, 153186647Srwatson#else 154186647Srwatson ERRNO_NO_LOCAL_MAPPING, 155186647Srwatson#endif 156187214Srwatson ES("Link number out of range") }, 157187214Srwatson { BSM_ERRNO_EUNATCH, 158186647Srwatson#ifdef EUNATCH 159186647Srwatson EUNATCH, 160186647Srwatson#else 161186647Srwatson ERRNO_NO_LOCAL_MAPPING, 162186647Srwatson#endif 163187214Srwatson ES("Protocol driver not attached") }, 164187214Srwatson { BSM_ERRNO_ENOCSI, 165186647Srwatson#ifdef ENOCSI 166186647Srwatson ENOCSI, 167186647Srwatson#else 168186647Srwatson ERRNO_NO_LOCAL_MAPPING, 169186647Srwatson#endif 170187214Srwatson ES("No CSI structure available") }, 171187214Srwatson { BSM_ERRNO_EL2HLT, 172186647Srwatson#ifdef EL2HLT 173186647Srwatson EL2HLT, 174186647Srwatson#else 175186647Srwatson ERRNO_NO_LOCAL_MAPPING, 176186647Srwatson#endif 177187214Srwatson ES("Level 2 halted") }, 178187214Srwatson { BSM_ERRNO_EDEADLK, EDEADLK, ES("Resource deadlock avoided") }, 179187214Srwatson { BSM_ERRNO_ENOLCK, ENOLCK, ES("No locks available") }, 180187214Srwatson { BSM_ERRNO_ECANCELED, ECANCELED, ES("Operation canceled") }, 181187214Srwatson { BSM_ERRNO_ENOTSUP, ENOTSUP, ES("Operation not supported") }, 182187214Srwatson { BSM_ERRNO_EDQUOT, EDQUOT, ES("Disc quota exceeded") }, 183187214Srwatson { BSM_ERRNO_EBADE, 184186647Srwatson#ifdef EBADE 185186647Srwatson EBADE, 186186647Srwatson#else 187186647Srwatson ERRNO_NO_LOCAL_MAPPING, 188186647Srwatson#endif 189187214Srwatson ES("Invalid exchange") }, 190187214Srwatson { BSM_ERRNO_EBADR, 191186647Srwatson#ifdef EBADR 192186647Srwatson EBADR, 193186647Srwatson#else 194186647Srwatson ERRNO_NO_LOCAL_MAPPING, 195186647Srwatson#endif 196187214Srwatson ES("Invalid request descriptor") }, 197187214Srwatson { BSM_ERRNO_EXFULL, 198186647Srwatson#ifdef EXFULL 199186647Srwatson EXFULL, 200186647Srwatson#else 201186647Srwatson ERRNO_NO_LOCAL_MAPPING, 202186647Srwatson#endif 203187214Srwatson ES("Exchange full") }, 204187214Srwatson { BSM_ERRNO_ENOANO, 205186647Srwatson#ifdef ENOANO 206186647Srwatson ENOANO, 207186647Srwatson#else 208186647Srwatson ERRNO_NO_LOCAL_MAPPING, 209186647Srwatson#endif 210187214Srwatson ES("No anode") }, 211187214Srwatson { BSM_ERRNO_EBADRQC, 212186647Srwatson#ifdef EBADRQC 213186647Srwatson EBADRQC, 214186647Srwatson#else 215186647Srwatson ERRNO_NO_LOCAL_MAPPING, 216186647Srwatson#endif 217187214Srwatson ES("Invalid request descriptor") }, 218187214Srwatson { BSM_ERRNO_EBADSLT, 219186647Srwatson#ifdef EBADSLT 220186647Srwatson EBADSLT, 221186647Srwatson#else 222186647Srwatson ERRNO_NO_LOCAL_MAPPING, 223186647Srwatson#endif 224187214Srwatson ES("Invalid slot") }, 225187214Srwatson { BSM_ERRNO_EDEADLOCK, 226186647Srwatson#ifdef EDEADLOCK 227186647Srwatson EDEADLOCK, 228186647Srwatson#else 229186647Srwatson ERRNO_NO_LOCAL_MAPPING, 230186647Srwatson#endif 231187214Srwatson ES("Resource deadlock avoided") }, 232187214Srwatson { BSM_ERRNO_EBFONT, 233186647Srwatson#ifdef EBFONT 234186647Srwatson EBFONT, 235186647Srwatson#else 236186647Srwatson ERRNO_NO_LOCAL_MAPPING, 237186647Srwatson#endif 238187214Srwatson ES("Bad font file format") }, 239187214Srwatson { BSM_ERRNO_EOWNERDEAD, 240186647Srwatson#ifdef EOWNERDEAD 241186647Srwatson EOWNERDEAD, 242186647Srwatson#else 243186647Srwatson ERRNO_NO_LOCAL_MAPPING, 244186647Srwatson#endif 245187214Srwatson ES("Process died with the lock") }, 246187214Srwatson { BSM_ERRNO_ENOTRECOVERABLE, 247186647Srwatson#ifdef ENOTRECOVERABLE 248186647Srwatson ENOTRECOVERABLE, 249186647Srwatson#else 250186647Srwatson ERRNO_NO_LOCAL_MAPPING, 251186647Srwatson#endif 252187214Srwatson ES("Lock is not recoverable") }, 253187214Srwatson { BSM_ERRNO_ENOSTR, 254186647Srwatson#ifdef ENOSTR 255186647Srwatson ENOSTR, 256186647Srwatson#else 257186647Srwatson ERRNO_NO_LOCAL_MAPPING, 258186647Srwatson#endif 259187214Srwatson ES("Device not a stream") }, 260187214Srwatson { BSM_ERRNO_ENONET, 261186647Srwatson#ifdef ENONET 262186647Srwatson ENONET, 263186647Srwatson#else 264186647Srwatson ERRNO_NO_LOCAL_MAPPING, 265186647Srwatson#endif 266187214Srwatson ES("Machine is not on the network") }, 267187214Srwatson { BSM_ERRNO_ENOPKG, 268186647Srwatson#ifdef ENOPKG 269186647Srwatson ENOPKG, 270186647Srwatson#else 271186647Srwatson ERRNO_NO_LOCAL_MAPPING, 272186647Srwatson#endif 273187214Srwatson ES("Package not installed") }, 274187214Srwatson { BSM_ERRNO_EREMOTE, EREMOTE, 275187214Srwatson ES("Too many levels of remote in path") }, 276187214Srwatson { BSM_ERRNO_ENOLINK, 277186647Srwatson#ifdef ENOLINK 278186647Srwatson ENOLINK, 279186647Srwatson#else 280186647Srwatson ERRNO_NO_LOCAL_MAPPING, 281186647Srwatson#endif 282187214Srwatson ES("Link has been severed") }, 283187214Srwatson { BSM_ERRNO_EADV, 284186647Srwatson#ifdef EADV 285186647Srwatson EADV, 286186647Srwatson#else 287186647Srwatson ERRNO_NO_LOCAL_MAPPING, 288186647Srwatson#endif 289187214Srwatson ES("Advertise error") }, 290187214Srwatson { BSM_ERRNO_ESRMNT, 291186647Srwatson#ifdef ESRMNT 292186647Srwatson ESRMNT, 293186647Srwatson#else 294186647Srwatson ERRNO_NO_LOCAL_MAPPING, 295186647Srwatson#endif 296187214Srwatson ES("srmount error") }, 297187214Srwatson { BSM_ERRNO_ECOMM, 298186647Srwatson#ifdef ECOMM 299186647Srwatson ECOMM, 300186647Srwatson#else 301186647Srwatson ERRNO_NO_LOCAL_MAPPING, 302186647Srwatson#endif 303187214Srwatson ES("Communication error on send") }, 304187214Srwatson { BSM_ERRNO_EPROTO, 305186647Srwatson#ifdef EPROTO 306186647Srwatson EPROTO, 307186647Srwatson#else 308186647Srwatson ERRNO_NO_LOCAL_MAPPING, 309186647Srwatson#endif 310187214Srwatson ES("Protocol error") }, 311187214Srwatson { BSM_ERRNO_ELOCKUNMAPPED, 312186647Srwatson#ifdef ELOCKUNMAPPED 313186647Srwatson ELOCKUNMAPPED, 314186647Srwatson#else 315186647Srwatson ERRNO_NO_LOCAL_MAPPING, 316186647Srwatson#endif 317187214Srwatson ES("Locked lock was unmapped") }, 318187214Srwatson { BSM_ERRNO_ENOTACTIVE, 319186647Srwatson#ifdef ENOTACTIVE 320186647Srwatson ENOTACTIVE, 321186647Srwatson#else 322186647Srwatson ERRNO_NO_LOCAL_MAPPING, 323186647Srwatson#endif 324187214Srwatson ES("Facility is not active") }, 325187214Srwatson { BSM_ERRNO_EMULTIHOP, 326186647Srwatson#ifdef EMULTIHOP 327186647Srwatson EMULTIHOP, 328186647Srwatson#else 329186647Srwatson ERRNO_NO_LOCAL_MAPPING, 330186647Srwatson#endif 331187214Srwatson ES("Multihop attempted") }, 332187214Srwatson { BSM_ERRNO_EBADMSG, 333186647Srwatson#ifdef EBADMSG 334186647Srwatson EBADMSG, 335186647Srwatson#else 336186647Srwatson ERRNO_NO_LOCAL_MAPPING, 337186647Srwatson#endif 338187214Srwatson ES("Bad message") }, 339187214Srwatson { BSM_ERRNO_ENAMETOOLONG, ENAMETOOLONG, ES("File name too long") }, 340187214Srwatson { BSM_ERRNO_EOVERFLOW, EOVERFLOW, 341187214Srwatson ES("Value too large to be stored in data type") }, 342187214Srwatson { BSM_ERRNO_ENOTUNIQ, 343186647Srwatson#ifdef ENOTUNIQ 344186647Srwatson ENOTUNIQ, 345186647Srwatson#else 346186647Srwatson ERRNO_NO_LOCAL_MAPPING, 347186647Srwatson#endif 348187214Srwatson ES("Given log name not unique") }, 349187214Srwatson { BSM_ERRNO_EBADFD, 350186647Srwatson#ifdef EBADFD 351186647Srwatson EBADFD, 352186647Srwatson#else 353186647Srwatson ERRNO_NO_LOCAL_MAPPING, 354186647Srwatson#endif 355187214Srwatson ES("Given f.d. invalid for this operation") }, 356187214Srwatson { BSM_ERRNO_EREMCHG, 357186647Srwatson#ifdef EREMCHG 358186647Srwatson EREMCHG, 359186647Srwatson#else 360186647Srwatson ERRNO_NO_LOCAL_MAPPING, 361186647Srwatson#endif 362187214Srwatson ES("Remote address changed") }, 363187214Srwatson { BSM_ERRNO_ELIBACC, 364186647Srwatson#ifdef ELIBACC 365186647Srwatson ELIBACC, 366186647Srwatson#else 367186647Srwatson ERRNO_NO_LOCAL_MAPPING, 368186647Srwatson#endif 369187214Srwatson ES("Can't access a needed shared lib") }, 370187214Srwatson { BSM_ERRNO_ELIBBAD, 371186647Srwatson#ifdef ELIBBAD 372186647Srwatson ELIBBAD, 373186647Srwatson#else 374186647Srwatson ERRNO_NO_LOCAL_MAPPING, 375186647Srwatson#endif 376187214Srwatson ES("Accessing a corrupted shared lib") }, 377187214Srwatson { BSM_ERRNO_ELIBSCN, 378186647Srwatson#ifdef ELIBSCN 379186647Srwatson ELIBSCN, 380186647Srwatson#else 381186647Srwatson ERRNO_NO_LOCAL_MAPPING, 382186647Srwatson#endif 383187214Srwatson ES(".lib section in a.out corrupted") }, 384187214Srwatson { BSM_ERRNO_ELIBMAX, 385186647Srwatson#ifdef ELIBMAX 386186647Srwatson ELIBMAX, 387186647Srwatson#else 388186647Srwatson ERRNO_NO_LOCAL_MAPPING, 389186647Srwatson#endif 390187214Srwatson ES("Attempting to link in too many libs") }, 391187214Srwatson { BSM_ERRNO_ELIBEXEC, 392186647Srwatson#ifdef ELIBEXEC 393186647Srwatson ELIBEXEC, 394186647Srwatson#else 395186647Srwatson ERRNO_NO_LOCAL_MAPPING, 396186647Srwatson#endif 397187214Srwatson ES("Attempting to exec a shared library") }, 398187214Srwatson { BSM_ERRNO_EILSEQ, EILSEQ, ES("Illegal byte sequence") }, 399187214Srwatson { BSM_ERRNO_ENOSYS, ENOSYS, ES("Function not implemented") }, 400187214Srwatson { BSM_ERRNO_ELOOP, ELOOP, ES("Too many levels of symbolic links") }, 401187214Srwatson { BSM_ERRNO_ERESTART, 402186647Srwatson#ifdef ERESTART 403186647Srwatson ERESTART, 404186647Srwatson#else 405186647Srwatson ERRNO_NO_LOCAL_MAPPING, 406186647Srwatson#endif 407187214Srwatson ES("Restart syscall") }, 408187214Srwatson { BSM_ERRNO_ESTRPIPE, 409186647Srwatson#ifdef ESTRPIPE 410186647Srwatson ESTRPIPE, 411186647Srwatson#else 412186647Srwatson ERRNO_NO_LOCAL_MAPPING, 413186647Srwatson#endif 414187214Srwatson ES("If pipe/FIFO, don't sleep in stream head") }, 415187214Srwatson { BSM_ERRNO_ENOTEMPTY, ENOTEMPTY, ES("Directory not empty") }, 416187214Srwatson { BSM_ERRNO_EUSERS, EUSERS, ES("Too many users") }, 417187214Srwatson { BSM_ERRNO_ENOTSOCK, ENOTSOCK, 418187214Srwatson ES("Socket operation on non-socket") }, 419187214Srwatson { BSM_ERRNO_EDESTADDRREQ, EDESTADDRREQ, 420187214Srwatson ES("Destination address required") }, 421187214Srwatson { BSM_ERRNO_EMSGSIZE, EMSGSIZE, ES("Message too long") }, 422187214Srwatson { BSM_ERRNO_EPROTOTYPE, EPROTOTYPE, 423187214Srwatson ES("Protocol wrong type for socket") }, 424187214Srwatson { BSM_ERRNO_ENOPROTOOPT, ENOPROTOOPT, ES("Protocol not available") }, 425187214Srwatson { BSM_ERRNO_EPROTONOSUPPORT, EPROTONOSUPPORT, 426187214Srwatson ES("Protocol not supported") }, 427187214Srwatson { BSM_ERRNO_ESOCKTNOSUPPORT, ESOCKTNOSUPPORT, 428187214Srwatson ES("Socket type not supported") }, 429187214Srwatson { BSM_ERRNO_EOPNOTSUPP, EOPNOTSUPP, ES("Operation not supported") }, 430187214Srwatson { BSM_ERRNO_EPFNOSUPPORT, EPFNOSUPPORT, 431187214Srwatson ES("Protocol family not supported") }, 432187214Srwatson { BSM_ERRNO_EAFNOSUPPORT, EAFNOSUPPORT, 433187214Srwatson ES("Address family not supported by protocol family") }, 434187214Srwatson { BSM_ERRNO_EADDRINUSE, EADDRINUSE, ES("Address already in use") }, 435187214Srwatson { BSM_ERRNO_EADDRNOTAVAIL, EADDRNOTAVAIL, 436187214Srwatson ES("Can't assign requested address") }, 437187214Srwatson { BSM_ERRNO_ENETDOWN, ENETDOWN, ES("Network is down") }, 438187214Srwatson { BSM_ERRNO_ENETRESET, ENETRESET, 439187214Srwatson ES("Network dropped connection on reset") }, 440187214Srwatson { BSM_ERRNO_ECONNABORTED, ECONNABORTED, 441187214Srwatson ES("Software caused connection abort") }, 442187214Srwatson { BSM_ERRNO_ECONNRESET, ECONNRESET, ES("Connection reset by peer") }, 443187214Srwatson { BSM_ERRNO_ENOBUFS, ENOBUFS, ES("No buffer space available") }, 444187214Srwatson { BSM_ERRNO_EISCONN, EISCONN, ES("Socket is already connected") }, 445187214Srwatson { BSM_ERRNO_ENOTCONN, ENOTCONN, ES("Socket is not connected") }, 446187214Srwatson { BSM_ERRNO_ESHUTDOWN, ESHUTDOWN, 447187214Srwatson ES("Can't send after socket shutdown") }, 448187214Srwatson { BSM_ERRNO_ETOOMANYREFS, ETOOMANYREFS, 449187214Srwatson ES("Too many references: can't splice") }, 450187214Srwatson { BSM_ERRNO_ETIMEDOUT, ETIMEDOUT, ES("Operation timed out") }, 451187214Srwatson { BSM_ERRNO_ECONNREFUSED, ECONNREFUSED, ES("Connection refused") }, 452187214Srwatson { BSM_ERRNO_EHOSTDOWN, EHOSTDOWN, ES("Host is down") }, 453187214Srwatson { BSM_ERRNO_EHOSTUNREACH, EHOSTUNREACH, ES("No route to host") }, 454187214Srwatson { BSM_ERRNO_EALREADY, EALREADY, ES("Operation already in progress") }, 455187214Srwatson { BSM_ERRNO_EINPROGRESS, EINPROGRESS, 456187214Srwatson ES("Operation now in progress") }, 457187214Srwatson { BSM_ERRNO_ESTALE, ESTALE, ES("Stale NFS file handle") }, 458195740Srwatson { BSM_ERRNO_EPROCLIM, 459195740Srwatson#ifdef EPROCLIM 460195740Srwatson EPROCLIM, 461195740Srwatson#else 462195740Srwatson ERRNO_NO_LOCAL_MAPPING, 463195740Srwatson#endif 464195740Srwatson ES("Too many processes") }, 465195740Srwatson { BSM_ERRNO_EBADRPC, 466195740Srwatson#ifdef EBADRPC 467195740Srwatson EBADRPC, 468195740Srwatson#else 469195740Srwatson ERRNO_NO_LOCAL_MAPPING, 470195740Srwatson#endif 471195740Srwatson ES("RPC struct is bad") }, 472195740Srwatson { BSM_ERRNO_ERPCMISMATCH, 473195740Srwatson#ifdef ERPCMISMATCH 474195740Srwatson ERPCMISMATCH, 475195740Srwatson#else 476195740Srwatson ERRNO_NO_LOCAL_MAPPING, 477195740Srwatson#endif 478195740Srwatson ES("RPC version wrong") }, 479195740Srwatson { BSM_ERRNO_EPROGUNAVAIL, 480195740Srwatson#ifdef EPROGUNAVAIL 481195740Srwatson EPROGUNAVAIL, 482195740Srwatson#else 483195740Srwatson ERRNO_NO_LOCAL_MAPPING, 484195740Srwatson#endif 485195740Srwatson ES("RPC prog. not avail") }, 486195740Srwatson { BSM_ERRNO_EPROGMISMATCH, 487195740Srwatson#ifdef EPROGMISMATCH 488195740Srwatson EPROGMISMATCH, 489195740Srwatson#else 490195740Srwatson ERRNO_NO_LOCAL_MAPPING, 491195740Srwatson#endif 492195740Srwatson ES("RPC version wrong") }, 493195740Srwatson { BSM_ERRNO_EPROCUNAVAIL, 494195740Srwatson#ifdef EPROCUNAVAIL 495195740Srwatson EPROCUNAVAIL, 496195740Srwatson#else 497243751Srwatson ERRNO_NO_LOCAL_MAPPING, 498195740Srwatson#endif 499195740Srwatson ES("Bad procedure for program") }, 500195740Srwatson { BSM_ERRNO_EFTYPE, 501195740Srwatson#ifdef EFTYPE 502195740Srwatson EFTYPE, 503195740Srwatson#else 504195740Srwatson ERRNO_NO_LOCAL_MAPPING, 505195740Srwatson#endif 506195740Srwatson ES("Inappropriate file type or format") }, 507195740Srwatson { BSM_ERRNO_EAUTH, 508195740Srwatson#ifdef EAUTH 509195740Srwatson EAUTH, 510195740Srwatson#else 511195740Srwatson ERRNO_NO_LOCAL_MAPPING, 512195740Srwatson#endif 513195740Srwatson ES("Authenticateion error") }, 514195740Srwatson { BSM_ERRNO_ENEEDAUTH, 515195740Srwatson#ifdef ENEEDAUTH 516195740Srwatson ENEEDAUTH, 517195740Srwatson#else 518195740Srwatson ERRNO_NO_LOCAL_MAPPING, 519195740Srwatson#endif 520195740Srwatson ES("Need authenticator") }, 521195740Srwatson { BSM_ERRNO_ENOATTR, 522195740Srwatson#ifdef ENOATTR 523195740Srwatson ENOATTR, 524195740Srwatson#else 525195740Srwatson ERRNO_NO_LOCAL_MAPPING, 526195740Srwatson#endif 527195740Srwatson ES("Attribute not found") }, 528195740Srwatson { BSM_ERRNO_EDOOFUS, 529195740Srwatson#ifdef EDOOFUS 530195740Srwatson EDOOFUS, 531195740Srwatson#else 532195740Srwatson ERRNO_NO_LOCAL_MAPPING, 533195740Srwatson#endif 534195740Srwatson ES("Programming error") }, 535195740Srwatson { BSM_ERRNO_EJUSTRETURN, 536195740Srwatson#ifdef EJUSTRETURN 537195740Srwatson EJUSTRETURN, 538195740Srwatson#else 539195740Srwatson ERRNO_NO_LOCAL_MAPPING, 540195740Srwatson#endif 541195740Srwatson ES("Just return") }, 542195740Srwatson { BSM_ERRNO_ENOIOCTL, 543195740Srwatson#ifdef ENOIOCTL 544195740Srwatson ENOIOCTL, 545195740Srwatson#else 546195740Srwatson ERRNO_NO_LOCAL_MAPPING, 547195740Srwatson#endif 548195740Srwatson ES("ioctl not handled by this layer") }, 549195740Srwatson { BSM_ERRNO_EDIRIOCTL, 550195740Srwatson#ifdef EDIRIOCTL 551195740Srwatson EDIRIOCTL, 552195740Srwatson#else 553195740Srwatson ERRNO_NO_LOCAL_MAPPING, 554195740Srwatson#endif 555195740Srwatson ES("do direct ioctl in GEOM") }, 556187214Srwatson { BSM_ERRNO_EPWROFF, 557186647Srwatson#ifdef EPWROFF 558186647Srwatson EPWROFF, 559186647Srwatson#else 560186647Srwatson ERRNO_NO_LOCAL_MAPPING, 561186647Srwatson#endif 562187214Srwatson ES("Device power is off") }, 563187214Srwatson { BSM_ERRNO_EDEVERR, 564186647Srwatson#ifdef EDEVERR 565186647Srwatson EDEVERR, 566186647Srwatson#else 567186647Srwatson ERRNO_NO_LOCAL_MAPPING, 568186647Srwatson#endif 569187214Srwatson ES("Device error") }, 570187214Srwatson { BSM_ERRNO_EBADEXEC, 571186647Srwatson#ifdef EBADEXEC 572186647Srwatson EBADEXEC, 573186647Srwatson#else 574186647Srwatson ERRNO_NO_LOCAL_MAPPING, 575186647Srwatson#endif 576187214Srwatson ES("Bad executable") }, 577187214Srwatson { BSM_ERRNO_EBADARCH, 578186647Srwatson#ifdef EBADARCH 579186647Srwatson EBADARCH, 580186647Srwatson#else 581186647Srwatson ERRNO_NO_LOCAL_MAPPING, 582186647Srwatson#endif 583187214Srwatson ES("Bad CPU type in executable") }, 584187214Srwatson { BSM_ERRNO_ESHLIBVERS, 585186647Srwatson#ifdef ESHLIBVERS 586186647Srwatson ESHLIBVERS, 587186647Srwatson#else 588186647Srwatson ERRNO_NO_LOCAL_MAPPING, 589186647Srwatson#endif 590187214Srwatson ES("Shared library version mismatch") }, 591187214Srwatson { BSM_ERRNO_EBADMACHO, 592186647Srwatson#ifdef EBADMACHO 593186647Srwatson EBADMACHO, 594186647Srwatson#else 595186647Srwatson ERRNO_NO_LOCAL_MAPPING, 596186647Srwatson#endif 597189279Srwatson ES("Malformed Macho file") }, 598187214Srwatson { BSM_ERRNO_EPOLICY, 599186647Srwatson#ifdef EPOLICY 600186647Srwatson EPOLICY, 601186647Srwatson#else 602186647Srwatson ERRNO_NO_LOCAL_MAPPING, 603186647Srwatson#endif 604187214Srwatson ES("Operation failed by policy") }, 605187214Srwatson { BSM_ERRNO_EDOTDOT, 606186647Srwatson#ifdef EDOTDOT 607186647Srwatson EDOTDOT, 608186647Srwatson#else 609186647Srwatson ERRNO_NO_LOCAL_MAPPING, 610186647Srwatson#endif 611187214Srwatson ES("RFS specific error") }, 612187214Srwatson { BSM_ERRNO_EUCLEAN, 613186647Srwatson#ifdef EUCLEAN 614186647Srwatson EUCLEAN, 615186647Srwatson#else 616186647Srwatson ERRNO_NO_LOCAL_MAPPING, 617186647Srwatson#endif 618187214Srwatson ES("Structure needs cleaning") }, 619187214Srwatson { BSM_ERRNO_ENOTNAM, 620186647Srwatson#ifdef ENOTNAM 621186647Srwatson ENOTNAM, 622186647Srwatson#else 623186647Srwatson ERRNO_NO_LOCAL_MAPPING, 624186647Srwatson#endif 625187214Srwatson ES("Not a XENIX named type file") }, 626187214Srwatson { BSM_ERRNO_ENAVAIL, 627186647Srwatson#ifdef ENAVAIL 628186647Srwatson ENAVAIL, 629186647Srwatson#else 630186647Srwatson ERRNO_NO_LOCAL_MAPPING, 631186647Srwatson#endif 632187214Srwatson ES("No XENIX semaphores available") }, 633187214Srwatson { BSM_ERRNO_EISNAM, 634186647Srwatson#ifdef EISNAM 635186647Srwatson EISNAM, 636186647Srwatson#else 637186647Srwatson ERRNO_NO_LOCAL_MAPPING, 638186647Srwatson#endif 639187214Srwatson ES("Is a named type file") }, 640187214Srwatson { BSM_ERRNO_EREMOTEIO, 641186647Srwatson#ifdef EREMOTEIO 642186647Srwatson EREMOTEIO, 643186647Srwatson#else 644186647Srwatson ERRNO_NO_LOCAL_MAPPING, 645186647Srwatson#endif 646187214Srwatson ES("Remote I/O error") }, 647187214Srwatson { BSM_ERRNO_ENOMEDIUM, 648186647Srwatson#ifdef ENOMEDIUM 649186647Srwatson ENOMEDIUM, 650186647Srwatson#else 651186647Srwatson ERRNO_NO_LOCAL_MAPPING, 652186647Srwatson#endif 653187214Srwatson ES("No medium found") }, 654187214Srwatson { BSM_ERRNO_EMEDIUMTYPE, 655186647Srwatson#ifdef EMEDIUMTYPE 656186647Srwatson EMEDIUMTYPE, 657186647Srwatson#else 658186647Srwatson ERRNO_NO_LOCAL_MAPPING, 659186647Srwatson#endif 660187214Srwatson ES("Wrong medium type") }, 661187214Srwatson { BSM_ERRNO_ENOKEY, 662186647Srwatson#ifdef ENOKEY 663186647Srwatson ENOKEY, 664186647Srwatson#else 665186647Srwatson ERRNO_NO_LOCAL_MAPPING, 666186647Srwatson#endif 667187214Srwatson ES("Required key not available") }, 668187214Srwatson { BSM_ERRNO_EKEYEXPIRED, 669243751Srwatson#ifdef EKEYEXPIRED 670186647Srwatson EKEYEXPIRED, 671186647Srwatson#else 672186647Srwatson ERRNO_NO_LOCAL_MAPPING, 673186647Srwatson#endif 674187214Srwatson ES("Key has expired") }, 675187214Srwatson { BSM_ERRNO_EKEYREVOKED, 676186647Srwatson#ifdef EKEYREVOKED 677186647Srwatson EKEYREVOKED, 678186647Srwatson#else 679186647Srwatson ERRNO_NO_LOCAL_MAPPING, 680186647Srwatson#endif 681187214Srwatson ES("Key has been revoked") }, 682187214Srwatson { BSM_ERRNO_EKEYREJECTED, 683243751Srwatson#ifdef EKEYREJECTED 684186647Srwatson EKEYREJECTED, 685186647Srwatson#else 686186647Srwatson ERRNO_NO_LOCAL_MAPPING, 687186647Srwatson#endif 688187214Srwatson ES("Key was rejected by service") }, 689219128Srwatson { BSM_ERRNO_ENOTCAPABLE, 690219128Srwatson#ifdef ENOTCAPABLE 691219128Srwatson ENOTCAPABLE, 692219128Srwatson#else 693219128Srwatson ERRNO_NO_LOCAL_MAPPING, 694219128Srwatson#endif 695219128Srwatson ES("Capabilities insufficient") }, 696219128Srwatson { BSM_ERRNO_ECAPMODE, 697219128Srwatson#ifdef ECAPMODE 698219128Srwatson ECAPMODE, 699219128Srwatson#else 700219128Srwatson ERRNO_NO_LOCAL_MAPPING, 701219128Srwatson#endif 702219128Srwatson ES("Not permitted in capability mode") }, 703186647Srwatson}; 704187214Srwatsonstatic const int bsm_errnos_count = sizeof(bsm_errnos) / sizeof(bsm_errnos[0]); 705186647Srwatson 706187214Srwatsonstatic const struct bsm_errno * 707187214Srwatsonbsm_lookup_errno_local(int local_errno) 708186647Srwatson{ 709186647Srwatson int i; 710186647Srwatson 711187214Srwatson for (i = 0; i < bsm_errnos_count; i++) { 712187214Srwatson if (bsm_errnos[i].be_local_errno == local_errno) 713187214Srwatson return (&bsm_errnos[i]); 714186647Srwatson } 715186647Srwatson return (NULL); 716186647Srwatson} 717186647Srwatson 718187214Srwatson/* 719187214Srwatson * Conversion to the BSM errno space isn't allowed to fail; we simply map to 720187214Srwatson * BSM_ERRNO_UNKNOWN and let the remote endpoint deal with it. 721187214Srwatson */ 722187214Srwatsonu_char 723187214Srwatsonau_errno_to_bsm(int local_errno) 724186647Srwatson{ 725187214Srwatson const struct bsm_errno *bsme; 726187214Srwatson 727187214Srwatson bsme = bsm_lookup_errno_local(local_errno); 728187214Srwatson if (bsme == NULL) 729187214Srwatson return (BSM_ERRNO_UNKNOWN); 730187214Srwatson return (bsme->be_bsm_errno); 731187214Srwatson} 732187214Srwatson 733187214Srwatsonstatic const struct bsm_errno * 734187214Srwatsonbsm_lookup_errno_bsm(u_char bsm_errno) 735187214Srwatson{ 736186647Srwatson int i; 737186647Srwatson 738187214Srwatson for (i = 0; i < bsm_errnos_count; i++) { 739187214Srwatson if (bsm_errnos[i].be_bsm_errno == bsm_errno) 740187214Srwatson return (&bsm_errnos[i]); 741186647Srwatson } 742186647Srwatson return (NULL); 743186647Srwatson} 744186647Srwatson 745186647Srwatson/* 746186647Srwatson * Converstion from a BSM error to a local error number may fail if either 747186647Srwatson * OpenBSM doesn't recognize the error on the wire, or because there is no 748187214Srwatson * appropriate local mapping. 749186647Srwatson */ 750186647Srwatsonint 751187214Srwatsonau_bsm_to_errno(u_char bsm_errno, int *errorp) 752186647Srwatson{ 753187214Srwatson const struct bsm_errno *bsme; 754186647Srwatson 755187214Srwatson bsme = bsm_lookup_errno_bsm(bsm_errno); 756187214Srwatson if (bsme == NULL || bsme->be_local_errno == ERRNO_NO_LOCAL_MAPPING) 757186647Srwatson return (-1); 758187214Srwatson *errorp = bsme->be_local_errno; 759186647Srwatson return (0); 760186647Srwatson} 761186647Srwatson 762186647Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 763186647Srwatsonconst char * 764187214Srwatsonau_strerror(u_char bsm_errno) 765186647Srwatson{ 766187214Srwatson const struct bsm_errno *bsme; 767186647Srwatson 768187214Srwatson bsme = bsm_lookup_errno_bsm(bsm_errno); 769186647Srwatson if (bsme == NULL) 770186647Srwatson return ("Unrecognized BSM error"); 771187214Srwatson if (bsme->be_local_errno != ERRNO_NO_LOCAL_MAPPING) 772187214Srwatson return (strerror(bsme->be_local_errno)); 773186647Srwatson return (bsme->be_strerror); 774186647Srwatson} 775186647Srwatson#endif 776