1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 2001, 2003 Sendmail, Inc. and its suppliers. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5*7c478bd9Sstevel@tonic-gate * Copyright (c) 1988, 1993 6*7c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 7*7c478bd9Sstevel@tonic-gate * 8*7c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 9*7c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 10*7c478bd9Sstevel@tonic-gate * the sendmail distribution. 11*7c478bd9Sstevel@tonic-gate */ 12*7c478bd9Sstevel@tonic-gate 13*7c478bd9Sstevel@tonic-gate #include <sm/gen.h> 14*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: errstring.c,v 1.19 2003/12/10 03:53:05 gshapiro Exp $") 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #include <errno.h> 17*7c478bd9Sstevel@tonic-gate #include <stdio.h> /* sys_errlist, on some platforms */ 18*7c478bd9Sstevel@tonic-gate 19*7c478bd9Sstevel@tonic-gate #include <sm/io.h> /* sm_snprintf */ 20*7c478bd9Sstevel@tonic-gate #include <sm/string.h> 21*7c478bd9Sstevel@tonic-gate #include <sm/errstring.h> 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate #if NAMED_BIND 24*7c478bd9Sstevel@tonic-gate # include <netdb.h> 25*7c478bd9Sstevel@tonic-gate #endif 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #if LDAPMAP 28*7c478bd9Sstevel@tonic-gate # include <lber.h> 29*7c478bd9Sstevel@tonic-gate # include <ldap.h> /* for LDAP error codes */ 30*7c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate ** Notice: this file is used by libmilter. Please try to avoid 34*7c478bd9Sstevel@tonic-gate ** using libsm specific functions. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /* 38*7c478bd9Sstevel@tonic-gate ** SM_ERRSTRING -- return string description of error code 39*7c478bd9Sstevel@tonic-gate ** 40*7c478bd9Sstevel@tonic-gate ** Parameters: 41*7c478bd9Sstevel@tonic-gate ** errnum -- the error number to translate 42*7c478bd9Sstevel@tonic-gate ** 43*7c478bd9Sstevel@tonic-gate ** Returns: 44*7c478bd9Sstevel@tonic-gate ** A string description of errnum. 45*7c478bd9Sstevel@tonic-gate ** 46*7c478bd9Sstevel@tonic-gate ** Note: this may point to a local (static) buffer. 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate const char * 50*7c478bd9Sstevel@tonic-gate sm_errstring(errnum) 51*7c478bd9Sstevel@tonic-gate int errnum; 52*7c478bd9Sstevel@tonic-gate { 53*7c478bd9Sstevel@tonic-gate char *ret; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate switch (errnum) 57*7c478bd9Sstevel@tonic-gate { 58*7c478bd9Sstevel@tonic-gate case EPERM: 59*7c478bd9Sstevel@tonic-gate /* SunOS gives "Not owner" -- this is the POSIX message */ 60*7c478bd9Sstevel@tonic-gate return "Operation not permitted"; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate ** Error messages used internally in sendmail. 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate case E_SM_OPENTIMEOUT: 67*7c478bd9Sstevel@tonic-gate return "Timeout on file open"; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate case E_SM_NOSLINK: 70*7c478bd9Sstevel@tonic-gate return "Symbolic links not allowed"; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate case E_SM_NOHLINK: 73*7c478bd9Sstevel@tonic-gate return "Hard links not allowed"; 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate case E_SM_REGONLY: 76*7c478bd9Sstevel@tonic-gate return "Regular files only"; 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate case E_SM_ISEXEC: 79*7c478bd9Sstevel@tonic-gate return "Executable files not allowed"; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate case E_SM_WWDIR: 82*7c478bd9Sstevel@tonic-gate return "World writable directory"; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate case E_SM_GWDIR: 85*7c478bd9Sstevel@tonic-gate return "Group writable directory"; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate case E_SM_FILECHANGE: 88*7c478bd9Sstevel@tonic-gate return "File changed after open"; 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate case E_SM_WWFILE: 91*7c478bd9Sstevel@tonic-gate return "World writable file"; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate case E_SM_GWFILE: 94*7c478bd9Sstevel@tonic-gate return "Group writable file"; 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate case E_SM_GRFILE: 97*7c478bd9Sstevel@tonic-gate return "Group readable file"; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate case E_SM_WRFILE: 100*7c478bd9Sstevel@tonic-gate return "World readable file"; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate ** DNS error messages. 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #if NAMED_BIND 107*7c478bd9Sstevel@tonic-gate case HOST_NOT_FOUND + E_DNSBASE: 108*7c478bd9Sstevel@tonic-gate return "Name server: host not found"; 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate case TRY_AGAIN + E_DNSBASE: 111*7c478bd9Sstevel@tonic-gate return "Name server: host name lookup failure"; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate case NO_RECOVERY + E_DNSBASE: 114*7c478bd9Sstevel@tonic-gate return "Name server: non-recoverable error"; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate case NO_DATA + E_DNSBASE: 117*7c478bd9Sstevel@tonic-gate return "Name server: no data known"; 118*7c478bd9Sstevel@tonic-gate #endif /* NAMED_BIND */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate /* 121*7c478bd9Sstevel@tonic-gate ** libsmdb error messages. 122*7c478bd9Sstevel@tonic-gate */ 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate case SMDBE_MALLOC: 125*7c478bd9Sstevel@tonic-gate return "Memory allocation failed"; 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate case SMDBE_GDBM_IS_BAD: 128*7c478bd9Sstevel@tonic-gate return "GDBM is not supported"; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate case SMDBE_UNSUPPORTED: 131*7c478bd9Sstevel@tonic-gate return "Unsupported action"; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate case SMDBE_DUPLICATE: 134*7c478bd9Sstevel@tonic-gate return "Key already exists"; 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate case SMDBE_BAD_OPEN: 137*7c478bd9Sstevel@tonic-gate return "Database open failed"; 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate case SMDBE_NOT_FOUND: 140*7c478bd9Sstevel@tonic-gate return "Key not found"; 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate case SMDBE_UNKNOWN_DB_TYPE: 143*7c478bd9Sstevel@tonic-gate return "Unknown database type"; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate case SMDBE_UNSUPPORTED_DB_TYPE: 146*7c478bd9Sstevel@tonic-gate return "Support for database type not compiled into this program"; 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate case SMDBE_INCOMPLETE: 149*7c478bd9Sstevel@tonic-gate return "DB sync did not finish"; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate case SMDBE_KEY_EMPTY: 152*7c478bd9Sstevel@tonic-gate return "Key is empty"; 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate case SMDBE_KEY_EXIST: 155*7c478bd9Sstevel@tonic-gate return "Key already exists"; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate case SMDBE_LOCK_DEADLOCK: 158*7c478bd9Sstevel@tonic-gate return "Locker killed to resolve deadlock"; 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate case SMDBE_LOCK_NOT_GRANTED: 161*7c478bd9Sstevel@tonic-gate return "Lock unavailable"; 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate case SMDBE_LOCK_NOT_HELD: 164*7c478bd9Sstevel@tonic-gate return "Lock not held by locker"; 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate case SMDBE_RUN_RECOVERY: 167*7c478bd9Sstevel@tonic-gate return "Database panic, run recovery"; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate case SMDBE_IO_ERROR: 170*7c478bd9Sstevel@tonic-gate return "I/O error"; 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate case SMDBE_READ_ONLY: 173*7c478bd9Sstevel@tonic-gate return "Database opened read-only"; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate case SMDBE_DB_NAME_TOO_LONG: 176*7c478bd9Sstevel@tonic-gate return "Name too long"; 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate case SMDBE_INVALID_PARAMETER: 179*7c478bd9Sstevel@tonic-gate return "Invalid parameter"; 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate case SMDBE_ONLY_SUPPORTS_ONE_CURSOR: 182*7c478bd9Sstevel@tonic-gate return "Only one cursor allowed"; 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate case SMDBE_NOT_A_VALID_CURSOR: 185*7c478bd9Sstevel@tonic-gate return "Invalid cursor"; 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate case SMDBE_OLD_VERSION: 188*7c478bd9Sstevel@tonic-gate return "Berkeley DB file is an old version, recreate it"; 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate case SMDBE_VERSION_MISMATCH: 191*7c478bd9Sstevel@tonic-gate return "Berkeley DB version mismatch between include file and library"; 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate #if LDAPMAP 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate /* 196*7c478bd9Sstevel@tonic-gate ** LDAP URL error messages. 197*7c478bd9Sstevel@tonic-gate */ 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate /* OpenLDAP errors */ 200*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_MEM 201*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_MEM: 202*7c478bd9Sstevel@tonic-gate return "LDAP URL can't allocate memory space"; 203*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_MEM */ 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_PARAM 206*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_PARAM: 207*7c478bd9Sstevel@tonic-gate return "LDAP URL parameter is bad"; 208*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_PARAM */ 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADSCHEME 211*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADSCHEME: 212*7c478bd9Sstevel@tonic-gate return "LDAP URL doesn't begin with \"ldap[si]://\""; 213*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADSCHEME */ 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADENCLOSURE 216*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADENCLOSURE: 217*7c478bd9Sstevel@tonic-gate return "LDAP URL is missing trailing \">\""; 218*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADENCLOSURE */ 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADURL 221*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADURL: 222*7c478bd9Sstevel@tonic-gate return "LDAP URL is bad"; 223*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADURL */ 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADHOST 226*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADHOST: 227*7c478bd9Sstevel@tonic-gate return "LDAP URL host port is bad"; 228*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADHOST */ 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADATTRS 231*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADATTRS: 232*7c478bd9Sstevel@tonic-gate return "LDAP URL bad (or missing) attributes"; 233*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADATTRS */ 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADSCOPE 236*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADSCOPE: 237*7c478bd9Sstevel@tonic-gate return "LDAP URL scope string is invalid (or missing)"; 238*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADSCOPE */ 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADFILTER 241*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADFILTER: 242*7c478bd9Sstevel@tonic-gate return "LDAP URL bad or missing filter"; 243*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADFILTER */ 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_BADEXTS 246*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_BADEXTS: 247*7c478bd9Sstevel@tonic-gate return "LDAP URL bad or missing extensions"; 248*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_BADEXTS */ 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate /* Sun LDAP errors */ 251*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_NOTLDAP 252*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_NOTLDAP: 253*7c478bd9Sstevel@tonic-gate return "LDAP URL doesn't begin with \"ldap://\""; 254*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_NOTLDAP */ 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate # ifdef LDAP_URL_ERR_NODN 257*7c478bd9Sstevel@tonic-gate case E_LDAPURLBASE + LDAP_URL_ERR_NODN: 258*7c478bd9Sstevel@tonic-gate return "LDAP URL has no DN (required)"; 259*7c478bd9Sstevel@tonic-gate # endif /* LDAP_URL_ERR_NODN */ 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */ 262*7c478bd9Sstevel@tonic-gate } 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate #if LDAPMAP 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate /* 267*7c478bd9Sstevel@tonic-gate ** LDAP error messages. 268*7c478bd9Sstevel@tonic-gate */ 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate if (errnum >= E_LDAPBASE) 271*7c478bd9Sstevel@tonic-gate return ldap_err2string(errnum - E_LDAPBASE); 272*7c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */ 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate ret = strerror(errnum); 275*7c478bd9Sstevel@tonic-gate if (ret == NULL) 276*7c478bd9Sstevel@tonic-gate { 277*7c478bd9Sstevel@tonic-gate static char buf[30]; 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate (void) sm_snprintf(buf, sizeof buf, "Error %d", errnum); 280*7c478bd9Sstevel@tonic-gate return buf; 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate return ret; 283*7c478bd9Sstevel@tonic-gate } 284