Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/globals.h

    r860 r988  
    2020
    2121#include "system/select.h"
    22 
    23 #if defined(WITH_AIO)
    24 struct aio_extra;
    25 extern struct aio_extra *aio_list_head;
    26 extern struct tevent_signal *aio_signal_event;
    27 extern int aio_pending_size;
    28 extern int outstanding_aio_calls;
    29 #endif
     22#include "librpc/gen_ndr/smbXsrv.h"
     23#include "smbprofile.h"
    3024
    3125#ifdef USE_DMAPI
     
    3327extern struct smbd_dmapi_context *dmapi_ctx;
    3428#endif
    35 
    36 extern bool dfree_broken;
    3729
    3830/* how many write cache buffers have been allocated */
     
    5951
    6052struct msg_state;
    61 extern struct msg_state *smbd_msg_state;
    6253
    6354extern bool logged_ioctl_message;
     
    6758extern time_t last_smb_conf_reload_time;
    6859extern time_t last_printer_reload_time;
     60extern pid_t background_lpq_updater_pid;
     61
    6962/****************************************************************************
    7063 structure to hold a linked list of queued messages.
    7164 for processing.
    7265****************************************************************************/
    73 struct pending_message_list;
    74 extern struct pending_message_list *deferred_open_queue;
    7566extern uint32_t common_flags2;
    7667
    77 struct smb_srv_trans_enc_ctx;
    78 extern struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx;
    79 extern struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx;
     68extern struct smb_trans_enc_state *partial_srv_trans_enc_ctx;
     69extern struct smb_trans_enc_state *srv_trans_enc_ctx;
    8070
    8171struct sec_ctx {
     
    9989struct conn_ctx {
    10090        connection_struct *conn;
    101         uint16 vuid;
     91        uint64_t vuid;
    10292};
    10393/* A stack of current_user connection contexts. */
     
    110100extern char *LastDir;
    111101
    112 /* Current number of oplocks we have outstanding. */
    113 extern int32_t exclusive_oplocks_open;
    114 extern int32_t level_II_oplocks_open;
    115 extern struct kernel_oplocks *koplocks;
    116 
    117 extern int am_parent;
    118 extern struct event_context *smbd_event_ctx;
    119 extern struct messaging_context *smbd_msg_ctx;
     102struct smbd_parent_context;
     103extern struct smbd_parent_context *am_parent;
    120104extern struct memcache *smbd_memcache_ctx;
    121105extern bool exit_firsttime;
    122 struct child_pid;
    123 extern struct child_pid *children;
    124 extern int num_children;
    125106
    126107struct tstream_context;
    127108struct smbd_smb2_request;
    128 struct smbd_smb2_session;
    129 struct smbd_smb2_tcon;
    130 
    131 DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbd_server_connection *sconn);
    132 
    133 void smbd_lock_socket(struct smbd_server_connection *sconn);
    134 void smbd_unlock_socket(struct smbd_server_connection *sconn);
    135 
    136 NTSTATUS smb2_signing_sign_pdu(DATA_BLOB session_key,
    137                                struct iovec *vector,
    138                                int count);
    139 NTSTATUS smb2_signing_check_pdu(DATA_BLOB session_key,
    140                                 const struct iovec *vector,
    141                                 int count);
     109
     110DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbXsrv_connection *xconn);
     111
     112void smbd_lock_socket(struct smbXsrv_connection *xconn);
     113void smbd_unlock_socket(struct smbXsrv_connection *xconn);
    142114
    143115NTSTATUS smbd_do_locking(struct smb_request *req,
     
    145117                         uint8_t type,
    146118                         int32_t timeout,
    147                          uint16_t num_ulocks,
    148                          struct smbd_lock_element *ulocks,
    149119                         uint16_t num_locks,
    150120                         struct smbd_lock_element *locks,
    151121                         bool *async);
     122NTSTATUS smbd_do_unlocking(struct smb_request *req,
     123                           files_struct *fsp,
     124                           uint16_t num_ulocks,
     125                           struct smbd_lock_element *ulocks);
    152126
    153127NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
     
    167141                               unsigned int *pdata_size);
    168142
     143NTSTATUS smbd_do_setfsinfo(connection_struct *conn,
     144                                struct smb_request *req,
     145                                TALLOC_CTX *mem_ctx,
     146                                uint16_t info_level,
     147                                files_struct *fsp,
     148                                const DATA_BLOB *pdata);
     149
    169150NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
    170151                                struct smb_request *req,
     
    176157                                int *ret_data_size);
    177158
    178 NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
     159NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
     160                         connection_struct *conn,
    179161                         TALLOC_CTX *mem_ctx,
    180162                         uint16_t info_level,
     
    207189                           long *_prev_offset);
    208190
    209 bool smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
     191NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
    210192                               connection_struct *conn,
    211193                               struct dptr_struct *dirptr,
    212                                uint16 flags2,
     194                               uint16_t flags2,
    213195                               const char *path_mask,
    214                                uint32 dirtype,
     196                               uint32_t dirtype,
    215197                               int info_level,
    216198                               int requires_resume_key,
     
    223205                               char *end_data,
    224206                               int space_remaining,
    225                                bool *out_of_space,
    226207                               bool *got_exact_match,
    227208                               int *_last_entry_off,
     
    230211NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
    231212                                    const struct smb_filename *smb_fname,
    232                                     bool file_existed,
     213                                    bool use_privs,
    233214                                    uint32_t access_mask,
    234215                                    uint32_t *access_mask_out);
    235 NTSTATUS smbd_check_open_rights(struct connection_struct *conn,
    236                                 const struct smb_filename *smb_fname,
    237                                 uint32_t access_mask,
    238                                 uint32_t *access_granted);
    239216
    240217void smbd_notify_cancel_by_smbreq(const struct smb_request *smbreq);
    241218
    242 void smbd_server_connection_terminate_ex(struct smbd_server_connection *sconn,
     219void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
    243220                                         const char *reason,
    244221                                         const char *location);
    245 #define smbd_server_connection_terminate(sconn, reason) \
    246         smbd_server_connection_terminate_ex(sconn, reason, __location__)
    247 
    248 struct server_id sconn_server_id(const struct smbd_server_connection *sconn);
     222#define smbd_server_connection_terminate(xconn, reason) \
     223        smbd_server_connection_terminate_ex(xconn, reason, __location__)
    249224
    250225const char *smb2_opcode_name(uint16_t opcode);
    251226bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
    252227
     228NTSTATUS smbd_add_connection(struct smbXsrv_client *client, int sock_fd,
     229                             struct smbXsrv_connection **_xconn);
     230
    253231void reply_smb2002(struct smb_request *req, uint16_t choice);
    254 void smbd_smb2_first_negprot(struct smbd_server_connection *sconn,
    255                              const uint8_t *inbuf, size_t size);
     232void reply_smb20ff(struct smb_request *req, uint16_t choice);
     233void smbd_smb2_process_negprot(struct smbXsrv_connection *xconn,
     234                               uint64_t expected_seq_low,
     235                               const uint8_t *inpdu, size_t size);
     236
     237DATA_BLOB smbd_smb2_generate_outbody(struct smbd_smb2_request *req, size_t size);
    256238
    257239NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
     
    268250        smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
    269251
    270 NTSTATUS smbd_smb2_send_oplock_break(struct smbd_server_connection *sconn,
    271                                      uint64_t file_id_persistent,
    272                                      uint64_t file_id_volatile,
     252NTSTATUS smbd_smb2_send_oplock_break(struct smbXsrv_connection *xconn,
     253                                     struct smbXsrv_session *session,
     254                                     struct smbXsrv_tcon *tcon,
     255                                     struct smbXsrv_open *op,
    273256                                     uint8_t oplock_level);
     257NTSTATUS smbd_smb2_send_lease_break(struct smbXsrv_connection *xconn,
     258                                    uint16_t new_epoch,
     259                                    uint32_t lease_flags,
     260                                    struct smb2_lease_key *lease_key,
     261                                    uint32_t current_lease_state,
     262                                    uint32_t new_lease_state);
    274263
    275264NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
    276                                          struct tevent_req *subreq);
    277 
    278 NTSTATUS smbd_smb2_request_check_session(struct smbd_smb2_request *req);
    279 NTSTATUS smbd_smb2_request_check_tcon(struct smbd_smb2_request *req);
     265                                         struct tevent_req *subreq,
     266                                         uint32_t defer_time);
    280267
    281268struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req);
     269size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req);
    282270void remove_smb2_chained_fsp(files_struct *fsp);
     271
     272NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req,
     273                                               uint32_t data_length);
    283274
    284275NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
    285276                                        size_t expected_body_size);
    286277
     278enum protocol_types smbd_smb2_protocol_dialect_match(const uint8_t *indyn,
     279                                                     const int dialect_count,
     280                                                     uint16_t *dialect);
    287281NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
    288282NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
     
    297291NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req);
    298292NTSTATUS smb2_write_complete(struct tevent_req *req, ssize_t nwritten, int err);
     293NTSTATUS smb2_write_complete_nosync(struct tevent_req *req, ssize_t nwritten,
     294                                    int err);
    299295NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req);
    300296NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req);
    301297NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
    302 NTSTATUS smbd_smb2_request_process_find(struct smbd_smb2_request *req);
     298NTSTATUS smbd_smb2_request_process_query_directory(struct smbd_smb2_request *req);
    303299NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req);
    304300NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req);
     
    310306                                void *private_data);
    311307
     308struct deferred_open_record;
     309
    312310/* SMB1 -> SMB2 glue. */
    313 void send_break_message_smb2(files_struct *fsp, int level);
     311void send_break_message_smb2(files_struct *fsp,
     312                             uint32_t break_from,
     313                             uint32_t break_to);
    314314struct blocking_lock_record *get_pending_smb2req_blr(struct smbd_smb2_request *smb2req);
    315315bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
     
    333333bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
    334334                        struct timeval *p_request_time,
    335                         void **pp_state);
    336 bool open_was_deferred_smb2(struct smbd_server_connection *sconn,
    337                             uint64_t mid);
     335                        struct deferred_open_record **open_rec);
     336bool open_was_deferred_smb2(
     337        struct smbXsrv_connection *xconn, uint64_t mid);
    338338void remove_deferred_open_message_smb2(
    339         struct smbd_server_connection *sconn, uint64_t mid);
    340 void schedule_deferred_open_message_smb2(
    341         struct smbd_server_connection *sconn, uint64_t mid);
     339        struct smbXsrv_connection *xconn, uint64_t mid);
     340bool schedule_deferred_open_message_smb2(
     341        struct smbXsrv_connection *xconn, uint64_t mid);
    342342bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
    343                         struct timeval request_time,
    344                         struct timeval timeout,
    345                         struct file_id id,
    346                         char *private_data,
    347                         size_t priv_len);
     343                                struct timeval request_time,
     344                                struct timeval timeout,
     345                                struct file_id id,
     346                                struct deferred_open_record *open_rec);
     347
     348struct smbXsrv_client;
     349
     350struct smbXsrv_preauth {
     351        uint8_t sha512_value[64];
     352};
     353
     354struct smbXsrv_connection {
     355        struct smbXsrv_connection *prev, *next;
     356
     357        struct smbXsrv_client *client;
     358
     359
     360        const struct tsocket_address *local_address;
     361        const struct tsocket_address *remote_address;
     362        const char *remote_hostname;
     363
     364        struct tevent_context *ev_ctx;
     365        struct messaging_context *msg_ctx;
     366
     367        enum protocol_types protocol;
     368
     369        struct {
     370                NTSTATUS status;
     371                int sock;
     372                struct tevent_fd *fde;
     373
     374                struct {
     375                        bool got_session;
     376                } nbt;
     377        } transport;
     378
     379        struct {
     380                struct {
     381                        /*
     382                         * fd for the fcntl lock and process shared
     383                         * robust mutex to coordinate access to the
     384                         * client socket. When the system supports
     385                         * process shared robust mutexes, those are
     386                         * used. If not, then the fcntl lock will be
     387                         * used.
     388                         */
     389                        int socket_lock_fd;
     390#ifdef HAVE_ROBUST_MUTEXES
     391                        pthread_mutex_t *socket_mutex;
     392#endif
     393
     394                        /*
     395                         * fd for the trusted pipe from
     396                         * echo handler child
     397                         */
     398                        int trusted_fd;
     399
     400                        /*
     401                         * fde for the trusted_fd
     402                         */
     403                        struct tevent_fd *trusted_fde;
     404
     405                        /*
     406                         * Reference count for the fcntl lock to
     407                         * allow recursive locks.
     408                         */
     409                        int ref_count;
     410                } echo_handler;
     411
     412                struct {
     413                        bool encrypted_passwords;
     414                        bool spnego;
     415                        struct auth4_context *auth_context;
     416                        bool done;
     417                        /*
     418                         * Size of the data we can receive. Set by us.
     419                         * Can be modified by the max xmit parameter.
     420                         */
     421                        int max_recv;
     422                } negprot;
     423
     424                struct {
     425                        bool done_sesssetup;
     426                        /*
     427                         * Size of data we can send to client. Set
     428                         *  by the client for all protocols above CORE.
     429                         *  Set by us for CORE protocol.
     430                         */
     431                        int max_send;
     432                } sessions;
     433                struct smb_signing_state *signing_state;
     434
     435                struct {
     436                        uint16_t client_major;
     437                        uint16_t client_minor;
     438                        uint32_t client_cap_low;
     439                        uint32_t client_cap_high;
     440                } unix_info;
     441
     442                struct msg_state *msg_state;
     443        } smb1;
     444        struct {
     445                struct smbd_smb2_request_read_state {
     446                        struct smbd_smb2_request *req;
     447                        struct {
     448                                uint8_t nbt[NBT_HDR_SIZE];
     449                                bool done;
     450                        } hdr;
     451                        struct iovec vector;
     452                        bool doing_receivefile;
     453                        size_t min_recv_size;
     454                        size_t pktfull;
     455                        size_t pktlen;
     456                        uint8_t *pktbuf;
     457                } request_read_state;
     458                struct smbd_smb2_send_queue *send_queue;
     459                size_t send_queue_len;
     460
     461                struct {
     462                        /*
     463                         * seq_low is the lowest sequence number
     464                         * we will accept.
     465                         */
     466                        uint64_t seq_low;
     467                        /*
     468                         * seq_range is the range of credits we have
     469                         * granted from the sequence windows starting
     470                         * at seq_low.
     471                         *
     472                         * This gets incremented when new credits are
     473                         * granted and gets decremented when the
     474                         * lowest sequence number is consumed
     475                         * (when seq_low gets incremented).
     476                         */
     477                        uint16_t seq_range;
     478                        /*
     479                         * The number of credits we have currently granted
     480                         * to the client.
     481                         *
     482                         * This gets incremented when new credits are
     483                         * granted and gets decremented when any credit
     484                         * is comsumed.
     485                         *
     486                         * Note: the decrementing is different compared
     487                         *       to seq_range.
     488                         */
     489                        uint16_t granted;
     490                        /*
     491                         * The maximum number of credits we will ever
     492                         * grant to the client.
     493                         *
     494                         * Typically we will only grant 1/16th of
     495                         * max_credits.
     496                         *
     497                         * This is the "server max credits" parameter.
     498                         */
     499                        uint16_t max;
     500                        /*
     501                         * a bitmap of size max_credits
     502                         */
     503                        struct bitmap *bitmap;
     504                        bool multicredit;
     505                } credits;
     506
     507                bool allow_2ff;
     508                struct {
     509                        uint32_t capabilities;
     510                        struct GUID guid;
     511                        bool guid_verified;
     512                        uint16_t security_mode;
     513                        uint16_t num_dialects;
     514                        uint16_t *dialects;
     515                } client;
     516                struct {
     517                        uint32_t capabilities;
     518                        struct GUID guid;
     519                        uint16_t security_mode;
     520                        uint16_t dialect;
     521                        uint32_t max_trans;
     522                        uint32_t max_read;
     523                        uint32_t max_write;
     524                        uint16_t cipher;
     525                } server;
     526
     527                struct smbXsrv_preauth preauth;
     528
     529                struct smbd_smb2_request *requests;
     530        } smb2;
     531};
     532
     533const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
     534
     535NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id);
     536uint32_t smbXsrv_version_global_current(void);
     537
     538struct smbXsrv_client_table;
     539NTSTATUS smbXsrv_client_global_init(void);
     540NTSTATUS smbXsrv_client_create(TALLOC_CTX *mem_ctx,
     541                               struct tevent_context *ev_ctx,
     542                               struct messaging_context *msg_ctx,
     543                               NTTIME now,
     544                               struct smbXsrv_client **_client);
     545NTSTATUS smbXsrv_client_update(struct smbXsrv_client *client);
     546NTSTATUS smbXsrv_client_remove(struct smbXsrv_client *client);
     547NTSTATUS smb2srv_client_lookup_global(struct smbXsrv_client *client,
     548                                      struct GUID client_guid,
     549                                      TALLOC_CTX *mem_ctx,
     550                                      struct smbXsrv_client_global0 **_pass);
     551NTSTATUS smb2srv_client_connection_pass(struct smbd_smb2_request *smb2req,
     552                                        struct smbXsrv_client_global0 *global);
     553
     554NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
     555                                        enum protocol_types protocol);
     556
     557NTSTATUS smbXsrv_session_global_init(void);
     558NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
     559                                NTTIME now,
     560                                struct smbXsrv_session **_session);
     561NTSTATUS smbXsrv_session_add_channel(struct smbXsrv_session *session,
     562                                     struct smbXsrv_connection *conn,
     563                                     struct smbXsrv_channel_global0 **_c);
     564NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
     565struct smbXsrv_channel_global0;
     566NTSTATUS smbXsrv_session_find_channel(const struct smbXsrv_session *session,
     567                                      const struct smbXsrv_connection *conn,
     568                                      struct smbXsrv_channel_global0 **_c);
     569NTSTATUS smbXsrv_session_find_auth(const struct smbXsrv_session *session,
     570                                   const struct smbXsrv_connection *conn,
     571                                   NTTIME now,
     572                                   struct smbXsrv_session_auth0 **_a);
     573NTSTATUS smbXsrv_session_create_auth(struct smbXsrv_session *session,
     574                                     struct smbXsrv_connection *conn,
     575                                     NTTIME now,
     576                                     uint8_t in_flags,
     577                                     uint8_t in_security_mode,
     578                                     struct smbXsrv_session_auth0 **_a);
     579struct tevent_req *smb2srv_session_shutdown_send(TALLOC_CTX *mem_ctx,
     580                                        struct tevent_context *ev,
     581                                        struct smbXsrv_session *session,
     582                                        struct smbd_smb2_request *current_req);
     583NTSTATUS smb2srv_session_shutdown_recv(struct tevent_req *req);
     584NTSTATUS smbXsrv_session_logoff(struct smbXsrv_session *session);
     585NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_connection *conn);
     586NTSTATUS smb1srv_session_table_init(struct smbXsrv_connection *conn);
     587NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
     588                                uint16_t vuid, NTTIME now,
     589                                struct smbXsrv_session **session);
     590NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
     591NTSTATUS smb2srv_session_lookup_conn(struct smbXsrv_connection *conn,
     592                                     uint64_t session_id, NTTIME now,
     593                                     struct smbXsrv_session **session);
     594NTSTATUS smb2srv_session_lookup_client(struct smbXsrv_client *client,
     595                                       uint64_t session_id, NTTIME now,
     596                                       struct smbXsrv_session **session);
     597struct smbXsrv_session_global0;
     598NTSTATUS smbXsrv_session_global_traverse(
     599                        int (*fn)(struct smbXsrv_session_global0 *, void *),
     600                        void *private_data);
     601struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
     602                                        struct tevent_context *ev,
     603                                        struct smbXsrv_connection *conn,
     604                                        struct auth_session_info *session_info,
     605                                        uint64_t previous_session_id,
     606                                        uint64_t current_session_id);
     607NTSTATUS smb2srv_session_close_previous_recv(struct tevent_req *req);
     608
     609NTSTATUS smbXsrv_tcon_global_init(void);
     610NTSTATUS smbXsrv_tcon_update(struct smbXsrv_tcon *tcon);
     611NTSTATUS smbXsrv_tcon_disconnect(struct smbXsrv_tcon *tcon, uint64_t vuid);
     612NTSTATUS smb1srv_tcon_table_init(struct smbXsrv_connection *conn);
     613NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
     614                             NTTIME now,
     615                             struct smbXsrv_tcon **_tcon);
     616NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
     617                             uint16_t tree_id, NTTIME now,
     618                             struct smbXsrv_tcon **tcon);
     619NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_connection *conn);
     620NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session);
     621NTSTATUS smb2srv_tcon_create(struct smbXsrv_session *session,
     622                             NTTIME now,
     623                             struct smbXsrv_tcon **_tcon);
     624NTSTATUS smb2srv_tcon_lookup(struct smbXsrv_session *session,
     625                             uint32_t tree_id, NTTIME now,
     626                             struct smbXsrv_tcon **tcon);
     627NTSTATUS smb2srv_tcon_disconnect_all(struct smbXsrv_session *session);
     628struct smbXsrv_tcon_global0;
     629NTSTATUS smbXsrv_tcon_global_traverse(
     630                        int (*fn)(struct smbXsrv_tcon_global0 *, void *),
     631                        void *private_data);
     632
     633NTSTATUS smbXsrv_open_global_init(void);
     634NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
     635                             struct auth_session_info *session_info,
     636                             NTTIME now,
     637                             struct smbXsrv_open **_open);
     638uint32_t smbXsrv_open_hash(struct smbXsrv_open *_open);
     639NTSTATUS smbXsrv_open_update(struct smbXsrv_open *_open);
     640NTSTATUS smbXsrv_open_close(struct smbXsrv_open *op, NTTIME now);
     641NTSTATUS smb1srv_open_table_init(struct smbXsrv_connection *conn);
     642NTSTATUS smb1srv_open_lookup(struct smbXsrv_connection *conn,
     643                             uint16_t fnum, NTTIME now,
     644                             struct smbXsrv_open **_open);
     645NTSTATUS smb2srv_open_table_init(struct smbXsrv_connection *conn);
     646NTSTATUS smb2srv_open_lookup(struct smbXsrv_connection *conn,
     647                             uint64_t persistent_id,
     648                             uint64_t volatile_id,
     649                             NTTIME now,
     650                             struct smbXsrv_open **_open);
     651NTSTATUS smb2srv_open_lookup_replay_cache(struct smbXsrv_connection *conn,
     652                                          const struct GUID *create_guid,
     653                                          NTTIME now,
     654                                          struct smbXsrv_open **_open);
     655NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
     656                               struct auth_session_info *session_info,
     657                               uint64_t persistent_id,
     658                               const struct GUID *create_guid,
     659                               NTTIME now,
     660                               struct smbXsrv_open **_open);
     661struct smbXsrv_open_global0;
     662NTSTATUS smbXsrv_open_global_traverse(
     663        int (*fn)(struct smbXsrv_open_global0 *, void *),
     664        void *private_data);
     665
     666NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id);
     667bool smbXsrv_is_encrypted(uint8_t encryption_flags);
     668bool smbXsrv_is_partially_encrypted(uint8_t encryption_flags);
     669bool smbXsrv_set_crypto_flag(uint8_t *flags, uint8_t flag);
     670bool smbXsrv_is_signed(uint8_t signing_flags);
     671bool smbXsrv_is_partially_signed(uint8_t signing_flags);
     672
     673struct smbd_smb2_send_queue {
     674        struct smbd_smb2_send_queue *prev, *next;
     675
     676        DATA_BLOB *sendfile_header;
     677        NTSTATUS *sendfile_status;
     678        struct iovec *vector;
     679        int count;
     680
     681        TALLOC_CTX *mem_ctx;
     682};
    348683
    349684struct smbd_smb2_request {
    350685        struct smbd_smb2_request *prev, *next;
    351686
    352         TALLOC_CTX *mem_pool;
    353         struct smbd_smb2_request **parent;
    354 
    355687        struct smbd_server_connection *sconn;
     688        struct smbXsrv_connection *xconn;
     689
     690        struct smbd_smb2_send_queue queue_entry;
    356691
    357692        /* the session the request operates on, maybe NULL */
    358         struct smbd_smb2_session *session;
     693        struct smbXsrv_session *session;
    359694        uint64_t last_session_id;
    360695
    361696        /* the tcon the request operates on, maybe NULL */
    362         struct smbd_smb2_tcon *tcon;
     697        struct smbXsrv_tcon *tcon;
    363698        uint32_t last_tid;
    364699
    365700        int current_idx;
    366701        bool do_signing;
    367         bool async;
    368         bool cancelled;
     702        /* Was the request encrypted? */
     703        bool was_encrypted;
     704        /* Should we encrypt? */
     705        bool do_encryption;
     706        struct tevent_timer *async_te;
    369707        bool compound_related;
     708
     709        /*
     710         * the encryption key for the whole
     711         * compound chain
     712         */
     713        DATA_BLOB first_key;
     714        /*
     715         * the signing key for the last
     716         * request/response of a compound chain
     717         */
     718        DATA_BLOB last_key;
     719        struct smbXsrv_preauth *preauth;
     720
     721        struct timeval request_time;
     722
     723        SMBPROFILE_IOBYTES_ASYNC_STATE(profile);
    370724
    371725        /* fake smb1 request. */
     
    379733        struct tevent_req *subreq;
    380734
     735#define SMBD_SMB2_TF_IOV_OFS 0
     736#define SMBD_SMB2_HDR_IOV_OFS 1
     737#define SMBD_SMB2_BODY_IOV_OFS 2
     738#define SMBD_SMB2_DYN_IOV_OFS 3
     739
     740#define SMBD_SMB2_NUM_IOV_PER_REQ 4
     741
     742#define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
     743        (&req->dir.vector[(idx)+(ofs)])
     744
     745#define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
     746        SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
     747#define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
     748        SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_HDR_IOV_OFS)
     749#define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
     750        SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_BODY_IOV_OFS)
     751#define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
     752        SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_DYN_IOV_OFS)
     753
     754#define SMBD_SMB2_IN_TF_IOV(req)    SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
     755#define SMBD_SMB2_IN_TF_PTR(req)    (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
     756#define SMBD_SMB2_IN_HDR_IOV(req)    SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
     757#define SMBD_SMB2_IN_HDR_PTR(req)    (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
     758#define SMBD_SMB2_IN_BODY_IOV(req)   SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
     759#define SMBD_SMB2_IN_BODY_PTR(req)   (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
     760#define SMBD_SMB2_IN_BODY_LEN(req)   (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
     761#define SMBD_SMB2_IN_DYN_IOV(req)    SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
     762#define SMBD_SMB2_IN_DYN_PTR(req)    (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
     763#define SMBD_SMB2_IN_DYN_LEN(req)    (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
     764
     765#define SMBD_SMB2_OUT_TF_IOV(req)   SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
     766#define SMBD_SMB2_OUT_TF_PTR(req)   (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
     767#define SMBD_SMB2_OUT_HDR_IOV(req)   SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
     768#define SMBD_SMB2_OUT_HDR_PTR(req)   (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
     769#define SMBD_SMB2_OUT_BODY_IOV(req)  SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
     770#define SMBD_SMB2_OUT_BODY_PTR(req)  (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
     771#define SMBD_SMB2_OUT_BODY_LEN(req)  (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
     772#define SMBD_SMB2_OUT_DYN_IOV(req)   SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
     773#define SMBD_SMB2_OUT_DYN_PTR(req)   (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
     774#define SMBD_SMB2_OUT_DYN_LEN(req)   (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
     775
     776#define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
     777
    381778        struct {
    382                 /* the NBT header is not allocated */
    383                 uint8_t nbt_hdr[4];
    384779                /*
    385                  * vector[0] NBT
    386                  * .
    387                  * vector[1] SMB2
    388                  * vector[2] fixed body
    389                  * vector[3] dynamic body
    390                  * .
    391                  * .
    392                  * .
    393                  * vector[4] SMB2
    394                  * vector[5] fixed body
    395                  * vector[6] dynamic body
     780                 * vector[0] TRANSPORT HEADER (empty)
     781                 * .
     782                 * vector[1] SMB2_TRANSFORM (optional)
     783                 * vector[2] SMB2
     784                 * vector[3] fixed body
     785                 * vector[4] dynamic body
     786                 * .
     787                 * .
     788                 * .
     789                 * vector[5] SMB2_TRANSFORM (optional)
     790                 * vector[6] SMB2
     791                 * vector[7] fixed body
     792                 * vector[8] dynamic body
    396793                 * .
    397794                 * .
     
    400797                struct iovec *vector;
    401798                int vector_count;
     799                struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
    402800        } in;
    403801        struct {
     
    405803                uint8_t nbt_hdr[4];
    406804                /*
    407                  * vector[0] NBT
    408                  * .
    409                  * vector[1] SMB2
    410                  * vector[2] fixed body
    411                  * vector[3] dynamic body
    412                  * .
    413                  * .
    414                  * .
    415                  * vector[4] SMB2
    416                  * vector[5] fixed body
    417                  * vector[6] dynamic body
     805                 * vector[0] TRANSPORT HEADER
     806                 * .
     807                 * vector[1] SMB2_TRANSFORM (optional)
     808                 * vector[2] SMB2
     809                 * vector[3] fixed body
     810                 * vector[4] dynamic body
     811                 * .
     812                 * .
     813                 * .
     814                 * vector[5] SMB2_TRANSFORM (empty)
     815                 * vector[6] SMB2
     816                 * vector[7] fixed body
     817                 * vector[8] dynamic body
    418818                 * .
    419819                 * .
     
    422822                struct iovec *vector;
    423823                int vector_count;
     824                struct iovec _vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
     825#define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
     826                uint8_t _hdr[OUTVEC_ALLOC_SIZE];
     827                uint8_t _body[0x58];
    424828        } out;
    425829};
    426830
    427831struct smbd_server_connection;
    428 
    429 struct smbd_smb2_session {
    430         struct smbd_smb2_session *prev, *next;
    431         struct smbd_server_connection *sconn;
    432         NTSTATUS status;
    433         uint64_t vuid;
    434         struct auth_ntlmssp_state *auth_ntlmssp_state;
    435         struct auth_serversupplied_info *session_info;
    436         DATA_BLOB session_key;
    437         bool do_signing;
    438 
    439         user_struct *compat_vuser;
    440 
    441         struct {
    442                 /* an id tree used to allocate tids */
    443                 struct idr_context *idtree;
    444 
    445                 /* this is the limit of tid values for this connection */
    446                 uint32_t limit;
    447 
    448                 struct smbd_smb2_tcon *list;
    449         } tcons;
     832struct user_struct;
     833
     834struct pending_message_list;
     835struct pending_auth_data;
     836
     837struct user_struct {
     838        struct user_struct *next, *prev;
     839        uint64_t vuid; /* Tag for this entry. */
     840
     841        char *session_keystr; /* used by utmp and pam session code.
     842                                 TDB key string */
     843        int homes_snum;
     844
     845        struct auth_session_info *session_info;
     846
     847        struct smbXsrv_session *session;
    450848};
    451849
    452 struct smbd_smb2_tcon {
    453         struct smbd_smb2_tcon *prev, *next;
    454         struct smbd_smb2_session *session;
    455         uint32_t tid;
    456         int snum;
    457         connection_struct *compat_conn;
    458 };
    459 
    460 struct pending_auth_data;
    461 
    462850struct smbd_server_connection {
    463         int sock;
    464         struct client_address client_id;
    465851        const struct tsocket_address *local_address;
    466852        const struct tsocket_address *remote_address;
     853        const char *remote_hostname;
     854        struct tevent_context *ev_ctx;
    467855        struct messaging_context *msg_ctx;
    468         struct {
    469                 bool got_session;
    470         } nbt;
     856        struct sys_notify_context *sys_notify_ctx;
     857        struct notify_context *notify_ctx;
    471858        bool using_smb2;
    472859        int trans_num;
    473860
    474         /*
    475          * Cache for calling poll(2) to avoid allocations in our
    476          * central event loop
    477          */
    478         struct pollfd *pfds;
    479 
     861        size_t num_users;
     862        struct user_struct *users;
     863
     864        size_t num_connections;
     865        struct connection_struct *connections;
     866
     867        size_t num_files;
    480868        struct files_struct *files;
    481         struct bitmap *file_bmap;
     869
    482870        int real_max_open_files;
    483         int files_used;
    484871        struct fsp_singleton_cache fsp_fi_cache;
    485         unsigned long file_gen_counter;
    486         int first_file;
    487 
    488         /* number of open connections (tcons) */
    489         int num_tcons_open;
     872
     873        struct pending_message_list *deferred_open_queue;
     874
    490875
    491876        /* open directory handles. */
     
    498883        uint64_t num_requests;
    499884
     885        /* Current number of oplocks we have outstanding. */
    500886        struct {
    501                 struct fd_event *fde;
    502 
    503                 struct {
    504                         /*
    505                          * fd for the fcntl lock mutexing access to our sock
    506                          */
    507                         int socket_lock_fd;
    508 
    509                         /*
    510                          * fd for the trusted pipe from
    511                          * echo handler child
    512                          */
    513                         int trusted_fd;
    514 
    515                         /*
    516                          * fde for the trusted_fd
    517                          */
    518                         struct fd_event *trusted_fde;
    519 
    520                         /*
    521                          * Reference count for the fcntl lock to
    522                          * allow recursive locks.
    523                          */
    524                         int ref_count;
    525                 } echo_handler;
    526 
    527                 struct {
    528                         bool encrypted_passwords;
    529                         bool spnego;
    530                         struct auth_context *auth_context;
    531                         bool done;
    532                         /*
    533                          * Size of the data we can receive. Set by us.
    534                          * Can be modified by the max xmit parameter.
    535                          */
    536                         int max_recv;
    537                 } negprot;
    538 
    539                 struct {
    540                         bool done_sesssetup;
    541                         /*
    542                          * Size of data we can send to client. Set
    543                          *  by the client for all protocols above CORE.
    544                          *  Set by us for CORE protocol.
    545                          */
    546                         int max_send;
    547                         uint16_t last_session_tag;
    548 
    549                         /* users from session setup */
    550                         char *session_userlist;
    551                         /* workgroup from session setup. */
    552                         char *session_workgroup;
    553                         /*
    554                          * this holds info on user ids that are already
    555                          * validated for this VC
    556                          */
    557                         user_struct *validated_users;
    558                         uint16_t next_vuid;
    559                         int num_validated_vuids;
    560                 } sessions;
    561                 struct {
    562                         connection_struct *Connections;
    563                         /* number of open connections */
    564                         struct bitmap *bmap;
    565                 } tcons;
    566                 struct smb_signing_state *signing_state;
    567                 /* List to store partial SPNEGO auth fragments. */
    568                 struct pending_auth_data *pd_list;
    569 
     887                int32_t exclusive_open;
     888                int32_t level_II_open;
     889                struct kernel_oplocks *kernel_ops;
     890        } oplocks;
     891
     892        struct {
    570893                struct notify_mid_map *notify_mid_maps;
    571894
     
    577900
    578901                        /* The event that makes us process our blocking lock queue */
    579                         struct timed_event *brl_timeout;
     902                        struct tevent_timer *brl_timeout;
    580903
    581904                        bool blocking_lock_unlock_state;
     
    584907        } smb1;
    585908        struct {
    586                 struct tevent_context *event_ctx;
    587                 struct tevent_queue *recv_queue;
    588                 struct tevent_queue *send_queue;
    589                 struct tstream_context *stream;
    590                 struct {
    591                         /* an id tree used to allocate vuids */
    592                         /* this holds info on session vuids that are already
    593                          * validated for this VC */
    594                         struct idr_context *idtree;
    595 
    596                         /* this is the limit of vuid values for this connection */
    597                         uint64_t limit;
    598 
    599                         struct smbd_smb2_session *list;
    600                 } sessions;
    601909                struct {
    602910                        /* The event that makes us process our blocking lock queue */
    603                         struct timed_event *brl_timeout;
     911                        struct tevent_timer *brl_timeout;
    604912                        bool blocking_lock_unlock_state;
    605913                } locks;
    606                 struct smbd_smb2_request *requests;
    607                 /*
    608                  * seqnum_low is the lowest sequence number
    609                  * we will accept.
    610                  */
    611                 uint64_t seqnum_low;
    612                 /*
    613                  * seqnum_range is the range of credits we have
    614                  * granted from the sequence windows starting
    615                  * at seqnum_low.
    616                  *
    617                  * This gets incremented when new credits are
    618                  * granted and gets decremented when the
    619                  * lowest sequence number is consumed
    620                  * (when seqnum_low gets incremented).
    621                  */
    622                 uint16_t seqnum_range;
    623                 /*
    624                  * credits_grantedThe number of credits we have currently granted
    625                  * to the client.
    626                  *
    627                  * This gets incremented when new credits are
    628                  * granted and gets decremented when any credit
    629                  * is comsumed.
    630                  *
    631                  * Note: the decrementing is different compared
    632                  *       to seqnum_range.
    633                  */
    634                 uint16_t credits_granted;
    635                 /*
    636                  * The maximum number of credits we will ever
    637                  * grant to the client.
    638                  *
    639                  * Typically we will only grant 1/16th of
    640                  * max_credits.
    641                  *
    642                  * This is the "server max credits" parameter.
    643                  */
    644                 uint16_t max_credits;
    645                 /*
    646                  * a bitmap of size max_credits
    647                  */
    648                 struct bitmap *credits_bitmap;
    649                 uint32_t max_trans;
    650                 uint32_t max_read;
    651                 uint32_t max_write;
    652914        } smb2;
     915
     916        /*
     917         * Link into libasys for asynchronous operations
     918         */
     919        struct asys_context *asys_ctx;
     920        struct tevent_fd *asys_fde;
     921
     922        struct smbXsrv_client *client;
    653923};
    654924
    655 extern struct smbd_server_connection *smbd_server_conn;
    656 
    657 struct smbd_server_connection *msg_ctx_to_sconn(struct messaging_context *msg_ctx);
     925extern struct smbXsrv_client *global_smbXsrv_client;
    658926
    659927void smbd_init_globals(void);
Note: See TracChangeset for help on using the changeset viewer.