errstring.c revision 95154
1/*
2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
3 *	All rights reserved.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5 * Copyright (c) 1988, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 */
12
13#include <sm/gen.h>
14SM_RCSID("@(#)$Id: errstring.c,v 1.1.1.1 2002/02/17 21:56:43 gshapiro Exp $")
15
16#include <errno.h>
17#include <stdio.h>	/* sys_errlist, on some platforms */
18
19#include <sm/io.h>	/* sm_snprintf */
20#include <sm/string.h>
21#include <sm/errstring.h>
22
23#if NAMED_BIND
24# include <netdb.h>
25#endif
26
27#if LDAPMAP
28# include <lber.h>
29# include <ldap.h>			/* for LDAP error codes */
30#endif /* LDAPMAP */
31
32/*
33**  Notice: this file is used by libmilter. Please try to avoid
34**	using libsm specific functions.
35*/
36
37/*
38**  SM_ERRSTRING -- return string description of error code
39**
40**	Parameters:
41**		errnum -- the error number to translate
42**
43**	Returns:
44**		A string description of errnum.
45*/
46
47const char *
48sm_errstring(errnum)
49	int errnum;
50{
51	char *ret;
52
53	switch (errnum)
54	{
55	  case EPERM:
56		/* SunOS gives "Not owner" -- this is the POSIX message */
57		return "Operation not permitted";
58
59	/*
60	**  Error messages used internally in sendmail.
61	*/
62
63	  case E_SM_OPENTIMEOUT:
64		return "Timeout on file open";
65
66	  case E_SM_NOSLINK:
67		return "Symbolic links not allowed";
68
69	  case E_SM_NOHLINK:
70		return "Hard links not allowed";
71
72	  case E_SM_REGONLY:
73		return "Regular files only";
74
75	  case E_SM_ISEXEC:
76		return "Executable files not allowed";
77
78	  case E_SM_WWDIR:
79		return "World writable directory";
80
81	  case E_SM_GWDIR:
82		return "Group writable directory";
83
84	  case E_SM_FILECHANGE:
85		return "File changed after open";
86
87	  case E_SM_WWFILE:
88		return "World writable file";
89
90	  case E_SM_GWFILE:
91		return "Group writable file";
92
93	  case E_SM_GRFILE:
94		return "Group readable file";
95
96	  case E_SM_WRFILE:
97		return "World readable file";
98
99	/*
100	**  DNS error messages.
101	*/
102
103#if NAMED_BIND
104	  case HOST_NOT_FOUND + E_DNSBASE:
105		return "Name server: host not found";
106
107	  case TRY_AGAIN + E_DNSBASE:
108		return "Name server: host name lookup failure";
109
110	  case NO_RECOVERY + E_DNSBASE:
111		return "Name server: non-recoverable error";
112
113	  case NO_DATA + E_DNSBASE:
114		return "Name server: no data known";
115#endif /* NAMED_BIND */
116
117	/*
118	**  libsmdb error messages.
119	*/
120
121	  case SMDBE_MALLOC:
122		return "Memory allocation failed";
123
124	  case SMDBE_GDBM_IS_BAD:
125		return "GDBM is not supported";
126
127	  case SMDBE_UNSUPPORTED:
128		return "Unsupported action";
129
130	  case SMDBE_DUPLICATE:
131		return "Key already exists";
132
133	  case SMDBE_BAD_OPEN:
134		return "Database open failed";
135
136	  case SMDBE_NOT_FOUND:
137		return "Key not found";
138
139	  case SMDBE_UNKNOWN_DB_TYPE:
140		return "Unknown database type";
141
142	  case SMDBE_UNSUPPORTED_DB_TYPE:
143		return "Support for database type not compiled into this program";
144
145	  case SMDBE_INCOMPLETE:
146		return "DB sync did not finish";
147
148	  case SMDBE_KEY_EMPTY:
149		return "Key is empty";
150
151	  case SMDBE_KEY_EXIST:
152		return "Key already exists";
153
154	  case SMDBE_LOCK_DEADLOCK:
155		return "Locker killed to resolve deadlock";
156
157	  case SMDBE_LOCK_NOT_GRANTED:
158		return "Lock unavailable";
159
160	  case SMDBE_LOCK_NOT_HELD:
161		return "Lock not held by locker";
162
163	  case SMDBE_RUN_RECOVERY:
164		return "Database panic, run recovery";
165
166	  case SMDBE_IO_ERROR:
167		return "I/O error";
168
169	  case SMDBE_READ_ONLY:
170		return "Database opened read-only";
171
172	  case SMDBE_DB_NAME_TOO_LONG:
173		return "Name too long";
174
175	  case SMDBE_INVALID_PARAMETER:
176		return "Invalid parameter";
177
178	  case SMDBE_ONLY_SUPPORTS_ONE_CURSOR:
179		return "Only one cursor allowed";
180
181	  case SMDBE_NOT_A_VALID_CURSOR:
182		return "Invalid cursor";
183
184	  case SMDBE_OLD_VERSION:
185		return "Berkeley DB file is an old version, recreate it";
186	}
187
188	/*
189	**  LDAP error messages.
190	*/
191
192#if LDAPMAP
193	if (errnum >= E_LDAPBASE)
194		return ldap_err2string(errnum - E_LDAPBASE);
195#endif /* LDAPMAP */
196
197	ret = strerror(errnum);
198	if (ret == NULL)
199	{
200		static char buf[30];
201
202		(void) sm_snprintf(buf, sizeof buf, "Error %d", errnum);
203		return buf;
204	}
205	return ret;
206}
207