From: Kurt Zeilenga Date: Fri, 27 Nov 1998 20:21:54 +0000 (+0000) Subject: Replace strdup() with ch_strdup() such that exit() will be called X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~1011 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e2ee741ea86edb97a08b3f217760f1cd5972302e;p=openldap Replace strdup() with ch_strdup() such that exit() will be called if strdup fails. This is better than not checking, but we should add orderly shutdown. --- diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index 7c922782fc..6e630ab14e 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -50,7 +50,7 @@ access_allowed( return( 0 ); } - edn = dn_normalize_case( strdup( e->e_dn ) ); + edn = dn_normalize_case( ch_strdup( e->e_dn ) ); Debug( LDAP_DEBUG_ACL, "\n=> access_allowed: entry (%s) attr (%s)\n", e->e_dn, attr, 0 ); @@ -250,7 +250,7 @@ acl_access_allowed( odn = NULL; if ( op->o_dn != NULL ) { - odn = dn_normalize_case( strdup( op->o_dn ) ); + odn = dn_normalize_case( ch_strdup( op->o_dn ) ); bv.bv_val = odn; bv.bv_len = strlen( odn ); } @@ -400,7 +400,7 @@ acl_check_mods( struct acl *a; char *edn; - edn = dn_normalize_case( strdup( e->e_dn ) ); + edn = dn_normalize_case( ch_strdup( e->e_dn ) ); for ( ; mods != NULL; mods = mods->mod_next ) { regmatch_t matches[MAXREMATCHES]; diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index 637471cb91..f6e5d29ed3 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -120,7 +120,7 @@ parse_acl( fname, lineno, right, buf ); acl_usage(); } - a->acl_dnpat = strdup( ".*" ); + a->acl_dnpat = ch_strdup( ".*" ); continue; } @@ -152,7 +152,7 @@ parse_acl( acl_usage(); } else { - a->acl_dnpat = dn_upcase(strdup( right )); + a->acl_dnpat = dn_upcase(ch_strdup( right )); } } else if ( strncasecmp( left, "attr", 4 ) == 0 ) { @@ -194,14 +194,14 @@ parse_acl( /* get */ split( argv[i], '=', &left, &right ); if ( strcasecmp( argv[i], "*" ) == 0 ) { - b->a_dnpat = strdup( ".*" ); + b->a_dnpat = ch_strdup( ".*" ); } else if ( strcasecmp( argv[i], "self" ) == 0 ) { - b->a_dnpat = strdup( "self" ); + b->a_dnpat = ch_strdup( "self" ); } else if ( strcasecmp( left, "dn" ) == 0 ) { regtest(fname, lineno, right); - b->a_dnpat = dn_upcase( strdup( right ) ); + b->a_dnpat = dn_upcase( ch_strdup( right ) ); } else if ( strcasecmp( left, "dnattr" ) == 0 ) { - b->a_dnattr = strdup( right ); + b->a_dnattr = ch_strdup( right ); #ifdef SLAPD_ACLGROUPS } else if ( strcasecmp( left, "group" ) == 0 ) { @@ -217,21 +217,21 @@ parse_acl( *name++ = '\0'; } - b->a_group = dn_upcase(strdup( right )); + b->a_group = dn_upcase(ch_strdup( right )); if (value && *value) { - b->a_objectclassvalue = strdup(value); + b->a_objectclassvalue = ch_strdup(value); *--value = '/'; } else - b->a_objectclassvalue = strdup("groupOfNames"); + b->a_objectclassvalue = ch_strdup("groupOfNames"); if (name && *name) { - b->a_groupattrname = strdup(name); + b->a_groupattrname = ch_strdup(name); *--name = '/'; } else - b->a_groupattrname = strdup("member"); + b->a_groupattrname = ch_strdup("member"); @@ -239,7 +239,7 @@ parse_acl( } else if ( strcasecmp( left, "domain" ) == 0 ) { char *s; regtest(fname, lineno, right); - b->a_domainpat = strdup( right ); + b->a_domainpat = ch_strdup( right ); /* normalize the domain */ for ( s = b->a_domainpat; *s; s++ ) { @@ -247,7 +247,7 @@ parse_acl( } } else if ( strcasecmp( left, "addr" ) == 0 ) { regtest(fname, lineno, right); - b->a_addrpat = strdup( right ); + b->a_addrpat = ch_strdup( right ); } else { fprintf( stderr, "%s: line %d: expecting got \"%s\"\n", diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 5393e3afe9..60ae1cf93d 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -57,7 +57,7 @@ do_add( Connection *conn, Operation *op ) return; } e->e_dn = dn; - dn = dn_normalize( strdup( dn ) ); + dn = dn_normalize( ch_strdup( dn ) ); Debug( LDAP_DEBUG_ARGS, " do_add: dn (%s)\n", dn, 0, 0 ); /* get the attrs */ diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index 51752ee9ac..0d696dc024 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -77,7 +77,7 @@ attr_merge_fast( if ( **a == NULL ) { **a = (Attribute *) ch_malloc( sizeof(Attribute) ); - (**a)->a_type = attr_normalize( strdup( type ) ); + (**a)->a_type = attr_normalize( ch_strdup( type ) ); (**a)->a_vals = NULL; (**a)->a_syntax = attr_syntax( type ); (**a)->a_next = NULL; @@ -112,7 +112,7 @@ attr_merge( if ( *a == NULL ) { *a = (Attribute *) ch_malloc( sizeof(Attribute) ); - (*a)->a_type = attr_normalize( strdup( type ) ); + (*a)->a_type = attr_normalize( ch_strdup( type ) ); (*a)->a_vals = NULL; (*a)->a_syntax = attr_syntax( type ); (*a)->a_next = NULL; diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index 77c92d220a..3b3dcee662 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -24,7 +24,7 @@ ldbm_back_add( Entry *p = NULL; int rc; - dn = dn_normalize( strdup( e->e_dn ) ); + dn = dn_normalize( ch_strdup( e->e_dn ) ); Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_add: %s\n", dn, 0, 0); diff --git a/servers/slapd/back-ldbm/alias.c b/servers/slapd/back-ldbm/alias.c index 1823fa3114..e9ca520019 100644 --- a/servers/slapd/back-ldbm/alias.c +++ b/servers/slapd/back-ldbm/alias.c @@ -54,8 +54,8 @@ Entry *derefAlias_r ( Backend *be, Debug( LDAP_DEBUG_TRACE, "<= %s is an alias for %s\n", e->e_dn, a->a_vals[0]->bv_val, 0 ); - newDN = strdup (a->a_vals[0]->bv_val); - oldDN = strdup (e->e_dn); + newDN = ch_strdup (a->a_vals[0]->bv_val); + oldDN = ch_strdup (e->e_dn); /* * ok, so what happens if there is an alias in the DN of a dereferenced @@ -124,7 +124,7 @@ char *derefDN ( Backend *be, "<= dereferencing dn %s\n", dn, 0, 0 ); - newDN = strdup ( dn ); + newDN = ch_strdup ( dn ); /* while we don't have a matched dn, deref the DN */ for ( depth = 0; @@ -212,7 +212,7 @@ char *derefDN ( Backend *be, if ( (eNew = dn2entry_r( be, newDN, &matched )) != NULL) { if ((eDeref = derefAlias_r( be, conn, op, eNew )) != NULL) { free (newDN); - newDN = strdup (eDeref->e_dn); + newDN = ch_strdup (eDeref->e_dn); /* free reader lock */ cache_return_entry_r(&li->li_cache, eDeref); } @@ -232,7 +232,7 @@ char *derefDN ( Backend *be, } if (newDN == NULL) { - newDN = strdup ( dn ); + newDN = ch_strdup ( dn ); } Debug( LDAP_DEBUG_TRACE, "<= returning deref DN of %s\n", newDN, 0, 0 ); diff --git a/servers/slapd/back-ldbm/attr.c b/servers/slapd/back-ldbm/attr.c index 1ef4bbd07f..7818fb1ff6 100644 --- a/servers/slapd/back-ldbm/attr.c +++ b/servers/slapd/back-ldbm/attr.c @@ -101,7 +101,7 @@ attr_index_config( } for ( i = 0; attrs[i] != NULL; i++ ) { a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) ); - a->ai_type = strdup( attrs[i] ); + a->ai_type = ch_strdup( attrs[i] ); a->ai_syntaxmask = attr_syntax( a->ai_type ); if ( argc == 1 ) { a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY | diff --git a/servers/slapd/back-ldbm/config.c b/servers/slapd/back-ldbm/config.c index dab1dec432..99a7c7794e 100644 --- a/servers/slapd/back-ldbm/config.c +++ b/servers/slapd/back-ldbm/config.c @@ -35,7 +35,7 @@ ldbm_back_config( fname, lineno ); exit( 1 ); } - li->li_directory = strdup( argv[1] ); + li->li_directory = ch_strdup( argv[1] ); /* mode with which to create new database files */ } else if ( strcasecmp( argv[0], "mode" ) == 0 ) { diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 3da34b0126..4beef6dd6e 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -100,7 +100,7 @@ ldbm_cache_open( pthread_mutex_unlock( &li->li_dbcache_mutex ); return( NULL ); } - li->li_dbcache[i].dbc_name = strdup( buf ); + li->li_dbcache[i].dbc_name = ch_strdup( buf ); li->li_dbcache[i].dbc_refcnt = 1; li->li_dbcache[i].dbc_lastref = curtime; if ( stat( buf, &st ) == 0 ) { diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index ae0f62d8dd..b5ca2a4c7c 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -37,7 +37,7 @@ dn2id_add( return( -1 ); } - dn = strdup( dn ); + dn = ch_strdup( dn ); dn_normalize_case( dn ); key.dptr = dn; @@ -73,7 +73,7 @@ dn2id( memset( &data, 0, sizeof( data ) ); #endif - dn = strdup( dn ); + dn = ch_strdup( dn ); Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 ); dn_normalize_case( dn ); diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index c00bd2509c..acb7844e8e 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -32,7 +32,7 @@ index_add_entry( * with index_add_values() call */ - bv.bv_val = strdup( e->e_dn ); + bv.bv_val = ch_strdup( e->e_dn ); bv.bv_len = strlen( bv.bv_val ); (void) dn_normalize_case( bv.bv_val ); bvals[0] = &bv; diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 407e3c74ee..6580fa5331 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -60,7 +60,7 @@ ldbm_back_init( attr_index_config( li, "ldbm id2children initialization", 0, 2, argv, 1 ); argv[ 0 ] = "objectclass"; - argv[ 1 ] = strdup( "pres,eq" ); + argv[ 1 ] = ch_strdup( "pres,eq" ); argv[ 2 ] = NULL; attr_index_config( li, "ldbm objectclass initialization", 0, 2, argv, 1 ); diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 4ea74e9533..d4209177c4 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -60,7 +60,7 @@ ldbm_back_modrdn( strcat( newdn, pdn ); } } else { - newdn = strdup( newrdn ); + newdn = ch_strdup( newrdn ); } (void) dn_normalize( newdn ); diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 65d78af635..959411b235 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -75,13 +75,15 @@ ldbm_back_search( * check and apply aliasing where the dereferencing applies to * the subordinates of the base */ - realBase = strdup (base); + switch ( deref ) { case LDAP_DEREF_FINDING: case LDAP_DEREF_ALWAYS: free (realBase); realBase = derefDN ( be, conn, op, base ); break; + default: + realBase = ch_strdup(base); } (void) dn_normalize (realBase); @@ -205,7 +207,7 @@ ldbm_back_search( } free( dn ); } else if ( scope == LDAP_SCOPE_SUBTREE ) { - dn = strdup( e->e_dn ); + dn = ch_strdup( e->e_dn ); (void) dn_normalize( dn ); scopeok = dn_issuffix( dn, realBase ); free( dn ); @@ -358,9 +360,9 @@ onelevel_candidates( f->f_choice = LDAP_FILTER_AND; f->f_and = (Filter *) ch_malloc( sizeof(Filter) ); f->f_and->f_choice = LDAP_FILTER_EQUALITY; - f->f_and->f_ava.ava_type = strdup( "id2children" ); + f->f_and->f_ava.ava_type = ch_strdup( "id2children" ); sprintf( buf, "%ld", e != NULL ? e->e_id : 0 ); - f->f_and->f_ava.ava_value.bv_val = strdup( buf ); + f->f_and->f_ava.ava_value.bv_val = ch_strdup( buf ); f->f_and->f_ava.ava_value.bv_len = strlen( buf ); f->f_and->f_next = filter; @@ -429,9 +431,9 @@ subtree_candidates( f->f_choice = LDAP_FILTER_OR; f->f_or = (Filter *) ch_malloc( sizeof(Filter) ); f->f_or->f_choice = LDAP_FILTER_EQUALITY; - f->f_or->f_avtype = strdup( "objectclass" ); + f->f_or->f_avtype = ch_strdup( "objectclass" ); /* Patch to use normalized uppercase */ - f->f_or->f_avvalue.bv_val = strdup( "REFERRAL" ); + f->f_or->f_avvalue.bv_val = ch_strdup( "REFERRAL" ); f->f_or->f_avvalue.bv_len = strlen( "REFERRAL" ); f->f_or->f_next = filter; filter = f; @@ -442,10 +444,10 @@ subtree_candidates( f->f_choice = LDAP_FILTER_AND; f->f_and = (Filter *) ch_malloc( sizeof(Filter) ); f->f_and->f_choice = LDAP_FILTER_SUBSTRINGS; - f->f_and->f_sub_type = strdup( "dn" ); + f->f_and->f_sub_type = ch_strdup( "dn" ); f->f_and->f_sub_initial = NULL; f->f_and->f_sub_any = NULL; - f->f_and->f_sub_final = strdup( base ); + f->f_and->f_sub_final = ch_strdup( base ); value_normalize( f->f_and->f_sub_final, SYNTAX_CIS ); f->f_and->f_next = filter; filter = f; diff --git a/servers/slapd/back-passwd/config.c b/servers/slapd/back-passwd/config.c index 5e9bf853a3..3ed61fa9e7 100644 --- a/servers/slapd/back-passwd/config.c +++ b/servers/slapd/back-passwd/config.c @@ -28,7 +28,7 @@ passwd_back_config( fname, lineno ); exit( 1 ); } - be->be_private = strdup( argv[1] ); + be->be_private = ch_strdup( argv[1] ); #else /* HAVE_SETPWFILE */ fprintf( stderr, "%s: line %d: ignoring \"file\" option (not supported on this platform)\n", diff --git a/servers/slapd/back-passwd/search.c b/servers/slapd/back-passwd/search.c index 86fb55e610..93b69fb1c2 100644 --- a/servers/slapd/back-passwd/search.c +++ b/servers/slapd/back-passwd/search.c @@ -135,7 +135,7 @@ pw2entry( Backend *be, struct passwd *pw ) e->e_attrs = NULL; sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] ); - e->e_dn = strdup( buf ); + e->e_dn = ch_strdup( buf ); val.bv_val = pw->pw_name; val.bv_len = strlen( pw->pw_name ); diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index 7cb354ac1a..9d4f01fddf 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -164,7 +164,7 @@ do_bind( if ( conn->c_dn != NULL ) { free( conn->c_dn ); } - conn->c_dn = strdup( dn ); + conn->c_dn = ch_strdup( dn ); pthread_mutex_unlock( &conn->c_dnmutex ); /* send this here to avoid a race condition */ diff --git a/servers/slapd/ch_malloc.c b/servers/slapd/ch_malloc.c index 366e7bc1f1..2c7f850520 100644 --- a/servers/slapd/ch_malloc.c +++ b/servers/slapd/ch_malloc.c @@ -3,6 +3,7 @@ #include "portable.h" #include +#include #include #include @@ -60,3 +61,19 @@ ch_calloc( return( new ); } + +char * +ch_strdup( + const char *string +) +{ + char *new; + + if ( (new = strdup( string )) == NULL ) { + Debug( LDAP_DEBUG_ANY, "strdup(%s) failed\n", string, 0, 0 ); + exit( 1 ); + } + + return( new ); +} + diff --git a/servers/slapd/charray.c b/servers/slapd/charray.c index 7edb80c848..26a669cd60 100644 --- a/servers/slapd/charray.c +++ b/servers/slapd/charray.c @@ -102,7 +102,7 @@ charray_dup( char **a ) new = (char **) ch_malloc( (i + 1) * sizeof(char *) ); for ( i = 0; a[i] != NULL; i++ ) { - new[i] = strdup( a[i] ); + new[i] = ch_strdup( a[i] ); } new[i] = NULL; @@ -117,7 +117,7 @@ str2charray( char *str, char *brkstr ) int i; /* protect the input string from strtok */ - str = strdup( str ); + str = ch_strdup( str ); i = 1; for ( s = str; *s; s++ ) { @@ -130,7 +130,7 @@ str2charray( char *str, char *brkstr ) i = 0; for ( s = strtok( str, brkstr ); s != NULL; s = strtok( NULL, brkstr ) ) { - res[i++] = strdup( s ); + res[i++] = ch_strdup( s ); } res[i] = NULL; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 715dd8baee..e5fa3bca6f 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -128,7 +128,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) "%s: line %d: suffix line must appear inside a database definition (ignored)\n", fname, lineno, 0 ); } else { - dn = strdup( cargv[1] ); + dn = ch_strdup( cargv[1] ); (void) dn_normalize( dn ); charray_add( &be->be_suffix, dn ); } @@ -155,11 +155,11 @@ read_config( char *fname, Backend **bep, FILE *pfp ) "%s: line %d: suffixAlias line must appear inside a database definition (ignored)\n", fname, lineno, 0 ); } else { - dn = strdup( cargv[1] ); + dn = ch_strdup( cargv[1] ); (void) dn_normalize( dn ); charray_add( &be->be_suffixAlias, dn ); - dn = strdup( cargv[2] ); + dn = ch_strdup( cargv[2] ); (void) dn_normalize( dn ); charray_add( &be->be_suffixAlias, dn ); } @@ -194,7 +194,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) "%s: line %d: rootdn line must appear inside a database definition (ignored)\n", fname, lineno, 0 ); } else { - dn = strdup( cargv[1] ); + dn = ch_strdup( cargv[1] ); (void) dn_normalize( dn ); be->be_rootdn = dn; } @@ -212,7 +212,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) "%s: line %d: rootpw line must appear inside a database definition (ignored)\n", fname, lineno, 0 ); } else { - be->be_rootpw = strdup( cargv[1] ); + be->be_rootpw = ch_strdup( cargv[1] ); } /* make this database read-only */ @@ -328,7 +328,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) if ( strncasecmp( cargv[i], "host=", 5 ) == 0 ) { charray_add( &be->be_replica, - strdup( cargv[i] + 5 ) ); + ch_strdup( cargv[i] + 5 ) ); break; } } @@ -352,7 +352,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) "%s: line %d: updatedn line must appear inside a database definition (ignored)\n", fname, lineno, 0 ); } else { - be->be_updatedn = strdup( cargv[1] ); + be->be_updatedn = ch_strdup( cargv[1] ); (void) dn_normalize( be->be_updatedn ); } @@ -365,9 +365,9 @@ read_config( char *fname, Backend **bep, FILE *pfp ) exit( 1 ); } if ( be ) { - be->be_replogfile = strdup( cargv[1] ); + be->be_replogfile = ch_strdup( cargv[1] ); } else { - replogfile = strdup( cargv[1] ); + replogfile = ch_strdup( cargv[1] ); } /* maintain lastmodified{by,time} attributes */ @@ -398,7 +398,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) fname, lineno, 0 ); exit( 1 ); } - savefname = strdup( cargv[1] ); + savefname = ch_strdup( cargv[1] ); savelineno = lineno; read_config( savefname, bep, NULL ); be = *bep; @@ -413,7 +413,7 @@ read_config( char *fname, Backend **bep, FILE *pfp ) fname, lineno, 0 ); exit( 1 ); } - ldap_srvtab = strdup( cargv[1] ); + ldap_srvtab = ch_strdup( cargv[1] ); /* pass anything else to the current backend config routine */ } else { diff --git a/servers/slapd/configinfo.c b/servers/slapd/configinfo.c index 9ad40ebedb..c25a76dc28 100644 --- a/servers/slapd/configinfo.c +++ b/servers/slapd/configinfo.c @@ -43,7 +43,7 @@ config_info( Connection *conn, Operation *op ) entry_rdwr_init(e); e->e_attrs = NULL; - e->e_dn = strdup( SLAPD_CONFIG_DN ); + e->e_dn = ch_strdup( SLAPD_CONFIG_DN ); for ( i = 0; i < nbackends; i++ ) { strcpy( buf, backends[i].be_type ); diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 2d630f4168..98275706a9 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -177,7 +177,7 @@ connection_activity( pthread_mutex_lock( &conn->c_dnmutex ); if ( conn->c_dn != NULL ) { - tmpdn = strdup( conn->c_dn ); + tmpdn = ch_strdup( conn->c_dn ); } else { tmpdn = NULL; } diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index d4df62a666..d14f37eda4 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -304,13 +304,13 @@ slapd_daemon( if ( c[ns].c_addr != NULL ) { free( c[ns].c_addr ); } - c[ns].c_addr = strdup( client_addr ); + c[ns].c_addr = ch_strdup( client_addr ); if ( c[ns].c_domain != NULL ) { free( c[ns].c_domain ); } - c[ns].c_domain = strdup( client_name == NULL + c[ns].c_domain = ch_strdup( client_name == NULL ? "" : client_name ); pthread_mutex_lock( &c[ns].c_dnmutex ); diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index a3df326eb3..41ec2e2a29 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -41,7 +41,7 @@ do_delete( send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" ); return; } - odn = strdup( dn ); + odn = ch_strdup( dn ); dn_normalize( dn ); Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 ); diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index bd51b3c13d..495eca4b70 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -179,7 +179,7 @@ dn_parent( if ( *(s + 1) == '\0' ) { return( NULL ); } else { - return( strdup( s + 1 ) ); + return( ch_strdup( s + 1 ) ); } } @@ -202,11 +202,11 @@ dn_parent( if ( *s == '"' ) inquote = 1; else if ( DNSEPARATOR( *s ) ) - return( strdup( s + 1 ) ); + return( ch_strdup( s + 1 ) ); } } - return( strdup("") ); + return( ch_strdup("") ); } /* diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index f9f397546e..5e7ee6d31b 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -91,7 +91,7 @@ str2entry( char *s ) e->e_id, e->e_dn, value ); continue; } - e->e_dn = strdup( value ); + e->e_dn = ch_strdup( value ); continue; } diff --git a/servers/slapd/filter.c b/servers/slapd/filter.c index 86d8dabcff..5f4c686571 100644 --- a/servers/slapd/filter.c +++ b/servers/slapd/filter.c @@ -134,7 +134,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) Debug( LDAP_DEBUG_FILTER, "AND\n", 0, 0, 0 ); if ( (err = get_filter_list( conn, ber, &f->f_and, &ftmp )) == 0 ) { - if (ftmp == NULL) ftmp = strdup(""); + if (ftmp == NULL) ftmp = ch_strdup(""); *fstr = ch_malloc( 4 + strlen( ftmp ) ); sprintf( *fstr, "(&%s)", ftmp ); free( ftmp ); @@ -145,7 +145,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) Debug( LDAP_DEBUG_FILTER, "OR\n", 0, 0, 0 ); if ( (err = get_filter_list( conn, ber, &f->f_or, &ftmp )) == 0 ) { - if (ftmp == NULL) ftmp = strdup(""); + if (ftmp == NULL) ftmp = ch_strdup(""); *fstr = ch_malloc( 4 + strlen( ftmp ) ); sprintf( *fstr, "(|%s)", ftmp ); free( ftmp ); @@ -156,7 +156,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) Debug( LDAP_DEBUG_FILTER, "NOT\n", 0, 0, 0 ); (void) ber_skip_tag( ber, &len ); if ( (err = get_filter( conn, ber, &f->f_not, &ftmp )) == 0 ) { - if (ftmp == NULL) ftmp = strdup(""); + if (ftmp == NULL) ftmp = ch_strdup(""); *fstr = ch_malloc( 4 + strlen( ftmp ) ); sprintf( *fstr, "(!%s)", ftmp ); free( ftmp ); diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 3c6ddb62a3..a9248996da 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -120,7 +120,7 @@ main( int argc, char **argv ) #endif case 'f': /* read config file */ - configfile = strdup( optarg ); + configfile = ch_strdup( optarg ); break; case 'i': /* run from inetd */ @@ -148,9 +148,9 @@ main( int argc, char **argv ) Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 ); if ( (myname = strrchr( argv[0], '/' )) == NULL ) { - myname = strdup( argv[0] ); + myname = ch_strdup( argv[0] ); } else { - myname = strdup( myname + 1 ); + myname = ch_strdup( myname + 1 ); } if ( ! inetd ) { @@ -243,7 +243,7 @@ main( int argc, char **argv ) inet_ntoa( from.sin_addr ), 0 ); c.c_addr = inet_ntoa( from.sin_addr ); - c.c_domain = strdup( hp == NULL ? "" : hp->h_name ); + c.c_domain = ch_strdup( hp == NULL ? "" : hp->h_name ); } else { Debug( LDAP_DEBUG_ARGS, "connection from unknown\n", 0, 0, 0 ); diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index fa65acc2a8..142fa8da99 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -63,7 +63,7 @@ do_modify( send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" ); return; } - odn = strdup( dn ); + odn = ch_strdup( dn ); dn_normalize( dn ); Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn, 0, 0 ); @@ -241,7 +241,7 @@ add_lastmods( Operation *op, LDAPMod **mods ) bv.bv_len = strlen( bv.bv_val ); } tmp = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) ); - tmp->mod_type = strdup( "modifiersname" ); + tmp->mod_type = ch_strdup( "modifiersname" ); tmp->mod_op = LDAP_MOD_REPLACE; tmp->mod_bvalues = (struct berval **) ch_calloc( 1, 2 * sizeof(struct berval *) ); @@ -261,7 +261,7 @@ add_lastmods( Operation *op, LDAPMod **mods ) bv.bv_val = buf; bv.bv_len = strlen( bv.bv_val ); tmp = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) ); - tmp->mod_type = strdup( "modifytimestamp" ); + tmp->mod_type = ch_strdup( "modifytimestamp" ); tmp->mod_op = LDAP_MOD_REPLACE; tmp->mod_bvalues = (struct berval **) ch_calloc( 1, 2 * sizeof(struct berval *) ); tmp->mod_bvalues[0] = ber_bvdup( &bv ); diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 25752ea85d..3a7e96704e 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -46,7 +46,7 @@ do_modrdn( send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" ); return; } - odn = strdup( dn ); + odn = ch_strdup( dn ); dn_normalize( dn ); Debug( LDAP_DEBUG_ARGS, diff --git a/servers/slapd/monitor.c b/servers/slapd/monitor.c index e7de185eed..698ac953a4 100644 --- a/servers/slapd/monitor.c +++ b/servers/slapd/monitor.c @@ -48,7 +48,7 @@ monitor_info( Connection *conn, Operation *op ) /* initialize reader/writer lock */ entry_rdwr_init(e); e->e_attrs = NULL; - e->e_dn = strdup( SLAPD_MONITOR_DN ); + e->e_dn = ch_strdup( SLAPD_MONITOR_DN ); val.bv_val = Versionstr; if (( p = strchr( Versionstr, '\n' )) == NULL ) { diff --git a/servers/slapd/operation.c b/servers/slapd/operation.c index 9a06f97fbd..b7c8613ff2 100644 --- a/servers/slapd/operation.c +++ b/servers/slapd/operation.c @@ -45,7 +45,7 @@ op_add( (*tmp)->o_msgid = msgid; (*tmp)->o_tag = tag; (*tmp)->o_abandon = 0; - (*tmp)->o_dn = strdup( dn != NULL ? dn : "" ); + (*tmp)->o_dn = ch_strdup( dn != NULL ? dn : "" ); pthread_mutex_lock( ¤ttime_mutex ); (*tmp)->o_time = currenttime; pthread_mutex_unlock( ¤ttime_mutex ); diff --git a/servers/slapd/phonetic.c b/servers/slapd/phonetic.c index 485e3718a7..4c7f3537bf 100644 --- a/servers/slapd/phonetic.c +++ b/servers/slapd/phonetic.c @@ -69,7 +69,7 @@ word_dup( char *w ) ; /* NULL */ save = *s; *s = '\0'; - ret = strdup( w ); + ret = ch_strdup( w ); *s = save; return( ret ); @@ -154,7 +154,7 @@ phonetic( char *s ) if ( i > 0 ) phoneme[i] = '\0'; - return( strdup( phoneme ) ); + return( ch_strdup( phoneme ) ); } #else @@ -205,7 +205,7 @@ phonetic( char *Word ) Metaph = buf; *Metaph = '\0'; if (n == ntrans + 4) { - return( strdup( buf ) ); /* Return if null */ + return( ch_strdup( buf ) ); /* Return if null */ } n_end = n; /* Set n_end to end of string */ @@ -426,7 +426,7 @@ phonetic( char *Word ) } *Metaph = 0; /* Null terminate */ - return( strdup( buf ) ); + return( ch_strdup( buf ) ); } #endif /* metaphone */ diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 200782010f..412174f6bf 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -66,6 +66,7 @@ void be_close LDAP_P(( void )); void * ch_malloc LDAP_P(( unsigned long size )); void * ch_realloc LDAP_P(( void *block, unsigned long size )); void * ch_calloc LDAP_P(( unsigned long nelem, unsigned long size )); +char * ch_strdup LDAP_P(( const char *string )); /* * charray.c diff --git a/servers/slapd/result.c b/servers/slapd/result.c index a18ba20a86..dd3613327b 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -196,7 +196,7 @@ send_search_entry( return( 1 ); } - edn = dn_normalize_case( strdup( e->e_dn ) ); + edn = dn_normalize_case( ch_strdup( e->e_dn ) ); #ifdef LDAP_COMPAT30 if ( (ber = ber_alloc_t( conn->c_version == 30 ? 0 : LBER_USE_DER )) diff --git a/servers/slapd/schemaparse.c b/servers/slapd/schemaparse.c index 08640bda5e..900263c84a 100644 --- a/servers/slapd/schemaparse.c +++ b/servers/slapd/schemaparse.c @@ -29,7 +29,7 @@ parse_oc( struct objclass **ocp; oc = (struct objclass *) ch_calloc( 1, sizeof(struct objclass) ); - oc->oc_name = strdup( argv[1] ); + oc->oc_name = ch_strdup( argv[1] ); for ( i = 2; i < argc; i++ ) { /* required attributes */ if ( strcasecmp( argv[i], "requires" ) == 0 ) { diff --git a/servers/slapd/str2filter.c b/servers/slapd/str2filter.c index 71d4d1f56a..1ab28f1462 100644 --- a/servers/slapd/str2filter.c +++ b/servers/slapd/str2filter.c @@ -167,7 +167,7 @@ str2simple( char *str ) f->f_choice = LDAP_FILTER_PRESENT; } else { f->f_choice = LDAP_FILTER_SUBSTRINGS; - f->f_sub_type = strdup( str ); + f->f_sub_type = ch_strdup( str ); if ( str2subvals( value, f ) != 0 ) { filter_free( f ); *(value-1) = '='; @@ -180,10 +180,10 @@ str2simple( char *str ) } if ( f->f_choice == LDAP_FILTER_PRESENT ) { - f->f_type = strdup( str ); + f->f_type = ch_strdup( str ); } else { - f->f_avtype = strdup( str ); - f->f_avvalue.bv_val = strdup( value ); + f->f_avtype = ch_strdup( str ); + f->f_avvalue.bv_val = ch_strdup( value ); f->f_avvalue.bv_len = strlen( value ); } @@ -206,11 +206,11 @@ str2subvals( char *val, Filter *f ) *nextstar++ = '\0'; if ( gotstar == 0 ) { - f->f_sub_initial = strdup( val ); + f->f_sub_initial = ch_strdup( val ); } else if ( nextstar == NULL ) { - f->f_sub_final = strdup( val ); + f->f_sub_final = ch_strdup( val ); } else { - charray_add( &f->f_sub_any, strdup( val ) ); + charray_add( &f->f_sub_any, ch_strdup( val ) ); } gotstar = 1; diff --git a/servers/slapd/suffixalias.c b/servers/slapd/suffixalias.c index 26b990cd57..7b11e63b75 100644 --- a/servers/slapd/suffixalias.c +++ b/servers/slapd/suffixalias.c @@ -39,12 +39,12 @@ char *suffixAlias (char *dn, Operation *op, Backend *be) if (!strcasecmp(be->be_suffixAlias[i], dn + (dnLength - aliasLength))) { char *oldDN = dn; - op->o_suffixAliased = strdup ( be->be_suffixAlias[i] ); + op->o_suffixAliased = ch_strdup ( be->be_suffixAlias[i] ); dn = ch_malloc ( (dnLength - aliasLength) + strlen (be->be_suffixAlias[ i+1 ]) + 1); strncpy (dn, oldDN, dnLength - aliasLength); strcpy (dn + (dnLength - aliasLength), be->be_suffixAlias[ i+1 ]); - op->o_suffix = strdup (dn); + op->o_suffix = ch_strdup (dn); Debug( LDAP_DEBUG_ARGS, "ALIAS: converted %s to %s", oldDN, dn, 0); free (oldDN); break;