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 #include "dhcpd.h"
00030 #include <omapip/omapip_p.h>
00031 #include "dhcpctl.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 dhcpctl_status dhcpctl_new_authenticator (dhcpctl_handle *h,
00044 const char *name,
00045 const char *algorithm,
00046 const unsigned char *secret,
00047 unsigned secret_len)
00048 {
00049 struct auth_key *key = (struct auth_key *)0;
00050 isc_result_t status;
00051
00052 status = omapi_auth_key_new (&key, MDL);
00053 if (status != ISC_R_SUCCESS)
00054 return status;
00055
00056 key -> name = dmalloc (strlen (name) + 1, MDL);
00057 if (!key -> name) {
00058 omapi_auth_key_dereference (&key, MDL);
00059 return ISC_R_NOMEMORY;
00060 }
00061 strcpy (key -> name, name);
00062
00063
00064
00065 if (strchr (algorithm, '.') == 0) {
00066 static char add[] = ".SIG-ALG.REG.INT.";
00067 key -> algorithm = dmalloc (strlen (algorithm) +
00068 sizeof (add), MDL);
00069 if (!key -> algorithm) {
00070 omapi_auth_key_dereference (&key, MDL);
00071 return ISC_R_NOMEMORY;
00072 }
00073 strcpy (key -> algorithm, algorithm);
00074 strcat (key -> algorithm, add);
00075 } else {
00076 key -> algorithm = dmalloc (strlen (algorithm) + 1, MDL);
00077 if (!key -> algorithm) {
00078 omapi_auth_key_dereference (&key, MDL);
00079 return ISC_R_NOMEMORY;
00080 }
00081 strcpy (key -> algorithm, algorithm);
00082 }
00083
00084 status = omapi_data_string_new (&key -> key, secret_len, MDL);
00085 if (status != ISC_R_SUCCESS) {
00086 omapi_auth_key_dereference (&key, MDL);
00087 return status;
00088 }
00089 memcpy (key -> key -> value, secret, secret_len);
00090 key -> key -> len = secret_len;
00091
00092 *h = (dhcpctl_handle) key;
00093 return ISC_R_SUCCESS;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 dhcpctl_status dhcpctl_new_object (dhcpctl_handle *h,
00107 dhcpctl_handle connection,
00108 const char *object_type)
00109 {
00110 dhcpctl_remote_object_t *m;
00111 omapi_object_t *g;
00112 isc_result_t status;
00113
00114 m = (dhcpctl_remote_object_t *)0;
00115 status = omapi_object_allocate((omapi_object_t **)&m,
00116 dhcpctl_remote_type, 0, MDL);
00117 if (status != ISC_R_SUCCESS)
00118 return status;
00119
00120 g = (omapi_object_t *)0;
00121 status = omapi_generic_new (&g, MDL);
00122 if (status != ISC_R_SUCCESS) {
00123 dfree (m, MDL);
00124 return status;
00125 }
00126 status = omapi_object_reference (&m -> inner, g, MDL);
00127 if (status != ISC_R_SUCCESS) {
00128 omapi_object_dereference ((omapi_object_t **)&m, MDL);
00129 omapi_object_dereference (&g, MDL);
00130 return status;
00131 }
00132 status = omapi_object_reference (&g -> outer,
00133 (omapi_object_t *)m, MDL);
00134
00135 if (status != ISC_R_SUCCESS) {
00136 omapi_object_dereference ((omapi_object_t **)&m, MDL);
00137 omapi_object_dereference (&g, MDL);
00138 return status;
00139 }
00140
00141 status = omapi_typed_data_new (MDL, &m -> rtype,
00142 omapi_datatype_string,
00143 object_type);
00144 if (status != ISC_R_SUCCESS) {
00145 omapi_object_dereference ((omapi_object_t **)&m, MDL);
00146 omapi_object_dereference (&g, MDL);
00147 return status;
00148 }
00149
00150 status = omapi_object_reference (h, (omapi_object_t *)m, MDL);
00151 omapi_object_dereference ((omapi_object_t **)&m, MDL);
00152 omapi_object_dereference (&g, MDL);
00153 if (status != ISC_R_SUCCESS)
00154 return status;
00155
00156 return status;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 dhcpctl_status dhcpctl_open_object (dhcpctl_handle h,
00172 dhcpctl_handle connection,
00173 int flags)
00174 {
00175 isc_result_t status;
00176 omapi_object_t *message = (omapi_object_t *)0;
00177 dhcpctl_remote_object_t *remote;
00178
00179 if (h -> type != dhcpctl_remote_type)
00180 return DHCP_R_INVALIDARG;
00181 remote = (dhcpctl_remote_object_t *)h;
00182
00183 status = omapi_message_new (&message, MDL);
00184 if (status != ISC_R_SUCCESS)
00185 return status;
00186 status = omapi_set_int_value (message, (omapi_object_t *)0,
00187 "op", OMAPI_OP_OPEN);
00188 if (status != ISC_R_SUCCESS) {
00189 omapi_object_dereference (&message, MDL);
00190 return status;
00191 }
00192 status = omapi_set_object_value (message, (omapi_object_t *)0,
00193 "object", h);
00194 if (status != ISC_R_SUCCESS) {
00195 omapi_object_dereference (&message, MDL);
00196 return status;
00197 }
00198 if (flags & DHCPCTL_CREATE) {
00199 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
00200 "create", 1);
00201 if (status != ISC_R_SUCCESS) {
00202 omapi_object_dereference (&message, MDL);
00203 return status;
00204 }
00205 }
00206 if (flags & DHCPCTL_UPDATE) {
00207 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
00208 "update", 1);
00209 if (status != ISC_R_SUCCESS) {
00210 omapi_object_dereference (&message, MDL);
00211 return status;
00212 }
00213 }
00214 if (flags & DHCPCTL_EXCL) {
00215 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
00216 "exclusive", 1);
00217 if (status != ISC_R_SUCCESS) {
00218 omapi_object_dereference (&message, MDL);
00219 return status;
00220 }
00221 }
00222
00223 if (remote -> rtype) {
00224 status = omapi_set_value_str (message, (omapi_object_t *)0,
00225 "type", remote -> rtype);
00226 if (status != ISC_R_SUCCESS) {
00227 omapi_object_dereference (&message, MDL);
00228 return status;
00229 }
00230 }
00231
00232 status = omapi_message_register (message);
00233 if (status != ISC_R_SUCCESS) {
00234 omapi_object_dereference (&message, MDL);
00235 return status;
00236 }
00237
00238 status = omapi_protocol_send_message (connection -> outer,
00239 (omapi_object_t *)0,
00240 message, (omapi_object_t *)0);
00241
00242 if (status != ISC_R_SUCCESS)
00243 omapi_message_unregister (message);
00244
00245 omapi_object_dereference (&message, MDL);
00246 return status;
00247 }
00248
00249
00250
00251 isc_result_t dhcpctl_remote_set_value (omapi_object_t *h,
00252 omapi_object_t *id,
00253 omapi_data_string_t *name,
00254 omapi_typed_data_t *value)
00255 {
00256 dhcpctl_remote_object_t *ro;
00257 unsigned long rh;
00258 isc_result_t status;
00259
00260 if (h -> type != dhcpctl_remote_type)
00261 return DHCP_R_INVALIDARG;
00262 ro = (dhcpctl_remote_object_t *)h;
00263
00264 if (!omapi_ds_strcmp (name, "remote-handle")) {
00265 status = omapi_get_int_value (&rh, value);
00266 if (status == ISC_R_SUCCESS)
00267 ro -> remote_handle = rh;
00268 return status;
00269 }
00270
00271 if (h -> inner && h -> inner -> type -> set_value)
00272 return (*(h -> inner -> type -> set_value))
00273 (h -> inner, id, name, value);
00274 return ISC_R_NOTFOUND;
00275 }
00276
00277 isc_result_t dhcpctl_remote_get_value (omapi_object_t *h,
00278 omapi_object_t *id,
00279 omapi_data_string_t *name,
00280 omapi_value_t **value)
00281 {
00282 if (h -> type != dhcpctl_remote_type)
00283 return DHCP_R_INVALIDARG;
00284
00285 if (h -> inner && h -> inner -> type -> get_value)
00286 return (*(h -> inner -> type -> get_value))
00287 (h -> inner, id, name, value);
00288 return ISC_R_NOTFOUND;
00289 }
00290
00291 isc_result_t dhcpctl_remote_signal_handler (omapi_object_t *o,
00292 const char *name, va_list ap)
00293 {
00294 dhcpctl_remote_object_t *p;
00295 omapi_typed_data_t *tv;
00296
00297 if (o -> type != dhcpctl_remote_type)
00298 return DHCP_R_INVALIDARG;
00299 p = (dhcpctl_remote_object_t *)o;
00300
00301 if (!strcmp (name, "updated")) {
00302 p -> waitstatus = ISC_R_SUCCESS;
00303 if (o -> inner -> type == omapi_type_generic)
00304 omapi_generic_clear_flags (o -> inner);
00305 return omapi_signal_in (o -> inner, "ready");
00306 }
00307 if (!strcmp (name, "status")) {
00308 p -> waitstatus = va_arg (ap, isc_result_t);
00309 if (p -> message)
00310 omapi_typed_data_dereference (&p -> message, MDL);
00311 tv = va_arg (ap, omapi_typed_data_t *);
00312 if (tv)
00313 omapi_typed_data_reference (&p -> message, tv, MDL);
00314 return omapi_signal_in (o -> inner, "ready");
00315 }
00316
00317 if (p -> inner && p -> inner -> type -> signal_handler)
00318 return (*(p -> inner -> type -> signal_handler))
00319 (p -> inner, name, ap);
00320
00321 return ISC_R_SUCCESS;
00322 }
00323
00324 isc_result_t dhcpctl_remote_destroy (omapi_object_t *h,
00325 const char *file, int line)
00326 {
00327 dhcpctl_remote_object_t *p;
00328 if (h -> type != dhcpctl_remote_type)
00329 return DHCP_R_INVALIDARG;
00330 p = (dhcpctl_remote_object_t *)h;
00331 if (p -> handle)
00332 omapi_object_dereference ((omapi_object_t **)&p -> handle,
00333 file, line);
00334 if (p -> rtype)
00335 omapi_typed_data_dereference ((omapi_typed_data_t **)&p->rtype,
00336 file, line);
00337 return ISC_R_SUCCESS;
00338 }
00339
00340
00341
00342
00343 isc_result_t dhcpctl_remote_stuff_values (omapi_object_t *c,
00344 omapi_object_t *id,
00345 omapi_object_t *p)
00346 {
00347 if (p -> type != dhcpctl_remote_type)
00348 return DHCP_R_INVALIDARG;
00349
00350 if (p -> inner && p -> inner -> type -> stuff_values)
00351 return (*(p -> inner -> type -> stuff_values)) (c, id,
00352 p -> inner);
00353 return ISC_R_SUCCESS;
00354 }
00355