00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __OMAPIP_OMAPIP_P_H__
00031 #define __OMAPIP_OMAPIP_P_H__
00032
00033 #ifndef __CYGWIN32__
00034 #include <sys/types.h>
00035 #include <netinet/in.h>
00036 #include <sys/socket.h>
00037 #include <sys/un.h>
00038 #include <arpa/inet.h>
00039
00040 #include <netdb.h>
00041 #else
00042 #define fd_set cygwin_fd_set
00043 #include <sys/types.h>
00044 #endif
00045 #include <fcntl.h>
00046 #include <stdio.h>
00047 #include <unistd.h>
00048 #include <string.h>
00049 #include <memory.h>
00050 #include <stdlib.h>
00051 #include <sys/stat.h>
00052 #include <ctype.h>
00053 #include <time.h>
00054
00055
00056
00057
00058
00059
00060
00061 #include <dst/dst.h>
00062 #include "result.h"
00063
00064 #include <omapip/convert.h>
00065 #include <omapip/hash.h>
00066 #include <omapip/omapip.h>
00067 #include <omapip/trace.h>
00068
00069
00070
00071 #define SIG_MODE_INIT 1
00072 #define SIG_MODE_UPDATE 2
00073 #define SIG_MODE_FINAL 4
00074 #define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
00075
00076
00077 typedef struct {
00078 u_int32_t authlen;
00079 u_int32_t authid;
00080 u_int32_t op;
00081 omapi_handle_t handle;
00082
00083 u_int32_t id;
00084 u_int32_t rid;
00085 } omapi_protocol_header_t;
00086
00087 #define OMAPI_PROTOCOL_VERSION 100
00088
00089 #define OMAPI_OP_OPEN 1
00090 #define OMAPI_OP_REFRESH 2
00091 #define OMAPI_OP_UPDATE 3
00092 #define OMAPI_OP_NOTIFY 4
00093 #define OMAPI_OP_STATUS 5
00094 #define OMAPI_OP_DELETE 6
00095
00096 typedef enum {
00097 omapi_connection_unconnected,
00098 omapi_connection_connecting,
00099 omapi_connection_connected,
00100 omapi_connection_disconnecting,
00101 omapi_connection_closed
00102 } omapi_connection_state_t;
00103
00104 typedef enum {
00105 omapi_protocol_intro_wait,
00106 omapi_protocol_header_wait,
00107 omapi_protocol_signature_wait,
00108 omapi_protocol_name_wait,
00109 omapi_protocol_name_length_wait,
00110 omapi_protocol_value_wait,
00111 omapi_protocol_value_length_wait
00112 } omapi_protocol_state_t;
00113
00114 typedef struct __omapi_message_object {
00115 OMAPI_OBJECT_PREAMBLE;
00116 struct __omapi_message_object *next, *prev;
00117 omapi_object_t *object;
00118 omapi_object_t *notify_object;
00119 struct __omapi_protocol_object *protocol_object;
00120 u_int32_t authlen;
00121 omapi_typed_data_t *authenticator;
00122 u_int32_t authid;
00123 omapi_object_t *id_object;
00124 u_int32_t op;
00125 u_int32_t h;
00126 u_int32_t id;
00127 u_int32_t rid;
00128 } omapi_message_object_t;
00129
00130 typedef struct __omapi_remote_auth {
00131 struct __omapi_remote_auth *next;
00132 omapi_handle_t remote_handle;
00133 omapi_object_t *a;
00134 } omapi_remote_auth_t;
00135
00136 typedef struct __omapi_protocol_object {
00137 OMAPI_OBJECT_PREAMBLE;
00138 u_int32_t header_size;
00139 u_int32_t protocol_version;
00140 u_int32_t next_xid;
00141
00142 omapi_protocol_state_t state;
00143 int reading_message_values;
00144
00145 omapi_message_object_t *message;
00146 omapi_data_string_t *name;
00147 omapi_typed_data_t *value;
00148 isc_result_t verify_result;
00149 omapi_remote_auth_t *default_auth;
00150 omapi_remote_auth_t *remote_auth_list;
00151
00152
00153 isc_boolean_t insecure;
00154
00155
00156 isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
00157 } omapi_protocol_object_t;
00158
00159 typedef struct {
00160 OMAPI_OBJECT_PREAMBLE;
00161
00162 isc_boolean_t insecure;
00163
00164
00165 isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
00166 } omapi_protocol_listener_object_t;
00167
00168 #include <omapip/buffer.h>
00169
00170 typedef struct __omapi_listener_object {
00171 OMAPI_OBJECT_PREAMBLE;
00172 int socket;
00173 int index;
00174 struct sockaddr_in address;
00175 isc_result_t (*verify_addr) (omapi_object_t *, omapi_addr_t *);
00176 } omapi_listener_object_t;
00177
00178 typedef struct __omapi_connection_object {
00179 OMAPI_OBJECT_PREAMBLE;
00180 int socket;
00181 int32_t index;
00182 omapi_connection_state_t state;
00183 struct sockaddr_in remote_addr;
00184 struct sockaddr_in local_addr;
00185 omapi_addr_list_t *connect_list;
00186
00187 int cptr;
00188 u_int32_t bytes_needed;
00189 u_int32_t in_bytes;
00190 omapi_buffer_t *inbufs;
00191 u_int32_t out_bytes;
00192 omapi_buffer_t *outbufs;
00193 omapi_listener_object_t *listener;
00194
00195 dst_key_t *in_key;
00196
00197 void *in_context;
00198 dst_key_t *out_key;
00199
00200 void *out_context;
00201 } omapi_connection_object_t;
00202
00203 typedef struct __omapi_io_object {
00204 OMAPI_OBJECT_PREAMBLE;
00205 struct __omapi_io_object *next;
00206 int (*readfd) (omapi_object_t *);
00207 int (*writefd) (omapi_object_t *);
00208 isc_result_t (*reader) (omapi_object_t *);
00209 isc_result_t (*writer) (omapi_object_t *);
00210 isc_result_t (*reaper) (omapi_object_t *);
00211 isc_socket_t *fd;
00212 isc_boolean_t closed;
00213 } omapi_io_object_t;
00214
00215 typedef struct __omapi_generic_object {
00216 OMAPI_OBJECT_PREAMBLE;
00217 omapi_value_t **values;
00218 u_int8_t *changed;
00219 int nvalues, va_max;
00220 } omapi_generic_object_t;
00221
00222 typedef struct __omapi_waiter_object {
00223 OMAPI_OBJECT_PREAMBLE;
00224 int ready;
00225 isc_result_t waitstatus;
00226 struct __omapi_waiter_object *next;
00227 } omapi_waiter_object_t;
00228
00229 #define OMAPI_HANDLE_TABLE_SIZE 120
00230
00231 typedef struct __omapi_handle_table {
00232 omapi_handle_t first, limit;
00233 omapi_handle_t next;
00234 int leafp;
00235 union {
00236 omapi_object_t *object;
00237 struct __omapi_handle_table *table;
00238 } children [OMAPI_HANDLE_TABLE_SIZE];
00239 } omapi_handle_table_t;
00240
00241 #include <omapip/alloc.h>
00242
00243 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol, omapi_protocol_object_t,
00244 omapi_type_protocol)
00245 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol_listener,
00246 omapi_protocol_listener_object_t,
00247 omapi_type_protocol_listener)
00248 OMAPI_OBJECT_ALLOC_DECL (omapi_connection,
00249 omapi_connection_object_t, omapi_type_connection)
00250 OMAPI_OBJECT_ALLOC_DECL (omapi_listener,
00251 omapi_listener_object_t, omapi_type_listener)
00252 OMAPI_OBJECT_ALLOC_DECL (omapi_io,
00253 omapi_io_object_t, omapi_type_io_object)
00254 OMAPI_OBJECT_ALLOC_DECL (omapi_waiter,
00255 omapi_waiter_object_t, omapi_type_waiter)
00256 OMAPI_OBJECT_ALLOC_DECL (omapi_generic,
00257 omapi_generic_object_t, omapi_type_generic)
00258 OMAPI_OBJECT_ALLOC_DECL (omapi_message,
00259 omapi_message_object_t, omapi_type_message)
00260
00261 isc_result_t omapi_connection_sign_data (int mode,
00262 dst_key_t *key,
00263 void **context,
00264 const unsigned char *data,
00265 const unsigned len,
00266 omapi_typed_data_t **result);
00267 isc_result_t omapi_listener_connect (omapi_connection_object_t **obj,
00268 omapi_listener_object_t *listener,
00269 int socket,
00270 struct sockaddr_in *remote_addr);
00271 void omapi_listener_trace_setup (void);
00272 void omapi_connection_trace_setup (void);
00273 void omapi_buffer_trace_setup (void);
00274 void omapi_connection_register (omapi_connection_object_t *,
00275 const char *, int);
00276 OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t);
00277 OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t);
00278
00279 isc_result_t omapi_handle_clear(omapi_handle_t);
00280
00281 extern int log_priority;
00282 extern int log_perror;
00283 extern void (*log_cleanup) (void);
00284
00285 void log_fatal (const char *, ...)
00286 __attribute__((__format__(__printf__,1,2))) ISC_DHCP_NORETURN;
00287 int log_error (const char *, ...)
00288 __attribute__((__format__(__printf__,1,2)));
00289 int log_info (const char *, ...)
00290 __attribute__((__format__(__printf__,1,2)));
00291 int log_debug (const char *, ...)
00292 __attribute__((__format__(__printf__,1,2)));
00293 void do_percentm (char *obuf, const char *ibuf);
00294
00295 isc_result_t uerr2isc (int);
00296 isc_result_t ns_rcode_to_isc (int);
00297
00298 extern omapi_message_object_t *omapi_registered_messages;
00299
00300 #endif