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/>.
24 #include "libcli/ldap/ldap_errors.h"
25 #include "lib/ldb/include/ldb.h"
26 #include "librpc/gen_ndr/misc.h"
28 enum ldap_request_tag {
29 LDAP_TAG_BindRequest = 0,
30 LDAP_TAG_BindResponse = 1,
31 LDAP_TAG_UnbindRequest = 2,
32 LDAP_TAG_SearchRequest = 3,
33 LDAP_TAG_SearchResultEntry = 4,
34 LDAP_TAG_SearchResultDone = 5,
35 LDAP_TAG_ModifyRequest = 6,
36 LDAP_TAG_ModifyResponse = 7,
37 LDAP_TAG_AddRequest = 8,
38 LDAP_TAG_AddResponse = 9,
39 LDAP_TAG_DelRequest = 10,
40 LDAP_TAG_DelResponse = 11,
41 LDAP_TAG_ModifyDNRequest = 12,
42 LDAP_TAG_ModifyDNResponse = 13,
43 LDAP_TAG_CompareRequest = 14,
44 LDAP_TAG_CompareResponse = 15,
45 LDAP_TAG_AbandonRequest = 16,
46 LDAP_TAG_SearchResultReference = 19,
47 LDAP_TAG_ExtendedRequest = 23,
48 LDAP_TAG_ExtendedResponse = 24
51 enum ldap_auth_mechanism {
52 LDAP_AUTH_MECH_SIMPLE = 0,
53 LDAP_AUTH_MECH_SASL = 3
59 const char *errormessage;
63 struct ldap_BindRequest {
66 enum ldap_auth_mechanism mechanism;
70 const char *mechanism;
71 DATA_BLOB *secblob;/* optional */
76 struct ldap_BindResponse {
77 struct ldap_Result response;
79 DATA_BLOB *secblob;/* optional */
83 struct ldap_UnbindRequest {
88 LDAP_SEARCH_SCOPE_BASE = 0,
89 LDAP_SEARCH_SCOPE_SINGLE = 1,
90 LDAP_SEARCH_SCOPE_SUB = 2
94 LDAP_DEREFERENCE_NEVER = 0,
95 LDAP_DEREFERENCE_IN_SEARCHING = 1,
96 LDAP_DEREFERENCE_FINDING_BASE = 2,
97 LDAP_DEREFERENCE_ALWAYS
100 struct ldap_SearchRequest {
102 enum ldap_scope scope;
103 enum ldap_deref deref;
107 struct ldb_parse_tree *tree;
109 const char **attributes;
112 struct ldap_SearchResEntry {
115 struct ldb_message_element *attributes;
118 struct ldap_SearchResRef {
119 const char *referral;
122 enum ldap_modify_type {
123 LDAP_MODIFY_NONE = -1,
125 LDAP_MODIFY_DELETE = 1,
126 LDAP_MODIFY_REPLACE = 2
130 enum ldap_modify_type type;
131 struct ldb_message_element attrib;
134 struct ldap_ModifyRequest {
137 struct ldap_mod *mods;
140 struct ldap_AddRequest {
143 struct ldb_message_element *attributes;
146 struct ldap_DelRequest {
150 struct ldap_ModifyDNRequest {
154 const char *newsuperior;/* optional */
157 struct ldap_CompareRequest {
159 const char *attribute;
163 struct ldap_AbandonRequest {
167 struct ldap_ExtendedRequest {
169 DATA_BLOB *value;/* optional */
172 struct ldap_ExtendedResponse {
173 struct ldap_Result response;
174 const char *oid;/* optional */
175 DATA_BLOB *value;/* optional */
179 struct ldap_Result GeneralResult;
180 struct ldap_BindRequest BindRequest;
181 struct ldap_BindResponse BindResponse;
182 struct ldap_UnbindRequest UnbindRequest;
183 struct ldap_SearchRequest SearchRequest;
184 struct ldap_SearchResEntry SearchResultEntry;
185 struct ldap_Result SearchResultDone;
186 struct ldap_SearchResRef SearchResultReference;
187 struct ldap_ModifyRequest ModifyRequest;
188 struct ldap_Result ModifyResponse;
189 struct ldap_AddRequest AddRequest;
190 struct ldap_Result AddResponse;
191 struct ldap_DelRequest DelRequest;
192 struct ldap_Result DelResponse;
193 struct ldap_ModifyDNRequest ModifyDNRequest;
194 struct ldap_Result ModifyDNResponse;
195 struct ldap_CompareRequest CompareRequest;
196 struct ldap_Result CompareResponse;
197 struct ldap_AbandonRequest AbandonRequest;
198 struct ldap_ExtendedRequest ExtendedRequest;
199 struct ldap_ExtendedResponse ExtendedResponse;
203 struct ldap_message {
205 enum ldap_request_tag type;
206 union ldap_Request r;
207 struct ldb_control **controls;
208 bool *controls_decoded;
211 struct tevent_context;
212 struct cli_credentials;
216 struct ldap_message *new_ldap_message(TALLOC_CTX *mem_ctx);
217 NTSTATUS ldap_decode(struct asn1_data *data, struct ldap_message *msg);
218 bool ldap_encode(struct ldap_message *msg, DATA_BLOB *result, TALLOC_CTX *mem_ctx);