s3-dcerpc: Use DATA_BLOB for pipes_struct input data
[kamenim/samba.git] / source3 / include / ntdomain.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB parameters and setup
4    Copyright (C) Andrew Tridgell 1992-1997
5    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
6    Copyright (C) Paul Ashton 1997
7    Copyright (C) Jeremy Allison 2000-2004
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 _NT_DOMAIN_H /* _NT_DOMAIN_H */
24 #define _NT_DOMAIN_H 
25
26 /*
27  * A bunch of stuff that was put into smb.h
28  * in the NTDOM branch - it didn't belong there.
29  */
30
31 #define prs_init_empty( _ps_, _ctx_, _io_ ) (void) prs_init((_ps_), 0, (_ctx_), (_io_))
32
33 typedef struct _prs_struct {
34         bool io; /* parsing in or out of data stream */
35         /* 
36          * If the (incoming) data is big-endian. On output we are
37          * always little-endian.
38          */ 
39         bool bigendian_data;
40         uint8 align; /* data alignment */
41         bool is_dynamic; /* Do we own this memory or not ? */
42         uint32 data_offset; /* Current working offset into data. */
43         uint32 buffer_size; /* Current allocated size of the buffer. */
44         uint32 grow_size; /* size requested via prs_grow() calls */
45         /* The buffer itself. If "is_dynamic" is true this
46          * MUST BE TALLOC'ed off mem_ctx. */
47         char *data_p;
48         TALLOC_CTX *mem_ctx; /* When unmarshalling, use this.... */
49 } prs_struct;
50
51 /*
52  * Defines for io member of prs_struct.
53  */
54
55 #define MARSHALL 0
56 #define UNMARSHALL 1
57
58 #define MARSHALLING(ps) (!(ps)->io)
59 #define UNMARSHALLING(ps) ((ps)->io)
60
61 #define RPC_BIG_ENDIAN          1
62 #define RPC_LITTLE_ENDIAN       0
63
64 #define RPC_PARSE_ALIGN 4
65
66 typedef struct _output_data {
67         /*
68          * Raw RPC output data. This does not include RPC headers or footers.
69          */
70         DATA_BLOB rdata;
71
72         /* The amount of data sent from the current rdata struct. */
73         uint32 data_sent_length;
74
75         /*
76          * The current fragment being returned. This inclues
77          * headers, data and authentication footer.
78          */
79         DATA_BLOB frag;
80
81         /* The amount of data sent from the current PDU. */
82         uint32 current_pdu_sent;
83 } output_data;
84
85 typedef struct _input_data {
86         /*
87          * This is the current incoming pdu. The data here
88          * is collected via multiple writes until a complete
89          * pdu is seen, then the data is copied into the in_data
90          * structure. The maximum size of this is 0x1630 (RPC_MAX_PDU_FRAG_LEN).
91          * If length is zero, then we are at the start of a new
92          * pdu.
93          */
94         DATA_BLOB pdu;
95
96         /*
97          * The amount of data needed to complete the in_pdu.
98          * If this is zero, then we are at the start of a new
99          * pdu.
100          */
101         uint32 pdu_needed_len;
102
103         /*
104          * This is the collection of input data with all
105          * the rpc headers and auth footers removed.
106          * The maximum length of this (1Mb) is strictly enforced.
107          */
108         DATA_BLOB data;
109
110 } input_data;
111
112 struct handle_list;
113
114 typedef struct pipe_rpc_fns {
115
116         struct pipe_rpc_fns *next, *prev;
117
118         /* RPC function table associated with the current rpc_bind (associated by context) */
119
120         const struct api_struct *cmds;
121         int n_cmds;
122         uint32 context_id;
123
124 } PIPE_RPC_FNS;
125
126 /*
127  * Different auth types we support.
128  * Can't keep in sync with wire values as spnego wraps different auth methods.
129  */
130
131 enum pipe_auth_type { PIPE_AUTH_TYPE_NONE = 0, PIPE_AUTH_TYPE_NTLMSSP, PIPE_AUTH_TYPE_SCHANNEL,
132                         PIPE_AUTH_TYPE_SPNEGO_NTLMSSP, PIPE_AUTH_TYPE_KRB5, PIPE_AUTH_TYPE_SPNEGO_KRB5 };
133
134 /* auth state for krb5. */
135 struct kerberos_auth_struct {
136         const char *service_principal;
137         DATA_BLOB session_key;
138 };
139
140 /* auth state for all bind types. */
141
142 struct pipe_auth_data {
143         enum pipe_auth_type auth_type; /* switch for union below. */
144         enum dcerpc_AuthLevel auth_level;
145         union {
146                 struct schannel_state *schannel_auth;
147                 struct auth_ntlmssp_state *auth_ntlmssp_state;
148 /*              struct kerberos_auth_struct *kerberos_auth; TO BE ADDED... */
149         } a_u;
150         void (*auth_data_free_func)(struct pipe_auth_data *);
151 };
152
153 /*
154  * DCE/RPC-specific samba-internal-specific handling of data on
155  * NamedPipes.
156  */
157
158 typedef struct pipes_struct {
159         struct pipes_struct *next, *prev;
160
161         char client_address[INET6_ADDRSTRLEN];
162
163         struct auth_serversupplied_info *server_info;
164
165         struct ndr_syntax_id syntax;
166
167         /* linked list of rpc dispatch tables associated 
168            with the open rpc contexts */
169
170         PIPE_RPC_FNS *contexts;
171
172         struct pipe_auth_data auth;
173
174         /*
175          * Set to true when an RPC bind has been done on this pipe.
176          */
177
178         bool pipe_bound;
179
180         /*
181          * Set to true when we should return fault PDU's for everything.
182          */
183
184         bool fault_state;
185
186         /*
187          * Set to true when we should return fault PDU's for a bad handle.
188          */
189
190         bool bad_handle_fault_state;
191
192         /*
193          * Set to true when the backend does not support a call.
194          */
195
196         bool rng_fault_state;
197
198         /*
199          * Set to RPC_BIG_ENDIAN when dealing with big-endian PDU's
200          */
201
202         bool endian;
203
204         /*
205          * Struct to deal with multiple pdu inputs.
206          */
207
208         input_data in_data;
209
210         /*
211          * Struct to deal with multiple pdu outputs.
212          */
213
214         output_data out_data;
215
216         /* This context is used for PDU data and is freed between each pdu.
217                 Don't use for pipe state storage. */
218         TALLOC_CTX *mem_ctx;
219
220         /* handle database to use on this pipe. */
221         struct handle_list *pipe_handles;
222
223         /* call id retrieved from the pdu header */
224         uint32_t call_id;
225
226         /* operation number retrieved from the rpc header */
227         uint16_t opnum;
228
229         /* private data for the interface implementation */
230         void *private_data;
231
232 } pipes_struct;
233
234 struct api_struct {  
235         const char *name;
236         uint8 opnum;
237         bool (*fn) (pipes_struct *);
238 };
239
240 #endif /* _NT_DOMAIN_H */