xref: /illumos-gate/usr/src/lib/libadutils/common/adutils_impl.h (revision b31b5de1357c915fe7dab4d9646d9d84f9fe69bc)
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 "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 	char			*dflt_w2k_dom;	/* used to qualify bare names */
64 	int			num_known_domains;
65 	struct known_domain	*known_domains;
66 	pthread_mutex_t		lock;
67 	uint32_t		ref;
68 	struct adutils_host	*last_adh;
69 	adutils_ad_partition_t	partition;	/* Data or global catalog? */
70 };
71 
72 typedef struct adutils_attr {
73 	char	*attr_name;
74 	uint_t	num_values;
75 	char	**attr_values;
76 } adutils_attr_t;
77 
78 /* typedef in libadutils.h */
79 struct adutils_entry {
80 	uint_t			num_nvpairs;
81 	adutils_attr_t		*attr_nvpairs;
82 	struct adutils_entry	*next;
83 };
84 
85 /* typedef in libadutils.h */
86 struct adutils_result {
87 	uint_t		num_entries;
88 	adutils_entry_t	*entries;
89 };
90 
91 /* A single DS */
92 typedef struct adutils_host {
93 	struct adutils_host	*next;
94 	struct adutils_ad	*owner;		/* ad_t to which this belongs */
95 	pthread_mutex_t		lock;
96 	LDAP			*ld;		/* LDAP connection */
97 	uint32_t		ref;		/* ref count */
98 	time_t			idletime;	/* time since last activity */
99 	int			dead;		/* error on LDAP connection */
100 	/*
101 	 * Used to distinguish between different instances of LDAP
102 	 * connections to this same DS.  We need this so we never mix up
103 	 * results for a given msgID from one connection with those of
104 	 * another earlier connection where two batch state structures
105 	 * share this adutils_host object but used different LDAP connections
106 	 * to send their LDAP searches.
107 	 */
108 	uint64_t		generation;
109 
110 	/* LDAP DS info */
111 	char			*host;
112 	int			port;
113 
114 	/* hardwired to SASL GSSAPI only for now */
115 	char			*saslmech;
116 	unsigned		saslflags;
117 
118 	/* Number of outstanding search requests */
119 	uint32_t		max_requests;
120 	uint32_t		num_requests;
121 } adutils_host_t;
122 
123 /*  A place to put the results of a batched (async) query */
124 typedef struct adutils_q {
125 	const char		*edomain;	/* expected domain name */
126 	struct adutils_result	**result;	/* The LDAP search result */
127 	adutils_rc		*rc;
128 	int			msgid;		/* LDAP message ID */
129 } adutils_q_t;
130 
131 /* Batch context structure */
132 struct adutils_query_state {
133 	struct adutils_query_state	*next;
134 	int			qsize;		/* Size of queries */
135 	int			ref_cnt;	/* reference count */
136 	pthread_cond_t		cv;		/* Condition wait variable */
137 	uint32_t		qcount;		/* Number of items queued */
138 	uint32_t		qinflight;	/* how many queries in flight */
139 	uint16_t		qdead;		/* oops, lost LDAP connection */
140 	adutils_host_t		*qadh;		/* LDAP connection */
141 	uint64_t		qadh_gen;	/* same as qadh->generation */
142 	adutils_ldap_res_search_cb ldap_res_search_cb;
143 	void			*ldap_res_search_argp;
144 	char			*default_domain;
145 	char			*basedn;
146 	adutils_q_t		queries[1];	/* array of query results */
147 };
148 
149 /* Private routines */
150 
151 char *DN_to_DNS(const char *dn_name);
152 
153 int adutils_getsid(BerValue *bval, adutils_sid_t *sidp);
154 
155 char *adutils_sid2txt(adutils_sid_t *sidp);
156 
157 int saslcallback(LDAP *ld, unsigned flags, void *defaults, void *prompts);
158 
159 /* Global logger function */
160 
161 extern adutils_logger logger;
162 
163 #ifdef	__cplusplus
164 }
165 #endif
166 
167 #endif	/* _ADUTILS_IMPL_H */
168