Back to index

openldap  2.4.31
Defines | Functions | Variables
proto-sql.h File Reference
#include "back-sql.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define backsql_BindParamStr(sth, par_ind, io, str, maxlen)
#define backsql_BindParamBerVal(sth, par_ind, io, bv)
#define backsql_BindParamInt(sth, par_ind, io, val)
#define backsql_BindParamNumID(sth, par_ind, io, val)
#define backsql_BindParamID(sth, par_ind, io, id)   backsql_BindParamNumID( (sth), (par_ind), (io), (id) )

Functions

int backsql_modify_delete_all_values (Operation *op, SlapReply *rs, SQLHDBC dbh, backsql_entryID *e_id, backsql_at_map_rec *at)
int backsql_modify_internal (Operation *op, SlapReply *rs, SQLHDBC dbh, backsql_oc_map_rec *oc, backsql_entryID *e_id, Modifications *modlist)
int backsql_api_config (backsql_info *bi, const char *name, int argc, char *argv[])
int backsql_api_destroy (backsql_info *bi)
int backsql_api_register (backsql_api *ba)
int backsql_api_dn2odbc (Operation *op, SlapReply *rs, struct berval *dn)
int backsql_api_odbc2dn (Operation *op, SlapReply *rs, struct berval *dn)
int backsql_dn2id (Operation *op, SlapReply *rs, SQLHDBC dbh, struct berval *ndn, backsql_entryID *id, int matched, int muck)
int backsql_count_children (Operation *op, SQLHDBC dbh, struct berval *dn, unsigned long *nchildren)
int backsql_has_children (Operation *op, SQLHDBC dbh, struct berval *dn)
backsql_entryIDbacksql_free_entryID (backsql_entryID *id, int freeit, void *ctx)
int backsql_id2entry (backsql_srch_info *bsi, backsql_entryID *id)
backsql_entryIDbacksql_entryID_dup (backsql_entryID *eid, void *ctx)
Attributebacksql_operational_entryUUID (backsql_info *bi, backsql_entryID *id)
Attributebacksql_operational_entryCSN (Operation *op)
int backsql_load_schema_map (backsql_info *si, SQLHDBC dbh)
backsql_oc_map_recbacksql_oc2oc (backsql_info *si, ObjectClass *oc)
backsql_oc_map_recbacksql_id2oc (backsql_info *si, unsigned long id)
backsql_oc_map_recbacksql_name2oc (backsql_info *si, struct berval *oc_name)
backsql_at_map_recbacksql_ad2at (backsql_oc_map_rec *objclass, AttributeDescription *ad)
int backsql_supad2at (backsql_oc_map_rec *objclass, AttributeDescription *supad, backsql_at_map_rec ***pret)
int backsql_destroy_schema_map (backsql_info *si)
int backsql_init_search (backsql_srch_info *bsi, struct berval *nbase, int scope, time_t stoptime, Filter *filter, SQLHDBC dbh, Operation *op, SlapReply *rs, AttributeName *attrs, unsigned flags)
void backsql_entry_clean (Operation *op, Entry *e)
RETCODE backsql_Prepare (SQLHDBC dbh, SQLHSTMT *sth, const char *query, int timeout)
RETCODE backsql_BindRowAsStrings_x (SQLHSTMT sth, BACKSQL_ROW_NTS *row, void *ctx)
RETCODE backsql_BindRowAsStrings (SQLHSTMT sth, BACKSQL_ROW_NTS *row)
RETCODE backsql_FreeRow_x (BACKSQL_ROW_NTS *row, void *ctx)
RETCODE backsql_FreeRow (BACKSQL_ROW_NTS *row)
void backsql_PrintErrors (SQLHENV henv, SQLHDBC hdbc, SQLHSTMT sth, int rc)
int backsql_conn_destroy (backsql_info *bi)
int backsql_init_db_env (backsql_info *si)
int backsql_free_db_env (backsql_info *si)
int backsql_get_db_conn (Operation *op, SQLHDBC *dbh)
int backsql_free_db_conn (Operation *op, SQLHDBC dbh)
struct berbufbacksql_strcat_x (struct berbuf *dest, void *memctx,...)
struct berbufbacksql_strfcat_x (struct berbuf *dest, void *memctx, const char *fmt,...)
int backsql_entry_addattr (Entry *e, AttributeDescription *ad, struct berval *at_val, void *memctx)
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, int expected)
int backsql_prepare_pattern (BerVarray split_pattern, BerVarray values, struct berval *res)
int backsql_entryUUID (backsql_info *bi, backsql_entryID *id, struct berval *entryUUID, void *memctx)
int backsql_entryUUID_decode (struct berval *entryUUID, unsigned long *oc_id, unsigned long *keyval)
int backsql_init_cf (BackendInfo *bi)

Variables

const char backsql_def_oc_query []
const char backsql_def_needs_select_oc_query []
const char backsql_def_at_query []
const char backsql_def_delentry_stmt []
const char backsql_def_renentry_stmt []
const char backsql_def_insentry_stmt []
const char backsql_def_delobjclasses_stmt []
const char backsql_def_subtree_cond []
const char backsql_def_upper_subtree_cond []
const char backsql_id_query []
const char backsql_def_concat_func []
const char backsql_check_dn_ru_query []
BI_init sql_back_initialize
BI_destroy backsql_destroy
BI_db_init backsql_db_init
BI_db_open backsql_db_open
BI_db_close backsql_db_close
BI_db_destroy backsql_db_destroy
BI_db_config backsql_db_config
BI_op_bind backsql_bind
BI_op_search backsql_search
BI_op_compare backsql_compare
BI_op_modify backsql_modify
BI_op_modrdn backsql_modrdn
BI_op_add backsql_add
BI_op_delete backsql_delete
BI_operational backsql_operational
BI_entry_get_rw backsql_entry_get
BI_entry_release_rw backsql_entry_release
BI_connection_destroy backsql_connection_destroy

Define Documentation

#define backsql_BindParamBerVal (   sth,
  par_ind,
  io,
  bv 
)
Value:
SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),              \
                     (io), SQL_C_CHAR, SQL_VARCHAR,                   \
                     (SQLULEN)(bv)->bv_len, 0,                 \
                     (SQLPOINTER)(bv)->bv_val,                 \
                     (SQLLEN)(bv)->bv_len, NULL )

Definition at line 195 of file proto-sql.h.

#define backsql_BindParamID (   sth,
  par_ind,
  io,
  id 
)    backsql_BindParamNumID( (sth), (par_ind), (io), (id) )

Definition at line 216 of file proto-sql.h.

#define backsql_BindParamInt (   sth,
  par_ind,
  io,
  val 
)
Value:
SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),              \
                     (io), SQL_C_ULONG, SQL_INTEGER,                  \
                     0, 0, (SQLPOINTER)(val), 0, (SQLLEN*)NULL )

Definition at line 202 of file proto-sql.h.

#define backsql_BindParamNumID (   sth,
  par_ind,
  io,
  val 
)
Value:
SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),              \
                     (io), BACKSQL_C_NUMID, SQL_INTEGER,              \
                     0, 0, (SQLPOINTER)(val), 0, (SQLLEN*)NULL )

Definition at line 207 of file proto-sql.h.

#define backsql_BindParamStr (   sth,
  par_ind,
  io,
  str,
  maxlen 
)
Value:
SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),              \
                     (io), SQL_C_CHAR, SQL_VARCHAR,                   \
                     (SQLULEN)(maxlen), 0, (SQLPOINTER)(str),  \
                     (SQLLEN)(maxlen), NULL )

Definition at line 189 of file proto-sql.h.


Function Documentation

Definition at line 849 of file schema-map.c.

{
       backsql_at_map_rec   tmp = { 0 }, *res;
 
#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>backsql_ad2at(): "
              "searching for attribute \"%s\" for objectclass \"%s\"\n",
              ad->ad_cname.bv_val, BACKSQL_OC_NAME( objclass ), 0 );
#endif /* BACKSQL_TRACE */

       tmp.bam_ad = ad;
       res = (backsql_at_map_rec *)avl_find( objclass->bom_attrs, &tmp,
                     backsql_cmp_attr );

#ifdef BACKSQL_TRACE
       if ( res != NULL ) {
              Debug( LDAP_DEBUG_TRACE, "<==backsql_ad2at(): "
                     "found name=\"%s\", sel_expr=\"%s\"\n",
                     res->bam_ad->ad_cname.bv_val,
                     res->bam_sel_expr.bv_val, 0 );
       } else {
              Debug( LDAP_DEBUG_TRACE, "<==backsql_ad2at(): "
                     "not found\n", 0, 0, 0 );
       }
#endif /* BACKSQL_TRACE */

       return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_api_config ( backsql_info bi,
const char *  name,
int  argc,
char *  argv[] 
)

Definition at line 34 of file api.c.

{
       backsql_api   *ba;

       assert( bi != NULL );
       assert( name != NULL );

       for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
              if ( strcasecmp( name, ba->ba_name ) == 0 ) {
                     backsql_api   *ba2;

                     ba2 = ch_malloc( sizeof( backsql_api ) );
                     *ba2 = *ba;

                     if ( ba2->ba_config ) {
                            if ( ( *ba2->ba_config )( ba2, argc, argv ) ) {
                                   ch_free( ba2 );
                                   return 1;
                            }
                            ba2->ba_argc = argc;
                            if ( argc ) {
                                   int i;
                                   ba2->ba_argv = ch_malloc( argc * sizeof(char *));
                                   for ( i=0; i<argc; i++ )
                                          ba2->ba_argv[i] = ch_strdup( argv[i] );
                            }
                     }
                     
                     ba2->ba_next = bi->sql_api;
                     bi->sql_api = ba2;
                     return 0;
              }
       }

       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 72 of file api.c.

{
       backsql_api   *ba;

       assert( bi != NULL );

       ba = bi->sql_api;

       if ( ba == NULL ) {
              return 0;
       }

       for ( ; ba; ba = ba->ba_next ) {
              if ( ba->ba_destroy ) {
                     (void)( *ba->ba_destroy )( ba );
              }
       }

       return 0;
}

Here is the call graph for this function:

int backsql_api_dn2odbc ( Operation op,
SlapReply rs,
struct berval dn 
)

Definition at line 120 of file api.c.

{
       backsql_info  *bi = (backsql_info *)op->o_bd->be_private;
       backsql_api   *ba;
       int           rc;
       struct berval bv;

       ba = bi->sql_api;

       if ( ba == NULL ) {
              return 0;
       }

       ber_dupbv( &bv, dn );

       for ( ; ba; ba = ba->ba_next ) {
              if ( ba->ba_dn2odbc ) {
                     /*
                      * The dn2odbc() helper is supposed to rewrite
                      * the contents of bv, freeing the original value
                      * with ch_free() if required and replacing it 
                      * with a newly allocated one using ch_malloc() 
                      * or companion functions.
                      *
                      * NOTE: it is supposed to __always__ free
                      * the value of bv in case of error, and reset
                      * it with BER_BVZERO() .
                      */
                     rc = ( *ba->ba_dn2odbc )( op, rs, &bv );

                     if ( rc ) {
                            /* in case of error, dn2odbc() must cleanup */
                            assert( BER_BVISNULL( &bv ) );

                            return rc;
                     }
              }
       }

       assert( !BER_BVISNULL( &bv ) );

       *dn = bv;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_api_odbc2dn ( Operation op,
SlapReply rs,
struct berval dn 
)

Definition at line 167 of file api.c.

{
       backsql_info  *bi = (backsql_info *)op->o_bd->be_private;
       backsql_api   *ba;
       int           rc;
       struct berval bv;

       ba = bi->sql_api;

       if ( ba == NULL ) {
              return 0;
       }

       ber_dupbv( &bv, dn );

       for ( ; ba; ba = ba->ba_next ) {
              if ( ba->ba_dn2odbc ) {
                     rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
                     /*
                      * The odbc2dn() helper is supposed to rewrite
                      * the contents of bv, freeing the original value
                      * with ch_free() if required and replacing it 
                      * with a newly allocated one using ch_malloc() 
                      * or companion functions.
                      *
                      * NOTE: it is supposed to __always__ free
                      * the value of bv in case of error, and reset
                      * it with BER_BVZERO() .
                      */
                     if ( rc ) {
                            /* in case of error, odbc2dn() must cleanup */
                            assert( BER_BVISNULL( &bv ) );

                            return rc;
                     }
              }
       }

       assert( !BER_BVISNULL( &bv ) );

       *dn = bv;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 94 of file api.c.

{
       backsql_api   *ba2;

       assert( ba != NULL );
       assert( ba->ba_private == NULL );

       if ( ba->ba_name == NULL ) {
              fprintf( stderr, "API module has no name\n" );
              exit(EXIT_FAILURE);
       }

       for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
              if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
                     fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
                     exit( EXIT_FAILURE );
              }
       }

       ba->ba_next = backsqlapi;
       backsqlapi = ba;

       return 0;
}

Here is the call graph for this function:

RETCODE backsql_BindRowAsStrings ( SQLHSTMT  sth,
BACKSQL_ROW_NTS row 
)

Definition at line 280 of file sql-wrap.c.

