/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ldap-int.h"
struct ldaperror {
int e_code;
char *e_reason;
};
#ifdef _SOLARIS_SDK
#include <synch.h>
{ LDAP_SUCCESS, 0 },
{ LDAP_OPERATIONS_ERROR, 0 },
{ LDAP_PROTOCOL_ERROR, 0 },
{ LDAP_TIMELIMIT_EXCEEDED, 0 },
{ LDAP_SIZELIMIT_EXCEEDED, 0 },
{ LDAP_COMPARE_FALSE, 0 },
{ LDAP_COMPARE_TRUE, 0 },
{ LDAP_STRONG_AUTH_NOT_SUPPORTED, 0 },
{ LDAP_STRONG_AUTH_REQUIRED, 0 },
{ LDAP_PARTIAL_RESULTS, 0 },
{ LDAP_REFERRAL, 0 },
{ LDAP_ADMINLIMIT_EXCEEDED, 0 },
{ LDAP_CONFIDENTIALITY_REQUIRED, 0 },
{ LDAP_SASL_BIND_IN_PROGRESS, 0 },
{ LDAP_NO_SUCH_ATTRIBUTE, 0 },
{ LDAP_UNDEFINED_TYPE, 0 },
{ LDAP_INAPPROPRIATE_MATCHING, 0 },
{ LDAP_CONSTRAINT_VIOLATION, 0 },
{ LDAP_TYPE_OR_VALUE_EXISTS, 0 },
{ LDAP_INVALID_SYNTAX, 0 },
{ LDAP_NO_SUCH_OBJECT, 0 },
{ LDAP_ALIAS_PROBLEM, 0 },
{ LDAP_INVALID_DN_SYNTAX, 0 },
{ LDAP_IS_LEAF, 0 },
{ LDAP_ALIAS_DEREF_PROBLEM, 0 },
{ LDAP_INAPPROPRIATE_AUTH, 0 },
{ LDAP_INVALID_CREDENTIALS, 0 },
{ LDAP_INSUFFICIENT_ACCESS, 0 },
{ LDAP_BUSY, 0 },
{ LDAP_UNAVAILABLE, 0 },
{ LDAP_UNWILLING_TO_PERFORM, 0 },
{ LDAP_LOOP_DETECT, 0 },
{ LDAP_SORT_CONTROL_MISSING, 0 },
{ LDAP_INDEX_RANGE_ERROR, 0 },
{ LDAP_NAMING_VIOLATION, 0 },
{ LDAP_OBJECT_CLASS_VIOLATION, 0 },
{ LDAP_NOT_ALLOWED_ON_NONLEAF, 0 },
{ LDAP_NOT_ALLOWED_ON_RDN, 0 },
{ LDAP_ALREADY_EXISTS, 0 },
{ LDAP_NO_OBJECT_CLASS_MODS, 0 },
{ LDAP_RESULTS_TOO_LARGE, 0 },
{ LDAP_AFFECTS_MULTIPLE_DSAS, 0 },
{ LDAP_OTHER, 0 },
{ LDAP_SERVER_DOWN, 0 },
{ LDAP_LOCAL_ERROR, 0 },
{ LDAP_ENCODING_ERROR, 0 },
{ LDAP_DECODING_ERROR, 0 },
{ LDAP_TIMEOUT, 0 },
{ LDAP_AUTH_UNKNOWN, 0 },
{ LDAP_FILTER_ERROR, 0 },
{ LDAP_USER_CANCELLED, 0 },
{ LDAP_PARAM_ERROR, 0 },
{ LDAP_NO_MEMORY, 0 },
{ LDAP_CONNECT_ERROR, 0 },
{ LDAP_NOT_SUPPORTED, 0 },
{ LDAP_CONTROL_NOT_FOUND, 0 },
{ LDAP_NO_RESULTS_RETURNED, 0 },
{ LDAP_MORE_RESULTS_TO_RETURN, 0 },
{ LDAP_CLIENT_LOOP, 0 },
{ LDAP_REFERRAL_LIMIT_EXCEEDED, 0 },
{ -1, 0 }
};
#else
{ LDAP_SUCCESS, "Success" },
{ LDAP_OPERATIONS_ERROR, "Operations error" },
{ LDAP_PROTOCOL_ERROR, "Protocol error" },
{ LDAP_TIMELIMIT_EXCEEDED, "Timelimit exceeded" },
{ LDAP_SIZELIMIT_EXCEEDED, "Sizelimit exceeded" },
{ LDAP_COMPARE_FALSE, "Compare false" },
{ LDAP_COMPARE_TRUE, "Compare true" },
{ LDAP_STRONG_AUTH_NOT_SUPPORTED, "Authentication method not supported" },
{ LDAP_STRONG_AUTH_REQUIRED, "Strong authentication required" },
{ LDAP_PARTIAL_RESULTS, "Partial results and referral received" },
{ LDAP_REFERRAL, "Referral received" },
{ LDAP_ADMINLIMIT_EXCEEDED, "Administrative limit exceeded" },
{ LDAP_UNAVAILABLE_CRITICAL_EXTENSION, "Unavailable critical extension" },
{ LDAP_CONFIDENTIALITY_REQUIRED, "Confidentiality required" },
{ LDAP_SASL_BIND_IN_PROGRESS, "SASL bind in progress" },
{ LDAP_NO_SUCH_ATTRIBUTE, "No such attribute" },
{ LDAP_UNDEFINED_TYPE, "Undefined attribute type" },
{ LDAP_INAPPROPRIATE_MATCHING, "Inappropriate matching" },
{ LDAP_CONSTRAINT_VIOLATION, "Constraint violation" },
{ LDAP_TYPE_OR_VALUE_EXISTS, "Type or value exists" },
{ LDAP_INVALID_SYNTAX, "Invalid syntax" },
{ LDAP_NO_SUCH_OBJECT, "No such object" },
{ LDAP_ALIAS_PROBLEM, "Alias problem" },
{ LDAP_INVALID_DN_SYNTAX, "Invalid DN syntax" },
{ LDAP_IS_LEAF, "Object is a leaf" },
{ LDAP_ALIAS_DEREF_PROBLEM, "Alias dereferencing problem" },
{ LDAP_INAPPROPRIATE_AUTH, "Inappropriate authentication" },
{ LDAP_INVALID_CREDENTIALS, "Invalid credentials" },
{ LDAP_INSUFFICIENT_ACCESS, "Insufficient access" },
{ LDAP_BUSY, "DSA is busy" },
{ LDAP_UNAVAILABLE, "DSA is unavailable" },
{ LDAP_UNWILLING_TO_PERFORM, "DSA is unwilling to perform" },
{ LDAP_LOOP_DETECT, "Loop detected" },
{ LDAP_SORT_CONTROL_MISSING, "Sort Control is missing" },
{ LDAP_INDEX_RANGE_ERROR, "Search results exceed the range specified by the offsets" },
{ LDAP_NAMING_VIOLATION, "Naming violation" },
{ LDAP_OBJECT_CLASS_VIOLATION, "Object class violation" },
{ LDAP_NOT_ALLOWED_ON_NONLEAF, "Operation not allowed on nonleaf" },
{ LDAP_NOT_ALLOWED_ON_RDN, "Operation not allowed on RDN" },
{ LDAP_ALREADY_EXISTS, "Already exists" },
{ LDAP_NO_OBJECT_CLASS_MODS, "Cannot modify object class" },
{ LDAP_RESULTS_TOO_LARGE, "Results too large" },
{ LDAP_AFFECTS_MULTIPLE_DSAS, "Affects multiple servers" },
{ LDAP_OTHER, "Unknown error" },
{ LDAP_SERVER_DOWN, "Can't contact LDAP server" },
{ LDAP_LOCAL_ERROR, "Local error" },
{ LDAP_ENCODING_ERROR, "Encoding error" },
{ LDAP_DECODING_ERROR, "Decoding error" },
{ LDAP_TIMEOUT, "Timed out" },
{ LDAP_AUTH_UNKNOWN, "Unknown authentication method" },
{ LDAP_FILTER_ERROR, "Bad search filter" },
{ LDAP_USER_CANCELLED, "User cancelled operation" },
{ LDAP_PARAM_ERROR, "Bad parameter to an ldap routine" },
{ LDAP_NO_MEMORY, "Out of memory" },
{ LDAP_CONNECT_ERROR, "Can't connect to the LDAP server" },
{ LDAP_NOT_SUPPORTED, "Not supported by this version of the LDAP protocol" },
{ LDAP_CONTROL_NOT_FOUND, "Requested LDAP control not found" },
{ LDAP_NO_RESULTS_RETURNED, "No results returned" },
{ LDAP_MORE_RESULTS_TO_RETURN, "More results to return" },
{ LDAP_CLIENT_LOOP, "Client detected loop" },
{ LDAP_REFERRAL_LIMIT_EXCEEDED, "Referral hop limit exceeded" },
{ -1, 0 }
};
#endif
#ifdef _SOLARIS_SDK
static void fill_ldap_errlist()
{
int i=0;
return;
}
"Timelimit exceeded");
"Sizelimit exceeded");
"Authentication method not supported");
"Strong authentication required");
"Partial results and referral received");
"Referral received");
"Administrative limit exceeded");
"Unavailable critical extension");
"Confidentiality required");
"SASL bind in progress");
"No such attribute");
"Undefined attribute type");
"Inappropriate matching");
"Constraint violation");
"Type or value exists");
"Invalid DN syntax");
"Alias dereferencing problem");
"Inappropriate authentication");
"Invalid credentials");
"Insufficient access");
"DSA is unavailable");
"DSA is unwilling to perform");
"Sort Control is missing");
"Search results exceed the range specified by the offsets");
"Object class violation");
"Operation not allowed on nonleaf");
"Operation not allowed on RDN");
"Cannot modify object class");
"Results too large");
"Affects multiple servers");
"Can't contact LDAP server");
"Unknown authentication method");
"Bad search filter");
"User cancelled operation");
"Bad parameter to an ldap routine");
"Can't connect to the LDAP server");
"Not supported by this version of the LDAP protocol");
"Requested LDAP control not found");
"No results returned");
"More results to return");
"Client detected loop");
"Referral hop limit exceeded");
}
#endif
char *
{
int i;
#ifdef _SOLARIS_SDK
/* Make sure errlist is initialized before referencing err string */
#endif
return( ldap_errlist[i].e_reason );
}
}
static char *
nsldapi_safe_strerror( int e )
{
char *s;
}
return( s );
}
void
{
int i, err;
#ifdef _SOLARIS_SDK
/* Make sure errlist is initialized before referencing err string */
#endif
if ( s == NULL ) {
s = separator = "";
} else {
separator = ": ";
}
nsldapi_safe_strerror( errno ) );
ber_err_print( msg );
return;
}
ldap_errlist[i].e_reason );
ber_err_print( msg );
if ( err == LDAP_CONNECT_ERROR ) {
ber_err_print( " - " );
LDAP_GET_ERRNO( ld )));
}
ber_err_print( "\n" );
"%s%smatched: %s\n"),
ber_err_print( msg );
}
"%s%sadditional info: %s\n"),
ber_err_print( msg );
}
return;
}
}
ber_err_print( msg );
}
int
{
if ( lderr_parse != LDAP_SUCCESS ) {
return( lderr_parse );
}
return( lderr );
}
int
{
if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
return( LDAP_PARAM_ERROR ); /* punt */
}
if ( m != NULL ) {
*m = ld->ld_matched;
}
if ( s != NULL ) {
}
} else {
}
}
/*
* Note: there is no need for callers of ldap_set_lderrno() to lock the
* ld mutex. If applications intend to share an LDAP session handle
* between threads they *must* perform their own locking around the
* session handle or they must install a "set lderrno" thread callback
* function.
*
*/
int
{
if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
return( LDAP_PARAM_ERROR );
}
} else {
if ( ld->ld_matched ) {
}
ld->ld_matched = m;
}
}
return( LDAP_SUCCESS );
}
/*
* Returns an LDAP error that says whether parse succeeded. The error code
* from the LDAP result itself is returned in the errcodep result parameter.
* If any of the result params. (errcodep, matchednp, errmsgp, referralsp,
* or serverctrlsp) are NULL we don't return that info.
*/
int
int freeit )
{
char *m, *e;
if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) ||
return( LDAP_PARAM_ERROR );
}
/* skip over entries and references to find next result in this chain */
break;
}
}
return( err );
}
&m, &e, referralsp, serverctrlsp );
if ( err == LDAP_SUCCESS ) {
}
*matchednp = nsldapi_strdup( m );
}
*errmsgp = nsldapi_strdup( e );
}
/*
* if there are more result messages in the chain, arrange to
* return the special LDAP_MORE_RESULTS_TO_RETURN "error" code.
*/
break;
}
}
} else {
m = e = NULL;
}
if ( freeit ) {
ldap_msgfree( res );
}
return( err );
}
/*
* returns an LDAP error code indicating success or failure of parsing
* does NOT set any error information inside "ld"
*/
int
LDAPControl ***serverctrlsp )
{
char *m, *e;
/*
* Parse the result message. LDAPv3 result messages look like this:
*
* LDAPResult ::= SEQUENCE {
* resultCode ENUMERATED { ... },
* matchedDN LDAPDN,
* errorMessage LDAPString,
* referral [3] Referral OPTIONAL
* opSpecificStuff OPTIONAL
* }
*
* all wrapped up in an LDAPMessage sequence which looks like this:
* LDAPMessage ::= SEQUENCE {
* messageID MessageID,
* LDAPResult CHOICE { ... }, // message type
* controls [0] Controls OPTIONAL
* }
*
* LDAPv2 messages don't include referrals or controls.
* LDAPv1 messages don't include matchedDN, referrals, or controls.
*
* ldap_result() pulls out the message id, so by the time a result
* message gets here we are sitting at the start of the LDAPResult.
*/
m = e = NULL;
}
}
if ( referralsp != NULL ) {
*referralsp = NULL;
}
if ( serverctrlsp != NULL ) {
*serverctrlsp = NULL;
}
} else {
!= LBER_ERROR ) {
/* check for optional referrals */
if ( referralsp == NULL ) {
/* skip referrals */
} else {
/* suck out referrals */
referralsp );
}
} else if ( referralsp != NULL ) {
*referralsp = NULL;
}
}
if ( berrc != LBER_ERROR ) {
/*
* skip past optional operation-specific elements:
* bind results - serverSASLcreds
* extendedop results - OID plus value
*/
if ( msgtype == LDAP_RES_BIND ) {
}
} else if ( msgtype == LDAP_RES_EXTENDED ) {
}
if ( berrc != LBER_ERROR &&
}
}
}
/* pull out controls (if requested and any are present) */
}
}
}
}
*matchednp = m;
} else if ( m != NULL ) {
NSLDAPI_FREE( m );
}
*errmsgp = e;
} else if ( e != NULL ) {
NSLDAPI_FREE( e );
}
return( err );
}