#define LBER_ERROR_PARAM 0x1
#define LBER_ERROR_MEMORY 0x2
+#ifdef LDAP_DEVEL
+#define LDAP_NULL_IS_NULL
+#endif
+
LDAP_END_DECL
#endif /* _LBER_H */
return tag;
}
+#ifdef LDAP_NULL_IS_NULL
+ber_tag_t
+ber_get_stringbv_null( BerElement *ber, struct berval *bv, int alloc )
+{
+ ber_tag_t tag;
+
+ assert( ber != NULL );
+ assert( bv != NULL );
+
+ assert( LBER_VALID( ber ) );
+
+ if ( (tag = ber_skip_tag( ber, &bv->bv_len )) == LBER_DEFAULT ) {
+ bv->bv_val = NULL;
+ return LBER_DEFAULT;
+ }
+
+ if ( (ber_len_t) ber_pvt_ber_remaining( ber ) < bv->bv_len ) {
+ return LBER_DEFAULT;
+ }
+
+ if ( bv->bv_len == 0 ) {
+ bv->bv_val = NULL;
+ ber->ber_tag = *(unsigned char *)ber->ber_ptr;
+ return tag;
+ }
+
+ if ( alloc ) {
+ bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1,
+ ber->ber_memctx );
+ if ( bv->bv_val == NULL ) {
+ return LBER_DEFAULT;
+ }
+
+ if ( bv->bv_len > 0 && (ber_len_t) ber_read( ber, bv->bv_val,
+ bv->bv_len ) != bv->bv_len )
+ {
+ LBER_FREE( bv->bv_val );
+ bv->bv_val = NULL;
+ return LBER_DEFAULT;
+ }
+ } else {
+ bv->bv_val = ber->ber_ptr;
+ ber->ber_ptr += bv->bv_len;
+ }
+ ber->ber_tag = *(unsigned char *)ber->ber_ptr;
+ bv->bv_val[bv->bv_len] = '\0';
+
+ return tag;
+}
+#endif /* LDAP_NULL_IS_NULL */
+
ber_tag_t
ber_get_stringa( BerElement *ber, char **buf )
{
return tag;
}
+#ifdef LDAP_NULL_IS_NULL
+ber_tag_t
+ber_get_stringa_null( BerElement *ber, char **buf )
+{
+ BerValue bv;
+ ber_tag_t tag;
+
+ assert( buf != NULL );
+
+ tag = ber_get_stringbv_null( ber, &bv, 1 );
+ *buf = bv.bv_val;
+
+ return tag;
+}
+#endif /* LDAP_NULL_IS_NULL */
+
ber_tag_t
ber_get_stringal( BerElement *ber, struct berval **bv )
{
rc = ber_get_stringa( ber, ss );
break;
+#ifdef LDAP_NULL_IS_NULL
+ case 'A': /* octet string - allocate storage as needed,
+ * but return NULL if len == 0 */
+ ss = va_arg( ap, char ** );
+ rc = ber_get_stringa_null( ber, ss );
+ break;
+#endif /* LDAP_NULL_IS_NULL */
+
case 'b': /* boolean */
i = va_arg( ap, ber_int_t * );
rc = ber_get_boolean( ber, i );
break;
+ case 'B': /* bit string - allocate storage as needed */
+ ss = va_arg( ap, char ** );
+ l = va_arg( ap, ber_len_t * ); /* for length, in bits */
+ rc = ber_get_bitstringa( ber, ss, l );
+ break;
+
case 'e': /* enumerated */
case 'i': /* int */
i = va_arg( ap, ber_int_t * );
rc = ber_peek_tag( ber, l );
break;
- case 'n': /* null */
- rc = ber_get_null( ber );
+ case 'm': /* octet string in berval, in-place */
+ bval = va_arg( ap, struct berval * );
+ rc = ber_get_stringbv( ber, bval, 0 );
break;
- case 's': /* octet string - in a buffer */
- s = va_arg( ap, char * );
+ case 'M': /* bvoffarray - must include address of
+ * a record len, and record offset.
+ * number of records will be returned thru
+ * len ptr on finish. parsed in-place.
+ */
+ {
+ bgbvr cookie = { BvOff };
+ cookie.ber = ber;
+ cookie.res.ba = va_arg( ap, struct berval ** );
+ cookie.alloc = 0;
l = va_arg( ap, ber_len_t * );
- rc = ber_get_stringb( ber, s, l );
+ cookie.siz = *l;
+ cookie.off = va_arg( ap, ber_len_t );
+ rc = ber_get_stringbvl( &cookie, l );
break;
+ }
- case 'm': /* octet string in berval, in-place */
- bval = va_arg( ap, struct berval * );
- rc = ber_get_stringbv( ber, bval, 0 );
+ case 'n': /* null */
+ rc = ber_get_null( ber );
break;
case 'o': /* octet string in a supplied berval */
rc = ber_get_stringal( ber, bvp );
break;
- case 'B': /* bit string - allocate storage as needed */
- ss = va_arg( ap, char ** );
- l = va_arg( ap, ber_len_t * ); /* for length, in bits */
- rc = ber_get_bitstringa( ber, ss, l );
+ case 's': /* octet string - in a buffer */
+ s = va_arg( ap, char * );
+ l = va_arg( ap, ber_len_t * );
+ rc = ber_get_stringb( ber, s, l );
break;
case 't': /* tag of next item */
break;
}
- case 'M': /* bvoffarray - must include address of
- * a record len, and record offset.
- * number of records will be returned thru
- * len ptr on finish. parsed in-place.
- */
- {
- bgbvr cookie = { BvOff };
- cookie.ber = ber;
- cookie.res.ba = va_arg( ap, struct berval ** );
- cookie.alloc = 0;
- l = va_arg( ap, ber_len_t * );
- cookie.siz = *l;
- cookie.off = va_arg( ap, ber_len_t );
- rc = ber_get_stringbvl( &cookie, l );
- break;
- }
-
case 'x': /* skip the next element - whatever it is */
if ( (rc = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
break;
} break;
case 'a': /* octet string - allocate storage as needed */
+#ifdef LDAP_NULL_IS_NULL
+ case 'A':
+#endif /* LDAP_NULL_IS_NULL */
ss = va_arg( ap, char ** );
if ( *ss ) {
LBER_FREE( *ss );
(void) va_arg( ap, int * );
break;
- case 's': /* octet string - in a buffer */
- (void) va_arg( ap, char * );
- (void) va_arg( ap, ber_len_t * );
- break;
-
case 'l': /* length of next item */
(void) va_arg( ap, ber_len_t * );
break;
- case 't': /* tag of next item */
- case 'T': /* skip tag of next item */
- (void) va_arg( ap, ber_tag_t * );
- break;
-
case 'o': /* octet string in a supplied berval */
bval = va_arg( ap, struct berval * );
if ( bval->bv_val != NULL ) {
}
break;
+ case 's': /* octet string - in a buffer */
+ (void) va_arg( ap, char * );
+ (void) va_arg( ap, ber_len_t * );
+ break;
+
+ case 't': /* tag of next item */
+ case 'T': /* skip tag of next item */
+ (void) va_arg( ap, ber_tag_t * );
+ break;
+
case 'B': /* bit string - allocate storage as needed */
ss = va_arg( ap, char ** );
if ( *ss ) {
*(va_arg( ap, ber_len_t * )) = 0; /* for length, in bits */
break;
- case 'v': /* sequence of strings */
- case 'V': /* sequence of strings + lengths */
- case 'W': /* BerVarray */
case 'm': /* berval in-place */
case 'M': /* BVoff array in-place */
case 'n': /* null */
+ case 'v': /* sequence of strings */
+ case 'V': /* sequence of strings + lengths */
+ case 'W': /* BerVarray */
case 'x': /* skip the next element - whatever it is */
case '{': /* begin sequence */
case '[': /* begin set */
ber = ber_dup( lm->lm_ber );
if ( ld->ld_version < LDAP_VERSION2 ) {
+#ifdef LDAP_NULL_IS_NULL
+ tag = ber_scanf( ber, "{iA}",
+ &ld->ld_errno, &ld->ld_error );
+#else /* ! LDAP_NULL_IS_NULL */
tag = ber_scanf( ber, "{ia}",
&ld->ld_errno, &ld->ld_error );
+#endif /* ! LDAP_NULL_IS_NULL */
+
} else {
ber_len_t len;
+
+#ifdef LDAP_NULL_IS_NULL
+ tag = ber_scanf( ber, "{iAA" /*}*/,
+ &ld->ld_errno, &ld->ld_matched, &ld->ld_error );
+#else /* ! LDAP_NULL_IS_NULL */
tag = ber_scanf( ber, "{iaa" /*}*/,
&ld->ld_errno, &ld->ld_matched, &ld->ld_error );
+#endif /* ! LDAP_NULL_IS_NULL */
if( tag != LBER_ERROR ) {
/* peek for referrals */
}
if ( errcode == LDAP_SUCCESS ) {
if( matcheddnp != NULL ) {
- *matcheddnp = LDAP_STRDUP( ld->ld_matched );
+#ifdef LDAP_NULL_IS_NULL
+ if ( ld->ld_matched )
+#endif /* LDAP_NULL_IS_NULL */
+ {
+ *matcheddnp = LDAP_STRDUP( ld->ld_matched );
+ }
}
if( errmsgp != NULL ) {
- *errmsgp = LDAP_STRDUP( ld->ld_error );
+#ifdef LDAP_NULL_IS_NULL
+ if ( ld->ld_error )
+#endif /* LDAP_NULL_IS_NULL */
+ {
+ *errmsgp = LDAP_STRDUP( ld->ld_error );
+ }
}
if( referralsp != NULL) {
return ld->ld_errno;
}
+#ifdef LDAP_NULL_IS_NULL
+ rc = ber_scanf( ber, "{eAA" /*}*/, &errcode,
+ &ld->ld_matched, &ld->ld_error );
+#else /* ! LDAP_NULL_IS_NULL */
rc = ber_scanf( ber, "{eaa" /*}*/, &errcode,
&ld->ld_matched, &ld->ld_error );
+#endif /* ! LDAP_NULL_IS_NULL */
if( rc == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return ld->ld_errno;
}
+#ifdef LDAP_NULL_IS_NULL
+ assert( resoid[ 0 ] != '\0' );
+#endif /* LDAP_NULL_IS_NULL */
+
tag = ber_peek_tag( ber, &len );
}
return ld->ld_errno;
}
+#ifdef LDAP_NULL_IS_NULL
+ assert( resoid[ 0 ] != '\0' );
+#endif /* LDAP_NULL_IS_NULL */
+
tag = ber_peek_tag( ber, &len );
}
if( ld->ld_matched == NULL ) {
* (char **) outvalue = NULL;
} else {
- * (char **) outvalue = LDAP_STRDUP(ld->ld_matched);
+ * (char **) outvalue = LDAP_STRDUP( ld->ld_matched );
}
return LDAP_OPT_SUCCESS;
if( ld->ld_error ) {
LDAP_FREE(ld->ld_error);
+ ld->ld_error = NULL;
}
- ld->ld_error = LDAP_STRDUP(err);
+ if ( err ) {
+ ld->ld_error = LDAP_STRDUP(err);
+ }
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_MATCHED_DN: {
- const char *err = (const char *) invalue;
+ const char *matched = (const char *) invalue;
- if(ld == NULL) {
+ if (ld == NULL) {
/* need a struct ldap */
break;
}
if( ld->ld_matched ) {
LDAP_FREE(ld->ld_matched);
+ ld->ld_matched = NULL;
}
- ld->ld_matched = LDAP_STRDUP(err);
+ if ( matched ) {
+ ld->ld_matched = LDAP_STRDUP( matched );
+ }
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_REFERRAL_URLS: {
ber_len_t len;
char *lr_res_error = NULL;
+#ifdef LDAP_NULL_IS_NULL
+ if ( ber_scanf( &tmpber, "{eAA",/*}*/ &lderr,
+ &lr->lr_res_matched, &lr_res_error )
+ != LBER_ERROR )
+#else /* ! LDAP_NULL_IS_NULL */
if ( ber_scanf( &tmpber, "{eaa",/*}*/ &lderr,
&lr->lr_res_matched, &lr_res_error )
!= LBER_ERROR )
+#endif /* ! LDAP_NULL_IS_NULL */
{
if ( lr_res_error != NULL ) {
- if ( lr->lr_res_error != NULL ) {
- (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error );
- LDAP_FREE( (char *)lr_res_error );
+#ifndef LDAP_NULL_IS_NULL
+ if ( lr_res_error[ 0 ] == '\0' ) {
+ LDAP_FREE( lr_res_error );
+ lr_res_error = NULL;
+ } else
+#endif /* ! LDAP_NULL_IS_NULL */
+ {
+ if ( lr->lr_res_error != NULL ) {
+ (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error );
+ LDAP_FREE( (char *)lr_res_error );
- } else {
- lr->lr_res_error = lr_res_error;
+ } else {
+ lr->lr_res_error = lr_res_error;
+ }
}
+ lr_res_error = NULL;
}
/* Check if V3 referral */
*/
if ( tag == LDAP_RES_SEARCH_RESULT )
refer_cnt = 0;
+#ifdef LDAP_NULL_IS_NULL
+ } else if ( ber_scanf( &tmpber, "{eAA}", &lderr,
+ &lr->lr_res_matched, &lr_res_error )
+ != LBER_ERROR )
+#else /* ! LDAP_NULL_IS_NULL */
} else if ( ber_scanf( &tmpber, "{eaa}", &lderr,
&lr->lr_res_matched, &lr_res_error )
!= LBER_ERROR )
+#endif /* ! LDAP_NULL_IS_NULL */
{
if ( lr_res_error != NULL ) {
- if ( lr->lr_res_error != NULL ) {
- (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error );
- LDAP_FREE( (char *)lr_res_error );
- } else {
- lr->lr_res_error = lr_res_error;
+#ifndef LDAP_NULL_IS_NULL
+ if ( lr_res_error[ 0 ] == '\0' ) {
+ LDAP_FREE( lr_res_error );
+ } else
+#endif /* ! LDAP_NULL_IS_NULL */
+ {
+ if ( lr->lr_res_error != NULL ) {
+ (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error );
+ LDAP_FREE( (char *)lr_res_error );
+ } else {
+ lr->lr_res_error = lr_res_error;
+ }
}
lr_res_error = NULL;
}
} else {
lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
}
-Debug( LDAP_DEBUG_TRACE,
- "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
- lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
- lr->lr_res_matched ? lr->lr_res_matched : "" );
+
+ Debug( LDAP_DEBUG_TRACE, "new result: "
+ "res_errno: %d, "
+ "res_error: <%s>, "
+ "res_matched: <%s>\n",
+ lr->lr_res_errno,
+ lr->lr_res_error ? lr->lr_res_error : "",
+ lr->lr_res_matched ? lr->lr_res_matched : "" );
+ }
+
+ /* in any case, don't leave any lr_res_error 'round */
+ if ( lr_res_error ) {
+ LDAP_FREE( lr_res_error );
}
}
}
if ( ld->ld_version < LDAP_VERSION2 ) {
+#ifdef LDAP_NULL_IS_NULL
+ tag = ber_scanf( ber, "{iA}",
+ &errcode, &ld->ld_error );
+#else /* ! LDAP_NULL_IS_NULL */
tag = ber_scanf( ber, "{ia}",
&errcode, &ld->ld_error );
+#endif /* ! LDAP_NULL_IS_NULL */
if( tag == LBER_ERROR ) {
ber_free( ber, 0 );
} else {
ber_len_t len;
+#ifdef LDAP_NULL_IS_NULL
+ tag = ber_scanf( ber, "{eAA" /*}*/,
+ &errcode, &ld->ld_matched, &ld->ld_error );
+#else /* ! LDAP_NULL_IS_NULL */
tag = ber_scanf( ber, "{eaa" /*}*/,
&errcode, &ld->ld_matched, &ld->ld_error );
+#endif /* ! LDAP_NULL_IS_NULL */
if( tag == LBER_ERROR ) {
ber_free( ber, 0 );