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 DEBUG(0,("net_join_domain: no args\n"));
41 case 1: /* only DOMAIN */
42 tmp = talloc_strdup(ctx->mem_ctx, argv[0]);
44 case 2: /* DOMAIN and role */
45 tmp = talloc_strdup(ctx->mem_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 DEBUG(0, ("net_join: 2nd argument must be MEMBER or BDC\n"));
55 default: /* too many args -> fail */
56 DEBUG(0,("net_join: too many args [%d]\n",argc));
62 libnetctx = libnet_context_init();
66 libnetctx->user.account_name = ctx->user.account_name;
67 libnetctx->user.domain_name = ctx->user.domain_name;
68 libnetctx->user.password = ctx->user.password;
70 /* prepare password change */
71 r.generic.level = LIBNET_JOIN_GENERIC;
72 r.generic.in.domain_name = domain_name;
73 r.generic.in.secure_channel_type = secure_channel_type;
74 r.generic.out.error_string = NULL;
76 /* do the domain join */
77 status = libnet_Join(libnetctx, ctx->mem_ctx, &r);
78 if (!NT_STATUS_IS_OK(status)) {
79 DEBUG(0,("libnet_Join returned %s: %s\n",
81 r.generic.out.error_string));
85 libnet_context_destroy(&libnetctx);
90 int net_join_usage(struct net_context *ctx, int argc, const char **argv)
92 d_printf("net_password_usage: TODO\n");
96 int net_join_help(struct net_context *ctx, int argc, const char **argv)
98 d_printf("net_password_help: TODO\n");