added server side SMB2 signing
[kai/samba.git] / source4 / smb_server / smb_server.h
index a5c2b73dc76d5418db5f37adc5f5aec8d372a00a..ac3e0f3bd3d48da003d436768d18c487dbcd6cc4 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "libcli/raw/request.h"
 #include "libcli/raw/interfaces.h"
 #include "lib/events/events.h"
 #include "lib/socket/socket.h"
+#include "lib/util/dlinklist.h"
 
 /*
   this header declares the core context structures associated with smb
@@ -184,13 +184,14 @@ struct smbsrv_handle {
        /*
         * the value passed over the wire
         * - 16 bit for smb
-        * - 64 bit for smb2
+        * - 32 bit for smb2
         *   Note: for SMB2 handles are 128 bit
-        *         we'll fill the 2nd 64 bit with:
+        *         we'll fill them with
+        *         - 32 bit HID
         *         - 32 bit TID
-        *         - 32 bit 0xFFFFFFFF
+        *         - 64 bit VUID
         */
-       uint64_t hid;
+       uint32_t hid;
 
        /*
         * the ntvfs handle passed to the ntvfs backend
@@ -209,6 +210,8 @@ struct smbsrv_handle {
 /* a set of flags to control handling of request structures */
 #define SMBSRV_REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
 
