]> git.sur5r.net Git - openldap/commitdiff
allow to search for "auxiliary" objectClasses (i.e. those in ldap_entry_objclasses...
authorPierangelo Masarati <ando@openldap.org>
Fri, 20 Aug 2004 12:06:03 +0000 (12:06 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 20 Aug 2004 12:06:03 +0000 (12:06 +0000)
servers/slapd/back-sql/bind.c
servers/slapd/back-sql/compare.c
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/rdbms_depend/mysql/backsql_create.sql
servers/slapd/back-sql/rdbms_depend/mysql/testdb_data.sql
servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/util.c

index 21906b22f4520c040efeeb1a91c8eee9eebde080..a871cdc71d798a01a47b37bd1c8fea7f6315ab54 100644 (file)
@@ -101,21 +101,24 @@ backsql_bind( Operation *op, SlapReply *rs )
 
        backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE, 
                        -1, -1, -1, NULL, dbh, op, rs, anlist );
-       e = backsql_id2entry( &bsi, &user_entry, &user_id );
-       if ( e == NULL ) {
+       bsi.bsi_e = &user_entry;
+       rc = backsql_id2entry( &bsi, &user_id );
+       if ( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
-                       "error in backsql_id2entry() - auth failed\n",
-                       0, 0, 0 );
-               rs->sr_err = LDAP_OTHER;
+                       "error %d in backsql_id2entry() "
+                       "- auth failed\n", rc, 0, 0 );
+               rs->sr_err = LDAP_INVALID_CREDENTIALS;
                goto error_return;
        }
+       e = &user_entry;
 
        if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
                rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
                goto error_return;
        }
 
-       if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
+       a = attr_find( e->e_attrs, password );
+       if ( a == NULL ) {
                rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
                goto error_return;
        }
index b5a4582a814d4e95ab2b02a0b895f726febc9c19..9dd4ea76206939756be82a43bda9ae3d312434f0 100644 (file)
@@ -104,20 +104,21 @@ backsql_compare( Operation *op, SlapReply *rs )
                }
                
                user_entry.e_attrs = nrs.sr_operational_attrs;
-               e = &user_entry;
 
        } else {
                backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE, 
                                -1, -1, -1, NULL, dbh, op, rs, anlist );
-               e = backsql_id2entry( &bsi, &user_entry, &user_id );
-               if ( e == NULL ) {
+               bsi.bsi_e = &user_entry;
+               rc = backsql_id2entry( &bsi, &user_id );
+               if ( rc != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
-                               "error in backsql_id2entry() "
-                               "- compare failed\n", 0, 0, 0 );
-                       rs->sr_err = LDAP_OTHER;
+                               "error %d in backsql_id2entry() "
+                               "- compare failed\n", rc, 0, 0 );
+                       rs->sr_err = rc;
                        goto return_results;
                }
        }
+       e = &user_entry;
 
        if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc, 
                                &op->oq_compare.rs_ava->aa_value,
@@ -152,17 +153,7 @@ return_results:;
        }
 
        if ( e != NULL ) {
-               if ( e->e_name.bv_val != NULL ) {
-                       free( e->e_name.bv_val );
-               }
-
-               if ( e->e_nname.bv_val != NULL ) {
-                       free( e->e_nname.bv_val );
-               }
-
-               if ( e->e_attrs != NULL ) {
-                       attrs_free( e->e_attrs );
-               }
+               entry_clean( e );
        }
 
        Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
index 051e4f12ad883b992a0fdf1091d6b7e4381155eb..747f8bf968e95ffcc22e963ee134821443f78b29 100644 (file)
@@ -396,8 +396,8 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
        return 1;
 }
 
-Entry *
-backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid )
+int
+backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid )
 {
        int                     i;
        int                     rc;
@@ -405,35 +405,44 @@ backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid )
 
        Debug( LDAP_DEBUG_TRACE, "==>backsql_id2entry()\n", 0, 0, 0 );
 
