# # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2014 Nexenta Systems, Inc. All rights reserved. # set -o emacs setenv ROOT ${CODEMGR_WS}/proto/root_i386 setenv LD_LIBRARY_PATH ${ROOT}/usr/lib:${ROOT}/lib loadobject -load ${ROOT}/usr/lib/libadutils.so.1 debug ./test-getdc # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright 2014 Nexenta Systems, Inc. All rights reserved. # PROG = test-getdc OBJS = getdc_main.o SRCS = $(OBJS:%.o=%.c) POFILES = $(OBJS:.o=.po) include ../../Makefile.cmd POFILE = $(PROG)_all.po LDLIBS += -ladutils -lnsl -lumem LDFLAGS += -R'$$ORIGIN/../lib' INCS += -I. -I../../../lib/libadutils/common LINTFLAGS += -xerroff=E_NAME_DEF_NOT_USED2 CFLAGS += $(CCVERBOSE) $(OBJS) : CPPFLAGS += $(INCS) -D_REENTRANT $(POFILE) : CPPFLAGS += $(INCS) lint_SRCS : CPPFLAGS += $(INCS) .KEEP_STATE: all: $(PROG) $(PROG): $(OBJS) FRC $(LINK.c) $(CCGDEBUG) -o $@ $(OBJS) $(LDLIBS) $(POST_PROCESS) $(POFILE): $(POFILES) $(RM) $@ cat $(POFILES) > $@ install: all $(ROOTPROG) clean: $(RM) $(OBJS) lint: lint_SRCS include ../../Makefile.targ FRC: /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2019 Nexenta Systems, Inc. All rights reserved. */ #include #include #include #include #include #include int debug; char *domainname = NULL; char *sitename = NULL; void print_ds(ad_disc_ds_t *); void mylogger(int pri, const char *format, ...); int main(int argc, char *argv[]) { ad_disc_t ad_ctx = NULL; boolean_t autodisc; ad_disc_ds_t *dc, *gc; char *s; int c; while ((c = getopt(argc, argv, "d")) != -1) { switch (c) { case '?': (void) fprintf(stderr, "bad option: -%c\n", optopt); return (1); case 'd': debug++; break; } } if (optind < argc) domainname = argv[optind++]; if (optind < argc) sitename = argv[optind++]; adutils_set_logger(mylogger); adutils_set_debug(AD_DEBUG_ALL, debug); ad_ctx = ad_disc_init(); ad_disc_set_StatusFP(ad_ctx, stdout); if (domainname) (void) ad_disc_set_DomainName(ad_ctx, domainname); if (sitename) (void) ad_disc_set_SiteName(ad_ctx, sitename); ad_disc_refresh(ad_ctx); dc = ad_disc_get_DomainController(ad_ctx, AD_DISC_PREFER_SITE, &autodisc); if (dc == NULL) { (void) printf("getdc failed\n"); return (1); } (void) printf("Found a DC:\n"); print_ds(dc); free(dc); s = ad_disc_get_ForestName(ad_ctx, NULL); (void) printf("Forest: %s\n", s); free(s); s = ad_disc_get_SiteName(ad_ctx, NULL); (void) printf("Site: %s\n", s); free(s); gc = ad_disc_get_GlobalCatalog(ad_ctx, AD_DISC_PREFER_SITE, &autodisc); if (gc != NULL) { (void) printf("Found a GC:\n"); print_ds(gc); free(gc); } ad_disc_done(ad_ctx); ad_disc_fini(ad_ctx); ad_ctx = NULL; return (0); } void print_ds(ad_disc_ds_t *ds) { char buf[64]; for (; ds->host[0] != '\0'; ds++) { const char *p; (void) printf("Name: %s\n", ds->host); (void) printf(" flags: 0x%X\n", ds->flags); if (ds->addr.ss_family == AF_INET) { struct sockaddr_in *sin; sin = (struct sockaddr_in *)&ds->addr; p = inet_ntop(AF_INET, &sin->sin_addr, buf, sizeof (buf)); if (p == NULL) p = "?"; (void) printf(" A %s %d\n", p, ds->port); } if (ds->addr.ss_family == AF_INET6) { struct sockaddr_in6 *sin6; sin6 = (struct sockaddr_in6 *)&ds->addr; p = inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof (buf)); if (p == NULL) p = "?"; (void) printf(" AAAA %s %d\n", p, ds->port); } } } /* printflike */ void mylogger(int pri, const char *format, ...) { _NOTE(ARGUNUSED(pri)) va_list args; va_start(args, format); (void) vfprintf(stderr, format, args); (void) fprintf(stderr, "\n"); va_end(args); } /* * This is a unit-test program. Always enable libumem debugging. */ const char * _umem_debug_init(void) { return ("default,verbose"); /* $UMEM_DEBUG setting */ } const char * _umem_logging_init(void) { return ("fail,contents"); /* $UMEM_LOGGING setting */ }