Give NetJoinDomain() enough time to finish.
[Samba.git] / source3 / lib / netapi / joindomain.c
blob7c71276de6f5f21782a72965ec85cf7d62364dd6
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetApi Join Support
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/>.
20 #include "includes.h"
21 #include "utils/net.h"
23 WERROR NetJoinDomain(const char *server_name,
24 const char *domain_name,
25 const char *account_ou,
26 const char *Account,
27 const char *password,
28 uint32_t join_flags)
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;
34 NTSTATUS status;
35 WERROR werr;
36 unsigned int old_timeout;
38 mem_ctx = talloc_init("NetJoinDomain");
39 if (!mem_ctx) {
40 werr = WERR_NOMEM;
41 goto done;
44 if (!server_name || is_myname_or_ipaddr(server_name)) {
45 werr = WERR_NOT_SUPPORTED;
46 goto done;
49 if (!domain_name) {
50 werr = WERR_INVALID_PARAM;
51 goto done;
54 status = net_make_ipc_connection_ex(domain_name,
55 server_name,
56 NULL, 0, &cli);
57 if (!NT_STATUS_IS_OK(status)) {
58 werr = ntstatus_to_werror(status);
59 goto done;
62 old_timeout = cli_set_timeout(cli, 60000);
64 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
65 &status);
66 if (!pipe_cli) {
67 werr = ntstatus_to_werror(status);
68 goto done;
71 encode_wkssvc_join_password_buffer(mem_ctx,
72 password,
73 &cli->user_session_key,
74 &encrypted_password);
76 old_timeout = cli_set_timeout(cli, 60000);
78 status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx,
79 server_name, domain_name,
80 account_ou, Account,
81 &encrypted_password,
82 join_flags);
83 if (!NT_STATUS_IS_OK(status)) {
84 werr = ntstatus_to_werror(status);
87 werr = WERR_OK;
89 done:
90 cli_set_timeout(cli, old_timeout);
91 cli_shutdown(cli);
92 TALLOC_FREE(mem_ctx);
94 return werr;