3
The dhcpctl remote object. */
6
* Copyright (c) 2004,2007 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
#include <omapip/omapip_p.h>
39
/* dhcpctl_new_authenticator
41
synchronous - creates an authenticator object.
42
returns nonzero status code if the object couldn't be created
43
stores handle to authenticator through h if successful, and returns zero.
44
name is the authenticator name (NUL-terminated string).
45
algorithm is the NUL-terminated string name of the algorithm to use
46
(currently, only "hmac-md5" is supported).
47
secret and secret_len is the key secret. */
49
dhcpctl_status dhcpctl_new_authenticator (dhcpctl_handle *h,
51
const char *algorithm,
52
const unsigned char *secret,
55
struct auth_key *key = (struct auth_key *)0;
58
status = omapi_auth_key_new (&key, MDL);
59
if (status != ISC_R_SUCCESS)
62
key -> name = dmalloc (strlen (name) + 1, MDL);
64
omapi_auth_key_dereference (&key, MDL);
65
return ISC_R_NOMEMORY;
67
strcpy (key -> name, name);
69
/* If the algorithm name isn't an FQDN, tack on the
70
.SIG-ALG.REG.NET. domain. */
71
if (strchr (algorithm, '.') == 0) {
72
static char add[] = ".SIG-ALG.REG.INT.";
73
key -> algorithm = dmalloc (strlen (algorithm) +
75
if (!key -> algorithm) {
76
omapi_auth_key_dereference (&key, MDL);
77
return ISC_R_NOMEMORY;
79
strcpy (key -> algorithm, algorithm);
80
strcat (key -> algorithm, add);
82
key -> algorithm = dmalloc (strlen (algorithm) + 1, MDL);
83
if (!key -> algorithm) {
84
omapi_auth_key_dereference (&key, MDL);
85
return ISC_R_NOMEMORY;
87
strcpy (key -> algorithm, algorithm);
90
status = omapi_data_string_new (&key -> key, secret_len, MDL);
91
if (status != ISC_R_SUCCESS) {
92
omapi_auth_key_dereference (&key, MDL);
95
memcpy (key -> key -> value, secret, secret_len);
96
key -> key -> len = secret_len;
98
*h = (dhcpctl_handle) key;
103
/* dhcpctl_new_object
105
synchronous - creates a local handle for a host entry.
106
returns nonzero status code if the local host entry couldn't
108
stores handle to host through h if successful, and returns zero.
109
object_type is a pointer to a NUL-terminated string containing
110
the ascii name of the type of object being accessed - e.g., "host" */
112
dhcpctl_status dhcpctl_new_object (dhcpctl_handle *h,
113
dhcpctl_handle connection,
114
const char *object_type)
116
dhcpctl_remote_object_t *m;
120
m = (dhcpctl_remote_object_t *)0;
121
status = omapi_object_allocate((omapi_object_t **)&m,
122
dhcpctl_remote_type, 0, MDL);
123
if (status != ISC_R_SUCCESS)
126
g = (omapi_object_t *)0;
127
status = omapi_generic_new (&g, MDL);
128
if (status != ISC_R_SUCCESS) {
132
status = omapi_object_reference (&m -> inner, g, MDL);
133
if (status != ISC_R_SUCCESS) {
134
omapi_object_dereference ((omapi_object_t **)&m, MDL);
135
omapi_object_dereference (&g, MDL);
138
status = omapi_object_reference (&g -> outer,
139
(omapi_object_t *)m, MDL);
141
if (status != ISC_R_SUCCESS) {
142
omapi_object_dereference ((omapi_object_t **)&m, MDL);
143
omapi_object_dereference (&g, MDL);
147
status = omapi_typed_data_new (MDL, &m -> rtype,
148
omapi_datatype_string,
150
if (status != ISC_R_SUCCESS) {
151
omapi_object_dereference ((omapi_object_t **)&m, MDL);
152
omapi_object_dereference (&g, MDL);
156
status = omapi_object_reference (h, (omapi_object_t *)m, MDL);
157
omapi_object_dereference ((omapi_object_t **)&m, MDL);
158
omapi_object_dereference (&g, MDL);
159
if (status != ISC_R_SUCCESS)
165
/* asynchronous - just queues the request
166
returns nonzero status code if open couldn't be queued
167
returns zero if open was queued
168
h is a handle to an object created by dhcpctl_new_object
169
connection is a connection to a DHCP server
171
DHCPCTL_CREATE - if the object doesn't exist, create it
172
DHCPCTL_UPDATE - update the object on the server using the
174
DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
175
was also specified */
177
dhcpctl_status dhcpctl_open_object (dhcpctl_handle h,
178
dhcpctl_handle connection,
182
omapi_object_t *message = (omapi_object_t *)0;
183
dhcpctl_remote_object_t *remote;
185
if (h -> type != dhcpctl_remote_type)
186
return ISC_R_INVALIDARG;
187
remote = (dhcpctl_remote_object_t *)h;
189
status = omapi_message_new (&message, MDL);
190
if (status != ISC_R_SUCCESS)
192
status = omapi_set_int_value (message, (omapi_object_t *)0,
193
"op", OMAPI_OP_OPEN);
194
if (status != ISC_R_SUCCESS) {
195
omapi_object_dereference (&message, MDL);
198
status = omapi_set_object_value (message, (omapi_object_t *)0,
200
if (status != ISC_R_SUCCESS) {
201
omapi_object_dereference (&message, MDL);
204
if (flags & DHCPCTL_CREATE) {
205
status = omapi_set_boolean_value (message, (omapi_object_t *)0,
207
if (status != ISC_R_SUCCESS) {
208
omapi_object_dereference (&message, MDL);
212
if (flags & DHCPCTL_UPDATE) {
213
status = omapi_set_boolean_value (message, (omapi_object_t *)0,
215
if (status != ISC_R_SUCCESS) {
216
omapi_object_dereference (&message, MDL);
220
if (flags & DHCPCTL_EXCL) {
221
status = omapi_set_boolean_value (message, (omapi_object_t *)0,
223
if (status != ISC_R_SUCCESS) {
224
omapi_object_dereference (&message, MDL);
229
if (remote -> rtype) {
230
status = omapi_set_value_str (message, (omapi_object_t *)0,
231
"type", remote -> rtype);
232
if (status != ISC_R_SUCCESS) {
233
omapi_object_dereference (&message, MDL);
238
status = omapi_message_register (message);
239
if (status != ISC_R_SUCCESS) {
240
omapi_object_dereference (&message, MDL);
244
status = omapi_protocol_send_message (connection -> outer,
246
message, (omapi_object_t *)0);
248
if (status != ISC_R_SUCCESS)
249
omapi_message_unregister (message);
251
omapi_object_dereference (&message, MDL);
255
/* Callback methods (not meant to be called directly) */
257
isc_result_t dhcpctl_remote_set_value (omapi_object_t *h,
259
omapi_data_string_t *name,
260
omapi_typed_data_t *value)
262
dhcpctl_remote_object_t *ro;
266
if (h -> type != dhcpctl_remote_type)
267
return ISC_R_INVALIDARG;
268
ro = (dhcpctl_remote_object_t *)h;
270
if (!omapi_ds_strcmp (name, "remote-handle")) {
271
status = omapi_get_int_value (&rh, value);
272
if (status == ISC_R_SUCCESS)
273
ro -> remote_handle = rh;
277
if (h -> inner && h -> inner -> type -> set_value)
278
return (*(h -> inner -> type -> set_value))
279
(h -> inner, id, name, value);
280
return ISC_R_NOTFOUND;
283
isc_result_t dhcpctl_remote_get_value (omapi_object_t *h,
285
omapi_data_string_t *name,
286
omapi_value_t **value)
288
if (h -> type != dhcpctl_remote_type)
289
return ISC_R_INVALIDARG;
291
if (h -> inner && h -> inner -> type -> get_value)
292
return (*(h -> inner -> type -> get_value))
293
(h -> inner, id, name, value);
294
return ISC_R_NOTFOUND;
297
isc_result_t dhcpctl_remote_signal_handler (omapi_object_t *o,
298
const char *name, va_list ap)
300
dhcpctl_remote_object_t *p;
301
omapi_typed_data_t *tv;
303
if (o -> type != dhcpctl_remote_type)
304
return ISC_R_INVALIDARG;
305
p = (dhcpctl_remote_object_t *)o;
307
if (!strcmp (name, "updated")) {
308
p -> waitstatus = ISC_R_SUCCESS;
309
if (o -> inner -> type == omapi_type_generic)
310
omapi_generic_clear_flags (o -> inner);
311
return omapi_signal_in (o -> inner, "ready");
313
if (!strcmp (name, "status")) {
314
p -> waitstatus = va_arg (ap, isc_result_t);
316
omapi_typed_data_dereference (&p -> message, MDL);
317
tv = va_arg (ap, omapi_typed_data_t *);
319
omapi_typed_data_reference (&p -> message, tv, MDL);
320
return omapi_signal_in (o -> inner, "ready");
323
if (p -> inner && p -> inner -> type -> signal_handler)
324
return (*(p -> inner -> type -> signal_handler))
325
(p -> inner, name, ap);
327
return ISC_R_SUCCESS;
330
isc_result_t dhcpctl_remote_destroy (omapi_object_t *h,
331
const char *file, int line)
333
dhcpctl_remote_object_t *p;
334
if (h -> type != dhcpctl_remote_type)
335
return ISC_R_INVALIDARG;
336
p = (dhcpctl_remote_object_t *)h;
338
omapi_object_dereference ((omapi_object_t **)&p -> handle,
341
omapi_typed_data_dereference ((omapi_typed_data_t **)&p->rtype,
343
return ISC_R_SUCCESS;
346
/* Write all the published values associated with the object through the
347
specified connection. */
349
isc_result_t dhcpctl_remote_stuff_values (omapi_object_t *c,
353
if (p -> type != dhcpctl_remote_type)
354
return ISC_R_INVALIDARG;
356
if (p -> inner && p -> inner -> type -> stuff_values)
357
return (*(p -> inner -> type -> stuff_values)) (c, id,
359
return ISC_R_SUCCESS;