diff options
Diffstat (limited to 'omapip')
-rw-r--r-- | omapip/Makefile.am | 5 | ||||
-rw-r--r-- | omapip/alloc.c | 70 | ||||
-rw-r--r-- | omapip/array.c | 12 | ||||
-rw-r--r-- | omapip/auth.c | 53 | ||||
-rw-r--r-- | omapip/buffer.c | 48 | ||||
-rw-r--r-- | omapip/connection.c | 209 | ||||
-rw-r--r-- | omapip/dispatch.c | 121 | ||||
-rw-r--r-- | omapip/generic.c | 10 | ||||
-rw-r--r-- | omapip/handle.c | 2 | ||||
-rw-r--r-- | omapip/isclib.c | 230 | ||||
-rw-r--r-- | omapip/listener.c | 16 | ||||
-rw-r--r-- | omapip/message.c | 64 | ||||
-rw-r--r-- | omapip/mrtrace.c | 4 | ||||
-rw-r--r-- | omapip/protocol.c | 62 | ||||
-rw-r--r-- | omapip/result.c | 161 | ||||
-rw-r--r-- | omapip/support.c | 10 | ||||
-rw-r--r-- | omapip/test.c | 5 | ||||
-rw-r--r-- | omapip/toisc.c | 126 | ||||
-rw-r--r-- | omapip/trace.c | 22 |
19 files changed, 752 insertions, 478 deletions
diff --git a/omapip/Makefile.am b/omapip/Makefile.am index 6a3c39f0..60aecf7f 100644 --- a/omapip/Makefile.am +++ b/omapip/Makefile.am @@ -4,10 +4,11 @@ noinst_PROGRAMS = svtest libomapi_a_SOURCES = protocol.c buffer.c alloc.c result.c connection.c \ errwarn.c listener.c dispatch.c generic.c support.c \ handle.c message.c convert.c hash.c auth.c inet_addr.c \ - array.c trace.c mrtrace.c toisc.c iscprint.c + array.c trace.c mrtrace.c toisc.c iscprint.c isclib.c + man_MANS = omapi.3 EXTRA_DIST = $(man_MANS) svtest_SOURCES = test.c -svtest_LDADD = libomapi.a ../dst/libdst.a +svtest_LDADD = libomapi.a ../bind/lib/libdns.a ../bind/lib/libisc.a diff --git a/omapip/alloc.c b/omapip/alloc.c index ad7f5f68..bff6fa23 100644 --- a/omapip/alloc.c +++ b/omapip/alloc.c @@ -526,7 +526,7 @@ isc_result_t omapi_object_allocate (omapi_object_t **o, /* Sanity check. */ if (tsize < sizeof (omapi_object_t)) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; foo = dmalloc (tsize, file, line); if (!foo) @@ -561,7 +561,7 @@ isc_result_t omapi_object_reference (omapi_object_t **r, const char *file, int line) { if (!h || !r) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (*r) { #if defined (POINTER_DEBUG) @@ -569,7 +569,7 @@ isc_result_t omapi_object_reference (omapi_object_t **r, file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } *r = h; @@ -588,14 +588,14 @@ isc_result_t omapi_object_dereference (omapi_object_t **h, omapi_object_t *p, *hp; if (!h) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!*h) { #if defined (POINTER_DEBUG) log_error ("%s(%d): dereference of null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -609,7 +609,7 @@ isc_result_t omapi_object_dereference (omapi_object_t **h, abort (); #else *h = 0; - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -727,7 +727,7 @@ isc_result_t omapi_buffer_reference (omapi_buffer_t **r, const char *file, int line) { if (!h || !r) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (*r) { #if defined (POINTER_DEBUG) @@ -735,7 +735,7 @@ isc_result_t omapi_buffer_reference (omapi_buffer_t **r, file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } *r = h; @@ -748,14 +748,14 @@ isc_result_t omapi_buffer_dereference (omapi_buffer_t **h, const char *file, int line) { if (!h) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!*h) { #if defined (POINTER_DEBUG) log_error ("%s(%d): dereference of null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -769,7 +769,7 @@ isc_result_t omapi_buffer_dereference (omapi_buffer_t **h, abort (); #else *h = 0; - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -807,7 +807,7 @@ isc_result_t omapi_typed_data_new (const char *file, int line, len = OMAPI_TYPED_DATA_NOBUFFER_LEN + val; if (len < val) { va_end(l); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } break; case omapi_datatype_data: @@ -815,7 +815,7 @@ isc_result_t omapi_typed_data_new (const char *file, int line, len = OMAPI_TYPED_DATA_NOBUFFER_LEN + val; if (len < val) { va_end(l); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } break; case omapi_datatype_object: @@ -824,7 +824,7 @@ isc_result_t omapi_typed_data_new (const char *file, int line, break; default: va_end (l); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } va_end (l); @@ -863,14 +863,14 @@ isc_result_t omapi_typed_data_reference (omapi_typed_data_t **r, const char *file, int line) { if (!h || !r) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (*r) { #if defined (POINTER_DEBUG) log_error ("%s(%d): reference store into non-null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } *r = h; @@ -883,14 +883,14 @@ isc_result_t omapi_typed_data_dereference (omapi_typed_data_t **h, const char *file, int line) { if (!h) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!*h) { #if defined (POINTER_DEBUG) log_error ("%s(%d): dereference of null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -904,7 +904,7 @@ isc_result_t omapi_typed_data_dereference (omapi_typed_data_t **h, abort (); #else *h = 0; - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -936,7 +936,7 @@ isc_result_t omapi_data_string_new (omapi_data_string_t **d, unsigned len, nlen = OMAPI_DATA_STRING_EMPTY_SIZE + len; if (nlen < len) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; new = dmalloc (nlen, file, line); if (!new) return ISC_R_NOMEMORY; @@ -950,14 +950,14 @@ isc_result_t omapi_data_string_reference (omapi_data_string_t **r, const char *file, int line) { if (!h || !r) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (*r) { #if defined (POINTER_DEBUG) log_error ("%s(%d): reference store into non-null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } *r = h; @@ -970,14 +970,14 @@ isc_result_t omapi_data_string_dereference (omapi_data_string_t **h, const char *file, int line) { if (!h) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!*h) { #if defined (POINTER_DEBUG) log_error ("%s(%d): dereference of null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -991,7 +991,7 @@ isc_result_t omapi_data_string_dereference (omapi_data_string_t **h, abort (); #else *h = 0; - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -1021,7 +1021,7 @@ isc_result_t omapi_value_reference (omapi_value_t **r, const char *file, int line) { if (!h || !r) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (*r) { #if defined (POINTER_DEBUG) @@ -1029,7 +1029,7 @@ isc_result_t omapi_value_reference (omapi_value_t **r, file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } *r = h; @@ -1042,14 +1042,14 @@ isc_result_t omapi_value_dereference (omapi_value_t **h, const char *file, int line) { if (!h) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!*h) { #if defined (POINTER_DEBUG) log_error ("%s(%d): dereference of null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -1063,7 +1063,7 @@ isc_result_t omapi_value_dereference (omapi_value_t **h, abort (); #else *h = 0; - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -1103,7 +1103,7 @@ isc_result_t omapi_addr_list_reference (omapi_addr_list_t **r, const char *file, int line) { if (!h || !r) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (*r) { #if defined (POINTER_DEBUG) @@ -1111,7 +1111,7 @@ isc_result_t omapi_addr_list_reference (omapi_addr_list_t **r, file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } *r = h; @@ -1124,14 +1124,14 @@ isc_result_t omapi_addr_list_dereference (omapi_addr_list_t **h, const char *file, int line) { if (!h) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!*h) { #if defined (POINTER_DEBUG) log_error ("%s(%d): dereference of null pointer!", file, line); abort (); #else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } @@ -1145,7 +1145,7 @@ isc_result_t omapi_addr_list_dereference (omapi_addr_list_t **h, abort (); #else *h = 0; - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #endif } diff --git a/omapip/array.c b/omapip/array.c index f361b110..f42993ae 100644 --- a/omapip/array.c +++ b/omapip/array.c @@ -46,7 +46,7 @@ isc_result_t omapi_array_allocate (omapi_array_t **array, omapi_array_t *aptr; if (!array || *array) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; aptr = dmalloc (sizeof (omapi_array_t),file, line); if (!aptr) return ISC_R_NOMEMORY; @@ -63,7 +63,7 @@ isc_result_t omapi_array_free (omapi_array_t **array, int i; if (!array || !*array) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; aptr = *array; for (i = 0; i < aptr -> count; i++) if (aptr -> data [i] && aptr -> deref) @@ -98,11 +98,11 @@ isc_result_t omapi_array_set (omapi_array_t *array, void *ptr, int index, isc_result_t status; if (!array) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!ptr) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (index < 0) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; /* If the proposed index is larger than the current available space in the array, make more space in the array. */ @@ -153,7 +153,7 @@ isc_result_t omapi_array_lookup (char **ptr, omapi_array_t *array, int index, const char *file, int line) { if (!array || !ptr || *ptr || index < 0 || index >= array -> count) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (array -> data [index]) return (*array -> ref) (ptr, array -> data [index], file, line); diff --git a/omapip/auth.c b/omapip/auth.c index 021b5a62..2f0b430c 100644 --- a/omapip/auth.c +++ b/omapip/auth.c @@ -57,19 +57,21 @@ isc_result_t omapi_auth_key_destroy (omapi_object_t *h, { omapi_auth_key_t *a; - if (h -> type != omapi_type_auth_key) - return ISC_R_INVALIDARG; + if (h->type != omapi_type_auth_key) + return DHCP_R_INVALIDARG; a = (omapi_auth_key_t *)h; - if (auth_key_hash) - omapi_auth_key_hash_delete (auth_key_hash, a -> name, 0, MDL); - - if (a -> name) - dfree (a -> name, MDL); - if (a -> algorithm) - dfree (a -> algorithm, MDL); - if (a -> key) - omapi_data_string_dereference (&a -> key, MDL); + if (auth_key_hash != NULL) + omapi_auth_key_hash_delete(auth_key_hash, a->name, 0, MDL); + + if (a->name != NULL) + dfree(a->name, MDL); + if (a->algorithm != NULL) + dfree(a->algorithm, MDL); + if (a->key != NULL) + omapi_data_string_dereference(&a->key, MDL); + if (a->tsec_key != NULL) + dns_tsec_destroy(&a->tsec_key); return ISC_R_SUCCESS; } @@ -77,9 +79,11 @@ isc_result_t omapi_auth_key_destroy (omapi_object_t *h, isc_result_t omapi_auth_key_enter (omapi_auth_key_t *a) { omapi_auth_key_t *tk; + isc_result_t status; + dst_key_t *dstkey; if (a -> type != omapi_type_auth_key) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; tk = (omapi_auth_key_t *)0; if (auth_key_hash) { @@ -99,9 +103,28 @@ isc_result_t omapi_auth_key_enter (omapi_auth_key_t *a) KEY_HASH_SIZE, MDL)) return ISC_R_NOMEMORY; } + + /* + * If possible create a tsec structure for this key, + * if we can't create the structure we put out a warning + * and continue. + */ + status = isclib_make_dst_key(a->name, a->algorithm, + a->key->value, a->key->len, + &dstkey); + if (status == ISC_R_SUCCESS) { + status = dns_tsec_create(dhcp_gbl_ctx.mctx, dns_tsectype_tsig, + dstkey, &a->tsec_key); + } + if (status != ISC_R_SUCCESS) { + if (dstkey != NULL) { + dst_key_free(&dstkey); + } + log_error("Unable to create tsec structure for %s", a->name); + } + omapi_auth_key_hash_add (auth_key_hash, a -> name, 0, a, MDL); return ISC_R_SUCCESS; - } isc_result_t omapi_auth_key_lookup_name (omapi_auth_key_t **a, @@ -126,7 +149,7 @@ isc_result_t omapi_auth_key_lookup (omapi_object_t **h, return ISC_R_NOTFOUND; if (!ref) - return ISC_R_NOKEYS; + return DHCP_R_NOKEYS; status = omapi_get_value_str (ref, id, "name", &name); if (status != ISC_R_SUCCESS) @@ -183,7 +206,7 @@ isc_result_t omapi_auth_key_stuff_values (omapi_object_t *c, isc_result_t status; if (h -> type != omapi_type_auth_key) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; a = (omapi_auth_key_t *)h; /* Write only the name and algorithm -- not the secret! */ diff --git a/omapip/buffer.c b/omapip/buffer.c index 1a47a181..1d6ee63a 100644 --- a/omapip/buffer.c +++ b/omapip/buffer.c @@ -154,7 +154,7 @@ static isc_result_t omapi_connection_reader_trace (omapi_object_t *h, unsigned bytes_to_read; if (!h || h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; /* See if there are enough bytes. */ @@ -216,7 +216,7 @@ static isc_result_t omapi_connection_reader_trace (omapi_object_t *h, else if (errno == EIO) return ISC_R_IOERROR; else if (errno == EINVAL) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; else if (errno == ECONNRESET) { omapi_disconnect (h, 1); return ISC_R_SHUTTINGDOWN; @@ -281,9 +281,9 @@ isc_result_t omapi_connection_copyin (omapi_object_t *h, /* Make sure len is valid. */ if (len < 0) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!h || h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; /* If the connection is closed, return an error if the caller @@ -299,7 +299,7 @@ isc_result_t omapi_connection_copyin (omapi_object_t *h, } else { status = omapi_buffer_new (&c -> outbufs, MDL); if (status != ISC_R_SUCCESS) - return status; + goto leave; buffer = c -> outbufs; } @@ -309,7 +309,7 @@ isc_result_t omapi_connection_copyin (omapi_object_t *h, if (!BUFFER_BYTES_FREE (buffer)) { status = (omapi_buffer_new (&buffer -> next, MDL)); if (status != ISC_R_SUCCESS) - return status; + goto leave; buffer = buffer -> next; } @@ -329,7 +329,7 @@ isc_result_t omapi_connection_copyin (omapi_object_t *h, &bufp [bytes_copied], copy_len, (omapi_typed_data_t **)0); if (status != ISC_R_SUCCESS) - return status; + goto leave; } memcpy (&buffer -> buf [buffer -> tail], @@ -340,7 +340,25 @@ isc_result_t omapi_connection_copyin (omapi_object_t *h, if (buffer -> tail == sizeof buffer -> buf) buffer -> tail = 0; } - return ISC_R_SUCCESS; + + status = ISC_R_SUCCESS; + + leave: + /* + * If we have any bytes to send and we have a proper io object + * inform the socket code that we would like to know when we + * can send more bytes. + */ + if (c->out_bytes != 0) { + if ((c->outer != NULL) && + (c->outer->type == omapi_type_io_object)) { + omapi_io_object_t *io = (omapi_io_object_t *)c->outer; + isc_socket_fdwatchpoke(io->fd, + ISC_SOCKFDWATCH_WRITE); + } + } + + return (status); } /* Copy some bytes from the input buffer, and advance the input buffer @@ -360,7 +378,7 @@ isc_result_t omapi_connection_copyout (unsigned char *buf, isc_result_t status; if (!h || h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; if (size > c -> in_bytes) @@ -444,7 +462,7 @@ isc_result_t omapi_connection_writer (omapi_object_t *h) omapi_connection_object_t *c; if (!h || h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; /* Already flushed... */ @@ -478,7 +496,7 @@ isc_result_t omapi_connection_writer (omapi_object_t *h) are really errors. */ if (bytes_written < 0) { if (errno == EWOULDBLOCK || errno == EAGAIN) - return ISC_R_SUCCESS; + return ISC_R_INPROGRESS; else if (errno == EPIPE) return ISC_R_NOCONN; #ifdef EDQUOT @@ -492,14 +510,14 @@ isc_result_t omapi_connection_writer (omapi_object_t *h) else if (errno == EIO) return ISC_R_IOERROR; else if (errno == EINVAL) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; else if (errno == ECONNRESET) return ISC_R_SHUTTINGDOWN; else return ISC_R_UNEXPECTED; } if (bytes_written == 0) - return ISC_R_SUCCESS; + return ISC_R_INPROGRESS; #if defined (TRACING) if (trace_record ()) { @@ -533,7 +551,7 @@ isc_result_t omapi_connection_writer (omapi_object_t *h) O.S. output buffer and a further write would block, so stop trying to flush now. */ if (bytes_written != bytes_this_write) - return ISC_R_SUCCESS; + return ISC_R_INPROGRESS; } if (!BYTES_IN_BUFFER (buffer)) @@ -653,7 +671,7 @@ isc_result_t omapi_connection_write_typed_data (omapi_object_t *c, return omapi_connection_put_uint32 (c, handle); } - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } isc_result_t omapi_connection_put_name (omapi_object_t *c, const char *name) diff --git a/omapip/connection.c b/omapip/connection.c index e9289643..b32ee748 100644 --- a/omapip/connection.c +++ b/omapip/connection.c @@ -39,7 +39,6 @@ #include <arpa/nameser.h> #include <errno.h> - #if defined (TRACING) static void trace_connect_input (trace_type_t *, unsigned, char *); static void trace_connect_stop (trace_type_t *); @@ -73,11 +72,11 @@ isc_result_t omapi_connect (omapi_object_t *c, name. It's okay for this call to block. */ he = gethostbyname (server_name); if (!he) - return ISC_R_HOSTUNKNOWN; + return DHCP_R_HOSTUNKNOWN; for (i = 0; he -> h_addr_list [i]; i++) ; if (i == 0) - return ISC_R_HOSTUNKNOWN; + return DHCP_R_HOSTUNKNOWN; hix = i; status = omapi_addr_list_new (&addrs, hix, MDL); @@ -158,7 +157,7 @@ isc_result_t omapi_connect_list (omapi_object_t *c, /* Only do TCPv4 so far. */ if (local_addr -> addrtype != AF_INET) { omapi_connection_dereference (&obj, MDL); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } local_sin.sin_port = htons (local_addr -> port); memcpy (&local_sin.sin_addr, @@ -444,7 +443,7 @@ isc_result_t omapi_disconnect (omapi_object_t *h, c = (omapi_connection_object_t *)h; if (c -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #if defined (TRACING) if (trace_record ()) { @@ -488,12 +487,27 @@ isc_result_t omapi_disconnect (omapi_object_t *h, #endif c -> state = omapi_connection_closed; +#if 0 + /* + * Disconnecting from the I/O object seems incorrect as it doesn't + * cause the I/O object to be cleaned and released. Previous to + * using the isc socket library this wouldn't have caused a problem + * with the socket library we would have a reference to a closed + * socket. Instead we now do an unregister to properly free the + * I/O object. + */ + /* Disconnect from I/O object, if any. */ if (h -> outer) { if (h -> outer -> inner) omapi_object_dereference (&h -> outer -> inner, MDL); omapi_object_dereference (&h -> outer, MDL); } +#else + if (h->outer) { + omapi_unregister_io_object(h); + } +#endif /* If whatever created us registered a signal handler, send it a disconnect signal. */ @@ -528,20 +542,18 @@ isc_result_t omapi_connection_require (omapi_object_t *h, unsigned bytes) omapi_connection_object_t *c; if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; c -> bytes_needed = bytes; if (c -> bytes_needed <= c -> in_bytes) { return ISC_R_SUCCESS; } - return ISC_R_NOTYET; + return DHCP_R_NOTYET; } /* Return the socket on which the dispatcher should wait for readiness - to read, for a connection object. If we already have more bytes than - we need to do the next thing, and we have at least a single full input - buffer, then don't indicate that we're ready to read. */ + to read, for a connection object. */ int omapi_connection_readfd (omapi_object_t *h) { omapi_connection_object_t *c; @@ -550,27 +562,22 @@ int omapi_connection_readfd (omapi_object_t *h) c = (omapi_connection_object_t *)h; if (c -> state != omapi_connection_connected) return -1; - if (c -> in_bytes >= OMAPI_BUF_SIZE - 1 && - c -> in_bytes > c -> bytes_needed) - return -1; return c -> socket; } -/* Return the socket on which the dispatcher should wait for readiness - to write, for a connection object. If there are no bytes buffered - for writing, then don't indicate that we're ready to write. */ +/* + * Return the socket on which the dispatcher should wait for readiness + * to write, for a connection object. When bytes are buffered we should + * also poke the dispatcher to tell it to start or re-start watching the + * socket. + */ int omapi_connection_writefd (omapi_object_t *h) { omapi_connection_object_t *c; if (h -> type != omapi_type_connection) return -1; c = (omapi_connection_object_t *)h; - if (c -> state == omapi_connection_connecting) - return c -> socket; - if (c -> out_bytes) - return c -> socket; - else - return -1; + return c->socket; } isc_result_t omapi_connection_connect (omapi_object_t *h) @@ -591,7 +598,7 @@ static isc_result_t omapi_connection_connect_internal (omapi_object_t *h) isc_result_t status; if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; if (c -> state == omapi_connection_connecting) { @@ -625,7 +632,7 @@ static isc_result_t omapi_connection_connect_internal (omapi_object_t *h) if (c -> connect_list -> addresses [c -> cptr].addrtype != AF_INET) { omapi_disconnect (h, 1); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } memcpy (&c -> remote_addr.sin_addr, @@ -662,7 +669,7 @@ static isc_result_t omapi_connection_connect_internal (omapi_object_t *h) return status; } c -> state = omapi_connection_connecting; - return ISC_R_INCOMPLETE; + return DHCP_R_INCOMPLETE; } c -> state = omapi_connection_connected; } @@ -704,7 +711,7 @@ isc_result_t omapi_connection_reaper (omapi_object_t *h) omapi_connection_object_t *c; if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; if (c -> state == omapi_connection_disconnecting && @@ -723,11 +730,10 @@ isc_result_t omapi_connection_reaper (omapi_object_t *h) return ISC_R_SUCCESS; } -static isc_result_t make_dst_key (DST_KEY **dst_key, omapi_object_t *a) { +static isc_result_t make_dst_key (dst_key_t **dst_key, omapi_object_t *a) { omapi_value_t *name = (omapi_value_t *)0; omapi_value_t *algorithm = (omapi_value_t *)0; omapi_value_t *key = (omapi_value_t *)0; - int algorithm_id = UNKNOWN_KEYALG; char *name_str = NULL; isc_result_t status = ISC_R_SUCCESS; @@ -744,14 +750,12 @@ static isc_result_t make_dst_key (DST_KEY **dst_key, omapi_object_t *a) { (a, (omapi_object_t *)0, "key", &key); if (status == ISC_R_SUCCESS) { - if ((algorithm -> value -> type == omapi_datatype_data || - algorithm -> value -> type == omapi_datatype_string) && - strncasecmp ((char *)algorithm -> value -> u.buffer.value, - NS_TSIG_ALG_HMAC_MD5 ".", - algorithm -> value -> u.buffer.len) == 0) { - algorithm_id = KEY_HMAC_MD5; - } else { - status = ISC_R_INVALIDARG; + if ((algorithm->value->type != omapi_datatype_data && + algorithm->value->type != omapi_datatype_string) || + strncasecmp((char *)algorithm->value->u.buffer.value, + NS_TSIG_ALG_HMAC_MD5 ".", + algorithm->value->u.buffer.len) != 0) { + status = DHCP_R_INVALIDARG; } } @@ -767,10 +771,13 @@ static isc_result_t make_dst_key (DST_KEY **dst_key, omapi_object_t *a) { name -> value -> u.buffer.len); name_str [name -> value -> u.buffer.len] = 0; - *dst_key = dst_buffer_to_key (name_str, algorithm_id, 0, 0, - key -> value -> u.buffer.value, - key -> value -> u.buffer.len); - if (!*dst_key) + status = isclib_make_dst_key(name_str, + DHCP_HMAC_MD5_NAME, + key->value->u.buffer.value, + key->value->u.buffer.len, + dst_key); + + if (*dst_key == NULL) status = ISC_R_NOMEMORY; } @@ -787,7 +794,7 @@ static isc_result_t make_dst_key (DST_KEY **dst_key, omapi_object_t *a) { } isc_result_t omapi_connection_sign_data (int mode, - DST_KEY *key, + dst_key_t *key, void **context, const unsigned char *data, const unsigned len, @@ -795,37 +802,62 @@ isc_result_t omapi_connection_sign_data (int mode, { omapi_typed_data_t *td = (omapi_typed_data_t *)0; isc_result_t status; - int r; + dst_context_t **dctx = (dst_context_t **)context; + /* Create the context for the dst module */ + if (mode & SIG_MODE_INIT) { + status = dst_context_create(key, dhcp_gbl_ctx.mctx, dctx); + if (status != ISC_R_SUCCESS) { + return status; + } + } + + /* If we have any data add it to the context */ + if (len != 0) { + isc_region_t region; + region.base = (unsigned char *)data; + region.length = len; + dst_context_adddata(*dctx, ®ion); + } + + /* Finish the signature and clean up the context */ if (mode & SIG_MODE_FINAL) { + unsigned int sigsize; + isc_buffer_t sigbuf; + + status = dst_key_sigsize(key, &sigsize); + if (status != ISC_R_SUCCESS) { + goto cleanup; + } + status = omapi_typed_data_new (MDL, &td, omapi_datatype_data, - dst_sig_size (key)); - if (status != ISC_R_SUCCESS) - return status; - } + sigsize); + if (status != ISC_R_SUCCESS) { + goto cleanup; + } - r = dst_sign_data (mode, key, context, data, len, - td ? td -> u.buffer.value : (u_char *)0, - td ? td -> u.buffer.len : 0); + isc_buffer_init(&sigbuf, td->u.buffer.value, td->u.buffer.len); + status = dst_context_sign(*dctx, &sigbuf); + if (status != ISC_R_SUCCESS) { + goto cleanup; + } - /* dst_sign_data() really should do this for us, shouldn't it? */ - if (mode & SIG_MODE_FINAL) - *context = (void *)0; + if (result) { + omapi_typed_data_reference (result, td, MDL); + } - if (r < 0) { - if (td) + cleanup: + /* We are done with the context and the td. On success + * the td is now referenced from result, on failure we + * don't need it any more */ + if (td) { omapi_typed_data_dereference (&td, MDL); - return ISC_R_INVALIDKEY; - } - - if (result && td) { - omapi_typed_data_reference (result, td, MDL); + } + dst_context_destroy(dctx); + return status; } - if (td) - omapi_typed_data_dereference (&td, MDL); - return ISC_R_SUCCESS; } @@ -834,15 +866,14 @@ isc_result_t omapi_connection_output_auth_length (omapi_object_t *h, { omapi_connection_object_t *c; - if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + if (h->type != omapi_type_connection) + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; - if (!c -> out_key) + if (c->out_key == NULL) return ISC_R_NOTFOUND; - *l = dst_sig_size (c -> out_key); - return ISC_R_SUCCESS; + return(dst_key_sigsize(c->out_key, l)); } isc_result_t omapi_connection_set_value (omapi_object_t *h, @@ -854,12 +885,12 @@ isc_result_t omapi_connection_set_value (omapi_object_t *h, isc_result_t status; if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; if (omapi_ds_strcmp (name, "input-authenticator") == 0) { if (value && value -> type != omapi_datatype_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (c -> in_context) { omapi_connection_sign_data (SIG_MODE_FINAL, @@ -869,9 +900,8 @@ isc_result_t omapi_connection_set_value (omapi_object_t *h, (omapi_typed_data_t **) 0); } - if (c -> in_key) { - dst_free_key (c -> in_key); - c -> in_key = (DST_KEY *)0; + if (c->in_key != NULL) { + dst_key_free(&c->in_key); } if (value) { @@ -885,7 +915,7 @@ isc_result_t omapi_connection_set_value (omapi_object_t *h, } else if (omapi_ds_strcmp (name, "output-authenticator") == 0) { if (value && value -> type != omapi_datatype_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (c -> out_context) { omapi_connection_sign_data (SIG_MODE_FINAL, @@ -895,9 +925,8 @@ isc_result_t omapi_connection_set_value (omapi_object_t *h, (omapi_typed_data_t **) 0); } - if (c -> out_key) { - dst_free_key (c -> out_key); - c -> out_key = (DST_KEY *)0; + if (c->out_key != NULL) { + dst_key_free(&c->out_key); } if (value) { @@ -924,9 +953,10 @@ isc_result_t omapi_connection_get_value (omapi_object_t *h, omapi_connection_object_t *c; omapi_typed_data_t *td = (omapi_typed_data_t *)0; isc_result_t status; + unsigned int sigsize; if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; if (omapi_ds_strcmp (name, "input-signature") == 0) { @@ -945,11 +975,15 @@ isc_result_t omapi_connection_get_value (omapi_object_t *h, return status; } else if (omapi_ds_strcmp (name, "input-signature-size") == 0) { - if (!c -> in_key) + if (c->in_key == NULL) return ISC_R_NOTFOUND; - return omapi_make_int_value (value, name, - dst_sig_size (c -> in_key), MDL); + status = dst_key_sigsize(c->in_key, &sigsize); + if (status != ISC_R_SUCCESS) { + return(status); + } + + return omapi_make_int_value(value, name, sigsize, MDL); } else if (omapi_ds_strcmp (name, "output-signature") == 0) { if (!c -> out_key || !c -> out_context) @@ -967,11 +1001,16 @@ isc_result_t omapi_connection_get_value (omapi_object_t *h, return status; } else if (omapi_ds_strcmp (name, "output-signature-size") == 0) { - if (!c -> out_key) + if (c->out_key == NULL) return ISC_R_NOTFOUND; - return omapi_make_int_value (value, name, - dst_sig_size (c -> out_key), MDL); + + status = dst_key_sigsize(c->out_key, &sigsize); + if (status != ISC_R_SUCCESS) { + return(status); + } + + return omapi_make_int_value(value, name, sigsize, MDL); } if (h -> inner && h -> inner -> type -> get_value) @@ -1005,7 +1044,7 @@ isc_result_t omapi_connection_signal_handler (omapi_object_t *h, const char *name, va_list ap) { if (h -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; #ifdef DEBUG_PROTOCOL log_debug ("omapi_connection_signal_handler(%s)", name); @@ -1025,7 +1064,7 @@ isc_result_t omapi_connection_stuff_values (omapi_object_t *c, omapi_object_t *m) { if (m -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (m -> inner && m -> inner -> type -> stuff_values) return (*(m -> inner -> type -> stuff_values)) (c, id, diff --git a/omapip/dispatch.c b/omapip/dispatch.c index 9e3fb8ae..887a337b 100644 --- a/omapip/dispatch.c +++ b/omapip/dispatch.c @@ -104,6 +104,60 @@ trigger_event(struct eventqueue **queue) } } +/* + * Callback routine to connect the omapi I/O object and socket with + * the isc socket code. The isc socket code will call this routine + * which will then call the correct local routine to process the bytes. + * + * Currently we are always willing to read more data, this should be modified + * so that on connections we don't read more if we already have enough. + * + * If we have more bytes to write we ask the library to call us when + * we can write more. If we indicate we don't have more to write we need + * to poke the library via isc_socket_fdwatchpoke. + */ +int +omapi_iscsock_cb(isc_task_t *task, + isc_socket_t *socket, + void *cbarg, + int flags) +{ + omapi_io_object_t *obj; + isc_result_t status; + + /* Get the current time... */ + gettimeofday (&cur_tv, (struct timezone *)0); + + /* Not much to be done if we have the wrong type of object. */ + if (((omapi_object_t *)cbarg) -> type != omapi_type_io_object) { + log_fatal ("Incorrect object type, must be of type io_object"); + } + obj = (omapi_io_object_t *)cbarg; + + if ((flags == ISC_SOCKFDWATCH_READ) && + (obj->reader != NULL) && + (obj->inner != NULL)) { + obj->reader(obj->inner); + /* We always ask for more when reading */ + return (1); + } else if ((flags == ISC_SOCKFDWATCH_WRITE) && + (obj->writer != NULL) && + (obj->inner != NULL)) { + status = obj->writer(obj->inner); + /* If the writer has more to write they should return + * ISC_R_INPROGRESS */ + if (status == ISC_R_INPROGRESS) { + return (1); + } + } + + /* + * We get here if we either had an error (inconsistent + * structures etc) or no more to write, tell the socket + * lib we don't have more to do right now. + */ + return (0); +} /* Register an I/O handle so that we can do asynchronous I/O on it. */ @@ -119,6 +173,7 @@ isc_result_t omapi_register_io_object (omapi_object_t *h, { isc_result_t status; omapi_io_object_t *obj, *p; + int fd_flags = 0, fd = 0; /* omapi_io_states is a static object. If its reference count is zero, this is the first I/O handle to be registered, so @@ -148,6 +203,43 @@ isc_result_t omapi_register_io_object (omapi_object_t *h, return status; } + /* + * Attach the I/O object to the isc socket library via the + * fdwatch function. This allows the socket library to watch + * over a socket that we built. If there are both a read and + * a write socket we asssume they are the same socket. + */ + + if (readfd) { + fd_flags |= ISC_SOCKFDWATCH_READ; + fd = readfd(h); + } + + if (writefd) { + fd_flags |= ISC_SOCKFDWATCH_WRITE; + fd = writefd(h); + } + + if (fd_flags != 0) { + status = isc_socket_fdwatchcreate(dhcp_gbl_ctx.socketmgr, + fd, fd_flags, + omapi_iscsock_cb, + obj, + dhcp_gbl_ctx.task, + &obj->fd); + if (status != ISC_R_SUCCESS) { + log_error("Unable to register fd with library %s", + isc_result_totext(status)); + + /*sar*/ + /* is this the cleanup we need? */ + omapi_object_dereference(&h->outer, MDL); + omapi_io_dereference (&obj, MDL); + return (status); + } + } + + /* Find the last I/O state, if there are any. */ for (p = omapi_io_states.next; p && p -> next; p = p -> next) @@ -216,7 +308,7 @@ isc_result_t omapi_unregister_io_object (omapi_object_t *h) omapi_io_object_t *p, *obj, *last, *ph; if (!h -> outer || h -> outer -> type != omapi_type_io_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; obj = (omapi_io_object_t *)h -> outer; ph = (omapi_io_object_t *)0; omapi_io_reference (&ph, obj, MDL); @@ -242,6 +334,12 @@ isc_result_t omapi_unregister_io_object (omapi_object_t *h) } omapi_object_dereference (&obj -> inner, MDL); omapi_object_dereference (&h -> outer, MDL); + + /* remove isc socket associations */ + if (obj->fd != NULL) { + isc_socket_detach(&obj->fd); + } + omapi_io_dereference (&ph, MDL); return ISC_R_SUCCESS; } @@ -577,7 +675,6 @@ isc_result_t omapi_one_dispatch (omapi_object_t *wo, omapi_io_dereference(&prev, MDL); } omapi_io_reference(&prev, io, MDL); - } /* @@ -608,7 +705,7 @@ isc_result_t omapi_io_set_value (omapi_object_t *h, omapi_typed_data_t *value) { if (h -> type != omapi_type_io_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> set_value) return (*(h -> inner -> type -> set_value)) @@ -622,7 +719,7 @@ isc_result_t omapi_io_get_value (omapi_object_t *h, omapi_value_t **value) { if (h -> type != omapi_type_io_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> get_value) return (*(h -> inner -> type -> get_value)) @@ -643,7 +740,7 @@ isc_result_t omapi_io_destroy (omapi_object_t *h, const char *file, int line) omapi_io_object_t *obj = NULL, *p, *last = NULL, **holder; if (h -> type != omapi_type_io_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; /* remove from the list of I/O states */ for (p = omapi_io_states.next; p; p = p -> next) { @@ -674,7 +771,7 @@ isc_result_t omapi_io_signal_handler (omapi_object_t *h, const char *name, va_list ap) { if (h -> type != omapi_type_io_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> signal_handler) return (*(h -> inner -> type -> signal_handler)) (h -> inner, @@ -687,7 +784,7 @@ isc_result_t omapi_io_stuff_values (omapi_object_t *c, omapi_object_t *i) { if (i -> type != omapi_type_io_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (i -> inner && i -> inner -> type -> stuff_values) return (*(i -> inner -> type -> stuff_values)) (c, id, @@ -701,7 +798,7 @@ isc_result_t omapi_waiter_signal_handler (omapi_object_t *h, omapi_waiter_object_t *waiter; if (h -> type != omapi_type_waiter) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!strcmp (name, "ready")) { waiter = (omapi_waiter_object_t *)h; @@ -710,17 +807,17 @@ isc_result_t omapi_waiter_signal_handler (omapi_object_t *h, return ISC_R_SUCCESS; } - if (!strcmp (name, "status")) { + if (!strcmp(name, "status")) { waiter = (omapi_waiter_object_t *)h; - waiter -> ready = 1; - waiter -> waitstatus = va_arg (ap, isc_result_t); + waiter->ready = 1; + waiter->waitstatus = va_arg(ap, isc_result_t); return ISC_R_SUCCESS; } if (!strcmp (name, "disconnect")) { waiter = (omapi_waiter_object_t *)h; waiter -> ready = 1; - waiter -> waitstatus = ISC_R_CONNRESET; + waiter -> waitstatus = DHCP_R_CONNRESET; return ISC_R_SUCCESS; } diff --git a/omapip/generic.c b/omapip/generic.c index da3c9d7c..bd18f337 100644 --- a/omapip/generic.c +++ b/omapip/generic.c @@ -61,7 +61,7 @@ isc_result_t omapi_generic_set_value (omapi_object_t *h, isc_result_t status; if (h -> type != omapi_type_generic) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; g = (omapi_generic_object_t *)h; /* See if there's already a value with this name attached to @@ -177,7 +177,7 @@ isc_result_t omapi_generic_get_value (omapi_object_t *h, omapi_generic_object_t *g; if (h -> type != omapi_type_generic) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; g = (omapi_generic_object_t *)h; /* Look up the specified name in our list of objects. */ @@ -232,7 +232,7 @@ isc_result_t omapi_generic_signal_handler (omapi_object_t *h, const char *name, va_list ap) { if (h -> type != omapi_type_generic) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> signal_handler) return (*(h -> inner -> type -> signal_handler)) (h -> inner, @@ -252,7 +252,7 @@ isc_result_t omapi_generic_stuff_values (omapi_object_t *c, isc_result_t status; if (g -> type != omapi_type_generic) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; src = (omapi_generic_object_t *)g; for (i = 0; i < src -> nvalues; i++) { @@ -292,7 +292,7 @@ isc_result_t omapi_generic_clear_flags (omapi_object_t *o) omapi_generic_object_t *g; if (o -> type != omapi_type_generic) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; g = (omapi_generic_object_t *)o; for (i = 0; i < g -> nvalues; i++) { diff --git a/omapip/handle.c b/omapip/handle.c index a65c3e4b..b7e72ca7 100644 --- a/omapip/handle.c +++ b/omapip/handle.c @@ -290,6 +290,6 @@ isc_result_t omapi_handle_td_lookup (omapi_object_t **obj, memcpy (&h, handle -> u.buffer.value, sizeof h); h = ntohl (h); } else - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; return omapi_handle_lookup (obj, h); } diff --git a/omapip/isclib.c b/omapip/isclib.c new file mode 100644 index 00000000..f4cb46a6 --- /dev/null +++ b/omapip/isclib.c @@ -0,0 +1,230 @@ +/* + * Copyright(c) 2009 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/ + * + */ + +/*Trying to figure out what we need to define to get things to work. + It looks like we want/need the export library but need the fdwatchcommand + which may be a problem */ + +#include "dhcpd.h" + +dhcp_context_t dhcp_gbl_ctx; + +void +isclib_cleanup(void) +{ +#if defined (NSUPDATE) + if (dhcp_gbl_ctx.dnsclient != NULL) + dns_client_destroy((dns_client_t **)&dhcp_gbl_ctx.dnsclient); +#endif + + if (dhcp_gbl_ctx.task != NULL) { +// isc_task_destroy(&dhcp_gbl_ctx.task); + isc_task_shutdown(dhcp_gbl_ctx.task); + isc_task_detach(&dhcp_gbl_ctx.task); + } + + if (dhcp_gbl_ctx.timermgr != NULL) + isc_timermgr_destroy(&dhcp_gbl_ctx.timermgr); + + if (dhcp_gbl_ctx.socketmgr != NULL) + isc_socketmgr_destroy(&dhcp_gbl_ctx.socketmgr); + + if (dhcp_gbl_ctx.taskmgr != NULL) + isc_taskmgr_destroy(&dhcp_gbl_ctx.taskmgr); + + if (dhcp_gbl_ctx.actx_started != ISC_FALSE) { + isc_app_ctxfinish(dhcp_gbl_ctx.actx); + dhcp_gbl_ctx.actx_started = ISC_FALSE; + } + + if (dhcp_gbl_ctx.actx != NULL) + isc_appctx_destroy(&dhcp_gbl_ctx.actx); + + if (dhcp_gbl_ctx.mctx != NULL) + isc_mem_detach(&dhcp_gbl_ctx.mctx); + + return; +} + +isc_result_t +dhcp_context_create(void) { + isc_result_t result; + + /* + * Set up the error messages, this isn't the right place + * for this call but it is convienent for now. + */ + result = dhcp_result_register(); + if (result != ISC_R_SUCCESS) { + log_fatal("register_table() %s: %u", "failed", result); + } + + memset(&dhcp_gbl_ctx, 0, sizeof (dhcp_gbl_ctx)); + + isc_lib_register(); + + /* get the current time for use as the random seed */ + gettimeofday(&cur_tv, (struct timezone *)0); + isc_random_seed(cur_tv.tv_sec); + +#if defined (NSUPDATE) + result = dns_lib_init(); + if (result != ISC_R_SUCCESS) + goto cleanup; +#endif + + result = isc_mem_create(0, 0, &dhcp_gbl_ctx.mctx); + if (result != ISC_R_SUCCESS) + goto cleanup; + + result = isc_appctx_create(dhcp_gbl_ctx.mctx, &dhcp_gbl_ctx.actx); + if (result != ISC_R_SUCCESS) + goto cleanup; + + result = isc_app_ctxstart(dhcp_gbl_ctx.actx); + if (result != ISC_R_SUCCESS) + return (result); + dhcp_gbl_ctx.actx_started = ISC_TRUE; + + result = isc_taskmgr_createinctx(dhcp_gbl_ctx.mctx, + dhcp_gbl_ctx.actx, + 1, 0, + &dhcp_gbl_ctx.taskmgr); + if (result != ISC_R_SUCCESS) + goto cleanup; + + result = isc_socketmgr_createinctx(dhcp_gbl_ctx.mctx, + dhcp_gbl_ctx.actx, + &dhcp_gbl_ctx.socketmgr); + if (result != ISC_R_SUCCESS) + goto cleanup; + + result = isc_timermgr_createinctx(dhcp_gbl_ctx.mctx, + dhcp_gbl_ctx.actx, + &dhcp_gbl_ctx.timermgr); + if (result != ISC_R_SUCCESS) + goto cleanup; + + result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0, &dhcp_gbl_ctx.task); + if (result != ISC_R_SUCCESS) + goto cleanup; + +#if defined (NSUPDATE) + result = dns_client_createx(dhcp_gbl_ctx.mctx, + dhcp_gbl_ctx.actx, + dhcp_gbl_ctx.taskmgr, + dhcp_gbl_ctx.socketmgr, + dhcp_gbl_ctx.timermgr, + 0, + &dhcp_gbl_ctx.dnsclient); + if (result != ISC_R_SUCCESS) + goto cleanup; +#else + /* The dst library is inited as part of dns_lib_init, we don't + * need it if NSUPDATE is enabled */ + result = dst_lib_init(dhcp_gbl_ctx.mctx, NULL, 0); + if (result != ISC_R_SUCCESS) + goto cleanup; + +#endif + return(ISC_R_SUCCESS); + + cleanup: + isclib_cleanup(); + + return(result); +} + +/* Convert a string name into the proper structure for the isc routines */ +isc_result_t +dhcp_isc_name(unsigned char *namestr, + dns_fixedname_t *namefix, + dns_name_t **name) +{ + size_t namelen; + isc_buffer_t b; + isc_result_t result; + + namelen = strlen((char *)namestr); + isc_buffer_init(&b, namestr, namelen); + isc_buffer_add(&b, namelen); + dns_fixedname_init(namefix); + *name = dns_fixedname_name(namefix); + result = dns_name_fromtext(*name, &b, NULL, 0, NULL); + isc_buffer_invalidate(&b); + return(result); +} + +isc_result_t +isclib_make_dst_key(char *inname, + char *algorithm, + unsigned char *secret, + int length, + dst_key_t **dstkey) +{ + isc_result_t result; + dns_name_t *name; + dns_fixedname_t name0; + isc_buffer_t b; + int namelen; + + isc_buffer_init(&b, secret, length); + isc_buffer_add(&b, length); + + /* We only support HMAC_MD5 currently */ + if (strcasecmp(algorithm, DHCP_HMAC_MD5_NAME) != 0) { + return(DHCP_R_INVALIDARG); + } + + /* + * Previously we allowed key names without a trailing '.' + * however the current dst code requires the names to end + * in a period. If the name doesn't have a trailing period + * add one before sending it to the dst code. + */ + namelen = strlen(inname); + if (inname[namelen-1] != '.') { + char *newname = NULL; + newname = (char *)dmalloc(namelen + 2, MDL); + if (newname == NULL) { + log_error("unable to allocate memory for key name"); + return(ISC_R_NOMEMORY); + } + strcpy(newname, inname); + newname[namelen] = '.'; + newname[namelen+1] = 0; + result = dhcp_isc_name((unsigned char *)newname, &name0, &name); + dfree(newname, MDL); + } else { + result = dhcp_isc_name((unsigned char *)inname, &name0, &name); + } + + if (result != ISC_R_SUCCESS) { + return(result); + } + + return(dst_key_frombuffer(name, DST_ALG_HMACMD5, DNS_KEYOWNER_ENTITY, + DNS_KEYPROTO_DNSSEC, dns_rdataclass_in, + &b, dhcp_gbl_ctx.mctx, dstkey)); +} + diff --git a/omapip/listener.c b/omapip/listener.c index 2d5c4fa2..3cdbec79 100644 --- a/omapip/listener.c +++ b/omapip/listener.c @@ -77,7 +77,7 @@ isc_result_t omapi_listen_addr (omapi_object_t *h, /* Currently only support IPv4 addresses. */ if (addr->addrtype != AF_INET) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; /* Get the handle. */ obj = (omapi_listener_object_t *)0; @@ -219,7 +219,7 @@ isc_result_t omapi_accept (omapi_object_t *h) int socket; if (h -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; listener = (omapi_listener_object_t *)h; /* Accept the connection. */ @@ -392,7 +392,7 @@ isc_result_t omapi_listener_configure_security (omapi_object_t *h, omapi_listener_object_t *l; if (h -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; l = (omapi_listener_object_t *)h; l -> verify_addr = verify_addr; @@ -406,7 +406,7 @@ isc_result_t omapi_listener_set_value (omapi_object_t *h, omapi_typed_data_t *value) { if (h -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> set_value) return (*(h -> inner -> type -> set_value)) @@ -420,7 +420,7 @@ isc_result_t omapi_listener_get_value (omapi_object_t *h, omapi_value_t **value) { if (h -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> get_value) return (*(h -> inner -> type -> get_value)) @@ -434,7 +434,7 @@ isc_result_t omapi_listener_destroy (omapi_object_t *h, omapi_listener_object_t *l; if (h -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; l = (omapi_listener_object_t *)h; #ifdef DEBUG_PROTOCOL @@ -452,7 +452,7 @@ isc_result_t omapi_listener_signal_handler (omapi_object_t *h, const char *name, va_list ap) { if (h -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> signal_handler) return (*(h -> inner -> type -> signal_handler)) (h -> inner, @@ -468,7 +468,7 @@ isc_result_t omapi_listener_stuff_values (omapi_object_t *c, omapi_object_t *l) { if (l -> type != omapi_type_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (l -> inner && l -> inner -> type -> stuff_values) return (*(l -> inner -> type -> stuff_values)) (c, id, diff --git a/omapip/message.c b/omapip/message.c index d1149583..6d8b88f3 100644 --- a/omapip/message.c +++ b/omapip/message.c @@ -91,7 +91,7 @@ isc_result_t omapi_message_set_value (omapi_object_t *h, isc_result_t status; if (h -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m = (omapi_message_object_t *)h; /* Can't set authlen. */ @@ -106,7 +106,7 @@ isc_result_t omapi_message_set_value (omapi_object_t *h, } else if (!omapi_ds_strcmp (name, "object")) { if (value -> type != omapi_datatype_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (m -> object) omapi_object_dereference (&m -> object, MDL); omapi_object_reference (&m -> object, value -> u.object, MDL); @@ -114,7 +114,7 @@ isc_result_t omapi_message_set_value (omapi_object_t *h, } else if (!omapi_ds_strcmp (name, "notify-object")) { if (value -> type != omapi_datatype_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (m -> notify_object) omapi_object_dereference (&m -> notify_object, MDL); omapi_object_reference (&m -> notify_object, @@ -124,35 +124,35 @@ isc_result_t omapi_message_set_value (omapi_object_t *h, /* Can set authid, but it has to be an integer. */ } else if (!omapi_ds_strcmp (name, "authid")) { if (value -> type != omapi_datatype_int) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m -> authid = value -> u.integer; return ISC_R_SUCCESS; /* Can set op, but it has to be an integer. */ } else if (!omapi_ds_strcmp (name, "op")) { if (value -> type != omapi_datatype_int) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m -> op = value -> u.integer; return ISC_R_SUCCESS; /* Handle also has to be an integer. */ } else if (!omapi_ds_strcmp (name, "handle")) { if (value -> type != omapi_datatype_int) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m -> h = value -> u.integer; return ISC_R_SUCCESS; /* Transaction ID has to be an integer. */ } else if (!omapi_ds_strcmp (name, "id")) { if (value -> type != omapi_datatype_int) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m -> id = value -> u.integer; return ISC_R_SUCCESS; /* Remote transaction ID has to be an integer. */ } else if (!omapi_ds_strcmp (name, "rid")) { if (value -> type != omapi_datatype_int) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m -> rid = value -> u.integer; return ISC_R_SUCCESS; } @@ -175,7 +175,7 @@ isc_result_t omapi_message_get_value (omapi_object_t *h, { omapi_message_object_t *m; if (h -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m = (omapi_message_object_t *)h; /* Look for values that are in the message data structure. */ @@ -213,7 +213,7 @@ isc_result_t omapi_message_destroy (omapi_object_t *h, { omapi_message_object_t *m; if (h -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m = (omapi_message_object_t *)h; if (m -> authenticator) { omapi_typed_data_dereference (&m -> authenticator, file, line); @@ -236,7 +236,7 @@ isc_result_t omapi_message_signal_handler (omapi_object_t *h, { omapi_message_object_t *m; if (h -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m = (omapi_message_object_t *)h; if (!strcmp (name, "status")) { @@ -262,7 +262,7 @@ isc_result_t omapi_message_stuff_values (omapi_object_t *c, omapi_object_t *m) { if (m -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (m -> inner && m -> inner -> type -> stuff_values) return (*(m -> inner -> type -> stuff_values)) (c, id, @@ -275,12 +275,12 @@ isc_result_t omapi_message_register (omapi_object_t *mo) omapi_message_object_t *m; if (mo -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m = (omapi_message_object_t *)mo; /* Already registered? */ if (m -> prev || m -> next || omapi_registered_messages == m) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (omapi_registered_messages) { omapi_object_reference @@ -304,12 +304,12 @@ isc_result_t omapi_message_unregister (omapi_object_t *mo) omapi_message_object_t *n; if (mo -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; m = (omapi_message_object_t *)mo; /* Not registered? */ if (!m -> prev && omapi_registered_messages != m) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; n = (omapi_message_object_t *)0; if (m -> next) { @@ -398,7 +398,7 @@ omapi_message_process_internal (omapi_object_t *mo, omapi_object_t *po) omapi_object_type_t *type; if (mo -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; message = (omapi_message_object_t *)mo; #ifdef DEBUG_PROTOCOL @@ -426,12 +426,12 @@ omapi_message_process_internal (omapi_object_t *mo, omapi_object_t *po) /* All messages must have an authenticator, with the exception of messages that are opening a new authenticator. */ - if (omapi_protocol_authenticated (po) && - !message -> id_object && - message -> op != OMAPI_OP_OPEN) { + if (omapi_protocol_authenticated(po) && + !message->id_object && + message->op != OMAPI_OP_OPEN) { return omapi_protocol_send_status - (po, message -> id_object, ISC_R_NOKEYS, - message -> id, "No authenticator on message"); + (po, message->id_object, DHCP_R_NOKEYS, + message->id, "No authenticator on message"); } } @@ -439,8 +439,8 @@ omapi_message_process_internal (omapi_object_t *mo, omapi_object_t *po) case OMAPI_OP_OPEN: if (m) { return omapi_protocol_send_status - (po, message -> id_object, ISC_R_INVALIDARG, - message -> id, "OPEN can't be a response"); + (po, message->id_object, DHCP_R_INVALIDARG, + message->id, "OPEN can't be a response"); } /* Get the type of the requested object, if one was @@ -462,12 +462,12 @@ omapi_message_process_internal (omapi_object_t *mo, omapi_object_t *po) /* If this object had no authenticator, the requested object must be an authenticator object. */ - if (omapi_protocol_authenticated (po) && - !message -> id_object && + if (omapi_protocol_authenticated(po) && + !message->id_object && type != omapi_type_auth_key) { return omapi_protocol_send_status - (po, message -> id_object, ISC_R_NOKEYS, - message -> id, "No authenticator on message"); + (po, message->id_object, DHCP_R_NOKEYS, + message->id, "No authenticator on message"); } /* Get the create flag. */ @@ -520,9 +520,9 @@ omapi_message_process_internal (omapi_object_t *mo, omapi_object_t *po) if (!type) { if (create) { return omapi_protocol_send_status - (po, message -> id_object, - ISC_R_INVALIDARG, - message -> id, + (po, message->id_object, + DHCP_R_INVALIDARG, + message->id, "type required on create"); } goto refresh; @@ -542,7 +542,7 @@ omapi_message_process_internal (omapi_object_t *mo, omapi_object_t *po) if (status != ISC_R_SUCCESS && status != ISC_R_NOTFOUND && - status != ISC_R_NOKEYS) { + status != DHCP_R_NOKEYS) { return omapi_protocol_send_status (po, message -> id_object, status, message -> id, diff --git a/omapip/mrtrace.c b/omapip/mrtrace.c index 23697440..57cf9157 100644 --- a/omapip/mrtrace.c +++ b/omapip/mrtrace.c @@ -33,7 +33,7 @@ #include "dhcpd.h" #include <omapip/omapip_p.h> -#include "minires/minires.h" +#include "minires.h" #include "arpa/nameser.h" #include <errno.h> @@ -83,6 +83,7 @@ void trace_mr_init () trace_mr_randomid_stop, MDL); } +#if 0 void trace_mr_statp_setup (res_state statp) { unsigned buflen = 0; @@ -142,6 +143,7 @@ void trace_mr_statp_setup (res_state statp) } } #endif +#endif ssize_t trace_mr_send (int fd, void *msg, size_t len, int flags) { diff --git a/omapip/protocol.c b/omapip/protocol.c index c3a66367..e34508d0 100644 --- a/omapip/protocol.c +++ b/omapip/protocol.c @@ -59,7 +59,7 @@ isc_result_t omapi_protocol_connect (omapi_object_t *h, return status; rstatus = omapi_connect ((omapi_object_t *)obj, server_name, port); - if (rstatus != ISC_R_SUCCESS && rstatus != ISC_R_INCOMPLETE) { + if (rstatus != ISC_R_SUCCESS && rstatus != DHCP_R_INCOMPLETE) { omapi_protocol_dereference (&obj, MDL); return rstatus; } @@ -95,7 +95,7 @@ isc_result_t omapi_protocol_connect (omapi_object_t *h, } obj -> insecure = 0; - rstatus = ISC_R_INCOMPLETE; + rstatus = DHCP_R_INCOMPLETE; } else { obj -> insecure = 1; #if 0 @@ -120,7 +120,7 @@ isc_result_t omapi_protocol_send_intro (omapi_object_t *h, #endif if (h -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)h; if (!h -> outer || h -> outer -> type != omapi_type_connection) @@ -139,7 +139,7 @@ isc_result_t omapi_protocol_send_intro (omapi_object_t *h, protocol input state machine. */ p -> state = omapi_protocol_intro_wait; status = omapi_connection_require (h -> outer, 8); - if (status != ISC_R_SUCCESS && status != ISC_R_NOTYET) + if (status != ISC_R_SUCCESS && status != DHCP_R_NOTYET) return status; /* Make up an initial transaction ID for this connection. */ @@ -167,9 +167,9 @@ isc_result_t omapi_protocol_send_message (omapi_object_t *po, if (po -> type != omapi_type_protocol || !po -> outer || po -> outer -> type != omapi_type_connection || mo -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (omo && omo -> type != omapi_type_message) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)po; c = (omapi_object_t *)(po -> outer); m = (omapi_message_object_t *)mo; @@ -192,7 +192,7 @@ isc_result_t omapi_protocol_send_message (omapi_object_t *po, } if (!ra) - return ISC_R_KEY_UNKNOWN; + return DHCP_R_KEY_UNKNOWN; } else if (p -> remote_auth_list) { ra = p -> default_auth; } else { @@ -433,7 +433,7 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, } if (!p -> outer || p -> outer -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; c = p -> outer; /* We get here because we requested that we be woken up after @@ -449,12 +449,12 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, /* We currently only support the current protocol version. */ if (p -> protocol_version != OMAPI_PROTOCOL_VERSION) { omapi_disconnect (c, 1); - return ISC_R_VERSIONMISMATCH; + return DHCP_R_VERSIONMISMATCH; } if (p -> header_size < sizeof (omapi_protocol_header_t)) { omapi_disconnect (c, 1); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } if (p -> default_auth) { @@ -722,7 +722,7 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, p -> message -> authenticator -> u.buffer.value, p -> message -> authlen) != 0))) { /* Invalid signature. */ - p -> verify_result = ISC_R_INVALIDKEY; + p->verify_result = DHCP_R_INVALIDKEY; } omapi_value_dereference (&signature, MDL); @@ -778,10 +778,10 @@ isc_result_t omapi_protocol_add_auth (omapi_object_t *po, if (ao -> type != omapi_type_auth_key && (!ao -> inner || ao -> inner -> type != omapi_type_auth_key)) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (po -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)po; #ifdef DEBUG_PROTOCOL @@ -836,14 +836,14 @@ isc_result_t omapi_protocol_lookup_auth (omapi_object_t **a, omapi_remote_auth_t *r; if (po -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)po; for (r = p -> remote_auth_list; r; r = r -> next) if (r -> remote_handle == handle) return omapi_object_reference (a, r -> a, MDL); - return ISC_R_KEY_UNKNOWN; + return DHCP_R_KEY_UNKNOWN; } isc_result_t omapi_protocol_set_value (omapi_object_t *h, @@ -855,12 +855,12 @@ isc_result_t omapi_protocol_set_value (omapi_object_t *h, omapi_remote_auth_t *r; if (h -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)h; if (omapi_ds_strcmp (name, "default-authenticator") == 0) { if (value -> type != omapi_datatype_object) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (!value || !value -> u.object) { p -> default_auth = (omapi_remote_auth_t *)0; @@ -870,7 +870,7 @@ isc_result_t omapi_protocol_set_value (omapi_object_t *h, break; if (!r) - return ISC_R_KEY_UNKNOWN; + return DHCP_R_KEY_UNKNOWN; p -> default_auth = r; } @@ -892,7 +892,7 @@ isc_result_t omapi_protocol_get_value (omapi_object_t *h, omapi_protocol_object_t *p; if (h -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)h; if (omapi_ds_strcmp (name, "default-authenticator") == 0) { @@ -914,7 +914,7 @@ isc_result_t omapi_protocol_destroy (omapi_object_t *h, { omapi_protocol_object_t *p; if (h -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_object_t *)h; if (p -> message) omapi_message_dereference (&p -> message, file, line); @@ -944,7 +944,7 @@ isc_result_t omapi_protocol_stuff_values (omapi_object_t *c, omapi_object_t *p) { if (p -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (p -> inner && p -> inner -> type -> stuff_values) return (*(p -> inner -> type -> stuff_values)) (c, id, @@ -982,7 +982,7 @@ isc_result_t omapi_protocol_configure_security (omapi_object_t *h, h = h -> outer; if (h -> type != omapi_type_protocol_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; l = (omapi_protocol_listener_object_t *)h; l -> verify_auth = verify_auth; @@ -1039,7 +1039,7 @@ isc_result_t omapi_protocol_listener_signal (omapi_object_t *o, omapi_protocol_listener_object_t *p; if (!o || o -> type != omapi_type_protocol_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; p = (omapi_protocol_listener_object_t *)o; /* Not a signal we recognize? */ @@ -1052,7 +1052,7 @@ isc_result_t omapi_protocol_listener_signal (omapi_object_t *o, c = va_arg (ap, omapi_object_t *); if (!c || c -> type != omapi_type_connection) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; obj = (omapi_protocol_object_t *)0; status = omapi_protocol_allocate (&obj, MDL); @@ -1092,7 +1092,7 @@ isc_result_t omapi_protocol_listener_set_value (omapi_object_t *h, omapi_typed_data_t *value) { if (h -> type != omapi_type_protocol_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> set_value) return (*(h -> inner -> type -> set_value)) @@ -1106,7 +1106,7 @@ isc_result_t omapi_protocol_listener_get_value (omapi_object_t *h, omapi_value_t **value) { if (h -> type != omapi_type_protocol_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (h -> inner && h -> inner -> type -> get_value) return (*(h -> inner -> type -> get_value)) @@ -1118,7 +1118,7 @@ isc_result_t omapi_protocol_listener_destroy (omapi_object_t *h, const char *file, int line) { if (h -> type != omapi_type_protocol_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; return ISC_R_SUCCESS; } @@ -1130,7 +1130,7 @@ isc_result_t omapi_protocol_listener_stuff (omapi_object_t *c, omapi_object_t *p) { if (p -> type != omapi_type_protocol_listener) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (p -> inner && p -> inner -> type -> stuff_values) return (*(p -> inner -> type -> stuff_values)) (c, id, @@ -1148,7 +1148,7 @@ isc_result_t omapi_protocol_send_status (omapi_object_t *po, omapi_object_t *mo; if (po -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; status = omapi_message_new ((omapi_object_t **)&message, MDL); if (status != ISC_R_SUCCESS) @@ -1206,7 +1206,7 @@ isc_result_t omapi_protocol_send_open (omapi_object_t *po, omapi_object_t *mo; if (po -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; status = omapi_message_new ((omapi_object_t **)&message, MDL); mo = (omapi_object_t *)message; @@ -1265,7 +1265,7 @@ isc_result_t omapi_protocol_send_update (omapi_object_t *po, omapi_object_t *mo; if (po -> type != omapi_type_protocol) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; status = omapi_message_new ((omapi_object_t **)&message, MDL); if (status != ISC_R_SUCCESS) diff --git a/omapip/result.c b/omapip/result.c index 6b682362..383279fb 100644 --- a/omapip/result.c +++ b/omapip/result.c @@ -1,23 +1,21 @@ /* result.c + */ - Cheap knock-off of libisc result table code. This is just a place-holder - until the actual libisc merge. */ - -/* - * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") +/* + * Copyright (c) 2004,2007,2009 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999-2003 by Internet Software Consortium * - * Permission to use, copy, modify, and distribute this software for any + * 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. + * 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 @@ -25,97 +23,64 @@ * <info@isc.org> * https://www.isc.org/ * - * This software has been written for Internet Systems Consortium - * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. - * To learn more about Internet Systems Consortium, see - * ``https://www.isc.org/''. To learn more about Vixie Enterprises, - * see ``http://www.vix.com''. To learn more about Nominum, Inc., see - * ``http://www.nominum.com''. */ #include "dhcpd.h" -#include <omapip/omapip_p.h> +/* + * In the previous code the results started at 36 + * rather than ISC_RESULTCLASS_DHCP + 0 + * ISC_R_NOTCONNECTED was + 4 (40), it has been superseeded by the isc version + */ -static const char *text[ISC_R_NRESULTS] = { - "success", /* 0 */ - "out of memory", /* 1 */ - "timed out", /* 2 */ - "no available threads", /* 3 */ - "address not available", /* 4 */ - "address in use", /* 5 */ - "permission denied", /* 6 */ - "no pending connections", /* 7 */ - "network unreachable", /* 8 */ - "host unreachable", /* 9 */ - "network down", /* 10 */ - "host down", /* 11 */ - "connection refused", /* 12 */ - "not enough free resources", /* 13 */ - "end of file", /* 14 */ - "socket already bound", /* 15 */ - "task is done", /* 16 */ - "lock busy", /* 17 */ - "already exists", /* 18 */ - "ran out of space", /* 19 */ - "operation canceled", /* 20 */ - "sending events is not allowed", /* 21 */ - "shutting down", /* 22 */ - "not found", /* 23 */ - "unexpected end of input", /* 24 */ - "failure", /* 25 */ - "I/O error", /* 26 */ - "not implemented", /* 27 */ - "unbalanced parentheses", /* 28 */ - "no more", /* 29 */ - "invalid file", /* 30 */ - "bad base64 encoding", /* 31 */ - "unexpected token", /* 32 */ - "quota reached", /* 33 */ - "unexpected error", /* 34 */ - "already running", /* 35 */ - "host unknown", /* 36 */ - "protocol version mismatch", /* 37 */ - "protocol error", /* 38 */ - "invalid argument", /* 39 */ - "not connected", /* 40 */ - "data not yet available", /* 41 */ - "object unchanged", /* 42 */ - "more than one object matches key", /* 43 */ - "key conflict", /* 44 */ - "parse error(s) occurred", /* 45 */ - "no key specified", /* 46 */ - "zone TSIG key not known", /* 47 */ - "invalid TSIG key", /* 48 */ - "operation in progress", /* 49 */ - "DNS format error", /* 50 */ - "DNS server failed", /* 51 */ - "no such domain", /* 52 */ - "not implemented", /* 53 */ - "refused", /* 54 */ - "domain already exists", /* 55 */ - "RRset already exists", /* 56 */ - "no such RRset", /* 57 */ - "not authorized", /* 58 */ - "not a zone", /* 59 */ - "bad DNS signature", /* 60 */ - "bad DNS key", /* 61 */ - "clock skew too great", /* 62 */ - "no root zone", /* 63 */ - "destination address required", /* 64 */ - "cross-zone update", /* 65 */ - "no TSIG signature", /* 66 */ - "not equal", /* 67 */ - "connection reset by peer", /* 68 */ - "unknown attribute" /* 69 */ +static const char *text[DHCP_R_NRESULTS] = { + "host unknown", /* 0 */ + "protocol version mismatch", /* 1 */ + "protocol error", /* 2 */ + "invalid argument", /* 3 */ + "data not yet available", /* 4 */ + "object unchanged", /* 5 */ + "more than one object matches key", /* 6 */ + "key conflict", /* 7 */ + "parse error(s) occurred", /* 8 */ + "no key specified", /* 9 */ + "zone TSIG key not known", /* 10 */ + "invalid TSIG key", /* 11 */ + "operation in progress", /* 12 */ + "DNS format error", /* 13 */ + "DNS server failed", /* 14 */ + "no such domain", /* 15 */ + "not implemented", /* 16 */ + "refused", /* 17 */ + "domain already exists", /* 18 */ + "RRset already exists", /* 19 */ + "no such RRset", /* 20 */ + "not authorized", /* 21 */ + "not a zone", /* 22 */ + "bad DNS signature", /* 23 */ + "bad DNS key", /* 24 */ + "clock skew too great", /* 25 */ + "no root zone", /* 26 */ + "destination address required", /* 27 */ + "cross-zone update", /* 28 */ + "no TSIG signature", /* 29 */ + "not equal", /* 30 */ + "connection reset by peer", /* 31 */ + "unknown attribute" /* 32 */ }; -const char *isc_result_totext (isc_result_t result) -{ - static char ebuf[40]; +#define DHCP_RESULT_RESULTSET 2 +#define DHCP_RESULT_UNAVAILABLESET 3 + +// This is a placeholder as we don't allow for external message catalogs yet +isc_msgcat_t * dhcp_msgcat = NULL; + +isc_result_t +dhcp_result_register(void) { + isc_result_t result; + + result = isc_result_register(ISC_RESULTCLASS_DHCP, DHCP_R_NRESULTS, + text, dhcp_msgcat, DHCP_RESULT_RESULTSET); - if (result >= ISC_R_SUCCESS && result < ISC_R_NRESULTS) - return text [result]; - sprintf(ebuf, "unknown error: %d", result); - return ebuf; + return(result); } diff --git a/omapip/support.c b/omapip/support.c index 2a4e8c75..15eeac04 100644 --- a/omapip/support.c +++ b/omapip/support.c @@ -68,8 +68,6 @@ isc_result_t omapi_init (void) { isc_result_t status; - dst_init(); - /* Register all the standard object types... */ status = omapi_object_type_register (&omapi_type_connection, "connection", @@ -543,7 +541,7 @@ isc_result_t omapi_object_update (omapi_object_t *obj, omapi_object_t *id, int i; if (!src) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; if (src -> type != omapi_type_generic) return ISC_R_NOTIMPLEMENTED; gsrc = (omapi_generic_object_t *)src; @@ -551,7 +549,7 @@ isc_result_t omapi_object_update (omapi_object_t *obj, omapi_object_t *id, status = omapi_set_value (obj, id, gsrc -> values [i] -> name, gsrc -> values [i] -> value); - if (status != ISC_R_SUCCESS && status != ISC_R_UNCHANGED) + if (status != ISC_R_SUCCESS && status != DHCP_R_UNCHANGED) return status; } if (handle) @@ -845,10 +843,10 @@ isc_result_t omapi_get_int_value (unsigned long *v, omapi_typed_data_t *t) } else if (t -> type == omapi_datatype_string || t -> type == omapi_datatype_data) { if (t -> u.buffer.len != sizeof (rv)) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; memcpy (&rv, t -> u.buffer.value, sizeof rv); *v = ntohl (rv); return ISC_R_SUCCESS; } - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } diff --git a/omapip/test.c b/omapip/test.c index 4bdefdec..ccd3c7a6 100644 --- a/omapip/test.c +++ b/omapip/test.c @@ -37,9 +37,10 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> -#include <isc-dhcp/result.h> +#include <omapip/result.h> #include <sys/time.h> #include <omapip/omapip.h> +#include <omapip/isclib.h> int main (int argc, char **argv) { @@ -47,6 +48,8 @@ int main (int argc, char **argv) omapi_object_t *connection = (omapi_object_t*)0; isc_result_t status; + dhcp_context_create(); + omapi_init (); if (argc > 1 && !strcmp (argv [1], "listen")) { diff --git a/omapip/toisc.c b/omapip/toisc.c index 437816fa..d3dfa8ae 100644 --- a/omapip/toisc.c +++ b/omapip/toisc.c @@ -36,61 +36,10 @@ #include <omapip/omapip_p.h> #include "arpa/nameser.h" -#include "minires/minires.h" +#include "minires.h" #include <errno.h> -isc_result_t ns_rcode_to_isc (int nsr) -{ - switch (nsr) { - case ns_r_noerror: - return ISC_R_SUCCESS; - - case ns_r_formerr: - return ISC_R_FORMERR; - - case ns_r_servfail: - return ISC_R_SERVFAIL; - - case ns_r_nxdomain: - return ISC_R_NXDOMAIN; - - case ns_r_notimpl: - return ISC_R_NOTIMPL; - - case ns_r_refused: - return ISC_R_REFUSED; - - case ns_r_yxdomain: - return ISC_R_YXDOMAIN; - - case ns_r_yxrrset: - return ISC_R_YXRRSET; - - case ns_r_nxrrset: - return ISC_R_NXRRSET; - - case ns_r_notauth: - return ISC_R_NOTAUTH; - - case ns_r_notzone: - return ISC_R_NOTZONE; - - case ns_r_badsig: - return ISC_R_BADSIG; - - case ns_r_badkey: - return ISC_R_BADKEY; - - case ns_r_badtime: - return ISC_R_BADTIME; - - default: - ; - } - return ISC_R_UNEXPECTED; -} - isc_result_t uerr2isc (int err) { switch (err) { @@ -113,7 +62,7 @@ isc_result_t uerr2isc (int err) return ISC_R_NOSPACE; case ENOEXEC: - return ISC_R_FORMERR; + return DHCP_R_FORMERR; case ECHILD: return ISC_R_NOTFOUND; @@ -125,16 +74,16 @@ isc_result_t uerr2isc (int err) return ISC_R_NOPERM; case EFAULT: - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; case EEXIST: return ISC_R_EXISTS; case EINVAL: - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; case ENOTTY: - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; case EFBIG: return ISC_R_NOSPACE; @@ -161,13 +110,13 @@ isc_result_t uerr2isc (int err) return ISC_R_INVALIDFILE; case EDESTADDRREQ: - return ISC_R_DESTADDRREQ; + return DHCP_R_DESTADDRREQ; case EMSGSIZE: return ISC_R_NOSPACE; case EPROTOTYPE: - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; case ENOPROTOOPT: return ISC_R_NOTIMPLEMENTED; @@ -203,7 +152,7 @@ isc_result_t uerr2isc (int err) return ISC_R_TIMEDOUT; case ECONNRESET: - return ISC_R_CONNRESET; + return DHCP_R_CONNRESET; case ENOBUFS: return ISC_R_NOSPACE; @@ -241,22 +190,22 @@ isc_result_t uerr2isc (int err) #ifdef ERPCMISMATCH case ERPCMISMATCH: - return ISC_R_VERSIONMISMATCH; + return DHCP_R_VERSIONMISMATCH; #endif #ifdef EPROGMISMATCH case EPROGMISMATCH: - return ISC_R_VERSIONMISMATCH; + return DHCP_R_VERSIONMISMATCH; #endif #ifdef EAUTH case EAUTH: - return ISC_R_NOTAUTH; + return DHCP_R_NOTAUTH; #endif #ifdef ENEEDAUTH case ENEEDAUTH: - return ISC_R_NOTAUTH; + return DHCP_R_NOTAUTH; #endif #ifdef EOVERFLOW @@ -266,54 +215,3 @@ isc_result_t uerr2isc (int err) } return ISC_R_UNEXPECTED; } - -ns_rcode isc_rcode_to_ns (isc_result_t isc) -{ - switch (isc) { - case ISC_R_SUCCESS: - return ns_r_noerror; - - case ISC_R_FORMERR: - return ns_r_formerr; - - case ISC_R_SERVFAIL: - return ns_r_servfail; - - case ISC_R_NXDOMAIN: - return ns_r_nxdomain; - - case ISC_R_NOTIMPL: - return ns_r_notimpl; - - case ISC_R_REFUSED: - return ns_r_refused; - - case ISC_R_YXDOMAIN: - return ns_r_yxdomain; - - case ISC_R_YXRRSET: - return ns_r_yxrrset; - - case ISC_R_NXRRSET: - return ns_r_nxrrset; - - case ISC_R_NOTAUTH: - return ns_r_notauth; - - case ISC_R_NOTZONE: - return ns_r_notzone; - - case ISC_R_BADSIG: - return ns_r_badsig; - - case ISC_R_BADKEY: - return ns_r_badkey; - - case ISC_R_BADTIME: - return ns_r_badtime; - - default: - ; - } - return ns_r_servfail; -} diff --git a/omapip/trace.c b/omapip/trace.c index 26ec08d1..1f521a67 100644 --- a/omapip/trace.c +++ b/omapip/trace.c @@ -137,7 +137,7 @@ isc_result_t trace_begin (const char *filename, if (traceoutfile) { log_error ("%s(%d): trace_begin called twice", file, line); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600); @@ -218,12 +218,12 @@ isc_result_t trace_write_packet_iov (trace_type_t *ttype, if (!ttype) { log_error ("%s(%d): trace_write_packet with null trace type", file ? file : "<unknown file>", line); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } if (!traceoutfile) { log_error ("%s(%d): trace_write_packet with no tracefile.", file ? file : "<unknown file>", line); - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; } /* Compute the total length of the iov. */ @@ -532,7 +532,7 @@ isc_result_t trace_get_next_packet (trace_type_t **ttp, "%ld %ld.", (long int)status, (long int)tracefile_header.phlen); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } /* Swap the packet. */ @@ -547,7 +547,7 @@ isc_result_t trace_get_next_packet (trace_type_t **ttp, else { log_error ("Trace packet with unknown index %ld", (long int)tpkt -> type_index); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } /* If we were just hunting for the time marker, we've found it, @@ -558,7 +558,7 @@ isc_result_t trace_get_next_packet (trace_type_t **ttp, status = fsetpos (traceinfile, &curpos); if (status < 0) { log_error ("fsetpos in tracefile failed: %m"); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } return ISC_R_EXISTS; } @@ -571,7 +571,7 @@ isc_result_t trace_get_next_packet (trace_type_t **ttp, status = fsetpos (traceinfile, &curpos); if (status < 0) { log_error ("fsetpos in tracefile failed: %m"); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } return ISC_R_UNEXPECTEDTOKEN; } @@ -598,7 +598,7 @@ isc_result_t trace_get_next_packet (trace_type_t **ttp, else log_error ("Short read on trace payload: %d %d.", status, paylen); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } /* Store the actual length of the payload. */ @@ -620,7 +620,7 @@ isc_result_t trace_get_packet (trace_type_t **ttp, isc_result_t status; if (!buf || *buf) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; tpkt = dmalloc ((unsigned)tracefile_header.phlen, MDL); if (!tpkt) { @@ -676,7 +676,7 @@ isc_result_t trace_get_file (trace_type_t *ttype, /* Disallow some obvious bogosities. */ if (!buf || !len || *buf) - return ISC_R_INVALIDARG; + return DHCP_R_INVALIDARG; /* Save file position in case of filename mismatch. */ status = fgetpos (traceinfile, &curpos); @@ -705,7 +705,7 @@ isc_result_t trace_get_file (trace_type_t *ttype, log_error ("fsetpos in tracefile failed: %m"); dfree (tpkt, MDL); dfree (*buf, MDL); - return ISC_R_PROTOCOLERROR; + return DHCP_R_PROTOCOLERROR; } return ISC_R_UNEXPECTEDTOKEN; } |