{
       return backsql_BindRowAsStrings_x( sth, row, NULL );
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETCODE backsql_BindRowAsStrings_x ( SQLHSTMT  sth,
BACKSQL_ROW_NTS row,
void ctx 
)

Definition at line 127 of file sql-wrap.c.

{
       RETCODE              rc;

       if ( row == NULL ) {
              return SQL_ERROR;
       }

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==> backsql_BindRowAsStrings()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */
       
       rc = SQLNumResultCols( sth, &row->ncols );
       if ( rc != SQL_SUCCESS ) {
#ifdef BACKSQL_TRACE
              Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings(): "
                     "SQLNumResultCols() failed:\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */
              
              backsql_PrintErrors( SQL_NULL_HENV, SQL_NULL_HDBC, sth, rc );

       } else {
              SQLCHAR              colname[ 64 ];
              SQLSMALLINT   name_len, col_type, col_scale, col_null;
              SQLLEN        col_prec;
              int           i;

#ifdef BACKSQL_TRACE
              Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: "
                     "ncols=%d\n", (int)row->ncols, 0, 0 );
#endif /* BACKSQL_TRACE */

              row->col_names = (BerVarray)ber_memcalloc_x( row->ncols + 1, 
                            sizeof( struct berval ), ctx );
              if ( row->col_names == NULL ) {
                     goto nomem;
              }

              row->col_prec = (UDWORD *)ber_memcalloc_x( row->ncols,
                            sizeof( UDWORD ), ctx );
              if ( row->col_prec == NULL ) {
                     goto nomem;
              }

              row->col_type = (SQLSMALLINT *)ber_memcalloc_x( row->ncols,
                            sizeof( SQLSMALLINT ), ctx );
              if ( row->col_type == NULL ) {
                     goto nomem;
              }

              row->cols = (char **)ber_memcalloc_x( row->ncols + 1, 
                            sizeof( char * ), ctx );
              if ( row->cols == NULL ) {
                     goto nomem;
              }

              row->value_len = (SQLLEN *)ber_memcalloc_x( row->ncols,
                            sizeof( SQLLEN ), ctx );
              if ( row->value_len == NULL ) {
                     goto nomem;
              }

              if ( 0 ) {
nomem:
                     ber_memfree_x( row->col_names, ctx );
                     row->col_names = NULL;
                     ber_memfree_x( row->col_prec, ctx );
                     row->col_prec = NULL;
                     ber_memfree_x( row->col_type, ctx );
                     row->col_type = NULL;
                     ber_memfree_x( row->cols, ctx );
                     row->cols = NULL;
                     ber_memfree_x( row->value_len, ctx );
                     row->value_len = NULL;

                     Debug( LDAP_DEBUG_ANY, "backsql_BindRowAsStrings: "
                            "out of memory\n", 0, 0, 0 );

                     return LDAP_NO_MEMORY;
              }

              for ( i = 0; i < row->ncols; i++ ) {
                     SQLSMALLINT   TargetType;

                     rc = SQLDescribeCol( sth, (SQLSMALLINT)(i + 1), &colname[ 0 ],
                                   (SQLUINTEGER)( sizeof( colname ) - 1 ),
                                   &name_len, &col_type,
                                   &col_prec, &col_scale, &col_null );
                     /* FIXME: test rc? */

                     ber_str2bv_x( (char *)colname, 0, 1,
                                   &row->col_names[ i ], ctx );
#ifdef BACKSQL_TRACE
                     Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: "
                            "col_name=%s, col_prec[%d]=%d\n",
                            colname, (int)(i + 1), (int)col_prec );
#endif /* BACKSQL_TRACE */
                     if ( col_type != SQL_CHAR && col_type != SQL_VARCHAR )
                     {
                            col_prec = MAX_ATTR_LEN;
                     }

                     row->cols[ i ] = (char *)ber_memcalloc_x( col_prec + 1,
                                   sizeof( char ), ctx );
                     row->col_prec[ i ] = col_prec;
                     row->col_type[ i ] = col_type;

                     /*
                      * ITS#3386, ITS#3113 - 20070308
                      * Note: there are many differences between various DPMS and ODBC
                      * Systems; some support SQL_C_BLOB, SQL_C_BLOB_LOCATOR.  YMMV:
                      * This has only been tested on Linux/MySQL/UnixODBC
                      * For BINARY-type Fields (BLOB, etc), read the data as BINARY
                      */
                     if ( BACKSQL_IS_BINARY( col_type ) ) {
#ifdef BACKSQL_TRACE
                            Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: "
                                   "col_name=%s, col_type[%d]=%d: reading binary data\n",
                                   colname, (int)(i + 1), (int)col_type);
#endif /* BACKSQL_TRACE */
                            TargetType = SQL_C_BINARY;

                     } else {
                            /* Otherwise read it as Character data */
#ifdef BACKSQL_TRACE
                            Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: "
                                   "col_name=%s, col_type[%d]=%d: reading character data\n",
                                   colname, (int)(i + 1), (int)col_type);
#endif /* BACKSQL_TRACE */
                            TargetType = SQL_C_CHAR;
                     }

                     rc = SQLBindCol( sth, (SQLUSMALLINT)(i + 1),
                             TargetType,
                             (SQLPOINTER)row->cols[ i ],
                             col_prec + 1,
                             &row->value_len[ i ] );

                     /* FIXME: test rc? */
              }

              BER_BVZERO( &row->col_names[ i ] );
              row->cols[ i ] = NULL;
       }

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "<== backsql_BindRowAsStrings()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 334 of file sql-wrap.c.

{
       return 0;
}

Here is the caller graph for this function:

int backsql_count_children ( Operation op,
SQLHDBC  dbh,
struct berval dn,
unsigned long *  nchildren 
)

Definition at line 385 of file entry-id.c.

{
       backsql_info         *bi = (backsql_info *)op->o_bd->be_private;
       SQLHSTMT             sth = SQL_NULL_HSTMT;
       BACKSQL_ROW_NTS             row;
       RETCODE              rc;
       int                  res = LDAP_SUCCESS;

       Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn=\"%s\"\n", 
                     dn->bv_val, 0, 0 );

       if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
              Debug( LDAP_DEBUG_TRACE, 
                     "backsql_count_children(): DN \"%s\" (%ld bytes) "
                     "exceeds max DN length (%d):\n",
                     dn->bv_val, dn->bv_len, BACKSQL_MAX_DN_LEN );
              return LDAP_OTHER;
       }
       
       /* begin TimesTen */
       assert( bi->sql_has_children_query != NULL );
       Debug(LDAP_DEBUG_TRACE, "children id query \"%s\"\n", 
                     bi->sql_has_children_query, 0, 0);
       rc = backsql_Prepare( dbh, &sth, bi->sql_has_children_query, 0 );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, 
                     "backsql_count_children(): error preparing SQL:\n%s", 
                     bi->sql_has_children_query, 0, 0);
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              SQLFreeStmt( sth, SQL_DROP );
              return LDAP_OTHER;
       }

       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, dn );
       if ( rc != SQL_SUCCESS) {
              /* end TimesTen */ 
              Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
                     "error binding dn=\"%s\" parameter:\n", 
                     dn->bv_val, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              SQLFreeStmt( sth, SQL_DROP );
              return LDAP_OTHER;
       }

       rc = SQLExecute( sth );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
                     "error executing query (\"%s\", \"%s\"):\n", 
                     bi->sql_has_children_query, dn->bv_val, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              SQLFreeStmt( sth, SQL_DROP );
              return LDAP_OTHER;
       }

       backsql_BindRowAsStrings_x( sth, &row, op->o_tmpmemctx );
       
       rc = SQLFetch( sth );
       if ( BACKSQL_SUCCESS( rc ) ) {
              char *end;

              *nchildren = strtol( row.cols[ 0 ], &end, 0 );
              if ( end == row.cols[ 0 ] ) {
                     res = LDAP_OTHER;

              } else {
                     switch ( end[ 0 ] ) {
                     case '\0':
                            break;

                     case '.': {
                            unsigned long ul;

                            /* FIXME: braindead RDBMSes return
                             * a fractional number from COUNT!
                             */
                            if ( lutil_atoul( &ul, end + 1 ) != 0 || ul != 0 ) {
                                   res = LDAP_OTHER;
                            }
                            } break;

                     default:
                            res = LDAP_OTHER;
                     }
              }

       } else {
              res = LDAP_OTHER;
       }
       backsql_FreeRow_x( &row, op->o_tmpmemctx );

       SQLFreeStmt( sth, SQL_DROP );

       Debug( LDAP_DEBUG_TRACE, "<==backsql_count_children(): %lu\n",
                     *nchildren, 0, 0 );

       return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1028 of file schema-map.c.

