]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/proto-sql.h
allow backwards compatibility for 'T' option (single char)
[openldap] / servers / slapd / back-sql / proto-sql.h
1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
2  *
3  * Copyright 1999-2004 The OpenLDAP Foundation.
4  * Portions Copyright 1999 Dmitry Kovalev.
5  * Portions Copyright 2002 Pierangelo Mararati.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Dmitry Kovalev for inclusion
18  * by OpenLDAP Software.  Additional significant contributors include
19  *    Pierangelo Mararati
20  */
21
22 /*
23  * The following changes have been addressed:
24  *       
25  * Enhancements:
26  *   - re-styled code for better readability
27  *   - upgraded backend API to reflect recent changes
28  *   - LDAP schema is checked when loading SQL/LDAP mapping
29  *   - AttributeDescription/ObjectClass pointers used for more efficient
30  *     mapping lookup
31  *   - bervals used where string length is required often
32  *   - atomized write operations by committing at the end of each operation
33  *     and defaulting connection closure to rollback
34  *   - added LDAP access control to write operations
35  *   - fully implemented modrdn (with rdn attrs change, deleteoldrdn,
36  *     access check, parent/children check and more)
37  *   - added parent access control, children control to delete operation
38  *   - added structuralObjectClass operational attribute check and
39  *     value return on search
40  *   - added hasSubordinate operational attribute on demand
41  *   - search limits are appropriately enforced
42  *   - function backsql_strcat() has been made more efficient
43  *   - concat function has been made configurable by means of a pattern
44  *   - added config switches:
45  *       - fail_if_no_mapping   write operations fail if there is no mapping
46  *       - has_ldapinfo_dn_ru   overrides autodetect
47  *       - concat_pattern       a string containing two '?' is used
48  *                              (note that "?||?" should be more portable
49  *                              than builtin function "CONCAT(?,?)")
50  *       - strcast_func         cast of string constants in "SELECT DISTINCT
51  *                              statements (needed by PostgreSQL)
52  *       - upper_needs_cast     cast the argument of upper when required
53  *                              (basically when building dn substring queries)
54  *   - added noop control
55  *   - added values return filter control
56  *   - hasSubordinate can be used in search filters (with limitations)
57  *   - eliminated oc->name; use oc->oc->soc_cname instead
58  * 
59  * Todo:
60  *   - add security checks for SQL statements that can be injected (?)
61  *   - re-test with previously supported RDBMs
62  *   - replace dn_ru and so with normalized dn (no need for upper() and so
63  *     in dn match)
64  *   - implement a backsql_normalize() function to replace the upper()
65  *     conversion routines
66  *   - note that subtree deletion, subtree renaming and so could be easily
67  *     implemented (rollback and consistency checks are available :)
68  *   - implement "lastmod" and other operational stuff (ldap_entries table ?)
69  *   - check how to allow multiple operations with one statement, to remove
70  *     BACKSQL_REALLOC_STMT from modify.c (a more recent unixODBC lib?)
71  */
72
73 #ifndef PROTO_SQL_H
74 #define PROTO_SQL_H
75
76 #include "back-sql.h"
77 #include "sql-types.h"
78
79 /*
80  * add.c
81  */
82 int backsql_modify_internal(
83         Operation               *op,
84         SlapReply               *rs,
85         SQLHDBC                 dbh, 
86         backsql_oc_map_rec      *oc,
87         backsql_entryID         *e_id,
88         Modifications           *modlist );
89
90 /*
91  * api.c
92  */
93 int backsql_api_config( backsql_info *si, const char *name );
94 int backsql_api_register( backsql_api *ba );
95 int backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn );
96 int backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn );
97
98 /*
99  * entry-id.c
100  */
101
102 /* stores in *id the ID in table ldap_entries corresponding to DN, if any */
103 int backsql_dn2id( backsql_info *bi, backsql_entryID *id,
104                 SQLHDBC dbh, struct berval *dn );
105
106 /* stores in *nchildren the count of children for an entry */
107 int backsql_count_children( backsql_info *bi, SQLHDBC dbh,
108                 struct berval *dn, unsigned long *nchildren );
109
110 /* returns LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE if the entry corresponding
111  * to DN has/has not children */
112 int backsql_has_children( backsql_info *bi, SQLHDBC dbh, struct berval *dn );
113
114 /* frees *id and returns next in list */
115 backsql_entryID *backsql_free_entryID( backsql_entryID *id, int freeit );
116
117 /* turns an ID into an entry */
118 Entry *backsql_id2entry( backsql_srch_info *bsi, Entry *e, 
119                 backsql_entryID *id );
120
121 /*
122  * schema-map.c
123  */
124
125 int backsql_load_schema_map( backsql_info *si, SQLHDBC dbh );
126
127 backsql_oc_map_rec *backsql_oc2oc( backsql_info *si, ObjectClass *oc );
128
129 backsql_oc_map_rec *backsql_id2oc( backsql_info *si, unsigned long id );
130
131 backsql_oc_map_rec * backsql_name2oc( backsql_info *si,
132                 struct berval *oc_name );
133
134 backsql_at_map_rec *backsql_ad2at( backsql_oc_map_rec *objclass,
135                 AttributeDescription *ad );
136
137 int backsql_supad2at( backsql_oc_map_rec *objclass,
138                 AttributeDescription *supad, backsql_at_map_rec ***pret );
139
140 int backsql_destroy_schema_map( backsql_info *si );
141
142 /*
143  * search.c
144  */
145
146 void backsql_init_search( backsql_srch_info *bsi, 
147                 struct berval *nbase, int scope, int slimit, int tlimit,
148                 time_t stoptime, Filter *filter, SQLHDBC dbh,
149                 Operation *op, SlapReply *rs, AttributeName *attrs );
150
151 /*
152  * sql-wrap.h
153  */
154
155 RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char* query, int timeout );
156
157 #define backsql_BindParamStr( sth, par_ind, str, maxlen )               \
158         SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),               \
159                         SQL_PARAM_INPUT,                                \
160                         SQL_C_CHAR, SQL_VARCHAR,                        \
161                         (SQLUINTEGER)(maxlen), 0, (SQLPOINTER)(str),    \
162                         (SQLUINTEGER)(maxlen), NULL )
163
164 #define backsql_BindParamID( sth, par_ind, id )                         \
165         SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),               \
166                         SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,      \
167                         0, 0, (SQLPOINTER)(id), 0, (SQLINTEGER*)NULL )
168
169 RETCODE backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row );
170
171 RETCODE backsql_FreeRow( BACKSQL_ROW_NTS *row );
172
173 void backsql_PrintErrors( SQLHENV henv, SQLHDBC hdbc, SQLHSTMT sth, int rc );
174
175 int backsql_init_db_env( backsql_info *si );
176
177 int backsql_free_db_env( backsql_info *si );
178
179 int backsql_get_db_conn( Operation *op, SQLHDBC *dbh );
180
181 int backsql_free_db_conn( Operation *op );
182
183 /*
184  * util.c
185  */
186
187 extern char 
188         backsql_def_oc_query[],
189         backsql_def_needs_select_oc_query[],
190         backsql_def_at_query[],
191         backsql_def_delentry_query[],
192         backsql_def_insentry_query[],
193         backsql_def_subtree_cond[],
194         backsql_def_upper_subtree_cond[],
195         backsql_id_query[],
196         backsql_def_concat_func[];
197 extern char 
198         backsql_check_dn_ru_query[];
199
200 struct berbuf * backsql_strcat( struct berbuf *dest, ... );
201 struct berbuf * backsql_strfcat( struct berbuf *dest, const char *fmt, ... );
202
203 int backsql_entry_addattr( Entry *e, struct berval *at_name, 
204                 struct berval *at_val, void *memctx );
205
206 int backsql_merge_from_clause( struct berbuf *dest_from, 
207                 struct berval *src_from );
208
209 int backsql_split_pattern( const char *pattern, BerVarray *split_pattern,
210                 int expected );
211
212 int backsql_prepare_pattern( BerVarray split_pattern, BerVarray values,
213                 struct berval *res );
214
215 #endif /* PROTO_SQL_H */