xref: /onnv-gate/usr/src/lib/libldap4/common/error.c (revision 3857:21b9b714e4ab)
10Sstevel@tonic-gate /*
2*3857Sstevel  * Portions Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
3*3857Sstevel  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
70Sstevel@tonic-gate 
80Sstevel@tonic-gate #include <stdio.h>
90Sstevel@tonic-gate #include <string.h>
100Sstevel@tonic-gate #include <stdlib.h> /* free() for Solaris */
110Sstevel@tonic-gate #ifdef MACOS
120Sstevel@tonic-gate #include <stdlib.h>
130Sstevel@tonic-gate #else /* MACOS */
140Sstevel@tonic-gate #if defined( DOS ) || defined( _WIN32 )
150Sstevel@tonic-gate #include <malloc.h>
160Sstevel@tonic-gate #include "msdos.h"
170Sstevel@tonic-gate #else /* DOS */
180Sstevel@tonic-gate #include <sys/types.h>
190Sstevel@tonic-gate #include <sys/socket.h>
200Sstevel@tonic-gate #endif /* DOS */
210Sstevel@tonic-gate #endif /* MACOS */
220Sstevel@tonic-gate #include "lber.h"
230Sstevel@tonic-gate #include "ldap.h"
240Sstevel@tonic-gate #include "ldap-private.h"
250Sstevel@tonic-gate #include "ldap-int.h"
260Sstevel@tonic-gate 
270Sstevel@tonic-gate struct ldaperror {
280Sstevel@tonic-gate 	int	e_code;
290Sstevel@tonic-gate 	char	*e_reason;
300Sstevel@tonic-gate };
310Sstevel@tonic-gate 
320Sstevel@tonic-gate static struct ldaperror ldap_errlist[] = {
330Sstevel@tonic-gate #ifdef SUN
340Sstevel@tonic-gate 	LDAP_SUCCESS, 			0,
350Sstevel@tonic-gate 	LDAP_OPERATIONS_ERROR, 		0,
360Sstevel@tonic-gate 	LDAP_PROTOCOL_ERROR, 		0,
370Sstevel@tonic-gate 	LDAP_TIMELIMIT_EXCEEDED,	0,
380Sstevel@tonic-gate 	LDAP_SIZELIMIT_EXCEEDED, 	0,
390Sstevel@tonic-gate 	LDAP_COMPARE_FALSE, 		0,
400Sstevel@tonic-gate 	LDAP_COMPARE_TRUE, 		0,
410Sstevel@tonic-gate 	LDAP_AUTH_METHOD_NOT_SUPPORTED, 0,
420Sstevel@tonic-gate 	LDAP_STRONG_AUTH_REQUIRED, 	0,
430Sstevel@tonic-gate 	LDAP_PARTIAL_RESULTS, 		0,
440Sstevel@tonic-gate /* new with ldapv3 */
450Sstevel@tonic-gate 	LDAP_REFERRAL,			0,
460Sstevel@tonic-gate 	LDAP_ADMINLIMIT_EXCEEDED,	0,
470Sstevel@tonic-gate 	LDAP_UNAVAILABLE_CRITICAL_EXTENSION, 	0,
480Sstevel@tonic-gate 	LDAP_CONFIDENTIALITY_REQUIRED,	0,
490Sstevel@tonic-gate /* end of new */
500Sstevel@tonic-gate 	LDAP_NO_SUCH_ATTRIBUTE, 	0,
510Sstevel@tonic-gate 	LDAP_UNDEFINED_TYPE, 		0,
520Sstevel@tonic-gate 	LDAP_INAPPROPRIATE_MATCHING, 	0,
530Sstevel@tonic-gate 	LDAP_CONSTRAINT_VIOLATION, 	0,
540Sstevel@tonic-gate 	LDAP_TYPE_OR_VALUE_EXISTS, 	0,
550Sstevel@tonic-gate 	LDAP_INVALID_SYNTAX, 		0,
560Sstevel@tonic-gate 	LDAP_NO_SUCH_OBJECT, 		0,
570Sstevel@tonic-gate 	LDAP_ALIAS_PROBLEM, 		0,
580Sstevel@tonic-gate 	LDAP_INVALID_DN_SYNTAX,		0,
590Sstevel@tonic-gate 	LDAP_IS_LEAF, 			0,
600Sstevel@tonic-gate 	LDAP_ALIAS_DEREF_PROBLEM, 	0,
610Sstevel@tonic-gate 	LDAP_INAPPROPRIATE_AUTH, 	0,
620Sstevel@tonic-gate 	LDAP_INVALID_CREDENTIALS, 	0,
630Sstevel@tonic-gate 	LDAP_INSUFFICIENT_ACCESS, 	0,
640Sstevel@tonic-gate 	LDAP_BUSY, 			0,
650Sstevel@tonic-gate 	LDAP_UNAVAILABLE, 		0,
660Sstevel@tonic-gate 	LDAP_UNWILLING_TO_PERFORM, 	0,
670Sstevel@tonic-gate 	LDAP_LOOP_DETECT, 		0,
680Sstevel@tonic-gate 	LDAP_NAMING_VIOLATION, 		0,
690Sstevel@tonic-gate 	LDAP_OBJECT_CLASS_VIOLATION, 	0,
700Sstevel@tonic-gate 	LDAP_NOT_ALLOWED_ON_NONLEAF, 	0,
710Sstevel@tonic-gate 	LDAP_NOT_ALLOWED_ON_RDN, 	0,
720Sstevel@tonic-gate 	LDAP_ALREADY_EXISTS, 		0,
730Sstevel@tonic-gate 	LDAP_NO_OBJECT_CLASS_MODS, 	0,
740Sstevel@tonic-gate 	LDAP_RESULTS_TOO_LARGE,		0,
750Sstevel@tonic-gate /* new with ldapv3 */
760Sstevel@tonic-gate 	LDAP_AFFECTS_MULTIPLE_DSAS, 0,
770Sstevel@tonic-gate /* end of new */
780Sstevel@tonic-gate 	LDAP_OTHER, 			0,
790Sstevel@tonic-gate 	LDAP_SERVER_DOWN,		0,
800Sstevel@tonic-gate 	LDAP_LOCAL_ERROR,		0,
810Sstevel@tonic-gate 	LDAP_ENCODING_ERROR,		0,
820Sstevel@tonic-gate 	LDAP_DECODING_ERROR,		0,
830Sstevel@tonic-gate 	LDAP_TIMEOUT,			0,
840Sstevel@tonic-gate 	LDAP_AUTH_UNKNOWN,		0,
850Sstevel@tonic-gate 	LDAP_FILTER_ERROR,		0,
860Sstevel@tonic-gate 	LDAP_USER_CANCELLED,		0,
870Sstevel@tonic-gate 	LDAP_PARAM_ERROR,		0,
880Sstevel@tonic-gate 	LDAP_NO_MEMORY,			0,
890Sstevel@tonic-gate /* new with ldapv3 */
900Sstevel@tonic-gate 	LDAP_CONNECT_ERROR,		0,
910Sstevel@tonic-gate 	LDAP_NOT_SUPPORTED,		0,
920Sstevel@tonic-gate 	LDAP_CONTROL_NOT_FOUND,	0,
930Sstevel@tonic-gate 	LDAP_NO_RESULTS_RETURNED,	0,
940Sstevel@tonic-gate 	LDAP_MORE_RESULTS_TO_RETURN,	0,
950Sstevel@tonic-gate 	LDAP_CLIENT_LOOP,		0,
960Sstevel@tonic-gate 	LDAP_REFERRAL_LIMIT_EXCEEDED,	0,
970Sstevel@tonic-gate /* end of new */
980Sstevel@tonic-gate #else
990Sstevel@tonic-gate 	LDAP_SUCCESS, 			"Success",
1000Sstevel@tonic-gate 	LDAP_OPERATIONS_ERROR, 		"Operations error",
1010Sstevel@tonic-gate 	LDAP_PROTOCOL_ERROR, 		"Protocol error",
1020Sstevel@tonic-gate 	LDAP_TIMELIMIT_EXCEEDED,	"Timelimit exceeded",
1030Sstevel@tonic-gate 	LDAP_SIZELIMIT_EXCEEDED, 	"Sizelimit exceeded",
1040Sstevel@tonic-gate 	LDAP_COMPARE_FALSE, 		"Compare false",
1050Sstevel@tonic-gate 	LDAP_COMPARE_TRUE, 		"Compare true",
1060Sstevel@tonic-gate 	LDAP_AUTH_METHOD_NOT_SUPPORTED, "Authentication method not supported",
1070Sstevel@tonic-gate 	LDAP_STRONG_AUTH_REQUIRED, 	"Strong authentication required",
1080Sstevel@tonic-gate 	LDAP_PARTIAL_RESULTS, 		"Partial results and referral received",
1090Sstevel@tonic-gate /* new with ldapv3 */
1100Sstevel@tonic-gate 	LDAP_REFERRAL,			"Referral received",
1110Sstevel@tonic-gate 	LDAP_ADMINLIMIT_EXCEEDED,	"Admin. limit exceeded",
1120Sstevel@tonic-gate 	LDAP_UNAVAILABLE_CRITICAL_EXTENSION, 	"Unavailable critical extension",
1130Sstevel@tonic-gate 	LDAP_CONFIDENTIALITY_REQUIRED,	"Confidentiality required",
1140Sstevel@tonic-gate /* end of new */
1150Sstevel@tonic-gate 	LDAP_NO_SUCH_ATTRIBUTE, 	"No such attribute",
1160Sstevel@tonic-gate 	LDAP_UNDEFINED_TYPE, 		"Undefined attribute type",
1170Sstevel@tonic-gate 	LDAP_INAPPROPRIATE_MATCHING, 	"Inappropriate matching",
1180Sstevel@tonic-gate 	LDAP_CONSTRAINT_VIOLATION, 	"Constraint violation",
1190Sstevel@tonic-gate 	LDAP_TYPE_OR_VALUE_EXISTS, 	"Type or value exists",
1200Sstevel@tonic-gate 	LDAP_INVALID_SYNTAX, 		"Invalid syntax",
1210Sstevel@tonic-gate 	LDAP_NO_SUCH_OBJECT, 		"No such object",
1220Sstevel@tonic-gate 	LDAP_ALIAS_PROBLEM, 		"Alias problem",
1230Sstevel@tonic-gate 	LDAP_INVALID_DN_SYNTAX,		"Invalid DN syntax",
1240Sstevel@tonic-gate 	LDAP_IS_LEAF, 			"Object is a leaf",
1250Sstevel@tonic-gate 	LDAP_ALIAS_DEREF_PROBLEM, 	"Alias dereferencing problem",
1260Sstevel@tonic-gate 	LDAP_INAPPROPRIATE_AUTH, 	"Inappropriate authentication",
1270Sstevel@tonic-gate 	LDAP_INVALID_CREDENTIALS, 	"Invalid credentials",
1280Sstevel@tonic-gate 	LDAP_INSUFFICIENT_ACCESS, 	"Insufficient access",
1290Sstevel@tonic-gate 	LDAP_BUSY, 			"DSA is busy",
1300Sstevel@tonic-gate 	LDAP_UNAVAILABLE, 		"DSA is unavailable",
1310Sstevel@tonic-gate 	LDAP_UNWILLING_TO_PERFORM, 	"DSA is unwilling to perform",
1320Sstevel@tonic-gate 	LDAP_LOOP_DETECT, 		"Loop detected",
1330Sstevel@tonic-gate 	LDAP_NAMING_VIOLATION, 		"Naming violation",
1340Sstevel@tonic-gate 	LDAP_OBJECT_CLASS_VIOLATION, 	"Object class violation",
1350Sstevel@tonic-gate 	LDAP_NOT_ALLOWED_ON_NONLEAF, 	"Operation not allowed on nonleaf",
1360Sstevel@tonic-gate 	LDAP_NOT_ALLOWED_ON_RDN, 	"Operation not allowed on RDN",
1370Sstevel@tonic-gate 	LDAP_ALREADY_EXISTS, 		"Already exists",
1380Sstevel@tonic-gate 	LDAP_NO_OBJECT_CLASS_MODS, 	"Cannot modify object class",
1390Sstevel@tonic-gate 	LDAP_RESULTS_TOO_LARGE,		"Results too large",
1400Sstevel@tonic-gate /* new with ldapv3 */
1410Sstevel@tonic-gate 	LDAP_AFFECTS_MULTIPLE_DSAS, "Affects multiple DSAs",
1420Sstevel@tonic-gate /* end of new */
1430Sstevel@tonic-gate 	LDAP_OTHER, 			"Unknown error",
1440Sstevel@tonic-gate 	LDAP_SERVER_DOWN,		"Can't contact LDAP server",
1450Sstevel@tonic-gate 	LDAP_LOCAL_ERROR,		"Local error",
1460Sstevel@tonic-gate 	LDAP_ENCODING_ERROR,		"Encoding error",
1470Sstevel@tonic-gate 	LDAP_DECODING_ERROR,		"Decoding error",
1480Sstevel@tonic-gate 	LDAP_TIMEOUT,			"Timed out",
1490Sstevel@tonic-gate 	LDAP_AUTH_UNKNOWN,		"Unknown authentication method",
1500Sstevel@tonic-gate 	LDAP_FILTER_ERROR,		"Bad search filter",
1510Sstevel@tonic-gate 	LDAP_USER_CANCELLED,		"User cancelled operation",
1520Sstevel@tonic-gate 	LDAP_PARAM_ERROR,		"Bad parameter to an ldap routine",
1530Sstevel@tonic-gate 	LDAP_NO_MEMORY,			"Out of memory",
1540Sstevel@tonic-gate /* new with ldapv3 */
1550Sstevel@tonic-gate 	LDAP_CONNECT_ERROR,		"Connection error",
1560Sstevel@tonic-gate 	LDAP_NOT_SUPPORTED,		"Not supported",
1570Sstevel@tonic-gate 	LDAP_CONTROL_NOT_FOUND,	"Control not found",
1580Sstevel@tonic-gate 	LDAP_NO_RESULTS_RETURNED,	"No results have been returned",
1590Sstevel@tonic-gate 	LDAP_MORE_RESULTS_TO_RETURN,	"More results to return",
1600Sstevel@tonic-gate 	LDAP_CLIENT_LOOP,		"Loop detected in referrals",
1610Sstevel@tonic-gate 	LDAP_REFERRAL_LIMIT_EXCEEDED,	"Too many referrals followed",
1620Sstevel@tonic-gate /* end of new */
1630Sstevel@tonic-gate #endif
1640Sstevel@tonic-gate 	-1, 0
1650Sstevel@tonic-gate };
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #ifdef SUN
1680Sstevel@tonic-gate #pragma init	(fill_ldap_errlist)
1690Sstevel@tonic-gate 
fill_ldap_errlist()1700Sstevel@tonic-gate static void fill_ldap_errlist()
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate 	int i=0;
1730Sstevel@tonic-gate 	Debug(LDAP_DEBUG_TRACE, "fill_ldap_errlist\n", 0, 0, 0 );
1740Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 130, "Success");
1750Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 131, "Operations error");
1760Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 132, "Protocol error");
1770Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 133, "Timelimit exceeded");
1780Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 134, "Sizelimit exceeded");
1790Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 135, "Compare false");
1800Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 136, "Compare true");
1810Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 137, "Strong authentication not supported");
1820Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 138, "Strong authentication required");
1830Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 139, "Partial results and referral received");
1840Sstevel@tonic-gate /* new with ldapv3 */
1850Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1262, "Referral received");
1860Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1263, "Admin. limit exceeded");
1870Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1264, "Unavailable critical extension");
1880Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1265, "Confidentiality required");
1890Sstevel@tonic-gate /* end of new */
1900Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 140, "No such attribute");
1910Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 141, "Undefined attribute type");
1920Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 142, "Inappropriate matching");
1930Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 143, "Constraint violation");
1940Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 144, "Type or value exists");
1950Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 145, "Invalid syntax");
1960Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 146, "No such object");
1970Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 147, "Alias problem");
1980Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 148, "Invalid DN syntax");
1990Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 149, "Object is a leaf");
2000Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 150, "Alias dereferencing problem");
2010Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 151, "Inappropriate authentication");
2020Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 152, "Invalid credentials");
2030Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 153, "Insufficient access");
2040Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 154, "DSA is busy");
2050Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 155, "DSA is unavailable");
2060Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 156, "DSA is unwilling to perform");
2070Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 157, "Loop detected");
2080Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 158, "Naming violation");
2090Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 159, "Object class violation");
2100Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 160, "Operation not allowed on nonleaf");
2110Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 161, "Operation not allowed on RDN");
2120Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 162, "Already exists");
2130Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 163, "Cannot modify object class");
2140Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 164, "Results too large");
2150Sstevel@tonic-gate /* new with ldapv3 */
2160Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1266, "Affects multiple DSAs");
2170Sstevel@tonic-gate /* end of new */
2180Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 165, "Unknown error");
2190Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 166, "Can't contact LDAP server");
2200Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 167, "Local error");
2210Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 168, "Encoding error");
2220Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 169, "Decoding error");
2230Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 170, "Timed out");
2240Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 171, "Unknown authentication method");
2250Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 172, "Bad search filter");
2260Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 173, "User cancelled operation");
2270Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 174, "Bad parameter to an ldap routine");
2280Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 175, "Out of memory");
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1267, "Connection error");
2310Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1268, "Not supported");
2320Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1269, "Control not found");
2330Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1270, "No results have been returned");
2340Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1271, "More results to return");
2350Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1272, "Loop detected in referrals");
2360Sstevel@tonic-gate 	ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1273, "Too many referrals followed");
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate #endif
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate char *
ldap_err2string(int err)2410Sstevel@tonic-gate ldap_err2string( int err )
2420Sstevel@tonic-gate {
2430Sstevel@tonic-gate 	int	i;
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0 );
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
2480Sstevel@tonic-gate 		if ( err == ldap_errlist[i].e_code )
2490Sstevel@tonic-gate 			return( ldap_errlist[i].e_reason );
2500Sstevel@tonic-gate 	}
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 	return( catgets(slapdcat, 1 , 165, "Unknown error") );
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate #ifndef NO_USERINTERFACE
2560Sstevel@tonic-gate void
ldap_perror(LDAP * ld,char * s)2570Sstevel@tonic-gate ldap_perror( LDAP *ld, char *s )
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate 	int	i;
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0 );
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	if ( ld == NULL ) {
2640Sstevel@tonic-gate 		perror( s );
2650Sstevel@tonic-gate 		return;
2660Sstevel@tonic-gate 	}
2670Sstevel@tonic-gate #ifdef SUN
2680Sstevel@tonic-gate 	/* for I18N */
2690Sstevel@tonic-gate 	if ( ldap_errlist[0].e_reason == NULL ) {
2700Sstevel@tonic-gate 		fill_ldap_errlist();
2710Sstevel@tonic-gate 	} /* end if */
2720Sstevel@tonic-gate #endif
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate 	for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
2750Sstevel@tonic-gate 		if ( ld->ld_errno == ldap_errlist[i].e_code ) {
2760Sstevel@tonic-gate 			(void) fprintf( stderr, "%s: %s\n", s,
2770Sstevel@tonic-gate 			    ldap_errlist[i].e_reason );
2780Sstevel@tonic-gate 			if ( ld->ld_matched != NULL && *ld->ld_matched != '\0' )
2790Sstevel@tonic-gate 				(void) fprintf( stderr, catgets(slapdcat, 1, 176, "%1$s: matched: %2$s\n"), s,
2800Sstevel@tonic-gate 				    ld->ld_matched );
2810Sstevel@tonic-gate 			if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
2820Sstevel@tonic-gate 				(void) fprintf( stderr, catgets(slapdcat, 1, 177, "%1$s: additional info: %2$s\n"),
2830Sstevel@tonic-gate 				    s, ld->ld_error );
2840Sstevel@tonic-gate 			(void) fflush( stderr );
2850Sstevel@tonic-gate 			return;
2860Sstevel@tonic-gate 		}
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	(void) fprintf( stderr, catgets(slapdcat, 1, 178, "%1$s: Not an LDAP errno %2$d\n"), s, ld->ld_errno );
2900Sstevel@tonic-gate 	(void) fflush( stderr );
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate #else
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate void
ldap_perror(LDAP * ld,char * s)2960Sstevel@tonic-gate ldap_perror( LDAP *ld, char *s )
2970Sstevel@tonic-gate {
2980Sstevel@tonic-gate }
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate #endif /* NO_USERINTERFACE */
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate int
ldap_result2error(LDAP * ld,LDAPMessage * r,int freeit)3040Sstevel@tonic-gate ldap_result2error( LDAP *ld, LDAPMessage *r, int freeit )
3050Sstevel@tonic-gate {
3060Sstevel@tonic-gate 	LDAPMessage	*lm;
3070Sstevel@tonic-gate 	BerElement	ber;
3080Sstevel@tonic-gate 	int		along;
3090Sstevel@tonic-gate 	int		rc;
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, "ldap_result2error\n", 0, 0, 0 );
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate 	if ( r == NULLMSG )
3140Sstevel@tonic-gate 		return( LDAP_PARAM_ERROR );
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	for ( lm = r; lm->lm_chain != NULL; lm = lm->lm_chain )
3170Sstevel@tonic-gate 		;	/* NULL */
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	if ( ld->ld_error ) {
3200Sstevel@tonic-gate 		free( ld->ld_error );
3210Sstevel@tonic-gate 		ld->ld_error = NULL;
3220Sstevel@tonic-gate 	}
3230Sstevel@tonic-gate 	if ( ld->ld_matched ) {
3240Sstevel@tonic-gate 		free( ld->ld_matched );
3250Sstevel@tonic-gate 		ld->ld_matched = NULL;
3260Sstevel@tonic-gate 	}
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	ber = *(lm->lm_ber);
3290Sstevel@tonic-gate 	if ( ld->ld_version == LDAP_VERSION2 ) {
3300Sstevel@tonic-gate 		rc = ber_scanf( &ber, "{iaa}", &along, &ld->ld_matched,
3310Sstevel@tonic-gate 		    &ld->ld_error );
3320Sstevel@tonic-gate 	} else {
3330Sstevel@tonic-gate 		rc = ber_scanf( &ber, "{ia}", &along, &ld->ld_error );
3340Sstevel@tonic-gate 	}
3350Sstevel@tonic-gate 	if ( rc == LBER_ERROR ) {
3360Sstevel@tonic-gate 		ld->ld_errno = LDAP_DECODING_ERROR;
3370Sstevel@tonic-gate 	} else {
3380Sstevel@tonic-gate 		ld->ld_errno = along;
3390Sstevel@tonic-gate 	}
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 	if ( freeit )
3420Sstevel@tonic-gate 		ldap_msgfree( r );
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	return( ld->ld_errno );
3450Sstevel@tonic-gate }
346