From: claudio Date: Wed, 17 Jan 2024 08:25:02 +0000 (+0000) Subject: Convert to use imsg_get_fd() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fecd42b79d684eb665ce8c88a61411c9ade5f934;p=openbsd Convert to use imsg_get_fd() proc_forward_imsg() does not need to forward file descriptors so just use -1 there. In other places shuffle debug messages around or use a helper variable since imsg_get_fd() can only be called once. OK tb@ tobhe@ --- diff --git a/sbin/iked/config.c b/sbin/iked/config.c index 157aeb44b8e..cc26eeef729 100644 --- a/sbin/iked/config.c +++ b/sbin/iked/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.94 2024/01/15 15:29:00 tobhe Exp $ */ +/* $OpenBSD: config.c,v 1.95 2024/01/17 08:25:02 claudio Exp $ */ /* * Copyright (c) 2019 Tobias Heider @@ -611,17 +611,17 @@ config_getsocket(struct iked *env, struct imsg *imsg, { struct iked_socket *sock, **sock0 = NULL, **sock1 = NULL; - log_debug("%s: received socket fd %d", __func__, imsg->fd); - if ((sock = calloc(1, sizeof(*sock))) == NULL) fatal("config_getsocket: calloc"); IMSG_SIZE_CHECK(imsg, &sock->sock_addr); memcpy(&sock->sock_addr, imsg->data, sizeof(sock->sock_addr)); - sock->sock_fd = imsg->fd; + sock->sock_fd = imsg_get_fd(imsg); sock->sock_env = env; + log_debug("%s: received socket fd %d", __func__, sock->sock_fd); + switch (sock->sock_addr.ss_family) { case AF_INET: sock0 = &env->sc_sock4[0]; @@ -665,8 +665,10 @@ config_setpfkey(struct iked *env) int config_getpfkey(struct iked *env, struct imsg *imsg) { - log_debug("%s: received pfkey fd %d", __func__, imsg->fd); - pfkey_init(env, imsg->fd); + int fd = imsg_get_fd(imsg); + + log_debug("%s: received pfkey fd %d", __func__, fd); + pfkey_init(env, fd); return (0); } diff --git a/sbin/iked/ocsp.c b/sbin/iked/ocsp.c index b6f41d3055c..91c44fcb6af 100644 --- a/sbin/iked/ocsp.c +++ b/sbin/iked/ocsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ocsp.c,v 1.24 2022/12/03 22:34:35 tobhe Exp $ */ +/* $OpenBSD: ocsp.c,v 1.25 2024/01/17 08:25:02 claudio Exp $ */ /* * Copyright (c) 2014 Markus Friedl @@ -364,9 +364,7 @@ ocsp_receive_fd(struct iked *env, struct imsg *imsg) uint8_t *ptr; char *path = NULL; size_t len; - int ret = -1; - - log_debug("%s: received socket fd %d", __func__, imsg->fd); + int fd, ret = -1; IMSG_SIZE_CHECK(imsg, &sh); @@ -385,30 +383,32 @@ ocsp_receive_fd(struct iked *env, struct imsg *imsg) } if (ioe == NULL) { log_debug("%s: no pending request found", __func__); - if (imsg->fd != -1) - close(imsg->fd); + if ((fd = imsg_get_fd(imsg)) != -1) /* XXX */ + close(fd); return (-1); } TAILQ_REMOVE(&env->sc_ocsp, ioe, ioe_entry); ocsp = ioe->ioe_ocsp; free(ioe); - if (imsg->fd == -1) + if ((fd = imsg_get_fd(imsg)) == -1) goto done; if ((sock = calloc(1, sizeof(*sock))) == NULL) fatal("ocsp_receive_fd: calloc sock"); /* note that sock_addr is not set */ - sock->sock_fd = imsg->fd; + sock->sock_fd = fd; sock->sock_env = env; ocsp->ocsp_sock = sock; + log_debug("%s: received socket fd %d", __func__, sock->sock_fd); + /* fetch 'path' and 'fd' from imsg */ if ((path = get_string(ptr, len)) == NULL) goto done; - BIO_set_fd(ocsp->ocsp_cbio, imsg->fd, BIO_NOCLOSE); + BIO_set_fd(ocsp->ocsp_cbio, sock->sock_fd, BIO_NOCLOSE); if ((ocsp->ocsp_req_ctx = OCSP_sendreq_new(ocsp->ocsp_cbio, path, NULL, -1)) == NULL) diff --git a/sbin/iked/proc.c b/sbin/iked/proc.c index 6ade7315f4e..5e23b7bda04 100644 --- a/sbin/iked/proc.c +++ b/sbin/iked/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.39 2023/06/28 12:31:19 gerhard Exp $ */ +/* $OpenBSD: proc.c,v 1.40 2024/01/17 08:25:02 claudio Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -667,7 +667,7 @@ proc_dispatch(int fd, short event, void *arg) case IMSG_CTL_PROCFD: IMSG_SIZE_CHECK(&imsg, &pf); memcpy(&pf, imsg.data, sizeof(pf)); - proc_accept(ps, imsg.fd, pf.pf_procid, + proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid, pf.pf_instance); break; default: @@ -798,7 +798,7 @@ proc_forward_imsg(struct privsep *ps, struct imsg *imsg, enum privsep_procid id, int n) { return (proc_compose_imsg(ps, id, n, imsg->hdr.type, - imsg->hdr.peerid, imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg))); + imsg->hdr.peerid, -1, imsg->data, IMSG_DATA_SIZE(imsg))); } struct imsgbuf *