bsm_errno.c revision 186647
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 * 29186647Srwatson * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#12 30186647Srwatson */ 31186647Srwatson 32186647Srwatson#include <sys/cdefs.h> 33186647Srwatson__FBSDID("$FreeBSD: head/sys/security/audit/audit_bsm_errno.c 186647 2008-12-31 11:12:24Z rwatson $"); 34186647Srwatson 35186647Srwatson#include <sys/types.h> 36186647Srwatson 37186647Srwatson#include <bsm/audit_errno.h> 38186647Srwatson#include <bsm/libbsm.h> 39186647Srwatson 40186647Srwatson#include <sys/errno.h> 41186647Srwatson 42186647Srwatson/* 43186647Srwatson * Different operating systems use different numeric constants for different 44186647Srwatson * error numbers, and sometimes error numbers don't exist in more than one 45186647Srwatson * operating system. These routines convert between BSM and local error 46186647Srwatson * number spaces, subject to the above realities. BSM error numbers are 47186647Srwatson * stored in a single 8-bit character, so don't have a byte order. 48186647Srwatson */ 49186647Srwatson 50186647Srwatsonstruct bsm_errors { 51186647Srwatson int be_bsm_error; 52186647Srwatson int be_os_error; 53186647Srwatson const char *be_strerror; 54186647Srwatson}; 55186647Srwatson 56186647Srwatson#define ERRNO_NO_LOCAL_MAPPING -600 57186647Srwatson 58186647Srwatson/* 59186647Srwatson * Mapping table -- please maintain in numeric sorted order with respect to 60186647Srwatson * the BSM constant. Today we do a linear lookup, but could switch to a 61186647Srwatson * binary search if it makes sense. We only ifdef errors that aren't 62186647Srwatson * generally available, but it does make the table a lot more ugly. 63186647Srwatson * 64186647Srwatson * XXXRW: It would be nice to have a similar ordered table mapping to BSM 65186647Srwatson * constant from local constant, but the order of local constants varies by 66186647Srwatson * OS. Really we need to build that table at compile-time but don't do that 67186647Srwatson * yet. 68186647Srwatson * 69186647Srwatson * XXXRW: We currently embed English-language error strings here, but should 70186647Srwatson * support catalogues; these are only used if the OS doesn't have an error 71186647Srwatson * string using strerror(3). 72186647Srwatson */ 73186647Srwatsonstatic const struct bsm_errors bsm_errors[] = { 74186647Srwatson { BSM_ESUCCESS, 0, "Success" }, 75186647Srwatson { BSM_EPERM, EPERM, "Operation not permitted" }, 76186647Srwatson { BSM_ENOENT, ENOENT, "No such file or directory" }, 77186647Srwatson { BSM_ESRCH, ESRCH, "No such process" }, 78186647Srwatson { BSM_EINTR, EINTR, "Interrupted system call" }, 79186647Srwatson { BSM_EIO, EIO, "Input/output error" }, 80186647Srwatson { BSM_ENXIO, ENXIO, "Device not configured" }, 81186647Srwatson { BSM_E2BIG, E2BIG, "Argument list too long" }, 82186647Srwatson { BSM_ENOEXEC, ENOEXEC, "Exec format error" }, 83186647Srwatson { BSM_EBADF, EBADF, "BAd file descriptor" }, 84186647Srwatson { BSM_ECHILD, ECHILD, "No child processes" }, 85186647Srwatson { BSM_EAGAIN, EAGAIN, "Resource temporarily unavailable" }, 86186647Srwatson { BSM_ENOMEM, ENOMEM, "Cannot allocate memory" }, 87186647Srwatson { BSM_EACCES, EACCES, "Permission denied" }, 88186647Srwatson { BSM_EFAULT, EFAULT, "Bad address" }, 89186647Srwatson { BSM_ENOTBLK, ENOTBLK, "Block device required" }, 90186647Srwatson { BSM_EBUSY, EBUSY, "Device busy" }, 91186647Srwatson { BSM_EEXIST, EEXIST, "File exists" }, 92186647Srwatson { BSM_EXDEV, EXDEV, "Cross-device link" }, 93186647Srwatson { BSM_ENODEV, ENODEV, "Operation not supported by device" }, 94186647Srwatson { BSM_ENOTDIR, ENOTDIR, "Not a directory" }, 95186647Srwatson { BSM_EISDIR, EISDIR, "Is a directory" }, 96186647Srwatson { BSM_EINVAL, EINVAL, "Invalid argument" }, 97186647Srwatson { BSM_ENFILE, ENFILE, "Too many open files in system" }, 98186647Srwatson { BSM_EMFILE, EMFILE, "Too many open files" }, 99186647Srwatson { BSM_ENOTTY, ENOTTY, "Inappropriate ioctl for device" }, 100186647Srwatson { BSM_ETXTBSY, ETXTBSY, "Text file busy" }, 101186647Srwatson { BSM_EFBIG, EFBIG, "File too large" }, 102186647Srwatson { BSM_ENOSPC, ENOSPC, "No space left on device" }, 103186647Srwatson { BSM_ESPIPE, ESPIPE, "Illegal seek" }, 104186647Srwatson { BSM_EROFS, EROFS, "Read-only file system" }, 105186647Srwatson { BSM_EMLINK, EMLINK, "Too many links" }, 106186647Srwatson { BSM_EPIPE, EPIPE, "Broken pipe" }, 107186647Srwatson { BSM_EDOM, EDOM, "Numerical argument out of domain" }, 108186647Srwatson { BSM_ERANGE, ERANGE, "Result too large" }, 109186647Srwatson { BSM_ENOMSG, ENOMSG, "No message of desired type" }, 110186647Srwatson { BSM_EIDRM, EIDRM, "Identifier removed" }, 111186647Srwatson { BSM_ECHRNG, 112186647Srwatson#ifdef ECHRNG 113186647Srwatson ECHRNG, 114186647Srwatson#else 115186647Srwatson ERRNO_NO_LOCAL_MAPPING, 116186647Srwatson#endif 117186647Srwatson "Channel number out of range" }, 118186647Srwatson { BSM_EL2NSYNC, 119186647Srwatson#ifdef EL2NSYNC 120186647Srwatson EL2NSYNC, 121186647Srwatson#else 122186647Srwatson ERRNO_NO_LOCAL_MAPPING, 123186647Srwatson#endif 124186647Srwatson "Level 2 not synchronized" }, 125186647Srwatson { BSM_EL3HLT, 126186647Srwatson#ifdef EL3HLT 127186647Srwatson EL3HLT, 128186647Srwatson#else 129186647Srwatson ERRNO_NO_LOCAL_MAPPING, 130186647Srwatson#endif 131186647Srwatson "Level 3 halted" }, 132186647Srwatson { BSM_EL3RST, 133186647Srwatson#ifdef EL3RST 134186647Srwatson EL3RST, 135186647Srwatson#else 136186647Srwatson ERRNO_NO_LOCAL_MAPPING, 137186647Srwatson#endif 138186647Srwatson "Level 3 reset" }, 139186647Srwatson { BSM_ELNRNG, 140186647Srwatson#ifdef ELNRNG 141186647Srwatson ELNRNG, 142186647Srwatson#else 143186647Srwatson ERRNO_NO_LOCAL_MAPPING, 144186647Srwatson#endif 145186647Srwatson "Link number out of range" }, 146186647Srwatson { BSM_EUNATCH, 147186647Srwatson#ifdef EUNATCH 148186647Srwatson EUNATCH, 149186647Srwatson#else 150186647Srwatson ERRNO_NO_LOCAL_MAPPING, 151186647Srwatson#endif 152186647Srwatson "Protocol driver not attached" }, 153186647Srwatson { BSM_ENOCSI, 154186647Srwatson#ifdef ENOCSI 155186647Srwatson ENOCSI, 156186647Srwatson#else 157186647Srwatson ERRNO_NO_LOCAL_MAPPING, 158186647Srwatson#endif 159186647Srwatson "No CSI structure available" }, 160186647Srwatson { BSM_EL2HLT, 161186647Srwatson#ifdef EL2HLT 162186647Srwatson EL2HLT, 163186647Srwatson#else 164186647Srwatson ERRNO_NO_LOCAL_MAPPING, 165186647Srwatson#endif 166186647Srwatson "Level 2 halted" }, 167186647Srwatson { BSM_EDEADLK, EDEADLK, "Resource deadlock avoided" }, 168186647Srwatson { BSM_ENOLCK, ENOLCK, "No locks available" }, 169186647Srwatson { BSM_ECANCELED, ECANCELED, "Operation canceled" }, 170186647Srwatson { BSM_ENOTSUP, ENOTSUP, "Operation not supported" }, 171186647Srwatson { BSM_EDQUOT, EDQUOT, "Disc quota exceeded" }, 172186647Srwatson { BSM_EBADE, 173186647Srwatson#ifdef EBADE 174186647Srwatson EBADE, 175186647Srwatson#else 176186647Srwatson ERRNO_NO_LOCAL_MAPPING, 177186647Srwatson#endif 178186647Srwatson "Invalid exchange" }, 179186647Srwatson { BSM_EBADR, 180186647Srwatson#ifdef EBADR 181186647Srwatson EBADR, 182186647Srwatson#else 183186647Srwatson ERRNO_NO_LOCAL_MAPPING, 184186647Srwatson#endif 185186647Srwatson "Invalid request descriptor" }, 186186647Srwatson { BSM_EXFULL, 187186647Srwatson#ifdef EXFULL 188186647Srwatson EXFULL, 189186647Srwatson#else 190186647Srwatson ERRNO_NO_LOCAL_MAPPING, 191186647Srwatson#endif 192186647Srwatson "Exchange full" }, 193186647Srwatson { BSM_ENOANO, 194186647Srwatson#ifdef ENOANO 195186647Srwatson ENOANO, 196186647Srwatson#else 197186647Srwatson ERRNO_NO_LOCAL_MAPPING, 198186647Srwatson#endif 199186647Srwatson "No anode" }, 200186647Srwatson { BSM_EBADRQC, 201186647Srwatson#ifdef EBADRQC 202186647Srwatson EBADRQC, 203186647Srwatson#else 204186647Srwatson ERRNO_NO_LOCAL_MAPPING, 205186647Srwatson#endif 206186647Srwatson "Invalid request descriptor" }, 207186647Srwatson { BSM_EBADSLT, 208186647Srwatson#ifdef EBADSLT 209186647Srwatson EBADSLT, 210186647Srwatson#else 211186647Srwatson ERRNO_NO_LOCAL_MAPPING, 212186647Srwatson#endif 213186647Srwatson "Invalid slot" }, 214186647Srwatson { BSM_EDEADLOCK, 215186647Srwatson#ifdef EDEADLOCK 216186647Srwatson EDEADLOCK, 217186647Srwatson#else 218186647Srwatson ERRNO_NO_LOCAL_MAPPING, 219186647Srwatson#endif 220186647Srwatson "Resource deadlock avoided" }, 221186647Srwatson { BSM_EBFONT, 222186647Srwatson#ifdef EBFONT 223186647Srwatson EBFONT, 224186647Srwatson#else 225186647Srwatson ERRNO_NO_LOCAL_MAPPING, 226186647Srwatson#endif 227186647Srwatson "Bad font file format" }, 228186647Srwatson { BSM_EOWNERDEAD, 229186647Srwatson#ifdef EOWNERDEAD 230186647Srwatson EOWNERDEAD, 231186647Srwatson#else 232186647Srwatson ERRNO_NO_LOCAL_MAPPING, 233186647Srwatson#endif 234186647Srwatson "Process died with the lock" }, 235186647Srwatson { BSM_ENOTRECOVERABLE, 236186647Srwatson#ifdef ENOTRECOVERABLE 237186647Srwatson ENOTRECOVERABLE, 238186647Srwatson#else 239186647Srwatson ERRNO_NO_LOCAL_MAPPING, 240186647Srwatson#endif 241186647Srwatson "Lock is not recoverable" }, 242186647Srwatson { BSM_ENOSTR, 243186647Srwatson#ifdef ENOSTR 244186647Srwatson ENOSTR, 245186647Srwatson#else 246186647Srwatson ERRNO_NO_LOCAL_MAPPING, 247186647Srwatson#endif 248186647Srwatson "Device not a stream" }, 249186647Srwatson { BSM_ENONET, 250186647Srwatson#ifdef ENONET 251186647Srwatson ENONET, 252186647Srwatson#else 253186647Srwatson ERRNO_NO_LOCAL_MAPPING, 254186647Srwatson#endif 255186647Srwatson "Machine is not on the network" }, 256186647Srwatson { BSM_ENOPKG, 257186647Srwatson#ifdef ENOPKG 258186647Srwatson ENOPKG, 259186647Srwatson#else 260186647Srwatson ERRNO_NO_LOCAL_MAPPING, 261186647Srwatson#endif 262186647Srwatson "Package not installed" }, 263186647Srwatson { BSM_EREMOTE, EREMOTE, "Too many levels of remote in path" }, 264186647Srwatson { BSM_ENOLINK, 265186647Srwatson#ifdef ENOLINK 266186647Srwatson ENOLINK, 267186647Srwatson#else 268186647Srwatson ERRNO_NO_LOCAL_MAPPING, 269186647Srwatson#endif 270186647Srwatson "Link has been severed" }, 271186647Srwatson { BSM_EADV, 272186647Srwatson#ifdef EADV 273186647Srwatson EADV, 274186647Srwatson#else 275186647Srwatson ERRNO_NO_LOCAL_MAPPING, 276186647Srwatson#endif 277186647Srwatson "Advertise error" }, 278186647Srwatson { BSM_ESRMNT, 279186647Srwatson#ifdef ESRMNT 280186647Srwatson ESRMNT, 281186647Srwatson#else 282186647Srwatson ERRNO_NO_LOCAL_MAPPING, 283186647Srwatson#endif 284186647Srwatson "srmount error" }, 285186647Srwatson { BSM_ECOMM, 286186647Srwatson#ifdef ECOMM 287186647Srwatson ECOMM, 288186647Srwatson#else 289186647Srwatson ERRNO_NO_LOCAL_MAPPING, 290186647Srwatson#endif 291186647Srwatson "Communication error on send" }, 292186647Srwatson { BSM_EPROTO, 293186647Srwatson#ifdef EPROTO 294186647Srwatson EPROTO, 295186647Srwatson#else 296186647Srwatson ERRNO_NO_LOCAL_MAPPING, 297186647Srwatson#endif 298186647Srwatson "Protocol error" }, 299186647Srwatson { BSM_ELOCKUNMAPPED, 300186647Srwatson#ifdef ELOCKUNMAPPED 301186647Srwatson ELOCKUNMAPPED, 302186647Srwatson#else 303186647Srwatson ERRNO_NO_LOCAL_MAPPING, 304186647Srwatson#endif 305186647Srwatson "Locked lock was unmapped" }, 306186647Srwatson { BSM_ENOTACTIVE, 307186647Srwatson#ifdef ENOTACTIVE 308186647Srwatson ENOTACTIVE, 309186647Srwatson#else 310186647Srwatson ERRNO_NO_LOCAL_MAPPING, 311186647Srwatson#endif 312186647Srwatson "Facility is not active" }, 313186647Srwatson { BSM_EMULTIHOP, 314186647Srwatson#ifdef EMULTIHOP 315186647Srwatson EMULTIHOP, 316186647Srwatson#else 317186647Srwatson ERRNO_NO_LOCAL_MAPPING, 318186647Srwatson#endif 319186647Srwatson "Multihop attempted" }, 320186647Srwatson { BSM_EBADMSG, 321186647Srwatson#ifdef EBADMSG 322186647Srwatson EBADMSG, 323186647Srwatson#else 324186647Srwatson ERRNO_NO_LOCAL_MAPPING, 325186647Srwatson#endif 326186647Srwatson "Bad message" }, 327186647Srwatson { BSM_ENAMETOOLONG, ENAMETOOLONG, "File name too long" }, 328186647Srwatson { BSM_EOVERFLOW, EOVERFLOW, "Value too large to be stored in data type" }, 329186647Srwatson { BSM_ENOTUNIQ, 330186647Srwatson#ifdef ENOTUNIQ 331186647Srwatson ENOTUNIQ, 332186647Srwatson#else 333186647Srwatson ERRNO_NO_LOCAL_MAPPING, 334186647Srwatson#endif 335186647Srwatson "Given log name not unique" }, 336186647Srwatson { BSM_EBADFD, 337186647Srwatson#ifdef EBADFD 338186647Srwatson EBADFD, 339186647Srwatson#else 340186647Srwatson ERRNO_NO_LOCAL_MAPPING, 341186647Srwatson#endif 342186647Srwatson "Given f.d. invalid for this operation" }, 343186647Srwatson { BSM_EREMCHG, 344186647Srwatson#ifdef EREMCHG 345186647Srwatson EREMCHG, 346186647Srwatson#else 347186647Srwatson ERRNO_NO_LOCAL_MAPPING, 348186647Srwatson#endif 349186647Srwatson "Remote address changed" }, 350186647Srwatson { BSM_ELIBACC, 351186647Srwatson#ifdef ELIBACC 352186647Srwatson ELIBACC, 353186647Srwatson#else 354186647Srwatson ERRNO_NO_LOCAL_MAPPING, 355186647Srwatson#endif 356186647Srwatson "Can't access a needed shared lib" }, 357186647Srwatson { BSM_ELIBBAD, 358186647Srwatson#ifdef ELIBBAD 359186647Srwatson ELIBBAD, 360186647Srwatson#else 361186647Srwatson ERRNO_NO_LOCAL_MAPPING, 362186647Srwatson#endif 363186647Srwatson "Accessing a corrupted shared lib" }, 364186647Srwatson { BSM_ELIBSCN, 365186647Srwatson#ifdef ELIBSCN 366186647Srwatson ELIBSCN, 367186647Srwatson#else 368186647Srwatson ERRNO_NO_LOCAL_MAPPING, 369186647Srwatson#endif 370186647Srwatson ".lib section in a.out corrupted" }, 371186647Srwatson { BSM_ELIBMAX, 372186647Srwatson#ifdef ELIBMAX 373186647Srwatson ELIBMAX, 374186647Srwatson#else 375186647Srwatson ERRNO_NO_LOCAL_MAPPING, 376186647Srwatson#endif 377186647Srwatson "Attempting to link in too many libs" }, 378186647Srwatson { BSM_ELIBEXEC, 379186647Srwatson#ifdef ELIBEXEC 380186647Srwatson ELIBEXEC, 381186647Srwatson#else 382186647Srwatson ERRNO_NO_LOCAL_MAPPING, 383186647Srwatson#endif 384186647Srwatson "Attempting to exec a shared library" }, 385186647Srwatson { BSM_EILSEQ, EILSEQ, "Illegal byte sequence" }, 386186647Srwatson { BSM_ENOSYS, ENOSYS, "Function not implemented" }, 387186647Srwatson { BSM_ELOOP, ELOOP, "Too many levels of symbolic links" }, 388186647Srwatson { BSM_ERESTART, 389186647Srwatson#ifdef ERESTART 390186647Srwatson ERESTART, 391186647Srwatson#else 392186647Srwatson ERRNO_NO_LOCAL_MAPPING, 393186647Srwatson#endif 394186647Srwatson "Restart syscall" }, 395186647Srwatson { BSM_ESTRPIPE, 396186647Srwatson#ifdef ESTRPIPE 397186647Srwatson ESTRPIPE, 398186647Srwatson#else 399186647Srwatson ERRNO_NO_LOCAL_MAPPING, 400186647Srwatson#endif 401186647Srwatson "If pipe/FIFO, don't sleep in stream head" }, 402186647Srwatson { BSM_ENOTEMPTY, ENOTEMPTY, "Directory not empty" }, 403186647Srwatson { BSM_EUSERS, EUSERS, "Too many users" }, 404186647Srwatson { BSM_ENOTSOCK, ENOTSOCK, "Socket operation on non-socket" }, 405186647Srwatson { BSM_EDESTADDRREQ, EDESTADDRREQ, "Destination address required" }, 406186647Srwatson { BSM_EMSGSIZE, EMSGSIZE, "Message too long" }, 407186647Srwatson { BSM_EPROTOTYPE, EPROTOTYPE, "Protocol wrong type for socket" }, 408186647Srwatson { BSM_ENOPROTOOPT, ENOPROTOOPT, "Protocol not available" }, 409186647Srwatson { BSM_EPROTONOSUPPORT, EPROTONOSUPPORT, "Protocol not supported" }, 410186647Srwatson { BSM_ESOCKTNOSUPPORT, ESOCKTNOSUPPORT, "Socket type not supported" }, 411186647Srwatson { BSM_EOPNOTSUPP, EOPNOTSUPP, "Operation not supported" }, 412186647Srwatson { BSM_EPFNOSUPPORT, EPFNOSUPPORT, "Protocol family not supported" }, 413186647Srwatson { BSM_EAFNOSUPPORT, EAFNOSUPPORT, "Address family not supported by protocol family" }, 414186647Srwatson { BSM_EADDRINUSE, EADDRINUSE, "Address already in use" }, 415186647Srwatson { BSM_EADDRNOTAVAIL, EADDRNOTAVAIL, "Can't assign requested address" }, 416186647Srwatson { BSM_ENETDOWN, ENETDOWN, "Network is down" }, 417186647Srwatson { BSM_ENETRESET, ENETRESET, "Network dropped connection on reset" }, 418186647Srwatson { BSM_ECONNABORTED, ECONNABORTED, "Software caused connection abort" }, 419186647Srwatson { BSM_ECONNRESET, ECONNRESET, "Connection reset by peer" }, 420186647Srwatson { BSM_ENOBUFS, ENOBUFS, "No buffer space available" }, 421186647Srwatson { BSM_EISCONN, EISCONN, "Socket is already connected" }, 422186647Srwatson { BSM_ENOTCONN, ENOTCONN, "Socket is not connected" }, 423186647Srwatson { BSM_ESHUTDOWN, ESHUTDOWN, "Can't send after socket shutdown" }, 424186647Srwatson { BSM_ETOOMANYREFS, ETOOMANYREFS, "Too many references: can't splice" }, 425186647Srwatson { BSM_ETIMEDOUT, ETIMEDOUT, "Operation timed out" }, 426186647Srwatson { BSM_ECONNREFUSED, ECONNREFUSED, "Connection refused" }, 427186647Srwatson { BSM_EHOSTDOWN, EHOSTDOWN, "Host is down" }, 428186647Srwatson { BSM_EHOSTUNREACH, EHOSTUNREACH, "No route to host" }, 429186647Srwatson { BSM_EALREADY, EALREADY, "Operation already in progress" }, 430186647Srwatson { BSM_EINPROGRESS, EINPROGRESS, "Operation now in progress" }, 431186647Srwatson { BSM_ESTALE, ESTALE, "Stale NFS file handle" }, 432186647Srwatson { BSM_EPWROFF, 433186647Srwatson#ifdef EPWROFF 434186647Srwatson EPWROFF, 435186647Srwatson#else 436186647Srwatson ERRNO_NO_LOCAL_MAPPING, 437186647Srwatson#endif 438186647Srwatson "Device power is off" }, 439186647Srwatson { BSM_EDEVERR, 440186647Srwatson#ifdef EDEVERR 441186647Srwatson EDEVERR, 442186647Srwatson#else 443186647Srwatson ERRNO_NO_LOCAL_MAPPING, 444186647Srwatson#endif 445186647Srwatson "Device error" }, 446186647Srwatson { BSM_EBADEXEC, 447186647Srwatson#ifdef EBADEXEC 448186647Srwatson EBADEXEC, 449186647Srwatson#else 450186647Srwatson ERRNO_NO_LOCAL_MAPPING, 451186647Srwatson#endif 452186647Srwatson "Bad executable" }, 453186647Srwatson { BSM_EBADARCH, 454186647Srwatson#ifdef EBADARCH 455186647Srwatson EBADARCH, 456186647Srwatson#else 457186647Srwatson ERRNO_NO_LOCAL_MAPPING, 458186647Srwatson#endif 459186647Srwatson "Bad CPU type in executable" }, 460186647Srwatson { BSM_ESHLIBVERS, 461186647Srwatson#ifdef ESHLIBVERS 462186647Srwatson ESHLIBVERS, 463186647Srwatson#else 464186647Srwatson ERRNO_NO_LOCAL_MAPPING, 465186647Srwatson#endif 466186647Srwatson "Shared library version mismatch" }, 467186647Srwatson { BSM_EBADMACHO, 468186647Srwatson#ifdef EBADMACHO 469186647Srwatson EBADMACHO, 470186647Srwatson#else 471186647Srwatson ERRNO_NO_LOCAL_MAPPING, 472186647Srwatson#endif 473186647Srwatson "Malfored Macho file" }, 474186647Srwatson { BSM_EPOLICY, 475186647Srwatson#ifdef EPOLICY 476186647Srwatson EPOLICY, 477186647Srwatson#else 478186647Srwatson ERRNO_NO_LOCAL_MAPPING, 479186647Srwatson#endif 480186647Srwatson "Operation failed by policy" }, 481186647Srwatson { BSM_EDOTDOT, 482186647Srwatson#ifdef EDOTDOT 483186647Srwatson EDOTDOT, 484186647Srwatson#else 485186647Srwatson ERRNO_NO_LOCAL_MAPPING, 486186647Srwatson#endif 487186647Srwatson "RFS specific error" }, 488186647Srwatson { BSM_EUCLEAN, 489186647Srwatson#ifdef EUCLEAN 490186647Srwatson EUCLEAN, 491186647Srwatson#else 492186647Srwatson ERRNO_NO_LOCAL_MAPPING, 493186647Srwatson#endif 494186647Srwatson "Structure needs cleaning" }, 495186647Srwatson { BSM_ENOTNAM, 496186647Srwatson#ifdef ENOTNAM 497186647Srwatson ENOTNAM, 498186647Srwatson#else 499186647Srwatson ERRNO_NO_LOCAL_MAPPING, 500186647Srwatson#endif 501186647Srwatson "Not a XENIX named type file" }, 502186647Srwatson { BSM_ENAVAIL, 503186647Srwatson#ifdef ENAVAIL 504186647Srwatson ENAVAIL, 505186647Srwatson#else 506186647Srwatson ERRNO_NO_LOCAL_MAPPING, 507186647Srwatson#endif 508186647Srwatson "No XENIX semaphores available" }, 509186647Srwatson { BSM_EISNAM, 510186647Srwatson#ifdef EISNAM 511186647Srwatson EISNAM, 512186647Srwatson#else 513186647Srwatson ERRNO_NO_LOCAL_MAPPING, 514186647Srwatson#endif 515186647Srwatson "Is a named type file" }, 516186647Srwatson { BSM_EREMOTEIO, 517186647Srwatson#ifdef EREMOTEIO 518186647Srwatson EREMOTEIO, 519186647Srwatson#else 520186647Srwatson ERRNO_NO_LOCAL_MAPPING, 521186647Srwatson#endif 522186647Srwatson "Remote I/O error" }, 523186647Srwatson { BSM_ENOMEDIUM, 524186647Srwatson#ifdef ENOMEDIUM 525186647Srwatson ENOMEDIUM, 526186647Srwatson#else 527186647Srwatson ERRNO_NO_LOCAL_MAPPING, 528186647Srwatson#endif 529186647Srwatson "No medium found" }, 530186647Srwatson { BSM_EMEDIUMTYPE, 531186647Srwatson#ifdef EMEDIUMTYPE 532186647Srwatson EMEDIUMTYPE, 533186647Srwatson#else 534186647Srwatson ERRNO_NO_LOCAL_MAPPING, 535186647Srwatson#endif 536186647Srwatson "Wrong medium type" }, 537186647Srwatson { BSM_ENOKEY, 538186647Srwatson#ifdef ENOKEY 539186647Srwatson ENOKEY, 540186647Srwatson#else 541186647Srwatson ERRNO_NO_LOCAL_MAPPING, 542186647Srwatson#endif 543186647Srwatson "Required key not available" }, 544186647Srwatson { BSM_EKEYEXPIRED, 545186647Srwatson#ifdef EKEEXPIRED 546186647Srwatson EKEYEXPIRED, 547186647Srwatson#else 548186647Srwatson ERRNO_NO_LOCAL_MAPPING, 549186647Srwatson#endif 550186647Srwatson "Key has expired" }, 551186647Srwatson { BSM_EKEYREVOKED, 552186647Srwatson#ifdef EKEYREVOKED 553186647Srwatson EKEYREVOKED, 554186647Srwatson#else 555186647Srwatson ERRNO_NO_LOCAL_MAPPING, 556186647Srwatson#endif 557186647Srwatson "Key has been revoked" }, 558186647Srwatson { BSM_EKEYREJECTED, 559186647Srwatson#ifdef EKEREJECTED 560186647Srwatson EKEYREJECTED, 561186647Srwatson#else 562186647Srwatson ERRNO_NO_LOCAL_MAPPING, 563186647Srwatson#endif 564186647Srwatson "Key was rejected by service" }, 565186647Srwatson}; 566186647Srwatsonstatic const int bsm_errors_count = sizeof(bsm_errors) / sizeof(bsm_errors[0]); 567186647Srwatson 568186647Srwatsonstatic const struct bsm_errors * 569186647Srwatsonau_bsm_error_lookup_errno(int error) 570186647Srwatson{ 571186647Srwatson int i; 572186647Srwatson 573186647Srwatson if (error == ERRNO_NO_LOCAL_MAPPING) 574186647Srwatson return (NULL); 575186647Srwatson for (i = 0; i < bsm_errors_count; i++) { 576186647Srwatson if (bsm_errors[i].be_os_error == error) 577186647Srwatson return (&bsm_errors[i]); 578186647Srwatson } 579186647Srwatson return (NULL); 580186647Srwatson} 581186647Srwatson 582186647Srwatsonstatic const struct bsm_errors * 583186647Srwatsonau_bsm_error_lookup_bsm(u_char bsm_error) 584186647Srwatson{ 585186647Srwatson int i; 586186647Srwatson 587186647Srwatson for (i = 0; i < bsm_errors_count; i++) { 588186647Srwatson if (bsm_errors[i].be_bsm_error == bsm_error) 589186647Srwatson return (&bsm_errors[i]); 590186647Srwatson } 591186647Srwatson return (NULL); 592186647Srwatson} 593186647Srwatson 594186647Srwatson/* 595186647Srwatson * Converstion from a BSM error to a local error number may fail if either 596186647Srwatson * OpenBSM doesn't recognize the error on the wire, or because there is no 597186647Srwatson * appropriate local mapping. However, we don't allow conversion to BSM to 598186647Srwatson * fail, we just convert to BSM_UKNOWNERR. 599186647Srwatson */ 600186647Srwatsonint 601186647Srwatsonau_bsm_to_errno(u_char bsm_error, int *errorp) 602186647Srwatson{ 603186647Srwatson const struct bsm_errors *bsme; 604186647Srwatson 605186647Srwatson bsme = au_bsm_error_lookup_bsm(bsm_error); 606186647Srwatson if (bsme == NULL || bsme->be_os_error == ERRNO_NO_LOCAL_MAPPING) 607186647Srwatson return (-1); 608186647Srwatson *errorp = bsme->be_os_error; 609186647Srwatson return (0); 610186647Srwatson} 611186647Srwatson 612186647Srwatsonu_char 613186647Srwatsonau_errno_to_bsm(int error) 614186647Srwatson{ 615186647Srwatson const struct bsm_errors *bsme; 616186647Srwatson 617186647Srwatson /* 618186647Srwatson * We should never be passed this libbsm-internal constant, and 619186647Srwatson * because it is ambiguous we just return an error. 620186647Srwatson */ 621186647Srwatson if (error == ERRNO_NO_LOCAL_MAPPING) 622186647Srwatson return (BSM_UNKNOWNERR); 623186647Srwatson bsme = au_bsm_error_lookup_errno(error); 624186647Srwatson if (bsme == NULL) 625186647Srwatson return (BSM_UNKNOWNERR); 626186647Srwatson return (bsme->be_bsm_error); 627186647Srwatson} 628186647Srwatson 629186647Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 630186647Srwatsonconst char * 631186647Srwatsonau_strerror(u_char bsm_error) 632186647Srwatson{ 633186647Srwatson const struct bsm_errors *bsme; 634186647Srwatson 635186647Srwatson bsme = au_bsm_error_lookup_bsm(bsm_error); 636186647Srwatson if (bsme == NULL) 637186647Srwatson return ("Unrecognized BSM error"); 638186647Srwatson if (bsme->be_os_error != ERRNO_NO_LOCAL_MAPPING) 639186647Srwatson return (strerror(bsme->be_os_error)); 640186647Srwatson return (bsme->be_strerror); 641186647Srwatson} 642186647Srwatson#endif 643