smbd: qfilepathinfo has fixed/variable buffers
[samba.git] / source3 / smbd / globals.h
index 1a87238d1d26e6e4fc89b148995ac3d07df98e9a..7fbe608744076e6f87aed6e9eed59baa3935117d 100644 (file)
@@ -18,6 +18,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "system/select.h"
+
 #if defined(WITH_AIO)
 struct aio_extra;
 extern struct aio_extra *aio_list_head;
@@ -36,33 +38,24 @@ extern bool dfree_broken;
 /* how many write cache buffers have been allocated */
 extern unsigned int allocated_write_caches;
 
-extern int real_max_open_files;
-extern struct bitmap *file_bmap;
-extern files_struct *Files;
-extern int files_used;
 /* A singleton cache to speed up searching by dev/inode. */
 struct fsp_singleton_cache {
        files_struct *fsp;
        struct file_id id;
 };
-extern struct fsp_singleton_cache fsp_fi_cache;
-extern unsigned long file_gen_counter;
-extern int first_file;
 
 extern const struct mangle_fns *mangle_fns;
 
 extern unsigned char *chartest;
-extern TDB_CONTEXT *tdb_mangled_cache;
+struct tdb_context;
+extern struct tdb_context *tdb_mangled_cache;
 
-/* these tables are used to provide fast tests for characters */
-extern unsigned char char_flags[256];
 /*
   this determines how many characters are used from the original filename
   in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
   The largest possible value is 6.
 */
 extern unsigned mangle_prefix;
-extern unsigned char base_reverse[256];
 
 struct msg_state;
 extern struct msg_state *smbd_msg_state;
@@ -71,7 +64,6 @@ extern bool logged_ioctl_message;
 
 extern int trans_num;
 
-extern pid_t mypid;
 extern time_t last_smb_conf_reload_time;
 extern time_t last_printer_reload_time;
 /****************************************************************************
@@ -87,8 +79,8 @@ extern struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx;
 extern struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx;
 
 struct sec_ctx {
-       UNIX_USER_TOKEN ut;
-       NT_USER_TOKEN *token;
+       struct security_unix_token ut;
+       struct security_token *token;
 };
 /* A stack of security contexts.  We include the current context as being
    the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
@@ -115,6 +107,7 @@ extern int conn_ctx_stack_ndx;
 struct vfs_init_function_entry;
 extern struct vfs_init_function_entry *backends;
 extern char *sparse_buf;
+extern char *LastDir;
 
 /* Current number of oplocks we have outstanding. */
 extern int32_t exclusive_oplocks_open;
@@ -122,7 +115,6 @@ extern int32_t level_II_oplocks_open;
 extern struct kernel_oplocks *koplocks;
 
 extern int am_parent;
-extern int server_fd;
 extern struct event_context *smbd_event_ctx;
 extern struct messaging_context *smbd_msg_ctx;
 extern struct memcache *smbd_memcache_ctx;
@@ -136,7 +128,7 @@ struct smbd_smb2_request;
 struct smbd_smb2_session;
 struct smbd_smb2_tcon;
 
-DATA_BLOB negprot_spnego(struct smbd_server_connection *sconn);
+DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbd_server_connection *sconn);
 
 void smbd_lock_socket(struct smbd_server_connection *sconn);
 void smbd_unlock_socket(struct smbd_server_connection *sconn);
@@ -170,6 +162,7 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                               char *lock_data,
                               uint16_t flags2,
                               unsigned int max_data_bytes,
+                              size_t *fixed_portion,
                               char **ppdata,
                               unsigned int *pdata_size);
 
@@ -187,6 +180,7 @@ NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
                         uint16_t info_level,
                         uint16_t flags2,
                         unsigned int max_data_bytes,
+                        struct smb_filename *smb_fname,
                         char **ppdata,
                         int *ret_data_len);
 
@@ -232,6 +226,11 @@ bool smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
                               int *_last_entry_off,
                               struct ea_list *name_list);
 
+NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
+                                   const struct smb_filename *smb_fname,
+                                   bool file_existed,
+                                   uint32_t access_mask,
+                                   uint32_t *access_mask_out);
 NTSTATUS smbd_check_open_rights(struct connection_struct *conn,
                                const struct smb_filename *smb_fname,
                                uint32_t access_mask,
@@ -245,6 +244,9 @@ void smbd_server_connection_terminate_ex(struct smbd_server_connection *sconn,
 #define smbd_server_connection_terminate(sconn, reason) \
        smbd_server_connection_terminate_ex(sconn, reason, __location__)
 
+struct server_id sconn_server_id(const struct smbd_server_connection *sconn);
+
+const char *smb2_opcode_name(uint16_t opcode);
 bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
 
 void reply_smb2002(struct smb_request *req, uint16_t choice);
@@ -278,6 +280,9 @@ NTSTATUS smbd_smb2_request_check_tcon(struct smbd_smb2_request *req);
 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req);
 void remove_smb2_chained_fsp(files_struct *fsp);
 
+NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
+                                       size_t expected_body_size);
+
 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);
@@ -317,7 +322,8 @@ bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
                                uint64_t offset,
                                uint64_t count,
                                uint64_t blocking_smblctx);
-void process_blocking_lock_queue_smb2(struct timeval tv_curr);
+void process_blocking_lock_queue_smb2(
+       struct smbd_server_connection *sconn, struct timeval tv_curr);
 void cancel_pending_lock_requests_by_fid_smb2(files_struct *fsp,
                        struct byte_range_lock *br_lck,
                        enum file_close_type close_type);
