1999-10-27 22:24:32 +00:00
|
|
|
/*
|
1999-11-02 04:01:34 +00:00
|
|
|
* Copyright (C) 1996, 1997, 1998, 1999 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM 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.
|
1999-10-27 22:24:32 +00:00
|
|
|
*/
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Functions supporting the object management protocol.
|
|
|
|
*/
|
|
|
|
#include <stddef.h> /* NULL */
|
2000-01-04 20:04:42 +00:00
|
|
|
#include <stdlib.h> /* random */
|
1999-11-02 04:01:34 +00:00
|
|
|
#include <string.h> /* memset */
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
#include <omapi/private.h>
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
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_OBJECT_PREAMBLE;
|
|
|
|
} omapi_protocol_listener_object_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OMAPI_OBJECT_PREAMBLE;
|
|
|
|
unsigned int header_size;
|
|
|
|
unsigned int protocol_version;
|
|
|
|
isc_uint32_t next_xid;
|
|
|
|
omapi_object_t * authinfo; /* Default authinfo. */
|
|
|
|
|
|
|
|
omapi_protocol_state_t state; /* Input state. */
|
|
|
|
/* XXXDCL make isc_boolean_t */
|
|
|
|
/*
|
|
|
|
* True when reading message-specific values.
|
|
|
|
*/
|
2000-01-06 23:56:51 +00:00
|
|
|
isc_boolean_t reading_message_values;
|
1999-11-02 04:01:34 +00:00
|
|
|
omapi_message_object_t * message; /* Incoming message. */
|
|
|
|
omapi_data_string_t * name; /* Incoming name. */
|
|
|
|
omapi_typed_data_t * value; /* Incoming value. */
|
|
|
|
} omapi_protocol_object_t;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* OMAPI protocol header, version 1.00
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
unsigned int authlen; /* Length of authenticator. */
|
|
|
|
unsigned int authid; /* Authenticator object ID. */
|
|
|
|
unsigned int op; /* Opcode. */
|
|
|
|
omapi_handle_t handle; /* Handle of object being operated on, or 0. */
|
|
|
|
unsigned int id; /* Transaction ID. */
|
|
|
|
unsigned int rid; /* ID of transaction responding to. */
|
|
|
|
} omapi_protocol_header_t;
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_connect(omapi_object_t *h, const char *server_name,
|
|
|
|
int port, omapi_object_t *authinfo)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_protocol_object_t *obj;
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
obj = isc_mem_get(omapi_mctx, sizeof(*obj));
|
1999-11-02 04:01:34 +00:00
|
|
|
if (obj == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
memset(obj, 0, sizeof(*obj));
|
2000-01-04 20:04:42 +00:00
|
|
|
obj->object_size = sizeof(*obj);
|
1999-11-02 04:01:34 +00:00
|
|
|
obj->refcnt = 1;
|
|
|
|
obj->type = omapi_type_protocol;
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_connection_toserver((omapi_object_t *)obj,
|
|
|
|
server_name, port);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&obj, "omapi_protocol_connect");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_REF(&h->outer, obj, "omapi_protocol_connect");
|
|
|
|
OBJECT_REF(&obj->inner, h, "omapi_protocol_connect");
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the introductory message.
|
|
|
|
*/
|
|
|
|
result = omapi_protocol_send_intro((omapi_object_t *)obj,
|
|
|
|
OMAPI_PROTOCOL_VERSION,
|
|
|
|
sizeof(omapi_protocol_header_t));
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&obj, "omapi_protocol_connect");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (authinfo)
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_REF(&obj->authinfo, authinfo, "omapi_protocol_connect");
|
|
|
|
OBJECT_DEREF(&obj, "omapi_protocol_accept");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
void
|
|
|
|
omapi_protocol_disconnect(omapi_object_t *handle, isc_boolean_t force) {
|
|
|
|
omapi_protocol_object_t *protocol;
|
|
|
|
omapi_connection_object_t *connection;
|
|
|
|
|
|
|
|
REQUIRE(handle != NULL);
|
|
|
|
|
|
|
|
protocol = (omapi_protocol_object_t *)handle->outer;
|
|
|
|
|
|
|
|
ENSURE(protocol != NULL && protocol->type == omapi_type_protocol);
|
|
|
|
|
|
|
|
connection = (omapi_connection_object_t *)protocol->outer;
|
|
|
|
|
|
|
|
ENSURE(connection != NULL && connection->type == omapi_type_connection);
|
|
|
|
|
|
|
|
omapi_connection_disconnect((omapi_object_t *)connection, force);
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Send the protocol introduction message.
|
|
|
|
*/
|
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_send_intro(omapi_object_t *h, unsigned int ver,
|
|
|
|
unsigned int hsize)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_protocol_object_t *p;
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_connection_object_t *connection;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
p = (omapi_protocol_object_t *)h;
|
2000-01-04 20:04:42 +00:00
|
|
|
connection = (omapi_connection_object_t *)h->outer;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (h->outer == NULL || h->outer->type != omapi_type_connection)
|
2000-01-06 23:56:51 +00:00
|
|
|
return (OMAPI_R_NOTCONNECTED);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32((omapi_object_t *)connection,
|
2000-01-04 20:04:42 +00:00
|
|
|
ver);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32((omapi_object_t *)connection,
|
2000-01-04 20:04:42 +00:00
|
|
|
hsize);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Require the other end to send an intro - this kicks off the
|
|
|
|
* protocol input state machine.
|
|
|
|
*/
|
|
|
|
p->state = omapi_protocol_intro_wait;
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_connection_require((omapi_object_t *)connection, 8);
|
2000-01-06 03:36:32 +00:00
|
|
|
if (result != ISC_R_SUCCESS && result != OMAPI_R_NOTYET)
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make up an initial transaction ID for this connection.
|
|
|
|
* XXXDCL better generator than random()?
|
|
|
|
*/
|
|
|
|
p->next_xid = random();
|
2000-01-04 20:04:42 +00:00
|
|
|
|
2000-01-06 03:36:32 +00:00
|
|
|
connection_send(connection);
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
|
|
|
|
omapi_object_t *mo, omapi_object_t *omo)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
|
|
|
omapi_protocol_object_t *p;
|
|
|
|
omapi_object_t *c;
|
|
|
|
omapi_message_object_t *m;
|
|
|
|
omapi_message_object_t *om;
|
2000-01-13 06:13:26 +00:00
|
|
|
omapi_connection_object_t *connection;
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(po != NULL && po->type == omapi_type_protocol &&
|
|
|
|
po->outer != NULL && po->outer->type == omapi_type_connection);
|
|
|
|
REQUIRE(mo != NULL && mo->type == omapi_type_message);
|
|
|
|
REQUIRE(omo == NULL || omo->type == omapi_type_message);
|
|
|
|
|
1999-10-27 22:24:32 +00:00
|
|
|
p = (omapi_protocol_object_t *)po;
|
1999-11-02 04:01:34 +00:00
|
|
|
c = (omapi_object_t *)(po->outer);
|
2000-01-13 06:13:26 +00:00
|
|
|
connection = (omapi_connection_object_t *)c;
|
1999-10-27 22:24:32 +00:00
|
|
|
m = (omapi_message_object_t *)mo;
|
|
|
|
om = (omapi_message_object_t *)omo;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/* XXXTL Write the authenticator length */
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32(c, 0);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
/* XXXTL Write the ID of the authentication key we're using. */
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32(c, 0);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write the opcode.
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32(c, m->op);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write the handle. If we've been given an explicit handle, use
|
|
|
|
* that. Otherwise, use the handle of the object we're sending.
|
|
|
|
* The caller is responsible for arranging for one of these handles
|
|
|
|
* to be set (or not).
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32(c, (m->h ? m->h
|
1999-11-02 04:01:34 +00:00
|
|
|
: (m->object ?
|
|
|
|
m->object->handle
|
|
|
|
: 0)));
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Set and write the transaction ID.
|
|
|
|
*/
|
|
|
|
m->id = p->next_xid++;
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32(c, m->id);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write the transaction ID of the message to which this is a
|
|
|
|
* response, if there is such a message.
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint32(c, om ? om->id : m->rid);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Stuff out the name/value pairs specific to this message.
|
|
|
|
*/
|
|
|
|
result = omapi_stuff_values(c, id, (omapi_object_t *)m);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write the zero-length name that terminates the list of name/value
|
|
|
|
* pairs specific to the message.
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint16(c, 0);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Stuff out all the published name/value pairs in the object that's
|
|
|
|
* being sent in the message, if there is one.
|
|
|
|
*/
|
|
|
|
if (m->object != NULL) {
|
|
|
|
result = omapi_stuff_values(c, id, m->object);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write the zero-length name that terminates the list of name/value
|
|
|
|
* pairs for the associated object.
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_putuint16(c, 0);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/* XXXTL Write the authenticator... */
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
|
2000-01-13 06:13:26 +00:00
|
|
|
/*
|
|
|
|
* When the client sends a message, it expects a reply.
|
|
|
|
*/
|
|
|
|
if (connection->is_client) {
|
|
|
|
result = isc_mutex_lock(&connection->mutex);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
|
|
|
|
|
|
|
connection->messages_expected++;
|
|
|
|
|
|
|
|
result = isc_mutex_unlock(&connection->mutex);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
connection_send(connection);
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2000-01-13 06:13:26 +00:00
|
|
|
|
|
|
|
disconnect:
|
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_signal_handler(omapi_object_t *h, const char *name, va_list ap)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_protocol_object_t *p;
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_object_t *connection;
|
2000-01-13 06:13:26 +00:00
|
|
|
omapi_connection_object_t *c;
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_uint16_t nlen;
|
|
|
|
isc_uint32_t vlen;
|
|
|
|
|
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
p = (omapi_protocol_object_t *)h;
|
2000-01-13 06:13:26 +00:00
|
|
|
c = (omapi_connection_object_t *)p->outer;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Not a signal we recognize?
|
|
|
|
*/
|
2000-01-04 20:04:42 +00:00
|
|
|
if (strcmp(name, "ready") != 0)
|
|
|
|
PASS_SIGNAL(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
INSIST(p->outer != NULL && p->outer->type == omapi_type_connection);
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
connection = p->outer;
|
1999-11-02 04:01:34 +00:00
|
|
|
|
2000-01-13 06:13:26 +00:00
|
|
|
/*
|
|
|
|
* XXXDCL figure out how come when this function throws
|
|
|
|
* an error, it is not seen by the main program.
|
|
|
|
*/
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* We get here because we requested that we be woken up after
|
|
|
|
* some number of bytes were read, and that number of bytes
|
|
|
|
* has in fact been read.
|
|
|
|
*/
|
|
|
|
switch (p->state) {
|
|
|
|
case omapi_protocol_intro_wait:
|
|
|
|
/*
|
|
|
|
* Get protocol version and header size in network
|
|
|
|
* byte order.
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)
|
|
|
|
&p->protocol_version);
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->header_size);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* We currently only support the current protocol version.
|
|
|
|
*/
|
|
|
|
if (p->protocol_version != OMAPI_PROTOCOL_VERSION) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
|
|
|
return (OMAPI_R_VERSIONMISMATCH);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (p->header_size < sizeof(omapi_protocol_header_t)) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
|
|
|
return (OMAPI_R_PROTOCOLERROR);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
2000-01-13 06:13:26 +00:00
|
|
|
/*
|
|
|
|
* Signal omapi_connection_wait() to wake up.
|
|
|
|
* Only do this for the client side.
|
|
|
|
* XXXDCL duplicated below
|
|
|
|
*/
|
|
|
|
if (c->is_client) {
|
|
|
|
result = isc_mutex_lock(&c->mutex);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an unsigned int but on the server it will
|
|
|
|
* count below 0 for each incoming message received.
|
|
|
|
* But that's ok, because the server doesn't support
|
|
|
|
* omapi_connection_wait.
|
|
|
|
*/
|
|
|
|
c->messages_expected--;
|
|
|
|
|
|
|
|
result = isc_condition_signal(&c->waiter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the lock. Contrary to what you might think
|
|
|
|
* from some documentation sources, it is necessary
|
|
|
|
* to do this for the waiting thread to unblock.
|
|
|
|
*/
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = isc_mutex_unlock(&c->mutex);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
|
|
|
}
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
to_header_wait:
|
|
|
|
/*
|
|
|
|
* The next thing we're expecting is a message header.
|
|
|
|
*/
|
|
|
|
p->state = omapi_protocol_header_wait;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a need for the number of bytes in a
|
|
|
|
* header, and if we already have that many, process
|
|
|
|
* them immediately.
|
|
|
|
*/
|
2000-01-04 20:04:42 +00:00
|
|
|
if ((omapi_connection_require(connection, p->header_size))
|
1999-11-02 04:01:34 +00:00
|
|
|
!= ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If we already have the data, fall through.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case omapi_protocol_header_wait:
|
|
|
|
result = omapi_message_new((omapi_object_t **)&p->message,
|
|
|
|
"omapi_protocol_signal_handler");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Swap in the header.
|
|
|
|
*/
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->message->authid);
|
|
|
|
|
|
|
|
/* XXXTL bind the authenticator here! */
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->message->authlen);
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->message->op);
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->message->handle);
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->message->id);
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
(isc_uint32_t *)&p->message->rid);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there was any extra header data, skip over it.
|
|
|
|
*/
|
2000-01-13 06:13:26 +00:00
|
|
|
if (p->header_size > sizeof(omapi_protocol_header_t))
|
|
|
|
omapi_connection_copyout(NULL, connection,
|
2000-01-04 20:04:42 +00:00
|
|
|
(p->header_size -
|
1999-11-02 04:01:34 +00:00
|
|
|
sizeof(omapi_protocol_header_t)));
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* XXXTL must compute partial signature across the preceding
|
|
|
|
* bytes. Also, if authenticator specifies encryption as well
|
|
|
|
* as signing, we may have to decrypt the data on the way in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First we read in message-specific values, then object
|
|
|
|
* values.
|
|
|
|
*/
|
2000-01-06 23:56:51 +00:00
|
|
|
p->reading_message_values = ISC_TRUE;
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
need_name_length:
|
|
|
|
/*
|
|
|
|
* The next thing we're expecting is length of the
|
|
|
|
* first name.
|
|
|
|
*/
|
|
|
|
p->state = omapi_protocol_name_length_wait;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for a 16-bit length.
|
|
|
|
*/
|
2000-01-04 20:04:42 +00:00
|
|
|
if (omapi_connection_require(connection, 2) != ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If it's already here, fall through.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case omapi_protocol_name_length_wait:
|
2000-01-06 03:36:32 +00:00
|
|
|
result = omapi_connection_getuint16(connection, &nlen);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
|
|
|
}
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* A zero-length name means that we're done reading name+value
|
|
|
|
* pairs.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
if (nlen == 0) {
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If we've already read in the object, we are
|
|
|
|
* done reading the message, but if we've just
|
|
|
|
* finished reading in the values associated
|
|
|
|
* with the message, we need to read the
|
|
|
|
* object.
|
|
|
|
*/
|
|
|
|
if (p->reading_message_values) {
|
2000-01-06 23:56:51 +00:00
|
|
|
p->reading_message_values = ISC_FALSE;
|
1999-10-27 22:24:32 +00:00
|
|
|
goto need_name_length;
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If the authenticator length is zero, there's no
|
|
|
|
* signature to read in, so go straight to processing
|
|
|
|
* the message.
|
|
|
|
*/
|
|
|
|
if (p->message->authlen == 0)
|
1999-10-27 22:24:32 +00:00
|
|
|
goto message_done;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* The next thing we're expecting is the
|
|
|
|
* message signature.
|
|
|
|
*/
|
|
|
|
p->state = omapi_protocol_signature_wait;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the number of bytes specified for
|
|
|
|
* the authenticator. If we already have it,
|
|
|
|
* go read it in.
|
|
|
|
*/
|
2000-01-04 20:04:42 +00:00
|
|
|
if (omapi_connection_require(connection,
|
|
|
|
p->message->authlen)
|
1999-11-02 04:01:34 +00:00
|
|
|
== ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
goto signature_wait;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Allocate a buffer for the name.
|
|
|
|
*/
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_data_newstring(&p->name, nlen,
|
1999-11-02 04:01:34 +00:00
|
|
|
"omapi_protocol_signal_handler");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
p->state = omapi_protocol_name_wait;
|
2000-01-04 20:04:42 +00:00
|
|
|
if (omapi_connection_require(connection, nlen) !=
|
|
|
|
ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's already here, fall through.
|
|
|
|
* */
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
case omapi_protocol_name_wait:
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_connection_copyout(p->name->value, connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
p->name->len);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for a 32-bit length.
|
|
|
|
*/
|
|
|
|
p->state = omapi_protocol_value_length_wait;
|
2000-01-13 06:13:26 +00:00
|
|
|
result = omapi_connection_require(connection, 4);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If it's already here, fall through.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
case omapi_protocol_value_length_wait:
|
2000-01-06 03:36:32 +00:00
|
|
|
omapi_connection_getuint32(connection, &vlen);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero-length values are allowed - if we get one, we
|
|
|
|
* don't have to read any data for the value - just
|
|
|
|
* get the next one, if there is a next one.
|
|
|
|
*/
|
|
|
|
if (vlen == 0)
|
1999-10-27 22:24:32 +00:00
|
|
|
goto insert_new_value;
|
|
|
|
|
2000-01-13 06:13:26 +00:00
|
|
|
result = omapi_data_new(&p->value, omapi_datatype_data, vlen,
|
|
|
|
"omapi_protocol_signal_handler");
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
p->state = omapi_protocol_value_wait;
|
2000-01-13 06:13:26 +00:00
|
|
|
result = omapi_connection_require(connection, vlen);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If it's already here, fall through.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
case omapi_protocol_value_wait:
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_connection_copyout(p->value->u.buffer.value,
|
|
|
|
connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
p->value->u.buffer.len);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
insert_new_value:
|
2000-01-06 23:56:51 +00:00
|
|
|
if (p->reading_message_values) {
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_set_value((omapi_object_t *)p->message,
|
|
|
|
p->message->id_object,
|
|
|
|
p->name, p->value);
|
1999-10-27 22:24:32 +00:00
|
|
|
} else {
|
1999-11-02 04:01:34 +00:00
|
|
|
if (p->message->object == NULL) {
|
|
|
|
/*
|
|
|
|
* We need a generic object to hang off of the
|
|
|
|
* incoming message.
|
|
|
|
*/
|
|
|
|
result = omapi_generic_new(&p->message->object,
|
|
|
|
"omapi_protocol_signal_handler");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
1999-11-02 04:01:34 +00:00
|
|
|
OMAPI_FORCE_DISCONNECT);
|
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
result = (omapi_set_value
|
|
|
|
((omapi_object_t *)p->message->object,
|
|
|
|
p->message->id_object,
|
|
|
|
p->name, p->value));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_stringdereference(&p->name,
|
1999-10-27 22:24:32 +00:00
|
|
|
"omapi_protocol_signal_handler");
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_dereference(&p->value,
|
|
|
|
"omapi_protocol_signal_handler");
|
1999-10-27 22:24:32 +00:00
|
|
|
goto need_name_length;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
signature_wait:
|
|
|
|
case omapi_protocol_signature_wait:
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_data_new(&p->message->authenticator,
|
|
|
|
omapi_datatype_data,
|
|
|
|
p->message->authlen);
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
result = (omapi_connection_copyout
|
2000-01-04 20:04:42 +00:00
|
|
|
(p->message->authenticator->u.buffer.value,
|
|
|
|
connection, p->message->authlen));
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(connection,
|
|
|
|
OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
/* XXXTL now do something to verify the signature. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the message.
|
|
|
|
*/
|
|
|
|
message_done:
|
|
|
|
result = omapi_message_process((omapi_object_t *)p->message,
|
|
|
|
h);
|
2000-01-13 06:13:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Signal omapi_connection_wait() to wake up.
|
|
|
|
* XXXDCL duplicated from above.
|
|
|
|
*/
|
|
|
|
if (c->is_client) {
|
|
|
|
result = isc_mutex_lock(&c->mutex);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an unsigned int but on the server it will
|
|
|
|
* count below 0 for each incoming message received.
|
|
|
|
* But that's ok, because the server doesn't support
|
|
|
|
* omapi_connection_wait.
|
|
|
|
*/
|
|
|
|
c->messages_expected--;
|
|
|
|
|
|
|
|
result = isc_condition_signal(&c->waiter);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
|
|
|
|
|
|
|
result = isc_mutex_unlock(&c->mutex);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto disconnect;
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/* XXXTL unbind the authenticator. */
|
2000-01-13 06:13:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the message object.
|
|
|
|
*/
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&p->message, "omapi_protocol_signal_handler");
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Now wait for the next message.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
goto to_header_wait;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
default:
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"unknown state in "
|
|
|
|
"omapi_protocol_signal_handler: %d\n",
|
|
|
|
p->state);
|
|
|
|
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
2000-01-13 06:13:26 +00:00
|
|
|
|
|
|
|
/* XXXDCL
|
|
|
|
* 'goto' could be avoided by wrapping the body in another function.
|
|
|
|
*/
|
|
|
|
disconnect:
|
|
|
|
omapi_connection_disconnect(connection, OMAPI_FORCE_DISCONNECT);
|
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_set_value(omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name, omapi_typed_data_t *value)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_SETVALUE(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_get_value(omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_GETVALUE(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
void
|
|
|
|
omapi_protocol_destroy(omapi_object_t *h, const char *name) {
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_protocol_object_t *p;
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol);
|
|
|
|
|
1999-10-27 22:24:32 +00:00
|
|
|
p = (omapi_protocol_object_t *)h;
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
if (p->message != NULL)
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&p->message, name);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
if (p->authinfo != NULL)
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&p->authinfo, name);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write all the published values associated with the object through the
|
|
|
|
* specified connection.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_protocol_stuff_values(omapi_object_t *connection, omapi_object_t *id,
|
1999-11-02 04:01:34 +00:00
|
|
|
omapi_object_t *h)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_STUFFVALUES(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Set up a listener for the omapi protocol. The handle stored points to
|
|
|
|
* a listener object, not a protocol object.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_listen(omapi_object_t *h, int port, int max) {
|
|
|
|
isc_result_t result;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_protocol_listener_object_t *obj;
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
obj = isc_mem_get(omapi_mctx, sizeof(*obj));
|
1999-11-02 04:01:34 +00:00
|
|
|
if (obj == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
memset(obj, 0, sizeof(*obj));
|
2000-01-04 20:04:42 +00:00
|
|
|
obj->object_size = sizeof(*obj);
|
1999-11-02 04:01:34 +00:00
|
|
|
obj->refcnt = 1;
|
|
|
|
obj->type = omapi_type_protocol_listener;
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_REF(&h->outer, obj, "omapi_protocol_listen");
|
|
|
|
OBJECT_REF(&obj->inner, h, "omapi_protocol_listen");
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_listener_listen((omapi_object_t *)obj, port, max);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&obj, "omapi_protocol_listen");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Signal handler for protocol listener - if we get a connect signal,
|
|
|
|
* create a new protocol connection, otherwise pass the signal down.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_listener_signal(omapi_object_t *h, const char *name, va_list ap)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_object_t *c;
|
|
|
|
omapi_protocol_object_t *obj;
|
|
|
|
omapi_protocol_listener_object_t *p;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol_listener);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
p = (omapi_protocol_listener_object_t *)h;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Not a signal we recognize?
|
|
|
|
*/
|
|
|
|
if (strcmp(name, "connect") != 0) {
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_SIGNAL(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
c = va_arg(ap, omapi_object_t *);
|
|
|
|
|
|
|
|
INSIST(c != NULL && c->type == omapi_type_connection);
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
obj = isc_mem_get(omapi_mctx, sizeof(*obj));
|
1999-11-02 04:01:34 +00:00
|
|
|
if (obj == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
memset(obj, 0, sizeof(*obj));
|
2000-01-04 20:04:42 +00:00
|
|
|
obj->object_size = sizeof(*obj);
|
1999-11-02 04:01:34 +00:00
|
|
|
obj->refcnt = 1;
|
|
|
|
obj->type = omapi_type_protocol;
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_REF(&obj->outer, c, "omapi_protocol_accept");
|
|
|
|
OBJECT_REF(&c->inner, obj, "omapi_protocol_accept");
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the introductory message.
|
|
|
|
*/
|
|
|
|
result = omapi_protocol_send_intro((omapi_object_t *)obj,
|
|
|
|
OMAPI_PROTOCOL_VERSION,
|
|
|
|
sizeof(omapi_protocol_header_t));
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_connection_disconnect(c, OMAPI_FORCE_DISCONNECT);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&obj, "omapi_protocol_accept");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_listener_set_value(omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_typed_data_t *value)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol_listener);
|
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_SETVALUE(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_listener_get_value(omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol_listener);
|
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_GETVALUE(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
void
|
|
|
|
omapi_protocol_listener_destroy(omapi_object_t *h, const char *name) {
|
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol_listener);
|
|
|
|
|
|
|
|
(void)name; /* Unused. */
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Write all the published values associated with the object through the
|
|
|
|
* specified connection.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_protocol_listener_stuff(omapi_object_t *connection, omapi_object_t *id,
|
1999-11-02 04:01:34 +00:00
|
|
|
omapi_object_t *h)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_protocol_listener);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-06 23:56:51 +00:00
|
|
|
PASS_STUFFVALUES(h);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_send_status(omapi_object_t *po, omapi_object_t *id,
|
|
|
|
isc_result_t waitstatus,
|
|
|
|
unsigned int rid, const char *msg)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
|
|
|
omapi_object_t *message = NULL;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(po != NULL && po->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_message_new(&message, "omapi_protocol_send_status");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = omapi_set_int_value(message, NULL, "op", OMAPI_OP_STATUS);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = omapi_set_int_value(message, NULL, "rid", (int)rid);
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = omapi_set_int_value(message, NULL, "result",
|
|
|
|
(int)waitstatus);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a message has been provided, send it.
|
|
|
|
*/
|
|
|
|
if (result == ISC_R_SUCCESS && msg != NULL)
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_set_string_value(message, NULL, "message", msg);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&message, "omapi_protocol_send_status");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_message(po, id, message, NULL));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_protocol_send_update(omapi_object_t *po, omapi_object_t *id,
|
|
|
|
unsigned int rid, omapi_object_t *object)
|
1999-10-27 22:24:32 +00:00
|
|
|
{
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
|
|
|
omapi_object_t *message = NULL;
|
|
|
|
|
|
|
|
REQUIRE(po != NULL && po->type == omapi_type_protocol);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_message_new(&message, "omapi_protocol_send_update");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
result = omapi_set_int_value(message, NULL, "op", OMAPI_OP_UPDATE);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS && rid != 0) {
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_handle_t handle;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_set_int_value(message, NULL, "rid", (int)rid);
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = omapi_object_handle(&handle, object);
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = omapi_set_int_value(message, NULL,
|
|
|
|
"handle", (int)handle);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = omapi_set_object_value(message, NULL,
|
|
|
|
"object", object);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-04 20:04:42 +00:00
|
|
|
OBJECT_DEREF(&message, "dhcpctl_open_object");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_message(po, id, message, NULL));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|