+#define SMBSRV_REQ_DEFAULT_STR_FLAGS(req) (((req)->flags2 & FLAGS2_UNICODE_STRINGS) ? STR_UNICODE : STR_ASCII)
+
 /* the context for a single SMB request. This is passed to any request-context 
    functions */
 struct smbsrv_request {
@@ -251,36 +254,11 @@ struct smbsrv_request {
        /* the sequence number for signing */
        uint64_t seq_num;
 
-       struct request_buffer in;
-       struct request_buffer out;
+       struct smb_request_buffer in;
+       struct smb_request_buffer out;
 };
 
-/* this contains variables that should be used in % substitutions for
- * smb.conf parameters */
-struct substitute_context {
-       char *remote_arch;
-
-       /* our local netbios name, as give to us by the client */
-       char *local_machine;
-
-       /* the remote netbios name, as give to us by the client */
-       char *remote_machine;
-
-       /* the select remote protocol */
-       char *remote_proto;     
-
-       /* the name of the client as should be displayed in
-        * smbstatus. Can be an IP or a netbios name */
-       char *client_name; 
-
-       /* the username for %U */
-       char *user_name;
-};
-
-/* Remote architectures we know about. */
-enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_WINXP, RA_SAMBA};
-
-enum security_types {SEC_SHARE,SEC_USER} security;
+enum security_types {SEC_SHARE,SEC_USER};
 
 /* smb server context structure. This should contain all the state
  * information associated with a SMB server connection 
@@ -289,14 +267,14 @@ struct smbsrv_connection {
        /* context that has been negotiated between the client and server */
        struct {
                /* have we already done the NBT session establishment? */
-               BOOL done_nbt_session;
+               bool done_nbt_session;
        
                /* only one negprot per connection is allowed */
-               BOOL done_negprot;
+               bool done_negprot;
        
                /* multiple session setups are allowed, but some parameters are
                   ignored in any but the first */
-               BOOL done_sesssetup;
+               bool done_sesssetup;
                
                /* 
                 * Size of data we can send to client. Set
@@ -311,13 +289,9 @@ struct smbsrv_connection {
                 */
                unsigned max_recv; /* init to BUFFER_SIZE */
        
-               /* a guess at the remote architecture. Try not to rely on this - in almost
-                  all cases using these values is the wrong thing to do */
-               enum remote_arch_types ra_type;
-       
                /* the negotiatiated protocol */
                enum protocol_types protocol;
-       
+
                /* authentication context for multi-part negprot */
                struct auth_context *auth_context;
        
@@ -325,7 +299,7 @@ struct smbsrv_connection {
                struct cli_credentials *server_credentials;
        
                /* did we tell the client we support encrypted passwords? */
-               BOOL encrypted_passwords;
+               bool encrypted_passwords;
        
                /* Did we choose SPNEGO, or perhaps raw NTLMSSP, or even no extended security at all? */
                const char *oid;
@@ -347,15 +321,28 @@ struct smbsrv_connection {
        /* context associated with currently valid session setups */
        struct smbsrv_sessions_context sessions;
 
-       /* the server_context holds a linked list of pending requests,
-        * this is used for blocking locks and requests blocked due to oplock
-        * break requests */
-       struct _smbsrv_pending_request {
-               struct _smbsrv_pending_request *next, *prev;
-       
-               /* the request itself - needs to be freed */
-               struct smbsrv_request *request;
-       } *requests;
+       /*
+        * the server_context holds a linked list of pending requests,
+        * this is used for finding the request structures on ntcancel requests
+        * For SMB only
+        */
+       struct smbsrv_request *requests;
+
+       /*
+        * the server_context holds a linked list of pending requests,
+        * and an idtree for finding the request structures on SMB2 Cancel
+        * For SMB2 only
+        */
+       struct {
+               /* an id tree used to allocate ids */
+               struct idr_context *idtree_req;
+
+               /* this is the limit of pending requests values for this connection */
+               uint32_t idtree_limit;
+
+               /* list of open tree connects */
+               struct smb2srv_request *list;
+       } requests2;
 
        struct smb_signing_context signing;
 
@@ -375,7 +362,7 @@ struct smbsrv_connection {
        /* configuration parameters */
        struct {
                enum security_types security;
-               BOOL nt_status_support;
+               bool nt_status_support;
        } config;
 
        /* some statictics for the management tools */
@@ -385,15 +372,31 @@ struct smbsrv_connection {
                /* the time when the last request comes in */
                struct timeval last_request_time;
        } statistics;
+
+       struct share_context *share_context;
+
+       struct loadparm_context *lp_ctx;
+
+       bool doing_signing;
 };
 
+struct model_ops;
+struct loadparm_context;
+
+NTSTATUS smbsrv_add_socket(struct event_context *event_context,
+                          struct loadparm_context *lp_ctx,
+                              const struct model_ops *model_ops,
+                              const char *address);
+
+struct loadparm_context;
+
 #include "smb_server/smb_server_proto.h"
 #include "smb_server/smb/smb_proto.h"
 
 /* useful way of catching wct errors with file and line number */
 #define SMBSRV_CHECK_WCT(req, wcount) do { \
        if ((req)->in.wct != (wcount)) { \
-               DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", \
+               DEBUG(1,("Unexpected WCT %u at %s(%d) - expected %d\n", \
                         (req)->in.wct, __FILE__, __LINE__, wcount)); \
                smbsrv_send_error(req, NT_STATUS_DOS(ERRSRV, ERRerror)); \
                return; \
@@ -414,14 +417,13 @@ struct smbsrv_connection {
        req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req, \
                                          req->session->session_info,\
                                          SVAL(req->in.hdr,HDR_PID), \
-                                         SVAL(req->in.hdr,HDR_MID), \
                                          req->request_time, \
                                          req, send_fn, state); \
        if (!req->ntvfs) { \
                smbsrv_send_error(req, NT_STATUS_NO_MEMORY); \
                return; \
        } \
-       talloc_steal(req->tcon->ntvfs, req); \
+       (void)talloc_steal(req->tcon->ntvfs, req); \
        req->ntvfs->frontend_data.private_data = req; \
 } while (0)
 
@@ -445,6 +447,15 @@ struct smbsrv_connection {
        } \
 } while (0)
 
+#define SMBSRV_CHECK(cmd) do {\
+       NTSTATUS _status; \
+       _status = cmd; \
+       if (!NT_STATUS_IS_OK(_status)) { \
+               smbsrv_send_error(req,  _status); \
+               return; \
+       } \
+} while (0)
+
 /* 
    check if the backend wants to handle the request asynchronously.
    if it wants it handled synchronously then call the send function
@@ -452,7 +463,9 @@ struct smbsrv_connection {
 */
 #define SMBSRV_CALL_NTVFS_BACKEND(cmd) do { \
        req->ntvfs->async_states->status = cmd; \
-       if (!(req->ntvfs->async_states->state & NTVFS_ASYNC_STATE_ASYNC)) { \
+       if (req->ntvfs->async_states->state & NTVFS_ASYNC_STATE_ASYNC) { \
+               DLIST_ADD_END(req->smb_conn->requests, req, struct smbsrv_request *); \
+       } else { \
                req->ntvfs->async_states->send_fn(req->ntvfs); \
        } \
 } while (0)