45 isc_result_t
find_class (
struct class **c,
const char *n,
const char *f,
int l)
65 void classify (
struct packet *packet,
struct class *
class) { }
67 static void usage (
const char *s) {
68 fprintf (stderr,
"Usage: %s\n", s);
72 static void check (isc_result_t status,
const char *func) {
73 if (status != ISC_R_SUCCESS) {
74 fprintf (stderr,
"%s: %s\n", func, isc_result_totext (status));
80 main(
int argc,
char **argv) {
81 isc_result_t status, waitstatus;
86 const char *name = 0, *algorithm =
"hmac-md5";
89 const char *server =
"127.0.0.1";
101 progname =
"omshell";
106 for (i = 1; i < argc; i++) {
107 usage(isc_file_basename(progname));
111 openlog (isc_file_basename(progname),
114 if (status != ISC_R_SUCCESS) {
115 fprintf (stderr,
"dhcpctl_initialize: %s\n",
116 isc_result_totext (status));
120 memset (&oh, 0,
sizeof oh);
124 }
else if (oh == NULL) {
125 printf (
"obj: <null>\n");
137 (
int)(r -> rtype -> u .
buffer . len),
138 r -> rtype -> u .
buffer . value);
141 for (i = 0; i < g -> nvalues; i++) {
144 if (!g -> values [i])
147 printf (
"%.*s = ", (
int)v -> name -> len,
154 switch (v -> value -> type) {
157 v -> value -> u . integer);
161 printf (
"\"%.*s\"\n",
162 (
int) v -> value -> u.buffer.len,
163 v -> value -> u.buffer.
value);
169 sizeof(hex_buf), hex_buf);
170 printf(
"%s\n", hex_buf);
180 fputs (
"> ", stdout);
182 if (fgets (buf,
sizeof(buf), stdin) == NULL)
185 status =
new_parse (&cfile, -1, buf, strlen(buf),
"<STDIN>", 1);
186 check(status,
"new_parse()");
188 token =
next_token (&val, (
unsigned *)0, cfile);
201 printf (
"Commands:\n");
202 printf (
" port <server omapi port>\n");
203 printf (
" server <server address>\n");
204 printf (
" key <key name> <key value>\n");
205 printf (
" connect\n");
206 printf (
" new <object-type>\n");
207 printf (
" set <name> = <value>\n");
208 printf (
" create\n");
210 printf (
" update\n");
211 printf (
" unset <name>\n");
212 printf (
" refresh\n");
213 printf (
" remove\n");
218 token =
next_token (&val, (
unsigned *)0, cfile);
221 se = getservbyname (val,
"tcp");
223 port = ntohs (se -> s_port);
225 printf (
"unknown service name: %s\n", val);
228 }
else if (token ==
NUMBER) {
232 printf (
"usage: port <port>\n");
235 token =
next_token (&val, (
unsigned *)0, cfile);
237 printf (
"usage: port <server>\n");
244 token =
next_token (&val, (
unsigned *)0, cfile);
246 int alen = (
sizeof buf) - 1;
251 if (len + 1 > alen) {
253 printf (
"usage: server <server>\n");
258 token =
next_token (&val, (
unsigned *)0, cfile);
262 token =
next_token (&val, (
unsigned *)0, cfile);
270 token =
next_token (&val, (
unsigned *)0, cfile);
274 token =
next_token (&val, (
unsigned *)0, cfile);
282 token =
next_token (&val, (
unsigned *)0, cfile);
286 token =
next_token (&val, (
unsigned *)0, cfile);
297 printf (
"usage: server <server>\n");
304 printf (
"no memory to store server name.\n");
311 token =
next_token (&val, (
unsigned *)0, cfile);
313 printf (
"usage: server <server>\n");
320 token =
peek_token(&val, (
unsigned *)0, cfile);
322 token =
next_token (&val, (
unsigned *)0, cfile);
324 printf (
"usage: key <name> <value>\n");
330 printf (
"no memory for key name.\n");
338 printf (
"usage: key <name> <value>\n");
345 memset (&secret, 0,
sizeof secret);
350 token =
next_token (&val, (
unsigned *)0, cfile);
352 printf (
"usage: key <name> <secret>\n");
359 token =
next_token (&val, (
unsigned *)0, cfile);
361 printf (
"usage: connect\n");
374 if (status != ISC_R_SUCCESS) {
376 "Cannot create authenticator: %s\n",
377 isc_result_totext (status));
382 memset (&connection, 0,
sizeof connection);
384 server, port, authenticator);
385 if (status != ISC_R_SUCCESS) {
386 fprintf (stderr,
"dhcpctl_connect: %s\n",
387 isc_result_totext (status));
394 token =
next_token (&val, (
unsigned *)0, cfile);
396 printf (
"usage: new <object-type>\n");
401 printf (
"an object is already open.\n");
407 printf (
"not connected.\n");
413 if (status != ISC_R_SUCCESS) {
414 printf (
"can't create object: %s\n",
415 isc_result_totext (status));
419 token =
next_token (&val, (
unsigned *)0, cfile);
421 printf (
"usage: new <object-type>\n");
428 token =
next_token (&val, (
unsigned *)0, cfile);
430 printf (
"usage: close\n");
436 printf (
"not connected.\n");
442 printf (
"not open.\n");
451 token =
next_token (&val, (
unsigned *)0, cfile);
455 printf (
"usage: set <name> = <value>\n");
461 printf (
"no open object.\n");
467 printf (
"not connected.\n");
473 strlcpy (s1, val,
sizeof(s1));
476 strncat (s1, val,
sizeof(s1)-strlen(s1)-1);
479 token =
next_token (&val, (
unsigned *)0, cfile);
483 token =
next_token (&val, (
unsigned *)0, cfile);
487 token =
next_token (&val, (
unsigned *)0, cfile);
492 token =
peek_token (&val, (
unsigned *)0, cfile);
496 else if (token ==
DOT) {
500 int intval = atoi (val);
503 "dotted octet > 255: %s",
510 (
unsigned *)0, cfile);
515 (
unsigned *)0, cfile)) ==
DOT)
517 }
while (token ==
NUMBER);
524 token =
next_token (&val, (
unsigned *)0, cfile);
538 (
unsigned *)0, cfile);
542 (
unsigned *)0, cfile);
543 }
while (token ==
NUMBER ||
546 (
unsigned)(s - buf), s1);
550 printf (
"invalid value.\n");
559 token =
next_token (&val, (
unsigned *)0, cfile);
563 printf (
"usage: unset <name>\n");
569 printf (
"no open object.\n");
575 printf (
"not connected.\n");
581 strlcpy (s1, val,
sizeof(s1));
584 strncat (s1, val,
sizeof(s1)-strlen(s1)-1);
587 token =
next_token (&val, (
unsigned *)0, cfile);
598 token =
next_token (&val, (
unsigned *)0, cfile);
600 printf (
"usage: %s\n", val);
606 printf (
"not connected.\n");
612 printf (
"you must make a new object first!\n");
623 if (status == ISC_R_SUCCESS)
626 if (status == ISC_R_SUCCESS)
628 if (status != ISC_R_SUCCESS) {
629 printf (
"can't open object: %s\n",
630 isc_result_totext (status));
637 token =
next_token (&val, (
unsigned *)0, cfile);
639 printf (
"usage: %s\n", val);
645 printf (
"not connected.\n");
651 printf (
"you haven't opened an object yet!\n");
657 if (status == ISC_R_SUCCESS)
660 if (status == ISC_R_SUCCESS)
662 if (status != ISC_R_SUCCESS) {
663 printf (
"can't update object: %s\n",
664 isc_result_totext (status));
671 token =
next_token (&val, (
unsigned *)0, cfile);
673 printf (
"usage: remove\n");
679 printf (
"not connected.\n");
684 printf (
"no object.\n");
689 if (status == ISC_R_SUCCESS)
692 if (status == ISC_R_SUCCESS)
694 if (status != ISC_R_SUCCESS) {
695 printf (
"can't destroy object: %s\n",
696 isc_result_totext (status));
703 token =
next_token (&val, (
unsigned *)0, cfile);
705 printf (
"usage: refresh\n");
711 printf (
"not connected.\n");
716 printf (
"no object.\n");
721 if (status == ISC_R_SUCCESS)
724 if (status == ISC_R_SUCCESS)
726 if (status != ISC_R_SUCCESS) {
727 printf (
"can't refresh object: %s\n",
728 isc_result_totext (status));
745 return ISC_R_SUCCESS;
void print_hex_or_string(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
isc_result_t end_parse(struct parse **cfile)
isc_result_t dhcp_set_control_state(control_object_state_t oldstate, control_object_state_t newstate)
dhcpctl_status dhcpctl_set_null_value(dhcpctl_handle h, const char *value_name)
dhcpctl_status dhcpctl_connect(dhcpctl_handle *connection, const char *server_name, int port, dhcpctl_handle authinfo)
int check_collection(struct packet *p, struct lease *l, struct collection *c)
omapi_typed_data_t * value
dhcpctl_status dhcpctl_new_object(dhcpctl_handle *, dhcpctl_handle, const char *)
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
dhcpctl_status dhcpctl_open_object(dhcpctl_handle, dhcpctl_handle, int)
void bootp(struct packet *packet)
dhcpctl_status dhcpctl_initialize()
struct omapi_typed_data_t::@3::@4 buffer
int main(int argc, char **argv)
dhcpctl_status dhcpctl_wait_for_completion(dhcpctl_handle h, dhcpctl_status *s)
enum dhcp_token next_token(const char **rval, unsigned *rlen, struct parse *cfile)
#define DHCPD_LOG_FACILITY
dhcpctl_status dhcpctl_set_data_value(dhcpctl_handle h, const char *value, unsigned len, const char *value_name)
void convert_num(struct parse *cfile, unsigned char *buf, const char *str, int base, unsigned size)
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
dhcpctl_status dhcpctl_set_int_value(dhcpctl_handle h, int value, const char *value_name)
#define dhcpctl_null_handle
union omapi_typed_data_t::@3 u
dhcpctl_status dhcpctl_object_remove(dhcpctl_handle connection, dhcpctl_handle h)
void skip_to_semi(struct parse *cfile)
void * dmalloc(size_t, const char *, int)
char * parse_host_name(struct parse *cfile)
int parse_allow_deny(struct option_cache **oc, struct parse *cfile, int flag)
void dhcpv6(struct packet *)
int parse_base64(struct data_string *data, struct parse *cfile)
dhcpctl_status dhcpctl_object_refresh(dhcpctl_handle connection, dhcpctl_handle h)
isc_result_t find_class(struct class **c, const char *n, const char *f, int l)
dhcpctl_status dhcpctl_new_authenticator(dhcpctl_handle *, const char *, const char *, const unsigned char *, unsigned)
dhcpctl_status dhcpctl_set_string_value(dhcpctl_handle h, const char *value, const char *value_name)
dhcpctl_status dhcpctl_object_update(dhcpctl_handle connection, dhcpctl_handle h)
const unsigned char * data
void classify(struct packet *packet, struct class *class)
int parse_warn(struct parse *cfile, const char *fmt,...)
void dhcp(struct packet *packet)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)