2011-01-11 17:08:41 +03:00
/*
Unix SMB / CIFS implementation .
Authentication utility functions
Copyright ( C ) Volker Lendecke 2010
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "../librpc/gen_ndr/netlogon.h"
# include "../libcli/security/security.h"
# include "rpc_client/util_netlogon.h"
# define COPY_LSA_STRING(mem_ctx, in, out, name) do { \
if ( in - > name . string ) { \
out - > name . string = talloc_strdup ( mem_ctx , in - > name . string ) ; \
NT_STATUS_HAVE_NO_MEMORY ( out - > name . string ) ; \
} \
} while ( 0 )
NTSTATUS copy_netr_SamBaseInfo ( TALLOC_CTX * mem_ctx ,
const struct netr_SamBaseInfo * in ,
struct netr_SamBaseInfo * out )
{
/* first copy all, then realloc pointers */
* out = * in ;
COPY_LSA_STRING ( mem_ctx , in , out , account_name ) ;
COPY_LSA_STRING ( mem_ctx , in , out , full_name ) ;
COPY_LSA_STRING ( mem_ctx , in , out , logon_script ) ;
COPY_LSA_STRING ( mem_ctx , in , out , profile_path ) ;
COPY_LSA_STRING ( mem_ctx , in , out , home_directory ) ;
COPY_LSA_STRING ( mem_ctx , in , out , home_drive ) ;
if ( in - > groups . count ) {
out - > groups . rids = ( struct samr_RidWithAttribute * )
talloc_memdup ( mem_ctx , in - > groups . rids ,
( sizeof ( struct samr_RidWithAttribute ) *
in - > groups . count ) ) ;
NT_STATUS_HAVE_NO_MEMORY ( out - > groups . rids ) ;
}
COPY_LSA_STRING ( mem_ctx , in , out , logon_server ) ;
2011-10-22 00:10:43 +04:00
COPY_LSA_STRING ( mem_ctx , in , out , logon_domain ) ;
2011-01-11 17:08:41 +03:00
if ( in - > domain_sid ) {
out - > domain_sid = dom_sid_dup ( mem_ctx , in - > domain_sid ) ;
NT_STATUS_HAVE_NO_MEMORY ( out - > domain_sid ) ;
}
return NT_STATUS_OK ;
}
2017-12-03 00:35:36 +03:00
2018-01-11 11:06:31 +03:00
NTSTATUS copy_netr_SamInfo3 ( TALLOC_CTX * mem_ctx ,
const struct netr_SamInfo3 * in ,
struct netr_SamInfo3 * * pout )
2017-12-03 00:35:36 +03:00
{
2018-01-11 11:06:31 +03:00
struct netr_SamInfo3 * info3 = NULL ;
2017-12-03 00:35:36 +03:00
unsigned int i ;
2018-01-11 11:06:31 +03:00
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2017-12-03 00:35:36 +03:00
info3 = talloc_zero ( mem_ctx , struct netr_SamInfo3 ) ;
2018-01-11 11:06:31 +03:00
if ( info3 = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto out ;
}
2017-12-03 00:35:36 +03:00
2018-01-11 11:06:31 +03:00
status = copy_netr_SamBaseInfo ( info3 , & in - > base , & info3 - > base ) ;
2017-12-03 00:35:36 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2018-01-11 11:06:31 +03:00
goto out ;
2017-12-03 00:35:36 +03:00
}
2018-01-11 11:06:31 +03:00
if ( in - > sidcount ) {
info3 - > sidcount = in - > sidcount ;
2017-12-03 00:35:36 +03:00
info3 - > sids = talloc_array ( info3 , struct netr_SidAttr ,
2018-01-11 11:06:31 +03:00
in - > sidcount ) ;
if ( info3 - > sids = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto out ;
}
for ( i = 0 ; i < in - > sidcount ; i + + ) {
2017-12-03 00:35:36 +03:00
info3 - > sids [ i ] . sid = dom_sid_dup ( info3 - > sids ,
2018-01-11 11:06:31 +03:00
in - > sids [ i ] . sid ) ;
if ( info3 - > sids [ i ] . sid = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto out ;
}
info3 - > sids [ i ] . attributes = in - > sids [ i ] . attributes ;
2017-12-03 00:35:36 +03:00
}
}
2018-01-11 11:06:31 +03:00
* pout = info3 ;
info3 = NULL ;
status = NT_STATUS_OK ;
out :
TALLOC_FREE ( info3 ) ;
return status ;
2017-12-03 00:35:36 +03:00
}
2017-12-01 01:19:07 +03:00
NTSTATUS map_validation_to_info3 ( TALLOC_CTX * mem_ctx ,
uint16_t validation_level ,
union netr_Validation * validation ,
struct netr_SamInfo3 * * info3_p )
{
2018-01-11 11:06:31 +03:00
struct netr_SamInfo3 * info3 = NULL ;
2017-12-01 01:19:07 +03:00
struct netr_SamInfo6 * info6 = NULL ;
NTSTATUS status ;
if ( validation = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
switch ( validation_level ) {
case 3 :
if ( validation - > sam3 = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2018-01-11 11:06:31 +03:00
status = copy_netr_SamInfo3 ( mem_ctx ,
validation - > sam3 ,
& info3 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2017-12-01 01:19:07 +03:00
}
2018-01-11 11:06:31 +03:00
2017-12-01 01:19:07 +03:00
break ;
case 6 :
if ( validation - > sam6 = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
info6 = validation - > sam6 ;
info3 = talloc_zero ( mem_ctx , struct netr_SamInfo3 ) ;
if ( info3 = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
status = copy_netr_SamBaseInfo ( info3 ,
& info6 - > base ,
& info3 - > base ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
TALLOC_FREE ( info3 ) ;
return status ;
}
if ( validation - > sam6 - > sidcount > 0 ) {
int i ;
info3 - > sidcount = info6 - > sidcount ;
info3 - > sids = talloc_array ( info3 ,
struct netr_SidAttr ,
info3 - > sidcount ) ;
if ( info3 - > sids = = NULL ) {
TALLOC_FREE ( info3 ) ;
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < info3 - > sidcount ; i + + ) {
info3 - > sids [ i ] . sid = dom_sid_dup (
info3 - > sids , info6 - > sids [ i ] . sid ) ;
if ( info3 - > sids [ i ] . sid = = NULL ) {
TALLOC_FREE ( info3 ) ;
return NT_STATUS_NO_MEMORY ;
}
info3 - > sids [ i ] . attributes =
info6 - > sids [ i ] . attributes ;
}
}
break ;
default :
return NT_STATUS_BAD_VALIDATION_CLASS ;
}
* info3_p = info3 ;
return NT_STATUS_OK ;
}
2017-12-11 17:18:58 +03:00
NTSTATUS map_info3_to_validation ( TALLOC_CTX * mem_ctx ,
struct netr_SamInfo3 * info3 ,
uint16_t * _validation_level ,
union netr_Validation * * _validation )
{
union netr_Validation * validation = NULL ;
2018-01-11 11:06:31 +03:00
NTSTATUS status ;
2017-12-11 17:18:58 +03:00
validation = talloc_zero ( mem_ctx , union netr_Validation ) ;
if ( validation = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2018-01-11 11:06:31 +03:00
status = copy_netr_SamInfo3 ( mem_ctx ,
info3 ,
& validation - > sam3 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2017-12-11 17:18:58 +03:00
}
* _validation_level = 3 ;
* _validation = validation ;
return NT_STATUS_OK ;
}