xref: /illumos-gate/usr/src/lib/libadutils/common/addisc_impl.h (revision 915894ef19890baaed00080f85f6b69e225cda98)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
24  */
25 
26 #ifndef	_ADDISC_IMPL_H
27 #define	_ADDISC_IMPL_H
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <resolv.h>
33 #include <ldap.h>
34 #include <pthread.h>
35 #include "addisc.h"
36 #include "libadutils.h"
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 enum ad_item_state {
43 		AD_STATE_INVALID = 0,	/* The value is not valid */
44 		AD_STATE_FIXED,		/* The value was fixed by caller */
45 		AD_STATE_AUTO		/* The value is auto discovered */
46 		};
47 
48 enum ad_data_type {
49 		AD_STRING = 123,
50 		AD_UUID,
51 		AD_DIRECTORY,
52 		AD_DOMAINS_IN_FOREST,
53 		AD_TRUSTED_DOMAINS
54 		};
55 
56 
57 typedef struct ad_subnet {
58 	char subnet[24];
59 } ad_subnet_t;
60 
61 
62 typedef struct ad_item {
63 	enum ad_item_state	state;
64 	enum ad_data_type	type;
65 	void 			*value;
66 	time_t 			expires;
67 	unsigned int 		version;	/* Version is only changed */
68 						/* if the value changes */
69 #define	PARAM1		0
70 #define	PARAM2		1
71 	int 		param_version[2];
72 					/* These holds the version of */
73 					/* dependents so that a dependent */
74 					/* change can be detected */
75 } ad_item_t;
76 
77 typedef struct ad_disc {
78 	struct __res_state res_state;
79 	int		res_ninitted;
80 	ad_subnet_t	*subnets;
81 	boolean_t	subnets_changed;
82 	time_t		subnets_last_check;
83 	time_t		expires_not_before;
84 	time_t		expires_not_after;
85 	ad_item_t	domain_name;		/* DNS hostname string */
86 	ad_item_t	domain_guid;		/* Domain UUID (binary) */
87 	ad_item_t	domain_controller;	/* Directory hostname and */
88 						/* port array */
89 	ad_item_t	preferred_dc;
90 	ad_item_t	site_name;		/* String */
91 	ad_item_t	forest_name;		/* DNS forestname string */
92 	ad_item_t	global_catalog;		/* Directory hostname and */
93 						/* port array */
94 	ad_item_t	domains_in_forest;	/* DNS domainname and SID */
95 						/* array */
96 	ad_item_t	trusted_domains;	/* DNS domainname and trust */
97 						/* direction array */
98 	/* Site specfic versions */
99 	ad_item_t	site_domain_controller;	/* Directory hostname and */
100 						/* port array */
101 	ad_item_t	site_global_catalog;	/* Directory hostname and */
102 						/* port array */
103 	/* Optional FILE * for DC Location status. */
104 	struct __FILE_TAG *status_fp;
105 
106 	int		debug[AD_DEBUG_MAX+1];	/* Debug levels */
107 } ad_disc;
108 
109 /* Candidate Directory Servers (CDS) */
110 typedef struct ad_disc_cds {
111 	struct ad_disc_ds cds_ds;
112 	struct addrinfo *cds_ai;
113 } ad_disc_cds_t;
114 
115 ad_disc_ds_t *ldap_ping(ad_disc_t, ad_disc_cds_t *, char *, int);
116 
117 int srv_getdom(res_state, const char *, char **);
118 ad_disc_cds_t *srv_query(res_state, const char *, const char *,
119     ad_disc_ds_t *);
120 void srv_free(ad_disc_cds_t *);
121 
122 void auto_set_DomainGUID(ad_disc_t, uchar_t *);
123 void auto_set_ForestName(ad_disc_t, char *);
124 void auto_set_SiteName(ad_disc_t, char *);
125 
126 #ifdef	__cplusplus
127 }
128 #endif
129 
130 #endif	/* _ADDISC_IMPL_H */
131