s3:smbd: implement SMB2 Tree Disconnect
[ira/wip.git] / source3 / smbd / globals.h
index 178263ba2ce487a5bd292d3e784db9ddac3df1c7..9d5eead93976dbfefc9cd55ad9e8c1cc5d2aedcd 100644 (file)
 #if defined(WITH_AIO)
 struct aio_extra;
 extern struct aio_extra *aio_list_head;
+extern struct tevent_signal *aio_signal_event;
 extern int aio_pending_size;
-extern sig_atomic_t aio_signals_received;
 extern int outstanding_aio_calls;
-extern uint16_t *aio_pending_array;
 #endif
 
 /* dlink list we store pending lock records on. */
@@ -124,8 +123,6 @@ extern int max_send;
  * Can be modified by the max xmit parameter.
  */
 extern int max_recv;
-extern SIG_ATOMIC_T reload_after_sighup;
-extern SIG_ATOMIC_T got_sig_term;
 extern uint16 last_session_tag;
 extern int trans_num;
 extern char *orig_inbuf;
@@ -184,29 +181,15 @@ extern struct vfs_init_function_entry *backends;
 extern char *sparse_buf;
 extern char *LastDir;
 
-#if HAVE_KERNEL_OPLOCKS_LINUX
-extern SIG_ATOMIC_T oplock_signals_received;
-#define FD_PENDING_SIZE 100
-extern SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE];
-extern struct kernel_oplocks linux_koplocks;
-#endif
-
-#if HAVE_KERNEL_OPLOCKS_IRIX
-extern int oplock_pipe_write;
-extern int oplock_pipe_read;
-extern struct kernel_oplocks irix_koplocks;
-#endif
-
 /* Current number of oplocks we have outstanding. */
 extern int32_t exclusive_oplocks_open;
 extern int32_t level_II_oplocks_open;
 extern bool global_client_failed_oplock_break;
-extern const struct kernel_oplocks *koplocks;
+extern struct kernel_oplocks *koplocks;
 
 extern struct notify_mid_map *notify_changes_by_mid;
 
 extern int am_parent;
-extern SIG_ATOMIC_T got_sig_cld;
 extern int server_fd;
 extern struct event_context *smbd_event_ctx;
 extern struct messaging_context *smbd_msg_ctx;
@@ -216,4 +199,149 @@ struct child_pid;
 extern struct child_pid *children;
 extern int num_children;
 
+struct tstream_context;
+struct smbd_smb2_request;
+struct smbd_smb2_session;
+struct smbd_smb2_tcon;
+
+DATA_BLOB negprot_spnego(void);
+
+bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
+
+void reply_smb2002(struct smb_request *req, uint16_t choice);
+void smbd_smb2_first_negprot(struct smbd_server_connection *conn,
+                            const uint8_t *inbuf, size_t size);
+
+NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
+                                   NTSTATUS status, DATA_BLOB *info);
+NTSTATUS smbd_smb2_request_error(struct smbd_smb2_request *req,
+                                NTSTATUS status);
+NTSTATUS smbd_smb2_request_done_ex(struct smbd_smb2_request *req,
+                                  NTSTATUS status,
+                                  DATA_BLOB body, DATA_BLOB *dyn);
+NTSTATUS smbd_smb2_request_done(struct smbd_smb2_request *req,
+                               DATA_BLOB body, DATA_BLOB *dyn);
+
+NTSTATUS smbd_smb2_request_check_session(struct smbd_smb2_request *req);
+NTSTATUS smbd_smb2_request_check_tcon(struct smbd_smb2_request *req);
+
+NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
+NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
+NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req);
+NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req);
+NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req);
+NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
+
+struct smbd_smb2_request {
+       TALLOC_CTX *mem_pool;
+
+       struct smbd_server_connection *conn;
+
+       /* the session the request operates on, maybe NULL */
+       struct smbd_smb2_session *session;
+
+       /* the tcon the request operates on, maybe NULL */
+       struct smbd_smb2_tcon *tcon;
+
+       int current_idx;
+
+       struct {
+               /* the NBT header is not allocated */
+               uint8_t nbt_hdr[4];
+               /*
+                * vector[0] NBT
+                * .
+                * vector[1] SMB2
+                * vector[2] fixed body
+                * vector[3] dynamic body
+                * .
+                * .
+                * .
+                * vector[4] SMB2
+                * vector[5] fixed body
+                * vector[6] dynamic body
+                * .
+                * .
+                * .
+                */
+               struct iovec *vector;
+               int vector_count;
+       } in;
+       struct {
+               /* the NBT header is not allocated */
+               uint8_t nbt_hdr[4];
+               /*
+                * vector[0] NBT
+                * .
+                * vector[1] SMB2
+                * vector[2] fixed body
+                * vector[3] dynamic body
+                * .
+                * .
+                * .
+                * vector[4] SMB2
+                * vector[5] fixed body
+                * vector[6] dynamic body
+                * .
+                * .
+                * .
+                */
+               struct iovec *vector;
+               int vector_count;
+       } out;
+};
+
+struct smbd_server_connection;
+
+struct smbd_smb2_session {
+       struct smbd_smb2_session *prev, *next;
+       struct smbd_server_connection *conn;
+       NTSTATUS status;
+       uint64_t vuid;
+       AUTH_NTLMSSP_STATE *auth_ntlmssp_state;
+
+       struct {
+               /* an id tree used to allocate tids */
+               struct idr_context *idtree;
+
+               /* this is the limit of tid values for this connection */
+               uint32_t limit;
+
+               struct smbd_smb2_tcon *list;
+       } tcons;
+};
+
+struct smbd_smb2_tcon {
+       struct smbd_smb2_tcon *prev, *next;
+       struct smbd_smb2_session *session;
+       uint32_t tid;
+       int snum;
+};
+
+struct smbd_server_connection {
+       struct fd_event *fde;
+       uint64_t num_requests;
+       struct smb_signing_state *signing_state;
+       bool allow_smb2;
+       struct {
+               struct tevent_context *event_ctx;
+               struct tevent_queue *recv_queue;
+               struct tevent_queue *send_queue;
+               struct tstream_context *stream;
+               struct {
+                       /* an id tree used to allocate vuids */
+                       /* this holds info on session vuids that are already
+                        * validated for this VC */
+                       struct idr_context *idtree;
+
+                       /* this is the limit of vuid values for this connection */
+                       uint64_t limit;
+
+                       struct smbd_smb2_session *list;
+               } sessions;
+       } smb2;
+};
+
+extern struct smbd_server_connection *smbd_server_conn;
+
 void smbd_init_globals(void);