1*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 2*7c478bd9Sstevel@tonic-gate 3*7c478bd9Sstevel@tonic-gate /* 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public 5*7c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file 6*7c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of 7*7c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/ 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS 10*7c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11*7c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing 12*7c478bd9Sstevel@tonic-gate * rights and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released 15*7c478bd9Sstevel@tonic-gate * March 31, 1998. 16*7c478bd9Sstevel@tonic-gate * 17*7c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape 18*7c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are 19*7c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All 20*7c478bd9Sstevel@tonic-gate * Rights Reserved. 21*7c478bd9Sstevel@tonic-gate * 22*7c478bd9Sstevel@tonic-gate * Contributor(s): 23*7c478bd9Sstevel@tonic-gate */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate /* 26*7c478bd9Sstevel@tonic-gate * Utilities for manageing the relationship between NSPR errors and 27*7c478bd9Sstevel@tonic-gate * OS (errno-style) errors. 28*7c478bd9Sstevel@tonic-gate * 29*7c478bd9Sstevel@tonic-gate * The overall strategy used is to map NSPR errors into OS errors. 30*7c478bd9Sstevel@tonic-gate */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include "ldappr-int.h" 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate void 36*7c478bd9Sstevel@tonic-gate prldap_set_system_errno( int oserrno ) 37*7c478bd9Sstevel@tonic-gate { 38*7c478bd9Sstevel@tonic-gate PR_SetError( PR_UNKNOWN_ERROR, oserrno ); 39*7c478bd9Sstevel@tonic-gate } 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate int 43*7c478bd9Sstevel@tonic-gate prldap_get_system_errno( void ) 44*7c478bd9Sstevel@tonic-gate { 45*7c478bd9Sstevel@tonic-gate return( PR_GetOSError()); 46*7c478bd9Sstevel@tonic-gate } 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate /* 49*7c478bd9Sstevel@tonic-gate * Retrieve the NSPR error number, convert to a system error code, and return 50*7c478bd9Sstevel@tonic-gate * the result. 51*7c478bd9Sstevel@tonic-gate */ 52*7c478bd9Sstevel@tonic-gate struct prldap_errormap_entry { 53*7c478bd9Sstevel@tonic-gate PRInt32 erm_nspr; /* NSPR error code */ 54*7c478bd9Sstevel@tonic-gate int erm_system; /* corresponding system error code */ 55*7c478bd9Sstevel@tonic-gate }; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* XXX: not sure if this extra mapping for Windows is good or correct */ 58*7c478bd9Sstevel@tonic-gate #ifdef _WINDOWS 59*7c478bd9Sstevel@tonic-gate #ifndef ENOTSUP 60*7c478bd9Sstevel@tonic-gate #define ENOTSUP -1 61*7c478bd9Sstevel@tonic-gate #endif 62*7c478bd9Sstevel@tonic-gate #ifndef ETIMEDOUT 63*7c478bd9Sstevel@tonic-gate #define ETIMEDOUT WSAETIMEDOUT 64*7c478bd9Sstevel@tonic-gate #endif 65*7c478bd9Sstevel@tonic-gate #ifndef EADDRNOTAVAIL 66*7c478bd9Sstevel@tonic-gate #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 67*7c478bd9Sstevel@tonic-gate #endif 68*7c478bd9Sstevel@tonic-gate #ifndef EAFNOSUPPORT 69*7c478bd9Sstevel@tonic-gate #define EAFNOSUPPORT WSAEAFNOSUPPORT 70*7c478bd9Sstevel@tonic-gate #endif 71*7c478bd9Sstevel@tonic-gate #ifndef EISCONN 72*7c478bd9Sstevel@tonic-gate #define EISCONN WSAEISCONN 73*7c478bd9Sstevel@tonic-gate #endif 74*7c478bd9Sstevel@tonic-gate #ifndef EADDRINUSE 75*7c478bd9Sstevel@tonic-gate #define EADDRINUSE WSAEADDRINUSE 76*7c478bd9Sstevel@tonic-gate #endif 77*7c478bd9Sstevel@tonic-gate #ifndef ECONNREFUSED 78*7c478bd9Sstevel@tonic-gate #define ECONNREFUSED WSAECONNREFUSED 79*7c478bd9Sstevel@tonic-gate #endif 80*7c478bd9Sstevel@tonic-gate #ifndef EHOSTUNREACH 81*7c478bd9Sstevel@tonic-gate #define EHOSTUNREACH WSAEHOSTUNREACH 82*7c478bd9Sstevel@tonic-gate #endif 83*7c478bd9Sstevel@tonic-gate #ifndef ENOTCONN 84*7c478bd9Sstevel@tonic-gate #define ENOTCONN WSAENOTCONN 85*7c478bd9Sstevel@tonic-gate #endif 86*7c478bd9Sstevel@tonic-gate #ifndef ENOTSOCK 87*7c478bd9Sstevel@tonic-gate #define ENOTSOCK WSAENOTSOCK 88*7c478bd9Sstevel@tonic-gate #endif 89*7c478bd9Sstevel@tonic-gate #ifndef EPROTOTYPE 90*7c478bd9Sstevel@tonic-gate #define EPROTOTYPE WSAEPROTOTYPE 91*7c478bd9Sstevel@tonic-gate #endif 92*7c478bd9Sstevel@tonic-gate #ifndef EOPNOTSUPP 93*7c478bd9Sstevel@tonic-gate #define EOPNOTSUPP WSAEOPNOTSUPP 94*7c478bd9Sstevel@tonic-gate #endif 95*7c478bd9Sstevel@tonic-gate #ifndef EPROTONOSUPPORT 96*7c478bd9Sstevel@tonic-gate #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 97*7c478bd9Sstevel@tonic-gate #endif 98*7c478bd9Sstevel@tonic-gate #ifndef EOVERFLOW 99*7c478bd9Sstevel@tonic-gate #define EOVERFLOW -1 100*7c478bd9Sstevel@tonic-gate #endif 101*7c478bd9Sstevel@tonic-gate #ifndef ECONNRESET 102*7c478bd9Sstevel@tonic-gate #define ECONNRESET WSAECONNRESET 103*7c478bd9Sstevel@tonic-gate #endif 104*7c478bd9Sstevel@tonic-gate #ifndef ELOOP 105*7c478bd9Sstevel@tonic-gate #define ELOOP WSAELOOP 106*7c478bd9Sstevel@tonic-gate #endif 107*7c478bd9Sstevel@tonic-gate #ifndef ENOTBLK 108*7c478bd9Sstevel@tonic-gate #define ENOTBLK -1 109*7c478bd9Sstevel@tonic-gate #endif 110*7c478bd9Sstevel@tonic-gate #ifndef ETXTBSY 111*7c478bd9Sstevel@tonic-gate #define ETXTBSY -1 112*7c478bd9Sstevel@tonic-gate #endif 113*7c478bd9Sstevel@tonic-gate #ifndef ENETDOWN 114*7c478bd9Sstevel@tonic-gate #define ENETDOWN WSAENETDOWN 115*7c478bd9Sstevel@tonic-gate #endif 116*7c478bd9Sstevel@tonic-gate #ifndef ESHUTDOWN 117*7c478bd9Sstevel@tonic-gate #define ESHUTDOWN WSAESHUTDOWN 118*7c478bd9Sstevel@tonic-gate #endif 119*7c478bd9Sstevel@tonic-gate #ifndef ECONNABORTED 120*7c478bd9Sstevel@tonic-gate #define ECONNABORTED WSAECONNABORTED 121*7c478bd9Sstevel@tonic-gate #endif 122*7c478bd9Sstevel@tonic-gate #endif /* _WINDOWS */ 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /* XXX: need to verify that the -1 entries are correct (no mapping) */ 125*7c478bd9Sstevel@tonic-gate static struct prldap_errormap_entry prldap_errormap[] = { 126*7c478bd9Sstevel@tonic-gate { PR_OUT_OF_MEMORY_ERROR, ENOMEM }, 127*7c478bd9Sstevel@tonic-gate { PR_BAD_DESCRIPTOR_ERROR, EBADF }, 128*7c478bd9Sstevel@tonic-gate { PR_WOULD_BLOCK_ERROR, EAGAIN }, 129*7c478bd9Sstevel@tonic-gate { PR_ACCESS_FAULT_ERROR, EFAULT }, 130*7c478bd9Sstevel@tonic-gate { PR_INVALID_METHOD_ERROR, EINVAL }, /* XXX: correct mapping ? */ 131*7c478bd9Sstevel@tonic-gate { PR_ILLEGAL_ACCESS_ERROR, EACCES }, /* XXX: correct mapping ? */ 132*7c478bd9Sstevel@tonic-gate { PR_UNKNOWN_ERROR, -1 }, 133*7c478bd9Sstevel@tonic-gate { PR_PENDING_INTERRUPT_ERROR, -1 }, 134*7c478bd9Sstevel@tonic-gate { PR_NOT_IMPLEMENTED_ERROR, ENOTSUP }, 135*7c478bd9Sstevel@tonic-gate { PR_IO_ERROR, EIO }, 136*7c478bd9Sstevel@tonic-gate { PR_IO_TIMEOUT_ERROR, ETIMEDOUT }, /* XXX: correct mapping ? */ 137*7c478bd9Sstevel@tonic-gate { PR_IO_PENDING_ERROR, -1 }, 138*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_OPEN_ERROR, ENOTDIR }, 139*7c478bd9Sstevel@tonic-gate { PR_INVALID_ARGUMENT_ERROR, EINVAL }, 140*7c478bd9Sstevel@tonic-gate { PR_ADDRESS_NOT_AVAILABLE_ERROR, EADDRNOTAVAIL }, 141*7c478bd9Sstevel@tonic-gate { PR_ADDRESS_NOT_SUPPORTED_ERROR, EAFNOSUPPORT }, 142*7c478bd9Sstevel@tonic-gate { PR_IS_CONNECTED_ERROR, EISCONN }, 143*7c478bd9Sstevel@tonic-gate { PR_BAD_ADDRESS_ERROR, EFAULT }, /* XXX: correct mapping ? */ 144*7c478bd9Sstevel@tonic-gate { PR_ADDRESS_IN_USE_ERROR, EADDRINUSE }, 145*7c478bd9Sstevel@tonic-gate { PR_CONNECT_REFUSED_ERROR, ECONNREFUSED }, 146*7c478bd9Sstevel@tonic-gate { PR_NETWORK_UNREACHABLE_ERROR, EHOSTUNREACH }, 147*7c478bd9Sstevel@tonic-gate { PR_CONNECT_TIMEOUT_ERROR, ETIMEDOUT }, 148*7c478bd9Sstevel@tonic-gate { PR_NOT_CONNECTED_ERROR, ENOTCONN }, 149*7c478bd9Sstevel@tonic-gate { PR_LOAD_LIBRARY_ERROR, -1 }, 150*7c478bd9Sstevel@tonic-gate { PR_UNLOAD_LIBRARY_ERROR, -1 }, 151*7c478bd9Sstevel@tonic-gate { PR_FIND_SYMBOL_ERROR, -1 }, 152*7c478bd9Sstevel@tonic-gate { PR_INSUFFICIENT_RESOURCES_ERROR, -1 }, 153*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_LOOKUP_ERROR, -1 }, 154*7c478bd9Sstevel@tonic-gate { PR_TPD_RANGE_ERROR, -1 }, 155*7c478bd9Sstevel@tonic-gate { PR_PROC_DESC_TABLE_FULL_ERROR, -1 }, 156*7c478bd9Sstevel@tonic-gate { PR_SYS_DESC_TABLE_FULL_ERROR, -1 }, 157*7c478bd9Sstevel@tonic-gate { PR_NOT_SOCKET_ERROR, ENOTSOCK }, 158*7c478bd9Sstevel@tonic-gate { PR_NOT_TCP_SOCKET_ERROR, EPROTOTYPE }, 159*7c478bd9Sstevel@tonic-gate { PR_SOCKET_ADDRESS_IS_BOUND_ERROR, -1 }, 160*7c478bd9Sstevel@tonic-gate { PR_NO_ACCESS_RIGHTS_ERROR, EACCES }, /* XXX: correct mapping ? */ 161*7c478bd9Sstevel@tonic-gate { PR_OPERATION_NOT_SUPPORTED_ERROR, EOPNOTSUPP }, 162*7c478bd9Sstevel@tonic-gate { PR_PROTOCOL_NOT_SUPPORTED_ERROR, EPROTONOSUPPORT }, 163*7c478bd9Sstevel@tonic-gate { PR_REMOTE_FILE_ERROR, -1 }, 164*7c478bd9Sstevel@tonic-gate #if defined(OSF1) 165*7c478bd9Sstevel@tonic-gate { PR_BUFFER_OVERFLOW_ERROR, -1 }, 166*7c478bd9Sstevel@tonic-gate #else 167*7c478bd9Sstevel@tonic-gate { PR_BUFFER_OVERFLOW_ERROR, EOVERFLOW }, 168*7c478bd9Sstevel@tonic-gate #endif /* OSF1 */ 169*7c478bd9Sstevel@tonic-gate { PR_CONNECT_RESET_ERROR, ECONNRESET }, 170*7c478bd9Sstevel@tonic-gate { PR_RANGE_ERROR, ERANGE }, 171*7c478bd9Sstevel@tonic-gate { PR_DEADLOCK_ERROR, EDEADLK }, 172*7c478bd9Sstevel@tonic-gate #if defined(HPUX11) || defined(AIX4_3) || defined(OSF1) 173*7c478bd9Sstevel@tonic-gate { PR_FILE_IS_LOCKED_ERROR, -1 }, /* XXX: correct mapping ? */ 174*7c478bd9Sstevel@tonic-gate #else 175*7c478bd9Sstevel@tonic-gate { PR_FILE_IS_LOCKED_ERROR, EDEADLOCK }, /* XXX: correct mapping ? */ 176*7c478bd9Sstevel@tonic-gate #endif /* HPUX11 */ 177*7c478bd9Sstevel@tonic-gate { PR_FILE_TOO_BIG_ERROR, EFBIG }, 178*7c478bd9Sstevel@tonic-gate { PR_NO_DEVICE_SPACE_ERROR, ENOSPC }, 179*7c478bd9Sstevel@tonic-gate { PR_PIPE_ERROR, EPIPE }, 180*7c478bd9Sstevel@tonic-gate { PR_NO_SEEK_DEVICE_ERROR, ESPIPE }, 181*7c478bd9Sstevel@tonic-gate { PR_IS_DIRECTORY_ERROR, EISDIR }, 182*7c478bd9Sstevel@tonic-gate { PR_LOOP_ERROR, ELOOP }, 183*7c478bd9Sstevel@tonic-gate { PR_NAME_TOO_LONG_ERROR, ENAMETOOLONG }, 184*7c478bd9Sstevel@tonic-gate { PR_FILE_NOT_FOUND_ERROR, ENOENT }, 185*7c478bd9Sstevel@tonic-gate { PR_NOT_DIRECTORY_ERROR, ENOTDIR }, 186*7c478bd9Sstevel@tonic-gate { PR_READ_ONLY_FILESYSTEM_ERROR, EROFS }, 187*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_NOT_EMPTY_ERROR, ENOTEMPTY }, 188*7c478bd9Sstevel@tonic-gate { PR_FILESYSTEM_MOUNTED_ERROR, EBUSY }, 189*7c478bd9Sstevel@tonic-gate { PR_NOT_SAME_DEVICE_ERROR, EXDEV }, 190*7c478bd9Sstevel@tonic-gate { PR_DIRECTORY_CORRUPTED_ERROR, -1 }, 191*7c478bd9Sstevel@tonic-gate { PR_FILE_EXISTS_ERROR, EEXIST }, 192*7c478bd9Sstevel@tonic-gate { PR_MAX_DIRECTORY_ENTRIES_ERROR, -1 }, 193*7c478bd9Sstevel@tonic-gate { PR_INVALID_DEVICE_STATE_ERROR, ENOTBLK }, /* XXX: correct mapping ? */ 194*7c478bd9Sstevel@tonic-gate { PR_DEVICE_IS_LOCKED_ERROR, -2 }, 195*7c478bd9Sstevel@tonic-gate { PR_NO_MORE_FILES_ERROR, ENFILE }, 196*7c478bd9Sstevel@tonic-gate { PR_END_OF_FILE_ERROR, -1 }, 197*7c478bd9Sstevel@tonic-gate { PR_FILE_SEEK_ERROR, ESPIPE }, /* XXX: correct mapping ? */ 198*7c478bd9Sstevel@tonic-gate { PR_FILE_IS_BUSY_ERROR, ETXTBSY }, 199*7c478bd9Sstevel@tonic-gate { PR_OPERATION_ABORTED_ERROR, -1 }, 200*7c478bd9Sstevel@tonic-gate { PR_IN_PROGRESS_ERROR, -1 }, 201*7c478bd9Sstevel@tonic-gate { PR_ALREADY_INITIATED_ERROR, -1 }, 202*7c478bd9Sstevel@tonic-gate { PR_GROUP_EMPTY_ERROR, -1 }, 203*7c478bd9Sstevel@tonic-gate { PR_INVALID_STATE_ERROR, -1 }, 204*7c478bd9Sstevel@tonic-gate { PR_NETWORK_DOWN_ERROR, ENETDOWN }, 205*7c478bd9Sstevel@tonic-gate { PR_SOCKET_SHUTDOWN_ERROR, ESHUTDOWN }, 206*7c478bd9Sstevel@tonic-gate { PR_CONNECT_ABORTED_ERROR, ECONNABORTED }, 207*7c478bd9Sstevel@tonic-gate { PR_HOST_UNREACHABLE_ERROR, EHOSTUNREACH }, 208*7c478bd9Sstevel@tonic-gate { PR_MAX_ERROR, -1 }, 209*7c478bd9Sstevel@tonic-gate }; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate int 213*7c478bd9Sstevel@tonic-gate prldap_prerr2errno( void ) 214*7c478bd9Sstevel@tonic-gate { 215*7c478bd9Sstevel@tonic-gate int oserr, i; 216*7c478bd9Sstevel@tonic-gate PRInt32 nsprerr; 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate nsprerr = PR_GetError(); 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate oserr = -1; /* unknown */ 221*7c478bd9Sstevel@tonic-gate for ( i = 0; prldap_errormap[i].erm_nspr != PR_MAX_ERROR; ++i ) { 222*7c478bd9Sstevel@tonic-gate if ( prldap_errormap[i].erm_nspr == nsprerr ) { 223*7c478bd9Sstevel@tonic-gate oserr = prldap_errormap[i].erm_system; 224*7c478bd9Sstevel@tonic-gate break; 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate return( oserr ); 229*7c478bd9Sstevel@tonic-gate } 230