source: vendor/current/source4/utils/net/net_join.c@ 414

Last change on this file since 414 was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 3.1 KB
Line 
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 3 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, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "includes.h"
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"
28
29int net_join(struct net_context *ctx, int argc, const char **argv)
30{
31 NTSTATUS status;
32 struct libnet_context *libnetctx;
33 struct libnet_Join *r;
34 char *tmp;
35 const char *domain_name;
36 enum netr_SchannelType secure_channel_type = SEC_CHAN_WKSTA;
37
38 switch (argc) {
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]);
43 break;
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;
50 } else {
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);
53 }
54 break;
55 default: /* too many args -> fail */
56 return net_join_usage(ctx, argc, argv);
57 }
58
59 domain_name = tmp;
60
61 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
62 if (!libnetctx) {
63 return -1;
64 }
65 libnetctx->cred = ctx->credentials;
66 r = talloc(ctx, struct libnet_Join);
67 if (!r) {
68 return -1;
69 }
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;
76
77 /* do the domain join */
78 status = libnet_Join(libnetctx, r, r);
79
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));
83 talloc_free(r);
84 talloc_free(libnetctx);
85 return -1;
86 }
87 d_printf("Joined domain %s (%s)\n", r->out.domain_name, dom_sid_string(ctx, r->out.domain_sid));
88
89 talloc_free(libnetctx);
90 return 0;
91}
92
93int net_join_usage(struct net_context *ctx, int argc, const char **argv)
94{
95 d_printf("net join <domain> [BDC | MEMBER] [options]\n");
96 return 0;
97}
98
99int net_join_help(struct net_context *ctx, int argc, const char **argv)
100{
101 d_printf("Joins domain as either member or backup domain controller.\n");
102 return 0;
103}
104
Note: See TracBrowser for help on using the repository browser.