r10656: BIG merge from trunk. Features not copied over
[nivanova/samba-autobuild/.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 /* DCE/RPC packet types */
27
28 enum RPC_PKT_TYPE {
29         RPC_REQUEST = 0x00,
30         RPC_RESPONSE = 0x02,
31         RPC_FAULT    = 0x03,
32         RPC_BIND     = 0x0B,
33         RPC_BINDACK  = 0x0C,
34         RPC_BINDNACK = 0x0D,
35         RPC_ALTCONT  = 0x0E,
36         RPC_ALTCONTRESP = 0x0F,
37         RPC_AUTH3 = 0x10 /* not the real name!  this is undocumented! */
38 };
39
40 /* DCE/RPC flags */
41 #define RPC_FLG_FIRST 0x01
42 #define RPC_FLG_LAST  0x02
43 #define RPC_FLG_NOCALL 0x20
44
45
46 #define SMBD_NTLMSSP_NEG_FLAGS 0x000082b1 /* ALWAYS_SIGN|NEG_NTLM|NEG_LM|NEG_SEAL|NEG_SIGN|NEG_UNICODE */
47
48 /* NTLMSSP signature version */
49 #define NTLMSSP_SIGN_VERSION 0x01
50
51 /* DCE RPC auth types - extended by Microsoft. */
52 #define RPC_ANONYMOUS_AUTH_TYPE    0
53 #define RPC_AUTH_TYPE_KRB5_1       1
54 #define RPC_SPNEGO_AUTH_TYPE       9 
55 #define RPC_NTLMSSP_AUTH_TYPE     10
56 #define RPC_KRB5_AUTH_TYPE        16 /* Not yet implemented. */ 
57 #define RPC_SCHANNEL_AUTH_TYPE    68 /* 0x44 */
58
59 /* DCE-RPC standard identifiers to indicate 
60    signing or sealing of an RPC pipe */
61 #define RPC_AUTH_LEVEL_NONE      1
62 #define RPC_AUTH_LEVEL_CONNECT   2
63 #define RPC_AUTH_LEVEL_CALL      3
64 #define RPC_AUTH_LEVEL_PACKET    4
65 #define RPC_AUTH_LEVEL_INTEGRITY 5
66 #define RPC_AUTH_LEVEL_PRIVACY   6
67
68 #if 0
69 #define RPC_PIPE_AUTH_SIGN_LEVEL 0x5
70 #define RPC_PIPE_AUTH_SEAL_LEVEL 0x6
71 #endif
72
73 /* Netlogon schannel auth type and level */
74 #define SCHANNEL_SIGN_SIGNATURE { 0x77, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }
75 #define SCHANNEL_SEAL_SIGNATURE { 0x77, 0x00, 0x7a, 0x00, 0xff, 0xff, 0x00, 0x00 }
76
77 #define RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN  0x20
78 #define RPC_AUTH_SCHANNEL_SIGN_ONLY_CHK_LEN     0x18
79
80
81 /* The 7 here seems to be required to get Win2k not to downgrade us
82    to NT4.  Actually, anything other than 1ff would seem to do... */
83 #define NETLOGON_NEG_AUTH2_FLAGS 0x000701ff
84  
85 #define NETLOGON_NEG_SCHANNEL                   0x40000000
86 #define NETLOGON_NEG_DOMAIN_TRUST_ACCOUNT       0x2010b000
87
88 enum schannel_direction {
89         SENDER_IS_INITIATOR,
90         SENDER_IS_ACCEPTOR
91 };
92
93 /* Maximum size of the signing data in a fragment. */
94 #define RPC_MAX_SIGN_SIZE 0x20 /* 32 */
95
96 /* Maximum PDU fragment size. */
97 /* #define MAX_PDU_FRAG_LEN 0x1630              this is what wnt sets */
98 #define RPC_MAX_PDU_FRAG_LEN 0x10b8                     /* this is what w2k sets */
99
100 /* RPC_IFACE */
101 typedef struct rpc_iface_info {
102         struct uuid uuid;  /* 16 bytes of rpc interface identification */
103         uint32 version;    /* the interface version number */
104 } RPC_IFACE;
105
106 #define RPC_IFACE_LEN (UUID_SIZE + 4)
107
108 struct pipe_id_info {
109         /* the names appear not to matter: the syntaxes _do_ matter */
110
111         const char *client_pipe;
112         RPC_IFACE abstr_syntax; /* this one is the abstract syntax id */
113
114         const char *server_pipe;  /* this one is the secondary syntax name */
115         RPC_IFACE trans_syntax; /* this one is the primary syntax id */
116 };
117
118 /* RPC_HDR - dce rpc header */
119 typedef struct rpc_hdr_info {
120         uint8  major; /* 5 - RPC major version */
121         uint8  minor; /* 0 - RPC minor version */
122         uint8  pkt_type; /* RPC_PKT_TYPE - RPC response packet */
123         uint8  flags; /* DCE/RPC flags */
124         uint8  pack_type[4]; /* 0x1000 0000 - little-endian packed data representation */
125         uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */
126         uint16 auth_len; /* 0 - authentication length  */
127         uint32 call_id; /* call identifier.  matches 12th uint32 of incoming RPC data. */
128 } RPC_HDR;
129
130 #define RPC_HEADER_LEN 16
131
132 /* RPC_HDR_REQ - ms request rpc header */
133 typedef struct rpc_hdr_req_info {
134         uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
135         uint16 context_id;   /* presentation context identifier */
136         uint16  opnum;       /* opnum */
137 } RPC_HDR_REQ;
138
139 #define RPC_HDR_REQ_LEN 8
140
141 /* RPC_HDR_RESP - ms response rpc header */
142 typedef struct rpc_hdr_resp_info {
143         uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
144         uint16 context_id;   /* 0 - presentation context identifier */
145         uint8  cancel_count; /* 0 - cancel count */
146         uint8  reserved;     /* 0 - reserved. */
147 } RPC_HDR_RESP;
148
149 #define RPC_HDR_RESP_LEN 8
150
151 /* RPC_HDR_FAULT - fault rpc header */
152 typedef struct rpc_hdr_fault_info {
153         NTSTATUS status;
154         uint32 reserved; /* 0x0000 0000 */
155 } RPC_HDR_FAULT;
156
157 #define RPC_HDR_FAULT_LEN 8
158
159 /* this seems to be the same string name depending on the name of the pipe,
160  * but is more likely to be linked to the interface name
161  * "srvsvc", "\\PIPE\\ntsvcs"
162  * "samr", "\\PIPE\\lsass"
163  * "wkssvc", "\\PIPE\\wksvcs"
164  * "NETLOGON", "\\PIPE\\NETLOGON"
165  */
166 /* RPC_ADDR_STR */
167 typedef struct rpc_addr_info {
168         uint16 len;   /* length of the string including null terminator */
169         fstring str; /* the string above in single byte, null terminated form */
170 } RPC_ADDR_STR;
171
172 /* RPC_HDR_BBA - bind acknowledge, and alter context response. */
173 typedef struct rpc_hdr_bba_info {
174         uint16 max_tsize;       /* maximum transmission fragment size (0x1630) */
175         uint16 max_rsize;       /* max receive fragment size (0x1630) */
176         uint32 assoc_gid;       /* associated group id (0x0) */
177 } RPC_HDR_BBA;
178
179 #define RPC_HDR_BBA_LEN 8
180
181 /* RPC_HDR_AUTH */
182 typedef struct rpc_hdr_auth_info {
183         uint8 auth_type; /* See XXX_AUTH_TYPE above. */
184         uint8 auth_level; /* See RPC_PIPE_AUTH_XXX_LEVEL above. */
185         uint8 auth_pad_len;
186         uint8 auth_reserved;
187         uint32 auth_context_id;
188 } RPC_HDR_AUTH;
189
190 #define RPC_HDR_AUTH_LEN 8
191
192 /* this is TEMPORARILY coded up as a specific structure */
193 /* this structure comes after the bind request */
194 /* RPC_AUTH_SCHANNEL_NEG */
195 typedef struct rpc_auth_schannel_neg_info {
196         uint32 type1;   /* Always zero ? */
197         uint32 type2;   /* Types 0x3 and 0x13 seen. Check AcquireSecurityContext() docs.... */
198         fstring domain; /* calling workstations's domain */
199         fstring myname; /* calling workstation's name */
200 } RPC_AUTH_SCHANNEL_NEG;
201
202 /* attached to the end of encrypted rpc requests and responses */
203 /* RPC_AUTH_SCHANNEL_CHK */
204 typedef struct rpc_auth_schannel_chk_info {
205         uint8 sig  [8]; /* 77 00 7a 00 ff ff 00 00 */
206         uint8 packet_digest[8]; /* checksum over the packet, MD5'ed with session key */
207         uint8 seq_num[8]; /* verifier, seq num */
208         uint8 confounder[8]; /* random 8-byte nonce */
209 } RPC_AUTH_SCHANNEL_CHK;
210
211 typedef struct rpc_context {
212         uint16 context_id;              /* presentation context identifier. */
213         uint8 num_transfer_syntaxes;    /* the number of syntaxes */
214         RPC_IFACE abstract;             /* num and vers. of interface client is using */
215         RPC_IFACE *transfer;            /* Array of transfer interfaces. */
216 } RPC_CONTEXT;
217
218 /* RPC_BIND_REQ - ms req bind */
219 typedef struct rpc_bind_req_info {
220         RPC_HDR_BBA bba;
221         uint8 num_contexts;    /* the number of contexts */
222         RPC_CONTEXT *rpc_context;
223 } RPC_HDR_RB;
224
225 /* 
226  * The following length is 8 bytes RPC_HDR_BBA_LEN + 
227  * 4 bytes size of context count +
228  * (context_count * (4 bytes of context_id, size of transfer syntax count + RPC_IFACE_LEN bytes +
229  *                    (transfer_syntax_count * RPC_IFACE_LEN bytes)))
230  */
231
232 #define RPC_HDR_RB_LEN(rpc_hdr_rb) (RPC_HDR_BBA_LEN + 4 + \
233         ((rpc_hdr_rb)->num_contexts) * (4 + RPC_IFACE_LEN + (((rpc_hdr_rb)->rpc_context->num_transfer_syntaxes)*RPC_IFACE_LEN)))
234
235 /* RPC_RESULTS - can only cope with one reason, right now... */
236 typedef struct rpc_results_info {
237         /* uint8[] # 4-byte alignment padding, against SMB header */
238
239         uint8 num_results; /* the number of results (0x01) */
240
241         /* uint8[] # 4-byte alignment padding, against SMB header */
242
243         uint16 result; /* result (0x00 = accept) */
244         uint16 reason; /* reason (0x00 = no reason specified) */
245 } RPC_RESULTS;
246
247 /* RPC_HDR_BA */
248 typedef struct rpc_hdr_ba_info {
249         RPC_HDR_BBA bba;
250
251         RPC_ADDR_STR addr    ;  /* the secondary address string, as described earlier */
252         RPC_RESULTS  res     ; /* results and reasons */
253         RPC_IFACE    transfer; /* the transfer syntax from the request */
254 } RPC_HDR_BA;
255
256 /* RPC_AUTH_VERIFIER */
257 typedef struct rpc_auth_verif_info {
258         fstring signature; /* "NTLMSSP".. Ok, not quite anymore */
259         uint32  msg_type; /* NTLMSSP_MESSAGE_TYPE (1,2,3) and 5 for schannel */
260 } RPC_AUTH_VERIFIER;
261
262 #endif /* _DCE_RPC_H */