{
       Debug( LDAP_DEBUG_TRACE, "==>destroy_schema_map()\n", 0, 0, 0 );
       avl_free( bi->sql_oc_by_oc, 0 );
       avl_free( bi->sql_oc_by_id, backsql_free_oc );
       Debug( LDAP_DEBUG_TRACE, "<==destroy_schema_map()\n", 0, 0, 0 );
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_dn2id ( Operation op,
SlapReply rs,
SQLHDBC  dbh,
struct berval ndn,
backsql_entryID id,
int  matched,
int  muck 
)

Definition at line 111 of file entry-id.c.

{
       backsql_info         *bi = op->o_bd->be_private;
       SQLHSTMT             sth = SQL_NULL_HSTMT; 
       BACKSQL_ROW_NTS             row = { 0 };
       RETCODE              rc;
       int                  res;
       struct berval        realndn = BER_BVNULL;

       /* TimesTen */
       char                 upperdn[ BACKSQL_MAX_DN_LEN + 1 ];
       struct berval        tbbDN;
       int                  i, j;

       /*
        * NOTE: id can be NULL; in this case, the function
        * simply checks whether the DN can be successfully 
        * turned into an ID, returning LDAP_SUCCESS for
        * positive cases, or the most appropriate error
        */

       Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(\"%s\")%s%s\n", 
                     ndn->bv_val, id == NULL ? " (no ID expected)" : "",
                     matched ? " matched expected" : "" );

       if ( id ) {
              /* NOTE: trap inconsistencies */
              assert( BER_BVISNULL( &id->eid_ndn ) );
       }

       if ( ndn->bv_len > BACKSQL_MAX_DN_LEN ) {
              Debug( LDAP_DEBUG_TRACE, 
                     "   backsql_dn2id(\"%s\"): DN length=%ld "
                     "exceeds max DN length %d:\n",
                     ndn->bv_val, ndn->bv_len, BACKSQL_MAX_DN_LEN );
              return LDAP_OTHER;
       }

       /* return baseObject if available and matches */
       /* FIXME: if ndn is already mucked, we cannot check this */
       if ( bi->sql_baseObject != NULL &&
                     dn_match( ndn, &bi->sql_baseObject->e_nname ) )
       {
              if ( id != NULL ) {
#ifdef BACKSQL_ARBITRARY_KEY
                     ber_dupbv_x( &id->eid_id, &backsql_baseObject_bv,
                                   op->o_tmpmemctx );
                     ber_dupbv_x( &id->eid_keyval, &backsql_baseObject_bv,
                                   op->o_tmpmemctx );
#else /* ! BACKSQL_ARBITRARY_KEY */
                     id->eid_id = BACKSQL_BASEOBJECT_ID;
                     id->eid_keyval = BACKSQL_BASEOBJECT_KEYVAL;
#endif /* ! BACKSQL_ARBITRARY_KEY */
                     id->eid_oc_id = BACKSQL_BASEOBJECT_OC;

                     ber_dupbv_x( &id->eid_ndn, &bi->sql_baseObject->e_nname,
                                   op->o_tmpmemctx );
                     ber_dupbv_x( &id->eid_dn, &bi->sql_baseObject->e_name,
                                   op->o_tmpmemctx );

                     id->eid_next = NULL;
              }

              return LDAP_SUCCESS;
       }
       
       /* begin TimesTen */
       assert( bi->sql_id_query != NULL );
       Debug( LDAP_DEBUG_TRACE, "   backsql_dn2id(\"%s\"): id_query \"%s\"\n",
                     ndn->bv_val, bi->sql_id_query, 0 );
       rc = backsql_Prepare( dbh, &sth, bi->sql_id_query, 0 );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, 
                     "   backsql_dn2id(\"%s\"): "
                     "error preparing SQL:\n   %s", 
                     ndn->bv_val, bi->sql_id_query, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              res = LDAP_OTHER;
              goto done;
       }

       realndn = *ndn;
       if ( muck ) {
              if ( backsql_api_dn2odbc( op, rs, &realndn ) ) {
                     Debug( LDAP_DEBUG_TRACE, "   backsql_dn2id(\"%s\"): "
                            "backsql_api_dn2odbc(\"%s\") failed\n", 
                            ndn->bv_val, realndn.bv_val, 0 );
                     res = LDAP_OTHER;
                     goto done;
              }
       }

       if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) {
              /*
               * Prepare an upper cased, byte reversed version 
               * that can be searched using indexes
               */

              for ( i = 0, j = realndn.bv_len - 1; realndn.bv_val[ i ]; i++, j--)
              {
                     upperdn[ i ] = realndn.bv_val[ j ];
              }
              upperdn[ i ] = '\0';
              ldap_pvt_str2upper( upperdn );

              Debug( LDAP_DEBUG_TRACE, "   backsql_dn2id(\"%s\"): "
                            "upperdn=\"%s\"\n",
                            ndn->bv_val, upperdn, 0 );
              ber_str2bv( upperdn, 0, 0, &tbbDN );

       } else {
              if ( BACKSQL_USE_REVERSE_DN( bi ) ) {
                     AC_MEMCPY( upperdn, realndn.bv_val, realndn.bv_len + 1 );
                     ldap_pvt_str2upper( upperdn );
                     Debug( LDAP_DEBUG_TRACE,
                            "   backsql_dn2id(\"%s\"): "
                            "upperdn=\"%s\"\n",
                            ndn->bv_val, upperdn, 0 );
                     ber_str2bv( upperdn, 0, 0, &tbbDN );

              } else {
                     tbbDN = realndn;
              }
       }

       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &tbbDN );
       if ( rc != SQL_SUCCESS) {
              /* end TimesTen */ 
              Debug( LDAP_DEBUG_TRACE, "   backsql_dn2id(\"%s\"): "
                     "error binding dn=\"%s\" parameter:\n", 
                     ndn->bv_val, tbbDN.bv_val, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              res = LDAP_OTHER;
              goto done;
       }

       rc = SQLExecute( sth );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "   backsql_dn2id(\"%s\"): "
                     "error executing query (\"%s\", \"%s\"):\n", 
                     ndn->bv_val, bi->sql_id_query, tbbDN.bv_val );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              res = LDAP_OTHER;
              goto done;
       }

       backsql_BindRowAsStrings_x( sth, &row, op->o_tmpmemctx );
       rc = SQLFetch( sth );
       if ( BACKSQL_SUCCESS( rc ) ) {
              char   buf[ SLAP_TEXT_BUFLEN ];

#ifdef LDAP_DEBUG
              snprintf( buf, sizeof(buf),
                     "id=%s keyval=%s oc_id=%s dn=%s",
                     row.cols[ 0 ], row.cols[ 1 ],
                     row.cols[ 2 ], row.cols[ 3 ] );
              Debug( LDAP_DEBUG_TRACE,
                     "   backsql_dn2id(\"%s\"): %s\n",
                     ndn->bv_val, buf, 0 );
#endif /* LDAP_DEBUG */

              res = LDAP_SUCCESS;
              if ( id != NULL ) {
                     struct berval dn;

                     id->eid_next = NULL;

#ifdef BACKSQL_ARBITRARY_KEY
                     ber_str2bv_x( row.cols[ 0 ], 0, 1, &id->eid_id,
                                   op->o_tmpmemctx );
                     ber_str2bv_x( row.cols[ 1 ], 0, 1, &id->eid_keyval,
                                   op->o_tmpmemctx );
#else /* ! BACKSQL_ARBITRARY_KEY */
                     if ( BACKSQL_STR2ID( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
                            res = LDAP_OTHER;
                            goto done;
                     }
                     if ( BACKSQL_STR2ID( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
                            res = LDAP_OTHER;
                            goto done;
                     }
#endif /* ! BACKSQL_ARBITRARY_KEY */
                     if ( BACKSQL_STR2ID( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) {
                            res = LDAP_OTHER;
                            goto done;
                     }

                     ber_str2bv( row.cols[ 3 ], 0, 0, &dn );

                     if ( backsql_api_odbc2dn( op, rs, &dn ) ) {
                            res = LDAP_OTHER;
                            goto done;
                     }
                     
                     res = dnPrettyNormal( NULL, &dn,
                                   &id->eid_dn, &id->eid_ndn,
                                   op->o_tmpmemctx );
                     if ( res != LDAP_SUCCESS ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_dn2id(\"%s\"): "
                                   "dnPrettyNormal failed (%d: %s)\n",
                                   realndn.bv_val, res,
                                   ldap_err2string( res ) );

                            /* cleanup... */
                            (void)backsql_free_entryID( id, 0, op->o_tmpmemctx );
                     }

                     if ( dn.bv_val != row.cols[ 3 ] ) {
                            free( dn.bv_val );
                     }
              }

       } else {
              res = LDAP_NO_SUCH_OBJECT;
              if ( matched ) {
                     struct berval pdn = *ndn;

                     /*
                      * Look for matched
                      */
                     rs->sr_matched = NULL;
                     while ( !be_issuffix( op->o_bd, &pdn ) ) {
                            char          *matchedDN = NULL;
       
                            dnParent( &pdn, &pdn );
       
                            /*
                             * Empty DN ("") defaults to LDAP_SUCCESS
                             */
                            rs->sr_err = backsql_dn2id( op, rs, dbh, &pdn, id, 0, 1 );
                            switch ( rs->sr_err ) {
                            case LDAP_NO_SUCH_OBJECT:
                                   /* try another one */
                                   break;
                                   
                            case LDAP_SUCCESS:
                                   matchedDN = pdn.bv_val;
                                   /* fail over to next case */
       
                            default:
                                   rs->sr_err = LDAP_NO_SUCH_OBJECT;
                                   rs->sr_matched = matchedDN;
                                   goto done;
                            } 
                     }
              }
       }

done:;
       backsql_FreeRow_x( &row, op->o_tmpmemctx );

       Debug( LDAP_DEBUG_TRACE,
              "<==backsql_dn2id(\"%s\"): err=%d\n",
              ndn->bv_val, res, 0 );
       if ( sth != SQL_NULL_HSTMT ) {
              SQLFreeStmt( sth, SQL_DROP );
       }

       if ( !BER_BVISNULL( &realndn ) && realndn.bv_val != ndn->bv_val ) {
              ch_free( realndn.bv_val );
       }

       return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_entry_addattr ( Entry e,
AttributeDescription ad,
struct berval at_val,
void memctx 
)

Definition at line 245 of file util.c.

{
       int                  rc;

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(\"%s\"): %s=%s\n", 
              e->e_name.bv_val, ad->ad_cname.bv_val, val->bv_val );
#endif /* BACKSQL_TRACE */

       rc = attr_merge_normalize_one( e, ad, val, memctx );

       if ( rc != LDAP_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(\"%s\"): "
                     "failed to merge value \"%s\" for attribute \"%s\"\n",
                     e->e_name.bv_val, val->bv_val, ad->ad_cname.bv_val );
              return rc;
       }

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "<==backsql_entry_addattr(\"%s\")\n",
              e->e_name.bv_val, 0, 0 );
#endif /* BACKSQL_TRACE */

       return LDAP_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void backsql_entry_clean ( Operation op,
Entry e 
)

Definition at line 2651 of file search.c.

{
       void *ctx;

       ctx = ldap_pvt_thread_pool_context();

       if ( ctx == NULL || ctx != op->o_tmpmemctx ) {
              if ( !BER_BVISNULL( &e->e_name ) ) {
                     op->o_tmpfree( e->e_name.bv_val, op->o_tmpmemctx );
                     BER_BVZERO( &e->e_name );
              }

              if ( !BER_BVISNULL( &e->e_nname ) ) {
                     op->o_tmpfree( e->e_nname.bv_val, op->o_tmpmemctx );
                     BER_BVZERO( &e->e_nname );
              }
       }

       entry_clean( e );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 39 of file entry-id.c.

{
       backsql_entryID      *dst;

       if ( src == NULL ) return NULL;

       dst = slap_sl_calloc( 1, sizeof( backsql_entryID ), ctx );
       ber_dupbv_x( &dst->eid_ndn, &src->eid_ndn, ctx );
       if ( src->eid_dn.bv_val == src->eid_ndn.bv_val ) {
              dst->eid_dn = dst->eid_ndn;
       } else {
              ber_dupbv_x( &dst->eid_dn, &src->eid_dn, ctx );
       }

#ifdef BACKSQL_ARBITRARY_KEY
       ber_dupbv_x( &dst->eid_id, &src->eid_id, ctx );
       ber_dupbv_x( &dst->eid_keyval, &src->eid_keyval, ctx );
#else /* ! BACKSQL_ARBITRARY_KEY */
       dst->eid_id = src->eid_id;
       dst->eid_keyval = src->eid_keyval;
#endif /* ! BACKSQL_ARBITRARY_KEY */

       dst->eid_oc = src->eid_oc;
       dst->eid_oc_id = src->eid_oc_id;

       return dst;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_entryUUID ( backsql_info bi,
backsql_entryID id,
struct berval entryUUID,
void memctx 
)

Definition at line 482 of file util.c.

{
       char          uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
       struct berval uuid;
#ifdef BACKSQL_ARBITRARY_KEY
       int           i;
       ber_len_t     l, lmax;
#endif /* BACKSQL_ARBITRARY_KEY */

       /* entryUUID is generated as "%08x-%04x-%04x-0000-eaddrXXX"
        * with eid_oc_id as %08x and hi and lo eid_id as %04x-%04x */
       assert( bi != NULL );
       assert( id != NULL );
       assert( entryUUID != NULL );

#ifdef BACKSQL_ARBITRARY_KEY
       snprintf( uuidbuf, sizeof( uuidbuf ),
                     "%08x-0000-0000-0000-000000000000",
                     ( id->eid_oc_id & 0xFFFFFFFF ) );
       lmax = id->eid_keyval.bv_len < 12 ? id->eid_keyval.bv_len : 12;
       for ( l = 0, i = 9; l < lmax; l++, i += 2 ) {
              switch ( i ) {
              case STRLENOF( "00000000-0000" ):
              case STRLENOF( "00000000-0000-0000" ):
              case STRLENOF( "00000000-0000-0000-0000" ):
                     uuidbuf[ i++ ] = '-';
              /* FALLTHRU */

              default:
                     snprintf( &uuidbuf[ i ], 3, "%2x", id->eid_keyval.bv_val[ l ] );
                     break;
              }
       }
#else /* ! BACKSQL_ARBITRARY_KEY */
       /* note: works only with 32 bit architectures... */
       snprintf( uuidbuf, sizeof( uuidbuf ),
                     "%08x-%04x-%04x-0000-000000000000",
                     ( (unsigned)id->eid_oc_id & 0xFFFFFFFF ),
                     ( ( (unsigned)id->eid_keyval & 0xFFFF0000 ) >> 020 /* 16 */ ),
                     ( (unsigned)id->eid_keyval & 0xFFFF ) );
#endif /* ! BACKSQL_ARBITRARY_KEY */

       uuid.bv_val = uuidbuf;
       uuid.bv_len = strlen( uuidbuf );

       ber_dupbv_x( entryUUID, &uuid, memctx );

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_entryUUID_decode ( struct berval entryUUID,
unsigned long *  oc_id,
unsigned long *  keyval 
)

Definition at line 537 of file util.c.

{
#if 0
       fprintf( stderr, "==> backsql_entryUUID_decode()\n" );
#endif

       *oc_id = ( entryUUID->bv_val[0] << 030 /* 24 */ )
              + ( entryUUID->bv_val[1] << 020 /* 16 */ )
              + ( entryUUID->bv_val[2] << 010 /* 8 */ )
              + entryUUID->bv_val[3];

#ifdef BACKSQL_ARBITRARY_KEY
       /* FIXME */
#else /* ! BACKSQL_ARBITRARY_KEY */
       *keyval = ( entryUUID->bv_val[4] << 030 /* 24 */ )
              + ( entryUUID->bv_val[5] << 020 /* 16 */ )
              + ( entryUUID->bv_val[6] << 010 /* 8 */ )
              + entryUUID->bv_val[7];
#endif /* ! BACKSQL_ARBITRARY_KEY */

#if 0
       fprintf( stderr, "<== backsql_entryUUID_decode(): oc=%lu id=%lu\n",
                     *oc_id, *keyval );
#endif

       return LDAP_SUCCESS;
}

Here is the caller graph for this function:

int backsql_free_db_conn ( Operation op,
SQLHDBC  dbh 
)

Definition at line 477 of file sql-wrap.c.

{
       Debug( LDAP_DEBUG_TRACE, "==>backsql_free_db_conn()\n", 0, 0, 0 );

       (void)backsql_close_db_handle( dbh );
       ldap_pvt_thread_pool_setkey( op->o_threadctx,
              &backsql_db_conn_dummy, (void *)SQL_NULL_HDBC,
              backsql_db_conn_keyfree, NULL, NULL );

       Debug( LDAP_DEBUG_TRACE, "<==backsql_free_db_conn()\n", 0, 0, 0 );

       return LDAP_SUCCESS;
}

Here is the call graph for this function:

Definition at line 363 of file sql-wrap.c.

{
       Debug( LDAP_DEBUG_TRACE, "==>backsql_free_db_env()\n", 0, 0, 0 );

       (void)SQLFreeEnv( bi->sql_db_env );
       bi->sql_db_env = SQL_NULL_HENV;

       /*
        * stop, if frontend waits for all threads to shutdown 
        * before calling this -- then what are we going to delete?? 
        * everything is already deleted...
        */
       Debug( LDAP_DEBUG_TRACE, "<==backsql_free_db_env()\n", 0, 0, 0 );

       return SQL_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

backsql_entryID* backsql_free_entryID ( backsql_entryID id,
int  freeit,
void ctx 
)

Definition at line 68 of file entry-id.c.

{
       backsql_entryID      *next;

       assert( id != NULL );

       next = id->eid_next;

       if ( !BER_BVISNULL( &id->eid_ndn ) ) {
              if ( !BER_BVISNULL( &id->eid_dn )
                            && id->eid_dn.bv_val != id->eid_ndn.bv_val )
              {
                     slap_sl_free( id->eid_dn.bv_val, ctx );
                     BER_BVZERO( &id->eid_dn );
              }

              slap_sl_free( id->eid_ndn.bv_val, ctx );
              BER_BVZERO( &id->eid_ndn );
       }

#ifdef BACKSQL_ARBITRARY_KEY
       if ( !BER_BVISNULL( &id->eid_id ) ) {
              slap_sl_free( id->eid_id.bv_val, ctx );
              BER_BVZERO( &id->eid_id );
       }

       if ( !BER_BVISNULL( &id->eid_keyval ) ) {
              slap_sl_free( id->eid_keyval.bv_val, ctx );
              BER_BVZERO( &id->eid_keyval );
       }
#endif /* BACKSQL_ARBITRARY_KEY */

       if ( freeit ) {
              slap_sl_free( id, ctx );
       }

       return next;
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETCODE backsql_FreeRow ( BACKSQL_ROW_NTS row)

Definition at line 303 of file sql-wrap.c.

{
       return backsql_FreeRow_x( row, NULL );
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETCODE backsql_FreeRow_x ( BACKSQL_ROW_NTS row,
void ctx 
)

Definition at line 286 of file sql-wrap.c.

{
       if ( row->cols == NULL ) {
              return SQL_ERROR;
       }

       ber_bvarray_free_x( row->col_names, ctx );
       ber_memfree_x( row->col_prec, ctx );
       ber_memfree_x( row->col_type, ctx );
       ber_memvfree_x( (void **)row->cols, ctx );
       ber_memfree_x( row->value_len, ctx );

       return SQL_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_get_db_conn ( Operation op,
SQLHDBC *  dbh 
)

Definition at line 492 of file sql-wrap.c.

{
       backsql_info  *bi = (backsql_info *)op->o_bd->be_private;
       int           rc = LDAP_SUCCESS;
       SQLHDBC              dbh = SQL_NULL_HDBC;

       Debug( LDAP_DEBUG_TRACE, "==>backsql_get_db_conn()\n", 0, 0, 0 );

       assert( dbhp != NULL );
       *dbhp = SQL_NULL_HDBC;

       if ( op->o_threadctx ) {
              void          *data = NULL;

              ldap_pvt_thread_pool_getkey( op->o_threadctx,
                            &backsql_db_conn_dummy, &data, NULL );
              dbh = (SQLHDBC)data;

       } else {
              dbh = bi->sql_dbh;
       }

       if ( dbh == SQL_NULL_HDBC ) {
              rc = backsql_open_db_handle( bi, &dbh );
              if ( rc != LDAP_SUCCESS ) {
                     return rc;
              }

              if ( op->o_threadctx ) {
                     void          *data = (void *)dbh;

                     ldap_pvt_thread_pool_setkey( op->o_threadctx,
                                   &backsql_db_conn_dummy, data,
                                   backsql_db_conn_keyfree, NULL, NULL );

              } else {
                     bi->sql_dbh = dbh;
              }
       }

       *dbhp = dbh;

       Debug( LDAP_DEBUG_TRACE, "<==backsql_get_db_conn()\n", 0, 0, 0 );

       return LDAP_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_has_children ( Operation op,
SQLHDBC  dbh,
struct berval dn 
)

Definition at line 488 of file entry-id.c.

{
       unsigned long nchildren;
       int           rc;

       rc = backsql_count_children( op, dbh, dn, &nchildren );

       if ( rc == LDAP_SUCCESS ) {
              return nchildren > 0 ? LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE;
       }

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 911 of file entry-id.c.

{
       Operation            *op = bsi->bsi_op;
       backsql_info         *bi = (backsql_info *)op->o_bd->be_private;
       int                  i;
       int                  rc;

       Debug( LDAP_DEBUG_TRACE, "==>backsql_id2entry()\n", 0, 0, 0 );

       assert( bsi->bsi_e != NULL );

       memset( bsi->bsi_e, 0, sizeof( Entry ) );

       if ( bi->sql_baseObject && BACKSQL_IS_BASEOBJECT_ID( &eid->eid_id ) ) {
              (void)entry_dup2( bsi->bsi_e, bi->sql_baseObject );
              goto done;
       }

       bsi->bsi_e->e_attrs = NULL;
       bsi->bsi_e->e_private = NULL;

       if ( eid->eid_oc == NULL ) {
              eid->eid_oc = backsql_id2oc( bsi->bsi_op->o_bd->be_private,
                     eid->eid_oc_id );
              if ( eid->eid_oc == NULL ) {
                     Debug( LDAP_DEBUG_TRACE,
                            "backsql_id2entry(): unable to fetch objectClass with id=" BACKSQL_IDNUMFMT " for entry id=" BACKSQL_IDFMT " dn=\"%s\"\n",
                            eid->eid_oc_id, BACKSQL_IDARG(eid->eid_id),
                            eid->eid_dn.bv_val );
                     return LDAP_OTHER;
              }
       }
       bsi->bsi_oc = eid->eid_oc;
       bsi->bsi_c_eid = eid;

       ber_dupbv_x( &bsi->bsi_e->e_name, &eid->eid_dn, op->o_tmpmemctx );
       ber_dupbv_x( &bsi->bsi_e->e_nname, &eid->eid_ndn, op->o_tmpmemctx );

#ifndef BACKSQL_ARBITRARY_KEY      
       /* FIXME: unused */
       bsi->bsi_e->e_id = eid->eid_id;
#endif /* ! BACKSQL_ARBITRARY_KEY */
 
       rc = attr_merge_normalize_one( bsi->bsi_e,
                     slap_schema.si_ad_objectClass,
                     &bsi->bsi_oc->bom_oc->soc_cname,
                     bsi->bsi_op->o_tmpmemctx );
       if ( rc != LDAP_SUCCESS ) {
              backsql_entry_clean( op, bsi->bsi_e );
              return rc;
       }

       if ( bsi->bsi_attrs == NULL || ( bsi->bsi_flags & BSQL_SF_ALL_USER ) )
       {
              Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
                     "retrieving all attributes\n", 0, 0, 0 );
              avl_apply( bsi->bsi_oc->bom_attrs, backsql_get_attr_vals,
                            bsi, 0, AVL_INORDER );

       } else {
              Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
                     "custom attribute list\n", 0, 0, 0 );
              for ( i = 0; !BER_BVISNULL( &bsi->bsi_attrs[ i ].an_name ); i++ ) {
                     backsql_at_map_rec   **vat;
                     AttributeName        *an = &bsi->bsi_attrs[ i ];
                     int                  j;

                     /* if one of the attributes listed here is
                      * a subtype of another, it must be ignored,
                      * because subtypes are already dealt with
                      * by backsql_supad2at()
                      */
                     for ( j = 0; !BER_BVISNULL( &bsi->bsi_attrs[ j ].an_name ); j++ ) {
                            /* skip self */
                            if ( j == i ) {
                                   continue;
                            }

                            /* skip subtypes */
                            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, an->an_desc, &vat );
                     if ( rc != 0 || vat == NULL ) {
                            Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
                                          "attribute \"%s\" is not defined "
                                          "for objectlass \"%s\"\n",
                                          an->an_name.bv_val, 
                                          BACKSQL_OC_NAME( bsi->bsi_oc ), 0 );
                            continue;
                     }

                     for ( j = 0; vat[j]; j++ ) {
                            backsql_get_attr_vals( vat[j], bsi );
                     }

                     ch_free( vat );

next:;
              }
       }

       if ( bsi->bsi_flags & BSQL_SF_RETURN_ENTRYUUID ) {
              Attribute     *a_entryUUID,
                            **ap;

              a_entryUUID = backsql_operational_entryUUID( bi, eid );
              if ( a_entryUUID != NULL ) {
                     for ( ap = &bsi->bsi_e->e_attrs; 
                                   *ap; 
                                   ap = &(*ap)->a_next );

                     *ap = a_entryUUID;
              }
       }

       if ( ( bsi->bsi_flags & BSQL_SF_ALL_OPER )
                     || an_find( bsi->bsi_attrs, slap_bv_all_operational_attrs )
                     || an_find( bsi->bsi_attrs, &slap_schema.si_ad_structuralObjectClass->ad_cname ) )
       {
              ObjectClass   *soc = NULL;

              if ( BACKSQL_CHECK_SCHEMA( bi ) ) {
                     Attribute     *a;
                     const char    *text = NULL;
                     char          textbuf[ 1024 ];
                     size_t        textlen = sizeof( textbuf );
                     struct berval bv[ 2 ],
                                   *nvals;
                     int           rc = LDAP_SUCCESS;

                     a = attr_find( bsi->bsi_e->e_attrs,
                                   slap_schema.si_ad_objectClass );
                     if ( a != NULL ) {
                            nvals = a->a_nvals;

                     } else {
                            bv[ 0 ] = bsi->bsi_oc->bom_oc->soc_cname;
                            BER_BVZERO( &bv[ 1 ] );
                            nvals = bv;
                     }

                     rc = structural_class( nvals, &soc, NULL, 
                                   &text, textbuf, textlen, op->o_tmpmemctx );
                     if ( rc != LDAP_SUCCESS ) {
                            Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(%s): "
                                   "structural_class() failed %d (%s)\n",
                                   bsi->bsi_e->e_name.bv_val,
                                   rc, text ? text : "" );
                            backsql_entry_clean( op, bsi->bsi_e );
                            return rc;
                     }

                     if ( !bvmatch( &soc->soc_cname, &bsi->bsi_oc->bom_oc->soc_cname ) ) {
                            if ( !is_object_subclass( bsi->bsi_oc->bom_oc, soc ) ) {
                                   Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(%s): "
                                          "computed structuralObjectClass %s "
                                          "does not match objectClass %s associated "
                                          "to entry\n",
                                          bsi->bsi_e->e_name.bv_val, soc->soc_cname.bv_val,
                                          bsi->bsi_oc->bom_oc->soc_cname.bv_val );
                                   backsql_entry_clean( op, bsi->bsi_e );
                                   return rc;
                            }

                            Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(%s): "
                                   "computed structuralObjectClass %s "
                                   "is subclass of objectClass %s associated "
                                   "to entry\n",
                                   bsi->bsi_e->e_name.bv_val, soc->soc_cname.bv_val,
                                   bsi->bsi_oc->bom_oc->soc_cname.bv_val );
                     }

              } else {
                     soc = bsi->bsi_oc->bom_oc;
              }

              rc = attr_merge_normalize_one( bsi->bsi_e,
                            slap_schema.si_ad_structuralObjectClass,
                            &soc->soc_cname,
                            bsi->bsi_op->o_tmpmemctx );
              if ( rc != LDAP_SUCCESS ) {
                     backsql_entry_clean( op, bsi->bsi_e );
                     return rc;
              }
       }

done:;
       Debug( LDAP_DEBUG_TRACE, "<==backsql_id2entry()\n", 0, 0, 0 );

       return LDAP_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 821 of file schema-map.c.

{
       backsql_oc_map_rec   tmp, *res;
 
#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>oc_with_id(): "
              "searching for objectclass with id=%lu\n", id, 0, 0 );
#endif /* BACKSQL_TRACE */

       tmp.bom_id = id;
       res = (backsql_oc_map_rec *)avl_find( bi->sql_oc_by_id, &tmp,
                     backsql_cmp_oc_id );

#ifdef BACKSQL_TRACE
       if ( res != NULL ) {
              Debug( LDAP_DEBUG_TRACE, "<==oc_with_id(): "
                     "found name=\"%s\", id=%lu\n",
                     BACKSQL_OC_NAME( res ), res->bom_id, 0 );
       } else {
              Debug( LDAP_DEBUG_TRACE, "<==oc_with_id(): "
                     "id=%lu not found\n", res->bom_id, 0, 0 );
       }
#endif /* BACKSQL_TRACE */
       
       return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 747 of file config.c.

{
       int rc;

       bi->bi_cf_ocs = sqlocs;
       rc = config_register_schema( sqlcfg, sqlocs );
       if ( rc ) return rc;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 341 of file sql-wrap.c.

{
       RETCODE              rc;
       int           ret = SQL_SUCCESS;
       
       Debug( LDAP_DEBUG_TRACE, "==>backsql_init_db_env()\n", 0, 0, 0 );

       rc = SQLAllocEnv( &bi->sql_db_env );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "init_db_env: SQLAllocEnv failed:\n",
                            0, 0, 0 );
              backsql_PrintErrors( SQL_NULL_HENV, SQL_NULL_HDBC,
                            SQL_NULL_HENV, rc );
              ret = SQL_ERROR;
       }

       Debug( LDAP_DEBUG_TRACE, "<==backsql_init_db_env()=%d\n", ret, 0, 0 );

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_init_search ( backsql_srch_info bsi,
struct berval nbase,
int  scope,
time_t  stoptime,
Filter filter,
SQLHDBC  dbh,
Operation op,
SlapReply rs,
AttributeName attrs,
unsigned  flags 
)

Definition at line 135 of file search.c.

{
       backsql_info         *bi = (backsql_info *)op->o_bd->be_private;
       int                  rc = LDAP_SUCCESS;

       bsi->bsi_base_ndn = nbase;
       bsi->bsi_use_subtree_shortcut = 0;
       BER_BVZERO( &bsi->bsi_base_id.eid_dn );
       BER_BVZERO( &bsi->bsi_base_id.eid_ndn );
       bsi->bsi_scope = scope;
       bsi->bsi_filter = filter;
       bsi->bsi_dbh = dbh;
       bsi->bsi_op = op;
       bsi->bsi_rs = rs;
       bsi->bsi_flags = BSQL_SF_NONE;

       bsi->bsi_attrs = NULL;

       if ( BACKSQL_FETCH_ALL_ATTRS( bi ) ) {
              /*
               * if requested, simply try to fetch all attributes
               */
              bsi->bsi_flags |= BSQL_SF_ALL_ATTRS;

       } else {
              if ( BACKSQL_FETCH_ALL_USERATTRS( bi ) ) {
                     bsi->bsi_flags |= BSQL_SF_ALL_USER;

              } else if ( BACKSQL_FETCH_ALL_OPATTRS( bi ) ) {
                     bsi->bsi_flags |= BSQL_SF_ALL_OPER;
              }

              if ( attrs == NULL ) {
                     /* NULL means all user attributes */
                     bsi->bsi_flags |= BSQL_SF_ALL_USER;

              } else {
                     AttributeName *p;
                     int           got_oc = 0;

                     bsi->bsi_attrs = (AttributeName *)bsi->bsi_op->o_tmpalloc(
                                   sizeof( AttributeName ),
                                   bsi->bsi_op->o_tmpmemctx );
                     BER_BVZERO( &bsi->bsi_attrs[ 0 ].an_name );
       
                     for ( p = attrs; !BER_BVISNULL( &p->an_name ); p++ ) {
                            if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_user_attrs ) == 0 ) {
                                   /* handle "*" */
                                   bsi->bsi_flags |= BSQL_SF_ALL_USER;

                                   /* if all attrs are requested, there's
                                    * no need to continue */
                                   if ( BSQL_ISF_ALL_ATTRS( bsi ) ) {
                                          bsi->bsi_op->o_tmpfree( bsi->bsi_attrs,
                                                        bsi->bsi_op->o_tmpmemctx );
                                          bsi->bsi_attrs = NULL;
                                          break;
                                   }
                                   continue;

                            } else if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_operational_attrs ) == 0 ) {
                                   /* handle "+" */
                                   bsi->bsi_flags |= BSQL_SF_ALL_OPER;

                                   /* if all attrs are requested, there's
                                    * no need to continue */
                                   if ( BSQL_ISF_ALL_ATTRS( bsi ) ) {
                                          bsi->bsi_op->o_tmpfree( bsi->bsi_attrs,
                                                        bsi->bsi_op->o_tmpmemctx );
                                          bsi->bsi_attrs = NULL;
                                          break;
                                   }
                                   continue;

                            } else if ( BACKSQL_NCMP( &p->an_name, slap_bv_no_attrs ) == 0 ) {
                                   /* ignore "1.1" */
                                   continue;

                            } else if ( p->an_desc == slap_schema.si_ad_objectClass ) {
                                   got_oc = 1;
                            }

                            backsql_attrlist_add( bsi, p->an_desc );
                     }

                     if ( got_oc == 0 && !( bsi->bsi_flags & BSQL_SF_ALL_USER ) ) {
                            /* add objectClass if not present,
                             * because it is required to understand
                             * if an entry is a referral, an alias 
                             * or so... */
                            backsql_attrlist_add( bsi, slap_schema.si_ad_objectClass );
                     }
              }

              if ( !BSQL_ISF_ALL_ATTRS( bsi ) && bi->sql_anlist ) {
                     AttributeName *p;
                     
                     /* use hints if available */
                     for ( p = bi->sql_anlist; !BER_BVISNULL( &p->an_name ); p++ ) {
                            if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_user_attrs ) == 0 ) {
                                   /* handle "*" */
                                   bsi->bsi_flags |= BSQL_SF_ALL_USER;

                                   /* if all attrs are requested, there's
                                    * no need to continue */
                                   if ( BSQL_ISF_ALL_ATTRS( bsi ) ) {
                                          bsi->bsi_op->o_tmpfree( bsi->bsi_attrs,
                                                        bsi->bsi_op->o_tmpmemctx );
                                          bsi->bsi_attrs = NULL;
                                          break;
                                   }
                                   continue;

                            } else if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_operational_attrs ) == 0 ) {
                                   /* handle "+" */
                                   bsi->bsi_flags |= BSQL_SF_ALL_OPER;

                                   /* if all attrs are requested, there's
                                    * no need to continue */
                                   if ( BSQL_ISF_ALL_ATTRS( bsi ) ) {
                                          bsi->bsi_op->o_tmpfree( bsi->bsi_attrs,
                                                        bsi->bsi_op->o_tmpmemctx );
                                          bsi->bsi_attrs = NULL;
                                          break;
                                   }
                                   continue;
                            }

                            backsql_attrlist_add( bsi, p->an_desc );
                     }

              }
       }

       bsi->bsi_id_list = NULL;
       bsi->bsi_id_listtail = &bsi->bsi_id_list;
       bsi->bsi_n_candidates = 0;
       bsi->bsi_stoptime = stoptime;
       BER_BVZERO( &bsi->bsi_sel.bb_val );
       bsi->bsi_sel.bb_len = 0;
       BER_BVZERO( &bsi->bsi_from.bb_val );
       bsi->bsi_from.bb_len = 0;
       BER_BVZERO( &bsi->bsi_join_where.bb_val );
       bsi->bsi_join_where.bb_len = 0;
       BER_BVZERO( &bsi->bsi_flt_where.bb_val );
       bsi->bsi_flt_where.bb_len = 0;
       bsi->bsi_filter_oc = NULL;

       if ( BACKSQL_IS_GET_ID( flags ) ) {
              int    matched = BACKSQL_IS_MATCHED( flags );
              int    getentry = BACKSQL_IS_GET_ENTRY( flags );
              int    gotit = 0;

              assert( op->o_bd->be_private != NULL );

              rc = backsql_dn2id( op, rs, dbh, nbase, &bsi->bsi_base_id,
                            matched, 1 );

              /* the entry is collected either if requested for by getentry
               * or if get noSuchObject and requested to climb the tree,
               * so that a matchedDN or a referral can be returned */
              if ( ( rc == LDAP_NO_SUCH_OBJECT && matched ) || getentry ) {
                     if ( !BER_BVISNULL( &bsi->bsi_base_id.eid_ndn ) ) {
                            assert( bsi->bsi_e != NULL );
                            
                            if ( dn_match( nbase, &bsi->bsi_base_id.eid_ndn ) )
                            {
                                   gotit = 1;
                            }
                     
                            /*
                             * let's see if it is a referral and, in case, get it
                             */
                            backsql_attrlist_add( bsi, slap_schema.si_ad_ref );
                            rc = backsql_id2entry( bsi, &bsi->bsi_base_id );
                            if ( rc == LDAP_SUCCESS ) {
                                   if ( is_entry_referral( bsi->bsi_e ) )
                                   {
                                          BerVarray erefs = get_entry_referrals( op, bsi->bsi_e );
                                          if ( erefs ) {
                                                 rc = rs->sr_err = LDAP_REFERRAL;
                                                 rs->sr_ref = referral_rewrite( erefs,
                                                               &bsi->bsi_e->e_nname,
                                                               &op->o_req_dn,
                                                               scope );
                                                 ber_bvarray_free( erefs );
       
                                          } else {
                                                 rc = rs->sr_err = LDAP_OTHER;
                                                 rs->sr_text = "bad referral object";
                                          }

                                   } else if ( !gotit ) {
                                          rc = rs->sr_err = LDAP_NO_SUCH_OBJECT;
                                   }
                            }

                     } else {
                            rs->sr_err = rc;
                     }
              }

              if ( gotit && BACKSQL_IS_GET_OC( flags ) ) {
                     bsi->bsi_base_id.eid_oc = backsql_id2oc( bi,
                            bsi->bsi_base_id.eid_oc_id );
                     if ( bsi->bsi_base_id.eid_oc == NULL ) {
                            /* error? */
                            backsql_free_entryID( &bsi->bsi_base_id, 1,
                                   op->o_tmpmemctx );
                            rc = rs->sr_err = LDAP_OTHER;
                     }
              }
       }

       bsi->bsi_status = rc;

       switch ( rc ) {
       case LDAP_SUCCESS:
       case LDAP_REFERRAL:
              break;

       default:
              bsi->bsi_op->o_tmpfree( bsi->bsi_attrs,
                            bsi->bsi_op->o_tmpmemctx );
              break;
       }

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_load_schema_map ( backsql_info si,
SQLHDBC  dbh 
)

