[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.
[Samba.git] / source / include / rpc_client.h
blobb05924e657dc26ab7122a4539ff50554010b8281
1 /*
2 Unix SMB/CIFS implementation.
3 SMB parameters and setup
4 Copyright (C) Gerald (Jerry) Carter 2005.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef _RPC_CLIENT_H
22 #define _RPC_CLIENT_H
24 /* autogenerated client stubs */
26 #include "librpc/gen_ndr/cli_wkssvc.h"
28 /* macro to expand cookie-cutter code in cli_xxx() using rpc_api_pipe_req() */
30 #define CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
31 q_ps, r_ps, q_io_fn, r_io_fn, default_error, copy_sess_key ) \
33 SMB_ASSERT(pcli->pipe_idx == p_idx); \
34 if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \
35 return NT_STATUS_NO_MEMORY;\
37 if (!prs_init( &r_ps, 0, ctx, UNMARSHALL )) {\
38 prs_mem_free( &q_ps );\
39 return NT_STATUS_NO_MEMORY;\
41 if ( copy_sess_key) prs_set_session_key(&q_ps, (const char *)pcli->dc->sess_key);\
42 if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
43 NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \
44 if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\
45 prs_mem_free( &q_ps );\
46 prs_mem_free( &r_ps );\
47 return _smb_pipe_stat_;\
49 if ( copy_sess_key ) prs_set_session_key(&r_ps, (const char *)pcli->dc->sess_key);\
50 if (!r_io_fn("", &r_out, &r_ps, 0)) {\
51 prs_mem_free( &q_ps );\
52 prs_mem_free( &r_ps );\
53 return default_error;\
55 } else {\
56 prs_mem_free( &q_ps );\
57 prs_mem_free( &r_ps );\
58 return default_error;\
60 prs_mem_free( &q_ps );\
61 prs_mem_free( &r_ps );\
64 #define CLI_DO_RPC_COPY_SESS_KEY( pcli, ctx, p_idx, opnum, q_in, r_out, \
65 q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
67 CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
68 q_ps, r_ps, q_io_fn, r_io_fn, default_error, True ); \
71 #define CLI_DO_RPC( pcli, ctx, p_idx, opnum, q_in, r_out, \
72 q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
74 CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
75 q_ps, r_ps, q_io_fn, r_io_fn, default_error, False ); \
79 /* Arrrgg. Same but with WERRORS. Needed for registry code. */
81 #define CLI_DO_RPC_WERR( pcli, ctx, p_idx, opnum, q_in, r_out, \
82 q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
84 SMB_ASSERT(pcli->pipe_idx == p_idx); \
85 if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \
86 return WERR_NOMEM;\
88 if (!prs_init( &r_ps, 0, ctx, UNMARSHALL )) {\
89 prs_mem_free( &q_ps );\
90 return WERR_NOMEM;\
92 if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
93 NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \
94 if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\
95 prs_mem_free( &q_ps );\
96 prs_mem_free( &r_ps );\
97 return ntstatus_to_werror(_smb_pipe_stat_);\
99 if (!r_io_fn("", &r_out, &r_ps, 0)) {\
100 prs_mem_free( &q_ps );\
101 prs_mem_free( &r_ps );\
102 return default_error;\
104 } else {\
105 prs_mem_free( &q_ps );\
106 prs_mem_free( &r_ps );\
107 return default_error;\
109 prs_mem_free( &q_ps );\
110 prs_mem_free( &r_ps );\
113 #endif /* _RPC_CLIENT_H */