2015-05-15 05:44:48 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
nsjail
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
Copyright 2014 Google Inc. All Rights Reserved.
|
2016-01-21 03:21:27 +08:00
|
|
|
Copyright 2016 Sergiusz Bazanski. All Rights Reserved.
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
*/
|
2016-01-22 07:11:31 +08:00
|
|
|
|
2016-03-11 09:45:43 +08:00
|
|
|
#ifndef NS_NSJAIL_H
|
|
|
|
#define NS_NSJAIL_H
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2018-02-01 21:19:01 +08:00
|
|
|
#include <linux/filter.h>
|
2017-10-18 20:27:34 +08:00
|
|
|
#include <netinet/ip6.h>
|
2017-10-18 18:33:24 +08:00
|
|
|
#include <signal.h>
|
2017-10-18 20:27:34 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2017-11-09 00:20:57 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-02-10 06:04:57 +08:00
|
|
|
#include <string>
|
2018-02-10 05:35:33 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2018-02-11 00:49:15 +08:00
|
|
|
#include "logs.h"
|
|
|
|
|
2017-10-18 18:33:24 +08:00
|
|
|
static const int nssigs[] = {
|
2017-10-26 06:26:02 +08:00
|
|
|
SIGINT,
|
|
|
|
SIGQUIT,
|
|
|
|
SIGUSR1,
|
|
|
|
SIGALRM,
|
|
|
|
SIGCHLD,
|
|
|
|
SIGTERM,
|
2017-10-18 18:33:24 +08:00
|
|
|
};
|
2016-03-02 00:03:11 +08:00
|
|
|
|
2017-10-18 20:27:34 +08:00
|
|
|
struct pids_t {
|
|
|
|
pid_t pid;
|
|
|
|
time_t start;
|
|
|
|
char remote_txt[64];
|
|
|
|
struct sockaddr_in6 remote_addr;
|
|
|
|
int pid_syscall_fd;
|
|
|
|
};
|
|
|
|
|
2018-02-10 21:38:01 +08:00
|
|
|
struct mount_t {
|
|
|
|
std::string src;
|
|
|
|
std::string src_content;
|
|
|
|
std::string dst;
|
|
|
|
std::string fs_type;
|
|
|
|
std::string options;
|
2017-10-18 20:27:34 +08:00
|
|
|
uintptr_t flags;
|
|
|
|
bool isDir;
|
|
|
|
bool isSymlink;
|
|
|
|
bool mandatory;
|
|
|
|
bool mounted;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct idmap_t {
|
|
|
|
uid_t inside_id;
|
|
|
|
uid_t outside_id;
|
|
|
|
size_t count;
|
|
|
|
bool is_newidmap;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ns_mode_t {
|
|
|
|
MODE_LISTEN_TCP = 0,
|
|
|
|
MODE_STANDALONE_ONCE,
|
|
|
|
MODE_STANDALONE_EXECVE,
|
|
|
|
MODE_STANDALONE_RERUN
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsjconf_t {
|
|
|
|
const char* exec_file;
|
2017-10-18 23:57:52 +08:00
|
|
|
bool use_execveat;
|
|
|
|
int exec_fd;
|
|
|
|
const char** argv;
|
2018-02-10 11:10:18 +08:00
|
|
|
std::string hostname;
|
|
|
|
std::string cwd;
|
|
|
|
std::string chroot;
|
2017-10-18 20:27:34 +08:00
|
|
|
int port;
|
|
|
|
const char* bindhost;
|
2018-02-10 11:10:18 +08:00
|
|
|
std::string logfile;
|
2018-02-11 00:49:15 +08:00
|
|
|
logs::llevel_t loglevel;
|
2017-10-18 20:27:34 +08:00
|
|
|
bool daemonize;
|
|
|
|
time_t tlimit;
|
|
|
|
size_t max_cpus;
|
|
|
|
bool keep_env;
|
|
|
|
bool keep_caps;
|
|
|
|
bool disable_no_new_privs;
|
2017-10-25 21:44:35 +08:00
|
|
|
uint64_t rl_as;
|
|
|
|
uint64_t rl_core;
|
|
|
|
uint64_t rl_cpu;
|
|
|
|
uint64_t rl_fsize;
|
|
|
|
uint64_t rl_nofile;
|
|
|
|
uint64_t rl_nproc;
|
|
|
|
uint64_t rl_stack;
|
2017-10-18 20:27:34 +08:00
|
|
|
unsigned long personality;
|
|
|
|
bool clone_newnet;
|
|
|
|
bool clone_newuser;
|
|
|
|
bool clone_newns;
|
|
|
|
bool clone_newpid;
|
|
|
|
bool clone_newipc;
|
|
|
|
bool clone_newuts;
|
|
|
|
bool clone_newcgroup;
|
|
|
|
enum ns_mode_t mode;
|
|
|
|
bool is_root_rw;
|
|
|
|
bool is_silent;
|
|
|
|
bool skip_setsid;
|
|
|
|
unsigned int max_conns_per_ip;
|
|
|
|
size_t tmpfs_size;
|
|
|
|
bool mount_proc;
|
|
|
|
const char* proc_path;
|
|
|
|
bool is_proc_rw;
|
|
|
|
bool iface_no_lo;
|
|
|
|
const char* iface_vs;
|
|
|
|
const char* iface_vs_ip;
|
|
|
|
const char* iface_vs_nm;
|
|
|
|
const char* iface_vs_gw;
|
|
|
|
const char* cgroup_mem_mount;
|
|
|
|
const char* cgroup_mem_parent;
|
|
|
|
size_t cgroup_mem_max;
|
|
|
|
const char* cgroup_pids_mount;
|
|
|
|
const char* cgroup_pids_parent;
|
2017-10-25 21:50:24 +08:00
|
|
|
unsigned int cgroup_pids_max;
|
2017-10-25 16:15:03 +08:00
|
|
|
const char* cgroup_net_cls_mount;
|
|
|
|
const char* cgroup_net_cls_parent;
|
|
|
|
unsigned int cgroup_net_cls_classid;
|
2018-02-04 11:15:19 +08:00
|
|
|
const char* cgroup_cpu_mount;
|
|
|
|
const char* cgroup_cpu_parent;
|
|
|
|
unsigned int cgroup_cpu_ms_per_sec;
|
2018-01-31 23:04:39 +08:00
|
|
|
const char* kafel_file_path;
|
|
|
|
const char* kafel_string;
|
2018-02-01 21:19:01 +08:00
|
|
|
struct sock_fprog seccomp_fprog;
|
2017-10-18 20:27:34 +08:00
|
|
|
long num_cpus;
|
2017-10-20 04:39:37 +08:00
|
|
|
uid_t orig_uid;
|
2018-02-10 21:38:01 +08:00
|
|
|
std::vector<mount_t> mountpts;
|
2018-02-10 12:13:25 +08:00
|
|
|
std::vector<pids_t> pids;
|
2018-02-10 07:37:23 +08:00
|
|
|
std::vector<idmap_t> uids;
|
|
|
|
std::vector<idmap_t> gids;
|
2018-02-10 06:04:57 +08:00
|
|
|
std::vector<std::string> envs;
|
2018-02-10 05:47:00 +08:00
|
|
|
std::vector<int> openfds;
|
2018-02-10 05:35:33 +08:00
|
|
|
std::vector<int> caps;
|
2017-10-18 20:27:34 +08:00
|
|
|
};
|
|
|
|
|
2017-10-09 05:00:45 +08:00
|
|
|
#endif /* _NSJAIL_H */
|