2006-01-06 07:01:23 +03:00
/*
2016-04-20 08:10:41 +03:00
Unix SMB / CIFS implementation .
2006-01-06 07:01:23 +03:00
LDAP protocol helper functions for SAMBA
Copyright ( C ) Simo Sorce 2005
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-01-06 07:01:23 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-01-06 07:01:23 +03:00
*/
# include "includes.h"
2016-02-17 13:41:47 +03:00
# include <ldb.h>
2008-10-11 23:31:42 +04:00
# include "../lib/util/asn1.h"
2010-05-21 11:39:15 +04:00
# include "libcli/ldap/libcli_ldap.h"
2008-10-20 20:59:51 +04:00
# include "libcli/ldap/ldap_proto.h"
2008-12-16 10:28:55 +03:00
# include "dsdb/samdb/samdb.h"
2006-01-06 07:01:23 +03:00
2009-02-24 16:45:01 +03:00
static bool decode_server_sort_response ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-01-06 07:01:23 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-01-06 07:01:23 +03:00
DATA_BLOB attr ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
struct ldb_sort_resp_control * lsrc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
lsrc = talloc ( mem_ctx , struct ldb_sort_resp_control ) ;
if ( ! lsrc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_enumerated ( data , & ( lsrc - > result ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
lsrc - > attr_desc = NULL ;
2007-05-21 10:12:06 +04:00
if ( asn1_peek_tag ( data , ASN1_OCTET_STRING ) ) {
if ( ! asn1_read_OctetString ( data , mem_ctx , & attr ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2006-01-17 21:56:04 +03:00
lsrc - > attr_desc = talloc_strndup ( lsrc , ( const char * ) attr . data , attr . length ) ;
2006-01-06 07:01:23 +03:00
if ( ! lsrc - > attr_desc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
* out = lsrc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2009-02-24 16:45:01 +03:00
static bool decode_server_sort_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-01-06 07:01:23 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-01-06 07:01:23 +03:00
DATA_BLOB attr ;
DATA_BLOB rule ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
struct ldb_server_sort_control * * lssc ;
int num ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
lssc = NULL ;
2007-05-21 10:12:06 +04:00
for ( num = 0 ; asn1_peek_tag ( data , ASN1_SEQUENCE ( 0 ) ) ; num + + ) {
2006-01-06 07:01:23 +03:00
lssc = talloc_realloc ( mem_ctx , lssc , struct ldb_server_sort_control * , num + 2 ) ;
if ( ! lssc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2006-02-15 16:33:33 +03:00
lssc [ num ] = talloc_zero ( lssc , struct ldb_server_sort_control ) ;
2006-01-06 07:01:23 +03:00
if ( ! lssc [ num ] ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_OctetString ( data , mem_ctx , & attr ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2006-01-17 21:56:04 +03:00
lssc [ num ] - > attributeName = talloc_strndup ( lssc [ num ] , ( const char * ) attr . data , attr . length ) ;
2006-01-06 07:01:23 +03:00
if ( ! lssc [ num ] - > attributeName ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-03-04 04:46:46 +03:00
if ( asn1_peek_tag ( data , ASN1_CONTEXT_SIMPLE ( 0 ) ) ) {
if ( ! asn1_read_ContextSimple ( data , mem_ctx , 0 , & rule ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2006-01-17 21:56:04 +03:00
lssc [ num ] - > orderingRule = talloc_strndup ( lssc [ num ] , ( const char * ) rule . data , rule . length ) ;
2006-01-06 07:01:23 +03:00
if ( ! lssc [ num ] - > orderingRule ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
2009-06-10 05:45:13 +04:00
if ( asn1_peek_tag ( data , ASN1_CONTEXT_SIMPLE ( 1 ) ) ) {
2007-10-07 02:28:14 +04:00
bool reverse ;
2009-06-10 05:45:13 +04:00
if ( ! asn1_read_BOOLEAN_context ( data , & reverse , 1 ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2006-04-30 17:54:03 +04:00
lssc [ num ] - > reverse = reverse ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
2006-03-15 08:31:51 +03:00
if ( lssc ! = NULL ) {
lssc [ num ] = NULL ;
}
2006-01-06 07:01:23 +03:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
* out = lssc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2009-02-24 16:45:01 +03:00
static bool decode_extended_dn_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-01-06 07:01:23 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2007-11-29 10:00:04 +03:00
struct asn1_data * data ;
2006-01-06 07:01:23 +03:00
struct ldb_extended_dn_control * ledc ;
2007-11-29 10:00:04 +03:00
/* The content of this control is optional */
if ( in . length = = 0 ) {
* out = NULL ;
return true ;
}
2020-04-03 02:18:03 +03:00
data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
ledc = talloc ( mem_ctx , struct ldb_extended_dn_control ) ;
if ( ! ledc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( ledc - > type ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
* out = ledc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2009-02-24 16:45:01 +03:00
static bool decode_sd_flags_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-08-05 14:26:23 +04:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-08-05 14:26:23 +04:00
struct ldb_sd_flags_control * lsdfc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
lsdfc = talloc ( mem_ctx , struct ldb_sd_flags_control ) ;
if ( ! lsdfc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2009-09-29 13:49:50 +04:00
if ( ! asn1_read_Integer ( data , ( int * ) & ( lsdfc - > secinfo_flags ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
* out = lsdfc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-08-05 14:26:23 +04:00
}
2009-02-24 16:45:01 +03:00
static bool decode_search_options_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-08-05 15:18:14 +04:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-08-05 15:18:14 +04:00
struct ldb_search_options_control * lsoc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
lsoc = talloc ( mem_ctx , struct ldb_search_options_control ) ;
if ( ! lsoc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2009-09-29 13:49:50 +04:00
if ( ! asn1_read_Integer ( data , ( int * ) & ( lsoc - > search_options ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
* out = lsoc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-08-05 15:18:14 +04:00
}
2009-02-24 16:45:01 +03:00
static bool decode_paged_results_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-01-06 07:01:23 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-01-06 07:01:23 +03:00
DATA_BLOB cookie ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
struct ldb_paged_control * lprc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
lprc = talloc ( mem_ctx , struct ldb_paged_control ) ;
if ( ! lprc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lprc - > size ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_OctetString ( data , mem_ctx , & cookie ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
lprc - > cookie_len = cookie . length ;
if ( lprc - > cookie_len ) {
lprc - > cookie = talloc_memdup ( lprc , cookie . data , cookie . length ) ;
if ( ! ( lprc - > cookie ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
} else {
lprc - > cookie = NULL ;
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
* out = lprc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2009-02-24 16:45:01 +03:00
static bool decode_dirsync_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-01-17 07:04:57 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-01-17 07:04:57 +03:00
DATA_BLOB cookie ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-17 07:04:57 +03:00
struct ldb_dirsync_control * ldc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
ldc = talloc ( mem_ctx , struct ldb_dirsync_control ) ;
if ( ! ldc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( ldc - > flags ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( ldc - > max_attributes ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_OctetString ( data , mem_ctx , & cookie ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
ldc - > cookie_len = cookie . length ;
if ( ldc - > cookie_len ) {
ldc - > cookie = talloc_memdup ( ldc , cookie . data , cookie . length ) ;
if ( ! ( ldc - > cookie ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
} else {
ldc - > cookie = NULL ;
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
* out = ldc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-01-17 07:04:57 +03:00
}
2006-01-14 04:06:16 +03:00
/* seem that this controls has 2 forms one in case it is used with
* a Search Request and another when used ina Search Response
*/
2009-02-24 16:45:01 +03:00
static bool decode_asq_control ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-01-14 04:06:16 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-01-14 04:06:16 +03:00
DATA_BLOB source_attribute ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-14 04:06:16 +03:00
struct ldb_asq_control * lac ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
lac = talloc ( mem_ctx , struct ldb_asq_control ) ;
if ( ! lac ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
2007-05-21 10:12:06 +04:00
if ( asn1_peek_tag ( data , ASN1_OCTET_STRING ) ) {
2006-01-14 04:06:16 +03:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_OctetString ( data , mem_ctx , & source_attribute ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
lac - > src_attr_len = source_attribute . length ;
if ( lac - > src_attr_len ) {
2006-02-15 18:19:10 +03:00
lac - > source_attribute = talloc_strndup ( lac , ( const char * ) source_attribute . data , source_attribute . length ) ;
2006-01-14 04:06:16 +03:00
if ( ! ( lac - > source_attribute ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
} else {
lac - > source_attribute = NULL ;
}
lac - > request = 1 ;
2007-05-21 10:12:06 +04:00
} else if ( asn1_peek_tag ( data , ASN1_ENUMERATED ) ) {
2006-01-14 04:06:16 +03:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_enumerated ( data , & ( lac - > result ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
lac - > request = 0 ;
} else {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
* out = lac ;
2007-10-07 02:28:14 +04:00
return true ;
2006-01-14 04:06:16 +03:00
}
2012-05-15 22:15:38 +04:00
static bool decode_verify_name_request ( void * mem_ctx , DATA_BLOB in , void * _out )
{
void * * out = ( void * * ) _out ;
DATA_BLOB name ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2012-05-15 22:15:38 +04:00
struct ldb_verify_name_control * lvnc ;
int len ;
if ( ! data ) return false ;
if ( ! asn1_load ( data , in ) ) {
return false ;
}
lvnc = talloc ( mem_ctx , struct ldb_verify_name_control ) ;
if ( ! lvnc ) {
return false ;
}
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
if ( ! asn1_read_Integer ( data , & ( lvnc - > flags ) ) ) {
return false ;
}
if ( ! asn1_read_OctetString ( data , mem_ctx , & name ) ) {
return false ;
}
if ( name . length ) {
len = utf16_len_n ( name . data , name . length ) ;
convert_string_talloc ( mem_ctx , CH_UTF16 , CH_UNIX ,
name . data , len ,
( void * * ) & lvnc - > gc , & lvnc - > gc_len ) ;
if ( ! ( lvnc - > gc ) ) {
return false ;
}
} else {
lvnc - > gc_len = 0 ;
lvnc - > gc = NULL ;
}
if ( ! asn1_end_tag ( data ) ) {
return false ;
}
* out = lvnc ;
return true ;
}
static bool encode_verify_name_request ( void * mem_ctx , void * in , DATA_BLOB * out )
{
struct ldb_verify_name_control * lvnc = talloc_get_type ( in , struct ldb_verify_name_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2012-05-15 22:15:38 +04:00
DATA_BLOB gc_utf16 ;
if ( ! data ) return false ;
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
if ( ! asn1_write_Integer ( data , lvnc - > flags ) ) {
return false ;
}
if ( lvnc - > gc_len ) {
convert_string_talloc ( mem_ctx , CH_UNIX , CH_UTF16 ,
lvnc - > gc , lvnc - > gc_len ,
( void * * ) & gc_utf16 . data , & gc_utf16 . length ) ;
if ( ! asn1_write_OctetString ( data , gc_utf16 . data , gc_utf16 . length ) ) {
return false ;
}
} else {
if ( ! asn1_write_OctetString ( data , NULL , 0 ) ) {
return false ;
}
}
if ( ! asn1_pop_tag ( data ) ) {
return false ;
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2012-05-15 22:15:38 +04:00
return false ;
}
2016-01-02 22:10:53 +03:00
2012-05-15 22:15:38 +04:00
talloc_free ( data ) ;
return true ;
}
2009-02-24 16:45:01 +03:00
static bool decode_vlv_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-02-06 04:21:17 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-02-06 04:21:17 +03:00
DATA_BLOB assertion_value , context_id ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-02-06 04:21:17 +03:00
struct ldb_vlv_req_control * lvrc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
lvrc = talloc ( mem_ctx , struct ldb_vlv_req_control ) ;
if ( ! lvrc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lvrc - > beforeCount ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lvrc - > afterCount ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( asn1_peek_tag ( data , ASN1_CONTEXT ( 0 ) ) ) {
2006-02-06 04:21:17 +03:00
lvrc - > type = 0 ;
2006-02-22 04:31:35 +03:00
2016-03-04 04:46:46 +03:00
if ( ! asn1_start_tag ( data , ASN1_CONTEXT ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lvrc - > match . byOffset . offset ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lvrc - > match . byOffset . contentCount ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) { /*CONTEXT*/
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
} else {
lvrc - > type = 1 ;
2016-03-04 04:46:46 +03:00
if ( ! asn1_read_ContextSimple ( data , mem_ctx , 1 , & assertion_value ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-22 04:31:35 +03:00
}
2006-02-06 04:21:17 +03:00
lvrc - > match . gtOrEq . value_len = assertion_value . length ;
if ( lvrc - > match . gtOrEq . value_len ) {
lvrc - > match . gtOrEq . value = talloc_memdup ( lvrc , assertion_value . data , assertion_value . length ) ;
if ( ! ( lvrc - > match . gtOrEq . value ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
} else {
lvrc - > match . gtOrEq . value = NULL ;
}
}
2007-05-21 10:12:06 +04:00
if ( asn1_peek_tag ( data , ASN1_OCTET_STRING ) ) {
if ( ! asn1_read_OctetString ( data , mem_ctx , & context_id ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
lvrc - > ctxid_len = context_id . length ;
if ( lvrc - > ctxid_len ) {
lvrc - > contextId = talloc_memdup ( lvrc , context_id . data , context_id . length ) ;
if ( ! ( lvrc - > contextId ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
} else {
lvrc - > contextId = NULL ;
}
} else {
lvrc - > contextId = NULL ;
lvrc - > ctxid_len = 0 ;
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
* out = lvrc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-02-06 04:21:17 +03:00
}
2009-02-24 16:45:01 +03:00
static bool decode_vlv_response ( void * mem_ctx , DATA_BLOB in , void * _out )
2006-02-06 04:21:17 +03:00
{
2009-02-24 16:45:01 +03:00
void * * out = ( void * * ) _out ;
2006-02-06 04:21:17 +03:00
DATA_BLOB context_id ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-02-06 04:21:17 +03:00
struct ldb_vlv_resp_control * lvrc ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_load ( data , in ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
lvrc = talloc ( mem_ctx , struct ldb_vlv_resp_control ) ;
if ( ! lvrc ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lvrc - > targetPosition ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_Integer ( data , & ( lvrc - > contentCount ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_read_enumerated ( data , & ( lvrc - > vlv_result ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( asn1_peek_tag ( data , ASN1_OCTET_STRING ) ) {
if ( ! asn1_read_OctetString ( data , mem_ctx , & context_id ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2015-12-22 07:10:14 +03:00
lvrc - > contextId = talloc_memdup ( lvrc , ( const char * ) context_id . data , context_id . length ) ;
2006-02-06 04:21:17 +03:00
if ( ! lvrc - > contextId ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
lvrc - > ctxid_len = context_id . length ;
} else {
lvrc - > contextId = NULL ;
lvrc - > ctxid_len = 0 ;
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_end_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
* out = lvrc ;
2007-10-07 02:28:14 +04:00
return true ;
2006-02-06 04:21:17 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_server_sort_response ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-01-06 07:01:23 +03:00
{
struct ldb_sort_resp_control * lsrc = talloc_get_type ( in , struct ldb_sort_resp_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_enumerated ( data , lsrc - > result ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
if ( lsrc - > attr_desc ) {
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , lsrc - > attr_desc , strlen ( lsrc - > attr_desc ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_server_sort_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-01-06 07:01:23 +03:00
{
struct ldb_server_sort_control * * lssc = talloc_get_type ( in , struct ldb_server_sort_control * ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
int num ;
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2009-06-10 05:45:13 +04:00
/*
RFC2891 section 1.1 :
SortKeyList : : = SEQUENCE OF SEQUENCE {
attributeType AttributeDescription ,
orderingRule [ 0 ] MatchingRuleId OPTIONAL ,
reverseOrder [ 1 ] BOOLEAN DEFAULT FALSE }
*/
2006-01-06 07:01:23 +03:00
for ( num = 0 ; lssc [ num ] ; num + + ) {
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , lssc [ num ] - > attributeName , strlen ( lssc [ num ] - > attributeName ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
if ( lssc [ num ] - > orderingRule ) {
2015-12-17 00:33:54 +03:00
DATA_BLOB order = data_blob_string_const ( lssc [ num ] - > orderingRule ) ;
if ( ! asn1_write_ContextSimple ( data , 0 , & order ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
if ( lssc [ num ] - > reverse ) {
2009-06-10 05:45:13 +04:00
if ( ! asn1_write_BOOLEAN_context ( data , lssc [ num ] - > reverse , 1 ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_extended_dn_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-01-06 07:01:23 +03:00
{
struct ldb_extended_dn_control * ledc = talloc_get_type ( in , struct ldb_extended_dn_control ) ;
2007-11-29 10:00:04 +03:00
struct asn1_data * data ;
if ( ! in ) {
* out = data_blob ( NULL , 0 ) ;
return true ;
}
2020-04-03 02:18:03 +03:00
data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , ledc - > type ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_sd_flags_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-08-05 14:26:23 +04:00
{
struct ldb_sd_flags_control * lsdfc = talloc_get_type ( in , struct ldb_sd_flags_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-08-05 14:26:23 +04:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lsdfc - > secinfo_flags ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 14:26:23 +04:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-08-05 14:26:23 +04:00
2007-10-07 02:28:14 +04:00
return true ;
2006-08-05 14:26:23 +04:00
}
2007-10-07 02:28:14 +04:00
static bool encode_search_options_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-08-05 15:18:14 +04:00
{
struct ldb_search_options_control * lsoc = talloc_get_type ( in , struct ldb_search_options_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-08-05 15:18:14 +04:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lsoc - > search_options ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-08-05 15:18:14 +04:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-08-05 15:18:14 +04:00
2007-10-07 02:28:14 +04:00
return true ;
2006-08-05 15:18:14 +04:00
}
2007-10-07 02:28:14 +04:00
static bool encode_paged_results_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-01-06 07:01:23 +03:00
{
struct ldb_paged_control * lprc = talloc_get_type ( in , struct ldb_paged_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lprc - > size ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , lprc - > cookie , lprc - > cookie_len ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-06 07:01:23 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-01-06 07:01:23 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-01-06 07:01:23 +03:00
}
2006-01-14 04:06:16 +03:00
/* seem that this controls has 2 forms one in case it is used with
* a Search Request and another when used ina Search Response
*/
2007-10-07 02:28:14 +04:00
static bool encode_asq_control ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-01-14 04:06:16 +03:00
{
struct ldb_asq_control * lac = talloc_get_type ( in , struct ldb_asq_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-14 04:06:16 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
if ( lac - > request ) {
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , lac - > source_attribute , lac - > src_attr_len ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
} else {
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_enumerated ( data , lac - > result ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-14 04:06:16 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-01-14 04:06:16 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-01-14 04:06:16 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_dirsync_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-01-17 07:04:57 +03:00
{
struct ldb_dirsync_control * ldc = talloc_get_type ( in , struct ldb_dirsync_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-01-17 07:04:57 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , ldc - > flags ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , ldc - > max_attributes ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , ldc - > cookie , ldc - > cookie_len ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-01-17 07:04:57 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-01-17 07:04:57 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-01-17 07:04:57 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_vlv_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-02-06 04:21:17 +03:00
{
struct ldb_vlv_req_control * lvrc = talloc_get_type ( in , struct ldb_vlv_req_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-02-06 04:21:17 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lvrc - > beforeCount ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lvrc - > afterCount ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
if ( lvrc - > type = = 0 ) {
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_CONTEXT ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-22 04:31:35 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lvrc - > match . byOffset . offset ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lvrc - > match . byOffset . contentCount ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2006-02-07 01:55:34 +03:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) { /*CONTEXT*/
2007-10-07 02:28:14 +04:00
return false ;
2006-02-07 01:55:34 +03:00
}
2006-02-06 04:21:17 +03:00
} else {
2015-12-22 07:07:38 +03:00
if ( ! asn1_push_tag ( data , ASN1_CONTEXT_SIMPLE ( 1 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-22 04:31:35 +03:00
}
2006-02-06 04:21:17 +03:00
2015-12-22 07:07:38 +03:00
if ( ! asn1_write ( data , lvrc - > match . gtOrEq . value , lvrc - > match . gtOrEq . value_len ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2006-02-22 04:31:35 +03:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) { /*CONTEXT*/
2007-10-07 02:28:14 +04:00
return false ;
2006-02-22 04:31:35 +03:00
}
2006-02-06 04:21:17 +03:00
}
if ( lvrc - > ctxid_len ) {
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , lvrc - > contextId , lvrc - > ctxid_len ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-02-06 04:21:17 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-02-06 04:21:17 +03:00
}
2007-10-07 02:28:14 +04:00
static bool encode_vlv_response ( void * mem_ctx , void * in , DATA_BLOB * out )
2006-02-06 04:21:17 +03:00
{
struct ldb_vlv_resp_control * lvrc = talloc_get_type ( in , struct ldb_vlv_resp_control ) ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2006-02-06 04:21:17 +03:00
2007-10-07 02:28:14 +04:00
if ( ! data ) return false ;
2007-05-21 16:47:18 +04:00
2007-05-21 10:12:06 +04:00
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lvrc - > targetPosition ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_Integer ( data , lvrc - > contentCount ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_enumerated ( data , lvrc - > vlv_result ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
if ( lvrc - > ctxid_len ) {
2007-05-21 10:12:06 +04:00
if ( ! asn1_write_OctetString ( data , lvrc - > contextId , lvrc - > ctxid_len ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
}
2007-05-21 10:12:06 +04:00
if ( ! asn1_pop_tag ( data ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-02-06 04:21:17 +03:00
}
2016-01-02 22:10:53 +03:00
2007-05-21 10:12:06 +04:00
talloc_free ( data ) ;
2006-02-06 04:21:17 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2006-02-06 04:21:17 +03:00
}
2008-12-16 10:28:55 +03:00
static bool encode_openldap_dereference ( void * mem_ctx , void * in , DATA_BLOB * out )
{
struct dsdb_openldap_dereference_control * control = talloc_get_type ( in , struct dsdb_openldap_dereference_control ) ;
int i , j ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2008-12-16 10:28:55 +03:00
if ( ! data ) return false ;
if ( ! control ) return false ;
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
for ( i = 0 ; control - > dereference & & control - > dereference [ i ] ; i + + ) {
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
if ( ! asn1_write_OctetString ( data , control - > dereference [ i ] - > source_attribute , strlen ( control - > dereference [ i ] - > source_attribute ) ) ) {
return false ;
}
if ( ! asn1_push_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
for ( j = 0 ; control - > dereference & & control - > dereference [ i ] - > dereference_attribute [ j ] ; j + + ) {
if ( ! asn1_write_OctetString ( data , control - > dereference [ i ] - > dereference_attribute [ j ] ,
strlen ( control - > dereference [ i ] - > dereference_attribute [ j ] ) ) ) {
return false ;
}
}
2014-09-23 00:28:18 +04:00
if ( ! asn1_pop_tag ( data ) ) {
return false ;
}
if ( ! asn1_pop_tag ( data ) ) {
return false ;
}
}
if ( ! asn1_pop_tag ( data ) ) {
return false ;
2008-12-16 10:28:55 +03:00
}
2016-01-02 22:10:53 +03:00
if ( ! asn1_extract_blob ( data , mem_ctx , out ) ) {
2008-12-16 10:28:55 +03:00
return false ;
}
2016-01-02 22:10:53 +03:00
2008-12-16 10:28:55 +03:00
talloc_free ( data ) ;
return true ;
}
2009-02-24 16:45:01 +03:00
static bool decode_openldap_dereference ( void * mem_ctx , DATA_BLOB in , void * _out )
2008-12-16 10:28:55 +03:00
{
2009-02-24 18:49:26 +03:00
void * * out = ( void * * ) _out ;
2020-04-03 02:18:03 +03:00
struct asn1_data * data = asn1_init ( mem_ctx , ASN1_MAX_TREE_DEPTH ) ;
2008-12-16 10:28:55 +03:00
struct dsdb_openldap_dereference_result_control * control ;
struct dsdb_openldap_dereference_result * * r = NULL ;
int i = 0 ;
if ( ! data ) return false ;
control = talloc ( mem_ctx , struct dsdb_openldap_dereference_result_control ) ;
if ( ! control ) return false ;
if ( ! asn1_load ( data , in ) ) {
return false ;
}
control = talloc ( mem_ctx , struct dsdb_openldap_dereference_result_control ) ;
if ( ! control ) {
return false ;
}
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
while ( asn1_tag_remaining ( data ) > 0 ) {
r = talloc_realloc ( control , r , struct dsdb_openldap_dereference_result * , i + 2 ) ;
if ( ! r ) {
return false ;
}
r [ i ] = talloc_zero ( r , struct dsdb_openldap_dereference_result ) ;
if ( ! r [ i ] ) {
return false ;
}
if ( ! asn1_start_tag ( data , ASN1_SEQUENCE ( 0 ) ) ) {
return false ;
}
2014-09-23 00:28:18 +04:00
if ( ! asn1_read_OctetString_talloc ( r [ i ] , data , & r [ i ] - > source_attribute ) ) {
return false ;
}
if ( ! asn1_read_OctetString_talloc ( r [ i ] , data , & r [ i ] - > dereferenced_dn ) ) {
return false ;
}
2008-12-16 10:28:55 +03:00
if ( asn1_peek_tag ( data , ASN1_CONTEXT ( 0 ) ) ) {
if ( ! asn1_start_tag ( data , ASN1_CONTEXT ( 0 ) ) ) {
return false ;
}
2014-09-23 03:08:26 +04:00
if ( ! ldap_decode_attribs_bare ( r , data , & r [ i ] - > attributes ,
& r [ i ] - > num_attributes ) ) {
return false ;
}
2008-12-16 10:28:55 +03:00
if ( ! asn1_end_tag ( data ) ) {
return false ;
}
}
if ( ! asn1_end_tag ( data ) ) {
return false ;
}
i + + ;
r [ i ] = NULL ;
}
if ( ! asn1_end_tag ( data ) ) {
return false ;
}
control - > attributes = r ;
* out = control ;
return true ;
}
2010-08-17 03:17:17 +04:00
static bool encode_flag_request ( void * mem_ctx , void * in , DATA_BLOB * out )
2009-11-19 01:47:07 +03:00
{
if ( in ) {
return false ;
}
* out = data_blob ( NULL , 0 ) ;
return true ;
}
2010-08-17 03:17:17 +04:00
static bool decode_flag_request ( void * mem_ctx , DATA_BLOB in , void * _out )
2009-11-19 01:47:07 +03:00
{
if ( in . length ! = 0 ) {
return false ;
}
return true ;
}
2009-02-24 18:49:26 +03:00
static const struct ldap_control_handler ldap_known_controls [ ] = {
2010-10-16 22:46:20 +04:00
{ LDB_CONTROL_PAGED_RESULTS_OID , decode_paged_results_request , encode_paged_results_request } ,
{ LDB_CONTROL_SD_FLAGS_OID , decode_sd_flags_request , encode_sd_flags_request } ,
{ LDB_CONTROL_DOMAIN_SCOPE_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_SEARCH_OPTIONS_OID , decode_search_options_request , encode_search_options_request } ,
{ LDB_CONTROL_NOTIFICATION_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_TREE_DELETE_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_SHOW_DELETED_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_SHOW_RECYCLED_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_SHOW_DEACTIVATED_LINK_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_EXTENDED_DN_OID , decode_extended_dn_request , encode_extended_dn_request } ,
{ LDB_CONTROL_SERVER_SORT_OID , decode_server_sort_request , encode_server_sort_request } ,
{ LDB_CONTROL_SORT_RESP_OID , decode_server_sort_response , encode_server_sort_response } ,
{ LDB_CONTROL_ASQ_OID , decode_asq_control , encode_asq_control } ,
{ LDB_CONTROL_DIRSYNC_OID , decode_dirsync_request , encode_dirsync_request } ,
2016-01-26 11:37:13 +03:00
{ LDB_CONTROL_DIRSYNC_EX_OID , decode_dirsync_request , encode_dirsync_request } ,
2010-10-16 22:46:20 +04:00
{ LDB_CONTROL_VLV_REQ_OID , decode_vlv_request , encode_vlv_request } ,
{ LDB_CONTROL_VLV_RESP_OID , decode_vlv_response , encode_vlv_response } ,
{ LDB_CONTROL_PERMISSIVE_MODIFY_OID , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_SERVER_LAZY_COMMIT , decode_flag_request , encode_flag_request } ,
{ LDB_CONTROL_RODC_DCPROMO_OID , decode_flag_request , encode_flag_request } ,
2010-10-18 03:24:56 +04:00
{ LDB_CONTROL_RELAX_OID , decode_flag_request , encode_flag_request } ,
2010-10-16 22:46:20 +04:00
{ DSDB_OPENLDAP_DEREFERENCE_CONTROL , decode_openldap_dereference , encode_openldap_dereference } ,
2012-05-15 22:15:38 +04:00
{ LDB_CONTROL_VERIFY_NAME_OID , decode_verify_name_request , encode_verify_name_request } ,
2010-10-16 22:46:20 +04:00
2011-09-30 01:08:15 +04:00
/* the following are internal only, with a network
representation */
{ DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID , decode_flag_request , encode_flag_request } ,
/* all the ones below are internal only, and have no network
* representation */
2010-10-16 22:46:20 +04:00
{ DSDB_CONTROL_CURRENT_PARTITION_OID , NULL , NULL } ,
{ DSDB_CONTROL_REPLICATED_UPDATE_OID , NULL , NULL } ,
{ DSDB_CONTROL_DN_STORAGE_FORMAT_OID , NULL , NULL } ,
{ LDB_CONTROL_RECALCULATE_SD_OID , NULL , NULL } ,
{ LDB_CONTROL_REVEAL_INTERNALS , NULL , NULL } ,
{ LDB_CONTROL_AS_SYSTEM_OID , NULL , NULL } ,
{ DSDB_CONTROL_PASSWORD_CHANGE_STATUS_OID , NULL , NULL } ,
{ DSDB_CONTROL_PASSWORD_HASH_VALUES_OID , NULL , NULL } ,
2022-02-09 06:53:08 +03:00
{ DSDB_CONTROL_PASSWORD_CHANGE_OLD_PW_CHECKED_OID , NULL , NULL } ,
2018-02-16 17:30:13 +03:00
{ DSDB_CONTROL_PASSWORD_ACL_VALIDATION_OID , NULL , NULL } ,
2010-10-16 22:46:20 +04:00
{ DSDB_CONTROL_APPLY_LINKS , NULL , NULL } ,
2010-10-23 18:06:17 +04:00
{ LDB_CONTROL_BYPASS_OPERATIONAL_OID , NULL , NULL } ,
2010-10-16 22:46:20 +04:00
{ DSDB_CONTROL_CHANGEREPLMETADATA_OID , NULL , NULL } ,
2010-10-23 18:15:51 +04:00
{ LDB_CONTROL_PROVISION_OID , NULL , NULL } ,
2010-10-16 22:46:20 +04:00
{ DSDB_EXTENDED_REPLICATED_OBJECTS_OID , NULL , NULL } ,
{ DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID , NULL , NULL } ,
{ DSDB_EXTENDED_ALLOCATE_RID_POOL , NULL , NULL } ,
2011-09-30 01:08:15 +04:00
{ DSDB_CONTROL_NO_GLOBAL_CATALOG , NULL , NULL } ,
2012-04-06 04:20:37 +04:00
{ DSDB_EXTENDED_SCHEMA_UPGRADE_IN_PROGRESS_OID , NULL , NULL } ,
2018-04-15 22:59:43 +03:00
{ DSDB_CONTROL_TRANSACTION_IDENTIFIER_OID , NULL , NULL } ,
2021-10-25 13:10:56 +03:00
{ DSDB_CONTROL_CALCULATED_DEFAULT_SD_OID , NULL , NULL } ,
2006-01-06 07:01:23 +03:00
{ NULL , NULL , NULL }
} ;
2009-02-24 18:49:26 +03:00
const struct ldap_control_handler * samba_ldap_control_handlers ( void )
2006-01-06 07:01:23 +03:00
{
2009-02-24 18:49:26 +03:00
return ldap_known_controls ;
2007-03-13 03:59:06 +03:00
}