Move to a handle database per pipe name, not per pipe.
[tprouty/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 #define CHECK_STRUCT(data) \
43 { \
44         if ((data)->struct_start != 0xfefefefe || \
45             (data)->struct_end != 0xdcdcdcdc) \
46         { \
47                 DEBUG(0,("uninitialised structure (%s, %d)\n", \
48                 FUNCTION_MACRO, __LINE__)); \
49                 sleep(30); \
50         } \
51 }
52
53  
54 typedef struct _prs_struct 
55 {
56         BOOL io; /* parsing in or out of data stream */
57         /* 
58          * If the (incoming) data is big-endian. On output we are
59          * always little-endian.
60          */ 
61         BOOL bigendian_data;
62         uint8 align; /* data alignment */
63         BOOL is_dynamic; /* Do we own this memory or not ? */
64         uint32 data_offset; /* Current working offset into data. */
65         uint32 buffer_size; /* Current allocated size of the buffer. */
66         uint32 grow_size; /* size requested via prs_grow() calls */
67         char *data_p; /* The buffer itself. */
68         TALLOC_CTX *mem_ctx; /* When unmarshalling, use this.... */
69 } prs_struct;
70
71 /*
72  * Defines for io member of prs_struct.
73  */
74
75 #define MARSHALL 0
76 #define UNMARSHALL 1
77
78 #define MARSHALLING(ps) (!(ps)->io)
79 #define UNMARSHALLING(ps) ((ps)->io)
80
81 #define RPC_BIG_ENDIAN          1
82 #define RPC_LITTLE_ENDIAN       0
83
84 #define RPC_PARSE_ALIGN 4
85
86 typedef struct _output_data {
87         /*
88          * Raw RPC output data. This does not include RPC headers or footers.
89          */
90         prs_struct rdata;
91
92         /* The amount of data sent from the current rdata struct. */
93         uint32 data_sent_length;
94
95         /*
96          * The current PDU being returned. This inclues
97          * headers, data and authentication footer.
98          */
99         unsigned char current_pdu[MAX_PDU_FRAG_LEN];
100
101         /* The amount of data in the current_pdu buffer. */
102         uint32 current_pdu_len;
103
104         /* The amount of data sent from the current PDU. */
105         uint32 current_pdu_sent;
106 } output_data;
107
108 typedef struct _input_data {
109     /*
110      * This is the current incoming pdu. The data here
111      * is collected via multiple writes until a complete
112      * pdu is seen, then the data is copied into the in_data
113      * structure. The maximum size of this is 0x1630 (MAX_PDU_FRAG_LEN).
114      */
115     unsigned char current_in_pdu[MAX_PDU_FRAG_LEN];
116
117     /*
118      * The amount of data needed to complete the in_pdu.
119      * If this is zero, then we are at the start of a new
120      * pdu.
121      */
122     uint32 pdu_needed_len;
123
124     /*
125      * The amount of data received so far in the in_pdu.
126      * If this is zero, then we are at the start of a new
127      * pdu.
128      */
129     uint32 pdu_received_len;
130
131     /*
132      * This is the collection of input data with all
133      * the rpc headers and auth footers removed.
134      * The maximum length of this (1Mb) is strictly enforced.
135      */
136     prs_struct data;
137 } input_data;
138
139 /*
140  * Handle database - stored per pipe.
141  */
142
143 struct policy
144 {
145     struct policy *next, *prev;
146     struct pipes_struct *p;
147
148     POLICY_HND pol_hnd;
149
150     void *data_ptr;
151     void (*free_fn)(void *);
152
153 };
154
155 struct handle_list {
156         struct policy *Policy;  /* List of policies. */
157         size_t count;                   /* Current number of handles. */
158         size_t pipe_ref_count;  /* Number of pipe handles referring to this list. */
159 };
160
161 /* Domain controller authentication protocol info */
162 struct dcinfo
163 {
164         DOM_CHAL clnt_chal; /* Initial challenge received from client */
165         DOM_CHAL srv_chal;  /* Initial server challenge */
166         DOM_CRED clnt_cred; /* Last client credential */
167         DOM_CRED srv_cred;  /* Last server credential */
168  
169         uchar  sess_key[8]; /* Session key */
170         uchar  md4pw[16];   /* md4(machine password) */
171
172         fstring mach_acct;  /* Machine name we've authenticated. */
173 };
174
175 typedef struct pipes_struct
176 {
177         struct pipes_struct *next, *prev;
178         int pnum;
179         connection_struct *conn;
180         uint16 vuid; /* points to the unauthenticated user that opened this pipe. */
181         BOOL open; /* open connection */
182         uint16 device_state;
183         uint16 priority;
184         fstring name;
185         fstring pipe_srv_name;
186
187         RPC_HDR hdr; /* Incoming RPC header. */
188         RPC_HDR_REQ hdr_req; /* Incoming request header. */
189
190         uint32 ntlmssp_chal_flags; /* Client challenge flags. */
191         BOOL ntlmssp_auth_requested; /* If the client wanted authenticated rpc. */
192         BOOL ntlmssp_auth_validated; /* If the client *got* authenticated rpc. */
193         unsigned char challenge[8];
194         unsigned char ntlmssp_hash[258];
195         uint32 ntlmssp_seq_num;
196         struct dcinfo dc; /* Keeps the creds data. */
197
198         /*
199          * Windows user info.
200          */
201         fstring user_name;
202         fstring domain;
203         fstring wks;
204
205         /*
206          * Unix user name and credentials.
207          */
208
209         fstring pipe_user_name;
210         struct current_user pipe_user;
211
212         /*
213          * Set to true when an RPC bind has been done on this pipe.
214          */
215         
216         BOOL pipe_bound;
217         
218         /*
219          * Set to true when we should return fault PDU's for everything.
220          */
221         
222         BOOL fault_state;
223         
224         /*
225          * Set to RPC_BIG_ENDIAN when dealing with big-endian PDU's
226          */
227         
228         BOOL endian;
229         
230         /*
231          * Struct to deal with multiple pdu inputs.
232          */
233
234         input_data in_data;
235
236         /*
237          * Struct to deal with multiple pdu outputs.
238          */
239
240         output_data out_data;
241
242         /* When replying to an SMBtrans, this is the maximum amount of
243            data that can be sent in the initial reply. */
244         int max_trans_reply;
245
246         /* talloc context to use when allocating memory on this pipe. */
247         TALLOC_CTX *mem_ctx;
248
249         /* handle database to use on this pipe. */
250         struct handle_list *pipe_handles;
251
252 } pipes_struct;
253
254 struct api_struct
255 {  
256   char *name;
257   uint8 opnum;
258   BOOL (*fn) (pipes_struct *);
259 };
260
261 typedef struct
262 {  
263         uint32 rid;
264         char *name;
265
266 } rid_name;
267
268 struct acct_info
269 {
270     fstring acct_name; /* account name */
271     uint32 smb_userid; /* domain-relative RID */
272 };
273
274 /*
275  * higher order functions for use with msrpc client code
276  */
277
278 #define PRINT_INFO_FN(fn)\
279         void (*fn)(const char*, uint32, uint32, void  *const *const)
280 #define JOB_INFO_FN(fn)\
281         void (*fn)(const char*, const char*, uint32, uint32, void *const *const)
282
283 /* end higher order functions */
284
285
286 /* security descriptor structures */
287 #include "rpc_secdes.h"
288
289 /* different dce/rpc pipes */
290 #include "rpc_lsa.h"
291 #include "rpc_netlogon.h"
292 #include "rpc_reg.h"
293 #include "rpc_samr.h"
294 #include "rpc_srvsvc.h"
295 #include "rpc_wkssvc.h"
296 #include "rpc_spoolss.h"
297 #include "rpc_dfs.h"
298 #include "sids.h"
299
300 #endif /* _NT_DOMAIN_H */