source: branches/samba-3.3.x/source/utils/net_dom.c@ 259

Last change on this file since 259 was 206, checked in by Herwig Bauernfeind, 17 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 6.0 KB
RevLine 
[206]1/*
2 Samba Unix/Linux SMB client library
3 net dom commands for remote join/unjoin
4 Copyright (C) 2007 GÃŒnther Deschner
5
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.
10
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.
15
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/>.
18*/
19
20#include "includes.h"
21#include "utils/net.h"
22
23int net_dom_usage(struct net_context *c, int argc, const char **argv)
24{
25 d_printf("usage: net dom join "
26 "<domain=DOMAIN> <ou=OU> <account=ACCOUNT> "
27 "<password=PASSWORD> <reboot>\n Join a remote machine\n");
28 d_printf("usage: net dom unjoin "
29 "<account=ACCOUNT> <password=PASSWORD> <reboot>\n"
30 " Unjoin a remote machine\n");
31
32 return -1;
33}
34
35static int net_dom_unjoin(struct net_context *c, int argc, const char **argv)
36{
37 const char *server_name = NULL;
38 const char *account = NULL;
39 const char *password = NULL;
40 uint32_t unjoin_flags = NETSETUP_ACCT_DELETE |
41 NETSETUP_JOIN_DOMAIN;
42 struct cli_state *cli = NULL;
43 bool do_reboot = false;
44 NTSTATUS ntstatus;
45 NET_API_STATUS status;
46 int ret = -1;
47 int i;
48
49 if (argc < 1 || c->display_usage) {
50 return net_dom_usage(c, argc, argv);
51 }
52
53 if (c->opt_host) {
54 server_name = c->opt_host;
55 }
56
57 for (i=0; i<argc; i++) {
58 if (strnequal(argv[i], "account", strlen("account"))) {
59 account = get_string_param(argv[i]);
60 if (!account) {
61 return -1;
62 }
63 }
64 if (strnequal(argv[i], "password", strlen("password"))) {
65 password = get_string_param(argv[i]);
66 if (!password) {
67 return -1;
68 }
69 }
70 if (strequal(argv[i], "reboot")) {
71 do_reboot = true;
72 }
73 }
74
75 if (do_reboot) {
76 ntstatus = net_make_ipc_connection_ex(c, c->opt_workgroup,
77 server_name, NULL, 0,
78 &cli);
79 if (!NT_STATUS_IS_OK(ntstatus)) {
80 return -1;
81 }
82 }
83
84 status = NetUnjoinDomain(server_name, account, password, unjoin_flags);
85 if (status != 0) {
86 printf("Failed to unjoin domain: %s\n",
87 libnetapi_get_error_string(c->netapi_ctx, status));
88 goto done;
89 }
90
91 if (do_reboot) {
92 c->opt_comment = "Shutting down due to a domain membership "
93 "change";
94 c->opt_reboot = true;
95 c->opt_timeout = 30;
96
97 ret = run_rpc_command(c, cli,
98 &ndr_table_initshutdown.syntax_id,
99 0, rpc_init_shutdown_internals,
100 argc, argv);
101 if (ret == 0) {
102 goto done;
103 }
104
105 ret = run_rpc_command(c, cli, &ndr_table_winreg.syntax_id, 0,
106 rpc_reg_shutdown_internals,
107 argc, argv);
108 goto done;
109 }
110