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