1/* 2 * Unix SMB/CIFS implementation. 3 * DsGetDcName query 4 * Copyright (C) Guenther Deschner 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 30int main(int argc, const char **argv) 31{ 32 NET_API_STATUS status; 33 struct libnetapi_ctx *ctx = NULL; 34 35 const char *hostname = NULL; 36 const char *domain = NULL; 37 uint32_t flags = 0; 38 struct DOMAIN_CONTROLLER_INFO *info = NULL; 39 40 poptContext pc; 41 int opt; 42 43 struct poptOption long_options[] = { 44 POPT_AUTOHELP 45 POPT_COMMON_LIBNETAPI_EXAMPLES 46 { "flags", 0, POPT_ARG_INT, NULL, 'f', "Query flags", "FLAGS" }, 47 POPT_TABLEEND 48 }; 49 50 status = libnetapi_init(&ctx); 51 if (status != 0) { 52 return status; 53 } 54 55 pc = poptGetContext("dsgetdc", argc, argv, long_options, 0); 56 57 poptSetOtherOptionHelp(pc, "hostname domainname"); 58 while((opt = poptGetNextOpt(pc)) != -1) { 59 switch (opt) { 60 case 'f': 61 sscanf(poptGetOptArg(pc), "%x", &flags); 62 } 63 } 64 65 if (!poptPeekArg(pc)) { 66 poptPrintHelp(pc, stderr, 0); 67 goto out; 68 } 69 hostname = poptGetArg(pc); 70 71 if (!poptPeekArg(pc)) { 72 poptPrintHelp(pc, stderr, 0); 73 goto out; 74 } 75 domain = poptGetArg(pc); 76 77 /* DsGetDcName */ 78 79 status = DsGetDcName(hostname, domain, NULL, NULL, flags, &info); 80 if (status != 0) { 81 printf("DsGetDcName failed with: %s\n", 82 libnetapi_errstr(status)); 83 return status; 84 } 85 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); 94 95 out: 96 NetApiBufferFree(info); 97 libnetapi_free(ctx); 98 poptFreeContext(pc); 99 100 return status; 101} 102