1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

Handle radiusd and npppd, they are different but nothing stands out.

OK tb@
This commit is contained in:
claudio 2024-11-21 13:43:10 +00:00
parent 545b6e3145
commit 882428cdbd
9 changed files with 51 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: npppctl.c,v 1.14 2024/11/21 13:23:13 claudio Exp $ */
/* $OpenBSD: npppctl.c,v 1.15 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2012 Internet Initiative Japan Inc.
@ -108,7 +108,8 @@ main(int argc, char *argv[])
if (connect(ctlsock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
err(EXIT_FAILURE, "connect");
imsgbuf_init(&ctl_ibuf, ctlsock);
if (imsgbuf_init(&ctl_ibuf, ctlsock) == -1)
err(EXIT_FAILURE, "imsgbuf_init");
switch (result->action) {
case SESSION_BRIEF:

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.14 2024/11/21 13:23:13 claudio Exp $ */
/* $OpenBSD: control.c,v 1.15 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -181,13 +181,20 @@ control_accept(int listenfd, short event, void *arg)
return;
}
if ((c->ctx = npppd_ctl_create(cs->cs_ctx)) == NULL) {
free(c);
log_warn("control_accept");
close(connfd);
free(c);
return;
}
if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) {
log_warn("control_accept");
close(connfd);
free(c->ctx);
free(c);
return;
}
imsgbuf_init(&c->iev.ibuf, connfd);
c->iev.handler = control_dispatch_imsg;
c->iev.events = EV_READ;
c->iev.data = cs;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: privsep.c,v 1.28 2024/11/21 13:23:13 claudio Exp $ */
/* $OpenBSD: privsep.c,v 1.29 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2010 Yasuoka Masahiko <yasuoka@openbsd.org>
@ -37,6 +37,7 @@
#include "npppd.h"
#include "ppp.h"
#include "log.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@ -191,7 +192,9 @@ privsep_init(void)
close(pairsock[0]);
privsep_sock = pairsock[1];
privsep_pid = pid;
imsgbuf_init(&privsep_ibuf, privsep_sock);
if (imsgbuf_init(&privsep_ibuf, privsep_sock) == -1)
goto fail;
imsgbuf_allow_fdpass(&privsep_ibuf);
return (0);
/* NOTREACHED */
@ -565,7 +568,9 @@ privsep_priv_main(int sock)
{
struct imsgbuf ibuf;
imsgbuf_init(&ibuf, sock);
if (imsgbuf_init(&ibuf, sock) == -1)
fatal("imsgbuf_init");
imsgbuf_allow_fdpass(&ibuf);
privsep_priv_dispatch_imsg(&ibuf);
imsgbuf_clear(&ibuf);
close(sock);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: radiusctl.c,v 1.16 2024/11/21 13:23:37 claudio Exp $ */
/* $OpenBSD: radiusctl.c,v 1.17 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
*
@ -147,7 +147,8 @@ main(int argc, char *argv[])
err(EX_OSERR, "socket");
if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
err(EX_OSERR, "connect");
imsgbuf_init(&ibuf, sock);
if (imsgbuf_init(&ibuf, sock) == -1)
err(EX_OSERR, "imsgbuf_init");
res = parse(argc, argv);
if (res == NULL)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.6 2024/11/21 13:23:37 claudio Exp $ */
/* $OpenBSD: control.c,v 1.7 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -165,10 +165,15 @@ control_accept(int listenfd, short event, void *bula)
return;
}
if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) {
log_warn("control_accept");
close(connfd);
free(c);
return;
}
if (idseq == 0) /* don't use zero. See radiusd_module_imsg */
++idseq;
c->id = idseq++;
imsgbuf_init(&c->iev.ibuf, connfd);
c->iev.handler = control_dispatch_imsg;
c->iev.events = EV_READ;
event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events, c->iev.handler, c);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: radiusd.c,v 1.60 2024/11/21 13:23:37 claudio Exp $ */
/* $OpenBSD: radiusd.c,v 1.61 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2013, 2023 Internet Initiative Japan Inc.
@ -1200,7 +1200,10 @@ radiusd_module_load(struct radiusd *radiusd, const char *path, const char *name)
}
strlcpy(module->name, name, sizeof(module->name));
module->pid = pid;
imsgbuf_init(&module->ibuf, module->fd);
if (imsgbuf_init(&module->ibuf, module->fd) == -1) {
log_warn("Could not load module `%s': imsgbuf_init", name);
goto on_error;
}
if (imsg_sync_read(&module->ibuf, MODULE_IO_TIMEOUT) <= 0 ||
(n = imsg_get(&module->ibuf, &imsg)) <= 0) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: radiusd_bsdauth.c,v 1.18 2024/11/21 13:23:37 claudio Exp $ */
/* $OpenBSD: radiusd_bsdauth.c,v 1.19 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@ -113,7 +113,8 @@ main(int argc, char *argv[])
* Privileged process
*/
setproctitle("[priv]");
imsgbuf_init(&ibuf, pairsock[0]);
if (imsgbuf_init(&ibuf, pairsock[0]) == 1)
err(EXIT_FAILURE, "imsgbuf_init");
if (pledge("stdio getpw rpath proc exec", NULL) == -1)
err(EXIT_FAILURE, "pledge");
@ -250,7 +251,8 @@ module_bsdauth_main(void)
module_drop_privilege(module_bsdauth.base, 0);
module_load(module_bsdauth.base);
imsgbuf_init(&module_bsdauth.ibuf, 3);
if (imsgbuf_init(&module_bsdauth.ibuf, 3) == -1)
err(EXIT_FAILURE, "imsgbuf_init");
if (pledge("stdio proc", NULL) == -1)
err(EXIT_FAILURE, "pledge");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: radiusd_file.c,v 1.7 2024/11/21 13:23:37 claudio Exp $ */
/* $OpenBSD: radiusd_file.c,v 1.8 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2024 YASUOKA Masahiko <yasuoka@yasuoka.net>
@ -128,7 +128,8 @@ main(int argc, char *argv[])
if (pledge("stdio rpath unveil", NULL) == -1)
err(EXIT_FAILURE, "pledge");
setproctitle("[priv]");
imsgbuf_init(&ibuf, pairsock[0]);
if (imsgbuf_init(&ibuf, pairsock[0]) == -1)
err(EXIT_FAILURE, "imsgbuf_init");
/* Receive parameters from the main process. */
if (imsg_sync_read(&ibuf, 2000) <= 0 ||
@ -244,7 +245,8 @@ module_file_main(void)
module_drop_privilege(module_file.base, 0);
module_load(module_file.base);
imsgbuf_init(&module_file.ibuf, 3);
if (imsgbuf_init(&module_file.ibuf, 3) == -1)
err(EXIT_FAILURE, "imsgbuf_init");
if (pledge("stdio", NULL) == -1)
err(EXIT_FAILURE, "pledge");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: radiusd_module.c,v 1.25 2024/11/21 13:23:37 claudio Exp $ */
/* $OpenBSD: radiusd_module.c,v 1.26 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@ -95,7 +95,10 @@ module_create(int sock, void *ctx, struct module_handlers *handler)
if ((base = calloc(1, sizeof(struct module_base))) == NULL)
return (NULL);
imsgbuf_init(&base->ibuf, sock);
if (imsgbuf_init(&base->ibuf, sock) == -1) {
free(base);
return (NULL);
}
base->ctx = ctx;
module_userpass = handler->userpass;