X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fufn.c;h=db21748c8db8d0fe6d3441902b648d8f1a32d52f;hb=49d73e12a720cfe052a335d82e67994ff261d21c;hp=9596adf131dcee892fb90b5dea07a43cfd14919f;hpb=42e0d83cb3a1a1c5b25183f1ab74ce7edbe25de7;p=openldap diff --git a/libraries/libldap/ufn.c b/libraries/libldap/ufn.c index 9596adf131..db21748c8d 100644 --- a/libraries/libldap/ufn.c +++ b/libraries/libldap/ufn.c @@ -1,55 +1,39 @@ +/* $OpenLDAP$ */ /* + * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* Portions * Copyright (c) 1990 Regents of the University of Michigan. * All rights reserved. * * ufn.c */ -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif +#include "portable.h" #include -#include -#include - -#ifdef MACOS -#include -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include "msdos.h" -#else /* DOS */ -#include -#include -#include -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" - -#ifdef NEEDPROTOS -typedef int (*cancelptype)( void *cancelparm ); -#else /* NEEDPROTOS */ -typedef int (*cancelptype)(); -#endif /* NEEDPROTOS */ - -#ifdef NEEDPROTOS -static int ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, + +#include + +#include +#include +#include + +#include "ldap-int.h" +#include "ldap_defaults.h" + +typedef int (*cancelptype) LDAP_P(( void *cancelparm )); + +/* local functions */ +static int ldap_ufn_search_ctx LDAP_P(( LDAP *ld, char **ufncomp, int ncomp, char *prefix, char **attrs, int attrsonly, LDAPMessage **res, cancelptype cancelproc, void *cancelparm, char *tag1, char *tag2, - char *tag3 ); -static LDAPMessage *ldap_msg_merge( LDAP *ld, LDAPMessage *a, LDAPMessage *b ); -static LDAPMessage *ldap_ufn_expand( LDAP *ld, cancelptype cancelproc, + char *tag3 )); +static LDAPMessage *ldap_msg_merge LDAP_P(( LDAP *ld, LDAPMessage *a, LDAPMessage *b )); +static LDAPMessage *ldap_ufn_expand LDAP_P(( LDAP *ld, cancelptype cancelproc, void *cancelparm, char **dns, char *filter, int scope, - char **attrs, int aonly, int *err ); -LDAPFiltDesc *ldap_ufn_setfilter( LDAP *ld, char *fname ); -#else /* NEEDPROTOS */ -static LDAPMessage *ldap_msg_merge(); -static LDAPMessage *ldap_ufn_expand(); -LDAPFiltDesc *ldap_ufn_setfilter(); -#endif /* NEEDPROTOS */ + char **attrs, int aonly, int *err )); /* * ldap_ufn_search_ctx - do user friendly searching; provide cancel feature; @@ -63,8 +47,8 @@ LDAPFiltDesc *ldap_ufn_setfilter(); * 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 @@ -83,13 +67,12 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, char **attrs, int attrsonly, LDAPMessage **res, cancelptype cancelproc, void *cancelparm, char *tag1, char *tag2, char *tag3 ) { - char *dn, *ftag; - char **dns; - int max, i, err, scope, phase, tries; + char *dn, *ftag = NULL; + char **dns = NULL; + int max, i, err, scope = 0, phase, tries; LDAPFiltInfo *fi; LDAPMessage *tmpcand; LDAPMessage *candidates; - LDAPMessage *ldap_msg_merge(), *ldap_ufn_expand(); static char *objattrs[] = { "objectClass", NULL }; /* @@ -115,7 +98,8 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, if ( (quote = strrchr( ufncomp[ncomp], '"' )) != NULL ) *quote = '\0'; - strcpy( ufncomp[ncomp], ufncomp[ncomp] + 1 ); + SAFEMEMCPY( ufncomp[ncomp], ufncomp[ncomp] + 1, + strlen( ufncomp[ncomp] + 1 ) + 1 ); } if ( ncomp == 0 ) phase = 3; @@ -142,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; @@ -161,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 ) { @@ -200,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 ); @@ -213,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 ); @@ -224,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; } } @@ -234,13 +218,14 @@ 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 ) { char **ufncomp, **prefixcomp; char *pbuf; - int ncomp, pcomp, i, err; + int ncomp, pcomp, i, err = 0; /* initialize the getfilter stuff if it's not already */ if ( ld->ld_filtd == NULL && ldap_ufn_setfilter( ld, FILTERFILE ) @@ -260,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 ); @@ -269,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 ); } @@ -307,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 ); } @@ -319,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, @@ -330,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; @@ -444,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; @@ -476,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 ); @@ -485,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