]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Export new bind action in favour of pakfire_bind()
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 15:57:23 +0000 (15:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 15:57:23 +0000 (15:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/mount.h
src/libpakfire/jail.c
src/libpakfire/libpakfire.sym
src/libpakfire/mount.c
src/scripts/pakfire.in

index 22eda846eb7eeb39fa2552e044408f7e37b81c1e..7f4c9abb18eccde73f5dcbbaad6c3e3725a19fce 100644 (file)
@@ -808,6 +808,7 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
        char* kwlist[] = {
                "command",
                "environ",
+               "bind",
                "interactive",
                "logging_callback",
                "nice",
@@ -824,13 +825,14 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
 
        PyObject* command = NULL;
        PyObject* environ = NULL;
+       PyObject* bind = NULL;
        int interactive = 0;
        PyObject* logging_callback = NULL;
        int nice = 0;
        int return_output = 0;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OpOip", kwlist, &command, &environ,
-                       &interactive, &logging_callback, &nice, &return_output))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOpOip", kwlist, &command, &environ,
+                       &bind, &interactive, &logging_callback, &nice, &return_output))
                return NULL;
 
        // Check if command is a list
@@ -865,6 +867,12 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
                argv[i] = PyUnicode_AsUTF8(item);
        }
 
+       // Check if bind is a sequence
+       if (bind && !PySequence_Check(bind)) {
+               PyErr_SetString(PyExc_ValueError, "bind is not a sequence");
+               goto ERROR;
+       }
+
        // Interactive?
        if (interactive)
                flags |= PAKFIRE_JAIL_INTERACTIVE;
@@ -923,6 +931,34 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
                }
        }
 
+       const Py_ssize_t num_bind = PySequence_Length(bind);
+
+       // Bind
+       for (unsigned int i = 0; i < num_bind; i++) {
+               PyObject* b = PySequence_ITEM(bind, i);
+               if (!b)
+                       goto ERROR;
+
+               // Check if this is a Unicode object
+               if (!PyUnicode_Check(b)) {
+                       PyErr_SetString(PyExc_ValueError, "bind contains a non-Unicode object");
+                       Py_DECREF(b);
+                       goto ERROR;
+               }
+
+               const char* path = PyUnicode_AsUTF8(b);
+
+               // Perform bind
+               r = pakfire_jail_bind(jail, path, path, 0);
+               if (r) {
+                       PyErr_SetFromErrno(PyExc_OSError);
+                       Py_DECREF(b);
+                       goto ERROR;
+               }
+
+               Py_DECREF(b);
+       }
+
        // Execute command
        r = pakfire_jail_exec(jail, argv, (return_output) ? &output : NULL);
 
@@ -994,22 +1030,6 @@ static PyObject* Pakfire_dist(PakfireObject* self, PyObject* args) {
        return ret;
 }
 
-static PyObject* Pakfire_bind(PakfireObject* self, PyObject* args) {
-       const char* src = NULL;
-       const char* dst = NULL;
-
-       if (!PyArg_ParseTuple(args, "s|z", &src, &dst))
-               return NULL;
-
-       int r = pakfire_bind(self->pakfire, src, dst, 0);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       Py_RETURN_NONE;
-}
-
 static PyObject* Pakfire_copy_in(PakfireObject* self, PyObject* args) {
        const char* src = NULL;
        const char* dst = NULL;
@@ -1292,12 +1312,6 @@ ERROR:
 }
 
 static struct PyMethodDef Pakfire_methods[] = {
-       {
-               "bind",
-               (PyCFunction)Pakfire_bind,
-               METH_VARARGS,
-               NULL,
-       },
        {
                "build",
                (PyCFunction)Pakfire_build,
index fe9d3023fd1bb99a80037bce9623cab67774465e..aee963c8fe97a0bb63e53459c05aec41e0d1a16b 100644 (file)
 #ifndef PAKFIRE_MOUNT_H
 #define PAKFIRE_MOUNT_H
 
+#ifdef PAKFIRE_PRIVATE
+
 #include <pakfire/pakfire.h>
 
 int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags);
 
-#ifdef PAKFIRE_PRIVATE
-
 int pakfire_mount_list(struct pakfire* pakfire);
 
 int pakfire_mount_all(struct pakfire* pakfire);
index fafaa108ea5d2c184c399c1f2b4ad993a1f13fde..29d2bb6e7bf0955cc917cc067cc35391731e789b 100644 (file)
@@ -899,7 +899,7 @@ ERROR:
 
 // Mountpoints
 
-int pakfire_jail_bind(struct pakfire_jail* jail,
+PAKFIRE_EXPORT int pakfire_jail_bind(struct pakfire_jail* jail,
                const char* source, const char* target, int flags) {
        struct pakfire_jail_mountpoint* mp = NULL;
        int r;
index ed88ce63da5e8bbbf71cf958f717b4b8cb65ad4a..37378e8c9a211c2fbb5b77e8a1692d268b9e82f1 100644 (file)
@@ -21,7 +21,6 @@
 LIBPAKFIRE_0 {
 global:
        # pakfire
-       pakfire_bind;
        pakfire_check;
        pakfire_clean;
        pakfire_copy_in;
@@ -138,6 +137,7 @@ global:
        pakfire_key_unref;
 
        # jail
+       pakfire_jail_bind;
        pakfire_jail_create;
        pakfire_jail_exec;
        pakfire_jail_exec_script;
index c2490589eace627e403178b7d38d6ff635862e31..c7e0191687ebe825bca7cb16b62947a85d151b02 100644 (file)
@@ -32,7 +32,6 @@
 #include <pakfire/arch.h>
 #include <pakfire/logging.h>
 #include <pakfire/pakfire.h>
-#include <pakfire/private.h>
 #include <pakfire/mount.h>
 #include <pakfire/util.h>
 
@@ -382,7 +381,7 @@ RETRY:
        return 0;
 }
 
-PAKFIRE_EXPORT int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
+int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
        struct stat st;
        char mountpoint[PATH_MAX];
 
index 52a16248a99f78e9dccbbd97bbdfa0f4cb84368b..c298f6a05abc18298413f676184510651f8ba30e 100644 (file)
@@ -307,10 +307,6 @@ class Cli(object):
                """
                        Executes a command
                """
-               # Bind-mount everything
-               for bind in args.binds:
-                       p.bind(bind)
-
                # Log everything to the console
                def logging_callback(level, line):
                        if level >= logging.ERROR:
@@ -319,7 +315,7 @@ class Cli(object):
                                sys.stdout.write("%s\n" % line)
 
                try:
-                       return p.execute(args.command,
+                       return p.execute(args.command, bind=args.binds,
                                interactive=args.interactive, logging_callback=logging_callback)
 
                # Exit program with the command's exit code