-       rc = dnPrettyNormal( NULL, &eid->eid_dn, &e->e_name, &e->e_nname,
+       assert( bsi->bsi_e );
+
+       memset( bsi->bsi_e, 0, sizeof( Entry ) );
+
+       rc = dnPrettyNormal( NULL, &eid->eid_dn,
+                       &bsi->bsi_e->e_name, &bsi->bsi_e->e_nname,
                        bsi->bsi_op->o_tmpmemctx );
        if ( rc != LDAP_SUCCESS ) {
-               return NULL;
+               return rc;
        }
 
+       bsi->bsi_e->e_attrs = NULL;
+       bsi->bsi_e->e_private = NULL;
+
        bsi->bsi_oc = backsql_id2oc( bsi->bsi_op->o_bd->be_private,
                        eid->eid_oc_id );
-       bsi->bsi_e = e;
        bsi->bsi_c_eid = eid;
-       e->e_attrs = NULL;
-       e->e_private = NULL;
 
 #ifndef BACKSQL_ARBITRARY_KEY  
-       e->e_id = eid->eid_id;
+       bsi->bsi_e->e_id = eid->eid_id;
 #endif /* ! BACKSQL_ARBITRARY_KEY */
  
+       rc = attr_merge_normalize_one( bsi->bsi_e, ad_oc,
+                               &bsi->bsi_oc->bom_oc->soc_cname,
+                               bsi->bsi_op->o_tmpmemctx );
+       if ( rc != LDAP_SUCCESS ) {
+               entry_clean( bsi->bsi_e );
+               return rc;
+       }
+
        if ( bsi->bsi_attrs != NULL ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
                        "custom attribute list\n", 0, 0, 0 );
                for ( i = 0; bsi->bsi_attrs[ i ].an_name.bv_val; i++ ) {
                        backsql_at_map_rec      **vat;
-                       AttributeName           *attr = &bsi->bsi_attrs[ i ];
+                       AttributeName           *an = &bsi->bsi_attrs[ i ];
                        int                     j;
 
-                       if ( attr->an_desc == ad_oc ) {
-                               continue;
-                       }
-
                        /* if one of the attributes listed here is
                         * a subtype of another, it must be ignored,
                         * because subtypes are already dealt with
@@ -446,18 +455,19 @@ backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid )
                                }
 
                                /* skip subtypes */
-                               if ( is_at_subtype( attr->an_desc->ad_type, bsi->bsi_attrs[ j ].an_desc->ad_type ) )
+                               if ( is_at_subtype( an->an_desc->ad_type,
+                                                       bsi->bsi_attrs[ j ].an_desc->ad_type ) )
                                {
                                        goto next;
                                }
                        }
 
-                       rc = backsql_supad2at( bsi->bsi_oc, attr->an_desc, &vat );
+                       rc = backsql_supad2at( bsi->bsi_oc, an->an_desc, &vat );
                        if ( rc != 0 || vat == NULL ) {
                                Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
                                                "attribute \"%s\" is not defined "
                                                "for objectlass \"%s\"\n",
-                                               attr->an_name.bv_val, 
+                                               an->an_name.bv_val, 
                                                BACKSQL_OC_NAME( bsi->bsi_oc ), 0 );
                                continue;
                        }
@@ -478,13 +488,6 @@ next:;
                                bsi, 0, AVL_INORDER );
        }
 
-       if ( attr_merge_normalize_one( bsi->bsi_e, ad_oc,
-                               &bsi->bsi_oc->bom_oc->soc_cname,
-                               bsi->bsi_op->o_tmpmemctx ) ) {
-               entry_free( e );
-               return NULL;
-       }
-
        if ( global_schemacheck ) {
                const char      *text = NULL;
                char            textbuf[ 1024 ];
@@ -499,8 +502,12 @@ next:;
                rc = structural_class( bv, &soc, NULL, 
                                &text, textbuf, textlen );
                if ( rc != LDAP_SUCCESS ) {
-                       entry_free( e );
-                       return NULL;
+                       Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(%s): "
+                               "structural_class() failed %d (%s)\n",
+                               bsi->bsi_e->e_name.bv_val,
+                               rc, text ? text : "" );
+                       entry_clean( bsi->bsi_e );
+                       return rc;
                }
 
                if ( ( bsi->bsi_flags | BSQL_SF_ALL_OPER )
@@ -509,15 +516,15 @@ next:;
                                        slap_schema.si_ad_structuralObjectClass,
                                        &soc, bsi->bsi_op->o_tmpmemctx );
                        if ( rc != LDAP_SUCCESS ) {
-                               entry_free( e );
-                               return NULL;
+                               entry_clean( bsi->bsi_e );
+                               return rc;
                        }
                }
        }
 
        Debug( LDAP_DEBUG_TRACE, "<==backsql_id2entry()\n", 0, 0, 0 );
 
