From: Kurt Zeilenga Date: Sat, 5 Jun 1999 20:18:32 +0000 (+0000) Subject: s/LDAP_OPT_MATCHED_STRING/LDAP_OPT_MATCHED_DN/ X-Git-Tag: OPENLDAP_REL_ENG_2_BP~397 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8c772985c7b7300665a30932d71d45c8af24af21;p=openldap s/LDAP_OPT_MATCHED_STRING/LDAP_OPT_MATCHED_DN/ Added place holder for LDAP_FILTER_EXTENDED code. Added assert() here and there and removed lint. Removed version promotion code (version must be manually set). Added messages.c to MSVC project. --- diff --git a/libraries/libldap/add.c b/libraries/libldap/add.c index 56ce242e48..d945988a39 100644 --- a/libraries/libldap/add.c +++ b/libraries/libldap/add.c @@ -87,7 +87,10 @@ ldap_add( LDAP *ld, LDAP_CONST char *dn, LDAPMod **attrs ) * rc = ldap_add_ext( ld, dn, attrs, NULL, NULL, &msgid ); */ int -ldap_add_ext( LDAP *ld, LDAP_CONST char *dn, LDAPMod **attrs, +ldap_add_ext( + LDAP *ld, + LDAP_CONST char *dn, + LDAPMod **attrs, LDAPControl **sctrls, LDAPControl **cctrls, int *msgidp ) @@ -96,6 +99,10 @@ ldap_add_ext( LDAP *ld, LDAP_CONST char *dn, LDAPMod **attrs, int i, rc; Debug( LDAP_DEBUG_TRACE, "ldap_add\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( dn != NULL ); + assert( msgidp != NULL ); /* create a message to send */ if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) { diff --git a/libraries/libldap/bind.c b/libraries/libldap/bind.c index 9fc07d4c40..6f807e789e 100644 --- a/libraries/libldap/bind.c +++ b/libraries/libldap/bind.c @@ -135,5 +135,8 @@ void ldap_set_rebind_proc( LDAP *ld, int (*rebindproc)( LDAP *ld, char **dnp, char **passwdp, int *authmethodp, int freeit )) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + ld->ld_rebindproc = rebindproc; } diff --git a/libraries/libldap/compare.c b/libraries/libldap/compare.c index 072def5471..21a99aa80d 100644 --- a/libraries/libldap/compare.c +++ b/libraries/libldap/compare.c @@ -54,6 +54,12 @@ ldap_compare_ext( Debug( LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( dn != NULL ); + assert( attr != NULL ); + assert( msgidp != NULL ); + /* create a message to send */ if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) { return( LDAP_NO_MEMORY ); diff --git a/libraries/libldap/controls.c b/libraries/libldap/controls.c index 13a0b13a09..f330685616 100644 --- a/libraries/libldap/controls.c +++ b/libraries/libldap/controls.c @@ -218,6 +218,8 @@ int ldap_int_get_controls LDAP_P(( void ldap_control_free( LDAPControl *c ) { + assert( c != NULL ); + if ( c != NULL ) { if( c->ldctl_oid != NULL) { LDAP_FREE( c->ldctl_oid ); @@ -237,6 +239,8 @@ ldap_control_free( LDAPControl *c ) void ldap_controls_free( LDAPControl **controls ) { + assert( controls != NULL ); + if ( controls != NULL ) { LDAPControl *c; diff --git a/libraries/libldap/delete.c b/libraries/libldap/delete.c index b132dde3b2..b5602db2eb 100644 --- a/libraries/libldap/delete.c +++ b/libraries/libldap/delete.c @@ -48,6 +48,11 @@ ldap_delete_ext( Debug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( dn != NULL ); + assert( msgidp != NULL ); + /* create a message to send */ if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) { ld->ld_errno = LDAP_NO_MEMORY; diff --git a/libraries/libldap/error.c b/libraries/libldap/error.c index 93e586363d..41147c7609 100644 --- a/libraries/libldap/error.c +++ b/libraries/libldap/error.c @@ -120,15 +120,15 @@ ldap_err2string( int err ) void ldap_perror( LDAP *ld, LDAP_CONST char *str ) { - char *s; + const char *s; struct ldaperror *e; Debug( LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0 ); assert( ld != NULL ); assert( LDAP_VALID( ld ) ); - assert( s ); + assert( str ); - s = ( str != NULL ) ? (char *) str : "ldap_perror"; + s = ( str != NULL ) ? str : "ldap_perror"; if ( ld == NULL ) { perror( s ); diff --git a/libraries/libldap/extended.c b/libraries/libldap/extended.c index 72657c3476..31b4dd146c 100644 --- a/libraries/libldap/extended.c +++ b/libraries/libldap/extended.c @@ -49,10 +49,6 @@ ldap_extended_operation( assert( msgidp != NULL ); /* must be version 3 (or greater) */ - if ( ld->ld_version == 0 ) { - ld->ld_version = LDAP_VERSION3; - } - if ( ld->ld_version < LDAP_VERSION3 ) { ld->ld_errno = LDAP_NOT_SUPPORTED; return( ld->ld_errno ); diff --git a/libraries/libldap/free.c b/libraries/libldap/free.c index 99257665a4..f9569dd04a 100644 --- a/libraries/libldap/free.c +++ b/libraries/libldap/free.c @@ -126,6 +126,7 @@ ldap_mods_free( LDAPMod **mods, int freemods ) LDAP_FREE( (char *) mods[i] ); } - if ( freemods ) + if ( freemods ) { LDAP_FREE( (char *) mods ); + } } diff --git a/libraries/libldap/getattr.c b/libraries/libldap/getattr.c index 5a6d77066e..fc4d31f56a 100644 --- a/libraries/libldap/getattr.c +++ b/libraries/libldap/getattr.c @@ -26,12 +26,13 @@ ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber ) { char *attr; + Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); assert( entry != NULL ); assert( ber != NULL ); - Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 ); - if ( (*ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) { *ber = NULL; return( NULL ); @@ -62,12 +63,13 @@ ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber ) { char *attr; + Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); assert( entry != NULL ); assert( ber != NULL ); - Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 ); - /* skip sequence, snarf attribute type, skip values */ if ( ber_scanf( ber, "{ax}", &attr ) == LBER_ERROR ) { diff --git a/libraries/libldap/getentry.c b/libraries/libldap/getentry.c index 9e2e49c4db..8724758b84 100644 --- a/libraries/libldap/getentry.c +++ b/libraries/libldap/getentry.c @@ -25,6 +25,9 @@ LDAPMessage * ldap_first_entry( LDAP *ld, LDAPMessage *chain ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + if( ld == NULL || chain == NULLMSG ) { return NULLMSG; } @@ -34,10 +37,12 @@ ldap_first_entry( LDAP *ld, LDAPMessage *chain ) : ldap_next_entry( ld, chain ); } -/* ARGSUSED */ LDAPMessage * ldap_next_entry( LDAP *ld, LDAPMessage *entry ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + if ( ld == NULL || entry == NULLMSG ) { return NULLMSG; } @@ -55,12 +60,14 @@ ldap_next_entry( LDAP *ld, LDAPMessage *entry ) return( NULLMSG ); } -/* ARGSUSED */ int ldap_count_entries( LDAP *ld, LDAPMessage *chain ) { int i; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + if ( ld == NULL ) { return -1; } @@ -78,12 +85,17 @@ int ldap_get_entry_controls( LDAP *ld, LDAPMessage *entry, - LDAPControl ***serverctrls) + LDAPControl ***sctrls ) { int rc; BerElement be; - if ( ld == NULL || serverctrls == NULL || + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( entry != NULL ); + assert( sctrls != NULL ); + + if ( ld == NULL || sctrls == NULL || entry == NULL || entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) { return LDAP_PARAM_ERROR; @@ -97,7 +109,7 @@ ldap_get_entry_controls( goto cleanup_and_return; } - rc = ldap_int_get_controls( &be, serverctrls ); + rc = ldap_int_get_controls( &be, sctrls ); cleanup_and_return: if( rc != LDAP_SUCCESS ) { diff --git a/libraries/libldap/libldap.dsp b/libraries/libldap/libldap.dsp index 2bebd67640..e16dac581b 100644 --- a/libraries/libldap/libldap.dsp +++ b/libraries/libldap/libldap.dsp @@ -255,6 +255,10 @@ SOURCE=..\..\include\ldapconfig.h # End Source File # Begin Source File +SOURCE=.\messages.c +# End Source File +# Begin Source File + SOURCE=.\modify.c # End Source File # Begin Source File diff --git a/libraries/libldap/messages.c b/libraries/libldap/messages.c index eea7bed70c..a67aecc860 100644 --- a/libraries/libldap/messages.c +++ b/libraries/libldap/messages.c @@ -19,18 +19,25 @@ #include "ldap-int.h" -/* ARGSUSED */ LDAPMessage * ldap_first_message( LDAP *ld, LDAPMessage *chain ) { - return( ld == NULL || chain == NULLMSG - ? NULLMSG : chain ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + + if ( ld == NULL || chain == NULLMSG ) { + return NULLMSG; + } + + return chain; } -/* ARGSUSED */ LDAPMessage * ldap_next_message( LDAP *ld, LDAPMessage *msg ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + if ( ld == NULL || msg == NULLMSG || msg->lm_chain == NULL ) { return NULLMSG; } @@ -38,12 +45,14 @@ ldap_next_message( LDAP *ld, LDAPMessage *msg ) return( msg->lm_chain ); } -/* ARGSUSED */ int ldap_count_messages( LDAP *ld, LDAPMessage *chain ) { int i; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + if ( ld == NULL ) { return -1; } diff --git a/libraries/libldap/modrdn.c b/libraries/libldap/modrdn.c index f9b435aa05..d2885bd63e 100644 --- a/libraries/libldap/modrdn.c +++ b/libraries/libldap/modrdn.c @@ -76,10 +76,6 @@ ldap_rename( if( newSuperior != NULL ) { /* must be version 3 (or greater) */ - if ( ld->ld_version == 0 ) { - ld->ld_version = LDAP_VERSION3; - } - if ( ld->ld_version < LDAP_VERSION3 ) { ld->ld_errno = LDAP_NOT_SUPPORTED; ber_free( ber, 1 ); diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 9985a2bf23..3e748a7848 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -200,12 +200,6 @@ ldap_get_option( return LDAP_OPT_SUCCESS; case LDAP_OPT_HOST_NAME: - /* - * draft-ietf-ldapext-ldap-c-api-01 doesn't state - * whether caller has to free host names or not, - * we do. - */ - * (char **) outvalue = LDAP_STRDUP(lo->ldo_defhost); return LDAP_OPT_SUCCESS; @@ -223,11 +217,6 @@ ldap_get_option( break; } - /* - * draft-ietf-ldapext-ldap-c-api-01 doesn't require - * the client to have to free error strings, we do - */ - if( ld->ld_error == NULL ) { * (char **) outvalue = NULL; } else { @@ -236,24 +225,19 @@ ldap_get_option( return LDAP_OPT_SUCCESS; - case LDAP_OPT_MATCH_STRING: + case LDAP_OPT_MATCHED_DN: if(ld == NULL) { /* bad param */ break; } - /* - * draft-ietf-ldapext-ldap-c-api-01 doesn't require - * the client to have to free error strings, we do - */ - if( ld->ld_matched == NULL ) { * (char **) outvalue = NULL; } else { * (char **) outvalue = LDAP_STRDUP(ld->ld_matched); } - return 0; + return LDAP_OPT_SUCCESS; case LDAP_OPT_API_FEATURE_INFO: { LDAPAPIFeatureInfo *info = (LDAPAPIFeatureInfo *) outvalue; @@ -460,6 +444,21 @@ ldap_set_option( ld->ld_error = LDAP_STRDUP(err); } return LDAP_OPT_SUCCESS; + case LDAP_OPT_MATCHED_DN: { + char* err = (char *) invalue; + + if(ld == NULL) { + /* need a struct ldap */ + break; + } + + if( ld->ld_matched ) { + LDAP_FREE(ld->ld_matched); + } + + ld->ld_matched = LDAP_STRDUP(err); + } return LDAP_OPT_SUCCESS; + case LDAP_OPT_API_FEATURE_INFO: /* read-only */ break; diff --git a/libraries/libldap/sbind.c b/libraries/libldap/sbind.c index 6d194a8657..fd7892d5e6 100644 --- a/libraries/libldap/sbind.c +++ b/libraries/libldap/sbind.c @@ -58,6 +58,9 @@ ldap_simple_bind( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd ) Debug( LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0 ); + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + if ( dn == NULL ) dn = ""; if ( passwd == NULL ) diff --git a/libraries/libldap/search.c b/libraries/libldap/search.c index d6e7584e18..d1afce7c0a 100644 --- a/libraries/libldap/search.c +++ b/libraries/libldap/search.c @@ -22,13 +22,31 @@ #include "ldap-int.h" -static char *find_right_paren LDAP_P(( char *s )); -static char *put_complex_filter LDAP_P(( BerElement *ber, char *str, - unsigned long tag, int not )); -static int put_filter LDAP_P(( BerElement *ber, char *str )); -static int put_simple_filter LDAP_P(( BerElement *ber, char *str )); -static int put_substring_filter LDAP_P(( BerElement *ber, char *type, char *str )); -static int put_filter_list LDAP_P(( BerElement *ber, char *str )); +static char *find_right_paren LDAP_P(( + char *s )); + +static char *put_complex_filter LDAP_P(( + BerElement *ber, + char *str, + unsigned long tag, + int not )); + +static int put_filter LDAP_P(( + BerElement *ber, + char *str )); + +static int put_simple_filter LDAP_P(( + BerElement *ber, + char *str )); + +static int put_substring_filter LDAP_P(( + BerElement *ber, + char *type, + char *str )); + +static int put_filter_list LDAP_P(( + BerElement *ber, + char *str )); /* * ldap_search_ext - initiate an ldap search operation. @@ -341,11 +359,6 @@ put_complex_filter( BerElement *ber, char *str, unsigned long tag, int not ) if ( ber_printf( ber, "t{", tag ) == -1 ) return( NULL ); -#if 0 - if ( !not && ber_printf( ber, "{" ) == -1 ) - return( NULL ); -#endif - str++; if ( (next = find_right_paren( str )) == NULL ) return( NULL ); @@ -359,11 +372,6 @@ put_complex_filter( BerElement *ber, char *str, unsigned long tag, int not ) if ( ber_printf( ber, "}" ) == -1 ) return( NULL ); -#if 0 - if ( !not && ber_printf( ber, "}" ) == -1 ) - return( NULL ); -#endif - return( next ); } @@ -576,7 +584,9 @@ put_filter_list( BerElement *ber, char *str ) } static int -put_simple_filter( BerElement *ber, char *str ) +put_simple_filter( + BerElement *ber, + char *str ) { char *s; char *value, savechar; @@ -604,6 +614,10 @@ put_simple_filter( BerElement *ber, char *str ) ftype = LDAP_FILTER_APPROX; *s = '\0'; break; + case ':': /* LDAPv3 extended filter */ + ftype = LDAP_FILTER_EXTENDED; + return -1; + break; default: if ( strchr( value, '*' ) == NULL ) { ftype = LDAP_FILTER_EQUALITY;