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