]> git.sur5r.net Git - openldap/commitdiff
make aliasing and aliasing quotes configurable
authorPierangelo Masarati <ando@openldap.org>
Thu, 9 Jun 2005 09:43:20 +0000 (09:43 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 9 Jun 2005 09:43:20 +0000 (09:43 +0000)
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/config.c
servers/slapd/back-sql/init.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/util.c

index 9945a615db3c7baed573a6ab2382cdf367430804..21c152e2b172f4f6700fbedc3a53ec3329eeaf38 100644 (file)
@@ -493,6 +493,10 @@ typedef struct backsql_info {
        BerVarray       sql_concat_func;
        struct berval   sql_strcast_func;
 
+       struct berval   sql_aliasing;
+       struct berval   sql_aliasing_quote;
+       struct berval   sql_dn_oc_aliasing;
+
        AttributeName   *sql_anlist;
 
        unsigned int    sql_flags;
index a333ae0419c8faa9f0be3f499bc9a61a3944a984..700f8cc1eef3e78b5502f93e0b282eed25c1c150 100644 (file)
@@ -321,7 +321,7 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -352,7 +352,7 @@ backsql_db_config(
                        "has_ldapinfo_dn_ru=%s\n", 
                        BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ? "yes" : "no", 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -381,7 +381,7 @@ backsql_db_config(
                        "fail_if_no_mapping=%s\n", 
                        BACKSQL_FAIL_IF_NO_MAPPING( bi ) ? "yes" : "no", 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "allow_orphans") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "allow_orphans" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -443,7 +443,7 @@ backsql_db_config(
                        return 1;
                }
 
-       } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "sqllayer" ) ) {
                if ( backsql_api_config( bi, argv[ 1 ], argc - 2, &argv[ 2 ] ) )
                {
                        Debug( LDAP_DEBUG_TRACE,
@@ -466,7 +466,7 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "id_query=%s\n", bi->sql_id_query, 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -496,7 +496,7 @@ backsql_db_config(
                        BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no",
                        0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -526,7 +526,7 @@ backsql_db_config(
                        BACKSQL_FETCH_ALL_ATTRS( bi ) ? "yes" : "no",
                        0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs" ) ) {
                char    *str, *s, *next;
                char    delimstr[] = ",";
 
@@ -561,8 +561,8 @@ backsql_db_config(
                        return -1;
                }
 
-       } else if ( !strcasecmp( argv[ 0 ], "check_schema") ) {
-               if ( argc < 2 ) {
+       } else if ( !strcasecmp( argv[ 0 ], "check_schema" ) ) {
+               if ( argc != 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
                                "missing { yes | no }"
@@ -591,6 +591,41 @@ backsql_db_config(
                        BACKSQL_CHECK_SCHEMA( bi ) ? "yes" : "no",
                        0, 0 );
 
+       } else if ( !strcasecmp( argv[ 0 ], "aliasing" ) ) {
+               if ( argc != 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing arg "
+                               "in \"aliasing <string>\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               if ( ! BER_BVISNULL( &bi->sql_aliasing ) ) {
+                       ch_free( bi->sql_aliasing.bv_val );
+               }
+
+               ber_str2bv( argv[ 1 ], strlen( argv[ 1 ] ) + 1, 1,
+                       &bi->sql_aliasing );
+               /* add a trailing space... */
+               bi->sql_aliasing.bv_val[ bi->sql_aliasing.bv_len - 1] = ' ';
+
+       } else if ( !strcasecmp( argv[ 0 ], "aliasing_quote" ) ) {
+               if ( argc != 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing arg "
+                               "in \"aliasing_quote <string>\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               if ( ! BER_BVISNULL( &bi->sql_aliasing_quote ) ) {
+                       ch_free( bi->sql_aliasing_quote.bv_val );
+               }
+
+               ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_aliasing_quote );
+
        } else {
                return SLAP_CONF_UNKNOWN;
        }
index cf0bebf73b95282f32b40d805184a295731892b3..e31d3b85eb470b856aa982199c2de1f741bdb367 100644 (file)
@@ -147,6 +147,9 @@ backsql_db_destroy(
        free( bi->sql_renentry_stmt );
        free( bi->sql_delobjclasses_stmt );
 
+       free( bi->sql_aliasing.bv_val );
+       free( bi->sql_aliasing_quote.bv_val );
+
        if ( bi->sql_anlist ) {
                int     i;
 
@@ -201,6 +204,21 @@ backsql_db_open(
                }
        }
 
+       /*
+        * see back-sql.h for default values
+        */
+       if ( BER_BVISNULL( &bi->sql_aliasing ) ) {
+               ber_str2bv( BACKSQL_ALIASING,
+                       STRLENOF( BACKSQL_ALIASING ),
+                       1, &bi->sql_aliasing );
+       }
+
+       if ( BER_BVISNULL( &bi->sql_aliasing_quote ) ) {
+               ber_str2bv( BACKSQL_ALIASING_QUOTE,
+                       STRLENOF( BACKSQL_ALIASING_QUOTE ),
+                       1, &bi->sql_aliasing_quote );
+       }
+
        /*
         * Prepare cast string as required
         */
@@ -445,21 +463,31 @@ backsql_db_open(
                bi->sql_id_query = bb.bb_val.bv_val;
        }
 
-               /*
+       /*
         * Prepare children ID selection query
         */
-       bi->sql_has_children_query = NULL;
-
-       bb.bb_val.bv_val = NULL;
-       bb.bb_val.bv_len = 0;
+       BER_BVZERO( &bb.bb_val );
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "sb",
+       backsql_strfcat( &bb, "sbsb",
                        "SELECT COUNT(distinct subordinates.id) "
-                       "FROM ldap_entries,ldap_entries " BACKSQL_ALIASING "subordinates "
+                       "FROM ldap_entries,ldap_entries ",
+                       &bi->sql_aliasing, "subordinates "
                        "WHERE subordinates.parent=ldap_entries.id AND ",
                        &bi->sql_children_cond );
        bi->sql_has_children_query = bb.bb_val.bv_val;
  
+       /*
+        * Prepare DN and objectClass aliasing bit of query
+        */
+       BER_BVZERO( &bb.bb_val );
+       bb.bb_len = 0;
+       backsql_strfcat( &bb, "sbbsbsbbsb",
+                       " ", &bi->sql_aliasing, &bi->sql_aliasing_quote,
+                       "objectClass", &bi->sql_aliasing_quote,
+                       ",ldap_entries.dn ", &bi->sql_aliasing,
+                       &bi->sql_aliasing_quote, "dn", &bi->sql_aliasing_quote );
+       bi->sql_dn_oc_aliasing = bb.bb_val;
        backsql_free_db_conn( op );
        if ( !BACKSQL_SCHEMA_LOADED( bi ) ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
@@ -475,6 +503,7 @@ backsql_db_open(
                /* enable if only one suffix is defined */
                bi->sql_flags |= BSQLF_USE_SUBTREE_SHORTCUT;
        }
+
        bi->sql_flags |= BSQLF_CHECK_SCHEMA;
        
        Debug( LDAP_DEBUG_TRACE, "<==backsql_db_open(): "
index 4cdc28d20273b246c495165e8b7ae6f6eddf658c..3a5bd3e2d968a9793223aa43d1b6d6aa8f1016ca 100644 (file)
@@ -242,7 +242,7 @@ struct berbuf * backsql_strfcat( struct berbuf *dest, const char *fmt, ... );
 int backsql_entry_addattr( Entry *e, AttributeDescription *ad, 
                struct berval *at_val, void *memctx );
 
-int backsql_merge_from_clause( struct berbuf *dest_from, 
+int backsql_merge_from_clause( backsql_info *bi, struct berbuf *dest_from, 
                struct berval *src_from );
 
 int backsql_split_pattern( const char *pattern, BerVarray *split_pattern,
index bf87251401a4aeba04aff4385d7866005996ad17..44698952f50864c746a4384c2ff87f38d8dac606 100644 (file)
@@ -100,19 +100,21 @@ backsql_dup_attr( void *v_m1, void *v_m2 )
 
 static int
 backsql_make_attr_query( 
+       backsql_info            *bi,
        backsql_oc_map_rec      *oc_map,
        backsql_at_map_rec      *at_map )
 {
        struct berbuf   bb = BB_NULL;
 
-       backsql_strfcat( &bb, "lblblblbcbl", 
+       backsql_strfcat( &bb, "lblbbbblblbcbl", 
                        (ber_len_t)STRLENOF( "SELECT " ), "SELECT ", 
                        &at_map->bam_sel_expr, 
-                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE ),
-                               " " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE, 
+                       (ber_len_t)STRLENOF( " " ), " ",
+                       &bi->sql_aliasing,
+                       &bi->sql_aliasing_quote, 
                        &at_map->bam_ad->ad_cname,
-                       (ber_len_t)STRLENOF( BACKSQL_ALIASING_QUOTE " FROM " ),
-                               BACKSQL_ALIASING_QUOTE " FROM ", 
+                       &bi->sql_aliasing_quote,
+                       (ber_len_t)STRLENOF( " FROM " ), " FROM ", 
                        &at_map->bam_from_tbls, 
                        (ber_len_t)STRLENOF( " WHERE " ), " WHERE ", 
                        &oc_map->bom_keytbl,
@@ -126,12 +128,11 @@ backsql_make_attr_query(
                                &at_map->bam_join_where );
        }
 
-       backsql_strfcat( &bb, "lbl", 
-                       (ber_len_t)STRLENOF( " ORDER BY " BACKSQL_ALIASING_QUOTE ),
-                               " ORDER BY " BACKSQL_ALIASING_QUOTE,
+       backsql_strfcat( &bb, "lbbb", 
+                       (ber_len_t)STRLENOF( " ORDER BY " ), " ORDER BY ",
+                       &bi->sql_aliasing_quote,
                        &at_map->bam_ad->ad_cname,
-                       (ber_len_t)STRLENOF( BACKSQL_ALIASING_QUOTE ),
-                               BACKSQL_ALIASING_QUOTE );
+                       &bi->sql_aliasing_quote );
 
        at_map->bam_query = bb.bb_val.bv_val;
 
@@ -162,7 +163,7 @@ backsql_make_attr_query(
 }
 
 static int
-backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
+backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
 {
        backsql_at_map_rec      *at_map;
        char                    s[] = "+9223372036854775807L";
@@ -183,7 +184,7 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
        
        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 );
+       backsql_merge_from_clause( bi, &bb, &oc_map->bom_keytbl );
        at_map->bam_from_tbls = bb.bb_val;
 
        BER_BVZERO( &bb.bb_val );
@@ -240,7 +241,7 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map )
        at_map->bam_expect_return = 0;
        at_map->bam_next = NULL;
 
-       backsql_make_attr_query( oc_map, at_map );
+       backsql_make_attr_query( bi, oc_map, at_map );
        if ( avl_insert( &oc_map->bom_attrs, at_map, backsql_cmp_attr, backsql_dup_attr ) == BACKSQL_DUPLICATE ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_add_sysmaps(): "
                                "duplicate attribute \"%s\" in objectClass \"%s\" map\n",
@@ -359,7 +360,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                }
 
                ber_str2bv( at_row.cols[ 2 ], 0, 0, &bv );
-               backsql_merge_from_clause( &bb, &bv );
+               backsql_merge_from_clause( bas->bas_bi, &bb, &bv );
                at_map->bam_from_tbls = bb.bb_val;
                if ( at_row.value_len[ 3 ] < 0 ) {
                        BER_BVZERO( &at_map->bam_join_where );
@@ -386,7 +387,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                if ( next == at_row.cols[ 7 ] || next[0] != '\0' ) {
                        /* error */
                }
-               backsql_make_attr_query( oc_map, at_map );
+               backsql_make_attr_query( bas->bas_bi, oc_map, at_map );
                Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_attr_mapping(): "
                        "preconstructed query \"%s\"\n",
                        at_map->bam_query, 0, 0 );
@@ -419,7 +420,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                "autoadding 'objectClass' and 'ref' mappings\n",
                BACKSQL_OC_NAME( oc_map ), 0, 0 );
 
-       (void)backsql_add_sysmaps( oc_map );
+       (void)backsql_add_sysmaps( bas->bas_bi, oc_map );
 
        return BACKSQL_AVL_CONTINUE;
 }
index 98f0041501becd6d7d1637172eb5cfddfbf8101b..aa084453859cb95e4145327b4f5c55d0f5dbf23e 100644 (file)
@@ -1247,8 +1247,8 @@ equality_match:;
 static int
 backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
 {
-       backsql_info    *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
-       int             rc;
+       backsql_info            *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
+       int                     rc;
 
        assert( query );
        BER_BVZERO( query );
@@ -1288,14 +1288,8 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                                &bsi->bsi_oc->bom_oc->soc_cname,
                                '\'' );
        }
-       backsql_strfcat( &bsi->bsi_sel, "l",
-                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING 
-                                       BACKSQL_ALIASING_QUOTE "objectClass" BACKSQL_ALIASING_QUOTE 
-                                       ",ldap_entries.dn " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE "dn" BACKSQL_ALIASING_QUOTE ),
-                               " " BACKSQL_ALIASING 
-                                       BACKSQL_ALIASING_QUOTE "objectClass" BACKSQL_ALIASING_QUOTE
-                                       ",ldap_entries.dn " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE "dn" BACKSQL_ALIASING_QUOTE );
 
+       backsql_strfcat( &bsi->bsi_sel, "b", &bi->sql_dn_oc_aliasing );
        backsql_strfcat( &bsi->bsi_from, "lb",
                        (ber_len_t)STRLENOF( " FROM ldap_entries," ),
                                " FROM ldap_entries,",
index ab4042e9264ca79e6a4bcf400ba32c9299f63b3c..c90823b73e96b4f577a530f0ed9d8052b6769661 100644 (file)
@@ -275,7 +275,7 @@ backsql_entry_addattr(
 }
 
 static char *
-backsql_get_table_spec( char **p )
+backsql_get_table_spec( backsql_info *bi, char **p )
 {
        char            *s, *q;
        struct berbuf   res = BB_NULL;
@@ -312,13 +312,19 @@ backsql_get_table_spec( char **p )
        }
 
        /* oracle doesn't understand "AS" :( and other RDBMSes don't need it */
-       backsql_strcat( &res, " " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE, s, BACKSQL_ALIASING_QUOTE, NULL );
+       backsql_strfcat( &res, "lbbsb",
+                       STRLENOF( " " ), " ",
+                       &bi->sql_aliasing,
+                       &bi->sql_aliasing_quote,
+                       s,
+                       &bi->sql_aliasing_quote );
 
        return res.bb_val.bv_val;
 }
 
 int
 backsql_merge_from_clause( 
+       backsql_info    *bi,
        struct berbuf   *dest_from,
        struct berval   *src_from )
 {
@@ -340,7 +346,7 @@ backsql_merge_from_clause(
        }
        
        while ( *p ) {
-               s = backsql_get_table_spec( &p );
+               s = backsql_get_table_spec( bi, &p );
 
 #ifdef BACKSQL_TRACE
                Debug( LDAP_DEBUG_TRACE, "backsql_merge_from_clause(): "