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"
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;
160 struct ldb_extended_dn_control *ledc;
162 /* The content of this control is optional */
163 if (in.length == 0) {
168 data = asn1_init(mem_ctx);
169 if (!data) return false;
171 if (!asn1_load(data, in)) {
175 ledc = talloc(mem_ctx, struct ldb_extended_dn_control);
180 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
184 if (!asn1_read_Integer(data, &(ledc->type))) {
188 if (!asn1_end_tag(data)) {
197 static bool decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, 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, &(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 struct asn1_data *data = asn1_init(mem_ctx);
233 struct ldb_search_options_control *lsoc;
235 if (!data) return false;
237 if (!asn1_load(data, in)) {
241 lsoc = talloc(mem_ctx, struct ldb_search_options_control);
246 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
250 if (!asn1_read_Integer(data, &(lsoc->search_options))) {
254 if (!asn1_end_tag(data)) {
263 static bool decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out)
266 struct asn1_data *data = asn1_init(mem_ctx);
267 struct ldb_paged_control *lprc;
269 if (!data) return false;
271 if (!asn1_load(data, in)) {
275 lprc = talloc(mem_ctx, struct ldb_paged_control);
280 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
284 if (!asn1_read_Integer(data, &(lprc->size))) {
288 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
291 lprc->cookie_len = cookie.length;
292 if (lprc->cookie_len) {
293 lprc->cookie = talloc_memdup(lprc, cookie.data, cookie.length);
295 if (!(lprc->cookie)) {
302 if (!asn1_end_tag(data)) {
311 static bool decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out)
314 struct asn1_data *data = asn1_init(mem_ctx);
315 struct ldb_dirsync_control *ldc;
317 if (!data) return false;
319 if (!asn1_load(data, in)) {
323 ldc = talloc(mem_ctx, struct ldb_dirsync_control);
328 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
332 if (!asn1_read_Integer(data, &(ldc->flags))) {
336 if (!asn1_read_Integer(data, &(ldc->max_attributes))) {
340 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
343 ldc->cookie_len = cookie.length;
344 if (ldc->cookie_len) {
345 ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length);
347 if (!(ldc->cookie)) {
354 if (!asn1_end_tag(data)) {
363 /* seem that this controls has 2 forms one in case it is used with
364 * a Search Request and another when used ina Search Response
366 static bool decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out)
368 DATA_BLOB source_attribute;
369 struct asn1_data *data = asn1_init(mem_ctx);
370 struct ldb_asq_control *lac;
372 if (!data) return false;
374 if (!asn1_load(data, in)) {
378 lac = talloc(mem_ctx, struct ldb_asq_control);
383 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
387 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
389 if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) {
392 lac->src_attr_len = source_attribute.length;
393 if (lac->src_attr_len) {
394 lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length);
396 if (!(lac->source_attribute)) {
400 lac->source_attribute = NULL;
405 } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) {
407 if (!asn1_read_enumerated(data, &(lac->result))) {
417 if (!asn1_end_tag(data)) {
426 static bool decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out)
428 if (in.length != 0) {
435 static bool decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out)
437 if (in.length != 0) {
444 static bool decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out)
446 if (in.length != 0) {
453 static bool decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out)
455 if (in.length != 0) {
462 static bool decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out)
464 if (in.length != 0) {
471 static bool decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out)
473 DATA_BLOB assertion_value, context_id;
474 struct asn1_data *data = asn1_init(mem_ctx);
475 struct ldb_vlv_req_control *lvrc;
477 if (!data) return false;
479 if (!asn1_load(data, in)) {
483 lvrc = talloc(mem_ctx, struct ldb_vlv_req_control);
488 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
492 if (!asn1_read_Integer(data, &(lvrc->beforeCount))) {
496 if (!asn1_read_Integer(data, &(lvrc->afterCount))) {
500 if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
504 if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
508 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
512 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) {
516 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) {
520 if (!asn1_end_tag(data)) { /*SEQUENCE*/
524 if (!asn1_end_tag(data)) { /*CONTEXT*/
532 if (!asn1_start_tag(data, ASN1_CONTEXT(1))) {
536 if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) {
539 lvrc->match.gtOrEq.value_len = assertion_value.length;
540 if (lvrc->match.gtOrEq.value_len) {
541 lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length);
543 if (!(lvrc->match.gtOrEq.value)) {
547 lvrc->match.gtOrEq.value = NULL;
550 if (!asn1_end_tag(data)) { /*CONTEXT*/
555 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
556 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
559 lvrc->ctxid_len = context_id.length;
560 if (lvrc->ctxid_len) {
561 lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length);
563 if (!(lvrc->contextId)) {
567 lvrc->contextId = NULL;
570 lvrc->contextId = NULL;
574 if (!asn1_end_tag(data)) {
583 static bool decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out)
585 DATA_BLOB context_id;
586 struct asn1_data *data = asn1_init(mem_ctx);
587 struct ldb_vlv_resp_control *lvrc;
589 if (!data) return false;
591 if (!asn1_load(data, in)) {
595 lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control);
600 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
604 if (!asn1_read_Integer(data, &(lvrc->targetPosition))) {
608 if (!asn1_read_Integer(data, &(lvrc->contentCount))) {
612 if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) {
616 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
617 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
620 lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length);
621 if (!lvrc->contextId) {
624 lvrc->ctxid_len = context_id.length;
626 lvrc->contextId = NULL;
630 if (!asn1_end_tag(data)) {
639 static bool encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out)
641 struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control);
642 struct asn1_data *data = asn1_init(mem_ctx);
644 if (!data) return false;
646 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
650 if (!asn1_write_enumerated(data, lsrc->result)) {
654 if (lsrc->attr_desc) {
655 if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) {
660 if (!asn1_pop_tag(data)) {
664 *out = data_blob_talloc(mem_ctx, data->data, data->length);
665 if (out->data == NULL) {
673 static bool encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out)
675 struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *);
676 struct asn1_data *data = asn1_init(mem_ctx);
679 if (!data) return false;
681 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
685 for (num = 0; lssc[num]; num++) {
686 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
690 if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) {
694 if (lssc[num]->orderingRule) {
695 if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) {
700 if (lssc[num]->reverse) {
701 if (!asn1_write_BOOLEAN(data, lssc[num]->reverse)) {
706 if (!asn1_pop_tag(data)) {
711 if (!asn1_pop_tag(data)) {
715 *out = data_blob_talloc(mem_ctx, data->data, data->length);
716 if (out->data == NULL) {
724 static bool encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out)
726 struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control);
727 struct asn1_data *data;
730 *out = data_blob(NULL, 0);
734 data = asn1_init(mem_ctx);
736 if (!data) return false;
738 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
742 if (!asn1_write_Integer(data, ledc->type)) {
746 if (!asn1_pop_tag(data)) {
750 *out = data_blob_talloc(mem_ctx, data->data, data->length);
751 if (out->data == NULL) {
759 static bool encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out)
761 struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control);
762 struct asn1_data *data = asn1_init(mem_ctx);
764 if (!data) return false;
766 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
770 if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) {
774 if (!asn1_pop_tag(data)) {
778 *out = data_blob_talloc(mem_ctx, data->data, data->length);
779 if (out->data == NULL) {
787 static bool encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out)
789 struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control);
790 struct asn1_data *data = asn1_init(mem_ctx);
792 if (!data) return false;
794 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
798 if (!asn1_write_Integer(data, lsoc->search_options)) {
802 if (!asn1_pop_tag(data)) {
806 *out = data_blob_talloc(mem_ctx, data->data, data->length);
807 if (out->data == NULL) {
815 static bool encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out)
817 struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control);
818 struct asn1_data *data = asn1_init(mem_ctx);
820 if (!data) return false;
822 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
826 if (!asn1_write_Integer(data, lprc->size)) {
830 if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) {
834 if (!asn1_pop_tag(data)) {
838 *out = data_blob_talloc(mem_ctx, data->data, data->length);
839 if (out->data == NULL) {
847 /* seem that this controls has 2 forms one in case it is used with
848 * a Search Request and another when used ina Search Response
850 static bool encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out)
852 struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control);
853 struct asn1_data *data = asn1_init(mem_ctx);
855 if (!data) return false;
857 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
863 if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) {
867 if (!asn1_write_enumerated(data, lac->result)) {
872 if (!asn1_pop_tag(data)) {
876 *out = data_blob_talloc(mem_ctx, data->data, data->length);
877 if (out->data == NULL) {
885 static bool encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out)
887 struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control);
888 struct asn1_data *data = asn1_init(mem_ctx);
890 if (!data) return false;
892 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
896 if (!asn1_write_Integer(data, ldc->flags)) {
900 if (!asn1_write_Integer(data, ldc->max_attributes)) {
904 if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) {
908 if (!asn1_pop_tag(data)) {
912 *out = data_blob_talloc(mem_ctx, data->data, data->length);
913 if (out->data == NULL) {
921 static bool encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out)
927 *out = data_blob(NULL, 0);
931 static bool encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out)
937 *out = data_blob(NULL, 0);
941 static bool encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out)
947 *out = data_blob(NULL, 0);
951 static bool encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out)
957 *out = data_blob(NULL, 0);
961 static bool encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out)
967 *out = data_blob(NULL, 0);
971 static bool encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out)
973 struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control);
974 struct asn1_data *data = asn1_init(mem_ctx);
976 if (!data) return false;
978 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
982 if (!asn1_write_Integer(data, lvrc->beforeCount)) {
986 if (!asn1_write_Integer(data, lvrc->afterCount)) {
990 if (lvrc->type == 0) {
991 if (!asn1_push_tag(data, ASN1_CONTEXT(0))) {
995 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
999 if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) {
1003 if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) {
1007 if (!asn1_pop_tag(data)) { /*SEQUENCE*/
1011 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1015 if (!asn1_push_tag(data, ASN1_CONTEXT(1))) {
1019 if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) {
1023 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1028 if (lvrc->ctxid_len) {
1029 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1034 if (!asn1_pop_tag(data)) {
1038 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1039 if (out->data == NULL) {
1047 static bool encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out)
1049 struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control);
1050 struct asn1_data *data = asn1_init(mem_ctx);
1052 if (!data) return false;
1054 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1058 if (!asn1_write_Integer(data, lvrc->targetPosition)) {
1062 if (!asn1_write_Integer(data, lvrc->contentCount)) {
1066 if (!asn1_write_enumerated(data, lvrc->vlv_result)) {
1070 if (lvrc->ctxid_len) {
1071 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1076 if (!asn1_pop_tag(data)) {
1080 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1081 if (out->data == NULL) {
1089 struct control_handler ldap_known_controls[] = {
1090 { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request },
1091 { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request },
1092 { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request },
1093 { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response },
1094 { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
1095 { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request },
1096 { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request },
1097 { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request },
1098 { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request },
1099 { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request },
1100 { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request },
1101 { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request },
1102 { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request },
1103 { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request },
1104 { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response },
1105 /* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */
1106 { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL },
1107 /* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */
1108 { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL },
1109 { NULL, NULL, NULL }
1112 bool ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl)
1116 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1117 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1118 if (!ldap_known_controls[i].decode || !ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) {
1124 if (ldap_known_controls[i].oid == NULL) {
1131 bool ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value)
1135 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1139 if (!asn1_read_OctetString(data, mem_ctx, &oid)) {
1142 ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length);
1147 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
1149 if (!asn1_read_BOOLEAN(data, &critical)) {
1152 ctrl->critical = critical;
1154 ctrl->critical = false;
1159 if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) {
1160 *value = data_blob(NULL, 0);
1164 if (!asn1_read_OctetString(data, mem_ctx, value)) {
1169 if (!asn1_end_tag(data)) {
1176 bool ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl)
1181 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1182 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1183 if (!ldap_known_controls[i].encode) {
1184 if (ctrl->critical) {
1187 /* not encoding this control */
1191 if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) {
1197 if (ldap_known_controls[i].oid == NULL) {
1201 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1205 if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) {
1209 if (ctrl->critical) {
1210 if (!asn1_write_BOOLEAN(data, ctrl->critical)) {
1219 if (!asn1_write_OctetString(data, value.data, value.length)) {
1224 if (!asn1_pop_tag(data)) {