xattr: fix listing EAs on *BSD for non-root users
[Samba.git] / libcli / ldap / ldap_message.h
blob94eaed2f962489ed56fa4b7da00282fc35f88b9d
1 /*
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"
25 #if _SAMBA_BUILD_ == 3
26 #include "lib/ldb_compat.h"
27 #else
28 #include <ldb.h>
29 #endif
31 enum ldap_request_tag {
32 LDAP_TAG_BindRequest = 0,
33 LDAP_TAG_BindResponse = 1,
34 LDAP_TAG_UnbindRequest = 2,
35 LDAP_TAG_SearchRequest = 3,
36 LDAP_TAG_SearchResultEntry = 4,
37 LDAP_TAG_SearchResultDone = 5,
38 LDAP_TAG_ModifyRequest = 6,
39 LDAP_TAG_ModifyResponse = 7,
40 LDAP_TAG_AddRequest = 8,
41 LDAP_TAG_AddResponse = 9,
42 LDAP_TAG_DelRequest = 10,
43 LDAP_TAG_DelResponse = 11,
44 LDAP_TAG_ModifyDNRequest = 12,
45 LDAP_TAG_ModifyDNResponse = 13,
46 LDAP_TAG_CompareRequest = 14,
47 LDAP_TAG_CompareResponse = 15,
48 LDAP_TAG_AbandonRequest = 16,
49 LDAP_TAG_SearchResultReference = 19,
50 LDAP_TAG_ExtendedRequest = 23,
51 LDAP_TAG_ExtendedResponse = 24
54 enum ldap_auth_mechanism {
55 LDAP_AUTH_MECH_SIMPLE = 0,
56 LDAP_AUTH_MECH_SASL = 3
59 struct ldap_Result {
60 int resultcode;
61 const char *dn;
62 const char *errormessage;
63 const char *referral;
66 struct ldap_BindRequest {
67 int version;
68 const char *dn;
69 enum ldap_auth_mechanism mechanism;
70 union {
71 const char *password;
72 struct {
73 const char *mechanism;
74 DATA_BLOB *secblob;/* optional */
75 } SASL;
76 } creds;
79 struct ldap_BindResponse {
80 struct ldap_Result response;
81 union {
82 DATA_BLOB *secblob;/* optional */
83 } SASL;
86 struct ldap_UnbindRequest {
87 uint8_t __dummy;
90 enum ldap_scope {
91 LDAP_SEARCH_SCOPE_BASE = 0,
92 LDAP_SEARCH_SCOPE_SINGLE = 1,
93 LDAP_SEARCH_SCOPE_SUB = 2
96 enum ldap_deref {
97 LDAP_DEREFERENCE_NEVER = 0,
98 LDAP_DEREFERENCE_IN_SEARCHING = 1,
99 LDAP_DEREFERENCE_FINDING_BASE = 2,
100 LDAP_DEREFERENCE_ALWAYS
103 struct ldap_SearchRequest {
104 const char *basedn;
105 enum ldap_scope scope;
106 enum ldap_deref deref;
107 uint32_t timelimit;
108 uint32_t sizelimit;
109 bool attributesonly;
110 struct ldb_parse_tree *tree;
111 int num_attributes;
112 const char * const *attributes;
115 struct ldap_SearchResEntry {
116 const char *dn;
117 int num_attributes;
118 struct ldb_message_element *attributes;
121 struct ldap_SearchResRef {
122 const char *referral;
125 enum ldap_modify_type {
126 LDAP_MODIFY_NONE = -1,
127 LDAP_MODIFY_ADD = 0,
128 LDAP_MODIFY_DELETE = 1,
129 LDAP_MODIFY_REPLACE = 2
132 struct ldap_mod {
133 enum ldap_modify_type type;
134 struct ldb_message_element attrib;
137 struct ldap_ModifyRequest {
138 const char *dn;
139 int num_mods;
140 struct ldap_mod *mods;
143 struct ldap_AddRequest {
144 const char *dn;
145 int num_attributes;
146 struct ldb_message_element *attributes;
149 struct ldap_DelRequest {
150 const char *dn;
153 struct ldap_ModifyDNRequest {
154 const char *dn;
155 const char *newrdn;
156 bool deleteolddn;
157 const char *newsuperior;/* optional */
160 struct ldap_CompareRequest {
161 const char *dn;
162 const char *attribute;
163 DATA_BLOB value;
166 struct ldap_AbandonRequest {
167 int messageid;
170 struct ldap_ExtendedRequest {
171 const char *oid;
172 DATA_BLOB *value;/* optional */
175 struct ldap_ExtendedResponse {
176 struct ldap_Result response;
177 const char *oid;/* optional */
178 DATA_BLOB *value;/* optional */
181 union ldap_Request {
182 struct ldap_Result GeneralResult;
183 struct ldap_BindRequest BindRequest;
184 struct ldap_BindResponse BindResponse;
185 struct ldap_UnbindRequest UnbindRequest;
186 struct ldap_SearchRequest SearchRequest;
187 struct ldap_SearchResEntry SearchResultEntry;
188 struct ldap_Result SearchResultDone;
189 struct ldap_SearchResRef SearchResultReference;
190 struct ldap_ModifyRequest ModifyRequest;
191 struct ldap_Result ModifyResponse;
192 struct ldap_AddRequest AddRequest;
193 struct ldap_Result AddResponse;
194 struct ldap_DelRequest DelRequest;
195 struct ldap_Result DelResponse;
196 struct ldap_ModifyDNRequest ModifyDNRequest;
197 struct ldap_Result ModifyDNResponse;
198 struct ldap_CompareRequest CompareRequest;
199 struct ldap_Result CompareResponse;
200 struct ldap_AbandonRequest AbandonRequest;
201 struct ldap_ExtendedRequest ExtendedRequest;
202 struct ldap_ExtendedResponse ExtendedResponse;
206 struct ldap_message {
207 int messageid;
208 enum ldap_request_tag type;
209 union ldap_Request r;
210 struct ldb_control **controls;
211 bool *controls_decoded;
214 struct ldap_control_handler {
215 const char *oid;
216 bool (*decode)(void *mem_ctx, DATA_BLOB in, void *_out);
217 bool (*encode)(void *mem_ctx, void *in, DATA_BLOB *out);
220 struct asn1_data;
222 struct ldap_message *new_ldap_message(TALLOC_CTX *mem_ctx);
223 NTSTATUS ldap_decode(struct asn1_data *data,
224 const struct ldap_control_handler *control_handlers,
225 struct ldap_message *msg);
226 bool ldap_encode(struct ldap_message *msg,
227 const struct ldap_control_handler *control_handlers,
228 DATA_BLOB *result, TALLOC_CTX *mem_ctx);
229 NTSTATUS ldap_full_packet(void *private_data, DATA_BLOB blob, size_t *packet_size);
231 bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx,
232 struct asn1_data *data,
233 const char **result);
235 void ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
236 struct ldb_message_element **attributes,
237 int *num_attributes);
239 #endif