Merge from vendor branch FILE:
[dragonfly.git] / sys / sys / jail.h
1 /*
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD: src/sys/sys/jail.h,v 1.8.2.2 2000/11/01 17:58:06 rwatson Exp $
10  * $DragonFly: src/sys/sys/jail.h,v 1.8 2006/10/27 04:56:33 dillon Exp $
11  *
12  */
13
14 #ifndef _SYS_JAIL_H_
15 #define _SYS_JAIL_H_
16
17 #ifndef _SYS_TYPES_H_
18 #include <sys/types.h>
19 #endif
20 #ifndef _SYS_PARAM_H_
21 #include <sys/param.h>
22 #endif
23 #ifndef _SYS_UCRED_H_
24 #include <sys/ucred.h>
25 #endif
26
27 struct jail {
28         uint32_t        version;
29         char            *path;
30         char            *hostname;
31         uint32_t        ip_number;
32 };
33
34 #ifndef _KERNEL
35
36 int jail(struct jail *);
37 int jail_attach(int);
38
39 #else /* _KERNEL */
40
41 #ifndef _SYS_NAMECACHE_H_
42 #include <sys/namecache.h>
43 #endif
44 #ifndef _SYS_VARSYM_H_
45 #include <sys/varsym.h>
46 #endif
47
48 #ifdef MALLOC_DECLARE
49 MALLOC_DECLARE(M_PRISON);
50 #endif
51
52 #define JAIL_MAX        999999
53
54 /*
55  * This structure describes a prison.  It is pointed to by all struct
56  * proc's of the inmates.  pr_ref keeps track of them and is used to
57  * delete the struture when the last inmate is dead.
58  */
59
60 struct prison {
61         LIST_ENTRY(prison) pr_list;                     /* all prisons */
62         int             pr_id;                          /* prison id */
63         int             pr_ref;                         /* reference count */
64         struct nchandle pr_root;                        /* namecache entry of root */
65         char            pr_host[MAXHOSTNAMELEN];        /* host name */
66         uint32_t        pr_ip;                          /* IP address */
67         void            *pr_linux;                      /* Linux ABI emulation */
68         int              pr_securelevel;                /* jail securelevel */
69         struct varsymset pr_varsymset;                  /* jail varsyms */
70 };
71
72 /*
73  * Sysctl-set variables that determine global jail policy
74  */
75 extern int      jail_set_hostname_allowed;
76 extern int      jail_socket_unixiproute_only;
77 extern int      jail_sysvipc_allowed;
78 extern int      jail_chflags_allowed;
79
80 void    prison_hold(struct prison *);
81 void    prison_free(struct prison *);
82
83 /*
84  * Return 1 if the passed credential is in a jail, otherwise 0.
85  */
86 static __inline int
87 jailed(struct ucred *cred)
88 {
89         return(cred->cr_prison != NULL);
90 }
91
92 #endif /* !_KERNEL */
93 #endif /* !_SYS_JAIL_H_ */