ISC DHCP  4.3.0
A reference DHCPv4 and DHCPv6 implementation
omapi.c
Go to the documentation of this file.
1 /* omapi.c
2 
3  OMAPI object interfaces for the DHCP server. */
4 
5 /*
6  * Copyright (c) 2012-2014 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 2004-2009 by Internet Systems Consortium, Inc. ("ISC")
8  * Copyright (c) 1999-2003 by Internet Software Consortium
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  *
22  * Internet Systems Consortium, Inc.
23  * 950 Charter Street
24  * Redwood City, CA 94063
25  * <info@isc.org>
26  * https://www.isc.org/
27  *
28  */
29 
30 /* Many, many thanks to Brian Murrell and BCtel for this code - BCtel
31  provided the funding that resulted in this code and the entire
32  OMAPI support library being written, and Brian helped brainstorm
33  and refine the requirements. To the extent that this code is
34  useful, you have Brian and BCtel to thank. Any limitations in the
35  code are a result of mistakes on my part. -- Ted Lemon */
36 
37 #include "dhcpd.h"
38 #include <omapip/omapip_p.h>
39 
40 static isc_result_t class_lookup (omapi_object_t **,
43 
49 #if defined (FAILOVER_PROTOCOL)
53 #endif
54 
56 {
57  isc_result_t status;
58 
59  status = omapi_object_type_register (&dhcp_type_lease,
60  "lease",
69 #if defined (COMPACT_LEASES)
72 #else
73  0, 0,
74 #endif
75  0,
76  sizeof (struct lease),
77  0, RC_LEASE);
78  if (status != ISC_R_SUCCESS)
79  log_fatal ("Can't register lease object type: %s",
80  isc_result_totext (status));
81 
82  status = omapi_object_type_register (&dhcp_type_class,
83  "class",
91  dhcp_class_remove, 0, 0, 0,
92  sizeof (struct class), 0,
93  RC_MISC);
94  if (status != ISC_R_SUCCESS)
95  log_fatal ("Can't register class object type: %s",
96  isc_result_totext (status));
97 
98  status = omapi_object_type_register (&dhcp_type_subclass,
99  "subclass",
107  dhcp_subclass_remove, 0, 0, 0,
108  sizeof (struct class), 0, RC_MISC);
109  if (status != ISC_R_SUCCESS)
110  log_fatal ("Can't register subclass object type: %s",
111  isc_result_totext (status));
112 
113  status = omapi_object_type_register (&dhcp_type_pool,
114  "pool",
122  dhcp_pool_remove, 0, 0, 0,
123  sizeof (struct pool), 0, RC_MISC);
124 
125  if (status != ISC_R_SUCCESS)
126  log_fatal ("Can't register pool object type: %s",
127  isc_result_totext (status));
128 
129  status = omapi_object_type_register (&dhcp_type_host,
130  "host",
138  dhcp_host_remove, 0, 0, 0,
139  sizeof (struct host_decl),
140  0, RC_MISC);
141 
142  if (status != ISC_R_SUCCESS)
143  log_fatal ("Can't register host object type: %s",
144  isc_result_totext (status));
145 
146 #if defined (FAILOVER_PROTOCOL)
147  status = omapi_object_type_register (&dhcp_type_failover_state,
148  "failover-state",
157  0, 0, 0,
158  sizeof (dhcp_failover_state_t),
159  0, RC_MISC);
160 
161  if (status != ISC_R_SUCCESS)
162  log_fatal ("Can't register failover state object type: %s",
163  isc_result_totext (status));
164 
165  status = omapi_object_type_register (&dhcp_type_failover_link,
166  "failover-link",
172  0, 0, 0, 0, 0, 0,
173  sizeof (dhcp_failover_link_t), 0,
174  RC_MISC);
175 
176  if (status != ISC_R_SUCCESS)
177  log_fatal ("Can't register failover link object type: %s",
178  isc_result_totext (status));
179 
180  status = omapi_object_type_register (&dhcp_type_failover_listener,
181  "failover-listener",
187  0, 0, 0, 0, 0, 0,
188  sizeof
190  RC_MISC);
191 
192  if (status != ISC_R_SUCCESS)
193  log_fatal ("Can't register failover listener object type: %s",
194  isc_result_totext (status));
195 #endif /* FAILOVER_PROTOCOL */
196 }
197 
199  omapi_object_t *id,
200  omapi_data_string_t *name,
201  omapi_typed_data_t *value)
202 {
203  struct lease *lease;
204  isc_result_t status;
205 
206  if (h -> type != dhcp_type_lease)
207  return DHCP_R_INVALIDARG;
208  lease = (struct lease *)h;
209 
210  /* We're skipping a lot of things it might be interesting to
211  set - for now, we just make it possible to whack the state. */
212  if (!omapi_ds_strcmp (name, "state")) {
213  unsigned long bar;
214  const char *ols, *nls;
215  status = omapi_get_int_value (&bar, value);
216  if (status != ISC_R_SUCCESS)
217  return status;
218 
219  if (bar < 1 || bar > FTS_LAST)
220  return DHCP_R_INVALIDARG;
221  nls = binding_state_names [bar - 1];
222  if (lease -> binding_state >= 1 &&
223  lease -> binding_state <= FTS_LAST)
224  ols = binding_state_names [lease -> binding_state - 1];
225  else
226  ols = "unknown state";
227 
228  if (lease -> binding_state != bar) {
229  lease -> next_binding_state = bar;
230  if (supersede_lease (lease, 0, 1, 1, 1)) {
231  log_info ("lease %s state changed from %s to %s",
232  piaddr(lease->ip_addr), ols, nls);
233  return ISC_R_SUCCESS;
234  }
235  log_info ("lease %s state change from %s to %s failed.",
236  piaddr (lease -> ip_addr), ols, nls);
237  return ISC_R_IOERROR;
238  }
239  return DHCP_R_UNCHANGED;
240  } else if (!omapi_ds_strcmp (name, "ip-address")) {
241  return ISC_R_NOPERM;
242  } else if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
243  return DHCP_R_UNCHANGED; /* XXX take change. */
244  } else if (!omapi_ds_strcmp (name, "hostname")) {
245  return DHCP_R_UNCHANGED; /* XXX take change. */
246  } else if (!omapi_ds_strcmp (name, "client-hostname")) {
247  return DHCP_R_UNCHANGED; /* XXX take change. */
248  } else if (!omapi_ds_strcmp (name, "host")) {
249  return DHCP_R_UNCHANGED; /* XXX take change. */
250  } else if (!omapi_ds_strcmp (name, "subnet")) {
251  return DHCP_R_INVALIDARG;
252  } else if (!omapi_ds_strcmp (name, "pool")) {
253  return ISC_R_NOPERM;
254  } else if (!omapi_ds_strcmp (name, "starts")) {
255  return ISC_R_NOPERM;
256  } else if (!omapi_ds_strcmp (name, "ends")) {
257  unsigned long lease_end, old_lease_end;
258  status = omapi_get_int_value (&lease_end, value);
259  if (status != ISC_R_SUCCESS)
260  return status;
261  old_lease_end = lease->ends;
262  lease->ends = lease_end;
263  if (supersede_lease (lease, 0, 1, 1, 1)) {
264  log_info ("lease %s end changed from %lu to %lu",
265  piaddr(lease->ip_addr), old_lease_end, lease_end);
266  return ISC_R_SUCCESS;
267  }
268  log_info ("lease %s end change from %lu to %lu failed",
269  piaddr(lease->ip_addr), old_lease_end, lease_end);
270  return ISC_R_IOERROR;
271  } else if (!omapi_ds_strcmp(name, "flags")) {
272  u_int8_t oldflags;
273 
274  if (value->type != omapi_datatype_data)
275  return DHCP_R_INVALIDARG;
276 
277  oldflags = lease->flags;
278  lease->flags = (value->u.buffer.value[0] & EPHEMERAL_FLAGS) |
279  (lease->flags & ~EPHEMERAL_FLAGS);
280  if(oldflags == lease->flags)
281  return ISC_R_SUCCESS;
282  if (!supersede_lease(lease, NULL, 1, 1, 1)) {
283  log_error("Failed to update flags for lease %s.",
284  piaddr(lease->ip_addr));
285  return ISC_R_IOERROR;
286  }
287  return ISC_R_SUCCESS;
288  } else if (!omapi_ds_strcmp (name, "billing-class")) {
289  return DHCP_R_UNCHANGED; /* XXX carefully allow change. */
290  } else if (!omapi_ds_strcmp (name, "hardware-address")) {
291  return DHCP_R_UNCHANGED; /* XXX take change. */
292  } else if (!omapi_ds_strcmp (name, "hardware-type")) {
293  return DHCP_R_UNCHANGED; /* XXX take change. */
294  } else if (lease -> scope) {
295  status = binding_scope_set_value (lease -> scope, 0, name, value);
296  if (status == ISC_R_SUCCESS) {
297  if (write_lease (lease) && commit_leases ())
298  return ISC_R_SUCCESS;
299  return ISC_R_IOERROR;
300  }
301  }
302 
303  /* Try to find some inner object that can take the value. */
304  if (h -> inner && h -> inner -> type -> set_value) {
305  status = ((*(h -> inner -> type -> set_value))
306  (h -> inner, id, name, value));
307  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
308  return status;
309  }
310 
311  if (!lease -> scope) {
312  if (!binding_scope_allocate (&lease -> scope, MDL))
313  return ISC_R_NOMEMORY;
314  }
315  status = binding_scope_set_value (lease -> scope, 1, name, value);
316  if (status != ISC_R_SUCCESS)
317  return status;
318 
319  if (write_lease (lease) && commit_leases ())
320  return ISC_R_SUCCESS;
321  return ISC_R_IOERROR;
322 }
323 
324 
326  omapi_data_string_t *name,
327  omapi_value_t **value)
328 {
329  struct lease *lease;
330  isc_result_t status;
331 
332  if (h -> type != dhcp_type_lease)
333  return DHCP_R_INVALIDARG;
334  lease = (struct lease *)h;
335 
336  if (!omapi_ds_strcmp (name, "state"))
337  return omapi_make_int_value (value, name,
338  (int)lease -> binding_state, MDL);
339  else if (!omapi_ds_strcmp (name, "ip-address"))
340  return omapi_make_const_value (value, name,
341  lease -> ip_addr.iabuf,
342  lease -> ip_addr.len, MDL);
343  else if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
344  return omapi_make_const_value (value, name,
345  lease -> uid,
346  lease -> uid_len, MDL);
347  } else if (!omapi_ds_strcmp (name, "client-hostname")) {
348  if (lease -> client_hostname)
350  (value, name, lease -> client_hostname, MDL);
351  return ISC_R_NOTFOUND;
352  } else if (!omapi_ds_strcmp (name, "host")) {
353  if (lease -> host)
355  (value, name,
356  ((omapi_object_t *)lease -> host), MDL);
357  } else if (!omapi_ds_strcmp (name, "subnet"))
358  return omapi_make_handle_value (value, name,
359  ((omapi_object_t *)
360  lease -> subnet), MDL);
361  else if (!omapi_ds_strcmp (name, "pool"))
362  return omapi_make_handle_value (value, name,
363  ((omapi_object_t *)
364  lease -> pool), MDL);
365  else if (!omapi_ds_strcmp (name, "billing-class")) {
366  if (lease -> billing_class)
368  (value, name,
369  ((omapi_object_t *)lease -> billing_class),
370  MDL);
371  return ISC_R_NOTFOUND;
372  } else if (!omapi_ds_strcmp (name, "hardware-address")) {
373  if (lease -> hardware_addr.hlen)
375  (value, name, &lease -> hardware_addr.hbuf [1],
376  (unsigned)(lease -> hardware_addr.hlen - 1),
377  MDL);
378  return ISC_R_NOTFOUND;
379  } else if (!omapi_ds_strcmp (name, "hardware-type")) {
380  if (lease -> hardware_addr.hlen)
381  return omapi_make_int_value
382  (value, name, lease -> hardware_addr.hbuf [0],
383  MDL);
384  return ISC_R_NOTFOUND;
385  } else if (lease -> scope) {
386  status = binding_scope_get_value (value, lease -> scope, name);
387  if (status != ISC_R_NOTFOUND)
388  return status;
389  }
390 
391  /* Try to find some inner object that can take the value. */
392  if (h -> inner && h -> inner -> type -> get_value) {
393  status = ((*(h -> inner -> type -> get_value))
394  (h -> inner, id, name, value));
395  if (status == ISC_R_SUCCESS)
396  return status;
397  }
399 }
400 
401 isc_result_t dhcp_lease_destroy (omapi_object_t *h, const char *file, int line)
402 {
403  struct lease *lease;
404 
405  if (h->type != dhcp_type_lease)
406  return DHCP_R_INVALIDARG;
407  lease = (struct lease *)h;
408 
409  if (lease-> uid)
410  uid_hash_delete (lease);
411  hw_hash_delete (lease);
412 
413  if (lease->on_star.on_release)
415  file, line);
416  if (lease->on_star.on_expiry)
418  file, line);
419  if (lease->on_star.on_commit)
421  file, line);
422  if (lease->scope)
423  binding_scope_dereference (&lease->scope, file, line);
424 
425  if (lease->agent_options)
427  file, line);
428  if (lease->uid && lease->uid != lease->uid_buf) {
429  dfree (lease->uid, MDL);
430  lease->uid = &lease->uid_buf [0];
431  lease->uid_len = 0;
432  }
433 
434  if (lease->client_hostname) {
435  dfree (lease->client_hostname, MDL);
436  lease->client_hostname = (char *)0;
437  }
438 
439  if (lease->host)
440  host_dereference (&lease->host, file, line);
441  if (lease->subnet)
442  subnet_dereference (&lease->subnet, file, line);
443  if (lease->pool)
444  pool_dereference (&lease->pool, file, line);
445 
446  if (lease->state) {
447  free_lease_state (lease->state, file, line);
448  lease->state = (struct lease_state *)0;
449 
451  --outstanding_pings; /* XXX */
452  }
453 
454  if (lease->billing_class)
455  class_dereference
456  (&lease->billing_class, file, line);
457 
458 #if defined (DEBUG_MEMORY_LEAKAGE) || \
459  defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
460  /* XXX we should never be destroying a lease with a next
461  XXX pointer except on exit... */
462  if (lease->next)
463  lease_dereference (&lease->next, file, line);
464  if (lease->n_hw)
465  lease_dereference (&lease->n_hw, file, line);
466  if (lease->n_uid)
467  lease_dereference (&lease->n_uid, file, line);
468  if (lease->next_pending)
469  lease_dereference (&lease->next_pending, file, line);
470 #endif
471 
472  return ISC_R_SUCCESS;
473 }
474 
476  const char *name, va_list ap)
477 {
478  /* h should point to (struct lease *) */
479  isc_result_t status;
480 
481  if (h -> type != dhcp_type_lease)
482  return DHCP_R_INVALIDARG;
483 
484  if (!strcmp (name, "updated"))
485  return ISC_R_SUCCESS;
486 
487  /* Try to find some inner object that can take the value. */
488  if (h -> inner && h -> inner -> type -> signal_handler) {
489  status = ((*(h -> inner -> type -> signal_handler))
490  (h -> inner, name, ap));
491  if (status == ISC_R_SUCCESS)
492  return status;
493  }
494  return ISC_R_NOTFOUND;
495 }
496 
498  omapi_object_t *id,
499  omapi_object_t *h)
500 {
501  u_int32_t bouncer;
502  struct lease *lease;
503  isc_result_t status;
504  u_int8_t flagbuf;
505 
506  if (h -> type != dhcp_type_lease)
507  return DHCP_R_INVALIDARG;
508  lease = (struct lease *)h;
509 
510  /* Write out all the values. */
511 
512  status = omapi_connection_put_named_uint32(c, "state",
513  lease->binding_state);
514  if (status != ISC_R_SUCCESS)
515  return (status);
516 
517  status = omapi_connection_put_name (c, "ip-address");
518  if (status != ISC_R_SUCCESS)
519  return status;
520  status = omapi_connection_put_uint32 (c, lease -> ip_addr.len);
521  if (status != ISC_R_SUCCESS)
522  return status;
523  status = omapi_connection_copyin (c, lease -> ip_addr.iabuf,
524  lease -> ip_addr.len);
525  if (status != ISC_R_SUCCESS)
526  return status;
527 
528  if (lease -> uid_len) {
529  status = omapi_connection_put_name (c,
530  "dhcp-client-identifier");
531  if (status != ISC_R_SUCCESS)
532  return status;
533  status = omapi_connection_put_uint32 (c, lease -> uid_len);
534  if (status != ISC_R_SUCCESS)
535  return status;
536  if (lease -> uid_len) {
537  status = omapi_connection_copyin (c, lease -> uid,
538  lease -> uid_len);
539  if (status != ISC_R_SUCCESS)
540  return status;
541  }
542  }
543 
544  if (lease -> client_hostname) {
545  status = omapi_connection_put_name (c, "client-hostname");
546  if (status != ISC_R_SUCCESS)
547  return status;
548  status =
550  lease -> client_hostname);
551  if (status != ISC_R_SUCCESS)
552  return status;
553  }
554 
555  if (lease -> host) {
556  status = omapi_connection_put_name (c, "host");
557  if (status != ISC_R_SUCCESS)
558  return status;
559  status = omapi_connection_put_handle (c,
560  (omapi_object_t *)
561  lease -> host);
562  if (status != ISC_R_SUCCESS)
563  return status;
564  }
565 
566  status = omapi_connection_put_name (c, "subnet");
567  if (status != ISC_R_SUCCESS)
568  return status;
570  (c, (omapi_object_t *)lease -> subnet);
571  if (status != ISC_R_SUCCESS)
572  return status;
573 
574  status = omapi_connection_put_name (c, "pool");
575  if (status != ISC_R_SUCCESS)
576  return status;
577  status = omapi_connection_put_handle (c,
578  (omapi_object_t *)lease -> pool);
579  if (status != ISC_R_SUCCESS)
580  return status;
581 
582  if (lease -> billing_class) {
583  status = omapi_connection_put_name (c, "billing-class");
584  if (status != ISC_R_SUCCESS)
585  return status;
587  (c, (omapi_object_t *)lease -> billing_class);
588  if (status != ISC_R_SUCCESS)
589  return status;
590  }
591 
592  if (lease -> hardware_addr.hlen) {
593  status = omapi_connection_put_name (c, "hardware-address");
594  if (status != ISC_R_SUCCESS)
595  return status;
597  (c,
598  (unsigned long)(lease -> hardware_addr.hlen - 1)));
599  if (status != ISC_R_SUCCESS)
600  return status;
601  status = (omapi_connection_copyin
602  (c, &lease -> hardware_addr.hbuf [1],
603  (unsigned long)(lease -> hardware_addr.hlen - 1)));
604 
605  if (status != ISC_R_SUCCESS)
606  return status;
607 
608  status = omapi_connection_put_named_uint32(c, "hardware-type",
609  lease->hardware_addr.hbuf[0]);
610  if (status != ISC_R_SUCCESS)
611  return (status);
612  }
613 
614  /* TIME values may be 64-bit, depending on system architecture.
615  * OMAPI must be system independent, both in terms of transmitting
616  * bytes on the wire in network byte order, and in terms of being
617  * readable and usable by both systems.
618  *
619  * XXX: In a future feature release, a put_int64() should be made
620  * to exist, and perhaps a put_time() wrapper that selects which
621  * to use based upon sizeof(TIME). In the meantime, use existing,
622  * 32-bit, code.
623  */
624  bouncer = (u_int32_t)lease->ends;
625  status = omapi_connection_put_named_uint32(c, "ends", bouncer);
626  if (status != ISC_R_SUCCESS)
627  return (status);
628 
629  bouncer = (u_int32_t)lease->starts;
630  status = omapi_connection_put_named_uint32(c, "starts", bouncer);
631  if (status != ISC_R_SUCCESS)
632  return (status);
633 
634  bouncer = (u_int32_t)lease->tstp;
635  status = omapi_connection_put_named_uint32(c, "tstp", bouncer);
636  if (status != ISC_R_SUCCESS)
637  return (status);
638 
639  bouncer = (u_int32_t)lease->tsfp;
640  status = omapi_connection_put_named_uint32(c, "tsfp", bouncer);
641  if (status != ISC_R_SUCCESS)
642  return status;
643 
644  bouncer = (u_int32_t)lease->atsfp;
645  status = omapi_connection_put_named_uint32(c, "atsfp", bouncer);
646  if (status != ISC_R_SUCCESS)
647  return status;
648 
649  bouncer = (u_int32_t)lease->cltt;
650  status = omapi_connection_put_named_uint32(c, "cltt", bouncer);
651  if (status != ISC_R_SUCCESS)
652  return status;
653 
654  status = omapi_connection_put_name (c, "flags");
655  if (status != ISC_R_SUCCESS)
656  return status;
657  status = omapi_connection_put_uint32(c, sizeof(flagbuf));
658  if (status != ISC_R_SUCCESS)
659  return status;
660  flagbuf = lease->flags & EPHEMERAL_FLAGS;
661  status = omapi_connection_copyin(c, &flagbuf, sizeof(flagbuf));
662  if (status != ISC_R_SUCCESS)
663  return status;
664 
665  if (lease -> scope) {
666  status = binding_scope_stuff_values (c, lease -> scope);
667  if (status != ISC_R_SUCCESS)
668  return status;
669  }
670 
671  /* Write out the inner object, if any. */
672  if (h -> inner && h -> inner -> type -> stuff_values) {
673  status = ((*(h -> inner -> type -> stuff_values))
674  (c, id, h -> inner));
675  if (status == ISC_R_SUCCESS)
676  return status;
677  }
678 
679  return ISC_R_SUCCESS;
680 }
681 
683  omapi_object_t *id, omapi_object_t *ref)
684 {
685  omapi_value_t *tv = (omapi_value_t *)0;
686  isc_result_t status;
687  struct lease *lease;
688 
689  if (!ref)
690  return DHCP_R_NOKEYS;
691 
692  /* First see if we were sent a handle. */
693  status = omapi_get_value_str (ref, id, "handle", &tv);
694  if (status == ISC_R_SUCCESS) {
695  status = omapi_handle_td_lookup (lp, tv -> value);
696 
698  if (status != ISC_R_SUCCESS)
699  return status;
700 
701  /* Don't return the object if the type is wrong. */
702  if ((*lp) -> type != dhcp_type_lease) {
704  return DHCP_R_INVALIDARG;
705  }
706  }
707 
708  /* Now look for an IP address. */
709  status = omapi_get_value_str (ref, id, "ip-address", &tv);
710  if (status == ISC_R_SUCCESS) {
711  lease = (struct lease *)0;
712  lease_ip_hash_lookup(&lease, lease_ip_addr_hash,
713  tv->value->u.buffer.value,
714  tv->value->u.buffer.len, MDL);
715 
717 
718  /* If we already have a lease, and it's not the same one,
719  then the query was invalid. */
720  if (*lp && *lp != (omapi_object_t *)lease) {
722  lease_dereference (&lease, MDL);
723  return DHCP_R_KEYCONFLICT;
724  } else if (!lease) {
725  if (*lp)
727  return ISC_R_NOTFOUND;
728  } else if (!*lp) {
729  /* XXX fix so that hash lookup itself creates
730  XXX the reference. */
732  (omapi_object_t *)lease, MDL);
733  lease_dereference (&lease, MDL);
734  }
735  }
736 
737  /* Now look for a client identifier. */
738  status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);
739  if (status == ISC_R_SUCCESS) {
740  lease = (struct lease *)0;
741  lease_id_hash_lookup(&lease, lease_uid_hash,
742  tv->value->u.buffer.value,
743  tv->value->u.buffer.len, MDL);
745 
746  if (*lp && *lp != (omapi_object_t *)lease) {
748  lease_dereference (&lease, MDL);
749  return DHCP_R_KEYCONFLICT;
750  } else if (!lease) {
751  if (*lp)
753  return ISC_R_NOTFOUND;
754  } else if (lease -> n_uid) {
755  if (*lp)
757  return DHCP_R_MULTIPLE;
758  } else if (!*lp) {
759  /* XXX fix so that hash lookup itself creates
760  XXX the reference. */
762  (omapi_object_t *)lease, MDL);
763  lease_dereference (&lease, MDL);
764  }
765  }
766 
767  /* Now look for a hardware address. */
768  status = omapi_get_value_str (ref, id, "hardware-address", &tv);
769  if (status == ISC_R_SUCCESS) {
770  unsigned char *haddr;
771  unsigned int len;
772 
773  len = tv -> value -> u.buffer.len + 1;
774  haddr = dmalloc (len, MDL);
775  if (!haddr) {
777  return ISC_R_NOMEMORY;
778  }
779 
780  memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1);
782 
783  status = omapi_get_value_str (ref, id, "hardware-type", &tv);
784  if (status == ISC_R_SUCCESS) {
785  if (tv -> value -> type == omapi_datatype_data) {
786  if ((tv -> value -> u.buffer.len != 4) ||
787  (tv -> value -> u.buffer.value[0] != 0) ||
788  (tv -> value -> u.buffer.value[1] != 0) ||
789  (tv -> value -> u.buffer.value[2] != 0)) {
791  dfree (haddr, MDL);
792  return DHCP_R_INVALIDARG;
793  }
794 
795  haddr[0] = tv -> value -> u.buffer.value[3];
796  } else if (tv -> value -> type == omapi_datatype_int) {
797  haddr[0] = (unsigned char)
798  tv -> value -> u.integer;
799  } else {
801  dfree (haddr, MDL);
802  return DHCP_R_INVALIDARG;
803  }
804 
806  } else {
807  /* If no hardware-type is specified, default to
808  ethernet. This may or may not be a good idea,
809  but Telus is currently relying on this behavior.
810  - DPN */
811  haddr[0] = HTYPE_ETHER;
812  }
813 
814  lease = (struct lease *)0;
815  lease_id_hash_lookup(&lease, lease_hw_addr_hash, haddr, len,
816  MDL);
817  dfree (haddr, MDL);
818 
819  if (*lp && *lp != (omapi_object_t *)lease) {
821  lease_dereference (&lease, MDL);
822  return DHCP_R_KEYCONFLICT;
823  } else if (!lease) {
824  if (*lp)
826  return ISC_R_NOTFOUND;
827  } else if (lease -> n_hw) {
828  if (*lp)
830  lease_dereference (&lease, MDL);
831  return DHCP_R_MULTIPLE;
832  } else if (!*lp) {
833  /* XXX fix so that hash lookup itself creates
834  XXX the reference. */
836  (omapi_object_t *)lease, MDL);
837  lease_dereference (&lease, MDL);
838  }
839  }
840 
841  /* If we get to here without finding a lease, no valid key was
842  specified. */
843  if (!*lp)
844  return DHCP_R_NOKEYS;
845  return ISC_R_SUCCESS;
846 }
847 
849  omapi_object_t *id)
850 {
851  return ISC_R_NOTIMPLEMENTED;
852 }
853 
855  omapi_object_t *id)
856 {
857  return ISC_R_NOTIMPLEMENTED;
858 }
859 
861  omapi_object_t *id,
862  omapi_data_string_t *name,
863  omapi_typed_data_t *value)
864 {
865  struct host_decl *host;
866  isc_result_t status;
867 
868  if (h -> type != dhcp_type_host)
869  return DHCP_R_INVALIDARG;
870  host = (struct host_decl *)h;
871 
872  /* XXX For now, we can only set these values on new host objects.
873  XXX Soon, we need to be able to update host objects. */
874  if (!omapi_ds_strcmp (name, "name")) {
875  if (host -> name)
876  return ISC_R_EXISTS;
877  if (value && (value -> type == omapi_datatype_data ||
878  value -> type == omapi_datatype_string)) {
879  host -> name = dmalloc (value -> u.buffer.len + 1,
880  MDL);
881  if (!host -> name)
882  return ISC_R_NOMEMORY;
883  memcpy (host -> name,
884  value -> u.buffer.value,
885  value -> u.buffer.len);
886  host -> name [value -> u.buffer.len] = 0;
887  } else
888  return DHCP_R_INVALIDARG;
889  return ISC_R_SUCCESS;
890  }
891 
892  if (!omapi_ds_strcmp (name, "group")) {
893  if (value && (value -> type == omapi_datatype_data ||
894  value -> type == omapi_datatype_string)) {
895  struct group_object *group;
896  group = (struct group_object *)0;
897  group_hash_lookup (&group, group_name_hash,
898  (char *)value -> u.buffer.value,
899  value -> u.buffer.len, MDL);
900  if (!group || (group -> flags & GROUP_OBJECT_DELETED))
901  return ISC_R_NOTFOUND;
902  if (host -> group)
903  group_dereference (&host -> group, MDL);
904  group_reference (&host -> group, group -> group, MDL);
905  if (host -> named_group)
906  group_object_dereference (&host -> named_group,
907  MDL);
908  group_object_reference (&host -> named_group,
909  group, MDL);
910  group_object_dereference (&group, MDL);
911  } else
912  return DHCP_R_INVALIDARG;
913  return ISC_R_SUCCESS;
914  }
915 
916  if (!omapi_ds_strcmp (name, "hardware-address")) {
917  if (host -> interface.hlen)
918  return ISC_R_EXISTS;
919  if (value && (value -> type == omapi_datatype_data ||
920  value -> type == omapi_datatype_string)) {
921  if (value -> u.buffer.len >
922  (sizeof host -> interface.hbuf) - 1)
923  return DHCP_R_INVALIDARG;
924  memcpy (&host -> interface.hbuf [1],
925  value -> u.buffer.value,
926  value -> u.buffer.len);
927  host -> interface.hlen = value -> u.buffer.len + 1;
928  } else
929  return DHCP_R_INVALIDARG;
930  return ISC_R_SUCCESS;
931  }
932 
933  if (!omapi_ds_strcmp (name, "hardware-type")) {
934  int type;
935  if ((value != NULL) &&
936  ((value->type == omapi_datatype_data) &&
937  (value->u.buffer.len == sizeof(type)))) {
938  if (value->u.buffer.len > sizeof(type))
939  return (DHCP_R_INVALIDARG);
940  memcpy(&type, value->u.buffer.value,
941  value->u.buffer.len);
942  type = ntohl(type);
943  } else if ((value != NULL) &&
944  (value->type == omapi_datatype_int))
945  type = value->u.integer;
946  else
947  return (DHCP_R_INVALIDARG);
948  host->interface.hbuf[0] = type;
949  return (ISC_R_SUCCESS);
950  }
951 
952  if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
953  if (host -> client_identifier.data)
954  return ISC_R_EXISTS;
955  if (value && (value -> type == omapi_datatype_data ||
956  value -> type == omapi_datatype_string)) {
957  if (!buffer_allocate (&host -> client_identifier.buffer,
958  value -> u.buffer.len, MDL))
959  return ISC_R_NOMEMORY;
960  host -> client_identifier.data =
961  &host -> client_identifier.buffer -> data [0];
962  memcpy (host -> client_identifier.buffer -> data,
963  value -> u.buffer.value,
964  value -> u.buffer.len);
965  host -> client_identifier.len = value -> u.buffer.len;
966  } else
967  return DHCP_R_INVALIDARG;
968  return ISC_R_SUCCESS;
969  }
970 
971  if (!omapi_ds_strcmp (name, "ip-address")) {
972  if (host -> fixed_addr)
973  option_cache_dereference (&host -> fixed_addr, MDL);
974  if (!value)
975  return ISC_R_SUCCESS;
976  if (value && (value -> type == omapi_datatype_data ||
977  value -> type == omapi_datatype_string)) {
978  struct data_string ds;
979  memset (&ds, 0, sizeof ds);
980  ds.len = value -> u.buffer.len;
981  if (!buffer_allocate (&ds.buffer, ds.len, MDL))
982  return ISC_R_NOMEMORY;
983  ds.data = (&ds.buffer -> data [0]);
984  memcpy (ds.buffer -> data,
985  value -> u.buffer.value, ds.len);
986  if (!option_cache (&host -> fixed_addr,
987  &ds, (struct expression *)0,
988  (struct option *)0, MDL)) {
989  data_string_forget (&ds, MDL);
990  return ISC_R_NOMEMORY;
991  }
992  data_string_forget (&ds, MDL);
993  } else
994  return DHCP_R_INVALIDARG;
995  return ISC_R_SUCCESS;
996  }
997 
998  if (!omapi_ds_strcmp (name, "statements")) {
999  if (!host -> group) {
1000  if (!clone_group (&host -> group, root_group, MDL))
1001  return ISC_R_NOMEMORY;
1002  } else {
1003  if (host -> group -> statements &&
1004  (!host -> named_group ||
1005  host -> group != host -> named_group -> group) &&
1006  host -> group != root_group)
1007  return ISC_R_EXISTS;
1008  if (!clone_group (&host -> group, host -> group, MDL))
1009  return ISC_R_NOMEMORY;
1010  }
1011  if (!host -> group)
1012  return ISC_R_NOMEMORY;
1013  if (value && (value -> type == omapi_datatype_data ||
1014  value -> type == omapi_datatype_string)) {
1015  struct parse *parse;
1016  int lose = 0;
1017  parse = (struct parse *)0;
1018  status = new_parse(&parse, -1,
1019  (char *) value->u.buffer.value,
1020  value->u.buffer.len,
1021  "network client", 0);
1022  if (status != ISC_R_SUCCESS || parse == NULL)
1023  return status;
1024 
1026  (&host -> group -> statements, parse, &lose,
1027  context_any))) {
1028  end_parse (&parse);
1029  return DHCP_R_BADPARSE;
1030  }
1031  end_parse (&parse);
1032  } else
1033  return DHCP_R_INVALIDARG;
1034  return ISC_R_SUCCESS;
1035  }
1036 
1037  /* The "known" flag isn't supported in the database yet, but it's
1038  legitimate. */
1039  if (!omapi_ds_strcmp (name, "known")) {
1040  return ISC_R_SUCCESS;
1041  }
1042 
1043  /* Try to find some inner object that can take the value. */
1044  if (h -> inner && h -> inner -> type -> set_value) {
1045  status = ((*(h -> inner -> type -> set_value))
1046  (h -> inner, id, name, value));
1047  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1048  return status;
1049  }
1050 
1051  return DHCP_R_UNKNOWNATTRIBUTE;
1052 }
1053 
1054 
1056  omapi_data_string_t *name,
1057  omapi_value_t **value)
1058 {
1059  struct host_decl *host;
1060  isc_result_t status;
1061  struct data_string ip_addrs;
1062 
1063  if (h -> type != dhcp_type_host)
1064  return DHCP_R_INVALIDARG;
1065  host = (struct host_decl *)h;
1066 
1067  if (!omapi_ds_strcmp (name, "ip-addresses")) {
1068  memset (&ip_addrs, 0, sizeof ip_addrs);
1069  if (host -> fixed_addr &&
1070  evaluate_option_cache (&ip_addrs, (struct packet *)0,
1071  (struct lease *)0,
1072  (struct client_state *)0,
1073  (struct option_state *)0,
1074  (struct option_state *)0,
1075  &global_scope,
1076  host -> fixed_addr, MDL)) {
1077  status = omapi_make_const_value (value, name,
1078  ip_addrs.data,
1079  ip_addrs.len, MDL);
1080  data_string_forget (&ip_addrs, MDL);
1081  return status;
1082  }
1083  return ISC_R_NOTFOUND;
1084  }
1085 
1086  if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
1087  if (!host -> client_identifier.len)
1088  return ISC_R_NOTFOUND;
1089  return omapi_make_const_value (value, name,
1090  host -> client_identifier.data,
1091  host -> client_identifier.len,
1092  MDL);
1093  }
1094 
1095  if (!omapi_ds_strcmp (name, "name"))
1096  return omapi_make_string_value (value, name, host -> name,
1097  MDL);
1098 
1099  if (!omapi_ds_strcmp (name, "hardware-address")) {
1100  if (!host -> interface.hlen)
1101  return ISC_R_NOTFOUND;
1102  return (omapi_make_const_value
1103  (value, name, &host -> interface.hbuf [1],
1104  (unsigned long)(host -> interface.hlen - 1), MDL));
1105  }
1106 
1107  if (!omapi_ds_strcmp (name, "hardware-type")) {
1108  if (!host -> interface.hlen)
1109  return ISC_R_NOTFOUND;
1110  return omapi_make_int_value (value, name,
1111  host -> interface.hbuf [0], MDL);
1112  }
1113 
1114  /* Try to find some inner object that can take the value. */
1115  if (h -> inner && h -> inner -> type -> get_value) {
1116  status = ((*(h -> inner -> type -> get_value))
1117  (h -> inner, id, name, value));
1118  if (status == ISC_R_SUCCESS)
1119  return status;
1120  }
1121  return DHCP_R_UNKNOWNATTRIBUTE;
1122 }
1123 
1124 isc_result_t dhcp_host_destroy (omapi_object_t *h, const char *file, int line)
1125 {
1126 
1127  if (h -> type != dhcp_type_host)
1128  return DHCP_R_INVALIDARG;
1129 
1130  struct host_decl *host = (struct host_decl *)h;
1131  if (host -> n_ipaddr)
1132  host_dereference (&host -> n_ipaddr, file, line);
1133  if (host -> n_dynamic)
1134  host_dereference (&host -> n_dynamic, file, line);
1135  if (host -> name) {
1136  dfree (host -> name, file, line);
1137  host -> name = (char *)0;
1138  }
1139  data_string_forget (&host -> client_identifier, file, line);
1140  if (host -> fixed_addr)
1141  option_cache_dereference (&host -> fixed_addr, file, line);
1142  if (host -> group)
1143  group_dereference (&host -> group, file, line);
1144  if (host -> named_group)
1146  &host -> named_group, file, line);
1147  data_string_forget (&host -> auth_key_id, file, line);
1148 
1149  return ISC_R_SUCCESS;
1150 }
1151 
1153  const char *name, va_list ap)
1154 {
1155  struct host_decl *host;
1156  isc_result_t status;
1157  int updatep = 0;
1158 
1159  if (h -> type != dhcp_type_host)
1160  return DHCP_R_INVALIDARG;
1161  host = (struct host_decl *)h;
1162 
1163  if (!strcmp (name, "updated")) {
1164  /* There must be a client identifier of some sort. */
1165  if (host -> interface.hlen == 0 &&
1166  !host -> client_identifier.len)
1167  return DHCP_R_INVALIDARG;
1168 
1169  if (!host -> name) {
1170  char hnbuf [64];
1171  sprintf (hnbuf, "nh%08lx%08lx",
1172  (unsigned long)cur_time, (unsigned long)host);
1173  host -> name = dmalloc (strlen (hnbuf) + 1, MDL);
1174  if (!host -> name)
1175  return ISC_R_NOMEMORY;
1176  strcpy (host -> name, hnbuf);
1177  }
1178 
1179 #ifdef DEBUG_OMAPI
1180  log_debug ("OMAPI added host %s", host -> name);
1181 #endif
1182  status = enter_host (host, 1, 1);
1183  if (status != ISC_R_SUCCESS)
1184  return status;
1185  updatep = 1;
1186  }
1187 
1188  /* Try to find some inner object that can take the value. */
1189  if (h -> inner && h -> inner -> type -> signal_handler) {
1190  status = ((*(h -> inner -> type -> signal_handler))
1191  (h -> inner, name, ap));
1192  if (status == ISC_R_SUCCESS)
1193  return status;
1194  }
1195  if (updatep)
1196  return ISC_R_SUCCESS;
1197  return ISC_R_NOTFOUND;
1198 }
1199 
1201  omapi_object_t *id,
1202  omapi_object_t *h)
1203 {
1204  struct host_decl *host;
1205  isc_result_t status;
1206  struct data_string ip_addrs;
1207 
1208  if (h -> type != dhcp_type_host)
1209  return DHCP_R_INVALIDARG;
1210  host = (struct host_decl *)h;
1211 
1212  /* Write out all the values. */
1213 
1214  memset (&ip_addrs, 0, sizeof ip_addrs);
1215  if (host -> fixed_addr &&
1216  evaluate_option_cache (&ip_addrs, (struct packet *)0,
1217  (struct lease *)0,
1218  (struct client_state *)0,
1219  (struct option_state *)0,
1220  (struct option_state *)0,
1221  &global_scope,
1222  host -> fixed_addr, MDL)) {
1223  status = omapi_connection_put_name (c, "ip-address");
1224  if (status != ISC_R_SUCCESS)
1225  return status;
1226  status = omapi_connection_put_uint32 (c, ip_addrs.len);
1227  if (status != ISC_R_SUCCESS)
1228  return status;
1229  status = omapi_connection_copyin (c,
1230  ip_addrs.data, ip_addrs.len);
1231  if (status != ISC_R_SUCCESS)
1232  return status;
1233  data_string_forget (&ip_addrs, MDL);
1234  }
1235 
1236  if (host -> client_identifier.len) {
1237  status = omapi_connection_put_name (c,
1238  "dhcp-client-identifier");
1239  if (status != ISC_R_SUCCESS)
1240  return status;
1241  status = (omapi_connection_put_uint32
1242  (c, host -> client_identifier.len));
1243  if (status != ISC_R_SUCCESS)
1244  return status;
1245  status = (omapi_connection_copyin
1246  (c,
1247  host -> client_identifier.data,
1248  host -> client_identifier.len));
1249  if (status != ISC_R_SUCCESS)
1250  return status;
1251  }
1252 
1253  if (host -> name) {
1254  status = omapi_connection_put_name (c, "name");
1255  if (status != ISC_R_SUCCESS)
1256  return status;
1257  status = omapi_connection_put_string (c, host -> name);
1258  if (status != ISC_R_SUCCESS)
1259  return status;
1260  }
1261 
1262  if (host -> interface.hlen) {
1263  status = omapi_connection_put_name (c, "hardware-address");
1264  if (status != ISC_R_SUCCESS)
1265  return status;
1266  status = (omapi_connection_put_uint32
1267  (c, (unsigned long)(host -> interface.hlen - 1)));
1268  if (status != ISC_R_SUCCESS)
1269  return status;
1270  status = (omapi_connection_copyin
1271  (c, &host -> interface.hbuf [1],
1272  (unsigned long)(host -> interface.hlen - 1)));
1273  if (status != ISC_R_SUCCESS)
1274  return status;
1275 
1276  status = omapi_connection_put_named_uint32(c, "hardware-type",
1277  host->interface.hbuf[0]);
1278  if (status != ISC_R_SUCCESS)
1279  return status;
1280  }
1281 
1282  /* Write out the inner object, if any. */
1283  if (h -> inner && h -> inner -> type -> stuff_values) {
1284  status = ((*(h -> inner -> type -> stuff_values))
1285  (c, id, h -> inner));
1286  if (status == ISC_R_SUCCESS)
1287  return status;
1288  }
1289 
1290  return ISC_R_SUCCESS;
1291 }
1292 
1294  omapi_object_t *id, omapi_object_t *ref)
1295 {
1296  omapi_value_t *tv = (omapi_value_t *)0;
1297  isc_result_t status;
1298  struct host_decl *host;
1299 
1300  if (!ref)
1301  return DHCP_R_NOKEYS;
1302 
1303  /* First see if we were sent a handle. */
1304  status = omapi_get_value_str (ref, id, "handle", &tv);
1305  if (status == ISC_R_SUCCESS) {
1306  status = omapi_handle_td_lookup (lp, tv -> value);
1307 
1309  if (status != ISC_R_SUCCESS)
1310  return status;
1311 
1312  /* Don't return the object if the type is wrong. */
1313  if ((*lp) -> type != dhcp_type_host) {
1315  return DHCP_R_INVALIDARG;
1316  }
1317  if (((struct host_decl *)(*lp)) -> flags & HOST_DECL_DELETED) {
1319  }
1320  }
1321 
1322  /* Now look for a client identifier. */
1323  status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);
1324  if (status == ISC_R_SUCCESS) {
1325  host = (struct host_decl *)0;
1326  host_hash_lookup (&host, host_uid_hash,
1327  tv -> value -> u.buffer.value,
1328  tv -> value -> u.buffer.len, MDL);
1330 
1331  if (*lp && *lp != (omapi_object_t *)host) {
1333  if (host)
1334  host_dereference (&host, MDL);
1335  return DHCP_R_KEYCONFLICT;
1336  } else if (!host || (host -> flags & HOST_DECL_DELETED)) {
1337  if (*lp)
1339  if (host)
1340  host_dereference (&host, MDL);
1341  return ISC_R_NOTFOUND;
1342  } else if (!*lp) {
1343  /* XXX fix so that hash lookup itself creates
1344  XXX the reference. */
1346  (omapi_object_t *)host, MDL);
1347  host_dereference (&host, MDL);
1348  }
1349  }
1350 
1351  /* Now look for a hardware address. */
1352  status = omapi_get_value_str (ref, id, "hardware-address", &tv);
1353  if (status == ISC_R_SUCCESS) {
1354  unsigned char *haddr;
1355  unsigned int len;
1356 
1357  len = tv -> value -> u.buffer.len + 1;
1358  haddr = dmalloc (len, MDL);
1359  if (!haddr) {
1361  return ISC_R_NOMEMORY;
1362  }
1363 
1364  memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1);
1366 
1367  status = omapi_get_value_str (ref, id, "hardware-type", &tv);
1368  if (status == ISC_R_SUCCESS) {
1369  if (tv -> value -> type == omapi_datatype_data) {
1370  if ((tv -> value -> u.buffer.len != 4) ||
1371  (tv -> value -> u.buffer.value[0] != 0) ||
1372  (tv -> value -> u.buffer.value[1] != 0) ||
1373  (tv -> value -> u.buffer.value[2] != 0)) {
1375  dfree (haddr, MDL);
1376  return DHCP_R_INVALIDARG;
1377  }
1378 
1379  haddr[0] = tv -> value -> u.buffer.value[3];
1380  } else if (tv -> value -> type == omapi_datatype_int) {
1381  haddr[0] = (unsigned char)
1382  tv -> value -> u.integer;
1383  } else {
1385  dfree (haddr, MDL);
1386  return DHCP_R_INVALIDARG;
1387  }
1388 
1390  } else {
1391  /* If no hardware-type is specified, default to
1392  ethernet. This may or may not be a good idea,
1393  but Telus is currently relying on this behavior.
1394  - DPN */
1395  haddr[0] = HTYPE_ETHER;
1396  }
1397 
1398  host = (struct host_decl *)0;
1399  host_hash_lookup (&host, host_hw_addr_hash, haddr, len, MDL);
1400  dfree (haddr, MDL);
1401 
1402  if (*lp && *lp != (omapi_object_t *)host) {
1404  if (host)
1405  host_dereference (&host, MDL);
1406  return DHCP_R_KEYCONFLICT;
1407  } else if (!host || (host -> flags & HOST_DECL_DELETED)) {
1408  if (*lp)
1410  if (host)
1411  host_dereference (&host, MDL);
1412  return ISC_R_NOTFOUND;
1413  } else if (!*lp) {
1414  /* XXX fix so that hash lookup itself creates
1415  XXX the reference. */
1417  (omapi_object_t *)host, MDL);
1418  host_dereference (&host, MDL);
1419  }
1420  }
1421 
1422  /* Now look for an ip address. */
1423  status = omapi_get_value_str (ref, id, "ip-address", &tv);
1424  if (status == ISC_R_SUCCESS) {
1425  struct lease *l;
1426 
1427  /* first find the lease for this ip address */
1428  l = (struct lease *)0;
1429  lease_ip_hash_lookup(&l, lease_ip_addr_hash,
1430  tv->value->u.buffer.value,
1431  tv->value->u.buffer.len, MDL);
1433 
1434  if (!l && !*lp)
1435  return ISC_R_NOTFOUND;
1436 
1437  if (l) {
1438  /* now use that to get a host */
1439  host = (struct host_decl *)0;
1440  host_hash_lookup (&host, host_hw_addr_hash,
1441  l -> hardware_addr.hbuf,
1442  l -> hardware_addr.hlen, MDL);
1443 
1444  if (host && *lp && *lp != (omapi_object_t *)host) {
1446  if (host)
1447  host_dereference (&host, MDL);
1448  return DHCP_R_KEYCONFLICT;
1449  } else if (!host || (host -> flags &
1450  HOST_DECL_DELETED)) {
1451  if (host)
1452  host_dereference (&host, MDL);
1453  if (!*lp)
1454  return ISC_R_NOTFOUND;
1455  } else if (!*lp) {
1456  /* XXX fix so that hash lookup itself creates
1457  XXX the reference. */
1459  MDL);
1460  host_dereference (&host, MDL);
1461  }
1462  lease_dereference (&l, MDL);
1463  }
1464  }
1465 
1466  /* Now look for a name. */
1467  status = omapi_get_value_str (ref, id, "name", &tv);
1468  if (status == ISC_R_SUCCESS) {
1469  host = (struct host_decl *)0;
1470  host_hash_lookup (&host, host_name_hash,
1471  tv -> value -> u.buffer.value,
1472  tv -> value -> u.buffer.len, MDL);
1474 
1475  if (*lp && *lp != (omapi_object_t *)host) {
1477  if (host)
1478  host_dereference (&host, MDL);
1479  return DHCP_R_KEYCONFLICT;
1480  } else if (!host || (host -> flags & HOST_DECL_DELETED)) {
1481  if (host)
1482  host_dereference (&host, MDL);
1483  return ISC_R_NOTFOUND;
1484  } else if (!*lp) {
1485  /* XXX fix so that hash lookup itself creates
1486  XXX the reference. */
1488  (omapi_object_t *)host, MDL);
1489  host_dereference (&host, MDL);
1490  }
1491  }
1492 
1493  /* If we get to here without finding a host, no valid key was
1494  specified. */
1495  if (!*lp)
1496  return DHCP_R_NOKEYS;
1497  return ISC_R_SUCCESS;
1498 }
1499 
1501  omapi_object_t *id)
1502 {
1503  struct host_decl *hp;
1504  isc_result_t status;
1505  hp = (struct host_decl *)0;
1506  status = host_allocate (&hp, MDL);
1507  if (status != ISC_R_SUCCESS)
1508  return status;
1509  group_reference (&hp -> group, root_group, MDL);
1510  hp -> flags = HOST_DECL_DYNAMIC;
1511  status = omapi_object_reference (lp, (omapi_object_t *)hp, MDL);
1512  host_dereference (&hp, MDL);
1513  return status;
1514 }
1515 
1517  omapi_object_t *id)
1518 {
1519  struct host_decl *hp;
1520  if (lp -> type != dhcp_type_host)
1521  return DHCP_R_INVALIDARG;
1522  hp = (struct host_decl *)lp;
1523 
1524 #ifdef DEBUG_OMAPI
1525  log_debug ("OMAPI delete host %s", hp -> name);
1526 #endif
1527  delete_host (hp, 1);
1528  return ISC_R_SUCCESS;
1529 }
1530 
1532  omapi_object_t *id,
1534  omapi_typed_data_t *value)
1535 {
1536  /* h should point to (struct pool *) */
1537  isc_result_t status;
1538 
1539  if (h -> type != dhcp_type_pool)
1540  return DHCP_R_INVALIDARG;
1541 
1542  /* No values to set yet. */
1543 
1544  /* Try to find some inner object that can take the value. */
1545  if (h -> inner && h -> inner -> type -> set_value) {
1546  status = ((*(h -> inner -> type -> set_value))
1547  (h -> inner, id, name, value));
1548  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1549  return status;
1550  }
1551 
1552  return DHCP_R_UNKNOWNATTRIBUTE;
1553 }
1554 
1555 
1558  omapi_value_t **value)
1559 {
1560  /* h should point to (struct pool *) */
1561  isc_result_t status;
1562 
1563  if (h -> type != dhcp_type_pool)
1564  return DHCP_R_INVALIDARG;
1565 
1566  /* No values to get yet. */
1567 
1568  /* Try to find some inner object that can provide the value. */
1569  if (h -> inner && h -> inner -> type -> get_value) {
1570  status = ((*(h -> inner -> type -> get_value))
1571  (h -> inner, id, name, value));
1572  if (status == ISC_R_SUCCESS)
1573  return status;
1574  }
1575  return DHCP_R_UNKNOWNATTRIBUTE;
1576 }
1577 
1578 isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line)
1579 {
1580 #if defined (DEBUG_MEMORY_LEAKAGE) || \
1581  defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1582  struct permit *pc, *pn;
1583 #endif
1584 
1585  if (h -> type != dhcp_type_pool)
1586  return DHCP_R_INVALIDARG;
1587 
1588 #if defined (DEBUG_MEMORY_LEAKAGE) || \
1589  defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1590  struct pool *pool = (struct pool *)h;
1591  if (pool -> next)
1592  pool_dereference (&pool -> next, file, line);
1593  if (pool -> group)
1594  group_dereference (&pool -> group, file, line);
1595  if (pool -> shared_network)
1596  shared_network_dereference (&pool -> shared_network, file, line);
1597  if (pool -> active)
1598  lease_dereference (&pool -> active, file, line);
1599  if (pool -> expired)
1600  lease_dereference (&pool -> expired, file, line);
1601  if (pool -> free)
1602  lease_dereference (&pool -> free, file, line);
1603  if (pool -> backup)
1604  lease_dereference (&pool -> backup, file, line);
1605  if (pool -> abandoned)
1606  lease_dereference (&pool -> abandoned, file, line);
1607 #if defined (FAILOVER_PROTOCOL)
1608  if (pool -> failover_peer)
1609  dhcp_failover_state_dereference (&pool -> failover_peer,
1610  file, line);
1611 #endif
1612  for (pc = pool -> permit_list; pc; pc = pn) {
1613  pn = pc -> next;
1614  free_permit (pc, file, line);
1615  }
1616  pool -> permit_list = (struct permit *)0;
1617 
1618  for (pc = pool -> prohibit_list; pc; pc = pn) {
1619  pn = pc -> next;
1620  free_permit (pc, file, line);
1621  }
1622  pool -> prohibit_list = (struct permit *)0;
1623 #endif
1624 
1625  return ISC_R_SUCCESS;
1626 }
1627 
1629  const char *name, va_list ap)
1630 {
1631  /* h should point to (struct pool *) */
1632  isc_result_t status;
1633 
1634  if (h -> type != dhcp_type_pool)
1635  return DHCP_R_INVALIDARG;
1636 
1637  /* Can't write pools yet. */
1638 
1639  /* Try to find some inner object that can take the value. */
1640  if (h -> inner && h -> inner -> type -> signal_handler) {
1641  status = ((*(h -> inner -> type -> signal_handler))
1642  (h -> inner, name, ap));
1643  if (status == ISC_R_SUCCESS)
1644  return status;
1645  }
1646 
1647  return ISC_R_NOTFOUND;
1648 }
1649 
1651  omapi_object_t *id,
1652  omapi_object_t *h)
1653 {
1654  struct pool *pool;
1655  isc_result_t status;
1656 
1657  if (h->type != dhcp_type_pool)
1658  return (DHCP_R_INVALIDARG);
1659  pool = (struct pool *)h;
1660 
1661  /*
1662  * I don't think we can actually find a pool yet
1663  * but include the output of interesting values
1664  * for when we do
1665  */
1666  status = omapi_connection_put_named_uint32(c, "lease-count",
1667  ((u_int32_t)
1668  pool->lease_count));
1669  if (status != ISC_R_SUCCESS)
1670  return (status);
1671 
1672  status = omapi_connection_put_named_uint32(c, "free-leases",
1673  ((u_int32_t)
1674  pool->free_leases));
1675  if (status != ISC_R_SUCCESS)
1676  return (status);
1677 
1678  status = omapi_connection_put_named_uint32(c, "backup-leases",
1679  ((u_int32_t)
1680  pool->backup_leases));
1681  if (status != ISC_R_SUCCESS)
1682  return (status);
1683  /* we could add time stamps but lets wait on those */
1684 
1685  /* Write out the inner object, if any. */
1686  if (h->inner && h->inner->type->stuff_values) {
1687  status = ((*(h->inner->type->stuff_values))
1688  (c, id, h->inner));
1689  if (status == ISC_R_SUCCESS)
1690  return (status);
1691  }
1692 
1693  return (ISC_R_SUCCESS);
1694 }
1695 
1697  omapi_object_t *id, omapi_object_t *ref)
1698 {
1699  /* Can't look up pools yet. */
1700 
1701  /* If we get to here without finding a pool, no valid key was
1702  specified. */
1703  if (!*lp)
1704  return DHCP_R_NOKEYS;
1705  return ISC_R_SUCCESS;
1706 }
1707 
1709  omapi_object_t *id)
1710 {
1711  return ISC_R_NOTIMPLEMENTED;
1712 }
1713 
1715  omapi_object_t *id)
1716 {
1717  return ISC_R_NOTIMPLEMENTED;
1718 }
1719 
1720 static isc_result_t
1721 class_set_value (omapi_object_t *h,
1722  omapi_object_t *id,
1723  omapi_data_string_t *name,
1724  omapi_typed_data_t *value)
1725 {
1726  struct class *class;
1727  struct class *superclass = 0;
1728  isc_result_t status;
1729  int issubclass = (h -> type == dhcp_type_subclass);
1730 
1731  class = (struct class *)h;
1732 
1733  if (!omapi_ds_strcmp(name, "name")) {
1734  char *tname;
1735 
1736  if (class->name)
1737  return ISC_R_EXISTS;
1738 
1739  if ((tname = dmalloc(value->u.buffer.len + 1, MDL)) == NULL) {
1740  return ISC_R_NOMEMORY;
1741  }
1742 
1743  /* tname is null terminated from dmalloc() */
1744  memcpy(tname, value->u.buffer.value, value->u.buffer.len);
1745 
1746  if (issubclass) {
1747  status = find_class(&superclass, tname, MDL);
1748  dfree(tname, MDL);
1749 
1750  if (status == ISC_R_NOTFOUND)
1751  return status;
1752 
1753  if (class->superclass != NULL)
1754  class_dereference(&class->superclass, MDL);
1755  class_reference(&class->superclass, superclass, MDL);
1756 
1757  if (class->group != NULL)
1758  group_dereference(&class->group, MDL);
1759  group_reference(&class->group, superclass->group, MDL);
1760 
1761  class->lease_limit = superclass->lease_limit;
1762  if (class->lease_limit != 0) {
1763  class->billed_leases =
1764  dmalloc(class->lease_limit *
1765  sizeof(struct lease *),
1766  MDL);
1767  if (class->billed_leases == NULL) {
1768  return ISC_R_NOMEMORY;
1769  }
1770  }
1771 
1772  } else if (value->type == omapi_datatype_data ||
1773  value->type == omapi_datatype_string) {
1774  class->name = dmalloc(value->u.buffer.len + 1, MDL);
1775  if (!class->name)
1776  return ISC_R_NOMEMORY;
1777 
1778  /* class->name is null-terminated from dmalloc() */
1779  memcpy(class->name, value->u.buffer.value,
1780  value->u.buffer.len);
1781  } else
1782  return DHCP_R_INVALIDARG;
1783 
1784  return ISC_R_SUCCESS;
1785  }
1786 
1787 
1788  if (issubclass && !omapi_ds_strcmp(name, "hashstring")) {
1789  if (class->hash_string.data)
1790  return ISC_R_EXISTS;
1791 
1792  if (value->type == omapi_datatype_data ||
1793  value->type == omapi_datatype_string) {
1794  if (!buffer_allocate(&class->hash_string.buffer,
1795  value->u.buffer.len, MDL))
1796  return ISC_R_NOMEMORY;
1797  class->hash_string.data =
1798  class->hash_string.buffer->data;
1799  memcpy(class->hash_string.buffer->data,
1800  value->u.buffer.value, value->u.buffer.len);
1801  class->hash_string.len = value->u.buffer.len;
1802  } else
1803  return DHCP_R_INVALIDARG;
1804 
1805  return ISC_R_SUCCESS;
1806  }
1807 
1808  if (!omapi_ds_strcmp(name, "group")) {
1809  if (value->type == omapi_datatype_data ||
1810  value->type == omapi_datatype_string) {
1811  struct group_object *group = NULL;
1812 
1813  group_hash_lookup(&group, group_name_hash,
1814  (char *)value->u.buffer.value,
1815  value->u.buffer.len, MDL);
1816  if (!group || (group->flags & GROUP_OBJECT_DELETED))
1817  return ISC_R_NOTFOUND;
1818  if (class->group)
1819  group_dereference(&class->group, MDL);
1820  group_reference(&class->group, group->group, MDL);
1821  group_object_dereference(&group, MDL);
1822  } else
1823  return DHCP_R_INVALIDARG;
1824 
1825  return ISC_R_SUCCESS;
1826  }
1827 
1828 
1829  /* note we do not support full expressions via omapi because the
1830  expressions parser needs to be re-done to support parsing from
1831  strings and not just files. */
1832 
1833  if (!omapi_ds_strcmp(name, "match")) {
1834  if (value->type == omapi_datatype_data ||
1835  value->type == omapi_datatype_string) {
1836  unsigned minlen = (value->u.buffer.len > 8 ?
1837  8 : value->u.buffer.len);
1838 
1839  if (!strncmp("hardware",
1840  (char *)value->u.buffer.value, minlen))
1841  {
1842  if (!expression_allocate(&class->submatch, MDL))
1843  return ISC_R_NOMEMORY;
1844 
1845  class->submatch->op = expr_hardware;
1846  } else
1847  return DHCP_R_INVALIDARG;
1848  } else
1849  return DHCP_R_INVALIDARG;
1850 
1851  return ISC_R_SUCCESS;
1852  }
1853 
1854 
1855  if (!omapi_ds_strcmp(name, "option")) {
1856  if (value->type == omapi_datatype_data ||
1857  value->type == omapi_datatype_string) {
1858  /* XXXJAB support 'options' here. */
1859  /* XXXJAB specifically 'bootfile-name' */
1860  return DHCP_R_INVALIDARG; /* XXX tmp */
1861  } else
1862  return DHCP_R_INVALIDARG;
1863 
1864  /*
1865  * Currently no way to get here, if we update the above
1866  * code so that we do get here this return needs to be
1867  * uncommented.
1868  * return ISC_R_SUCCESS;
1869  */
1870  }
1871 
1872 
1873  /* Try to find some inner object that can take the value. */
1874  if (h->inner && h->inner->type->set_value) {
1875  status = ((*(h->inner->type->set_value))
1876  (h->inner, id, name, value));
1877  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1878  return status;
1879  }
1880 
1881  return DHCP_R_UNKNOWNATTRIBUTE;
1882 }
1883 
1884 
1885 
1887  omapi_object_t *id,
1888  omapi_data_string_t *name,
1889  omapi_typed_data_t *value)
1890 {
1891  if (h -> type != dhcp_type_class)
1892  return DHCP_R_INVALIDARG;
1893 
1894  return class_set_value(h, id, name, value);
1895 }
1896 
1898  omapi_data_string_t *name,
1899  omapi_value_t **value)
1900 {
1901  struct class *class;
1902  isc_result_t status;
1903 
1904  if (h -> type != dhcp_type_class)
1905  return DHCP_R_INVALIDARG;
1906  class = (struct class *)h;
1907 
1908  if (!omapi_ds_strcmp (name, "name"))
1909  return omapi_make_string_value (value, name, class -> name,
1910  MDL);
1911 
1912  /* Try to find some inner object that can provide the value. */
1913  if (h -> inner && h -> inner -> type -> get_value) {
1914  status = ((*(h -> inner -> type -> get_value))
1915  (h -> inner, id, name, value));
1916  if (status == ISC_R_SUCCESS)
1917  return status;
1918  }
1919  return DHCP_R_UNKNOWNATTRIBUTE;
1920 }
1921 
1922 isc_result_t dhcp_class_destroy (omapi_object_t *h, const char *file, int line)
1923 {
1924 
1925  if (h -> type != dhcp_type_class && h -> type != dhcp_type_subclass)
1926  return DHCP_R_INVALIDARG;
1927  struct class *class = (struct class *)h;
1928 
1929  if (class -> nic)
1930  class_dereference (&class -> nic, file, line);
1931  if (class -> superclass)
1932  class_dereference (&class -> superclass, file, line);
1933  if (class -> name) {
1934  dfree (class -> name, file, line);
1935  class -> name = (char *)0;
1936  }
1937  if (class -> billed_leases) {
1938  int i;
1939  for (i = 0; i < class -> lease_limit; i++) {
1940  if (class -> billed_leases [i]) {
1941  lease_dereference (&class -> billed_leases [i],
1942  file, line);
1943  }
1944  }
1945  dfree (class -> billed_leases, file, line);
1946  class -> billed_leases = (struct lease **)0;
1947  }
1948  if (class -> hash) {
1949  class_free_hash_table (&class -> hash, file, line);
1950  class -> hash = (class_hash_t *)0;
1951  }
1952  data_string_forget (&class -> hash_string, file, line);
1953 
1954  if (class -> expr)
1955  expression_dereference (&class -> expr, file, line);
1956  if (class -> submatch)
1957  expression_dereference (&class -> submatch, file, line);
1958  if (class -> group)
1959  group_dereference (&class -> group, file, line);
1960  if (class -> statements)
1961  executable_statement_dereference (&class -> statements,
1962  file, line);
1963  if (class -> superclass)
1964  class_dereference (&class -> superclass, file, line);
1965 
1966  return ISC_R_SUCCESS;
1967 }
1968 
1969 static isc_result_t
1970 class_signal_handler(omapi_object_t *h,
1971  const char *name, va_list ap)
1972 {
1973  struct class *class = (struct class *)h;
1974  isc_result_t status;
1975  int updatep = 0;
1976  int issubclass;
1977 
1978  issubclass = (h->type == dhcp_type_subclass);
1979 
1980  if (!strcmp (name, "updated")) {
1981 
1982  if (!issubclass) {
1983  if (class->name == 0 || strlen(class->name) == 0) {
1984  return DHCP_R_INVALIDARG;
1985  }
1986  } else {
1987  if (class->superclass == 0) {
1988  return DHCP_R_INVALIDARG; /* didn't give name */
1989  }
1990 
1991  if (class->hash_string.data == NULL) {
1992  return DHCP_R_INVALIDARG;
1993  }
1994  }
1995 
1996 
1997  if (issubclass) {
1998  if (!class->superclass->hash)
1999  class_new_hash(&class->superclass->hash,
2001 
2002  class_hash_add(class->superclass->hash,
2003  (const char *)class->hash_string.data,
2004  class->hash_string.len,
2005  (void *)class, MDL);
2006  }
2007 
2008 #ifdef DEBUG_OMAPI
2009  if (issubclass) {
2010  log_debug ("OMAPI added subclass %s",
2011  class->superclass->name);
2012  } else {
2013  log_debug ("OMAPI added class %s", class->name);
2014  }
2015 #endif
2016 
2017  status = enter_class (class, 1, 1);
2018  if (status != ISC_R_SUCCESS)
2019  return status;
2020  updatep = 1;
2021  }
2022 
2023  /* Try to find some inner object that can take the value. */
2024  if (h->inner && h->inner->type->signal_handler) {
2025  status = ((*(h->inner->type->signal_handler))
2026  (h->inner, name, ap));
2027  if (status == ISC_R_SUCCESS)
2028  return status;
2029  }
2030 
2031  if (updatep)
2032  return ISC_R_SUCCESS;
2033 
2034  return ISC_R_NOTFOUND;
2035 }
2036 
2037 
2039  const char *name, va_list ap)
2040 {
2041  if (h -> type != dhcp_type_class)
2042  return DHCP_R_INVALIDARG;
2043 
2044  return class_signal_handler(h, name, ap);
2045 }
2046 
2047 
2048 /*
2049  * Routine to put out generic class & subclass information
2050  */
2052  omapi_object_t *id,
2053  omapi_object_t *h)
2054 {
2055  struct class *class;
2056  isc_result_t status;
2057 
2058  class = (struct class *)h;
2059 
2060  status = omapi_connection_put_named_uint32(c, "lease-limit",
2061  ((u_int32_t)
2062  class->lease_limit));
2063  if (status != ISC_R_SUCCESS)
2064  return (status);
2065 
2066  status = omapi_connection_put_named_uint32(c, "leases-used",
2067  ((u_int32_t)
2068  class->leases_consumed));
2069  if (status != ISC_R_SUCCESS)
2070  return (status);
2071 
2072  /* Write out the inner object, if any. */
2073  if (h->inner && h->inner->type->stuff_values) {
2074  status = ((*(h->inner->type->stuff_values))
2075  (c, id, h->inner));
2076  if (status == ISC_R_SUCCESS)
2077  return (status);
2078  }
2079 
2080  return (ISC_R_SUCCESS);
2081 }
2082 
2083 
2085  omapi_object_t *id,
2086  omapi_object_t *h)
2087 {
2088  if (h->type != dhcp_type_class)
2089  return (DHCP_R_INVALIDARG);
2090 
2091  /* add any class specific items here */
2092 
2093  return (class_stuff_values(c, id, h));
2094 }
2095 
2096 static isc_result_t class_lookup (omapi_object_t **lp,
2097  omapi_object_t *id, omapi_object_t *ref,
2098  omapi_object_type_t *typewanted)
2099 {
2100  omapi_value_t *nv = NULL;
2101  omapi_value_t *hv = NULL;
2102  isc_result_t status;
2103  struct class *class = 0;
2104  struct class *subclass = 0;
2105 
2106  *lp = NULL;
2107 
2108  if (ref == NULL)
2109  return (DHCP_R_NOKEYS);
2110 
2111  /* see if we have a name */
2112  status = omapi_get_value_str(ref, id, "name", &nv);
2113  if (status == ISC_R_SUCCESS) {
2114  char *name = dmalloc(nv->value->u.buffer.len + 1, MDL);
2115  memcpy (name,
2116  nv->value->u.buffer.value,
2117  nv->value->u.buffer.len);
2118 
2120 
2121  find_class(&class, name, MDL);
2122 
2123  dfree(name, MDL);
2124 
2125  if (class == NULL) {
2126  return (ISC_R_NOTFOUND);
2127  }
2128 
2129  if (typewanted == dhcp_type_subclass) {
2130  status = omapi_get_value_str(ref, id,
2131  "hashstring", &hv);
2132  if (status != ISC_R_SUCCESS) {
2133  class_dereference(&class, MDL);
2134  return (DHCP_R_NOKEYS);
2135  }
2136 
2137  if (hv->value->type != omapi_datatype_data &&
2138  hv->value->type != omapi_datatype_string) {
2139  class_dereference(&class, MDL);
2141  return (DHCP_R_NOKEYS);
2142  }
2143 
2144  class_hash_lookup(&subclass, class->hash,
2145  (const char *)
2146  hv->value->u.buffer.value,
2147  hv->value->u.buffer.len, MDL);
2148 
2150 
2151  class_dereference(&class, MDL);
2152 
2153  if (subclass == NULL) {
2154  return (ISC_R_NOTFOUND);
2155  }
2156 
2157  class_reference(&class, subclass, MDL);
2158  class_dereference(&subclass, MDL);
2159  }
2160 
2161  /* Don't return the object if the type is wrong. */
2162  if (class->type != typewanted) {
2163  class_dereference(&class, MDL);
2164  return (DHCP_R_INVALIDARG);
2165  }
2166 
2167  if (class->flags & CLASS_DECL_DELETED) {
2168  class_dereference(&class, MDL);
2169  return (ISC_R_NOTFOUND);
2170  }
2171 
2172  omapi_object_reference(lp, (omapi_object_t *)class, MDL);
2173  class_dereference(&class, MDL);
2174 
2175  return (ISC_R_SUCCESS);
2176  }
2177 
2178  return (DHCP_R_NOKEYS);
2179 }
2180 
2181 
2183  omapi_object_t *id, omapi_object_t *ref)
2184 {
2185  return class_lookup(lp, id, ref, dhcp_type_class);
2186 }
2187 
2189  omapi_object_t *id)
2190 {
2191  struct class *cp = 0;
2192  isc_result_t status;
2193 
2194  status = class_allocate(&cp, MDL);
2195  if (status != ISC_R_SUCCESS)
2196  return (status);
2197 
2198  clone_group(&cp->group, root_group, MDL);
2199  cp->flags = CLASS_DECL_DYNAMIC;
2200  status = omapi_object_reference(lp, (omapi_object_t *)cp, MDL);
2201  class_dereference(&cp, MDL);
2202  return (status);
2203 }
2204 
2206  omapi_object_t *id)
2207 {
2208  struct class *cp;
2209  if (lp -> type != dhcp_type_class)
2210  return DHCP_R_INVALIDARG;
2211  cp = (struct class *)lp;
2212 
2213 #ifdef DEBUG_OMAPI
2214  log_debug ("OMAPI delete class %s", cp -> name);
2215 #endif
2216 
2217  delete_class (cp, 1);
2218  return ISC_R_SUCCESS;
2219 }
2220 
2222  omapi_object_t *id,
2223  omapi_data_string_t *name,
2224  omapi_typed_data_t *value)
2225 {
2226  if (h -> type != dhcp_type_subclass)
2227  return DHCP_R_INVALIDARG;
2228 
2229  return class_set_value(h, id, name, value);
2230 }
2231 
2232 
2234  omapi_data_string_t *name,
2235  omapi_value_t **value)
2236 {
2237  struct class *subclass;
2238  isc_result_t status;
2239 
2240  if (h -> type != dhcp_type_class)
2241  return DHCP_R_INVALIDARG;
2242  subclass = (struct class *)h;
2243  if (subclass -> name != 0)
2244  return DHCP_R_INVALIDARG;
2245 
2246  /* XXXJAB No values to get yet. */
2247 
2248  /* Try to find some inner object that can provide the value. */
2249  if (h -> inner && h -> inner -> type -> get_value) {
2250  status = ((*(h -> inner -> type -> get_value))
2251  (h -> inner, id, name, value));
2252  if (status == ISC_R_SUCCESS)
2253  return status;
2254  }
2255  return DHCP_R_UNKNOWNATTRIBUTE;
2256 }
2257 
2259  const char *name, va_list ap)
2260 {
2261  if (h -> type != dhcp_type_subclass)
2262  return DHCP_R_INVALIDARG;
2263 
2264  return class_signal_handler(h, name, ap);
2265 }
2266 
2267 
2269  omapi_object_t *id,
2270  omapi_object_t *h)
2271 {
2272  struct class *subclass;
2273 
2274  if (h->type != dhcp_type_subclass)
2275  return (DHCP_R_INVALIDARG);
2276  subclass = (struct class *)h;
2277  if (subclass->name != 0)
2278  return (DHCP_R_INVALIDARG);
2279 
2280  /* add any subclass specific items here */
2281 
2282  return (class_stuff_values(c, id, h));
2283 }
2284 
2286  omapi_object_t *id, omapi_object_t *ref)
2287 {
2288  return class_lookup(lp, id, ref, dhcp_type_subclass);
2289 }
2290 
2291 
2292 
2293 
2295  omapi_object_t *id)
2296 {
2297  struct class *cp = 0;
2298  isc_result_t status;
2299 
2300  status = subclass_allocate(&cp, MDL);
2301  if (status != ISC_R_SUCCESS)
2302  return status;
2304 
2305  cp->flags = CLASS_DECL_DYNAMIC;
2306 
2307  status = omapi_object_reference (lp, (omapi_object_t *)cp, MDL);
2308  subclass_dereference (&cp, MDL);
2309  return status;
2310 }
2311 
2313  omapi_object_t *id)
2314 {
2315  struct class *cp;
2316  if (lp -> type != dhcp_type_subclass)
2317  return DHCP_R_INVALIDARG;
2318  cp = (struct class *)lp;
2319 
2320 #ifdef DEBUG_OMAPI
2321  log_debug ("OMAPI delete subclass %s", cp -> name);
2322 #endif
2323 
2324  delete_class (cp, 1);
2325 
2326  return ISC_R_SUCCESS;
2327 }
2328 
2329 isc_result_t binding_scope_set_value (struct binding_scope *scope, int createp,
2330  omapi_data_string_t *name,
2331  omapi_typed_data_t *value)
2332 {
2333  struct binding *bp;
2334  char *nname;
2335  struct binding_value *nv;
2336  nname = dmalloc (name -> len + 1, MDL);
2337  if (!nname)
2338  return ISC_R_NOMEMORY;
2339  memcpy (nname, name -> value, name -> len);
2340  nname [name -> len] = 0;
2341  bp = find_binding (scope, nname);
2342  if (!bp && !createp) {
2343  dfree (nname, MDL);
2344  return DHCP_R_UNKNOWNATTRIBUTE;
2345  }
2346  if (!value) {
2347  dfree (nname, MDL);
2348  if (!bp)
2349  return DHCP_R_UNKNOWNATTRIBUTE;
2350  binding_value_dereference (&bp -> value, MDL);
2351  return ISC_R_SUCCESS;
2352  }
2353 
2354  nv = (struct binding_value *)0;
2355  if (!binding_value_allocate (&nv, MDL)) {
2356  dfree (nname, MDL);
2357  return ISC_R_NOMEMORY;
2358  }
2359  switch (value -> type) {
2360  case omapi_datatype_int:
2361  nv -> type = binding_numeric;
2362  nv -> value.intval = value -> u.integer;
2363  break;
2364 
2365  case omapi_datatype_string:
2366  case omapi_datatype_data:
2367  if (!buffer_allocate (&nv -> value.data.buffer,
2368  value -> u.buffer.len, MDL)) {
2370  dfree (nname, MDL);
2371  return ISC_R_NOMEMORY;
2372  }
2373  memcpy (&nv -> value.data.buffer -> data [1],
2374  value -> u.buffer.value, value -> u.buffer.len);
2375  nv -> value.data.len = value -> u.buffer.len;
2376  break;
2377 
2378  case omapi_datatype_object:
2380  dfree (nname, MDL);
2381  return DHCP_R_INVALIDARG;
2382  }
2383 
2384  if (!bp) {
2385  bp = dmalloc (sizeof *bp, MDL);
2386  if (!bp) {
2388  dfree (nname, MDL);
2389  return ISC_R_NOMEMORY;
2390  }
2391  memset (bp, 0, sizeof *bp);
2392  bp -> name = nname;
2393  bp -> next = scope -> bindings;
2394  scope -> bindings = bp;
2395  } else {
2396  if (bp -> value)
2397  binding_value_dereference (&bp -> value, MDL);
2398  dfree (nname, MDL);
2399  }
2400  binding_value_reference (&bp -> value, nv, MDL);
2402  return ISC_R_SUCCESS;
2403 }
2404 
2406  struct binding_scope *scope,
2407  omapi_data_string_t *name)
2408 {
2409  struct binding *bp;
2410  omapi_typed_data_t *td;
2411  isc_result_t status;
2412  char *nname;
2413  nname = dmalloc (name -> len + 1, MDL);
2414  if (!nname)
2415  return ISC_R_NOMEMORY;
2416  memcpy (nname, name -> value, name -> len);
2417  nname [name -> len] = 0;
2418  bp = find_binding (scope, nname);
2419  dfree (nname, MDL);
2420  if (!bp)
2421  return DHCP_R_UNKNOWNATTRIBUTE;
2422  if (!bp -> value)
2423  return DHCP_R_UNKNOWNATTRIBUTE;
2424 
2425  switch (bp -> value -> type) {
2426  case binding_boolean:
2427  td = (omapi_typed_data_t *)0;
2429  bp -> value -> value.boolean);
2430  break;
2431 
2432  case binding_numeric:
2433  td = (omapi_typed_data_t *)0;
2435  (int)
2436  bp -> value -> value.intval);
2437  break;
2438 
2439  case binding_data:
2440  td = (omapi_typed_data_t *)0;
2442  bp -> value -> value.data.len);
2443  if (status != ISC_R_SUCCESS)
2444  return status;
2445  memcpy (&td -> u.buffer.value [0],
2446  bp -> value -> value.data.data,
2447  bp -> value -> value.data.len);
2448  break;
2449 
2450  /* Can't return values for these two (yet?). */
2451  case binding_dns:
2452  case binding_function:
2453  return DHCP_R_INVALIDARG;
2454 
2455  default:
2456  log_fatal ("Impossible case at %s:%d.", MDL);
2457  return ISC_R_FAILURE;
2458  }
2459 
2460  if (status != ISC_R_SUCCESS)
2461  return status;
2462  status = omapi_value_new (value, MDL);
2463  if (status != ISC_R_SUCCESS) {
2465  return status;
2466  }
2467 
2468  omapi_data_string_reference (&(*value) -> name, name, MDL);
2469  omapi_typed_data_reference (&(*value) -> value, td, MDL);
2471 
2472  return ISC_R_SUCCESS;
2473 }
2474 
2476  struct binding_scope *scope)
2477 {
2478  struct binding *bp;
2479  unsigned len;
2480  isc_result_t status;
2481 
2482  for (bp = scope -> bindings; bp; bp = bp -> next) {
2483  if (bp -> value) {
2484  if (bp -> value -> type == binding_dns ||
2485  bp -> value -> type == binding_function)
2486  continue;
2487 
2488  /* Stuff the name. */
2489  len = strlen (bp -> name);
2490  status = omapi_connection_put_uint16 (c, len);
2491  if (status != ISC_R_SUCCESS)
2492  return status;
2493  status = omapi_connection_copyin (c,
2494  (unsigned char *)bp -> name,
2495  len);
2496  if (status != ISC_R_SUCCESS)
2497  return status;
2498 
2499  switch (bp -> value -> type) {
2500  case binding_boolean:
2501  status = omapi_connection_put_uint32 (c,
2502  sizeof (u_int32_t));
2503  if (status != ISC_R_SUCCESS)
2504  return status;
2505  status = (omapi_connection_put_uint32
2506  (c,
2507  ((u_int32_t)(bp -> value -> value.boolean))));
2508  if (status != ISC_R_SUCCESS)
2509  return status;
2510  break;
2511 
2512  case binding_data:
2513  status = (omapi_connection_put_uint32
2514  (c, bp -> value -> value.data.len));
2515  if (status != ISC_R_SUCCESS)
2516  return status;
2517  if (bp -> value -> value.data.len) {
2518  status = (omapi_connection_copyin
2519  (c, bp -> value -> value.data.data,
2520  bp -> value -> value.data.len));
2521  if (status != ISC_R_SUCCESS)
2522  return status;
2523  }
2524  break;
2525 
2526  case binding_numeric:
2527  status = (omapi_connection_put_uint32
2528  (c, sizeof (u_int32_t)));
2529  if (status != ISC_R_SUCCESS)
2530  return status;
2531  status = (omapi_connection_put_uint32
2532  (c, ((u_int32_t)
2533  (bp -> value -> value.intval))));
2534  if (status != ISC_R_SUCCESS)
2535  return status;
2536  break;
2537 
2538 
2539  /* NOTREACHED */
2540  case binding_dns:
2541  case binding_function:
2542  break;
2543  }
2544  }
2545  }
2546  return ISC_R_SUCCESS;
2547 }
2548 
2549 /* vim: set tabstop=8: */
isc_result_t dhcp_failover_state_signal(omapi_object_t *, const char *, va_list)
#define FTS_LAST
Definition: dhcpd.h:494
isc_result_t dhcp_subclass_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:2294
isc_result_t omapi_typed_data_new(const char *, int, omapi_typed_data_t **, omapi_datatype_t,...)
Definition: alloc.c:789
isc_result_t dhcp_failover_state_stuff(omapi_object_t *, omapi_object_t *, omapi_object_t *)
lease_id_hash_t * lease_uid_hash
Definition: mdb.c:38
const char int line
Definition: dhcpd.h:3535
isc_result_t dhcp_failover_link_get_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_value_t **)
struct binding_scope * global_scope
Definition: tree.c:39
isc_result_t dhcp_failover_listener_set_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_typed_data_t *)
struct on_star on_star
Definition: dhcpd.h:523
isc_result_t dhcp_lease_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:848
isc_result_t dhcp_class_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:2205
int binding_value_dereference(struct binding_value **v, const char *file, int line)
Definition: tree.c:653
isc_result_t omapi_make_int_value(omapi_value_t **, omapi_data_string_t *, int, const char *, int)
Definition: support.c:710
Definition: dhcpd.h:507
unsigned len
Definition: tree.h:80
isc_result_t dhcp_class_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:2188
isc_result_t omapi_connection_put_handle(omapi_object_t *c, omapi_object_t *h)
Definition: buffer.c:701
int executable_statement_dereference(struct executable_statement **ptr, const char *file, int line)
Definition: execute.c:615
isc_result_t omapi_object_reference(omapi_object_t **, omapi_object_t *, const char *, int)
Definition: alloc.c:557
isc_result_t dhcp_host_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:1500
const char * piaddr(const struct iaddr addr)
Definition: inet.c:581
u_int8_t hlen
Definition: dhcpd.h:440
omapi_object_type_t * dhcp_type_failover_link
isc_result_t dhcp_lease_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:475
unsigned char * uid
Definition: dhcpd.h:525
unsigned len
Definition: omapip.h:54
isc_result_t end_parse(struct parse **cfile)
Definition: conflex.c:103
omapi_object_type_t * dhcp_type_subclass
Definition: omapi.c:47
int outstanding_pings
Definition: dhcp.c:38
isc_result_t dhcp_host_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:1152
isc_result_t dhcp_pool_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:1714
void * dmalloc(unsigned, const char *, int)
Definition: alloc.c:56
struct lease_state * state
Definition: dhcpd.h:568
struct class * superclass
Definition: dhcpd.h:978
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
Definition: options.c:2699
isc_result_t omapi_connection_copyin(omapi_object_t *, const unsigned char *, unsigned)
Definition: buffer.c:266
int expression_allocate(struct expression **cptr, const char *file, int line)
Definition: alloc.c:427
Definition: dhcpd.h:948
isc_result_t dhcp_subclass_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:2312
isc_result_t dhcp_class_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:1922
struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address)
Definition: inet.c:65
int binding_value_reference(struct binding_value **ptr, struct binding_value *src, const char *file, int line)
Definition: alloc.c:521
#define MDL
Definition: omapip.h:568
#define HOST_DECL_DYNAMIC
Definition: dhcpd.h:880
void cancel_timeout(void(*)(void *) where, void *what)
Definition: dispatch.c:390
isc_result_t omapi_connection_put_named_uint32(omapi_object_t *, const char *, u_int32_t)
Definition: buffer.c:718
unsigned char iabuf[16]
Definition: inet.h:33
#define DHCP_R_INVALIDARG
Definition: result.h:48
class_hash_t * hash
Definition: dhcpd.h:991
omapi_typed_data_t * value
Definition: omapip.h:91
#define CLASS_DECL_DELETED
Definition: dhcpd.h:1007
host_hash_t * host_uid_hash
Definition: mdb.c:36
isc_result_t dhcp_subclass_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2268
isc_result_t dhcp_host_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:1293
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
isc_result_t dhcp_subclass_set_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_typed_data_t *value)
Definition: omapi.c:2221
struct lease * next_pending
Definition: dhcpd.h:582
struct binding * next
Definition: tree.h:119
isc_result_t dhcp_failover_state_create(omapi_object_t **, omapi_object_t *)
struct executable_statement * on_release
Definition: dhcpd.h:503
void lease_ping_timeout(void *)
Definition: dhcpd.c:1186
isc_result_t dhcp_failover_listener_stuff(omapi_object_t *, omapi_object_t *, omapi_object_t *)
struct lease * abandoned
Definition: dhcpd.h:915
isc_result_t dhcp_pool_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition: omapi.c:1556
int group_reference(struct group **ptr, struct group *bp, const char *file, int line)
Definition: alloc.c:178
void data_string_forget(struct data_string *data, const char *file, int line)
Definition: alloc.c:1276
isc_result_t dhcp_pool_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:1650
omapi_object_type_t * dhcp_type_failover_state
void hw_hash_delete(struct lease *)
Definition: mdb.c:2270
isc_result_t dhcp_pool_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:1628
struct option_cache * fixed_addr
Definition: dhcpd.h:873
struct class * billing_class
Definition: dhcpd.h:519
struct group * root_group
Definition: memory.c:31
enum binding_value::@15 type
#define SCLASS_HASH_SIZE
Definition: dhcpd.h:203
int log_error(const char *,...) __attribute__((__format__(__printf__
isc_result_t dhcp_lease_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:682
#define HOST_DECL_DELETED
Definition: dhcpd.h:879
omapi_object_type_t * dhcp_type_host
Definition: omapi.c:48
lease_id_hash_t * lease_hw_addr_hash
Definition: mdb.c:40
int binding_scope_dereference(struct binding_scope **ptr, const char *file, int line)
Definition: tree.c:3722
void free_permit(struct permit *, const char *, int)
Definition: salloc.c:243
isc_result_t dhcp_class_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:2038
isc_result_t omapi_data_string_reference(omapi_data_string_t **, omapi_data_string_t *, const char *, int)
Definition: alloc.c:953
omapi_datatype_t type
Definition: omapip.h:51
struct data_string auth_key_id
Definition: dhcpd.h:877
unsigned len
Definition: inet.h:32
dhcp_failover_state_t * failover_peer
Definition: dhcpd.h:926
isc_result_t dhcp_subclass_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:2258
isc_result_t omapi_value_new(omapi_value_t **, const char *, int)
Definition: alloc.c:1012
struct data_string client_identifier
Definition: dhcpd.h:867
#define DHCP_R_KEYCONFLICT
Definition: result.h:52
isc_result_t enter_class(struct class *, int, int)
Definition: mdb.c:73
Definition: dhcpd.h:252
char * name
Definition: dhcpd.h:979
void expression_dereference(struct expression **eptr, const char *file, int line)
Definition: tree.c:2751
omapi_object_type_t * dhcp_type_pool
Definition: omapi.c:45
struct lease * backup
Definition: dhcpd.h:914
void log_fatal(const char *,...) __attribute__((__format__(__printf__
isc_result_t dhcp_failover_link_destroy(omapi_object_t *, const char *, int)
isc_result_t omapi_make_handle_value(omapi_value_t **, omapi_data_string_t *, omapi_object_t *, const char *, int)
Definition: support.c:773
int binding_value_allocate(struct binding_value **cptr, const char *file, int line)
Definition: alloc.c:501
#define DHCP_R_BADPARSE
Definition: result.h:53
isc_result_t dhcp_class_set_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_typed_data_t *value)
Definition: omapi.c:1886
#define DHCP_R_MULTIPLE
Definition: result.h:51
struct omapi_typed_data_t::@3::@4 buffer
isc_result_t dhcp_failover_state_destroy(omapi_object_t *, const char *, int)
#define CLASS_DECL_DYNAMIC
Definition: dhcpd.h:1008
void free_lease_state(struct lease_state *, const char *, int)
Definition: salloc.c:196
struct hardware hardware_addr
Definition: dhcpd.h:529
isc_result_t omapi_connection_put_uint32(omapi_object_t *, u_int32_t)
Definition: buffer.c:587
#define HTYPE_ETHER
Definition: dhcp.h:76
omapi_object_type_t * dhcp_type_failover_listener
#define RC_LEASE
Definition: alloc.h:55
isc_result_t binding_scope_get_value(omapi_value_t **value, struct binding_scope *scope, omapi_data_string_t *name)
Definition: omapi.c:2405
isc_result_t dhcp_failover_state_remove(omapi_object_t *, omapi_object_t *)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
Definition: tree.c:2643
Definition: tree.h:345
isc_result_t omapi_get_value_str(omapi_object_t *, omapi_object_t *, const char *, omapi_value_t **)
Definition: support.c:483
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)
Definition: omapi.c:860
isc_result_t dhcp_subclass_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:2285
int option_chain_head_dereference(struct option_chain_head **ptr, const char *file, int line)
Definition: alloc.c:96
host_hash_t * host_name_hash
Definition: mdb.c:37
struct lease * active
Definition: dhcpd.h:911
isc_result_t dhcp_failover_state_set_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_typed_data_t *)
isc_result_t delete_host(struct host_decl *, int)
Definition: mdb.c:468
Definition: dhcpd.h:904
binding_state_t binding_state
Definition: dhcpd.h:563
isc_result_t dhcp_failover_state_get_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_value_t **)
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
Definition: alloc.c:680
isc_result_t dhcp_class_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition: omapi.c:1897
int binding_scope_allocate(struct binding_scope **ptr, const char *file, int line)
Definition: alloc.c:1195
int write_lease(struct lease *lease)
Definition: dhclient.c:1792
isc_result_t class_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2051
int group_dereference(struct group **ptr, const char *file, int line)
Definition: alloc.c:206
#define DHCP_R_UNKNOWNATTRIBUTE
Definition: result.h:77
#define COMPACT_LEASES
Definition: site.h:204
Definition: dhcpd.h:369
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
Definition: alloc.c:579
struct pool * pool
Definition: dhcpd.h:518
char * name
Definition: dhcpd.h:865
host_hash_t * host_hw_addr_hash
Definition: mdb.c:35
dhcp_failover_listener_t
Definition: dhcpd.h:3506
TIME atsfp
Definition: dhcpd.h:579
isc_result_t dhcp_pool_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:1708
#define cur_time
Definition: dhcpd.h:1926
struct lease * n_hw
Definition: dhcpd.h:510
int free_leases
Definition: dhcpd.h:919
isc_result_t dhcp_failover_link_signal(omapi_object_t *, const char *, va_list)
struct lease * n_uid
Definition: dhcpd.h:510
TIME starts
Definition: dhcpd.h:513
isc_result_t omapi_get_int_value(unsigned long *, omapi_typed_data_t *)
Definition: support.c:836
u_int8_t flags
Definition: dhcpd.h:531
struct lease * free
Definition: dhcpd.h:913
void dfree(void *, const char *, int)
Definition: alloc.c:131
union omapi_typed_data_t::@3 u
struct permit * next
Definition: dhcpd.h:889
int lease_count
Definition: dhcpd.h:918
struct host_decl * n_ipaddr
Definition: dhcpd.h:863
isc_result_t dhcp_failover_link_stuff_values(omapi_object_t *, omapi_object_t *, omapi_object_t *)
enum permit::@0 type
isc_result_t omapi_handle_td_lookup(omapi_object_t **, omapi_typed_data_t *)
Definition: handle.c:283
void uid_hash_delete(struct lease *)
Definition: mdb.c:2140
int lease_limit
Definition: dhcpd.h:982
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)
Definition: omapi.c:198
int supersede_lease(struct lease *, struct lease *, int, int, int)
Definition: mdb.c:1094
int int log_info(const char *,...) __attribute__((__format__(__printf__
omapi_object_type_t * dhcp_type_class
Definition: omapi.c:46
struct subnet * subnet
Definition: dhcpd.h:517
#define GROUP_OBJECT_DELETED
Definition: dhcpd.h:843
isc_result_t dhcp_lease_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:854
isc_result_t dhcp_pool_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:1578
void dhcp_db_objects_setup()
Definition: omapi.c:55
omapi_object_type_t * dhcp_type_lease
Definition: omapi.c:44
isc_result_t omapi_connection_put_string(omapi_object_t *, const char *)
Definition: buffer.c:681
isc_result_t delete_class(struct class *, int)
Definition: mdb.c:436
char * name
Definition: dhcpd.h:841
isc_result_t omapi_typed_data_reference(omapi_typed_data_t **, omapi_typed_data_t *, const char *, int)
Definition: alloc.c:866
isc_result_t dhcp_lease_get(omapi_object_t **, const char *, int)
TIME cltt
Definition: dhcpd.h:580
Definition: dhcpd.h:888
isc_result_t binding_scope_stuff_values(omapi_object_t *c, struct binding_scope *scope)
Definition: omapi.c:2475
isc_result_t omapi_value_dereference(omapi_value_t **, const char *, int)
Definition: alloc.c:1046
isc_result_t omapi_object_type_register(omapi_object_type_t **, const char *, isc_result_t(*)(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_typed_data_t *), isc_result_t(*)(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_value_t **), isc_result_t(*)(omapi_object_t *, const char *, int), isc_result_t(*)(omapi_object_t *, const char *, va_list), isc_result_t(*)(omapi_object_t *, omapi_object_t *, omapi_object_t *), isc_result_t(*)(omapi_object_t **, omapi_object_t *, omapi_object_t *), isc_result_t(*)(omapi_object_t **, omapi_object_t *), isc_result_t(*)(omapi_object_t *, omapi_object_t *), isc_result_t(*)(omapi_object_t *, const char *, int), isc_result_t(*)(omapi_object_t **, const char *, int), isc_result_t(*)(size_t), size_t, isc_result_t(*)(omapi_object_t *, const char *, int), int)
Definition: support.c:194
unsigned short uid_len
Definition: dhcpd.h:526
struct iaddr ip_addr
Definition: dhcpd.h:512
#define DHCP_R_NOKEYS
Definition: result.h:54
#define EPHEMERAL_FLAGS
Definition: dhcpd.h:545
struct group_object * named_group
Definition: dhcpd.h:876
Definition: dhcpd.h:849
#define DHCP_R_UNCHANGED
Definition: result.h:50
TIME tstp
Definition: dhcpd.h:577
isc_result_t dhcp_class_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2084
struct host_decl * host
Definition: dhcpd.h:516
int omapi_ds_strcmp(omapi_data_string_t *, const char *)
Definition: support.c:582
isc_result_t find_class(struct class **c, const char *s, const char *file, int line)
Definition: dhclient.c:1220
isc_result_t dhcp_lease_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:401
isc_result_t omapi_connection_put_uint16(omapi_object_t *, u_int32_t)
Definition: buffer.c:613
int commit_leases()
Definition: dhclient.c:1787
isc_result_t dhcp_failover_listener_destroy(omapi_object_t *, const char *, int)
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)
Definition: omapi.c:1531
TIME tsfp
Definition: dhcpd.h:578
isc_result_t enter_host(struct host_decl *, int, int)
Definition: mdb.c:221
isc_result_t dhcp_host_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition: omapi.c:1055
int flags
Definition: dhcpd.h:842
isc_result_t dhcp_lease_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:497
group_hash_t * group_name_hash
Definition: memory.c:32
int flags
Definition: dhcpd.h:1012
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
Definition: dhcpd.h:441
struct lease * next
Definition: dhcpd.h:509
Definition: tree.h:118
isc_result_t dhcp_lease_free(omapi_object_t *, const char *, int)
struct lease * expired
Definition: dhcpd.h:912
isc_result_t dhcp_subclass_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition: omapi.c:2233
isc_result_t omapi_make_const_value(omapi_value_t **, omapi_data_string_t *, const unsigned char *, unsigned, const char *, int)
Definition: support.c:680
int flags
Definition: dhcpd.h:878
isc_result_t dhcp_class_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:2182
unsigned char uid_buf[7]
Definition: dhcpd.h:528
isc_result_t dhcp_failover_listener_signal(omapi_object_t *, const char *, va_list)
const char * binding_state_names[]
Definition: stables.c:161
struct executable_statement * on_expiry
Definition: dhcpd.h:501
struct binding * find_binding(struct binding_scope *scope, const char *name)
Definition: tree.c:3691
isc_result_t dhcp_host_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:1124
const char * file
Definition: dhcpd.h:3535
struct permit * permit_list
Definition: dhcpd.h:909
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
Definition: buffer.c:670
isc_result_t dhcp_host_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:1200
int parse_executable_statements(struct executable_statement **statements, struct parse *cfile, int *lose, enum expression_context case_context)
Definition: parse.c:2099
isc_result_t binding_scope_set_value(struct binding_scope *scope, int createp, omapi_data_string_t *name, omapi_typed_data_t *value)
Definition: omapi.c:2329
struct executable_statement * on_commit
Definition: dhcpd.h:502
Definition: dhcpd.h:975
const unsigned char * data
Definition: tree.h:79
TIME ends
Definition: dhcpd.h:513
struct binding_scope * scope
Definition: dhcpd.h:515
struct hardware interface
Definition: dhcpd.h:866
isc_result_t dhcp_failover_state_lookup(omapi_object_t **, omapi_object_t *, omapi_object_t *)
struct host_decl * n_dynamic
Definition: dhcpd.h:864
struct group * group
Definition: dhcpd.h:840
isc_result_t dhcp_failover_listener_get_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_value_t **)
#define RC_MISC
Definition: alloc.h:56
int clone_group(struct group **gp, struct group *group, const char *file, int line)
Definition: memory.c:130
isc_result_t omapi_typed_data_dereference(omapi_typed_data_t **, const char *, int)
Definition: alloc.c:887
binding_state_t next_binding_state
Definition: dhcpd.h:564
isc_result_t dhcp_failover_link_set_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_typed_data_t *)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)
Definition: conflex.c:41
lease_ip_hash_t * lease_ip_addr_hash
Definition: mdb.c:39
isc_result_t dhcp_lease_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition: omapi.c:325
isc_result_t omapi_make_string_value(omapi_value_t **, omapi_data_string_t *, const char *, const char *, int)
Definition: support.c:808
struct buffer * buffer
Definition: tree.h:78
isc_result_t dhcp_pool_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:1696
struct pool * next
Definition: dhcpd.h:906
isc_result_t dhcp_host_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:1516
char * client_hostname
Definition: dhcpd.h:514
struct group * group
Definition: dhcpd.h:1002
struct option_chain_head * agent_options
Definition: dhcpd.h:520
int backup_leases
Definition: dhcpd.h:920