3 Subroutines having to do with authentication. */
6 * Copyright (c) 1998-2001 Internet Software Consortium.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38 * To learn more about the Internet Software Consortium, see
39 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
40 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
41 * ``http://www.nominum.com''.
45 static char ocopyright[] =
46 "$Id: auth.c,v 1.3.2.3 2001/10/17 03:27:56 mellon Exp $ Copyright 1998-2000 The Internet Software Consortium.";
49 #include <omapip/omapip_p.h>
51 OMAPI_OBJECT_ALLOC (omapi_auth_key, omapi_auth_key_t, omapi_type_auth_key)
52 typedef struct hash omapi_auth_hash_t;
53 HASH_FUNCTIONS_DECL (omapi_auth_key, const char *,
54 omapi_auth_key_t, omapi_auth_hash_t)
55 omapi_auth_hash_t *auth_key_hash;
56 HASH_FUNCTIONS (omapi_auth_key, const char *, omapi_auth_key_t,
58 omapi_auth_key_reference, omapi_auth_key_dereference)
60 isc_result_t omapi_auth_key_new (omapi_auth_key_t **o, const char *file,
63 return omapi_auth_key_allocate (o, file, line);
66 isc_result_t omapi_auth_key_destroy (omapi_object_t *h,
67 const char *file, int line)
71 if (h -> type != omapi_type_auth_key)
72 return ISC_R_INVALIDARG;
73 a = (omapi_auth_key_t *)h;
76 omapi_auth_key_hash_delete (auth_key_hash, a -> name, 0, MDL);
79 dfree (a -> name, MDL);
81 dfree (a -> algorithm, MDL);
83 omapi_data_string_dereference (&a -> key, MDL);
88 isc_result_t omapi_auth_key_enter (omapi_auth_key_t *a)
92 if (a -> type != omapi_type_auth_key)
93 return ISC_R_INVALIDARG;
95 tk = (omapi_auth_key_t *)0;
97 omapi_auth_key_hash_lookup (&tk, auth_key_hash,
100 omapi_auth_key_dereference (&tk, MDL);
101 return ISC_R_SUCCESS;
104 omapi_auth_key_hash_delete (auth_key_hash,
106 omapi_auth_key_dereference (&tk, MDL);
109 if (!omapi_auth_key_new_hash (&auth_key_hash, 1, MDL))
110 return ISC_R_NOMEMORY;
112 omapi_auth_key_hash_add (auth_key_hash, a -> name, 0, a, MDL);
113 return ISC_R_SUCCESS;
117 isc_result_t omapi_auth_key_lookup_name (omapi_auth_key_t **a,
121 return ISC_R_NOTFOUND;
122 if (!omapi_auth_key_hash_lookup (a, auth_key_hash, name, 0, MDL))
123 return ISC_R_NOTFOUND;
124 return ISC_R_SUCCESS;
127 isc_result_t omapi_auth_key_lookup (omapi_object_t **h,
132 omapi_value_t *name = (omapi_value_t *)0;
133 omapi_value_t *algorithm = (omapi_value_t *)0;
136 return ISC_R_NOTFOUND;
141 status = omapi_get_value_str (ref, id, "name", &name);
142 if (status != ISC_R_SUCCESS)
145 if ((name -> value -> type != omapi_datatype_string) &&
146 (name -> value -> type != omapi_datatype_data)) {
147 omapi_value_dereference (&name, MDL);
148 return ISC_R_NOTFOUND;
151 status = omapi_get_value_str (ref, id, "algorithm", &algorithm);
152 if (status != ISC_R_SUCCESS) {
153 omapi_value_dereference (&name, MDL);
157 if ((algorithm -> value -> type != omapi_datatype_string) &&
158 (algorithm -> value -> type != omapi_datatype_data)) {
159 omapi_value_dereference (&name, MDL);
160 omapi_value_dereference (&algorithm, MDL);
161 return ISC_R_NOTFOUND;
165 if (!omapi_auth_key_hash_lookup ((omapi_auth_key_t **)h, auth_key_hash,
167 name -> value -> u.buffer.value,
168 name -> value -> u.buffer.len, MDL)) {
169 omapi_value_dereference (&name, MDL);
170 omapi_value_dereference (&algorithm, MDL);
171 return ISC_R_NOTFOUND;
174 if (omapi_td_strcasecmp (algorithm -> value,
175 ((omapi_auth_key_t *)*h) -> algorithm) != 0) {
176 omapi_value_dereference (&name, MDL);
177 omapi_value_dereference (&algorithm, MDL);
178 omapi_object_dereference (h, MDL);
179 return ISC_R_NOTFOUND;
182 omapi_value_dereference (&name, MDL);
183 omapi_value_dereference (&algorithm, MDL);
185 return ISC_R_SUCCESS;
188 isc_result_t omapi_auth_key_stuff_values (omapi_object_t *c,
195 if (h -> type != omapi_type_auth_key)
196 return ISC_R_INVALIDARG;
197 a = (omapi_auth_key_t *)h;
199 /* Write only the name and algorithm -- not the secret! */
201 status = omapi_connection_put_name (c, "name");
202 if (status != ISC_R_SUCCESS)
204 status = omapi_connection_put_string (c, a -> name);
205 if (status != ISC_R_SUCCESS)
208 if (a -> algorithm) {
209 status = omapi_connection_put_name (c, "algorithm");
210 if (status != ISC_R_SUCCESS)
212 status = omapi_connection_put_string (c, a -> algorithm);
213 if (status != ISC_R_SUCCESS)
217 return ISC_R_SUCCESS;
220 isc_result_t omapi_auth_key_get_value (omapi_object_t *h,
222 omapi_data_string_t *name,
223 omapi_value_t **value)
228 if (h -> type != omapi_type_auth_key)
229 return ISC_R_UNEXPECTED;
230 a = (omapi_auth_key_t *)h;
232 if (omapi_ds_strcmp (name, "name") == 0) {
234 return omapi_make_string_value
235 (value, name, a -> name, MDL);
237 return ISC_R_NOTFOUND;
238 } else if (omapi_ds_strcmp (name, "key") == 0) {
240 status = omapi_value_new (value, MDL);
241 if (status != ISC_R_SUCCESS)
244 status = omapi_data_string_reference
245 (&(*value) -> name, name, MDL);
246 if (status != ISC_R_SUCCESS) {
247 omapi_value_dereference (value, MDL);
251 status = omapi_typed_data_new (MDL, &(*value) -> value,
254 if (status != ISC_R_SUCCESS) {
255 omapi_value_dereference (value, MDL);
259 memcpy ((*value) -> value -> u.buffer.value,
260 a -> key -> value, a -> key -> len);
261 return ISC_R_SUCCESS;
263 return ISC_R_NOTFOUND;
264 } else if (omapi_ds_strcmp (name, "algorithm") == 0) {
266 return omapi_make_string_value
267 (value, name, a -> algorithm, MDL);
269 return ISC_R_NOTFOUND;
272 return ISC_R_SUCCESS;