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