Definition at line 501 of file schema-map.c.

{
       SQLHSTMT                    sth = SQL_NULL_HSTMT;
       RETCODE                            rc;
       BACKSQL_ROW_NTS                    oc_row;
       backsql_key_t               oc_id;
       backsql_oc_map_rec          *oc_map;
       struct backsql_attr_schema_info    bas;

       int                         delete_proc_idx = 5;
       int                         create_hint_idx = delete_proc_idx + 2;

       Debug( LDAP_DEBUG_TRACE, "==>backsql_load_schema_map()\n", 0, 0, 0 );

       /* 
        * TimesTen : See if the ldap_entries.dn_ru field exists in the schema
        */
       if ( !BACKSQL_DONTCHECK_LDAPINFO_DN_RU( bi ) ) {
              rc = backsql_Prepare( dbh, &sth, 
                            backsql_check_dn_ru_query, 0 );
              if ( rc == SQL_SUCCESS ) {
                     /* Yes, the field exists */
                     bi->sql_flags |= BSQLF_HAS_LDAPINFO_DN_RU;
                     Debug( LDAP_DEBUG_TRACE, "ldapinfo.dn_ru field exists "
                            "in the schema\n", 0, 0, 0 );
              } else {
                     /* No such field exists */
                     bi->sql_flags &= ~BSQLF_HAS_LDAPINFO_DN_RU;
              }

              SQLFreeStmt( sth, SQL_DROP );
       }

       Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): oc_query \"%s\"\n", 
                     bi->sql_oc_query, 0, 0 );

       rc = backsql_Prepare( dbh, &sth, bi->sql_oc_query, 0 );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                     "error preparing oc_query: \"%s\"\n", 
                     bi->sql_oc_query, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              return LDAP_OTHER;
       }

       rc = SQLExecute( sth );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                     "error executing oc_query: \n", 0, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              return LDAP_OTHER;
       }

       backsql_BindRowAsStrings( sth, &oc_row );
       rc = SQLFetch( sth );

       if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) {
              delete_proc_idx++;
              create_hint_idx++;
       }

       for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) {
              {
                     struct {
                            int idx;
                            char *name;
                     } required[] = {
                            { 0, "id" },
                            { 1, "name" },
                            { 2, "keytbl" },
                            { 3, "keycol" },
                            { -1, "expect_return" },
                            { -1, NULL },
                     };
                     int i;

                     required[4].idx = delete_proc_idx + 1;

                     for ( i = 0; required[ i ].name != NULL; i++ ) {
                            if ( oc_row.value_len[ required[ i ].idx ] <= 0 ) {
                                   Debug( LDAP_DEBUG_ANY,
                                          "backsql_load_schema_map(): "
                                          "required column #%d \"%s\" is empty\n",
                                          required[ i ].idx, required[ i ].name, 0 );
                                   return LDAP_OTHER;
                            }
                     }
              }

              {
                     char          buf[ SLAP_TEXT_BUFLEN ];

                     snprintf( buf, sizeof( buf ),
                            "objectClass: "
                            "id=\"%s\" "
                            "name=\"%s\" "
                            "keytbl=\"%s\" "
                            "keycol=\"%s\" "
                            "create_proc=\"%s\" "
                            "create_keyval=\"%s\" "
                            "delete_proc=\"%s\" "
                            "expect_return=\"%s\""
                            "create_hint=\"%s\" ",
                            oc_row.cols[ 0 ],
                            oc_row.cols[ 1 ],
                            oc_row.cols[ 2 ],
                            oc_row.cols[ 3 ],
                            oc_row.cols[ 4 ] ? oc_row.cols[ 4 ] : "",
                            ( BACKSQL_CREATE_NEEDS_SELECT( bi ) && oc_row.cols[ 5 ] ) ? oc_row.cols[ 5 ] : "",
                            oc_row.cols[ delete_proc_idx ] ? oc_row.cols[ delete_proc_idx ] : "",
                            oc_row.cols[ delete_proc_idx + 1 ],
                            ( ( oc_row.ncols > create_hint_idx ) && oc_row.cols[ create_hint_idx ] ) ? oc_row.cols[ create_hint_idx ] : "" );
                     Debug( LDAP_DEBUG_TRACE, "%s\n", buf, 0, 0 );
              }

              oc_map = (backsql_oc_map_rec *)ch_calloc( 1,
                            sizeof( backsql_oc_map_rec ) );

              if ( BACKSQL_STR2ID( &oc_map->bom_id, oc_row.cols[ 0 ], 0 ) != 0 ) {
                     Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                            "unable to parse id=\"%s\"\n", 
                            oc_row.cols[ 0 ], 0, 0 );
                     return LDAP_OTHER;
              }

              oc_map->bom_oc = oc_find( oc_row.cols[ 1 ] );
              if ( oc_map->bom_oc == NULL ) {
                     Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                            "objectClass \"%s\" is not defined in schema\n", 
                            oc_row.cols[ 1 ], 0, 0 );
                     return LDAP_OTHER;   /* undefined objectClass ? */
              }
              
              ber_str2bv( oc_row.cols[ 2 ], 0, 1, &oc_map->bom_keytbl );
              ber_str2bv( oc_row.cols[ 3 ], 0, 1, &oc_map->bom_keycol );
              oc_map->bom_create_proc = ( oc_row.value_len[ 4 ] <= 0 ) ? NULL 
                     : ch_strdup( oc_row.cols[ 4 ] );

              if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) {
                     oc_map->bom_create_keyval = ( oc_row.value_len[ 5 ] <= 0 ) 
                            ? NULL : ch_strdup( oc_row.cols[ 5 ] );
              }
              oc_map->bom_delete_proc = ( oc_row.value_len[ delete_proc_idx ] <= 0 ) ? NULL 
                     : ch_strdup( oc_row.cols[ delete_proc_idx ] );
              if ( lutil_atoix( &oc_map->bom_expect_return, oc_row.cols[ delete_proc_idx + 1 ], 0 ) != 0 ) {
                     Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                            "unable to parse expect_return=\"%s\" for objectClass \"%s\"\n", 
                            oc_row.cols[ delete_proc_idx + 1 ], oc_row.cols[ 1 ], 0 );
                     return LDAP_OTHER;
              }

              if ( ( oc_row.ncols > create_hint_idx ) &&
                            ( oc_row.value_len[ create_hint_idx ] > 0 ) )
              {
                     const char    *text;

                     oc_map->bom_create_hint = NULL;
                     rc = slap_str2ad( oc_row.cols[ create_hint_idx ],
                                   &oc_map->bom_create_hint, &text );
                     if ( rc != SQL_SUCCESS ) {
                            Debug( LDAP_DEBUG_TRACE, "load_schema_map(): "
                                          "error matching "
                                          "AttributeDescription %s "
                                          "in create_hint: %s (%d)\n",
                                          oc_row.cols[ create_hint_idx ],
                                          text, rc );
                            backsql_PrintErrors( bi->sql_db_env, dbh,
                                          sth, rc );
                            return LDAP_OTHER;
                     }
              }

              /*
               * FIXME: first attempt to check for offending
               * instructions in {create|delete}_proc
               */

              oc_map->bom_attrs = NULL;
              if ( avl_insert( &bi->sql_oc_by_oc, oc_map, backsql_cmp_oc, avl_dup_error ) == -1 ) {
                     Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                                   "duplicate objectClass \"%s\" in objectClass map\n",
                                   oc_map->bom_oc->soc_cname.bv_val, 0, 0 );
                     return LDAP_OTHER;
              }
              if ( avl_insert( &bi->sql_oc_by_id, oc_map, backsql_cmp_oc_id, avl_dup_error ) == -1 ) {
                     Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                                   "duplicate objectClass \"%s\" in objectClass by ID map\n",
                                   oc_map->bom_oc->soc_cname.bv_val, 0, 0 );
                     return LDAP_OTHER;
              }
              oc_id = oc_map->bom_id;
              Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                     "objectClass \"%s\":\n    keytbl=\"%s\" keycol=\"%s\"\n",
                     BACKSQL_OC_NAME( oc_map ),
                     oc_map->bom_keytbl.bv_val, oc_map->bom_keycol.bv_val );
              if ( oc_map->bom_create_proc ) {
                     Debug( LDAP_DEBUG_TRACE, "    create_proc=\"%s\"\n",
                            oc_map->bom_create_proc, 0, 0 );
              }
              if ( oc_map->bom_create_keyval ) {
                     Debug( LDAP_DEBUG_TRACE, "    create_keyval=\"%s\"\n",
                            oc_map->bom_create_keyval, 0, 0 );
              }
              if ( oc_map->bom_create_hint ) {
                     Debug( LDAP_DEBUG_TRACE, "    create_hint=\"%s\"\n", 
                            oc_map->bom_create_hint->ad_cname.bv_val,
                            0, 0 );
              }
              if ( oc_map->bom_delete_proc ) {
                     Debug( LDAP_DEBUG_TRACE, "    delete_proc=\"%s\"\n", 
                            oc_map->bom_delete_proc, 0, 0 );
              }
              Debug( LDAP_DEBUG_TRACE, "    expect_return: "
                     "add=%d, del=%d; attributes:\n",
                     BACKSQL_IS_ADD( oc_map->bom_expect_return ), 
                     BACKSQL_IS_DEL( oc_map->bom_expect_return ), 0 );
       }

       backsql_FreeRow( &oc_row );
       SQLFreeStmt( sth, SQL_DROP );

       /* prepare for attribute fetching */
       Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): at_query \"%s\"\n", 
                     bi->sql_at_query, 0, 0 );

       rc = backsql_Prepare( dbh, &sth, bi->sql_at_query, 0 );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                     "error preparing at_query: \"%s\"\n", 
                     bi->sql_at_query, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              return LDAP_OTHER;
       }

       rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_INPUT, &oc_id );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                     "error binding param \"oc_id\" for at_query\n", 0, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
              SQLFreeStmt( sth, SQL_DROP );
              return LDAP_OTHER;
       }

       bas.bas_bi = bi;
       bas.bas_dbh = dbh;
       bas.bas_sth = sth;
       bas.bas_oc_id = &oc_id;
       bas.bas_rc = LDAP_SUCCESS;

       (void)avl_apply( bi->sql_oc_by_oc, backsql_oc_get_attr_mapping,
                     &bas, BACKSQL_AVL_STOP, AVL_INORDER );

       SQLFreeStmt( sth, SQL_DROP );

       bi->sql_flags |= BSQLF_SCHEMA_LOADED;

       Debug( LDAP_DEBUG_TRACE, "<==backsql_load_schema_map()\n", 0, 0, 0 );

       return bas.bas_rc;
}

