Commit e2ee741e authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

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.
parent 9b09d42a
......@@ -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];
......
......@@ -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 <who> */
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 <who> got \"%s\"\n",
......
......@@ -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 */
......
......@@ -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;
......
......@@ -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);
......
......@@ -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 );
......
......@@ -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 |
......
......@@ -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 ) {
......
......@@ -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 ) {
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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 );
......
......@@ -60,7 +60,7 @@ ldbm_back_modrdn(
strcat( newdn, pdn );
}
} else {
newdn = strdup( newrdn );
newdn = ch_strdup( newrdn );
}
(void) dn_normalize( newdn );
......
......@@ -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;
......
......@@ -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",
......
......@@ -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 );
......
......@@ -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 */
......
......@@ -3,6 +3,7 @@
#include "portable.h"
#include <stdio.h>
#include <stdlib.h>
#include <ac/string.h>
#include <ac/socket.h>
......@@ -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 );
}
......@@ -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;
......
......@@ -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 {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment