]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/back-sql.h
now I remember why I introduced the 'has_ldapinfo_dn_ru' flag
[openldap] / servers / slapd / back-sql / back-sql.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2004 The OpenLDAP Foundation.
5  * Portions Copyright 1999 Dmitry Kovalev.
6  * Portions Copyright 2002 Pierangelo Mararati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Dmitry Kovalev for inclusion
19  * by OpenLDAP Software.  Additional significant contributors include
20  *    Pierangelo Mararati
21  */
22
23 /*
24  * The following changes have been addressed:
25  *       
26  * Enhancements:
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
31  *     mapping lookup
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
59  * 
60  * Todo:
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
64  *     in dn match)
65  *   - implement a backsql_normalize() function to replace the upper()
66  *     conversion routines
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?)
72  */
73
74 #ifndef __BACKSQL_H__
75 #define __BACKSQL_H__
76
77 #include "external.h"
78 #include "sql-types.h"
79
80 /*
81  * Better use the standard length of 8192 (as of servers/slapd/dn.c) ?
82  */
83 #define BACKSQL_MAX_DN_LEN      255
84
85 /*
86  * define to enable very extensive trace logging (debug only)
87  */
88 #undef BACKSQL_TRACE
89
90 typedef struct {
91         char            *dbhost;
92         int             dbport;
93         char            *dbuser;
94         char            *dbpasswd;
95         char            *dbname;
96         /*
97          * SQL condition for subtree searches differs in syntax:
98          * "LIKE CONCAT('%',?)" or "LIKE '%'+?" or "LIKE '%'||?"
99          * or smth else 
100          */
101         struct berval   subtree_cond;
102         struct berval   children_cond;
103         char            *oc_query, *at_query;
104         char            *insentry_query,*delentry_query;
105         char            *id_query;
106         char            *has_children_query;
107
108         MatchingRule    *bi_caseIgnoreMatch;
109
110         struct berval   upper_func;
111         struct berval   upper_func_open;
112         struct berval   upper_func_close;
113         BerVarray       concat_func;
114
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
123
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)
138         
139         struct berval   strcast_func;
140         Avlnode         *db_conns;
141         Avlnode         *oc_by_oc;
142         Avlnode         *oc_by_id;
143         ldap_pvt_thread_mutex_t         dbconn_mutex;
144         ldap_pvt_thread_mutex_t         schema_mutex;
145         SQLHENV         db_env;
146 } backsql_info;
147
148 #define BACKSQL_SUCCESS( rc ) \
149         ( (rc) == SQL_SUCCESS || (rc) == SQL_SUCCESS_WITH_INFO )
150
151 #endif /* __BACKSQL_H__ */
152