Misc library fixes from HEAD

This commit is contained in:
Kurt Zeilenga 2006-04-03 21:49:54 +00:00
parent d0848dd5fe
commit 4076114b80
22 changed files with 247 additions and 154 deletions

View file

@ -1023,7 +1023,7 @@ int ldap_pvt_sasl_secprops(
sasl_security_properties_t *secprops )
{
int i, j, l;
char **props = ldap_str2charray( in, "," );
char **props;
unsigned sflags = 0;
int got_sflags = 0;
sasl_ssf_t max_ssf = 0;
@ -1033,7 +1033,11 @@ int ldap_pvt_sasl_secprops(
unsigned maxbufsize = 0;
int got_maxbufsize = 0;
if( props == NULL || secprops == NULL ) {
if( secprops == NULL ) {
return LDAP_PARAM_ERROR;
}
props = ldap_str2charray( in, "," );
if( props == NULL ) {
return LDAP_PARAM_ERROR;
}
@ -1046,7 +1050,8 @@ int ldap_pvt_sasl_secprops(
if ( sprops[j].ival ) {
unsigned v;
char *next = NULL;
if ( !isdigit( props[i][sprops[j].key.bv_len] )) continue;
if ( !isdigit( (unsigned char)props[i][sprops[j].key.bv_len] ))
continue;
v = strtoul( &props[i][sprops[j].key.bv_len], &next, 10 );
if ( next == &props[i][sprops[j].key.bv_len] || next[0] != '\0' ) continue;
switch( sprops[j].ival ) {
@ -1068,6 +1073,7 @@ int ldap_pvt_sasl_secprops(
break;
}
if ( BER_BVISNULL( &sprops[j].key )) {
ldap_charray_free( props );
return LDAP_NOT_SUPPORTED;
}
}

View file

@ -104,6 +104,10 @@ static struct ldaperror ldap_builtin_errlist[] = {
{LDAP_CUP_UNSUPPORTED_SCHEME, N_("LCUP Unsupported Scheme")},
{LDAP_CUP_RELOAD_REQUIRED, N_("LCUP Reload Required")},
#ifdef LDAP_X_TXN
{LDAP_X_TXN_SPECIFY_OKAY, N_("TXN specify okay")},
{LDAP_X_TXN_ID_INVALID, N_("TXN ID is invalid")},
#endif
/* API ResultCodes */
{LDAP_SERVER_DOWN, N_("Can't contact LDAP server")},
@ -279,10 +283,19 @@ ldap_parse_result(
#endif
/* Find the result, last msg in chain... */
lm = r->lm_chain_tail;
if ((lm->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
(lm->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
(lm->lm_msgtype == LDAP_RES_INTERMEDIATE)) {
lm = NULL;
/* FIXME: either this is not possible (assert?)
* or it should be handled */
if ( lm != NULL ) {
switch ( lm->lm_msgtype ) {
case LDAP_RES_SEARCH_ENTRY:
case LDAP_RES_SEARCH_REFERENCE:
case LDAP_RES_INTERMEDIATE:
lm = NULL;
break;
default:
break;
}
}
if( lm == NULL ) {

View file

@ -417,6 +417,12 @@ ldap_int_destroy_global_options(void)
ldap_int_hostname = NULL;
}
#endif
#ifdef HAVE_CYRUS_SASL
if ( gopts->ldo_def_sasl_authcid ) {
LDAP_FREE( gopts->ldo_def_sasl_authcid );
gopts->ldo_def_sasl_authcid = NULL;
}
#endif
}
/*
@ -567,7 +573,7 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
if( user == NULL ) user = getenv("LOGNAME");
if( user != NULL ) {
gopts->ldo_def_sasl_authcid = user;
gopts->ldo_def_sasl_authcid = LDAP_STRDUP( user );
}
}
#endif

View file

@ -452,58 +452,6 @@ ldap_set_option(
}
} return LDAP_OPT_SUCCESS;
/* Only accessed from inside this function by ldap_set_rebind_proc() */
case LDAP_OPT_REBIND_PROC: {
lo->ldo_rebind_proc = (LDAP_REBIND_PROC *)invalue;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_REBIND_PARAMS: {
lo->ldo_rebind_params = (void *)invalue;
} return LDAP_OPT_SUCCESS;
/* Only accessed from inside this function by ldap_set_nextref_proc() */
case LDAP_OPT_NEXTREF_PROC: {
lo->ldo_nextref_proc = (LDAP_NEXTREF_PROC *)invalue;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_NEXTREF_PARAMS: {
lo->ldo_nextref_params = (void *)invalue;
} return LDAP_OPT_SUCCESS;
}
if(invalue == NULL) {
/* no place to set from */
return LDAP_OPT_ERROR;
}
/* options which cannot withstand invalue == NULL */
switch(option) {
case LDAP_OPT_API_INFO:
case LDAP_OPT_DESC:
/* READ ONLY */
break;
case LDAP_OPT_DEREF:
lo->ldo_deref = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_SIZELIMIT:
lo->ldo_sizelimit = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_TIMELIMIT:
lo->ldo_timelimit = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_PROTOCOL_VERSION: {
int vers = * (const int *) invalue;
if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
/* not supported */
break;
}
lo->ldo_version = vers;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_HOST_NAME: {
const char *host = (const char *) invalue;
LDAPURLDesc *ludlist = NULL;
@ -594,6 +542,57 @@ ldap_set_option(
return rc;
}
/* Only accessed from inside this function by ldap_set_rebind_proc() */
case LDAP_OPT_REBIND_PROC: {
lo->ldo_rebind_proc = (LDAP_REBIND_PROC *)invalue;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_REBIND_PARAMS: {
lo->ldo_rebind_params = (void *)invalue;
} return LDAP_OPT_SUCCESS;
/* Only accessed from inside this function by ldap_set_nextref_proc() */
case LDAP_OPT_NEXTREF_PROC: {
lo->ldo_nextref_proc = (LDAP_NEXTREF_PROC *)invalue;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_NEXTREF_PARAMS: {
lo->ldo_nextref_params = (void *)invalue;
} return LDAP_OPT_SUCCESS;
}
if(invalue == NULL) {
/* no place to set from */
return LDAP_OPT_ERROR;
}
/* options which cannot withstand invalue == NULL */
switch(option) {
case LDAP_OPT_API_INFO:
case LDAP_OPT_DESC:
/* READ ONLY */
break;
case LDAP_OPT_DEREF:
lo->ldo_deref = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_SIZELIMIT:
lo->ldo_sizelimit = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_TIMELIMIT:
lo->ldo_timelimit = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_PROTOCOL_VERSION: {
int vers = * (const int *) invalue;
if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
/* not supported */
break;
}
lo->ldo_version = vers;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_NUMBER: {
int err = * (const int *) invalue;

View file

@ -93,7 +93,6 @@ ldap_send_initial_request(
BerElement *ber,
ber_int_t msgid)
{
LDAPURLDesc *servers;
int rc;
Debug( LDAP_DEBUG_TRACE, "ldap_send_initial_request\n", 0, 0, 0 );
@ -112,14 +111,6 @@ ldap_send_initial_request(
0, 0, 0 );
}
{
/*
* use of DNS is turned off or this is an X.500 DN...
* use our default connection
*/
servers = NULL;
}
#ifdef LDAP_CONNECTIONLESS
if (LDAP_IS_UDP(ld)) {
if (msgtype == LDAP_REQ_BIND) {
@ -136,12 +127,10 @@ ldap_send_initial_request(
ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
#endif
rc = ldap_send_server_request( ld, ber, msgid, NULL,
servers, NULL, NULL );
NULL, NULL, NULL );
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
#endif
if (servers)
ldap_free_urllist(servers);
return(rc);
}
@ -422,6 +411,9 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb,
ldap_free_urldesc( srvfunc );
}
} else {
int msgid, rc;
struct berval passwd = BER_BVNULL;
savedefconn = ld->ld_defconn;
++lc->lconn_refcnt; /* avoid premature free */
ld->ld_defconn = lc;
@ -431,8 +423,42 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb,
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
#endif
if ( ldap_bind_s( ld, "", "", LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
rc = ldap_sasl_bind( ld, "", LDAP_SASL_SIMPLE, &passwd,
NULL, NULL, &msgid );
if ( rc != LDAP_SUCCESS ) {
err = -1;
} else {
for ( err = 1; err > 0; ) {
struct timeval tv = { 0, 100000 };
LDAPMessage *res = NULL;
switch ( ldap_result( ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) {
case -1:
err = -1;
break;
case 0:
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_yield();
#endif
break;
case LDAP_RES_BIND:
rc = ldap_parse_result( ld, res, &err, NULL, NULL, NULL, NULL, 1 );
if ( rc != LDAP_SUCCESS ) {
err = -1;
} else if ( err != LDAP_SUCCESS ) {
err = -1;
}
/* else err == LDAP_SUCCESS == 0 */
break;
default:
assert( 0 );
}
}
}
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
@ -871,20 +897,21 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char *
LDAPRequest *lp;
int looped = 0;
int len = srv->lud_dn ? strlen( srv->lud_dn ) : 0;
for (lp = origreq; lp; ) {
for ( lp = origreq; lp; ) {
if ( lp->lr_conn == lc ) {
if ( len == lp->lr_dn.bv_len ) {
if ( len && strncmp( srv->lud_dn, lp->lr_dn.bv_val,
len ))
continue;
if ( len == lp->lr_dn.bv_len
&& len
&& strncmp( srv->lud_dn, lp->lr_dn.bv_val, len ) == 0 )
{
looped = 1;
break;
}
}
if ( lp == origreq )
if ( lp == origreq ) {
lp = lp->lr_child;
else
} else {
lp = lr->lr_refnext;
}
}
if ( looped ) {
ldap_free_urllist( srv );
@ -894,7 +921,7 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char *
continue;
}
if( lc->lconn_rebind_inprogress) {
if ( lc->lconn_rebind_inprogress ) {
/* We are already chasing a referral or search reference and a
* bind on that connection is in progress. We must queue
* referrals on that connection, so we don't get a request

View file

@ -73,7 +73,7 @@ static int ldap_mark_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid ));
static int wait4msg LDAP_P(( LDAP *ld, ber_int_t msgid, int all, struct timeval *timeout,
LDAPMessage **result ));
static ber_tag_t try_read1msg LDAP_P(( LDAP *ld, ber_int_t msgid,
int all, Sockbuf *sb, LDAPConn **lc, LDAPMessage **result ));
int all, LDAPConn **lc, LDAPMessage **result ));
static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr ));
static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ));
static LDAPMessage * chkResponseList LDAP_P(( LDAP *ld, int msgid, int all));
@ -284,8 +284,7 @@ wait4msg(
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
#endif
rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
&lc, result );
rc = try_read1msg( ld, msgid, all, &lc, result );
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
#endif
@ -344,8 +343,7 @@ wait4msg(
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
#endif
rc = try_read1msg( ld, msgid, all,
lc->lconn_sb, &lc, result );
rc = try_read1msg( ld, msgid, all, &lc, result );
if ( lc == NULL ) lc = nextlc;
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
@ -384,7 +382,6 @@ try_read1msg(
LDAP *ld,
ber_int_t msgid,
int all,
Sockbuf *sb,
LDAPConn **lcp,
LDAPMessage **result )
{
@ -441,12 +438,12 @@ retry:
#ifdef LDAP_CONNECTIONLESS
if ( LDAP_IS_UDP(ld) ) {
struct sockaddr from;
ber_int_sb_read(sb, &from, sizeof(struct sockaddr));
ber_int_sb_read( lc->lconn_sb, &from, sizeof(struct sockaddr) );
if (ld->ld_options.ldo_version == LDAP_VERSION2) isv2=1;
}
nextresp3:
#endif
tag = ber_get_next( sb, &len, ber );
tag = ber_get_next( lc->lconn_sb, &len, ber );
if ( tag == LDAP_TAG_MESSAGE ) {
/*
* We read a complete message.
@ -486,7 +483,7 @@ nextresp3:
(void *)ld, (long) id, 0);
retry_ber:
ber_free( ber, 1 );
if ( ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ) ) {
if ( ber_sockbuf_ctrl( lc->lconn_sb, LBER_SB_OPT_DATA_READY, NULL ) ) {
goto retry;
}
return( LDAP_MSG_X_KEEP_LOOKING ); /* continue looking */
@ -827,7 +824,7 @@ lr->lr_res_matched ? lr->lr_res_matched : "" );
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
#endif
*lcp = NULL;
lc = *lcp = NULL;
}
}
}
@ -888,8 +885,8 @@ lr->lr_res_matched ? lr->lr_res_matched : "" );
* datagram, if the sockbuf is readable we still have data
* to parse.
*/
ber = ldap_alloc_ber_with_options(ld);
if (ber_sockbuf_ctrl(sb, LBER_SB_OPT_DATA_READY, NULL)) ok=1;
ber = ldap_alloc_ber_with_options( ld );
if ( ber_sockbuf_ctrl( lc->lconn_sb, LBER_SB_OPT_DATA_READY, NULL ) ) ok = 1;
}
/* set up response chain */
if ( tmp == NULL ) {
@ -988,7 +985,7 @@ exit:
ld->ld_errno = LDAP_SUCCESS;
return( tag );
}
if ( ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ) ) {
if ( lc && ber_sockbuf_ctrl( lc->lconn_sb, LBER_SB_OPT_DATA_READY, NULL ) ) {
goto retry;
}
return( LDAP_MSG_X_KEEP_LOOKING ); /* continue looking */

View file

@ -1414,16 +1414,20 @@ add_extension(LDAPSchemaExtensionItem ***extensions,
if ( !*extensions ) {
*extensions =
LDAP_CALLOC(2, sizeof(LDAPSchemaExtensionItem *));
if ( !*extensions )
return 1;
if ( !*extensions ) {
LDAP_FREE( ext );
return 1;
}
n = 0;
} else {
for ( n=0; (*extensions)[n] != NULL; n++ )
;
tmp = LDAP_REALLOC(*extensions,
(n+2)*sizeof(LDAPSchemaExtensionItem *));
if ( !tmp )
if ( !tmp ) {
LDAP_FREE( ext );
return 1;
}
*extensions = tmp;
}
(*extensions)[n] = ext;
@ -3231,6 +3235,21 @@ ldap_str2nameform( LDAP_CONST char * s,
seen_obsolete = 1;
nf->nf_obsolete = LDAP_SCHEMA_YES;
parse_whsp(&ss);
} else if ( !strcasecmp(sval,"OC") ) {
LDAP_FREE(sval);
if ( seen_class ) {
*code = LDAP_SCHERR_DUPOPT;
*errp = ss;
ldap_nameform_free(nf);
return(NULL);
}
seen_class = 1;
nf->nf_objectclass = parse_woid(&ss,code);
if ( !nf->nf_objectclass ) {
*errp = ss;
ldap_nameform_free(nf);
return NULL;
}
} else if ( !strcasecmp(sval,"MUST") ) {
LDAP_FREE(sval);
if ( seen_must ) {

View file

@ -205,6 +205,10 @@ get_modlist(
6 ) == 0 ) {
if ( file_read( tmp.mod_values[i] + 6,
bvals[i] ) < 0 ) {
free( bvals );
for ( i = 0; i<num; i++ )
free( result[ i ] );
free( result );
return( NULL );
}
} else {

View file

@ -42,6 +42,7 @@ ldap_turn(
LDAPControl **cctrls,
int *msgidp )
{
#ifdef LDAP_EXOP_X_TURN
BerElement *turnvalber = NULL;
struct berval *turnvalp = NULL;
int rc;
@ -58,6 +59,9 @@ ldap_turn(
turnvalp, sctrls, cctrls, msgidp );
ber_free( turnvalber, 1 );
return rc;
#else
return LDAP_CONTROL_NOT_FOUND;
#endif
}
int
@ -68,6 +72,7 @@ ldap_turn_s(
LDAPControl **sctrls,
LDAPControl **cctrls )
{
#ifdef LDAP_EXOP_X_TURN
BerElement *turnvalber = NULL;
struct berval *turnvalp = NULL;
int rc;
@ -84,5 +89,8 @@ ldap_turn_s(
turnvalp, sctrls, cctrls, NULL, NULL );
ber_free( turnvalber, 1 );
return rc;
#else
return LDAP_CONTROL_NOT_FOUND;
#endif
}

View file

@ -106,6 +106,11 @@ ldap_ld_free(
next = lm->lm_next;
ldap_msgfree( lm );
}
if ( ld->ld_abandoned != NULL ) {
LDAP_FREE( ld->ld_abandoned );
ld->ld_abandoned = NULL;
}
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
#endif
@ -125,11 +130,6 @@ ldap_ld_free(
ld->ld_referrals = NULL;
}
if ( ld->ld_abandoned != NULL ) {
LDAP_FREE( ld->ld_abandoned );
ld->ld_abandoned = NULL;
}
if ( ld->ld_selectinfo != NULL ) {
ldap_free_select_info( ld->ld_selectinfo );
ld->ld_selectinfo = NULL;
@ -194,6 +194,7 @@ ldap_ld_free(
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_destroy( &ld->ld_req_mutex );
ldap_pvt_thread_mutex_destroy( &ld->ld_res_mutex );
ldap_pvt_thread_mutex_destroy( &ld->ld_conn_mutex );
#endif
#ifndef NDEBUG
LDAP_TRASH(ld);

View file

@ -348,7 +348,7 @@ hex_escape_len( const char *s, unsigned list )
/* RFC 2396: unreserved alphanum */
default:
if ( !isalnum( s[0] ) ) {
if ( !isalnum( (unsigned char) s[0] ) ) {
len += 3;
} else {
len++;
@ -413,7 +413,7 @@ hex_escape( char *buf, int len, const char *s, unsigned list )
/* RFC 2396: unreserved alphanum */
default:
if ( !isalnum( s[i] ) ) {
if ( !isalnum( (unsigned char) s[i] ) ) {
escape = 1;
}
break;
@ -1320,12 +1320,18 @@ ldap_url_parsehosts(
specs[i] = ludp->lud_host;
ludp->lud_host = p;
p = strchr( ludp->lud_host, ']' );
if ( p == NULL )
if ( p == NULL ) {
LDAP_FREE(ludp);
ldap_charray_free(specs);
return LDAP_PARAM_ERROR;
}
*p++ = '\0';
if ( *p != ':' ) {
if ( *p != '\0' )
if ( *p != '\0' ) {
LDAP_FREE(ludp);
ldap_charray_free(specs);
return LDAP_PARAM_ERROR;
}
p = NULL;
}
} else {
@ -1339,6 +1345,8 @@ ldap_url_parsehosts(
ldap_pvt_hex_unescape(p);
ludp->lud_port = strtol( p, &next, 10 );
if ( next == p || next[0] != '\0' ) {
LDAP_FREE(ludp);
ldap_charray_free(specs);
return LDAP_PARAM_ERROR;
}
}

View file

@ -129,8 +129,12 @@ ldap_x_utf8s_to_wcs ( wchar_t *wcstr, const char *utf8str, size_t count )
wchar_t ch;
/* If input ptr is NULL, treat it as empty string. */
if (utf8str == NULL) utf8str = "";
/* If input ptr is NULL or empty... */
if (utf8str == NULL || !*utf8str) {
if ( wcstr )
*wcstr = 0;
return 0;
}
/* Examine next UTF-8 character. If output buffer is NULL, ignore count */
while ( *utf8str && (wcstr==NULL || wclen<count) ) {

View file

@ -78,6 +78,8 @@ ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rwlock )
rw = (struct ldap_int_thread_rdwr_s *) LDAP_CALLOC( 1,
sizeof( struct ldap_int_thread_rdwr_s ) );
if ( !rw )
return LDAP_NO_MEMORY;
/* we should check return results */
ldap_pvt_thread_mutex_init( &rw->ltrw_mutex );

View file

@ -224,7 +224,8 @@ ldap_pvt_thread_yield( void )
#endif
return 0;
#elif HAVE_THR_YIELD
return thr_yield();
thr_yield();
return 0;
#elif HAVE_PTHREADS == 10
return sched_yield();

View file

@ -353,7 +353,6 @@ int
ldap_pvt_thread_pool_destroy ( ldap_pvt_thread_pool_t *tpool, int run_pending )
{
struct ldap_int_thread_pool_s *pool, *pptr;
long waiting;
ldap_int_thread_ctx_t *ctx;
if (tpool == NULL)

View file

@ -401,6 +401,7 @@ int UTF8bvnormcmp(
l1 = ulen;
ucs = malloc( l2 * sizeof(*ucs) );
if ( ucs == NULL ) {
free( ucsout1 );
return l1 > l2 ? 1 : -1; /* what to do??? */
}
} else {

View file

@ -734,7 +734,7 @@ int ldif_is_not_printable(
ber_len_t i;
for ( i = 0; val[i]; i++ ) {
if ( !isascii( val[i] ) || !isprint( val[i] ) ) {
if ( !isascii( val[i] ) || !isprint( (unsigned char) val[i] ) ) {
return 1;
}
}
@ -858,7 +858,7 @@ ldif_read_record(
}
ptr = line + STRLENOF("include:");
while (isspace(*ptr)) ptr++;
while (isspace((unsigned char) *ptr)) ptr++;
fp2 = ldif_open_url( ptr );
if ( fp2 ) {
LDIFFP *lnew = ber_memalloc( sizeof( LDIFFP ));

View file

@ -207,7 +207,7 @@ int lutil_parsetime( char *atm, struct lutil_tm *tm )
unsigned i, fracs;
/* Is the stamp reasonably long? */
for (i=0; isdigit(atm[i]); i++);
for (i=0; isdigit((unsigned char) atm[i]); i++);
if (i < sizeof("00000101000000")-1)
break;
@ -247,7 +247,7 @@ int lutil_parsetime( char *atm, struct lutil_tm *tm )
if (tm->tm_sec < 0 || tm->tm_sec > 61) break;
/* Fractions of seconds */
for (i = 0, fracs = 0;isdigit(*ptr);) {
for (i = 0, fracs = 0; isdigit((unsigned char) *ptr); ) {
i*=10; i+= *ptr++ - '0';
fracs++;
}

View file

@ -431,6 +431,7 @@ rewrite_parse_builtin_map(
* Error
*/
} else {
free( map );
Debug( LDAP_DEBUG_ANY, "[%s:%d] unknown map type\n%s",
fname, lineno, "" );
return -1;

View file

@ -99,11 +99,20 @@ destroy_action(
return 0;
}
static void
destroy_actions(
struct rewrite_action *paction
)
{
struct rewrite_action *next;
for (; paction; paction = next) {
next = paction->la_next;
destroy_action( &paction );
}
}
/*
* In case of error it returns NULL and does not free all the memory
* it allocated; as this is a once only phase, and an error at this stage
* would require the server to stop, there is no need to be paranoid
* about memory allocation
*/
int
rewrite_rule_compile(
@ -186,8 +195,7 @@ rewrite_rule_compile(
*/
action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) {
/* cleanup ... */
return REWRITE_ERR;
goto fail;
}
action->la_type = REWRITE_ACTION_STOP;
@ -199,8 +207,7 @@ rewrite_rule_compile(
*/
action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) {
/* cleanup ... */
return REWRITE_ERR;
goto fail;
}
mode &= ~REWRITE_RECURSE;
@ -222,26 +229,24 @@ rewrite_rule_compile(
int *d;
if ( p[ 1 ] != '{' ) {
/* XXX Need to free stuff */
return REWRITE_ERR;
goto fail;
}
d = malloc( sizeof( int ) );
if ( d == NULL ) {
/* XXX Need to free stuff */
return REWRITE_ERR;
goto fail;
}
d[ 0 ] = strtol( &p[ 2 ], &next, 0 );
if ( next == &p[ 2 ] || next[0] != '}' ) {
/* XXX Need to free stuff */
return REWRITE_ERR;
free( d );
goto fail;
}
action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) {
/* cleanup ... */
return REWRITE_ERR;
free( d );
goto fail;
}
switch ( p[ 0 ] ) {
case REWRITE_FLAG_GOTO:
@ -270,14 +275,12 @@ rewrite_rule_compile(
char *next = NULL;
if ( p[ 1 ] != '{' ) {
/* XXX Need to free stuff */
return REWRITE_ERR;
goto fail;
}
max_passes = strtol( &p[ 2 ], &next, 0 );
if ( next == &p[ 2 ] || next[0] != '}' ) {
/* XXX Need to free stuff */
return REWRITE_ERR;
goto fail;
}
if ( max_passes < 1 ) {
@ -296,8 +299,7 @@ rewrite_rule_compile(
*/
action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) {
/* cleanup ... */
return REWRITE_ERR;
goto fail;
}
action->la_type = REWRITE_ACTION_IGNORE_ERR;
@ -327,23 +329,15 @@ rewrite_rule_compile(
*/
rule = calloc( sizeof( struct rewrite_rule ), 1 );
if ( rule == NULL ) {
/* charray_free( res ); */
/*
* XXX need to free the value subst stuff!
*/
return REWRITE_ERR;
goto fail;
}
/*
* REGEX compilation (luckily I don't need to take care of this ...)
*/
if ( regcomp( &rule->lr_regex, ( char * )pattern, flags ) != 0 ) {
/* charray_free( res ); */
/*
*XXX need to free the value subst stuff!
*/
free( rule );
return REWRITE_ERR;
goto fail;
}
/*
@ -372,6 +366,11 @@ rewrite_rule_compile(
append_rule( context, rule );
return REWRITE_SUCCESS;
fail:
destroy_actions( first_action );
free( subst );
return REWRITE_ERR;
}
/*
@ -462,7 +461,6 @@ rewrite_rule_destroy(
)
{
struct rewrite_rule *rule;
struct rewrite_action *action;
assert( prule != NULL );
assert( *prule != NULL );
@ -490,12 +488,7 @@ rewrite_rule_destroy(
regfree( &rule->lr_regex );
for ( action = rule->lr_action; action; ) {
struct rewrite_action *curraction = action;
action = action->la_next;
destroy_action( &curraction );
}
destroy_actions( rule->lr_action );
free( rule );
*prule = NULL;

View file

@ -324,6 +324,9 @@ rewrite_session_clean( void *v_session )
static void
rewrite_session_free( void *v_session )
{
struct rewrite_session *session = (struct rewrite_session *)v_session;
ldap_pvt_thread_mutex_lock( &session->ls_mutex );
rewrite_session_clean( v_session );
free( v_session );
}

View file

@ -214,7 +214,8 @@ rewrite_xmap_parse(
/* Unhandled map */
}
free( map );
return NULL;
}