Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
error.c File Reference
#include "ldap-int.h"

Go to the source code of this file.

Classes

struct  ldaperror

Functions

char *LDAP_CALL ldap_err2string (int err)
static char * nsldapi_safe_strerror (e)
void LDAP_CALL ldap_perror (LDAP *ld, const char *s)
int LDAP_CALL ldap_result2error (LDAP *ld, LDAPMessage *r, int freeit)
int LDAP_CALL ldap_get_lderrno (LDAP *ld, char **m, char **s)
int LDAP_CALL ldap_set_lderrno (LDAP *ld, int e, char *m, char *s)
int LDAP_CALL ldap_parse_result (LDAP *ld, LDAPMessage *res, int *errcodep, char **matchednp, char **errmsgp, char ***referralsp, LDAPControl ***serverctrlsp, int freeit)
int nsldapi_parse_result (LDAP *ld, int msgtype, BerElement *rber, int *errcodep, char **matchednp, char **errmsgp, char ***referralsp, LDAPControl ***serverctrlsp)

Variables

static struct ldaperror []

Class Documentation

struct ldaperror

Definition at line 39 of file error.c.

Collaboration diagram for ldaperror:
Class Members
int e_code
char * e_reason

Function Documentation

char* LDAP_CALL ldap_err2string ( int  err)

Definition at line 116 of file error.c.

{
       int    i;

       LDAPDebug( LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0 );

       for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
              if ( err == ldap_errlist[i].e_code )
                     return( ldap_errlist[i].e_reason );
       }

       return( "Unknown error" );
}

Here is the caller graph for this function:

int LDAP_CALL ldap_get_lderrno ( LDAP *  ld,
char **  m,
char **  s 
)

Definition at line 217 of file error.c.

{
       if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
              return( LDAP_PARAM_ERROR ); /* punt */
       }

       if ( ld->ld_get_lderrno_fn == NULL ) {
              if ( m != NULL ) {
                     *m = ld->ld_matched;
              }
              if ( s != NULL ) {
                     *s = ld->ld_error;
              }
              return( ld->ld_errno );
       } else {
              return( ld->ld_get_lderrno_fn( m, s, ld->ld_lderrno_arg ) );
       }
}

Here is the caller graph for this function:

int LDAP_CALL ldap_parse_result ( LDAP *  ld,
LDAPMessage *  res,
int errcodep,
char **  matchednp,
char **  errmsgp,
char ***  referralsp,
LDAPControl ***  serverctrlsp,
int  freeit 
)

Definition at line 281 of file error.c.

