]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/back-sql.h
remove dnNormalize2
[openldap] / servers / slapd / back-sql / back-sql.h
1 /*
2  *       Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
3  *
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.
8  */
9 /*
10  *       Copyright 2002, Pierangelo Masarati <ando@OpenLDAP.org>.
11  *       All rights reserved.
12  *
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.
17  *
18  *       This copyright statement cannot be altered.
19  */
20 /*
21  *       The following changes have been addressed:
22  *       
23  * Enhancements:
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
28  *     mapping lookup
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
56  * 
57  * Todo:
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
61  *     in dn match)
62  *   - implement a backsql_normalize() function to replace the upper()
63  *     conversion routines
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?)
69  */
70
71 #ifndef __BACKSQL_H__
72 #define __BACKSQL_H__
73
74 #include "external.h"
75 #include "sql-types.h"
76
77 /*
78  * Better use the standard length of 8192 (as of servers/slapd/dn.c) ?
79  */
80 #define BACKSQL_MAX_DN_LEN      255
81
82 /*
83  * define to enable very extensive trace logging (debug only)
84  */
85 #undef BACKSQL_TRACE
86
87 typedef struct {
88         char            *dbhost;
89         int             dbport;
90         char            *dbuser;
91         char            *dbpasswd;
92         char            *dbname;
93         /*
94          * SQL condition for subtree searches differs in syntax:
95          * "LIKE CONCAT('%',?)" or "LIKE '%'+?" or "LIKE '%'||?"
96          * or smth else 
97          */
98         struct berval   subtree_cond;
99         struct berval   children_cond;
100         char            *oc_query, *at_query;
101         char            *insentry_query,*delentry_query;
102         char            *id_query;
103         char            *has_children_query;
104
105         MatchingRule    *bi_caseIgnoreMatch;
106
107         struct berval   upper_func;
108         struct berval   upper_func_open;
109         struct berval   upper_func_close;
110         BerVarray       concat_func;
111
112         unsigned int    bsql_flags;
113 #define BSQLF_SCHEMA_LOADED             0x0001
114 #define BSQLF_UPPER_NEEDS_CAST          0x0002
115 #define BSQLF_CREATE_NEEDS_SELECT       0x0004
116 #define BSQLF_FAIL_IF_NO_MAPPING        0x0008
117 #define BSQLF_HAS_LDAPINFO_DN_RU        0x0010
118 #define BSQLF_DONTCHECK_LDAPINFO_DN_RU  0x0020
119 #define BSQLF_USE_REVERSE_DN            0x0040
120
121 #define BACKSQL_SCHEMA_LOADED(si) \
122         ((si)->bsql_flags & BSQLF_SCHEMA_LOADED)
123 #define BACKSQL_UPPER_NEEDS_CAST(si) \
124         ((si)->bsql_flags & BSQLF_UPPER_NEEDS_CAST)
125 #define BACKSQL_CREATE_NEEDS_SELECT(si) \
126         ((si)->bsql_flags & BSQLF_CREATE_NEEDS_SELECT)
127 #define BACKSQL_FAIL_IF_NO_MAPPING(si) \
128         ((si)->bsql_flags & BSQLF_FAIL_IF_NO_MAPPING)
129 #define BACKSQL_HAS_LDAPINFO_DN_RU(si) \
130         ((si)->bsql_flags & BSQLF_HAS_LDAPINFO_DN_RU)
131 #define BACKSQL_DONTCHECK_LDAPINFO_DN_RU(si) \
132         ((si)->bsql_flags & BSQLF_DONTCHECK_LDAPINFO_DN_RU)
133 #define BACKSQL_USE_REVERSE_DN(si) \
134         ((si)->bsql_flags & BSQLF_USE_REVERSE_DN)
135         
136         struct berval   strcast_func;
137         Avlnode         *db_conns;
138         Avlnode         *oc_by_oc;
139         Avlnode         *oc_by_id;
140         ldap_pvt_thread_mutex_t         dbconn_mutex;
141         ldap_pvt_thread_mutex_t         schema_mutex;
142         SQLHENV         db_env;
143 } backsql_info;
144
145 #define BACKSQL_SUCCESS( rc ) \
146         ( (rc) == SQL_SUCCESS || (rc) == SQL_SUCCESS_WITH_INFO )
147
148 #endif /* __BACKSQL_H__ */
149