2005-05-13 06:07:53 +00:00
/*
Unix SMB / CIFS mplementation .
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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-05-13 06:07:53 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-05-13 06:07:53 +00:00
*/
# include "includes.h"
2010-05-06 10:41:43 +02:00
# if _SAMBA_BUILD_ == 3
# include "lib/ldb_compat.h"
# else
2009-02-24 12:50:43 +01:00
# include "lib/ldb/include/ldb.h"
2010-05-06 10:41:43 +02:00
# endif
2006-01-06 04:01:23 +00:00
# include "librpc/gen_ndr/ndr_security.h"
2005-07-28 00:27:28 +00:00
# include "librpc/gen_ndr/ndr_misc.h"
2008-10-20 18:59:51 +02:00
# include "libcli/ldap/ldap_ndr.h"
2005-05-13 06:07:53 +00:00
/*
encode a NDR uint32 as a ldap filter element
*/
2005-08-11 13:12:45 +00:00
char * ldap_encode_ndr_uint32 ( TALLOC_CTX * mem_ctx , uint32_t value )
2005-05-13 06:07:53 +00:00
{
uint8_t buf [ 4 ] ;
2005-06-13 06:06:29 +00:00
struct ldb_val val ;
2005-05-13 06:07:53 +00:00
SIVAL ( buf , 0 , value ) ;
2005-06-13 06:06:29 +00:00
val . data = buf ;
val . length = 4 ;
return ldb_binary_encode ( mem_ctx , val ) ;
2005-05-13 06:07:53 +00:00
}
/*
encode a NDR dom_sid as a ldap filter element
*/
2005-08-11 13:12:45 +00:00
char * ldap_encode_ndr_dom_sid ( TALLOC_CTX * mem_ctx , const struct dom_sid * sid )
2005-05-13 06:07:53 +00:00
{
DATA_BLOB blob ;
2007-11-09 19:24:51 +01:00
enum ndr_err_code ndr_err ;
2005-08-11 13:12:45 +00:00
char * ret ;
2010-05-09 17:20:01 +02:00
ndr_err = ndr_push_struct_blob ( & blob , mem_ctx , sid ,
2007-11-09 19:24:51 +01:00
( ndr_push_flags_fn_t ) ndr_push_dom_sid ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
2005-05-13 06:07:53 +00:00
return NULL ;
}
2005-06-15 01:12:31 +00:00
ret = ldb_binary_encode ( mem_ctx , blob ) ;
2005-05-13 06:07:53 +00:00
data_blob_free ( & blob ) ;
return ret ;
}
/*
encode a NDR GUID as a ldap filter element
*/
2010-09-17 11:15:28 +10:00
char * ldap_encode_ndr_GUID ( TALLOC_CTX * mem_ctx , const struct GUID * guid )
2005-05-13 06:07:53 +00:00
{
DATA_BLOB blob ;
2009-12-10 14:31:13 +11:00
NTSTATUS status ;
2005-08-11 13:12:45 +00:00
char * ret ;
2009-12-10 14:31:13 +11:00
status = GUID_to_ndr_blob ( guid , mem_ctx , & blob ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-05-13 06:07:53 +00:00
return NULL ;
}
2005-06-15 01:12:31 +00:00
ret = ldb_binary_encode ( mem_ctx , blob ) ;
2005-05-13 06:07:53 +00:00
data_blob_free ( & blob ) ;
return ret ;
}
2005-05-16 11:17:57 +00:00
/*
decode a NDR GUID from a ldap filter element
*/
2005-06-13 06:06:29 +00:00
NTSTATUS ldap_decode_ndr_GUID ( TALLOC_CTX * mem_ctx , struct ldb_val val , struct GUID * guid )
2005-05-16 11:17:57 +00:00
{
DATA_BLOB blob ;
2007-11-09 19:24:51 +01:00
enum ndr_err_code ndr_err ;
2005-05-16 11:17:57 +00:00
blob . data = val . data ;
blob . length = val . length ;
2010-05-09 17:20:01 +02:00
ndr_err = ndr_pull_struct_blob ( & blob , mem_ctx , guid ,
2007-11-09 19:24:51 +01:00
( ndr_pull_flags_fn_t ) ndr_pull_GUID ) ;
2005-05-16 11:17:57 +00:00
talloc_free ( val . data ) ;
2007-11-09 19:24:51 +01:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
}
return NT_STATUS_OK ;
2005-05-16 11:17:57 +00:00
}