]> git.sur5r.net Git - openldap/commitdiff
cleanup and fixes
authorPierangelo Masarati <ando@openldap.org>
Thu, 3 Apr 2003 21:35:27 +0000 (21:35 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 3 Apr 2003 21:35:27 +0000 (21:35 +0000)
servers/slapd/back-ldap/back-ldap.h
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/init.c
servers/slapd/back-ldap/search.c

index 7a21585ef80687f453aeb6476968ea040658e377..9d5f0eac6a2572a761e5e9d5153f3cca8eaca4c1 100644 (file)
@@ -76,8 +76,8 @@ struct ldapmapping {
 struct ldapinfo {
        struct slap_backend_db  *be;
        char *url;
-       char *binddn;
-       char *bindpw;
+       struct berval binddn;
+       struct berval bindpw;
        ldap_pvt_thread_mutex_t         conn_mutex;
        int savecred;
        Avlnode *conntree;
@@ -158,7 +158,7 @@ extern int suffix_massage_config( struct rewrite_info *info,
 extern int ldap_dnattr_rewrite( struct rewrite_info *rwinfo, BerVarray a_vals, void *cookie );
 #endif /* ENABLE_REWRITE */
 
-int ldap_build_entry( Backend *be, Connection *c, LDAPMessage *e, Entry *ent,
+int ldap_build_entry( Operation *op, LDAPMessage *e, Entry *ent,
         struct berval *bdn, int private );
 
 LDAP_END_DECL
index f8972bc41161fe6be8a698415c94a07094abbd2b..e050576c29c0eb610a0ba56fee8ac8cb489eeb16 100644 (file)
@@ -72,17 +72,23 @@ ldap_back_bind(
         * Rewrite the bind dn if needed
         */
 #ifdef ENABLE_REWRITE
-       switch ( rewrite_session( li->rwinfo, "bindDn", op->o_req_dn.bv_val, op->o_conn, &mdn.bv_val ) ) {
+       switch ( rewrite_session( li->rwinfo, "bindDn",
+                               op->o_req_dn.bv_val,
+                               op->o_conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
                if ( mdn.bv_val == NULL ) {
-                       mdn.bv_val = ( char * )op->o_req_dn.bv_val;
+                       mdn = op->o_req_dn;
+               } else {
+                       mdn.bv_len = strlen( mdn.bv_val );
                }
+
 #ifdef NEW_LOGGING
                LDAP_LOG( BACK_LDAP, DETAIL1, 
-                       "[rw] bindDn: \"%s\" -> \"%s\"\n", op->o_req_dn.bv_val, mdn.bv_val, 0 );
+                               "[rw] bindDn: \"%s\" -> \"%s\"\n",
+                               op->o_req_dn.bv_val, mdn.bv_val, 0 );
 #else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS, "rw> bindDn: \"%s\" -> \"%s\"\n%s",
-                               op->o_req_dn.bv_val, mdn.bv_val, "" );
+               Debug( LDAP_DEBUG_ARGS, "rw> bindDn: \"%s\" -> \"%s\"\n",
+                               op->o_req_dn.bv_val, mdn.bv_val, 0 );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -126,17 +132,19 @@ ldap_back_bind(
        }
 
        /* must re-insert if local DN changed as result of bind */
-       if ( lc->bound && ber_bvcmp(&op->o_req_ndn, &lc->local_dn ) ) {
-               int err;
+       if ( lc->bound && !bvmatch(&op->o_req_ndn, &lc->local_dn ) ) {
+               int lerr;
+
                ldap_pvt_thread_mutex_lock( &li->conn_mutex );
-               lc = avl_delete( &li->conntree, (caddr_t)lc, ldap_back_conn_cmp );
+               lc = avl_delete( &li->conntree, (caddr_t)lc,
+                               ldap_back_conn_cmp );
                if ( lc->local_dn.bv_val )
                        ch_free( lc->local_dn.bv_val );
                ber_dupbv( &lc->local_dn, &op->o_req_ndn );
-               err = avl_insert( &li->conntree, (caddr_t)lc,
+               lerr = avl_insert( &li->conntree, (caddr_t)lc,
                        ldap_back_conn_cmp, ldap_back_conn_dup );
                ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
-               if ( err == -1 ) {
+               if ( lerr == -1 ) {
                        ldap_back_conn_free( lc );
                }
        }
@@ -167,7 +175,7 @@ ldap_back_conn_cmp(
        /* For shared sessions, conn is NULL. Only explicitly
         * bound sessions will have non-NULL conn.
         */
-       return lc1->conn - lc2->conn;
+       return (int)lc1->conn - (int)lc2->conn;
 }
 
 /*
@@ -207,7 +215,8 @@ static void ravl_print( Avlnode *root, int depth )
                printf( "   " );
 
        lc = root->avl_data;
-       printf( "lc(%lx) local(%s) conn(%lx) %d\n", lc, lc->local_dn.bv_val, lc->conn, root->avl_bf );
+       printf( "lc(%lx) local(%s) conn(%lx) %d\n",
+                       lc, lc->local_dn.bv_val, lc->conn, root->avl_bf );
        
        ravl_print( root->avl_left, depth+1 );
 }
@@ -276,7 +285,7 @@ ldap_back_getconn(struct ldapinfo *li, Operation *op, SlapReply *rs)
                ber_dupbv( &lc->local_dn, &lc_curr.local_dn );
 
                if ( is_priv ) {
-                       ber_str2bv( li->bindpw, 0, 1, &lc->cred );
+                       ber_dupbv( &lc->cred, &li->bindpw );
                } else {
                        lc->cred.bv_len = 0;
                        lc->cred.bv_val = NULL;
@@ -300,25 +309,28 @@ ldap_back_getconn(struct ldapinfo *li, Operation *op, SlapReply *rs)
                        lc->bound_dn.bv_val = NULL;
                        lc->bound_dn.bv_len = 0;
                        switch ( rewrite_session( li->rwinfo, "bindDn",
-                                               op->o_conn->c_dn.bv_val, op->o_conn,
+                                               op->o_conn->c_dn.bv_val,
+                                               op->o_conn,
                                                &lc->bound_dn.bv_val ) ) {
                        case REWRITE_REGEXEC_OK:
                                if ( lc->bound_dn.bv_val == NULL ) {
                                        ber_dupbv( &lc->bound_dn,
                                                        &op->o_conn->c_dn );
+                               } else {
+                                       lc->bound_dn.bv_len = strlen( lc->bound_dn.bv_val );
                                }
 #ifdef NEW_LOGGING
                                LDAP_LOG( BACK_LDAP, DETAIL1, 
                                                "[rw] bindDn: \"%s\" ->" 
-                                               " \"%s\"\n%s",
+                                               " \"%s\"\n",
                                                op->o_conn->c_dn.bv_val, 
-                                               lc->bound_dn.bv_val, "" );
+                                               lc->bound_dn.bv_val, 0 );
 #else /* !NEW_LOGGING */
                                Debug( LDAP_DEBUG_ARGS,
                                                "rw> bindDn: \"%s\" ->"
-                                               " \"%s\"\n%s",
+                                               " \"%s\"\n",
                                                op->o_conn->c_dn.bv_val,
-                                               lc->bound_dn.bv_val, "" );
+                                               lc->bound_dn.bv_val, 0 );
 #endif /* !NEW_LOGGING */
                                break;
                                
@@ -367,8 +379,7 @@ ldap_back_getconn(struct ldapinfo *li, Operation *op, SlapReply *rs)
                        "ldap_back_getconn: conn %lx inserted\n", lc, 0, 0);
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_TRACE,
-                       "=>ldap_back_getconn: conn %lx inserted\n%s%s",
-                       lc, "", "" );
+                       "=>ldap_back_getconn: conn %lx inserted\n", lc, 0, 0 );
 #endif /* !NEW_LOGGING */
        
                /* Err could be -1 in case a duplicate ldapconn is inserted */
@@ -385,8 +396,7 @@ ldap_back_getconn(struct ldapinfo *li, Operation *op, SlapReply *rs)
                        lc, 0, 0 );
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_TRACE,
-                       "=>ldap_back_getconn: conn %lx fetched%s%s\n",
-                       lc, "", "" );
+                       "=>ldap_back_getconn: conn %lx fetched\n", lc, 0, 0 );
 #endif /* !NEW_LOGGING */
        }
        
@@ -535,9 +545,9 @@ ldap_back_op_result(struct ldapinfo *li, struct ldapconn *lc,
        }
        if (rs->sr_matched != match) free((char *)rs->sr_matched);
        rs->sr_matched = NULL;
-       if ( match ) free( match );
+       if ( match ) ldap_memfree( match );
        if ( rs->sr_text ) {
-               free( (char *)rs->sr_text );
+               ldap_memfree( (char *)rs->sr_text );
                rs->sr_text = NULL;
        }
        return( (err==LDAP_SUCCESS) ? 0 : -1 );
index 2cdbeb21d303b5628268025c64036fce6c507d30..f1eadd992a8e9ce2d03a961cd09cc6e373577795 100644 (file)
@@ -102,7 +102,7 @@ ldap_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->binddn = ch_strdup(argv[1]);
+               ber_str2bv( argv[1], 0, 1, &li->binddn );
 
        /* password to use for ldap_back_group */
        } else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
@@ -112,7 +112,7 @@ ldap_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->bindpw = ch_strdup(argv[1]);
+               ber_str2bv( argv[1], 0, 1, &li->bindpw );
        
        /* save bind creds for referral rebinds? */
        } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
