3 The dhcpctl remote object. */
6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1999-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 copyright
[] =
37 "$Id$ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
40 #include <omapip/omapip_p.h>
43 /* dhcpctl_new_authenticator
45 synchronous - creates an authenticator object.
46 returns nonzero status code if the object couldn't be created
47 stores handle to authenticator through h if successful, and returns zero.
48 name is the authenticator name (NUL-terminated string).
49 algorithm is the NUL-terminated string name of the algorithm to use
50 (currently, only "hmac-md5" is supported).
51 secret and secret_len is the key secret. */
53 dhcpctl_status
dhcpctl_new_authenticator (dhcpctl_handle
*h
,
55 const char *algorithm
,
56 const unsigned char *secret
,
59 struct auth_key
*key
= (struct auth_key
*)0;
62 status
= omapi_auth_key_new (&key
, MDL
);
63 if (status
!= ISC_R_SUCCESS
)
66 key
-> name
= dmalloc (strlen (name
) + 1, MDL
);
68 omapi_auth_key_dereference (&key
, MDL
);
69 return ISC_R_NOMEMORY
;
71 strcpy (key
-> name
, name
);
73 /* If the algorithm name isn't an FQDN, tack on the
74 .SIG-ALG.REG.NET. domain. */
75 if (strchr (algorithm
, '.') == 0) {
76 static char add
[] = ".SIG-ALG.REG.INT.";
77 key
-> algorithm
= dmalloc (strlen (algorithm
) +
79 if (!key
-> algorithm
) {
80 omapi_auth_key_dereference (&key
, MDL
);
81 return ISC_R_NOMEMORY
;
83 strcpy (key
-> algorithm
, algorithm
);
84 strcat (key
-> algorithm
, add
);
86 key
-> algorithm
= dmalloc (strlen (algorithm
) + 1, MDL
);
87 if (!key
-> algorithm
) {
88 omapi_auth_key_dereference (&key
, MDL
);
89 return ISC_R_NOMEMORY
;
91 strcpy (key
-> algorithm
, algorithm
);
94 status
= omapi_data_string_new (&key
-> key
, secret_len
, MDL
);
95 if (status
!= ISC_R_SUCCESS
) {
96 omapi_auth_key_dereference (&key
, MDL
);
99 memcpy (key
-> key
-> value
, secret
, secret_len
);
100 key
-> key
-> len
= secret_len
;
102 *h
= (dhcpctl_handle
) key
;
103 return ISC_R_SUCCESS
;
107 /* dhcpctl_new_object
109 synchronous - creates a local handle for a host entry.
110 returns nonzero status code if the local host entry couldn't
112 stores handle to host through h if successful, and returns zero.
113 object_type is a pointer to a NUL-terminated string containing
114 the ascii name of the type of object being accessed - e.g., "host" */
116 dhcpctl_status
dhcpctl_new_object (dhcpctl_handle
*h
,
117 dhcpctl_handle connection
,
118 const char *object_type
)
120 dhcpctl_remote_object_t
*m
;
124 m
= (dhcpctl_remote_object_t
*)0;
125 status
= omapi_object_allocate ((omapi_object_t
**)&m
,
126 dhcpctl_remote_type
, 0, MDL
);
127 if (status
!= ISC_R_SUCCESS
)
130 g
= (omapi_object_t
*)0;
131 status
= omapi_generic_new (&g
, MDL
);
132 if (status
!= ISC_R_SUCCESS
) {
136 status
= omapi_object_reference (&m
-> inner
, g
, MDL
);
137 if (status
!= ISC_R_SUCCESS
) {
138 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
139 omapi_object_dereference (&g
, MDL
);
142 status
= omapi_object_reference (&g
-> outer
,
143 (omapi_object_t
*)m
, MDL
);
145 if (status
!= ISC_R_SUCCESS
) {
146 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
147 omapi_object_dereference (&g
, MDL
);
151 status
= omapi_typed_data_new (MDL
, &m
-> rtype
,
152 omapi_datatype_string
,
154 if (status
!= ISC_R_SUCCESS
) {
155 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
156 omapi_object_dereference (&g
, MDL
);
160 status
= omapi_object_reference (h
, (omapi_object_t
*)m
, MDL
);
161 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
162 omapi_object_dereference (&g
, MDL
);
163 if (status
!= ISC_R_SUCCESS
)
169 /* asynchronous - just queues the request
170 returns nonzero status code if open couldn't be queued
171 returns zero if open was queued
172 h is a handle to an object created by dhcpctl_new_object
173 connection is a connection to a DHCP server
175 DHCPCTL_CREATE - if the object doesn't exist, create it
176 DHCPCTL_UPDATE - update the object on the server using the
178 DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
179 was also specified */
181 dhcpctl_status
dhcpctl_open_object (dhcpctl_handle h
,
182 dhcpctl_handle connection
,
186 omapi_object_t
*message
= (omapi_object_t
*)0;
187 dhcpctl_remote_object_t
*remote
;
189 if (h
-> type
!= dhcpctl_remote_type
)
190 return ISC_R_INVALIDARG
;
191 remote
= (dhcpctl_remote_object_t
*)h
;
193 status
= omapi_message_new (&message
, MDL
);
194 if (status
!= ISC_R_SUCCESS
)
196 status
= omapi_set_int_value (message
, (omapi_object_t
*)0,
197 "op", OMAPI_OP_OPEN
);
198 if (status
!= ISC_R_SUCCESS
) {
199 omapi_object_dereference (&message
, MDL
);
202 status
= omapi_set_object_value (message
, (omapi_object_t
*)0,
204 if (status
!= ISC_R_SUCCESS
) {
205 omapi_object_dereference (&message
, MDL
);
208 if (flags
& DHCPCTL_CREATE
) {
209 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
211 if (status
!= ISC_R_SUCCESS
) {
212 omapi_object_dereference (&message
, MDL
);
216 if (flags
& DHCPCTL_UPDATE
) {
217 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
219 if (status
!= ISC_R_SUCCESS
) {
220 omapi_object_dereference (&message
, MDL
);
224 if (flags
& DHCPCTL_EXCL
) {
225 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
227 if (status
!= ISC_R_SUCCESS
) {
228 omapi_object_dereference (&message
, MDL
);
233 if (remote
-> rtype
) {
234 status
= omapi_set_value_str (message
, (omapi_object_t
*)0,
235 "type", remote
-> rtype
);
236 if (status
!= ISC_R_SUCCESS
) {
237 omapi_object_dereference (&message
, MDL
);
242 status
= omapi_message_register (message
);
243 if (status
!= ISC_R_SUCCESS
) {
244 omapi_object_dereference (&message
, MDL
);
248 status
= omapi_protocol_send_message (connection
-> outer
,
250 message
, (omapi_object_t
*)0);
252 if (status
!= ISC_R_SUCCESS
)
253 omapi_message_unregister (message
);
255 omapi_object_dereference (&message
, MDL
);
259 /* Callback methods (not meant to be called directly) */
261 isc_result_t
dhcpctl_remote_set_value (omapi_object_t
*h
,
263 omapi_data_string_t
*name
,
264 omapi_typed_data_t
*value
)
266 dhcpctl_remote_object_t
*ro
;
270 if (h
-> type
!= dhcpctl_remote_type
)
271 return ISC_R_INVALIDARG
;
272 ro
= (dhcpctl_remote_object_t
*)h
;
274 if (!omapi_ds_strcmp (name
, "remote-handle")) {
275 status
= omapi_get_int_value (&rh
, value
);
276 if (status
== ISC_R_SUCCESS
)
277 ro
-> remote_handle
= rh
;
281 if (h
-> inner
&& h
-> inner
-> type
-> set_value
)
282 return (*(h
-> inner
-> type
-> set_value
))
283 (h
-> inner
, id
, name
, value
);
284 return ISC_R_NOTFOUND
;
287 isc_result_t
dhcpctl_remote_get_value (omapi_object_t
*h
,
289 omapi_data_string_t
*name
,
290 omapi_value_t
**value
)
292 if (h
-> type
!= dhcpctl_remote_type
)
293 return ISC_R_INVALIDARG
;
295 if (h
-> inner
&& h
-> inner
-> type
-> get_value
)
296 return (*(h
-> inner
-> type
-> get_value
))
297 (h
-> inner
, id
, name
, value
);
298 return ISC_R_NOTFOUND
;
301 isc_result_t
dhcpctl_remote_signal_handler (omapi_object_t
*o
,
302 const char *name
, va_list ap
)
304 dhcpctl_remote_object_t
*p
;
305 omapi_typed_data_t
*tv
;
307 if (o
-> type
!= dhcpctl_remote_type
)
308 return ISC_R_INVALIDARG
;
309 p
= (dhcpctl_remote_object_t
*)o
;
311 if (!strcmp (name
, "updated")) {
312 p
-> waitstatus
= ISC_R_SUCCESS
;
313 if (o
-> inner
-> type
== omapi_type_generic
)
314 omapi_generic_clear_flags (o
-> inner
);
315 return omapi_signal_in (o
-> inner
, "ready");
317 if (!strcmp (name
, "status")) {
318 p
-> waitstatus
= va_arg (ap
, isc_result_t
);
320 omapi_typed_data_dereference (&p
-> message
, MDL
);
321 tv
= va_arg (ap
, omapi_typed_data_t
*);
323 omapi_typed_data_reference (&p
-> message
, tv
, MDL
);
324 return omapi_signal_in (o
-> inner
, "ready");
327 if (p
-> inner
&& p
-> inner
-> type
-> signal_handler
)
328 return (*(p
-> inner
-> type
-> signal_handler
))
329 (p
-> inner
, name
, ap
);
331 return ISC_R_SUCCESS
;
334 isc_result_t
dhcpctl_remote_destroy (omapi_object_t
*h
,
335 const char *file
, int line
)
337 dhcpctl_remote_object_t
*p
;
338 if (h
-> type
!= dhcpctl_remote_type
)
339 return ISC_R_INVALIDARG
;
340 p
= (dhcpctl_remote_object_t
*)h
;
342 omapi_object_dereference ((omapi_object_t
**)&p
-> handle
,
345 omapi_typed_data_dereference ((omapi_typed_data_t
**)&p
->rtype
,
347 return ISC_R_SUCCESS
;
350 /* Write all the published values associated with the object through the
351 specified connection. */
353 isc_result_t
dhcpctl_remote_stuff_values (omapi_object_t
*c
,
359 if (p
-> type
!= dhcpctl_remote_type
)
360 return ISC_R_INVALIDARG
;
362 if (p
-> inner
&& p
-> inner
-> type
-> stuff_values
)
363 return (*(p
-> inner
-> type
-> stuff_values
)) (c
, id
,
365 return ISC_R_SUCCESS
;