introduce a SOL_LOCAL for unix-domain socket level socket options

as an alias of the current 0 used for these options, as in FreeBSD.

reviewed by many.
This commit is contained in:
nia 2021-08-08 20:54:48 +00:00
parent f1229b5389
commit 213aa76def
11 changed files with 32 additions and 34 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $ */
/* $NetBSD: getpeereid.c,v 1.4 2021/08/08 20:54:48 nia Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $");
__RCSID("$NetBSD: getpeereid.c,v 1.4 2021/08/08 20:54:48 nia Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -57,7 +57,7 @@ getpeereid(int s, uid_t *euid, gid_t *egid)
}
len = sizeof(cred);
if (getsockopt(s, 0, LOCAL_PEEREID, &cred, &len) == -1)
if (getsockopt(s, SOL_LOCAL, LOCAL_PEEREID, &cred, &len) == -1)
return -1;
if (euid != NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: svc_vc.c,v 1.34 2015/11/10 20:56:20 christos Exp $ */
/* $NetBSD: svc_vc.c,v 1.35 2021/08/08 20:54:48 nia Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@ -37,7 +37,7 @@
static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";
#else
__RCSID("$NetBSD: svc_vc.c,v 1.34 2015/11/10 20:56:20 christos Exp $");
__RCSID("$NetBSD: svc_vc.c,v 1.35 2021/08/08 20:54:48 nia Exp $");
#endif
#endif
@ -178,8 +178,8 @@ svc_vc_create(int fd, u_int sendsize, u_int recvsize)
* We want to be able to check credentials on local sockets.
*/
if (sslocal.ss_family == AF_LOCAL)
if (setsockopt(fd, 0, LOCAL_CREDS, &one, (socklen_t)sizeof one)
== -1)
if (setsockopt(fd, SOL_LOCAL, LOCAL_CREDS, &one,
(socklen_t)sizeof one) == -1)
goto cleanup_svc_vc_create;
xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: getsockopt.2,v 1.41 2019/05/09 09:09:38 wiz Exp $
.\" $NetBSD: getsockopt.2,v 1.42 2021/08/08 20:54:48 nia Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95
.\"
.Dd May 8, 2019
.Dd August 7, 2021
.Dt GETSOCKOPT 2
.Os
.Sh NAME
@ -55,10 +55,6 @@ and
manipulate the
.Em options
associated with a socket.
Options may exist at multiple
protocol levels; they are always present at the uppermost
.Dq socket
level.
.Pp
When manipulating socket options the level at which the
option resides and the name of the option must be specified.
@ -69,6 +65,7 @@ is specified as
To manipulate options at any
other level the protocol number of the appropriate protocol
controlling the option is supplied.
Options may exist at multiple protocol levels.
For example, to indicate that an option is to be interpreted by the
.Tn TCP
protocol,

View File

@ -1,4 +1,4 @@
/* $NetBSD: perfuse.c,v 1.42 2019/04/17 12:30:51 maya Exp $ */
/* $NetBSD: perfuse.c,v 1.43 2021/08/08 20:54:48 nia Exp $ */
/*-
* Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@ -255,7 +255,7 @@ perfuse_open(const char *path, int flags, mode_t mode)
*/
opt = 1;
optlen = sizeof(opt);
if (setsockopt(sv[1], 0, LOCAL_CREDS, &opt, optlen) != 0)
if (setsockopt(sv[1], SOL_LOCAL, LOCAL_CREDS, &opt, optlen) != 0)
DWARN("%s: setsockopt LOCAL_CREDS failed", __func__);
(void)sprintf(fdstr, "%d", sv[1]);

View File

