1 /* $NetBSD: back-sql.h,v 1.1.1.2 2010/03/08 02:14:20 lukem Exp $ */ 2 3 /* OpenLDAP: pkg/ldap/servers/slapd/back-sql/back-sql.h,v 1.49.2.5 2009/01/22 00:01:11 kurt Exp */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1999-2009 The OpenLDAP Foundation. 7 * Portions Copyright 1999 Dmitry Kovalev. 8 * Portions Copyright 2002 Pierangelo Mararati. 9 * Portions Copyright 2004 Mark Adamson. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted only as authorized by the OpenLDAP 14 * Public License. 15 * 16 * A copy of this license is available in the file LICENSE in the 17 * top-level directory of the distribution or, alternatively, at 18 * <http://www.OpenLDAP.org/license.html>. 19 */ 20 /* ACKNOWLEDGEMENTS: 21 * This work was initially developed by Dmitry Kovalev for inclusion 22 * by OpenLDAP Software. Additional significant contributors include 23 * Pierangelo Masarati and Mark Adamson. 24 */ 25 /* 26 * The following changes have been addressed: 27 * 28 * Enhancements: 29 * - re-styled code for better readability 30 * - upgraded backend API to reflect recent changes 31 * - LDAP schema is checked when loading SQL/LDAP mapping 32 * - AttributeDescription/ObjectClass pointers used for more efficient 33 * mapping lookup 34 * - bervals used where string length is required often 35 * - atomized write operations by committing at the end of each operation 36 * and defaulting connection closure to rollback 37 * - added LDAP access control to write operations 38 * - fully implemented modrdn (with rdn attrs change, deleteoldrdn, 39 * access check, parent/children check and more) 40 * - added parent access control, children control to delete operation 41 * - added structuralObjectClass operational attribute check and 42 * value return on search 43 * - added hasSubordinate operational attribute on demand 44 * - search limits are appropriately enforced 45 * - function backsql_strcat() has been made more efficient 46 * - concat function has been made configurable by means of a pattern 47 * - added config switches: 48 * - fail_if_no_mapping write operations fail if there is no mapping 49 * - has_ldapinfo_dn_ru overrides autodetect 50 * - concat_pattern a string containing two '?' is used 51 * (note that "?||?" should be more portable 52 * than builtin function "CONCAT(?,?)") 53 * - strcast_func cast of string constants in "SELECT DISTINCT 54 * statements (needed by PostgreSQL) 55 * - upper_needs_cast cast the argument of upper when required 56 * (basically when building dn substring queries) 57 * - added noop control 58 * - added values return filter control 59 * - hasSubordinate can be used in search filters (with limitations) 60 * - eliminated oc->name; use oc->oc->soc_cname instead 61 * 62 * Todo: 63 * - add security checks for SQL statements that can be injected (?) 64 * - re-test with previously supported RDBMs 65 * - replace dn_ru and so with normalized dn (no need for upper() and so 66 * in dn match) 67 * - implement a backsql_normalize() function to replace the upper() 68 * conversion routines 69 * - note that subtree deletion, subtree renaming and so could be easily 70 * implemented (rollback and consistency checks are available :) 71 * - implement "lastmod" and other operational stuff (ldap_entries table ?) 72 * - check how to allow multiple operations with one statement, to remove 73 * BACKSQL_REALLOC_STMT from modify.c (a more recent unixODBC lib?) 74 */ 75 /* 76 * Improvements submitted by (ITS#3432) 77 * 78 * 1. id_query.patch applied (with changes) 79 * 2. shortcut.patch applied (reworked) 80 * 3. create_hint.patch applied 81 * 4. count_query.patch applied (reworked) 82 * 5. returncodes.patch applied (with sanity checks) 83 * 6. connpool.patch under evaluation 84 * 7. modoc.patch under evaluation (requires 85 * manageDSAit and "manage" 86 * access privileges) 87 * 8. miscfixes.patch applied (reworked; other 88 * operations need to load the 89 * entire entry for ACL purposes; 90 * see ITS#3480, now fixed) 91 * 92 * original description: 93 94 Changes that were made to the SQL backend. 95 96 The patches were made against 2.2.18 and can be applied individually, 97 but would best be applied in the numerical order of the file names. 98 A synopsis of each patch is given here: 99 100 101 1. Added an option to set SQL query for the "id_query" operation. 102 103 2. Added an option to the SQL backend called "use_subtree_shortcut". 104 When a search is performed, the SQL query includes a WHERE clause 105 which says the DN must be "LIKE %<searchbase>". The LIKE operation 106 can be slow in an RDBM. This shortcut option says that if the 107 searchbase of the LDAP search is the root DN of the SQL backend, 108 and thus all objects will match the LIKE operator, do not include 109 the "LIKE %<searchbase>" clause in the SQL query (it is replaced 110 instead by the always true "1=1" clause to keep the "AND"'s 111 working correctly). This option is off by default, and should be 112 turned on only if all objects to be found in the RDBM are under the 113 same root DN. Multiple backends working within the same RDBM table 114 space would encounter problems. LDAP searches whose searchbase are 115 not at the root DN will bypass this shortcut and employ the LIKE 116 clause. 117 118 3. Added a "create_hint" column to ldap_oc_mappings table. Allows 119 taking the value of an attr named in "create_hint" and passing it to 120 the create_proc procedure. This is necessary for when an objectClass's 121 table is partition indexed by some indexing column and thus the value 122 in that indexing column cannot change after the row is created. The 123 value for the indexed column is passed into the create_proc, which 124 uses it to fill in the indexed column as the new row is created. 125 126 4. When loading the values of an attribute, the count(*) of the number 127 of values is fetched first and memory is allocated for the array of 128 values and normalized values. The old system of loading the values one 129 by one and running realloc() on the array of values and normalized 130 values each time was badly fragmenting memory. The array of values and 131 normalized values would be side by side in memory, and realloc()'ing 132 them over and over would force them to leapfrog each other through all 133 of available memory. Attrs with a large number of values could not be 134 loaded without crashing the slapd daemon. 135 136 5. Added code to interpret the value returned by stored procedures 137 which have expect_return set. Returned value is interpreted as an LDAP 138 return code. This allows the distinction between the SQL failing to 139 execute and the SQL running to completion and returning an error code 140 which can indicate a policy violation. 141 142 6. Added RDBM connection pooling. Once an operation is finished the 143 connection to the RDBM is returned to a pool rather than closing. 144 Allows the next operation to skip the initialization and authentication 145 phases of contacting the RDBM. Also, if licensing with ODBC places 146 a limit on the number of connections, an LDAP thread can block waiting 147 for another thread to finish, so that no LDAP errors are returned 148 for having more LDAP connections than allowed RDBM connections. An 149 RDBM connection which receives an SQL error is marked as "tainted" 150 so that it will be closed rather than returned to the pool. 151 Also, RDBM connections must be bound to a given LDAP connection AND 152 operation number, and NOT just the connection number. Asynchronous 153 LDAP clients can have multiple simultaneous LDAP operations which 154 should not share the same RDBM connection. A given LDAP operation can 155 even make multiple SQL operations (e.g. a BIND operation which 156 requires SASL to perform an LDAP search to convert the SASL ID to an 157 LDAP DN), so each RDBM connection now has a refcount that must reach 158 zero before the connection is returned to the free pool. 159 160 7. Added ability to change the objectClass of an object. Required 161 considerable work to copy all attributes out of old object and into 162 new object. Does a schema check before proceeding. Creates a new 163 object, fills it in, deletes the old object, then changes the 164 oc_map_id and keyval of the entry in the "ldap_entries" table. 165 166 8. Generic fixes. Includes initializing pointers before they 167 get used in error branch cases, pointer checks before dereferencing, 168 resetting a return code to success after a COMPARE op, sealing 169 memory leaks, and in search.c, changing some of the "1=1" tests to 170 "2=2", "3=3", etc so that when reading slapd trace output, the 171 location in the source code where the x=x test was added to the SQL 172 can be easily distinguished. 173 */ 174 175 #ifndef __BACKSQL_H__ 176 #define __BACKSQL_H__ 177 178 /* former sql-types.h */ 179 #include <sql.h> 180 #include <sqlext.h> 181 182 typedef struct { 183 SWORD ncols; 184 BerVarray col_names; 185 UDWORD *col_prec; 186 SQLSMALLINT *col_type; 187 char **cols; 188 SQLINTEGER *value_len; 189 } BACKSQL_ROW_NTS; 190 191 /* 192 * Better use the standard length of 8192 (as of slap.h)? 193 * 194 * NOTE: must be consistent with definition in ldap_entries table 195 */ 196 /* #define BACKSQL_MAX_DN_LEN SLAP_LDAPDN_MAXLEN */ 197 #define BACKSQL_MAX_DN_LEN 255 198 199 /* 200 * define to enable very extensive trace logging (debug only) 201 */ 202 #undef BACKSQL_TRACE 203 204 /* 205 * define if using MS SQL and workaround needed (see sql-wrap.c) 206 */ 207 #undef BACKSQL_MSSQL_WORKAROUND 208 209 /* 210 * define to enable values counting for attributes 211 */ 212 #define BACKSQL_COUNTQUERY 213 214 /* 215 * define to enable prettification/validation of values 216 */ 217 #define BACKSQL_PRETTY_VALIDATE 218 219 /* 220 * define to enable varchars as unique keys in user tables 221 * 222 * by default integers are used (and recommended) 223 * for performances. Integers are used anyway in back-sql 224 * related tables. 225 */ 226 #undef BACKSQL_ARBITRARY_KEY 227 228 /* 229 * define to enable support for syncprov overlay 230 */ 231 #define BACKSQL_SYNCPROV 232 233 /* 234 * define to the appropriate aliasing string 235 * 236 * some RDBMSes tolerate (or require) that " AS " is not used 237 * when aliasing tables/columns 238 */ 239 #define BACKSQL_ALIASING "AS " 240 /* #define BACKSQL_ALIASING "" */ 241 242 /* 243 * define to the appropriate quoting char 244 * 245 * some RDBMSes tolerate/require that the aliases be enclosed 246 * in quotes. This is especially true for those that do not 247 * allow keywords used as aliases. 248 */ 249 #define BACKSQL_ALIASING_QUOTE "" 250 /* #define BACKSQL_ALIASING_QUOTE "\"" */ 251 /* #define BACKSQL_ALIASING_QUOTE "'" */ 252 253 /* 254 * API 255 * 256 * a simple mechanism to allow DN mucking between the LDAP 257 * and the stored string representation. 258 */ 259 typedef struct backsql_api { 260 char *ba_name; 261 int (*ba_config)( struct backsql_api *self, int argc, char *argv[] ); 262 int (*ba_destroy)( struct backsql_api *self ); 263 264 int (*ba_dn2odbc)( Operation *op, SlapReply *rs, struct berval *dn ); 265 int (*ba_odbc2dn)( Operation *op, SlapReply *rs, struct berval *dn ); 266 267 void *ba_private; 268 struct backsql_api *ba_next; 269 } backsql_api; 270 271 /* 272 * "structural" objectClass mapping structure 273 */ 274 typedef struct backsql_oc_map_rec { 275 /* 276 * Structure of corresponding LDAP objectClass definition 277 */ 278 ObjectClass *bom_oc; 279 #define BACKSQL_OC_NAME(ocmap) ((ocmap)->bom_oc->soc_cname.bv_val) 280 281 struct berval bom_keytbl; 282 struct berval bom_keycol; 283 /* expected to return keyval of newly created entry */ 284 char *bom_create_proc; 285 /* in case create_proc does not return the keyval of the newly 286 * created row */ 287 char *bom_create_keyval; 288 /* supposed to expect keyval as parameter and delete 289 * all the attributes as well */ 290 char *bom_delete_proc; 291 /* flags whether delete_proc is a function (whether back-sql 292 * should bind first parameter as output for return code) */ 293 int bom_expect_return; 294 unsigned long bom_id; 295 Avlnode *bom_attrs; 296 AttributeDescription *bom_create_hint; 297 } backsql_oc_map_rec; 298 299 /* 300 * attributeType mapping structure 301 */ 302 typedef struct backsql_at_map_rec { 303 /* Description of corresponding LDAP attribute type */ 304 AttributeDescription *bam_ad; 305 AttributeDescription *bam_true_ad; 306 /* ObjectClass if bam_ad is objectClass */ 307 ObjectClass *bam_oc; 308 309 struct berval bam_from_tbls; 310 struct berval bam_join_where; 311 struct berval bam_sel_expr; 312 313 /* TimesTen, or, if a uppercase function is defined, 314 * an uppercased version of bam_sel_expr */ 315 struct berval bam_sel_expr_u; 316 317 /* supposed to expect 2 binded values: entry keyval 318 * and attr. value to add, like "add_name(?,?,?)" */ 319 char *bam_add_proc; 320 /* supposed to expect 2 binded values: entry keyval 321 * and attr. value to delete */ 322 char *bam_delete_proc; 323 /* for optimization purposes attribute load query 324 * is preconstructed from parts on schemamap load time */ 325 char *bam_query; 326 #ifdef BACKSQL_COUNTQUERY 327 char *bam_countquery; 328 #endif /* BACKSQL_COUNTQUERY */ 329 /* following flags are bitmasks (first bit used for add_proc, 330 * second - for delete_proc) */ 331 /* order of parameters for procedures above; 332 * 1 means "data then keyval", 0 means "keyval then data" */ 333 int bam_param_order; 334 /* flags whether one or more of procedures is a function 335 * (whether back-sql should bind first parameter as output 336 * for return code) */ 337 int bam_expect_return; 338 339 /* next mapping for attribute */ 340 struct backsql_at_map_rec *bam_next; 341 } backsql_at_map_rec; 342 343 #define BACKSQL_AT_MAP_REC_INIT { NULL, NULL, BER_BVC(""), BER_BVC(""), BER_BVNULL, BER_BVNULL, NULL, NULL, NULL, 0, 0, NULL } 344 345 /* define to uppercase filters only if the matching rule requires it 346 * (currently broken) */ 347 /* #define BACKSQL_UPPERCASE_FILTER */ 348 349 #define BACKSQL_AT_CANUPPERCASE(at) ( !BER_BVISNULL( &(at)->bam_sel_expr_u ) ) 350 351 /* defines to support bitmasks above */ 352 #define BACKSQL_ADD 0x1 353 #define BACKSQL_DEL 0x2 354 355 #define BACKSQL_IS_ADD(x) ( ( BACKSQL_ADD & (x) ) == BACKSQL_ADD ) 356 #define BACKSQL_IS_DEL(x) ( ( BACKSQL_DEL & (x) ) == BACKSQL_DEL ) 357 358 #define BACKSQL_NCMP(v1,v2) ber_bvcmp((v1),(v2)) 359 360 #define BACKSQL_CONCAT 361 /* 362 * berbuf structure: a berval with a buffer size associated 363 */ 364 typedef struct berbuf { 365 struct berval bb_val; 366 ber_len_t bb_len; 367 } BerBuffer; 368 369 #define BB_NULL { BER_BVNULL, 0 } 370 371 /* 372 * Entry ID structure 373 */ 374 typedef struct backsql_entryID { 375 /* #define BACKSQL_ARBITRARY_KEY to allow a non-numeric key. 376 * It is required by some special applications that use 377 * strings as keys for the main table. 378 * In this case, #define BACKSQL_MAX_KEY_LEN consistently 379 * with the key size definition */ 380 #ifdef BACKSQL_ARBITRARY_KEY 381 struct berval eid_id; 382 struct berval eid_keyval; 383 #define BACKSQL_MAX_KEY_LEN 64 384 #else /* ! BACKSQL_ARBITRARY_KEY */ 385 /* The original numeric key is maintained as default. */ 386 unsigned long eid_id; 387 unsigned long eid_keyval; 388 #endif /* ! BACKSQL_ARBITRARY_KEY */ 389 390 unsigned long eid_oc_id; 391 backsql_oc_map_rec *eid_oc; 392 struct berval eid_dn; 393 struct berval eid_ndn; 394 struct backsql_entryID *eid_next; 395 } backsql_entryID; 396 397 #ifdef BACKSQL_ARBITRARY_KEY 398 #define BACKSQL_ENTRYID_INIT { BER_BVNULL, BER_BVNULL, 0, NULL, BER_BVNULL, BER_BVNULL, NULL } 399 #else /* ! BACKSQL_ARBITRARY_KEY */ 400 #define BACKSQL_ENTRYID_INIT { 0, 0, 0, NULL, BER_BVNULL, BER_BVNULL, NULL } 401 #endif /* BACKSQL_ARBITRARY_KEY */ 402 403 /* the function must collect the entry associated to nbase */ 404 #define BACKSQL_ISF_GET_ID 0x1U 405 #define BACKSQL_ISF_GET_ENTRY ( 0x2U | BACKSQL_ISF_GET_ID ) 406 #define BACKSQL_ISF_GET_OC ( 0x4U | BACKSQL_ISF_GET_ID ) 407 #define BACKSQL_ISF_MATCHED 0x8U 408 #define BACKSQL_IS_GET_ID(f) \ 409 ( ( (f) & BACKSQL_ISF_GET_ID ) == BACKSQL_ISF_GET_ID ) 410 #define BACKSQL_IS_GET_ENTRY(f) \ 411 ( ( (f) & BACKSQL_ISF_GET_ENTRY ) == BACKSQL_ISF_GET_ENTRY ) 412 #define BACKSQL_IS_GET_OC(f) \ 413 ( ( (f) & BACKSQL_ISF_GET_OC ) == BACKSQL_ISF_GET_OC ) 414 #define BACKSQL_IS_MATCHED(f) \ 415 ( ( (f) & BACKSQL_ISF_MATCHED ) == BACKSQL_ISF_MATCHED ) 416 typedef struct backsql_srch_info { 417 Operation *bsi_op; 418 SlapReply *bsi_rs; 419 420 unsigned bsi_flags; 421 #define BSQL_SF_NONE 0x0000U 422 #define BSQL_SF_ALL_USER 0x0001U 423 #define BSQL_SF_ALL_OPER 0x0002U 424 #define BSQL_SF_ALL_ATTRS (BSQL_SF_ALL_USER|BSQL_SF_ALL_OPER) 425 #define BSQL_SF_FILTER_HASSUBORDINATE 0x0010U 426 #define BSQL_SF_FILTER_ENTRYUUID 0x0020U 427 #define BSQL_SF_FILTER_ENTRYCSN 0x0040U 428 #define BSQL_SF_RETURN_ENTRYUUID (BSQL_SF_FILTER_ENTRYUUID << 8) 429 #define BSQL_ISF(bsi, f) ( ( (bsi)->bsi_flags & f ) == f ) 430 #define BSQL_ISF_ALL_USER(bsi) BSQL_ISF(bsi, BSQL_SF_ALL_USER) 431 #define BSQL_ISF_ALL_OPER(bsi) BSQL_ISF(bsi, BSQL_SF_ALL_OPER) 432 #define BSQL_ISF_ALL_ATTRS(bsi) BSQL_ISF(bsi, BSQL_SF_ALL_ATTRS) 433 434 struct berval *bsi_base_ndn; 435 int bsi_use_subtree_shortcut; 436 backsql_entryID bsi_base_id; 437 int bsi_scope; 438 /* BACKSQL_SCOPE_BASE_LIKE can be set by API in ors_scope 439 * whenever the search base DN contains chars that cannot 440 * be mapped into the charset used in the RDBMS; so they're 441 * turned into '%' and an approximate ('LIKE') condition 442 * is used */ 443 #define BACKSQL_SCOPE_BASE_LIKE ( LDAP_SCOPE_BASE | 0x1000 ) 444 Filter *bsi_filter; 445 time_t bsi_stoptime; 446 447 backsql_entryID *bsi_id_list, 448 **bsi_id_listtail, 449 *bsi_c_eid; 450 int bsi_n_candidates; 451 int bsi_status; 452 453 backsql_oc_map_rec *bsi_oc; 454 struct berbuf bsi_sel, 455 bsi_from, 456 bsi_join_where, 457 bsi_flt_where; 458 ObjectClass *bsi_filter_oc; 459 SQLHDBC bsi_dbh; 460 AttributeName *bsi_attrs; 461 462 Entry *bsi_e; 463 } backsql_srch_info; 464 465 /* 466 * Backend private data structure 467 */ 468 typedef struct backsql_info { 469 char *sql_dbhost; 470 int sql_dbport; 471 char *sql_dbuser; 472 char *sql_dbpasswd; 473 char *sql_dbname; 474 475 /* 476 * SQL condition for subtree searches differs in syntax: 477 * "LIKE CONCAT('%',?)" or "LIKE '%'+?" or "LIKE '%'||?" 478 * or smtg else 479 */ 480 struct berval sql_subtree_cond; 481 struct berval sql_children_cond; 482 struct berval sql_dn_match_cond; 483 char *sql_oc_query; 484 char *sql_at_query; 485 char *sql_insentry_stmt; 486 char *sql_delentry_stmt; 487 char *sql_renentry_stmt; 488 char *sql_delobjclasses_stmt; 489 char *sql_id_query; 490 char *sql_has_children_query; 491 char *sql_list_children_query; 492 493 MatchingRule *sql_caseIgnoreMatch; 494 MatchingRule *sql_telephoneNumberMatch; 495 496 struct berval sql_upper_func; 497 struct berval sql_upper_func_open; 498 struct berval sql_upper_func_close; 499 BerVarray sql_concat_func; 500 struct berval sql_strcast_func; 501 502 struct berval sql_aliasing; 503 struct berval sql_aliasing_quote; 504 struct berval sql_dn_oc_aliasing; 505 506 AttributeName *sql_anlist; 507 508 unsigned int sql_flags; 509 #define BSQLF_SCHEMA_LOADED 0x0001 510 #define BSQLF_UPPER_NEEDS_CAST 0x0002 511 #define BSQLF_CREATE_NEEDS_SELECT 0x0004 512 #define BSQLF_FAIL_IF_NO_MAPPING 0x0008 513 #define BSQLF_HAS_LDAPINFO_DN_RU 0x0010 514 #define BSQLF_DONTCHECK_LDAPINFO_DN_RU 0x0020 515 #define BSQLF_USE_REVERSE_DN 0x0040 516 #define BSQLF_ALLOW_ORPHANS 0x0080 517 #define BSQLF_USE_SUBTREE_SHORTCUT 0x0100 518 #define BSQLF_FETCH_ALL_USERATTRS 0x0200 519 #define BSQLF_FETCH_ALL_OPATTRS 0x0400 520 #define BSQLF_FETCH_ALL_ATTRS (BSQLF_FETCH_ALL_USERATTRS|BSQLF_FETCH_ALL_OPATTRS) 521 #define BSQLF_CHECK_SCHEMA 0x0800 522 523 #define BACKSQL_ISF(si, f) \ 524 (((si)->sql_flags & f) == f) 525 526 #define BACKSQL_SCHEMA_LOADED(si) \ 527 BACKSQL_ISF(si, BSQLF_SCHEMA_LOADED) 528 #define BACKSQL_UPPER_NEEDS_CAST(si) \ 529 BACKSQL_ISF(si, BSQLF_UPPER_NEEDS_CAST) 530 #define BACKSQL_CREATE_NEEDS_SELECT(si) \ 531 BACKSQL_ISF(si, BSQLF_CREATE_NEEDS_SELECT) 532 #define BACKSQL_FAIL_IF_NO_MAPPING(si) \ 533 BACKSQL_ISF(si, BSQLF_FAIL_IF_NO_MAPPING) 534 #define BACKSQL_HAS_LDAPINFO_DN_RU(si) \ 535 BACKSQL_ISF(si, BSQLF_HAS_LDAPINFO_DN_RU) 536 #define BACKSQL_DONTCHECK_LDAPINFO_DN_RU(si) \ 537 BACKSQL_ISF(si, BSQLF_DONTCHECK_LDAPINFO_DN_RU) 538 #define BACKSQL_USE_REVERSE_DN(si) \ 539 BACKSQL_ISF(si, BSQLF_USE_REVERSE_DN) 540 #define BACKSQL_CANUPPERCASE(si) \ 541 (!BER_BVISNULL( &(si)->sql_upper_func )) 542 #define BACKSQL_ALLOW_ORPHANS(si) \ 543 BACKSQL_ISF(si, BSQLF_ALLOW_ORPHANS) 544 #define BACKSQL_USE_SUBTREE_SHORTCUT(si) \ 545 BACKSQL_ISF(si, BSQLF_USE_SUBTREE_SHORTCUT) 546 #define BACKSQL_FETCH_ALL_USERATTRS(si) \ 547 BACKSQL_ISF(si, BSQLF_FETCH_ALL_USERATTRS) 548 #define BACKSQL_FETCH_ALL_OPATTRS(si) \ 549 BACKSQL_ISF(si, BSQLF_FETCH_ALL_OPATTRS) 550 #define BACKSQL_FETCH_ALL_ATTRS(si) \ 551 BACKSQL_ISF(si, BSQLF_FETCH_ALL_ATTRS) 552 #define BACKSQL_CHECK_SCHEMA(si) \ 553 BACKSQL_ISF(si, BSQLF_CHECK_SCHEMA) 554 555 Entry *sql_baseObject; 556 #ifdef BACKSQL_ARBITRARY_KEY 557 #define BACKSQL_BASEOBJECT_IDSTR "baseObject" 558 #define BACKSQL_BASEOBJECT_KEYVAL BACKSQL_BASEOBJECT_IDSTR 559 #define BACKSQL_IS_BASEOBJECT_ID(id) (bvmatch((id), &backsql_baseObject_bv)) 560 #else /* ! BACKSQL_ARBITRARY_KEY */ 561 #define BACKSQL_BASEOBJECT_ID 0 562 #define BACKSQL_BASEOBJECT_IDSTR LDAP_XSTRING(BACKSQL_BASEOBJECT_ID) 563 #define BACKSQL_BASEOBJECT_KEYVAL 0 564 #define BACKSQL_IS_BASEOBJECT_ID(id) (*(id) == BACKSQL_BASEOBJECT_ID) 565 #endif /* ! BACKSQL_ARBITRARY_KEY */ 566 #define BACKSQL_BASEOBJECT_OC 0 567 568 Avlnode *sql_db_conns; 569 SQLHDBC sql_dbh; 570 ldap_pvt_thread_mutex_t sql_dbconn_mutex; 571 Avlnode *sql_oc_by_oc; 572 Avlnode *sql_oc_by_id; 573 ldap_pvt_thread_mutex_t sql_schema_mutex; 574 SQLHENV sql_db_env; 575 576 backsql_api *sql_api; 577 } backsql_info; 578 579 #define BACKSQL_SUCCESS( rc ) \ 580 ( (rc) == SQL_SUCCESS || (rc) == SQL_SUCCESS_WITH_INFO ) 581 582 #define BACKSQL_AVL_STOP 0 583 #define BACKSQL_AVL_CONTINUE 1 584 585 /* see ldap.h for the meaning of the macros and of the values */ 586 #define BACKSQL_LEGAL_ERROR( rc ) \ 587 ( LDAP_RANGE( (rc), 0x00, 0x0e ) \ 588 || LDAP_ATTR_ERROR( (rc) ) \ 589 || LDAP_NAME_ERROR( (rc) ) \ 590 || LDAP_SECURITY_ERROR( (rc) ) \ 591 || LDAP_SERVICE_ERROR( (rc) ) \ 592 || LDAP_UPDATE_ERROR( (rc) ) ) 593 #define BACKSQL_SANITIZE_ERROR( rc ) \ 594 ( BACKSQL_LEGAL_ERROR( (rc) ) ? (rc) : LDAP_OTHER ) 595 596 #define BACKSQL_IS_BINARY(ct) \ 597 ( (ct) == SQL_BINARY \ 598 || (ct) == SQL_VARBINARY \ 599 || (ct) == SQL_LONGVARBINARY) 600 601 #endif /* __BACKSQL_H__ */ 602 603