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