2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2007
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "utils/net.h"
23 WERROR NetJoinDomain(const char *server_name,
24 const char *domain_name,
25 const char *account_ou,
30 TALLOC_CTX *mem_ctx = NULL;
31 struct cli_state *cli = NULL;
32 struct rpc_pipe_client *pipe_cli = NULL;
33 struct wkssvc_PasswordBuffer encrypted_password;
36 unsigned int old_timeout;
38 ZERO_STRUCT(encrypted_password);
40 mem_ctx = talloc_init("NetJoinDomain");
46 if (!server_name || is_myname_or_ipaddr(server_name)) {
47 werr = WERR_NOT_SUPPORTED;
52 werr = WERR_INVALID_PARAM;
56 status = net_make_ipc_connection_ex(domain_name,
59 if (!NT_STATUS_IS_OK(status)) {
60 werr = ntstatus_to_werror(status);
64 old_timeout = cli_set_timeout(cli, 60000);
66 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
69 werr = ntstatus_to_werror(status);
74 encode_wkssvc_join_password_buffer(mem_ctx,
76 &cli->user_session_key,
80 old_timeout = cli_set_timeout(cli, 60000);
82 status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx,
83 server_name, domain_name,
87 if (!NT_STATUS_IS_OK(status)) {
88 werr = ntstatus_to_werror(status);
96 cli_set_timeout(cli, old_timeout);
104 WERROR NetUnjoinDomain(const char *server_name,
106 const char *password,
107 uint32_t unjoin_flags)
109 TALLOC_CTX *mem_ctx = NULL;
110 struct cli_state *cli = NULL;
111 struct rpc_pipe_client *pipe_cli = NULL;
112 struct wkssvc_PasswordBuffer encrypted_password;
115 unsigned int old_timeout;
117 ZERO_STRUCT(encrypted_password);
119 mem_ctx = talloc_init("NetUnjoinDomain");
125 if (!server_name || is_myname_or_ipaddr(server_name)) {
126 werr = WERR_NOT_SUPPORTED;
130 status = net_make_ipc_connection_ex(NULL,
133 if (!NT_STATUS_IS_OK(status)) {
134 werr = ntstatus_to_werror(status);
138 old_timeout = cli_set_timeout(cli, 60000);
140 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
143 werr = ntstatus_to_werror(status);
148 encode_wkssvc_join_password_buffer(mem_ctx,
150 &cli->user_session_key,
151 &encrypted_password);
154 old_timeout = cli_set_timeout(cli, 60000);
156 status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, mem_ctx,
161 if (!NT_STATUS_IS_OK(status)) {
162 werr = ntstatus_to_werror(status);
170 cli_set_timeout(cli, old_timeout);
173 TALLOC_FREE(mem_ctx);