r14714: On DCE/RPC, we need the name of the remote server used on the socket,
[ira/wip.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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef __DCERPC_H__
25 #define __DCERPC_H__
26
27 #include "core.h"
28 #include "librpc/gen_ndr/dcerpc.h"
29 #include "librpc/ndr/libndr.h"
30
31 enum dcerpc_transport_t {
32         NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, NCACN_VNS_SPP, 
33         NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, NCADG_UNIX_DGRAM,
34         NCACN_HTTP, NCADG_IPX, NCACN_SPX };
35
36 /*
37   this defines a generic security context for signed/sealed dcerpc pipes.
38 */
39 struct dcerpc_connection;
40 struct dcerpc_security {
41         struct dcerpc_auth *auth_info;
42         struct gensec_security *generic_state;
43
44         /* get the session key */
45         NTSTATUS (*session_key)(struct dcerpc_connection *, DATA_BLOB *);
46 };
47
48 /*
49   this holds the information that is not specific to a particular rpc context_id
50 */
51 struct dcerpc_connection {
52         uint32_t call_id;
53         uint32_t srv_max_xmit_frag;
54         uint32_t srv_max_recv_frag;
55         uint32_t flags;
56         struct dcerpc_security security_state;
57         const char *binding_string;
58         struct event_context *event_ctx;
59
60         struct dcerpc_transport {
61                 enum dcerpc_transport_t transport;
62                 void *private;
63
64                 NTSTATUS (*shutdown_pipe)(struct dcerpc_connection *);
65
66                 const char *(*peer_name)(struct dcerpc_connection *);
67
68                 const char *(*target_hostname)(struct dcerpc_connection *);
69
70                 /* send a request to the server */
71                 NTSTATUS (*send_request)(struct dcerpc_connection *, DATA_BLOB *, BOOL trigger_read);
72
73                 /* send a read request to the server */
74                 NTSTATUS (*send_read)(struct dcerpc_connection *);
75
76                 /* a callback to the dcerpc code when a full fragment
77                    has been received */
78                 void (*recv_data)(struct dcerpc_connection *, DATA_BLOB *, NTSTATUS status);
79         } transport;
80
81         /* Requests that have been sent, waiting for a reply */
82         struct rpc_request *pending;
83
84         /* Sync requests waiting to be shipped */
85         struct rpc_request *request_queue;
86
87         /* private pointer for pending binds */
88         void *bind_private;
89
90         /* private pointer for pending alter context requests */
91         void *alter_private;
92
93         /* the next context_id to be assigned */
94         uint32_t next_context_id;
95 };
96
97 /*
98   this encapsulates a full dcerpc client side pipe 
99 */
100 struct dcerpc_pipe {
101         uint32_t context_id;
102
103         struct dcerpc_syntax_id syntax;
104         struct dcerpc_syntax_id transfer_syntax;
105
106         struct dcerpc_connection *conn;
107         struct dcerpc_binding *binding;
108
109         /* the last fault code from a DCERPC fault */
110         uint32_t last_fault_code;
111
112         /* timeout for individual rpc requests, in seconds */
113         uint32_t request_timeout;
114 };
115
116 /* default timeout for all rpc requests, in seconds */
117 #define DCERPC_REQUEST_TIMEOUT 60
118
119
120 /* dcerpc pipe flags */
121 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
122 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
123 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
124
125 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
126 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
127 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
128
129 #define DCERPC_CONNECT                 (1<<4)
130 #define DCERPC_SIGN                    (1<<5)
131 #define DCERPC_SEAL                    (1<<6)
132
133 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
134 #define DCERPC_PULL_BIGENDIAN          (1<<8)
135
136 #define DCERPC_SCHANNEL                (1<<9)
137
138 /* use a 128 bit session key */
139 #define DCERPC_SCHANNEL_128            (1<<12)
140
141 /* check incoming pad bytes */
142 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
143
144 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
145 #define DCERPC_NDR_REF_ALLOC           (1<<14)
146
147 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5)
148
149 /* enable spnego auth */
150 #define DCERPC_AUTH_SPNEGO             (1<<15)
151
152 /* enable krb5 auth */
153 #define DCERPC_AUTH_KRB5               (1<<16)
154
155 #define DCERPC_SMB2                    (1<<17)
156
157 /*
158   this is used to find pointers to calls
159 */
160 struct dcerpc_interface_call {
161         const char *name;
162         size_t struct_size;
163         ndr_push_flags_fn_t ndr_push;
164         ndr_pull_flags_fn_t ndr_pull;
165         ndr_print_function_t ndr_print;
166         BOOL async;
167 };
168
169 struct dcerpc_endpoint_list {
170         uint32_t count;
171         const char * const *names;
172 };
173
174 struct dcerpc_authservice_list {
175         uint32_t count;
176         const char * const *names;
177 };
178
179 struct dcerpc_interface_table {
180         const char *name;
181         struct GUID uuid;
182         uint32_t if_version;
183         const char *helpstring;
184         uint32_t num_calls;
185         const struct dcerpc_interface_call *calls;
186         const struct dcerpc_endpoint_list *endpoints;
187         const struct dcerpc_authservice_list *authservices;
188 };
189
190 struct dcerpc_interface_list {
191         struct dcerpc_interface_list *prev, *next;
192         const struct dcerpc_interface_table *table;
193 };
194
195 /* this describes a binding to a particular transport/pipe */
196 struct dcerpc_binding {
197         enum dcerpc_transport_t transport;
198         struct GUID object;
199         uint16_t object_version;
200         const char *host;
201         const char *endpoint;
202         const char **options;
203         uint32_t flags;
204 };
205
206
207 struct dcerpc_pipe_connect {
208         struct dcerpc_pipe *pipe;
209         struct dcerpc_binding *binding;
210         const char *pipe_name;
211         const struct dcerpc_interface_table *interface;
212         struct cli_credentials *creds;
213 };
214
215
216 enum rpc_request_state {
217         RPC_REQUEST_PENDING,
218         RPC_REQUEST_DONE
219 };
220
221 /*
222   handle for an async dcerpc request
223 */
224 struct rpc_request {
225         struct rpc_request *next, *prev;
226         struct dcerpc_pipe *p;
227         NTSTATUS status;
228         uint32_t call_id;
229         enum rpc_request_state state;
230         DATA_BLOB payload;
231         uint32_t flags;
232         uint32_t fault_code;
233
234         const struct GUID *object;
235         uint16_t opnum;
236         DATA_BLOB request_data;
237         BOOL async_call;
238
239         /* use by the ndr level async recv call */
240         struct {
241                 const struct dcerpc_interface_table *table;
242                 uint32_t opnum;
243                 void *struct_ptr;
244                 TALLOC_CTX *mem_ctx;
245         } ndr;
246
247         struct {
248                 void (*callback)(struct rpc_request *);
249                 void *private;
250         } async;
251 };
252
253 struct epm_tower;
254 struct epm_floor;
255
256 struct smbcli_tree;
257 struct smb2_tree;
258 struct socket_address;
259
260 #include "librpc/rpc/dcerpc_proto.h"
261
262 #endif /* __DCERPC_H__ */