zapret/nfq/sec.h

93 lines
1.7 KiB
C
Raw Normal View History

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