add ldap_strdup and eliminate strdup in libldap

This commit is contained in:
Hallvard Furuseth 1998-11-19 06:18:23 +00:00
parent ad9a9ac8bc
commit c24d932b02
18 changed files with 54 additions and 45 deletions

View file

@ -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

View file

@ -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 );
}
}

View file

@ -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;

View file

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

View file

@ -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++;
}

View file

@ -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;

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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;

View file

@ -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

View file

@ -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);
}

View file

@ -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;

View file

@ -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 ));
}
}

View file

@ -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 */

View file

@ -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++ ) {

View file

@ -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;

View file

@ -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

View file

@ -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 );