xref: /illumos-gate/usr/src/lib/libsldap/common/ns_cache_door.h (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_NS_CACHE_DOOR_H
27 #define	_NS_CACHE_DOOR_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Definitions for client side of doors-based ldap caching
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <netdb.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
42 #include <sys/socket.h>
43 #include <grp.h>
44 #include <pwd.h>
45 
46 
47 /*
48  *	statistics & control structure
49  */
50 
51 typedef struct ldap_stat {
52 	int	ldap_numbercalls;	/* number of times called */
53 	int	ldap_ttl;		/* time to live for positive entries */
54 } ldap_stat_t;
55 
56 
57 /*
58  * Structure used to transfer arrays of strings.
59  * Buffer format:
60  *   count
61  *   array of offsets from start of buffer
62  *   array of characters of strings
63  *        charp = buf + ldap_offsets[n];
64  */
65 
66 typedef struct ldap_strlist {
67 	int	ldap_count;		/* number of strings */
68 	int	ldap_offsets[1];	/* array of offsets */
69 } ldap_strlist_t;
70 
71 /*
72  * Structure used to request/inform config and server status changes.
73  */
74 
75 typedef struct ldap_get_chg_cookie {
76 	pid_t		mgr_pid;  /* current process id of ldap_cachemgr */
77 	uint32_t	seq_num;  /* current config sequence number */
78 } ldap_get_chg_cookie_t;
79 
80 typedef struct ldap_get_change {
81 	uint32_t		op;	/* start or stop */
82 	ldap_get_chg_cookie_t	cookie;	/* get status change cookie */
83 } ldap_get_change_t;
84 
85 typedef struct ldap_get_change_out {
86 	uint32_t	type;		 /* config change or server change */
87 	ldap_get_chg_cookie_t cookie;    /* get status change cookie */
88 	uint32_t	server_count;	 /* if server change: num of servers */
89 	uint32_t	data_size;	 /* if server change: size of data */
90 	char 		data[sizeof (int)]; /* real size is data_size */
91 } ldap_get_change_out_t;
92 
93 typedef struct ldap_config_out {
94 	ldap_get_chg_cookie_t cookie;    /* get status change cookie */
95 	uint32_t	data_size;	 /* length of the config string */
96 	char 		config_str[sizeof (int)]; /* real size is data_size */
97 } ldap_config_out_t;
98 
99 /*
100  * structure returned by server for all calls
101  */
102 
103 #define	BUFFERSIZE	8192
104 #define	OFFSET		36
105 
106 typedef struct {
107 	int 		ldap_bufferbytesused;
108 	int 		ldap_return_code;
109 	int 		ldap_errno;
110 
111 	union {
112 		char		config[BUFFERSIZE - OFFSET]; /* V1 Config */
113 		ldap_stat_t 	stats;
114 		char 		buff[4];
115 		char 		ber[4];		/* BER/DER encoded packet */
116 		ldap_strlist_t	strlist;
117 		ldap_config_out_t config_str;
118 		ldap_get_change_out_t changes;
119 	} ldap_u;
120 
121 } ldap_return_t;
122 
123 /*
124  * calls look like this
125  */
126 
127 typedef struct {
128 	int ldap_callnumber;
129 	union {
130 		uid_t uid;
131 		gid_t gid;
132 		char domainname[sizeof (int)]; 	/* size is indeterminate */
133 		struct {
134 			int  a_type;
135 			int  a_length;
136 			char a_data[sizeof (int)];
137 		} addr;
138 		char servername[sizeof (int)]; 	/* Format: server:port */
139 		ldap_strlist_t	strlist;
140 		ldap_get_change_t get_change;
141 	} ldap_u;
142 } ldap_call_t;
143 /*
144  * how the client views the call process
145  */
146 
147 typedef union {
148 	ldap_call_t 		ldap_call;
149 	ldap_return_t 		ldap_ret;
150 	char 			ldap_buff[sizeof (int)];
151 } ldap_data_t;
152 
153 /* Version 1 Cache Manager calls */
154 	/* Cache manager ping */
155 #define	NULLCALL	0
156 	/* NativeLDAP I Get Config */
157 #define	GETLDAPCONFIG	1
158 #define	GETLDAPCONFIGV1	1
159 
160 /*
161  * administrative calls
162  */
163 
164 #define	KILLSERVER	7
165 #define	GETADMIN	8
166 #define	SETADMIN	9
167 
168 /*
169  * debug levels
170  */
171 
172 #define	DBG_OFF		0
173 #define	DBG_CANT_FIND	1
174 #define	DBG_NETLOOKUPS	2
175 #define	DBG_SERVER_LIST_REFRESH	3	/* debug server list refresh */
176 #define	DBG_PROFILE_REFRESH	4	/* debug profile TTL/refresh */
177 #define	DBG_ALL		6
178 
179 /* Version 2 Cache Manager calls */
180 	/* NativeLDAP II Get Server and RootDSE Info */
181 #define	GETLDAPSERVER	21
182 	/* NativeLDAP II Get cached data */
183 #define	GETCACHE	22
184 	/* NativeLDAP II Set cached data */
185 #define	SETCACHE	23
186 	/* NativeLDAP II get cache data statistics */
187 #define	GETCACHESTAT	24
188 	/* Configuration change or server status change notification */
189 #define	GETSTATUSCHANGE	25
190 
191 /*
192  * GETLDAPSERVER request flags
193  */
194 
195 #define	NS_CACHE_NEW	"0"
196 #define	NS_CACHE_NORESP	"1"
197 #define	NS_CACHE_NEXT	"2"
198 #define	NS_CACHE_WRITE	"3"
199 #define	NS_CACHE_ADDR_HOSTNAME	"H"
200 #define	NS_CACHE_ADDR_IP	"I"
201 
202 /*
203  * GETSTATUSCHANGE operation: start or stop
204  */
205 #define	NS_STATUS_CHANGE_OP_START	1
206 #define	NS_STATUS_CHANGE_OP_STOP	2
207 
208 /*
209  * GETSTATUSCHANGE change type: config or server
210  */
211 #define	NS_STATUS_CHANGE_TYPE_CONFIG	1
212 #define	NS_STATUS_CHANGE_TYPE_SERVER	2
213 
214 /*
215  * Server status change
216  */
217 #define	NS_SERVER_CHANGE_UP	"0"	/* mapped to NS_SERVER_UP */
218 #define	NS_SERVER_CHANGE_DOWN	"1"	/* mapped to NS_SERVER_DOWN */
219 /*
220  * GETCACHE/SETCACHE data flags
221  */
222 #define	NS_CACHE_DN2DOMAIN	"DM"
223 
224 /*
225  * Max size name we allow to be passed to avoid
226  * buffer overflow problems
227  */
228 #define	LDAPMAXNAMELEN	255
229 
230 /*
231  * defines for client-server interaction
232  */
233 
234 #define	LDAP_CACHE_DOOR_VERSION 1
235 #define	LDAP_CACHE_DOOR "/var/run/ldap_cache_door"
236 #define	LDAP_CACHE_DOOR_COOKIE ((void*)(0xdeadbeef^LDAP_CACHE_DOOR_VERSION))
237 #define	UPDATE_DOOR_COOKIE ((void*)(0xdeadcafe)
238 
239 #define	NS_CACHE_SUCCESS	0
240 #define	NS_CACHE_NOTFOUND  	-1
241 #define	NS_CACHE_CREDERROR 	-2
242 #define	NS_CACHE_SERVERERROR 	-3
243 #define	NS_CACHE_NOSERVER 	-4
244 
245 int
246 __ns_ldap_trydoorcall(ldap_data_t **dptr, int *ndata, int *adata);
247 int
248 __ns_ldap_trydoorcall_getfd();
249 int
250 __ns_ldap_trydoorcall_send(ldap_data_t **dptr, int *ndata, int *adata);
251 void
252 __ns_ldap_doorfd_close();
253 
254 #ifdef	__cplusplus
255 }
256 #endif
257 
258 
259 #endif	/* _NS_CACHE_DOOR_H */
260