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