Here is the call graph for this function:

int backsql_merge_from_clause ( backsql_info bi,
struct berbuf dest_from,
struct berval src_from 
)

Definition at line 324 of file util.c.

{
       char          *s, *p, *srcc, *pos, e;
       struct berbuf res = BB_NULL;

#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->bv_val, 0 );
#endif /* BACKSQL_TRACE */

       srcc = ch_strdup( src_from->bv_val );
       p = srcc;

       if ( dest_from != NULL ) {
              res = *dest_from;
       }
       
       while ( *p ) {
              s = backsql_get_table_spec( bi, &p );

#ifdef BACKSQL_TRACE
              Debug( LDAP_DEBUG_TRACE, "backsql_merge_from_clause(): "
                     "p=\"%s\" s=\"%s\"\n", p, s, 0 );
#endif /* BACKSQL_TRACE */

              if ( BER_BVISNULL( &res.bb_val ) ) {
                     backsql_strcat_x( &res, NULL, s, NULL );

              } else {
                     pos = strstr( res.bb_val.bv_val, s );
                     if ( pos == NULL || ( ( e = pos[ strlen( s ) ] ) != '\0' && e != ',' ) ) {
                            backsql_strfcat_x( &res, NULL, "cs", ',', s );
                     }
              }
              
              if ( s ) {
                     ch_free( s );
              }
       }

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "<==backsql_merge_from_clause()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */

       free( srcc );
       *dest_from = res;

       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_modify_delete_all_values ( Operation op,
SlapReply rs,
SQLHDBC  dbh,
backsql_entryID e_id,
backsql_at_map_rec at 
)

Definition at line 57 of file add.c.

{
       backsql_info  *bi = (backsql_info *)op->o_bd->be_private;
       RETCODE              rc;
       SQLHSTMT      asth = SQL_NULL_HSTMT;
       BACKSQL_ROW_NTS      row;

       assert( at != NULL );
       if ( at->bam_delete_proc == NULL ) {
              Debug( LDAP_DEBUG_TRACE,
                     "   backsql_modify_delete_all_values(): "
                     "missing attribute value delete procedure "
                     "for attr \"%s\"\n",
                     at->bam_ad->ad_cname.bv_val, 0, 0 );
              if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                     rs->sr_text = "SQL-backend error";
                     return rs->sr_err = LDAP_OTHER;
              }

              return LDAP_SUCCESS;
       }

       rc = backsql_Prepare( dbh, &asth, at->bam_query, 0 );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE,
                     "   backsql_modify_delete_all_values(): "
                     "error preparing attribute value select query "
                     "\"%s\"\n",
                     at->bam_query, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, 
                            asth, rc );

              rs->sr_text = "SQL-backend error";
              return rs->sr_err = LDAP_OTHER;
       }

       rc = backsql_BindParamID( asth, 1, SQL_PARAM_INPUT, &e_id->eid_keyval );
       if ( rc != SQL_SUCCESS ) {
              Debug( LDAP_DEBUG_TRACE,
                     "   backsql_modify_delete_all_values(): "
                     "error binding key value parameter "
                     "to attribute value select query\n",
                     0, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, 
                            asth, rc );
              SQLFreeStmt( asth, SQL_DROP );

              rs->sr_text = "SQL-backend error";
              return rs->sr_err = LDAP_OTHER;
       }
                     
       rc = SQLExecute( asth );
       if ( !BACKSQL_SUCCESS( rc ) ) {
              Debug( LDAP_DEBUG_TRACE,
                     "   backsql_modify_delete_all_values(): "
                     "error executing attribute value select query\n",
                     0, 0, 0 );
              backsql_PrintErrors( bi->sql_db_env, dbh, 
                            asth, rc );
              SQLFreeStmt( asth, SQL_DROP );

              rs->sr_text = "SQL-backend error";
              return rs->sr_err = LDAP_OTHER;
       }

       backsql_BindRowAsStrings_x( asth, &row, op->o_tmpmemctx );
       for ( rc = SQLFetch( asth );
                     BACKSQL_SUCCESS( rc );
                     rc = SQLFetch( asth ) )
       {
              int           i;
              /* first parameter no, parameter order */
              SQLUSMALLINT  pno = 0,
                            po = 0;
              /* procedure return code */
              int           prc = LDAP_SUCCESS;
              
              for ( i = 0; i < row.ncols; i++ ) {
                     SQLHSTMT      sth = SQL_NULL_HSTMT;
                     ber_len_t     col_len;
                     
                     rc = backsql_Prepare( dbh, &sth, at->bam_delete_proc, 0 );
                     if ( rc != SQL_SUCCESS ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_delete_all_values(): "
                                   "error preparing attribute value "
                                   "delete procedure "
                                   "\"%s\"\n",
                                   at->bam_delete_proc, 0, 0 );
                            backsql_PrintErrors( bi->sql_db_env, dbh, 
                                          sth, rc );

                            rs->sr_text = "SQL-backend error";
                            rs->sr_err = LDAP_OTHER;
                            goto done;
                     }

                     if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) {
                            pno = 1;
                            rc = backsql_BindParamInt( sth, 1,
                                          SQL_PARAM_OUTPUT, &prc );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_delete_all_values(): "
                                          "error binding output parameter for %s[%d]\n",
                                          at->bam_ad->ad_cname.bv_val, i, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, 
                                          sth, rc );
                                   SQLFreeStmt( sth, SQL_DROP );

                                   rs->sr_text = "SQL-backend error";
                                   rs->sr_err = LDAP_OTHER;
                                   goto done;
                            }
                     }
                     po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0;
                     rc = backsql_BindParamID( sth, pno + 1 + po,
                            SQL_PARAM_INPUT, &e_id->eid_keyval );
                     if ( rc != SQL_SUCCESS ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_delete_all_values(): "
                                   "error binding keyval parameter for %s[%d]\n",
                                   at->bam_ad->ad_cname.bv_val, i, 0 );
                            backsql_PrintErrors( bi->sql_db_env, dbh, 
                                   sth, rc );
                            SQLFreeStmt( sth, SQL_DROP );

                            rs->sr_text = "SQL-backend error";
                            rs->sr_err = LDAP_OTHER;
                            goto done;
                     }

                     Debug( LDAP_DEBUG_TRACE,
                            "   backsql_modify_delete_all_values() "
                            "arg(%d)=" BACKSQL_IDFMT "\n",
                            pno + 1 + po,
                            BACKSQL_IDARG(e_id->eid_keyval), 0 );

                     /*
                      * check for syntax needed here 
                      * maybe need binary bind?
                      */
                     col_len = strlen( row.cols[ i ] );
                     rc = backsql_BindParamStr( sth, pno + 2 - po,
                            SQL_PARAM_INPUT, row.cols[ i ], col_len );
                     if ( rc != SQL_SUCCESS ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_delete_all_values(): "
                                   "error binding value parameter for %s[%d]\n",
                                   at->bam_ad->ad_cname.bv_val, i, 0 );
                            backsql_PrintErrors( bi->sql_db_env, dbh, 
                                   sth, rc );
                            SQLFreeStmt( sth, SQL_DROP );

                            rs->sr_text = "SQL-backend error";
                            rs->sr_err = LDAP_OTHER;
                            goto done;
                     }
        
                     Debug( LDAP_DEBUG_TRACE, 
                            "   backsql_modify_delete_all_values(): "
                            "arg(%d)=%s; executing \"%s\"\n",
                            pno + 2 - po, row.cols[ i ],
                            at->bam_delete_proc );
                     rc = SQLExecute( sth );
                     if ( rc == SQL_SUCCESS && prc == LDAP_SUCCESS ) {
                            rs->sr_err = LDAP_SUCCESS;

                     } else {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_delete_all_values(): "
                                   "delete_proc "
                                   "execution failed (rc=%d, prc=%d)\n",
                                   rc, prc, 0 );
                            if ( prc != LDAP_SUCCESS ) {
                                   /* SQL procedure executed fine 
                                    * but returned an error */
                                   rs->sr_err = BACKSQL_SANITIZE_ERROR( prc );

                            } else {
                                   backsql_PrintErrors( bi->sql_db_env, dbh,
                                                 sth, rc );
                                   rs->sr_err = LDAP_OTHER;
                            }
                            rs->sr_text = op->o_req_dn.bv_val;
                            SQLFreeStmt( sth, SQL_DROP );
                            goto done;
                     }
                     SQLFreeStmt( sth, SQL_DROP );
              }
       }

       rs->sr_err = LDAP_SUCCESS;

