2
* Unix SMB/CIFS implementation.
4
* Copyright (C) Guenther Deschner 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>
30
int main(int argc, const char **argv)
32
NET_API_STATUS status;
33
struct libnetapi_ctx *ctx = NULL;
35
const char *hostname = NULL;
36
const char *domain = NULL;
38
struct DOMAIN_CONTROLLER_INFO *info = NULL;
43
struct poptOption long_options[] = {
45
POPT_COMMON_LIBNETAPI_EXAMPLES
46
{ "flags", 0, POPT_ARG_INT, NULL, 'f', "Query flags", "FLAGS" },
50
status = libnetapi_init(&ctx);
55
pc = poptGetContext("dsgetdc", argc, argv, long_options, 0);
57
poptSetOtherOptionHelp(pc, "hostname domainname");
58
while((opt = poptGetNextOpt(pc)) != -1) {
61
sscanf(poptGetOptArg(pc), "%x", &flags);
65
if (!poptPeekArg(pc)) {
66
poptPrintHelp(pc, stderr, 0);
69
hostname = poptGetArg(pc);
71
if (!poptPeekArg(pc)) {
72
poptPrintHelp(pc, stderr, 0);
75
domain = poptGetArg(pc);
79
status = DsGetDcName(hostname, domain, NULL, NULL, flags, &info);
81
printf("DsGetDcName failed with: %s\n",
82
libnetapi_errstr(status));
86
printf("DC Name:\t\t%s\n", info->domain_controller_name);
87
printf("DC Address:\t\t%s\n", info->domain_controller_address);
88
printf("DC Address Type:\t%d\n", info->domain_controller_address_type);
89
printf("Domain Name:\t\t%s\n", info->domain_name);
90
printf("DNS Forest Name:\t%s\n", info->dns_forest_name);
91
printf("DC flags:\t\t0x%08x\n", info->flags);
92
printf("DC Sitename:\t\t%s\n", info->dc_site_name);
93
printf("Client Sitename:\t%s\n", info->client_site_name);
96
NetApiBufferFree(info);