3 * Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef H_VSERVER_SYSCALL_H
21 #define H_VSERVER_SYSCALL_H
26 #include <sys/types.h>
28 /** the value which is returned in error-case (no ctx found) */
29 #define VC_NOCTX ((xid_t)(-1))
30 /** the value which means a random (the next free) ctx */
31 #define VC_DYNAMIC_XID ((xid_t)(-1))
32 /** the value which means the current ctx */
33 #define VC_SAMECTX ((xid_t)(-2))
35 #define VC_LIM_INFINITY (~0ULL)
36 #define VC_LIM_KEEP (~1ULL)
39 #ifndef S_CTX_INFO_LOCK
40 # define S_CTX_INFO_LOCK 1
43 #ifndef S_CTX_INFO_SCHED
44 # define S_CTX_INFO_SCHED 2
47 #ifndef S_CTX_INFO_NPROC
48 # define S_CTX_INFO_NPROC 4
51 #ifndef S_CTX_INFO_PRIVATE
52 # define S_CTX_INFO_PRIVATE 8
55 #ifndef S_CTX_INFO_INIT
56 # define S_CTX_INFO_INIT 16
59 #ifndef S_CTX_INFO_HIDEINFO
60 # define S_CTX_INFO_HIDEINFO 32
63 #ifndef S_CTX_INFO_ULIMIT
64 # define S_CTX_INFO_ULIMIT 64
67 #ifndef S_CTX_INFO_NAMESPACE
68 # define S_CTX_INFO_NAMESPACE 128
71 #define VC_CAP_CHOWN 0
72 #define VC_CAP_DAC_OVERRIDE 1
73 #define VC_CAP_DAC_READ_SEARCH 2
74 #define VC_CAP_FOWNER 3
75 #define VC_CAP_FSETID 4
77 #define VC_CAP_SETGID 6
78 #define VC_CAP_SETUID 7
79 #define VC_CAP_SETPCAP 8
80 #define VC_CAP_LINUX_IMMUTABLE 9
81 #define VC_CAP_NET_BIND_SERVICE 10
82 #define VC_CAP_NET_BROADCAST 11
83 #define VC_CAP_NET_ADMIN 12
84 #define VC_CAP_NET_RAW 13
85 #define VC_CAP_IPC_LOCK 14
86 #define VC_CAP_IPC_OWNER 15
87 #define VC_CAP_SYS_MODULE 16
88 #define VC_CAP_SYS_RAWIO 17
89 #define VC_CAP_SYS_CHROOT 18
90 #define VC_CAP_SYS_PTRACE 19
91 #define VC_CAP_SYS_PACCT 20
92 #define VC_CAP_SYS_ADMIN 21
93 #define VC_CAP_SYS_BOOT 22
94 #define VC_CAP_SYS_NICE 23
95 #define VC_CAP_SYS_RESOURCE 24
96 #define VC_CAP_SYS_TIME 25
97 #define VC_CAP_SYS_TTY_CONFIG 26
98 #define VC_CAP_MKNOD 27
99 #define VC_CAP_LEASE 28
100 #define VC_CAP_QUOTACTL 29
102 #define VC_IMMUTABLE_FILE_FL 0x00000010l
103 #define VC_IMMUTABLE_LINK_FL 0x00008000l
104 #define VC_IMMUTABLE_ALL (VC_IMMUTABLE_LINK_FL|VC_IMMUTABLE_FILE_FL)
106 #define VC_IATTR_XID 0x01000000
108 #define VC_IATTR_ADMIN 0x00000001
109 #define VC_IATTR_WATCH 0x00000002
110 #define VC_IATTR_HIDE 0x00000004
112 #define VC_IATTR_BARRIER 0x00010000
113 #define VC_IATTR_IUNLINK 0x00020000
120 struct vc_ip_mask_pair {
125 /** Returns the version of the current kernel API. */
126 int vc_get_version();
128 /** Puts current process into context <ctx>, removes the given caps and
130 * Special values for ctx are
131 * - VC_SAMECTX which means the current context (just for changing caps and flags)
132 * - VC_RANDCTX which means the next free context; this value can be used by
133 * ordinary users also
134 * See http://vserver.13thfloor.at/Stuff/Logic.txt for details */
135 xid_t vc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags);
137 /** Sets the ipv4root information.
138 * \precondition: nb<16 */
139 int vc_set_ipv4root(uint32_t bcast, size_t nb, struct vc_ip_mask_pair const *ips);
141 xid_t vc_create_context(xid_t xid);
142 int vc_migrate_context(xid_t xid);
144 /* rlimit related functions */
145 typedef uint64_t vc_limit_t;
153 struct vc_rlimit_mask {
159 int vc_get_rlimit(xid_t ctx, int resource, struct vc_rlimit *lim);
160 int vc_set_rlimit(xid_t ctx, int resource, struct vc_rlimit const *lim);
161 int vc_get_rlimit_mask(xid_t ctx, struct vc_rlimit_mask *lim);
164 /** sends a signal to a context/pid
165 Special values for pid are:
166 * -1 which means every process in ctx except the init-process
167 * 0 which means every process in ctx inclusive the init-process */
168 int vc_ctx_kill(xid_t ctx, pid_t pid, int sig);
172 int vc_set_iattr(char const *filename, xid_t xid, uint32_t flags, uint32_t mask);
173 int vc_get_iattr(char const *filename, xid_t * /*@null@*/ xid,
174 uint32_t * /*@null@*/ flags, uint32_t * /*@null@*/ mask);
181 /** Returns the context of the given process. pid==0 means the current process. */
182 xid_t vc_get_task_xid(pid_t pid);
183 int vc_get_vx_info(xid_t xid, struct vc_vx_info *info);
186 typedef enum { vcVHI_CONTEXT, vcVHI_SYSNAME, vcVHI_NODENAME,
187 vcVHI_RELEASE, vcVHI_VERSION, vcVHI_MACHINE,
188 vcVHI_DOMAINNAME } vc_uts_type;
190 int vc_set_vhi_name(xid_t xid, vc_uts_type type, char const *val, size_t len);
191 int vc_get_vhi_name(xid_t xid, vc_uts_type type, char *val, size_t len);
194 int vc_enter_namespace(xid_t xid);
195 int vc_set_namespace();
196 int vc_cleanup_namespace();
198 struct vc_ctx_flags {
203 int vc_get_flags(xid_t xid, struct vc_ctx_flags *);
204 int vc_set_flags(xid_t xid, struct vc_ctx_flags const *);
206 uint32_t vc_textlist2flag(char const *, size_t len,
207 char const **err_ptr, size_t *err_len);
208 uint32_t vc_text2flag(char const *, size_t len);
209 char const * vc_hiflag2text(unsigned int);
211 int vc_text2cap(char const *);
212 char const * vc_cap2text(unsigned int);
214 inline static int vc_get_securecaps() {
215 return ( (1<<VC_CAP_LINUX_IMMUTABLE) | (1<<VC_CAP_NET_BROADCAST) |
216 (1<<VC_CAP_NET_ADMIN) | (1<<VC_CAP_NET_RAW) |
217 (1<<VC_CAP_IPC_LOCK) | (1<<VC_CAP_IPC_OWNER) |
218 (1<<VC_CAP_SYS_MODULE) | (1<<VC_CAP_SYS_RAWIO) |
219 (1<<VC_CAP_SYS_PACCT) | (1<<VC_CAP_SYS_ADMIN) |
220 (1<<VC_CAP_SYS_BOOT) | (1<<VC_CAP_SYS_NICE) |
221 (1<<VC_CAP_SYS_RESOURCE) | (1<<VC_CAP_SYS_TIME) |
222 (1<<VC_CAP_MKNOD) | (1<<VC_CAP_QUOTACTL) );
225 inline static int vc_setfilecontext(char const *filename, xid_t xid) {
226 return vc_set_iattr(filename, xid, 0, VC_IATTR_XID);
229 inline static xid_t vc_getfilecontext(char const *filename) {
231 if (vc_get_iattr(filename, &res, 0,0)==-1) return VC_NOCTX;
236 struct vc_set_sched {
243 int vc_set_sched(xid_t xid, struct vc_set_sched const *);
246 typedef enum { vcFEATURE_VKILL, vcFEATURE_IATTR, vcFEATURE_RLIMIT,
247 vcFEATURE_COMPAT, vcFEATURE_MIGRATE, vcFEATURE_NAMESPACE,
248 vcFEATURE_SCHED, vcFEATURE_VINFO, vcFEATURE_VHI }
251 bool vc_isSupported(vcFeatureSet);
253 /* The management part */
255 #define VC_LIMIT_VSERVER_NAME_LEN 1024
257 typedef enum { vcCFG_NONE, vcCFG_AUTO,
260 vcCFG_RECENT_FULL } vcCfgStyle;
262 vcCfgStyle vc_getVserverCfgStyle(char const *id);
264 /** Resolves the name of the vserver. The result will be allocated and must
265 be freed by the caller. */
266 char * vc_getVserverName(char const *id, vcCfgStyle style);
268 /** Returns the path of the vserver configuration directory. When the given
269 * vserver does not exist, or when it does not have such a directory, NULL
270 * will be returned. Else, the result will be allocated and must be freed
272 char * vc_getVserverCfgDir(char const *id, vcCfgStyle style);
274 /** Returns the path of the configuration directory for the given
275 * application. The result will be allocated and must be freed by the
277 char * vc_getVserverAppDir(char const *id, vcCfgStyle style, char const *app);
279 /** Returns the path to the vserver root-directory. The result will be
280 * allocated and must be freed by the caller. */
281 char * vc_getVserverVdir(char const *id, vcCfgStyle style, bool physical);
283 /** Returns the ctx of the given vserver. When vserver is not running and
284 * 'honor_static' is false, VC_NOCTX will be returned. Else, when
285 * 'honor_static' is true and a static assignment exists, those value will
286 * be returned. Else, the result will be VC_NOCTX.
288 * When 'is_running' is not null, the status of the vserver will be
289 * assigned to this variable. */
290 xid_t vc_getVserverCtx(char const *id, vcCfgStyle style,
291 bool honor_static, bool /*@null@*/ *is_running);
293 /** Resolves the cfg-path of the vserver owning the given ctx. 'revdir' will
294 be used as the directory holding the mapping-links; when NULL, the
295 default value will be assumed. The result will be allocated and must be
296 freed by the caller. */
297 char * vc_getVserverByCtx(xid_t ctx, /*@null@*/vcCfgStyle *style,
298 /*@null@*/char const *revdir);
300 #define vcSKEL_INTERFACES 1u
301 #define vcSKEL_PKGMGMT 2u
302 #define vcSKEL_FILESYSTEM 4u
304 /** Create a basic configuration skeleton for a vserver plus toplevel
305 * directories for pkgmanagemt and filesystem (when requested). */
306 int vc_createSkeleton(char const *id, vcCfgStyle style, int flags);