xref: /titanic_44/usr/src/lib/libadutils/common/adutils_impl.h (revision 148c5f43199ca0b43fc8e3b643aab11cd66ea327)
12b4a7802SBaban Kenkre /*
22b4a7802SBaban Kenkre  * CDDL HEADER START
32b4a7802SBaban Kenkre  *
42b4a7802SBaban Kenkre  * The contents of this file are subject to the terms of the
52b4a7802SBaban Kenkre  * Common Development and Distribution License (the "License").
62b4a7802SBaban Kenkre  * You may not use this file except in compliance with the License.
72b4a7802SBaban Kenkre  *
82b4a7802SBaban Kenkre  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92b4a7802SBaban Kenkre  * or http://www.opensolaris.org/os/licensing.
102b4a7802SBaban Kenkre  * See the License for the specific language governing permissions
112b4a7802SBaban Kenkre  * and limitations under the License.
122b4a7802SBaban Kenkre  *
132b4a7802SBaban Kenkre  * When distributing Covered Code, include this CDDL HEADER in each
142b4a7802SBaban Kenkre  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152b4a7802SBaban Kenkre  * If applicable, add the following below this CDDL HEADER, with the
162b4a7802SBaban Kenkre  * fields enclosed by brackets "[]" replaced with your own identifying
172b4a7802SBaban Kenkre  * information: Portions Copyright [yyyy] [name of copyright owner]
182b4a7802SBaban Kenkre  *
192b4a7802SBaban Kenkre  * CDDL HEADER END
202b4a7802SBaban Kenkre  */
212b4a7802SBaban Kenkre /*
22*148c5f43SAlan Wright  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
232b4a7802SBaban Kenkre  */
242b4a7802SBaban Kenkre 
252b4a7802SBaban Kenkre #ifndef	_ADUTILS_IMPL_H
262b4a7802SBaban Kenkre #define	_ADUTILS_IMPL_H
272b4a7802SBaban Kenkre 
282b4a7802SBaban Kenkre #include <stdlib.h>
292b4a7802SBaban Kenkre #include <stdio.h>
302b4a7802SBaban Kenkre #include <sys/types.h>
312b4a7802SBaban Kenkre #include <ldap.h>
322b4a7802SBaban Kenkre #include <pthread.h>
332b4a7802SBaban Kenkre #include "addisc.h"
349b214d32SJordan Brown #include <rpcsvc/idmap_prot.h>
352b4a7802SBaban Kenkre #include "libadutils.h"
362b4a7802SBaban Kenkre 
372b4a7802SBaban Kenkre #ifdef	__cplusplus
382b4a7802SBaban Kenkre extern "C" {
392b4a7802SBaban Kenkre #endif
402b4a7802SBaban Kenkre 
41*148c5f43SAlan Wright #define	DBG(type, lev)	\
42*148c5f43SAlan Wright 	(ad_debug[AD_DEBUG_##type] >= (lev) || \
43*148c5f43SAlan Wright 	    ad_debug[AD_DEBUG_ALL] >= (lev))
44*148c5f43SAlan Wright extern int ad_debug[AD_DEBUG_MAX + 1];
45*148c5f43SAlan Wright 
462b4a7802SBaban Kenkre #define	ADUTILS_SEARCH_TIMEOUT	3
472b4a7802SBaban Kenkre #define	ADUTILS_LDAP_OPEN_TIMEOUT	1
482b4a7802SBaban Kenkre 
494d61c878SJulian Pullen 
502b4a7802SBaban Kenkre typedef struct adutils_sid {
512b4a7802SBaban Kenkre 	uchar_t		version;
522b4a7802SBaban Kenkre 	uchar_t		sub_authority_count;
532b4a7802SBaban Kenkre 	uint64_t	authority;  /* really, 48-bits */
542b4a7802SBaban Kenkre 	uint32_t	sub_authorities[ADUTILS_SID_MAX_SUB_AUTHORITIES];
552b4a7802SBaban Kenkre } adutils_sid_t;
562b4a7802SBaban Kenkre 
572b4a7802SBaban Kenkre struct adutils_host;
582b4a7802SBaban Kenkre 
594d61c878SJulian Pullen struct known_domain {
604d61c878SJulian Pullen 	char		name[MAXDOMAINNAME];
617a8a68f5SJulian Pullen 	char		sid[MAXSTRSID];
624d61c878SJulian Pullen };
634d61c878SJulian Pullen 
642b4a7802SBaban Kenkre 
652b4a7802SBaban Kenkre /* A set of DSs for a given AD partition */
662b4a7802SBaban Kenkre struct adutils_ad {
674d61c878SJulian Pullen 	int			num_known_domains;
684d61c878SJulian Pullen 	struct known_domain	*known_domains;
692b4a7802SBaban Kenkre 	pthread_mutex_t		lock;
702b4a7802SBaban Kenkre 	uint32_t		ref;
712b4a7802SBaban Kenkre 	struct adutils_host	*last_adh;
722b4a7802SBaban Kenkre 	adutils_ad_partition_t	partition;	/* Data or global catalog? */
73e3f2c991SKeyur Desai 	/* If this is a reference to DC, this is the base DN for that DC */
74e3f2c991SKeyur Desai 	char			*basedn;
752b4a7802SBaban Kenkre };
762b4a7802SBaban Kenkre 
772b4a7802SBaban Kenkre typedef struct adutils_attr {
782b4a7802SBaban Kenkre 	char	*attr_name;
792b4a7802SBaban Kenkre 	uint_t	num_values;
802b4a7802SBaban Kenkre 	char	**attr_values;
812b4a7802SBaban Kenkre } adutils_attr_t;
822b4a7802SBaban Kenkre 
832b4a7802SBaban Kenkre /* typedef in libadutils.h */
842b4a7802SBaban Kenkre struct adutils_entry {
852b4a7802SBaban Kenkre 	uint_t			num_nvpairs;
862b4a7802SBaban Kenkre 	adutils_attr_t		*attr_nvpairs;
872b4a7802SBaban Kenkre 	struct adutils_entry	*next;
882b4a7802SBaban Kenkre };
892b4a7802SBaban Kenkre 
902b4a7802SBaban Kenkre /* typedef in libadutils.h */
912b4a7802SBaban Kenkre struct adutils_result {
922b4a7802SBaban Kenkre 	uint_t		num_entries;
932b4a7802SBaban Kenkre 	adutils_entry_t	*entries;
942b4a7802SBaban Kenkre };
952b4a7802SBaban Kenkre 
962b4a7802SBaban Kenkre /* A single DS */
972b4a7802SBaban Kenkre typedef struct adutils_host {
982b4a7802SBaban Kenkre 	struct adutils_host	*next;
992b4a7802SBaban Kenkre 	struct adutils_ad	*owner;		/* ad_t to which this belongs */
1002b4a7802SBaban Kenkre 	pthread_mutex_t		lock;
1012b4a7802SBaban Kenkre 	LDAP			*ld;		/* LDAP connection */
1022b4a7802SBaban Kenkre 	uint32_t		ref;		/* ref count */
1032b4a7802SBaban Kenkre 	time_t			idletime;	/* time since last activity */
1042b4a7802SBaban Kenkre 	int			dead;		/* error on LDAP connection */
1052b4a7802SBaban Kenkre 	/*
1062b4a7802SBaban Kenkre 	 * Used to distinguish between different instances of LDAP
1072b4a7802SBaban Kenkre 	 * connections to this same DS.  We need this so we never mix up
1082b4a7802SBaban Kenkre 	 * results for a given msgID from one connection with those of
1092b4a7802SBaban Kenkre 	 * another earlier connection where two batch state structures
1102b4a7802SBaban Kenkre 	 * share this adutils_host object but used different LDAP connections
1112b4a7802SBaban Kenkre 	 * to send their LDAP searches.
1122b4a7802SBaban Kenkre 	 */
1132b4a7802SBaban Kenkre 	uint64_t		generation;
1142b4a7802SBaban Kenkre 
1152b4a7802SBaban Kenkre 	/* LDAP DS info */
1162b4a7802SBaban Kenkre 	char			*host;
1172b4a7802SBaban Kenkre 	int			port;
1182b4a7802SBaban Kenkre 
1192b4a7802SBaban Kenkre 	/* hardwired to SASL GSSAPI only for now */
1202b4a7802SBaban Kenkre 	char			*saslmech;
1212b4a7802SBaban Kenkre 	unsigned		saslflags;
1222b4a7802SBaban Kenkre 
1232b4a7802SBaban Kenkre 	/* Number of outstanding search requests */
1242b4a7802SBaban Kenkre 	uint32_t		max_requests;
1252b4a7802SBaban Kenkre 	uint32_t		num_requests;
1262b4a7802SBaban Kenkre } adutils_host_t;
1272b4a7802SBaban Kenkre 
1282b4a7802SBaban Kenkre /*  A place to put the results of a batched (async) query */
1292b4a7802SBaban Kenkre typedef struct adutils_q {
1302b4a7802SBaban Kenkre 	const char		*edomain;	/* expected domain name */
1312b4a7802SBaban Kenkre 	struct adutils_result	**result;	/* The LDAP search result */
1322b4a7802SBaban Kenkre 	adutils_rc		*rc;
1332b4a7802SBaban Kenkre 	int			msgid;		/* LDAP message ID */
1342b4a7802SBaban Kenkre } adutils_q_t;
1352b4a7802SBaban Kenkre 
1362b4a7802SBaban Kenkre /* Batch context structure */
1372b4a7802SBaban Kenkre struct adutils_query_state {
1382b4a7802SBaban Kenkre 	struct adutils_query_state	*next;
1394d61c878SJulian Pullen 	int			qsize;		/* Size of queries */
1402b4a7802SBaban Kenkre 	int			ref_cnt;	/* reference count */
1412b4a7802SBaban Kenkre 	pthread_cond_t		cv;		/* Condition wait variable */
1424d61c878SJulian Pullen 	uint32_t		qcount;		/* Number of items queued */
1432b4a7802SBaban Kenkre 	uint32_t		qinflight;	/* how many queries in flight */
1442b4a7802SBaban Kenkre 	uint16_t		qdead;		/* oops, lost LDAP connection */
1452b4a7802SBaban Kenkre 	adutils_host_t		*qadh;		/* LDAP connection */
1462b4a7802SBaban Kenkre 	uint64_t		qadh_gen;	/* same as qadh->generation */
1472b4a7802SBaban Kenkre 	adutils_ldap_res_search_cb ldap_res_search_cb;
1482b4a7802SBaban Kenkre 	void			*ldap_res_search_argp;
1492b4a7802SBaban Kenkre 	adutils_q_t		queries[1];	/* array of query results */
1502b4a7802SBaban Kenkre };
1512b4a7802SBaban Kenkre 
1527a8a68f5SJulian Pullen /* Private routines */
1537a8a68f5SJulian Pullen 
1547a8a68f5SJulian Pullen char *DN_to_DNS(const char *dn_name);
1557a8a68f5SJulian Pullen 
1567a8a68f5SJulian Pullen int adutils_getsid(BerValue *bval, adutils_sid_t *sidp);
1577a8a68f5SJulian Pullen 
1587a8a68f5SJulian Pullen char *adutils_sid2txt(adutils_sid_t *sidp);
1597a8a68f5SJulian Pullen 
1607a8a68f5SJulian Pullen int saslcallback(LDAP *ld, unsigned flags, void *defaults, void *prompts);
1617a8a68f5SJulian Pullen 
162bd428526SJulian Pullen int adutils_set_thread_functions(LDAP *ld);
163bd428526SJulian Pullen 
1647a8a68f5SJulian Pullen /* Global logger function */
1657a8a68f5SJulian Pullen 
1667a8a68f5SJulian Pullen extern adutils_logger logger;
1677a8a68f5SJulian Pullen 
1682b4a7802SBaban Kenkre #ifdef	__cplusplus
1692b4a7802SBaban Kenkre }
1702b4a7802SBaban Kenkre #endif
1712b4a7802SBaban Kenkre 
1722b4a7802SBaban Kenkre #endif	/* _ADUTILS_IMPL_H */
173