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 "libcli/util/asn_1.h"
24 #include "libcli/ldap/ldap.h"
25 #include "lib/ldb/include/ldb.h"
27 struct control_handler {
29 BOOL (*decode)(void *mem_ctx, DATA_BLOB in, void **out);
30 BOOL (*encode)(void *mem_ctx, void *in, DATA_BLOB *out);
33 static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out)
36 struct asn1_data *data = asn1_init(mem_ctx);
37 struct ldb_sort_resp_control *lsrc;
39 if (!data) return False;
41 if (!asn1_load(data, in)) {
45 lsrc = talloc(mem_ctx, struct ldb_sort_resp_control);
50 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
54 if (!asn1_read_enumerated(data, &(lsrc->result))) {
58 lsrc->attr_desc = NULL;
59 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
60 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
63 lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length);
64 if (!lsrc->attr_desc) {
69 if (!asn1_end_tag(data)) {
78 static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out)
82 struct asn1_data *data = asn1_init(mem_ctx);
83 struct ldb_server_sort_control **lssc;
86 if (!data) return False;
88 if (!asn1_load(data, in)) {
92 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
98 for (num = 0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); num++) {
99 lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2);
103 lssc[num] = talloc_zero(lssc, struct ldb_server_sort_control);
108 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
112 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
116 lssc[num]->attributeName = talloc_strndup(lssc[num], (const char *)attr.data, attr.length);
117 if (!lssc [num]->attributeName) {
121 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
122 if (!asn1_read_OctetString(data, mem_ctx, &rule)) {
125 lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length);
126 if (!lssc[num]->orderingRule) {
131 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
133 if (!asn1_read_BOOLEAN(data, &reverse)) {
136 lssc[num]->reverse = reverse;
139 if (!asn1_end_tag(data)) {
148 if (!asn1_end_tag(data)) {
157 static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out)
159 struct asn1_data *data = asn1_init(mem_ctx);
160 struct ldb_extended_dn_control *ledc;
162 if (!data) return False;
164 if (!asn1_load(data, in)) {
168 ledc = talloc(mem_ctx, struct ldb_extended_dn_control);
173 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
177 if (!asn1_read_Integer(data, &(ledc->type))) {
181 if (!asn1_end_tag(data)) {
190 static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out)
192 struct asn1_data *data = asn1_init(mem_ctx);
193 struct ldb_sd_flags_control *lsdfc;
195 if (!data) return False;
197 if (!asn1_load(data, in)) {
201 lsdfc = talloc(mem_ctx, struct ldb_sd_flags_control);
206 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
210 if (!asn1_read_Integer(data, &(lsdfc->secinfo_flags))) {
214 if (!asn1_end_tag(data)) {
223 static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **out)
225 struct asn1_data *data = asn1_init(mem_ctx);
226 struct ldb_search_options_control *lsoc;
228 if (!data) return False;
230 if (!asn1_load(data, in)) {
234 lsoc = talloc(mem_ctx, struct ldb_search_options_control);
239 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
243 if (!asn1_read_Integer(data, &(lsoc->search_options))) {
247 if (!asn1_end_tag(data)) {
256 static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out)
259 struct asn1_data *data = asn1_init(mem_ctx);
260 struct ldb_paged_control *lprc;
262 if (!data) return False;
264 if (!asn1_load(data, in)) {
268 lprc = talloc(mem_ctx, struct ldb_paged_control);
273 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
277 if (!asn1_read_Integer(data, &(lprc->size))) {
281 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
284 lprc->cookie_len = cookie.length;
285 if (lprc->cookie_len) {
286 lprc->cookie = talloc_memdup(lprc, cookie.data, cookie.length);
288 if (!(lprc->cookie)) {
295 if (!asn1_end_tag(data)) {
304 static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out)
307 struct asn1_data *data = asn1_init(mem_ctx);
308 struct ldb_dirsync_control *ldc;
310 if (!data) return False;
312 if (!asn1_load(data, in)) {
316 ldc = talloc(mem_ctx, struct ldb_dirsync_control);
321 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
325 if (!asn1_read_Integer(data, &(ldc->flags))) {
329 if (!asn1_read_Integer(data, &(ldc->max_attributes))) {
333 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
336 ldc->cookie_len = cookie.length;
337 if (ldc->cookie_len) {
338 ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length);
340 if (!(ldc->cookie)) {
347 if (!asn1_end_tag(data)) {
356 /* seem that this controls has 2 forms one in case it is used with
357 * a Search Request and another when used ina Search Response
359 static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out)
361 DATA_BLOB source_attribute;
362 struct asn1_data *data = asn1_init(mem_ctx);
363 struct ldb_asq_control *lac;
365 if (!data) return False;
367 if (!asn1_load(data, in)) {
371 lac = talloc(mem_ctx, struct ldb_asq_control);
376 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
380 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
382 if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) {
385 lac->src_attr_len = source_attribute.length;
386 if (lac->src_attr_len) {
387 lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length);
389 if (!(lac->source_attribute)) {
393 lac->source_attribute = NULL;
398 } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) {
400 if (!asn1_read_enumerated(data, &(lac->result))) {
410 if (!asn1_end_tag(data)) {
419 static BOOL decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out)
421 if (in.length != 0) {
428 static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out)
430 if (in.length != 0) {
437 static BOOL decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out)
439 if (in.length != 0) {
446 static BOOL decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out)
448 if (in.length != 0) {
455 static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out)
457 if (in.length != 0) {
464 static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out)
466 DATA_BLOB assertion_value, context_id;
467 struct asn1_data *data = asn1_init(mem_ctx);
468 struct ldb_vlv_req_control *lvrc;
470 if (!data) return False;
472 if (!asn1_load(data, in)) {
476 lvrc = talloc(mem_ctx, struct ldb_vlv_req_control);
481 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
485 if (!asn1_read_Integer(data, &(lvrc->beforeCount))) {
489 if (!asn1_read_Integer(data, &(lvrc->afterCount))) {
493 if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
497 if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
501 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
505 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) {
509 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) {
513 if (!asn1_end_tag(data)) { /*SEQUENCE*/
517 if (!asn1_end_tag(data)) { /*CONTEXT*/
525 if (!asn1_start_tag(data, ASN1_CONTEXT(1))) {
529 if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) {
532 lvrc->match.gtOrEq.value_len = assertion_value.length;
533 if (lvrc->match.gtOrEq.value_len) {
534 lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length);
536 if (!(lvrc->match.gtOrEq.value)) {
540 lvrc->match.gtOrEq.value = NULL;
543 if (!asn1_end_tag(data)) { /*CONTEXT*/
548 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
549 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
552 lvrc->ctxid_len = context_id.length;
553 if (lvrc->ctxid_len) {
554 lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length);
556 if (!(lvrc->contextId)) {
560 lvrc->contextId = NULL;
563 lvrc->contextId = NULL;
567 if (!asn1_end_tag(data)) {
576 static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out)
578 DATA_BLOB context_id;
579 struct asn1_data *data = asn1_init(mem_ctx);
580 struct ldb_vlv_resp_control *lvrc;
582 if (!data) return False;
584 if (!asn1_load(data, in)) {
588 lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control);
593 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
597 if (!asn1_read_Integer(data, &(lvrc->targetPosition))) {
601 if (!asn1_read_Integer(data, &(lvrc->contentCount))) {
605 if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) {
609 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
610 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
613 lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length);
614 if (!lvrc->contextId) {
617 lvrc->ctxid_len = context_id.length;
619 lvrc->contextId = NULL;
623 if (!asn1_end_tag(data)) {
632 static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out)
634 struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control);
635 struct asn1_data *data = asn1_init(mem_ctx);
637 if (!data) return False;
639 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
643 if (!asn1_write_enumerated(data, lsrc->result)) {
647 if (lsrc->attr_desc) {
648 if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) {
653 if (!asn1_pop_tag(data)) {
657 *out = data_blob_talloc(mem_ctx, data->data, data->length);
658 if (out->data == NULL) {
666 static BOOL encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out)
668 struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *);
669 struct asn1_data *data = asn1_init(mem_ctx);
672 if (!data) return False;
674 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
678 for (num = 0; lssc[num]; num++) {
679 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
683 if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) {
687 if (lssc[num]->orderingRule) {
688 if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) {
693 if (lssc[num]->reverse) {
694 if (!asn1_write_BOOLEAN(data, lssc[num]->reverse)) {
699 if (!asn1_pop_tag(data)) {
704 if (!asn1_pop_tag(data)) {
708 *out = data_blob_talloc(mem_ctx, data->data, data->length);
709 if (out->data == NULL) {
717 static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out)
719 struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control);
720 struct asn1_data *data = asn1_init(mem_ctx);
722 if (!data) return False;
724 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
728 if (!asn1_write_Integer(data, ledc->type)) {
732 if (!asn1_pop_tag(data)) {
736 *out = data_blob_talloc(mem_ctx, data->data, data->length);
737 if (out->data == NULL) {
745 static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out)
747 struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control);
748 struct asn1_data *data = asn1_init(mem_ctx);
750 if (!data) return False;
752 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
756 if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) {
760 if (!asn1_pop_tag(data)) {
764 *out = data_blob_talloc(mem_ctx, data->data, data->length);
765 if (out->data == NULL) {
773 static BOOL encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out)
775 struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control);
776 struct asn1_data *data = asn1_init(mem_ctx);
778 if (!data) return False;
780 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
784 if (!asn1_write_Integer(data, lsoc->search_options)) {
788 if (!asn1_pop_tag(data)) {
792 *out = data_blob_talloc(mem_ctx, data->data, data->length);
793 if (out->data == NULL) {
801 static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out)
803 struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control);
804 struct asn1_data *data = asn1_init(mem_ctx);
806 if (!data) return False;
808 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
812 if (!asn1_write_Integer(data, lprc->size)) {
816 if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) {
820 if (!asn1_pop_tag(data)) {
824 *out = data_blob_talloc(mem_ctx, data->data, data->length);
825 if (out->data == NULL) {
833 /* seem that this controls has 2 forms one in case it is used with
834 * a Search Request and another when used ina Search Response
836 static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out)
838 struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control);
839 struct asn1_data *data = asn1_init(mem_ctx);
841 if (!data) return False;
843 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
849 if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) {
853 if (!asn1_write_enumerated(data, lac->result)) {
858 if (!asn1_pop_tag(data)) {
862 *out = data_blob_talloc(mem_ctx, data->data, data->length);
863 if (out->data == NULL) {
871 static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out)
873 struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control);
874 struct asn1_data *data = asn1_init(mem_ctx);
876 if (!data) return False;
878 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
882 if (!asn1_write_Integer(data, ldc->flags)) {
886 if (!asn1_write_Integer(data, ldc->max_attributes)) {
890 if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) {
894 if (!asn1_pop_tag(data)) {
898 *out = data_blob_talloc(mem_ctx, data->data, data->length);
899 if (out->data == NULL) {
907 static BOOL encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out)
913 *out = data_blob(NULL, 0);
917 static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out)
923 *out = data_blob(NULL, 0);
927 static BOOL encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out)
933 *out = data_blob(NULL, 0);
937 static BOOL encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out)
943 *out = data_blob(NULL, 0);
947 static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out)
953 *out = data_blob(NULL, 0);
957 static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out)
959 struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control);
960 struct asn1_data *data = asn1_init(mem_ctx);
962 if (!data) return False;
964 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
968 if (!asn1_write_Integer(data, lvrc->beforeCount)) {
972 if (!asn1_write_Integer(data, lvrc->afterCount)) {
976 if (lvrc->type == 0) {
977 if (!asn1_push_tag(data, ASN1_CONTEXT(0))) {
981 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
985 if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) {
989 if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) {
993 if (!asn1_pop_tag(data)) { /*SEQUENCE*/
997 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1001 if (!asn1_push_tag(data, ASN1_CONTEXT(1))) {
1005 if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) {
1009 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1014 if (lvrc->ctxid_len) {
1015 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1020 if (!asn1_pop_tag(data)) {
1024 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1025 if (out->data == NULL) {
1033 static BOOL encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out)
1035 struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control);
1036 struct asn1_data *data = asn1_init(mem_ctx);
1038 if (!data) return False;
1040 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1044 if (!asn1_write_Integer(data, lvrc->targetPosition)) {
1048 if (!asn1_write_Integer(data, lvrc->contentCount)) {
1052 if (!asn1_write_enumerated(data, lvrc->vlv_result)) {
1056 if (lvrc->ctxid_len) {
1057 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1062 if (!asn1_pop_tag(data)) {
1066 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1067 if (out->data == NULL) {
1075 struct control_handler ldap_known_controls[] = {
1076 { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request },
1077 { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request },
1078 { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request },
1079 { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response },
1080 { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
1081 { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request },
1082 { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request },
1083 { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request },
1084 { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request },
1085 { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request },
1086 { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request },
1087 { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request },
1088 { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request },
1089 { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request },
1090 { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response },
1091 /* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */
1092 { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL },
1093 /* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */
1094 { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL },
1095 { NULL, NULL, NULL }
1098 BOOL ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl)
1102 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1103 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1104 if (!ldap_known_controls[i].decode || !ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) {
1110 if (ldap_known_controls[i].oid == NULL) {
1117 BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value)
1121 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1125 if (!asn1_read_OctetString(data, mem_ctx, &oid)) {
1128 ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length);
1133 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
1135 if (!asn1_read_BOOLEAN(data, &critical)) {
1138 ctrl->critical = critical;
1140 ctrl->critical = False;
1145 if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) {
1149 if (!asn1_read_OctetString(data, mem_ctx, value)) {
1154 if (!asn1_end_tag(data)) {
1161 BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl)
1166 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1167 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1168 if (!ldap_known_controls[i].encode) {
1169 if (ctrl->critical) {
1172 /* not encoding this control */
1176 if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) {
1182 if (ldap_known_controls[i].oid == NULL) {
1186 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1190 if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) {
1194 if (ctrl->critical) {
1195 if (!asn1_write_BOOLEAN(data, ctrl->critical)) {
1204 if (!asn1_write_OctetString(data, value.data, value.length)) {
1209 if (!asn1_pop_tag(data)) {