2005-05-13 10:07:53 +04:00
/*
2016-04-20 08:10:41 +03:00
Unix SMB / CIFS implementation .
2005-05-13 10:07:53 +04:00
wrap / unwrap NDR encoded elements for ldap calls
Copyright ( C ) Andrew Tridgell 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
2005-05-13 10:07:53 +04: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/>.
2005-05-13 10:07:53 +04:00
*/
# include "includes.h"
2011-02-10 06:12:51 +03:00
# include <ldb.h>
2006-01-06 07:01:23 +03:00
# include "librpc/gen_ndr/ndr_security.h"
2005-07-28 04:27:28 +04:00
# include "librpc/gen_ndr/ndr_misc.h"
2008-10-20 20:59:51 +04:00
# include "libcli/ldap/ldap_ndr.h"
2005-05-13 10:07:53 +04:00
/*
encode a NDR uint32 as a ldap filter element
*/
2005-08-11 17:12:45 +04:00
char * ldap_encode_ndr_uint32 ( TALLOC_CTX * mem_ctx , uint32_t value )
2005-05-13 10:07:53 +04:00
{
uint8_t buf [ 4 ] ;
2005-06-13 10:06:29 +04:00
struct ldb_val val ;
2005-05-13 10:07:53 +04:00
SIVAL ( buf , 0 , value ) ;
2005-06-13 10:06:29 +04:00
val . data = buf ;
val . length = 4 ;
return ldb_binary_encode ( mem_ctx , val ) ;
2005-05-13 10:07:53 +04:00
}
/*
encode a NDR dom_sid as a ldap filter element
*/
2005-08-11 17:12:45 +04:00
char * ldap_encode_ndr_dom_sid ( TALLOC_CTX * mem_ctx , const struct dom_sid * sid )
2005-05-13 10:07:53 +04:00
{
DATA_BLOB blob ;
2007-11-09 21:24:51 +03:00
enum ndr_err_code ndr_err ;
2005-08-11 17:12:45 +04:00
char * ret ;
2010-05-09 19:20:01 +04:00
ndr_err = ndr_push_struct_blob ( & blob , mem_ctx , sid ,
2007-11-09 21:24:51 +03:00
( ndr_push_flags_fn_t ) ndr_push_dom_sid ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
2005-05-13 10:07:53 +04:00
return NULL ;
}
2005-06-15 05:12:31 +04:00
ret = ldb_binary_encode ( mem_ctx , blob ) ;
2005-05-13 10:07:53 +04:00
data_blob_free ( & blob ) ;
return ret ;
}
/*
encode a NDR GUID as a ldap filter element
*/
2010-09-17 05:15:28 +04:00
char * ldap_encode_ndr_GUID ( TALLOC_CTX * mem_ctx , const struct GUID * guid )
2005-05-13 10:07:53 +04:00
{
2020-09-29 11:13:20 +03:00
struct GUID_ndr_buf buf = { . buf = { 0 } , } ;
DATA_BLOB blob = { . data = buf . buf , . length = sizeof ( buf . buf ) , } ;
2009-12-10 06:31:13 +03:00
NTSTATUS status ;
2005-08-11 17:12:45 +04:00
char * ret ;
2020-09-29 11:13:20 +03:00
status = GUID_to_ndr_buf ( guid , & buf ) ;
2009-12-10 06:31:13 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-05-13 10:07:53 +04:00
return NULL ;
}
2005-06-15 05:12:31 +04:00
ret = ldb_binary_encode ( mem_ctx , blob ) ;
2005-05-13 10:07:53 +04:00
return ret ;
}
2005-05-16 15:17:57 +04:00
/*
decode a NDR GUID from a ldap filter element
*/
2005-06-13 10:06:29 +04:00
NTSTATUS ldap_decode_ndr_GUID ( TALLOC_CTX * mem_ctx , struct ldb_val val , struct GUID * guid )
2005-05-16 15:17:57 +04:00
{
DATA_BLOB blob ;
2007-11-09 21:24:51 +03:00
enum ndr_err_code ndr_err ;
2005-05-16 15:17:57 +04:00
blob . data = val . data ;
blob . length = val . length ;
2010-05-09 19:20:01 +04:00
ndr_err = ndr_pull_struct_blob ( & blob , mem_ctx , guid ,
2007-11-09 21:24:51 +03:00
( ndr_pull_flags_fn_t ) ndr_pull_GUID ) ;
2005-05-16 15:17:57 +04:00
talloc_free ( val . data ) ;
2007-11-09 21:24:51 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
}
return NT_STATUS_OK ;
2005-05-16 15:17:57 +04:00
}