r4360: destroy the gensec context
[samba.git] / source4 / librpc / rpc / dcerpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3    DCERPC interface structures
4
5    Copyright (C) Tim Potter 2003
6    Copyright (C) Andrew Tridgell 2003
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 enum dcerpc_transport_t {
24         NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, NCACN_VNS_SPP, 
25         NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, NCADG_UNIX_DGRAM,
26         NCACN_HTTP, NCADG_IPX, NCACN_SPX };
27
28 /*
29   this defines a generic security context for signed/sealed dcerpc pipes.
30 */
31 struct dcerpc_pipe;
32 struct dcerpc_security {
33         struct dcerpc_auth *auth_info;
34         struct gensec_security *generic_state;
35
36         /* get the session key */
37         NTSTATUS (*session_key)(struct dcerpc_pipe *, DATA_BLOB *);
38 };
39
40 struct dcerpc_pipe {
41         int reference_count;
42         uint32_t call_id;
43         uint32_t srv_max_xmit_frag;
44         uint32_t srv_max_recv_frag;
45         uint_t flags;
46         struct dcerpc_security security_state;
47         const char *binding_string;
48
49         struct dcerpc_syntax_id syntax;
50         struct dcerpc_syntax_id transfer_syntax;
51
52         struct dcerpc_transport {
53                 enum dcerpc_transport_t transport;
54                 void *private;
55
56                 NTSTATUS (*shutdown_pipe)(struct dcerpc_pipe *);
57
58                 const char *(*peer_name)(struct dcerpc_pipe *);
59
60                 /* send a request to the server */
61                 NTSTATUS (*send_request)(struct dcerpc_pipe *, DATA_BLOB *, BOOL trigger_read);
62
63                 /* send a read request to the server */
64                 NTSTATUS (*send_read)(struct dcerpc_pipe *);
65
66                 /* get an event context for the connection */
67                 struct event_context *(*event_context)(struct dcerpc_pipe *);
68
69                 /* a callback to the dcerpc code when a full fragment
70                    has been received */
71                 void (*recv_data)(struct dcerpc_pipe *, DATA_BLOB *, NTSTATUS status);
72
73         } transport;
74
75         /* the last fault code from a DCERPC fault */
76         uint32_t last_fault_code;
77
78         /* pending requests */
79         struct rpc_request *pending;
80
81         /* private pointer for pending full requests */
82         void *full_request_private;
83 };
84
85 /* dcerpc pipe flags */
86 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
87 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
88 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
89
90 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
91 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
92 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
93
94 #define DCERPC_CONNECT                 (1<<4)
95 #define DCERPC_SIGN                    (1<<5)
96 #define DCERPC_SEAL                    (1<<6)
97
98 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
99 #define DCERPC_PULL_BIGENDIAN          (1<<8)
100
101 #define DCERPC_SCHANNEL_BDC            (1<<9)
102 #define DCERPC_SCHANNEL_WORKSTATION    (1<<10)
103 #define DCERPC_SCHANNEL_DOMAIN         (1<<11)
104 #define DCERPC_SCHANNEL_ANY            (DCERPC_SCHANNEL_BDC| \
105                                         DCERPC_SCHANNEL_DOMAIN| \
106                                         DCERPC_SCHANNEL_WORKSTATION)
107 /* use a 128 bit session key */
108 #define DCERPC_SCHANNEL_128            (1<<12)
109
110 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL_ANY)
111
112 /* check incoming pad bytes */
113 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
114
115 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
116 #define DCERPC_NDR_REF_ALLOC           (1<<14)
117
118 /*
119   this is used to find pointers to calls
120 */
121 struct dcerpc_interface_call {
122         const char *name;
123         size_t struct_size;
124         NTSTATUS (*ndr_push)(struct ndr_push *, int , void *);
125         NTSTATUS (*ndr_pull)(struct ndr_pull *, int , void *);
126         void (*ndr_print)(struct ndr_print *, const char *, int, void *);       
127 };
128
129 struct dcerpc_endpoint_list {
130         uint32_t count;
131         const char * const *names;
132 };
133
134 struct dcerpc_interface_table {
135         const char *name;
136         const char *uuid;
137         uint32_t if_version;
138         const char *helpstring;
139         uint32_t num_calls;
140         const struct dcerpc_interface_call *calls;
141         const struct dcerpc_endpoint_list *endpoints;
142 };
143
144 struct dcerpc_interface_list
145 {
146         struct dcerpc_interface_list *prev, *next;
147         const struct dcerpc_interface_table *table;
148 };
149
150 extern struct dcerpc_interface_list *dcerpc_pipes;
151
152
153 /* this describes a binding to a particular transport/pipe */
154 struct dcerpc_binding {
155         enum dcerpc_transport_t transport;
156         struct GUID object;
157         int object_version;
158         const char *host;
159         const char *endpoint;
160         const char **options;
161         uint32_t flags;
162 };
163
164
165 enum rpc_request_state {
166         RPC_REQUEST_PENDING,
167         RPC_REQUEST_DONE
168 };
169
170 /*
171   handle for an async dcerpc request
172 */
173 struct rpc_request {
174         struct rpc_request *next, *prev;
175         struct dcerpc_pipe *p;
176         NTSTATUS status;
177         uint32_t call_id;
178         enum rpc_request_state state;
179         DATA_BLOB payload;
180         uint_t flags;
181         uint32_t fault_code;
182
183         /* use by the ndr level async recv call */
184         struct {
185                 const struct dcerpc_interface_table *table;
186                 uint32_t opnum;
187                 void *struct_ptr;
188                 TALLOC_CTX *mem_ctx;
189         } ndr;
190
191         struct {
192                 void (*callback)(struct rpc_request *);
193                 void *private;
194         } async;
195 };