Add ber_strdup(), remove ldap_int_strdup(), add LDAP_STRDUP macro

and ripple change through -lldap.
This commit is contained in:
Kurt Zeilenga 1999-06-02 22:28:22 +00:00
parent bed6465529
commit 1f52f6e43e
22 changed files with 70 additions and 66 deletions

View file

@ -458,6 +458,10 @@ LDAP_F( struct berval * )
ber_bvdup LDAP_P((
LDAP_CONST struct berval *bv ));
LDAP_F( char * )
ber_strdup LDAP_P((
LDAP_CONST char * ));
LDAP_END_DECL
#endif /* _LBER_H */

View file

@ -200,12 +200,14 @@ extern BerMemoryFunctions* ber_int_memory_fns;
#define LBER_INT_REALLOC(p,s) ber_memrealloc((p),(s))
#define LBER_INT_FREE(p) ber_memfree((p))
#define LBER_INT_VFREE(v) ber_memvfree((void**)(v))
#define LBER_INT_STRDUP(s) ber_strdup((s))
#define LBER_MALLOC(s) ber_memalloc((s))
#define LBER_CALLOC(n,s) ber_memcalloc((n),(s))
#define LBER_REALLOC(p,s) ber_memrealloc((p),(s))
#define LBER_FREE(p) ber_memfree((p))
#define LBER_VFREE(v) ber_memvfree((void**)(v))
#define LBER_STRDUP(s) ber_strdup((s))
/* sockbuf.c */

View file

@ -241,3 +241,17 @@ ber_bvdup(
return( new );
}
char *
(ber_strdup)( LDAP_CONST char *s )
{
char *p;
size_t len = strlen( s ) + 1;
if ( (p = (char *) LBER_MALLOC( len )) == NULL ) {
return( NULL );
}
SAFEMEMCPY( p, s, len );
return( p );
}

View file

@ -143,7 +143,7 @@ cldap_open( char *host, int port )
}
if ( ld->ld_host == NULL ) {
ld->ld_host = strdup( host );
ld->ld_host = LDAP_STRDUP( host );
}
}
} else {

View file

@ -300,7 +300,7 @@ LDAPControl *ldap_control_dup( const LDAPControl *c )
}
if( c->ldctl_oid != NULL ) {
new->ldctl_oid = strdup( c->ldctl_oid );
new->ldctl_oid = LDAP_STRDUP( c->ldctl_oid );
if(new->ldctl_oid == NULL) {
LDAP_FREE( new );

View file

@ -388,7 +388,7 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) {
if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) *
sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
strdup( includeattrs[ i ] )) == NULL ) {
LDAP_STRDUP( includeattrs[ i ] )) == NULL ) {
memerr = 1;
} else {
attrs[ attrcnt ] = NULL;
@ -415,7 +415,7 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
if ( ticolp->ti_attrname != NULL ) {
if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) *
sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
strdup( ticolp->ti_attrname )) == NULL ) {
LDAP_STRDUP( ticolp->ti_attrname )) == NULL ) {
memerr = 1;
} else {
attrs[ attrcnt ] = NULL;

View file

@ -192,7 +192,7 @@ next_token( char **sp )
return( NULL );
}
return( strdup( tokstart ));
return( LDAP_STRDUP( tokstart ));
}

View file

@ -86,8 +86,8 @@ ldap_friendly_name(
}
}
(*map)[i].lf_unfriendly = strdup( buf );
(*map)[i].lf_friendly = strdup( s );
(*map)[i].lf_unfriendly = LDAP_STRDUP( buf );
(*map)[i].lf_friendly = LDAP_STRDUP( s );
i++;
}

View file

@ -54,9 +54,9 @@ ldap_dn2ufn( LDAP_CONST char *dn )
Debug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 );
if ( ldap_is_dns_dn( dn ) || ( p = strchr( dn, '=' )) == NULL )
return( strdup( dn ) );
return( LDAP_STRDUP( dn ) );
ufn = strdup( ++p );
ufn = LDAP_STRDUP( ++p );
#define INQUOTE 1
#define OUTQUOTE 2
@ -129,7 +129,7 @@ ldap_explode_dns( LDAP_CONST char *dn_in )
int ncomps;
int maxcomps = 8;
if ( (dn = strdup( dn_in )) == NULL ) {
if ( (dn = LDAP_STRDUP( dn_in )) == NULL ) {
return( NULL );
}
@ -151,7 +151,7 @@ ldap_explode_dns( LDAP_CONST char *dn_in )
return NULL;
}
}
rdns[ncomps++] = strdup( s );
rdns[ncomps++] = LDAP_STRDUP( s );
}
LDAP_FREE(dn);

