]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/back-sql.h
Final run of changes to back-sql; IBM db2 support has been tested.
[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  * 
53  * Todo:
54  *   - add security checks for SQL statements that can be injected (?)
55  *   - re-test with previously supported RDBMs
56  *   - replace dn_ru and so with normalized dn (no need for upper() and so
57  *     in dn match)
58  *   - implement a backsql_normalize() function to replace the upper()
59  *     conversion routines
60  *   - note that subtree deletion, subtree renaming and so could be easily
61  *     implemented (rollback and consistency checks are available :)
62  *   - implement "lastmod" and other operational stuff (ldap_entries table ?)
63  *   - check how to allow multiple operations with one statement, to remove
64  *     BACKSQL_REALLOC_STMT from modify.c (a more recent unixODBC lib?)
65  */
66
67 #ifndef __BACKSQL_H__
68 #define __BACKSQL_H__
69
70 #include "external.h"
71 #include "sql-types.h"
72
73 /*
74  * Better use the standard length of 8192 (as of servers/slapd/dn.c) ?
75  */
76 #define BACKSQL_MAX_DN_LEN      255
77
78 /*
79  * define to enable very extensive trace logging (debug only)
80  */
81 #undef BACKSQL_TRACE
82
83
84 typedef struct {
85         char            *dbhost;
86         int             dbport;
87         char            *dbuser;
88         char            *dbpasswd;
89         char            *dbname;
90         /*
91          * SQL condition for subtree searches differs in syntax:
92          * "LIKE CONCAT('%',?)" or "LIKE '%'+?" or "LIKE '%'||?"
93          * or smth else 
94          */
95         struct berval   subtree_cond;
96         struct berval   children_cond;
97         char            *oc_query, *at_query;
98         char            *insentry_query,*delentry_query;
99         char            *id_query;
100         char            *has_children_query;
101         struct berval   upper_func;
102         struct berval   upper_func_open;
103         struct berval   upper_func_close;
104         BerVarray       concat_func;
105
106         unsigned int    bsql_flags;
107 #define BSQLF_SCHEMA_LOADED             0x0001
108 #define BSQLF_UPPER_NEEDS_CAST          0x0002
109 #define BSQLF_CREATE_NEEDS_SELECT       0x0004
110 #define BSQLF_FAIL_IF_NO_MAPPING        0x0008
111 #define BSQLF_HAS_LDAPINFO_DN_RU        0x0010
112 #define BSQLF_DONTCHECK_LDAPINFO_DN_RU  0x0020
113 #define BSQLF_USE_REVERSE_DN            0x0040
114
115 #define BACKSQL_SCHEMA_LOADED(si) \
116         ((si)->bsql_flags & BSQLF_SCHEMA_LOADED)
117 #define BACKSQL_UPPER_NEEDS_CAST(si) \
118         ((si)->bsql_flags & BSQLF_UPPER_NEEDS_CAST)
119 #define BACKSQL_CREATE_NEEDS_SELECT(si) \
120         ((si)->bsql_flags & BSQLF_CREATE_NEEDS_SELECT)
121 #define BACKSQL_FAIL_IF_NO_MAPPING(si) \
122         ((si)->bsql_flags & BSQLF_FAIL_IF_NO_MAPPING)
123 #define BACKSQL_HAS_LDAPINFO_DN_RU(si) \
124         ((si)->bsql_flags & BSQLF_HAS_LDAPINFO_DN_RU)
125 #define BACKSQL_DONTCHECK_LDAPINFO_DN_RU(si) \
126         ((si)->bsql_flags & BSQLF_DONTCHECK_LDAPINFO_DN_RU)
127 #define BACKSQL_USE_REVERSE_DN(si) \
128         ((si)->bsql_flags & BSQLF_USE_REVERSE_DN)
129         
130         struct berval   strcast_func;
131         Avlnode         *db_conns;
132         Avlnode         *oc_by_oc;
133         Avlnode         *oc_by_id;
134         ldap_pvt_thread_mutex_t         dbconn_mutex;
135         ldap_pvt_thread_mutex_t         schema_mutex;
136         SQLHENV         db_env;
137 } backsql_info;
138
139 #define BACKSQL_SUCCESS( rc ) \
140         ( (rc) == SQL_SUCCESS || (rc) == SQL_SUCCESS_WITH_INFO )
141
142 #endif /* __BACKSQL_H__ */
143