s3: smbd: Remove 'is_dfs' parameter to check_path_syntax_smb2().
[Samba.git] / source3 / smbd / globals.h
blob5fb9f2e647c213c9dd8ecfe7b08b3d3841f5e704
1 /*
2 Unix SMB/Netbios implementation.
3 smbd globals
4 Copyright (C) Stefan Metzmacher 2009
5 Copyright (C) Jeremy Allison 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _SOURCE3_SMBD_GLOBALS_H_
22 #define _SOURCE3_SMBD_GLOBALS_H_
24 #include "system/select.h"
25 #include "librpc/gen_ndr/smbXsrv.h"
26 #include "smbprofile.h"
28 #ifdef USE_DMAPI
29 struct smbd_dmapi_context;
30 extern struct smbd_dmapi_context *dmapi_ctx;
31 #endif
33 /* A singleton cache to speed up searching by dev/inode. */
34 struct fsp_singleton_cache {
35 files_struct *fsp;
36 struct file_id id;
39 extern const struct mangle_fns *mangle_fns;
41 extern unsigned char *chartest;
42 struct tdb_context;
43 extern struct tdb_context *tdb_mangled_cache;
46 this determines how many characters are used from the original filename
47 in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
48 The largest possible value is 6.
50 extern unsigned mangle_prefix;
52 struct msg_state;
54 extern bool logged_ioctl_message;
56 extern int trans_num;
58 extern time_t last_smb_conf_reload_time;
59 extern time_t last_printer_reload_time;
60 extern pid_t background_lpq_updater_pid;
62 /****************************************************************************
63 structure to hold a linked list of queued messages.
64 for processing.
65 ****************************************************************************/
66 extern uint32_t common_flags2;
68 extern struct smb_trans_enc_state *partial_srv_trans_enc_ctx;
69 extern struct smb_trans_enc_state *srv_trans_enc_ctx;
71 struct sec_ctx {
72 struct security_unix_token ut;
73 struct security_token *token;
75 /* A stack of security contexts. We include the current context as being
76 the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
77 extern struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1];
78 extern int sec_ctx_stack_ndx;
79 extern bool become_uid_done;
80 extern bool become_gid_done;
82 extern uint32_t global_client_caps;
84 extern uint16_t fnf_handle;
86 struct conn_ctx {
87 connection_struct *conn;
88 uint64_t vuid;
89 userdom_struct user_info;
91 /* A stack of current_user connection contexts. */
92 extern struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH];
93 extern int conn_ctx_stack_ndx;
95 struct vfs_init_function_entry;
96 extern struct vfs_init_function_entry *backends;
97 extern char *sparse_buf;
98 extern char *LastDir;
100 struct smbd_parent_context;
101 extern struct smbd_parent_context *am_parent;
102 extern struct memcache *smbd_memcache_ctx;
103 extern bool exit_firsttime;
105 struct tstream_context;
106 struct smbd_smb2_request;
108 DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbXsrv_connection *xconn);
110 void smbd_lock_socket(struct smbXsrv_connection *xconn);
111 void smbd_unlock_socket(struct smbXsrv_connection *xconn);
113 struct GUID smbd_request_guid(struct smb_request *smb1req, uint16_t idx);
115 NTSTATUS smbd_do_unlocking(struct smb_request *req,
116 files_struct *fsp,
117 uint16_t num_ulocks,
118 struct smbd_lock_element *ulocks);
120 NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
121 TALLOC_CTX *mem_ctx,
122 struct smb_request *req,
123 uint16_t info_level,
124 files_struct *fsp,
125 struct smb_filename *smb_fname,
126 bool delete_pending,
127 struct timespec write_time_ts,
128 struct ea_list *ea_list,
129 uint16_t flags2,
130 unsigned int max_data_bytes,
131 size_t *fixed_portion,
132 char **ppdata,
133 unsigned int *pdata_size);
135 NTSTATUS smbd_do_setfsinfo(connection_struct *conn,
136 struct smb_request *req,
137 TALLOC_CTX *mem_ctx,
138 uint16_t info_level,
139 files_struct *fsp,
140 const DATA_BLOB *pdata);
142 NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
143 struct smb_request *req,
144 TALLOC_CTX *mem_ctx,
145 uint16_t info_level,
146 files_struct *fsp,
147 struct smb_filename *smb_fname,
148 char **ppdata, int total_data,
149 int *ret_data_size);
151 NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
152 connection_struct *conn,
153 TALLOC_CTX *mem_ctx,
154 uint16_t info_level,
155 uint16_t flags2,
156 unsigned int max_data_bytes,
157 size_t *fixed_portion,
158 struct smb_filename *smb_fname,
159 char **ppdata,
160 int *ret_data_len);
162 bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
163 struct dptr_struct *dirptr,
164 const char *mask,
165 uint32_t dirtype,
166 bool dont_descend,
167 bool ask_sharemode,
168 bool get_dosmode,
169 bool (*match_fn)(TALLOC_CTX *ctx,
170 void *private_data,
171 const char *dname,
172 const char *mask,
173 char **_fname),
174 bool (*mode_fn)(TALLOC_CTX *ctx,
175 void *private_data,
176 struct files_struct *dirfsp,
177 struct smb_filename *atname,
178 struct smb_filename *smb_fname,
179 bool get_dosmode,
180 uint32_t *_mode),
181 void *private_data,
182 char **_fname,
183 struct smb_filename **_smb_fname,
184 uint32_t *_mode,
185 long *_prev_offset);
187 NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
188 connection_struct *conn,
189 struct dptr_struct *dirptr,
190 uint16_t flags2,
191 const char *path_mask,
192 uint32_t dirtype,
193 int info_level,
194 int requires_resume_key,
195 bool dont_descend,
196 bool ask_sharemode,
197 bool get_dosmode,
198 uint8_t align,
199 bool do_pad,
200 char **ppdata,
201 char *base_data,
202 char *end_data,
203 int space_remaining,
204 struct smb_filename **smb_fname,
205 bool *got_exact_match,
206 int *_last_entry_off,
207 struct ea_list *name_list,
208 struct file_id *file_id);
210 NTSTATUS smbd_calculate_access_mask_fsp(struct files_struct *dirsfp,
211 struct files_struct *fsp,
212 bool use_privs,
213 uint32_t access_mask,
214 uint32_t *access_mask_out);
216 void smbd_notify_cancel_by_smbreq(const struct smb_request *smbreq);
218 void smbXsrv_connection_disconnect_transport(struct smbXsrv_connection *xconn,
219 NTSTATUS status);
220 size_t smbXsrv_client_valid_connections(struct smbXsrv_client *client);
221 void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
222 const char *reason,
223 const char *location);
224 #define smbd_server_connection_terminate(xconn, reason) \
225 smbd_server_connection_terminate_ex(xconn, reason, __location__)
227 void smbd_server_disconnect_client_ex(struct smbXsrv_client *client,
228 const char *reason,
229 const char *location);
230 #define smbd_server_disconnect_client(__client, __reason) \
231 smbd_server_disconnect_client_ex(__client, __reason, __location__)
233 const char *smb2_opcode_name(uint16_t opcode);
234 bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
235 bool smbd_smb2_is_compound(const struct smbd_smb2_request *req);
236 bool smbd_smb2_is_last_in_compound(const struct smbd_smb2_request *req);
238 NTSTATUS smbd_add_connection(struct smbXsrv_client *client, int sock_fd,
239 NTTIME now, struct smbXsrv_connection **_xconn);
241 NTSTATUS reply_smb2002(struct smb_request *req, uint16_t choice);
242 NTSTATUS reply_smb20ff(struct smb_request *req, uint16_t choice);
243 NTSTATUS smbd_smb2_process_negprot(struct smbXsrv_connection *xconn,
244 uint64_t expected_seq_low,
245 const uint8_t *inpdu, size_t size);
246 NTSTATUS smb2_multi_protocol_reply_negprot(struct smb_request *req);
248 DATA_BLOB smbd_smb2_generate_outbody(struct smbd_smb2_request *req, size_t size);
250 bool smbXsrv_server_multi_channel_enabled(void);
252 NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
253 NTSTATUS status,
254 uint8_t error_context_count,
255 DATA_BLOB *info,
256 const char *location);
257 #define smbd_smb2_request_error(req, status) \
258 smbd_smb2_request_error_ex(req, status, 0, NULL, __location__)
259 NTSTATUS smbd_smb2_request_done_ex(struct smbd_smb2_request *req,
260 NTSTATUS status,
261 DATA_BLOB body, DATA_BLOB *dyn,
262 const char *location);
263 #define smbd_smb2_request_done(req, body, dyn) \
264 smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
266 NTSTATUS smbd_smb2_send_oplock_break(struct smbXsrv_client *client,
267 struct smbXsrv_open *op,
268 uint8_t oplock_level);
269 NTSTATUS smbd_smb2_send_lease_break(struct smbXsrv_client *client,
270 uint16_t new_epoch,
271 uint32_t lease_flags,
272 struct smb2_lease_key *lease_key,
273 uint32_t current_lease_state,
274 uint32_t new_lease_state);
276 NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
277 struct tevent_req *subreq,
278 uint32_t defer_time);
280 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req);
281 size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req);
282 void remove_smb2_chained_fsp(files_struct *fsp);
284 NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req,
285 uint32_t data_length);
287 NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
288 size_t expected_body_size);
290 void smb2_request_set_async_internal(struct smbd_smb2_request *req,
291 bool async_internal);
293 enum protocol_types smbd_smb2_protocol_dialect_match(const uint8_t *indyn,
294 const int dialect_count,
295 uint16_t *dialect);
296 NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
297 NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
298 NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req);
299 NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req);
300 NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req);
301 NTSTATUS smbd_smb2_request_process_create(struct smbd_smb2_request *req);
302 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req);
303 NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req);
304 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req);
305 NTSTATUS smb2_read_complete(struct tevent_req *req, ssize_t nread, int err);
306 NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req);
307 NTSTATUS smb2_write_complete(struct tevent_req *req, ssize_t nwritten, int err);
308 NTSTATUS smb2_write_complete_nosync(struct tevent_req *req, ssize_t nwritten,
309 int err);
310 NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req);
311 NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req);
312 NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
313 NTSTATUS smbd_smb2_request_process_query_directory(struct smbd_smb2_request *req);
314 NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req);
315 NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req);
316 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req);
317 NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req);
318 NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req);
319 void smbd_smb2_request_dispatch_immediate(struct tevent_context *ctx,
320 struct tevent_immediate *im,
321 void *private_data);
323 struct deferred_open_record;
325 /* SMB1 -> SMB2 glue. */
326 void send_break_message_smb2(files_struct *fsp,
327 uint32_t break_from,
328 uint32_t break_to);
329 /* From smbd/smb2_create.c */
330 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level);
331 bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
332 struct timeval *p_request_time,
333 struct deferred_open_record **open_rec);
334 bool open_was_deferred_smb2(
335 struct smbXsrv_connection *xconn, uint64_t mid);
336 void remove_deferred_open_message_smb2(
337 struct smbXsrv_connection *xconn, uint64_t mid);
338 bool schedule_deferred_open_message_smb2(
339 struct smbXsrv_connection *xconn, uint64_t mid);
340 bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
341 struct timeval request_time,
342 struct timeval timeout,
343 struct file_id id,
344 struct deferred_open_record *open_rec);
346 struct smbXsrv_client;
348 struct smbXsrv_preauth {
349 uint8_t sha512_value[64];
352 struct smbXsrv_connection {
353 struct smbXsrv_connection *prev, *next;
355 struct smbXsrv_client *client;
357 NTTIME connect_time;
358 uint64_t channel_id;
359 const struct tsocket_address *local_address;
360 const struct tsocket_address *remote_address;
361 const char *remote_hostname;
362 bool has_cluster_movable_ip;
364 enum protocol_types protocol;
366 struct {
367 NTSTATUS status;
368 bool terminating;
369 struct tevent_queue *shutdown_wait_queue;
370 int sock;
371 struct tevent_fd *fde;
373 struct {
374 bool got_session;
375 } nbt;
376 } transport;
378 struct {
379 bool force_unacked_timeout;
380 uint64_t unacked_bytes;
381 uint32_t rto_usecs;
382 struct tevent_req *checker_subreq;
383 struct smbd_smb2_send_queue *queue;
384 } ack;
386 #if defined(WITH_SMB1SERVER)
387 struct {
388 struct {
390 * fd for the fcntl lock and process shared
391 * robust mutex to coordinate access to the
392 * client socket. When the system supports
393 * process shared robust mutexes, those are
394 * used. If not, then the fcntl lock will be
395 * used.
397 int socket_lock_fd;
398 #ifdef HAVE_ROBUST_MUTEXES
399 pthread_mutex_t *socket_mutex;
400 #endif
403 * fd for the trusted pipe from
404 * echo handler child
406 int trusted_fd;
409 * fde for the trusted_fd
411 struct tevent_fd *trusted_fde;
414 * Reference count for the fcntl lock to
415 * allow recursive locks.
417 int ref_count;
418 } echo_handler;
420 struct {
421 bool encrypted_passwords;
422 bool spnego;
423 struct auth4_context *auth_context;
424 bool done;
426 * Size of the data we can receive. Set by us.
427 * Can be modified by the max xmit parameter.
429 int max_recv;
430 } negprot;
432 struct {
433 bool done_sesssetup;
435 * Size of data we can send to client. Set
436 * by the client for all protocols above CORE.
437 * Set by us for CORE protocol.
439 int max_send;
440 } sessions;
441 struct smb1_signing_state *signing_state;
443 struct {
444 uint16_t client_major;
445 uint16_t client_minor;
446 uint32_t client_cap_low;
447 uint32_t client_cap_high;
448 } unix_info;
450 struct msg_state *msg_state;
451 } smb1;
452 #endif
453 struct {
454 struct smbd_smb2_request_read_state {
455 struct smbd_smb2_request *req;
456 struct {
457 uint8_t nbt[NBT_HDR_SIZE];
458 bool done;
459 } hdr;
460 struct iovec vector;
461 bool doing_receivefile;
462 size_t min_recv_size;
463 size_t pktfull;
464 size_t pktlen;
465 uint8_t *pktbuf;
466 } request_read_state;
467 struct smbd_smb2_send_queue *send_queue;
468 size_t send_queue_len;
470 struct {
472 * seq_low is the lowest sequence number
473 * we will accept.
475 uint64_t seq_low;
477 * seq_range is the range of credits we have
478 * granted from the sequence windows starting
479 * at seq_low.
481 * This gets incremented when new credits are
482 * granted and gets decremented when the
483 * lowest sequence number is consumed
484 * (when seq_low gets incremented).
486 uint16_t seq_range;
488 * The number of credits we have currently granted
489 * to the client.
491 * This gets incremented when new credits are
492 * granted and gets decremented when any credit
493 * is comsumed.
495 * Note: the decrementing is different compared
496 * to seq_range.
498 uint16_t granted;
500 * The maximum number of credits we will ever
501 * grant to the client.
503 * Typically we will only grant 1/16th of
504 * max_credits.
506 * This is the "server max credits" parameter.
508 uint16_t max;
510 * a bitmap of size max_credits
512 struct bitmap *bitmap;
513 bool multicredit;
514 } credits;
516 bool allow_2ff;
517 struct {
518 uint32_t capabilities;
519 struct GUID guid;
520 bool guid_verified;
521 uint16_t security_mode;
522 uint16_t num_dialects;
523 uint16_t *dialects;
524 } client;
525 struct {
526 uint32_t capabilities;
527 struct GUID guid;
528 uint16_t security_mode;
529 uint16_t dialect;
530 uint32_t max_trans;
531 uint32_t max_read;
532 uint32_t max_write;
533 uint16_t sign_algo;
534 uint16_t cipher;
535 bool posix_extensions_negotiated;
536 } server;
538 struct smbXsrv_preauth preauth;
540 struct smbd_smb2_request *requests;
542 struct {
543 uint8_t read_body_padding;
544 } smbtorture;
546 bool signing_mandatory;
547 } smb2;
550 const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
552 NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id);
553 uint32_t smbXsrv_version_global_current(void);
555 struct smbXsrv_client_table;
556 NTSTATUS smbXsrv_client_global_init(void);
557 NTSTATUS smbXsrv_client_create(TALLOC_CTX *mem_ctx,
558 struct tevent_context *ev_ctx,
559 struct messaging_context *msg_ctx,
560 NTTIME now,
561 struct smbXsrv_client **_client);
562 NTSTATUS smbXsrv_client_remove(struct smbXsrv_client *client);
563 struct tevent_req *smb2srv_client_mc_negprot_send(TALLOC_CTX *mem_ctx,
564 struct tevent_context *ev,
565 struct smbd_smb2_request *smb2req);
566 NTSTATUS smb2srv_client_mc_negprot_recv(struct tevent_req *req);
568 NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
569 enum protocol_types protocol);
571 NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx);
572 NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
573 NTTIME now,
574 struct smbXsrv_session **_session);
575 NTSTATUS smbXsrv_session_add_channel(struct smbXsrv_session *session,
576 struct smbXsrv_connection *conn,
577 NTTIME now,
578 struct smbXsrv_channel_global0 **_c);
579 NTSTATUS smbXsrv_session_remove_channel(struct smbXsrv_session *session,
580 struct smbXsrv_connection *xconn);
581 NTSTATUS smbXsrv_session_disconnect_xconn(struct smbXsrv_connection *xconn);
582 NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
583 struct smbXsrv_channel_global0;
584 NTSTATUS smbXsrv_session_find_channel(const struct smbXsrv_session *session,
585 const struct smbXsrv_connection *conn,
586 struct smbXsrv_channel_global0 **_c);
587 NTSTATUS smbXsrv_session_find_auth(const struct smbXsrv_session *session,
588 const struct smbXsrv_connection *conn,
589 NTTIME now,
590 struct smbXsrv_session_auth0 **_a);
591 NTSTATUS smbXsrv_session_create_auth(struct smbXsrv_session *session,
592 struct smbXsrv_connection *conn,
593 NTTIME now,
594 uint8_t in_flags,
595 uint8_t in_security_mode,
596 struct smbXsrv_session_auth0 **_a);
597 struct tevent_req *smb2srv_session_shutdown_send(TALLOC_CTX *mem_ctx,
598 struct tevent_context *ev,
599 struct smbXsrv_session *session,
600 struct smbd_smb2_request *current_req);
601 NTSTATUS smb2srv_session_shutdown_recv(struct tevent_req *req);
602 NTSTATUS smbXsrv_session_logoff(struct smbXsrv_session *session);
603 NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_client *client);
604 NTSTATUS smb1srv_session_table_init(struct smbXsrv_connection *conn);
605 NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
606 uint16_t vuid, NTTIME now,
607 struct smbXsrv_session **session);
608 NTSTATUS smbXsrv_session_info_lookup(struct smbXsrv_client *client,
609 uint64_t session_wire_id,
610 struct auth_session_info **si);
611 NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
612 NTSTATUS smb2srv_session_lookup_conn(struct smbXsrv_connection *conn,
613 uint64_t session_id, NTTIME now,
614 struct smbXsrv_session **session);
615 NTSTATUS smb2srv_session_lookup_client(struct smbXsrv_client *client,
616 uint64_t session_id, NTTIME now,
617 struct smbXsrv_session **session);
618 NTSTATUS smb2srv_session_lookup_global(struct smbXsrv_client *client,
619 uint64_t session_wire_id,
620 TALLOC_CTX *mem_ctx,
621 struct smbXsrv_session **session);
622 NTSTATUS get_valid_smbXsrv_session(struct smbXsrv_client *client,
623 uint64_t session_wire_id,
624 struct smbXsrv_session **session);
625 NTSTATUS smbXsrv_session_local_traverse(
626 struct smbXsrv_client *client,
627 int (*caller_cb)(struct smbXsrv_session *session,
628 void *caller_data),
629 void *caller_data);
630 struct smbXsrv_session_global0;
631 NTSTATUS smbXsrv_session_global_traverse(
632 int (*fn)(struct smbXsrv_session_global0 *, void *),
633 void *private_data);
634 struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
635 struct tevent_context *ev,
636 struct smbXsrv_connection *conn,
637 struct auth_session_info *session_info,
638 uint64_t previous_session_id,
639 uint64_t current_session_id);
640 NTSTATUS smb2srv_session_close_previous_recv(struct tevent_req *req);
642 NTSTATUS smbXsrv_tcon_global_init(void);
643 NTSTATUS smbXsrv_tcon_update(struct smbXsrv_tcon *tcon);
644 NTSTATUS smbXsrv_tcon_disconnect(struct smbXsrv_tcon *tcon, uint64_t vuid);
645 NTSTATUS smb1srv_tcon_table_init(struct smbXsrv_connection *conn);
646 NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
647 NTTIME now,
648 struct smbXsrv_tcon **_tcon);
649 NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
650 uint16_t tree_id, NTTIME now,
651 struct smbXsrv_tcon **tcon);
652 NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_client *client);
653 NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session);
654 NTSTATUS smb2srv_tcon_create(struct smbXsrv_session *session,
655 NTTIME now,
656 struct smbXsrv_tcon **_tcon);
657 NTSTATUS smb2srv_tcon_lookup(struct smbXsrv_session *session,
658 uint32_t tree_id, NTTIME now,
659 struct smbXsrv_tcon **tcon);
660 NTSTATUS smb2srv_tcon_disconnect_all(struct smbXsrv_session *session);
661 struct smbXsrv_tcon_global0;
662 NTSTATUS smbXsrv_tcon_global_traverse(
663 int (*fn)(struct smbXsrv_tcon_global0 *, void *),
664 void *private_data);
667 bool smbXsrv_is_encrypted(uint8_t encryption_flags);
668 bool smbXsrv_is_partially_encrypted(uint8_t encryption_flags);
669 bool smbXsrv_set_crypto_flag(uint8_t *flags, uint8_t flag);
670 bool smbXsrv_is_signed(uint8_t signing_flags);
671 bool smbXsrv_is_partially_signed(uint8_t signing_flags);
673 struct smbd_smb2_send_queue {
674 struct smbd_smb2_send_queue *prev, *next;
676 DATA_BLOB *sendfile_header;
677 uint32_t sendfile_body_size;
678 NTSTATUS *sendfile_status;
679 struct iovec *vector;
680 int count;
682 struct {
683 struct tevent_req *req;
684 struct timeval timeout;
685 uint64_t required_acked_bytes;
686 } ack;
688 TALLOC_CTX *mem_ctx;
691 struct smbd_smb2_request {
692 struct smbd_smb2_request *prev, *next;
694 struct smbd_server_connection *sconn;
695 struct smbXsrv_connection *xconn;
697 struct smbd_smb2_send_queue queue_entry;
699 /* the session the request operates on, maybe NULL */
700 struct smbXsrv_session *session;
701 uint64_t last_session_id;
703 /* the tcon the request operates on, maybe NULL */
704 struct smbXsrv_tcon *tcon;
705 uint32_t last_tid;
707 int current_idx;
708 bool do_signing;
709 /* Was the request encrypted? */
710 bool was_encrypted;
711 /* Should we encrypt? */
712 bool do_encryption;
713 struct tevent_timer *async_te;
714 bool compound_related;
715 NTSTATUS compound_create_err;
718 * Give the implementation of an SMB2 req a way to tell the SMB2 request
719 * processing engine that the internal request is going async, while
720 * preserving synchronous SMB2 behaviour.
722 bool async_internal;
725 * the encryption key for the whole
726 * compound chain
728 struct smb2_signing_key *first_enc_key;
730 * the signing key for the last
731 * request/response of a compound chain
733 struct smb2_signing_key *last_sign_key;
734 struct smbXsrv_preauth *preauth;
736 struct timeval request_time;
738 SMBPROFILE_IOBYTES_ASYNC_STATE(profile);
740 /* fake smb1 request. */
741 struct smb_request *smb1req;
742 struct files_struct *compat_chain_fsp;
745 * Keep track of whether the outstanding request counters
746 * had been updated in dispatch, so that they need to be
747 * adapted again in reply.
749 bool request_counters_updated;
750 uint64_t channel_generation;
753 * The sub request for async backend calls.
754 * This is used for SMB2 Cancel.
756 struct tevent_req *subreq;
758 #define SMBD_SMB2_TF_IOV_OFS 0
759 #define SMBD_SMB2_HDR_IOV_OFS 1
760 #define SMBD_SMB2_BODY_IOV_OFS 2
761 #define SMBD_SMB2_DYN_IOV_OFS 3
763 #define SMBD_SMB2_NUM_IOV_PER_REQ 4
765 #define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
766 (&req->dir.vector[(idx)+(ofs)])
768 #define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
769 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
770 #define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
771 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_HDR_IOV_OFS)
772 #define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
773 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_BODY_IOV_OFS)
774 #define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
775 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_DYN_IOV_OFS)
777 #define SMBD_SMB2_IN_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
778 #define SMBD_SMB2_IN_TF_PTR(req) (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
779 #define SMBD_SMB2_IN_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
780 #define SMBD_SMB2_IN_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
781 #define SMBD_SMB2_IN_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
782 #define SMBD_SMB2_IN_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
783 #define SMBD_SMB2_IN_BODY_LEN(req) (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
784 #define SMBD_SMB2_IN_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
785 #define SMBD_SMB2_IN_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
786 #define SMBD_SMB2_IN_DYN_LEN(req) (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
788 #define SMBD_SMB2_OUT_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
789 #define SMBD_SMB2_OUT_TF_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
790 #define SMBD_SMB2_OUT_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
791 #define SMBD_SMB2_OUT_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
792 #define SMBD_SMB2_OUT_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
793 #define SMBD_SMB2_OUT_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
794 #define SMBD_SMB2_OUT_BODY_LEN(req) (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
795 #define SMBD_SMB2_OUT_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
796 #define SMBD_SMB2_OUT_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
797 #define SMBD_SMB2_OUT_DYN_LEN(req) (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
799 #define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
801 struct {
803 * vector[0] TRANSPORT HEADER (empty)
805 * vector[1] SMB2_TRANSFORM (optional)
806 * vector[2] SMB2
807 * vector[3] fixed body
808 * vector[4] dynamic body
812 * vector[5] SMB2_TRANSFORM (optional)
813 * vector[6] SMB2
814 * vector[7] fixed body
815 * vector[8] dynamic body
820 struct iovec *vector;
821 int vector_count;
822 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
823 } in;
824 struct {
825 /* the NBT header is not allocated */
826 uint8_t nbt_hdr[4];
828 * vector[0] TRANSPORT HEADER
830 * vector[1] SMB2_TRANSFORM (optional)
831 * vector[2] SMB2
832 * vector[3] fixed body
833 * vector[4] dynamic body
837 * vector[5] SMB2_TRANSFORM (empty)
838 * vector[6] SMB2
839 * vector[7] fixed body
840 * vector[8] dynamic body
845 struct iovec *vector;
846 int vector_count;
847 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
848 #define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
849 uint8_t _hdr[OUTVEC_ALLOC_SIZE];
850 uint8_t _body[0x58];
851 } out;
854 struct smbd_server_connection;
856 struct pending_message_list;
857 struct pending_auth_data;
859 struct pthreadpool_tevent;
860 struct dcesrv_context;
862 struct smbd_server_connection {
863 const struct tsocket_address *local_address;
864 const struct tsocket_address *remote_address;
865 const char *remote_hostname;
866 struct tevent_context *ev_ctx;
867 struct messaging_context *msg_ctx;
868 struct dcesrv_context *dce_ctx;
869 struct notify_context *notify_ctx;
870 bool using_smb2;
871 int trans_num;
873 size_t num_users;
875 size_t num_connections;
876 struct connection_struct *connections;
878 size_t num_files;
879 struct files_struct *files;
881 int real_max_open_files;
882 struct fsp_singleton_cache fsp_fi_cache;
884 struct pending_message_list *deferred_open_queue;
887 /* open directory handles. */
888 struct {
889 struct bitmap *dptr_bmap;
890 struct dptr_struct *dirptrs;
891 } searches;
893 uint64_t num_requests;
895 /* Current number of oplocks we have outstanding. */
896 struct {
897 int32_t exclusive_open;
898 int32_t level_II_open;
899 struct kernel_oplocks *kernel_ops;
900 } oplocks;
902 struct notify_mid_map *notify_mid_maps;
904 struct pthreadpool_tevent *pool;
906 struct smbXsrv_client *client;
909 extern struct smbXsrv_client *global_smbXsrv_client;
911 void smbd_init_globals(void);
913 /****************************************************************************
914 The buffer we keep around whilst an aio request is in process.
915 *****************************************************************************/
917 struct aio_extra {
918 files_struct *fsp;
919 struct smb_request *smbreq;
920 DATA_BLOB outbuf;
921 struct lock_struct lock;
922 size_t nbyte;
923 off_t offset;
924 bool write_through;
927 #endif /* _SOURCE3_SMBD_GLOBALS_H_ */