summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libsm/errstring.c
blob: b2999bdec97110a3cd858176d32a2b19dcb51a7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
 * Copyright (c) 2001, 2003 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
 * Copyright (c) 1988, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include <sm/gen.h>
SM_RCSID("@(#)$Id: errstring.c,v 1.19 2003/12/10 03:53:05 gshapiro Exp $")

#include <errno.h>
#include <stdio.h>	/* sys_errlist, on some platforms */

#include <sm/io.h>	/* sm_snprintf */
#include <sm/string.h>
#include <sm/errstring.h>

#if NAMED_BIND
# include <netdb.h>
#endif

#if LDAPMAP
# include <lber.h>
# include <ldap.h>			/* for LDAP error codes */
#endif /* LDAPMAP */

/*
**  Notice: this file is used by libmilter. Please try to avoid
**	using libsm specific functions.
*/

/*
**  SM_ERRSTRING -- return string description of error code
**
**	Parameters:
**		errnum -- the error number to translate
**
**	Returns:
**		A string description of errnum.
**
**	Note: this may point to a local (static) buffer.
*/

const char *
sm_errstring(errnum)
	int errnum;
{
	char *ret;


	switch (errnum)
	{
	  case EPERM:
		/* SunOS gives "Not owner" -- this is the POSIX message */
		return "Operation not permitted";

	/*
	**  Error messages used internally in sendmail.
	*/

	  case E_SM_OPENTIMEOUT:
		return "Timeout on file open";

	  case E_SM_NOSLINK:
		return "Symbolic links not allowed";

	  case E_SM_NOHLINK:
		return "Hard links not allowed";

	  case E_SM_REGONLY:
		return "Regular files only";

	  case E_SM_ISEXEC:
		return "Executable files not allowed";

	  case E_SM_WWDIR:
		return "World writable directory";

	  case E_SM_GWDIR:
		return "Group writable directory";

	  case E_SM_FILECHANGE:
		return "File changed after open";

	  case E_SM_WWFILE:
		return "World writable file";

	  case E_SM_GWFILE:
		return "Group writable file";

	  case E_SM_GRFILE:
		return "Group readable file";

	  case E_SM_WRFILE:
		return "World readable file";

	/*
	**  DNS error messages.
	*/

#if NAMED_BIND
	  case HOST_NOT_FOUND + E_DNSBASE:
		return "Name server: host not found";

	  case TRY_AGAIN + E_DNSBASE:
		return "Name server: host name lookup failure";

	  case NO_RECOVERY + E_DNSBASE:
		return "Name server: non-recoverable error";

	  case NO_DATA + E_DNSBASE:
		return "Name server: no data known";
#endif /* NAMED_BIND */

	/*
	**  libsmdb error messages.
	*/

	  case SMDBE_MALLOC:
		return "Memory allocation failed";

	  case SMDBE_GDBM_IS_BAD:
		return "GDBM is not supported";

	  case SMDBE_UNSUPPORTED:
		return "Unsupported action";

	  case SMDBE_DUPLICATE:
		return "Key already exists";

	  case SMDBE_BAD_OPEN:
		return "Database open failed";

	  case SMDBE_NOT_FOUND:
		return "Key not found";

	  case SMDBE_UNKNOWN_DB_TYPE:
		return "Unknown database type";

	  case SMDBE_UNSUPPORTED_DB_TYPE:
		return "Support for database type not compiled into this program";

	  case SMDBE_INCOMPLETE:
		return "DB sync did not finish";

	  case SMDBE_KEY_EMPTY:
		return "Key is empty";

	  case SMDBE_KEY_EXIST:
		return "Key already exists";

	  case SMDBE_LOCK_DEADLOCK:
		return "Locker killed to resolve deadlock";

	  case SMDBE_LOCK_NOT_GRANTED:
		return "Lock unavailable";

	  case SMDBE_LOCK_NOT_HELD:
		return "Lock not held by locker";

	  case SMDBE_RUN_RECOVERY:
		return "Database panic, run recovery";

	  case SMDBE_IO_ERROR:
		return "I/O error";

	  case SMDBE_READ_ONLY:
		return "Database opened read-only";

	  case SMDBE_DB_NAME_TOO_LONG:
		return "Name too long";

	  case SMDBE_INVALID_PARAMETER:
		return "Invalid parameter";

	  case SMDBE_ONLY_SUPPORTS_ONE_CURSOR:
		return "Only one cursor allowed";

	  case SMDBE_NOT_A_VALID_CURSOR:
		return "Invalid cursor";

	  case SMDBE_OLD_VERSION:
		return "Berkeley DB file is an old version, recreate it";

	  case SMDBE_VERSION_MISMATCH:
		return "Berkeley DB version mismatch between include file and library";

#if LDAPMAP

	/*
	**  LDAP URL error messages.
	*/

	/* OpenLDAP errors */
# ifdef LDAP_URL_ERR_MEM
	  case E_LDAPURLBASE + LDAP_URL_ERR_MEM:
		return "LDAP URL can't allocate memory space";
# endif /* LDAP_URL_ERR_MEM */

# ifdef LDAP_URL_ERR_PARAM
	  case E_LDAPURLBASE + LDAP_URL_ERR_PARAM:
		return "LDAP URL parameter is bad";
# endif /* LDAP_URL_ERR_PARAM */

# ifdef LDAP_URL_ERR_BADSCHEME
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADSCHEME:
		return "LDAP URL doesn't begin with \"ldap[si]://\"";
# endif /* LDAP_URL_ERR_BADSCHEME */

# ifdef LDAP_URL_ERR_BADENCLOSURE
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADENCLOSURE:
		return "LDAP URL is missing trailing \">\"";
# endif /* LDAP_URL_ERR_BADENCLOSURE */

# ifdef LDAP_URL_ERR_BADURL
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADURL:
		return "LDAP URL is bad";
# endif /* LDAP_URL_ERR_BADURL */

# ifdef LDAP_URL_ERR_BADHOST
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADHOST:
		return "LDAP URL host port is bad";
# endif /* LDAP_URL_ERR_BADHOST */

# ifdef LDAP_URL_ERR_BADATTRS
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADATTRS:
		return "LDAP URL bad (or missing) attributes";
# endif /* LDAP_URL_ERR_BADATTRS */

# ifdef LDAP_URL_ERR_BADSCOPE
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADSCOPE:
		return "LDAP URL scope string is invalid (or missing)";
# endif /* LDAP_URL_ERR_BADSCOPE */

# ifdef LDAP_URL_ERR_BADFILTER
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADFILTER:
		return "LDAP URL bad or missing filter";
# endif /* LDAP_URL_ERR_BADFILTER */

# ifdef LDAP_URL_ERR_BADEXTS
	  case E_LDAPURLBASE + LDAP_URL_ERR_BADEXTS:
		return "LDAP URL bad or missing extensions";
# endif /* LDAP_URL_ERR_BADEXTS */

	/* Sun LDAP errors */
# ifdef LDAP_URL_ERR_NOTLDAP
	  case E_LDAPURLBASE + LDAP_URL_ERR_NOTLDAP:
		return "LDAP URL doesn't begin with \"ldap://\"";
# endif /* LDAP_URL_ERR_NOTLDAP */

# ifdef LDAP_URL_ERR_NODN
	  case E_LDAPURLBASE + LDAP_URL_ERR_NODN:
		return "LDAP URL has no DN (required)";
# endif /* LDAP_URL_ERR_NODN */

#endif /* LDAPMAP */
	}

#if LDAPMAP

	/*
	**  LDAP error messages.
	*/

	if (errnum >= E_LDAPBASE)
		return ldap_err2string(errnum - E_LDAPBASE);
#endif /* LDAPMAP */

	ret = strerror(errnum);
	if (ret == NULL)
	{
		static char buf[30];

		(void) sm_snprintf(buf, sizeof buf, "Error %d", errnum);
		return buf;
	}
	return ret;
}
OpenPOWER on IntegriCloud