2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
6 * Portions Copyright 2002 Pierangelo Mararati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Dmitry Kovalev for inclusion
19 * by OpenLDAP Software. Additional significant contributors include
24 * The following changes have been addressed:
27 * - re-styled code for better readability
28 * - upgraded backend API to reflect recent changes
29 * - LDAP schema is checked when loading SQL/LDAP mapping
30 * - AttributeDescription/ObjectClass pointers used for more efficient
32 * - bervals used where string length is required often
33 * - atomized write operations by committing at the end of each operation
34 * and defaulting connection closure to rollback
35 * - added LDAP access control to write operations
36 * - fully implemented modrdn (with rdn attrs change, deleteoldrdn,
37 * access check, parent/children check and more)
38 * - added parent access control, children control to delete operation
39 * - added structuralObjectClass operational attribute check and
40 * value return on search
41 * - added hasSubordinate operational attribute on demand
42 * - search limits are appropriately enforced
43 * - function backsql_strcat() has been made more efficient
44 * - concat function has been made configurable by means of a pattern
45 * - added config switches:
46 * - fail_if_no_mapping write operations fail if there is no mapping
47 * - has_ldapinfo_dn_ru overrides autodetect
48 * - concat_pattern a string containing two '?' is used
49 * (note that "?||?" should be more portable
50 * than builtin function "CONCAT(?,?)")
51 * - strcast_func cast of string constants in "SELECT DISTINCT
52 * statements (needed by PostgreSQL)
53 * - upper_needs_cast cast the argument of upper when required
54 * (basically when building dn substring queries)
55 * - added noop control
56 * - added values return filter control
57 * - hasSubordinate can be used in search filters (with limitations)
58 * - eliminated oc->name; use oc->oc->soc_cname instead
61 * - add security checks for SQL statements that can be injected (?)
62 * - re-test with previously supported RDBMs
63 * - replace dn_ru and so with normalized dn (no need for upper() and so
65 * - implement a backsql_normalize() function to replace the upper()
67 * - note that subtree deletion, subtree renaming and so could be easily
68 * implemented (rollback and consistency checks are available :)
69 * - implement "lastmod" and other operational stuff (ldap_entries table ?)
70 * - check how to allow multiple operations with one statement, to remove
71 * BACKSQL_REALLOC_STMT from modify.c (a more recent unixODBC lib?)
78 #include "sql-types.h"
81 * Better use the standard length of 8192 (as of servers/slapd/dn.c) ?
83 #define BACKSQL_MAX_DN_LEN 255
86 * define to enable very extensive trace logging (debug only)
97 * SQL condition for subtree searches differs in syntax:
98 * "LIKE CONCAT('%',?)" or "LIKE '%'+?" or "LIKE '%'||?"
101 struct berval subtree_cond;
102 struct berval children_cond;
103 char *oc_query, *at_query;
104 char *insentry_query,*delentry_query;
106 char *has_children_query;
108 MatchingRule *bi_caseIgnoreMatch;
110 struct berval upper_func;
111 struct berval upper_func_open;
112 struct berval upper_func_close;
113 BerVarray concat_func;
115 unsigned int bsql_flags;
116 #define BSQLF_SCHEMA_LOADED 0x0001
117 #define BSQLF_UPPER_NEEDS_CAST 0x0002
118 #define BSQLF_CREATE_NEEDS_SELECT 0x0004
119 #define BSQLF_FAIL_IF_NO_MAPPING 0x0008
120 #define BSQLF_HAS_LDAPINFO_DN_RU 0x0010
121 #define BSQLF_DONTCHECK_LDAPINFO_DN_RU 0x0020
122 #define BSQLF_USE_REVERSE_DN 0x0040
124 #define BACKSQL_SCHEMA_LOADED(si) \
125 ((si)->bsql_flags & BSQLF_SCHEMA_LOADED)
126 #define BACKSQL_UPPER_NEEDS_CAST(si) \
127 ((si)->bsql_flags & BSQLF_UPPER_NEEDS_CAST)
128 #define BACKSQL_CREATE_NEEDS_SELECT(si) \
129 ((si)->bsql_flags & BSQLF_CREATE_NEEDS_SELECT)
130 #define BACKSQL_FAIL_IF_NO_MAPPING(si) \
131 ((si)->bsql_flags & BSQLF_FAIL_IF_NO_MAPPING)
132 #define BACKSQL_HAS_LDAPINFO_DN_RU(si) \
133 ((si)->bsql_flags & BSQLF_HAS_LDAPINFO_DN_RU)
134 #define BACKSQL_DONTCHECK_LDAPINFO_DN_RU(si) \
135 ((si)->bsql_flags & BSQLF_DONTCHECK_LDAPINFO_DN_RU)
136 #define BACKSQL_USE_REVERSE_DN(si) \
137 ((si)->bsql_flags & BSQLF_USE_REVERSE_DN)
139 struct berval strcast_func;
143 ldap_pvt_thread_mutex_t dbconn_mutex;
144 ldap_pvt_thread_mutex_t schema_mutex;
148 #define BACKSQL_SUCCESS( rc ) \
149 ( (rc) == SQL_SUCCESS || (rc) == SQL_SUCCESS_WITH_INFO )
151 #endif /* __BACKSQL_H__ */