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