1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
* 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 <sys/note.h>
#include <stdarg.h>
#include <stdio.h>
#include <addisc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
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 */
}
|