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 struct control_handler {
31 bool (*decode)(void *mem_ctx, DATA_BLOB in, void **out);
32 bool (*encode)(void *mem_ctx, void *in, DATA_BLOB *out);
35 static bool decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out)
38 struct asn1_data *data = asn1_init(mem_ctx);
39 struct ldb_sort_resp_control *lsrc;
41 if (!data) return false;
43 if (!asn1_load(data, in)) {
47 lsrc = talloc(mem_ctx, struct ldb_sort_resp_control);
52 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
56 if (!asn1_read_enumerated(data, &(lsrc->result))) {
60 lsrc->attr_desc = NULL;
61 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
62 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
65 lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length);
66 if (!lsrc->attr_desc) {
71 if (!asn1_end_tag(data)) {
80 static bool decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out)
84 struct asn1_data *data = asn1_init(mem_ctx);
85 struct ldb_server_sort_control **lssc;
88 if (!data) return false;
90 if (!asn1_load(data, in)) {
94 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
100 for (num = 0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); num++) {
101 lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2);
105 lssc[num] = talloc_zero(lssc, struct ldb_server_sort_control);
110 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
114 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
118 lssc[num]->attributeName = talloc_strndup(lssc[num], (const char *)attr.data, attr.length);
119 if (!lssc [num]->attributeName) {
123 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
124 if (!asn1_read_OctetString(data, mem_ctx, &rule)) {
127 lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length);
128 if (!lssc[num]->orderingRule) {
133 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
135 if (!asn1_read_BOOLEAN(data, &reverse)) {
138 lssc[num]->reverse = reverse;
141 if (!asn1_end_tag(data)) {
150 if (!asn1_end_tag(data)) {
159 static bool decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out)
161 struct asn1_data *data;
162 struct ldb_extended_dn_control *ledc;
164 /* The content of this control is optional */
165 if (in.length == 0) {
170 data = asn1_init(mem_ctx);
171 if (!data) return false;
173 if (!asn1_load(data, in)) {
177 ledc = talloc(mem_ctx, struct ldb_extended_dn_control);
182 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
186 if (!asn1_read_Integer(data, &(ledc->type))) {
190 if (!asn1_end_tag(data)) {
199 static bool decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out)
201 struct asn1_data *data = asn1_init(mem_ctx);
202 struct ldb_sd_flags_control *lsdfc;
204 if (!data) return false;
206 if (!asn1_load(data, in)) {
210 lsdfc = talloc(mem_ctx, struct ldb_sd_flags_control);
215 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
219 if (!asn1_read_Integer(data, &(lsdfc->secinfo_flags))) {
223 if (!asn1_end_tag(data)) {
232 static bool decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **out)
234 struct asn1_data *data = asn1_init(mem_ctx);
235 struct ldb_search_options_control *lsoc;
237 if (!data) return false;
239 if (!asn1_load(data, in)) {
243 lsoc = talloc(mem_ctx, struct ldb_search_options_control);
248 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
252 if (!asn1_read_Integer(data, &(lsoc->search_options))) {
256 if (!asn1_end_tag(data)) {
265 static bool decode_paged_results_request(void *mem_ctx, DATA_BLOB in, 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)
316 struct asn1_data *data = asn1_init(mem_ctx);
317 struct ldb_dirsync_control *ldc;
319 if (!data) return false;
321 if (!asn1_load(data, in)) {
325 ldc = talloc(mem_ctx, struct ldb_dirsync_control);
330 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
334 if (!asn1_read_Integer(data, &(ldc->flags))) {
338 if (!asn1_read_Integer(data, &(ldc->max_attributes))) {
342 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
345 ldc->cookie_len = cookie.length;
346 if (ldc->cookie_len) {
347 ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length);
349 if (!(ldc->cookie)) {
356 if (!asn1_end_tag(data)) {
365 /* seem that this controls has 2 forms one in case it is used with
366 * a Search Request and another when used ina Search Response
368 static bool decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out)
370 DATA_BLOB source_attribute;
371 struct asn1_data *data = asn1_init(mem_ctx);
372 struct ldb_asq_control *lac;
374 if (!data) return false;
376 if (!asn1_load(data, in)) {
380 lac = talloc(mem_ctx, struct ldb_asq_control);
385 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
389 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
391 if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) {
394 lac->src_attr_len = source_attribute.length;
395 if (lac->src_attr_len) {
396 lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length);
398 if (!(lac->source_attribute)) {
402 lac->source_attribute = NULL;
407 } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) {
409 if (!asn1_read_enumerated(data, &(lac->result))) {
419 if (!asn1_end_tag(data)) {
428 static bool decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out)
430 if (in.length != 0) {
437 static bool decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out)
439 if (in.length != 0) {
446 static bool decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out)
448 if (in.length != 0) {
455 static bool decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out)
457 if (in.length != 0) {
464 static bool decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out)
466 if (in.length != 0) {
473 static bool decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out)
475 DATA_BLOB assertion_value, context_id;
476 struct asn1_data *data = asn1_init(mem_ctx);
477 struct ldb_vlv_req_control *lvrc;
479 if (!data) return false;
481 if (!asn1_load(data, in)) {
485 lvrc = talloc(mem_ctx, struct ldb_vlv_req_control);
490 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
494 if (!asn1_read_Integer(data, &(lvrc->beforeCount))) {
498 if (!asn1_read_Integer(data, &(lvrc->afterCount))) {
502 if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
506 if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
510 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
514 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) {
518 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) {
522 if (!asn1_end_tag(data)) { /*SEQUENCE*/
526 if (!asn1_end_tag(data)) { /*CONTEXT*/
534 if (!asn1_start_tag(data, ASN1_CONTEXT(1))) {
538 if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) {
541 lvrc->match.gtOrEq.value_len = assertion_value.length;
542 if (lvrc->match.gtOrEq.value_len) {
543 lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length);
545 if (!(lvrc->match.gtOrEq.value)) {
549 lvrc->match.gtOrEq.value = NULL;
552 if (!asn1_end_tag(data)) { /*CONTEXT*/
557 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
558 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
561 lvrc->ctxid_len = context_id.length;
562 if (lvrc->ctxid_len) {
563 lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length);
565 if (!(lvrc->contextId)) {
569 lvrc->contextId = NULL;
572 lvrc->contextId = NULL;
576 if (!asn1_end_tag(data)) {
585 static bool decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out)
587 DATA_BLOB context_id;
588 struct asn1_data *data = asn1_init(mem_ctx);
589 struct ldb_vlv_resp_control *lvrc;
591 if (!data) return false;
593 if (!asn1_load(data, in)) {
597 lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control);
602 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
606 if (!asn1_read_Integer(data, &(lvrc->targetPosition))) {
610 if (!asn1_read_Integer(data, &(lvrc->contentCount))) {
614 if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) {
618 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
619 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
622 lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length);
623 if (!lvrc->contextId) {
626 lvrc->ctxid_len = context_id.length;
628 lvrc->contextId = NULL;
632 if (!asn1_end_tag(data)) {
641 static bool encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out)
643 struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control);
644 struct asn1_data *data = asn1_init(mem_ctx);
646 if (!data) return false;
648 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
652 if (!asn1_write_enumerated(data, lsrc->result)) {
656 if (lsrc->attr_desc) {
657 if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) {
662 if (!asn1_pop_tag(data)) {
666 *out = data_blob_talloc(mem_ctx, data->data, data->length);
667 if (out->data == NULL) {
675 static bool encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out)
677 struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *);
678 struct asn1_data *data = asn1_init(mem_ctx);
681 if (!data) return false;
683 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
687 for (num = 0; lssc[num]; num++) {
688 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
692 if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) {
696 if (lssc[num]->orderingRule) {
697 if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) {
702 if (lssc[num]->reverse) {
703 if (!asn1_write_BOOLEAN(data, lssc[num]->reverse)) {
708 if (!asn1_pop_tag(data)) {
713 if (!asn1_pop_tag(data)) {
717 *out = data_blob_talloc(mem_ctx, data->data, data->length);
718 if (out->data == NULL) {
726 static bool encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out)
728 struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control);
729 struct asn1_data *data;
732 *out = data_blob(NULL, 0);
736 data = asn1_init(mem_ctx);
738 if (!data) return false;
740 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
744 if (!asn1_write_Integer(data, ledc->type)) {
748 if (!asn1_pop_tag(data)) {
752 *out = data_blob_talloc(mem_ctx, data->data, data->length);
753 if (out->data == NULL) {
761 static bool encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out)
763 struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control);
764 struct asn1_data *data = asn1_init(mem_ctx);
766 if (!data) return false;
768 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
772 if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) {
776 if (!asn1_pop_tag(data)) {
780 *out = data_blob_talloc(mem_ctx, data->data, data->length);
781 if (out->data == NULL) {
789 static bool encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out)
791 struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control);
792 struct asn1_data *data = asn1_init(mem_ctx);
794 if (!data) return false;
796 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
800 if (!asn1_write_Integer(data, lsoc->search_options)) {
804 if (!asn1_pop_tag(data)) {
808 *out = data_blob_talloc(mem_ctx, data->data, data->length);
809 if (out->data == NULL) {
817 static bool encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out)
819 struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control);
820 struct asn1_data *data = asn1_init(mem_ctx);
822 if (!data) return false;
824 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
828 if (!asn1_write_Integer(data, lprc->size)) {
832 if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) {
836 if (!asn1_pop_tag(data)) {
840 *out = data_blob_talloc(mem_ctx, data->data, data->length);
841 if (out->data == NULL) {
849 /* seem that this controls has 2 forms one in case it is used with
850 * a Search Request and another when used ina Search Response
852 static bool encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out)
854 struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control);
855 struct asn1_data *data = asn1_init(mem_ctx);
857 if (!data) return false;
859 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
865 if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) {
869 if (!asn1_write_enumerated(data, lac->result)) {
874 if (!asn1_pop_tag(data)) {
878 *out = data_blob_talloc(mem_ctx, data->data, data->length);
879 if (out->data == NULL) {
887 static bool encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out)
889 struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control);
890 struct asn1_data *data = asn1_init(mem_ctx);
892 if (!data) return false;
894 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
898 if (!asn1_write_Integer(data, ldc->flags)) {
902 if (!asn1_write_Integer(data, ldc->max_attributes)) {
906 if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) {
910 if (!asn1_pop_tag(data)) {
914 *out = data_blob_talloc(mem_ctx, data->data, data->length);
915 if (out->data == NULL) {
923 static bool encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out)
929 *out = data_blob(NULL, 0);
933 static bool encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out)
939 *out = data_blob(NULL, 0);
943 static bool encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out)
949 *out = data_blob(NULL, 0);
953 static bool encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out)
959 *out = data_blob(NULL, 0);
963 static bool encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out)
969 *out = data_blob(NULL, 0);
973 static bool encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out)
975 struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control);
976 struct asn1_data *data = asn1_init(mem_ctx);
978 if (!data) return false;
980 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
984 if (!asn1_write_Integer(data, lvrc->beforeCount)) {
988 if (!asn1_write_Integer(data, lvrc->afterCount)) {
992 if (lvrc->type == 0) {
993 if (!asn1_push_tag(data, ASN1_CONTEXT(0))) {
997 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1001 if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) {
1005 if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) {
1009 if (!asn1_pop_tag(data)) { /*SEQUENCE*/
1013 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1017 if (!asn1_push_tag(data, ASN1_CONTEXT(1))) {
1021 if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) {
1025 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1030 if (lvrc->ctxid_len) {
1031 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1036 if (!asn1_pop_tag(data)) {
1040 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1041 if (out->data == NULL) {
1049 static bool encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out)
1051 struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control);
1052 struct asn1_data *data = asn1_init(mem_ctx);
1054 if (!data) return false;
1056 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1060 if (!asn1_write_Integer(data, lvrc->targetPosition)) {
1064 if (!asn1_write_Integer(data, lvrc->contentCount)) {
1068 if (!asn1_write_enumerated(data, lvrc->vlv_result)) {
1072 if (lvrc->ctxid_len) {
1073 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1078 if (!asn1_pop_tag(data)) {
1082 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1083 if (out->data == NULL) {
1091 static bool encode_openldap_dereference(void *mem_ctx, void *in, DATA_BLOB *out)
1093 struct dsdb_openldap_dereference_control *control = talloc_get_type(in, struct dsdb_openldap_dereference_control);
1095 struct asn1_data *data = asn1_init(mem_ctx);
1097 if (!data) return false;
1099 if (!control) return false;
1101 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1105 for (i=0; control->dereference && control->dereference[i]; i++) {
1106 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1109 if (!asn1_write_OctetString(data, control->dereference[i]->source_attribute, strlen(control->dereference[i]->source_attribute))) {
1112 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1115 for (j=0; control->dereference && control->dereference[i]->dereference_attribute[j]; j++) {
1116 if (!asn1_write_OctetString(data, control->dereference[i]->dereference_attribute[j],
1117 strlen(control->dereference[i]->dereference_attribute[j]))) {
1127 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1128 if (out->data == NULL) {
1135 static bool decode_openldap_dereference(void *mem_ctx, DATA_BLOB in, void **out)
1137 struct asn1_data *data = asn1_init(mem_ctx);
1138 struct dsdb_openldap_dereference_result_control *control;
1139 struct dsdb_openldap_dereference_result **r;
1141 if (!data) return false;
1143 control = talloc(mem_ctx, struct dsdb_openldap_dereference_result_control);
1144 if (!control) return false;
1146 r = control->attributes = talloc_array(control, struct dsdb_openldap_dereference_result *, 0);
1147 if (!r) return false;
1149 if (!asn1_load(data, in)) {
1153 control = talloc(mem_ctx, struct dsdb_openldap_dereference_result_control);
1158 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1162 while (asn1_tag_remaining(data) > 0) {
1164 r = talloc_realloc(r, control, struct dsdb_openldap_dereference_result *, i + 1);
1166 r[i] = talloc(r, struct dsdb_openldap_dereference_result);
1168 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1172 asn1_read_OctetString_talloc(r[i], data, &r[i]->source_attribute);
1173 asn1_read_OctetString_talloc(r[i], data, &r[i]->dereferenced_dn);
1174 ldap_decode_attribs(r[i], data, &r[i]->attributes,
1175 &r[i]->num_attributes);
1177 if (!asn1_end_tag(data)) {
1183 if (!asn1_end_tag(data)) {
1192 struct control_handler ldap_known_controls[] = {
1193 { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request },
1194 { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request },
1195 { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request },
1196 { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response },
1197 { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
1198 { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request },
1199 { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request },
1200 { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request },
1201 { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request },
1202 { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request },
1203 { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request },
1204 { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request },
1205 { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request },
1206 { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request },
1207 { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response },
1208 /* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */
1209 { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL },
1210 /* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */
1211 { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL },
1212 { DSDB_OPENLDAP_DEREFERENCE_CONTROL, decode_openldap_dereference, encode_openldap_dereference},
1213 { NULL, NULL, NULL }
1216 bool ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl)
1220 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1221 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1222 if (!ldap_known_controls[i].decode || !ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) {
1228 if (ldap_known_controls[i].oid == NULL) {
1235 bool ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value)
1239 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1243 if (!asn1_read_OctetString(data, mem_ctx, &oid)) {
1246 ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length);
1251 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
1253 if (!asn1_read_BOOLEAN(data, &critical)) {
1256 ctrl->critical = critical;
1258 ctrl->critical = false;
1263 if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) {
1264 *value = data_blob(NULL, 0);
1268 if (!asn1_read_OctetString(data, mem_ctx, value)) {
1273 if (!asn1_end_tag(data)) {
1280 bool ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl)
1285 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1286 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1287 if (!ldap_known_controls[i].encode) {
1288 if (ctrl->critical) {
1291 /* not encoding this control */
1295 if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) {
1301 if (ldap_known_controls[i].oid == NULL) {
1305 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1309 if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) {
1313 if (ctrl->critical) {
1314 if (!asn1_write_BOOLEAN(data, ctrl->critical)) {
1323 if (!asn1_write_OctetString(data, value.data, value.length)) {
1328 if (!asn1_pop_tag(data)) {