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