{
       LDAPMessage          *lm;
       int                  err, errcode;
       char                 *m, *e;

       LDAPDebug( LDAP_DEBUG_TRACE, "ldap_parse_result\n", 0, 0, 0 );

       if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) ||
           !NSLDAPI_VALID_LDAPMESSAGE_POINTER( res )) {
              return( LDAP_PARAM_ERROR );
       }

       /* skip over entries and references to find next result in this chain */
       for ( lm = res; lm != NULL; lm = lm->lm_chain ) {       
              if ( lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY &&
                  lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE ) {
                     break;
              }
       }

       if ( lm == NULL ) {
              err = LDAP_NO_RESULTS_RETURNED;
              LDAP_SET_LDERRNO( ld, err, NULL, NULL );
              return( err );
       }

       err = nsldapi_parse_result( ld, lm->lm_msgtype, lm->lm_ber, &errcode,
           &m, &e, referralsp, serverctrlsp );

       if ( err == LDAP_SUCCESS ) {
              if ( errcodep != NULL ) {
                     *errcodep = errcode;
              }
              if ( matchednp != NULL ) {
                     *matchednp = nsldapi_strdup( m );
              }
              if ( errmsgp != NULL ) {
                     *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.
               */
              for ( lm = lm->lm_chain; lm != NULL; lm = lm->lm_chain ) {     
                     if ( lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY &&
                         lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE ) {
                            err = LDAP_MORE_RESULTS_TO_RETURN;
                            break;
                     }
              }
       } else {
              m = e = NULL;
       }

       if ( freeit ) {
              ldap_msgfree( res );
       }

       LDAP_SET_LDERRNO( ld, ( err == LDAP_SUCCESS ) ? errcode : err, m, e );

       return( err );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void LDAP_CALL ldap_perror ( LDAP *  ld,
const char *  s 
)

Definition at line 146 of file error.c.

{
       int    i, err;
       char   *matched, *errmsg, *separator;
       char    msg[1024];

       LDAPDebug( LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0 );

       if ( s == NULL ) {
              s = separator = "";
       } else {
              separator = ": ";
       }

       if ( ld == NULL ) {
              sprintf( msg, "%s%s%s", s, separator,
                  nsldapi_safe_strerror( errno ) );
              ber_err_print( msg );
              return;
       }

       LDAP_MUTEX_LOCK( ld, LDAP_ERR_LOCK );
       err = LDAP_GET_LDERRNO( ld, &matched, &errmsg );
       for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
              if ( err == ldap_errlist[i].e_code ) {
                     sprintf( msg, "%s%s%s", s, separator,
                                ldap_errlist[i].e_reason );
                     ber_err_print( msg );
                     if ( err == LDAP_CONNECT_ERROR ) {
                            ber_err_print( " - " );
                            ber_err_print( nsldapi_safe_strerror(
                                LDAP_GET_ERRNO( ld )));
                     }
                     ber_err_print( "\n" );
                     if ( matched != NULL && *matched != '\0' ) {
                            sprintf( msg, "%s%smatched: %s\n",
                                s, separator, matched );
                            ber_err_print( msg );
                     }
                     if ( errmsg != NULL && *errmsg != '\0' ) {
                            sprintf( msg, "%s%sadditional info: %s\n",
                                s, separator, errmsg );
                            ber_err_print( msg );
                     }
                     LDAP_MUTEX_UNLOCK( ld, LDAP_ERR_LOCK );
                     return;
              }
       }
       sprintf( msg, "%s%sNot an LDAP errno %d\n", s, separator, err );
       ber_err_print( msg );
       LDAP_MUTEX_UNLOCK( ld, LDAP_ERR_LOCK );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_result2error ( LDAP *  ld,
LDAPMessage *  r,
int  freeit 
)

Definition at line 201 of file error.c.

{
       int    lderr_parse, lderr;

       lderr_parse = ldap_parse_result( ld, r, &lderr, NULL, NULL, NULL,
           NULL, freeit );

       if ( lderr_parse != LDAP_SUCCESS ) {
              return( lderr_parse );
       }

       return( lderr );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_set_lderrno ( LDAP *  ld,
int  e,
char *  m,
char *  s 
)

Definition at line 247 of file error.c.

{
       if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
              return( LDAP_PARAM_ERROR );
       }

       if ( ld->ld_set_lderrno_fn != NULL ) {
              ld->ld_set_lderrno_fn( e, m, s, ld->ld_lderrno_arg );
       } else {
        LDAP_MUTEX_LOCK( ld, LDAP_ERR_LOCK );
              ld->ld_errno = e;
              if ( ld->ld_matched ) {
                     NSLDAPI_FREE( ld->ld_matched );
              }
              ld->ld_matched = m;
              if ( ld->ld_error ) {
                     NSLDAPI_FREE( ld->ld_error );
              }
              ld->ld_error = s;
        LDAP_MUTEX_UNLOCK( ld, LDAP_ERR_LOCK );
       }

       return( LDAP_SUCCESS );
}

Here is the caller graph for this function:

int nsldapi_parse_result ( LDAP *  ld,
int  msgtype,
BerElement *  rber,
int errcodep,
char **  matchednp,
char **  errmsgp,
char ***  referralsp,
LDAPControl ***  serverctrlsp 
)

Definition at line 354 of file error.c.

{
       BerElement    ber;
       unsigned long len;
       int           berrc, err, errcode;
       long          along;
       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.
        */

       err = LDAP_SUCCESS;  /* optimistic */
       m = e = NULL;
       if ( matchednp != NULL ) {
              *matchednp = NULL;
       }
       if ( errmsgp != NULL ) {
              *errmsgp = NULL;
       }
       if ( referralsp != NULL ) {
              *referralsp = NULL;
       }
       if ( serverctrlsp != NULL ) {
              *serverctrlsp = NULL;
       }
       ber = *rber;         /* struct copy */

       if ( NSLDAPI_LDAP_VERSION( ld ) < LDAP_VERSION2 ) {
              berrc = ber_scanf( &ber, "{ia}", &along, &e );
              errcode = (int)along;       /* XXX lossy cast */
       } else {
              if (( berrc = ber_scanf( &ber, "{iaa", &along, &m, &e ))
                  != LBER_ERROR ) {
                     errcode = (int)along;       /* XXX lossy cast */
                     /* check for optional referrals */
                     if ( ber_peek_tag( &ber, &len ) == LDAP_TAG_REFERRAL ) {
                            if ( referralsp == NULL ) {
                                   /* skip referrals */
                                   berrc = ber_scanf( &ber, "x" );
                            } else {
                                   /* suck out referrals */
                                   berrc = ber_scanf( &ber, "v",
                                       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 ) {
                            if ( ber_peek_tag( &ber, &len ) == 
                                LDAP_TAG_SASL_RES_CREDS ) {
                                   berrc = ber_scanf( &ber, "x" );
                            }
                     } else if ( msgtype == LDAP_RES_EXTENDED ) {
                            if ( ber_peek_tag( &ber, &len ) ==
                                LDAP_TAG_EXOP_RES_OID ) {
                                   berrc = ber_scanf( &ber, "x" );
                            }
                            if ( berrc != LBER_ERROR &&
                                ber_peek_tag( &ber, &len ) ==
                                LDAP_TAG_EXOP_RES_VALUE ) {
                                   berrc = ber_scanf( &ber, "x" );
                            }
                     }
              }

              /* pull out controls (if requested and any are present) */
              if ( berrc != LBER_ERROR && serverctrlsp != NULL &&
                  ( berrc = ber_scanf( &ber, "}" )) != LBER_ERROR ) {
                     err = nsldapi_get_controls( &ber, serverctrlsp );
              }
       }

       if ( berrc == LBER_ERROR && err == LDAP_SUCCESS ) {
              err = LDAP_DECODING_ERROR;
       }

       if ( errcodep != NULL ) {
              *errcodep = errcode;
       }
       if ( matchednp != NULL ) {
              *matchednp = m;
       } else if ( m != NULL ) {
              NSLDAPI_FREE( m );
       }
       if ( errmsgp != NULL ) {
              *errmsgp = e;
       } else if ( e != NULL ) {
              NSLDAPI_FREE( e );
       }

       return( err );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* nsldapi_safe_strerror ( e  ) [static]

Definition at line 132 of file error.c.

{
       char *s;

       if (( s = strerror( e )) == NULL ) {
              s = "unknown error";
       }

       return( s );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct ldaperror[] [static]

Definition at line 44 of file error.c.