@ -1,4 +1,4 @@
/* $NetBSD: unfdpass.c,v 1.11 2017/01/10 22:37:44 christos Exp $ */
/* $NetBSD: unfdpass.c,v 1.12 2021/08/08 20:54:48 nia Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -168,7 +168,7 @@ main(argc, argv)
sun.sun_len = SUN_LEN(&sun);
i = 1;
if (setsockopt(listensock, 0, LOCAL_CREDS, &i, sizeof(i)) == -1)
if (setsockopt(listensock, SOL_LOCAL, LOCAL_CREDS, &i, sizeof(i)) == -1)
err(1, "setsockopt");
if (bind(listensock, (struct sockaddr *)&sun, sizeof(sun)) == -1)

View File

@ -1,4 +1,4 @@
.\" $NetBSD: unix.4,v 1.26 2017/07/03 21:30:58 wiz Exp $
.\" $NetBSD: unix.4,v 1.27 2021/08/08 20:54:48 nia Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" @(#)unix.4 8.1 (Berkeley) 6/9/93
.\"
.Dd March 31, 2016
.Dd August 7, 2021
.Dt UNIX 4
.Os
.Sh NAME
@ -172,9 +172,9 @@ Descriptors that are awaiting delivery, or that are
purposely not received, are automatically closed by the system
when the destination socket is closed.
.Pp
A UNIX-domain socket supports two
.Tn socket-level
options for use with
A UNIX-domain socket supports several
.Dv SOL_LOCAL
level options for use with
.Xr setsockopt 2
and
.Xr getsockopt 2 :

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_usrreq.c,v 1.200 2020/11/06 14:50:13 christos Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.201 2021/08/08 20:54:48 nia Exp $ */
/*-
* Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc.
@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.200 2020/11/06 14:50:13 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.201 2021/08/08 20:54:48 nia Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -608,7 +608,7 @@ uipc_ctloutput(int op, struct socket *so, struct sockopt *sopt)
KASSERT(solocked(so));
if (sopt->sopt_level != 0) {
if (sopt->sopt_level != SOL_LOCAL) {
error = ENOPROTOOPT;
} else switch (op) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: un.h,v 1.59 2020/11/06 14:50:13 christos Exp $ */
/* $NetBSD: un.h,v 1.60 2021/08/08 20:54:49 nia Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -56,6 +56,7 @@ struct sockaddr_un {
* Socket options for UNIX IPC domain.
*/
#if defined(_NETBSD_SOURCE)
#define SOL_LOCAL 0 /* options level for getsockopt(2) */
#define LOCAL_OCREDS 0x0001 /* pass credentials to receiver */
#define LOCAL_CONNWAIT 0x0002 /* connects block until accepted */
#define LOCAL_PEEREID 0x0003 /* get peer identification */

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_unix.c,v 1.24 2020/08/28 14:18:29 riastradh Exp $ */
/* $NetBSD: t_unix.c,v 1.25 2021/08/08 20:54:49 nia Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -39,7 +39,7 @@
#define _GNU_SOURCE
#include <sys/cdefs.h>
#ifdef __RCSID
__RCSID("$Id: t_unix.c,v 1.24 2020/08/28 14:18:29 riastradh Exp $");
__RCSID("$Id: t_unix.c,v 1.25 2021/08/08 20:54:49 nia Exp $");
#else
#define getprogname() argv[0]
#endif
@ -147,7 +147,7 @@ peercred(int s, uid_t *euid, gid_t *egid, pid_t *pid)
# define LOCAL_PEEREID SO_PEERCRED
# define LEVEL SOL_SOCKET
#else
# define LEVEL 0
# define LEVEL SOL_LOCAL
#endif
#ifdef LOCAL_PEEREID

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.c,v 1.25 2019/04/17 12:30:51 maya Exp $ */
/* $NetBSD: msg.c,v 1.26 2021/08/08 20:54:49 nia Exp $ */
/*-
* Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@ -92,7 +92,7 @@ perfused_open_sock(void)
* Request peer credentials
*/
opt = 1;
if (setsockopt(s, 0, LOCAL_CREDS, &opt, sizeof(opt)) != 0)
if (setsockopt(s, SOL_LOCAL, LOCAL_CREDS, &opt, sizeof(opt)) != 0)
DWARN("%s: setsockopt LOCAL_CREDS failed", __func__);
if (bind(s, sa, (socklen_t )sun.sun_len) == -1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: server.c,v 1.11 2012/03/01 22:38:31 joerg Exp $ */
/* $NetBSD: server.c,v 1.12 2021/08/08 20:54:49 nia Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@ -58,7 +58,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: server.c,v 1.11 2012/03/01 22:38:31 joerg Exp $");
__RCSID("$NetBSD: server.c,v 1.12 2021/08/08 20:54:49 nia Exp $");
#include <sys/select.h>
#include <sys/stat.h>
@ -165,7 +165,7 @@ server_open_control(server_t *srv, char const *control)
}
opt = 1;
if (setsockopt(fd, 0, LOCAL_CREDS, &opt, sizeof(opt)) == -1)
if (setsockopt(fd, SOL_LOCAL, LOCAL_CREDS, &opt, sizeof(opt)) == -1)
log_crit("Warning: No credential checks on control socket");
memset(&un, 0, sizeof(un));