From: Kurt Zeilenga Date: Wed, 2 Jun 1999 22:28:22 +0000 (+0000) Subject: Add ber_strdup(), remove ldap_int_strdup(), add LDAP_STRDUP macro X-Git-Tag: OPENLDAP_REL_ENG_2_BP~425 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1f52f6e43e678c8f77625f5c96105a1bb51cc1ce;p=openldap Add ber_strdup(), remove ldap_int_strdup(), add LDAP_STRDUP macro and ripple change through -lldap. --- diff --git a/include/lber.h b/include/lber.h index e4f3178d1e..3bf2c7888d 100644 --- a/include/lber.h +++ b/include/lber.h @@ -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 */ diff --git a/libraries/liblber/lber-int.h b/libraries/liblber/lber-int.h index 8cb299ef95..40d61109ec 100644 --- a/libraries/liblber/lber-int.h +++ b/libraries/liblber/lber-int.h @@ -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 */ diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 8b95a18eb3..f4f4b490c6 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -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 ); +} \ No newline at end of file diff --git a/libraries/libldap/cldap.c b/libraries/libldap/cldap.c index b27d108450..fbc7228169 100644 --- a/libraries/libldap/cldap.c +++ b/libraries/libldap/cldap.c @@ -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 { diff --git a/libraries/libldap/controls.c b/libraries/libldap/controls.c index 7e3a5f6b21..9262bcb955 100644 --- a/libraries/libldap/controls.c +++ b/libraries/libldap/controls.c @@ -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 ); diff --git a/libraries/libldap/disptmpl.c b/libraries/libldap/disptmpl.c index d9d768ef9b..0fb3e20163 100644 --- a/libraries/libldap/disptmpl.c +++ b/libraries/libldap/disptmpl.c @@ -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; diff --git a/libraries/libldap/dsparse.c b/libraries/libldap/dsparse.c index ce3f873d6c..22f6357164 100644 --- a/libraries/libldap/dsparse.c +++ b/libraries/libldap/dsparse.c @@ -192,7 +192,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 d88052a1fd..db42adee04 100644 --- a/libraries/libldap/friendly.c +++ b/libraries/libldap/friendly.c @@ -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++; } diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index 31d6381f6e..f434465058 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -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); diff --git a/libraries/libldap/getdxbyname.c b/libraries/libldap/getdxbyname.c index 2f1f284647..221bd409fb 100644 --- a/libraries/libldap/getdxbyname.c +++ b/libraries/libldap/getdxbyname.c @@ -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 ); } diff --git a/libraries/libldap/getfilter.c b/libraries/libldap/getfilter.c index c085d146ae..a357abf78b 100644 --- a/libraries/libldap/getfilter.c +++ b/libraries/libldap/getfilter.c @@ -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 ); } diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 531cac49c7..b4f82f95c7 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -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; diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 6a7953ec6f..f638a581f4 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -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 */ /* * in unbind.c diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index 10e15fd404..50641603c7 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -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); } diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index e659643982..f13656eba0 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -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: diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 525472835b..f00b039659 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -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 ); } } diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 3f7970f7cc..70773082f1 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -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 */ diff --git a/libraries/libldap/schema.c b/libraries/libldap/schema.c index 3f06e8ce36..af41fc3f66 100644 --- a/libraries/libldap/schema.c +++ b/libraries/libldap/schema.c @@ -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); } diff --git a/libraries/libldap/search.c b/libraries/libldap/search.c index b489feafe6..a9a5b599a9 100644 --- a/libraries/libldap/search.c +++ b/libraries/libldap/search.c @@ -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++ ) { diff --git a/libraries/libldap/string.c b/libraries/libldap/string.c index e2d142d958..0e3d14849f 100644 --- a/libraries/libldap/string.c +++ b/libraries/libldap/string.c @@ -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 ); } \ No newline at end of file diff --git a/libraries/libldap/ufn.c b/libraries/libldap/ufn.c index ff4e38dedc..5a6b070291 100644 --- a/libraries/libldap/ufn.c +++ b/libraries/libldap/ufn.c @@ -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 diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 249af5aa61..27a58b3ea8 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -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 );