done:;
       backsql_FreeRow_x( &row, op->o_tmpmemctx );
       SQLFreeStmt( asth, SQL_DROP );

       return rs->sr_err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_modify_internal ( Operation op,
SlapReply rs,
SQLHDBC  dbh,
backsql_oc_map_rec oc,
backsql_entryID e_id,
Modifications modlist 
)

Definition at line 264 of file add.c.

{
       backsql_info  *bi = (backsql_info *)op->o_bd->be_private;
       RETCODE              rc;
       Modifications *ml;

       Debug( LDAP_DEBUG_TRACE, "==>backsql_modify_internal(): "
              "traversing modifications list\n", 0, 0, 0 );

       for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
              AttributeDescription *ad;
              int                  sm_op;
              static char          *sm_ops[] = { "add", "delete", "replace", "increment", NULL };

              BerVarray            sm_values;
#if 0
              /* NOTE: some day we'll have to pass 
               * the normalized values as well */
              BerVarray            sm_nvalues;
#endif
              backsql_at_map_rec   *at = NULL;
              struct berval        *at_val;
              int                  i;
              
              ad = ml->sml_mod.sm_desc;
              sm_op = ( ml->sml_mod.sm_op & LDAP_MOD_OP );
              sm_values = ml->sml_mod.sm_values;
#if 0
              sm_nvalues = ml->sml_mod.sm_nvalues;
#endif

              Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                     "modifying attribute \"%s\" (%s) according to "
                     "mappings for objectClass \"%s\"\n",
                     ad->ad_cname.bv_val, sm_ops[ sm_op ], BACKSQL_OC_NAME( oc ) );

              if ( backsql_attr_skip( ad, sm_values ) ) {
                     continue;
              }

              at = backsql_ad2at( oc, ad );
              if ( at == NULL ) {
                     Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                            "attribute \"%s\" is not registered "
                            "in objectClass \"%s\"\n",
                            ad->ad_cname.bv_val, BACKSQL_OC_NAME( oc ), 0 );

                     if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                            rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                            rs->sr_text = "operation not permitted "
                                   "within namingContext";
                            goto done;
                     }

                     continue;
              }
  
              switch ( sm_op ) {
              case LDAP_MOD_REPLACE: {
                     Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                            "replacing values for attribute \"%s\"\n",
                            at->bam_ad->ad_cname.bv_val, 0, 0 );

                     if ( at->bam_add_proc == NULL ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "add procedure is not defined "
                                   "for attribute \"%s\" "
                                   "- unable to perform replacements\n",
                                   at->bam_ad->ad_cname.bv_val, 0, 0 );

                            if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                   rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                                   rs->sr_text = "operation not permitted "
                                          "within namingContext";
                                   goto done;
                            }

                            break;
                     }

                     if ( at->bam_delete_proc == NULL ) {
                            if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "delete procedure is not defined "
                                          "for attribute \"%s\"\n",
                                          at->bam_ad->ad_cname.bv_val, 0, 0 );

                                   rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                                   rs->sr_text = "operation not permitted "
                                          "within namingContext";
                                   goto done;
                            }

                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "delete procedure is not defined "
                                   "for attribute \"%s\" "
                                   "- adding only\n",
                                   at->bam_ad->ad_cname.bv_val, 0, 0 );

                            goto add_only;
                     }

