44 isc_result_t
find_class (
struct class **c,
const char *n,
const char *f,
int l)
61 return ISC_R_NOTIMPLEMENTED;
72 static void usage (
const char *s) {
73 fprintf (stderr,
"Usage: %s\n", s);
77 static void check (isc_result_t status,
const char *func) {
79 fprintf (stderr,
"%s: %s\n", func, isc_result_totext (status));
85 main(
int argc,
char **argv) {
86 isc_result_t status, waitstatus;
91 const char *name = 0, *algorithm =
"hmac-md5";
94 const char *server =
"127.0.0.1";
106 progname =
"omshell";
111 for (i = 1; i < argc; i++) {
112 usage(isc_file_basename(progname));
116 openlog (isc_file_basename(progname),
120 fprintf (stderr,
"dhcpctl_initialize: %s\n",
121 isc_result_totext (status));
125 memset (&oh, 0,
sizeof oh);
129 }
else if (oh == NULL) {
130 printf (
"obj: <null>\n");
142 (
int)(r -> rtype -> u .
buffer . len),
143 r -> rtype -> u .
buffer . value);
146 for (i = 0; i < g -> nvalues; i++) {
149 if (!g -> values [i])
152 printf (
"%.*s = ", (
int)v -> name -> len,
159 switch (v -> value -> type) {
162 v -> value -> u . integer);
166 printf (
"\"%.*s\"\n",
167 (
int) v -> value -> u.buffer.len,
168 v -> value -> u.buffer.
value);
174 sizeof(hex_buf), hex_buf);
175 printf(
"%s\n", hex_buf);
185 fputs (
"> ", stdout);
187 if (fgets (buf,
sizeof(buf), stdin) == NULL)
190 status =
new_parse (&cfile, -1, buf, strlen(buf),
"<STDIN>", 1);
191 check(status,
"new_parse()");
193 token =
next_token (&val, (
unsigned *)0, cfile);
206 printf (
"Commands:\n");
207 printf (
" port <server omapi port>\n");
208 printf (
" server <server address>\n");
209 printf (
" key <key name> <key value>\n");
210 printf (
" connect\n");
211 printf (
" new <object-type>\n");
212 printf (
" set <name> = <value>\n");
213 printf (
" create\n");
215 printf (
" update\n");
216 printf (
" unset <name>\n");
217 printf (
" refresh\n");
218 printf (
" remove\n");
223 token =
next_token (&val, (
unsigned *)0, cfile);
226 se = getservbyname (val,
"tcp");
228 port = ntohs (se -> s_port);
230 printf (
"unknown service name: %s\n", val);
233 }
else if (token ==
NUMBER) {
237 printf (
"usage: port <port>\n");
240 token =
next_token (&val, (
unsigned *)0, cfile);
242 printf (
"usage: port <server>\n");
249 token =
next_token (&val, (
unsigned *)0, cfile);
251 int alen = (
sizeof buf) - 1;
256 if (len + 1 > alen) {
258 printf (
"usage: server <server>\n");
263 token =
next_token (&val, (
unsigned *)0, cfile);
267 token =
next_token (&val, (
unsigned *)0, cfile);
275 token =
next_token (&val, (
unsigned *)0, cfile);
279 token =
next_token (&val, (
unsigned *)0, cfile);
287 token =
next_token (&val, (
unsigned *)0, cfile);
291 token =
next_token (&val, (
unsigned *)0, cfile);
302 printf (
"usage: server <server>\n");
309 printf (
"no memory to store server name.\n");
316 token =
next_token (&val, (
unsigned *)0, cfile);
318 printf (
"usage: server <server>\n");
326 token =
next_token (&val, (
unsigned *)0, cfile);
328 printf (
"missing or invalid algorithm name\n");
329 printf (
"usage: key-algoritm <algorithm name>\n");
336 printf (
"no memory for algorithm name.\n");
344 token =
next_token (&val, (
unsigned *)0, cfile);
346 printf (
"extra information after %s\n", algorithm);
347 printf (
"usage: key-algorithm <algorithm name>\n");
355 token =
peek_token(&val, (
unsigned *)0, cfile);
357 token =
next_token (&val, (
unsigned *)0, cfile);
359 printf (
"usage: key <name> <value>\n");
365 printf (
"no memory for key name.\n");
373 printf (
"usage: key <name> <value>\n");
380 memset (&secret, 0,
sizeof secret);
386 token =
next_token (&val, (
unsigned *)0, cfile);
388 printf (
"usage: key <name> <value>\n");
396 token =
next_token (&val, (
unsigned *)0, cfile);
398 printf (
"usage: connect\n");
413 "Cannot create authenticator: %s\n",
414 isc_result_totext (status));
419 memset (&connection, 0,
sizeof connection);
421 server, port, authenticator);
423 fprintf (stderr,
"dhcpctl_connect: %s\n",
424 isc_result_totext (status));
431 token =
next_token (&val, (
unsigned *)0, cfile);
433 printf (
"usage: new <object-type>\n");
438 printf (
"an object is already open.\n");
444 printf (
"not connected.\n");
451 printf (
"can't create object: %s\n",
452 isc_result_totext (status));
456 token =
next_token (&val, (
unsigned *)0, cfile);
458 printf (
"usage: new <object-type>\n");
465 token =
next_token (&val, (
unsigned *)0, cfile);
467 printf (
"usage: close\n");
473 printf (
"not connected.\n");
479 printf (
"not open.\n");
488 token =
next_token (&val, (
unsigned *)0, cfile);
492 printf (
"usage: set <name> = <value>\n");
498 printf (
"no open object.\n");
504 printf (
"not connected.\n");
510 strlcpy (s1, val,
sizeof(s1));
513 strncat (s1, val,
sizeof(s1)-strlen(s1)-1);
516 token =
next_token (&val, (
unsigned *)0, cfile);
520 token =
next_token (&val, (
unsigned *)0, cfile);
524 token =
next_token (&val, (
unsigned *)0, cfile);
529 token =
peek_token (&val, (
unsigned *)0, cfile);
533 else if (token ==
DOT) {
537 int intval = atoi (val);
540 "dotted octet > 255: %s",
547 (
unsigned *)0, cfile);
552 (
unsigned *)0, cfile)) ==
DOT)
554 }
while (token ==
NUMBER);
561 token =
next_token (&val, (
unsigned *)0, cfile);
575 (
unsigned *)0, cfile);
579 (
unsigned *)0, cfile);
580 }
while (token ==
NUMBER ||
583 (
unsigned)(s - buf), s1);
587 printf (
"invalid value.\n");
596 token =
next_token (&val, (
unsigned *)0, cfile);
600 printf (
"usage: unset <name>\n");
606 printf (
"no open object.\n");
612 printf (
"not connected.\n");
618 strlcpy (s1, val,
sizeof(s1));
621 strncat (s1, val,
sizeof(s1)-strlen(s1)-1);
624 token =
next_token (&val, (
unsigned *)0, cfile);
635 token =
next_token (&val, (
unsigned *)0, cfile);
637 printf (
"usage: %s\n", val);
643 printf (
"not connected.\n");
649 printf (
"you must make a new object first!\n");
666 printf (
"can't open object: %s\n",
667 isc_result_totext (status));
674 token =
next_token (&val, (
unsigned *)0, cfile);
676 printf (
"usage: %s\n", val);
682 printf (
"not connected.\n");
688 printf (
"you haven't opened an object yet!\n");
700 printf (
"can't update object: %s\n",
701 isc_result_totext (status));
708 token =
next_token (&val, (
unsigned *)0, cfile);
710 printf (
"usage: remove\n");
716 printf (
"not connected.\n");
721 printf (
"no object.\n");
732 printf (
"can't destroy object: %s\n",
733 isc_result_totext (status));
740 token =
next_token (&val, (
unsigned *)0, cfile);
742 printf (
"usage: refresh\n");
748 printf (
"not connected.\n");
753 printf (
"no object.\n");
764 printf (
"can't refresh object: %s\n",
765 isc_result_totext (status));
void print_hex_or_string(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
isc_result_t end_parse(struct parse **cfile)
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)
omapi_typed_data_t * value
void bootp(struct packet *packet)
int parse_allow_deny(struct option_cache **oc, struct parse *cfile, int flag)
dhcpctl_status dhcpctl_new_object(dhcpctl_handle *, dhcpctl_handle, const char *)
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
parse_warn(cfile,"expecting ip-address or ip-address/prefixlen")
dhcpctl_status dhcpctl_open_object(dhcpctl_handle, dhcpctl_handle, int)
dhcpctl_status dhcpctl_initialize()
struct omapi_typed_data_t::@3::@4 buffer
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)
void classify(struct packet *packet, struct class *class)
#define DHCPD_LOG_FACILITY
int main(int argc, char **argv)
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 check_collection(struct packet *packet, struct lease *lease, struct collection *collection)
void dhcpv6(struct packet *)
int parse_base64(struct data_string *data, struct parse *cfile)
isc_result_t find_class(struct class **c, const char *s, const char *file, int line)
dhcpctl_status dhcpctl_object_refresh(dhcpctl_handle connection, dhcpctl_handle h)
void dhcp(struct packet *packet)
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)
isc_result_t dhcp_set_control_state(control_object_state_t oldstate, control_object_state_t newstate)
dhcpctl_status dhcpctl_object_update(dhcpctl_handle connection, dhcpctl_handle h)
const unsigned char * data
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)