aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2024-01-21 19:40:06 +0000
committerOmar Polo <op@omarpolo.com>2024-01-21 19:40:06 +0000
commit83a2644bfb1d8683faf024275a98600b0edc5063 (patch)
treeea0783914312c1cf661315acd15ef787ad24b85c
parent4f3b85e6d72b0df0b6264baf711290af4661807d (diff)
convert remaining code to the imsg getters
Now gmid doesn't touch anymore the internals of the imsg structs.
-rw-r--r--config.c10
-rw-r--r--crypto.c30
-rw-r--r--gmid.c6
-rw-r--r--logger.c4
-rw-r--r--server.c2
5 files changed, 27 insertions, 25 deletions
diff --git a/config.c b/config.c
index 14ef23d..c793b26 100644
--- a/config.c
+++ b/config.c
@@ -479,9 +479,9 @@ config_crypto_recv_kp(struct conf *conf, struct imsg *imsg)
/* XXX: check for duplicates */
if ((fd = imsg_get_fd(imsg)) == -1)
- fatalx("no fd for imsg %d", imsg->hdr.type);
+ fatalx("%s: no fd for imsg %d", __func__, imsg_get_type(imsg));
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_CERT:
if (pki != NULL)
fatalx("imsg in wrong order; pki is not NULL");
@@ -497,8 +497,8 @@ config_crypto_recv_kp(struct conf *conf, struct imsg *imsg)
case IMSG_RECONF_KEY:
if (pki == NULL)
- fatalx("got key without cert beforehand %d",
- imsg->hdr.type);
+ fatalx("%s: RECONF_KEY: got key without cert",
+ __func__);
if (load_file(fd, &d, &len) == -1)
fatalx("failed to load private key");
if ((pki->pkey = ssl_load_pkey(d, len)) == NULL)
@@ -533,7 +533,7 @@ config_recv(struct conf *conf, struct imsg *imsg)
size_t len;
int fd;
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_START:
config_purge(conf);
h = NULL;
diff --git a/crypto.c b/crypto.c
index ab6753e..8d6df32 100644
--- a/crypto.c
+++ b/crypto.c
@@ -80,7 +80,7 @@ crypto_init(struct privsep *ps, struct privsep_proc *p, void *arg)
static int
crypto_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
{
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_START:
case IMSG_RECONF_CERT:
case IMSG_RECONF_KEY:
@@ -121,18 +121,20 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
struct iovec iov[2];
const void *from;
unsigned char *to;
- int n, ret;
+ int n, ret, type;
unsigned int len;
+ pid_t pid;
if (imsg_get_ibuf(imsg, &ibuf) == -1)
fatalx("%s: couldn't get an ibuf", __func__);
- switch (imsg->hdr.type) {
+ pid = imsg_get_pid(imsg);
+ switch (type = imsg_get_type(imsg)) {
case IMSG_CRYPTO_RSA_PRIVENC:
case IMSG_CRYPTO_RSA_PRIVDEC:
if (ibuf_get(&ibuf, &req, sizeof(req)) == -1 ||
ibuf_size(&ibuf) != req.flen)
- fatalx("size mismatch for imsg %d", imsg->hdr.type);
+ fatalx("size mismatch for imsg %d", type);
from = ibuf_data(&ibuf);
if ((pkey = get_pkey(req.hash)) == NULL ||
@@ -142,7 +144,7 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
if ((to = calloc(1, req.tlen)) == NULL)
fatal("calloc");
- if (imsg->hdr.type == IMSG_CRYPTO_RSA_PRIVENC)
+ if (type == IMSG_CRYPTO_RSA_PRIVENC)
ret = RSA_private_encrypt(req.flen, from,
to, rsa, req.padding);
else
@@ -166,12 +168,12 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
n++;
}
- log_debug("replying to server #%d", imsg->hdr.pid);
- if (proc_composev_imsg(ps, PROC_SERVER, imsg->hdr.pid - 1,
- imsg->hdr.type, 0, -1, iov, n) == -1)
+ log_debug("replying to server #%d", pid);
+ if (proc_composev_imsg(ps, PROC_SERVER, pid - 1,
+ type, 0, -1, iov, n) == -1)
fatal("proc_composev_imsg");
- if (proc_flush_imsg(ps, PROC_SERVER, imsg->hdr.pid - 1) == -1)
+ if (proc_flush_imsg(ps, PROC_SERVER, pid - 1) == -1)
fatal("proc_flush_imsg");
free(to);
@@ -181,7 +183,7 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_CRYPTO_ECDSA_SIGN:
if (ibuf_get(&ibuf, &req, sizeof(req)) == -1 ||
ibuf_size(&ibuf) != req.flen)
- fatalx("size mismatch for imsg %d", imsg->hdr.type);
+ fatalx("size mismatch for imsg %d", type);
from = ibuf_data(&ibuf);
if ((pkey = get_pkey(req.hash)) == NULL ||
@@ -210,12 +212,12 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
n++;
}
- log_debug("replying to server #%d", imsg->hdr.pid);
- if (proc_composev_imsg(ps, PROC_SERVER, imsg->hdr.pid - 1,
- imsg->hdr.type, 0, -1, iov, n) == -1)
+ log_debug("replying to server #%d", pid);
+ if (proc_composev_imsg(ps, PROC_SERVER, pid - 1,
+ type, 0, -1, iov, n) == -1)
fatal("proc_composev_imsg");
- if (proc_flush_imsg(ps, PROC_SERVER, imsg->hdr.pid - 1) == -1)
+ if (proc_flush_imsg(ps, PROC_SERVER, pid - 1) == -1)
fatal("proc_flush_imsg");
free(to);
diff --git a/gmid.c b/gmid.c
index 54441f3..f264670 100644
--- a/gmid.c
+++ b/gmid.c
@@ -526,7 +526,7 @@ main_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
struct privsep *ps = p->p_ps;
struct conf *conf = ps->ps_env;
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_DONE:
main_configure_done(conf);
break;
@@ -543,7 +543,7 @@ main_dispatch_crypto(int fd, struct privsep_proc *p, struct imsg *imsg)
struct privsep *ps = p->p_ps;
struct conf *conf = ps->ps_env;
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_DONE:
main_configure_done(conf);
break;
@@ -560,7 +560,7 @@ main_dispatch_logger(int fd, struct privsep_proc *p, struct imsg *imsg)
struct privsep *ps = p->p_ps;
struct conf *conf = ps->ps_env;
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_DONE:
main_configure_done(conf);
break;
diff --git a/logger.c b/logger.c
index 1398686..c4bd96b 100644
--- a/logger.c
+++ b/logger.c
@@ -79,7 +79,7 @@ logger_shutdown(void)
static int
logger_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
{
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_LOG_FACILITY:
if (imsg_get_data(imsg, &facility, sizeof(facility)) == -1)
fatal("corrupted IMSG_LOG_SYSLOG");
@@ -108,7 +108,7 @@ logger_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
size_t datalen = 0;
struct ibuf ibuf;
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_LOG_REQUEST:
if (imsg_get_ibuf(imsg, &ibuf) == -1 ||
(datalen = ibuf_size(&ibuf)) == 0)
diff --git a/server.c b/server.c
index b6b1cfb..748ac45 100644
--- a/server.c
+++ b/server.c
@@ -1496,7 +1496,7 @@ server_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
struct privsep *ps = p->p_ps;
struct conf *conf = ps->ps_env;
- switch (imsg->hdr.type) {
+ switch (imsg_get_type(imsg)) {
case IMSG_RECONF_START:
case IMSG_RECONF_LOG_FMT:
case IMSG_RECONF_MIME: