1998-08-17 11:15:54 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1998-08-17 11:15:54 +04:00
negprot reply code
Copyright ( C ) Andrew Tridgell 1992 - 1998
2007-08-02 22:28:41 +04:00
Copyright ( C ) Volker Lendecke 2007
2010-12-10 21:59:06 +03:00
1998-08-17 11:15:54 +04:00
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-08-17 11:15:54 +04:00
( at your option ) any later version .
2010-12-10 21:59:06 +03:00
1998-08-17 11:15:54 +04:00
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 .
2010-12-10 21:59:06 +03:00
1998-08-17 11:15:54 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-08-17 11:15:54 +04:00
*/
# include "includes.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2009-01-08 14:03:45 +03:00
# include "smbd/globals.h"
2011-02-25 01:05:57 +03:00
# include "serverid.h"
2011-03-24 15:46:20 +03:00
# include "auth.h"
2011-03-24 17:31:06 +03:00
# include "messages.h"
2011-04-14 02:36:23 +04:00
# include "smbprofile.h"
2011-07-26 09:11:47 +04:00
# include "auth/gensec/gensec.h"
2011-11-16 18:06:30 +04:00
# include "../libcli/smb/smb_signing.h"
2020-08-07 21:17:34 +03:00
# include "lib/util/string_wrappers.h"
2022-11-30 18:28:56 +03:00
# include "source3/lib/substitute.h"
1998-08-17 11:15:54 +04:00
2018-09-27 00:46:41 +03:00
/*
* MS - CIFS , 2.2 .4 .52 .2 SMB_COM_NEGOTIATE Response :
* If the server does not support any of the listed dialects , it MUST return a
* DialectIndex of 0 XFFFF
*/
# define NO_PROTOCOL_CHOSEN 0xffff
2015-05-03 07:01:14 +03:00
static void get_challenge ( struct smbXsrv_connection * xconn , uint8_t buff [ 8 ] )
2002-01-05 07:55:41 +03:00
{
NTSTATUS nt_status ;
2006-09-21 04:30:47 +04:00
/* We might be called more than once, multiple negprots are
* permitted */
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . auth_context ) {
2009-05-26 14:48:58 +04:00
DEBUG ( 3 , ( " get challenge: is this a secondary negprot? "
" sconn->negprot.auth_context is non-NULL! \n " ) ) ;
2014-05-21 12:27:50 +04:00
TALLOC_FREE ( xconn - > smb1 . negprot . auth_context ) ;
2002-01-05 07:55:41 +03:00
}
2002-01-21 01:50:23 +03:00
DEBUG ( 10 , ( " get challenge: creating negprot_global_auth_context \n " ) ) ;
2012-02-03 10:09:37 +04:00
nt_status = make_auth4_context (
2014-05-21 12:27:50 +04:00
xconn , & xconn - > smb1 . negprot . auth_context ) ;
2009-05-26 14:48:58 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " make_auth_context_subsystem returned %s " ,
nt_errstr ( nt_status ) ) ) ;
2007-06-16 01:58:49 +04:00
smb_panic ( " cannot make_negprot_global_auth_context! " ) ;
2002-01-05 07:55:41 +03:00
}
2002-01-21 01:50:23 +03:00
DEBUG ( 10 , ( " get challenge: getting challenge \n " ) ) ;
2014-05-21 12:27:50 +04:00
xconn - > smb1 . negprot . auth_context - > get_ntlm_challenge (
xconn - > smb1 . negprot . auth_context , buff ) ;
2002-01-05 07:55:41 +03:00
}
1998-08-17 11:15:54 +04:00
/****************************************************************************
2002-07-15 14:35:28 +04:00
Reply for the lanman 1.0 protocol .
1998-08-17 11:15:54 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 14:35:28 +04:00
2019-11-26 23:43:25 +03:00
static NTSTATUS reply_lanman1 ( struct smb_request * req , uint16_t choice )
1998-08-17 11:15:54 +04:00
{
2002-07-15 14:35:28 +04:00
int secword = 0 ;
time_t t = time ( NULL ) ;
2014-06-11 14:42:56 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-01-15 05:48:40 +04:00
uint16_t raw ;
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
NTSTATUS status ;
2014-01-15 05:48:40 +04:00
if ( lp_async_smb_echo_handler ( ) ) {
raw = 0 ;
} else {
raw = ( lp_read_raw ( ) ? 1 : 0 ) | ( lp_write_raw ( ) ? 2 : 0 ) ;
}
1998-08-17 11:15:54 +04:00
2014-05-21 12:27:50 +04:00
xconn - > smb1 . negprot . encrypted_passwords = lp_encrypt_passwords ( ) ;
2001-09-26 17:55:59 +04:00
2012-06-10 10:08:12 +04:00
secword | = NEGOTIATE_SECURITY_USER_LEVEL ;
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords ) {
2002-07-15 14:35:28 +04:00
secword | = NEGOTIATE_SECURITY_CHALLENGE_RESPONSE ;
2009-05-26 14:48:58 +04:00
}
1998-08-17 11:15:54 +04:00
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 13 , xconn - > smb1 . negprot . encrypted_passwords ? 8 : 0 ) ;
2007-07-23 15:18:20 +04:00
SSVAL ( req - > outbuf , smb_vwv0 , choice ) ;
SSVAL ( req - > outbuf , smb_vwv1 , secword ) ;
2002-07-15 14:35:28 +04:00
/* Create a token value and add it to the outgoing packet. */
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords ) {
2015-05-03 07:01:14 +03:00
get_challenge ( xconn , ( uint8_t * ) smb_buf ( req - > outbuf ) ) ;
2007-07-23 15:18:20 +04:00
SSVAL ( req - > outbuf , smb_vwv11 , 8 ) ;
2002-07-15 14:35:28 +04:00
}
1998-08-17 11:15:54 +04:00
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
status = smbXsrv_connection_init_tables ( xconn , PROTOCOL_LANMAN1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
reply_nterror ( req , status ) ;
2019-11-26 23:43:25 +03:00
return status ;
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
}
1998-08-17 11:15:54 +04:00
2002-07-15 14:35:28 +04:00
/* Reply, SMBlockread, SMBwritelock supported. */
2012-03-24 23:17:08 +04:00
SCVAL ( req - > outbuf , smb_flg , FLAG_REPLY | FLAG_SUPPORT_LOCKREAD ) ;
2014-05-21 12:27:50 +04:00
SSVAL ( req - > outbuf , smb_vwv2 , xconn - > smb1 . negprot . max_recv ) ;
2014-02-04 06:09:09 +04:00
SSVAL ( req - > outbuf , smb_vwv3 , lp_max_mux ( ) ) ; /* maxmux */
2012-03-24 23:17:08 +04:00
SSVAL ( req - > outbuf , smb_vwv4 , 1 ) ;
SSVAL ( req - > outbuf , smb_vwv5 , raw ) ; /* tell redirector we support
2002-07-15 14:35:28 +04:00
readbraw writebraw ( possibly ) */
2012-03-24 23:17:08 +04:00
SIVAL ( req - > outbuf , smb_vwv6 , getpid ( ) ) ;
2007-07-23 15:18:20 +04:00
SSVAL ( req - > outbuf , smb_vwv10 , set_server_zone_offset ( t ) / 60 ) ;
1998-08-17 11:15:54 +04:00
2007-07-23 15:18:20 +04:00
srv_put_dos_date ( ( char * ) req - > outbuf , smb_vwv8 , t ) ;
1998-08-17 11:15:54 +04:00
2019-11-26 23:43:25 +03:00
return NT_STATUS_OK ;
1998-08-17 11:15:54 +04:00
}
/****************************************************************************
2002-07-15 14:35:28 +04:00
Reply for the lanman 2.0 protocol .
1998-08-17 11:15:54 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 14:35:28 +04:00
2019-11-26 23:43:25 +03:00
static NTSTATUS reply_lanman2 ( struct smb_request * req , uint16_t choice )
1998-08-17 11:15:54 +04:00
{
2002-07-15 14:35:28 +04:00
int secword = 0 ;
time_t t = time ( NULL ) ;
2014-06-11 14:42:56 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-01-15 05:48:40 +04:00
uint16_t raw ;
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
NTSTATUS status ;
2014-01-15 05:48:40 +04:00
if ( lp_async_smb_echo_handler ( ) ) {
raw = 0 ;
} else {
raw = ( lp_read_raw ( ) ? 1 : 0 ) | ( lp_write_raw ( ) ? 2 : 0 ) ;
}
1998-08-17 11:15:54 +04:00
2014-05-21 12:27:50 +04:00
xconn - > smb1 . negprot . encrypted_passwords = lp_encrypt_passwords ( ) ;
2010-12-10 21:59:06 +03:00
2012-06-10 10:08:12 +04:00
secword | = NEGOTIATE_SECURITY_USER_LEVEL ;
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords ) {
2002-07-15 14:35:28 +04:00
secword | = NEGOTIATE_SECURITY_CHALLENGE_RESPONSE ;
2009-05-26 14:48:58 +04:00
}
1998-08-17 11:15:54 +04:00
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 13 , xconn - > smb1 . negprot . encrypted_passwords ? 8 : 0 ) ;
2007-07-23 15:18:20 +04:00
2012-03-24 23:17:08 +04:00
SSVAL ( req - > outbuf , smb_vwv0 , choice ) ;
SSVAL ( req - > outbuf , smb_vwv1 , secword ) ;
SIVAL ( req - > outbuf , smb_vwv6 , getpid ( ) ) ;
1998-08-17 11:15:54 +04:00
2002-07-15 14:35:28 +04:00
/* Create a token value and add it to the outgoing packet. */
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords ) {
2015-05-03 07:01:14 +03:00
get_challenge ( xconn , ( uint8_t * ) smb_buf ( req - > outbuf ) ) ;
2007-07-23 15:18:20 +04:00
SSVAL ( req - > outbuf , smb_vwv11 , 8 ) ;
2002-07-15 14:35:28 +04:00
}
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
status = smbXsrv_connection_init_tables ( xconn , PROTOCOL_LANMAN2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
reply_nterror ( req , status ) ;
2019-11-26 23:43:25 +03:00
return status ;
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
}
2002-07-15 14:35:28 +04:00
/* Reply, SMBlockread, SMBwritelock supported. */
2007-07-23 15:18:20 +04:00
SCVAL ( req - > outbuf , smb_flg , FLAG_REPLY | FLAG_SUPPORT_LOCKREAD ) ;
2014-05-21 12:27:50 +04:00
SSVAL ( req - > outbuf , smb_vwv2 , xconn - > smb1 . negprot . max_recv ) ;
2014-02-04 06:09:09 +04:00
SSVAL ( req - > outbuf , smb_vwv3 , lp_max_mux ( ) ) ;
2007-07-23 15:18:20 +04:00
SSVAL ( req - > outbuf , smb_vwv4 , 1 ) ;
SSVAL ( req - > outbuf , smb_vwv5 , raw ) ; /* readbraw and/or writebraw */
SSVAL ( req - > outbuf , smb_vwv10 , set_server_zone_offset ( t ) / 60 ) ;
srv_put_dos_date ( ( char * ) req - > outbuf , smb_vwv8 , t ) ;
2019-11-26 23:43:25 +03:00
return NT_STATUS_OK ;
2002-07-15 14:35:28 +04:00
}
1998-08-17 11:15:54 +04:00
/****************************************************************************
2002-07-15 14:35:28 +04:00
Reply for the nt protocol .
1998-08-17 11:15:54 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 14:35:28 +04:00
2019-11-26 23:43:25 +03:00
static NTSTATUS reply_nt1 ( struct smb_request * req , uint16_t choice )
1998-08-17 11:15:54 +04:00
{
2001-08-27 12:19:43 +04:00
/* dual names + lock_and_read + nt SMBs + remote API calls */
int capabilities = CAP_NT_FIND | CAP_LOCK_AND_READ |
2002-02-28 00:46:53 +03:00
CAP_LEVEL_II_OPLOCKS ;
2001-08-27 12:19:43 +04:00
int secword = 0 ;
2007-10-19 04:40:25 +04:00
bool negotiate_spnego = False ;
2010-05-12 12:50:17 +04:00
struct timespec ts ;
2007-07-23 15:18:20 +04:00
ssize_t ret ;
2014-06-11 14:41:26 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-04-15 12:08:12 +04:00
bool signing_desired = false ;
2011-11-16 18:06:30 +04:00
bool signing_required = false ;
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
NTSTATUS status ;
2001-10-17 12:54:19 +04:00
2014-05-21 12:27:50 +04:00
xconn - > smb1 . negprot . encrypted_passwords = lp_encrypt_passwords ( ) ;
2001-09-26 17:55:59 +04:00
2007-02-09 00:48:09 +03:00
/* Check the flags field to see if this is Vista.
WinXP sets it and Vista does not . But we have to
distinguish from NT which doesn ' t set it either . */
2007-07-23 15:18:20 +04:00
if ( ( req - > flags2 & FLAGS2_EXTENDED_SECURITY ) & &
2011-09-10 00:43:28 +04:00
( ( req - > flags2 & FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED ) = = 0 ) )
2007-02-09 00:48:09 +03:00
{
2014-07-26 19:41:25 +04:00
if ( ( get_remote_arch ( ) ! = RA_SAMBA ) & &
( get_remote_arch ( ) ! = RA_CIFSFS ) ) {
2007-03-16 19:20:47 +03:00
set_remote_arch ( RA_VISTA ) ;
}
2007-02-09 00:48:09 +03:00
}
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 17 , 0 ) ;
2007-07-23 15:18:20 +04:00
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
/* do spnego in user level security if the client
supports it and we can do encrypted passwords */
2010-12-10 21:59:06 +03:00
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords & &
2007-07-23 15:18:20 +04:00
( req - > flags2 & FLAGS2_EXTENDED_SECURITY ) ) {
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
negotiate_spnego = True ;
capabilities | = CAP_EXTENDED_SECURITY ;
2004-08-20 00:03:41 +04:00
add_to_common_flags2 ( FLAGS2_EXTENDED_SECURITY ) ;
2007-07-23 15:18:20 +04:00
/* Ensure FLAGS2_EXTENDED_SECURITY gets set in this reply
( already partially constructed . */
SSVAL ( req - > outbuf , smb_flg2 ,
req - > flags2 | FLAGS2_EXTENDED_SECURITY ) ;
2001-08-27 12:19:43 +04:00
}
2010-12-10 21:59:06 +03:00
2012-07-23 03:14:39 +04:00
capabilities | = CAP_NT_SMBS | CAP_RPC_REMOTE_APIS ;
if ( lp_unicode ( ) ) {
capabilities | = CAP_UNICODE ;
}
2002-09-25 19:19:00 +04:00
2022-01-22 01:49:11 +03:00
if ( lp_smb1_unix_extensions ( ) ) {
2002-09-25 19:19:00 +04:00
capabilities | = CAP_UNIX ;
}
2010-12-10 21:59:06 +03:00
2013-03-19 16:24:46 +04:00
if ( lp_large_readwrite ( ) )
2001-08-27 12:19:43 +04:00
capabilities | = CAP_LARGE_READX | CAP_LARGE_WRITEX | CAP_W2K_SMBS ;
2010-12-10 21:59:06 +03:00
2013-03-19 16:24:46 +04:00
capabilities | = CAP_LARGE_FILES ;
2002-02-28 00:46:53 +03:00
2014-01-15 05:48:40 +04:00
if ( ! lp_async_smb_echo_handler ( ) & & lp_read_raw ( ) & & lp_write_raw ( ) )
2001-08-27 12:19:43 +04:00
capabilities | = CAP_RAW_MODE ;
2010-12-10 21:59:06 +03:00
2002-02-28 00:46:53 +03:00
if ( lp_nt_status_support ( ) )
capabilities | = CAP_STATUS32 ;
2010-12-10 21:59:06 +03:00
2001-09-12 07:08:51 +04:00
if ( lp_host_msdfs ( ) )
2001-08-27 12:19:43 +04:00
capabilities | = CAP_DFS ;
2010-12-10 21:59:06 +03:00
2012-06-10 10:08:12 +04:00
secword | = NEGOTIATE_SECURITY_USER_LEVEL ;
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords ) {
2002-07-15 14:35:28 +04:00
secword | = NEGOTIATE_SECURITY_CHALLENGE_RESPONSE ;
2009-05-26 14:48:58 +04:00
}
2022-03-08 06:34:42 +03:00
signing_desired = smb1_signing_is_desired ( xconn - > smb1 . signing_state ) ;
2022-03-08 06:36:25 +03:00
signing_required = smb1_signing_is_mandatory ( xconn - > smb1 . signing_state ) ;
2011-11-16 18:06:30 +04:00
2014-04-15 12:08:12 +04:00
if ( signing_desired ) {
2012-06-10 10:08:12 +04:00
secword | = NEGOTIATE_SECURITY_SIGNATURES_ENABLED ;
/* No raw mode with smb signing. */
capabilities & = ~ CAP_RAW_MODE ;
if ( signing_required ) {
secword | = NEGOTIATE_SECURITY_SIGNATURES_REQUIRED ;
2003-07-18 04:53:34 +04:00
}
2003-07-17 04:48:21 +04:00
}
2007-07-23 15:18:20 +04:00
SSVAL ( req - > outbuf , smb_vwv0 , choice ) ;
SCVAL ( req - > outbuf , smb_vwv1 , secword ) ;
2010-12-10 21:59:06 +03:00
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
status = smbXsrv_connection_init_tables ( xconn , PROTOCOL_NT1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
reply_nterror ( req , status ) ;
2019-11-26 23:43:25 +03:00
return status ;
s3:smbd: Do not crash if we fail to init the session table
This should the following segfault with SMB1:
#6 sig_fault (sig=<optimized out>) at ../lib/util/fault.c:94
#7 <signal handler called>
#8 smbXsrv_session_create (conn=conn@entry=0x5654d3512af0, now=now@entry=131594481900356690, _session=_session@entry=0x7ffc93a778e8)
at ../source3/smbd/smbXsrv_session.c:1212
#9 0x00007f7618aa21ef in reply_sesssetup_and_X (req=req@entry=0x5654d35174b0) at ../source3/smbd/sesssetup.c:961
#10 0x00007f7618ae17b0 in switch_message (type=<optimized out>, req=req@entry=0x5654d35174b0) at ../source3/smbd/process.c:1726
#11 0x00007f7618ae3550 in construct_reply (deferred_pcd=0x0, encrypted=false, seqnum=0, unread_bytes=0, size=140, inbuf=0x0, xconn=0x5654d35146d0)
at ../source3/smbd/process.c:1762
#12 process_smb (xconn=xconn@entry=0x5654d3512af0, inbuf=<optimized out>, nread=140, unread_bytes=0, seqnum=0, encrypted=<optimized out>,
deferred_pcd=deferred_pcd@entry=0x0) at ../source3/smbd/process.c:2008
#13 0x00007f7618ae4c41 in smbd_server_connection_read_handler (xconn=0x5654d3512af0, fd=40) at ../source3/smbd/process.c:2608
#14 0x00007f761587eedb in epoll_event_loop_once () from /lib64/libtevent.so.0
Inspection the core shows that:
conn->client-session_table is NULL
conn->protocol is PROTOCOL_NONE
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13315
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-02-19 20:07:50 +03:00
}
2010-12-10 21:59:06 +03:00
2014-02-04 06:09:09 +04:00
SSVAL ( req - > outbuf , smb_vwv1 + 1 , lp_max_mux ( ) ) ; /* maxmpx */
2012-03-24 23:17:08 +04:00
SSVAL ( req - > outbuf , smb_vwv2 + 1 , 1 ) ; /* num vcs */
2009-05-26 16:56:08 +04:00
SIVAL ( req - > outbuf , smb_vwv3 + 1 ,
2014-05-21 12:27:50 +04:00
xconn - > smb1 . negprot . max_recv ) ; /* max buffer. LOTS! */
2012-03-24 23:17:08 +04:00
SIVAL ( req - > outbuf , smb_vwv5 + 1 , 0x10000 ) ; /* raw size. full 64k */
SIVAL ( req - > outbuf , smb_vwv7 + 1 , getpid ( ) ) ; /* session key */
SIVAL ( req - > outbuf , smb_vwv9 + 1 , capabilities ) ; /* capabilities */
2010-05-12 12:50:17 +04:00
clock_gettime ( CLOCK_REALTIME , & ts ) ;
2019-11-30 23:29:07 +03:00
put_long_date_full_timespec ( TIMESTAMP_SET_NT_OR_BETTER , ( char * ) req - > outbuf + smb_vwv11 + 1 , & ts ) ;
2010-05-12 12:50:17 +04:00
SSVALS ( req - > outbuf , smb_vwv15 + 1 , set_server_zone_offset ( ts . tv_sec ) / 60 ) ;
2010-12-10 21:59:06 +03:00
2001-10-17 12:54:19 +04:00
if ( ! negotiate_spnego ) {
2002-01-05 07:55:41 +03:00
/* Create a token value and add it to the outgoing packet. */
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . encrypted_passwords ) {
2015-05-03 07:01:14 +03:00
uint8_t chal [ 8 ] ;
2002-08-17 19:27:10 +04:00
/* note that we do not send a challenge at all if
we are using plaintext */
2014-06-11 14:42:56 +04:00
get_challenge ( xconn , chal ) ;
2007-07-23 15:18:20 +04:00
ret = message_push_blob (
& req - > outbuf , data_blob_const ( chal , sizeof ( chal ) ) ) ;
if ( ret = = - 1 ) {
DEBUG ( 0 , ( " Could not push challenge \n " ) ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2019-11-26 23:43:25 +03:00
return NT_STATUS_NO_MEMORY ;
2007-07-23 15:18:20 +04:00
}
SCVAL ( req - > outbuf , smb_vwv16 + 1 , ret ) ;
}
ret = message_push_string ( & req - > outbuf , lp_workgroup ( ) ,
STR_UNICODE | STR_TERMINATE
| STR_NOALIGN ) ;
if ( ret = = - 1 ) {
2010-11-29 23:36:05 +03:00
DEBUG ( 0 , ( " Could not push workgroup string \n " ) ) ;
2007-07-23 15:18:20 +04:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2019-11-26 23:43:25 +03:00
return NT_STATUS_NO_MEMORY ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
}
2011-11-04 16:49:05 +04:00
ret = message_push_string ( & req - > outbuf , lp_netbios_name ( ) ,
STR_UNICODE | STR_TERMINATE
| STR_NOALIGN ) ;
if ( ret = = - 1 ) {
DEBUG ( 0 , ( " Could not push netbios name string \n " ) ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2019-11-26 23:43:25 +03:00
return NT_STATUS_NO_MEMORY ;
2011-11-04 16:49:05 +04:00
}
2001-10-31 09:24:25 +03:00
DEBUG ( 3 , ( " not using SPNEGO \n " ) ) ;
2001-10-17 12:54:19 +04:00
} else {
2014-06-11 14:41:26 +04:00
DATA_BLOB spnego_blob = negprot_spnego ( req , xconn ) ;
2006-09-21 09:29:07 +04:00
if ( spnego_blob . data = = NULL ) {
2007-07-23 15:18:20 +04:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2019-11-26 23:43:25 +03:00
return NT_STATUS_NO_MEMORY ;
2006-09-21 09:29:07 +04:00
}
2007-07-23 15:18:20 +04:00
ret = message_push_blob ( & req - > outbuf , spnego_blob ) ;
if ( ret = = - 1 ) {
DEBUG ( 0 , ( " Could not push spnego blob \n " ) ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2019-11-26 23:43:25 +03:00
return NT_STATUS_NO_MEMORY ;
2007-07-23 15:18:20 +04:00
}
2006-09-21 09:29:07 +04:00
data_blob_free ( & spnego_blob ) ;
2007-07-23 15:18:20 +04:00
SCVAL ( req - > outbuf , smb_vwv16 + 1 , 0 ) ;
2001-10-31 09:24:25 +03:00
DEBUG ( 3 , ( " using SPNEGO \n " ) ) ;
2001-10-17 12:54:19 +04:00
}
2007-07-23 15:18:20 +04:00
2019-11-26 23:43:25 +03:00
return NT_STATUS_OK ;
1998-08-17 11:15:54 +04:00
}
/* these are the protocol lists used for auto architecture detection:
WinNT 3.51 :
protocol [ PC NETWORK PROGRAM 1.0 ]
protocol [ XENIX CORE ]
protocol [ MICROSOFT NETWORKS 1.03 ]
protocol [ LANMAN1 .0 ]
protocol [ Windows for Workgroups 3.1 a ]
protocol [ LM1 .2 X002 ]
protocol [ LANMAN2 .1 ]
protocol [ NT LM 0.12 ]
Win95 :
protocol [ PC NETWORK PROGRAM 1.0 ]
protocol [ XENIX CORE ]
protocol [ MICROSOFT NETWORKS 1.03 ]
protocol [ LANMAN1 .0 ]
protocol [ Windows for Workgroups 3.1 a ]
protocol [ LM1 .2 X002 ]
protocol [ LANMAN2 .1 ]
protocol [ NT LM 0.12 ]
1999-12-13 16:27:58 +03:00
Win2K :
protocol [ PC NETWORK PROGRAM 1.0 ]
protocol [ LANMAN1 .0 ]
protocol [ Windows for Workgroups 3.1 a ]
protocol [ LM1 .2 X002 ]
protocol [ LANMAN2 .1 ]
protocol [ NT LM 0.12 ]
2007-02-09 00:48:09 +03:00
Vista :
protocol [ PC NETWORK PROGRAM 1.0 ]
protocol [ LANMAN1 .0 ]
protocol [ Windows for Workgroups 3.1 a ]
protocol [ LM1 .2 X002 ]
protocol [ LANMAN2 .1 ]
protocol [ NT LM 0.12 ]
protocol [ SMB 2.001 ]
1998-08-17 11:15:54 +04:00
OS / 2 :
protocol [ PC NETWORK PROGRAM 1.0 ]
protocol [ XENIX CORE ]
protocol [ LANMAN1 .0 ]
protocol [ LM1 .2 X002 ]
protocol [ LANMAN2 .1 ]
2016-03-02 21:19:56 +03:00
OSX :
protocol [ NT LM 0.12 ]
protocol [ SMB 2.002 ]
protocol [ SMB 2. ? ? ? ]
1998-08-17 11:15:54 +04:00
*/
/*
* Modified to recognize the architecture of the remote machine better .
*
* This appears to be the matrix of which protocol is used by which
2016-03-02 21:19:56 +03:00
* product .
Protocol WfWg Win95 WinNT Win2K OS / 2 Vista OSX
PC NETWORK PROGRAM 1.0 1 1 1 1 1 1
XENIX CORE 2 2
MICROSOFT NETWORKS 3.0 2 2
DOS LM1 .2 X002 3 3
MICROSOFT NETWORKS 1.03 3
DOS LANMAN2 .1 4 4
LANMAN1 .0 4 2 3 2
Windows for Workgroups 3.1 a 5 5 5 3 3
LM1 .2 X002 6 4 4 4
LANMAN2 .1 7 5 5 5
NT LM 0.12 6 8 6 6 6 1
SMB 2.001 7
SMB 2.002 2
SMB 2. ? ? ? 3
1998-08-17 11:15:54 +04:00
*
* tim @ fsg . com 09 / 29 / 95
1999-12-13 16:27:58 +03:00
* Win2K added by matty 17 / 7 / 99
1998-08-17 11:15:54 +04:00
*/
2010-12-10 21:59:06 +03:00
2016-03-02 21:18:34 +03:00
# define PROT_PC_NETWORK_PROGRAM_1_0 0x0001
# define PROT_XENIX_CORE 0x0002
# define PROT_MICROSOFT_NETWORKS_3_0 0x0004
# define PROT_DOS_LM1_2X002 0x0008
# define PROT_MICROSOFT_NETWORKS_1_03 0x0010
# define PROT_DOS_LANMAN2_1 0x0020
# define PROT_LANMAN1_0 0x0040
# define PROT_WFWG 0x0080
# define PROT_LM1_2X002 0x0100
# define PROT_LANMAN2_1 0x0200
# define PROT_NT_LM_0_12 0x0400
# define PROT_SMB_2_001 0x0800
# define PROT_SMB_2_002 0x1000
# define PROT_SMB_2_FF 0x2000
# define PROT_SAMBA 0x4000
# define PROT_POSIX_2 0x8000
# define ARCH_WFWG ( PROT_PC_NETWORK_PROGRAM_1_0 | PROT_MICROSOFT_NETWORKS_3_0 | \
PROT_DOS_LM1_2X002 | PROT_DOS_LANMAN2_1 | PROT_WFWG )
# define ARCH_WIN95 ( ARCH_WFWG | PROT_NT_LM_0_12 )
# define ARCH_WINNT ( PROT_PC_NETWORK_PROGRAM_1_0 | PROT_XENIX_CORE | \
PROT_MICROSOFT_NETWORKS_1_03 | PROT_LANMAN1_0 | PROT_WFWG | \
PROT_LM1_2X002 | PROT_LANMAN2_1 | PROT_NT_LM_0_12 )
# define ARCH_WIN2K ( ARCH_WINNT & ~(PROT_XENIX_CORE | PROT_MICROSOFT_NETWORKS_1_03) )
# define ARCH_OS2 ( ARCH_WINNT & ~(PROT_MICROSOFT_NETWORKS_1_03 | PROT_WFWG) )
# define ARCH_VISTA ( ARCH_WIN2K | PROT_SMB_2_001 )
# define ARCH_SAMBA ( PROT_SAMBA )
# define ARCH_CIFSFS ( PROT_POSIX_2 )
2016-03-02 21:19:56 +03:00
# define ARCH_OSX ( PROT_NT_LM_0_12 | PROT_SMB_2_002 | PROT_SMB_2_FF )
2010-12-10 21:59:06 +03:00
1998-08-17 11:15:54 +04:00
/* List of supported protocols, most desired first */
2003-01-03 11:28:12 +03:00
static const struct {
const char * proto_name ;
const char * short_name ;
2019-11-26 23:43:25 +03:00
NTSTATUS ( * proto_reply_fn ) ( struct smb_request * req , uint16_t choice ) ;
2002-07-15 14:35:28 +04:00
int protocol_level ;
1998-08-17 11:15:54 +04:00
} supported_protocols [ ] = {
2011-09-05 15:14:40 +04:00
{ " SMB 2.??? " , " SMB2_FF " , reply_smb20ff , PROTOCOL_SMB2_10 } ,
2011-07-12 00:23:56 +04:00
{ " SMB 2.002 " , " SMB2_02 " , reply_smb2002 , PROTOCOL_SMB2_02 } ,
2002-07-15 14:35:28 +04:00
{ " NT LANMAN 1.0 " , " NT1 " , reply_nt1 , PROTOCOL_NT1 } ,
{ " NT LM 0.12 " , " NT1 " , reply_nt1 , PROTOCOL_NT1 } ,
2004-06-15 22:36:45 +04:00
{ " POSIX 2 " , " NT1 " , reply_nt1 , PROTOCOL_NT1 } ,
2005-03-26 03:44:46 +03:00
{ " LANMAN2.1 " , " LANMAN2 " , reply_lanman2 , PROTOCOL_LANMAN2 } ,
2002-07-15 14:35:28 +04:00
{ " LM1.2X002 " , " LANMAN2 " , reply_lanman2 , PROTOCOL_LANMAN2 } ,
{ " Samba " , " LANMAN2 " , reply_lanman2 , PROTOCOL_LANMAN2 } ,
{ " DOS LM1.2X002 " , " LANMAN2 " , reply_lanman2 , PROTOCOL_LANMAN2 } ,
{ " LANMAN1.0 " , " LANMAN1 " , reply_lanman1 , PROTOCOL_LANMAN1 } ,
{ " MICROSOFT NETWORKS 3.0 " , " LANMAN1 " , reply_lanman1 , PROTOCOL_LANMAN1 } ,
{ NULL , NULL , NULL , 0 } ,
1998-08-17 11:15:54 +04:00
} ;
/****************************************************************************
2002-07-15 14:35:28 +04:00
Reply to a negprot .
2006-06-20 06:38:28 +04:00
conn POINTER CAN BE NULL HERE !
1998-08-17 11:15:54 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 14:35:28 +04:00
2008-01-05 02:37:24 +03:00
void reply_negprot ( struct smb_request * req )
1998-08-17 11:15:54 +04:00
{
2018-03-22 13:49:18 +03:00
size_t choice = 0 ;
2013-08-14 14:46:46 +04:00
int chosen_level = - 1 ;
2018-03-22 13:49:18 +03:00
bool choice_set = false ;
2002-07-15 14:35:28 +04:00
int protocol ;
2008-11-01 19:35:48 +03:00
const char * p ;
2016-03-02 21:18:34 +03:00
int protocols = 0 ;
2007-07-23 15:08:43 +04:00
int num_cliprotos ;
char * * cliprotos ;
2018-03-22 13:49:18 +03:00
size_t i ;
2008-04-30 01:36:24 +04:00
size_t converted_size ;
2014-06-11 14:42:56 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-06-11 14:42:56 +04:00
struct smbd_server_connection * sconn = req - > sconn ;
2015-07-15 11:57:03 +03:00
bool signing_required = true ;
2017-01-18 10:37:30 +03:00
int max_proto ;
int min_proto ;
2019-11-26 23:46:16 +03:00
NTSTATUS status ;
2002-08-17 19:27:10 +04:00
2002-07-15 14:35:28 +04:00
START_PROFILE ( SMBnegprot ) ;
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . done ) {
2002-08-17 19:27:10 +04:00
END_PROFILE ( SMBnegprot ) ;
2006-12-18 07:25:21 +03:00
exit_server_cleanly ( " multiple negprot's are not permitted " ) ;
2002-08-17 19:27:10 +04:00
}
2008-11-03 00:09:51 +03:00
if ( req - > buflen = = 0 ) {
DEBUG ( 0 , ( " negprot got no protocols \n " ) ) ;
reply_nterror ( req , NT_STATUS_INVALID_PARAMETER ) ;
END_PROFILE ( SMBnegprot ) ;
return ;
}
if ( req - > buf [ req - > buflen - 1 ] ! = ' \0 ' ) {
2007-07-23 15:08:43 +04:00
DEBUG ( 0 , ( " negprot protocols not 0-terminated \n " ) ) ;
2007-07-23 15:18:20 +04:00
reply_nterror ( req , NT_STATUS_INVALID_PARAMETER ) ;
2007-07-23 15:08:43 +04:00
END_PROFILE ( SMBnegprot ) ;
2007-07-23 15:18:20 +04:00
return ;
2007-07-23 15:08:43 +04:00
}
2008-11-01 19:35:48 +03:00
p = ( const char * ) req - > buf + 1 ;
2007-07-23 15:08:43 +04:00
num_cliprotos = 0 ;
cliprotos = NULL ;
2008-11-02 03:21:53 +03:00
while ( smbreq_bufrem ( req , p ) > 0 ) {
2007-07-23 18:36:54 +04:00
2007-07-23 23:46:48 +04:00
char * * tmp ;
2007-07-23 18:36:54 +04:00
2011-06-07 05:10:15 +04:00
tmp = talloc_realloc ( talloc_tos ( ) , cliprotos , char * ,
2007-07-23 15:08:43 +04:00
num_cliprotos + 1 ) ;
if ( tmp = = NULL ) {
DEBUG ( 0 , ( " talloc failed \n " ) ) ;
TALLOC_FREE ( cliprotos ) ;
2007-07-23 15:18:20 +04:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2007-07-23 15:08:43 +04:00
END_PROFILE ( SMBnegprot ) ;
2007-07-23 15:18:20 +04:00
return ;
2007-07-23 15:08:43 +04:00
}
cliprotos = tmp ;
2008-04-30 01:36:24 +04:00
if ( ! pull_ascii_talloc ( cliprotos , & cliprotos [ num_cliprotos ] , p ,
& converted_size ) ) {
2007-07-23 15:08:43 +04:00
DEBUG ( 0 , ( " pull_ascii_talloc failed \n " ) ) ;
TALLOC_FREE ( cliprotos ) ;
2007-07-23 15:18:20 +04:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2007-07-23 15:08:43 +04:00
END_PROFILE ( SMBnegprot ) ;
2007-07-23 15:18:20 +04:00
return ;
2007-07-23 15:08:43 +04:00
}
DEBUG ( 3 , ( " Requested protocol [%s] \n " ,
cliprotos [ num_cliprotos ] ) ) ;
num_cliprotos + = 1 ;
2007-07-23 23:46:48 +04:00
p + = strlen ( p ) + 2 ;
2007-07-23 15:08:43 +04:00
}
for ( i = 0 ; i < num_cliprotos ; i + + ) {
2016-03-02 21:18:34 +03:00
if ( strcsequal ( cliprotos [ i ] , " Windows for Workgroups 3.1a " ) ) {
protocols | = PROT_WFWG ;
} else if ( strcsequal ( cliprotos [ i ] , " DOS LM1.2X002 " ) ) {
protocols | = PROT_DOS_LM1_2X002 ;
} else if ( strcsequal ( cliprotos [ i ] , " DOS LANMAN2.1 " ) ) {
protocols | = PROT_DOS_LANMAN2_1 ;
} else if ( strcsequal ( cliprotos [ i ] , " LANMAN1.0 " ) ) {
protocols | = PROT_LANMAN1_0 ;
} else if ( strcsequal ( cliprotos [ i ] , " NT LM 0.12 " ) ) {
protocols | = PROT_NT_LM_0_12 ;
} else if ( strcsequal ( cliprotos [ i ] , " SMB 2.001 " ) ) {
protocols | = PROT_SMB_2_001 ;
} else if ( strcsequal ( cliprotos [ i ] , " SMB 2.002 " ) ) {
protocols | = PROT_SMB_2_002 ;
} else if ( strcsequal ( cliprotos [ i ] , " SMB 2.??? " ) ) {
protocols | = PROT_SMB_2_FF ;
} else if ( strcsequal ( cliprotos [ i ] , " LANMAN2.1 " ) ) {
protocols | = PROT_LANMAN2_1 ;
} else if ( strcsequal ( cliprotos [ i ] , " LM1.2X002 " ) ) {
protocols | = PROT_LM1_2X002 ;
} else if ( strcsequal ( cliprotos [ i ] , " MICROSOFT NETWORKS 1.03 " ) ) {
protocols | = PROT_MICROSOFT_NETWORKS_1_03 ;
} else if ( strcsequal ( cliprotos [ i ] , " MICROSOFT NETWORKS 3.0 " ) ) {
protocols | = PROT_MICROSOFT_NETWORKS_3_0 ;
} else if ( strcsequal ( cliprotos [ i ] , " PC NETWORK PROGRAM 1.0 " ) ) {
protocols | = PROT_PC_NETWORK_PROGRAM_1_0 ;
} else if ( strcsequal ( cliprotos [ i ] , " XENIX CORE " ) ) {
protocols | = PROT_XENIX_CORE ;
} else if ( strcsequal ( cliprotos [ i ] , " Samba " ) ) {
protocols = PROT_SAMBA ;
2002-07-15 14:35:28 +04:00
break ;
2007-07-23 15:08:43 +04:00
} else if ( strcsequal ( cliprotos [ i ] , " POSIX 2 " ) ) {
2016-03-02 21:18:34 +03:00
protocols = PROT_POSIX_2 ;
2004-06-15 22:36:45 +04:00
break ;
2002-07-15 14:35:28 +04:00
}
}
2004-06-15 22:36:45 +04:00
2016-03-02 21:18:34 +03:00
switch ( protocols ) {
/* Old CIFSFS can send one arch only, NT LM 0.12. */
case PROT_NT_LM_0_12 :
2004-06-15 22:36:45 +04:00
case ARCH_CIFSFS :
set_remote_arch ( RA_CIFSFS ) ;
break ;
2002-07-15 14:35:28 +04:00
case ARCH_SAMBA :
set_remote_arch ( RA_SAMBA ) ;
break ;
case ARCH_WFWG :
set_remote_arch ( RA_WFWG ) ;
break ;
case ARCH_WIN95 :
set_remote_arch ( RA_WIN95 ) ;
break ;
case ARCH_WINNT :
2016-03-02 21:18:34 +03:00
set_remote_arch ( RA_WINNT ) ;
2002-07-15 14:35:28 +04:00
break ;
case ARCH_WIN2K :
2016-03-02 21:18:34 +03:00
set_remote_arch ( RA_WIN2K ) ;
2007-02-09 00:48:09 +03:00
break ;
case ARCH_VISTA :
set_remote_arch ( RA_VISTA ) ;
2002-07-15 14:35:28 +04:00
break ;
case ARCH_OS2 :
set_remote_arch ( RA_OS2 ) ;
break ;
2016-03-02 21:19:56 +03:00
case ARCH_OSX :
set_remote_arch ( RA_OSX ) ;
break ;
2002-07-15 14:35:28 +04:00
default :
set_remote_arch ( RA_UNKNOWN ) ;
break ;
}
2010-12-10 21:59:06 +03:00
2002-07-15 14:35:28 +04:00
/* possibly reload - change of architecture */
2011-12-14 16:25:20 +04:00
reload_services ( sconn , conn_snum_used , true ) ;
2010-12-10 21:59:06 +03:00
2017-01-18 10:37:30 +03:00
/*
* Anything higher than PROTOCOL_SMB2_10 still
* needs to go via " SMB 2.??? " , which is marked
* as PROTOCOL_SMB2_10 .
*
* The real negotiation happens via reply_smb20ff ( )
* using SMB2 Negotiation .
*/
max_proto = lp_server_max_protocol ( ) ;
if ( max_proto > PROTOCOL_SMB2_10 ) {
max_proto = PROTOCOL_SMB2_10 ;
}
min_proto = lp_server_min_protocol ( ) ;
if ( min_proto > PROTOCOL_SMB2_10 ) {
min_proto = PROTOCOL_SMB2_10 ;
}
2002-07-15 14:35:28 +04:00
/* Check for protocols, most desirable first */
for ( protocol = 0 ; supported_protocols [ protocol ] . proto_name ; protocol + + ) {
2007-07-23 15:08:43 +04:00
i = 0 ;
2017-01-18 10:37:30 +03:00
if ( ( supported_protocols [ protocol ] . protocol_level < = max_proto ) & &
( supported_protocols [ protocol ] . protocol_level > = min_proto ) )
2007-07-23 15:08:43 +04:00
while ( i < num_cliprotos ) {
2013-08-14 14:46:46 +04:00
if ( strequal ( cliprotos [ i ] , supported_protocols [ protocol ] . proto_name ) ) {
2007-07-23 15:08:43 +04:00
choice = i ;
2013-08-14 14:46:46 +04:00
chosen_level = supported_protocols [ protocol ] . protocol_level ;
2018-03-22 13:49:18 +03:00
choice_set = true ;
2013-08-14 14:46:46 +04:00
}
2007-07-23 15:08:43 +04:00
i + + ;
2002-07-15 14:35:28 +04:00
}
2018-03-22 13:49:18 +03:00
if ( choice_set ) {
2002-07-15 14:35:28 +04:00
break ;
2018-03-22 13:49:18 +03:00
}
2002-07-15 14:35:28 +04:00
}
2010-12-10 21:59:06 +03:00
2018-03-22 13:49:18 +03:00
if ( ! choice_set ) {
2017-02-28 18:03:45 +03:00
bool ok ;
2016-09-09 00:16:18 +03:00
DBG_NOTICE ( " No protocol supported ! \n " ) ;
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 1 , 0 ) ;
2018-09-27 00:46:41 +03:00
SSVAL ( req - > outbuf , smb_vwv0 , NO_PROTOCOL_CHOSEN ) ;
2017-02-28 18:03:45 +03:00
2022-03-31 22:09:13 +03:00
ok = smb1_srv_send ( xconn , ( char * ) req - > outbuf ,
2017-02-28 18:03:45 +03:00
false , 0 , false , NULL ) ;
if ( ! ok ) {
2022-03-31 22:09:13 +03:00
DBG_NOTICE ( " smb1_srv_send failed \n " ) ;
2017-02-28 18:03:45 +03:00
}
exit_server_cleanly ( " no protocol supported \n " ) ;
2002-07-15 14:35:28 +04:00
}
2010-12-10 21:59:06 +03:00
2022-11-30 18:28:56 +03:00
set_remote_proto ( supported_protocols [ protocol ] . short_name ) ;
2017-02-28 18:03:45 +03:00
reload_services ( sconn , conn_snum_used , true ) ;
2019-11-26 23:46:16 +03:00
status = supported_protocols [ protocol ] . proto_reply_fn ( req , choice ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
exit_server_cleanly ( " negprot function failed \n " ) ;
}
2017-02-28 18:03:45 +03:00
DEBUG ( 3 , ( " Selected protocol %s \n " , supported_protocols [ protocol ] . proto_name ) ) ;
2018-03-22 13:49:18 +03:00
DBG_INFO ( " negprot index=%zu \n " , choice ) ;
1998-08-17 11:15:54 +04:00
2019-11-26 23:53:09 +03:00
xconn - > smb1 . negprot . done = true ;
2015-07-15 11:57:03 +03:00
/* We always have xconn->smb1.signing_state also for >= SMB2_02 */
2022-03-08 06:36:25 +03:00
signing_required = smb1_signing_is_mandatory ( xconn - > smb1 . signing_state ) ;
2015-07-15 11:57:03 +03:00
if ( signing_required & & ( chosen_level < PROTOCOL_NT1 ) ) {
2006-12-18 07:25:21 +03:00
exit_server_cleanly ( " SMB signing is required and "
" client negotiated a downlevel protocol " ) ;
2003-07-17 04:48:21 +04:00
}
2007-07-23 15:08:43 +04:00
TALLOC_FREE ( cliprotos ) ;
2011-05-20 15:07:17 +04:00
2013-08-14 14:46:46 +04:00
if ( lp_async_smb_echo_handler ( ) & & ( chosen_level < PROTOCOL_SMB2_02 ) & &
2014-06-12 10:43:26 +04:00
! fork_echo_handler ( xconn ) ) {
2011-05-20 15:07:17 +04:00
exit_server ( " Failed to fork echo handler " ) ;
}
2002-07-15 14:35:28 +04:00
END_PROFILE ( SMBnegprot ) ;
2007-07-23 15:18:20 +04:00
return ;
1998-08-17 11:15:54 +04:00
}