2008-09-24 00:48:57 +04:00
/*
2008-05-21 08:26:38 +04:00
Unix SMB / CIFS implementation .
2008-05-20 04:58:43 +04:00
2008-05-21 08:26:38 +04:00
CLDAP server structures
2008-05-20 04:58:43 +04:00
2008-05-21 08:26:38 +04:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2008
2008-09-24 00:48:57 +04:00
2008-05-21 08:26:38 +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
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
2008-09-24 00:48:57 +04:00
2008-05-21 08:26:38 +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 .
2008-09-24 00:48:57 +04:00
2008-05-21 08:26:38 +04:00
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2008-05-20 04:58:43 +04:00
2008-05-21 08:26:38 +04:00
# include "includes.h"
2011-01-07 14:01:42 +03:00
# include "../libcli/netlogon/netlogon.h"
2008-05-20 04:58:43 +04:00
2008-09-24 00:48:57 +04:00
NTSTATUS push_netlogon_samlogon_response ( DATA_BLOB * data , TALLOC_CTX * mem_ctx ,
struct netlogon_samlogon_response * response )
2008-05-20 04:58:43 +04:00
{
enum ndr_err_code ndr_err ;
if ( response - > ntver = = NETLOGON_NT_VERSION_1 ) {
2008-09-24 00:48:57 +04:00
ndr_err = ndr_push_struct_blob ( data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . nt4 ,
2008-05-20 04:58:43 +04:00
( ndr_push_flags_fn_t ) ndr_push_NETLOGON_SAM_LOGON_RESPONSE_NT40 ) ;
} else if ( response - > ntver & NETLOGON_NT_VERSION_5EX ) {
2008-09-24 00:48:57 +04:00
ndr_err = ndr_push_struct_blob ( data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . nt5_ex ,
2008-05-20 04:58:43 +04:00
( ndr_push_flags_fn_t ) ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags ) ;
} else if ( response - > ntver & NETLOGON_NT_VERSION_5 ) {
2008-09-24 00:48:57 +04:00
ndr_err = ndr_push_struct_blob ( data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . nt5 ,
2008-05-20 04:58:43 +04:00
( ndr_push_flags_fn_t ) ndr_push_NETLOGON_SAM_LOGON_RESPONSE ) ;
} else {
DEBUG ( 0 , ( " Asked to push unknown netlogon response type 0x%02x \n " , response - > ntver ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
DEBUG ( 2 , ( " failed to push netlogon response of type 0x%02x \n " ,
response - > ntver ) ) ;
return ndr_map_error2ntstatus ( ndr_err ) ;
}
return NT_STATUS_OK ;
}
2008-09-24 00:48:57 +04:00
NTSTATUS pull_netlogon_samlogon_response ( DATA_BLOB * data , TALLOC_CTX * mem_ctx ,
2008-05-20 04:58:43 +04:00
struct netlogon_samlogon_response * response )
{
uint32_t ntver ;
enum ndr_err_code ndr_err ;
if ( data - > length < 8 ) {
return NT_STATUS_BUFFER_TOO_SMALL ;
}
/* lmnttoken */
if ( SVAL ( data - > data , data - > length - 4 ) ! = 0xffff ) {
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
/* lm20token */
if ( SVAL ( data - > data , data - > length - 2 ) ! = 0xffff ) {
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
ntver = IVAL ( data - > data , data - > length - 8 ) ;
2008-09-24 00:48:57 +04:00
2008-05-20 04:58:43 +04:00
if ( ntver = = NETLOGON_NT_VERSION_1 ) {
2008-09-24 00:48:57 +04:00
ndr_err = ndr_pull_struct_blob_all ( data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . nt4 ,
2008-05-20 04:58:43 +04:00
( ndr_pull_flags_fn_t ) ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_NT40 ) ;
response - > ntver = NETLOGON_NT_VERSION_1 ;
2008-09-24 03:16:10 +04:00
if ( NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) & & DEBUGLEVEL > = 10 ) {
2008-10-02 10:09:25 +04:00
NDR_PRINT_DEBUG ( NETLOGON_SAM_LOGON_RESPONSE_NT40 ,
& response - > data . nt4 ) ;
2008-09-24 03:16:10 +04:00
}
2008-05-20 04:58:43 +04:00
} else if ( ntver & NETLOGON_NT_VERSION_5EX ) {
struct ndr_pull * ndr ;
2010-05-09 19:20:01 +04:00
ndr = ndr_pull_init_blob ( data , mem_ctx ) ;
2008-05-20 04:58:43 +04:00
if ( ! ndr ) {
return NT_STATUS_NO_MEMORY ;
}
2008-10-02 10:09:25 +04:00
ndr_err = ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags (
ndr , NDR_SCALARS | NDR_BUFFERS , & response - > data . nt5_ex ,
ntver ) ;
2008-05-20 04:58:43 +04:00
if ( ndr - > offset < ndr - > data_size ) {
2014-12-23 14:09:04 +03:00
TALLOC_FREE ( ndr ) ;
/*
2020-11-11 19:50:45 +03:00
* We need to handle a bug in IPA ( at least < = 4.1 .2 ) .
2014-12-23 14:09:04 +03:00
*
* They include the ip address information without setting
* NETLOGON_NT_VERSION_5EX_WITH_IP , while using
* ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX instead of
* ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags .
*/
ndr_err = ndr_pull_struct_blob_all ( data , mem_ctx ,
& response - > data . nt5 ,
( ndr_pull_flags_fn_t ) ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX ) ;
2008-05-20 04:58:43 +04:00
}
response - > ntver = NETLOGON_NT_VERSION_5EX ;
2008-09-24 03:16:10 +04:00
if ( NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) & & DEBUGLEVEL > = 10 ) {
2008-10-02 10:09:25 +04:00
NDR_PRINT_DEBUG ( NETLOGON_SAM_LOGON_RESPONSE_EX ,
& response - > data . nt5_ex ) ;
2008-09-24 03:16:10 +04:00
}
2008-05-20 04:58:43 +04:00
} else if ( ntver & NETLOGON_NT_VERSION_5 ) {
2008-09-24 00:48:57 +04:00
ndr_err = ndr_pull_struct_blob_all ( data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . nt5 ,
2008-05-20 04:58:43 +04:00
( ndr_pull_flags_fn_t ) ndr_pull_NETLOGON_SAM_LOGON_RESPONSE ) ;
response - > ntver = NETLOGON_NT_VERSION_5 ;
2008-09-24 03:16:10 +04:00
if ( NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) & & DEBUGLEVEL > = 10 ) {
2008-10-02 10:09:25 +04:00
NDR_PRINT_DEBUG ( NETLOGON_SAM_LOGON_RESPONSE ,
& response - > data . nt5 ) ;
2008-09-24 03:16:10 +04:00
}
2008-05-20 04:58:43 +04:00
} else {
DEBUG ( 2 , ( " failed to parse netlogon response of type 0x%02x - unknown response type \n " ,
ntver ) ) ;
dump_data ( 10 , data - > data , data - > length ) ;
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
DEBUG ( 2 , ( " failed to parse netlogon response of type 0x%02x \n " ,
ntver ) ) ;
dump_data ( 10 , data - > data , data - > length ) ;
return ndr_map_error2ntstatus ( ndr_err ) ;
}
2008-09-24 03:16:10 +04:00
2008-05-20 04:58:43 +04:00
return NT_STATUS_OK ;
}
void map_netlogon_samlogon_response ( struct netlogon_samlogon_response * response )
{
struct NETLOGON_SAM_LOGON_RESPONSE_EX response_5_ex ;
switch ( response - > ntver ) {
case NETLOGON_NT_VERSION_5EX :
break ;
case NETLOGON_NT_VERSION_5 :
ZERO_STRUCT ( response_5_ex ) ;
2008-10-02 10:09:25 +04:00
response_5_ex . command = response - > data . nt5 . command ;
response_5_ex . pdc_name = response - > data . nt5 . pdc_name ;
response_5_ex . user_name = response - > data . nt5 . user_name ;
2010-04-27 18:56:36 +04:00
response_5_ex . domain_name = response - > data . nt5 . domain_name ;
2008-10-02 10:09:25 +04:00
response_5_ex . domain_uuid = response - > data . nt5 . domain_uuid ;
response_5_ex . forest = response - > data . nt5 . forest ;
response_5_ex . dns_domain = response - > data . nt5 . dns_domain ;
response_5_ex . pdc_dns_name = response - > data . nt5 . pdc_dns_name ;
response_5_ex . sockaddr . pdc_ip = response - > data . nt5 . pdc_ip ;
response_5_ex . server_type = response - > data . nt5 . server_type ;
response_5_ex . nt_version = response - > data . nt5 . nt_version ;
response_5_ex . lmnt_token = response - > data . nt5 . lmnt_token ;
response_5_ex . lm20_token = response - > data . nt5 . lm20_token ;
2008-05-20 04:58:43 +04:00
response - > ntver = NETLOGON_NT_VERSION_5EX ;
2008-10-02 10:09:25 +04:00
response - > data . nt5_ex = response_5_ex ;
2008-05-20 04:58:43 +04:00
break ;
2008-09-24 00:48:57 +04:00
2008-05-20 04:58:43 +04:00
case NETLOGON_NT_VERSION_1 :
ZERO_STRUCT ( response_5_ex ) ;
2008-10-02 10:09:25 +04:00
response_5_ex . command = response - > data . nt4 . command ;
2010-04-27 18:56:36 +04:00
response_5_ex . pdc_name = response - > data . nt4 . pdc_name ;
2008-10-02 10:09:25 +04:00
response_5_ex . user_name = response - > data . nt4 . user_name ;
2010-04-27 18:56:36 +04:00
response_5_ex . domain_name = response - > data . nt4 . domain_name ;
2008-10-02 10:09:25 +04:00
response_5_ex . nt_version = response - > data . nt4 . nt_version ;
response_5_ex . lmnt_token = response - > data . nt4 . lmnt_token ;
response_5_ex . lm20_token = response - > data . nt4 . lm20_token ;
2008-05-20 04:58:43 +04:00
response - > ntver = NETLOGON_NT_VERSION_5EX ;
2008-10-02 10:09:25 +04:00
response - > data . nt5_ex = response_5_ex ;
2008-05-20 04:58:43 +04:00
break ;
}
return ;
}
2008-09-24 00:48:57 +04:00
NTSTATUS push_nbt_netlogon_response ( DATA_BLOB * data , TALLOC_CTX * mem_ctx ,
struct nbt_netlogon_response * response )
2008-05-20 04:58:43 +04:00
{
2019-07-10 18:34:56 +03:00
NTSTATUS status ;
2008-05-20 04:58:43 +04:00
enum ndr_err_code ndr_err ;
switch ( response - > response_type ) {
case NETLOGON_GET_PDC :
2008-10-02 10:09:25 +04:00
ndr_err = ndr_push_struct_blob ( data , mem_ctx ,
& response - > data . get_pdc ,
2008-05-20 04:58:43 +04:00
( ndr_push_flags_fn_t ) ndr_push_nbt_netlogon_response_from_pdc ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
status = ndr_map_error2ntstatus ( ndr_err ) ;
DEBUG ( 0 , ( " Failed to parse netlogon packet of length %d: %s \n " ,
( int ) data - > length , nt_errstr ( status ) ) ) ;
if ( DEBUGLVL ( 10 ) ) {
2022-05-11 12:32:47 +03:00
( void ) file_save ( " netlogon.dat " , data - > data , data - > length ) ;
2008-05-20 04:58:43 +04:00
}
return status ;
}
status = NT_STATUS_OK ;
break ;
case NETLOGON_SAMLOGON :
2008-10-02 10:09:25 +04:00
status = push_netlogon_samlogon_response (
2022-05-11 12:31:52 +03:00
data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . samlogon ) ;
2008-05-20 04:58:43 +04:00
break ;
2010-09-08 00:41:44 +04:00
case NETLOGON_RESPONSE2 :
ndr_err = ndr_push_struct_blob ( data , mem_ctx ,
& response - > data . response2 ,
( ndr_push_flags_fn_t ) ndr_push_nbt_netlogon_response2 ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
}
status = NT_STATUS_OK ;
break ;
2019-07-10 18:34:56 +03:00
default :
status = NT_STATUS_INVALID_NETWORK_RESPONSE ;
break ;
2008-05-20 04:58:43 +04:00
}
2010-09-08 00:41:44 +04:00
2008-05-20 04:58:43 +04:00
return status ;
}
2008-09-24 00:48:57 +04:00
NTSTATUS pull_nbt_netlogon_response ( DATA_BLOB * data , TALLOC_CTX * mem_ctx ,
struct nbt_netlogon_response * response )
2008-05-20 04:58:43 +04:00
{
2019-07-10 18:34:56 +03:00
NTSTATUS status ;
2008-05-20 04:58:43 +04:00
enum netlogon_command command ;
enum ndr_err_code ndr_err ;
if ( data - > length < 4 ) {
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
command = SVAL ( data - > data , 0 ) ;
switch ( command ) {
case NETLOGON_RESPONSE_FROM_PDC :
2008-10-02 10:09:25 +04:00
ndr_err = ndr_pull_struct_blob_all ( data , mem_ctx ,
& response - > data . get_pdc ,
2008-05-20 04:58:43 +04:00
( ndr_pull_flags_fn_t ) ndr_pull_nbt_netlogon_response_from_pdc ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
status = ndr_map_error2ntstatus ( ndr_err ) ;
DEBUG ( 0 , ( " Failed to parse netlogon packet of length %d: %s \n " ,
( int ) data - > length , nt_errstr ( status ) ) ) ;
if ( DEBUGLVL ( 10 ) ) {
2022-05-11 12:32:47 +03:00
( void ) file_save ( " netlogon.dat " , data - > data , data - > length ) ;
2008-05-20 04:58:43 +04:00
}
return status ;
}
status = NT_STATUS_OK ;
response - > response_type = NETLOGON_GET_PDC ;
break ;
2010-09-08 20:59:19 +04:00
case LOGON_RESPONSE2 :
ndr_err = ndr_pull_struct_blob ( data , mem_ctx , & response - > data . response2 ,
( ndr_pull_flags_fn_t ) ndr_pull_nbt_netlogon_response2 ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
}
status = NT_STATUS_OK ;
response - > response_type = NETLOGON_RESPONSE2 ;
break ;
2008-05-20 04:58:43 +04:00
case LOGON_SAM_LOGON_RESPONSE :
case LOGON_SAM_LOGON_PAUSE_RESPONSE :
case LOGON_SAM_LOGON_USER_UNKNOWN :
case LOGON_SAM_LOGON_RESPONSE_EX :
case LOGON_SAM_LOGON_PAUSE_RESPONSE_EX :
case LOGON_SAM_LOGON_USER_UNKNOWN_EX :
2008-10-02 10:09:25 +04:00
status = pull_netlogon_samlogon_response (
2022-05-11 12:31:52 +03:00
data , mem_ctx ,
2008-10-02 10:09:25 +04:00
& response - > data . samlogon ) ;
2008-05-20 04:58:43 +04:00
response - > response_type = NETLOGON_SAMLOGON ;
break ;
2008-09-24 00:48:57 +04:00
2008-05-20 04:58:43 +04:00
/* These levels are queries, not responses */
case LOGON_PRIMARY_QUERY :
2010-09-08 13:58:04 +04:00
case LOGON_REQUEST :
2008-05-20 04:58:43 +04:00
case NETLOGON_ANNOUNCE_UAS :
case LOGON_SAM_LOGON_REQUEST :
2019-07-10 18:34:56 +03:00
default :
2008-05-20 04:58:43 +04:00
status = NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
return status ;
}