1999-09-08 01:36:05 +00:00
|
|
|
/* omapi.c
|
|
|
|
|
|
|
|
OMAPI object interfaces for the DHCP server. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996-1999 Internet Software Consortium.
|
|
|
|
* Use is subject to license terms which appear in the file named
|
|
|
|
* ISC-LICENSE that should have accompanied this file when you
|
|
|
|
* received it. If a file named ISC-LICENSE did not accompany this
|
|
|
|
* file, or you are not sure the one you have is correct, you may
|
|
|
|
* obtain an applicable copy of the license at:
|
|
|
|
*
|
|
|
|
* http://www.isc.org/isc-license-1.0.html.
|
|
|
|
*
|
|
|
|
* This file is part of the ISC DHCP distribution. The documentation
|
|
|
|
* associated with this file is listed in the file DOCUMENTATION,
|
|
|
|
* included in the top-level directory of this release.
|
|
|
|
*
|
|
|
|
* Support and other services are available for ISC products - see
|
|
|
|
* http://www.isc.org for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Many, many thanks to Brian Murrell and BCtel for this code - BCtel
|
|
|
|
provided the funding that resulted in this code and the entire
|
|
|
|
OMAPI support library being written, and Brian helped brainstorm
|
|
|
|
and refine the requirements. To the extent that this code is
|
|
|
|
useful, you have Brian and BCtel to thank. Any limitations in the
|
|
|
|
code are a result of mistakes on my part. -- Ted Lemon */
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char copyright[] =
|
2000-01-08 01:49:36 +00:00
|
|
|
"$Id: omapi.c,v 1.24 2000/01/08 01:49:36 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
1999-09-08 01:36:05 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "dhcpd.h"
|
1999-10-08 03:43:15 +00:00
|
|
|
#include <omapip/omapip_p.h>
|
1999-09-08 01:36:05 +00:00
|
|
|
|
|
|
|
omapi_object_type_t *dhcp_type_lease;
|
|
|
|
omapi_object_type_t *dhcp_type_group;
|
|
|
|
omapi_object_type_t *dhcp_type_pool;
|
|
|
|
omapi_object_type_t *dhcp_type_shared_network;
|
|
|
|
omapi_object_type_t *dhcp_type_subnet;
|
|
|
|
omapi_object_type_t *dhcp_type_class;
|
1999-11-20 18:36:32 +00:00
|
|
|
#if defined (FAILOVER_PROTOCOL)
|
1999-11-14 00:39:33 +00:00
|
|
|
omapi_object_type_t *dhcp_type_failover_state;
|
|
|
|
omapi_object_type_t *dhcp_type_failover_link;
|
|
|
|
omapi_object_type_t *dhcp_type_failover_listener;
|
1999-11-20 18:36:32 +00:00
|
|
|
#endif
|
1999-09-08 01:36:05 +00:00
|
|
|
|
|
|
|
void dhcp_db_objects_setup ()
|
|
|
|
{
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
status = omapi_object_type_register (&dhcp_type_lease,
|
|
|
|
"lease",
|
|
|
|
dhcp_lease_set_value,
|
|
|
|
dhcp_lease_get_value,
|
|
|
|
dhcp_lease_destroy,
|
|
|
|
dhcp_lease_signal_handler,
|
|
|
|
dhcp_lease_stuff_values,
|
|
|
|
dhcp_lease_lookup,
|
1999-09-09 23:33:43 +00:00
|
|
|
dhcp_lease_create,
|
1999-09-16 04:53:38 +00:00
|
|
|
dhcp_lease_remove);
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
log_fatal ("Can't register lease object type: %s",
|
|
|
|
isc_result_totext (status));
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
status = omapi_object_type_register (&dhcp_type_group,
|
|
|
|
"group",
|
|
|
|
dhcp_group_set_value,
|
|
|
|
dhcp_group_get_value,
|
|
|
|
dhcp_group_destroy,
|
|
|
|
dhcp_group_signal_handler,
|
|
|
|
dhcp_group_stuff_values,
|
|
|
|
dhcp_group_lookup,
|
|
|
|
dhcp_group_create,
|
|
|
|
dhcp_group_remove);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
log_fatal ("Can't register group object type: %s",
|
|
|
|
isc_result_totext (status));
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
status = omapi_object_type_register (&dhcp_type_host,
|
|
|
|
"host",
|
|
|
|
dhcp_host_set_value,
|
|
|
|
dhcp_host_get_value,
|
|
|
|
dhcp_host_destroy,
|
|
|
|
dhcp_host_signal_handler,
|
|
|
|
dhcp_host_stuff_values,
|
|
|
|
dhcp_host_lookup,
|
1999-09-09 23:33:43 +00:00
|
|
|
dhcp_host_create,
|
1999-09-16 04:53:38 +00:00
|
|
|
dhcp_host_remove);
|
1999-09-29 00:00:35 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
1999-09-08 01:36:05 +00:00
|
|
|
log_fatal ("Can't register host object type: %s",
|
|
|
|
isc_result_totext (status));
|
|
|
|
|
|
|
|
status = omapi_object_type_register (&dhcp_type_pool,
|
|
|
|
"pool",
|
|
|
|
dhcp_pool_set_value,
|
|
|
|
dhcp_pool_get_value,
|
|
|
|
dhcp_pool_destroy,
|
|
|
|
dhcp_pool_signal_handler,
|
|
|
|
dhcp_pool_stuff_values,
|
|
|
|
dhcp_pool_lookup,
|
1999-09-09 23:33:43 +00:00
|
|
|
dhcp_pool_create,
|
1999-09-16 04:53:38 +00:00
|
|
|
dhcp_pool_remove);
|
1999-11-14 00:39:33 +00:00
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
log_fatal ("Can't register pool object type: %s",
|
|
|
|
isc_result_totext (status));
|
1999-11-14 00:39:33 +00:00
|
|
|
|
|
|
|
#if defined (FAILOVER_PROTOCOL)
|
|
|
|
status = omapi_object_type_register (&dhcp_type_failover_state,
|
|
|
|
"failover-state",
|
|
|
|
dhcp_failover_state_set_value,
|
|
|
|
dhcp_failover_state_get_value,
|
|
|
|
dhcp_failover_state_destroy,
|
|
|
|
dhcp_failover_state_signal,
|
1999-11-23 22:24:31 +00:00
|
|
|
dhcp_failover_state_stuff,
|
1999-11-14 00:39:33 +00:00
|
|
|
dhcp_failover_state_lookup,
|
|
|
|
dhcp_failover_state_create,
|
|
|
|
dhcp_failover_state_remove);
|
|
|
|
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
log_fatal ("Can't register failover state object type: %s",
|
|
|
|
isc_result_totext (status));
|
|
|
|
|
|
|
|
status = omapi_object_type_register (&dhcp_type_failover_link,
|
|
|
|
"failover-link",
|
|
|
|
dhcp_failover_link_set_value,
|
|
|
|
dhcp_failover_link_get_value,
|
|
|
|
dhcp_failover_link_destroy,
|
|
|
|
dhcp_failover_link_signal,
|
1999-11-23 22:24:31 +00:00
|
|
|
dhcp_failover_link_stuff_values,
|
1999-11-14 00:39:33 +00:00
|
|
|
0, 0, 0);
|
|
|
|
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
log_fatal ("Can't register failover link object type: %s",
|
|
|
|
isc_result_totext (status));
|
|
|
|
|
|
|
|
status = omapi_object_type_register (&dhcp_type_failover_listener,
|
|
|
|
"failover-listener",
|
|
|
|
dhcp_failover_listener_set_value,
|
|
|
|
dhcp_failover_listener_get_value,
|
|
|
|
dhcp_failover_listener_destroy,
|
|
|
|
dhcp_failover_listener_signal,
|
|
|
|
dhcp_failover_listener_stuff,
|
|
|
|
0, 0, 0);
|
|
|
|
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
log_fatal ("Can't register failover listener object type: %s",
|
|
|
|
isc_result_totext (status));
|
|
|
|
#endif /* FAILOVER_PROTOCOL */
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_lease_set_value (omapi_object_t *h,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_typed_data_t *value)
|
|
|
|
{
|
|
|
|
struct lease *lease;
|
|
|
|
isc_result_t status;
|
|
|
|
int foo;
|
|
|
|
|
1999-09-09 21:12:12 +00:00
|
|
|
if (h -> type != dhcp_type_lease)
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
lease = (struct lease *)h;
|
|
|
|
|
|
|
|
/* We're skipping a lot of things it might be interesting to
|
|
|
|
set - for now, we just make it possible to whack the abandoned
|
|
|
|
flag. */
|
|
|
|
if (!omapi_ds_strcmp (name, "abandoned")) {
|
|
|
|
int bar;
|
|
|
|
|
|
|
|
if (value -> type == omapi_datatype_int)
|
|
|
|
bar = value -> u.integer;
|
|
|
|
else if (value -> type == omapi_datatype_data &&
|
|
|
|
value -> u.buffer.len == sizeof (int)) {
|
|
|
|
memcpy (&bar, value -> u.buffer.value, sizeof bar);
|
|
|
|
/* No need to byte-swap here. */
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
foo = lease -> flags;
|
|
|
|
if (bar)
|
|
|
|
lease -> flags |= ABANDONED_LEASE;
|
|
|
|
else
|
|
|
|
lease -> flags &= ~ABANDONED_LEASE;
|
|
|
|
if (foo != lease -> flags)
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
return ISC_R_UNCHANGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> set_value) {
|
|
|
|
status = ((*(h -> inner -> type -> set_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t dhcp_lease_get_value (omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
|
|
|
{
|
|
|
|
struct lease *lease;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_lease)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
lease = (struct lease *)h;
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "abandoned"))
|
|
|
|
return omapi_make_int_value (value, name,
|
|
|
|
(lease -> flags &
|
|
|
|
ABANDONED_LEASE) ? 1 : 0,
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
else if (!omapi_ds_strcmp (name, "bootpp"))
|
|
|
|
return omapi_make_int_value (value, name,
|
|
|
|
(lease -> flags &
|
|
|
|
BOOTP_LEASE) ? 1 : 0,
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
else if (!omapi_ds_strcmp (name, "ip-address"))
|
|
|
|
return omapi_make_const_value (value, name,
|
|
|
|
lease -> ip_addr.iabuf,
|
|
|
|
lease -> ip_addr.len,
|
|
|
|
"dhcp_lease_get_value");
|
1999-10-14 18:30:52 +00:00
|
|
|
else if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
|
1999-09-08 01:36:05 +00:00
|
|
|
return omapi_make_const_value (value, name,
|
|
|
|
lease -> uid,
|
|
|
|
lease -> uid_len,
|
|
|
|
"dhcp_lease_get_value");
|
1999-10-14 18:30:52 +00:00
|
|
|
} else if (!omapi_ds_strcmp (name, "hostname")) {
|
|
|
|
if (lease -> hostname)
|
|
|
|
return omapi_make_string_value
|
|
|
|
(value, name, lease -> hostname,
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
} else if (!omapi_ds_strcmp (name, "client-hostname")) {
|
|
|
|
if (lease -> client_hostname)
|
|
|
|
return omapi_make_string_value
|
|
|
|
(value, name, lease -> client_hostname,
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
} else if (!omapi_ds_strcmp (name, "host")) {
|
|
|
|
if (lease -> host)
|
|
|
|
return omapi_make_handle_value
|
|
|
|
(value, name,
|
|
|
|
((omapi_object_t *)lease -> host),
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
} else if (!omapi_ds_strcmp (name, "subnet"))
|
1999-09-08 01:36:05 +00:00
|
|
|
return omapi_make_handle_value (value, name,
|
|
|
|
((omapi_object_t *)
|
|
|
|
lease -> subnet),
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
else if (!omapi_ds_strcmp (name, "pool"))
|
|
|
|
return omapi_make_handle_value (value, name,
|
|
|
|
((omapi_object_t *)
|
|
|
|
lease -> pool),
|
|
|
|
"dhcp_lease_get_value");
|
1999-10-14 18:30:52 +00:00
|
|
|
else if (!omapi_ds_strcmp (name, "billing-class")) {
|
|
|
|
if (lease -> billing_class)
|
|
|
|
return omapi_make_handle_value
|
|
|
|
(value, name,
|
|
|
|
((omapi_object_t *)lease -> billing_class),
|
|
|
|
"dhcp_lease_get_value");
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
} else if (!omapi_ds_strcmp (name, "hardware-address"))
|
2000-01-05 18:22:58 +00:00
|
|
|
return omapi_make_const_value
|
|
|
|
(value, name, &lease -> hardware_addr.hbuf [1],
|
|
|
|
(unsigned)(lease -> hardware_addr.hlen - 1),
|
|
|
|
"dhcp_lease_get_value");
|
1999-09-08 01:36:05 +00:00
|
|
|
else if (!omapi_ds_strcmp (name, "hardware-type"))
|
|
|
|
return omapi_make_int_value (value, name,
|
2000-01-05 18:22:58 +00:00
|
|
|
lease -> hardware_addr.hbuf [0],
|
1999-09-08 01:36:05 +00:00
|
|
|
"dhcp_lease_get_value");
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> get_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
1999-10-07 06:36:35 +00:00
|
|
|
isc_result_t dhcp_lease_destroy (omapi_object_t *h, const char *name)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct lease *lease;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_lease)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
lease = (struct lease *)h;
|
|
|
|
|
|
|
|
uid_hash_delete (lease);
|
|
|
|
hw_hash_delete (lease);
|
|
|
|
if (lease -> billing_class)
|
|
|
|
omapi_object_dereference
|
|
|
|
((omapi_object_t **)&lease -> billing_class, name);
|
|
|
|
if (lease -> uid && lease -> uid != &lease -> uid_buf [0]) {
|
|
|
|
free (lease -> uid);
|
|
|
|
lease -> uid = &lease -> uid_buf [0];
|
|
|
|
lease -> uid_len = 0;
|
|
|
|
}
|
|
|
|
if (lease -> hostname) {
|
|
|
|
free (lease -> hostname);
|
|
|
|
lease -> hostname = (char *)0;
|
|
|
|
}
|
|
|
|
if (lease -> client_hostname) {
|
|
|
|
free (lease -> client_hostname);
|
|
|
|
lease -> hostname = (char *)0;
|
|
|
|
}
|
|
|
|
if (lease -> host)
|
|
|
|
omapi_object_dereference ((omapi_object_t **)&lease -> host,
|
|
|
|
name);
|
|
|
|
if (lease -> subnet)
|
|
|
|
omapi_object_dereference ((omapi_object_t **)&lease -> subnet,
|
|
|
|
name);
|
|
|
|
if (lease -> pool)
|
|
|
|
omapi_object_dereference ((omapi_object_t **)&lease -> pool,
|
|
|
|
name);
|
|
|
|
if (lease -> on_expiry)
|
|
|
|
executable_statement_dereference (&lease -> on_expiry, name);
|
|
|
|
if (lease -> on_commit)
|
|
|
|
executable_statement_dereference (&lease -> on_commit, name);
|
|
|
|
if (lease -> on_release)
|
|
|
|
executable_statement_dereference (&lease -> on_release, name);
|
|
|
|
if (lease -> state) {
|
|
|
|
data_string_forget (&lease -> state -> parameter_request_list,
|
|
|
|
name);
|
|
|
|
free_lease_state (lease -> state, name);
|
|
|
|
lease -> state = (struct lease_state *)0;
|
|
|
|
|
|
|
|
cancel_timeout (lease_ping_timeout, lease);
|
|
|
|
--outstanding_pings; /* XXX */
|
|
|
|
}
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_lease_signal_handler (omapi_object_t *h,
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *name, va_list ap)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct lease *lease;
|
|
|
|
isc_result_t status;
|
1999-09-29 00:00:35 +00:00
|
|
|
int updatep = 0;
|
1999-09-08 01:36:05 +00:00
|
|
|
|
|
|
|
if (h -> type != dhcp_type_lease)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
lease = (struct lease *)h;
|
|
|
|
|
|
|
|
if (!strcmp (name, "updated")) {
|
1999-09-16 05:12:38 +00:00
|
|
|
if (lease -> hardware_addr.hlen == 0 ||
|
2000-01-05 18:22:58 +00:00
|
|
|
lease -> hardware_addr.hlen > 17)
|
1999-09-16 05:12:38 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
1999-10-01 03:27:37 +00:00
|
|
|
if (!write_lease (lease) || !commit_leases ()) {
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_IOERROR;
|
1999-10-01 03:27:37 +00:00
|
|
|
}
|
1999-09-29 00:00:35 +00:00
|
|
|
updatep = 1;
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> signal_handler))
|
|
|
|
(h -> inner, name, ap));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
1999-09-29 00:00:35 +00:00
|
|
|
if (updatep)
|
|
|
|
return ISC_R_SUCCESS;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_lease_stuff_values (omapi_object_t *c,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_object_t *h)
|
|
|
|
{
|
|
|
|
struct lease *lease;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_lease)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
lease = (struct lease *)h;
|
|
|
|
|
|
|
|
/* Write out all the values. */
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "abandoned");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, sizeof (int));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, (lease -> flags &
|
1999-10-07 06:36:35 +00:00
|
|
|
ABANDONED_LEASE) ? 1U : 0U);
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "bootpp");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, sizeof (int));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-10-07 06:36:35 +00:00
|
|
|
status = omapi_connection_put_uint32 (c, ((unsigned)
|
|
|
|
((lease -> flags &
|
|
|
|
BOOTP_LEASE) ? 1 : 0)));
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "ip-address");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, lease -> ip_addr.len);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_copyin (c, lease -> ip_addr.iabuf,
|
|
|
|
lease -> ip_addr.len);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "dhcp-client-identifier");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, lease -> uid_len);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
if (lease -> uid_len) {
|
|
|
|
status = omapi_connection_copyin (c, lease -> uid,
|
|
|
|
lease -> uid_len);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "hostname");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_string (c, lease -> hostname);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "client-hostname");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_string (c, lease -> client_hostname);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "host");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_handle (c,
|
|
|
|
(omapi_object_t *)lease -> host);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "subnet");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_handle
|
|
|
|
(c, (omapi_object_t *)lease -> subnet);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "pool");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_handle (c,
|
|
|
|
(omapi_object_t *)lease -> pool);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "billing-class");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_handle
|
|
|
|
(c, (omapi_object_t *)lease -> billing_class);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "hardware-address");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
2000-01-05 18:22:58 +00:00
|
|
|
status = (omapi_connection_put_uint32
|
|
|
|
(c, (unsigned long)(lease -> hardware_addr.hlen - 1)));
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
2000-01-05 18:22:58 +00:00
|
|
|
status = (omapi_connection_copyin
|
|
|
|
(c, &lease -> hardware_addr.hbuf [1],
|
|
|
|
(unsigned long)(lease -> hardware_addr.hlen - 1)));
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "hardware-type");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, sizeof (int));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
2000-01-05 18:22:58 +00:00
|
|
|
status = omapi_connection_put_uint32 (c,
|
|
|
|
lease -> hardware_addr.hbuf [0]);
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
1999-10-15 12:34:18 +00:00
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "ends");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, sizeof (TIME));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = (omapi_connection_copyin
|
|
|
|
(c, (const unsigned char *)&(lease -> ends), sizeof(TIME)));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = omapi_connection_put_name (c, "starts");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, sizeof (TIME));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = (omapi_connection_copyin
|
|
|
|
(c,
|
|
|
|
(const unsigned char *)&(lease -> starts), sizeof (TIME)));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
/* Write out the inner object, if any. */
|
|
|
|
if (h -> inner && h -> inner -> type -> stuff_values) {
|
|
|
|
status = ((*(h -> inner -> type -> stuff_values))
|
|
|
|
(c, id, h -> inner));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_lease_lookup (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id, omapi_object_t *ref)
|
|
|
|
{
|
|
|
|
omapi_value_t *tv = (omapi_value_t *)0;
|
|
|
|
isc_result_t status;
|
|
|
|
struct lease *lease;
|
|
|
|
|
|
|
|
/* First see if we were sent a handle. */
|
|
|
|
status = omapi_get_value_str (ref, id, "handle", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
status = omapi_handle_td_lookup (lp, tv -> value);
|
|
|
|
|
|
|
|
omapi_value_dereference (&tv, "dhcp_lease_lookup");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* Don't return the object if the type is wrong. */
|
|
|
|
if ((*lp) -> type != dhcp_type_lease) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for an IP address. */
|
1999-09-16 00:51:27 +00:00
|
|
|
status = omapi_get_value_str (ref, id, "ip-address", &tv);
|
1999-09-08 01:36:05 +00:00
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
lease = ((struct lease *)
|
|
|
|
hash_lookup (lease_ip_addr_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
|
|
|
|
omapi_value_dereference (&tv, "dhcp_lease_lookup");
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
/* If we already have a lease, and it's not the same one,
|
|
|
|
then the query was invalid. */
|
|
|
|
if (*lp && *lp != (omapi_object_t *)lease) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
|
|
|
} else if (!lease) {
|
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp,
|
|
|
|
"dhcp_lease_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (!*lp)
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp, (omapi_object_t *)lease,
|
|
|
|
"dhcp_lease_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a client identifier. */
|
|
|
|
status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
lease = ((struct lease *)
|
|
|
|
hash_lookup (lease_uid_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_lease_lookup");
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (*lp && *lp != (omapi_object_t *)lease) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
|
|
|
} else if (!lease) {
|
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (lease -> n_uid) {
|
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_MULTIPLE;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp, (omapi_object_t *)lease,
|
|
|
|
"dhcp_lease_lookup");
|
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a hardware address. */
|
|
|
|
status = omapi_get_value_str (ref, id, "hardware-address", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
lease = ((struct lease *)
|
1999-09-16 00:51:27 +00:00
|
|
|
hash_lookup (lease_hw_addr_hash,
|
1999-09-08 01:36:05 +00:00
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_lease_lookup");
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (*lp && *lp != (omapi_object_t *)lease) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
|
|
|
} else if (!lease) {
|
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (lease -> n_hw) {
|
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp, "dhcp_lease_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_MULTIPLE;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp, (omapi_object_t *)lease,
|
|
|
|
"dhcp_lease_lookup");
|
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get to here without finding a lease, no valid key was
|
|
|
|
specified. */
|
|
|
|
if (!*lp)
|
1999-10-01 03:27:37 +00:00
|
|
|
return ISC_R_NOKEYS;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_lease_create (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
return ISC_R_NOTIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-09-16 04:53:38 +00:00
|
|
|
isc_result_t dhcp_lease_remove (omapi_object_t *lp,
|
1999-09-09 23:33:43 +00:00
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
return ISC_R_NOTIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
isc_result_t dhcp_group_set_value (omapi_object_t *h,
|
1999-09-08 01:36:05 +00:00
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_typed_data_t *value)
|
1999-09-29 00:00:35 +00:00
|
|
|
{
|
|
|
|
struct group_object *group;
|
|
|
|
isc_result_t status;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
group = (struct group_object *)h;
|
|
|
|
|
|
|
|
/* XXX For now, we can only set these values on new group objects.
|
|
|
|
XXX Soon, we need to be able to update group objects. */
|
|
|
|
if (!omapi_ds_strcmp (name, "name")) {
|
|
|
|
if (group -> name)
|
|
|
|
return ISC_R_EXISTS;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
group -> name = malloc (value -> u.buffer.len + 1);
|
|
|
|
if (!group -> name)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
memcpy (group -> name,
|
|
|
|
value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len);
|
|
|
|
group -> name [value -> u.buffer.len] = 0;
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-10-01 03:27:37 +00:00
|
|
|
if (!omapi_ds_strcmp (name, "statements")) {
|
|
|
|
if (group -> group && group -> group -> statements)
|
|
|
|
return ISC_R_EXISTS;
|
|
|
|
if (!group -> group)
|
|
|
|
group -> group = clone_group (&root_group,
|
|
|
|
"dhcp_group_set_value");
|
|
|
|
if (!group -> group)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
struct parse *parse;
|
1999-10-04 23:53:57 +00:00
|
|
|
int lose = 0;
|
1999-10-01 03:27:37 +00:00
|
|
|
parse = (struct parse *)0;
|
|
|
|
status = new_parse (&parse, -1,
|
|
|
|
(char *)value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len,
|
|
|
|
"network client");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
if (!(parse_executable_statements
|
2000-01-08 01:49:36 +00:00
|
|
|
(&group -> group -> statements, parse, &lose,
|
|
|
|
context_any))) {
|
1999-10-01 03:27:37 +00:00
|
|
|
end_parse (&parse);
|
|
|
|
return ISC_R_BADPARSE;
|
|
|
|
}
|
|
|
|
end_parse (&parse);
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> set_value) {
|
|
|
|
status = ((*(h -> inner -> type -> set_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t dhcp_group_get_value (omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
|
|
|
{
|
|
|
|
struct group_object *group;
|
|
|
|
isc_result_t status;
|
|
|
|
struct data_string ip_addrs;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
group = (struct group_object *)h;
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "name"))
|
|
|
|
return omapi_make_string_value (value, name, group -> name,
|
|
|
|
"dhcp_group_get_value");
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> get_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
1999-10-07 06:36:35 +00:00
|
|
|
isc_result_t dhcp_group_destroy (omapi_object_t *h, const char *name)
|
1999-09-29 00:00:35 +00:00
|
|
|
{
|
|
|
|
struct group_object *group, *t;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
group = (struct group_object *)h;
|
|
|
|
|
|
|
|
if (group -> name) {
|
|
|
|
if (group_name_hash) {
|
|
|
|
t = ((struct group_object *)
|
|
|
|
hash_lookup (group_name_hash,
|
1999-10-07 02:14:10 +00:00
|
|
|
(unsigned char *)group -> name,
|
1999-09-29 00:00:35 +00:00
|
|
|
strlen (group -> name)));
|
|
|
|
if (t) {
|
|
|
|
delete_hash_entry (group_name_hash,
|
1999-10-07 02:14:10 +00:00
|
|
|
(unsigned char *)
|
1999-09-29 00:00:35 +00:00
|
|
|
group -> name,
|
|
|
|
strlen (group -> name));
|
|
|
|
--group -> refcnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (group -> name);
|
|
|
|
group -> name = (char *)0;
|
|
|
|
}
|
|
|
|
if (group -> group)
|
|
|
|
group -> group = (struct group *)0; /* XXX refcounts!!! */
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_group_signal_handler (omapi_object_t *h,
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *name, va_list ap)
|
1999-09-29 00:00:35 +00:00
|
|
|
{
|
|
|
|
struct group_object *group, *t;
|
|
|
|
isc_result_t status;
|
|
|
|
int updatep = 0;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
group = (struct group_object *)h;
|
|
|
|
|
|
|
|
if (!strcmp (name, "updated")) {
|
|
|
|
/* A group object isn't valid if a subgroup hasn't yet been
|
|
|
|
associated with it. */
|
|
|
|
if (!group -> group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
/* Group objects always have to have names. */
|
|
|
|
if (!group -> name) {
|
|
|
|
char hnbuf [64];
|
|
|
|
sprintf (hnbuf, "ng%08lx%08lx",
|
|
|
|
cur_time, (unsigned long)group);
|
|
|
|
group -> name = malloc (strlen (hnbuf) + 1);
|
|
|
|
if (!group -> name)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
strcpy (group -> name, hnbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
supersede_group (group, 1);
|
|
|
|
updatep = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> signal_handler))
|
|
|
|
(h -> inner, name, ap));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
if (updatep)
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_group_stuff_values (omapi_object_t *c,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_object_t *h)
|
|
|
|
{
|
|
|
|
struct group_object *group;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
group = (struct group_object *)h;
|
|
|
|
|
|
|
|
/* Write out all the values. */
|
|
|
|
if (group -> name) {
|
|
|
|
status = omapi_connection_put_name (c, "name");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_string (c, group -> name);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out the inner object, if any. */
|
|
|
|
if (h -> inner && h -> inner -> type -> stuff_values) {
|
|
|
|
status = ((*(h -> inner -> type -> stuff_values))
|
|
|
|
(c, id, h -> inner));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_group_lookup (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id, omapi_object_t *ref)
|
|
|
|
{
|
|
|
|
omapi_value_t *tv = (omapi_value_t *)0;
|
|
|
|
isc_result_t status;
|
|
|
|
struct group_object *group;
|
|
|
|
|
|
|
|
/* First see if we were sent a handle. */
|
|
|
|
status = omapi_get_value_str (ref, id, "handle", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
status = omapi_handle_td_lookup (lp, tv -> value);
|
|
|
|
|
|
|
|
omapi_value_dereference (&tv, "dhcp_group_lookup");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* Don't return the object if the type is wrong. */
|
|
|
|
if ((*lp) -> type != dhcp_type_group) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_group_lookup");
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a name. */
|
|
|
|
status = omapi_get_value_str (ref, id, "name", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
if (group_name_hash) {
|
|
|
|
group = ((struct group_object *)
|
|
|
|
hash_lookup (group_name_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_group_lookup");
|
|
|
|
|
|
|
|
/* Don't register a deleted group here. */
|
|
|
|
if (group -> flags & GROUP_OBJECT_DELETED) {
|
|
|
|
if (!*lp)
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
group = (struct group_object *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*lp && *lp != (omapi_object_t *)group) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_group_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
|
|
|
} else if (!group) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_group_lookup");
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp,
|
|
|
|
(omapi_object_t *)group,
|
|
|
|
"dhcp_group_lookup");
|
|
|
|
}
|
|
|
|
} else if (!*lp)
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get to here without finding a group, no valid key was
|
|
|
|
specified. */
|
|
|
|
if (!*lp)
|
1999-10-01 03:27:37 +00:00
|
|
|
return ISC_R_NOKEYS;
|
1999-09-29 00:00:35 +00:00
|
|
|
|
|
|
|
if (((struct group_object *)(*lp)) -> flags & GROUP_OBJECT_DELETED) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_group_lookup");
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_group_create (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
struct group_object *group;
|
|
|
|
group = (struct group_object *)dmalloc (sizeof (struct group_object),
|
|
|
|
"dhcp_group_create");
|
|
|
|
if (!group)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
memset (group, 0, sizeof *group);
|
|
|
|
group -> refcnt = 0;
|
|
|
|
group -> type = dhcp_type_group;
|
1999-10-01 03:27:37 +00:00
|
|
|
group -> flags = GROUP_OBJECT_DYNAMIC;
|
1999-09-29 00:00:35 +00:00
|
|
|
return omapi_object_reference (lp, (omapi_object_t *)group,
|
|
|
|
"dhcp_group_create");
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_group_remove (omapi_object_t *lp,
|
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
struct group_object *group;
|
|
|
|
isc_result_t status;
|
|
|
|
if (lp -> type != dhcp_type_group)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
group = (struct group_object *)lp;
|
|
|
|
|
|
|
|
group -> flags |= GROUP_OBJECT_DELETED;
|
1999-10-01 03:27:37 +00:00
|
|
|
if (!write_group (group) || !commit_leases ())
|
1999-09-29 00:00:35 +00:00
|
|
|
return ISC_R_IOERROR;
|
|
|
|
|
|
|
|
status = dhcp_group_destroy ((omapi_object_t *)group,
|
|
|
|
"dhcp_group_remove");
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_host_set_value (omapi_object_t *h,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_typed_data_t *value)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct host_decl *host;
|
|
|
|
isc_result_t status;
|
|
|
|
int foo;
|
|
|
|
|
1999-09-09 21:12:12 +00:00
|
|
|
if (h -> type != dhcp_type_host)
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
host = (struct host_decl *)h;
|
|
|
|
|
|
|
|
/* XXX For now, we can only set these values on new host objects.
|
|
|
|
XXX Soon, we need to be able to update host objects. */
|
|
|
|
if (!omapi_ds_strcmp (name, "name")) {
|
|
|
|
if (host -> name)
|
|
|
|
return ISC_R_EXISTS;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
host -> name = malloc (value -> u.buffer.len + 1);
|
|
|
|
if (!host -> name)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
memcpy (host -> name,
|
|
|
|
value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len);
|
|
|
|
host -> name [value -> u.buffer.len] = 0;
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (!omapi_ds_strcmp (name, "group")) {
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
struct group_object *group;
|
|
|
|
group = ((struct group_object *)
|
|
|
|
hash_lookup (group_name_hash,
|
|
|
|
value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len));
|
|
|
|
if (!group || (group -> flags & GROUP_OBJECT_DELETED))
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
host -> group = group -> group;
|
|
|
|
if (host -> named_group)
|
|
|
|
omapi_object_dereference
|
|
|
|
((omapi_object_t **)
|
|
|
|
&host -> named_group,
|
|
|
|
"dhcp_host_set_value");
|
|
|
|
omapi_object_reference ((omapi_object_t **)
|
|
|
|
&host -> named_group,
|
|
|
|
(omapi_object_t *)group,
|
|
|
|
"dhcp_host_set_value");
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
if (!omapi_ds_strcmp (name, "hardware-address")) {
|
|
|
|
if (host -> interface.hlen)
|
|
|
|
return ISC_R_EXISTS;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
if (value -> u.buffer.len >
|
2000-01-05 18:22:58 +00:00
|
|
|
(sizeof host -> interface.hbuf) - 1)
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
2000-01-05 18:22:58 +00:00
|
|
|
memcpy (&host -> interface.hbuf [1],
|
1999-09-08 01:36:05 +00:00
|
|
|
value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len);
|
2000-01-05 18:22:58 +00:00
|
|
|
host -> interface.hlen = value -> u.buffer.len + 1;
|
1999-09-08 01:36:05 +00:00
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "hardware-type")) {
|
|
|
|
int type;
|
|
|
|
if (value -> type == omapi_datatype_data &&
|
|
|
|
value -> u.buffer.len == sizeof type) {
|
2000-01-05 18:22:58 +00:00
|
|
|
if (value -> u.buffer.len > sizeof type)
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
memcpy (&type,
|
|
|
|
value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len);
|
|
|
|
} else if (value -> type == omapi_datatype_int)
|
|
|
|
type = value -> u.integer;
|
|
|
|
else
|
|
|
|
return ISC_R_INVALIDARG;
|
2000-01-05 18:22:58 +00:00
|
|
|
host -> interface.hbuf [0] = type;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
|
|
|
|
if (host -> client_identifier.data)
|
|
|
|
return ISC_R_EXISTS;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
if (!buffer_allocate
|
|
|
|
(&host -> client_identifier.buffer,
|
1999-09-29 00:00:35 +00:00
|
|
|
value -> u.buffer.len,
|
1999-09-08 01:36:05 +00:00
|
|
|
"dhcp_host_set_value"))
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
host -> client_identifier.data =
|
|
|
|
&host -> client_identifier.buffer -> data [0];
|
1999-10-07 06:36:35 +00:00
|
|
|
memcpy (host -> client_identifier.buffer -> data,
|
1999-09-08 01:36:05 +00:00
|
|
|
value -> u.buffer.value,
|
1999-09-29 00:00:35 +00:00
|
|
|
value -> u.buffer.len);
|
|
|
|
host -> client_identifier.len = value -> u.buffer.len;
|
1999-09-08 01:36:05 +00:00
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "ip-address")) {
|
|
|
|
if (host -> fixed_addr)
|
|
|
|
return ISC_R_EXISTS;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
struct data_string ds;
|
|
|
|
memset (&ds, 0, sizeof ds);
|
|
|
|
ds.len = value -> u.buffer.len;
|
|
|
|
if (!buffer_allocate (&ds.buffer, ds.len,
|
|
|
|
"dhcp_host_set_value"))
|
|
|
|
return ISC_R_NOMEMORY;
|
1999-09-29 00:00:35 +00:00
|
|
|
ds.data = (&ds.buffer -> data [0]);
|
1999-10-07 06:36:35 +00:00
|
|
|
memcpy (ds.buffer -> data,
|
|
|
|
value -> u.buffer.value, ds.len);
|
1999-09-08 01:36:05 +00:00
|
|
|
if (!option_cache (&host -> fixed_addr,
|
|
|
|
&ds, (struct expression *)0,
|
|
|
|
(struct option *)0)) {
|
|
|
|
data_string_forget (&ds,
|
|
|
|
"dhcp_host_set_value");
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
}
|
|
|
|
data_string_forget (&ds, "dhcp_host_set_value");
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-10-04 23:53:57 +00:00
|
|
|
if (!omapi_ds_strcmp (name, "statements")) {
|
|
|
|
if (!host -> group)
|
|
|
|
host -> group = clone_group (&root_group,
|
|
|
|
"dhcp_host_set_value");
|
1999-10-06 19:17:44 +00:00
|
|
|
else {
|
|
|
|
if (host -> group -> statements &&
|
|
|
|
(!host -> named_group ||
|
|
|
|
host -> group != host -> named_group -> group) &&
|
|
|
|
host -> group != &root_group)
|
|
|
|
return ISC_R_EXISTS;
|
1999-10-04 23:53:57 +00:00
|
|
|
host -> group = clone_group (host -> group,
|
|
|
|
"dhcp_host_set_value");
|
|
|
|
}
|
|
|
|
if (!host -> group)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
if (value -> type == omapi_datatype_data ||
|
|
|
|
value -> type == omapi_datatype_string) {
|
|
|
|
struct parse *parse;
|
|
|
|
int lose = 0;
|
|
|
|
parse = (struct parse *)0;
|
|
|
|
status = new_parse (&parse, -1,
|
|
|
|
(char *)value -> u.buffer.value,
|
|
|
|
value -> u.buffer.len,
|
|
|
|
"network client");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
if (!(parse_executable_statements
|
2000-01-08 01:49:36 +00:00
|
|
|
(&host -> group -> statements, parse, &lose,
|
|
|
|
context_any))) {
|
1999-10-04 23:53:57 +00:00
|
|
|
end_parse (&parse);
|
|
|
|
return ISC_R_BADPARSE;
|
|
|
|
}
|
|
|
|
end_parse (&parse);
|
|
|
|
} else
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-09 21:12:12 +00:00
|
|
|
/* The "known" flag isn't supported in the database yet, but it's
|
|
|
|
legitimate. */
|
|
|
|
if (!omapi_ds_strcmp (name, "known")) {
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> set_value) {
|
|
|
|
status = ((*(h -> inner -> type -> set_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t dhcp_host_get_value (omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
|
|
|
{
|
|
|
|
struct host_decl *host;
|
|
|
|
isc_result_t status;
|
|
|
|
struct data_string ip_addrs;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_host)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
host = (struct host_decl *)h;
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "ip-addresses")) {
|
|
|
|
memset (&ip_addrs, 0, sizeof ip_addrs);
|
|
|
|
if (host -> fixed_addr &&
|
|
|
|
evaluate_option_cache (&ip_addrs, (struct packet *)0,
|
|
|
|
(struct lease *)0,
|
|
|
|
(struct option_state *)0,
|
|
|
|
(struct option_state *)0,
|
|
|
|
host -> fixed_addr)) {
|
|
|
|
status = (omapi_make_const_value
|
|
|
|
(value, name, ip_addrs.data, ip_addrs.len,
|
|
|
|
"dhcp_host_get_value"));
|
|
|
|
data_string_forget (&ip_addrs, "dhcp_host_get_value");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
|
|
|
|
if (!host -> client_identifier.len)
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
return omapi_make_const_value (value, name,
|
|
|
|
host -> client_identifier.data,
|
|
|
|
host -> client_identifier.len,
|
|
|
|
"dhcp_host_get_value");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "name"))
|
|
|
|
return omapi_make_string_value (value, name, host -> name,
|
|
|
|
"dhcp_host_get_value");
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "hardware-address")) {
|
|
|
|
if (!host -> interface.hlen)
|
|
|
|
return ISC_R_NOTFOUND;
|
2000-01-05 18:22:58 +00:00
|
|
|
return (omapi_make_const_value
|
|
|
|
(value, name, &host -> interface.hbuf [1],
|
|
|
|
(unsigned long)(host -> interface.hlen - 1),
|
|
|
|
"dhcp_host_get_value"));
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!omapi_ds_strcmp (name, "hardware-type")) {
|
|
|
|
if (!host -> interface.hlen)
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
return omapi_make_int_value (value, name,
|
2000-01-05 18:22:58 +00:00
|
|
|
host -> interface.hbuf [0],
|
1999-09-08 01:36:05 +00:00
|
|
|
"dhcp_host_get_value");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> get_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
1999-10-07 06:36:35 +00:00
|
|
|
isc_result_t dhcp_host_destroy (omapi_object_t *h, const char *name)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct host_decl *host;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_host)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
host = (struct host_decl *)h;
|
|
|
|
|
|
|
|
/* Currently, this is completely hopeless - have to complete
|
|
|
|
reference counting support for server OMAPI objects. */
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_host_signal_handler (omapi_object_t *h,
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *name, va_list ap)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct host_decl *host;
|
|
|
|
isc_result_t status;
|
1999-09-29 00:00:35 +00:00
|
|
|
int updatep = 0;
|
1999-09-08 01:36:05 +00:00
|
|
|
|
|
|
|
if (h -> type != dhcp_type_host)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
host = (struct host_decl *)h;
|
|
|
|
|
|
|
|
if (!strcmp (name, "updated")) {
|
1999-09-29 00:00:35 +00:00
|
|
|
if ((host -> interface.hlen == 0 ||
|
2000-01-05 18:22:58 +00:00
|
|
|
host -> interface.hbuf [0] == 0 ||
|
|
|
|
host -> interface.hlen > 17) &&
|
1999-09-29 00:00:35 +00:00
|
|
|
!host -> client_identifier.len)
|
1999-09-16 05:12:38 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
if (!host -> name) {
|
|
|
|
char hnbuf [64];
|
1999-09-09 23:53:29 +00:00
|
|
|
sprintf (hnbuf, "nh%08lx%08lx",
|
|
|
|
cur_time, (unsigned long)host);
|
1999-09-08 01:36:05 +00:00
|
|
|
host -> name = malloc (strlen (hnbuf) + 1);
|
|
|
|
if (!host -> name)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
strcpy (host -> name, hnbuf);
|
|
|
|
}
|
1999-09-16 05:12:38 +00:00
|
|
|
|
1999-10-14 18:30:52 +00:00
|
|
|
#ifdef DEBUG_OMAPI
|
|
|
|
log_debug ("OMAPI added host %s", host -> name);
|
|
|
|
#endif
|
1999-09-16 05:12:38 +00:00
|
|
|
status = enter_host (host, 1, 1);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-09-29 00:00:35 +00:00
|
|
|
updatep = 1;
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> signal_handler))
|
|
|
|
(h -> inner, name, ap));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
1999-09-29 00:00:35 +00:00
|
|
|
if (updatep)
|
|
|
|
return ISC_R_SUCCESS;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_host_stuff_values (omapi_object_t *c,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_object_t *h)
|
|
|
|
{
|
|
|
|
struct host_decl *host;
|
|
|
|
isc_result_t status;
|
|
|
|
struct data_string ip_addrs;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_host)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
host = (struct host_decl *)h;
|
|
|
|
|
|
|
|
/* Write out all the values. */
|
|
|
|
|
|
|
|
memset (&ip_addrs, 0, sizeof ip_addrs);
|
|
|
|
if (host -> fixed_addr &&
|
|
|
|
evaluate_option_cache (&ip_addrs, (struct packet *)0,
|
|
|
|
(struct lease *)0,
|
|
|
|
(struct option_state *)0,
|
|
|
|
(struct option_state *)0,
|
|
|
|
host -> fixed_addr)) {
|
|
|
|
status = omapi_connection_put_name (c, "ip-address");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, ip_addrs.len);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_copyin (c,
|
|
|
|
ip_addrs.data, ip_addrs.len);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (host -> client_identifier.len) {
|
|
|
|
status = omapi_connection_put_name (c,
|
|
|
|
"dhcp-client-identifier");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = (omapi_connection_put_uint32
|
|
|
|
(c, host -> client_identifier.len));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-09-09 21:12:12 +00:00
|
|
|
status = (omapi_connection_copyin
|
|
|
|
(c,
|
|
|
|
host -> client_identifier.data,
|
|
|
|
host -> client_identifier.len));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (host -> name) {
|
|
|
|
status = omapi_connection_put_name (c, "name");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_string (c, host -> name);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (host -> interface.hlen) {
|
|
|
|
status = omapi_connection_put_name (c, "hardware-address");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
2000-01-05 18:22:58 +00:00
|
|
|
status = (omapi_connection_put_uint32
|
|
|
|
(c, (unsigned long)(host -> interface.hlen - 1)));
|
1999-09-29 00:00:35 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
2000-01-05 18:22:58 +00:00
|
|
|
status = (omapi_connection_copyin
|
|
|
|
(c, &host -> interface.hbuf [1],
|
|
|
|
(unsigned long)(host -> interface.hlen)));
|
1999-09-29 00:00:35 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-09-08 01:36:05 +00:00
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
status = omapi_connection_put_name (c, "hardware-type");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
status = omapi_connection_put_uint32 (c, sizeof (int));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
2000-01-05 18:22:58 +00:00
|
|
|
status = (omapi_connection_put_uint32
|
|
|
|
(c, host -> interface.hbuf [0]));
|
1999-09-29 00:00:35 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
|
|
|
|
/* Write out the inner object, if any. */
|
|
|
|
if (h -> inner && h -> inner -> type -> stuff_values) {
|
|
|
|
status = ((*(h -> inner -> type -> stuff_values))
|
|
|
|
(c, id, h -> inner));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_host_lookup (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id, omapi_object_t *ref)
|
|
|
|
{
|
|
|
|
omapi_value_t *tv = (omapi_value_t *)0;
|
|
|
|
isc_result_t status;
|
|
|
|
struct host_decl *host;
|
|
|
|
|
|
|
|
/* First see if we were sent a handle. */
|
|
|
|
status = omapi_get_value_str (ref, id, "handle", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
status = omapi_handle_td_lookup (lp, tv -> value);
|
|
|
|
|
|
|
|
omapi_value_dereference (&tv, "dhcp_host_lookup");
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* Don't return the object if the type is wrong. */
|
|
|
|
if ((*lp) -> type != dhcp_type_host) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
}
|
1999-10-25 01:56:38 +00:00
|
|
|
if (((struct host_decl *)(*lp)) -> flags & HOST_DECL_DELETED) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a client identifier. */
|
|
|
|
status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
host = ((struct host_decl *)
|
|
|
|
hash_lookup (host_uid_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_host_lookup");
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (*lp && *lp != (omapi_object_t *)host) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
1999-10-25 01:56:38 +00:00
|
|
|
} else if (!host || (host -> flags & HOST_DECL_DELETED)) {
|
1999-09-29 00:00:35 +00:00
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp, (omapi_object_t *)host,
|
|
|
|
"dhcp_host_lookup");
|
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a hardware address. */
|
|
|
|
status = omapi_get_value_str (ref, id, "hardware-address", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
host = ((struct host_decl *)
|
|
|
|
hash_lookup (host_hw_addr_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_host_lookup");
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (*lp && *lp != (omapi_object_t *)host) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
1999-10-25 01:56:38 +00:00
|
|
|
} else if (!host || (host -> flags & HOST_DECL_DELETED)) {
|
1999-09-29 00:00:35 +00:00
|
|
|
if (*lp)
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
1999-09-29 00:00:35 +00:00
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp, (omapi_object_t *)host,
|
|
|
|
"dhcp_host_lookup");
|
|
|
|
}
|
1999-09-16 00:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for an ip address. */
|
|
|
|
status = omapi_get_value_str (ref, id, "ip-address", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
struct lease *l;
|
|
|
|
|
|
|
|
/* first find the lease for this ip address */
|
|
|
|
l = ((struct lease *)
|
|
|
|
hash_lookup (lease_ip_addr_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_host_lookup");
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (!l && !*lp)
|
1999-09-16 00:51:27 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (l) {
|
|
|
|
/* now use that to get a host */
|
|
|
|
host = ((struct host_decl *)
|
|
|
|
hash_lookup (host_hw_addr_hash,
|
2000-01-05 18:22:58 +00:00
|
|
|
l -> hardware_addr.hbuf,
|
1999-09-29 00:00:35 +00:00
|
|
|
l -> hardware_addr.hlen));
|
1999-09-16 00:51:27 +00:00
|
|
|
|
1999-09-29 00:00:35 +00:00
|
|
|
if (host && *lp && *lp != (omapi_object_t *)host) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
1999-10-25 01:56:38 +00:00
|
|
|
} else if (!host || (host -> flags &
|
|
|
|
HOST_DECL_DELETED)) {
|
1999-09-29 00:00:35 +00:00
|
|
|
if (!*lp)
|
|
|
|
return ISC_R_NOTFOUND;
|
1999-10-14 18:30:52 +00:00
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp,
|
|
|
|
(omapi_object_t *)host,
|
|
|
|
"dhcp_host_lookup");
|
1999-09-29 00:00:35 +00:00
|
|
|
}
|
1999-10-04 23:53:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look for a name. */
|
|
|
|
status = omapi_get_value_str (ref, id, "name", &tv);
|
|
|
|
if (status == ISC_R_SUCCESS) {
|
|
|
|
host = ((struct host_decl *)
|
|
|
|
hash_lookup (host_name_hash,
|
|
|
|
tv -> value -> u.buffer.value,
|
|
|
|
tv -> value -> u.buffer.len));
|
|
|
|
omapi_value_dereference (&tv, "dhcp_host_lookup");
|
|
|
|
|
|
|
|
if (*lp && *lp != (omapi_object_t *)host) {
|
|
|
|
omapi_object_dereference (lp, "dhcp_host_lookup");
|
|
|
|
return ISC_R_KEYCONFLICT;
|
1999-10-25 01:56:38 +00:00
|
|
|
} else if (!host || (host -> flags & HOST_DECL_DELETED)) {
|
1999-10-04 23:53:57 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
} else if (!*lp) {
|
|
|
|
/* XXX fix so that hash lookup itself creates
|
|
|
|
XXX the reference. */
|
|
|
|
omapi_object_reference (lp, (omapi_object_t *)host,
|
|
|
|
"dhcp_host_lookup");
|
1999-09-29 00:00:35 +00:00
|
|
|
}
|
1999-09-08 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get to here without finding a host, no valid key was
|
|
|
|
specified. */
|
|
|
|
if (!*lp)
|
1999-10-01 03:27:37 +00:00
|
|
|
return ISC_R_NOKEYS;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_host_create (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
struct host_decl *hp;
|
|
|
|
hp = (struct host_decl *)dmalloc (sizeof (struct host_decl),
|
|
|
|
"dhcp_host_create");
|
|
|
|
if (!hp)
|
|
|
|
return ISC_R_NOMEMORY;
|
|
|
|
memset (hp, 0, sizeof *hp);
|
|
|
|
hp -> refcnt = 0;
|
1999-09-09 21:12:12 +00:00
|
|
|
hp -> type = dhcp_type_host;
|
|
|
|
hp -> group = &root_group; /* XXX */
|
1999-10-25 01:56:38 +00:00
|
|
|
hp -> flags = HOST_DECL_DYNAMIC;
|
1999-09-08 01:36:05 +00:00
|
|
|
return omapi_object_reference (lp, (omapi_object_t *)hp,
|
|
|
|
"dhcp_host_create");
|
|
|
|
}
|
|
|
|
|
1999-09-16 04:53:38 +00:00
|
|
|
isc_result_t dhcp_host_remove (omapi_object_t *lp,
|
1999-09-09 23:33:43 +00:00
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
struct host_decl *hp;
|
|
|
|
if (lp -> type != dhcp_type_host)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
hp = (struct host_decl *)lp;
|
|
|
|
|
1999-10-14 18:30:52 +00:00
|
|
|
#ifdef DEBUG_OMAPI
|
|
|
|
log_debug ("OMAPI delete host %s", hp -> name);
|
|
|
|
#endif
|
1999-09-09 23:33:43 +00:00
|
|
|
delete_host (hp, 1);
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-08 01:36:05 +00:00
|
|
|
isc_result_t dhcp_pool_set_value (omapi_object_t *h,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_typed_data_t *value)
|
|
|
|
{
|
|
|
|
struct pool *pool;
|
|
|
|
isc_result_t status;
|
|
|
|
int foo;
|
|
|
|
|
1999-09-09 21:12:12 +00:00
|
|
|
if (h -> type != dhcp_type_pool)
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
pool = (struct pool *)h;
|
|
|
|
|
|
|
|
/* No values to set yet. */
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> set_value) {
|
|
|
|
status = ((*(h -> inner -> type -> set_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t dhcp_pool_get_value (omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
|
|
|
{
|
|
|
|
struct pool *pool;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_pool)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
pool = (struct pool *)h;
|
|
|
|
|
|
|
|
/* No values to get yet. */
|
|
|
|
|
|
|
|
/* Try to find some inner object that can provide the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> get_value))
|
|
|
|
(h -> inner, id, name, value));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
1999-10-07 06:36:35 +00:00
|
|
|
isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *name)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct pool *pool;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_pool)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
pool = (struct pool *)h;
|
|
|
|
|
|
|
|
/* Can't destroy pools yet. */
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_pool_signal_handler (omapi_object_t *h,
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *name, va_list ap)
|
1999-09-08 01:36:05 +00:00
|
|
|
{
|
|
|
|
struct pool *pool;
|
|
|
|
isc_result_t status;
|
1999-09-29 00:00:35 +00:00
|
|
|
int updatep = 0;
|
1999-09-08 01:36:05 +00:00
|
|
|
|
|
|
|
if (h -> type != dhcp_type_pool)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
pool = (struct pool *)h;
|
|
|
|
|
|
|
|
/* Can't write pools yet. */
|
|
|
|
|
|
|
|
/* Try to find some inner object that can take the value. */
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value) {
|
|
|
|
status = ((*(h -> inner -> type -> signal_handler))
|
|
|
|
(h -> inner, name, ap));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
1999-09-29 00:00:35 +00:00
|
|
|
if (updatep)
|
|
|
|
return ISC_R_SUCCESS;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_pool_stuff_values (omapi_object_t *c,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_object_t *h)
|
|
|
|
{
|
|
|
|
struct pool *pool;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
if (h -> type != dhcp_type_pool)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
pool = (struct pool *)h;
|
|
|
|
|
|
|
|
/* Can't stuff pool values yet. */
|
|
|
|
|
|
|
|
/* Write out the inner object, if any. */
|
|
|
|
if (h -> inner && h -> inner -> type -> stuff_values) {
|
|
|
|
status = ((*(h -> inner -> type -> stuff_values))
|
|
|
|
(c, id, h -> inner));
|
|
|
|
if (status == ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_pool_lookup (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id, omapi_object_t *ref)
|
|
|
|
{
|
|
|
|
omapi_value_t *tv = (omapi_value_t *)0;
|
|
|
|
isc_result_t status;
|
|
|
|
struct pool *pool;
|
|
|
|
|
|
|
|
/* Can't look up pools yet. */
|
|
|
|
|
|
|
|
/* If we get to here without finding a pool, no valid key was
|
|
|
|
specified. */
|
|
|
|
if (!*lp)
|
1999-10-01 03:27:37 +00:00
|
|
|
return ISC_R_NOKEYS;
|
1999-09-08 01:36:05 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t dhcp_pool_create (omapi_object_t **lp,
|
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
return ISC_R_NOTIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-09-16 04:53:38 +00:00
|
|
|
isc_result_t dhcp_pool_remove (omapi_object_t *lp,
|
1999-09-09 23:33:43 +00:00
|
|
|
omapi_object_t *id)
|
|
|
|
{
|
|
|
|
return ISC_R_NOTIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-10-14 18:30:52 +00:00
|
|
|
/* vim: set tabstop=8: */
|