Skip to content

Commit

Permalink
core-capabilies: move *CAP* capability macros to new header
Browse files Browse the repository at this point in the history
Move *CAP* capabilities macros from stress-ng.h to core-capabilities.
as these macros are only required for just several stressors and
it makes cppchecking faster.

Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Jan 24, 2022
1 parent a21310b commit 2bb0e81
Show file tree
Hide file tree
Showing 43 changed files with 338 additions and 386 deletions.
267 changes: 267 additions & 0 deletions core-capabilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
* Copyright (C) 2022 Colin Ian King
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CORE_CAPABILITIES_H
#define CORE_CAPABILITIES_H

#define SHIM_CAP_IS_ROOT (-1)

/* POSIX-draft defined capabilities */
#if defined(CAP_CHOWN)
#define SHIM_CAP_CHOWN CAP_CHOWN
#else
#define SHIM_CAP_CHOWN SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_DAC_OVERRIDE)
#define SHIM_CAP_DAC_OVERRIDE CAP_DAC_OVERRIDE
#else
#define SHIM_CAP_DAC_OVERRIDE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_DAC_READ_SEARCH)
#define SHIM_CAP_DAC_READ_SEARCH CAP_DAC_READ_SEARCH
#else
#define SHIM_CAP_DAC_READ_SEARCH SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_FOWNER)
#define SHIM_CAP_FOWNER CAP_FOWNER
#else
#define SHIM_CAP_FOWNER SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_FSETID)
#define SHIM_CAP_FSETID CAP_FSETID
#else
#define SHIM_CAP_FSETID SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_KILL)
#define SHIM_CAP_KILL CAP_KILL
#else
#define SHIM_CAP_KILL SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SETGID)
#define SHIM_CAP_SETGID CAP_SETGID
#else
#define SHIM_CAP_SETGID SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SETUID)
#define SHIM_CAP_SETUID CAP_SETUID
#else
#define SHIM_CAP_SETUID SHIM_CAP_IS_ROOT
#endif

/* Linux specific capabilities */
#if defined(CAP_SETPCAP)
#define SHIM_CAP_SETPCAP CAP_SETPCAP
#else
#define SHIM_CAP_SETPCAP SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_LINUX_IMMUTABLE)
#define SHIM_CAP_LINUX_IMMUTABLE CAP_LINUX_IMMUTABLE
#else
#define SHIM_CAP_LINUX_IMMUTABLE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_NET_BIND_SERVICE)
#define SHIM_CAP_NET_BIND_SERVICE CAP_NET_BIND_SERVICE
#else
#define SHIM_CAP_NET_BIND_SERVICE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_NET_BROADCAST)
#define SHIM_CAP_NET_BROADCAST CAP_NET_BROADCAST
#else
#define SHIM_CAP_NET_BROADCAST SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_NET_ADMIN)
#define SHIM_CAP_NET_ADMIN CAP_NET_ADMIN
#else
#define SHIM_CAP_NET_ADMIN SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_NET_RAW)
#define SHIM_CAP_NET_RAW CAP_NET_RAW
#else
#define SHIM_CAP_NET_RAW SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_IPC_LOCK)
#define SHIM_CAP_IPC_LOCK CAP_IPC_LOCK
#else
#define SHIM_CAP_IPC_LOCK SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_IPC_OWNER)
#define SHIM_CAP_IPC_OWNER CAP_IPC_OWNER
#else
#define SHIM_CAP_IPC_OWNER SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_MODULE)
#define SHIM_CAP_SYS_MODULE CAP_SYS_MODULE
#else
#define SHIM_CAP_SYS_MODULE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_RAWIO)
#define SHIM_CAP_SYS_RAWIO CAP_SYS_RAWIO
#else
#define SHIM_CAP_SYS_RAWIO SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_CHROOT)
#define SHIM_CAP_SYS_CHROOT CAP_SYS_CHROOT
#else
#define SHIM_CAP_SYS_CHROOT SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_PTRACE)
#define SHIM_CAP_SYS_PTRACE CAP_SYS_PTRACE
#else
#define SHIM_CAP_SYS_PTRACE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_PACCT)
#define SHIM_CAP_SYS_PACCT CAP_SYS_PACCT
#else
#define SHIM_CAP_SYS_PACCT SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_ADMIN)
#define SHIM_CAP_SYS_ADMIN CAP_SYS_ADMIN
#else
#define SHIM_CAP_SYS_ADMIN SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_BOOT)
#define SHIM_CAP_SYS_BOOT CAP_SYS_BOOT
#else
#define SHIM_CAP_SYS_BOOT SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_NICE)
#define SHIM_CAP_SYS_NICE CAP_SYS_NICE
#else
#define SHIM_CAP_SYS_NICE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_RESOURCE)
#define SHIM_CAP_SYS_RESOURCE CAP_SYS_RESOURCE
#else
#define SHIM_CAP_SYS_RESOURCE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_TIME)
#define SHIM_CAP_SYS_TIME CAP_SYS_TIME
#else
#define SHIM_CAP_SYS_TIME SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYS_TTY_CONFIG)
#define SHIM_CAP_SYS_TTY_CONFIG CAP_SYS_TTY_CONFIG
#else
#define SHIM_CAP_SYS_TTY_CONFIG SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_MKNOD)
#define SHIM_CAP_MKNOD CAP_MKNOD
#else
#define SHIM_CAP_MKNOD SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_LEASE)
#define SHIM_CAP_LEASE CAP_LEASE
#else
#define SHIM_CAP_LEASE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_AUDIT_WRITE)
#define SHIM_CAP_AUDIT_WRITE CAP_AUDIT_WRITE
#else
#define SHIM_CAP_AUDIT_WRITE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_AUDIT_CONTROL)
#define SHIM_CAP_AUDIT_CONTROL CAP_AUDIT_CONTROL
#else
#define SHIM_CAP_AUDIT_CONTROL SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SETFCAP)
#define SHIM_CAP_SETFCAP CAP_SETFCAP
#else
#define SHIM_CAP_SETFCAP SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_MAC_OVERRIDE)
#define SHIM_CAP_MAC_OVERRIDE CAP_MAC_OVERRIDE
#else
#define SHIM_CAP_MAC_OVERRIDE SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_MAC_ADMIN)
#define SHIM_CAP_MAC_ADMIN CAP_MAC_ADMIN
#else
#define SHIM_CAP_MAC_ADMIN SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_SYSLOG)
#define SHIM_CAP_SYSLOG CAP_SYSLOG
#else
#define SHIM_CAP_SYSLOG SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_WAKE_ALARM)
#define SHIM_CAP_WAKE_ALARM CAP_WAKE_ALARM
#else
#define SHIM_CAP_WAKE_ALARM SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_BLOCK_SUSPEND)
#define SHIM_CAP_BLOCK_SUSPEND CAP_BLOCK_SUSPEND
#else
#define SHIM_CAP_BLOCK_SUSPEND SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_AUDIT_READ)
#define SHIM_CAP_AUDIT_READ CAP_AUDIT_READ
#else
#define SHIM_CAP_AUDIT_READ SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_PERFMON)
#define SHIM_CAP_PERFMON CAP_PERFMON
#else
#define SHIM_CAP_PERFMON SHIM_CAP_IS_ROOT
#endif