index 765660806ebd7953a4821e488f98fd350f5e785d..3beaec8d57f53ff4927794653b66f08d081d10ee 100644 (file)
@@ -111,6 +111,11 @@ ldap_back_db_init(
                return -1;
        }
 
+       li->binddn.bv_val = NULL;
+       li->binddn.bv_len = 0;
+       li->bindpw.bv_val = NULL;
+       li->bindpw.bv_len = 0;
+
 #ifdef ENABLE_REWRITE
        li->rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
        if ( li->rwinfo == NULL ) {
@@ -174,13 +179,13 @@ ldap_back_db_destroy(
                        ch_free(li->url);
                        li->url = NULL;
                }
-               if (li->binddn) {
-                       ch_free(li->binddn);
-                       li->binddn = NULL;
+               if (li->binddn.bv_val) {
+                       ch_free(li->binddn.bv_val);
+                       li->binddn.bv_val = NULL;
                }
-               if (li->bindpw) {
-                       ch_free(li->bindpw);
-                       li->bindpw = NULL;
+               if (li->bindpw.bv_val) {
+                       ch_free(li->bindpw.bv_val);
+                       li->bindpw.bv_val = NULL;
                }
                 if (li->conntree) {
                        avl_free( li->conntree, ldap_back_conn_free );
index 1dd06f0344c837f24fae74dd38dd9cf49de4ec8d..3fafc9dcc849bf620c175ff157d1a3461b4d5d1a 100644 (file)
@@ -61,14 +61,13 @@ ldap_back_search(
        struct ldapconn *lc;
        struct timeval  tv;
        LDAPMessage             *res, *e;
-       int     count, rc = 0, msgid, sres = LDAP_SUCCESS
+       int     count, rc = 0, msgid; 
        char *match = NULL;
        char **mapped_attrs = NULL;
        struct berval mbase;
        struct berval mfilter = { 0, NULL };
        struct slap_limits_set *limit = NULL;
        int isroot = 0;
-       BerVarray v2refs = NULL;
 
        lc = ldap_back_getconn(li, op, rs);
        if ( !lc ) {
@@ -233,7 +232,7 @@ fail:;
                        Entry ent;
                        struct berval bdn;
                        e = ldap_first_entry(lc->ld,res);
-                       if ( ldap_build_entry(op->o_bd, op->o_conn, e, &ent, &bdn, 1) == LDAP_SUCCESS ) {
+                       if ( ldap_build_entry(op, e, &ent, &bdn, 1) == LDAP_SUCCESS ) {
                                Attribute *a;
                                rs->sr_entry = &ent;
                                rs->sr_attrs = op->oq_search.rs_attrs;
@@ -376,15 +375,14 @@ finish:;
 
 int
 ldap_build_entry(
-       Backend *be,
-       Connection *conn,
+       Operation *op,
        LDAPMessage *e,
        Entry *ent,
        struct berval *bdn,
        int private
 )
 {
-       struct ldapinfo *li = (struct ldapinfo *) be->be_private;
+       struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
        struct berval a, mapped;
        BerElement ber = *e->lm_ber;
        Attribute *attr, **attrp;
@@ -400,7 +398,8 @@ ldap_build_entry(
         * Rewrite the dn of the result, if needed
         */
        switch ( rewrite_session( li->rwinfo, "searchResult",
-                               bdn->bv_val, conn, &ent->e_name.bv_val ) ) {
+                               bdn->bv_val, op->o_conn,
+                               &ent->e_name.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
                if ( ent->e_name.bv_val == NULL ) {
                        ent->e_name = *bdn;
@@ -539,7 +538,7 @@ ldap_build_entry(
                                switch ( rewrite_session( li->rwinfo,
                                                        "searchResult",
                                                        bv->bv_val,
-                                                       conn, 
+                                                       op->o_conn, 
                                                        &newval.bv_val )) {
                                case REWRITE_REGEXEC_OK:
                                        /* left as is */
@@ -678,7 +677,7 @@ ldap_back_entry_get(
 
        *ent = ch_malloc(sizeof(Entry));
 
-       rc = ldap_build_entry(op->o_bd, op->o_conn, e, *ent, &bdn, 0);
+       rc = ldap_build_entry(op, e, *ent, &bdn, 0);
 
        if (rc != LDAP_SUCCESS) {
                ch_free(*ent);