View file

@ -49,7 +49,7 @@ ldap_getdxbyname( char *domain )
* punt: return list conisting of the original domain name only
*/
if (( dxs = (char **)LDAP_MALLOC( 2 * sizeof( char * ))) == NULL ||
( dxs[ 0 ] = strdup( domain )) == NULL ) {
( dxs[ 0 ] = LDAP_STRDUP( domain )) == NULL ) {
if ( dxs != NULL ) {
LDAP_FREE( dxs );
}

View file

@ -118,7 +118,7 @@ ldap_init_getfilter_buf( char *buf, long buflen )
ldap_getfilter_free( lfdp );
return( NULL );
}
nextflp->lfl_tag = strdup( tag );
nextflp->lfl_tag = LDAP_STRDUP( tag );
nextflp->lfl_pattern = tok[ 0 ];
if ( (rc = regcomp( &re, nextflp->lfl_pattern, 0 )) != 0 ) {
#ifdef LDAP_LIBUI
@ -213,12 +213,12 @@ ldap_setfilteraffixes( LDAPFiltDesc *lfdp, LDAP_CONST char *prefix, LDAP_CONST c
if ( lfdp->lfd_filtprefix != NULL ) {
LDAP_FREE( lfdp->lfd_filtprefix );
}
lfdp->lfd_filtprefix = ( prefix == NULL ) ? NULL : strdup( prefix );
lfdp->lfd_filtprefix = ( prefix == NULL ) ? NULL : LDAP_STRDUP( prefix );
if ( lfdp->lfd_filtsuffix != NULL ) {
LDAP_FREE( lfdp->lfd_filtsuffix );
}
lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : strdup( suffix );
lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : LDAP_STRDUP( suffix );
}
@ -270,7 +270,7 @@ ldap_getfirstfilter(
return( NULL );
}
if (( lfdp->lfd_curvalcopy = strdup( value )) == NULL ) {
if (( lfdp->lfd_curvalcopy = LDAP_STRDUP( value )) == NULL ) {
return( NULL );
}

View file

@ -166,7 +166,7 @@ static void openldap_ldap_init_w_conf(const char *file)
case ATTR_STRING:
p = &((char *) &gopts)[attrs[i].offset];
if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
* (char**) p = strdup(opt);
* (char**) p = LDAP_STRDUP(opt);
break;
}
}
@ -276,7 +276,7 @@ static void openldap_ldap_init_w_env(const char *prefix)
if (*value == '\0') {
* (char**) p = NULL;
} else {
* (char**) p = strdup(value);
* (char**) p = LDAP_STRDUP(value);
}
break;
}
@ -298,7 +298,7 @@ void ldap_int_initialize( void )
gopts.ldo_debug = 0;
gopts.ldo_defhost = strdup("localhost");
gopts.ldo_defhost = LDAP_STRDUP("localhost");
gopts.ldo_defport = LDAP_PORT;
gopts.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;

View file

