2 Samba Unix/Linux SMB client library
3 net dom commands for remote join/unjoin
4 Copyright (C) 2007 Günther Deschner
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"
22 #include "lib/netapi/joindomain.h"
24 static int net_dom_usage(int argc
, const char **argv
)
26 d_printf("usage: net dom join "
27 "<domain=DOMAIN> <ou=OU> <account=ACCOUNT> <password=PASSWORD> <reboot>\n");
28 d_printf("usage: net dom unjoin "
29 "<account=ACCOUNT> <password=PASSWORD> <reboot>\n");
34 int net_help_dom(int argc
, const char **argv
)
36 d_printf("net dom join"\
37 "\n Join a remote machine\n");
38 d_printf("net dom unjoin"\
39 "\n Unjoin a remote machine\n");
44 static int net_dom_unjoin(int argc
, const char **argv
)
46 const char *server_name
= NULL
;
47 const char *account
= NULL
;
48 const char *password
= NULL
;
49 uint32_t unjoin_flags
= WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE
|
50 WKSSVC_JOIN_FLAGS_JOIN_TYPE
;
51 struct cli_state
*cli
= NULL
;
59 return net_dom_usage(argc
, argv
);
62 server_name
= opt_host
;
64 for (i
=0; i
<argc
; i
++) {
65 if (strnequal(argv
[i
], "account", strlen("account"))) {
66 account
= get_string_param(argv
[i
]);
71 if (strnequal(argv
[i
], "password", strlen("password"))) {
72 password
= get_string_param(argv
[i
]);
77 if (strequal(argv
[i
], "reboot")) {
83 status
= net_make_ipc_connection_ex(opt_workgroup
, server_name
,
85 if (!NT_STATUS_IS_OK(status
)) {
90 werr
= NetUnjoinDomain(server_name
, account
, password
, unjoin_flags
);
91 if (!W_ERROR_IS_OK(werr
)) {
92 printf("Failed to unjoin domain: %s\n",
93 get_friendly_nt_error_msg(werror_to_ntstatus(werr
)));
98 opt_comment
= "Shutting down due to a domain membership change";
102 ret
= run_rpc_command(cli
, PI_INITSHUTDOWN
, 0,
103 rpc_init_shutdown_internals
,
109 ret
= run_rpc_command(cli
, PI_WINREG
, 0,
110 rpc_reg_shutdown_internals
,
125 static int net_dom_join(int argc
, const char **argv
)
127 const char *server_name
= NULL
;
128 const char *domain_name
= NULL
;
129 const char *account_ou
= NULL
;
130 const char *Account
= NULL
;
131 const char *password
= NULL
;
132 uint32_t join_flags
= WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
|
133 WKSSVC_JOIN_FLAGS_JOIN_TYPE
;
134 struct cli_state
*cli
= NULL
;
142 return net_dom_usage(argc
, argv
);
145 server_name
= opt_host
;
148 join_flags
|= WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
;
151 for (i
=0; i
<argc
; i
++) {
152 if (strnequal(argv
[i
], "ou", strlen("ou"))) {
153 account_ou
= get_string_param(argv
[i
]);
158 if (strnequal(argv
[i
], "domain", strlen("domain"))) {
159 domain_name
= get_string_param(argv
[i
]);
164 if (strnequal(argv
[i
], "account", strlen("account"))) {
165 Account
= get_string_param(argv
[i
]);
170 if (strnequal(argv
[i
], "password", strlen("password"))) {
171 password
= get_string_param(argv
[i
]);
176 if (strequal(argv
[i
], "reboot")) {
182 status
= net_make_ipc_connection_ex(opt_workgroup
, server_name
,
184 if (!NT_STATUS_IS_OK(status
)) {
189 /* check if domain is a domain or a workgroup */
191 werr
= NetJoinDomain(server_name
, domain_name
, account_ou
,
192 Account
, password
, join_flags
);
193 if (!W_ERROR_IS_OK(werr
)) {
194 printf("Failed to join domain: %s\n",
195 get_friendly_nt_error_msg(werror_to_ntstatus(werr
)));
200 opt_comment
= "Shutting down due to a domain membership change";
204 ret
= run_rpc_command(cli
, PI_INITSHUTDOWN
, 0,
205 rpc_init_shutdown_internals
,
211 ret
= run_rpc_command(cli
, PI_WINREG
, 0,
212 rpc_reg_shutdown_internals
,
227 int net_dom(int argc
, const char **argv
)
229 struct functable func
[] = {
230 {"JOIN", net_dom_join
},
231 {"UNJOIN", net_dom_unjoin
},
232 {"HELP", net_help_dom
},
236 return net_run_function(argc
, argv
, func
, net_dom_usage
);