]> git.ipfire.org Git - thirdparty/dhcp.git/blame - dhcpctl/remote.c
- Replaced ./configure shellscripting with GNU Autoconf. [ISC-Bugs #16405b]
[thirdparty/dhcp.git] / dhcpctl / remote.c
CommitLineData
fe4ab6d6
TL
1/* remote.c
2
3 The dhcpctl remote object. */
4
5/*
98311e4b
DH
6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1999-2003 by Internet Software Consortium
fe4ab6d6 8 *
98311e4b
DH
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.
fe4ab6d6 12 *
98311e4b
DH
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.
fe4ab6d6 20 *
98311e4b
DH
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
25 * http://www.isc.org/
49733f31 26 *
98311e4b 27 * This software has been written for Internet Systems Consortium
49733f31 28 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
98311e4b 29 * To learn more about Internet Systems Consortium, see
49733f31
TL
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''.
fe4ab6d6
TL
33 */
34
98311e4b
DH
35#ifndef lint
36static char copyright[] =
fe5b0fdd 37"$Id: remote.c,v 1.15 2007/05/19 18:47:14 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
98311e4b
DH
38#endif /* not lint */
39
fe5b0fdd 40#include "dhcpd.h"
6a4c4be8 41#include <omapip/omapip_p.h>
fe4ab6d6
TL
42#include "dhcpctl.h"
43
49146f3c
DN
44/* dhcpctl_new_authenticator
45
46 synchronous - creates an authenticator object.
47 returns nonzero status code if the object couldn't be created
48 stores handle to authenticator through h if successful, and returns zero.
49 name is the authenticator name (NUL-terminated string).
50 algorithm is the NUL-terminated string name of the algorithm to use
51 (currently, only "hmac-md5" is supported).
52 secret and secret_len is the key secret. */
53
54dhcpctl_status dhcpctl_new_authenticator (dhcpctl_handle *h,
55 const char *name,
56 const char *algorithm,
6ad8c39d 57 const unsigned char *secret,
49146f3c
DN
58 unsigned secret_len)
59{
60 struct auth_key *key = (struct auth_key *)0;
61 isc_result_t status;
62
63 status = omapi_auth_key_new (&key, MDL);
64 if (status != ISC_R_SUCCESS)
65 return status;
66
67 key -> name = dmalloc (strlen (name) + 1, MDL);
68 if (!key -> name) {
69 omapi_auth_key_dereference (&key, MDL);
70 return ISC_R_NOMEMORY;
71 }
72 strcpy (key -> name, name);
73
8c3c6552
DN
74 /* If the algorithm name isn't an FQDN, tack on the
75 .SIG-ALG.REG.NET. domain. */
76 if (strchr (algorithm, '.') == 0) {
77 static char add[] = ".SIG-ALG.REG.INT.";
78 key -> algorithm = dmalloc (strlen (algorithm) +
79 sizeof (add), MDL);
80 if (!key -> algorithm) {
81 omapi_auth_key_dereference (&key, MDL);
82 return ISC_R_NOMEMORY;
83 }
84 strcpy (key -> algorithm, algorithm);
85 strcat (key -> algorithm, add);
86 } else {
87 key -> algorithm = dmalloc (strlen (algorithm) + 1, MDL);
88 if (!key -> algorithm) {
89 omapi_auth_key_dereference (&key, MDL);
90 return ISC_R_NOMEMORY;
91 }
92 strcpy (key -> algorithm, algorithm);
49146f3c 93 }
49146f3c
DN
94
95 status = omapi_data_string_new (&key -> key, secret_len, MDL);
96 if (status != ISC_R_SUCCESS) {
97 omapi_auth_key_dereference (&key, MDL);
98 return status;
99 }
100 memcpy (key -> key -> value, secret, secret_len);
101 key -> key -> len = secret_len;
102
103 *h = (dhcpctl_handle) key;
104 return ISC_R_SUCCESS;
105}
106
107
fe4ab6d6
TL
108/* dhcpctl_new_object
109
110 synchronous - creates a local handle for a host entry.
111 returns nonzero status code if the local host entry couldn't
112 be created
113 stores handle to host through h if successful, and returns zero.
114 object_type is a pointer to a NUL-terminated string containing
115 the ascii name of the type of object being accessed - e.g., "host" */
116
117dhcpctl_status dhcpctl_new_object (dhcpctl_handle *h,
118 dhcpctl_handle connection,
b1b7b521 119 const char *object_type)
fe4ab6d6
TL
120{
121 dhcpctl_remote_object_t *m;
122 omapi_object_t *g;
123 isc_result_t status;
124
eadee396
TL
125 m = (dhcpctl_remote_object_t *)0;
126 status = omapi_object_allocate ((omapi_object_t **)&m,
127 dhcpctl_remote_type, 0, MDL);
128 if (status != ISC_R_SUCCESS)
129 return status;
fe4ab6d6
TL
130
131 g = (omapi_object_t *)0;
4bd8800e 132 status = omapi_generic_new (&g, MDL);
fe4ab6d6 133 if (status != ISC_R_SUCCESS) {
4bd8800e 134 dfree (m, MDL);
fe4ab6d6
TL
135 return status;
136 }
4bd8800e 137 status = omapi_object_reference (&m -> inner, g, MDL);
fe4ab6d6 138 if (status != ISC_R_SUCCESS) {
4bd8800e
TL
139 omapi_object_dereference ((omapi_object_t **)&m, MDL);
140 omapi_object_dereference (&g, MDL);
fe4ab6d6
TL
141 return status;
142 }
143 status = omapi_object_reference (&g -> outer,
4bd8800e 144 (omapi_object_t *)m, MDL);
fe4ab6d6
TL
145
146 if (status != ISC_R_SUCCESS) {
4bd8800e
TL
147 omapi_object_dereference ((omapi_object_t **)&m, MDL);
148 omapi_object_dereference (&g, MDL);
fe4ab6d6
TL
149 return status;
150 }
151
4bd8800e 152 status = omapi_typed_data_new (MDL, &m -> rtype,
fe4ab6d6 153 omapi_datatype_string,
4bd8800e 154 object_type);
fe4ab6d6 155 if (status != ISC_R_SUCCESS) {
4bd8800e
TL
156 omapi_object_dereference ((omapi_object_t **)&m, MDL);
157 omapi_object_dereference (&g, MDL);
fe4ab6d6
TL
158 return status;
159 }
160
4bd8800e
TL
161 status = omapi_object_reference (h, (omapi_object_t *)m, MDL);
162 omapi_object_dereference ((omapi_object_t **)&m, MDL);
163 omapi_object_dereference (&g, MDL);
fe4ab6d6
TL
164 if (status != ISC_R_SUCCESS)
165 return status;
166
167 return status;
168}
169
170/* asynchronous - just queues the request
171 returns nonzero status code if open couldn't be queued
172 returns zero if open was queued
173 h is a handle to an object created by dhcpctl_new_object
174 connection is a connection to a DHCP server
175 flags include:
176 DHCPCTL_CREATE - if the object doesn't exist, create it
177 DHCPCTL_UPDATE - update the object on the server using the
178 attached parameters
179 DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
180 was also specified */
181
182dhcpctl_status dhcpctl_open_object (dhcpctl_handle h,
183 dhcpctl_handle connection,
184 int flags)
185{
186 isc_result_t status;
187 omapi_object_t *message = (omapi_object_t *)0;
188 dhcpctl_remote_object_t *remote;
189
190 if (h -> type != dhcpctl_remote_type)
191 return ISC_R_INVALIDARG;
192 remote = (dhcpctl_remote_object_t *)h;
193
4bd8800e 194 status = omapi_message_new (&message, MDL);
fe4ab6d6
TL
195 if (status != ISC_R_SUCCESS)
196 return status;
197 status = omapi_set_int_value (message, (omapi_object_t *)0,
198 "op", OMAPI_OP_OPEN);
199 if (status != ISC_R_SUCCESS) {
4bd8800e 200 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
201 return status;
202 }
203 status = omapi_set_object_value (message, (omapi_object_t *)0,
204 "object", h);
205 if (status != ISC_R_SUCCESS) {
4bd8800e 206 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
207 return status;
208 }
209 if (flags & DHCPCTL_CREATE) {
210 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
211 "create", 1);
212 if (status != ISC_R_SUCCESS) {
4bd8800e 213 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
214 return status;
215 }
216 }
217 if (flags & DHCPCTL_UPDATE) {
218 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
219 "update", 1);
220 if (status != ISC_R_SUCCESS) {
4bd8800e 221 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
222 return status;
223 }
224 }
225 if (flags & DHCPCTL_EXCL) {
226 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
227 "exclusive", 1);
228 if (status != ISC_R_SUCCESS) {
4bd8800e 229 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
230 return status;
231 }
232 }
233
234 if (remote -> rtype) {
235 status = omapi_set_value_str (message, (omapi_object_t *)0,
236 "type", remote -> rtype);
237 if (status != ISC_R_SUCCESS) {
4bd8800e 238 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
239 return status;
240 }
241 }
242
243 status = omapi_message_register (message);
244 if (status != ISC_R_SUCCESS) {
4bd8800e 245 omapi_object_dereference (&message, MDL);
fe4ab6d6
TL
246 return status;
247 }
98311e4b
DH
248
249 status = omapi_protocol_send_message (connection -> outer,
fe4ab6d6
TL
250 (omapi_object_t *)0,
251 message, (omapi_object_t *)0);
98311e4b
DH
252
253 if (status != ISC_R_SUCCESS)
254 omapi_message_unregister (message);
255
256 omapi_object_dereference (&message, MDL);
257 return status;
fe4ab6d6
TL
258}
259
260/* Callback methods (not meant to be called directly) */
261
262isc_result_t dhcpctl_remote_set_value (omapi_object_t *h,
263 omapi_object_t *id,
264 omapi_data_string_t *name,
265 omapi_typed_data_t *value)
266{
f5423ffa 267 dhcpctl_remote_object_t *ro;
013be24d
TL
268 unsigned long rh;
269 isc_result_t status;
270
fe4ab6d6
TL
271 if (h -> type != dhcpctl_remote_type)
272 return ISC_R_INVALIDARG;
f5423ffa
TL
273 ro = (dhcpctl_remote_object_t *)h;
274
275 if (!omapi_ds_strcmp (name, "remote-handle")) {
013be24d
TL
276 status = omapi_get_int_value (&rh, value);
277 if (status == ISC_R_SUCCESS)
278 ro -> remote_handle = rh;
279 return status;
f5423ffa 280 }
fe4ab6d6
TL
281
282 if (h -> inner && h -> inner -> type -> set_value)
283 return (*(h -> inner -> type -> set_value))
284 (h -> inner, id, name, value);
285 return ISC_R_NOTFOUND;
286}
287
288isc_result_t dhcpctl_remote_get_value (omapi_object_t *h,
289 omapi_object_t *id,
290 omapi_data_string_t *name,
291 omapi_value_t **value)
292{
293 if (h -> type != dhcpctl_remote_type)
294 return ISC_R_INVALIDARG;
295
296 if (h -> inner && h -> inner -> type -> get_value)
297 return (*(h -> inner -> type -> get_value))
298 (h -> inner, id, name, value);
299 return ISC_R_NOTFOUND;
300}
301
302isc_result_t dhcpctl_remote_signal_handler (omapi_object_t *o,
b1b7b521 303 const char *name, va_list ap)
fe4ab6d6
TL
304{
305 dhcpctl_remote_object_t *p;
306 omapi_typed_data_t *tv;
307
308 if (o -> type != dhcpctl_remote_type)
309 return ISC_R_INVALIDARG;
310 p = (dhcpctl_remote_object_t *)o;
311
312 if (!strcmp (name, "updated")) {
313 p -> waitstatus = ISC_R_SUCCESS;
d758ad8c
TL
314 if (o -> inner -> type == omapi_type_generic)
315 omapi_generic_clear_flags (o -> inner);
fe4ab6d6
TL
316 return omapi_signal_in (o -> inner, "ready");
317 }
318 if (!strcmp (name, "status")) {
319 p -> waitstatus = va_arg (ap, isc_result_t);
320 if (p -> message)
4bd8800e 321 omapi_typed_data_dereference (&p -> message, MDL);
fe4ab6d6
TL
322 tv = va_arg (ap, omapi_typed_data_t *);
323 if (tv)
4bd8800e 324 omapi_typed_data_reference (&p -> message, tv, MDL);
fe4ab6d6
TL
325 return omapi_signal_in (o -> inner, "ready");
326 }
327
328 if (p -> inner && p -> inner -> type -> signal_handler)
329 return (*(p -> inner -> type -> signal_handler))
330 (p -> inner, name, ap);
331
332 return ISC_R_SUCCESS;
333}
334
4bd8800e
TL
335isc_result_t dhcpctl_remote_destroy (omapi_object_t *h,
336 const char *file, int line)
fe4ab6d6
TL
337{
338 dhcpctl_remote_object_t *p;
339 if (h -> type != dhcpctl_remote_type)
340 return ISC_R_INVALIDARG;
341 p = (dhcpctl_remote_object_t *)h;
342 if (p -> handle)
343 omapi_object_dereference ((omapi_object_t **)&p -> handle,
4bd8800e 344 file, line);
98311e4b
DH
345 if (p -> rtype)
346 omapi_typed_data_dereference ((omapi_typed_data_t **)&p->rtype,
347 file, line);
fe4ab6d6
TL
348 return ISC_R_SUCCESS;
349}
350
351/* Write all the published values associated with the object through the
352 specified connection. */
353
354isc_result_t dhcpctl_remote_stuff_values (omapi_object_t *c,
355 omapi_object_t *id,
356 omapi_object_t *p)
357{
358 int i;
359
360 if (p -> type != dhcpctl_remote_type)
361 return ISC_R_INVALIDARG;
362
363 if (p -> inner && p -> inner -> type -> stuff_values)
364 return (*(p -> inner -> type -> stuff_values)) (c, id,
365 p -> inner);
366 return ISC_R_SUCCESS;
367}
368