@ -272,14 +272,14 @@ void ldap_int_initialize LDAP_P((void));
#define LDAP_INT_REALLOC(p,s) (LBER_REALLOC((p),(s)))
#define LDAP_INT_FREE(p) (LBER_FREE((p)))
#define LDAP_INT_VFREE(v) (LBER_VFREE((void **)(v)))
#define LDAP_INT_STRDUP(s) (LBER_STRDUP((s)))
#ifndef LDAP_MALLOC
#define LDAP_MALLOC(s) (LBER_MALLOC((s)))
#define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
#define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
#define LDAP_FREE(p) (LBER_FREE((p)))
#define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
#endif
#define LDAP_STRDUP(s) (LBER_STRDUP((s)))
/*
* in unit-int.c
@ -409,9 +409,7 @@ BerElement *ldap_build_search_req LDAP_P((
/*
* in string.c
*/
char *ldap_int_strdup LDAP_P(( const char * ));
#undef strdup
#define strdup ldap_int_strdup
/* see <ac/string.h> */
/*
* in unbind.c

View file

@ -49,7 +49,7 @@ ldap_open( LDAP_CONST char *host, int port )
if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) ==
NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host =
strdup( ld->ld_defhost )) == NULL )) {
LDAP_STRDUP( ld->ld_defhost )) == NULL )) {
if(srv != NULL) LDAP_FREE( (char*) srv );
ldap_ld_free( ld, 0, NULL, NULL );
return( NULL );
@ -147,9 +147,9 @@ ldap_init( LDAP_CONST char *defhost, int defport )
ld->ld_options.ldo_cctrls = NULL;
if ( defhost != NULL ) {
ld->ld_options.ldo_defhost = strdup( defhost );
ld->ld_options.ldo_defhost = LDAP_STRDUP( defhost );
} else {
ld->ld_options.ldo_defhost = strdup(
ld->ld_options.ldo_defhost = LDAP_STRDUP(
ldap_int_global_options.ldo_defhost);
}
@ -160,7 +160,7 @@ ldap_init( LDAP_CONST char *defhost, int defport )
}
if ( ldap_int_global_options.ldo_defbase != NULL ) {
ld->ld_options.ldo_defbase = strdup(
ld->ld_options.ldo_defbase = LDAP_STRDUP(
ldap_int_global_options.ldo_defbase);
}

View file

@ -133,13 +133,13 @@ ldap_get_option(
for(i=0; features[i].ldapaif_name != NULL; i++) {
info->ldapai_extensions[i] =
strdup(features[i].ldapaif_name);
LDAP_STRDUP(features[i].ldapaif_name);
}
info->ldapai_extensions[i] = NULL;
}
info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
info->ldapai_vendor_name = LDAP_STRDUP(LDAP_VENDOR_NAME);
info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
return LDAP_OPT_SUCCESS;
@ -205,7 +205,7 @@ ldap_get_option(
* we do.
*/
* (char **) outvalue = strdup(lo->ldo_defhost);
* (char **) outvalue = LDAP_STRDUP(lo->ldo_defhost);
return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_NUMBER:
@ -230,7 +230,7 @@ ldap_get_option(
if( ld->ld_error == NULL ) {
* (char **) outvalue = NULL;
} else {
* (char **) outvalue = strdup(ld->ld_error);
* (char **) outvalue = LDAP_STRDUP(ld->ld_error);
}
return LDAP_OPT_SUCCESS;
@ -249,7 +249,7 @@ ldap_get_option(
if( ld->ld_matched == NULL ) {
* (char **) outvalue = NULL;
} else {
* (char **) outvalue = strdup(ld->ld_matched);
* (char **) outvalue = LDAP_STRDUP(ld->ld_matched);
}
return 0;
@ -412,7 +412,7 @@ ldap_set_option(
}
if(host != NULL) {
lo->ldo_defhost = strdup(host);
lo->ldo_defhost = LDAP_STRDUP(host);
return LDAP_OPT_SUCCESS;
}
@ -421,14 +421,14 @@ ldap_set_option(
* must want global default returned
* to initial condition.
*/
lo->ldo_defhost = strdup("localhost");
lo->ldo_defhost = LDAP_STRDUP("localhost");
} else {
/*
* must want the session default
* updated to the current global default
*/
lo->ldo_defhost = strdup(
lo->ldo_defhost = LDAP_STRDUP(
ldap_int_global_options.ldo_defhost);
}
} return LDAP_OPT_SUCCESS;
@ -456,7 +456,7 @@ ldap_set_option(
LDAP_FREE(ld->ld_error);
}
ld->ld_error = strdup(err);
ld->ld_error = LDAP_STRDUP(err);
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_API_FEATURE_INFO:

View file

@ -196,7 +196,7 @@ ldap_host_connected_to( Sockbuf *sb )
&hp,&local_h_errno ) ==0 ) && (hp != NULL) )
{
if ( hp->h_name != NULL ) {
char *host = strdup( hp->h_name );
char *host = LDAP_STRDUP( hp->h_name );
DO_RETURN( host );
}
}

View file

