zapret/tpws/sec.h

91 lines
1.7 KiB
C
Raw Normal View History

2021-03-04 14:30:38 +03:00
#pragma once
2024-08-23 21:15:27 +03:00
#include "params.h"
2021-03-04 14:30:38 +03:00
#include <sys/types.h>
#include <stdbool.h>
#ifdef __linux__
2022-11-22 17:49:53 +03:00
#include <stddef.h>
2021-03-04 14:30:38 +03:00
#include <sys/capability.h>
2022-11-22 17:49:53 +03:00
#include <linux/audit.h>
2021-03-04 14:30:38 +03:00
bool checkpcap(uint64_t caps);
bool setpcap(uint64_t caps);
2023-10-13 20:10:46 +03:00
int getmaxcap(void);
bool dropcaps(void);
2022-11-22 17:49:53 +03: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 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
# define ARCH_NR AUDIT_ARCH_AARCH64
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
#elif defined(__amd64__)
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
# define ARCH_NR AUDIT_ARCH_X86_64
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
#elif defined(__arm__) && (defined(__ARM_EABI__) || defined(__thumb__))
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define ARCH_NR AUDIT_ARCH_ARM
# else
# define ARCH_NR AUDIT_ARCH_ARMEB
# endif
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
#elif defined(__i386__)
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
# define ARCH_NR AUDIT_ARCH_I386
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
#elif defined(__mips__)
2024-09-14 21:00:15 +03:00
#if _MIPS_SIM == _MIPS_SIM_ABI32
2022-11-22 17:49:53 +03:00
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define ARCH_NR AUDIT_ARCH_MIPSEL
# else
# define ARCH_NR AUDIT_ARCH_MIPS
# endif
2024-09-14 21:00:15 +03: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
2024-09-15 09:25:16 +03:00
# error "Unsupported mips abi"
2024-09-14 21:00:15 +03:00
#endif
2024-09-15 09:25:16 +03:00
#elif defined(__PPC64__)
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define ARCH_NR AUDIT_ARCH_PPC64LE
# else
# define ARCH_NR AUDIT_ARCH_PPC64
# endif
2022-11-22 17:49:53 +03:00
#elif defined(__PPC__)
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
# define ARCH_NR AUDIT_ARCH_PPC
2024-09-14 21:00:15 +03:00
2024-09-15 12:10:04 +03:00
#elif __riscv && __riscv_xlen == 64
# define ARCH_NR AUDIT_ARCH_RISCV64
2022-11-22 17:49:53 +03:00
#else
2024-09-14 21:00:15 +03:00
2024-09-15 09:25:16 +03:00
# error "Platform does not support seccomp filter yet"
2024-09-14 21:00:15 +03:00
2022-11-22 17:49:53 +03:00
#endif
2021-03-04 14:30:38 +03:00
#endif
2023-10-13 20:10:46 +03:00
bool sec_harden(void);
2021-03-04 14:30:38 +03:00
bool can_drop_root();
bool droproot(uid_t uid, gid_t gid);
2023-10-13 20:10:46 +03:00
void print_id(void);
void daemonize(void);
2021-03-04 14:30:38 +03:00
bool writepid(const char *filename);