1/*- 2 * Copyright (c) 2010 James Gritton. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 2010 James Gritton. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
69 70#define JF_OP_MASK (JF_START | JF_SET | JF_STOP) 71#define JF_RESTART (JF_START | JF_STOP) 72#define JF_START_SET (JF_START | JF_SET) 73#define JF_SET_RESTART (JF_SET | JF_STOP) 74#define JF_START_SET_RESTART (JF_START | JF_SET | JF_STOP) 75#define JF_DO_STOP(js) (((js) & (JF_SET | JF_STOP)) == JF_STOP) 76 77enum intparam { 78 IP_ALLOW_DYING = 1, /* Allow making changes to a dying jail */ 79 IP_COMMAND, /* Command run inside jail at creation */ 80 IP_DEPEND, /* Jail starts after (stops before) another */ 81 IP_EXEC_CLEAN, /* Run commands in a clean environment */ 82 IP_EXEC_CONSOLELOG, /* Redirect optput for commands run in jail */ 83 IP_EXEC_FIB, /* Run jailed commands with this FIB */ 84 IP_EXEC_JAIL_USER, /* Run jailed commands as this user */ 85 IP_EXEC_POSTSTART, /* Commands run outside jail after creating */ 86 IP_EXEC_POSTSTOP, /* Commands run outside jail after removing */ 87 IP_EXEC_PRESTART, /* Commands run outside jail before creating */ 88 IP_EXEC_PRESTOP, /* Commands run outside jail before removing */ 89 IP_EXEC_START, /* Commands run inside jail on creation */ 90 IP_EXEC_STOP, /* Commands run inside jail on removal */ 91 IP_EXEC_SYSTEM_JAIL_USER,/* Get jail_user from system passwd file */ 92 IP_EXEC_SYSTEM_USER, /* Run non-jailed commands as this user */ 93 IP_EXEC_TIMEOUT, /* Time to wait for a command to complete */ 94 IP_INTERFACE, /* Add IP addresses to this interface */ 95 IP_IP_HOSTNAME, /* Get jail IP address(es) from hostname */ 96 IP_MOUNT, /* Mount points in fstab(5) form */ 97 IP_MOUNT_DEVFS, /* Mount /dev under prison root */ 98 IP_MOUNT_DEVFS_RULESET, /* Ruleset for the devfs mount */ 99 IP_MOUNT_FSTAB, /* A standard fstab(5) file */ 100 IP_STOP_TIMEOUT, /* Time to wait after sending SIGTERM */ 101 IP_VNET_INTERFACE, /* Assign interface(s) to vnet jail */ 102 IP__IP4_IFADDR, /* Copy of ip4.addr with interface/netmask */ 103#ifdef INET6 104 IP__IP6_IFADDR, /* Copy of ip6.addr with interface/prefixlen */ 105#endif 106 KP_ALLOW_CHFLAGS, 107 KP_ALLOW_MOUNT, 108 KP_ALLOW_RAW_SOCKETS, 109 KP_ALLOW_SET_HOSTNAME, 110 KP_ALLOW_SOCKET_AF, 111 KP_ALLOW_SYSVIPC, 112 KP_ENFORCE_STATFS, 113 KP_HOST_HOSTNAME, 114 KP_IP4_ADDR, 115#ifdef INET6 116 KP_IP6_ADDR, 117#endif 118 KP_JID, 119 KP_NAME, 120 KP_PATH, 121 KP_PERSIST, 122 KP_SECURELEVEL, 123 KP_VNET, 124 IP_NPARAM 125}; 126 127STAILQ_HEAD(cfvars, cfvar); 128 129struct cfvar { 130 STAILQ_ENTRY(cfvar) tq; 131 char *name; 132 size_t pos; 133}; 134 135STAILQ_HEAD(cfstrings, cfstring); 136 137struct cfstring { 138 STAILQ_ENTRY(cfstring) tq; 139 char *s; 140 size_t len; 141 struct cfvars vars; 142}; 143 144TAILQ_HEAD(cfparams, cfparam); 145 146struct cfparam { 147 TAILQ_ENTRY(cfparam) tq; 148 char *name; 149 struct cfstrings val; 150 unsigned flags; 151 int gen; 152}; 153 154TAILQ_HEAD(cfjails, cfjail); 155STAILQ_HEAD(cfdepends, cfdepend); 156 157struct cfjail { 158 TAILQ_ENTRY(cfjail) tq; 159 char *name; 160 char *comline; 161 struct cfparams params; 162 struct cfdepends dep[2]; 163 struct cfjails *queue; 164 struct cfparam *intparams[IP_NPARAM]; 165 struct cfstring *comstring; 166 struct jailparam *jp; 167 struct timespec timeout; 168 enum intparam comparam; 169 unsigned flags; 170 int jid; 171 int seq; 172 int pstatus; 173 int ndeps; 174 int njp; 175 int nprocs; 176}; 177 178struct cfdepend { 179 STAILQ_ENTRY(cfdepend) tq[2]; 180 struct cfjail *j[2]; 181 unsigned flags; 182}; 183 184extern void *emalloc(size_t); 185extern void *erealloc(void *, size_t); 186extern char *estrdup(const char *); 187extern void failed(struct cfjail *j); 188extern void jail_note(const struct cfjail *j, const char *fmt, ...); 189extern void jail_warnx(const struct cfjail *j, const char *fmt, ...); 190 191extern int run_command(struct cfjail *j, int *plimit, enum intparam comparam); 192extern int finish_command(struct cfjail *j, int *plimit); 193extern struct cfjail *next_proc(int nonblock); 194extern int term_procs(struct cfjail *j); 195 196extern void load_config(void); 197extern struct cfjail *add_jail(void); 198extern void add_param(struct cfjail *j, const struct cfparam *p, 199 enum intparam ipnum, const char *value);
| 68 69#define JF_OP_MASK (JF_START | JF_SET | JF_STOP) 70#define JF_RESTART (JF_START | JF_STOP) 71#define JF_START_SET (JF_START | JF_SET) 72#define JF_SET_RESTART (JF_SET | JF_STOP) 73#define JF_START_SET_RESTART (JF_START | JF_SET | JF_STOP) 74#define JF_DO_STOP(js) (((js) & (JF_SET | JF_STOP)) == JF_STOP) 75 76enum intparam { 77 IP_ALLOW_DYING = 1, /* Allow making changes to a dying jail */ 78 IP_COMMAND, /* Command run inside jail at creation */ 79 IP_DEPEND, /* Jail starts after (stops before) another */ 80 IP_EXEC_CLEAN, /* Run commands in a clean environment */ 81 IP_EXEC_CONSOLELOG, /* Redirect optput for commands run in jail */ 82 IP_EXEC_FIB, /* Run jailed commands with this FIB */ 83 IP_EXEC_JAIL_USER, /* Run jailed commands as this user */ 84 IP_EXEC_POSTSTART, /* Commands run outside jail after creating */ 85 IP_EXEC_POSTSTOP, /* Commands run outside jail after removing */ 86 IP_EXEC_PRESTART, /* Commands run outside jail before creating */ 87 IP_EXEC_PRESTOP, /* Commands run outside jail before removing */ 88 IP_EXEC_START, /* Commands run inside jail on creation */ 89 IP_EXEC_STOP, /* Commands run inside jail on removal */ 90 IP_EXEC_SYSTEM_JAIL_USER,/* Get jail_user from system passwd file */ 91 IP_EXEC_SYSTEM_USER, /* Run non-jailed commands as this user */ 92 IP_EXEC_TIMEOUT, /* Time to wait for a command to complete */ 93 IP_INTERFACE, /* Add IP addresses to this interface */ 94 IP_IP_HOSTNAME, /* Get jail IP address(es) from hostname */ 95 IP_MOUNT, /* Mount points in fstab(5) form */ 96 IP_MOUNT_DEVFS, /* Mount /dev under prison root */ 97 IP_MOUNT_DEVFS_RULESET, /* Ruleset for the devfs mount */ 98 IP_MOUNT_FSTAB, /* A standard fstab(5) file */ 99 IP_STOP_TIMEOUT, /* Time to wait after sending SIGTERM */ 100 IP_VNET_INTERFACE, /* Assign interface(s) to vnet jail */ 101 IP__IP4_IFADDR, /* Copy of ip4.addr with interface/netmask */ 102#ifdef INET6 103 IP__IP6_IFADDR, /* Copy of ip6.addr with interface/prefixlen */ 104#endif 105 KP_ALLOW_CHFLAGS, 106 KP_ALLOW_MOUNT, 107 KP_ALLOW_RAW_SOCKETS, 108 KP_ALLOW_SET_HOSTNAME, 109 KP_ALLOW_SOCKET_AF, 110 KP_ALLOW_SYSVIPC, 111 KP_ENFORCE_STATFS, 112 KP_HOST_HOSTNAME, 113 KP_IP4_ADDR, 114#ifdef INET6 115 KP_IP6_ADDR, 116#endif 117 KP_JID, 118 KP_NAME, 119 KP_PATH, 120 KP_PERSIST, 121 KP_SECURELEVEL, 122 KP_VNET, 123 IP_NPARAM 124}; 125 126STAILQ_HEAD(cfvars, cfvar); 127 128struct cfvar { 129 STAILQ_ENTRY(cfvar) tq; 130 char *name; 131 size_t pos; 132}; 133 134STAILQ_HEAD(cfstrings, cfstring); 135 136struct cfstring { 137 STAILQ_ENTRY(cfstring) tq; 138 char *s; 139 size_t len; 140 struct cfvars vars; 141}; 142 143TAILQ_HEAD(cfparams, cfparam); 144 145struct cfparam { 146 TAILQ_ENTRY(cfparam) tq; 147 char *name; 148 struct cfstrings val; 149 unsigned flags; 150 int gen; 151}; 152 153TAILQ_HEAD(cfjails, cfjail); 154STAILQ_HEAD(cfdepends, cfdepend); 155 156struct cfjail { 157 TAILQ_ENTRY(cfjail) tq; 158 char *name; 159 char *comline; 160 struct cfparams params; 161 struct cfdepends dep[2]; 162 struct cfjails *queue; 163 struct cfparam *intparams[IP_NPARAM]; 164 struct cfstring *comstring; 165 struct jailparam *jp; 166 struct timespec timeout; 167 enum intparam comparam; 168 unsigned flags; 169 int jid; 170 int seq; 171 int pstatus; 172 int ndeps; 173 int njp; 174 int nprocs; 175}; 176 177struct cfdepend { 178 STAILQ_ENTRY(cfdepend) tq[2]; 179 struct cfjail *j[2]; 180 unsigned flags; 181}; 182 183extern void *emalloc(size_t); 184extern void *erealloc(void *, size_t); 185extern char *estrdup(const char *); 186extern void failed(struct cfjail *j); 187extern void jail_note(const struct cfjail *j, const char *fmt, ...); 188extern void jail_warnx(const struct cfjail *j, const char *fmt, ...); 189 190extern int run_command(struct cfjail *j, int *plimit, enum intparam comparam); 191extern int finish_command(struct cfjail *j, int *plimit); 192extern struct cfjail *next_proc(int nonblock); 193extern int term_procs(struct cfjail *j); 194 195extern void load_config(void); 196extern struct cfjail *add_jail(void); 197extern void add_param(struct cfjail *j, const struct cfparam *p, 198 enum intparam ipnum, const char *value);
|