@ -82,7 +82,7 @@ ldap_send_initial_request(
if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) ==
NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host =
strdup( ld->ld_defhost )) == NULL ))
LDAP_STRDUP( ld->ld_defhost )) == NULL ))
{
if (srv != NULL) LDAP_FREE( srv );
ber_free( ber, 1 );
@ -700,7 +700,7 @@ ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
return( -1 );
}
if (( srv->lsrv_host = strdup( tmpref )) == NULL ) {
if (( srv->lsrv_host = LDAP_STRDUP( tmpref )) == NULL ) {
LDAP_FREE( (char *)srv );
ber_free( ber, 1 );
ld->ld_errno = LDAP_NO_MEMORY;
@ -933,9 +933,9 @@ dn2servers( LDAP *ld, char *dn ) /* dn can also be a domain.... */
prevsrv = srv;
/* copy in info. */
if (( srv->lsrv_host = strdup( host )) == NULL ||
if (( srv->lsrv_host = LDAP_STRDUP( host )) == NULL ||
( server_dn != NULL && ( srv->lsrv_dn =
strdup( server_dn )) == NULL )) {
LDAP_STRDUP( server_dn )) == NULL )) {
free_servers( srvlist );
srvlist = NULL;
break; /* exit loop & return */

View file

@ -256,7 +256,7 @@ ldap_syntax2str( LDAP_SYNTAX * syn )
print_whsp(ss);
print_literal(ss,")");
retstring = strdup(safe_string_val(ss));
retstring = LDAP_STRDUP(safe_string_val(ss));
safe_string_free(ss);
return(retstring);
}
@ -330,7 +330,7 @@ ldap_objectclass2str( LDAP_OBJECT_CLASS * oc )
print_whsp(ss);
print_literal(ss,")");
retstring = strdup(safe_string_val(ss));
retstring = LDAP_STRDUP(safe_string_val(ss));
safe_string_free(ss);
return(retstring);
}
@ -429,7 +429,7 @@ ldap_attributetype2str( LDAP_ATTRIBUTE_TYPE * at )
print_whsp(ss);
print_literal(ss,")");
retstring = strdup(safe_string_val(ss));
retstring = LDAP_STRDUP(safe_string_val(ss));
safe_string_free(ss);
return(retstring);
}

View file

@ -268,7 +268,7 @@ ldap_build_search_req(
return( NULLBER );
}
filter = strdup( filter_in );
filter = LDAP_STRDUP( filter_in );
err = put_filter( ber, filter );
LDAP_FREE( filter );
@ -464,7 +464,7 @@ put_filter( BerElement *ber, char *str )
return( -1 );
*next = '\0';
tmp = strdup( str );
tmp = LDAP_STRDUP( str );
if ( gotescape ) {
escape = 0;
for ( s = d = tmp; *s; s++ ) {
@ -506,7 +506,7 @@ put_filter( BerElement *ber, char *str )
Debug( LDAP_DEBUG_TRACE, "put_filter: default\n", 0, 0,
0 );
next = strchr( str, '\0' );
tmp = strdup( str );
tmp = LDAP_STRDUP( str );
if ( strchr( tmp, '\\' ) != NULL ) {
escape = 0;
for ( s = d = tmp; *s; s++ ) {

View file

@ -100,20 +100,6 @@ char *
return( NULL );
}
memcpy( p, s, len );
return( p );
}
char *
(ldap_int_strdup)( const char *s )
{
char *p;
size_t len = strlen( s ) + 1;
if ( (p = (char *) LDAP_MALLOC( len )) == NULL ) {
return( NULL );
}
memcpy( p, s, len );
return( p );
}

View file

@ -129,7 +129,7 @@ ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix,
* 2 )) == NULL ) {
return( ld->ld_errno = LDAP_NO_MEMORY );
}
dns[0] = strdup( prefix );
dns[0] = LDAP_STRDUP( prefix );
dns[1] = NULL;
} else {
dns = NULL;
@ -476,7 +476,7 @@ ldap_ufn_setprefix( LDAP *ld, LDAP_CONST char *prefix )
if ( ld->ld_ufnprefix != NULL )
LDAP_FREE( ld->ld_ufnprefix );
ld->ld_ufnprefix = strdup( prefix );
ld->ld_ufnprefix = LDAP_STRDUP( prefix );
}
int

View file

@ -116,7 +116,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
}
/* make working copy of the remainder of the URL */
if (( url = strdup( url_tmp )) == NULL ) {
if (( url = LDAP_STRDUP( url_tmp )) == NULL ) {
return( LDAP_URL_ERR_MEM );
}
@ -274,7 +274,7 @@ ldap_url_search( LDAP *ld, LDAP_CONST char *url, int attrsonly )
if ( ludp->lud_host != NULL || ludp->lud_port != 0 ) {
if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer )))
== NULL || ( srv->lsrv_host = strdup( ludp->lud_host ==
== NULL || ( srv->lsrv_host = LDAP_STRDUP( ludp->lud_host ==
NULL ? ld->ld_defhost : ludp->lud_host )) == NULL ) {
if ( srv != NULL ) {
LDAP_FREE( srv );