3 The dhcpctl remote object. */
6 * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1999-2003 by Internet Software Consortium
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 * Newmarket, NH 03857 USA
25 * https://www.isc.org/
30 #include <omapip/omapip_p.h>
33 /* dhcpctl_new_authenticator
35 synchronous - creates an authenticator object.
36 returns nonzero status code if the object couldn't be created
37 stores handle to authenticator through h if successful, and returns zero.
38 name is the authenticator name (NUL-terminated string).
39 algorithm is the NUL-terminated string name of the algorithm to use
40 (currently, only "hmac-md5" is supported).
41 secret and secret_len is the key secret. */
43 dhcpctl_status
dhcpctl_new_authenticator (dhcpctl_handle
*h
,
45 const char *algorithm
,
46 const unsigned char *secret
,
49 struct auth_key
*key
= (struct auth_key
*)0;
52 status
= omapi_auth_key_new (&key
, MDL
);
53 if (status
!= ISC_R_SUCCESS
)
56 key
-> name
= dmalloc (strlen (name
) + 1, MDL
);
58 omapi_auth_key_dereference (&key
, MDL
);
59 return ISC_R_NOMEMORY
;
61 strcpy (key
-> name
, name
);
63 /* If the algorithm name isn't an FQDN, tack on the
64 .SIG-ALG.REG.NET. domain. */
65 if (strchr (algorithm
, '.') == 0) {
66 static char add
[] = ".SIG-ALG.REG.INT.";
67 key
-> algorithm
= dmalloc (strlen (algorithm
) +
69 if (!key
-> algorithm
) {
70 omapi_auth_key_dereference (&key
, MDL
);
71 return ISC_R_NOMEMORY
;
73 strcpy (key
-> algorithm
, algorithm
);
74 strcat (key
-> algorithm
, add
);
76 key
-> algorithm
= dmalloc (strlen (algorithm
) + 1, MDL
);
77 if (!key
-> algorithm
) {
78 omapi_auth_key_dereference (&key
, MDL
);
79 return ISC_R_NOMEMORY
;
81 strcpy (key
-> algorithm
, algorithm
);
84 status
= omapi_data_string_new (&key
-> key
, secret_len
, MDL
);
85 if (status
!= ISC_R_SUCCESS
) {
86 omapi_auth_key_dereference (&key
, MDL
);
89 memcpy (key
-> key
-> value
, secret
, secret_len
);
90 key
-> key
-> len
= secret_len
;
92 *h
= (dhcpctl_handle
) key
;
99 synchronous - creates a local handle for a host entry.
100 returns nonzero status code if the local host entry couldn't
102 stores handle to host through h if successful, and returns zero.
103 object_type is a pointer to a NUL-terminated string containing
104 the ascii name of the type of object being accessed - e.g., "host" */
106 dhcpctl_status
dhcpctl_new_object (dhcpctl_handle
*h
,
107 dhcpctl_handle connection
,
108 const char *object_type
)
110 dhcpctl_remote_object_t
*m
;
114 m
= (dhcpctl_remote_object_t
*)0;
115 status
= omapi_object_allocate((omapi_object_t
**)&m
,
116 dhcpctl_remote_type
, 0, MDL
);
117 if (status
!= ISC_R_SUCCESS
)
120 g
= (omapi_object_t
*)0;
121 status
= omapi_generic_new (&g
, MDL
);
122 if (status
!= ISC_R_SUCCESS
) {
126 status
= omapi_object_reference (&m
-> inner
, g
, MDL
);
127 if (status
!= ISC_R_SUCCESS
) {
128 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
129 omapi_object_dereference (&g
, MDL
);
132 status
= omapi_object_reference (&g
-> outer
,
133 (omapi_object_t
*)m
, MDL
);
135 if (status
!= ISC_R_SUCCESS
) {
136 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
137 omapi_object_dereference (&g
, MDL
);
141 status
= omapi_typed_data_new (MDL
, &m
-> rtype
,
142 omapi_datatype_string
,
144 if (status
!= ISC_R_SUCCESS
) {
145 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
146 omapi_object_dereference (&g
, MDL
);
150 status
= omapi_object_reference (h
, (omapi_object_t
*)m
, MDL
);
151 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
152 omapi_object_dereference (&g
, MDL
);
153 if (status
!= ISC_R_SUCCESS
)
159 /* asynchronous - just queues the request
160 returns nonzero status code if open couldn't be queued
161 returns zero if open was queued
162 h is a handle to an object created by dhcpctl_new_object
163 connection is a connection to a DHCP server
165 DHCPCTL_CREATE - if the object doesn't exist, create it
166 DHCPCTL_UPDATE - update the object on the server using the
168 DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
169 was also specified */
171 dhcpctl_status
dhcpctl_open_object (dhcpctl_handle h
,
172 dhcpctl_handle connection
,
176 omapi_object_t
*message
= (omapi_object_t
*)0;
177 dhcpctl_remote_object_t
*remote
;
179 if (h
-> type
!= dhcpctl_remote_type
)
180 return DHCP_R_INVALIDARG
;
181 remote
= (dhcpctl_remote_object_t
*)h
;
183 status
= omapi_message_new (&message
, MDL
);
184 if (status
!= ISC_R_SUCCESS
)
186 status
= omapi_set_int_value (message
, (omapi_object_t
*)0,
187 "op", OMAPI_OP_OPEN
);
188 if (status
!= ISC_R_SUCCESS
) {
189 omapi_object_dereference (&message
, MDL
);
192 status
= omapi_set_object_value (message
, (omapi_object_t
*)0,
194 if (status
!= ISC_R_SUCCESS
) {
195 omapi_object_dereference (&message
, MDL
);
198 if (flags
& DHCPCTL_CREATE
) {
199 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
201 if (status
!= ISC_R_SUCCESS
) {
202 omapi_object_dereference (&message
, MDL
);
206 if (flags
& DHCPCTL_UPDATE
) {
207 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
209 if (status
!= ISC_R_SUCCESS
) {
210 omapi_object_dereference (&message
, MDL
);
214 if (flags
& DHCPCTL_EXCL
) {
215 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
217 if (status
!= ISC_R_SUCCESS
) {
218 omapi_object_dereference (&message
, MDL
);
223 if (remote
-> rtype
) {
224 status
= omapi_set_value_str (message
, (omapi_object_t
*)0,
225 "type", remote
-> rtype
);
226 if (status
!= ISC_R_SUCCESS
) {
227 omapi_object_dereference (&message
, MDL
);
232 status
= omapi_message_register (message
);
233 if (status
!= ISC_R_SUCCESS
) {
234 omapi_object_dereference (&message
, MDL
);
238 status
= omapi_protocol_send_message (connection
-> outer
,
240 message
, (omapi_object_t
*)0);
242 if (status
!= ISC_R_SUCCESS
)
243 omapi_message_unregister (message
);
245 omapi_object_dereference (&message
, MDL
);
249 /* Callback methods (not meant to be called directly) */
251 isc_result_t
dhcpctl_remote_set_value (omapi_object_t
*h
,
253 omapi_data_string_t
*name
,
254 omapi_typed_data_t
*value
)
256 dhcpctl_remote_object_t
*ro
;
260 if (h
-> type
!= dhcpctl_remote_type
)
261 return DHCP_R_INVALIDARG
;
262 ro
= (dhcpctl_remote_object_t
*)h
;
264 if (!omapi_ds_strcmp (name
, "remote-handle")) {
265 status
= omapi_get_int_value (&rh
, value
);
266 if (status
== ISC_R_SUCCESS
)
267 ro
-> remote_handle
= rh
;
271 if (h
-> inner
&& h
-> inner
-> type
-> set_value
)
272 return (*(h
-> inner
-> type
-> set_value
))
273 (h
-> inner
, id
, name
, value
);
274 return ISC_R_NOTFOUND
;
277 isc_result_t
dhcpctl_remote_get_value (omapi_object_t
*h
,
279 omapi_data_string_t
*name
,
280 omapi_value_t
**value
)
282 if (h
-> type
!= dhcpctl_remote_type
)
283 return DHCP_R_INVALIDARG
;
285 if (h
-> inner
&& h
-> inner
-> type
-> get_value
)
286 return (*(h
-> inner
-> type
-> get_value
))
287 (h
-> inner
, id
, name
, value
);
288 return ISC_R_NOTFOUND
;
291 isc_result_t
dhcpctl_remote_signal_handler (omapi_object_t
*o
,
292 const char *name
, va_list ap
)
294 dhcpctl_remote_object_t
*p
;
295 omapi_typed_data_t
*tv
;
297 if (o
-> type
!= dhcpctl_remote_type
)
298 return DHCP_R_INVALIDARG
;
299 p
= (dhcpctl_remote_object_t
*)o
;
301 if (!strcmp (name
, "updated")) {
302 p
-> waitstatus
= ISC_R_SUCCESS
;
303 if (o
-> inner
-> type
== omapi_type_generic
)
304 omapi_generic_clear_flags (o
-> inner
);
305 return omapi_signal_in (o
-> inner
, "ready");
307 if (!strcmp (name
, "status")) {
308 p
-> waitstatus
= va_arg (ap
, isc_result_t
);
310 omapi_typed_data_dereference (&p
-> message
, MDL
);
311 tv
= va_arg (ap
, omapi_typed_data_t
*);
313 omapi_typed_data_reference (&p
-> message
, tv
, MDL
);
314 return omapi_signal_in (o
-> inner
, "ready");
317 if (p
-> inner
&& p
-> inner
-> type
-> signal_handler
)
318 return (*(p
-> inner
-> type
-> signal_handler
))
319 (p
-> inner
, name
, ap
);
321 return ISC_R_SUCCESS
;
324 isc_result_t
dhcpctl_remote_destroy (omapi_object_t
*h
,
325 const char *file
, int line
)
327 dhcpctl_remote_object_t
*p
;
328 if (h
-> type
!= dhcpctl_remote_type
)
329 return DHCP_R_INVALIDARG
;
330 p
= (dhcpctl_remote_object_t
*)h
;
332 omapi_object_dereference ((omapi_object_t
**)&p
-> handle
,
335 omapi_typed_data_dereference ((omapi_typed_data_t
**)&p
->rtype
,
337 return ISC_R_SUCCESS
;
340 /* Write all the published values associated with the object through the
341 specified connection. */
343 isc_result_t
dhcpctl_remote_stuff_values (omapi_object_t
*c
,
347 if (p
-> type
!= dhcpctl_remote_type
)
348 return DHCP_R_INVALIDARG
;
350 if (p
-> inner
&& p
-> inner
-> type
-> stuff_values
)
351 return (*(p
-> inner
-> type
-> stuff_values
)) (c
, id
,
353 return ISC_R_SUCCESS
;