commit ed19b3aa6d26aef32ca6bc590c1fc3ebbc2b9fdc from: Tracey Emery date: Fri Jul 17 20:23:11 2020 UTC fix thingsctl list things commit - f6d9e37d6ce756655c4cf785fd9a04d5d1680aea commit + ed19b3aa6d26aef32ca6bc590c1fc3ebbc2b9fdc blob - 324b35b44b121490745789d40d457af8f53d289b blob + a0362c09395f2cc2b753fafe550703313c6c5934 --- thingsctl/parser.c +++ thingsctl/parser.c @@ -55,7 +55,7 @@ static const struct token t_main[]; static const struct token t_show[]; static const struct token t_main[] = { - {KEYWORD, "reset", RESET, NULL}, + {KEYWORD, "reload", RELOAD, NULL}, {KEYWORD, "list", LIST, t_list}, {KEYWORD, "show", SHOW, t_show}, {KEYWORD, "log", NONE, t_log}, blob - 0e376804e4d9e81ca36283ca26bacf9beda1daa5 blob + 4b025c82e5266d19c384e4391442c67c32db7ea9 --- thingsctl/parser.h +++ thingsctl/parser.h @@ -25,8 +25,7 @@ enum actions { SHOW, SHOW_CONTROL, SHOW_PARENT, - SHOW_THING, - RESET + RELOAD }; struct parse_result { blob - a743e98a09278ad32b41df19b4150cfb8788c3c1 blob + 2c3c4ffa0cb484c10bf40f20463b54b683bdb4bb --- thingsctl/thingsctl.c +++ thingsctl/thingsctl.c @@ -131,11 +131,19 @@ main(int argc, char *argv[]) imsg_compose(ibuf, IMSG_GET_INFO_PARENT_REQUEST, 0, 0, -1, NULL, 0); break; - case SHOW_THING: - break; - case RESET: - imsg_compose(ibuf, IMSG_CTL_RESET, 0, 0, -1, &v, sizeof(v)); - printf("reset request sent.\n"); + case RELOAD: + printf("\nAll things and sockets will be reset.\n"); + printf("This can have unintended consequences!\n"); + printf("For example, all clients will have to reconnect.\n\n"); + printf("Are you sure you want to reload the config? (y|n) "); + ch = getchar(); + if (ch == 'y' || ch == 'Y') { + imsg_compose(ibuf, IMSG_CTL_RESET, 0, 0, -1, &v, + sizeof(v)); + printf("Reload request sent\n"); + } else + printf("Reload request ignored\n"); + printf("\n"); done = 1; break; default: @@ -188,7 +196,7 @@ show_parent_msg(struct imsg *imsg) switch (imsg->hdr.type) { case IMSG_GET_INFO_PARENT_DATA: npi = imsg->data; - printf("parent says: Logging level is "); + printf("Parent says: Logging level is "); if (npi->verbose == 2) printf("debug"); else if (npi->verbose == 1) @@ -208,28 +216,6 @@ show_parent_msg(struct imsg *imsg) } int -list_things_msg(struct imsg *imsg) -{ - struct thing *nei; - - switch (imsg->hdr.type) { - case IMSG_GET_INFO_THINGS_DATA: - nei = (struct thing *) imsg->data; - printf("Thing: '%s'\n", nei->name); - printf("\tPassword: %s\n", nei->password); - printf("\n"); - break; - case IMSG_GET_INFO_THINGS_END_DATA: - case IMSG_CTL_END: - return (1); - default: - break; - } - - return (0); -} - -int show_control_msg(struct imsg *imsg) { struct thingsd_control_info *nci; @@ -237,7 +223,7 @@ show_control_msg(struct imsg *imsg) switch (imsg->hdr.type) { case IMSG_GET_INFO_CONTROL_DATA: nci = imsg->data; - printf("parent says: Logging level is "); + printf("Control says: Logging level is "); if (nci->verbose == 2) printf("debug"); else if (nci->verbose == 1) @@ -255,3 +241,65 @@ show_control_msg(struct imsg *imsg) return (0); } + +int +list_things_msg(struct imsg *imsg) +{ + struct thing *nti; + + switch (imsg->hdr.type) { + case IMSG_GET_INFO_THINGS_DATA: + nti = (struct thing *) imsg->data; + + + printf("\nThing Name:\t\t\t%s\n", nti->name); + switch(nti->type) { + case TCP: + printf("\tIP Addr:\t\t%s\n", nti->ipaddr); + printf("\tConnect Port:\t\t%d\n", nti->conn_port); + printf("\tPersists:\t\t%d\n", nti->persist); + break; + case UDP: + printf("\tUDP Listener:\t\t%s\n", nti->udp); + printf("\tConnect Port:\t\t%d\n", nti->rcv_port); + break; + case DEV: + printf("\tDevice:\t\t\t%s\n", nti->location); + printf("\tBaud:\t\t\t%d\n", nti->baud); + printf("\tData:\t\t\t%d\n", nti->data_bits); + printf("\tStop:\t\t\t%d\n", nti->stop_bits); + printf("\tHardware:\t\t%d\n", nti->hw_ctl); + printf("\tSoftware:\t\t%d\n", nti->sw_ctl); + printf("\tParity:\t\t\t%s\n", nti->parity); + break; + } + if (strncmp(nti->iface, "", PKT_BUFF) == 0) + printf("\tBind Interface:\t\tall\n"); + else + printf("\tBind Interface:\t\t%s\n", nti->iface); + printf("\tListen Port:\t\t%d\n", nti->port); + if (nti->max_clients == 0) + printf("\tMax Clients:\t\tunlimited\n"); + else + printf("\tMax Clients:\t\t%d\n", nti->max_clients); + printf("\tPassword:\t\t%s\n", nti->password); + printf("\tClient Count:\t\t%zu\n", nti->client_cnt); + if (nti->tls == false) + break; + printf("\tTLS:\t\t\t%d\n", nti->tls); + printf("\tCert:\t\t\t%s\n", nti->tls_cert_file); + printf("\tKey:\t\t\t%s\n", nti->tls_key_file); + printf("\tCA:\t\t\t%s\n", nti->tls_ca_file); + printf("\tCRL:\t\t\t%s\n", nti->tls_crl_file); + printf("\tOCSP:\t\t\t%s\n", nti->tls_ocsp_staple_file); + + break; + case IMSG_GET_INFO_THINGS_END_DATA: + case IMSG_CTL_END: + return (1); + default: + break; + } + + return (0); +} blob - 22886ef3495a9f58e53a5c6973665361e89c011d blob + fc65e060564fdddd45bc820eebc9784288adab06 --- thingsd/proc.c +++ thingsd/proc.c @@ -672,7 +672,7 @@ proc_dispatch(int fd, short event, void *arg) pf.pf_instance); break; default: - fatalx("%s: %s %d got invalid imsg %d peerid %d " + log_warnx("%s: %s %d got invalid imsg %d peerid %d " "from %s %d", __func__, title, ps->ps_instance + 1, imsg.hdr.type, imsg.hdr.peerid, blob - 105097551009fe7990711cc9339962e20aa4d0c6 blob + ee3366adb6d80c0dd57abbf3e79fae416ef8d6ea --- thingsd/things.c +++ thingsd/things.c @@ -47,7 +47,6 @@ int things_dispatch_parent(int, struct privsep_proc *, struct imsg *); void things_run(struct privsep *, struct privsep_proc *, void *); -void things_show_info(struct privsep *, struct imsg *); struct thing compose_thing(struct thing *, enum imsg_type); @@ -168,11 +167,6 @@ things_dispatch_parent(int fd, struct privsep_proc *p, TAILQ_INSERT_TAIL(thingsd_env->things, thing, entry); break; - case IMSG_GET_INFO_THINGS_REQUEST: - case IMSG_GET_INFO_THINGS_REQUEST_ROOT: - things_show_info(ps, imsg); - cmd = IMSG_GET_INFO_THINGS_END_DATA; - break; case IMSG_CTL_RESET: IMSG_SIZE_CHECK(imsg, &mode); memcpy(&mode, imsg->data, sizeof(mode)); @@ -308,7 +302,7 @@ things_show_info(struct privsep *ps, struct imsg *imsg thing->name, sizeof(filter)) == 0) { nti = compose_thing(thing, imsg->hdr.type); - if (proc_compose_imsg(ps, PROC_PARENT, -1, + if (proc_compose_imsg(ps, PROC_CONTROL, -1, IMSG_GET_INFO_THINGS_DATA, imsg->hdr.peerid, -1, &nti, sizeof(nti)) == -1) @@ -317,7 +311,7 @@ things_show_info(struct privsep *ps, struct imsg *imsg } } - if (proc_compose_imsg(ps, PROC_PARENT, -1, + if (proc_compose_imsg(ps, PROC_CONTROL, -1, IMSG_GET_INFO_THINGS_END_DATA, imsg->hdr.peerid, -1, &nti, sizeof(nti)) == -1) return; blob - a1caef5aab2c397c07f0522481837f924c20057d blob + 46124396806eaac65b68571ecb63a3e57b262190 --- thingsd/thingsd.c +++ thingsd/thingsd.c @@ -79,7 +79,7 @@ thingsd_dispatch_control(int fd, struct privsep_proc * switch (imsg->hdr.type) { case IMSG_GET_INFO_THINGS_REQUEST: case IMSG_GET_INFO_THINGS_REQUEST_ROOT: - proc_forward_imsg(ps, imsg, PROC_THINGS, -1); + things_show_info(ps, imsg); break; case IMSG_GET_INFO_PARENT_REQUEST: thingsd_show_info(ps, imsg); blob - 371247fde940a73dbeaf031b896001761b3293b9 blob + f0e92360b4d7c6e910cf08c5223d666e7a646f79 --- thingsd/thingsd.h +++ thingsd/thingsd.h @@ -269,6 +269,7 @@ void things_shutdown(void); void add_reconn(struct thing *); void do_reconn(void); void things_sighdlr(int, short, void *); +void things_show_info(struct privsep *, struct imsg *); /* control.c */ int config_init(struct thingsd *);