diff options
author | Omar Polo <op@omarpolo.com> | 2024-01-21 12:23:28 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-01-21 12:23:28 +0000 |
commit | 6dec2ad700aac233ab001f91b8fa05813180eaba (patch) | |
tree | ade12becb86ae1edd4c83a13d6382ea54e3470d3 | |
parent | b03e976aa26d100ec1bf976dfdd005868395b490 (diff) |
convert most of gmid to the new imsg APIs
Makes parsing and handling of imsgs simpler / clearer. only crypto.c
is left as-is.
-rw-r--r-- | config.c | 50 | ||||
-rw-r--r-- | logger.c | 14 | ||||
-rw-r--r-- | proc.c | 4 |
3 files changed, 34 insertions, 34 deletions
@@ -530,11 +530,9 @@ config_recv(struct conf *conf, struct imsg *imsg) struct proxy *proxy; struct address *addr; uint8_t *d; - size_t len, datalen; + size_t len; int fd; - datalen = IMSG_DATA_SIZE(imsg); - switch (imsg->hdr.type) { case IMSG_RECONF_START: config_purge(conf); @@ -543,13 +541,14 @@ config_recv(struct conf *conf, struct imsg *imsg) break; case IMSG_RECONF_LOG_FMT: - IMSG_SIZE_CHECK(imsg, &conf->log_format); - memcpy(&conf->log_format, imsg->data, datalen); + if (imsg_get_data(imsg, &conf->log_format, + sizeof(conf->log_format)) == -1) + fatalx("bad length imsg LOG_FMT"); break; case IMSG_RECONF_MIME: - IMSG_SIZE_CHECK(imsg, &m); - memcpy(&m, imsg->data, datalen); + if (imsg_get_data(imsg, &m, sizeof(m)) == -1) + fatalx("bad length imsg RECONF_MIME"); if (m.mime[sizeof(m.mime) - 1] != '\0' || m.ext[sizeof(m.ext) - 1] != '\0') fatal("received corrupted IMSG_RECONF_MIME"); @@ -559,14 +558,15 @@ config_recv(struct conf *conf, struct imsg *imsg) break; case IMSG_RECONF_PROTOS: - IMSG_SIZE_CHECK(imsg, &conf->protos); - memcpy(&conf->protos, imsg->data, datalen); + if (imsg_get_data(imsg, &conf->protos, sizeof(conf->protos)) + == -1) + fatalx("bad length imsg RECONF_PROTOS"); break; case IMSG_RECONF_SOCK: addr = xcalloc(1, sizeof(*addr)); - IMSG_SIZE_CHECK(imsg, addr); - memcpy(addr, imsg->data, sizeof(*addr)); + if (imsg_get_data(imsg, addr, sizeof(*addr)) == -1) + fatalx("bad length imsg RECONF_SOCK"); if ((fd = imsg_get_fd(imsg)) == -1) fatalx("missing socket for IMSG_RECONF_SOCK"); addr->conf = conf; @@ -579,16 +579,16 @@ config_recv(struct conf *conf, struct imsg *imsg) break; case IMSG_RECONF_FCGI: - IMSG_SIZE_CHECK(imsg, fcgi); fcgi = xcalloc(1, sizeof(*fcgi)); - memcpy(fcgi, imsg->data, datalen); + if (imsg_get_data(imsg, fcgi, sizeof(*fcgi)) == -1) + fatalx("bad length imsg RECONF_FCGI"); log_debug("received fcgi %s", fcgi->path); TAILQ_INSERT_TAIL(&conf->fcgi, fcgi, fcgi); break; case IMSG_RECONF_HOST: - IMSG_SIZE_CHECK(imsg, &vht); - memcpy(&vht, imsg->data, datalen); + if (imsg_get_data(imsg, &vht, sizeof(vht)) == -1) + fatalx("bad length imsg RECONF_HOST"); vh = new_vhost(); strlcpy(vh->domain, vht.domain, sizeof(vh->domain)); h = vh; @@ -646,18 +646,18 @@ config_recv(struct conf *conf, struct imsg *imsg) log_debug("receiving host addr"); if (h == NULL) fatalx("recv'd host address withouth host"); - IMSG_SIZE_CHECK(imsg, addr); addr = xcalloc(1, sizeof(*addr)); - memcpy(addr, imsg->data, datalen); + if (imsg_get_data(imsg, addr, sizeof(*addr)) == -1) + fatalx("bad length imsg RECONF_HOST_ADDR"); TAILQ_INSERT_TAIL(&h->addrs, addr, addrs); break; case IMSG_RECONF_LOC: if (h == NULL) fatalx("recv'd location without host"); - IMSG_SIZE_CHECK(imsg, loc); loc = xcalloc(1, sizeof(*loc)); - memcpy(loc, imsg->data, datalen); + if (imsg_get_data(imsg, loc, sizeof(*loc)) == -1) + fatalx("bad length imsg RECONF_LOC"); TAILQ_INIT(&loc->params); if ((fd = imsg_get_fd(imsg)) != -1) { @@ -676,18 +676,18 @@ config_recv(struct conf *conf, struct imsg *imsg) case IMSG_RECONF_ENV: if (l == NULL) fatalx("recv'd env without location"); - IMSG_SIZE_CHECK(imsg, env); env = xcalloc(1, sizeof(*env)); - memcpy(env, imsg->data, datalen); + if (imsg_get_data(imsg, env, sizeof(*env)) == -1) + fatalx("bad length imsg RECONF_ENV"); TAILQ_INSERT_TAIL(&l->params, env, envs); break; case IMSG_RECONF_ALIAS: if (h == NULL) fatalx("recv'd alias without host"); - IMSG_SIZE_CHECK(imsg, alias); alias = xcalloc(1, sizeof(*alias)); - memcpy(alias, imsg->data, datalen); + if (imsg_get_data(imsg, alias, sizeof(*alias)) == -1) + fatalx("bad length imsg RECONF_ALIAS"); TAILQ_INSERT_TAIL(&h->aliases, alias, aliases); break; @@ -695,9 +695,9 @@ config_recv(struct conf *conf, struct imsg *imsg) log_debug("receiving proxy"); if (h == NULL) fatalx("recv'd proxy without host"); - IMSG_SIZE_CHECK(imsg, proxy); proxy = xcalloc(1, sizeof(*proxy)); - memcpy(proxy, imsg->data, datalen); + if (imsg_get_data(imsg, proxy, sizeof(*proxy)) == -1) + fatalx("bad length imsg RECONF_PROXY"); if ((fd = imsg_get_fd(imsg)) != -1) { if (load_file(fd, &d, &len) == -1) @@ -81,14 +81,13 @@ logger_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) { switch (imsg->hdr.type) { case IMSG_LOG_FACILITY: - if (IMSG_DATA_SIZE(imsg) != sizeof(facility)) + if (imsg_get_data(imsg, &facility, sizeof(facility)) == -1) fatal("corrupted IMSG_LOG_SYSLOG"); - memcpy(&facility, imsg->data, sizeof(facility)); break; case IMSG_LOG_SYSLOG: - if (IMSG_DATA_SIZE(imsg) != sizeof(log_to_syslog)) + if (imsg_get_data(imsg, &log_to_syslog, + sizeof(log_to_syslog)) == -1) fatal("corrupted IMSG_LOG_SYSLOG"); - memcpy(&log_to_syslog, imsg->data, sizeof(log_to_syslog)); break; case IMSG_LOG_ACCESS: if (logfd != -1) @@ -107,13 +106,14 @@ logger_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg) { char *msg; size_t datalen; + struct ibuf ibuf; switch (imsg->hdr.type) { case IMSG_LOG_REQUEST: - msg = imsg->data; - datalen = IMSG_DATA_SIZE(imsg); - if (datalen == 0) + if (imsg_get_ibuf(imsg, &ibuf) == -1 || + (datalen = ibuf_size(&ibuf)) == 0) fatal("got invalid IMSG_LOG_REQUEST"); + msg = ibuf_data(&ibuf); msg[datalen - 1] = '\0'; if (logfd != -1) dprintf(logfd, "%s\n", msg); @@ -671,8 +671,8 @@ proc_dispatch(int fd, short event, void *arg) */ switch (imsg.hdr.type) { case IMSG_CTL_PROCFD: - IMSG_SIZE_CHECK(&imsg, &pf); - memcpy(&pf, imsg.data, sizeof(pf)); + if (imsg_get_data(&imsg, &pf, sizeof(pf))) + fatalx("bad length imsg CTL_PROCFD"); proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid, pf.pf_instance); break; |