del_all:
                     rs->sr_err = backsql_modify_delete_all_values( op, rs, dbh, e_id, at );
                     if ( rs->sr_err != LDAP_SUCCESS ) {
                            goto done;
                     }

                     /* LDAP_MOD_DELETE gets here if all values must be deleted */
                     if ( sm_op == LDAP_MOD_DELETE ) {
                            break;
                     }
                     }

              /*
               * PASSTHROUGH - to add new attributes -- do NOT add break
               */
              case LDAP_MOD_ADD:
              /* case SLAP_MOD_SOFTADD: */
              /* case SLAP_MOD_ADD_IF_NOT_PRESENT: */
add_only:;
                     if ( at->bam_add_proc == NULL ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "add procedure is not defined "
                                   "for attribute \"%s\"\n",
                                   at->bam_ad->ad_cname.bv_val, 0, 0 );

                            if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                   rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                                   rs->sr_text = "operation not permitted "
                                          "within namingContext";
                                   goto done;
                            }

                            break;
                     }
                     
                     Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                            "adding new values for attribute \"%s\"\n",
                            at->bam_ad->ad_cname.bv_val, 0, 0 );

                     /* can't add a NULL val array */
                     assert( sm_values != NULL );
                     
                     for ( i = 0, at_val = sm_values;
                                   !BER_BVISNULL( at_val ); 
                                   i++, at_val++ )
                     {
                            SQLHSTMT      sth = SQL_NULL_HSTMT;
                            /* first parameter position, parameter order */
                            SQLUSMALLINT  pno = 0,
                                          po;
                            /* procedure return code */
                            int           prc = LDAP_SUCCESS;

                            rc = backsql_Prepare( dbh, &sth, at->bam_add_proc, 0 );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "error preparing add query\n", 
                                          0, 0, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );

                                   rs->sr_err = LDAP_OTHER;
                                   rs->sr_text = "SQL-backend error";
                                   goto done;
                            }

                            if ( BACKSQL_IS_ADD( at->bam_expect_return ) ) {
                                   pno = 1;
                                   rc = backsql_BindParamInt( sth, 1,
                                          SQL_PARAM_OUTPUT, &prc );
                                   if ( rc != SQL_SUCCESS ) {
                                          Debug( LDAP_DEBUG_TRACE,
                                                 "   backsql_modify_internal(): "
                                                 "error binding output parameter for %s[%d]\n",
                                                 at->bam_ad->ad_cname.bv_val, i, 0 );
                                          backsql_PrintErrors( bi->sql_db_env, dbh, 
                                                 sth, rc );
                                          SQLFreeStmt( sth, SQL_DROP );

                                          rs->sr_text = "SQL-backend error";
                                          rs->sr_err = LDAP_OTHER;
                                          goto done;
                                   }
                            }
                            po = ( BACKSQL_IS_ADD( at->bam_param_order ) ) > 0;
                            rc = backsql_BindParamID( sth, pno + 1 + po,
                                   SQL_PARAM_INPUT, &e_id->eid_keyval );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "error binding keyval parameter for %s[%d]\n",
                                          at->bam_ad->ad_cname.bv_val, i, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, 
                                          sth, rc );
                                   SQLFreeStmt( sth, SQL_DROP );

                                   rs->sr_text = "SQL-backend error";
                                   rs->sr_err = LDAP_OTHER;
                                   goto done;
                            }

                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "arg(%d)=" BACKSQL_IDFMT "\n", 
                                   pno + 1 + po,
                                   BACKSQL_IDARG(e_id->eid_keyval), 0 );

                            /*
                             * check for syntax needed here
                             * maybe need binary bind?
                             */
                            rc = backsql_BindParamBerVal( sth, pno + 2 - po,
                                   SQL_PARAM_INPUT, at_val );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "error binding value parameter for %s[%d]\n",
                                          at->bam_ad->ad_cname.bv_val, i, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, 
                                          sth, rc );
                                   SQLFreeStmt( sth, SQL_DROP );

                                   rs->sr_text = "SQL-backend error";
                                   rs->sr_err = LDAP_OTHER;
                                   goto done;
                            }
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "arg(%d)=\"%s\"; executing \"%s\"\n", 
                                   pno + 2 - po, at_val->bv_val,
                                   at->bam_add_proc );

                            rc = SQLExecute( sth );
                            if ( rc == SQL_SUCCESS && prc == LDAP_SUCCESS ) {
                                   rs->sr_err = LDAP_SUCCESS;

                            } else {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "add_proc execution failed "
                                          "(rc=%d, prc=%d)\n",
                                          rc, prc, 0 );
                                   if ( prc != LDAP_SUCCESS ) {
                                          /* SQL procedure executed fine 
                                           * but returned an error */
                                          SQLFreeStmt( sth, SQL_DROP );

                                          rs->sr_err = BACKSQL_SANITIZE_ERROR( prc );
                                          rs->sr_text = at->bam_ad->ad_cname.bv_val;
                                          return rs->sr_err;
                                   
                                   } else {
                                          backsql_PrintErrors( bi->sql_db_env, dbh,
                                                        sth, rc );
                                          if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) 
                                          {
                                                 SQLFreeStmt( sth, SQL_DROP );

                                                 rs->sr_err = LDAP_OTHER;
                                                 rs->sr_text = "SQL-backend error";
                                                 goto done;
                                          }
                                   }
                            }
                            SQLFreeStmt( sth, SQL_DROP );
                     }
                     break;
                     
              case LDAP_MOD_DELETE:
              /* case SLAP_MOD_SOFTDEL: */
                     if ( at->bam_delete_proc == NULL ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "delete procedure is not defined "
                                   "for attribute \"%s\"\n",
                                   at->bam_ad->ad_cname.bv_val, 0, 0 );

                            if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                   rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                                   rs->sr_text = "operation not permitted "
                                          "within namingContext";
                                   goto done;
                            }

                            break;
                     }

                     if ( sm_values == NULL ) {
                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "no values given to delete "
                                   "for attribute \"%s\" "
                                   "-- deleting all values\n",
                                   at->bam_ad->ad_cname.bv_val, 0, 0 );
                            goto del_all;
                     }

                     Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                            "deleting values for attribute \"%s\"\n",
                            at->bam_ad->ad_cname.bv_val, 0, 0 );

                     for ( i = 0, at_val = sm_values;
                                   !BER_BVISNULL( at_val );
                                   i++, at_val++ )
                     {
                            SQLHSTMT      sth = SQL_NULL_HSTMT;
                            /* first parameter position, parameter order */
                            SQLUSMALLINT  pno = 0,
                                          po;
                            /* procedure return code */
                            int           prc = LDAP_SUCCESS;

                            rc = backsql_Prepare( dbh, &sth, at->bam_delete_proc, 0 );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "error preparing delete query\n", 
                                          0, 0, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );

                                   rs->sr_err = LDAP_OTHER;
                                   rs->sr_text = "SQL-backend error";
                                   goto done;
                            }

                            if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) {
                                   pno = 1;
                                   rc = backsql_BindParamInt( sth, 1,
                                          SQL_PARAM_OUTPUT, &prc );
                                   if ( rc != SQL_SUCCESS ) {
                                          Debug( LDAP_DEBUG_TRACE,
                                                 "   backsql_modify_internal(): "
                                                 "error binding output parameter for %s[%d]\n",
                                                 at->bam_ad->ad_cname.bv_val, i, 0 );
                                          backsql_PrintErrors( bi->sql_db_env, dbh, 
                                                 sth, rc );
                                          SQLFreeStmt( sth, SQL_DROP );

                                          rs->sr_text = "SQL-backend error";
                                          rs->sr_err = LDAP_OTHER;
                                          goto done;
                                   }
                            }
                            po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0;
                            rc = backsql_BindParamID( sth, pno + 1 + po,
                                   SQL_PARAM_INPUT, &e_id->eid_keyval );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "error binding keyval parameter for %s[%d]\n",
                                          at->bam_ad->ad_cname.bv_val, i, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, 
                                          sth, rc );
                                   SQLFreeStmt( sth, SQL_DROP );

                                   rs->sr_text = "SQL-backend error";
                                   rs->sr_err = LDAP_OTHER;
                                   goto done;
                            }

                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "arg(%d)=" BACKSQL_IDFMT "\n", 
                                   pno + 1 + po,
                                   BACKSQL_IDARG(e_id->eid_keyval), 0 );

                            /*
                             * check for syntax needed here 
                             * maybe need binary bind?
                             */
                            rc = backsql_BindParamBerVal( sth, pno + 2 - po,
                                   SQL_PARAM_INPUT, at_val );
                            if ( rc != SQL_SUCCESS ) {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "error binding value parameter for %s[%d]\n",
                                          at->bam_ad->ad_cname.bv_val, i, 0 );
                                   backsql_PrintErrors( bi->sql_db_env, dbh, 
                                          sth, rc );
                                   SQLFreeStmt( sth, SQL_DROP );

                                   rs->sr_text = "SQL-backend error";
                                   rs->sr_err = LDAP_OTHER;
                                   goto done;
                            }

                            Debug( LDAP_DEBUG_TRACE,
                                   "   backsql_modify_internal(): "
                                   "executing \"%s\"\n", 
                                   at->bam_delete_proc, 0, 0 );
                            rc = SQLExecute( sth );
                            if ( rc == SQL_SUCCESS && prc == LDAP_SUCCESS )
                            {
                                   rs->sr_err = LDAP_SUCCESS;
                                   
                            } else {
                                   Debug( LDAP_DEBUG_TRACE,
                                          "   backsql_modify_internal(): "
                                          "delete_proc execution "
                                          "failed (rc=%d, prc=%d)\n",
                                          rc, prc, 0 );

                                   if ( prc != LDAP_SUCCESS ) {
                                          /* SQL procedure executed fine
                                           * but returned an error */
                                          rs->sr_err = BACKSQL_SANITIZE_ERROR( prc );
                                          rs->sr_text = at->bam_ad->ad_cname.bv_val;
                                          goto done;
                                          
                                   } else {
                                          backsql_PrintErrors( bi->sql_db_env,
                                                        dbh, sth, rc );
                                          SQLFreeStmt( sth, SQL_DROP );
                                          rs->sr_err = LDAP_OTHER;
                                          rs->sr_text = at->bam_ad->ad_cname.bv_val;
                                          goto done;
                                   }
                            }
                            SQLFreeStmt( sth, SQL_DROP );
                     }
                     break;

              case LDAP_MOD_INCREMENT:
                     Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                            "increment not supported yet\n", 0, 0, 0 );
                     if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                            rs->sr_err = LDAP_OTHER;
                            rs->sr_text = "SQL-backend error";
                            goto done;
                     }
                     break;
              }
       }

done:;
       Debug( LDAP_DEBUG_TRACE, "<==backsql_modify_internal(): %d%s%s\n",
              rs->sr_err,
              rs->sr_text ? ": " : "",
              rs->sr_text ? rs->sr_text : "" );

       /*
        * FIXME: should fail in case one change fails?
        */
       return rs->sr_err;
}

Here is the call graph for this function:

backsql_oc_map_rec* backsql_name2oc ( backsql_info si,
struct berval oc_name 
)

Definition at line 790 of file schema-map.c.

{
       backsql_oc_map_rec   tmp, *res;

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>oc_with_name(): "
              "searching for objectclass with name=\"%s\"\n",
              oc_name->bv_val, 0, 0 );
#endif /* BACKSQL_TRACE */

       tmp.bom_oc = oc_bvfind( oc_name );
       if ( tmp.bom_oc == NULL ) {
              return NULL;
       }

       res = (backsql_oc_map_rec *)avl_find( bi->sql_oc_by_oc, &tmp, backsql_cmp_oc );
#ifdef BACKSQL_TRACE
       if ( res != NULL ) {
              Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
                     "found name=\"%s\", id=%d\n", 
                     BACKSQL_OC_NAME( res ), res->bom_id, 0 );
       } else {
              Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): "
                     "not found\n", 0, 0, 0 );
       }
#endif /* BACKSQL_TRACE */
 
       return res;
}

Here is the call graph for this function:

Definition at line 763 of file schema-map.c.

{
       backsql_oc_map_rec   tmp, *res;

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>backsql_oc2oc(): "
              "searching for objectclass with name=\"%s\"\n",
              oc->soc_cname.bv_val, 0, 0 );
#endif /* BACKSQL_TRACE */

       tmp.bom_oc = oc;
       res = (backsql_oc_map_rec *)avl_find( bi->sql_oc_by_oc, &tmp, backsql_cmp_oc );
#ifdef BACKSQL_TRACE
       if ( res != NULL ) {
              Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): "
                     "found name=\"%s\", id=%d\n", 
                     BACKSQL_OC_NAME( res ), res->bom_id, 0 );
       } else {
              Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): "
                     "not found\n", 0, 0, 0 );
       }
#endif /* BACKSQL_TRACE */
 
       return res;
}

Here is the call graph for this function:

Definition at line 71 of file operational.c.

{
       char          csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
       struct berval entryCSN;
       Attribute     *a;

       a = attr_alloc( slap_schema.si_ad_entryCSN );
       a->a_numvals = 1;
       a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
       BER_BVZERO( &a->a_vals[ 1 ] );

#ifdef BACKSQL_SYNCPROV
       if ( op->o_sync && op->o_tag == LDAP_REQ_SEARCH && op->o_private != NULL ) {
              assert( op->o_private != NULL );

              entryCSN = *((struct berval *)op->o_private);

       } else
#endif /* BACKSQL_SYNCPROV */
       {
              entryCSN.bv_val = csnbuf;
              entryCSN.bv_len = sizeof( csnbuf );
              slap_get_csn( op, &entryCSN, 0 );
       }

       ber_dupbv( &a->a_vals[ 0 ], &entryCSN );

       a->a_nvals = a->a_vals;

       return a;
}

