docs-xml: change http://samba.org to https://www.samba.org
[Samba.git] / source3 / include / tldap.h
blob74279a4ba18ff75307a169435f654c8d7bed4fb0
1 /*
2 Unix SMB/CIFS implementation.
3 Infrastructure for async ldap client requests
4 Copyright (C) Volker Lendecke 2009
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.
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.
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/>.
20 #ifndef __TLDAP_H__
21 #define __TLDAP_H__
23 #include "replace.h"
24 #include <talloc.h>
25 #include <tevent.h>
26 #include "lib/util/data_blob.h"
28 struct tldap_context;
29 struct tldap_message;
31 struct tldap_control {
32 const char *oid;
33 DATA_BLOB value;
34 bool critical;
37 struct tldap_attribute {
38 char *name;
39 int num_values;
40 DATA_BLOB *values;
43 struct tldap_mod {
44 int mod_op;
45 char *attribute;
46 int num_values;
47 DATA_BLOB *values;
50 typedef struct { uint8_t rc; } TLDAPRC;
51 #define TLDAP_RC(x) ((TLDAPRC){.rc = x})
52 #define TLDAP_RC_V(x) ((x).rc)
54 #define TLDAP_RC_EQUAL(x,y) (TLDAP_RC_V(x)==TLDAP_RC_V(y))
55 #define TLDAP_RC_IS_SUCCESS(x) TLDAP_RC_EQUAL(x,TLDAP_SUCCESS)
57 #define TLDAP_SUCCESS TLDAP_RC(0x00)
58 #define TLDAP_OPERATIONS_ERROR TLDAP_RC(0x01)
59 #define TLDAP_PROTOCOL_ERROR TLDAP_RC(0x02)
60 #define TLDAP_TIMELIMIT_EXCEEDED TLDAP_RC(0x03)
61 #define TLDAP_SIZELIMIT_EXCEEDED TLDAP_RC(0x04)
62 #define TLDAP_COMPARE_FALSE TLDAP_RC(0x05)
63 #define TLDAP_COMPARE_TRUE TLDAP_RC(0x06)
64 #define TLDAP_STRONG_AUTH_NOT_SUPPORTED TLDAP_RC(0x07)
65 #define TLDAP_STRONG_AUTH_REQUIRED TLDAP_RC(0x08)
66 #define TLDAP_REFERRAL TLDAP_RC(0x0a)
67 #define TLDAP_ADMINLIMIT_EXCEEDED TLDAP_RC(0x0b)
68 #define TLDAP_UNAVAILABLE_CRITICAL_EXTENSION TLDAP_RC(0x0c)
69 #define TLDAP_CONFIDENTIALITY_REQUIRED TLDAP_RC(0x0d)
70 #define TLDAP_SASL_BIND_IN_PROGRESS TLDAP_RC(0x0e)
71 #define TLDAP_NO_SUCH_ATTRIBUTE TLDAP_RC(0x10)
72 #define TLDAP_UNDEFINED_TYPE TLDAP_RC(0x11)
73 #define TLDAP_INAPPROPRIATE_MATCHING TLDAP_RC(0x12)
74 #define TLDAP_CONSTRAINT_VIOLATION TLDAP_RC(0x13)
75 #define TLDAP_TYPE_OR_VALUE_EXISTS TLDAP_RC(0x14)
76 #define TLDAP_INVALID_SYNTAX TLDAP_RC(0x15)
77 #define TLDAP_NO_SUCH_OBJECT TLDAP_RC(0x20)
78 #define TLDAP_ALIAS_PROBLEM TLDAP_RC(0x21)
79 #define TLDAP_INVALID_DN_SYNTAX TLDAP_RC(0x22)
80 #define TLDAP_IS_LEAF TLDAP_RC(0x23)
81 #define TLDAP_ALIAS_DEREF_PROBLEM TLDAP_RC(0x24)
82 #define TLDAP_INAPPROPRIATE_AUTH TLDAP_RC(0x30)
83 #define TLDAP_INVALID_CREDENTIALS TLDAP_RC(0x31)
84 #define TLDAP_INSUFFICIENT_ACCESS TLDAP_RC(0x32)
85 #define TLDAP_BUSY TLDAP_RC(0x33)
86 #define TLDAP_UNAVAILABLE TLDAP_RC(0x34)
87 #define TLDAP_UNWILLING_TO_PERFORM TLDAP_RC(0x35)
88 #define TLDAP_LOOP_DETECT TLDAP_RC(0x36)
89 #define TLDAP_NAMING_VIOLATION TLDAP_RC(0x40)
90 #define TLDAP_OBJECT_CLASS_VIOLATION TLDAP_RC(0x41)
91 #define TLDAP_NOT_ALLOWED_ON_NONLEAF TLDAP_RC(0x42)
92 #define TLDAP_NOT_ALLOWED_ON_RDN TLDAP_RC(0x43)
93 #define TLDAP_ALREADY_EXISTS TLDAP_RC(0x44)
94 #define TLDAP_NO_OBJECT_CLASS_MODS TLDAP_RC(0x45)
95 #define TLDAP_RESULTS_TOO_LARGE TLDAP_RC(0x46)
96 #define TLDAP_AFFECTS_MULTIPLE_DSAS TLDAP_RC(0x47)
97 #define TLDAP_OTHER TLDAP_RC(0x50)
98 #define TLDAP_SERVER_DOWN TLDAP_RC(0x51)
99 #define TLDAP_LOCAL_ERROR TLDAP_RC(0x52)
100 #define TLDAP_ENCODING_ERROR TLDAP_RC(0x53)
101 #define TLDAP_DECODING_ERROR TLDAP_RC(0x54)
102 #define TLDAP_TIMEOUT TLDAP_RC(0x55)
103 #define TLDAP_AUTH_UNKNOWN TLDAP_RC(0x56)
104 #define TLDAP_FILTER_ERROR TLDAP_RC(0x57)
105 #define TLDAP_USER_CANCELLED TLDAP_RC(0x58)
106 #define TLDAP_PARAM_ERROR TLDAP_RC(0x59)
107 #define TLDAP_NO_MEMORY TLDAP_RC(0x5a)
108 #define TLDAP_CONNECT_ERROR TLDAP_RC(0x5b)
109 #define TLDAP_NOT_SUPPORTED TLDAP_RC(0x5c)
110 #define TLDAP_CONTROL_NOT_FOUND TLDAP_RC(0x5d)
111 #define TLDAP_NO_RESULTS_RETURNED TLDAP_RC(0x5e)
112 #define TLDAP_MORE_RESULTS_TO_RETURN TLDAP_RC(0x5f)
113 #define TLDAP_CLIENT_LOOP TLDAP_RC(0x60)
114 #define TLDAP_REFERRAL_LIMIT_EXCEEDED TLDAP_RC(0x61)
116 bool tevent_req_ldap_error(struct tevent_req *req, TLDAPRC rc);
117 bool tevent_req_is_ldap_error(struct tevent_req *req, TLDAPRC *perr);
119 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd);
120 struct tstream_context *tldap_get_tstream(struct tldap_context *ld);
121 void tldap_set_tstream(struct tldap_context *ld,
122 struct tstream_context *stream);
124 bool tldap_connection_ok(struct tldap_context *ld);
125 bool tldap_context_setattr(struct tldap_context *ld,
126 const char *name, const void *pptr);
127 void *tldap_context_getattr(struct tldap_context *ld, const char *name);
129 struct tevent_req *tldap_sasl_bind_send(TALLOC_CTX *mem_ctx,
130 struct tevent_context *ev,
131 struct tldap_context *ld,
132 const char *dn,
133 const char *mechanism,
134 DATA_BLOB *creds,
135 struct tldap_control *sctrls,
136 int num_sctrls,
137 struct tldap_control *cctrls,
138 int num_cctrls);
139 TLDAPRC tldap_sasl_bind_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
140 DATA_BLOB *serverSaslCreds);
141 TLDAPRC tldap_sasl_bind(struct tldap_context *ldap,
142 const char *dn,
143 const char *mechanism,
144 DATA_BLOB *creds,
145 struct tldap_control *sctrls,
146 int num_sctrls,
147 struct tldap_control *cctrls,
148 int num_cctrls,
149 TALLOC_CTX *mem_ctx,
150 DATA_BLOB *serverSaslCreds);
152 struct tevent_req *tldap_simple_bind_send(TALLOC_CTX *mem_ctx,
153 struct tevent_context *ev,
154 struct tldap_context *ldap,
155 const char *dn,
156 const char *passwd);
157 TLDAPRC tldap_simple_bind_recv(struct tevent_req *req);
158 TLDAPRC tldap_simple_bind(struct tldap_context *ldap, const char *dn,
159 const char *passwd);
161 struct tevent_req *tldap_search_send(TALLOC_CTX *mem_ctx,
162 struct tevent_context *ev,
163 struct tldap_context *ld,
164 const char *base, int scope,
165 const char *filter,
166 const char **attrs,
167 int num_attrs,
168 int attrsonly,
169 struct tldap_control *sctrls,
170 int num_sctrls,
171 struct tldap_control *cctrls,
172 int num_cctrls,
173 int timelimit,
174 int sizelimit,
175 int deref);
176 TLDAPRC tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
177 struct tldap_message **pmsg);
179 struct tevent_req *tldap_search_all_send(
180 TALLOC_CTX *mem_ctx, struct tevent_context *ev,
181 struct tldap_context *ld, const char *base, int scope,
182 const char *filter, const char **attrs, int num_attrs, int attrsonly,
183 struct tldap_control *sctrls, int num_sctrls,
184 struct tldap_control *cctrls, int num_cctrls,
185 int timelimit, int sizelimit, int deref);
186 TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
187 struct tldap_message ***msgs,
188 struct tldap_message **result);
190 TLDAPRC tldap_search(struct tldap_context *ld,
191 const char *base, int scope, const char *filter,
192 const char **attrs, int num_attrs, int attrsonly,
193 struct tldap_control *sctrls, int num_sctrls,
194 struct tldap_control *cctrls, int num_cctrls,
195 int timelimit, int sizelimit, int deref,
196 TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs);
198 bool tldap_entry_dn(struct tldap_message *msg, char **dn);
199 bool tldap_entry_attributes(struct tldap_message *msg,
200 struct tldap_attribute **attributes,
201 int *num_attributes);
203 struct tevent_req *tldap_add_send(TALLOC_CTX *mem_ctx,
204 struct tevent_context *ev,
205 struct tldap_context *ld,
206 const char *dn,
207 struct tldap_mod *attributes,
208 int num_attributes,
209 struct tldap_control *sctrls,
210 int num_sctrls,
211 struct tldap_control *cctrls,
212 int num_cctrls);
213 TLDAPRC tldap_add_recv(struct tevent_req *req);
214 TLDAPRC tldap_add(struct tldap_context *ld, const char *dn,
215 struct tldap_mod *attributes, int num_attributes,
216 struct tldap_control *sctrls, int num_sctrls,
217 struct tldap_control *cctrls, int num_cctrls);
219 struct tevent_req *tldap_modify_send(TALLOC_CTX *mem_ctx,
220 struct tevent_context *ev,
221 struct tldap_context *ld,
222 const char *dn,
223 struct tldap_mod *mods, int num_mods,
224 struct tldap_control *sctrls,
225 int num_sctrls,
226 struct tldap_control *cctrls,
227 int num_cctrls);
228 TLDAPRC tldap_modify_recv(struct tevent_req *req);
229 TLDAPRC tldap_modify(struct tldap_context *ld, const char *dn,
230 struct tldap_mod *mods, int num_mods,
231 struct tldap_control *sctrls, int num_sctrls,
232 struct tldap_control *cctrls, int num_cctrls);
234 struct tevent_req *tldap_delete_send(TALLOC_CTX *mem_ctx,
235 struct tevent_context *ev,
236 struct tldap_context *ld,
237 const char *dn,
238 struct tldap_control *sctrls,
239 int num_sctrls,
240 struct tldap_control *cctrls,
241 int num_cctrls);
242 TLDAPRC tldap_delete_recv(struct tevent_req *req);
243 TLDAPRC tldap_delete(struct tldap_context *ld, const char *dn,
244 struct tldap_control *sctrls, int num_sctrls,
245 struct tldap_control *cctrls, int num_cctrls);
247 int tldap_msg_id(const struct tldap_message *msg);
248 int tldap_msg_type(const struct tldap_message *msg);
249 const char *tldap_msg_matcheddn(struct tldap_message *msg);
250 const char *tldap_msg_diagnosticmessage(struct tldap_message *msg);
251 const char *tldap_msg_referral(struct tldap_message *msg);
252 void tldap_msg_sctrls(struct tldap_message *msg, int *num_sctrls,
253 struct tldap_control **sctrls);
254 struct tldap_message *tldap_ctx_lastmsg(struct tldap_context *ld);
255 const char *tldap_rc2string(TLDAPRC rc);
257 /* DEBUG */
258 enum tldap_debug_level {
259 TLDAP_DEBUG_FATAL,
260 TLDAP_DEBUG_ERROR,
261 TLDAP_DEBUG_WARNING,
262 TLDAP_DEBUG_TRACE
265 void tldap_set_debug(struct tldap_context *ld,
266 void (*log_fn)(void *log_private,
267 enum tldap_debug_level level,
268 const char *fmt,
269 va_list ap) PRINTF_ATTRIBUTE(3,0),
270 void *log_private);
273 * "+ 0x60" is from ASN1_APPLICATION
275 #define TLDAP_REQ_BIND (0 + 0x60)
276 #define TLDAP_RES_BIND (1 + 0x60)
277 #define TLDAP_REQ_UNBIND (2 + 0x60)
278 #define TLDAP_REQ_SEARCH (3 + 0x60)
279 #define TLDAP_RES_SEARCH_ENTRY (4 + 0x60)
280 #define TLDAP_RES_SEARCH_RESULT (5 + 0x60)
281 #define TLDAP_REQ_MODIFY (6 + 0x60)
282 #define TLDAP_RES_MODIFY (7 + 0x60)
283 #define TLDAP_REQ_ADD (8 + 0x60)
284 #define TLDAP_RES_ADD (9 + 0x60)
285 /* ASN1_APPLICATION_SIMPLE instead of ASN1_APPLICATION */
286 #define TLDAP_REQ_DELETE (10 + 0x40)
287 #define TLDAP_RES_DELETE (11 + 0x60)
288 #define TLDAP_REQ_MODDN (12 + 0x60)
289 #define TLDAP_RES_MODDN (13 + 0x60)
290 #define TLDAP_REQ_COMPARE (14 + 0x60)
291 #define TLDAP_RES_COMPARE (15 + 0x60)
292 /* ASN1_APPLICATION_SIMPLE instead of ASN1_APPLICATION */
293 #define TLDAP_REQ_ABANDON (16 + 0x40)
294 #define TLDAP_RES_SEARCH_REFERENCE (19 + 0x60)
295 #define TLDAP_REQ_EXTENDED (23 + 0x60)
296 #define TLDAP_RES_EXTENDED (24 + 0x60)
297 #define TLDAP_RES_INTERMEDIATE (25 + 0x60)
299 #define TLDAP_MOD_ADD (0)
300 #define TLDAP_MOD_DELETE (1)
301 #define TLDAP_MOD_REPLACE (2)
303 #define TLDAP_SCOPE_BASE (0)
304 #define TLDAP_SCOPE_ONE (1)
305 #define TLDAP_SCOPE_SUB (2)
307 #define TLDAP_CONTROL_PAGEDRESULTS "1.2.840.113556.1.4.319"
309 #endif