-       return e;
+       return LDAP_SUCCESS;
 }
 
 #endif /* SLAPD_SQL */
index e57e9b4d4fe1ab1630d05d1de5d349b6019a4969..a239e7b5c59ad2ff075c540daf11b7ef0358a909 100644 (file)
@@ -115,8 +115,7 @@ int backsql_has_children( backsql_info *bi, SQLHDBC dbh, struct berval *dn );
 backsql_entryID *backsql_free_entryID( backsql_entryID *id, int freeit );
 
 /* turns an ID into an entry */
-Entry *backsql_id2entry( backsql_srch_info *bsi, Entry *e, 
-               backsql_entryID *id );
+int backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *id );
 
 /*
  * schema-map.c
index 4e5bb51e0f770fd486bf7da0e48e3fb20e83e502..b39df23abdc82485ecbe508e3087669b66939d69 100644 (file)
@@ -17,6 +17,7 @@ create table ldap_attr_mappings
        oc_map_id integer unsigned not null references ldap_oc_mappings(id),
        name varchar(255) not null,
        sel_expr varchar(255) not null,
+       sel_expr_u varchar(255),
        from_tbls varchar(255) not null,
        join_where varchar(255),
        add_proc varchar(255),
index f141f414eb0881a0cc33802d3ae5c786e5c37f44..f04d6dab164499614d4acd653ec950bb76f75954 100644 (file)
@@ -1,4 +1,4 @@
-insert into institutes (id,name) values (1,'sql');
+insert into institutes (id,name) values (1,'Example');
 
 insert into persons (id,name) values (1,'Mitya Kovalev');
 insert into persons (id,name) values (2,'Torvlobnor Puzdoy');
index f119abba799339eb6c4bdb184260d6741e5e6958..3cc3128787ca9f1c3a59e2fd84705eed265800e4 100644 (file)
@@ -53,8 +53,8 @@ insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,
 values (7,3,'o','institutes.name','institutes',NULL,NULL,NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons',
-        'ldap_entries.keyval=documents.id AND ldap_entries.oc_map_id=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id',
+values (8,1,'documentIdentifier','documentIdentifier.dn','ldap_entries AS documentIdentifier,documents,authors_docs,persons',
+        'documentIdentifier.keyval=documents.id AND documentIdentifier.oc_map_id=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id',
        NULL,NULL,3,0);
 
 -- entries mapping: each entry must appear in this table, with a unique DN rooted at the database naming context
@@ -64,22 +64,22 @@ values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,
 --     parent          the "ldap_entries.id" of the parent of this objectClass; 0 if it is the "suffix" of the database
 --     keyval          the value of the "keytbl.keycol" defined for this objectClass
 insert into ldap_entries (id,dn,oc_map_id,parent,keyval)
-values (1,'o=sql,c=RU',3,0,1);
+values (1,'o=Example,c=RU',3,0,1);
 
 insert into ldap_entries (id,dn,oc_map_id,parent,keyval)
-values (2,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1);
+values (2,'cn=Mitya Kovalev,o=Example,c=RU',1,1,1);
 
 insert into ldap_entries (id,dn,oc_map_id,parent,keyval)
-values (3,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2);
+values (3,'cn=Torvlobnor Puzdoy,o=Example,c=RU',1,1,2);
 
 insert into ldap_entries (id,dn,oc_map_id,parent,keyval)
-values (4,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3);
+values (4,'cn=Akakiy Zinberstein,o=Example,c=RU',1,1,3);
 
 insert into ldap_entries (id,dn,oc_map_id,parent,keyval)
-values (5,'documentTitle=book1,o=sql,c=RU',2,1,1);
+values (5,'documentTitle=book1,o=Example,c=RU',2,1,1);
 
 insert into ldap_entries (id,dn,oc_map_id,parent,keyval)
-values (6,'documentTitle=book2,o=sql,c=RU',2,1,2);
+values (6,'documentTitle=book2,o=Example,c=RU',2,1,2);
        
 
 -- objectClass mapping: entries that have multiple objectClass instances are listed here with the objectClass name (view them as auxiliary objectClass)
@@ -92,4 +92,5 @@ values (4,'referral');
 --     entry_id        the "ldap_entries.id" of the entry that should be treated as a referral
 --     url             the URI of the referral
 insert into ldap_referrals (entry_id,url)
-values (4,'http://localhost');
+values (4,'ldap://localhost/');
+
index ee01b8ddd1ded56ff3338ae1facf9086b6b3d503..69bd1c293ee268943bdc54da1f3bfb36cd39261f 100644 (file)
@@ -113,13 +113,14 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
 {
        backsql_at_map_rec      *at_map;
        char                    s[] = "+9223372036854775807L";
-       ber_len_t               slen;
+       struct berval           sbv;
        struct berbuf           bb;
        
-
+       sbv.bv_val = s;
        snprintf( s, sizeof( s ), "%ld", oc_map->bom_id );
-       slen = strlen( s );
+       sbv.bv_len = strlen( s );
 
+       /* extra objectClasses */
        at_map = (backsql_at_map_rec *)ch_calloc(1, 
                        sizeof( backsql_at_map_rec ) );
        at_map->bam_ad = slap_schema.si_ad_objectClass;
