2 Unix SMB/CIFS mplementation.
3 LDAP protocol helper functions for SAMBA
5 Copyright (C) Simo Sorce 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "../lib/util/asn1.h"
24 #include "libcli/ldap/ldap.h"
25 #include "lib/ldb/include/ldb.h"
26 #include "libcli/ldap/ldap_proto.h"
27 #include "dsdb/samdb/samdb.h"
29 static bool decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void *_out)
31 void **out = (void **)_out;
33 struct asn1_data *data = asn1_init(mem_ctx);
34 struct ldb_sort_resp_control *lsrc;
36 if (!data) return false;
38 if (!asn1_load(data, in)) {
42 lsrc = talloc(mem_ctx, struct ldb_sort_resp_control);
47 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
51 if (!asn1_read_enumerated(data, &(lsrc->result))) {
55 lsrc->attr_desc = NULL;
56 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
57 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
60 lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length);
61 if (!lsrc->attr_desc) {
66 if (!asn1_end_tag(data)) {
75 static bool decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void *_out)
77 void **out = (void **)_out;
80 struct asn1_data *data = asn1_init(mem_ctx);
81 struct ldb_server_sort_control **lssc;
84 if (!data) return false;
86 if (!asn1_load(data, in)) {
90 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
96 for (num = 0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); num++) {
97 lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2);
101 lssc[num] = talloc_zero(lssc, struct ldb_server_sort_control);
106 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
110 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
114 lssc[num]->attributeName = talloc_strndup(lssc[num], (const char *)attr.data, attr.length);
115 if (!lssc [num]->attributeName) {
119 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
120 if (!asn1_read_OctetString(data, mem_ctx, &rule)) {
123 lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length);
124 if (!lssc[num]->orderingRule) {
129 if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(1))) {
131 if (!asn1_read_BOOLEAN_context(data, &reverse, 1)) {
134 lssc[num]->reverse = reverse;
137 if (!asn1_end_tag(data)) {
146 if (!asn1_end_tag(data)) {
155 static bool decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void *_out)
157 void **out = (void **)_out;
158 struct asn1_data *data;
159 struct ldb_extended_dn_control *ledc;
161 /* The content of this control is optional */
162 if (in.length == 0) {
167 data = asn1_init(mem_ctx);
168 if (!data) return false;
170 if (!asn1_load(data, in)) {
174 ledc = talloc(mem_ctx, struct ldb_extended_dn_control);
179 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
183 if (!asn1_read_Integer(data, &(ledc->type))) {
187 if (!asn1_end_tag(data)) {
196 static bool decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void *_out)
198 void **out = (void **)_out;
199 struct asn1_data *data = asn1_init(mem_ctx);
200 struct ldb_sd_flags_control *lsdfc;
202 if (!data) return false;
204 if (!asn1_load(data, in)) {
208 lsdfc = talloc(mem_ctx, struct ldb_sd_flags_control);
213 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
217 if (!asn1_read_Integer(data, (int *) &(lsdfc->secinfo_flags))) {
221 if (!asn1_end_tag(data)) {
230 static bool decode_search_options_request(void *mem_ctx, DATA_BLOB in, void *_out)
232 void **out = (void **)_out;
233 struct asn1_data *data = asn1_init(mem_ctx);
234 struct ldb_search_options_control *lsoc;
236 if (!data) return false;
238 if (!asn1_load(data, in)) {
242 lsoc = talloc(mem_ctx, struct ldb_search_options_control);
247 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
251 if (!asn1_read_Integer(data, (int *) &(lsoc->search_options))) {
255 if (!asn1_end_tag(data)) {
264 static bool decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void *_out)
266 void **out = (void **)_out;
268 struct asn1_data *data = asn1_init(mem_ctx);
269 struct ldb_paged_control *lprc;
271 if (!data) return false;
273 if (!asn1_load(data, in)) {
277 lprc = talloc(mem_ctx, struct ldb_paged_control);
282 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
286 if (!asn1_read_Integer(data, &(lprc->size))) {
290 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
293 lprc->cookie_len = cookie.length;
294 if (lprc->cookie_len) {
295 lprc->cookie = talloc_memdup(lprc, cookie.data, cookie.length);
297 if (!(lprc->cookie)) {
304 if (!asn1_end_tag(data)) {
313 static bool decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void *_out)
315 void **out = (void **)_out;
317 struct asn1_data *data = asn1_init(mem_ctx);
318 struct ldb_dirsync_control *ldc;
320 if (!data) return false;
322 if (!asn1_load(data, in)) {
326 ldc = talloc(mem_ctx, struct ldb_dirsync_control);
331 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
335 if (!asn1_read_Integer(data, &(ldc->flags))) {
339 if (!asn1_read_Integer(data, &(ldc->max_attributes))) {
343 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
346 ldc->cookie_len = cookie.length;
347 if (ldc->cookie_len) {
348 ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length);
350 if (!(ldc->cookie)) {
357 if (!asn1_end_tag(data)) {
366 /* seem that this controls has 2 forms one in case it is used with
367 * a Search Request and another when used ina Search Response
369 static bool decode_asq_control(void *mem_ctx, DATA_BLOB in, void *_out)
371 void **out = (void **)_out;
372 DATA_BLOB source_attribute;
373 struct asn1_data *data = asn1_init(mem_ctx);
374 struct ldb_asq_control *lac;
376 if (!data) return false;
378 if (!asn1_load(data, in)) {
382 lac = talloc(mem_ctx, struct ldb_asq_control);
387 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
391 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
393 if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) {
396 lac->src_attr_len = source_attribute.length;
397 if (lac->src_attr_len) {
398 lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length);
400 if (!(lac->source_attribute)) {
404 lac->source_attribute = NULL;
409 } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) {
411 if (!asn1_read_enumerated(data, &(lac->result))) {
421 if (!asn1_end_tag(data)) {
430 static bool decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void *_out)
432 if (in.length != 0) {
439 static bool decode_notification_request(void *mem_ctx, DATA_BLOB in, void *_out)
441 if (in.length != 0) {
448 static bool decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void *_out)
450 if (in.length != 0) {
457 static bool decode_show_recycled_request(void *mem_ctx, DATA_BLOB in, void *_out)
459 if (in.length != 0) {
466 static bool decode_show_deactivated_link_request(void *mem_ctx, DATA_BLOB in, void *_out)
468 if (in.length != 0) {
475 static bool decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void *_out)
477 if (in.length != 0) {
484 static bool decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void *_out)
486 if (in.length != 0) {
493 static bool decode_vlv_request(void *mem_ctx, DATA_BLOB in, void *_out)
495 void **out = (void **)_out;
496 DATA_BLOB assertion_value, context_id;
497 struct asn1_data *data = asn1_init(mem_ctx);
498 struct ldb_vlv_req_control *lvrc;
500 if (!data) return false;
502 if (!asn1_load(data, in)) {
506 lvrc = talloc(mem_ctx, struct ldb_vlv_req_control);
511 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
515 if (!asn1_read_Integer(data, &(lvrc->beforeCount))) {
519 if (!asn1_read_Integer(data, &(lvrc->afterCount))) {
523 if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
527 if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
531 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
535 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) {
539 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) {
543 if (!asn1_end_tag(data)) { /*SEQUENCE*/
547 if (!asn1_end_tag(data)) { /*CONTEXT*/
555 if (!asn1_start_tag(data, ASN1_CONTEXT(1))) {
559 if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) {
562 lvrc->match.gtOrEq.value_len = assertion_value.length;
563 if (lvrc->match.gtOrEq.value_len) {
564 lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length);
566 if (!(lvrc->match.gtOrEq.value)) {
570 lvrc->match.gtOrEq.value = NULL;
573 if (!asn1_end_tag(data)) { /*CONTEXT*/
578 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
579 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
582 lvrc->ctxid_len = context_id.length;
583 if (lvrc->ctxid_len) {
584 lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length);
586 if (!(lvrc->contextId)) {
590 lvrc->contextId = NULL;
593 lvrc->contextId = NULL;
597 if (!asn1_end_tag(data)) {
606 static bool decode_vlv_response(void *mem_ctx, DATA_BLOB in, void *_out)
608 void **out = (void **)_out;
609 DATA_BLOB context_id;
610 struct asn1_data *data = asn1_init(mem_ctx);
611 struct ldb_vlv_resp_control *lvrc;
613 if (!data) return false;
615 if (!asn1_load(data, in)) {
619 lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control);
624 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
628 if (!asn1_read_Integer(data, &(lvrc->targetPosition))) {
632 if (!asn1_read_Integer(data, &(lvrc->contentCount))) {
636 if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) {
640 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
641 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
644 lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length);
645 if (!lvrc->contextId) {
648 lvrc->ctxid_len = context_id.length;
650 lvrc->contextId = NULL;
654 if (!asn1_end_tag(data)) {
663 static bool encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out)
665 struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control);
666 struct asn1_data *data = asn1_init(mem_ctx);
668 if (!data) return false;
670 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
674 if (!asn1_write_enumerated(data, lsrc->result)) {
678 if (lsrc->attr_desc) {
679 if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) {
684 if (!asn1_pop_tag(data)) {
688 *out = data_blob_talloc(mem_ctx, data->data, data->length);
689 if (out->data == NULL) {
697 static bool encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out)
699 struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *);
700 struct asn1_data *data = asn1_init(mem_ctx);
703 if (!data) return false;
705 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
711 SortKeyList ::= SEQUENCE OF SEQUENCE {
712 attributeType AttributeDescription,
713 orderingRule [0] MatchingRuleId OPTIONAL,
714 reverseOrder [1] BOOLEAN DEFAULT FALSE }
716 for (num = 0; lssc[num]; num++) {
717 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
721 if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) {
725 if (lssc[num]->orderingRule) {
726 if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) {
731 if (lssc[num]->reverse) {
732 if (!asn1_write_BOOLEAN_context(data, lssc[num]->reverse, 1)) {
737 if (!asn1_pop_tag(data)) {
742 if (!asn1_pop_tag(data)) {
746 *out = data_blob_talloc(mem_ctx, data->data, data->length);
747 if (out->data == NULL) {
755 static bool encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out)
757 struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control);
758 struct asn1_data *data;
761 *out = data_blob(NULL, 0);
765 data = asn1_init(mem_ctx);
767 if (!data) return false;
769 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
773 if (!asn1_write_Integer(data, ledc->type)) {
777 if (!asn1_pop_tag(data)) {
781 *out = data_blob_talloc(mem_ctx, data->data, data->length);
782 if (out->data == NULL) {
790 static bool encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out)
792 struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control);
793 struct asn1_data *data = asn1_init(mem_ctx);
795 if (!data) return false;
797 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
801 if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) {
805 if (!asn1_pop_tag(data)) {
809 *out = data_blob_talloc(mem_ctx, data->data, data->length);
810 if (out->data == NULL) {
818 static bool encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out)
820 struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control);
821 struct asn1_data *data = asn1_init(mem_ctx);
823 if (!data) return false;
825 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
829 if (!asn1_write_Integer(data, lsoc->search_options)) {
833 if (!asn1_pop_tag(data)) {
837 *out = data_blob_talloc(mem_ctx, data->data, data->length);
838 if (out->data == NULL) {
846 static bool encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out)
848 struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control);
849 struct asn1_data *data = asn1_init(mem_ctx);
851 if (!data) return false;
853 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
857 if (!asn1_write_Integer(data, lprc->size)) {
861 if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) {
865 if (!asn1_pop_tag(data)) {
869 *out = data_blob_talloc(mem_ctx, data->data, data->length);
870 if (out->data == NULL) {
878 /* seem that this controls has 2 forms one in case it is used with
879 * a Search Request and another when used ina Search Response
881 static bool encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out)
883 struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control);
884 struct asn1_data *data = asn1_init(mem_ctx);
886 if (!data) return false;
888 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
894 if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) {
898 if (!asn1_write_enumerated(data, lac->result)) {
903 if (!asn1_pop_tag(data)) {
907 *out = data_blob_talloc(mem_ctx, data->data, data->length);
908 if (out->data == NULL) {
916 static bool encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out)
918 struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control);
919 struct asn1_data *data = asn1_init(mem_ctx);
921 if (!data) return false;
923 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
927 if (!asn1_write_Integer(data, ldc->flags)) {
931 if (!asn1_write_Integer(data, ldc->max_attributes)) {
935 if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) {
939 if (!asn1_pop_tag(data)) {
943 *out = data_blob_talloc(mem_ctx, data->data, data->length);
944 if (out->data == NULL) {
952 static bool encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out)
958 *out = data_blob(NULL, 0);
962 static bool encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out)
968 *out = data_blob(NULL, 0);
972 static bool encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out)
978 *out = data_blob(NULL, 0);
982 static bool encode_show_recycled_request(void *mem_ctx, void *in, DATA_BLOB *out)
988 *out = data_blob(NULL, 0);
992 static bool encode_show_deactivated_link_request(void *mem_ctx, void *in, DATA_BLOB *out)
998 *out = data_blob(NULL, 0);
1002 static bool encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out)
1008 *out = data_blob(NULL, 0);
1012 static bool encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out)
1018 *out = data_blob(NULL, 0);
1022 static bool encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out)
1024 struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control);
1025 struct asn1_data *data = asn1_init(mem_ctx);
1027 if (!data) return false;
1029 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1033 if (!asn1_write_Integer(data, lvrc->beforeCount)) {
1037 if (!asn1_write_Integer(data, lvrc->afterCount)) {
1041 if (lvrc->type == 0) {
1042 if (!asn1_push_tag(data, ASN1_CONTEXT(0))) {
1046 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1050 if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) {
1054 if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) {
1058 if (!asn1_pop_tag(data)) { /*SEQUENCE*/
1062 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1066 if (!asn1_push_tag(data, ASN1_CONTEXT(1))) {
1070 if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) {
1074 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1079 if (lvrc->ctxid_len) {
1080 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1085 if (!asn1_pop_tag(data)) {
1089 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1090 if (out->data == NULL) {
1098 static bool encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out)
1100 struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control);
1101 struct asn1_data *data = asn1_init(mem_ctx);
1103 if (!data) return false;
1105 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1109 if (!asn1_write_Integer(data, lvrc->targetPosition)) {
1113 if (!asn1_write_Integer(data, lvrc->contentCount)) {
1117 if (!asn1_write_enumerated(data, lvrc->vlv_result)) {
1121 if (lvrc->ctxid_len) {
1122 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1127 if (!asn1_pop_tag(data)) {
1131 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1132 if (out->data == NULL) {
1140 static bool encode_openldap_dereference(void *mem_ctx, void *in, DATA_BLOB *out)
1142 struct dsdb_openldap_dereference_control *control = talloc_get_type(in, struct dsdb_openldap_dereference_control);
1144 struct asn1_data *data = asn1_init(mem_ctx);
1146 if (!data) return false;
1148 if (!control) return false;
1150 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1154 for (i=0; control->dereference && control->dereference[i]; i++) {
1155 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1158 if (!asn1_write_OctetString(data, control->dereference[i]->source_attribute, strlen(control->dereference[i]->source_attribute))) {
1161 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1164 for (j=0; control->dereference && control->dereference[i]->dereference_attribute[j]; j++) {
1165 if (!asn1_write_OctetString(data, control->dereference[i]->dereference_attribute[j],
1166 strlen(control->dereference[i]->dereference_attribute[j]))) {
1176 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1177 if (out->data == NULL) {
1184 static bool decode_openldap_dereference(void *mem_ctx, DATA_BLOB in, void *_out)
1186 void **out = (void **)_out;
1187 struct asn1_data *data = asn1_init(mem_ctx);
1188 struct dsdb_openldap_dereference_result_control *control;
1189 struct dsdb_openldap_dereference_result **r = NULL;
1191 if (!data) return false;
1193 control = talloc(mem_ctx, struct dsdb_openldap_dereference_result_control);
1194 if (!control) return false;
1196 if (!asn1_load(data, in)) {
1200 control = talloc(mem_ctx, struct dsdb_openldap_dereference_result_control);
1205 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1209 while (asn1_tag_remaining(data) > 0) {
1210 r = talloc_realloc(control, r, struct dsdb_openldap_dereference_result *, i + 2);
1214 r[i] = talloc_zero(r, struct dsdb_openldap_dereference_result);
1219 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1223 asn1_read_OctetString_talloc(r[i], data, &r[i]->source_attribute);
1224 asn1_read_OctetString_talloc(r[i], data, &r[i]->dereferenced_dn);
1225 if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
1226 if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
1230 ldap_decode_attribs_bare(r, data, &r[i]->attributes,
1231 &r[i]->num_attributes);
1233 if (!asn1_end_tag(data)) {
1237 if (!asn1_end_tag(data)) {
1244 if (!asn1_end_tag(data)) {
1248 control->attributes = r;
1254 static bool encode_relax_request(void *mem_ctx, void *in, DATA_BLOB *out)
1260 *out = data_blob(NULL, 0);
1264 static bool decode_relax_request(void *mem_ctx, DATA_BLOB in, void *_out)
1266 if (in.length != 0) {
1273 static const struct ldap_control_handler ldap_known_controls[] = {
1274 { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request },
1275 { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request },
1276 { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request },
1277 { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response },
1278 { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
1279 { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request },
1280 { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request },
1281 { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request },
1282 { "1.2.840.113556.1.4.2064", decode_show_recycled_request, encode_show_recycled_request },
1283 { "1.2.840.113556.1.4.2065", decode_show_deactivated_link_request, encode_show_deactivated_link_request },
1284 { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request },
1285 { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request },
1286 { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request },
1287 { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request },
1288 { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request },
1289 { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request },
1290 { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response },
1291 /* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */
1292 { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL },
1293 /* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */
1294 { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL },
1295 { DSDB_OPENLDAP_DEREFERENCE_CONTROL, decode_openldap_dereference, encode_openldap_dereference},
1296 { LDB_CONTROL_RELAX_OID, decode_relax_request, encode_relax_request },
1297 { NULL, NULL, NULL }
1300 const struct ldap_control_handler *samba_ldap_control_handlers(void)
1302 return ldap_known_controls;