1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

Actually implement reboot feature for net dom join/unjoin.

Guenther
(This used to be commit bbbeeba163)
This commit is contained in:
Günther Deschner 2007-12-03 11:07:27 +01:00
parent 107c1f854d
commit e9e182feda
2 changed files with 77 additions and 8 deletions

View File

@ -48,8 +48,11 @@ static int net_dom_unjoin(int argc, const char **argv)
const char *password = NULL;
uint32_t unjoin_flags = WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE |
WKSSVC_JOIN_FLAGS_JOIN_TYPE;
struct cli_state *cli = NULL;
bool reboot = false;
NTSTATUS status;
WERROR werr;
int ret = -1;
int i;
if (argc < 1) {
@ -76,16 +79,47 @@ static int net_dom_unjoin(int argc, const char **argv)
}
}
if (reboot) {
status = net_make_ipc_connection_ex(opt_workgroup, server_name,
NULL, 0, &cli);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
}
werr = NetUnjoinDomain(server_name, account, password, unjoin_flags);
if (!W_ERROR_IS_OK(werr)) {
printf("Failed to unjoin domain: %s\n",
get_friendly_nt_error_msg(werror_to_ntstatus(werr)));
return -1;
goto done;
}
/* reboot then */
if (reboot) {
opt_comment = "Shutting down due to a domain membership change";
opt_reboot = true;
opt_timeout = 30;
return 0;
ret = run_rpc_command(cli, PI_INITSHUTDOWN, 0,
rpc_init_shutdown_internals,
argc, argv);
if (ret == 0) {
goto done;
}
ret = run_rpc_command(cli, PI_WINREG, 0,
rpc_reg_shutdown_internals,
argc, argv);
goto done;
}
ret = 0;
done:
if (cli) {
cli_shutdown(cli);
}
return ret;
}
static int net_dom_join(int argc, const char **argv)
@ -97,8 +131,11 @@ static int net_dom_join(int argc, const char **argv)
const char *password = NULL;
uint32_t join_flags = WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE |
WKSSVC_JOIN_FLAGS_JOIN_TYPE;
struct cli_state *cli = NULL;
bool reboot = false;
NTSTATUS status;
WERROR werr;
int ret = -1;
int i;
if (argc < 1) {
@ -141,6 +178,14 @@ static int net_dom_join(int argc, const char **argv)
}
}
if (reboot) {
status = net_make_ipc_connection_ex(opt_workgroup, server_name,
NULL, 0, &cli);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
}
/* check if domain is a domain or a workgroup */
werr = NetJoinDomain(server_name, domain_name, account_ou,
@ -148,12 +193,35 @@ static int net_dom_join(int argc, const char **argv)
if (!W_ERROR_IS_OK(werr)) {
printf("Failed to join domain: %s\n",
get_friendly_nt_error_msg(werror_to_ntstatus(werr)));
return -1;
goto done;
}
/* reboot then */
if (reboot) {
opt_comment = "Shutting down due to a domain membership change";
opt_reboot = true;
opt_timeout = 30;
return 0;
ret = run_rpc_command(cli, PI_INITSHUTDOWN, 0,
rpc_init_shutdown_internals,
argc, argv);
if (ret == 0) {
goto done;
}
ret = run_rpc_command(cli, PI_WINREG, 0,
rpc_reg_shutdown_internals,
argc, argv);
goto done;
}
ret = 0;
done:
if (cli) {
cli_shutdown(cli);
}
return ret;
}
int net_dom(int argc, const char **argv)
@ -161,6 +229,7 @@ int net_dom(int argc, const char **argv)
struct functable func[] = {
{"JOIN", net_dom_join},
{"UNJOIN", net_dom_unjoin},
{"HELP", net_help_dom},
{NULL, NULL}
};

View File

@ -5181,7 +5181,7 @@ static int rpc_shutdown_abort(int argc, const char **argv)
* @return Normal NTSTATUS return.
**/
static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
const char *domain_name,
struct cli_state *cli,
struct rpc_pipe_client *pipe_hnd,
@ -5234,7 +5234,7 @@ static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
* @return Normal NTSTATUS return.
**/
static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
const char *domain_name,
struct cli_state *cli,
struct rpc_pipe_client *pipe_hnd,