1N/A/*
1N/A * Portions Copyright 1999 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <stdio.h>
1N/A#include <string.h>
1N/A#include <stdlib.h> /* free() for Solaris */
1N/A#ifdef MACOS
1N/A#include <stdlib.h>
1N/A#else /* MACOS */
1N/A#if defined( DOS ) || defined( _WIN32 )
1N/A#include <malloc.h>
1N/A#include "msdos.h"
1N/A#else /* DOS */
1N/A#include <sys/types.h>
1N/A#include <sys/socket.h>
1N/A#endif /* DOS */
1N/A#endif /* MACOS */
1N/A#include "lber.h"
1N/A#include "ldap.h"
1N/A#include "ldap-private.h"
1N/A#include "ldap-int.h"
1N/A
1N/Astruct ldaperror {
1N/A int e_code;
1N/A char *e_reason;
1N/A};
1N/A
1N/Astatic struct ldaperror ldap_errlist[] = {
1N/A#ifdef SUN
1N/A LDAP_SUCCESS, 0,
1N/A LDAP_OPERATIONS_ERROR, 0,
1N/A LDAP_PROTOCOL_ERROR, 0,
1N/A LDAP_TIMELIMIT_EXCEEDED, 0,
1N/A LDAP_SIZELIMIT_EXCEEDED, 0,
1N/A LDAP_COMPARE_FALSE, 0,
1N/A LDAP_COMPARE_TRUE, 0,
1N/A LDAP_AUTH_METHOD_NOT_SUPPORTED, 0,
1N/A LDAP_STRONG_AUTH_REQUIRED, 0,
1N/A LDAP_PARTIAL_RESULTS, 0,
1N/A/* new with ldapv3 */
1N/A LDAP_REFERRAL, 0,
1N/A LDAP_ADMINLIMIT_EXCEEDED, 0,
1N/A LDAP_UNAVAILABLE_CRITICAL_EXTENSION, 0,
1N/A LDAP_CONFIDENTIALITY_REQUIRED, 0,
1N/A/* end of new */
1N/A LDAP_NO_SUCH_ATTRIBUTE, 0,
1N/A LDAP_UNDEFINED_TYPE, 0,
1N/A LDAP_INAPPROPRIATE_MATCHING, 0,
1N/A LDAP_CONSTRAINT_VIOLATION, 0,
1N/A LDAP_TYPE_OR_VALUE_EXISTS, 0,
1N/A LDAP_INVALID_SYNTAX, 0,
1N/A LDAP_NO_SUCH_OBJECT, 0,
1N/A LDAP_ALIAS_PROBLEM, 0,
1N/A LDAP_INVALID_DN_SYNTAX, 0,
1N/A LDAP_IS_LEAF, 0,
1N/A LDAP_ALIAS_DEREF_PROBLEM, 0,
1N/A LDAP_INAPPROPRIATE_AUTH, 0,
1N/A LDAP_INVALID_CREDENTIALS, 0,
1N/A LDAP_INSUFFICIENT_ACCESS, 0,
1N/A LDAP_BUSY, 0,
1N/A LDAP_UNAVAILABLE, 0,
1N/A LDAP_UNWILLING_TO_PERFORM, 0,
1N/A LDAP_LOOP_DETECT, 0,
1N/A LDAP_NAMING_VIOLATION, 0,
1N/A LDAP_OBJECT_CLASS_VIOLATION, 0,
1N/A LDAP_NOT_ALLOWED_ON_NONLEAF, 0,
1N/A LDAP_NOT_ALLOWED_ON_RDN, 0,
1N/A LDAP_ALREADY_EXISTS, 0,
1N/A LDAP_NO_OBJECT_CLASS_MODS, 0,
1N/A LDAP_RESULTS_TOO_LARGE, 0,
1N/A/* new with ldapv3 */
1N/A LDAP_AFFECTS_MULTIPLE_DSAS, 0,
1N/A/* end of new */
1N/A LDAP_OTHER, 0,
1N/A LDAP_SERVER_DOWN, 0,
1N/A LDAP_LOCAL_ERROR, 0,
1N/A LDAP_ENCODING_ERROR, 0,
1N/A LDAP_DECODING_ERROR, 0,
1N/A LDAP_TIMEOUT, 0,
1N/A LDAP_AUTH_UNKNOWN, 0,
1N/A LDAP_FILTER_ERROR, 0,
1N/A LDAP_USER_CANCELLED, 0,
1N/A LDAP_PARAM_ERROR, 0,
1N/A LDAP_NO_MEMORY, 0,
1N/A/* new with ldapv3 */
1N/A LDAP_CONNECT_ERROR, 0,
1N/A LDAP_NOT_SUPPORTED, 0,
1N/A LDAP_CONTROL_NOT_FOUND, 0,
1N/A LDAP_NO_RESULTS_RETURNED, 0,
1N/A LDAP_MORE_RESULTS_TO_RETURN, 0,
1N/A LDAP_CLIENT_LOOP, 0,
1N/A LDAP_REFERRAL_LIMIT_EXCEEDED, 0,
1N/A/* end of new */
1N/A#else
1N/A LDAP_SUCCESS, "Success",
1N/A LDAP_OPERATIONS_ERROR, "Operations error",
1N/A LDAP_PROTOCOL_ERROR, "Protocol error",
1N/A LDAP_TIMELIMIT_EXCEEDED, "Timelimit exceeded",
1N/A LDAP_SIZELIMIT_EXCEEDED, "Sizelimit exceeded",
1N/A LDAP_COMPARE_FALSE, "Compare false",
1N/A LDAP_COMPARE_TRUE, "Compare true",
1N/A LDAP_AUTH_METHOD_NOT_SUPPORTED, "Authentication method not supported",
1N/A LDAP_STRONG_AUTH_REQUIRED, "Strong authentication required",
1N/A LDAP_PARTIAL_RESULTS, "Partial results and referral received",
1N/A/* new with ldapv3 */
1N/A LDAP_REFERRAL, "Referral received",
1N/A LDAP_ADMINLIMIT_EXCEEDED, "Admin. limit exceeded",
1N/A LDAP_UNAVAILABLE_CRITICAL_EXTENSION, "Unavailable critical extension",
1N/A LDAP_CONFIDENTIALITY_REQUIRED, "Confidentiality required",
1N/A/* end of new */
1N/A LDAP_NO_SUCH_ATTRIBUTE, "No such attribute",
1N/A LDAP_UNDEFINED_TYPE, "Undefined attribute type",
1N/A LDAP_INAPPROPRIATE_MATCHING, "Inappropriate matching",
1N/A LDAP_CONSTRAINT_VIOLATION, "Constraint violation",
1N/A LDAP_TYPE_OR_VALUE_EXISTS, "Type or value exists",
1N/A LDAP_INVALID_SYNTAX, "Invalid syntax",
1N/A LDAP_NO_SUCH_OBJECT, "No such object",
1N/A LDAP_ALIAS_PROBLEM, "Alias problem",
1N/A LDAP_INVALID_DN_SYNTAX, "Invalid DN syntax",
1N/A LDAP_IS_LEAF, "Object is a leaf",
1N/A LDAP_ALIAS_DEREF_PROBLEM, "Alias dereferencing problem",
1N/A LDAP_INAPPROPRIATE_AUTH, "Inappropriate authentication",
1N/A LDAP_INVALID_CREDENTIALS, "Invalid credentials",
1N/A LDAP_INSUFFICIENT_ACCESS, "Insufficient access",
1N/A LDAP_BUSY, "DSA is busy",
1N/A LDAP_UNAVAILABLE, "DSA is unavailable",
1N/A LDAP_UNWILLING_TO_PERFORM, "DSA is unwilling to perform",
1N/A LDAP_LOOP_DETECT, "Loop detected",
1N/A LDAP_NAMING_VIOLATION, "Naming violation",
1N/A LDAP_OBJECT_CLASS_VIOLATION, "Object class violation",
1N/A LDAP_NOT_ALLOWED_ON_NONLEAF, "Operation not allowed on nonleaf",
1N/A LDAP_NOT_ALLOWED_ON_RDN, "Operation not allowed on RDN",
1N/A LDAP_ALREADY_EXISTS, "Already exists",
1N/A LDAP_NO_OBJECT_CLASS_MODS, "Cannot modify object class",
1N/A LDAP_RESULTS_TOO_LARGE, "Results too large",
1N/A/* new with ldapv3 */
1N/A LDAP_AFFECTS_MULTIPLE_DSAS, "Affects multiple DSAs",
1N/A/* end of new */
1N/A LDAP_OTHER, "Unknown error",
1N/A LDAP_SERVER_DOWN, "Can't contact LDAP server",
1N/A LDAP_LOCAL_ERROR, "Local error",
1N/A LDAP_ENCODING_ERROR, "Encoding error",
1N/A LDAP_DECODING_ERROR, "Decoding error",
1N/A LDAP_TIMEOUT, "Timed out",
1N/A LDAP_AUTH_UNKNOWN, "Unknown authentication method",
1N/A LDAP_FILTER_ERROR, "Bad search filter",
1N/A LDAP_USER_CANCELLED, "User cancelled operation",
1N/A LDAP_PARAM_ERROR, "Bad parameter to an ldap routine",
1N/A LDAP_NO_MEMORY, "Out of memory",
1N/A/* new with ldapv3 */
1N/A LDAP_CONNECT_ERROR, "Connection error",
1N/A LDAP_NOT_SUPPORTED, "Not supported",
1N/A LDAP_CONTROL_NOT_FOUND, "Control not found",
1N/A LDAP_NO_RESULTS_RETURNED, "No results have been returned",
1N/A LDAP_MORE_RESULTS_TO_RETURN, "More results to return",
1N/A LDAP_CLIENT_LOOP, "Loop detected in referrals",
1N/A LDAP_REFERRAL_LIMIT_EXCEEDED, "Too many referrals followed",
1N/A/* end of new */
1N/A#endif
1N/A -1, 0
1N/A};
1N/A
1N/A#ifdef SUN
1N/A#pragma init (fill_ldap_errlist)
1N/A
1N/Astatic void fill_ldap_errlist()
1N/A{
1N/A int i=0;
1N/A Debug(LDAP_DEBUG_TRACE, "fill_ldap_errlist\n", 0, 0, 0 );
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 130, "Success");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 131, "Operations error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 132, "Protocol error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 133, "Timelimit exceeded");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 134, "Sizelimit exceeded");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 135, "Compare false");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 136, "Compare true");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 137, "Strong authentication not supported");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 138, "Strong authentication required");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 139, "Partial results and referral received");
1N/A/* new with ldapv3 */
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1262, "Referral received");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1263, "Admin. limit exceeded");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1264, "Unavailable critical extension");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1265, "Confidentiality required");
1N/A/* end of new */
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 140, "No such attribute");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 141, "Undefined attribute type");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 142, "Inappropriate matching");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 143, "Constraint violation");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 144, "Type or value exists");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 145, "Invalid syntax");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 146, "No such object");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 147, "Alias problem");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 148, "Invalid DN syntax");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 149, "Object is a leaf");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 150, "Alias dereferencing problem");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 151, "Inappropriate authentication");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 152, "Invalid credentials");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 153, "Insufficient access");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 154, "DSA is busy");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 155, "DSA is unavailable");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 156, "DSA is unwilling to perform");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 157, "Loop detected");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 158, "Naming violation");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 159, "Object class violation");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 160, "Operation not allowed on nonleaf");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 161, "Operation not allowed on RDN");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 162, "Already exists");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 163, "Cannot modify object class");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 164, "Results too large");
1N/A/* new with ldapv3 */
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1266, "Affects multiple DSAs");
1N/A/* end of new */
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 165, "Unknown error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 166, "Can't contact LDAP server");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 167, "Local error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 168, "Encoding error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 169, "Decoding error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 170, "Timed out");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 171, "Unknown authentication method");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 172, "Bad search filter");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 173, "User cancelled operation");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 174, "Bad parameter to an ldap routine");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 175, "Out of memory");
1N/A
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1267, "Connection error");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1268, "Not supported");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1269, "Control not found");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1270, "No results have been returned");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1271, "More results to return");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1272, "Loop detected in referrals");
1N/A ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1273, "Too many referrals followed");
1N/A}
1N/A#endif
1N/A
1N/Achar *
1N/Aldap_err2string( int err )
1N/A{
1N/A int i;
1N/A
1N/A Debug( LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0 );
1N/A
1N/A for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
1N/A if ( err == ldap_errlist[i].e_code )
1N/A return( ldap_errlist[i].e_reason );
1N/A }
1N/A
1N/A return( catgets(slapdcat, 1 , 165, "Unknown error") );
1N/A}
1N/A
1N/A#ifndef NO_USERINTERFACE
1N/Avoid
1N/Aldap_perror( LDAP *ld, char *s )
1N/A{
1N/A int i;
1N/A
1N/A Debug( LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0 );
1N/A
1N/A if ( ld == NULL ) {
1N/A perror( s );
1N/A return;
1N/A }
1N/A#ifdef SUN
1N/A /* for I18N */
1N/A if ( ldap_errlist[0].e_reason == NULL ) {
1N/A fill_ldap_errlist();
1N/A } /* end if */
1N/A#endif
1N/A
1N/A for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
1N/A if ( ld->ld_errno == ldap_errlist[i].e_code ) {
1N/A (void) fprintf( stderr, "%s: %s\n", s,
1N/A ldap_errlist[i].e_reason );
1N/A if ( ld->ld_matched != NULL && *ld->ld_matched != '\0' )
1N/A (void) fprintf( stderr, catgets(slapdcat, 1, 176, "%1$s: matched: %2$s\n"), s,
1N/A ld->ld_matched );
1N/A if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
1N/A (void) fprintf( stderr, catgets(slapdcat, 1, 177, "%1$s: additional info: %2$s\n"),
1N/A s, ld->ld_error );
1N/A (void) fflush( stderr );
1N/A return;
1N/A }
1N/A }
1N/A
1N/A (void) fprintf( stderr, catgets(slapdcat, 1, 178, "%1$s: Not an LDAP errno %2$d\n"), s, ld->ld_errno );
1N/A (void) fflush( stderr );
1N/A}
1N/A
1N/A#else
1N/A
1N/Avoid
1N/Aldap_perror( LDAP *ld, char *s )
1N/A{
1N/A}
1N/A
1N/A#endif /* NO_USERINTERFACE */
1N/A
1N/A
1N/Aint
1N/Aldap_result2error( LDAP *ld, LDAPMessage *r, int freeit )
1N/A{
1N/A LDAPMessage *lm;
1N/A BerElement ber;
1N/A int along;
1N/A int rc;
1N/A
1N/A Debug( LDAP_DEBUG_TRACE, "ldap_result2error\n", 0, 0, 0 );
1N/A
1N/A if ( r == NULLMSG )
1N/A return( LDAP_PARAM_ERROR );
1N/A
1N/A for ( lm = r; lm->lm_chain != NULL; lm = lm->lm_chain )
1N/A ; /* NULL */
1N/A
1N/A if ( ld->ld_error ) {
1N/A free( ld->ld_error );
1N/A ld->ld_error = NULL;
1N/A }
1N/A if ( ld->ld_matched ) {
1N/A free( ld->ld_matched );
1N/A ld->ld_matched = NULL;
1N/A }
1N/A
1N/A ber = *(lm->lm_ber);
1N/A if ( ld->ld_version == LDAP_VERSION2 ) {
1N/A rc = ber_scanf( &ber, "{iaa}", &along, &ld->ld_matched,
1N/A &ld->ld_error );
1N/A } else {
1N/A rc = ber_scanf( &ber, "{ia}", &along, &ld->ld_error );
1N/A }
1N/A if ( rc == LBER_ERROR ) {
1N/A ld->ld_errno = LDAP_DECODING_ERROR;
1N/A } else {
1N/A ld->ld_errno = along;
1N/A }
1N/A
1N/A if ( freeit )
1N/A ldap_msgfree( r );
1N/A
1N/A return( ld->ld_errno );
1N/A}