added new management functions + doc
[util-vserver.git] / util-vserver / lib / vserver.h
index d45dc9d..88c7085 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <stdint.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <sys/types.h>
 
 /** the value which is returned in error-case (no ctx found) */
@@ -94,6 +95,9 @@
 #define VC_CAP_LEASE                   28
 #define VC_CAP_QUOTACTL                29
 
+#define VC_IMMUTABLE_FILE_FL           0x00000010l
+#define VC_IMMUTABLE_LINK_FL           0x00008000l
+#define VC_IMMUTABLE_ALL               (VC_IMMUTABLE_LINK_FL|VC_IMMUTABLE_FILE_FL)
 
 #ifdef __cplusplus
 extern "C" {
@@ -112,7 +116,8 @@ extern "C" {
      *  Special values for ctx are
      *  - VC_SAMECTX  which means the current context (just for changing caps and flags)
      *  - VC_RANDCTX  which means the next free context; this value can be used by
-     *                ordinary users also */
+     *                ordinary users also
+     *  See http://vserver.13thfloor.at/Stuff/Logic.txt for details */
   int  vc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags);
 
     /** Sets the ipv4root information.
@@ -154,9 +159,27 @@ extern "C" {
   pid_t        vc_X_getinitpid(pid_t pid);
 
 
+  xid_t                vc_X_get_filecontext(int fd);
+  int          vc_X_set_filecontext(int fd, xid_t ctx);
+
+  int          vc_X_get_ext2flags(int fd, long *flags);
+  int          vc_X_set_ext2flags(int fd, long set_flags, long del_flags);
+
+
   int          vc_text2cap(char const *);
   char const * vc_cap2text(int);
 
+  inline static int    vc_get_securecaps() {
+    return ( (1<<VC_CAP_LINUX_IMMUTABLE) | (1<<VC_CAP_NET_BROADCAST) |
+            (1<<VC_CAP_NET_ADMIN) | (1<<VC_CAP_NET_RAW) |
+            (1<<VC_CAP_IPC_LOCK) | (1<<VC_CAP_IPC_OWNER) |
+            (1<<VC_CAP_SYS_MODULE) | (1<<VC_CAP_SYS_RAWIO) |
+            (1<<VC_CAP_SYS_PACCT) | (1<<VC_CAP_SYS_ADMIN) |
+            (1<<VC_CAP_SYS_BOOT) | (1<<VC_CAP_SYS_NICE) |
+            (1<<VC_CAP_SYS_RESOURCE) | (1<<VC_CAP_SYS_TIME) |
+            (1<<VC_CAP_MKNOD) | (1<<VC_CAP_QUOTACTL) );
+  }
+
   
   /* The management part */
 
@@ -173,11 +196,30 @@ extern "C" {
       be freed by the caller. */
   char *       vc_getVserverName(char const *id, vcCfgStyle style);
 
+  /** Returns the path of the vserver configuration directory. When the given
+   *  vserver does not exist, or when it does not have such a directory, NULL
+   *  will be returned. Else, the result will be allocated and must be freed
+   *  by the caller. */
+  char *       vc_getVserverCfgDir(char const *id, vcCfgStyle style);
+
+  /** Returns the path of the configuration directory for the given
+   *  application. The result will be allocated and must be freed by the
+   *  caller. */
+  char *       vc_getVserverAppDir(char const *id, vcCfgStyle style, char const *app);
+
+  /** Returns the path to the vserver root-directory. The result will be
+   *  allocated and must be freed by the caller. */
   char *       vc_getVserverVdir(char const *id, vcCfgStyle style);
 
-  /** Returns the ctx of the given vserver, or VC_NOCTX if vserver is not
-   *  running */
-  xid_t                vc_getVserverCtx(char const *id, vcCfgStyle style);
+  /** Returns the ctx of the given vserver. When vserver is not running and
+   *  'honor_static' is false, VC_NOCTX will be returned. Else, when
+   *  'honor_static' is true and a static assignment exists, those value will
+   *  be returned. Else, the result will be VC_NOCTX.
+   *
+   *  When 'is_running' is not null, the status of the vserver will be
+   *  assigned to this variable. */
+  xid_t                vc_getVserverCtx(char const *id, vcCfgStyle style,
+                                bool honor_static, bool /*@null@*/ *is_running);
 
   /** Resolves the cfg-path of the vserver owning the given ctx. 'revdir' will
       be used as the directory holding the mapping-links; when NULL, the