2021-03-04 11:30:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#include <stddef.h>
|
2021-03-04 11:30:38 +00:00
|
|
|
#include <sys/capability.h>
|
2022-11-22 14:49:53 +00:00
|
|
|
#include <linux/audit.h>
|
2021-03-04 11:30:38 +00:00
|
|
|
|
|
|
|
bool checkpcap(uint64_t caps);
|
|
|
|
bool setpcap(uint64_t caps);
|
2023-10-13 17:10:46 +00:00
|
|
|
int getmaxcap(void);
|
|
|
|
bool dropcaps(void);
|
2022-11-22 14:49:53 +00:00
|
|
|
|
|
|
|
#define syscall_nr (offsetof(struct seccomp_data, nr))
|
|
|
|
#define arch_nr (offsetof(struct seccomp_data, arch))
|
|
|
|
#define syscall_arg(x) (offsetof(struct seccomp_data, args[x]))
|
|
|
|
|
|
|
|
#if defined(__aarch64__)
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# define REG_SYSCALL regs.regs[8]
|
|
|
|
# define ARCH_NR AUDIT_ARCH_AARCH64
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#elif defined(__amd64__)
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# define REG_SYSCALL REG_RAX
|
|
|
|
# define ARCH_NR AUDIT_ARCH_X86_64
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#elif defined(__arm__) && (defined(__ARM_EABI__) || defined(__thumb__))
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# define REG_SYSCALL regs.uregs[7]
|
|
|
|
# if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
# define ARCH_NR AUDIT_ARCH_ARM
|
|
|
|
# else
|
|
|
|
# define ARCH_NR AUDIT_ARCH_ARMEB
|
|
|
|
# endif
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#elif defined(__i386__)
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# define REG_SYSCALL REG_EAX
|
|
|
|
# define ARCH_NR AUDIT_ARCH_I386
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#elif defined(__mips__)
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# define REG_SYSCALL regs[2]
|
2024-09-14 18:00:15 +00:00
|
|
|
|
|
|
|
#if _MIPS_SIM == _MIPS_SIM_ABI32
|
2022-11-22 14:49:53 +00:00
|
|
|
# if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
# define ARCH_NR AUDIT_ARCH_MIPSEL
|
|
|
|
# else
|
|
|
|
# define ARCH_NR AUDIT_ARCH_MIPS
|
|
|
|
# endif
|
2024-09-14 18:00:15 +00:00
|
|
|
#elif _MIPS_SIM == _MIPS_SIM_ABI64
|
|
|
|
# if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
# define ARCH_NR AUDIT_ARCH_MIPSEL64
|
|
|
|
# else
|
|
|
|
# define ARCH_NR AUDIT_ARCH_MIPS64
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# warning "Platform does not support seccomp filter yet"
|
|
|
|
# define REG_SYSCALL 0
|
|
|
|
# define ARCH_NR 0
|
|
|
|
#endif
|
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#elif defined(__PPC__)
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# define REG_SYSCALL regs.gpr[0]
|
|
|
|
# define ARCH_NR AUDIT_ARCH_PPC
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#else
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
# warning "Platform does not support seccomp filter yet"
|
|
|
|
# define REG_SYSCALL 0
|
|
|
|
# define ARCH_NR 0
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2022-11-22 14:49:53 +00:00
|
|
|
#endif
|
|
|
|
|
2021-03-04 11:30:38 +00:00
|
|
|
#endif
|
|
|
|
|
2024-09-14 18:00:15 +00:00
|
|
|
|
2024-04-26 18:36:27 +00:00
|
|
|
#ifndef __CYGWIN__
|
2023-10-13 17:10:46 +00:00
|
|
|
bool sec_harden(void);
|
|
|
|
bool can_drop_root(void);
|
2021-03-04 11:30:38 +00:00
|
|
|
bool droproot(uid_t uid, gid_t gid);
|
2023-10-13 17:10:46 +00:00
|
|
|
void print_id(void);
|
2024-04-26 18:36:27 +00:00
|
|
|
#endif
|
|
|
|
|
2023-10-13 17:10:46 +00:00
|
|
|
void daemonize(void);
|
2021-03-04 11:30:38 +00:00
|
|
|
bool writepid(const char *filename);
|