2019-10-03 20:38:31 +03:00
/*
2003-12-14 04:09:10 +03:00
Unix SMB / CIFS implementation .
server side dcerpc authentication code
Copyright ( C ) Andrew Tridgell 2003
r1294: A nice, large, commit...
This implements gensec for Samba's server side, and brings gensec up
to the standards of a full subsystem.
This means that use of the subsystem is by gensec_* functions, not
function pointers in structures (this is internal). This causes
changes in all the existing gensec users.
Our RPC server no longer contains it's own generalised security
scheme, and now calls gensec directly.
Gensec has also taken over the role of auth/auth_ntlmssp.c
An important part of gensec, is the output of the 'session_info'
struct. This is now reference counted, so that we can correctly free
it when a pipe is closed, no matter if it was inherited, or created by
per-pipe authentication.
The schannel code is reworked, to be in the same file for client and
server.
ntlm_auth is reworked to use gensec.
The major problem with this code is the way it relies on subsystem
auto-initialisation. The primary reason for this commit now.is to
allow these problems to be looked at, and fixed.
There are problems with the new code:
- I've tested it with smbtorture, but currently don't have VMware and
valgrind working (this I'll fix soon).
- The SPNEGO code is client-only at this point.
- We still do not do kerberos.
Andrew Bartlett
(This used to be commit 07fd885fd488fd1051eacc905a2d4962f8a018ec)
2004-06-29 13:40:10 +04:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2004
This patch adds a better dcerpc server infastructure.
1.) We now register endpoint servers add startup via register_backend()
and later use the smb.conf 'dcerpc endpoint servers' parameter to setup the dcesrv_context
2.) each endpoint server can register at context creation time as much interfaces as it wants
(multiple interfaces on one endpoint are supported!)
(NOTE: there's a difference between 'endpoint server' and 'endpoint'!
for details look at rpc_server/dcesrv_server.h)
3.) one endpoint can have a security descriptor registered to it self
this will be checked in the future when a client wants to connect
to an smb pipe endpoint.
4.) we now have a 'remote' endpoint server, which works like the ntvfs_cifs module
it takes this options in the [globals] section:
dcerpc remote:interfaces = srvsvc, winreg, w32time, epmapper
dcerpc remote:binding = ...
dcerpc remote:user = ...
dcerpc remote:password = ...
5.) we currently have tree endpoint servers: epmapper, rpcecho and remote
the default for the 'dcerpc endpiont servers = epmapper, rpcecho'
for testing you can also do
dcerpc endpoint servers = rpcecho, remote, epmapper
dcerpc remote:interfaces = srvsvc, samr, netlogon
6,) please notice the the epmapper now only returns NO_ENTRIES
(but I think we'll find a solution for this too:-)
7.) also there're some other stuff left, but step by step :-)
This patch also includes updates for the
register_subsystem() , ntvfs_init(), and some other funtions
to check for duplicate subsystem registration
metze
(hmmm, my first large commit...I hope it works as supposed :-)
(This used to be commit 917e45dafd5be4c2cd90ff425b8d6f8403122349)
2004-01-09 01:55:27 +03:00
2003-12-14 04:09:10 +03: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-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-12-14 04:09:10 +03:00
( at your option ) any later version .
2019-10-03 20:38:31 +03:00
2003-12-14 04:09:10 +03: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 .
2019-10-03 20:38:31 +03:00
2003-12-14 04:09:10 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-12-14 04:09:10 +03:00
*/
# include "includes.h"
2019-10-03 20:38:31 +03:00
# include "librpc/rpc/dcesrv_core.h"
# include "librpc/rpc/dcesrv_core_proto.h"
2021-04-02 13:20:38 +03:00
# include "librpc/rpc/dcerpc_util.h"
2021-04-02 14:41:21 +03:00
# include "librpc/rpc/dcerpc_pkt_auth.h"
2005-07-28 04:27:28 +04:00
# include "librpc/gen_ndr/ndr_dcerpc.h"
2006-11-07 03:48:36 +03:00
# include "auth/credentials/credentials.h"
2005-12-28 18:38:36 +03:00
# include "auth/gensec/gensec.h"
2009-02-13 02:24:16 +03:00
# include "auth/auth.h"
2007-09-28 05:17:46 +04:00
# include "param/param.h"
2003-12-14 04:09:10 +03:00
2018-11-21 11:39:36 +03:00
static NTSTATUS dcesrv_auth_negotiate_hdr_signing ( struct dcesrv_call_state * call ,
struct ncacn_packet * pkt )
{
struct dcesrv_connection * dce_conn = call - > conn ;
2018-11-08 16:59:58 +03:00
struct dcesrv_auth * a = NULL ;
2018-11-21 11:39:36 +03:00
if ( ! ( call - > pkt . pfc_flags & DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN ) ) {
return NT_STATUS_OK ;
}
if ( dce_conn - > client_hdr_signing ) {
if ( dce_conn - > negotiated_hdr_signing & & pkt ! = NULL ) {
pkt - > pfc_flags | = DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN ;
}
return NT_STATUS_OK ;
}
dce_conn - > client_hdr_signing = true ;
dce_conn - > negotiated_hdr_signing = dce_conn - > support_hdr_signing ;
if ( ! dce_conn - > negotiated_hdr_signing ) {
return NT_STATUS_OK ;
}
if ( pkt ! = NULL ) {
pkt - > pfc_flags | = DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN ;
}
2018-11-08 16:59:58 +03:00
a = call - > conn - > default_auth_state ;
if ( a - > gensec_security ! = NULL ) {
gensec_want_feature ( a - > gensec_security ,
GENSEC_FEATURE_SIGN_PKT_HEADER ) ;
2018-11-21 11:39:36 +03:00
}
2018-11-08 16:59:58 +03:00
for ( a = call - > conn - > auth_states ; a ! = NULL ; a = a - > next ) {
if ( a - > gensec_security = = NULL ) {
continue ;
}
gensec_want_feature ( a - > gensec_security ,
GENSEC_FEATURE_SIGN_PKT_HEADER ) ;
}
2018-11-21 11:39:36 +03:00
return NT_STATUS_OK ;
}
2018-11-08 18:36:13 +03:00
static bool dcesrv_auth_prepare_gensec ( struct dcesrv_call_state * call )
2003-12-14 04:09:10 +03:00
{
This patch adds a better dcerpc server infastructure.
1.) We now register endpoint servers add startup via register_backend()
and later use the smb.conf 'dcerpc endpoint servers' parameter to setup the dcesrv_context
2.) each endpoint server can register at context creation time as much interfaces as it wants
(multiple interfaces on one endpoint are supported!)
(NOTE: there's a difference between 'endpoint server' and 'endpoint'!
for details look at rpc_server/dcesrv_server.h)
3.) one endpoint can have a security descriptor registered to it self
this will be checked in the future when a client wants to connect
to an smb pipe endpoint.
4.) we now have a 'remote' endpoint server, which works like the ntvfs_cifs module
it takes this options in the [globals] section:
dcerpc remote:interfaces = srvsvc, winreg, w32time, epmapper
dcerpc remote:binding = ...
dcerpc remote:user = ...
dcerpc remote:password = ...
5.) we currently have tree endpoint servers: epmapper, rpcecho and remote
the default for the 'dcerpc endpiont servers = epmapper, rpcecho'
for testing you can also do
dcerpc endpoint servers = rpcecho, remote, epmapper
dcerpc remote:interfaces = srvsvc, samr, netlogon
6,) please notice the the epmapper now only returns NO_ENTRIES
(but I think we'll find a solution for this too:-)
7.) also there're some other stuff left, but step by step :-)
This patch also includes updates for the
register_subsystem() , ntvfs_init(), and some other funtions
to check for duplicate subsystem registration
metze
(hmmm, my first large commit...I hope it works as supposed :-)
(This used to be commit 917e45dafd5be4c2cd90ff425b8d6f8403122349)
2004-01-09 01:55:27 +03:00
struct dcesrv_connection * dce_conn = call - > conn ;
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2021-02-02 17:07:35 +03:00
struct dcesrv_context_callbacks * cb = call - > conn - > dce_ctx - > callbacks ;
2003-12-14 13:45:50 +03:00
NTSTATUS status ;
2018-11-22 12:30:47 +03:00
if ( auth - > auth_started ) {
return false ;
}
auth - > auth_started = true ;
2018-11-08 18:36:52 +03:00
if ( auth - > auth_invalid ) {
return false ;
}
if ( auth - > auth_finished ) {
return false ;
}
if ( auth - > gensec_security ! = NULL ) {
return false ;
}
2015-07-10 14:55:27 +03:00
switch ( call - > in_auth_info . auth_level ) {
case DCERPC_AUTH_LEVEL_CONNECT :
case DCERPC_AUTH_LEVEL_CALL :
case DCERPC_AUTH_LEVEL_PACKET :
case DCERPC_AUTH_LEVEL_INTEGRITY :
case DCERPC_AUTH_LEVEL_PRIVACY :
/*
* We evaluate auth_type only if auth_level was valid
*/
break ;
default :
/*
* Setting DCERPC_AUTH_LEVEL_NONE ,
2016-08-31 22:39:25 +03:00
* gives the caller the reject_reason
* as auth_context_id .
2015-07-10 14:55:27 +03:00
*
* Note : DCERPC_AUTH_LEVEL_NONE = = 1
*/
auth - > auth_type = DCERPC_AUTH_TYPE_NONE ;
auth - > auth_level = DCERPC_AUTH_LEVEL_NONE ;
2016-08-31 22:39:25 +03:00
auth - > auth_context_id = DCERPC_BIND_NAK_REASON_NOT_SPECIFIED ;
2015-07-10 14:55:27 +03:00
return false ;
}
2015-06-26 09:10:46 +03:00
auth - > auth_type = call - > in_auth_info . auth_type ;
auth - > auth_level = call - > in_auth_info . auth_level ;
auth - > auth_context_id = call - > in_auth_info . auth_context_id ;
2015-06-29 12:03:58 +03:00
2020-11-13 12:55:43 +03:00
if ( auth - > auth_level = = DCERPC_AUTH_LEVEL_CONNECT & &
! call - > conn - > got_explicit_auth_level_connect )
{
call - > conn - > default_auth_level_connect = auth ;
}
2022-01-22 03:08:26 +03:00
cb - > auth . become_root ( ) ;
2021-01-29 20:16:08 +03:00
status = cb - > auth . gensec_prepare (
auth ,
call ,
& auth - > gensec_security ,
cb - > auth . private_data ) ;
2022-01-22 03:08:26 +03:00
cb - > auth . unbecome_root ( ) ;
2015-01-22 16:05:15 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to call samba_server_gensec_start %s \n " ,
nt_errstr ( status ) ) ) ;
return false ;
}
2017-02-20 03:32:47 +03:00
/*
* We have to call this because we set the target_service for
* Kerberos to NULL above , and in any case we wish to log a
* more specific service target .
*
*/
status = gensec_set_target_service_description ( auth - > gensec_security ,
" DCE/RPC " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to call gensec_set_target_service_description %s \n " ,
nt_errstr ( status ) ) ) ;
return false ;
}
2015-01-22 16:05:15 +03:00
if ( call - > conn - > remote_address ! = NULL ) {
status = gensec_set_remote_address ( auth - > gensec_security ,
call - > conn - > remote_address ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to call gensec_set_remote_address() %s \n " ,
nt_errstr ( status ) ) ) ;
return false ;
}
}
2005-10-20 07:47:55 +04:00
2017-02-24 03:29:12 +03:00
if ( call - > conn - > local_address ! = NULL ) {
status = gensec_set_local_address ( auth - > gensec_security ,
call - > conn - > local_address ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to call gensec_set_local_address() %s \n " ,
nt_errstr ( status ) ) ) ;
return false ;
}
}
2015-06-29 12:03:58 +03:00
status = gensec_start_mech_by_authtype ( auth - > gensec_security , auth - > auth_type ,
auth - > auth_level ) ;
2003-12-14 13:45:50 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2016-08-31 22:39:25 +03:00
const char * backend_name =
gensec_get_name_by_authtype ( auth - > gensec_security ,
auth - > auth_type ) ;
DEBUG ( 3 , ( " Failed to start GENSEC mechanism for DCERPC server: "
" auth_type=%d (%s), auth_level=%d: %s \n " ,
( int ) auth - > auth_type , backend_name ,
2015-06-29 12:03:58 +03:00
( int ) auth - > auth_level ,
2005-04-25 08:06:59 +04:00
nt_errstr ( status ) ) ) ;
2016-08-31 22:39:25 +03:00
/*
* Setting DCERPC_AUTH_LEVEL_NONE ,
* gives the caller the reject_reason
* as auth_context_id .
*
* Note : DCERPC_AUTH_LEVEL_NONE = = 1
*/
auth - > auth_type = DCERPC_AUTH_TYPE_NONE ;
auth - > auth_level = DCERPC_AUTH_LEVEL_NONE ;
if ( backend_name ! = NULL ) {
auth - > auth_context_id =
DCERPC_BIND_NAK_REASON_INVALID_CHECKSUM ;
} else {
auth - > auth_context_id =
DCERPC_BIND_NAK_REASON_INVALID_AUTH_TYPE ;
}
2007-10-07 02:25:41 +04:00
return false ;
2003-12-14 13:45:50 +03:00
}
2004-06-04 13:46:46 +04:00
2018-11-21 11:39:36 +03:00
if ( dce_conn - > negotiated_hdr_signing ) {
2017-05-12 08:56:47 +03:00
gensec_want_feature ( auth - > gensec_security ,
GENSEC_FEATURE_SIGN_PKT_HEADER ) ;
}
2007-10-07 02:25:41 +04:00
return true ;
2003-12-14 04:09:10 +03:00
}
2018-11-08 16:59:58 +03:00
static void dcesrv_default_auth_state_finish_bind ( struct dcesrv_call_state * call )
{
SMB_ASSERT ( call - > pkt . ptype = = DCERPC_PKT_BIND ) ;
if ( call - > auth_state = = call - > conn - > default_auth_state ) {
return ;
}
if ( call - > conn - > default_auth_state - > auth_started ) {
return ;
}
if ( call - > conn - > default_auth_state - > auth_invalid ) {
return ;
}
call - > conn - > default_auth_state - > auth_type = DCERPC_AUTH_TYPE_NONE ;
call - > conn - > default_auth_state - > auth_level = DCERPC_AUTH_LEVEL_NONE ;
call - > conn - > default_auth_state - > auth_context_id = 0 ;
call - > conn - > default_auth_state - > auth_started = true ;
call - > conn - > default_auth_state - > auth_finished = true ;
/*
*
* We defer log_successful_dcesrv_authz_event ( )
* to dcesrv_default_auth_state_prepare_request ( )
*
* As we don ' t want to trigger authz_events
* just for alter_context requests without authentication
*/
}
void dcesrv_default_auth_state_prepare_request ( struct dcesrv_call_state * call )
{
struct dcesrv_connection * dce_conn = call - > conn ;
struct dcesrv_auth * auth = call - > auth_state ;
2021-02-02 17:07:35 +03:00
struct dcesrv_context_callbacks * cb = call - > conn - > dce_ctx - > callbacks ;
2018-11-08 16:59:58 +03:00
if ( auth - > auth_audited ) {
return ;
}
if ( call - > pkt . ptype ! = DCERPC_PKT_REQUEST ) {
return ;
}
if ( auth ! = dce_conn - > default_auth_state ) {
return ;
}
if ( auth - > auth_invalid ) {
return ;
}
if ( ! auth - > auth_finished ) {
return ;
}
2021-01-29 20:16:08 +03:00
if ( cb - > log . successful_authz = = NULL ) {
2019-01-24 22:03:44 +03:00
return ;
}
2021-01-29 20:16:08 +03:00
cb - > log . successful_authz ( call , cb - > log . private_data ) ;
2018-11-22 15:26:21 +03:00
}
2018-11-08 18:36:13 +03:00
/*
parse any auth information from a dcerpc bind request
return false if we can ' t handle the auth request for some
reason ( in which case we send a bind_nak )
*/
bool dcesrv_auth_bind ( struct dcesrv_call_state * call )
{
struct ncacn_packet * pkt = & call - > pkt ;
struct dcesrv_auth * auth = call - > auth_state ;
2021-02-02 17:07:35 +03:00
struct dcesrv_context_callbacks * cb = call - > conn - > dce_ctx - > callbacks ;
2018-11-08 18:36:13 +03:00
NTSTATUS status ;
if ( pkt - > auth_length = = 0 ) {
auth - > auth_type = DCERPC_AUTH_TYPE_NONE ;
auth - > auth_level = DCERPC_AUTH_LEVEL_NONE ;
auth - > auth_context_id = 0 ;
2018-11-22 12:30:47 +03:00
auth - > auth_started = true ;
2018-11-08 18:36:13 +03:00
2021-01-29 20:16:08 +03:00
if ( cb - > log . successful_authz ! = NULL ) {
cb - > log . successful_authz ( call , cb - > log . private_data ) ;
2019-01-24 22:03:44 +03:00
}
2018-11-08 18:36:13 +03:00
return true ;
}
status = dcerpc_pull_auth_trailer ( pkt , call , & pkt - > u . bind . auth_info ,
& call - > in_auth_info ,
NULL , true ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
/*
* Setting DCERPC_AUTH_LEVEL_NONE ,
* gives the caller the reject_reason
* as auth_context_id .
*
* Note : DCERPC_AUTH_LEVEL_NONE = = 1
*/
auth - > auth_type = DCERPC_AUTH_TYPE_NONE ;
auth - > auth_level = DCERPC_AUTH_LEVEL_NONE ;
2020-11-11 19:59:45 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_RPC_PROTOCOL_ERROR ) ) {
auth - > auth_context_id =
call - > in_auth_info . auth_context_id ;
} else {
auth - > auth_context_id =
DCERPC_BIND_NAK_REASON_NOT_SPECIFIED ;
}
2018-11-08 18:36:13 +03:00
return false ;
}
return dcesrv_auth_prepare_gensec ( call ) ;
}
2017-05-15 10:00:45 +03:00
NTSTATUS dcesrv_auth_complete ( struct dcesrv_call_state * call , NTSTATUS status )
{
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2022-01-22 03:08:26 +03:00
struct dcesrv_context_callbacks * cb = call - > conn - > dce_ctx - > callbacks ;
2017-05-15 10:00:45 +03:00
const char * pdu = " <unknown> " ;
switch ( call - > pkt . ptype ) {
case DCERPC_PKT_BIND :
pdu = " BIND " ;
break ;
case DCERPC_PKT_ALTER :
pdu = " ALTER " ;
break ;
case DCERPC_PKT_AUTH3 :
pdu = " AUTH3 " ;
2017-05-15 10:13:08 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
2023-08-02 00:43:48 +03:00
DEBUG ( 4 , ( " GENSEC not finished at %s \n " , pdu ) ) ;
2017-05-15 10:13:08 +03:00
return NT_STATUS_RPC_SEC_PKG_ERROR ;
}
2017-05-15 10:00:45 +03:00
break ;
default :
return NT_STATUS_INTERNAL_ERROR ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
return NT_STATUS_OK ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 4 , ( " GENSEC mech rejected the incoming authentication "
" at %s: %s \n " , pdu , nt_errstr ( status ) ) ) ;
return status ;
}
2022-01-22 03:08:26 +03:00
cb - > auth . become_root ( ) ;
2018-10-31 19:12:02 +03:00
status = gensec_session_info ( auth - > gensec_security ,
2018-11-08 15:28:07 +03:00
auth ,
2018-10-31 19:12:02 +03:00
& auth - > session_info ) ;
2022-01-22 03:08:26 +03:00
cb - > auth . unbecome_root ( ) ;
2017-05-15 10:00:45 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to establish session_info: %s \n " ,
nt_errstr ( status ) ) ) ;
return status ;
}
2018-10-31 19:12:02 +03:00
auth - > auth_finished = true ;
2017-05-15 10:00:45 +03:00
2017-05-15 10:13:08 +03:00
if ( call - > pkt . ptype ! = DCERPC_PKT_AUTH3 ) {
return NT_STATUS_OK ;
}
if ( call - > out_auth_info - > credentials . length ! = 0 ) {
DEBUG ( 4 , ( " GENSEC produced output token (len=%zu) at %s \n " ,
call - > out_auth_info - > credentials . length , pdu ) ) ;
return NT_STATUS_RPC_SEC_PKG_ERROR ;
}
2017-05-15 10:00:45 +03:00
return NT_STATUS_OK ;
}
2003-12-14 04:09:10 +03:00
/*
r1294: A nice, large, commit...
This implements gensec for Samba's server side, and brings gensec up
to the standards of a full subsystem.
This means that use of the subsystem is by gensec_* functions, not
function pointers in structures (this is internal). This causes
changes in all the existing gensec users.
Our RPC server no longer contains it's own generalised security
scheme, and now calls gensec directly.
Gensec has also taken over the role of auth/auth_ntlmssp.c
An important part of gensec, is the output of the 'session_info'
struct. This is now reference counted, so that we can correctly free
it when a pipe is closed, no matter if it was inherited, or created by
per-pipe authentication.
The schannel code is reworked, to be in the same file for client and
server.
ntlm_auth is reworked to use gensec.
The major problem with this code is the way it relies on subsystem
auto-initialisation. The primary reason for this commit now.is to
allow these problems to be looked at, and fixed.
There are problems with the new code:
- I've tested it with smbtorture, but currently don't have VMware and
valgrind working (this I'll fix soon).
- The SPNEGO code is client-only at this point.
- We still do not do kerberos.
Andrew Bartlett
(This used to be commit 07fd885fd488fd1051eacc905a2d4962f8a018ec)
2004-06-29 13:40:10 +04:00
add any auth information needed in a bind ack , and process the authentication
information found in the bind .
2003-12-14 04:09:10 +03:00
*/
2017-05-15 13:16:35 +03:00
NTSTATUS dcesrv_auth_prepare_bind_ack ( struct dcesrv_call_state * call , struct ncacn_packet * pkt )
2003-12-14 04:09:10 +03:00
{
This patch adds a better dcerpc server infastructure.
1.) We now register endpoint servers add startup via register_backend()
and later use the smb.conf 'dcerpc endpoint servers' parameter to setup the dcesrv_context
2.) each endpoint server can register at context creation time as much interfaces as it wants
(multiple interfaces on one endpoint are supported!)
(NOTE: there's a difference between 'endpoint server' and 'endpoint'!
for details look at rpc_server/dcesrv_server.h)
3.) one endpoint can have a security descriptor registered to it self
this will be checked in the future when a client wants to connect
to an smb pipe endpoint.
4.) we now have a 'remote' endpoint server, which works like the ntvfs_cifs module
it takes this options in the [globals] section:
dcerpc remote:interfaces = srvsvc, winreg, w32time, epmapper
dcerpc remote:binding = ...
dcerpc remote:user = ...
dcerpc remote:password = ...
5.) we currently have tree endpoint servers: epmapper, rpcecho and remote
the default for the 'dcerpc endpiont servers = epmapper, rpcecho'
for testing you can also do
dcerpc endpoint servers = rpcecho, remote, epmapper
dcerpc remote:interfaces = srvsvc, samr, netlogon
6,) please notice the the epmapper now only returns NO_ENTRIES
(but I think we'll find a solution for this too:-)
7.) also there're some other stuff left, but step by step :-)
This patch also includes updates for the
register_subsystem() , ntvfs_init(), and some other funtions
to check for duplicate subsystem registration
metze
(hmmm, my first large commit...I hope it works as supposed :-)
(This used to be commit 917e45dafd5be4c2cd90ff425b8d6f8403122349)
2004-01-09 01:55:27 +03:00
struct dcesrv_connection * dce_conn = call - > conn ;
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2018-11-21 11:39:36 +03:00
NTSTATUS status ;
status = dcesrv_auth_negotiate_hdr_signing ( call , pkt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2003-12-14 13:45:50 +03:00
2015-06-26 09:10:46 +03:00
dce_conn - > allow_alter = true ;
2018-11-08 16:59:58 +03:00
dcesrv_default_auth_state_finish_bind ( call ) ;
2015-06-26 09:10:46 +03:00
2015-06-26 09:10:46 +03:00
if ( call - > pkt . auth_length = = 0 ) {
2018-10-31 19:12:02 +03:00
auth - > auth_finished = true ;
2007-08-17 09:28:39 +04:00
return NT_STATUS_OK ;
2003-12-14 13:45:50 +03:00
}
2015-06-26 09:10:46 +03:00
/* We can't work without an existing gensec state */
2018-10-31 19:12:02 +03:00
if ( auth - > gensec_security = = NULL ) {
2015-06-26 09:10:46 +03:00
return NT_STATUS_INTERNAL_ERROR ;
}
2015-06-26 09:10:46 +03:00
call - > _out_auth_info = ( struct dcerpc_auth ) {
2018-10-31 19:12:02 +03:00
. auth_type = auth - > auth_type ,
. auth_level = auth - > auth_level ,
. auth_context_id = auth - > auth_context_id ,
2015-06-26 09:10:46 +03:00
} ;
call - > out_auth_info = & call - > _out_auth_info ;
2017-05-15 13:16:35 +03:00
return NT_STATUS_OK ;
}
2003-12-14 13:45:50 +03:00
/*
2004-06-04 03:15:16 +04:00
process the final stage of a auth request
2003-12-14 13:45:50 +03:00
*/
2017-05-15 13:16:35 +03:00
bool dcesrv_auth_prepare_auth3 ( struct dcesrv_call_state * call )
2003-12-14 13:45:50 +03:00
{
2005-06-06 03:05:37 +04:00
struct ncacn_packet * pkt = & call - > pkt ;
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2003-12-14 13:45:50 +03:00
NTSTATUS status ;
2020-11-13 04:47:51 +03:00
if ( pkt - > frag_length > call - > conn - > transport_max_recv_frag ) {
/*
* Note that we don ' t check against the negotiated
* max_recv_frag , but a hard coded value from
* the transport .
*/
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
return false ;
}
if ( pkt - > auth_length > 4096 ) {
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
2015-06-26 09:10:46 +03:00
return false ;
}
2018-10-31 19:12:02 +03:00
if ( auth - > auth_finished ) {
2020-11-13 04:47:51 +03:00
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
return false ;
}
if ( ! auth - > auth_started ) {
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
return false ;
}
if ( auth - > auth_invalid ) {
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
return false ;
}
if ( pkt - > auth_length = = 0 ) {
call - > fault_code = DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY ;
2015-06-26 09:10:46 +03:00
return false ;
}
2020-11-16 16:15:06 +03:00
if ( auth - > auth_invalid ) {
return false ;
}
2015-06-26 09:10:46 +03:00
/* We can't work without an existing gensec state */
2018-10-31 19:12:02 +03:00
if ( auth - > gensec_security = = NULL ) {
2007-10-07 02:25:41 +04:00
return false ;
2003-12-14 13:45:50 +03:00
}
2010-02-13 07:32:23 +03:00
status = dcerpc_pull_auth_trailer ( pkt , call , & pkt - > u . auth3 . auth_info ,
2016-06-20 17:11:37 +03:00
& call - > in_auth_info , NULL , true ) ;
2010-02-13 07:32:23 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2020-11-13 04:47:51 +03:00
struct dcerpc_auth * auth_info = & call - > in_auth_info ;
uint32_t nr = auth_info - > auth_context_id ;
2016-06-23 14:50:39 +03:00
/*
* Windows returns DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY
2020-11-13 04:47:51 +03:00
* instead of DCERPC_NCA_S_PROTO_ERROR in most cases .
2016-06-23 14:50:39 +03:00
*/
call - > fault_code = DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY ;
2020-11-13 04:47:51 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_RPC_PROTOCOL_ERROR ) & &
nr ! = DCERPC_BIND_NAK_REASON_PROTOCOL_VERSION_NOT_SUPPORTED )
{
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
}
2007-10-07 02:25:41 +04:00
return false ;
2003-12-14 13:45:50 +03:00
}
2018-10-31 19:12:02 +03:00
if ( call - > in_auth_info . auth_type ! = auth - > auth_type ) {
2020-11-13 04:47:51 +03:00
call - > fault_code = DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY ;
2015-06-26 09:10:46 +03:00
return false ;
}
2018-10-31 19:12:02 +03:00
if ( call - > in_auth_info . auth_level ! = auth - > auth_level ) {
2020-11-13 04:47:51 +03:00
call - > fault_code = DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY ;
2015-06-26 09:10:46 +03:00
return false ;
}
2018-10-31 19:12:02 +03:00
if ( call - > in_auth_info . auth_context_id ! = auth - > auth_context_id ) {
2020-11-13 04:47:51 +03:00
call - > fault_code = DCERPC_FAULT_ACCESS_DENIED ;
2015-06-26 09:10:46 +03:00
return false ;
}
2015-06-26 09:10:46 +03:00
call - > _out_auth_info = ( struct dcerpc_auth ) {
2018-10-31 19:12:02 +03:00
. auth_type = auth - > auth_type ,
. auth_level = auth - > auth_level ,
. auth_context_id = auth - > auth_context_id ,
2015-06-26 09:10:46 +03:00
} ;
call - > out_auth_info = & call - > _out_auth_info ;
2017-05-15 13:16:35 +03:00
return true ;
}
2004-12-06 20:48:51 +03:00
/*
parse any auth information from a dcerpc alter request
2019-10-03 20:38:31 +03:00
return false if we can ' t handle the auth request for some
2004-12-06 20:48:51 +03:00
reason ( in which case we send a bind_nak ( is this true for here ? ) )
*/
2007-10-07 02:25:41 +04:00
bool dcesrv_auth_alter ( struct dcesrv_call_state * call )
2004-12-06 20:48:51 +03:00
{
2005-06-06 03:05:37 +04:00
struct ncacn_packet * pkt = & call - > pkt ;
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2010-02-13 07:32:23 +03:00
NTSTATUS status ;
2004-12-06 20:48:51 +03:00
2005-01-10 15:39:42 +03:00
/* on a pure interface change there is no auth blob */
2015-06-26 09:10:46 +03:00
if ( pkt - > auth_length = = 0 ) {
2018-10-31 19:12:02 +03:00
if ( ! auth - > auth_finished ) {
2015-06-26 09:10:46 +03:00
return false ;
}
2007-10-07 02:25:41 +04:00
return true ;
2005-01-10 15:39:42 +03:00
}
2018-10-31 19:12:02 +03:00
if ( auth - > auth_finished ) {
2016-06-23 14:50:39 +03:00
call - > fault_code = DCERPC_FAULT_ACCESS_DENIED ;
2007-10-07 02:25:41 +04:00
return false ;
2004-12-06 20:48:51 +03:00
}
2010-02-13 07:32:23 +03:00
status = dcerpc_pull_auth_trailer ( pkt , call , & pkt - > u . alter . auth_info ,
2016-06-20 17:11:37 +03:00
& call - > in_auth_info , NULL , true ) ;
2010-02-13 07:32:23 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2016-06-23 14:50:39 +03:00
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
return false ;
}
2018-11-08 16:59:58 +03:00
if ( ! auth - > auth_started ) {
bool ok ;
ok = dcesrv_auth_prepare_gensec ( call ) ;
if ( ! ok ) {
call - > fault_code = DCERPC_FAULT_ACCESS_DENIED ;
return false ;
}
return true ;
}
2016-06-23 14:50:39 +03:00
if ( call - > in_auth_info . auth_type = = DCERPC_AUTH_TYPE_NONE ) {
call - > fault_code = DCERPC_FAULT_ACCESS_DENIED ;
2007-10-07 02:25:41 +04:00
return false ;
2004-12-06 20:48:51 +03:00
}
2020-11-16 16:15:06 +03:00
if ( auth - > auth_invalid ) {
return false ;
}
2018-10-31 19:12:02 +03:00
if ( call - > in_auth_info . auth_type ! = auth - > auth_type ) {
2015-06-26 09:10:46 +03:00
return false ;
}
2018-10-31 19:12:02 +03:00
if ( call - > in_auth_info . auth_level ! = auth - > auth_level ) {
2015-06-26 09:10:46 +03:00
return false ;
}
2018-10-31 19:12:02 +03:00
if ( call - > in_auth_info . auth_context_id ! = auth - > auth_context_id ) {
2015-06-26 09:10:46 +03:00
return false ;
}
2007-10-07 02:25:41 +04:00
return true ;
2004-12-06 20:48:51 +03:00
}
/*
add any auth information needed in a alter ack , and process the authentication
information found in the alter .
*/
2017-05-15 13:16:35 +03:00
NTSTATUS dcesrv_auth_prepare_alter_ack ( struct dcesrv_call_state * call , struct ncacn_packet * pkt )
2004-12-06 20:48:51 +03:00
{
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2018-11-21 11:39:36 +03:00
NTSTATUS status ;
status = dcesrv_auth_negotiate_hdr_signing ( call , pkt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2004-12-06 20:48:51 +03:00
2005-01-11 04:53:14 +03:00
/* on a pure interface change there is no auth_info structure
setup */
2015-06-26 09:10:46 +03:00
if ( call - > pkt . auth_length = = 0 ) {
2007-08-17 09:28:39 +04:00
return NT_STATUS_OK ;
2005-01-10 15:39:42 +03:00
}
2018-10-31 19:12:02 +03:00
if ( auth - > gensec_security = = NULL ) {
2015-06-26 09:10:46 +03:00
return NT_STATUS_INTERNAL_ERROR ;
2004-12-06 20:48:51 +03:00
}
2015-06-26 09:10:46 +03:00
call - > _out_auth_info = ( struct dcerpc_auth ) {
2018-10-31 19:12:02 +03:00
. auth_type = auth - > auth_type ,
. auth_level = auth - > auth_level ,
. auth_context_id = auth - > auth_context_id ,
2015-06-26 09:10:46 +03:00
} ;
call - > out_auth_info = & call - > _out_auth_info ;
2017-05-15 13:16:35 +03:00
return NT_STATUS_OK ;
}
2003-12-14 13:45:50 +03:00
/*
2015-10-28 15:04:38 +03:00
check credentials on a packet
2003-12-14 13:45:50 +03:00
*/
2015-10-28 15:04:38 +03:00
bool dcesrv_auth_pkt_pull ( struct dcesrv_call_state * call ,
DATA_BLOB * full_packet ,
uint8_t required_flags ,
uint8_t optional_flags ,
uint8_t payload_offset ,
DATA_BLOB * payload_and_verifier )
2003-12-14 13:45:50 +03:00
{
2005-06-06 03:05:37 +04:00
struct ncacn_packet * pkt = & call - > pkt ;
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2015-10-28 15:04:38 +03:00
const struct dcerpc_auth tmp_auth = {
2018-10-31 19:12:02 +03:00
. auth_type = auth - > auth_type ,
. auth_level = auth - > auth_level ,
. auth_context_id = auth - > auth_context_id ,
2015-10-28 15:04:38 +03:00
} ;
2020-11-16 16:15:06 +03:00
bool check_pkt_auth_fields ;
2003-12-14 13:45:50 +03:00
NTSTATUS status ;
2018-11-08 16:59:58 +03:00
if ( ! auth - > auth_started ) {
return false ;
}
2020-11-13 12:55:43 +03:00
if ( auth - > auth_invalid ) {
2015-06-26 09:10:46 +03:00
return false ;
}
2020-11-13 12:55:43 +03:00
if ( ! auth - > auth_finished ) {
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
2015-07-14 17:18:45 +03:00
return false ;
}
2020-11-16 16:15:06 +03:00
if ( call - > pkt . pfc_flags & DCERPC_PFC_FLAG_FIRST ) {
/*
* The caller most likely checked this
* already , but we better double check .
*/
check_pkt_auth_fields = true ;
} else {
/*
* The caller already found first fragment
* and is passing the auth_state of it .
* A server is supposed to use the
* setting of the first fragment and
* completely ignore the values
* on the remaining fragments
*/
check_pkt_auth_fields = false ;
}
2015-10-28 15:04:38 +03:00
status = dcerpc_ncacn_pull_pkt_auth ( & tmp_auth ,
2018-10-31 19:12:02 +03:00
auth - > gensec_security ,
2020-11-16 16:15:06 +03:00
check_pkt_auth_fields ,
2015-10-28 15:04:38 +03:00
call ,
2015-10-28 15:04:38 +03:00
pkt - > ptype ,
required_flags ,
optional_flags ,
2015-10-28 15:04:38 +03:00
payload_offset ,
2015-10-28 15:04:38 +03:00
payload_and_verifier ,
2015-10-28 15:04:38 +03:00
full_packet ,
pkt ) ;
if ( NT_STATUS_EQUAL ( status , NT_STATUS_RPC_PROTOCOL_ERROR ) ) {
call - > fault_code = DCERPC_NCA_S_PROTO_ERROR ;
2014-01-09 13:59:01 +04:00
return false ;
}
2015-10-28 15:04:38 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_RPC_UNSUPPORTED_AUTHN_LEVEL ) ) {
call - > fault_code = DCERPC_NCA_S_UNSUPPORTED_AUTHN_LEVEL ;
2014-01-09 13:59:01 +04:00
return false ;
}
2015-10-28 15:04:38 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_RPC_SEC_PKG_ERROR ) ) {
call - > fault_code = DCERPC_FAULT_SEC_PKG_ERROR ;
2014-01-09 13:59:01 +04:00
return false ;
}
2015-10-28 15:04:38 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_ACCESS_DENIED ) ) {
call - > fault_code = DCERPC_FAULT_ACCESS_DENIED ;
2016-09-01 11:35:13 +03:00
return false ;
}
2016-09-01 11:31:04 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
return true ;
2003-12-14 13:45:50 +03:00
}
2019-10-03 20:38:31 +03:00
/*
2003-12-14 13:45:50 +03:00
push a signed or sealed dcerpc request packet into a blob
*/
2015-10-23 17:06:17 +03:00
bool dcesrv_auth_pkt_push ( struct dcesrv_call_state * call ,
2008-08-11 20:12:54 +04:00
DATA_BLOB * blob , size_t sig_size ,
2015-10-23 17:06:17 +03:00
uint8_t payload_offset ,
const DATA_BLOB * payload ,
2015-10-23 17:06:17 +03:00
const struct ncacn_packet * pkt )
2003-12-14 13:45:50 +03:00
{
2018-10-31 16:44:33 +03:00
struct dcesrv_auth * auth = call - > auth_state ;
2015-10-23 17:06:17 +03:00
const struct dcerpc_auth tmp_auth = {
2018-10-31 19:12:02 +03:00
. auth_type = auth - > auth_type ,
. auth_level = auth - > auth_level ,
. auth_context_id = auth - > auth_context_id ,
2015-06-26 09:10:46 +03:00
} ;
2015-10-23 17:06:17 +03:00
NTSTATUS status ;
2010-02-14 09:09:55 +03:00
2015-10-23 17:06:17 +03:00
status = dcerpc_ncacn_push_pkt_auth ( & tmp_auth ,
2018-10-31 19:12:02 +03:00
auth - > gensec_security ,
2015-10-23 17:06:17 +03:00
call , blob , sig_size ,
2015-10-23 17:06:17 +03:00
payload_offset ,
payload ,
2015-10-23 17:06:17 +03:00
pkt ) ;
return NT_STATUS_IS_OK ( status ) ;
2003-12-14 04:09:10 +03:00
}