-/* $OpenBSD: npppd_iface.c,v 1.11 2015/07/20 18:58:30 yasuoka Exp $ */
+/* $OpenBSD: npppd_iface.c,v 1.12 2015/10/11 07:32:06 guenther Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/* $Id: npppd_iface.c,v 1.11 2015/07/20 18:58:30 yasuoka Exp $ */
+/* $Id: npppd_iface.c,v 1.12 2015/10/11 07:32:06 guenther Exp $ */
/**@file
* The interface of npppd and kernel.
* This is an implementation to use tun(4) or pppx(4).
/* open device file */
snprintf(buf, sizeof(buf), "/dev/%s", _this->ifname);
- if ((_this->devf = priv_open(buf, O_RDWR, 0600)) < 0) {
+ if ((_this->devf = priv_open(buf, O_RDWR | O_NONBLOCK)) < 0) {
npppd_iface_log(_this, LOG_ERR, "open(%s) failed: %m", buf);
goto fail;
}
- x = 1;
- if (ioctl(_this->devf, FIONBIO, &x) != 0) {
- npppd_iface_log(_this, LOG_ERR,
- "ioctl(FIONBIO) failed in %s(): %m", __func__);
- goto fail;
- }
-
if (_this->using_pppx == 0) {
x = IFF_BROADCAST;
if (ioctl(_this->devf, TUNSIFMODE, &x) != 0) {
-/* $OpenBSD: npppd_tun.c,v 1.5 2015/01/19 01:48:59 deraadt Exp $ */
+/* $OpenBSD: npppd_tun.c,v 1.6 2015/10/11 07:32:06 guenther Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
int
npppd_tundev_start(npppd *_this)
{
- int x, sock;
+ int sock;
char buf[PATH_MAX];
struct ifaliasreq ifra;
struct sockaddr_in *sin0;
NPPPD_TUN_ASSERT(_this != NULL);
snprintf(buf, sizeof(buf), "/dev/tun%d", _this->tun_minor);
- if ((_this->tun_file = open(buf, O_RDWR, 0600)) < 0) {
+ if ((_this->tun_file = open(buf, O_RDWR | O_NONBLOCK)) < 0) {
log_printf(LOG_ERR, "open(%s) failed in %s(): %m",
buf, __func__);
goto fail;
}
close(sock);
- x = 1;
- if (ioctl(_this->tun_file, FIONBIO, &x) != 0) {
- log_printf(LOG_ERR, "ioctl(FIONBIO) failed in %s(): %m",
- __func__);
- goto fail;
- }
event_set(&_this->ev_tun, _this->tun_file, EV_READ | EV_PERSIST,
npppd_tundev_io_event_handler, _this);
event_add(&_this->ev_tun, NULL);
-/* $OpenBSD: privsep.c,v 1.17 2015/07/20 18:55:35 yasuoka Exp $ */
+/* $OpenBSD: privsep.c,v 1.18 2015/10/11 07:32:06 guenther Exp $ */
/*
* Copyright (c) 2010 Yasuoka Masahiko <yasuoka@openbsd.org>
struct PRIVSEP_OPEN_ARG {
char path[PATH_MAX];
int flags;
- mode_t mode;
};
struct PRIVSEP_SOCKET_ARG {
}
int
-priv_open(const char *path, int flags, mode_t mode)
+priv_open(const char *path, int flags)
{
struct PRIVSEP_OPEN_ARG a;
strlcpy(a.path, path, sizeof(a.path));
a.flags = flags;
- a.mode = mode;
(void)imsg_compose(&privsep_ibuf, PRIVSEP_OPEN, 0, 0, -1,
&a, sizeof(a));
imsg_flush(&privsep_ibuf);
int f;
FILE *fp;
- if ((f = priv_open(path, O_RDONLY, 0600)) < 0)
+ if ((f = priv_open(path, O_RDONLY)) < 0)
return (NULL);
if ((fp = fdopen(f, "r")) == NULL) {
else if (privsep_npppd_check_open(a))
r.rerrno = EACCES;
else {
- if ((f = open(a->path, a->flags, a->mode))
+ if ((f = open(a->path, a->flags & ~O_CREAT))
== -1)
r.rerrno = errno;
else
{ "/dev/pppx", 1, 0 }
};
+ /* O_NONBLOCK is the only 'extra' flag permitted */
+ if (arg->flags & ~(O_ACCMODE | O_NONBLOCK))
+ return (1);
for (i = 0; i < (int)nitems(allow_paths); i++) {
if (allow_paths[i].path_is_prefix) {
if (!startswith(arg->path, allow_paths[i].path))
-/* $OpenBSD: privsep.h,v 1.6 2014/07/12 14:04:18 yasuoka Exp $ */
+/* $OpenBSD: privsep.h,v 1.7 2015/10/11 07:32:06 guenther Exp $ */
/*
* Copyright (c) 2010 Yasuoka Masahiko <yasuoka@openbsd.org>
int priv_bind (int, const struct sockaddr *, socklen_t);
int priv_unlink (const char *);
int priv_socket (int, int, int);
-int priv_open (const char *, int, mode_t);
+int priv_open (const char *, int);
int priv_send (int, const void *, int, int);
int priv_sendto (int, const void *, int, int, const struct sockaddr *, socklen_t);
int priv_get_user_info(const char *, const char *, npppd_auth_user **);
-/* $OpenBSD: pppoed.c,v 1.17 2015/01/19 01:48:59 deraadt Exp $ */
+/* $OpenBSD: pppoed.c,v 1.18 2015/10/11 07:32:06 guenther Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
/**@file
* This file provides the PPPoE(RFC2516) server(access concentrator)
* implementaion.
- * $Id: pppoed.c,v 1.17 2015/01/19 01:48:59 deraadt Exp $
+ * $Id: pppoed.c,v 1.18 2015/10/11 07:32:06 guenther Exp $
*/
#include <sys/param.h> /* ALIGN */
#include <sys/types.h>
/* FIXME: /dev/bpf of NetBSD3.0 can simultaneity open */
for (i = 0; i < 256; i++) {
snprintf(buf, sizeof(buf), "/dev/bpf%d", i);
- if ((_this->bpf = priv_open(buf, O_RDWR, 0600)) >= 0) {
+ if ((_this->bpf = priv_open(buf, O_RDWR)) >= 0) {
break;
} else if (errno == ENXIO || errno == ENOENT)
break; /* no more entries */