17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*cb5caa98Sdjl  * Common Development and Distribution License (the "License").
6*cb5caa98Sdjl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*cb5caa98Sdjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_NS_CACHE_DOOR_H
277c478bd9Sstevel@tonic-gate #define	_NS_CACHE_DOOR_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Definitions for client side of doors-based ldap caching
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <netdb.h>
407c478bd9Sstevel@tonic-gate #include <netinet/in.h>
417c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
427c478bd9Sstevel@tonic-gate #include <sys/socket.h>
437c478bd9Sstevel@tonic-gate #include <grp.h>
447c478bd9Sstevel@tonic-gate #include <pwd.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  *	statistics & control structure
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef struct ldap_stat {
527c478bd9Sstevel@tonic-gate 	int	ldap_numbercalls;	/* number of times called */
537c478bd9Sstevel@tonic-gate 	int	ldap_ttl;		/* time to live for positive entries */
547c478bd9Sstevel@tonic-gate } ldap_stat_t;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * Structure used to transfer arrays of strings.
597c478bd9Sstevel@tonic-gate  * Buffer format:
607c478bd9Sstevel@tonic-gate  *   count
617c478bd9Sstevel@tonic-gate  *   array of offsets from start of buffer
627c478bd9Sstevel@tonic-gate  *   array of characters of strings
637c478bd9Sstevel@tonic-gate  *        charp = buf + ldap_offsets[n];
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate typedef struct ldap_strlist {
677c478bd9Sstevel@tonic-gate 	int	ldap_count;		/* number of strings */
687c478bd9Sstevel@tonic-gate 	int	ldap_offsets[1];	/* array of offsets */
697c478bd9Sstevel@tonic-gate } ldap_strlist_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * structure returned by server for all calls
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define	BUFFERSIZE	8192
767c478bd9Sstevel@tonic-gate #define	OFFSET		36
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate typedef struct {
797c478bd9Sstevel@tonic-gate 	int 		ldap_bufferbytesused;
807c478bd9Sstevel@tonic-gate 	int 		ldap_return_code;
817c478bd9Sstevel@tonic-gate 	int 		ldap_errno;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	union {
847c478bd9Sstevel@tonic-gate 		char		config[BUFFERSIZE - OFFSET]; /* V1 Config */
857c478bd9Sstevel@tonic-gate 		ldap_stat_t 	stats;
867c478bd9Sstevel@tonic-gate 		char 		buff[4];
877c478bd9Sstevel@tonic-gate 		char 		ber[4];		/* BER/DER encoded packet */
887c478bd9Sstevel@tonic-gate 		ldap_strlist_t	strlist;
897c478bd9Sstevel@tonic-gate 	} ldap_u;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate } ldap_return_t;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * calls look like this
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate typedef struct {
987c478bd9Sstevel@tonic-gate 	int ldap_callnumber;
997c478bd9Sstevel@tonic-gate 	union {
1007c478bd9Sstevel@tonic-gate 		uid_t uid;
1017c478bd9Sstevel@tonic-gate 		gid_t gid;
1027c478bd9Sstevel@tonic-gate 		char domainname[sizeof (int)]; 	/* size is indeterminate */
1037c478bd9Sstevel@tonic-gate 		struct {
1047c478bd9Sstevel@tonic-gate 			int  a_type;
1057c478bd9Sstevel@tonic-gate 			int  a_length;
1067c478bd9Sstevel@tonic-gate 			char a_data[sizeof (int)];
1077c478bd9Sstevel@tonic-gate 		} addr;
1087c478bd9Sstevel@tonic-gate 		char servername[sizeof (int)]; 	/* Format: server:port */
1097c478bd9Sstevel@tonic-gate 		ldap_strlist_t	strlist;
1107c478bd9Sstevel@tonic-gate 	} ldap_u;
1117c478bd9Sstevel@tonic-gate } ldap_call_t;
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * how the client views the call process
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate typedef union {
1177c478bd9Sstevel@tonic-gate 	ldap_call_t 		ldap_call;
1187c478bd9Sstevel@tonic-gate 	ldap_return_t 		ldap_ret;
1197c478bd9Sstevel@tonic-gate 	char 			ldap_buff[sizeof (int)];
1207c478bd9Sstevel@tonic-gate } ldap_data_t;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /* Version 1 Cache Manager calls */
1237c478bd9Sstevel@tonic-gate 	/* Cache manager ping */
1247c478bd9Sstevel@tonic-gate #define	NULLCALL	0
1257c478bd9Sstevel@tonic-gate 	/* NativeLDAP I Get Config */
1267c478bd9Sstevel@tonic-gate #define	GETLDAPCONFIG	1
1277c478bd9Sstevel@tonic-gate #define	GETLDAPCONFIGV1	1
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * administrative calls
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #define	KILLSERVER	7
1347c478bd9Sstevel@tonic-gate #define	GETADMIN	8
1357c478bd9Sstevel@tonic-gate #define	SETADMIN	9
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * debug levels
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate #define	DBG_OFF		0
1427c478bd9Sstevel@tonic-gate #define	DBG_CANT_FIND	1
1437c478bd9Sstevel@tonic-gate #define	DBG_NETLOOKUPS	2
1447c478bd9Sstevel@tonic-gate #define	DBG_SERVER_LIST_REFRESH	3	/* debug server list refresh */
1457c478bd9Sstevel@tonic-gate #define	DBG_PROFILE_REFRESH	4	/* debug profile TTL/refresh */
1467c478bd9Sstevel@tonic-gate #define	DBG_ALL		6
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* Version 2 Cache Manager calls */
1497c478bd9Sstevel@tonic-gate 	/* NativeLDAP II Get Server and RootDSE Info */
1507c478bd9Sstevel@tonic-gate #define	GETLDAPSERVER	21
1517c478bd9Sstevel@tonic-gate 	/* NativeLDAP II Get cached data */
1527c478bd9Sstevel@tonic-gate #define	GETCACHE	22
1537c478bd9Sstevel@tonic-gate 	/* NativeLDAP II Set cached data */
1547c478bd9Sstevel@tonic-gate #define	SETCACHE	23
1557c478bd9Sstevel@tonic-gate 	/* NativeLDAP II get cache data statistics */
1567c478bd9Sstevel@tonic-gate #define	GETCACHESTAT	24
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * GETLDAPSERVER request flags
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #define	NS_CACHE_NEW	"0"
1637c478bd9Sstevel@tonic-gate #define	NS_CACHE_NORESP	"1"
1647c478bd9Sstevel@tonic-gate #define	NS_CACHE_NEXT	"2"
1657c478bd9Sstevel@tonic-gate #define	NS_CACHE_WRITE	"3"
166*cb5caa98Sdjl #define	NS_CACHE_ADDR_HOSTNAME	"H"
167*cb5caa98Sdjl #define	NS_CACHE_ADDR_IP	"I"
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * GETCACHE/SETCACHE data flags
1717c478bd9Sstevel@tonic-gate  */
1727c478bd9Sstevel@tonic-gate #define	NS_CACHE_DN2DOMAIN	"DM"
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate  * Max size name we allow to be passed to avoid
1767c478bd9Sstevel@tonic-gate  * buffer overflow problems
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate #define	LDAPMAXNAMELEN	255
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate  * defines for client-server interaction
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	LDAP_CACHE_DOOR_VERSION 1
1857c478bd9Sstevel@tonic-gate #define	LDAP_CACHE_DOOR "/var/run/ldap_cache_door"
1867c478bd9Sstevel@tonic-gate #define	LDAP_CACHE_DOOR_COOKIE ((void*)(0xdeadbeef^LDAP_CACHE_DOOR_VERSION))
1877c478bd9Sstevel@tonic-gate #define	UPDATE_DOOR_COOKIE ((void*)(0xdeadcafe)
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #define	SUCCESS		0
1907c478bd9Sstevel@tonic-gate #define	NOTFOUND  	-1
1917c478bd9Sstevel@tonic-gate #define	CREDERROR 	-2
1927c478bd9Sstevel@tonic-gate #define	SERVERERROR 	-3
1937c478bd9Sstevel@tonic-gate #define	NOSERVER 	-4
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate int
1967c478bd9Sstevel@tonic-gate __ns_ldap_trydoorcall(ldap_data_t **dptr, int *ndata, int *adata);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate #endif
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #endif	/* _NS_CACHE_DOOR_H */
204