X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fufn.c;h=db21748c8db8d0fe6d3441902b648d8f1a32d52f;hb=49d73e12a720cfe052a335d82e67994ff261d21c;hp=342bd8a1e94e1068b2374780c5cf84e37d8563cf;hpb=027d2fadc635098e4238f3acc391748ba87950e4;p=openldap diff --git a/libraries/libldap/ufn.c b/libraries/libldap/ufn.c index 342bd8a1e9..db21748c8d 100644 --- a/libraries/libldap/ufn.c +++ b/libraries/libldap/ufn.c @@ -1,5 +1,6 @@ +/* $OpenLDAP$ */ /* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ /* Portions @@ -12,15 +13,15 @@ #include "portable.h" #include -#include -#include -#include + +#include #include +#include #include #include "ldap-int.h" -#include "ldapconfig.h" +#include "ldap_defaults.h" typedef int (*cancelptype) LDAP_P(( void *cancelparm )); @@ -46,8 +47,8 @@ static LDAPMessage *ldap_ufn_expand LDAP_P(( LDAP *ld, cancelptype cancelproc, * attrsonly 1 => attributes only 0 => attributes and values * res will contain the result of the search * cancelproc routine that returns non-zero if operation should be - * cancelled. This can be NULL. If it is non-NULL, the - * routine will be called periodically. + * cancelled. This can be a null function pointer. If + * it is not 0, the routine will be called periodically. * cancelparm void * that is passed to cancelproc * tag[123] the ldapfilter.conf tag that will be used in phases * 1, 2, and 3 of the search, respectively @@ -125,11 +126,11 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, if ( candidates == NULL ) { if ( prefix != NULL ) { - if ( (dns = (char **) malloc( sizeof(char *) + if ( (dns = (char **) LDAP_MALLOC( sizeof(char *) * 2 )) == NULL ) { return( ld->ld_errno = LDAP_NO_MEMORY ); } - dns[0] = strdup( prefix ); + dns[0] = LDAP_STRDUP( prefix ); dns[1] = NULL; } else { dns = NULL; @@ -144,14 +145,14 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, continue; if ( dns == NULL ) { - if ( (dns = (char **) malloc( + if ( (dns = (char **) LDAP_MALLOC( sizeof(char *) * 8 )) == NULL ) { ld->ld_errno = LDAP_NO_MEMORY; return( LDAP_NO_MEMORY ); } max = 8; } else if ( i >= max ) { - if ( (dns = (char **) realloc( dns, + if ( (dns = (char **) LDAP_REALLOC( dns, sizeof(char *) * 2 * max )) == NULL ) { @@ -183,7 +184,7 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, if ( err == -1 || err == LDAP_USER_CANCELLED ) { if ( dns != NULL ) { - ldap_value_free( dns ); + LDAP_VFREE( dns ); dns = NULL; } return( err ); @@ -196,7 +197,7 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, goto tryagain; } else { if ( dns != NULL ) { - ldap_value_free( dns ); + LDAP_VFREE( dns ); dns = NULL; } return( err ); @@ -207,7 +208,7 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, if ( phase == 1 ) phase++; if ( dns != NULL ) { - ldap_value_free( dns ); + LDAP_VFREE( dns ); dns = NULL; } } @@ -217,7 +218,8 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, } int -ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, +ldap_ufn_search_ct( + LDAP *ld, LDAP_CONST char *ufn, char **attrs, int attrsonly, LDAPMessage **res, cancelptype cancelproc, void *cancelparm, char *tag1, char *tag2, char *tag3 ) { @@ -243,7 +245,7 @@ ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, attrsonly, res, cancelproc, cancelparm, tag1, tag2, tag3 ); if ( ldap_count_entries( ld, *res ) > 0 ) { - ldap_value_free( ufncomp ); + LDAP_VFREE( ufncomp ); return( err ); } else { ldap_msgfree( *res ); @@ -252,21 +254,21 @@ ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, } if ( ld->ld_ufnprefix == NULL ) { - ldap_value_free( ufncomp ); + LDAP_VFREE( ufncomp ); return( err ); } /* if that failed, or < 2 components, use the prefix */ if ( (prefixcomp = ldap_explode_dn( ld->ld_ufnprefix, 0 )) == NULL ) { - ldap_value_free( ufncomp ); + LDAP_VFREE( ufncomp ); return( ld->ld_errno = LDAP_LOCAL_ERROR ); } for ( pcomp = 0; prefixcomp[pcomp] != NULL; pcomp++ ) ; /* NULL */ - if ( (pbuf = (char *) malloc( strlen( ld->ld_ufnprefix ) + 1 )) + if ( (pbuf = (char *) LDAP_MALLOC( strlen( ld->ld_ufnprefix ) + 1 )) == NULL ) { - ldap_value_free( ufncomp ); - ldap_value_free( prefixcomp ); + LDAP_VFREE( ufncomp ); + LDAP_VFREE( prefixcomp ); return( ld->ld_errno = LDAP_NO_MEMORY ); } @@ -290,9 +292,9 @@ ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, } } - ldap_value_free( ufncomp ); - ldap_value_free( prefixcomp ); - free( pbuf ); + LDAP_VFREE( ufncomp ); + LDAP_VFREE( prefixcomp ); + LDAP_FREE( pbuf ); return( err ); } @@ -302,7 +304,8 @@ ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, * ldapfilter.conf tags. */ int -ldap_ufn_search_c( LDAP *ld, char *ufn, char **attrs, int attrsonly, +ldap_ufn_search_c( + LDAP *ld, LDAP_CONST char *ufn, char **attrs, int attrsonly, LDAPMessage **res, cancelptype cancelproc, void *cancelparm ) { return( ldap_ufn_search_ct( ld, ufn, attrs, attrsonly, res, cancelproc, @@ -313,7 +316,8 @@ ldap_ufn_search_c( LDAP *ld, char *ufn, char **attrs, int attrsonly, * same as ldap_ufn_search_c without the cancel function */ int -ldap_ufn_search_s( LDAP *ld, char *ufn, char **attrs, int attrsonly, +ldap_ufn_search_s( + LDAP *ld, LDAP_CONST char *ufn, char **attrs, int attrsonly, LDAPMessage **res ) { struct timeval tv; @@ -427,7 +431,7 @@ ldap_ufn_expand( LDAP *ld, cancelptype cancelproc, void *cancelparm, do { *err = ldap_result( ld, msgid, 1, &tv, &tmpres ); - if ( *err == 0 && cancelproc != NULL && + if ( *err == 0 && cancelproc != 0 && (*cancelproc)( cancelparm ) != 0 ) { ldap_abandon( ld, msgid ); *err = LDAP_USER_CANCELLED; @@ -459,7 +463,7 @@ ldap_ufn_expand( LDAP *ld, cancelptype cancelproc, void *cancelparm, */ LDAPFiltDesc * -ldap_ufn_setfilter( LDAP *ld, char *fname ) +ldap_ufn_setfilter( LDAP *ld, LDAP_CONST char *fname ) { if ( ld->ld_filtd != NULL ) ldap_getfilter_free( ld->ld_filtd ); @@ -468,12 +472,13 @@ ldap_ufn_setfilter( LDAP *ld, char *fname ) } void -ldap_ufn_setprefix( LDAP *ld, char *prefix ) +ldap_ufn_setprefix( LDAP *ld, LDAP_CONST char *prefix ) { if ( ld->ld_ufnprefix != NULL ) - free( ld->ld_ufnprefix ); + LDAP_FREE( ld->ld_ufnprefix ); - ld->ld_ufnprefix = strdup( prefix ); + ld->ld_ufnprefix = prefix == NULL + ? NULL : LDAP_STRDUP( prefix ); } int