Here is the call graph for this function:

Definition at line 37 of file operational.c.

{
       int                  rc;
       struct berval        val, nval;
       AttributeDescription *desc = slap_schema.si_ad_entryUUID;
       Attribute            *a;

       backsql_entryUUID( bi, id, &val, NULL );

       rc = (*desc->ad_type->sat_equality->smr_normalize)(
                     SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
                     desc->ad_type->sat_syntax,
                     desc->ad_type->sat_equality,
                     &val, &nval, NULL );
       if ( rc != LDAP_SUCCESS ) {
              ber_memfree( val.bv_val );
              return NULL;
       }

       a = attr_alloc( desc );

       a->a_numvals = 1;
       a->a_vals = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
       a->a_vals[ 0 ] = val;
       BER_BVZERO( &a->a_vals[ 1 ] );

       a->a_nvals = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
       a->a_nvals[ 0 ] = nval;
       BER_BVZERO( &a->a_nvals[ 1 ] );

       return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETCODE backsql_Prepare ( SQLHDBC  dbh,
SQLHSTMT *  sth,
const char *  query,
int  timeout 
)

Definition at line 55 of file sql-wrap.c.

{
       RETCODE              rc;

       rc = SQLAllocStmt( dbh, sth );
       if ( rc != SQL_SUCCESS ) {
              return rc;
       }

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>backsql_Prepare()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */

#ifdef BACKSQL_MSSQL_WORKAROUND
       {
              char          drv_name[ 30 ];
              SWORD         len;

              SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len );

#ifdef BACKSQL_TRACE
              Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n",
                            drv_name, 0, 0 );
#endif /* BACKSQL_TRACE */

              ldap_pvt_str2upper( drv_name );
              if ( !strncmp( drv_name, "SQLSRV32.DLL", STRLENOF( "SQLSRV32.DLL" ) ) ) {
                     /*
                      * stupid default result set in MS SQL Server
                      * does not support multiple active statements
                      * on the same connection -- so we are trying 
                      * to make it not to use default result set...
                      */
                     Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
                            "enabling MS SQL Server default result "
                            "set workaround\n", 0, 0, 0 );
                     rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, 
                                   SQL_CONCUR_ROWVER );
                     if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
                            Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): "
                                   "SQLSetStmtOption(SQL_CONCURRENCY,"
                                   "SQL_CONCUR_ROWVER) failed:\n", 
                                   0, 0, 0 );
                            backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc );
                            SQLFreeStmt( *sth, SQL_DROP );
                            return rc;
                     }
              }
       }
#endif /* BACKSQL_MSSQL_WORKAROUND */

       if ( timeout > 0 ) {
              Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
                     "setting query timeout to %d sec.\n", 
                     timeout, 0, 0 );
              rc = SQLSetStmtOption( *sth, SQL_QUERY_TIMEOUT, timeout );
              if ( rc != SQL_SUCCESS ) {
                     backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc );
                     SQLFreeStmt( *sth, SQL_DROP );
                     return rc;
              }
       }

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "<==backsql_Prepare() calling SQLPrepare()\n",
                     0, 0, 0 );
#endif /* BACKSQL_TRACE */

       return SQLPrepare( *sth, (SQLCHAR *)query, SQL_NTS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int backsql_prepare_pattern ( BerVarray  split_pattern,
BerVarray  values,
struct berval res 
)

Definition at line 450 of file util.c.

{
       int           i;
       struct berbuf bb = BB_NULL;

       assert( res != NULL );

       for ( i = 0; values[i].bv_val; i++ ) {
              if ( split_pattern[i].bv_val == NULL ) {
                     ch_free( bb.bb_val.bv_val );
                     return -1;
              }
              backsql_strfcat_x( &bb, NULL, "b", &split_pattern[ i ] );
              backsql_strfcat_x( &bb, NULL, "b", &values[ i ] );
       }

       if ( split_pattern[ i ].bv_val == NULL ) {
              ch_free( bb.bb_val.bv_val );
              return -1;
       }

       backsql_strfcat_x( &bb, NULL, "b", &split_pattern[ i ] );

       *res = bb.bb_val;

       return 0;
}

Here is the call graph for this function:

void backsql_PrintErrors ( SQLHENV  henv,
SQLHDBC  hdbc,
SQLHSTMT  sth,
int  rc 
)

Definition at line 36 of file sql-wrap.c.

{
       SQLCHAR       msg[SQL_MAX_MESSAGE_LENGTH];              /* msg. buffer    */
       SQLCHAR       state[SQL_SQLSTATE_SIZE];          /* statement buf. */
       SDWORD iSqlCode;                          /* return code    */
       SWORD  len = SQL_MAX_MESSAGE_LENGTH - 1;  /* return length  */ 

       Debug( LDAP_DEBUG_TRACE, "Return code: %d\n", rc, 0, 0 );

       for ( ; rc = SQLError( henv, hdbc, sth, state, &iSqlCode, msg,
              SQL_MAX_MESSAGE_LENGTH - 1, &len ), BACKSQL_SUCCESS( rc ); )
       {
              Debug( LDAP_DEBUG_TRACE,
                     "   nativeErrCode=%d SQLengineState=%s msg=\"%s\"\n",
                     (int)iSqlCode, state, msg );
       }
}

Here is the caller graph for this function:

int backsql_split_pattern ( const char *  pattern,
BerVarray split_pattern,
int  expected 
)

Definition at line 387 of file util.c.

{
       char          *pattern, *start, *end;
       struct berval bv;
       int           rc = 0;

#define SPLIT_CHAR   '?'
       
       assert( _pattern != NULL );
       assert( split_pattern != NULL );

       pattern = ch_strdup( _pattern );

       start = pattern;
       end = strchr( start, SPLIT_CHAR );
       for ( ; start; expected-- ) {
              char          *real_end = end;
              ber_len_t     real_len;
              
              if ( real_end == NULL ) {
                     real_end = start + strlen( start );

              } else if ( real_end[ 1 ] == SPLIT_CHAR ) {
                     expected++;
                     AC_MEMCPY( real_end, real_end + 1, strlen( real_end ) );
                     end = strchr( real_end + 1, SPLIT_CHAR );
                     continue;
              }

              real_len = real_end - start;
              if ( real_len == 0 ) {
                     ber_str2bv( "", 0, 1, &bv );
              } else {
                     ber_str2bv( start, real_len, 1, &bv );
              }

              ber_bvarray_add( split_pattern, &bv );

              if ( expected == 0 ) {
                     if ( end != NULL ) {
                            rc = -1;
                            goto done;
                     }
                     break;
              }

              if ( end != NULL ) {
                     start = end + 1;
                     end = strchr( start, SPLIT_CHAR );
              }
       }

done:;

       ch_free( pattern );

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct berbuf* backsql_strcat_x ( struct berbuf dest,
void memctx,
  ... 
) [read]

Definition at line 68 of file util.c.

{
       va_list              strs;
       ber_len_t     cdlen, cslen, grow;
       char          *cstr;

       assert( dest != NULL );
       assert( dest->bb_val.bv_val == NULL 
                     || dest->bb_val.bv_len == strlen( dest->bb_val.bv_val ) );
 
#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>backsql_strcat()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */

       va_start( strs, memctx );
       if ( dest->bb_val.bv_val == NULL || dest->bb_len == 0 ) {
              dest->bb_val.bv_val = (char *)ber_memalloc_x( BACKSQL_STR_GROW * sizeof( char ), memctx );
              dest->bb_val.bv_len = 0;
              dest->bb_len = BACKSQL_STR_GROW;
       }
       cdlen = dest->bb_val.bv_len;
       while ( ( cstr = va_arg( strs, char * ) ) != NULL ) {
              cslen = strlen( cstr );
              grow = BACKSQL_MAX( BACKSQL_STR_GROW, cslen );
              if ( dest->bb_len - cdlen <= cslen ) {
                     char   *tmp_dest;

#ifdef BACKSQL_TRACE
                     Debug( LDAP_DEBUG_TRACE, "backsql_strcat(): "
                            "buflen=%d, cdlen=%d, cslen=%d "
                            "-- reallocating dest\n",
                            dest->bb_len, cdlen + 1, cslen );
#endif /* BACKSQL_TRACE */

                     tmp_dest = (char *)ber_memrealloc_x( dest->bb_val.bv_val,
                                   dest->bb_len + grow * sizeof( char ), memctx );
                     if ( tmp_dest == NULL ) {
                            Debug( LDAP_DEBUG_ANY, "backsql_strcat(): "
                                   "could not reallocate string buffer.\n",
                                   0, 0, 0 );
                            return NULL;
                     }
                     dest->bb_val.bv_val = tmp_dest;
                     dest->bb_len += grow;

#ifdef BACKSQL_TRACE
                     Debug( LDAP_DEBUG_TRACE, "backsql_strcat(): "
                            "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 );
              cdlen += cslen;
       }
       va_end( strs );

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "<==backsql_strcat() (dest=\"%s\")\n", 
                     dest->bb_val.bv_val, 0, 0 );
#endif /* BACKSQL_TRACE */

       dest->bb_val.bv_len = cdlen;

       return dest;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

struct berbuf* backsql_strfcat_x ( struct berbuf dest,
void memctx,
const char *  fmt,
  ... 
) [read]

Definition at line 135 of file util.c.

{
       va_list              strs;
       ber_len_t     cdlen;

       assert( dest != NULL );
       assert( fmt != NULL );
       assert( dest->bb_len == 0 || dest->bb_len > dest->bb_val.bv_len );
       assert( dest->bb_val.bv_val == NULL 
                     || dest->bb_val.bv_len == strlen( dest->bb_val.bv_val ) );
 
#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "==>backsql_strfcat()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */

       va_start( strs, fmt );
       if ( dest->bb_val.bv_val == NULL || dest->bb_len == 0 ) {
              dest->bb_val.bv_val = (char *)ber_memalloc_x( BACKSQL_STR_GROW * sizeof( char ), memctx );
              dest->bb_val.bv_len = 0;
              dest->bb_len = BACKSQL_STR_GROW;
       }

       cdlen = dest->bb_val.bv_len;
       for ( ; fmt[0]; fmt++ ) {
              ber_len_t     cslen, grow;
              char          *cstr, cc[ 2 ] = { '\0', '\0' };
              struct berval *cbv;

              switch ( fmt[ 0 ] ) {

              /* berval */
              case 'b':
                     cbv = va_arg( strs, struct berval * );
                     cstr = cbv->bv_val;
                     cslen = cbv->bv_len;
                     break;

              /* length + string */
              case 'l':
                     cslen = va_arg( strs, ber_len_t );
                     cstr = va_arg( strs, char * );
                     break;

              /* string */
              case 's':
                     cstr = va_arg( strs, char * );
                     cslen = strlen( cstr );
                     break;

              /* char */
              case 'c':
                     /* 
                      * `char' is promoted to `int' when passed through `...'
                      */
                     cc[0] = va_arg( strs, int );
                     cstr = cc;
                     cslen = 1;
                     break;

              default:
                     assert( 0 );
              }

              grow = BACKSQL_MAX( BACKSQL_STR_GROW, cslen );
              if ( dest->bb_len - cdlen <= cslen ) {
                     char   *tmp_dest;

#ifdef BACKSQL_TRACE
                     Debug( LDAP_DEBUG_TRACE, "backsql_strfcat(): "
                            "buflen=%d, cdlen=%d, cslen=%d "
                            "-- reallocating dest\n",
                            dest->bb_len, cdlen + 1, cslen );
#endif /* BACKSQL_TRACE */

                     tmp_dest = (char *)ber_memrealloc_x( dest->bb_val.bv_val,
                                   ( dest->bb_len ) + grow * sizeof( char ), memctx );
                     if ( tmp_dest == NULL ) {
                            Debug( LDAP_DEBUG_ANY, "backsql_strfcat(): "
                                   "could not reallocate string buffer.\n",
                                   0, 0, 0 );
                            return NULL;
                     }
                     dest->bb_val.bv_val = tmp_dest;
                     dest->bb_len += grow * sizeof( char );

#ifdef BACKSQL_TRACE
                     Debug( LDAP_DEBUG_TRACE, "backsql_strfcat(): "
                            "new buflen=%d, dest=%p\n", dest->bb_len, dest, 0 );
#endif /* BACKSQL_TRACE */
              }

              assert( cstr != NULL );
              
              AC_MEMCPY( dest->bb_val.bv_val + cdlen, cstr, cslen + 1 );
              cdlen += cslen;
       }

       va_end( strs );

#ifdef BACKSQL_TRACE
       Debug( LDAP_DEBUG_TRACE, "<==backsql_strfcat() (dest=\"%s\")\n", 
                     dest->bb_val.bv_val, 0, 0 );
#endif /* BACKSQL_TRACE */

       dest->bb_val.bv_len = cdlen;

       return dest;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 934 of file schema-map.c.

{
       struct supad2at_t    va = { 0 };
       int                  rc;

       assert( objclass != NULL );
       assert( supad != NULL );
       assert( pret != NULL );

       *pret = NULL;

       va.ad = supad;

       rc = avl_apply( objclass->bom_attrs, supad2at_f, &va,
                     SUPAD2AT_STOP, AVL_INORDER );
       if ( rc == SUPAD2AT_STOP ) {
              return -1;
       }

       *pret = va.ret;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 65 of file util.c.

BI_db_config backsql_db_config

Definition at line 46 of file util.c.

Definition at line 62 of file util.c.

Definition at line 50 of file util.c.

Definition at line 56 of file util.c.

Definition at line 53 of file util.c.

Definition at line 43 of file util.c.

Definition at line 40 of file util.c.

Definition at line 51 of file util.c.

Definition at line 58 of file util.c.

Definition at line 59 of file util.c.

BI_entry_get_rw backsql_entry_get
BI_entry_release_rw backsql_entry_release

Definition at line 60 of file util.c.

BI_operational backsql_operational