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;
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): "
"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): "
"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): "
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,
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): "
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): "
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[] = ",";
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 }"
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;
}
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;
}
}
+ /*
+ * 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
*/
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(): "
/* 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(): "
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,
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,
&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;
}
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";
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 );
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",
}
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 );
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 );
"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;
}
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 );
&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,",
}
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;
}
/* 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 )
{
}
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(): "