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