r18717: remove old defines in preference of the flags in librpc/gen_ndr/srvsvc.h
[tprouty/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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef _RPC_CLIENT_H
22 #define _RPC_CLIENT_H
23
24 /* autogenerated client stubs */
25
26 #include "librpc/gen_ndr/cli_echo.h"
27 #include "librpc/gen_ndr/cli_unixinfo.h"
28 #include "librpc/gen_ndr/cli_dfs.h"
29 #include "librpc/gen_ndr/cli_lsa.h"
30 #include "librpc/gen_ndr/cli_winreg.h"
31 #include "librpc/gen_ndr/cli_wkssvc.h"
32
33 /* macro to expand cookie-cutter code in cli_xxx() using rpc_api_pipe_req() */
34
35 #define CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
36                              q_ps, r_ps, q_io_fn, r_io_fn, default_error, copy_sess_key ) \
37 {\
38         SMB_ASSERT(pcli->pipe_idx == p_idx); \
39         if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \
40                 return NT_STATUS_NO_MEMORY;\
41         }\
42         if (!prs_init( &r_ps, 0, ctx, UNMARSHALL )) {\
43                 prs_mem_free( &q_ps );\
44                 return NT_STATUS_NO_MEMORY;\
45         }\
46         if ( copy_sess_key) prs_set_session_key(&q_ps, (const char *)pcli->dc->sess_key);\
47         if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
48                 NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \
49                 if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\
50                         prs_mem_free( &q_ps );\
51                         prs_mem_free( &r_ps );\
52                         return _smb_pipe_stat_;\
53                 }\
54                 if ( copy_sess_key ) prs_set_session_key(&r_ps, (const char *)pcli->dc->sess_key);\
55                 if (!r_io_fn("", &r_out, &r_ps, 0)) {\
56                         prs_mem_free( &q_ps );\
57                         prs_mem_free( &r_ps );\
58                         return default_error;\
59                 }\
60         } else {\
61                 prs_mem_free( &q_ps );\
62                 prs_mem_free( &r_ps );\
63                 return default_error;\
64         }\
65         prs_mem_free( &q_ps );\
66         prs_mem_free( &r_ps );\
67 }
68
69 #define CLI_DO_RPC_COPY_SESS_KEY( pcli, ctx, p_idx, opnum, q_in, r_out, \
70                                   q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
71 {\
72         CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
73                              q_ps, r_ps, q_io_fn, r_io_fn, default_error, True ); \
74 }
75
76 #define CLI_DO_RPC( pcli, ctx, p_idx, opnum, q_in, r_out, \
77                     q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
78 {\
79         CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \
80                              q_ps, r_ps, q_io_fn, r_io_fn, default_error, False ); \
81 }
82
83
84 /* Arrrgg. Same but with WERRORS. Needed for registry code. */
85
86 #define CLI_DO_RPC_WERR( pcli, ctx, p_idx, opnum, q_in, r_out, \
87                              q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \
88 {\
89         SMB_ASSERT(pcli->pipe_idx == p_idx); \
90         if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \
91                 return WERR_NOMEM;\
92         }\
93         if (!prs_init( &r_ps, 0, ctx, UNMARSHALL )) {\
94                 prs_mem_free( &q_ps );\
95                 return WERR_NOMEM;\
96         }\
97         if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
98                 NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \
99                 if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\
100                         prs_mem_free( &q_ps );\
101                         prs_mem_free( &r_ps );\
102                         return ntstatus_to_werror(_smb_pipe_stat_);\
103                 }\
104                 if (!r_io_fn("", &r_out, &r_ps, 0)) {\
105                         prs_mem_free( &q_ps );\
106                         prs_mem_free( &r_ps );\
107                         return default_error;\
108                 }\
109         } else {\
110                 prs_mem_free( &q_ps );\
111                 prs_mem_free( &r_ps );\
112                 return default_error;\
113         }\
114         prs_mem_free( &q_ps );\
115         prs_mem_free( &r_ps );\
116 }
117
118 #endif /* _RPC_CLIENT_H */