#if defined(CAP_BPF)
#define SHIM_CAP_BPF CAP_BPF
#else
#define SHIM_CAP_BPF SHIM_CAP_IS_ROOT
#endif


#endif
8 changes: 2 additions & 6 deletions core-ftrace.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2021 Canonical, Ltd.
* Copyright (C) 2022 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -15,14 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* This code is a complete clean re-write of the stress tool by
* Colin Ian King <[email protected]> and attempts to be
* backwardly compatible with the stress tool by Amos Waterland
* <[email protected]> but has more stress tests and more
* functionality.
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

#if defined(HAVE_LIB_BSD) && \
defined(__linux__)
Expand Down
1 change: 1 addition & 0 deletions core-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
#include "stress-ng.h"
#include "git-commit-id.h"
#include "core-capabilities.h"

#if !defined(PR_SET_DISABLE)
#define SUID_DUMP_DISABLE (0) /* No setuid dumping */
Expand Down
3 changes: 2 additions & 1 deletion core-smart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2021 Canonical, Ltd.
* Copyright (C) 2022 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -17,7 +18,7 @@
*
*/
#include "stress-ng.h"

#include "core-capabilities.h"

#define DEVS_MAX (256)

Expand Down
1 change: 1 addition & 0 deletions stress-bad-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

static const stress_help_t help[] = {
{ NULL, "bad-ioctl N", "start N stressors that perform illegal read ioctls on devices" },
Expand Down
8 changes: 2 additions & 6 deletions stress-binderfs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2021 Canonical, Ltd.
* Copyright (C) 2022 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -15,14 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* This code is a complete clean re-write of the stress tool by
* Colin Ian King <[email protected]> and attempts to be
* backwardly compatible with the stress tool by Amos Waterland
* <[email protected]> but has more stress tests and more
* functionality.
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

static const stress_help_t help[] = {
{ NULL, "binderfs N", "start N workers exercising binderfs" },
Expand Down
1 change: 1 addition & 0 deletions stress-chdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

#define MIN_CHDIR_DIRS (64)
#define MAX_CHDIR_DIRS (65536)
Expand Down
1 change: 1 addition & 0 deletions stress-chroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

static const stress_help_t help[] = {
{ NULL, "chroot N", "start N workers thrashing chroot" },
Expand Down
1 change: 1 addition & 0 deletions stress-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

static const stress_help_t help[] = {
{ NULL, "clock N", "start N workers thrashing clocks and POSIX timers" },
Expand Down
2 changes: 2 additions & 0 deletions stress-close.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2021 Canonical, Ltd.
* Copyright (C) 2022 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -23,6 +24,7 @@
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"

static const stress_help_t help[] = {
{ NULL, "close N", "start N workers that exercise races on close" },
Expand Down
Loading

0 comments on commit 2bb0e81

Please sign in to comment.