r1802: start to support SASL in our ldap libraries
[jra/samba/.git] / source4 / libcli / ldap / ldap.h
1 /* 
2    Unix SMB/CIFS Implementation.
3    LDAP protocol helper functions for SAMBA
4    Copyright (C) Volker Lendecke 2004
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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19    
20 */
21
22 #ifndef _SMB_LDAP_H
23 #define _SMB_LDAP_H
24
25 enum ldap_request_tag {
26         LDAP_TAG_BindRequest = 0,
27         LDAP_TAG_BindResponse = 1,
28         LDAP_TAG_UnbindRequest = 2,
29         LDAP_TAG_SearchRequest = 3,
30         LDAP_TAG_SearchResultEntry = 4,
31         LDAP_TAG_SearchResultDone = 5,
32         LDAP_TAG_ModifyRequest = 6,
33         LDAP_TAG_ModifyResponse = 7,
34         LDAP_TAG_AddRequest = 8,
35         LDAP_TAG_AddResponse = 9,
36         LDAP_TAG_DelRequest = 10,
37         LDAP_TAG_DelResponse = 11,
38         LDAP_TAG_ModifyDNRequest = 12,
39         LDAP_TAG_ModifyDNResponse = 13,
40         LDAP_TAG_CompareRequest = 14,
41         LDAP_TAG_CompareResponse = 15,
42         LDAP_TAG_AbandonRequest = 16,
43         LDAP_TAG_SearchResultReference = 19,
44         LDAP_TAG_ExtendedRequest = 23,
45         LDAP_TAG_ExtendedResponse = 24
46 };
47
48 enum ldap_auth_mechanism {
49         LDAP_AUTH_MECH_SIMPLE = 0,
50         LDAP_AUTH_MECH_SASL = 3
51 };
52
53 enum ldap_result_code {
54         LDAP_SUCCESS = 0,
55         LDAP_SASL_BIND_IN_PROGRESS = 0x0e,
56         LDAP_OTHER = 0x50
57 };
58
59 struct ldap_Result {
60         int resultcode;
61         const char *dn;
62         const char *errormessage;
63         const char *referral;
64 };
65
66 struct ldap_attribute {
67         const char *name;
68         int num_values;
69         DATA_BLOB *values;
70 };
71
72 struct ldap_BindRequest {
73         int version;
74         const char *dn;
75         enum ldap_auth_mechanism mechanism;
76         union {
77                 const char *password;
78                 struct {
79                         const char *mechanism;
80                         DATA_BLOB secblob;
81                 } SASL;
82         } creds;
83 };
84
85 struct ldap_BindResponse {
86         struct ldap_Result response;
87         union {
88                 DATA_BLOB creds;
89         } SASL;
90 };
91
92 struct ldap_UnbindRequest {
93 };
94
95 enum ldap_scope {
96         LDAP_SEARCH_SCOPE_BASE = 0,
97         LDAP_SEARCH_SCOPE_SINGLE = 1,
98         LDAP_SEARCH_SCOPE_SUB = 2
99 };
100
101 enum ldap_deref {
102         LDAP_DEREFERENCE_NEVER = 0,
103         LDAP_DEREFERENCE_IN_SEARCHING = 1,
104         LDAP_DEREFERENCE_FINDING_BASE = 2,
105         LDAP_DEREFERENCE_ALWAYS
106 };
107
108 struct ldap_SearchRequest {
109         const char *basedn;
110         enum ldap_scope scope;
111         enum ldap_deref deref;
112         uint32 timelimit;
113         uint32 sizelimit;
114         BOOL attributesonly;
115         char *filter;
116         int num_attributes;
117         const char **attributes;
118 };
119
120 struct ldap_SearchResEntry {
121         const char *dn;
122         int num_attributes;
123         struct ldap_attribute *attributes;
124 };
125
126 struct ldap_SearchResRef {
127         int num_referrals;
128         const char **referrals;
129 };
130
131 enum ldap_modify_type {
132         LDAP_MODIFY_NONE = -1,
133         LDAP_MODIFY_ADD = 0,
134         LDAP_MODIFY_DELETE = 1,
135         LDAP_MODIFY_REPLACE = 2
136 };
137
138 struct ldap_mod {
139         enum ldap_modify_type type;
140         struct ldap_attribute attrib;
141 };
142
143 struct ldap_ModifyRequest {
144         const char *dn;
145         int num_mods;
146         struct ldap_mod *mods;
147 };
148
149 struct ldap_AddRequest {
150         const char *dn;
151         int num_attributes;
152         struct ldap_attribute *attributes;
153 };
154
155 struct ldap_DelRequest {
156         const char *dn;
157 };
158
159 struct ldap_ModifyDNRequest {
160         const char *dn;
161         const char *newrdn;
162         BOOL deleteolddn;
163         const char *newsuperior;
164 };
165
166 struct ldap_CompareRequest {
167         const char *dn;
168         const char *attribute;
169         const char *value;
170 };
171
172 struct ldap_AbandonRequest {
173         uint32 messageid;
174 };
175
176 struct ldap_ExtendedRequest {
177         const char *oid;
178         DATA_BLOB value;
179 };
180
181 struct ldap_ExtendedResponse {
182         struct ldap_Result response;
183         const char *name;
184         DATA_BLOB value;
185 };
186
187 union ldap_Request {
188         struct ldap_BindRequest         BindRequest;
189         struct ldap_BindResponse        BindResponse;
190         struct ldap_UnbindRequest       UnbindRequest;
191         struct ldap_SearchRequest       SearchRequest;
192         struct ldap_SearchResEntry      SearchResultEntry;
193         struct ldap_Result              SearchResultDone;
194         struct ldap_SearchResRef        SearchResultReference;
195         struct ldap_ModifyRequest       ModifyRequest;
196         struct ldap_Result              ModifyResponse;
197         struct ldap_AddRequest          AddRequest;
198         struct ldap_Result              AddResponse;
199         struct ldap_DelRequest          DelRequest;
200         struct ldap_Result              DelResponse;
201         struct ldap_ModifyDNRequest     ModifyDNRequest;
202         struct ldap_Result              ModifyDNResponse;
203         struct ldap_CompareRequest      CompareRequest;
204         struct ldap_Result              CompareResponse;
205         struct ldap_AbandonRequest      AbandonRequest;
206         struct ldap_ExtendedRequest     ExtendedRequest;
207         struct ldap_ExtendedResponse    ExtendedResponse;
208 };
209
210 struct ldap_Control {
211         const char *oid;
212         BOOL        critical;
213         DATA_BLOB   value;
214 };
215
216 struct ldap_message {
217         TALLOC_CTX             *mem_ctx;
218         uint32                  messageid;
219         uint8                   type;
220         union  ldap_Request     r;
221         int                     num_controls;
222         struct ldap_Control    *controls;
223 };
224
225 struct ldap_queue_entry {
226         struct ldap_queue_entry *next, *prev;
227         int msgid;
228         struct ldap_message *msg;
229 };
230
231 struct ldap_connection {
232         TALLOC_CTX *mem_ctx;
233         int sock;
234         int next_msgid;
235         char *host;
236         uint16 port;
237         BOOL ldaps;
238
239         const char *auth_dn;
240         const char *simple_pw;
241
242         /* Current outstanding search entry */
243         int searchid;
244
245         /* List for incoming search entries */
246         struct ldap_queue_entry *search_entries;
247
248         /* Outstanding LDAP requests that have not yet been replied to */
249         struct ldap_queue_entry *outstanding;
250
251         /* Let's support SASL */
252         struct gensec_security *gensec;
253 };
254
255 #endif