r1862: add invalid_creds ldap error
[tprouty/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_INVALID_CREDENTIALS = 0x31,
57         LDAP_OTHER = 0x50
58 };
59
60 struct ldap_Result {
61         int resultcode;
62         const char *dn;
63         const char *errormessage;
64         const char *referral;
65 };
66
67 struct ldap_attribute {
68         const char *name;
69         int num_values;
70         DATA_BLOB *values;
71 };
72
73 struct ldap_BindRequest {
74         int version;
75         const char *dn;
76         enum ldap_auth_mechanism mechanism;
77         union {
78                 const char *password;
79                 struct {
80                         const char *mechanism;
81                         DATA_BLOB secblob;
82                 } SASL;
83         } creds;
84 };
85
86 struct ldap_BindResponse {
87         struct ldap_Result response;
88         union {
89                 DATA_BLOB secblob;
90         } SASL;
91 };
92
93 struct ldap_UnbindRequest {
94 };
95
96 enum ldap_scope {
97         LDAP_SEARCH_SCOPE_BASE = 0,
98         LDAP_SEARCH_SCOPE_SINGLE = 1,
99         LDAP_SEARCH_SCOPE_SUB = 2
100 };
101
102 enum ldap_deref {
103         LDAP_DEREFERENCE_NEVER = 0,
104         LDAP_DEREFERENCE_IN_SEARCHING = 1,
105         LDAP_DEREFERENCE_FINDING_BASE = 2,
106         LDAP_DEREFERENCE_ALWAYS
107 };
108
109 struct ldap_SearchRequest {
110         const char *basedn;
111         enum ldap_scope scope;
112         enum ldap_deref deref;
113         uint32 timelimit;
114         uint32 sizelimit;
115         BOOL attributesonly;
116         char *filter;
117         int num_attributes;
118         const char **attributes;
119 };
120
121 struct ldap_SearchResEntry {
122         const char *dn;
123         int num_attributes;
124         struct ldap_attribute *attributes;
125 };
126
127 struct ldap_SearchResRef {
128         int num_referrals;
129         const char **referrals;
130 };
131
132 enum ldap_modify_type {
133         LDAP_MODIFY_NONE = -1,
134         LDAP_MODIFY_ADD = 0,
135         LDAP_MODIFY_DELETE = 1,
136         LDAP_MODIFY_REPLACE = 2
137 };
138
139 struct ldap_mod {
140         enum ldap_modify_type type;
141         struct ldap_attribute attrib;
142 };
143
144 struct ldap_ModifyRequest {
145         const char *dn;
146         int num_mods;
147         struct ldap_mod *mods;
148 };
149
150 struct ldap_AddRequest {
151         const char *dn;
152         int num_attributes;
153         struct ldap_attribute *attributes;
154 };
155
156 struct ldap_DelRequest {
157         const char *dn;
158 };
159
160 struct ldap_ModifyDNRequest {
161         const char *dn;
162         const char *newrdn;
163         BOOL deleteolddn;
164         const char *newsuperior;
165 };
166
167 struct ldap_CompareRequest {
168         const char *dn;
169         const char *attribute;
170         const char *value;
171 };
172
173 struct ldap_AbandonRequest {
174         uint32 messageid;
175 };
176
177 struct ldap_ExtendedRequest {
178         const char *oid;
179         DATA_BLOB value;
180 };
181
182 struct ldap_ExtendedResponse {
183         struct ldap_Result response;
184         const char *name;
185         DATA_BLOB value;
186 };
187
188 union ldap_Request {
189         struct ldap_BindRequest         BindRequest;
190         struct ldap_BindResponse        BindResponse;
191         struct ldap_UnbindRequest       UnbindRequest;
192         struct ldap_SearchRequest       SearchRequest;
193         struct ldap_SearchResEntry      SearchResultEntry;
194         struct ldap_Result              SearchResultDone;
195         struct ldap_SearchResRef        SearchResultReference;
196         struct ldap_ModifyRequest       ModifyRequest;
197         struct ldap_Result              ModifyResponse;
198         struct ldap_AddRequest          AddRequest;
199         struct ldap_Result              AddResponse;
200         struct ldap_DelRequest          DelRequest;
201         struct ldap_Result              DelResponse;
202         struct ldap_ModifyDNRequest     ModifyDNRequest;
203         struct ldap_Result              ModifyDNResponse;
204         struct ldap_CompareRequest      CompareRequest;
205         struct ldap_Result              CompareResponse;
206         struct ldap_AbandonRequest      AbandonRequest;
207         struct ldap_ExtendedRequest     ExtendedRequest;
208         struct ldap_ExtendedResponse    ExtendedResponse;
209 };
210
211 struct ldap_Control {
212         const char *oid;
213         BOOL        critical;
214         DATA_BLOB   value;
215 };
216
217 struct ldap_message {
218         TALLOC_CTX             *mem_ctx;
219         uint32                  messageid;
220         uint8                   type;
221         union  ldap_Request     r;
222         int                     num_controls;
223         struct ldap_Control    *controls;
224 };
225
226 struct ldap_queue_entry {
227         struct ldap_queue_entry *next, *prev;
228         int msgid;
229         struct ldap_message *msg;
230 };
231
232 struct ldap_connection {
233         TALLOC_CTX *mem_ctx;
234         int sock;
235         int next_msgid;
236         char *host;
237         uint16 port;
238         BOOL ldaps;
239
240         const char *auth_dn;
241         const char *simple_pw;
242
243         /* Current outstanding search entry */
244         int searchid;
245
246         /* List for incoming search entries */
247         struct ldap_queue_entry *search_entries;
248
249         /* Outstanding LDAP requests that have not yet been replied to */
250         struct ldap_queue_entry *outstanding;
251
252         /* Let's support SASL */
253         struct gensec_security *gensec;
254 };
255
256 #endif