1N/A/*
1N/A * Copyright (c) 2001, 2003 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
1N/A * Copyright (c) 1988, 1993
1N/A * The Regents of the University of California. All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_RCSID("@(#)$Id: errstring.c,v 1.19 2003/12/10 03:53:05 gshapiro Exp $")
1N/A
1N/A#include <errno.h>
1N/A#include <stdio.h> /* sys_errlist, on some platforms */
1N/A
1N/A#include <sm/io.h> /* sm_snprintf */
1N/A#include <sm/string.h>
1N/A#include <sm/errstring.h>
1N/A
1N/A#if NAMED_BIND
1N/A# include <netdb.h>
1N/A#endif
1N/A
1N/A#if LDAPMAP
1N/A# include <lber.h>
1N/A# include <ldap.h> /* for LDAP error codes */
1N/A#endif /* LDAPMAP */
1N/A
1N/A/*
1N/A** Notice: this file is used by libmilter. Please try to avoid
1N/A** using libsm specific functions.
1N/A*/
1N/A
1N/A/*
1N/A** SM_ERRSTRING -- return string description of error code
1N/A**
1N/A** Parameters:
1N/A** errnum -- the error number to translate
1N/A**
1N/A** Returns:
1N/A** A string description of errnum.
1N/A**
1N/A** Note: this may point to a local (static) buffer.
1N/A*/
1N/A
1N/Aconst char *
1N/Asm_errstring(errnum)
1N/A int errnum;
1N/A{
1N/A char *ret;
1N/A
1N/A
1N/A switch (errnum)
1N/A {
1N/A case EPERM:
1N/A /* SunOS gives "Not owner" -- this is the POSIX message */
1N/A return "Operation not permitted";
1N/A
1N/A /*
1N/A ** Error messages used internally in sendmail.
1N/A */
1N/A
1N/A case E_SM_OPENTIMEOUT:
1N/A return "Timeout on file open";
1N/A
1N/A case E_SM_NOSLINK:
1N/A return "Symbolic links not allowed";
1N/A
1N/A case E_SM_NOHLINK:
1N/A return "Hard links not allowed";
1N/A
1N/A case E_SM_REGONLY:
1N/A return "Regular files only";
1N/A
1N/A case E_SM_ISEXEC:
1N/A return "Executable files not allowed";
1N/A
1N/A case E_SM_WWDIR:
1N/A return "World writable directory";
1N/A
1N/A case E_SM_GWDIR:
1N/A return "Group writable directory";
1N/A
1N/A case E_SM_FILECHANGE:
1N/A return "File changed after open";
1N/A
1N/A case E_SM_WWFILE:
1N/A return "World writable file";
1N/A
1N/A case E_SM_GWFILE:
1N/A return "Group writable file";
1N/A
1N/A case E_SM_GRFILE:
1N/A return "Group readable file";
1N/A
1N/A case E_SM_WRFILE:
1N/A return "World readable file";
1N/A
1N/A /*
1N/A ** DNS error messages.
1N/A */
1N/A
1N/A#if NAMED_BIND
1N/A case HOST_NOT_FOUND + E_DNSBASE:
1N/A return "Name server: host not found";
1N/A
1N/A case TRY_AGAIN + E_DNSBASE:
1N/A return "Name server: host name lookup failure";
1N/A
1N/A case NO_RECOVERY + E_DNSBASE:
1N/A return "Name server: non-recoverable error";
1N/A
1N/A case NO_DATA + E_DNSBASE:
1N/A return "Name server: no data known";
1N/A#endif /* NAMED_BIND */
1N/A
1N/A /*
1N/A ** libsmdb error messages.
1N/A */
1N/A
1N/A case SMDBE_MALLOC:
1N/A return "Memory allocation failed";
1N/A
1N/A case SMDBE_GDBM_IS_BAD:
1N/A return "GDBM is not supported";
1N/A
1N/A case SMDBE_UNSUPPORTED:
1N/A return "Unsupported action";
1N/A
1N/A case SMDBE_DUPLICATE:
1N/A return "Key already exists";
1N/A
1N/A case SMDBE_BAD_OPEN:
1N/A return "Database open failed";
1N/A
1N/A case SMDBE_NOT_FOUND:
1N/A return "Key not found";
1N/A
1N/A case SMDBE_UNKNOWN_DB_TYPE:
1N/A return "Unknown database type";
1N/A
1N/A case SMDBE_UNSUPPORTED_DB_TYPE:
1N/A return "Support for database type not compiled into this program";
1N/A
1N/A case SMDBE_INCOMPLETE:
1N/A return "DB sync did not finish";
1N/A
1N/A case SMDBE_KEY_EMPTY:
1N/A return "Key is empty";
1N/A
1N/A case SMDBE_KEY_EXIST:
1N/A return "Key already exists";
1N/A
1N/A case SMDBE_LOCK_DEADLOCK:
1N/A return "Locker killed to resolve deadlock";
1N/A
1N/A case SMDBE_LOCK_NOT_GRANTED:
1N/A return "Lock unavailable";
1N/A
1N/A case SMDBE_LOCK_NOT_HELD:
1N/A return "Lock not held by locker";
1N/A
1N/A case SMDBE_RUN_RECOVERY:
1N/A return "Database panic, run recovery";
1N/A
1N/A case SMDBE_IO_ERROR:
1N/A return "I/O error";
1N/A
1N/A case SMDBE_READ_ONLY:
1N/A return "Database opened read-only";
1N/A
1N/A case SMDBE_DB_NAME_TOO_LONG:
1N/A return "Name too long";
1N/A
1N/A case SMDBE_INVALID_PARAMETER:
1N/A return "Invalid parameter";
1N/A
1N/A case SMDBE_ONLY_SUPPORTS_ONE_CURSOR:
1N/A return "Only one cursor allowed";
1N/A
1N/A case SMDBE_NOT_A_VALID_CURSOR:
1N/A return "Invalid cursor";
1N/A
1N/A case SMDBE_OLD_VERSION:
1N/A return "Berkeley DB file is an old version, recreate it";
1N/A
1N/A case SMDBE_VERSION_MISMATCH:
1N/A return "Berkeley DB version mismatch between include file and library";
1N/A
1N/A#if LDAPMAP
1N/A
1N/A /*
1N/A ** LDAP URL error messages.
1N/A */
1N/A
1N/A /* OpenLDAP errors */
1N/A# ifdef LDAP_URL_ERR_MEM
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_MEM:
1N/A return "LDAP URL can't allocate memory space";
1N/A# endif /* LDAP_URL_ERR_MEM */
1N/A
1N/A# ifdef LDAP_URL_ERR_PARAM
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_PARAM:
1N/A return "LDAP URL parameter is bad";
1N/A# endif /* LDAP_URL_ERR_PARAM */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADSCHEME
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADSCHEME:
1N/A return "LDAP URL doesn't begin with \"ldap[si]://\"";
1N/A# endif /* LDAP_URL_ERR_BADSCHEME */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADENCLOSURE
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADENCLOSURE:
1N/A return "LDAP URL is missing trailing \">\"";
1N/A# endif /* LDAP_URL_ERR_BADENCLOSURE */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADURL
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADURL:
1N/A return "LDAP URL is bad";
1N/A# endif /* LDAP_URL_ERR_BADURL */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADHOST
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADHOST:
1N/A return "LDAP URL host port is bad";
1N/A# endif /* LDAP_URL_ERR_BADHOST */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADATTRS
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADATTRS:
1N/A return "LDAP URL bad (or missing) attributes";
1N/A# endif /* LDAP_URL_ERR_BADATTRS */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADSCOPE
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADSCOPE:
1N/A return "LDAP URL scope string is invalid (or missing)";
1N/A# endif /* LDAP_URL_ERR_BADSCOPE */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADFILTER
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADFILTER:
1N/A return "LDAP URL bad or missing filter";
1N/A# endif /* LDAP_URL_ERR_BADFILTER */
1N/A
1N/A# ifdef LDAP_URL_ERR_BADEXTS
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_BADEXTS:
1N/A return "LDAP URL bad or missing extensions";
1N/A# endif /* LDAP_URL_ERR_BADEXTS */
1N/A
1N/A /* Sun LDAP errors */
1N/A# ifdef LDAP_URL_ERR_NOTLDAP
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_NOTLDAP:
1N/A return "LDAP URL doesn't begin with \"ldap://\"";
1N/A# endif /* LDAP_URL_ERR_NOTLDAP */
1N/A
1N/A# ifdef LDAP_URL_ERR_NODN
1N/A case E_LDAPURLBASE + LDAP_URL_ERR_NODN:
1N/A return "LDAP URL has no DN (required)";
1N/A# endif /* LDAP_URL_ERR_NODN */
1N/A
1N/A#endif /* LDAPMAP */
1N/A }
1N/A
1N/A#if LDAPMAP
1N/A
1N/A /*
1N/A ** LDAP error messages.
1N/A */
1N/A
1N/A if (errnum >= E_LDAPBASE)
1N/A return ldap_err2string(errnum - E_LDAPBASE);
1N/A#endif /* LDAPMAP */
1N/A
1N/A ret = strerror(errnum);
1N/A if (ret == NULL)
1N/A {
1N/A static char buf[30];
1N/A
1N/A (void) sm_snprintf(buf, sizeof buf, "Error %d", errnum);
1N/A return buf;
1N/A }
1N/A return ret;
1N/A}