smbXsrv_session: add smbXsrv_session_find_auth()
[Samba.git] / source3 / smbd / globals.h
blobc0fc8485cfc160cd0c2703fdd9e9a75d8026ffd3
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 #include "system/select.h"
22 #include "librpc/gen_ndr/smbXsrv.h"
23 #include "smbprofile.h"
25 extern int aio_pending_size;
26 extern int outstanding_aio_calls;
28 #ifdef USE_DMAPI
29 struct smbd_dmapi_context;
30 extern struct smbd_dmapi_context *dmapi_ctx;
31 #endif
33 /* how many write cache buffers have been allocated */
34 extern unsigned int allocated_write_caches;
36 /* A singleton cache to speed up searching by dev/inode. */
37 struct fsp_singleton_cache {
38 files_struct *fsp;
39 struct file_id id;
42 extern const struct mangle_fns *mangle_fns;
44 extern unsigned char *chartest;
45 struct tdb_context;
46 extern struct tdb_context *tdb_mangled_cache;
49 this determines how many characters are used from the original filename
50 in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
51 The largest possible value is 6.
53 extern unsigned mangle_prefix;
55 struct msg_state;
57 extern bool logged_ioctl_message;
59 extern int trans_num;
61 extern time_t last_smb_conf_reload_time;
62 extern time_t last_printer_reload_time;
63 extern pid_t background_lpq_updater_pid;
65 /****************************************************************************
66 structure to hold a linked list of queued messages.
67 for processing.
68 ****************************************************************************/
69 extern uint32_t common_flags2;
71 extern struct smb_trans_enc_state *partial_srv_trans_enc_ctx;
72 extern struct smb_trans_enc_state *srv_trans_enc_ctx;
74 struct sec_ctx {
75 struct security_unix_token ut;
76 struct security_token *token;
78 /* A stack of security contexts. We include the current context as being
79 the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
80 extern struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1];
81 extern int sec_ctx_stack_ndx;
82 extern bool become_uid_done;
83 extern bool become_gid_done;
85 extern connection_struct *last_conn;
86 extern uint16_t last_flags;
88 extern uint32_t global_client_caps;
90 extern uint16_t fnf_handle;
92 struct conn_ctx {
93 connection_struct *conn;
94 uint64_t vuid;
96 /* A stack of current_user connection contexts. */
97 extern struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH];
98 extern int conn_ctx_stack_ndx;
100 struct vfs_init_function_entry;
101 extern struct vfs_init_function_entry *backends;
102 extern char *sparse_buf;
103 extern char *LastDir;
105 struct smbd_parent_context;
106 extern struct smbd_parent_context *am_parent;
107 extern struct memcache *smbd_memcache_ctx;
108 extern bool exit_firsttime;
110 struct tstream_context;
111 struct smbd_smb2_request;
113 DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbXsrv_connection *xconn);
115 void smbd_lock_socket(struct smbXsrv_connection *xconn);
116 void smbd_unlock_socket(struct smbXsrv_connection *xconn);
118 NTSTATUS smbd_do_locking(struct smb_request *req,
119 files_struct *fsp,
120 uint8_t type,
121 int32_t timeout,
122 uint16_t num_locks,
123 struct smbd_lock_element *locks,
124 bool *async);
125 NTSTATUS smbd_do_unlocking(struct smb_request *req,
126 files_struct *fsp,
127 uint16_t num_ulocks,
128 struct smbd_lock_element *ulocks);
130 NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
131 TALLOC_CTX *mem_ctx,
132 uint16_t info_level,
133 files_struct *fsp,
134 struct smb_filename *smb_fname,
135 bool delete_pending,
136 struct timespec write_time_ts,
137 struct ea_list *ea_list,
138 int lock_data_count,
139 char *lock_data,
140 uint16_t flags2,
141 unsigned int max_data_bytes,
142 size_t *fixed_portion,
143 char **ppdata,
144 unsigned int *pdata_size);
146 NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
147 struct smb_request *req,
148 TALLOC_CTX *mem_ctx,
149 uint16_t info_level,
150 files_struct *fsp,
151 struct smb_filename *smb_fname,
152 char **ppdata, int total_data,
153 int *ret_data_size);
155 NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
156 connection_struct *conn,
157 TALLOC_CTX *mem_ctx,
158 uint16_t info_level,
159 uint16_t flags2,
160 unsigned int max_data_bytes,
161 size_t *fixed_portion,
162 struct smb_filename *smb_fname,
163 char **ppdata,
164 int *ret_data_len);
166 bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
167 struct dptr_struct *dirptr,
168 const char *mask,
169 uint32_t dirtype,
170 bool dont_descend,
171 bool ask_sharemode,
172 bool (*match_fn)(TALLOC_CTX *ctx,
173 void *private_data,
174 const char *dname,
175 const char *mask,
176 char **_fname),
177 bool (*mode_fn)(TALLOC_CTX *ctx,
178 void *private_data,
179 struct smb_filename *smb_fname,
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 uint8_t align,
198 bool do_pad,
199 char **ppdata,
200 char *base_data,
201 char *end_data,
202 int space_remaining,
203 bool *got_exact_match,
204 int *_last_entry_off,
205 struct ea_list *name_list);
207 NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
208 const struct smb_filename *smb_fname,
209 bool use_privs,
210 uint32_t access_mask,
211 uint32_t *access_mask_out);
213 void smbd_notify_cancel_by_smbreq(const struct smb_request *smbreq);
215 void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
216 const char *reason,
217 const char *location);
218 #define smbd_server_connection_terminate(xconn, reason) \
219 smbd_server_connection_terminate_ex(xconn, reason, __location__)
221 const char *smb2_opcode_name(uint16_t opcode);
222 bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
224 NTSTATUS smbd_add_connection(struct smbXsrv_client *client, int sock_fd,
225 struct smbXsrv_connection **_xconn);
227 void reply_smb2002(struct smb_request *req, uint16_t choice);
228 void reply_smb20ff(struct smb_request *req, uint16_t choice);
229 void smbd_smb2_first_negprot(struct smbXsrv_connection *xconn,
230 const uint8_t *inpdu, size_t size);
232 DATA_BLOB smbd_smb2_generate_outbody(struct smbd_smb2_request *req, size_t size);
234 NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
235 NTSTATUS status,
236 DATA_BLOB *info,
237 const char *location);
238 #define smbd_smb2_request_error(req, status) \
239 smbd_smb2_request_error_ex(req, status, NULL, __location__)
240 NTSTATUS smbd_smb2_request_done_ex(struct smbd_smb2_request *req,
241 NTSTATUS status,
242 DATA_BLOB body, DATA_BLOB *dyn,
243 const char *location);
244 #define smbd_smb2_request_done(req, body, dyn) \
245 smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
247 NTSTATUS smbd_smb2_send_oplock_break(struct smbXsrv_connection *xconn,
248 struct smbXsrv_session *session,
249 struct smbXsrv_tcon *tcon,
250 struct smbXsrv_open *op,
251 uint8_t oplock_level);
252 NTSTATUS smbd_smb2_send_lease_break(struct smbXsrv_connection *xconn,
253 uint16_t new_epoch,
254 uint32_t lease_flags,
255 struct smb2_lease_key *lease_key,
256 uint32_t current_lease_state,
257 uint32_t new_lease_state);
259 NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
260 struct tevent_req *subreq,
261 uint32_t defer_time);
263 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req);
264 size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req);
265 void remove_smb2_chained_fsp(files_struct *fsp);
267 NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req,
268 uint32_t data_length);
270 NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
271 size_t expected_body_size);
273 enum protocol_types smbd_smb2_protocol_dialect_match(const uint8_t *indyn,
274 const int dialect_count,
275 uint16_t *dialect);
276 NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
277 NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
278 NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req);
279 NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req);
280 NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req);
281 NTSTATUS smbd_smb2_request_process_create(struct smbd_smb2_request *req);
282 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req);
283 NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req);
284 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req);
285 NTSTATUS smb2_read_complete(struct tevent_req *req, ssize_t nread, int err);
286 NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req);
287 NTSTATUS smb2_write_complete(struct tevent_req *req, ssize_t nwritten, int err);
288 NTSTATUS smb2_write_complete_nosync(struct tevent_req *req, ssize_t nwritten,
289 int err);
290 NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req);
291 NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req);
292 NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
293 NTSTATUS smbd_smb2_request_process_query_directory(struct smbd_smb2_request *req);
294 NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req);
295 NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req);
296 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req);
297 NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req);
298 NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req);
299 void smbd_smb2_request_dispatch_immediate(struct tevent_context *ctx,
300 struct tevent_immediate *im,
301 void *private_data);
303 struct deferred_open_record;
305 /* SMB1 -> SMB2 glue. */
306 void send_break_message_smb2(files_struct *fsp,
307 uint32_t break_from,
308 uint32_t break_to);
309 struct blocking_lock_record *get_pending_smb2req_blr(struct smbd_smb2_request *smb2req);
310 bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
311 struct smb_request *req,
312 files_struct *fsp,
313 int lock_timeout,
314 int lock_num,
315 uint64_t smblctx,
316 enum brl_type lock_type,
317 enum brl_flavour lock_flav,
318 uint64_t offset,
319 uint64_t count,
320 uint64_t blocking_smblctx);
321 void process_blocking_lock_queue_smb2(
322 struct smbd_server_connection *sconn, struct timeval tv_curr);
323 void cancel_pending_lock_requests_by_fid_smb2(files_struct *fsp,
324 struct byte_range_lock *br_lck,
325 enum file_close_type close_type);
326 /* From smbd/smb2_create.c */
327 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level);
328 bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
329 struct timeval *p_request_time,
330 struct deferred_open_record **open_rec);
331 bool open_was_deferred_smb2(
332 struct smbXsrv_connection *xconn, uint64_t mid);
333 void remove_deferred_open_message_smb2(
334 struct smbXsrv_connection *xconn, uint64_t mid);
335 bool schedule_deferred_open_message_smb2(
336 struct smbXsrv_connection *xconn, uint64_t mid);
337 bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
338 struct timeval request_time,
339 struct timeval timeout,
340 struct file_id id,
341 struct deferred_open_record *open_rec);
343 struct smbXsrv_client;
345 struct smbXsrv_preauth {
346 uint8_t sha512_value[64];
349 struct smbXsrv_connection {
350 struct smbXsrv_connection *prev, *next;
352 struct smbXsrv_client *client;
355 const struct tsocket_address *local_address;
356 const struct tsocket_address *remote_address;
357 const char *remote_hostname;
359 struct tevent_context *ev_ctx;
360 struct messaging_context *msg_ctx;
362 enum protocol_types protocol;
364 struct {
365 NTSTATUS status;
366 int sock;
367 struct tevent_fd *fde;
369 struct {
370 bool got_session;
371 } nbt;
372 } transport;
374 struct {
375 struct {
377 * fd for the fcntl lock and process shared
378 * robust mutex to coordinate access to the
379 * client socket. When the system supports
380 * process shared robust mutexes, those are
381 * used. If not, then the fcntl lock will be
382 * used.
384 int socket_lock_fd;
385 #ifdef HAVE_ROBUST_MUTEXES
386 pthread_mutex_t *socket_mutex;
387 #endif
390 * fd for the trusted pipe from
391 * echo handler child
393 int trusted_fd;
396 * fde for the trusted_fd
398 struct tevent_fd *trusted_fde;
401 * Reference count for the fcntl lock to
402 * allow recursive locks.
404 int ref_count;
405 } echo_handler;
407 struct {
408 bool encrypted_passwords;
409 bool spnego;
410 struct auth4_context *auth_context;
411 bool done;
413 * Size of the data we can receive. Set by us.
414 * Can be modified by the max xmit parameter.
416 int max_recv;
417 } negprot;
419 struct {
420 bool done_sesssetup;
422 * Size of data we can send to client. Set
423 * by the client for all protocols above CORE.
424 * Set by us for CORE protocol.
426 int max_send;
427 } sessions;
428 struct smb_signing_state *signing_state;
430 struct {
431 uint16_t client_major;
432 uint16_t client_minor;
433 uint32_t client_cap_low;
434 uint32_t client_cap_high;
435 } unix_info;
437 struct msg_state *msg_state;
438 } smb1;
439 struct {
440 struct smbd_smb2_request_read_state {
441 struct smbd_smb2_request *req;
442 struct {
443 uint8_t nbt[NBT_HDR_SIZE];
444 bool done;
445 } hdr;
446 struct iovec vector;
447 bool doing_receivefile;
448 size_t min_recv_size;
449 size_t pktfull;
450 size_t pktlen;
451 uint8_t *pktbuf;
452 } request_read_state;
453 struct smbd_smb2_send_queue *send_queue;
454 size_t send_queue_len;
456 struct {
458 * seq_low is the lowest sequence number
459 * we will accept.
461 uint64_t seq_low;
463 * seq_range is the range of credits we have
464 * granted from the sequence windows starting
465 * at seq_low.
467 * This gets incremented when new credits are
468 * granted and gets decremented when the
469 * lowest sequence number is consumed
470 * (when seq_low gets incremented).
472 uint16_t seq_range;
474 * The number of credits we have currently granted
475 * to the client.
477 * This gets incremented when new credits are
478 * granted and gets decremented when any credit
479 * is comsumed.
481 * Note: the decrementing is different compared
482 * to seq_range.
484 uint16_t granted;
486 * The maximum number of credits we will ever
487 * grant to the client.
489 * Typically we will only grant 1/16th of
490 * max_credits.
492 * This is the "server max credits" parameter.
494 uint16_t max;
496 * a bitmap of size max_credits
498 struct bitmap *bitmap;
499 bool multicredit;
500 } credits;
502 bool allow_2ff;
503 struct {
504 uint32_t capabilities;
505 struct GUID guid;
506 uint16_t security_mode;
507 uint16_t num_dialects;
508 uint16_t *dialects;
509 } client;
510 struct {
511 uint32_t capabilities;
512 struct GUID guid;
513 uint16_t security_mode;
514 uint16_t dialect;
515 uint32_t max_trans;
516 uint32_t max_read;
517 uint32_t max_write;
518 uint16_t cipher;
519 } server;
521 struct smbXsrv_preauth preauth;
523 struct smbd_smb2_request *requests;
524 } smb2;
527 const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
529 NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id);
530 uint32_t smbXsrv_version_global_current(void);
532 NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
533 enum protocol_types protocol);
535 NTSTATUS smbXsrv_session_global_init(void);
536 NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
537 NTTIME now,
538 struct smbXsrv_session **_session);
539 NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
540 struct smbXsrv_channel_global0;
541 NTSTATUS smbXsrv_session_find_channel(const struct smbXsrv_session *session,
542 const struct smbXsrv_connection *conn,
543 struct smbXsrv_channel_global0 **_c);
544 NTSTATUS smbXsrv_session_find_auth(const struct smbXsrv_session *session,
545 const struct smbXsrv_connection *conn,
546 NTTIME now,
547 struct smbXsrv_session_auth0 **_a);
548 struct tevent_req *smb2srv_session_shutdown_send(TALLOC_CTX *mem_ctx,
549 struct tevent_context *ev,
550 struct smbXsrv_session *session,
551 struct smbd_smb2_request *current_req);
552 NTSTATUS smb2srv_session_shutdown_recv(struct tevent_req *req);
553 NTSTATUS smbXsrv_session_logoff(struct smbXsrv_session *session);
554 NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_connection *conn);
555 NTSTATUS smb1srv_session_table_init(struct smbXsrv_connection *conn);
556 NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
557 uint16_t vuid, NTTIME now,
558 struct smbXsrv_session **session);
559 NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
560 NTSTATUS smb2srv_session_lookup_conn(struct smbXsrv_connection *conn,
561 uint64_t session_id, NTTIME now,
562 struct smbXsrv_session **session);
563 NTSTATUS smb2srv_session_lookup_client(struct smbXsrv_client *client,
564 uint64_t session_id, NTTIME now,
565 struct smbXsrv_session **session);
566 struct smbXsrv_session_global0;
567 NTSTATUS smbXsrv_session_global_traverse(
568 int (*fn)(struct smbXsrv_session_global0 *, void *),
569 void *private_data);
570 struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
571 struct tevent_context *ev,
572 struct smbXsrv_connection *conn,
573 struct auth_session_info *session_info,
574 uint64_t previous_session_id,
575 uint64_t current_session_id);
576 NTSTATUS smb2srv_session_close_previous_recv(struct tevent_req *req);
578 NTSTATUS smbXsrv_tcon_global_init(void);
579 NTSTATUS smbXsrv_tcon_update(struct smbXsrv_tcon *tcon);
580 NTSTATUS smbXsrv_tcon_disconnect(struct smbXsrv_tcon *tcon, uint64_t vuid);
581 NTSTATUS smb1srv_tcon_table_init(struct smbXsrv_connection *conn);
582 NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
583 NTTIME now,
584 struct smbXsrv_tcon **_tcon);
585 NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
586 uint16_t tree_id, NTTIME now,
587 struct smbXsrv_tcon **tcon);
588 NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_connection *conn);
589 NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session);
590 NTSTATUS smb2srv_tcon_create(struct smbXsrv_session *session,
591 NTTIME now,
592 struct smbXsrv_tcon **_tcon);
593 NTSTATUS smb2srv_tcon_lookup(struct smbXsrv_session *session,
594 uint32_t tree_id, NTTIME now,
595 struct smbXsrv_tcon **tcon);
596 NTSTATUS smb2srv_tcon_disconnect_all(struct smbXsrv_session *session);
597 struct smbXsrv_tcon_global0;
598 NTSTATUS smbXsrv_tcon_global_traverse(
599 int (*fn)(struct smbXsrv_tcon_global0 *, void *),
600 void *private_data);
602 NTSTATUS smbXsrv_open_global_init(void);
603 NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
604 struct auth_session_info *session_info,
605 NTTIME now,
606 struct smbXsrv_open **_open);
607 uint32_t smbXsrv_open_hash(struct smbXsrv_open *_open);
608 NTSTATUS smbXsrv_open_update(struct smbXsrv_open *_open);
609 NTSTATUS smbXsrv_open_close(struct smbXsrv_open *op, NTTIME now);
610 NTSTATUS smb1srv_open_table_init(struct smbXsrv_connection *conn);
611 NTSTATUS smb1srv_open_lookup(struct smbXsrv_connection *conn,
612 uint16_t fnum, NTTIME now,
613 struct smbXsrv_open **_open);
614 NTSTATUS smb2srv_open_table_init(struct smbXsrv_connection *conn);
615 NTSTATUS smb2srv_open_lookup(struct smbXsrv_connection *conn,
616 uint64_t persistent_id,
617 uint64_t volatile_id,
618 NTTIME now,
619 struct smbXsrv_open **_open);
620 NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
621 struct auth_session_info *session_info,
622 uint64_t persistent_id,
623 const struct GUID *create_guid,
624 NTTIME now,
625 struct smbXsrv_open **_open);
626 struct smbXsrv_open_global0;
627 NTSTATUS smbXsrv_open_global_traverse(
628 int (*fn)(struct smbXsrv_open_global0 *, void *),
629 void *private_data);
631 NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id);
633 struct smbd_smb2_send_queue {
634 struct smbd_smb2_send_queue *prev, *next;
636 DATA_BLOB *sendfile_header;
637 NTSTATUS *sendfile_status;
638 struct iovec *vector;
639 int count;
641 TALLOC_CTX *mem_ctx;
644 struct smbd_smb2_request {
645 struct smbd_smb2_request *prev, *next;
647 struct smbd_server_connection *sconn;
648 struct smbXsrv_connection *xconn;
650 struct smbd_smb2_send_queue queue_entry;
652 /* the session the request operates on, maybe NULL */
653 struct smbXsrv_session *session;
654 uint64_t last_session_id;
656 /* the tcon the request operates on, maybe NULL */
657 struct smbXsrv_tcon *tcon;
658 uint32_t last_tid;
660 int current_idx;
661 bool do_signing;
662 /* Was the request encrypted? */
663 bool was_encrypted;
664 /* Should we encrypt? */
665 bool do_encryption;
666 struct tevent_timer *async_te;
667 bool compound_related;
670 * the encryption key for the whole
671 * compound chain
673 DATA_BLOB first_key;
675 * the signing key for the last
676 * request/response of a compound chain
678 DATA_BLOB last_key;
679 struct smbXsrv_preauth *preauth;
681 struct timeval request_time;
683 SMBPROFILE_IOBYTES_ASYNC_STATE(profile);
685 /* fake smb1 request. */
686 struct smb_request *smb1req;
687 struct files_struct *compat_chain_fsp;
690 * The sub request for async backend calls.
691 * This is used for SMB2 Cancel.
693 struct tevent_req *subreq;
695 #define SMBD_SMB2_TF_IOV_OFS 0
696 #define SMBD_SMB2_HDR_IOV_OFS 1
697 #define SMBD_SMB2_BODY_IOV_OFS 2
698 #define SMBD_SMB2_DYN_IOV_OFS 3
700 #define SMBD_SMB2_NUM_IOV_PER_REQ 4
702 #define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
703 (&req->dir.vector[(idx)+(ofs)])
705 #define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
706 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
707 #define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
708 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_HDR_IOV_OFS)
709 #define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
710 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_BODY_IOV_OFS)
711 #define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
712 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_DYN_IOV_OFS)
714 #define SMBD_SMB2_IN_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
715 #define SMBD_SMB2_IN_TF_PTR(req) (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
716 #define SMBD_SMB2_IN_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
717 #define SMBD_SMB2_IN_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
718 #define SMBD_SMB2_IN_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
719 #define SMBD_SMB2_IN_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
720 #define SMBD_SMB2_IN_BODY_LEN(req) (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
721 #define SMBD_SMB2_IN_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
722 #define SMBD_SMB2_IN_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
723 #define SMBD_SMB2_IN_DYN_LEN(req) (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
725 #define SMBD_SMB2_OUT_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
726 #define SMBD_SMB2_OUT_TF_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
727 #define SMBD_SMB2_OUT_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
728 #define SMBD_SMB2_OUT_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
729 #define SMBD_SMB2_OUT_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
730 #define SMBD_SMB2_OUT_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
731 #define SMBD_SMB2_OUT_BODY_LEN(req) (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
732 #define SMBD_SMB2_OUT_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
733 #define SMBD_SMB2_OUT_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
734 #define SMBD_SMB2_OUT_DYN_LEN(req) (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
736 #define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
738 struct {
740 * vector[0] TRANSPORT HEADER (empty)
742 * vector[1] SMB2_TRANSFORM (optional)
743 * vector[2] SMB2
744 * vector[3] fixed body
745 * vector[4] dynamic body
749 * vector[5] SMB2_TRANSFORM (optional)
750 * vector[6] SMB2
751 * vector[7] fixed body
752 * vector[8] dynamic body
757 struct iovec *vector;
758 int vector_count;
759 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
760 } in;
761 struct {
762 /* the NBT header is not allocated */
763 uint8_t nbt_hdr[4];
765 * vector[0] TRANSPORT HEADER
767 * vector[1] SMB2_TRANSFORM (optional)
768 * vector[2] SMB2
769 * vector[3] fixed body
770 * vector[4] dynamic body
774 * vector[5] SMB2_TRANSFORM (empty)
775 * vector[6] SMB2
776 * vector[7] fixed body
777 * vector[8] dynamic body
782 struct iovec *vector;
783 int vector_count;
784 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
785 #define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
786 uint8_t _hdr[OUTVEC_ALLOC_SIZE];
787 uint8_t _body[0x58];
788 } out;
791 struct smbd_server_connection;
792 struct user_struct;
794 struct pending_message_list;
795 struct pending_auth_data;
797 struct user_struct {
798 struct user_struct *next, *prev;
799 uint64_t vuid; /* Tag for this entry. */
801 char *session_keystr; /* used by utmp and pam session code.
802 TDB key string */
803 int homes_snum;
805 struct auth_session_info *session_info;
807 struct smbXsrv_session *session;
810 struct smbd_server_connection {
811 const struct tsocket_address *local_address;
812 const struct tsocket_address *remote_address;
813 const char *remote_hostname;
814 struct tevent_context *ev_ctx;
815 struct messaging_context *msg_ctx;
816 struct sys_notify_context *sys_notify_ctx;
817 struct notify_context *notify_ctx;
818 bool using_smb2;
819 int trans_num;
821 size_t num_users;
822 struct user_struct *users;
824 size_t num_connections;
825 struct connection_struct *connections;
827 size_t num_files;
828 struct files_struct *files;
830 int real_max_open_files;
831 struct fsp_singleton_cache fsp_fi_cache;
833 struct pending_message_list *deferred_open_queue;
836 /* open directory handles. */
837 struct {
838 struct bitmap *dptr_bmap;
839 struct dptr_struct *dirptrs;
840 int dirhandles_open;
841 } searches;
843 uint64_t num_requests;
845 /* Current number of oplocks we have outstanding. */
846 struct {
847 int32_t exclusive_open;
848 int32_t level_II_open;
849 struct kernel_oplocks *kernel_ops;
850 } oplocks;
852 struct {
853 struct notify_mid_map *notify_mid_maps;
855 struct {
856 /* dlink list we store pending lock records on. */
857 struct blocking_lock_record *blocking_lock_queue;
858 /* dlink list we move cancelled lock records onto. */
859 struct blocking_lock_record *blocking_lock_cancelled_queue;
861 /* The event that makes us process our blocking lock queue */
862 struct tevent_timer *brl_timeout;
864 bool blocking_lock_unlock_state;
865 bool blocking_lock_cancel_state;
866 } locks;
867 } smb1;
868 struct {
869 struct {
870 /* The event that makes us process our blocking lock queue */
871 struct tevent_timer *brl_timeout;
872 bool blocking_lock_unlock_state;
873 } locks;
874 } smb2;
877 * Link into libasys for asynchronous operations
879 struct asys_context *asys_ctx;
880 struct tevent_fd *asys_fde;
882 struct smbXsrv_client *client;
885 extern struct smbXsrv_client *global_smbXsrv_client;
887 void smbd_init_globals(void);