2006-07-11 18:01:26 +00:00
/*
Unix SMB / CIFS implementation .
libndr interface
Copyright ( C ) Jelmer Vernooij 2006
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-09 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2006-07-11 18:01:26 +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 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-07-11 18:01:26 +00:00
*/
# include "includes.h"
2007-08-21 12:20:33 +00:00
NTSTATUS cli_do_rpc_ndr ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int p_idx ,
const struct ndr_interface_table * table ,
uint32 opnum , void * r )
2006-07-11 18:01:26 +00:00
{
prs_struct q_ps , r_ps ;
2007-08-21 12:20:33 +00:00
const struct ndr_interface_call * call ;
2006-07-11 18:01:26 +00:00
struct ndr_pull * pull ;
DATA_BLOB blob ;
struct ndr_push * push ;
NTSTATUS status ;
2007-11-09 14:39:45 +01:00
enum ndr_err_code ndr_err ;
2006-07-11 18:01:26 +00:00
SMB_ASSERT ( cli - > pipe_idx = = p_idx ) ;
2007-08-21 12:20:33 +00:00
SMB_ASSERT ( table - > num_calls > opnum ) ;
call = & table - > calls [ opnum ] ;
2006-07-11 18:01:26 +00:00
push = ndr_push_init_ctx ( mem_ctx ) ;
if ( ! push ) {
return NT_STATUS_NO_MEMORY ;
}
2007-11-09 14:39:45 +01:00
ndr_err = call - > ndr_push ( push , NDR_IN , r ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
2006-07-11 18:01:26 +00:00
}
blob = ndr_push_blob ( push ) ;
if ( ! prs_init_data_blob ( & q_ps , & blob , mem_ctx ) ) {
return NT_STATUS_NO_MEMORY ;
}
talloc_free ( push ) ;
if ( ! prs_init ( & r_ps , 0 , mem_ctx , UNMARSHALL ) ) {
prs_mem_free ( & q_ps ) ;
return NT_STATUS_NO_MEMORY ;
}
status = rpc_api_pipe_req ( cli , opnum , & q_ps , & r_ps ) ;
prs_mem_free ( & q_ps ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
prs_mem_free ( & r_ps ) ;
return status ;
}
if ( ! prs_data_blob ( & r_ps , & blob , mem_ctx ) ) {
prs_mem_free ( & r_ps ) ;
return NT_STATUS_NO_MEMORY ;
}
prs_mem_free ( & r_ps ) ;
pull = ndr_pull_init_blob ( & blob , mem_ctx ) ;
if ( pull = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2006-09-11 20:00:00 +00:00
/* have the ndr parser alloc memory for us */
pull - > flags | = LIBNDR_FLAG_REF_ALLOC ;
2007-11-09 14:39:45 +01:00
ndr_err = call - > ndr_pull ( pull , NDR_OUT , r ) ;
2006-07-11 18:01:26 +00:00
talloc_free ( pull ) ;
2007-11-09 14:39:45 +01:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
2006-07-11 18:01:26 +00:00
}
return NT_STATUS_OK ;
}