r17930: Merge noinclude branch:
[kai/samba.git] / source4 / smb_server / smb_server.h
index f479bc35b42b9516069c222bc598741d6bf5709d..e0913db030755567ebdc8a15c311bd80ae22d1ec 100644 (file)
@@ -24,6 +24,7 @@
 #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
@@ -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 {
@@ -255,31 +258,6 @@ struct smbsrv_request {
        struct 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};
 
 /* smb server context structure. This should contain all the state
@@ -311,10 +289,6 @@ 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;
        
@@ -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;
 
@@ -385,6 +372,8 @@ struct smbsrv_connection {
                /* the time when the last request comes in */
                struct timeval last_request_time;
        } statistics;
+
+       struct share_context *share_context;
 };
 
 #include "smb_server/smb_server_proto.h"
@@ -414,14 +403,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 +433,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 +449,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)