1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
14 */
15
16
17 #include <sys/note.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <addisc.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23
24 int debug;
25 char *domainname = NULL;
26
27 void print_ds(ad_disc_ds_t *);
28 void mylogger(int pri, const char *format, ...);
29
30 int
31 main(int argc, char *argv[])
32 {
33 ad_disc_t ad_ctx = NULL;
34 boolean_t autodisc;
35 ad_disc_ds_t *dc, *gc;
36 char *s;
37 int c;
38
39 while ((c = getopt(argc, argv, "d")) != -1) {
40 switch (c) {
41 case '?':
42 (void) fprintf(stderr, "bad option: -%c\n", optopt);
43 return (1);
44 case 'd':
45 debug++;
46 break;
47 }
48 }
49
50 if (optind < argc)
51 domainname = argv[optind];
52
53 adutils_set_logger(mylogger);
54 adutils_set_debug(AD_DEBUG_ALL, debug);
55
56 ad_ctx = ad_disc_init();
57 ad_disc_set_StatusFP(ad_ctx, stdout);
58
59 if (domainname)
60 (void) ad_disc_set_DomainName(ad_ctx, domainname);
61
62 ad_disc_refresh(ad_ctx);
63
64 dc = ad_disc_get_DomainController(ad_ctx,
65 AD_DISC_PREFER_SITE, &autodisc);
66 if (dc == NULL) {
67 (void) printf("getdc failed\n");
68 return (1);
69 }
70 (void) printf("Found a DC:\n");
71 print_ds(dc);
72 free(dc);
73
74 s = ad_disc_get_ForestName(ad_ctx, NULL);
75 (void) printf("Forest: %s\n", s);
76 free(s);
77
78 s = ad_disc_get_SiteName(ad_ctx, NULL);
79 (void) printf("Site: %s\n", s);
80 free(s);
|
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2019 Nexenta Systems, Inc. All rights reserved.
14 */
15
16
17 #include <sys/note.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <addisc.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23
24 int debug;
25 char *domainname = NULL;
26 char *sitename = NULL;
27
28 void print_ds(ad_disc_ds_t *);
29 void mylogger(int pri, const char *format, ...);
30
31 int
32 main(int argc, char *argv[])
33 {
34 ad_disc_t ad_ctx = NULL;
35 boolean_t autodisc;
36 ad_disc_ds_t *dc, *gc;
37 char *s;
38 int c;
39
40 while ((c = getopt(argc, argv, "d")) != -1) {
41 switch (c) {
42 case '?':
43 (void) fprintf(stderr, "bad option: -%c\n", optopt);
44 return (1);
45 case 'd':
46 debug++;
47 break;
48 }
49 }
50
51 if (optind < argc)
52 domainname = argv[optind++];
53 if (optind < argc)
54 sitename = argv[optind++];
55
56 adutils_set_logger(mylogger);
57 adutils_set_debug(AD_DEBUG_ALL, debug);
58
59 ad_ctx = ad_disc_init();
60 ad_disc_set_StatusFP(ad_ctx, stdout);
61
62 if (domainname)
63 (void) ad_disc_set_DomainName(ad_ctx, domainname);
64 if (sitename)
65 (void) ad_disc_set_SiteName(ad_ctx, sitename);
66
67 ad_disc_refresh(ad_ctx);
68
69 dc = ad_disc_get_DomainController(ad_ctx,
70 AD_DISC_PREFER_SITE, &autodisc);
71 if (dc == NULL) {
72 (void) printf("getdc failed\n");
73 return (1);
74 }
75 (void) printf("Found a DC:\n");
76 print_ds(dc);
77 free(dc);
78
79 s = ad_disc_get_ForestName(ad_ctx, NULL);
80 (void) printf("Forest: %s\n", s);
81 free(s);
82
83 s = ad_disc_get_SiteName(ad_ctx, NULL);
84 (void) printf("Site: %s\n", s);
85 free(s);
|