source: branches/samba-3.2.x/source/lib/netapi/examples/netdomjoin/netdomjoin.c@ 536

Last change on this file since 536 was 133, checked in by Paul Smedley, 18 years ago

Update trunk to 3.2.0pre3

File size: 2.5 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * Join Support (cmdline + netapi)
4 * Copyright (C) Guenther Deschner 2007-2008
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <sys/types.h>
21#include <inttypes.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include <netapi.h>
27
28#include "common.h"
29
30enum {
31 OPT_OU = 1000
32};
33
34int main(int argc, const char **argv)
35{
36 NET_API_STATUS status;
37 const char *host_name = NULL;
38 const char *domain_name = NULL;
39 const char *account_ou = NULL;
40 const char *account = NULL;
41 const char *password = NULL;
42 uint32_t join_flags = 0x00000023;
43 struct libnetapi_ctx *ctx = NULL;
44
45 poptContext pc;
46 int opt;
47
48 struct poptOption long_options[] = {
49 POPT_AUTOHELP
50 { "ou", 0, POPT_ARG_STRING, &account_ou, 'U', "Account ou", "ACCOUNT_OU" },
51 { "domain", 0, POPT_ARG_STRING, &domain_name, 'U', "Domain name (required)", "DOMAIN" },
52 { "userd", 0, POPT_ARG_STRING, &account, 'U', "Domain admin account", "USERNAME" },
53 { "passwordd", 0, POPT_ARG_STRING, &password, 'U', "Domain admin password", "PASSWORD" },
54 POPT_COMMON_LIBNETAPI_EXAMPLES
55 POPT_TABLEEND
56 };
57
58
59 status = libnetapi_init(&ctx);
60 if (status != 0) {
61 return status;
62 }
63
64 pc = poptGetContext("netdomjoin", argc, argv, long_options, 0);
65
66 poptSetOtherOptionHelp(pc, "hostname");
67 while((opt = poptGetNextOpt(pc)) != -1) {
68 }
69
70 if (!poptPeekArg(pc)) {
71 poptPrintHelp(pc, stderr, 0);
72 goto out;
73 }
74 host_name = poptGetArg(pc);
75
76 if (!domain_name) {
77 poptPrintHelp(pc, stderr, 0);
78 goto out;
79 }
80
81 /* NetJoinDomain */
82
83 status = NetJoinDomain(host_name,
84 domain_name,
85 account_ou,
86 account,
87 password,
88 join_flags);
89 if (status != 0) {
90 const char *errstr = NULL;
91 errstr = libnetapi_get_error_string(ctx, status);
92 printf("Join failed with: %s\n", errstr);
93 } else {
94 printf("Successfully joined\n");
95 }
96
97 out:
98 libnetapi_free(ctx);
99 poptFreeContext(pc);
100
101 return status;
102}
Note: See TracBrowser for help on using the repository browser.