diff options
Diffstat (limited to 'includes/omapip')
-rw-r--r-- | includes/omapip/alloc.h | 105 | ||||
-rw-r--r-- | includes/omapip/buffer.h | 77 | ||||
-rw-r--r-- | includes/omapip/convert.h | 46 | ||||
-rw-r--r-- | includes/omapip/hash.h | 161 | ||||
-rw-r--r-- | includes/omapip/isclib.h | 130 | ||||
-rw-r--r-- | includes/omapip/omapip.h | 616 | ||||
-rw-r--r-- | includes/omapip/omapip_p.h | 299 | ||||
-rw-r--r-- | includes/omapip/result.h | 121 | ||||
-rw-r--r-- | includes/omapip/trace.h | 111 |
9 files changed, 1666 insertions, 0 deletions
diff --git a/includes/omapip/alloc.h b/includes/omapip/alloc.h new file mode 100644 index 0000000..407f590 --- /dev/null +++ b/includes/omapip/alloc.h @@ -0,0 +1,105 @@ +/* alloc.h + + Definitions for the object management API protocol memory allocation... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +isc_result_t omapi_buffer_new (omapi_buffer_t **, const char *, int); +isc_result_t omapi_buffer_reference (omapi_buffer_t **, + omapi_buffer_t *, const char *, int); +isc_result_t omapi_buffer_dereference (omapi_buffer_t **, const char *, int); + +#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +#define DMDOFFSET (sizeof (struct dmalloc_preamble)) +#define DMLFSIZE 16 +#define DMUFSIZE 16 +#define DMDSIZE (DMDOFFSET + DMLFSIZE + DMUFSIZE) + +struct dmalloc_preamble { + struct dmalloc_preamble *prev, *next; + const char *file; + int line; + size_t size; + unsigned long generation; + unsigned char low_fence [DMLFSIZE]; +}; +#else +#define DMDOFFSET 0 +#define DMDSIZE 0 +#endif + +/* rc_history flags... */ +#define RC_LEASE 1 +#define RC_MISC 2 + +#if defined (DEBUG_RC_HISTORY) +#if !defined (RC_HISTORY_MAX) +# define RC_HISTORY_MAX 256 +#endif + +#if !defined (RC_HISTORY_FLAGS) +# define RC_HISTORY_FLAGS (RC_LEASE | RC_MISC) +#endif + +struct rc_history_entry { + const char *file; + int line; + void *reference; + void *addr; + int refcnt; +}; + +#define rc_register(x, l, r, y, z, d, f) do { \ + if (RC_HISTORY_FLAGS & ~(f)) { \ + rc_history [rc_history_index].file = (x); \ + rc_history [rc_history_index].line = (l); \ + rc_history [rc_history_index].reference = (r); \ + rc_history [rc_history_index].addr = (y); \ + rc_history [rc_history_index].refcnt = (z); \ + rc_history_next (d); \ + } \ + } while (0) +#define rc_register_mdl(r, y, z, d, f) \ + rc_register (__FILE__, __LINE__, r, y, z, d, f) +#else +#define rc_register(file, line, reference, addr, refcnt, d, f) +#define rc_register_mdl(reference, addr, refcnt, d, f) +#endif + +#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +extern struct dmalloc_preamble *dmalloc_list; +extern unsigned long dmalloc_outstanding; +extern unsigned long dmalloc_longterm; +extern unsigned long dmalloc_generation; +extern unsigned long dmalloc_cutoff_generation; +#endif + +#if defined (DEBUG_RC_HISTORY) +extern struct rc_history_entry rc_history [RC_HISTORY_MAX]; +extern int rc_history_index; +extern int rc_history_count; +#endif diff --git a/includes/omapip/buffer.h b/includes/omapip/buffer.h new file mode 100644 index 0000000..f31aa99 --- /dev/null +++ b/includes/omapip/buffer.h @@ -0,0 +1,77 @@ +/* buffer.h + + Definitions for the object management API protocol buffering... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +/* OMAPI buffers are ring buffers, which means that the beginning of the + buffer and the end of the buffer chase each other around. As long as + the tail never catches up to the head, there's room in the buffer for + data. + + - If the tail and the head are equal, the buffer is empty. + + - If the tail is less than the head, the contents of the buffer + are the bytes from the head to the end of buffer, and in addition, + the bytes between the beginning of the buffer and the tail, not + including the byte addressed by the tail. + + - If the tail is greater than the head, then the buffer contains + valid bytes starting with the byte addressed by the head, and + ending with the byte before the byte addressed by the tail. + + There will always be at least one byte of waste, because the tail can't + increase so that it's equal to the head (that would represent an empty + buffer. */ +#define OMAPI_BUF_SIZE 4048 +typedef struct _omapi_buffer { + struct _omapi_buffer *next; /* Buffers can be chained. */ + u_int32_t refcnt; /* Buffers are reference counted. */ + u_int16_t head, tail; /* Buffers are organized in a ring. */ + char buf [OMAPI_BUF_SIZE]; /* The actual buffer is included in + the buffer data structure. */ +} omapi_buffer_t; + +#define BUFFER_BYTES_FREE(x) \ + ((x) -> tail > (x) -> head \ + ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \ + : (x) -> head - (x) -> tail) + +#define BYTES_IN_BUFFER(x) \ + ((x) -> tail > (x) -> head \ + ? (x) -> tail - (x) -> head - 1 \ + : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1) + +isc_result_t omapi_connection_require (omapi_object_t *, unsigned); +isc_result_t omapi_connection_copyout (unsigned char *, + omapi_object_t *, unsigned); +isc_result_t omapi_connection_copyin (omapi_object_t *, + const unsigned char *, unsigned); +isc_result_t omapi_connection_flush (omapi_object_t *); +isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *); +isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t); +isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *); +isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t); + diff --git a/includes/omapip/convert.h b/includes/omapip/convert.h new file mode 100644 index 0000000..589594a --- /dev/null +++ b/includes/omapip/convert.h @@ -0,0 +1,46 @@ +/* convert.h + + Safe copying of integers into and out of a non-aligned memory buffer. */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef OMAPI_CONVERT_H +#define OMAPI_CONVERT_H + +u_int32_t getULong (const unsigned char *); +int32_t getLong (const unsigned char *); +u_int32_t getUShort (const unsigned char *); +int32_t getShort (const unsigned char *); +u_int32_t getUChar (const unsigned char *); +void putULong (unsigned char *, u_int32_t); +void putLong (unsigned char *, int32_t); +void putUShort (unsigned char *, u_int32_t); +void putShort (unsigned char *, int32_t); +void putUChar (unsigned char *, u_int32_t); +int converted_length (const unsigned char *, unsigned int, unsigned int); +int binary_to_ascii (unsigned char *, const unsigned char *, + unsigned int, unsigned int); + +#endif /* OMAPI_CONVERT_H */ diff --git a/includes/omapip/hash.h b/includes/omapip/hash.h new file mode 100644 index 0000000..4e7a413 --- /dev/null +++ b/includes/omapip/hash.h @@ -0,0 +1,161 @@ +/* hash.h + + Definitions for hashing... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1995-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef OMAPI_HASH_H +#define OMAPI_HASH_H + +#if !defined (DEFAULT_HASH_SIZE) +# define DEFAULT_HASH_SIZE 9973 +#endif + +#if !defined (KEY_HASH_SIZE) +# define KEY_HASH_SIZE 1009 +#endif + +/* The purpose of the hashed_object_t struct is to not match anything else. */ +typedef struct { + int foo; +} hashed_object_t; + +typedef isc_result_t (*hash_foreach_func)(const void *, unsigned, void *); +typedef int (*hash_reference) (hashed_object_t **, hashed_object_t *, + const char *, int); +typedef int (*hash_dereference) (hashed_object_t **, const char *, int); + +struct hash_bucket { + struct hash_bucket *next; + const unsigned char *name; + unsigned len; + hashed_object_t *value; +}; + +typedef int (*hash_comparator_t)(const void *, const void *, size_t); + +struct hash_table { + unsigned hash_count; + hash_reference referencer; + hash_dereference dereferencer; + hash_comparator_t cmp; + unsigned (*do_hash)(const void *, unsigned, unsigned); + + /* This must remain the last entry in this table. */ + struct hash_bucket *buckets [1]; +}; + +struct named_hash { + struct named_hash *next; + const char *name; + struct hash_table *hash; +}; + +#define HASH_FUNCTIONS_DECL(name, bufarg, type, hashtype) \ +void name##_hash_add (hashtype *, bufarg, unsigned, type *, \ + const char *, int); \ +void name##_hash_delete (hashtype *, bufarg, unsigned, \ + const char *, int); \ +int name##_hash_lookup (type **, hashtype *, bufarg, unsigned, \ + const char *, int); \ +unsigned char * name##_hash_report(hashtype *); \ +int name##_hash_foreach (hashtype *, hash_foreach_func); \ +int name##_new_hash (hashtype **, unsigned, const char *, int); \ +void name##_free_hash_table (hashtype **, const char *, int); + + +#define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher) \ +void name##_hash_add (hashtype *table, \ + bufarg buf, unsigned len, type *ptr, \ + const char *file, int line) \ +{ \ + add_hash ((struct hash_table *)table, buf, \ + len, (hashed_object_t *)ptr, file, line); \ +} \ + \ +void name##_hash_delete (hashtype *table, bufarg buf, unsigned len, \ + const char *file, int line) \ +{ \ + delete_hash_entry ((struct hash_table *)table, buf, len, \ + file, line); \ +} \ + \ +int name##_hash_lookup (type **ptr, hashtype *table, \ + bufarg buf, unsigned len, const char *file, int line) \ +{ \ + return hash_lookup ((hashed_object_t **)ptr, \ + (struct hash_table *)table, \ + buf, len, file, line); \ +} \ + \ +unsigned char * name##_hash_report(hashtype *table) \ +{ \ + return hash_report((struct hash_table *)table); \ +} \ + \ +int name##_hash_foreach (hashtype *table, hash_foreach_func func) \ +{ \ + return hash_foreach ((struct hash_table *)table, \ + func); \ +} \ + \ +int name##_new_hash (hashtype **tp, unsigned c, const char *file, int line) \ +{ \ + return new_hash ((struct hash_table **)tp, \ + (hash_reference)ref, (hash_dereference)deref, c, \ + hasher, file, line); \ +} \ + \ +void name##_free_hash_table (hashtype **table, const char *file, int line) \ +{ \ + free_hash_table ((struct hash_table **)table, file, line); \ +} + +void relinquish_hash_bucket_hunks (void); +int new_hash_table (struct hash_table **, unsigned, const char *, int); +void free_hash_table (struct hash_table **, const char *, int); +struct hash_bucket *new_hash_bucket (const char *, int); +void free_hash_bucket (struct hash_bucket *, const char *, int); +int new_hash(struct hash_table **, + hash_reference, hash_dereference, unsigned, + unsigned (*do_hash)(const void *, unsigned, unsigned), + const char *, int); +unsigned do_string_hash(const void *, unsigned, unsigned); +unsigned do_case_hash(const void *, unsigned, unsigned); +unsigned do_id_hash(const void *, unsigned, unsigned); +unsigned do_number_hash(const void *, unsigned, unsigned); +unsigned do_ip4_hash(const void *, unsigned, unsigned); +unsigned char *hash_report(struct hash_table *); +void add_hash (struct hash_table *, + const void *, unsigned, hashed_object_t *, + const char *, int); +void delete_hash_entry (struct hash_table *, const void *, + unsigned, const char *, int); +int hash_lookup (hashed_object_t **, struct hash_table *, + const void *, unsigned, const char *, int); +int hash_foreach (struct hash_table *, hash_foreach_func); +int casecmp (const void *s, const void *t, size_t len); + +#endif /* OMAPI_HASH_H */ diff --git a/includes/omapip/isclib.h b/includes/omapip/isclib.h new file mode 100644 index 0000000..30abacd --- /dev/null +++ b/includes/omapip/isclib.h @@ -0,0 +1,130 @@ +/* isclib.h + + connections to the isc and dns libraries */ + +/* + * Copyright (c) 2009,2013,2014 by Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * http://www.isc.org/ + * + */ + +#ifndef ISCLIB_H +#define ISCLIB_H + +#include "config.h" + +#include <syslog.h> + +#define MAXWIRE 256 + +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <arpa/inet.h> + +#include <unistd.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <netdb.h> + +#include <isc/buffer.h> +#include <isc/lex.h> +#include <isc/lib.h> +#include <isc/app.h> +#include <isc/mem.h> +#include <isc/parseint.h> +#include <isc/socket.h> +#include <isc/sockaddr.h> +#include <isc/task.h> +#include <isc/timer.h> +#include <isc/heap.h> +#include <isc/random.h> + +#include <dns/client.h> +#include <dns/fixedname.h> +#include <dns/keyvalues.h> +#include <dns/lib.h> +#include <dns/name.h> +#include <dns/rdata.h> +#include <dns/rdataclass.h> +#include <dns/rdatalist.h> +#include <dns/rdataset.h> +#include <dns/rdatastruct.h> +#include <dns/rdatatype.h> +#include <dns/result.h> +#include <dns/secalg.h> +#include <dns/tsec.h> + +#include <dst/dst.h> + +#include "result.h" + + +/* + * DHCP context structure + * This holds the libisc information for a dhcp entity + */ + +typedef struct dhcp_context { + isc_mem_t *mctx; + isc_appctx_t *actx; + int actx_started; + isc_taskmgr_t *taskmgr; + isc_task_t *task; + isc_socketmgr_t *socketmgr; + isc_timermgr_t *timermgr; +#if defined (NSUPDATE) + dns_client_t *dnsclient; +#endif +} dhcp_context_t; + +extern dhcp_context_t dhcp_gbl_ctx; + +#define DHCP_MAXDNS_WIRE 256 +#define DHCP_MAXNS 3 +#define DHCP_HMAC_MD5_NAME "HMAC-MD5.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA1_NAME "HMAC-SHA1.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA224_NAME "HMAC-SHA224.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA256_NAME "HMAC-SHA256.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA384_NAME "HMAC-SHA384.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA512_NAME "HMAC-SHA512.SIG-ALG.REG.INT." + +isc_result_t dhcp_isc_name(unsigned char *namestr, + dns_fixedname_t *namefix, + dns_name_t **name); + +isc_result_t +isclib_make_dst_key(char *inname, + char *algorithm, + unsigned char *secret, + int length, + dst_key_t **dstkey); + +isc_result_t dhcp_context_create(void); +void isclib_cleanup(void); + +void dhcp_signal_handler(int signal); +extern int shutdown_signal; + +#endif /* ISCLIB_H */ diff --git a/includes/omapip/omapip.h b/includes/omapip/omapip.h new file mode 100644 index 0000000..c4724e3 --- /dev/null +++ b/includes/omapip/omapip.h @@ -0,0 +1,616 @@ +/* omapip.h + + Definitions for the object management API and protocol... */ + +/* + * Copyright (c) 2009,2013-2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef _OMAPIP_H_ +#define _OMAPIP_H_ +#include "result.h" +#include <stdarg.h> + +#include <dns/tsec.h> + +typedef unsigned int omapi_handle_t; + +struct __omapi_object; +typedef struct __omapi_object omapi_object_t; + +typedef enum { + omapi_datatype_int, + omapi_datatype_string, + omapi_datatype_data, + omapi_datatype_object +} omapi_datatype_t; + +typedef struct { + int refcnt; + omapi_datatype_t type; + union { + struct { + unsigned len; +#define OMAPI_TYPED_DATA_NOBUFFER_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + sizeof (int)) + unsigned char value [1]; + } buffer; +#define OMAPI_TYPED_DATA_OBJECT_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + sizeof (omapi_object_t *)) + omapi_object_t *object; +#define OMAPI_TYPED_DATA_REF_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + 3 * sizeof (void *)) + struct { + void *ptr; + isc_result_t (*reference) (void *, + void *, const char *, int); + isc_result_t (*dereference) (void *, + const char *, int); + } ref; +#define OMAPI_TYPED_DATA_INT_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + sizeof (int)) + int integer; + } u; +} omapi_typed_data_t; + +typedef struct { + int refcnt; + unsigned len; +#define OMAPI_DATA_STRING_EMPTY_SIZE (2 * sizeof (int)) + unsigned char value [1]; +} omapi_data_string_t; + +typedef struct { + int refcnt; + omapi_data_string_t *name; + omapi_typed_data_t *value; +} omapi_value_t; + +typedef struct __omapi_object_type_t { + const char *name; + struct __omapi_object_type_t *next; + + isc_result_t (*set_value) (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); + isc_result_t (*get_value) (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, omapi_value_t **); + isc_result_t (*destroy) (omapi_object_t *, const char *, int); + isc_result_t (*signal_handler) (omapi_object_t *, + const char *, va_list); + isc_result_t (*stuff_values) (omapi_object_t *, + omapi_object_t *, omapi_object_t *); + isc_result_t (*lookup) (omapi_object_t **, omapi_object_t *, + omapi_object_t *); + isc_result_t (*create) (omapi_object_t **, omapi_object_t *); + isc_result_t (*remove) (omapi_object_t *, omapi_object_t *); + isc_result_t (*freer) (omapi_object_t *, const char *, int); + isc_result_t (*allocator) (omapi_object_t **, const char *, int); + isc_result_t (*sizer) (size_t); + size_t size; + int rc_flag; + isc_result_t (*initialize) (omapi_object_t *, const char *, int); +} omapi_object_type_t; + +#define OMAPI_OBJECT_PREAMBLE \ + omapi_object_type_t *type; \ + int refcnt; \ + omapi_handle_t handle; \ + omapi_object_t *outer, *inner + +/* The omapi handle structure. */ +struct __omapi_object { + OMAPI_OBJECT_PREAMBLE; +}; + +/* The port on which applications should listen for OMAPI connections. */ +#define OMAPI_PROTOCOL_PORT 7911 + +typedef struct { + unsigned addrtype; + unsigned addrlen; + unsigned char address [16]; + unsigned port; +} omapi_addr_t; + +typedef struct { + int refcnt; + unsigned count; + omapi_addr_t *addresses; +} omapi_addr_list_t; + +typedef struct auth_key { + OMAPI_OBJECT_PREAMBLE; + char *name; + char *algorithm; + omapi_data_string_t *key; + dns_tsec_t *tsec_key; +} omapi_auth_key_t; + +#define OMAPI_CREATE 1 +#define OMAPI_UPDATE 2 +#define OMAPI_EXCL 4 +#define OMAPI_NOTIFY_PROTOCOL 8 + +#define OMAPI_OBJECT_ALLOC(name, stype, type) \ +isc_result_t name##_allocate (stype **p, const char *file, int line) \ +{ \ + return omapi_object_allocate ((omapi_object_t **)p, \ + type, 0, file, line); \ +} \ + \ +isc_result_t name##_reference (stype **pptr, stype *ptr, \ + const char *file, int line) \ +{ \ + return omapi_object_reference ((omapi_object_t **)pptr, \ + (omapi_object_t *)ptr, file, line); \ +} \ + \ +isc_result_t name##_dereference (stype **ptr, const char *file, int line) \ +{ \ + return omapi_object_dereference ((omapi_object_t **)ptr, file, line); \ +} + +#define OMAPI_OBJECT_ALLOC_DECL(name, stype, type) \ +isc_result_t name##_allocate (stype **p, const char *file, int line); \ +isc_result_t name##_reference (stype **pptr, stype *ptr, \ + const char *file, int line); \ +isc_result_t name##_dereference (stype **ptr, const char *file, int line); + +typedef isc_result_t (*omapi_array_ref_t) (char **, char *, const char *, int); +typedef isc_result_t (*omapi_array_deref_t) (char **, const char *, int); + +/* An extensible array type. */ +typedef struct { + char **data; + omapi_array_ref_t ref; + omapi_array_deref_t deref; + int count; + int max; +} omapi_array_t; + +#define OMAPI_ARRAY_TYPE(name, stype) \ +isc_result_t name##_array_allocate (omapi_array_t **p, \ + const char *file, int line) \ +{ \ + return (omapi_array_allocate \ + (p, \ + (omapi_array_ref_t)name##_reference, \ + (omapi_array_deref_t)name##_dereference, \ + file, line)); \ +} \ + \ +isc_result_t name##_array_free (omapi_array_t **p, \ + const char *file, int line) \ +{ \ + return omapi_array_free (p, file, line); \ +} \ + \ +isc_result_t name##_array_extend (omapi_array_t *pptr, stype *ptr, int *index,\ + const char *file, int line) \ +{ \ + return omapi_array_extend (pptr, (char *)ptr, index, file, line); \ +} \ + \ +isc_result_t name##_array_set (omapi_array_t *pptr, stype *ptr, int index, \ + const char *file, int line) \ +{ \ + return omapi_array_set (pptr, (char *)ptr, index, file, line); \ +} \ + \ +isc_result_t name##_array_lookup (stype **ptr, omapi_array_t *pptr, \ + int index, const char *file, int line) \ +{ \ + return omapi_array_lookup ((char **)ptr, pptr, index, file, line); \ +} + +#define OMAPI_ARRAY_TYPE_DECL(name, stype) \ +isc_result_t name##_array_allocate (omapi_array_t **, const char *, int); \ +isc_result_t name##_array_free (omapi_array_t **, const char *, int); \ +isc_result_t name##_array_extend (omapi_array_t *, stype *, int *, \ + const char *, int); \ +isc_result_t name##_array_set (omapi_array_t *, \ + stype *, int, const char *, int); \ +isc_result_t name##_array_lookup (stype **, \ + omapi_array_t *, int, const char *, int) + +#define omapi_array_foreach_begin(array, stype, var) \ + { \ + int omapi_array_foreach_index; \ + stype *var = (stype *)0; \ + for (omapi_array_foreach_index = 0; \ + array && \ + omapi_array_foreach_index < (array) -> count; \ + omapi_array_foreach_index++) { \ + if ((array) -> data [omapi_array_foreach_index]) { \ + ((*(array) -> ref) \ + ((char **)&var, \ + (array) -> data [omapi_array_foreach_index],\ + MDL)); + +#define omapi_array_foreach_end(array, stype, var) \ + (*(array) -> deref) ((char **)&var, MDL); \ + } \ + } \ + } + +isc_result_t omapi_protocol_connect (omapi_object_t *, + const char *, unsigned, omapi_object_t *); +isc_result_t omapi_connect_list (omapi_object_t *, omapi_addr_list_t *, + omapi_addr_t *); +isc_result_t omapi_protocol_listen (omapi_object_t *, unsigned, int); +isc_boolean_t omapi_protocol_authenticated (omapi_object_t *); +isc_result_t omapi_protocol_configure_security (omapi_object_t *, + isc_result_t (*) + (omapi_object_t *, + omapi_addr_t *), + isc_result_t (*) + (omapi_object_t *, + omapi_auth_key_t *)); +isc_result_t omapi_protocol_accept (omapi_object_t *); +isc_result_t omapi_protocol_send_intro (omapi_object_t *, unsigned, unsigned); +isc_result_t omapi_protocol_ready (omapi_object_t *); +isc_result_t omapi_protocol_add_auth (omapi_object_t *, omapi_object_t *, + omapi_handle_t); +isc_result_t omapi_protocol_lookup_auth (omapi_object_t **, omapi_object_t *, + omapi_handle_t); +isc_result_t omapi_protocol_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_protocol_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_protocol_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +isc_result_t omapi_protocol_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_protocol_send_message (omapi_object_t *, + omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_protocol_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_protocol_listener_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_protocol_listener_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_protocol_listener_destroy (omapi_object_t *, + const char *, int); +isc_result_t omapi_protocol_listener_signal (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_protocol_listener_stuff (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_protocol_send_status (omapi_object_t *, omapi_object_t *, + isc_result_t, unsigned, const char *); +isc_result_t omapi_protocol_send_open (omapi_object_t *, omapi_object_t *, + const char *, omapi_object_t *, + unsigned); +isc_result_t omapi_protocol_send_update (omapi_object_t *, omapi_object_t *, + unsigned, omapi_object_t *); + +isc_result_t omapi_connect (omapi_object_t *, const char *, unsigned); +isc_result_t omapi_disconnect (omapi_object_t *, int); +int omapi_connection_readfd (omapi_object_t *); +int omapi_connection_writefd (omapi_object_t *); +isc_result_t omapi_connection_connect (omapi_object_t *); +isc_result_t omapi_connection_reader (omapi_object_t *); +isc_result_t omapi_connection_writer (omapi_object_t *); +isc_result_t omapi_connection_reaper (omapi_object_t *); +isc_result_t omapi_connection_output_auth_length (omapi_object_t *, + unsigned *); +isc_result_t omapi_connection_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_connection_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_connection_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_connection_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_connection_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_connection_write_typed_data (omapi_object_t *, + omapi_typed_data_t *); +isc_result_t omapi_connection_put_name (omapi_object_t *, const char *); +isc_result_t omapi_connection_put_string (omapi_object_t *, const char *); +isc_result_t omapi_connection_put_handle (omapi_object_t *c, + omapi_object_t *h); + +isc_result_t omapi_listen (omapi_object_t *, unsigned, int); +isc_result_t omapi_listen_addr (omapi_object_t *, + omapi_addr_t *, int); +isc_result_t omapi_listener_accept (omapi_object_t *); +int omapi_listener_readfd (omapi_object_t *); +isc_result_t omapi_accept (omapi_object_t *); +isc_result_t omapi_listener_configure_security (omapi_object_t *, + isc_result_t (*) + (omapi_object_t *, + omapi_addr_t *)); +isc_result_t omapi_listener_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_listener_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_listener_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_listener_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_listener_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +isc_result_t omapi_register_io_object (omapi_object_t *, + int (*)(omapi_object_t *), + int (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *)); +isc_result_t omapi_reregister_io_object (omapi_object_t *, + int (*)(omapi_object_t *), + int (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *)); +isc_result_t omapi_unregister_io_object (omapi_object_t *); +isc_result_t omapi_dispatch (struct timeval *); +isc_result_t omapi_wait_for_completion (omapi_object_t *, struct timeval *); +isc_result_t omapi_one_dispatch (omapi_object_t *, struct timeval *); +isc_result_t omapi_io_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_io_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, omapi_value_t **); +isc_result_t omapi_io_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_io_signal_handler (omapi_object_t *, const char *, va_list); +isc_result_t omapi_io_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_waiter_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_io_state_foreach (isc_result_t (*func) (omapi_object_t *, + void *), + void *p); + +isc_result_t omapi_generic_new (omapi_object_t **, const char *, int); +isc_result_t omapi_generic_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_generic_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_generic_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_generic_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_generic_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_generic_clear_flags (omapi_object_t *); + +isc_result_t omapi_message_new (omapi_object_t **, const char *, int); +isc_result_t omapi_message_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_message_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_message_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_message_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_message_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_message_register (omapi_object_t *); +isc_result_t omapi_message_unregister (omapi_object_t *); +isc_result_t omapi_message_process (omapi_object_t *, omapi_object_t *); + +OMAPI_OBJECT_ALLOC_DECL (omapi_auth_key, + omapi_auth_key_t, omapi_type_auth_key) +isc_result_t omapi_auth_key_new (omapi_auth_key_t **, const char *, int); +isc_result_t omapi_auth_key_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_auth_key_enter (omapi_auth_key_t *); +isc_result_t omapi_auth_key_lookup_name (omapi_auth_key_t **, const char *); +isc_result_t omapi_auth_key_lookup (omapi_object_t **, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_auth_key_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_auth_key_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +extern omapi_object_type_t *omapi_type_connection; +extern omapi_object_type_t *omapi_type_listener; +extern omapi_object_type_t *omapi_type_io_object; +extern omapi_object_type_t *omapi_type_generic; +extern omapi_object_type_t *omapi_type_protocol; +extern omapi_object_type_t *omapi_type_protocol_listener; +extern omapi_object_type_t *omapi_type_waiter; +extern omapi_object_type_t *omapi_type_remote; +extern omapi_object_type_t *omapi_type_message; +extern omapi_object_type_t *omapi_type_auth_key; + +extern omapi_object_type_t *omapi_object_types; + +void omapi_type_relinquish (void); +isc_result_t omapi_init (void); +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); +isc_result_t omapi_signal (omapi_object_t *, const char *, ...); +isc_result_t omapi_signal_in (omapi_object_t *, const char *, ...); +isc_result_t omapi_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_set_value_str (omapi_object_t *, omapi_object_t *, + const char *, omapi_typed_data_t *); +isc_result_t omapi_set_boolean_value (omapi_object_t *, omapi_object_t *, + const char *, int); +isc_result_t omapi_set_int_value (omapi_object_t *, omapi_object_t *, + const char *, int); +isc_result_t omapi_set_object_value (omapi_object_t *, omapi_object_t *, + const char *, omapi_object_t *); +isc_result_t omapi_set_string_value (omapi_object_t *, omapi_object_t *, + const char *, const char *); +isc_result_t omapi_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_get_value_str (omapi_object_t *, omapi_object_t *, + const char *, omapi_value_t **); +isc_result_t omapi_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_object_create (omapi_object_t **, omapi_object_t *, + omapi_object_type_t *); +isc_result_t omapi_object_update (omapi_object_t *, omapi_object_t *, + omapi_object_t *, omapi_handle_t); +int omapi_data_string_cmp (omapi_data_string_t *, omapi_data_string_t *); +int omapi_ds_strcmp (omapi_data_string_t *, const char *); +int omapi_td_strcmp (omapi_typed_data_t *, const char *); +int omapi_td_strcasecmp (omapi_typed_data_t *, const char *); +isc_result_t omapi_make_value (omapi_value_t **, omapi_data_string_t *, + omapi_typed_data_t *, const char *, int); +isc_result_t omapi_make_const_value (omapi_value_t **, omapi_data_string_t *, + const unsigned char *, + unsigned, const char *, int); +isc_result_t omapi_make_int_value (omapi_value_t **, omapi_data_string_t *, + int, const char *, int); +isc_result_t omapi_make_uint_value (omapi_value_t **, omapi_data_string_t *, + unsigned int, const char *, int); +isc_result_t omapi_make_object_value (omapi_value_t **, omapi_data_string_t *, + 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); +isc_result_t omapi_make_string_value (omapi_value_t **, omapi_data_string_t *, + const char *, const char *, int); +isc_result_t omapi_get_int_value (unsigned long *, omapi_typed_data_t *); + +isc_result_t omapi_object_handle (omapi_handle_t *, omapi_object_t *); +isc_result_t omapi_handle_lookup (omapi_object_t **, omapi_handle_t); +isc_result_t omapi_handle_td_lookup (omapi_object_t **, omapi_typed_data_t *); + +void * dmalloc (unsigned, const char *, int); +void dfree (void *, const char *, int); +#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +void dmalloc_reuse (void *, const char *, int, int); +void dmalloc_dump_outstanding (void); +#else +#define dmalloc_reuse(x,y,l,z) +#endif +#define MDL __FILE__, __LINE__ +#if defined (DEBUG_RC_HISTORY) +void dump_rc_history (void *); +void rc_history_next (int); +#endif +void omapi_print_dmalloc_usage_by_caller (void); +isc_result_t omapi_object_allocate (omapi_object_t **, + omapi_object_type_t *, + size_t, const char *, int); +isc_result_t omapi_object_initialize (omapi_object_t *, + omapi_object_type_t *, + size_t, size_t, const char *, int); +isc_result_t omapi_object_reference (omapi_object_t **, + omapi_object_t *, const char *, int); +isc_result_t omapi_object_dereference (omapi_object_t **, const char *, int); +isc_result_t omapi_typed_data_new (const char *, int, omapi_typed_data_t **, + omapi_datatype_t, ...); +isc_result_t omapi_typed_data_reference (omapi_typed_data_t **, + omapi_typed_data_t *, + const char *, int); +isc_result_t omapi_typed_data_dereference (omapi_typed_data_t **, + const char *, int); +isc_result_t omapi_data_string_new (omapi_data_string_t **, + unsigned, const char *, int); +isc_result_t omapi_data_string_reference (omapi_data_string_t **, + omapi_data_string_t *, + const char *, int); +isc_result_t omapi_data_string_dereference (omapi_data_string_t **, + const char *, int); +isc_result_t omapi_value_new (omapi_value_t **, const char *, int); +isc_result_t omapi_value_reference (omapi_value_t **, + omapi_value_t *, const char *, int); +isc_result_t omapi_value_dereference (omapi_value_t **, const char *, int); +isc_result_t omapi_addr_list_new (omapi_addr_list_t **, unsigned, + const char *, int); +isc_result_t omapi_addr_list_reference (omapi_addr_list_t **, + omapi_addr_list_t *, + const char *, int); +isc_result_t omapi_addr_list_dereference (omapi_addr_list_t **, + const char *, int); + +isc_result_t omapi_array_allocate (omapi_array_t **, omapi_array_ref_t, + omapi_array_deref_t, const char *, int); +isc_result_t omapi_array_free (omapi_array_t **, const char *, int); +isc_result_t omapi_array_extend (omapi_array_t *, char *, int *, + const char *, int); +isc_result_t omapi_array_set (omapi_array_t *, void *, int, const char *, int); +isc_result_t omapi_array_lookup (char **, + omapi_array_t *, int, const char *, int); +OMAPI_ARRAY_TYPE_DECL(omapi_object, omapi_object_t); +#endif /* _OMAPIP_H_ */ diff --git a/includes/omapip/omapip_p.h b/includes/omapip/omapip_p.h new file mode 100644 index 0000000..788c91e --- /dev/null +++ b/includes/omapip/omapip_p.h @@ -0,0 +1,299 @@ +/* omapip_p.h + + Private master include file for the OMAPI library. */ + +/* + * Copyright (c) 2009-2010,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef __OMAPIP_OMAPIP_P_H__ +#define __OMAPIP_OMAPIP_P_H__ + +#ifndef __CYGWIN32__ +#include <sys/types.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <arpa/inet.h> + +#include <netdb.h> +#else +#define fd_set cygwin_fd_set +#include <sys/types.h> +#endif +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <memory.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <ctype.h> +#include <time.h> + +/* + * XXX: I'm not sure why these were here. +#include "cdefs.h" +#include "osdep.h" + */ + +#include <dst/dst.h> +#include "result.h" + +#include <omapip/convert.h> +#include <omapip/hash.h> +#include <omapip/omapip.h> +#include <omapip/trace.h> + +/* DST_API control flags */ +/* These are used in functions dst_sign_data and dst_verify_data */ +#define SIG_MODE_INIT 1 /* initalize digest */ +#define SIG_MODE_UPDATE 2 /* add data to digest */ +#define SIG_MODE_FINAL 4 /* generate/verify signature */ +#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) + +/* OMAPI protocol header, version 1.00 */ +typedef struct { + u_int32_t authlen; /* Length of authenticator. */ + u_int32_t authid; /* Authenticator object ID. */ + u_int32_t op; /* Opcode. */ + omapi_handle_t handle; /* Handle of object being operated on, + or zero. */ + u_int32_t id; /* Transaction ID. */ + u_int32_t rid; /* ID of transaction to which this is a response. */ +} omapi_protocol_header_t; + +#define OMAPI_PROTOCOL_VERSION 100 + +#define OMAPI_OP_OPEN 1 +#define OMAPI_OP_REFRESH 2 +#define OMAPI_OP_UPDATE 3 +#define OMAPI_OP_NOTIFY 4 +#define OMAPI_OP_STATUS 5 +#define OMAPI_OP_DELETE 6 + +typedef enum { + omapi_connection_unconnected, + omapi_connection_connecting, + omapi_connection_connected, + omapi_connection_disconnecting, + omapi_connection_closed +} omapi_connection_state_t; + +typedef enum { + omapi_protocol_intro_wait, + omapi_protocol_header_wait, + omapi_protocol_signature_wait, + omapi_protocol_name_wait, + omapi_protocol_name_length_wait, + omapi_protocol_value_wait, + omapi_protocol_value_length_wait +} omapi_protocol_state_t; + +typedef struct __omapi_message_object { + OMAPI_OBJECT_PREAMBLE; + struct __omapi_message_object *next, *prev; + omapi_object_t *object; + omapi_object_t *notify_object; + struct __omapi_protocol_object *protocol_object; + u_int32_t authlen; + omapi_typed_data_t *authenticator; + u_int32_t authid; + omapi_object_t *id_object; + u_int32_t op; + u_int32_t h; + u_int32_t id; + u_int32_t rid; +} omapi_message_object_t; + +typedef struct __omapi_remote_auth { + struct __omapi_remote_auth *next; + omapi_handle_t remote_handle; + omapi_object_t *a; +} omapi_remote_auth_t; + +typedef struct __omapi_protocol_object { + OMAPI_OBJECT_PREAMBLE; + u_int32_t header_size; + u_int32_t protocol_version; + u_int32_t next_xid; + + omapi_protocol_state_t state; /* Input state. */ + int reading_message_values; /* True if reading message-specific + values. */ + omapi_message_object_t *message; /* Incoming message. */ + omapi_data_string_t *name; /* Incoming name. */ + omapi_typed_data_t *value; /* Incoming value. */ + isc_result_t verify_result; + omapi_remote_auth_t *default_auth; /* Default authinfo to use. */ + omapi_remote_auth_t *remote_auth_list; /* Authenticators active on + this connection. */ + + isc_boolean_t insecure; /* Set to allow unauthenticated + messages. */ + + isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *); +} omapi_protocol_object_t; + +typedef struct { + OMAPI_OBJECT_PREAMBLE; + + isc_boolean_t insecure; /* Set to allow unauthenticated + messages. */ + + isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *); +} omapi_protocol_listener_object_t; + +#include <omapip/buffer.h> + +typedef struct __omapi_listener_object { + OMAPI_OBJECT_PREAMBLE; + int socket; /* Connection socket. */ + int index; + struct sockaddr_in address; + isc_result_t (*verify_addr) (omapi_object_t *, omapi_addr_t *); +} omapi_listener_object_t; + +typedef struct __omapi_connection_object { + OMAPI_OBJECT_PREAMBLE; + int socket; /* Connection socket. */ + int32_t index; + omapi_connection_state_t state; + struct sockaddr_in remote_addr; + struct sockaddr_in local_addr; + omapi_addr_list_t *connect_list; /* List of addresses to which + to connect. */ + int cptr; /* Current element we are connecting to. */ + u_int32_t bytes_needed; /* Bytes of input needed before wakeup. */ + u_int32_t in_bytes; /* Bytes of input already buffered. */ + omapi_buffer_t *inbufs; + u_int32_t out_bytes; /* Bytes of output in buffers. */ + omapi_buffer_t *outbufs; + omapi_listener_object_t *listener; /* Listener that accepted this + connection, if any. */ + dst_key_t *in_key; /* Authenticator signing incoming + data. */ + void *in_context; /* Input hash context. */ + dst_key_t *out_key; /* Authenticator signing outgoing + data. */ + void *out_context; /* Output hash context. */ +} omapi_connection_object_t; + +typedef struct __omapi_io_object { + OMAPI_OBJECT_PREAMBLE; + struct __omapi_io_object *next; + int (*readfd) (omapi_object_t *); + int (*writefd) (omapi_object_t *); + isc_result_t (*reader) (omapi_object_t *); + isc_result_t (*writer) (omapi_object_t *); + isc_result_t (*reaper) (omapi_object_t *); + isc_socket_t *fd; + isc_boolean_t closed; /* ISC_TRUE = closed, do not use */ +} omapi_io_object_t; + +typedef struct __omapi_generic_object { + OMAPI_OBJECT_PREAMBLE; + omapi_value_t **values; + u_int8_t *changed; + int nvalues, va_max; +} omapi_generic_object_t; + +typedef struct __omapi_waiter_object { + OMAPI_OBJECT_PREAMBLE; + int ready; + isc_result_t waitstatus; + struct __omapi_waiter_object *next; +} omapi_waiter_object_t; + +#define OMAPI_HANDLE_TABLE_SIZE 120 + +typedef struct __omapi_handle_table { + omapi_handle_t first, limit; + omapi_handle_t next; + int leafp; + union { + omapi_object_t *object; + struct __omapi_handle_table *table; + } children [OMAPI_HANDLE_TABLE_SIZE]; +} omapi_handle_table_t; + +#include <omapip/alloc.h> + +OMAPI_OBJECT_ALLOC_DECL (omapi_protocol, omapi_protocol_object_t, + omapi_type_protocol) +OMAPI_OBJECT_ALLOC_DECL (omapi_protocol_listener, + omapi_protocol_listener_object_t, + omapi_type_protocol_listener) +OMAPI_OBJECT_ALLOC_DECL (omapi_connection, + omapi_connection_object_t, omapi_type_connection) +OMAPI_OBJECT_ALLOC_DECL (omapi_listener, + omapi_listener_object_t, omapi_type_listener) +OMAPI_OBJECT_ALLOC_DECL (omapi_io, + omapi_io_object_t, omapi_type_io_object) +OMAPI_OBJECT_ALLOC_DECL (omapi_waiter, + omapi_waiter_object_t, omapi_type_waiter) +OMAPI_OBJECT_ALLOC_DECL (omapi_generic, + omapi_generic_object_t, omapi_type_generic) +OMAPI_OBJECT_ALLOC_DECL (omapi_message, + omapi_message_object_t, omapi_type_message) + +isc_result_t omapi_connection_sign_data (int mode, + dst_key_t *key, + void **context, + const unsigned char *data, + const unsigned len, + omapi_typed_data_t **result); +isc_result_t omapi_listener_connect (omapi_connection_object_t **obj, + omapi_listener_object_t *listener, + int socket, + struct sockaddr_in *remote_addr); +void omapi_listener_trace_setup (void); +void omapi_connection_trace_setup (void); +void omapi_buffer_trace_setup (void); +void omapi_connection_register (omapi_connection_object_t *, + const char *, int); +OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t); +OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t); + +isc_result_t omapi_handle_clear(omapi_handle_t); + +extern int log_perror; +extern void (*log_cleanup) (void); + +void log_fatal (const char *, ...) + __attribute__((__format__(__printf__,1,2))) ISC_DHCP_NORETURN; +int log_error (const char *, ...) + __attribute__((__format__(__printf__,1,2))); +int log_info (const char *, ...) + __attribute__((__format__(__printf__,1,2))); +int log_debug (const char *, ...) + __attribute__((__format__(__printf__,1,2))); +void do_percentm (char *obuf, const char *ibuf); + +isc_result_t uerr2isc (int); +isc_result_t ns_rcode_to_isc (int); + +extern omapi_message_object_t *omapi_registered_messages; + +#endif /* __OMAPIP_OMAPIP_P_H__ */ diff --git a/includes/omapip/result.h b/includes/omapip/result.h new file mode 100644 index 0000000..ae5f7d6 --- /dev/null +++ b/includes/omapip/result.h @@ -0,0 +1,121 @@ +/* result.h + */ + +/* + * Copyright (C) 2009,2014 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + */ + +#ifndef DHCP_RESULT_H +#define DHCP_RESULT_H 1 + +#include <isc/lang.h> +#include <isc/resultclass.h> +#include <isc/types.h> + +#include <isc/result.h> + +/* + * DHCP result codes + */ + +/* + * In the previous code the results started at 36 + * rather than ISC_RESULTCLASS_DHCP + 0 + * ISC_R_NOTCONNECTED was + 4 (40), it has been superseded by the isc version + */ + +#define DHCP_R_HOSTUNKNOWN (ISC_RESULTCLASS_DHCP + 0) +#define DHCP_R_VERSIONMISMATCH (ISC_RESULTCLASS_DHCP + 1) +#define DHCP_R_PROTOCOLERROR (ISC_RESULTCLASS_DHCP + 2) +#define DHCP_R_INVALIDARG (ISC_RESULTCLASS_DHCP + 3) +#define DHCP_R_NOTYET (ISC_RESULTCLASS_DHCP + 4) +#define DHCP_R_UNCHANGED (ISC_RESULTCLASS_DHCP + 5) +#define DHCP_R_MULTIPLE (ISC_RESULTCLASS_DHCP + 6) +#define DHCP_R_KEYCONFLICT (ISC_RESULTCLASS_DHCP + 7) +#define DHCP_R_BADPARSE (ISC_RESULTCLASS_DHCP + 8) +#define DHCP_R_NOKEYS (ISC_RESULTCLASS_DHCP + 9) +#define DHCP_R_KEY_UNKNOWN (ISC_RESULTCLASS_DHCP + 10) +#define DHCP_R_INVALIDKEY (ISC_RESULTCLASS_DHCP + 11) +#define DHCP_R_INCOMPLETE (ISC_RESULTCLASS_DHCP + 12) +#define DHCP_R_FORMERR (ISC_RESULTCLASS_DHCP + 13) +#define DHCP_R_SERVFAIL (ISC_RESULTCLASS_DHCP + 14) +#define DHCP_R_NXDOMAIN (ISC_RESULTCLASS_DHCP + 15) +#define DHCP_R_NOTIMPL (ISC_RESULTCLASS_DHCP + 16) +#define DHCP_R_REFUSED (ISC_RESULTCLASS_DHCP + 17) +#define DHCP_R_YXDOMAIN (ISC_RESULTCLASS_DHCP + 18) +#define DHCP_R_YXRRSET (ISC_RESULTCLASS_DHCP + 19) +#define DHCP_R_NXRRSET (ISC_RESULTCLASS_DHCP + 20) +#define DHCP_R_NOTAUTH (ISC_RESULTCLASS_DHCP + 21) +#define DHCP_R_NOTZONE (ISC_RESULTCLASS_DHCP + 22) +#define DHCP_R_BADSIG (ISC_RESULTCLASS_DHCP + 23) +#define DHCP_R_BADKEY (ISC_RESULTCLASS_DHCP + 24) +#define DHCP_R_BADTIME (ISC_RESULTCLASS_DHCP + 25) +#define DHCP_R_NOROOTZONE (ISC_RESULTCLASS_DHCP + 26) +#define DHCP_R_DESTADDRREQ (ISC_RESULTCLASS_DHCP + 27) +#define DHCP_R_CROSSZONE (ISC_RESULTCLASS_DHCP + 28) +#define DHCP_R_NO_TSIG (ISC_RESULTCLASS_DHCP + 29) +#define DHCP_R_NOT_EQUAL (ISC_RESULTCLASS_DHCP + 30) +#define DHCP_R_CONNRESET (ISC_RESULTCLASS_DHCP + 31) +#define DHCP_R_UNKNOWNATTRIBUTE (ISC_RESULTCLASS_DHCP + 32) + +#define DHCP_R_NRESULTS 33 /*%< Number of results */ + +// Included for historical reasons, these should be removed as +// soon as reasonable +#ifdef INCLUDE_OLD_DHCP_ISC_ERROR_CODES +#define ISC_R_HOSTUNKNOWN DHCP_R_HOSTUNKNOWN +#define ISC_R_VERSIONMISMATCH DHCP_R_VERSIONMISMATCH +#define ISC_R_PROTOCOLERROR DHCP_R_PROTOCOLERROR +#define ISC_R_INVALIDARG DHCP_R_INVALIDARG +#define ISC_R_NOTYET DHCP_R_NOTYET +#define ISC_R_UNCHANGED DHCP_R_UNCHANGED +#define ISC_R_KEYCONFLICT DHCP_R_KEYCONFLICT +#define ISC_R_BADPARSE DHCP_R_BADPARSE +#define ISC_R_NOKEYS DHCP_R_NOKEYS +#define ISC_R_KEY_UNKNOWN DHCP_R_KEY_UNKNOWN +#define ISC_R_INVALIDKEY DHCP_R_INVALIDKEY +#define ISC_R_INCOMPLETE DHCP_R_INCOMPLETE +#define ISC_R_FORMERR DHCP_R_FORMERR +#define ISC_R_SERVFAIL DHCP_R_SERVFAIL +#define ISC_R_NXDOMAIN DHCP_R_NXDOMAIN +#define ISC_R_NOTIMPL DHCP_R_NOTIMPL +#define ISC_R_REFUSED DHCP_R_REFUSED +#define ISC_R_YXDOMAIN DHCP_R_YXDOMAIN +#define ISC_R_YXRRSET DHCP_R_YXRRSET +#define ISC_R_NXRRSET DHCP_R_NXRRSET +#define ISC_R_NOTAUTH DHCP_R_NOTAUTH +#define ISC_R_NOTZONE DHCP_R_NOTZONE +#define ISC_R_BADSIG DHCP_R_BADSIG +#define ISC_R_BADKEY DHCP_R_BADKEY +#define ISC_R_BADTIME DHCP_R_BADTIME +#define ISC_R_NOROOTZONE DHCP_R_NOROOTZONE +#define ISC_R_DESTADDRREQ DHCP_R_DESTADDRREQ +#define ISC_R_CROSSZONE DHCP_R_CROSSZONE +#define ISC_R_NO_TSIG DHCP_R_NO_TSIG +#define ISC_R_NOT_EQUAL DHCP_R_NOT_EQUAL +#define ISC_R_CONNRESET DHCP_R_CONNRESET +#define ISC_R_UNKNOWNATTRIBUTE DHCP_R_UNKNOWNATTRIBUTE +#endif + +isc_result_t +dhcp_result_register(void); + +#endif /* DHCP_RESULT_H */ diff --git a/includes/omapip/trace.h b/includes/omapip/trace.h new file mode 100644 index 0000000..d55587b --- /dev/null +++ b/includes/omapip/trace.h @@ -0,0 +1,111 @@ +/* trace.h + + Definitions for omapi tracing facility... */ + +/* + * Copyright (c) 2004,2005,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2001-2003 by Internet Software Consortium + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#define TRACEFILE_MAGIC 0x64484370UL /* dHCp */ +#define TRACEFILE_VERSION 1 + +/* The first thing in a trace file is the header, which basically just + defines the version of the file. */ +typedef struct { + u_int32_t magic; /* Magic number for trace file. */ + u_int32_t version; /* Version of file. */ + int32_t hlen; /* Length of this header. */ + int32_t phlen; /* Length of packet headers. */ +} tracefile_header_t; + +/* The trace file is composed of a bunch of trace packets. Each such packet + has a type, followed by a length, followed by a timestamp, followed by + the actual contents of the packet. The type indexes are not fixed - + they are allocated either on readback or when writing a trace file. + One index type is reserved - type zero means that this record is a type + name to index mapping. */ +typedef struct { + u_int32_t type_index; /* Index to the type of handler that this + packet needs. */ + u_int32_t length; /* Length of the packet. This includes + everything except the fixed header. */ + u_int32_t when; /* When the packet was written. */ + u_int32_t pad; /* Round this out to a quad boundary. */ +} tracepacket_t; + +#define TRACE_INDEX_MAPPING_SIZE 4 /* trace_index_mapping_t less name. */ +typedef struct { + u_int32_t index; + char name [1]; +} trace_index_mapping_t; + +struct trace_type; /* forward */ +typedef struct trace_type trace_type_t; + +struct trace_type { + trace_type_t *next; + int index; + char *name; + void *baggage; + void (*have_packet) (trace_type_t *, unsigned, char *); + void (*stop_tracing) (trace_type_t *); +}; + +typedef struct trace_iov { + const char *buf; + unsigned len; +} trace_iov_t; + +typedef struct { + u_int16_t addrtype; + u_int16_t addrlen; + u_int8_t address [16]; + u_int16_t port; +} trace_addr_t; + +void trace_free_all (void); +int trace_playback (void); +int trace_record (void); +isc_result_t trace_init(void (*set_time)(time_t), const char *, int); +isc_result_t trace_begin (const char *, const char *, int); +isc_result_t trace_write_packet (trace_type_t *, unsigned, const char *, + const char *, int); +isc_result_t trace_write_packet_iov (trace_type_t *, int, trace_iov_t *, + const char *, int); +void trace_type_stash (trace_type_t *); +trace_type_t *trace_type_register (const char *, void *, + void (*) (trace_type_t *, + unsigned, char *), + void (*) (trace_type_t *), + const char *, int); +void trace_stop (void); +void trace_index_map_input (trace_type_t *, unsigned, char *); +void trace_index_stop_tracing (trace_type_t *); +void trace_replay_init (void); +void trace_file_replay (const char *); +isc_result_t trace_get_next_packet (trace_type_t **, tracepacket_t *, + char **, unsigned *, unsigned *); +isc_result_t trace_get_file (trace_type_t *, + const char *, unsigned *, char **); +isc_result_t trace_get_packet (trace_type_t **, unsigned *, char **); +time_t trace_snoop_time (trace_type_t **); |