@@ -136,7 +137,7 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
        bb.bb_val.bv_val = NULL;
        bb.bb_val.bv_len = 0;
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "lbcbll",
+       backsql_strfcat( &bb, "lbcblb",
                        (ber_len_t)STRLENOF( "ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=" ),
                                "ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=",
                        &oc_map->bom_keytbl, 
@@ -144,7 +145,7 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
                        &oc_map->bom_keycol,
                        (ber_len_t)STRLENOF( " and ldap_entries.oc_map_id=" ), 
                                " and ldap_entries.oc_map_id=", 
-                       slen, s );
+                       &sbv );
 
        at_map->bam_oc = oc_map->bom_oc;
        at_map->bam_join_where = bb.bb_val;
@@ -162,22 +163,22 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
                                oc_map->bom_oc->soc_cname.bv_val, 0 );
        }
 
+       /* referral attribute */
        at_map = (backsql_at_map_rec *)ch_calloc( 1, 
                        sizeof( backsql_at_map_rec ) );
        at_map->bam_ad = slap_schema.si_ad_ref;
        ber_str2bv( "ldap_referrals.url", 0, 1, &at_map->bam_sel_expr );
        ber_str2bv( "ldap_referrals,ldap_entries", 0, 1, &at_map->bam_from_tbls );
-       
-       bb.bb_val.bv_val = NULL;
-       bb.bb_val.bv_len = 0;
+
        bb.bb_len = at_map->bam_from_tbls.bv_len + 1;
+       bb.bb_val = at_map->bam_from_tbls;
        backsql_merge_from_clause( &bb, &oc_map->bom_keytbl );
        at_map->bam_from_tbls = bb.bb_val;
 
        bb.bb_val.bv_val = NULL;
        bb.bb_val.bv_len = 0;
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "lbcbll",
+       backsql_strfcat( &bb, "lbcblb",
                        (ber_len_t)STRLENOF( "ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=" ),
                                "ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=",
                        &oc_map->bom_keytbl, 
@@ -185,7 +186,7 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
                        &oc_map->bom_keycol,
                        (ber_len_t)STRLENOF( " and ldap_entries.oc_map_id=" ), 
                                " and ldap_entries.oc_map_id=", 
-                       slen, s );
+                       &sbv );
 
        at_map->bam_oc = NULL;
        at_map->bam_join_where = bb.bb_val;
index a270e79ac1622264784ee76f34629728efabff8c..e14733b53b9cb1355c18e22cbe8090392cc4326b 100644 (file)
@@ -60,7 +60,7 @@ backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad )
                return 1;
        }
 
