r4962: add infrastructure to use raw krb5 auth in dcerpc client code
[ira/wip.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 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
52         struct dcerpc_transport {
53                 enum dcerpc_transport_t transport;
54                 void *private;
55
56                 NTSTATUS (*shutdown_pipe)(struct dcerpc_connection *);
57
58                 const char *(*peer_name)(struct dcerpc_connection *);
59
60                 /* send a request to the server */
61                 NTSTATUS (*send_request)(struct dcerpc_connection *, DATA_BLOB *, BOOL trigger_read);
62
63                 /* send a read request to the server */
64                 NTSTATUS (*send_read)(struct dcerpc_connection *);
65
66                 /* get an event context for the connection */
67                 struct event_context *(*event_context)(struct dcerpc_connection *);
68
69                 /* a callback to the dcerpc code when a full fragment
70                    has been received */
71                 void (*recv_data)(struct dcerpc_connection *, DATA_BLOB *, NTSTATUS status);
72         } transport;
73
74         /* pending requests */
75         struct rpc_request *pending;
76
77         /* private pointer for pending full requests */
78         void *full_request_private;
79
80         /* the next context_id to be assigned */
81         uint32_t next_context_id;
82 };
83
84 /*
85   this encapsulates a full dcerpc client side pipe 
86 */
87 struct dcerpc_pipe {
88         uint32_t context_id;
89
90         struct dcerpc_syntax_id syntax;
91         struct dcerpc_syntax_id transfer_syntax;
92
93         struct dcerpc_connection *conn;
94
95         /* the last fault code from a DCERPC fault */
96         uint32_t last_fault_code;
97 };
98
99
100 /* dcerpc pipe flags */
101 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
102 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
103 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
104
105 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
106 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
107 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
108
109 #define DCERPC_CONNECT                 (1<<4)
110 #define DCERPC_SIGN                    (1<<5)
111 #define DCERPC_SEAL                    (1<<6)
112
113 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
114 #define DCERPC_PULL_BIGENDIAN          (1<<8)
115
116 #define DCERPC_SCHANNEL_BDC            (1<<9)
117 #define DCERPC_SCHANNEL_WORKSTATION    (1<<10)
118 #define DCERPC_SCHANNEL_DOMAIN         (1<<11)
119 #define DCERPC_SCHANNEL_ANY            (DCERPC_SCHANNEL_BDC| \
120                                         DCERPC_SCHANNEL_DOMAIN| \
121                                         DCERPC_SCHANNEL_WORKSTATION)
122
123 /* use a 128 bit session key */
124 #define DCERPC_SCHANNEL_128            (1<<12)
125
126 /* check incoming pad bytes */
127 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
128
129 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
130 #define DCERPC_NDR_REF_ALLOC           (1<<14)
131
132 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL_ANY|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5)
133
134 /* enable spnego auth */
135 #define DCERPC_AUTH_SPNEGO             (1<<15)
136
137 /* enable krb5 auth */
138 #define DCERPC_AUTH_KRB5               (1<<16)
139
140 /*
141   this is used to find pointers to calls
142 */
143 struct dcerpc_interface_call {
144         const char *name;
145         size_t struct_size;
146         NTSTATUS (*ndr_push)(struct ndr_push *, int , void *);
147         NTSTATUS (*ndr_pull)(struct ndr_pull *, int , void *);
148         void (*ndr_print)(struct ndr_print *, const char *, int, void *);       
149 };
150
151 struct dcerpc_endpoint_list {
152         uint32_t count;
153         const char * const *names;
154 };
155
156 struct dcerpc_interface_table {
157         const char *name;
158         const char *uuid;
159         uint32_t if_version;
160         const char *helpstring;
161         uint32_t num_calls;
162         const struct dcerpc_interface_call *calls;
163         const struct dcerpc_endpoint_list *endpoints;
164 };
165
166 struct dcerpc_interface_list {
167         struct dcerpc_interface_list *prev, *next;
168         const struct dcerpc_interface_table *table;
169 };
170
171 /* this describes a binding to a particular transport/pipe */
172 struct dcerpc_binding {
173         enum dcerpc_transport_t transport;
174         struct GUID object;
175         int object_version;
176         const char *host;
177         const char *endpoint;
178         const char **options;
179         uint32_t flags;
180 };
181
182
183 enum rpc_request_state {
184         RPC_REQUEST_PENDING,
185         RPC_REQUEST_DONE
186 };
187
188 /*
189   handle for an async dcerpc request
190 */
191 struct rpc_request {
192         struct rpc_request *next, *prev;
193         struct dcerpc_pipe *p;
194         NTSTATUS status;
195         uint32_t call_id;
196         enum rpc_request_state state;
197         DATA_BLOB payload;
198         uint_t flags;
199         uint32_t fault_code;
200
201         /* use by the ndr level async recv call */
202         struct {
203                 const struct dcerpc_interface_table *table;
204                 uint32_t opnum;
205                 void *struct_ptr;
206                 TALLOC_CTX *mem_ctx;
207         } ndr;
208
209         struct {
210                 void (*callback)(struct rpc_request *);
211                 void *private;
212         } async;
213 };