@@ -328,8 +334,10 @@ bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
                        void **pp_state);
 bool open_was_deferred_smb2(struct smbd_server_connection *sconn,
                            uint64_t mid);
-void remove_deferred_open_message_smb2(uint64_t mid);
-void schedule_deferred_open_message_smb2(uint64_t mid);
+void remove_deferred_open_message_smb2(
+       struct smbd_server_connection *sconn, uint64_t mid);
+void schedule_deferred_open_message_smb2(
+       struct smbd_server_connection *sconn, uint64_t mid);
 bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
                        struct timeval request_time,
                        struct timeval timeout,
@@ -347,21 +355,22 @@ struct smbd_smb2_request {
 
        /* the session the request operates on, maybe NULL */
        struct smbd_smb2_session *session;
+       uint64_t last_session_id;
 
        /* the tcon the request operates on, maybe NULL */
        struct smbd_smb2_tcon *tcon;
+       uint32_t last_tid;
 
        int current_idx;
        bool do_signing;
        bool async;
        bool cancelled;
+       bool compound_related;
 
        /* fake smb1 request. */
        struct smb_request *smb1req;
        struct files_struct *compat_chain_fsp;
 
-       NTSTATUS next_status;
-
        /*
         * The sub request for async backend calls.
         * This is used for SMB2 Cancel.
@@ -422,7 +431,7 @@ struct smbd_smb2_session {
        NTSTATUS status;
        uint64_t vuid;
        struct auth_ntlmssp_state *auth_ntlmssp_state;
-       struct auth_serversupplied_info *server_info;
+       struct auth_serversupplied_info *session_info;
        DATA_BLOB session_key;
        bool do_signing;
 
@@ -450,18 +459,49 @@ struct smbd_smb2_tcon {
 struct pending_auth_data;
 
 struct smbd_server_connection {
+       int sock;
+       struct client_address client_id;
        const struct tsocket_address *local_address;
        const struct tsocket_address *remote_address;
+       struct messaging_context *msg_ctx;
        struct {
                bool got_session;
        } nbt;
        bool using_smb2;
+       int trans_num;
+
+       /*
+        * Cache for calling poll(2) to avoid allocations in our
+        * central event loop
+        */
+       struct pollfd *pfds;
+
+       struct files_struct *files;
+       struct bitmap *file_bmap;
+       int real_max_open_files;
+       int files_used;
+       struct fsp_singleton_cache fsp_fi_cache;
+       unsigned long file_gen_counter;
+       int first_file;
+
+       /* number of open connections (tcons) */
+       int num_tcons_open;
+
+       /* open directory handles. */
+       struct {
+               struct bitmap *dptr_bmap;
+               struct dptr_struct *dirptrs;
+               int dirhandles_open;
+       } searches;
+
+       uint64_t num_requests;
+
        struct {
                struct fd_event *fde;
 
                struct {
                        /*
-                        * fd for the fcntl lock mutexing access to smbd_server_fd
+                        * fd for the fcntl lock mutexing access to our sock
                         */
                        int socket_lock_fd;
 
@@ -483,7 +523,6 @@ struct smbd_server_connection {
                        int ref_count;
                } echo_handler;
 
-               uint64_t num_requests;
                struct {
                        bool encrypted_passwords;
                        bool spnego;
@@ -522,7 +561,6 @@ struct smbd_server_connection {
                        connection_struct *Connections;
                        /* number of open connections */
                        struct bitmap *bmap;
-                       int num_open;
                } tcons;
                struct smb_signing_state *signing_state;
                /* List to store partial SPNEGO auth fragments. */
@@ -530,11 +568,6 @@ struct smbd_server_connection {
 
                struct notify_mid_map *notify_mid_maps;
 
-               struct {
-                       struct bitmap *dptr_bmap;
-                       struct dptr_struct *dirptrs;
-                       int dirhandles_open;
-               } searches;
                struct {
                        /* dlink list we store pending lock records on. */
                        struct blocking_lock_record *blocking_lock_queue;
@@ -570,10 +603,56 @@ struct smbd_server_connection {
                        bool blocking_lock_unlock_state;
                } locks;
                struct smbd_smb2_request *requests;
-               uint64_t credits_granted;
+               /*
+                * seqnum_low is the lowest sequence number
+                * we will accept.
+                */
+               uint64_t seqnum_low;
+               /*
+                * seqnum_range is the range of credits we have
+                * granted from the sequence windows starting
+                * at seqnum_low.
+                *
+                * This gets incremented when new credits are
+                * granted and gets decremented when the
+                * lowest sequence number is consumed
+                * (when seqnum_low gets incremented).
+                */
+               uint16_t seqnum_range;
+               /*
+                * credits_grantedThe number of credits we have currently granted
+                * to the client.
+                *
+                * This gets incremented when new credits are
+                * granted and gets decremented when any credit
+                * is comsumed.
+                *
+                * Note: the decrementing is different compared
+                *       to seqnum_range.
+                */
+               uint16_t credits_granted;
+               /*
+                * The maximum number of credits we will ever
+                * grant to the client.
+                *
+                * Typically we will only grant 1/16th of
+                * max_credits.
+                *
+                * This is the "server max credits" parameter.
+                */
+               uint16_t max_credits;
+               /*
+                * a bitmap of size max_credits
+                */
+               struct bitmap *credits_bitmap;
+               uint32_t max_trans;
+               uint32_t max_read;
+               uint32_t max_write;
        } smb2;
 };
 
 extern struct smbd_server_connection *smbd_server_conn;
 
+struct smbd_server_connection *msg_ctx_to_sconn(struct messaging_context *msg_ctx);
+
 void smbd_init_globals(void);