trying to get HEAD building again. If you want the code
[tprouty/samba.git] / source3 / include / rpc_dce.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    
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 #ifndef _DCE_RPC_H /* _DCE_RPC_H */
24 #define _DCE_RPC_H 
25
26 #include "rpc_misc.h"  /* this only pulls in STRHDR */
27
28
29 /* DCE/RPC packet types */
30
31 enum RPC_PKT_TYPE
32 {
33         RPC_REQUEST = 0x00,
34         RPC_RESPONSE = 0x02,
35         RPC_FAULT    = 0x03,
36         RPC_BIND     = 0x0B,
37         RPC_BINDACK  = 0x0C,
38         RPC_BINDNACK = 0x0D,
39         RPC_ALTCONT  = 0x0E,
40         RPC_ALTCONTRESP = 0x0F,
41         RPC_BINDRESP = 0x10 /* not the real name!  this is undocumented! */
42 };
43
44 /* DCE/RPC flags */
45 #define RPC_FLG_FIRST 0x01
46 #define RPC_FLG_LAST  0x02
47 #define RPC_FLG_NOCALL 0x20
48
49 #define SMBD_NTLMSSP_NEG_FLAGS 0x000082b1 /* ALWAYS_SIGN|NEG_NTLM|NEG_LM|NEG_SEAL|NEG_SIGN|NEG_UNICODE */
50
51 /* NTLMSSP signature version */
52 #define NTLMSSP_SIGN_VERSION 0x01
53
54 /* NTLMSSP auth type */
55 #define NTLMSSP_AUTH_TYPE 0xa
56
57 /* DCE-RPC standard identifiers to indicate 
58    signing or sealing of an RPC pipe */
59 #define RPC_PIPE_AUTH_SIGN_LEVEL 0x5
60 #define RPC_PIPE_AUTH_SEAL_LEVEL 0x6
61
62 /* Netlogon schannel auth type and level */
63 #define NETSEC_AUTH_TYPE 0x44
64 #define NETSEC_SIGNATURE { 0x77, 0x00, 0x7a, 0x00, 0xff, 0xff, 0x00, 0x00 }
65 #define RPC_AUTH_NETSEC_CHK_LEN 0x20
66 #define NETLOGON_NEG_SCHANNEL    0x40000000
67
68 enum netsec_direction
69 {
70         SENDER_IS_INITIATOR,
71         SENDER_IS_ACCEPTOR
72 };
73
74 /* Internal Flags to indicate what type of authentication on the pipe */
75 #define AUTH_PIPE_SIGN    0x0001
76 #define AUTH_PIPE_SEAL    0x0002
77 #define AUTH_PIPE_NTLMSSP 0x0004
78 #define AUTH_PIPE_NETSEC  0x0008
79
80 /* Maximum PDU fragment size. */
81 #define MAX_PDU_FRAG_LEN 0x1630
82 /* #define MAX_PDU_FRAG_LEN 0x10b8              this is what w2k sets */
83
84 /*
85  * Actual structure of a DCE UUID
86  */
87
88 typedef struct rpc_uuid
89 {
90   uint32 time_low;
91   uint16 time_mid;
92   uint16 time_hi_and_version;
93   uint8 remaining[8];
94 } RPC_UUID;
95
96 #define RPC_UUID_LEN 16
97
98 /* RPC_IFACE */
99 typedef struct rpc_iface_info
100 {
101   RPC_UUID uuid;    /* 16 bytes of rpc interface identification */
102   uint32 version;    /* the interface version number */
103
104 } RPC_IFACE;
105
106 #define RPC_IFACE_LEN (RPC_UUID_LEN + 4)
107
108 struct pipe_id_info
109 {
110         /* the names appear not to matter: the syntaxes _do_ matter */
111
112         const char *client_pipe;
113         RPC_IFACE abstr_syntax; /* this one is the abstract syntax id */
114
115         const char *server_pipe;  /* this one is the secondary syntax name */
116         RPC_IFACE trans_syntax; /* this one is the primary syntax id */
117 };
118
119 /* RPC_HDR - dce rpc header */
120 typedef struct rpc_hdr_info
121 {
122   uint8  major; /* 5 - RPC major version */
123   uint8  minor; /* 0 - RPC minor version */
124   uint8  pkt_type; /* RPC_PKT_TYPE - RPC response packet */
125   uint8  flags; /* DCE/RPC flags */
126   uint8  pack_type[4]; /* 0x1000 0000 - little-endian packed data representation */
127   uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */
128   uint16 auth_len; /* 0 - authentication length  */
129   uint32 call_id; /* call identifier.  matches 12th uint32 of incoming RPC data. */
130
131 } RPC_HDR;
132
133 #define RPC_HEADER_LEN 16
134
135 /* RPC_HDR_REQ - ms request rpc header */
136 typedef struct rpc_hdr_req_info
137 {
138   uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
139   uint16 context_id;   /* 0 - presentation context identifier */
140   uint16  opnum;        /* opnum */
141
142 } RPC_HDR_REQ;
143
144 #define RPC_HDR_REQ_LEN 8
145
146 /* RPC_HDR_RESP - ms response rpc header */
147 typedef struct rpc_hdr_resp_info
148 {
149   uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
150   uint16 context_id;   /* 0 - presentation context identifier */
151   uint8  cancel_count; /* 0 - cancel count */
152   uint8  reserved;     /* 0 - reserved. */
153
154 } RPC_HDR_RESP;
155
156 #define RPC_HDR_RESP_LEN 8
157
158 /* RPC_HDR_FAULT - fault rpc header */
159 typedef struct rpc_hdr_fault_info
160 {
161   NTSTATUS status;
162   uint32 reserved; /* 0x0000 0000 */
163 } RPC_HDR_FAULT;
164
165 #define RPC_HDR_FAULT_LEN 8
166
167 /* this seems to be the same string name depending on the name of the pipe,
168  * but is more likely to be linked to the interface name
169  * "srvsvc", "\\PIPE\\ntsvcs"
170  * "samr", "\\PIPE\\lsass"
171  * "wkssvc", "\\PIPE\\wksvcs"
172  * "NETLOGON", "\\PIPE\\NETLOGON"
173  */
174 /* RPC_ADDR_STR */
175 typedef struct rpc_addr_info
176 {
177   uint16 len;   /* length of the string including null terminator */
178   fstring str; /* the string above in single byte, null terminated form */
179
180 } RPC_ADDR_STR;
181
182 /* RPC_HDR_BBA */
183 typedef struct rpc_hdr_bba_info
184 {
185   uint16 max_tsize;       /* maximum transmission fragment size (0x1630) */
186   uint16 max_rsize;       /* max receive fragment size (0x1630) */
187   uint32 assoc_gid;       /* associated group id (0x0) */
188
189 } RPC_HDR_BBA;
190
191 #define RPC_HDR_BBA_LEN 8
192
193 /* RPC_HDR_AUTHA */
194 typedef struct rpc_hdr_autha_info
195 {
196         uint16 max_tsize;       /* maximum transmission fragment size (0x1630) */
197         uint16 max_rsize;       /* max receive fragment size (0x1630) */
198
199         uint8 auth_type; /* 0x0a */
200         uint8 auth_level; /* 0x06 */
201         uint8 stub_type_len; /* don't know */
202         uint8 padding; /* padding */
203
204         uint32 unknown; /* 0x0014a0c0 */
205
206 } RPC_HDR_AUTHA;
207
208 #define RPC_HDR_AUTHA_LEN 12
209
210 /* RPC_HDR_AUTH */
211 typedef struct rpc_hdr_auth_info
212 {
213         uint8 auth_type; /* 0x0a */
214         uint8 auth_level; /* 0x06 */
215         uint8 padding;
216         uint8 reserved; /* padding */
217
218         uint32 auth_context; /* pointer */
219
220 } RPC_HDR_AUTH;
221
222 #define RPC_HDR_AUTH_LEN 8
223
224 /* this is TEMPORARILY coded up as a specific structure */
225 /* this structure comes after the bind request */
226 /* RPC_AUTH_NETSEC_NEG */
227 typedef struct rpc_auth_netsec_neg_info
228 {
229         uint32 type1;   /* Always zero ? */
230         uint32 type2;   /* Types 0x3 and 0x13 seen. Check AcquireSecurityContext() docs.... */
231         fstring domain; /* calling workstations's domain */
232         fstring myname; /* calling workstation's name */
233 } RPC_AUTH_NETSEC_NEG;
234
235 /* attached to the end of encrypted rpc requests and responses */
236 /* RPC_AUTH_NETSEC_CHK */
237 typedef struct rpc_auth_netsec_chk_info
238 {
239         uint8 sig  [8]; /* 77 00 7a 00 ff ff 00 00 */
240         uint8 packet_digest[8]; /* checksum over the packet, MD5'ed with session key */
241         uint8 seq_num[8]; /* verifier, seq num */
242         uint8 data8[8]; /* random 8-byte nonce */
243 } RPC_AUTH_NETSEC_CHK;
244
245 struct netsec_auth_struct
246 {
247         uchar sess_key[16];
248         uint32 seq_num;
249 };
250
251 /* RPC_BIND_REQ - ms req bind */
252 typedef struct rpc_bind_req_info
253 {
254   RPC_HDR_BBA bba;
255
256   uint32 num_elements;    /* the number of elements (0x1) */
257   uint16 context_id;      /* presentation context identifier (0x0) */
258   uint8 num_syntaxes;     /* the number of syntaxes (has always been 1?)(0x1) */
259
260   RPC_IFACE abstract;     /* num and vers. of interface client is using */
261   RPC_IFACE transfer;     /* num and vers. of interface to use for replies */
262   
263 } RPC_HDR_RB;
264
265 /* 
266  * The following length is 8 bytes RPC_HDR_BBA_LEN, 8 bytes internals 
267  * (with 3 bytes padding), + 2 x RPC_IFACE_LEN bytes for RPC_IFACE structs.
268  */
269
270 #define RPC_HDR_RB_LEN (RPC_HDR_BBA_LEN + 8 + (2*RPC_IFACE_LEN))
271
272 /* RPC_RESULTS - can only cope with one reason, right now... */
273 typedef struct rpc_results_info
274 {
275 /* uint8[] # 4-byte alignment padding, against SMB header */
276
277   uint8 num_results; /* the number of results (0x01) */
278
279 /* uint8[] # 4-byte alignment padding, against SMB header */
280
281   uint16 result; /* result (0x00 = accept) */
282   uint16 reason; /* reason (0x00 = no reason specified) */
283
284 } RPC_RESULTS;
285
286 /* RPC_HDR_BA */
287 typedef struct rpc_hdr_ba_info
288 {
289   RPC_HDR_BBA bba;
290
291   RPC_ADDR_STR addr    ;  /* the secondary address string, as described earlier */
292   RPC_RESULTS  res     ; /* results and reasons */
293   RPC_IFACE    transfer; /* the transfer syntax from the request */
294
295 } RPC_HDR_BA;
296
297 /* RPC_AUTH_VERIFIER */
298 typedef struct rpc_auth_verif_info
299 {
300         fstring signature; /* "NTLMSSP".. Ok, not quite anymore */
301         uint32  msg_type; /* NTLMSSP_MESSAGE_TYPE (1,2,3) and 5 for schannel */
302
303 } RPC_AUTH_VERIFIER;
304
305 /* this is TEMPORARILY coded up as a specific structure */
306 /* this structure comes after the bind request */
307 /* RPC_AUTH_NTLMSSP_NEG */
308 typedef struct rpc_auth_ntlmssp_neg_info
309 {
310         uint32  neg_flgs; /* 0x0000 b2b3 */
311
312         STRHDR hdr_myname; /* offset is against START of this structure */
313         STRHDR hdr_domain; /* offset is against START of this structure */
314
315         fstring myname; /* calling workstation's name */
316         fstring domain; /* calling workstations's domain */
317
318 } RPC_AUTH_NTLMSSP_NEG;
319
320 /* this is TEMPORARILY coded up as a specific structure */
321 /* this structure comes after the bind acknowledgement */
322 /* RPC_AUTH_NTLMSSP_CHAL */
323 typedef struct rpc_auth_ntlmssp_chal_info
324 {
325         uint32 unknown_1; /* 0x0000 0000 */
326         uint32 unknown_2; /* 0x0000 0028 */
327         uint32 neg_flags; /* 0x0000 82b1 */
328
329         uint8 challenge[8]; /* ntlm challenge */
330         uint8 reserved [8]; /* zeros */
331
332 } RPC_AUTH_NTLMSSP_CHAL;
333
334
335 /* RPC_AUTH_NTLMSSP_RESP */
336 typedef struct rpc_auth_ntlmssp_resp_info
337 {
338         STRHDR hdr_lm_resp; /* 24 byte response */
339         STRHDR hdr_nt_resp; /* 24 byte response */
340         STRHDR hdr_domain;
341         STRHDR hdr_usr;
342         STRHDR hdr_wks;
343         STRHDR hdr_sess_key; /* NULL unless negotiated */
344         uint32 neg_flags; /* 0x0000 82b1 */
345
346         fstring sess_key;
347         fstring wks;
348         fstring user;
349         fstring domain;
350         fstring nt_resp;
351         fstring lm_resp;
352
353 } RPC_AUTH_NTLMSSP_RESP;
354
355 /* attached to the end of encrypted rpc requests and responses */
356 /* RPC_AUTH_NTLMSSP_CHK */
357 typedef struct rpc_auth_ntlmssp_chk_info
358 {
359         uint32 ver; /* 0x0000 0001 */
360         uint32 reserved;
361         uint32 crc32; /* checksum using 0xEDB8 8320 as a polynomial */
362         uint32 seq_num;
363
364 } RPC_AUTH_NTLMSSP_CHK;
365
366 #define RPC_AUTH_NTLMSSP_CHK_LEN 16
367
368 #endif /* _DCE_RPC_H */