r5380: Removed extra newline.
[bbaumbach/samba-autobuild/.git] / source4 / utils / net / net_join.c
1 /* 
2    Samba Unix/Linux SMB client library 
3    Distributed SMB/CIFS Server Management Utility 
4
5    Copyright (C) 2004 Stefan Metzmacher <metze@samba.org>
6    Copyright (C) 2005 Andrew Bartlett <abartlet@samba.org>
7
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "utils/net/net.h"
25 #include "libnet/libnet.h"
26 #include "librpc/gen_ndr/ndr_samr.h"
27
28 int net_join(struct net_context *ctx, int argc, const char **argv) 
29 {
30         NTSTATUS status;
31         struct libnet_context *libnetctx;
32         union libnet_Join r;
33         char *tmp;
34         const char *domain_name;
35         enum netr_SchannelType secure_channel_type = SEC_CHAN_WKSTA;
36
37         switch (argc) {
38                 case 0: /* no args -> fail */
39                         DEBUG(0,("net_join_domain: no args\n"));
40                         return -1;
41                 case 1: /* only DOMAIN */
42                         tmp = talloc_strdup(ctx->mem_ctx, argv[0]);
43                         break;
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;
50                         } else {
51                                 DEBUG(0, ("net_join: 2nd argument must be MEMBER or BDC\n"));
52                                 return -1;
53                         }
54                         break;
55                 default: /* too many args -> fail */
56                         DEBUG(0,("net_join: too many args [%d]\n",argc));
57                         return -1;
58         }
59
60         domain_name = tmp;
61
62         libnetctx = libnet_context_init();
63         if (!libnetctx) {
64                 return -1;      
65         }
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;
69
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;
75
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",
80                          nt_errstr(status),
81                          r.generic.out.error_string));
82                 return -1;
83         }
84
85         libnet_context_destroy(&libnetctx);
86
87         return 0;
88 }
89
90 int net_join_usage(struct net_context *ctx, int argc, const char **argv)
91 {
92         d_printf("net_password_usage: TODO\n");
93         return 0;       
94 }
95
96 int net_join_help(struct net_context *ctx, int argc, const char **argv)
97 {
98         d_printf("net_password_help: TODO\n");
99         return 0;       
100 }