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.c,v 1.28 2006/05/25 01:47:12 johnfranks Exp $
29 * Security driver interface for the Amanda backup system.
38 extern const security_driver_t bsd_security_driver;
41 extern const security_driver_t krb4_security_driver;
44 extern const security_driver_t krb5_security_driver;
47 extern const security_driver_t rsh_security_driver;
50 extern const security_driver_t ssh_security_driver;
52 #ifdef BSDTCP_SECURITY
53 extern const security_driver_t bsdtcp_security_driver;
55 #ifdef BSDUDP_SECURITY
56 extern const security_driver_t bsdudp_security_driver;
59 static const security_driver_t *drivers[] = {
64 &krb4_security_driver,
67 &krb5_security_driver,
75 #ifdef BSDTCP_SECURITY
76 &bsdtcp_security_driver,
78 #ifdef BSDUDP_SECURITY
79 &bsdudp_security_driver,
82 #define NDRIVERS (size_t)(sizeof(drivers) / sizeof(drivers[0]))
85 * Given a name of a security type, returns the driver structure
87 const security_driver_t *
95 for (i = 0; i < NDRIVERS; i++) {
96 if (strcasecmp(name, drivers[i]->name) == 0) {
97 dbprintf(("%s: security_getdriver(name=%s) returns %p\n",
98 debug_prefix_time(NULL), name, drivers[i]));
102 dbprintf(("%s: security_getdriver(name=%s) returns NULL\n",
103 debug_prefix_time(NULL), name));
108 * For the drivers: initialize the common part of a security_handle_t
112 security_handle_t * handle,
113 const security_driver_t * driver)
115 dbprintf(("%s: security_handleinit(handle=%p, driver=%p (%s))\n",
116 debug_prefix_time(NULL), handle, driver, driver->name));
117 handle->driver = driver;
118 handle->error = stralloc("unknown protocol error");
121 printf_arglist_function1(void security_seterror, security_handle_t *, handle,
124 static char buf[256];
127 assert(handle->error != NULL);
128 arglist_start(argp, fmt);
129 vsnprintf(buf, SIZEOF(buf), fmt, argp);
131 handle->error = newstralloc(handle->error, buf);
132 dbprintf(("%s: security_seterror(handle=%p, driver=%p (%s) error=%s)\n",
133 debug_prefix_time(NULL), handle, handle->driver,
134 handle->driver->name, handle->error));
139 security_handle_t * handle)
141 dbprintf(("%s: security_close(handle=%p, driver=%p (%s))\n",
142 debug_prefix_time(NULL), handle, handle->driver,
143 handle->driver->name));
144 amfree(handle->error);
145 (*handle->driver->close)(handle);
149 * For the drivers: initialize the common part of a security_stream_t
153 security_stream_t * stream,
154 const security_driver_t * driver)
156 dbprintf(("%s: security_streaminit(stream=%p, driver=%p (%s))\n",
157 debug_prefix_time(NULL), stream, driver, driver->name));
158 stream->driver = driver;
159 stream->error = stralloc("unknown stream error");
162 printf_arglist_function1(void security_stream_seterror,
163 security_stream_t *, stream,
166 static char buf[256];
169 arglist_start(argp, fmt);
170 vsnprintf(buf, SIZEOF(buf), fmt, argp);
172 stream->error = newstralloc(stream->error, buf);
173 dbprintf(("%s: security_stream_seterr(%p, %s)\n",
174 debug_prefix_time(NULL), stream, stream->error));
178 security_stream_close(
179 security_stream_t * stream)
181 dbprintf(("%s: security_stream_close(%p)\n",
182 debug_prefix_time(NULL), stream));
183 amfree(stream->error);
184 (*stream->driver->stream_close)(stream);