util:ldb Allow multiple entries to be added in one LDIF snippit
[Samba/ekacnet.git] / libcli / ldap / ldap_message.h
blobc50018465c88d83c30fbcd28d1336338e1bd2f9a
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 #include "lib/ldb/include/ldb.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
55 struct ldap_Result {
56 int resultcode;
57 const char *dn;
58 const char *errormessage;
59 const char *referral;
62 struct ldap_BindRequest {
63 int version;
64 const char *dn;
65 enum ldap_auth_mechanism mechanism;
66 union {
67 const char *password;
68 struct {
69 const char *mechanism;
70 DATA_BLOB *secblob;/* optional */
71 } SASL;
72 } creds;
75 struct ldap_BindResponse {
76 struct ldap_Result response;
77 union {
78 DATA_BLOB *secblob;/* optional */
79 } SASL;
82 struct ldap_UnbindRequest {
83 uint8_t __dummy;
86 enum ldap_scope {
87 LDAP_SEARCH_SCOPE_BASE = 0,
88 LDAP_SEARCH_SCOPE_SINGLE = 1,
89 LDAP_SEARCH_SCOPE_SUB = 2
92 enum ldap_deref {
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 {
100 const char *basedn;
101 enum ldap_scope scope;
102 enum ldap_deref deref;
103 uint32_t timelimit;
104 uint32_t sizelimit;
105 bool attributesonly;
106 struct ldb_parse_tree *tree;
107 int num_attributes;
108 const char * const *attributes;
111 struct ldap_SearchResEntry {
112 const char *dn;
113 int num_attributes;
114 struct ldb_message_element *attributes;
117 struct ldap_SearchResRef {
118 const char *referral;
121 enum ldap_modify_type {
122 LDAP_MODIFY_NONE = -1,
123 LDAP_MODIFY_ADD = 0,
124 LDAP_MODIFY_DELETE = 1,
125 LDAP_MODIFY_REPLACE = 2
128 struct ldap_mod {
129 enum ldap_modify_type type;
130 struct ldb_message_element attrib;
133 struct ldap_ModifyRequest {
134 const char *dn;
135 int num_mods;
136 struct ldap_mod *mods;
139 struct ldap_AddRequest {
140 const char *dn;
141 int num_attributes;
142 struct ldb_message_element *attributes;
145 struct ldap_DelRequest {
146 const char *dn;
149 struct ldap_ModifyDNRequest {
150 const char *dn;
151 const char *newrdn;
152 bool deleteolddn;
153 const char *newsuperior;/* optional */
156 struct ldap_CompareRequest {
157 const char *dn;
158 const char *attribute;
159 DATA_BLOB value;
162 struct ldap_AbandonRequest {
163 int messageid;
166 struct ldap_ExtendedRequest {
167 const char *oid;
168 DATA_BLOB *value;/* optional */
171 struct ldap_ExtendedResponse {
172 struct ldap_Result response;
173 const char *oid;/* optional */
174 DATA_BLOB *value;/* optional */
177 union ldap_Request {
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 {
203 int messageid;
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 {
211 const char *oid;
212 bool (*decode)(void *mem_ctx, DATA_BLOB in, void *_out);
213 bool (*encode)(void *mem_ctx, void *in, DATA_BLOB *out);
216 struct asn1_data;
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 void ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
232 struct ldb_message_element **attributes,
233 int *num_attributes);
235 #endif