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/libcli_ldap.h"
25 #include "libcli/ldap/ldap_proto.h"
26 #include "dsdb/samdb/samdb.h"
28 static bool decode_server_sort_response(void *mem_ctx
, DATA_BLOB in
, void *_out
)
30 void **out
= (void **)_out
;
32 struct asn1_data
*data
= asn1_init(mem_ctx
);
33 struct ldb_sort_resp_control
*lsrc
;
35 if (!data
) return false;
37 if (!asn1_load(data
, in
)) {
41 lsrc
= talloc(mem_ctx
, struct ldb_sort_resp_control
);
46 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
50 if (!asn1_read_enumerated(data
, &(lsrc
->result
))) {
54 lsrc
->attr_desc
= NULL
;
55 if (asn1_peek_tag(data
, ASN1_OCTET_STRING
)) {
56 if (!asn1_read_OctetString(data
, mem_ctx
, &attr
)) {
59 lsrc
->attr_desc
= talloc_strndup(lsrc
, (const char *)attr
.data
, attr
.length
);
60 if (!lsrc
->attr_desc
) {
65 if (!asn1_end_tag(data
)) {
74 static bool decode_server_sort_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
76 void **out
= (void **)_out
;
79 struct asn1_data
*data
= asn1_init(mem_ctx
);
80 struct ldb_server_sort_control
**lssc
;
83 if (!data
) return false;
85 if (!asn1_load(data
, in
)) {
89 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
95 for (num
= 0; asn1_peek_tag(data
, ASN1_SEQUENCE(0)); num
++) {
96 lssc
= talloc_realloc(mem_ctx
, lssc
, struct ldb_server_sort_control
*, num
+ 2);
100 lssc
[num
] = talloc_zero(lssc
, struct ldb_server_sort_control
);
105 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
109 if (!asn1_read_OctetString(data
, mem_ctx
, &attr
)) {
113 lssc
[num
]->attributeName
= talloc_strndup(lssc
[num
], (const char *)attr
.data
, attr
.length
);
114 if (!lssc
[num
]->attributeName
) {
118 if (asn1_peek_tag(data
, ASN1_OCTET_STRING
)) {
119 if (!asn1_read_OctetString(data
, mem_ctx
, &rule
)) {
122 lssc
[num
]->orderingRule
= talloc_strndup(lssc
[num
], (const char *)rule
.data
, rule
.length
);
123 if (!lssc
[num
]->orderingRule
) {
128 if (asn1_peek_tag(data
, ASN1_CONTEXT_SIMPLE(1))) {
130 if (!asn1_read_BOOLEAN_context(data
, &reverse
, 1)) {
133 lssc
[num
]->reverse
= reverse
;
136 if (!asn1_end_tag(data
)) {
145 if (!asn1_end_tag(data
)) {
154 static bool decode_extended_dn_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
156 void **out
= (void **)_out
;
157 struct asn1_data
*data
;
158 struct ldb_extended_dn_control
*ledc
;
160 /* The content of this control is optional */
161 if (in
.length
== 0) {
166 data
= asn1_init(mem_ctx
);
167 if (!data
) return false;
169 if (!asn1_load(data
, in
)) {
173 ledc
= talloc(mem_ctx
, struct ldb_extended_dn_control
);
178 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
182 if (!asn1_read_Integer(data
, &(ledc
->type
))) {
186 if (!asn1_end_tag(data
)) {
195 static bool decode_sd_flags_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
197 void **out
= (void **)_out
;
198 struct asn1_data
*data
= asn1_init(mem_ctx
);
199 struct ldb_sd_flags_control
*lsdfc
;
201 if (!data
) return false;
203 if (!asn1_load(data
, in
)) {
207 lsdfc
= talloc(mem_ctx
, struct ldb_sd_flags_control
);
212 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
216 if (!asn1_read_Integer(data
, (int *) &(lsdfc
->secinfo_flags
))) {
220 if (!asn1_end_tag(data
)) {
229 static bool decode_search_options_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
231 void **out
= (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
, (int *) &(lsoc
->search_options
))) {
254 if (!asn1_end_tag(data
)) {
263 static bool decode_paged_results_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
265 void **out
= (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
)
314 void **out
= (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 void **out
= (void **)_out
;
371 DATA_BLOB source_attribute
;
372 struct asn1_data
*data
= asn1_init(mem_ctx
);
373 struct ldb_asq_control
*lac
;
375 if (!data
) return false;
377 if (!asn1_load(data
, in
)) {
381 lac
= talloc(mem_ctx
, struct ldb_asq_control
);
386 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
390 if (asn1_peek_tag(data
, ASN1_OCTET_STRING
)) {
392 if (!asn1_read_OctetString(data
, mem_ctx
, &source_attribute
)) {
395 lac
->src_attr_len
= source_attribute
.length
;
396 if (lac
->src_attr_len
) {
397 lac
->source_attribute
= talloc_strndup(lac
, (const char *)source_attribute
.data
, source_attribute
.length
);
399 if (!(lac
->source_attribute
)) {
403 lac
->source_attribute
= NULL
;
408 } else if (asn1_peek_tag(data
, ASN1_ENUMERATED
)) {
410 if (!asn1_read_enumerated(data
, &(lac
->result
))) {
420 if (!asn1_end_tag(data
)) {
429 static bool decode_verify_name_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
431 void **out
= (void **)_out
;
433 struct asn1_data
*data
= asn1_init(mem_ctx
);
434 struct ldb_verify_name_control
*lvnc
;
437 if (!data
) return false;
439 if (!asn1_load(data
, in
)) {
443 lvnc
= talloc(mem_ctx
, struct ldb_verify_name_control
);
448 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
452 if (!asn1_read_Integer(data
, &(lvnc
->flags
))) {
456 if (!asn1_read_OctetString(data
, mem_ctx
, &name
)) {
461 len
= utf16_len_n(name
.data
, name
.length
);
462 convert_string_talloc(mem_ctx
, CH_UTF16
, CH_UNIX
,
464 (void **)&lvnc
->gc
, &lvnc
->gc_len
);
474 if (!asn1_end_tag(data
)) {
482 static bool encode_verify_name_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
484 struct ldb_verify_name_control
*lvnc
= talloc_get_type(in
, struct ldb_verify_name_control
);
485 struct asn1_data
*data
= asn1_init(mem_ctx
);
488 if (!data
) return false;
490 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
494 if (!asn1_write_Integer(data
, lvnc
->flags
)) {
499 convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
,
500 lvnc
->gc
, lvnc
->gc_len
,
501 (void **)&gc_utf16
.data
, &gc_utf16
.length
);
502 if (!asn1_write_OctetString(data
, gc_utf16
.data
, gc_utf16
.length
)) {
506 if (!asn1_write_OctetString(data
, NULL
, 0)) {
511 if (!asn1_pop_tag(data
)) {
515 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
524 static bool decode_vlv_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
526 void **out
= (void **)_out
;
527 DATA_BLOB assertion_value
, context_id
;
528 struct asn1_data
*data
= asn1_init(mem_ctx
);
529 struct ldb_vlv_req_control
*lvrc
;
531 if (!data
) return false;
533 if (!asn1_load(data
, in
)) {
537 lvrc
= talloc(mem_ctx
, struct ldb_vlv_req_control
);
542 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
546 if (!asn1_read_Integer(data
, &(lvrc
->beforeCount
))) {
550 if (!asn1_read_Integer(data
, &(lvrc
->afterCount
))) {
554 if (asn1_peek_tag(data
, ASN1_CONTEXT(0))) {
558 if (!asn1_start_tag(data
, ASN1_CONTEXT(0))) {
562 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
566 if (!asn1_read_Integer(data
, &(lvrc
->match
.byOffset
.offset
))) {
570 if (!asn1_read_Integer(data
, &(lvrc
->match
.byOffset
.contentCount
))) {
574 if (!asn1_end_tag(data
)) { /*SEQUENCE*/
578 if (!asn1_end_tag(data
)) { /*CONTEXT*/
586 if (!asn1_start_tag(data
, ASN1_CONTEXT(1))) {
590 if (!asn1_read_OctetString(data
, mem_ctx
, &assertion_value
)) {
593 lvrc
->match
.gtOrEq
.value_len
= assertion_value
.length
;
594 if (lvrc
->match
.gtOrEq
.value_len
) {
595 lvrc
->match
.gtOrEq
.value
= talloc_memdup(lvrc
, assertion_value
.data
, assertion_value
.length
);
597 if (!(lvrc
->match
.gtOrEq
.value
)) {
601 lvrc
->match
.gtOrEq
.value
= NULL
;
604 if (!asn1_end_tag(data
)) { /*CONTEXT*/
609 if (asn1_peek_tag(data
, ASN1_OCTET_STRING
)) {
610 if (!asn1_read_OctetString(data
, mem_ctx
, &context_id
)) {
613 lvrc
->ctxid_len
= context_id
.length
;
614 if (lvrc
->ctxid_len
) {
615 lvrc
->contextId
= talloc_memdup(lvrc
, context_id
.data
, context_id
.length
);
617 if (!(lvrc
->contextId
)) {
621 lvrc
->contextId
= NULL
;
624 lvrc
->contextId
= NULL
;
628 if (!asn1_end_tag(data
)) {
637 static bool decode_vlv_response(void *mem_ctx
, DATA_BLOB in
, void *_out
)
639 void **out
= (void **)_out
;
640 DATA_BLOB context_id
;
641 struct asn1_data
*data
= asn1_init(mem_ctx
);
642 struct ldb_vlv_resp_control
*lvrc
;
644 if (!data
) return false;
646 if (!asn1_load(data
, in
)) {
650 lvrc
= talloc(mem_ctx
, struct ldb_vlv_resp_control
);
655 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
659 if (!asn1_read_Integer(data
, &(lvrc
->targetPosition
))) {
663 if (!asn1_read_Integer(data
, &(lvrc
->contentCount
))) {
667 if (!asn1_read_enumerated(data
, &(lvrc
->vlv_result
))) {
671 if (asn1_peek_tag(data
, ASN1_OCTET_STRING
)) {
672 if (!asn1_read_OctetString(data
, mem_ctx
, &context_id
)) {
675 lvrc
->contextId
= talloc_strndup(lvrc
, (const char *)context_id
.data
, context_id
.length
);
676 if (!lvrc
->contextId
) {
679 lvrc
->ctxid_len
= context_id
.length
;
681 lvrc
->contextId
= NULL
;
685 if (!asn1_end_tag(data
)) {
694 static bool encode_server_sort_response(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
696 struct ldb_sort_resp_control
*lsrc
= talloc_get_type(in
, struct ldb_sort_resp_control
);
697 struct asn1_data
*data
= asn1_init(mem_ctx
);
699 if (!data
) return false;
701 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
705 if (!asn1_write_enumerated(data
, lsrc
->result
)) {
709 if (lsrc
->attr_desc
) {
710 if (!asn1_write_OctetString(data
, lsrc
->attr_desc
, strlen(lsrc
->attr_desc
))) {
715 if (!asn1_pop_tag(data
)) {
719 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
728 static bool encode_server_sort_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
730 struct ldb_server_sort_control
**lssc
= talloc_get_type(in
, struct ldb_server_sort_control
*);
731 struct asn1_data
*data
= asn1_init(mem_ctx
);
734 if (!data
) return false;
736 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
742 SortKeyList ::= SEQUENCE OF SEQUENCE {
743 attributeType AttributeDescription,
744 orderingRule [0] MatchingRuleId OPTIONAL,
745 reverseOrder [1] BOOLEAN DEFAULT FALSE }
747 for (num
= 0; lssc
[num
]; num
++) {
748 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
752 if (!asn1_write_OctetString(data
, lssc
[num
]->attributeName
, strlen(lssc
[num
]->attributeName
))) {
756 if (lssc
[num
]->orderingRule
) {
757 if (!asn1_write_OctetString(data
, lssc
[num
]->orderingRule
, strlen(lssc
[num
]->orderingRule
))) {
762 if (lssc
[num
]->reverse
) {
763 if (!asn1_write_BOOLEAN_context(data
, lssc
[num
]->reverse
, 1)) {
768 if (!asn1_pop_tag(data
)) {
773 if (!asn1_pop_tag(data
)) {
777 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
786 static bool encode_extended_dn_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
788 struct ldb_extended_dn_control
*ledc
= talloc_get_type(in
, struct ldb_extended_dn_control
);
789 struct asn1_data
*data
;
792 *out
= data_blob(NULL
, 0);
796 data
= asn1_init(mem_ctx
);
798 if (!data
) return false;
800 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
804 if (!asn1_write_Integer(data
, ledc
->type
)) {
808 if (!asn1_pop_tag(data
)) {
812 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
821 static bool encode_sd_flags_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
823 struct ldb_sd_flags_control
*lsdfc
= talloc_get_type(in
, struct ldb_sd_flags_control
);
824 struct asn1_data
*data
= asn1_init(mem_ctx
);
826 if (!data
) return false;
828 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
832 if (!asn1_write_Integer(data
, lsdfc
->secinfo_flags
)) {
836 if (!asn1_pop_tag(data
)) {
840 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
849 static bool encode_search_options_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
851 struct ldb_search_options_control
*lsoc
= talloc_get_type(in
, struct ldb_search_options_control
);
852 struct asn1_data
*data
= asn1_init(mem_ctx
);
854 if (!data
) return false;
856 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
860 if (!asn1_write_Integer(data
, lsoc
->search_options
)) {
864 if (!asn1_pop_tag(data
)) {
868 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
877 static bool encode_paged_results_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
879 struct ldb_paged_control
*lprc
= talloc_get_type(in
, struct ldb_paged_control
);
880 struct asn1_data
*data
= asn1_init(mem_ctx
);
882 if (!data
) return false;
884 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
888 if (!asn1_write_Integer(data
, lprc
->size
)) {
892 if (!asn1_write_OctetString(data
, lprc
->cookie
, lprc
->cookie_len
)) {
896 if (!asn1_pop_tag(data
)) {
900 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
909 /* seem that this controls has 2 forms one in case it is used with
910 * a Search Request and another when used ina Search Response
912 static bool encode_asq_control(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
914 struct ldb_asq_control
*lac
= talloc_get_type(in
, struct ldb_asq_control
);
915 struct asn1_data
*data
= asn1_init(mem_ctx
);
917 if (!data
) return false;
919 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
925 if (!asn1_write_OctetString(data
, lac
->source_attribute
, lac
->src_attr_len
)) {
929 if (!asn1_write_enumerated(data
, lac
->result
)) {
934 if (!asn1_pop_tag(data
)) {
938 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
947 static bool encode_dirsync_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
949 struct ldb_dirsync_control
*ldc
= talloc_get_type(in
, struct ldb_dirsync_control
);
950 struct asn1_data
*data
= asn1_init(mem_ctx
);
952 if (!data
) return false;
954 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
958 if (!asn1_write_Integer(data
, ldc
->flags
)) {
962 if (!asn1_write_Integer(data
, ldc
->max_attributes
)) {
966 if (!asn1_write_OctetString(data
, ldc
->cookie
, ldc
->cookie_len
)) {
970 if (!asn1_pop_tag(data
)) {
974 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
983 static bool encode_vlv_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
985 struct ldb_vlv_req_control
*lvrc
= talloc_get_type(in
, struct ldb_vlv_req_control
);
986 struct asn1_data
*data
= asn1_init(mem_ctx
);
988 if (!data
) return false;
990 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
994 if (!asn1_write_Integer(data
, lvrc
->beforeCount
)) {
998 if (!asn1_write_Integer(data
, lvrc
->afterCount
)) {
1002 if (lvrc
->type
== 0) {
1003 if (!asn1_push_tag(data
, ASN1_CONTEXT(0))) {
1007 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
1011 if (!asn1_write_Integer(data
, lvrc
->match
.byOffset
.offset
)) {
1015 if (!asn1_write_Integer(data
, lvrc
->match
.byOffset
.contentCount
)) {
1019 if (!asn1_pop_tag(data
)) { /*SEQUENCE*/
1023 if (!asn1_pop_tag(data
)) { /*CONTEXT*/
1027 if (!asn1_push_tag(data
, ASN1_CONTEXT(1))) {
1031 if (!asn1_write_OctetString(data
, lvrc
->match
.gtOrEq
.value
, lvrc
->match
.gtOrEq
.value_len
)) {
1035 if (!asn1_pop_tag(data
)) { /*CONTEXT*/
1040 if (lvrc
->ctxid_len
) {
1041 if (!asn1_write_OctetString(data
, lvrc
->contextId
, lvrc
->ctxid_len
)) {
1046 if (!asn1_pop_tag(data
)) {
1050 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
1059 static bool encode_vlv_response(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
1061 struct ldb_vlv_resp_control
*lvrc
= talloc_get_type(in
, struct ldb_vlv_resp_control
);
1062 struct asn1_data
*data
= asn1_init(mem_ctx
);
1064 if (!data
) return false;
1066 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
1070 if (!asn1_write_Integer(data
, lvrc
->targetPosition
)) {
1074 if (!asn1_write_Integer(data
, lvrc
->contentCount
)) {
1078 if (!asn1_write_enumerated(data
, lvrc
->vlv_result
)) {
1082 if (lvrc
->ctxid_len
) {
1083 if (!asn1_write_OctetString(data
, lvrc
->contextId
, lvrc
->ctxid_len
)) {
1088 if (!asn1_pop_tag(data
)) {
1092 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
1101 static bool encode_openldap_dereference(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
1103 struct dsdb_openldap_dereference_control
*control
= talloc_get_type(in
, struct dsdb_openldap_dereference_control
);
1105 struct asn1_data
*data
= asn1_init(mem_ctx
);
1107 if (!data
) return false;
1109 if (!control
) return false;
1111 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
1115 for (i
=0; control
->dereference
&& control
->dereference
[i
]; i
++) {
1116 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
1119 if (!asn1_write_OctetString(data
, control
->dereference
[i
]->source_attribute
, strlen(control
->dereference
[i
]->source_attribute
))) {
1122 if (!asn1_push_tag(data
, ASN1_SEQUENCE(0))) {
1125 for (j
=0; control
->dereference
&& control
->dereference
[i
]->dereference_attribute
[j
]; j
++) {
1126 if (!asn1_write_OctetString(data
, control
->dereference
[i
]->dereference_attribute
[j
],
1127 strlen(control
->dereference
[i
]->dereference_attribute
[j
]))) {
1132 if (!asn1_pop_tag(data
)) {
1135 if (!asn1_pop_tag(data
)) {
1139 if (!asn1_pop_tag(data
)) {
1143 if (!asn1_extract_blob(data
, mem_ctx
, out
)) {
1151 static bool decode_openldap_dereference(void *mem_ctx
, DATA_BLOB in
, void *_out
)
1153 void **out
= (void **)_out
;
1154 struct asn1_data
*data
= asn1_init(mem_ctx
);
1155 struct dsdb_openldap_dereference_result_control
*control
;
1156 struct dsdb_openldap_dereference_result
**r
= NULL
;
1158 if (!data
) return false;
1160 control
= talloc(mem_ctx
, struct dsdb_openldap_dereference_result_control
);
1161 if (!control
) return false;
1163 if (!asn1_load(data
, in
)) {
1167 control
= talloc(mem_ctx
, struct dsdb_openldap_dereference_result_control
);
1172 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
1176 while (asn1_tag_remaining(data
) > 0) {
1177 r
= talloc_realloc(control
, r
, struct dsdb_openldap_dereference_result
*, i
+ 2);
1181 r
[i
] = talloc_zero(r
, struct dsdb_openldap_dereference_result
);
1186 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) {
1190 if (!asn1_read_OctetString_talloc(r
[i
], data
, &r
[i
]->source_attribute
)) {
1193 if (!asn1_read_OctetString_talloc(r
[i
], data
, &r
[i
]->dereferenced_dn
)) {
1196 if (asn1_peek_tag(data
, ASN1_CONTEXT(0))) {
1197 if (!asn1_start_tag(data
, ASN1_CONTEXT(0))) {
1200 if (!ldap_decode_attribs_bare(r
, data
, &r
[i
]->attributes
,
1201 &r
[i
]->num_attributes
)) {
1204 if (!asn1_end_tag(data
)) {
1208 if (!asn1_end_tag(data
)) {
1215 if (!asn1_end_tag(data
)) {
1219 control
->attributes
= r
;
1225 static bool encode_flag_request(void *mem_ctx
, void *in
, DATA_BLOB
*out
)
1231 *out
= data_blob(NULL
, 0);
1235 static bool decode_flag_request(void *mem_ctx
, DATA_BLOB in
, void *_out
)
1237 if (in
.length
!= 0) {
1244 static const struct ldap_control_handler ldap_known_controls
[] = {
1245 { LDB_CONTROL_PAGED_RESULTS_OID
, decode_paged_results_request
, encode_paged_results_request
},
1246 { LDB_CONTROL_SD_FLAGS_OID
, decode_sd_flags_request
, encode_sd_flags_request
},
1247 { LDB_CONTROL_DOMAIN_SCOPE_OID
, decode_flag_request
, encode_flag_request
},
1248 { LDB_CONTROL_SEARCH_OPTIONS_OID
, decode_search_options_request
, encode_search_options_request
},
1249 { LDB_CONTROL_NOTIFICATION_OID
, decode_flag_request
, encode_flag_request
},
1250 { LDB_CONTROL_TREE_DELETE_OID
, decode_flag_request
, encode_flag_request
},
1251 { LDB_CONTROL_SHOW_DELETED_OID
, decode_flag_request
, encode_flag_request
},
1252 { LDB_CONTROL_SHOW_RECYCLED_OID
, decode_flag_request
, encode_flag_request
},
1253 { LDB_CONTROL_SHOW_DEACTIVATED_LINK_OID
, decode_flag_request
, encode_flag_request
},
1254 { LDB_CONTROL_EXTENDED_DN_OID
, decode_extended_dn_request
, encode_extended_dn_request
},
1255 { LDB_CONTROL_SERVER_SORT_OID
, decode_server_sort_request
, encode_server_sort_request
},
1256 { LDB_CONTROL_SORT_RESP_OID
, decode_server_sort_response
, encode_server_sort_response
},
1257 { LDB_CONTROL_ASQ_OID
, decode_asq_control
, encode_asq_control
},
1258 { LDB_CONTROL_DIRSYNC_OID
, decode_dirsync_request
, encode_dirsync_request
},
1259 { LDB_CONTROL_DIRSYNC_EX_OID
, decode_dirsync_request
, encode_dirsync_request
},
1260 { LDB_CONTROL_VLV_REQ_OID
, decode_vlv_request
, encode_vlv_request
},
1261 { LDB_CONTROL_VLV_RESP_OID
, decode_vlv_response
, encode_vlv_response
},
1262 { LDB_CONTROL_PERMISSIVE_MODIFY_OID
, decode_flag_request
, encode_flag_request
},
1263 { LDB_CONTROL_SERVER_LAZY_COMMIT
, decode_flag_request
, encode_flag_request
},
1264 { LDB_CONTROL_RODC_DCPROMO_OID
, decode_flag_request
, encode_flag_request
},
1265 { LDB_CONTROL_RELAX_OID
, decode_flag_request
, encode_flag_request
},
1266 { DSDB_OPENLDAP_DEREFERENCE_CONTROL
, decode_openldap_dereference
, encode_openldap_dereference
},
1267 { LDB_CONTROL_VERIFY_NAME_OID
, decode_verify_name_request
, encode_verify_name_request
},
1269 /* the following are internal only, with a network
1271 { DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID
, decode_flag_request
, encode_flag_request
},
1273 /* all the ones below are internal only, and have no network
1275 { DSDB_CONTROL_CURRENT_PARTITION_OID
, NULL
, NULL
},
1276 { DSDB_CONTROL_REPLICATED_UPDATE_OID
, NULL
, NULL
},
1277 { DSDB_CONTROL_DN_STORAGE_FORMAT_OID
, NULL
, NULL
},
1278 { LDB_CONTROL_RECALCULATE_SD_OID
, NULL
, NULL
},
1279 { LDB_CONTROL_REVEAL_INTERNALS
, NULL
, NULL
},
1280 { LDB_CONTROL_AS_SYSTEM_OID
, NULL
, NULL
},
1281 { DSDB_CONTROL_PASSWORD_CHANGE_STATUS_OID
, NULL
, NULL
},
1282 { DSDB_CONTROL_PASSWORD_HASH_VALUES_OID
, NULL
, NULL
},
1283 { DSDB_CONTROL_PASSWORD_CHANGE_OID
, NULL
, NULL
},
1284 { DSDB_CONTROL_APPLY_LINKS
, NULL
, NULL
},
1285 { LDB_CONTROL_BYPASS_OPERATIONAL_OID
, NULL
, NULL
},
1286 { DSDB_CONTROL_CHANGEREPLMETADATA_OID
, NULL
, NULL
},
1287 { LDB_CONTROL_PROVISION_OID
, NULL
, NULL
},
1288 { DSDB_EXTENDED_REPLICATED_OBJECTS_OID
, NULL
, NULL
},
1289 { DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID
, NULL
, NULL
},
1290 { DSDB_EXTENDED_ALLOCATE_RID_POOL
, NULL
, NULL
},
1291 { DSDB_CONTROL_NO_GLOBAL_CATALOG
, NULL
, NULL
},
1292 { DSDB_EXTENDED_SCHEMA_UPGRADE_IN_PROGRESS_OID
, NULL
, NULL
},
1293 { NULL
, NULL
, NULL
}
1296 const struct ldap_control_handler
*samba_ldap_control_handlers(void)
1298 return ldap_known_controls
;