X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-sql%2Fback-sql.h;h=e1d0db4a86431f696c8c6daa404ddefa3722441b;hb=5fcc9285fb8c549a5264921a2b61cfc40803d720;hp=dd3a35edceae9c488f2436e259b9c18e7735b83f;hpb=f5936eb7fcc66b9183399e9ea33793cf47f9e4a3;p=openldap diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index dd3a35edce..e1d0db4a86 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2005 The OpenLDAP Foundation. + * Copyright 1999-2012 The OpenLDAP Foundation. * Portions Copyright 1999 Dmitry Kovalev. * Portions Copyright 2002 Pierangelo Mararati. * Portions Copyright 2004 Mark Adamson. @@ -76,13 +76,16 @@ * 1. id_query.patch applied (with changes) * 2. shortcut.patch applied (reworked) * 3. create_hint.patch applied - * 4. count_query.patch rejected (conflicts with other features) + * 4. count_query.patch applied (reworked) * 5. returncodes.patch applied (with sanity checks) * 6. connpool.patch under evaluation - * 7. modoc.patch under evaluation - * 8. miscfixes.patch applied (reworked; FIXME: other - * operations may need to load the - * entire entry for ACL purposes) + * 7. modoc.patch under evaluation (requires + * manageDSAit and "manage" + * access privileges) + * 8. miscfixes.patch applied (reworked; other + * operations need to load the + * entire entry for ACL purposes; + * see ITS#3480, now fixed) * * original description: @@ -178,8 +181,9 @@ typedef struct { SWORD ncols; BerVarray col_names; UDWORD *col_prec; + SQLSMALLINT *col_type; char **cols; - SQLINTEGER *value_len; + SQLLEN *value_len; } BACKSQL_ROW_NTS; /* @@ -195,6 +199,21 @@ typedef struct { */ #undef BACKSQL_TRACE +/* + * define if using MS SQL and workaround needed (see sql-wrap.c) + */ +#undef BACKSQL_MSSQL_WORKAROUND + +/* + * define to enable values counting for attributes + */ +#define BACKSQL_COUNTQUERY + +/* + * define to enable prettification/validation of values + */ +#define BACKSQL_PRETTY_VALIDATE + /* * define to enable varchars as unique keys in user tables * @@ -205,11 +224,25 @@ typedef struct { #undef BACKSQL_ARBITRARY_KEY /* - * define to enable experimental support for syncporv overlay + * type used for keys + */ +#if defined(HAVE_LONG_LONG) && defined(SQL_C_UBIGINT) && \ + ( defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ) ) +typedef unsigned long long backsql_key_t; +#define BACKSQL_C_NUMID SQL_C_UBIGINT +#define BACKSQL_IDNUMFMT "%llu" +#define BACKSQL_STR2ID lutil_atoullx +#else /* ! HAVE_LONG_LONG || ! SQL_C_UBIGINT */ +typedef unsigned long backsql_key_t; +#define BACKSQL_C_NUMID SQL_C_ULONG +#define BACKSQL_IDNUMFMT "%lu" +#define BACKSQL_STR2ID lutil_atoulx +#endif /* ! HAVE_LONG_LONG */ + +/* + * define to enable support for syncprov overlay */ -#ifdef LDAP_DEVEL #define BACKSQL_SYNCPROV -#endif /* LDAP_DEVEL */ /* * define to the appropriate aliasing string @@ -227,8 +260,9 @@ typedef struct { * in quotes. This is especially true for those that do not * allow keywords used as aliases. */ -/* #define BACKSQL_ALIASING_QUOTE '"' */ -/* #define BACKSQL_ALIASING_QUOTE '\'' */ +#define BACKSQL_ALIASING_QUOTE "" +/* #define BACKSQL_ALIASING_QUOTE "\"" */ +/* #define BACKSQL_ALIASING_QUOTE "'" */ /* * API @@ -246,39 +280,10 @@ typedef struct backsql_api { void *ba_private; struct backsql_api *ba_next; + char **ba_argv; + int ba_argc; } backsql_api; -/* - * Entry ID structure - */ -typedef struct backsql_entryID { - /* #define BACKSQL_ARBITRARY_KEY to allow a non-numeric key. - * It is required by some special applications that use - * strings as keys for the main table. - * In this case, #define BACKSQL_MAX_KEY_LEN consistently - * with the key size definition */ -#ifdef BACKSQL_ARBITRARY_KEY - struct berval eid_id; - struct berval eid_keyval; -#define BACKSQL_MAX_KEY_LEN 64 -#else /* ! BACKSQL_ARBITRARY_KEY */ - /* The original numeric key is maintained as default. */ - unsigned long eid_id; - unsigned long eid_keyval; -#endif /* ! BACKSQL_ARBITRARY_KEY */ - - unsigned long eid_oc_id; - struct berval eid_dn; - struct berval eid_ndn; - struct backsql_entryID *eid_next; -} backsql_entryID; - -#ifdef BACKSQL_ARBITRARY_KEY -#define BACKSQL_ENTRYID_INIT { BER_BVNULL, BER_BVNULL, 0, BER_BVNULL, BER_BVNULL, NULL } -#else /* ! BACKSQL_ARBITRARY_KEY */ -#define BACKSQL_ENTRYID_INIT { 0, 0, 0, BER_BVNULL, BER_BVNULL, NULL } -#endif /* BACKSQL_ARBITRARY_KEY */ - /* * "structural" objectClass mapping structure */ @@ -302,7 +307,7 @@ typedef struct backsql_oc_map_rec { /* flags whether delete_proc is a function (whether back-sql * should bind first parameter as output for return code) */ int bom_expect_return; - unsigned long bom_id; + backsql_key_t bom_id; Avlnode *bom_attrs; AttributeDescription *bom_create_hint; } backsql_oc_map_rec; @@ -313,6 +318,7 @@ typedef struct backsql_oc_map_rec { typedef struct backsql_at_map_rec { /* Description of corresponding LDAP attribute type */ AttributeDescription *bam_ad; + AttributeDescription *bam_true_ad; /* ObjectClass if bam_ad is objectClass */ ObjectClass *bam_oc; @@ -333,6 +339,9 @@ typedef struct backsql_at_map_rec { /* for optimization purposes attribute load query * is preconstructed from parts on schemamap load time */ char *bam_query; +#ifdef BACKSQL_COUNTQUERY + char *bam_countquery; +#endif /* BACKSQL_COUNTQUERY */ /* following flags are bitmasks (first bit used for add_proc, * second - for delete_proc) */ /* order of parameters for procedures above; @@ -353,14 +362,14 @@ typedef struct backsql_at_map_rec { * (currently broken) */ /* #define BACKSQL_UPPERCASE_FILTER */ -#define BACKSQL_AT_CANUPPERCASE(at) ((at)->bam_sel_expr_u.bv_val) +#define BACKSQL_AT_CANUPPERCASE(at) ( !BER_BVISNULL( &(at)->bam_sel_expr_u ) ) /* defines to support bitmasks above */ #define BACKSQL_ADD 0x1 #define BACKSQL_DEL 0x2 -#define BACKSQL_IS_ADD(x) ( BACKSQL_ADD & (x) ) -#define BACKSQL_IS_DEL(x) ( BACKSQL_DEL & (x) ) +#define BACKSQL_IS_ADD(x) ( ( BACKSQL_ADD & (x) ) == BACKSQL_ADD ) +#define BACKSQL_IS_DEL(x) ( ( BACKSQL_DEL & (x) ) == BACKSQL_DEL ) #define BACKSQL_NCMP(v1,v2) ber_bvcmp((v1),(v2)) @@ -373,8 +382,53 @@ typedef struct berbuf { ber_len_t bb_len; } BerBuffer; -#define BB_NULL { { 0, NULL }, 0 } +#define BB_NULL { BER_BVNULL, 0 } +/* + * Entry ID structure + */ +typedef struct backsql_entryID { + /* #define BACKSQL_ARBITRARY_KEY to allow a non-numeric key. + * It is required by some special applications that use + * strings as keys for the main table. + * In this case, #define BACKSQL_MAX_KEY_LEN consistently + * with the key size definition */ +#ifdef BACKSQL_ARBITRARY_KEY + struct berval eid_id; + struct berval eid_keyval; +#define BACKSQL_MAX_KEY_LEN 64 +#else /* ! BACKSQL_ARBITRARY_KEY */ + /* The original numeric key is maintained as default. */ + backsql_key_t eid_id; + backsql_key_t eid_keyval; +#endif /* ! BACKSQL_ARBITRARY_KEY */ + + backsql_key_t eid_oc_id; + backsql_oc_map_rec *eid_oc; + struct berval eid_dn; + struct berval eid_ndn; + struct backsql_entryID *eid_next; +} backsql_entryID; + +#ifdef BACKSQL_ARBITRARY_KEY +#define BACKSQL_ENTRYID_INIT { BER_BVNULL, BER_BVNULL, 0, NULL, BER_BVNULL, BER_BVNULL, NULL } +#else /* ! BACKSQL_ARBITRARY_KEY */ +#define BACKSQL_ENTRYID_INIT { 0, 0, 0, NULL, BER_BVNULL, BER_BVNULL, NULL } +#endif /* BACKSQL_ARBITRARY_KEY */ + +/* the function must collect the entry associated to nbase */ +#define BACKSQL_ISF_GET_ID 0x1U +#define BACKSQL_ISF_GET_ENTRY ( 0x2U | BACKSQL_ISF_GET_ID ) +#define BACKSQL_ISF_GET_OC ( 0x4U | BACKSQL_ISF_GET_ID ) +#define BACKSQL_ISF_MATCHED 0x8U +#define BACKSQL_IS_GET_ID(f) \ + ( ( (f) & BACKSQL_ISF_GET_ID ) == BACKSQL_ISF_GET_ID ) +#define BACKSQL_IS_GET_ENTRY(f) \ + ( ( (f) & BACKSQL_ISF_GET_ENTRY ) == BACKSQL_ISF_GET_ENTRY ) +#define BACKSQL_IS_GET_OC(f) \ + ( ( (f) & BACKSQL_ISF_GET_OC ) == BACKSQL_ISF_GET_OC ) +#define BACKSQL_IS_MATCHED(f) \ + ( ( (f) & BACKSQL_ISF_MATCHED ) == BACKSQL_ISF_MATCHED ) typedef struct backsql_srch_info { Operation *bsi_op; SlapReply *bsi_rs; @@ -388,6 +442,10 @@ typedef struct backsql_srch_info { #define BSQL_SF_FILTER_ENTRYUUID 0x0020U #define BSQL_SF_FILTER_ENTRYCSN 0x0040U #define BSQL_SF_RETURN_ENTRYUUID (BSQL_SF_FILTER_ENTRYUUID << 8) +#define BSQL_ISF(bsi, f) ( ( (bsi)->bsi_flags & f ) == f ) +#define BSQL_ISF_ALL_USER(bsi) BSQL_ISF(bsi, BSQL_SF_ALL_USER) +#define BSQL_ISF_ALL_OPER(bsi) BSQL_ISF(bsi, BSQL_SF_ALL_OPER) +#define BSQL_ISF_ALL_ATTRS(bsi) BSQL_ISF(bsi, BSQL_SF_ALL_ATTRS) struct berval *bsi_base_ndn; int bsi_use_subtree_shortcut; @@ -400,15 +458,12 @@ typedef struct backsql_srch_info { * is used */ #define BACKSQL_SCOPE_BASE_LIKE ( LDAP_SCOPE_BASE | 0x1000 ) Filter *bsi_filter; - int bsi_slimit, - bsi_tlimit; time_t bsi_stoptime; backsql_entryID *bsi_id_list, **bsi_id_listtail, *bsi_c_eid; int bsi_n_candidates; - int bsi_abandon; int bsi_status; backsql_oc_map_rec *bsi_oc; @@ -426,7 +481,7 @@ typedef struct backsql_srch_info { /* * Backend private data structure */ -typedef struct { +typedef struct backsql_info { char *sql_dbhost; int sql_dbport; char *sql_dbuser; @@ -440,14 +495,16 @@ typedef struct { */ struct berval sql_subtree_cond; struct berval sql_children_cond; - char *sql_oc_query, - *sql_at_query; - char *sql_insentry_stmt, - *sql_delentry_stmt, - *sql_delobjclasses_stmt, - *sql_delreferrals_stmt; + struct berval sql_dn_match_cond; + char *sql_oc_query; + char *sql_at_query; + char *sql_insentry_stmt; + char *sql_delentry_stmt; + char *sql_renentry_stmt; + char *sql_delobjclasses_stmt; char *sql_id_query; char *sql_has_children_query; + char *sql_list_children_query; MatchingRule *sql_caseIgnoreMatch; MatchingRule *sql_telephoneNumberMatch; @@ -455,9 +512,15 @@ typedef struct { struct berval sql_upper_func; struct berval sql_upper_func_open; struct berval sql_upper_func_close; + struct berval sql_strcast_func; BerVarray sql_concat_func; + char *sql_concat_patt; - struct berval sql_strcast_func; + struct berval sql_aliasing; + struct berval sql_aliasing_quote; + struct berval sql_dn_oc_aliasing; + + AttributeName *sql_anlist; unsigned int sql_flags; #define BSQLF_SCHEMA_LOADED 0x0001 @@ -469,45 +532,65 @@ typedef struct { #define BSQLF_USE_REVERSE_DN 0x0040 #define BSQLF_ALLOW_ORPHANS 0x0080 #define BSQLF_USE_SUBTREE_SHORTCUT 0x0100 +#define BSQLF_FETCH_ALL_USERATTRS 0x0200 +#define BSQLF_FETCH_ALL_OPATTRS 0x0400 +#define BSQLF_FETCH_ALL_ATTRS (BSQLF_FETCH_ALL_USERATTRS|BSQLF_FETCH_ALL_OPATTRS) +#define BSQLF_CHECK_SCHEMA 0x0800 +#define BSQLF_AUTOCOMMIT_ON 0x1000 + +#define BACKSQL_ISF(si, f) \ + (((si)->sql_flags & f) == f) #define BACKSQL_SCHEMA_LOADED(si) \ - ((si)->sql_flags & BSQLF_SCHEMA_LOADED) + BACKSQL_ISF(si, BSQLF_SCHEMA_LOADED) #define BACKSQL_UPPER_NEEDS_CAST(si) \ - ((si)->sql_flags & BSQLF_UPPER_NEEDS_CAST) + BACKSQL_ISF(si, BSQLF_UPPER_NEEDS_CAST) #define BACKSQL_CREATE_NEEDS_SELECT(si) \ - ((si)->sql_flags & BSQLF_CREATE_NEEDS_SELECT) + BACKSQL_ISF(si, BSQLF_CREATE_NEEDS_SELECT) #define BACKSQL_FAIL_IF_NO_MAPPING(si) \ - ((si)->sql_flags & BSQLF_FAIL_IF_NO_MAPPING) + BACKSQL_ISF(si, BSQLF_FAIL_IF_NO_MAPPING) #define BACKSQL_HAS_LDAPINFO_DN_RU(si) \ - ((si)->sql_flags & BSQLF_HAS_LDAPINFO_DN_RU) + BACKSQL_ISF(si, BSQLF_HAS_LDAPINFO_DN_RU) #define BACKSQL_DONTCHECK_LDAPINFO_DN_RU(si) \ - ((si)->sql_flags & BSQLF_DONTCHECK_LDAPINFO_DN_RU) + BACKSQL_ISF(si, BSQLF_DONTCHECK_LDAPINFO_DN_RU) #define BACKSQL_USE_REVERSE_DN(si) \ - ((si)->sql_flags & BSQLF_USE_REVERSE_DN) + BACKSQL_ISF(si, BSQLF_USE_REVERSE_DN) #define BACKSQL_CANUPPERCASE(si) \ (!BER_BVISNULL( &(si)->sql_upper_func )) #define BACKSQL_ALLOW_ORPHANS(si) \ - ((si)->sql_flags & BSQLF_ALLOW_ORPHANS) + BACKSQL_ISF(si, BSQLF_ALLOW_ORPHANS) #define BACKSQL_USE_SUBTREE_SHORTCUT(si) \ - ((si)->sql_flags & BSQLF_USE_SUBTREE_SHORTCUT) + BACKSQL_ISF(si, BSQLF_USE_SUBTREE_SHORTCUT) +#define BACKSQL_FETCH_ALL_USERATTRS(si) \ + BACKSQL_ISF(si, BSQLF_FETCH_ALL_USERATTRS) +#define BACKSQL_FETCH_ALL_OPATTRS(si) \ + BACKSQL_ISF(si, BSQLF_FETCH_ALL_OPATTRS) +#define BACKSQL_FETCH_ALL_ATTRS(si) \ + BACKSQL_ISF(si, BSQLF_FETCH_ALL_ATTRS) +#define BACKSQL_CHECK_SCHEMA(si) \ + BACKSQL_ISF(si, BSQLF_CHECK_SCHEMA) +#define BACKSQL_AUTOCOMMIT_ON(si) \ + BACKSQL_ISF(si, BSQLF_AUTOCOMMIT_ON) Entry *sql_baseObject; + char *sql_base_ob_file; #ifdef BACKSQL_ARBITRARY_KEY #define BACKSQL_BASEOBJECT_IDSTR "baseObject" #define BACKSQL_BASEOBJECT_KEYVAL BACKSQL_BASEOBJECT_IDSTR #define BACKSQL_IS_BASEOBJECT_ID(id) (bvmatch((id), &backsql_baseObject_bv)) #else /* ! BACKSQL_ARBITRARY_KEY */ #define BACKSQL_BASEOBJECT_ID 0 -#define BACKSQL_BASEOBJECT_IDSTR "0" +#define BACKSQL_BASEOBJECT_IDSTR LDAP_XSTRING(BACKSQL_BASEOBJECT_ID) #define BACKSQL_BASEOBJECT_KEYVAL 0 #define BACKSQL_IS_BASEOBJECT_ID(id) (*(id) == BACKSQL_BASEOBJECT_ID) #endif /* ! BACKSQL_ARBITRARY_KEY */ #define BACKSQL_BASEOBJECT_OC 0 Avlnode *sql_db_conns; + SQLHDBC sql_dbh; + ldap_pvt_thread_mutex_t sql_dbconn_mutex; Avlnode *sql_oc_by_oc; Avlnode *sql_oc_by_id; - ldap_pvt_thread_mutex_t sql_dbconn_mutex; ldap_pvt_thread_mutex_t sql_schema_mutex; SQLHENV sql_db_env; @@ -531,5 +614,18 @@ typedef struct { #define BACKSQL_SANITIZE_ERROR( rc ) \ ( BACKSQL_LEGAL_ERROR( (rc) ) ? (rc) : LDAP_OTHER ) +#define BACKSQL_IS_BINARY(ct) \ + ( (ct) == SQL_BINARY \ + || (ct) == SQL_VARBINARY \ + || (ct) == SQL_LONGVARBINARY) + +#ifdef BACKSQL_ARBITRARY_KEY +#define BACKSQL_IDFMT "%s" +#define BACKSQL_IDARG(arg) ((arg).bv_val) +#else /* ! BACKSQL_ARBITRARY_KEY */ +#define BACKSQL_IDFMT BACKSQL_IDNUMFMT +#define BACKSQL_IDARG(arg) (arg) +#endif /* ! BACKSQL_ARBITRARY_KEY */ + #endif /* __BACKSQL_H__ */