2009-06-02 13:54:00 +04:00
/*
Unix SMB / CIFS implementation .
Core SMB2 server
Copyright ( C ) Stefan Metzmacher 2009
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 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2009-06-02 13:54:00 +04:00
# include "smbd/globals.h"
2009-08-12 19:52:55 +04:00
# include "../libcli/smb/smb_common.h"
2009-06-02 13:54:00 +04:00
2018-03-21 22:01:05 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_SMB2
2009-06-02 13:54:00 +04:00
struct smb_request * smbd_smb2_fake_smb_request ( struct smbd_smb2_request * req )
{
struct smb_request * smbreq ;
2012-08-05 16:58:57 +04:00
const uint8_t * inhdr = SMBD_SMB2_IN_HDR_PTR ( req ) ;
2009-06-02 13:54:00 +04:00
2013-03-19 23:16:32 +04:00
if ( req - > smb1req ) {
smbreq = req - > smb1req ;
} else {
smbreq = talloc_zero ( req , struct smb_request ) ;
if ( smbreq = = NULL ) {
return NULL ;
}
2009-06-02 13:54:00 +04:00
}
2012-04-11 18:54:17 +04:00
smbreq - > request_time = req - > request_time ;
2012-03-27 13:09:05 +04:00
smbreq - > vuid = req - > session - > compat - > vuid ;
smbreq - > tid = req - > tcon - > compat - > cnum ;
smbreq - > conn = req - > tcon - > compat ;
2010-06-12 14:54:02 +04:00
smbreq - > sconn = req - > sconn ;
2014-06-10 15:34:55 +04:00
smbreq - > xconn = req - > xconn ;
2018-03-22 12:54:41 +03:00
smbreq - > ev_ctx = req - > ev_ctx ;
2009-06-02 13:54:00 +04:00
smbreq - > smbpid = ( uint16_t ) IVAL ( inhdr , SMB2_HDR_PID ) ;
smbreq - > flags2 = FLAGS2_UNICODE_STRINGS |
FLAGS2_32_BIT_ERROR_CODES |
FLAGS2_LONG_PATH_COMPONENTS |
FLAGS2_IS_LONG_NAME ;
2016-08-04 14:59:23 +03:00
2009-06-02 13:54:00 +04:00
if ( IVAL ( inhdr , SMB2_HDR_FLAGS ) & SMB2_HDR_FLAG_DFS ) {
smbreq - > flags2 | = FLAGS2_DFS_PATHNAMES ;
}
2010-04-13 08:40:28 +04:00
smbreq - > mid = BVAL ( inhdr , SMB2_HDR_MESSAGE_ID ) ;
2009-06-05 22:02:21 +04:00
smbreq - > chain_fsp = req - > compat_chain_fsp ;
2010-04-09 09:15:55 +04:00
smbreq - > smb2req = req ;
2010-06-09 08:20:07 +04:00
req - > smb1req = smbreq ;
2009-06-02 13:54:00 +04:00
return smbreq ;
}
2010-06-09 08:20:07 +04:00
2013-03-19 23:24:17 +04:00
/*********************************************************
Are there unread bytes for recvfile ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
size_t smbd_smb2_unread_bytes ( struct smbd_smb2_request * req )
{
if ( req - > smb1req ) {
return req - > smb1req - > unread_bytes ;
}
return 0 ;
}
2010-06-09 08:20:07 +04:00
/*********************************************************
Called from file_free ( ) to remove any chained fsp pointers .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void remove_smb2_chained_fsp ( files_struct * fsp )
{
2010-08-08 10:47:05 +04:00
struct smbd_server_connection * sconn = fsp - > conn - > sconn ;
2014-09-16 09:50:41 +04:00
struct smbXsrv_connection * xconn = NULL ;
2010-06-09 08:20:07 +04:00
2014-09-16 09:50:41 +04:00
if ( sconn - > client ! = NULL ) {
xconn = sconn - > client - > connections ;
}
for ( ; xconn ! = NULL ; xconn = xconn - > next ) {
struct smbd_smb2_request * smb2req ;
for ( smb2req = xconn - > smb2 . requests ; smb2req ; smb2req = smb2req - > next ) {
if ( smb2req - > compat_chain_fsp = = fsp ) {
smb2req - > compat_chain_fsp = NULL ;
}
if ( smb2req - > smb1req & & smb2req - > smb1req - > chain_fsp = = fsp ) {
smb2req - > smb1req - > chain_fsp = NULL ;
}
2010-06-09 08:20:07 +04:00
}
}
}