summaryrefslogtreecommitdiff
path: root/usr/src/lib/libsldap/common/ns_cache_door.h
blob: 8e260c4f53fb1d7a0b9051a8b47505e373a69c39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_NS_CACHE_DOOR_H
#define	_NS_CACHE_DOOR_H

/*
 * Definitions for client side of doors-based ldap caching
 */

#ifdef	__cplusplus
extern "C" {
#endif

#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <grp.h>
#include <pwd.h>


/*
 *	statistics & control structure
 */

typedef struct ldap_stat {
	int	ldap_numbercalls;	/* number of times called */
	int	ldap_ttl;		/* time to live for positive entries */
} ldap_stat_t;


/*
 * Structure used to transfer arrays of strings.
 * Buffer format:
 *   count
 *   array of offsets from start of buffer
 *   array of characters of strings
 *        charp = buf + ldap_offsets[n];
 */

typedef struct ldap_strlist {
	int	ldap_count;		/* number of strings */
	int	ldap_offsets[1];	/* array of offsets */
} ldap_strlist_t;

/*
 * Structure used to request/inform config and server status changes.
 */

typedef struct ldap_get_chg_cookie {
	pid_t		mgr_pid;  /* current process id of ldap_cachemgr */
	uint32_t	seq_num;  /* current config sequence number */
} ldap_get_chg_cookie_t;

typedef struct ldap_get_change {
	uint32_t		op;	/* start or stop */
	ldap_get_chg_cookie_t	cookie;	/* get status change cookie */
} ldap_get_change_t;

typedef struct ldap_get_change_out {
	uint32_t	type;		 /* config change or server change */
	ldap_get_chg_cookie_t cookie;    /* get status change cookie */
	uint32_t	server_count;	 /* if server change: num of servers */
	uint32_t	data_size;	 /* if server change: size of data */
	char 		data[sizeof (int)]; /* real size is data_size */
} ldap_get_change_out_t;

typedef struct ldap_config_out {
	ldap_get_chg_cookie_t cookie;    /* get status change cookie */
	uint32_t	data_size;	 /* length of the config string */
	char 		config_str[sizeof (int)]; /* real size is data_size */
} ldap_config_out_t;

typedef struct ldap_admin_mod_result {
	uint32_t	ns_err;		/* ns_ldap error code */
	uint32_t	status;		/* error status */
	uint32_t	msg_size;	/* length of error message */
	char 		msg[sizeof (int)]; /* real size is msg_size */
} ldap_admin_mod_result_t;

/*
 * structure returned by server for all calls
 */

#define	BUFFERSIZE	8192
#define	OFFSET		36

typedef struct {
	int 		ldap_bufferbytesused;
	int 		ldap_return_code;
	int 		ldap_errno;

	union {
		char		config[BUFFERSIZE - OFFSET]; /* V1 Config */
		ldap_stat_t 	stats;
		char 		buff[4];
		char 		ber[4];		/* BER/DER encoded packet */
		ldap_strlist_t	strlist;
		ldap_config_out_t config_str;
		ldap_get_change_out_t changes;
		ldap_admin_mod_result_t admin_result;
	} ldap_u;

} ldap_return_t;

/*
 * calls look like this
 */

typedef struct {
	int ldap_callnumber;
	union {
		uid_t uid;
		gid_t gid;
		char domainname[sizeof (int)]; 	/* size is indeterminate */
		struct {
			int  a_type;
			int  a_length;
			char a_data[sizeof (int)];
		} addr;
		char servername[sizeof (int)]; 	/* Format: server:port */
		ldap_strlist_t	strlist;
		ldap_get_change_t get_change;
	} ldap_u;
} ldap_call_t;
/*
 * how the client views the call process
 */

typedef union {
	ldap_call_t 		ldap_call;
	ldap_return_t 		ldap_ret;
	char 			ldap_buff[sizeof (int)];
} ldap_data_t;

/* Version 1 Cache Manager calls */
	/* Cache manager ping */
#define	NULLCALL	0
	/* NativeLDAP I Get Config */
#define	GETLDAPCONFIG	1
#define	GETLDAPCONFIGV1	1

/*
 * administrative calls
 */

#define	KILLSERVER	7
#define	GETADMIN	8
#define	SETADMIN	9

/*
 * debug levels
 */

#define	DBG_OFF		0
#define	DBG_CANT_FIND	1
#define	DBG_NETLOOKUPS	2
#define	DBG_SERVER_LIST_REFRESH	3	/* debug server list refresh */
#define	DBG_PROFILE_REFRESH	4	/* debug profile TTL/refresh */
#define	DBG_ALL		6

/* Version 2 Cache Manager calls */
	/* NativeLDAP II Get Server and RootDSE Info */
#define	GETLDAPSERVER	21
	/* NativeLDAP II Get cached data */
#define	GETCACHE	22
	/* NativeLDAP II Set cached data */
#define	SETCACHE	23
	/* NativeLDAP II get cache data statistics */
#define	GETCACHESTAT	24
	/* Configuration change or server status change notification */
#define	GETSTATUSCHANGE	25
	/* perform admin modify via ldap_cachemgr */
#define	ADMINMODIFY	26
	/* get admin credentials for shadow lookups */
#define	GETADMINCRED	27

/*
 * GETLDAPSERVER request flags
 */

#define	NS_CACHE_NEW	"0"
#define	NS_CACHE_NORESP	"1"
#define	NS_CACHE_NEXT	"2"
#define	NS_CACHE_WRITE	"3"
#define	NS_CACHE_ADDR_HOSTNAME	"H"
#define	NS_CACHE_ADDR_IP	"I"

/*
 * GETSTATUSCHANGE operation: start or stop
 */
#define	NS_STATUS_CHANGE_OP_START	1
#define	NS_STATUS_CHANGE_OP_STOP	2

/*
 * GETSTATUSCHANGE change type: config or server
 */
#define	NS_STATUS_CHANGE_TYPE_CONFIG	1
#define	NS_STATUS_CHANGE_TYPE_SERVER	2

/*
 * Server status change
 */
#define	NS_SERVER_CHANGE_UP	"0"	/* mapped to NS_SERVER_UP */
#define	NS_SERVER_CHANGE_DOWN	"1"	/* mapped to NS_SERVER_DOWN */
/*
 * GETCACHE/SETCACHE data flags
 */
#define	NS_CACHE_DN2DOMAIN	"DM"

/*
 * Max size name we allow to be passed to avoid
 * buffer overflow problems
 */
#define	LDAPMAXNAMELEN	255

/*
 * defines for client-server interaction
 */

#define	LDAP_CACHE_DOOR_VERSION 1
#define	LDAP_CACHE_DOOR "/var/run/ldap_cache_door"
#define	LDAP_CACHE_DOOR_COOKIE ((void*)(0xdeadbeef^LDAP_CACHE_DOOR_VERSION))
#define	UPDATE_DOOR_COOKIE ((void*)(0xdeadcafe)

#define	NS_CACHE_SUCCESS	0
#define	NS_CACHE_NOTFOUND  	-1
#define	NS_CACHE_CREDERROR 	-2
#define	NS_CACHE_SERVERERROR 	-3
#define	NS_CACHE_NOSERVER 	-4

int
__ns_ldap_trydoorcall(ldap_data_t **dptr, int *ndata, int *adata);
int
__ns_ldap_trydoorcall_getfd();
int
__ns_ldap_trydoorcall_send(ldap_data_t **dptr, int *ndata, int *adata);
void
__ns_ldap_doorfd_close();

#ifdef	__cplusplus
}
#endif


#endif	/* _NS_CACHE_DOOR_H */