2007-12-21 15:51:00 +01:00
/*
* Unix SMB / CIFS implementation .
* NetApi GetDC Support
* Copyright ( C ) Guenther Deschner 2007
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2011-01-12 11:17:48 +01:00
# include "../librpc/gen_ndr/ndr_netlogon_c.h"
2008-04-08 02:42:50 +02:00
# include "librpc/gen_ndr/libnetapi.h"
2007-12-21 15:51:00 +01:00
# include "lib/netapi/netapi.h"
2008-04-10 21:52:03 +02:00
# include "lib/netapi/netapi_private.h"
2008-04-08 02:42:50 +02:00
# include "lib/netapi/libnetapi.h"
2018-01-05 14:21:05 +01:00
# include "libsmb/dsgetdcname.h"
2007-12-21 15:51:00 +01:00
2008-01-18 02:38:35 +01:00
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 02:42:50 +02:00
WERROR NetGetDCName_l ( struct libnetapi_ctx * ctx ,
struct NetGetDCName * r )
2007-12-21 15:51:00 +01:00
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGetDCName ) ;
2007-12-21 15:51:00 +01:00
}
2008-01-18 02:38:35 +01:00
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 02:42:50 +02:00
WERROR NetGetDCName_r ( struct libnetapi_ctx * ctx ,
struct NetGetDCName * r )
2007-12-21 15:51:00 +01:00
{
NTSTATUS status ;
WERROR werr ;
2011-01-12 11:17:48 +01:00
struct dcerpc_binding_handle * b ;
2011-10-21 11:06:14 +02:00
const char * dcname ;
void * buffer ;
2007-12-21 15:51:00 +01:00
2011-04-06 14:35:24 +02:00
werr = libnetapi_get_binding_handle ( ctx , r - > in . server_name ,
2013-05-17 16:08:16 +02:00
& ndr_table_netlogon ,
2011-04-06 14:35:24 +02:00
& b ) ;
2008-04-10 22:44:00 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-21 15:51:00 +01:00
goto done ;
2008-04-08 02:42:50 +02:00
}
2007-12-21 15:51:00 +01:00
2011-01-12 11:17:48 +01:00
status = dcerpc_netr_GetDcName ( b , talloc_tos ( ) ,
2008-04-08 02:42:50 +02:00
r - > in . server_name ,
r - > in . domain_name ,
2011-10-21 11:06:14 +02:00
& dcname ,
2008-01-31 14:10:22 +01:00
& werr ) ;
2008-10-05 13:58:09 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
2011-10-21 11:06:14 +02:00
goto done ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
if ( NetApiBufferAllocate ( strlen_m_term ( dcname ) , & buffer ) ) {
2015-12-03 15:24:14 +01:00
werr = WERR_NOT_ENOUGH_MEMORY ;
2011-10-21 11:06:14 +02:00
goto done ;
2008-10-05 13:58:09 +02:00
}
2011-10-21 11:06:14 +02:00
memcpy ( buffer , dcname , strlen_m_term ( dcname ) ) ;
* r - > out . buffer = buffer ;
2007-12-21 15:51:00 +01:00
done :
return werr ;
}
2008-01-18 02:38:35 +01:00
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 02:42:50 +02:00
WERROR NetGetAnyDCName_l ( struct libnetapi_ctx * ctx ,
struct NetGetAnyDCName * r )
2007-12-21 15:51:00 +01:00
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGetAnyDCName ) ;
2007-12-21 15:51:00 +01:00
}
2008-01-18 02:38:35 +01:00
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 02:42:50 +02:00
WERROR NetGetAnyDCName_r ( struct libnetapi_ctx * ctx ,
struct NetGetAnyDCName * r )
2007-12-21 15:51:00 +01:00
{
NTSTATUS status ;
WERROR werr ;
2011-01-12 11:17:48 +01:00
struct dcerpc_binding_handle * b ;
2011-10-21 11:06:14 +02:00
const char * dcname ;
void * buffer ;
2007-12-21 15:51:00 +01:00
2011-04-06 14:35:24 +02:00
werr = libnetapi_get_binding_handle ( ctx , r - > in . server_name ,
2013-05-17 16:08:16 +02:00
& ndr_table_netlogon ,
2011-04-06 14:35:24 +02:00
& b ) ;
2008-04-10 22:44:00 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-21 15:51:00 +01:00
goto done ;
2008-04-10 22:44:00 +02:00
}
2007-12-21 15:51:00 +01:00
2011-01-12 11:17:48 +01:00
status = dcerpc_netr_GetAnyDCName ( b , talloc_tos ( ) ,
2008-04-08 02:42:50 +02:00
r - > in . server_name ,
r - > in . domain_name ,
2011-10-21 11:06:14 +02:00
& dcname ,
2007-12-21 15:51:00 +01:00
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 11:17:48 +01:00
werr = ntstatus_to_werror ( status ) ;
2007-12-21 15:51:00 +01:00
goto done ;
}
2011-10-21 11:06:14 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
if ( NetApiBufferAllocate ( strlen_m_term ( dcname ) , & buffer ) ) {
2015-12-03 15:24:14 +01:00
werr = WERR_NOT_ENOUGH_MEMORY ;
2011-10-21 11:06:14 +02:00
goto done ;
}
memcpy ( buffer , dcname , strlen_m_term ( dcname ) ) ;
* r - > out . buffer = buffer ;
2007-12-21 15:51:00 +01:00
done :
return werr ;
}
2008-04-08 18:43:51 +02:00
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR DsGetDcName_l ( struct libnetapi_ctx * ctx ,
struct DsGetDcName * r )
{
NTSTATUS status ;
2010-09-21 20:56:23 -07:00
struct libnetapi_private_ctx * priv ;
priv = talloc_get_type_abort ( ctx - > private_data ,
struct libnetapi_private_ctx ) ;
2008-04-08 18:43:51 +02:00
status = dsgetdcname ( ctx ,
2010-09-21 20:56:23 -07:00
priv - > msg_ctx ,
2008-04-08 18:43:51 +02:00
r - > in . domain_name ,
r - > in . domain_guid ,
r - > in . site_name ,
r - > in . flags ,
( struct netr_DsRGetDCNameInfo * * ) r - > out . dc_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
libnetapi_set_error_string ( ctx ,
" failed to find DC: %s " ,
get_friendly_nt_error_msg ( status ) ) ;
}
return ntstatus_to_werror ( status ) ;
}
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR DsGetDcName_r ( struct libnetapi_ctx * ctx ,
struct DsGetDcName * r )
{
WERROR werr ;
2019-09-16 10:43:54 +00:00
NTSTATUS status ;
2011-01-12 11:17:48 +01:00
struct dcerpc_binding_handle * b ;
2008-04-08 18:43:51 +02:00
2011-04-06 14:35:24 +02:00
werr = libnetapi_get_binding_handle ( ctx , r - > in . server_name ,
2013-05-17 16:08:16 +02:00
& ndr_table_netlogon ,
2011-04-06 14:35:24 +02:00
& b ) ;
2008-04-10 22:44:00 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-08 18:43:51 +02:00
goto done ;
}
2011-01-12 11:17:48 +01:00
status = dcerpc_netr_DsRGetDCNameEx ( b ,
2010-09-15 10:11:38 +02:00
ctx ,
r - > in . server_name ,
r - > in . domain_name ,
r - > in . domain_guid ,
r - > in . site_name ,
r - > in . flags ,
( struct netr_DsRGetDCNameInfo * * ) r - > out . dc_info ,
& werr ) ;
2011-01-12 11:17:48 +01:00
if ( NT_STATUS_IS_OK ( status ) & & W_ERROR_IS_OK ( werr ) ) {
2010-09-15 10:11:38 +02:00
goto done ;
}
2011-01-12 11:17:48 +01:00
status = dcerpc_netr_DsRGetDCName ( b ,
2008-04-08 18:43:51 +02:00
ctx ,
r - > in . server_name ,
r - > in . domain_name ,
r - > in . domain_guid ,
NULL ,
r - > in . flags ,
( struct netr_DsRGetDCNameInfo * * ) r - > out . dc_info ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
return werr ;
}