+/* $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.
*
#include "portable.h"
-#ifndef lint
-static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
-
#include <stdio.h>
-#include <ac/string.h>
-#include <ctype.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
#include <ac/socket.h>
+#include <ac/string.h>
#include <ac/time.h>
#include "ldap-int.h"
-#include "ldapconfig.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,
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;
* 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
LDAPFiltInfo *fi;
LDAPMessage *tmpcand;
LDAPMessage *candidates;
- LDAPMessage *ldap_msg_merge(), *ldap_ufn_expand();
static char *objattrs[] = { "objectClass", NULL };
/*
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;
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;
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 )
{
if ( err == -1 || err == LDAP_USER_CANCELLED ) {
if ( dns != NULL ) {
- ldap_value_free( dns );
+ LDAP_VFREE( dns );
dns = NULL;
}
return( err );
goto tryagain;
} else {
if ( dns != NULL ) {
- ldap_value_free( dns );
+ LDAP_VFREE( dns );
dns = NULL;
}
return( err );
if ( phase == 1 )
phase++;
if ( dns != NULL ) {
- ldap_value_free( dns );
+ LDAP_VFREE( dns );
dns = NULL;
}
}
}
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 )
{
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 );
}
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 );
}
}
}
- ldap_value_free( ufncomp );
- ldap_value_free( prefixcomp );
- free( pbuf );
+ LDAP_VFREE( ufncomp );
+ LDAP_VFREE( prefixcomp );
+ LDAP_FREE( pbuf );
return( err );
}
* 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,
* 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;
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;
*/
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 );
}
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