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"
28 struct control_handler {
30 bool (*decode)(void *mem_ctx, DATA_BLOB in, void **out);
31 bool (*encode)(void *mem_ctx, void *in, DATA_BLOB *out);
34 static bool decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out)
37 struct asn1_data *data = asn1_init(mem_ctx);
38 struct ldb_sort_resp_control *lsrc;
40 if (!data) return false;
42 if (!asn1_load(data, in)) {
46 lsrc = talloc(mem_ctx, struct ldb_sort_resp_control);
51 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
55 if (!asn1_read_enumerated(data, &(lsrc->result))) {
59 lsrc->attr_desc = NULL;
60 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
61 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
64 lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length);
65 if (!lsrc->attr_desc) {
70 if (!asn1_end_tag(data)) {
79 static bool decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out)
83 struct asn1_data *data = asn1_init(mem_ctx);
84 struct ldb_server_sort_control **lssc;
87 if (!data) return false;
89 if (!asn1_load(data, in)) {
93 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
99 for (num = 0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); num++) {
100 lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2);
104 lssc[num] = talloc_zero(lssc, struct ldb_server_sort_control);
109 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
113 if (!asn1_read_OctetString(data, mem_ctx, &attr)) {
117 lssc[num]->attributeName = talloc_strndup(lssc[num], (const char *)attr.data, attr.length);
118 if (!lssc [num]->attributeName) {
122 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
123 if (!asn1_read_OctetString(data, mem_ctx, &rule)) {
126 lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length);
127 if (!lssc[num]->orderingRule) {
132 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
134 if (!asn1_read_BOOLEAN(data, &reverse)) {
137 lssc[num]->reverse = reverse;
140 if (!asn1_end_tag(data)) {
149 if (!asn1_end_tag(data)) {
158 static bool decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out)
160 struct asn1_data *data;
161 struct ldb_extended_dn_control *ledc;
163 /* The content of this control is optional */
164 if (in.length == 0) {
169 data = asn1_init(mem_ctx);
170 if (!data) return false;
172 if (!asn1_load(data, in)) {
176 ledc = talloc(mem_ctx, struct ldb_extended_dn_control);
181 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
185 if (!asn1_read_Integer(data, &(ledc->type))) {
189 if (!asn1_end_tag(data)) {
198 static bool decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out)
200 struct asn1_data *data = asn1_init(mem_ctx);
201 struct ldb_sd_flags_control *lsdfc;
203 if (!data) return false;
205 if (!asn1_load(data, in)) {
209 lsdfc = talloc(mem_ctx, struct ldb_sd_flags_control);
214 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
218 if (!asn1_read_Integer(data, &(lsdfc->secinfo_flags))) {
222 if (!asn1_end_tag(data)) {
231 static bool decode_search_options_request(void *mem_ctx, DATA_BLOB in, 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, &(lsoc->search_options))) {
255 if (!asn1_end_tag(data)) {
264 static bool decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out)
267 struct asn1_data *data = asn1_init(mem_ctx);
268 struct ldb_paged_control *lprc;
270 if (!data) return false;
272 if (!asn1_load(data, in)) {
276 lprc = talloc(mem_ctx, struct ldb_paged_control);
281 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
285 if (!asn1_read_Integer(data, &(lprc->size))) {
289 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
292 lprc->cookie_len = cookie.length;
293 if (lprc->cookie_len) {
294 lprc->cookie = talloc_memdup(lprc, cookie.data, cookie.length);
296 if (!(lprc->cookie)) {
303 if (!asn1_end_tag(data)) {
312 static bool decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out)
315 struct asn1_data *data = asn1_init(mem_ctx);
316 struct ldb_dirsync_control *ldc;
318 if (!data) return false;
320 if (!asn1_load(data, in)) {
324 ldc = talloc(mem_ctx, struct ldb_dirsync_control);
329 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
333 if (!asn1_read_Integer(data, &(ldc->flags))) {
337 if (!asn1_read_Integer(data, &(ldc->max_attributes))) {
341 if (!asn1_read_OctetString(data, mem_ctx, &cookie)) {
344 ldc->cookie_len = cookie.length;
345 if (ldc->cookie_len) {
346 ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length);
348 if (!(ldc->cookie)) {
355 if (!asn1_end_tag(data)) {
364 /* seem that this controls has 2 forms one in case it is used with
365 * a Search Request and another when used ina Search Response
367 static bool decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out)
369 DATA_BLOB source_attribute;
370 struct asn1_data *data = asn1_init(mem_ctx);
371 struct ldb_asq_control *lac;
373 if (!data) return false;
375 if (!asn1_load(data, in)) {
379 lac = talloc(mem_ctx, struct ldb_asq_control);
384 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
388 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
390 if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) {
393 lac->src_attr_len = source_attribute.length;
394 if (lac->src_attr_len) {
395 lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length);
397 if (!(lac->source_attribute)) {
401 lac->source_attribute = NULL;
406 } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) {
408 if (!asn1_read_enumerated(data, &(lac->result))) {
418 if (!asn1_end_tag(data)) {
427 static bool decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out)
429 if (in.length != 0) {
436 static bool decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out)
438 if (in.length != 0) {
445 static bool decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out)
447 if (in.length != 0) {
454 static bool decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out)
456 if (in.length != 0) {
463 static bool decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out)
465 if (in.length != 0) {
472 static bool decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out)
474 DATA_BLOB assertion_value, context_id;
475 struct asn1_data *data = asn1_init(mem_ctx);
476 struct ldb_vlv_req_control *lvrc;
478 if (!data) return false;
480 if (!asn1_load(data, in)) {
484 lvrc = talloc(mem_ctx, struct ldb_vlv_req_control);
489 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
493 if (!asn1_read_Integer(data, &(lvrc->beforeCount))) {
497 if (!asn1_read_Integer(data, &(lvrc->afterCount))) {
501 if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
505 if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
509 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
513 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) {
517 if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) {
521 if (!asn1_end_tag(data)) { /*SEQUENCE*/
525 if (!asn1_end_tag(data)) { /*CONTEXT*/
533 if (!asn1_start_tag(data, ASN1_CONTEXT(1))) {
537 if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) {
540 lvrc->match.gtOrEq.value_len = assertion_value.length;
541 if (lvrc->match.gtOrEq.value_len) {
542 lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length);
544 if (!(lvrc->match.gtOrEq.value)) {
548 lvrc->match.gtOrEq.value = NULL;
551 if (!asn1_end_tag(data)) { /*CONTEXT*/
556 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
557 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
560 lvrc->ctxid_len = context_id.length;
561 if (lvrc->ctxid_len) {
562 lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length);
564 if (!(lvrc->contextId)) {
568 lvrc->contextId = NULL;
571 lvrc->contextId = NULL;
575 if (!asn1_end_tag(data)) {
584 static bool decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out)
586 DATA_BLOB context_id;
587 struct asn1_data *data = asn1_init(mem_ctx);
588 struct ldb_vlv_resp_control *lvrc;
590 if (!data) return false;
592 if (!asn1_load(data, in)) {
596 lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control);
601 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
605 if (!asn1_read_Integer(data, &(lvrc->targetPosition))) {
609 if (!asn1_read_Integer(data, &(lvrc->contentCount))) {
613 if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) {
617 if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
618 if (!asn1_read_OctetString(data, mem_ctx, &context_id)) {
621 lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length);
622 if (!lvrc->contextId) {
625 lvrc->ctxid_len = context_id.length;
627 lvrc->contextId = NULL;
631 if (!asn1_end_tag(data)) {
640 static bool encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out)
642 struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control);
643 struct asn1_data *data = asn1_init(mem_ctx);
645 if (!data) return false;
647 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
651 if (!asn1_write_enumerated(data, lsrc->result)) {
655 if (lsrc->attr_desc) {
656 if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) {
661 if (!asn1_pop_tag(data)) {
665 *out = data_blob_talloc(mem_ctx, data->data, data->length);
666 if (out->data == NULL) {
674 static bool encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out)
676 struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *);
677 struct asn1_data *data = asn1_init(mem_ctx);
680 if (!data) return false;
682 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
686 for (num = 0; lssc[num]; num++) {
687 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
691 if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) {
695 if (lssc[num]->orderingRule) {
696 if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) {
701 if (lssc[num]->reverse) {
702 if (!asn1_write_BOOLEAN(data, lssc[num]->reverse)) {
707 if (!asn1_pop_tag(data)) {
712 if (!asn1_pop_tag(data)) {
716 *out = data_blob_talloc(mem_ctx, data->data, data->length);
717 if (out->data == NULL) {
725 static bool encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out)
727 struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control);
728 struct asn1_data *data;
731 *out = data_blob(NULL, 0);
735 data = asn1_init(mem_ctx);
737 if (!data) return false;
739 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
743 if (!asn1_write_Integer(data, ledc->type)) {
747 if (!asn1_pop_tag(data)) {
751 *out = data_blob_talloc(mem_ctx, data->data, data->length);
752 if (out->data == NULL) {
760 static bool encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out)
762 struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control);
763 struct asn1_data *data = asn1_init(mem_ctx);
765 if (!data) return false;
767 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
771 if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) {
775 if (!asn1_pop_tag(data)) {
779 *out = data_blob_talloc(mem_ctx, data->data, data->length);
780 if (out->data == NULL) {
788 static bool encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out)
790 struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control);
791 struct asn1_data *data = asn1_init(mem_ctx);
793 if (!data) return false;
795 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
799 if (!asn1_write_Integer(data, lsoc->search_options)) {
803 if (!asn1_pop_tag(data)) {
807 *out = data_blob_talloc(mem_ctx, data->data, data->length);
808 if (out->data == NULL) {
816 static bool encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out)
818 struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control);
819 struct asn1_data *data = asn1_init(mem_ctx);
821 if (!data) return false;
823 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
827 if (!asn1_write_Integer(data, lprc->size)) {
831 if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) {
835 if (!asn1_pop_tag(data)) {
839 *out = data_blob_talloc(mem_ctx, data->data, data->length);
840 if (out->data == NULL) {
848 /* seem that this controls has 2 forms one in case it is used with
849 * a Search Request and another when used ina Search Response
851 static bool encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out)
853 struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control);
854 struct asn1_data *data = asn1_init(mem_ctx);
856 if (!data) return false;
858 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
864 if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) {
868 if (!asn1_write_enumerated(data, lac->result)) {
873 if (!asn1_pop_tag(data)) {
877 *out = data_blob_talloc(mem_ctx, data->data, data->length);
878 if (out->data == NULL) {
886 static bool encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out)
888 struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control);
889 struct asn1_data *data = asn1_init(mem_ctx);
891 if (!data) return false;
893 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
897 if (!asn1_write_Integer(data, ldc->flags)) {
901 if (!asn1_write_Integer(data, ldc->max_attributes)) {
905 if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) {
909 if (!asn1_pop_tag(data)) {
913 *out = data_blob_talloc(mem_ctx, data->data, data->length);
914 if (out->data == NULL) {
922 static bool encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out)
928 *out = data_blob(NULL, 0);
932 static bool encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out)
938 *out = data_blob(NULL, 0);
942 static bool encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out)
948 *out = data_blob(NULL, 0);
952 static bool encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out)
958 *out = data_blob(NULL, 0);
962 static bool encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out)
968 *out = data_blob(NULL, 0);
972 static bool encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out)
974 struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control);
975 struct asn1_data *data = asn1_init(mem_ctx);
977 if (!data) return false;
979 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
983 if (!asn1_write_Integer(data, lvrc->beforeCount)) {
987 if (!asn1_write_Integer(data, lvrc->afterCount)) {
991 if (lvrc->type == 0) {
992 if (!asn1_push_tag(data, ASN1_CONTEXT(0))) {
996 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1000 if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) {
1004 if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) {
1008 if (!asn1_pop_tag(data)) { /*SEQUENCE*/
1012 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1016 if (!asn1_push_tag(data, ASN1_CONTEXT(1))) {
1020 if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) {
1024 if (!asn1_pop_tag(data)) { /*CONTEXT*/
1029 if (lvrc->ctxid_len) {
1030 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1035 if (!asn1_pop_tag(data)) {
1039 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1040 if (out->data == NULL) {
1048 static bool encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out)
1050 struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control);
1051 struct asn1_data *data = asn1_init(mem_ctx);
1053 if (!data) return false;
1055 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1059 if (!asn1_write_Integer(data, lvrc->targetPosition)) {
1063 if (!asn1_write_Integer(data, lvrc->contentCount)) {
1067 if (!asn1_write_enumerated(data, lvrc->vlv_result)) {
1071 if (lvrc->ctxid_len) {
1072 if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) {
1077 if (!asn1_pop_tag(data)) {
1081 *out = data_blob_talloc(mem_ctx, data->data, data->length);
1082 if (out->data == NULL) {
1090 struct control_handler ldap_known_controls[] = {
1091 { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request },
1092 { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request },
1093 { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request },
1094 { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response },
1095 { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
1096 { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request },
1097 { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request },
1098 { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request },
1099 { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request },
1100 { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request },
1101 { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request },
1102 { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request },
1103 { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request },
1104 { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request },
1105 { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response },
1106 /* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */
1107 { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL },
1108 /* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */
1109 { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL },
1110 { NULL, NULL, NULL }
1113 bool ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl)
1117 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1118 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1119 if (!ldap_known_controls[i].decode || !ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) {
1125 if (ldap_known_controls[i].oid == NULL) {
1132 bool ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value)
1136 if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
1140 if (!asn1_read_OctetString(data, mem_ctx, &oid)) {
1143 ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length);
1148 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
1150 if (!asn1_read_BOOLEAN(data, &critical)) {
1153 ctrl->critical = critical;
1155 ctrl->critical = false;
1160 if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) {
1161 *value = data_blob(NULL, 0);
1165 if (!asn1_read_OctetString(data, mem_ctx, value)) {
1170 if (!asn1_end_tag(data)) {
1177 bool ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl)
1182 for (i = 0; ldap_known_controls[i].oid != NULL; i++) {
1183 if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) {
1184 if (!ldap_known_controls[i].encode) {
1185 if (ctrl->critical) {
1188 /* not encoding this control */
1192 if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) {
1198 if (ldap_known_controls[i].oid == NULL) {
1202 if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) {
1206 if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) {
1210 if (ctrl->critical) {
1211 if (!asn1_write_BOOLEAN(data, ctrl->critical)) {
1220 if (!asn1_write_OctetString(data, value.data, value.length)) {
1225 if (!asn1_pop_tag(data)) {