2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1999 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: security.h,v 1.11 2003/04/26 02:02:19 kovert Exp $
34 struct security_handle;
37 * This is a type that gets passed to the security_recvpkt() and
38 * security_connect() callbacks.
39 * It details what the status of this callback is.
41 typedef enum { S_OK, S_TIMEOUT, S_ERROR } security_status_t;
44 * This structure defines a security driver. This driver abstracts
45 * common security actions behind a set of function pointers. Macros
48 typedef struct security_driver {
50 * The name of this driver, eg, "BSD", "KRB4", etc...
55 * Connects a security handle, for this driver to a remote
58 void (*connect) P((const char *,
59 char *(*)(char *, void *),
60 void (*)(void *, struct security_handle *, security_status_t),
64 * This form sets up a callback that returns new handles as
65 * they are received. It takes an input and output file descriptor.
67 void (*accept) P((int, int, void (*)(struct security_handle *, pkt_t *)));
70 * Frees up handles allocated by the previous
72 void (*close) P((void *));
75 * This transmits a packet after adding the security information
76 * Returns 0 on success, negative on error.
78 int (*sendpkt) P((void *, pkt_t *));
81 * This creates an event in the event handler for receiving pkt_t's
82 * on a security_handle. The given callback with the given arg
83 * will be called when the driver determines that it has data
84 * for that handle. The last argument is a timeout, in seconds.
85 * This may be -1 to indicate no timeout.
87 * If there was an error or timeout, this will be indicated in
88 * the status argument.
90 * Only one recvpkt request can exist per handle.
92 void (*recvpkt) P((void *, void (*)(void *, pkt_t *,
93 security_status_t), void *, int));
96 * Cancel an outstanding recvpkt request on a handle.
98 void (*recvpkt_cancel) P((void *));
101 * Get a stream given a security handle
103 void *(*stream_server) P((void *));
106 * Accept a stream created by stream_server
108 int (*stream_accept) P((void *));
111 * Get a stream and connect it to a remote given a security handle
114 void *(*stream_client) P((void *, int));
117 * Close a stream opened with stream_server or stream_client
119 void (*stream_close) P((void *));
122 * Authenticate a stream.
124 int (*stream_auth) P((void *));
127 * Return a numeric id for a stream.
129 int (*stream_id) P((void *));
134 int (*stream_write) P((void *, const void *, size_t));
137 * Read asyncronously from a stream. Only one request can exist
140 void (*stream_read) P((void *, void (*)(void *, void *, ssize_t), void *));
143 * Cancel a stream read request
145 void (*stream_read_cancel) P((void *));
150 * This structure is a handle to a connection to a host for transmission
151 * of protocol packets (pkt_t's). The underlying security type defines
152 * the actual protocol and transport.
154 * This handle is reference counted so that it can be used inside of
155 * security streams after it has been closed by our callers.
157 typedef struct security_handle {
158 const security_driver_t *driver;
163 * This structure is a handle to a stream connection to a host for
164 * transmission of random data such as dumps or index data.
166 typedef struct security_stream {
167 const security_driver_t *driver;
172 const security_driver_t *security_getdriver P((const char *));
173 void security_handleinit P((security_handle_t *, const security_driver_t *));
174 void security_streaminit P((security_stream_t *, const security_driver_t *));
176 /* const char *security_geterror P((security_handle_t *)); */
177 #define security_geterror(handle) ((handle)->error)
178 void security_seterror P((security_handle_t *, const char *, ...))
179 __attribute__ ((format (printf, 2, 3)));
182 /* void security_connect P((const security_driver_t *, const char *,
183 void (*)(void *, security_handle_t *, security_status_t), void *)); */
184 #define security_connect(driver, hostname, conf_fn, fn, arg) \
185 (*(driver)->connect)(hostname, conf_fn, fn, arg)
186 /* void security_accept P((const security_driver_t *, int, int,
187 void (*)(security_handle_t *, pkt_t *))); */
188 #define security_accept(driver, in, out, fn) \
189 (*(driver)->accept)(in, out, fn)
190 void security_close P((security_handle_t *));
192 /* int security_sendpkt P((security_handle_t *, const pkt_t *)); */
193 #define security_sendpkt(handle, pkt) \
194 (*(handle)->driver->sendpkt)(handle, pkt)
196 /* void security_recvpkt P((security_handle_t *,
197 void (*)(void *, pkt_t *, security_status_t), void *, int); */
198 #define security_recvpkt(handle, fn, arg, timeout) \
199 (*(handle)->driver->recvpkt)(handle, fn, arg, timeout)
201 /* void security_recvpkt_cancel P((security_handle_t *)); */
202 #define security_recvpkt_cancel(handle) \
203 (*(handle)->driver->recvpkt_cancel)(handle)
205 /* const char *security_stream_geterror P((security_stream_t *)); */
206 #define security_stream_geterror(stream) ((stream)->error)
207 void security_stream_seterror P((security_stream_t *, const char *, ...))
208 __attribute__ ((format (printf, 2, 3)));
210 /* security_stream_t *security_stream_server P((security_handle_t *)); */
211 #define security_stream_server(handle) \
212 (*(handle)->driver->stream_server)(handle)
214 /* int security_stream_accept P((security_stream_t *)); */
215 #define security_stream_accept(stream) \
216 (*(stream)->driver->stream_accept)(stream)
218 /* security_stream_t *security_stream_client P((security_handle_t *, int)); */
219 #define security_stream_client(handle, id) \
220 (*(handle)->driver->stream_client)(handle, id)
222 void security_stream_close P((security_stream_t *));
224 /* int security_stream_auth P((security_stream_t *)); */
225 #define security_stream_auth(stream) \
226 (*(stream)->driver->stream_auth)(stream)
228 /* int security_stream_id P((security_stream_t *)); */
229 #define security_stream_id(stream) \
230 (*(stream)->driver->stream_id)(stream)
232 /* int security_stream_write P((security_stream_t *, const void *, size_t)); */
233 #define security_stream_write(stream, buf, size) \
234 (*(stream)->driver->stream_write)(stream, buf, size)
236 /* void security_stream_read P((security_stream_t *,
237 void (*)(void *, void *, size_t), void *)); */
238 #define security_stream_read(stream, fn, arg) \
239 (*(stream)->driver->stream_read)(stream, fn, arg)
241 /* void security_stream_read_cancel P((security_stream_t *)); */
242 #define security_stream_read_cancel(stream) \
243 (*(stream)->driver->stream_read_cancel)(stream)
245 #endif /* SECURITY_H */