smbd: Implement FSCTL_DELETE_REPARSE_POINT
[samba.git] / source3 / include / tldap.h
1 /*
2    Unix SMB/CIFS implementation.
3    Infrastructure for async ldap client requests
4    Copyright (C) Volker Lendecke 2009
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __TLDAP_H__
21 #define __TLDAP_H__
22
23 #include "replace.h"
24 #include <talloc.h>
25 #include <tevent.h>
26 #include "lib/util/data_blob.h"
27
28 struct tldap_context;
29 struct tldap_message;
30
31 struct tldap_control {
32         const char *oid;
33         DATA_BLOB value;
34         bool critical;
35 };
36
37 struct tldap_attribute {
38         char *name;
39         int num_values;
40         DATA_BLOB *values;
41 };
42
43 struct tldap_mod {
44         int mod_op;
45         char *attribute;
46         int num_values;
47         DATA_BLOB *values;
48 };
49
50 #if defined(HAVE_IMMEDIATE_STRUCTURES)
51 typedef struct { uint8_t rc; } TLDAPRC;
52 #define TLDAP_RC(x) ((TLDAPRC){.rc = x})
53 #define TLDAP_RC_V(x) ((x).rc)
54 #else
55 typedef uint8_t TLDAPRC;
56 #define TLDAP_RC(x) (x)
57 #define TLDAP_RC_V(x) (x)
58 #endif
59
60 #define TLDAP_RC_EQUAL(x,y) (TLDAP_RC_V(x)==TLDAP_RC_V(y))
61 #define TLDAP_RC_IS_SUCCESS(x) TLDAP_RC_EQUAL(x,TLDAP_SUCCESS)
62
63 #define TLDAP_SUCCESS TLDAP_RC(0x00)
64 #define TLDAP_OPERATIONS_ERROR TLDAP_RC(0x01)
65 #define TLDAP_PROTOCOL_ERROR TLDAP_RC(0x02)
66 #define TLDAP_TIMELIMIT_EXCEEDED TLDAP_RC(0x03)
67 #define TLDAP_SIZELIMIT_EXCEEDED TLDAP_RC(0x04)
68 #define TLDAP_COMPARE_FALSE TLDAP_RC(0x05)
69 #define TLDAP_COMPARE_TRUE TLDAP_RC(0x06)
70 #define TLDAP_STRONG_AUTH_NOT_SUPPORTED TLDAP_RC(0x07)
71 #define TLDAP_STRONG_AUTH_REQUIRED TLDAP_RC(0x08)
72 #define TLDAP_REFERRAL TLDAP_RC(0x0a)
73 #define TLDAP_ADMINLIMIT_EXCEEDED TLDAP_RC(0x0b)
74 #define TLDAP_UNAVAILABLE_CRITICAL_EXTENSION TLDAP_RC(0x0c)
75 #define TLDAP_CONFIDENTIALITY_REQUIRED TLDAP_RC(0x0d)
76 #define TLDAP_SASL_BIND_IN_PROGRESS TLDAP_RC(0x0e)
77 #define TLDAP_NO_SUCH_ATTRIBUTE TLDAP_RC(0x10)
78 #define TLDAP_UNDEFINED_TYPE TLDAP_RC(0x11)
79 #define TLDAP_INAPPROPRIATE_MATCHING TLDAP_RC(0x12)
80 #define TLDAP_CONSTRAINT_VIOLATION TLDAP_RC(0x13)
81 #define TLDAP_TYPE_OR_VALUE_EXISTS TLDAP_RC(0x14)
82 #define TLDAP_INVALID_SYNTAX TLDAP_RC(0x15)
83 #define TLDAP_NO_SUCH_OBJECT TLDAP_RC(0x20)
84 #define TLDAP_ALIAS_PROBLEM TLDAP_RC(0x21)
85 #define TLDAP_INVALID_DN_SYNTAX TLDAP_RC(0x22)
86 #define TLDAP_IS_LEAF TLDAP_RC(0x23)
87 #define TLDAP_ALIAS_DEREF_PROBLEM TLDAP_RC(0x24)
88 #define TLDAP_INAPPROPRIATE_AUTH TLDAP_RC(0x30)
89 #define TLDAP_INVALID_CREDENTIALS TLDAP_RC(0x31)
90 #define TLDAP_INSUFFICIENT_ACCESS TLDAP_RC(0x32)
91 #define TLDAP_BUSY TLDAP_RC(0x33)
92 #define TLDAP_UNAVAILABLE TLDAP_RC(0x34)
93 #define TLDAP_UNWILLING_TO_PERFORM TLDAP_RC(0x35)
94 #define TLDAP_LOOP_DETECT TLDAP_RC(0x36)
95 #define TLDAP_NAMING_VIOLATION TLDAP_RC(0x40)
96 #define TLDAP_OBJECT_CLASS_VIOLATION TLDAP_RC(0x41)
97 #define TLDAP_NOT_ALLOWED_ON_NONLEAF TLDAP_RC(0x42)
98 #define TLDAP_NOT_ALLOWED_ON_RDN TLDAP_RC(0x43)
99 #define TLDAP_ALREADY_EXISTS TLDAP_RC(0x44)
100 #define TLDAP_NO_OBJECT_CLASS_MODS TLDAP_RC(0x45)
101 #define TLDAP_RESULTS_TOO_LARGE TLDAP_RC(0x46)
102 #define TLDAP_AFFECTS_MULTIPLE_DSAS TLDAP_RC(0x47)
103 #define TLDAP_OTHER TLDAP_RC(0x50)
104 #define TLDAP_SERVER_DOWN TLDAP_RC(0x51)
105 #define TLDAP_LOCAL_ERROR TLDAP_RC(0x52)
106 #define TLDAP_ENCODING_ERROR TLDAP_RC(0x53)
107 #define TLDAP_DECODING_ERROR TLDAP_RC(0x54)
108 #define TLDAP_TIMEOUT TLDAP_RC(0x55)
109 #define TLDAP_AUTH_UNKNOWN TLDAP_RC(0x56)
110 #define TLDAP_FILTER_ERROR TLDAP_RC(0x57)
111 #define TLDAP_USER_CANCELLED TLDAP_RC(0x58)
112 #define TLDAP_PARAM_ERROR TLDAP_RC(0x59)
113 #define TLDAP_NO_MEMORY TLDAP_RC(0x5a)
114 #define TLDAP_CONNECT_ERROR TLDAP_RC(0x5b)
115 #define TLDAP_NOT_SUPPORTED TLDAP_RC(0x5c)
116 #define TLDAP_CONTROL_NOT_FOUND TLDAP_RC(0x5d)
117 #define TLDAP_NO_RESULTS_RETURNED TLDAP_RC(0x5e)
118 #define TLDAP_MORE_RESULTS_TO_RETURN TLDAP_RC(0x5f)
119 #define TLDAP_CLIENT_LOOP TLDAP_RC(0x60)
120 #define TLDAP_REFERRAL_LIMIT_EXCEEDED TLDAP_RC(0x61)
121
122 bool tevent_req_ldap_error(struct tevent_req *req, TLDAPRC rc);
123 bool tevent_req_is_ldap_error(struct tevent_req *req, TLDAPRC *perr);
124
125 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd);
126 struct tstream_context *tldap_get_plain_tstream(struct tldap_context *ld);
127 void tldap_set_starttls_needed(struct tldap_context *ld, bool needed);
128 bool tldap_get_starttls_needed(struct tldap_context *ld);
129 bool tldap_has_tls_tstream(struct tldap_context *ld);
130 const DATA_BLOB *tldap_tls_channel_bindings(struct tldap_context *ld);
131 void tldap_set_tls_tstream(struct tldap_context *ld,
132                            struct tstream_context **stream);
133 bool tldap_has_gensec_tstream(struct tldap_context *ld);
134 void tldap_set_gensec_tstream(struct tldap_context *ld,
135                               struct tstream_context **stream);
136
137 bool tldap_connection_ok(struct tldap_context *ld);
138 bool tldap_context_setattr(struct tldap_context *ld,
139                            const char *name, const void *pptr);
140 void *tldap_context_getattr(struct tldap_context *ld, const char *name);
141
142 struct tevent_req *tldap_sasl_bind_send(TALLOC_CTX *mem_ctx,
143                                         struct tevent_context *ev,
144                                         struct tldap_context *ld,
145                                         const char *dn,
146                                         const char *mechanism,
147                                         DATA_BLOB *creds,
148                                         struct tldap_control *sctrls,
149                                         int num_sctrls,
150                                         struct tldap_control *cctrls,
151                                         int num_cctrls);
152 TLDAPRC tldap_sasl_bind_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
153                              DATA_BLOB *serverSaslCreds);
154 TLDAPRC tldap_sasl_bind(struct tldap_context *ldap,
155                         const char *dn,
156                         const char *mechanism,
157                         DATA_BLOB *creds,
158                         struct tldap_control *sctrls,
159                         int num_sctrls,
160                         struct tldap_control *cctrls,
161                         int num_cctrls,
162                         TALLOC_CTX *mem_ctx,
163                         DATA_BLOB *serverSaslCreds);
164
165 struct tevent_req *tldap_simple_bind_send(TALLOC_CTX *mem_ctx,
166                                           struct tevent_context *ev,
167                                           struct tldap_context *ldap,
168                                           const char *dn,
169                                           const char *passwd);
170 TLDAPRC tldap_simple_bind_recv(struct tevent_req *req);
171 TLDAPRC tldap_simple_bind(struct tldap_context *ldap, const char *dn,
172                           const char *passwd);
173
174 struct tevent_req *tldap_search_send(TALLOC_CTX *mem_ctx,
175                                      struct tevent_context *ev,
176                                      struct tldap_context *ld,
177                                      const char *base, int scope,
178                                      const char *filter,
179                                      const char **attrs,
180                                      int num_attrs,
181                                      int attrsonly,
182                                      struct tldap_control *sctrls,
183                                      int num_sctrls,
184                                      struct tldap_control *cctrls,
185                                      int num_cctrls,
186                                      int timelimit,
187                                      int sizelimit,
188                                      int deref);
189 TLDAPRC tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
190                           struct tldap_message **pmsg);
191
192 struct tevent_req *tldap_search_all_send(
193         TALLOC_CTX *mem_ctx, struct tevent_context *ev,
194         struct tldap_context *ld, const char *base, int scope,
195         const char *filter, const char **attrs, int num_attrs, int attrsonly,
196         struct tldap_control *sctrls, int num_sctrls,
197         struct tldap_control *cctrls, int num_cctrls,
198         int timelimit, int sizelimit, int deref);
199 TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
200                               struct tldap_message ***msgs,
201                               struct tldap_message **result);
202
203 TLDAPRC tldap_search(struct tldap_context *ld,
204                      const char *base, int scope, const char *filter,
205                      const char **attrs, int num_attrs, int attrsonly,
206                      struct tldap_control *sctrls, int num_sctrls,
207                      struct tldap_control *cctrls, int num_cctrls,
208                      int timelimit, int sizelimit, int deref,
209                      TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs);
210
211 bool tldap_entry_dn(struct tldap_message *msg, char **dn);
212 bool tldap_entry_attributes(struct tldap_message *msg,
213                             struct tldap_attribute **attributes,
214                             int *num_attributes);
215
216 struct tevent_req *tldap_add_send(TALLOC_CTX *mem_ctx,
217                                   struct tevent_context *ev,
218                                   struct tldap_context *ld,
219                                   const char *dn,
220                                   struct tldap_mod *attributes,
221                                   int num_attributes,
222                                   struct tldap_control *sctrls,
223                                   int num_sctrls,
224                                   struct tldap_control *cctrls,
225                                   int num_cctrls);
226 TLDAPRC tldap_add_recv(struct tevent_req *req);
227 TLDAPRC tldap_add(struct tldap_context *ld, const char *dn,
228                   struct tldap_mod *attributes, int num_attributes,
229                   struct tldap_control *sctrls, int num_sctrls,
230                   struct tldap_control *cctrls, int num_cctrls);
231
232 struct tevent_req *tldap_modify_send(TALLOC_CTX *mem_ctx,
233                                      struct tevent_context *ev,
234                                      struct tldap_context *ld,
235                                      const char *dn,
236                                      struct tldap_mod *mods, int num_mods,
237                                      struct tldap_control *sctrls,
238                                      int num_sctrls,
239                                      struct tldap_control *cctrls,
240                                      int num_cctrls);
241 TLDAPRC tldap_modify_recv(struct tevent_req *req);
242 TLDAPRC tldap_modify(struct tldap_context *ld, const char *dn,
243                      struct tldap_mod *mods, int num_mods,
244                      struct tldap_control *sctrls, int num_sctrls,
245                      struct tldap_control *cctrls, int num_cctrls);
246
247 struct tevent_req *tldap_delete_send(TALLOC_CTX *mem_ctx,
248                                      struct tevent_context *ev,
249                                      struct tldap_context *ld,
250                                      const char *dn,
251                                      struct tldap_control *sctrls,
252                                      int num_sctrls,
253                                      struct tldap_control *cctrls,
254                                      int num_cctrls);
255 TLDAPRC tldap_delete_recv(struct tevent_req *req);
256 TLDAPRC tldap_delete(struct tldap_context *ld, const char *dn,
257                      struct tldap_control *sctrls, int num_sctrls,
258                      struct tldap_control *cctrls, int num_cctrls);
259
260 struct tevent_req *tldap_extended_send(TALLOC_CTX *mem_ctx,
261                                        struct tevent_context *ev,
262                                        struct tldap_context *ld,
263                                        const char *in_oid,
264                                        const DATA_BLOB *in_blob,
265                                        struct tldap_control *sctrls,
266                                        int num_sctrls,
267                                        struct tldap_control *cctrls,
268                                        int num_cctrls);
269 TLDAPRC tldap_extended_recv(struct tevent_req *req,
270                             TALLOC_CTX *mem_ctx,
271                             char **out_oid,
272                             DATA_BLOB *out_blob);
273 TLDAPRC tldap_extended(struct tldap_context *ld,
274                         const char *in_oid,
275                         const DATA_BLOB *in_blob,
276                         struct tldap_control *sctrls,
277                         int num_sctrls,
278                         struct tldap_control *cctrls,
279                         int num_cctrls,
280                         TALLOC_CTX *mem_ctx,
281                         char **out_oid,
282                         DATA_BLOB *out_blob);
283
284 int tldap_msg_id(const struct tldap_message *msg);
285 int tldap_msg_type(const struct tldap_message *msg);
286 const char *tldap_msg_matcheddn(struct tldap_message *msg);
287 const char *tldap_msg_diagnosticmessage(struct tldap_message *msg);
288 const char *tldap_msg_referral(struct tldap_message *msg);
289 void tldap_msg_sctrls(struct tldap_message *msg, int *num_sctrls,
290                       struct tldap_control **sctrls);
291 struct tldap_message *tldap_ctx_lastmsg(struct tldap_context *ld);
292 const char *tldap_rc2string(TLDAPRC rc);
293
294 /* DEBUG */
295 enum tldap_debug_level {
296         TLDAP_DEBUG_FATAL,
297         TLDAP_DEBUG_ERROR,
298         TLDAP_DEBUG_WARNING,
299         TLDAP_DEBUG_TRACE
300 };
301
302 void tldap_set_debug(struct tldap_context *ld,
303                      void (*log_fn)(void *log_private,
304                                     enum tldap_debug_level level,
305                                     const char *fmt,
306                                     va_list ap) PRINTF_ATTRIBUTE(3,0),
307                      void *log_private);
308
309 /*
310  * "+ 0x60" is from ASN1_APPLICATION
311  */
312 #define TLDAP_REQ_BIND (0 + 0x60)
313 #define TLDAP_RES_BIND (1 + 0x60)
314 #define TLDAP_REQ_UNBIND (2 + 0x60)
315 #define TLDAP_REQ_SEARCH (3 + 0x60)
316 #define TLDAP_RES_SEARCH_ENTRY (4 + 0x60)
317 #define TLDAP_RES_SEARCH_RESULT (5 + 0x60)
318 #define TLDAP_REQ_MODIFY (6 + 0x60)
319 #define TLDAP_RES_MODIFY (7 + 0x60)
320 #define TLDAP_REQ_ADD (8 + 0x60)
321 #define TLDAP_RES_ADD (9 + 0x60)
322 /* ASN1_APPLICATION_SIMPLE instead of ASN1_APPLICATION */
323 #define TLDAP_REQ_DELETE (10 + 0x40)
324 #define TLDAP_RES_DELETE (11 + 0x60)
325 #define TLDAP_REQ_MODDN (12 + 0x60)
326 #define TLDAP_RES_MODDN (13 + 0x60)
327 #define TLDAP_REQ_COMPARE (14 + 0x60)
328 #define TLDAP_RES_COMPARE (15 + 0x60)
329 /* ASN1_APPLICATION_SIMPLE instead of ASN1_APPLICATION */
330 #define TLDAP_REQ_ABANDON (16 + 0x40)
331 #define TLDAP_RES_SEARCH_REFERENCE (19 + 0x60)
332 #define TLDAP_REQ_EXTENDED (23 + 0x60)
333 #define TLDAP_RES_EXTENDED (24 + 0x60)
334 #define TLDAP_RES_INTERMEDIATE (25 + 0x60)
335
336 #define TLDAP_MOD_ADD (0)
337 #define TLDAP_MOD_DELETE (1)
338 #define TLDAP_MOD_REPLACE (2)
339
340 #define TLDAP_SCOPE_BASE (0)
341 #define TLDAP_SCOPE_ONE (1)
342 #define TLDAP_SCOPE_SUB (2)
343
344 #define TLDAP_CONTROL_PAGEDRESULTS "1.2.840.113556.1.4.319"
345
346 #endif