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/>.
22 extern const char *opt_user_name;
23 extern const char *opt_workgroup;
24 extern const char *opt_password;
26 WERROR NetJoinDomain(const char *server_name,
27 const char *domain_name,
28 const char *account_ou,
33 TALLOC_CTX *mem_ctx = NULL;
34 struct cli_state *cli = NULL;
35 struct rpc_pipe_client *pipe_cli = NULL;
36 struct wkssvc_PasswordBuffer encrypted_password;
39 unsigned int old_timeout = 0;
41 ZERO_STRUCT(encrypted_password);
43 mem_ctx = talloc_init("NetJoinDomain");
49 if (!server_name || is_myname_or_ipaddr(server_name)) {
50 werr = WERR_NOT_SUPPORTED;
55 werr = WERR_INVALID_PARAM;
59 status = cli_full_connection(&cli, NULL, server_name,
62 opt_user_name, opt_workgroup,
63 opt_password, 0, Undefined, NULL);
65 if (!NT_STATUS_IS_OK(status)) {
66 werr = ntstatus_to_werror(status);
70 old_timeout = cli_set_timeout(cli, 60000);
72 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
75 werr = ntstatus_to_werror(status);
80 encode_wkssvc_join_password_buffer(mem_ctx,
82 &cli->user_session_key,
86 old_timeout = cli_set_timeout(cli, 60000);
88 status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx,
89 server_name, domain_name,
93 if (!NT_STATUS_IS_OK(status)) {
94 werr = ntstatus_to_werror(status);
100 cli_set_timeout(cli, old_timeout);
103 TALLOC_FREE(mem_ctx);
108 WERROR NetUnjoinDomain(const char *server_name,
110 const char *password,
111 uint32_t unjoin_flags)
113 TALLOC_CTX *mem_ctx = NULL;
114 struct cli_state *cli = NULL;
115 struct rpc_pipe_client *pipe_cli = NULL;
116 struct wkssvc_PasswordBuffer encrypted_password;
119 unsigned int old_timeout = 0;
121 ZERO_STRUCT(encrypted_password);
123 mem_ctx = talloc_init("NetUnjoinDomain");
129 if (!server_name || is_myname_or_ipaddr(server_name)) {
130 werr = WERR_NOT_SUPPORTED;
134 status = cli_full_connection(&cli, NULL, server_name,
137 opt_user_name, opt_workgroup,
138 opt_password, 0, Undefined, NULL);
140 if (!NT_STATUS_IS_OK(status)) {
141 werr = ntstatus_to_werror(status);
145 old_timeout = cli_set_timeout(cli, 60000);
147 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
150 werr = ntstatus_to_werror(status);
155 encode_wkssvc_join_password_buffer(mem_ctx,
157 &cli->user_session_key,
158 &encrypted_password);
161 old_timeout = cli_set_timeout(cli, 60000);
163 status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, mem_ctx,
169 if (!NT_STATUS_IS_OK(status)) {
170 werr = ntstatus_to_werror(status);
176 cli_set_timeout(cli, old_timeout);
179 TALLOC_FREE(mem_ctx);