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