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"
23 static int net_dom_usage(int argc
, const char **argv
)
25 d_printf("usage: net dom join "
26 "<domain=DOMAIN> <ou=OU> <account=ACCOUNT> <password=PASSWORD> <reboot>\n");
27 d_printf("usage: net dom unjoin "
28 "<account=ACCOUNT> <password=PASSWORD> <reboot>\n");
33 int net_help_dom(int argc
, const char **argv
)
35 d_printf("net dom join"\
36 "\n Join a remote machine\n");
37 d_printf("net dom unjoin"\
38 "\n Unjoin a remote machine\n");
43 static int net_dom_unjoin(int argc
, const char **argv
)
45 struct libnetapi_ctx
*ctx
= NULL
;
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
;
54 NET_API_STATUS status
;
59 return net_dom_usage(argc
, argv
);
63 server_name
= opt_host
;
66 for (i
=0; i
<argc
; i
++) {
67 if (strnequal(argv
[i
], "account", strlen("account"))) {
68 account
= get_string_param(argv
[i
]);
73 if (strnequal(argv
[i
], "password", strlen("password"))) {
74 password
= get_string_param(argv
[i
]);
79 if (strequal(argv
[i
], "reboot")) {
85 ntstatus
= net_make_ipc_connection_ex(opt_workgroup
, server_name
,
87 if (!NT_STATUS_IS_OK(ntstatus
)) {
92 status
= libnetapi_init(&ctx
);
97 libnetapi_set_username(ctx
, opt_user_name
);
98 libnetapi_set_password(ctx
, opt_password
);
100 status
= NetUnjoinDomain(server_name
, account
, password
, unjoin_flags
);
102 printf("Failed to unjoin domain: %s\n",
103 libnetapi_get_error_string(ctx
, status
));
108 opt_comment
= "Shutting down due to a domain membership change";
112 ret
= run_rpc_command(cli
, PI_INITSHUTDOWN
, 0,
113 rpc_init_shutdown_internals
,
119 ret
= run_rpc_command(cli
, PI_WINREG
, 0,
120 rpc_reg_shutdown_internals
,
135 static int net_dom_join(int argc
, const char **argv
)
137 struct libnetapi_ctx
*ctx
= NULL
;
138 const char *server_name
= NULL
;
139 const char *domain_name
= NULL
;
140 const char *account_ou
= NULL
;
141 const char *Account
= NULL
;
142 const char *password
= NULL
;
143 uint32_t join_flags
= WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
|
144 WKSSVC_JOIN_FLAGS_JOIN_TYPE
;
145 struct cli_state
*cli
= NULL
;
148 NET_API_STATUS status
;
153 return net_dom_usage(argc
, argv
);
157 server_name
= opt_host
;
161 join_flags
|= WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
;
164 for (i
=0; i
<argc
; i
++) {
165 if (strnequal(argv
[i
], "ou", strlen("ou"))) {
166 account_ou
= get_string_param(argv
[i
]);
171 if (strnequal(argv
[i
], "domain", strlen("domain"))) {
172 domain_name
= get_string_param(argv
[i
]);
177 if (strnequal(argv
[i
], "account", strlen("account"))) {
178 Account
= get_string_param(argv
[i
]);
183 if (strnequal(argv
[i
], "password", strlen("password"))) {
184 password
= get_string_param(argv
[i
]);
189 if (strequal(argv
[i
], "reboot")) {
195 ntstatus
= net_make_ipc_connection_ex(opt_workgroup
, server_name
,
197 if (!NT_STATUS_IS_OK(ntstatus
)) {
202 /* check if domain is a domain or a workgroup */
204 status
= libnetapi_init(&ctx
);
209 libnetapi_set_username(ctx
, opt_user_name
);
210 libnetapi_set_password(ctx
, opt_password
);
212 status
= NetJoinDomain(server_name
, domain_name
, account_ou
,
213 Account
, password
, join_flags
);
215 printf("Failed to join domain: %s\n",
216 libnetapi_get_error_string(ctx
, status
));
221 opt_comment
= "Shutting down due to a domain membership change";
225 ret
= run_rpc_command(cli
, PI_INITSHUTDOWN
, 0,
226 rpc_init_shutdown_internals
,
232 ret
= run_rpc_command(cli
, PI_WINREG
, 0,
233 rpc_reg_shutdown_internals
,
248 int net_dom(int argc
, const char **argv
)
250 struct functable func
[] = {
251 {"JOIN", net_dom_join
},
252 {"UNJOIN", net_dom_unjoin
},
253 {"HELP", net_help_dom
},
257 return net_run_function(argc
, argv
, func
, net_dom_usage
);