s4:auth: Set ‘authoritative’ even if there is an error
[Samba.git] / source3 / smbd / globals.h
blob96dee78119fd5c2cd8ce5bea62be56fc0108ac84
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 void smbd_dirptr_push_overflow(struct dptr_struct *dirptr,
186 char **_fname,
187 struct smb_filename **_smb_fname,
188 uint32_t mode);
189 void smbd_dirptr_set_last_name_sent(struct dptr_struct *dirptr,
190 char **_fname);
191 char *smbd_dirptr_get_last_name_sent(struct dptr_struct *dirptr);
193 NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
194 connection_struct *conn,
195 struct dptr_struct *dirptr,
196 uint16_t flags2,
197 const char *path_mask,
198 uint32_t dirtype,
199 int info_level,
200 int requires_resume_key,
201 bool dont_descend,
202 bool ask_sharemode,
203 bool get_dosmode,
204 uint8_t align,
205 bool do_pad,
206 char **ppdata,
207 char *base_data,
208 char *end_data,
209 int space_remaining,
210 struct smb_filename **smb_fname,
211 int *_last_entry_off,
212 struct ea_list *name_list,
213 struct file_id *file_id);
215 NTSTATUS smbd_calculate_access_mask_fsp(struct files_struct *dirsfp,
216 struct files_struct *fsp,
217 bool use_privs,
218 uint32_t access_mask,
219 uint32_t *access_mask_out);
221 void smbd_notify_cancel_by_smbreq(const struct smb_request *smbreq);
223 void smbXsrv_connection_disconnect_transport(struct smbXsrv_connection *xconn,
224 NTSTATUS status);
225 size_t smbXsrv_client_valid_connections(struct smbXsrv_client *client);
226 void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
227 const char *reason,
228 const char *location);
229 #define smbd_server_connection_terminate(xconn, reason) \
230 smbd_server_connection_terminate_ex(xconn, reason, __location__)
232 void smbd_server_disconnect_client_ex(struct smbXsrv_client *client,
233 const char *reason,
234 const char *location);
235 #define smbd_server_disconnect_client(__client, __reason) \
236 smbd_server_disconnect_client_ex(__client, __reason, __location__)
238 const char *smb2_opcode_name(uint16_t opcode);
239 bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
240 bool smbd_smb2_is_compound(const struct smbd_smb2_request *req);
241 bool smbd_smb2_is_last_in_compound(const struct smbd_smb2_request *req);
243 NTSTATUS smbd_add_connection(struct smbXsrv_client *client, int sock_fd,
244 NTTIME now, struct smbXsrv_connection **_xconn);
246 NTSTATUS reply_smb2002(struct smb_request *req, uint16_t choice);
247 NTSTATUS reply_smb20ff(struct smb_request *req, uint16_t choice);
248 NTSTATUS smbd_smb2_process_negprot(struct smbXsrv_connection *xconn,
249 uint64_t expected_seq_low,
250 const uint8_t *inpdu, size_t size);
251 NTSTATUS smb2_multi_protocol_reply_negprot(struct smb_request *req);
253 DATA_BLOB smbd_smb2_generate_outbody(struct smbd_smb2_request *req, size_t size);
255 bool smbXsrv_server_multi_channel_enabled(void);
257 NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
258 NTSTATUS status,
259 uint8_t error_context_count,
260 DATA_BLOB *info,
261 const char *location);
262 #define smbd_smb2_request_error(req, status) \
263 smbd_smb2_request_error_ex(req, status, 0, NULL, __location__)
264 NTSTATUS smbd_smb2_request_done_ex(struct smbd_smb2_request *req,
265 NTSTATUS status,
266 DATA_BLOB body, DATA_BLOB *dyn,
267 const char *location);
268 #define smbd_smb2_request_done(req, body, dyn) \
269 smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
271 NTSTATUS smbd_smb2_send_oplock_break(struct smbXsrv_client *client,
272 struct smbXsrv_open *op,
273 uint8_t oplock_level);
274 NTSTATUS smbd_smb2_send_lease_break(struct smbXsrv_client *client,
275 uint16_t new_epoch,
276 uint32_t lease_flags,
277 struct smb2_lease_key *lease_key,
278 uint32_t current_lease_state,
279 uint32_t new_lease_state);
281 NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
282 struct tevent_req *subreq,
283 uint32_t defer_time);
285 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req,
286 struct files_struct *fsp);
287 size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req);
288 void remove_smb2_chained_fsp(files_struct *fsp);
290 NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req,
291 uint32_t data_length);
293 NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
294 size_t expected_body_size);
296 void smb2_request_set_async_internal(struct smbd_smb2_request *req,
297 bool async_internal);
299 enum protocol_types smbd_smb2_protocol_dialect_match(const uint8_t *indyn,
300 const int dialect_count,
301 uint16_t *dialect);
302 NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
303 NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
304 NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req);
305 NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req);
306 NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req);
307 NTSTATUS smbd_smb2_request_process_create(struct smbd_smb2_request *req);
308 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req);
309 NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req);
310 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req);
311 NTSTATUS smb2_read_complete(struct tevent_req *req, ssize_t nread, int err);
312 NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req);
313 NTSTATUS smb2_write_complete(struct tevent_req *req, ssize_t nwritten, int err);
314 NTSTATUS smb2_write_complete_nosync(struct tevent_req *req, ssize_t nwritten,
315 int err);
316 NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req);
317 NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req);
318 NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
319 NTSTATUS smbd_smb2_request_process_query_directory(struct smbd_smb2_request *req);
320 NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req);
321 NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req);
322 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req);
323 NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req);
324 NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req);
325 void smbd_smb2_request_dispatch_immediate(struct tevent_context *ctx,
326 struct tevent_immediate *im,
327 void *private_data);
329 struct deferred_open_record;
331 /* SMB1 -> SMB2 glue. */
332 void send_break_message_smb2(files_struct *fsp,
333 uint32_t break_from,
334 uint32_t break_to);
335 /* From smbd/smb2_create.c */
336 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level);
337 bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
338 struct timeval *p_request_time,
339 struct deferred_open_record **open_rec);
340 bool open_was_deferred_smb2(
341 struct smbXsrv_connection *xconn, uint64_t mid);
342 void remove_deferred_open_message_smb2(
343 struct smbXsrv_connection *xconn, uint64_t mid);
344 bool schedule_deferred_open_message_smb2(
345 struct smbXsrv_connection *xconn, uint64_t mid);
346 bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
347 struct timeval request_time,
348 struct timeval timeout,
349 struct file_id id,
350 struct deferred_open_record *open_rec);
352 struct smbXsrv_client;
354 struct smbXsrv_preauth {
355 uint8_t sha512_value[64];
358 struct smbXsrv_connection {
359 struct smbXsrv_connection *prev, *next;
361 struct smbXsrv_client *client;
363 NTTIME connect_time;
364 uint64_t channel_id;
365 const struct tsocket_address *local_address;
366 const struct tsocket_address *remote_address;
367 const char *remote_hostname;
368 bool has_cluster_movable_ip;
370 enum protocol_types protocol;
372 struct {
373 NTSTATUS status;
374 bool terminating;
375 struct tevent_queue *shutdown_wait_queue;
376 int sock;
377 struct tevent_fd *fde;
379 struct {
380 bool got_session;
381 } nbt;
382 } transport;
384 struct {
385 bool force_unacked_timeout;
386 uint64_t unacked_bytes;
387 uint32_t rto_usecs;
388 struct tevent_req *checker_subreq;
389 struct smbd_smb2_send_queue *queue;
390 } ack;
392 #if defined(WITH_SMB1SERVER)
393 struct {
394 struct {
396 * fd for the fcntl lock and process shared
397 * robust mutex to coordinate access to the
398 * client socket. When the system supports
399 * process shared robust mutexes, those are
400 * used. If not, then the fcntl lock will be
401 * used.
403 int socket_lock_fd;
404 #ifdef HAVE_ROBUST_MUTEXES
405 pthread_mutex_t *socket_mutex;
406 #endif
409 * fd for the trusted pipe from
410 * echo handler child
412 int trusted_fd;
415 * fde for the trusted_fd
417 struct tevent_fd *trusted_fde;
420 * Reference count for the fcntl lock to
421 * allow recursive locks.
423 int ref_count;
424 } echo_handler;
426 struct {
427 bool encrypted_passwords;
428 bool spnego;
429 struct auth4_context *auth_context;
430 bool done;
432 * Size of the data we can receive. Set by us.
433 * Can be modified by the max xmit parameter.
435 int max_recv;
436 } negprot;
438 struct {
439 bool done_sesssetup;
441 * Size of data we can send to client. Set
442 * by the client for all protocols above CORE.
443 * Set by us for CORE protocol.
445 int max_send;
446 } sessions;
447 struct smb1_signing_state *signing_state;
449 struct {
450 uint16_t client_major;
451 uint16_t client_minor;
452 uint32_t client_cap_low;
453 uint32_t client_cap_high;
454 } unix_info;
456 struct msg_state *msg_state;
457 } smb1;
458 #endif
459 struct {
460 struct smbd_smb2_request_read_state {
461 struct smbd_smb2_request *req;
462 struct {
463 uint8_t nbt[NBT_HDR_SIZE];
464 bool done;
465 } hdr;
466 struct iovec vector;
467 bool doing_receivefile;
468 size_t min_recv_size;
469 size_t pktfull;
470 size_t pktlen;
471 uint8_t *pktbuf;
472 } request_read_state;
473 struct smbd_smb2_send_queue *send_queue;
474 size_t send_queue_len;
476 struct {
478 * seq_low is the lowest sequence number
479 * we will accept.
481 uint64_t seq_low;
483 * seq_range is the range of credits we have
484 * granted from the sequence windows starting
485 * at seq_low.
487 * This gets incremented when new credits are
488 * granted and gets decremented when the
489 * lowest sequence number is consumed
490 * (when seq_low gets incremented).
492 uint16_t seq_range;
494 * The number of credits we have currently granted
495 * to the client.
497 * This gets incremented when new credits are
498 * granted and gets decremented when any credit
499 * is comsumed.
501 * Note: the decrementing is different compared
502 * to seq_range.
504 uint16_t granted;
506 * The maximum number of credits we will ever
507 * grant to the client.
509 * Typically we will only grant 1/16th of
510 * max_credits.
512 * This is the "server max credits" parameter.
514 uint16_t max;
516 * a bitmap of size max_credits
518 struct bitmap *bitmap;
519 bool multicredit;
520 } credits;
522 bool allow_2ff;
523 struct {
524 uint32_t capabilities;
525 struct GUID guid;
526 bool guid_verified;
527 uint16_t security_mode;
528 uint16_t num_dialects;
529 uint16_t *dialects;
530 } client;
531 struct {
532 uint32_t capabilities;
533 struct GUID guid;
534 uint16_t security_mode;
535 uint16_t dialect;
536 uint32_t max_trans;
537 uint32_t max_read;
538 uint32_t max_write;
539 uint16_t sign_algo;
540 uint16_t cipher;
541 bool posix_extensions_negotiated;
542 } server;
544 struct smbXsrv_preauth preauth;
546 struct smbd_smb2_request *requests;
548 struct {
549 uint8_t read_body_padding;
550 } smbtorture;
552 bool signing_mandatory;
553 } smb2;
556 const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
558 NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id);
559 uint32_t smbXsrv_version_global_current(void);
561 struct smbXsrv_client_table;
562 NTSTATUS smbXsrv_client_global_init(void);
563 NTSTATUS smbXsrv_client_create(TALLOC_CTX *mem_ctx,
564 struct tevent_context *ev_ctx,
565 struct messaging_context *msg_ctx,
566 NTTIME now,
567 struct smbXsrv_client **_client);
568 NTSTATUS smbXsrv_client_remove(struct smbXsrv_client *client);
569 struct tevent_req *smb2srv_client_mc_negprot_send(TALLOC_CTX *mem_ctx,
570 struct tevent_context *ev,
571 struct smbd_smb2_request *smb2req);
572 NTSTATUS smb2srv_client_mc_negprot_recv(struct tevent_req *req);
574 NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
575 enum protocol_types protocol);
577 NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx);
578 NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
579 NTTIME now,
580 struct smbXsrv_session **_session);
581 NTSTATUS smbXsrv_session_add_channel(struct smbXsrv_session *session,
582 struct smbXsrv_connection *conn,
583 NTTIME now,
584 struct smbXsrv_channel_global0 **_c);
585 NTSTATUS smbXsrv_session_remove_channel(struct smbXsrv_session *session,
586 struct smbXsrv_connection *xconn);
587 NTSTATUS smbXsrv_session_disconnect_xconn(struct smbXsrv_connection *xconn);
588 NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
589 struct smbXsrv_channel_global0;
590 NTSTATUS smbXsrv_session_find_channel(const struct smbXsrv_session *session,
591 const struct smbXsrv_connection *conn,
592 struct smbXsrv_channel_global0 **_c);
593 NTSTATUS smbXsrv_session_find_auth(const struct smbXsrv_session *session,
594 const struct smbXsrv_connection *conn,
595 NTTIME now,
596 struct smbXsrv_session_auth0 **_a);
597 NTSTATUS smbXsrv_session_create_auth(struct smbXsrv_session *session,
598 struct smbXsrv_connection *conn,
599 NTTIME now,
600 uint8_t in_flags,
601 uint8_t in_security_mode,
602 struct smbXsrv_session_auth0 **_a);
603 struct tevent_req *smb2srv_session_shutdown_send(TALLOC_CTX *mem_ctx,
604 struct tevent_context *ev,
605 struct smbXsrv_session *session,
606 struct smbd_smb2_request *current_req);
607 NTSTATUS smb2srv_session_shutdown_recv(struct tevent_req *req);
608 NTSTATUS smbXsrv_session_logoff(struct smbXsrv_session *session);
609 NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_client *client);
610 NTSTATUS smb1srv_session_table_init(struct smbXsrv_connection *conn);
611 NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
612 uint16_t vuid, NTTIME now,
613 struct smbXsrv_session **session);
614 NTSTATUS smbXsrv_session_info_lookup(struct smbXsrv_client *client,
615 uint64_t session_wire_id,
616 struct auth_session_info **si);
617 NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
618 NTSTATUS smb2srv_session_lookup_conn(struct smbXsrv_connection *conn,
619 uint64_t session_id, NTTIME now,
620 struct smbXsrv_session **session);
621 NTSTATUS smb2srv_session_lookup_client(struct smbXsrv_client *client,
622 uint64_t session_id, NTTIME now,
623 struct smbXsrv_session **session);
624 NTSTATUS smb2srv_session_lookup_global(struct smbXsrv_client *client,
625 uint64_t session_wire_id,
626 TALLOC_CTX *mem_ctx,
627 struct smbXsrv_session **session);
628 NTSTATUS get_valid_smbXsrv_session(struct smbXsrv_client *client,
629 uint64_t session_wire_id,
630 struct smbXsrv_session **session);
631 NTSTATUS smbXsrv_session_local_traverse(
632 struct smbXsrv_client *client,
633 int (*caller_cb)(struct smbXsrv_session *session,
634 void *caller_data),
635 void *caller_data);
636 struct smbXsrv_session_global0;
637 NTSTATUS smbXsrv_session_global_traverse(
638 int (*fn)(struct smbXsrv_session_global0 *, void *),
639 void *private_data);
640 struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
641 struct tevent_context *ev,
642 struct smbXsrv_connection *conn,
643 struct auth_session_info *session_info,
644 uint64_t previous_session_id,
645 uint64_t current_session_id);
646 NTSTATUS smb2srv_session_close_previous_recv(struct tevent_req *req);
648 NTSTATUS smbXsrv_tcon_global_init(void);
649 NTSTATUS smbXsrv_tcon_update(struct smbXsrv_tcon *tcon);
650 NTSTATUS smbXsrv_tcon_disconnect(struct smbXsrv_tcon *tcon, uint64_t vuid);
651 NTSTATUS smb1srv_tcon_table_init(struct smbXsrv_connection *conn);
652 NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
653 uint32_t session_global_id,
654 const char *share_name,
655 NTTIME now,
656 struct smbXsrv_tcon **_tcon);
657 NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
658 uint16_t tree_id, NTTIME now,
659 struct smbXsrv_tcon **tcon);
660 NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_client *client);
661 NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session);
662 NTSTATUS smb2srv_tcon_create(struct smbXsrv_session *session,
663 uint32_t session_global_id,
664 uint8_t encryption_flags,
665 const char *share_name,
666 NTTIME now,
667 struct smbXsrv_tcon **_tcon);
668 NTSTATUS smb2srv_tcon_lookup(struct smbXsrv_session *session,
669 uint32_t tree_id, NTTIME now,
670 struct smbXsrv_tcon **tcon);
671 NTSTATUS smb2srv_tcon_disconnect_all(struct smbXsrv_session *session);
672 struct smbXsrv_tcon_global0;
673 NTSTATUS smbXsrv_tcon_global_traverse(
674 int (*fn)(struct smbXsrv_tcon_global0 *, void *),
675 void *private_data);
678 bool smbXsrv_is_encrypted(uint8_t encryption_flags);
679 bool smbXsrv_is_partially_encrypted(uint8_t encryption_flags);
680 bool smbXsrv_set_crypto_flag(uint8_t *flags, uint8_t flag);
681 bool smbXsrv_is_signed(uint8_t signing_flags);
682 bool smbXsrv_is_partially_signed(uint8_t signing_flags);
684 struct smbd_smb2_send_queue {
685 struct smbd_smb2_send_queue *prev, *next;
687 DATA_BLOB *sendfile_header;
688 uint32_t sendfile_body_size;
689 NTSTATUS *sendfile_status;
690 struct iovec *vector;
691 int count;
693 struct {
694 struct tevent_req *req;
695 struct timeval timeout;
696 uint64_t required_acked_bytes;
697 } ack;
699 TALLOC_CTX *mem_ctx;
702 struct smbd_smb2_request {
703 struct smbd_smb2_request *prev, *next;
705 struct smbd_server_connection *sconn;
706 struct smbXsrv_connection *xconn;
708 struct smbd_smb2_send_queue queue_entry;
710 /* the session the request operates on, maybe NULL */
711 struct smbXsrv_session *session;
712 uint64_t last_session_id;
714 /* the tcon the request operates on, maybe NULL */
715 struct smbXsrv_tcon *tcon;
716 uint32_t last_tid;
718 int current_idx;
719 bool do_signing;
720 /* Was the request encrypted? */
721 bool was_encrypted;
722 /* Should we encrypt? */
723 bool do_encryption;
724 struct tevent_timer *async_te;
725 bool compound_related;
726 NTSTATUS compound_create_err;
729 * Give the implementation of an SMB2 req a way to tell the SMB2 request
730 * processing engine that the internal request is going async, while
731 * preserving synchronous SMB2 behaviour.
733 bool async_internal;
736 * the encryption key for the whole
737 * compound chain
739 struct smb2_signing_key *first_enc_key;
741 * the signing key for the last
742 * request/response of a compound chain
744 struct smb2_signing_key *last_sign_key;
745 struct smbXsrv_preauth *preauth;
747 struct timeval request_time;
749 SMBPROFILE_IOBYTES_ASYNC_STATE(profile);
751 /* fake smb1 request. */
752 struct smb_request *smb1req;
753 struct files_struct *compat_chain_fsp;
756 * Keep track of whether the outstanding request counters
757 * had been updated in dispatch, so that they need to be
758 * adapted again in reply.
760 bool request_counters_updated;
761 uint64_t channel_generation;
764 * The sub request for async backend calls.
765 * This is used for SMB2 Cancel.
767 struct tevent_req *subreq;
769 #define SMBD_SMB2_TF_IOV_OFS 0
770 #define SMBD_SMB2_HDR_IOV_OFS 1
771 #define SMBD_SMB2_BODY_IOV_OFS 2
772 #define SMBD_SMB2_DYN_IOV_OFS 3
774 #define SMBD_SMB2_NUM_IOV_PER_REQ 4
776 #define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
777 (&req->dir.vector[(idx)+(ofs)])
779 #define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
780 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
781 #define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
782 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_HDR_IOV_OFS)
783 #define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
784 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_BODY_IOV_OFS)
785 #define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
786 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_DYN_IOV_OFS)
788 #define SMBD_SMB2_IN_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
789 #define SMBD_SMB2_IN_TF_PTR(req) (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
790 #define SMBD_SMB2_IN_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
791 #define SMBD_SMB2_IN_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
792 #define SMBD_SMB2_IN_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
793 #define SMBD_SMB2_IN_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
794 #define SMBD_SMB2_IN_BODY_LEN(req) (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
795 #define SMBD_SMB2_IN_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
796 #define SMBD_SMB2_IN_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
797 #define SMBD_SMB2_IN_DYN_LEN(req) (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
799 #define SMBD_SMB2_OUT_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
800 #define SMBD_SMB2_OUT_TF_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
801 #define SMBD_SMB2_OUT_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
802 #define SMBD_SMB2_OUT_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
803 #define SMBD_SMB2_OUT_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
804 #define SMBD_SMB2_OUT_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
805 #define SMBD_SMB2_OUT_BODY_LEN(req) (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
806 #define SMBD_SMB2_OUT_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
807 #define SMBD_SMB2_OUT_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
808 #define SMBD_SMB2_OUT_DYN_LEN(req) (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
810 #define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
812 struct {
814 * vector[0] TRANSPORT HEADER (empty)
816 * vector[1] SMB2_TRANSFORM (optional)
817 * vector[2] SMB2
818 * vector[3] fixed body
819 * vector[4] dynamic body
823 * vector[5] SMB2_TRANSFORM (optional)
824 * vector[6] SMB2
825 * vector[7] fixed body
826 * vector[8] dynamic body
831 struct iovec *vector;
832 int vector_count;
833 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
834 } in;
835 struct {
836 /* the NBT header is not allocated */
837 uint8_t nbt_hdr[4];
839 * vector[0] TRANSPORT HEADER
841 * vector[1] SMB2_TRANSFORM (optional)
842 * vector[2] SMB2
843 * vector[3] fixed body
844 * vector[4] dynamic body
848 * vector[5] SMB2_TRANSFORM (empty)
849 * vector[6] SMB2
850 * vector[7] fixed body
851 * vector[8] dynamic body
856 struct iovec *vector;
857 int vector_count;
858 struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
859 #define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
860 uint8_t _hdr[OUTVEC_ALLOC_SIZE];
861 uint8_t _body[0x58];
862 } out;
865 struct smbd_server_connection;
867 struct pending_message_list;
868 struct pending_auth_data;
870 struct pthreadpool_tevent;
871 struct dcesrv_context;
873 struct smbd_server_connection {
874 const struct tsocket_address *local_address;
875 const struct tsocket_address *remote_address;
876 const char *remote_hostname;
877 struct tevent_context *ev_ctx;
878 struct messaging_context *msg_ctx;
879 struct dcesrv_context *dce_ctx;
880 struct notify_context *notify_ctx;
881 bool using_smb2;
882 int trans_num;
884 size_t num_users;
886 size_t num_connections;
887 struct connection_struct *connections;
889 size_t num_files;
890 struct files_struct *files;
892 int real_max_open_files;
893 struct fsp_singleton_cache fsp_fi_cache;
895 struct pending_message_list *deferred_open_queue;
898 /* open directory handles. */
899 struct {
900 struct bitmap *dptr_bmap;
901 struct dptr_struct *dirptrs;
902 } searches;
904 uint64_t num_requests;
906 /* Current number of oplocks we have outstanding. */
907 struct {
908 int32_t exclusive_open;
909 int32_t level_II_open;
910 struct kernel_oplocks *kernel_ops;
911 } oplocks;
913 struct notify_mid_map *notify_mid_maps;
915 struct pthreadpool_tevent *pool;
917 struct smbXsrv_client *client;
920 extern struct smbXsrv_client *global_smbXsrv_client;
922 void smbd_init_globals(void);
924 /****************************************************************************
925 The buffer we keep around whilst an aio request is in process.
926 *****************************************************************************/
928 struct aio_extra {
929 files_struct *fsp;
930 struct smb_request *smbreq;
931 DATA_BLOB outbuf;
932 struct lock_struct lock;
933 size_t nbyte;
934 off_t offset;
935 bool write_through;
938 #endif /* _SOURCE3_SMBD_GLOBALS_H_ */