(merge from 3.0)
[tprouty/samba.git] / source / include / ntdomain.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 _NT_DOMAIN_H /* _NT_DOMAIN_H */
24 #define _NT_DOMAIN_H 
25
26 struct uuid
27 {
28   uint32 time_low;
29   uint16 time_mid;
30   uint16 time_hi_and_version;
31   uint8  clock_seq[2];
32   uint8  node[6];
33 };
34 #define UUID_SIZE 16
35
36 #define UUID_FLAT_SIZE 16
37 typedef struct uuid_flat
38 {
39         uint8 info[UUID_FLAT_SIZE];
40 } UUID_FLAT;
41
42 /* dce/rpc support */
43 #include "rpc_dce.h"
44
45 /* miscellaneous structures / defines */
46 #include "rpc_misc.h"
47
48 #include "rpc_creds.h"
49
50 #include "talloc.h"
51
52 /*
53  * A bunch of stuff that was put into smb.h
54  * in the NTDOM branch - it didn't belong there.
55  */
56  
57 typedef struct _prs_struct 
58 {
59         BOOL io; /* parsing in or out of data stream */
60         /* 
61          * If the (incoming) data is big-endian. On output we are
62          * always little-endian.
63          */ 
64         BOOL bigendian_data;
65         uint8 align; /* data alignment */
66         BOOL is_dynamic; /* Do we own this memory or not ? */
67         uint32 data_offset; /* Current working offset into data. */
68         uint32 buffer_size; /* Current allocated size of the buffer. */
69         uint32 grow_size; /* size requested via prs_grow() calls */
70         char *data_p; /* The buffer itself. */
71         TALLOC_CTX *mem_ctx; /* When unmarshalling, use this.... */
72 } prs_struct;
73
74 /*
75  * Defines for io member of prs_struct.
76  */
77
78 #define MARSHALL 0
79 #define UNMARSHALL 1
80
81 #define MARSHALLING(ps) (!(ps)->io)
82 #define UNMARSHALLING(ps) ((ps)->io)
83
84 #define RPC_BIG_ENDIAN          1
85 #define RPC_LITTLE_ENDIAN       0
86
87 #define RPC_PARSE_ALIGN 4
88
89 typedef struct _output_data {
90         /*
91          * Raw RPC output data. This does not include RPC headers or footers.
92          */
93         prs_struct rdata;
94
95         /* The amount of data sent from the current rdata struct. */
96         uint32 data_sent_length;
97
98         /*
99          * The current PDU being returned. This inclues
100          * headers, data and authentication footer.
101          */
102         unsigned char current_pdu[MAX_PDU_FRAG_LEN];
103
104         /* The amount of data in the current_pdu buffer. */
105         uint32 current_pdu_len;
106
107         /* The amount of data sent from the current PDU. */
108         uint32 current_pdu_sent;
109 } output_data;
110
111 typedef struct _input_data {
112     /*
113      * This is the current incoming pdu. The data here
114      * is collected via multiple writes until a complete
115      * pdu is seen, then the data is copied into the in_data
116      * structure. The maximum size of this is 0x1630 (MAX_PDU_FRAG_LEN).
117      */
118     unsigned char current_in_pdu[MAX_PDU_FRAG_LEN];
119
120     /*
121      * The amount of data needed to complete the in_pdu.
122      * If this is zero, then we are at the start of a new
123      * pdu.
124      */
125     uint32 pdu_needed_len;
126
127     /*
128      * The amount of data received so far in the in_pdu.
129      * If this is zero, then we are at the start of a new
130      * pdu.
131      */
132     uint32 pdu_received_len;
133
134     /*
135      * This is the collection of input data with all
136      * the rpc headers and auth footers removed.
137      * The maximum length of this (1Mb) is strictly enforced.
138      */
139     prs_struct data;
140 } input_data;
141
142 /*
143  * Handle database - stored per pipe.
144  */
145
146 struct policy
147 {
148     struct policy *next, *prev;
149
150     POLICY_HND pol_hnd;
151
152     void *data_ptr;
153     void (*free_fn)(void *);
154
155 };
156
157 struct handle_list {
158         struct policy *Policy;  /* List of policies. */
159         size_t count;                   /* Current number of handles. */
160         size_t pipe_ref_count;  /* Number of pipe handles referring to this list. */
161 };
162
163 /* Domain controller authentication protocol info */
164 struct dcinfo
165 {
166         DOM_CHAL clnt_chal; /* Initial challenge received from client */
167         DOM_CHAL srv_chal;  /* Initial server challenge */
168         DOM_CRED clnt_cred; /* Last client credential */
169         DOM_CRED srv_cred;  /* Last server credential */
170  
171         uchar  sess_key[8]; /* Session key */
172         uchar  md4pw[16];   /* md4(machine password) */
173
174         fstring mach_acct;  /* Machine name we've authenticated. */
175
176         fstring remote_machine;  /* Machine name we've authenticated. */
177
178         BOOL challenge_sent;
179         BOOL got_session_key;
180         BOOL authenticated;
181
182 };
183
184 typedef struct pipe_rpc_fns {
185
186         struct pipe_rpc_fns *next, *prev;
187         
188         /* RPC function table associated with the current rpc_bind (associated by context) */
189         
190         struct api_struct *cmds;
191         int n_cmds;
192         uint32 context_id;
193         
194 } PIPE_RPC_FNS;
195
196 /*
197  * DCE/RPC-specific samba-internal-specific handling of data on
198  * NamedPipes.
199  */
200
201 typedef struct pipes_struct
202 {
203         struct pipes_struct *next, *prev;
204
205         connection_struct *conn;
206         uint16 vuid; /* points to the unauthenticated user that opened this pipe. */
207
208         fstring name;
209         fstring pipe_srv_name;
210         
211         /* linked list of rpc dispatch tables associated 
212            with the open rpc contexts */
213            
214         PIPE_RPC_FNS *contexts;
215         
216         RPC_HDR hdr; /* Incoming RPC header. */
217         RPC_HDR_REQ hdr_req; /* Incoming request header. */
218
219         uint32 ntlmssp_chal_flags; /* Client challenge flags. */
220         BOOL ntlmssp_auth_requested; /* If the client wanted authenticated rpc. */
221         BOOL ntlmssp_auth_validated; /* If the client *got* authenticated rpc. */
222         unsigned char challenge[8];
223         unsigned char ntlmssp_hash[258];
224         uint32 ntlmssp_seq_num;
225         struct dcinfo dc; /* Keeps the creds data. */
226
227          /* Hmm. In my understanding the authentication happens
228             implicitly later, so there are no two stages for
229             schannel. */
230
231         BOOL netsec_auth_validated;
232         struct netsec_auth_struct netsec_auth;
233
234         /*
235          * Windows user info.
236          */
237         fstring user_name;
238         fstring domain;
239         fstring wks;
240
241         /*
242          * Unix user name and credentials.
243          */
244
245         fstring pipe_user_name;
246         struct current_user pipe_user;
247
248         DATA_BLOB session_key;
249
250         /*
251          * Set to true when an RPC bind has been done on this pipe.
252          */
253         
254         BOOL pipe_bound;
255         
256         /*
257          * Set to true when we should return fault PDU's for everything.
258          */
259         
260         BOOL fault_state;
261
262         /*
263          * Set to true when we should return fault PDU's for a bad handle.
264          */
265
266         BOOL bad_handle_fault_state;
267         
268         /*
269          * Set to RPC_BIG_ENDIAN when dealing with big-endian PDU's
270          */
271         
272         BOOL endian;
273         
274         /*
275          * Struct to deal with multiple pdu inputs.
276          */
277
278         input_data in_data;
279
280         /*
281          * Struct to deal with multiple pdu outputs.
282          */
283
284         output_data out_data;
285
286         /* talloc context to use when allocating memory on this pipe. */
287         TALLOC_CTX *mem_ctx;
288
289         /* handle database to use on this pipe. */
290         struct handle_list *pipe_handles;
291
292 } pipes_struct;
293
294 typedef struct smb_np_struct
295 {
296         struct smb_np_struct *next, *prev;
297         int pnum;
298         connection_struct *conn;
299         uint16 vuid; /* points to the unauthenticated user that opened this pipe. */
300         BOOL open; /* open connection */
301         uint16 device_state;
302         uint16 priority;
303         fstring name;
304
305         /* When replying to an SMBtrans, this is the maximum amount of
306            data that can be sent in the initial reply. */
307         int max_trans_reply;
308
309         /*
310          * NamedPipe state information.
311          *
312          * (e.g. typecast a np_struct, above).
313          */
314         void *np_state;
315
316         /*
317          * NamedPipe functions, to be called to perform
318          * Named Pipe transactions on request from an
319          * SMB client.
320          */
321
322         /* call to create a named pipe connection.
323          * returns: state information representing the connection.
324          *          is stored in np_state, above.
325          */
326         void *   (*namedpipe_create)(char *pipe_name, 
327                                           connection_struct *conn, uint16 vuid);
328
329         /* call to perform a write / read namedpipe transaction.
330          * TransactNamedPipe is weird: it returns whether there
331          * is more data outstanding to be read, and the
332          * caller is expected to take note and follow up with
333          * read requests.
334          */
335         ssize_t  (*namedpipe_transact)(void *np_state,
336                                        char *data, int len,
337                                        char *rdata, int rlen,
338                                        BOOL *pipe_outstanding);
339
340         /* call to perform a write namedpipe operation
341          */
342         ssize_t  (*namedpipe_write)(void * np_state,
343                                     char *data, size_t n);
344
345         /* call to perform a read namedpipe operation.
346          *
347          * NOTE: the only reason that the pipe_outstanding
348          * argument is here is because samba does not use
349          * the namedpipe_transact function yet: instead,
350          * it performs the same as what namedpipe_transact
351          * does - a write, followed by a read.
352          *
353          * when samba is modified to use namedpipe_transact,
354          * the pipe_outstanding argument may be removed.
355          */
356         ssize_t  (*namedpipe_read)(void * np_state,
357                                    char *data, size_t max_len,
358                                    BOOL *pipe_outstanding);
359
360         /* call to close a namedpipe.
361          * function is expected to perform all cleanups
362          * necessary, free all memory etc.
363          *
364          * returns True if cleanup was successful (not that
365          * we particularly care).
366          */
367         BOOL     (*namedpipe_close)(void * np_state);
368
369 } smb_np_struct;
370
371 struct api_struct
372 {  
373   const char *name;
374   uint8 opnum;
375   BOOL (*fn) (pipes_struct *);
376 };
377
378 typedef struct
379 {  
380         uint32 rid;
381         const char *name;
382
383 } rid_name;
384
385 struct acct_info
386 {
387     fstring acct_name; /* account name */
388     fstring acct_desc; /* account name */
389     uint32 rid; /* domain-relative RID */
390 };
391
392 /*
393  * higher order functions for use with msrpc client code
394  */
395
396 #define PRINT_INFO_FN(fn)\
397         void (*fn)(const char*, uint32, uint32, void  *const *const)
398 #define JOB_INFO_FN(fn)\
399         void (*fn)(const char*, const char*, uint32, uint32, void *const *const)
400
401 /* end higher order functions */
402
403
404 /* security descriptor structures */
405 #include "rpc_secdes.h"
406
407 /* pac */
408 #include "authdata.h"
409
410 /* different dce/rpc pipes */
411 #include "rpc_lsa.h"
412 #include "rpc_netlogon.h"
413 #include "rpc_reg.h"
414 #include "rpc_samr.h"
415 #include "rpc_srvsvc.h"
416 #include "rpc_wkssvc.h"
417 #include "rpc_spoolss.h"
418 #include "rpc_dfs.h"
419 #include "rpc_ds.h"
420 #include "rpc_echo.h"
421 #include "rpc_epmapper.h"
422 #include "rpc_shutdown.h"
423
424 #endif /* _NT_DOMAIN_H */