2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
5 Copyright (C) 2004 Stefan Metzmacher <metze@samba.org>
6 Copyright (C) 2005 Andrew Bartlett <abartlet@samba.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "utils/net/net.h"
24 #include "libnet/libnet.h"
25 #include "libcli/security/security.h"
26 #include "param/param.h"
27 #include "lib/events/events.h"
29 int net_join(struct net_context *ctx, int argc, const char **argv)
32 struct libnet_context *libnetctx;
33 struct libnet_Join *r;
35 const char *domain_name;
36 enum netr_SchannelType secure_channel_type = SEC_CHAN_WKSTA;
39 case 0: /* no args -> fail */
40 return net_join_usage(ctx, argc, argv);
41 case 1: /* only DOMAIN */
42 tmp = talloc_strdup(ctx, argv[0]);
44 case 2: /* DOMAIN and role */
45 tmp = talloc_strdup(ctx, argv[0]);
46 if (strcasecmp(argv[1], "BDC") == 0) {
47 secure_channel_type = SEC_CHAN_BDC;
48 } else if (strcasecmp(argv[1], "MEMBER") == 0) {
49 secure_channel_type = SEC_CHAN_WKSTA;
51 d_fprintf(stderr, "net_join: Invalid 2nd argument (%s) must be MEMBER or BDC\n", argv[1]);
52 return net_join_usage(ctx, argc, argv);
55 default: /* too many args -> fail */
56 return net_join_usage(ctx, argc, argv);
61 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
65 libnetctx->cred = ctx->credentials;
66 r = talloc(ctx, struct libnet_Join);
70 /* prepare parameters for the join */
71 r->in.netbios_name = lp_netbios_name(ctx->lp_ctx);
72 r->in.domain_name = domain_name;
73 r->in.join_type = secure_channel_type;
74 r->in.level = LIBNET_JOIN_AUTOMATIC;
75 r->out.error_string = NULL;
77 /* do the domain join */
78 status = libnet_Join(libnetctx, r, r);
80 if (!NT_STATUS_IS_OK(status)) {
81 d_fprintf(stderr, "Joining domain failed: %s\n",
82 r->out.error_string ? r->out.error_string : nt_errstr(status));
84 talloc_free(libnetctx);
87 d_printf("Joined domain %s (%s)\n", r->out.domain_name, dom_sid_string(ctx, r->out.domain_sid));
89 talloc_free(libnetctx);
93 int net_join_usage(struct net_context *ctx, int argc, const char **argv)
95 d_printf("net join <domain> [BDC | MEMBER] [options]\n");
99 int net_join_help(struct net_context *ctx, int argc, const char **argv)
101 d_printf("Joins domain as either member or backup domain controller.\n");
105 int net_vampire(struct net_context *ctx, int argc, const char **argv)
108 struct libnet_context *libnetctx;
109 struct libnet_Vampire *r;
110 char *tmp, *targetdir = NULL;
111 const char *domain_name;
114 case 0: /* no args -> fail */
115 return net_vampire_usage(ctx, argc, argv);
116 case 1: /* only DOMAIN */
117 tmp = talloc_strdup(ctx, argv[0]);
119 case 2: /* domain and target dir */
120 tmp = talloc_strdup(ctx, argv[0]);
121 targetdir = talloc_strdup(ctx, argv[1]);
123 default: /* too many args -> fail */
124 return net_vampire_usage(ctx, argc, argv);
129 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
133 libnetctx->cred = ctx->credentials;
134 r = talloc(ctx, struct libnet_Vampire);
138 /* prepare parameters for the vampire */
139 r->in.netbios_name = lp_netbios_name(ctx->lp_ctx);
140 r->in.domain_name = domain_name;
141 r->in.targetdir = targetdir;
142 r->out.error_string = NULL;
144 /* do the domain vampire */
145 status = libnet_Vampire(libnetctx, r, r);
147 if (!NT_STATUS_IS_OK(status)) {
148 d_fprintf(stderr, "Vampire of domain failed: %s\n",
149 r->out.error_string ? r->out.error_string : nt_errstr(status));
151 talloc_free(libnetctx);
154 d_printf("Vampired domain %s (%s)\n", r->out.domain_name, dom_sid_string(ctx, r->out.domain_sid));
156 talloc_free(libnetctx);
160 int net_vampire_usage(struct net_context *ctx, int argc, const char **argv)
162 d_printf("net vampire <domain> [options]\n");
166 int net_vampire_help(struct net_context *ctx, int argc, const char **argv)
168 d_printf("Vampires domain as either member or backup domain controller.\n");