samba-3.5.8 for ARM
[tomato.git] / release / src-rt-6.x.4708 / router / samba-3.5.8 / source3 / lib / netapi / examples / join / getjoininformation.c
blob3db0f4aeb2dbd75c1c7972687d77d0728f075b32
1 /*
2 * Unix SMB/CIFS implementation.
3 * Join Support (cmdline + netapi)
4 * Copyright (C) Guenther Deschner 2009
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 <string.h>
21 #include <stdio.h>
22 #include <sys/types.h>
23 #include <inttypes.h>
25 #include <netapi.h>
27 #include "common.h"
29 int main(int argc, const char **argv)
31 NET_API_STATUS status;
32 const char *host_name = NULL;
33 const char *name_buffer = NULL;
34 uint16_t name_type = 0;
35 struct libnetapi_ctx *ctx = NULL;
37 poptContext pc;
38 int opt;
40 struct poptOption long_options[] = {
41 POPT_AUTOHELP
42 POPT_COMMON_LIBNETAPI_EXAMPLES
43 POPT_TABLEEND
46 status = libnetapi_init(&ctx);
47 if (status != 0) {
48 return status;
51 pc = poptGetContext("getjoininformation", argc, argv, long_options, 0);
53 poptSetOtherOptionHelp(pc, "hostname");
54 while((opt = poptGetNextOpt(pc)) != -1) {
57 if (!poptPeekArg(pc)) {
58 poptPrintHelp(pc, stderr, 0);
59 goto out;
61 host_name = poptGetArg(pc);
63 /* NetGetJoinInformation */
65 status = NetGetJoinInformation(host_name,
66 &name_buffer,
67 &name_type);
68 if (status != 0) {
69 printf("failed with: %s\n",
70 libnetapi_get_error_string(ctx, status));
71 } else {
72 printf("Successfully queried join information:\n");
74 switch (name_type) {
75 case NetSetupUnknownStatus:
76 printf("%s's join status unknown (name: %s)\n",
77 host_name, name_buffer);
78 break;
79 case NetSetupUnjoined:
80 printf("%s is not joined (name: %s)\n",
81 host_name, name_buffer);
82 break;
83 case NetSetupWorkgroupName:
84 printf("%s is joined to workgroup %s\n",
85 host_name, name_buffer);
86 break;
87 case NetSetupDomainName:
88 printf("%s is joined to domain %s\n",
89 host_name, name_buffer);
90 break;
91 default:
92 printf("%s is in unknown status %d (name: %s)\n",
93 host_name, name_type, name_buffer);
94 break;
98 out:
99 NetApiBufferFree((void *)name_buffer);
100 libnetapi_free(ctx);
101 poptFreeContext(pc);
103 return status;