xref: /titanic_41/usr/src/lib/libadutils/common/adutils_impl.h (revision d24234c24aeaca4ca56ee3ac2794507968f274c4)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_ADUTILS_IMPL_H
27 #define	_ADUTILS_IMPL_H
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <ldap.h>
33 #include <pthread.h>
34 #include "addisc.h"
35 #include <rpcsvc/idmap_prot.h>
36 #include "libadutils.h"
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	ADUTILS_SEARCH_TIMEOUT	3
43 #define	ADUTILS_LDAP_OPEN_TIMEOUT	1
44 
45 
46 typedef struct adutils_sid {
47 	uchar_t		version;
48 	uchar_t		sub_authority_count;
49 	uint64_t	authority;  /* really, 48-bits */
50 	uint32_t	sub_authorities[ADUTILS_SID_MAX_SUB_AUTHORITIES];
51 } adutils_sid_t;
52 
53 struct adutils_host;
54 
55 struct known_domain {
56 	char		name[MAXDOMAINNAME];
57 	char		sid[MAXSTRSID];
58 };
59 
60 
61 /* A set of DSs for a given AD partition */
62 struct adutils_ad {
63 	int			num_known_domains;
64 	struct known_domain	*known_domains;
65 	pthread_mutex_t		lock;
66 	uint32_t		ref;
67 	struct adutils_host	*last_adh;
68 	adutils_ad_partition_t	partition;	/* Data or global catalog? */
69 	/* If this is a reference to DC, this is the base DN for that DC */
70 	char			*basedn;
71 };
72 
73 typedef struct adutils_attr {
74 	char	*attr_name;
75 	uint_t	num_values;
76 	char	**attr_values;
77 } adutils_attr_t;
78 
79 /* typedef in libadutils.h */
80 struct adutils_entry {
81 	uint_t			num_nvpairs;
82 	adutils_attr_t		*attr_nvpairs;
83 	struct adutils_entry	*next;
84 };
85 
86 /* typedef in libadutils.h */
87 struct adutils_result {
88 	uint_t		num_entries;
89 	adutils_entry_t	*entries;
90 };
91 
92 /* A single DS */
93 typedef struct adutils_host {
94 	struct adutils_host	*next;
95 	struct adutils_ad	*owner;		/* ad_t to which this belongs */
96 	pthread_mutex_t		lock;
97 	LDAP			*ld;		/* LDAP connection */
98 	uint32_t		ref;		/* ref count */
99 	time_t			idletime;	/* time since last activity */
100 	int			dead;		/* error on LDAP connection */
101 	/*
102 	 * Used to distinguish between different instances of LDAP
103 	 * connections to this same DS.  We need this so we never mix up
104 	 * results for a given msgID from one connection with those of
105 	 * another earlier connection where two batch state structures
106 	 * share this adutils_host object but used different LDAP connections
107 	 * to send their LDAP searches.
108 	 */
109 	uint64_t		generation;
110 
111 	/* LDAP DS info */
112 	char			*host;
113 	int			port;
114 
115 	/* hardwired to SASL GSSAPI only for now */
116 	char			*saslmech;
117 	unsigned		saslflags;
118 
119 	/* Number of outstanding search requests */
120 	uint32_t		max_requests;
121 	uint32_t		num_requests;
122 } adutils_host_t;
123 
124 /*  A place to put the results of a batched (async) query */
125 typedef struct adutils_q {
126 	const char		*edomain;	/* expected domain name */
127 	struct adutils_result	**result;	/* The LDAP search result */
128 	adutils_rc		*rc;
129 	int			msgid;		/* LDAP message ID */
130 } adutils_q_t;
131 
132 /* Batch context structure */
133 struct adutils_query_state {
134 	struct adutils_query_state	*next;
135 	int			qsize;		/* Size of queries */
136 	int			ref_cnt;	/* reference count */
137 	pthread_cond_t		cv;		/* Condition wait variable */
138 	uint32_t		qcount;		/* Number of items queued */
139 	uint32_t		qinflight;	/* how many queries in flight */
140 	uint16_t		qdead;		/* oops, lost LDAP connection */
141 	adutils_host_t		*qadh;		/* LDAP connection */
142 	uint64_t		qadh_gen;	/* same as qadh->generation */
143 	adutils_ldap_res_search_cb ldap_res_search_cb;
144 	void			*ldap_res_search_argp;
145 	adutils_q_t		queries[1];	/* array of query results */
146 };
147 
148 /* Private routines */
149 
150 char *DN_to_DNS(const char *dn_name);
151 
152 int adutils_getsid(BerValue *bval, adutils_sid_t *sidp);
153 
154 char *adutils_sid2txt(adutils_sid_t *sidp);
155 
156 int saslcallback(LDAP *ld, unsigned flags, void *defaults, void *prompts);
157 
158 int adutils_set_thread_functions(LDAP *ld);
159 
160 /* Global logger function */
161 
162 extern adutils_logger logger;
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif	/* _ADUTILS_IMPL_H */
169