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