From owner-svn-src-all@freebsd.org Wed Jun 26 16:38:47 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AE9EA15CC902; Wed, 26 Jun 2019 16:38:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5723B751EE; Wed, 26 Jun 2019 16:38:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2F4CC245D; Wed, 26 Jun 2019 16:38:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5QGclrG051290; Wed, 26 Jun 2019 16:38:47 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5QGckQS051285; Wed, 26 Jun 2019 16:38:46 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201906261638.x5QGckQS051285@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Wed, 26 Jun 2019 16:38:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r349425 - stable/12/lib/libcapsicum X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/lib/libcapsicum X-SVN-Commit-Revision: 349425 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5723B751EE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.954,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2019 16:38:47 -0000 Author: ian Date: Wed Jun 26 16:38:46 2019 New Revision: 349425 URL: https://svnweb.freebsd.org/changeset/base/349425 Log: MFC r340130, r340134: r340130: (by oshogbo) libcapsicum: Introduce caph_{rights,ioctls,fcntls}_limit The idea behind those functions is not to force consumers to remember that there is a need to check errno on failure. We already have a caph_enter(3) function which does the same for cap_enter(2). r340134: (by oshogbo) Fix a recusive call introduce in the r340130. Modified: stable/12/lib/libcapsicum/Makefile stable/12/lib/libcapsicum/capsicum_helpers.3 stable/12/lib/libcapsicum/capsicum_helpers.h Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libcapsicum/Makefile ============================================================================== --- stable/12/lib/libcapsicum/Makefile Wed Jun 26 16:38:30 2019 (r349424) +++ stable/12/lib/libcapsicum/Makefile Wed Jun 26 16:38:46 2019 (r349425) @@ -8,6 +8,7 @@ MAN+= capsicum_helpers.3 MLINKS+=capsicum_helpers.3 caph_enter.3 MLINKS+=capsicum_helpers.3 caph_enter_casper.3 +MLINKS+=capsicum_helpers.3 caph_rights_limit.3 MLINKS+=capsicum_helpers.3 caph_limit_stream.3 MLINKS+=capsicum_helpers.3 caph_limit_stdin.3 MLINKS+=capsicum_helpers.3 caph_limit_stderr.3 Modified: stable/12/lib/libcapsicum/capsicum_helpers.3 ============================================================================== --- stable/12/lib/libcapsicum/capsicum_helpers.3 Wed Jun 26 16:38:30 2019 (r349424) +++ stable/12/lib/libcapsicum/capsicum_helpers.3 Wed Jun 26 16:38:46 2019 (r349425) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 18, 2018 +.Dd November 4, 2018 .Dt CAPSICUM_HELPERS 3 .Os .Sh NAME @@ -34,7 +34,12 @@ .Nm caph_limit_stdout , .Nm caph_limit_stdio , .Nm caph_cache_tzdata , -.Nm caph_cache_catpages +.Nm caph_cache_catpages , +.Nm caph_enter , +.Nm caph_enter_casper , +.Nm caph_rights_limit , +.Nm caph_ioctls_limit , +.Nm caph_fcntls_limit .Nd "set of the capsicum helpers, part of the libcapsicum" .Sh LIBRARY .Lb libcapsicum @@ -45,8 +50,12 @@ .Ft int .Fn caph_enter_casper "void" .Ft int -.Fn caph_limit_stream "int fd" "int flags" +.Fn caph_rights_limit "inf fd" "const cap_righst_t *rights" .Ft int +.Fn caph_ioctls_limit "inf fd" "const unsigned long *cmds" "size_t ncmds" +.Ft int +.Fn caph_fcntls_limit "inf fd" "uint32_t fcntlrights" +.Ft int .Fn caph_limit_stdin "void" .Ft int .Fn caph_limit_stderr "void" @@ -60,9 +69,17 @@ .Fn caph_cache_catpages "void" .Sh DESCRIPTION The -.Nm caph_enter -is equivalent to the -.Xr cap_enter 2 +.Nm caph_enter , +.Nm caph_rights_limit , +.Nm caph_ioctls_limit +and +.Nm caph_fcntls_limit +are respectively equivalent to +.Xr cap_enter 2 , +.Xr cap_rights_limit 2 , +.Xr cap_ioctls_limit 2 +and +.Xr cap_fcntls_limit 2 , it returns success when the kernel is built without support of the capability mode. .Pp @@ -125,4 +142,5 @@ among others. .Ed .Sh SEE ALSO .Xr cap_enter 2 , +.Xr cap_rights_limit 2 , .Xr rights 4 Modified: stable/12/lib/libcapsicum/capsicum_helpers.h ============================================================================== --- stable/12/lib/libcapsicum/capsicum_helpers.h Wed Jun 26 16:38:30 2019 (r349424) +++ stable/12/lib/libcapsicum/capsicum_helpers.h Wed Jun 26 16:38:46 2019 (r349425) @@ -136,6 +136,35 @@ caph_enter(void) return (0); } +static __inline int +caph_rights_limit(int fd, const cap_rights_t *rights) +{ + + if (cap_rights_limit(fd, rights) < 0 && errno != ENOSYS) + return (-1); + + return (0); +} + +static __inline int +caph_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds) +{ + + if (cap_ioctls_limit(fd, cmds, ncmds) < 0 && errno != ENOSYS) + return (-1); + + return (0); +} + +static __inline int +caph_fcntls_limit(int fd, uint32_t fcntlrights) +{ + + if (cap_fcntls_limit(fd, fcntlrights) < 0 && errno != ENOSYS) + return (-1); + + return (0); +} static __inline int caph_enter_casper(void)