Download raw body.
npppd convert to imsg_get_fd()
ok yasuoka
Thanks,
On Wed, 17 Jan 2024 11:08:46 +0100
Claudio Jeker <cjeker@diehard.n-r-g.com> wrote:
> Same conversions away from imsg.fd to imsg_get_fd().
>
> This code base is a bit different to other imsg daemons but I think
> the conversion is still rather simple. This needs a local variable fd
> since the fd is accessed multiple times.
>
> This was only compile tested since I no longer use npppd.
> --
> :wq Claudio
>
> Index: npppd/privsep.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/npppd/npppd/privsep.c,v
> diff -u -p -r1.24 privsep.c
> --- npppd/privsep.c 23 Jan 2020 00:17:27 -0000 1.24
> +++ npppd/privsep.c 13 Dec 2023 13:06:53 -0000
> @@ -526,7 +526,7 @@ privsep_recvfd(void)
> if (r->retval != 0)
> errno = r->rerrno;
> else
> - retval = imsg.fd;
> + retval = imsg_get_fd(&imsg);
> }
> imsg_free(&imsg);
>
> @@ -646,18 +646,19 @@ privsep_priv_dispatch_imsg(struct imsgbu
> case PRIVSEP_BIND: {
> struct PRIVSEP_BIND_ARG *a = imsg.data;
> struct PRIVSEP_COMMON_RESP r = { -1, 0 };
> + int fd;
>
> if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(*a) ||
> - imsg.fd < 0)
> + (fd = imsg_get_fd(&imsg)) < 0)
> r.rerrno = EINVAL;
> else if (privsep_npppd_check_bind(a))
> r.rerrno = EACCES;
> else {
> - if ((r.retval = bind(imsg.fd,
> + if ((r.retval = bind(fd,
> (struct sockaddr *)&a->name, a->namelen))
> != 0)
> r.rerrno = errno;
> - close(imsg.fd);
> + close(fd);
> }
> (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1,
> &r, sizeof(r));
> @@ -744,28 +745,29 @@ on_broken_entry:
> case PRIVSEP_SENDTO: {
> struct PRIVSEP_SENDTO_ARG *a = imsg.data;
> struct PRIVSEP_COMMON_RESP r = { -1, 0 };
> + int fd;
>
> if (imsg.hdr.len < IMSG_HEADER_SIZE + sizeof(*a) ||
> imsg.hdr.len < IMSG_HEADER_SIZE +
> offsetof(struct PRIVSEP_SENDTO_ARG,
> msg[a->len]))
> r.rerrno = EMSGSIZE;
> - else if (imsg.fd < 0)
> + else if ((fd = imsg_get_fd(&imsg)) < 0)
> r.rerrno = EINVAL;
> else if (privsep_npppd_check_sendto(a))
> r.rerrno = EACCES;
> else {
> if (a->tolen > 0)
> - r.retval = sendto(imsg.fd, a->msg,
> + r.retval = sendto(fd, a->msg,
> a->len, a->flags,
> (struct sockaddr *)&a->to,
> a->tolen);
> else
> - r.retval = send(imsg.fd, a->msg, a->len,
> + r.retval = send(fd, a->msg, a->len,
> a->flags);
> if (r.retval < 0)
> r.rerrno = errno;
> - close(imsg.fd);
> + close(fd);
> }
> (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1,
> &r, sizeof(r));
>
>
npppd convert to imsg_get_fd()