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