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