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