Fix chdir/fchdir for setuid/setgid binaries
[dragonfly.git] / usr.sbin / nscd / protocol.h
blob3d6760fa8d06c44ad4efb63ea086e6d9834ee68a
1 /*-
2 * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/usr.sbin/nscd/protocol.h,v 1.3 2007/09/27 12:30:11 bushman Exp $
29 #ifndef __NSCD_PROTOCOL_H__
30 #define __NSCD_PROTOCOL_H__
32 #include <stdlib.h>
34 /* maximum buffer size to receive - larger buffers are not allowed */
35 #define MAX_BUFFER_SIZE (1 << 20)
37 /* buffer size correctness checking routine */
38 #define BUFSIZE_CORRECT(x) (((x) > 0) && ((x) < MAX_BUFFER_SIZE))
39 #define BUFSIZE_INVALID(x) (!BUFSIZE_CORRECT(x))
41 /* structures below represent the data that are sent/received by the daemon */
42 struct cache_write_request
44 char *entry;
45 char *cache_key;
46 char *data;
48 size_t entry_length;
49 size_t cache_key_size;
50 size_t data_size;
53 struct cache_write_response
55 int error_code;
58 struct cache_read_request
60 char *entry;
61 char *cache_key;
63 size_t entry_length;
64 size_t cache_key_size;
67 struct cache_read_response
69 char *data; // ignored if error_code is not 0
70 size_t data_size; // ignored if error_code is not 0
72 int error_code;
75 enum transformation_type {
76 TT_USER = 0, // tranform only the entries of the caller
77 TT_ALL = 1 // transform all entries
80 struct cache_transform_request
82 char *entry; // ignored if entry_length is 0
83 size_t entry_length;
85 int transformation_type;
88 struct cache_transform_response
90 int error_code;
93 struct cache_mp_write_session_request {
94 char *entry;
95 size_t entry_length;
98 struct cache_mp_write_session_response {
99 int error_code;
102 struct cache_mp_write_session_write_request {
103 char *data;
104 size_t data_size;
107 struct cache_mp_write_session_write_response {
108 int error_code;
111 struct cache_mp_read_session_request {
112 char *entry;
113 size_t entry_length;
116 struct cache_mp_read_session_response {
117 int error_code;
120 struct cache_mp_read_session_read_response {
121 char *data;
122 size_t data_size;
124 int error_code;
128 enum comm_element_t {
129 CET_UNDEFINED = 0,
130 CET_WRITE_REQUEST = 1,
131 CET_WRITE_RESPONSE = 2,
132 CET_READ_REQUEST = 3,
133 CET_READ_RESPONSE = 4,
134 CET_TRANSFORM_REQUEST = 5,
135 CET_TRANSFORM_RESPONSE = 6,
136 CET_MP_WRITE_SESSION_REQUEST = 7,
137 CET_MP_WRITE_SESSION_RESPONSE = 8,
138 CET_MP_WRITE_SESSION_WRITE_REQUEST = 9,
139 CET_MP_WRITE_SESSION_WRITE_RESPONSE = 10,
140 CET_MP_WRITE_SESSION_CLOSE_NOTIFICATION = 11,
141 CET_MP_WRITE_SESSION_ABANDON_NOTIFICATION = 12,
142 CET_MP_READ_SESSION_REQUEST = 13,
143 CET_MP_READ_SESSION_RESPONSE = 14,
144 CET_MP_READ_SESSION_READ_REQUEST = 15,
145 CET_MP_READ_SESSION_READ_RESPONSE = 16,
146 CET_MP_READ_SESSION_CLOSE_NOTIFICATION = 17,
147 CET_MAX = 18
151 * The comm_element is used as the holder of any known (defined above) data
152 * type that is to be sent/received.
154 struct comm_element
156 union {
157 struct cache_write_request c_write_request;
158 struct cache_write_response c_write_response;
159 struct cache_read_request c_read_request;
160 struct cache_read_response c_read_response;
161 struct cache_transform_request c_transform_request;
162 struct cache_transform_response c_transform_response;
164 struct cache_mp_write_session_request c_mp_ws_request;
165 struct cache_mp_write_session_response c_mp_ws_response;
166 struct cache_mp_write_session_write_request c_mp_ws_write_request;
167 struct cache_mp_write_session_write_response c_mp_ws_write_response;
169 struct cache_mp_read_session_request c_mp_rs_request;
170 struct cache_mp_read_session_response c_mp_rs_response;
171 struct cache_mp_read_session_read_response c_mp_rs_read_response;
173 enum comm_element_t type;
176 extern void init_comm_element(struct comm_element *, enum comm_element_t type);
177 extern void finalize_comm_element(struct comm_element *);
180 * For each type of data, there is three functions (init/finalize/get), that
181 * used with comm_element structure
183 extern void init_cache_write_request(struct cache_write_request *);
184 extern void finalize_cache_write_request(struct cache_write_request *);
185 extern struct cache_write_request *get_cache_write_request(
186 struct comm_element *);
188 extern void init_cache_write_response(struct cache_write_response *);
189 extern void finalize_cache_write_response(struct cache_write_response *);
190 extern struct cache_write_response *get_cache_write_response(
191 struct comm_element *);
193 extern void init_cache_read_request(struct cache_read_request *);
194 extern void finalize_cache_read_request(struct cache_read_request *);
195 extern struct cache_read_request *get_cache_read_request(
196 struct comm_element *);
198 extern void init_cache_read_response(struct cache_read_response *);
199 extern void finalize_cache_read_response(struct cache_read_response *);
200 extern struct cache_read_response *get_cache_read_response(
201 struct comm_element *);
203 extern void init_cache_transform_request(struct cache_transform_request *);
204 extern void finalize_cache_transform_request(struct cache_transform_request *);
205 extern struct cache_transform_request *get_cache_transform_request(
206 struct comm_element *);
208 extern void init_cache_transform_response(struct cache_transform_response *);
209 extern void finalize_cache_transform_response(
210 struct cache_transform_response *);
211 extern struct cache_transform_response *get_cache_transform_response(
212 struct comm_element *);
214 extern void init_cache_mp_write_session_request(
215 struct cache_mp_write_session_request *);
216 extern void finalize_cache_mp_write_session_request(
217 struct cache_mp_write_session_request *);
218 extern struct cache_mp_write_session_request *
219 get_cache_mp_write_session_request(
220 struct comm_element *);
222 extern void init_cache_mp_write_session_response(
223 struct cache_mp_write_session_response *);
224 extern void finalize_cache_mp_write_session_response(
225 struct cache_mp_write_session_response *);
226 extern struct cache_mp_write_session_response *
227 get_cache_mp_write_session_response(struct comm_element *);
229 extern void init_cache_mp_write_session_write_request(
230 struct cache_mp_write_session_write_request *);
231 extern void finalize_cache_mp_write_session_write_request(
232 struct cache_mp_write_session_write_request *);
233 extern struct cache_mp_write_session_write_request *
234 get_cache_mp_write_session_write_request(struct comm_element *);
236 extern void init_cache_mp_write_session_write_response(
237 struct cache_mp_write_session_write_response *);
238 extern void finalize_cache_mp_write_session_write_response(
239 struct cache_mp_write_session_write_response *);
240 extern struct cache_mp_write_session_write_response *
241 get_cache_mp_write_session_write_response(struct comm_element *);
243 extern void init_cache_mp_read_session_request(
244 struct cache_mp_read_session_request *);
245 extern void finalize_cache_mp_read_session_request(
246 struct cache_mp_read_session_request *);
247 extern struct cache_mp_read_session_request *get_cache_mp_read_session_request(
248 struct comm_element *);
250 extern void init_cache_mp_read_session_response(
251 struct cache_mp_read_session_response *);
252 extern void finalize_cache_mp_read_session_response(
253 struct cache_mp_read_session_response *);
254 extern struct cache_mp_read_session_response *
255 get_cache_mp_read_session_response(
256 struct comm_element *);
258 extern void init_cache_mp_read_session_read_response(
259 struct cache_mp_read_session_read_response *);
260 extern void finalize_cache_mp_read_session_read_response(
261 struct cache_mp_read_session_read_response *);
262 extern struct cache_mp_read_session_read_response *
263 get_cache_mp_read_session_read_response(struct comm_element *);
265 #endif