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 mem_ctx = talloc_init("NetJoinDomain");
44 if (!server_name || is_myname_or_ipaddr(server_name)) {
45 werr = WERR_NOT_SUPPORTED;
50 werr = WERR_INVALID_PARAM;
54 status = net_make_ipc_connection_ex(domain_name,
57 if (!NT_STATUS_IS_OK(status)) {
58 werr = ntstatus_to_werror(status);
62 old_timeout = cli_set_timeout(cli, 60000);
64 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
67 werr = ntstatus_to_werror(status);
71 encode_wkssvc_join_password_buffer(mem_ctx,
73 &cli->user_session_key,
76 old_timeout = cli_set_timeout(cli, 60000);
78 status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx,
79 server_name, domain_name,
83 if (!NT_STATUS_IS_OK(status)) {
84 werr = ntstatus_to_werror(status);
90 cli_set_timeout(cli, old_timeout);