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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "utils/net/net.h"
25 #include "libnet/libnet.h"
26 #include "librpc/gen_ndr/ndr_samr.h"
28 int net_join(struct net_context *ctx, int argc, const char **argv)
31 struct libnet_context *libnetctx;
34 const char *domain_name;
35 enum netr_SchannelType secure_channel_type = SEC_CHAN_WKSTA;
38 case 0: /* no args -> fail */
39 return net_join_usage(ctx, argc, argv);
40 case 1: /* only DOMAIN */
41 tmp = talloc_strdup(ctx->mem_ctx, argv[0]);
43 case 2: /* DOMAIN and role */
44 tmp = talloc_strdup(ctx->mem_ctx, argv[0]);
45 if (strcasecmp(argv[1], "BDC") == 0) {
46 secure_channel_type = SEC_CHAN_BDC;
47 } else if (strcasecmp(argv[1], "MEMBER") == 0) {
48 secure_channel_type = SEC_CHAN_WKSTA;
50 DEBUG(0, ("net_join: 2nd argument must be MEMBER or BDC\n"));
51 return net_join_usage(ctx, argc, argv);
54 default: /* too many args -> fail */
55 return net_join_usage(ctx, argc, argv);
60 libnetctx = libnet_context_init();
64 libnetctx->user.account_name= cli_credentials_get_username(ctx->credentials);
65 libnetctx->user.domain_name = cli_credentials_get_domain(ctx->credentials);
66 libnetctx->user.password = cli_credentials_get_password(ctx->credentials);
68 /* prepare password change */
69 r.generic.level = LIBNET_JOIN_GENERIC;
70 r.generic.in.domain_name = domain_name;
71 r.generic.in.secure_channel_type = secure_channel_type;
72 r.generic.out.error_string = NULL;
74 /* do the domain join */
75 status = libnet_Join(libnetctx, ctx->mem_ctx, &r);
76 if (!NT_STATUS_IS_OK(status)) {
77 DEBUG(0,("libnet_Join returned %s: %s\n",
79 r.generic.out.error_string));
83 libnet_context_destroy(&libnetctx);
88 int net_join_usage(struct net_context *ctx, int argc, const char **argv)
90 d_printf("net join <domain> [BDC | MEMBER] [options]\n");
94 int net_join_help(struct net_context *ctx, int argc, const char **argv)
96 d_printf("Joins domain as either member or backup domain controller.\n");