From c24d932b02e97472a67f7e71e01b3963469e3e77 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Thu, 19 Nov 1998 06:18:23 +0000 Subject: [PATCH] add ldap_strdup and eliminate strdup in libldap --- libraries/libldap/Makefile.in | 4 ++-- libraries/libldap/cldap.c | 2 +- libraries/libldap/disptmpl.c | 4 ++-- libraries/libldap/dsparse.c | 2 +- libraries/libldap/friendly.c | 4 ++-- libraries/libldap/getdn.c | 6 +++--- libraries/libldap/getdxbyname.c | 2 +- libraries/libldap/getfilter.c | 8 ++++---- libraries/libldap/init.c | 6 +++--- libraries/libldap/ldap-int.h | 10 +++++++++- libraries/libldap/open.c | 6 +++--- libraries/libldap/options.c | 15 ++++++++------- libraries/libldap/os-ip.c | 2 +- libraries/libldap/request.c | 6 +++--- libraries/libldap/search.c | 6 +++--- libraries/libldap/test.c | 8 ++++---- libraries/libldap/ufn.c | 4 ++-- libraries/libldap/url.c | 4 ++-- 18 files changed, 54 insertions(+), 45 deletions(-) diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index 9580ac1db7..82437c0806 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -14,14 +14,14 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \ free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c getdxbyname.c os-ip.c url.c charset.c \ - init.c options.c + init.c options.c strdup.c OBJS = bind.o open.o result.o error.o compare.o search.o \ modify.o add.o modrdn.o delete.o abandon.o ufn.o cache.o \ getfilter.o sbind.o kbind.o unbind.o friendly.o cldap.o \ free.o disptmpl.o srchpref.o dsparse.o tmplout.o sort.o \ getdn.o getentry.o getattr.o getvalues.o addentry.o \ request.o getdxbyname.o os-ip.o url.o charset.o \ - init.o options.o + init.o options.o strdup.o LIBS = -L$(LDAP_LIBDIR) -lldap -llber $(AC_LIBS) LIBLBER = ../liblber/liblber.a diff --git a/libraries/libldap/cldap.c b/libraries/libldap/cldap.c index 8af9627307..5ae4c6a663 100644 --- a/libraries/libldap/cldap.c +++ b/libraries/libldap/cldap.c @@ -134,7 +134,7 @@ cldap_open( char *host, int port ) } if ( ld->ld_host == NULL ) { - ld->ld_host = strdup( host ); + ld->ld_host = ldap_strdup( host ); } } diff --git a/libraries/libldap/disptmpl.c b/libraries/libldap/disptmpl.c index 54b493e7c7..35e61d11b2 100644 --- a/libraries/libldap/disptmpl.c +++ b/libraries/libldap/disptmpl.c @@ -384,7 +384,7 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) { if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) * sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] = - strdup( includeattrs[ i ] )) == NULL ) { + ldap_strdup( includeattrs[ i ] )) == NULL ) { memerr = 1; } else { attrs[ attrcnt ] = NULL; @@ -411,7 +411,7 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, if ( ticolp->ti_attrname != NULL ) { if (( attrs = (char **)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; diff --git a/libraries/libldap/dsparse.c b/libraries/libldap/dsparse.c index 394e61ec34..836e2c9007 100644 --- a/libraries/libldap/dsparse.c +++ b/libraries/libldap/dsparse.c @@ -188,7 +188,7 @@ next_token( char **sp ) return( NULL ); } - return( strdup( tokstart )); + return( ldap_strdup( tokstart )); } diff --git a/libraries/libldap/friendly.c b/libraries/libldap/friendly.c index 12896aad83..278c729cee 100644 --- a/libraries/libldap/friendly.c +++ b/libraries/libldap/friendly.c @@ -83,8 +83,8 @@ ldap_friendly_name( char *filename, char *uname, FriendlyMap **map ) } } - (*map)[i].f_unfriendly = strdup( buf ); - (*map)[i].f_friendly = strdup( s ); + (*map)[i].f_unfriendly = ldap_strdup( buf ); + (*map)[i].f_friendly = ldap_strdup( s ); i++; } diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index 70c09c7933..1142c88364 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -54,9 +54,9 @@ ldap_dn2ufn( 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 @@ -139,7 +139,7 @@ ldap_explode_dns( char *dn ) return( NULL ); } } - rdns[ncomps++] = strdup( s ); + rdns[ncomps++] = ldap_strdup( s ); } rdns[ncomps] = NULL; diff --git a/libraries/libldap/getdxbyname.c b/libraries/libldap/getdxbyname.c index c9ec19f9ac..c31d926374 100644 --- a/libraries/libldap/getdxbyname.c +++ b/libraries/libldap/getdxbyname.c @@ -45,7 +45,7 @@ ldap_getdxbyname( char *domain ) * punt: return list conisting of the original domain name only */ if (( dxs = (char **)malloc( 2 * sizeof( char * ))) == NULL || - ( dxs[ 0 ] = strdup( domain )) == NULL ) { + ( dxs[ 0 ] = ldap_strdup( domain )) == NULL ) { if ( dxs != NULL ) { free( dxs ); } diff --git a/libraries/libldap/getfilter.c b/libraries/libldap/getfilter.c index b6272659c4..e466adc243 100644 --- a/libraries/libldap/getfilter.c +++ b/libraries/libldap/getfilter.c @@ -115,7 +115,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 @@ -210,12 +210,12 @@ ldap_setfilteraffixes( LDAPFiltDesc *lfdp, char *prefix, char *suffix ) if ( lfdp->lfd_filtprefix != NULL ) { 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 ) { free( lfdp->lfd_filtsuffix ); } - lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : strdup( suffix ); + lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : ldap_strdup( suffix ); } @@ -264,7 +264,7 @@ ldap_getfirstfilter( LDAPFiltDesc *lfdp, char *tagpat, char *value ) return( NULL ); } - if (( lfdp->lfd_curvalcopy = strdup( value )) == NULL ) { + if (( lfdp->lfd_curvalcopy = ldap_strdup( value )) == NULL ) { return( NULL ); } diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 57f6d2423f..3801899ceb 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -156,7 +156,7 @@ static void openldap_ldap_init_w_conf(const char *file) case ATTR_STRING: if (* (char**) p != NULL) free(* (char**) p); - * (char**) p = strdup(opt); + * (char**) p = ldap_strdup(opt); break; } } @@ -251,7 +251,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; } @@ -269,7 +269,7 @@ void openldap_ldap_initialize( void ) gopts.ldo_timelimit = LDAP_NO_LIMIT; gopts.ldo_sizelimit = LDAP_NO_LIMIT; - gopts.ldo_defhost = strdup("localhost"); + gopts.ldo_defhost = ldap_strdup("localhost"); gopts.ldo_defport = LDAP_PORT; gopts.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT; diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index bd3335c153..09628931fc 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -139,7 +139,6 @@ struct ldap { #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */ }; - /* * in init.c */ @@ -240,6 +239,15 @@ LDAP_F int cldap_getmsg ( LDAP *ld, struct timeval *timeout, BerElement *ber ); BerElement *ldap_build_search_req( LDAP *ld, char *base, int scope, char *filter, char **attrs, int attrsonly ); +/* + * in strdup.c + */ +#ifdef HAVE_STRDUP +#define ldap_strdup(s) strdup(s) +extern char *strdup(); +#else +extern char *ldap_strdup LDAP_P(( const char * )); +#endif /* * in unbind.c diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index ff88c63463..2aa8eafcb2 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -59,7 +59,7 @@ ldap_open( char *host, int port ) #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) == NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host = - strdup( ld->ld_defhost )) == NULL )) { + ldap_strdup( ld->ld_defhost )) == NULL )) { ldap_ld_free( ld, 0 ); return( NULL ); } @@ -158,9 +158,9 @@ ldap_init( char *defhost, int defport ) ld->ld_options.ldo_defhost = 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( openldap_ldap_global_options.ldo_defhost); } diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 182e7df67d..07374e228c 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -66,13 +66,14 @@ ldap_get_option( info->ldapai_extensions = malloc(sizeof(features)); for(i=0; features[i] != NULL; i++) { - info->ldapai_extensions[i] = strdup(features[i]); + info->ldapai_extensions[i] = + ldap_strdup(features[i]); } 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 0; @@ -131,7 +132,7 @@ ldap_get_option( * we do */ - * (char **) outvalue = strdup(lo->ldo_defhost); + * (char **) outvalue = ldap_strdup(lo->ldo_defhost); return 0; case LDAP_OPT_ERROR_NUMBER: @@ -157,7 +158,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); } break; @@ -249,7 +250,7 @@ ldap_set_option( } if(host != NULL) { - lo->ldo_defhost = strdup(host); + lo->ldo_defhost = ldap_strdup(host); return 0; } @@ -258,14 +259,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( openldap_ldap_global_options.ldo_defhost); } } return 0; diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index b56809cda4..1b22917a46 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -179,7 +179,7 @@ ldap_host_connected_to( Sockbuf *sb ) if (( hp = gethostbyaddr( (char *) &sin.sin_addr, sizeof( sin.sin_addr ), AF_INET )) != NULL ) { if ( hp->h_name != NULL ) { - return( strdup( hp->h_name )); + return( ldap_strdup( hp->h_name )); } } diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index f9b724ef8a..821a29aa74 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -685,7 +685,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 ) { free( (char *)srv ); ber_free( ber, 1 ); ld->ld_errno = LDAP_NO_MEMORY; @@ -919,9 +919,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 */ diff --git a/libraries/libldap/search.c b/libraries/libldap/search.c index 2a45f1ce6d..c6be97c4d7 100644 --- a/libraries/libldap/search.c +++ b/libraries/libldap/search.c @@ -135,7 +135,7 @@ ldap_build_search_req( LDAP *ld, char *base, int scope, char *filter, return( NULLBER ); } - filter = strdup( filter ); + filter = ldap_strdup( filter ); err = put_filter( ber, filter ); free( filter ); @@ -317,7 +317,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++ ) { @@ -359,7 +359,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++ ) { diff --git a/libraries/libldap/test.c b/libraries/libldap/test.c index 66e86efb85..ad50e483ca 100644 --- a/libraries/libldap/test.c +++ b/libraries/libldap/test.c @@ -78,7 +78,7 @@ get_list( char *prompt ) result = (char **) realloc( result, sizeof(char *) * (num + 1) ); - result[num++] = (char *) strdup( buf ); + result[num++] = (char *) ldap_strdup( buf ); } if ( result == (char **) 0 ) return( NULL ); @@ -172,7 +172,7 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 ) getline( buf, sizeof(buf), stdin, prompt2 ); if ( buf[0] == '\0' ) break; - tmp.mod_type = strdup( buf ); + tmp.mod_type = ldap_strdup( buf ); tmp.mod_values = get_list( prompt3 ); @@ -316,12 +316,12 @@ main( int argc, char **argv ) break; case 't': /* copy ber's to given file */ - copyfname = strdup( optarg ); + copyfname = ldap_strdup( optarg ); copyoptions = LBER_TO_FILE; break; case 'T': /* only output ber's to given file */ - copyfname = strdup( optarg ); + copyfname = ldap_strdup( optarg ); copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY); break; diff --git a/libraries/libldap/ufn.c b/libraries/libldap/ufn.c index 6a2ef9ec83..d56dc5799d 100644 --- a/libraries/libldap/ufn.c +++ b/libraries/libldap/ufn.c @@ -128,7 +128,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; @@ -472,7 +472,7 @@ ldap_ufn_setprefix( LDAP *ld, char *prefix ) if ( ld->ld_ufnprefix != NULL ) free( ld->ld_ufnprefix ); - ld->ld_ufnprefix = strdup( prefix ); + ld->ld_ufnprefix = ldap_strdup( prefix ); } int diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 4de1a914e0..bc6726164f 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -113,7 +113,7 @@ ldap_url_parse( char *url, LDAPURLDesc **ludpp ) } /* make working copy of the remainder of the URL */ - if (( url = strdup( url )) == NULL ) { + if (( url = ldap_strdup( url )) == NULL ) { ldap_free_urldesc( ludp ); return( LDAP_URL_ERR_MEM ); } @@ -263,7 +263,7 @@ ldap_url_search( LDAP *ld, char *url, int attrsonly ) if ( ludp->lud_host != NULL || ludp->lud_port != 0 ) { #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS if (( srv = (LDAPServer *)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 ) { free( srv ); -- 2.39.5