2007-11-30 20:49:21 +03:00
/*
* Unix SMB / CIFS implementation .
* NetApi Join Support
2008-01-04 19:01:52 +03:00
* Copyright ( C ) Guenther Deschner 2007 - 2008
2007-11-30 20:49:21 +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
* 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"
2010-07-02 02:32:52 +04:00
# include "ads.h"
2008-04-08 04:42:50 +04:00
# include "librpc/gen_ndr/libnetapi.h"
2010-08-05 17:14:04 +04:00
# include "libcli/auth/libcli_auth.h"
2007-12-18 04:54:18 +03:00
# include "lib/netapi/netapi.h"
2008-04-10 23:52:03 +04:00
# include "lib/netapi/netapi_private.h"
2008-04-08 04:42:50 +04:00
# include "lib/netapi/libnetapi.h"
2010-07-02 02:14:04 +04:00
# include "librpc/gen_ndr/libnet_join.h"
# include "libnet/libnet_join.h"
2011-01-11 18:03:24 +03:00
# include "../librpc/gen_ndr/ndr_wkssvc_c.h"
2011-02-28 12:19:44 +03:00
# include "rpc_client/cli_pipe.h"
2010-08-05 04:25:37 +04:00
# include "secrets.h"
2018-01-05 16:21:05 +03:00
# include "libsmb/dsgetdcname.h"
2021-02-05 15:05:45 +03:00
# include "../librpc/gen_ndr/ndr_ODJ.h"
# include "lib/util/base64.h"
# include "libnet/libnet_join_offline.h"
2023-08-31 13:45:42 +03:00
# include "libcli/security/dom_sid.h"
2007-12-18 04:54:18 +03:00
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetJoinDomain_l ( struct libnetapi_ctx * mem_ctx ,
struct NetJoinDomain * r )
2007-12-11 23:23:40 +03:00
{
2008-04-08 04:42:50 +04:00
struct libnet_JoinCtx * j = NULL ;
2010-09-22 07:56:23 +04:00
struct libnetapi_private_ctx * priv ;
2007-12-11 23:32:16 +03:00
WERROR werr ;
2010-09-22 07:56:23 +04:00
priv = talloc_get_type_abort ( mem_ctx - > private_data ,
struct libnetapi_private_ctx ) ;
2008-04-08 04:42:50 +04:00
if ( ! r - > in . domain ) {
2015-12-03 17:24:23 +03:00
return WERR_INVALID_PARAMETER ;
2007-12-11 23:32:16 +03:00
}
2008-04-08 04:42:50 +04:00
werr = libnet_init_JoinCtx ( mem_ctx , & j ) ;
2008-01-07 20:41:49 +03:00
W_ERROR_NOT_OK_RETURN ( werr ) ;
2008-04-08 04:42:50 +04:00
j - > in . domain_name = talloc_strdup ( mem_ctx , r - > in . domain ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > in . domain_name ) ;
2007-12-11 23:32:16 +03:00
2008-04-08 04:42:50 +04:00
if ( r - > in . join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE ) {
2007-12-19 04:25:15 +03:00
NTSTATUS status ;
2008-02-28 14:30:18 +03:00
struct netr_DsRGetDCNameInfo * info = NULL ;
2008-05-08 16:23:20 +04:00
const char * dc = NULL ;
2007-12-19 04:25:15 +03:00
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_WRITABLE_REQUIRED |
DS_RETURN_DNS_NAME ;
2010-09-22 07:56:23 +04:00
status = dsgetdcname ( mem_ctx , priv - > msg_ctx , r - > in . domain ,
2007-12-19 04:25:15 +03:00
NULL , NULL , flags , & info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-01-18 04:38:35 +03:00
libnetapi_set_error_string ( mem_ctx ,
" %s " , get_friendly_nt_error_msg ( status ) ) ;
2007-12-19 04:25:15 +03:00
return ntstatus_to_werror ( status ) ;
}
2008-05-08 16:23:20 +04:00
dc = strip_hostname ( info - > dc_unc ) ;
j - > in . dc_name = talloc_strdup ( mem_ctx , dc ) ;
2008-04-08 04:42:50 +04:00
W_ERROR_HAVE_NO_MEMORY ( j - > in . dc_name ) ;
2007-12-19 04:25:15 +03:00
}
2008-04-08 04:42:50 +04:00
if ( r - > in . account_ou ) {
j - > in . account_ou = talloc_strdup ( mem_ctx , r - > in . account_ou ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > in . account_ou ) ;
2007-12-11 23:32:16 +03:00
}
2008-04-08 04:42:50 +04:00
if ( r - > in . account ) {
j - > in . admin_account = talloc_strdup ( mem_ctx , r - > in . account ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > in . admin_account ) ;
2007-12-11 23:32:16 +03:00
}
2008-04-08 04:42:50 +04:00
if ( r - > in . password ) {
j - > in . admin_password = talloc_strdup ( mem_ctx , r - > in . password ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > in . admin_password ) ;
2007-12-11 23:32:16 +03:00
}
2008-04-08 04:42:50 +04:00
j - > in . join_flags = r - > in . join_flags ;
j - > in . modify_config = true ;
j - > in . debug = true ;
2007-12-11 23:32:16 +03:00
2008-04-08 04:42:50 +04:00
werr = libnet_Join ( mem_ctx , j ) ;
if ( ! W_ERROR_IS_OK ( werr ) & & j - > out . error_string ) {
libnetapi_set_error_string ( mem_ctx , " %s " , j - > out . error_string ) ;
2008-01-07 22:08:45 +03:00
}
2008-04-08 04:42:50 +04:00
TALLOC_FREE ( j ) ;
2008-01-07 20:40:25 +03:00
return werr ;
2007-12-11 23:23:40 +03:00
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetJoinDomain_r ( struct libnetapi_ctx * ctx ,
struct NetJoinDomain * r )
2007-11-30 20:49:21 +03:00
{
struct rpc_pipe_client * pipe_cli = NULL ;
2008-01-05 00:56:31 +03:00
struct wkssvc_PasswordBuffer * encrypted_password = NULL ;
2007-11-30 20:49:21 +03:00
NTSTATUS status ;
WERROR werr ;
2007-12-01 13:41:44 +03:00
unsigned int old_timeout = 0 ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b ;
2011-03-25 00:14:20 +03:00
DATA_BLOB session_key ;
2007-11-30 20:49:21 +03:00
2013-12-11 05:59:20 +04:00
if ( IS_DC ) {
2015-12-03 17:24:39 +03:00
return WERR_NERR_SETUPDOMAINCONTROLLER ;
2013-12-11 05:59:20 +04:00
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server ,
2013-05-17 18:10:13 +04:00
& ndr_table_wkssvc ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-11-30 20:49:21 +03:00
goto done ;
2008-01-03 18:41:38 +03:00
}
2007-11-30 20:49:21 +03:00
2011-01-11 18:03:24 +03:00
b = pipe_cli - > binding_handle ;
2008-04-08 04:42:50 +04:00
if ( r - > in . password ) {
2011-03-25 00:14:20 +03:00
2011-03-25 14:13:36 +03:00
status = cli_get_session_key ( talloc_tos ( ) , pipe_cli , & session_key ) ;
2011-03-25 00:14:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2019-05-29 16:50:45 +03:00
werr = encode_wkssvc_join_password_buffer ( ctx ,
r - > in . password ,
& session_key ,
& encrypted_password ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-11-30 21:56:41 +03:00
}
2007-11-30 20:49:21 +03:00
2009-01-18 20:15:49 +03:00
old_timeout = rpccli_set_timeout ( pipe_cli , 600000 ) ;
2007-11-30 21:55:40 +03:00
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrJoinDomain2 ( b , talloc_tos ( ) ,
2008-04-08 04:42:50 +04:00
r - > in . server ,
r - > in . domain ,
r - > in . account_ou ,
r - > in . account ,
2008-01-05 00:56:31 +03:00
encrypted_password ,
2008-04-08 04:42:50 +04:00
r - > in . join_flags ,
& werr ) ;
2007-11-30 20:49:21 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
2007-11-30 21:56:41 +03:00
goto done ;
2007-11-30 20:49:21 +03:00
}
done :
2009-01-18 20:15:49 +03:00
if ( pipe_cli & & old_timeout ) {
rpccli_set_timeout ( pipe_cli , old_timeout ) ;
2007-11-30 21:56:41 +03:00
}
2007-12-11 23:23:40 +03:00
return werr ;
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetUnjoinDomain_l ( struct libnetapi_ctx * mem_ctx ,
struct NetUnjoinDomain * r )
2007-12-18 04:54:18 +03:00
{
2008-04-08 04:42:50 +04:00
struct libnet_UnjoinCtx * u = NULL ;
2007-12-19 13:03:45 +03:00
struct dom_sid domain_sid ;
2008-04-02 13:14:15 +04:00
const char * domain = NULL ;
2007-12-19 13:03:45 +03:00
WERROR werr ;
2010-09-22 07:56:23 +04:00
struct libnetapi_private_ctx * priv ;
2016-06-15 17:05:58 +03:00
const char * realm = lp_realm ( ) ;
2010-09-22 07:56:23 +04:00
priv = talloc_get_type_abort ( mem_ctx - > private_data ,
struct libnetapi_private_ctx ) ;
2007-12-19 13:03:45 +03:00
if ( ! secrets_fetch_domain_sid ( lp_workgroup ( ) , & domain_sid ) ) {
2015-12-03 17:24:39 +03:00
return WERR_NERR_SETUPNOTJOINED ;
2007-12-19 13:03:45 +03:00
}
2008-04-08 04:42:50 +04:00
werr = libnet_init_UnjoinCtx ( mem_ctx , & u ) ;
2007-12-19 13:03:45 +03:00
W_ERROR_NOT_OK_RETURN ( werr ) ;
2016-06-15 17:05:58 +03:00
if ( realm [ 0 ] ! = ' \0 ' ) {
domain = realm ;
2008-04-02 13:14:15 +04:00
} else {
domain = lp_workgroup ( ) ;
}
2008-04-08 04:42:50 +04:00
if ( r - > in . server_name ) {
u - > in . dc_name = talloc_strdup ( mem_ctx , r - > in . server_name ) ;
W_ERROR_HAVE_NO_MEMORY ( u - > in . dc_name ) ;
2007-12-19 13:03:45 +03:00
} else {
NTSTATUS status ;
2008-02-28 14:30:18 +03:00
struct netr_DsRGetDCNameInfo * info = NULL ;
2008-05-08 16:23:20 +04:00
const char * dc = NULL ;
2007-12-19 13:03:45 +03:00
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_WRITABLE_REQUIRED |
DS_RETURN_DNS_NAME ;
2010-09-22 07:56:23 +04:00
status = dsgetdcname ( mem_ctx , priv - > msg_ctx , domain ,
2007-12-19 13:03:45 +03:00
NULL , NULL , flags , & info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-01-18 04:38:35 +03:00
libnetapi_set_error_string ( mem_ctx ,
2008-04-02 13:14:15 +04:00
" failed to find DC for domain %s: %s " ,
domain ,
get_friendly_nt_error_msg ( status ) ) ;
2007-12-19 13:03:45 +03:00
return ntstatus_to_werror ( status ) ;
}
2008-05-08 16:23:20 +04:00
dc = strip_hostname ( info - > dc_unc ) ;
u - > in . dc_name = talloc_strdup ( mem_ctx , dc ) ;
2008-04-08 04:42:50 +04:00
W_ERROR_HAVE_NO_MEMORY ( u - > in . dc_name ) ;
u - > in . domain_name = domain ;
2007-12-19 13:03:45 +03:00
}
2008-04-08 04:42:50 +04:00
if ( r - > in . account ) {
u - > in . admin_account = talloc_strdup ( mem_ctx , r - > in . account ) ;
W_ERROR_HAVE_NO_MEMORY ( u - > in . admin_account ) ;
2007-12-19 13:03:45 +03:00
}
2008-04-08 04:42:50 +04:00
if ( r - > in . password ) {
u - > in . admin_password = talloc_strdup ( mem_ctx , r - > in . password ) ;
W_ERROR_HAVE_NO_MEMORY ( u - > in . admin_password ) ;
2007-12-19 13:03:45 +03:00
}
2008-04-08 04:42:50 +04:00
u - > in . domain_name = domain ;
u - > in . unjoin_flags = r - > in . unjoin_flags ;
2009-06-19 21:46:07 +04:00
u - > in . delete_machine_account = false ;
2008-04-08 04:42:50 +04:00
u - > in . modify_config = true ;
u - > in . debug = true ;
2007-12-19 13:03:45 +03:00
2008-04-08 04:42:50 +04:00
u - > in . domain_sid = & domain_sid ;
2007-12-19 13:03:45 +03:00
2008-04-08 04:42:50 +04:00
werr = libnet_Unjoin ( mem_ctx , u ) ;
if ( ! W_ERROR_IS_OK ( werr ) & & u - > out . error_string ) {
libnetapi_set_error_string ( mem_ctx , " %s " , u - > out . error_string ) ;
2008-01-18 04:38:35 +03:00
}
2008-04-08 04:42:50 +04:00
TALLOC_FREE ( u ) ;
2007-12-19 13:03:45 +03:00
2008-01-18 04:38:35 +03:00
return werr ;
2007-12-19 13:03:45 +03:00
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetUnjoinDomain_r ( struct libnetapi_ctx * ctx ,
struct NetUnjoinDomain * r )
2007-11-30 21:57:08 +03:00
{
struct rpc_pipe_client * pipe_cli = NULL ;
2008-01-05 00:56:31 +03:00
struct wkssvc_PasswordBuffer * encrypted_password = NULL ;
2007-11-30 21:57:08 +03:00
NTSTATUS status ;
WERROR werr ;
2007-12-01 13:41:44 +03:00
unsigned int old_timeout = 0 ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b ;
2011-03-25 00:14:20 +03:00
DATA_BLOB session_key ;
2007-11-30 21:57:08 +03:00
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_wkssvc ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-11-30 21:57:08 +03:00
goto done ;
2008-01-03 18:41:38 +03:00
}
2007-11-30 21:57:08 +03:00
2011-01-11 18:03:24 +03:00
b = pipe_cli - > binding_handle ;
2008-04-08 04:42:50 +04:00
if ( r - > in . password ) {
2011-03-25 00:14:20 +03:00
2011-03-25 14:13:36 +03:00
status = cli_get_session_key ( talloc_tos ( ) , pipe_cli , & session_key ) ;
2011-03-25 00:14:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2019-05-29 16:50:45 +03:00
werr = encode_wkssvc_join_password_buffer ( ctx ,
r - > in . password ,
& session_key ,
& encrypted_password ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-11-30 21:57:08 +03:00
}
2009-01-18 20:15:49 +03:00
old_timeout = rpccli_set_timeout ( pipe_cli , 60000 ) ;
2007-11-30 21:57:08 +03:00
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrUnjoinDomain2 ( b , talloc_tos ( ) ,
2008-04-08 04:42:50 +04:00
r - > in . server_name ,
r - > in . account ,
2008-01-05 00:56:31 +03:00
encrypted_password ,
2008-04-08 04:42:50 +04:00
r - > in . unjoin_flags ,
2007-12-03 20:40:09 +03:00
& werr ) ;
2007-11-30 21:57:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
2009-01-18 20:15:49 +03:00
if ( pipe_cli & & old_timeout ) {
rpccli_set_timeout ( pipe_cli , old_timeout ) ;
2007-11-30 21:57:08 +03:00
}
return werr ;
}
2007-12-06 21:04:49 +03:00
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetGetJoinInformation_r ( struct libnetapi_ctx * ctx ,
struct NetGetJoinInformation * r )
2007-12-06 21:04:49 +03:00
{
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
2008-04-29 22:11:02 +04:00
const char * buffer = NULL ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b ;
2007-12-06 21:04:49 +03:00
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_wkssvc ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-06 21:04:49 +03:00
goto done ;
2008-01-03 18:41:38 +03:00
}
2007-12-06 21:04:49 +03:00
2011-01-11 18:03:24 +03:00
b = pipe_cli - > binding_handle ;
status = dcerpc_wkssvc_NetrGetJoinInformation ( b , talloc_tos ( ) ,
2008-04-08 04:42:50 +04:00
r - > in . server_name ,
2008-04-29 22:11:02 +04:00
& buffer ,
2008-04-08 04:42:50 +04:00
( enum wkssvc_NetJoinStatus * ) r - > out . name_type ,
2007-12-06 21:04:49 +03:00
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
2011-01-12 15:32:10 +03:00
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
2007-12-06 21:04:49 +03:00
}
2008-04-29 22:11:02 +04:00
* r - > out . name_buffer = talloc_strdup ( ctx , buffer ) ;
W_ERROR_HAVE_NO_MEMORY ( * r - > out . name_buffer ) ;
2007-12-06 21:04:49 +03:00
done :
return werr ;
}
2007-12-18 04:54:18 +03:00
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetGetJoinInformation_l ( struct libnetapi_ctx * ctx ,
struct NetGetJoinInformation * r )
2007-12-19 15:52:51 +03:00
{
2016-06-15 17:05:58 +03:00
const char * realm = lp_realm ( ) ;
if ( ( lp_security ( ) = = SEC_ADS ) & & realm [ 0 ] ! = ' \0 ' ) {
* r - > out . name_buffer = talloc_strdup ( ctx , realm ) ;
2007-12-19 15:52:51 +03:00
} else {
2008-04-08 04:42:50 +04:00
* r - > out . name_buffer = talloc_strdup ( ctx , lp_workgroup ( ) ) ;
2007-12-19 15:52:51 +03:00
}
2008-04-08 04:42:50 +04:00
if ( ! * r - > out . name_buffer ) {
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2007-12-19 15:52:51 +03:00
}
switch ( lp_server_role ( ) ) {
case ROLE_DOMAIN_MEMBER :
case ROLE_DOMAIN_PDC :
case ROLE_DOMAIN_BDC :
2020-11-11 19:50:45 +03:00
case ROLE_IPA_DC :
2008-04-08 04:42:50 +04:00
* r - > out . name_type = NetSetupDomainName ;
2007-12-19 15:52:51 +03:00
break ;
case ROLE_STANDALONE :
default :
2008-04-08 04:42:50 +04:00
* r - > out . name_type = NetSetupWorkgroupName ;
2007-12-19 15:52:51 +03:00
break ;
}
return WERR_OK ;
}
2008-01-18 04:50:33 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetGetJoinableOUs_l ( struct libnetapi_ctx * ctx ,
struct NetGetJoinableOUs * r )
2008-01-18 04:50:33 +03:00
{
2011-03-18 17:18:29 +03:00
# ifdef HAVE_ADS
2022-05-24 13:01:13 +03:00
TALLOC_CTX * tmp_ctx = talloc_stackframe ( ) ;
WERROR ret ;
2008-01-18 04:50:33 +03:00
NTSTATUS status ;
ADS_STATUS ads_status ;
ADS_STRUCT * ads = NULL ;
2008-02-28 14:30:18 +03:00
struct netr_DsRGetDCNameInfo * info = NULL ;
2008-05-08 16:23:20 +04:00
const char * dc = NULL ;
2008-01-18 04:50:33 +03:00
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_RETURN_DNS_NAME ;
2010-09-22 07:56:23 +04:00
struct libnetapi_private_ctx * priv ;
2014-02-26 23:16:26 +04:00
char * * p ;
size_t s ;
2010-09-22 07:56:23 +04:00
priv = talloc_get_type_abort ( ctx - > private_data ,
struct libnetapi_private_ctx ) ;
2008-01-18 04:50:33 +03:00
2022-05-24 13:01:13 +03:00
status = dsgetdcname ( tmp_ctx , priv - > msg_ctx , r - > in . domain ,
2008-01-18 04:50:33 +03:00
NULL , NULL , flags , & info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
libnetapi_set_error_string ( ctx , " %s " ,
get_friendly_nt_error_msg ( status ) ) ;
2022-05-24 13:01:13 +03:00
ret = ntstatus_to_werror ( status ) ;
goto out ;
2008-01-18 04:50:33 +03:00
}
2008-05-08 16:23:20 +04:00
dc = strip_hostname ( info - > dc_unc ) ;
2022-05-26 18:28:34 +03:00
ads = ads_init ( tmp_ctx ,
info - > domain_name ,
2019-08-13 18:41:40 +03:00
info - > domain_name ,
dc ,
ADS_SASL_PLAIN ) ;
2008-01-18 04:50:33 +03:00
if ( ! ads ) {
2022-05-24 13:01:13 +03:00
ret = WERR_GEN_FAILURE ;
goto out ;
2008-01-18 04:50:33 +03:00
}
2016-08-17 12:58:02 +03:00
ADS_TALLOC_CONST_FREE ( ads - > auth . user_name ) ;
2008-04-08 04:42:50 +04:00
if ( r - > in . account ) {
2022-06-13 17:53:32 +03:00
ads - > auth . user_name = talloc_strdup ( ads , r - > in . account ) ;
if ( ads - > auth . user_name = = NULL ) {
ret = WERR_NOT_ENOUGH_MEMORY ;
goto out ;
}
2021-03-18 13:08:57 +03:00
} else {
2021-03-18 13:14:39 +03:00
const char * username = NULL ;
libnetapi_get_username ( ctx , & username ) ;
2021-03-18 13:08:57 +03:00
if ( username ! = NULL ) {
2022-06-13 17:53:32 +03:00
ads - > auth . user_name = talloc_strdup ( ads , username ) ;
if ( ads - > auth . user_name = = NULL ) {
ret = WERR_NOT_ENOUGH_MEMORY ;
goto out ;
}
2021-03-18 13:08:57 +03:00
}
2008-01-18 04:50:33 +03:00
}
2016-08-17 12:58:02 +03:00
ADS_TALLOC_CONST_FREE ( ads - > auth . password ) ;
2008-04-08 04:42:50 +04:00
if ( r - > in . password ) {
2022-06-13 14:56:10 +03:00
ads - > auth . password = talloc_strdup ( ads , r - > in . password ) ;
if ( ads - > auth . password = = NULL ) {
ret = WERR_NOT_ENOUGH_MEMORY ;
goto out ;
}
2021-03-18 13:08:57 +03:00
} else {
2021-03-18 13:14:39 +03:00
const char * password = NULL ;
libnetapi_get_password ( ctx , & password ) ;
2021-03-18 13:08:57 +03:00
if ( password ! = NULL ) {
2022-06-13 14:56:10 +03:00
ads - > auth . password = talloc_strdup ( ads , password ) ;
if ( ads - > auth . password = = NULL ) {
ret = WERR_NOT_ENOUGH_MEMORY ;
goto out ;
}
2021-03-18 13:08:57 +03:00
}
2008-01-18 04:50:33 +03:00
}
2008-06-24 15:06:38 +04:00
ads_status = ads_connect_user_creds ( ads ) ;
2008-01-18 04:50:33 +03:00
if ( ! ADS_ERR_OK ( ads_status ) ) {
2022-05-24 13:01:13 +03:00
ret = WERR_NERR_DEFAULTJOINREQUIRED ;
goto out ;
2008-01-18 04:50:33 +03:00
}
2014-02-26 23:16:26 +04:00
ads_status = ads_get_joinable_ous ( ads , ctx , & p , & s ) ;
2008-01-18 04:50:33 +03:00
if ( ! ADS_ERR_OK ( ads_status ) ) {
2022-05-24 13:01:13 +03:00
ret = WERR_NERR_DEFAULTJOINREQUIRED ;
goto out ;
2008-01-18 04:50:33 +03:00
}
2014-02-26 23:16:26 +04:00
* r - > out . ous = discard_const_p ( const char * , p ) ;
* r - > out . ou_count = s ;
2008-01-18 04:50:33 +03:00
2022-05-24 13:01:13 +03:00
ret = WERR_OK ;
out :
TALLOC_FREE ( tmp_ctx ) ;
return ret ;
2008-01-18 10:48:44 +03:00
# else
return WERR_NOT_SUPPORTED ;
# endif
2008-01-18 04:50:33 +03:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetGetJoinableOUs_r ( struct libnetapi_ctx * ctx ,
struct NetGetJoinableOUs * r )
2008-01-18 04:50:33 +03:00
{
struct rpc_pipe_client * pipe_cli = NULL ;
struct wkssvc_PasswordBuffer * encrypted_password = NULL ;
NTSTATUS status ;
WERROR werr ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b ;
2011-03-25 00:14:20 +03:00
DATA_BLOB session_key ;
2008-01-18 04:50:33 +03:00
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_wkssvc ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-01-18 04:50:33 +03:00
goto done ;
}
2011-01-11 18:03:24 +03:00
b = pipe_cli - > binding_handle ;
2008-04-08 04:42:50 +04:00
if ( r - > in . password ) {
2011-03-25 00:14:20 +03:00
2011-03-25 14:13:36 +03:00
status = cli_get_session_key ( talloc_tos ( ) , pipe_cli , & session_key ) ;
2011-03-25 00:14:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2019-05-29 16:50:45 +03:00
werr = encode_wkssvc_join_password_buffer ( ctx ,
r - > in . password ,
& session_key ,
& encrypted_password ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-01-18 04:50:33 +03:00
}
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrGetJoinableOus2 ( b , talloc_tos ( ) ,
2008-04-08 04:42:50 +04:00
r - > in . server_name ,
r - > in . domain ,
r - > in . account ,
2008-01-18 04:50:33 +03:00
encrypted_password ,
2008-04-08 04:42:50 +04:00
r - > out . ou_count ,
r - > out . ous ,
2008-01-18 04:50:33 +03:00
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
return werr ;
}
2008-09-02 13:02:43 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetRenameMachineInDomain_r ( struct libnetapi_ctx * ctx ,
struct NetRenameMachineInDomain * r )
{
2008-09-02 15:17:57 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
struct wkssvc_PasswordBuffer * encrypted_password = NULL ;
NTSTATUS status ;
WERROR werr ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b ;
2011-03-25 00:14:20 +03:00
DATA_BLOB session_key ;
2008-09-02 15:17:57 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_wkssvc ,
2008-09-02 15:17:57 +04:00
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-11 18:03:24 +03:00
b = pipe_cli - > binding_handle ;
2008-09-02 15:17:57 +04:00
if ( r - > in . password ) {
2011-03-25 00:14:20 +03:00
2011-03-25 14:13:36 +03:00
status = cli_get_session_key ( talloc_tos ( ) , pipe_cli , & session_key ) ;
2011-03-25 00:14:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2019-05-29 16:50:45 +03:00
werr = encode_wkssvc_join_password_buffer ( ctx ,
r - > in . password ,
& session_key ,
& encrypted_password ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-09-02 15:17:57 +04:00
}
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrRenameMachineInDomain2 ( b , talloc_tos ( ) ,
2008-09-02 15:17:57 +04:00
r - > in . server_name ,
r - > in . new_machine_name ,
r - > in . account ,
encrypted_password ,
r - > in . rename_options ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
return werr ;
2008-09-02 13:02:43 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetRenameMachineInDomain_l ( struct libnetapi_ctx * ctx ,
struct NetRenameMachineInDomain * r )
{
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetRenameMachineInDomain ) ;
}
2021-02-04 23:41:27 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetProvisionComputerAccount_r ( struct libnetapi_ctx * ctx ,
struct NetProvisionComputerAccount * r )
{
2021-02-05 15:05:45 +03:00
return NetProvisionComputerAccount_l ( ctx , r ) ;
2021-02-04 23:41:27 +03:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-02-05 15:05:45 +03:00
static WERROR NetProvisionComputerAccount_backend ( struct libnetapi_ctx * ctx ,
struct NetProvisionComputerAccount * r ,
TALLOC_CTX * mem_ctx ,
struct ODJ_PROVISION_DATA * * p )
{
WERROR werr ;
struct libnet_JoinCtx * j = NULL ;
int use_kerberos = 0 ;
const char * username = NULL ;
werr = libnet_init_JoinCtx ( mem_ctx , & j ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
j - > in . domain_name = talloc_strdup ( j , r - > in . domain ) ;
if ( j - > in . domain_name = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
talloc_free ( discard_const_p ( char * , j - > in . machine_name ) ) ;
j - > in . machine_name = talloc_strdup ( j , r - > in . machine_name ) ;
if ( j - > in . machine_name = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
if ( r - > in . dcname ) {
j - > in . dc_name = talloc_strdup ( j , r - > in . dcname ) ;
if ( j - > in . dc_name = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
}
if ( r - > in . machine_account_ou ) {
j - > in . account_ou = talloc_strdup ( j , r - > in . machine_account_ou ) ;
if ( j - > in . account_ou = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
}
libnetapi_get_username ( ctx , & username ) ;
if ( username = = NULL ) {
talloc_free ( j ) ;
return WERR_NERR_BADUSERNAME ;
}
j - > in . admin_account = talloc_strdup ( j , username ) ;
if ( j - > in . admin_account = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
libnetapi_get_use_kerberos ( ctx , & use_kerberos ) ;
if ( ! use_kerberos ) {
const char * password = NULL ;
libnetapi_get_password ( ctx , & password ) ;
if ( password = = NULL ) {
talloc_free ( j ) ;
return WERR_NERR_BADPASSWORD ;
}
j - > in . admin_password = talloc_strdup ( j , password ) ;
if ( j - > in . admin_password = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
}
j - > in . use_kerberos = use_kerberos ;
j - > in . debug = true ;
j - > in . join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ;
if ( r - > in . options & NETSETUP_PROVISION_REUSE_ACCOUNT ) {
j - > in . join_flags | = WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ;
}
if ( r - > in . options & NETSETUP_PROVISION_USE_DEFAULT_PASSWORD ) {
j - > in . join_flags | = WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED ;
j - > in . machine_password = talloc_strdup ( j , r - > in . machine_name ) ;
if ( j - > in . machine_password = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
}
j - > in . provision_computer_account_only = true ;
werr = libnet_Join ( mem_ctx , j ) ;
if ( ! W_ERROR_IS_OK ( werr ) & & j - > out . error_string ) {
libnetapi_set_error_string ( ctx , " %s " , j - > out . error_string ) ;
talloc_free ( j ) ;
return werr ;
}
werr = libnet_odj_compose_ODJ_PROVISION_DATA ( mem_ctx , j , p ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
talloc_free ( j ) ;
return werr ;
}
TALLOC_FREE ( j ) ;
return WERR_OK ;
}
2021-02-04 23:41:27 +03:00
WERROR NetProvisionComputerAccount_l ( struct libnetapi_ctx * ctx ,
struct NetProvisionComputerAccount * r )
{
2021-02-05 15:05:45 +03:00
WERROR werr ;
enum ndr_err_code ndr_err ;
const char * b64_bin_data_str ;
DATA_BLOB blob ;
struct ODJ_PROVISION_DATA_serialized_ptr odj_provision_data ;
struct ODJ_PROVISION_DATA * p ;
TALLOC_CTX * mem_ctx = talloc_new ( ctx ) ;
if ( r - > in . provision_bin_data = = NULL & &
r - > in . provision_text_data = = NULL ) {
return WERR_INVALID_PARAMETER ;
}
if ( r - > in . provision_bin_data ! = NULL & &
r - > in . provision_text_data ! = NULL ) {
return WERR_INVALID_PARAMETER ;
}
if ( r - > in . provision_bin_data = = NULL & &
r - > in . provision_bin_data_size ! = NULL ) {
return WERR_INVALID_PARAMETER ;
}
if ( r - > in . provision_bin_data ! = NULL & &
r - > in . provision_bin_data_size = = NULL ) {
return WERR_INVALID_PARAMETER ;
}
if ( r - > in . domain = = NULL ) {
return WERR_INVALID_PARAMETER ;
}
if ( r - > in . machine_name = = NULL ) {
return WERR_INVALID_PARAMETER ;
}
werr = NetProvisionComputerAccount_backend ( ctx , r , mem_ctx , & p ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
talloc_free ( mem_ctx ) ;
return werr ;
}
ZERO_STRUCT ( odj_provision_data ) ;
odj_provision_data . s . p = p ;
ndr_err = ndr_push_struct_blob ( & blob , ctx , & odj_provision_data ,
( ndr_push_flags_fn_t ) ndr_push_ODJ_PROVISION_DATA_serialized_ptr ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
talloc_free ( mem_ctx ) ;
return W_ERROR ( NERR_BadOfflineJoinInfo ) ;
}
talloc_free ( mem_ctx ) ;
if ( r - > out . provision_text_data ! = NULL ) {
b64_bin_data_str = base64_encode_data_blob ( ctx , blob ) ;
if ( b64_bin_data_str = = NULL ) {
return WERR_NOT_ENOUGH_MEMORY ;
}
* r - > out . provision_text_data = b64_bin_data_str ;
}
if ( r - > out . provision_bin_data ! = NULL & &
r - > out . provision_bin_data_size ! = NULL ) {
* r - > out . provision_bin_data = blob . data ;
* r - > out . provision_bin_data_size = blob . length ;
}
return werr ;
2021-02-04 23:41:27 +03:00
}
2021-02-08 15:59:40 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetRequestOfflineDomainJoin_r ( struct libnetapi_ctx * ctx ,
struct NetRequestOfflineDomainJoin * r )
{
return WERR_NOT_SUPPORTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-02-09 19:15:20 +03:00
static WERROR NetRequestOfflineDomainJoin_backend ( struct libnetapi_ctx * ctx ,
const struct ODJ_WIN7BLOB * win7blob ,
const struct ODJ_PROVISION_DATA * odj_provision_data )
{
struct libnet_JoinCtx * j = NULL ;
WERROR werr ;
werr = libnet_init_JoinCtx ( ctx , & j ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
j - > in . domain_name = talloc_strdup ( j , win7blob - > lpDomain ) ;
if ( j - > in . domain_name = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
talloc_free ( discard_const_p ( char * , j - > in . machine_name ) ) ;
j - > in . machine_name = talloc_strdup ( j , win7blob - > lpMachineName ) ;
if ( j - > in . machine_name = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
j - > in . machine_password = talloc_strdup ( j , win7blob - > lpMachinePassword ) ;
if ( j - > in . machine_password = = NULL ) {
talloc_free ( j ) ;
return WERR_NOT_ENOUGH_MEMORY ;
}
j - > in . request_offline_join = true ;
j - > in . odj_provision_data = discard_const ( odj_provision_data ) ;
j - > in . debug = true ;
j - > in . join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED ;
werr = libnet_Join ( j , j ) ;
2023-08-30 20:59:04 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
if ( j - > out . error_string ! = NULL ) {
libnetapi_set_error_string ( ctx , " %s " , j - > out . error_string ) ;
}
2021-02-09 19:15:20 +03:00
talloc_free ( j ) ;
return werr ;
}
TALLOC_FREE ( j ) ;
return WERR_OK ;
}
2021-02-08 15:59:40 +03:00
WERROR NetRequestOfflineDomainJoin_l ( struct libnetapi_ctx * ctx ,
struct NetRequestOfflineDomainJoin * r )
{
2021-02-09 19:15:20 +03:00
DATA_BLOB blob , blob_base64 ;
enum ndr_err_code ndr_err ;
struct ODJ_PROVISION_DATA_serialized_ptr odj_provision_data ;
bool ok ;
struct ODJ_WIN7BLOB win7blob = { 0 } ;
WERROR werr ;
if ( r - > in . provision_bin_data = = NULL | |
r - > in . provision_bin_data_size = = 0 ) {
return W_ERROR ( NERR_NoOfflineJoinInfo ) ;
}
if ( r - > in . provision_bin_data_size < 2 ) {
return W_ERROR ( NERR_BadOfflineJoinInfo ) ;
}
2023-09-04 11:47:06 +03:00
/*
* Windows produces and consumes UTF16 / UCS2 encoded blobs . Check for the
* unicode BOM mark and convert back to UNIX charset if necessary .
*/
2021-02-09 19:15:20 +03:00
if ( r - > in . provision_bin_data [ 0 ] = = 0xff & &
r - > in . provision_bin_data [ 1 ] = = 0xfe ) {
ok = convert_string_talloc ( ctx , CH_UTF16LE , CH_UNIX ,
r - > in . provision_bin_data + 2 ,
r - > in . provision_bin_data_size - 2 ,
& blob_base64 . data ,
& blob_base64 . length ) ;
if ( ! ok ) {
return W_ERROR ( NERR_BadOfflineJoinInfo ) ;
}
} else {
blob_base64 = data_blob ( r - > in . provision_bin_data ,
r - > in . provision_bin_data_size ) ;
}
blob = base64_decode_data_blob_talloc ( ctx , ( const char * ) blob_base64 . data ) ;
ndr_err = ndr_pull_struct_blob ( & blob , ctx , & odj_provision_data ,
( ndr_pull_flags_fn_t ) ndr_pull_ODJ_PROVISION_DATA_serialized_ptr ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return W_ERROR ( NERR_BadOfflineJoinInfo ) ;
}
if ( DEBUGLEVEL > = 10 ) {
NDR_PRINT_DEBUG ( ODJ_PROVISION_DATA_serialized_ptr , & odj_provision_data ) ;
}
if ( odj_provision_data . s . p - > ulVersion ! = 1 ) {
return W_ERROR ( NERR_ProvisioningBlobUnsupported ) ;
}
werr = libnet_odj_find_win7blob ( odj_provision_data . s . p , & win7blob ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
if ( ! ( r - > in . options & NETSETUP_PROVISION_ONLINE_CALLER ) ) {
return WERR_NERR_SETUPNOTJOINED ;
}
werr = NetRequestOfflineDomainJoin_backend ( ctx ,
& win7blob ,
odj_provision_data . s . p ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
return W_ERROR ( NERR_JoinPerformedMustRestart ) ;
2021-02-08 15:59:40 +03:00
}
2023-08-31 13:43:22 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetComposeOfflineDomainJoin_r ( struct libnetapi_ctx * ctx ,
struct NetComposeOfflineDomainJoin * r )
{
return WERR_NOT_SUPPORTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-08-31 13:45:42 +03:00
static WERROR NetComposeOfflineDomainJoin_backend ( struct libnetapi_ctx * ctx ,
struct NetComposeOfflineDomainJoin * r ,
TALLOC_CTX * mem_ctx ,
struct ODJ_PROVISION_DATA * * p )
{
struct libnet_JoinCtx * j = NULL ;
WERROR werr ;
werr = libnet_init_JoinCtx ( ctx , & j ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
j - > in . domain_name = talloc_strdup ( j , r - > in . dns_domain_name ) ;
if ( j - > in . domain_name = = NULL ) {
return WERR_NOT_ENOUGH_MEMORY ;
}
j - > in . dc_name = talloc_strdup ( j , r - > in . dc_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > in . dc_name ) ;
j - > in . machine_password = talloc_strdup ( j , r - > in . machine_account_password ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > in . machine_password ) ;
j - > out . account_name = talloc_strdup ( j , r - > in . machine_account_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . account_name ) ;
j - > out . dns_domain_name = talloc_strdup ( j , r - > in . dns_domain_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . dns_domain_name ) ;
j - > out . netbios_domain_name = talloc_strdup ( j , r - > in . netbios_domain_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . netbios_domain_name ) ;
j - > out . domain_sid = dom_sid_dup ( j , ( struct dom_sid * ) r - > in . domain_sid ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . domain_sid ) ;
j - > out . domain_guid = * r - > in . domain_guid ;
j - > out . forest_name = talloc_strdup ( j , r - > in . forest_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . forest_name ) ;
j - > out . domain_is_ad = r - > in . domain_is_ad ;
j - > out . dcinfo = talloc_zero ( j , struct netr_DsRGetDCNameInfo ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . dcinfo ) ;
j - > out . dcinfo - > dc_unc = talloc_asprintf ( j - > out . dcinfo , " \\ \\ %s " , r - > in . dc_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . dcinfo - > dc_unc ) ;
j - > out . dcinfo - > dc_address = talloc_asprintf ( j - > out . dcinfo , " \\ \\ %s " , r - > in . dc_address ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . dcinfo - > dc_address ) ;
j - > out . dcinfo - > dc_address_type = DS_ADDRESS_TYPE_INET ;
j - > out . dcinfo - > domain_guid = * r - > in . domain_guid ;
j - > out . dcinfo - > domain_name = talloc_strdup ( j - > out . dcinfo , r - > in . dns_domain_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . dcinfo - > domain_name ) ;
j - > out . dcinfo - > forest_name = talloc_strdup ( j - > out . dcinfo , r - > in . forest_name ) ;
W_ERROR_HAVE_NO_MEMORY ( j - > out . dcinfo - > forest_name ) ;
werr = libnet_odj_compose_ODJ_PROVISION_DATA ( mem_ctx , j , p ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
return WERR_OK ;
}
2023-08-31 13:43:22 +03:00
WERROR NetComposeOfflineDomainJoin_l ( struct libnetapi_ctx * ctx ,
struct NetComposeOfflineDomainJoin * r )
{
2023-08-31 13:45:42 +03:00
WERROR werr ;
enum ndr_err_code ndr_err ;
const char * b64_bin_data_str ;
DATA_BLOB blob ;
struct ODJ_PROVISION_DATA_serialized_ptr odj_compose_data ;
struct ODJ_PROVISION_DATA * p ;
TALLOC_CTX * tmp_ctx = talloc_stackframe ( ) ;
if ( r - > in . compose_bin_data = = NULL & &
r - > in . compose_text_data = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . compose_bin_data ! = NULL & &
r - > in . compose_text_data ! = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . compose_bin_data = = NULL & &
r - > in . compose_bin_data_size ! = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . compose_bin_data ! = NULL & &
r - > in . compose_bin_data_size = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . dns_domain_name = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . netbios_domain_name = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . domain_sid = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . domain_guid = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . forest_name = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . machine_account_name = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . machine_account_password = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . dc_name = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
if ( r - > in . dc_address = = NULL ) {
werr = WERR_INVALID_PARAMETER ;
goto out ;
}
werr = NetComposeOfflineDomainJoin_backend ( ctx , r , tmp_ctx , & p ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto out ;
}
ZERO_STRUCT ( odj_compose_data ) ;
odj_compose_data . s . p = p ;
ndr_err = ndr_push_struct_blob ( & blob , ctx , & odj_compose_data ,
( ndr_push_flags_fn_t ) ndr_push_ODJ_PROVISION_DATA_serialized_ptr ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
werr = W_ERROR ( NERR_BadOfflineJoinInfo ) ;
goto out ;
}
if ( r - > out . compose_text_data ! = NULL ) {
b64_bin_data_str = base64_encode_data_blob ( ctx , blob ) ;
if ( b64_bin_data_str = = NULL ) {
werr = WERR_NOT_ENOUGH_MEMORY ;
}
* r - > out . compose_text_data = b64_bin_data_str ;
}
if ( r - > out . compose_bin_data ! = NULL & &
r - > out . compose_bin_data_size ! = NULL ) {
* r - > out . compose_bin_data = blob . data ;
* r - > out . compose_bin_data_size = blob . length ;
}
werr = WERR_OK ;
out :
talloc_free ( tmp_ctx ) ;
return werr ;
2023-08-31 13:43:22 +03:00
}