3 Subroutines having to do with authentication. */
6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1998-2003 by Internet Software Consortium
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Internet Systems Consortium, Inc.
23 * Redwood City, CA 94063
27 * This software has been written for Internet Systems Consortium
28 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29 * To learn more about Internet Systems Consortium, see
30 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
31 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
32 * ``http://www.nominum.com''.
36 static char ocopyright
[] =
37 "$Id$ Copyright 2004 Internet Systems Consortium.";
40 #include <omapip/omapip_p.h>
42 OMAPI_OBJECT_ALLOC (omapi_auth_key
, omapi_auth_key_t
, omapi_type_auth_key
)
43 typedef struct hash omapi_auth_hash_t
;
44 HASH_FUNCTIONS_DECL (omapi_auth_key
, const char *,
45 omapi_auth_key_t
, omapi_auth_hash_t
)
46 omapi_auth_hash_t
*auth_key_hash
;
47 HASH_FUNCTIONS (omapi_auth_key
, const char *, omapi_auth_key_t
,
49 omapi_auth_key_reference
, omapi_auth_key_dereference
)
51 isc_result_t
omapi_auth_key_new (omapi_auth_key_t
**o
, const char *file
,
54 return omapi_auth_key_allocate (o
, file
, line
);
57 isc_result_t
omapi_auth_key_destroy (omapi_object_t
*h
,
58 const char *file
, int line
)
62 if (h
-> type
!= omapi_type_auth_key
)
63 return ISC_R_INVALIDARG
;
64 a
= (omapi_auth_key_t
*)h
;
67 omapi_auth_key_hash_delete (auth_key_hash
, a
-> name
, 0, MDL
);
70 dfree (a
-> name
, MDL
);
72 dfree (a
-> algorithm
, MDL
);
74 omapi_data_string_dereference (&a
-> key
, MDL
);
79 isc_result_t
omapi_auth_key_enter (omapi_auth_key_t
*a
)
83 if (a
-> type
!= omapi_type_auth_key
)
84 return ISC_R_INVALIDARG
;
86 tk
= (omapi_auth_key_t
*)0;
88 omapi_auth_key_hash_lookup (&tk
, auth_key_hash
,
91 omapi_auth_key_dereference (&tk
, MDL
);
95 omapi_auth_key_hash_delete (auth_key_hash
,
97 omapi_auth_key_dereference (&tk
, MDL
);
100 if (!omapi_auth_key_new_hash (&auth_key_hash
, 1, MDL
))
101 return ISC_R_NOMEMORY
;
103 omapi_auth_key_hash_add (auth_key_hash
, a
-> name
, 0, a
, MDL
);
104 return ISC_R_SUCCESS
;
108 isc_result_t
omapi_auth_key_lookup_name (omapi_auth_key_t
**a
,
112 return ISC_R_NOTFOUND
;
113 if (!omapi_auth_key_hash_lookup (a
, auth_key_hash
, name
, 0, MDL
))
114 return ISC_R_NOTFOUND
;
115 return ISC_R_SUCCESS
;
118 isc_result_t
omapi_auth_key_lookup (omapi_object_t
**h
,
123 omapi_value_t
*name
= (omapi_value_t
*)0;
124 omapi_value_t
*algorithm
= (omapi_value_t
*)0;
127 return ISC_R_NOTFOUND
;
132 status
= omapi_get_value_str (ref
, id
, "name", &name
);
133 if (status
!= ISC_R_SUCCESS
)
136 if ((name
-> value
-> type
!= omapi_datatype_string
) &&
137 (name
-> value
-> type
!= omapi_datatype_data
)) {
138 omapi_value_dereference (&name
, MDL
);
139 return ISC_R_NOTFOUND
;
142 status
= omapi_get_value_str (ref
, id
, "algorithm", &algorithm
);
143 if (status
!= ISC_R_SUCCESS
) {
144 omapi_value_dereference (&name
, MDL
);
148 if ((algorithm
-> value
-> type
!= omapi_datatype_string
) &&
149 (algorithm
-> value
-> type
!= omapi_datatype_data
)) {
150 omapi_value_dereference (&name
, MDL
);
151 omapi_value_dereference (&algorithm
, MDL
);
152 return ISC_R_NOTFOUND
;
156 if (!omapi_auth_key_hash_lookup ((omapi_auth_key_t
**)h
, auth_key_hash
,
158 name
-> value
-> u
.buffer
.value
,
159 name
-> value
-> u
.buffer
.len
, MDL
)) {
160 omapi_value_dereference (&name
, MDL
);
161 omapi_value_dereference (&algorithm
, MDL
);
162 return ISC_R_NOTFOUND
;
165 if (omapi_td_strcasecmp (algorithm
-> value
,
166 ((omapi_auth_key_t
*)*h
) -> algorithm
) != 0) {
167 omapi_value_dereference (&name
, MDL
);
168 omapi_value_dereference (&algorithm
, MDL
);
169 omapi_object_dereference (h
, MDL
);
170 return ISC_R_NOTFOUND
;
173 omapi_value_dereference (&name
, MDL
);
174 omapi_value_dereference (&algorithm
, MDL
);
176 return ISC_R_SUCCESS
;
179 isc_result_t
omapi_auth_key_stuff_values (omapi_object_t
*c
,
186 if (h
-> type
!= omapi_type_auth_key
)
187 return ISC_R_INVALIDARG
;
188 a
= (omapi_auth_key_t
*)h
;
190 /* Write only the name and algorithm -- not the secret! */
192 status
= omapi_connection_put_name (c
, "name");
193 if (status
!= ISC_R_SUCCESS
)
195 status
= omapi_connection_put_string (c
, a
-> name
);
196 if (status
!= ISC_R_SUCCESS
)
199 if (a
-> algorithm
) {
200 status
= omapi_connection_put_name (c
, "algorithm");
201 if (status
!= ISC_R_SUCCESS
)
203 status
= omapi_connection_put_string (c
, a
-> algorithm
);
204 if (status
!= ISC_R_SUCCESS
)
208 return ISC_R_SUCCESS
;
211 isc_result_t
omapi_auth_key_get_value (omapi_object_t
*h
,
213 omapi_data_string_t
*name
,
214 omapi_value_t
**value
)
219 if (h
-> type
!= omapi_type_auth_key
)
220 return ISC_R_UNEXPECTED
;
221 a
= (omapi_auth_key_t
*)h
;
223 if (omapi_ds_strcmp (name
, "name") == 0) {
225 return omapi_make_string_value
226 (value
, name
, a
-> name
, MDL
);
228 return ISC_R_NOTFOUND
;
229 } else if (omapi_ds_strcmp (name
, "key") == 0) {
231 status
= omapi_value_new (value
, MDL
);
232 if (status
!= ISC_R_SUCCESS
)
235 status
= omapi_data_string_reference
236 (&(*value
) -> name
, name
, MDL
);
237 if (status
!= ISC_R_SUCCESS
) {
238 omapi_value_dereference (value
, MDL
);
242 status
= omapi_typed_data_new (MDL
, &(*value
) -> value
,
245 if (status
!= ISC_R_SUCCESS
) {
246 omapi_value_dereference (value
, MDL
);
250 memcpy ((*value
) -> value
-> u
.buffer
.value
,
251 a
-> key
-> value
, a
-> key
-> len
);
252 return ISC_R_SUCCESS
;
254 return ISC_R_NOTFOUND
;
255 } else if (omapi_ds_strcmp (name
, "algorithm") == 0) {
257 return omapi_make_string_value
258 (value
, name
, a
-> algorithm
, MDL
);
260 return ISC_R_NOTFOUND
;
263 return ISC_R_SUCCESS
;