95aeffdcb9da94e56f953feb8352f61fa37bd1f8
[samba.git] / source / include / rpc_client.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB parameters and setup
4    Copyright (C) Gerald (Jerry) Carter         2005.
5    
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 3 of the License, or
9    (at your option) any later version.
10    
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.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _RPC_CLIENT_H
21 #define _RPC_CLIENT_H
22
23 /* autogenerated client stubs */
24
25 #include "librpc/gen_ndr/cli_echo.h"
26 #include "librpc/gen_ndr/cli_unixinfo.h"
27 #include "librpc/gen_ndr/cli_epmapper.h"
28 #include "librpc/gen_ndr/cli_dfs.h"
29 #include "librpc/gen_ndr/cli_lsa.h"
30 #include "librpc/gen_ndr/cli_srvsvc.h"
31 #include "librpc/gen_ndr/cli_svcctl.h"
32 #include "librpc/gen_ndr/cli_winreg.h"
33 #include "librpc/gen_ndr/cli_initshutdown.h"
34 #include "librpc/gen_ndr/cli_wkssvc.h"
35
36 /* macro to expand cookie-cutter code in cli_xxx() using rpc_api_pipe_req() */
37
38 #define CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
39                              q_ps, r_ps, q_io_fn, r_io_fn, default_error, copy_sess_key ) \
40 {\
41         SMB_ASSERT(pcli->pipe_idx == p_idx); \
42         if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \
43                 return NT_STATUS_NO_MEMORY;\
44         }\
45         if (!prs_init( &r_ps, 0, ctx, UNMARSHALL )) {\
46                 prs_mem_free( &q_ps );\
47                 return NT_STATUS_NO_MEMORY;\
48         }\
49         if ( copy_sess_key) prs_set_session_key(&q_ps, (const char *)pcli->dc->sess_key);\
50         if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
51                 NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \
52                 if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\
53                         prs_mem_free( &q_ps );\
54                         prs_mem_free( &r_ps );\
55                         return _smb_pipe_stat_;\
56                 }\
57                 if ( copy_sess_key ) prs_set_session_key(&r_ps, (const char *)pcli->dc->sess_key);\
58                 if (!r_io_fn("", &r_out, &r_ps, 0)) {\
59                         prs_mem_free( &q_ps );\
60                         prs_mem_free( &r_ps );\
61                         return default_error;\
62                 }\
63         } else {\
64                 prs_mem_free( &q_ps );\
65                 prs_mem_free( &r_ps );\
66                 return default_error;\
67         }\
68         prs_mem_free( &q_ps );\
69         prs_mem_free( &r_ps );\
70 }
71
72 #define CLI_DO_RPC_COPY_SESS_KEY( pcli, ctx, p_idx, opnum, q_in, r_out, \
73                                   q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
74 {\
75         CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
76                              q_ps, r_ps, q_io_fn, r_io_fn, default_error, True ); \
77 }
78
79 #define CLI_DO_RPC( pcli, ctx, p_idx, opnum, q_in, r_out, \
80                     q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
81 {\
82         CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
83                              q_ps, r_ps, q_io_fn, r_io_fn, default_error, False ); \
84 }
85
86
87 /* Arrrgg. Same but with WERRORS. Needed for registry code. */
88
89 #define CLI_DO_RPC_WERR( pcli, ctx, p_idx, opnum, q_in, r_out, \
90                              q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
91 {\
92         SMB_ASSERT(pcli->pipe_idx == p_idx); \
93         if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \
94                 return WERR_NOMEM;\
95         }\
96         if (!prs_init( &r_ps, 0, ctx, UNMARSHALL )) {\
97                 prs_mem_free( &q_ps );\
98                 return WERR_NOMEM;\
99         }\
100         if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
101                 NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \
102                 if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\
103                         prs_mem_free( &q_ps );\
104                         prs_mem_free( &r_ps );\
105                         return ntstatus_to_werror(_smb_pipe_stat_);\
106                 }\
107                 if (!r_io_fn("", &r_out, &r_ps, 0)) {\
108                         prs_mem_free( &q_ps );\
109                         prs_mem_free( &r_ps );\
110                         return default_error;\
111                 }\
112         } else {\
113                 prs_mem_free( &q_ps );\
114                 prs_mem_free( &r_ps );\
115                 return default_error;\
116         }\
117         prs_mem_free( &q_ps );\
118         prs_mem_free( &r_ps );\
119 }
120
121 #endif /* _RPC_CLIENT_H */