-       for ( ; bsi->bsi_attrs[ n_attrs ].an_name.bv_val; n_attrs++ ) {
+       for ( ; !BER_BVISNULL( &bsi->bsi_attrs[ n_attrs ].an_name ); n_attrs++ ) {
                an = &bsi->bsi_attrs[ n_attrs ];
                
                Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): "
@@ -86,8 +86,7 @@ backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad )
 
        an[ n_attrs ].an_name = ad->ad_cname;
        an[ n_attrs ].an_desc = ad;
-       an[ n_attrs + 1 ].an_name.bv_val = NULL;
-       an[ n_attrs + 1 ].an_name.bv_len = 0;
+       BER_BVZERO( &an[ n_attrs + 1 ].an_name );
 
        bsi->bsi_attrs = an;
        
@@ -129,10 +128,9 @@ backsql_init_search(
        } else {
                bsi->bsi_attrs = (AttributeName *)ch_calloc( 1, 
                                sizeof( AttributeName ) );
-               bsi->bsi_attrs[ 0 ].an_name.bv_val = NULL;
-               bsi->bsi_attrs[ 0 ].an_name.bv_len = 0;
+               BER_BVZERO( &bsi->bsi_attrs[ 0 ].an_name );
                
-               for ( p = attrs; p->an_name.bv_val; p++ ) {
+               for ( p = attrs; !BER_BVISNULL( &p->an_name ); p++ ) {
                        /*
                         * ignore "1.1"; handle "+"
                         */
@@ -152,17 +150,13 @@ backsql_init_search(
        bsi->bsi_id_list = NULL;
        bsi->bsi_n_candidates = 0;
        bsi->bsi_stoptime = stoptime;
-       bsi->bsi_sel.bb_val.bv_val = NULL;
-       bsi->bsi_sel.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_sel.bb_val );
        bsi->bsi_sel.bb_len = 0;
-       bsi->bsi_from.bb_val.bv_val = NULL;
-       bsi->bsi_from.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_from.bb_val );
        bsi->bsi_from.bb_len = 0;
-       bsi->bsi_join_where.bb_val.bv_val = NULL;
-       bsi->bsi_join_where.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_join_where.bb_val );
        bsi->bsi_join_where.bb_len = 0;
-       bsi->bsi_flt_where.bb_val.bv_val = NULL;
-       bsi->bsi_flt_where.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_flt_where.bb_val );
        bsi->bsi_flt_where.bb_len = 0;
        bsi->bsi_filter_oc = NULL;
 
@@ -251,7 +245,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                 * val LIKE '%1%2%3%4%'
                 */
 
-               bv.bv_len = 0;
+               BER_BVZERO( &bv );
                if ( f->f_sub_initial.bv_val ) {
                        bv.bv_len += f->f_sub_initial.bv_len;
                }
@@ -267,7 +261,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                bv.bv_val = ch_malloc( bv.bv_len + 1 );
 
                s = 0;
