ISC DHCP  4.3.3-P1
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-2015 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  /* We no longer check for a next pointer as that should
461  * be cleared when we destroy the pool and as before we
462  * should only ever be doing that on exit.
463  if (lease->next)
464  lease_dereference (&lease->next, file, line);
465  */
466 
467  if (lease->n_hw)
468  lease_dereference (&lease->n_hw, file, line);
469  if (lease->n_uid)
470  lease_dereference (&lease->n_uid, file, line);
471  if (lease->next_pending)
472  lease_dereference (&lease->next_pending, file, line);
473 #endif
474 
475  return ISC_R_SUCCESS;
476 }
477 
479  const char *name, va_list ap)
480 {
481  /* h should point to (struct lease *) */
482  isc_result_t status;
483 
484  if (h -> type != dhcp_type_lease)
485  return DHCP_R_INVALIDARG;
486 
487  if (!strcmp (name, "updated"))
488  return ISC_R_SUCCESS;
489 
490  /* Try to find some inner object that can take the value. */
491  if (h -> inner && h -> inner -> type -> signal_handler) {
492  status = ((*(h -> inner -> type -> signal_handler))
493  (h -> inner, name, ap));
494  if (status == ISC_R_SUCCESS)
495  return status;
496  }
497  return ISC_R_NOTFOUND;
498 }
499 
501  omapi_object_t *id,
502  omapi_object_t *h)
503 {
504  u_int32_t bouncer;
505  struct lease *lease;
506  isc_result_t status;
507  u_int8_t flagbuf;
508 
509  if (h -> type != dhcp_type_lease)
510  return DHCP_R_INVALIDARG;
511  lease = (struct lease *)h;
512 
513  /* Write out all the values. */
514 
515  status = omapi_connection_put_named_uint32(c, "state",
516  lease->binding_state);
517  if (status != ISC_R_SUCCESS)
518  return (status);
519 
520  status = omapi_connection_put_name (c, "ip-address");
521  if (status != ISC_R_SUCCESS)
522  return status;
523  status = omapi_connection_put_uint32 (c, lease -> ip_addr.len);
524  if (status != ISC_R_SUCCESS)
525  return status;
526  status = omapi_connection_copyin (c, lease -> ip_addr.iabuf,
527  lease -> ip_addr.len);
528  if (status != ISC_R_SUCCESS)
529  return status;
530 
531  if (lease -> uid_len) {
532  status = omapi_connection_put_name (c,
533  "dhcp-client-identifier");
534  if (status != ISC_R_SUCCESS)
535  return status;
536  status = omapi_connection_put_uint32 (c, lease -> uid_len);
537  if (status != ISC_R_SUCCESS)
538  return status;
539  if (lease -> uid_len) {
540  status = omapi_connection_copyin (c, lease -> uid,
541  lease -> uid_len);
542  if (status != ISC_R_SUCCESS)
543  return status;
544  }
545  }
546 
547  if (lease -> client_hostname) {
548  status = omapi_connection_put_name (c, "client-hostname");
549  if (status != ISC_R_SUCCESS)
550  return status;
551  status =
553  lease -> client_hostname);
554  if (status != ISC_R_SUCCESS)
555  return status;
556  }
557 
558  if (lease -> host) {
559  status = omapi_connection_put_name (c, "host");
560  if (status != ISC_R_SUCCESS)
561  return status;
562  status = omapi_connection_put_handle (c,
563  (omapi_object_t *)
564  lease -> host);
565  if (status != ISC_R_SUCCESS)
566  return status;
567  }
568 
569  status = omapi_connection_put_name (c, "subnet");
570  if (status != ISC_R_SUCCESS)
571  return status;
573  (c, (omapi_object_t *)lease -> subnet);
574  if (status != ISC_R_SUCCESS)
575  return status;
576 
577  status = omapi_connection_put_name (c, "pool");
578  if (status != ISC_R_SUCCESS)
579  return status;
580  status = omapi_connection_put_handle (c,
581  (omapi_object_t *)lease -> pool);
582  if (status != ISC_R_SUCCESS)
583  return status;
584 
585  if (lease -> billing_class) {
586  status = omapi_connection_put_name (c, "billing-class");
587  if (status != ISC_R_SUCCESS)
588  return status;
590  (c, (omapi_object_t *)lease -> billing_class);
591  if (status != ISC_R_SUCCESS)
592  return status;
593  }
594 
595  if (lease -> hardware_addr.hlen) {
596  status = omapi_connection_put_name (c, "hardware-address");
597  if (status != ISC_R_SUCCESS)
598  return status;
600  (c,
601  (unsigned long)(lease -> hardware_addr.hlen - 1)));
602  if (status != ISC_R_SUCCESS)
603  return status;
604  status = (omapi_connection_copyin
605  (c, &lease -> hardware_addr.hbuf [1],
606  (unsigned long)(lease -> hardware_addr.hlen - 1)));
607 
608  if (status != ISC_R_SUCCESS)
609  return status;
610 
611  status = omapi_connection_put_named_uint32(c, "hardware-type",
612  lease->hardware_addr.hbuf[0]);
613  if (status != ISC_R_SUCCESS)
614  return (status);
615  }
616 
617  /* TIME values may be 64-bit, depending on system architecture.
618  * OMAPI must be system independent, both in terms of transmitting
619  * bytes on the wire in network byte order, and in terms of being
620  * readable and usable by both systems.
621  *
622  * XXX: In a future feature release, a put_int64() should be made
623  * to exist, and perhaps a put_time() wrapper that selects which
624  * to use based upon sizeof(TIME). In the meantime, use existing,
625  * 32-bit, code.
626  */
627  bouncer = (u_int32_t)lease->ends;
628  status = omapi_connection_put_named_uint32(c, "ends", bouncer);
629  if (status != ISC_R_SUCCESS)
630  return (status);
631 
632  bouncer = (u_int32_t)lease->starts;
633  status = omapi_connection_put_named_uint32(c, "starts", bouncer);
634  if (status != ISC_R_SUCCESS)
635  return (status);
636 
637  bouncer = (u_int32_t)lease->tstp;
638  status = omapi_connection_put_named_uint32(c, "tstp", bouncer);
639  if (status != ISC_R_SUCCESS)
640  return (status);
641 
642  bouncer = (u_int32_t)lease->tsfp;
643  status = omapi_connection_put_named_uint32(c, "tsfp", bouncer);
644  if (status != ISC_R_SUCCESS)
645  return status;
646 
647  bouncer = (u_int32_t)lease->atsfp;
648  status = omapi_connection_put_named_uint32(c, "atsfp", bouncer);
649  if (status != ISC_R_SUCCESS)
650  return status;
651 
652  bouncer = (u_int32_t)lease->cltt;
653  status = omapi_connection_put_named_uint32(c, "cltt", bouncer);
654  if (status != ISC_R_SUCCESS)
655  return status;
656 
657  status = omapi_connection_put_name (c, "flags");
658  if (status != ISC_R_SUCCESS)
659  return status;
660  status = omapi_connection_put_uint32(c, sizeof(flagbuf));
661  if (status != ISC_R_SUCCESS)
662  return status;
663  flagbuf = lease->flags & EPHEMERAL_FLAGS;
664  status = omapi_connection_copyin(c, &flagbuf, sizeof(flagbuf));
665  if (status != ISC_R_SUCCESS)
666  return status;
667 
668  if (lease -> scope) {
669  status = binding_scope_stuff_values (c, lease -> scope);
670  if (status != ISC_R_SUCCESS)
671  return status;
672  }
673 
674  /* Write out the inner object, if any. */
675  if (h -> inner && h -> inner -> type -> stuff_values) {
676  status = ((*(h -> inner -> type -> stuff_values))
677  (c, id, h -> inner));
678  if (status == ISC_R_SUCCESS)
679  return status;
680  }
681 
682  return ISC_R_SUCCESS;
683 }
684 
686  omapi_object_t *id, omapi_object_t *ref)
687 {
688  omapi_value_t *tv = (omapi_value_t *)0;
689  isc_result_t status;
690  struct lease *lease;
691 
692  if (!ref)
693  return DHCP_R_NOKEYS;
694 
695  /* First see if we were sent a handle. */
696  status = omapi_get_value_str (ref, id, "handle", &tv);
697  if (status == ISC_R_SUCCESS) {
698  status = omapi_handle_td_lookup (lp, tv -> value);
699 
701  if (status != ISC_R_SUCCESS)
702  return status;
703 
704  /* Don't return the object if the type is wrong. */
705  if ((*lp) -> type != dhcp_type_lease) {
707  return DHCP_R_INVALIDARG;
708  }
709  }
710 
711  /* Now look for an IP address. */
712  status = omapi_get_value_str (ref, id, "ip-address", &tv);
713  if (status == ISC_R_SUCCESS) {
714  lease = (struct lease *)0;
715  lease_ip_hash_lookup(&lease, lease_ip_addr_hash,
716  tv->value->u.buffer.value,
717  tv->value->u.buffer.len, MDL);
718 
720 
721  /* If we already have a lease, and it's not the same one,
722  then the query was invalid. */
723  if (*lp && *lp != (omapi_object_t *)lease) {
725  lease_dereference (&lease, MDL);
726  return DHCP_R_KEYCONFLICT;
727  } else if (!lease) {
728  if (*lp)
730  return ISC_R_NOTFOUND;
731  } else if (!*lp) {
732  /* XXX fix so that hash lookup itself creates
733  XXX the reference. */
735  (omapi_object_t *)lease, MDL);
736  lease_dereference (&lease, MDL);
737  }
738  }
739 
740  /* Now look for a client identifier. */
741  status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);
742  if (status == ISC_R_SUCCESS) {
743  lease = (struct lease *)0;
744  lease_id_hash_lookup(&lease, lease_uid_hash,
745  tv->value->u.buffer.value,
746  tv->value->u.buffer.len, MDL);
748 
749  if (*lp && *lp != (omapi_object_t *)lease) {
751  lease_dereference (&lease, MDL);
752  return DHCP_R_KEYCONFLICT;
753  } else if (!lease) {
754  if (*lp)
756  return ISC_R_NOTFOUND;
757  } else if (lease -> n_uid) {
758  if (*lp)
760  return DHCP_R_MULTIPLE;
761  } else if (!*lp) {
762  /* XXX fix so that hash lookup itself creates
763  XXX the reference. */
765  (omapi_object_t *)lease, MDL);
766  lease_dereference (&lease, MDL);
767  }
768  }
769 
770  /* Now look for a hardware address. */
771  status = omapi_get_value_str (ref, id, "hardware-address", &tv);
772  if (status == ISC_R_SUCCESS) {
773  unsigned char *haddr;
774  unsigned int len;
775 
776  len = tv -> value -> u.buffer.len + 1;
777  haddr = dmalloc (len, MDL);
778  if (!haddr) {
780  return ISC_R_NOMEMORY;
781  }
782 
783  memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1);
785 
786  status = omapi_get_value_str (ref, id, "hardware-type", &tv);
787  if (status == ISC_R_SUCCESS) {
788  if (tv -> value -> type == omapi_datatype_data) {
789  if ((tv -> value -> u.buffer.len != 4) ||
790  (tv -> value -> u.buffer.value[0] != 0) ||
791  (tv -> value -> u.buffer.value[1] != 0) ||
792  (tv -> value -> u.buffer.value[2] != 0)) {
794  dfree (haddr, MDL);
795  return DHCP_R_INVALIDARG;
796  }
797 
798  haddr[0] = tv -> value -> u.buffer.value[3];
799  } else if (tv -> value -> type == omapi_datatype_int) {
800  haddr[0] = (unsigned char)
801  tv -> value -> u.integer;
802  } else {
804  dfree (haddr, MDL);
805  return DHCP_R_INVALIDARG;
806  }
807 
809  } else {
810  /* If no hardware-type is specified, default to
811  ethernet. This may or may not be a good idea,
812  but Telus is currently relying on this behavior.
813  - DPN */
814  haddr[0] = HTYPE_ETHER;
815  }
816 
817  lease = (struct lease *)0;
818  lease_id_hash_lookup(&lease, lease_hw_addr_hash, haddr, len,
819  MDL);
820  dfree (haddr, MDL);
821 
822  if (*lp && *lp != (omapi_object_t *)lease) {
824  lease_dereference (&lease, MDL);
825  return DHCP_R_KEYCONFLICT;
826  } else if (!lease) {
827  if (*lp)
829  return ISC_R_NOTFOUND;
830  } else if (lease -> n_hw) {
831  if (*lp)
833  lease_dereference (&lease, MDL);
834  return DHCP_R_MULTIPLE;
835  } else if (!*lp) {
836  /* XXX fix so that hash lookup itself creates
837  XXX the reference. */
839  (omapi_object_t *)lease, MDL);
840  lease_dereference (&lease, MDL);
841  }
842  }
843 
844  /* If we get to here without finding a lease, no valid key was
845  specified. */
846  if (!*lp)
847  return DHCP_R_NOKEYS;
848  return ISC_R_SUCCESS;
849 }
850 
852  omapi_object_t *id)
853 {
854  return ISC_R_NOTIMPLEMENTED;
855 }
856 
858  omapi_object_t *id)
859 {
860  return ISC_R_NOTIMPLEMENTED;
861 }
862 
864  omapi_object_t *id,
865  omapi_data_string_t *name,
866  omapi_typed_data_t *value)
867 {
868  struct host_decl *host;
869  isc_result_t status;
870 
871  if (h -> type != dhcp_type_host)
872  return DHCP_R_INVALIDARG;
873  host = (struct host_decl *)h;
874 
875  /* XXX For now, we can only set these values on new host objects.
876  XXX Soon, we need to be able to update host objects. */
877  if (!omapi_ds_strcmp (name, "name")) {
878  if (host -> name)
879  return ISC_R_EXISTS;
880  if (value && (value -> type == omapi_datatype_data ||
881  value -> type == omapi_datatype_string)) {
882  host -> name = dmalloc (value -> u.buffer.len + 1,
883  MDL);
884  if (!host -> name)
885  return ISC_R_NOMEMORY;
886  memcpy (host -> name,
887  value -> u.buffer.value,
888  value -> u.buffer.len);
889  host -> name [value -> u.buffer.len] = 0;
890  } else
891  return DHCP_R_INVALIDARG;
892  return ISC_R_SUCCESS;
893  }
894 
895  if (!omapi_ds_strcmp (name, "group")) {
896  if (value && (value -> type == omapi_datatype_data ||
897  value -> type == omapi_datatype_string)) {
898  struct group_object *group;
899  group = (struct group_object *)0;
900  group_hash_lookup (&group, group_name_hash,
901  (char *)value -> u.buffer.value,
902  value -> u.buffer.len, MDL);
903  if (!group || (group -> flags & GROUP_OBJECT_DELETED))
904  return ISC_R_NOTFOUND;
905  if (host -> group)
906  group_dereference (&host -> group, MDL);
907  group_reference (&host -> group, group -> group, MDL);
908  if (host -> named_group)
909  group_object_dereference (&host -> named_group,
910  MDL);
911  group_object_reference (&host -> named_group,
912  group, MDL);
913  group_object_dereference (&group, MDL);
914  } else
915  return DHCP_R_INVALIDARG;
916  return ISC_R_SUCCESS;
917  }
918 
919  if (!omapi_ds_strcmp (name, "hardware-address")) {
920  if (host -> interface.hlen)
921  return ISC_R_EXISTS;
922  if (value && (value -> type == omapi_datatype_data ||
923  value -> type == omapi_datatype_string)) {
924  if (value -> u.buffer.len >
925  (sizeof host -> interface.hbuf) - 1)
926  return DHCP_R_INVALIDARG;
927  memcpy (&host -> interface.hbuf [1],
928  value -> u.buffer.value,
929  value -> u.buffer.len);
930  host -> interface.hlen = value -> u.buffer.len + 1;
931  } else
932  return DHCP_R_INVALIDARG;
933  return ISC_R_SUCCESS;
934  }
935 
936  if (!omapi_ds_strcmp (name, "hardware-type")) {
937  int type;
938  if ((value != NULL) &&
939  ((value->type == omapi_datatype_data) &&
940  (value->u.buffer.len == sizeof(type)))) {
941  if (value->u.buffer.len > sizeof(type))
942  return (DHCP_R_INVALIDARG);
943  memcpy(&type, value->u.buffer.value,
944  value->u.buffer.len);
945  type = ntohl(type);
946  } else if ((value != NULL) &&
947  (value->type == omapi_datatype_int))
948  type = value->u.integer;
949  else
950  return (DHCP_R_INVALIDARG);
951  host->interface.hbuf[0] = type;
952  return (ISC_R_SUCCESS);
953  }
954 
955  if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
956  if (host -> client_identifier.data)
957  return ISC_R_EXISTS;
958  if (value && (value -> type == omapi_datatype_data ||
959  value -> type == omapi_datatype_string)) {
960  if (!buffer_allocate (&host -> client_identifier.buffer,
961  value -> u.buffer.len, MDL))
962  return ISC_R_NOMEMORY;
963  host -> client_identifier.data =
964  &host -> client_identifier.buffer -> data [0];
965  memcpy (host -> client_identifier.buffer -> data,
966  value -> u.buffer.value,
967  value -> u.buffer.len);
968  host -> client_identifier.len = value -> u.buffer.len;
969  } else
970  return DHCP_R_INVALIDARG;
971  return ISC_R_SUCCESS;
972  }
973 
974  if (!omapi_ds_strcmp (name, "ip-address")) {
975  if (host -> fixed_addr)
976  option_cache_dereference (&host -> fixed_addr, MDL);
977  if (!value)
978  return ISC_R_SUCCESS;
979  if (value && (value -> type == omapi_datatype_data ||
980  value -> type == omapi_datatype_string)) {
981  struct data_string ds;
982  memset (&ds, 0, sizeof ds);
983  ds.len = value -> u.buffer.len;
984  if (!buffer_allocate (&ds.buffer, ds.len, MDL))
985  return ISC_R_NOMEMORY;
986  ds.data = (&ds.buffer -> data [0]);
987  memcpy (ds.buffer -> data,
988  value -> u.buffer.value, ds.len);
989  if (!option_cache (&host -> fixed_addr,
990  &ds, (struct expression *)0,
991  (struct option *)0, MDL)) {
992  data_string_forget (&ds, MDL);
993  return ISC_R_NOMEMORY;
994  }
995  data_string_forget (&ds, MDL);
996  } else
997  return DHCP_R_INVALIDARG;
998  return ISC_R_SUCCESS;
999  }
1000 
1001  if (!omapi_ds_strcmp (name, "statements")) {
1002  if (!host -> group) {
1003  if (!clone_group (&host -> group, root_group, MDL))
1004  return ISC_R_NOMEMORY;
1005  } else {
1006  if (host -> group -> statements &&
1007  (!host -> named_group ||
1008  host -> group != host -> named_group -> group) &&
1009  host -> group != root_group)
1010  return ISC_R_EXISTS;
1011  if (!clone_group (&host -> group, host -> group, MDL))
1012  return ISC_R_NOMEMORY;
1013  }
1014  if (!host -> group)
1015  return ISC_R_NOMEMORY;
1016  if (value && (value -> type == omapi_datatype_data ||
1017  value -> type == omapi_datatype_string)) {
1018  struct parse *parse;
1019  int lose = 0;
1020  parse = (struct parse *)0;
1021  status = new_parse(&parse, -1,
1022  (char *) value->u.buffer.value,
1023  value->u.buffer.len,
1024  "network client", 0);
1025  if (status != ISC_R_SUCCESS || parse == NULL)
1026  return status;
1027 
1029  (&host -> group -> statements, parse, &lose,
1030  context_any))) {
1031  end_parse (&parse);
1032  return DHCP_R_BADPARSE;
1033  }
1034  end_parse (&parse);
1035  } else
1036  return DHCP_R_INVALIDARG;
1037  return ISC_R_SUCCESS;
1038  }
1039 
1040  /* The "known" flag isn't supported in the database yet, but it's
1041  legitimate. */
1042  if (!omapi_ds_strcmp (name, "known")) {
1043  return ISC_R_SUCCESS;
1044  }
1045 
1046  /* Try to find some inner object that can take the value. */
1047  if (h -> inner && h -> inner -> type -> set_value) {
1048  status = ((*(h -> inner -> type -> set_value))
1049  (h -> inner, id, name, value));
1050  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1051  return status;
1052  }
1053 
1054  return DHCP_R_UNKNOWNATTRIBUTE;
1055 }
1056 
1057 
1059  omapi_data_string_t *name,
1060  omapi_value_t **value)
1061 {
1062  struct host_decl *host;
1063  isc_result_t status;
1064  struct data_string ip_addrs;
1065 
1066  if (h -> type != dhcp_type_host)
1067  return DHCP_R_INVALIDARG;
1068  host = (struct host_decl *)h;
1069 
1070  if (!omapi_ds_strcmp (name, "ip-addresses")) {
1071  memset (&ip_addrs, 0, sizeof ip_addrs);
1072  if (host -> fixed_addr &&
1073  evaluate_option_cache (&ip_addrs, (struct packet *)0,
1074  (struct lease *)0,
1075  (struct client_state *)0,
1076  (struct option_state *)0,
1077  (struct option_state *)0,
1078  &global_scope,
1079  host -> fixed_addr, MDL)) {
1080  status = omapi_make_const_value (value, name,
1081  ip_addrs.data,
1082  ip_addrs.len, MDL);
1083  data_string_forget (&ip_addrs, MDL);
1084  return status;
1085  }
1086  return ISC_R_NOTFOUND;
1087  }
1088 
1089  if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {
1090  if (!host -> client_identifier.len)
1091  return ISC_R_NOTFOUND;
1092  return omapi_make_const_value (value, name,
1093  host -> client_identifier.data,
1094  host -> client_identifier.len,
1095  MDL);
1096  }
1097 
1098  if (!omapi_ds_strcmp (name, "name"))
1099  return omapi_make_string_value (value, name, host -> name,
1100  MDL);
1101 
1102  if (!omapi_ds_strcmp (name, "hardware-address")) {
1103  if (!host -> interface.hlen)
1104  return ISC_R_NOTFOUND;
1105  return (omapi_make_const_value
1106  (value, name, &host -> interface.hbuf [1],
1107  (unsigned long)(host -> interface.hlen - 1), MDL));
1108  }
1109 
1110  if (!omapi_ds_strcmp (name, "hardware-type")) {
1111  if (!host -> interface.hlen)
1112  return ISC_R_NOTFOUND;
1113  return omapi_make_int_value (value, name,
1114  host -> interface.hbuf [0], MDL);
1115  }
1116 
1117  /* Try to find some inner object that can take the value. */
1118  if (h -> inner && h -> inner -> type -> get_value) {
1119  status = ((*(h -> inner -> type -> get_value))
1120  (h -> inner, id, name, value));
1121  if (status == ISC_R_SUCCESS)
1122  return status;
1123  }
1124  return DHCP_R_UNKNOWNATTRIBUTE;
1125 }
1126 
1127 isc_result_t dhcp_host_destroy (omapi_object_t *h, const char *file, int line)
1128 {
1129 
1130  if (h -> type != dhcp_type_host)
1131  return DHCP_R_INVALIDARG;
1132 
1133  struct host_decl *host = (struct host_decl *)h;
1134  if (host -> n_ipaddr)
1135  host_dereference (&host -> n_ipaddr, file, line);
1136  if (host -> n_dynamic)
1137  host_dereference (&host -> n_dynamic, file, line);
1138  if (host -> name) {
1139  dfree (host -> name, file, line);
1140  host -> name = (char *)0;
1141  }
1142  data_string_forget (&host -> client_identifier, file, line);
1143  if (host -> fixed_addr)
1144  option_cache_dereference (&host -> fixed_addr, file, line);
1145  if (host -> group)
1146  group_dereference (&host -> group, file, line);
1147  if (host -> named_group)
1149  &host -> named_group, file, line);
1150  data_string_forget (&host -> auth_key_id, file, line);
1151 
1152  return ISC_R_SUCCESS;
1153 }
1154 
1156  const char *name, va_list ap)
1157 {
1158  struct host_decl *host;
1159  isc_result_t status;
1160  int updatep = 0;
1161 
1162  if (h -> type != dhcp_type_host)
1163  return DHCP_R_INVALIDARG;
1164  host = (struct host_decl *)h;
1165 
1166  if (!strcmp (name, "updated")) {
1167  /* There must be a client identifier of some sort. */
1168  if (host -> interface.hlen == 0 &&
1169  !host -> client_identifier.len)
1170  return DHCP_R_INVALIDARG;
1171 
1172  if (!host -> name) {
1173  char hnbuf [64];
1174  sprintf (hnbuf, "nh%08lx%08lx",
1175  (unsigned long)cur_time, (unsigned long)host);
1176  host -> name = dmalloc (strlen (hnbuf) + 1, MDL);
1177  if (!host -> name)
1178  return ISC_R_NOMEMORY;
1179  strcpy (host -> name, hnbuf);
1180  }
1181 
1182 #ifdef DEBUG_OMAPI
1183  log_debug ("OMAPI added host %s", host -> name);
1184 #endif
1185  status = enter_host (host, 1, 1);
1186  if (status != ISC_R_SUCCESS)
1187  return status;
1188  updatep = 1;
1189  }
1190 
1191  /* Try to find some inner object that can take the value. */
1192  if (h -> inner && h -> inner -> type -> signal_handler) {
1193  status = ((*(h -> inner -> type -> signal_handler))
1194  (h -> inner, name, ap));
1195  if (status == ISC_R_SUCCESS)
1196  return status;
1197  }
1198  if (updatep)
1199  return ISC_R_SUCCESS;
1200  return ISC_R_NOTFOUND;
1201 }
1202 
1204  omapi_object_t *id,
1205  omapi_object_t *h)
1206 {
1207  struct host_decl *host;
1208  isc_result_t status;
1209  struct data_string ip_addrs;
1210 
1211  if (h -> type != dhcp_type_host)
1212  return DHCP_R_INVALIDARG;
1213  host = (struct host_decl *)h;
1214 
1215  /* Write out all the values. */
1216 
1217  memset (&ip_addrs, 0, sizeof ip_addrs);
1218  if (host -> fixed_addr &&
1219  evaluate_option_cache (&ip_addrs, (struct packet *)0,
1220  (struct lease *)0,
1221  (struct client_state *)0,
1222  (struct option_state *)0,
1223  (struct option_state *)0,
1224  &global_scope,
1225  host -> fixed_addr, MDL)) {
1226  status = omapi_connection_put_name (c, "ip-address");
1227  if (status != ISC_R_SUCCESS)
1228  return status;
1229  status = omapi_connection_put_uint32 (c, ip_addrs.len);
1230  if (status != ISC_R_SUCCESS)
1231  return status;
1232  status = omapi_connection_copyin (c,
1233  ip_addrs.data, ip_addrs.len);
1234  if (status != ISC_R_SUCCESS)
1235  return status;
1236  data_string_forget (&ip_addrs, MDL);
1237  }
1238 
1239  if (host -> client_identifier.len) {
1240  status = omapi_connection_put_name (c,
1241  "dhcp-client-identifier");
1242  if (status != ISC_R_SUCCESS)
1243  return status;
1244  status = (omapi_connection_put_uint32
1245  (c, host -> client_identifier.len));
1246  if (status != ISC_R_SUCCESS)
1247  return status;
1248  status = (omapi_connection_copyin
1249  (c,
1250  host -> client_identifier.data,
1251  host -> client_identifier.len));
1252  if (status != ISC_R_SUCCESS)
1253  return status;
1254  }
1255 
1256  if (host -> name) {
1257  status = omapi_connection_put_name (c, "name");
1258  if (status != ISC_R_SUCCESS)
1259  return status;
1260  status = omapi_connection_put_string (c, host -> name);
1261  if (status != ISC_R_SUCCESS)
1262  return status;
1263  }
1264 
1265  if (host -> interface.hlen) {
1266  status = omapi_connection_put_name (c, "hardware-address");
1267  if (status != ISC_R_SUCCESS)
1268  return status;
1269  status = (omapi_connection_put_uint32
1270  (c, (unsigned long)(host -> interface.hlen - 1)));
1271  if (status != ISC_R_SUCCESS)
1272  return status;
1273  status = (omapi_connection_copyin
1274  (c, &host -> interface.hbuf [1],
1275  (unsigned long)(host -> interface.hlen - 1)));
1276  if (status != ISC_R_SUCCESS)
1277  return status;
1278 
1279  status = omapi_connection_put_named_uint32(c, "hardware-type",
1280  host->interface.hbuf[0]);
1281  if (status != ISC_R_SUCCESS)
1282  return status;
1283  }
1284 
1285  /* Write out the inner object, if any. */
1286  if (h -> inner && h -> inner -> type -> stuff_values) {
1287  status = ((*(h -> inner -> type -> stuff_values))
1288  (c, id, h -> inner));
1289  if (status == ISC_R_SUCCESS)
1290  return status;
1291  }
1292 
1293  return ISC_R_SUCCESS;
1294 }
1295 
1297  omapi_object_t *id, omapi_object_t *ref)
1298 {
1299  omapi_value_t *tv = (omapi_value_t *)0;
1300  isc_result_t status;
1301  struct host_decl *host;
1302 
1303  if (!ref)
1304  return DHCP_R_NOKEYS;
1305 
1306  /* First see if we were sent a handle. */
1307  status = omapi_get_value_str (ref, id, "handle", &tv);
1308  if (status == ISC_R_SUCCESS) {
1309  status = omapi_handle_td_lookup (lp, tv -> value);
1310 
1312  if (status != ISC_R_SUCCESS)
1313  return status;
1314 
1315  /* Don't return the object if the type is wrong. */
1316  if ((*lp) -> type != dhcp_type_host) {
1318  return DHCP_R_INVALIDARG;
1319  }
1320  if (((struct host_decl *)(*lp)) -> flags & HOST_DECL_DELETED) {
1322  }
1323  }
1324 
1325  /* Now look for a client identifier. */
1326  status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);
1327  if (status == ISC_R_SUCCESS) {
1328  host = (struct host_decl *)0;
1329  host_hash_lookup (&host, host_uid_hash,
1330  tv -> value -> u.buffer.value,
1331  tv -> value -> u.buffer.len, MDL);
1333 
1334  if (*lp && *lp != (omapi_object_t *)host) {
1336  if (host)
1337  host_dereference (&host, MDL);
1338  return DHCP_R_KEYCONFLICT;
1339  } else if (!host || (host -> flags & HOST_DECL_DELETED)) {
1340  if (*lp)
1342  if (host)
1343  host_dereference (&host, MDL);
1344  return ISC_R_NOTFOUND;
1345  } else if (!*lp) {
1346  /* XXX fix so that hash lookup itself creates
1347  XXX the reference. */
1349  (omapi_object_t *)host, MDL);
1350  host_dereference (&host, MDL);
1351  }
1352  }
1353 
1354  /* Now look for a hardware address. */
1355  status = omapi_get_value_str (ref, id, "hardware-address", &tv);
1356  if (status == ISC_R_SUCCESS) {
1357  unsigned char *haddr;
1358  unsigned int len;
1359 
1360  len = tv -> value -> u.buffer.len + 1;
1361  haddr = dmalloc (len, MDL);
1362  if (!haddr) {
1364  return ISC_R_NOMEMORY;
1365  }
1366 
1367  memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1);
1369 
1370  status = omapi_get_value_str (ref, id, "hardware-type", &tv);
1371  if (status == ISC_R_SUCCESS) {
1372  if (tv -> value -> type == omapi_datatype_data) {
1373  if ((tv -> value -> u.buffer.len != 4) ||
1374  (tv -> value -> u.buffer.value[0] != 0) ||
1375  (tv -> value -> u.buffer.value[1] != 0) ||
1376  (tv -> value -> u.buffer.value[2] != 0)) {
1378  dfree (haddr, MDL);
1379  return DHCP_R_INVALIDARG;
1380  }
1381 
1382  haddr[0] = tv -> value -> u.buffer.value[3];
1383  } else if (tv -> value -> type == omapi_datatype_int) {
1384  haddr[0] = (unsigned char)
1385  tv -> value -> u.integer;
1386  } else {
1388  dfree (haddr, MDL);
1389  return DHCP_R_INVALIDARG;
1390  }
1391 
1393  } else {
1394  /* If no hardware-type is specified, default to
1395  ethernet. This may or may not be a good idea,
1396  but Telus is currently relying on this behavior.
1397  - DPN */
1398  haddr[0] = HTYPE_ETHER;
1399  }
1400 
1401  host = (struct host_decl *)0;
1402  host_hash_lookup (&host, host_hw_addr_hash, haddr, len, MDL);
1403  dfree (haddr, MDL);
1404 
1405  if (*lp && *lp != (omapi_object_t *)host) {
1407  if (host)
1408  host_dereference (&host, MDL);
1409  return DHCP_R_KEYCONFLICT;
1410  } else if (!host || (host -> flags & HOST_DECL_DELETED)) {
1411  if (*lp)
1413  if (host)
1414  host_dereference (&host, MDL);
1415  return ISC_R_NOTFOUND;
1416  } else if (!*lp) {
1417  /* XXX fix so that hash lookup itself creates
1418  XXX the reference. */
1420  (omapi_object_t *)host, MDL);
1421  host_dereference (&host, MDL);
1422  }
1423  }
1424 
1425  /* Now look for an ip address. */
1426  status = omapi_get_value_str (ref, id, "ip-address", &tv);
1427  if (status == ISC_R_SUCCESS) {
1428  struct lease *l;
1429 
1430  /* first find the lease for this ip address */
1431  l = (struct lease *)0;
1432  lease_ip_hash_lookup(&l, lease_ip_addr_hash,
1433  tv->value->u.buffer.value,
1434  tv->value->u.buffer.len, MDL);
1436 
1437  if (!l && !*lp)
1438  return ISC_R_NOTFOUND;
1439 
1440  if (l) {
1441  /* now use that to get a host */
1442  host = (struct host_decl *)0;
1443  host_hash_lookup (&host, host_hw_addr_hash,
1444  l -> hardware_addr.hbuf,
1445  l -> hardware_addr.hlen, MDL);
1446 
1447  if (host && *lp && *lp != (omapi_object_t *)host) {
1449  if (host)
1450  host_dereference (&host, MDL);
1451  return DHCP_R_KEYCONFLICT;
1452  } else if (!host || (host -> flags &
1453  HOST_DECL_DELETED)) {
1454  if (host)
1455  host_dereference (&host, MDL);
1456  if (!*lp)
1457  return ISC_R_NOTFOUND;
1458  } else if (!*lp) {
1459  /* XXX fix so that hash lookup itself creates
1460  XXX the reference. */
1462  MDL);
1463  host_dereference (&host, MDL);
1464  }
1465  lease_dereference (&l, MDL);
1466  }
1467  }
1468 
1469  /* Now look for a name. */
1470  status = omapi_get_value_str (ref, id, "name", &tv);
1471  if (status == ISC_R_SUCCESS) {
1472  host = (struct host_decl *)0;
1473  host_hash_lookup (&host, host_name_hash,
1474  tv -> value -> u.buffer.value,
1475  tv -> value -> u.buffer.len, MDL);
1477 
1478  if (*lp && *lp != (omapi_object_t *)host) {
1480  if (host)
1481  host_dereference (&host, MDL);
1482  return DHCP_R_KEYCONFLICT;
1483  } else if (!host || (host -> flags & HOST_DECL_DELETED)) {
1484  if (host)
1485  host_dereference (&host, MDL);
1486  return ISC_R_NOTFOUND;
1487  } else if (!*lp) {
1488  /* XXX fix so that hash lookup itself creates
1489  XXX the reference. */
1491  (omapi_object_t *)host, MDL);
1492  host_dereference (&host, MDL);
1493  }
1494  }
1495 
1496  /* If we get to here without finding a host, no valid key was
1497  specified. */
1498  if (!*lp)
1499  return DHCP_R_NOKEYS;
1500  return ISC_R_SUCCESS;
1501 }
1502 
1504  omapi_object_t *id)
1505 {
1506  struct host_decl *hp;
1507  isc_result_t status;
1508  hp = (struct host_decl *)0;
1509  status = host_allocate (&hp, MDL);
1510  if (status != ISC_R_SUCCESS)
1511  return status;
1512  group_reference (&hp -> group, root_group, MDL);
1513  hp -> flags = HOST_DECL_DYNAMIC;
1514  status = omapi_object_reference (lp, (omapi_object_t *)hp, MDL);
1515  host_dereference (&hp, MDL);
1516  return status;
1517 }
1518 
1520  omapi_object_t *id)
1521 {
1522  struct host_decl *hp;
1523  if (lp -> type != dhcp_type_host)
1524  return DHCP_R_INVALIDARG;
1525  hp = (struct host_decl *)lp;
1526 
1527 #ifdef DEBUG_OMAPI
1528  log_debug ("OMAPI delete host %s", hp -> name);
1529 #endif
1530  delete_host (hp, 1);
1531  return ISC_R_SUCCESS;
1532 }
1533 
1535  omapi_object_t *id,
1537  omapi_typed_data_t *value)
1538 {
1539  /* h should point to (struct pool *) */
1540  isc_result_t status;
1541 
1542  if (h -> type != dhcp_type_pool)
1543  return DHCP_R_INVALIDARG;
1544 
1545  /* No values to set yet. */
1546 
1547  /* Try to find some inner object that can take the value. */
1548  if (h -> inner && h -> inner -> type -> set_value) {
1549  status = ((*(h -> inner -> type -> set_value))
1550  (h -> inner, id, name, value));
1551  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1552  return status;
1553  }
1554 
1555  return DHCP_R_UNKNOWNATTRIBUTE;
1556 }
1557 
1558 
1561  omapi_value_t **value)
1562 {
1563  /* h should point to (struct pool *) */
1564  isc_result_t status;
1565 
1566  if (h -> type != dhcp_type_pool)
1567  return DHCP_R_INVALIDARG;
1568 
1569  /* No values to get yet. */
1570 
1571  /* Try to find some inner object that can provide the value. */
1572  if (h -> inner && h -> inner -> type -> get_value) {
1573  status = ((*(h -> inner -> type -> get_value))
1574  (h -> inner, id, name, value));
1575  if (status == ISC_R_SUCCESS)
1576  return status;
1577  }
1578  return DHCP_R_UNKNOWNATTRIBUTE;
1579 }
1580 
1581 isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line)
1582 {
1583 #if defined (DEBUG_MEMORY_LEAKAGE) || \
1584  defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1585  struct permit *pc, *pn;
1586 #endif
1587 
1588  if (h -> type != dhcp_type_pool)
1589  return DHCP_R_INVALIDARG;
1590 
1591 #if defined (DEBUG_MEMORY_LEAKAGE) || \
1592  defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1593  struct pool *pool = (struct pool *)h;
1594  if (pool -> next)
1595  pool_dereference (&pool -> next, file, line);
1596  if (pool -> group)
1597  group_dereference (&pool -> group, file, line);
1598  if (pool -> shared_network)
1599  shared_network_dereference (&pool -> shared_network, file, line);
1600 
1601  POOL_DESTROYP(&pool->active);
1602  POOL_DESTROYP(&pool->expired);
1603  POOL_DESTROYP(&pool->free);
1604  POOL_DESTROYP(&pool->backup);
1605  POOL_DESTROYP(&pool->abandoned);
1606  POOL_DESTROYP(&pool->reserved);
1607 
1608 #if defined (FAILOVER_PROTOCOL)
1609  if (pool -> failover_peer)
1610  dhcp_failover_state_dereference (&pool -> failover_peer,
1611  file, line);
1612 #endif
1613  for (pc = pool -> permit_list; pc; pc = pn) {
1614  pn = pc -> next;
1615  free_permit (pc, file, line);
1616  }
1617  pool -> permit_list = (struct permit *)0;
1618 
1619  for (pc = pool -> prohibit_list; pc; pc = pn) {
1620  pn = pc -> next;
1621  free_permit (pc, file, line);
1622  }
1623  pool -> prohibit_list = (struct permit *)0;
1624 #endif
1625 
1626  return ISC_R_SUCCESS;
1627 }
1628 
1630  const char *name, va_list ap)
1631 {
1632  /* h should point to (struct pool *) */
1633  isc_result_t status;
1634 
1635  if (h -> type != dhcp_type_pool)
1636  return DHCP_R_INVALIDARG;
1637 
1638  /* Can't write pools yet. */
1639 
1640  /* Try to find some inner object that can take the value. */
1641  if (h -> inner && h -> inner -> type -> signal_handler) {
1642  status = ((*(h -> inner -> type -> signal_handler))
1643  (h -> inner, name, ap));
1644  if (status == ISC_R_SUCCESS)
1645  return status;
1646  }
1647 
1648  return ISC_R_NOTFOUND;
1649 }
1650 
1652  omapi_object_t *id,
1653  omapi_object_t *h)
1654 {
1655  struct pool *pool;
1656  isc_result_t status;
1657 
1658  if (h->type != dhcp_type_pool)
1659  return (DHCP_R_INVALIDARG);
1660  pool = (struct pool *)h;
1661 
1662  /*
1663  * I don't think we can actually find a pool yet
1664  * but include the output of interesting values
1665  * for when we do
1666  */
1667  status = omapi_connection_put_named_uint32(c, "lease-count",
1668  ((u_int32_t)
1669  pool->lease_count));
1670  if (status != ISC_R_SUCCESS)
1671  return (status);
1672 
1673  status = omapi_connection_put_named_uint32(c, "free-leases",
1674  ((u_int32_t)
1675  pool->free_leases));
1676  if (status != ISC_R_SUCCESS)
1677  return (status);
1678 
1679  status = omapi_connection_put_named_uint32(c, "backup-leases",
1680  ((u_int32_t)
1681  pool->backup_leases));
1682  if (status != ISC_R_SUCCESS)
1683  return (status);
1684  /* we could add time stamps but lets wait on those */
1685 
1686  /* Write out the inner object, if any. */
1687  if (h->inner && h->inner->type->stuff_values) {
1688  status = ((*(h->inner->type->stuff_values))
1689  (c, id, h->inner));
1690  if (status == ISC_R_SUCCESS)
1691  return (status);
1692  }
1693 
1694  return (ISC_R_SUCCESS);
1695 }
1696 
1698  omapi_object_t *id, omapi_object_t *ref)
1699 {
1700  /* Can't look up pools yet. */
1701 
1702  /* If we get to here without finding a pool, no valid key was
1703  specified. */
1704  if (!*lp)
1705  return DHCP_R_NOKEYS;
1706  return ISC_R_SUCCESS;
1707 }
1708 
1710  omapi_object_t *id)
1711 {
1712  return ISC_R_NOTIMPLEMENTED;
1713 }
1714 
1716  omapi_object_t *id)
1717 {
1718  return ISC_R_NOTIMPLEMENTED;
1719 }
1720 
1721 static isc_result_t
1722 class_set_value (omapi_object_t *h,
1723  omapi_object_t *id,
1724  omapi_data_string_t *name,
1725  omapi_typed_data_t *value)
1726 {
1727  struct class *class;
1728  struct class *superclass = 0;
1729  isc_result_t status;
1730  int issubclass = (h -> type == dhcp_type_subclass);
1731 
1732  class = (struct class *)h;
1733 
1734  if (!omapi_ds_strcmp(name, "name")) {
1735  if (class->name)
1736  return ISC_R_EXISTS;
1737 
1738  if (issubclass) {
1739  char tname[value->u.buffer.len + 1];
1740  memcpy(tname, value->u.buffer.value, value->u.buffer.len);
1741  tname[sizeof(tname)-1] = '\0';
1742  status = find_class(&superclass, tname, MDL);
1743 
1744  if (status == ISC_R_NOTFOUND)
1745  return status;
1746 
1747  if (class->superclass != NULL)
1748  class_dereference(&class->superclass, MDL);
1749  class_reference(&class->superclass, superclass, MDL);
1750 
1751  if (class->group != NULL)
1752  group_dereference(&class->group, MDL);
1753  group_reference(&class->group, superclass->group, MDL);
1754 
1755  class->lease_limit = superclass->lease_limit;
1756  if (class->lease_limit != 0) {
1757  class->billed_leases =
1758  dmalloc(class->lease_limit *
1759  sizeof(struct lease *),
1760  MDL);
1761  if (class->billed_leases == NULL) {
1762  return ISC_R_NOMEMORY;
1763  }
1764  }
1765 
1766  } else if (value->type == omapi_datatype_data ||
1767  value->type == omapi_datatype_string) {
1768  class->name = dmalloc(value->u.buffer.len + 1, MDL);
1769  if (!class->name)
1770  return ISC_R_NOMEMORY;
1771 
1772  /* class->name is null-terminated from dmalloc() */
1773  memcpy(class->name, value->u.buffer.value,
1774  value->u.buffer.len);
1775  } else
1776  return DHCP_R_INVALIDARG;
1777 
1778  return ISC_R_SUCCESS;
1779  }
1780 
1781 
1782  if (issubclass && !omapi_ds_strcmp(name, "hashstring")) {
1783  if (class->hash_string.data)
1784  return ISC_R_EXISTS;
1785 
1786  if (value->type == omapi_datatype_data ||
1787  value->type == omapi_datatype_string) {
1788  if (!buffer_allocate(&class->hash_string.buffer,
1789  value->u.buffer.len, MDL))
1790  return ISC_R_NOMEMORY;
1791  class->hash_string.data =
1792  class->hash_string.buffer->data;
1793  memcpy(class->hash_string.buffer->data,
1794  value->u.buffer.value, value->u.buffer.len);
1795  class->hash_string.len = value->u.buffer.len;
1796  } else
1797  return DHCP_R_INVALIDARG;
1798 
1799  return ISC_R_SUCCESS;
1800  }
1801 
1802  if (!omapi_ds_strcmp(name, "group")) {
1803  if (value->type == omapi_datatype_data ||
1804  value->type == omapi_datatype_string) {
1805  struct group_object *group = NULL;
1806 
1807  group_hash_lookup(&group, group_name_hash,
1808  (char *)value->u.buffer.value,
1809  value->u.buffer.len, MDL);
1810  if (!group || (group->flags & GROUP_OBJECT_DELETED))
1811  return ISC_R_NOTFOUND;
1812  if (class->group)
1813  group_dereference(&class->group, MDL);
1814  group_reference(&class->group, group->group, MDL);
1815  group_object_dereference(&group, MDL);
1816  } else
1817  return DHCP_R_INVALIDARG;
1818 
1819  return ISC_R_SUCCESS;
1820  }
1821 
1822 
1823  /* note we do not support full expressions via omapi because the
1824  expressions parser needs to be re-done to support parsing from
1825  strings and not just files. */
1826 
1827  if (!omapi_ds_strcmp(name, "match")) {
1828  if (value->type == omapi_datatype_data ||
1829  value->type == omapi_datatype_string) {
1830  unsigned minlen = (value->u.buffer.len > 8 ?
1831  8 : value->u.buffer.len);
1832 
1833  if (!strncmp("hardware",
1834  (char *)value->u.buffer.value, minlen))
1835  {
1836  if (!expression_allocate(&class->submatch, MDL))
1837  return ISC_R_NOMEMORY;
1838 
1839  class->submatch->op = expr_hardware;
1840  } else
1841  return DHCP_R_INVALIDARG;
1842  } else
1843  return DHCP_R_INVALIDARG;
1844 
1845  return ISC_R_SUCCESS;
1846  }
1847 
1848 
1849  if (!omapi_ds_strcmp(name, "option")) {
1850  if (value->type == omapi_datatype_data ||
1851  value->type == omapi_datatype_string) {
1852  /* XXXJAB support 'options' here. */
1853  /* XXXJAB specifically 'bootfile-name' */
1854  return DHCP_R_INVALIDARG; /* XXX tmp */
1855  } else
1856  return DHCP_R_INVALIDARG;
1857 
1858  /*
1859  * Currently no way to get here, if we update the above
1860  * code so that we do get here this return needs to be
1861  * uncommented.
1862  * return ISC_R_SUCCESS;
1863  */
1864  }
1865 
1866 
1867  /* Try to find some inner object that can take the value. */
1868  if (h->inner && h->inner->type->set_value) {
1869  status = ((*(h->inner->type->set_value))
1870  (h->inner, id, name, value));
1871  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1872  return status;
1873  }
1874 
1875  return DHCP_R_UNKNOWNATTRIBUTE;
1876 }
1877 
1878 
1879 
1881  omapi_object_t *id,
1882  omapi_data_string_t *name,
1883  omapi_typed_data_t *value)
1884 {
1885  if (h -> type != dhcp_type_class)
1886  return DHCP_R_INVALIDARG;
1887 
1888  return class_set_value(h, id, name, value);
1889 }
1890 
1892  omapi_data_string_t *name,
1893  omapi_value_t **value)
1894 {
1895  struct class *class;
1896  isc_result_t status;
1897 
1898  if (h -> type != dhcp_type_class)
1899  return DHCP_R_INVALIDARG;
1900  class = (struct class *)h;
1901 
1902  if (!omapi_ds_strcmp (name, "name"))
1903  return omapi_make_string_value (value, name, class -> name,
1904  MDL);
1905 
1906  /* Try to find some inner object that can provide the value. */
1907  if (h -> inner && h -> inner -> type -> get_value) {
1908  status = ((*(h -> inner -> type -> get_value))
1909  (h -> inner, id, name, value));
1910  if (status == ISC_R_SUCCESS)
1911  return status;
1912  }
1913  return DHCP_R_UNKNOWNATTRIBUTE;
1914 }
1915 
1916 isc_result_t dhcp_class_destroy (omapi_object_t *h, const char *file, int line)
1917 {
1918 
1919  if (h -> type != dhcp_type_class && h -> type != dhcp_type_subclass)
1920  return DHCP_R_INVALIDARG;
1921  struct class *class = (struct class *)h;
1922 
1923  if (class -> nic)
1924  class_dereference (&class -> nic, file, line);
1925  if (class -> superclass)
1926  class_dereference (&class -> superclass, file, line);
1927  if (class -> name) {
1928  dfree (class -> name, file, line);
1929  class -> name = (char *)0;
1930  }
1931  if (class -> billed_leases) {
1932  int i;
1933  for (i = 0; i < class -> lease_limit; i++) {
1934  if (class -> billed_leases [i]) {
1935  lease_dereference (&class -> billed_leases [i],
1936  file, line);
1937  }
1938  }
1939  dfree (class -> billed_leases, file, line);
1940  class -> billed_leases = (struct lease **)0;
1941  }
1942  if (class -> hash) {
1943  class_free_hash_table (&class -> hash, file, line);
1944  class -> hash = (class_hash_t *)0;
1945  }
1946  data_string_forget (&class -> hash_string, file, line);
1947 
1948  if (class -> expr)
1949  expression_dereference (&class -> expr, file, line);
1950  if (class -> submatch)
1951  expression_dereference (&class -> submatch, file, line);
1952  if (class -> group)
1953  group_dereference (&class -> group, file, line);
1954  if (class -> statements)
1955  executable_statement_dereference (&class -> statements,
1956  file, line);
1957  if (class -> superclass)
1958  class_dereference (&class -> superclass, file, line);
1959 
1960  return ISC_R_SUCCESS;
1961 }
1962 
1963 static isc_result_t
1964 class_signal_handler(omapi_object_t *h,
1965  const char *name, va_list ap)
1966 {
1967  struct class *class = (struct class *)h;
1968  isc_result_t status;
1969  int updatep = 0;
1970  int issubclass;
1971 
1972  issubclass = (h->type == dhcp_type_subclass);
1973 
1974  if (!strcmp (name, "updated")) {
1975 
1976  if (!issubclass) {
1977  if (class->name == 0 || strlen(class->name) == 0) {
1978  return DHCP_R_INVALIDARG;
1979  }
1980  } else {
1981  if (class->superclass == 0) {
1982  return DHCP_R_INVALIDARG; /* didn't give name */
1983  }
1984 
1985  if (class->hash_string.data == NULL) {
1986  return DHCP_R_INVALIDARG;
1987  }
1988  }
1989 
1990 
1991  if (issubclass) {
1992  if (!class->superclass->hash)
1993  class_new_hash(&class->superclass->hash,
1995 
1996  class_hash_add(class->superclass->hash,
1997  (const char *)class->hash_string.data,
1998  class->hash_string.len,
1999  (void *)class, MDL);
2000  }
2001 
2002 #ifdef DEBUG_OMAPI
2003  if (issubclass) {
2004  log_debug ("OMAPI added subclass %s",
2005  class->superclass->name);
2006  } else {
2007  log_debug ("OMAPI added class %s", class->name);
2008  }
2009 #endif
2010 
2011  status = enter_class (class, 1, 1);
2012  if (status != ISC_R_SUCCESS)
2013  return status;
2014  updatep = 1;
2015  }
2016 
2017  /* Try to find some inner object that can take the value. */
2018  if (h->inner && h->inner->type->signal_handler) {
2019  status = ((*(h->inner->type->signal_handler))
2020  (h->inner, name, ap));
2021  if (status == ISC_R_SUCCESS)
2022  return status;
2023  }
2024 
2025  if (updatep)
2026  return ISC_R_SUCCESS;
2027 
2028  return ISC_R_NOTFOUND;
2029 }
2030 
2031 
2033  const char *name, va_list ap)
2034 {
2035  if (h -> type != dhcp_type_class)
2036  return DHCP_R_INVALIDARG;
2037 
2038  return class_signal_handler(h, name, ap);
2039 }
2040 
2041 
2042 /*
2043  * Routine to put out generic class & subclass information
2044  */
2046  omapi_object_t *id,
2047  omapi_object_t *h)
2048 {
2049  struct class *class;
2050  isc_result_t status;
2051 
2052  class = (struct class *)h;
2053 
2054  status = omapi_connection_put_named_uint32(c, "lease-limit",
2055  ((u_int32_t)
2056  class->lease_limit));
2057  if (status != ISC_R_SUCCESS)
2058  return (status);
2059 
2060  status = omapi_connection_put_named_uint32(c, "leases-used",
2061  ((u_int32_t)
2062  class->leases_consumed));
2063  if (status != ISC_R_SUCCESS)
2064  return (status);
2065 
2066  /* Write out the inner object, if any. */
2067  if (h->inner && h->inner->type->stuff_values) {
2068  status = ((*(h->inner->type->stuff_values))
2069  (c, id, h->inner));
2070  if (status == ISC_R_SUCCESS)
2071  return (status);
2072  }
2073 
2074  return (ISC_R_SUCCESS);
2075 }
2076 
2077 
2079  omapi_object_t *id,
2080  omapi_object_t *h)
2081 {
2082  if (h->type != dhcp_type_class)
2083  return (DHCP_R_INVALIDARG);
2084 
2085  /* add any class specific items here */
2086 
2087  return (class_stuff_values(c, id, h));
2088 }
2089 
2090 static isc_result_t class_lookup (omapi_object_t **lp,
2091  omapi_object_t *id, omapi_object_t *ref,
2092  omapi_object_type_t *typewanted)
2093 {
2094  omapi_value_t *nv = NULL;
2095  omapi_value_t *hv = NULL;
2096  isc_result_t status;
2097  struct class *class = 0;
2098  struct class *subclass = 0;
2099 
2100  *lp = NULL;
2101 
2102  if (ref == NULL)
2103  return (DHCP_R_NOKEYS);
2104 
2105  /* see if we have a name */
2106  status = omapi_get_value_str(ref, id, "name", &nv);
2107  if (status == ISC_R_SUCCESS) {
2108  char *name = dmalloc(nv->value->u.buffer.len + 1, MDL);
2109  memcpy (name,
2110  nv->value->u.buffer.value,
2111  nv->value->u.buffer.len);
2112 
2114 
2115  find_class(&class, name, MDL);
2116 
2117  dfree(name, MDL);
2118 
2119  if (class == NULL) {
2120  return (ISC_R_NOTFOUND);
2121  }
2122 
2123  if (typewanted == dhcp_type_subclass) {
2124  status = omapi_get_value_str(ref, id,
2125  "hashstring", &hv);
2126  if (status != ISC_R_SUCCESS) {
2127  class_dereference(&class, MDL);
2128  return (DHCP_R_NOKEYS);
2129  }
2130 
2131  if (hv->value->type != omapi_datatype_data &&
2132  hv->value->type != omapi_datatype_string) {
2133  class_dereference(&class, MDL);
2135  return (DHCP_R_NOKEYS);
2136  }
2137 
2138  class_hash_lookup(&subclass, class->hash,
2139  (const char *)
2140  hv->value->u.buffer.value,
2141  hv->value->u.buffer.len, MDL);
2142 
2144 
2145  class_dereference(&class, MDL);
2146 
2147  if (subclass == NULL) {
2148  return (ISC_R_NOTFOUND);
2149  }
2150 
2151  class_reference(&class, subclass, MDL);
2152  class_dereference(&subclass, MDL);
2153  }
2154 
2155  /* Don't return the object if the type is wrong. */
2156  if (class->type != typewanted) {
2157  class_dereference(&class, MDL);
2158  return (DHCP_R_INVALIDARG);
2159  }
2160 
2161  if (class->flags & CLASS_DECL_DELETED) {
2162  class_dereference(&class, MDL);
2163  return (ISC_R_NOTFOUND);
2164  }
2165 
2166  omapi_object_reference(lp, (omapi_object_t *)class, MDL);
2167  class_dereference(&class, MDL);
2168 
2169  return (ISC_R_SUCCESS);
2170  }
2171 
2172  return (DHCP_R_NOKEYS);
2173 }
2174 
2175 
2177  omapi_object_t *id, omapi_object_t *ref)
2178 {
2179  return class_lookup(lp, id, ref, dhcp_type_class);
2180 }
2181 
2183  omapi_object_t *id)
2184 {
2185  struct class *cp = 0;
2186  isc_result_t status;
2187 
2188  status = class_allocate(&cp, MDL);
2189  if (status != ISC_R_SUCCESS)
2190  return (status);
2191 
2192  if (clone_group(&cp->group, root_group, MDL) == 0)
2193  return (ISC_R_NOMEMORY);
2194 
2195  cp->flags = CLASS_DECL_DYNAMIC;
2196  status = omapi_object_reference(lp, (omapi_object_t *)cp, MDL);
2197  class_dereference(&cp, MDL);
2198  return (status);
2199 }
2200 
2202  omapi_object_t *id)
2203 {
2204  struct class *cp;
2205  if (lp -> type != dhcp_type_class)
2206  return DHCP_R_INVALIDARG;
2207  cp = (struct class *)lp;
2208 
2209 #ifdef DEBUG_OMAPI
2210  log_debug ("OMAPI delete class %s", cp -> name);
2211 #endif
2212 
2213  delete_class (cp, 1);
2214  return ISC_R_SUCCESS;
2215 }
2216 
2218  omapi_object_t *id,
2219  omapi_data_string_t *name,
2220  omapi_typed_data_t *value)
2221 {
2222  if (h -> type != dhcp_type_subclass)
2223  return DHCP_R_INVALIDARG;
2224 
2225  return class_set_value(h, id, name, value);
2226 }
2227 
2228 
2230  omapi_data_string_t *name,
2231  omapi_value_t **value)
2232 {
2233  struct class *subclass;
2234  isc_result_t status;
2235 
2236  if (h -> type != dhcp_type_class)
2237  return DHCP_R_INVALIDARG;
2238  subclass = (struct class *)h;
2239  if (subclass -> name != 0)
2240  return DHCP_R_INVALIDARG;
2241 
2242  /* XXXJAB No values to get yet. */
2243 
2244  /* Try to find some inner object that can provide the value. */
2245  if (h -> inner && h -> inner -> type -> get_value) {
2246  status = ((*(h -> inner -> type -> get_value))
2247  (h -> inner, id, name, value));
2248  if (status == ISC_R_SUCCESS)
2249  return status;
2250  }
2251  return DHCP_R_UNKNOWNATTRIBUTE;
2252 }
2253 
2255  const char *name, va_list ap)
2256 {
2257  if (h -> type != dhcp_type_subclass)
2258  return DHCP_R_INVALIDARG;
2259 
2260  return class_signal_handler(h, name, ap);
2261 }
2262 
2263 
2265  omapi_object_t *id,
2266  omapi_object_t *h)
2267 {
2268  struct class *subclass;
2269 
2270  if (h->type != dhcp_type_subclass)
2271  return (DHCP_R_INVALIDARG);
2272  subclass = (struct class *)h;
2273  if (subclass->name != 0)
2274  return (DHCP_R_INVALIDARG);
2275 
2276  /* add any subclass specific items here */
2277 
2278  return (class_stuff_values(c, id, h));
2279 }
2280 
2282  omapi_object_t *id, omapi_object_t *ref)
2283 {
2284  return class_lookup(lp, id, ref, dhcp_type_subclass);
2285 }
2286 
2287 
2288 
2289 
2291  omapi_object_t *id)
2292 {
2293  struct class *cp = 0;
2294  isc_result_t status;
2295 
2296  status = subclass_allocate(&cp, MDL);
2297  if (status != ISC_R_SUCCESS)
2298  return status;
2300 
2301  cp->flags = CLASS_DECL_DYNAMIC;
2302 
2303  status = omapi_object_reference (lp, (omapi_object_t *)cp, MDL);
2304  subclass_dereference (&cp, MDL);
2305  return status;
2306 }
2307 
2309  omapi_object_t *id)
2310 {
2311  struct class *cp;
2312  if (lp -> type != dhcp_type_subclass)
2313  return DHCP_R_INVALIDARG;
2314  cp = (struct class *)lp;
2315 
2316 #ifdef DEBUG_OMAPI
2317  log_debug ("OMAPI delete subclass %s", cp -> name);
2318 #endif
2319 
2320  delete_class (cp, 1);
2321 
2322  return ISC_R_SUCCESS;
2323 }
2324 
2325 isc_result_t binding_scope_set_value (struct binding_scope *scope, int createp,
2326  omapi_data_string_t *name,
2327  omapi_typed_data_t *value)
2328 {
2329  struct binding *bp;
2330  char *nname;
2331  struct binding_value *nv;
2332  nname = dmalloc (name -> len + 1, MDL);
2333  if (!nname)
2334  return ISC_R_NOMEMORY;
2335  memcpy (nname, name -> value, name -> len);
2336  nname [name -> len] = 0;
2337  bp = find_binding (scope, nname);
2338  if (!bp && !createp) {
2339  dfree (nname, MDL);
2340  return DHCP_R_UNKNOWNATTRIBUTE;
2341  }
2342  if (!value) {
2343  dfree (nname, MDL);
2344  if (!bp)
2345  return DHCP_R_UNKNOWNATTRIBUTE;
2346  binding_value_dereference (&bp -> value, MDL);
2347  return ISC_R_SUCCESS;
2348  }
2349 
2350  nv = (struct binding_value *)0;
2351  if (!binding_value_allocate (&nv, MDL)) {
2352  dfree (nname, MDL);
2353  return ISC_R_NOMEMORY;
2354  }
2355  switch (value -> type) {
2356  case omapi_datatype_int:
2357  nv -> type = binding_numeric;
2358  nv -> value.intval = value -> u.integer;
2359  break;
2360 
2361  case omapi_datatype_string:
2362  case omapi_datatype_data:
2363  if (!buffer_allocate (&nv -> value.data.buffer,
2364  value -> u.buffer.len, MDL)) {
2366  dfree (nname, MDL);
2367  return ISC_R_NOMEMORY;
2368  }
2369  memcpy (&nv -> value.data.buffer -> data [1],
2370  value -> u.buffer.value, value -> u.buffer.len);
2371  nv -> value.data.len = value -> u.buffer.len;
2372  break;
2373 
2374  case omapi_datatype_object:
2376  dfree (nname, MDL);
2377  return DHCP_R_INVALIDARG;
2378  }
2379 
2380  if (!bp) {
2381  bp = dmalloc (sizeof *bp, MDL);
2382  if (!bp) {
2384  dfree (nname, MDL);
2385  return ISC_R_NOMEMORY;
2386  }
2387  memset (bp, 0, sizeof *bp);
2388  bp -> name = nname;
2389  bp -> next = scope -> bindings;
2390  scope -> bindings = bp;
2391  } else {
2392  if (bp -> value)
2393  binding_value_dereference (&bp -> value, MDL);
2394  dfree (nname, MDL);
2395  }
2396  binding_value_reference (&bp -> value, nv, MDL);
2398  return ISC_R_SUCCESS;
2399 }
2400 
2402  struct binding_scope *scope,
2403  omapi_data_string_t *name)
2404 {
2405  struct binding *bp;
2406  omapi_typed_data_t *td;
2407  isc_result_t status;
2408  char *nname;
2409  nname = dmalloc (name -> len + 1, MDL);
2410  if (!nname)
2411  return ISC_R_NOMEMORY;
2412  memcpy (nname, name -> value, name -> len);
2413  nname [name -> len] = 0;
2414  bp = find_binding (scope, nname);
2415  dfree (nname, MDL);
2416  if (!bp)
2417  return DHCP_R_UNKNOWNATTRIBUTE;
2418  if (!bp -> value)
2419  return DHCP_R_UNKNOWNATTRIBUTE;
2420 
2421  switch (bp -> value -> type) {
2422  case binding_boolean:
2423  td = (omapi_typed_data_t *)0;
2425  bp -> value -> value.boolean);
2426  break;
2427 
2428  case binding_numeric:
2429  td = (omapi_typed_data_t *)0;
2431  (int)
2432  bp -> value -> value.intval);
2433  break;
2434 
2435  case binding_data:
2436  td = (omapi_typed_data_t *)0;
2438  bp -> value -> value.data.len);
2439  if (status != ISC_R_SUCCESS)
2440  return status;
2441  memcpy (&td -> u.buffer.value [0],
2442  bp -> value -> value.data.data,
2443  bp -> value -> value.data.len);
2444  break;
2445 
2446  /* Can't return values for these two (yet?). */
2447  case binding_dns:
2448  case binding_function:
2449  return DHCP_R_INVALIDARG;
2450 
2451  default:
2452  log_fatal ("Impossible case at %s:%d.", MDL);
2453  return ISC_R_FAILURE;
2454  }
2455 
2456  if (status != ISC_R_SUCCESS)
2457  return status;
2458  status = omapi_value_new (value, MDL);
2459  if (status != ISC_R_SUCCESS) {
2461  return status;
2462  }
2463 
2464  omapi_data_string_reference (&(*value) -> name, name, MDL);
2465  omapi_typed_data_reference (&(*value) -> value, td, MDL);
2467 
2468  return ISC_R_SUCCESS;
2469 }
2470 
2472  struct binding_scope *scope)
2473 {
2474  struct binding *bp;
2475  unsigned len;
2476  isc_result_t status;
2477 
2478  for (bp = scope -> bindings; bp; bp = bp -> next) {
2479  if (bp -> value) {
2480  if (bp -> value -> type == binding_dns ||
2481  bp -> value -> type == binding_function)
2482  continue;
2483 
2484  /* Stuff the name. */
2485  len = strlen (bp -> name);
2486  status = omapi_connection_put_uint16 (c, len);
2487  if (status != ISC_R_SUCCESS)
2488  return status;
2489  status = omapi_connection_copyin (c,
2490  (unsigned char *)bp -> name,
2491  len);
2492  if (status != ISC_R_SUCCESS)
2493  return status;
2494 
2495  switch (bp -> value -> type) {
2496  case binding_boolean:
2497  status = omapi_connection_put_uint32 (c,
2498  sizeof (u_int32_t));
2499  if (status != ISC_R_SUCCESS)
2500  return status;
2501  status = (omapi_connection_put_uint32
2502  (c,
2503  ((u_int32_t)(bp -> value -> value.boolean))));
2504  if (status != ISC_R_SUCCESS)
2505  return status;
2506  break;
2507 
2508  case binding_data:
2509  status = (omapi_connection_put_uint32
2510  (c, bp -> value -> value.data.len));
2511  if (status != ISC_R_SUCCESS)
2512  return status;
2513  if (bp -> value -> value.data.len) {
2514  status = (omapi_connection_copyin
2515  (c, bp -> value -> value.data.data,
2516  bp -> value -> value.data.len));
2517  if (status != ISC_R_SUCCESS)
2518  return status;
2519  }
2520  break;
2521 
2522  case binding_numeric:
2523  status = (omapi_connection_put_uint32
2524  (c, sizeof (u_int32_t)));
2525  if (status != ISC_R_SUCCESS)
2526  return status;
2527  status = (omapi_connection_put_uint32
2528  (c, ((u_int32_t)
2529  (bp -> value -> value.intval))));
2530  if (status != ISC_R_SUCCESS)
2531  return status;
2532  break;
2533 
2534 
2535  /* NOTREACHED */
2536  case binding_dns:
2537  case binding_function:
2538  break;
2539  }
2540  }
2541  }
2542  return ISC_R_SUCCESS;
2543 }
2544 
2545 /* 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:1122
#define FTS_LAST
Definition: dhcpd.h:537
LEASE_STRUCT reserved
Definition: dhcpd.h:997
isc_result_t dhcp_subclass_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:2290
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:3676
isc_result_t dhcp_failover_link_get_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_value_t **)
LEASE_STRUCT expired
Definition: dhcpd.h:993
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:573
isc_result_t dhcp_lease_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:851
isc_result_t dhcp_class_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:2201
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:550
unsigned len
Definition: tree.h:80
isc_result_t dhcp_class_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:2182
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:623
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:1503
const char * piaddr(const struct iaddr addr)
Definition: inet.c:581
u_int8_t hlen
Definition: dhcpd.h:483
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:478
unsigned char * uid
Definition: dhcpd.h:575
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:42
isc_result_t dhcp_host_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:1155
isc_result_t dhcp_pool_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:1715
void * dmalloc(unsigned, const char *, int)
Definition: alloc.c:56
struct lease_state * state
Definition: dhcpd.h:618
struct class * superclass
Definition: dhcpd.h:1061
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:1031
isc_result_t dhcp_subclass_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:2308
isc_result_t dhcp_class_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:1916
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:949
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:1074
omapi_typed_data_t * value
Definition: omapip.h:91
#define CLASS_DECL_DELETED
Definition: dhcpd.h:1090
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:2264
isc_result_t dhcp_host_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:1296
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:2217
struct lease * next_pending
Definition: dhcpd.h:632
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:546
void lease_ping_timeout(void *)
Definition: dhcpd.c:1247
isc_result_t dhcp_failover_listener_stuff(omapi_object_t *, omapi_object_t *, omapi_object_t *)
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:1559
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:1651
omapi_object_type_t * dhcp_type_failover_state
void hw_hash_delete(struct lease *)
Definition: mdb.c:2283
isc_result_t dhcp_pool_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:1629
struct option_cache * fixed_addr
Definition: dhcpd.h:942
struct class * billing_class
Definition: dhcpd.h:569
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:685
#define HOST_DECL_DELETED
Definition: dhcpd.h:948
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:2032
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:946
unsigned len
Definition: inet.h:32
dhcp_failover_state_t * failover_peer
Definition: dhcpd.h:1007
isc_result_t dhcp_subclass_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: omapi.c:2254
isc_result_t omapi_value_new(omapi_value_t **, const char *, int)
Definition: alloc.c:1012
struct data_string client_identifier
Definition: dhcpd.h:936
#define DHCP_R_KEYCONFLICT
Definition: result.h:52
isc_result_t enter_class(struct class *, int, int)
Definition: mdb.c:73
Definition: dhcpd.h:288
char * name
Definition: dhcpd.h:1062
LEASE_STRUCT free
Definition: dhcpd.h:994
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
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:1880
#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:1091
void free_lease_state(struct lease_state *, const char *, int)
Definition: salloc.c:196
struct hardware hardware_addr
Definition: dhcpd.h:579
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:2401
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:863
isc_result_t dhcp_subclass_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:2281
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
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:985
binding_state_t binding_state
Definition: dhcpd.h:613
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:1891
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:1824
isc_result_t class_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2045
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:207
Definition: dhcpd.h:405
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
Definition: alloc.c:579
struct pool * pool
Definition: dhcpd.h:568
char * name
Definition: dhcpd.h:934
host_hash_t * host_hw_addr_hash
Definition: mdb.c:35
dhcp_failover_listener_t
Definition: dhcpd.h:3645
TIME atsfp
Definition: dhcpd.h:629
isc_result_t dhcp_pool_create(omapi_object_t **lp, omapi_object_t *id)
Definition: omapi.c:1709
#define cur_time
Definition: dhcpd.h:2041
struct lease * n_hw
Definition: dhcpd.h:557
int free_leases
Definition: dhcpd.h:1000
isc_result_t dhcp_failover_link_signal(omapi_object_t *, const char *, va_list)
struct lease * n_uid
Definition: dhcpd.h:557
TIME starts
Definition: dhcpd.h:560
isc_result_t omapi_get_int_value(unsigned long *, omapi_typed_data_t *)
Definition: support.c:836
u_int8_t flags
Definition: dhcpd.h:581
void dfree(void *, const char *, int)
Definition: alloc.c:131
union omapi_typed_data_t::@3 u
struct permit * next
Definition: dhcpd.h:958
int lease_count
Definition: dhcpd.h:999
struct host_decl * n_ipaddr
Definition: dhcpd.h:932
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:2153
int lease_limit
Definition: dhcpd.h:1065
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:567
#define GROUP_OBJECT_DELETED
Definition: dhcpd.h:912
isc_result_t dhcp_lease_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:857
isc_result_t dhcp_pool_destroy(omapi_object_t *h, const char *file, int line)
Definition: omapi.c:1581
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:910
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:630
Definition: dhcpd.h:957
isc_result_t binding_scope_stuff_values(omapi_object_t *c, struct binding_scope *scope)
Definition: omapi.c:2471
isc_result_t omapi_value_dereference(omapi_value_t **, const char *, int)
Definition: alloc.c:1046
unsigned short uid_len
Definition: dhcpd.h:576
struct iaddr ip_addr
Definition: dhcpd.h:559
#define DHCP_R_NOKEYS
Definition: result.h:54
#define EPHEMERAL_FLAGS
Definition: dhcpd.h:595
struct group_object * named_group
Definition: dhcpd.h:945
Definition: dhcpd.h:918
#define DHCP_R_UNCHANGED
Definition: result.h:50
TIME tstp
Definition: dhcpd.h:627
isc_result_t dhcp_class_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:2078
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:566
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:1264
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:1819
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:1534
TIME tsfp
Definition: dhcpd.h:628
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:1058
int flags
Definition: dhcpd.h:911
isc_result_t dhcp_lease_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:500
group_hash_t * group_name_hash
Definition: memory.c:32
int flags
Definition: dhcpd.h:1095
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
Definition: dhcpd.h:484
Definition: tree.h:118
isc_result_t dhcp_lease_free(omapi_object_t *, const char *, int)
#define POOL_DESTROYP(LQ)
Definition: dhcpd.h:266
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:2229
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:947
isc_result_t dhcp_class_lookup(omapi_object_t **lp, omapi_object_t *id, omapi_object_t *ref)
Definition: omapi.c:2176
unsigned char uid_buf[7]
Definition: dhcpd.h:578
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:544
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:1127
const char * file
Definition: dhcpd.h:3676
struct permit * permit_list
Definition: dhcpd.h:990
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
Definition: buffer.c:670
LEASE_STRUCT active
Definition: dhcpd.h:992
isc_result_t dhcp_host_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: omapi.c:1203
int parse_executable_statements(struct executable_statement **statements, struct parse *cfile, int *lose, enum expression_context case_context)
Definition: parse.c:2113
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:2325
struct executable_statement * on_commit
Definition: dhcpd.h:545
Definition: dhcpd.h:1058
const unsigned char * data
Definition: tree.h:79
TIME ends
Definition: dhcpd.h:560
struct binding_scope * scope
Definition: dhcpd.h:565
struct hardware interface
Definition: dhcpd.h:935
isc_result_t dhcp_failover_state_lookup(omapi_object_t **, omapi_object_t *, omapi_object_t *)
LEASE_STRUCT backup
Definition: dhcpd.h:995
struct host_decl * n_dynamic
Definition: dhcpd.h:933
struct group * group
Definition: dhcpd.h:909
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:614
isc_result_t dhcp_failover_link_set_value(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_typed_data_t *)
LEASE_STRUCT abandoned
Definition: dhcpd.h:996
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:1697
struct pool * next
Definition: dhcpd.h:987
isc_result_t dhcp_host_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: omapi.c:1519
char * client_hostname
Definition: dhcpd.h:564
struct group * group
Definition: dhcpd.h:1085
struct option_chain_head * agent_options
Definition: dhcpd.h:570
int backup_leases
Definition: dhcpd.h:1001