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