vc_getVserverByCtx(), vc_getVserverCtx(): added
[util-vserver.git] / util-vserver / lib / vserver.h
1 /* $Id$
2
3 *  Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 *   
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)
8 *  any later version.
9 *   
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.
14 *   
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.
18 */
19
20 #ifndef H_VSERVER_SYSCALL_H
21 #define H_VSERVER_SYSCALL_H
22
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <sys/types.h>
26
27 /** the value which is returned in error-case (no ctx found) */
28 #define VC_NOCTX                ((ctx_t)(-1))
29 /** the value which means a random (the next free) ctx */
30 #define VC_RANDCTX              ((ctx_t)(-1))
31 /** the value which means the current ctx */
32 #define VC_SAMECTX              ((ctx_t)(-2))
33
34 #define VC_LIM_INFINITY         (~0ULL)
35 #define VC_LIM_KEEP             (~1ULL)
36
37   
38 #ifndef S_CTX_INFO_LOCK
39 #  define S_CTX_INFO_LOCK       1
40 #endif
41
42 #ifndef S_CTX_INFO_SCHED
43 #  define S_CTX_INFO_SCHED      2
44 #endif
45
46 #ifndef S_CTX_INFO_NPROC
47 #  define S_CTX_INFO_NPROC      4
48 #endif
49
50 #ifndef S_CTX_INFO_PRIVATE
51 #  define S_CTX_INFO_PRIVATE    8
52 #endif
53
54 #ifndef S_CTX_INFO_INIT
55 #  define S_CTX_INFO_INIT       16
56 #endif
57
58 #ifndef S_CTX_INFO_HIDEINFO
59 #  define S_CTX_INFO_HIDEINFO   32
60 #endif
61
62 #ifndef S_CTX_INFO_ULIMIT
63 #  define S_CTX_INFO_ULIMIT     64
64 #endif
65
66 #define VC_CAP_CHOWN                     0
67 #define VC_CAP_DAC_OVERRIDE              1
68 #define VC_CAP_DAC_READ_SEARCH           2
69 #define VC_CAP_FOWNER                    3
70 #define VC_CAP_FSETID                    4
71 #define VC_CAP_KILL                      5
72 #define VC_CAP_SETGID                    6
73 #define VC_CAP_SETUID                    7
74 #define VC_CAP_SETPCAP                   8
75 #define VC_CAP_LINUX_IMMUTABLE           9
76 #define VC_CAP_NET_BIND_SERVICE         10
77 #define VC_CAP_NET_BROADCAST            11
78 #define VC_CAP_NET_ADMIN                12
79 #define VC_CAP_NET_RAW                  13
80 #define VC_CAP_IPC_LOCK                 14
81 #define VC_CAP_IPC_OWNER                15
82 #define VC_CAP_SYS_MODULE               16
83 #define VC_CAP_SYS_RAWIO                17
84 #define VC_CAP_SYS_CHROOT               18
85 #define VC_CAP_SYS_PTRACE               19
86 #define VC_CAP_SYS_PACCT                20
87 #define VC_CAP_SYS_ADMIN                21
88 #define VC_CAP_SYS_BOOT                 22
89 #define VC_CAP_SYS_NICE                 23
90 #define VC_CAP_SYS_RESOURCE             24
91 #define VC_CAP_SYS_TIME                 25
92 #define VC_CAP_SYS_TTY_CONFIG           26
93 #define VC_CAP_MKNOD                    27
94 #define VC_CAP_LEASE                    28
95 #define VC_CAP_QUOTACTL                 29
96
97
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101
102   struct vc_ip_mask_pair {
103     uint32_t    ip;
104     uint32_t    mask;
105   };
106
107     /** Returns version of the given API-category */
108   int   vc_get_version(int category);
109   
110     /** Puts current process into context <ctx>, removes the given caps and
111      *  sets flags.
112      *  Special values for ctx are
113      *  - -2 which means the current context (just for changing caps and flags)
114      *  - -1 which means the next free context; this value can be used by
115      *    ordinary users also */
116   int   vc_new_s_context(ctx_t ctx, unsigned int remove_cap, unsigned int flags);
117
118     /** Sets the ipv4root information.
119      *  \precondition: nb<16 */
120   int   vc_set_ipv4root(uint32_t  bcast, size_t nb, struct vc_ip_mask_pair const *ips);
121   
122   int   vc_chrootsafe(char const *dir);
123
124   /* rlimit related functions */
125   typedef uint64_t      vc_limit_t;
126   
127   
128   struct vc_rlimit {
129       vc_limit_t min;
130       vc_limit_t soft;
131       vc_limit_t hard;      
132   };
133
134   struct  vc_rlimit_mask {
135       uint32_t min;
136       uint32_t soft;
137       uint32_t hard;
138   };
139
140   int   vc_get_rlimit(ctx_t ctx, int resource, struct vc_rlimit *lim);
141   int   vc_set_rlimit(ctx_t ctx, int resource, struct vc_rlimit const *lim);
142   int   vc_get_rlimit_mask(ctx_t ctx, struct vc_rlimit_mask *lim);
143
144
145     /** Returns the context of the given process. pid==0 means the current process. */
146   ctx_t vc_X_getctx(pid_t pid);
147
148     /** Returns the pid of the 'init' process */
149   pid_t vc_X_getinitpid(pid_t pid);
150
151
152   int           vc_text2cap(char const *);
153   char const *  vc_cap2text(int);
154
155   
156   /* The management part */
157
158 #define VC_LIMIT_VSERVER_NAME_LEN       1024
159   
160   typedef enum { vcCFG_NONE, vcCFG_AUTO,
161                  vcCFG_LEGACY,
162                  vcCFG_RECENT_SHORT,
163                  vcCFG_RECENT_FULL }            vcCfgStyle;
164
165   vcCfgStyle    vc_getVserverCfgStyle(char const *id);
166   
167   /** Resolves the name of the vserver. The result will be allocated and must
168       be freed by the caller. */
169   char *        vc_getVserverName(char const *id, vcCfgStyle style);
170
171   char *        vc_getVserverVdir(char const *id, vcCfgStyle style);
172
173   /** Returns the ctx of the given vserver, or VC_NOCTX if vserver is not
174    *  running */
175   ctx_t         vc_getVserverCtx(char const *id, vcCfgStyle style);
176
177   /** Resolves the cfg-path of the vserver owning the given ctx. 'revdir' will
178       be used as the directory holding the mapping-links; when NULL, the
179       default value will be assumed.  The result will be allocated and must be
180       freed by the caller. */
181   char *        vc_getVserverByCtx(ctx_t ctx, /*@null@*/vcCfgStyle *style,
182                                    /*@null@*/char const *revdir);
183   
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif