FUSE patch from Jeremy Stribling.
[util-vserver-pl.git] / python / vserverimpl.c
index cb30228..b9a06aa 100644 (file)
@@ -60,6 +60,7 @@ static inline PyObject *inc_and_ret_none(void)
 #define NONE  inc_and_ret_none()
 
 #define PL_INSECURE_BCAPS      (vc_get_insecurebcaps() | (1 << VC_CAP_NET_BIND_SERVICE))
+#define PL_INSECURE_CCAPS      vc_get_insecureccaps()
 
 /*
  * context create
@@ -369,6 +370,81 @@ vserver_bcaps2text(PyObject *self, PyObject *args)
   return list;
 }
 
+static PyObject *
+vserver_set_ccaps(PyObject *self, PyObject *args)
+{
+  xid_t ctx;
+  struct vc_ctx_caps caps;
+
+  if (!PyArg_ParseTuple(args, "IK", &ctx, &caps.ccaps))
+    return NULL;
+
+  caps.cmask = PL_INSECURE_CCAPS;
+  caps.bmask = caps.bcaps = 0;
+  if (vc_set_ccaps(ctx, &caps) == -1 && errno != ESRCH)
+    return PyErr_SetFromErrno(PyExc_OSError);
+
+  return NONE;
+}
+
+static PyObject *
+vserver_text2ccaps(PyObject *self, PyObject *args)
+{
+  struct vc_ctx_caps caps = { .ccaps = 0 };
+  const char *list;
+  int len;
+  struct vc_err_listparser err;
+
+  if (!PyArg_ParseTuple(args, "s#", &list, &len))
+    return NULL;
+
+  vc_list2ccap(list, len, &err, &caps);
+
+  return Py_BuildValue("K", caps.ccaps);
+}
+
+static PyObject *
+vserver_get_ccaps(PyObject *self, PyObject *args)
+{
+  xid_t ctx;
+  struct vc_ctx_caps caps;
+
+  if (!PyArg_ParseTuple(args, "I", &ctx))
+    return NULL;
+
+  if (vc_get_ccaps(ctx, &caps) == -1) {
+    if (errno != ESRCH)
+      return PyErr_SetFromErrno(PyExc_OSError);
+    else
+      caps.ccaps = 0;
+  }
+
+  return Py_BuildValue("K", caps.ccaps & PL_INSECURE_CCAPS);
+}
+
+static PyObject *
+vserver_ccaps2text(PyObject *self, PyObject *args)
+{
+  struct vc_ctx_caps caps = { .ccaps = 0 };
+  PyObject *list;
+  const char *cap;
+
+  if (!PyArg_ParseTuple(args, "K", &caps.ccaps))
+    return NULL;
+
+  list = PyString_FromString("");
+
+  while ((cap = vc_loccap2text(&caps.ccaps)) != NULL) {
+    if (list == NULL)
+      break;
+    PyString_ConcatAndDel(&list, PyString_FromFormat(
+                         (PyString_Size(list) > 0 ? ",%s" : "%s" ),
+                         cap));
+  }
+
+  return list;
+}
+
 static inline int
 convert_address(const char *str, struct vc_net_addr *addr)
 {
@@ -728,6 +804,14 @@ static PyMethodDef  methods[] = {
     "Translate a string of capabilities to a bitmap" },
   { "bcaps2text", vserver_bcaps2text, METH_VARARGS,
     "Translate a capability-bitmap into a string" },
+  { "setccaps", vserver_set_ccaps, METH_VARARGS,
+    "Set context capabilities of a vserver context" },
+  { "getccaps", vserver_get_ccaps, METH_VARARGS,
+    "Get context capabilities of a vserver context" },
+  { "text2ccaps", vserver_text2ccaps, METH_VARARGS,
+    "Translate a string of context capabilities to a bitmap" },
+  { "ccaps2text", vserver_ccaps2text, METH_VARARGS,
+    "Translate a context-capability-bitmap into a string" },
   { "netadd", vserver_net_add, METH_VARARGS,
     "Assign an IP address to a context" },
   { "netremove", vserver_net_remove, METH_VARARGS,