s3: smbd: Correctly process SMB3 POSIX paths in create.
[Samba.git] / source3 / smbd / globals.h
blobff69d95ddfb9f2f0a08aa030b08522e0b5f7dc72
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 struct files_struct *fsp);
282 size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req);
283 void remove_smb2_chained_fsp(files_struct *fsp);
285 NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req,
286 uint32_t data_length);
288 NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
289 size_t expected_body_size);
291 void smb2_request_set_async_internal(struct smbd_smb2_request *req,
292 bool async_internal);
294 enum protocol_types smbd_smb2_protocol_dialect_match(const uint8_t *indyn,
295 const int dialect_count,
296 uint16_t *dialect);
297 NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
298 NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
299 NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req);
300 NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req);
301 NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req);
302 NTSTATUS smbd_smb2_request_process_create(struct smbd_smb2_request *req);
303 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req);
304 NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req);
305 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req);
306 NTSTATUS smb2_read_complete(struct tevent_req *req, ssize_t nread, int err);
307 NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req);
308 NTSTATUS smb2_write_complete(struct tevent_req *req, ssize_t nwritten, int err);
309 NTSTATUS smb2_write_complete_nosync(struct tevent_req *req, ssize_t nwritten,
310 int err);
311 NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req);
312 NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req);
313 NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
314 NTSTATUS smbd_smb2_request_process_query_directory(struct smbd_smb2_request *req);
315 NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req);
316 NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req);
317 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req);
318 NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req);
319 NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req);
320 void smbd_smb2_request_dispatch_immediate(struct tevent_context *ctx,
321 struct tevent_immediate *im,
322 void *private_data);
324 struct deferred_open_record;
326 /* SMB1 -> SMB2 glue. */
327 void send_break_message_smb2(files_struct *fsp,
328 uint32_t break_from,
329 uint32_t break_to);
330 /* From smbd/smb2_create.c */
331 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level);
332 bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
333 struct timeval *p_request_time,
334 struct deferred_open_record **open_rec);
335 bool open_was_deferred_smb2(
336 struct smbXsrv_connection *xconn, uint64_t mid);
337 void remove_deferred_open_message_smb2(
338 struct smbXsrv_connection *xconn, uint64_t mid);
339 bool schedule_deferred_open_message_smb2(
340 struct smbXsrv_connection *xconn, uint64_t mid);
341 bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
342 struct timeval request_time,
343 struct timeval timeout,
344 struct file_id id,
345 struct deferred_open_record *open_rec);
347 struct smbXsrv_client;
349 struct smbXsrv_preauth {
350 uint8_t sha512_value[64];
353 struct smbXsrv_connection {
354 struct smbXsrv_connection *prev, *next;
356 struct smbXsrv_client *client;
358 NTTIME connect_time;
359 uint64_t channel_id;
360 const struct tsocket_address *local_address;
361 const struct tsocket_address *remote_address;
362 const char *remote_hostname;
363 bool has_cluster_movable_ip;
365 enum protocol_types protocol;
367 struct {
368 NTSTATUS status;
369 bool terminating;
370 struct tevent_queue *shutdown_wait_queue;
371 int sock;
372 struct tevent_fd *fde;
374 struct {
375 bool got_session;
376 } nbt;
377 } transport;
379 struct {
380 bool force_unacked_timeout;
381 uint64_t unacked_bytes;
382 uint32_t rto_usecs;
383 struct tevent_req *checker_subreq;
384 struct smbd_smb2_send_queue *queue;
385 } ack;
387 #if defined(WITH_SMB1SERVER)
388 struct {
389 struct {
391 * fd for the fcntl lock and process shared
392 * robust mutex to coordinate access to the
393 * client socket. When the system supports
394 * process shared robust mutexes, those are
395 * used. If not, then the fcntl lock will be
396 * used.
398 int socket_lock_fd;
399 #ifdef HAVE_ROBUST_MUTEXES
400 pthread_mutex_t *socket_mutex;
401 #endif
404 * fd for the trusted pipe from
405 * echo handler child
407 int trusted_fd;
410 * fde for the trusted_fd
412 struct tevent_fd *trusted_fde;
415 * Reference count for the fcntl lock to
416 * allow recursive locks.
418 int ref_count;
419 } echo_handler;
421 struct {
422 bool encrypted_passwords;
423 bool spnego;
424 struct auth4_context *auth_context;
425 bool done;
427 * Size of the data we can receive. Set by us.
428 * Can be modified by the max xmit parameter.
430 int max_recv;
431 } negprot;
433 struct {
434 bool done_sesssetup;
436 * Size of data we can send to client. Set
437 * by the client for all protocols above CORE.
438 * Set by us for CORE protocol.
440 int max_send;
441 } sessions;
442 struct smb1_signing_state *signing_state;
444 struct {
445 uint16_t client_major;
446 uint16_t client_minor;
447 uint32_t client_cap_low;
448 uint32_t client_cap_high;
449 } unix_info;
451 struct msg_state *msg_state;
452 } smb1;
453 #endif
454 struct {
455 struct smbd_smb2_request_read_state {
456 struct smbd_smb2_request *req;
457 struct {
458 uint8_t nbt[NBT_HDR_SIZE];
459 bool done;
460 } hdr;
461 struct iovec vector;
462 bool doing_receivefile;
463 size_t min_recv_size;
464 size_t pktfull;
465 size_t pktlen;
466 uint8_t *pktbuf;
467 } request_read_state;
468 struct smbd_smb2_send_queue *send_queue;
469 size_t send_queue_len;
471 struct {
473 * seq_low is the lowest sequence number
474 * we will accept.
476 uint64_t seq_low;
478 * seq_range is the range of credits we have
479 * granted from the sequence windows starting
480 * at seq_low.
482 * This gets incremented when new credits are
483 * granted and gets decremented when the
484 * lowest sequence number is consumed
485 * (when seq_low gets incremented).
487 uint16_t seq_range;
489 * The number of credits we have currently granted
490 * to the client.
492 * This gets incremented when new credits are
493 * granted and gets decremented when any credit
494 * is comsumed.
496 * Note: the decrementing is different compared
497 * to seq_range.
499 uint16_t granted;
501 * The maximum number of credits we will ever
502 * grant to the client.
504 * Typically we will only grant 1/16th of
505 * max_credits.
507 * This is the "server max credits" parameter.
509 uint16_t max;
511 * a bitmap of size max_credits
513 struct bitmap *bitmap;
514 bool multicredit;
515 } credits;
517 bool allow_2ff;
518 struct {
519 uint32_t capabilities;
520 struct GUID guid;
521 bool guid_verified;
522 uint16_t security_mode;
523 uint16_t num_dialects;
524 uint16_t *dialects;
525 } client;
526 struct {
527 uint32_t capabilities;
528 struct GUID guid;
529 uint16_t security_mode;
530 uint16_t dialect;
531 uint32_t max_trans;
532 uint32_t max_read;
533 uint32_t max_write;
534 uint16_t sign_algo;
535 uint16_t cipher;
536 bool posix_extensions_negotiated;
537 } server;
539 struct smbXsrv_preauth preauth;
541 struct smbd_smb2_request *requests;
543 struct {
544 uint8_t read_body_padding;
545 } smbtorture;
547 bool signing_mandatory;
548 } smb2;
551 const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
553 NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id);
554 uint32_t smbXsrv_version_global_current(void);
556 struct smbXsrv_client_table;
557 NTSTATUS smbXsrv_client_global_init(void);
558 NTSTATUS smbXsrv_client_create(TALLOC_CTX *mem_ctx,
559 struct tevent_context *ev_ctx,
560 struct messaging_context *msg_ctx,
561 NTTIME now,
562 struct smbXsrv_client **_client);
563 NTSTATUS smbXsrv_client_remove(struct smbXsrv_client *client);
564 struct tevent_req *smb2srv_client_mc_negprot_send(TALLOC_CTX *mem_ctx,
565 struct tevent_context *ev,
566 struct smbd_smb2_request *smb2req);
567 NTSTATUS smb2srv_client_mc_negprot_recv(struct tevent_req *req);
569 NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
570 enum protocol_types protocol);
572 NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx);
573 NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
574 NTTIME now,
575 struct smbXsrv_session **_session);
576 NTSTATUS smbXsrv_session_add_channel(struct smbXsrv_session *session,
577 struct smbXsrv_connection *conn,
578 NTTIME now,
579 struct smbXsrv_channel_global0 **_c);
580 NTSTATUS smbXsrv_session_remove_channel(struct smbXsrv_session *session,
581 struct smbXsrv_connection *xconn);
582 NTSTATUS smbXsrv_session_disconnect_xconn(struct smbXsrv_connection *xconn);
583 NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
584 struct smbXsrv_channel_global0;
585 NTSTATUS smbXsrv_session_find_channel(const struct smbXsrv_session *session,
586 const struct smbXsrv_connection *conn,
587 struct smbXsrv_channel_global0 **_c);
588 NTSTATUS smbXsrv_session_find_auth(const struct smbXsrv_session *session,
589 const struct smbXsrv_connection *conn,
590 NTTIME now,
591 struct smbXsrv_session_auth0 **_a);
592 NTSTATUS smbXsrv_session_create_auth(struct smbXsrv_session *session,
593 struct smbXsrv_connection *conn,
594 NTTIME now,
595 uint8_t in_flags,
596 uint8_t in_security_mode,
597 struct smbXsrv_session_auth0 **_a);
598 struct tevent_req *smb2srv_session_shutdown_send(TALLOC_CTX *mem_ctx,
599 struct tevent_context *ev,
600 struct smbXsrv_session *session,
601 struct smbd_smb2_request *current_req);
602 NTSTATUS smb2srv_session_shutdown_recv(struct tevent_req *req);
603 NTSTATUS smbXsrv_session_logoff(struct smbXsrv_session *session);
604 NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_client *client);
605 NTSTATUS smb1srv_session_table_init(struct smbXsrv_connection *conn);
606 NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
607 uint16_t vuid, NTTIME now,
608 struct smbXsrv_session **session);
609 NTSTATUS smbXsrv_session_info_lookup(struct smbXsrv_client *client,
610 uint64_t session_wire_id,
611 struct auth_session_info **si);
612 NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
613 NTSTATUS smb2srv_session_lookup_conn(struct smbXsrv_connection *conn,
614 uint64_t session_id, NTTIME now,
615 struct smbXsrv_session **session);
616 NTSTATUS smb2srv_session_lookup_client(struct smbXsrv_client *client,
617 uint64_t session_id, NTTIME now,
618 struct smbXsrv_session **session);
619 NTSTATUS smb2srv_session_lookup_global(struct smbXsrv_client *client,
620 uint64_t session_wire_id,
621 TALLOC_CTX *mem_ctx,
622 struct smbXsrv_session **session);
623 NTSTATUS get_valid_smbXsrv_session(struct smbXsrv_client *client,
624 uint64_t session_wire_id,
625 struct smbXsrv_session **session);
626 NTSTATUS smbXsrv_session_local_traverse(
627 struct smbXsrv_client *client,
628 int (*caller_cb)(struct smbXsrv_session *session,
629 void *caller_data),
630 void *caller_data);
631 struct smbXsrv_session_global0;
632 NTSTATUS smbXsrv_session_global_traverse(
633 int (*fn)(struct smbXsrv_session_global0 *, void *),
634 void *private_data);
635 struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
636 struct tevent_context *ev,
637 struct smbXsrv_connection *conn,
638 struct auth_session_info *session_info,
639 uint64_t previous_session_id,
640 uint64_t current_session_id);
641 NTSTATUS smb2srv_session_close_previous_recv(struct tevent_req *req);
643 NTSTATUS smbXsrv_tcon_global_init(void);
644 NTSTATUS smbXsrv_tcon_update(struct smbXsrv_tcon *tcon);
645 NTSTATUS smbXsrv_tcon_disconnect(struct smbXsrv_tcon *tcon, uint64_t vuid);
646 NTSTATUS smb1srv_tcon_table_init(struct smbXsrv_connection *conn);
647 NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
648 NTTIME now,
649 struct smbXsrv_tcon **_tcon);
650 NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
651 uint16_t tree_id, NTTIME now,
652 struct smbXsrv_tcon **tcon);
653 NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_client *client);
654 NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session);
655 NTSTATUS smb2srv_tcon_create(struct smbXsrv_session *session,
656 NTTIME now,
657 struct smbXsrv_tcon **_tcon);
658 NTSTATUS smb2srv_tcon_lookup(struct smbXsrv_session *session,
659 uint32_t tree_id, NTTIME now,
660 struct smbXsrv_tcon **tcon);
661 NTSTATUS smb2srv_tcon_disconnect_all(struct smbXsrv_session *session);
662 struct smbXsrv_tcon_global0;
663 NTSTATUS smbXsrv_tcon_global_traverse(
664 int (*fn)(struct smbXsrv_tcon_global0 *, void *),
665 void *private_data);
668 bool smbXsrv_is_encrypted(uint8_t encryption_flags);
669 bool smbXsrv_is_partially_encrypted(uint8_t encryption_flags);
670 bool smbXsrv_set_crypto_flag(uint8_t *flags, uint8_t flag);
671 bool smbXsrv_is_signed(uint8_t signing_flags);
672 bool smbXsrv_is_partially_signed(uint8_t signing_flags);
674 struct smbd_smb2_send_queue {
675 struct smbd_smb2_send_queue *prev, *next;
677 DATA_BLOB *sendfile_header;
678 uint32_t sendfile_body_size;
679 NTSTATUS *sendfile_status;
680 struct iovec *vector;
681 int count;
683 struct {
684 struct tevent_req *req;
685 struct timeval timeout;
686 uint64_t required_acked_bytes;
687 } ack;
689 TALLOC_CTX *mem_ctx;
692 struct smbd_smb2_request {
693 struct smbd_smb2_request *prev, *next;
695 struct smbd_server_connection *sconn;
696 struct smbXsrv_connection *xconn;
698 struct smbd_smb2_send_queue queue_entry;
700 /* the session the request operates on, maybe NULL */
701 struct smbXsrv_session *session;
702 uint64_t last_session_id;
704 /* the tcon the request operates on, maybe NULL */
705 struct smbXsrv_tcon *tcon;
706 uint32_t last_tid;
708 int current_idx;
709 bool do_signing;
710 /* Was the request encrypted? */
711 bool was_encrypted;
712 /* Should we encrypt? */
713 bool do_encryption;
714 struct tevent_timer *async_te;
715 bool compound_related;
716 NTSTATUS compound_create_err;
719 * Give the implementation of an SMB2 req a way to tell the SMB2 request
720 * processing engine that the internal request is going async, while
721 * preserving synchronous SMB2 behaviour.
723 bool async_internal;
726 * the encryption key for the whole
727 * compound chain
729 struct smb2_signing_key *first_enc_key;
731 * the signing key for the last
732 * request/response of a compound chain
734 struct smb2_signing_key *last_sign_key;
735 struct smbXsrv_preauth *preauth;
737 struct timeval request_time;
739 SMBPROFILE_IOBYTES_ASYNC_STATE(profile);
741 /* fake smb1 request. */
742 struct smb_request *smb1req;
743 struct files_struct *compat_chain_fsp;
746 * Keep track of whether the outstanding request counters
747 * had been updated in dispatch, so that they need to be
748 * adapted again in reply.
750 bool request_counters_updated;
751 uint64_t channel_generation;
754 * The sub request for async backend calls.
755 * This is used for SMB2 Cancel.
757 struct tevent_req *subreq;
759 #define SMBD_SMB2_TF_IOV_OFS 0
760 #define SMBD_SMB2_HDR_IOV_OFS 1
761 #define SMBD_SMB2_BODY_IOV_OFS 2
762 #define SMBD_SMB2_DYN_IOV_OFS 3
764 #define SMBD_SMB2_NUM_IOV_PER_REQ 4
766 #define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
767 (&req->dir.vector[(idx)+(ofs)])
769 #define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
770 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
771 #define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
772 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_HDR_IOV_OFS)
773 #define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
774 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_BODY_IOV_OFS)
775 #define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
776 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_DYN_IOV_OFS)
778 #define SMBD_SMB2_IN_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
779 #define SMBD_SMB2_IN_TF_PTR(req) (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
780 #define SMBD_SMB2_IN_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
781 #define SMBD_SMB2_IN_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
782 #define SMBD_SMB2_IN_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
783 #define SMBD_SMB2_IN_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
784 #define SMBD_SMB2_IN_BODY_LEN(req) (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
785 #define SMBD_SMB2_IN_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
786 #define SMBD_SMB2_IN_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
787 #define SMBD_SMB2_IN_DYN_LEN(req) (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
789 #define SMBD_SMB2_OUT_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
790 #define SMBD_SMB2_OUT_TF_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
791 #define SMBD_SMB2_OUT_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
792 #define SMBD_SMB2_OUT_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
793 #define SMBD_SMB2_OUT_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
794 #define SMBD_SMB2_OUT_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
795 #define SMBD_SMB2_OUT_BODY_LEN(req) (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
796 #define SMBD_SMB2_OUT_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
797 #define SMBD_SMB2_OUT_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
798 #define SMBD_SMB2_OUT_DYN_LEN(req) (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
800 #define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
802 struct {
804 * vector[0] TRANSPORT HEADER (empty)
806 * vector[1] SMB2_TRANSFORM (optional)
807 * vector[2] SMB2
808 * vector[3] fixed body
809 * vector[4] dynamic body
813 * vector[5] SMB2_TRANSFORM (optional)
814 * vector[6] SMB2
815 * vector[7] fixed body
816 * vector[8] dynamic body
821 struct iovec *vector;
822 int vector_count;
823 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
824 } in;
825 struct {
826 /* the NBT header is not allocated */
827 uint8_t nbt_hdr[4];
829 * vector[0] TRANSPORT HEADER
831 * vector[1] SMB2_TRANSFORM (optional)
832 * vector[2] SMB2
833 * vector[3] fixed body
834 * vector[4] dynamic body
838 * vector[5] SMB2_TRANSFORM (empty)
839 * vector[6] SMB2
840 * vector[7] fixed body
841 * vector[8] dynamic body
846 struct iovec *vector;
847 int vector_count;
848 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
849 #define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
850 uint8_t _hdr[OUTVEC_ALLOC_SIZE];
851 uint8_t _body[0x58];
852 } out;
855 struct smbd_server_connection;
857 struct pending_message_list;
858 struct pending_auth_data;
860 struct pthreadpool_tevent;
861 struct dcesrv_context;
863 struct smbd_server_connection {
864 const struct tsocket_address *local_address;
865 const struct tsocket_address *remote_address;
866 const char *remote_hostname;
867 struct tevent_context *ev_ctx;
868 struct messaging_context *msg_ctx;
869 struct dcesrv_context *dce_ctx;
870 struct notify_context *notify_ctx;
871 bool using_smb2;
872 int trans_num;
874 size_t num_users;
876 size_t num_connections;
877 struct connection_struct *connections;
879 size_t num_files;
880 struct files_struct *files;
882 int real_max_open_files;
883 struct fsp_singleton_cache fsp_fi_cache;
885 struct pending_message_list *deferred_open_queue;
888 /* open directory handles. */
889 struct {
890 struct bitmap *dptr_bmap;
891 struct dptr_struct *dirptrs;
892 } searches;
894 uint64_t num_requests;
896 /* Current number of oplocks we have outstanding. */
897 struct {
898 int32_t exclusive_open;
899 int32_t level_II_open;
900 struct kernel_oplocks *kernel_ops;
901 } oplocks;
903 struct notify_mid_map *notify_mid_maps;
905 struct pthreadpool_tevent *pool;
907 struct smbXsrv_client *client;
910 extern struct smbXsrv_client *global_smbXsrv_client;
912 void smbd_init_globals(void);
914 /****************************************************************************
915 The buffer we keep around whilst an aio request is in process.
916 *****************************************************************************/
918 struct aio_extra {
919 files_struct *fsp;
920 struct smb_request *smbreq;
921 DATA_BLOB outbuf;
922 struct lock_struct lock;
923 size_t nbyte;
924 off_t offset;
925 bool write_through;
928 #endif /* _SOURCE3_SMBD_GLOBALS_H_ */