2 * Unix SMB/CIFS implementation.
3 * Join Support (cmdline + netapi)
4 * Copyright (C) Guenther Deschner 2007-2008
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.
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.
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/>.
20 #include <sys/types.h>
34 int main(int argc
, const char **argv
)
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
= NETSETUP_JOIN_DOMAIN
|
43 NETSETUP_ACCT_CREATE
|
44 NETSETUP_DOMAIN_JOIN_IF_JOINED
;
45 struct libnetapi_ctx
*ctx
= NULL
;
50 struct poptOption long_options
[] = {
52 { "ou", 0, POPT_ARG_STRING
, &account_ou
, 'U', "Account ou", "ACCOUNT_OU" },
53 { "domain", 0, POPT_ARG_STRING
, &domain_name
, 'U', "Domain name (required)", "DOMAIN" },
54 { "userd", 0, POPT_ARG_STRING
, &account
, 'U', "Domain admin account", "USERNAME" },
55 { "passwordd", 0, POPT_ARG_STRING
, &password
, 'U', "Domain admin password", "PASSWORD" },
56 POPT_COMMON_LIBNETAPI_EXAMPLES
61 status
= libnetapi_init(&ctx
);
66 pc
= poptGetContext("netdomjoin", argc
, argv
, long_options
, 0);
68 poptSetOtherOptionHelp(pc
, "hostname");
69 while((opt
= poptGetNextOpt(pc
)) != -1) {
72 if (!poptPeekArg(pc
)) {
73 poptPrintHelp(pc
, stderr
, 0);
76 host_name
= poptGetArg(pc
);
79 poptPrintHelp(pc
, stderr
, 0);
85 status
= NetJoinDomain(host_name
,
92 const char *errstr
= NULL
;
93 errstr
= libnetapi_get_error_string(ctx
, status
);
94 printf("Join failed with: %s\n", errstr
);
96 printf("Successfully joined\n");