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.17 2006/05/26 14:00:58 martinea Exp $
36 struct security_handle;
39 * This is a type that gets passed to the security_recvpkt() and
40 * security_connect() callbacks.
41 * It details what the status of this callback is.
43 typedef enum { S_OK, S_TIMEOUT, S_ERROR } security_status_t;
46 * This structure defines a security driver. This driver abstracts
47 * common security actions behind a set of function pointers. Macros
50 typedef struct security_driver {
52 * The name of this driver, eg, "BSD", "KRB4", etc...
57 * Connects a security handle, for this driver to a remote
60 void (*connect)(const char *,
61 char *(*)(char *, void *),
62 void (*)(void *, struct security_handle *, security_status_t),
66 * This form sets up a callback that returns new handles as
67 * they are received. It takes an input and output file descriptor.
69 void (*accept)(const struct security_driver *, int, int,
70 void (*)(struct security_handle *, pkt_t *));
73 * Frees up handles allocated by the previous
75 void (*close)(void *);
78 * This transmits a packet after adding the security information
79 * Returns 0 on success, negative on error.
81 ssize_t (*sendpkt)(void *, pkt_t *);
84 * This creates an event in the event handler for receiving pkt_t's
85 * on a security_handle. The given callback with the given arg
86 * will be called when the driver determines that it has data
87 * for that handle. The last argument is a timeout, in seconds.
88 * This may be -1 to indicate no timeout.
90 * If there was an error or timeout, this will be indicated in
91 * the status argument.
93 * Only one recvpkt request can exist per handle.
95 void (*recvpkt)(void *, void (*)(void *, pkt_t *,
96 security_status_t), void *, int);
99 * Cancel an outstanding recvpkt request on a handle.
101 void (*recvpkt_cancel)(void *);
104 * Get a stream given a security handle
106 void *(*stream_server)(void *);
109 * Accept a stream created by stream_server
111 int (*stream_accept)(void *);
114 * Get a stream and connect it to a remote given a security handle
117 void *(*stream_client)(void *, int);
120 * Close a stream opened with stream_server or stream_client
122 void (*stream_close)(void *);
125 * Authenticate a stream.
127 int (*stream_auth)(void *);
130 * Return a numeric id for a stream.
132 int (*stream_id)(void *);
137 int (*stream_write)(void *, const void *, size_t);
140 * Read asyncronously from a stream. Only one request can exist
143 void (*stream_read)(void *, void (*)(void *, void *, ssize_t), void *);
146 * Read syncronously from a stream.
148 ssize_t (*stream_read_sync)(void *, void **);
151 * Cancel a stream read request
153 void (*stream_read_cancel)(void *);
155 void (*close_connection)(void *, char *);
160 * This structure is a handle to a connection to a host for transmission
161 * of protocol packets (pkt_t's). The underlying security type defines
162 * the actual protocol and transport.
164 * This handle is reference counted so that it can be used inside of
165 * security streams after it has been closed by our callers.
167 typedef struct security_handle {
168 const security_driver_t *driver;
173 * This structure is a handle to a stream connection to a host for
174 * transmission of random data such as dumps or index data.
176 typedef struct security_stream {
177 const security_driver_t *driver;
182 const security_driver_t *security_getdriver(const char *);
183 void security_handleinit(security_handle_t *, const security_driver_t *);
184 void security_streaminit(security_stream_t *, const security_driver_t *);
186 /* const char *security_geterror(security_handle_t *); */
187 #define security_geterror(handle) ((handle)->error)
188 void security_seterror(security_handle_t *, const char *, ...)
189 __attribute__ ((format (printf, 2, 3)));
192 /* void security_connect(const security_driver_t *, const char *,
193 void (*)(void *, security_handle_t *, security_status_t), void *, void *); */
194 #define security_connect(driver, hostname, conf_fn, fn, arg, datap) \
195 (*(driver)->connect)(hostname, conf_fn, fn, arg, datap)
196 /* void security_accept(const security_driver_t *, int, int,
197 void (*)(security_handle_t *, pkt_t *)); */
198 #define security_accept(driver, in, out, fn) \
199 (*(driver)->accept)(driver, in, out, fn)
200 void security_close(security_handle_t *);
202 /* int security_sendpkt(security_handle_t *, const pkt_t *); */
203 #define security_sendpkt(handle, pkt) \
204 (*(handle)->driver->sendpkt)(handle, pkt)
206 /* void security_recvpkt(security_handle_t *,
207 void (*)(void *, pkt_t *, security_status_t), void *, int); */
208 #define security_recvpkt(handle, fn, arg, timeout) \
209 (*(handle)->driver->recvpkt)(handle, fn, arg, timeout)
211 /* void security_recvpkt_cancel(security_handle_t *); */
212 #define security_recvpkt_cancel(handle) \
213 (*(handle)->driver->recvpkt_cancel)(handle)
215 /* const char *security_stream_geterror(security_stream_t *); */
216 #define security_stream_geterror(stream) ((stream)->error)
217 void security_stream_seterror(security_stream_t *, const char *, ...)
218 __attribute__ ((format (printf, 2, 3)));
220 /* security_stream_t *security_stream_server(security_handle_t *); */
221 #define security_stream_server(handle) \
222 (*(handle)->driver->stream_server)(handle)
224 /* int security_stream_accept(security_stream_t *); */
225 #define security_stream_accept(stream) \
226 (*(stream)->driver->stream_accept)(stream)
228 /* security_stream_t *security_stream_client(security_handle_t *, int); */
229 #define security_stream_client(handle, id) \
230 (*(handle)->driver->stream_client)(handle, id)
232 void security_stream_close(security_stream_t *);
234 /* int security_stream_auth(security_stream_t *); */
235 #define security_stream_auth(stream) \
236 (*(stream)->driver->stream_auth)(stream)
238 /* int security_stream_id(security_stream_t *); */
239 #define security_stream_id(stream) \
240 (*(stream)->driver->stream_id)(stream)
242 /* int security_stream_write(security_stream_t *, const void *, size_t); */
243 #define security_stream_write(stream, buf, size) \
244 (*(stream)->driver->stream_write)(stream, buf, size)
246 /* void security_stream_read(security_stream_t *,
247 void (*)(void *, void *, size_t), void *); */
248 #define security_stream_read(stream, fn, arg) \
249 (*(stream)->driver->stream_read)(stream, fn, arg)
251 /* void security_stream_read_sync(security_stream_t *, void *); */
252 #define security_stream_read_sync(stream, buf) \
253 (*(stream)->driver->stream_read_sync)(stream, buf)
255 /* void security_stream_read_cancel(security_stream_t *); */
256 #define security_stream_read_cancel(stream) \
257 (*(stream)->driver->stream_read_cancel)(stream)
259 #define security_close_connection(handle, hostname) \
260 (*(handle)->driver->close_connection)(handle, hostname)
261 #endif /* SECURITY_H */