From: Michael Tremer Date: Tue, 16 Aug 2022 15:57:23 +0000 (+0000) Subject: jail: Export new bind action in favour of pakfire_bind() X-Git-Tag: 0.9.28~495 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=061223f71ff655ec8f860b9f12f1abe92274c7fc;p=people%2Fms%2Fpakfire.git jail: Export new bind action in favour of pakfire_bind() Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 22eda846e..7f4c9abb1 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -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, diff --git a/src/libpakfire/include/pakfire/mount.h b/src/libpakfire/include/pakfire/mount.h index fe9d3023f..aee963c8f 100644 --- a/src/libpakfire/include/pakfire/mount.h +++ b/src/libpakfire/include/pakfire/mount.h @@ -21,12 +21,12 @@ #ifndef PAKFIRE_MOUNT_H #define PAKFIRE_MOUNT_H +#ifdef PAKFIRE_PRIVATE + #include 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); diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index fafaa108e..29d2bb6e7 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -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; diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index ed88ce63d..37378e8c9 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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; diff --git a/src/libpakfire/mount.c b/src/libpakfire/mount.c index c2490589e..c7e019168 100644 --- a/src/libpakfire/mount.c +++ b/src/libpakfire/mount.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -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]; diff --git a/src/scripts/pakfire.in b/src/scripts/pakfire.in index 52a16248a..c298f6a05 100644 --- a/src/scripts/pakfire.in +++ b/src/scripts/pakfire.in @@ -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