1/*- 2 * Copyright (c) 2011 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) 2011 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 *
|
26 * $FreeBSD: stable/10/usr.sbin/jail/jailp.h 256387 2013-10-12 17:46:13Z hrs $
| 26 * $FreeBSD: stable/10/usr.sbin/jail/jailp.h 278484 2015-02-10 01:05:51Z jamie $
|
27 */ 28 29#include <sys/param.h> 30#include <sys/types.h> 31#include <sys/jail.h> 32#include <sys/queue.h> 33#include <sys/time.h> 34 35#include <jail.h> 36 37#define CONF_FILE "/etc/jail.conf" 38 39#define DEP_FROM 0 40#define DEP_TO 1 41 42#define DF_SEEN 0x01 /* Dependency has been followed */ 43#define DF_LIGHT 0x02 /* Implied dependency on jail existence only */ 44#define DF_NOFAIL 0x04 /* Don't propigate failed jails */ 45 46#define PF_VAR 0x01 /* This is a variable, not a true parameter */ 47#define PF_APPEND 0x02 /* Append to existing parameter list */ 48#define PF_BAD 0x04 /* Unable to resolve parameter value */ 49#define PF_INTERNAL 0x08 /* Internal parameter, not passed to kernel */ 50#define PF_BOOL 0x10 /* Boolean parameter */ 51#define PF_INT 0x20 /* Integer parameter */ 52#define PF_CONV 0x40 /* Parameter duplicated in converted form */ 53#define PF_REV 0x80 /* Run commands in reverse order on stopping */ 54 55#define JF_START 0x0001 /* -c */ 56#define JF_SET 0x0002 /* -m */ 57#define JF_STOP 0x0004 /* -r */ 58#define JF_DEPEND 0x0008 /* Operation required by dependency */ 59#define JF_WILD 0x0010 /* Not specified on the command line */ 60#define JF_FAILED 0x0020 /* Operation failed */ 61#define JF_PARAMS 0x0040 /* Parameters checked and imported */ 62#define JF_RDTUN 0x0080 /* Create-only parameter check has been done */ 63#define JF_PERSIST 0x0100 /* Jail is temporarily persistent */ 64#define JF_TIMEOUT 0x0200 /* A command (or process kill) timed out */ 65#define JF_SLEEPQ 0x0400 /* Waiting on a command and/or timeout */ 66 67#define JF_OP_MASK (JF_START | JF_SET | JF_STOP) 68#define JF_RESTART (JF_START | JF_STOP) 69#define JF_START_SET (JF_START | JF_SET) 70#define JF_SET_RESTART (JF_SET | JF_STOP) 71#define JF_START_SET_RESTART (JF_START | JF_SET | JF_STOP) 72#define JF_DO_STOP(js) (((js) & (JF_SET | JF_STOP)) == JF_STOP) 73 74enum intparam { 75 IP__NULL = 0, /* Null command */ 76 IP_ALLOW_DYING, /* Allow making changes to a dying jail */ 77 IP_COMMAND, /* Command run inside jail at creation */ 78 IP_DEPEND, /* Jail starts after (stops before) another */ 79 IP_EXEC_CLEAN, /* Run commands in a clean environment */ 80 IP_EXEC_CONSOLELOG, /* Redirect optput for commands run in jail */ 81 IP_EXEC_FIB, /* Run jailed commands with this FIB */ 82 IP_EXEC_JAIL_USER, /* Run jailed commands as this user */ 83 IP_EXEC_POSTSTART, /* Commands run outside jail after creating */ 84 IP_EXEC_POSTSTOP, /* Commands run outside jail after removing */ 85 IP_EXEC_PRESTART, /* Commands run outside jail before creating */ 86 IP_EXEC_PRESTOP, /* Commands run outside jail before removing */ 87 IP_EXEC_START, /* Commands run inside jail on creation */ 88 IP_EXEC_STOP, /* Commands run inside jail on removal */ 89 IP_EXEC_SYSTEM_JAIL_USER,/* Get jail_user from system passwd file */ 90 IP_EXEC_SYSTEM_USER, /* Run non-jailed commands as this user */ 91 IP_EXEC_TIMEOUT, /* Time to wait for a command to complete */ 92#if defined(INET) || defined(INET6) 93 IP_INTERFACE, /* Add IP addresses to this interface */ 94 IP_IP_HOSTNAME, /* Get jail IP address(es) from hostname */ 95#endif 96 IP_MOUNT, /* Mount points in fstab(5) form */ 97 IP_MOUNT_DEVFS, /* Mount /dev under prison root */ 98 IP_MOUNT_FDESCFS, /* Mount /dev/fd under prison root */
| 27 */ 28 29#include <sys/param.h> 30#include <sys/types.h> 31#include <sys/jail.h> 32#include <sys/queue.h> 33#include <sys/time.h> 34 35#include <jail.h> 36 37#define CONF_FILE "/etc/jail.conf" 38 39#define DEP_FROM 0 40#define DEP_TO 1 41 42#define DF_SEEN 0x01 /* Dependency has been followed */ 43#define DF_LIGHT 0x02 /* Implied dependency on jail existence only */ 44#define DF_NOFAIL 0x04 /* Don't propigate failed jails */ 45 46#define PF_VAR 0x01 /* This is a variable, not a true parameter */ 47#define PF_APPEND 0x02 /* Append to existing parameter list */ 48#define PF_BAD 0x04 /* Unable to resolve parameter value */ 49#define PF_INTERNAL 0x08 /* Internal parameter, not passed to kernel */ 50#define PF_BOOL 0x10 /* Boolean parameter */ 51#define PF_INT 0x20 /* Integer parameter */ 52#define PF_CONV 0x40 /* Parameter duplicated in converted form */ 53#define PF_REV 0x80 /* Run commands in reverse order on stopping */ 54 55#define JF_START 0x0001 /* -c */ 56#define JF_SET 0x0002 /* -m */ 57#define JF_STOP 0x0004 /* -r */ 58#define JF_DEPEND 0x0008 /* Operation required by dependency */ 59#define JF_WILD 0x0010 /* Not specified on the command line */ 60#define JF_FAILED 0x0020 /* Operation failed */ 61#define JF_PARAMS 0x0040 /* Parameters checked and imported */ 62#define JF_RDTUN 0x0080 /* Create-only parameter check has been done */ 63#define JF_PERSIST 0x0100 /* Jail is temporarily persistent */ 64#define JF_TIMEOUT 0x0200 /* A command (or process kill) timed out */ 65#define JF_SLEEPQ 0x0400 /* Waiting on a command and/or timeout */ 66 67#define JF_OP_MASK (JF_START | JF_SET | JF_STOP) 68#define JF_RESTART (JF_START | JF_STOP) 69#define JF_START_SET (JF_START | JF_SET) 70#define JF_SET_RESTART (JF_SET | JF_STOP) 71#define JF_START_SET_RESTART (JF_START | JF_SET | JF_STOP) 72#define JF_DO_STOP(js) (((js) & (JF_SET | JF_STOP)) == JF_STOP) 73 74enum intparam { 75 IP__NULL = 0, /* Null command */ 76 IP_ALLOW_DYING, /* Allow making changes to a dying jail */ 77 IP_COMMAND, /* Command run inside jail at creation */ 78 IP_DEPEND, /* Jail starts after (stops before) another */ 79 IP_EXEC_CLEAN, /* Run commands in a clean environment */ 80 IP_EXEC_CONSOLELOG, /* Redirect optput for commands run in jail */ 81 IP_EXEC_FIB, /* Run jailed commands with this FIB */ 82 IP_EXEC_JAIL_USER, /* Run jailed commands as this user */ 83 IP_EXEC_POSTSTART, /* Commands run outside jail after creating */ 84 IP_EXEC_POSTSTOP, /* Commands run outside jail after removing */ 85 IP_EXEC_PRESTART, /* Commands run outside jail before creating */ 86 IP_EXEC_PRESTOP, /* Commands run outside jail before removing */ 87 IP_EXEC_START, /* Commands run inside jail on creation */ 88 IP_EXEC_STOP, /* Commands run inside jail on removal */ 89 IP_EXEC_SYSTEM_JAIL_USER,/* Get jail_user from system passwd file */ 90 IP_EXEC_SYSTEM_USER, /* Run non-jailed commands as this user */ 91 IP_EXEC_TIMEOUT, /* Time to wait for a command to complete */ 92#if defined(INET) || defined(INET6) 93 IP_INTERFACE, /* Add IP addresses to this interface */ 94 IP_IP_HOSTNAME, /* Get jail IP address(es) from hostname */ 95#endif 96 IP_MOUNT, /* Mount points in fstab(5) form */ 97 IP_MOUNT_DEVFS, /* Mount /dev under prison root */ 98 IP_MOUNT_FDESCFS, /* Mount /dev/fd under prison root */
|
| 99 IP_MOUNT_PROCFS, /* Mount /proc under prison root */
|
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#ifdef INET 103 IP__IP4_IFADDR, /* Copy of ip4.addr with interface/netmask */ 104#endif 105#ifdef INET6 106 IP__IP6_IFADDR, /* Copy of ip6.addr with interface/prefixlen */ 107#endif 108 IP__MOUNT_FROM_FSTAB, /* Line from mount.fstab file */ 109 IP__OP, /* Placeholder for requested operation */ 110 KP_ALLOW_CHFLAGS, 111 KP_ALLOW_MOUNT, 112 KP_ALLOW_RAW_SOCKETS, 113 KP_ALLOW_SET_HOSTNAME, 114 KP_ALLOW_SOCKET_AF, 115 KP_ALLOW_SYSVIPC, 116 KP_DEVFS_RULESET, 117 KP_ENFORCE_STATFS, 118 KP_HOST_HOSTNAME, 119#ifdef INET 120 KP_IP4_ADDR, 121#endif 122#ifdef INET6 123 KP_IP6_ADDR, 124#endif 125 KP_JID, 126 KP_NAME, 127 KP_PATH, 128 KP_PERSIST, 129 KP_SECURELEVEL, 130 KP_VNET, 131 IP_NPARAM 132}; 133 134STAILQ_HEAD(cfvars, cfvar); 135 136struct cfvar { 137 STAILQ_ENTRY(cfvar) tq; 138 char *name; 139 size_t pos; 140}; 141 142TAILQ_HEAD(cfstrings, cfstring); 143 144struct cfstring { 145 TAILQ_ENTRY(cfstring) tq; 146 char *s; 147 size_t len; 148 struct cfvars vars; 149}; 150 151TAILQ_HEAD(cfparams, cfparam); 152 153struct cfparam { 154 TAILQ_ENTRY(cfparam) tq; 155 char *name; 156 struct cfstrings val; 157 unsigned flags; 158 int gen; 159}; 160 161TAILQ_HEAD(cfjails, cfjail); 162STAILQ_HEAD(cfdepends, cfdepend); 163 164struct cfjail { 165 TAILQ_ENTRY(cfjail) tq; 166 char *name; 167 char *comline; 168 struct cfparams params; 169 struct cfdepends dep[2]; 170 struct cfjails *queue; 171 struct cfparam *intparams[IP_NPARAM]; 172 struct cfstring *comstring; 173 struct jailparam *jp; 174 struct timespec timeout; 175 const enum intparam *comparam; 176 unsigned flags; 177 int jid; 178 int seq; 179 int pstatus; 180 int ndeps; 181 int njp; 182 int nprocs; 183}; 184 185struct cfdepend { 186 STAILQ_ENTRY(cfdepend) tq[2]; 187 struct cfjail *j[2]; 188 unsigned flags; 189}; 190 191extern void *emalloc(size_t); 192extern void *erealloc(void *, size_t); 193extern char *estrdup(const char *); 194extern int create_jail(struct cfjail *j); 195extern void failed(struct cfjail *j); 196extern void jail_note(const struct cfjail *j, const char *fmt, ...); 197extern void jail_warnx(const struct cfjail *j, const char *fmt, ...); 198 199extern int next_command(struct cfjail *j); 200extern int finish_command(struct cfjail *j); 201extern struct cfjail *next_proc(int nonblock); 202 203extern void load_config(void); 204extern struct cfjail *add_jail(void); 205extern void add_param(struct cfjail *j, const struct cfparam *p, 206 enum intparam ipnum, const char *value); 207extern int bool_param(const struct cfparam *p); 208extern int int_param(const struct cfparam *p, int *ip); 209extern const char *string_param(const struct cfparam *p); 210extern int check_intparams(struct cfjail *j); 211extern int import_params(struct cfjail *j); 212extern int equalopts(const char *opt1, const char *opt2); 213extern int wild_jail_name(const char *wname); 214extern int wild_jail_match(const char *jname, const char *wname); 215 216extern void dep_setup(int docf); 217extern int dep_check(struct cfjail *j); 218extern void dep_done(struct cfjail *j, unsigned flags); 219extern void dep_reset(struct cfjail *j); 220extern struct cfjail *next_jail(void); 221extern int start_state(const char *target, int docf, unsigned state, 222 int running); 223extern void requeue(struct cfjail *j, struct cfjails *queue); 224 225extern void yyerror(const char *); 226extern int yylex(void); 227 228extern struct cfjails cfjails; 229extern struct cfjails ready; 230extern struct cfjails depend; 231extern const char *cfname; 232extern int iflag; 233extern int note_remove; 234extern int paralimit; 235extern int verbose;
| 100 IP_MOUNT_FSTAB, /* A standard fstab(5) file */ 101 IP_STOP_TIMEOUT, /* Time to wait after sending SIGTERM */ 102 IP_VNET_INTERFACE, /* Assign interface(s) to vnet jail */ 103#ifdef INET 104 IP__IP4_IFADDR, /* Copy of ip4.addr with interface/netmask */ 105#endif 106#ifdef INET6 107 IP__IP6_IFADDR, /* Copy of ip6.addr with interface/prefixlen */ 108#endif 109 IP__MOUNT_FROM_FSTAB, /* Line from mount.fstab file */ 110 IP__OP, /* Placeholder for requested operation */ 111 KP_ALLOW_CHFLAGS, 112 KP_ALLOW_MOUNT, 113 KP_ALLOW_RAW_SOCKETS, 114 KP_ALLOW_SET_HOSTNAME, 115 KP_ALLOW_SOCKET_AF, 116 KP_ALLOW_SYSVIPC, 117 KP_DEVFS_RULESET, 118 KP_ENFORCE_STATFS, 119 KP_HOST_HOSTNAME, 120#ifdef INET 121 KP_IP4_ADDR, 122#endif 123#ifdef INET6 124 KP_IP6_ADDR, 125#endif 126 KP_JID, 127 KP_NAME, 128 KP_PATH, 129 KP_PERSIST, 130 KP_SECURELEVEL, 131 KP_VNET, 132 IP_NPARAM 133}; 134 135STAILQ_HEAD(cfvars, cfvar); 136 137struct cfvar { 138 STAILQ_ENTRY(cfvar) tq; 139 char *name; 140 size_t pos; 141}; 142 143TAILQ_HEAD(cfstrings, cfstring); 144 145struct cfstring { 146 TAILQ_ENTRY(cfstring) tq; 147 char *s; 148 size_t len; 149 struct cfvars vars; 150}; 151 152TAILQ_HEAD(cfparams, cfparam); 153 154struct cfparam { 155 TAILQ_ENTRY(cfparam) tq; 156 char *name; 157 struct cfstrings val; 158 unsigned flags; 159 int gen; 160}; 161 162TAILQ_HEAD(cfjails, cfjail); 163STAILQ_HEAD(cfdepends, cfdepend); 164 165struct cfjail { 166 TAILQ_ENTRY(cfjail) tq; 167 char *name; 168 char *comline; 169 struct cfparams params; 170 struct cfdepends dep[2]; 171 struct cfjails *queue; 172 struct cfparam *intparams[IP_NPARAM]; 173 struct cfstring *comstring; 174 struct jailparam *jp; 175 struct timespec timeout; 176 const enum intparam *comparam; 177 unsigned flags; 178 int jid; 179 int seq; 180 int pstatus; 181 int ndeps; 182 int njp; 183 int nprocs; 184}; 185 186struct cfdepend { 187 STAILQ_ENTRY(cfdepend) tq[2]; 188 struct cfjail *j[2]; 189 unsigned flags; 190}; 191 192extern void *emalloc(size_t); 193extern void *erealloc(void *, size_t); 194extern char *estrdup(const char *); 195extern int create_jail(struct cfjail *j); 196extern void failed(struct cfjail *j); 197extern void jail_note(const struct cfjail *j, const char *fmt, ...); 198extern void jail_warnx(const struct cfjail *j, const char *fmt, ...); 199 200extern int next_command(struct cfjail *j); 201extern int finish_command(struct cfjail *j); 202extern struct cfjail *next_proc(int nonblock); 203 204extern void load_config(void); 205extern struct cfjail *add_jail(void); 206extern void add_param(struct cfjail *j, const struct cfparam *p, 207 enum intparam ipnum, const char *value); 208extern int bool_param(const struct cfparam *p); 209extern int int_param(const struct cfparam *p, int *ip); 210extern const char *string_param(const struct cfparam *p); 211extern int check_intparams(struct cfjail *j); 212extern int import_params(struct cfjail *j); 213extern int equalopts(const char *opt1, const char *opt2); 214extern int wild_jail_name(const char *wname); 215extern int wild_jail_match(const char *jname, const char *wname); 216 217extern void dep_setup(int docf); 218extern int dep_check(struct cfjail *j); 219extern void dep_done(struct cfjail *j, unsigned flags); 220extern void dep_reset(struct cfjail *j); 221extern struct cfjail *next_jail(void); 222extern int start_state(const char *target, int docf, unsigned state, 223 int running); 224extern void requeue(struct cfjail *j, struct cfjails *queue); 225 226extern void yyerror(const char *); 227extern int yylex(void); 228 229extern struct cfjails cfjails; 230extern struct cfjails ready; 231extern struct cfjails depend; 232extern const char *cfname; 233extern int iflag; 234extern int note_remove; 235extern int paralimit; 236extern int verbose;
|