ac31ce54f038f83ba8ad12626f0fccacc8466198
[nivanova/samba-autobuild/.git] / source3 / smbd / smb2_glue.c
1 /*
2    Unix SMB/CIFS implementation.
3    Core SMB2 server
4
5    Copyright (C) Stefan Metzmacher 2009
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "smbd/globals.h"
23 #include "../libcli/smb/smb_common.h"
24
25 static uint16_t allocate_next_mid(void)
26 {
27         struct smbd_server_connection *sconn = smbd_server_conn;
28
29         sconn->smb2.next_compat_mid++;
30         /* Avoid mid == 0 and mid == 0xffff. */
31         if (sconn->smb2.next_compat_mid == 0xFFFF) {
32                 sconn->smb2.next_compat_mid += 2;
33         }
34         return sconn->smb2.next_compat_mid;
35 }
36
37 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req)
38 {
39         struct smb_request *smbreq;
40         const uint8_t *inhdr;
41         int i = req->current_idx;
42
43         inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
44
45         smbreq = talloc_zero(req, struct smb_request);
46         if (smbreq == NULL) {
47                 return NULL;
48         }
49
50         smbreq->vuid = req->session->compat_vuser->vuid;
51         smbreq->tid = req->tcon->compat_conn->cnum;
52         smbreq->conn = req->tcon->compat_conn;
53         smbreq->smbpid = (uint16_t)IVAL(inhdr, SMB2_HDR_PID);
54         smbreq->flags2 = FLAGS2_UNICODE_STRINGS |
55                          FLAGS2_32_BIT_ERROR_CODES |
56                          FLAGS2_LONG_PATH_COMPONENTS |
57                          FLAGS2_IS_LONG_NAME;
58         if (IVAL(inhdr, SMB2_HDR_FLAGS) & SMB2_HDR_FLAG_DFS) {
59                 smbreq->flags2 |= FLAGS2_DFS_PATHNAMES;
60         }
61         req->compat_mid = smbreq->mid = allocate_next_mid();
62         smbreq->chain_fsp = req->compat_chain_fsp;
63         smbreq->smb2req = req;
64
65         return smbreq;
66 }
67
68 /* Dummy functions for the SMB1 -> SMB2 deferred open message
69  * hooks. */
70
71 void remove_deferred_open_message_smb2(uint16_t mid)
72 {
73 }
74
75 void schedule_deferred_open_message_smb2(uint16_t mid)
76 {
77 }
78
79 bool open_was_deferred_smb2(uint16_t mid)
80 {
81         return false;
82 }
83
84 bool get_deferred_open_message_state_smb2(uint16_t mid,
85                         struct timeval *p_request_time,
86                         void **pp_state)
87 {
88         return false;
89 }
90
91 bool push_deferred_open_message_smb2(struct smb_request *req,
92                                 struct timeval request_time,
93                                 struct timeval timeout,
94                                 char *private_data,
95                                 size_t priv_len)
96 {
97         return false;
98 }