b4b2913cce65cb4a62fec07abcc2e25e425fd9b5
[samba.git] / source4 / librpc / rpc / dcerpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    DCERPC client side interface structures
5
6    Copyright (C) Tim Potter 2003
7    Copyright (C) Andrew Tridgell 2003-2005
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /* This is a public header file that is installed as part of Samba. 
24  * If you remove any functions or change their signature, update 
25  * the so version number. */
26
27 #ifndef __S4_DCERPC_H__
28 #define __S4_DCERPC_H__
29
30 #include "../lib/util/data_blob.h"
31 #include "librpc/gen_ndr/dcerpc.h"
32 #include "../librpc/ndr/libndr.h"
33 #include "../librpc/rpc/rpc_common.h"
34
35 struct tevent_context;
36 struct tevent_req;
37 struct dcerpc_binding_handle;
38 struct tstream_context;
39 struct ndr_interface_table;
40 struct resolve_context;
41
42 /*
43   this defines a generic security context for signed/sealed dcerpc pipes.
44 */
45 struct dcecli_connection;
46 struct gensec_settings;
47 struct cli_credentials;
48 struct dcecli_security {
49         struct dcerpc_auth *auth_info;
50         struct gensec_security *generic_state;
51
52         /* get the session key */
53         NTSTATUS (*session_key)(struct dcecli_connection *, DATA_BLOB *);
54 };
55
56 /*
57   this holds the information that is not specific to a particular rpc context_id
58 */
59 struct rpc_request;
60 struct dcecli_connection {
61         uint32_t call_id;
62         uint32_t srv_max_xmit_frag;
63         uint32_t srv_max_recv_frag;
64         uint32_t flags;
65         struct dcecli_security security_state;
66         const char *binding_string;
67         struct tevent_context *event_ctx;
68
69         struct tevent_immediate *io_trigger;
70         bool io_trigger_pending;
71
72         /** Directory in which to save ndrdump-parseable files */
73         const char *packet_log_dir;
74
75         bool dead;
76         bool free_skipped;
77
78         struct dcerpc_transport {
79                 enum dcerpc_transport_t transport;
80                 void *private_data;
81
82                 struct tstream_context *stream;
83                 /** to serialize write events */
84                 struct tevent_queue *write_queue;
85                 /** the current active read request if any */
86                 struct tevent_req *read_subreq;
87                 /** number of read requests other than the current active */
88                 uint32_t pending_reads;
89         } transport;
90
91         const char *server_name;
92
93         /* Requests that have been sent, waiting for a reply */
94         struct rpc_request *pending;
95
96         /* Sync requests waiting to be shipped */
97         struct rpc_request *request_queue;
98
99         /* the next context_id to be assigned */
100         uint32_t next_context_id;
101 };
102
103 /*
104   this encapsulates a full dcerpc client side pipe 
105 */
106 struct dcerpc_pipe {
107         struct dcerpc_binding_handle *binding_handle;
108
109         uint32_t context_id;
110
111         uint32_t assoc_group_id;
112
113         struct ndr_syntax_id syntax;
114         struct ndr_syntax_id transfer_syntax;
115
116         struct dcecli_connection *conn;
117         struct dcerpc_binding *binding;
118
119         /** the last fault code from a DCERPC fault */
120         uint32_t last_fault_code;
121
122         /** timeout for individual rpc requests, in seconds */
123         uint32_t request_timeout;
124
125         /*
126          * Set for the timeout in dcerpc_pipe_connect_b_send(), to
127          * allow the timeout not to destory the stack during a nested
128          * event loop caused by gensec_update()
129          */
130         bool inhibit_timeout_processing;
131         bool timed_out;
132 };
133
134 /* default timeout for all rpc requests, in seconds */
135 #define DCERPC_REQUEST_TIMEOUT 60
136
137 struct epm_tower;
138 struct epm_floor;
139
140 struct smbcli_tree;
141 struct smb2_tree;
142 struct smbXcli_conn;
143 struct smbXcli_session;
144 struct smbXcli_tcon;
145 struct socket_address;
146
147 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
148                              struct dcerpc_pipe **pp, 
149                              const char *binding,
150                              const struct ndr_interface_table *table,
151                              struct cli_credentials *credentials,
152                              struct tevent_context *ev,
153                              struct loadparm_context *lp_ctx);
154 const char *dcerpc_server_name(struct dcerpc_pipe *p);
155 struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev);
156 NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p,
157                               struct smbcli_tree *tree,
158                               const char *pipe_name);
159 NTSTATUS dcerpc_pipe_open_smb2(struct dcerpc_pipe *p,
160                                struct smb2_tree *tree,
161                                const char *pipe_name);
162 NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
163                                const struct ndr_interface_table *table);
164 NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
165                                   DATA_BLOB *session_key);
166 struct composite_context;
167 NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c,
168                                           struct dcerpc_pipe **p2);
169
170 struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
171                                                      struct dcerpc_binding *binding,
172                                                      const struct ndr_interface_table *table,
173                                                      struct cli_credentials *credentials,
174                                                      struct tevent_context *ev,
175                                                      struct loadparm_context *lp_ctx);
176
177 NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
178                                     struct dcerpc_pipe **p);
179
180 NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
181                                struct dcerpc_pipe **pp,
182                                struct dcerpc_binding *binding,
183                                const struct ndr_interface_table *table,
184                                struct cli_credentials *credentials,
185                                struct tevent_context *ev,
186                                struct loadparm_context *lp_ctx);
187
188 NTSTATUS dcerpc_pipe_auth(TALLOC_CTX *mem_ctx,
189                           struct dcerpc_pipe **p, 
190                           struct dcerpc_binding *binding,
191                           const struct ndr_interface_table *table,
192                           struct cli_credentials *credentials,
193                           struct loadparm_context *lp_ctx);
194 NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p,
195                                      struct dcerpc_pipe **p2,
196                                      struct dcerpc_binding *b);
197 NTSTATUS dcerpc_bind_auth_schannel(TALLOC_CTX *tmp_ctx, 
198                                    struct dcerpc_pipe *p,
199                                    const struct ndr_interface_table *table,
200                                    struct cli_credentials *credentials,
201                                    struct loadparm_context *lp_ctx,
202                                    uint8_t auth_level);
203 NTSTATUS dcerpc_init(void);
204 struct composite_context *dcerpc_secondary_smb_send(struct dcecli_connection *c1,
205                                                     struct dcecli_connection *c2,
206                                                     const char *pipe_name);
207 NTSTATUS dcerpc_secondary_smb_recv(struct composite_context *c);
208 NTSTATUS dcerpc_secondary_context(struct dcerpc_pipe *p, 
209                                   struct dcerpc_pipe **pp2,
210                                   const struct ndr_interface_table *table);
211 NTSTATUS dcerpc_alter_context(struct dcerpc_pipe *p, 
212                               TALLOC_CTX *mem_ctx,
213                               const struct ndr_syntax_id *syntax,
214                               const struct ndr_syntax_id *transfer_syntax);
215
216 NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
217                           const struct ndr_interface_table *table,
218                           struct cli_credentials *credentials,
219                           struct gensec_settings *gensec_settings,
220                           uint8_t auth_type, uint8_t auth_level,
221                           const char *service);
222 struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
223                                                    const char *binding,
224                                                    const struct ndr_interface_table *table,
225                                                    struct cli_credentials *credentials,
226                                                    struct tevent_context *ev, struct loadparm_context *lp_ctx);
227 NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
228                                   TALLOC_CTX *mem_ctx,
229                                   struct dcerpc_pipe **pp);
230
231 NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *binding,
232                                 const struct ndr_interface_table *table, struct tevent_context *ev,
233                                 struct loadparm_context *lp_ctx);
234 struct composite_context* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe *p,
235                                                                 struct dcerpc_binding *binding,
236                                                                 const struct ndr_interface_table *table,
237                                                                 struct cli_credentials *credentials,
238                                                                 struct loadparm_context *lp_ctx);
239 NTSTATUS dcerpc_secondary_auth_connection_recv(struct composite_context *c, 
240                                                TALLOC_CTX *mem_ctx,
241                                                struct dcerpc_pipe **p);
242
243 struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
244                                                            struct dcerpc_binding *b);
245 void dcerpc_log_packet(const char *lockdir, 
246                        const struct ndr_interface_table *ndr,
247                        uint32_t opnum, uint32_t flags,
248                        const DATA_BLOB *pkt);
249
250 #endif /* __S4_DCERPC_H__ */