bsm_errno.c revision 187214
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 187214 2009-01-14 10:44:16Z 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. 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") }, 458187214Srwatson { BSM_ERRNO_EPWROFF, 459186647Srwatson#ifdef EPWROFF 460186647Srwatson EPWROFF, 461186647Srwatson#else 462186647Srwatson ERRNO_NO_LOCAL_MAPPING, 463186647Srwatson#endif 464187214Srwatson ES("Device power is off") }, 465187214Srwatson { BSM_ERRNO_EDEVERR, 466186647Srwatson#ifdef EDEVERR 467186647Srwatson EDEVERR, 468186647Srwatson#else 469186647Srwatson ERRNO_NO_LOCAL_MAPPING, 470186647Srwatson#endif 471187214Srwatson ES("Device error") }, 472187214Srwatson { BSM_ERRNO_EBADEXEC, 473186647Srwatson#ifdef EBADEXEC 474186647Srwatson EBADEXEC, 475186647Srwatson#else 476186647Srwatson ERRNO_NO_LOCAL_MAPPING, 477186647Srwatson#endif 478187214Srwatson ES("Bad executable") }, 479187214Srwatson { BSM_ERRNO_EBADARCH, 480186647Srwatson#ifdef EBADARCH 481186647Srwatson EBADARCH, 482186647Srwatson#else 483186647Srwatson ERRNO_NO_LOCAL_MAPPING, 484186647Srwatson#endif 485187214Srwatson ES("Bad CPU type in executable") }, 486187214Srwatson { BSM_ERRNO_ESHLIBVERS, 487186647Srwatson#ifdef ESHLIBVERS 488186647Srwatson ESHLIBVERS, 489186647Srwatson#else 490186647Srwatson ERRNO_NO_LOCAL_MAPPING, 491186647Srwatson#endif 492187214Srwatson ES("Shared library version mismatch") }, 493187214Srwatson { BSM_ERRNO_EBADMACHO, 494186647Srwatson#ifdef EBADMACHO 495186647Srwatson EBADMACHO, 496186647Srwatson#else 497186647Srwatson ERRNO_NO_LOCAL_MAPPING, 498186647Srwatson#endif 499187214Srwatson ES("Malfored Macho file") }, 500187214Srwatson { BSM_ERRNO_EPOLICY, 501186647Srwatson#ifdef EPOLICY 502186647Srwatson EPOLICY, 503186647Srwatson#else 504186647Srwatson ERRNO_NO_LOCAL_MAPPING, 505186647Srwatson#endif 506187214Srwatson ES("Operation failed by policy") }, 507187214Srwatson { BSM_ERRNO_EDOTDOT, 508186647Srwatson#ifdef EDOTDOT 509186647Srwatson EDOTDOT, 510186647Srwatson#else 511186647Srwatson ERRNO_NO_LOCAL_MAPPING, 512186647Srwatson#endif 513187214Srwatson ES("RFS specific error") }, 514187214Srwatson { BSM_ERRNO_EUCLEAN, 515186647Srwatson#ifdef EUCLEAN 516186647Srwatson EUCLEAN, 517186647Srwatson#else 518186647Srwatson ERRNO_NO_LOCAL_MAPPING, 519186647Srwatson#endif 520187214Srwatson ES("Structure needs cleaning") }, 521187214Srwatson { BSM_ERRNO_ENOTNAM, 522186647Srwatson#ifdef ENOTNAM 523186647Srwatson ENOTNAM, 524186647Srwatson#else 525186647Srwatson ERRNO_NO_LOCAL_MAPPING, 526186647Srwatson#endif 527187214Srwatson ES("Not a XENIX named type file") }, 528187214Srwatson { BSM_ERRNO_ENAVAIL, 529186647Srwatson#ifdef ENAVAIL 530186647Srwatson ENAVAIL, 531186647Srwatson#else 532186647Srwatson ERRNO_NO_LOCAL_MAPPING, 533186647Srwatson#endif 534187214Srwatson ES("No XENIX semaphores available") }, 535187214Srwatson { BSM_ERRNO_EISNAM, 536186647Srwatson#ifdef EISNAM 537186647Srwatson EISNAM, 538186647Srwatson#else 539186647Srwatson ERRNO_NO_LOCAL_MAPPING, 540186647Srwatson#endif 541187214Srwatson ES("Is a named type file") }, 542187214Srwatson { BSM_ERRNO_EREMOTEIO, 543186647Srwatson#ifdef EREMOTEIO 544186647Srwatson EREMOTEIO, 545186647Srwatson#else 546186647Srwatson ERRNO_NO_LOCAL_MAPPING, 547186647Srwatson#endif 548187214Srwatson ES("Remote I/O error") }, 549187214Srwatson { BSM_ERRNO_ENOMEDIUM, 550186647Srwatson#ifdef ENOMEDIUM 551186647Srwatson ENOMEDIUM, 552186647Srwatson#else 553186647Srwatson ERRNO_NO_LOCAL_MAPPING, 554186647Srwatson#endif 555187214Srwatson ES("No medium found") }, 556187214Srwatson { BSM_ERRNO_EMEDIUMTYPE, 557186647Srwatson#ifdef EMEDIUMTYPE 558186647Srwatson EMEDIUMTYPE, 559186647Srwatson#else 560186647Srwatson ERRNO_NO_LOCAL_MAPPING, 561186647Srwatson#endif 562187214Srwatson ES("Wrong medium type") }, 563187214Srwatson { BSM_ERRNO_ENOKEY, 564186647Srwatson#ifdef ENOKEY 565186647Srwatson ENOKEY, 566186647Srwatson#else 567186647Srwatson ERRNO_NO_LOCAL_MAPPING, 568186647Srwatson#endif 569187214Srwatson ES("Required key not available") }, 570187214Srwatson { BSM_ERRNO_EKEYEXPIRED, 571186647Srwatson#ifdef EKEEXPIRED 572186647Srwatson EKEYEXPIRED, 573186647Srwatson#else 574186647Srwatson ERRNO_NO_LOCAL_MAPPING, 575186647Srwatson#endif 576187214Srwatson ES("Key has expired") }, 577187214Srwatson { BSM_ERRNO_EKEYREVOKED, 578186647Srwatson#ifdef EKEYREVOKED 579186647Srwatson EKEYREVOKED, 580186647Srwatson#else 581186647Srwatson ERRNO_NO_LOCAL_MAPPING, 582186647Srwatson#endif 583187214Srwatson ES("Key has been revoked") }, 584187214Srwatson { BSM_ERRNO_EKEYREJECTED, 585186647Srwatson#ifdef EKEREJECTED 586186647Srwatson EKEYREJECTED, 587186647Srwatson#else 588186647Srwatson ERRNO_NO_LOCAL_MAPPING, 589186647Srwatson#endif 590187214Srwatson ES("Key was rejected by service") }, 591186647Srwatson}; 592187214Srwatsonstatic const int bsm_errnos_count = sizeof(bsm_errnos) / sizeof(bsm_errnos[0]); 593186647Srwatson 594187214Srwatsonstatic const struct bsm_errno * 595187214Srwatsonbsm_lookup_errno_local(int local_errno) 596186647Srwatson{ 597186647Srwatson int i; 598186647Srwatson 599187214Srwatson for (i = 0; i < bsm_errnos_count; i++) { 600187214Srwatson if (bsm_errnos[i].be_local_errno == local_errno) 601187214Srwatson return (&bsm_errnos[i]); 602186647Srwatson } 603186647Srwatson return (NULL); 604186647Srwatson} 605186647Srwatson 606187214Srwatson/* 607187214Srwatson * Conversion to the BSM errno space isn't allowed to fail; we simply map to 608187214Srwatson * BSM_ERRNO_UNKNOWN and let the remote endpoint deal with it. 609187214Srwatson */ 610187214Srwatsonu_char 611187214Srwatsonau_errno_to_bsm(int local_errno) 612186647Srwatson{ 613187214Srwatson const struct bsm_errno *bsme; 614187214Srwatson 615187214Srwatson bsme = bsm_lookup_errno_local(local_errno); 616187214Srwatson if (bsme == NULL) 617187214Srwatson return (BSM_ERRNO_UNKNOWN); 618187214Srwatson return (bsme->be_bsm_errno); 619187214Srwatson} 620187214Srwatson 621187214Srwatsonstatic const struct bsm_errno * 622187214Srwatsonbsm_lookup_errno_bsm(u_char bsm_errno) 623187214Srwatson{ 624186647Srwatson int i; 625186647Srwatson 626187214Srwatson for (i = 0; i < bsm_errnos_count; i++) { 627187214Srwatson if (bsm_errnos[i].be_bsm_errno == bsm_errno) 628187214Srwatson return (&bsm_errnos[i]); 629186647Srwatson } 630186647Srwatson return (NULL); 631186647Srwatson} 632186647Srwatson 633186647Srwatson/* 634186647Srwatson * Converstion from a BSM error to a local error number may fail if either 635186647Srwatson * OpenBSM doesn't recognize the error on the wire, or because there is no 636187214Srwatson * appropriate local mapping. 637186647Srwatson */ 638186647Srwatsonint 639187214Srwatsonau_bsm_to_errno(u_char bsm_errno, int *errorp) 640186647Srwatson{ 641187214Srwatson const struct bsm_errno *bsme; 642186647Srwatson 643187214Srwatson bsme = bsm_lookup_errno_bsm(bsm_errno); 644187214Srwatson if (bsme == NULL || bsme->be_local_errno == ERRNO_NO_LOCAL_MAPPING) 645186647Srwatson return (-1); 646187214Srwatson *errorp = bsme->be_local_errno; 647186647Srwatson return (0); 648186647Srwatson} 649186647Srwatson 650186647Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 651186647Srwatsonconst char * 652187214Srwatsonau_strerror(u_char bsm_errno) 653186647Srwatson{ 654187214Srwatson const struct bsm_errno *bsme; 655186647Srwatson 656187214Srwatson bsme = bsm_lookup_errno_bsm(bsm_errno); 657186647Srwatson if (bsme == NULL) 658186647Srwatson return ("Unrecognized BSM error"); 659187214Srwatson if (bsme->be_local_errno != ERRNO_NO_LOCAL_MAPPING) 660187214Srwatson return (strerror(bsme->be_local_errno)); 661186647Srwatson return (bsme->be_strerror); 662186647Srwatson} 663186647Srwatson#endif 664