2 Unix SMB/CIFS Implementation.
3 LDAP protocol helper functions for SAMBA
4 Copyright (C) Volker Lendecke 2004
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/>.
21 #ifndef _LIBCLI_LDAP_MESSAGE_H_
22 #define _LIBCLI_LDAP_MESSAGE_H_
24 #include "../libcli/ldap/ldap_errors.h"
27 enum ldap_request_tag
{
28 LDAP_TAG_BindRequest
= 0,
29 LDAP_TAG_BindResponse
= 1,
30 LDAP_TAG_UnbindRequest
= 2,
31 LDAP_TAG_SearchRequest
= 3,
32 LDAP_TAG_SearchResultEntry
= 4,
33 LDAP_TAG_SearchResultDone
= 5,
34 LDAP_TAG_ModifyRequest
= 6,
35 LDAP_TAG_ModifyResponse
= 7,
36 LDAP_TAG_AddRequest
= 8,
37 LDAP_TAG_AddResponse
= 9,
38 LDAP_TAG_DelRequest
= 10,
39 LDAP_TAG_DelResponse
= 11,
40 LDAP_TAG_ModifyDNRequest
= 12,
41 LDAP_TAG_ModifyDNResponse
= 13,
42 LDAP_TAG_CompareRequest
= 14,
43 LDAP_TAG_CompareResponse
= 15,
44 LDAP_TAG_AbandonRequest
= 16,
45 LDAP_TAG_SearchResultReference
= 19,
46 LDAP_TAG_ExtendedRequest
= 23,
47 LDAP_TAG_ExtendedResponse
= 24
50 enum ldap_auth_mechanism
{
51 LDAP_AUTH_MECH_SIMPLE
= 0,
52 LDAP_AUTH_MECH_SASL
= 3
58 const char *errormessage
;
62 struct ldap_BindRequest
{
65 enum ldap_auth_mechanism mechanism
;
69 const char *mechanism
;
70 DATA_BLOB
*secblob
;/* optional */
75 struct ldap_BindResponse
{
76 struct ldap_Result response
;
78 DATA_BLOB
*secblob
;/* optional */
82 struct ldap_UnbindRequest
{
87 LDAP_SEARCH_SCOPE_BASE
= 0,
88 LDAP_SEARCH_SCOPE_SINGLE
= 1,
89 LDAP_SEARCH_SCOPE_SUB
= 2
93 LDAP_DEREFERENCE_NEVER
= 0,
94 LDAP_DEREFERENCE_IN_SEARCHING
= 1,
95 LDAP_DEREFERENCE_FINDING_BASE
= 2,
96 LDAP_DEREFERENCE_ALWAYS
99 struct ldap_SearchRequest
{
101 enum ldap_scope scope
;
102 enum ldap_deref deref
;
106 struct ldb_parse_tree
*tree
;
107 size_t num_attributes
;
108 const char * const *attributes
;
111 struct ldap_SearchResEntry
{
114 struct ldb_message_element
*attributes
;
117 struct ldap_SearchResRef
{
118 const char *referral
;
121 enum ldap_modify_type
{
122 LDAP_MODIFY_NONE
= -1,
124 LDAP_MODIFY_DELETE
= 1,
125 LDAP_MODIFY_REPLACE
= 2
129 enum ldap_modify_type type
;
130 struct ldb_message_element attrib
;
133 struct ldap_ModifyRequest
{
136 struct ldap_mod
*mods
;
139 struct ldap_AddRequest
{
142 struct ldb_message_element
*attributes
;
145 struct ldap_DelRequest
{
149 struct ldap_ModifyDNRequest
{
153 const char *newsuperior
;/* optional */
156 struct ldap_CompareRequest
{
158 const char *attribute
;
162 struct ldap_AbandonRequest
{
166 struct ldap_ExtendedRequest
{
168 DATA_BLOB
*value
;/* optional */
171 struct ldap_ExtendedResponse
{
172 struct ldap_Result response
;
173 const char *oid
;/* optional */
174 DATA_BLOB
*value
;/* optional */
178 struct ldap_Result GeneralResult
;
179 struct ldap_BindRequest BindRequest
;
180 struct ldap_BindResponse BindResponse
;
181 struct ldap_UnbindRequest UnbindRequest
;
182 struct ldap_SearchRequest SearchRequest
;
183 struct ldap_SearchResEntry SearchResultEntry
;
184 struct ldap_Result SearchResultDone
;
185 struct ldap_SearchResRef SearchResultReference
;
186 struct ldap_ModifyRequest ModifyRequest
;
187 struct ldap_Result ModifyResponse
;
188 struct ldap_AddRequest AddRequest
;
189 struct ldap_Result AddResponse
;
190 struct ldap_DelRequest DelRequest
;
191 struct ldap_Result DelResponse
;
192 struct ldap_ModifyDNRequest ModifyDNRequest
;
193 struct ldap_Result ModifyDNResponse
;
194 struct ldap_CompareRequest CompareRequest
;
195 struct ldap_Result CompareResponse
;
196 struct ldap_AbandonRequest AbandonRequest
;
197 struct ldap_ExtendedRequest ExtendedRequest
;
198 struct ldap_ExtendedResponse ExtendedResponse
;
202 struct ldap_message
{
204 enum ldap_request_tag type
;
205 union ldap_Request r
;
206 struct ldb_control
**controls
;
207 bool *controls_decoded
;
210 struct ldap_control_handler
{
212 bool (*decode
)(void *mem_ctx
, DATA_BLOB in
, void *_out
);
213 bool (*encode
)(void *mem_ctx
, void *in
, DATA_BLOB
*out
);
218 struct ldap_message
*new_ldap_message(TALLOC_CTX
*mem_ctx
);
219 NTSTATUS
ldap_decode(struct asn1_data
*data
,
220 const struct ldap_control_handler
*control_handlers
,
221 struct ldap_message
*msg
);
222 bool ldap_encode(struct ldap_message
*msg
,
223 const struct ldap_control_handler
*control_handlers
,
224 DATA_BLOB
*result
, TALLOC_CTX
*mem_ctx
);
225 NTSTATUS
ldap_full_packet(void *private_data
, DATA_BLOB blob
, size_t *packet_size
);
227 bool asn1_read_OctetString_talloc(TALLOC_CTX
*mem_ctx
,
228 struct asn1_data
*data
,
229 const char **result
);
231 bool ldap_decode_attribs_bare(TALLOC_CTX
*mem_ctx
, struct asn1_data
*data
,
232 struct ldb_message_element
**attributes
,
233 int *num_attributes
);