ISC DHCP  4.3.2
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, NULL, 1, 1, 1, 0)) {
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, NULL, 1, 1, 1, 0)) {
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, 0)) {
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  if (class->name)
1735  return ISC_R_EXISTS;
1736 
1737  if (issubclass) {
1738  char tname[value->u.buffer.len + 1];
1739  memcpy(tname, value->u.buffer.value, value->u.buffer.len);
1740  tname[sizeof(tname)-1] = '\0';
1741  status = find_class(&superclass, tname, MDL);
1742 
1743  if (status == ISC_R_NOTFOUND)
1744  return status;
1745 
1746  if (class->superclass != NULL)
1747  class_dereference(&class->superclass, MDL);
1748  class_reference(&class->superclass, superclass, MDL);
1749 
1750  if (class->group != NULL)
1752  group_reference(&class->group, superclass->group, MDL);
1753 
1754  class->lease_limit = superclass->lease_limit;
1755  if (class->lease_limit != 0) {
1756  class->billed_leases =
1758  sizeof(struct lease *),
1759  MDL);
1760  if (class->billed_leases == NULL) {
1761  return ISC_R_NOMEMORY;
1762  }
1763  }
1764 
1765  } else if (value->type == omapi_datatype_data ||
1766  value->type == omapi_datatype_string) {
1767  class->name = dmalloc(value->u.buffer.len + 1, MDL);
1768  if (!class->name)
1769  return ISC_R_NOMEMORY;
1770 
1771  /* class->name is null-terminated from dmalloc() */
1772  memcpy(class->name, value->u.buffer.value,
1773  value->u.buffer.len);
1774  } else
1775  return DHCP_R_INVALIDARG;
1776 
1777  return ISC_R_SUCCESS;
1778  }
1779 
1780 
1781  if (issubclass && !omapi_ds_strcmp(name, "hashstring")) {
1782  if (class->hash_string.data)
1783  return ISC_R_EXISTS;
1784 
1785  if (value->type == omapi_datatype_data ||
1786  value->type == omapi_datatype_string) {
1788  value->u.buffer.len, MDL))
1789  return ISC_R_NOMEMORY;
1790  class->hash_string.data =
1791  class->hash_string.buffer->data;
1792  memcpy(class->hash_string.buffer->data,
1793  value->u.buffer.value, value->u.buffer.len);
1794  class->hash_string.len = value->u.buffer.len;
1795  } else
1796  return DHCP_R_INVALIDARG;
1797 
1798  return ISC_R_SUCCESS;
1799  }
1800 
1801  if (!omapi_ds_strcmp(name, "group")) {
1802  if (value->type == omapi_datatype_data ||
1803  value->type == omapi_datatype_string) {
1804  struct group_object *group = NULL;
1805 
1806  group_hash_lookup(&group, group_name_hash,
1807  (char *)value->u.buffer.value,
1808  value->u.buffer.len, MDL);
1809  if (!group || (group->flags & GROUP_OBJECT_DELETED))
1810  return ISC_R_NOTFOUND;
1811  if (class->group)
1813  group_reference(&class->group, group->group, MDL);
1814  group_object_dereference(&group, MDL);
1815  } else
1816  return DHCP_R_INVALIDARG;
1817 
1818  return ISC_R_SUCCESS;
1819  }
1820 
1821 
1822  /* note we do not support full expressions via omapi because the
1823  expressions parser needs to be re-done to support parsing from
1824  strings and not just files. */
1825 
1826  if (!omapi_ds_strcmp(name, "match")) {
1827  if (value->type == omapi_datatype_data ||
1828  value->type == omapi_datatype_string) {
1829  unsigned minlen = (value->u.buffer.len > 8 ?
1830  8 : value->u.buffer.len);
1831 
1832  if (!strncmp("hardware",
1833  (char *)value->u.buffer.value, minlen))
1834  {
1836  return ISC_R_NOMEMORY;
1837 
1838  class->submatch->op = expr_hardware;
1839  } else
1840  return DHCP_R_INVALIDARG;
1841  } else
1842  return DHCP_R_INVALIDARG;
1843 
1844  return ISC_R_SUCCESS;
1845  }
1846 
1847 
1848  if (!omapi_ds_strcmp(name, "option")) {
1849  if (value->type == omapi_datatype_data ||
1850  value->type == omapi_datatype_string) {
1851  /* XXXJAB support 'options' here. */
1852  /* XXXJAB specifically 'bootfile-name' */
1853  return DHCP_R_INVALIDARG; /* XXX tmp */
1854  } else
1855  return DHCP_R_INVALIDARG;
1856 
1857  /*
1858  * Currently no way to get here, if we update the above
1859  * code so that we do get here this return needs to be
1860  * uncommented.
1861  * return ISC_R_SUCCESS;
1862  */
1863  }
1864 
1865 
1866  /* Try to find some inner object that can take the value. */
1867  if (h->inner && h->inner->type->set_value) {
1868  status = ((*(h->inner->type->set_value))
1869  (h->inner, id, name, value));
1870  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1871  return status;
1872  }
1873 
1874  return DHCP_R_UNKNOWNATTRIBUTE;
1875 }
1876 
1877 
1878 
1880  omapi_object_t *id,
1881  omapi_data_string_t *name,
1882  omapi_typed_data_t *value)
1883 {
1884  if (h -> type != dhcp_type_class)
1885  return DHCP_R_INVALIDARG;
1886 
1887  return class_set_value(h, id, name, value);
1888 }
1889 
1891  omapi_data_string_t *name,
1892  omapi_value_t **value)
1893 {
1894  struct class *class;
1895  isc_result_t status;
1896 
1897  if (h -> type != dhcp_type_class)
1898  return DHCP_R_INVALIDARG;
1899  class = (struct class *)h;
1900 
1901  if (!omapi_ds_strcmp (name, "name"))
1902  return omapi_make_string_value (value, name, class -> name,
1903  MDL);
1904 
1905  /* Try to find some inner object that can provide the value. */
1906  if (h -> inner && h -> inner -> type -> get_value) {
1907  status = ((*(h -> inner -> type -> get_value))
1908  (h -> inner, id, name, value));
1909  if (status == ISC_R_SUCCESS)
1910  return status;
1911  }
1912  return DHCP_R_UNKNOWNATTRIBUTE;
1913 }
1914 
1915 isc_result_t dhcp_class_destroy (omapi_object_t *h, const char *file, int line)
1916 {
1917 
1918  if (h -> type != dhcp_type_class && h -> type != dhcp_type_subclass)
1919  return DHCP_R_INVALIDARG;
1920  struct class *class = (struct class *)h;
1921 
1922  if (class -> nic)
1923  class_dereference (&class -> nic, file, line);
1924  if (class -> superclass)
1925  class_dereference (&class -> superclass, file, line);
1926  if (class -> name) {
1927  dfree (class -> name, file, line);
1928  class -> name = (char *)0;
1929  }
1930  if (class -> billed_leases) {
1931  int i;
1932  for (i = 0; i < class -> lease_limit; i++) {
1933  if (class -> billed_leases [i]) {
1934  lease_dereference (&class -> billed_leases [i],
1935  file, line);
1936  }
1937  }
1938  dfree (class -> billed_leases, file, line);
1939  class -> billed_leases = (struct lease **)0;
1940  }
1941  if (class -> hash) {
1942  class_free_hash_table (&class -> hash, file, line);
1943  class -> hash = (class_hash_t *)0;
1944  }
1945  data_string_forget (&class -> hash_string, file, line);
1946 
1947  if (class -> expr)
1948  expression_dereference (&class -> expr, file, line);
1949  if (class -> submatch)
1950  expression_dereference (&class -> submatch, file, line);
1951  if (class -> group)
1952  group_dereference (&class -> group, file, line);
1953  if (class -> statements)
1954  executable_statement_dereference (&class -> statements,
1955  file, line);
1956  if (class -> superclass)
1957  class_dereference (&class -> superclass, file, line);
1958 
1959  return ISC_R_SUCCESS;
1960 }
1961 
1962 static isc_result_t
1963 class_signal_handler(omapi_object_t *h,
1964  const char *name, va_list ap)
1965 {
1966  struct class *class = (struct class *)h;
1967  isc_result_t status;
1968  int updatep = 0;
1969  int issubclass;
1970 
1971  issubclass = (h->type == dhcp_type_subclass);
1972 
1973  if (!strcmp (name, "updated")) {
1974 
1975  if (!issubclass) {
1976  if (class->name == 0 || strlen(class->name) == 0) {
1977  return DHCP_R_INVALIDARG;
1978  }
1979  } else {
1980  if (class->superclass == 0) {
1981  return DHCP_R_INVALIDARG; /* didn't give name */
1982  }
1983 
1984  if (class->hash_string.data == NULL) {
1985  return DHCP_R_INVALIDARG;
1986  }
1987  }
1988 
1989 
1990  if (issubclass) {
1991  if (!class->superclass->hash)
1992  class_new_hash(&class->superclass->hash,
1994 
1995  class_hash_add(class->superclass->hash,
1996  (const char *)class->hash_string.data,
1998  (void *)class, MDL);
1999  }
2000 
2001 #ifdef DEBUG_OMAPI
2002  if (issubclass) {
2003  log_debug ("OMAPI added subclass %s",
2004  class->superclass->name);
2005  } else {
2006  log_debug ("OMAPI added class %s", class->name);
2007  }
2008 #endif
2009 
2010  status = enter_class (class, 1, 1);
2011  if (status != ISC_R_SUCCESS)
2012  return status;
2013  updatep = 1;
2014  }
2015 
2016  /* Try to find some inner object that can take the value. */
2017  if (h->inner && h->inner->type->signal_handler) {
2018  status = ((*(h->inner->type->signal_handler))
2019  (h->inner, name, ap));
2020  if (status == ISC_R_SUCCESS)
2021  return status;
2022  }
2023 
2024  if (updatep)
2025  return ISC_R_SUCCESS;
2026 
2027  return ISC_R_NOTFOUND;
2028 }
2029 
2030 
2032  const char *name, va_list ap)
2033 {
2034  if (h -> type != dhcp_type_class)
2035  return DHCP_R_INVALIDARG;
2036 
2037  return class_signal_handler(h, name, ap);
2038 }
2039 
2040 
2041 /*
2042  * Routine to put out generic class & subclass information
2043  */
2045  omapi_object_t *id,
2046  omapi_object_t *h)
2047 {
2048  struct class *class;
2049  isc_result_t status;
2050 
2051  class = (struct class *)h;
2052 
2053  status = omapi_connection_put_named_uint32(c, "lease-limit",
2054  ((u_int32_t)
2055  class->lease_limit));
2056  if (status != ISC_R_SUCCESS)
2057  return (status);
2058 
2059  status = omapi_connection_put_named_uint32(c, "leases-used",
2060  ((u_int32_t)
2061  class->leases_consumed));
2062  if (status != ISC_R_SUCCESS)
2063  return (status);
2064 
2065  /* Write out the inner object, if any. */
2066  if (h->inner && h->inner->type->stuff_values) {
2067  status = ((*(h->inner->type->stuff_values))
2068  (c, id, h->inner));
2069  if (status == ISC_R_SUCCESS)
2070  return (status);
2071  }
2072 
2073  return (ISC_R_SUCCESS);
2074 }
2075 
2076 
2078  omapi_object_t *id,
2079  omapi_object_t *h)
2080 {
2081  if (h->type != dhcp_type_class)
2082  return (DHCP_R_INVALIDARG);
2083 
2084  /* add any class specific items here */
2085 
2086  return (class_stuff_values(c, id, h));
2087 }
2088 
2089 static isc_result_t class_lookup (omapi_object_t **lp,
2090  omapi_object_t *id, omapi_object_t *ref,
2091  omapi_object_type_t *typewanted)
2092 {
2093  omapi_value_t *nv = NULL;
2094  omapi_value_t *hv = NULL;
2095  isc_result_t status;
2096  struct class *class = 0;
2097  struct class *subclass = 0;
2098 
2099  *lp = NULL;
2100 
2101  if (ref == NULL)
2102  return (DHCP_R_NOKEYS);
2103 
2104  /* see if we have a name */
2105  status = omapi_get_value_str(ref, id, "name", &nv);
2106  if (status == ISC_R_SUCCESS) {
2107  char *name = dmalloc(nv->value->u.buffer.len + 1, MDL);
2108  memcpy (name,
2109  nv->value->u.buffer.value,
2110  nv->value->u.buffer.len);
2111 
2113 
2114  find_class(&class, name, MDL);
2115 
2116  dfree(name, MDL);
2117 
2118  if (class == NULL) {
2119  return (ISC_R_NOTFOUND);
2120  }
2121 
2122  if (typewanted == dhcp_type_subclass) {
2123  status = omapi_get_value_str(ref, id,
2124  "hashstring", &hv);
2125  if (status != ISC_R_SUCCESS) {
2126  class_dereference(&class, MDL);
2127  return (DHCP_R_NOKEYS);
2128  }
2129 
2130  if (hv->value->type != omapi_datatype_data &&
2131  hv->value->type != omapi_datatype_string) {
2132  class_dereference(&class, MDL);
2134  return (DHCP_R_NOKEYS);
2135  }
2136 
2137  class_hash_lookup(&subclass, class->hash,
2138  (const char *)
2139  hv->value->u.buffer.value,
2140  hv->value->u.buffer.len, MDL);
2141 
2143 
2144  class_dereference(&class, MDL);
2145 
2146  if (subclass == NULL) {
2147  return (ISC_R_NOTFOUND);
2148  }
2149 
2150  class_reference(&class, subclass, MDL);
2151  class_dereference(&subclass, MDL);
2152  }
2153 
2154  /* Don't return the object if the type is wrong. */
2155  if (class->type != typewanted) {
2156  class_dereference(&class, MDL);
2157  return (DHCP_R_INVALIDARG);
2158  }
2159 
2160  if (class->flags & CLASS_DECL_DELETED) {
2161  class_dereference(&class, MDL);
2162  return (ISC_R_NOTFOUND);
2163  }
2164 
2165  omapi_object_reference(lp, (omapi_object_t *)class, MDL);
2166  class_dereference(&class, MDL);
2167 
2168  return (ISC_R_SUCCESS);
2169  }
2170 
2171  return (DHCP_R_NOKEYS);
2172 }
2173 
2174 
2176  omapi_object_t *id, omapi_object_t *ref)
2177 {
2178  return class_lookup(lp, id, ref, dhcp_type_class);
2179 }
2180 
2182  omapi_object_t *id)
2183 {
2184  struct class *cp = 0;
2185  isc_result_t status;
2186 
2187  status = class_allocate(&cp, MDL);
2188  if (status != ISC_R_SUCCESS)
2189  return (status);
2190 
2191  if (clone_group(&cp->group, root_group, MDL) == 0)
2192  return (ISC_R_NOMEMORY);
2193 
2194  cp->flags = CLASS_DECL_DYNAMIC;
2195  status = omapi_object_reference(lp, (omapi_object_t *)cp, MDL);
2196  class_dereference(&cp, MDL);
2197  return (status);
2198 }
2199 
2201  omapi_object_t *id)
2202 {
2203  struct class *cp;
2204  if (lp -> type != dhcp_type_class)
2205  return DHCP_R_INVALIDARG;
2206  cp = (struct class *)lp;
2207 
2208 #ifdef DEBUG_OMAPI
2209  log_debug ("OMAPI delete class %s", cp -> name);
2210 #endif
2211 
2212  delete_class (cp, 1);
2213  return ISC_R_SUCCESS;
2214 }
2215 
2217  omapi_object_t *id,
2218  omapi_data_string_t *name,
2219  omapi_typed_data_t *value)
2220 {
2221  if (h -> type != dhcp_type_subclass)
2222  return DHCP_R_INVALIDARG;
2223 
2224  return class_set_value(h, id, name, value);
2225 }
2226 
2227 
2229  omapi_data_string_t *name,
2230  omapi_value_t **value)
2231 {
2232  struct class *subclass;
2233  isc_result_t status;
2234 
2235  if (h -> type != dhcp_type_class)
2236  return DHCP_R_INVALIDARG;
2237  subclass = (struct class *)h;
2238  if (subclass -> name != 0)
2239  return DHCP_R_INVALIDARG;
2240 
2241  /* XXXJAB No values to get yet. */
2242 
2243  /* Try to find some inner object that can provide the value. */
2244  if (h -> inner && h -> inner -> type -> get_value) {
2245  status = ((*(h -> inner -> type -> get_value))
2246  (h -> inner, id, name, value));
2247  if (status == ISC_R_SUCCESS)
2248  return status;
2249  }
2250  return DHCP_R_UNKNOWNATTRIBUTE;
2251 }
2252 
2254  const char *name, va_list ap)
2255 {
2256  if (h -> type != dhcp_type_subclass)
2257  return DHCP_R_INVALIDARG;
2258 
2259  return class_signal_handler(h, name, ap);
2260 }
2261 
2262 
2264  omapi_object_t *id,
2265  omapi_object_t *h)
2266 {
2267  struct class *subclass;
2268 
2269  if (h->type != dhcp_type_subclass)
2270  return (DHCP_R_INVALIDARG);
2271  subclass = (struct class *)h;
2272  if (subclass->name != 0)
2273  return (DHCP_R_INVALIDARG);
2274 
2275  /* add any subclass specific items here */
2276 
2277  return (class_stuff_values(c, id, h));
2278 }
2279 
2281  omapi_object_t *id, omapi_object_t *ref)
2282 {
2283  return class_lookup(lp, id, ref, dhcp_type_subclass);
2284 }
2285 
2286 
2287 
2288 
2290  omapi_object_t *id)
2291 {
2292  struct class *cp = 0;
2293  isc_result_t status;
2294 
2295  status = subclass_allocate(&cp, MDL);
2296  if (status != ISC_R_SUCCESS)
2297  return status;
2299 
2300  cp->flags = CLASS_DECL_DYNAMIC;
2301 
2302  status = omapi_object_reference (lp, (omapi_object_t *)cp, MDL);
2303  subclass_dereference (&cp, MDL);
2304  return status;
2305 }
2306 
2308  omapi_object_t *id)
2309 {
2310  struct class *cp;
2311  if (lp -> type != dhcp_type_subclass)
2312  return DHCP_R_INVALIDARG;
2313  cp = (struct class *)lp;
2314 
2315 #ifdef DEBUG_OMAPI
2316  log_debug ("OMAPI delete subclass %s", cp -> name);
2317 #endif
2318 
2319  delete_class (cp, 1);
2320 
2321  return ISC_R_SUCCESS;
2322 }
2323 
2324 isc_result_t binding_scope_set_value (struct binding_scope *scope, int createp,
2325  omapi_data_string_t *name,
2326  omapi_typed_data_t *value)
2327 {
2328  struct binding *bp;
2329  char *nname;
2330  struct binding_value *nv;
2331  nname = dmalloc (name -> len + 1, MDL);
2332  if (!nname)
2333  return ISC_R_NOMEMORY;
2334  memcpy (nname, name -> value, name -> len);
2335  nname [name -> len] = 0;
2336  bp = find_binding (scope, nname);
2337  if (!bp && !createp) {
2338  dfree (nname, MDL);
2339  return DHCP_R_UNKNOWNATTRIBUTE;
2340  }
2341  if (!value) {
2342  dfree (nname, MDL);
2343  if (!bp)
2344  return DHCP_R_UNKNOWNATTRIBUTE;
2345  binding_value_dereference (&bp -> value, MDL);
2346  return ISC_R_SUCCESS;
2347  }
2348 
2349  nv = (struct binding_value *)0;
2350  if (!binding_value_allocate (&nv, MDL)) {
2351  dfree (nname, MDL);
2352  return ISC_R_NOMEMORY;
2353  }
2354  switch (value -> type) {
2355  case omapi_datatype_int:
2356  nv -> type = binding_numeric;
2357  nv -> value.intval = value -> u.integer;
2358  break;
2359 
2360  case omapi_datatype_string:
2361  case omapi_datatype_data:
2362  if (!buffer_allocate (&nv -> value.data.buffer,
2363  value -> u.buffer.len, MDL)) {
2365  dfree (nname, MDL);
2366  return ISC_R_NOMEMORY;
2367  }
2368  memcpy (&nv -> value.data.buffer -> data [1],
2369  value -> u.buffer.value, value -> u.buffer.len);
2370  nv -> value.data.len = value -> u.buffer.len;
2371  break;
2372 
2373  case omapi_datatype_object:
2375  dfree (nname, MDL);
2376  return DHCP_R_INVALIDARG;
2377  }
2378 
2379  if (!bp) {
2380  bp = dmalloc (sizeof *bp, MDL);
2381  if (!bp) {
2383  dfree (nname, MDL);
2384  return ISC_R_NOMEMORY;
2385  }
2386  memset (bp, 0, sizeof *bp);
2387  bp -> name = nname;
2388  bp -> next = scope -> bindings;
2389  scope -> bindings = bp;
2390  } else {
2391  if (bp -> value)
2392  binding_value_dereference (&bp -> value, MDL);
2393  dfree (nname, MDL);
2394  }
2395  binding_value_reference (&bp -> value, nv, MDL);
2397  return ISC_R_SUCCESS;
2398 }
2399 
2401  struct binding_scope *scope,
2402  omapi_data_string_t *name)
2403 {
2404  struct binding *bp;
2405  omapi_typed_data_t *td;
2406  isc_result_t status;
2407  char *nname;
2408  nname = dmalloc (name -> len + 1, MDL);
2409  if (!nname)
2410  return ISC_R_NOMEMORY;
2411  memcpy (nname, name -> value, name -> len);
2412  nname [name -> len] = 0;
2413  bp = find_binding (scope, nname);
2414  dfree (nname, MDL);
2415  if (!bp)
2416  return DHCP_R_UNKNOWNATTRIBUTE;
2417  if (!bp -> value)
2418  return DHCP_R_UNKNOWNATTRIBUTE;
2419 
2420  switch (bp -> value -> type) {
2421  case binding_boolean:
2422  td = (omapi_typed_data_t *)0;
2424  bp -> value -> value.boolean);
2425  break;
2426 
2427  case binding_numeric:
2428  td = (omapi_typed_data_t *)0;
2430  (int)
2431  bp -> value -> value.intval);
2432  break;
2433 
2434  case binding_data:
2435  td = (omapi_typed_data_t *)0;
2437  bp -> value -> value.data.len);
2438  if (status != ISC_R_SUCCESS)
2439  return status;
2440  memcpy (&td -> u.buffer.value [0],
2441  bp -> value -> value.data.data,
2442  bp -> value -> value.data.len);
2443  break;
2444 
2445  /* Can't return values for these two (yet?). */
2446  case binding_dns:
2447  case binding_function:
2448  return DHCP_R_INVALIDARG;
2449 
2450  default:
2451  log_fatal ("Impossible case at %s:%d.", MDL);
2452  return ISC_R_FAILURE;
2453  }
2454 
2455  if (status != ISC_R_SUCCESS)
2456  return status;
2457  status = omapi_value_new (value, MDL);
2458  if (status != ISC_R_SUCCESS) {
2460  return status;
2461  }
2462 
2463  omapi_data_string_reference (&(*value) -> name, name, MDL);
2464  omapi_typed_data_reference (&(*value) -> value, td, MDL);
2466 
2467  return ISC_R_SUCCESS;
2468 }
2469 
2471  struct binding_scope *scope)
2472 {
2473  struct binding *bp;
2474  unsigned len;
2475  isc_result_t status;
2476 
2477  for (bp = scope -> bindings; bp; bp = bp -> next) {
2478  if (bp -> value) {
2479  if (bp -> value -> type == binding_dns ||
2480  bp -> value -> type == binding_function)
2481  continue;
2482 
2483  /* Stuff the name. */
2484  len = strlen (bp -> name);
2485  status = omapi_connection_put_uint16 (c, len);
2486  if (status != ISC_R_SUCCESS)
2487  return status;
2488  status = omapi_connection_copyin (c,
2489  (unsigned char *)bp -> name,
2490  len);
2491  if (status != ISC_R_SUCCESS)
2492  return status;
2493 
2494  switch (bp -> value -> type) {
2495  case binding_boolean:
2496  status = omapi_connection_put_uint32 (c,
2497  sizeof (u_int32_t));
2498  if (status != ISC_R_SUCCESS)
2499  return status;
2500  status = (omapi_connection_put_uint32
2501  (c,
2502  ((u_int32_t)(bp -> value -> value.boolean))));
2503  if (status != ISC_R_SUCCESS)
2504  return status;
2505  break;
2506 
2507  case binding_data:
2508  status = (omapi_connection_put_uint32
2509  (c, bp -> value -> value.data.len));
2510  if (status != ISC_R_SUCCESS)
2511  return status;
2512  if (bp -> value -> value.data.len) {
2513  status = (omapi_connection_copyin
2514  (c, bp -> value -> value.data.data,
2515  bp -> value -> value.data.len));
2516  if (status != ISC_R_SUCCESS)
2517  return status;
2518  }
2519  break;
2520 
2521  case binding_numeric:
2522  status = (omapi_connection_put_uint32
2523  (c, sizeof (u_int32_t)));
2524  if (status != ISC_R_SUCCESS)
2525  return status;
2526  status = (omapi_connection_put_uint32
2527  (c, ((u_int32_t)
2528  (bp -> value -> value.intval))));
2529  if (status != ISC_R_SUCCESS)
2530  return status;
2531  break;
2532 
2533 
2534  /* NOTREACHED */
2535  case binding_dns:
2536  case binding_function:
2537  break;
2538  }
2539  }
2540  }
2541  return ISC_R_SUCCESS;
2542 }
2543 
2544 /* vim: set tabstop=8: */
isc_result_t dhcp_failover_state_signal(omapi_object_t *, const char *, va_list)
int supersede_lease(struct lease *, struct lease *, int, int, int, int)
Definition: mdb.c:1095
#define FTS_LAST
Definition: dhcpd.h:508
isc_result_t dhcp_subclass_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:2289
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:3615
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:537
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:2200
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:521
unsigned len
Definition: tree.h:80
isc_result_t dhcp_class_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:2181
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:454
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:539
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:41
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:582
struct class * superclass
Definition: dhcpd.h:1015
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
Definition: options.c:2798
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:985
isc_result_t dhcp_subclass_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:2307
isc_result_t dhcp_class_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:1915
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:915
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:1028
omapi_typed_data_t * value
Definition: omapip.h:91
#define CLASS_DECL_DELETED
Definition: dhcpd.h:1044
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:2263
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:2216
struct lease * next_pending
Definition: dhcpd.h:596
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:517
void lease_ping_timeout(void *)
Definition: dhcpd.c:1235
isc_result_t dhcp_failover_listener_stuff(omapi_object_t *, omapi_object_t *, omapi_object_t *)
struct lease * abandoned
Definition: dhcpd.h:950
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:1340
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:2282
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:908
struct class * billing_class
Definition: dhcpd.h:533
struct group * root_group
Definition: memory.c:31
enum binding_value::@15 type
struct data_string hash_string
Definition: dhcpd.h:1029
#define SCLASS_HASH_SIZE
Definition: dhcpd.h:210
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:914
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:3775
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:2031
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:912
unsigned len
Definition: inet.h:32
dhcp_failover_state_t * failover_peer
Definition: dhcpd.h:961
isc_result_t dhcp_subclass_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:2253
isc_result_t omapi_value_new(omapi_value_t **, const char *, int)
Definition: alloc.c:1012
struct data_string client_identifier
Definition: dhcpd.h:902
#define DHCP_R_KEYCONFLICT
Definition: result.h:52
isc_result_t enter_class(struct class *, int, int)
Definition: mdb.c:73
Definition: dhcpd.h:259
char * name
Definition: dhcpd.h:1016
void expression_dereference(struct expression **eptr, const char *file, int line)
Definition: tree.c:2802
omapi_object_type_t * dhcp_type_pool
Definition: omapi.c:45
struct lease * backup
Definition: dhcpd.h:949
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:1879
#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:1045
void free_lease_state(struct lease_state *, const char *, int)
Definition: salloc.c:196
struct hardware hardware_addr
Definition: dhcpd.h:543
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:2400
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:2688
Definition: tree.h:346
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:2280
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:946
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:469
Definition: dhcpd.h:939
binding_state_t binding_state
Definition: dhcpd.h:577
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:1890
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:1815
isc_result_t class_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2044
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:376
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
Definition: alloc.c:579
struct pool * pool
Definition: dhcpd.h:532
char * name
Definition: dhcpd.h:900
host_hash_t * host_hw_addr_hash
Definition: mdb.c:35
dhcp_failover_listener_t
Definition: dhcpd.h:3586
TIME atsfp
Definition: dhcpd.h:593
isc_result_t dhcp_pool_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:1708
#define cur_time
Definition: dhcpd.h:1988
struct lease * n_hw
Definition: dhcpd.h:524
int free_leases
Definition: dhcpd.h:954
isc_result_t dhcp_failover_link_signal(omapi_object_t *, const char *, va_list)
struct lease * n_uid
Definition: dhcpd.h:524
TIME starts
Definition: dhcpd.h:527
isc_result_t omapi_get_int_value(unsigned long *, omapi_typed_data_t *)
Definition: support.c:836
struct expression * submatch
Definition: dhcpd.h:1036
u_int8_t flags
Definition: dhcpd.h:545
struct lease * free
Definition: dhcpd.h:948
void dfree(void *, const char *, int)
Definition: alloc.c:131
union omapi_typed_data_t::@3 u
struct permit * next
Definition: dhcpd.h:924
int lease_count
Definition: dhcpd.h:953
struct host_decl * n_ipaddr
Definition: dhcpd.h:898
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:2152
int lease_limit
Definition: dhcpd.h:1019
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 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:531
#define GROUP_OBJECT_DELETED
Definition: dhcpd.h:878
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:437
char * name
Definition: dhcpd.h:876
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:594
struct lease ** billed_leases
Definition: dhcpd.h:1021
Definition: dhcpd.h:923
isc_result_t binding_scope_stuff_values(omapi_object_t *c, struct binding_scope *scope)
Definition: omapi.c:2470
isc_result_t omapi_value_dereference(omapi_value_t **, const char *, int)
Definition: alloc.c:1046
unsigned short uid_len
Definition: dhcpd.h:540
struct iaddr ip_addr
Definition: dhcpd.h:526
#define DHCP_R_NOKEYS
Definition: result.h:54
#define EPHEMERAL_FLAGS
Definition: dhcpd.h:559
struct group_object * named_group
Definition: dhcpd.h:911
Definition: dhcpd.h:884
#define DHCP_R_UNCHANGED
Definition: result.h:50
TIME tstp
Definition: dhcpd.h:591
isc_result_t dhcp_class_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2077
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)
struct host_decl * host
Definition: dhcpd.h:530
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:1253
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:1810
unsigned char data[1]
Definition: tree.h:63
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:592
isc_result_t enter_host(struct host_decl *, int, int)
Definition: mdb.c:222
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:877
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:1049
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
Definition: dhcpd.h:455
struct lease * next
Definition: dhcpd.h:523
Definition: tree.h:118
isc_result_t dhcp_lease_free(omapi_object_t *, const char *, int)
struct lease * expired
Definition: dhcpd.h:947
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:2228
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:913
isc_result_t dhcp_class_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:2175
unsigned char uid_buf[7]
Definition: dhcpd.h:542
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:515
struct binding * find_binding(struct binding_scope *scope, const char *name)
Definition: tree.c:3744
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:3615
struct permit * permit_list
Definition: dhcpd.h:944
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:2105
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:2324
struct executable_statement * on_commit
Definition: dhcpd.h:516
Definition: dhcpd.h:1012
const unsigned char * data
Definition: tree.h:79
TIME ends
Definition: dhcpd.h:527
struct binding_scope * scope
Definition: dhcpd.h:529
struct hardware interface
Definition: dhcpd.h:901
isc_result_t dhcp_failover_state_lookup(omapi_object_t **, omapi_object_t *, omapi_object_t *)
struct host_decl * n_dynamic
Definition: dhcpd.h:899
struct group * group
Definition: dhcpd.h:875
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:578
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:941
isc_result_t dhcp_host_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:1516
char * client_hostname
Definition: dhcpd.h:528
struct group * group
Definition: dhcpd.h:1039
struct option_chain_head * agent_options
Definition: dhcpd.h:534
int backup_leases
Definition: dhcpd.h:955