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 "lib/netapi/joindomain.h"
23 extern const char *opt_user_name;
24 extern const char *opt_workgroup;
25 extern const char *opt_password;
27 WERROR NetJoinDomain(const char *server_name,
28 const char *domain_name,
29 const char *account_ou,
34 TALLOC_CTX *mem_ctx = NULL;
35 struct cli_state *cli = NULL;
36 struct rpc_pipe_client *pipe_cli = NULL;
37 struct wkssvc_PasswordBuffer encrypted_password;
40 unsigned int old_timeout = 0;
42 ZERO_STRUCT(encrypted_password);
44 mem_ctx = talloc_init("NetJoinDomain");
50 if (!server_name || is_myname_or_ipaddr(server_name)) {
51 werr = WERR_NOT_SUPPORTED;
56 werr = WERR_INVALID_PARAM;
60 status = cli_full_connection(&cli, NULL, server_name,
63 opt_user_name, opt_workgroup,
64 opt_password, 0, Undefined, NULL);
66 if (!NT_STATUS_IS_OK(status)) {
67 werr = ntstatus_to_werror(status);
71 old_timeout = cli_set_timeout(cli, 60000);
73 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
76 werr = ntstatus_to_werror(status);
81 encode_wkssvc_join_password_buffer(mem_ctx,
83 &cli->user_session_key,
87 old_timeout = cli_set_timeout(cli, 60000);
89 status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx,
90 server_name, domain_name,
94 if (!NT_STATUS_IS_OK(status)) {
95 werr = ntstatus_to_werror(status);
101 cli_set_timeout(cli, old_timeout);
104 TALLOC_FREE(mem_ctx);
109 WERROR NetUnjoinDomain(const char *server_name,
111 const char *password,
112 uint32_t unjoin_flags)
114 TALLOC_CTX *mem_ctx = NULL;
115 struct cli_state *cli = NULL;
116 struct rpc_pipe_client *pipe_cli = NULL;
117 struct wkssvc_PasswordBuffer encrypted_password;
120 unsigned int old_timeout = 0;
122 ZERO_STRUCT(encrypted_password);
124 mem_ctx = talloc_init("NetUnjoinDomain");
130 if (!server_name || is_myname_or_ipaddr(server_name)) {
131 werr = WERR_NOT_SUPPORTED;
135 status = cli_full_connection(&cli, NULL, server_name,
138 opt_user_name, opt_workgroup,
139 opt_password, 0, Undefined, NULL);
141 if (!NT_STATUS_IS_OK(status)) {
142 werr = ntstatus_to_werror(status);
146 old_timeout = cli_set_timeout(cli, 60000);
148 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
151 werr = ntstatus_to_werror(status);
156 encode_wkssvc_join_password_buffer(mem_ctx,
158 &cli->user_session_key,
159 &encrypted_password);
162 old_timeout = cli_set_timeout(cli, 60000);
164 status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, mem_ctx,
170 if (!NT_STATUS_IS_OK(status)) {
171 werr = ntstatus_to_werror(status);
177 cli_set_timeout(cli, old_timeout);
180 TALLOC_FREE(mem_ctx);
185 WERROR NetGetJoinInformation(const char *server_name,
186 const char **name_buffer,
189 TALLOC_CTX *mem_ctx = NULL;
190 struct cli_state *cli = NULL;
191 struct rpc_pipe_client *pipe_cli = NULL;
195 mem_ctx = talloc_init("NetGetJoinInformation");
201 status = cli_full_connection(&cli, NULL, server_name,
204 opt_user_name, opt_workgroup,
205 opt_password, 0, Undefined, NULL);
207 if (!NT_STATUS_IS_OK(status)) {
208 werr = ntstatus_to_werror(status);
212 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
215 werr = ntstatus_to_werror(status);
219 status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, mem_ctx,
222 (enum wkssvc_NetJoinStatus *)name_type,
224 if (!NT_STATUS_IS_OK(status)) {
225 werr = ntstatus_to_werror(status);
233 TALLOC_FREE(mem_ctx);