Merge branch 'master' into wspp-schema
[kamenim/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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _DCE_RPC_H /* _DCE_RPC_H */
23 #define _DCE_RPC_H 
24
25 /* DCE/RPC packet types */
26
27 enum RPC_PKT_TYPE {
28         RPC_REQUEST  = 0x00,    /* Ordinary request. */
29         RPC_PING     = 0x01,    /* Connectionless is server alive ? */
30         RPC_RESPONSE = 0x02,    /* Ordinary reply. */
31         RPC_FAULT    = 0x03,    /* Fault in processing of call. */
32         RPC_WORKING  = 0x04,    /* Connectionless reply to a ping when server busy. */
33         RPC_NOCALL   = 0x05,    /* Connectionless reply to a ping when server has lost part of clients call. */
34         RPC_REJECT   = 0x06,    /* Refuse a request with a code. */
35         RPC_ACK      = 0x07,    /* Connectionless client to server code. */
36         RPC_CL_CANCEL= 0x08,    /* Connectionless cancel. */
37         RPC_FACK     = 0x09,    /* Connectionless fragment ack. Both client and server send. */
38         RPC_CANCEL_ACK = 0x0A,  /* Server ACK to client cancel request. */
39         RPC_BIND     = 0x0B,    /* Bind to interface. */
40         RPC_BINDACK  = 0x0C,    /* Server ack of bind. */
41         RPC_BINDNACK = 0x0D,    /* Server nack of bind. */
42         RPC_ALTCONT  = 0x0E,    /* Alter auth. */
43         RPC_ALTCONTRESP = 0x0F, /* Reply to alter auth. */
44         RPC_AUTH3    = 0x10,    /* not the real name!  this is undocumented! */
45         RPC_SHUTDOWN = 0x11,    /* Server to client request to shutdown. */
46         RPC_CO_CANCEL= 0x12,    /* Connection-oriented cancel request. */
47         RPC_ORPHANED = 0x13     /* Client telling server it's aborting a partially sent request or telling
48                                    server to stop sending replies. */
49 };
50
51 /* DCE/RPC flags */
52 #define RPC_FLG_FIRST 0x01
53 #define RPC_FLG_LAST  0x02
54 #define RPC_FLG_NOCALL 0x20
55
56
57 #define SMBD_NTLMSSP_NEG_FLAGS 0x000082b1 /* ALWAYS_SIGN|NEG_NTLM|NEG_LM|NEG_SEAL|NEG_SIGN|NEG_UNICODE */
58
59 /* NTLMSSP signature version */
60 #define NTLMSSP_SIGN_VERSION 0x01
61
62 /* DCE RPC auth types - extended by Microsoft. */
63 #define RPC_ANONYMOUS_AUTH_TYPE    0
64 #define RPC_AUTH_TYPE_KRB5_1       1
65 #define RPC_SPNEGO_AUTH_TYPE       9 
66 #define RPC_NTLMSSP_AUTH_TYPE     10
67 #define RPC_KRB5_AUTH_TYPE        16 /* Not yet implemented. */ 
68 #define RPC_SCHANNEL_AUTH_TYPE    68 /* 0x44 */
69
70 /* DCE-RPC standard identifiers to indicate 
71    signing or sealing of an RPC pipe */
72 #define RPC_AUTH_LEVEL_NONE      1
73 #define RPC_AUTH_LEVEL_CONNECT   2
74 #define RPC_AUTH_LEVEL_CALL      3
75 #define RPC_AUTH_LEVEL_PACKET    4
76 #define RPC_AUTH_LEVEL_INTEGRITY 5
77 #define RPC_AUTH_LEVEL_PRIVACY   6
78
79 #if 0
80 #define RPC_PIPE_AUTH_SIGN_LEVEL 0x5
81 #define RPC_PIPE_AUTH_SEAL_LEVEL 0x6
82 #endif
83
84 /* Netlogon schannel auth type and level */
85 #define SCHANNEL_SIGN_SIGNATURE { 0x77, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }
86 #define SCHANNEL_SEAL_SIGNATURE { 0x77, 0x00, 0x7a, 0x00, 0xff, 0xff, 0x00, 0x00 }
87
88 #define RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN  0x20
89 #define RPC_AUTH_SCHANNEL_SIGN_ONLY_CHK_LEN     0x18
90
91 /* The 7 here seems to be required to get Win2k not to downgrade us
92    to NT4.  Actually, anything other than 1ff would seem to do... */
93 #define NETLOGON_NEG_AUTH2_FLAGS 0x000701ff
94 /*
95         (NETLOGON_NEG_ACCOUNT_LOCKOUT |
96          NETLOGON_NEG_PERSISTENT_SAMREPL |
97          NETLOGON_NEG_ARCFOUR |
98          NETLOGON_NEG_PROMOTION_COUNT |
99          NETLOGON_NEG_CHANGELOG_BDC |
100          NETLOGON_NEG_FULL_SYNC_REPL |
101          NETLOGON_NEG_MULTIPLE_SIDS |
102          NETLOGON_NEG_REDO |
103          NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
104          NETLOGON_NEG_DNS_DOMAIN_TRUSTS |
105          NETLOGON_NEG_PASSWORD_SET2 |
106          NETLOGON_NEG_GETDOMAININFO)
107 */
108 #define NETLOGON_NEG_DOMAIN_TRUST_ACCOUNT       0x2010b000
109
110 /* these are the flags that ADS clients use */
111 #define NETLOGON_NEG_AUTH2_ADS_FLAGS 0x600fffff
112 /*
113         (NETLOGON_NEG_ACCOUNT_LOCKOUT |
114          NETLOGON_NEG_PERSISTENT_SAMREPL |
115          NETLOGON_NEG_ARCFOUR |
116          NETLOGON_NEG_PROMOTION_COUNT |
117          NETLOGON_NEG_CHANGELOG_BDC |
118          NETLOGON_NEG_FULL_SYNC_REPL |
119          NETLOGON_NEG_MULTIPLE_SIDS |
120          NETLOGON_NEG_REDO |
121          NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
122          NETLOGON_NEG_SEND_PASSWORD_INFO_PDC |
123          NETLOGON_NEG_GENERIC_PASSTHROUGH |
124          NETLOGON_NEG_CONCURRENT_RPC |
125          NETLOGON_NEG_AVOID_ACCOUNT_DB_REPL |
126          NETLOGON_NEG_AVOID_SECURITYAUTH_DB_REPL |
127          NETLOGON_NEG_128BIT |
128          NETLOGON_NEG_TRANSITIVE_TRUSTS |
129          NETLOGON_NEG_DNS_DOMAIN_TRUSTS |
130          NETLOGON_NEG_PASSWORD_SET2 |
131          NETLOGON_NEG_GETDOMAININFO |
132          NETLOGON_NEG_CROSS_FOREST_TRUSTS |
133          NETLOGON_NEG_AUTHENTICATED_RPC_LSASS |
134          NETLOGON_NEG_SCHANNEL)
135 */
136
137 enum schannel_direction {
138         SENDER_IS_INITIATOR,
139         SENDER_IS_ACCEPTOR
140 };
141
142 /* Maximum size of the signing data in a fragment. */
143 #define RPC_MAX_SIGN_SIZE 0x20 /* 32 */
144
145 /* Maximum PDU fragment size. */
146 /* #define MAX_PDU_FRAG_LEN 0x1630              this is what wnt sets */
147 #define RPC_MAX_PDU_FRAG_LEN 0x10b8                     /* this is what w2k sets */
148
149 /* RPC_IFACE */
150 typedef struct ndr_syntax_id RPC_IFACE;
151
152 #define RPC_IFACE_LEN (UUID_SIZE + 4)
153
154 /* RPC_HDR - dce rpc header */
155 typedef struct rpc_hdr_info {
156         uint8  major; /* 5 - RPC major version */
157         uint8  minor; /* 0 - RPC minor version */
158         uint8  pkt_type; /* RPC_PKT_TYPE - RPC response packet */
159         uint8  flags; /* DCE/RPC flags */
160         uint8  pack_type[4]; /* 0x1000 0000 - little-endian packed data representation */
161         uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */
162         uint16 auth_len; /* 0 - authentication length  */
163         uint32 call_id; /* call identifier.  matches 12th uint32 of incoming RPC data. */
164 } RPC_HDR;
165
166 #define RPC_HEADER_LEN 16
167
168 /* RPC_HDR_REQ - ms request rpc header */
169 typedef struct rpc_hdr_req_info {
170         uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
171         uint16 context_id;   /* presentation context identifier */
172         uint16  opnum;       /* opnum */
173 } RPC_HDR_REQ;
174
175 #define RPC_HDR_REQ_LEN 8
176
177 /* RPC_HDR_RESP - ms response rpc header */
178 typedef struct rpc_hdr_resp_info {
179         uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
180         uint16 context_id;   /* 0 - presentation context identifier */
181         uint8  cancel_count; /* 0 - cancel count */
182         uint8  reserved;     /* 0 - reserved. */
183 } RPC_HDR_RESP;
184
185 #define RPC_HDR_RESP_LEN 8
186
187 /* RPC_HDR_FAULT - fault rpc header */
188 typedef struct rpc_hdr_fault_info {
189         NTSTATUS status;
190         uint32 reserved; /* 0x0000 0000 */
191 } RPC_HDR_FAULT;
192
193 #define RPC_HDR_FAULT_LEN 8
194
195 /* this seems to be the same string name depending on the name of the pipe,
196  * but is more likely to be linked to the interface name
197  * "srvsvc", "\\PIPE\\ntsvcs"
198  * "samr", "\\PIPE\\lsass"
199  * "wkssvc", "\\PIPE\\wksvcs"
200  * "NETLOGON", "\\PIPE\\NETLOGON"
201  */
202 /* RPC_ADDR_STR */
203 typedef struct rpc_addr_info {
204         uint16 len;   /* length of the string including null terminator */
205         fstring str; /* the string above in single byte, null terminated form */
206 } RPC_ADDR_STR;
207
208 /* RPC_HDR_BBA - bind acknowledge, and alter context response. */
209 typedef struct rpc_hdr_bba_info {
210         uint16 max_tsize;       /* maximum transmission fragment size (0x1630) */
211         uint16 max_rsize;       /* max receive fragment size (0x1630) */
212         uint32 assoc_gid;       /* associated group id (0x0) */
213 } RPC_HDR_BBA;
214
215 #define RPC_HDR_BBA_LEN 8
216
217 /* RPC_HDR_AUTH */
218 typedef struct rpc_hdr_auth_info {
219         uint8 auth_type; /* See XXX_AUTH_TYPE above. */
220         uint8 auth_level; /* See RPC_PIPE_AUTH_XXX_LEVEL above. */
221         uint8 auth_pad_len;
222         uint8 auth_reserved;
223         uint32 auth_context_id;
224 } RPC_HDR_AUTH;
225
226 #define RPC_HDR_AUTH_LEN 8
227
228 /* this is TEMPORARILY coded up as a specific structure */
229 /* this structure comes after the bind request */
230 /* RPC_AUTH_SCHANNEL_NEG */
231 typedef struct rpc_auth_schannel_neg_info {
232         uint32 type1;   /* Always zero ? */
233         uint32 type2;   /* Types 0x3 and 0x13 seen. Check AcquireSecurityContext() docs.... */
234         fstring domain; /* calling workstations's domain */
235         fstring myname; /* calling workstation's name */
236 } RPC_AUTH_SCHANNEL_NEG;
237
238 /* attached to the end of encrypted rpc requests and responses */
239 /* RPC_AUTH_SCHANNEL_CHK */
240 typedef struct rpc_auth_schannel_chk_info {
241         uint8 sig  [8]; /* 77 00 7a 00 ff ff 00 00 */
242         uint8 packet_digest[8]; /* checksum over the packet, MD5'ed with session key */
243         uint8 seq_num[8]; /* verifier, seq num */
244         uint8 confounder[8]; /* random 8-byte nonce */
245 } RPC_AUTH_SCHANNEL_CHK;
246
247 typedef struct rpc_context {
248         uint16 context_id;              /* presentation context identifier. */
249         uint8 num_transfer_syntaxes;    /* the number of syntaxes */
250         RPC_IFACE abstract;             /* num and vers. of interface client is using */
251         RPC_IFACE *transfer;            /* Array of transfer interfaces. */
252 } RPC_CONTEXT;
253
254 /* RPC_BIND_REQ - ms req bind */
255 typedef struct rpc_bind_req_info {
256         RPC_HDR_BBA bba;
257         uint8 num_contexts;    /* the number of contexts */
258         RPC_CONTEXT *rpc_context;
259 } RPC_HDR_RB;
260
261 /* 
262  * The following length is 8 bytes RPC_HDR_BBA_LEN + 
263  * 4 bytes size of context count +
264  * (context_count * (4 bytes of context_id, size of transfer syntax count + RPC_IFACE_LEN bytes +
265  *                    (transfer_syntax_count * RPC_IFACE_LEN bytes)))
266  */
267
268 #define RPC_HDR_RB_LEN(rpc_hdr_rb) (RPC_HDR_BBA_LEN + 4 + \
269         ((rpc_hdr_rb)->num_contexts) * (4 + RPC_IFACE_LEN + (((rpc_hdr_rb)->rpc_context->num_transfer_syntaxes)*RPC_IFACE_LEN)))
270
271 /* RPC_RESULTS - can only cope with one reason, right now... */
272 typedef struct rpc_results_info {
273         /* uint8[] # 4-byte alignment padding, against SMB header */
274
275         uint8 num_results; /* the number of results (0x01) */
276
277         /* uint8[] # 4-byte alignment padding, against SMB header */
278
279         uint16 result; /* result (0x00 = accept) */
280         uint16 reason; /* reason (0x00 = no reason specified) */
281 } RPC_RESULTS;
282
283 /* RPC_HDR_BA */
284 typedef struct rpc_hdr_ba_info {
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 } RPC_HDR_BA;
291
292 /* RPC_AUTH_VERIFIER */
293 typedef struct rpc_auth_verif_info {
294         fstring signature; /* "NTLMSSP".. Ok, not quite anymore */
295         uint32  msg_type; /* NTLMSSP_MESSAGE_TYPE (1,2,3) and 5 for schannel */
296 } RPC_AUTH_VERIFIER;
297
298 #endif /* _DCE_RPC_H */