X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fufn.c;h=9d215cdec999aa45eb2333482374cbee70225c60;hb=91e24173d0fa168bdd3e585af2d56f3299a20c00;hp=f87af4d87a710fb1a55990e6b1ce8e28970d190d;hpb=13bd786abf3248e39428a8edac67c27772cb8dc0;p=openldap diff --git a/libraries/libldap/ufn.c b/libraries/libldap/ufn.c index f87af4d87a..9d215cdec9 100644 --- a/libraries/libldap/ufn.c +++ b/libraries/libldap/ufn.c @@ -1,4 +1,9 @@ +/* $OpenLDAP$ */ /* + * Copyright 1998-1999 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. * @@ -7,24 +12,21 @@ #include "portable.h" -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - #include -#include -#include -#include -#include +#include -#include "lber.h" -#include "ldap.h" +#include +#include +#include +#include -#include "ldapconfig.h" +#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, @@ -33,7 +35,6 @@ static LDAPMessage *ldap_msg_merge LDAP_P(( LDAP *ld, LDAPMessage *a, LDAPMessag 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_P(( LDAP *ld, char *fname )); /* * ldap_ufn_search_ctx - do user friendly searching; provide cancel feature; @@ -47,8 +48,8 @@ LDAPFiltDesc *ldap_ufn_setfilter LDAP_P(( LDAP *ld, char *fname )); * 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 @@ -73,7 +74,6 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix, LDAPFiltInfo *fi; LDAPMessage *tmpcand; LDAPMessage *candidates; - LDAPMessage *ldap_msg_merge(), *ldap_ufn_expand(); static char *objattrs[] = { "objectClass", NULL }; /* @@ -99,7 +99,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; @@ -126,11 +127,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; @@ -145,14 +146,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 ) { @@ -218,7 +219,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 ) { @@ -264,7 +266,7 @@ ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, } 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 ); @@ -293,7 +295,7 @@ ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly, ldap_value_free( ufncomp ); ldap_value_free( prefixcomp ); - free( pbuf ); + LDAP_FREE( pbuf ); return( err ); } @@ -303,7 +305,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, @@ -314,7 +317,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; @@ -428,7 +432,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; @@ -460,7 +464,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 ); @@ -469,12 +473,12 @@ 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 = LDAP_STRDUP( prefix ); } int