]> git.sur5r.net Git - openldap/commitdiff
Misc library fixes from HEAD
authorKurt Zeilenga <kurt@openldap.org>
Mon, 3 Apr 2006 21:49:54 +0000 (21:49 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 3 Apr 2006 21:49:54 +0000 (21:49 +0000)
22 files changed:
libraries/libldap/cyrus.c
libraries/libldap/error.c
libraries/libldap/init.c
libraries/libldap/options.c
libraries/libldap/request.c
libraries/libldap/result.c
libraries/libldap/schema.c
libraries/libldap/test.c
libraries/libldap/turn.c
libraries/libldap/unbind.c
libraries/libldap/url.c
libraries/libldap/utf-8-conv.c
libraries/libldap_r/rdwr.c
libraries/libldap_r/thr_posix.c
libraries/libldap_r/tpool.c
libraries/liblunicode/ucstr.c
libraries/liblutil/ldif.c
libraries/liblutil/utils.c
libraries/librewrite/config.c
libraries/librewrite/rule.c
libraries/librewrite/session.c
libraries/librewrite/xmap.c

index 6222090d231e3cc156cc36972955d74e50882eb4..ac963fc85e8de767974cc51656baf29931ef511e 100644 (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;
                }
        }
index e8d4d179f4fb4342d1cde956221e157e4816bbb6..76dbe0136fcfd7dcc6a097b71f59a12e528e28b0 100644 (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 ) {
index dc65b464765e2ae07ede48c288e6292845cdbc93..98b64eea9993333ce5d25b489810a471024192cb 100644 (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
index 9d608c9c2c759403de25839c466de90f44c3a4b2..4b76a0c5f7aa2553620e10f5bc1a4919f03be70f 100644 (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;
 
index 379e3aeeebc0856e28d8059ef7eb53586025437b..ce56f7ea7c55a12b5719a35e070df77895da0a9c 100644 (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
index ad3263d3927b4f3d1ff4b0f09ee290e1a07dba01..b33afc48e435c459dc7f5e4c40bef6b412feb85b 100644 (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 */
index 820ae3a875e88af6d72ff0c092a7fa8cfd63c9b7..46271968e663fa2fb965fe59dbbadc10474f2e2a 100644 (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 ) {
index 1affb1c71444e6e94ed9c61818a31d5147ee6e9c..88060893121c4fd5a198f3dc6072e40a618d2585 100644 (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 {
index 2ddd608805c63f0268899014d71c92fa88f3d538..bcda1cbf5dd689d9f9b253f65fb194ffaff3efd5 100644 (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
 }
 
index 24cf90ad249c6d9bbb9b47524f691c6efb3ff658..564432ea78f466efbce0628d3227b67ecdeb4379 100644 (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);
index a87b1ca8a453714282aa0cdac399fa26ae71c7ae..0539b75fa65ea9e5d273289f25fdbfce54328320 100644 (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;
                                }
                        }
index 29809deca6c70ce83585882c62433d687ef6b115..e1ffe3c67b66478b134c6d81a75031e4c74ea462 100644 (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) ) {
index 81febcbd2dbaa39f550bc3bba0a466a86ab10643..45f642de4f46b0815959615c3803b0ffd7e76210 100644 (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 );
index c867e5715bebe9a895b2d8f2c9fb8d23c814c877..ce48b32b53000e919b28449f138745bb055e6422 100644 (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();
index d044f05d1cfcc7fd24960cd5121014e32d76ed0b..dde68e882609ed2fe3fe093875a8f0f38a10d8e6 100644 (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)
index 21bd0b41935187e7d1ac998e475b89a01bb75387..d964649addb5bb79d5ff4c40e38e12bd42b3424b 100644 (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 {
index 32e52d1ca758d654335550fc08d3cc0b2fb5674f..defc1932d34c0ecd9a17682166f0317ae890fe52 100644 (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 ));
index 7e86618e51ff45aeee957097ee56b831a620a687..e76395f4e97af4dd93a00edb2904942f8d1e8a00 100644 (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++;
                }
index a8ca8cc71d9ec8ce0cfd9b634e3da20c929b7d53..3cbd1f73e76d928d689db9fbc282c14cbef5cec5 100644 (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;
index 9659b11722c79d617df86ad730e7cb4ccb3e0d48..f834bca78b42613d01f4769ebecb70050d4a6854 100644 (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;
index 1471ec787e57a503b9cd426d03894f7cfb2884f6..bcec2d401f337243a1c452a8426b5bb4bde08296 100644 (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 );
 }
index fbc73d0bf4050d9011c9535128d42adfb843d56d..d0d0874f7115d39f504fc6dd147d5b1e8b832415 100644 (file)
@@ -214,7 +214,8 @@ rewrite_xmap_parse(
        
        /* Unhandled map */
        }
-       
+
+       free( map );
        return NULL;
 }