-               if ( f->f_sub_initial.bv_val ) {
+               if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
                        bv.bv_val[ s ] = f->f_sub_initial.bv_val[ 0 ];
                        for ( i = 1; i < f->f_sub_initial.bv_len; i++ ) {
                                bv.bv_val[ s + 2 * i - 1 ] = '%';
@@ -278,7 +272,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                }
 
                if ( f->f_sub_any != NULL ) {
-                       for ( a = 0; f->f_sub_any[ a ].bv_val != NULL; a++ ) {
+                       for ( a = 0; !BER_BVISNULL( &f->f_sub_any[ a ] ); a++ ) {
                                bv.bv_val[ s ] = f->f_sub_any[ a ].bv_val[ 0 ];
                                for ( i = 1; i < f->f_sub_any[ a ].bv_len; i++ ) {
                                        bv.bv_val[ s + 2 * i - 1 ] = '%';
@@ -289,7 +283,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                        }
                }
 
-               if ( f->f_sub_final.bv_val ) {
+               if ( !BER_BVISNULL( &f->f_sub_final ) ) {
                        bv.bv_val[ s ] = f->f_sub_final.bv_val[ 0 ];
                        for ( i = 1; i < f->f_sub_final.bv_len; i++ ) {
                                bv.bv_val[ s + 2 * i - 1 ] = '%';
@@ -338,7 +332,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                                (ber_len_t)STRLENOF( " LIKE '" ), " LIKE '" );
        }
  
-       if ( f->f_sub_initial.bv_val != NULL ) {
+       if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
                ber_len_t       start;
 
 #ifdef BACKSQL_TRACE
@@ -359,7 +353,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
        backsql_strfcat( &bsi->bsi_flt_where, "c", '%' );
 
        if ( f->f_sub_any != NULL ) {
-               for ( i = 0; f->f_sub_any[ i ].bv_val != NULL; i++ ) {
+               for ( i = 0; !BER_BVISNULL( &f->f_sub_any[ i ] ); i++ ) {
                        ber_len_t       start;
 
 #ifdef BACKSQL_TRACE
@@ -383,7 +377,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                }
        }
 
-       if ( f->f_sub_final.bv_val != NULL ) {
+       if ( !BER_BVISNULL( &f->f_sub_final ) ) {
                ber_len_t       start;
 
 #ifdef BACKSQL_TRACE
@@ -748,7 +742,7 @@ backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_r
         */
        backsql_attrlist_add( bsi, at->bam_ad );
 
-       if ( at->bam_join_where.bv_val != NULL 
+       if ( !BER_BVISNULL( &at->bam_join_where )
                        && strstr( bsi->bsi_join_where.bb_val.bv_val, at->bam_join_where.bv_val ) == NULL ) {
                backsql_strfcat( &bsi->bsi_join_where, "lb",
                                (ber_len_t)STRLENOF( " AND " ), " AND ",
@@ -912,21 +906,17 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
        int             rc;
 
        assert( query );
-       query->bv_val = NULL;
-       query->bv_len = 0;
+       BER_BVZERO( query );
 
        Debug( LDAP_DEBUG_TRACE, "==>backsql_srch_query()\n", 0, 0, 0 );
-       bsi->bsi_sel.bb_val.bv_val = NULL;
-       bsi->bsi_sel.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_sel.bb_val );
+       BER_BVZERO( &bsi->bsi_sel.bb_val );
        bsi->bsi_sel.bb_len = 0;
-       bsi->bsi_from.bb_val.bv_val = NULL;
-       bsi->bsi_from.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_from.bb_val );
        bsi->bsi_from.bb_len = 0;
-       bsi->bsi_join_where.bb_val.bv_val = NULL;
-       bsi->bsi_join_where.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_join_where.bb_val );
        bsi->bsi_join_where.bb_len = 0;
-       bsi->bsi_flt_where.bb_val.bv_val = NULL;
-       bsi->bsi_flt_where.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_flt_where.bb_val );
        bsi->bsi_flt_where.bb_len = 0;
 
        backsql_strfcat( &bsi->bsi_sel, "lbcbc",
@@ -937,7 +927,7 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                        &bsi->bsi_oc->bom_keycol, 
                        ',' );
 
-       if ( bi->strcast_func.bv_val ) {
+       if ( !BER_BVISNULL( &bi->strcast_func ) ) {
                backsql_strfcat( &bsi->bsi_sel, "blbl",
                                &bi->strcast_func, 
                                (ber_len_t)sizeof( "('" /* ') */ ) - 1,
@@ -1038,20 +1028,20 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                 * anything.  No need to issue the query
                 */
                free( query->bv_val );
-               query->bv_val = NULL;
+               BER_BVZERO( query );
        }
  
        free( bsi->bsi_sel.bb_val.bv_val );
-       bsi->bsi_sel.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_sel.bb_val );
        bsi->bsi_sel.bb_len = 0;
        free( bsi->bsi_from.bb_val.bv_val );
-       bsi->bsi_from.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_from.bb_val );
        bsi->bsi_from.bb_len = 0;
        free( bsi->bsi_join_where.bb_val.bv_val );
-       bsi->bsi_join_where.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_join_where.bb_val );
        bsi->bsi_join_where.bb_len = 0;
        free( bsi->bsi_flt_where.bb_val.bv_val );
-       bsi->bsi_flt_where.bb_val.bv_len = 0;
+       BER_BVZERO( &bsi->bsi_flt_where.bb_val );
        bsi->bsi_flt_where.bb_len = 0;
        
        Debug( LDAP_DEBUG_TRACE, "<==backsql_srch_query() returns %s\n",
@@ -1124,7 +1114,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                }
        }
 
-       if ( query.bv_val == NULL ) {
+       if ( BER_BVISNULL( &query ) ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
                        "could not construct query for objectclass \"%s\"\n",
                        oc->bom_oc->soc_cname.bv_val, 0, 0 );
@@ -1137,6 +1127,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
 
        rc = backsql_Prepare( bsi->bsi_dbh, &sth, query.bv_val, 0 );
        free( query.bv_val );
+       BER_BVZERO( &query );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
                        "error preparing query\n", 0, 0, 0 );
@@ -1358,7 +1349,7 @@ backsql_search( Operation *op, SlapReply *rs )
        backsql_info            *bi = (backsql_info *)op->o_bd->be_private;
        SQLHDBC                 dbh;
        int                     sres;
-       Entry                   *entry, *res;
+       Entry                   user_entry = { 0 };
        int                     manageDSAit;
        time_t                  stoptime = 0;
        backsql_srch_info       srch_info;
@@ -1448,8 +1439,11 @@ backsql_search( Operation *op, SlapReply *rs )
         * mentioned in attrs and filter), test it against full filter 
         * and then send to client
         */
-       for ( eid = srch_info.bsi_id_list; eid != NULL; 
-                       eid = backsql_free_entryID( eid, 1 ) ) {
+       for ( eid = srch_info.bsi_id_list;
+                       eid != NULL; 
+                       eid = backsql_free_entryID( eid, 1 ) )
+       {
+               int             rc;
                Attribute       *hasSubordinate = NULL,
                                *a = NULL;
 
@@ -1482,24 +1476,25 @@ backsql_search( Operation *op, SlapReply *rs )
                        eid->eid_id, eid->eid_oc_id, eid->eid_keyval );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
 
-               entry = (Entry *)ch_calloc( sizeof( Entry ), 1 );
-               res = backsql_id2entry( &srch_info, entry, eid );
-               if ( res == NULL ) {
+               srch_info.bsi_e = &user_entry;
+               rc = backsql_id2entry( &srch_info, eid );
+               if ( rc != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
-                               "error in backsql_id2entry() "
-                               "- skipping entry\n", 0, 0, 0 );
+                               "error %d in backsql_id2entry() "
+                               "- skipping\n", rc, 0, 0 );
                        continue;
                }
 
                if ( !manageDSAit &&
                                op->ors_scope != LDAP_SCOPE_BASE &&
                                op->ors_scope != BACKSQL_SCOPE_BASE_LIKE &&
-                               is_entry_referral( entry ) ) {
+                               is_entry_referral( &user_entry ) )
+               {
                        BerVarray refs;
                        struct berval matched_dn;
 
-                       ber_dupbv( &matched_dn, &entry->e_name );
-                       refs = get_entry_referrals( op, entry );
+                       ber_dupbv( &matched_dn, &user_entry.e_name );
+                       refs = get_entry_referrals( op, &user_entry );
                        if ( refs ) {
                                rs->sr_ref = referral_rewrite( refs,
                                                &matched_dn, &op->o_req_dn,
@@ -1529,16 +1524,14 @@ backsql_search( Operation *op, SlapReply *rs )
                 * filter_has_subordinates()
                 */
                if ( srch_info.bsi_flags & BSQL_SF_FILTER_HASSUBORDINATE ) {
-                       int             rc;
-
-                       rc = backsql_has_children( bi, dbh, &entry->e_nname );
+                       rc = backsql_has_children( bi, dbh, &user_entry.e_nname );
 
-                       switch( rc ) {
+                       switch ( rc ) {
                        case LDAP_COMPARE_TRUE:
                        case LDAP_COMPARE_FALSE:
                                hasSubordinate = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
                                if ( hasSubordinate != NULL ) {
-                                       for ( a = entry->e_attrs; 
+                                       for ( a = user_entry.e_attrs; 
                                                        a && a->a_next; 
                                                        a = a->a_next );
 
@@ -1561,7 +1554,7 @@ backsql_search( Operation *op, SlapReply *rs )
                        }
                }
 
-               if ( test_filter( op, entry, op->ors_filter )
+               if ( test_filter( op, &user_entry, op->ors_filter )
                                == LDAP_COMPARE_TRUE ) {
                        if ( hasSubordinate && !( srch_info.bsi_flags & BSQL_SF_ALL_OPER ) 
                                        && !ad_inlist( slap_schema.si_ad_hasSubordinates, op->ors_attrs ) ) {
@@ -1578,7 +1571,7 @@ backsql_search( Operation *op, SlapReply *rs )
                        {
                                rs->sr_attrs = op->ors_attrs;
                                rs->sr_operational_attrs = NULL;
-                               rs->sr_entry = entry;
+                               rs->sr_entry = &user_entry;
                                rs->sr_flags = REP_ENTRY_MODIFIABLE;
                                sres = send_search_entry( op, rs );
                                rs->sr_entry = NULL;
@@ -1603,7 +1596,7 @@ backsql_search( Operation *op, SlapReply *rs )
                                break;
                        }
                }
-               entry_free( entry );
+               entry_clean( &user_entry );
 
                if ( op->ors_slimit != SLAP_NO_LIMIT
                                && rs->sr_nentries >= op->ors_slimit )
@@ -1615,11 +1608,14 @@ backsql_search( Operation *op, SlapReply *rs )
        }
 
 end_of_search:;
+       /* in case we got here accidentally */
+       entry_clean( &user_entry );
 
        if ( rs->sr_nentries > 0 ) {
                rs->sr_ref = rs->sr_v2ref;
                rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS
                        : LDAP_REFERRAL;
+
        } else {
                rs->sr_err = srch_info.bsi_status;
        }
index 1bb975f434718a813527d06cf8ab905674e66845..4fb534ae26150606e08cfbc56c4f8a241f89b3ef 100644 (file)
@@ -110,7 +110,8 @@ backsql_strcat( struct berbuf *dest, ... )
 
 #ifdef BACKSQL_TRACE
                        Debug( LDAP_DEBUG_TRACE, "backsql_strcat(): "
-                               "new buflen=%d, dest=%p\n", dest->bb_len, dest, 0 );
+                               "new buflen=%d, dest=%p\n",
+                               dest->bb_len, dest, 0 );
 #endif /* BACKSQL_TRACE */
                }
                AC_MEMCPY( dest->bb_val.bv_val + cdlen, cstr, cslen + 1 );
@@ -120,7 +121,7 @@ backsql_strcat( struct berbuf *dest, ... )
 
 #ifdef BACKSQL_TRACE
        Debug( LDAP_DEBUG_TRACE, "<==backsql_strcat() (dest=\"%s\")\n", 
-                       dest, 0, 0 );
+                       dest->bb_val.bv_val, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
        dest->bb_val.bv_len = cdlen;
@@ -231,7 +232,7 @@ backsql_strfcat( struct berbuf *dest, const char *fmt, ... )
 
 #ifdef BACKSQL_TRACE
        Debug( LDAP_DEBUG_TRACE, "<==backsql_strfcat() (dest=\"%s\")\n", 
-                       dest, 0, 0 );
+                       dest->bb_val.bv_val, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
        dest->bb_val.bv_len = cdlen;
@@ -340,7 +341,8 @@ backsql_merge_from_clause(
 #ifdef BACKSQL_TRACE
        Debug( LDAP_DEBUG_TRACE, "==>backsql_merge_from_clause(): "
                "dest_from=\"%s\",src_from=\"%s\"\n",
-               dest_from ? dest_from->bb_val.bv_val : "<NULL>", src_from, 0 );
+               dest_from ? dest_from->bb_val.bv_val : "<NULL>",
+               src_from->bv_val, 0 );
 #endif /* BACKSQL_TRACE */
 
        srcc = ch_strdup( src_from->bv_val );