From owner-dev-commits-src-main@freebsd.org Mon Jan 4 19:57:41 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 78EE34C87EB; Mon, 4 Jan 2021 19:57:41 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4D8md132cPz3vTf; Mon, 4 Jan 2021 19:57:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5765E1FABC; Mon, 4 Jan 2021 19:57:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 104Jvf3Q009291; Mon, 4 Jan 2021 19:57:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 104JvfmM009290; Mon, 4 Jan 2021 19:57:41 GMT (envelope-from git) Date: Mon, 4 Jan 2021 19:57:41 GMT Message-Id: <202101041957.104JvfmM009290@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mariusz Zaborski Subject: git: 8c121177f063 - main - casper: convert macros to inline functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: oshogbo X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8c121177f063a187534dcd475b136c34474802cd Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jan 2021 19:57:41 -0000 The branch main has been updated by oshogbo: URL: https://cgit.FreeBSD.org/src/commit/?id=8c121177f063a187534dcd475b136c34474802cd commit 8c121177f063a187534dcd475b136c34474802cd Author: Mariusz Zaborski AuthorDate: 2021-01-04 19:50:58 +0000 Commit: Mariusz Zaborski CommitDate: 2021-01-04 19:55:35 +0000 casper: convert macros to inline functions In libcasper, the first argument to the function is a structure that represents a connection to Casper. On systems without Casper, macros are used to interpose the Casper functions to standard libc ones. This may cause errors/warnings that the variable is not used. With the inline function, there is no such problem. --- lib/libcasper/services/cap_pwd/cap_pwd.h | 109 +++++++++++++++++++++---- lib/libcasper/services/cap_sysctl/cap_sysctl.h | 65 ++++++++++++--- 2 files changed, 145 insertions(+), 29 deletions(-) diff --git a/lib/libcasper/services/cap_pwd/cap_pwd.h b/lib/libcasper/services/cap_pwd/cap_pwd.h index 74b9de098e2d..d8de56c3bea9 100644 --- a/lib/libcasper/services/cap_pwd/cap_pwd.h +++ b/lib/libcasper/services/cap_pwd/cap_pwd.h @@ -66,24 +66,97 @@ int cap_pwd_limit_users(cap_channel_t *chan, const char * const *names, __END_DECLS #else -#define cap_getpwent(chan) getpwent() -#define cap_getpwnam(chan, login) getpwnam(login) -#define cap_getpwuid(chan, uid) getpwuid(uid) - -#define cap_getpwent_r(chan, pwd, buffer, bufsize, result) \ - getpwent_r(pwd, buffer, bufsize, result) -#define cap_getpwnam_r(chan, name, pwd, buffer, bufsize, result) \ - getpwnam_r(name, pwd, buffer, bufsize, result) -#define cap_getpwuid_r(chan, uid, pwd, buffer, bufsize, result) \ - getpwuid_r(uid, pwd, buffer, bufsize, result) - -#define cap_setpassent(chan, stayopen) setpassent(stayopen) -#define cap_setpwent(chan) setpwent() -#define cap_endpwent(chan) endpwent() - -#define cap_pwd_limit_cmds(chan, cmds, ncmds) (0) -#define cap_pwd_limit_fields(chan, fields, nfields) (0) -#define cap_pwd_limit_users(chan, names, nnames, uids, nuids) (0) + +static inline struct passwd * +cap_getpwent(cap_channel_t *chan __unused) +{ + + return (getpwent()); +} + +static inline struct passwd * +cap_getpwnam(cap_channel_t *chan __unused, const char *login) +{ + + return (getpwnam(login)); +} + +static inline struct passwd * +cap_getpwuid(cap_channel_t *chan __unused, uid_t uid) +{ + + return (getpwuid(uid)); +} + +static inline int +cap_getpwent_r(cap_channel_t *chan __unused, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **result) +{ + + return (getpwent_r(pwd, buffer, bufsize, result)); +} + +static inline int +cap_getpwnam_r(cap_channel_t *chan __unused, const char *name, + struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) +{ + + return (getpwnam_r(name, pwd, buffer, bufsize, result)); +} + +static inline int +cap_getpwuid_r(cap_channel_t *chan __unused, uid_t uid, struct passwd *pwd, + char *buffer, size_t bufsize, struct passwd **result) +{ + + return (getpwuid_r(uid, pwd, buffer, bufsize, result)); +} + +static inline int +cap_setpassent(cap_channel_t *chan __unused, int stayopen) +{ + + return (setpassent(stayopen)); +} + +static inline void +cap_setpwent(cap_channel_t *chan __unused) +{ + + return (setpwent()); +} + +static inline void +cap_endpwent(cap_channel_t *chan __unused) +{ + + return (endpwent()); +} + +static inline int +cap_pwd_limit_cmds(cap_channel_t *chan __unused, + const char * const *cmds __unused, size_t ncmds __unused) +{ + + return (0); +} + +static inline int +cap_pwd_limit_fields(cap_channel_t *chan __unused, + const char * const *fields __unused, size_t nfields __unused) +{ + + return (0); +} + +static inline int +cap_pwd_limit_users(cap_channel_t *chan __unused, + const char * const *names __unused, size_t nnames __unused, + uid_t *uids __unused, size_t nuids __unused) +{ + + return (0); +} #endif #endif /* !_CAP_PWD_H_ */ diff --git a/lib/libcasper/services/cap_sysctl/cap_sysctl.h b/lib/libcasper/services/cap_sysctl/cap_sysctl.h index 226d7766a95e..df0fb7fd6f45 100644 --- a/lib/libcasper/services/cap_sysctl/cap_sysctl.h +++ b/lib/libcasper/services/cap_sysctl/cap_sysctl.h @@ -66,17 +66,60 @@ int cap_sysctl_limit(cap_sysctl_limit_t *limit); __END_DECLS #else /* !WITH_CASPER */ -#define cap_sysctl(chan, name, namelen, oldp, oldlenp, newp, newlen) \ - sysctl((name), (namelen), (oldp), (oldlenp), (newp), (newlen)) -#define cap_sysctlbyname(chan, name, oldp, oldlenp, newp, newlen) \ - sysctlbyname((name), (oldp), (oldlenp), (newp), (newlen)) -#define cap_sysctlnametomib(chan, name, mibp, sizep) \ - sysctlnametomib((name), (mibp), (sizep)) - -#define cap_sysctl_limit_init(chan) (NULL) -#define cap_sysctl_limit_name(limit, name, flags) (NULL) -#define cap_sysctl_limit_mib(limit, mibp, miblen, flags) (NULL) -#define cap_sysctl_limit(limit) (0) +static inline int +cap_sysctl(cap_channel_t *chan __unused, const int *name, u_int namelen, + void *oldp, size_t *oldlenp, const void *newp, size_t newlen) +{ + + return (sysctl(name, namelen, oldp, oldlenp, newp, newlen)); +} + +static inline int +cap_sysctlbyname(cap_channel_t *chan __unused, const char *name, + void *oldp, size_t *oldlenp, const void *newp, size_t newlen) +{ + + return (sysctlbyname(name, oldp, oldlenp, newp, newlen)); +} + +static inline int +cap_sysctlnametomib(cap_channel_t *chan __unused, const char *name, int *mibp, + size_t *sizep) +{ + + return (sysctlnametomib(name, mibp, sizep)); +} + +static inline cap_sysctl_limit_t * +cap_sysctl_limit_init(cap_channel_t *limit __unused) +{ + + return (NULL); +} + +static inline cap_sysctl_limit_t * +cap_sysctl_limit_name(cap_sysctl_limit_t *limit __unused, + const char *name __unused, int flags __unused) +{ + + return (NULL); +} + +static inline cap_sysctl_limit_t * +cap_sysctl_limit_mib(cap_sysctl_limit_t *limit __unused, + const int *mibp __unused, u_int miblen __unused, + int flags __unused) +{ + + return (NULL); +} + +static inline int +cap_sysctl_limit(cap_sysctl_limit_t *limit __unused) +{ + + return (0); +} #endif /* WITH_CASPER */ #endif /* !_CAP_SYSCTL_H_ */